[Python-3000-checkins] r61962 - in python/branches/py3k-importlib: Demo/classes/README Demo/classes/Range.py Demo/classes/Rat.py Demo/curses/repeat.py Demo/embed/demo.c Demo/imputil/knee.py Demo/newmetaclasses/Eiffel.py Demo/pdist/client.py Demo/pdist/cvslock.py Demo/scripts/toaiff.py Demo/tkinter/guido/ShellWindow.py Demo/tkinter/guido/brownian2.py Doc/ACKS.txt Doc/Makefile Doc/README.txt Doc/TODO.txt Doc/about.rst Doc/bugs.rst Doc/c-api/abstract.rst Doc/c-api/allocation.rst Doc/c-api/arg.rst Doc/c-api/bool.rst Doc/c-api/buffer.rst Doc/c-api/cell.rst Doc/c-api/cobject.rst Doc/c-api/complex.rst Doc/c-api/concrete.rst Doc/c-api/conversion.rst Doc/c-api/datetime.rst Doc/c-api/descriptor.rst Doc/c-api/dict.rst Doc/c-api/exceptions.rst Doc/c-api/file.rst Doc/c-api/float.rst Doc/c-api/function.rst Doc/c-api/gcsupport.rst Doc/c-api/gen.rst Doc/c-api/import.rst Doc/c-api/index.rst Doc/c-api/init.rst Doc/c-api/intro.rst Doc/c-api/iter.rst Doc/c-api/iterator.rst Doc/c-api/list.rst Doc/c-api/long.rst Doc/c-api/mapping.rst Doc/c-api/marshal.rst Doc/c-api/memory.rst Doc/c-api/method.rst Doc/c-api/module.rst Doc/c-api/newtypes.rst Doc/c-api/none.rst Doc/c-api/number.rst Doc/c-api/objbuffer.rst Doc/c-api/object.rst Doc/c-api/objimpl.rst Doc/c-api/refcounting.rst Doc/c-api/reflection.rst Doc/c-api/sequence.rst Doc/c-api/set.rst Doc/c-api/slice.rst Doc/c-api/string.rst Doc/c-api/structures.rst Doc/c-api/sys.rst Doc/c-api/tuple.rst Doc/c-api/type.rst Doc/c-api/typeobj.rst Doc/c-api/unicode.rst Doc/c-api/utilities.rst Doc/c-api/veryhigh.rst Doc/c-api/weakref.rst Doc/conf.py Doc/contents.rst Doc/copyright.rst Doc/data/refcounts.dat Doc/distutils/apiref.rst Doc/distutils/builtdist.rst Doc/distutils/commandref.rst Doc/distutils/configfile.rst Doc/distutils/examples.rst Doc/distutils/extending.rst Doc/distutils/index.rst Doc/distutils/introduction.rst Doc/distutils/packageindex.rst Doc/distutils/setupscript.rst Doc/distutils/sourcedist.rst Doc/distutils/uploading.rst Doc/documenting/fromlatex.rst Doc/documenting/index.rst Doc/documenting/intro.rst Doc/documenting/markup.rst Doc/documenting/rest.rst Doc/documenting/sphinx.rst Doc/documenting/style.rst Doc/extending/building.rst Doc/extending/embedding.rst Doc/extending/extending.rst Doc/extending/index.rst Doc/extending/newtypes.rst Doc/extending/windows.rst Doc/glossary.rst Doc/howto/advocacy.rst Doc/howto/curses.rst Doc/howto/doanddont.rst Doc/howto/functional.rst Doc/howto/index.rst Doc/howto/pythonmac.rst Doc/howto/regex.rst Doc/howto/sockets.rst Doc/howto/unicode.rst Doc/howto/urllib2.rst Doc/includes/email-alternative.py Doc/includes/email-dir.py Doc/includes/email-mime.py Doc/includes/email-simple.py Doc/includes/email-unpack.py Doc/includes/minidom-example.py Doc/includes/noddy2.c Doc/includes/noddy3.c Doc/includes/noddy4.c Doc/includes/run-func.c Doc/includes/setup.py Doc/includes/shoddy.c Doc/includes/sqlite3/adapter_datetime.py Doc/includes/sqlite3/adapter_point_1.py Doc/includes/sqlite3/adapter_point_2.py Doc/includes/sqlite3/collation_reverse.py Doc/includes/sqlite3/complete_statement.py Doc/includes/sqlite3/connect_db_1.py Doc/includes/sqlite3/connect_db_2.py Doc/includes/sqlite3/converter_point.py Doc/includes/sqlite3/countcursors.py Doc/includes/sqlite3/createdb.py Doc/includes/sqlite3/execsql_fetchonerow.py Doc/includes/sqlite3/execsql_printall_1.py Doc/includes/sqlite3/execute_1.py Doc/includes/sqlite3/execute_2.py Doc/includes/sqlite3/execute_3.py Doc/includes/sqlite3/executemany_1.py Doc/includes/sqlite3/executemany_2.py Doc/includes/sqlite3/executescript.py Doc/includes/sqlite3/insert_more_people.py Doc/includes/sqlite3/md5func.py Doc/includes/sqlite3/mysumaggr.py Doc/includes/sqlite3/parse_colnames.py Doc/includes/sqlite3/pysqlite_datetime.py Doc/includes/sqlite3/row_factory.py Doc/includes/sqlite3/rowclass.py Doc/includes/sqlite3/shared_cache.py Doc/includes/sqlite3/shortcut_methods.py Doc/includes/sqlite3/simple_tableprinter.py Doc/includes/sqlite3/text_factory.py Doc/includes/test.py Doc/includes/tzinfo-examples.py Doc/install/index.rst Doc/library/__builtin__.rst Doc/library/__future__.rst Doc/library/__main__.rst Doc/library/_ast.rst Doc/library/_winreg.rst Doc/library/abc.rst Doc/library/aepack.rst Doc/library/aetools.rst Doc/library/aetypes.rst Doc/library/aifc.rst Doc/library/allos.rst Doc/library/anydbm.rst Doc/library/archiving.rst Doc/library/array.rst Doc/library/asynchat.rst Doc/library/asyncore.rst Doc/library/atexit.rst Doc/library/audioop.rst Doc/library/autogil.rst Doc/library/base64.rst Doc/library/basehttpserver.rst Doc/library/bdb.rst Doc/library/binascii.rst Doc/library/binhex.rst Doc/library/bisect.rst Doc/library/bsddb.rst Doc/library/builtins.rst Doc/library/bz2.rst Doc/library/calendar.rst Doc/library/carbon.rst Doc/library/cgi.rst Doc/library/cgihttpserver.rst Doc/library/cgitb.rst Doc/library/chunk.rst Doc/library/cmath.rst Doc/library/cmd.rst Doc/library/code.rst Doc/library/codecs.rst Doc/library/codeop.rst Doc/library/collections.rst Doc/library/colorpicker.rst Doc/library/colorsys.rst Doc/library/commands.rst Doc/library/compileall.rst Doc/library/configparser.rst Doc/library/constants.rst Doc/library/contextlib.rst Doc/library/cookie.rst Doc/library/cookielib.rst Doc/library/copy.rst Doc/library/copy_reg.rst Doc/library/crypt.rst Doc/library/crypto.rst Doc/library/csv.rst Doc/library/ctypes.rst Doc/library/curses.ascii.rst Doc/library/curses.panel.rst Doc/library/curses.rst Doc/library/custominterp.rst Doc/library/datatypes.rst Doc/library/datetime.rst Doc/library/dbhash.rst Doc/library/dbm.rst Doc/library/debug.rst Doc/library/decimal.rst Doc/library/development.rst Doc/library/difflib.rst Doc/library/dircache.rst Doc/library/dis.rst Doc/library/distutils.rst Doc/library/dl.rst Doc/library/doctest.rst Doc/library/docxmlrpcserver.rst Doc/library/dumbdbm.rst Doc/library/dummy_thread.rst Doc/library/dummy_threading.rst Doc/library/easydialogs.rst Doc/library/email-examples.rst Doc/library/email.charset.rst Doc/library/email.encoders.rst Doc/library/email.errors.rst Doc/library/email.generator.rst Doc/library/email.header.rst Doc/library/email.iterators.rst Doc/library/email.message.rst Doc/library/email.mime.rst Doc/library/email.parser.rst Doc/library/email.rst Doc/library/email.util.rst Doc/library/errno.rst Doc/library/exceptions.rst Doc/library/fcntl.rst Doc/library/filecmp.rst Doc/library/fileformats.rst Doc/library/fileinput.rst Doc/library/filesys.rst Doc/library/fnmatch.rst Doc/library/formatter.rst Doc/library/fpectl.rst Doc/library/fpformat.rst Doc/library/fractions.rst Doc/library/framework.rst Doc/library/frameworks.rst Doc/library/ftplib.rst Doc/library/functions.rst Doc/library/functools.rst Doc/library/future_builtins.rst Doc/library/gc.rst Doc/library/gdbm.rst Doc/library/gensuitemodule.rst Doc/library/getopt.rst Doc/library/getpass.rst Doc/library/gettext.rst Doc/library/glob.rst Doc/library/grp.rst Doc/library/gzip.rst Doc/library/hashlib.rst Doc/library/heapq.rst Doc/library/hmac.rst Doc/library/htmllib.rst Doc/library/htmlparser.rst Doc/library/httplib.rst Doc/library/i18n.rst Doc/library/ic.rst Doc/library/idle.rst Doc/library/imaplib.rst Doc/library/imghdr.rst Doc/library/imp.rst Doc/library/imputil.rst Doc/library/index.rst Doc/library/inspect.rst Doc/library/internet.rst Doc/library/intro.rst Doc/library/ipc.rst Doc/library/itertools.rst Doc/library/keyword.rst Doc/library/language.rst Doc/library/linecache.rst Doc/library/locale.rst Doc/library/logging.rst Doc/library/mac.rst Doc/library/macos.rst Doc/library/macosa.rst Doc/library/macostools.rst Doc/library/macpath.rst Doc/library/mailbox.rst Doc/library/mailcap.rst Doc/library/markup.rst Doc/library/marshal.rst Doc/library/math.rst Doc/library/mhlib.rst Doc/library/mimetools.rst Doc/library/mimetypes.rst Doc/library/miniaeframe.rst Doc/library/misc.rst Doc/library/mm.rst Doc/library/mmap.rst Doc/library/modulefinder.rst Doc/library/modules.rst Doc/library/msilib.rst Doc/library/msvcrt.rst Doc/library/multifile.rst Doc/library/mutex.rst Doc/library/netdata.rst Doc/library/netrc.rst Doc/library/new.rst Doc/library/nis.rst Doc/library/nntplib.rst Doc/library/numbers.rst Doc/library/numeric.rst Doc/library/objects.rst Doc/library/operator.rst Doc/library/optparse.rst Doc/library/os.path.rst Doc/library/os.rst Doc/library/ossaudiodev.rst Doc/library/othergui.rst Doc/library/parser.rst Doc/library/pdb.rst Doc/library/persistence.rst Doc/library/pickle.rst Doc/library/pickletools.rst Doc/library/pipes.rst Doc/library/pkgutil.rst Doc/library/platform.rst Doc/library/plistlib.rst Doc/library/poplib.rst Doc/library/posix.rst Doc/library/pprint.rst Doc/library/profile.rst Doc/library/pty.rst Doc/library/pwd.rst Doc/library/py_compile.rst Doc/library/pyclbr.rst Doc/library/pydoc.rst Doc/library/pyexpat.rst Doc/library/python.rst Doc/library/queue.rst Doc/library/quopri.rst Doc/library/random.rst Doc/library/re.rst Doc/library/readline.rst Doc/library/repr.rst Doc/library/resource.rst Doc/library/rfc822.rst Doc/library/rlcompleter.rst Doc/library/robotparser.rst Doc/library/runpy.rst Doc/library/sched.rst Doc/library/scrolledtext.rst Doc/library/select.rst Doc/library/sgmllib.rst Doc/library/shelve.rst Doc/library/shlex.rst Doc/library/shutil.rst Doc/library/signal.rst Doc/library/simplehttpserver.rst Doc/library/simplexmlrpcserver.rst Doc/library/site.rst Doc/library/smtpd.rst Doc/library/smtplib.rst Doc/library/sndhdr.rst Doc/library/socket.rst Doc/library/socketserver.rst Doc/library/someos.rst Doc/library/spwd.rst Doc/library/sqlite3.rst Doc/library/ssl.rst Doc/library/stat.rst Doc/library/statvfs.rst Doc/library/stdtypes.rst Doc/library/string.rst Doc/library/stringio.rst Doc/library/stringprep.rst Doc/library/strings.rst Doc/library/struct.rst Doc/library/subprocess.rst Doc/library/sunau.rst Doc/library/symbol.rst Doc/library/sys.rst Doc/library/syslog.rst Doc/library/tabnanny.rst Doc/library/tarfile.rst Doc/library/telnetlib.rst Doc/library/tempfile.rst Doc/library/termios.rst Doc/library/test.rst Doc/library/textwrap.rst Doc/library/thread.rst Doc/library/threading.rst Doc/library/time.rst Doc/library/timeit.rst Doc/library/tix.rst Doc/library/tk.rst Doc/library/tkinter.rst Doc/library/token.rst Doc/library/tokenize.rst Doc/library/trace.rst Doc/library/traceback.rst Doc/library/tty.rst Doc/library/turtle.rst Doc/library/types.rst Doc/library/undoc.rst Doc/library/unicodedata.rst Doc/library/unittest.rst Doc/library/unix.rst Doc/library/urllib.rst Doc/library/urllib2.rst Doc/library/urlparse.rst Doc/library/user.rst Doc/library/userdict.rst Doc/library/uu.rst Doc/library/uuid.rst Doc/library/warnings.rst Doc/library/wave.rst Doc/library/weakref.rst Doc/library/webbrowser.rst Doc/library/whichdb.rst Doc/library/windows.rst Doc/library/winsound.rst Doc/library/wsgiref.rst Doc/library/xdrlib.rst Doc/library/xml.dom.minidom.rst Doc/library/xml.dom.pulldom.rst Doc/library/xml.dom.rst Doc/library/xml.etree.elementtree.rst Doc/library/xml.etree.rst Doc/library/xml.sax.handler.rst Doc/library/xml.sax.reader.rst Doc/library/xml.sax.rst Doc/library/xml.sax.utils.rst Doc/library/xmlrpclib.rst Doc/library/zipfile.rst Doc/library/zipimport.rst Doc/library/zlib.rst Doc/license.rst Doc/make.bat Doc/reference/compound_stmts.rst Doc/reference/datamodel.rst Doc/reference/executionmodel.rst Doc/reference/expressions.rst Doc/reference/index.rst Doc/reference/introduction.rst Doc/reference/lexical_analysis.rst Doc/reference/simple_stmts.rst Doc/reference/toplevel_components.rst Doc/tools/sphinx-build.py Doc/tools/sphinx-web.py Doc/tools/sphinxext Doc/tutorial/appetite.rst Doc/tutorial/classes.rst Doc/tutorial/controlflow.rst Doc/tutorial/datastructures.rst Doc/tutorial/errors.rst Doc/tutorial/floatingpoint.rst Doc/tutorial/index.rst Doc/tutorial/inputoutput.rst Doc/tutorial/interactive.rst Doc/tutorial/interpreter.rst Doc/tutorial/introduction.rst Doc/tutorial/modules.rst Doc/tutorial/stdlib.rst Doc/tutorial/stdlib2.rst Doc/tutorial/whatnow.rst Doc/using Doc/whatsnew/2.0.rst Doc/whatsnew/2.1.rst Doc/whatsnew/2.2.rst Doc/whatsnew/2.3.rst Doc/whatsnew/2.4.rst Doc/whatsnew/2.5.rst Doc/whatsnew/2.6.rst Doc/whatsnew/3.0.rst Include/Python.h Include/abstract.h Include/boolobject.h Include/bytes_methods.h Include/bytesobject.h Include/cStringIO.h Include/cellobject.h Include/ceval.h Include/classobject.h Include/cobject.h Include/code.h Include/compile.h Include/complexobject.h Include/datetime.h Include/descrobject.h Include/dictobject.h Include/fileobject.h Include/floatobject.h Include/frameobject.h Include/funcobject.h Include/genobject.h Include/import.h Include/intobject.h Include/iterobject.h Include/listobject.h Include/longobject.h Include/memoryobject.h Include/methodobject.h Include/modsupport.h Include/moduleobject.h Include/object.h Include/objimpl.h Include/opcode.h Include/patchlevel.h Include/py_curses.h Include/pydebug.h Include/pyerrors.h Include/pyport.h Include/pystrcmp.h Include/pythonrun.h Include/rangeobject.h Include/setobject.h Include/sliceobject.h Include/stringobject.h Include/structmember.h Include/symtable.h Include/traceback.h Include/tupleobject.h Include/unicodeobject.h Include/weakrefobject.h LICENSE Lib/BaseHTTPServer.py Lib/ConfigParser.py Lib/DocXMLRPCServer.py Lib/HTMLParser.py Lib/Queue.py Lib/SimpleHTTPServer.py Lib/SimpleXMLRPCServer.py Lib/SocketServer.py Lib/UserDict.py Lib/UserList.py Lib/UserString.py Lib/__future__.py Lib/_abcoll.py Lib/_markupbase.py Lib/_strptime.py Lib/_weakrefset.py Lib/abc.py Lib/aifc.py Lib/asyncore.py Lib/base64.py Lib/binhex.py Lib/bsddb/__init__.py Lib/bsddb/dbobj.py Lib/bsddb/dbshelve.py Lib/bsddb/dbtables.py Lib/bsddb/test/test_1413192.py Lib/bsddb/test/test_associate.py Lib/bsddb/test/test_basics.py Lib/bsddb/test/test_compare.py Lib/bsddb/test/test_cursor_pget_bug.py Lib/bsddb/test/test_dbobj.py Lib/bsddb/test/test_dbshelve.py Lib/bsddb/test/test_dbtables.py Lib/bsddb/test/test_env_close.py Lib/bsddb/test/test_join.py Lib/bsddb/test/test_lock.py Lib/bsddb/test/test_misc.py Lib/bsddb/test/test_pickle.py Lib/bsddb/test/test_recno.py Lib/bsddb/test/test_sequence.py Lib/bsddb/test/test_thread.py Lib/cProfile.py Lib/calendar.py Lib/cgi.py Lib/cmd.py Lib/code.py Lib/codecs.py Lib/collections.py Lib/compileall.py Lib/contextlib.py Lib/cookielib.py Lib/copy.py Lib/copy_reg.py Lib/csv.py Lib/ctypes/__init__.py Lib/ctypes/test/__init__.py Lib/ctypes/test/test_array_in_pointer.py Lib/ctypes/test/test_arrays.py Lib/ctypes/test/test_buffers.py Lib/ctypes/test/test_byteswap.py Lib/ctypes/test/test_callbacks.py Lib/ctypes/test/test_cfuncs.py Lib/ctypes/test/test_checkretval.py Lib/ctypes/test/test_delattr.py Lib/ctypes/test/test_find.py Lib/ctypes/test/test_functions.py Lib/ctypes/test/test_libc.py Lib/ctypes/test/test_memfunctions.py Lib/ctypes/test/test_numbers.py Lib/ctypes/test/test_pickling.py Lib/ctypes/test/test_prototypes.py Lib/ctypes/test/test_python_api.py Lib/ctypes/test/test_returnfuncptrs.py Lib/ctypes/test/test_slicing.py Lib/ctypes/test/test_strings.py Lib/ctypes/test/test_structures.py Lib/ctypes/test/test_unicode.py Lib/ctypes/test/test_values.py Lib/ctypes/util.py Lib/curses/__init__.py Lib/curses/textpad.py Lib/curses/wrapper.py Lib/decimal.py Lib/difflib.py Lib/dis.py Lib/distutils/__init__.py Lib/distutils/bcppcompiler.py Lib/distutils/ccompiler.py Lib/distutils/cmd.py Lib/distutils/command/bdist_dumb.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/install_data.py Lib/distutils/command/install_headers.py Lib/distutils/command/register.py Lib/distutils/command/sdist.py Lib/distutils/command/wininst-6.0.exe Lib/distutils/command/wininst-6.exe Lib/distutils/command/wininst-8.0.exe Lib/distutils/command/wininst-8.exe Lib/distutils/command/wininst-9.0.exe Lib/distutils/cygwinccompiler.py Lib/distutils/dir_util.py Lib/distutils/dist.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/spawn.py Lib/distutils/sysconfig.py Lib/distutils/tests/test_dist.py Lib/distutils/tests/test_sysconfig.py Lib/distutils/unixccompiler.py Lib/distutils/util.py Lib/doctest.py Lib/dumbdbm.py Lib/email/base64mime.py Lib/email/feedparser.py Lib/email/generator.py Lib/email/iterators.py Lib/email/mime/multipart.py Lib/email/test/data/msg_15.txt Lib/email/test/test_email.py Lib/encodings/__init__.py Lib/encodings/aliases.py Lib/encodings/bz2_codec.py Lib/encodings/idna.py Lib/encodings/punycode.py Lib/encodings/utf_7.py Lib/encodings/utf_8_sig.py Lib/filecmp.py Lib/fileinput.py Lib/formatter.py Lib/fractions.py Lib/ftplib.py Lib/getpass.py Lib/gettext.py Lib/glob.py Lib/gzip.py Lib/hashlib.py Lib/heapq.py Lib/hmac.py Lib/htmlentitydefs.py Lib/httplib.py Lib/idlelib/AutoComplete.py Lib/idlelib/AutoCompleteWindow.py Lib/idlelib/CallTips.py Lib/idlelib/CodeContext.py Lib/idlelib/ColorDelegator.py Lib/idlelib/EditorWindow.py Lib/idlelib/FileList.py Lib/idlelib/FormatParagraph.py Lib/idlelib/IOBinding.py Lib/idlelib/MultiCall.py Lib/idlelib/NEWS.txt Lib/idlelib/OutputWindow.py Lib/idlelib/PyParse.py Lib/idlelib/PyShell.py Lib/idlelib/RemoteDebugger.py Lib/idlelib/ScriptBinding.py Lib/idlelib/TreeWidget.py Lib/idlelib/UndoDelegator.py Lib/idlelib/WidgetRedirector.py Lib/idlelib/aboutDialog.py Lib/idlelib/configDialog.py Lib/idlelib/configHandler.py Lib/idlelib/idlever.py Lib/idlelib/keybindingDialog.py Lib/idlelib/run.py Lib/idlelib/tabbedpages.py Lib/idlelib/tabpage.py Lib/idlelib/textView.py Lib/ihooks.py Lib/imaplib.py Lib/imputil.py Lib/inspect.py Lib/io.py Lib/keyword.py Lib/lib-tk/FixTk.py Lib/lib-tk/Tkinter.py Lib/lib-tk/tkSimpleDialog.py Lib/lib2to3 Lib/lib2to3/fixes Lib/lib2to3/pgen2 Lib/lib2to3/tests Lib/locale.py Lib/logging/__init__.py Lib/logging/config.py Lib/logging/handlers.py Lib/mailbox.py Lib/markupbase.py Lib/mhlib.py Lib/mimetypes.py Lib/modulefinder.py Lib/msilib/__init__.py Lib/msilib/schema.py Lib/netrc.py Lib/new.py Lib/ntpath.py Lib/numbers.py Lib/opcode.py Lib/optparse.py Lib/os.py Lib/pdb.py Lib/pickle.py Lib/pickletools.py Lib/pkgutil.py Lib/plat-freebsd6/IN.py Lib/plat-freebsd7/IN.py Lib/plat-freebsd8 Lib/plat-mac/EasyDialogs.py Lib/plat-mac/MiniAEFrame.py Lib/plat-mac/aepack.py Lib/plat-mac/aetools.py Lib/plat-mac/aetypes.py Lib/plat-mac/bgenlocations.py Lib/plat-mac/gensuitemodule.py Lib/plat-mac/ic.py Lib/plat-mac/icopen.py Lib/plat-mac/macostools.py Lib/plat-mac/plistlib.py Lib/plat-mac/terminalcommand.py Lib/platform.py Lib/plistlib.py Lib/posixpath.py Lib/pprint.py Lib/pstats.py Lib/py_compile.py Lib/pyclbr.py Lib/pydoc.py Lib/quopri.py Lib/random.py Lib/re.py Lib/repr.py Lib/rlcompleter.py Lib/runpy.py Lib/sched.py Lib/sgmllib.py Lib/shelve.py Lib/shlex.py Lib/shutil.py Lib/site.py Lib/smtpd.py Lib/smtplib.py Lib/socket.py Lib/sqlite3/dbapi2.py Lib/sqlite3/test/factory.py Lib/sqlite3/test/hooks.py Lib/sqlite3/test/regression.py Lib/sqlite3/test/transactions.py Lib/sqlite3/test/types.py Lib/sqlite3/test/userfunctions.py Lib/sre_compile.py Lib/sre_parse.py Lib/ssl.py Lib/stat.py Lib/string.py Lib/struct.py Lib/subprocess.py Lib/sunau.py Lib/tarfile.py Lib/tempfile.py Lib/test/README Lib/test/buffer_tests.py Lib/test/cjkencodings_test.py Lib/test/crashers/borrowed_ref_2.py Lib/test/crashers/file_threads.py Lib/test/crashers/loosing_dict_ref.py Lib/test/crashers/multithreaded_close.py Lib/test/crashers/weakref_in_del.py Lib/test/curses_tests.py Lib/test/decimaltestdata/abs.decTest Lib/test/decimaltestdata/add.decTest Lib/test/decimaltestdata/and.decTest Lib/test/decimaltestdata/base.decTest Lib/test/decimaltestdata/clamp.decTest Lib/test/decimaltestdata/class.decTest Lib/test/decimaltestdata/compare.decTest Lib/test/decimaltestdata/comparetotal.decTest Lib/test/decimaltestdata/comparetotmag.decTest Lib/test/decimaltestdata/copy.decTest Lib/test/decimaltestdata/copyabs.decTest Lib/test/decimaltestdata/copynegate.decTest Lib/test/decimaltestdata/copysign.decTest Lib/test/decimaltestdata/ddAbs.decTest Lib/test/decimaltestdata/ddAdd.decTest Lib/test/decimaltestdata/ddAnd.decTest Lib/test/decimaltestdata/ddBase.decTest Lib/test/decimaltestdata/ddCanonical.decTest Lib/test/decimaltestdata/ddClass.decTest Lib/test/decimaltestdata/ddCompare.decTest Lib/test/decimaltestdata/ddCompareSig.decTest Lib/test/decimaltestdata/ddCompareTotal.decTest Lib/test/decimaltestdata/ddCompareTotalMag.decTest Lib/test/decimaltestdata/ddCopy.decTest Lib/test/decimaltestdata/ddCopyAbs.decTest Lib/test/decimaltestdata/ddCopyNegate.decTest Lib/test/decimaltestdata/ddCopySign.decTest Lib/test/decimaltestdata/ddDivide.decTest Lib/test/decimaltestdata/ddDivideInt.decTest Lib/test/decimaltestdata/ddEncode.decTest Lib/test/decimaltestdata/ddFMA.decTest Lib/test/decimaltestdata/ddInvert.decTest Lib/test/decimaltestdata/ddLogB.decTest Lib/test/decimaltestdata/ddMax.decTest Lib/test/decimaltestdata/ddMaxMag.decTest Lib/test/decimaltestdata/ddMin.decTest Lib/test/decimaltestdata/ddMinMag.decTest Lib/test/decimaltestdata/ddMinus.decTest Lib/test/decimaltestdata/ddMultiply.decTest Lib/test/decimaltestdata/ddNextMinus.decTest Lib/test/decimaltestdata/ddNextPlus.decTest Lib/test/decimaltestdata/ddNextToward.decTest Lib/test/decimaltestdata/ddOr.decTest Lib/test/decimaltestdata/ddPlus.decTest Lib/test/decimaltestdata/ddQuantize.decTest Lib/test/decimaltestdata/ddReduce.decTest Lib/test/decimaltestdata/ddRemainder.decTest Lib/test/decimaltestdata/ddRemainderNear.decTest Lib/test/decimaltestdata/ddRotate.decTest Lib/test/decimaltestdata/ddSameQuantum.decTest Lib/test/decimaltestdata/ddScaleB.decTest Lib/test/decimaltestdata/ddShift.decTest Lib/test/decimaltestdata/ddSubtract.decTest Lib/test/decimaltestdata/ddToIntegral.decTest Lib/test/decimaltestdata/ddXor.decTest Lib/test/decimaltestdata/decDouble.decTest Lib/test/decimaltestdata/decQuad.decTest Lib/test/decimaltestdata/decSingle.decTest Lib/test/decimaltestdata/divide.decTest Lib/test/decimaltestdata/divideint.decTest Lib/test/decimaltestdata/dqAbs.decTest Lib/test/decimaltestdata/dqAdd.decTest Lib/test/decimaltestdata/dqAnd.decTest Lib/test/decimaltestdata/dqBase.decTest Lib/test/decimaltestdata/dqCanonical.decTest Lib/test/decimaltestdata/dqClass.decTest Lib/test/decimaltestdata/dqCompare.decTest Lib/test/decimaltestdata/dqCompareSig.decTest Lib/test/decimaltestdata/dqCompareTotal.decTest Lib/test/decimaltestdata/dqCompareTotalMag.decTest Lib/test/decimaltestdata/dqCopy.decTest Lib/test/decimaltestdata/dqCopyAbs.decTest Lib/test/decimaltestdata/dqCopyNegate.decTest Lib/test/decimaltestdata/dqCopySign.decTest Lib/test/decimaltestdata/dqDivide.decTest Lib/test/decimaltestdata/dqDivideInt.decTest Lib/test/decimaltestdata/dqEncode.decTest Lib/test/decimaltestdata/dqFMA.decTest Lib/test/decimaltestdata/dqInvert.decTest Lib/test/decimaltestdata/dqLogB.decTest Lib/test/decimaltestdata/dqMax.decTest Lib/test/decimaltestdata/dqMaxMag.decTest Lib/test/decimaltestdata/dqMin.decTest Lib/test/decimaltestdata/dqMinMag.decTest Lib/test/decimaltestdata/dqMinus.decTest Lib/test/decimaltestdata/dqMultiply.decTest Lib/test/decimaltestdata/dqNextMinus.decTest Lib/test/decimaltestdata/dqNextPlus.decTest Lib/test/decimaltestdata/dqNextToward.decTest Lib/test/decimaltestdata/dqOr.decTest Lib/test/decimaltestdata/dqPlus.decTest Lib/test/decimaltestdata/dqQuantize.decTest Lib/test/decimaltestdata/dqReduce.decTest Lib/test/decimaltestdata/dqRemainder.decTest Lib/test/decimaltestdata/dqRemainderNear.decTest Lib/test/decimaltestdata/dqRotate.decTest Lib/test/decimaltestdata/dqSameQuantum.decTest Lib/test/decimaltestdata/dqScaleB.decTest Lib/test/decimaltestdata/dqShift.decTest Lib/test/decimaltestdata/dqSubtract.decTest Lib/test/decimaltestdata/dqToIntegral.decTest Lib/test/decimaltestdata/dqXor.decTest Lib/test/decimaltestdata/dsBase.decTest Lib/test/decimaltestdata/dsEncode.decTest Lib/test/decimaltestdata/exp.decTest Lib/test/decimaltestdata/extra.decTest Lib/test/decimaltestdata/fma.decTest Lib/test/decimaltestdata/inexact.decTest Lib/test/decimaltestdata/invert.decTest Lib/test/decimaltestdata/ln.decTest Lib/test/decimaltestdata/log10.decTest Lib/test/decimaltestdata/logb.decTest Lib/test/decimaltestdata/max.decTest Lib/test/decimaltestdata/maxmag.decTest Lib/test/decimaltestdata/min.decTest Lib/test/decimaltestdata/minmag.decTest Lib/test/decimaltestdata/minus.decTest Lib/test/decimaltestdata/multiply.decTest Lib/test/decimaltestdata/nextminus.decTest Lib/test/decimaltestdata/nextplus.decTest Lib/test/decimaltestdata/nexttoward.decTest Lib/test/decimaltestdata/or.decTest Lib/test/decimaltestdata/plus.decTest Lib/test/decimaltestdata/power.decTest Lib/test/decimaltestdata/powersqrt.decTest Lib/test/decimaltestdata/quantize.decTest Lib/test/decimaltestdata/randomBound32.decTest Lib/test/decimaltestdata/randoms.decTest Lib/test/decimaltestdata/reduce.decTest Lib/test/decimaltestdata/remainder.decTest Lib/test/decimaltestdata/remainderNear.decTest Lib/test/decimaltestdata/rescale.decTest Lib/test/decimaltestdata/rotate.decTest Lib/test/decimaltestdata/rounding.decTest Lib/test/decimaltestdata/samequantum.decTest Lib/test/decimaltestdata/scaleb.decTest Lib/test/decimaltestdata/shift.decTest Lib/test/decimaltestdata/squareroot.decTest Lib/test/decimaltestdata/subtract.decTest Lib/test/decimaltestdata/testall.decTest Lib/test/decimaltestdata/tointegral.decTest Lib/test/decimaltestdata/tointegralx.decTest Lib/test/decimaltestdata/xor.decTest Lib/test/exception_hierarchy.txt Lib/test/floating_points.txt Lib/test/fork_wait.py Lib/test/inspect_fodder2.py Lib/test/list_tests.py Lib/test/mapping_tests.py Lib/test/output Lib/test/outstanding_bugs.py Lib/test/pickletester.py Lib/test/profilee.py Lib/test/pydocfodder.py Lib/test/randv2_32.pck Lib/test/randv2_64.pck Lib/test/randv3.pck Lib/test/regex_tests.py Lib/test/regrtest.py Lib/test/relimport.py Lib/test/seq_tests.py Lib/test/string_tests.py Lib/test/svn_python_org_https_cert.pem Lib/test/test_SimpleHTTPServer.py Lib/test/test___all__.py Lib/test/test___future__.py Lib/test/test__locale.py Lib/test/test_abc.py Lib/test/test_abstract_numbers.py Lib/test/test_applesingle.py Lib/test/test_ast.py Lib/test/test_asynchat.py Lib/test/test_asyncore.py Lib/test/test_audioop.py Lib/test/test_bigmem.py Lib/test/test_binascii.py Lib/test/test_bisect.py Lib/test/test_bsddb3.py Lib/test/test_bufio.py Lib/test/test_builtin.py Lib/test/test_bytes.py Lib/test/test_bz2.py Lib/test/test_cProfile.py Lib/test/test_cfgparser.py Lib/test/test_class.py Lib/test/test_cmd.py Lib/test/test_cmd_line.py Lib/test/test_cmd_line_script.py Lib/test/test_codeccallbacks.py Lib/test/test_codecmaps_hk.py Lib/test/test_codecs.py Lib/test/test_coding.py Lib/test/test_collections.py Lib/test/test_compare.py Lib/test/test_compile.py Lib/test/test_complex.py Lib/test/test_contains.py Lib/test/test_copy.py Lib/test/test_crypt.py Lib/test/test_csv.py Lib/test/test_curses.py Lib/test/test_datetime.py Lib/test/test_dbm.py Lib/test/test_decimal.py Lib/test/test_defaultdict.py Lib/test/test_deque.py Lib/test/test_descr.py Lib/test/test_descrtut.py Lib/test/test_dict.py Lib/test/test_dis.py Lib/test/test_doctest.py Lib/test/test_docxmlrpc.py Lib/test/test_dumbdbm.py Lib/test/test_dummy_threading.py Lib/test/test_email.py Lib/test/test_eof.py Lib/test/test_epoll.py Lib/test/test_errno.py Lib/test/test_exceptions.py Lib/test/test_extcall.py Lib/test/test_fcntl.py Lib/test/test_file.py Lib/test/test_fileinput.py Lib/test/test_fileio.py Lib/test/test_float.py Lib/test/test_format.py Lib/test/test_fractions.py Lib/test/test_frozen.py Lib/test/test_ftplib.py Lib/test/test_funcattrs.py Lib/test/test_gc.py Lib/test/test_gdbm.py Lib/test/test_generators.py Lib/test/test_getargs2.py Lib/test/test_getopt.py Lib/test/test_gettext.py Lib/test/test_grammar.py Lib/test/test_grp.py Lib/test/test_gzip.py Lib/test/test_heapq.py Lib/test/test_hexoct.py Lib/test/test_hmac.py Lib/test/test_htmlparser.py Lib/test/test_httplib.py Lib/test/test_imp.py Lib/test/test_import.py Lib/test/test_index.py Lib/test/test_inspect.py Lib/test/test_int_literal.py Lib/test/test_io.py Lib/test/test_ioctl.py Lib/test/test_isinstance.py Lib/test/test_iter.py Lib/test/test_iterlen.py Lib/test/test_itertools.py Lib/test/test_keywordonlyarg.py Lib/test/test_kqueue.py Lib/test/test_largefile.py Lib/test/test_list.py Lib/test/test_locale.py Lib/test/test_logging.py Lib/test/test_long.py Lib/test/test_mailbox.py Lib/test/test_marshal.py Lib/test/test_math.py Lib/test/test_memoryview.py Lib/test/test_minidom.py Lib/test/test_mmap.py Lib/test/test_module.py Lib/test/test_modulefinder.py Lib/test/test_multibytecodec.py Lib/test/test_multibytecodec_support.py Lib/test/test_mutex.py Lib/test/test_netrc.py Lib/test/test_new.py Lib/test/test_nis.py Lib/test/test_ntpath.py Lib/test/test_operator.py Lib/test/test_optparse.py Lib/test/test_os.py Lib/test/test_ossaudiodev.py Lib/test/test_parser.py Lib/test/test_pep247.py Lib/test/test_pep263.py Lib/test/test_pep277.py Lib/test/test_pep352.py Lib/test/test_pickle.py Lib/test/test_pickletools.py Lib/test/test_pkg.py Lib/test/test_plistlib.py Lib/test/test_poll.py Lib/test/test_poplib.py Lib/test/test_posix.py Lib/test/test_posixpath.py Lib/test/test_pprint.py Lib/test/test_print.py Lib/test/test_profile.py Lib/test/test_profilehooks.py Lib/test/test_property.py Lib/test/test_pstats.py Lib/test/test_pty.py Lib/test/test_pwd.py Lib/test/test_pyclbr.py Lib/test/test_pyexpat.py Lib/test/test_queue.py Lib/test/test_random.py Lib/test/test_range.py Lib/test/test_re.py Lib/test/test_repr.py Lib/test/test_resource.py Lib/test/test_rfc822.py Lib/test/test_richcmp.py Lib/test/test_runpy.py Lib/test/test_scope.py Lib/test/test_scriptpackages.py Lib/test/test_select.py Lib/test/test_set.py Lib/test/test_sgmllib.py Lib/test/test_shelve.py Lib/test/test_shutil.py Lib/test/test_signal.py Lib/test/test_site.py Lib/test/test_slice.py Lib/test/test_smtplib.py Lib/test/test_socket.py Lib/test/test_socket_ssl.py Lib/test/test_socketserver.py Lib/test/test_sort.py Lib/test/test_sqlite.py Lib/test/test_ssl.py Lib/test/test_str.py Lib/test/test_strftime.py Lib/test/test_strlit.py Lib/test/test_strptime.py Lib/test/test_struct.py Lib/test/test_structmembers.py Lib/test/test_structseq.py Lib/test/test_subprocess.py Lib/test/test_support.py Lib/test/test_sys.py Lib/test/test_tarfile.py Lib/test/test_telnetlib.py Lib/test/test_tempfile.py Lib/test/test_textwrap.py Lib/test/test_thread.py Lib/test/test_threading.py Lib/test/test_threading_local.py Lib/test/test_timeout.py Lib/test/test_tokenize.py Lib/test/test_trace.py Lib/test/test_traceback.py Lib/test/test_tuple.py Lib/test/test_typechecks.py Lib/test/test_types.py Lib/test/test_unicode.py Lib/test/test_unicode_file.py Lib/test/test_unicodedata.py Lib/test/test_unittest.py Lib/test/test_univnewlines.py Lib/test/test_unpack.py Lib/test/test_unpack_ex.py Lib/test/test_urllib.py Lib/test/test_urllib2.py Lib/test/test_urllib2_localnet.py Lib/test/test_urllib2net.py Lib/test/test_urllibnet.py Lib/test/test_urlparse.py Lib/test/test_userdict.py Lib/test/test_userlist.py Lib/test/test_userstring.py Lib/test/test_warnings.py Lib/test/test_wave.py Lib/test/test_weakref.py Lib/test/test_whichdb.py Lib/test/test_winreg.py Lib/test/test_winsound.py Lib/test/test_with.py Lib/test/test_xml_etree.py Lib/test/test_xml_etree_c.py Lib/test/test_xmlrpc.py Lib/test/test_zipfile.py Lib/test/test_zipimport.py Lib/test/test_zlib.py Lib/test/testall.py Lib/test/testcodec.py Lib/test/testtar.tar Lib/test/tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt Lib/test/tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt Lib/test/tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt Lib/test/tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt Lib/test/tokenize_tests.txt Lib/textwrap.py Lib/threading.py Lib/timeit.py Lib/token.py Lib/tokenize.py Lib/trace.py Lib/traceback.py Lib/types.py Lib/unittest.py Lib/urllib.py Lib/urllib2.py Lib/urlparse.py Lib/uu.py Lib/uuid.py Lib/warnings.py Lib/wave.py Lib/weakref.py Lib/webbrowser.py Lib/xml/dom/domreg.py Lib/xml/dom/expatbuilder.py Lib/xml/dom/minicompat.py Lib/xml/dom/minidom.py Lib/xml/dom/pulldom.py Lib/xml/sax/saxutils.py Lib/xmlrpclib.py Lib/zipfile.py Mac/Demo/PICTbrowse/ICONbrowse.py Mac/Demo/PICTbrowse/PICTbrowse.py Mac/Demo/PICTbrowse/PICTbrowse2.py Mac/Demo/PICTbrowse/cicnbrowse.py Mac/Demo/PICTbrowse/oldPICTbrowse.py Mac/Demo/example1/dnslookup-1.py Mac/Demo/example2/dnslookup-2.py Mac/Demo/imgbrowse/imgbrowse.py Mac/Demo/imgbrowse/mac_image.py Mac/Modules/MacOS.c Mac/Modules/ae/_AEmodule.c Mac/Modules/ae/aescan.py Mac/Modules/ah/ahscan.py Mac/Modules/app/_Appmodule.c Mac/Modules/app/appscan.py Mac/Modules/carbonevt/CarbonEvtscan.py Mac/Modules/carbonevt/_CarbonEvtmodule.c Mac/Modules/cf/_CFmodule.c Mac/Modules/cf/cfscan.py Mac/Modules/cf/pycfbridge.c Mac/Modules/cg/_CGmodule.c Mac/Modules/cg/cgscan.py Mac/Modules/cm/_Cmmodule.c Mac/Modules/cm/cmscan.py Mac/Modules/ctl/_Ctlmodule.c Mac/Modules/ctl/ctlscan.py Mac/Modules/dlg/_Dlgmodule.c Mac/Modules/dlg/dlgscan.py Mac/Modules/drag/_Dragmodule.c Mac/Modules/drag/dragscan.py Mac/Modules/evt/evtscan.py Mac/Modules/file/_Filemodule.c Mac/Modules/file/filescan.py Mac/Modules/fm/fmscan.py Mac/Modules/folder/folderscan.py Mac/Modules/gestaltmodule.c Mac/Modules/help/helpscan.py Mac/Modules/ibcarbon/IBCarbonscan.py Mac/Modules/ibcarbon/_IBCarbon.c Mac/Modules/icn/icnscan.py Mac/Modules/launch/launchscan.py Mac/Modules/list/_Listmodule.c Mac/Modules/list/listscan.py Mac/Modules/menu/_Menumodule.c Mac/Modules/menu/menuscan.py Mac/Modules/mlte/_Mltemodule.c Mac/Modules/mlte/mltescan.py Mac/Modules/osa/_OSAmodule.c Mac/Modules/osa/osascan.py Mac/Modules/qd/_Qdmodule.c Mac/Modules/qd/qdscan.py Mac/Modules/qdoffs/_Qdoffsmodule.c Mac/Modules/qdoffs/qdoffsscan.py Mac/Modules/qt/_Qtmodule.c Mac/Modules/qt/qtscan.py Mac/Modules/res/_Resmodule.c Mac/Modules/res/resscan.py Mac/Modules/scrap/_Scrapmodule.c Mac/Modules/scrap/scrapscan.py Mac/Modules/snd/_Sndihooks.c Mac/Modules/snd/_Sndmodule.c Mac/Modules/snd/sndscan.py Mac/Modules/te/_TEmodule.c Mac/Modules/te/tescan.py Mac/Modules/win/_Winmodule.c Mac/Modules/win/winscan.py Makefile.pre.in Misc/ACKS Misc/HISTORY Misc/NEWS Misc/Vim/python.vim Misc/Vim/syntax_test.py Misc/Vim/vim_syntax.py Misc/Vim/vimrc Misc/build.sh Misc/cheatsheet Misc/developers.txt Misc/python-mode.el Modules/Setup.dist Modules/_bisectmodule.c Modules/_bsddb.c Modules/_codecsmodule.c Modules/_collectionsmodule.c Modules/_csv.c Modules/_ctypes/_ctypes.c Modules/_ctypes/_ctypes_test.c Modules/_ctypes/callbacks.c Modules/_ctypes/callproc.c Modules/_ctypes/cfield.c Modules/_ctypes/ctypes.h Modules/_ctypes/libffi/LICENSE Modules/_ctypes/libffi/Makefile.am Modules/_ctypes/libffi/Makefile.in Modules/_ctypes/libffi/README Modules/_ctypes/libffi/acinclude.m4 Modules/_ctypes/libffi/aclocal.m4 Modules/_ctypes/libffi/config.guess Modules/_ctypes/libffi/config.sub Modules/_ctypes/libffi/configure Modules/_ctypes/libffi/configure.ac Modules/_ctypes/libffi/configure.host Modules/_ctypes/libffi/fficonfig.h.in Modules/_ctypes/libffi/fficonfig.py.in Modules/_ctypes/libffi/include/Makefile.am Modules/_ctypes/libffi/include/Makefile.in Modules/_ctypes/libffi/include/ffi.h.in Modules/_ctypes/libffi/include/ffi_common.h Modules/_ctypes/libffi/install-sh Modules/_ctypes/libffi/libffi.pc.in Modules/_ctypes/libffi/missing Modules/_ctypes/libffi/src/alpha/ffi.c Modules/_ctypes/libffi/src/alpha/ffitarget.h Modules/_ctypes/libffi/src/alpha/osf.S Modules/_ctypes/libffi/src/arm/ffi.c Modules/_ctypes/libffi/src/arm/ffitarget.h Modules/_ctypes/libffi/src/arm/sysv.S Modules/_ctypes/libffi/src/cris/ffi.c Modules/_ctypes/libffi/src/cris/ffitarget.h Modules/_ctypes/libffi/src/frv/eabi.S Modules/_ctypes/libffi/src/frv/ffi.c Modules/_ctypes/libffi/src/frv/ffitarget.h Modules/_ctypes/libffi/src/ia64/ffi.c Modules/_ctypes/libffi/src/ia64/ffitarget.h Modules/_ctypes/libffi/src/ia64/ia64_flags.h Modules/_ctypes/libffi/src/ia64/unix.S Modules/_ctypes/libffi/src/m32r/ffi.c Modules/_ctypes/libffi/src/m68k/ffi.c Modules/_ctypes/libffi/src/m68k/ffitarget.h Modules/_ctypes/libffi/src/m68k/sysv.S Modules/_ctypes/libffi/src/mips/ffi.c Modules/_ctypes/libffi/src/mips/ffitarget.h Modules/_ctypes/libffi/src/mips/n32.S Modules/_ctypes/libffi/src/mips/o32.S Modules/_ctypes/libffi/src/pa/ffi.c Modules/_ctypes/libffi/src/pa/ffitarget.h Modules/_ctypes/libffi/src/pa/linux.S Modules/_ctypes/libffi/src/powerpc/darwin.S Modules/_ctypes/libffi/src/powerpc/darwin_closure.S Modules/_ctypes/libffi/src/powerpc/ffi.c Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c Modules/_ctypes/libffi/src/powerpc/ffitarget.h Modules/_ctypes/libffi/src/powerpc/linux64.S Modules/_ctypes/libffi/src/powerpc/linux64_closure.S Modules/_ctypes/libffi/src/powerpc/ppc_closure.S Modules/_ctypes/libffi/src/powerpc/sysv.S Modules/_ctypes/libffi/src/prep_cif.c Modules/_ctypes/libffi/src/s390/ffi.c Modules/_ctypes/libffi/src/s390/ffitarget.h Modules/_ctypes/libffi/src/s390/sysv.S Modules/_ctypes/libffi/src/sh/ffi.c Modules/_ctypes/libffi/src/sh/ffitarget.h Modules/_ctypes/libffi/src/sh/sysv.S Modules/_ctypes/libffi/src/sh64/ffi.c Modules/_ctypes/libffi/src/sh64/ffitarget.h Modules/_ctypes/libffi/src/sh64/sysv.S Modules/_ctypes/libffi/src/sparc/ffi.c Modules/_ctypes/libffi/src/sparc/ffitarget.h Modules/_ctypes/libffi/src/sparc/v8.S Modules/_ctypes/libffi/src/sparc/v9.S Modules/_ctypes/libffi/src/x86/darwin.S Modules/_ctypes/libffi/src/x86/ffi.c Modules/_ctypes/libffi/src/x86/ffi64.c Modules/_ctypes/libffi/src/x86/ffi_darwin.c Modules/_ctypes/libffi/src/x86/ffitarget.h Modules/_ctypes/libffi/src/x86/sysv.S Modules/_ctypes/libffi/src/x86/unix64.S Modules/_ctypes/libffi/src/x86/win32.S Modules/_ctypes/libffi_msvc/prep_cif.c Modules/_ctypes/libffi_osx Modules/_ctypes/stgdict.c Modules/_curses_panel.c Modules/_cursesmodule.c Modules/_elementtree.c Modules/_fileio.c Modules/_functoolsmodule.c Modules/_hashopenssl.c Modules/_heapqmodule.c Modules/_localemodule.c Modules/_lsprof.c Modules/_randommodule.c Modules/_sqlite/cache.c Modules/_sqlite/connection.c Modules/_sqlite/cursor.c Modules/_sqlite/module.c Modules/_sqlite/prepare_protocol.c Modules/_sqlite/row.c Modules/_sqlite/statement.c Modules/_sqlite/util.c Modules/_sre.c Modules/_ssl.c Modules/_struct.c Modules/_testcapimodule.c Modules/_tkinter.c Modules/_weakref.c Modules/arraymodule.c Modules/audioop.c Modules/binascii.c Modules/bsddb.h Modules/bz2module.c Modules/cStringIO.c Modules/cjkcodecs/_codecs_hk.c Modules/cjkcodecs/_codecs_iso2022.c Modules/cjkcodecs/cjkcodecs.h Modules/cjkcodecs/mappings_hk.h Modules/cjkcodecs/multibytecodec.c Modules/config.c.in Modules/datetimemodule.c Modules/dbmmodule.c Modules/dlmodule.c Modules/errnomodule.c Modules/fcntlmodule.c Modules/gcmodule.c Modules/gdbmmodule.c Modules/grpmodule.c Modules/itertoolsmodule.c Modules/main.c Modules/mathmodule.c Modules/md5module.c Modules/mmapmodule.c Modules/operator.c Modules/ossaudiodev.c Modules/parsermodule.c Modules/posixmodule.c Modules/pwdmodule.c Modules/pyexpat.c Modules/readline.c Modules/resource.c Modules/selectmodule.c Modules/sha1module.c Modules/sha256module.c Modules/sha512module.c Modules/signalmodule.c Modules/socketmodule.c Modules/socketmodule.h Modules/spwdmodule.c Modules/syslogmodule.c Modules/termios.c Modules/threadmodule.c Modules/timemodule.c Modules/unicodedata.c Modules/xxmodule.c Modules/xxsubtype.c Modules/zipimport.c Modules/zlibmodule.c Objects/abstract.c Objects/bytes_methods.c Objects/bytesobject.c Objects/cellobject.c Objects/classobject.c Objects/codeobject.c Objects/complexobject.c Objects/descrobject.c Objects/dictobject.c Objects/doubledigits.c Objects/enumobject.c Objects/exceptions.c Objects/fileobject.c Objects/floatobject.c Objects/frameobject.c Objects/funcobject.c Objects/genobject.c Objects/iterobject.c Objects/listobject.c Objects/longobject.c Objects/memoryobject.c Objects/methodobject.c Objects/moduleobject.c Objects/object.c Objects/rangeobject.c Objects/setobject.c Objects/sliceobject.c Objects/stringlib/README.txt Objects/stringlib/ctype.h Objects/stringlib/eq.h Objects/stringlib/find.h Objects/stringlib/formatter.h Objects/stringlib/string_format.h Objects/stringlib/stringdefs.h Objects/stringlib/transmogrify.h Objects/stringlib/unicodedefs.h Objects/stringobject.c Objects/structseq.c Objects/tupleobject.c Objects/typeobject.c Objects/unicodeobject.c Objects/weakrefobject.c PC/VC6/_msi.dsp PC/VC6/build_ssl.py PC/VC6/pcbuild.dsw PC/VC6/python.dsp PC/VC6/pythoncore.dsp PC/VC6/readme.txt PC/VS7.1 PC/VS8.0 PC/_msi.c PC/_subprocess.c PC/_winreg.c PC/bdist_wininst/install.c PC/config.c PC/dl_nt.c PC/msvcrtmodule.c PC/os2emx/Makefile PC/os2emx/README.os2emx PC/os2emx/config.c PC/os2emx/pyconfig.h PC/os2emx/python25.def PC/os2emx/python26.def PC/os2vacpp/config.c PC/os2vacpp/pyconfig.h PC/pyconfig.h PC/python_nt.rc PC/readme.txt PCbuild PCbuild/_bsddb.vcproj PCbuild/_ctypes.vcproj PCbuild/_ctypes_test.vcproj PCbuild/_elementtree.vcproj PCbuild/_msi.vcproj PCbuild/_socket.vcproj PCbuild/_sqlite3.vcproj PCbuild/_ssl.vcproj PCbuild/_testcapi.vcproj PCbuild/_tkinter.vcproj PCbuild/build_ssl.bat PCbuild/build_ssl.py PCbuild/bz2.vcproj PCbuild/field3.py PCbuild/installer.bmp PCbuild/make_buildinfo.c PCbuild/make_buildinfo.vcproj PCbuild/make_versioninfo.vcproj PCbuild/pcbuild.sln PCbuild/pyexpat.vcproj PCbuild/python.vcproj PCbuild/pythoncore.vcproj PCbuild/pythonw.vcproj PCbuild/readme.txt PCbuild/rmpyc.py PCbuild/rt.bat PCbuild/select.vcproj PCbuild/unicodedata.vcproj PCbuild/w9xpopen.vcproj PCbuild/winsound.vcproj PCbuild8 Parser/asdl.py Parser/asdl_c.py Parser/parser.h Parser/parsetok.c Parser/pgen.c Parser/spark.py Parser/tokenizer.c Parser/tokenizer.h Python/Python-ast.c Python/ast.c Python/bltinmodule.c Python/ceval.c Python/codecs.c Python/compile.c Python/dynload_win.c Python/errors.c Python/frozen.c Python/future.c Python/getargs.c Python/getcopyright.c Python/hypot.c Python/import.c Python/mactoolboxglue.c Python/marshal.c Python/memmove.c Python/modsupport.c Python/mystrtoul.c Python/peephole.c Python/pystate.c Python/pystrcmp.c Python/pystrtod.c Python/pythonrun.c Python/strerror.c Python/strtod.c Python/structmember.c Python/symtable.c Python/sysmodule.c Python/thread.c Python/traceback.c README RELNOTES Tools/bgen/bgen/bgenObjectDefinition.py Tools/buildbot/build-amd64.bat Tools/buildbot/build.bat Tools/buildbot/buildmsi.bat Tools/buildbot/clean-amd64.bat Tools/buildbot/clean.bat Tools/buildbot/external-amd64.bat Tools/buildbot/external-common.bat Tools/buildbot/external.bat Tools/buildbot/kill_python.c Tools/buildbot/test-amd64.bat Tools/faqwiz/faqw.py Tools/freeze/flag.py Tools/freeze/makeconfig.py Tools/i18n/pygettext.py Tools/modulator/Tkextra.py Tools/msi/msi.py Tools/msi/msilib.py Tools/msi/uuids.py Tools/pybench/Setup.py Tools/pybench/With.py Tools/pybench/pybench.py Tools/pybench/systimes.py Tools/pynche/ChipViewer.py Tools/pynche/ColorDB.py Tools/pynche/TypeinViewer.py Tools/scripts Tools/scripts/checkappend.py Tools/scripts/combinerefs.py Tools/scripts/finddiv.py Tools/scripts/h2py.py Tools/scripts/logmerge.py Tools/scripts/nm2def.py Tools/scripts/patchcheck.py Tools/scripts/pindent.py Tools/scripts/pysource.py Tools/scripts/reindent.py Tools/scripts/texcheck.py Tools/scripts/win_add2path.py Tools/scripts/xxci.py Tools/ssl/get-remote-certificate.py Tools/unicode/gencodec.py Tools/unicode/makeunicodedata.py Tools/webchecker/wcgui.py Tools/webchecker/wsgui.py Tools/world/world configure configure.in pyconfig.h.in runtests.sh setup.py

brett.cannon python-3000-checkins at python.org
Thu Mar 27 00:49:12 CET 2008


Author: brett.cannon
Date: Thu Mar 27 00:48:05 2008
New Revision: 61962

Added:
   python/branches/py3k-importlib/Demo/tkinter/guido/brownian2.py
      - copied unchanged from r61829, python/branches/py3k/Demo/tkinter/guido/brownian2.py
   python/branches/py3k-importlib/Doc/c-api/allocation.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/allocation.rst
   python/branches/py3k-importlib/Doc/c-api/arg.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/arg.rst
   python/branches/py3k-importlib/Doc/c-api/bool.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/bool.rst
   python/branches/py3k-importlib/Doc/c-api/buffer.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/buffer.rst
   python/branches/py3k-importlib/Doc/c-api/cell.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/cell.rst
   python/branches/py3k-importlib/Doc/c-api/cobject.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/cobject.rst
   python/branches/py3k-importlib/Doc/c-api/complex.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/complex.rst
   python/branches/py3k-importlib/Doc/c-api/conversion.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/conversion.rst
   python/branches/py3k-importlib/Doc/c-api/datetime.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/datetime.rst
   python/branches/py3k-importlib/Doc/c-api/descriptor.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/descriptor.rst
   python/branches/py3k-importlib/Doc/c-api/dict.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/dict.rst
   python/branches/py3k-importlib/Doc/c-api/file.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/file.rst
   python/branches/py3k-importlib/Doc/c-api/float.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/float.rst
   python/branches/py3k-importlib/Doc/c-api/function.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/function.rst
   python/branches/py3k-importlib/Doc/c-api/gcsupport.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/gcsupport.rst
   python/branches/py3k-importlib/Doc/c-api/gen.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/gen.rst
   python/branches/py3k-importlib/Doc/c-api/import.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/import.rst
   python/branches/py3k-importlib/Doc/c-api/iter.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/iter.rst
   python/branches/py3k-importlib/Doc/c-api/iterator.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/iterator.rst
   python/branches/py3k-importlib/Doc/c-api/list.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/list.rst
   python/branches/py3k-importlib/Doc/c-api/long.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/long.rst
   python/branches/py3k-importlib/Doc/c-api/mapping.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/mapping.rst
   python/branches/py3k-importlib/Doc/c-api/marshal.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/marshal.rst
   python/branches/py3k-importlib/Doc/c-api/method.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/method.rst
   python/branches/py3k-importlib/Doc/c-api/module.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/module.rst
   python/branches/py3k-importlib/Doc/c-api/none.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/none.rst
   python/branches/py3k-importlib/Doc/c-api/number.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/number.rst
   python/branches/py3k-importlib/Doc/c-api/objbuffer.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/objbuffer.rst
   python/branches/py3k-importlib/Doc/c-api/object.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/object.rst
   python/branches/py3k-importlib/Doc/c-api/objimpl.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/objimpl.rst
   python/branches/py3k-importlib/Doc/c-api/reflection.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/reflection.rst
   python/branches/py3k-importlib/Doc/c-api/sequence.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/sequence.rst
   python/branches/py3k-importlib/Doc/c-api/set.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/set.rst
   python/branches/py3k-importlib/Doc/c-api/slice.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/slice.rst
   python/branches/py3k-importlib/Doc/c-api/string.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/string.rst
   python/branches/py3k-importlib/Doc/c-api/structures.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/structures.rst
   python/branches/py3k-importlib/Doc/c-api/sys.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/sys.rst
   python/branches/py3k-importlib/Doc/c-api/tuple.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/tuple.rst
   python/branches/py3k-importlib/Doc/c-api/type.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/type.rst
   python/branches/py3k-importlib/Doc/c-api/typeobj.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/typeobj.rst
   python/branches/py3k-importlib/Doc/c-api/unicode.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/unicode.rst
   python/branches/py3k-importlib/Doc/c-api/weakref.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/c-api/weakref.rst
   python/branches/py3k-importlib/Doc/includes/email-alternative.py
      - copied unchanged from r61829, python/branches/py3k/Doc/includes/email-alternative.py
   python/branches/py3k-importlib/Doc/library/builtins.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/library/builtins.rst
   python/branches/py3k-importlib/Doc/library/fractions.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/library/fractions.rst
   python/branches/py3k-importlib/Doc/library/future_builtins.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/library/future_builtins.rst
   python/branches/py3k-importlib/Doc/library/numbers.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/library/numbers.rst
   python/branches/py3k-importlib/Doc/library/plistlib.rst
      - copied unchanged from r61829, python/branches/py3k/Doc/library/plistlib.rst
   python/branches/py3k-importlib/Doc/make.bat
      - copied unchanged from r61829, python/branches/py3k/Doc/make.bat
   python/branches/py3k-importlib/Doc/tools/sphinxext/   (props changed)
      - copied from r61829, python/branches/py3k/Doc/tools/sphinxext/
   python/branches/py3k-importlib/Doc/using/
      - copied from r61829, python/branches/py3k/Doc/using/
   python/branches/py3k-importlib/Include/bytes_methods.h
      - copied unchanged from r61829, python/branches/py3k/Include/bytes_methods.h
   python/branches/py3k-importlib/Include/pystrcmp.h
      - copied unchanged from r61829, python/branches/py3k/Include/pystrcmp.h
   python/branches/py3k-importlib/Lib/_markupbase.py
      - copied unchanged from r61829, python/branches/py3k/Lib/_markupbase.py
   python/branches/py3k-importlib/Lib/_weakrefset.py
      - copied unchanged from r61829, python/branches/py3k/Lib/_weakrefset.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_delattr.py
      - copied unchanged from r61829, python/branches/py3k/Lib/ctypes/test/test_delattr.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_pickling.py
      - copied unchanged from r61829, python/branches/py3k/Lib/ctypes/test/test_pickling.py
   python/branches/py3k-importlib/Lib/distutils/command/wininst-6.0.exe
      - copied unchanged from r61829, python/branches/py3k/Lib/distutils/command/wininst-6.0.exe
   python/branches/py3k-importlib/Lib/distutils/command/wininst-8.0.exe
      - copied unchanged from r61829, python/branches/py3k/Lib/distutils/command/wininst-8.0.exe
   python/branches/py3k-importlib/Lib/distutils/command/wininst-9.0.exe
      - copied unchanged from r61829, python/branches/py3k/Lib/distutils/command/wininst-9.0.exe
   python/branches/py3k-importlib/Lib/distutils/msvc9compiler.py
      - copied unchanged from r61829, python/branches/py3k/Lib/distutils/msvc9compiler.py
   python/branches/py3k-importlib/Lib/distutils/tests/test_sysconfig.py
      - copied unchanged from r61829, python/branches/py3k/Lib/distutils/tests/test_sysconfig.py
   python/branches/py3k-importlib/Lib/fractions.py
      - copied unchanged from r61829, python/branches/py3k/Lib/fractions.py
   python/branches/py3k-importlib/Lib/idlelib/tabbedpages.py
      - copied unchanged from r61829, python/branches/py3k/Lib/idlelib/tabbedpages.py
   python/branches/py3k-importlib/Lib/lib2to3/   (props changed)
      - copied from r61829, python/branches/py3k/Lib/lib2to3/
   python/branches/py3k-importlib/Lib/plat-freebsd8/   (props changed)
      - copied from r61829, python/branches/py3k/Lib/plat-freebsd8/
   python/branches/py3k-importlib/Lib/plistlib.py
      - copied unchanged from r61829, python/branches/py3k/Lib/plistlib.py
   python/branches/py3k-importlib/Lib/test/buffer_tests.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/buffer_tests.py
   python/branches/py3k-importlib/Lib/test/crashers/multithreaded_close.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/crashers/multithreaded_close.py
   python/branches/py3k-importlib/Lib/test/curses_tests.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/curses_tests.py
   python/branches/py3k-importlib/Lib/test/floating_points.txt
      - copied unchanged from r61829, python/branches/py3k/Lib/test/floating_points.txt
   python/branches/py3k-importlib/Lib/test/profilee.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/profilee.py
   python/branches/py3k-importlib/Lib/test/randv2_32.pck
      - copied unchanged from r61829, python/branches/py3k/Lib/test/randv2_32.pck
   python/branches/py3k-importlib/Lib/test/randv2_64.pck
      - copied unchanged from r61829, python/branches/py3k/Lib/test/randv2_64.pck
   python/branches/py3k-importlib/Lib/test/randv3.pck
      - copied unchanged from r61829, python/branches/py3k/Lib/test/randv3.pck
   python/branches/py3k-importlib/Lib/test/relimport.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/relimport.py
   python/branches/py3k-importlib/Lib/test/svn_python_org_https_cert.pem
      - copied unchanged from r61829, python/branches/py3k/Lib/test/svn_python_org_https_cert.pem
   python/branches/py3k-importlib/Lib/test/test_SimpleHTTPServer.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_SimpleHTTPServer.py
   python/branches/py3k-importlib/Lib/test/test_cmd.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_cmd.py
   python/branches/py3k-importlib/Lib/test/test_cmd_line_script.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_cmd_line_script.py
   python/branches/py3k-importlib/Lib/test/test_docxmlrpc.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_docxmlrpc.py
   python/branches/py3k-importlib/Lib/test/test_epoll.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_epoll.py
   python/branches/py3k-importlib/Lib/test/test_fractions.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_fractions.py
   python/branches/py3k-importlib/Lib/test/test_int_literal.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_int_literal.py
   python/branches/py3k-importlib/Lib/test/test_kqueue.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_kqueue.py
   python/branches/py3k-importlib/Lib/test/test_memoryview.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_memoryview.py
   python/branches/py3k-importlib/Lib/test/test_mutex.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_mutex.py
   python/branches/py3k-importlib/Lib/test/test_print.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_print.py
   python/branches/py3k-importlib/Lib/test/test_property.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_property.py
   python/branches/py3k-importlib/Lib/test/test_pstats.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_pstats.py
   python/branches/py3k-importlib/Lib/test/test_strlit.py
      - copied unchanged from r61829, python/branches/py3k/Lib/test/test_strlit.py
   python/branches/py3k-importlib/Lib/test/tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt
      - copied unchanged from r61829, python/branches/py3k/Lib/test/tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt
   python/branches/py3k-importlib/Lib/test/tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt
      - copied unchanged from r61829, python/branches/py3k/Lib/test/tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt
   python/branches/py3k-importlib/Lib/test/tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt
      - copied unchanged from r61829, python/branches/py3k/Lib/test/tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt
   python/branches/py3k-importlib/Lib/test/tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt
      - copied unchanged from r61829, python/branches/py3k/Lib/test/tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt
   python/branches/py3k-importlib/Modules/_ctypes/libffi/Makefile.am
      - copied unchanged from r61829, python/branches/py3k/Modules/_ctypes/libffi/Makefile.am
   python/branches/py3k-importlib/Modules/_ctypes/libffi/Makefile.in
      - copied unchanged from r61829, python/branches/py3k/Modules/_ctypes/libffi/Makefile.in
   python/branches/py3k-importlib/Modules/_ctypes/libffi/acinclude.m4
      - copied unchanged from r61829, python/branches/py3k/Modules/_ctypes/libffi/acinclude.m4
   python/branches/py3k-importlib/Modules/_ctypes/libffi/configure.host
      - copied unchanged from r61829, python/branches/py3k/Modules/_ctypes/libffi/configure.host
   python/branches/py3k-importlib/Modules/_ctypes/libffi/include/Makefile.am
      - copied unchanged from r61829, python/branches/py3k/Modules/_ctypes/libffi/include/Makefile.am
   python/branches/py3k-importlib/Modules/_ctypes/libffi/include/Makefile.in
      - copied unchanged from r61829, python/branches/py3k/Modules/_ctypes/libffi/include/Makefile.in
   python/branches/py3k-importlib/Modules/_ctypes/libffi/libffi.pc.in
      - copied unchanged from r61829, python/branches/py3k/Modules/_ctypes/libffi/libffi.pc.in
   python/branches/py3k-importlib/Modules/_ctypes/libffi/missing
      - copied unchanged from r61829, python/branches/py3k/Modules/_ctypes/libffi/missing
   python/branches/py3k-importlib/Modules/_ctypes/libffi_osx/
      - copied from r61829, python/branches/py3k/Modules/_ctypes/libffi_osx/
   python/branches/py3k-importlib/Modules/bsddb.h
      - copied unchanged from r61829, python/branches/py3k/Modules/bsddb.h
   python/branches/py3k-importlib/Objects/bytes_methods.c
      - copied unchanged from r61829, python/branches/py3k/Objects/bytes_methods.c
   python/branches/py3k-importlib/Objects/doubledigits.c
      - copied unchanged from r61829, python/branches/py3k/Objects/doubledigits.c
   python/branches/py3k-importlib/Objects/stringlib/ctype.h
      - copied unchanged from r61829, python/branches/py3k/Objects/stringlib/ctype.h
   python/branches/py3k-importlib/Objects/stringlib/eq.h
      - copied unchanged from r61829, python/branches/py3k/Objects/stringlib/eq.h
   python/branches/py3k-importlib/Objects/stringlib/transmogrify.h
      - copied unchanged from r61829, python/branches/py3k/Objects/stringlib/transmogrify.h
   python/branches/py3k-importlib/PC/VC6/_msi.dsp
      - copied unchanged from r61829, python/branches/py3k/PC/VC6/_msi.dsp
   python/branches/py3k-importlib/PC/VS7.1/   (props changed)
      - copied from r61829, python/branches/py3k/PC/VS7.1/
   python/branches/py3k-importlib/PC/VS8.0/   (props changed)
      - copied from r61829, python/branches/py3k/PC/VS8.0/
   python/branches/py3k-importlib/PC/os2emx/python26.def
      - copied unchanged from r61829, python/branches/py3k/PC/os2emx/python26.def
   python/branches/py3k-importlib/PCbuild/   (props changed)
      - copied from r61829, python/branches/py3k/PCbuild/
   python/branches/py3k-importlib/PCbuild/_bsddb.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/_bsddb.vcproj
   python/branches/py3k-importlib/PCbuild/_ctypes.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/_ctypes.vcproj
   python/branches/py3k-importlib/PCbuild/_ctypes_test.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/_ctypes_test.vcproj
   python/branches/py3k-importlib/PCbuild/_elementtree.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/_elementtree.vcproj
   python/branches/py3k-importlib/PCbuild/_msi.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/_msi.vcproj
   python/branches/py3k-importlib/PCbuild/_socket.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/_socket.vcproj
   python/branches/py3k-importlib/PCbuild/_sqlite3.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/_sqlite3.vcproj
   python/branches/py3k-importlib/PCbuild/_ssl.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/_ssl.vcproj
   python/branches/py3k-importlib/PCbuild/_testcapi.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/_testcapi.vcproj
   python/branches/py3k-importlib/PCbuild/_tkinter.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/_tkinter.vcproj
   python/branches/py3k-importlib/PCbuild/build_ssl.bat
      - copied unchanged from r61829, python/branches/py3k/PCbuild/build_ssl.bat
   python/branches/py3k-importlib/PCbuild/build_ssl.py
      - copied unchanged from r61829, python/branches/py3k/PCbuild/build_ssl.py
   python/branches/py3k-importlib/PCbuild/bz2.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/bz2.vcproj
   python/branches/py3k-importlib/PCbuild/field3.py
      - copied unchanged from r61829, python/branches/py3k/PCbuild/field3.py
   python/branches/py3k-importlib/PCbuild/installer.bmp
      - copied unchanged from r61829, python/branches/py3k/PCbuild/installer.bmp
   python/branches/py3k-importlib/PCbuild/make_buildinfo.c
      - copied unchanged from r61829, python/branches/py3k/PCbuild/make_buildinfo.c
   python/branches/py3k-importlib/PCbuild/make_buildinfo.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/make_buildinfo.vcproj
   python/branches/py3k-importlib/PCbuild/make_versioninfo.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/make_versioninfo.vcproj
   python/branches/py3k-importlib/PCbuild/pcbuild.sln
      - copied unchanged from r61829, python/branches/py3k/PCbuild/pcbuild.sln
   python/branches/py3k-importlib/PCbuild/pyexpat.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/pyexpat.vcproj
   python/branches/py3k-importlib/PCbuild/python.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/python.vcproj
   python/branches/py3k-importlib/PCbuild/pythoncore.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/pythoncore.vcproj
   python/branches/py3k-importlib/PCbuild/pythonw.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/pythonw.vcproj
   python/branches/py3k-importlib/PCbuild/readme.txt
      - copied unchanged from r61829, python/branches/py3k/PCbuild/readme.txt
   python/branches/py3k-importlib/PCbuild/rmpyc.py
      - copied unchanged from r61829, python/branches/py3k/PCbuild/rmpyc.py
   python/branches/py3k-importlib/PCbuild/rt.bat
      - copied unchanged from r61829, python/branches/py3k/PCbuild/rt.bat
   python/branches/py3k-importlib/PCbuild/select.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/select.vcproj
   python/branches/py3k-importlib/PCbuild/unicodedata.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/unicodedata.vcproj
   python/branches/py3k-importlib/PCbuild/w9xpopen.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/w9xpopen.vcproj
   python/branches/py3k-importlib/PCbuild/winsound.vcproj
      - copied unchanged from r61829, python/branches/py3k/PCbuild/winsound.vcproj
   python/branches/py3k-importlib/Python/pystrcmp.c
      - copied unchanged from r61829, python/branches/py3k/Python/pystrcmp.c
   python/branches/py3k-importlib/Tools/buildbot/external-common.bat
      - copied unchanged from r61829, python/branches/py3k/Tools/buildbot/external-common.bat
   python/branches/py3k-importlib/Tools/freeze/flag.py
      - copied unchanged from r61829, python/branches/py3k/Tools/freeze/flag.py
   python/branches/py3k-importlib/Tools/pybench/With.py
      - copied unchanged from r61829, python/branches/py3k/Tools/pybench/With.py
   python/branches/py3k-importlib/Tools/scripts/patchcheck.py
      - copied unchanged from r61829, python/branches/py3k/Tools/scripts/patchcheck.py
   python/branches/py3k-importlib/Tools/scripts/win_add2path.py
      - copied unchanged from r61829, python/branches/py3k/Tools/scripts/win_add2path.py
Removed:
   python/branches/py3k-importlib/Demo/classes/Rat.py
   python/branches/py3k-importlib/Doc/c-api/newtypes.rst
   python/branches/py3k-importlib/Doc/howto/pythonmac.rst
   python/branches/py3k-importlib/Doc/library/__builtin__.rst
   python/branches/py3k-importlib/Doc/library/new.rst
   python/branches/py3k-importlib/Doc/library/userdict.rst
   python/branches/py3k-importlib/Lib/UserDict.py
   python/branches/py3k-importlib/Lib/UserList.py
   python/branches/py3k-importlib/Lib/UserString.py
   python/branches/py3k-importlib/Lib/distutils/command/wininst-6.exe
   python/branches/py3k-importlib/Lib/distutils/command/wininst-8.exe
   python/branches/py3k-importlib/Lib/encodings/bz2_codec.py
   python/branches/py3k-importlib/Lib/idlelib/tabpage.py
   python/branches/py3k-importlib/Lib/markupbase.py
   python/branches/py3k-importlib/Lib/new.py
   python/branches/py3k-importlib/Lib/plat-mac/plistlib.py
   python/branches/py3k-importlib/Lib/test/crashers/file_threads.py
   python/branches/py3k-importlib/Lib/test/crashers/loosing_dict_ref.py
   python/branches/py3k-importlib/Lib/test/crashers/weakref_in_del.py
   python/branches/py3k-importlib/Lib/test/output/
   python/branches/py3k-importlib/Lib/test/test_hexoct.py
   python/branches/py3k-importlib/Lib/test/test_new.py
   python/branches/py3k-importlib/Lib/test/test_socket_ssl.py
   python/branches/py3k-importlib/Lib/test/test_str.py
   python/branches/py3k-importlib/Lib/test/testall.py
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffi_darwin.c
   python/branches/py3k-importlib/PC/os2emx/python25.def
   python/branches/py3k-importlib/PCbuild8/
   python/branches/py3k-importlib/Python/memmove.c
   python/branches/py3k-importlib/Python/strerror.c
   python/branches/py3k-importlib/Tools/scripts/texcheck.py
Modified:
   python/branches/py3k-importlib/   (props changed)
   python/branches/py3k-importlib/Demo/classes/README
   python/branches/py3k-importlib/Demo/classes/Range.py
   python/branches/py3k-importlib/Demo/curses/repeat.py
   python/branches/py3k-importlib/Demo/embed/demo.c
   python/branches/py3k-importlib/Demo/imputil/knee.py
   python/branches/py3k-importlib/Demo/newmetaclasses/Eiffel.py
   python/branches/py3k-importlib/Demo/pdist/client.py
   python/branches/py3k-importlib/Demo/pdist/cvslock.py
   python/branches/py3k-importlib/Demo/scripts/toaiff.py
   python/branches/py3k-importlib/Demo/tkinter/guido/ShellWindow.py
   python/branches/py3k-importlib/Doc/ACKS.txt   (contents, props changed)
   python/branches/py3k-importlib/Doc/Makefile   (contents, props changed)
   python/branches/py3k-importlib/Doc/README.txt   (contents, props changed)
   python/branches/py3k-importlib/Doc/TODO.txt   (props changed)
   python/branches/py3k-importlib/Doc/about.rst   (props changed)
   python/branches/py3k-importlib/Doc/bugs.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/c-api/abstract.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/c-api/concrete.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/c-api/exceptions.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/c-api/index.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/c-api/init.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/c-api/intro.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/c-api/memory.rst   (props changed)
   python/branches/py3k-importlib/Doc/c-api/refcounting.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/c-api/utilities.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/c-api/veryhigh.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/conf.py   (contents, props changed)
   python/branches/py3k-importlib/Doc/contents.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/copyright.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/data/refcounts.dat
   python/branches/py3k-importlib/Doc/distutils/apiref.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/distutils/builtdist.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/distutils/commandref.rst   (props changed)
   python/branches/py3k-importlib/Doc/distutils/configfile.rst   (props changed)
   python/branches/py3k-importlib/Doc/distutils/examples.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/distutils/extending.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/distutils/index.rst   (props changed)
   python/branches/py3k-importlib/Doc/distutils/introduction.rst   (props changed)
   python/branches/py3k-importlib/Doc/distutils/packageindex.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/distutils/setupscript.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/distutils/sourcedist.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/distutils/uploading.rst   (props changed)
   python/branches/py3k-importlib/Doc/documenting/fromlatex.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/documenting/index.rst   (props changed)
   python/branches/py3k-importlib/Doc/documenting/intro.rst   (props changed)
   python/branches/py3k-importlib/Doc/documenting/markup.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/documenting/rest.rst   (props changed)
   python/branches/py3k-importlib/Doc/documenting/sphinx.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/documenting/style.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/extending/building.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/extending/embedding.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/extending/extending.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/extending/index.rst   (props changed)
   python/branches/py3k-importlib/Doc/extending/newtypes.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/extending/windows.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/glossary.rst
   python/branches/py3k-importlib/Doc/howto/advocacy.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/howto/curses.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/howto/doanddont.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/howto/functional.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/howto/index.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/howto/regex.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/howto/sockets.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/howto/unicode.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/howto/urllib2.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/includes/email-dir.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/email-mime.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/email-simple.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/email-unpack.py   (contents, props changed)
   python/branches/py3k-importlib/Doc/includes/minidom-example.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/noddy2.c
   python/branches/py3k-importlib/Doc/includes/noddy3.c
   python/branches/py3k-importlib/Doc/includes/noddy4.c
   python/branches/py3k-importlib/Doc/includes/run-func.c
   python/branches/py3k-importlib/Doc/includes/setup.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/shoddy.c
   python/branches/py3k-importlib/Doc/includes/sqlite3/adapter_datetime.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/adapter_point_1.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/adapter_point_2.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/collation_reverse.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/complete_statement.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/connect_db_1.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/connect_db_2.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/converter_point.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/countcursors.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/createdb.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/execsql_fetchonerow.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/execsql_printall_1.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/execute_1.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/execute_2.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/execute_3.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/executemany_1.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/executemany_2.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/executescript.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/insert_more_people.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/md5func.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/mysumaggr.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/parse_colnames.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/pysqlite_datetime.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/row_factory.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/rowclass.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/shared_cache.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/shortcut_methods.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/simple_tableprinter.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/sqlite3/text_factory.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/test.py   (props changed)
   python/branches/py3k-importlib/Doc/includes/tzinfo-examples.py   (props changed)
   python/branches/py3k-importlib/Doc/install/index.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/__future__.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/__main__.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/_ast.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/_winreg.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/abc.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/aepack.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/aetools.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/aetypes.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/aifc.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/allos.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/anydbm.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/archiving.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/array.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/asynchat.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/asyncore.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/atexit.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/audioop.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/autogil.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/base64.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/basehttpserver.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/bdb.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/binascii.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/binhex.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/bisect.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/bsddb.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/bz2.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/calendar.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/carbon.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/cgi.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/cgihttpserver.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/cgitb.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/chunk.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/cmath.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/cmd.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/code.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/codecs.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/codeop.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/collections.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/colorpicker.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/colorsys.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/commands.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/compileall.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/configparser.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/constants.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/contextlib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/cookie.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/cookielib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/copy.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/copy_reg.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/crypt.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/crypto.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/csv.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/ctypes.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/curses.ascii.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/curses.panel.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/curses.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/custominterp.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/datatypes.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/datetime.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/dbhash.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/dbm.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/debug.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/decimal.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/development.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/difflib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/dircache.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/dis.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/distutils.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/dl.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/doctest.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/docxmlrpcserver.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/dumbdbm.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/dummy_thread.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/dummy_threading.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/easydialogs.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/email-examples.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/email.charset.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/email.encoders.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/email.errors.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/email.generator.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/email.header.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/email.iterators.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/email.message.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/email.mime.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/email.parser.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/email.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/email.util.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/errno.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/exceptions.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/fcntl.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/filecmp.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/fileformats.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/fileinput.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/filesys.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/fnmatch.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/formatter.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/fpectl.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/fpformat.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/framework.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/frameworks.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/ftplib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/functions.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/functools.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/gc.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/gdbm.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/gensuitemodule.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/getopt.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/getpass.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/gettext.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/glob.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/grp.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/gzip.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/hashlib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/heapq.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/hmac.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/htmllib.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/htmlparser.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/httplib.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/i18n.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/ic.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/idle.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/imaplib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/imghdr.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/imp.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/imputil.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/index.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/inspect.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/internet.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/intro.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/ipc.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/itertools.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/keyword.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/language.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/linecache.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/locale.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/logging.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/mac.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/macos.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/macosa.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/macostools.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/macpath.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/mailbox.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/mailcap.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/markup.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/marshal.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/math.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/mhlib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/mimetools.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/mimetypes.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/miniaeframe.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/misc.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/mm.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/mmap.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/modulefinder.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/modules.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/msilib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/msvcrt.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/multifile.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/mutex.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/netdata.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/netrc.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/nis.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/nntplib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/numeric.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/objects.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/operator.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/optparse.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/os.path.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/os.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/ossaudiodev.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/othergui.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/parser.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/pdb.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/persistence.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/pickle.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/pickletools.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/pipes.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/pkgutil.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/platform.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/poplib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/posix.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/pprint.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/profile.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/pty.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/pwd.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/py_compile.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/pyclbr.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/pydoc.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/pyexpat.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/python.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/queue.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/quopri.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/random.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/re.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/readline.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/repr.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/resource.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/rfc822.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/rlcompleter.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/robotparser.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/runpy.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/sched.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/scrolledtext.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/select.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/sgmllib.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/shelve.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/shlex.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/shutil.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/signal.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/simplehttpserver.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/simplexmlrpcserver.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/site.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/smtpd.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/smtplib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/sndhdr.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/socket.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/socketserver.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/someos.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/spwd.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/sqlite3.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/ssl.rst
   python/branches/py3k-importlib/Doc/library/stat.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/statvfs.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/stdtypes.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/string.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/stringio.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/stringprep.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/strings.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/struct.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/subprocess.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/sunau.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/symbol.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/sys.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/syslog.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/tabnanny.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/tarfile.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/telnetlib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/tempfile.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/termios.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/test.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/textwrap.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/thread.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/threading.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/time.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/timeit.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/tix.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/tk.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/tkinter.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/token.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/tokenize.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/trace.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/traceback.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/tty.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/turtle.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/types.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/undoc.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/unicodedata.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/unittest.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/unix.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/urllib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/urllib2.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/urlparse.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/user.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/uu.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/uuid.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/warnings.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/wave.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/weakref.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/webbrowser.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/whichdb.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/windows.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/winsound.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/wsgiref.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/xdrlib.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/xml.dom.minidom.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/xml.dom.pulldom.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/xml.dom.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/xml.etree.elementtree.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/xml.etree.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/xml.sax.handler.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/xml.sax.reader.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/xml.sax.rst   (props changed)
   python/branches/py3k-importlib/Doc/library/xml.sax.utils.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/xmlrpclib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/zipfile.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/zipimport.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/library/zlib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/license.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/reference/compound_stmts.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/reference/datamodel.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/reference/executionmodel.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/reference/expressions.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/reference/index.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/reference/introduction.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/reference/lexical_analysis.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/reference/simple_stmts.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/reference/toplevel_components.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tools/sphinx-build.py   (contents, props changed)
   python/branches/py3k-importlib/Doc/tools/sphinx-web.py   (props changed)
   python/branches/py3k-importlib/Doc/tutorial/appetite.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tutorial/classes.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tutorial/controlflow.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tutorial/datastructures.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tutorial/errors.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tutorial/floatingpoint.rst   (props changed)
   python/branches/py3k-importlib/Doc/tutorial/index.rst   (props changed)
   python/branches/py3k-importlib/Doc/tutorial/inputoutput.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tutorial/interactive.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tutorial/interpreter.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tutorial/introduction.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tutorial/modules.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tutorial/stdlib.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tutorial/stdlib2.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/tutorial/whatnow.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/whatsnew/2.0.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/whatsnew/2.1.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/whatsnew/2.2.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/whatsnew/2.3.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/whatsnew/2.4.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/whatsnew/2.5.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/whatsnew/2.6.rst   (contents, props changed)
   python/branches/py3k-importlib/Doc/whatsnew/3.0.rst   (contents, props changed)
   python/branches/py3k-importlib/Include/Python.h
   python/branches/py3k-importlib/Include/abstract.h
   python/branches/py3k-importlib/Include/boolobject.h
   python/branches/py3k-importlib/Include/bytesobject.h
   python/branches/py3k-importlib/Include/cStringIO.h
   python/branches/py3k-importlib/Include/cellobject.h
   python/branches/py3k-importlib/Include/ceval.h
   python/branches/py3k-importlib/Include/classobject.h
   python/branches/py3k-importlib/Include/cobject.h
   python/branches/py3k-importlib/Include/code.h
   python/branches/py3k-importlib/Include/compile.h
   python/branches/py3k-importlib/Include/complexobject.h
   python/branches/py3k-importlib/Include/datetime.h
   python/branches/py3k-importlib/Include/descrobject.h
   python/branches/py3k-importlib/Include/dictobject.h
   python/branches/py3k-importlib/Include/fileobject.h
   python/branches/py3k-importlib/Include/floatobject.h
   python/branches/py3k-importlib/Include/frameobject.h
   python/branches/py3k-importlib/Include/funcobject.h
   python/branches/py3k-importlib/Include/genobject.h
   python/branches/py3k-importlib/Include/import.h
   python/branches/py3k-importlib/Include/intobject.h
   python/branches/py3k-importlib/Include/iterobject.h
   python/branches/py3k-importlib/Include/listobject.h
   python/branches/py3k-importlib/Include/longobject.h
   python/branches/py3k-importlib/Include/memoryobject.h
   python/branches/py3k-importlib/Include/methodobject.h
   python/branches/py3k-importlib/Include/modsupport.h
   python/branches/py3k-importlib/Include/moduleobject.h
   python/branches/py3k-importlib/Include/object.h
   python/branches/py3k-importlib/Include/objimpl.h
   python/branches/py3k-importlib/Include/opcode.h
   python/branches/py3k-importlib/Include/patchlevel.h
   python/branches/py3k-importlib/Include/py_curses.h
   python/branches/py3k-importlib/Include/pydebug.h
   python/branches/py3k-importlib/Include/pyerrors.h
   python/branches/py3k-importlib/Include/pyport.h
   python/branches/py3k-importlib/Include/pythonrun.h
   python/branches/py3k-importlib/Include/rangeobject.h
   python/branches/py3k-importlib/Include/setobject.h
   python/branches/py3k-importlib/Include/sliceobject.h
   python/branches/py3k-importlib/Include/stringobject.h
   python/branches/py3k-importlib/Include/structmember.h
   python/branches/py3k-importlib/Include/symtable.h
   python/branches/py3k-importlib/Include/traceback.h
   python/branches/py3k-importlib/Include/tupleobject.h
   python/branches/py3k-importlib/Include/unicodeobject.h
   python/branches/py3k-importlib/Include/weakrefobject.h
   python/branches/py3k-importlib/LICENSE
   python/branches/py3k-importlib/Lib/BaseHTTPServer.py
   python/branches/py3k-importlib/Lib/ConfigParser.py
   python/branches/py3k-importlib/Lib/DocXMLRPCServer.py
   python/branches/py3k-importlib/Lib/HTMLParser.py
   python/branches/py3k-importlib/Lib/Queue.py
   python/branches/py3k-importlib/Lib/SimpleHTTPServer.py
   python/branches/py3k-importlib/Lib/SimpleXMLRPCServer.py
   python/branches/py3k-importlib/Lib/SocketServer.py
   python/branches/py3k-importlib/Lib/__future__.py
   python/branches/py3k-importlib/Lib/_abcoll.py
   python/branches/py3k-importlib/Lib/_strptime.py
   python/branches/py3k-importlib/Lib/abc.py
   python/branches/py3k-importlib/Lib/aifc.py
   python/branches/py3k-importlib/Lib/asyncore.py
   python/branches/py3k-importlib/Lib/base64.py
   python/branches/py3k-importlib/Lib/binhex.py
   python/branches/py3k-importlib/Lib/bsddb/__init__.py
   python/branches/py3k-importlib/Lib/bsddb/dbobj.py
   python/branches/py3k-importlib/Lib/bsddb/dbshelve.py
   python/branches/py3k-importlib/Lib/bsddb/dbtables.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_1413192.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_associate.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_basics.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_compare.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_cursor_pget_bug.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_dbobj.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_dbshelve.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_dbtables.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_env_close.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_join.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_lock.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_misc.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_pickle.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_recno.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_sequence.py
   python/branches/py3k-importlib/Lib/bsddb/test/test_thread.py
   python/branches/py3k-importlib/Lib/cProfile.py
   python/branches/py3k-importlib/Lib/calendar.py
   python/branches/py3k-importlib/Lib/cgi.py
   python/branches/py3k-importlib/Lib/cmd.py
   python/branches/py3k-importlib/Lib/code.py
   python/branches/py3k-importlib/Lib/codecs.py
   python/branches/py3k-importlib/Lib/collections.py
   python/branches/py3k-importlib/Lib/compileall.py
   python/branches/py3k-importlib/Lib/contextlib.py
   python/branches/py3k-importlib/Lib/cookielib.py
   python/branches/py3k-importlib/Lib/copy.py
   python/branches/py3k-importlib/Lib/copy_reg.py
   python/branches/py3k-importlib/Lib/csv.py
   python/branches/py3k-importlib/Lib/ctypes/__init__.py
   python/branches/py3k-importlib/Lib/ctypes/test/__init__.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_array_in_pointer.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_arrays.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_buffers.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_byteswap.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_callbacks.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_cfuncs.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_checkretval.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_find.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_functions.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_libc.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_memfunctions.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_numbers.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_prototypes.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_python_api.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_returnfuncptrs.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_slicing.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_strings.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_structures.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_unicode.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_values.py
   python/branches/py3k-importlib/Lib/ctypes/util.py
   python/branches/py3k-importlib/Lib/curses/__init__.py
   python/branches/py3k-importlib/Lib/curses/textpad.py
   python/branches/py3k-importlib/Lib/curses/wrapper.py
   python/branches/py3k-importlib/Lib/decimal.py
   python/branches/py3k-importlib/Lib/difflib.py
   python/branches/py3k-importlib/Lib/dis.py
   python/branches/py3k-importlib/Lib/distutils/__init__.py
   python/branches/py3k-importlib/Lib/distutils/bcppcompiler.py
   python/branches/py3k-importlib/Lib/distutils/ccompiler.py
   python/branches/py3k-importlib/Lib/distutils/cmd.py
   python/branches/py3k-importlib/Lib/distutils/command/bdist_dumb.py
   python/branches/py3k-importlib/Lib/distutils/command/bdist_rpm.py
   python/branches/py3k-importlib/Lib/distutils/command/bdist_wininst.py
   python/branches/py3k-importlib/Lib/distutils/command/build.py
   python/branches/py3k-importlib/Lib/distutils/command/build_clib.py
   python/branches/py3k-importlib/Lib/distutils/command/build_ext.py
   python/branches/py3k-importlib/Lib/distutils/command/build_py.py
   python/branches/py3k-importlib/Lib/distutils/command/build_scripts.py
   python/branches/py3k-importlib/Lib/distutils/command/config.py
   python/branches/py3k-importlib/Lib/distutils/command/install.py
   python/branches/py3k-importlib/Lib/distutils/command/install_data.py
   python/branches/py3k-importlib/Lib/distutils/command/install_headers.py
   python/branches/py3k-importlib/Lib/distutils/command/register.py
   python/branches/py3k-importlib/Lib/distutils/command/sdist.py
   python/branches/py3k-importlib/Lib/distutils/cygwinccompiler.py
   python/branches/py3k-importlib/Lib/distutils/dir_util.py
   python/branches/py3k-importlib/Lib/distutils/dist.py
   python/branches/py3k-importlib/Lib/distutils/extension.py
   python/branches/py3k-importlib/Lib/distutils/fancy_getopt.py
   python/branches/py3k-importlib/Lib/distutils/file_util.py
   python/branches/py3k-importlib/Lib/distutils/filelist.py
   python/branches/py3k-importlib/Lib/distutils/msvccompiler.py
   python/branches/py3k-importlib/Lib/distutils/spawn.py
   python/branches/py3k-importlib/Lib/distutils/sysconfig.py
   python/branches/py3k-importlib/Lib/distutils/tests/test_dist.py
   python/branches/py3k-importlib/Lib/distutils/unixccompiler.py
   python/branches/py3k-importlib/Lib/distutils/util.py
   python/branches/py3k-importlib/Lib/doctest.py
   python/branches/py3k-importlib/Lib/dumbdbm.py
   python/branches/py3k-importlib/Lib/email/base64mime.py
   python/branches/py3k-importlib/Lib/email/feedparser.py
   python/branches/py3k-importlib/Lib/email/generator.py
   python/branches/py3k-importlib/Lib/email/iterators.py
   python/branches/py3k-importlib/Lib/email/mime/multipart.py
   python/branches/py3k-importlib/Lib/email/test/data/msg_15.txt
   python/branches/py3k-importlib/Lib/email/test/test_email.py
   python/branches/py3k-importlib/Lib/encodings/__init__.py
   python/branches/py3k-importlib/Lib/encodings/aliases.py
   python/branches/py3k-importlib/Lib/encodings/idna.py
   python/branches/py3k-importlib/Lib/encodings/punycode.py
   python/branches/py3k-importlib/Lib/encodings/utf_7.py
   python/branches/py3k-importlib/Lib/encodings/utf_8_sig.py
   python/branches/py3k-importlib/Lib/filecmp.py
   python/branches/py3k-importlib/Lib/fileinput.py
   python/branches/py3k-importlib/Lib/formatter.py
   python/branches/py3k-importlib/Lib/ftplib.py
   python/branches/py3k-importlib/Lib/getpass.py
   python/branches/py3k-importlib/Lib/gettext.py
   python/branches/py3k-importlib/Lib/glob.py
   python/branches/py3k-importlib/Lib/gzip.py
   python/branches/py3k-importlib/Lib/hashlib.py
   python/branches/py3k-importlib/Lib/heapq.py
   python/branches/py3k-importlib/Lib/hmac.py
   python/branches/py3k-importlib/Lib/htmlentitydefs.py
   python/branches/py3k-importlib/Lib/httplib.py
   python/branches/py3k-importlib/Lib/idlelib/AutoComplete.py
   python/branches/py3k-importlib/Lib/idlelib/AutoCompleteWindow.py
   python/branches/py3k-importlib/Lib/idlelib/CallTips.py
   python/branches/py3k-importlib/Lib/idlelib/CodeContext.py
   python/branches/py3k-importlib/Lib/idlelib/ColorDelegator.py
   python/branches/py3k-importlib/Lib/idlelib/EditorWindow.py
   python/branches/py3k-importlib/Lib/idlelib/FileList.py
   python/branches/py3k-importlib/Lib/idlelib/FormatParagraph.py
   python/branches/py3k-importlib/Lib/idlelib/IOBinding.py
   python/branches/py3k-importlib/Lib/idlelib/MultiCall.py
   python/branches/py3k-importlib/Lib/idlelib/NEWS.txt
   python/branches/py3k-importlib/Lib/idlelib/OutputWindow.py
   python/branches/py3k-importlib/Lib/idlelib/PyParse.py
   python/branches/py3k-importlib/Lib/idlelib/PyShell.py
   python/branches/py3k-importlib/Lib/idlelib/RemoteDebugger.py
   python/branches/py3k-importlib/Lib/idlelib/ScriptBinding.py
   python/branches/py3k-importlib/Lib/idlelib/TreeWidget.py
   python/branches/py3k-importlib/Lib/idlelib/UndoDelegator.py
   python/branches/py3k-importlib/Lib/idlelib/WidgetRedirector.py
   python/branches/py3k-importlib/Lib/idlelib/aboutDialog.py
   python/branches/py3k-importlib/Lib/idlelib/configDialog.py
   python/branches/py3k-importlib/Lib/idlelib/configHandler.py
   python/branches/py3k-importlib/Lib/idlelib/idlever.py
   python/branches/py3k-importlib/Lib/idlelib/keybindingDialog.py
   python/branches/py3k-importlib/Lib/idlelib/run.py
   python/branches/py3k-importlib/Lib/idlelib/textView.py
   python/branches/py3k-importlib/Lib/ihooks.py
   python/branches/py3k-importlib/Lib/imaplib.py
   python/branches/py3k-importlib/Lib/imputil.py
   python/branches/py3k-importlib/Lib/inspect.py
   python/branches/py3k-importlib/Lib/io.py
   python/branches/py3k-importlib/Lib/keyword.py
   python/branches/py3k-importlib/Lib/lib-tk/FixTk.py
   python/branches/py3k-importlib/Lib/lib-tk/Tkinter.py
   python/branches/py3k-importlib/Lib/lib-tk/tkSimpleDialog.py
   python/branches/py3k-importlib/Lib/lib2to3/fixes/   (props changed)
   python/branches/py3k-importlib/Lib/lib2to3/pgen2/   (props changed)
   python/branches/py3k-importlib/Lib/lib2to3/tests/   (props changed)
   python/branches/py3k-importlib/Lib/locale.py
   python/branches/py3k-importlib/Lib/logging/__init__.py
   python/branches/py3k-importlib/Lib/logging/config.py
   python/branches/py3k-importlib/Lib/logging/handlers.py
   python/branches/py3k-importlib/Lib/mailbox.py
   python/branches/py3k-importlib/Lib/mhlib.py
   python/branches/py3k-importlib/Lib/mimetypes.py
   python/branches/py3k-importlib/Lib/modulefinder.py
   python/branches/py3k-importlib/Lib/msilib/__init__.py
   python/branches/py3k-importlib/Lib/msilib/schema.py
   python/branches/py3k-importlib/Lib/netrc.py
   python/branches/py3k-importlib/Lib/ntpath.py
   python/branches/py3k-importlib/Lib/numbers.py
   python/branches/py3k-importlib/Lib/opcode.py
   python/branches/py3k-importlib/Lib/optparse.py
   python/branches/py3k-importlib/Lib/os.py
   python/branches/py3k-importlib/Lib/pdb.py
   python/branches/py3k-importlib/Lib/pickle.py
   python/branches/py3k-importlib/Lib/pickletools.py
   python/branches/py3k-importlib/Lib/pkgutil.py
   python/branches/py3k-importlib/Lib/plat-freebsd6/IN.py
   python/branches/py3k-importlib/Lib/plat-freebsd7/IN.py
   python/branches/py3k-importlib/Lib/plat-mac/EasyDialogs.py
   python/branches/py3k-importlib/Lib/plat-mac/MiniAEFrame.py
   python/branches/py3k-importlib/Lib/plat-mac/aepack.py
   python/branches/py3k-importlib/Lib/plat-mac/aetools.py
   python/branches/py3k-importlib/Lib/plat-mac/aetypes.py
   python/branches/py3k-importlib/Lib/plat-mac/bgenlocations.py
   python/branches/py3k-importlib/Lib/plat-mac/gensuitemodule.py
   python/branches/py3k-importlib/Lib/plat-mac/ic.py
   python/branches/py3k-importlib/Lib/plat-mac/icopen.py
   python/branches/py3k-importlib/Lib/plat-mac/macostools.py
   python/branches/py3k-importlib/Lib/plat-mac/terminalcommand.py
   python/branches/py3k-importlib/Lib/platform.py
   python/branches/py3k-importlib/Lib/posixpath.py
   python/branches/py3k-importlib/Lib/pprint.py
   python/branches/py3k-importlib/Lib/pstats.py
   python/branches/py3k-importlib/Lib/py_compile.py
   python/branches/py3k-importlib/Lib/pyclbr.py
   python/branches/py3k-importlib/Lib/pydoc.py
   python/branches/py3k-importlib/Lib/quopri.py
   python/branches/py3k-importlib/Lib/random.py
   python/branches/py3k-importlib/Lib/re.py
   python/branches/py3k-importlib/Lib/repr.py
   python/branches/py3k-importlib/Lib/rlcompleter.py
   python/branches/py3k-importlib/Lib/runpy.py
   python/branches/py3k-importlib/Lib/sched.py
   python/branches/py3k-importlib/Lib/sgmllib.py
   python/branches/py3k-importlib/Lib/shelve.py
   python/branches/py3k-importlib/Lib/shlex.py
   python/branches/py3k-importlib/Lib/shutil.py
   python/branches/py3k-importlib/Lib/site.py
   python/branches/py3k-importlib/Lib/smtpd.py
   python/branches/py3k-importlib/Lib/smtplib.py
   python/branches/py3k-importlib/Lib/socket.py
   python/branches/py3k-importlib/Lib/sqlite3/dbapi2.py
   python/branches/py3k-importlib/Lib/sqlite3/test/factory.py
   python/branches/py3k-importlib/Lib/sqlite3/test/hooks.py
   python/branches/py3k-importlib/Lib/sqlite3/test/regression.py
   python/branches/py3k-importlib/Lib/sqlite3/test/transactions.py
   python/branches/py3k-importlib/Lib/sqlite3/test/types.py
   python/branches/py3k-importlib/Lib/sqlite3/test/userfunctions.py
   python/branches/py3k-importlib/Lib/sre_compile.py
   python/branches/py3k-importlib/Lib/sre_parse.py
   python/branches/py3k-importlib/Lib/ssl.py
   python/branches/py3k-importlib/Lib/stat.py
   python/branches/py3k-importlib/Lib/string.py
   python/branches/py3k-importlib/Lib/struct.py
   python/branches/py3k-importlib/Lib/subprocess.py
   python/branches/py3k-importlib/Lib/sunau.py
   python/branches/py3k-importlib/Lib/tarfile.py
   python/branches/py3k-importlib/Lib/tempfile.py
   python/branches/py3k-importlib/Lib/test/README
   python/branches/py3k-importlib/Lib/test/cjkencodings_test.py
   python/branches/py3k-importlib/Lib/test/crashers/borrowed_ref_2.py
   python/branches/py3k-importlib/Lib/test/decimaltestdata/abs.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/add.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/and.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/base.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/clamp.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/class.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/compare.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/comparetotal.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/comparetotmag.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/copy.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/copyabs.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/copynegate.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/copysign.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAbs.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAdd.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAnd.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddBase.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCanonical.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddClass.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompare.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareSig.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareTotal.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareTotalMag.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopy.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopyAbs.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopyNegate.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopySign.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddDivide.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddDivideInt.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddEncode.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddFMA.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddInvert.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddLogB.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMax.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMaxMag.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMin.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMinMag.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMinus.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMultiply.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextMinus.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextPlus.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextToward.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddOr.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddPlus.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddQuantize.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddReduce.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRemainder.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRemainderNear.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRotate.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddSameQuantum.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddScaleB.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddShift.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddSubtract.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddToIntegral.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ddXor.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/decDouble.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/decQuad.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/decSingle.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/divide.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/divideint.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAbs.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAdd.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAnd.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqBase.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCanonical.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqClass.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompare.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareSig.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareTotal.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareTotalMag.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopy.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopyAbs.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopyNegate.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopySign.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqDivide.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqDivideInt.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqEncode.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqFMA.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqInvert.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqLogB.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMax.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMaxMag.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMin.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMinMag.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMinus.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMultiply.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextMinus.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextPlus.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextToward.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqOr.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqPlus.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqQuantize.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqReduce.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRemainder.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRemainderNear.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRotate.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqSameQuantum.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqScaleB.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqShift.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqSubtract.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqToIntegral.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dqXor.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dsBase.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/dsEncode.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/exp.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/extra.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/fma.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/inexact.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/invert.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/ln.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/log10.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/logb.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/max.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/maxmag.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/min.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/minmag.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/minus.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/multiply.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/nextminus.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/nextplus.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/nexttoward.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/or.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/plus.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/power.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/powersqrt.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/quantize.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/randomBound32.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/randoms.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/reduce.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/remainder.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/remainderNear.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/rescale.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/rotate.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/rounding.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/samequantum.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/scaleb.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/shift.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/squareroot.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/subtract.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/testall.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegral.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegralx.decTest
   python/branches/py3k-importlib/Lib/test/decimaltestdata/xor.decTest
   python/branches/py3k-importlib/Lib/test/exception_hierarchy.txt
   python/branches/py3k-importlib/Lib/test/fork_wait.py
   python/branches/py3k-importlib/Lib/test/inspect_fodder2.py
   python/branches/py3k-importlib/Lib/test/list_tests.py
   python/branches/py3k-importlib/Lib/test/mapping_tests.py
   python/branches/py3k-importlib/Lib/test/outstanding_bugs.py
   python/branches/py3k-importlib/Lib/test/pickletester.py
   python/branches/py3k-importlib/Lib/test/pydocfodder.py
   python/branches/py3k-importlib/Lib/test/regex_tests.py
   python/branches/py3k-importlib/Lib/test/regrtest.py
   python/branches/py3k-importlib/Lib/test/seq_tests.py
   python/branches/py3k-importlib/Lib/test/string_tests.py
   python/branches/py3k-importlib/Lib/test/test___all__.py
   python/branches/py3k-importlib/Lib/test/test___future__.py
   python/branches/py3k-importlib/Lib/test/test__locale.py
   python/branches/py3k-importlib/Lib/test/test_abc.py
   python/branches/py3k-importlib/Lib/test/test_abstract_numbers.py
   python/branches/py3k-importlib/Lib/test/test_applesingle.py
   python/branches/py3k-importlib/Lib/test/test_ast.py
   python/branches/py3k-importlib/Lib/test/test_asynchat.py
   python/branches/py3k-importlib/Lib/test/test_asyncore.py
   python/branches/py3k-importlib/Lib/test/test_audioop.py
   python/branches/py3k-importlib/Lib/test/test_bigmem.py
   python/branches/py3k-importlib/Lib/test/test_binascii.py
   python/branches/py3k-importlib/Lib/test/test_bisect.py
   python/branches/py3k-importlib/Lib/test/test_bsddb3.py
   python/branches/py3k-importlib/Lib/test/test_bufio.py
   python/branches/py3k-importlib/Lib/test/test_builtin.py
   python/branches/py3k-importlib/Lib/test/test_bytes.py
   python/branches/py3k-importlib/Lib/test/test_bz2.py
   python/branches/py3k-importlib/Lib/test/test_cProfile.py
   python/branches/py3k-importlib/Lib/test/test_cfgparser.py
   python/branches/py3k-importlib/Lib/test/test_class.py
   python/branches/py3k-importlib/Lib/test/test_cmd_line.py
   python/branches/py3k-importlib/Lib/test/test_codeccallbacks.py
   python/branches/py3k-importlib/Lib/test/test_codecmaps_hk.py
   python/branches/py3k-importlib/Lib/test/test_codecs.py
   python/branches/py3k-importlib/Lib/test/test_coding.py
   python/branches/py3k-importlib/Lib/test/test_collections.py
   python/branches/py3k-importlib/Lib/test/test_compare.py
   python/branches/py3k-importlib/Lib/test/test_compile.py
   python/branches/py3k-importlib/Lib/test/test_complex.py
   python/branches/py3k-importlib/Lib/test/test_contains.py
   python/branches/py3k-importlib/Lib/test/test_copy.py
   python/branches/py3k-importlib/Lib/test/test_crypt.py
   python/branches/py3k-importlib/Lib/test/test_csv.py
   python/branches/py3k-importlib/Lib/test/test_curses.py
   python/branches/py3k-importlib/Lib/test/test_datetime.py
   python/branches/py3k-importlib/Lib/test/test_dbm.py
   python/branches/py3k-importlib/Lib/test/test_decimal.py
   python/branches/py3k-importlib/Lib/test/test_defaultdict.py
   python/branches/py3k-importlib/Lib/test/test_deque.py
   python/branches/py3k-importlib/Lib/test/test_descr.py
   python/branches/py3k-importlib/Lib/test/test_descrtut.py
   python/branches/py3k-importlib/Lib/test/test_dict.py
   python/branches/py3k-importlib/Lib/test/test_dis.py
   python/branches/py3k-importlib/Lib/test/test_doctest.py
   python/branches/py3k-importlib/Lib/test/test_dumbdbm.py
   python/branches/py3k-importlib/Lib/test/test_dummy_threading.py
   python/branches/py3k-importlib/Lib/test/test_email.py
   python/branches/py3k-importlib/Lib/test/test_eof.py
   python/branches/py3k-importlib/Lib/test/test_errno.py
   python/branches/py3k-importlib/Lib/test/test_exceptions.py
   python/branches/py3k-importlib/Lib/test/test_extcall.py
   python/branches/py3k-importlib/Lib/test/test_fcntl.py
   python/branches/py3k-importlib/Lib/test/test_file.py
   python/branches/py3k-importlib/Lib/test/test_fileinput.py
   python/branches/py3k-importlib/Lib/test/test_fileio.py
   python/branches/py3k-importlib/Lib/test/test_float.py
   python/branches/py3k-importlib/Lib/test/test_format.py
   python/branches/py3k-importlib/Lib/test/test_frozen.py
   python/branches/py3k-importlib/Lib/test/test_ftplib.py
   python/branches/py3k-importlib/Lib/test/test_funcattrs.py
   python/branches/py3k-importlib/Lib/test/test_gc.py
   python/branches/py3k-importlib/Lib/test/test_gdbm.py
   python/branches/py3k-importlib/Lib/test/test_generators.py
   python/branches/py3k-importlib/Lib/test/test_getargs2.py
   python/branches/py3k-importlib/Lib/test/test_getopt.py
   python/branches/py3k-importlib/Lib/test/test_gettext.py
   python/branches/py3k-importlib/Lib/test/test_grammar.py
   python/branches/py3k-importlib/Lib/test/test_grp.py
   python/branches/py3k-importlib/Lib/test/test_gzip.py
   python/branches/py3k-importlib/Lib/test/test_heapq.py
   python/branches/py3k-importlib/Lib/test/test_hmac.py
   python/branches/py3k-importlib/Lib/test/test_htmlparser.py
   python/branches/py3k-importlib/Lib/test/test_httplib.py
   python/branches/py3k-importlib/Lib/test/test_imp.py
   python/branches/py3k-importlib/Lib/test/test_import.py
   python/branches/py3k-importlib/Lib/test/test_index.py
   python/branches/py3k-importlib/Lib/test/test_inspect.py
   python/branches/py3k-importlib/Lib/test/test_io.py
   python/branches/py3k-importlib/Lib/test/test_ioctl.py
   python/branches/py3k-importlib/Lib/test/test_isinstance.py
   python/branches/py3k-importlib/Lib/test/test_iter.py
   python/branches/py3k-importlib/Lib/test/test_iterlen.py
   python/branches/py3k-importlib/Lib/test/test_itertools.py
   python/branches/py3k-importlib/Lib/test/test_keywordonlyarg.py
   python/branches/py3k-importlib/Lib/test/test_largefile.py
   python/branches/py3k-importlib/Lib/test/test_list.py
   python/branches/py3k-importlib/Lib/test/test_locale.py
   python/branches/py3k-importlib/Lib/test/test_logging.py
   python/branches/py3k-importlib/Lib/test/test_long.py
   python/branches/py3k-importlib/Lib/test/test_mailbox.py
   python/branches/py3k-importlib/Lib/test/test_marshal.py
   python/branches/py3k-importlib/Lib/test/test_math.py
   python/branches/py3k-importlib/Lib/test/test_minidom.py
   python/branches/py3k-importlib/Lib/test/test_mmap.py
   python/branches/py3k-importlib/Lib/test/test_module.py
   python/branches/py3k-importlib/Lib/test/test_modulefinder.py
   python/branches/py3k-importlib/Lib/test/test_multibytecodec.py
   python/branches/py3k-importlib/Lib/test/test_multibytecodec_support.py
   python/branches/py3k-importlib/Lib/test/test_netrc.py
   python/branches/py3k-importlib/Lib/test/test_nis.py
   python/branches/py3k-importlib/Lib/test/test_ntpath.py
   python/branches/py3k-importlib/Lib/test/test_operator.py
   python/branches/py3k-importlib/Lib/test/test_optparse.py
   python/branches/py3k-importlib/Lib/test/test_os.py
   python/branches/py3k-importlib/Lib/test/test_ossaudiodev.py
   python/branches/py3k-importlib/Lib/test/test_parser.py
   python/branches/py3k-importlib/Lib/test/test_pep247.py
   python/branches/py3k-importlib/Lib/test/test_pep263.py
   python/branches/py3k-importlib/Lib/test/test_pep277.py
   python/branches/py3k-importlib/Lib/test/test_pep352.py
   python/branches/py3k-importlib/Lib/test/test_pickle.py
   python/branches/py3k-importlib/Lib/test/test_pickletools.py
   python/branches/py3k-importlib/Lib/test/test_pkg.py
   python/branches/py3k-importlib/Lib/test/test_plistlib.py
   python/branches/py3k-importlib/Lib/test/test_poll.py
   python/branches/py3k-importlib/Lib/test/test_poplib.py
   python/branches/py3k-importlib/Lib/test/test_posix.py
   python/branches/py3k-importlib/Lib/test/test_posixpath.py
   python/branches/py3k-importlib/Lib/test/test_pprint.py
   python/branches/py3k-importlib/Lib/test/test_profile.py   (contents, props changed)
   python/branches/py3k-importlib/Lib/test/test_profilehooks.py
   python/branches/py3k-importlib/Lib/test/test_pty.py
   python/branches/py3k-importlib/Lib/test/test_pwd.py
   python/branches/py3k-importlib/Lib/test/test_pyclbr.py
   python/branches/py3k-importlib/Lib/test/test_pyexpat.py
   python/branches/py3k-importlib/Lib/test/test_queue.py
   python/branches/py3k-importlib/Lib/test/test_random.py
   python/branches/py3k-importlib/Lib/test/test_range.py
   python/branches/py3k-importlib/Lib/test/test_re.py
   python/branches/py3k-importlib/Lib/test/test_repr.py
   python/branches/py3k-importlib/Lib/test/test_resource.py
   python/branches/py3k-importlib/Lib/test/test_rfc822.py
   python/branches/py3k-importlib/Lib/test/test_richcmp.py
   python/branches/py3k-importlib/Lib/test/test_runpy.py
   python/branches/py3k-importlib/Lib/test/test_scope.py
   python/branches/py3k-importlib/Lib/test/test_scriptpackages.py
   python/branches/py3k-importlib/Lib/test/test_select.py
   python/branches/py3k-importlib/Lib/test/test_set.py
   python/branches/py3k-importlib/Lib/test/test_sgmllib.py
   python/branches/py3k-importlib/Lib/test/test_shelve.py
   python/branches/py3k-importlib/Lib/test/test_shutil.py
   python/branches/py3k-importlib/Lib/test/test_signal.py
   python/branches/py3k-importlib/Lib/test/test_site.py
   python/branches/py3k-importlib/Lib/test/test_slice.py
   python/branches/py3k-importlib/Lib/test/test_smtplib.py
   python/branches/py3k-importlib/Lib/test/test_socket.py
   python/branches/py3k-importlib/Lib/test/test_socketserver.py
   python/branches/py3k-importlib/Lib/test/test_sort.py
   python/branches/py3k-importlib/Lib/test/test_sqlite.py
   python/branches/py3k-importlib/Lib/test/test_ssl.py
   python/branches/py3k-importlib/Lib/test/test_strftime.py
   python/branches/py3k-importlib/Lib/test/test_strptime.py
   python/branches/py3k-importlib/Lib/test/test_struct.py
   python/branches/py3k-importlib/Lib/test/test_structmembers.py
   python/branches/py3k-importlib/Lib/test/test_structseq.py
   python/branches/py3k-importlib/Lib/test/test_subprocess.py
   python/branches/py3k-importlib/Lib/test/test_support.py
   python/branches/py3k-importlib/Lib/test/test_sys.py
   python/branches/py3k-importlib/Lib/test/test_tarfile.py
   python/branches/py3k-importlib/Lib/test/test_telnetlib.py
   python/branches/py3k-importlib/Lib/test/test_tempfile.py
   python/branches/py3k-importlib/Lib/test/test_textwrap.py
   python/branches/py3k-importlib/Lib/test/test_thread.py
   python/branches/py3k-importlib/Lib/test/test_threading.py
   python/branches/py3k-importlib/Lib/test/test_threading_local.py
   python/branches/py3k-importlib/Lib/test/test_timeout.py
   python/branches/py3k-importlib/Lib/test/test_tokenize.py
   python/branches/py3k-importlib/Lib/test/test_trace.py
   python/branches/py3k-importlib/Lib/test/test_traceback.py
   python/branches/py3k-importlib/Lib/test/test_tuple.py
   python/branches/py3k-importlib/Lib/test/test_typechecks.py
   python/branches/py3k-importlib/Lib/test/test_types.py
   python/branches/py3k-importlib/Lib/test/test_unicode.py
   python/branches/py3k-importlib/Lib/test/test_unicode_file.py
   python/branches/py3k-importlib/Lib/test/test_unicodedata.py
   python/branches/py3k-importlib/Lib/test/test_unittest.py
   python/branches/py3k-importlib/Lib/test/test_univnewlines.py
   python/branches/py3k-importlib/Lib/test/test_unpack.py
   python/branches/py3k-importlib/Lib/test/test_unpack_ex.py
   python/branches/py3k-importlib/Lib/test/test_urllib.py
   python/branches/py3k-importlib/Lib/test/test_urllib2.py
   python/branches/py3k-importlib/Lib/test/test_urllib2_localnet.py
   python/branches/py3k-importlib/Lib/test/test_urllib2net.py
   python/branches/py3k-importlib/Lib/test/test_urllibnet.py
   python/branches/py3k-importlib/Lib/test/test_urlparse.py
   python/branches/py3k-importlib/Lib/test/test_userdict.py
   python/branches/py3k-importlib/Lib/test/test_userlist.py
   python/branches/py3k-importlib/Lib/test/test_userstring.py
   python/branches/py3k-importlib/Lib/test/test_warnings.py
   python/branches/py3k-importlib/Lib/test/test_wave.py
   python/branches/py3k-importlib/Lib/test/test_weakref.py
   python/branches/py3k-importlib/Lib/test/test_whichdb.py
   python/branches/py3k-importlib/Lib/test/test_winreg.py
   python/branches/py3k-importlib/Lib/test/test_winsound.py
   python/branches/py3k-importlib/Lib/test/test_with.py
   python/branches/py3k-importlib/Lib/test/test_xml_etree.py
   python/branches/py3k-importlib/Lib/test/test_xml_etree_c.py
   python/branches/py3k-importlib/Lib/test/test_xmlrpc.py
   python/branches/py3k-importlib/Lib/test/test_zipfile.py
   python/branches/py3k-importlib/Lib/test/test_zipimport.py
   python/branches/py3k-importlib/Lib/test/test_zlib.py
   python/branches/py3k-importlib/Lib/test/testcodec.py
   python/branches/py3k-importlib/Lib/test/testtar.tar
   python/branches/py3k-importlib/Lib/test/tokenize_tests.txt
   python/branches/py3k-importlib/Lib/textwrap.py
   python/branches/py3k-importlib/Lib/threading.py
   python/branches/py3k-importlib/Lib/timeit.py
   python/branches/py3k-importlib/Lib/token.py
   python/branches/py3k-importlib/Lib/tokenize.py
   python/branches/py3k-importlib/Lib/trace.py
   python/branches/py3k-importlib/Lib/traceback.py
   python/branches/py3k-importlib/Lib/types.py
   python/branches/py3k-importlib/Lib/unittest.py
   python/branches/py3k-importlib/Lib/urllib.py
   python/branches/py3k-importlib/Lib/urllib2.py
   python/branches/py3k-importlib/Lib/urlparse.py
   python/branches/py3k-importlib/Lib/uu.py
   python/branches/py3k-importlib/Lib/uuid.py
   python/branches/py3k-importlib/Lib/warnings.py
   python/branches/py3k-importlib/Lib/wave.py
   python/branches/py3k-importlib/Lib/weakref.py
   python/branches/py3k-importlib/Lib/webbrowser.py
   python/branches/py3k-importlib/Lib/xml/dom/domreg.py
   python/branches/py3k-importlib/Lib/xml/dom/expatbuilder.py
   python/branches/py3k-importlib/Lib/xml/dom/minicompat.py
   python/branches/py3k-importlib/Lib/xml/dom/minidom.py
   python/branches/py3k-importlib/Lib/xml/dom/pulldom.py
   python/branches/py3k-importlib/Lib/xml/sax/saxutils.py
   python/branches/py3k-importlib/Lib/xmlrpclib.py
   python/branches/py3k-importlib/Lib/zipfile.py
   python/branches/py3k-importlib/Mac/Demo/PICTbrowse/ICONbrowse.py
   python/branches/py3k-importlib/Mac/Demo/PICTbrowse/PICTbrowse.py
   python/branches/py3k-importlib/Mac/Demo/PICTbrowse/PICTbrowse2.py
   python/branches/py3k-importlib/Mac/Demo/PICTbrowse/cicnbrowse.py
   python/branches/py3k-importlib/Mac/Demo/PICTbrowse/oldPICTbrowse.py
   python/branches/py3k-importlib/Mac/Demo/example1/dnslookup-1.py
   python/branches/py3k-importlib/Mac/Demo/example2/dnslookup-2.py
   python/branches/py3k-importlib/Mac/Demo/imgbrowse/imgbrowse.py
   python/branches/py3k-importlib/Mac/Demo/imgbrowse/mac_image.py
   python/branches/py3k-importlib/Mac/Modules/MacOS.c
   python/branches/py3k-importlib/Mac/Modules/ae/_AEmodule.c
   python/branches/py3k-importlib/Mac/Modules/ae/aescan.py
   python/branches/py3k-importlib/Mac/Modules/ah/ahscan.py
   python/branches/py3k-importlib/Mac/Modules/app/_Appmodule.c
   python/branches/py3k-importlib/Mac/Modules/app/appscan.py
   python/branches/py3k-importlib/Mac/Modules/carbonevt/CarbonEvtscan.py
   python/branches/py3k-importlib/Mac/Modules/carbonevt/_CarbonEvtmodule.c
   python/branches/py3k-importlib/Mac/Modules/cf/_CFmodule.c
   python/branches/py3k-importlib/Mac/Modules/cf/cfscan.py
   python/branches/py3k-importlib/Mac/Modules/cf/pycfbridge.c
   python/branches/py3k-importlib/Mac/Modules/cg/_CGmodule.c
   python/branches/py3k-importlib/Mac/Modules/cg/cgscan.py
   python/branches/py3k-importlib/Mac/Modules/cm/_Cmmodule.c
   python/branches/py3k-importlib/Mac/Modules/cm/cmscan.py
   python/branches/py3k-importlib/Mac/Modules/ctl/_Ctlmodule.c
   python/branches/py3k-importlib/Mac/Modules/ctl/ctlscan.py
   python/branches/py3k-importlib/Mac/Modules/dlg/_Dlgmodule.c
   python/branches/py3k-importlib/Mac/Modules/dlg/dlgscan.py
   python/branches/py3k-importlib/Mac/Modules/drag/_Dragmodule.c
   python/branches/py3k-importlib/Mac/Modules/drag/dragscan.py
   python/branches/py3k-importlib/Mac/Modules/evt/evtscan.py
   python/branches/py3k-importlib/Mac/Modules/file/_Filemodule.c
   python/branches/py3k-importlib/Mac/Modules/file/filescan.py
   python/branches/py3k-importlib/Mac/Modules/fm/fmscan.py
   python/branches/py3k-importlib/Mac/Modules/folder/folderscan.py
   python/branches/py3k-importlib/Mac/Modules/gestaltmodule.c
   python/branches/py3k-importlib/Mac/Modules/help/helpscan.py
   python/branches/py3k-importlib/Mac/Modules/ibcarbon/IBCarbonscan.py
   python/branches/py3k-importlib/Mac/Modules/ibcarbon/_IBCarbon.c
   python/branches/py3k-importlib/Mac/Modules/icn/icnscan.py
   python/branches/py3k-importlib/Mac/Modules/launch/launchscan.py
   python/branches/py3k-importlib/Mac/Modules/list/_Listmodule.c
   python/branches/py3k-importlib/Mac/Modules/list/listscan.py
   python/branches/py3k-importlib/Mac/Modules/menu/_Menumodule.c
   python/branches/py3k-importlib/Mac/Modules/menu/menuscan.py
   python/branches/py3k-importlib/Mac/Modules/mlte/_Mltemodule.c
   python/branches/py3k-importlib/Mac/Modules/mlte/mltescan.py
   python/branches/py3k-importlib/Mac/Modules/osa/_OSAmodule.c
   python/branches/py3k-importlib/Mac/Modules/osa/osascan.py
   python/branches/py3k-importlib/Mac/Modules/qd/_Qdmodule.c
   python/branches/py3k-importlib/Mac/Modules/qd/qdscan.py
   python/branches/py3k-importlib/Mac/Modules/qdoffs/_Qdoffsmodule.c
   python/branches/py3k-importlib/Mac/Modules/qdoffs/qdoffsscan.py
   python/branches/py3k-importlib/Mac/Modules/qt/_Qtmodule.c
   python/branches/py3k-importlib/Mac/Modules/qt/qtscan.py
   python/branches/py3k-importlib/Mac/Modules/res/_Resmodule.c
   python/branches/py3k-importlib/Mac/Modules/res/resscan.py
   python/branches/py3k-importlib/Mac/Modules/scrap/_Scrapmodule.c
   python/branches/py3k-importlib/Mac/Modules/scrap/scrapscan.py
   python/branches/py3k-importlib/Mac/Modules/snd/_Sndihooks.c
   python/branches/py3k-importlib/Mac/Modules/snd/_Sndmodule.c
   python/branches/py3k-importlib/Mac/Modules/snd/sndscan.py
   python/branches/py3k-importlib/Mac/Modules/te/_TEmodule.c
   python/branches/py3k-importlib/Mac/Modules/te/tescan.py
   python/branches/py3k-importlib/Mac/Modules/win/_Winmodule.c
   python/branches/py3k-importlib/Mac/Modules/win/winscan.py
   python/branches/py3k-importlib/Makefile.pre.in
   python/branches/py3k-importlib/Misc/ACKS
   python/branches/py3k-importlib/Misc/HISTORY
   python/branches/py3k-importlib/Misc/NEWS
   python/branches/py3k-importlib/Misc/Vim/python.vim
   python/branches/py3k-importlib/Misc/Vim/syntax_test.py
   python/branches/py3k-importlib/Misc/Vim/vim_syntax.py
   python/branches/py3k-importlib/Misc/Vim/vimrc
   python/branches/py3k-importlib/Misc/build.sh
   python/branches/py3k-importlib/Misc/cheatsheet
   python/branches/py3k-importlib/Misc/developers.txt
   python/branches/py3k-importlib/Misc/python-mode.el
   python/branches/py3k-importlib/Modules/Setup.dist
   python/branches/py3k-importlib/Modules/_bisectmodule.c
   python/branches/py3k-importlib/Modules/_bsddb.c
   python/branches/py3k-importlib/Modules/_codecsmodule.c
   python/branches/py3k-importlib/Modules/_collectionsmodule.c
   python/branches/py3k-importlib/Modules/_csv.c
   python/branches/py3k-importlib/Modules/_ctypes/_ctypes.c
   python/branches/py3k-importlib/Modules/_ctypes/_ctypes_test.c
   python/branches/py3k-importlib/Modules/_ctypes/callbacks.c
   python/branches/py3k-importlib/Modules/_ctypes/callproc.c
   python/branches/py3k-importlib/Modules/_ctypes/cfield.c
   python/branches/py3k-importlib/Modules/_ctypes/ctypes.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/LICENSE
   python/branches/py3k-importlib/Modules/_ctypes/libffi/README
   python/branches/py3k-importlib/Modules/_ctypes/libffi/aclocal.m4
   python/branches/py3k-importlib/Modules/_ctypes/libffi/config.guess
   python/branches/py3k-importlib/Modules/_ctypes/libffi/config.sub
   python/branches/py3k-importlib/Modules/_ctypes/libffi/configure
   python/branches/py3k-importlib/Modules/_ctypes/libffi/configure.ac
   python/branches/py3k-importlib/Modules/_ctypes/libffi/fficonfig.h.in
   python/branches/py3k-importlib/Modules/_ctypes/libffi/fficonfig.py.in
   python/branches/py3k-importlib/Modules/_ctypes/libffi/include/ffi.h.in
   python/branches/py3k-importlib/Modules/_ctypes/libffi/include/ffi_common.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/install-sh
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/alpha/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/alpha/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/alpha/osf.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/arm/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/arm/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/arm/sysv.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/cris/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/cris/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/frv/eabi.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/frv/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/frv/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/ia64_flags.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/unix.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m32r/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m68k/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m68k/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m68k/sysv.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/n32.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/o32.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/pa/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/pa/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/pa/linux.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/darwin.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/linux64.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/linux64_closure.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ppc_closure.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/sysv.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/prep_cif.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/s390/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/s390/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/s390/sysv.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh/sysv.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh64/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh64/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh64/sysv.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/v8.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/v9.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/darwin.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffi.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffi64.c
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffitarget.h
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/sysv.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/unix64.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/win32.S
   python/branches/py3k-importlib/Modules/_ctypes/libffi_msvc/prep_cif.c
   python/branches/py3k-importlib/Modules/_ctypes/stgdict.c
   python/branches/py3k-importlib/Modules/_curses_panel.c
   python/branches/py3k-importlib/Modules/_cursesmodule.c
   python/branches/py3k-importlib/Modules/_elementtree.c
   python/branches/py3k-importlib/Modules/_fileio.c
   python/branches/py3k-importlib/Modules/_functoolsmodule.c
   python/branches/py3k-importlib/Modules/_hashopenssl.c
   python/branches/py3k-importlib/Modules/_heapqmodule.c
   python/branches/py3k-importlib/Modules/_localemodule.c
   python/branches/py3k-importlib/Modules/_lsprof.c
   python/branches/py3k-importlib/Modules/_randommodule.c
   python/branches/py3k-importlib/Modules/_sqlite/cache.c
   python/branches/py3k-importlib/Modules/_sqlite/connection.c
   python/branches/py3k-importlib/Modules/_sqlite/cursor.c
   python/branches/py3k-importlib/Modules/_sqlite/module.c
   python/branches/py3k-importlib/Modules/_sqlite/prepare_protocol.c
   python/branches/py3k-importlib/Modules/_sqlite/row.c
   python/branches/py3k-importlib/Modules/_sqlite/statement.c
   python/branches/py3k-importlib/Modules/_sqlite/util.c
   python/branches/py3k-importlib/Modules/_sre.c
   python/branches/py3k-importlib/Modules/_ssl.c
   python/branches/py3k-importlib/Modules/_struct.c
   python/branches/py3k-importlib/Modules/_testcapimodule.c
   python/branches/py3k-importlib/Modules/_tkinter.c
   python/branches/py3k-importlib/Modules/_weakref.c
   python/branches/py3k-importlib/Modules/arraymodule.c
   python/branches/py3k-importlib/Modules/audioop.c
   python/branches/py3k-importlib/Modules/binascii.c
   python/branches/py3k-importlib/Modules/bz2module.c
   python/branches/py3k-importlib/Modules/cStringIO.c
   python/branches/py3k-importlib/Modules/cjkcodecs/_codecs_hk.c
   python/branches/py3k-importlib/Modules/cjkcodecs/_codecs_iso2022.c
   python/branches/py3k-importlib/Modules/cjkcodecs/cjkcodecs.h
   python/branches/py3k-importlib/Modules/cjkcodecs/mappings_hk.h
   python/branches/py3k-importlib/Modules/cjkcodecs/multibytecodec.c
   python/branches/py3k-importlib/Modules/config.c.in
   python/branches/py3k-importlib/Modules/datetimemodule.c
   python/branches/py3k-importlib/Modules/dbmmodule.c
   python/branches/py3k-importlib/Modules/dlmodule.c
   python/branches/py3k-importlib/Modules/errnomodule.c
   python/branches/py3k-importlib/Modules/fcntlmodule.c
   python/branches/py3k-importlib/Modules/gcmodule.c
   python/branches/py3k-importlib/Modules/gdbmmodule.c
   python/branches/py3k-importlib/Modules/grpmodule.c
   python/branches/py3k-importlib/Modules/itertoolsmodule.c
   python/branches/py3k-importlib/Modules/main.c
   python/branches/py3k-importlib/Modules/mathmodule.c
   python/branches/py3k-importlib/Modules/md5module.c
   python/branches/py3k-importlib/Modules/mmapmodule.c
   python/branches/py3k-importlib/Modules/operator.c
   python/branches/py3k-importlib/Modules/ossaudiodev.c
   python/branches/py3k-importlib/Modules/parsermodule.c
   python/branches/py3k-importlib/Modules/posixmodule.c
   python/branches/py3k-importlib/Modules/pwdmodule.c
   python/branches/py3k-importlib/Modules/pyexpat.c
   python/branches/py3k-importlib/Modules/readline.c
   python/branches/py3k-importlib/Modules/resource.c
   python/branches/py3k-importlib/Modules/selectmodule.c
   python/branches/py3k-importlib/Modules/sha1module.c
   python/branches/py3k-importlib/Modules/sha256module.c
   python/branches/py3k-importlib/Modules/sha512module.c
   python/branches/py3k-importlib/Modules/signalmodule.c
   python/branches/py3k-importlib/Modules/socketmodule.c
   python/branches/py3k-importlib/Modules/socketmodule.h
   python/branches/py3k-importlib/Modules/spwdmodule.c
   python/branches/py3k-importlib/Modules/syslogmodule.c
   python/branches/py3k-importlib/Modules/termios.c
   python/branches/py3k-importlib/Modules/threadmodule.c
   python/branches/py3k-importlib/Modules/timemodule.c
   python/branches/py3k-importlib/Modules/unicodedata.c
   python/branches/py3k-importlib/Modules/xxmodule.c
   python/branches/py3k-importlib/Modules/xxsubtype.c
   python/branches/py3k-importlib/Modules/zipimport.c
   python/branches/py3k-importlib/Modules/zlibmodule.c
   python/branches/py3k-importlib/Objects/abstract.c
   python/branches/py3k-importlib/Objects/bytesobject.c
   python/branches/py3k-importlib/Objects/cellobject.c
   python/branches/py3k-importlib/Objects/classobject.c
   python/branches/py3k-importlib/Objects/codeobject.c
   python/branches/py3k-importlib/Objects/complexobject.c
   python/branches/py3k-importlib/Objects/descrobject.c
   python/branches/py3k-importlib/Objects/dictobject.c
   python/branches/py3k-importlib/Objects/enumobject.c
   python/branches/py3k-importlib/Objects/exceptions.c
   python/branches/py3k-importlib/Objects/fileobject.c
   python/branches/py3k-importlib/Objects/floatobject.c
   python/branches/py3k-importlib/Objects/frameobject.c
   python/branches/py3k-importlib/Objects/funcobject.c
   python/branches/py3k-importlib/Objects/genobject.c
   python/branches/py3k-importlib/Objects/iterobject.c
   python/branches/py3k-importlib/Objects/listobject.c
   python/branches/py3k-importlib/Objects/longobject.c
   python/branches/py3k-importlib/Objects/memoryobject.c
   python/branches/py3k-importlib/Objects/methodobject.c
   python/branches/py3k-importlib/Objects/moduleobject.c
   python/branches/py3k-importlib/Objects/object.c
   python/branches/py3k-importlib/Objects/rangeobject.c
   python/branches/py3k-importlib/Objects/setobject.c
   python/branches/py3k-importlib/Objects/sliceobject.c
   python/branches/py3k-importlib/Objects/stringlib/README.txt
   python/branches/py3k-importlib/Objects/stringlib/find.h
   python/branches/py3k-importlib/Objects/stringlib/formatter.h
   python/branches/py3k-importlib/Objects/stringlib/string_format.h
   python/branches/py3k-importlib/Objects/stringlib/stringdefs.h
   python/branches/py3k-importlib/Objects/stringlib/unicodedefs.h
   python/branches/py3k-importlib/Objects/stringobject.c
   python/branches/py3k-importlib/Objects/structseq.c
   python/branches/py3k-importlib/Objects/tupleobject.c
   python/branches/py3k-importlib/Objects/typeobject.c
   python/branches/py3k-importlib/Objects/unicodeobject.c
   python/branches/py3k-importlib/Objects/weakrefobject.c
   python/branches/py3k-importlib/PC/VC6/build_ssl.py
   python/branches/py3k-importlib/PC/VC6/pcbuild.dsw
   python/branches/py3k-importlib/PC/VC6/python.dsp
   python/branches/py3k-importlib/PC/VC6/pythoncore.dsp
   python/branches/py3k-importlib/PC/VC6/readme.txt
   python/branches/py3k-importlib/PC/_msi.c
   python/branches/py3k-importlib/PC/_subprocess.c
   python/branches/py3k-importlib/PC/_winreg.c
   python/branches/py3k-importlib/PC/bdist_wininst/install.c
   python/branches/py3k-importlib/PC/config.c
   python/branches/py3k-importlib/PC/dl_nt.c
   python/branches/py3k-importlib/PC/msvcrtmodule.c
   python/branches/py3k-importlib/PC/os2emx/Makefile
   python/branches/py3k-importlib/PC/os2emx/README.os2emx
   python/branches/py3k-importlib/PC/os2emx/config.c
   python/branches/py3k-importlib/PC/os2emx/pyconfig.h
   python/branches/py3k-importlib/PC/os2vacpp/config.c
   python/branches/py3k-importlib/PC/os2vacpp/pyconfig.h
   python/branches/py3k-importlib/PC/pyconfig.h
   python/branches/py3k-importlib/PC/python_nt.rc
   python/branches/py3k-importlib/PC/readme.txt
   python/branches/py3k-importlib/Parser/asdl.py
   python/branches/py3k-importlib/Parser/asdl_c.py
   python/branches/py3k-importlib/Parser/parser.h
   python/branches/py3k-importlib/Parser/parsetok.c
   python/branches/py3k-importlib/Parser/pgen.c
   python/branches/py3k-importlib/Parser/spark.py
   python/branches/py3k-importlib/Parser/tokenizer.c
   python/branches/py3k-importlib/Parser/tokenizer.h
   python/branches/py3k-importlib/Python/Python-ast.c
   python/branches/py3k-importlib/Python/ast.c
   python/branches/py3k-importlib/Python/bltinmodule.c
   python/branches/py3k-importlib/Python/ceval.c
   python/branches/py3k-importlib/Python/codecs.c
   python/branches/py3k-importlib/Python/compile.c
   python/branches/py3k-importlib/Python/dynload_win.c
   python/branches/py3k-importlib/Python/errors.c
   python/branches/py3k-importlib/Python/frozen.c
   python/branches/py3k-importlib/Python/future.c
   python/branches/py3k-importlib/Python/getargs.c
   python/branches/py3k-importlib/Python/getcopyright.c
   python/branches/py3k-importlib/Python/hypot.c
   python/branches/py3k-importlib/Python/import.c
   python/branches/py3k-importlib/Python/mactoolboxglue.c
   python/branches/py3k-importlib/Python/marshal.c
   python/branches/py3k-importlib/Python/modsupport.c
   python/branches/py3k-importlib/Python/mystrtoul.c
   python/branches/py3k-importlib/Python/peephole.c
   python/branches/py3k-importlib/Python/pystate.c
   python/branches/py3k-importlib/Python/pystrtod.c
   python/branches/py3k-importlib/Python/pythonrun.c
   python/branches/py3k-importlib/Python/strtod.c
   python/branches/py3k-importlib/Python/structmember.c
   python/branches/py3k-importlib/Python/symtable.c
   python/branches/py3k-importlib/Python/sysmodule.c
   python/branches/py3k-importlib/Python/thread.c
   python/branches/py3k-importlib/Python/traceback.c
   python/branches/py3k-importlib/README
   python/branches/py3k-importlib/RELNOTES
   python/branches/py3k-importlib/Tools/bgen/bgen/bgenObjectDefinition.py
   python/branches/py3k-importlib/Tools/buildbot/build-amd64.bat
   python/branches/py3k-importlib/Tools/buildbot/build.bat
   python/branches/py3k-importlib/Tools/buildbot/buildmsi.bat
   python/branches/py3k-importlib/Tools/buildbot/clean-amd64.bat
   python/branches/py3k-importlib/Tools/buildbot/clean.bat
   python/branches/py3k-importlib/Tools/buildbot/external-amd64.bat
   python/branches/py3k-importlib/Tools/buildbot/external.bat
   python/branches/py3k-importlib/Tools/buildbot/kill_python.c
   python/branches/py3k-importlib/Tools/buildbot/test-amd64.bat
   python/branches/py3k-importlib/Tools/faqwiz/faqw.py
   python/branches/py3k-importlib/Tools/freeze/makeconfig.py
   python/branches/py3k-importlib/Tools/i18n/pygettext.py
   python/branches/py3k-importlib/Tools/modulator/Tkextra.py
   python/branches/py3k-importlib/Tools/msi/msi.py
   python/branches/py3k-importlib/Tools/msi/msilib.py
   python/branches/py3k-importlib/Tools/msi/uuids.py
   python/branches/py3k-importlib/Tools/pybench/Setup.py
   python/branches/py3k-importlib/Tools/pybench/pybench.py
   python/branches/py3k-importlib/Tools/pybench/systimes.py
   python/branches/py3k-importlib/Tools/pynche/ChipViewer.py
   python/branches/py3k-importlib/Tools/pynche/ColorDB.py
   python/branches/py3k-importlib/Tools/pynche/TypeinViewer.py
   python/branches/py3k-importlib/Tools/scripts/   (props changed)
   python/branches/py3k-importlib/Tools/scripts/checkappend.py
   python/branches/py3k-importlib/Tools/scripts/combinerefs.py
   python/branches/py3k-importlib/Tools/scripts/finddiv.py
   python/branches/py3k-importlib/Tools/scripts/h2py.py
   python/branches/py3k-importlib/Tools/scripts/logmerge.py
   python/branches/py3k-importlib/Tools/scripts/nm2def.py
   python/branches/py3k-importlib/Tools/scripts/pindent.py
   python/branches/py3k-importlib/Tools/scripts/pysource.py
   python/branches/py3k-importlib/Tools/scripts/reindent.py
   python/branches/py3k-importlib/Tools/scripts/xxci.py
   python/branches/py3k-importlib/Tools/ssl/get-remote-certificate.py
   python/branches/py3k-importlib/Tools/unicode/gencodec.py
   python/branches/py3k-importlib/Tools/unicode/makeunicodedata.py
   python/branches/py3k-importlib/Tools/webchecker/wcgui.py
   python/branches/py3k-importlib/Tools/webchecker/wsgui.py
   python/branches/py3k-importlib/Tools/world/world
   python/branches/py3k-importlib/configure
   python/branches/py3k-importlib/configure.in
   python/branches/py3k-importlib/pyconfig.h.in
   python/branches/py3k-importlib/runtests.sh
   python/branches/py3k-importlib/setup.py
Log:
Merged revisions 58486 through 61829 using svnmerge.


Modified: python/branches/py3k-importlib/Demo/classes/README
==============================================================================
--- python/branches/py3k-importlib/Demo/classes/README	(original)
+++ python/branches/py3k-importlib/Demo/classes/README	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,6 @@
 Dates.py	Date manipulation package by Tim Peters
 Dbm.py		Wrapper around built-in dbm, supporting	arbitrary values
 Range.py	Example of a generator: re-implement built-in range()
-Rat.py		Rational numbers
 Rev.py		Yield the reverse of a sequence
 Vec.py		A simple vector class
 bitvec.py	A bit-vector class by Jan-Hein B\"uhrman

Modified: python/branches/py3k-importlib/Demo/classes/Range.py
==============================================================================
--- python/branches/py3k-importlib/Demo/classes/Range.py	(original)
+++ python/branches/py3k-importlib/Demo/classes/Range.py	Thu Mar 27 00:48:05 2008
@@ -64,9 +64,9 @@
 
 
 def test():
-    import time, __builtin__
+    import time, builtins
     #Just a quick sanity check
-    correct_result = __builtin__.range(5, 100, 3)
+    correct_result = builtins.range(5, 100, 3)
     oldrange_result = list(oldrange(5, 100, 3))
     genrange_result = list(genrange(5, 100, 3))
     if genrange_result != correct_result or oldrange_result != correct_result:
@@ -81,7 +81,7 @@
     for i in genrange(1000):
         pass
     t3 = time.time()
-    for i in __builtin__.range(1000):
+    for i in builtins.range(1000):
         pass
     t4 = time.time()
     print(t2-t1, 'sec (old-style class)')

Deleted: /python/branches/py3k-importlib/Demo/classes/Rat.py
==============================================================================
--- /python/branches/py3k-importlib/Demo/classes/Rat.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,306 +0,0 @@
-'''\
-This module implements rational numbers.
-
-The entry point of this module is the function
-        rat(numerator, denominator)
-If either numerator or denominator is of an integral or rational type,
-the result is a rational number, else, the result is the simplest of
-the types float and complex which can hold numerator/denominator.
-If denominator is omitted, it defaults to 1.
-Rational numbers can be used in calculations with any other numeric
-type.  The result of the calculation will be rational if possible.
-
-There is also a test function with calling sequence
-        test()
-The documentation string of the test function contains the expected
-output.
-'''
-
-# Contributed by Sjoerd Mullender
-
-from types import *
-
-def gcd(a, b):
-    '''Calculate the Greatest Common Divisor.'''
-    while b:
-        a, b = b, a%b
-    return a
-
-def rat(num, den = 1):
-    # must check complex before float
-    if isinstance(num, complex) or isinstance(den, complex):
-        # numerator or denominator is complex: return a complex
-        return complex(num) / complex(den)
-    if isinstance(num, float) or isinstance(den, float):
-        # numerator or denominator is float: return a float
-        return float(num) / float(den)
-    # otherwise return a rational
-    return Rat(num, den)
-
-class Rat:
-    '''This class implements rational numbers.'''
-
-    def __init__(self, num, den = 1):
-        if den == 0:
-            raise ZeroDivisionError('rat(x, 0)')
-
-        # normalize
-
-        # must check complex before float
-        if (isinstance(num, complex) or
-            isinstance(den, complex)):
-            # numerator or denominator is complex:
-            # normalized form has denominator == 1+0j
-            self.__num = complex(num) / complex(den)
-            self.__den = complex(1)
-            return
-        if isinstance(num, float) or isinstance(den, float):
-            # numerator or denominator is float:
-            # normalized form has denominator == 1.0
-            self.__num = float(num) / float(den)
-            self.__den = 1.0
-            return
-        if (isinstance(num, self.__class__) or
-            isinstance(den, self.__class__)):
-            # numerator or denominator is rational
-            new = num / den
-            if not isinstance(new, self.__class__):
-                self.__num = new
-                if isinstance(new, complex):
-                    self.__den = complex(1)
-                else:
-                    self.__den = 1.0
-            else:
-                self.__num = new.__num
-                self.__den = new.__den
-        else:
-            # make sure numerator and denominator don't
-            # have common factors
-            # this also makes sure that denominator > 0
-            g = gcd(num, den)
-            self.__num = num / g
-            self.__den = den / g
-        # try making numerator and denominator of IntType if they fit
-        try:
-            numi = int(self.__num)
-            deni = int(self.__den)
-        except (OverflowError, TypeError):
-            pass
-        else:
-            if self.__num == numi and self.__den == deni:
-                self.__num = numi
-                self.__den = deni
-
-    def __repr__(self):
-        return 'Rat(%s,%s)' % (self.__num, self.__den)
-
-    def __str__(self):
-        if self.__den == 1:
-            return str(self.__num)
-        else:
-            return '(%s/%s)' % (str(self.__num), str(self.__den))
-
-    # a + b
-    def __add__(a, b):
-        try:
-            return rat(a.__num * b.__den + b.__num * a.__den,
-                       a.__den * b.__den)
-        except OverflowError:
-            return rat(int(a.__num) * int(b.__den) +
-                       int(b.__num) * int(a.__den),
-                       int(a.__den) * int(b.__den))
-
-    def __radd__(b, a):
-        return Rat(a) + b
-
-    # a - b
-    def __sub__(a, b):
-        try:
-            return rat(a.__num * b.__den - b.__num * a.__den,
-                       a.__den * b.__den)
-        except OverflowError:
-            return rat(int(a.__num) * int(b.__den) -
-                       int(b.__num) * int(a.__den),
-                       int(a.__den) * int(b.__den))
-
-    def __rsub__(b, a):
-        return Rat(a) - b
-
-    # a * b
-    def __mul__(a, b):
-        try:
-            return rat(a.__num * b.__num, a.__den * b.__den)
-        except OverflowError:
-            return rat(int(a.__num) * int(b.__num),
-                       int(a.__den) * int(b.__den))
-
-    def __rmul__(b, a):
-        return Rat(a) * b
-
-    # a / b
-    def __div__(a, b):
-        try:
-            return rat(a.__num * b.__den, a.__den * b.__num)
-        except OverflowError:
-            return rat(int(a.__num) * int(b.__den),
-                       int(a.__den) * int(b.__num))
-
-    def __rdiv__(b, a):
-        return Rat(a) / b
-
-    # a % b
-    def __mod__(a, b):
-        div = a / b
-        try:
-            div = int(div)
-        except OverflowError:
-            div = int(div)
-        return a - b * div
-
-    def __rmod__(b, a):
-        return Rat(a) % b
-
-    # a ** b
-    def __pow__(a, b):
-        if b.__den != 1:
-            if isinstance(a.__num, complex):
-                a = complex(a)
-            else:
-                a = float(a)
-            if isinstance(b.__num, complex):
-                b = complex(b)
-            else:
-                b = float(b)
-            return a ** b
-        try:
-            return rat(a.__num ** b.__num, a.__den ** b.__num)
-        except OverflowError:
-            return rat(int(a.__num) ** b.__num,
-                       int(a.__den) ** b.__num)
-
-    def __rpow__(b, a):
-        return Rat(a) ** b
-
-    # -a
-    def __neg__(a):
-        try:
-            return rat(-a.__num, a.__den)
-        except OverflowError:
-            # a.__num == sys.maxint
-            return rat(-int(a.__num), a.__den)
-
-    # abs(a)
-    def __abs__(a):
-        return rat(abs(a.__num), a.__den)
-
-    # int(a)
-    def __int__(a):
-        return int(a.__num / a.__den)
-
-    # long(a)
-    def __long__(a):
-        return int(a.__num) / int(a.__den)
-
-    # float(a)
-    def __float__(a):
-        return float(a.__num) / float(a.__den)
-
-    # complex(a)
-    def __complex__(a):
-        return complex(a.__num) / complex(a.__den)
-
-    # cmp(a,b)
-    def __cmp__(a, b):
-        diff = Rat(a - b)
-        if diff.__num < 0:
-            return -1
-        elif diff.__num > 0:
-            return 1
-        else:
-            return 0
-
-    def __rcmp__(b, a):
-        return cmp(Rat(a), b)
-
-    # a != 0
-    def __bool__(a):
-        return a.__num != 0
-
-def test():
-    '''\
-    Test function for rat module.
-
-    The expected output is (module some differences in floating
-    precission):
-    -1
-    -1
-    0 0L 0.1 (0.1+0j)
-    [Rat(1,2), Rat(-3,10), Rat(1,25), Rat(1,4)]
-    [Rat(-3,10), Rat(1,25), Rat(1,4), Rat(1,2)]
-    0
-    (11/10)
-    (11/10)
-    1.1
-    OK
-    2 1.5 (3/2) (1.5+1.5j) (15707963/5000000)
-    2 2 2.0 (2+0j)
-
-    4 0 4 1 4 0
-    3.5 0.5 3.0 1.33333333333 2.82842712475 1
-    (7/2) (1/2) 3 (4/3) 2.82842712475 1
-    (3.5+1.5j) (0.5-1.5j) (3+3j) (0.666666666667-0.666666666667j) (1.43248815986+2.43884761145j) 1
-    1.5 1 1.5 (1.5+0j)
-
-    3.5 -0.5 3.0 0.75 2.25 -1
-    3.0 0.0 2.25 1.0 1.83711730709 0
-    3.0 0.0 2.25 1.0 1.83711730709 1
-    (3+1.5j) -1.5j (2.25+2.25j) (0.5-0.5j) (1.50768393746+1.04970907623j) -1
-    (3/2) 1 1.5 (1.5+0j)
-
-    (7/2) (-1/2) 3 (3/4) (9/4) -1
-    3.0 0.0 2.25 1.0 1.83711730709 -1
-    3 0 (9/4) 1 1.83711730709 0
-    (3+1.5j) -1.5j (2.25+2.25j) (0.5-0.5j) (1.50768393746+1.04970907623j) -1
-    (1.5+1.5j) (1.5+1.5j)
-
-    (3.5+1.5j) (-0.5+1.5j) (3+3j) (0.75+0.75j) 4.5j -1
-    (3+1.5j) 1.5j (2.25+2.25j) (1+1j) (1.18235814075+2.85446505899j) 1
-    (3+1.5j) 1.5j (2.25+2.25j) (1+1j) (1.18235814075+2.85446505899j) 1
-    (3+3j) 0j 4.5j (1+0j) (-0.638110484918+0.705394566962j) 0
-    '''
-    print(rat(-1, 1))
-    print(rat(1, -1))
-    a = rat(1, 10)
-    print(int(a), int(a), float(a), complex(a))
-    b = rat(2, 5)
-    l = [a+b, a-b, a*b, a/b]
-    print(l)
-    l.sort()
-    print(l)
-    print(rat(0, 1))
-    print(a+1)
-    print(a+1)
-    print(a+1.0)
-    try:
-        print(rat(1, 0))
-        raise SystemError('should have been ZeroDivisionError')
-    except ZeroDivisionError:
-        print('OK')
-    print(rat(2), rat(1.5), rat(3, 2), rat(1.5+1.5j), rat(31415926,10000000))
-    list = [2, 1.5, rat(3,2), 1.5+1.5j]
-    for i in list:
-        print(i, end=' ')
-        if not isinstance(i, complex):
-            print(int(i), float(i), end=' ')
-        print(complex(i))
-        print()
-        for j in list:
-            print(i + j, i - j, i * j, i / j, i ** j, end=' ')
-            if not (isinstance(i, complex) or
-                    isinstance(j, complex)):
-                print(cmp(i, j))
-            print()
-
-
-if __name__ == '__main__':
-    test()

Modified: python/branches/py3k-importlib/Demo/curses/repeat.py
==============================================================================
--- python/branches/py3k-importlib/Demo/curses/repeat.py	(original)
+++ python/branches/py3k-importlib/Demo/curses/repeat.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,6 @@
 #! /usr/bin/env python
 
-"""repeat <shell-command>
+"""repeat [-i SECONDS] <shell-command>
 
 This simple program repeatedly (at 1-second intervals) executes the
 shell command given on the command line and displays the output (or as
@@ -9,6 +9,8 @@
 screen doesn't change.  This is handy to watch for changes in e.g. a
 directory or process listing.
 
+The -i option lets you override the sleep time between executions.
+
 To end, hit Control-C.
 """
 
@@ -24,18 +26,30 @@
 import sys
 import time
 import curses
+import getopt
 
 def main():
-    if not sys.argv[1:]:
+    interval = 1.0
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "hi:")
+    except getopt.error as err:
+        print(err, file=sys.stderr)
+        sys.exit(2)
+    if not args:
         print(__doc__)
         sys.exit(0)
-    cmd = " ".join(sys.argv[1:])
-    p = os.popen(cmd, "r")
+    for opt, arg in opts:
+        if opt == "-i":
+            interval = float(arg)
+        if opt == "-h":
+            print(__doc__)
+            sys.exit(0)
+    cmd = " ".join(args)
+    cmd_really = cmd + " 2>&1"
+    p = os.popen(cmd_really, "r")
     text = p.read()
     sts = p.close()
-    if sts:
-        print("Exit code:", sts, file=sys.stderr)
-        sys.exit(sts)
+    text = addsts(interval, cmd, text, sts)
     w = curses.initscr()
     try:
         while True:
@@ -45,14 +59,22 @@
             except curses.error:
                 pass
             w.refresh()
-            time.sleep(1)
-            p = os.popen(cmd, "r")
+            time.sleep(interval)
+            p = os.popen(cmd_really, "r")
             text = p.read()
             sts = p.close()
-            if sts:
-                print("Exit code:", sts, file=sys.stderr)
-                sys.exit(sts)
+            text = addsts(interval, cmd, text, sts)
     finally:
         curses.endwin()
 
+def addsts(interval, cmd, text, sts):
+    now = time.strftime("%H:%M:%S")
+    text = "%s, every %g sec: %s\n%s" % (now, interval, cmd, text)
+    if sts:
+        msg = "Exit status: %d; signal: %d" % (sts>>8, sts&0xFF)
+        if text and not text.endswith("\n"):
+            msg = "\n" + msg
+        text += msg
+    return text
+
 main()

Modified: python/branches/py3k-importlib/Demo/embed/demo.c
==============================================================================
--- python/branches/py3k-importlib/Demo/embed/demo.c	(original)
+++ python/branches/py3k-importlib/Demo/embed/demo.c	Thu Mar 27 00:48:05 2008
@@ -48,7 +48,7 @@
 static PyObject *
 xyzzy_foo(PyObject *self, PyObject* args)
 {
-	return PyInt_FromLong(42L);
+	return PyLong_FromLong(42L);
 }
 
 static PyMethodDef xyzzy_methods[] = {

Modified: python/branches/py3k-importlib/Demo/imputil/knee.py
==============================================================================
--- python/branches/py3k-importlib/Demo/imputil/knee.py	(original)
+++ python/branches/py3k-importlib/Demo/imputil/knee.py	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,7 @@
 
 """
 
-import sys, imp, __builtin__
+import sys, imp, builtins
 
 
 # Replacement for __import__()
@@ -117,7 +117,7 @@
 
 
 # Save the original hooks
-original_import = __builtin__.__import__
+original_import = builtins.__import__
 
 # Now install our hooks
-__builtin__.__import__ = import_hook
+builtins.__import__ = import_hook

Modified: python/branches/py3k-importlib/Demo/newmetaclasses/Eiffel.py
==============================================================================
--- python/branches/py3k-importlib/Demo/newmetaclasses/Eiffel.py	(original)
+++ python/branches/py3k-importlib/Demo/newmetaclasses/Eiffel.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,6 @@
 """Support Eiffel-style preconditions and postconditions."""
 
-from new import function
+from types import FunctionType as function
 
 class EiffelBaseMetaClass(type):
 

Modified: python/branches/py3k-importlib/Demo/pdist/client.py
==============================================================================
--- python/branches/py3k-importlib/Demo/pdist/client.py	(original)
+++ python/branches/py3k-importlib/Demo/pdist/client.py	Thu Mar 27 00:48:05 2008
@@ -3,7 +3,7 @@
 import sys
 import socket
 import pickle
-import __builtin__
+import builtins
 import os
 
 
@@ -90,8 +90,8 @@
         if exception is None:
             return value
         x = exception
-        if hasattr(__builtin__, exception):
-            x = getattr(__builtin__, exception)
+        if hasattr(builtins, exception):
+            x = getattr(builtins, exception)
         elif exception in ('posix.error', 'mac.error'):
             x = os.error
         if x == exception:

Modified: python/branches/py3k-importlib/Demo/pdist/cvslock.py
==============================================================================
--- python/branches/py3k-importlib/Demo/pdist/cvslock.py	(original)
+++ python/branches/py3k-importlib/Demo/pdist/cvslock.py	Thu Mar 27 00:48:05 2008
@@ -131,7 +131,7 @@
                 return
             except os.error as msg:
                 self.lockdir = None
-                if msg[0] == EEXIST:
+                if msg.args[0] == EEXIST:
                     try:
                         st = os.stat(self.cvslck)
                     except os.error:

Modified: python/branches/py3k-importlib/Demo/scripts/toaiff.py
==============================================================================
--- python/branches/py3k-importlib/Demo/scripts/toaiff.py	(original)
+++ python/branches/py3k-importlib/Demo/scripts/toaiff.py	Thu Mar 27 00:48:05 2008
@@ -89,8 +89,8 @@
             ftype = ftype[0] # All we're interested in
     except IOError as msg:
         if type(msg) == type(()) and len(msg) == 2 and \
-                type(msg[0]) == type(0) and type(msg[1]) == type(''):
-            msg = msg[1]
+                type(msg.args[0]) == type(0) and type(msg.args[1]) == type(''):
+            msg = msg.args[1]
         if type(msg) != type(''):
             msg = repr(msg)
         raise error(filename + ': ' + msg)

Modified: python/branches/py3k-importlib/Demo/tkinter/guido/ShellWindow.py
==============================================================================
--- python/branches/py3k-importlib/Demo/tkinter/guido/ShellWindow.py	(original)
+++ python/branches/py3k-importlib/Demo/tkinter/guido/ShellWindow.py	Thu Mar 27 00:48:05 2008
@@ -121,11 +121,7 @@
             sys.stderr.write('popen2: bad write dup\n')
         if os.dup(c2pwrite) != 2:
             sys.stderr.write('popen2: bad write dup\n')
-        for i in range(3, MAXFD):
-            try:
-                os.close(i)
-            except:
-                pass
+        os.closerange(3, MAXFD)
         try:
             os.execvp(prog, args)
         finally:

Modified: python/branches/py3k-importlib/Doc/ACKS.txt
==============================================================================
--- python/branches/py3k-importlib/Doc/ACKS.txt	(original)
+++ python/branches/py3k-importlib/Doc/ACKS.txt	Thu Mar 27 00:48:05 2008
@@ -1,197 +1,214 @@
 Contributors to the Python Documentation
 ----------------------------------------
 
-This file lists people who have contributed in some way to the Python
+This section lists people who have contributed in some way to the Python
 documentation.  It is probably not complete -- if you feel that you or
 anyone else should be on this list, please let us know (send email to
 docs at python.org), and we'll be glad to correct the problem.
 
-* Aahz
-* Michael Abbott
-* Steve Alexander
-* Jim Ahlstrom
-* Fred Allen
-* A. Amoroso
-* Pehr Anderson
-* Oliver Andrich
-* Jesús Cea Avión
-* Daniel Barclay
-* Chris Barker
-* Don Bashford
-* Anthony Baxter
-* Bennett Benson
-* Jonathan Black
-* Robin Boerdijk
-* Michal Bozon
-* Aaron Brancotti
-* Georg Brandl
-* Keith Briggs
-* Lee Busby
-* Lorenzo M. Catucci
-* Carl Cerecke
-* Mauro Cicognini
-* Gilles Civario
-* Mike Clarkson
-* Steve Clift
-* Dave Cole
-* Matthew Cowles
-* Jeremy Craven
-* Andrew Dalke
-* Ben Darnell
-* L. Peter Deutsch
-* Robert Donohue
-* Fred L. Drake, Jr.
-* Jeff Epler
-* Michael Ernst
-* Blame Andy Eskilsson
-* Carey Evans
-* Martijn Faassen
-* Carl Feynman
-* Hernán Martínez Foffani
-* Stefan Franke
-* Jim Fulton
-* Peter Funk
-* Lele Gaifax
-* Matthew Gallagher
-* Ben Gertzfield
-* Nadim Ghaznavi
-* Jonathan Giddy
-* Shelley Gooch
-* Nathaniel Gray
-* Grant Griffin
-* Thomas Guettler
-* Anders Hammarquist
-* Mark Hammond
-* Harald Hanche-Olsen
-* Manus Hand
-* Gerhard Häring
-* Peter Harris
-* Travis B. Hartwell
-* Tim Hatch
-* Janko Hauser
-* Bernhard Herzog
-* Magnus L. Hetland
-* Konrad Hinsen
-* Stefan Hoffmeister
-* Albert Hofkamp
-* Gregor Hoffleit
-* Steve Holden
-* Thomas Holenstein
-* Gerrit Holl
-* Rob Hooft
-* Brian Hooper
-* Randall Hopper
-* Michael Hudson
-* Eric Huss
-* Jeremy Hylton
-* Roger Irwin
-* Jack Jansen
-* Philip H. Jensen
-* Pedro Diaz Jimenez
-* Kent Johnson
-* Lucas de Jonge
-* Andreas Jung
-* Robert Kern
-* Jim Kerr
-* Jan Kim
-* Greg Kochanski
-* Guido Kollerie
-* Peter A. Koren
-* Daniel Kozan
-* Andrew M. Kuchling
-* Dave Kuhlman
-* Erno Kuusela
-* Detlef Lannert
-* Piers Lauder
-* Glyph Lefkowitz
-* Marc-André Lemburg
-* Ulf A. Lindgren
-* Everett Lipman
-* Mirko Liss
-* Martin von Löwis
-* Fredrik Lundh
-* Jeff MacDonald
-* John Machin
-* Andrew MacIntyre
-* Vladimir Marangozov
-* Vincent Marchetti
-* Laura Matson
-* Daniel May
-* Doug Mennella
-* Paolo Milani
-* Skip Montanaro
-* Paul Moore
-* Ross Moore
-* Sjoerd Mullender
-* Dale Nagata
-* Ng Pheng Siong
-* Koray Oner
-* Tomas Oppelstrup
-* Denis S. Otkidach
-* Zooko O'Whielacronx
-* William Park
-* Joonas Paalasmaa
-* Harri Pasanen
-* Bo Peng
-* Tim Peters
-* Christopher Petrilli
-* Justin D. Pettit
-* Chris Phoenix
-* François Pinard
-* Paul Prescod
-* Eric S. Raymond
-* Edward K. Ream
-* Sean Reifschneider
-* Bernhard Reiter
-* Armin Rigo
-* Wes Rishel
-* Jim Roskind
-* Guido van Rossum
-* Donald Wallace Rouse II
-* Nick Russo
-* Chris Ryland
-* Constantina S.
-* Hugh Sasse
-* Bob Savage
-* Scott Schram
-* Neil Schemenauer
-* Barry Scott
-* Joakim Sernbrant
-* Justin Sheehy
-* Michael Simcich
-* Ionel Simionescu
-* Gregory P. Smith
-* Roy Smith
-* Clay Spence
-* Nicholas Spies
-* Tage Stabell-Kulo
-* Frank Stajano
-* Anthony Starks
-* Greg Stein
-* Peter Stoehr
-* Mark Summerfield
-* Reuben Sumner
-* Kalle Svensson
-* Jim Tittsler
-* Ville Vainio
-* Martijn Vries
-* Charles G. Waldman
-* Greg Ward
-* Barry Warsaw
-* Corran Webster
-* Glyn Webster
-* Bob Weiner
-* Eddy Welbourne
-* Mats Wichmann
-* Gerry Wiener
-* Timothy Wild
-* Collin Winter
-* Blake Winton
-* Dan Wolfe
-* Steven Work
-* Thomas Wouters
-* Ka-Ping Yee
-* Rory Yorke
-* Moshe Zadka
-* Milan Zamazal
-* Cheng Zhang
+.. acks::
+
+   * Aahz
+   * Michael Abbott
+   * Steve Alexander
+   * Jim Ahlstrom
+   * Fred Allen
+   * A. Amoroso
+   * Pehr Anderson
+   * Oliver Andrich
+   * Jesús Cea Avión
+   * Daniel Barclay
+   * Chris Barker
+   * Don Bashford
+   * Anthony Baxter
+   * Alexander Belopolsky
+   * Bennett Benson
+   * Jonathan Black
+   * Robin Boerdijk
+   * Michal Bozon
+   * Aaron Brancotti
+   * Georg Brandl
+   * Keith Briggs
+   * Ian Bruntlett
+   * Lee Busby
+   * Lorenzo M. Catucci
+   * Carl Cerecke
+   * Mauro Cicognini
+   * Gilles Civario
+   * Mike Clarkson
+   * Steve Clift
+   * Dave Cole
+   * Matthew Cowles
+   * Jeremy Craven
+   * Andrew Dalke
+   * Ben Darnell
+   * L. Peter Deutsch
+   * Robert Donohue
+   * Fred L. Drake, Jr.
+   * Josip Dzolonga
+   * Jeff Epler
+   * Michael Ernst
+   * Blame Andy Eskilsson
+   * Carey Evans
+   * Martijn Faassen
+   * Carl Feynman
+   * Dan Finnie
+   * Hernán Martínez Foffani
+   * Stefan Franke
+   * Jim Fulton
+   * Peter Funk
+   * Lele Gaifax
+   * Matthew Gallagher
+   * Ben Gertzfield
+   * Nadim Ghaznavi
+   * Jonathan Giddy
+   * Shelley Gooch
+   * Nathaniel Gray
+   * Grant Griffin
+   * Thomas Guettler
+   * Anders Hammarquist
+   * Mark Hammond
+   * Harald Hanche-Olsen
+   * Manus Hand
+   * Gerhard Häring
+   * Travis B. Hartwell
+   * Tim Hatch
+   * Janko Hauser
+   * Thomas Heller
+   * Bernhard Herzog
+   * Magnus L. Hetland
+   * Konrad Hinsen
+   * Stefan Hoffmeister
+   * Albert Hofkamp
+   * Gregor Hoffleit
+   * Steve Holden
+   * Thomas Holenstein
+   * Gerrit Holl
+   * Rob Hooft
+   * Brian Hooper
+   * Randall Hopper
+   * Michael Hudson
+   * Eric Huss
+   * Jeremy Hylton
+   * Roger Irwin
+   * Jack Jansen
+   * Philip H. Jensen
+   * Pedro Diaz Jimenez
+   * Kent Johnson
+   * Lucas de Jonge
+   * Andreas Jung
+   * Robert Kern
+   * Jim Kerr
+   * Jan Kim
+   * Greg Kochanski
+   * Guido Kollerie
+   * Peter A. Koren
+   * Daniel Kozan
+   * Andrew M. Kuchling
+   * Dave Kuhlman
+   * Erno Kuusela
+   * Thomas Lamb
+   * Detlef Lannert
+   * Piers Lauder
+   * Glyph Lefkowitz
+   * Robert Lehmann
+   * Marc-André Lemburg
+   * Ross Light
+   * Ulf A. Lindgren
+   * Everett Lipman
+   * Mirko Liss
+   * Martin von Löwis
+   * Fredrik Lundh
+   * Jeff MacDonald
+   * John Machin
+   * Andrew MacIntyre
+   * Vladimir Marangozov
+   * Vincent Marchetti
+   * Laura Matson
+   * Daniel May
+   * Rebecca McCreary
+   * Doug Mennella
+   * Paolo Milani
+   * Skip Montanaro
+   * Paul Moore
+   * Ross Moore
+   * Sjoerd Mullender
+   * Dale Nagata
+   * Ng Pheng Siong
+   * Koray Oner
+   * Tomas Oppelstrup
+   * Denis S. Otkidach
+   * Zooko O'Whielacronx
+   * Shriphani Palakodety
+   * William Park
+   * Joonas Paalasmaa
+   * Harri Pasanen
+   * Bo Peng
+   * Tim Peters
+   * Christopher Petrilli
+   * Justin D. Pettit
+   * Chris Phoenix
+   * François Pinard
+   * Paul Prescod
+   * Eric S. Raymond
+   * Edward K. Ream
+   * Sean Reifschneider
+   * Bernhard Reiter
+   * Armin Rigo
+   * Wes Rishel
+   * Jim Roskind
+   * Guido van Rossum
+   * Donald Wallace Rouse II
+   * Mark Russell
+   * Nick Russo
+   * Chris Ryland
+   * Constantina S.
+   * Hugh Sasse
+   * Bob Savage
+   * Scott Schram
+   * Neil Schemenauer
+   * Barry Scott
+   * Joakim Sernbrant
+   * Justin Sheehy
+   * Charlie Shepherd
+   * Michael Simcich
+   * Ionel Simionescu
+   * Michael Sloan
+   * Gregory P. Smith
+   * Roy Smith
+   * Clay Spence
+   * Nicholas Spies
+   * Tage Stabell-Kulo
+   * Frank Stajano
+   * Anthony Starks
+   * Greg Stein
+   * Peter Stoehr
+   * Mark Summerfield
+   * Reuben Sumner
+   * Kalle Svensson
+   * Jim Tittsler
+   * Ville Vainio
+   * Martijn Vries
+   * Charles G. Waldman
+   * Greg Ward
+   * Barry Warsaw
+   * Corran Webster
+   * Glyn Webster
+   * Bob Weiner
+   * Eddy Welbourne
+   * Jeff Wheeler
+   * Mats Wichmann
+   * Gerry Wiener
+   * Timothy Wild
+   * Collin Winter
+   * Blake Winton
+   * Dan Wolfe
+   * Steven Work
+   * Thomas Wouters
+   * Ka-Ping Yee
+   * Rory Yorke
+   * Moshe Zadka
+   * Milan Zamazal
+   * Cheng Zhang
+   * Trent Nelson
+   * Michael Foord

Modified: python/branches/py3k-importlib/Doc/Makefile
==============================================================================
--- python/branches/py3k-importlib/Doc/Makefile	(original)
+++ python/branches/py3k-importlib/Doc/Makefile	Thu Mar 27 00:48:05 2008
@@ -7,16 +7,23 @@
 PYTHON       = python2.5
 SVNROOT      = http://svn.python.org/projects
 SPHINXOPTS   =
+PAPER        =
+SOURCES      =
 
-ALLSPHINXOPTS = -b$(BUILDER) -dbuild/doctrees $(SPHINXOPTS) . build/$(BUILDER)
+ALLSPHINXOPTS = -b $(BUILDER) -d build/doctrees -D latex_paper_size=$(PAPER) \
+                $(SPHINXOPTS) . build/$(BUILDER) $(SOURCES)
 
-.PHONY: help checkout update build html web htmlhelp clean
+.PHONY: help checkout update build html web htmlhelp clean coverage
 
 help:
 	@echo "Please use \`make <target>' where <target> is one of"
-	@echo "  html  to make standalone HTML files"
-	@echo "  web   to make file usable by Sphinx.web"
-	@echo "  htmlhelp to make HTML files and a HTML help project"
+	@echo "  html      to make standalone HTML files"
+	@echo "  web       to make file usable by Sphinx.web"
+	@echo "  htmlhelp  to make HTML files and a HTML help project"
+	@echo "  latex     to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+	@echo "  changes   to make an overview over all changed/added/deprecated items"
+	@echo "  linkcheck to check all external links for integrity"
+	@echo "  coverage  to check documentation coverage for library and C API"
 
 checkout:
 	@if [ ! -d tools/sphinx ]; then \
@@ -29,7 +36,7 @@
 	fi
 	@if [ ! -d tools/pygments ]; then \
 	  echo "Checking out Pygments..."; \
-	  svn checkout $(SVNROOT)/external/Pygments-0.8.1/pygments tools/pygments; \
+	  svn checkout $(SVNROOT)/external/Pygments-0.9/pygments tools/pygments; \
 	fi
 
 update: checkout
@@ -57,6 +64,30 @@
 	@echo "Build finished; now you can run HTML Help Workshop with the" \
 	      "build/htmlhelp/pydoc.hhp project file."
 
+latex: BUILDER = latex
+latex: build
+	@echo "Build finished; the LaTeX files are in build/latex."
+	@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
+	      "run these through (pdf)latex."
+
+changes: BUILDER = changes
+changes: build
+	@echo "The overview file is in build/changes."
+
+linkcheck: BUILDER = linkcheck
+linkcheck: build
+	@echo "Link check complete; look for any errors in the above output " \
+	      "or in build/$(BUILDER)/output.txt"
+
+coverage: BUILDER = coverage
+coverage: build
+	@echo "Coverage finished; see c.txt and python.txt in build/coverage"
+
+doctest: BUILDER = doctest
+doctest: build
+	@echo "Testing of doctests in the sources finished, look at the " \
+	      "results in build/doctest/output.txt"
+
 clean:
 	-rm -rf build/*
 	-rm -rf tools/sphinx

Modified: python/branches/py3k-importlib/Doc/README.txt
==============================================================================
--- python/branches/py3k-importlib/Doc/README.txt	(original)
+++ python/branches/py3k-importlib/Doc/README.txt	Thu Mar 27 00:48:05 2008
@@ -14,7 +14,7 @@
 Building the docs
 =================
 
-You need to install Python 2.5.1 or higher (but Python 3.0 is not supported yet);
+You need to install Python 2.4 or higher (but Python 3.0 is not supported yet);
 the toolset used to build the docs are written in Python.  The toolset used
 to build the documentation is called *Sphinx*, it is not included in this
 tree, but maintained separately in the Python Subversion repository.  Also
@@ -53,6 +53,20 @@
    To create the CHM file, you need to run the Microsoft HTML Help Workshop
    over the generated project (.hhp) file.
 
+ * "latex", which builds LaTeX source files that can be run with "pdflatex"
+   to produce PDF documents.
+
+ * "linkcheck", which checks all external references to see whether they are
+   broken, redirected or malformed, and outputs this information to stdout
+   as well as a plain-text (.txt) file.
+
+ * "changes", which builds an overview over all versionadded/versionchanged/
+   deprecated items in the current version. This is meant as a help for the
+   writer of the "What's New" document.
+
+ * "coverage", which builds a coverage overview for standard library modules
+   and C API.
+
 A "make update" updates the Subversion checkouts in `tools/`.
 
 
@@ -72,7 +86,7 @@
 
 You can optionally also install Pygments, either as a checkout via :: 
 
-   svn co http://svn.python.org/projects/external/Pygments-0.8.1/pygments tools/pygments
+   svn co http://svn.python.org/projects/external/Pygments-0.9/pygments tools/pygments
 
 or from PyPI at http://pypi.python.org/pypi/Pygments.
 
@@ -109,7 +123,7 @@
 as long as you don't change or remove the copyright notice:
 
 ----------------------------------------------------------------------
-Copyright (c) 2000-2007 Python Software Foundation.
+Copyright (c) 2000-2008 Python Software Foundation.
 All rights reserved.
 
 Copyright (c) 2000 BeOpen.com.

Modified: python/branches/py3k-importlib/Doc/bugs.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/bugs.rst	(original)
+++ python/branches/py3k-importlib/Doc/bugs.rst	Thu Mar 27 00:48:05 2008
@@ -49,11 +49,11 @@
 
 .. seealso::
 
-   `How to Report Bugs Effectively <http://www-mice.cs.ucl.ac.uk/multimedia/software/documentation/ReportingBugs.html>`_
+   `How to Report Bugs Effectively <http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>`_
       Article which goes into some detail about how to create a useful bug report.
       This describes what kind of information is useful and why it is useful.
 
-   `Bug Writing Guidelines <http://www.mozilla.org/quality/bug-writing-guidelines.html>`_
+   `Bug Writing Guidelines <http://developer.mozilla.org/en/docs/Bug_writing_guidelines>`_
       Information about writing a good bug report.  Some of this is specific to the
       Mozilla project, but describes general good practices.
 

Modified: python/branches/py3k-importlib/Doc/c-api/abstract.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/c-api/abstract.rst	(original)
+++ python/branches/py3k-importlib/Doc/c-api/abstract.rst	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,5 @@
 .. highlightlang:: c
 
-
 .. _abstract:
 
 **********************
@@ -16,936 +15,11 @@
 initialized, such as a list object that has been created by :cfunc:`PyList_New`,
 but whose items have not been set to some non-\ ``NULL`` value yet.
 
+.. toctree::
 
-.. _object:
-
-Object Protocol
-===============
-
-
-.. cfunction:: int PyObject_Print(PyObject *o, FILE *fp, int flags)
-
-   Print an object *o*, on file *fp*.  Returns ``-1`` on error.  The flags argument
-   is used to enable certain printing options.  The only option currently supported
-   is :const:`Py_PRINT_RAW`; if given, the :func:`str` of the object is written
-   instead of the :func:`repr`.
-
-
-.. cfunction:: int PyObject_HasAttrString(PyObject *o, const char *attr_name)
-
-   Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise.  This
-   is equivalent to the Python expression ``hasattr(o, attr_name)``.  This function
-   always succeeds.
-
-
-.. cfunction:: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name)
-
-   Retrieve an attribute named *attr_name* from object *o*. Returns the attribute
-   value on success, or *NULL* on failure. This is the equivalent of the Python
-   expression ``o.attr_name``.
-
-
-.. cfunction:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name)
-
-   Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise.  This
-   is equivalent to the Python expression ``hasattr(o, attr_name)``.  This function
-   always succeeds.
-
-
-.. cfunction:: PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name)
-
-   Retrieve an attribute named *attr_name* from object *o*. Returns the attribute
-   value on success, or *NULL* on failure.  This is the equivalent of the Python
-   expression ``o.attr_name``.
-
-
-.. cfunction:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v)
-
-   Set the value of the attribute named *attr_name*, for object *o*, to the value
-   *v*. Returns ``-1`` on failure.  This is the equivalent of the Python statement
-   ``o.attr_name = v``.
-
-
-.. cfunction:: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v)
-
-   Set the value of the attribute named *attr_name*, for object *o*, to the value
-   *v*. Returns ``-1`` on failure.  This is the equivalent of the Python statement
-   ``o.attr_name = v``.
-
-
-.. cfunction:: int PyObject_DelAttrString(PyObject *o, const char *attr_name)
-
-   Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure.
-   This is the equivalent of the Python statement: ``del o.attr_name``.
-
-
-.. cfunction:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name)
-
-   Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure.
-   This is the equivalent of the Python statement ``del o.attr_name``.
-
-
-.. cfunction:: PyObject* PyObject_RichCompare(PyObject *o1, PyObject *o2, int opid)
-
-   Compare the values of *o1* and *o2* using the operation specified by *opid*,
-   which must be one of :const:`Py_LT`, :const:`Py_LE`, :const:`Py_EQ`,
-   :const:`Py_NE`, :const:`Py_GT`, or :const:`Py_GE`, corresponding to ``<``,
-   ``<=``, ``==``, ``!=``, ``>``, or ``>=`` respectively. This is the equivalent of
-   the Python expression ``o1 op o2``, where ``op`` is the operator corresponding
-   to *opid*. Returns the value of the comparison on success, or *NULL* on failure.
-
-
-.. cfunction:: int PyObject_RichCompareBool(PyObject *o1, PyObject *o2, int opid)
-
-   Compare the values of *o1* and *o2* using the operation specified by *opid*,
-   which must be one of :const:`Py_LT`, :const:`Py_LE`, :const:`Py_EQ`,
-   :const:`Py_NE`, :const:`Py_GT`, or :const:`Py_GE`, corresponding to ``<``,
-   ``<=``, ``==``, ``!=``, ``>``, or ``>=`` respectively. Returns ``-1`` on error,
-   ``0`` if the result is false, ``1`` otherwise. This is the equivalent of the
-   Python expression ``o1 op o2``, where ``op`` is the operator corresponding to
-   *opid*.
-
-
-.. cfunction:: int PyObject_Cmp(PyObject *o1, PyObject *o2, int *result)
-
-   .. index:: builtin: cmp
-
-   Compare the values of *o1* and *o2* using a routine provided by *o1*, if one
-   exists, otherwise with a routine provided by *o2*.  The result of the comparison
-   is returned in *result*.  Returns ``-1`` on failure.  This is the equivalent of
-   the Python statement ``result = cmp(o1, o2)``.
-
-
-.. cfunction:: int PyObject_Compare(PyObject *o1, PyObject *o2)
-
-   .. index:: builtin: cmp
-
-   Compare the values of *o1* and *o2* using a routine provided by *o1*, if one
-   exists, otherwise with a routine provided by *o2*.  Returns the result of the
-   comparison on success.  On error, the value returned is undefined; use
-   :cfunc:`PyErr_Occurred` to detect an error.  This is equivalent to the Python
-   expression ``cmp(o1, o2)``.
-
-
-.. cfunction:: PyObject* PyObject_Repr(PyObject *o)
-
-   .. index:: builtin: repr
-
-   Compute a string representation of object *o*.  Returns the string
-   representation on success, *NULL* on failure.  This is the equivalent of the
-   Python expression ``repr(o)``.  Called by the :func:`repr` built-in function and
-   by reverse quotes.
-
-
-.. cfunction:: PyObject* PyObject_Str(PyObject *o)
-
-   .. index:: builtin: str
-
-   Compute a string representation of object *o*.  Returns the string
-   representation on success, *NULL* on failure.  This is the equivalent of the
-   Python expression ``str(o)``.  Called by the :func:`str` built-in function
-   and, therefore, by the :func:`print` function.
-
-
-.. cfunction:: PyObject* PyObject_Unicode(PyObject *o)
-
-   .. index:: builtin: unicode
-
-   Compute a Unicode string representation of object *o*.  Returns the Unicode
-   string representation on success, *NULL* on failure. This is the equivalent of
-   the Python expression ``unicode(o)``.  Called by the :func:`unicode` built-in
-   function.
-
-
-.. cfunction:: int PyObject_IsInstance(PyObject *inst, PyObject *cls)
-
-   Returns ``1`` if *inst* is an instance of the class *cls* or a subclass of
-   *cls*, or ``0`` if not.  On error, returns ``-1`` and sets an exception.  If
-   *cls* is a type object rather than a class object, :cfunc:`PyObject_IsInstance`
-   returns ``1`` if *inst* is of type *cls*.  If *cls* is a tuple, the check will
-   be done against every entry in *cls*. The result will be ``1`` when at least one
-   of the checks returns ``1``, otherwise it will be ``0``. If *inst* is not a
-   class instance and *cls* is neither a type object, nor a class object, nor a
-   tuple, *inst* must have a :attr:`__class__` attribute --- the class relationship
-   of the value of that attribute with *cls* will be used to determine the result
-   of this function.
-
-
-Subclass determination is done in a fairly straightforward way, but includes a
-wrinkle that implementors of extensions to the class system may want to be aware
-of.  If :class:`A` and :class:`B` are class objects, :class:`B` is a subclass of
-:class:`A` if it inherits from :class:`A` either directly or indirectly.  If
-either is not a class object, a more general mechanism is used to determine the
-class relationship of the two objects.  When testing if *B* is a subclass of
-*A*, if *A* is *B*, :cfunc:`PyObject_IsSubclass` returns true.  If *A* and *B*
-are different objects, *B*'s :attr:`__bases__` attribute is searched in a
-depth-first fashion for *A* --- the presence of the :attr:`__bases__` attribute
-is considered sufficient for this determination.
-
-
-.. cfunction:: int PyObject_IsSubclass(PyObject *derived, PyObject *cls)
-
-   Returns ``1`` if the class *derived* is identical to or derived from the class
-   *cls*, otherwise returns ``0``.  In case of an error, returns ``-1``. If *cls*
-   is a tuple, the check will be done against every entry in *cls*. The result will
-   be ``1`` when at least one of the checks returns ``1``, otherwise it will be
-   ``0``. If either *derived* or *cls* is not an actual class object (or tuple),
-   this function uses the generic algorithm described above.
-
-
-.. cfunction:: int PyCallable_Check(PyObject *o)
-
-   Determine if the object *o* is callable.  Return ``1`` if the object is callable
-   and ``0`` otherwise.  This function always succeeds.
-
-
-.. cfunction:: PyObject* PyObject_Call(PyObject *callable_object, PyObject *args, PyObject *kw)
-
-   Call a callable Python object *callable_object*, with arguments given by the
-   tuple *args*, and named arguments given by the dictionary *kw*. If no named
-   arguments are needed, *kw* may be *NULL*. *args* must not be *NULL*, use an
-   empty tuple if no arguments are needed. Returns the result of the call on
-   success, or *NULL* on failure.  This is the equivalent of the Python expression
-   ``callable_object(*args, **kw)``.
-
-
-.. cfunction:: PyObject* PyObject_CallObject(PyObject *callable_object, PyObject *args)
-
-   Call a callable Python object *callable_object*, with arguments given by the
-   tuple *args*.  If no arguments are needed, then *args* may be *NULL*.  Returns
-   the result of the call on success, or *NULL* on failure.  This is the equivalent
-   of the Python expression ``callable_object(*args)``.
-
-
-.. cfunction:: PyObject* PyObject_CallFunction(PyObject *callable, char *format, ...)
-
-   Call a callable Python object *callable*, with a variable number of C arguments.
-   The C arguments are described using a :cfunc:`Py_BuildValue` style format
-   string.  The format may be *NULL*, indicating that no arguments are provided.
-   Returns the result of the call on success, or *NULL* on failure.  This is the
-   equivalent of the Python expression ``callable(*args)``. Note that if you only
-   pass :ctype:`PyObject \*` args, :cfunc:`PyObject_CallFunctionObjArgs` is a
-   faster alternative.
-
-
-.. cfunction:: PyObject* PyObject_CallMethod(PyObject *o, char *method, char *format, ...)
-
-   Call the method named *method* of object *o* with a variable number of C
-   arguments.  The C arguments are described by a :cfunc:`Py_BuildValue` format
-   string that should  produce a tuple.  The format may be *NULL*, indicating that
-   no arguments are provided. Returns the result of the call on success, or *NULL*
-   on failure.  This is the equivalent of the Python expression ``o.method(args)``.
-   Note that if you only pass :ctype:`PyObject \*` args,
-   :cfunc:`PyObject_CallMethodObjArgs` is a faster alternative.
-
-
-.. cfunction:: PyObject* PyObject_CallFunctionObjArgs(PyObject *callable, ..., NULL)
-
-   Call a callable Python object *callable*, with a variable number of
-   :ctype:`PyObject\*` arguments.  The arguments are provided as a variable number
-   of parameters followed by *NULL*. Returns the result of the call on success, or
-   *NULL* on failure.
-
-
-.. cfunction:: PyObject* PyObject_CallMethodObjArgs(PyObject *o, PyObject *name, ..., NULL)
-
-   Calls a method of the object *o*, where the name of the method is given as a
-   Python string object in *name*.  It is called with a variable number of
-   :ctype:`PyObject\*` arguments.  The arguments are provided as a variable number
-   of parameters followed by *NULL*. Returns the result of the call on success, or
-   *NULL* on failure.
-
-
-.. cfunction:: long PyObject_Hash(PyObject *o)
-
-   .. index:: builtin: hash
-
-   Compute and return the hash value of an object *o*.  On failure, return ``-1``.
-   This is the equivalent of the Python expression ``hash(o)``.
-
-
-.. cfunction:: int PyObject_IsTrue(PyObject *o)
-
-   Returns ``1`` if the object *o* is considered to be true, and ``0`` otherwise.
-   This is equivalent to the Python expression ``not not o``.  On failure, return
-   ``-1``.
-
-
-.. cfunction:: int PyObject_Not(PyObject *o)
-
-   Returns ``0`` if the object *o* is considered to be true, and ``1`` otherwise.
-   This is equivalent to the Python expression ``not o``.  On failure, return
-   ``-1``.
-
-
-.. cfunction:: PyObject* PyObject_Type(PyObject *o)
-
-   .. index:: builtin: type
-
-   When *o* is non-*NULL*, returns a type object corresponding to the object type
-   of object *o*. On failure, raises :exc:`SystemError` and returns *NULL*.  This
-   is equivalent to the Python expression ``type(o)``. This function increments the
-   reference count of the return value. There's really no reason to use this
-   function instead of the common expression ``o->ob_type``, which returns a
-   pointer of type :ctype:`PyTypeObject\*`, except when the incremented reference
-   count is needed.
-
-
-.. cfunction:: int PyObject_TypeCheck(PyObject *o, PyTypeObject *type)
-
-   Return true if the object *o* is of type *type* or a subtype of *type*.  Both
-   parameters must be non-*NULL*.
-
-
-.. cfunction:: Py_ssize_t PyObject_Length(PyObject *o)
-               Py_ssize_t PyObject_Size(PyObject *o)
-
-   .. index:: builtin: len
-
-   Return the length of object *o*.  If the object *o* provides either the sequence
-   and mapping protocols, the sequence length is returned.  On error, ``-1`` is
-   returned.  This is the equivalent to the Python expression ``len(o)``.
-
-
-.. cfunction:: PyObject* PyObject_GetItem(PyObject *o, PyObject *key)
-
-   Return element of *o* corresponding to the object *key* or *NULL* on failure.
-   This is the equivalent of the Python expression ``o[key]``.
-
-
-.. cfunction:: int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v)
-
-   Map the object *key* to the value *v*.  Returns ``-1`` on failure.  This is the
-   equivalent of the Python statement ``o[key] = v``.
-
-
-.. cfunction:: int PyObject_DelItem(PyObject *o, PyObject *key)
-
-   Delete the mapping for *key* from *o*.  Returns ``-1`` on failure. This is the
-   equivalent of the Python statement ``del o[key]``.
-
-
-.. cfunction:: int PyObject_AsFileDescriptor(PyObject *o)
-
-   Derives a file-descriptor from a Python object.  If the object is an integer or
-   long integer, its value is returned.  If not, the object's :meth:`fileno` method
-   is called if it exists; the method must return an integer or long integer, which
-   is returned as the file descriptor value.  Returns ``-1`` on failure.
-
-
-.. cfunction:: PyObject* PyObject_Dir(PyObject *o)
-
-   This is equivalent to the Python expression ``dir(o)``, returning a (possibly
-   empty) list of strings appropriate for the object argument, or *NULL* if there
-   was an error.  If the argument is *NULL*, this is like the Python ``dir()``,
-   returning the names of the current locals; in this case, if no execution frame
-   is active then *NULL* is returned but :cfunc:`PyErr_Occurred` will return false.
-
-
-.. cfunction:: PyObject* PyObject_GetIter(PyObject *o)
-
-   This is equivalent to the Python expression ``iter(o)``. It returns a new
-   iterator for the object argument, or the object  itself if the object is already
-   an iterator.  Raises :exc:`TypeError` and returns *NULL* if the object cannot be
-   iterated.
-
-
-.. _number:
-
-Number Protocol
-===============
-
-
-.. cfunction:: int PyNumber_Check(PyObject *o)
-
-   Returns ``1`` if the object *o* provides numeric protocols, and false otherwise.
-   This function always succeeds.
-
-
-.. cfunction:: PyObject* PyNumber_Add(PyObject *o1, PyObject *o2)
-
-   Returns the result of adding *o1* and *o2*, or *NULL* on failure.  This is the
-   equivalent of the Python expression ``o1 + o2``.
-
-
-.. cfunction:: PyObject* PyNumber_Subtract(PyObject *o1, PyObject *o2)
-
-   Returns the result of subtracting *o2* from *o1*, or *NULL* on failure.  This is
-   the equivalent of the Python expression ``o1 - o2``.
-
-
-.. cfunction:: PyObject* PyNumber_Multiply(PyObject *o1, PyObject *o2)
-
-   Returns the result of multiplying *o1* and *o2*, or *NULL* on failure.  This is
-   the equivalent of the Python expression ``o1 * o2``.
-
-
-.. cfunction:: PyObject* PyNumber_Divide(PyObject *o1, PyObject *o2)
-
-   Returns the result of dividing *o1* by *o2*, or *NULL* on failure.  This is the
-   equivalent of the Python expression ``o1 / o2``.
-
-
-.. cfunction:: PyObject* PyNumber_FloorDivide(PyObject *o1, PyObject *o2)
-
-   Return the floor of *o1* divided by *o2*, or *NULL* on failure.  This is
-   equivalent to the "classic" division of integers.
-
-
-.. cfunction:: PyObject* PyNumber_TrueDivide(PyObject *o1, PyObject *o2)
-
-   Return a reasonable approximation for the mathematical value of *o1* divided by
-   *o2*, or *NULL* on failure.  The return value is "approximate" because binary
-   floating point numbers are approximate; it is not possible to represent all real
-   numbers in base two.  This function can return a floating point value when
-   passed two integers.
-
-
-.. cfunction:: PyObject* PyNumber_Remainder(PyObject *o1, PyObject *o2)
-
-   Returns the remainder of dividing *o1* by *o2*, or *NULL* on failure.  This is
-   the equivalent of the Python expression ``o1 % o2``.
-
-
-.. cfunction:: PyObject* PyNumber_Divmod(PyObject *o1, PyObject *o2)
-
-   .. index:: builtin: divmod
-
-   See the built-in function :func:`divmod`. Returns *NULL* on failure.  This is
-   the equivalent of the Python expression ``divmod(o1, o2)``.
-
-
-.. cfunction:: PyObject* PyNumber_Power(PyObject *o1, PyObject *o2, PyObject *o3)
-
-   .. index:: builtin: pow
-
-   See the built-in function :func:`pow`. Returns *NULL* on failure.  This is the
-   equivalent of the Python expression ``pow(o1, o2, o3)``, where *o3* is optional.
-   If *o3* is to be ignored, pass :cdata:`Py_None` in its place (passing *NULL* for
-   *o3* would cause an illegal memory access).
-
-
-.. cfunction:: PyObject* PyNumber_Negative(PyObject *o)
-
-   Returns the negation of *o* on success, or *NULL* on failure. This is the
-   equivalent of the Python expression ``-o``.
-
-
-.. cfunction:: PyObject* PyNumber_Positive(PyObject *o)
-
-   Returns *o* on success, or *NULL* on failure.  This is the equivalent of the
-   Python expression ``+o``.
-
-
-.. cfunction:: PyObject* PyNumber_Absolute(PyObject *o)
-
-   .. index:: builtin: abs
-
-   Returns the absolute value of *o*, or *NULL* on failure.  This is the equivalent
-   of the Python expression ``abs(o)``.
-
-
-.. cfunction:: PyObject* PyNumber_Invert(PyObject *o)
-
-   Returns the bitwise negation of *o* on success, or *NULL* on failure.  This is
-   the equivalent of the Python expression ``~o``.
-
-
-.. cfunction:: PyObject* PyNumber_Lshift(PyObject *o1, PyObject *o2)
-
-   Returns the result of left shifting *o1* by *o2* on success, or *NULL* on
-   failure.  This is the equivalent of the Python expression ``o1 << o2``.
-
-
-.. cfunction:: PyObject* PyNumber_Rshift(PyObject *o1, PyObject *o2)
-
-   Returns the result of right shifting *o1* by *o2* on success, or *NULL* on
-   failure.  This is the equivalent of the Python expression ``o1 >> o2``.
-
-
-.. cfunction:: PyObject* PyNumber_And(PyObject *o1, PyObject *o2)
-
-   Returns the "bitwise and" of *o1* and *o2* on success and *NULL* on failure.
-   This is the equivalent of the Python expression ``o1 & o2``.
-
-
-.. cfunction:: PyObject* PyNumber_Xor(PyObject *o1, PyObject *o2)
-
-   Returns the "bitwise exclusive or" of *o1* by *o2* on success, or *NULL* on
-   failure.  This is the equivalent of the Python expression ``o1 ^ o2``.
-
-
-.. cfunction:: PyObject* PyNumber_Or(PyObject *o1, PyObject *o2)
-
-   Returns the "bitwise or" of *o1* and *o2* on success, or *NULL* on failure.
-   This is the equivalent of the Python expression ``o1 | o2``.
-
-
-.. cfunction:: PyObject* PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2)
-
-   Returns the result of adding *o1* and *o2*, or *NULL* on failure.  The operation
-   is done *in-place* when *o1* supports it.  This is the equivalent of the Python
-   statement ``o1 += o2``.
-
-
-.. cfunction:: PyObject* PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2)
-
-   Returns the result of subtracting *o2* from *o1*, or *NULL* on failure.  The
-   operation is done *in-place* when *o1* supports it.  This is the equivalent of
-   the Python statement ``o1 -= o2``.
-
-
-.. cfunction:: PyObject* PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2)
-
-   Returns the result of multiplying *o1* and *o2*, or *NULL* on failure.  The
-   operation is done *in-place* when *o1* supports it.  This is the equivalent of
-   the Python statement ``o1 *= o2``.
-
-
-.. cfunction:: PyObject* PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2)
-
-   Returns the result of dividing *o1* by *o2*, or *NULL* on failure.  The
-   operation is done *in-place* when *o1* supports it. This is the equivalent of
-   the Python statement ``o1 /= o2``.
-
-
-.. cfunction:: PyObject* PyNumber_InPlaceFloorDivide(PyObject *o1, PyObject *o2)
-
-   Returns the mathematical floor of dividing *o1* by *o2*, or *NULL* on failure.
-   The operation is done *in-place* when *o1* supports it.  This is the equivalent
-   of the Python statement ``o1 //= o2``.
-
-
-.. cfunction:: PyObject* PyNumber_InPlaceTrueDivide(PyObject *o1, PyObject *o2)
-
-   Return a reasonable approximation for the mathematical value of *o1* divided by
-   *o2*, or *NULL* on failure.  The return value is "approximate" because binary
-   floating point numbers are approximate; it is not possible to represent all real
-   numbers in base two.  This function can return a floating point value when
-   passed two integers.  The operation is done *in-place* when *o1* supports it.
-
-
-.. cfunction:: PyObject* PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2)
-
-   Returns the remainder of dividing *o1* by *o2*, or *NULL* on failure.  The
-   operation is done *in-place* when *o1* supports it.  This is the equivalent of
-   the Python statement ``o1 %= o2``.
-
-
-.. cfunction:: PyObject* PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject *o3)
-
-   .. index:: builtin: pow
-
-   See the built-in function :func:`pow`. Returns *NULL* on failure.  The operation
-   is done *in-place* when *o1* supports it.  This is the equivalent of the Python
-   statement ``o1 **= o2`` when o3 is :cdata:`Py_None`, or an in-place variant of
-   ``pow(o1, o2, o3)`` otherwise. If *o3* is to be ignored, pass :cdata:`Py_None`
-   in its place (passing *NULL* for *o3* would cause an illegal memory access).
-
-
-.. cfunction:: PyObject* PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2)
-
-   Returns the result of left shifting *o1* by *o2* on success, or *NULL* on
-   failure.  The operation is done *in-place* when *o1* supports it.  This is the
-   equivalent of the Python statement ``o1 <<= o2``.
-
-
-.. cfunction:: PyObject* PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2)
-
-   Returns the result of right shifting *o1* by *o2* on success, or *NULL* on
-   failure.  The operation is done *in-place* when *o1* supports it.  This is the
-   equivalent of the Python statement ``o1 >>= o2``.
-
-
-.. cfunction:: PyObject* PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2)
-
-   Returns the "bitwise and" of *o1* and *o2* on success and *NULL* on failure. The
-   operation is done *in-place* when *o1* supports it.  This is the equivalent of
-   the Python statement ``o1 &= o2``.
-
-
-.. cfunction:: PyObject* PyNumber_InPlaceXor(PyObject *o1, PyObject *o2)
-
-   Returns the "bitwise exclusive or" of *o1* by *o2* on success, or *NULL* on
-   failure.  The operation is done *in-place* when *o1* supports it.  This is the
-   equivalent of the Python statement ``o1 ^= o2``.
-
-
-.. cfunction:: PyObject* PyNumber_InPlaceOr(PyObject *o1, PyObject *o2)
-
-   Returns the "bitwise or" of *o1* and *o2* on success, or *NULL* on failure.  The
-   operation is done *in-place* when *o1* supports it.  This is the equivalent of
-   the Python statement ``o1 |= o2``.
-
-
-.. cfunction:: PyObject* PyNumber_Int(PyObject *o)
-
-   .. index:: builtin: int
-
-   Returns the *o* converted to an integer object on success, or *NULL* on failure.
-   If the argument is outside the integer range a long object will be returned
-   instead. This is the equivalent of the Python expression ``int(o)``.
-
-
-.. cfunction:: PyObject* PyNumber_Long(PyObject *o)
-
-   .. index:: builtin: long
-
-   Returns the *o* converted to a long integer object on success, or *NULL* on
-   failure.  This is the equivalent of the Python expression ``long(o)``.
-
-
-.. cfunction:: PyObject* PyNumber_Float(PyObject *o)
-
-   .. index:: builtin: float
-
-   Returns the *o* converted to a float object on success, or *NULL* on failure.
-   This is the equivalent of the Python expression ``float(o)``.
-
-
-.. cfunction:: PyObject* PyNumber_Index(PyObject *o)
-
-   Returns the *o* converted to a Python int or long on success or *NULL* with a
-   TypeError exception raised on failure.
-
-
-.. cfunction:: Py_ssize_t PyNumber_AsSsize_t(PyObject *o, PyObject *exc)
-
-   Returns *o* converted to a Py_ssize_t value if *o* can be interpreted as an
-   integer. If *o* can be converted to a Python int or long but the attempt to
-   convert to a Py_ssize_t value would raise an :exc:`OverflowError`, then the
-   *exc* argument is the type of exception that will be raised (usually
-   :exc:`IndexError` or :exc:`OverflowError`).  If *exc* is *NULL*, then the
-   exception is cleared and the value is clipped to *PY_SSIZE_T_MIN* for a negative
-   integer or *PY_SSIZE_T_MAX* for a positive integer.
-
-
-.. cfunction:: int PyIndex_Check(PyObject *o)
-
-   Returns True if *o* is an index integer (has the nb_index slot of  the
-   tp_as_number structure filled in).
-
-
-.. _sequence:
-
-Sequence Protocol
-=================
-
-
-.. cfunction:: int PySequence_Check(PyObject *o)
-
-   Return ``1`` if the object provides sequence protocol, and ``0`` otherwise.
-   This function always succeeds.
-
-
-.. cfunction:: Py_ssize_t PySequence_Size(PyObject *o)
-
-   .. index:: builtin: len
-
-   Returns the number of objects in sequence *o* on success, and ``-1`` on failure.
-   For objects that do not provide sequence protocol, this is equivalent to the
-   Python expression ``len(o)``.
-
-
-.. cfunction:: Py_ssize_t PySequence_Length(PyObject *o)
-
-   Alternate name for :cfunc:`PySequence_Size`.
-
-
-.. cfunction:: PyObject* PySequence_Concat(PyObject *o1, PyObject *o2)
-
-   Return the concatenation of *o1* and *o2* on success, and *NULL* on failure.
-   This is the equivalent of the Python expression ``o1 + o2``.
-
-
-.. cfunction:: PyObject* PySequence_Repeat(PyObject *o, Py_ssize_t count)
-
-   Return the result of repeating sequence object *o* *count* times, or *NULL* on
-   failure.  This is the equivalent of the Python expression ``o * count``.
-
-
-.. cfunction:: PyObject* PySequence_InPlaceConcat(PyObject *o1, PyObject *o2)
-
-   Return the concatenation of *o1* and *o2* on success, and *NULL* on failure.
-   The operation is done *in-place* when *o1* supports it.  This is the equivalent
-   of the Python expression ``o1 += o2``.
-
-
-.. cfunction:: PyObject* PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count)
-
-   Return the result of repeating sequence object *o* *count* times, or *NULL* on
-   failure.  The operation is done *in-place* when *o* supports it.  This is the
-   equivalent of the Python expression ``o *= count``.
-
-
-.. cfunction:: PyObject* PySequence_GetItem(PyObject *o, Py_ssize_t i)
-
-   Return the *i*th element of *o*, or *NULL* on failure. This is the equivalent of
-   the Python expression ``o[i]``.
-
-
-.. cfunction:: PyObject* PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2)
-
-   Return the slice of sequence object *o* between *i1* and *i2*, or *NULL* on
-   failure. This is the equivalent of the Python expression ``o[i1:i2]``.
-
-
-.. cfunction:: int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v)
-
-   Assign object *v* to the *i*th element of *o*.  Returns ``-1`` on failure.  This
-   is the equivalent of the Python statement ``o[i] = v``.  This function *does
-   not* steal a reference to *v*.
-
-
-.. cfunction:: int PySequence_DelItem(PyObject *o, Py_ssize_t i)
-
-   Delete the *i*th element of object *o*.  Returns ``-1`` on failure.  This is the
-   equivalent of the Python statement ``del o[i]``.
-
-
-.. cfunction:: int PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, PyObject *v)
-
-   Assign the sequence object *v* to the slice in sequence object *o* from *i1* to
-   *i2*.  This is the equivalent of the Python statement ``o[i1:i2] = v``.
-
-
-.. cfunction:: int PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2)
-
-   Delete the slice in sequence object *o* from *i1* to *i2*.  Returns ``-1`` on
-   failure.  This is the equivalent of the Python statement ``del o[i1:i2]``.
-
-
-.. cfunction:: Py_ssize_t PySequence_Count(PyObject *o, PyObject *value)
-
-   Return the number of occurrences of *value* in *o*, that is, return the number
-   of keys for which ``o[key] == value``.  On failure, return ``-1``.  This is
-   equivalent to the Python expression ``o.count(value)``.
-
-
-.. cfunction:: int PySequence_Contains(PyObject *o, PyObject *value)
-
-   Determine if *o* contains *value*.  If an item in *o* is equal to *value*,
-   return ``1``, otherwise return ``0``. On error, return ``-1``.  This is
-   equivalent to the Python expression ``value in o``.
-
-
-.. cfunction:: Py_ssize_t PySequence_Index(PyObject *o, PyObject *value)
-
-   Return the first index *i* for which ``o[i] == value``.  On error, return
-   ``-1``.    This is equivalent to the Python expression ``o.index(value)``.
-
-
-.. cfunction:: PyObject* PySequence_List(PyObject *o)
-
-   Return a list object with the same contents as the arbitrary sequence *o*.  The
-   returned list is guaranteed to be new.
-
-
-.. cfunction:: PyObject* PySequence_Tuple(PyObject *o)
-
-   .. index:: builtin: tuple
-
-   Return a tuple object with the same contents as the arbitrary sequence *o* or
-   *NULL* on failure.  If *o* is a tuple, a new reference will be returned,
-   otherwise a tuple will be constructed with the appropriate contents.  This is
-   equivalent to the Python expression ``tuple(o)``.
-
-
-.. cfunction:: PyObject* PySequence_Fast(PyObject *o, const char *m)
-
-   Returns the sequence *o* as a tuple, unless it is already a tuple or list, in
-   which case *o* is returned.  Use :cfunc:`PySequence_Fast_GET_ITEM` to access the
-   members of the result.  Returns *NULL* on failure.  If the object is not a
-   sequence, raises :exc:`TypeError` with *m* as the message text.
-
-
-.. cfunction:: PyObject* PySequence_Fast_GET_ITEM(PyObject *o, Py_ssize_t i)
-
-   Return the *i*th element of *o*, assuming that *o* was returned by
-   :cfunc:`PySequence_Fast`, *o* is not *NULL*, and that *i* is within bounds.
-
-
-.. cfunction:: PyObject** PySequence_Fast_ITEMS(PyObject *o)
-
-   Return the underlying array of PyObject pointers.  Assumes that *o* was returned
-   by :cfunc:`PySequence_Fast` and *o* is not *NULL*.
-
-
-.. cfunction:: PyObject* PySequence_ITEM(PyObject *o, Py_ssize_t i)
-
-   Return the *i*th element of *o* or *NULL* on failure. Macro form of
-   :cfunc:`PySequence_GetItem` but without checking that
-   :cfunc:`PySequence_Check(o)` is true and without adjustment for negative
-   indices.
-
-
-.. cfunction:: Py_ssize_t PySequence_Fast_GET_SIZE(PyObject *o)
-
-   Returns the length of *o*, assuming that *o* was returned by
-   :cfunc:`PySequence_Fast` and that *o* is not *NULL*.  The size can also be
-   gotten by calling :cfunc:`PySequence_Size` on *o*, but
-   :cfunc:`PySequence_Fast_GET_SIZE` is faster because it can assume *o* is a list
-   or tuple.
-
-
-.. _mapping:
-
-Mapping Protocol
-================
-
-
-.. cfunction:: int PyMapping_Check(PyObject *o)
-
-   Return ``1`` if the object provides mapping protocol, and ``0`` otherwise.  This
-   function always succeeds.
-
-
-.. cfunction:: Py_ssize_t PyMapping_Length(PyObject *o)
-
-   .. index:: builtin: len
-
-   Returns the number of keys in object *o* on success, and ``-1`` on failure.  For
-   objects that do not provide mapping protocol, this is equivalent to the Python
-   expression ``len(o)``.
-
-
-.. cfunction:: int PyMapping_DelItemString(PyObject *o, char *key)
-
-   Remove the mapping for object *key* from the object *o*. Return ``-1`` on
-   failure.  This is equivalent to the Python statement ``del o[key]``.
-
-
-.. cfunction:: int PyMapping_DelItem(PyObject *o, PyObject *key)
-
-   Remove the mapping for object *key* from the object *o*. Return ``-1`` on
-   failure.  This is equivalent to the Python statement ``del o[key]``.
-
-
-.. cfunction:: int PyMapping_HasKeyString(PyObject *o, char *key)
-
-   On success, return ``1`` if the mapping object has the key *key* and ``0``
-   otherwise.  This is equivalent to the Python expression ``key in o``.
-   This function always succeeds.
-
-
-.. cfunction:: int PyMapping_HasKey(PyObject *o, PyObject *key)
-
-   Return ``1`` if the mapping object has the key *key* and ``0`` otherwise.  This
-   is equivalent to the Python expression ``key in o``.  This function always
-   succeeds.
-
-
-.. cfunction:: PyObject* PyMapping_Keys(PyObject *o)
-
-   On success, return a list of the keys in object *o*.  On failure, return *NULL*.
-   This is equivalent to the Python expression ``o.keys()``.
-
-
-.. cfunction:: PyObject* PyMapping_Values(PyObject *o)
-
-   On success, return a list of the values in object *o*.  On failure, return
-   *NULL*. This is equivalent to the Python expression ``o.values()``.
-
-
-.. cfunction:: PyObject* PyMapping_Items(PyObject *o)
-
-   On success, return a list of the items in object *o*, where each item is a tuple
-   containing a key-value pair.  On failure, return *NULL*. This is equivalent to
-   the Python expression ``o.items()``.
-
-
-.. cfunction:: PyObject* PyMapping_GetItemString(PyObject *o, char *key)
-
-   Return element of *o* corresponding to the object *key* or *NULL* on failure.
-   This is the equivalent of the Python expression ``o[key]``.
-
-
-.. cfunction:: int PyMapping_SetItemString(PyObject *o, char *key, PyObject *v)
-
-   Map the object *key* to the value *v* in object *o*. Returns ``-1`` on failure.
-   This is the equivalent of the Python statement ``o[key] = v``.
-
-
-.. _iterator:
-
-Iterator Protocol
-=================
-
-There are only a couple of functions specifically for working with iterators.
-
-.. cfunction:: int PyIter_Check(PyObject *o)
-
-   Return true if the object *o* supports the iterator protocol.
-
-
-.. cfunction:: PyObject* PyIter_Next(PyObject *o)
-
-   Return the next value from the iteration *o*.  If the object is an iterator,
-   this retrieves the next value from the iteration, and returns *NULL* with no
-   exception set if there are no remaining items.  If the object is not an
-   iterator, :exc:`TypeError` is raised, or if there is an error in retrieving the
-   item, returns *NULL* and passes along the exception.
-
-To write a loop which iterates over an iterator, the C code should look
-something like this::
-
-   PyObject *iterator = PyObject_GetIter(obj);
-   PyObject *item;
-
-   if (iterator == NULL) {
-       /* propagate error */
-   }
-
-   while (item = PyIter_Next(iterator)) {
-       /* do something with item */
-       ...
-       /* release reference when done */
-       Py_DECREF(item);
-   }
-
-   Py_DECREF(iterator);
-
-   if (PyErr_Occurred()) {
-       /* propagate error */
-   }
-   else {
-       /* continue doing useful work */
-   }
-
-
-.. _abstract-buffer:
-
-Buffer Protocol
-===============
-
-
-.. cfunction:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len)
-
-   Returns a pointer to a read-only memory location useable as character- based
-   input.  The *obj* argument must support the single-segment character buffer
-   interface.  On success, returns ``0``, sets *buffer* to the memory location and
-   *buffer_len* to the buffer length.  Returns ``-1`` and sets a :exc:`TypeError`
-   on error.
-
-
-.. cfunction:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len)
-
-   Returns a pointer to a read-only memory location containing arbitrary data.  The
-   *obj* argument must support the single-segment readable buffer interface.  On
-   success, returns ``0``, sets *buffer* to the memory location and *buffer_len* to
-   the buffer length.  Returns ``-1`` and sets a :exc:`TypeError` on error.
-
-
-.. cfunction:: int PyObject_CheckReadBuffer(PyObject *o)
-
-   Returns ``1`` if *o* supports the single-segment readable buffer interface.
-   Otherwise returns ``0``.
-
-
-.. cfunction:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len)
-
-   Returns a pointer to a writable memory location.  The *obj* argument must
-   support the single-segment, character buffer interface.  On success, returns
-   ``0``, sets *buffer* to the memory location and *buffer_len* to the buffer
-   length.  Returns ``-1`` and sets a :exc:`TypeError` on error.
-
+   object.rst
+   number.rst
+   sequence.rst
+   mapping.rst
+   iter.rst
+   objbuffer.rst

Modified: python/branches/py3k-importlib/Doc/c-api/concrete.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/c-api/concrete.rst	(original)
+++ python/branches/py3k-importlib/Doc/c-api/concrete.rst	Thu Mar 27 00:48:05 2008
@@ -29,99 +29,10 @@
 
 This section describes Python type objects and the singleton object ``None``.
 
+.. toctree::
 
-.. _typeobjects:
-
-Type Objects
-------------
-
-.. index:: object: type
-
-
-.. ctype:: PyTypeObject
-
-   The C structure of the objects used to describe built-in types.
-
-
-.. cvar:: PyObject* PyType_Type
-
-   .. index:: single: TypeType (in module types)
-
-   This is the type object for type objects; it is the same object as ``type`` and
-   ``types.TypeType`` in the Python layer.
-
-
-.. cfunction:: int PyType_Check(PyObject *o)
-
-   Return true if the object *o* is a type object, including instances of types
-   derived from the standard type object.  Return false in all other cases.
-
-
-.. cfunction:: int PyType_CheckExact(PyObject *o)
-
-   Return true if the object *o* is a type object, but not a subtype of the
-   standard type object.  Return false in all other cases.
-
-
-.. cfunction:: int PyType_HasFeature(PyObject *o, int feature)
-
-   Return true if the type object *o* sets the feature *feature*.  Type features
-   are denoted by single bit flags.
-
-
-.. cfunction:: int PyType_IS_GC(PyObject *o)
-
-   Return true if the type object includes support for the cycle detector; this
-   tests the type flag :const:`Py_TPFLAGS_HAVE_GC`.
-
-
-.. cfunction:: int PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b)
-
-   Return true if *a* is a subtype of *b*.
-
-
-.. cfunction:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
-
-   XXX: Document.
-
-
-.. cfunction:: PyObject* PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
-
-   XXX: Document.
-
-
-.. cfunction:: int PyType_Ready(PyTypeObject *type)
-
-   Finalize a type object.  This should be called on all type objects to finish
-   their initialization.  This function is responsible for adding inherited slots
-   from a type's base class.  Return ``0`` on success, or return ``-1`` and sets an
-   exception on error.
-
-
-.. _noneobject:
-
-The None Object
----------------
-
-.. index:: object: None
-
-Note that the :ctype:`PyTypeObject` for ``None`` is not directly exposed in the
-Python/C API.  Since ``None`` is a singleton, testing for object identity (using
-``==`` in C) is sufficient. There is no :cfunc:`PyNone_Check` function for the
-same reason.
-
-
-.. cvar:: PyObject* Py_None
-
-   The Python ``None`` object, denoting lack of value.  This object has no methods.
-   It needs to be treated just like any other object with respect to reference
-   counts.
-
-
-.. cmacro:: Py_RETURN_NONE
-
-   Properly handle returning :cdata:`Py_None` from within a C function (that is,
-   increment the reference count of None and return it.)
+   type.rst
+   none.rst
 
 
 .. _numericobjects:
@@ -131,3300 +42,65 @@
 
 .. index:: object: numeric
 
+.. toctree::
 
-.. _intobjects:
-
-Plain Integer Objects
----------------------
-
-.. index:: object: integer
-
-
-.. ctype:: PyIntObject
-
-   This subtype of :ctype:`PyObject` represents a Python integer object.
-
-
-.. cvar:: PyTypeObject PyInt_Type
-
-   .. index:: single: IntType (in modules types)
-
-   This instance of :ctype:`PyTypeObject` represents the Python plain integer type.
-   This is the same object as ``int`` and ``types.IntType``.
-
-
-.. cfunction:: int PyInt_Check(PyObject *o)
-
-   Return true if *o* is of type :cdata:`PyInt_Type` or a subtype of
-   :cdata:`PyInt_Type`.
-
-
-.. cfunction:: int PyInt_CheckExact(PyObject *o)
-
-   Return true if *o* is of type :cdata:`PyInt_Type`, but not a subtype of
-   :cdata:`PyInt_Type`.
-
-
-.. cfunction:: PyObject* PyInt_FromString(char *str, char **pend, int base)
-
-   Return a new :ctype:`PyIntObject` or :ctype:`PyLongObject` based on the string
-   value in *str*, which is interpreted according to the radix in *base*.  If
-   *pend* is non-*NULL*, ``*pend`` will point to the first character in *str* which
-   follows the representation of the number.  If *base* is ``0``, the radix will be
-   determined based on the leading characters of *str*: if *str* starts with
-   ``'0x'`` or ``'0X'``, radix 16 will be used; if *str* starts with ``'0'``, radix
-   8 will be used; otherwise radix 10 will be used.  If *base* is not ``0``, it
-   must be between ``2`` and ``36``, inclusive.  Leading spaces are ignored.  If
-   there are no digits, :exc:`ValueError` will be raised.  If the string represents
-   a number too large to be contained within the machine's :ctype:`long int` type
-   and overflow warnings are being suppressed, a :ctype:`PyLongObject` will be
-   returned.  If overflow warnings are not being suppressed, *NULL* will be
-   returned in this case.
-
-
-.. cfunction:: PyObject* PyInt_FromLong(long ival)
-
-   Create a new integer object with a value of *ival*.
-
-   The current implementation keeps an array of integer objects for all integers
-   between ``-5`` and ``256``, when you create an int in that range you actually
-   just get back a reference to the existing object. So it should be possible to
-   change the value of ``1``.  I suspect the behaviour of Python in this case is
-   undefined. :-)
-
-
-.. cfunction:: PyObject* PyInt_FromSsize_t(Py_ssize_t ival)
-
-   Create a new integer object with a value of *ival*. If the value exceeds
-   ``LONG_MAX``, a long integer object is returned.
-
-
-.. cfunction:: long PyInt_AsLong(PyObject *io)
-
-   Will first attempt to cast the object to a :ctype:`PyIntObject`, if it is not
-   already one, and then return its value. If there is an error, ``-1`` is
-   returned, and the caller should check ``PyErr_Occurred()`` to find out whether
-   there was an error, or whether the value just happened to be -1.
-
-
-.. cfunction:: long PyInt_AS_LONG(PyObject *io)
-
-   Return the value of the object *io*.  No error checking is performed.
-
-
-.. cfunction:: unsigned long PyInt_AsUnsignedLongMask(PyObject *io)
-
-   Will first attempt to cast the object to a :ctype:`PyIntObject` or
-   :ctype:`PyLongObject`, if it is not already one, and then return its value as
-   unsigned long.  This function does not check for overflow.
-
-
-.. cfunction:: unsigned PY_LONG_LONG PyInt_AsUnsignedLongLongMask(PyObject *io)
-
-   Will first attempt to cast the object to a :ctype:`PyIntObject` or
-   :ctype:`PyLongObject`, if it is not already one, and then return its value as
-   unsigned long long, without checking for overflow.
-
-
-.. cfunction:: Py_ssize_t PyInt_AsSsize_t(PyObject *io)
-
-   Will first attempt to cast the object to a :ctype:`PyIntObject` or
-   :ctype:`PyLongObject`, if it is not already one, and then return its value as
-   :ctype:`Py_ssize_t`.
-
-
-.. cfunction:: long PyInt_GetMax()
-
-   .. index:: single: LONG_MAX
-
-   Return the system's idea of the largest integer it can handle
-   (:const:`LONG_MAX`, as defined in the system header files).
-
-
-.. _boolobjects:
-
-Boolean Objects
----------------
-
-Booleans in Python are implemented as a subclass of integers.  There are only
-two booleans, :const:`Py_False` and :const:`Py_True`.  As such, the normal
-creation and deletion functions don't apply to booleans.  The following macros
-are available, however.
-
-
-.. cfunction:: int PyBool_Check(PyObject *o)
-
-   Return true if *o* is of type :cdata:`PyBool_Type`.
-
-
-.. cvar:: PyObject* Py_False
-
-   The Python ``False`` object.  This object has no methods.  It needs to be
-   treated just like any other object with respect to reference counts.
-
-
-.. cvar:: PyObject* Py_True
-
-   The Python ``True`` object.  This object has no methods.  It needs to be treated
-   just like any other object with respect to reference counts.
-
-
-.. cmacro:: Py_RETURN_FALSE
-
-   Return :const:`Py_False` from a function, properly incrementing its reference
-   count.
-
-
-.. cmacro:: Py_RETURN_TRUE
-
-   Return :const:`Py_True` from a function, properly incrementing its reference
-   count.
-
-
-.. cfunction:: PyObject* PyBool_FromLong(long v)
-
-   Return a new reference to :const:`Py_True` or :const:`Py_False` depending on the
-   truth value of *v*.
-
-
-.. _longobjects:
-
-Long Integer Objects
---------------------
-
-.. index:: object: long integer
-
-
-.. ctype:: PyLongObject
-
-   This subtype of :ctype:`PyObject` represents a Python long integer object.
-
-
-.. cvar:: PyTypeObject PyLong_Type
-
-   .. index:: single: LongType (in modules types)
-
-   This instance of :ctype:`PyTypeObject` represents the Python long integer type.
-   This is the same object as ``long`` and ``types.LongType``.
-
-
-.. cfunction:: int PyLong_Check(PyObject *p)
-
-   Return true if its argument is a :ctype:`PyLongObject` or a subtype of
-   :ctype:`PyLongObject`.
-
-
-.. cfunction:: int PyLong_CheckExact(PyObject *p)
-
-   Return true if its argument is a :ctype:`PyLongObject`, but not a subtype of
-   :ctype:`PyLongObject`.
-
+   long.rst
+   bool.rst
+   float.rst
+   complex.rst
 
-.. cfunction:: PyObject* PyLong_FromLong(long v)
-
-   Return a new :ctype:`PyLongObject` object from *v*, or *NULL* on failure.
-
-
-.. cfunction:: PyObject* PyLong_FromUnsignedLong(unsigned long v)
-
-   Return a new :ctype:`PyLongObject` object from a C :ctype:`unsigned long`, or
-   *NULL* on failure.
-
-
-.. cfunction:: PyObject* PyLong_FromLongLong(PY_LONG_LONG v)
-
-   Return a new :ctype:`PyLongObject` object from a C :ctype:`long long`, or *NULL*
-   on failure.
-
-
-.. cfunction:: PyObject* PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG v)
-
-   Return a new :ctype:`PyLongObject` object from a C :ctype:`unsigned long long`,
-   or *NULL* on failure.
-
-
-.. cfunction:: PyObject* PyLong_FromDouble(double v)
-
-   Return a new :ctype:`PyLongObject` object from the integer part of *v*, or
-   *NULL* on failure.
-
-
-.. cfunction:: PyObject* PyLong_FromString(char *str, char **pend, int base)
-
-   Return a new :ctype:`PyLongObject` based on the string value in *str*, which is
-   interpreted according to the radix in *base*.  If *pend* is non-*NULL*,
-   ``*pend`` will point to the first character in *str* which follows the
-   representation of the number.  If *base* is ``0``, the radix will be determined
-   based on the leading characters of *str*: if *str* starts with ``'0x'`` or
-   ``'0X'``, radix 16 will be used; if *str* starts with ``'0'``, radix 8 will be
-   used; otherwise radix 10 will be used.  If *base* is not ``0``, it must be
-   between ``2`` and ``36``, inclusive.  Leading spaces are ignored.  If there are
-   no digits, :exc:`ValueError` will be raised.
-
-
-.. cfunction:: PyObject* PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
-
-   Convert a sequence of Unicode digits to a Python long integer value.  The first
-   parameter, *u*, points to the first character of the Unicode string, *length*
-   gives the number of characters, and *base* is the radix for the conversion.  The
-   radix must be in the range [2, 36]; if it is out of range, :exc:`ValueError`
-   will be raised.
-
-
-.. cfunction:: PyObject* PyLong_FromVoidPtr(void *p)
-
-   Create a Python integer or long integer from the pointer *p*. The pointer value
-   can be retrieved from the resulting value using :cfunc:`PyLong_AsVoidPtr`.
-   If the integer is larger than LONG_MAX, a positive long integer is returned.
-
-
-.. cfunction:: long PyLong_AsLong(PyObject *pylong)
-
-   .. index::
-      single: LONG_MAX
-      single: OverflowError (built-in exception)
-
-   Return a C :ctype:`long` representation of the contents of *pylong*.  If
-   *pylong* is greater than :const:`LONG_MAX`, an :exc:`OverflowError` is raised.
-
-
-.. cfunction:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong)
-
-   .. index::
-      single: ULONG_MAX
-      single: OverflowError (built-in exception)
-
-   Return a C :ctype:`unsigned long` representation of the contents of *pylong*.
-   If *pylong* is greater than :const:`ULONG_MAX`, an :exc:`OverflowError` is
-   raised.
-
-
-.. cfunction:: PY_LONG_LONG PyLong_AsLongLong(PyObject *pylong)
-
-   Return a C :ctype:`long long` from a Python long integer.  If *pylong* cannot be
-   represented as a :ctype:`long long`, an :exc:`OverflowError` will be raised.
-
-
-.. cfunction:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(PyObject *pylong)
-
-   Return a C :ctype:`unsigned long long` from a Python long integer. If *pylong*
-   cannot be represented as an :ctype:`unsigned long long`, an :exc:`OverflowError`
-   will be raised if the value is positive, or a :exc:`TypeError` will be raised if
-   the value is negative.
-
-
-.. cfunction:: unsigned long PyLong_AsUnsignedLongMask(PyObject *io)
-
-   Return a C :ctype:`unsigned long` from a Python long integer, without checking
-   for overflow.
-
-
-.. cfunction:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(PyObject *io)
-
-   Return a C :ctype:`unsigned long long` from a Python long integer, without
-   checking for overflow.
-
-
-.. cfunction:: double PyLong_AsDouble(PyObject *pylong)
-
-   Return a C :ctype:`double` representation of the contents of *pylong*.  If
-   *pylong* cannot be approximately represented as a :ctype:`double`, an
-   :exc:`OverflowError` exception is raised and ``-1.0`` will be returned.
-
-
-.. cfunction:: void* PyLong_AsVoidPtr(PyObject *pylong)
-
-   Convert a Python integer or long integer *pylong* to a C :ctype:`void` pointer.
-   If *pylong* cannot be converted, an :exc:`OverflowError` will be raised.  This
-   is only assured to produce a usable :ctype:`void` pointer for values created
-   with :cfunc:`PyLong_FromVoidPtr`.
-
-   For values outside 0..LONG_MAX, both signed and unsigned integers are acccepted.
-
-
-.. _floatobjects:
-
-Floating Point Objects
-----------------------
-
-.. index:: object: floating point
-
-
-.. ctype:: PyFloatObject
-
-   This subtype of :ctype:`PyObject` represents a Python floating point object.
-
-
-.. cvar:: PyTypeObject PyFloat_Type
-
-   .. index:: single: FloatType (in modules types)
-
-   This instance of :ctype:`PyTypeObject` represents the Python floating point
-   type.  This is the same object as ``float`` and ``types.FloatType``.
-
-
-.. cfunction:: int PyFloat_Check(PyObject *p)
-
-   Return true if its argument is a :ctype:`PyFloatObject` or a subtype of
-   :ctype:`PyFloatObject`.
-
-
-.. cfunction:: int PyFloat_CheckExact(PyObject *p)
-
-   Return true if its argument is a :ctype:`PyFloatObject`, but not a subtype of
-   :ctype:`PyFloatObject`.
-
-
-.. cfunction:: PyObject* PyFloat_FromString(PyObject *str)
-
-   Create a :ctype:`PyFloatObject` object based on the string value in *str*, or
-   *NULL* on failure.
-
-
-.. cfunction:: PyObject* PyFloat_FromDouble(double v)
-
-   Create a :ctype:`PyFloatObject` object from *v*, or *NULL* on failure.
-
-
-.. cfunction:: double PyFloat_AsDouble(PyObject *pyfloat)
-
-   Return a C :ctype:`double` representation of the contents of *pyfloat*.  If
-   *pyfloat* is not a Python floating point object but has a :meth:`__float__`
-   method, this method will first be called to convert *pyfloat* into a float.
-
-
-.. cfunction:: double PyFloat_AS_DOUBLE(PyObject *pyfloat)
-
-   Return a C :ctype:`double` representation of the contents of *pyfloat*, but
-   without error checking.
-
-
-.. _complexobjects:
-
-Complex Number Objects
-----------------------
-
-.. index:: object: complex number
-
-Python's complex number objects are implemented as two distinct types when
-viewed from the C API:  one is the Python object exposed to Python programs, and
-the other is a C structure which represents the actual complex number value.
-The API provides functions for working with both.
-
-
-Complex Numbers as C Structures
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Note that the functions which accept these structures as parameters and return
-them as results do so *by value* rather than dereferencing them through
-pointers.  This is consistent throughout the API.
-
-
-.. ctype:: Py_complex
-
-   The C structure which corresponds to the value portion of a Python complex
-   number object.  Most of the functions for dealing with complex number objects
-   use structures of this type as input or output values, as appropriate.  It is
-   defined as::
-
-      typedef struct {
-         double real;
-         double imag;
-      } Py_complex;
-
-
-.. cfunction:: Py_complex _Py_c_sum(Py_complex left, Py_complex right)
-
-   Return the sum of two complex numbers, using the C :ctype:`Py_complex`
-   representation.
-
-
-.. cfunction:: Py_complex _Py_c_diff(Py_complex left, Py_complex right)
-
-   Return the difference between two complex numbers, using the C
-   :ctype:`Py_complex` representation.
-
-
-.. cfunction:: Py_complex _Py_c_neg(Py_complex complex)
-
-   Return the negation of the complex number *complex*, using the C
-   :ctype:`Py_complex` representation.
-
-
-.. cfunction:: Py_complex _Py_c_prod(Py_complex left, Py_complex right)
-
-   Return the product of two complex numbers, using the C :ctype:`Py_complex`
-   representation.
-
-
-.. cfunction:: Py_complex _Py_c_quot(Py_complex dividend, Py_complex divisor)
-
-   Return the quotient of two complex numbers, using the C :ctype:`Py_complex`
-   representation.
-
-
-.. cfunction:: Py_complex _Py_c_pow(Py_complex num, Py_complex exp)
-
-   Return the exponentiation of *num* by *exp*, using the C :ctype:`Py_complex`
-   representation.
-
-
-Complex Numbers as Python Objects
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-
-.. ctype:: PyComplexObject
-
-   This subtype of :ctype:`PyObject` represents a Python complex number object.
-
-
-.. cvar:: PyTypeObject PyComplex_Type
-
-   This instance of :ctype:`PyTypeObject` represents the Python complex number
-   type. It is the same object as ``complex`` and ``types.ComplexType``.
 
+.. _sequenceobjects:
 
-.. cfunction:: int PyComplex_Check(PyObject *p)
+Sequence Objects
+================
 
-   Return true if its argument is a :ctype:`PyComplexObject` or a subtype of
-   :ctype:`PyComplexObject`.
+.. index:: object: sequence
 
+Generic operations on sequence objects were discussed in the previous chapter;
+this section deals with the specific kinds of sequence objects that are
+intrinsic to the Python language.
 
-.. cfunction:: int PyComplex_CheckExact(PyObject *p)
+.. XXX sort out unicode, str, bytes and bytearray
 
-   Return true if its argument is a :ctype:`PyComplexObject`, but not a subtype of
-   :ctype:`PyComplexObject`.
+.. toctree::
 
+   string.rst
+   unicode.rst
+   buffer.rst
+   tuple.rst
+   list.rst
 
-.. cfunction:: PyObject* PyComplex_FromCComplex(Py_complex v)
 
-   Create a new Python complex number object from a C :ctype:`Py_complex` value.
+.. _mapobjects:
 
+Mapping Objects
+===============
 
-.. cfunction:: PyObject* PyComplex_FromDoubles(double real, double imag)
+.. index:: object: mapping
 
-   Return a new :ctype:`PyComplexObject` object from *real* and *imag*.
+.. toctree::
 
+   dict.rst
 
-.. cfunction:: double PyComplex_RealAsDouble(PyObject *op)
 
-   Return the real part of *op* as a C :ctype:`double`.
+.. _otherobjects:
 
+Other Objects
+=============
 
-.. cfunction:: double PyComplex_ImagAsDouble(PyObject *op)
-
-   Return the imaginary part of *op* as a C :ctype:`double`.
-
-
-.. cfunction:: Py_complex PyComplex_AsCComplex(PyObject *op)
-
-   Return the :ctype:`Py_complex` value of the complex number *op*.
-
-   If *op* is not a Python complex number object but has a :meth:`__complex__`
-   method, this method will first be called to convert *op* to a Python complex
-   number object.
-
-
-.. _sequenceobjects:
-
-Sequence Objects
-================
-
-.. index:: object: sequence
-
-Generic operations on sequence objects were discussed in the previous chapter;
-this section deals with the specific kinds of sequence objects that are
-intrinsic to the Python language.
-
-
-.. _stringobjects:
-
-String Objects
---------------
-
-These functions raise :exc:`TypeError` when expecting a string parameter and are
-called with a non-string parameter.
-
-.. index:: object: string
-
-
-.. ctype:: PyStringObject
-
-   This subtype of :ctype:`PyObject` represents a Python string object.
-
-
-.. cvar:: PyTypeObject PyString_Type
-
-   .. index:: single: StringType (in module types)
-
-   This instance of :ctype:`PyTypeObject` represents the Python string type; it is
-   the same object as ``str`` and ``types.StringType`` in the Python layer. .
-
-
-.. cfunction:: int PyString_Check(PyObject *o)
-
-   Return true if the object *o* is a string object or an instance of a subtype of
-   the string type.
-
-
-.. cfunction:: int PyString_CheckExact(PyObject *o)
-
-   Return true if the object *o* is a string object, but not an instance of a
-   subtype of the string type.
-
-
-.. cfunction:: PyObject* PyString_FromString(const char *v)
-
-   Return a new string object with a copy of the string *v* as value on success,
-   and *NULL* on failure.  The parameter *v* must not be *NULL*; it will not be
-   checked.
-
-
-.. cfunction:: PyObject* PyString_FromStringAndSize(const char *v, Py_ssize_t len)
-
-   Return a new string object with a copy of the string *v* as value and length
-   *len* on success, and *NULL* on failure.  If *v* is *NULL*, the contents of the
-   string are uninitialized.
-
-
-.. cfunction:: PyObject* PyString_FromFormat(const char *format, ...)
-
-   Take a C :cfunc:`printf`\ -style *format* string and a variable number of
-   arguments, calculate the size of the resulting Python string and return a string
-   with the values formatted into it.  The variable arguments must be C types and
-   must correspond exactly to the format characters in the *format* string.  The
-   following format characters are allowed:
-
-   .. % XXX: This should be exactly the same as the table in PyErr_Format.
-   .. % One should just refer to the other.
-   .. % XXX: The descriptions for %zd and %zu are wrong, but the truth is complicated
-   .. % because not all compilers support the %z width modifier -- we fake it
-   .. % when necessary via interpolating PY_FORMAT_SIZE_T.
-   .. % %u, %lu, %zu should have "new in Python 2.5" blurbs.
-
-   +-------------------+---------------+--------------------------------+
-   | Format Characters | Type          | Comment                        |
-   +===================+===============+================================+
-   | :attr:`%%`        | *n/a*         | The literal % character.       |
-   +-------------------+---------------+--------------------------------+
-   | :attr:`%c`        | int           | A single character,            |
-   |                   |               | represented as an C int.       |
-   +-------------------+---------------+--------------------------------+
-   | :attr:`%d`        | int           | Exactly equivalent to          |
-   |                   |               | ``printf("%d")``.              |
-   +-------------------+---------------+--------------------------------+
-   | :attr:`%u`        | unsigned int  | Exactly equivalent to          |
-   |                   |               | ``printf("%u")``.              |
-   +-------------------+---------------+--------------------------------+
-   | :attr:`%ld`       | long          | Exactly equivalent to          |
-   |                   |               | ``printf("%ld")``.             |
-   +-------------------+---------------+--------------------------------+
-   | :attr:`%lu`       | unsigned long | Exactly equivalent to          |
-   |                   |               | ``printf("%lu")``.             |
-   +-------------------+---------------+--------------------------------+
-   | :attr:`%zd`       | Py_ssize_t    | Exactly equivalent to          |
-   |                   |               | ``printf("%zd")``.             |
-   +-------------------+---------------+--------------------------------+
-   | :attr:`%zu`       | size_t        | Exactly equivalent to          |
-   |                   |               | ``printf("%zu")``.             |
-   +-------------------+---------------+--------------------------------+
-   | :attr:`%i`        | int           | Exactly equivalent to          |
-   |                   |               | ``printf("%i")``.              |
-   +-------------------+---------------+--------------------------------+
-   | :attr:`%x`        | int           | Exactly equivalent to          |
-   |                   |               | ``printf("%x")``.              |
-   +-------------------+---------------+--------------------------------+
-   | :attr:`%s`        | char\*        | A null-terminated C character  |
-   |                   |               | array.                         |
-   +-------------------+---------------+--------------------------------+
-   | :attr:`%p`        | void\*        | The hex representation of a C  |
-   |                   |               | pointer. Mostly equivalent to  |
-   |                   |               | ``printf("%p")`` except that   |
-   |                   |               | it is guaranteed to start with |
-   |                   |               | the literal ``0x`` regardless  |
-   |                   |               | of what the platform's         |
-   |                   |               | ``printf`` yields.             |
-   +-------------------+---------------+--------------------------------+
-
-   An unrecognized format character causes all the rest of the format string to be
-   copied as-is to the result string, and any extra arguments discarded.
-
-
-.. cfunction:: PyObject* PyString_FromFormatV(const char *format, va_list vargs)
-
-   Identical to :func:`PyString_FromFormat` except that it takes exactly two
-   arguments.
-
-
-.. cfunction:: Py_ssize_t PyString_Size(PyObject *string)
-
-   Return the length of the string in string object *string*.
-
-
-.. cfunction:: Py_ssize_t PyString_GET_SIZE(PyObject *string)
-
-   Macro form of :cfunc:`PyString_Size` but without error checking.
-
-
-.. cfunction:: char* PyString_AsString(PyObject *string)
-
-   Return a NUL-terminated representation of the contents of *string*.  The pointer
-   refers to the internal buffer of *string*, not a copy.  The data must not be
-   modified in any way, unless the string was just created using
-   ``PyString_FromStringAndSize(NULL, size)``. It must not be deallocated.  If
-   *string* is a Unicode object, this function computes the default encoding of
-   *string* and operates on that.  If *string* is not a string object at all,
-   :cfunc:`PyString_AsString` returns *NULL* and raises :exc:`TypeError`.
-
-
-.. cfunction:: char* PyString_AS_STRING(PyObject *string)
-
-   Macro form of :cfunc:`PyString_AsString` but without error checking.  Only
-   string objects are supported; no Unicode objects should be passed.
-
-
-.. cfunction:: int PyString_AsStringAndSize(PyObject *obj, char **buffer, Py_ssize_t *length)
-
-   Return a NUL-terminated representation of the contents of the object *obj*
-   through the output variables *buffer* and *length*.
-
-   The function accepts both string and Unicode objects as input. For Unicode
-   objects it returns the default encoded version of the object.  If *length* is
-   *NULL*, the resulting buffer may not contain NUL characters; if it does, the
-   function returns ``-1`` and a :exc:`TypeError` is raised.
-
-   The buffer refers to an internal string buffer of *obj*, not a copy. The data
-   must not be modified in any way, unless the string was just created using
-   ``PyString_FromStringAndSize(NULL, size)``.  It must not be deallocated.  If
-   *string* is a Unicode object, this function computes the default encoding of
-   *string* and operates on that.  If *string* is not a string object at all,
-   :cfunc:`PyString_AsStringAndSize` returns ``-1`` and raises :exc:`TypeError`.
-
-
-.. cfunction:: void PyString_Concat(PyObject **string, PyObject *newpart)
-
-   Create a new string object in *\*string* containing the contents of *newpart*
-   appended to *string*; the caller will own the new reference.  The reference to
-   the old value of *string* will be stolen.  If the new string cannot be created,
-   the old reference to *string* will still be discarded and the value of
-   *\*string* will be set to *NULL*; the appropriate exception will be set.
-
-
-.. cfunction:: void PyString_ConcatAndDel(PyObject **string, PyObject *newpart)
-
-   Create a new string object in *\*string* containing the contents of *newpart*
-   appended to *string*.  This version decrements the reference count of *newpart*.
-
-
-.. cfunction:: int _PyString_Resize(PyObject **string, Py_ssize_t newsize)
-
-   A way to resize a string object even though it is "immutable". Only use this to
-   build up a brand new string object; don't use this if the string may already be
-   known in other parts of the code.  It is an error to call this function if the
-   refcount on the input string object is not one. Pass the address of an existing
-   string object as an lvalue (it may be written into), and the new size desired.
-   On success, *\*string* holds the resized string object and ``0`` is returned;
-   the address in *\*string* may differ from its input value.  If the reallocation
-   fails, the original string object at *\*string* is deallocated, *\*string* is
-   set to *NULL*, a memory exception is set, and ``-1`` is returned.
-
-
-.. cfunction:: PyObject* PyString_Format(PyObject *format, PyObject *args)
-
-   Return a new string object from *format* and *args*. Analogous to ``format %
-   args``.  The *args* argument must be a tuple.
-
-
-.. cfunction:: void PyString_InternInPlace(PyObject **string)
-
-   Intern the argument *\*string* in place.  The argument must be the address of a
-   pointer variable pointing to a Python string object.  If there is an existing
-   interned string that is the same as *\*string*, it sets *\*string* to it
-   (decrementing the reference count of the old string object and incrementing the
-   reference count of the interned string object), otherwise it leaves *\*string*
-   alone and interns it (incrementing its reference count).  (Clarification: even
-   though there is a lot of talk about reference counts, think of this function as
-   reference-count-neutral; you own the object after the call if and only if you
-   owned it before the call.)
-
-
-.. cfunction:: PyObject* PyString_InternFromString(const char *v)
-
-   A combination of :cfunc:`PyString_FromString` and
-   :cfunc:`PyString_InternInPlace`, returning either a new string object that has
-   been interned, or a new ("owned") reference to an earlier interned string object
-   with the same value.
-
-
-.. cfunction:: PyObject* PyString_Decode(const char *s, Py_ssize_t size, const char *encoding, const char *errors)
-
-   Create an object by decoding *size* bytes of the encoded buffer *s* using the
-   codec registered for *encoding*.  *encoding* and *errors* have the same meaning
-   as the parameters of the same name in the :func:`unicode` built-in function.
-   The codec to be used is looked up using the Python codec registry.  Return
-   *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyString_AsDecodedObject(PyObject *str, const char *encoding, const char *errors)
-
-   Decode a string object by passing it to the codec registered for *encoding* and
-   return the result as Python object. *encoding* and *errors* have the same
-   meaning as the parameters of the same name in the string :meth:`encode` method.
-   The codec to be used is looked up using the Python codec registry. Return *NULL*
-   if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyString_Encode(const char *s, Py_ssize_t size, const char *encoding, const char *errors)
-
-   Encode the :ctype:`char` buffer of the given size by passing it to the codec
-   registered for *encoding* and return a Python object. *encoding* and *errors*
-   have the same meaning as the parameters of the same name in the string
-   :meth:`encode` method. The codec to be used is looked up using the Python codec
-   registry.  Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyString_AsEncodedObject(PyObject *str, const char *encoding, const char *errors)
-
-   Encode a string object using the codec registered for *encoding* and return the
-   result as Python object. *encoding* and *errors* have the same meaning as the
-   parameters of the same name in the string :meth:`encode` method. The codec to be
-   used is looked up using the Python codec registry. Return *NULL* if an exception
-   was raised by the codec.
-
-
-.. _unicodeobjects:
-
-Unicode Objects
----------------
-
-.. sectionauthor:: Marc-Andre Lemburg <mal at lemburg.com>
-
-
-These are the basic Unicode object types used for the Unicode implementation in
-Python:
-
-.. % --- Unicode Type -------------------------------------------------------
-
-
-.. ctype:: Py_UNICODE
-
-   This type represents the storage type which is used by Python internally as
-   basis for holding Unicode ordinals.  Python's default builds use a 16-bit type
-   for :ctype:`Py_UNICODE` and store Unicode values internally as UCS2. It is also
-   possible to build a UCS4 version of Python (most recent Linux distributions come
-   with UCS4 builds of Python). These builds then use a 32-bit type for
-   :ctype:`Py_UNICODE` and store Unicode data internally as UCS4. On platforms
-   where :ctype:`wchar_t` is available and compatible with the chosen Python
-   Unicode build variant, :ctype:`Py_UNICODE` is a typedef alias for
-   :ctype:`wchar_t` to enhance native platform compatibility. On all other
-   platforms, :ctype:`Py_UNICODE` is a typedef alias for either :ctype:`unsigned
-   short` (UCS2) or :ctype:`unsigned long` (UCS4).
-
-Note that UCS2 and UCS4 Python builds are not binary compatible. Please keep
-this in mind when writing extensions or interfaces.
-
-
-.. ctype:: PyUnicodeObject
-
-   This subtype of :ctype:`PyObject` represents a Python Unicode object.
-
-
-.. cvar:: PyTypeObject PyUnicode_Type
-
-   This instance of :ctype:`PyTypeObject` represents the Python Unicode type.  It
-   is exposed to Python code as ``str``.
-
-The following APIs are really C macros and can be used to do fast checks and to
-access internal read-only data of Unicode objects:
-
-
-.. cfunction:: int PyUnicode_Check(PyObject *o)
-
-   Return true if the object *o* is a Unicode object or an instance of a Unicode
-   subtype.
-
-
-.. cfunction:: int PyUnicode_CheckExact(PyObject *o)
-
-   Return true if the object *o* is a Unicode object, but not an instance of a
-   subtype.
-
-
-.. cfunction:: Py_ssize_t PyUnicode_GET_SIZE(PyObject *o)
-
-   Return the size of the object.  *o* has to be a :ctype:`PyUnicodeObject` (not
-   checked).
-
-
-.. cfunction:: Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject *o)
-
-   Return the size of the object's internal buffer in bytes.  *o* has to be a
-   :ctype:`PyUnicodeObject` (not checked).
-
-
-.. cfunction:: Py_UNICODE* PyUnicode_AS_UNICODE(PyObject *o)
-
-   Return a pointer to the internal :ctype:`Py_UNICODE` buffer of the object.  *o*
-   has to be a :ctype:`PyUnicodeObject` (not checked).
-
-
-.. cfunction:: const char* PyUnicode_AS_DATA(PyObject *o)
-
-   Return a pointer to the internal buffer of the object. *o* has to be a
-   :ctype:`PyUnicodeObject` (not checked).
-
-Unicode provides many different character properties. The most often needed ones
-are available through these macros which are mapped to C functions depending on
-the Python configuration.
-
-.. % --- Unicode character properties ---------------------------------------
-
-
-.. cfunction:: int Py_UNICODE_ISSPACE(Py_UNICODE ch)
-
-   Return 1 or 0 depending on whether *ch* is a whitespace character.
-
-
-.. cfunction:: int Py_UNICODE_ISLOWER(Py_UNICODE ch)
-
-   Return 1 or 0 depending on whether *ch* is a lowercase character.
-
-
-.. cfunction:: int Py_UNICODE_ISUPPER(Py_UNICODE ch)
-
-   Return 1 or 0 depending on whether *ch* is an uppercase character.
-
-
-.. cfunction:: int Py_UNICODE_ISTITLE(Py_UNICODE ch)
-
-   Return 1 or 0 depending on whether *ch* is a titlecase character.
-
-
-.. cfunction:: int Py_UNICODE_ISLINEBREAK(Py_UNICODE ch)
-
-   Return 1 or 0 depending on whether *ch* is a linebreak character.
-
-
-.. cfunction:: int Py_UNICODE_ISDECIMAL(Py_UNICODE ch)
-
-   Return 1 or 0 depending on whether *ch* is a decimal character.
-
-
-.. cfunction:: int Py_UNICODE_ISDIGIT(Py_UNICODE ch)
-
-   Return 1 or 0 depending on whether *ch* is a digit character.
-
-
-.. cfunction:: int Py_UNICODE_ISNUMERIC(Py_UNICODE ch)
-
-   Return 1 or 0 depending on whether *ch* is a numeric character.
-
-
-.. cfunction:: int Py_UNICODE_ISALPHA(Py_UNICODE ch)
-
-   Return 1 or 0 depending on whether *ch* is an alphabetic character.
-
-
-.. cfunction:: int Py_UNICODE_ISALNUM(Py_UNICODE ch)
-
-   Return 1 or 0 depending on whether *ch* is an alphanumeric character.
-
-These APIs can be used for fast direct character conversions:
-
-
-.. cfunction:: Py_UNICODE Py_UNICODE_TOLOWER(Py_UNICODE ch)
-
-   Return the character *ch* converted to lower case.
-
-
-.. cfunction:: Py_UNICODE Py_UNICODE_TOUPPER(Py_UNICODE ch)
-
-   Return the character *ch* converted to upper case.
-
-
-.. cfunction:: Py_UNICODE Py_UNICODE_TOTITLE(Py_UNICODE ch)
-
-   Return the character *ch* converted to title case.
-
-
-.. cfunction:: int Py_UNICODE_TODECIMAL(Py_UNICODE ch)
-
-   Return the character *ch* converted to a decimal positive integer.  Return
-   ``-1`` if this is not possible.  This macro does not raise exceptions.
-
-
-.. cfunction:: int Py_UNICODE_TODIGIT(Py_UNICODE ch)
-
-   Return the character *ch* converted to a single digit integer. Return ``-1`` if
-   this is not possible.  This macro does not raise exceptions.
-
-
-.. cfunction:: double Py_UNICODE_TONUMERIC(Py_UNICODE ch)
-
-   Return the character *ch* converted to a double. Return ``-1.0`` if this is not
-   possible.  This macro does not raise exceptions.
-
-To create Unicode objects and access their basic sequence properties, use these
-APIs:
-
-.. % --- Plain Py_UNICODE ---------------------------------------------------
-
-
-.. cfunction:: PyObject* PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size)
-
-   Create a Unicode Object from the Py_UNICODE buffer *u* of the given size. *u*
-   may be *NULL* which causes the contents to be undefined. It is the user's
-   responsibility to fill in the needed data.  The buffer is copied into the new
-   object. If the buffer is not *NULL*, the return value might be a shared object.
-   Therefore, modification of the resulting Unicode object is only allowed when *u*
-   is *NULL*.
-
-
-.. cfunction:: PyObject* PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size)
-
-   Create a Unicode Object from the char buffer *u*.  The bytes will be interpreted
-   as being UTF-8 encoded.  *u* may also be *NULL* which
-   causes the contents to be undefined. It is the user's responsibility to fill in
-   the needed data.  The buffer is copied into the new object. If the buffer is not
-   *NULL*, the return value might be a shared object. Therefore, modification of
-   the resulting Unicode object is only allowed when *u* is *NULL*.
-
-
-.. cfunction:: PyObject *PyUnicode_FromString(const char *u)
-
-   Create a Unicode object from an UTF-8 encoded null-terminated char buffer
-   *u*.
-
-
-.. cfunction:: PyObject* PyUnicode_FromFormat(const char *format, ...)
-
-   Take a C :cfunc:`printf`\ -style *format* string and a variable number of
-   arguments, calculate the size of the resulting Python unicode string and return
-   a string with the values formatted into it.  The variable arguments must be C
-   types and must correspond exactly to the format characters in the *format*
-   string.  The following format characters are allowed:
-
-   .. % The descriptions for %zd and %zu are wrong, but the truth is complicated
-   .. % because not all compilers support the %z width modifier -- we fake it
-   .. % when necessary via interpolating PY_FORMAT_SIZE_T.
-
-   +-------------------+---------------------+--------------------------------+
-   | Format Characters | Type                | Comment                        |
-   +===================+=====================+================================+
-   | :attr:`%%`        | *n/a*               | The literal % character.       |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%c`        | int                 | A single character,            |
-   |                   |                     | represented as an C int.       |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%d`        | int                 | Exactly equivalent to          |
-   |                   |                     | ``printf("%d")``.              |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%u`        | unsigned int        | Exactly equivalent to          |
-   |                   |                     | ``printf("%u")``.              |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%ld`       | long                | Exactly equivalent to          |
-   |                   |                     | ``printf("%ld")``.             |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%lu`       | unsigned long       | Exactly equivalent to          |
-   |                   |                     | ``printf("%lu")``.             |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%zd`       | Py_ssize_t          | Exactly equivalent to          |
-   |                   |                     | ``printf("%zd")``.             |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%zu`       | size_t              | Exactly equivalent to          |
-   |                   |                     | ``printf("%zu")``.             |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%i`        | int                 | Exactly equivalent to          |
-   |                   |                     | ``printf("%i")``.              |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%x`        | int                 | Exactly equivalent to          |
-   |                   |                     | ``printf("%x")``.              |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%s`        | char\*              | A null-terminated C character  |
-   |                   |                     | array.                         |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%p`        | void\*              | The hex representation of a C  |
-   |                   |                     | pointer. Mostly equivalent to  |
-   |                   |                     | ``printf("%p")`` except that   |
-   |                   |                     | it is guaranteed to start with |
-   |                   |                     | the literal ``0x`` regardless  |
-   |                   |                     | of what the platform's         |
-   |                   |                     | ``printf`` yields.             |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%U`        | PyObject\*          | A unicode object.              |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%V`        | PyObject\*, char \* | A unicode object (which may be |
-   |                   |                     | *NULL*) and a null-terminated  |
-   |                   |                     | C character array as a second  |
-   |                   |                     | parameter (which will be used, |
-   |                   |                     | if the first parameter is      |
-   |                   |                     | *NULL*).                       |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%S`        | PyObject\*          | The result of calling          |
-   |                   |                     | :func:`PyObject_Unicode`.      |
-   +-------------------+---------------------+--------------------------------+
-   | :attr:`%R`        | PyObject\*          | The result of calling          |
-   |                   |                     | :func:`PyObject_Repr`.         |
-   +-------------------+---------------------+--------------------------------+
-
-   An unrecognized format character causes all the rest of the format string to be
-   copied as-is to the result string, and any extra arguments discarded.
-
-
-.. cfunction:: PyObject* PyUnicode_FromFormatV(const char *format, va_list vargs)
-
-   Identical to :func:`PyUnicode_FromFormat` except that it takes exactly two
-   arguments.
-
-
-.. cfunction:: Py_UNICODE* PyUnicode_AsUnicode(PyObject *unicode)
-
-   Return a read-only pointer to the Unicode object's internal :ctype:`Py_UNICODE`
-   buffer, *NULL* if *unicode* is not a Unicode object.
-
-
-.. cfunction:: Py_ssize_t PyUnicode_GetSize(PyObject *unicode)
-
-   Return the length of the Unicode object.
-
-
-.. cfunction:: PyObject* PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, const char *errors)
-
-   Coerce an encoded object *obj* to an Unicode object and return a reference with
-   incremented refcount.
-
-   String and other char buffer compatible objects are decoded according to the
-   given encoding and using the error handling defined by errors.  Both can be
-   *NULL* to have the interface use the default values (see the next section for
-   details).
-
-   All other objects, including Unicode objects, cause a :exc:`TypeError` to be
-   set.
-
-   The API returns *NULL* if there was an error.  The caller is responsible for
-   decref'ing the returned objects.
-
-
-.. cfunction:: PyObject* PyUnicode_FromObject(PyObject *obj)
-
-   Shortcut for ``PyUnicode_FromEncodedObject(obj, NULL, "strict")`` which is used
-   throughout the interpreter whenever coercion to Unicode is needed.
-
-If the platform supports :ctype:`wchar_t` and provides a header file wchar.h,
-Python can interface directly to this type using the following functions.
-Support is optimized if Python's own :ctype:`Py_UNICODE` type is identical to
-the system's :ctype:`wchar_t`.
-
-.. % --- wchar_t support for platforms which support it ---------------------
-
-
-.. cfunction:: PyObject* PyUnicode_FromWideChar(const wchar_t *w, Py_ssize_t size)
-
-   Create a Unicode object from the :ctype:`wchar_t` buffer *w* of the given size.
-   Return *NULL* on failure.
-
-
-.. cfunction:: Py_ssize_t PyUnicode_AsWideChar(PyUnicodeObject *unicode, wchar_t *w, Py_ssize_t size)
-
-   Copy the Unicode object contents into the :ctype:`wchar_t` buffer *w*.  At most
-   *size* :ctype:`wchar_t` characters are copied (excluding a possibly trailing
-   0-termination character).  Return the number of :ctype:`wchar_t` characters
-   copied or -1 in case of an error.  Note that the resulting :ctype:`wchar_t`
-   string may or may not be 0-terminated.  It is the responsibility of the caller
-   to make sure that the :ctype:`wchar_t` string is 0-terminated in case this is
-   required by the application.
-
-
-.. _builtincodecs:
-
-Built-in Codecs
-^^^^^^^^^^^^^^^
-
-Python provides a set of builtin codecs which are written in C for speed. All of
-these codecs are directly usable via the following functions.
-
-Many of the following APIs take two arguments encoding and errors. These
-parameters encoding and errors have the same semantics as the ones of the
-builtin unicode() Unicode object constructor.
-
-Setting encoding to *NULL* causes the default encoding to be used which is
-ASCII.  The file system calls should use :cdata:`Py_FileSystemDefaultEncoding`
-as the encoding for file names. This variable should be treated as read-only: On
-some systems, it will be a pointer to a static string, on others, it will change
-at run-time (such as when the application invokes setlocale).
-
-Error handling is set by errors which may also be set to *NULL* meaning to use
-the default handling defined for the codec.  Default error handling for all
-builtin codecs is "strict" (:exc:`ValueError` is raised).
-
-The codecs all use a similar interface.  Only deviation from the following
-generic ones are documented for simplicity.
-
-These are the generic codec APIs:
-
-.. % --- Generic Codecs -----------------------------------------------------
-
-
-.. cfunction:: PyObject* PyUnicode_Decode(const char *s, Py_ssize_t size, const char *encoding, const char *errors)
-
-   Create a Unicode object by decoding *size* bytes of the encoded string *s*.
-   *encoding* and *errors* have the same meaning as the parameters of the same name
-   in the :func:`unicode` builtin function.  The codec to be used is looked up
-   using the Python codec registry.  Return *NULL* if an exception was raised by
-   the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_Encode(const Py_UNICODE *s, Py_ssize_t size, const char *encoding, const char *errors)
-
-   Encode the :ctype:`Py_UNICODE` buffer of the given size and return a Python
-   string object.  *encoding* and *errors* have the same meaning as the parameters
-   of the same name in the Unicode :meth:`encode` method.  The codec to be used is
-   looked up using the Python codec registry.  Return *NULL* if an exception was
-   raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_AsEncodedString(PyObject *unicode, const char *encoding, const char *errors)
-
-   Encode a Unicode object and return the result as Python string object.
-   *encoding* and *errors* have the same meaning as the parameters of the same name
-   in the Unicode :meth:`encode` method. The codec to be used is looked up using
-   the Python codec registry. Return *NULL* if an exception was raised by the
-   codec.
-
-These are the UTF-8 codec APIs:
-
-.. % --- UTF-8 Codecs -------------------------------------------------------
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeUTF8(const char *s, Py_ssize_t size, const char *errors)
-
-   Create a Unicode object by decoding *size* bytes of the UTF-8 encoded string
-   *s*. Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeUTF8Stateful(const char *s, Py_ssize_t size, const char *errors, Py_ssize_t *consumed)
-
-   If *consumed* is *NULL*, behave like :cfunc:`PyUnicode_DecodeUTF8`. If
-   *consumed* is not *NULL*, trailing incomplete UTF-8 byte sequences will not be
-   treated as an error. Those bytes will not be decoded and the number of bytes
-   that have been decoded will be stored in *consumed*.
-
-
-.. cfunction:: PyObject* PyUnicode_EncodeUTF8(const Py_UNICODE *s, Py_ssize_t size, const char *errors)
-
-   Encode the :ctype:`Py_UNICODE` buffer of the given size using UTF-8 and return a
-   Python string object.  Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_AsUTF8String(PyObject *unicode)
-
-   Encode a Unicode objects using UTF-8 and return the result as Python string
-   object.  Error handling is "strict".  Return *NULL* if an exception was raised
-   by the codec.
-
-These are the UTF-32 codec APIs:
-
-.. % --- UTF-32 Codecs ------------------------------------------------------ */
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeUTF32(const char *s, Py_ssize_t size, const char *errors, int *byteorder)
-
-   Decode *length* bytes from a UTF-32 encoded buffer string and return the
-   corresponding Unicode object.  *errors* (if non-*NULL*) defines the error
-   handling. It defaults to "strict".
-
-   If *byteorder* is non-*NULL*, the decoder starts decoding using the given byte
-   order::
-
-      *byteorder == -1: little endian
-      *byteorder == 0:  native order
-      *byteorder == 1:  big endian
-
-   and then switches if the first four bytes of the input data are a byte order mark
-   (BOM) and the specified byte order is native order.  This BOM is not copied into
-   the resulting Unicode string.  After completion, *\*byteorder* is set to the
-   current byte order at the end of input data.
-
-   In a narrow build codepoints outside the BMP will be decoded as surrogate pairs.
-
-   If *byteorder* is *NULL*, the codec starts in native order mode.
-
-   Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeUTF32Stateful(const char *s, Py_ssize_t size, const char *errors, int *byteorder, Py_ssize_t *consumed)
-
-   If *consumed* is *NULL*, behave like :cfunc:`PyUnicode_DecodeUTF32`. If
-   *consumed* is not *NULL*, :cfunc:`PyUnicode_DecodeUTF32Stateful` will not treat
-   trailing incomplete UTF-32 byte sequences (such as a number of bytes not divisible
-   by four) as an error. Those bytes will not be decoded and the number of bytes
-   that have been decoded will be stored in *consumed*.
-
-
-.. cfunction:: PyObject* PyUnicode_EncodeUTF32(const Py_UNICODE *s, Py_ssize_t size, const char *errors, int byteorder)
-
-   Return a Python bytes object holding the UTF-32 encoded value of the Unicode
-   data in *s*.  If *byteorder* is not ``0``, output is written according to the
-   following byte order::
-
-      byteorder == -1: little endian
-      byteorder == 0:  native byte order (writes a BOM mark)
-      byteorder == 1:  big endian
-
-   If byteorder is ``0``, the output string will always start with the Unicode BOM
-   mark (U+FEFF). In the other two modes, no BOM mark is prepended.
-
-   If *Py_UNICODE_WIDE* is not defined, surrogate pairs will be output
-   as a single codepoint.
-
-   Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_AsUTF32String(PyObject *unicode)
-
-   Return a Python string using the UTF-32 encoding in native byte order. The
-   string always starts with a BOM mark.  Error handling is "strict".  Return
-   *NULL* if an exception was raised by the codec.
-
-
-These are the UTF-16 codec APIs:
-
-.. % --- UTF-16 Codecs ------------------------------------------------------ */
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors, int *byteorder)
-
-   Decode *length* bytes from a UTF-16 encoded buffer string and return the
-   corresponding Unicode object.  *errors* (if non-*NULL*) defines the error
-   handling. It defaults to "strict".
-
-   If *byteorder* is non-*NULL*, the decoder starts decoding using the given byte
-   order::
-
-      *byteorder == -1: little endian
-      *byteorder == 0:  native order
-      *byteorder == 1:  big endian
-
-   and then switches if the first two bytes of the input data are a byte order mark
-   (BOM) and the specified byte order is native order.  This BOM is not copied into
-   the resulting Unicode string.  After completion, *\*byteorder* is set to the
-   current byte order at the end of input data.
-
-   If *byteorder* is *NULL*, the codec starts in native order mode.
-
-   Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeUTF16Stateful(const char *s, Py_ssize_t size, const char *errors, int *byteorder, Py_ssize_t *consumed)
-
-   If *consumed* is *NULL*, behave like :cfunc:`PyUnicode_DecodeUTF16`. If
-   *consumed* is not *NULL*, :cfunc:`PyUnicode_DecodeUTF16Stateful` will not treat
-   trailing incomplete UTF-16 byte sequences (such as an odd number of bytes or a
-   split surrogate pair) as an error. Those bytes will not be decoded and the
-   number of bytes that have been decoded will be stored in *consumed*.
-
-
-.. cfunction:: PyObject* PyUnicode_EncodeUTF16(const Py_UNICODE *s, Py_ssize_t size, const char *errors, int byteorder)
-
-   Return a Python string object holding the UTF-16 encoded value of the Unicode
-   data in *s*.  If *byteorder* is not ``0``, output is written according to the
-   following byte order::
-
-      byteorder == -1: little endian
-      byteorder == 0:  native byte order (writes a BOM mark)
-      byteorder == 1:  big endian
-
-   If byteorder is ``0``, the output string will always start with the Unicode BOM
-   mark (U+FEFF). In the other two modes, no BOM mark is prepended.
-
-   If *Py_UNICODE_WIDE* is defined, a single :ctype:`Py_UNICODE` value may get
-   represented as a surrogate pair. If it is not defined, each :ctype:`Py_UNICODE`
-   values is interpreted as an UCS-2 character.
-
-   Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_AsUTF16String(PyObject *unicode)
-
-   Return a Python string using the UTF-16 encoding in native byte order. The
-   string always starts with a BOM mark.  Error handling is "strict".  Return
-   *NULL* if an exception was raised by the codec.
-
-These are the "Unicode Escape" codec APIs:
-
-.. % --- Unicode-Escape Codecs ----------------------------------------------
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeUnicodeEscape(const char *s, Py_ssize_t size, const char *errors)
-
-   Create a Unicode object by decoding *size* bytes of the Unicode-Escape encoded
-   string *s*.  Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s, Py_ssize_t size)
-
-   Encode the :ctype:`Py_UNICODE` buffer of the given size using Unicode-Escape and
-   return a Python string object.  Return *NULL* if an exception was raised by the
-   codec.
-
-
-.. cfunction:: PyObject* PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
-
-   Encode a Unicode objects using Unicode-Escape and return the result as Python
-   string object.  Error handling is "strict". Return *NULL* if an exception was
-   raised by the codec.
-
-These are the "Raw Unicode Escape" codec APIs:
-
-.. % --- Raw-Unicode-Escape Codecs ------------------------------------------
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeRawUnicodeEscape(const char *s, Py_ssize_t size, const char *errors)
-
-   Create a Unicode object by decoding *size* bytes of the Raw-Unicode-Escape
-   encoded string *s*.  Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s, Py_ssize_t size, const char *errors)
-
-   Encode the :ctype:`Py_UNICODE` buffer of the given size using Raw-Unicode-Escape
-   and return a Python string object.  Return *NULL* if an exception was raised by
-   the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
-
-   Encode a Unicode objects using Raw-Unicode-Escape and return the result as
-   Python string object. Error handling is "strict". Return *NULL* if an exception
-   was raised by the codec.
-
-These are the Latin-1 codec APIs: Latin-1 corresponds to the first 256 Unicode
-ordinals and only these are accepted by the codecs during encoding.
-
-.. % --- Latin-1 Codecs -----------------------------------------------------
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeLatin1(const char *s, Py_ssize_t size, const char *errors)
-
-   Create a Unicode object by decoding *size* bytes of the Latin-1 encoded string
-   *s*.  Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_EncodeLatin1(const Py_UNICODE *s, Py_ssize_t size, const char *errors)
-
-   Encode the :ctype:`Py_UNICODE` buffer of the given size using Latin-1 and return
-   a Python string object.  Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_AsLatin1String(PyObject *unicode)
-
-   Encode a Unicode objects using Latin-1 and return the result as Python string
-   object.  Error handling is "strict".  Return *NULL* if an exception was raised
-   by the codec.
-
-These are the ASCII codec APIs.  Only 7-bit ASCII data is accepted. All other
-codes generate errors.
-
-.. % --- ASCII Codecs -------------------------------------------------------
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeASCII(const char *s, Py_ssize_t size, const char *errors)
-
-   Create a Unicode object by decoding *size* bytes of the ASCII encoded string
-   *s*.  Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_EncodeASCII(const Py_UNICODE *s, Py_ssize_t size, const char *errors)
-
-   Encode the :ctype:`Py_UNICODE` buffer of the given size using ASCII and return a
-   Python string object.  Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_AsASCIIString(PyObject *unicode)
-
-   Encode a Unicode objects using ASCII and return the result as Python string
-   object.  Error handling is "strict".  Return *NULL* if an exception was raised
-   by the codec.
-
-These are the mapping codec APIs:
-
-.. % --- Character Map Codecs -----------------------------------------------
-
-This codec is special in that it can be used to implement many different codecs
-(and this is in fact what was done to obtain most of the standard codecs
-included in the :mod:`encodings` package). The codec uses mapping to encode and
-decode characters.
-
-Decoding mappings must map single string characters to single Unicode
-characters, integers (which are then interpreted as Unicode ordinals) or None
-(meaning "undefined mapping" and causing an error).
-
-Encoding mappings must map single Unicode characters to single string
-characters, integers (which are then interpreted as Latin-1 ordinals) or None
-(meaning "undefined mapping" and causing an error).
-
-The mapping objects provided must only support the __getitem__ mapping
-interface.
-
-If a character lookup fails with a LookupError, the character is copied as-is
-meaning that its ordinal value will be interpreted as Unicode or Latin-1 ordinal
-resp. Because of this, mappings only need to contain those mappings which map
-characters to different code points.
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeCharmap(const char *s, Py_ssize_t size, PyObject *mapping, const char *errors)
-
-   Create a Unicode object by decoding *size* bytes of the encoded string *s* using
-   the given *mapping* object.  Return *NULL* if an exception was raised by the
-   codec. If *mapping* is *NULL* latin-1 decoding will be done. Else it can be a
-   dictionary mapping byte or a unicode string, which is treated as a lookup table.
-   Byte values greater that the length of the string and U+FFFE "characters" are
-   treated as "undefined mapping".
-
-
-.. cfunction:: PyObject* PyUnicode_EncodeCharmap(const Py_UNICODE *s, Py_ssize_t size, PyObject *mapping, const char *errors)
-
-   Encode the :ctype:`Py_UNICODE` buffer of the given size using the given
-   *mapping* object and return a Python string object. Return *NULL* if an
-   exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_AsCharmapString(PyObject *unicode, PyObject *mapping)
-
-   Encode a Unicode objects using the given *mapping* object and return the result
-   as Python string object.  Error handling is "strict".  Return *NULL* if an
-   exception was raised by the codec.
-
-The following codec API is special in that maps Unicode to Unicode.
-
-
-.. cfunction:: PyObject* PyUnicode_TranslateCharmap(const Py_UNICODE *s, Py_ssize_t size, PyObject *table, const char *errors)
-
-   Translate a :ctype:`Py_UNICODE` buffer of the given length by applying a
-   character mapping *table* to it and return the resulting Unicode object.  Return
-   *NULL* when an exception was raised by the codec.
-
-   The *mapping* table must map Unicode ordinal integers to Unicode ordinal
-   integers or None (causing deletion of the character).
-
-   Mapping tables need only provide the :meth:`__getitem__` interface; dictionaries
-   and sequences work well.  Unmapped character ordinals (ones which cause a
-   :exc:`LookupError`) are left untouched and are copied as-is.
-
-These are the MBCS codec APIs. They are currently only available on Windows and
-use the Win32 MBCS converters to implement the conversions.  Note that MBCS (or
-DBCS) is a class of encodings, not just one.  The target encoding is defined by
-the user settings on the machine running the codec.
-
-.. % --- MBCS codecs for Windows --------------------------------------------
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeMBCS(const char *s, Py_ssize_t size, const char *errors)
-
-   Create a Unicode object by decoding *size* bytes of the MBCS encoded string *s*.
-   Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_DecodeMBCSStateful(const char *s, int size, const char *errors, int *consumed)
-
-   If *consumed* is *NULL*, behave like :cfunc:`PyUnicode_DecodeMBCS`. If
-   *consumed* is not *NULL*, :cfunc:`PyUnicode_DecodeMBCSStateful` will not decode
-   trailing lead byte and the number of bytes that have been decoded will be stored
-   in *consumed*.
-
-
-.. cfunction:: PyObject* PyUnicode_EncodeMBCS(const Py_UNICODE *s, Py_ssize_t size, const char *errors)
-
-   Encode the :ctype:`Py_UNICODE` buffer of the given size using MBCS and return a
-   Python string object.  Return *NULL* if an exception was raised by the codec.
-
-
-.. cfunction:: PyObject* PyUnicode_AsMBCSString(PyObject *unicode)
-
-   Encode a Unicode objects using MBCS and return the result as Python string
-   object.  Error handling is "strict".  Return *NULL* if an exception was raised
-   by the codec.
-
-.. % --- Methods & Slots ----------------------------------------------------
-
-
-.. _unicodemethodsandslots:
-
-Methods and Slot Functions
-^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-The following APIs are capable of handling Unicode objects and strings on input
-(we refer to them as strings in the descriptions) and return Unicode objects or
-integers as appropriate.
-
-They all return *NULL* or ``-1`` if an exception occurs.
-
-
-.. cfunction:: PyObject* PyUnicode_Concat(PyObject *left, PyObject *right)
-
-   Concat two strings giving a new Unicode string.
-
-
-.. cfunction:: PyObject* PyUnicode_Split(PyObject *s, PyObject *sep, Py_ssize_t maxsplit)
-
-   Split a string giving a list of Unicode strings.  If sep is *NULL*, splitting
-   will be done at all whitespace substrings.  Otherwise, splits occur at the given
-   separator.  At most *maxsplit* splits will be done.  If negative, no limit is
-   set.  Separators are not included in the resulting list.
-
-
-.. cfunction:: PyObject* PyUnicode_Splitlines(PyObject *s, int keepend)
-
-   Split a Unicode string at line breaks, returning a list of Unicode strings.
-   CRLF is considered to be one line break.  If *keepend* is 0, the Line break
-   characters are not included in the resulting strings.
-
-
-.. cfunction:: PyObject* PyUnicode_Translate(PyObject *str, PyObject *table, const char *errors)
-
-   Translate a string by applying a character mapping table to it and return the
-   resulting Unicode object.
-
-   The mapping table must map Unicode ordinal integers to Unicode ordinal integers
-   or None (causing deletion of the character).
-
-   Mapping tables need only provide the :meth:`__getitem__` interface; dictionaries
-   and sequences work well.  Unmapped character ordinals (ones which cause a
-   :exc:`LookupError`) are left untouched and are copied as-is.
-
-   *errors* has the usual meaning for codecs. It may be *NULL* which indicates to
-   use the default error handling.
-
-
-.. cfunction:: PyObject* PyUnicode_Join(PyObject *separator, PyObject *seq)
-
-   Join a sequence of strings using the given separator and return the resulting
-   Unicode string.
-
-
-.. cfunction:: int PyUnicode_Tailmatch(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end, int direction)
-
-   Return 1 if *substr* matches *str*[*start*:*end*] at the given tail end
-   (*direction* == -1 means to do a prefix match, *direction* == 1 a suffix match),
-   0 otherwise. Return ``-1`` if an error occurred.
-
-
-.. cfunction:: Py_ssize_t PyUnicode_Find(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end, int direction)
-
-   Return the first position of *substr* in *str*[*start*:*end*] using the given
-   *direction* (*direction* == 1 means to do a forward search, *direction* == -1 a
-   backward search).  The return value is the index of the first match; a value of
-   ``-1`` indicates that no match was found, and ``-2`` indicates that an error
-   occurred and an exception has been set.
-
-
-.. cfunction:: Py_ssize_t PyUnicode_Count(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end)
-
-   Return the number of non-overlapping occurrences of *substr* in
-   ``str[start:end]``.  Return ``-1`` if an error occurred.
-
-
-.. cfunction:: PyObject* PyUnicode_Replace(PyObject *str, PyObject *substr, PyObject *replstr, Py_ssize_t maxcount)
-
-   Replace at most *maxcount* occurrences of *substr* in *str* with *replstr* and
-   return the resulting Unicode object. *maxcount* == -1 means replace all
-   occurrences.
-
-
-.. cfunction:: int PyUnicode_Compare(PyObject *left, PyObject *right)
-
-   Compare two strings and return -1, 0, 1 for less than, equal, and greater than,
-   respectively.
-
-
-.. cfunction:: int PyUnicode_RichCompare(PyObject *left,  PyObject *right,  int op)
-
-   Rich compare two unicode strings and return one of the following:
-
-   * ``NULL`` in case an exception was raised
-   * :const:`Py_True` or :const:`Py_False` for successful comparisons
-   * :const:`Py_NotImplemented` in case the type combination is unknown
-
-   Note that :const:`Py_EQ` and :const:`Py_NE` comparisons can cause a
-   :exc:`UnicodeWarning` in case the conversion of the arguments to Unicode fails
-   with a :exc:`UnicodeDecodeError`.
-
-   Possible values for *op* are :const:`Py_GT`, :const:`Py_GE`, :const:`Py_EQ`,
-   :const:`Py_NE`, :const:`Py_LT`, and :const:`Py_LE`.
-
-
-.. cfunction:: PyObject* PyUnicode_Format(PyObject *format, PyObject *args)
-
-   Return a new string object from *format* and *args*; this is analogous to
-   ``format % args``.  The *args* argument must be a tuple.
-
-
-.. cfunction:: int PyUnicode_Contains(PyObject *container, PyObject *element)
-
-   Check whether *element* is contained in *container* and return true or false
-   accordingly.
-
-   *element* has to coerce to a one element Unicode string. ``-1`` is returned if
-   there was an error.
-
-
-.. cfunction:: void PyUnicode_InternInPlace(PyObject **string)
-
-   Intern the argument *\*string* in place.  The argument must be the address of a
-   pointer variable pointing to a Python unicode string object.  If there is an
-   existing interned string that is the same as *\*string*, it sets *\*string* to
-   it (decrementing the reference count of the old string object and incrementing
-   the reference count of the interned string object), otherwise it leaves
-   *\*string* alone and interns it (incrementing its reference count).
-   (Clarification: even though there is a lot of talk about reference counts, think
-   of this function as reference-count-neutral; you own the object after the call
-   if and only if you owned it before the call.)
-
-
-.. cfunction:: PyObject* PyUnicode_InternFromString(const char *v)
-
-   A combination of :cfunc:`PyUnicode_FromString` and
-   :cfunc:`PyUnicode_InternInPlace`, returning either a new unicode string object
-   that has been interned, or a new ("owned") reference to an earlier interned
-   string object with the same value.
-
-
-.. _bufferobjects:
-
-Buffer Objects
---------------
-
-.. sectionauthor:: Greg Stein <gstein at lyra.org>
-
-
-.. index::
-   object: buffer
-   single: buffer interface
-
-Python objects implemented in C can export a group of functions called the
-"buffer interface."  These functions can be used by an object to expose its data
-in a raw, byte-oriented format. Clients of the object can use the buffer
-interface to access the object data directly, without needing to copy it first.
-
-Two examples of objects that support the buffer interface are strings and
-arrays. The string object exposes the character contents in the buffer
-interface's byte-oriented form. An array can also expose its contents, but it
-should be noted that array elements may be multi-byte values.
-
-An example user of the buffer interface is the file object's :meth:`write`
-method. Any object that can export a series of bytes through the buffer
-interface can be written to a file. There are a number of format codes to
-:cfunc:`PyArg_ParseTuple` that operate against an object's buffer interface,
-returning data from the target object.
-
-.. index:: single: PyBufferProcs
-
-More information on the buffer interface is provided in the section 
-:ref:`buffer-structs`, under the description for :ctype:`PyBufferProcs`.
-
-A "buffer object" is defined in the :file:`bufferobject.h` header (included by
-:file:`Python.h`). These objects look very similar to string objects at the
-Python programming level: they support slicing, indexing, concatenation, and
-some other standard string operations. However, their data can come from one of
-two sources: from a block of memory, or from another object which exports the
-buffer interface.
-
-Buffer objects are useful as a way to expose the data from another object's
-buffer interface to the Python programmer. They can also be used as a zero-copy
-slicing mechanism. Using their ability to reference a block of memory, it is
-possible to expose any data to the Python programmer quite easily. The memory
-could be a large, constant array in a C extension, it could be a raw block of
-memory for manipulation before passing to an operating system library, or it
-could be used to pass around structured data in its native, in-memory format.
-
-
-.. ctype:: PyBufferObject
-
-   This subtype of :ctype:`PyObject` represents a buffer object.
-
-
-.. cvar:: PyTypeObject PyBuffer_Type
-
-   .. index:: single: BufferType (in module types)
-
-   The instance of :ctype:`PyTypeObject` which represents the Python buffer type;
-   it is the same object as ``buffer`` and  ``types.BufferType`` in the Python
-   layer. .
-
-
-.. cvar:: int Py_END_OF_BUFFER
-
-   This constant may be passed as the *size* parameter to
-   :cfunc:`PyBuffer_FromObject` or :cfunc:`PyBuffer_FromReadWriteObject`.  It
-   indicates that the new :ctype:`PyBufferObject` should refer to *base* object
-   from the specified *offset* to the end of its exported buffer.  Using this
-   enables the caller to avoid querying the *base* object for its length.
-
-
-.. cfunction:: int PyBuffer_Check(PyObject *p)
-
-   Return true if the argument has type :cdata:`PyBuffer_Type`.
-
-
-.. cfunction:: PyObject* PyBuffer_FromObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size)
-
-   Return a new read-only buffer object.  This raises :exc:`TypeError` if *base*
-   doesn't support the read-only buffer protocol or doesn't provide exactly one
-   buffer segment, or it raises :exc:`ValueError` if *offset* is less than zero.
-   The buffer will hold a reference to the *base* object, and the buffer's contents
-   will refer to the *base* object's buffer interface, starting as position
-   *offset* and extending for *size* bytes. If *size* is :const:`Py_END_OF_BUFFER`,
-   then the new buffer's contents extend to the length of the *base* object's
-   exported buffer data.
-
-
-.. cfunction:: PyObject* PyBuffer_FromReadWriteObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size)
-
-   Return a new writable buffer object.  Parameters and exceptions are similar to
-   those for :cfunc:`PyBuffer_FromObject`.  If the *base* object does not export
-   the writable buffer protocol, then :exc:`TypeError` is raised.
-
-
-.. cfunction:: PyObject* PyBuffer_FromMemory(void *ptr, Py_ssize_t size)
-
-   Return a new read-only buffer object that reads from a specified location in
-   memory, with a specified size.  The caller is responsible for ensuring that the
-   memory buffer, passed in as *ptr*, is not deallocated while the returned buffer
-   object exists.  Raises :exc:`ValueError` if *size* is less than zero.  Note that
-   :const:`Py_END_OF_BUFFER` may *not* be passed for the *size* parameter;
-   :exc:`ValueError` will be raised in that case.
-
-
-.. cfunction:: PyObject* PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size)
-
-   Similar to :cfunc:`PyBuffer_FromMemory`, but the returned buffer is writable.
-
-
-.. cfunction:: PyObject* PyBuffer_New(Py_ssize_t size)
-
-   Return a new writable buffer object that maintains its own memory buffer of
-   *size* bytes.  :exc:`ValueError` is returned if *size* is not zero or positive.
-   Note that the memory buffer (as returned by :cfunc:`PyObject_AsWriteBuffer`) is
-   not specifically aligned.
-
-
-.. _tupleobjects:
-
-Tuple Objects
--------------
-
-.. index:: object: tuple
-
-
-.. ctype:: PyTupleObject
-
-   This subtype of :ctype:`PyObject` represents a Python tuple object.
-
-
-.. cvar:: PyTypeObject PyTuple_Type
-
-   .. index:: single: TupleType (in module types)
-
-   This instance of :ctype:`PyTypeObject` represents the Python tuple type; it is
-   the same object as ``tuple`` and ``types.TupleType`` in the Python layer..
-
-
-.. cfunction:: int PyTuple_Check(PyObject *p)
-
-   Return true if *p* is a tuple object or an instance of a subtype of the tuple
-   type.
-
-
-.. cfunction:: int PyTuple_CheckExact(PyObject *p)
-
-   Return true if *p* is a tuple object, but not an instance of a subtype of the
-   tuple type.
-
-
-.. cfunction:: PyObject* PyTuple_New(Py_ssize_t len)
-
-   Return a new tuple object of size *len*, or *NULL* on failure.
-
-
-.. cfunction:: PyObject* PyTuple_Pack(Py_ssize_t n, ...)
-
-   Return a new tuple object of size *n*, or *NULL* on failure. The tuple values
-   are initialized to the subsequent *n* C arguments pointing to Python objects.
-   ``PyTuple_Pack(2, a, b)`` is equivalent to ``Py_BuildValue("(OO)", a, b)``.
-
-
-.. cfunction:: Py_ssize_t PyTuple_Size(PyObject *p)
-
-   Take a pointer to a tuple object, and return the size of that tuple.
-
-
-.. cfunction:: Py_ssize_t PyTuple_GET_SIZE(PyObject *p)
-
-   Return the size of the tuple *p*, which must be non-*NULL* and point to a tuple;
-   no error checking is performed.
-
-
-.. cfunction:: PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos)
-
-   Return the object at position *pos* in the tuple pointed to by *p*.  If *pos* is
-   out of bounds, return *NULL* and sets an :exc:`IndexError` exception.
-
-
-.. cfunction:: PyObject* PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)
-
-   Like :cfunc:`PyTuple_GetItem`, but does no checking of its arguments.
-
-
-.. cfunction:: PyObject* PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)
-
-   Take a slice of the tuple pointed to by *p* from *low* to *high* and return it
-   as a new tuple.
-
-
-.. cfunction:: int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
-
-   Insert a reference to object *o* at position *pos* of the tuple pointed to by
-   *p*. Return ``0`` on success.
-
-   .. note::
-
-      This function "steals" a reference to *o*.
-
-
-.. cfunction:: void PyTuple_SET_ITEM(PyObject *p, Py_ssize_t pos, PyObject *o)
-
-   Like :cfunc:`PyTuple_SetItem`, but does no error checking, and should *only* be
-   used to fill in brand new tuples.
-
-   .. note::
-
-      This function "steals" a reference to *o*.
-
-
-.. cfunction:: int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize)
-
-   Can be used to resize a tuple.  *newsize* will be the new length of the tuple.
-   Because tuples are *supposed* to be immutable, this should only be used if there
-   is only one reference to the object.  Do *not* use this if the tuple may already
-   be known to some other part of the code.  The tuple will always grow or shrink
-   at the end.  Think of this as destroying the old tuple and creating a new one,
-   only more efficiently.  Returns ``0`` on success. Client code should never
-   assume that the resulting value of ``*p`` will be the same as before calling
-   this function. If the object referenced by ``*p`` is replaced, the original
-   ``*p`` is destroyed.  On failure, returns ``-1`` and sets ``*p`` to *NULL*, and
-   raises :exc:`MemoryError` or :exc:`SystemError`.
-
-
-.. _listobjects:
-
-List Objects
-------------
-
-.. index:: object: list
-
-
-.. ctype:: PyListObject
-
-   This subtype of :ctype:`PyObject` represents a Python list object.
-
-
-.. cvar:: PyTypeObject PyList_Type
-
-   .. index:: single: ListType (in module types)
-
-   This instance of :ctype:`PyTypeObject` represents the Python list type.  This is
-   the same object as ``list`` and ``types.ListType`` in the Python layer.
-
-
-.. cfunction:: int PyList_Check(PyObject *p)
-
-   Return true if *p* is a list object or an instance of a subtype of the list
-   type.
-
-
-.. cfunction:: int PyList_CheckExact(PyObject *p)
-
-   Return true if *p* is a list object, but not an instance of a subtype of the
-   list type.
-
-
-.. cfunction:: PyObject* PyList_New(Py_ssize_t len)
-
-   Return a new list of length *len* on success, or *NULL* on failure.
-
-   .. note::
-
-      If *length* is greater than zero, the returned list object's items are set to
-      ``NULL``.  Thus you cannot use abstract API functions such as
-      :cfunc:`PySequence_SetItem`  or expose the object to Python code before setting
-      all items to a real object with :cfunc:`PyList_SetItem`.
-
-
-.. cfunction:: Py_ssize_t PyList_Size(PyObject *list)
-
-   .. index:: builtin: len
-
-   Return the length of the list object in *list*; this is equivalent to
-   ``len(list)`` on a list object.
-
-
-.. cfunction:: Py_ssize_t PyList_GET_SIZE(PyObject *list)
-
-   Macro form of :cfunc:`PyList_Size` without error checking.
-
-
-.. cfunction:: PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)
-
-   Return the object at position *pos* in the list pointed to by *p*.  The position
-   must be positive, indexing from the end of the list is not supported.  If *pos*
-   is out of bounds, return *NULL* and set an :exc:`IndexError` exception.
-
-
-.. cfunction:: PyObject* PyList_GET_ITEM(PyObject *list, Py_ssize_t i)
-
-   Macro form of :cfunc:`PyList_GetItem` without error checking.
-
-
-.. cfunction:: int PyList_SetItem(PyObject *list, Py_ssize_t index, PyObject *item)
-
-   Set the item at index *index* in list to *item*.  Return ``0`` on success or
-   ``-1`` on failure.
-
-   .. note::
-
-      This function "steals" a reference to *item* and discards a reference to an item
-      already in the list at the affected position.
-
-
-.. cfunction:: void PyList_SET_ITEM(PyObject *list, Py_ssize_t i, PyObject *o)
-
-   Macro form of :cfunc:`PyList_SetItem` without error checking. This is normally
-   only used to fill in new lists where there is no previous content.
-
-   .. note::
-
-      This function "steals" a reference to *item*, and, unlike
-      :cfunc:`PyList_SetItem`, does *not* discard a reference to any item that it
-      being replaced; any reference in *list* at position *i* will be leaked.
-
-
-.. cfunction:: int PyList_Insert(PyObject *list, Py_ssize_t index, PyObject *item)
-
-   Insert the item *item* into list *list* in front of index *index*.  Return ``0``
-   if successful; return ``-1`` and set an exception if unsuccessful.  Analogous to
-   ``list.insert(index, item)``.
-
-
-.. cfunction:: int PyList_Append(PyObject *list, PyObject *item)
-
-   Append the object *item* at the end of list *list*. Return ``0`` if successful;
-   return ``-1`` and set an exception if unsuccessful.  Analogous to
-   ``list.append(item)``.
-
-
-.. cfunction:: PyObject* PyList_GetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high)
-
-   Return a list of the objects in *list* containing the objects *between* *low*
-   and *high*.  Return *NULL* and set an exception if unsuccessful. Analogous to
-   ``list[low:high]``.
-
-
-.. cfunction:: int PyList_SetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high, PyObject *itemlist)
-
-   Set the slice of *list* between *low* and *high* to the contents of *itemlist*.
-   Analogous to ``list[low:high] = itemlist``. The *itemlist* may be *NULL*,
-   indicating the assignment of an empty list (slice deletion). Return ``0`` on
-   success, ``-1`` on failure.
-
-
-.. cfunction:: int PyList_Sort(PyObject *list)
-
-   Sort the items of *list* in place.  Return ``0`` on success, ``-1`` on failure.
-   This is equivalent to ``list.sort()``.
-
-
-.. cfunction:: int PyList_Reverse(PyObject *list)
-
-   Reverse the items of *list* in place.  Return ``0`` on success, ``-1`` on
-   failure.  This is the equivalent of ``list.reverse()``.
-
-
-.. cfunction:: PyObject* PyList_AsTuple(PyObject *list)
-
-   .. index:: builtin: tuple
-
-   Return a new tuple object containing the contents of *list*; equivalent to
-   ``tuple(list)``.
-
-
-.. _mapobjects:
-
-Mapping Objects
-===============
-
-.. index:: object: mapping
-
-
-.. _dictobjects:
-
-Dictionary Objects
-------------------
-
-.. index:: object: dictionary
-
-
-.. ctype:: PyDictObject
-
-   This subtype of :ctype:`PyObject` represents a Python dictionary object.
-
-
-.. cvar:: PyTypeObject PyDict_Type
-
-   .. index::
-      single: DictType (in module types)
-      single: DictionaryType (in module types)
-
-   This instance of :ctype:`PyTypeObject` represents the Python dictionary type.
-   This is exposed to Python programs as ``dict`` and ``types.DictType``.
-
-
-.. cfunction:: int PyDict_Check(PyObject *p)
-
-   Return true if *p* is a dict object or an instance of a subtype of the dict
-   type.
-
-
-.. cfunction:: int PyDict_CheckExact(PyObject *p)
-
-   Return true if *p* is a dict object, but not an instance of a subtype of the
-   dict type.
-
-
-.. cfunction:: PyObject* PyDict_New()
-
-   Return a new empty dictionary, or *NULL* on failure.
-
-
-.. cfunction:: PyObject* PyDictProxy_New(PyObject *dict)
-
-   Return a proxy object for a mapping which enforces read-only behavior.  This is
-   normally used to create a proxy to prevent modification of the dictionary for
-   non-dynamic class types.
-
-
-.. cfunction:: void PyDict_Clear(PyObject *p)
-
-   Empty an existing dictionary of all key-value pairs.
-
-
-.. cfunction:: int PyDict_Contains(PyObject *p, PyObject *key)
-
-   Determine if dictionary *p* contains *key*.  If an item in *p* is matches *key*,
-   return ``1``, otherwise return ``0``.  On error, return ``-1``.  This is
-   equivalent to the Python expression ``key in p``.
-
-
-.. cfunction:: PyObject* PyDict_Copy(PyObject *p)
-
-   Return a new dictionary that contains the same key-value pairs as *p*.
-
-
-.. cfunction:: int PyDict_SetItem(PyObject *p, PyObject *key, PyObject *val)
-
-   Insert *value* into the dictionary *p* with a key of *key*.  *key* must be
-   hashable; if it isn't, :exc:`TypeError` will be raised. Return ``0`` on success
-   or ``-1`` on failure.
-
-
-.. cfunction:: int PyDict_SetItemString(PyObject *p, const char *key, PyObject *val)
-
-   .. index:: single: PyString_FromString()
-
-   Insert *value* into the dictionary *p* using *key* as a key. *key* should be a
-   :ctype:`char\*`.  The key object is created using ``PyString_FromString(key)``.
-   Return ``0`` on success or ``-1`` on failure.
-
-
-.. cfunction:: int PyDict_DelItem(PyObject *p, PyObject *key)
-
-   Remove the entry in dictionary *p* with key *key*. *key* must be hashable; if it
-   isn't, :exc:`TypeError` is raised.  Return ``0`` on success or ``-1`` on
-   failure.
-
-
-.. cfunction:: int PyDict_DelItemString(PyObject *p, char *key)
-
-   Remove the entry in dictionary *p* which has a key specified by the string
-   *key*.  Return ``0`` on success or ``-1`` on failure.
-
-
-.. cfunction:: PyObject* PyDict_GetItem(PyObject *p, PyObject *key)
-
-   Return the object from dictionary *p* which has a key *key*.  Return *NULL* if
-   the key *key* is not present, but *without* setting an exception.
-
-
-.. cfunction:: PyObject* PyDict_GetItemString(PyObject *p, const char *key)
-
-   This is the same as :cfunc:`PyDict_GetItem`, but *key* is specified as a
-   :ctype:`char\*`, rather than a :ctype:`PyObject\*`.
-
-
-.. cfunction:: PyObject* PyDict_Items(PyObject *p)
-
-   Return a :ctype:`PyListObject` containing all the items from the dictionary, as
-   in the dictionary method :meth:`dict.items`.
-
-
-.. cfunction:: PyObject* PyDict_Keys(PyObject *p)
-
-   Return a :ctype:`PyListObject` containing all the keys from the dictionary, as
-   in the dictionary method :meth:`dict.keys`.
-
-
-.. cfunction:: PyObject* PyDict_Values(PyObject *p)
-
-   Return a :ctype:`PyListObject` containing all the values from the dictionary
-   *p*, as in the dictionary method :meth:`dict.values`.
-
-
-.. cfunction:: Py_ssize_t PyDict_Size(PyObject *p)
-
-   .. index:: builtin: len
-
-   Return the number of items in the dictionary.  This is equivalent to ``len(p)``
-   on a dictionary.
-
-
-.. cfunction:: int PyDict_Next(PyObject *p, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue)
-
-   Iterate over all key-value pairs in the dictionary *p*.  The :ctype:`int`
-   referred to by *ppos* must be initialized to ``0`` prior to the first call to
-   this function to start the iteration; the function returns true for each pair in
-   the dictionary, and false once all pairs have been reported.  The parameters
-   *pkey* and *pvalue* should either point to :ctype:`PyObject\*` variables that
-   will be filled in with each key and value, respectively, or may be *NULL*.  Any
-   references returned through them are borrowed.  *ppos* should not be altered
-   during iteration. Its value represents offsets within the internal dictionary
-   structure, and since the structure is sparse, the offsets are not consecutive.
-
-   For example::
-
-      PyObject *key, *value;
-      Py_ssize_t pos = 0;
-
-      while (PyDict_Next(self->dict, &pos, &key, &value)) {
-          /* do something interesting with the values... */
-          ...
-      }
-
-   The dictionary *p* should not be mutated during iteration.  It is safe (since
-   Python 2.1) to modify the values of the keys as you iterate over the dictionary,
-   but only so long as the set of keys does not change.  For example::
-
-      PyObject *key, *value;
-      Py_ssize_t pos = 0;
-
-      while (PyDict_Next(self->dict, &pos, &key, &value)) {
-          int i = PyInt_AS_LONG(value) + 1;
-          PyObject *o = PyInt_FromLong(i);
-          if (o == NULL)
-              return -1;
-          if (PyDict_SetItem(self->dict, key, o) < 0) {
-              Py_DECREF(o);
-              return -1;
-          }
-          Py_DECREF(o);
-      }
-
-
-.. cfunction:: int PyDict_Merge(PyObject *a, PyObject *b, int override)
-
-   Iterate over mapping object *b* adding key-value pairs to dictionary *a*. *b*
-   may be a dictionary, or any object supporting :func:`PyMapping_Keys` and
-   :func:`PyObject_GetItem`. If *override* is true, existing pairs in *a* will be
-   replaced if a matching key is found in *b*, otherwise pairs will only be added
-   if there is not a matching key in *a*. Return ``0`` on success or ``-1`` if an
-   exception was raised.
-
-
-.. cfunction:: int PyDict_Update(PyObject *a, PyObject *b)
-
-   This is the same as ``PyDict_Merge(a, b, 1)`` in C, or ``a.update(b)`` in
-   Python.  Return ``0`` on success or ``-1`` if an exception was raised.
-
-
-.. cfunction:: int PyDict_MergeFromSeq2(PyObject *a, PyObject *seq2, int override)
-
-   Update or merge into dictionary *a*, from the key-value pairs in *seq2*.  *seq2*
-   must be an iterable object producing iterable objects of length 2, viewed as
-   key-value pairs.  In case of duplicate keys, the last wins if *override* is
-   true, else the first wins. Return ``0`` on success or ``-1`` if an exception was
-   raised. Equivalent Python (except for the return value)::
-
-      def PyDict_MergeFromSeq2(a, seq2, override):
-          for key, value in seq2:
-              if override or key not in a:
-                  a[key] = value
-
-
-.. _otherobjects:
-
-Other Objects
-=============
-
-.. _fileobjects:
-
-File Objects
-------------
-
-.. index:: object: file
-
-Python's built-in file objects are implemented entirely on the :ctype:`FILE\*`
-support from the C standard library.  This is an implementation detail and may
-change in future releases of Python.
-
-
-.. ctype:: PyFileObject
-
-   This subtype of :ctype:`PyObject` represents a Python file object.
-
-
-.. cvar:: PyTypeObject PyFile_Type
-
-   .. index:: single: FileType (in module types)
-
-   This instance of :ctype:`PyTypeObject` represents the Python file type.  This is
-   exposed to Python programs as ``file`` and ``types.FileType``.
-
-
-.. cfunction:: int PyFile_Check(PyObject *p)
-
-   Return true if its argument is a :ctype:`PyFileObject` or a subtype of
-   :ctype:`PyFileObject`.
-
-
-.. cfunction:: int PyFile_CheckExact(PyObject *p)
-
-   Return true if its argument is a :ctype:`PyFileObject`, but not a subtype of
-   :ctype:`PyFileObject`.
-
-
-.. cfunction:: PyObject* PyFile_FromString(char *filename, char *mode)
-
-   .. index:: single: fopen()
-
-   On success, return a new file object that is opened on the file given by
-   *filename*, with a file mode given by *mode*, where *mode* has the same
-   semantics as the standard C routine :cfunc:`fopen`.  On failure, return *NULL*.
-
-
-.. cfunction:: PyObject* PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE*))
-
-   Create a new :ctype:`PyFileObject` from the already-open standard C file
-   pointer, *fp*.  The function *close* will be called when the file should be
-   closed.  Return *NULL* on failure.
-
-
-.. cfunction:: FILE* PyFile_AsFile(PyObject *p)
-
-   Return the file object associated with *p* as a :ctype:`FILE\*`.
-
-
-.. cfunction:: PyObject* PyFile_GetLine(PyObject *p, int n)
-
-   .. index:: single: EOFError (built-in exception)
-
-   Equivalent to ``p.readline([n])``, this function reads one line from the
-   object *p*.  *p* may be a file object or any object with a :meth:`readline`
-   method.  If *n* is ``0``, exactly one line is read, regardless of the length of
-   the line.  If *n* is greater than ``0``, no more than *n* bytes will be read
-   from the file; a partial line can be returned.  In both cases, an empty string
-   is returned if the end of the file is reached immediately.  If *n* is less than
-   ``0``, however, one line is read regardless of length, but :exc:`EOFError` is
-   raised if the end of the file is reached immediately.
-
-
-.. cfunction:: PyObject* PyFile_Name(PyObject *p)
-
-   Return the name of the file specified by *p* as a string object.
-
-
-.. cfunction:: void PyFile_SetBufSize(PyFileObject *p, int n)
-
-   .. index:: single: setvbuf()
-
-   Available on systems with :cfunc:`setvbuf` only.  This should only be called
-   immediately after file object creation.
-
-
-.. cfunction:: int PyFile_SetEncoding(PyFileObject *p, const char *enc)
-
-   Set the file's encoding for Unicode output to *enc*. Return 1 on success and 0
-   on failure.
-
-
-.. cfunction:: int PyFile_SoftSpace(PyObject *p, int newflag)
-
-   .. index:: single: softspace (file attribute)
-
-   This function exists for internal use by the interpreter.  Set the
-   :attr:`softspace` attribute of *p* to *newflag* and return the previous value.
-   *p* does not have to be a file object for this function to work properly; any
-   object is supported (thought its only interesting if the :attr:`softspace`
-   attribute can be set).  This function clears any errors, and will return ``0``
-   as the previous value if the attribute either does not exist or if there were
-   errors in retrieving it.  There is no way to detect errors from this function,
-   but doing so should not be needed.
-
-
-.. cfunction:: int PyFile_WriteObject(PyObject *obj, PyObject *p, int flags)
-
-   .. index:: single: Py_PRINT_RAW
-
-   Write object *obj* to file object *p*.  The only supported flag for *flags* is
-   :const:`Py_PRINT_RAW`; if given, the :func:`str` of the object is written
-   instead of the :func:`repr`.  Return ``0`` on success or ``-1`` on failure; the
-   appropriate exception will be set.
-
-
-.. cfunction:: int PyFile_WriteString(const char *s, PyObject *p)
-
-   Write string *s* to file object *p*.  Return ``0`` on success or ``-1`` on
-   failure; the appropriate exception will be set.
-
-
-.. _function-objects:
-
-Function Objects
-----------------
-
-.. index:: object: function
-
-There are a few functions specific to Python functions.
-
-
-.. ctype:: PyFunctionObject
-
-   The C structure used for functions.
-
-
-.. cvar:: PyTypeObject PyFunction_Type
-
-   .. index:: single: MethodType (in module types)
-
-   This is an instance of :ctype:`PyTypeObject` and represents the Python function
-   type.  It is exposed to Python programmers as ``types.FunctionType``.
-
-
-.. cfunction:: int PyFunction_Check(PyObject *o)
-
-   Return true if *o* is a function object (has type :cdata:`PyFunction_Type`).
-   The parameter must not be *NULL*.
-
-
-.. cfunction:: PyObject* PyFunction_New(PyObject *code, PyObject *globals)
-
-   Return a new function object associated with the code object *code*. *globals*
-   must be a dictionary with the global variables accessible to the function.
-
-   The function's docstring, name and *__module__* are retrieved from the code
-   object, the argument defaults and closure are set to *NULL*.
-
-
-.. cfunction:: PyObject* PyFunction_GetCode(PyObject *op)
-
-   Return the code object associated with the function object *op*.
-
-
-.. cfunction:: PyObject* PyFunction_GetGlobals(PyObject *op)
-
-   Return the globals dictionary associated with the function object *op*.
-
-
-.. cfunction:: PyObject* PyFunction_GetModule(PyObject *op)
-
-   Return the *__module__* attribute of the function object *op*. This is normally
-   a string containing the module name, but can be set to any other object by
-   Python code.
-
-
-.. cfunction:: PyObject* PyFunction_GetDefaults(PyObject *op)
-
-   Return the argument default values of the function object *op*. This can be a
-   tuple of arguments or *NULL*.
-
-
-.. cfunction:: int PyFunction_SetDefaults(PyObject *op, PyObject *defaults)
-
-   Set the argument default values for the function object *op*. *defaults* must be
-   *Py_None* or a tuple.
-
-   Raises :exc:`SystemError` and returns ``-1`` on failure.
-
-
-.. cfunction:: PyObject* PyFunction_GetClosure(PyObject *op)
-
-   Return the closure associated with the function object *op*. This can be *NULL*
-   or a tuple of cell objects.
-
-
-.. cfunction:: int PyFunction_SetClosure(PyObject *op, PyObject *closure)
-
-   Set the closure associated with the function object *op*. *closure* must be
-   *Py_None* or a tuple of cell objects.
-
-   Raises :exc:`SystemError` and returns ``-1`` on failure.
-
-
-.. _method-objects:
-
-Method Objects
---------------
-
-.. index:: object: method
-
-There are some useful functions that are useful for working with method objects.
-
-
-.. cvar:: PyTypeObject PyMethod_Type
-
-   .. index:: single: MethodType (in module types)
-
-   This instance of :ctype:`PyTypeObject` represents the Python method type.  This
-   is exposed to Python programs as ``types.MethodType``.
-
-
-.. cfunction:: int PyMethod_Check(PyObject *o)
-
-   Return true if *o* is a method object (has type :cdata:`PyMethod_Type`).  The
-   parameter must not be *NULL*.
-
-
-.. cfunction:: PyObject* PyMethod_New(PyObject *func, PyObject *self, PyObject *class)
-
-   Return a new method object, with *func* being any callable object; this is the
-   function that will be called when the method is called.  If this method should
-   be bound to an instance, *self* should be the instance and *class* should be the
-   class of *self*, otherwise *self* should be *NULL* and *class* should be the
-   class which provides the unbound method..
-
-
-.. cfunction:: PyObject* PyMethod_Class(PyObject *meth)
-
-   Return the class object from which the method *meth* was created; if this was
-   created from an instance, it will be the class of the instance.
-
-
-.. cfunction:: PyObject* PyMethod_GET_CLASS(PyObject *meth)
-
-   Macro version of :cfunc:`PyMethod_Class` which avoids error checking.
-
-
-.. cfunction:: PyObject* PyMethod_Function(PyObject *meth)
-
-   Return the function object associated with the method *meth*.
-
-
-.. cfunction:: PyObject* PyMethod_GET_FUNCTION(PyObject *meth)
-
-   Macro version of :cfunc:`PyMethod_Function` which avoids error checking.
-
-
-.. cfunction:: PyObject* PyMethod_Self(PyObject *meth)
-
-   Return the instance associated with the method *meth* if it is bound, otherwise
-   return *NULL*.
-
-
-.. cfunction:: PyObject* PyMethod_GET_SELF(PyObject *meth)
-
-   Macro version of :cfunc:`PyMethod_Self` which avoids error checking.
-
-
-.. _moduleobjects:
-
-Module Objects
---------------
-
-.. index:: object: module
-
-There are only a few functions special to module objects.
-
-
-.. cvar:: PyTypeObject PyModule_Type
-
-   .. index:: single: ModuleType (in module types)
-
-   This instance of :ctype:`PyTypeObject` represents the Python module type.  This
-   is exposed to Python programs as ``types.ModuleType``.
-
-
-.. cfunction:: int PyModule_Check(PyObject *p)
-
-   Return true if *p* is a module object, or a subtype of a module object.
-
-
-.. cfunction:: int PyModule_CheckExact(PyObject *p)
-
-   Return true if *p* is a module object, but not a subtype of
-   :cdata:`PyModule_Type`.
-
-
-.. cfunction:: PyObject* PyModule_New(const char *name)
-
-   .. index::
-      single: __name__ (module attribute)
-      single: __doc__ (module attribute)
-      single: __file__ (module attribute)
-
-   Return a new module object with the :attr:`__name__` attribute set to *name*.
-   Only the module's :attr:`__doc__` and :attr:`__name__` attributes are filled in;
-   the caller is responsible for providing a :attr:`__file__` attribute.
-
-
-.. cfunction:: PyObject* PyModule_GetDict(PyObject *module)
-
-   .. index:: single: __dict__ (module attribute)
-
-   Return the dictionary object that implements *module*'s namespace; this object
-   is the same as the :attr:`__dict__` attribute of the module object.  This
-   function never fails.  It is recommended extensions use other
-   :cfunc:`PyModule_\*` and :cfunc:`PyObject_\*` functions rather than directly
-   manipulate a module's :attr:`__dict__`.
-
-
-.. cfunction:: char* PyModule_GetName(PyObject *module)
-
-   .. index::
-      single: __name__ (module attribute)
-      single: SystemError (built-in exception)
-
-   Return *module*'s :attr:`__name__` value.  If the module does not provide one,
-   or if it is not a string, :exc:`SystemError` is raised and *NULL* is returned.
-
-
-.. cfunction:: char* PyModule_GetFilename(PyObject *module)
-
-   .. index::
-      single: __file__ (module attribute)
-      single: SystemError (built-in exception)
-
-   Return the name of the file from which *module* was loaded using *module*'s
-   :attr:`__file__` attribute.  If this is not defined, or if it is not a string,
-   raise :exc:`SystemError` and return *NULL*.
-
-
-.. cfunction:: int PyModule_AddObject(PyObject *module, const char *name, PyObject *value)
-
-   Add an object to *module* as *name*.  This is a convenience function which can
-   be used from the module's initialization function.  This steals a reference to
-   *value*.  Return ``-1`` on error, ``0`` on success.
-
-
-.. cfunction:: int PyModule_AddIntConstant(PyObject *module, const char *name, long value)
-
-   Add an integer constant to *module* as *name*.  This convenience function can be
-   used from the module's initialization function. Return ``-1`` on error, ``0`` on
-   success.
-
-
-.. cfunction:: int PyModule_AddStringConstant(PyObject *module, const char *name, const char *value)
-
-   Add a string constant to *module* as *name*.  This convenience function can be
-   used from the module's initialization function.  The string *value* must be
-   null-terminated.  Return ``-1`` on error, ``0`` on success.
-
-
-.. _iterator-objects:
-
-Iterator Objects
-----------------
-
-Python provides two general-purpose iterator objects.  The first, a sequence
-iterator, works with an arbitrary sequence supporting the :meth:`__getitem__`
-method.  The second works with a callable object and a sentinel value, calling
-the callable for each item in the sequence, and ending the iteration when the
-sentinel value is returned.
-
-
-.. cvar:: PyTypeObject PySeqIter_Type
-
-   Type object for iterator objects returned by :cfunc:`PySeqIter_New` and the
-   one-argument form of the :func:`iter` built-in function for built-in sequence
-   types.
-
-
-.. cfunction:: int PySeqIter_Check(op)
-
-   Return true if the type of *op* is :cdata:`PySeqIter_Type`.
-
-
-.. cfunction:: PyObject* PySeqIter_New(PyObject *seq)
-
-   Return an iterator that works with a general sequence object, *seq*.  The
-   iteration ends when the sequence raises :exc:`IndexError` for the subscripting
-   operation.
-
-
-.. cvar:: PyTypeObject PyCallIter_Type
-
-   Type object for iterator objects returned by :cfunc:`PyCallIter_New` and the
-   two-argument form of the :func:`iter` built-in function.
-
-
-.. cfunction:: int PyCallIter_Check(op)
-
-   Return true if the type of *op* is :cdata:`PyCallIter_Type`.
-
-
-.. cfunction:: PyObject* PyCallIter_New(PyObject *callable, PyObject *sentinel)
-
-   Return a new iterator.  The first parameter, *callable*, can be any Python
-   callable object that can be called with no parameters; each call to it should
-   return the next item in the iteration.  When *callable* returns a value equal to
-   *sentinel*, the iteration will be terminated.
-
-
-.. _descriptor-objects:
-
-Descriptor Objects
-------------------
-
-"Descriptors" are objects that describe some attribute of an object. They are
-found in the dictionary of type objects.
-
-.. XXX document these!
-
-.. cvar:: PyTypeObject PyProperty_Type
-
-   The type object for the built-in descriptor types.
-
-
-.. cfunction:: PyObject* PyDescr_NewGetSet(PyTypeObject *type, struct PyGetSetDef *getset)
-
-
-.. cfunction:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *meth)
-
-
-.. cfunction:: PyObject* PyDescr_NewMethod(PyTypeObject *type, struct PyMethodDef *meth)
-
-
-.. cfunction:: PyObject* PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *wrapper, void *wrapped)
-
-
-.. cfunction:: PyObject* PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method)
-
-
-.. cfunction:: int PyDescr_IsData(PyObject *descr)
-
-   Return true if the descriptor objects *descr* describes a data attribute, or
-   false if it describes a method.  *descr* must be a descriptor object; there is
-   no error checking.
-
-
-.. cfunction:: PyObject* PyWrapper_New(PyObject *, PyObject *)
-
-
-.. _slice-objects:
-
-Slice Objects
--------------
-
-
-.. cvar:: PyTypeObject PySlice_Type
-
-   .. index:: single: SliceType (in module types)
-
-   The type object for slice objects.  This is the same as ``slice`` and
-   ``types.SliceType``.
-
-
-.. cfunction:: int PySlice_Check(PyObject *ob)
-
-   Return true if *ob* is a slice object; *ob* must not be *NULL*.
-
-
-.. cfunction:: PyObject* PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
-
-   Return a new slice object with the given values.  The *start*, *stop*, and
-   *step* parameters are used as the values of the slice object attributes of the
-   same names.  Any of the values may be *NULL*, in which case the ``None`` will be
-   used for the corresponding attribute.  Return *NULL* if the new object could not
-   be allocated.
-
-
-.. cfunction:: int PySlice_GetIndices(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)
-
-   Retrieve the start, stop and step indices from the slice object *slice*,
-   assuming a sequence of length *length*. Treats indices greater than *length* as
-   errors.
-
-   Returns 0 on success and -1 on error with no exception set (unless one of the
-   indices was not :const:`None` and failed to be converted to an integer, in which
-   case -1 is returned with an exception set).
-
-   You probably do not want to use this function.  If you want to use slice objects
-   in versions of Python prior to 2.3, you would probably do well to incorporate
-   the source of :cfunc:`PySlice_GetIndicesEx`, suitably renamed, in the source of
-   your extension.
-
-
-.. cfunction:: int PySlice_GetIndicesEx(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength)
-
-   Usable replacement for :cfunc:`PySlice_GetIndices`.  Retrieve the start, stop,
-   and step indices from the slice object *slice* assuming a sequence of length
-   *length*, and store the length of the slice in *slicelength*.  Out of bounds
-   indices are clipped in a manner consistent with the handling of normal slices.
-
-   Returns 0 on success and -1 on error with exception set.
-
-
-.. _weakrefobjects:
-
-Weak Reference Objects
-----------------------
-
-Python supports *weak references* as first-class objects.  There are two
-specific object types which directly implement weak references.  The first is a
-simple reference object, and the second acts as a proxy for the original object
-as much as it can.
-
-
-.. cfunction:: int PyWeakref_Check(ob)
-
-   Return true if *ob* is either a reference or proxy object.
-
-
-.. cfunction:: int PyWeakref_CheckRef(ob)
-
-   Return true if *ob* is a reference object.
-
-
-.. cfunction:: int PyWeakref_CheckProxy(ob)
-
-   Return true if *ob* is a proxy object.
-
-
-.. cfunction:: PyObject* PyWeakref_NewRef(PyObject *ob, PyObject *callback)
-
-   Return a weak reference object for the object *ob*.  This will always return
-   a new reference, but is not guaranteed to create a new object; an existing
-   reference object may be returned.  The second parameter, *callback*, can be a
-   callable object that receives notification when *ob* is garbage collected; it
-   should accept a single parameter, which will be the weak reference object
-   itself. *callback* may also be ``None`` or *NULL*.  If *ob* is not a
-   weakly-referencable object, or if *callback* is not callable, ``None``, or
-   *NULL*, this will return *NULL* and raise :exc:`TypeError`.
-
-
-.. cfunction:: PyObject* PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
-
-   Return a weak reference proxy object for the object *ob*.  This will always
-   return a new reference, but is not guaranteed to create a new object; an
-   existing proxy object may be returned.  The second parameter, *callback*, can
-   be a callable object that receives notification when *ob* is garbage
-   collected; it should accept a single parameter, which will be the weak
-   reference object itself. *callback* may also be ``None`` or *NULL*.  If *ob*
-   is not a weakly-referencable object, or if *callback* is not callable,
-   ``None``, or *NULL*, this will return *NULL* and raise :exc:`TypeError`.
-
-
-.. cfunction:: PyObject* PyWeakref_GetObject(PyObject *ref)
-
-   Return the referenced object from a weak reference, *ref*.  If the referent is
-   no longer live, returns ``None``.
-
-
-.. cfunction:: PyObject* PyWeakref_GET_OBJECT(PyObject *ref)
-
-   Similar to :cfunc:`PyWeakref_GetObject`, but implemented as a macro that does no
-   error checking.
-
-
-.. _cobjects:
-
-CObjects
---------
-
-.. index:: object: CObject
-
-Refer to *Extending and Embedding the Python Interpreter*, section 1.12,
-"Providing a C API for an Extension Module," for more information on using these
-objects.
-
-
-.. ctype:: PyCObject
-
-   This subtype of :ctype:`PyObject` represents an opaque value, useful for C
-   extension modules who need to pass an opaque value (as a :ctype:`void\*`
-   pointer) through Python code to other C code.  It is often used to make a C
-   function pointer defined in one module available to other modules, so the
-   regular import mechanism can be used to access C APIs defined in dynamically
-   loaded modules.
-
-
-.. cfunction:: int PyCObject_Check(PyObject *p)
-
-   Return true if its argument is a :ctype:`PyCObject`.
-
-
-.. cfunction:: PyObject* PyCObject_FromVoidPtr(void* cobj, void (*destr)(void *))
-
-   Create a :ctype:`PyCObject` from the ``void *`` *cobj*.  The *destr* function
-   will be called when the object is reclaimed, unless it is *NULL*.
-
-
-.. cfunction:: PyObject* PyCObject_FromVoidPtrAndDesc(void* cobj, void* desc, void (*destr)(void *, void *))
-
-   Create a :ctype:`PyCObject` from the :ctype:`void \*` *cobj*.  The *destr*
-   function will be called when the object is reclaimed. The *desc* argument can
-   be used to pass extra callback data for the destructor function.
-
-
-.. cfunction:: void* PyCObject_AsVoidPtr(PyObject* self)
-
-   Return the object :ctype:`void \*` that the :ctype:`PyCObject` *self* was
-   created with.
-
-
-.. cfunction:: void* PyCObject_GetDesc(PyObject* self)
-
-   Return the description :ctype:`void \*` that the :ctype:`PyCObject` *self* was
-   created with.
-
-
-.. cfunction:: int PyCObject_SetVoidPtr(PyObject* self, void* cobj)
-
-   Set the void pointer inside *self* to *cobj*. The :ctype:`PyCObject` must not
-   have an associated destructor. Return true on success, false on failure.
-
-
-.. _cell-objects:
-
-Cell Objects
-------------
-
-"Cell" objects are used to implement variables referenced by multiple scopes.
-For each such variable, a cell object is created to store the value; the local
-variables of each stack frame that references the value contains a reference to
-the cells from outer scopes which also use that variable.  When the value is
-accessed, the value contained in the cell is used instead of the cell object
-itself.  This de-referencing of the cell object requires support from the
-generated byte-code; these are not automatically de-referenced when accessed.
-Cell objects are not likely to be useful elsewhere.
-
-
-.. ctype:: PyCellObject
-
-   The C structure used for cell objects.
-
-
-.. cvar:: PyTypeObject PyCell_Type
-
-   The type object corresponding to cell objects.
-
-
-.. cfunction:: int PyCell_Check(ob)
-
-   Return true if *ob* is a cell object; *ob* must not be *NULL*.
-
-
-.. cfunction:: PyObject* PyCell_New(PyObject *ob)
-
-   Create and return a new cell object containing the value *ob*. The parameter may
-   be *NULL*.
-
-
-.. cfunction:: PyObject* PyCell_Get(PyObject *cell)
-
-   Return the contents of the cell *cell*.
-
-
-.. cfunction:: PyObject* PyCell_GET(PyObject *cell)
-
-   Return the contents of the cell *cell*, but without checking that *cell* is
-   non-*NULL* and a cell object.
-
-
-.. cfunction:: int PyCell_Set(PyObject *cell, PyObject *value)
-
-   Set the contents of the cell object *cell* to *value*.  This releases the
-   reference to any current content of the cell. *value* may be *NULL*.  *cell*
-   must be non-*NULL*; if it is not a cell object, ``-1`` will be returned.  On
-   success, ``0`` will be returned.
-
-
-.. cfunction:: void PyCell_SET(PyObject *cell, PyObject *value)
-
-   Sets the value of the cell object *cell* to *value*.  No reference counts are
-   adjusted, and no checks are made for safety; *cell* must be non-*NULL* and must
-   be a cell object.
-
-
-.. _gen-objects:
-
-Generator Objects
------------------
-
-Generator objects are what Python uses to implement generator iterators. They
-are normally created by iterating over a function that yields values, rather
-than explicitly calling :cfunc:`PyGen_New`.
-
-
-.. ctype:: PyGenObject
-
-   The C structure used for generator objects.
-
-
-.. cvar:: PyTypeObject PyGen_Type
-
-   The type object corresponding to generator objects
-
-
-.. cfunction:: int PyGen_Check(ob)
-
-   Return true if *ob* is a generator object; *ob* must not be *NULL*.
-
-
-.. cfunction:: int PyGen_CheckExact(ob)
-
-   Return true if *ob*'s type is *PyGen_Type* is a generator object; *ob* must not
-   be *NULL*.
-
-
-.. cfunction:: PyObject* PyGen_New(PyFrameObject *frame)
-
-   Create and return a new generator object based on the *frame* object. A
-   reference to *frame* is stolen by this function. The parameter must not be
-   *NULL*.
-
-
-.. _datetimeobjects:
-
-DateTime Objects
-----------------
-
-Various date and time objects are supplied by the :mod:`datetime` module.
-Before using any of these functions, the header file :file:`datetime.h` must be
-included in your source (note that this is not included by :file:`Python.h`),
-and the macro :cfunc:`PyDateTime_IMPORT` must be invoked.  The macro puts a
-pointer to a C structure into a static variable,  ``PyDateTimeAPI``, that is
-used by the following macros.
-
-Type-check macros:
-
-.. cfunction:: int PyDate_Check(PyObject *ob)
-
-   Return true if *ob* is of type :cdata:`PyDateTime_DateType` or a subtype of
-   :cdata:`PyDateTime_DateType`.  *ob* must not be *NULL*.
-
-
-.. cfunction:: int PyDate_CheckExact(PyObject *ob)
-
-   Return true if *ob* is of type :cdata:`PyDateTime_DateType`. *ob* must not be
-   *NULL*.
-
-
-.. cfunction:: int PyDateTime_Check(PyObject *ob)
-
-   Return true if *ob* is of type :cdata:`PyDateTime_DateTimeType` or a subtype of
-   :cdata:`PyDateTime_DateTimeType`.  *ob* must not be *NULL*.
-
-
-.. cfunction:: int PyDateTime_CheckExact(PyObject *ob)
-
-   Return true if *ob* is of type :cdata:`PyDateTime_DateTimeType`. *ob* must not
-   be *NULL*.
-
-
-.. cfunction:: int PyTime_Check(PyObject *ob)
-
-   Return true if *ob* is of type :cdata:`PyDateTime_TimeType` or a subtype of
-   :cdata:`PyDateTime_TimeType`.  *ob* must not be *NULL*.
-
-
-.. cfunction:: int PyTime_CheckExact(PyObject *ob)
-
-   Return true if *ob* is of type :cdata:`PyDateTime_TimeType`. *ob* must not be
-   *NULL*.
-
-
-.. cfunction:: int PyDelta_Check(PyObject *ob)
-
-   Return true if *ob* is of type :cdata:`PyDateTime_DeltaType` or a subtype of
-   :cdata:`PyDateTime_DeltaType`.  *ob* must not be *NULL*.
-
-
-.. cfunction:: int PyDelta_CheckExact(PyObject *ob)
-
-   Return true if *ob* is of type :cdata:`PyDateTime_DeltaType`. *ob* must not be
-   *NULL*.
-
-
-.. cfunction:: int PyTZInfo_Check(PyObject *ob)
-
-   Return true if *ob* is of type :cdata:`PyDateTime_TZInfoType` or a subtype of
-   :cdata:`PyDateTime_TZInfoType`.  *ob* must not be *NULL*.
-
-
-.. cfunction:: int PyTZInfo_CheckExact(PyObject *ob)
-
-   Return true if *ob* is of type :cdata:`PyDateTime_TZInfoType`. *ob* must not be
-   *NULL*.
-
-
-Macros to create objects:
-
-.. cfunction:: PyObject* PyDate_FromDate(int year, int month, int day)
-
-   Return a ``datetime.date`` object with the specified year, month and day.
-
-
-.. cfunction:: PyObject* PyDateTime_FromDateAndTime(int year, int month, int day, int hour, int minute, int second, int usecond)
-
-   Return a ``datetime.datetime`` object with the specified year, month, day, hour,
-   minute, second and microsecond.
-
-
-.. cfunction:: PyObject* PyTime_FromTime(int hour, int minute, int second, int usecond)
-
-   Return a ``datetime.time`` object with the specified hour, minute, second and
-   microsecond.
-
-
-.. cfunction:: PyObject* PyDelta_FromDSU(int days, int seconds, int useconds)
-
-   Return a ``datetime.timedelta`` object representing the given number of days,
-   seconds and microseconds.  Normalization is performed so that the resulting
-   number of microseconds and seconds lie in the ranges documented for
-   ``datetime.timedelta`` objects.
-
-
-Macros to extract fields from date objects.  The argument must be an instance of
-:cdata:`PyDateTime_Date`, including subclasses (such as
-:cdata:`PyDateTime_DateTime`).  The argument must not be *NULL*, and the type is
-not checked:
-
-.. cfunction:: int PyDateTime_GET_YEAR(PyDateTime_Date *o)
-
-   Return the year, as a positive int.
-
-
-.. cfunction:: int PyDateTime_GET_MONTH(PyDateTime_Date *o)
-
-   Return the month, as an int from 1 through 12.
-
-
-.. cfunction:: int PyDateTime_GET_DAY(PyDateTime_Date *o)
-
-   Return the day, as an int from 1 through 31.
-
-
-Macros to extract fields from datetime objects.  The argument must be an
-instance of :cdata:`PyDateTime_DateTime`, including subclasses. The argument
-must not be *NULL*, and the type is not checked:
-
-.. cfunction:: int PyDateTime_DATE_GET_HOUR(PyDateTime_DateTime *o)
-
-   Return the hour, as an int from 0 through 23.
-
-
-.. cfunction:: int PyDateTime_DATE_GET_MINUTE(PyDateTime_DateTime *o)
-
-   Return the minute, as an int from 0 through 59.
-
-
-.. cfunction:: int PyDateTime_DATE_GET_SECOND(PyDateTime_DateTime *o)
-
-   Return the second, as an int from 0 through 59.
-
-
-.. cfunction:: int PyDateTime_DATE_GET_MICROSECOND(PyDateTime_DateTime *o)
-
-   Return the microsecond, as an int from 0 through 999999.
-
-
-Macros to extract fields from time objects.  The argument must be an instance of
-:cdata:`PyDateTime_Time`, including subclasses. The argument must not be *NULL*,
-and the type is not checked:
-
-.. cfunction:: int PyDateTime_TIME_GET_HOUR(PyDateTime_Time *o)
-
-   Return the hour, as an int from 0 through 23.
-
-
-.. cfunction:: int PyDateTime_TIME_GET_MINUTE(PyDateTime_Time *o)
-
-   Return the minute, as an int from 0 through 59.
-
-
-.. cfunction:: int PyDateTime_TIME_GET_SECOND(PyDateTime_Time *o)
-
-   Return the second, as an int from 0 through 59.
-
-
-.. cfunction:: int PyDateTime_TIME_GET_MICROSECOND(PyDateTime_Time *o)
-
-   Return the microsecond, as an int from 0 through 999999.
-
-
-Macros for the convenience of modules implementing the DB API:
-
-.. cfunction:: PyObject* PyDateTime_FromTimestamp(PyObject *args)
-
-   Create and return a new ``datetime.datetime`` object given an argument tuple
-   suitable for passing to ``datetime.datetime.fromtimestamp()``.
-
-
-.. cfunction:: PyObject* PyDate_FromTimestamp(PyObject *args)
-
-   Create and return a new ``datetime.date`` object given an argument tuple
-   suitable for passing to ``datetime.date.fromtimestamp()``.
-
-
-.. _setobjects:
-
-Set Objects
------------
-
-.. sectionauthor:: Raymond D. Hettinger <python at rcn.com>
-
-
-.. index::
-   object: set
-   object: frozenset
-
-This section details the public API for :class:`set` and :class:`frozenset`
-objects.  Any functionality not listed below is best accessed using the either
-the abstract object protocol (including :cfunc:`PyObject_CallMethod`,
-:cfunc:`PyObject_RichCompareBool`, :cfunc:`PyObject_Hash`,
-:cfunc:`PyObject_Repr`, :cfunc:`PyObject_IsTrue`, :cfunc:`PyObject_Print`, and
-:cfunc:`PyObject_GetIter`) or the abstract number protocol (including
-:cfunc:`PyNumber_And`, :cfunc:`PyNumber_Subtract`, :cfunc:`PyNumber_Or`,
-:cfunc:`PyNumber_Xor`, :cfunc:`PyNumber_InPlaceAnd`,
-:cfunc:`PyNumber_InPlaceSubtract`, :cfunc:`PyNumber_InPlaceOr`, and
-:cfunc:`PyNumber_InPlaceXor`).
-
-
-.. ctype:: PySetObject
-
-   This subtype of :ctype:`PyObject` is used to hold the internal data for both
-   :class:`set` and :class:`frozenset` objects.  It is like a :ctype:`PyDictObject`
-   in that it is a fixed size for small sets (much like tuple storage) and will
-   point to a separate, variable sized block of memory for medium and large sized
-   sets (much like list storage). None of the fields of this structure should be
-   considered public and are subject to change.  All access should be done through
-   the documented API rather than by manipulating the values in the structure.
-
-
-.. cvar:: PyTypeObject PySet_Type
-
-   This is an instance of :ctype:`PyTypeObject` representing the Python
-   :class:`set` type.
-
-
-.. cvar:: PyTypeObject PyFrozenSet_Type
-
-   This is an instance of :ctype:`PyTypeObject` representing the Python
-   :class:`frozenset` type.
-
-The following type check macros work on pointers to any Python object. Likewise,
-the constructor functions work with any iterable Python object.
-
-
-.. cfunction:: int PyAnySet_Check(PyObject *p)
-
-   Return true if *p* is a :class:`set` object, a :class:`frozenset` object, or an
-   instance of a subtype.
-
-
-.. cfunction:: int PyAnySet_CheckExact(PyObject *p)
-
-   Return true if *p* is a :class:`set` object or a :class:`frozenset` object but
-   not an instance of a subtype.
-
-
-.. cfunction:: int PyFrozenSet_CheckExact(PyObject *p)
-
-   Return true if *p* is a :class:`frozenset` object but not an instance of a
-   subtype.
-
-
-.. cfunction:: PyObject* PySet_New(PyObject *iterable)
-
-   Return a new :class:`set` containing objects returned by the *iterable*.  The
-   *iterable* may be *NULL* to create a new empty set.  Return the new set on
-   success or *NULL* on failure.  Raise :exc:`TypeError` if *iterable* is not
-   actually iterable.  The constructor is also useful for copying a set
-   (``c=set(s)``).
-
-
-.. cfunction:: PyObject* PyFrozenSet_New(PyObject *iterable)
-
-   Return a new :class:`frozenset` containing objects returned by the *iterable*.
-   The *iterable* may be *NULL* to create a new empty frozenset.  Return the new
-   set on success or *NULL* on failure.  Raise :exc:`TypeError` if *iterable* is
-   not actually iterable.
-
-The following functions and macros are available for instances of :class:`set`
-or :class:`frozenset` or instances of their subtypes.
-
-
-.. cfunction:: Py_ssize_t PySet_Size(PyObject *anyset)
-
-   .. index:: builtin: len
-
-   Return the length of a :class:`set` or :class:`frozenset` object. Equivalent to
-   ``len(anyset)``.  Raises a :exc:`PyExc_SystemError` if *anyset* is not a
-   :class:`set`, :class:`frozenset`, or an instance of a subtype.
-
-
-.. cfunction:: Py_ssize_t PySet_GET_SIZE(PyObject *anyset)
-
-   Macro form of :cfunc:`PySet_Size` without error checking.
-
-
-.. cfunction:: int PySet_Contains(PyObject *anyset, PyObject *key)
-
-   Return 1 if found, 0 if not found, and -1 if an error is encountered.  Unlike
-   the Python :meth:`__contains__` method, this function does not automatically
-   convert unhashable sets into temporary frozensets.  Raise a :exc:`TypeError` if
-   the *key* is unhashable. Raise :exc:`PyExc_SystemError` if *anyset* is not a
-   :class:`set`, :class:`frozenset`, or an instance of a subtype.
-
-The following functions are available for instances of :class:`set` or its
-subtypes but not for instances of :class:`frozenset` or its subtypes.
-
-
-.. cfunction:: int PySet_Add(PyObject *set, PyObject *key)
-
-   Add *key* to a :class:`set` instance.  Does not apply to :class:`frozenset`
-   instances.  Return 0 on success or -1 on failure. Raise a :exc:`TypeError` if
-   the *key* is unhashable. Raise a :exc:`MemoryError` if there is no room to grow.
-   Raise a :exc:`SystemError` if *set* is an not an instance of :class:`set` or its
-   subtype.
-
-
-.. cfunction:: int PySet_Discard(PyObject *set, PyObject *key)
-
-   Return 1 if found and removed, 0 if not found (no action taken), and -1 if an
-   error is encountered.  Does not raise :exc:`KeyError` for missing keys.  Raise a
-   :exc:`TypeError` if the *key* is unhashable.  Unlike the Python :meth:`discard`
-   method, this function does not automatically convert unhashable sets into
-   temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is an not an
-   instance of :class:`set` or its subtype.
-
-
-.. cfunction:: PyObject* PySet_Pop(PyObject *set)
-
-   Return a new reference to an arbitrary object in the *set*, and removes the
-   object from the *set*.  Return *NULL* on failure.  Raise :exc:`KeyError` if the
-   set is empty. Raise a :exc:`SystemError` if *set* is an not an instance of
-   :class:`set` or its subtype.
-
-
-.. cfunction:: int PySet_Clear(PyObject *set)
-
-   Empty an existing set of all elements.
+.. toctree::
 
+   set.rst
+   function.rst
+   method.rst
+   file.rst
+   module.rst
+   iterator.rst
+   descriptor.rst
+   slice.rst
+   weakref.rst
+   cobject.rst
+   cell.rst
+   gen.rst
+   datetime.rst

Modified: python/branches/py3k-importlib/Doc/c-api/exceptions.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/c-api/exceptions.rst	(original)
+++ python/branches/py3k-importlib/Doc/c-api/exceptions.rst	Thu Mar 27 00:48:05 2008
@@ -31,8 +31,8 @@
 of ``sys.exc_info()``.  API functions exist to interact with the error indicator
 in various ways.  There is a separate error indicator for each thread.
 
-.. % XXX Order of these should be more thoughtful.
-.. % Either alphabetical or some kind of structure.
+.. XXX Order of these should be more thoughtful.
+   Either alphabetical or some kind of structure.
 
 
 .. cfunction:: void PyErr_Print()
@@ -355,6 +355,16 @@
    .. % thread.interrupt_main() (used from IDLE), so it's still needed.
 
 
+.. cfunction:: int PySignal_SetWakeupFd(int fd)
+
+   This utility function specifies a file descriptor to which a ``'\0'`` byte will
+   be written whenever a signal is received.  It returns the previous such file
+   descriptor.  The value ``-1`` disables the feature; this is the initial state.
+   This is equivalent to :func:`signal.set_wakeup_fd` in Python, but without any
+   error checking.  *fd* should be a valid file descriptor.  The function should
+   only be called from the main thread.
+
+
 .. cfunction:: PyObject* PyErr_NewException(char *name, PyObject *base, PyObject *dict)
 
    This utility function creates and returns a new exception object. The *name*

Modified: python/branches/py3k-importlib/Doc/c-api/index.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/c-api/index.rst	(original)
+++ python/branches/py3k-importlib/Doc/c-api/index.rst	Thu Mar 27 00:48:05 2008
@@ -12,12 +12,6 @@
 which describes the general principles of extension writing but does not
 document the API functions in detail.
 
-.. warning::
-
-   The current version of this document is somewhat incomplete. However, most of
-   the important functions, types and structures are described.
-
-
 .. toctree::
    :maxdepth: 2
 
@@ -30,4 +24,4 @@
    concrete.rst
    init.rst
    memory.rst
-   newtypes.rst
+   objimpl.rst

Modified: python/branches/py3k-importlib/Doc/c-api/init.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/c-api/init.rst	(original)
+++ python/branches/py3k-importlib/Doc/c-api/init.rst	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
       single: PyEval_AcquireLock()
       single: modules (in module sys)
       single: path (in module sys)
-      module: __builtin__
+      module: builtins
       module: __main__
       module: sys
       triple: module; search; path
@@ -29,7 +29,7 @@
    exception of :cfunc:`Py_SetProgramName`, :cfunc:`PyEval_InitThreads`,
    :cfunc:`PyEval_ReleaseLock`, and :cfunc:`PyEval_AcquireLock`. This initializes
    the table of loaded modules (``sys.modules``), and creates the fundamental
-   modules :mod:`__builtin__`, :mod:`__main__` and :mod:`sys`.  It also initializes
+   modules :mod:`builtins`, :mod:`__main__` and :mod:`sys`.  It also initializes
    the module search path (``sys.path``). It does not set ``sys.argv``; use
    :cfunc:`PySys_SetArgv` for that.  This is a no-op when called for a second time
    (without calling :cfunc:`Py_Finalize` first).  There is no return value; it is a
@@ -83,7 +83,7 @@
 .. cfunction:: PyThreadState* Py_NewInterpreter()
 
    .. index::
-      module: __builtin__
+      module: builtins
       module: __main__
       module: sys
       single: stdout (in module sys)
@@ -93,7 +93,7 @@
    Create a new sub-interpreter.  This is an (almost) totally separate environment
    for the execution of Python code.  In particular, the new interpreter has
    separate, independent versions of all imported modules, including the
-   fundamental modules :mod:`__builtin__`, :mod:`__main__` and :mod:`sys`.  The
+   fundamental modules :mod:`builtins`, :mod:`__main__` and :mod:`sys`.  The
    table of loaded modules (``sys.modules``) and the module search path
    (``sys.path``) are also separate.  The new environment has no ``sys.argv``
    variable.  It has new standard I/O stream file objects ``sys.stdin``,
@@ -264,7 +264,7 @@
    as the list ``sys.path``, which may be modified to change the future search path
    for loaded modules.
 
-   .. % XXX should give the exact rules
+   .. XXX should give the exact rules
 
 
 .. cfunction:: const char* Py_GetVersion()
@@ -357,10 +357,8 @@
    to initialize ``sys.argv``, a fatal condition is signalled using
    :cfunc:`Py_FatalError`.
 
-   .. % XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
-   .. % check w/ Guido.
-
-.. % XXX Other PySys thingies (doesn't really belong in this chapter)
+   .. XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
+      check w/ Guido.
 
 
 .. _threads:
@@ -615,6 +613,14 @@
    deadlock ensues.  (This function is available even when thread support is
    disabled at compile time.)
 
+
+.. cfunction:: void PyEval_ReInitThreads()
+
+   This function is called from :cfunc:`PyOS_AfterFork` to ensure that newly
+   created child processes don't hold locks referring to threads which
+   are not running in the child process.
+
+
 The following macros are normally used without a trailing semicolon; look for
 example usage in the Python source distribution.
 
@@ -876,6 +882,46 @@
    :cfunc:`PyEval_SetProfile`, except the tracing function does receive line-number
    events.
 
+.. cfunction:: PyObject* PyEval_GetCallStats(PyObject *self)
+
+   Return a tuple of function call counts.  There are constants defined for the
+   positions within the tuple:
+   
+   +-------------------------------+-------+
+   | Name                          | Value |
+   +===============================+=======+
+   | :const:`PCALL_ALL`            | 0     |
+   +-------------------------------+-------+
+   | :const:`PCALL_FUNCTION`       | 1     |
+   +-------------------------------+-------+
+   | :const:`PCALL_FAST_FUNCTION`  | 2     |
+   +-------------------------------+-------+
+   | :const:`PCALL_FASTER_FUNCTION`| 3     |
+   +-------------------------------+-------+
+   | :const:`PCALL_METHOD`         | 4     |
+   +-------------------------------+-------+
+   | :const:`PCALL_BOUND_METHOD`   | 5     |
+   +-------------------------------+-------+
+   | :const:`PCALL_CFUNCTION`      | 6     |
+   +-------------------------------+-------+
+   | :const:`PCALL_TYPE`           | 7     |
+   +-------------------------------+-------+
+   | :const:`PCALL_GENERATOR`      | 8     |
+   +-------------------------------+-------+
+   | :const:`PCALL_OTHER`          | 9     |
+   +-------------------------------+-------+
+   | :const:`PCALL_POP`            | 10    |
+   +-------------------------------+-------+
+   
+   :const:`PCALL_FAST_FUNCTION` means no argument tuple needs to be created.
+   :const:`PCALL_FASTER_FUNCTION` means that the fast-path frame setup code is used.
+
+   If there is a method call where the call can be optimized by changing
+   the argument tuple and calling the function directly, it gets recorded
+   twice.
+
+   This function is only present if Python is compiled with :const:`CALL_PROFILE`
+   defined.
 
 .. _advanced-debugging:
 

Modified: python/branches/py3k-importlib/Doc/c-api/intro.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/c-api/intro.rst	(original)
+++ python/branches/py3k-importlib/Doc/c-api/intro.rst	Thu Mar 27 00:48:05 2008
@@ -137,7 +137,7 @@
 object type, such as a list, as well as performing any additional finalization
 that's needed.  There's no chance that the reference count can overflow; at
 least as many bits are used to hold the reference count as there are distinct
-memory locations in virtual memory (assuming ``sizeof(long) >= sizeof(char*)``).
+memory locations in virtual memory (assuming ``sizeof(Py_ssize_t) >= sizeof(void*)``).
 Thus, the reference count increment is a simple operation.
 
 It is not necessary to increment an object's reference count for every  local
@@ -208,11 +208,11 @@
    PyObject *t;
 
    t = PyTuple_New(3);
-   PyTuple_SetItem(t, 0, PyInt_FromLong(1L));
-   PyTuple_SetItem(t, 1, PyInt_FromLong(2L));
+   PyTuple_SetItem(t, 0, PyLong_FromLong(1L));
+   PyTuple_SetItem(t, 1, PyLong_FromLong(2L));
    PyTuple_SetItem(t, 2, PyString_FromString("three"));
 
-Here, :cfunc:`PyInt_FromLong` returns a new reference which is immediately
+Here, :cfunc:`PyLong_FromLong` returns a new reference which is immediately
 stolen by :cfunc:`PyTuple_SetItem`.  When you want to keep using an object
 although the reference to it will be stolen, use :cfunc:`Py_INCREF` to grab
 another reference before calling the reference-stealing function.
@@ -252,7 +252,7 @@
        if (n < 0)
            return -1;
        for (i = 0; i < n; i++) {
-           PyObject *index = PyInt_FromLong(i);
+           PyObject *index = PyLong_FromLong(i);
            if (!index)
                return -1;
            if (PyObject_SetItem(target, index, item) < 0)
@@ -301,8 +301,8 @@
            return -1; /* Not a list */
        for (i = 0; i < n; i++) {
            item = PyList_GetItem(list, i); /* Can't fail */
-           if (!PyInt_Check(item)) continue; /* Skip non-integers */
-           total += PyInt_AsLong(item);
+           if (!PyLong_Check(item)) continue; /* Skip non-integers */
+           total += PyLong_AsLong(item);
        }
        return total;
    }
@@ -324,8 +324,8 @@
            item = PySequence_GetItem(sequence, i);
            if (item == NULL)
                return -1; /* Not a sequence, or other failure */
-           if (PyInt_Check(item))
-               total += PyInt_AsLong(item);
+           if (PyLong_Check(item))
+               total += PyLong_AsLong(item);
            Py_DECREF(item); /* Discard reference ownership */
        }
        return total;
@@ -449,11 +449,11 @@
 
            /* Clear the error and use zero: */
            PyErr_Clear();
-           item = PyInt_FromLong(0L);
+           item = PyLong_FromLong(0L);
            if (item == NULL)
                goto error;
        }
-       const_one = PyInt_FromLong(1L);
+       const_one = PyLong_FromLong(1L);
        if (const_one == NULL)
            goto error;
 
@@ -484,7 +484,7 @@
    single: PyErr_Clear()
    single: Py_XDECREF()
 
-This example represents an endorsed use of the :keyword:`goto` statement  in C!
+This example represents an endorsed use of the ``goto`` statement  in C!
 It illustrates the use of :cfunc:`PyErr_ExceptionMatches` and
 :cfunc:`PyErr_Clear` to handle specific exceptions, and the use of
 :cfunc:`Py_XDECREF` to dispose of owned references that may be *NULL* (note the
@@ -507,7 +507,7 @@
 
 .. index::
    single: Py_Initialize()
-   module: __builtin__
+   module: builtins
    module: __main__
    module: sys
    module: exceptions
@@ -516,7 +516,7 @@
 
 The basic initialization function is :cfunc:`Py_Initialize`. This initializes
 the table of loaded modules, and creates the fundamental modules
-:mod:`__builtin__`, :mod:`__main__`, :mod:`sys`, and :mod:`exceptions`.  It also
+:mod:`builtins`, :mod:`__main__`, :mod:`sys`, and :mod:`exceptions`.  It also
 initializes the module search path (``sys.path``).
 
 .. index:: single: PySys_SetArgv()

Deleted: /python/branches/py3k-importlib/Doc/c-api/newtypes.rst
==============================================================================
--- /python/branches/py3k-importlib/Doc/c-api/newtypes.rst	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,1856 +0,0 @@
-.. highlightlang:: c
-
-
-.. _newtypes:
-
-*****************************
-Object Implementation Support
-*****************************
-
-This chapter describes the functions, types, and macros used when defining new
-object types.
-
-
-.. _allocating-objects:
-
-Allocating Objects on the Heap
-==============================
-
-
-.. cfunction:: PyObject* _PyObject_New(PyTypeObject *type)
-
-
-.. cfunction:: PyVarObject* _PyObject_NewVar(PyTypeObject *type, Py_ssize_t size)
-
-
-.. cfunction:: PyObject* PyObject_Init(PyObject *op, PyTypeObject *type)
-
-   Initialize a newly-allocated object *op* with its type and initial reference.
-   Returns the initialized object.  If *type* indicates that the object
-   participates in the cyclic garbage detector, it is added to the detector's set
-   of observed objects. Other fields of the object are not affected.
-
-
-.. cfunction:: PyVarObject* PyObject_InitVar(PyVarObject *op, PyTypeObject *type, Py_ssize_t size)
-
-   This does everything :cfunc:`PyObject_Init` does, and also initializes the
-   length information for a variable-size object.
-
-
-.. cfunction:: TYPE* PyObject_New(TYPE, PyTypeObject *type)
-
-   Allocate a new Python object using the C structure type *TYPE* and the Python
-   type object *type*.  Fields not defined by the Python object header are not
-   initialized; the object's reference count will be one.  The size of the memory
-   allocation is determined from the :attr:`tp_basicsize` field of the type object.
-
-
-.. cfunction:: TYPE* PyObject_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size)
-
-   Allocate a new Python object using the C structure type *TYPE* and the Python
-   type object *type*.  Fields not defined by the Python object header are not
-   initialized.  The allocated memory allows for the *TYPE* structure plus *size*
-   fields of the size given by the :attr:`tp_itemsize` field of *type*.  This is
-   useful for implementing objects like tuples, which are able to determine their
-   size at construction time.  Embedding the array of fields into the same
-   allocation decreases the number of allocations, improving the memory management
-   efficiency.
-
-
-.. cfunction:: void PyObject_Del(PyObject *op)
-
-   Releases memory allocated to an object using :cfunc:`PyObject_New` or
-   :cfunc:`PyObject_NewVar`.  This is normally called from the :attr:`tp_dealloc`
-   handler specified in the object's type.  The fields of the object should not be
-   accessed after this call as the memory is no longer a valid Python object.
-
-
-.. cfunction:: PyObject* Py_InitModule(char *name, PyMethodDef *methods)
-
-   Create a new module object based on a name and table of functions, returning
-   the new module object; the *methods* argument can be *NULL* if no methods are
-   to be defined for the module.
-
-
-.. cfunction:: PyObject* Py_InitModule3(char *name, PyMethodDef *methods, char *doc)
-
-   Create a new module object based on a name and table of functions, returning
-   the new module object.  The *methods* argument can be *NULL* if no methods
-   are to be defined for the module.  If *doc* is non-*NULL*, it will be used to
-   define the docstring for the module.
-
-
-.. cfunction:: PyObject* Py_InitModule4(char *name, PyMethodDef *methods, char *doc, PyObject *self, int apiver)
-
-   Create a new module object based on a name and table of functions, returning
-   the new module object.  The *methods* argument can be *NULL* if no methods
-   are to be defined for the module.  If *doc* is non-*NULL*, it will be used to
-   define the docstring for the module.  If *self* is non-*NULL*, it will passed
-   to the functions of the module as their (otherwise *NULL*) first parameter.
-   (This was added as an experimental feature, and there are no known uses in
-   the current version of Python.)  For *apiver*, the only value which should be
-   passed is defined by the constant :const:`PYTHON_API_VERSION`.
-
-   .. note::
-
-      Most uses of this function should probably be using the :cfunc:`Py_InitModule3`
-      instead; only use this if you are sure you need it.
-
-
-.. cvar:: PyObject _Py_NoneStruct
-
-   Object which is visible in Python as ``None``.  This should only be accessed
-   using the :cmacro:`Py_None` macro, which evaluates to a pointer to this
-   object.
-
-
-.. _common-structs:
-
-Common Object Structures
-========================
-
-There are a large number of structures which are used in the definition of
-object types for Python.  This section describes these structures and how they
-are used.
-
-All Python objects ultimately share a small number of fields at the beginning of
-the object's representation in memory.  These are represented by the
-:ctype:`PyObject` and :ctype:`PyVarObject` types, which are defined, in turn, by
-the expansions of some macros also used, whether directly or indirectly, in the
-definition of all other Python objects.
-
-
-.. ctype:: PyObject
-
-   All object types are extensions of this type.  This is a type which contains the
-   information Python needs to treat a pointer to an object as an object.  In a
-   normal "release" build, it contains only the objects reference count and a
-   pointer to the corresponding type object.  It corresponds to the fields defined
-   by the expansion of the ``PyObject_HEAD`` macro.
-
-
-.. ctype:: PyVarObject
-
-   This is an extension of :ctype:`PyObject` that adds the :attr:`ob_size` field.
-   This is only used for objects that have some notion of *length*.  This type does
-   not often appear in the Python/C API.  It corresponds to the fields defined by
-   the expansion of the ``PyObject_VAR_HEAD`` macro.
-
-These macros are used in the definition of :ctype:`PyObject` and
-:ctype:`PyVarObject`:
-
-.. XXX need to document PEP 3123 changes here
-
-.. cmacro:: PyObject_HEAD
-
-   This is a macro which expands to the declarations of the fields of the
-   :ctype:`PyObject` type; it is used when declaring new types which represent
-   objects without a varying length.  The specific fields it expands to depend on
-   the definition of :cmacro:`Py_TRACE_REFS`.  By default, that macro is not
-   defined, and :cmacro:`PyObject_HEAD` expands to::
-
-      Py_ssize_t ob_refcnt;
-      PyTypeObject *ob_type;
-
-   When :cmacro:`Py_TRACE_REFS` is defined, it expands to::
-
-      PyObject *_ob_next, *_ob_prev;
-      Py_ssize_t ob_refcnt;
-      PyTypeObject *ob_type;
-
-
-.. cmacro:: PyObject_VAR_HEAD
-
-   This is a macro which expands to the declarations of the fields of the
-   :ctype:`PyVarObject` type; it is used when declaring new types which represent
-   objects with a length that varies from instance to instance.  This macro always
-   expands to::
-
-      PyObject_HEAD
-      Py_ssize_t ob_size;
-
-   Note that :cmacro:`PyObject_HEAD` is part of the expansion, and that its own
-   expansion varies depending on the definition of :cmacro:`Py_TRACE_REFS`.
-
-.. cmacro:: PyObject_HEAD_INIT
-
-
-.. ctype:: PyCFunction
-
-   Type of the functions used to implement most Python callables in C. Functions of
-   this type take two :ctype:`PyObject\*` parameters and return one such value.  If
-   the return value is *NULL*, an exception shall have been set.  If not *NULL*,
-   the return value is interpreted as the return value of the function as exposed
-   in Python.  The function must return a new reference.
-
-
-.. ctype:: PyCFunctionWithKeywords
-
-   Type of the functions used to implement Python callables in C that take
-   keyword arguments: they take three :ctype:`PyObject\*` parameters and return
-   one such value.  See :ctype:`PyCFunction` above for the meaning of the return
-   value.
-
-
-.. ctype:: PyMethodDef
-
-   Structure used to describe a method of an extension type.  This structure has
-   four fields:
-
-   +------------------+-------------+-------------------------------+
-   | Field            | C Type      | Meaning                       |
-   +==================+=============+===============================+
-   | :attr:`ml_name`  | char \*     | name of the method            |
-   +------------------+-------------+-------------------------------+
-   | :attr:`ml_meth`  | PyCFunction | pointer to the C              |
-   |                  |             | implementation                |
-   +------------------+-------------+-------------------------------+
-   | :attr:`ml_flags` | int         | flag bits indicating how the  |
-   |                  |             | call should be constructed    |
-   +------------------+-------------+-------------------------------+
-   | :attr:`ml_doc`   | char \*     | points to the contents of the |
-   |                  |             | docstring                     |
-   +------------------+-------------+-------------------------------+
-
-The :attr:`ml_meth` is a C function pointer.  The functions may be of different
-types, but they always return :ctype:`PyObject\*`.  If the function is not of
-the :ctype:`PyCFunction`, the compiler will require a cast in the method table.
-Even though :ctype:`PyCFunction` defines the first parameter as
-:ctype:`PyObject\*`, it is common that the method implementation uses a the
-specific C type of the *self* object.
-
-The :attr:`ml_flags` field is a bitfield which can include the following flags.
-The individual flags indicate either a calling convention or a binding
-convention.  Of the calling convention flags, only :const:`METH_VARARGS` and
-:const:`METH_KEYWORDS` can be combined (but note that :const:`METH_KEYWORDS`
-alone is equivalent to ``METH_VARARGS | METH_KEYWORDS``). Any of the calling
-convention flags can be combined with a binding flag.
-
-
-.. data:: METH_VARARGS
-
-   This is the typical calling convention, where the methods have the type
-   :ctype:`PyCFunction`. The function expects two :ctype:`PyObject\*` values.  The
-   first one is the *self* object for methods; for module functions, it has the
-   value given to :cfunc:`Py_InitModule4` (or *NULL* if :cfunc:`Py_InitModule` was
-   used).  The second parameter (often called *args*) is a tuple object
-   representing all arguments. This parameter is typically processed using
-   :cfunc:`PyArg_ParseTuple` or :cfunc:`PyArg_UnpackTuple`.
-
-
-.. data:: METH_KEYWORDS
-
-   Methods with these flags must be of type :ctype:`PyCFunctionWithKeywords`.  The
-   function expects three parameters: *self*, *args*, and a dictionary of all the
-   keyword arguments.  The flag is typically combined with :const:`METH_VARARGS`,
-   and the parameters are typically processed using
-   :cfunc:`PyArg_ParseTupleAndKeywords`.
-
-
-.. data:: METH_NOARGS
-
-   Methods without parameters don't need to check whether arguments are given if
-   they are listed with the :const:`METH_NOARGS` flag.  They need to be of type
-   :ctype:`PyCFunction`.  When used with object methods, the first parameter is
-   typically named ``self`` and will hold a reference to the object instance.  In
-   all cases the second parameter will be *NULL*.
-
-
-.. data:: METH_O
-
-   Methods with a single object argument can be listed with the :const:`METH_O`
-   flag, instead of invoking :cfunc:`PyArg_ParseTuple` with a ``"O"`` argument.
-   They have the type :ctype:`PyCFunction`, with the *self* parameter, and a
-   :ctype:`PyObject\*` parameter representing the single argument.
-
-
-These two constants are not used to indicate the calling convention but the
-binding when use with methods of classes.  These may not be used for functions
-defined for modules.  At most one of these flags may be set for any given
-method.
-
-
-.. data:: METH_CLASS
-
-   .. index:: builtin: classmethod
-
-   The method will be passed the type object as the first parameter rather than an
-   instance of the type.  This is used to create *class methods*, similar to what
-   is created when using the :func:`classmethod` built-in function.
-
-
-.. data:: METH_STATIC
-
-   .. index:: builtin: staticmethod
-
-   The method will be passed *NULL* as the first parameter rather than an instance
-   of the type.  This is used to create *static methods*, similar to what is
-   created when using the :func:`staticmethod` built-in function.
-
-One other constant controls whether a method is loaded in place of another
-definition with the same method name.
-
-
-.. data:: METH_COEXIST
-
-   The method will be loaded in place of existing definitions.  Without
-   *METH_COEXIST*, the default is to skip repeated definitions.  Since slot
-   wrappers are loaded before the method table, the existence of a *sq_contains*
-   slot, for example, would generate a wrapped method named :meth:`__contains__`
-   and preclude the loading of a corresponding PyCFunction with the same name.
-   With the flag defined, the PyCFunction will be loaded in place of the wrapper
-   object and will co-exist with the slot.  This is helpful because calls to
-   PyCFunctions are optimized more than wrapper object calls.
-
-
-.. cfunction:: PyObject* Py_FindMethod(PyMethodDef table[], PyObject *ob, char *name)
-
-   Return a bound method object for an extension type implemented in C.  This can
-   be useful in the implementation of a :attr:`tp_getattro` or :attr:`tp_getattr`
-   handler that does not use the :cfunc:`PyObject_GenericGetAttr` function.
-
-
-.. _type-structs:
-
-Type Objects
-============
-
-Perhaps one of the most important structures of the Python object system is the
-structure that defines a new type: the :ctype:`PyTypeObject` structure.  Type
-objects can be handled using any of the :cfunc:`PyObject_\*` or
-:cfunc:`PyType_\*` functions, but do not offer much that's interesting to most
-Python applications. These objects are fundamental to how objects behave, so
-they are very important to the interpreter itself and to any extension module
-that implements new types.
-
-Type objects are fairly large compared to most of the standard types. The reason
-for the size is that each type object stores a large number of values, mostly C
-function pointers, each of which implements a small part of the type's
-functionality.  The fields of the type object are examined in detail in this
-section.  The fields will be described in the order in which they occur in the
-structure.
-
-Typedefs: unaryfunc, binaryfunc, ternaryfunc, inquiry, intargfunc,
-intintargfunc, intobjargproc, intintobjargproc, objobjargproc, destructor,
-freefunc, printfunc, getattrfunc, getattrofunc, setattrfunc, setattrofunc,
-cmpfunc, reprfunc, hashfunc
-
-The structure definition for :ctype:`PyTypeObject` can be found in
-:file:`Include/object.h`.  For convenience of reference, this repeats the
-definition found there:
-
-.. literalinclude:: ../includes/typestruct.h
-
-
-The type object structure extends the :ctype:`PyVarObject` structure. The
-:attr:`ob_size` field is used for dynamic types (created by  :func:`type_new`,
-usually called from a class statement). Note that :cdata:`PyType_Type` (the
-metatype) initializes :attr:`tp_itemsize`, which means that its instances (i.e.
-type objects) *must* have the :attr:`ob_size` field.
-
-
-.. cmember:: PyObject* PyObject._ob_next
-             PyObject* PyObject._ob_prev
-
-   These fields are only present when the macro ``Py_TRACE_REFS`` is defined.
-   Their initialization to *NULL* is taken care of by the ``PyObject_HEAD_INIT``
-   macro.  For statically allocated objects, these fields always remain *NULL*.
-   For dynamically allocated objects, these two fields are used to link the object
-   into a doubly-linked list of *all* live objects on the heap.  This could be used
-   for various debugging purposes; currently the only use is to print the objects
-   that are still alive at the end of a run when the environment variable
-   :envvar:`PYTHONDUMPREFS` is set.
-
-   These fields are not inherited by subtypes.
-
-
-.. cmember:: Py_ssize_t PyObject.ob_refcnt
-
-   This is the type object's reference count, initialized to ``1`` by the
-   ``PyObject_HEAD_INIT`` macro.  Note that for statically allocated type objects,
-   the type's instances (objects whose :attr:`ob_type` points back to the type) do
-   *not* count as references.  But for dynamically allocated type objects, the
-   instances *do* count as references.
-
-   This field is not inherited by subtypes.
-
-
-.. cmember:: PyTypeObject* PyObject.ob_type
-
-   This is the type's type, in other words its metatype.  It is initialized by the
-   argument to the ``PyObject_HEAD_INIT`` macro, and its value should normally be
-   ``&PyType_Type``.  However, for dynamically loadable extension modules that must
-   be usable on Windows (at least), the compiler complains that this is not a valid
-   initializer.  Therefore, the convention is to pass *NULL* to the
-   ``PyObject_HEAD_INIT`` macro and to initialize this field explicitly at the
-   start of the module's initialization function, before doing anything else.  This
-   is typically done like this::
-
-      Foo_Type.ob_type = &PyType_Type;
-
-   This should be done before any instances of the type are created.
-   :cfunc:`PyType_Ready` checks if :attr:`ob_type` is *NULL*, and if so,
-   initializes it: in Python 2.2, it is set to ``&PyType_Type``; in Python 2.2.1
-   and later it is initialized to the :attr:`ob_type` field of the base class.
-   :cfunc:`PyType_Ready` will not change this field if it is non-zero.
-
-   In Python 2.2, this field is not inherited by subtypes.  In 2.2.1, and in 2.3
-   and beyond, it is inherited by subtypes.
-
-
-.. cmember:: Py_ssize_t PyVarObject.ob_size
-
-   For statically allocated type objects, this should be initialized to zero.  For
-   dynamically allocated type objects, this field has a special internal meaning.
-
-   This field is not inherited by subtypes.
-
-
-.. cmember:: char* PyTypeObject.tp_name
-
-   Pointer to a NUL-terminated string containing the name of the type. For types
-   that are accessible as module globals, the string should be the full module
-   name, followed by a dot, followed by the type name; for built-in types, it
-   should be just the type name.  If the module is a submodule of a package, the
-   full package name is part of the full module name.  For example, a type named
-   :class:`T` defined in module :mod:`M` in subpackage :mod:`Q` in package :mod:`P`
-   should have the :attr:`tp_name` initializer ``"P.Q.M.T"``.
-
-   For dynamically allocated type objects, this should just be the type name, and
-   the module name explicitly stored in the type dict as the value for key
-   ``'__module__'``.
-
-   For statically allocated type objects, the tp_name field should contain a dot.
-   Everything before the last dot is made accessible as the :attr:`__module__`
-   attribute, and everything after the last dot is made accessible as the
-   :attr:`__name__` attribute.
-
-   If no dot is present, the entire :attr:`tp_name` field is made accessible as the
-   :attr:`__name__` attribute, and the :attr:`__module__` attribute is undefined
-   (unless explicitly set in the dictionary, as explained above).  This means your
-   type will be impossible to pickle.
-
-   This field is not inherited by subtypes.
-
-
-.. cmember:: Py_ssize_t PyTypeObject.tp_basicsize
-             Py_ssize_t PyTypeObject.tp_itemsize
-
-   These fields allow calculating the size in bytes of instances of the type.
-
-   There are two kinds of types: types with fixed-length instances have a zero
-   :attr:`tp_itemsize` field, types with variable-length instances have a non-zero
-   :attr:`tp_itemsize` field.  For a type with fixed-length instances, all
-   instances have the same size, given in :attr:`tp_basicsize`.
-
-   For a type with variable-length instances, the instances must have an
-   :attr:`ob_size` field, and the instance size is :attr:`tp_basicsize` plus N
-   times :attr:`tp_itemsize`, where N is the "length" of the object.  The value of
-   N is typically stored in the instance's :attr:`ob_size` field.  There are
-   exceptions:  for example, long ints use a negative :attr:`ob_size` to indicate a
-   negative number, and N is ``abs(ob_size)`` there.  Also, the presence of an
-   :attr:`ob_size` field in the instance layout doesn't mean that the instance
-   structure is variable-length (for example, the structure for the list type has
-   fixed-length instances, yet those instances have a meaningful :attr:`ob_size`
-   field).
-
-   The basic size includes the fields in the instance declared by the macro
-   :cmacro:`PyObject_HEAD` or :cmacro:`PyObject_VAR_HEAD` (whichever is used to
-   declare the instance struct) and this in turn includes the :attr:`_ob_prev` and
-   :attr:`_ob_next` fields if they are present.  This means that the only correct
-   way to get an initializer for the :attr:`tp_basicsize` is to use the
-   :keyword:`sizeof` operator on the struct used to declare the instance layout.
-   The basic size does not include the GC header size (this is new in Python 2.2;
-   in 2.1 and 2.0, the GC header size was included in :attr:`tp_basicsize`).
-
-   These fields are inherited separately by subtypes.  If the base type has a
-   non-zero :attr:`tp_itemsize`, it is generally not safe to set
-   :attr:`tp_itemsize` to a different non-zero value in a subtype (though this
-   depends on the implementation of the base type).
-
-   A note about alignment: if the variable items require a particular alignment,
-   this should be taken care of by the value of :attr:`tp_basicsize`.  Example:
-   suppose a type implements an array of ``double``. :attr:`tp_itemsize` is
-   ``sizeof(double)``. It is the programmer's responsibility that
-   :attr:`tp_basicsize` is a multiple of ``sizeof(double)`` (assuming this is the
-   alignment requirement for ``double``).
-
-
-.. cmember:: destructor PyTypeObject.tp_dealloc
-
-   A pointer to the instance destructor function.  This function must be defined
-   unless the type guarantees that its instances will never be deallocated (as is
-   the case for the singletons ``None`` and ``Ellipsis``).
-
-   The destructor function is called by the :cfunc:`Py_DECREF` and
-   :cfunc:`Py_XDECREF` macros when the new reference count is zero.  At this point,
-   the instance is still in existence, but there are no references to it.  The
-   destructor function should free all references which the instance owns, free all
-   memory buffers owned by the instance (using the freeing function corresponding
-   to the allocation function used to allocate the buffer), and finally (as its
-   last action) call the type's :attr:`tp_free` function.  If the type is not
-   subtypable (doesn't have the :const:`Py_TPFLAGS_BASETYPE` flag bit set), it is
-   permissible to call the object deallocator directly instead of via
-   :attr:`tp_free`.  The object deallocator should be the one used to allocate the
-   instance; this is normally :cfunc:`PyObject_Del` if the instance was allocated
-   using :cfunc:`PyObject_New` or :cfunc:`PyObject_VarNew`, or
-   :cfunc:`PyObject_GC_Del` if the instance was allocated using
-   :cfunc:`PyObject_GC_New` or :cfunc:`PyObject_GC_VarNew`.
-
-   This field is inherited by subtypes.
-
-
-.. cmember:: printfunc PyTypeObject.tp_print
-
-   An optional pointer to the instance print function.
-
-   The print function is only called when the instance is printed to a *real* file;
-   when it is printed to a pseudo-file (like a :class:`StringIO` instance), the
-   instance's :attr:`tp_repr` or :attr:`tp_str` function is called to convert it to
-   a string.  These are also called when the type's :attr:`tp_print` field is
-   *NULL*.  A type should never implement :attr:`tp_print` in a way that produces
-   different output than :attr:`tp_repr` or :attr:`tp_str` would.
-
-   The print function is called with the same signature as :cfunc:`PyObject_Print`:
-   ``int tp_print(PyObject *self, FILE *file, int flags)``.  The *self* argument is
-   the instance to be printed.  The *file* argument is the stdio file to which it
-   is to be printed.  The *flags* argument is composed of flag bits. The only flag
-   bit currently defined is :const:`Py_PRINT_RAW`. When the :const:`Py_PRINT_RAW`
-   flag bit is set, the instance should be printed the same way as :attr:`tp_str`
-   would format it; when the :const:`Py_PRINT_RAW` flag bit is clear, the instance
-   should be printed the same was as :attr:`tp_repr` would format it. It should
-   return ``-1`` and set an exception condition when an error occurred during the
-   comparison.
-
-   It is possible that the :attr:`tp_print` field will be deprecated. In any case,
-   it is recommended not to define :attr:`tp_print`, but instead to rely on
-   :attr:`tp_repr` and :attr:`tp_str` for printing.
-
-   This field is inherited by subtypes.
-
-
-.. cmember:: getattrfunc PyTypeObject.tp_getattr
-
-   An optional pointer to the get-attribute-string function.
-
-   This field is deprecated.  When it is defined, it should point to a function
-   that acts the same as the :attr:`tp_getattro` function, but taking a C string
-   instead of a Python string object to give the attribute name.  The signature is
-   the same as for :cfunc:`PyObject_GetAttrString`.
-
-   This field is inherited by subtypes together with :attr:`tp_getattro`: a subtype
-   inherits both :attr:`tp_getattr` and :attr:`tp_getattro` from its base type when
-   the subtype's :attr:`tp_getattr` and :attr:`tp_getattro` are both *NULL*.
-
-
-.. cmember:: setattrfunc PyTypeObject.tp_setattr
-
-   An optional pointer to the set-attribute-string function.
-
-   This field is deprecated.  When it is defined, it should point to a function
-   that acts the same as the :attr:`tp_setattro` function, but taking a C string
-   instead of a Python string object to give the attribute name.  The signature is
-   the same as for :cfunc:`PyObject_SetAttrString`.
-
-   This field is inherited by subtypes together with :attr:`tp_setattro`: a subtype
-   inherits both :attr:`tp_setattr` and :attr:`tp_setattro` from its base type when
-   the subtype's :attr:`tp_setattr` and :attr:`tp_setattro` are both *NULL*.
-
-
-.. cmember:: cmpfunc PyTypeObject.tp_compare
-
-   An optional pointer to the three-way comparison function.
-
-   The signature is the same as for :cfunc:`PyObject_Compare`. The function should
-   return ``1`` if *self* greater than *other*, ``0`` if *self* is equal to
-   *other*, and ``-1`` if *self* less than *other*.  It should return ``-1`` and
-   set an exception condition when an error occurred during the comparison.
-
-   This field is inherited by subtypes together with :attr:`tp_richcompare` and
-   :attr:`tp_hash`: a subtypes inherits all three of :attr:`tp_compare`,
-   :attr:`tp_richcompare`, and :attr:`tp_hash` when the subtype's
-   :attr:`tp_compare`, :attr:`tp_richcompare`, and :attr:`tp_hash` are all *NULL*.
-
-
-.. cmember:: reprfunc PyTypeObject.tp_repr
-
-   .. index:: builtin: repr
-
-   An optional pointer to a function that implements the built-in function
-   :func:`repr`.
-
-   The signature is the same as for :cfunc:`PyObject_Repr`; it must return a string
-   or a Unicode object.  Ideally, this function should return a string that, when
-   passed to :func:`eval`, given a suitable environment, returns an object with the
-   same value.  If this is not feasible, it should return a string starting with
-   ``'<'`` and ending with ``'>'`` from which both the type and the value of the
-   object can be deduced.
-
-   When this field is not set, a string of the form ``<%s object at %p>`` is
-   returned, where ``%s`` is replaced by the type name, and ``%p`` by the object's
-   memory address.
-
-   This field is inherited by subtypes.
-
-.. cmember:: PyNumberMethods* tp_as_number
-
-   Pointer to an additional structure that contains fields relevant only to
-   objects which implement the number protocol.  These fields are documented in
-   :ref:`number-structs`.
-
-   The :attr:`tp_as_number` field is not inherited, but the contained fields are
-   inherited individually.
-
-
-.. cmember:: PySequenceMethods* tp_as_sequence
-
-   Pointer to an additional structure that contains fields relevant only to
-   objects which implement the sequence protocol.  These fields are documented
-   in :ref:`sequence-structs`.
-
-   The :attr:`tp_as_sequence` field is not inherited, but the contained fields
-   are inherited individually.
-
-
-.. cmember:: PyMappingMethods* tp_as_mapping
-
-   Pointer to an additional structure that contains fields relevant only to
-   objects which implement the mapping protocol.  These fields are documented in
-   :ref:`mapping-structs`.
-
-   The :attr:`tp_as_mapping` field is not inherited, but the contained fields are
-   inherited individually.
-
-
-.. cmember:: hashfunc PyTypeObject.tp_hash
-
-   .. index:: builtin: hash
-
-   An optional pointer to a function that implements the built-in function
-   :func:`hash`.
-
-   The signature is the same as for :cfunc:`PyObject_Hash`; it must return a C
-   long.  The value ``-1`` should not be returned as a normal return value; when an
-   error occurs during the computation of the hash value, the function should set
-   an exception and return ``-1``.
-
-   When this field is not set, two possibilities exist: if the :attr:`tp_compare`
-   and :attr:`tp_richcompare` fields are both *NULL*, a default hash value based on
-   the object's address is returned; otherwise, a :exc:`TypeError` is raised.
-
-   This field is inherited by subtypes together with :attr:`tp_richcompare` and
-   :attr:`tp_compare`: a subtypes inherits all three of :attr:`tp_compare`,
-   :attr:`tp_richcompare`, and :attr:`tp_hash`, when the subtype's
-   :attr:`tp_compare`, :attr:`tp_richcompare` and :attr:`tp_hash` are all *NULL*.
-
-
-.. cmember:: ternaryfunc PyTypeObject.tp_call
-
-   An optional pointer to a function that implements calling the object.  This
-   should be *NULL* if the object is not callable.  The signature is the same as
-   for :cfunc:`PyObject_Call`.
-
-   This field is inherited by subtypes.
-
-
-.. cmember:: reprfunc PyTypeObject.tp_str
-
-   An optional pointer to a function that implements the built-in operation
-   :func:`str`.  (Note that :class:`str` is a type now, and :func:`str` calls the
-   constructor for that type.  This constructor calls :cfunc:`PyObject_Str` to do
-   the actual work, and :cfunc:`PyObject_Str` will call this handler.)
-
-   The signature is the same as for :cfunc:`PyObject_Str`; it must return a string
-   or a Unicode object.  This function should return a "friendly" string
-   representation of the object, as this is the representation that will be used,
-   among other things, by the :func:`print` function.
-
-   When this field is not set, :cfunc:`PyObject_Repr` is called to return a string
-   representation.
-
-   This field is inherited by subtypes.
-
-
-.. cmember:: getattrofunc PyTypeObject.tp_getattro
-
-   An optional pointer to the get-attribute function.
-
-   The signature is the same as for :cfunc:`PyObject_GetAttr`.  It is usually
-   convenient to set this field to :cfunc:`PyObject_GenericGetAttr`, which
-   implements the normal way of looking for object attributes.
-
-   This field is inherited by subtypes together with :attr:`tp_getattr`: a subtype
-   inherits both :attr:`tp_getattr` and :attr:`tp_getattro` from its base type when
-   the subtype's :attr:`tp_getattr` and :attr:`tp_getattro` are both *NULL*.
-
-
-.. cmember:: setattrofunc PyTypeObject.tp_setattro
-
-   An optional pointer to the set-attribute function.
-
-   The signature is the same as for :cfunc:`PyObject_SetAttr`.  It is usually
-   convenient to set this field to :cfunc:`PyObject_GenericSetAttr`, which
-   implements the normal way of setting object attributes.
-
-   This field is inherited by subtypes together with :attr:`tp_setattr`: a subtype
-   inherits both :attr:`tp_setattr` and :attr:`tp_setattro` from its base type when
-   the subtype's :attr:`tp_setattr` and :attr:`tp_setattro` are both *NULL*.
-
-
-.. cmember:: PyBufferProcs* PyTypeObject.tp_as_buffer
-
-   Pointer to an additional structure that contains fields relevant only to objects
-   which implement the buffer interface.  These fields are documented in
-   :ref:`buffer-structs`.
-
-   The :attr:`tp_as_buffer` field is not inherited, but the contained fields are
-   inherited individually.
-
-
-.. cmember:: long PyTypeObject.tp_flags
-
-   This field is a bit mask of various flags.  Some flags indicate variant
-   semantics for certain situations; others are used to indicate that certain
-   fields in the type object (or in the extension structures referenced via
-   :attr:`tp_as_number`, :attr:`tp_as_sequence`, :attr:`tp_as_mapping`, and
-   :attr:`tp_as_buffer`) that were historically not always present are valid; if
-   such a flag bit is clear, the type fields it guards must not be accessed and
-   must be considered to have a zero or *NULL* value instead.
-
-   Inheritance of this field is complicated.  Most flag bits are inherited
-   individually, i.e. if the base type has a flag bit set, the subtype inherits
-   this flag bit.  The flag bits that pertain to extension structures are strictly
-   inherited if the extension structure is inherited, i.e. the base type's value of
-   the flag bit is copied into the subtype together with a pointer to the extension
-   structure.  The :const:`Py_TPFLAGS_HAVE_GC` flag bit is inherited together with
-   the :attr:`tp_traverse` and :attr:`tp_clear` fields, i.e. if the
-   :const:`Py_TPFLAGS_HAVE_GC` flag bit is clear in the subtype and the
-   :attr:`tp_traverse` and :attr:`tp_clear` fields in the subtype exist (as
-   indicated by the :const:`Py_TPFLAGS_HAVE_RICHCOMPARE` flag bit) and have *NULL*
-   values.
-
-   The following bit masks are currently defined; these can be or-ed together using
-   the ``|`` operator to form the value of the :attr:`tp_flags` field.  The macro
-   :cfunc:`PyType_HasFeature` takes a type and a flags value, *tp* and *f*, and
-   checks whether ``tp->tp_flags & f`` is non-zero.
-
-
-   .. data:: Py_TPFLAGS_HAVE_GETCHARBUFFER
-
-      If this bit is set, the :ctype:`PyBufferProcs` struct referenced by
-      :attr:`tp_as_buffer` has the :attr:`bf_getcharbuffer` field.
-
-
-   .. data:: Py_TPFLAGS_HAVE_SEQUENCE_IN
-
-      If this bit is set, the :ctype:`PySequenceMethods` struct referenced by
-      :attr:`tp_as_sequence` has the :attr:`sq_contains` field.
-
-
-   .. data:: Py_TPFLAGS_GC
-
-      This bit is obsolete.  The bit it used to name is no longer in use.  The symbol
-      is now defined as zero.
-
-
-   .. data:: Py_TPFLAGS_HAVE_INPLACEOPS
-
-      If this bit is set, the :ctype:`PySequenceMethods` struct referenced by
-      :attr:`tp_as_sequence` and the :ctype:`PyNumberMethods` structure referenced by
-      :attr:`tp_as_number` contain the fields for in-place operators. In particular,
-      this means that the :ctype:`PyNumberMethods` structure has the fields
-      :attr:`nb_inplace_add`, :attr:`nb_inplace_subtract`,
-      :attr:`nb_inplace_multiply`, :attr:`nb_inplace_divide`,
-      :attr:`nb_inplace_remainder`, :attr:`nb_inplace_power`,
-      :attr:`nb_inplace_lshift`, :attr:`nb_inplace_rshift`, :attr:`nb_inplace_and`,
-      :attr:`nb_inplace_xor`, and :attr:`nb_inplace_or`; and the
-      :ctype:`PySequenceMethods` struct has the fields :attr:`sq_inplace_concat` and
-      :attr:`sq_inplace_repeat`.
-
-
-   .. data:: Py_TPFLAGS_HAVE_RICHCOMPARE
-
-      If this bit is set, the type object has the :attr:`tp_richcompare` field, as
-      well as the :attr:`tp_traverse` and the :attr:`tp_clear` fields.
-
-
-   .. data:: Py_TPFLAGS_HAVE_WEAKREFS
-
-      If this bit is set, the :attr:`tp_weaklistoffset` field is defined.  Instances
-      of a type are weakly referenceable if the type's :attr:`tp_weaklistoffset` field
-      has a value greater than zero.
-
-
-   .. data:: Py_TPFLAGS_HAVE_ITER
-
-      If this bit is set, the type object has the :attr:`tp_iter` and
-      :attr:`tp_iternext` fields.
-
-
-   .. data:: Py_TPFLAGS_HAVE_CLASS
-
-      If this bit is set, the type object has several new fields defined starting in
-      Python 2.2: :attr:`tp_methods`, :attr:`tp_members`, :attr:`tp_getset`,
-      :attr:`tp_base`, :attr:`tp_dict`, :attr:`tp_descr_get`, :attr:`tp_descr_set`,
-      :attr:`tp_dictoffset`, :attr:`tp_init`, :attr:`tp_alloc`, :attr:`tp_new`,
-      :attr:`tp_free`, :attr:`tp_is_gc`, :attr:`tp_bases`, :attr:`tp_mro`,
-      :attr:`tp_cache`, :attr:`tp_subclasses`, and :attr:`tp_weaklist`.
-
-
-   .. data:: Py_TPFLAGS_HEAPTYPE
-
-      This bit is set when the type object itself is allocated on the heap.  In this
-      case, the :attr:`ob_type` field of its instances is considered a reference to
-      the type, and the type object is INCREF'ed when a new instance is created, and
-      DECREF'ed when an instance is destroyed (this does not apply to instances of
-      subtypes; only the type referenced by the instance's ob_type gets INCREF'ed or
-      DECREF'ed).
-
-
-   .. data:: Py_TPFLAGS_BASETYPE
-
-      This bit is set when the type can be used as the base type of another type.  If
-      this bit is clear, the type cannot be subtyped (similar to a "final" class in
-      Java).
-
-
-   .. data:: Py_TPFLAGS_READY
-
-      This bit is set when the type object has been fully initialized by
-      :cfunc:`PyType_Ready`.
-
-
-   .. data:: Py_TPFLAGS_READYING
-
-      This bit is set while :cfunc:`PyType_Ready` is in the process of initializing
-      the type object.
-
-
-   .. data:: Py_TPFLAGS_HAVE_GC
-
-      This bit is set when the object supports garbage collection.  If this bit
-      is set, instances must be created using :cfunc:`PyObject_GC_New` and
-      destroyed using :cfunc:`PyObject_GC_Del`.  More information in section
-      :ref:`supporting-cycle-detection`.  This bit also implies that the
-      GC-related fields :attr:`tp_traverse` and :attr:`tp_clear` are present in
-      the type object; but those fields also exist when
-      :const:`Py_TPFLAGS_HAVE_GC` is clear but
-      :const:`Py_TPFLAGS_HAVE_RICHCOMPARE` is set.
-
-
-   .. data:: Py_TPFLAGS_DEFAULT
-
-      This is a bitmask of all the bits that pertain to the existence of certain
-      fields in the type object and its extension structures. Currently, it includes
-      the following bits: :const:`Py_TPFLAGS_HAVE_GETCHARBUFFER`,
-      :const:`Py_TPFLAGS_HAVE_SEQUENCE_IN`, :const:`Py_TPFLAGS_HAVE_INPLACEOPS`,
-      :const:`Py_TPFLAGS_HAVE_RICHCOMPARE`, :const:`Py_TPFLAGS_HAVE_WEAKREFS`,
-      :const:`Py_TPFLAGS_HAVE_ITER`, and :const:`Py_TPFLAGS_HAVE_CLASS`.
-
-
-.. cmember:: char* PyTypeObject.tp_doc
-
-   An optional pointer to a NUL-terminated C string giving the docstring for this
-   type object.  This is exposed as the :attr:`__doc__` attribute on the type and
-   instances of the type.
-
-   This field is *not* inherited by subtypes.
-
-The following three fields only exist if the
-:const:`Py_TPFLAGS_HAVE_RICHCOMPARE` flag bit is set.
-
-
-.. cmember:: traverseproc PyTypeObject.tp_traverse
-
-   An optional pointer to a traversal function for the garbage collector.  This is
-   only used if the :const:`Py_TPFLAGS_HAVE_GC` flag bit is set.  More information
-   about Python's garbage collection scheme can be found in section
-   :ref:`supporting-cycle-detection`.
-
-   The :attr:`tp_traverse` pointer is used by the garbage collector to detect
-   reference cycles. A typical implementation of a :attr:`tp_traverse` function
-   simply calls :cfunc:`Py_VISIT` on each of the instance's members that are Python
-   objects.  For exampe, this is function :cfunc:`local_traverse` from the
-   :mod:`thread` extension module::
-
-      static int
-      local_traverse(localobject *self, visitproc visit, void *arg)
-      {
-          Py_VISIT(self->args);
-          Py_VISIT(self->kw);
-          Py_VISIT(self->dict);
-          return 0;
-      }
-
-   Note that :cfunc:`Py_VISIT` is called only on those members that can participate
-   in reference cycles.  Although there is also a ``self->key`` member, it can only
-   be *NULL* or a Python string and therefore cannot be part of a reference cycle.
-
-   On the other hand, even if you know a member can never be part of a cycle, as a
-   debugging aid you may want to visit it anyway just so the :mod:`gc` module's
-   :func:`get_referents` function will include it.
-
-   Note that :cfunc:`Py_VISIT` requires the *visit* and *arg* parameters to
-   :cfunc:`local_traverse` to have these specific names; don't name them just
-   anything.
-
-   This field is inherited by subtypes together with :attr:`tp_clear` and the
-   :const:`Py_TPFLAGS_HAVE_GC` flag bit: the flag bit, :attr:`tp_traverse`, and
-   :attr:`tp_clear` are all inherited from the base type if they are all zero in
-   the subtype *and* the subtype has the :const:`Py_TPFLAGS_HAVE_RICHCOMPARE` flag
-   bit set.
-
-
-.. cmember:: inquiry PyTypeObject.tp_clear
-
-   An optional pointer to a clear function for the garbage collector. This is only
-   used if the :const:`Py_TPFLAGS_HAVE_GC` flag bit is set.
-
-   The :attr:`tp_clear` member function is used to break reference cycles in cyclic
-   garbage detected by the garbage collector.  Taken together, all :attr:`tp_clear`
-   functions in the system must combine to break all reference cycles.  This is
-   subtle, and if in any doubt supply a :attr:`tp_clear` function.  For example,
-   the tuple type does not implement a :attr:`tp_clear` function, because it's
-   possible to prove that no reference cycle can be composed entirely of tuples.
-   Therefore the :attr:`tp_clear` functions of other types must be sufficient to
-   break any cycle containing a tuple.  This isn't immediately obvious, and there's
-   rarely a good reason to avoid implementing :attr:`tp_clear`.
-
-   Implementations of :attr:`tp_clear` should drop the instance's references to
-   those of its members that may be Python objects, and set its pointers to those
-   members to *NULL*, as in the following example::
-
-      static int
-      local_clear(localobject *self)
-      {
-          Py_CLEAR(self->key);
-          Py_CLEAR(self->args);
-          Py_CLEAR(self->kw);
-          Py_CLEAR(self->dict);
-          return 0;
-      }
-
-   The :cfunc:`Py_CLEAR` macro should be used, because clearing references is
-   delicate:  the reference to the contained object must not be decremented until
-   after the pointer to the contained object is set to *NULL*.  This is because
-   decrementing the reference count may cause the contained object to become trash,
-   triggering a chain of reclamation activity that may include invoking arbitrary
-   Python code (due to finalizers, or weakref callbacks, associated with the
-   contained object). If it's possible for such code to reference *self* again,
-   it's important that the pointer to the contained object be *NULL* at that time,
-   so that *self* knows the contained object can no longer be used.  The
-   :cfunc:`Py_CLEAR` macro performs the operations in a safe order.
-
-   Because the goal of :attr:`tp_clear` functions is to break reference cycles,
-   it's not necessary to clear contained objects like Python strings or Python
-   integers, which can't participate in reference cycles. On the other hand, it may
-   be convenient to clear all contained Python objects, and write the type's
-   :attr:`tp_dealloc` function to invoke :attr:`tp_clear`.
-
-   More information about Python's garbage collection scheme can be found in
-   section :ref:`supporting-cycle-detection`.
-
-   This field is inherited by subtypes together with :attr:`tp_traverse` and the
-   :const:`Py_TPFLAGS_HAVE_GC` flag bit: the flag bit, :attr:`tp_traverse`, and
-   :attr:`tp_clear` are all inherited from the base type if they are all zero in
-   the subtype *and* the subtype has the :const:`Py_TPFLAGS_HAVE_RICHCOMPARE` flag
-   bit set.
-
-
-.. cmember:: richcmpfunc PyTypeObject.tp_richcompare
-
-   An optional pointer to the rich comparison function.
-
-   The signature is the same as for :cfunc:`PyObject_RichCompare`. The function
-   should return the result of the comparison (usually ``Py_True`` or
-   ``Py_False``).  If the comparison is undefined, it must return
-   ``Py_NotImplemented``, if another error occurred it must return ``NULL`` and set
-   an exception condition.
-
-   This field is inherited by subtypes together with :attr:`tp_compare` and
-   :attr:`tp_hash`: a subtype inherits all three of :attr:`tp_compare`,
-   :attr:`tp_richcompare`, and :attr:`tp_hash`, when the subtype's
-   :attr:`tp_compare`, :attr:`tp_richcompare`, and :attr:`tp_hash` are all *NULL*.
-
-   The following constants are defined to be used as the third argument for
-   :attr:`tp_richcompare` and for :cfunc:`PyObject_RichCompare`:
-
-   +----------------+------------+
-   | Constant       | Comparison |
-   +================+============+
-   | :const:`Py_LT` | ``<``      |
-   +----------------+------------+
-   | :const:`Py_LE` | ``<=``     |
-   +----------------+------------+
-   | :const:`Py_EQ` | ``==``     |
-   +----------------+------------+
-   | :const:`Py_NE` | ``!=``     |
-   +----------------+------------+
-   | :const:`Py_GT` | ``>``      |
-   +----------------+------------+
-   | :const:`Py_GE` | ``>=``     |
-   +----------------+------------+
-
-The next field only exists if the :const:`Py_TPFLAGS_HAVE_WEAKREFS` flag bit is
-set.
-
-
-.. cmember:: long PyTypeObject.tp_weaklistoffset
-
-   If the instances of this type are weakly referenceable, this field is greater
-   than zero and contains the offset in the instance structure of the weak
-   reference list head (ignoring the GC header, if present); this offset is used by
-   :cfunc:`PyObject_ClearWeakRefs` and the :cfunc:`PyWeakref_\*` functions.  The
-   instance structure needs to include a field of type :ctype:`PyObject\*` which is
-   initialized to *NULL*.
-
-   Do not confuse this field with :attr:`tp_weaklist`; that is the list head for
-   weak references to the type object itself.
-
-   This field is inherited by subtypes, but see the rules listed below. A subtype
-   may override this offset; this means that the subtype uses a different weak
-   reference list head than the base type.  Since the list head is always found via
-   :attr:`tp_weaklistoffset`, this should not be a problem.
-
-   When a type defined by a class statement has no :attr:`__slots__` declaration,
-   and none of its base types are weakly referenceable, the type is made weakly
-   referenceable by adding a weak reference list head slot to the instance layout
-   and setting the :attr:`tp_weaklistoffset` of that slot's offset.
-
-   When a type's :attr:`__slots__` declaration contains a slot named
-   :attr:`__weakref__`, that slot becomes the weak reference list head for
-   instances of the type, and the slot's offset is stored in the type's
-   :attr:`tp_weaklistoffset`.
-
-   When a type's :attr:`__slots__` declaration does not contain a slot named
-   :attr:`__weakref__`, the type inherits its :attr:`tp_weaklistoffset` from its
-   base type.
-
-The next two fields only exist if the :const:`Py_TPFLAGS_HAVE_CLASS` flag bit is
-set.
-
-
-.. cmember:: getiterfunc PyTypeObject.tp_iter
-
-   An optional pointer to a function that returns an iterator for the object.  Its
-   presence normally signals that the instances of this type are iterable (although
-   sequences may be iterable without this function, and classic instances always
-   have this function, even if they don't define an :meth:`__iter__` method).
-
-   This function has the same signature as :cfunc:`PyObject_GetIter`.
-
-   This field is inherited by subtypes.
-
-
-.. cmember:: iternextfunc PyTypeObject.tp_iternext
-
-   An optional pointer to a function that returns the next item in an iterator, or
-   raises :exc:`StopIteration` when the iterator is exhausted.  Its presence
-   normally signals that the instances of this type are iterators (although classic
-   instances always have this function, even if they don't define a
-   :meth:`__next__` method).
-
-   Iterator types should also define the :attr:`tp_iter` function, and that
-   function should return the iterator instance itself (not a new iterator
-   instance).
-
-   This function has the same signature as :cfunc:`PyIter_Next`.
-
-   This field is inherited by subtypes.
-
-The next fields, up to and including :attr:`tp_weaklist`, only exist if the
-:const:`Py_TPFLAGS_HAVE_CLASS` flag bit is set.
-
-
-.. cmember:: struct PyMethodDef* PyTypeObject.tp_methods
-
-   An optional pointer to a static *NULL*-terminated array of :ctype:`PyMethodDef`
-   structures, declaring regular methods of this type.
-
-   For each entry in the array, an entry is added to the type's dictionary (see
-   :attr:`tp_dict` below) containing a method descriptor.
-
-   This field is not inherited by subtypes (methods are inherited through a
-   different mechanism).
-
-
-.. cmember:: struct PyMemberDef* PyTypeObject.tp_members
-
-   An optional pointer to a static *NULL*-terminated array of :ctype:`PyMemberDef`
-   structures, declaring regular data members (fields or slots) of instances of
-   this type.
-
-   For each entry in the array, an entry is added to the type's dictionary (see
-   :attr:`tp_dict` below) containing a member descriptor.
-
-   This field is not inherited by subtypes (members are inherited through a
-   different mechanism).
-
-
-.. cmember:: struct PyGetSetDef* PyTypeObject.tp_getset
-
-   An optional pointer to a static *NULL*-terminated array of :ctype:`PyGetSetDef`
-   structures, declaring computed attributes of instances of this type.
-
-   For each entry in the array, an entry is added to the type's dictionary (see
-   :attr:`tp_dict` below) containing a getset descriptor.
-
-   This field is not inherited by subtypes (computed attributes are inherited
-   through a different mechanism).
-
-   Docs for PyGetSetDef (XXX belong elsewhere)::
-
-      typedef PyObject *(*getter)(PyObject *, void *);
-      typedef int (*setter)(PyObject *, PyObject *, void *);
-
-      typedef struct PyGetSetDef {
-          char *name;    /* attribute name */
-          getter get;    /* C function to get the attribute */
-          setter set;    /* C function to set the attribute */
-          char *doc;     /* optional doc string */
-          void *closure; /* optional additional data for getter and setter */
-      } PyGetSetDef;
-
-
-.. cmember:: PyTypeObject* PyTypeObject.tp_base
-
-   An optional pointer to a base type from which type properties are inherited.  At
-   this level, only single inheritance is supported; multiple inheritance require
-   dynamically creating a type object by calling the metatype.
-
-   This field is not inherited by subtypes (obviously), but it defaults to
-   ``&PyBaseObject_Type`` (which to Python programmers is known as the type
-   :class:`object`).
-
-
-.. cmember:: PyObject* PyTypeObject.tp_dict
-
-   The type's dictionary is stored here by :cfunc:`PyType_Ready`.
-
-   This field should normally be initialized to *NULL* before PyType_Ready is
-   called; it may also be initialized to a dictionary containing initial attributes
-   for the type.  Once :cfunc:`PyType_Ready` has initialized the type, extra
-   attributes for the type may be added to this dictionary only if they don't
-   correspond to overloaded operations (like :meth:`__add__`).
-
-   This field is not inherited by subtypes (though the attributes defined in here
-   are inherited through a different mechanism).
-
-
-.. cmember:: descrgetfunc PyTypeObject.tp_descr_get
-
-   An optional pointer to a "descriptor get" function.
-
-   The function signature is ::
-
-      PyObject * tp_descr_get(PyObject *self, PyObject *obj, PyObject *type);
-
-   XXX more
-
-   This field is inherited by subtypes.
-
-
-.. cmember:: descrsetfunc PyTypeObject.tp_descr_set
-
-   An optional pointer to a "descriptor set" function.
-
-   The function signature is ::
-
-      int tp_descr_set(PyObject *self, PyObject *obj, PyObject *value);
-
-   This field is inherited by subtypes.
-
-   XXX more
-
-
-.. cmember:: long PyTypeObject.tp_dictoffset
-
-   If the instances of this type have a dictionary containing instance variables,
-   this field is non-zero and contains the offset in the instances of the type of
-   the instance variable dictionary; this offset is used by
-   :cfunc:`PyObject_GenericGetAttr`.
-
-   Do not confuse this field with :attr:`tp_dict`; that is the dictionary for
-   attributes of the type object itself.
-
-   If the value of this field is greater than zero, it specifies the offset from
-   the start of the instance structure.  If the value is less than zero, it
-   specifies the offset from the *end* of the instance structure.  A negative
-   offset is more expensive to use, and should only be used when the instance
-   structure contains a variable-length part.  This is used for example to add an
-   instance variable dictionary to subtypes of :class:`str` or :class:`tuple`. Note
-   that the :attr:`tp_basicsize` field should account for the dictionary added to
-   the end in that case, even though the dictionary is not included in the basic
-   object layout.  On a system with a pointer size of 4 bytes,
-   :attr:`tp_dictoffset` should be set to ``-4`` to indicate that the dictionary is
-   at the very end of the structure.
-
-   The real dictionary offset in an instance can be computed from a negative
-   :attr:`tp_dictoffset` as follows::
-
-      dictoffset = tp_basicsize + abs(ob_size)*tp_itemsize + tp_dictoffset
-      if dictoffset is not aligned on sizeof(void*):
-          round up to sizeof(void*)
-
-   where :attr:`tp_basicsize`, :attr:`tp_itemsize` and :attr:`tp_dictoffset` are
-   taken from the type object, and :attr:`ob_size` is taken from the instance.  The
-   absolute value is taken because long ints use the sign of :attr:`ob_size` to
-   store the sign of the number.  (There's never a need to do this calculation
-   yourself; it is done for you by :cfunc:`_PyObject_GetDictPtr`.)
-
-   This field is inherited by subtypes, but see the rules listed below. A subtype
-   may override this offset; this means that the subtype instances store the
-   dictionary at a difference offset than the base type.  Since the dictionary is
-   always found via :attr:`tp_dictoffset`, this should not be a problem.
-
-   When a type defined by a class statement has no :attr:`__slots__` declaration,
-   and none of its base types has an instance variable dictionary, a dictionary
-   slot is added to the instance layout and the :attr:`tp_dictoffset` is set to
-   that slot's offset.
-
-   When a type defined by a class statement has a :attr:`__slots__` declaration,
-   the type inherits its :attr:`tp_dictoffset` from its base type.
-
-   (Adding a slot named :attr:`__dict__` to the :attr:`__slots__` declaration does
-   not have the expected effect, it just causes confusion.  Maybe this should be
-   added as a feature just like :attr:`__weakref__` though.)
-
-
-.. cmember:: initproc PyTypeObject.tp_init
-
-   An optional pointer to an instance initialization function.
-
-   This function corresponds to the :meth:`__init__` method of classes.  Like
-   :meth:`__init__`, it is possible to create an instance without calling
-   :meth:`__init__`, and it is possible to reinitialize an instance by calling its
-   :meth:`__init__` method again.
-
-   The function signature is ::
-
-      int tp_init(PyObject *self, PyObject *args, PyObject *kwds)
-
-   The self argument is the instance to be initialized; the *args* and *kwds*
-   arguments represent positional and keyword arguments of the call to
-   :meth:`__init__`.
-
-   The :attr:`tp_init` function, if not *NULL*, is called when an instance is
-   created normally by calling its type, after the type's :attr:`tp_new` function
-   has returned an instance of the type.  If the :attr:`tp_new` function returns an
-   instance of some other type that is not a subtype of the original type, no
-   :attr:`tp_init` function is called; if :attr:`tp_new` returns an instance of a
-   subtype of the original type, the subtype's :attr:`tp_init` is called.  (VERSION
-   NOTE: described here is what is implemented in Python 2.2.1 and later.  In
-   Python 2.2, the :attr:`tp_init` of the type of the object returned by
-   :attr:`tp_new` was always called, if not *NULL*.)
-
-   This field is inherited by subtypes.
-
-
-.. cmember:: allocfunc PyTypeObject.tp_alloc
-
-   An optional pointer to an instance allocation function.
-
-   The function signature is ::
-
-      PyObject *tp_alloc(PyTypeObject *self, Py_ssize_t nitems)
-
-   The purpose of this function is to separate memory allocation from memory
-   initialization.  It should return a pointer to a block of memory of adequate
-   length for the instance, suitably aligned, and initialized to zeros, but with
-   :attr:`ob_refcnt` set to ``1`` and :attr:`ob_type` set to the type argument.  If
-   the type's :attr:`tp_itemsize` is non-zero, the object's :attr:`ob_size` field
-   should be initialized to *nitems* and the length of the allocated memory block
-   should be ``tp_basicsize + nitems*tp_itemsize``, rounded up to a multiple of
-   ``sizeof(void*)``; otherwise, *nitems* is not used and the length of the block
-   should be :attr:`tp_basicsize`.
-
-   Do not use this function to do any other instance initialization, not even to
-   allocate additional memory; that should be done by :attr:`tp_new`.
-
-   This field is inherited by static subtypes, but not by dynamic subtypes
-   (subtypes created by a class statement); in the latter, this field is always set
-   to :cfunc:`PyType_GenericAlloc`, to force a standard heap allocation strategy.
-   That is also the recommended value for statically defined types.
-
-
-.. cmember:: newfunc PyTypeObject.tp_new
-
-   An optional pointer to an instance creation function.
-
-   If this function is *NULL* for a particular type, that type cannot be called to
-   create new instances; presumably there is some other way to create instances,
-   like a factory function.
-
-   The function signature is ::
-
-      PyObject *tp_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
-
-   The subtype argument is the type of the object being created; the *args* and
-   *kwds* arguments represent positional and keyword arguments of the call to the
-   type.  Note that subtype doesn't have to equal the type whose :attr:`tp_new`
-   function is called; it may be a subtype of that type (but not an unrelated
-   type).
-
-   The :attr:`tp_new` function should call ``subtype->tp_alloc(subtype, nitems)``
-   to allocate space for the object, and then do only as much further
-   initialization as is absolutely necessary.  Initialization that can safely be
-   ignored or repeated should be placed in the :attr:`tp_init` handler.  A good
-   rule of thumb is that for immutable types, all initialization should take place
-   in :attr:`tp_new`, while for mutable types, most initialization should be
-   deferred to :attr:`tp_init`.
-
-   This field is inherited by subtypes, except it is not inherited by static types
-   whose :attr:`tp_base` is *NULL* or ``&PyBaseObject_Type``.  The latter exception
-   is a precaution so that old extension types don't become callable simply by
-   being linked with Python 2.2.
-
-
-.. cmember:: destructor PyTypeObject.tp_free
-
-   An optional pointer to an instance deallocation function.
-
-   The signature of this function has changed slightly: in Python 2.2 and 2.2.1,
-   its signature is :ctype:`destructor`::
-
-      void tp_free(PyObject *)
-
-   In Python 2.3 and beyond, its signature is :ctype:`freefunc`::
-
-      void tp_free(void *)
-
-   The only initializer that is compatible with both versions is ``PyObject_Free``,
-   whose definition has suitably adapted in Python 2.3.
-
-   This field is inherited by static subtypes, but not by dynamic subtypes
-   (subtypes created by a class statement); in the latter, this field is set to a
-   deallocator suitable to match :cfunc:`PyType_GenericAlloc` and the value of the
-   :const:`Py_TPFLAGS_HAVE_GC` flag bit.
-
-
-.. cmember:: inquiry PyTypeObject.tp_is_gc
-
-   An optional pointer to a function called by the garbage collector.
-
-   The garbage collector needs to know whether a particular object is collectible
-   or not.  Normally, it is sufficient to look at the object's type's
-   :attr:`tp_flags` field, and check the :const:`Py_TPFLAGS_HAVE_GC` flag bit.  But
-   some types have a mixture of statically and dynamically allocated instances, and
-   the statically allocated instances are not collectible.  Such types should
-   define this function; it should return ``1`` for a collectible instance, and
-   ``0`` for a non-collectible instance. The signature is ::
-
-      int tp_is_gc(PyObject *self)
-
-   (The only example of this are types themselves.  The metatype,
-   :cdata:`PyType_Type`, defines this function to distinguish between statically
-   and dynamically allocated types.)
-
-   This field is inherited by subtypes.  (VERSION NOTE: in Python 2.2, it was not
-   inherited.  It is inherited in 2.2.1 and later versions.)
-
-
-.. cmember:: PyObject* PyTypeObject.tp_bases
-
-   Tuple of base types.
-
-   This is set for types created by a class statement.  It should be *NULL* for
-   statically defined types.
-
-   This field is not inherited.
-
-
-.. cmember:: PyObject* PyTypeObject.tp_mro
-
-   Tuple containing the expanded set of base types, starting with the type itself
-   and ending with :class:`object`, in Method Resolution Order.
-
-   This field is not inherited; it is calculated fresh by :cfunc:`PyType_Ready`.
-
-
-.. cmember:: PyObject* PyTypeObject.tp_cache
-
-   Unused.  Not inherited.  Internal use only.
-
-
-.. cmember:: PyObject* PyTypeObject.tp_subclasses
-
-   List of weak references to subclasses.  Not inherited.  Internal use only.
-
-
-.. cmember:: PyObject* PyTypeObject.tp_weaklist
-
-   Weak reference list head, for weak references to this type object.  Not
-   inherited.  Internal use only.
-
-The remaining fields are only defined if the feature test macro
-:const:`COUNT_ALLOCS` is defined, and are for internal use only. They are
-documented here for completeness.  None of these fields are inherited by
-subtypes.
-
-
-.. cmember:: Py_ssize_t PyTypeObject.tp_allocs
-
-   Number of allocations.
-
-
-.. cmember:: Py_ssize_t PyTypeObject.tp_frees
-
-   Number of frees.
-
-
-.. cmember:: Py_ssize_t PyTypeObject.tp_maxalloc
-
-   Maximum simultaneously allocated objects.
-
-
-.. cmember:: PyTypeObject* PyTypeObject.tp_next
-
-   Pointer to the next type object with a non-zero :attr:`tp_allocs` field.
-
-Also, note that, in a garbage collected Python, tp_dealloc may be called from
-any Python thread, not just the thread which created the object (if the object
-becomes part of a refcount cycle, that cycle might be collected by a garbage
-collection on any thread).  This is not a problem for Python API calls, since
-the thread on which tp_dealloc is called will own the Global Interpreter Lock
-(GIL). However, if the object being destroyed in turn destroys objects from some
-other C or C++ library, care should be taken to ensure that destroying those
-objects on the thread which called tp_dealloc will not violate any assumptions
-of the library.
-
-
-.. _number-structs:
-
-Number Object Structures
-========================
-
-.. sectionauthor:: Amaury Forgeot d'Arc
-
-
-.. ctype:: PyNumberMethods
-
-   This structure holds pointers to the functions which an object uses to
-   implement the number protocol.  Each function is used by the function of
-   similar name documented in the :ref:`number` section.
-
-   Here is the structure definition::
-
-       typedef struct {
-            binaryfunc nb_add;
-            binaryfunc nb_subtract;
-            binaryfunc nb_multiply;
-            binaryfunc nb_remainder;
-            binaryfunc nb_divmod;
-            ternaryfunc nb_power;
-            unaryfunc nb_negative;
-            unaryfunc nb_positive;
-            unaryfunc nb_absolute;
-            inquiry nb_bool;
-            unaryfunc nb_invert;
-            binaryfunc nb_lshift;
-            binaryfunc nb_rshift;
-            binaryfunc nb_and;
-            binaryfunc nb_xor;
-            binaryfunc nb_or;
-            int nb_reserved;  /* unused, must be zero */
-            unaryfunc nb_int;
-            unaryfunc nb_long;
-            unaryfunc nb_float;
-            
-            unaryfunc nb_oct; /* not used anymore, must be zero */
-            unaryfunc nb_hex; /* not used anymore, must be zero */
-
-            binaryfunc nb_inplace_add;
-            binaryfunc nb_inplace_subtract;
-            binaryfunc nb_inplace_multiply;
-            binaryfunc nb_inplace_remainder;
-            ternaryfunc nb_inplace_power;
-            binaryfunc nb_inplace_lshift;
-            binaryfunc nb_inplace_rshift;
-            binaryfunc nb_inplace_and;
-            binaryfunc nb_inplace_xor;
-            binaryfunc nb_inplace_or;
-
-            binaryfunc nb_floor_divide;
-            binaryfunc nb_true_divide;
-            binaryfunc nb_inplace_floor_divide;
-            binaryfunc nb_inplace_true_divide;
-
-            unaryfunc nb_index;
-       } PyNumberMethods;
-
-   .. note::
-
-      Binary and ternary functions must check the type of all their operands,
-      and implement the necessary conversions (at least one of the operands is
-      an instance of the defined type).  If the operation is not defined for the
-      given operands, binary and ternary functions must return
-      ``Py_NotImplemented``, if another error occurred they must return ``NULL``
-      and set an exception.
-
-
-.. _mapping-structs:
-
-Mapping Object Structures
-=========================
-
-.. sectionauthor:: Amaury Forgeot d'Arc
-
-
-.. ctype:: PyMappingMethods
-
-   This structure holds pointers to the functions which an object uses to
-   implement the mapping protocol.  It has three members:
-
-.. cmember:: lenfunc PyMappingMethods.mp_length
-
-   This function is used by :cfunc:`PyMapping_Length` and
-   :cfunc:`PyObject_Size`, and has the same signature.  This slot may be set to
-   *NULL* if the object has no defined length.
-
-.. cmember:: binaryfunc PyMappingMethods.mp_subscript
-
-   This function is used by :cfunc:`PyObject_GetItem` and has the same
-   signature.  This slot must be filled for the :cfunc:`PyMapping_Check`
-   function to return ``1``, it can be *NULL* otherwise.
-
-.. cmember:: objobjargproc PyMappingMethods.mp_ass_subscript
-
-   This function is used by :cfunc:`PyObject_SetItem` and has the same
-   signature.  If this slot is *NULL*, the object does not support item
-   assignment.
-
-
-.. _sequence-structs:
-
-Sequence Object Structures
-==========================
-
-.. sectionauthor:: Amaury Forgeot d'Arc
-
-
-.. ctype:: PySequenceMethods
-
-   This structure holds pointers to the functions which an object uses to
-   implement the sequence protocol.
-
-.. cmember:: lenfunc PySequenceMethods.sq_length
-
-   This function is used by :cfunc:`PySequence_Size` and :cfunc:`PyObject_Size`,
-   and has the same signature.
-
-.. cmember:: binaryfunc PySequenceMethods.sq_concat
-
-   This function is used by :cfunc:`PySequence_Concat` and has the same
-   signature.  It is also used by the `+` operator, after trying the numeric
-   addition via the :attr:`tp_as_number.nb_add` slot.
-
-.. cmember:: ssizeargfunc PySequenceMethods.sq_repeat
-
-   This function is used by :cfunc:`PySequence_Repeat` and has the same
-   signature.  It is also used by the `*` operator, after trying numeric
-   multiplication via the :attr:`tp_as_number.nb_mul` slot.
-
-.. cmember:: ssizeargfunc PySequenceMethods.sq_item
-
-   This function is used by :cfunc:`PySequence_GetItem` and has the same
-   signature.  This slot must be filled for the :cfunc:`PySequence_Check`
-   function to return ``1``, it can be *NULL* otherwise.
-
-   Negative indexes are handled as follows: if the :attr:`sq_length` slot is
-   filled, it is called and the sequence length is used to compute a positive
-   index which is passed to :attr:`sq_item`.  If :attr:`sq_length` is *NULL*,
-   the index is passed as is to the function.
-
-.. cmember:: ssizeobjargproc PySequenceMethods.sq_ass_item
-
-   This function is used by :cfunc:`PySequence_SetItem` and has the same
-   signature.  This slot may be left to *NULL* if the object does not support
-   item assignment.
-
-.. cmember:: objobjproc PySequenceMethods.sq_contains
-
-   This function may be used by :cfunc:`PySequence_Contains` and has the same
-   signature.  This slot may be left to *NULL*, in this case
-   :cfunc:`PySequence_Contains` simply traverses the sequence until it finds a
-   match.
-
-.. cmember:: binaryfunc PySequenceMethods.sq_inplace_concat
-
-   This function is used by :cfunc:`PySequence_InPlaceConcat` and has the same
-   signature.  It should modify its first operand, and return it.
-
-.. cmember:: ssizeargfunc PySequenceMethods.sq_inplace_repeat
-
-   This function is used by :cfunc:`PySequence_InPlaceRepeat` and has the same
-   signature.  It should modify its first operand, and return it.
-
-.. XXX need to explain precedence between mapping and sequence
-.. XXX explains when to implement the sq_inplace_* slots
-
-
-.. _buffer-structs:
-
-Buffer Object Structures
-========================
-
-.. sectionauthor:: Greg J. Stein <greg at lyra.org>
-
-
-The buffer interface exports a model where an object can expose its internal
-data as a set of chunks of data, where each chunk is specified as a
-pointer/length pair.  These chunks are called :dfn:`segments` and are presumed
-to be non-contiguous in memory.
-
-If an object does not export the buffer interface, then its :attr:`tp_as_buffer`
-member in the :ctype:`PyTypeObject` structure should be *NULL*.  Otherwise, the
-:attr:`tp_as_buffer` will point to a :ctype:`PyBufferProcs` structure.
-
-.. note::
-
-   It is very important that your :ctype:`PyTypeObject` structure uses
-   :const:`Py_TPFLAGS_DEFAULT` for the value of the :attr:`tp_flags` member rather
-   than ``0``.  This tells the Python runtime that your :ctype:`PyBufferProcs`
-   structure contains the :attr:`bf_getcharbuffer` slot. Older versions of Python
-   did not have this member, so a new Python interpreter using an old extension
-   needs to be able to test for its presence before using it.
-
-
-.. ctype:: PyBufferProcs
-
-   Structure used to hold the function pointers which define an implementation of
-   the buffer protocol.
-
-   The first slot is :attr:`bf_getreadbuffer`, of type :ctype:`getreadbufferproc`.
-   If this slot is *NULL*, then the object does not support reading from the
-   internal data.  This is non-sensical, so implementors should fill this in, but
-   callers should test that the slot contains a non-*NULL* value.
-
-   The next slot is :attr:`bf_getwritebuffer` having type
-   :ctype:`getwritebufferproc`.  This slot may be *NULL* if the object does not
-   allow writing into its returned buffers.
-
-   The third slot is :attr:`bf_getsegcount`, with type :ctype:`getsegcountproc`.
-   This slot must not be *NULL* and is used to inform the caller how many segments
-   the object contains.  Simple objects such as :ctype:`PyString_Type` and
-   :ctype:`PyBuffer_Type` objects contain a single segment.
-
-   .. index:: single: PyType_HasFeature()
-
-   The last slot is :attr:`bf_getcharbuffer`, of type :ctype:`getcharbufferproc`.
-   This slot will only be present if the :const:`Py_TPFLAGS_HAVE_GETCHARBUFFER`
-   flag is present in the :attr:`tp_flags` field of the object's
-   :ctype:`PyTypeObject`. Before using this slot, the caller should test whether it
-   is present by using the :cfunc:`PyType_HasFeature` function.  If the flag is
-   present, :attr:`bf_getcharbuffer` may be *NULL*, indicating that the object's
-   contents cannot be used as *8-bit characters*. The slot function may also raise
-   an error if the object's contents cannot be interpreted as 8-bit characters.
-   For example, if the object is an array which is configured to hold floating
-   point values, an exception may be raised if a caller attempts to use
-   :attr:`bf_getcharbuffer` to fetch a sequence of 8-bit characters. This notion of
-   exporting the internal buffers as "text" is used to distinguish between objects
-   that are binary in nature, and those which have character-based content.
-
-   .. note::
-
-      The current policy seems to state that these characters may be multi-byte
-      characters. This implies that a buffer size of *N* does not mean there are *N*
-      characters present.
-
-
-.. data:: Py_TPFLAGS_HAVE_GETCHARBUFFER
-
-   Flag bit set in the type structure to indicate that the :attr:`bf_getcharbuffer`
-   slot is known.  This being set does not indicate that the object supports the
-   buffer interface or that the :attr:`bf_getcharbuffer` slot is non-*NULL*.
-
-
-.. ctype:: Py_ssize_t (*readbufferproc) (PyObject *self, Py_ssize_t segment, void **ptrptr)
-
-   Return a pointer to a readable segment of the buffer in ``*ptrptr``.  This
-   function is allowed to raise an exception, in which case it must return ``-1``.
-   The *segment* which is specified must be zero or positive, and strictly less
-   than the number of segments returned by the :attr:`bf_getsegcount` slot
-   function.  On success, it returns the length of the segment, and sets
-   ``*ptrptr`` to a pointer to that memory.
-
-
-.. ctype:: Py_ssize_t (*writebufferproc) (PyObject *self, Py_ssize_t segment, void **ptrptr)
-
-   Return a pointer to a writable memory buffer in ``*ptrptr``, and the length of
-   that segment as the function return value.  The memory buffer must correspond to
-   buffer segment *segment*.  Must return ``-1`` and set an exception on error.
-   :exc:`TypeError` should be raised if the object only supports read-only buffers,
-   and :exc:`SystemError` should be raised when *segment* specifies a segment that
-   doesn't exist.
-
-   .. % Why doesn't it raise ValueError for this one?
-   .. % GJS: because you shouldn't be calling it with an invalid
-   .. % segment. That indicates a blatant programming error in the C
-   .. % code.
-
-
-.. ctype:: Py_ssize_t (*segcountproc) (PyObject *self, Py_ssize_t *lenp)
-
-   Return the number of memory segments which comprise the buffer.  If *lenp* is
-   not *NULL*, the implementation must report the sum of the sizes (in bytes) of
-   all segments in ``*lenp``. The function cannot fail.
-
-
-.. ctype:: Py_ssize_t (*charbufferproc) (PyObject *self, Py_ssize_t segment, const char **ptrptr)
-
-   Return the size of the segment *segment* that *ptrptr*  is set to.  ``*ptrptr``
-   is set to the memory buffer. Returns ``-1`` on error.
-
-
-.. _supporting-iteration:
-
-Supporting the Iterator Protocol
-================================
-
-
-.. _supporting-cycle-detection:
-
-Supporting Cyclic Garbage Collection
-====================================
-
-Python's support for detecting and collecting garbage which involves circular
-references requires support from object types which are "containers" for other
-objects which may also be containers.  Types which do not store references to
-other objects, or which only store references to atomic types (such as numbers
-or strings), do not need to provide any explicit support for garbage collection.
-
-To create a container type, the :attr:`tp_flags` field of the type object must
-include the :const:`Py_TPFLAGS_HAVE_GC` and provide an implementation of the
-:attr:`tp_traverse` handler.  If instances of the type are mutable, a
-:attr:`tp_clear` implementation must also be provided.
-
-
-.. data:: Py_TPFLAGS_HAVE_GC
-
-   Objects with a type with this flag set must conform with the rules documented
-   here.  For convenience these objects will be referred to as container objects.
-
-Constructors for container types must conform to two rules:
-
-#. The memory for the object must be allocated using :cfunc:`PyObject_GC_New` or
-   :cfunc:`PyObject_GC_VarNew`.
-
-#. Once all the fields which may contain references to other containers are
-   initialized, it must call :cfunc:`PyObject_GC_Track`.
-
-
-.. cfunction:: TYPE* PyObject_GC_New(TYPE, PyTypeObject *type)
-
-   Analogous to :cfunc:`PyObject_New` but for container objects with the
-   :const:`Py_TPFLAGS_HAVE_GC` flag set.
-
-
-.. cfunction:: TYPE* PyObject_GC_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size)
-
-   Analogous to :cfunc:`PyObject_NewVar` but for container objects with the
-   :const:`Py_TPFLAGS_HAVE_GC` flag set.
-
-
-.. cfunction:: PyVarObject * PyObject_GC_Resize(PyVarObject *op, Py_ssize_t)
-
-   Resize an object allocated by :cfunc:`PyObject_NewVar`.  Returns the resized
-   object or *NULL* on failure.
-
-
-.. cfunction:: void PyObject_GC_Track(PyObject *op)
-
-   Adds the object *op* to the set of container objects tracked by the collector.
-   The collector can run at unexpected times so objects must be valid while being
-   tracked.  This should be called once all the fields followed by the
-   :attr:`tp_traverse` handler become valid, usually near the end of the
-   constructor.
-
-
-.. cfunction:: void _PyObject_GC_TRACK(PyObject *op)
-
-   A macro version of :cfunc:`PyObject_GC_Track`.  It should not be used for
-   extension modules.
-
-Similarly, the deallocator for the object must conform to a similar pair of
-rules:
-
-#. Before fields which refer to other containers are invalidated,
-   :cfunc:`PyObject_GC_UnTrack` must be called.
-
-#. The object's memory must be deallocated using :cfunc:`PyObject_GC_Del`.
-
-
-.. cfunction:: void PyObject_GC_Del(void *op)
-
-   Releases memory allocated to an object using :cfunc:`PyObject_GC_New` or
-   :cfunc:`PyObject_GC_NewVar`.
-
-
-.. cfunction:: void PyObject_GC_UnTrack(void *op)
-
-   Remove the object *op* from the set of container objects tracked by the
-   collector.  Note that :cfunc:`PyObject_GC_Track` can be called again on this
-   object to add it back to the set of tracked objects.  The deallocator
-   (:attr:`tp_dealloc` handler) should call this for the object before any of the
-   fields used by the :attr:`tp_traverse` handler become invalid.
-
-
-.. cfunction:: void _PyObject_GC_UNTRACK(PyObject *op)
-
-   A macro version of :cfunc:`PyObject_GC_UnTrack`.  It should not be used for
-   extension modules.
-
-The :attr:`tp_traverse` handler accepts a function parameter of this type:
-
-
-.. ctype:: int (*visitproc)(PyObject *object, void *arg)
-
-   Type of the visitor function passed to the :attr:`tp_traverse` handler.  The
-   function should be called with an object to traverse as *object* and the third
-   parameter to the :attr:`tp_traverse` handler as *arg*.  The Python core uses
-   several visitor functions to implement cyclic garbage detection; it's not
-   expected that users will need to write their own visitor functions.
-
-The :attr:`tp_traverse` handler must have the following type:
-
-
-.. ctype:: int (*traverseproc)(PyObject *self, visitproc visit, void *arg)
-
-   Traversal function for a container object.  Implementations must call the
-   *visit* function for each object directly contained by *self*, with the
-   parameters to *visit* being the contained object and the *arg* value passed to
-   the handler.  The *visit* function must not be called with a *NULL* object
-   argument.  If *visit* returns a non-zero value that value should be returned
-   immediately.
-
-To simplify writing :attr:`tp_traverse` handlers, a :cfunc:`Py_VISIT` macro is
-provided.  In order to use this macro, the :attr:`tp_traverse` implementation
-must name its arguments exactly *visit* and *arg*:
-
-
-.. cfunction:: void Py_VISIT(PyObject *o)
-
-   Call the *visit* callback, with arguments *o* and *arg*. If *visit* returns a
-   non-zero value, then return it.  Using this macro, :attr:`tp_traverse` handlers
-   look like::
-
-      static int
-      my_traverse(Noddy *self, visitproc visit, void *arg)
-      {
-          Py_VISIT(self->foo);
-          Py_VISIT(self->bar);
-          return 0;
-      }
-
-The :attr:`tp_clear` handler must be of the :ctype:`inquiry` type, or *NULL* if
-the object is immutable.
-
-
-.. ctype:: int (*inquiry)(PyObject *self)
-
-   Drop references that may have created reference cycles.  Immutable objects do
-   not have to define this method since they can never directly create reference
-   cycles.  Note that the object must still be valid after calling this method
-   (don't just call :cfunc:`Py_DECREF` on a reference).  The collector will call
-   this method if it detects that this object is involved in a reference cycle.
-

Modified: python/branches/py3k-importlib/Doc/c-api/refcounting.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/c-api/refcounting.rst	(original)
+++ python/branches/py3k-importlib/Doc/c-api/refcounting.rst	Thu Mar 27 00:48:05 2008
@@ -63,9 +63,9 @@
 
 
 The following functions are for runtime dynamic embedding of Python:
-``Py_IncRef(PyObject \*o)``, `Py_DecRef(PyObject \*o)``. They are simply
-exported function versions of :cfunc:`Py_XINCREF` and :cfunc:`Py_XDECREF`,
-respectively.
+``Py_IncRef(PyObject *o)``, ``Py_DecRef(PyObject *o)``. They are
+simply exported function versions of :cfunc:`Py_XINCREF` and
+:cfunc:`Py_XDECREF`, respectively.
 
 The following functions or macros are only for use within the interpreter core:
 :cfunc:`_Py_Dealloc`, :cfunc:`_Py_ForgetReference`, :cfunc:`_Py_NewReference`,

Modified: python/branches/py3k-importlib/Doc/c-api/utilities.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/c-api/utilities.rst	(original)
+++ python/branches/py3k-importlib/Doc/c-api/utilities.rst	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,5 @@
 .. highlightlang:: c
 
-
 .. _utilities:
 
 *********
@@ -11,981 +10,11 @@
 helping C code be more portable across platforms, using Python modules from C,
 and parsing function arguments and constructing Python values from C values.
 
+.. toctree::
 
-.. _os:
-
-Operating System Utilities
-==========================
-
-
-.. cfunction:: int Py_FdIsInteractive(FILE *fp, const char *filename)
-
-   Return true (nonzero) if the standard I/O file *fp* with name *filename* is
-   deemed interactive.  This is the case for files for which ``isatty(fileno(fp))``
-   is true.  If the global flag :cdata:`Py_InteractiveFlag` is true, this function
-   also returns true if the *filename* pointer is *NULL* or if the name is equal to
-   one of the strings ``'<stdin>'`` or ``'???'``.
-
-
-.. cfunction:: long PyOS_GetLastModificationTime(char *filename)
-
-   Return the time of last modification of the file *filename*. The result is
-   encoded in the same way as the timestamp returned by the standard C library
-   function :cfunc:`time`.
-
-
-.. cfunction:: void PyOS_AfterFork()
-
-   Function to update some internal state after a process fork; this should be
-   called in the new process if the Python interpreter will continue to be used.
-   If a new executable is loaded into the new process, this function does not need
-   to be called.
-
-
-.. cfunction:: int PyOS_CheckStack()
-
-   Return true when the interpreter runs out of stack space.  This is a reliable
-   check, but is only available when :const:`USE_STACKCHECK` is defined (currently
-   on Windows using the Microsoft Visual C++ compiler).  :const:`USE_STACKCHECK`
-   will be defined automatically; you should never change the definition in your
-   own code.
-
-
-.. cfunction:: PyOS_sighandler_t PyOS_getsig(int i)
-
-   Return the current signal handler for signal *i*.  This is a thin wrapper around
-   either :cfunc:`sigaction` or :cfunc:`signal`.  Do not call those functions
-   directly! :ctype:`PyOS_sighandler_t` is a typedef alias for :ctype:`void
-   (\*)(int)`.
-
-
-.. cfunction:: PyOS_sighandler_t PyOS_setsig(int i, PyOS_sighandler_t h)
-
-   Set the signal handler for signal *i* to be *h*; return the old signal handler.
-   This is a thin wrapper around either :cfunc:`sigaction` or :cfunc:`signal`.  Do
-   not call those functions directly!  :ctype:`PyOS_sighandler_t` is a typedef
-   alias for :ctype:`void (\*)(int)`.
-
-
-.. _processcontrol:
-
-Process Control
-===============
-
-
-.. cfunction:: void Py_FatalError(const char *message)
-
-   .. index:: single: abort()
-
-   Print a fatal error message and kill the process.  No cleanup is performed.
-   This function should only be invoked when a condition is detected that would
-   make it dangerous to continue using the Python interpreter; e.g., when the
-   object administration appears to be corrupted.  On Unix, the standard C library
-   function :cfunc:`abort` is called which will attempt to produce a :file:`core`
-   file.
-
-
-.. cfunction:: void Py_Exit(int status)
-
-   .. index::
-      single: Py_Finalize()
-      single: exit()
-
-   Exit the current process.  This calls :cfunc:`Py_Finalize` and then calls the
-   standard C library function ``exit(status)``.
-
-
-.. cfunction:: int Py_AtExit(void (*func) ())
-
-   .. index::
-      single: Py_Finalize()
-      single: cleanup functions
-
-   Register a cleanup function to be called by :cfunc:`Py_Finalize`.  The cleanup
-   function will be called with no arguments and should return no value.  At most
-   32 cleanup functions can be registered.  When the registration is successful,
-   :cfunc:`Py_AtExit` returns ``0``; on failure, it returns ``-1``.  The cleanup
-   function registered last is called first. Each cleanup function will be called
-   at most once.  Since Python's internal finalization will have completed before
-   the cleanup function, no Python APIs should be called by *func*.
-
-
-.. _importing:
-
-Importing Modules
-=================
-
-
-.. cfunction:: PyObject* PyImport_ImportModule(const char *name)
-
-   .. index::
-      single: package variable; __all__
-      single: __all__ (package variable)
-      single: modules (in module sys)
-
-   This is a simplified interface to :cfunc:`PyImport_ImportModuleEx` below,
-   leaving the *globals* and *locals* arguments set to *NULL*.  When the *name*
-   argument contains a dot (when it specifies a submodule of a package), the
-   *fromlist* argument is set to the list ``['*']`` so that the return value is the
-   named module rather than the top-level package containing it as would otherwise
-   be the case.  (Unfortunately, this has an additional side effect when *name* in
-   fact specifies a subpackage instead of a submodule: the submodules specified in
-   the package's ``__all__`` variable are  loaded.)  Return a new reference to the
-   imported module, or *NULL* with an exception set on failure.  Before Python 2.4,
-   the module may still be created in the failure case --- examine ``sys.modules``
-   to find out.  Starting with Python 2.4, a failing import of a module no longer
-   leaves the module in ``sys.modules``.
-
-
-.. cfunction:: PyObject* PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist)
-
-   .. index:: builtin: __import__
-
-   Import a module.  This is best described by referring to the built-in Python
-   function :func:`__import__`, as the standard :func:`__import__` function calls
-   this function directly.
-
-   The return value is a new reference to the imported module or top-level package,
-   or *NULL* with an exception set on failure (before Python 2.4, the module may
-   still be created in this case).  Like for :func:`__import__`, the return value
-   when a submodule of a package was requested is normally the top-level package,
-   unless a non-empty *fromlist* was given.
-
-   Failing imports remove incomplete module objects, like with
-   :cfunc:`PyImport_ImportModule`.
-
-
-.. cfunction:: PyObject* PyImport_Import(PyObject *name)
-
-   This is a higher-level interface that calls the current "import hook function".
-   It invokes the :func:`__import__` function from the ``__builtins__`` of the
-   current globals.  This means that the import is done using whatever import hooks
-   are installed in the current environment.
-
-
-.. cfunction:: PyObject* PyImport_ReloadModule(PyObject *m)
-
-   Reload a module.  Return a new reference to the reloaded module, or *NULL* with
-   an exception set on failure (the module still exists in this case).
-
-
-.. cfunction:: PyObject* PyImport_AddModule(const char *name)
-
-   Return the module object corresponding to a module name.  The *name* argument
-   may be of the form ``package.module``. First check the modules dictionary if
-   there's one there, and if not, create a new one and insert it in the modules
-   dictionary. Return *NULL* with an exception set on failure.
-
-   .. note::
-
-      This function does not load or import the module; if the module wasn't already
-      loaded, you will get an empty module object. Use :cfunc:`PyImport_ImportModule`
-      or one of its variants to import a module.  Package structures implied by a
-      dotted name for *name* are not created if not already present.
-
-
-.. cfunction:: PyObject* PyImport_ExecCodeModule(char *name, PyObject *co)
-
-   .. index:: builtin: compile
-
-   Given a module name (possibly of the form ``package.module``) and a code object
-   read from a Python bytecode file or obtained from the built-in function
-   :func:`compile`, load the module.  Return a new reference to the module object,
-   or *NULL* with an exception set if an error occurred.  Before Python 2.4, the
-   module could still be created in error cases.  Starting with Python 2.4, *name*
-   is removed from ``sys.modules`` in error cases, and even if *name* was already
-   in ``sys.modules`` on entry to :cfunc:`PyImport_ExecCodeModule`.  Leaving
-   incompletely initialized modules in ``sys.modules`` is dangerous, as imports of
-   such modules have no way to know that the module object is an unknown (and
-   probably damaged with respect to the module author's intents) state.
-
-   This function will reload the module if it was already imported.  See
-   :cfunc:`PyImport_ReloadModule` for the intended way to reload a module.
-
-   If *name* points to a dotted name of the form ``package.module``, any package
-   structures not already created will still not be created.
-
-
-.. cfunction:: long PyImport_GetMagicNumber()
-
-   Return the magic number for Python bytecode files (a.k.a. :file:`.pyc` and
-   :file:`.pyo` files).  The magic number should be present in the first four bytes
-   of the bytecode file, in little-endian byte order.
-
-
-.. cfunction:: PyObject* PyImport_GetModuleDict()
-
-   Return the dictionary used for the module administration (a.k.a.
-   ``sys.modules``).  Note that this is a per-interpreter variable.
-
-
-.. cfunction:: void _PyImport_Init()
-
-   Initialize the import mechanism.  For internal use only.
-
-
-.. cfunction:: void PyImport_Cleanup()
-
-   Empty the module table.  For internal use only.
-
-
-.. cfunction:: void _PyImport_Fini()
-
-   Finalize the import mechanism.  For internal use only.
-
-
-.. cfunction:: PyObject* _PyImport_FindExtension(char *, char *)
-
-   For internal use only.
-
-
-.. cfunction:: PyObject* _PyImport_FixupExtension(char *, char *)
-
-   For internal use only.
-
-
-.. cfunction:: int PyImport_ImportFrozenModule(char *name)
-
-   Load a frozen module named *name*.  Return ``1`` for success, ``0`` if the
-   module is not found, and ``-1`` with an exception set if the initialization
-   failed.  To access the imported module on a successful load, use
-   :cfunc:`PyImport_ImportModule`.  (Note the misnomer --- this function would
-   reload the module if it was already imported.)
-
-
-.. ctype:: struct _frozen
-
-   .. index:: single: freeze utility
-
-   This is the structure type definition for frozen module descriptors, as
-   generated by the :program:`freeze` utility (see :file:`Tools/freeze/` in the
-   Python source distribution).  Its definition, found in :file:`Include/import.h`,
-   is::
-
-      struct _frozen {
-          char *name;
-          unsigned char *code;
-          int size;
-      };
-
-
-.. cvar:: struct _frozen* PyImport_FrozenModules
-
-   This pointer is initialized to point to an array of :ctype:`struct _frozen`
-   records, terminated by one whose members are all *NULL* or zero.  When a frozen
-   module is imported, it is searched in this table.  Third-party code could play
-   tricks with this to provide a dynamically created collection of frozen modules.
-
-
-.. cfunction:: int PyImport_AppendInittab(char *name, void (*initfunc)(void))
-
-   Add a single module to the existing table of built-in modules.  This is a
-   convenience wrapper around :cfunc:`PyImport_ExtendInittab`, returning ``-1`` if
-   the table could not be extended.  The new module can be imported by the name
-   *name*, and uses the function *initfunc* as the initialization function called
-   on the first attempted import.  This should be called before
-   :cfunc:`Py_Initialize`.
-
-
-.. ctype:: struct _inittab
-
-   Structure describing a single entry in the list of built-in modules.  Each of
-   these structures gives the name and initialization function for a module built
-   into the interpreter.  Programs which embed Python may use an array of these
-   structures in conjunction with :cfunc:`PyImport_ExtendInittab` to provide
-   additional built-in modules.  The structure is defined in
-   :file:`Include/import.h` as::
-
-      struct _inittab {
-          char *name;
-          void (*initfunc)(void);
-      };
-
-
-.. cfunction:: int PyImport_ExtendInittab(struct _inittab *newtab)
-
-   Add a collection of modules to the table of built-in modules.  The *newtab*
-   array must end with a sentinel entry which contains *NULL* for the :attr:`name`
-   field; failure to provide the sentinel value can result in a memory fault.
-   Returns ``0`` on success or ``-1`` if insufficient memory could be allocated to
-   extend the internal table.  In the event of failure, no modules are added to the
-   internal table.  This should be called before :cfunc:`Py_Initialize`.
-
-
-.. _marshalling-utils:
-
-Data marshalling support
-========================
-
-These routines allow C code to work with serialized objects using the same data
-format as the :mod:`marshal` module.  There are functions to write data into the
-serialization format, and additional functions that can be used to read the data
-back.  Files used to store marshalled data must be opened in binary mode.
-
-Numeric values are stored with the least significant byte first.
-
-The module supports two versions of the data format: version 0 is the historical
-version, version 1 (new in Python 2.4) shares interned strings in the file, and
-upon unmarshalling. *Py_MARSHAL_VERSION* indicates the current file format
-(currently 1).
-
-
-.. cfunction:: void PyMarshal_WriteLongToFile(long value, FILE *file, int version)
-
-   Marshal a :ctype:`long` integer, *value*, to *file*.  This will only write the
-   least-significant 32 bits of *value*; regardless of the size of the native
-   :ctype:`long` type.  *version* indicates the file format.
-
-
-.. cfunction:: void PyMarshal_WriteObjectToFile(PyObject *value, FILE *file, int version)
-
-   Marshal a Python object, *value*, to *file*.
-   *version* indicates the file format.
-
-
-.. cfunction:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version)
-
-   Return a string object containing the marshalled representation of *value*.
-   *version* indicates the file format.
-
-
-The following functions allow marshalled values to be read back in.
-
-XXX What about error detection?  It appears that reading past the end of the
-file will always result in a negative numeric value (where that's relevant), but
-it's not clear that negative values won't be handled properly when there's no
-error.  What's the right way to tell? Should only non-negative values be written
-using these routines?
-
-
-.. cfunction:: long PyMarshal_ReadLongFromFile(FILE *file)
-
-   Return a C :ctype:`long` from the data stream in a :ctype:`FILE\*` opened for
-   reading.  Only a 32-bit value can be read in using this function, regardless of
-   the native size of :ctype:`long`.
-
-
-.. cfunction:: int PyMarshal_ReadShortFromFile(FILE *file)
-
-   Return a C :ctype:`short` from the data stream in a :ctype:`FILE\*` opened for
-   reading.  Only a 16-bit value can be read in using this function, regardless of
-   the native size of :ctype:`short`.
-
-
-.. cfunction:: PyObject* PyMarshal_ReadObjectFromFile(FILE *file)
-
-   Return a Python object from the data stream in a :ctype:`FILE\*` opened for
-   reading.  On error, sets the appropriate exception (:exc:`EOFError` or
-   :exc:`TypeError`) and returns *NULL*.
-
-
-.. cfunction:: PyObject* PyMarshal_ReadLastObjectFromFile(FILE *file)
-
-   Return a Python object from the data stream in a :ctype:`FILE\*` opened for
-   reading.  Unlike :cfunc:`PyMarshal_ReadObjectFromFile`, this function assumes
-   that no further objects will be read from the file, allowing it to aggressively
-   load file data into memory so that the de-serialization can operate from data in
-   memory rather than reading a byte at a time from the file.  Only use these
-   variant if you are certain that you won't be reading anything else from the
-   file.  On error, sets the appropriate exception (:exc:`EOFError` or
-   :exc:`TypeError`) and returns *NULL*.
-
-
-.. cfunction:: PyObject* PyMarshal_ReadObjectFromString(char *string, Py_ssize_t len)
-
-   Return a Python object from the data stream in a character buffer containing
-   *len* bytes pointed to by *string*.  On error, sets the appropriate exception
-   (:exc:`EOFError` or :exc:`TypeError`) and returns *NULL*.
-
-
-.. _arg-parsing:
-
-Parsing arguments and building values
-=====================================
-
-These functions are useful when creating your own extensions functions and
-methods.  Additional information and examples are available in
-:ref:`extending-index`.
-
-The first three of these functions described, :cfunc:`PyArg_ParseTuple`,
-:cfunc:`PyArg_ParseTupleAndKeywords`, and :cfunc:`PyArg_Parse`, all use *format
-strings* which are used to tell the function about the expected arguments.  The
-format strings use the same syntax for each of these functions.
-
-A format string consists of zero or more "format units."  A format unit
-describes one Python object; it is usually a single character or a parenthesized
-sequence of format units.  With a few exceptions, a format unit that is not a
-parenthesized sequence normally corresponds to a single address argument to
-these functions.  In the following description, the quoted form is the format
-unit; the entry in (round) parentheses is the Python object type that matches
-the format unit; and the entry in [square] brackets is the type of the C
-variable(s) whose address should be passed.
-
-``s`` (string or Unicode object) [const char \*]
-   Convert a Python string or Unicode object to a C pointer to a character string.
-   You must not provide storage for the string itself; a pointer to an existing
-   string is stored into the character pointer variable whose address you pass.
-   The C string is NUL-terminated.  The Python string must not contain embedded NUL
-   bytes; if it does, a :exc:`TypeError` exception is raised. Unicode objects are
-   converted to C strings using the default encoding.  If this conversion fails, a
-   :exc:`UnicodeError` is raised.
-
-``s#`` (string, Unicode or any read buffer compatible object) [const char \*, int]
-   This variant on ``s`` stores into two C variables, the first one a pointer to a
-   character string, the second one its length.  In this case the Python string may
-   contain embedded null bytes.  Unicode objects pass back a pointer to the default
-   encoded string version of the object if such a conversion is possible.  All
-   other read-buffer compatible objects pass back a reference to the raw internal
-   data representation.
-
-``y`` (bytes object) [const char \*]
-   This variant on ``s`` convert a Python bytes object to a C pointer to a
-   character string. The bytes object must not contain embedded NUL bytes; if it
-   does, a :exc:`TypeError` exception is raised.
-
-``y#`` (bytes object) [const char \*, int]
-   This variant on ``s#`` stores into two C variables, the first one a pointer to a
-   character string, the second one its length.  This only accepts bytes objects.
-
-``z`` (string or ``None``) [const char \*]
-   Like ``s``, but the Python object may also be ``None``, in which case the C
-   pointer is set to *NULL*.
-
-``z#`` (string or ``None`` or any read buffer compatible object) [const char \*, int]
-   This is to ``s#`` as ``z`` is to ``s``.
-
-``u`` (Unicode object) [Py_UNICODE \*]
-   Convert a Python Unicode object to a C pointer to a NUL-terminated buffer of
-   16-bit Unicode (UTF-16) data.  As with ``s``, there is no need to provide
-   storage for the Unicode data buffer; a pointer to the existing Unicode data is
-   stored into the :ctype:`Py_UNICODE` pointer variable whose address you pass.
-
-``u#`` (Unicode object) [Py_UNICODE \*, int]
-   This variant on ``u`` stores into two C variables, the first one a pointer to a
-   Unicode data buffer, the second one its length. Non-Unicode objects are handled
-   by interpreting their read-buffer pointer as pointer to a :ctype:`Py_UNICODE`
-   array.
-
-``Z`` (Unicode or ``None``) [Py_UNICODE \*]
-   Like ``s``, but the Python object may also be ``None``, in which case the C
-   pointer is set to *NULL*.
-
-``Z#`` (Unicode or ``None``) [Py_UNICODE \*, int]
-   This is to ``u#`` as ``Z`` is to ``u``.
-
-``es`` (string, Unicode object or character buffer compatible object) [const char \*encoding, char \*\*buffer]
-   This variant on ``s`` is used for encoding Unicode and objects convertible to
-   Unicode into a character buffer. It only works for encoded data without embedded
-   NUL bytes.
-
-   This format requires two arguments.  The first is only used as input, and
-   must be a :ctype:`const char\*` which points to the name of an encoding as a
-   NUL-terminated string, or *NULL*, in which case the default encoding is used.
-   An exception is raised if the named encoding is not known to Python.  The
-   second argument must be a :ctype:`char\*\*`; the value of the pointer it
-   references will be set to a buffer with the contents of the argument text.
-   The text will be encoded in the encoding specified by the first argument.
-
-   :cfunc:`PyArg_ParseTuple` will allocate a buffer of the needed size, copy the
-   encoded data into this buffer and adjust *\*buffer* to reference the newly
-   allocated storage.  The caller is responsible for calling :cfunc:`PyMem_Free` to
-   free the allocated buffer after use.
-
-``et`` (string, Unicode object or character buffer compatible object) [const char \*encoding, char \*\*buffer]
-   Same as ``es`` except that 8-bit string objects are passed through without
-   recoding them.  Instead, the implementation assumes that the string object uses
-   the encoding passed in as parameter.
-
-``es#`` (string, Unicode object or character buffer compatible object) [const char \*encoding, char \*\*buffer, int \*buffer_length]
-   This variant on ``s#`` is used for encoding Unicode and objects convertible to
-   Unicode into a character buffer.  Unlike the ``es`` format, this variant allows
-   input data which contains NUL characters.
-
-   It requires three arguments.  The first is only used as input, and must be a
-   :ctype:`const char\*` which points to the name of an encoding as a
-   NUL-terminated string, or *NULL*, in which case the default encoding is used.
-   An exception is raised if the named encoding is not known to Python.  The
-   second argument must be a :ctype:`char\*\*`; the value of the pointer it
-   references will be set to a buffer with the contents of the argument text.
-   The text will be encoded in the encoding specified by the first argument.
-   The third argument must be a pointer to an integer; the referenced integer
-   will be set to the number of bytes in the output buffer.
-
-   There are two modes of operation:
-
-   If *\*buffer* points a *NULL* pointer, the function will allocate a buffer of
-   the needed size, copy the encoded data into this buffer and set *\*buffer* to
-   reference the newly allocated storage.  The caller is responsible for calling
-   :cfunc:`PyMem_Free` to free the allocated buffer after usage.
-
-   If *\*buffer* points to a non-*NULL* pointer (an already allocated buffer),
-   :cfunc:`PyArg_ParseTuple` will use this location as the buffer and interpret the
-   initial value of *\*buffer_length* as the buffer size.  It will then copy the
-   encoded data into the buffer and NUL-terminate it.  If the buffer is not large
-   enough, a :exc:`ValueError` will be set.
-
-   In both cases, *\*buffer_length* is set to the length of the encoded data
-   without the trailing NUL byte.
-
-``et#`` (string, Unicode object or character buffer compatible object) [const char \*encoding, char \*\*buffer]
-   Same as ``es#`` except that string objects are passed through without recoding
-   them. Instead, the implementation assumes that the string object uses the
-   encoding passed in as parameter.
-
-``b`` (integer) [char]
-   Convert a Python integer to a tiny int, stored in a C :ctype:`char`.
-
-``B`` (integer) [unsigned char]
-   Convert a Python integer to a tiny int without overflow checking, stored in a C
-   :ctype:`unsigned char`.
-
-``h`` (integer) [short int]
-   Convert a Python integer to a C :ctype:`short int`.
-
-``H`` (integer) [unsigned short int]
-   Convert a Python integer to a C :ctype:`unsigned short int`, without overflow
-   checking.
-
-``i`` (integer) [int]
-   Convert a Python integer to a plain C :ctype:`int`.
-
-``I`` (integer) [unsigned int]
-   Convert a Python integer to a C :ctype:`unsigned int`, without overflow
-   checking.
-
-``l`` (integer) [long int]
-   Convert a Python integer to a C :ctype:`long int`.
-
-``k`` (integer) [unsigned long]
-   Convert a Python integer or long integer to a C :ctype:`unsigned long` without
-   overflow checking.
-
-``L`` (integer) [PY_LONG_LONG]
-   Convert a Python integer to a C :ctype:`long long`.  This format is only
-   available on platforms that support :ctype:`long long` (or :ctype:`_int64` on
-   Windows).
-
-``K`` (integer) [unsigned PY_LONG_LONG]
-   Convert a Python integer or long integer to a C :ctype:`unsigned long long`
-   without overflow checking.  This format is only available on platforms that
-   support :ctype:`unsigned long long` (or :ctype:`unsigned _int64` on Windows).
-
-``n`` (integer) [Py_ssize_t]
-   Convert a Python integer or long integer to a C :ctype:`Py_ssize_t`.
-
-``c`` (string of length 1) [char]
-   Convert a Python character, represented as a string of length 1, to a C
-   :ctype:`char`.
-
-``f`` (float) [float]
-   Convert a Python floating point number to a C :ctype:`float`.
-
-``d`` (float) [double]
-   Convert a Python floating point number to a C :ctype:`double`.
-
-``D`` (complex) [Py_complex]
-   Convert a Python complex number to a C :ctype:`Py_complex` structure.
-
-``O`` (object) [PyObject \*]
-   Store a Python object (without any conversion) in a C object pointer.  The C
-   program thus receives the actual object that was passed.  The object's reference
-   count is not increased.  The pointer stored is not *NULL*.
-
-``O!`` (object) [*typeobject*, PyObject \*]
-   Store a Python object in a C object pointer.  This is similar to ``O``, but
-   takes two C arguments: the first is the address of a Python type object, the
-   second is the address of the C variable (of type :ctype:`PyObject\*`) into which
-   the object pointer is stored.  If the Python object does not have the required
-   type, :exc:`TypeError` is raised.
-
-``O&`` (object) [*converter*, *anything*]
-   Convert a Python object to a C variable through a *converter* function.  This
-   takes two arguments: the first is a function, the second is the address of a C
-   variable (of arbitrary type), converted to :ctype:`void \*`.  The *converter*
-   function in turn is called as follows::
-
-      status = converter(object, address);
-
-   where *object* is the Python object to be converted and *address* is the
-   :ctype:`void\*` argument that was passed to the :cfunc:`PyArg_Parse\*` function.
-   The returned *status* should be ``1`` for a successful conversion and ``0`` if
-   the conversion has failed.  When the conversion fails, the *converter* function
-   should raise an exception.
-
-``S`` (string) [PyStringObject \*]
-   Like ``O`` but requires that the Python object is a string object.  Raises
-   :exc:`TypeError` if the object is not a string object.  The C variable may also
-   be declared as :ctype:`PyObject\*`.
-
-``U`` (Unicode string) [PyUnicodeObject \*]
-   Like ``O`` but requires that the Python object is a Unicode object.  Raises
-   :exc:`TypeError` if the object is not a Unicode object.  The C variable may also
-   be declared as :ctype:`PyObject\*`.
-
-``t#`` (read-only character buffer) [char \*, int]
-   Like ``s#``, but accepts any object which implements the read-only buffer
-   interface.  The :ctype:`char\*` variable is set to point to the first byte of
-   the buffer, and the :ctype:`int` is set to the length of the buffer.  Only
-   single-segment buffer objects are accepted; :exc:`TypeError` is raised for all
-   others.
-
-``w`` (read-write character buffer) [char \*]
-   Similar to ``s``, but accepts any object which implements the read-write buffer
-   interface.  The caller must determine the length of the buffer by other means,
-   or use ``w#`` instead.  Only single-segment buffer objects are accepted;
-   :exc:`TypeError` is raised for all others.
-
-``w#`` (read-write character buffer) [char \*, int]
-   Like ``s#``, but accepts any object which implements the read-write buffer
-   interface.  The :ctype:`char \*` variable is set to point to the first byte of
-   the buffer, and the :ctype:`int` is set to the length of the buffer.  Only
-   single-segment buffer objects are accepted; :exc:`TypeError` is raised for all
-   others.
-
-``(items)`` (tuple) [*matching-items*]
-   The object must be a Python sequence whose length is the number of format units
-   in *items*.  The C arguments must correspond to the individual format units in
-   *items*.  Format units for sequences may be nested.
-
-It is possible to pass Python long integers where integers are requested;
-however no proper range checking is done --- the most significant bits are
-silently truncated when the receiving field is too small to receive the value
-(actually, the semantics are inherited from downcasts in C --- your mileage may
-vary).
-
-A few other characters have a meaning in a format string.  These may not occur
-inside nested parentheses.  They are:
-
-``|``
-   Indicates that the remaining arguments in the Python argument list are optional.
-   The C variables corresponding to optional arguments should be initialized to
-   their default value --- when an optional argument is not specified,
-   :cfunc:`PyArg_ParseTuple` does not touch the contents of the corresponding C
-   variable(s).
-
-``:``
-   The list of format units ends here; the string after the colon is used as the
-   function name in error messages (the "associated value" of the exception that
-   :cfunc:`PyArg_ParseTuple` raises).
-
-``;``
-   The list of format units ends here; the string after the semicolon is used as
-   the error message *instead* of the default error message.  Clearly, ``:`` and
-   ``;`` mutually exclude each other.
-
-Note that any Python object references which are provided to the caller are
-*borrowed* references; do not decrement their reference count!
-
-Additional arguments passed to these functions must be addresses of variables
-whose type is determined by the format string; these are used to store values
-from the input tuple.  There are a few cases, as described in the list of format
-units above, where these parameters are used as input values; they should match
-what is specified for the corresponding format unit in that case.
-
-For the conversion to succeed, the *arg* object must match the format and the
-format must be exhausted.  On success, the :cfunc:`PyArg_Parse\*` functions
-return true, otherwise they return false and raise an appropriate exception.
-
-
-.. cfunction:: int PyArg_ParseTuple(PyObject *args, const char *format, ...)
-
-   Parse the parameters of a function that takes only positional parameters into
-   local variables.  Returns true on success; on failure, it returns false and
-   raises the appropriate exception.
-
-
-.. cfunction:: int PyArg_VaParse(PyObject *args, const char *format, va_list vargs)
-
-   Identical to :cfunc:`PyArg_ParseTuple`, except that it accepts a va_list rather
-   than a variable number of arguments.
-
-
-.. cfunction:: int PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], ...)
-
-   Parse the parameters of a function that takes both positional and keyword
-   parameters into local variables.  Returns true on success; on failure, it
-   returns false and raises the appropriate exception.
-
-
-.. cfunction:: int PyArg_VaParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], va_list vargs)
-
-   Identical to :cfunc:`PyArg_ParseTupleAndKeywords`, except that it accepts a
-   va_list rather than a variable number of arguments.
-
-
-.. XXX deprecated, will be removed
-.. cfunction:: int PyArg_Parse(PyObject *args, const char *format, ...)
-
-   Function used to deconstruct the argument lists of "old-style" functions ---
-   these are functions which use the :const:`METH_OLDARGS` parameter parsing
-   method.  This is not recommended for use in parameter parsing in new code, and
-   most code in the standard interpreter has been modified to no longer use this
-   for that purpose.  It does remain a convenient way to decompose other tuples,
-   however, and may continue to be used for that purpose.
-
-
-.. cfunction:: int PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, ...)
-
-   A simpler form of parameter retrieval which does not use a format string to
-   specify the types of the arguments.  Functions which use this method to retrieve
-   their parameters should be declared as :const:`METH_VARARGS` in function or
-   method tables.  The tuple containing the actual parameters should be passed as
-   *args*; it must actually be a tuple.  The length of the tuple must be at least
-   *min* and no more than *max*; *min* and *max* may be equal.  Additional
-   arguments must be passed to the function, each of which should be a pointer to a
-   :ctype:`PyObject\*` variable; these will be filled in with the values from
-   *args*; they will contain borrowed references.  The variables which correspond
-   to optional parameters not given by *args* will not be filled in; these should
-   be initialized by the caller. This function returns true on success and false if
-   *args* is not a tuple or contains the wrong number of elements; an exception
-   will be set if there was a failure.
-
-   This is an example of the use of this function, taken from the sources for the
-   :mod:`_weakref` helper module for weak references::
-
-      static PyObject *
-      weakref_ref(PyObject *self, PyObject *args)
-      {
-          PyObject *object;
-          PyObject *callback = NULL;
-          PyObject *result = NULL;
-
-          if (PyArg_UnpackTuple(args, "ref", 1, 2, &object, &callback)) {
-              result = PyWeakref_NewRef(object, callback);
-          }
-          return result;
-      }
-
-   The call to :cfunc:`PyArg_UnpackTuple` in this example is entirely equivalent to
-   this call to :cfunc:`PyArg_ParseTuple`::
-
-      PyArg_ParseTuple(args, "O|O:ref", &object, &callback)
-
-
-.. cfunction:: PyObject* Py_BuildValue(const char *format, ...)
-
-   Create a new value based on a format string similar to those accepted by the
-   :cfunc:`PyArg_Parse\*` family of functions and a sequence of values.  Returns
-   the value or *NULL* in the case of an error; an exception will be raised if
-   *NULL* is returned.
-
-   :cfunc:`Py_BuildValue` does not always build a tuple.  It builds a tuple only if
-   its format string contains two or more format units.  If the format string is
-   empty, it returns ``None``; if it contains exactly one format unit, it returns
-   whatever object is described by that format unit.  To force it to return a tuple
-   of size 0 or one, parenthesize the format string.
-
-   When memory buffers are passed as parameters to supply data to build objects, as
-   for the ``s`` and ``s#`` formats, the required data is copied.  Buffers provided
-   by the caller are never referenced by the objects created by
-   :cfunc:`Py_BuildValue`.  In other words, if your code invokes :cfunc:`malloc`
-   and passes the allocated memory to :cfunc:`Py_BuildValue`, your code is
-   responsible for calling :cfunc:`free` for that memory once
-   :cfunc:`Py_BuildValue` returns.
-
-   In the following description, the quoted form is the format unit; the entry in
-   (round) parentheses is the Python object type that the format unit will return;
-   and the entry in [square] brackets is the type of the C value(s) to be passed.
-
-   The characters space, tab, colon and comma are ignored in format strings (but
-   not within format units such as ``s#``).  This can be used to make long format
-   strings a tad more readable.
-
-   ``s`` (string) [char \*]
-      Convert a null-terminated C string to a Python object.  If the C string pointer
-      is *NULL*, ``None`` is used.
-
-   ``s#`` (string) [char \*, int]
-      Convert a C string and its length to a Python object.  If the C string pointer
-      is *NULL*, the length is ignored and ``None`` is returned.
-
-   ``z`` (string or ``None``) [char \*]
-      Same as ``s``.
-
-   ``z#`` (string or ``None``) [char \*, int]
-      Same as ``s#``.
-
-   ``u`` (Unicode string) [Py_UNICODE \*]
-      Convert a null-terminated buffer of Unicode (UCS-2 or UCS-4) data to a Python
-      Unicode object.  If the Unicode buffer pointer is *NULL*, ``None`` is returned.
-
-   ``u#`` (Unicode string) [Py_UNICODE \*, int]
-      Convert a Unicode (UCS-2 or UCS-4) data buffer and its length to a Python
-      Unicode object.   If the Unicode buffer pointer is *NULL*, the length is ignored
-      and ``None`` is returned.
-
-   ``U`` (string) [char \*]
-      Convert a null-terminated C string to a Python unicode object. If the C string
-      pointer is *NULL*, ``None`` is used.
-
-   ``U#`` (string) [char \*, int]
-      Convert a C string and its length to a Python unicode object. If the C string
-      pointer is *NULL*, the length is ignored and ``None`` is returned.
-
-   ``i`` (integer) [int]
-      Convert a plain C :ctype:`int` to a Python integer object.
-
-   ``b`` (integer) [char]
-      Convert a plain C :ctype:`char` to a Python integer object.
-
-   ``h`` (integer) [short int]
-      Convert a plain C :ctype:`short int` to a Python integer object.
-
-   ``l`` (integer) [long int]
-      Convert a C :ctype:`long int` to a Python integer object.
-
-   ``B`` (integer) [unsigned char]
-      Convert a C :ctype:`unsigned char` to a Python integer object.
-
-   ``H`` (integer) [unsigned short int]
-      Convert a C :ctype:`unsigned short int` to a Python integer object.
-
-   ``I`` (integer/long) [unsigned int]
-      Convert a C :ctype:`unsigned int` to a Python integer object or a Python long
-      integer object, if it is larger than ``sys.maxint``.
-
-   ``k`` (integer/long) [unsigned long]
-      Convert a C :ctype:`unsigned long` to a Python integer object or a Python long
-      integer object, if it is larger than ``sys.maxint``.
-
-   ``L`` (long) [PY_LONG_LONG]
-      Convert a C :ctype:`long long` to a Python long integer object. Only available
-      on platforms that support :ctype:`long long`.
-
-   ``K`` (long) [unsigned PY_LONG_LONG]
-      Convert a C :ctype:`unsigned long long` to a Python long integer object. Only
-      available on platforms that support :ctype:`unsigned long long`.
-
-   ``n`` (int) [Py_ssize_t]
-      Convert a C :ctype:`Py_ssize_t` to a Python integer or long integer.
-
-   ``c`` (string of length 1) [char]
-      Convert a C :ctype:`int` representing a character to a Python string of length
-      1.
-
-   ``d`` (float) [double]
-      Convert a C :ctype:`double` to a Python floating point number.
-
-   ``f`` (float) [float]
-      Same as ``d``.
-
-   ``D`` (complex) [Py_complex \*]
-      Convert a C :ctype:`Py_complex` structure to a Python complex number.
-
-   ``O`` (object) [PyObject \*]
-      Pass a Python object untouched (except for its reference count, which is
-      incremented by one).  If the object passed in is a *NULL* pointer, it is assumed
-      that this was caused because the call producing the argument found an error and
-      set an exception. Therefore, :cfunc:`Py_BuildValue` will return *NULL* but won't
-      raise an exception.  If no exception has been raised yet, :exc:`SystemError` is
-      set.
-
-   ``S`` (object) [PyObject \*]
-      Same as ``O``.
-
-   ``N`` (object) [PyObject \*]
-      Same as ``O``, except it doesn't increment the reference count on the object.
-      Useful when the object is created by a call to an object constructor in the
-      argument list.
-
-   ``O&`` (object) [*converter*, *anything*]
-      Convert *anything* to a Python object through a *converter* function.  The
-      function is called with *anything* (which should be compatible with :ctype:`void
-      \*`) as its argument and should return a "new" Python object, or *NULL* if an
-      error occurred.
-
-   ``(items)`` (tuple) [*matching-items*]
-      Convert a sequence of C values to a Python tuple with the same number of items.
-
-   ``[items]`` (list) [*matching-items*]
-      Convert a sequence of C values to a Python list with the same number of items.
-
-   ``{items}`` (dictionary) [*matching-items*]
-      Convert a sequence of C values to a Python dictionary.  Each pair of consecutive
-      C values adds one item to the dictionary, serving as key and value,
-      respectively.
-
-   If there is an error in the format string, the :exc:`SystemError` exception is
-   set and *NULL* returned.
-
-
-.. _string-conversion:
-
-String conversion and formatting
-================================
-
-Functions for number conversion and formatted string output.
-
-
-.. cfunction:: int PyOS_snprintf(char *str, size_t size,  const char *format, ...)
-
-   Output not more than *size* bytes to *str* according to the format string
-   *format* and the extra arguments. See the Unix man page :manpage:`snprintf(2)`.
-
-
-.. cfunction:: int PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
-
-   Output not more than *size* bytes to *str* according to the format string
-   *format* and the variable argument list *va*. Unix man page
-   :manpage:`vsnprintf(2)`.
-
-:cfunc:`PyOS_snprintf` and :cfunc:`PyOS_vsnprintf` wrap the Standard C library
-functions :cfunc:`snprintf` and :cfunc:`vsnprintf`. Their purpose is to
-guarantee consistent behavior in corner cases, which the Standard C functions do
-not.
-
-The wrappers ensure that *str*[*size*-1] is always ``'\0'`` upon return. They
-never write more than *size* bytes (including the trailing ``'\0'``) into str.
-Both functions require that ``str != NULL``, ``size > 0`` and ``format !=
-NULL``.
-
-If the platform doesn't have :cfunc:`vsnprintf` and the buffer size needed to
-avoid truncation exceeds *size* by more than 512 bytes, Python aborts with a
-*Py_FatalError*.
-
-The return value (*rv*) for these functions should be interpreted as follows:
-
-* When ``0 <= rv < size``, the output conversion was successful and *rv*
-  characters were written to *str* (excluding the trailing ``'\0'`` byte at
-  *str*[*rv*]).
-
-* When ``rv >= size``, the output conversion was truncated and a buffer with
-  ``rv + 1`` bytes would have been needed to succeed. *str*[*size*-1] is ``'\0'``
-  in this case.
-
-* When ``rv < 0``, "something bad happened." *str*[*size*-1] is ``'\0'`` in
-  this case too, but the rest of *str* is undefined. The exact cause of the error
-  depends on the underlying platform.
-
-The following functions provide locale-independent string to number conversions.
-
-
-.. cfunction:: double PyOS_ascii_strtod(const char *nptr, char **endptr)
-
-   Convert a string to a :ctype:`double`. This function behaves like the Standard C
-   function :cfunc:`strtod` does in the C locale. It does this without changing the
-   current locale, since that would not be thread-safe.
-
-   :cfunc:`PyOS_ascii_strtod` should typically be used for reading configuration
-   files or other non-user input that should be locale independent.
-
-   See the Unix man page :manpage:`strtod(2)` for details.
-
-
-.. cfunction:: char * PyOS_ascii_formatd(char *buffer, size_t buf_len, const char *format, double d)
-
-   Convert a :ctype:`double` to a string using the ``'.'`` as the decimal
-   separator. *format* is a :cfunc:`printf`\ -style format string specifying the
-   number format. Allowed conversion characters are ``'e'``, ``'E'``, ``'f'``,
-   ``'F'``, ``'g'`` and ``'G'``.
-
-   The return value is a pointer to *buffer* with the converted string or NULL if
-   the conversion failed.
-
-
-.. cfunction:: double PyOS_ascii_atof(const char *nptr)
-
-   Convert a string to a :ctype:`double` in a locale-independent way.
-
-   See the Unix man page :manpage:`atof(2)` for details.
-
+   sys.rst
+   import.rst
+   marshal.rst
+   arg.rst
+   conversion.rst
+   reflection.rst

Modified: python/branches/py3k-importlib/Doc/c-api/veryhigh.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/c-api/veryhigh.rst	(original)
+++ python/branches/py3k-importlib/Doc/c-api/veryhigh.rst	Thu Mar 27 00:48:05 2008
@@ -229,6 +229,43 @@
    be parsed or compiled.
 
 
+.. cfunction:: PyObject* PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)
+
+   This is a simplified interface to :cfunc:`PyEval_EvalCodeEx`, with just
+   the code object, and the dictionaries of global and local variables.
+   The other arguments are set to *NULL*.
+
+
+.. cfunction:: PyObject* PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals, PyObject **args, int argcount, PyObject **kws, int kwcount, PyObject **defs, int defcount, PyObject *closure)
+
+   Evaluate a precompiled code object, given a particular environment for its
+   evaluation.  This environment consists of dictionaries of global and local
+   variables, arrays of arguments, keywords and defaults, and a closure tuple of
+   cells.
+
+
+.. cfunction:: PyObject* PyEval_EvalFrame(PyFrameObject *f)
+
+   Evaluate an execution frame.  This is a simplified interface to
+   PyEval_EvalFrameEx, for backward compatibility.
+
+
+.. cfunction:: PyObject* PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
+
+   This is the main, unvarnished function of Python interpretation.  It is
+   literally 2000 lines long.  The code object associated with the execution
+   frame *f* is executed, interpreting bytecode and executing calls as needed.
+   The additional *throwflag* parameter can mostly be ignored - if true, then
+   it causes an exception to immediately be thrown; this is used for the
+   :meth:`throw` methods of generator objects.
+
+
+.. cfunction:: int PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
+
+   This function changes the flags of the current evaluation frame, and returns
+   true on success, false on failure.
+
+
 .. cvar:: int Py_eval_input
 
    .. index:: single: Py_CompileString()

Modified: python/branches/py3k-importlib/Doc/conf.py
==============================================================================
--- python/branches/py3k-importlib/Doc/conf.py	(original)
+++ python/branches/py3k-importlib/Doc/conf.py	Thu Mar 27 00:48:05 2008
@@ -2,20 +2,36 @@
 #
 # Python documentation build configuration file
 #
+# This file is execfile()d with the current directory set to its containing dir.
+#
 # The contents of this file are pickled, so don't put values in the namespace
 # that aren't pickleable (module imports are okay, they're removed automatically).
-#
+
+import sys, os, time
+sys.path.append('tools/sphinxext')
+
+# General configuration
+# ---------------------
+
+extensions = ['sphinx.ext.refcounting', 'sphinx.ext.coverage',
+              'sphinx.ext.doctest']
+templates_path = ['tools/sphinxext']
+
+# General substitutions.
+project = 'Python'
+copyright = '1990-%s, Python Software Foundation' % time.strftime('%Y')
 
 # The default replacements for |version| and |release|.
-# If 'auto', Sphinx looks for the Include/patchlevel.h file in the current Python
-# source tree and replaces the values accordingly.
 #
 # The short X.Y version.
 # version = '2.6'
-version = 'auto'
 # The full version, including alpha/beta/rc tags.
 # release = '2.6a0'
-release = 'auto'
+
+# We look for the Include/patchlevel.h file in the current Python source tree
+# and replace the values accordingly.
+import patchlevel
+version, release = patchlevel.get_version_info()
 
 # There are two options for replacing |today|: either, you set today to some
 # non-false value, then it is used:
@@ -23,30 +39,22 @@
 # Else, today_fmt is used as the format for a strftime call.
 today_fmt = '%B %d, %Y'
 
-# The base URL for download links.
-download_base_url = 'http://docs.python.org/ftp/python/doc/'
-
 # List of files that shouldn't be included in the build.
-unused_files = [
-    'whatsnew/2.0.rst',
-    'whatsnew/2.1.rst',
-    'whatsnew/2.2.rst',
-    'whatsnew/2.3.rst',
-    'whatsnew/2.4.rst',
-    'whatsnew/2.5.rst',
-    'whatsnew/2.6.rst',
-    'maclib/scrap.rst',
-    'library/xmllib.rst',
-    'library/xml.etree.rst',
+unused_docs = [
+    'whatsnew/2.0',
+    'whatsnew/2.1',
+    'whatsnew/2.2',
+    'whatsnew/2.3',
+    'whatsnew/2.4',
+    'whatsnew/2.5',
+    'whatsnew/2.6',
+    'maclib/scrap',
+    'library/xmllib',
+    'library/xml.etree',
 ]
 
-# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
-# using the given strftime format.
-last_updated_format = '%b %d, %Y'
-
-# If true, SmartyPants will be used to convert quotes and dashes to
-# typographically correct entities.
-use_smartypants = True
+# Relative filename of the reference count data file.
+refcount_file = 'data/refcounts.dat'
 
 # If true, '()' will be appended to :func: etc. cross-reference text.
 add_function_parentheses = True
@@ -54,3 +62,119 @@
 # If true, the current module name will be prepended to all description
 # unit titles (such as .. function::).
 add_module_names = True
+
+
+# Options for HTML output
+# -----------------------
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+html_use_smartypants = True
+
+# Content template for the index page, filename relative to this file.
+html_index = 'indexcontent.html'
+
+# Custom sidebar templates, filenames relative to this file.
+html_sidebars = {
+    'index': 'indexsidebar.html',
+}
+
+# Additional templates that should be rendered to pages.
+html_additional_pages = {
+    'download': 'download.html',
+}
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'python' + release.replace('.', '')
+
+
+# Options for LaTeX output
+# ------------------------
+
+# The paper size ('letter' or 'a4').
+latex_paper_size = 'a4'
+
+# The font size ('10pt', '11pt' or '12pt').
+latex_font_size = '10pt'
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, document class [howto/manual]).
+_stdauthor = r'Guido van Rossum\\Fred L. Drake, Jr., editor'
+latex_documents = [
+    ('c-api/index', 'c-api.tex',
+     'The Python/C API', _stdauthor, 'manual'),
+    ('distutils/index', 'distutils.tex',
+     'Distributing Python Modules', _stdauthor, 'manual'),
+    ('documenting/index', 'documenting.tex',
+     'Documenting Python', 'Georg Brandl', 'manual'),
+    ('extending/index', 'extending.tex',
+     'Extending and Embedding Python', _stdauthor, 'manual'),
+    ('install/index', 'install.tex',
+     'Installing Python Modules', _stdauthor, 'manual'),
+    ('library/index', 'library.tex',
+     'The Python Library Reference', _stdauthor, 'manual'),
+    ('reference/index', 'reference.tex',
+     'The Python Language Reference', _stdauthor, 'manual'),
+    ('tutorial/index', 'tutorial.tex',
+     'Python Tutorial', _stdauthor, 'manual'),
+    ('using/index', 'using.tex',
+     'Using Python', _stdauthor, 'manual'),
+    ('whatsnew/' + version, 'whatsnew.tex',
+     'What\'s New in Python', 'A. M. Kuchling', 'howto'),
+]
+# Collect all HOWTOs individually
+latex_documents.extend(('howto/' + fn[:-4], 'howto-' + fn[:-4] + '.tex',
+                        'HOWTO', _stdauthor, 'howto')
+                       for fn in os.listdir('howto')
+                       if fn.endswith('.rst') and fn != 'index.rst')
+
+# Additional stuff for the LaTeX preamble.
+latex_preamble = r'''
+\authoraddress{
+  \strong{Python Software Foundation}\\
+  Email: \email{docs at python.org}
+}
+'''
+
+# Documents to append as an appendix to all manuals.
+latex_appendices = ['glossary', 'about', 'license', 'copyright']
+
+# Options for the coverage checker
+# --------------------------------
+
+# The coverage checker will ignore all modules/functions/classes whose names
+# match any of the following regexes (using re.match).
+coverage_ignore_modules = [
+    r'[T|t][k|K]',
+    r'Tix',
+    r'distutils.*',
+]
+
+coverage_ignore_functions = [
+    'test($|_)',
+]
+
+coverage_ignore_classes = [
+]
+
+# Glob patterns for C source files for C API coverage, relative to this directory.
+coverage_c_path = [
+    '../Include/*.h',
+]
+
+# Regexes to find C items in the source files.
+coverage_c_regexes = {
+    'cfunction': (r'^PyAPI_FUNC\(.*\)\s+([^_][\w_]+)'),
+    'data': (r'^PyAPI_DATA\(.*\)\s+([^_][\w_]+)'),
+    'macro': (r'^#define ([^_][\w_]+)\(.*\)[\s|\\]'),
+}
+
+# The coverage checker will ignore all C items whose names match these regexes
+# (using re.match) -- the keys must be the same as in coverage_c_regexes.
+coverage_ignore_c_items = {
+#    'cfunction': [...]
+}

Modified: python/branches/py3k-importlib/Doc/contents.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/contents.rst	(original)
+++ python/branches/py3k-importlib/Doc/contents.rst	Thu Mar 27 00:48:05 2008
@@ -6,6 +6,7 @@
 
    whatsnew/3.0.rst
    tutorial/index.rst
+   using/index.rst
    reference/index.rst
    library/index.rst
    extending/index.rst

Modified: python/branches/py3k-importlib/Doc/copyright.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/copyright.rst	(original)
+++ python/branches/py3k-importlib/Doc/copyright.rst	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,7 @@
 
 Python and this documentation is:
 
-Copyright © 2001-2007 Python Software Foundation. All rights reserved.
+Copyright © 2001-2008 Python Software Foundation. All rights reserved.
 
 Copyright © 2000 BeOpen.com. All rights reserved.
 

Modified: python/branches/py3k-importlib/Doc/data/refcounts.dat
==============================================================================
--- python/branches/py3k-importlib/Doc/data/refcounts.dat	(original)
+++ python/branches/py3k-importlib/Doc/data/refcounts.dat	Thu Mar 27 00:48:05 2008
@@ -309,6 +309,11 @@
 PyEval_AcquireThread:void:::
 PyEval_AcquireThread:PyThreadState*:tstate::
 
+PyEval_GetBuiltins:PyObject*::0:
+PyEval_GetLocals:PyObject*::0:
+PyEval_GetGlobals:PyObject*::0:
+PyEval_GetFrame:PyObject*::0:
+
 PyEval_InitThreads:void:::
 
 PyEval_ReleaseLock:void:::
@@ -338,6 +343,15 @@
 PyFile_FromFile:char*:mode::
 PyFile_FromFile:int(*:close)::
 
+PyFile_FromFileEx:PyObject*::+1:
+PyFile_FromFileEx:FILE*:fp::
+PyFile_FromFileEx:char*:name::
+PyFile_FromFileEx:char*:mode::
+PyFile_FromFileEx:int(*:close)::
+PyFile_FromFileEx:int:buffering::
+PyFile_FromFileEx:char*:encoding::
+PyFile_FromFileEx:char*:newline::
+
 PyFile_FromString:PyObject*::+1:
 PyFile_FromString:char*:name::
 PyFile_FromString:char*:mode::
@@ -1237,10 +1251,32 @@
 PyString_AsEncodedString:const char*:encoding::
 PyString_AsEncodedString:const char*:errors::
 
+PySys_AddWarnOption:void:::
+PySys_AddWarnOption:char*:s::
+
+PySys_GetFile:FILE*:::
+PySys_GetFile:char*:name::
+PySys_GetFile:FILE*:def::
+
+PySys_GetObject:PyObject*::0:
+PySys_GetObject:char*:name::
+
 PySys_SetArgv:int:::
 PySys_SetArgv:int:argc::
 PySys_SetArgv:char**:argv::
 
+PySys_SetObject:int:::
+PySys_SetObject:char*:name::
+PySys_SetObject:PyObject*:v:+1:
+
+PySys_ResetWarnOptions:void:::
+
+PySys_WriteStdout:void:::
+PySys_WriteStdout:char*:format::
+
+PySys_WriteStderr:void:::
+PySys_WriteStderr:char*:format::
+
 PyThreadState_Clear:void:::
 PyThreadState_Clear:PyThreadState*:tstate::
 

Modified: python/branches/py3k-importlib/Doc/distutils/apiref.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/distutils/apiref.rst	(original)
+++ python/branches/py3k-importlib/Doc/distutils/apiref.rst	Thu Mar 27 00:48:05 2008
@@ -73,7 +73,7 @@
    +--------------------+--------------------------------+-------------------------------------------------------------+
    | *classifiers*      | A list of categories for the   | The list of available                                       |
    |                    | package                        | categorizations is at                                       |
-   |                    |                                | http://cheeseshop.python.org/pypi?:action=list_classifiers. |
+   |                    |                                | http://pypi.python.org/pypi?:action=list_classifiers.       |
    +--------------------+--------------------------------+-------------------------------------------------------------+
    | *distclass*        | the :class:`Distribution`      | A subclass of                                               |
    |                    | class to use                   | :class:`distutils.core.Distribution`                        |
@@ -1199,7 +1199,7 @@
 
    If *force* is true, all files are recompiled regardless of timestamps.
 
-   The source filename encoded in each bytecode file defaults to the filenames
+   The source filename encoded in each :term:`bytecode` file defaults to the filenames
    listed in *py_files*; you can modify these with *prefix* and *basedir*.
    *prefix* is a string that will be stripped off of each source filename, and
    *base_dir* is a directory name that will be prepended (after *prefix* is
@@ -1820,7 +1820,25 @@
    :synopsis: Build the .py/.pyc files of a package
 
 
-.. % todo
+.. class:: build_py(Command)
+
+.. class:: build_py_2to3(build_py)
+
+   Alternative implementation of build_py which also runs the
+   2to3 conversion library on each .py file that is going to be
+   installed. To use this in a setup.py file for a distribution
+   that is designed to run with both Python 2.x and 3.x, add::
+
+     try:
+        from distutils.command.build_py import build_py_2to3 as build_py
+     except ImportError:
+        from distutils.command.build_py import build_py
+
+   to your setup.py, and later::
+
+      cmdclass = {'build_py':build_py}
+
+   to the invocation of setup().
 
 
 :mod:`distutils.command.build_scripts` --- Build the scripts of a package
@@ -1965,12 +1983,12 @@
 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* an unbound method, a string or None. *predicate* is a method of
+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 unbound methods, so they must already have been defined.  The canonical
-example is the :command:`install` command.
+can be methods of the class, so they must already have been defined.  The
+canonical example is the :command:`install` command.

Modified: python/branches/py3k-importlib/Doc/distutils/builtdist.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/distutils/builtdist.rst	(original)
+++ python/branches/py3k-importlib/Doc/distutils/builtdist.rst	Thu Mar 27 00:48:05 2008
@@ -195,7 +195,7 @@
 |                                          | or  --- & :option:`maintainer` and           |
 |                                          | :option:`maintainer_email`                   |
 +------------------------------------------+----------------------------------------------+
-| Copyright                                | :option:`licence`                            |
+| Copyright                                | :option:`license`                            |
 +------------------------------------------+----------------------------------------------+
 | Url                                      | :option:`url`                                |
 +------------------------------------------+----------------------------------------------+
@@ -311,7 +311,7 @@
 have to create a separate installer for every Python version you want to
 support.
 
-The installer will try to compile pure modules into bytecode after installation
+The installer will try to compile pure modules into :term:`bytecode` after installation
 on the target system in normal and optimizing mode.  If you don't want this to
 happen for some reason, you can run the :command:`bdist_wininst` command with
 the :option:`--no-target-compile` and/or the :option:`--no-target-optimize`

Modified: python/branches/py3k-importlib/Doc/distutils/examples.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/distutils/examples.rst	(original)
+++ python/branches/py3k-importlib/Doc/distutils/examples.rst	Thu Mar 27 00:48:05 2008
@@ -11,7 +11,7 @@
 
 .. seealso::
 
-   `Distutils Cookbook <http://www.python.org/cgi-bin/moinmoin/DistutilsCookbook>`_
+   `Distutils Cookbook <http://wiki.python.org/moin/DistutilsCookbook>`_
       Collection of recipes showing how to achieve more control over distutils.
 
 

Modified: python/branches/py3k-importlib/Doc/distutils/extending.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/distutils/extending.rst	(original)
+++ python/branches/py3k-importlib/Doc/distutils/extending.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,4 @@
-.. _extending:
+.. _extending-distutils:
 
 *******************
 Extending Distutils

Modified: python/branches/py3k-importlib/Doc/distutils/packageindex.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/distutils/packageindex.rst	(original)
+++ python/branches/py3k-importlib/Doc/distutils/packageindex.rst	Thu Mar 27 00:48:05 2008
@@ -53,13 +53,13 @@
 The .pypirc file
 ================
 
-The format of the :file:`.pypirc` file is formated as follows::
+The format of the :file:`.pypirc` file is as follows::
 
    [server-login]
    repository: <repository-url>
    username: <username>
    password: <password>
 
-*repository* can be ommitted and defaults to ``http://www.python.org/pypi``.
+*repository* can be omitted and defaults to ``http://www.python.org/pypi``.
 
 

Modified: python/branches/py3k-importlib/Doc/distutils/setupscript.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/distutils/setupscript.rst	(original)
+++ python/branches/py3k-importlib/Doc/distutils/setupscript.rst	Thu Mar 27 00:48:05 2008
@@ -137,7 +137,7 @@
 extension name, source file(s), and any compile/link requirements (include
 directories, libraries to link with, etc.).
 
-.. % XXX read over this section
+.. XXX read over this section
 
 All of this is done through another keyword argument to :func:`setup`, the
 :option:`ext_modules` option.  :option:`ext_modules` is just a list of
@@ -185,7 +185,7 @@
 same base package), use the :option:`ext_package` keyword argument to
 :func:`setup`.  For example, ::
 
-   setup(...
+   setup(...,
          ext_package='pkg',
          ext_modules=[Extension('foo', ['foo.c']),
                       Extension('subpkg.bar', ['bar.c'])],
@@ -214,7 +214,7 @@
 This warning notwithstanding, options to SWIG can be currently passed like
 this::
 
-   setup(...
+   setup(...,
          ext_modules=[Extension('_foo', ['foo.i'], 
                                 swig_opts=['-modern', '-I../include'])],
          py_modules=['foo'],
@@ -443,7 +443,7 @@
 The :option:`scripts` option simply is a list of files to be handled in this
 way.  From the PyXML setup script::
 
-   setup(... 
+   setup(...,
          scripts=['scripts/xmlproc_parse', 'scripts/xmlproc_val']
          )
 
@@ -499,7 +499,7 @@
 :option:`data_files` specifies a sequence of (*directory*, *files*) pairs in the
 following way::
 
-   setup(...
+   setup(...,
          data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
                      ('config', ['cfg/data.cfg']),
                      ('/etc/init.d', ['init-script'])]
@@ -578,7 +578,7 @@
 (4)
    These fields should not be used if your package is to be compatible with Python
    versions prior to 2.2.3 or 2.3.  The list is available from the `PyPI website
-   <http://www.python.org/pypi>`_.
+   <http://pypi.python.org/pypi>`_.
 
 'short string'
    A single line of text, not more than 200 characters.
@@ -611,7 +611,7 @@
 
 :option:`classifiers` are specified in a python list::
 
-   setup(...
+   setup(...,
          classifiers=[
              'Development Status :: 4 - Beta',
              'Environment :: Console',

Modified: python/branches/py3k-importlib/Doc/distutils/sourcedist.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/distutils/sourcedist.rst	(original)
+++ python/branches/py3k-importlib/Doc/distutils/sourcedist.rst	Thu Mar 27 00:48:05 2008
@@ -122,7 +122,8 @@
 
 * all files in the Distutils "build" tree (default :file:`build/`)
 
-* all files in directories named :file:`RCS`, :file:`CVS` or :file:`.svn`
+* all files in directories named :file:`RCS`, :file:`CVS`, :file:`.svn`,
+  :file:`.hg`, :file:`.git`, :file:`.bzr` or :file:`_darcs`
 
 Now we have our complete list of files, which is written to the manifest for
 future reference, and then used to build the source distribution archive(s).
@@ -156,8 +157,9 @@
    previous two steps, so it's important that the ``prune`` command in the manifest
    template comes after the ``recursive-include`` command
 
-#. exclude the entire :file:`build` tree, and any :file:`RCS`, :file:`CVS` and
-   :file:`.svn` directories
+#. exclude the entire :file:`build` tree, and any :file:`RCS`, :file:`CVS`,
+   :file:`.svn`, :file:`.hg`, :file:`.git`, :file:`.bzr` and :file:`_darcs`
+   directories
 
 Just like in the setup script, file and directory names in the manifest template
 should always be slash-separated; the Distutils will take care of converting

Modified: python/branches/py3k-importlib/Doc/documenting/fromlatex.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/documenting/fromlatex.rst	(original)
+++ python/branches/py3k-importlib/Doc/documenting/fromlatex.rst	Thu Mar 27 00:48:05 2008
@@ -154,25 +154,35 @@
 
         Description.
 
-* **New information unit**
+* **New information units**
 
-  There is a new generic information unit called "describe" which can be used
-  to document things that are not covered by the other units::
+  There are new generic information units: One is called "describe" and can be
+  used to document things that are not covered by the other units::
 
      .. describe:: a == b
 
         The equals operator.
 
+  The others are::
+
+     .. cmdoption:: -O
+
+        Describes a command-line option.
+
+     .. envvar:: PYTHONINSPECT
+
+        Describes an environment variable.
+
 
 Structure
 ---------
 
-The LaTeX docs were split in several toplevel manuals.  Now, all files
-are part of the same documentation tree, as indicated by the *toctree*
-directives in the sources.  Every *toctree* directive embeds other files
-as subdocuments of the current file (this structure is not necessarily
-mirrored in the filesystem layout).  The toplevel file is
-:file:`contents.rst`.
+The LaTeX docs were split in several toplevel manuals.  Now, all files are part
+of the same documentation tree, as indicated by the *toctree* directives in the
+sources (though individual output formats may choose to split them up into parts
+again).  Every *toctree* directive embeds other files as subdocuments of the
+current file (this structure is not necessarily mirrored in the filesystem
+layout).  The toplevel file is :file:`contents.rst`.
 
 However, most of the old directory structure has been kept, with the
 directories renamed as follows:
@@ -183,8 +193,8 @@
 * :file:`ext` -> :file:`extending`
 * :file:`inst` -> :file:`installing`
 * :file:`lib` -> :file:`library`
-* :file:`mac` -> merged into :file:`library`, with `mac/using.tex`
-  moved to `howto/pythonmac.rst`
+* :file:`mac` -> merged into :file:`library`, with :file:`mac/using.tex`
+  moved to :file:`using/mac.rst`
 * :file:`ref` -> :file:`reference`
 * :file:`tut` -> :file:`tutorial`, with the single TeX file split up
 

Modified: python/branches/py3k-importlib/Doc/documenting/markup.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/documenting/markup.rst	(original)
+++ python/branches/py3k-importlib/Doc/documenting/markup.rst	Thu Mar 27 00:48:05 2008
@@ -210,7 +210,20 @@
 
 .. describe:: opcode
 
-   Describes a Python bytecode instruction.
+   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::
+
+      .. cmdoption:: -m <module>
+
+         Run a module as a script.
+
+.. describe:: envvar
+
+   Describes an environment variable that Python uses or defines.
 
 
 There is also a generic version of these directives:
@@ -442,7 +455,7 @@
 
 .. describe:: keyword
 
-   The name of a keyword in a programming language.
+   The name of a keyword in Python.
 
 .. describe:: mailheader
 

Modified: python/branches/py3k-importlib/Doc/documenting/sphinx.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/documenting/sphinx.rst	(original)
+++ python/branches/py3k-importlib/Doc/documenting/sphinx.rst	Thu Mar 27 00:48:05 2008
@@ -47,14 +47,30 @@
    could be docs for temporarily disabled modules or documentation that's not
    yet ready for public consumption.
 
-last_updated_format : string
+add_function_parentheses : bool
+   If true, ``()`` will be appended to the content of ``:func:``, ``:meth:`` and
+   ``:cfunc:`` cross-references.
+
+add_module_names : bool
+   If true, the current module name will be prepended to all description unit
+   titles (such as ``.. function::``).
+
+Builder-specific variables
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+html_download_base_url : string
+   The base URL for download links on the download page.
+
+html_last_updated_fmt : string
    If this is not an empty string, it will be given to ``time.strftime()`` and
    written to each generated output file after "last updated on:".
 
-use_smartypants : bool
+html_use_smartypants : bool
    If true, use SmartyPants to convert quotes and dashes to the typographically
    correct entities.
 
-add_function_parentheses : bool
-   If true, ``()`` will be appended to the content of ``:func:``, ``:meth:`` and
-   ``:cfunc:`` cross-references.
\ No newline at end of file
+latex_paper_size : "letter" or "a4"
+   The paper size option for the LaTeX document class.
+
+latex_font_size : "10pt", "11pt" or "12pt"
+   The font size option for the LaTeX document class.
\ No newline at end of file

Modified: python/branches/py3k-importlib/Doc/documenting/style.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/documenting/style.rst	(original)
+++ python/branches/py3k-importlib/Doc/documenting/style.rst	Thu Mar 27 00:48:05 2008
@@ -66,5 +66,5 @@
     1970s.
 
 
-.. _Apple Publications Style Guide: http://developer.apple.com/documentation/UserExperience/Conceptual/APStyleGuide/AppleStyleGuide2003.pdf
+.. _Apple Publications Style Guide: http://developer.apple.com/documentation/UserExperience/Conceptual/APStyleGuide/AppleStyleGuide2006.pdf
 

Modified: python/branches/py3k-importlib/Doc/extending/building.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/extending/building.rst	(original)
+++ python/branches/py3k-importlib/Doc/extending/building.rst	Thu Mar 27 00:48:05 2008
@@ -80,7 +80,7 @@
           description = 'This is a demo package',
           author = 'Martin v. Loewis',
           author_email = 'martin at v.loewis.de',
-          url = 'http://www.python.org/doc/current/ext/building.html',
+          url = 'http://docs.python.org/extending/building',
           long_description = '''
    This is really just a demo package.
    ''',

Modified: python/branches/py3k-importlib/Doc/extending/embedding.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/extending/embedding.rst	(original)
+++ python/branches/py3k-importlib/Doc/extending/embedding.rst	Thu Mar 27 00:48:05 2008
@@ -155,11 +155,7 @@
 
 Although the program is quite large for its functionality, most of the code is
 for data conversion between Python and C, and for error reporting.  The
-interesting part with respect to embedding Python starts with
-
-.. % $
-
-::
+interesting part with respect to embedding Python starts with ::
 
    Py_Initialize();
    pName = PyString_FromString(argv[1]);
@@ -239,15 +235,8 @@
 In a real application, the methods will expose an API of the application to
 Python.
 
-.. % \section{For the future}
-.. % 
-.. % You don't happen to have a nice library to get textual
-.. % equivalents of numeric values do you :-) ?
-.. % Callbacks here ? (I may be using information from that section
-.. % ?!)
-.. % threads
-.. % code examples do not really behave well if errors happen
-.. % (what to watch out for)
+.. TODO: threads, code examples do not really behave well if errors happen
+   (what to watch out for)
 
 
 .. _embeddingincplusplus:

Modified: python/branches/py3k-importlib/Doc/extending/extending.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/extending/extending.rst	(original)
+++ python/branches/py3k-importlib/Doc/extending/extending.rst	Thu Mar 27 00:48:05 2008
@@ -165,7 +165,7 @@
 Every failing :cfunc:`malloc` call must be turned into an exception --- the
 direct caller of :cfunc:`malloc` (or :cfunc:`realloc`) must call
 :cfunc:`PyErr_NoMemory` and return a failure indicator itself.  All the
-object-creating functions (for example, :cfunc:`PyInt_FromLong`) already do
+object-creating functions (for example, :cfunc:`PyLong_FromLong`) already do
 this, so this note is only relevant to those who call :cfunc:`malloc` directly.
 
 Also note that, with the important exception of :cfunc:`PyArg_ParseTuple` and
@@ -306,7 +306,7 @@
 The method table must be passed to the interpreter in the module's
 initialization function.  The initialization function must be named
 :cfunc:`initname`, where *name* is the name of the module, and should be the
-only non-\ :keyword:`static` item defined in the module file::
+only non-\ ``static`` item defined in the module file::
 
    PyMODINIT_FUNC
    initspam(void)
@@ -466,10 +466,10 @@
 :cfunc:`PyEval_CallObject`.  This function has two arguments, both pointers to
 arbitrary Python objects: the Python function, and the argument list.  The
 argument list must always be a tuple object, whose length is the number of
-arguments.  To call the Python function with no arguments, pass an empty tuple;
-to call it with one argument, pass a singleton tuple. :cfunc:`Py_BuildValue`
-returns a tuple when its format string consists of zero or more format codes
-between parentheses.  For example::
+arguments.  To call the Python function with no arguments, pass in NULL, or 
+an empty tuple; to call it with one argument, pass a singleton tuple.
+:cfunc:`Py_BuildValue` returns a tuple when its format string consists of zero
+or more format codes between parentheses.  For example::
 
    int arg;
    PyObject *arglist;
@@ -527,9 +527,22 @@
    Py_DECREF(result);
 
 Note the placement of ``Py_DECREF(arglist)`` immediately after the call, before
-the error check!  Also note that strictly spoken this code is not complete:
+the error check!  Also note that strictly speaking this code is not complete:
 :cfunc:`Py_BuildValue` may run out of memory, and this should be checked.
 
+You may also call a function with keyword arguments by using 
+:cfunc:`PyEval_CallObjectWithKeywords`.  As in the above example, we use
+:cfunc:`Py_BuildValue` to construct the dictionary. ::
+
+   PyObject *dict;
+   ...
+   dict = Py_BuildValue("{s:i}", "name", val);
+   result = PyEval_CallObjectWithKeywords(my_callback, NULL, dict);
+   Py_DECREF(dict);
+   if (result == NULL)
+       return NULL; /* Pass error back */
+   /* Here maybe use the result */
+   Py_DECREF(result);
 
 .. _parsetuple:
 
@@ -647,11 +660,7 @@
 .. index:: single: Philbrick, Geoff
 
 Here is an example module which uses keywords, based on an example by Geoff
-Philbrick (philbrick at hks.com):
-
-.. % 
-
-::
+Philbrick (philbrick at hks.com)::
 
    #include "Python.h"
 
@@ -749,8 +758,8 @@
 
 In languages like C or C++, the programmer is responsible for dynamic allocation
 and deallocation of memory on the heap.  In C, this is done using the functions
-:cfunc:`malloc` and :cfunc:`free`.  In C++, the operators :keyword:`new` and
-:keyword:`delete` are used with essentially the same meaning and we'll restrict
+:cfunc:`malloc` and :cfunc:`free`.  In C++, the operators ``new`` and
+``delete`` are used with essentially the same meaning and we'll restrict
 the following discussion to the C case.
 
 Every block of memory allocated with :cfunc:`malloc` should eventually be
@@ -817,10 +826,9 @@
 interfaces and the ability to disable the detector at runtime.  The cycle
 detector is considered an optional component; though it is included by default,
 it can be disabled at build time using the :option:`--without-cycle-gc` option
-to the :program:`configure` script on Unix platforms (including Mac OS X) or by
-removing the definition of ``WITH_CYCLE_GC`` in the :file:`pyconfig.h` header on
-other platforms.  If the cycle detector is disabled in this way, the :mod:`gc`
-module will not be available.
+to the :program:`configure` script on Unix platforms (including Mac OS X).  If
+the cycle detector is disabled in this way, the :mod:`gc` module will not be
+available.
 
 
 .. _refcountsinpython:
@@ -876,10 +884,10 @@
 
 Most functions that return a reference to an object pass on ownership with the
 reference.  In particular, all functions whose function it is to create a new
-object, such as :cfunc:`PyInt_FromLong` and :cfunc:`Py_BuildValue`, pass
+object, such as :cfunc:`PyLong_FromLong` and :cfunc:`Py_BuildValue`, pass
 ownership to the receiver.  Even if the object is not actually new, you still
 receive ownership of a new reference to that object.  For instance,
-:cfunc:`PyInt_FromLong` maintains a cache of popular values and can return a
+:cfunc:`PyLong_FromLong` maintains a cache of popular values and can return a
 reference to a cached item.
 
 Many functions that extract objects from other objects also transfer ownership
@@ -929,7 +937,7 @@
    {
        PyObject *item = PyList_GetItem(list, 0);
 
-       PyList_SetItem(list, 1, PyInt_FromLong(0L));
+       PyList_SetItem(list, 1, PyLong_FromLong(0L));
        PyObject_Print(item, stdout, 0); /* BUG! */
    }
 
@@ -961,7 +969,7 @@
        PyObject *item = PyList_GetItem(list, 0);
 
        Py_INCREF(item);
-       PyList_SetItem(list, 1, PyInt_FromLong(0L));
+       PyList_SetItem(list, 1, PyLong_FromLong(0L));
        PyObject_Print(item, stdout, 0);
        Py_DECREF(item);
    }
@@ -1023,11 +1031,10 @@
 
 It is a severe error to ever let a *NULL* pointer "escape" to the Python user.
 
-.. % Frank Stajano:
-.. % A pedagogically buggy example, along the lines of the previous listing,
-.. % would be helpful here -- showing in more concrete terms what sort of
-.. % actions could cause the problem. I can't very well imagine it from the
-.. % description.
+.. Frank Stajano:
+   A pedagogically buggy example, along the lines of the previous listing, would
+   be helpful here -- showing in more concrete terms what sort of actions could
+   cause the problem. I can't very well imagine it from the description.
 
 
 .. _cplusplus:
@@ -1063,7 +1070,7 @@
 manipulation from other extension modules.
 
 At first sight this seems easy: just write the functions (without declaring them
-:keyword:`static`, of course), provide an appropriate header file, and document
+``static``, of course), provide an appropriate header file, and document
 the C API. And in fact this would work if all extension modules were always
 linked statically with the Python interpreter. When modules are used as shared
 libraries, however, the symbols defined in one module may not be visible to
@@ -1076,7 +1083,7 @@
 
 Portability therefore requires not to make any assumptions about symbol
 visibility. This means that all symbols in extension modules should be declared
-:keyword:`static`, except for the module's initialization function, in order to
+``static``, except for the module's initialization function, in order to
 avoid name clashes with other extension modules (as discussed in section
 :ref:`methodtable`). And it means that symbols that *should* be accessible from
 other extension modules must be exported in a different way.
@@ -1111,7 +1118,7 @@
 :cfunc:`PySpam_System` is also exported to other extension modules.
 
 The function :cfunc:`PySpam_System` is a plain C function, declared
-:keyword:`static` like everything else::
+``static`` like everything else::
 
    static int
    PySpam_System(const char *command)
@@ -1167,7 +1174,7 @@
            PyModule_AddObject(m, "_C_API", c_api_object);
    }
 
-Note that ``PySpam_API`` is declared :keyword:`static`; otherwise the pointer
+Note that ``PySpam_API`` is declared ``static``; otherwise the pointer
 array would disappear when :func:`initspam` terminates!
 
 The bulk of the work is in the header file :file:`spammodule.h`, which looks

Modified: python/branches/py3k-importlib/Doc/extending/newtypes.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/extending/newtypes.rst	(original)
+++ python/branches/py3k-importlib/Doc/extending/newtypes.rst	Thu Mar 27 00:48:05 2008
@@ -70,12 +70,12 @@
 compile the code.)
 
 For contrast, let's take a look at the corresponding definition for standard
-Python integers::
+Python floats::
 
    typedef struct {
        PyObject_HEAD
-       long ob_ival;
-   } PyIntObject;
+       double ob_fval;
+   } PyFloatObject;
 
 Moving on, we come to the crunch --- the type object. ::
 
@@ -428,7 +428,7 @@
 * when decrementing a reference count in a :attr:`tp_dealloc` handler when
   garbage-collections is not supported [#]_
 
-We want to want to expose our instance variables as attributes. There are a
+We want to expose our instance variables as attributes. There are a
 number of ways to do that. The simplest way is to define member definitions::
 
    static PyMemberDef Noddy_members[] = {
@@ -616,7 +616,7 @@
 
    Noddy_getseters,           /* tp_getset */
 
-to register out attribute getters and setters.
+to register our attribute getters and setters.
 
 The last item in a :ctype:`PyGetSetDef` structure is the closure mentioned
 above. In this case, we aren't using the closure, so we just pass *NULL*.
@@ -1110,7 +1110,7 @@
 attributes, when the values are computed, or how relevant data is stored.
 
 When :cfunc:`PyType_Ready` is called, it uses three tables referenced by the
-type object to create *descriptors* which are placed in the dictionary of the
+type object to create :term:`descriptor`\s which are placed in the dictionary of the
 type object.  Each descriptor controls access to one attribute of the instance
 object.  Each of the tables is optional; if all three are *NULL*, instances of
 the type will only have attributes that are inherited from their base type, and
@@ -1154,7 +1154,7 @@
        char *doc;
    } PyMemberDef;
 
-For each entry in the table, a descriptor will be constructed and added to the
+For each entry in the table, a :term:`descriptor` will be constructed and added to the
 type which will be able to extract a value from the instance structure.  The
 :attr:`type` field should contain one of the type codes defined in the
 :file:`structmember.h` header; the value will be used to determine how to
@@ -1196,16 +1196,14 @@
 As with the :attr:`tp_methods` table, a sentinel entry with a :attr:`name` value
 of *NULL* is required.
 
-.. % XXX Descriptors need to be explained in more detail somewhere, but
-.. % not here.
-.. % 
-.. % Descriptor objects have two handler functions which correspond to
-.. % the \member{tp_getattro} and \member{tp_setattro} handlers.  The
-.. % \method{__get__()} handler is a function which is passed the
-.. % descriptor, instance, and type objects, and returns the value of the
-.. % attribute, or it returns \NULL{} and sets an exception.  The
-.. % \method{__set__()} handler is passed the descriptor, instance, type,
-.. % and new value;
+.. XXX Descriptors need to be explained in more detail somewhere, but not here.
+   
+   Descriptor objects have two handler functions which correspond to the
+   \member{tp_getattro} and \member{tp_setattro} handlers.  The
+   \method{__get__()} handler is a function which is passed the descriptor,
+   instance, and type objects, and returns the value of the attribute, or it
+   returns \NULL{} and sets an exception.  The \method{__set__()} handler is
+   passed the descriptor, instance, type, and new value;
 
 
 Type-specific Attribute Management
@@ -1540,7 +1538,7 @@
    less careful about decrementing their reference counts, however, we accept
    instances of string subclasses. Even though deallocating normal strings won't
    call back into our objects, we can't guarantee that deallocating an instance of
-   a string subclass won't. call back into out objects.
+   a string subclass won't call back into our objects.
 
 .. [#] Even in the third version, we aren't guaranteed to avoid cycles.  Instances of
    string subclasses are allowed and string subclasses could allow cycles even if

Modified: python/branches/py3k-importlib/Doc/extending/windows.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/extending/windows.rst	(original)
+++ python/branches/py3k-importlib/Doc/extending/windows.rst	Thu Mar 27 00:48:05 2008
@@ -7,8 +7,6 @@
 Building C and C++ Extensions on Windows
 ****************************************
 
-.. % 
-
 This chapter briefly explains how to create a Windows extension module for
 Python using Microsoft Visual C++, and follows with more detailed background
 information on how it works.  The explanatory material is useful for both the
@@ -181,7 +179,7 @@
 
    MyObject_Type.ob_type = &PyType_Type;
 
-Refer to section 3 of the `Python FAQ <http://www.python.org/doc/FAQ.html>`_ for
+Refer to section 3 of the `Python FAQ <http://www.python.org/doc/faq>`_ for
 details on why you must do this.
 
 

Modified: python/branches/py3k-importlib/Doc/glossary.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/glossary.rst	(original)
+++ python/branches/py3k-importlib/Doc/glossary.rst	Thu Mar 27 00:48:05 2008
@@ -15,18 +15,29 @@
    ``...``
       The typical Python prompt of the interactive shell when entering code for
       an indented code block.
+
+   argument
+      A value passed to a function or method, assigned to a name local to
+      the body.  A function or method may have both positional arguments and
+      keyword arguments in its definition.  Positional and keyword arguments
+      may be variable-length: ``*`` accepts or passes (if in the function
+      definition or call) several positional arguments in a list, while ``**``
+      does the same for keyword arguments in a dictionary.
+
+      Any expression may be used within the argument list, and the evaluated
+      value is passed to the local variable.
     
    BDFL
       Benevolent Dictator For Life, a.k.a. `Guido van Rossum
       <http://www.python.org/~guido/>`_, Python's creator.
     
-   byte code
-      The internal representation of a Python program in the interpreter. The
-      byte code is also cached in ``.pyc`` and ``.pyo`` files so that executing
-      the same file is faster the second time (recompilation from source to byte
-      code can be avoided).  This "intermediate language" is said to run on a
-      "virtual machine" that calls the subroutines corresponding to each
-      bytecode.
+   bytecode
+      Python source code is compiled into bytecode, the internal representation
+      of a Python program in the interpreter.  The bytecode is also cached in
+      ``.pyc`` and ``.pyo`` files so that executing the same file is faster the
+      second time (recompilation from source to bytecode can be avoided).  This
+      "intermediate language" is said to run on a "virtual machine" that calls
+      the subroutines corresponding to each bytecode.
     
    classic class
       One of the two flavors of classes in earlier Python versions.  Since
@@ -44,15 +55,41 @@
       advanced mathematical feature.  If you're not aware of a need for them,
       it's almost certain you can safely ignore them.
     
+   context manager
+      An objects that controls the environment seen in a :keyword:`with`
+      statement by defining :meth:`__enter__` and :meth:`__exit__` methods.
+      See :pep:`343`.
+
+   decorator
+      A function returning another function, usually applied as a function
+      transformation using the ``@wrapper`` syntax.  Common examples for
+      decorators are :func:`classmethod` and :func:`staticmethod`.
+
+      The decorator syntax is merely syntactic sugar, the following two
+      function definitions are semantically equivalent::
+
+         def f(...):
+             ...
+         f = staticmethod(f)
+
+         @staticmethod
+         def f(...):
+             ...
+
+      The same concept exists for classes, but is less commonly used there.
+
    descriptor
       An object that defines the methods :meth:`__get__`, :meth:`__set__`, or
       :meth:`__delete__`.  When a class attribute is a descriptor, its special
-      binding behavior is triggered upon attribute lookup.  Normally, writing
-      *a.b* looks up the object *b* in the class dictionary for *a*, but if *b*
-      is a descriptor, the defined method gets called.  Understanding
-      descriptors is a key to a deep understanding of Python because they are
-      the basis for many features including functions, methods, properties,
-      class methods, static methods, and reference to super classes.
+      binding behavior is triggered upon attribute lookup.  Normally, using
+      *a.b* to get, set or delete an attribute looks up the object named *b* in
+      the class dictionary for *a*, but if *b* is a descriptor, the respective
+      descriptor method gets called.  Understanding descriptors is a key to a
+      deep understanding of Python because they are the basis for many features
+      including functions, methods, properties, class methods, static methods,
+      and reference to super classes.
+
+      For more information about descriptors' methods, see :ref:`descriptors`.
     
    dictionary
       An associative array, where arbitrary keys are mapped to values.  The use
@@ -78,10 +115,24 @@
       statements.  The technique contrasts with the :term:`LBYL` style that is
       common in many other languages such as C.
 
+   expression
+      A piece of syntax which can be evaluated to some value.  In other words,
+      an expression is an accumulation of expression elements like literals, names,
+      attribute access, operators or function calls that all return a value.
+      In contrast to other languages, not all language constructs are expressions,
+      but there are also :term:`statement`\s that cannot be used as expressions,
+      such as :keyword:`while` or :keyword:`if`.  Assignments are also not
+      expressions.
+
    extension module
       A module written in C, using Python's C API to interact with the core and
       with user code.
-    
+
+   function
+      A series of statements which returns some value to a caller. It can also
+      be passed zero or more arguments which may be used in the execution of
+      the body. See also :term:`argument` and :term:`method`.
+
    __future__
       A pseudo module which programmers can use to enable new language features
       which are not compatible with the current interpreter.  For example, the
@@ -137,6 +188,20 @@
       in the past to create a "free-threaded" interpreter (one which locks
       shared data at a much finer granularity), but performance suffered in the
       common single-processor case.
+
+   hashable
+      An object is *hashable* if it has a hash value that never changes during
+      its lifetime (it needs a :meth:`__hash__` method), and can be compared to
+      other objects (it needs an :meth:`__eq__` or :meth:`__cmp__` method).
+      Hashable objects that compare equal must have the same hash value.
+
+      Hashability makes an object usable as a dictionary key and a set member,
+      because these data structures use the hash value internally.
+
+      All of Python's immutable built-in objects are hashable, while all mutable
+      containers (such as lists or dictionaries) are not.  Objects that are
+      instances of user-defined classes are hashable by default; they all
+      compare unequal, and their hash value is their :func:`id`.
     
    IDLE
       An Integrated Development Environment for Python.  IDLE is a basic editor
@@ -209,6 +274,19 @@
       with an iterator will just return the same exhausted iterator object used
       in the previous iteration pass, making it appear like an empty container.
     
+      More information can be found in :ref:`typeiter`.
+
+   keyword argument
+      Arguments which are preceded with a ``variable_name=`` in the call.
+      The variable name designates the local name in the function to which the
+      value is assigned.  ``**`` is used to accept or pass a dictionary of
+      keyword arguments.  See :term:`argument`.
+
+   lambda
+      An anonymous inline function consisting of a single :term:`expression`
+      which is evaluated when the function is called.  The syntax to create
+      a lambda function is ``lambda [arguments]: expression``
+
    LBYL
       Look before you leap.  This coding style explicitly tests for
       pre-conditions before making calls or lookups.  This style contrasts with
@@ -237,17 +315,38 @@
       powerful, elegant solutions.  They have been used for logging attribute
       access, adding thread-safety, tracking object creation, implementing
       singletons, and many other tasks.
+
+      More information can be found in :ref:`metaclasses`.
+
+   method
+      A function that is defined inside a class body.  If called as an attribute
+      of an instance of that class, the method will get the instance object as
+      its first :term:`argument` (which is usually called ``self``).
+      See :term:`function` and :term:`nested scope`.
     
    mutable
       Mutable objects can change their value but keep their :func:`id`.  See
       also :term:`immutable`.
+
+   named tuple
+      Any tuple subclass whose indexable fields are also accessible with
+      named attributes (for example, :func:`time.localtime` returns a
+      tuple-like object where the *year* is accessible either with an
+      index such as ``t[0]`` or with a named attribute like ``t.tm_year``).
+
+      A named tuple can be a built-in type such as :class:`time.struct_time`,
+      or it can be created with a regular class definition.  A full featured
+      named tuple can also be created with the factory function
+      :func:`collections.namedtuple`.  The latter approach automatically
+      provides extra features such as a self-documenting representation like
+      ``Employee(name='jones', title='programmer')``.
     
    namespace
       The place where a variable is stored.  Namespaces are implemented as
       dictionaries.  There are the local, global and builtin namespaces as well
       as nested namespaces in objects (in methods).  Namespaces support
       modularity by preventing naming conflicts.  For instance, the functions
-      :func:`__builtin__.open` and :func:`os.open` are distinguished by their
+      :func:`builtins.open` and :func:`os.open` are distinguished by their
       namespaces.  Namespaces also aid readability and maintainability by making
       it clear which module implements a function.  For instance, writing
       :func:`random.seed` or :func:`itertools.izip` makes it clear that those
@@ -267,11 +366,35 @@
       earlier Python versions, only new-style classes could use Python's newer,
       versatile features like :attr:`__slots__`, descriptors, properties,
       :meth:`__getattribute__`, class methods, and static methods.
+
+      More information can be found in :ref:`newstyle`.
     
+   positional argument
+      The arguments assigned to local names inside a function or method,
+      determined by the order in which they were given in the call.  ``*`` is
+      used to either accept multiple positional arguments (when in the
+      definition), or pass several arguments as a list to a function.  See
+      :term:`argument`.
+
    Python 3000
-      Nickname for the next major Python version, 3.0 (coined long ago when the
+      Nickname for the Python 3.x release line (coined long ago when the
       release of version 3 was something in the distant future.)
 
+   Pythonic
+      An idea or piece of code which closely follows the most common idioms of
+      the Python language, rather than implementing code using concepts common
+      in other languages.  For example, a common idiom in Python is the :keyword:`for`
+      loop structure; other languages don't have this easy keyword, so people
+      use a numerical counter instead::
+     
+          for i in range(len(food)):
+              print(food[i])
+
+      As opposed to the cleaner, Pythonic method::
+
+         for piece in food:
+             print(piece)
+
    reference count
       The number of places where a certain object is referenced to.  When the
       reference count drops to zero, an object is deallocated.  While reference
@@ -294,6 +417,17 @@
       mapping rather than a sequence because the lookups use arbitrary
       :term:`immutable` keys rather than integers.
 
+   slice
+      An object usually containing a portion of a :term:`sequence`.  A slice is
+      created using the subscript notation, ``[]`` with colons between numbers
+      when several are given, such as in ``variable_name[1:3:5]``.  The bracket
+      (subscript) notation uses :class:`slice` objects internally.
+
+   statement
+      A statement is part of a suite (a "block" of code).  A statement is either
+      an :term:`expression` or a one of several constructs with a keyword, such
+      as :keyword:`if`, :keyword:`while` or :keyword:`for`.
+
    type
       The type of a Python object determines what kind of object it is; every
       object has a type.  An object's type is accessible as its

Modified: python/branches/py3k-importlib/Doc/howto/advocacy.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/howto/advocacy.rst	(original)
+++ python/branches/py3k-importlib/Doc/howto/advocacy.rst	Thu Mar 27 00:48:05 2008
@@ -160,7 +160,7 @@
    don't merge cleanly into the overall design scheme (thus, some fans of Classic C
    maintain that ANSI C is no longer compact).
 
-   (From http://www.catb.org/ esr/jargon/html/C/compact.html)
+   (From http://www.catb.org/~esr/jargon/html/C/compact.html)
 
 In this sense of the word, Python is quite compact, because the language has
 just a few ideas, which are used in lots of places.  Take namespaces, for
@@ -174,14 +174,14 @@
 This simplicity arises from Python's development history.  The language syntax
 derives from different sources; ABC, a relatively obscure teaching language, is
 one primary influence, and Modula-3 is another.  (For more information about ABC
-and Modula-3, consult their respective Web sites at http://www.cwi.nl/
-steven/abc/ and http://www.m3.org.)  Other features have come from C, Icon,
+and Modula-3, consult their respective Web sites at http://www.cwi.nl/~steven/abc/
+and http://www.m3.org.)  Other features have come from C, Icon,
 Algol-68, and even Perl.  Python hasn't really innovated very much, but instead
 has tried to keep the language small and easy to learn, building on ideas that
 have been tried in other languages and found useful.
 
 Simplicity is a virtue that should not be underestimated.  It lets you learn the
-language more quickly, and then rapidly write code, code that often works the
+language more quickly, and then rapidly write code -- code that often works the
 first time you run it.
 
 
@@ -265,8 +265,8 @@
 **What are the restrictions on Python's use?**
 
 They're practically nonexistent.  Consult the :file:`Misc/COPYRIGHT` file in the
-source distribution, or http://www.python.org/doc/Copyright.html for the full
-language, but it boils down to three conditions.
+source distribution, or the section :ref:`history-and-license` for the full
+language, but it boils down to three conditions:
 
 * You have to leave the copyright notice on the software; if you don't include
   the source code in a product, you have to put the copyright notice in the
@@ -276,7 +276,7 @@
   product in any way.
 
 * If something goes wrong, you can't sue for damages.  Practically all software
-  licences contain this condition.
+  licenses contain this condition.
 
 Notice that you don't have to provide source code for anything that contains
 Python or is built with it.  Also, the Python interpreter and accompanying
@@ -302,11 +302,11 @@
    The Python Success Stories are a collection of stories from successful users of
    Python, with the emphasis on business and corporate users.
 
-.. % \term{\url{http://www.fsbassociates.com/books/pythonchpt1.htm}}
-.. % The first chapter of \emph{Internet Programming with Python} also
-.. % examines some of the reasons for using Python.  The book is well worth
-.. % buying, but the publishers have made the first chapter available on
-.. % the Web.
+.. http://www.fsbassociates.com/books/pythonchpt1.htm
+   The first chapter of \emph{Internet Programming with Python} also
+   examines some of the reasons for using Python.  The book is well worth
+   buying, but the publishers have made the first chapter available on
+   the Web.
 
 http://home.pacbell.net/ouster/scripting.html
    John Ousterhout's white paper on scripting is a good argument for the utility of
@@ -333,9 +333,9 @@
    to show that choosing Python didn't introduce any difficulties into a company's
    development process, and provided some substantial benefits.
 
-.. % \term{\url{http://www.python.org/psa/Commercial.html}}
-.. % Robin Friedrich wrote this document on how to support Python's use in
-.. % commercial projects.
+.. http://www.python.org/psa/Commercial.html
+   Robin Friedrich wrote this document on how to support Python's use in
+   commercial projects.
 
 http://www.python.org/workshops/1997-10/proceedings/stein.ps
    For the 6th Python conference, Greg Stein presented a paper that traced Python's
@@ -346,7 +346,7 @@
    wasn't written commercially.  This site presents arguments that show how open
    source software can have considerable advantages over closed-source software.
 
-http://sunsite.unc.edu/LDP/HOWTO/mini/Advocacy.html
+http://www.faqs.org/docs/Linux-mini/Advocacy.html
    The Linux Advocacy mini-HOWTO was the inspiration for this document, and is also
    well worth reading for general suggestions on winning acceptance for a new
    technology, such as Linux or Python.  In general, you won't make much progress

Modified: python/branches/py3k-importlib/Doc/howto/curses.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/howto/curses.rst	(original)
+++ python/branches/py3k-importlib/Doc/howto/curses.rst	Thu Mar 27 00:48:05 2008
@@ -1,9 +1,11 @@
+.. _curses-howto:
+
 **********************************
   Curses Programming with Python
 **********************************
 
 :Author: A.M. Kuchling, Eric S. Raymond
-:Release: 2.02
+:Release: 2.03
 
 
 .. topic:: Abstract
@@ -50,7 +52,7 @@
 No one has made a Windows port of the curses module.  On a Windows platform, try
 the Console module written by Fredrik Lundh.  The Console module provides
 cursor-addressable text output, plus full support for mouse and keyboard input,
-and is available from http://effbot.org/efflib/console.
+and is available from http://effbot.org/zone/console-index.htm.
 
 
 The Python curses module
@@ -367,8 +369,8 @@
 ``nodelay(1)``, :meth:`getch` for the window becomes non-blocking and returns
 ``curses.ERR`` (a value of -1) when no input is ready.  There's also a
 :func:`halfdelay` function, which can be used to (in effect) set a timer on each
-:meth:`getch`; if no input becomes available within the number of milliseconds
-specified as the argument to :func:`halfdelay`, curses raises an exception.
+:meth:`getch`; if no input becomes available within a specified
+delay (measured in tenths of a second), curses raises an exception.
 
 The :meth:`getch` method returns an integer; if it's between 0 and 255, it
 represents the ASCII code of the key pressed.  Values greater than 255 are
@@ -430,5 +432,5 @@
 If you write an interesting little program, feel free to contribute it as
 another demo.  We can always use more of them!
 
-The ncurses FAQ: http://dickey.his.com/ncurses/ncurses.faq.html
+The ncurses FAQ: http://invisible-island.net/ncurses/ncurses.faq.html
 

Modified: python/branches/py3k-importlib/Doc/howto/doanddont.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/howto/doanddont.rst	(original)
+++ python/branches/py3k-importlib/Doc/howto/doanddont.rst	Thu Mar 27 00:48:05 2008
@@ -75,46 +75,13 @@
 * When the module advertises itself as ``from import *`` safe.
 
 
-Unadorned :keyword:`exec` and friends
--------------------------------------
-
-The word "unadorned" refers to the use without an explicit dictionary, in which
-case those constructs evaluate code in the *current* environment. This is
-dangerous for the same reasons ``from import *`` is dangerous --- it might step
-over variables you are counting on and mess up things for the rest of your code.
-Simply do not do that.
-
-Bad examples::
-
-   >>> for name in sys.argv[1:]:
-   >>>     exec "%s=1" % name
-   >>> def func(s, **kw):
-   >>>     for var, val in kw.items():
-   >>>         exec "s.%s=val" % var  # invalid!
-   >>> exec(open("handler.py").read())
-   >>> handle()
-
-Good examples::
-
-   >>> d = {}
-   >>> for name in sys.argv[1:]:
-   >>>     d[name] = 1
-   >>> def func(s, **kw):
-   >>>     for var, val in kw.items():
-   >>>         setattr(s, var, val)
-   >>> d={}
-   >>> exec(open("handle.py").read(), d, d)
-   >>> handle = d['handle']
-   >>> handle()
-
-
 from module import name1, name2
 -------------------------------
 
 This is a "don't" which is much weaker then the previous "don't"s but is still
 something you should not do if you don't have good reasons to do that. The
 reason it is usually bad idea is because you suddenly have an object which lives
-in two seperate namespaces. When the binding in one namespace changes, the
+in two separate namespaces. When the binding in one namespace changes, the
 binding in the other will not, so there will be a discrepancy between them. This
 happens when, for example, one module is reloaded, or changes the definition of
 a function at runtime.
@@ -276,9 +243,9 @@
 line. The :func:`reduce` adds up all the numbers, and the rest is just some
 pre- and postprocessing.
 
-On the same note, note that :func:`float`, :func:`int` and :func:`long` all
-accept arguments of type string, and so are suited to parsing --- assuming you
-are ready to deal with the :exc:`ValueError` they raise.
+On the same note, note that :func:`float` and :func:`int` accept arguments of
+type string, and so are suited to parsing --- assuming you are ready to deal
+with the :exc:`ValueError` they raise.
 
 
 Using Backslash to Continue Statements
@@ -291,7 +258,7 @@
       calculate_number(10, 20) != forbulate(500, 360):
          pass
 
-You should realize that this is dangerous: a stray space after the ``XXX`` would
+You should realize that this is dangerous: a stray space after the ``\`` would
 make this line wrong, and stray spaces are notoriously hard to see in editors.
 In this case, at least it would be a syntax error, but if the code was::
 

Modified: python/branches/py3k-importlib/Doc/howto/functional.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/howto/functional.rst	(original)
+++ python/branches/py3k-importlib/Doc/howto/functional.rst	Thu Mar 27 00:48:05 2008
@@ -2,19 +2,17 @@
   Functional Programming HOWTO
 ********************************
 
-:Author: \A. M. Kuchling
-:Release: 0.30
+:Author: A. M. Kuchling
+:Release: 0.31
 
 (This is a first draft.  Please send comments/error reports/suggestions to
-amk at amk.ca.  This URL is probably not going to be the final location of the
-document, so be careful about linking to it -- you may want to add a
-disclaimer.)
+amk at amk.ca.)
 
 In this document, we'll take a tour of Python's features suitable for
 implementing programs in a functional style.  After an introduction to the
 concepts of functional programming, we'll look at language features such as
-iterators and generators and relevant library modules such as :mod:`itertools`
-and :mod:`functools`.
+:term:`iterator`\s and :term:`generator`\s and relevant library modules such as
+:mod:`itertools` and :mod:`functools`.
 
 
 Introduction
@@ -49,17 +47,19 @@
   functional languages include the ML family (Standard ML, OCaml, and other
   variants) and Haskell.
 
-The designers of some computer languages have chosen one approach to programming
-that's emphasized.  This often makes it difficult to write programs that use a
-different approach.  Other languages are multi-paradigm languages that support
-several different approaches.  Lisp, C++, and Python are multi-paradigm; you can
-write programs or libraries that are largely procedural, object-oriented, or
-functional in all of these languages.  In a large program, different sections
-might be written using different approaches; the GUI might be object-oriented
-while the processing logic is procedural or functional, for example.
+The designers of some computer languages choose to emphasize one
+particular approach to programming.  This often makes it difficult to
+write programs that use a different approach.  Other languages are
+multi-paradigm languages that support several different approaches.
+Lisp, C++, and Python are multi-paradigm; you can write programs or
+libraries that are largely procedural, object-oriented, or functional
+in all of these languages.  In a large program, different sections
+might be written using different approaches; the GUI might be
+object-oriented while the processing logic is procedural or
+functional, for example.
 
 In a functional program, input flows through a set of functions. Each function
-operates on its input and produces some output.  Functional style frowns upon
+operates on its input and produces some output.  Functional style discourages
 functions with side effects that modify internal state or make other changes
 that aren't visible in the function's return value.  Functions that have no side
 effects at all are called **purely functional**.  Avoiding side effects means
@@ -98,6 +98,7 @@
 * Composability.
 * Ease of debugging and testing.
 
+
 Formal provability
 ------------------
 
@@ -133,6 +134,7 @@
 proof; maybe there's an error in it, and you wrongly believe you've proved the
 program correct.
 
+
 Modularity
 ----------
 
@@ -159,7 +161,6 @@
 check that the output matches expectations.
 
 
-
 Composability
 -------------
 
@@ -175,7 +176,6 @@
 a few functions specialized for the current task.
 
 
-
 Iterators
 =========
 
@@ -197,12 +197,12 @@
 dictionaries.  An object is called an **iterable** object if you can get an
 iterator for it.
 
-You can experiment with the iteration interface manually::
+You can experiment with the iteration interface manually:
 
     >>> L = [1,2,3]
     >>> it = iter(L)
     >>> it
-    <iterator object at 0x8116870>
+    <...iterator object at ...>
     >>> it.next()
     1
     >>> it.next()
@@ -220,14 +220,15 @@
 be an iterator or some object for which ``iter()`` can create an iterator.
 These two statements are equivalent::
 
-        for i in iter(obj):
-            print(i)
 
-        for i in obj:
-            print(i)
+    for i in iter(obj):
+        print i
+
+    for i in obj:
+        print i
 
 Iterators can be materialized as lists or tuples by using the :func:`list` or
-:func:`tuple` constructor functions::
+:func:`tuple` constructor functions:
 
     >>> L = [1,2,3]
     >>> iterator = iter(L)
@@ -236,7 +237,7 @@
     (1, 2, 3)
 
 Sequence unpacking also supports iterators: if you know an iterator will return
-N elements, you can unpack them into an N-tuple::
+N elements, you can unpack them into an N-tuple:
 
     >>> L = [1,2,3]
     >>> iterator = iter(L)
@@ -269,7 +270,11 @@
 iterator.
 
 Calling :func:`iter` on a dictionary returns an iterator that will loop over the
-dictionary's keys::
+dictionary's keys:
+
+.. not a doctest since dict ordering varies across Pythons
+
+::
 
     >>> m = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6,
     ...      'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
@@ -279,11 +284,11 @@
     Feb 2
     Aug 8
     Sep 9
-    May 5
+    Apr 4
     Jun 6
     Jul 7
     Jan 1
-    Apr 4
+    May 5
     Nov 11
     Dec 12
     Oct 10
@@ -297,7 +302,7 @@
 :meth:`values` or :meth:`items` methods to get an appropriate iterator.
 
 The :func:`dict` constructor can accept an iterator that returns a finite stream
-of ``(key, value)`` tuples::
+of ``(key, value)`` tuples:
 
     >>> L = [('Italy', 'Rome'), ('France', 'Paris'), ('US', 'Washington DC')]
     >>> dict(iter(L))
@@ -314,7 +319,7 @@
 Sets can take their contents from an iterable and let you iterate over the set's
 elements::
 
-    S = set((2, 3, 5, 7, 11, 13))
+    S = {2, 3, 5, 7, 11, 13}
     for i in S:
         print(i)
 
@@ -334,18 +339,18 @@
 functional programming language Haskell (http://www.haskell.org).  You can strip
 all the whitespace from a stream of strings with the following code::
 
-        line_list = ['  line 1\n', 'line 2  \n', ...]
+    line_list = ['  line 1\n', 'line 2  \n', ...]
 
-        # Generator expression -- returns iterator
-        stripped_iter = (line.strip() for line in line_list)
+    # Generator expression -- returns iterator
+    stripped_iter = (line.strip() for line in line_list)
 
-        # List comprehension -- returns list
-        stripped_list = [line.strip() for line in line_list]
+    # List comprehension -- returns list
+    stripped_list = [line.strip() for line in line_list]
 
 You can select only certain elements by adding an ``"if"`` condition::
 
-        stripped_list = [line.strip() for line in line_list
-                         if line != ""]
+    stripped_list = [line.strip() for line in line_list
+                     if line != ""]
 
 With a list comprehension, you get back a Python list; ``stripped_list`` is a
 list containing the resulting lines, not an iterator.  Generator expressions
@@ -378,7 +383,7 @@
 parentheses signalling a function call also count.  If you want to create an
 iterator that will be immediately passed to a function you can write::
 
-        obj_total = sum(obj.count for obj in list_all_objects())
+    obj_total = sum(obj.count for obj in list_all_objects())
 
 The ``for...in`` clauses contain the sequences to be iterated over.  The
 sequences do not have to be the same length, because they are iterated over from
@@ -406,11 +411,14 @@
 This means that when there are multiple ``for...in`` clauses but no ``if``
 clauses, the length of the resulting output will be equal to the product of the
 lengths of all the sequences.  If you have two lists of length 3, the output
-list is 9 elements long::
+list is 9 elements long:
 
-    seq1 = 'abc'
-    seq2 = (1,2,3)
-    >>> [ (x,y) for x in seq1 for y in seq2]
+.. doctest::
+    :options: +NORMALIZE_WHITESPACE
+
+    >>> seq1 = 'abc'
+    >>> seq2 = (1,2,3)
+    >>> [(x,y) for x in seq1 for y in seq2]
     [('a', 1), ('a', 2), ('a', 3), 
      ('b', 1), ('b', 2), ('b', 3), 
      ('c', 1), ('c', 2), ('c', 3)]
@@ -441,15 +449,17 @@
 function?  What if you could later resume the function where it left off?  This
 is what generators provide; they can be thought of as resumable functions.
 
-Here's the simplest example of a generator function::
+Here's the simplest example of a generator function:
+
+.. testcode::
 
     def generate_ints(N):
         for i in range(N):
             yield i
 
 Any function containing a ``yield`` keyword is a generator function; this is
-detected by Python's bytecode compiler which compiles the function specially as
-a result.
+detected by Python's :term:`bytecode` compiler which compiles the function
+specially as a result.
 
 When you call a generator function, it doesn't return a single value; instead it
 returns a generator object that supports the iterator protocol.  On executing
@@ -459,11 +469,11 @@
 suspended and local variables are preserved.  On the next call to the
 generator's ``.next()`` method, the function will resume executing.
 
-Here's a sample usage of the ``generate_ints()`` generator::
+Here's a sample usage of the ``generate_ints()`` generator:
 
     >>> gen = generate_ints(3)
     >>> gen
-    <generator object at 0x8117f90>
+    <generator object at ...>
     >>> gen.next()
     0
     >>> gen.next()
@@ -496,9 +506,7 @@
 
 The test suite included with Python's library, ``test_generators.py``, contains
 a number of more interesting examples.  Here's one generator that implements an
-in-order traversal of a tree using generators recursively.
-
-::
+in-order traversal of a tree using generators recursively. ::
 
     # A recursive generator that generates Tree leaves in in-order.
     def inorder(t):
@@ -553,7 +561,7 @@
 Here's a simple counter that increments by 1 and allows changing the value of
 the internal counter.
 
-::
+.. testcode::
 
     def counter (maximum):
         i = 0
@@ -616,49 +624,52 @@
 
 Let's look in more detail at built-in functions often used with iterators.
 
-Two Python's built-in functions, :func:`map` and :func:`filter`, are somewhat
-obsolete; they duplicate the features of list comprehensions but return actual
-lists instead of iterators.
+Two of Python's built-in functions, :func:`map` and :func:`filter` duplicate the
+features of generator expressions:
 
-``map(f, iterA, iterB, ...)`` returns a list containing ``f(iterA[0], iterB[0]),
-f(iterA[1], iterB[1]), f(iterA[2], iterB[2]), ...``.
+``map(f, iterA, iterB, ...)`` returns an iterator over the sequence 
+ ``f(iterA[0], iterB[0]), f(iterA[1], iterB[1]), f(iterA[2], iterB[2]), ...``.
 
-::
+    >>> def upper(s):
+    ...     return s.upper()
 
-    def upper(s):
-        return s.upper()
-    map(upper, ['sentence', 'fragment']) =>
-      ['SENTENCE', 'FRAGMENT']
-
-    [upper(s) for s in ['sentence', 'fragment']] =>
-      ['SENTENCE', 'FRAGMENT']
-
-As shown above, you can achieve the same effect with a list comprehension.  The
-:func:`itertools.imap` function does the same thing but can handle infinite
-iterators; it'll be discussed later, in the section on the :mod:`itertools` module.
 
-``filter(predicate, iter)`` returns a list that contains all the sequence
-elements that meet a certain condition, and is similarly duplicated by list
+    >>> map(upper, ['sentence', 'fragment'])
+    ['SENTENCE', 'FRAGMENT']
+    >>> [upper(s) for s in ['sentence', 'fragment']]
+    ['SENTENCE', 'FRAGMENT']
+
+You can of course achieve the same effect with a list comprehension. 
+
+``filter(predicate, iter)`` returns an iterator over all the sequence elements
+that meet a certain condition, and is similarly duplicated by list
 comprehensions.  A **predicate** is a function that returns the truth value of
 some condition; for use with :func:`filter`, the predicate must take a single
 value.
 
-::
+    >>> def is_even(x):
+    ...     return (x % 2) == 0
 
-    def is_even(x):
-        return (x % 2) == 0
+    >>> filter(is_even, range(10))
+    [0, 2, 4, 6, 8]
 
-    filter(is_even, range(10)) =>
-      [0, 2, 4, 6, 8]
 
-This can also be written as a list comprehension::
+This can also be written as a list comprehension:
 
-    >>> [x for x in range(10) if is_even(x)]
+    >>> list(x for x in range(10) if is_even(x))
     [0, 2, 4, 6, 8]
 
-:func:`filter` also has a counterpart in the :mod:`itertools` module,
-:func:`itertools.ifilter`, that returns an iterator and can therefore handle
-infinite sequences just as :func:`itertools.imap` can.
+``functools.reduce(func, iter, [initial_value])`` cumulatively performs an
+operation on all the iterable's elements and, therefore, can't be applied to
+infinite iterables.  ``func`` must be a function that takes two elements and
+returns a single value.  :func:`functools.reduce` takes the first two elements A
+and B returned by the iterator and calculates ``func(A, B)``.  It then requests
+the third element, C, calculates ``func(func(A, B), C)``, combines this result
+with the fourth element returned, and continues until the iterable is exhausted.
+If the iterable returns no values at all, a :exc:`TypeError` exception is
+raised.  If the initial value is supplied, it's used as a starting point and
+``func(initial_value, A)`` is the first calculation. ::
+
 
 ``reduce(func, iter, [initial_value])`` doesn't have a counterpart in the
 :mod:`itertools` module because it cumulatively performs an operation on all the
@@ -672,48 +683,49 @@
 supplied, it's used as a starting point and ``func(initial_value, A)`` is the
 first calculation.
 
-::
-
-    import operator
-    reduce(operator.concat, ['A', 'BB', 'C']) =>
-      'ABBC'
-    reduce(operator.concat, []) =>
-      TypeError: reduce() of empty sequence with no initial value
-    reduce(operator.mul, [1,2,3], 1) =>
-      6
-    reduce(operator.mul, [], 1) =>
-      1
+    >>> import operator
+    >>> reduce(operator.concat, ['A', 'BB', 'C'])
+    'ABBC'
+    >>> reduce(operator.concat, [])
+    Traceback (most recent call last):
+      ...
+    TypeError: reduce() of empty sequence with no initial value
+    >>> reduce(operator.mul, [1,2,3], 1)
+    6
+    >>> reduce(operator.mul, [], 1)
+    1
 
 If you use :func:`operator.add` with :func:`reduce`, you'll add up all the
 elements of the iterable.  This case is so common that there's a special
-built-in called :func:`sum` to compute it::
+built-in called :func:`sum` to compute it:
 
-    reduce(operator.add, [1,2,3,4], 0) =>
-      10
-    sum([1,2,3,4]) =>
-      10
-    sum([]) =>
-      0
+    >>> reduce(operator.add, [1,2,3,4], 0)
+    10
+    >>> sum([1,2,3,4])
+    10
+    >>> sum([])
+    0
 
 For many uses of :func:`reduce`, though, it can be clearer to just write the
 obvious :keyword:`for` loop::
 
-    # Instead of:
-    product = reduce(operator.mul, [1,2,3], 1)
+   # Instead of:
+   product = functools.reduce(operator.mul, [1,2,3], 1)
 
-    # You can write:
-    product = 1
-    for i in [1,2,3]:
-        product *= i
+   # You can write:
+   product = 1
+   for i in [1,2,3]:
+       product *= i
 
 
 ``enumerate(iter)`` counts off the elements in the iterable, returning 2-tuples
-containing the count and each element.
-
-::
+containing the count and each element. ::
 
-    enumerate(['subject', 'verb', 'object']) =>
-      (0, 'subject'), (1, 'verb'), (2, 'object')
+    >>> for item in enumerate(['subject', 'verb', 'object']):
+    ...     print item
+    (0, 'subject')
+    (1, 'verb')
+    (2, 'object')
 
 :func:`enumerate` is often used when looping through a list and recording the
 indexes at which certain conditions are met::
@@ -723,22 +735,21 @@
         if line.strip() == '':
             print('Blank line at line #%i' % i)
 
+
 ``sorted(iterable, [cmp=None], [key=None], [reverse=False)`` collects all the
 elements of the iterable into a list, sorts the list, and returns the sorted
 result.  The ``cmp``, ``key``, and ``reverse`` arguments are passed through to
-the constructed list's ``.sort()`` method.
-
-::
+the constructed list's ``.sort()`` method. ::
 
-    import random
-    # Generate 8 random numbers between [0, 10000)
-    rand_list = random.sample(range(10000), 8)
-    rand_list =>
-      [769, 7953, 9828, 6431, 8442, 9878, 6213, 2207]
-    sorted(rand_list) =>
-      [769, 2207, 6213, 6431, 7953, 8442, 9828, 9878]
-    sorted(rand_list, reverse=True) =>
-      [9878, 9828, 8442, 7953, 6431, 6213, 2207, 769]
+    >>> import random
+    >>> # Generate 8 random numbers between [0, 10000)
+    >>> rand_list = random.sample(range(10000), 8)
+    >>> rand_list
+    [769, 7953, 9828, 6431, 8442, 9878, 6213, 2207]
+    >>> sorted(rand_list)
+    [769, 2207, 6213, 6431, 7953, 8442, 9828, 9878]
+    >>> sorted(rand_list, reverse=True)
+    [9878, 9828, 8442, 7953, 6431, 6213, 2207, 769]
 
 (For a more detailed discussion of sorting, see the Sorting mini-HOWTO in the
 Python wiki at http://wiki.python.org/moin/HowTo/Sorting.)
@@ -746,20 +757,20 @@
 The ``any(iter)`` and ``all(iter)`` built-ins look at the truth values of an
 iterable's contents.  :func:`any` returns True if any element in the iterable is
 a true value, and :func:`all` returns True if all of the elements are true
-values::
+values:
 
-    any([0,1,0]) =>
-      True
-    any([0,0,0]) =>
-      False
-    any([1,1,1]) =>
-      True
-    all([0,1,0]) =>
-      False
-    all([0,0,0]) => 
-      False
-    all([1,1,1]) =>
-      True
+    >>> any([0,1,0])
+    True
+    >>> any([0,0,0])
+    False
+    >>> any([1,1,1])
+    True
+    >>> all([0,1,0])
+    False
+    >>> all([0,0,0]) 
+    False
+    >>> all([1,1,1])
+    True
 
 
 Small functions and the lambda expression
@@ -771,31 +782,31 @@
 If there's a Python built-in or a module function that's suitable, you don't
 need to define a new function at all::
 
-        stripped_lines = [line.strip() for line in lines]
-        existing_files = filter(os.path.exists, file_list)
+    stripped_lines = [line.strip() for line in lines]
+    existing_files = filter(os.path.exists, file_list)
 
 If the function you need doesn't exist, you need to write it.  One way to write
 small functions is to use the ``lambda`` statement.  ``lambda`` takes a number
 of parameters and an expression combining these parameters, and creates a small
 function that returns the value of the expression::
 
-        lowercase = lambda x: x.lower()
+    lowercase = lambda x: x.lower()
 
-        print_assign = lambda name, value: name + '=' + str(value)
+    print_assign = lambda name, value: name + '=' + str(value)
 
-        adder = lambda x, y: x+y
+    adder = lambda x, y: x+y
 
 An alternative is to just use the ``def`` statement and define a function in the
 usual way::
 
-        def lowercase(x):
-            return x.lower()
+    def lowercase(x):
+        return x.lower()
 
-        def print_assign(name, value):
-            return name + '=' + str(value)
+    def print_assign(name, value):
+        return name + '=' + str(value)
 
-        def adder(x,y):
-            return x + y
+    def adder(x,y):
+        return x + y
 
 Which alternative is preferable?  That's a style question; my usual course is to
 avoid using ``lambda``.
@@ -842,8 +853,8 @@
 4) Convert the lambda to a def statement, using that name.
 5) Remove the comment.
 
-I really like these rules, but you're free to disagree that this lambda-free
-style is better.
+I really like these rules, but you're free to disagree 
+about whether this lambda-free style is better.
 
 
 The itertools module
@@ -866,24 +877,20 @@
 ``itertools.count(n)`` returns an infinite stream of integers, increasing by 1
 each time.  You can optionally supply the starting number, which defaults to 0::
 
-        itertools.count() =>
-          0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
-        itertools.count(10) =>
-          10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ...
+    itertools.count() =>
+      0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
+    itertools.count(10) =>
+      10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ...
 
 ``itertools.cycle(iter)`` saves a copy of the contents of a provided iterable
 and returns a new iterator that returns its elements from first to last.  The
-new iterator will repeat these elements infinitely.
+new iterator will repeat these elements infinitely. ::
 
-::
-
-        itertools.cycle([1,2,3,4,5]) =>
-          1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
+    itertools.cycle([1,2,3,4,5]) =>
+      1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
 
 ``itertools.repeat(elem, [n])`` returns the provided element ``n`` times, or
-returns the element endlessly if ``n`` is not provided.
-
-::
+returns the element endlessly if ``n`` is not provided. ::
 
     itertools.repeat('abc') =>
       abc, abc, abc, abc, abc, abc, abc, abc, abc, abc, ...
@@ -892,9 +899,7 @@
 
 ``itertools.chain(iterA, iterB, ...)`` takes an arbitrary number of iterables as
 input, and returns all the elements of the first iterator, then all the elements
-of the second, and so on, until all of the iterables have been exhausted.
-
-::
+of the second, and so on, until all of the iterables have been exhausted. ::
 
     itertools.chain(['a', 'b', 'c'], (1, 2, 3)) =>
       a, b, c, 1, 2, 3
@@ -905,7 +910,7 @@
     itertools.izip(['a', 'b', 'c'], (1, 2, 3)) =>
       ('a', 1), ('b', 2), ('c', 3)
 
-It's similiar to the built-in :func:`zip` function, but doesn't construct an
+It's similar to the built-in :func:`zip` function, but doesn't construct an
 in-memory list and exhaust all the input iterators before returning; instead
 tuples are constructed and returned only if they're requested.  (The technical
 term for this behaviour is `lazy evaluation
@@ -913,9 +918,7 @@
 
 This iterator is intended to be used with iterables that are all of the same
 length.  If the iterables are of different lengths, the resulting stream will be
-the same length as the shortest iterable.
-
-::
+the same length as the shortest iterable. ::
 
     itertools.izip(['a', 'b'], (1, 2, 3)) =>
       ('a', 1), ('b', 2)
@@ -929,9 +932,7 @@
 first ``stop`` elements.  If you supply a starting index, you'll get
 ``stop-start`` elements, and if you supply a value for ``step``, elements will
 be skipped accordingly.  Unlike Python's string and list slicing, you can't use
-negative values for ``start``, ``stop``, or ``step``.
-
-::
+negative values for ``start``, ``stop``, or ``step``. ::
 
     itertools.islice(range(10), 8) =>
       0, 1, 2, 3, 4, 5, 6, 7
@@ -945,9 +946,7 @@
 If you don't supply a value for ``n``, the default is 2.  Replicating iterators
 requires saving some of the contents of the source iterator, so this can consume
 significant memory if the iterator is large and one of the new iterators is
-consumed more than the others.
-
-::
+consumed more than the others. ::
 
         itertools.tee( itertools.count() ) =>
            iterA, iterB
@@ -962,14 +961,7 @@
 Calling functions on elements
 -----------------------------
 
-Two functions are used for calling other functions on the contents of an
-iterable.
-
-``itertools.imap(f, iterA, iterB, ...)`` returns a stream containing
-``f(iterA[0], iterB[0]), f(iterA[1], iterB[1]), f(iterA[2], iterB[2]), ...``::
-
-    itertools.imap(operator.add, [5, 6, 5], [1, 2, 3]) =>
-      6, 8, 8
+``itertools.imap(func, iter)`` is the same as built-in :func:`map`.
 
 The ``operator`` module contains a set of functions corresponding to Python's
 operators.  Some examples are ``operator.add(a, b)`` (adds two values),
@@ -992,14 +984,7 @@
 Another group of functions chooses a subset of an iterator's elements based on a
 predicate.
 
-``itertools.ifilter(predicate, iter)`` returns all the elements for which the
-predicate returns true::
-
-    def is_even(x):
-        return (x % 2) == 0
-
-    itertools.ifilter(is_even, itertools.count()) =>
-      0, 2, 4, 6, 8, 10, 12, 14, ...
+``itertools.ifilter(predicate, iter)`` is the same as built-in :func:`filter`.
 
 ``itertools.ifilterfalse(predicate, iter)`` is the opposite, returning all
 elements for which the predicate returns false::
@@ -1117,8 +1102,7 @@
 
 Some of the functions in this module are:
 
-* Math operations: ``add()``, ``sub()``, ``mul()``, ``div()``, ``floordiv()``,
-  ``abs()``, ...
+* Math operations: ``add()``, ``sub()``, ``mul()``, ``floordiv()``, ``abs()``, ...
 * Logical operations: ``not_()``, ``truth()``.
 * Bitwise operations: ``and_()``, ``or_()``, ``invert()``.
 * Comparisons: ``eq()``, ``ne()``, ``lt()``, ``le()``, ``gt()``, and ``ge()``.
@@ -1144,87 +1128,76 @@
 
 The ``compose()`` function implements function composition.  In other words, it
 returns a wrapper around the ``outer`` and ``inner`` callables, such that the
-return value from ``inner`` is fed directly to ``outer``.  That is,
-
-::
+return value from ``inner`` is fed directly to ``outer``.  That is, ::
 
-        >>> def add(a, b):
-        ...     return a + b
-        ...
-        >>> def double(a):
-        ...     return 2 * a
-        ...
-        >>> compose(double, add)(5, 6)
-        22
+    >>> def add(a, b):
+    ...     return a + b
+    ...
+    >>> def double(a):
+    ...     return 2 * a
+    ...
+    >>> compose(double, add)(5, 6)
+    22
 
-is equivalent to
-
-::
+is equivalent to ::
 
-        >>> double(add(5, 6))
-        22
+    >>> double(add(5, 6))
+    22
                     
 The ``unpack`` keyword is provided to work around the fact that Python functions
 are not always `fully curried <http://en.wikipedia.org/wiki/Currying>`__.  By
 default, it is expected that the ``inner`` function will return a single object
 and that the ``outer`` function will take a single argument. Setting the
 ``unpack`` argument causes ``compose`` to expect a tuple from ``inner`` which
-will be expanded before being passed to ``outer``. Put simply,
+will be expanded before being passed to ``outer``. Put simply, ::
 
-::
-
-        compose(f, g)(5, 6)
+    compose(f, g)(5, 6)
                     
 is equivalent to::
 
-        f(g(5, 6))
+    f(g(5, 6))
                     
-while
-
-::
+while ::
 
-        compose(f, g, unpack=True)(5, 6)
+    compose(f, g, unpack=True)(5, 6)
                     
 is equivalent to::
 
-        f(*g(5, 6))
+    f(*g(5, 6))
 
 Even though ``compose()`` only accepts two functions, it's trivial to build up a
-version that will compose any number of functions. We'll use ``reduce()``,
+version that will compose any number of functions. We'll use ``functools.reduce()``,
 ``compose()`` and ``partial()`` (the last of which is provided by both
-``functional`` and ``functools``).
+``functional`` and ``functools``). ::
 
-::
-
-        from functional import compose, partial
+    from functional import compose, partial
         
-        multi_compose = partial(reduce, compose)
+
+    multi_compose = partial(reduce, compose)
         
     
 We can also use ``map()``, ``compose()`` and ``partial()`` to craft a version of
 ``"".join(...)`` that converts its arguments to string::
 
-        from functional import compose, partial
+    from functional import compose, partial
         
-        join = compose("".join, partial(map, str))
+    join = compose("".join, partial(map, str))
 
 
 ``flip(func)``
                     
 ``flip()`` wraps the callable in ``func`` and causes it to receive its
-non-keyword arguments in reverse order.
-
-::
+non-keyword arguments in reverse order. ::
 
-        >>> def triple(a, b, c):
-        ...     return (a, b, c)
-        ...
-        >>> triple(5, 6, 7)
-        (5, 6, 7)
-        >>>
-        >>> flipped_triple = flip(triple)
-        >>> flipped_triple(5, 6, 7)
-        (7, 6, 5)
+    >>> def triple(a, b, c):
+    ...     return (a, b, c)
+    ...
+    >>> triple(5, 6, 7)
+    (5, 6, 7)
+    >>>
+    >>> flipped_triple = flip(triple)
+    >>> flipped_triple(5, 6, 7)
+    (7, 6, 5)
 
 ``foldl(func, start, iterable)``
                     
@@ -1235,35 +1208,34 @@
 
 This means that a call such as::
 
-        foldl(f, 0, [1, 2, 3])
+    foldl(f, 0, [1, 2, 3])
 
 is equivalent to::
 
-        f(f(f(0, 1), 2), 3)
+    f(f(f(0, 1), 2), 3)
 
     
 ``foldl()`` is roughly equivalent to the following recursive function::
 
-        def foldl(func, start, seq):
-            if len(seq) == 0:
-                return start
+    def foldl(func, start, seq):
+        if len(seq) == 0:
+            return start
 
-            return foldl(func, func(start, seq[0]), seq[1:])
+        return foldl(func, func(start, seq[0]), seq[1:])
 
 Speaking of equivalence, the above ``foldl`` call can be expressed in terms of
 the built-in ``reduce`` like so::
 
-        reduce(f, [1, 2, 3], 0)
+    reduce(f, [1, 2, 3], 0)
 
 
 We can use ``foldl()``, ``operator.concat()`` and ``partial()`` to write a
 cleaner, more aesthetically-pleasing version of Python's ``"".join(...)``
 idiom::
 
-        from functional import foldl, partial
-        from operator import concat
-        
-        join = partial(foldl, concat, "")
+    from functional import foldl, partial from operator import concat
+
+    join = partial(foldl, concat, "")
 
 
 Revision History and Acknowledgements

Modified: python/branches/py3k-importlib/Doc/howto/index.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/howto/index.rst	(original)
+++ python/branches/py3k-importlib/Doc/howto/index.rst	Thu Mar 27 00:48:05 2008
@@ -14,7 +14,6 @@
    :maxdepth: 1
 
    advocacy.rst
-   pythonmac.rst
    curses.rst
    doanddont.rst
    functional.rst

Deleted: /python/branches/py3k-importlib/Doc/howto/pythonmac.rst
==============================================================================
--- /python/branches/py3k-importlib/Doc/howto/pythonmac.rst	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,202 +0,0 @@
-
-.. _using-on-mac:
-
-***************************
-Using Python on a Macintosh
-***************************
-
-:Author: Bob Savage <bobsavage at mac.com>
-
-
-Python on a Macintosh running Mac OS X is in principle very similar to Python on
-any other Unix platform, but there are a number of additional features such as
-the IDE and the Package Manager that are worth pointing out.
-
-The Mac-specific modules are documented in :ref:`mac-specific-services`.
-
-Python on Mac OS 9 or earlier can be quite different from Python on Unix or
-Windows, but is beyond the scope of this manual, as that platform is no longer
-supported, starting with Python 2.4. See http://www.cwi.nl/~jack/macpython for
-installers for the latest 2.3 release for Mac OS 9 and related documentation.
-
-
-.. _getting-osx:
-
-Getting and Installing MacPython
-================================
-
-Mac OS X 10.4 comes with Python 2.3 pre-installed by Apple. However, you are
-encouraged to install the most recent version of Python from the Python website
-(http://www.python.org). A "universal binary" build of Python 2.5, which runs
-natively on the Mac's new Intel and legacy PPC CPU's, is available there.
-
-What you get after installing is a number of things:
-
-* A :file:`MacPython 2.5` folder in your :file:`Applications` folder. In here
-  you find IDLE, the development environment that is a standard part of official
-  Python distributions; PythonLauncher, which handles double-clicking Python
-  scripts from the Finder; and the "Build Applet" tool, which allows you to
-  package Python scripts as standalone applications on your system.
-
-* A framework :file:`/Library/Frameworks/Python.framework`, which includes the
-  Python executable and libraries. The installer adds this location to your shell
-  path. To uninstall MacPython, you can simply remove these three things. A
-  symlink to the Python executable is placed in /usr/local/bin/.
-
-The Apple-provided build of Python is installed in
-:file:`/System/Library/Frameworks/Python.framework` and :file:`/usr/bin/python`,
-respectively. You should never modify or delete these, as they are
-Apple-controlled and are used by Apple- or third-party software.
-
-IDLE includes a help menu that allows you to access Python documentation. If you
-are completely new to Python you should start reading the tutorial introduction
-in that document.
-
-If you are familiar with Python on other Unix platforms you should read the
-section on running Python scripts from the Unix shell.
-
-
-How to run a Python script
---------------------------
-
-Your best way to get started with Python on Mac OS X is through the IDLE
-integrated development environment, see section :ref:`ide` and use the Help menu
-when the IDE is running.
-
-If you want to run Python scripts from the Terminal window command line or from
-the Finder you first need an editor to create your script. Mac OS X comes with a
-number of standard Unix command line editors, :program:`vim` and
-:program:`emacs` among them. If you want a more Mac-like editor,
-:program:`BBEdit` or :program:`TextWrangler` from Bare Bones Software (see
-http://www.barebones.com/products/bbedit/index.shtml) are good choices, as is
-:program:`TextMate` (see http://macromates.com/). Other editors include
-:program:`Gvim` (http://macvim.org) and :program:`Aquamacs`
-(http://aquamacs.org).
-
-To run your script from the Terminal window you must make sure that
-:file:`/usr/local/bin` is in your shell search path.
-
-To run your script from the Finder you have two options:
-
-* Drag it to :program:`PythonLauncher`
-
-* Select :program:`PythonLauncher` as the default application to open your
-  script (or any .py script) through the finder Info window and double-click it.
-  :program:`PythonLauncher` has various preferences to control how your script is
-  launched. Option-dragging allows you to change these for one invocation, or use
-  its Preferences menu to change things globally.
-
-
-.. _osx-gui-scripts:
-
-Running scripts with a GUI
---------------------------
-
-With older versions of Python, there is one Mac OS X quirk that you need to be
-aware of: programs that talk to the Aqua window manager (in other words,
-anything that has a GUI) need to be run in a special way. Use :program:`pythonw`
-instead of :program:`python` to start such scripts.
-
-With Python 2.5, you can use either :program:`python` or :program:`pythonw`.
-
-
-Configuration
--------------
-
-Python on OS X honors all standard Unix environment variables such as
-:envvar:`PYTHONPATH`, but setting these variables for programs started from the
-Finder is non-standard as the Finder does not read your :file:`.profile` or
-:file:`.cshrc` at startup. You need to create a file :file:`~
-/.MacOSX/environment.plist`. See Apple's Technical Document QA1067 for details.
-
-For more information on installation Python packages in MacPython, see section
-:ref:`mac-package-manager`.
-
-
-.. _ide:
-
-The IDE
-=======
-
-MacPython ships with the standard IDLE development environment. A good
-introduction to using IDLE can be found at http://hkn.eecs.berkeley.edu/
-dyoo/python/idle_intro/index.html.
-
-
-.. _mac-package-manager:
-
-Installing Additional Python Packages
-=====================================
-
-There are several methods to install additional Python packages:
-
-* http://pythonmac.org/packages/ contains selected compiled packages for Python
-  2.5, 2.4, and 2.3.
-
-* Packages can be installed via the standard Python distutils mode (``python
-  setup.py install``).
-
-* Many packages can also be installed via the :program:`setuptools` extension.
-
-
-GUI Programming on the Mac
-==========================
-
-There are several options for building GUI applications on the Mac with Python.
-
-*PyObjC* is a Python binding to Apple's Objective-C/Cocoa framework, which is
-the foundation of most modern Mac development. Information on PyObjC is
-available from http://pyobjc.sourceforge.net.
-
-The standard Python GUI toolkit is :mod:`Tkinter`, based on the cross-platform
-Tk toolkit (http://www.tcl.tk). An Aqua-native version of Tk is bundled with OS
-X by Apple, and the latest version can be downloaded and installed from
-http://www.activestate.com; it can also be built from source.
-
-*wxPython* is another popular cross-platform GUI toolkit that runs natively on
-Mac OS X. Packages and documentation are available from http://www.wxpython.org.
-
-*PyQt* is another popular cross-platform GUI toolkit that runs natively on Mac
-OS X. More information can be found at
-http://www.riverbankcomputing.co.uk/pyqt/.
-
-
-Distributing Python Applications on the Mac
-===========================================
-
-The "Build Applet" tool that is placed in the MacPython 2.5 folder is fine for
-packaging small Python scripts on your own machine to run as a standard Mac
-application. This tool, however, is not robust enough to distribute Python
-applications to other users.
-
-The standard tool for deploying standalone Python applications on the Mac is
-:program:`py2app`. More information on installing and using py2app can be found
-at http://undefined.org/python/#py2app.
-
-
-Application Scripting
-=====================
-
-Python can also be used to script other Mac applications via Apple's Open
-Scripting Architecture (OSA); see http://appscript.sourceforge.net. Appscript is
-a high-level, user-friendly Apple event bridge that allows you to control
-scriptable Mac OS X applications using ordinary Python scripts. Appscript makes
-Python a serious alternative to Apple's own *AppleScript* language for
-automating your Mac. A related package, *PyOSA*, is an OSA language component
-for the Python scripting language, allowing Python code to be executed by any
-OSA-enabled application (Script Editor, Mail, iTunes, etc.). PyOSA makes Python
-a full peer to AppleScript.
-
-
-Other Resources
-===============
-
-The MacPython mailing list is an excellent support resource for Python users and
-developers on the Mac:
-
-http://www.python.org/community/sigs/current/pythonmac-sig/
-
-Another useful resource is the MacPython wiki:
-
-http://wiki.python.org/moin/MacPython
-

Modified: python/branches/py3k-importlib/Doc/howto/regex.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/howto/regex.rst	(original)
+++ python/branches/py3k-importlib/Doc/howto/regex.rst	Thu Mar 27 00:48:05 2008
@@ -1,3 +1,5 @@
+.. _regex-howto:
+
 ****************************
   Regular Expression HOWTO
 ****************************
@@ -5,11 +7,11 @@
 :Author: A.M. Kuchling
 :Release: 0.05
 
-.. % TODO:
-.. % Document lookbehind assertions
-.. % Better way of displaying a RE, a string, and what it matches
-.. % Mention optional argument to match.groups()
-.. % Unicode (at least a reference)
+.. TODO:
+   Document lookbehind assertions
+   Better way of displaying a RE, a string, and what it matches
+   Mention optional argument to match.groups()
+   Unicode (at least a reference)
 
 
 .. topic:: Abstract
@@ -91,8 +93,6 @@
 characters.  If you wanted to match only lowercase letters, your RE would be
 ``[a-z]``.
 
-.. % $
-
 Metacharacters are not active inside classes.  For example, ``[akm$]`` will
 match any of the characters ``'a'``, ``'k'``, ``'m'``, or ``'$'``; ``'$'`` is
 usually a metacharacter, but inside a character class it's stripped of its
@@ -203,7 +203,7 @@
 |      |           | ``bc``.                         |
 +------+-----------+---------------------------------+
 | 6    | ``abcb``  | Try ``b`` again.  This time     |
-|      |           | but the character at the        |
+|      |           | the character at the            |
 |      |           | current position is ``'b'``, so |
 |      |           | it succeeds.                    |
 +------+-----------+---------------------------------+
@@ -337,9 +337,8 @@
 
 Once you have an object representing a compiled regular expression, what do you
 do with it?  :class:`RegexObject` instances have several methods and attributes.
-Only the most significant ones will be covered here; consult `the Library
-Reference <http://www.python.org/doc/lib/module-re.html>`_ for a complete
-listing.
+Only the most significant ones will be covered here; consult the :mod:`re` docs
+for a complete listing.
 
 +------------------+-----------------------------------------------+
 | Method/Attribute | Purpose                                       |
@@ -354,7 +353,7 @@
 |                  | returns them as a list.                       |
 +------------------+-----------------------------------------------+
 | ``finditer()``   | Find all substrings where the RE matches, and |
-|                  | returns them as an iterator.                  |
+|                  | returns them as an :term:`iterator`.          |
 +------------------+-----------------------------------------------+
 
 :meth:`match` and :meth:`search` return ``None`` if no match can be found.  If
@@ -368,8 +367,8 @@
 Python distribution.  It allows you to enter REs and strings, and displays
 whether the RE matches or fails. :file:`redemo.py` can be quite useful when
 trying to debug a complicated RE.  Phil Schwartz's `Kodos
-<http://www.phil-schwartz.com/kodos.spy>`_ is also an interactive tool for
-developing and testing RE patterns.
+<http://kodos.sourceforge.net/>`_ is also an interactive tool for developing and
+testing RE patterns.
 
 This HOWTO uses the standard Python interpreter for its examples. First, run the
 Python interpreter, import the :mod:`re` module, and compile a RE::
@@ -460,7 +459,7 @@
 
 :meth:`findall` has to create the entire list before it can be returned as the
 result.  The :meth:`finditer` method returns a sequence of :class:`MatchObject`
-instances as an iterator. [#]_ ::
+instances as an :term:`iterator`. [#]_ ::
 
    >>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...')
    >>> iterator
@@ -500,7 +499,7 @@
 the same ones in several locations, then it might be worthwhile to collect all
 the definitions in one place, in a section of code that compiles all the REs
 ahead of time.  To take an example from the standard library, here's an extract
-from :file:`xmllib.py`::
+from the now deprecated :file:`xmllib.py`::
 
    ref = re.compile( ... )
    entityref = re.compile( ... )
@@ -679,8 +678,8 @@
       >>> print(re.search('^From', 'Reciting From Memory'))
       None
 
-   .. % To match a literal \character{\^}, use \regexp{\e\^} or enclose it
-   .. % inside a character class, as in \regexp{[{\e}\^]}.
+   .. To match a literal \character{\^}, use \regexp{\e\^} or enclose it
+   .. inside a character class, as in \regexp{[{\e}\^]}.
 
 ``$``
    Matches at the end of a line, which is defined as either the end of the string,
@@ -696,8 +695,6 @@
    To match a literal ``'$'``, use ``\$`` or enclose it inside a character class,
    as in  ``[$]``.
 
-   .. % $
-
 ``\A``
    Matches only at the start of the string.  When not in :const:`MULTILINE` mode,
    ``\A`` and ``^`` are effectively the same.  In :const:`MULTILINE` mode, they're
@@ -980,12 +977,8 @@
 that the first character of the extension is not a ``b``.  This is wrong,
 because the pattern also doesn't match ``foo.bar``.
 
-.. % $
-
 ``.*[.]([^b]..|.[^a].|..[^t])$``
 
-.. % Messes up the HTML without the curly braces around \^
-
 The expression gets messier when you try to patch up the first solution by
 requiring one of the following cases to match: the first character of the
 extension isn't ``b``; the second character isn't ``a``; or the third character
@@ -1013,16 +1006,12 @@
 that something like ``sample.batch``, where the extension only starts with
 ``bat``, will be allowed.
 
-.. % $
-
 Excluding another filename extension is now easy; simply add it as an
 alternative inside the assertion.  The following pattern excludes filenames that
 end in either ``bat`` or ``exe``:
 
 ``.*[.](?!bat$|exe$).*$``
 
-.. % $
-
 
 Modifying Strings
 =================
@@ -1343,16 +1332,10 @@
     \s*$                # Trailing whitespace to end-of-line
    """, re.VERBOSE)
 
-This is far more readable than:
-
-.. % $
-
-::
+This is far more readable than::
 
    pat = re.compile(r"\s*(?P<header>[^:]+)\s*:(?P<value>.*?)\s*$")
 
-.. % $
-
 
 Feedback
 ========

Modified: python/branches/py3k-importlib/Doc/howto/sockets.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/howto/sockets.rst	(original)
+++ python/branches/py3k-importlib/Doc/howto/sockets.rst	Thu Mar 27 00:48:05 2008
@@ -354,7 +354,7 @@
 reason to do otherwise.
 
 In return, you will get three lists. They have the sockets that are actually
-readable, writable and in error. Each of these lists is a subset (possbily
+readable, writable and in error. Each of these lists is a subset (possibly
 empty) of the corresponding list you passed in. And if you put a socket in more
 than one input list, it will only be (at most) in one output list.
 
@@ -368,7 +368,7 @@
 If you have a "server" socket, put it in the potential_readers list. If it comes
 out in the readable list, your ``accept`` will (almost certainly) work. If you
 have created a new socket to ``connect`` to someone else, put it in the
-ptoential_writers list. If it shows up in the writable list, you have a decent
+potential_writers list. If it shows up in the writable list, you have a decent
 chance that it has connected.
 
 One very nasty problem with ``select``: if somewhere in those input lists of

Modified: python/branches/py3k-importlib/Doc/howto/unicode.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/howto/unicode.rst	(original)
+++ python/branches/py3k-importlib/Doc/howto/unicode.rst	Thu Mar 27 00:48:05 2008
@@ -216,10 +216,6 @@
 to reading the Unicode character tables, available at
 <http://www.cs.tut.fi/~jkorpela/unicode/guide.html>.
 
-Roman Czyborra wrote another explanation of Unicode's basic principles; it's at
-<http://czyborra.com/unicode/characters.html>.  Czyborra has written a number of
-other Unicode-related documentation, available from <http://www.cyzborra.com>.
-
 Two other good introductory articles were written by Joel Spolsky
 <http://www.joelonsoftware.com/articles/Unicode.html> and Jason Orendorff
 <http://www.jorendorff.com/articles/unicode/>.  If this introduction didn't make
@@ -237,129 +233,83 @@
 Now that you've learned the rudiments of Unicode, we can look at Python's
 Unicode features.
 
+The String Type
+---------------
 
-The Unicode Type
-----------------
-
-Unicode strings are expressed as instances of the :class:`unicode` type, one of
-Python's repertoire of built-in types.  It derives from an abstract type called
-:class:`basestring`, which is also an ancestor of the :class:`str` type; you can
-therefore check if a value is a string type with ``isinstance(value,
-basestring)``.  Under the hood, Python represents Unicode strings as either 16-
-or 32-bit integers, depending on how the Python interpreter was compiled.
-
-The :func:`unicode` constructor has the signature ``unicode(string[, encoding,
-errors])``.  All of its arguments should be 8-bit strings.  The first argument
-is converted to Unicode using the specified encoding; if you leave off the
-``encoding`` argument, the ASCII encoding is used for the conversion, so
-characters greater than 127 will be treated as errors::
-
-    >>> unicode('abcdef')
-    u'abcdef'
-    >>> s = unicode('abcdef')
-    >>> type(s)
-    <type 'unicode'>
-    >>> unicode('abcdef' + chr(255))
-    Traceback (most recent call last):
-      File "<stdin>", line 1, in ?
-    UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 6:
-                        ordinal not in range(128)
+Since Python 3.0, the language features a ``str`` type that contain Unicode
+characters, meaning any string created using ``"unicode rocks!"``, ``'unicode
+rocks!``, or the triple-quoted string syntax is stored as Unicode.
+
+To insert a Unicode character that is not part ASCII, e.g., any letters with
+accents, one can use escape sequences in their string literals as such::
+
+   >>> "\N{GREEK CAPITAL LETTER DELTA}"  # Using the character name
+   '\u0394'
+   >>> "\u0394"                          # Using a 16-bit hex value
+   '\u0394'
+   >>> "\U00000394"                      # Using a 32-bit hex value
+   '\u0394'
+
+In addition, one can create a string using the :func:`decode` method of
+:class:`bytes`.  This method takes an encoding, such as UTF-8, and, optionally,
+an *errors* argument.
 
-The ``errors`` argument specifies the response when the input string can't be
+The *errors* argument specifies the response when the input string can't be
 converted according to the encoding's rules.  Legal values for this argument are
-'strict' (raise a ``UnicodeDecodeError`` exception), 'replace' (add U+FFFD,
+'strict' (raise a :exc:`UnicodeDecodeError` exception), 'replace' (add U+FFFD,
 'REPLACEMENT CHARACTER'), or 'ignore' (just leave the character out of the
 Unicode result).  The following examples show the differences::
 
-    >>> unicode('\x80abc', errors='strict')
+    >>> b'\x80abc'.decode("utf-8", "strict")
     Traceback (most recent call last):
       File "<stdin>", line 1, in ?
     UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0:
                         ordinal not in range(128)
-    >>> unicode('\x80abc', errors='replace')
-    u'\ufffdabc'
-    >>> unicode('\x80abc', errors='ignore')
-    u'abc'
+    >>> b'\x80abc'.decode("utf-8", "replace")
+    '\ufffdabc'
+    >>> b'\x80abc'.decode("utf-8", "ignore")
+    'abc'
 
-Encodings are specified as strings containing the encoding's name.  Python 2.4
+Encodings are specified as strings containing the encoding's name.  Python
 comes with roughly 100 different encodings; see the Python Library Reference at
-<http://docs.python.org/lib/standard-encodings.html> for a list.  Some encodings
+:ref:`standard-encodings` for a list.  Some encodings
 have multiple names; for example, 'latin-1', 'iso_8859_1' and '8859' are all
 synonyms for the same encoding.
 
-One-character Unicode strings can also be created with the :func:`unichr`
+One-character Unicode strings can also be created with the :func:`chr`
 built-in function, which takes integers and returns a Unicode string of length 1
 that contains the corresponding code point.  The reverse operation is the
 built-in :func:`ord` function that takes a one-character Unicode string and
 returns the code point value::
 
-    >>> unichr(40960)
-    u'\ua000'
-    >>> ord(u'\ua000')
+    >>> chr(40960)
+    '\ua000'
+    >>> ord('\ua000')
     40960
 
-Instances of the :class:`unicode` type have many of the same methods as the
-8-bit string type for operations such as searching and formatting::
-
-    >>> s = u'Was ever feather so lightly blown to and fro as this multitude?'
-    >>> s.count('e')
-    5
-    >>> s.find('feather')
-    9
-    >>> s.find('bird')
-    -1
-    >>> s.replace('feather', 'sand')
-    u'Was ever sand so lightly blown to and fro as this multitude?'
-    >>> s.upper()
-    u'WAS EVER FEATHER SO LIGHTLY BLOWN TO AND FRO AS THIS MULTITUDE?'
-
-Note that the arguments to these methods can be Unicode strings or 8-bit
-strings.  8-bit strings will be converted to Unicode before carrying out the
-operation; Python's default ASCII encoding will be used, so characters greater
-than 127 will cause an exception::
+Converting to Bytes
+-------------------
 
-    >>> s.find('Was\x9f')
-    Traceback (most recent call last):
-      File "<stdin>", line 1, in ?
-    UnicodeDecodeError: 'ascii' codec can't decode byte 0x9f in position 3: ordinal not in range(128)
-    >>> s.find(u'Was\x9f')
-    -1
-
-Much Python code that operates on strings will therefore work with Unicode
-strings without requiring any changes to the code.  (Input and output code needs
-more updating for Unicode; more on this later.)
-
-Another important method is ``.encode([encoding], [errors='strict'])``, which
-returns an 8-bit string version of the Unicode string, encoded in the requested
-encoding.  The ``errors`` parameter is the same as the parameter of the
-``unicode()`` constructor, with one additional possibility; as well as 'strict',
+Another important str method is ``.encode([encoding], [errors='strict'])``,
+which returns a ``bytes`` representation of the Unicode string, encoded in the
+requested encoding.  The ``errors`` parameter is the same as the parameter of
+the :meth:`decode` method, with one additional possibility; as well as 'strict',
 'ignore', and 'replace', you can also pass 'xmlcharrefreplace' which uses XML's
 character references.  The following example shows the different results::
 
-    >>> u = unichr(40960) + u'abcd' + unichr(1972)
+    >>> u = chr(40960) + 'abcd' + chr(1972)
     >>> u.encode('utf-8')
-    '\xea\x80\x80abcd\xde\xb4'
+    b'\xea\x80\x80abcd\xde\xb4'
     >>> u.encode('ascii')
     Traceback (most recent call last):
       File "<stdin>", line 1, in ?
     UnicodeEncodeError: 'ascii' codec can't encode character '\ua000' in position 0: ordinal not in range(128)
     >>> u.encode('ascii', 'ignore')
-    'abcd'
+    b'abcd'
     >>> u.encode('ascii', 'replace')
-    '?abcd?'
+    b'?abcd?'
     >>> u.encode('ascii', 'xmlcharrefreplace')
-    '&#40960;abcd&#1972;'
-
-Python's 8-bit strings have a ``.decode([encoding], [errors])`` method that
-interprets the string using the given encoding::
-
-    >>> u = unichr(40960) + u'abcd' + unichr(1972)   # Assemble a string
-    >>> utf8_version = u.encode('utf-8')             # Encode as UTF-8
-    >>> type(utf8_version), utf8_version
-    (<type 'str'>, '\xea\x80\x80abcd\xde\xb4')
-    >>> u2 = utf8_version.decode('utf-8')            # Decode using UTF-8
-    >>> u == u2                                      # The two strings match
-    True
+    b'&#40960;abcd&#1972;'
 
 The low-level routines for registering and accessing the available encodings are
 found in the :mod:`codecs` module.  However, the encoding and decoding functions
@@ -377,22 +327,14 @@
 Unicode Literals in Python Source Code
 --------------------------------------
 
-In Python source code, Unicode literals are written as strings prefixed with the
-'u' or 'U' character: ``u'abcdefghijk'``.  Specific code points can be written
-using the ``\u`` escape sequence, which is followed by four hex digits giving
-the code point.  The ``\U`` escape sequence is similar, but expects 8 hex
-digits, not 4.
-
-Unicode literals can also use the same escape sequences as 8-bit strings,
-including ``\x``, but ``\x`` only takes two hex digits so it can't express an
-arbitrary code point.  Octal escapes can go up to U+01ff, which is octal 777.
-
-::
-
-    >>> s = u"a\xac\u1234\u20ac\U00008000"
-               ^^^^ two-digit hex escape
-                   ^^^^^^ four-digit Unicode escape
-                               ^^^^^^^^^^ eight-digit Unicode escape
+In Python source code, specific Unicode code points can be written using the
+``\u`` escape sequence, which is followed by four hex digits giving the code
+point.  The ``\U`` escape sequence is similar, but expects 8 hex digits, not 4::
+
+    >>> s = "a\xac\u1234\u20ac\U00008000"
+              ^^^^ two-digit hex escape
+                   ^^^^^ four-digit Unicode escape
+                              ^^^^^^^^^^ eight-digit Unicode escape
     >>> for c in s:  print(ord(c), end=" ")
     ...
     97 172 4660 8364 32768
@@ -400,7 +342,7 @@
 Using escape sequences for code points greater than 127 is fine in small doses,
 but becomes an annoyance if you're using many accented characters, as you would
 in a program with messages in French or some other accent-using language.  You
-can also assemble strings using the :func:`unichr` built-in function, but this is
+can also assemble strings using the :func:`chr` built-in function, but this is
 even more tedious.
 
 Ideally, you'd want to be able to write literals in your language's natural
@@ -408,14 +350,15 @@
 which would display the accented characters naturally, and have the right
 characters used at runtime.
 
-Python supports writing Unicode literals in any encoding, but you have to
-declare the encoding being used.  This is done by including a special comment as
-either the first or second line of the source file::
+Python supports writing Unicode literals in UTF-8 by default, but you can use
+(almost) any encoding if you declare the encoding being used.  This is done by
+including a special comment as either the first or second line of the source
+file::
 
     #!/usr/bin/env python
     # -*- coding: latin-1 -*-
 
-    u = u'abcdé'
+    u = 'abcdé'
     print(ord(u[-1]))
 
 The syntax is inspired by Emacs's notation for specifying variables local to a
@@ -424,22 +367,8 @@
 them, you must supply the name ``coding`` and the name of your chosen encoding,
 separated by ``':'``.
 
-If you don't include such a comment, the default encoding used will be ASCII.
-Versions of Python before 2.4 were Euro-centric and assumed Latin-1 as a default
-encoding for string literals; in Python 2.4, characters greater than 127 still
-work but result in a warning.  For example, the following program has no
-encoding declaration::
-
-    #!/usr/bin/env python
-    u = u'abcdé'
-    print(ord(u[-1]))
-
-When you run it with Python 2.4, it will output the following warning::
-
-    amk:~$ python p263.py
-    sys:1: DeprecationWarning: Non-ASCII character '\xe9'
-         in file p263.py on line 2, but no encoding declared;
-         see http://www.python.org/peps/pep-0263.html for details
+If you don't include such a comment, the default encoding used will be UTF-8 as
+already mentioned.
 
 
 Unicode Properties
@@ -457,7 +386,7 @@
 
     import unicodedata
 
-    u = unichr(233) + unichr(0x0bf2) + unichr(3972) + unichr(6000) + unichr(13231)
+    u = chr(233) + chr(0x0bf2) + chr(3972) + chr(6000) + chr(13231)
 
     for i, c in enumerate(u):
         print(i, '%04x' % ord(c), unicodedata.category(c), end=" ")
@@ -487,8 +416,8 @@
 References
 ----------
 
-The Unicode and 8-bit string types are described in the Python library reference
-at :ref:`typesseq`.
+The ``str`` type is described in the Python library reference at
+:ref:`typesseq`.
 
 The documentation for the :mod:`unicodedata` module.
 
@@ -496,7 +425,7 @@
 
 Marc-André Lemburg gave a presentation at EuroPython 2002 titled "Python and
 Unicode".  A PDF version of his slides is available at
-<http://www.egenix.com/files/python/Unicode-EPC2002-Talk.pdf>, and is an
+<http://downloads.egenix.com/python/Unicode-EPC2002-Talk.pdf>, and is an
 excellent overview of the design of Python's Unicode features.
 
 
@@ -557,7 +486,7 @@
 writing::
 
     f = codecs.open('test', encoding='utf-8', mode='w+')
-    f.write(u'\u4500 blah blah blah\n')
+    f.write('\u4500 blah blah blah\n')
     f.seek(0)
     print(repr(f.readline()[:1]))
     f.close()
@@ -590,7 +519,7 @@
 usually just provide the Unicode string as the filename, and it will be
 automatically converted to the right encoding for you::
 
-    filename = u'filename\u4500abc'
+    filename = 'filename\u4500abc'
     f = open(filename, 'w')
     f.write('blah\n')
     f.close()
@@ -607,7 +536,7 @@
 path will return the 8-bit versions of the filenames.  For example, assuming the
 default filesystem encoding is UTF-8, running the following program::
 
-	fn = u'filename\u4500abc'
+	fn = 'filename\u4500abc'
 	f = open(fn, 'w')
 	f.close()
 
@@ -619,7 +548,7 @@
 
 	amk:~$ python t.py
 	['.svn', 'filename\xe4\x94\x80abc', ...]
-	[u'.svn', u'filename\u4500abc', ...]
+	['.svn', 'filename\u4500abc', ...]
 
 The first list contains UTF-8-encoded filenames, and the second list contains
 the Unicode versions.
@@ -683,7 +612,7 @@
 
 The PDF slides for Marc-André Lemburg's presentation "Writing Unicode-aware
 Applications in Python" are available at
-<http://www.egenix.com/files/python/LSM2005-Developing-Unicode-aware-applications-in-Python.pdf>
+<http://downloads.egenix.com/python/LSM2005-Developing-Unicode-aware-applications-in-Python.pdf>
 and discuss questions of character encodings as well as how to internationalize
 and localize an application.
 

Modified: python/branches/py3k-importlib/Doc/howto/urllib2.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/howto/urllib2.rst	(original)
+++ python/branches/py3k-importlib/Doc/howto/urllib2.rst	Thu Mar 27 00:48:05 2008
@@ -8,7 +8,7 @@
 
     There is an French translation of an earlier revision of this
     HOWTO, available at `urllib2 - Le Manuel manquant
-    <http://www.voidspace/python/articles/urllib2_francais.shtml>`_.
+    <http://www.voidspace.org.uk/python/articles/urllib2_francais.shtml>`_.
 
  
 

Modified: python/branches/py3k-importlib/Doc/includes/email-unpack.py
==============================================================================
--- python/branches/py3k-importlib/Doc/includes/email-unpack.py	(original)
+++ python/branches/py3k-importlib/Doc/includes/email-unpack.py	Thu Mar 27 00:48:05 2008
@@ -53,7 +53,7 @@
         # email message can't be used to overwrite important files
         filename = part.get_filename()
         if not filename:
-            ext = mimetypes.guess_extension(part.get_type())
+            ext = mimetypes.guess_extension(part.get_content_type())
             if not ext:
                 # Use a generic bag-of-bits extension
                 ext = '.bin'

Modified: python/branches/py3k-importlib/Doc/includes/noddy2.c
==============================================================================
--- python/branches/py3k-importlib/Doc/includes/noddy2.c	(original)
+++ python/branches/py3k-importlib/Doc/includes/noddy2.c	Thu Mar 27 00:48:05 2008
@@ -23,14 +23,14 @@
 
     self = (Noddy *)type->tp_alloc(type, 0);
     if (self != NULL) {
-        self->first = PyString_FromString("");
+        self->first = PyUnicode_FromString("");
         if (self->first == NULL)
           {
             Py_DECREF(self);
             return NULL;
           }
         
-        self->last = PyString_FromString("");
+        self->last = PyUnicode_FromString("");
         if (self->last == NULL)
           {
             Py_DECREF(self);
@@ -90,7 +90,7 @@
     PyObject *args, *result;
 
     if (format == NULL) {
-        format = PyString_FromString("%s %s");
+        format = PyUnicode_FromString("%s %s");
         if (format == NULL)
             return NULL;
     }
@@ -109,7 +109,7 @@
     if (args == NULL)
         return NULL;
 
-    result = PyString_Format(format, args);
+    result = PyUnicode_Format(format, args);
     Py_DECREF(args);
     
     return result;

Modified: python/branches/py3k-importlib/Doc/includes/noddy3.c
==============================================================================
--- python/branches/py3k-importlib/Doc/includes/noddy3.c	(original)
+++ python/branches/py3k-importlib/Doc/includes/noddy3.c	Thu Mar 27 00:48:05 2008
@@ -23,14 +23,14 @@
 
     self = (Noddy *)type->tp_alloc(type, 0);
     if (self != NULL) {
-        self->first = PyString_FromString("");
+        self->first = PyUnicode_FromString("");
         if (self->first == NULL)
           {
             Py_DECREF(self);
             return NULL;
           }
         
-        self->last = PyString_FromString("");
+        self->last = PyUnicode_FromString("");
         if (self->last == NULL)
           {
             Py_DECREF(self);
@@ -93,7 +93,7 @@
     return -1;
   }
   
-  if (! PyString_Check(value)) {
+  if (! PyUnicode_Check(value)) {
     PyErr_SetString(PyExc_TypeError, 
                     "The first attribute value must be a string");
     return -1;
@@ -121,7 +121,7 @@
     return -1;
   }
   
-  if (! PyString_Check(value)) {
+  if (! PyUnicode_Check(value)) {
     PyErr_SetString(PyExc_TypeError, 
                     "The last attribute value must be a string");
     return -1;
@@ -153,7 +153,7 @@
     PyObject *args, *result;
 
     if (format == NULL) {
-        format = PyString_FromString("%s %s");
+        format = PyUnicode_FromString("%s %s");
         if (format == NULL)
             return NULL;
     }
@@ -162,7 +162,7 @@
     if (args == NULL)
         return NULL;
 
-    result = PyString_Format(format, args);
+    result = PyUnicode_Format(format, args);
     Py_DECREF(args);
     
     return result;

Modified: python/branches/py3k-importlib/Doc/includes/noddy4.c
==============================================================================
--- python/branches/py3k-importlib/Doc/includes/noddy4.c	(original)
+++ python/branches/py3k-importlib/Doc/includes/noddy4.c	Thu Mar 27 00:48:05 2008
@@ -57,14 +57,14 @@
 
     self = (Noddy *)type->tp_alloc(type, 0);
     if (self != NULL) {
-        self->first = PyString_FromString("");
+        self->first = PyUnicode_FromString("");
         if (self->first == NULL)
           {
             Py_DECREF(self);
             return NULL;
           }
         
-        self->last = PyString_FromString("");
+        self->last = PyUnicode_FromString("");
         if (self->last == NULL)
           {
             Py_DECREF(self);
@@ -124,7 +124,7 @@
     PyObject *args, *result;
 
     if (format == NULL) {
-        format = PyString_FromString("%s %s");
+        format = PyUnicode_FromString("%s %s");
         if (format == NULL)
             return NULL;
     }
@@ -143,7 +143,7 @@
     if (args == NULL)
         return NULL;
 
-    result = PyString_Format(format, args);
+    result = PyUnicode_Format(format, args);
     Py_DECREF(args);
     
     return result;

Modified: python/branches/py3k-importlib/Doc/includes/run-func.c
==============================================================================
--- python/branches/py3k-importlib/Doc/includes/run-func.c	(original)
+++ python/branches/py3k-importlib/Doc/includes/run-func.c	Thu Mar 27 00:48:05 2008
@@ -13,7 +13,7 @@
     }
 
     Py_Initialize();
-    pName = PyString_FromString(argv[1]);
+    pName = PyUnicode_FromString(argv[1]);
     /* Error checking of pName left out */
 
     pModule = PyImport_Import(pName);
@@ -26,7 +26,7 @@
         if (pFunc && PyCallable_Check(pFunc)) {
             pArgs = PyTuple_New(argc - 3);
             for (i = 0; i < argc - 3; ++i) {
-                pValue = PyInt_FromLong(atoi(argv[i + 3]));
+                pValue = PyLong_FromLong(atoi(argv[i + 3]));
                 if (!pValue) {
                     Py_DECREF(pArgs);
                     Py_DECREF(pModule);
@@ -39,7 +39,7 @@
             pValue = PyObject_CallObject(pFunc, pArgs);
             Py_DECREF(pArgs);
             if (pValue != NULL) {
-                printf("Result of call: %ld\n", PyInt_AsLong(pValue));
+                printf("Result of call: %ld\n", PyLong_AsLong(pValue));
                 Py_DECREF(pValue);
             }
             else {

Modified: python/branches/py3k-importlib/Doc/includes/shoddy.c
==============================================================================
--- python/branches/py3k-importlib/Doc/includes/shoddy.c	(original)
+++ python/branches/py3k-importlib/Doc/includes/shoddy.c	Thu Mar 27 00:48:05 2008
@@ -10,7 +10,7 @@
 Shoddy_increment(Shoddy *self, PyObject *unused)
 {
     self->state++;
-    return PyInt_FromLong(self->state);
+    return PyLong_FromLong(self->state);
 }
 
 

Modified: python/branches/py3k-importlib/Doc/install/index.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/install/index.rst	(original)
+++ python/branches/py3k-importlib/Doc/install/index.rst	Thu Mar 27 00:48:05 2008
@@ -10,18 +10,17 @@
 :Release: |version|
 :Date: |today|
 
-.. % TODO:
-.. % Fill in XXX comments
+.. TODO: Fill in XXX comments
 
-.. % The audience for this document includes people who don't know anything
-.. % about Python and aren't about to learn the language just in order to
-.. % install and maintain it for their users, i.e. system administrators.
-.. % Thus, I have to be sure to explain the basics at some point:
-.. % sys.path and PYTHONPATH at least.  Should probably give pointers to
-.. % other docs on "import site", PYTHONSTARTUP, PYTHONHOME, etc.
-.. % 
-.. % Finally, it might be useful to include all the material from my "Care
-.. % and Feeding of a Python Installation" talk in here somewhere.  Yow!
+.. The audience for this document includes people who don't know anything
+   about Python and aren't about to learn the language just in order to
+   install and maintain it for their users, i.e. system administrators.
+   Thus, I have to be sure to explain the basics at some point:
+   sys.path and PYTHONPATH at least.  Should probably give pointers to
+   other docs on "import site", PYTHONSTARTUP, PYTHONHOME, etc.
+   
+   Finally, it might be useful to include all the material from my "Care
+   and Feeding of a Python Installation" talk in here somewhere.  Yow!
 
 .. topic:: Abstract
 
@@ -565,11 +564,11 @@
 the Distutils are the only ones you can use.) See section :ref:`inst-config-files`
 for details.
 
-.. % XXX need some Windows examples---when would custom
-.. % installation schemes be needed on those platforms?
+.. XXX need some Windows examples---when would custom installation schemes be
+   needed on those platforms?
 
-.. % XXX I'm not sure where this section should go.
 
+.. XXX I'm not sure where this section should go.
 
 .. _inst-search-path:
 
@@ -612,8 +611,7 @@
 installing fixed versions of standard modules.)
 
 Paths can be absolute or relative, in which case they're relative to the
-directory containing the :file:`.pth` file.  Any directories added to the search
-path will be scanned in turn for :file:`.pth` files.  See the documentation of
+directory containing the :file:`.pth` file.  See the documentation of
 the :mod:`site` module for more information.
 
 A slightly less convenient way is to edit the :file:`site.py` file in Python's
@@ -871,10 +869,10 @@
 
 
 
-Borland C++
-^^^^^^^^^^^
+Borland/CodeGear C++
+^^^^^^^^^^^^^^^^^^^^
 
-This subsection describes the necessary steps to use Distutils with the  Borland
+This subsection describes the necessary steps to use Distutils with the Borland
 C++ compiler version 5.5.  First you have to know that Borland's object file
 format (OMF) is different from the format used by the Python version you can
 download from the Python or ActiveState Web site.  (Python is built with
@@ -882,8 +880,8 @@
 reason you have to convert Python's library :file:`python25.lib` into the
 Borland format.  You can do this as follows:
 
-.. % Should we mention that users have to create cfg-files for the compiler?
-.. % see also http://community.borland.com/article/0,1410,21205,00.html
+.. Should we mention that users have to create cfg-files for the compiler?
+.. see also http://community.borland.com/article/0,1410,21205,00.html
 
 ::
 
@@ -914,7 +912,7 @@
 
 .. seealso::
 
-   `C++Builder Compiler <http://www.borland.com/bcppbuilder/freecompiler/>`_
+   `C++Builder Compiler <http://www.codegear.com/downloads/free/cppbuilder>`_
       Information about the free C++ compiler from Borland, including links to the
       download pages.
 
@@ -937,12 +935,10 @@
 These compilers require some special libraries. This task is more complex than
 for Borland's C++, because there is no program to convert the library.  First
 you have to create a list of symbols which the Python DLL exports. (You can find
-a good program for this task at
-http://starship.python.net/crew/kernr/mingw32/Notes.html, see at  PExports 0.42h
-there.)
+a good program for this task at http://www.emmestech.com/software/cygwin/pexports-0.43/download_pexports.html)
 
-.. % I don't understand what the next line means. --amk
-.. % (inclusive the references on data structures.)
+.. I don't understand what the next line means. --amk
+.. (inclusive the references on data structures.)
 
 ::
 
@@ -983,9 +979,6 @@
    `Building Python modules on MS Windows platform with MinGW <http://www.zope.org/Members/als/tips/win32_mingw_modules>`_
       Information about building the required libraries for the MinGW environment.
 
-   http://pyopengl.sourceforge.net/ftp/win32-stuff/
-      Converted import libraries in Cygwin/MinGW and Borland format, and a script to
-      create the registry entries needed for Distutils to locate the built Python.
 
 .. rubric:: Footnotes
 

Deleted: /python/branches/py3k-importlib/Doc/library/__builtin__.rst
==============================================================================
--- /python/branches/py3k-importlib/Doc/library/__builtin__.rst	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,41 +0,0 @@
-
-:mod:`__builtin__` --- Built-in objects
-=======================================
-
-.. module:: __builtin__
-   :synopsis: The module that provides the built-in namespace.
-
-
-This module provides direct access to all 'built-in' identifiers of Python; for
-example, ``__builtin__.open`` is the full name for the built-in function
-:func:`open`.  See chapter :ref:`builtin`.
-
-This module is not normally accessed explicitly by most applications, but can be
-useful in modules that provide objects with the same name as a built-in value,
-but in which the built-in of that name is also needed.  For example, in a module
-that wants to implement an :func:`open` function that wraps the built-in
-:func:`open`, this module can be used directly::
-
-   import __builtin__
-
-   def open(path):
-       f = __builtin__.open(path, 'r')
-       return UpperCaser(f)
-
-   class UpperCaser:
-       '''Wrapper around a file that converts output to upper-case.'''
-
-       def __init__(self, f):
-           self._f = f
-
-       def read(self, count=-1):
-           return self._f.read(count).upper()
-
-       # ...
-
-As an implementation detail, most modules have the name ``__builtins__`` (note
-the ``'s'``) made available as part of their globals.  The value of
-``__builtins__`` is normally either this module or the value of this modules's
-:attr:`__dict__` attribute.  Since this is an implementation detail, it may not
-be used by alternate implementations of Python.
-

Modified: python/branches/py3k-importlib/Doc/library/__future__.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/__future__.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/__future__.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`__future__` --- Future statement definitions
 ==================================================
 
@@ -22,8 +21,8 @@
 
 Each statement in :file:`__future__.py` is of the form::
 
-   FeatureName = "_Feature(" OptionalRelease "," MandatoryRelease ","
-                           CompilerFlag ")"
+   FeatureName = _Feature(OptionalRelease, MandatoryRelease,
+                          CompilerFlag)
 
 
 where, normally, *OptionalRelease* is less than *MandatoryRelease*, and both are

Modified: python/branches/py3k-importlib/Doc/library/_ast.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/_ast.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/_ast.rst	Thu Mar 27 00:48:05 2008
@@ -12,7 +12,7 @@
 The ``_ast`` module helps Python applications to process trees of the Python
 abstract syntax grammar. The Python compiler currently provides read-only access
 to such trees, meaning that applications can only create a tree for a given
-piece of Python source code; generating byte code from a (potentially modified)
+piece of Python source code; generating :term:`bytecode` from a (potentially modified)
 tree is not supported. The abstract syntax itself might change with each Python
 release; this module helps to find out programmatically what the current grammar
 looks like.

Modified: python/branches/py3k-importlib/Doc/library/_winreg.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/_winreg.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/_winreg.rst	Thu Mar 27 00:48:05 2008
@@ -131,6 +131,16 @@
    +-------+--------------------------------------------+
 
 
+.. function:: ExpandEnvironmentStrings(unicode)
+
+   Expands environment strings %NAME% in unicode string like const:`REG_EXPAND_SZ`::
+
+      >>> ExpandEnvironmentStrings(u"%windir%")
+      u"C:\\Windows"
+
+   .. versionadded:: 2.6
+
+
 .. function:: FlushKey(key)
 
    Writes all the attributes of a key to the registry.
@@ -219,7 +229,7 @@
    | ``1`` | An integer giving the number of values this |
    |       | key has.                                    |
    +-------+---------------------------------------------+
-   | ``2`` | A long integer giving when the key was last |
+   | ``2`` | An integer giving when the key was last     |
    |       | modified (if available) as 100's of         |
    |       | nanoseconds since Jan 1, 1600.              |
    +-------+---------------------------------------------+
@@ -408,11 +418,24 @@
 
    Detaches the Windows handle from the handle object.
 
-   The result is an integer (or long on 64 bit Windows) that holds the value of the
-   handle before it is detached.  If the handle is already detached or closed, this
-   will return zero.
+   The result is an integer that holds the value of the handle before it is
+   detached.  If the handle is already detached or closed, this will return
+   zero.
 
    After calling this function, the handle is effectively invalidated, but the
    handle is not closed.  You would call this function when  you need the
    underlying Win32 handle to exist beyond the lifetime  of the handle object.
 
+.. method:: PyHKEY.__enter__()
+            PyHKEY.__exit__(\*exc_info)
+
+   The HKEY object implements :meth:`__enter__` and :meth:`__exit__` and thus
+   supports the context protocol for the :keyword:`with` statement::
+
+      with OpenKey(HKEY_LOCAL_MACHINE, "foo") as key:
+          # ... work with key ...
+
+   will automatically close *key* when control leaves the :keyword:`with` block.
+
+   .. versionadded:: 2.6
+

Modified: python/branches/py3k-importlib/Doc/library/aepack.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/aepack.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/aepack.rst	Thu Mar 27 00:48:05 2008
@@ -6,9 +6,7 @@
    :platform: Mac
    :synopsis: Conversion between Python variables and AppleEvent data containers.
 .. sectionauthor:: Vincent Marchetti <vincem at en.com>
-
-
-.. % \moduleauthor{Jack Jansen?}{email}
+.. moduleauthor:: Jack Jansen
 
 The :mod:`aepack` module defines functions for converting (packing) Python
 variables to AppleEvent descriptors and back (unpacking). Within Python the
@@ -86,7 +84,3 @@
 
    Module :mod:`aetypes`
       Python definitions of codes for Apple Event descriptor types.
-
-   `Inside Macintosh: Interapplication Communication <http://developer.apple.com/techpubs/mac/IAC/IAC-2.html>`_
-      Information about inter-process communications on the Macintosh.
-

Modified: python/branches/py3k-importlib/Doc/library/aetools.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/aetools.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/aetools.rst	Thu Mar 27 00:48:05 2008
@@ -6,9 +6,7 @@
    :platform: Mac
    :synopsis: Basic support for sending Apple Events
 .. sectionauthor:: Jack Jansen <Jack.Jansen at cwi.nl>
-
-
-.. % \moduleauthor{Jack Jansen?}{email}
+.. moduleauthor:: Jack Jansen
 
 The :mod:`aetools` module contains the basic functionality on which Python
 AppleScript client support is built. It also imports and re-exports the core

Modified: python/branches/py3k-importlib/Doc/library/aetypes.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/aetypes.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/aetypes.rst	Thu Mar 27 00:48:05 2008
@@ -6,9 +6,7 @@
    :platform: Mac
    :synopsis: Python representation of the Apple Event Object Model.
 .. sectionauthor:: Vincent Marchetti <vincem at en.com>
-
-
-.. % \moduleauthor{Jack Jansen?}{email}
+.. moduleauthor:: Jack Jansen
 
 The :mod:`aetypes` defines classes used to represent Apple Event data
 descriptors and Apple Event object specifiers.

Modified: python/branches/py3k-importlib/Doc/library/array.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/array.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/array.rst	Thu Mar 27 00:48:05 2008
@@ -32,11 +32,11 @@
 +-----------+----------------+-------------------+-----------------------+
 | ``'i'``   | signed int     | int               | 2                     |
 +-----------+----------------+-------------------+-----------------------+
-| ``'I'``   | unsigned int   | long              | 2                     |
+| ``'I'``   | unsigned int   | int               | 2                     |
 +-----------+----------------+-------------------+-----------------------+
 | ``'l'``   | signed long    | int               | 4                     |
 +-----------+----------------+-------------------+-----------------------+
-| ``'L'``   | unsigned long  | long              | 4                     |
+| ``'L'``   | unsigned long  | int               | 4                     |
 +-----------+----------------+-------------------+-----------------------+
 | ``'f'``   | float          | float             | 4                     |
 +-----------+----------------+-------------------+-----------------------+
@@ -45,10 +45,7 @@
 
 The actual representation of values is determined by the machine architecture
 (strictly speaking, by the C implementation).  The actual size can be accessed
-through the :attr:`itemsize` attribute.  The values stored  for ``'L'`` and
-``'I'`` items will be represented as Python long integers when retrieved,
-because Python's plain integer type cannot represent the full range of C's
-unsigned (long) integers.
+through the :attr:`itemsize` attribute.
 
 The module defines the following type:
 
@@ -56,8 +53,9 @@
 .. function:: array(typecode[, initializer])
 
    Return a new array whose items are restricted by *typecode*, and initialized
-   from the optional *initializer* value, which must be a list, string, or iterable
-   over elements of the appropriate type.
+   from the optional *initializer* value, which must be a list, object
+   supporting the buffer interface, or iterable over elements of the 
+   appropriate type.
 
    If given a list or string, the initializer is passed to the new array's
    :meth:`fromlist`, :meth:`fromstring`, or :meth:`fromunicode` method (see below)
@@ -69,6 +67,10 @@
 
    Obsolete alias for :func:`array`.
 
+.. data:: typecodes
+
+   A string with all available type codes.
+
 Array objects support the ordinary sequence operations of indexing, slicing,
 concatenation, and multiplication.  When using slice assignment, the assigned
 value must be an array object with the same type code; in all other cases,
@@ -181,18 +183,6 @@
    returned.
 
 
-.. method:: array.read(f, n)
-
-   .. deprecated:: 1.5.1
-      Use the :meth:`fromfile` method.
-
-   Read *n* items (as machine values) from the file object *f* and append them to
-   the end of the array.  If less than *n* items are available, :exc:`EOFError` is
-   raised, but the items that were available are still inserted into the array.
-   *f* must be a real built-in file object; something else with a :meth:`read`
-   method won't do.
-
-
 .. method:: array.remove(x)
 
    Remove the first occurrence of *x* from the array.
@@ -227,13 +217,6 @@
    obtain a unicode string from an array of some other type.
 
 
-.. method:: array.write(f)
-
-   .. deprecated:: 1.5.1
-      Use the :meth:`tofile` method.
-
-   Write all items (as machine values) to the file object *f*.
-
 When an array object is printed or converted to a string, it is represented as
 ``array(typecode, initializer)``.  The *initializer* is omitted if the array is
 empty, otherwise it is a string if the *typecode* is ``'c'``, otherwise it is a

Modified: python/branches/py3k-importlib/Doc/library/asynchat.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/asynchat.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/asynchat.rst	Thu Mar 27 00:48:05 2008
@@ -9,72 +9,90 @@
 
 
 This module builds on the :mod:`asyncore` infrastructure, simplifying
-asynchronous clients and servers and making it easier to handle protocols whose
-elements are terminated by arbitrary strings, or are of variable length.
+asynchronous clients and servers and making it easier to handle protocols
+whose elements are terminated by arbitrary strings, or are of variable length.
 :mod:`asynchat` defines the abstract class :class:`async_chat` that you
 subclass, providing implementations of the :meth:`collect_incoming_data` and
 :meth:`found_terminator` methods. It uses the same asynchronous loop as
-:mod:`asyncore`, and the two types of channel, :class:`asyncore.dispatcher` and
-:class:`asynchat.async_chat`, can freely be mixed in the channel map. Typically
-an :class:`asyncore.dispatcher` server channel generates new
-:class:`asynchat.async_chat` channel objects as it receives incoming connection
-requests.
+:mod:`asyncore`, and the two types of channel, :class:`asyncore.dispatcher`
+and :class:`asynchat.async_chat`, can freely be mixed in the channel map.
+Typically an :class:`asyncore.dispatcher` server channel generates new
+:class:`asynchat.async_chat` channel objects as it receives incoming
+connection requests.
 
 
 .. class:: async_chat()
 
    This class is an abstract subclass of :class:`asyncore.dispatcher`. To make
    practical use of the code you must subclass :class:`async_chat`, providing
-   meaningful :meth:`collect_incoming_data` and :meth:`found_terminator` methods.
+   meaningful :meth:`collect_incoming_data` and :meth:`found_terminator`
+   methods.
    The :class:`asyncore.dispatcher` methods can be used, although not all make
    sense in a message/response context.
 
-   Like :class:`asyncore.dispatcher`, :class:`async_chat` defines a set of events
-   that are generated by an analysis of socket conditions after a :cfunc:`select`
-   call. Once the polling loop has been started the :class:`async_chat` object's
-   methods are called by the event-processing framework with no action on the part
-   of the programmer.
-
-   Unlike :class:`asyncore.dispatcher`, :class:`async_chat` allows you to define a
-   first-in-first-out queue (fifo) of *producers*. A producer need have only one
-   method, :meth:`more`, which should return data to be transmitted on the channel.
+   Like :class:`asyncore.dispatcher`, :class:`async_chat` defines a set of
+   events that are generated by an analysis of socket conditions after a
+   :cfunc:`select` call. Once the polling loop has been started the
+   :class:`async_chat` object's methods are called by the event-processing
+   framework with no action on the part of the programmer.
+
+   Two class attributes can be modified, to improve performance, or possibly
+   even to conserve memory.
+
+
+   .. data:: ac_in_buffer_size
+
+      The asynchronous input buffer size (default ``4096``).
+
+
+   .. data:: ac_out_buffer_size
+
+      The asynchronous output buffer size (default ``4096``).
+
+   Unlike :class:`asyncore.dispatcher`, :class:`async_chat` allows you to
+   define a first-in-first-out queue (fifo) of *producers*. A producer need
+   have only one method, :meth:`more`, which should return data to be
+   transmitted on the channel.
    The producer indicates exhaustion (*i.e.* that it contains no more data) by
    having its :meth:`more` method return the empty string. At this point the
-   :class:`async_chat` object removes the producer from the fifo and starts using
-   the next producer, if any. When the producer fifo is empty the
+   :class:`async_chat` object removes the producer from the fifo and starts
+   using the next producer, if any. When the producer fifo is empty the
    :meth:`handle_write` method does nothing. You use the channel object's
-   :meth:`set_terminator` method to describe how to recognize the end of, or an
-   important breakpoint in, an incoming transmission from the remote endpoint.
+   :meth:`set_terminator` method to describe how to recognize the end of, or
+   an important breakpoint in, an incoming transmission from the remote
+   endpoint.
 
    To build a functioning :class:`async_chat` subclass your  input methods
-   :meth:`collect_incoming_data` and :meth:`found_terminator` must handle the data
-   that the channel receives asynchronously. The methods are described below.
+   :meth:`collect_incoming_data` and :meth:`found_terminator` must handle the
+   data that the channel receives asynchronously. The methods are described
+   below.
 
 
 .. method:: async_chat.close_when_done()
 
-   Pushes a ``None`` on to the producer fifo. When this producer is popped off the
-   fifo it causes the channel to be closed.
+   Pushes a ``None`` on to the producer fifo. When this producer is popped off
+   the fifo it causes the channel to be closed.
 
 
 .. method:: async_chat.collect_incoming_data(data)
 
-   Called with *data* holding an arbitrary amount of received data. The default
-   method, which must be overridden, raises a :exc:`NotImplementedError` exception.
+   Called with *data* holding an arbitrary amount of received data.  The
+   default method, which must be overridden, raises a
+   :exc:`NotImplementedError` exception.
 
 
 .. method:: async_chat.discard_buffers()
 
-   In emergencies this method will discard any data held in the input and/or output
-   buffers and the producer fifo.
+   In emergencies this method will discard any data held in the input and/or
+   output buffers and the producer fifo.
 
 
 .. method:: async_chat.found_terminator()
 
-   Called when the incoming data stream  matches the termination condition set by
-   :meth:`set_terminator`. The default method, which must be overridden, raises a
-   :exc:`NotImplementedError` exception. The buffered input data should be
-   available via an instance attribute.
+   Called when the incoming data stream  matches the termination condition set
+   by :meth:`set_terminator`. The default method, which must be overridden,
+   raises a :exc:`NotImplementedError` exception. The buffered input data
+   should be available via an instance attribute.
 
 
 .. method:: async_chat.get_terminator()
@@ -90,59 +108,59 @@
 
 .. method:: async_chat.handle_read()
 
-   Called when a read event fires on the channel's socket in the asynchronous loop.
-   The default method checks for the termination condition established by
-   :meth:`set_terminator`, which can be either the appearance of a particular
-   string in the input stream or the receipt of a particular number of characters.
-   When the terminator is found, :meth:`handle_read` calls the
-   :meth:`found_terminator` method after calling :meth:`collect_incoming_data` with
-   any data preceding the terminating condition.
+   Called when a read event fires on the channel's socket in the asynchronous
+   loop.  The default method checks for the termination condition established
+   by :meth:`set_terminator`, which can be either the appearance of a
+   particular string in the input stream or the receipt of a particular number
+   of characters.  When the terminator is found, :meth:`handle_read` calls the
+   :meth:`found_terminator` method after calling :meth:`collect_incoming_data`
+   with any data preceding the terminating condition.
 
 
 .. method:: async_chat.handle_write()
 
-   Called when the application may write data to the channel.   The default method
-   calls the :meth:`initiate_send` method, which in turn will call
-   :meth:`refill_buffer` to collect data from the producer fifo associated with the
-   channel.
+   Called when the application may write data to the channel.   The default
+   method calls the :meth:`initiate_send` method, which in turn will call
+   :meth:`refill_buffer` to collect data from the producer fifo associated
+   with the channel.
 
 
 .. method:: async_chat.push(data)
 
-   Creates a :class:`simple_producer` object (*see below*) containing the data and
-   pushes it on to the channel's ``producer_fifo`` to ensure its transmission. This
-   is all you need to do to have the channel write the data out to the network,
-   although it is possible to use your own producers in more complex schemes to
-   implement encryption and chunking, for example.
+   Creates a :class:`simple_producer` object (*see below*) containing the data
+   and pushes it on to the channel's ``producer_fifo`` to ensure its
+   transmission.  This is all you need to do to have the channel write the
+   data out to the network, although it is possible to use your own producers
+   in more complex schemes to implement encryption and chunking, for example.
 
 
 .. method:: async_chat.push_with_producer(producer)
 
-   Takes a producer object and adds it to the producer fifo associated with the
-   channel. When all currently-pushed producers have been exhausted the channel
-   will consume this producer's data by calling its :meth:`more` method and send
-   the data to the remote endpoint.
+   Takes a producer object and adds it to the producer fifo associated with
+   the channel.  When all currently-pushed producers have been exhausted the
+   channel will consume this producer's data by calling its :meth:`more`
+   method and send the data to the remote endpoint.
 
 
 .. method:: async_chat.readable()
 
-   Should return ``True`` for the channel to be included in the set of channels
-   tested by the :cfunc:`select` loop for readability.
+   Should return ``True`` for the channel to be included in the set of
+   channels tested by the :cfunc:`select` loop for readability.
 
 
 .. method:: async_chat.refill_buffer()
 
-   Refills the output buffer by calling the :meth:`more` method of the producer at
-   the head of the fifo. If it is exhausted then the producer is popped off the
-   fifo and the next producer is activated. If the current producer is, or becomes,
-   ``None`` then the channel is closed.
+   Refills the output buffer by calling the :meth:`more` method of the
+   producer at the head of the fifo.  If it is exhausted then the producer is
+   popped off the fifo and the next producer is activated.  If the current
+   producer is, or becomes, ``None`` then the channel is closed.
 
 
 .. method:: async_chat.set_terminator(term)
 
-   Sets the terminating condition to be recognised on the channel. ``term`` may be
-   any of three types of value, corresponding to three different ways to handle
-   incoming protocol data.
+   Sets the terminating condition to be recognized on the channel.  ``term``
+   may be any of three types of value, corresponding to three different ways
+   to handle incoming protocol data.
 
    +-----------+---------------------------------------------+
    | term      | Description                                 |
@@ -158,8 +176,8 @@
    |           | forever                                     |
    +-----------+---------------------------------------------+
 
-   Note that any data following the terminator will be available for reading by the
-   channel after :meth:`found_terminator` is called.
+   Note that any data following the terminator will be available for reading
+   by the channel after :meth:`found_terminator` is called.
 
 
 .. method:: async_chat.writable()
@@ -174,29 +192,29 @@
 
 .. class:: simple_producer(data[, buffer_size=512])
 
-   A :class:`simple_producer` takes a chunk of data and an optional buffer size.
-   Repeated calls to its :meth:`more` method yield successive chunks of the data no
-   larger than *buffer_size*.
+   A :class:`simple_producer` takes a chunk of data and an optional buffer
+   size.  Repeated calls to its :meth:`more` method yield successive chunks of
+   the data no larger than *buffer_size*.
 
 
 .. method:: simple_producer.more()
 
-   Produces the next chunk of information from the producer, or returns the empty
-   string.
+   Produces the next chunk of information from the producer, or returns the
+   empty string.
 
 
 .. class:: fifo([list=None])
 
-   Each channel maintains a :class:`fifo` holding data which has been pushed by the
-   application but not yet popped for writing to the channel. A :class:`fifo` is a
-   list used to hold data and/or producers until they are required. If the *list*
-   argument is provided then it should contain producers or data items to be
-   written to the channel.
+   Each channel maintains a :class:`fifo` holding data which has been pushed
+   by the application but not yet popped for writing to the channel.  A
+   :class:`fifo` is a list used to hold data and/or producers until they are
+   required.  If the *list* argument is provided then it should contain
+   producers or data items to be written to the channel.
 
 
 .. method:: fifo.is_empty()
 
-   Returns ``True`` iff the fifo is empty.
+   Returns ``True`` if and only if the fifo is empty.
 
 
 .. method:: fifo.first()
@@ -206,14 +224,14 @@
 
 .. method:: fifo.push(data)
 
-   Adds the given data (which may be a string or a producer object) to the producer
-   fifo.
+   Adds the given data (which may be a string or a producer object) to the
+   producer fifo.
 
 
 .. method:: fifo.pop()
 
-   If the fifo is not empty, returns ``True, first()``, deleting the popped item.
-   Returns ``False, None`` for an empty fifo.
+   If the fifo is not empty, returns ``True, first()``, deleting the popped
+   item.  Returns ``False, None`` for an empty fifo.
 
 The :mod:`asynchat` module also defines one utility function, which may be of
 use in network and textual analysis operations.
@@ -221,8 +239,8 @@
 
 .. function:: find_prefix_at_end(haystack, needle)
 
-   Returns ``True`` if string *haystack* ends with any non-empty prefix of string
-   *needle*.
+   Returns ``True`` if string *haystack* ends with any non-empty prefix of
+   string *needle*.
 
 
 .. _asynchat-example:
@@ -231,19 +249,20 @@
 ----------------
 
 The following partial example shows how HTTP requests can be read with
-:class:`async_chat`. A web server might create an :class:`http_request_handler`
-object for each incoming client connection. Notice that initially the channel
-terminator is set to match the blank line at the end of the HTTP headers, and a
-flag indicates that the headers are being read.
-
-Once the headers have been read, if the request is of type POST (indicating that
-further data are present in the input stream) then the ``Content-Length:``
-header is used to set a numeric terminator to read the right amount of data from
-the channel.
+:class:`async_chat`.  A web server might create an
+:class:`http_request_handler` object for each incoming client connection.
+Notice that initially the channel terminator is set to match the blank line at
+the end of the HTTP headers, and a flag indicates that the headers are being
+read.
+
+Once the headers have been read, if the request is of type POST (indicating
+that further data are present in the input stream) then the
+``Content-Length:`` header is used to set a numeric terminator to read the
+right amount of data from the channel.
 
 The :meth:`handle_request` method is called once all relevant input has been
-marshalled, after setting the channel terminator to ``None`` to ensure that any
-extraneous data sent by the web client are ignored. ::
+marshalled, after setting the channel terminator to ``None`` to ensure that
+any extraneous data sent by the web client are ignored. ::
 
    class http_request_handler(asynchat.async_chat):
 
@@ -281,4 +300,3 @@
                self.handling = True
                self.ibuffer = []
                self.handle_request()
-

Modified: python/branches/py3k-importlib/Doc/library/asyncore.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/asyncore.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/asyncore.rst	Thu Mar 27 00:48:05 2008
@@ -3,89 +3,80 @@
 ===============================================
 
 .. module:: asyncore
-   :synopsis: A base class for developing asynchronous socket  handling services.
+   :synopsis: A base class for developing asynchronous socket handling
+              services.
 .. moduleauthor:: Sam Rushing <rushing at nightmare.com>
 .. sectionauthor:: Christopher Petrilli <petrilli at amber.org>
 .. sectionauthor:: Steve Holden <sholden at holdenweb.com>
+.. heavily adapted from original documentation by Sam Rushing
 
 
 This module provides the basic infrastructure for writing asynchronous  socket
 service clients and servers.
 
-.. % Heavily adapted from original documentation by Sam Rushing.
-
 There are only two ways to have a program on a single processor do  "more than
 one thing at a time." Multi-threaded programming is the  simplest and most
-popular way to do it, but there is another very  different technique, that lets
+popular way to do it, but there is another very different technique, that lets
 you have nearly all the advantages of  multi-threading, without actually using
 multiple threads.  It's really  only practical if your program is largely I/O
-bound.  If your program  is processor bound, then pre-emptive scheduled threads
-are probably what  you really need. Network servers are rarely processor bound,
-however.
+bound.  If your program is processor bound, then pre-emptive scheduled threads
+are probably what you really need.  Network servers are rarely processor
+bound, however.
 
 If your operating system supports the :cfunc:`select` system call in its I/O
 library (and nearly all do), then you can use it to juggle multiple
-communication channels at once; doing other work while your I/O is taking place
-in the "background."  Although this strategy can seem strange and complex,
-especially at first, it is in many ways easier to understand and control than
-multi-threaded programming.  The :mod:`asyncore` module solves many of the
-difficult problems for you, making the task of building sophisticated
-high-performance network servers and clients a snap. For "conversational"
-applications and protocols the companion :mod:`asynchat` module is invaluable.
-
-The basic idea behind both modules is to create one or more network *channels*,
-instances of class :class:`asyncore.dispatcher` and
-:class:`asynchat.async_chat`. Creating the channels adds them to a global map,
-used by the :func:`loop` function if you do not provide it with your own *map*.
+communication channels at once; doing other work while your I/O is taking
+place in the "background."  Although this strategy can seem strange and
+complex, especially at first, it is in many ways easier to understand and
+control than multi-threaded programming.  The :mod:`asyncore` module solves
+many of the difficult problems for you, making the task of building
+sophisticated high-performance network servers and clients a snap.  For
+"conversational" applications and protocols the companion :mod:`asynchat`
+module is invaluable.
+
+The basic idea behind both modules is to create one or more network
+*channels*, instances of class :class:`asyncore.dispatcher` and
+:class:`asynchat.async_chat`.  Creating the channels adds them to a global
+map, used by the :func:`loop` function if you do not provide it with your own
+*map*.
 
 Once the initial channel(s) is(are) created, calling the :func:`loop` function
-activates channel service, which continues until the last channel (including any
-that have been added to the map during asynchronous service) is closed.
+activates channel service, which continues until the last channel (including
+any that have been added to the map during asynchronous service) is closed.
 
 
 .. function:: loop([timeout[, use_poll[, map[,count]]]])
 
-   Enter a polling loop that terminates after count passes or all open channels
-   have been closed.  All arguments are optional.  The *count* parameter defaults
-   to None, resulting in the loop terminating only when all channels have been
-   closed.  The *timeout* argument sets the timeout parameter for the appropriate
-   :func:`select` or :func:`poll` call, measured in seconds; the default is 30
-   seconds. The *use_poll* parameter, if true, indicates that :func:`poll` should
-   be used in preference to :func:`select` (the default is ``False``).
-
-   The *map* parameter is a dictionary whose items are the channels to watch.  As
-   channels are closed they are deleted from their map.  If *map* is omitted, a
-   global map is used. Channels (instances of :class:`asyncore.dispatcher`,
-   :class:`asynchat.async_chat` and subclasses thereof) can freely be mixed in the
-   map.
+   Enter a polling loop that terminates after count passes or all open
+   channels have been closed.  All arguments are optional.  The *count*
+   parameter defaults to None, resulting in the loop terminating only when all
+   channels have been closed.  The *timeout* argument sets the timeout
+   parameter for the appropriate :func:`select` or :func:`poll` call, measured
+   in seconds; the default is 30 seconds.  The *use_poll* parameter, if true,
+   indicates that :func:`poll` should be used in preference to :func:`select`
+   (the default is ``False``).
+
+   The *map* parameter is a dictionary whose items are the channels to watch.
+   As channels are closed they are deleted from their map.  If *map* is
+   omitted, a global map is used. Channels (instances of
+   :class:`asyncore.dispatcher`, :class:`asynchat.async_chat` and subclasses
+   thereof) can freely be mixed in the map.
 
 
 .. class:: dispatcher()
 
    The :class:`dispatcher` class is a thin wrapper around a low-level socket
-   object. To make it more useful, it has a few methods for event-handling  which
-   are called from the asynchronous loop.   Otherwise, it can be treated as a
-   normal non-blocking socket object.
-
-   Two class attributes can be modified, to improve performance, or possibly even
-   to conserve memory.
-
-
-   .. data:: ac_in_buffer_size
-
-      The asynchronous input buffer size (default ``4096``).
-
-
-   .. data:: ac_out_buffer_size
-
-      The asynchronous output buffer size (default ``4096``).
-
-   The firing of low-level events at certain times or in certain connection states
-   tells the asynchronous loop that certain higher-level events have taken place.
-   For example, if we have asked for a socket to connect to another host, we know
-   that the connection has been made when the socket becomes writable for the first
-   time (at this point you know that you may write to it with the expectation of
-   success). The implied higher-level events are:
+   object. To make it more useful, it has a few methods for event-handling
+   which are called from the asynchronous loop.   Otherwise, it can be treated
+   as a normal non-blocking socket object.
+
+   The firing of low-level events at certain times or in certain connection
+   states tells the asynchronous loop that certain higher-level events have
+   taken place.  For example, if we have asked for a socket to connect to
+   another host, we know that the connection has been made when the socket
+   becomes writable for the first time (at this point you know that you may
+   write to it with the expectation of success).  The implied higher-level
+   events are:
 
    +----------------------+----------------------------------------+
    | Event                | Description                            |
@@ -101,11 +92,11 @@
 
    During asynchronous processing, each mapped channel's :meth:`readable` and
    :meth:`writable` methods are used to determine whether the channel's socket
-   should be added to the list of channels :cfunc:`select`\ ed or :cfunc:`poll`\ ed
-   for read and write events.
+   should be added to the list of channels :cfunc:`select`\ ed or
+   :cfunc:`poll`\ ed for read and write events.
 
-Thus, the set of channel events is larger than the basic socket events. The full
-set of methods that can be overridden in your subclass follows:
+Thus, the set of channel events is larger than the basic socket events.  The
+full set of methods that can be overridden in your subclass follows:
 
 
 .. method:: dispatcher.handle_read()
@@ -116,9 +107,9 @@
 
 .. method:: dispatcher.handle_write()
 
-   Called when the asynchronous loop detects that a writable socket can be written.
-   Often this method will implement the necessary buffering for  performance.  For
-   example::
+   Called when the asynchronous loop detects that a writable socket can be
+   written.  Often this method will implement the necessary buffering for
+   performance.  For example::
 
       def handle_write(self):
           sent = self.send(self.buffer)
@@ -127,15 +118,15 @@
 
 .. method:: dispatcher.handle_expt()
 
-   Called when there is out of band (OOB) data for a socket  connection.  This will
-   almost never happen, as OOB is  tenuously supported and rarely used.
+   Called when there is out of band (OOB) data for a socket connection.  This
+   will almost never happen, as OOB is tenuously supported and rarely used.
 
 
 .. method:: dispatcher.handle_connect()
 
-   Called when the active opener's socket actually makes a connection. Might send a
-   "welcome" banner, or initiate a protocol negotiation with the remote endpoint,
-   for example.
+   Called when the active opener's socket actually makes a connection.  Might
+   send a "welcome" banner, or initiate a protocol negotiation with the remote
+   endpoint, for example.
 
 
 .. method:: dispatcher.handle_close()
@@ -152,40 +143,40 @@
 .. method:: dispatcher.handle_accept()
 
    Called on listening channels (passive openers) when a   connection can be
-   established with a new remote endpoint that has issued a :meth:`connect` call
-   for the local endpoint.
+   established with a new remote endpoint that has issued a :meth:`connect`
+   call for the local endpoint.
 
 
 .. method:: dispatcher.readable()
 
-   Called each time around the asynchronous loop to determine whether a channel's
-   socket should be added to the list on which read events can occur.  The default
-   method simply returns ``True``,  indicating that by default, all channels will
-   be interested in read events.
+   Called each time around the asynchronous loop to determine whether a
+   channel's socket should be added to the list on which read events can
+   occur.  The default method simply returns ``True``, indicating that by
+   default, all channels will be interested in read events.
 
 
 .. method:: dispatcher.writable()
 
-   Called each time around the asynchronous loop to determine whether a channel's
-   socket should be added to the list on which write events can occur.  The default
-   method simply returns ``True``,  indicating that by default, all channels will
-   be interested in write events.
+   Called each time around the asynchronous loop to determine whether a
+   channel's socket should be added to the list on which write events can
+   occur.  The default method simply returns ``True``, indicating that by
+   default, all channels will be interested in write events.
 
-In addition, each channel delegates or extends many of the socket methods. Most
-of these are nearly identical to their socket partners.
+In addition, each channel delegates or extends many of the socket methods.
+Most of these are nearly identical to their socket partners.
 
 
 .. method:: dispatcher.create_socket(family, type)
 
-   This is identical to the creation of a normal socket, and  will use the same
-   options for creation.  Refer to the :mod:`socket` documentation for information
-   on creating sockets.
+   This is identical to the creation of a normal socket, and will use the same
+   options for creation.  Refer to the :mod:`socket` documentation for
+   information on creating sockets.
 
 
 .. method:: dispatcher.connect(address)
 
-   As with the normal socket object, *address* is a  tuple with the first element
-   the host to connect to, and the  second the port number.
+   As with the normal socket object, *address* is a tuple with the first
+   element the host to connect to, and the second the port number.
 
 
 .. method:: dispatcher.send(data)
@@ -195,38 +186,41 @@
 
 .. method:: dispatcher.recv(buffer_size)
 
-   Read at most *buffer_size* bytes from the socket's remote end-point. An empty
-   string implies that the channel has been closed from the other end.
+   Read at most *buffer_size* bytes from the socket's remote end-point.
+   An empty string implies that the channel has been closed from the other
+   end.
 
 
 .. method:: dispatcher.listen(backlog)
 
-   Listen for connections made to the socket.  The *backlog* argument specifies the
-   maximum number of queued connections and should be at least 1; the maximum value
-   is system-dependent (usually 5).
+   Listen for connections made to the socket.  The *backlog* argument
+   specifies the maximum number of queued connections and should be at least
+   1; the maximum value is system-dependent (usually 5).
 
 
 .. method:: dispatcher.bind(address)
 
    Bind the socket to *address*.  The socket must not already be bound.  (The
-   format of *address* depends on the address family --- see above.)  To mark the
-   socket as re-usable (setting the :const:`SO_REUSEADDR` option), call the
-   :class:`dispatcher` object's :meth:`set_reuse_addr` method.
+   format of *address* depends on the address family --- see above.)  To mark
+   the socket as re-usable (setting the :const:`SO_REUSEADDR` option), call
+   the :class:`dispatcher` object's :meth:`set_reuse_addr` method.
 
 
 .. method:: dispatcher.accept()
 
-   Accept a connection.  The socket must be bound to an address and listening for
-   connections.  The return value is a pair ``(conn, address)`` where *conn* is a
-   *new* socket object usable to send and receive data on the connection, and
-   *address* is the address bound to the socket on the other end of the connection.
+   Accept a connection.  The socket must be bound to an address and listening
+   for connections.  The return value is a pair ``(conn, address)`` where
+   *conn* is a *new* socket object usable to send and receive data on the
+   connection, and *address* is the address bound to the socket on the other
+   end of the connection.
 
 
 .. method:: dispatcher.close()
 
-   Close the socket.  All future operations on the socket object will fail.  The
-   remote end-point will receive no more data (after queued data is flushed).
-   Sockets are automatically closed when they are garbage-collected.
+   Close the socket.  All future operations on the socket object will fail.
+   The remote end-point will receive no more data (after queued data is
+   flushed).  Sockets are automatically closed when they are
+   garbage-collected.
 
 
 .. _asyncore-example:
@@ -266,4 +260,3 @@
    c = http_client('www.python.org', '/')
 
    asyncore.loop()
-

Modified: python/branches/py3k-importlib/Doc/library/atexit.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/atexit.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/atexit.rst	Thu Mar 27 00:48:05 2008
@@ -4,8 +4,8 @@
 
 .. module:: atexit
    :synopsis: Register and execute cleanup functions.
-.. moduleauthor:: Skip Montanaro <skip at mojam.com>
-.. sectionauthor:: Skip Montanaro <skip at mojam.com>
+.. moduleauthor:: Skip Montanaro <skip at pobox.com>
+.. sectionauthor:: Skip Montanaro <skip at pobox.com>
 
 
 The :mod:`atexit` module defines functions to register and unregister cleanup
@@ -88,7 +88,7 @@
    # or:
    atexit.register(goodbye, adjective='nice', name='Donny')
 
-Usage as a decorator::
+Usage as a :term:`decorator`::
 
    import atexit
 

Modified: python/branches/py3k-importlib/Doc/library/audioop.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/audioop.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/audioop.rst	Thu Mar 27 00:48:05 2008
@@ -19,7 +19,7 @@
 
 This module provides support for a-LAW, u-LAW and Intel/DVI ADPCM encodings.
 
-.. % This para is mostly here to provide an excuse for the index entries...
+.. This para is mostly here to provide an excuse for the index entries...
 
 A few of the more complicated operations only take 16-bit samples, otherwise the
 sample size (in bytes) is always a parameter of the operation.

Modified: python/branches/py3k-importlib/Doc/library/autogil.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/autogil.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/autogil.rst	Thu Mar 27 00:48:05 2008
@@ -9,8 +9,8 @@
 
 
 The :mod:`autoGIL` module provides a function :func:`installAutoGIL` that
-automatically locks and unlocks Python's Global Interpreter Lock when running an
-event loop.
+automatically locks and unlocks Python's :term:`Global Interpreter Lock` when
+running an event loop.
 
 
 .. exception:: AutoGILError

Modified: python/branches/py3k-importlib/Doc/library/base64.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/base64.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/base64.rst	Thu Mar 27 00:48:05 2008
@@ -150,7 +150,7 @@
    :func:`encodestring` returns a string containing one or more lines of
    base64-encoded data always including an extra trailing newline (``'\n'``).
 
-An example usage of the module::
+An example usage of the module:
 
    >>> import base64
    >>> encoded = base64.b64encode('data to be encoded')

Modified: python/branches/py3k-importlib/Doc/library/basehttpserver.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/basehttpserver.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/basehttpserver.rst	Thu Mar 27 00:48:05 2008
@@ -122,6 +122,15 @@
    class variable.
 
 
+.. attribute:: BaseHTTPRequestHandler.error_content_type
+
+   Specifies the Content-Type HTTP header of error responses sent to the client.
+   The default value is ``'text/html'``.
+
+   .. versionadded:: 2.6
+      Previously, the content type was always ``'text/html'``.
+
+
 .. attribute:: BaseHTTPRequestHandler.protocol_version
 
    This specifies the HTTP protocol version used in responses.  If set to

Modified: python/branches/py3k-importlib/Doc/library/bdb.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/bdb.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/bdb.rst	Thu Mar 27 00:48:05 2008
@@ -1,337 +1,337 @@
-:mod:`bdb` --- Debugger framework
-=================================
-
-.. module:: bdb
-   :synopsis: Debugger framework.
-
-The :mod:`bdb` module handles basic debugger functions, like setting breakpoints
-or managing execution via the debugger.
-
-The following exception is defined:
-
-.. exception:: BdbQuit
-
-   Exception raised by the :class:`Bdb` class for quitting the debugger.
-
-
-The :mod:`bdb` module also defines two classes:
-
-.. class:: Breakpoint(self, file, line[, temporary=0[, cond=None [, funcname=None]]])
-
-   This class implements temporary breakpoints, ignore counts, disabling and
-   (re-)enabling, and conditionals.
-
-   Breakpoints are indexed by number through a list called :attr:`bpbynumber`
-   and by ``(file, line)`` pairs through :attr:`bplist`.  The former points to a
-   single instance of class :class:`Breakpoint`.  The latter points to a list of
-   such instances since there may be more than one breakpoint per line.
-
-   When creating a breakpoint, its associated filename should be in canonical
-   form.  If a *funcname* is defined, a breakpoint hit will be counted when the
-   first line of that function is executed.  A conditional breakpoint always
-   counts a hit.
-
-:class:`Breakpoint` instances have the following methods:
-
-.. method:: Breakpoint.deleteMe()
-
-   Delete the breakpoint from the list associated to a file/line.  If it is the
-   last breakpoint in that position, it also deletes the entry for the
-   file/line.
-
-.. method:: Breakpoint.enable()
-
-   Mark the breakpoint as enabled.
-
-.. method:: Breakpoint.disable()
-
-   Mark the breakpoint as disabled.
-
-.. method:: Breakpoint.bpprint([out])
-
-   Print all the information about the breakpoint:
-
-   * The breakpoint number.
-   * If it is temporary or not.
-   * Its file,line position.
-   * The condition that causes a break.
-   * If it must be ignored the next N times.
-   * The breakpoint hit count.
-
-
-.. class:: Bdb()
-
-   The :class:`Bdb` acts as a generic Python debugger base class.
-
-   This class takes care of the details of the trace facility; a derived class
-   should implement user interaction.  The standard debugger class
-   (:class:`pdb.Pdb`) is an example.
-
-
-The following methods of :class:`Bdb` normally don't need to be overridden.
-
-.. method:: Bdb.canonic(filename)
-
-   Auxiliary method for getting a filename in a canonical form, that is, as a
-   case-normalized (on case-insensitive filesystems) absolute path, stripped
-   of surrounding angle brackets.
-
-.. method:: Bdb.reset()
-
-   Set the :attr:`botframe`, :attr:`stopframe`, :attr:`returnframe` and
-   :attr:`quitting` attributes with values ready to start debugging.
-
-
-.. method:: Bdb.trace_dispatch(frame, event, arg)
-
-   This function is installed as the trace function of debugged frames.  Its
-   return value is the new trace function (in most cases, that is, itself).
-
-   The default implementation decides how to dispatch a frame, depending on the
-   type of event (passed as a string) that is about to be executed.  *event* can
-   be one of the following:
-
-   * ``"line"``: A new line of code is going to be executed.
-   * ``"call"``: A function is about to be called, or another code block
-     entered.
-   * ``"return"``: A function or other code block is about to return.
-   * ``"exception"``: An exception has occurred.
-   * ``"c_call"``: A C function is about to be called.
-   * ``"c_return"``: A C function has returned.
-   * ``"c_exception"``: A C function has thrown an exception.
-
-   For the Python events, specialized functions (see below) are called.  For the
-   C events, no action is taken.
-
-   The *arg* parameter depends on the previous event.
-
-   For more information on trace functions, see :ref:`debugger-hooks`.  For more
-   information on code and frame objects, refer to :ref:`types`.
-
-.. method:: Bdb.dispatch_line(frame)
-
-   If the debugger should stop on the current line, invoke the :meth:`user_line`
-   method (which should be overridden in subclasses).  Raise a :exc:`BdbQuit`
-   exception if the :attr:`Bdb.quitting` flag is set (which can be set from
-   :meth:`user_line`).  Return a reference to the :meth:`trace_dispatch` method
-   for further tracing in that scope.
-
-.. method:: Bdb.dispatch_call(frame, arg)
-
-   If the debugger should stop on this function call, invoke the
-   :meth:`user_call` method (which should be overridden in subclasses).  Raise a
-   :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set (which can
-   be set from :meth:`user_call`).  Return a reference to the
-   :meth:`trace_dispatch` method for further tracing in that scope.
-
-.. method:: Bdb.dispatch_return(frame, arg)
-
-   If the debugger should stop on this function return, invoke the
-   :meth:`user_return` method (which should be overridden in subclasses).  Raise
-   a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set (which can
-   be set from :meth:`user_return`).  Return a reference to the
-   :meth:`trace_dispatch` method for further tracing in that scope.
-
-.. method:: Bdb.dispatch_exception(frame, arg)
-
-   If the debugger should stop at this exception, invokes the
-   :meth:`user_exception` method (which should be overridden in subclasses).
-   Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set
-   (which can be set from :meth:`user_exception`).  Return a reference to the
-   :meth:`trace_dispatch` method for further tracing in that scope.
-
-Normally derived classes don't override the following methods, but they may if
-they want to redefine the definition of stopping and breakpoints.
-
-.. method:: Bdb.stop_here(frame)
-
-   This method checks if the *frame* is somewhere below :attr:`botframe` in the
-   call stack.  :attr:`botframe` is the frame in which debugging started.
-
-.. method:: Bdb.break_here(frame)
-
-   This method checks if there is a breakpoint in the filename and line
-   belonging to *frame* or, at least, in the current function.  If the
-   breakpoint is a temporary one, this method deletes it.
-
-.. method:: Bdb.break_anywhere(frame)
-
-   This method checks if there is a breakpoint in the filename of the current
-   frame.
-
-Derived classes should override these methods to gain control over debugger
-operation.
-
-.. method:: Bdb.user_call(frame, argument_list)
-
-   This method is called from :meth:`dispatch_call` when there is the
-   possibility that a break might be necessary anywhere inside the called
-   function.
-
-.. method:: Bdb.user_line(frame)
-
-   This method is called from :meth:`dispatch_line` when either
-   :meth:`stop_here` or :meth:`break_here` yields True.
-
-.. method:: Bdb.user_return(frame, return_value)
-
-   This method is called from :meth:`dispatch_return` when :meth:`stop_here`
-   yields True.
-
-.. method:: Bdb.user_exception(frame, exc_info)
-
-   This method is called from :meth:`dispatch_exception` when :meth:`stop_here`
-   yields True.
-
-.. method:: Bdb.do_clear(arg)
-
-   Handle how a breakpoint must be removed when it is a temporary one.
-
-   This method must be implemented by derived classes.
-
-
-Derived classes and clients can call the following methods to affect the 
-stepping state.
-
-.. method:: Bdb.set_step()
-
-   Stop after one line of code.
-
-.. method:: Bdb.set_next(frame)
-
-   Stop on the next line in or below the given frame.
-
-.. method:: Bdb.set_return(frame)
-
-   Stop when returning from the given frame.
-
-.. method:: Bdb.set_trace([frame])
-
-   Start debugging from *frame*.  If *frame* is not specified, debugging starts
-   from caller's frame.
-
-.. method:: Bdb.set_continue()
-
-   Stop only at breakpoints or when finished.  If there are no breakpoints, set
-   the system trace function to None.
-
-.. method:: Bdb.set_quit()
-
-   Set the :attr:`quitting` attribute to True.  This raises :exc:`BdbQuit` in
-   the next call to one of the :meth:`dispatch_\*` methods.
-
-
-Derived classes and clients can call the following methods to manipulate
-breakpoints.  These methods return a string containing an error message if
-something went wrong, or ``None`` if all is well.
-
-.. method:: Bdb.set_break(filename, lineno[, temporary=0[, cond[, funcname]]])
-
-   Set a new breakpoint.  If the *lineno* line doesn't exist for the *filename*
-   passed as argument, return an error message.  The *filename* should be in
-   canonical form, as described in the :meth:`canonic` method.
-
-.. method:: Bdb.clear_break(filename, lineno)
-
-   Delete the breakpoints in *filename* and *lineno*.  If none were set, an
-   error message is returned.
-
-.. method:: Bdb.clear_bpbynumber(arg)
-
-   Delete the breakpoint which has the index *arg* in the
-   :attr:`Breakpoint.bpbynumber`.  If `arg` is not numeric or out of range,
-   return an error message.
-
-.. method:: Bdb.clear_all_file_breaks(filename)
-
-   Delete all breakpoints in *filename*.  If none were set, an error message is
-   returned.
-
-.. method:: Bdb.clear_all_breaks()
-
-   Delete all existing breakpoints.
-
-.. method:: Bdb.get_break(filename, lineno)
-
-   Check if there is a breakpoint for *lineno* of *filename*.
-
-.. method:: Bdb.get_breaks(filename, lineno)
-
-   Return all breakpoints for *lineno* in *filename*, or an empty list if none
-   are set.
-
-.. method:: Bdb.get_file_breaks(filename)
-
-   Return all breakpoints in *filename*, or an empty list if none are set.
-
-.. method:: Bdb.get_all_breaks()
-
-   Return all breakpoints that are set.
-
-
-Derived classes and clients can call the following methods to get a data
-structure representing a stack trace.
-
-.. method:: Bdb.get_stack(f, t)
-
-   Get a list of records for a frame and all higher (calling) and lower frames,
-   and the size of the higher part.
-
-.. method:: Bdb.format_stack_entry(frame_lineno, [lprefix=': '])
-
-   Return a string with information about a stack entry, identified by a
-   ``(frame, lineno)`` tuple:
-
-   * The canonical form of the filename which contains the frame.
-   * The function name, or ``"<lambda>"``.
-   * The input arguments.
-   * The return value.
-   * The line of code (if it exists).
-
-
-The following two methods can be called by clients to use a debugger to debug a
-statement, given as a string.
-
-.. method:: Bdb.run(cmd, [globals, [locals]])
-
-   Debug a statement executed via the :func:`exec` function.  *globals*
-   defaults to :attr:`__main__.__dict__`, *locals* defaults to *globals*.
-
-.. method:: Bdb.runeval(expr, [globals, [locals]])
-
-   Debug an expression executed via the :func:`eval` function.  *globals* and
-   *locals* have the same meaning as in :meth:`run`.
-
-.. method:: Bdb.runctx(cmd, globals, locals)
-
-   For backwards compatibility.  Calls the :meth:`run` method.
-
-.. method:: Bdb.runcall(func, *args, **kwds)
-
-   Debug a single function call, and return its result.
-
-
-Finally, the module defines the following functions:
-
-.. function:: checkfuncname(b, frame)
-
-   Check whether we should break here, depending on the way the breakpoint *b*
-   was set.
-   
-   If it was set via line number, it checks if ``b.line`` is the same as the one
-   in the frame also passed as argument.  If the breakpoint was set via function
-   name, we have to check we are in the right frame (the right function) and if
-   we are in its first executable line.
-
-.. function:: effective(file, line, frame)
-
-   Determine if there is an effective (active) breakpoint at this line of code.
-   Return breakpoint number or 0 if none.
-	
-   Called only if we know there is a breakpoint at this location.  Returns the
-   breakpoint that was triggered and a flag that indicates if it is ok to delete
-   a temporary breakpoint.
-
-.. function:: set_trace()
-
-   Starts debugging with a :class:`Bdb` instance from caller's frame.
+:mod:`bdb` --- Debugger framework
+=================================
+
+.. module:: bdb
+   :synopsis: Debugger framework.
+
+The :mod:`bdb` module handles basic debugger functions, like setting breakpoints
+or managing execution via the debugger.
+
+The following exception is defined:
+
+.. exception:: BdbQuit
+
+   Exception raised by the :class:`Bdb` class for quitting the debugger.
+
+
+The :mod:`bdb` module also defines two classes:
+
+.. class:: Breakpoint(self, file, line[, temporary=0[, cond=None [, funcname=None]]])
+
+   This class implements temporary breakpoints, ignore counts, disabling and
+   (re-)enabling, and conditionals.
+
+   Breakpoints are indexed by number through a list called :attr:`bpbynumber`
+   and by ``(file, line)`` pairs through :attr:`bplist`.  The former points to a
+   single instance of class :class:`Breakpoint`.  The latter points to a list of
+   such instances since there may be more than one breakpoint per line.
+
+   When creating a breakpoint, its associated filename should be in canonical
+   form.  If a *funcname* is defined, a breakpoint hit will be counted when the
+   first line of that function is executed.  A conditional breakpoint always
+   counts a hit.
+
+:class:`Breakpoint` instances have the following methods:
+
+.. method:: Breakpoint.deleteMe()
+
+   Delete the breakpoint from the list associated to a file/line.  If it is the
+   last breakpoint in that position, it also deletes the entry for the
+   file/line.
+
+.. method:: Breakpoint.enable()
+
+   Mark the breakpoint as enabled.
+
+.. method:: Breakpoint.disable()
+
+   Mark the breakpoint as disabled.
+
+.. method:: Breakpoint.bpprint([out])
+
+   Print all the information about the breakpoint:
+
+   * The breakpoint number.
+   * If it is temporary or not.
+   * Its file,line position.
+   * The condition that causes a break.
+   * If it must be ignored the next N times.
+   * The breakpoint hit count.
+
+
+.. class:: Bdb()
+
+   The :class:`Bdb` acts as a generic Python debugger base class.
+
+   This class takes care of the details of the trace facility; a derived class
+   should implement user interaction.  The standard debugger class
+   (:class:`pdb.Pdb`) is an example.
+
+
+The following methods of :class:`Bdb` normally don't need to be overridden.
+
+.. method:: Bdb.canonic(filename)
+
+   Auxiliary method for getting a filename in a canonical form, that is, as a
+   case-normalized (on case-insensitive filesystems) absolute path, stripped
+   of surrounding angle brackets.
+
+.. method:: Bdb.reset()
+
+   Set the :attr:`botframe`, :attr:`stopframe`, :attr:`returnframe` and
+   :attr:`quitting` attributes with values ready to start debugging.
+
+
+.. method:: Bdb.trace_dispatch(frame, event, arg)
+
+   This function is installed as the trace function of debugged frames.  Its
+   return value is the new trace function (in most cases, that is, itself).
+
+   The default implementation decides how to dispatch a frame, depending on the
+   type of event (passed as a string) that is about to be executed.  *event* can
+   be one of the following:
+
+   * ``"line"``: A new line of code is going to be executed.
+   * ``"call"``: A function is about to be called, or another code block
+     entered.
+   * ``"return"``: A function or other code block is about to return.
+   * ``"exception"``: An exception has occurred.
+   * ``"c_call"``: A C function is about to be called.
+   * ``"c_return"``: A C function has returned.
+   * ``"c_exception"``: A C function has thrown an exception.
+
+   For the Python events, specialized functions (see below) are called.  For the
+   C events, no action is taken.
+
+   The *arg* parameter depends on the previous event.
+
+   For more information on trace functions, see :ref:`debugger-hooks`.  For more
+   information on code and frame objects, refer to :ref:`types`.
+
+.. method:: Bdb.dispatch_line(frame)
+
+   If the debugger should stop on the current line, invoke the :meth:`user_line`
+   method (which should be overridden in subclasses).  Raise a :exc:`BdbQuit`
+   exception if the :attr:`Bdb.quitting` flag is set (which can be set from
+   :meth:`user_line`).  Return a reference to the :meth:`trace_dispatch` method
+   for further tracing in that scope.
+
+.. method:: Bdb.dispatch_call(frame, arg)
+
+   If the debugger should stop on this function call, invoke the
+   :meth:`user_call` method (which should be overridden in subclasses).  Raise a
+   :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set (which can
+   be set from :meth:`user_call`).  Return a reference to the
+   :meth:`trace_dispatch` method for further tracing in that scope.
+
+.. method:: Bdb.dispatch_return(frame, arg)
+
+   If the debugger should stop on this function return, invoke the
+   :meth:`user_return` method (which should be overridden in subclasses).  Raise
+   a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set (which can
+   be set from :meth:`user_return`).  Return a reference to the
+   :meth:`trace_dispatch` method for further tracing in that scope.
+
+.. method:: Bdb.dispatch_exception(frame, arg)
+
+   If the debugger should stop at this exception, invokes the
+   :meth:`user_exception` method (which should be overridden in subclasses).
+   Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set
+   (which can be set from :meth:`user_exception`).  Return a reference to the
+   :meth:`trace_dispatch` method for further tracing in that scope.
+
+Normally derived classes don't override the following methods, but they may if
+they want to redefine the definition of stopping and breakpoints.
+
+.. method:: Bdb.stop_here(frame)
+
+   This method checks if the *frame* is somewhere below :attr:`botframe` in the
+   call stack.  :attr:`botframe` is the frame in which debugging started.
+
+.. method:: Bdb.break_here(frame)
+
+   This method checks if there is a breakpoint in the filename and line
+   belonging to *frame* or, at least, in the current function.  If the
+   breakpoint is a temporary one, this method deletes it.
+
+.. method:: Bdb.break_anywhere(frame)
+
+   This method checks if there is a breakpoint in the filename of the current
+   frame.
+
+Derived classes should override these methods to gain control over debugger
+operation.
+
+.. method:: Bdb.user_call(frame, argument_list)
+
+   This method is called from :meth:`dispatch_call` when there is the
+   possibility that a break might be necessary anywhere inside the called
+   function.
+
+.. method:: Bdb.user_line(frame)
+
+   This method is called from :meth:`dispatch_line` when either
+   :meth:`stop_here` or :meth:`break_here` yields True.
+
+.. method:: Bdb.user_return(frame, return_value)
+
+   This method is called from :meth:`dispatch_return` when :meth:`stop_here`
+   yields True.
+
+.. method:: Bdb.user_exception(frame, exc_info)
+
+   This method is called from :meth:`dispatch_exception` when :meth:`stop_here`
+   yields True.
+
+.. method:: Bdb.do_clear(arg)
+
+   Handle how a breakpoint must be removed when it is a temporary one.
+
+   This method must be implemented by derived classes.
+
+
+Derived classes and clients can call the following methods to affect the 
+stepping state.
+
+.. method:: Bdb.set_step()
+
+   Stop after one line of code.
+
+.. method:: Bdb.set_next(frame)
+
+   Stop on the next line in or below the given frame.
+
+.. method:: Bdb.set_return(frame)
+
+   Stop when returning from the given frame.
+
+.. method:: Bdb.set_trace([frame])
+
+   Start debugging from *frame*.  If *frame* is not specified, debugging starts
+   from caller's frame.
+
+.. method:: Bdb.set_continue()
+
+   Stop only at breakpoints or when finished.  If there are no breakpoints, set
+   the system trace function to None.
+
+.. method:: Bdb.set_quit()
+
+   Set the :attr:`quitting` attribute to True.  This raises :exc:`BdbQuit` in
+   the next call to one of the :meth:`dispatch_\*` methods.
+
+
+Derived classes and clients can call the following methods to manipulate
+breakpoints.  These methods return a string containing an error message if
+something went wrong, or ``None`` if all is well.
+
+.. method:: Bdb.set_break(filename, lineno[, temporary=0[, cond[, funcname]]])
+
+   Set a new breakpoint.  If the *lineno* line doesn't exist for the *filename*
+   passed as argument, return an error message.  The *filename* should be in
+   canonical form, as described in the :meth:`canonic` method.
+
+.. method:: Bdb.clear_break(filename, lineno)
+
+   Delete the breakpoints in *filename* and *lineno*.  If none were set, an
+   error message is returned.
+
+.. method:: Bdb.clear_bpbynumber(arg)
+
+   Delete the breakpoint which has the index *arg* in the
+   :attr:`Breakpoint.bpbynumber`.  If `arg` is not numeric or out of range,
+   return an error message.
+
+.. method:: Bdb.clear_all_file_breaks(filename)
+
+   Delete all breakpoints in *filename*.  If none were set, an error message is
+   returned.
+
+.. method:: Bdb.clear_all_breaks()
+
+   Delete all existing breakpoints.
+
+.. method:: Bdb.get_break(filename, lineno)
+
+   Check if there is a breakpoint for *lineno* of *filename*.
+
+.. method:: Bdb.get_breaks(filename, lineno)
+
+   Return all breakpoints for *lineno* in *filename*, or an empty list if none
+   are set.
+
+.. method:: Bdb.get_file_breaks(filename)
+
+   Return all breakpoints in *filename*, or an empty list if none are set.
+
+.. method:: Bdb.get_all_breaks()
+
+   Return all breakpoints that are set.
+
+
+Derived classes and clients can call the following methods to get a data
+structure representing a stack trace.
+
+.. method:: Bdb.get_stack(f, t)
+
+   Get a list of records for a frame and all higher (calling) and lower frames,
+   and the size of the higher part.
+
+.. method:: Bdb.format_stack_entry(frame_lineno, [lprefix=': '])
+
+   Return a string with information about a stack entry, identified by a
+   ``(frame, lineno)`` tuple:
+
+   * The canonical form of the filename which contains the frame.
+   * The function name, or ``"<lambda>"``.
+   * The input arguments.
+   * The return value.
+   * The line of code (if it exists).
+
+
+The following two methods can be called by clients to use a debugger to debug a
+statement, given as a string.
+
+.. method:: Bdb.run(cmd, [globals, [locals]])
+
+   Debug a statement executed via the :func:`exec` function.  *globals*
+   defaults to :attr:`__main__.__dict__`, *locals* defaults to *globals*.
+
+.. method:: Bdb.runeval(expr, [globals, [locals]])
+
+   Debug an expression executed via the :func:`eval` function.  *globals* and
+   *locals* have the same meaning as in :meth:`run`.
+
+.. method:: Bdb.runctx(cmd, globals, locals)
+
+   For backwards compatibility.  Calls the :meth:`run` method.
+
+.. method:: Bdb.runcall(func, *args, **kwds)
+
+   Debug a single function call, and return its result.
+
+
+Finally, the module defines the following functions:
+
+.. function:: checkfuncname(b, frame)
+
+   Check whether we should break here, depending on the way the breakpoint *b*
+   was set.
+   
+   If it was set via line number, it checks if ``b.line`` is the same as the one
+   in the frame also passed as argument.  If the breakpoint was set via function
+   name, we have to check we are in the right frame (the right function) and if
+   we are in its first executable line.
+
+.. function:: effective(file, line, frame)
+
+   Determine if there is an effective (active) breakpoint at this line of code.
+   Return breakpoint number or 0 if none.
+	
+   Called only if we know there is a breakpoint at this location.  Returns the
+   breakpoint that was triggered and a flag that indicates if it is ok to delete
+   a temporary breakpoint.
+
+.. function:: set_trace()
+
+   Starts debugging with a :class:`Bdb` instance from caller's frame.

Modified: python/branches/py3k-importlib/Doc/library/bisect.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/bisect.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/bisect.rst	Thu Mar 27 00:48:05 2008
@@ -5,11 +5,7 @@
 .. module:: bisect
    :synopsis: Array bisection algorithms for binary searching.
 .. sectionauthor:: Fred L. Drake, Jr. <fdrake at acm.org>
-
-
-.. % LaTeX produced by Fred L. Drake, Jr. <fdrake at acm.org>, with an
-.. % example based on the PyModules FAQ entry by Aaron Watters
-.. % <arw at pythonpros.com>.
+.. example based on the PyModules FAQ entry by Aaron Watters <arw at pythonpros.com>
 
 This module provides support for maintaining a list in sorted order without
 having to sort the list after each insertion.  For long lists of items with
@@ -68,7 +64,7 @@
 The :func:`bisect` function is generally useful for categorizing numeric data.
 This example uses :func:`bisect` to look up a letter grade for an exam total
 (say) based on a set of ordered numeric breakpoints: 85 and up is an 'A', 75..84
-is a 'B', etc. ::
+is a 'B', etc.
 
    >>> grades = "FEDCBA"
    >>> breakpoints = [30, 44, 66, 75, 85]

Modified: python/branches/py3k-importlib/Doc/library/bsddb.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/bsddb.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/bsddb.rst	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,7 @@
 
 .. module:: bsddb
    :synopsis: Interface to Berkeley DB database library
-.. sectionauthor:: Skip Montanaro <skip at mojam.com>
+.. sectionauthor:: Skip Montanaro <skip at pobox.com>
 
 
 The :mod:`bsddb` module provides an interface to the Berkeley DB library.  Users

Modified: python/branches/py3k-importlib/Doc/library/bz2.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/bz2.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/bz2.rst	Thu Mar 27 00:48:05 2008
@@ -12,7 +12,10 @@
 It implements a complete file interface, one-shot (de)compression functions, and
 types for sequential (de)compression.
 
-Here is a resume of the features offered by the bz2 module:
+For other archive formats, see the :mod:`gzip`, :mod:`zipfile`, and
+:mod:`tarfile` modules.
+
+Here is a summary of the features offered by the bz2 module:
 
 * :class:`BZ2File` class implements a complete file interface, including
   :meth:`readline`, :meth:`readlines`, :meth:`writelines`, :meth:`seek`, etc;
@@ -30,9 +33,7 @@
 * One-shot (de)compression supported by :func:`compress` and :func:`decompress`
   functions;
 
-* Thread safety uses individual locking mechanism;
-
-* Complete inline documentation;
+* Thread safety uses individual locking mechanism.
 
 
 (De)compression of files
@@ -98,7 +99,7 @@
 
 .. method:: BZ2File.tell()
 
-   Return the current file position, an integer (may be a long integer).
+   Return the current file position, an integer.
 
 
 .. method:: BZ2File.write(data)

Modified: python/branches/py3k-importlib/Doc/library/calendar.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/calendar.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/calendar.rst	Thu Mar 27 00:48:05 2008
@@ -37,9 +37,9 @@
 
 .. method:: Calendar.iterweekdays(weekday)
 
-   Return an iterator for the week day numbers that will be used for one week. The
-   first number from the iterator will be the same as the number returned by
-   :meth:`firstweekday`.
+   Return an iterator for the week day numbers that will be used for one week.
+   The first value from the iterator will be the same as the value of the
+   :attr:`firstweekday` property.
 
 
 .. method:: Calendar.itermonthdates(year, month)
@@ -81,22 +81,22 @@
    Weeks are lists of seven day numbers.
 
 
-.. method:: Calendar.yeardatescalendar(year, month[, width])
+.. method:: Calendar.yeardatescalendar(year[, width])
 
-   Return the data for the specified year ready for formatting. The return value is
-   a list of month rows. Each month row contains up to *width* months (defaulting
-   to 3). Each month contains between 4 and 6 weeks and each week contains 1--7
-   days. Days are :class:`datetime.date` objects.
+   Return the data for the specified year ready for formatting. The return value
+   is a list of month rows. Each month row contains up to *width* months
+   (defaulting to 3). Each month contains between 4 and 6 weeks and each week
+   contains 1--7 days. Days are :class:`datetime.date` objects.
 
 
-.. method:: Calendar.yeardays2calendar(year, month[, width])
+.. method:: Calendar.yeardays2calendar(year[, width])
 
    Return the data for the specified year ready for formatting (similar to
-   :meth:`yeardatescalendar`). Entries in the week lists are tuples of day numbers
-   and weekday numbers. Day numbers outside this month are zero.
+   :meth:`yeardatescalendar`). Entries in the week lists are tuples of day
+   numbers and weekday numbers. Day numbers outside this month are zero.
 
 
-.. method:: Calendar.yeardayscalendar(year, month[, width])
+.. method:: Calendar.yeardayscalendar(year[, width])
 
    Return the data for the specified year ready for formatting (similar to
    :meth:`yeardatescalendar`). Entries in the week lists are day numbers. Day
@@ -113,9 +113,10 @@
 .. method:: TextCalendar.formatmonth(theyear, themonth[, w[, l]])
 
    Return a month's calendar in a multi-line string. If *w* is provided, it
-   specifies the width of the date columns, which are centered. If *l* is given, it
-   specifies the number of lines that each week will use. Depends on the first
-   weekday as set by :func:`setfirstweekday`.
+   specifies the width of the date columns, which are centered. If *l* is given,
+   it specifies the number of lines that each week will use. Depends on the
+   first weekday as specified in the constructor or set by the
+   :meth:`setfirstweekday` method.
 
 
 .. method:: TextCalendar.prmonth(theyear, themonth[, w[, l]])
@@ -125,11 +126,12 @@
 
 .. method:: TextCalendar.formatyear(theyear, themonth[, w[, l[, c[, m]]]])
 
-   Return a *m*-column calendar for an entire year as a multi-line string. Optional
-   parameters *w*, *l*, and *c* are for date column width, lines per week, and
-   number of spaces between month columns, respectively. Depends on the first
-   weekday as set by :meth:`setfirstweekday`.  The earliest year for which a
-   calendar can be generated is platform-dependent.
+   Return a *m*-column calendar for an entire year as a multi-line string.
+   Optional parameters *w*, *l*, and *c* are for date column width, lines per
+   week, and number of spaces between month columns, respectively. Depends on
+   the first weekday as specified in the constructor or set by the
+   :meth:`setfirstweekday` method.  The earliest year for which a calendar can
+   be generated is platform-dependent.
 
 
 .. method:: TextCalendar.pryear(theyear[, w[, l[, c[, m]]]])

Modified: python/branches/py3k-importlib/Doc/library/cgi.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/cgi.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/cgi.rst	Thu Mar 27 00:48:05 2008
@@ -176,7 +176,7 @@
 sections obsolete --- they are still useful to process file uploads efficiently,
 for example.
 
-.. % XXX: Is this true ?
+.. XXX: Is this true ?
 
 The interface consists of two simple methods. Using the methods you can process
 form data in a generic way, without the need to worry whether only one or more

Modified: python/branches/py3k-importlib/Doc/library/codecs.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/codecs.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/codecs.rst	Thu Mar 27 00:48:05 2008
@@ -202,7 +202,8 @@
 .. function:: open(filename, mode[, encoding[, errors[, buffering]]])
 
    Open an encoded file using the given *mode* and return a wrapped version
-   providing transparent encoding/decoding.
+   providing transparent encoding/decoding.  The default file mode is ``'r'``
+   meaning to open the file in read mode.
 
    .. note::
 
@@ -210,6 +211,13 @@
       i.e. Unicode objects for most built-in codecs.  Output is also codec-dependent
       and will usually be Unicode as well.
 
+   .. note::
+
+      Files are always opened in binary mode, even if no binary mode was
+      specified.  This is done to avoid data loss due to encodings using 8-bit
+      values.  This means that no automatic conversion of ``'\n'`` is done
+      on reading and writing.
+
    *encoding* specifies the encoding which is to be used for the file.
 
    *errors* may be given to define the error handling. It defaults to ``'strict'``
@@ -238,15 +246,15 @@
 .. function:: iterencode(iterable, encoding[, errors])
 
    Uses an incremental encoder to iteratively encode the input provided by
-   *iterable*. This function is a generator. *errors* (as well as any other keyword
-   argument) is passed through to the incremental encoder.
+   *iterable*. This function is a :term:`generator`.  *errors* (as well as any
+   other keyword argument) is passed through to the incremental encoder.
 
 
 .. function:: iterdecode(iterable, encoding[, errors])
 
    Uses an incremental decoder to iteratively decode the input provided by
-   *iterable*. This function is a generator. *errors* (as well as any other keyword
-   argument) is passed through to the incremental decoder.
+   *iterable*. This function is a :term:`generator`.  *errors* (as well as any
+   other keyword argument) is passed through to the incremental decoder.
 
 The module also provides the following constants which are useful for reading
 and writing to platform dependent files:
@@ -751,7 +759,7 @@
 
 Unicode strings are stored internally as sequences of codepoints (to be precise
 as :ctype:`Py_UNICODE` arrays). Depending on the way Python is compiled (either
-via :option:`--enable-unicode=ucs2` or :option:`--enable-unicode=ucs4`, with the
+via :option:`--without-wide-unicode` or :option:`--with-wide-unicode`, with the
 former being the default) :ctype:`Py_UNICODE` is either a 16-bit or 32-bit data
 type. Once a Unicode object is used outside of CPU and memory, CPU endianness
 and how these arrays are stored as bytes become an issue.  Transforming a
@@ -1010,7 +1018,7 @@
 +-----------------+--------------------------------+--------------------------------+
 | iso8859_3       | iso-8859-3, latin3, L3         | Esperanto, Maltese             |
 +-----------------+--------------------------------+--------------------------------+
-| iso8859_4       | iso-8859-4, latin4, L4         | Baltic languagues              |
+| iso8859_4       | iso-8859-4, latin4, L4         | Baltic languages               |
 +-----------------+--------------------------------+--------------------------------+
 | iso8859_5       | iso-8859-5, cyrillic           | Bulgarian, Byelorussian,       |
 |                 |                                | Macedonian, Russian, Serbian   |

Modified: python/branches/py3k-importlib/Doc/library/codeop.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/codeop.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/codeop.rst	Thu Mar 27 00:48:05 2008
@@ -7,9 +7,6 @@
 .. sectionauthor:: Moshe Zadka <moshez at zadka.site.co.il>
 .. sectionauthor:: Michael Hudson <mwh at python.net>
 
-
-.. % LaTeXed from excellent doc-string.
-
 The :mod:`codeop` module provides utilities upon which the Python
 read-eval-print loop can be emulated, as is done in the :mod:`code` module.  As
 a result, you probably don't want to use the module directly; if you want to
@@ -29,7 +26,6 @@
 
 To do just the former:
 
-
 .. function:: compile_command(source[, filename[, symbol]])
 
    Tries to compile *source*, which should be a string of Python code and return a
@@ -43,8 +39,8 @@
    :exc:`OverflowError` or :exc:`ValueError` if there is an invalid literal.
 
    The *symbol* argument determines whether *source* is compiled as a statement
-   (``'single'``, the default) or as an expression (``'eval'``).  Any other value
-   will cause :exc:`ValueError` to  be raised.
+   (``'single'``, the default) or as an :term:`expression` (``'eval'``).  Any
+   other value will cause :exc:`ValueError` to  be raised.
 
    .. warning::
       

Modified: python/branches/py3k-importlib/Doc/library/collections.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/collections.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/collections.rst	Thu Mar 27 00:48:05 2008
@@ -1,72 +1,138 @@
 
-:mod:`collections` --- High-performance container datatypes
-===========================================================
+:mod:`collections` --- Container datatypes
+==========================================
 
 .. module:: collections
-   :synopsis: High-performance datatypes
+   :synopsis: Container datatypes
 .. moduleauthor:: Raymond Hettinger <python at rcn.com>
 .. sectionauthor:: Raymond Hettinger <python at rcn.com>
 
+.. testsetup:: *
+
+   from collections import *
+   import itertools
+   __name__ = '<doctest>'
 
 This module implements high-performance container datatypes.  Currently,
 there are two datatypes, :class:`deque` and :class:`defaultdict`, and
-one datatype factory function, :func:`NamedTuple`. Python already
-includes built-in containers, :class:`dict`, :class:`list`,
-:class:`set`, and :class:`tuple`. In addition, the optional :mod:`bsddb`
-module has a :meth:`bsddb.btopen` method that can be used to create in-memory
-or file based ordered dictionaries with string keys.
-
-Future editions of the standard library may include balanced trees and
-ordered dictionaries.
+one datatype factory function, :func:`namedtuple`. This module also
+provides the :class:`UserDict` and :class:`UserList` classes which may
+be useful when inheriting directly from :class:`dict` or
+:class:`list` isn't convenient.
+
+The specialized containers provided in this module provide alternatives
+to Python's general purpose built-in containers, :class:`dict`,
+:class:`list`, :class:`set`, and :class:`tuple`.
+Besides the containers provided here, the optional :mod:`bsddb`
+module offers the ability to create in-memory or file based ordered
+dictionaries with string keys using the :meth:`bsddb.btopen` method.
 
 In addition to containers, the collections module provides some ABCs
-(abstract base classes) that can be used to test whether
-a class provides a particular interface, for example, is it hashable or
-a mapping. The ABCs provided include those in the following table:
-
-=====================================  ========================================
-ABC                                    Notes
-=====================================  ========================================
-:class:`collections.Container`         Defines ``__contains__()``
-:class:`collections.Hashable`          Defines ``__hash__()``
-:class:`collections.Iterable`          Defines ``__iter__()``
-:class:`collections.Iterator`          Derived from :class:`Iterable` and in
-                                       addition defines ``__next__()``
-:class:`collections.Mapping`           Derived from :class:`Container`,
-                                       :class:`Iterable`,
-                                       and :class:`Sized`, and in addition
-                                       defines ``__getitem__()``, ``get()``,
-                                       ``__contains__()``, ``__len__()``,
-                                       ``__iter__()``, ``keys()``,
-                                       ``items()``, and ``values()``
-:class:`collections.MutableMapping`    Derived from :class:`Mapping`
-:class:`collections.MutableSequence`   Derived from :class:`Sequence`
-:class:`collections.MutableSet`        Derived from :class:`Set` and in
-                                       addition defines ``add()``,
-                                       ``clear()``, ``discard()``, ``pop()``,
-                                       and ``toggle()``
-:class:`collections.Sequence`          Derived from :class:`Container`,
-                                       :class:`Iterable`, and :class:`Sized`,
-                                       and in addition defines
-                                       ``__getitem__()``
-:class:`collections.Set`               Derived from :class:`Container`, :class:`Iterable`, and :class:`Sized`
-:class:`collections.Sized`             Defines ``__len__()``
-=====================================  ========================================
+(abstract base classes) that can be used to test whether a class
+provides a particular interface, for example, is it hashable or
+a mapping, and some of them can also be used as mixin classes.
+
+ABCs - abstract base classes
+----------------------------
 
-.. XXX Have not included them all and the notes are imcomplete
-.. Deliberately did one row wide to get a neater output
+The collections module offers the following ABCs:
+
+=========================  ====================  ======================  ====================================================
+ABC                        Inherits              Abstract Methods        Mixin Methods
+=========================  ====================  ======================  ====================================================
+:class:`Container`                               ``__contains__``
+:class:`Hashable`                                ``__hash__``
+:class:`Iterable`                                ``__iter__``
+:class:`Iterator`          :class:`Iterable`     ``__next__``            ``__iter__``
+:class:`Sized`          			 ``__len__``
+
+:class:`Mapping`           :class:`Sized`,       ``__getitem__``,        ``__contains__``, ``keys``, ``items``, ``values``,
+                           :class:`Iterable`,    ``__len__``. and        ``get``, ``__eq__``, and ``__ne__``
+                           :class:`Container`    ``__iter__``
+
+:class:`MutableMapping`    :class:`Mapping`      ``__getitem__``         Inherited Mapping methods and
+                                                 ``__setitem__``,        ``pop``, ``popitem``, ``clear``, ``update``,
+                                                 ``__delitem__``,        and ``setdefault``
+						 ``__iter__``, and
+                                                 ``__len__``
+
+:class:`Sequence`          :class:`Sized`,       ``__getitem__``         ``__contains__``. ``__iter__``, ``__reversed__``.
+                           :class:`Iterable`,    and ``__len__``         ``index``, and ``count``
+                           :class:`Container`
+
+:class:`MutableSequnce`    :class:`Sequence`     ``__getitem__``         Inherited Sequence methods and
+                                                 ``__delitem__``,        ``append``, ``reverse``, ``extend``, ``pop``,
+                                                 ``insert``,             ``remove``, and ``__iadd__``
+                                                 and ``__len__``
+
+:class:`Set`               :class:`Sized`,       ``__len__``,            ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``,
+                           :class:`Iterable`,    ``__iter__``, and       ``__gt__``, ``__ge__``, ``__and__``, ``__or__``
+                           :class:`Container`    ``__contains__``        ``__sub__``, ``__xor__``, and ``isdisjoint``
+
+:class:`MutableSet`        :class:`Set`          ``add`` and             Inherited Set methods and
+                                                 ``discard``             ``clear``, ``pop``, ``remove``, ``__ior__``,
+                                                                         ``__iand__``, ``__ixor__``, and ``__isub__``
+=========================  ====================  ======================  ====================================================
 
 These ABCs allow us to ask classes or instances if they provide
 particular functionality, for example::
 
-    from collections import Sized
-
     size = None
-    if isinstance(myvar, Sized):
+    if isinstance(myvar, collections.Sized):
 	size = len(myvar)
 
-(For more about ABCs, see the :mod:`abc` module and :pep:`3119`.)
+Several of the ABCs are also useful as mixins that make it easier to develop
+classes supporting container APIs.  For example, to write a class supporting
+the full :class:`Set` API, it only necessary to supply the three underlying
+abstract methods: :meth:`__contains__`, :meth:`__iter__`, and :meth:`__len__`.
+The ABC supplies the remaining methods such as :meth:`__and__` and
+:meth:`isdisjoint` ::
+
+    class ListBasedSet(collections.Set):
+         ''' Alternate set implementation favoring space over speed
+             and not requiring the set elements to be hashable. '''
+         def __init__(self, iterable):
+             self.elements = lst = []
+             for value in iterable:
+                 if value not in lst:
+                     lst.append(value)
+         def __iter__(self):
+             return iter(self.elements)
+         def __contains__(self, value):
+             return value in self.elements
+         def __len__(self):
+             return len(self.elements)
+
+    s1 = ListBasedSet('abcdef')
+    s2 = ListBasedSet('defghi')
+    overlap = s1 & s2            # The __and__() method is supported automatically
+
+Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
+
+(1)
+   Since some set operations create new sets, the default mixin methods need
+   a way to create new instances from an iterable. The class constructor is
+   assumed to have a signature in the form ``ClassName(iterable)``.
+   That assumption is factored-out to a single internal classmethod called
+   :meth:`_from_iterable` which calls ``cls(iterable)`` to produce a new set.
+   If the :class:`Set` mixin is being used in a class with a different
+   constructor signature, you will need to override :meth:`from_iterable`
+   with a classmethod that can construct new instances from
+   an iterable argument.
+
+(2)
+   To override the comparisons (presumably for speed, as the
+   semantics are fixed), redefine :meth:`__le__` and
+   then the other operations will automatically follow suit.
+
+(3)
+   The :class:`Set` mixin provides a :meth:`_hash` method to compute a hash value
+   for the set; however, :meth:`__hash__` is not defined because not all sets
+   are hashable or immutable.  To add set hashabilty using mixins,
+   inherit from both :meth:`Set` and :meth:`Hashable`, then define
+   ``__hash__ = Set._hash``.
 
+(For more about ABCs, see the :mod:`abc` module and :pep:`3119`.)
 
 
 .. _deque-objects:
@@ -75,7 +141,7 @@
 ----------------------
 
 
-.. class:: deque([iterable])
+.. class:: deque([iterable[, maxlen]])
 
    Returns a new deque object initialized left-to-right (using :meth:`append`) with
    data from *iterable*.  If *iterable* is not specified, the new deque is empty.
@@ -91,6 +157,15 @@
    position of the underlying data representation.
 
 
+   If *maxlen* is not specified or is *None*, deques may grow to an
+   arbitrary length.  Otherwise, the deque is bounded to the specified maximum
+   length.  Once a bounded length deque is full, when new items are added, a
+   corresponding number of items are discarded from the opposite end.  Bounded
+   length deques provide functionality similar to the ``tail`` filter in
+   Unix. They are also useful for tracking transactions and other pools of data
+   where only the most recent activity is of interest.
+
+
 Deque objects support the following methods:
 
 .. method:: deque.append(x)
@@ -149,12 +224,14 @@
 ``reversed(d)``, ``copy.copy(d)``, ``copy.deepcopy(d)``, membership testing with
 the :keyword:`in` operator, and subscript references such as ``d[-1]``.
 
-Example::
+Example:
+
+.. doctest::
 
    >>> from collections import deque
    >>> d = deque('ghi')                 # make a new deque with three items
    >>> for elem in d:                   # iterate over the deque's elements
-   ...     print(elem.upper())
+   ...     print elem.upper()
    G
    H
    I
@@ -205,8 +282,8 @@
 
 .. _deque-recipes:
 
-Recipes
-^^^^^^^
+:class:`deque` Recipes
+^^^^^^^^^^^^^^^^^^^^^^
 
 This section shows various approaches to working with deques.
 
@@ -223,45 +300,17 @@
 :meth:`rotate` to bring a target element to the left side of the deque. Remove
 old entries with :meth:`popleft`, add new entries with :meth:`extend`, and then
 reverse the rotation.
-
 With minor variations on that approach, it is easy to implement Forth style
 stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``,
 ``rot``, and ``roll``.
 
-A roundrobin task server can be built from a :class:`deque` using
-:meth:`popleft` to select the current task and :meth:`append` to add it back to
-the tasklist if the input stream is not exhausted::
-
-   >>> def roundrobin(*iterables):
-   ...     pending = deque(iter(i) for i in iterables)
-   ...     while pending:
-   ...         task = pending.popleft()
-   ...         try:
-   ...             yield next(task)
-   ...         except StopIteration:
-   ...             continue
-   ...         pending.append(task)
-   ...
-   >>> for value in roundrobin('abc', 'd', 'efgh'):
-   ...     print(value)
-
-   a
-   d
-   e
-   b
-   f
-   c
-   g
-   h
-
-
 Multi-pass data reduction algorithms can be succinctly expressed and efficiently
 coded by extracting elements with multiple calls to :meth:`popleft`, applying
-the reduction function, and calling :meth:`append` to add the result back to the
-queue.
+a reduction function, and calling :meth:`append` to add the result back to the
+deque.
 
 For example, building a balanced binary tree of nested lists entails reducing
-two adjacent nodes into one by grouping them in a list::
+two adjacent nodes into one by grouping them in a list:
 
    >>> def maketree(iterable):
    ...     d = deque(iterable)
@@ -273,7 +322,12 @@
    >>> print(maketree('abcdefgh'))
    [[[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]]
 
+Bounded length deques provide functionality similar to the ``tail`` filter
+in Unix::
 
+   def tail(filename, n=10):
+       'Return the last n lines of a file'
+       return deque(open(filename), n)
 
 .. _defaultdict-objects:
 
@@ -328,7 +382,7 @@
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 Using :class:`list` as the :attr:`default_factory`, it is easy to group a
-sequence of key-value pairs into a dictionary of lists::
+sequence of key-value pairs into a dictionary of lists:
 
    >>> s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
    >>> d = defaultdict(list)
@@ -344,7 +398,7 @@
 operation then attaches the value to the new list.  When keys are encountered
 again, the look-up proceeds normally (returning the list for that key) and the
 :meth:`list.append` operation adds another value to the list. This technique is
-simpler and faster than an equivalent technique using :meth:`dict.setdefault`::
+simpler and faster than an equivalent technique using :meth:`dict.setdefault`:
 
    >>> d = {}
    >>> for k, v in s:
@@ -355,7 +409,7 @@
 
 Setting the :attr:`default_factory` to :class:`int` makes the
 :class:`defaultdict` useful for counting (like a bag or multiset in other
-languages)::
+languages):
 
    >>> s = 'mississippi'
    >>> d = defaultdict(int)
@@ -372,7 +426,7 @@
 The function :func:`int` which always returns zero is just a special case of
 constant functions.  A faster and more flexible way to create constant functions
 is to use a lambda function which can supply any constant value (not just
-zero)::
+zero):
 
    >>> def constant_factory(value):
    ...     return lambda: value
@@ -382,7 +436,7 @@
    'John ran to <missing>'
 
 Setting the :attr:`default_factory` to :class:`set` makes the
-:class:`defaultdict` useful for building a dictionary of sets::
+:class:`defaultdict` useful for building a dictionary of sets:
 
    >>> s = [('red', 1), ('blue', 2), ('red', 3), ('blue', 4), ('red', 1), ('blue', 4)]
    >>> d = defaultdict(set)
@@ -395,53 +449,84 @@
 
 .. _named-tuple-factory:
 
-:func:`NamedTuple` Factory Function for Tuples with Named Fields
+:func:`namedtuple` Factory Function for Tuples with Named Fields
 ----------------------------------------------------------------
 
 Named tuples assign meaning to each position in a tuple and allow for more readable,
 self-documenting code.  They can be used wherever regular tuples are used, and
 they add the ability to access fields by name instead of position index.
 
-.. function:: NamedTuple(typename, fieldnames, [verbose])
+.. function:: namedtuple(typename, fieldnames, [verbose])
 
    Returns a new tuple subclass named *typename*.  The new subclass is used to
-   create tuple-like objects that have fields accessable by attribute lookup as
+   create tuple-like objects that have fields accessible by attribute lookup as
    well as being indexable and iterable.  Instances of the subclass also have a
    helpful docstring (with typename and fieldnames) and a helpful :meth:`__repr__`
    method which lists the tuple contents in a ``name=value`` format.
 
-   The *fieldnames* are specified in a single string with each fieldname separated by
-   a space and/or comma.  Any valid Python identifier may be used for a fieldname.
+   The *fieldnames* are a single string with each fieldname separated by whitespace
+   and/or commas, for example ``'x y'`` or ``'x, y'``.  Alternatively, *fieldnames*
+   can be a sequence of strings such as ``['x', 'y']``.
+
+   Any valid Python identifier may be used for a fieldname except for names
+   starting with an underscore.  Valid identifiers consist of letters, digits,
+   and underscores but do not start with a digit or underscore and cannot be
+   a :mod:`keyword` such as *class*, *for*, *return*, *global*, *pass*,
+   or *raise*.
 
-   If *verbose* is true, will print the class definition.
+   If *verbose* is true, the class definition is printed just before being built.
 
-   *NamedTuple* instances do not have per-instance dictionaries, so they are
+   Named tuple instances do not have per-instance dictionaries, so they are
    lightweight and require no more memory than regular tuples.
 
-Example::
+Example:
+
+.. doctest::
+   :options: +NORMALIZE_WHITESPACE
 
-   >>> Point = NamedTuple('Point', 'x y', True)
+   >>> Point = namedtuple('Point', 'x y', verbose=True)
    class Point(tuple):
            'Point(x, y)'
+   <BLANKLINE>
            __slots__ = ()
-           __fields__ = ('x', 'y')
+   <BLANKLINE>
+           _fields = ('x', 'y')
+   <BLANKLINE>
            def __new__(cls, x, y):
                return tuple.__new__(cls, (x, y))
+   <BLANKLINE>
+           @classmethod
+           def _make(cls, iterable, new=tuple.__new__, len=len):
+               'Make a new Point object from a sequence or iterable'
+               result = new(cls, iterable)
+               if len(result) != 2:
+                   raise TypeError('Expected 2 arguments, got %d' % len(result))
+               return result
+   <BLANKLINE>
            def __repr__(self):
                return 'Point(x=%r, y=%r)' % self
-           def __replace__(self, field, value):
-               'Return a new Point object replacing one field with a new value'
-               return Point(**dict(zip(('x', 'y'), self) + [(field, value)]))
+   <BLANKLINE>
+           def _asdict(t):
+               'Return a new dict which maps field names to their values'
+               return {'x': t[0], 'y': t[1]}
+   <BLANKLINE>
+           def _replace(self, **kwds):
+               'Return a new Point object replacing specified fields with new values'
+               result = self._make(map(kwds.pop, ('x', 'y'), self))
+               if kwds:
+                   raise ValueError('Got unexpected field names: %r' % kwds.keys())
+               return result
+   <BLANKLINE>
            x = property(itemgetter(0))
            y = property(itemgetter(1))
 
    >>> p = Point(11, y=22)     # instantiate with positional or keyword arguments
-   >>> p[0] + p[1]             # indexable like the regular tuple (11, 22)
+   >>> p[0] + p[1]             # indexable like the plain tuple (11, 22)
    33
    >>> x, y = p                # unpack like a regular tuple
    >>> x, y
    (11, 22)
-   >>> p.x + p.y               # fields also accessable by name
+   >>> p.x + p.y               # fields also accessible by name
    33
    >>> p                       # readable __repr__ with a name=value style
    Point(x=11, y=22)
@@ -449,55 +534,202 @@
 Named tuples are especially useful for assigning field names to result tuples returned
 by the :mod:`csv` or :mod:`sqlite3` modules::
 
-   from itertools import starmap
+   EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, department, paygrade')
+
    import csv
-   EmployeeRecord = NamedTuple('EmployeeRecord', 'name age title department paygrade')
-   for record in starmap(EmployeeRecord, csv.reader(open("employees.csv", "rb"))):
+   for emp in map(EmployeeRecord._make, csv.reader(open("employees.csv", "rb"))):
        print(emp.name, emp.title)
 
-When casting a single record to a *NamedTuple*, use the star-operator [#]_ to unpack
-the values::
-
-   >>> t = [11, 22]
-   >>> Point(*t)               # the star-operator unpacks any iterable object
-   Point(x=11, y=22)
+   import sqlite3
+   conn = sqlite3.connect('/companydata')
+   cursor = conn.cursor()
+   cursor.execute('SELECT name, age, title, department, paygrade FROM employees')
+   for emp in map(EmployeeRecord._make, cursor.fetchall()):
+       print(emp.name, emp.title)
 
 In addition to the methods inherited from tuples, named tuples support
-an additonal method and an informational read-only attribute.
+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)
+
+   Class method that makes a new instance from an existing sequence or iterable.
 
-.. method:: somenamedtuple.replace(field, value)
+.. doctest::
 
-   Return a new instance of the named tuple replacing the named *field* with a new *value*:
+      >>> t = [11, 22]
+      >>> Point._make(t)
+      Point(x=11, y=22)
+
+.. method:: somenamedtuple._asdict()
+
+   Return a new dict which maps field names to their corresponding values::
+
+      >>> p._asdict()
+      {'x': 11, 'y': 22}
+
+.. method:: somenamedtuple._replace(kwargs)
+
+   Return a new instance of the named tuple replacing specified fields with new
+   values:
 
 ::
 
       >>> p = Point(x=11, y=22)
-      >>> p.__replace__('x', 33)
+      >>> p._replace(x=33)
       Point(x=33, y=22)
 
-      >>> for recordnum, record in inventory:
-      ...     inventory[recordnum] = record.replace('total', record.price * record.quantity)
+      >>> for partnum, record in inventory.items():
+      ...     inventory[partnum] = record._replace(price=newprices[partnum], timestamp=time.now())
 
-.. attribute:: somenamedtuple.__fields__
+.. attribute:: somenamedtuple._fields
 
-   Return a tuple of strings listing the field names.  This is useful for introspection,
-   for converting a named tuple instance to a dictionary, and for combining named tuple
-   types to create new named tuple types:
+   Tuple of strings listing the field names.  Useful for introspection
+   and for creating new named tuple types from existing named tuples.
 
-::
+.. doctest::
 
-      >>> p.__fields__                         # view the field names
+      >>> p._fields            # view the field names
       ('x', 'y')
-      >>> dict(zip(p.__fields__, p))           # convert to a dictionary
-      {'y': 22, 'x': 11}
 
-      >>> Color = NamedTuple('Color', 'red green blue')
-      >>> pixel_fields = ' '.join(Point.__fields__ + Color.__fields__)  # combine fields
-      >>> Pixel = NamedTuple('Pixel', pixel_fields)
+      >>> Color = namedtuple('Color', 'red green blue')
+      >>> Pixel = namedtuple('Pixel', Point._fields + Color._fields)
       >>> Pixel(11, 22, 128, 255, 0)
-      Pixel(x=11, y=22, red=128, green=255, blue=0)'
+      Pixel(x=11, y=22, red=128, green=255, blue=0)
+
+To retrieve a field whose name is stored in a string, use the :func:`getattr`
+function:
+
+    >>> getattr(p, 'x')
+    11
+
+To convert a dictionary to a named tuple, use the double-star-operator [#]_:
+
+   >>> d = {'x': 11, 'y': 22}
+   >>> Point(**d)
+   Point(x=11, y=22)
+
+Since a named tuple is a regular Python class, it is easy to add or change
+functionality with a subclass.  Here is how to add a calculated field and
+a fixed-width print format:
+
+    >>> class Point(namedtuple('Point', 'x y')):
+    ...     __slots__ = ()
+    ...     @property
+    ...     def hypot(self):
+    ...         return (self.x ** 2 + self.y ** 2) ** 0.5
+    ...     def __str__(self):
+    ...         return 'Point: x=%6.3f  y=%6.3f  hypot=%6.3f' % (self.x, self.y, self.hypot)
+
+    >>> for p in Point(3, 4), Point(14, 5/7.):
+    ...     print(p)
+    Point: x= 3.000  y= 4.000  hypot= 5.000
+    Point: x=14.000  y= 0.714  hypot=14.018
+
+The subclass shown above sets ``__slots__`` to an empty tuple.  This keeps
+keep memory requirements low by preventing the creation of instance dictionaries.
+
+
+Subclassing is not useful for adding new, stored fields.  Instead, simply
+create a new named tuple type from the :attr:`_fields` attribute:
+
+    >>> Point3D = namedtuple('Point3D', Point._fields + ('z',))
+
+Default values can be implemented by using :meth:`_replace` to
+customize a prototype instance:
+
+    >>> Account = namedtuple('Account', 'owner balance transaction_count')
+    >>> default_account = Account('<owner name>', 0.0, 0)
+    >>> johns_account = default_account._replace(owner='John')
 
 .. rubric:: Footnotes
 
-.. [#] For information on the star-operator see
+.. [#] For information on the double-star-operator see
    :ref:`tut-unpacking-arguments` and :ref:`calls`.
+
+
+
+:class:`UserDict` objects
+-------------------------
+
+The class, :class:`UserDict` acts as a wrapper around dictionary objects.  
+The need for this class has been partially supplanted by the ability to 
+subclass directly from :class:`dict`; however, this class can be easier
+to work with because the underlying dictionary is accessible as an
+attribute.
+
+.. class:: UserDict([initialdata])
+
+   Class that simulates a dictionary.  The instance's contents are kept in a
+   regular dictionary, which is accessible via the :attr:`data` attribute of
+   :class:`UserDict` instances.  If *initialdata* is provided, :attr:`data` is
+   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:
+
+.. attribute:: UserDict.data
+
+   A real dictionary used to store the contents of the :class:`UserDict` class.
+
+
+
+:class:`UserList` objects
+-------------------------
+
+This class acts as a wrapper around list objects.  It is a useful base class
+for your own list-like classes which can inherit from them and override 
+existing methods or add new ones.  In this way, one can add new behaviors to
+lists.
+
+The need for this class has been partially supplanted by the ability to 
+subclass directly from :class:`list`; however, this class can be easier
+to work with because the underlying list is accessible as an attribute.
+
+.. class:: UserList([list])
+
+   Class that simulates a list.  The instance's contents are kept in a regular
+   list, which is accessible via the :attr:`data` attribute of :class:`UserList`
+   instances.  The instance's contents are initially set to a copy of *list*,
+   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:
+
+.. attribute:: UserList.data
+
+   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
+argument.  List operations which return a new sequence attempt to create an
+instance of the actual implementation class.  To do so, it assumes that the
+constructor can be called with a single parameter, which is a sequence object
+used as a data source.
+
+If a derived class does not wish to comply with this requirement, all of the
+special methods supported by this class will need to be overridden; please
+consult the sources for information about the methods which need to be provided
+in that case.
+
+:class:`UserString` objects
+---------------------------
+
+The class, :class:`UserString` acts as a wrapper around string objects.  
+The need for this class has been partially supplanted by the ability to 
+subclass directly from :class:`str`; however, this class can be easier
+to work with because the underlying string is accessible as an
+attribute.
+
+.. class:: UserString([sequence])
+
+   Class that simulates a string or a Unicode string object.  The instance's
+   content is kept in a regular string object, which is accessible via the 
+   :attr:`data` attribute of :class:`UserString` instances.  The instance's 
+   contents are initially set to a copy of *sequence*.  The *sequence* can
+   be an instance of :class:`bytes`, :class:`str`, :class:`UserString` (or a
+   subclass) or an arbitrary sequence which can be converted into a string using
+   the built-in :func:`str` function.

Modified: python/branches/py3k-importlib/Doc/library/configparser.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/configparser.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/configparser.rst	Thu Mar 27 00:48:05 2008
@@ -87,7 +87,7 @@
    well. New applications should prefer this version if they don't need to be
    compatible with older versions of Python.
 
-   .. % XXX Need to explain what's safer/more predictable about it.
+   .. XXX Need to explain what's safer/more predictable about it.
 
 
 .. exception:: NoSectionError
@@ -176,8 +176,9 @@
 .. method:: RawConfigParser.add_section(section)
 
    Add a section named *section* to the instance.  If a section by the given name
-   already exists, :exc:`DuplicateSectionError` is raised.
-
+   already exists, :exc:`DuplicateSectionError` is raised. If the name
+   ``DEFAULT`` (or any of it's case-insensitive variants) is passed,
+   :exc:`ValueError` is raised.
 
 .. method:: RawConfigParser.has_section(section)
 
@@ -199,7 +200,7 @@
 .. method:: RawConfigParser.read(filenames)
 
    Attempt to read and parse a list of filenames, returning a list of filenames
-   which were successfully parsed.  If *filenames* is a string or Unicode string,
+   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
@@ -330,6 +331,95 @@
 .. method:: SafeConfigParser.set(section, option, value)
 
    If the given section exists, set the given option to the specified value;
-   otherwise raise :exc:`NoSectionError`.  *value* must be a string (:class:`str`
-   or :class:`unicode`); if not, :exc:`TypeError` is raised.
+   otherwise raise :exc:`NoSectionError`.  *value* must be a string; if it is
+   not, :exc:`TypeError` is raised.
+
+
+Examples
+--------
+
+An example of writing to a configuration file::
 
+   import ConfigParser
+
+   config = ConfigParser.RawConfigParser()
+   
+   # When adding sections or items, add them in the reverse order of
+   # how you want them to be displayed in the actual file.
+   # In addition, please note that using RawConfigParser's and the raw
+   # mode of ConfigParser's respective set functions, you can assign
+   # non-string values to keys internally, but will receive an error
+   # when attempting to write to a file or when you get it in non-raw
+   # mode. SafeConfigParser does not allow such assignments to take place.
+   config.add_section('Section1')
+   config.set('Section1', 'int', '15')
+   config.set('Section1', 'bool', 'true')
+   config.set('Section1', 'float', '3.1415')
+   config.set('Section1', 'baz', 'fun')
+   config.set('Section1', 'bar', 'Python')
+   config.set('Section1', 'foo', '%(bar)s is %(baz)s!')
+   
+   # Writing our configuration file to 'example.cfg'
+   with open('example.cfg', 'wb') as configfile:
+       config.write(configfile)
+
+An example of reading the configuration file again::
+
+   import ConfigParser
+
+   config = ConfigParser.RawConfigParser()
+   config.read('example.cfg')
+
+   # getfloat() raises an exception if the value is not a float
+   # getint() and getboolean() also do this for their respective types
+   float = config.getfloat('Section1', 'float')
+   int = config.getint('Section1', 'int')
+   print(float + int)
+
+   # Notice that the next output does not interpolate '%(bar)s' or '%(baz)s'.
+   # This is because we are using a RawConfigParser().
+   if config.getboolean('Section1', 'bool'):
+       print(config.get('Section1', 'foo'))
+
+To get interpolation, you will need to use a :class:`ConfigParser` or
+:class:`SafeConfigParser`::
+
+   import ConfigParser
+
+   config = ConfigParser.ConfigParser()
+   config.read('example.cfg')
+
+   # Set the third, optional argument of get to 1 if you wish to use raw mode.
+   print(config.get('Section1', 'foo', 0)) # -> "Python is fun!"
+   print(config.get('Section1', 'foo', 1)) # -> "%(bar)s is %(baz)s!"
+
+   # The optional fourth argument is a dict with members that will take
+   # precedence in interpolation.
+   print(config.get('Section1', 'foo', 0, {'bar': 'Documentation',
+                                           'baz': 'evil'}))
+
+Defaults are available in all three types of ConfigParsers. They are used in 
+interpolation if an option used is not defined elsewhere. ::
+
+   import ConfigParser
+
+   # New instance with 'bar' and 'baz' defaulting to 'Life' and 'hard' each
+   config = ConfigParser.SafeConfigParser({'bar': 'Life', 'baz': 'hard'})
+   config.read('example.cfg')
+   
+   print(config.get('Section1', 'foo')) # -> "Python is fun!"
+   config.remove_option('Section1', 'bar')
+   config.remove_option('Section1', 'baz')
+   print(config.get('Section1', 'foo')) # -> "Life is hard!"
+
+The function ``opt_move`` below can be used to move options between sections::
+
+   def opt_move(config, section1, section2, option):
+       try:
+           config.set(section2, option, config.get(section1, option, 1))
+       except ConfigParser.NoSectionError:
+           # Create non-existent section
+           config.add_section(section2)
+           opt_move(config, section1, section2, option)
+       else:
+           config.remove_option(section1, option)

Modified: python/branches/py3k-importlib/Doc/library/constants.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/constants.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/constants.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 Built-in Constants
 ==================
 
@@ -8,25 +7,28 @@
 .. note::
 
    :data:`None`, :data:`False`, :data:`True` and :data:`__debug__` cannot be
-   reassigned, so they can be considered "true" constants.
+   reassigned (assignments to them raise :exc:`SyntaxError`), so they can be
+   considered "true" constants.
 
 .. XXX False, True, None are keywords too
 
 .. data:: False
 
-   The false value of the :class:`bool` type.
+   The false value of the :class:`bool` type. Assignments to ``False`` 
+   are illegal and raise a :exc:`SyntaxError`.
 
 
 .. data:: True
 
-   The true value of the :class:`bool` type.
+   The true value of the :class:`bool` type. Assignments to ``True`` 
+   are illegal and raise a :exc:`SyntaxError`.
 
 
 .. data:: None
 
    The sole value of :attr:`types.NoneType`.  ``None`` is frequently used to
    represent the absence of a value, as when default arguments are not passed to a
-   function.
+   function. Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`.
 
 
 .. data:: NotImplemented
@@ -41,11 +43,36 @@
    The same as ``...``. Special value used mostly in conjunction with extended
    slicing syntax for user-defined container data types, as in ::
 
-      val = container[1:5, 7:10, ...]
+   .. XXX Someone who understands extended slicing should fill in here.
 
 
 .. data:: __debug__
 
-   A boolean value that is :data:`True` if Python was not started with the
-   ``-O`` command line option.  Its value is used indirectly by the
-   :keyword:`assert` statement, but it can also be used directly in code.
+   This constant is true if Python was not started with an :option:`-O` option.
+   Assignments to :const:`__debug__` are illegal and raise a :exc:`SyntaxError`.
+   See also the :keyword:`assert` statement.
+
+
+Constants added by the :mod:`site` module
+-----------------------------------------
+
+The :mod:`site` module (which is imported automatically during startup, except
+if the :option:`-S` command-line option is given) adds several constants to the
+built-in namespace.  They are useful for the interactive interpreter shell and
+should not be used in programs.
+
+.. data:: quit([code=None])
+          exit([code=None])
+
+   Objects that when printed, print a message like "Use quit() or Ctrl-D
+   (i.e. EOF) to exit", and when called, raise :exc:`SystemExit` with the
+   specified exit code, and when .
+
+.. data:: copyright
+          license
+          credits
+
+   Objects that when printed, print a message like "Type license() to see the
+   full license text", and when called, display the corresponding text in a
+   pager-like fashion (one screen at a time).
+

Modified: python/branches/py3k-importlib/Doc/library/contextlib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/contextlib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/contextlib.rst	Thu Mar 27 00:48:05 2008
@@ -15,13 +15,12 @@
 
 .. function:: contextmanager(func)
 
-   This function is a decorator that can be used to define a factory function for
-   :keyword:`with` statement context managers, without needing to create a class or
-   separate :meth:`__enter__` and :meth:`__exit__` methods.
+   This function is a :term:`decorator` that can be used to define a factory
+   function for :keyword:`with` statement context managers, without needing to
+   create a class or separate :meth:`__enter__` and :meth:`__exit__` methods.
 
    A simple example (this is not recommended as a real way of generating HTML!)::
 
-      from __future__ import with_statement
       from contextlib import contextmanager
 
       @contextmanager
@@ -37,9 +36,9 @@
       foo
       </h1>
 
-   The function being decorated must return a generator-iterator when called. This
-   iterator must yield exactly one value, which will be bound to the targets in the
-   :keyword:`with` statement's :keyword:`as` clause, if any.
+   The function being decorated must return a :term:`generator`-iterator when
+   called. This iterator must yield exactly one value, which will be bound to
+   the targets in the :keyword:`with` statement's :keyword:`as` clause, if any.
 
    At the point where the generator yields, the block nested in the :keyword:`with`
    statement is executed.  The generator is then resumed after the block is exited.
@@ -98,7 +97,6 @@
 
    And lets you write code like this::
 
-      from __future__ import with_statement
       from contextlib import closing
       import urllib
 

Modified: python/branches/py3k-importlib/Doc/library/cookie.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/cookie.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/cookie.rst	Thu Mar 27 00:48:05 2008
@@ -206,7 +206,10 @@
 Example
 -------
 
-The following example demonstrates how to use the :mod:`Cookie` module. ::
+The following example demonstrates how to use the :mod:`Cookie` module.
+
+.. doctest::
+   :options: +NORMALIZE_WHITESPACE
 
    >>> import Cookie
    >>> C = Cookie.SimpleCookie()
@@ -215,11 +218,11 @@
    >>> C["fig"] = "newton"
    >>> C["sugar"] = "wafer"
    >>> print(C) # generate HTTP headers
-   Set-Cookie: sugar=wafer
    Set-Cookie: fig=newton
-   >>> print(C.output()) # same thing
    Set-Cookie: sugar=wafer
+   >>> print(C.output()) # same thing
    Set-Cookie: fig=newton
+   Set-Cookie: sugar=wafer
    >>> C = Cookie.SmartCookie()
    >>> C["rocky"] = "road"
    >>> C["rocky"]["path"] = "/cookie"
@@ -230,8 +233,8 @@
    >>> C = Cookie.SmartCookie()
    >>> C.load("chips=ahoy; vienna=finger") # load from a string (HTTP header)
    >>> print(C)
-   Set-Cookie: vienna=finger
    Set-Cookie: chips=ahoy
+   Set-Cookie: vienna=finger
    >>> C = Cookie.SmartCookie()
    >>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";')
    >>> print(C)

Modified: python/branches/py3k-importlib/Doc/library/cookielib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/cookielib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/cookielib.rst	Thu Mar 27 00:48:05 2008
@@ -117,7 +117,7 @@
       Extensions to this module, including a class for reading Microsoft Internet
       Explorer cookies on Windows.
 
-   http://www.netscape.com/newsref/std/cookie_spec.html
+   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
       the major browsers (and :mod:`cookielib`) only bears a passing resemblance to
@@ -140,7 +140,7 @@
 CookieJar and FileCookieJar Objects
 -----------------------------------
 
-:class:`CookieJar` objects support the iterator protocol for iterating over
+:class:`CookieJar` objects support the :term:`iterator` protocol for iterating over
 contained :class:`Cookie` objects.
 
 :class:`CookieJar` has the following methods:

Modified: python/branches/py3k-importlib/Doc/library/copy.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/copy.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/copy.rst	Thu Mar 27 00:48:05 2008
@@ -21,8 +21,6 @@
 
 For module specific errors, :exc:`copy.error` is raised.
 
-.. % 
-
 The difference between shallow and deep copying is only relevant for compound
 objects (objects that contain other objects, like lists or class instances):
 

Modified: python/branches/py3k-importlib/Doc/library/crypt.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/crypt.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/crypt.rst	Thu Mar 27 00:48:05 2008
@@ -47,14 +47,8 @@
 
    import crypt, getpass, pwd
 
-   def raw_input(prompt):
-       import sys
-       sys.stdout.write(prompt)
-       sys.stdout.flush()
-       return sys.stdin.readline()
-
    def login():
-       username = raw_input('Python login:')
+       username = input('Python login:')
        cryptedpasswd = pwd.getpwnam(username)[1]
        if cryptedpasswd:
            if cryptedpasswd == 'x' or cryptedpasswd == '*': 

Modified: python/branches/py3k-importlib/Doc/library/csv.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/csv.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/csv.rst	Thu Mar 27 00:48:05 2008
@@ -43,8 +43,6 @@
 
 .. seealso::
 
-   .. % \seemodule{array}{Arrays of uniformly types numeric values.}
-
    :pep:`305` - CSV File API
       The Python Enhancement Proposal which proposed this addition to Python.
 
@@ -60,7 +58,7 @@
 .. function:: reader(csvfile[, dialect='excel'][, fmtparam])
 
    Return a reader object which will iterate over lines in the given *csvfile*.
-   *csvfile* can be any object which supports the iterator protocol and returns a
+   *csvfile* can be any object which supports the :term:`iterator` protocol and returns a
    string each time its :meth:`next` method is called --- file objects and list
    objects are both suitable.   If *csvfile* is a file object, it must be opened
    with the 'b' flag on platforms where that makes a difference.  An optional
@@ -83,6 +81,15 @@
    consequence, if newlines embedded within fields are important, the input should
    be split into lines in a manner which preserves the newline characters.
 
+   A short usage example::
+ 
+      >>> import csv
+      >>> spamReader = csv.reader(open('eggs.csv'), delimiter=' ', quotechar='|')
+      >>> for row in spamReader:
+      ...     print(', '.join(row))
+      Spam, Spam, Spam, Spam, Spam, Baked Beans
+      Spam, Lovely Spam, Wonderful Spam
+
 
 .. function:: writer(csvfile[, dialect='excel'][, fmtparam])
 
@@ -103,10 +110,18 @@
    CSV files without preprocessing the data returned from a ``cursor.fetch*`` call.
    All other non-string data are stringified with :func:`str` before being written.
 
+   A short usage example::
+
+      >>> import csv
+      >>> spamWriter = csv.writer(open('eggs.csv', 'w'), delimiter=' ',
+      ...                         quotechar='|', quoting=QUOTE_MINIMAL)
+      >>> spamWriter.writerow(['Spam'] * 5 + ['Baked Beans'])
+      >>> spamWriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
+
 
 .. function:: register_dialect(name[, dialect][, fmtparam])
 
-   Associate *dialect* with *name*.  *name* must be a string or Unicode object. The
+   Associate *dialect* with *name*.  *name* must be a string. The
    dialect can be specified either by passing a sub-class of :class:`Dialect`, or
    by *fmtparam* keyword arguments, or both, with keyword arguments overriding
    parameters of the dialect. For full details about the dialect and formatting
@@ -121,9 +136,9 @@
 
 .. function:: get_dialect(name)
 
-   Return the dialect associated with *name*.  An :exc:`Error` is raised if *name*
-   is not a registered dialect name.
-
+   Return the dialect associated with *name*.  An :exc:`Error` is raised if
+   *name* is not a registered dialect name.  This function returns an immutable
+   :class:`Dialect`.
 
 .. function:: list_dialects()
 
@@ -138,7 +153,7 @@
 
 The :mod:`csv` module defines the following classes:
 
-.. class:: DictReader(csvfile[, fieldnames=:const:None,[, restkey=:const:None[, restval=None[, dialect='excel'[, *args, **kwds]]]]])
+.. class:: DictReader(csvfile[, fieldnames=None[, restkey=None[, restval=None[, dialect='excel'[, *args, **kwds]]]]])
 
    Create an object which operates like a regular reader but maps the information
    read into a dict whose keys are given by the optional  *fieldnames* parameter.
@@ -196,7 +211,6 @@
 
 The :class:`Sniffer` class provides two methods:
 
-
 .. method:: Sniffer.sniff(sample[, delimiters=None])
 
    Analyze the given *sample* and return a :class:`Dialect` subclass reflecting the
@@ -209,9 +223,17 @@
    Analyze the sample text (presumed to be in CSV format) and return :const:`True`
    if the first row appears to be a series of column headers.
 
-The :mod:`csv` module defines the following constants:
+An example for :class:`Sniffer` use::
+
+   csvfile = open("example.csv")
+   dialect = csv.Sniffer().sniff(csvfile.read(1024))
+   csvfile.seek(0)
+   reader = csv.reader(csvfile, dialect)
+   # ... process CSV file contents here ...
 
 
+The :mod:`csv` module defines the following constants:
+
 .. data:: QUOTE_ALL
 
    Instructs :class:`writer` objects to quote all fields.
@@ -436,9 +458,9 @@
 write functions or classes that handle the encoding and decoding for you as long
 as you avoid encodings like UTF-16 that use NULs.  UTF-8 is recommended.
 
-:func:`unicode_csv_reader` below is a generator that wraps :class:`csv.reader`
+:func:`unicode_csv_reader` below is a :term:`generator` that wraps :class:`csv.reader`
 to handle Unicode CSV data (a list of Unicode strings).  :func:`utf_8_encoder`
-is a generator that encodes the Unicode strings as UTF-8, one string (or row) at
+is a :term:`generator` that encodes the Unicode strings as UTF-8, one string (or row) at
 a time.  The encoded strings are parsed by the CSV reader, and
 :func:`unicode_csv_reader` decodes the UTF-8-encoded cells back into Unicode::
 

Modified: python/branches/py3k-importlib/Doc/library/ctypes.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/ctypes.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/ctypes.rst	Thu Mar 27 00:48:05 2008
@@ -69,7 +69,7 @@
    <CDLL 'libc.so.6', handle ... at ...>
    >>>
 
-.. % XXX Add section for Mac OS X.
+.. XXX Add section for Mac OS X.
 
 
 .. _ctypes-accessing-functions-from-loaded-dlls:
@@ -197,11 +197,11 @@
 There are, however, enough ways to crash Python with ``ctypes``, so you should
 be careful anyway.
 
-``None``, integers, longs, byte strings and unicode strings are the only native
+``None``, integers, byte strings and unicode strings are the only native
 Python objects that can directly be used as parameters in these function calls.
 ``None`` is passed as a C ``NULL`` pointer, byte strings and unicode strings are
 passed as pointer to the memory block that contains their data (``char *`` or
-``wchar_t *``).  Python integers and Python longs are passed as the platforms
+``wchar_t *``).  Python integers are passed as the platforms
 default C ``int`` type, their value is masked to fit into the C type.
 
 Before we move on calling functions with other parameter types, we have to learn
@@ -222,25 +222,25 @@
    +----------------------+--------------------------------+----------------------------+
    | :class:`c_wchar`     | ``wchar_t``                    | 1-character unicode string |
    +----------------------+--------------------------------+----------------------------+
-   | :class:`c_byte`      | ``char``                       | int/long                   |
+   | :class:`c_byte`      | ``char``                       | int                        |
    +----------------------+--------------------------------+----------------------------+
-   | :class:`c_ubyte`     | ``unsigned char``              | int/long                   |
+   | :class:`c_ubyte`     | ``unsigned char``              | int                        |
    +----------------------+--------------------------------+----------------------------+
-   | :class:`c_short`     | ``short``                      | int/long                   |
+   | :class:`c_short`     | ``short``                      | int                        |
    +----------------------+--------------------------------+----------------------------+
-   | :class:`c_ushort`    | ``unsigned short``             | int/long                   |
+   | :class:`c_ushort`    | ``unsigned short``             | int                        |
    +----------------------+--------------------------------+----------------------------+
-   | :class:`c_int`       | ``int``                        | int/long                   |
+   | :class:`c_int`       | ``int``                        | int                        |
    +----------------------+--------------------------------+----------------------------+
-   | :class:`c_uint`      | ``unsigned int``               | int/long                   |
+   | :class:`c_uint`      | ``unsigned int``               | int                        |
    +----------------------+--------------------------------+----------------------------+
-   | :class:`c_long`      | ``long``                       | int/long                   |
+   | :class:`c_long`      | ``long``                       | int                        |
    +----------------------+--------------------------------+----------------------------+
-   | :class:`c_ulong`     | ``unsigned long``              | int/long                   |
+   | :class:`c_ulong`     | ``unsigned long``              | int                        |
    +----------------------+--------------------------------+----------------------------+
-   | :class:`c_longlong`  | ``__int64`` or ``long long``   | int/long                   |
+   | :class:`c_longlong`  | ``__int64`` or ``long long``   | int                        |
    +----------------------+--------------------------------+----------------------------+
-   | :class:`c_ulonglong` | ``unsigned __int64`` or        | int/long                   |
+   | :class:`c_ulonglong` | ``unsigned __int64`` or        | int                        |
    |                      | ``unsigned long long``         |                            |
    +----------------------+--------------------------------+----------------------------+
    | :class:`c_float`     | ``float``                      | float                      |
@@ -253,7 +253,7 @@
    +----------------------+--------------------------------+----------------------------+
    | :class:`c_wchar_p`   | ``wchar_t *`` (NUL terminated) | unicode or ``None``        |
    +----------------------+--------------------------------+----------------------------+
-   | :class:`c_void_p`    | ``void *``                     | int/long or ``None``       |
+   | :class:`c_void_p`    | ``void *``                     | int or ``None``            |
    +----------------------+--------------------------------+----------------------------+
 
 
@@ -584,8 +584,8 @@
    >>> r = RECT(POINT(1, 2), POINT(3, 4))
    >>> r = RECT((1, 2), (3, 4))
 
-Fields descriptors can be retrieved from the *class*, they are useful for
-debugging because they can provide useful information::
+Field :term:`descriptor`\s can be retrieved from the *class*, they are useful
+for debugging because they can provide useful information::
 
    >>> print(POINT.x)
    <Field type=c_long, ofs=0, size=4>
@@ -1195,10 +1195,10 @@
    >>>
 
 Why is it printing ``False``?  ctypes instances are objects containing a memory
-block plus some descriptors accessing the contents of the memory.  Storing a
-Python object in the memory block does not store the object itself, instead the
-``contents`` of the object is stored. Accessing the contents again constructs a
-new Python each time!
+block plus some :term:`descriptor`\s accessing the contents of the memory.
+Storing a Python object in the memory block does not store the object itself,
+instead the ``contents`` of the object is stored.  Accessing the contents again
+constructs a new Python object each time!
 
 
 .. _ctypes-variable-sized-data-types:
@@ -1256,10 +1256,6 @@
 
 ``long double`` is not implemented.
 
-.. % Local Variables:
-.. % compile-command: "make.bat"
-.. % End:
-
 
 .. _ctypes-ctypes-reference:
 
@@ -1366,8 +1362,8 @@
    :class:`WinDLL` and :class:`OleDLL` use the standard calling convention on this
    platform.
 
-The Python GIL is released before calling any function exported by these
-libraries, and reacquired afterwards.
+The Python :term:`global interpreter lock` is released before calling any
+function exported by these libraries, and reacquired afterwards.
 
 
 .. class:: PyDLL(name, mode=DEFAULT_MODE, handle=None)
@@ -1948,7 +1944,7 @@
    in case the memory block contains pointers.
 
 Common methods of ctypes data types, these are all class methods (to be exact,
-they are methods of the metaclass):
+they are methods of the :term:`metaclass`):
 
 
 .. method:: _CData.from_address(address)
@@ -2013,6 +2009,10 @@
    ctypes data types.  ``_SimpleCData`` is a subclass of ``_CData``, so it inherits
    their methods and attributes.
 
+   .. versionchanged:: 2.6
+      ctypes data types that are not and do not contain pointers can
+      now be pickled.
+
 Instances have a single attribute:
 
 
@@ -2263,7 +2263,7 @@
 
 Concrete structure and union types must be created by subclassing one of these
 types, and at least define a :attr:`_fields_` class variable. ``ctypes`` will
-create descriptors which allow reading and writing the fields by direct
+create :term:`descriptor`\s which allow reading and writing the fields by direct
 attribute accesses.  These are the
 
 

Modified: python/branches/py3k-importlib/Doc/library/curses.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/curses.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/curses.rst	Thu Mar 27 00:48:05 2008
@@ -16,6 +16,19 @@
 designed to match the API of ncurses, an open-source curses library hosted on
 Linux and the BSD variants of Unix.
 
+.. note::
+
+   Since version 5.4, the ncurses library decides how to interpret non-ASCII data
+   using the ``nl_langinfo`` function.  That means that you have to call
+   :func:`locale.setlocale` in the application and encode Unicode strings
+   using one of the system's available encodings.  This example uses the
+   system's default encoding::
+
+      import locale
+      locale.setlocale(locale.LC_ALL, '')
+      code = locale.getpreferredencoding()
+
+   Then use *code* as the encoding for :meth:`str.encode` calls.
 
 .. seealso::
 
@@ -32,9 +45,9 @@
       Convenience function to ensure proper terminal setup and resetting on
       application entry and exit.
 
-   `Curses Programming with Python <http://www.python.org/doc/howto/curses/curses.html>`_
+   :ref:`curses-howto`
       Tutorial material on using curses with Python, by Andrew Kuchling and Eric
-      Raymond, is available on the Python Web site.
+      Raymond.
 
    The :file:`Demo/curses/` directory in the Python source distribution contains
    some example programs using the curses bindings provided by this module.
@@ -1167,7 +1180,7 @@
 Keys are referred to by integer constants with names starting with  ``KEY_``.
 The exact keycaps available are system dependent.
 
-.. % XXX should this table be alphabetized?
+.. XXX this table is far too large! should it be alphabetized?
 
 +-------------------+--------------------------------------------+
 | Key constant      | Key                                        |

Modified: python/branches/py3k-importlib/Doc/library/datatypes.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/datatypes.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/datatypes.rst	Thu Mar 27 00:48:05 2008
@@ -11,8 +11,8 @@
 
 Python also provides some built-in data types, in particular,
 :class:`dict`, :class:`list`, :class:`set` and :class:`frozenset`, and
-:class:`tuple`.  The :class:`str` class can be used to handle binary data
-and 8-bit text, and the :class:`unicode` class to handle Unicode text.
+:class:`tuple`.  The :class:`str` class is used to hold
+Unicode strings, and the :class:`bytes` class is used to hold binary data.
 
 The following modules are documented in this chapter:
 
@@ -29,9 +29,7 @@
    mutex.rst
    queue.rst
    weakref.rst
-   userdict.rst
    types.rst
-   new.rst
    copy.rst
    pprint.rst
    repr.rst

Modified: python/branches/py3k-importlib/Doc/library/datetime.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/datetime.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/datetime.rst	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,3 @@
-.. % XXX what order should the types be discussed in?
-
-
 :mod:`datetime` --- Basic date and time types
 =============================================
 
@@ -10,6 +7,7 @@
 .. sectionauthor:: Tim Peters <tim at zope.com>
 .. sectionauthor:: A.M. Kuchling <amk at amk.ca>
 
+.. XXX what order should the types be discussed in?
 
 The :mod:`datetime` module supplies classes for manipulating dates and times in
 both simple and complex ways.  While date and time arithmetic is supported, the
@@ -132,7 +130,7 @@
 
 .. class:: timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])
 
-   All arguments are optional and default to ``0``.  Arguments may be ints, longs,
+   All arguments are optional and default to ``0``.  Arguments may be integers
    or floats, and may be positive or negative.
 
    Only *days*, *seconds* and *microseconds* are stored internally.  Arguments are
@@ -159,8 +157,9 @@
    :exc:`OverflowError` is raised.
 
    Note that normalization of negative values may be surprising at first. For
-   example, ::
+   example,
 
+      >>> from datetime import timedelta
       >>> d = timedelta(microseconds=-1)
       >>> (d.days, d.seconds, d.microseconds)
       (-1, 86399, 999999)
@@ -201,7 +200,7 @@
 
 Supported operations:
 
-.. % XXX this table is too wide!
+.. XXX this table is too wide!
 
 +--------------------------------+-----------------------------------------------+
 | Operation                      | Result                                        |
@@ -213,7 +212,7 @@
 |                                | == *t2* - *t3* and *t2* == *t1* + *t3* are    |
 |                                | true. (1)                                     |
 +--------------------------------+-----------------------------------------------+
-| ``t1 = t2 * i or t1 = i * t2`` | Delta multiplied by an integer or long.       |
+| ``t1 = t2 * i or t1 = i * t2`` | Delta multiplied by an integer.               |
 |                                | Afterwards *t1* // i == *t2* is true,         |
 |                                | provided ``i != 0``.                          |
 +--------------------------------+-----------------------------------------------+
@@ -260,10 +259,30 @@
 comparison is ``==`` or ``!=``.  The latter cases return :const:`False` or
 :const:`True`, respectively.
 
-:class:`timedelta` objects are hashable (usable as dictionary keys), support
+:class:`timedelta` objects are :term:`hashable` (usable as dictionary keys), support
 efficient pickling, and in Boolean contexts, a :class:`timedelta` object is
 considered to be true if and only if it isn't equal to ``timedelta(0)``.
 
+Example usage:
+    
+    >>> from datetime import timedelta
+    >>> year = timedelta(days=365)
+    >>> another_year = timedelta(weeks=40, days=84, hours=23, 
+    ...                          minutes=50, seconds=600)  # adds up to 365 days
+    >>> year == another_year
+    True
+    >>> ten_years = 10 * year
+    >>> ten_years, ten_years.days // 365
+    (datetime.timedelta(3650), 10)
+    >>> nine_years = ten_years - year
+    >>> nine_years, nine_years.days // 365
+    (datetime.timedelta(3285), 9)
+    >>> three_years = nine_years // 3;
+    >>> three_years, three_years.days // 365
+    (datetime.timedelta(1095), 3)
+    >>> abs(three_years - ten_years) == 2 * three_years + year
+    True
+
 
 .. _datetime-date:
 
@@ -282,7 +301,7 @@
 
 .. class:: date(year, month, day)
 
-   All arguments are required.  Arguments may be ints or longs, in the following
+   All arguments are required.  Arguments may be integers, in the following
    ranges:
 
    * ``MINYEAR <= year <= MAXYEAR``
@@ -485,6 +504,57 @@
    Format codes referring to hours, minutes or seconds will see 0 values. See
    section :ref:`strftime-behavior`.
 
+Example of counting days to an event::
+
+    >>> import time
+    >>> from datetime import date
+    >>> today = date.today()
+    >>> today
+    datetime.date(2007, 12, 5)
+    >>> today == date.fromtimestamp(time.time())
+    True
+    >>> my_birthday = date(today.year, 6, 24)
+    >>> if my_birthday < today:
+    ...     my_birthday = my_birthday.replace(year=today.year + 1) 
+    >>> my_birthday
+    datetime.date(2008, 6, 24)
+    >>> time_to_birthday = abs(my_birthday - today) 
+    >>> time_to_birthday.days
+    202
+
+Example of working with :class:`date`:
+
+.. doctest::
+
+    >>> from datetime import date
+    >>> d = date.fromordinal(730920) # 730920th day after 1. 1. 0001
+    >>> d
+    datetime.date(2002, 3, 11)
+    >>> t = d.timetuple()
+    >>> for i in t:     # doctest: +SKIP
+    ...     print i
+    2002                # year
+    3                   # month
+    11                  # day
+    0
+    0
+    0
+    0                   # weekday (0 = Monday)
+    70                  # 70th day in the year
+    -1
+    >>> ic = d.isocalendar()
+    >>> for i in ic:    # doctest: +SKIP
+    ...     print i
+    2002                # ISO year
+    11                  # ISO week number
+    1                   # ISO day number ( 1 = Monday )
+    >>> d.isoformat()
+    '2002-03-11'
+    >>> d.strftime("%d/%m/%y")
+    '11/03/02'
+    >>> d.strftime("%A %d. %B %Y")
+    'Monday 11. March 2002'
+
 
 .. _datetime-datetime:
 
@@ -503,8 +573,8 @@
 .. class:: datetime(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])
 
    The year, month and day arguments are required.  *tzinfo* may be ``None``, or an
-   instance of a :class:`tzinfo` subclass.  The remaining arguments may be ints or
-   longs, in the following ranges:
+   instance of a :class:`tzinfo` subclass.  The remaining arguments may be integers,
+   in the following ranges:
 
    * ``MINYEAR <= year <= MAXYEAR``
    * ``1 <= month <= 12``
@@ -889,7 +959,7 @@
    YYYY-MM-DDTHH:MM:SS+HH:MM
 
    The optional argument *sep* (default ``'T'``) is a one-character separator,
-   placed between the date and time portions of the result.  For example, ::
+   placed between the date and time portions of the result.  For example,
 
       >>> from datetime import tzinfo, timedelta, datetime
       >>> class TZ(tzinfo):
@@ -919,6 +989,108 @@
    Return a string representing the date and time, controlled by an explicit format
    string.  See section :ref:`strftime-behavior`.
 
+Examples of working with datetime objects:
+
+.. doctest::
+
+    >>> from datetime import datetime, date, time
+    >>> # Using datetime.combine()
+    >>> d = date(2005, 7, 14)
+    >>> t = time(12, 30)
+    >>> datetime.combine(d, t)
+    datetime.datetime(2005, 7, 14, 12, 30)
+    >>> # Using datetime.now() or datetime.utcnow()
+    >>> datetime.now()   # doctest: +SKIP
+    datetime.datetime(2007, 12, 6, 16, 29, 43, 79043)   # GMT +1
+    >>> datetime.utcnow()   # doctest: +SKIP
+    datetime.datetime(2007, 12, 6, 15, 29, 43, 79060)
+    >>> # Using datetime.strptime()
+    >>> dt = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")
+    >>> dt
+    datetime.datetime(2006, 11, 21, 16, 30)
+    >>> # Using datetime.timetuple() to get tuple of all attributes
+    >>> tt = dt.timetuple()
+    >>> for it in tt:   # doctest: +SKIP
+    ...     print it
+    ... 
+    2006    # year
+    11      # month
+    21      # day
+    16      # hour
+    30      # minute
+    0       # second
+    1       # weekday (0 = Monday)
+    325     # number of days since 1st January
+    -1      # dst - method tzinfo.dst() returned None
+    >>> # Date in ISO format
+    >>> ic = dt.isocalendar()
+    >>> for it in ic:   # doctest: +SKIP
+    ...     print it
+    ...
+    2006    # ISO year
+    47      # ISO week
+    2       # ISO weekday
+    >>> # Formatting datetime
+    >>> dt.strftime("%A, %d. %B %Y %I:%M%p")
+    'Tuesday, 21. November 2006 04:30PM'
+
+Using datetime with tzinfo:
+
+    >>> from datetime import timedelta, datetime, tzinfo
+    >>> class GMT1(tzinfo):
+    ...     def __init__(self):         # DST starts last Sunday in March
+    ...         d = datetime(dt.year, 4, 1)   # ends last Sunday in October
+    ...         self.dston = d - timedelta(days=d.weekday() + 1)
+    ...         d = datetime(dt.year, 11, 1)    
+    ...         self.dstoff = d - timedelta(days=d.weekday() + 1)
+    ...     def utcoffset(self, dt):
+    ...         return timedelta(hours=1) + self.dst(dt)
+    ...     def dst(self, dt):              
+    ...         if self.dston <=  dt.replace(tzinfo=None) < self.dstoff:
+    ...             return timedelta(hours=1)
+    ...         else:
+    ...             return timedelta(0)
+    ...     def tzname(self,dt):
+    ...          return "GMT +1"
+    ... 
+    >>> class GMT2(tzinfo):
+    ...     def __init__(self):
+    ...         d = datetime(dt.year, 4, 1)  
+    ...         self.dston = d - timedelta(days=d.weekday() + 1)
+    ...         d = datetime(dt.year, 11, 1)    
+    ...         self.dstoff = d - timedelta(days=d.weekday() + 1)
+    ...     def utcoffset(self, dt):
+    ...         return timedelta(hours=1) + self.dst(dt)
+    ...     def dst(self, dt):
+    ...         if self.dston <=  dt.replace(tzinfo=None) < self.dstoff:
+    ...             return timedelta(hours=2)
+    ...         else:
+    ...             return timedelta(0)
+    ...     def tzname(self,dt):
+    ...         return "GMT +2"
+    ... 
+    >>> gmt1 = GMT1()
+    >>> # Daylight Saving Time
+    >>> dt1 = datetime(2006, 11, 21, 16, 30, tzinfo=gmt1)
+    >>> dt1.dst()
+    datetime.timedelta(0)
+    >>> dt1.utcoffset()
+    datetime.timedelta(0, 3600)
+    >>> dt2 = datetime(2006, 6, 14, 13, 0, tzinfo=gmt1)
+    >>> dt2.dst()
+    datetime.timedelta(0, 3600)
+    >>> dt2.utcoffset()
+    datetime.timedelta(0, 7200)
+    >>> # Convert datetime to another time zone
+    >>> dt3 = dt2.astimezone(GMT2())
+    >>> dt3     # doctest: +ELLIPSIS
+    datetime.datetime(2006, 6, 14, 14, 0, tzinfo=<GMT2 object at 0x...>)
+    >>> dt2     # doctest: +ELLIPSIS
+    datetime.datetime(2006, 6, 14, 13, 0, tzinfo=<GMT1 object at 0x...>)
+    >>> dt2.utctimetuple() == dt3.utctimetuple()
+    True
+ 
+
 
 .. _datetime-time:
 
@@ -932,7 +1104,7 @@
 .. class:: time(hour[, minute[, second[, microsecond[, tzinfo]]]])
 
    All arguments are optional.  *tzinfo* may be ``None``, or an instance of a
-   :class:`tzinfo` subclass.  The remaining arguments may be ints or longs, in the
+   :class:`tzinfo` subclass.  The remaining arguments may be integers, in the
    following ranges:
 
    * ``0 <= hour < 24``
@@ -1064,6 +1236,30 @@
    ``self.tzinfo.tzname(None)``, or raises an exception if the latter doesn't
    return ``None`` or a string object.
 
+Example:
+    
+    >>> from datetime import time, tzinfo
+    >>> class GMT1(tzinfo):
+    ...     def utcoffset(self, dt):
+    ...         return timedelta(hours=1) 
+    ...     def dst(self, dt):              
+    ...         return timedelta(0)
+    ...     def tzname(self,dt):
+    ...         return "Europe/Prague"
+    ...
+    >>> t = time(12, 10, 30, tzinfo=GMT1())
+    >>> t                               # doctest: +ELLIPSIS
+    datetime.time(12, 10, 30, tzinfo=<GMT1 object at 0x...>)
+    >>> gmt = GMT1()
+    >>> t.isoformat()
+    '12:10:30+01:00'
+    >>> t.dst()
+    datetime.timedelta(0)
+    >>> t.tzname()
+    'Europe/Prague'
+    >>> t.strftime("%H:%M:%S %Z")
+    '12:10:30 Europe/Prague'
+
 
 .. _datetime-tzinfo:
 
@@ -1277,7 +1473,7 @@
 :class:`tzinfo` subclasses; there are no ambiguities when using UTC, or any
 other fixed-offset :class:`tzinfo` subclass (such as a class representing only
 EST (fixed offset -5 hours), or only EDT (fixed offset -4 hours)).
-
+    
 
 .. _strftime-behavior:
 
@@ -1294,9 +1490,15 @@
 be used, as time objects have no such values.  If they're used anyway, ``1900``
 is substituted for the year, and ``0`` for the month and day.
 
-For :class:`date` objects, the format codes for hours, minutes, and seconds
-should not be used, as :class:`date` objects have no such values.  If they're
-used anyway, ``0`` is substituted for them.
+For :class:`date` objects, the format codes for hours, minutes, seconds, and
+microseconds should not be used, as :class:`date` objects have no such
+values.  If they're used anyway, ``0`` is substituted for them.
+
+:class:`time` and :class:`datetime` objects support a ``%f`` format code
+which expands to the number of microseconds in the object, zero-padded on
+the left to six places.
+
+.. versionadded:: 2.6
 
 For a naive object, the ``%z`` and ``%Z`` format codes are replaced by empty
 strings.
@@ -1316,30 +1518,120 @@
 
 The full set of format codes supported varies across platforms, because Python
 calls the platform C library's :func:`strftime` function, and platform
-variations are common.  The documentation for Python's :mod:`time` module lists
-the format codes that the C standard (1989 version) requires, and those work on
-all platforms with a standard C implementation.  Note that the 1999 version of
-the C standard added additional format codes.
+variations are common.  
+
+The following is a list of all the format codes that the C standard (1989
+version) requires, and these work on all platforms with a standard C
+implementation.  Note that the 1999 version of the C standard added additional
+format codes.
 
 The exact range of years for which :meth:`strftime` works also varies across
 platforms.  Regardless of platform, years before 1900 cannot be used.
 
-.. % %% This example is obsolete, since strptime is now supported by datetime.
-.. % 
-.. % \subsection{Examples}
-.. % 
-.. % \subsubsection{Creating Datetime Objects from Formatted Strings}
-.. % 
-.. % The \class{datetime} class does not directly support parsing formatted time
-.. % strings.  You can use \function{time.strptime} to do the parsing and create
-.. % a \class{datetime} object from the tuple it returns:
-.. % 
-.. % \begin{verbatim}
-.. % >>> s = "2005-12-06T12:13:14"
-.. % >>> from datetime import datetime
-.. % >>> from time import strptime
-.. % >>> datetime(*strptime(s, "%Y-%m-%dT%H:%M:%S")[0:6])
-.. % datetime.datetime(2005, 12, 6, 12, 13, 14)
-.. % \end{verbatim}
-.. % 
++-----------+--------------------------------+-------+
+| Directive | Meaning                        | Notes |
++===========+================================+=======+
+| ``%a``    | Locale's abbreviated weekday   |       |
+|           | name.                          |       |
++-----------+--------------------------------+-------+
+| ``%A``    | Locale's full weekday name.    |       |
++-----------+--------------------------------+-------+
+| ``%b``    | Locale's abbreviated month     |       |
+|           | name.                          |       |
++-----------+--------------------------------+-------+
+| ``%B``    | Locale's full month name.      |       |
++-----------+--------------------------------+-------+
+| ``%c``    | Locale's appropriate date and  |       |
+|           | time representation.           |       |
++-----------+--------------------------------+-------+
+| ``%d``    | Day of the month as a decimal  |       |
+|           | number [01,31].                |       |
++-----------+--------------------------------+-------+
+| ``%f``    | Microsecond as a decimal       | \(1)  |
+|           | number [0,999999], zero-padded |       |
+|           | on the left                    |       |
++-----------+--------------------------------+-------+
+| ``%H``    | Hour (24-hour clock) as a      |       |
+|           | decimal number [00,23].        |       |
++-----------+--------------------------------+-------+
+| ``%I``    | Hour (12-hour clock) as a      |       |
+|           | decimal number [01,12].        |       |
++-----------+--------------------------------+-------+
+| ``%j``    | Day of the year as a decimal   |       |
+|           | number [001,366].              |       |
++-----------+--------------------------------+-------+
+| ``%m``    | Month as a decimal number      |       |
+|           | [01,12].                       |       |
++-----------+--------------------------------+-------+
+| ``%M``    | Minute as a decimal number     |       |
+|           | [00,59].                       |       |
++-----------+--------------------------------+-------+
+| ``%p``    | Locale's equivalent of either  | \(2)  |
+|           | AM or PM.                      |       |
++-----------+--------------------------------+-------+
+| ``%S``    | Second as a decimal number     | \(3)  |
+|           | [00,61].                       |       |
++-----------+--------------------------------+-------+
+| ``%U``    | Week number of the year        | \(4)  |
+|           | (Sunday as the first day of    |       |
+|           | the week) as a decimal number  |       |
+|           | [00,53].  All days in a new    |       |
+|           | year preceding the first       |       |
+|           | Sunday are considered to be in |       |
+|           | week 0.                        |       |
++-----------+--------------------------------+-------+
+| ``%w``    | Weekday as a decimal number    |       |
+|           | [0(Sunday),6].                 |       |
++-----------+--------------------------------+-------+
+| ``%W``    | Week number of the year        | \(4)  |
+|           | (Monday as the first day of    |       |
+|           | the week) as a decimal number  |       |
+|           | [00,53].  All days in a new    |       |
+|           | year preceding the first       |       |
+|           | Monday are considered to be in |       |
+|           | week 0.                        |       |
++-----------+--------------------------------+-------+
+| ``%x``    | Locale's appropriate date      |       |
+|           | representation.                |       |
++-----------+--------------------------------+-------+
+| ``%X``    | Locale's appropriate time      |       |
+|           | representation.                |       |
++-----------+--------------------------------+-------+
+| ``%y``    | Year without century as a      |       |
+|           | decimal number [00,99].        |       |
++-----------+--------------------------------+-------+
+| ``%Y``    | Year with century as a decimal |       |
+|           | number.                        |       |
++-----------+--------------------------------+-------+
+| ``%z``    | UTC offset in the form +HHMM   | \(5)  |
+|           | or -HHMM (empty string if the  |       |
+|           | the object is naive).          |       |
++-----------+--------------------------------+-------+
+| ``%Z``    | Time zone name (empty string   |       |
+|           | if the object is naive).       |       |
++-----------+--------------------------------+-------+
+| ``%%``    | A literal ``'%'`` character.   |       |
++-----------+--------------------------------+-------+
+
+Notes:
+
+(1)
+   When used with the :func:`strptime` function, the ``%f`` directive
+   accepts from one to six digits and zero pads on the right.  ``%f`` is
+   an extension to the set of format characters in the C standard.
+
+(2)
+   When used with the :func:`strptime` function, the ``%p`` directive only affects
+   the output hour field if the ``%I`` directive is used to parse the hour.
+
+(3)
+   The range really is ``0`` to ``61``; this accounts for leap seconds and the
+   (very rare) double leap seconds.
+
+(4)
+   When used with the :func:`strptime` function, ``%U`` and ``%W`` are only used in
+   calculations when the day of the week and the year are specified.
 
+(5)
+   For example, if :meth:`utcoffset` returns ``timedelta(hours=-3, minutes=-30)``,
+   ``%z`` is replaced with the string ``'-0330'``.

Modified: python/branches/py3k-importlib/Doc/library/decimal.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/decimal.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/decimal.rst	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,6 @@
 
-:mod:`decimal` --- Decimal floating point arithmetic
-====================================================
+:mod:`decimal` --- Decimal fixed point and floating point arithmetic
+====================================================================
 
 .. module:: decimal
    :synopsis: Implementation of the General Decimal Arithmetic  Specification.
@@ -12,10 +12,23 @@
 .. moduleauthor:: Tim Peters <tim.one at comcast.net>
 .. sectionauthor:: Raymond D. Hettinger <python at rcn.com>
 
+.. import modules for testing inline doctests with the Sphinx doctest builder
+.. testsetup:: *
+
+   import decimal
+   import math
+   from decimal import *
+   # make sure each group gets a fresh context
+   setcontext(Context())
 
 The :mod:`decimal` module provides support for decimal floating point
 arithmetic.  It offers several advantages over the :class:`float` datatype:
 
+* Decimal "is based on a floating-point model which was designed with people
+  in mind, and necessarily has a paramount guiding principle -- computers must
+  provide an arithmetic that works in the same way as the arithmetic that
+  people learn at school." -- excerpt from the decimal arithmetic specification.
+
 * Decimal numbers can be represented exactly.  In contrast, numbers like
   :const:`1.1` do not have an exact representation in binary floating point. End
   users typically would not expect :const:`1.1` to display as
@@ -25,7 +38,7 @@
   + 0.1 + 0.1 - 0.3`` is exactly equal to zero.  In binary floating point, the result
   is :const:`5.5511151231257827e-017`.  While near to zero, the differences
   prevent reliable equality testing and differences can accumulate. For this
-  reason, decimal would be preferred in accounting applications which have strict
+  reason, decimal is preferred in accounting applications which have strict
   equality invariants.
 
 * The decimal module incorporates a notion of significant places so that ``1.30
@@ -37,19 +50,26 @@
 
 * Unlike hardware based binary floating point, the decimal module has a user
   alterable precision (defaulting to 28 places) which can be as large as needed for
-  a given problem::
+  a given problem:
 
      >>> getcontext().prec = 6
      >>> Decimal(1) / Decimal(7)
-     Decimal("0.142857")
+     Decimal('0.142857')
      >>> getcontext().prec = 28
      >>> Decimal(1) / Decimal(7)
-     Decimal("0.1428571428571428571428571429")
+     Decimal('0.1428571428571428571428571429')
 
 * Both binary and decimal floating point are implemented in terms of published
   standards.  While the built-in float type exposes only a modest portion of its
   capabilities, the decimal module exposes all required parts of the standard.
   When needed, the programmer has full control over rounding and signal handling.
+  This includes an option to enforce exact arithmetic by using exceptions
+  to block any inexact operations.
+
+* The decimal module was designed to support "without prejudice, both exact
+  unrounded decimal arithmetic (sometimes called fixed-point arithmetic)
+  and rounded floating-point arithmetic."  -- excerpt from the decimal
+  arithmetic specification.
 
 The module design is centered around three concepts:  the decimal number, the
 context for arithmetic, and signals.
@@ -75,7 +95,7 @@
 :const:`Overflow`, and :const:`Underflow`.
 
 For each signal there is a flag and a trap enabler.  When a signal is
-encountered, its flag is incremented from zero and, then, if the trap enabler is
+encountered, its flag is set to one, then, if the trap enabler is
 set to one, an exception is raised.  Flags are sticky, so the user needs to
 reset them before monitoring a calculation.
 
@@ -86,9 +106,9 @@
      Specification <http://www2.hursley.ibm.com/decimal/decarith.html>`_.
 
    * IEEE standard 854-1987, `Unofficial IEEE 854 Text
-     <http://www.cs.berkeley.edu/~ejr/projects/754/private/drafts/854-1987/dir.html>`_.
+     <http://754r.ucbtest.org/standards/854.pdf>`_.
 
-.. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+.. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
 .. _decimal-tutorial:
@@ -103,8 +123,8 @@
    >>> from decimal import *
    >>> getcontext()
    Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-999999999, Emax=999999999,
-           capitals=1, flags=[], traps=[Overflow, InvalidOperation,
-           DivisionByZero])
+           capitals=1, flags=[], traps=[Overflow, DivisionByZero,
+           InvalidOperation])
 
    >>> getcontext().prec = 7       # Set a new precision
 
@@ -113,51 +133,56 @@
 serves as an explicit reminder of the details of the conversion (including
 representation error).  Decimal numbers include special values such as
 :const:`NaN` which stands for "Not a number", positive and negative
-:const:`Infinity`, and :const:`-0`.         ::
+:const:`Infinity`, and :const:`-0`.
 
    >>> Decimal(10)
-   Decimal("10")
-   >>> Decimal("3.14")
-   Decimal("3.14")
+   Decimal('10')
+   >>> Decimal('3.14')
+   Decimal('3.14')
    >>> Decimal((0, (3, 1, 4), -2))
-   Decimal("3.14")
+   Decimal('3.14')
    >>> Decimal(str(2.0 ** 0.5))
-   Decimal("1.41421356237")
-   >>> Decimal(2) ** Decimal("0.5")
-   Decimal("1.414213562373095048801688724")
-   >>> Decimal("NaN")
-   Decimal("NaN")
-   >>> Decimal("-Infinity")
-   Decimal("-Infinity")
+   Decimal('1.41421356237')
+   >>> Decimal(2) ** Decimal('0.5')
+   Decimal('1.414213562373095048801688724')
+   >>> Decimal('NaN')
+   Decimal('NaN')
+   >>> Decimal('-Infinity')
+   Decimal('-Infinity')
 
 The significance of a new Decimal is determined solely by the number of digits
 input.  Context precision and rounding only come into play during arithmetic
-operations. ::
+operations.
+
+.. doctest:: newcontext
 
    >>> getcontext().prec = 6
    >>> Decimal('3.0')
-   Decimal("3.0")
+   Decimal('3.0')
    >>> Decimal('3.1415926535')
-   Decimal("3.1415926535")
+   Decimal('3.1415926535')
    >>> Decimal('3.1415926535') + Decimal('2.7182818285')
-   Decimal("5.85987")
+   Decimal('5.85987')
    >>> getcontext().rounding = ROUND_UP
    >>> Decimal('3.1415926535') + Decimal('2.7182818285')
-   Decimal("5.85988")
+   Decimal('5.85988')
 
 Decimals interact well with much of the rest of Python.  Here is a small decimal
-floating point flying circus::
+floating point flying circus:
+
+.. doctest::
+   :options: +NORMALIZE_WHITESPACE
 
    >>> data = map(Decimal, '1.34 1.87 3.45 2.35 1.00 0.03 9.25'.split())
    >>> max(data)
-   Decimal("9.25")
+   Decimal('9.25')
    >>> min(data)
-   Decimal("0.03")
+   Decimal('0.03')
    >>> sorted(data)
-   [Decimal("0.03"), Decimal("1.00"), Decimal("1.34"), Decimal("1.87"),
-    Decimal("2.35"), Decimal("3.45"), Decimal("9.25")]
+   [Decimal('0.03'), Decimal('1.00'), Decimal('1.34'), Decimal('1.87'),
+    Decimal('2.35'), Decimal('3.45'), Decimal('9.25')]
    >>> sum(data)
-   Decimal("19.29")
+   Decimal('19.29')
    >>> a,b,c = data[:3]
    >>> str(a)
    '1.34'
@@ -168,31 +193,31 @@
    >>> int(a)
    1
    >>> a * 5
-   Decimal("6.70")
+   Decimal('6.70')
    >>> a * b
-   Decimal("2.5058")
+   Decimal('2.5058')
    >>> c % a
-   Decimal("0.77")
+   Decimal('0.77')
 
-And some mathematic functions are also available to Decimal::
+And some mathematical functions are also available to Decimal:
 
    >>> Decimal(2).sqrt()
-   Decimal("1.414213562373095048801688724")
+   Decimal('1.414213562373095048801688724')
    >>> Decimal(1).exp()
-   Decimal("2.718281828459045235360287471")
-   >>> Decimal("10").ln()
-   Decimal("2.302585092994045684017991455")
-   >>> Decimal("10").log10()
-   Decimal("1")
+   Decimal('2.718281828459045235360287471')
+   >>> Decimal('10').ln()
+   Decimal('2.302585092994045684017991455')
+   >>> Decimal('10').log10()
+   Decimal('1')
 
 The :meth:`quantize` method rounds a number to a fixed exponent.  This method is
 useful for monetary applications that often round results to a fixed number of
-places::
+places:
 
    >>> Decimal('7.325').quantize(Decimal('.01'), rounding=ROUND_DOWN)
-   Decimal("7.32")
+   Decimal('7.32')
    >>> Decimal('7.325').quantize(Decimal('1.'), rounding=ROUND_UP)
-   Decimal("8")
+   Decimal('8')
 
 As shown above, the :func:`getcontext` function accesses the current context and
 allows the settings to be changed.  This approach meets the needs of most
@@ -205,21 +230,24 @@
 In accordance with the standard, the :mod:`Decimal` module provides two ready to
 use standard contexts, :const:`BasicContext` and :const:`ExtendedContext`. The
 former is especially useful for debugging because many of the traps are
-enabled::
+enabled:
+
+.. doctest:: newcontext
+   :options: +NORMALIZE_WHITESPACE
 
    >>> myothercontext = Context(prec=60, rounding=ROUND_HALF_DOWN)
    >>> setcontext(myothercontext)
    >>> Decimal(1) / Decimal(7)
-   Decimal("0.142857142857142857142857142857142857142857142857142857142857")
+   Decimal('0.142857142857142857142857142857142857142857142857142857142857')
 
    >>> ExtendedContext
    Context(prec=9, rounding=ROUND_HALF_EVEN, Emin=-999999999, Emax=999999999,
            capitals=1, flags=[], traps=[])
    >>> setcontext(ExtendedContext)
    >>> Decimal(1) / Decimal(7)
-   Decimal("0.142857143")
+   Decimal('0.142857143')
    >>> Decimal(42) / Decimal(0)
-   Decimal("Infinity")
+   Decimal('Infinity')
 
    >>> setcontext(BasicContext)
    >>> Decimal(42) / Decimal(0)
@@ -236,20 +264,23 @@
    >>> setcontext(ExtendedContext)
    >>> getcontext().clear_flags()
    >>> Decimal(355) / Decimal(113)
-   Decimal("3.14159292")
+   Decimal('3.14159292')
    >>> getcontext()
    Context(prec=9, rounding=ROUND_HALF_EVEN, Emin=-999999999, Emax=999999999,
-           capitals=1, flags=[Inexact, Rounded], traps=[])
+           capitals=1, flags=[Rounded, Inexact], traps=[])
 
 The *flags* entry shows that the rational approximation to :const:`Pi` was
 rounded (digits beyond the context precision were thrown away) and that the
 result is inexact (some of the discarded digits were non-zero).
 
 Individual traps are set using the dictionary in the :attr:`traps` field of a
-context::
+context:
 
+.. doctest:: newcontext
+
+   >>> setcontext(ExtendedContext)
    >>> Decimal(1) / Decimal(0)
-   Decimal("Infinity")
+   Decimal('Infinity')
    >>> getcontext().traps[DivisionByZero] = 1
    >>> Decimal(1) / Decimal(0)
    Traceback (most recent call last):
@@ -263,7 +294,7 @@
 the program manipulates the data no differently than with other Python numeric
 types.
 
-.. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+.. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
 .. _decimal-decimal:
@@ -274,11 +305,12 @@
 
 .. class:: Decimal([value [, context]])
 
-   Constructs a new :class:`Decimal` object based from *value*.
+   Construct a new :class:`Decimal` object based from *value*.
 
-   *value* can be an integer, string, tuple, or another :class:`Decimal` object. If
-   no *value* is given, returns ``Decimal("0")``.  If *value* is a string, it
-   should conform to the decimal numeric string syntax::
+   *value* can be an integer, string, tuple, or another :class:`Decimal`
+   object. If no *value* is given, returns ``Decimal('0')``.  If *value* is a
+   string, it should conform to the decimal numeric string syntax after leading
+   and trailing whitespace characters are removed::
 
       sign           ::=  '+' | '-'
       digit          ::=  '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
@@ -294,11 +326,11 @@
    If *value* is a :class:`tuple`, it should have three components, a sign
    (:const:`0` for positive or :const:`1` for negative), a :class:`tuple` of
    digits, and an integer exponent. For example, ``Decimal((0, (1, 4, 1, 4), -3))``
-   returns ``Decimal("1.414")``.
+   returns ``Decimal('1.414')``.
 
    The *context* precision does not affect how many digits are stored. That is
    determined exclusively by the number of digits in *value*. For example,
-   ``Decimal("3.00000")`` records all five zeros even if the context precision is
+   ``Decimal('3.00000')`` records all five zeros even if the context precision is
    only three.
 
    The purpose of the *context* argument is determining what to do if *value* is a
@@ -308,6 +340,10 @@
 
    Once constructed, :class:`Decimal` objects are immutable.
 
+   .. versionchanged:: 2.6
+      leading and trailing whitespace characters are permitted when
+      creating a Decimal instance from a string.
+
 Decimal floating point objects share many properties with the other built-in
 numeric types such as :class:`float` and :class:`int`.  All of the usual math
 operations and special methods apply.  Likewise, decimal objects can be copied,
@@ -321,14 +357,18 @@
 .. method:: Decimal.adjusted()
 
    Return the adjusted exponent after shifting out the coefficient's rightmost
-   digits until only the lead digit remains: ``Decimal("321e+5").adjusted()``
+   digits until only the lead digit remains: ``Decimal('321e+5').adjusted()``
    returns seven.  Used for determining the position of the most significant digit
    with respect to the decimal point.
 
 
 .. method:: Decimal.as_tuple()
 
-   Return a tuple representation of the number: ``(sign, digit_tuple, exponent)``.
+   Return a :term:`named tuple` representation of the number:
+   ``DecimalTuple(sign, digits, exponent)``.
+
+   .. versionchanged:: 2.6
+      Use a named tuple.
 
 
 .. method:: Decimal.canonical()
@@ -337,7 +377,6 @@
    encoding of a :class:`Decimal` instance is always canonical, so
    this operation returns its argument unchanged.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.compare(other[, context])
 
@@ -347,10 +386,10 @@
    instance rather than an integer, and if either operand is a NaN
    then the result is a NaN::
 
-      a or b is a NaN ==> Decimal("NaN")
-      a < b           ==> Decimal("-1")
-      a == b          ==> Decimal("0")
-      a > b           ==> Decimal("1")
+      a or b is a NaN ==> Decimal('NaN')
+      a < b           ==> Decimal('-1')
+      a == b          ==> Decimal('0')
+      a > b           ==> Decimal('1')
 
 .. method:: Decimal.compare_signal(other[, context])
 
@@ -359,7 +398,6 @@
    NaN then any quiet NaN operand is treated as though it were a
    signaling NaN.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.compare_total(other)
 
@@ -368,20 +406,19 @@
    but the result gives a total ordering on :class:`Decimal`
    instances.  Two :class:`Decimal` instances with the same numeric
    value but different representations compare unequal in this
-   ordering::
+   ordering:
    
-      >>> Decimal("12.0").compare_total(Decimal("12"))
-      Decimal("-1")
+      >>> Decimal('12.0').compare_total(Decimal('12'))
+      Decimal('-1')
 
    Quiet and signaling NaNs are also included in the total ordering.
-   The result of this function is ``Decimal("0")`` if both operands
-   have the same representation, ``Decimal("-1")`` if the first
+   The result of this function is ``Decimal('0')`` if both operands
+   have the same representation, ``Decimal('-1')`` if the first
    operand is lower in the total order than the second, and
-   ``Decimal("1")`` if the first operand is higher in the total order
+   ``Decimal('1')`` if the first operand is higher in the total order
    than the second operand.  See the specification for details of the
    total order.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.compare_total_mag(other)
 
@@ -390,7 +427,6 @@
    of each operand.  ``x.compare_total_mag(y)`` is equivalent to
    ``x.copy_abs().compare_total(y.copy_abs())``.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.copy_abs()
 
@@ -398,7 +434,6 @@
    unaffected by the context and is quiet: no flags are changed and no
    rounding is performed.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.copy_negate()
 
@@ -406,20 +441,18 @@
    by the context and is quiet: no flags are changed and no rounding
    is performed.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.copy_sign(other)
 
    Return a copy of the first operand with the sign set to be the
-   same as the sign of the second operand.  For example::
+   same as the sign of the second operand.  For example:
 
-      >>> Decimal("2.3").copy_sign(Decimal("-1.5"))
-      Decimal("-2.3")
+      >>> Decimal('2.3').copy_sign(Decimal('-1.5'))
+      Decimal('-2.3')
    
    This operation is unaffected by the context and is quiet: no flags
    are changed and no rounding is performed.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.exp([context])
 
@@ -428,11 +461,10 @@
    :const:`ROUND_HALF_EVEN` rounding mode.
 
    >>> Decimal(1).exp()
-   Decimal("2.718281828459045235360287471")
+   Decimal('2.718281828459045235360287471')
    >>> Decimal(321).exp()
-   Decimal("2.561702493119680037517373933E+139")
+   Decimal('2.561702493119680037517373933E+139')
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.fma(other, third[, context])
 
@@ -440,9 +472,8 @@
    the intermediate product self*other.
 
    >>> Decimal(2).fma(3, 5)
-   Decimal("11")
+   Decimal('11')
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.is_canonical()
 
@@ -451,28 +482,24 @@
    is always canonical, so this operation always returns
    :const:`True`.
 
-   .. versionadded:: 2.6
 
 .. method:: is_finite()
 
    Return :const:`True` if the argument is a finite number, and
    :const:`False` if the argument is an infinity or a NaN.
 
-   .. versionadded:: 2.6
 
 .. method:: is_infinite()
 
    Return :const:`True` if the argument is either positive or
    negative infinity and :const:`False` otherwise.
 
-   .. versionadded:: 2.6
 
 .. method:: is_nan()
 
    Return :const:`True` if the argument is a (quiet or signaling)
    NaN and :const:`False` otherwise.
 
-   .. versionadded:: 2.6
 
 .. method:: is_normal()
 
@@ -480,14 +507,12 @@
    Return :const:`False` if the argument is zero, subnormal, infinite
    or a NaN.
 
-   .. versionadded:: 2.6
 
 .. method:: is_qnan()
 
    Return :const:`True` if the argument is a quiet NaN, and
    :const:`False` otherwise.
 
-   .. versionadded:: 2.6
 
 .. method:: is_signed()
 
@@ -495,28 +520,24 @@
    :const:`False` otherwise.  Note that zeros and NaNs can both carry
    signs.
 
-   .. versionadded:: 2.6
 
 .. method:: is_snan()
 
    Return :const:`True` if the argument is a signaling NaN and
    :const:`False` otherwise.
 
-   .. versionadded:: 2.6
 
 .. method:: is_subnormal()
 
    Return :const:`True` if the argument is subnormal, and
    :const:`False` otherwise.
 
-   .. versionadded:: 2.6
 
 .. method:: is_zero()
 
    Return :const:`True` if the argument is a (positive or negative)
    zero and :const:`False` otherwise.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.ln([context])
 
@@ -524,24 +545,21 @@
    is correctly rounded using the :const:`ROUND_HALF_EVEN` rounding
    mode.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.log10([context])
 
    Return the base ten logarithm of the operand.  The result is
    correctly rounded using the :const:`ROUND_HALF_EVEN` rounding mode.
 
-   .. versionadded:: 2.6
 
-.. method:  Decimal.logb([context])
+.. method:: Decimal.logb([context])
 
    For a nonzero number, return the adjusted exponent of its operand
    as a :class:`Decimal` instance.  If the operand is a zero then
-   ``Decimal("-Infinity")`` is returned and the
+   ``Decimal('-Infinity')`` is returned and the
    :const:`DivisionByZero` flag is raised.  If the operand is an
-   infinity then ``Decimal("Infinity")`` is returned.
+   infinity then ``Decimal('Infinity')`` is returned.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.logical_and(other[, context])
 
@@ -549,7 +567,6 @@
    *logical operands* (see :ref:`logical_operands_label`).  The result
    is the digit-wise ``and`` of the two operands.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.logical_invert(other[, context])
 
@@ -557,7 +574,6 @@
    be a *logical operand* (see :ref:`logical_operands_label`).  The
    result is the digit-wise inversion of the operand.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.logical_or(other[, context])
 
@@ -565,7 +581,6 @@
    operands* (see :ref:`logical_operands_label`).  The result is the
    digit-wise ``or`` of the two operands.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.logical_xor(other[, context])
 
@@ -573,7 +588,6 @@
    *logical operands* (see :ref:`logical_operands_label`).  The result
    is the digit-wise exclusive or of the two operands.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.max(other[, context])
 
@@ -581,12 +595,12 @@
    before returning and that :const:`NaN` values are either signaled or ignored
    (depending on the context and whether they are signaling or quiet).
 
+
 .. method:: Decimal.max_mag(other[, context])
 
    Similar to the :meth:`max` method, but the comparison is done using
    the absolute values of the operands.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.min(other[, context])
 
@@ -599,7 +613,6 @@
    Similar to the :meth:`min` method, but the comparison is done using
    the absolute values of the operands.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.next_minus([context])
 
@@ -607,7 +620,6 @@
    in the current thread's context if no context is given) that is smaller
    than the given operand.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.next_plus([context])
 
@@ -615,7 +627,6 @@
    in the current thread's context if no context is given) that is
    larger than the given operand.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.next_toward(other[, context])
 
@@ -624,15 +635,15 @@
    operands are numerically equal, return a copy of the first operand
    with the sign set to be the same as the sign of the second operand.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.normalize([context])
 
    Normalize the number by stripping the rightmost trailing zeros and converting
-   any result equal to :const:`Decimal("0")` to :const:`Decimal("0e0")`. Used for
+   any result equal to :const:`Decimal('0')` to :const:`Decimal('0e0')`. Used for
    producing canonical values for members of an equivalence class. For example,
-   ``Decimal("32.100")`` and ``Decimal("0.321000e+2")`` both normalize to the
-   equivalent value ``Decimal("32.1")``.
+   ``Decimal('32.100')`` and ``Decimal('0.321000e+2')`` both normalize to the
+   equivalent value ``Decimal('32.1')``.
+
 
 .. method:: Decimal.number_class([context])
 
@@ -650,15 +661,14 @@
    * ``"NaN"``, indicating that the operand is a quiet NaN (Not a Number).
    * ``"sNaN"``, indicating that the operand is a signaling NaN.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.quantize(exp[, rounding[, context[, watchexp]]])
 
-   Returns a value equal to the first operand after rounding and
+   Return a value equal to the first operand after rounding and
    having the exponent of the second operand.
 
-   >>> Decimal("1.41421356").quantize(Decimal("1.000"))
-   Decimal("1.414")
+   >>> Decimal('1.41421356').quantize(Decimal('1.000'))
+   Decimal('1.414')
 
    Unlike other operations, if the length of the coefficient after the
    quantize operation would be greater than precision, then an
@@ -675,8 +685,8 @@
    the given ``context`` argument; if neither argument is given the
    rounding mode of the current thread's context is used.
 
-   If watchexp is set (default), then an error is returned whenever 
-   the resulting exponent is greater than Emax or less than Etiny.
+   If *watchexp* is set (default), then an error is returned whenever the
+   resulting exponent is greater than :attr:`Emax` or less than :attr:`Etiny`.
 
 .. method:: Decimal.radix()
 
@@ -684,13 +694,12 @@
    :class:`Decimal` class does all its arithmetic.  Included for
    compatibility with the specification.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.remainder_near(other[, context])
 
-   Computes the modulo as either a positive or negative value depending on which is
+   Compute the modulo as either a positive or negative value depending on which is
    closest to zero.  For instance, ``Decimal(10).remainder_near(6)`` returns
-   ``Decimal("-2")`` which is closer to zero than ``Decimal("4")``.
+   ``Decimal('-2')`` which is closer to zero than ``Decimal('4')``.
 
    If both are equally close, the one chosen will have the same sign as *self*.
 
@@ -706,7 +715,6 @@
    if necessary.  The sign and exponent of the first operand are
    unchanged.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.same_quantum(other[, context])
 
@@ -719,7 +727,6 @@
    Equivalently, return the first operand multiplied by ``10**other``.
    The second operand must be an integer.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.shift(other[, context])
 
@@ -732,7 +739,6 @@
    coefficient are zeros.  The sign and exponent of the first operand
    are unchanged.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.sqrt([context])
 
@@ -745,7 +751,7 @@
 
    Engineering notation has an exponent which is a multiple of 3, so there are up
    to 3 digits left of the decimal place.  For example, converts
-   ``Decimal('123E+1')`` to ``Decimal("1.23E+3")``
+   ``Decimal('123E+1')`` to ``Decimal('1.23E+3')``
 
 .. method:: Decimal.to_integral([rounding[, context]])
 
@@ -754,34 +760,29 @@
 
 .. method:: Decimal.to_integral_exact([rounding[, context]])
 
-   Round the argument to the nearest integer, signaling
+   Round to the nearest integer, signaling
    :const:`Inexact` or :const:`Rounded` as appropriate if rounding
    occurs.  The rounding mode is determined by the ``rounding``
    parameter if given, else by the given ``context``.  If neither
    parameter is given then the rounding mode of the current context is
    used.
 
-   .. versionadded:: 2.6
 
 .. method:: Decimal.to_integral_value([rounding[, context]])
 
-   Rounds to the nearest integer without signaling :const:`Inexact` or
+   Round to the nearest integer without signaling :const:`Inexact` or
    :const:`Rounded`.  If given, applies *rounding*; otherwise, uses the rounding
    method in either the supplied *context* or the current context.
 
-   .. versionchanged:: 2.6
-      renamed from ``to_integral`` to ``to_integral_value``.  The old name
-      remains valid for compatibility.
 
 .. method:: Decimal.trim()
 
-   Returns its argument with *insignificant* trailing zeros removed.
+   Return the decimal with *insignificant* trailing zeros removed.
    Here, a trailing zero is considered insignificant either if it
    follows the decimal point, or if the exponent of the argument (that
    is, the last element of the :meth:`as_tuple` representation) is
    positive.
 
-   .. versionadded:: 2.6
 
 .. _logical_operands_label:
 
@@ -794,7 +795,7 @@
 exponent and sign are both zero, and whose digits are all either
 :const:`0` or :const:`1`.
 
-.. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+.. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
 .. _decimal-context:
@@ -833,7 +834,6 @@
    For example, the following code sets the current decimal precision to 42 places,
    performs a calculation, and then automatically restores the previous context::
 
-      from __future__ import with_statement
       from decimal import localcontext
 
       with localcontext() as ctx:
@@ -863,7 +863,7 @@
    :const:`ROUND_HALF_EVEN`.  All flags are cleared.  No traps are enabled (so that
    exceptions are not raised during computations).
 
-   Because the trapped are disabled, this context is useful for applications that
+   Because the traps are disabled, this context is useful for applications that
    prefer to have result value of :const:`NaN` or :const:`Infinity` instead of
    raising exceptions.  This allows an application to complete a run in the
    presence of conditions that would otherwise halt the program.
@@ -921,8 +921,6 @@
    :const:`1`, exponents are printed with a capital :const:`E`; otherwise, a
    lowercase :const:`e` is used: :const:`Decimal('6.02e+23')`.
 
-   .. versionchanged:: 2.6
-      The :const:`ROUND_05UP` rounding mode was added.
 
 The :class:`Context` class defines several general purpose methods as
 well as a large number of methods for doing arithmetic directly in a
@@ -955,14 +953,19 @@
    needed by the application.  Another benefit is that rounding immediately
    eliminates unintended effects from digits beyond the current precision. In the
    following example, using unrounded inputs means that adding zero to a sum can
-   change the result::
+   change the result:
 
-      >>> getcontext().prec = 3
-      >>> Decimal("3.4445") + Decimal("1.0023")
-      Decimal("4.45")
-      >>> Decimal("3.4445") + Decimal(0) + Decimal("1.0023")
-      Decimal("4.44")
+   .. doctest:: newcontext
 
+      >>> getcontext().prec = 3
+      >>> Decimal('3.4445') + Decimal('1.0023')
+      Decimal('4.45')
+      >>> Decimal('3.4445') + Decimal(0) + Decimal('1.0023')
+      Decimal('4.44')
+
+   This method implements the to-number operation of the IBM
+   specification.  If the argument is a string, no leading or trailing
+   whitespace is permitted.
 
 .. method:: Context.Etiny()
 
@@ -1048,10 +1051,6 @@
    modulo`` with unbounded precision, but is computed more
    efficiently.  It is always exact.
 
-   .. versionchanged:: 2.6 
-      ``y`` may now be nonintegral in ``x**y``.
-      Stricter requirements for the three-argument version.
-
 
 .. method:: Context.remainder(x, y)
 
@@ -1068,7 +1067,7 @@
 
    Converts a number to a string using scientific notation.
 
-.. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+.. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
 .. _decimal-signals:
@@ -1079,7 +1078,7 @@
 Signals represent conditions that arise during computation. Each corresponds to
 one context flag and one context trap enabler.
 
-The context flag is incremented whenever the condition is encountered. After the
+The context flag is set whenever the condition is encountered. After the
 computation, flags may be checked for informational purposes (for instance, to
 determine whether a computation was exact). After checking the flags, be sure to
 clear all flags before starting the next computation.
@@ -1189,7 +1188,7 @@
            Rounded
            Subnormal
 
-.. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+.. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
 .. _decimal-notes:
@@ -1209,7 +1208,9 @@
 of nearly offsetting quantities resulting in loss of significance.  Knuth
 provides two instructive examples where rounded floating point arithmetic with
 insufficient precision causes the breakdown of the associative and distributive
-properties of addition::
+properties of addition:
+
+.. doctest:: newcontext
 
    # Examples from Seminumerical Algorithms, Section 4.2.2.
    >>> from decimal import Decimal, getcontext
@@ -1217,31 +1218,33 @@
 
    >>> u, v, w = Decimal(11111113), Decimal(-11111111), Decimal('7.51111111')
    >>> (u + v) + w
-   Decimal("9.5111111")
+   Decimal('9.5111111')
    >>> u + (v + w)
-   Decimal("10")
+   Decimal('10')
 
    >>> u, v, w = Decimal(20000), Decimal(-6), Decimal('6.0000003')
    >>> (u*v) + (u*w)
-   Decimal("0.01")
+   Decimal('0.01')
    >>> u * (v+w)
-   Decimal("0.0060000")
+   Decimal('0.0060000')
 
 The :mod:`decimal` module makes it possible to restore the identities by
-expanding the precision sufficiently to avoid loss of significance::
+expanding the precision sufficiently to avoid loss of significance:
+
+.. doctest:: newcontext
 
    >>> getcontext().prec = 20
    >>> u, v, w = Decimal(11111113), Decimal(-11111111), Decimal('7.51111111')
    >>> (u + v) + w
-   Decimal("9.51111111")
+   Decimal('9.51111111')
    >>> u + (v + w)
-   Decimal("9.51111111")
+   Decimal('9.51111111')
    >>> 
    >>> u, v, w = Decimal(20000), Decimal(-6), Decimal('6.0000003')
    >>> (u*v) + (u*w)
-   Decimal("0.0060000")
+   Decimal('0.0060000')
    >>> u * (v+w)
-   Decimal("0.0060000")
+   Decimal('0.0060000')
 
 
 Special values
@@ -1272,6 +1275,19 @@
 operation.  This is a useful return value when an invalid result needs to
 interrupt a calculation for special handling.
 
+The behavior of Python's comparison operators can be a little surprising where a
+:const:`NaN` is involved.  A test for equality where one of the operands is a
+quiet or signaling :const:`NaN` always returns :const:`False` (even when doing
+``Decimal('NaN')==Decimal('NaN')``), while a test for inequality always returns
+:const:`True`.  An attempt to compare two Decimals using any of the ``<``,
+``<=``, ``>`` or ``>=`` operators will raise the :exc:`InvalidOperation` signal
+if either operand is a :const:`NaN`, and return :const:`False` if this signal is
+not trapped.  Note that the General Decimal Arithmetic specification does not
+specify the behavior of direct comparisons; these rules for comparisons
+involving a :const:`NaN` were taken from the IEEE 854 standard (see Table 3 in
+section 5.7).  To ensure strict standards-compliance, use the :meth:`compare`
+and :meth:`compare-signal` methods instead.
+
 The signed zeros can result from calculations that underflow. They keep the sign
 that would have resulted if the calculation had been carried out to greater
 precision.  Since their magnitude is zero, both positive and negative zeros are
@@ -1281,12 +1297,12 @@
 various representations of zero with differing precisions yet equivalent in
 value.  This takes a bit of getting used to.  For an eye accustomed to
 normalized floating point representations, it is not immediately obvious that
-the following calculation returns a value equal to zero::
+the following calculation returns a value equal to zero:
 
    >>> 1 / Decimal('Infinity')
-   Decimal("0E-1000000026")
+   Decimal('0E-1000000026')
 
-.. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+.. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
 .. _decimal-threads:
@@ -1324,7 +1340,7 @@
    t3.start()
     . . .
 
-.. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+.. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
 .. _decimal-recipes:
@@ -1361,19 +1377,15 @@
        '<.02>'
 
        """
-       q = Decimal((0, (1,), -places))    # 2 places --> '0.01'
-       sign, digits, exp = value.quantize(q).as_tuple()
-       assert exp == -places    
+       q = Decimal(10) ** -places      # 2 places --> '0.01'
+       sign, digits, exp = value.quantize(q).as_tuple()  
        result = []
        digits = map(str, digits)
        build, next = result.append, digits.pop
        if sign:
            build(trailneg)
        for i in range(places):
-           if digits:
-               build(next())
-           else:
-               build('0')
+           build(next() if digits else '0')
        build(dp)
        i = 0
        while digits:
@@ -1383,12 +1395,8 @@
                i = 0
                build(sep)
        build(curr)
-       if sign:
-           build(neg)
-       else:
-           build(pos)
-       result.reverse()
-       return ''.join(result)
+       build(neg if sign else pos)
+       return ''.join(reversed(result))
 
    def pi():
        """Compute Pi to the current precision.
@@ -1480,7 +1488,7 @@
        return +s
 
 
-.. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+.. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
 .. _decimal-faq:
@@ -1491,40 +1499,67 @@
 Q. It is cumbersome to type ``decimal.Decimal('1234.5')``.  Is there a way to
 minimize typing when using the interactive interpreter?
 
-\A. Some users abbreviate the constructor to just a single letter::
+A. Some users abbreviate the constructor to just a single letter:
 
    >>> D = decimal.Decimal
    >>> D('1.23') + D('3.45')
-   Decimal("4.68")
+   Decimal('4.68')
 
 Q. In a fixed-point application with two decimal places, some inputs have many
 places and need to be rounded.  Others are not supposed to have excess digits
 and need to be validated.  What methods should be used?
 
 A. The :meth:`quantize` method rounds to a fixed number of decimal places. If
-the :const:`Inexact` trap is set, it is also useful for validation::
+the :const:`Inexact` trap is set, it is also useful for validation:
 
    >>> TWOPLACES = Decimal(10) ** -2       # same as Decimal('0.01')
 
    >>> # Round to two places
-   >>> Decimal("3.214").quantize(TWOPLACES)
-   Decimal("3.21")
+   >>> Decimal('3.214').quantize(TWOPLACES)
+   Decimal('3.21')
 
    >>> # Validate that a number does not exceed two places 
-   >>> Decimal("3.21").quantize(TWOPLACES, context=Context(traps=[Inexact]))
-   Decimal("3.21")
+   >>> Decimal('3.21').quantize(TWOPLACES, context=Context(traps=[Inexact]))
+   Decimal('3.21')
 
-   >>> Decimal("3.214").quantize(TWOPLACES, context=Context(traps=[Inexact]))
+   >>> Decimal('3.214').quantize(TWOPLACES, context=Context(traps=[Inexact]))
    Traceback (most recent call last):
       ...
-   Inexact: Changed in rounding
+   Inexact
 
 Q. Once I have valid two place inputs, how do I maintain that invariant
 throughout an application?
 
-A. Some operations like addition and subtraction automatically preserve fixed
-point.  Others, like multiplication and division, change the number of decimal
-places and need to be followed-up with a :meth:`quantize` step.
+A. Some operations like addition, subtraction, and multiplication by an integer
+will automatically preserve fixed point.  Others operations, like division and
+non-integer multiplication, will change the number of decimal places and need to
+be followed-up with a :meth:`quantize` step:
+
+    >>> a = Decimal('102.72')           # Initial fixed-point values
+    >>> b = Decimal('3.17')
+    >>> a + b                           # Addition preserves fixed-point
+    Decimal('105.89')
+    >>> a - b
+    Decimal('99.55')
+    >>> a * 42                          # So does integer multiplication
+    Decimal('4314.24')
+    >>> (a * b).quantize(TWOPLACES)     # Must quantize non-integer multiplication
+    Decimal('325.62')
+    >>> (b / a).quantize(TWOPLACES)     # And quantize division
+    Decimal('0.03')
+
+In developing fixed-point applications, it is convenient to define functions
+to handle the :meth:`quantize` step:
+
+    >>> def mul(x, y, fp=TWOPLACES):
+    ...     return (x * y).quantize(fp)
+    >>> def div(x, y, fp=TWOPLACES):
+    ...     return (x / y).quantize(fp)
+
+    >>> mul(a, b)                       # Automatically preserve fixed-point
+    Decimal('325.62')
+    >>> div(b, a)
+    Decimal('0.03')
 
 Q. There are many ways to express the same value.  The numbers :const:`200`,
 :const:`200.000`, :const:`2E2`, and :const:`.02E+4` all have the same value at
@@ -1532,11 +1567,11 @@
 canonical value?
 
 A. The :meth:`normalize` method maps all equivalent values to a single
-representative::
+representative:
 
    >>> values = map(Decimal, '200 200.000 2E2 .02E+4'.split())
    >>> [v.normalize() for v in values]
-   [Decimal("2E+2"), Decimal("2E+2"), Decimal("2E+2"), Decimal("2E+2")]
+   [Decimal('2E+2'), Decimal('2E+2'), Decimal('2E+2'), Decimal('2E+2')]
 
 Q. Some decimal values always print with exponential notation.  Is there a way
 to get a non-exponential representation?
@@ -1546,44 +1581,48 @@
 :const:`5.0E+3` as :const:`5000` keeps the value constant but cannot show the
 original's two-place significance.
 
+If an application does not care about tracking significance, it is easy to
+remove the exponent and trailing zeroes, losing significance, but keeping the
+value unchanged:
+
+    >>> def remove_exponent(d):
+    ...     return d.quantize(Decimal(1)) if d == d.to_integral() else d.normalize()
+
+    >>> remove_exponent(Decimal('5E+3'))
+    Decimal('5000')
+
 Q. Is there a way to convert a regular float to a :class:`Decimal`?
 
 A. Yes, all binary floating point numbers can be exactly expressed as a
 Decimal.  An exact conversion may take more precision than intuition would
-suggest, so trapping :const:`Inexact` will signal a need for more precision::
+suggest, so we trap :const:`Inexact` to signal a need for more precision:
+
+.. testcode::
+
+    def float_to_decimal(f):
+        "Convert a floating point number to a Decimal with no loss of information"
+        n, d = f.as_integer_ratio()
+        with localcontext() as ctx:
+            ctx.traps[Inexact] = True
+            while True:
+                try:
+                   return Decimal(n) / Decimal(d)
+                except Inexact:
+                    ctx.prec += 1
 
-   def floatToDecimal(f):
-       "Convert a floating point number to a Decimal with no loss of information"
-       # Transform (exactly) a float to a mantissa (0.5 <= abs(m) < 1.0) and an
-       # exponent.  Double the mantissa until it is an integer.  Use the integer
-       # mantissa and exponent to compute an equivalent Decimal.  If this cannot
-       # be done exactly, then retry with more precision.
-
-       mantissa, exponent = math.frexp(f)
-       while mantissa != int(mantissa):
-           mantissa *= 2.0
-           exponent -= 1
-       mantissa = int(mantissa)
-
-       oldcontext = getcontext()
-       setcontext(Context(traps=[Inexact]))
-       try:
-           while True:
-               try:
-                  return mantissa * Decimal(2) ** exponent
-               except Inexact:
-                   getcontext().prec += 1
-       finally:
-           setcontext(oldcontext)
+.. doctest::
 
-Q. Why isn't the :func:`floatToDecimal` routine included in the module?
+    >>> float_to_decimal(math.pi)
+    Decimal('3.141592653589793115997963468544185161590576171875')
+
+Q. Why isn't the :func:`float_to_decimal` routine included in the module?
 
 A. There is some question about whether it is advisable to mix binary and
 decimal floating point.  Also, its use requires some care to avoid the
-representation issues associated with binary floating point::
+representation issues associated with binary floating point:
 
-   >>> floatToDecimal(1.1)
-   Decimal("1.100000000000000088817841970012523233890533447265625")
+   >>> float_to_decimal(1.1)
+   Decimal('1.100000000000000088817841970012523233890533447265625')
 
 Q. Within a complex calculation, how can I make sure that I haven't gotten a
 spurious result because of insufficient precision or rounding anomalies.
@@ -1600,24 +1639,28 @@
 A. Yes.  The principle is that all values are considered to be exact and so is
 the arithmetic on those values.  Only the results are rounded.  The advantage
 for inputs is that "what you type is what you get".  A disadvantage is that the
-results can look odd if you forget that the inputs haven't been rounded::
+results can look odd if you forget that the inputs haven't been rounded:
+
+.. doctest:: newcontext
 
    >>> getcontext().prec = 3
-   >>> Decimal('3.104') + D('2.104')
-   Decimal("5.21")
-   >>> Decimal('3.104') + D('0.000') + D('2.104')
-   Decimal("5.20")
+   >>> Decimal('3.104') + Decimal('2.104')
+   Decimal('5.21')
+   >>> Decimal('3.104') + Decimal('0.000') + Decimal('2.104')
+   Decimal('5.20')
 
 The solution is either to increase precision or to force rounding of inputs
-using the unary plus operation::
+using the unary plus operation:
+
+.. doctest:: newcontext
 
    >>> getcontext().prec = 3
    >>> +Decimal('1.23456789')      # unary plus triggers rounding
-   Decimal("1.23")
+   Decimal('1.23')
 
 Alternatively, inputs can be rounded upon creation using the
-:meth:`Context.create_decimal` method::
+:meth:`Context.create_decimal` method:
 
    >>> Context(prec=5, rounding=ROUND_DOWN).create_decimal('1.2345678')
-   Decimal("1.2345")
+   Decimal('1.2345')
 

Modified: python/branches/py3k-importlib/Doc/library/difflib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/difflib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/difflib.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`difflib` --- Helpers for computing deltas
 ===============================================
 
@@ -6,14 +5,22 @@
    :synopsis: Helpers for computing differences between objects.
 .. moduleauthor:: Tim Peters <tim_one at users.sourceforge.net>
 .. sectionauthor:: Tim Peters <tim_one at users.sourceforge.net>
+.. Markup by Fred L. Drake, Jr. <fdrake at acm.org>
+
+.. testsetup::
 
+   import sys
+   from difflib import *
 
-.. % LaTeXification by Fred L. Drake, Jr. <fdrake at acm.org>.
+This module provides classes and functions for comparing sequences. It
+can be used for example, for comparing files, and can produce difference
+information in various formats, including HTML and context and unified
+diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
 
 .. class:: SequenceMatcher
 
    This is a flexible class for comparing pairs of sequences of any type, so long
-   as the sequence elements are hashable.  The basic algorithm predates, and is a
+   as the sequence elements are :term:`hashable`.  The basic algorithm predates, and is a
    little fancier than, an algorithm published in the late 1980's by Ratcliff and
    Obershelp under the hyperbolic name "gestalt pattern matching."  The idea is to
    find the longest contiguous matching subsequence that contains no "junk"
@@ -117,8 +124,8 @@
 
 .. function:: context_diff(a, b[, fromfile][, tofile][, fromfiledate][, tofiledate][, n][, lineterm])
 
-   Compare *a* and *b* (lists of strings); return a delta (a generator generating
-   the delta lines) in context diff format.
+   Compare *a* and *b* (lists of strings); return a delta (a :term:`generator`
+   generating the delta lines) in context diff format.
 
    Context diffs are a compact way of showing just the lines that have changed plus
    a few lines of context.  The changes are shown in a before/after style.  The
@@ -139,7 +146,25 @@
    expressed in the format returned by :func:`time.ctime`.  If not specified, the
    strings default to blanks.
 
-   :file:`Tools/scripts/diff.py` is a command-line front-end for this function.
+      >>> s1 = ['bacon\n', 'eggs\n', 'ham\n', 'guido\n']
+      >>> s2 = ['python\n', 'eggy\n', 'hamster\n', 'guido\n']
+      >>> for line in context_diff(s1, s2, fromfile='before.py', tofile='after.py'):
+      ...     sys.stdout.write(line)  # doctest: +NORMALIZE_WHITESPACE
+      *** before.py
+      --- after.py
+      ***************
+      *** 1,4 ****
+      ! bacon
+      ! eggs
+      ! ham
+        guido
+      --- 1,4 ----
+      ! python
+      ! eggy
+      ! hamster
+        guido
+
+   See :ref:`difflib-interface` for a more detailed example.
 
 
 .. function:: get_close_matches(word, possibilities[, n][, cutoff])
@@ -155,7 +180,7 @@
    Possibilities that don't score at least that similar to *word* are ignored.
 
    The best (no more than *n*) matches among the possibilities are returned in a
-   list, sorted by similarity score, most similar first. ::
+   list, sorted by similarity score, most similar first.
 
       >>> get_close_matches('appel', ['ape', 'apple', 'peach', 'puppy'])
       ['apple', 'ape']
@@ -170,8 +195,8 @@
 
 .. function:: ndiff(a, b[, linejunk][, charjunk])
 
-   Compare *a* and *b* (lists of strings); return a :class:`Differ`\ -style delta
-   (a generator generating the delta lines).
+   Compare *a* and *b* (lists of strings); return a :class:`Differ`\ -style
+   delta (a :term:`generator` generating the delta lines).
 
    Optional keyword parameters *linejunk* and *charjunk* are for filter functions
    (or ``None``):
@@ -190,7 +215,7 @@
    function :func:`IS_CHARACTER_JUNK`, which filters out whitespace characters (a
    blank or tab; note: bad idea to include newline in this!).
 
-   :file:`Tools/scripts/ndiff.py` is a command-line front-end to this function. ::
+   :file:`Tools/scripts/ndiff.py` is a command-line front-end to this function.
 
       >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1),
       ...              'ore\ntree\nemu\n'.splitlines(1))
@@ -214,7 +239,7 @@
    lines originating from file 1 or 2 (parameter *which*), stripping off line
    prefixes.
 
-   Example::
+   Example:
 
       >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1),
       ...              'ore\ntree\nemu\n'.splitlines(1))
@@ -231,8 +256,8 @@
 
 .. function:: unified_diff(a, b[, fromfile][, tofile][, fromfiledate][, tofiledate][, n][, lineterm])
 
-   Compare *a* and *b* (lists of strings); return a delta (a generator generating
-   the delta lines) in unified diff format.
+   Compare *a* and *b* (lists of strings); return a delta (a :term:`generator`
+   generating the delta lines) in unified diff format.
 
    Unified diffs are a compact way of showing just the lines that have changed plus
    a few lines of context.  The changes are shown in a inline style (instead of
@@ -254,7 +279,23 @@
    expressed in the format returned by :func:`time.ctime`.  If not specified, the
    strings default to blanks.
 
-   :file:`Tools/scripts/diff.py` is a command-line front-end for this function.
+
+      >>> s1 = ['bacon\n', 'eggs\n', 'ham\n', 'guido\n']
+      >>> s2 = ['python\n', 'eggy\n', 'hamster\n', 'guido\n']
+      >>> for line in unified_diff(s1, s2, fromfile='before.py', tofile='after.py'):
+      ...     sys.stdout.write(line)   # doctest: +NORMALIZE_WHITESPACE
+      --- before.py
+      +++ after.py
+      @@ -1,4 +1,4 @@
+      -bacon
+      -eggs
+      -ham
+      +python
+      +eggy
+      +hamster
+       guido
+
+   See :ref:`difflib-interface` for a more detailed example.
 
 
 .. function:: IS_LINE_JUNK(line)
@@ -300,7 +341,7 @@
    on blanks or hard tabs.
 
    The optional arguments *a* and *b* are sequences to be compared; both default to
-   empty strings.  The elements of both sequences must be hashable.
+   empty strings.  The elements of both sequences must be :term:`hashable`.
 
 :class:`SequenceMatcher` objects have the following methods:
 
@@ -331,17 +372,17 @@
 
    Find longest matching block in ``a[alo:ahi]`` and ``b[blo:bhi]``.
 
-   If *isjunk* was omitted or ``None``, :meth:`get_longest_match` returns ``(i, j,
+   If *isjunk* was omitted or ``None``, :meth:`find_longest_match` returns ``(i, j,
    k)`` such that ``a[i:i+k]`` is equal to ``b[j:j+k]``, where ``alo <= i <= i+k <=
    ahi`` and ``blo <= j <= j+k <= bhi``. For all ``(i', j', k')`` meeting those
    conditions, the additional conditions ``k >= k'``, ``i <= i'``, and if ``i ==
    i'``, ``j <= j'`` are also met. In other words, of all maximal matching blocks,
    return one that starts earliest in *a*, and of all those maximal matching blocks
-   that start earliest in *a*, return the one that starts earliest in *b*. ::
+   that start earliest in *a*, return the one that starts earliest in *b*.
 
       >>> s = SequenceMatcher(None, " abcd", "abcd abcd")
       >>> s.find_longest_match(0, 5, 0, 9)
-      (0, 4, 5)
+      Match(a=0, b=4, size=5)
 
    If *isjunk* was provided, first the longest matching block is determined as
    above, but with the additional restriction that no junk element appears in the
@@ -352,14 +393,17 @@
    Here's the same example as before, but considering blanks to be junk. That
    prevents ``' abcd'`` from matching the ``' abcd'`` at the tail end of the second
    sequence directly.  Instead only the ``'abcd'`` can match, and matches the
-   leftmost ``'abcd'`` in the second sequence::
+   leftmost ``'abcd'`` in the second sequence:
 
       >>> s = SequenceMatcher(lambda x: x==" ", " abcd", "abcd abcd")
       >>> s.find_longest_match(0, 5, 0, 9)
-      (1, 0, 4)
+      Match(a=1, b=0, size=4)
 
    If no blocks match, this returns ``(alo, blo, 0)``.
 
+   .. versionchanged:: 2.6
+      This method returns a :term:`named tuple` ``Match(a, b, size)``.
+
 
 .. method:: SequenceMatcher.get_matching_blocks()
 
@@ -373,11 +417,13 @@
    then ``i+n != i'`` or ``j+n != j'``; in other words, adjacent triples always
    describe non-adjacent equal blocks.
 
-   ::
+   .. XXX Explain why a dummy is used!
+
+   .. doctest::
 
       >>> s = SequenceMatcher(None, "abxcd", "abcd")
       >>> s.get_matching_blocks()
-      [(0, 0, 2), (3, 2, 2), (5, 4, 0)]
+      [Match(a=0, b=0, size=2), Match(a=3, b=2, size=2), Match(a=5, b=4, size=0)]
 
 
 .. method:: SequenceMatcher.get_opcodes()
@@ -406,7 +452,7 @@
    |               | are equal).                                 |
    +---------------+---------------------------------------------+
 
-   For example::
+   For example:
 
       >>> a = "qabxcd"
       >>> b = "abycdf"
@@ -423,7 +469,7 @@
 
 .. method:: SequenceMatcher.get_grouped_opcodes([n])
 
-   Return a generator of groups with up to *n* lines of context.
+   Return a :term:`generator` of groups with up to *n* lines of context.
 
    Starting with the groups returned by :meth:`get_opcodes`, this method splits out
    smaller change clusters and eliminates intervening ranges which have no changes.
@@ -462,7 +508,7 @@
 The three methods that return the ratio of matching to total characters can give
 different results due to differing levels of approximation, although
 :meth:`quick_ratio` and :meth:`real_quick_ratio` are always at least as large as
-:meth:`ratio`::
+:meth:`ratio`:
 
    >>> s = SequenceMatcher(None, "abcd", "bcde")
    >>> s.ratio()
@@ -478,7 +524,7 @@
 SequenceMatcher Examples
 ------------------------
 
-This example compares two strings, considering blanks to be "junk:" ::
+This example compares two strings, considering blanks to be "junk:"
 
    >>> s = SequenceMatcher(lambda x: x == " ",
    ...                     "private Thread currentThread;",
@@ -486,19 +532,18 @@
 
 :meth:`ratio` returns a float in [0, 1], measuring the similarity of the
 sequences.  As a rule of thumb, a :meth:`ratio` value over 0.6 means the
-sequences are close matches::
+sequences are close matches:
 
    >>> print(round(s.ratio(), 3))
    0.866
 
 If you're only interested in where the sequences match,
-:meth:`get_matching_blocks` is handy::
+:meth:`get_matching_blocks` is handy:
 
    >>> for block in s.get_matching_blocks():
    ...     print("a[%d] and b[%d] match for %d elements" % block)
    a[0] and b[0] match for 8 elements
-   a[8] and b[17] match for 6 elements
-   a[14] and b[23] match for 15 elements
+   a[8] and b[17] match for 21 elements
    a[29] and b[38] match for 0 elements
 
 Note that the last tuple returned by :meth:`get_matching_blocks` is always a
@@ -506,14 +551,13 @@
 tuple element (number of elements matched) is ``0``.
 
 If you want to know how to change the first sequence into the second, use
-:meth:`get_opcodes`::
+:meth:`get_opcodes`:
 
    >>> for opcode in s.get_opcodes():
    ...     print("%6s a[%d:%d] b[%d:%d]" % opcode)
     equal a[0:8] b[0:8]
    insert a[8:8] b[8:17]
-    equal a[8:14] b[17:23]
-    equal a[14:29] b[23:38]
+    equal a[8:29] b[17:38]
 
 See also the function :func:`get_close_matches` in this module, which shows how
 simple code building on :class:`SequenceMatcher` can be used to do useful work.
@@ -566,7 +610,7 @@
 
 This example compares two texts. First we set up the texts, sequences of
 individual single-line strings ending with newlines (such sequences can also be
-obtained from the :meth:`readlines` method of file-like objects)::
+obtained from the :meth:`readlines` method of file-like objects):
 
    >>> text1 = '''  1. Beautiful is better than ugly.
    ...   2. Explicit is better than implicit.
@@ -583,7 +627,7 @@
    ...   5. Flat is better than nested.
    ... '''.splitlines(1)
 
-Next we instantiate a Differ object::
+Next we instantiate a Differ object:
 
    >>> d = Differ()
 
@@ -591,11 +635,11 @@
 filter out line and character "junk."  See the :meth:`Differ` constructor for
 details.
 
-Finally, we compare the two::
+Finally, we compare the two:
 
    >>> result = list(d.compare(text1, text2))
 
-``result`` is a list of strings, so let's pretty-print it::
+``result`` is a list of strings, so let's pretty-print it:
 
    >>> from pprint import pprint
    >>> pprint(result)
@@ -603,14 +647,14 @@
     '-   2. Explicit is better than implicit.\n',
     '-   3. Simple is better than complex.\n',
     '+   3.   Simple is better than complex.\n',
-    '?     ++                                \n',
+    '?     ++\n',
     '-   4. Complex is better than complicated.\n',
-    '?            ^                     ---- ^  \n',
+    '?            ^                     ---- ^\n',
     '+   4. Complicated is better than complex.\n',
-    '?           ++++ ^                      ^  \n',
+    '?           ++++ ^                      ^\n',
     '+   5. Flat is better than nested.\n']
 
-As a single multi-line string it looks like this::
+As a single multi-line string it looks like this:
 
    >>> import sys
    >>> sys.stdout.writelines(result)
@@ -625,3 +669,75 @@
    ?           ++++ ^                      ^
    +   5. Flat is better than nested.
 
+
+.. _difflib-interface:
+
+A command-line interface to difflib
+-----------------------------------
+
+This example shows how to use difflib to create a ``diff``-like utility.
+It is also contained in the Python source distribution, as
+:file:`Tools/scripts/diff.py`.
+
+.. testcode::
+
+   """ Command line interface to difflib.py providing diffs in four formats:
+
+   * ndiff:    lists every line and highlights interline changes.
+   * context:  highlights clusters of changes in a before/after format.
+   * unified:  highlights clusters of changes in an inline format.
+   * html:     generates side by side comparison with change highlights.
+
+   """
+
+   import sys, os, time, difflib, optparse
+
+   def main():
+        # Configure the option parser
+       usage = "usage: %prog [options] fromfile tofile"
+       parser = optparse.OptionParser(usage)
+       parser.add_option("-c", action="store_true", default=False,
+                         help='Produce a context format diff (default)')
+       parser.add_option("-u", action="store_true", default=False,
+                         help='Produce a unified format diff')
+       hlp = 'Produce HTML side by side diff (can use -c and -l in conjunction)'
+       parser.add_option("-m", action="store_true", default=False, help=hlp)
+       parser.add_option("-n", action="store_true", default=False,
+                         help='Produce a ndiff format diff')
+       parser.add_option("-l", "--lines", type="int", default=3,
+                         help='Set number of context lines (default 3)')
+       (options, args) = parser.parse_args()
+
+       if len(args) == 0:
+           parser.print_help()
+           sys.exit(1)
+       if len(args) != 2:
+           parser.error("need to specify both a fromfile and tofile")
+
+       n = options.lines
+       fromfile, tofile = args # as specified in the usage string
+
+       # we're passing these as arguments to the diff function
+       fromdate = time.ctime(os.stat(fromfile).st_mtime)
+       todate = time.ctime(os.stat(tofile).st_mtime)
+       fromlines = open(fromfile, 'U').readlines()
+       tolines = open(tofile, 'U').readlines()
+
+       if options.u:
+           diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile,
+                                       fromdate, todate, n=n)
+       elif options.n:
+           diff = difflib.ndiff(fromlines, tolines)
+       elif options.m:
+           diff = difflib.HtmlDiff().make_file(fromlines, tolines, fromfile,
+                                               tofile, context=options.c,
+                                               numlines=n)
+       else:
+           diff = difflib.context_diff(fromlines, tolines, fromfile, tofile,
+                                       fromdate, todate, n=n)
+
+       # we're using writelines because diff is a generator
+       sys.stdout.writelines(diff)
+
+   if __name__ == '__main__':
+       main()

Modified: python/branches/py3k-importlib/Doc/library/dis.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/dis.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/dis.rst	Thu Mar 27 00:48:05 2008
@@ -1,14 +1,14 @@
 
-:mod:`dis` --- Disassembler for Python byte code
-================================================
+:mod:`dis` --- Disassembler for Python bytecode
+===============================================
 
 .. module:: dis
-   :synopsis: Disassembler for Python byte code.
+   :synopsis: Disassembler for Python bytecode.
 
 
-The :mod:`dis` module supports the analysis of Python byte code by disassembling
+The :mod:`dis` module supports the analysis of Python :term:`bytecode` by disassembling
 it.  Since there is no Python assembler, this module defines the Python assembly
-language.  The Python byte code which this module takes as an input is defined
+language.  The Python bytecode which this module takes as an input is defined
 in the file  :file:`Include/opcode.h` and used by the compiler and the
 interpreter.
 
@@ -35,7 +35,7 @@
    Disassemble the *bytesource* object. *bytesource* can denote either a module, a
    class, a method, a function, or a code object.   For a module, it disassembles
    all functions.  For a class, it disassembles all methods.  For a single code
-   sequence, it prints one line per byte code instruction.  If no object is
+   sequence, it prints one line per bytecode instruction.  If no object is
    provided, it disassembles the last traceback.
 
 
@@ -70,12 +70,12 @@
 
 .. data:: opname
 
-   Sequence of operation names, indexable using the byte code.
+   Sequence of operation names, indexable using the bytecode.
 
 
 .. data:: opmap
 
-   Dictionary mapping byte codes to operation names.
+   Dictionary mapping bytecodes to operation names.
 
 
 .. data:: cmp_op
@@ -85,45 +85,45 @@
 
 .. data:: hasconst
 
-   Sequence of byte codes that have a constant parameter.
+   Sequence of bytecodes that have a constant parameter.
 
 
 .. data:: hasfree
 
-   Sequence of byte codes that access a free variable.
+   Sequence of bytecodes that access a free variable.
 
 
 .. data:: hasname
 
-   Sequence of byte codes that access an attribute by name.
+   Sequence of bytecodes that access an attribute by name.
 
 
 .. data:: hasjrel
 
-   Sequence of byte codes that have a relative jump target.
+   Sequence of bytecodes that have a relative jump target.
 
 
 .. data:: hasjabs
 
-   Sequence of byte codes that have an absolute jump target.
+   Sequence of bytecodes that have an absolute jump target.
 
 
 .. data:: haslocal
 
-   Sequence of byte codes that access a local variable.
+   Sequence of bytecodes that access a local variable.
 
 
 .. data:: hascompare
 
-   Sequence of byte codes of Boolean operations.
+   Sequence of bytecodes of Boolean operations.
 
 
 .. _bytecodes:
 
-Python Byte Code Instructions
------------------------------
+Python Bytecode Instructions
+----------------------------
 
-The Python compiler currently generates the following byte code instructions.
+The Python compiler currently generates the following bytecode instructions.
 
 
 .. opcode:: STOP_CODE ()
@@ -381,7 +381,7 @@
 
 .. opcode:: YIELD_VALUE ()
 
-   Pops ``TOS`` and yields it from a generator.
+   Pops ``TOS`` and yields it from a :term:`generator`.
 
 
 .. opcode:: IMPORT_STAR ()
@@ -412,21 +412,26 @@
 
 .. opcode:: WITH_CLEANUP ()
 
-   Cleans up the stack when a :keyword:`with` statement block exits.  TOS is the
-   context manager's :meth:`__exit__` bound method.  Below that are 1--3 values
-   indicating how/why the finally clause was entered:
-
-   * SECOND = None
-   * (SECOND, THIRD) = (WHY_{RETURN,CONTINUE}), retval
-   * SECOND = WHY_\*; no retval below it
-   * (SECOND, THIRD, FOURTH) = exc_info()
-
-   In the last case, ``TOS(SECOND, THIRD, FOURTH)`` is called, otherwise
-   ``TOS(None, None, None)``.
-
-   In addition, if the stack represents an exception, *and* the function call
-   returns a 'true' value, this information is "zapped", to prevent ``END_FINALLY``
-   from re-raising the exception.  (But non-local gotos should still be resumed.)
+   Cleans up the stack when a :keyword:`with` statement block exits.  On top of
+   the stack are 1--3 values indicating how/why the finally clause was entered:
+
+   * TOP = ``None``
+   * (TOP, SECOND) = (``WHY_{RETURN,CONTINUE}``), retval
+   * TOP = ``WHY_*``; no retval below it
+   * (TOP, SECOND, THIRD) = exc_info()
+
+   Under them is EXIT, the context manager's :meth:`__exit__` bound method.
+
+   In the last case, ``EXIT(TOP, SECOND, THIRD)`` is called, otherwise
+   ``EXIT(None, None, None)``.
+
+   EXIT is removed from the stack, leaving the values above it in the same
+   order. In addition, if the stack represents an exception, *and* the function
+   call returns a 'true' value, this information is "zapped", to prevent
+   ``END_FINALLY`` from re-raising the exception.  (But non-local gotos should
+   still be resumed.)
+
+   .. XXX explain the WHY stuff!
 
 
 All of the following opcodes expect arguments.  An argument is two bytes, with
@@ -435,7 +440,7 @@
 .. opcode:: STORE_NAME (namei)
 
    Implements ``name = TOS``. *namei* is the index of *name* in the attribute
-   :attr:`co_names` of the code object. The compiler tries to use ``STORE_LOCAL``
+   :attr:`co_names` of the code object. The compiler tries to use ``STORE_FAST``
    or ``STORE_GLOBAL`` if possible.
 
 
@@ -450,13 +455,6 @@
    Unpacks TOS into *count* individual values, which are put onto the stack
    right-to-left.
 
-.. % \begin{opcodedesc}{UNPACK_LIST}{count}
-.. % This opcode is obsolete.
-.. % \end{opcodedesc}
-.. % \begin{opcodedesc}{UNPACK_ARG}{count}
-.. % This opcode is obsolete.
-.. % \end{opcodedesc}
-
 
 .. opcode:: DUP_TOPX (count)
 
@@ -484,10 +482,6 @@
 
    Works as ``DELETE_NAME``, but deletes a global name.
 
-.. % \begin{opcodedesc}{UNPACK_VARARG}{argc}
-.. % This opcode is obsolete.
-.. % \end{opcodedesc}
-
 
 .. opcode:: LOAD_CONST (consti)
 
@@ -515,10 +509,10 @@
    Works as ``BUILD_TUPLE``, but creates a set.
 
 
-.. opcode:: BUILD_MAP (zero)
+.. opcode:: BUILD_MAP (count)
 
-   Pushes a new empty dictionary object onto the stack.  The argument is ignored
-   and set to zero by the compiler.
+   Pushes a new dictionary object onto the stack.  The dictionary is pre-sized
+   to hold *count* entries.
 
 
 .. opcode:: LOAD_ATTR (namei)
@@ -548,49 +542,38 @@
 
 .. opcode:: JUMP_FORWARD (delta)
 
-   Increments byte code counter by *delta*.
+   Increments bytecode counter by *delta*.
 
 
 .. opcode:: JUMP_IF_TRUE (delta)
 
-   If TOS is true, increment the byte code counter by *delta*.  TOS is left on the
+   If TOS is true, increment the bytecode counter by *delta*.  TOS is left on the
    stack.
 
 
 .. opcode:: JUMP_IF_FALSE (delta)
 
-   If TOS is false, increment the byte code counter by *delta*.  TOS is not
+   If TOS is false, increment the bytecode counter by *delta*.  TOS is not
    changed.
 
 
 .. opcode:: JUMP_ABSOLUTE (target)
 
-   Set byte code counter to *target*.
+   Set bytecode counter to *target*.
 
 
 .. opcode:: FOR_ITER (delta)
 
-   ``TOS`` is an iterator.  Call its :meth:`__next__` method.  If this yields a new
-   value, push it on the stack (leaving the iterator below it).  If the iterator
-   indicates it is exhausted ``TOS`` is popped, and the byte code counter is
-   incremented by *delta*.
-
-.. % \begin{opcodedesc}{FOR_LOOP}{delta}
-.. % This opcode is obsolete.
-.. % \end{opcodedesc}
-.. % \begin{opcodedesc}{LOAD_LOCAL}{namei}
-.. % This opcode is obsolete.
-.. % \end{opcodedesc}
+   ``TOS`` is an :term:`iterator`.  Call its :meth:`__next__` method.  If this
+   yields a new value, push it on the stack (leaving the iterator below it).  If
+   the iterator indicates it is exhausted ``TOS`` is popped, and the byte code
+   counter is incremented by *delta*.
 
 
 .. opcode:: LOAD_GLOBAL (namei)
 
    Loads the global named ``co_names[namei]`` onto the stack.
 
-.. % \begin{opcodedesc}{SET_FUNC_ARGS}{argc}
-.. % This opcode is obsolete.
-.. % \end{opcodedesc}
-
 
 .. opcode:: SETUP_LOOP (delta)
 
@@ -609,6 +592,10 @@
    Pushes a try block from a try-except clause onto the block stack. *delta* points
    to the finally block.
 
+.. opcode:: STORE_MAP ()
+
+   Store a key and value pair in a dictionary.  Pops the key and value while leaving
+   the dictionary on the stack.
 
 .. opcode:: LOAD_FAST (var_num)
 
@@ -688,7 +675,7 @@
 
    Pushes a slice object on the stack.  *argc* must be 2 or 3.  If it is 2,
    ``slice(TOS1, TOS)`` is pushed; if it is 3, ``slice(TOS2, TOS1, TOS)`` is
-   pushed. See the ``slice()`` built-in function for more information.
+   pushed. See the :func:`slice` built-in function for more information.
 
 
 .. opcode:: EXTENDED_ARG (ext)

Modified: python/branches/py3k-importlib/Doc/library/dl.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/dl.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/dl.rst	Thu Mar 27 00:48:05 2008
@@ -7,9 +7,6 @@
    :synopsis: Call C functions in shared objects.
 .. sectionauthor:: Moshe Zadka <moshez at zadka.site.co.il>
 
-
-.. % ?????????? Anyone????????????
-
 The :mod:`dl` module defines an interface to the :cfunc:`dlopen` function, which
 is the most common interface on Unix platforms for handling dynamically linked
 libraries. It allows the program to call arbitrary functions in such a library.

Modified: python/branches/py3k-importlib/Doc/library/doctest.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/doctest.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/doctest.rst	Thu Mar 27 00:48:05 2008
@@ -38,17 +38,10 @@
    def factorial(n):
        """Return the factorial of n, an exact integer >= 0.
 
-       If the result is small enough to fit in an int, return an int.
-       Else return a long.
-
        >>> [factorial(n) for n in range(6)]
        [1, 1, 2, 6, 24, 120]
-       >>> [factorial(long(n)) for n in range(6)]
-       [1, 1, 2, 6, 24, 120]
        >>> factorial(30)
-       265252859812191058636308480000000L
-       >>> factorial(30L)
-       265252859812191058636308480000000L
+       265252859812191058636308480000000
        >>> factorial(-1)
        Traceback (most recent call last):
            ...
@@ -60,7 +53,7 @@
            ...
        ValueError: n must be exact integer
        >>> factorial(30.0)
-       265252859812191058636308480000000L
+       265252859812191058636308480000000
 
        It must also not be ridiculously large:
        >>> factorial(1e100)
@@ -109,11 +102,6 @@
    Expecting:
        [1, 1, 2, 6, 24, 120]
    ok
-   Trying:
-       [factorial(long(n)) for n in range(6)]
-   Expecting:
-       [1, 1, 2, 6, 24, 120]
-   ok
 
 And so on, eventually ending with::
 
@@ -703,12 +691,7 @@
 surprise you a few times, as you learn exactly what Python does and doesn't
 guarantee about output.  For example, when printing a dict, Python doesn't
 guarantee that the key-value pairs will be printed in any particular order, so a
-test like
-
-.. % Hey! What happened to Monty Python examples?
-.. % Tim: ask Guido -- it's his example!
-
-::
+test like ::
 
    >>> foo()
    {"Hermione": "hippogryph", "Harry": "broomstick"}
@@ -1082,7 +1065,8 @@
 The advanced API revolves around two container classes, which are used to store
 the interactive examples extracted from doctest cases:
 
-* :class:`Example`: A single python statement, paired with its expected output.
+* :class:`Example`: A single python :term:`statement`, paired with its expected
+  output.
 
 * :class:`DocTest`: A collection of :class:`Example`\ s, typically extracted
   from a single docstring or text file.
@@ -1452,11 +1436,14 @@
 .. method:: DocTestRunner.summarize([verbose])
 
    Print a summary of all the test cases that have been run by this DocTestRunner,
-   and return a tuple ``(failure_count, test_count)``.
+   and return a :term:`named tuple` ``TestResults(failed, attempted)``.
 
    The optional *verbose* argument controls how detailed the summary is.  If the
    verbosity is not specified, then the :class:`DocTestRunner`'s verbosity is used.
 
+   .. versionchanged:: 2.6
+      Use a named tuple.
+
 
 .. _doctest-outputchecker:
 

Modified: python/branches/py3k-importlib/Doc/library/easydialogs.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/easydialogs.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/easydialogs.rst	Thu Mar 27 00:48:05 2008
@@ -107,7 +107,7 @@
    *actionButtonLabel* is a string to show instead of "Open" in the OK button,
    *cancelButtonLabel* is a string to show instead of "Cancel" in the cancel
    button, *wanted* is the type of value wanted as a return: :class:`str`,
-   :class:`unicode`, :class:`FSSpec`, :class:`FSRef` and subtypes thereof are
+   :class:`FSSpec`, :class:`FSRef` and subtypes thereof are
    acceptable.
 
    .. index:: single: Navigation Services
@@ -160,14 +160,14 @@
 
 .. attribute:: ProgressBar.curval
 
-   The current value (of type integer or long integer) of the progress bar.  The
+   The current value (of type integer) of the progress bar.  The
    normal access methods coerce :attr:`curval` between ``0`` and :attr:`maxval`.
    This attribute should not be altered directly.
 
 
 .. attribute:: ProgressBar.maxval
 
-   The maximum value (of type integer or long integer) of the progress bar; the
+   The maximum value (of type integer) of the progress bar; the
    progress bar (thermometer style) is full when :attr:`curval` equals
    :attr:`maxval`.  If :attr:`maxval` is ``0``, the bar will be indeterminate
    (barber-pole).  This attribute should not be altered directly.

Modified: python/branches/py3k-importlib/Doc/library/email-examples.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/email-examples.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/email-examples.rst	Thu Mar 27 00:48:05 2008
@@ -16,18 +16,23 @@
 
 
 Here's an example of how to send the entire contents of a directory as an email
-message:  [1]_
+message: [1]_
 
 .. literalinclude:: ../includes/email-dir.py
 
 
-And finally, here's an example of how to unpack a MIME message like the one
+Here's an example of how to unpack a MIME message like the one
 above, into a directory of files:
 
 .. literalinclude:: ../includes/email-unpack.py
 
+Here's an example of how to create an HTML message with an alternative plain
+text version: [2]_
+
+.. literalinclude:: ../includes/email-alternative.py
+
 
 .. rubric:: Footnotes
 
 .. [1] Thanks to Matthew Dixon Cowles for the original inspiration and examples.
-
+.. [2] Contributed by Martin Matejek.

Modified: python/branches/py3k-importlib/Doc/library/email.charset.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/email.charset.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/email.charset.rst	Thu Mar 27 00:48:05 2008
@@ -242,6 +242,6 @@
    Add a codec that map characters in the given character set to and from Unicode.
 
    *charset* is the canonical name of a character set. *codecname* is the name of a
-   Python codec, as appropriate for the second argument to the :func:`unicode`
-   built-in, or to the :meth:`encode` method of a Unicode string.
+   Python codec, as appropriate for the second argument to the :class:`str`'s
+   :func:`decode` method
 

Modified: python/branches/py3k-importlib/Doc/library/email.header.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/email.header.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/email.header.rst	Thu Mar 27 00:48:05 2008
@@ -53,8 +53,8 @@
 
    Optional *s* is the initial header value.  If ``None`` (the default), the
    initial header value is not set.  You can later append to the header with
-   :meth:`append` method calls.  *s* may be a byte string or a Unicode string, but
-   see the :meth:`append` documentation for semantics.
+   :meth:`append` method calls.  *s* may be an instance of :class:`bytes` or
+   :class:`str`, but see the :meth:`append` documentation for semantics.
 
    Optional *charset* serves two purposes: it has the same meaning as the *charset*
    argument to the :meth:`append` method.  It also sets the default character set
@@ -86,19 +86,19 @@
    a :class:`Charset` instance.  A value of ``None`` (the default) means that the
    *charset* given in the constructor is used.
 
-   *s* may be a byte string or a Unicode string.  If it is a byte string (i.e.
-   ``isinstance(s, str)`` is true), then *charset* is the encoding of that byte
-   string, and a :exc:`UnicodeError` will be raised if the string cannot be decoded
-   with that character set.
+   *s* may be an instance of :class:`bytes` or :class:`str`.  If it is an instance
+   of :class:`bytes`, then *charset* is the encoding of that byte string, and a 
+   :exc:`UnicodeError` will be raised if the string cannot be decoded with that
+   character set.
 
-   If *s* is a Unicode string, then *charset* is a hint specifying the character
-   set of the characters in the string.  In this case, when producing an
+   If *s* is an instance of :class:`str`, then *charset* is a hint specifying the
+   character set of the characters in the string.  In this case, when producing an
    :rfc:`2822`\ -compliant header using :rfc:`2047` rules, the Unicode string will
    be encoded using the following charsets in order: ``us-ascii``, the *charset*
    hint, ``utf-8``.  The first character set to not provoke a :exc:`UnicodeError`
    is used.
 
-   Optional *errors* is passed through to any :func:`unicode` or
+   Optional *errors* is passed through to any :func:`encode` or
    :func:`ustr.encode` call, and defaults to "strict".
 
 
@@ -121,7 +121,7 @@
 
 .. method:: Header.__unicode__()
 
-   A helper for the built-in :func:`unicode` function.  Returns the header as a
+   A helper for :class:`str`'s :func:`encode` method.  Returns the header as a
    Unicode string.
 
 

Modified: python/branches/py3k-importlib/Doc/library/email.message.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/email.message.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/email.message.rst	Thu Mar 27 00:48:05 2008
@@ -38,7 +38,7 @@
 
 .. method:: Message.as_string([unixfrom])
 
-   Return the entire message flatten as a string.  When optional *unixfrom* is
+   Return the entire message flattened as a string.  When optional *unixfrom* is
    ``True``, the envelope header is included in the returned string.  *unixfrom*
    defaults to ``False``.
 

Modified: python/branches/py3k-importlib/Doc/library/email.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/email.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/email.rst	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,3 @@
-.. % Copyright (C) 2001-2007 Python Software Foundation
-.. % Author: barry at python.org (Barry Warsaw)
-
-
 :mod:`email` --- An email and MIME handling package
 ===================================================
 
@@ -10,6 +6,7 @@
               including MIME documents.
 .. moduleauthor:: Barry A. Warsaw <barry at python.org>
 .. sectionauthor:: Barry A. Warsaw <barry at python.org>
+.. Copyright (C) 2001-2007 Python Software Foundation
 
 
 The :mod:`email` package is a library for managing email messages, including

Modified: python/branches/py3k-importlib/Doc/library/email.util.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/email.util.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/email.util.rst	Thu Mar 27 00:48:05 2008
@@ -130,10 +130,10 @@
    When a header parameter is encoded in :rfc:`2231` format,
    :meth:`Message.get_param` may return a 3-tuple containing the character set,
    language, and value.  :func:`collapse_rfc2231_value` turns this into a unicode
-   string.  Optional *errors* is passed to the *errors* argument of the built-in
-   :func:`unicode` function; it defaults to ``replace``.  Optional
+   string.  Optional *errors* is passed to the *errors* argument of :class:`str`'s
+   :func:`encode` method; it defaults to ``'replace'``.  Optional
    *fallback_charset* specifies the character set to use if the one in the
-   :rfc:`2231` header is not known by Python; it defaults to ``us-ascii``.
+   :rfc:`2231` header is not known by Python; it defaults to ``'us-ascii'``.
 
    For convenience, if the *value* passed to :func:`collapse_rfc2231_value` is not
    a tuple, it should be a string and it is returned unquoted.

Modified: python/branches/py3k-importlib/Doc/library/exceptions.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/exceptions.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/exceptions.rst	Thu Mar 27 00:48:05 2008
@@ -111,16 +111,15 @@
 
 .. exception:: AttributeError
 
-   Raised when an attribute reference or assignment fails.  (When an object does
-   not support attribute references or attribute assignments at all,
-   :exc:`TypeError` is raised.)
-
-   .. % xref to attribute reference?
+   Raised when an attribute reference (see :ref:`attribute-references`) or
+   assignment fails.  (When an object does not support attribute references or
+   attribute assignments at all, :exc:`TypeError` is raised.)
 
 
 .. exception:: EOFError
 
-   Raised when attempting to read beyond the end of a file. (N.B.: the
+   Raised when one of the built-in functions (:func:`input` or :func:`raw_input`)
+   hits an end-of-file condition (EOF) without reading any data. (N.B.: the
    :meth:`file.read` and :meth:`file.readline` methods return an empty string
    when they hit EOF.)
 
@@ -135,7 +134,9 @@
 
 .. exception:: GeneratorExit
 
-   Raise when a generator's :meth:`close` method is called.
+   Raise when a :term:`generator`\'s :meth:`close` method is called.  It
+   directly inherits from :exc:`BaseException` instead of :exc:`Exception` since
+   it is technically not an error.
 
 
 .. exception:: IOError
@@ -147,9 +148,6 @@
    This class is derived from :exc:`EnvironmentError`.  See the discussion above
    for more information on exception instance attributes.
 
-   .. versionchanged:: 2.6
-      Changed :exc:`socket.error` to use this as a base class.
-
 
 .. exception:: ImportError
 
@@ -163,14 +161,14 @@
    truncated to fall in the allowed range; if an index is not a plain integer,
    :exc:`TypeError` is raised.)
 
-   .. % XXXJH xref to sequences
+   .. XXX xref to sequences
 
 
 .. exception:: KeyError
 
    Raised when a mapping (dictionary) key is not found in the set of existing keys.
 
-   .. % XXXJH xref to mapping objects?
+   .. XXX xref to mapping objects?
 
 
 .. exception:: KeyboardInterrupt
@@ -209,15 +207,25 @@
 
 .. exception:: OSError
 
-   This class is derived from :exc:`EnvironmentError` and is used primarily as the
-   :mod:`os` module's ``os.error`` exception. See :exc:`EnvironmentError` above for
-   a description of the possible associated values.
+   .. index:: module: errno
+
+   This exception is derived from :exc:`EnvironmentError`.  It is raised when a
+   function returns a system-related error (not for illegal argument types or
+   other incidental errors).  The :attr:`errno` attribute is a numeric error
+   code from :cdata:`errno`, and the :attr:`strerror` attribute is the
+   corresponding string, as would be printed by the C function :cfunc:`perror`.
+   See the module :mod:`errno`, which contains names for the error codes defined
+   by the underlying operating system.
+
+   For exceptions that involve a file system path (such as :func:`chdir` or
+   :func:`unlink`), the exception instance will contain a third attribute,
+   :attr:`filename`, which is the file name passed to the function.
 
 
 .. exception:: OverflowError
 
    Raised when the result of an arithmetic operation is too large to be
-   represented.  This cannot occur for long integers (which would rather raise
+   represented.  This cannot occur for integers (which would rather raise
    :exc:`MemoryError` than give up).  Because of the lack of standardization of
    floating point exception handling in C, most floating point operations also
    aren't checked.
@@ -241,8 +249,8 @@
 
 .. exception:: StopIteration
 
-   Raised by builtin :func:`next` and an iterator's :meth:`__next__` method to
-   signal that there are no further values.
+   Raised by builtin :func:`next` and an :term:`iterator`\'s :meth:`__next__`
+   method to signal that there are no further values.
 
 
 .. exception:: SyntaxError
@@ -405,7 +413,11 @@
 
    Base class for warnings related to Unicode.
 
-The class hierarchy for built-in exceptions is:
+.. exception:: BytesWarning
+
+   Base class for warnings related to :class:`bytes` and :class:`buffer`.
 
 
+The class hierarchy for built-in exceptions is:
+
 .. literalinclude:: ../../Lib/test/exception_hierarchy.txt

Modified: python/branches/py3k-importlib/Doc/library/fcntl.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/fcntl.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/fcntl.rst	Thu Mar 27 00:48:05 2008
@@ -47,9 +47,10 @@
 .. function:: ioctl(fd, op[, arg[, mutate_flag]])
 
    This function is identical to the :func:`fcntl` function, except that the
-   operations are typically defined in the library module :mod:`termios` and the
    argument handling is even more complicated.
 
+   The op parameter is limited to values that can fit in 32-bits.
+
    The parameter *arg* can be one of an integer, absent (treated identically to the
    integer ``0``), an object supporting the read-only buffer interface (most likely
    a plain Python string) or an object supporting the read-write buffer interface.
@@ -109,7 +110,7 @@
    * :const:`LOCK_EX` -- acquire an exclusive lock
 
    When *operation* is :const:`LOCK_SH` or :const:`LOCK_EX`, it can also be
-   bit-wise OR'd with :const:`LOCK_NB` to avoid blocking on lock acquisition.
+   bitwise ORed with :const:`LOCK_NB` to avoid blocking on lock acquisition.
    If :const:`LOCK_NB` is used and the lock cannot be acquired, an
    :exc:`IOError` will be raised and the exception will have an *errno*
    attribute set to :const:`EACCES` or :const:`EAGAIN` (depending on the

Modified: python/branches/py3k-importlib/Doc/library/filecmp.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/filecmp.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/filecmp.rst	Thu Mar 27 00:48:05 2008
@@ -8,7 +8,8 @@
 
 
 The :mod:`filecmp` module defines functions to compare files and directories,
-with various optional time/correctness trade-offs.
+with various optional time/correctness trade-offs. For comparing files,
+see also the :mod:`difflib` module.
 
 The :mod:`filecmp` module defines the following functions:
 

Modified: python/branches/py3k-importlib/Doc/library/fileformats.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/fileformats.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/fileformats.rst	Thu Mar 27 00:48:05 2008
@@ -16,3 +16,4 @@
    robotparser.rst
    netrc.rst
    xdrlib.rst
+   plistlib.rst

Modified: python/branches/py3k-importlib/Doc/library/fileinput.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/fileinput.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/fileinput.rst	Thu Mar 27 00:48:05 2008
@@ -168,9 +168,3 @@
 
    Usage example: ``fi =
    fileinput.FileInput(openhook=fileinput.hook_encoded("iso-8859-1"))``
-
-   .. note::
-
-      With this hook, :class:`FileInput` might return Unicode strings depending on the
-      specified *encoding*.
-

Modified: python/branches/py3k-importlib/Doc/library/fnmatch.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/fnmatch.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/fnmatch.rst	Thu Mar 27 00:48:05 2008
@@ -70,7 +70,7 @@
 
    Return the shell-style *pattern* converted to a regular expression.
 
-   Example::
+   Example:
 
       >>> import fnmatch, re
       >>>

Modified: python/branches/py3k-importlib/Doc/library/ftplib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/ftplib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/ftplib.rst	Thu Mar 27 00:48:05 2008
@@ -176,11 +176,12 @@
 
 .. method:: FTP.retrlines(command[, callback])
 
-   Retrieve a file or directory listing in ASCII transfer mode. *command* should be
-   an appropriate ``RETR`` command (see :meth:`retrbinary`) or a ``LIST`` command
-   (usually just the string ``'LIST'``).  The *callback* function is called for
-   each line, with the trailing CRLF stripped.  The default *callback* prints the
-   line to ``sys.stdout``.
+   Retrieve a file or directory listing in ASCII transfer mode.  *command*
+   should be an appropriate ``RETR`` command (see :meth:`retrbinary`) or a
+   command such as ``LIST``, ``NLST`` or ``MLSD`` (usually just the string
+   ``'LIST'``).  The *callback* function is called for each line, with the
+   trailing CRLF stripped.  The default *callback* prints the line to
+   ``sys.stdout``.
 
 
 .. method:: FTP.set_pasv(boolean)
@@ -190,20 +191,23 @@
    it is on by default.)
 
 
-.. method:: FTP.storbinary(command, file[, blocksize])
+.. method:: FTP.storbinary(command, file[, blocksize, callback])
 
    Store a file in binary transfer mode.  *command* should be an appropriate
    ``STOR`` command: ``"STOR filename"``. *file* is an open file object which is
    read until EOF using its :meth:`read` method in blocks of size *blocksize* to
    provide the data to be stored.  The *blocksize* argument defaults to 8192.
+   *callback* is an optional single parameter callable that is called
+   on each block of data after it is sent.
 
 
-.. method:: FTP.storlines(command, file)
+.. method:: FTP.storlines(command, file[, callback])
 
    Store a file in ASCII transfer mode.  *command* should be an appropriate
    ``STOR`` command (see :meth:`storbinary`).  Lines are read until EOF from the
    open file object *file* using its :meth:`readline` method to provide the data to
-   be stored.
+   be stored.  *callback* is an optional single parameter callable
+   that is called on each line after it is sent.
 
 
 .. method:: FTP.transfercmd(cmd[, rest])

Modified: python/branches/py3k-importlib/Doc/library/functions.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/functions.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/functions.rst	Thu Mar 27 00:48:05 2008
@@ -28,7 +28,7 @@
    :func:`__import__` function.
 
    For example, the statement ``import spam`` results in the following call:
-   ``__import__('spam',`` ``globals(),`` ``locals(), [], -1)``; the statement
+   ``__import__('spam', globals(), locals(), [], -1)``; the statement
    ``from spam.ham import eggs`` results in ``__import__('spam.ham', globals(),
    locals(), ['eggs'], -1)``.  Note that even though ``locals()`` and ``['eggs']``
    are passed in as arguments, the :func:`__import__` function does not set the
@@ -41,7 +41,7 @@
    top-level package (the name up till the first dot) is returned, *not* the
    module named by *name*.  However, when a non-empty *fromlist* argument is
    given, the module named by *name* is returned.  This is done for
-   compatibility with the bytecode generated for the different kinds of import
+   compatibility with the :term:`bytecode` generated for the different kinds of import
    statement; when using ``import spam.ham.eggs``, the top-level package
    :mod:`spam` must be placed in the importing namespace, but when using ``from
    spam.ham import eggs``, the ``spam.ham`` subpackage must be used to find the
@@ -65,7 +65,7 @@
 
 .. function:: abs(x)
 
-   Return the absolute value of a number.  The argument may be a plain or long
+   Return the absolute value of a number.  The argument may be an
    integer or a floating point number.  If the argument is a complex number, its
    magnitude is returned.
 
@@ -92,14 +92,6 @@
           return False
 
 
-.. function:: basestring()
-
-   This abstract type is the superclass for :class:`str`.  It
-   cannot be called or instantiated, but it can be used to test whether an object
-   is an instance of :class:`str` (or a user-defined type inherited from
-   :class:`basestring`).
-
-
 .. function:: bin(x)
 
    Convert an integer number to a binary string. The result is a valid Python
@@ -118,18 +110,19 @@
    .. index:: pair: Boolean; type
 
 
-.. function:: bytes([arg[, encoding[, errors]]])
+.. function:: bytearray([arg[, encoding[, errors]]])
 
-   Return a new array of bytes.  The :class:`bytes` type is a mutable sequence
-   of integers in the range 0 <= x < 256.  It has most of the usual methods of
-   mutable sequences, described in :ref:`typesseq-mutable`, as well as a few
-   methods borrowed from strings, described in :ref:`bytes-methods`.
+   Return a new array of bytes.  The :class:`bytearray` type is a mutable
+   sequence of integers in the range 0 <= x < 256.  It has most of the usual
+   methods of mutable sequences, described in :ref:`typesseq-mutable`, as well
+   as most methods that the :class:`str` type has, see :ref:`bytes-methods`.
 
    The optional *arg* parameter can be used to initialize the array in a few
    different ways:
 
    * If it is a *string*, you must also give the *encoding* (and optionally,
-     *errors*) parameters; :func:`bytes` then acts like :meth:`str.encode`.
+     *errors*) parameters; :func:`bytearray` then converts the string to
+     bytes using :meth:`str.encode`.
 
    * If it is an *integer*, the array will have that size and will be
      initialized with null bytes.
@@ -137,12 +130,24 @@
    * If it is an object conforming to the *buffer* interface, a read-only buffer
      of the object will be used to initialize the bytes array.
 
-   * If it is an *iterable*, it must be an iterable of integers in the range 0
-     <= x < 256, which are used as the initial contents of the array.
+   * If it is an *iterable*, it must be an iterable of integers in the range
+     ``0 <= x < 256``, which are used as the initial contents of the array.
 
    Without an argument, an array of size 0 is created.
 
 
+.. function:: bytes([arg[, encoding[, errors]]])
+
+   Return a new "bytes" object, which is an immutable sequence of integers in
+   the range ``0 <= x < 256``.  :class:`bytes` is an immutable version of
+   :class:`bytearray` -- it has the same non-mutating methods and the same
+   indexing and slicing behavior.
+   
+   Accordingly, constructor arguments are interpreted as for :func:`buffer`.
+
+   Bytes objects can also be created with literals, see :ref:`strings`.
+
+
 .. function:: chr(i)
 
    Return the string of one character whose Unicode codepoint is the integer
@@ -164,8 +169,8 @@
           @classmethod
           def f(cls, arg1, arg2, ...): ...
 
-   The ``@classmethod`` form is a function decorator -- see the description of
-   function definitions in :ref:`function` for details.
+   The ``@classmethod`` form is a function :term:`decorator` -- see the description
+   of function definitions in :ref:`function` for details.
 
    It can be called either on the class (such as ``C.f()``) or on an instance (such
    as ``C().f()``).  The instance is ignored except for its class. If a class
@@ -214,11 +219,14 @@
    the *flags* argument is it -- the future statements in effect around the call to
    compile are ignored.
 
-   Future statements are specified by bits which can be bitwise or-ed together to
+   Future statements are specified by bits which can be bitwise ORed together to
    specify multiple statements.  The bitfield required to specify a given feature
    can be found as the :attr:`compiler_flag` attribute on the :class:`_Feature`
    instance in the :mod:`__future__` module.
 
+   This function raises :exc:`SyntaxError` if the compiled source is invalid,
+   and :exc:`TypeError` if the source contains null bytes.
+
 
 .. function:: complex([real[, imag]])
 
@@ -227,8 +235,8 @@
    interpreted as a complex number and the function must be called without a second
    parameter.  The second parameter can never be a string. Each argument may be any
    numeric type (including complex). If *imag* is omitted, it defaults to zero and
-   the function serves as a numeric conversion function like :func:`int`,
-   :func:`long` and :func:`float`.  If both arguments are omitted, returns ``0j``.
+   the function serves as a numeric conversion function like :func:`int`
+   and :func:`float`.  If both arguments are omitted, returns ``0j``.
 
    The complex type is described in :ref:`typesnumeric`.
 
@@ -280,13 +288,15 @@
      class's attributes, and recursively of the attributes of its class's base
      classes.
 
-   The resulting list is sorted alphabetically.  For example::
+   The resulting list is sorted alphabetically.  For example:
 
       >>> import struct
-      >>> dir()
+      >>> dir()   # doctest: +SKIP
       ['__builtins__', '__doc__', '__name__', 'struct']
-      >>> dir(struct)
-      ['__doc__', '__name__', 'calcsize', 'error', 'pack', 'unpack']
+      >>> dir(struct)   # doctest: +NORMALIZE_WHITESPACE
+      ['Struct', '__builtins__', '__doc__', '__file__', '__name__',
+       '__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into',
+       'unpack', 'unpack_from']
       >>> class Foo(object):
       ...     def __dir__(self):
       ...         return ["kan", "ga", "roo"]
@@ -300,15 +310,16 @@
       Because :func:`dir` is supplied primarily as a convenience for use at an
       interactive prompt, it tries to supply an interesting set of names more than it
       tries to supply a rigorously or consistently defined set of names, and its
-      detailed behavior may change across releases.
+      detailed behavior may change across releases.  For example, metaclass attributes
+      are not in the result list when the argument is a class.
 
 
 .. function:: divmod(a, b)
 
    Take two (non complex) numbers as arguments and return a pair of numbers
-   consisting of their quotient and remainder when using long division.  With mixed
-   operand types, the rules for binary arithmetic operators apply.  For plain and
-   long integers, the result is the same as ``(a // b, a % b)``. For floating point
+   consisting of their quotient and remainder when using integer division.  With mixed
+   operand types, the rules for binary arithmetic operators apply.  For integers, 
+   the result is the same as ``(a // b, a % b)``. For floating point
    numbers the result is ``(q, a % b)``, where *q* is usually ``math.floor(a / b)``
    but may be 1 less than that.  In any case ``q * b + a % b`` is very close to
    *a*, if ``a % b`` is non-zero it has the same sign as *b*, and ``0 <= abs(a % b)
@@ -317,15 +328,15 @@
 
 .. function:: enumerate(iterable)
 
-   Return an enumerate object. *iterable* must be a sequence, an iterator, or some
+   Return an enumerate object. *iterable* must be a sequence, an :term:`iterator`, or some
    other object which supports iteration.  The :meth:`__next__` method of the
    iterator returned by :func:`enumerate` returns a tuple containing a count (from
    zero) and the corresponding value obtained from iterating over *iterable*.
    :func:`enumerate` is useful for obtaining an indexed series: ``(0, seq[0])``,
-   ``(1, seq[1])``, ``(2, seq[2])``, .... For example::
+   ``(1, seq[1])``, ``(2, seq[2])``, .... For example:
 
       >>> for i, season in enumerate(['Spring', 'Summer', 'Fall', 'Winter')]:
-      >>>     print(i, season)
+      ...     print(i, season)
       0 Spring
       1 Summer
       2 Fall
@@ -340,14 +351,14 @@
 
    The *expression* argument is parsed and evaluated as a Python expression
    (technically speaking, a condition list) using the *globals* and *locals*
-   dictionaries as global and local name space.  If the *globals* dictionary is
+   dictionaries as global and local namespace.  If the *globals* dictionary is
    present and lacks '__builtins__', the current globals are copied into *globals*
    before *expression* is parsed.  This means that *expression* normally has full
-   access to the standard :mod:`__builtin__` module and restricted environments are
+   access to the standard :mod:`builtins` module and restricted environments are
    propagated.  If the *locals* dictionary is omitted it defaults to the *globals*
    dictionary.  If both dictionaries are omitted, the expression is executed in the
-   environment where :keyword:`eval` is called.  The return value is the result of
-   the evaluated expression. Syntax errors are reported as exceptions.  Example::
+   environment where :func:`eval` is called.  The return value is the result of
+   the evaluated expression. Syntax errors are reported as exceptions.  Example:
 
       >>> x = 1
       >>> eval('x+1')
@@ -385,7 +396,7 @@
 
    If the *globals* dictionary does not contain a value for the key
    ``__builtins__``, a reference to the dictionary of the built-in module
-   :mod:`__builtin__` is inserted under that key.  That way you can control what
+   :mod:`builtins` is inserted under that key.  That way you can control what
    builtins are available to the executed code by inserting your own
    ``__builtins__`` dictionary into *globals* before passing it to :func:`exec`.
 
@@ -398,20 +409,18 @@
    .. warning::
 
       The default *locals* act as described for function :func:`locals` below:
-      modifications to the default *locals* dictionary should not be attempted.  Pass
-      an explicit *locals* dictionary if you need to see effects of the code on
-      *locals* after function :func:`execfile` returns.  :func:`exec` cannot be
-      used reliably to modify a function's locals.
+      modifications to the default *locals* dictionary should not be attempted.
+      Pass an explicit *locals* dictionary if you need to see effects of the
+      code on *locals* after function :func:`exec` returns.
 
 
 .. function:: filter(function, iterable)
 
    Construct an iterator from those elements of *iterable* for which *function*
    returns true.  *iterable* may be either a sequence, a container which
-   supports iteration, or an iterator, If *iterable* is a string or a tuple, the
-   result also has that type; otherwise it is always a list.  If *function* is
-   ``None``, the identity function is assumed, that is, all elements of
-   *iterable* that are false are removed.
+   supports iteration, or an iterator.  If *function* is ``None``, the identity
+   function is assumed, that is, all elements of *iterable* that are false are
+   removed.
 
    Note that ``filter(function, iterable)`` is equivalent to the generator
    expression ``(item for item in iterable if function(item))`` if function is
@@ -423,7 +432,8 @@
 
    Convert a string or a number to floating point.  If the argument is a string, it
    must contain a possibly signed decimal or floating point number, possibly
-   embedded in whitespace. Otherwise, the argument may be a plain or long integer
+   embedded in whitespace. The argument may also be [+|-]nan or [+|-]inf.
+   Otherwise, the argument may be a plain integer
    or a floating point number, and a floating point number with the same value
    (within Python's floating point precision) is returned.  If no argument is
    given, returns ``0.0``.
@@ -435,9 +445,10 @@
          single: Infinity
 
       When passing in a string, values for NaN and Infinity may be returned, depending
-      on the underlying C library.  The specific set of strings accepted which cause
-      these values to be returned depends entirely on the C library and is known to
-      vary.
+      on the underlying C library.  Float accepts the strings nan, inf and -inf for
+      NaN and positive or negative infinity. The case and a leading + are ignored as
+      well as a leading - is ignored for NaN. Float always represents NaN and infinity
+      as nan, inf or -inf.
 
    The float type is described in :ref:`typesnumeric`.
 
@@ -508,6 +519,8 @@
    topic, and a help page is printed on the console.  If the argument is any other
    kind of object, a help page on the object is generated.
 
+   This function is added to the built-in namespace by the :mod:`site` module.
+
 
 .. function:: hex(x)
 
@@ -518,7 +531,7 @@
 
 .. function:: id(object)
 
-   Return the "identity" of an object.  This is an integer (or long integer) which
+   Return the "identity" of an object.  This is an integer which
    is guaranteed to be unique and constant for this object during its lifetime.
    Two objects with non-overlapping lifetimes may have the same :func:`id` value.
    (Implementation note: this is the address of the object.)
@@ -543,15 +556,15 @@
 .. function:: int([x[, radix]])
 
    Convert a string or number to an integer.  If the argument is a string, it
-   must contain a possibly signed number of arbitrary size,
-   possibly embedded in whitespace.  The *radix* parameter gives the base for the
-   conversion and may be any integer in the range [2, 36], or zero.  If *radix* is
-   zero, the interpretation is the same as for integer literals.  If *radix* is
-   specified and *x* is not a string, :exc:`TypeError` is raised.  Otherwise, the
-   argument may be another integer, a floating point number or any other object
-   that has an :meth:`__int__` method.  Conversion
-   of floating point numbers to integers truncates (towards zero).  If no
-   arguments are given, returns ``0``.
+   must contain a possibly signed number of arbitrary size, possibly embedded in
+   whitespace.  The *radix* parameter gives the base for the conversion (which
+   is 10 by default) and may be any integer in the range [2, 36], or zero.  If
+   *radix* is zero, the interpretation is the same as for integer literals.  If
+   *radix* is specified and *x* is not a string, :exc:`TypeError` is raised.
+   Otherwise, the argument may be another integer, a floating point number or
+   any other object that has an :meth:`__int__` method.  Conversion of floating
+   point numbers to integers truncates (towards zero).  If no arguments are
+   given, returns ``0``.
 
    The integer type is described in :ref:`typesnumeric`.
 
@@ -577,7 +590,7 @@
 
 .. function:: iter(o[, sentinel])
 
-   Return an iterator object.  The first argument is interpreted very differently
+   Return an :term:`iterator` object.  The first argument is interpreted very differently
    depending on the presence of the second argument. Without a second argument, *o*
    must be a collection object which supports the iteration protocol (the
    :meth:`__iter__` method), or it must support the sequence protocol (the
@@ -604,10 +617,7 @@
    returns ``['a', 'b', 'c']`` and ``list( (1, 2, 3) )`` returns ``[1, 2, 3]``.  If
    no argument is given, returns a new empty list, ``[]``.
 
-   :class:`list` is a mutable sequence type, as documented in
-   :ref:`typesseq`. For other containers see the built in :class:`dict`,
-   :class:`set`, and :class:`tuple` classes, and the :mod:`collections` module.
-
+   :class:`list` is a mutable sequence type, as documented in :ref:`typesseq`. 
 
 .. function:: locals()
 
@@ -618,7 +628,7 @@
       The contents of this dictionary should not be modified; changes may not affect
       the values of local variables used by the interpreter.
 
-   Free variables are returned by *locals* when it is called in a function block.
+   Free variables are returned by :func:`locals` when it is called in a function block.
    Modifications of free variables may not affect the values used by the
    interpreter.  Free variables are not returned in class blocks.
 
@@ -628,17 +638,7 @@
    Return an iterator that applies *function* to every item of *iterable*,
    yielding the results.  If additional *iterable* arguments are passed,
    *function* must take that many arguments and is applied to the items from all
-   iterables in parallel.  If one iterable is shorter than another it is assumed
-   to be extended with ``None`` items.  If *function* is ``None``, the identity
-   function is assumed; if there are multiple arguments, :func:`map` returns a
-   list consisting of tuples containing the corresponding items from all
-   iterables (a kind of transpose operation).  The *iterable* arguments may be a
-   sequence or any iterable object; the result is always a list.
-
-   Note that for only one *iterable* argument, ``map(function, iterable)`` is
-   equivalent to the generator expression ``(function(item) for item in
-   iterable)`` if *function* is not ``None``.
-
+   iterables in parallel.
 
 .. function:: max(iterable[, args...], *[, key])
 
@@ -693,31 +693,94 @@
    :meth:`__index__` method that returns an integer.
 
 
-.. function:: open(filename[, mode[, bufsize]])
+.. function:: open(filename[, mode='r'[, buffering=None[, encoding=None[, errors=None[, newline=None[, closefd=True]]]]]])
 
    Open a file, returning an object of the :class:`file` type described in
    section :ref:`bltin-file-objects`.  If the file cannot be opened,
    :exc:`IOError` is raised.  When opening a file, it's preferable to use
    :func:`open` instead of invoking the :class:`file` constructor directly.
-
-   The first two arguments are the same as for ``stdio``'s :cfunc:`fopen`:
-   *filename* is the file name to be opened, and *mode* is a string
-   indicating how the file is to be opened.
-
-   The most commonly-used values of *mode* are ``'r'`` for reading, ``'w'``
-   for writing (truncating the file if it already exists), and ``'a'`` for
-   appending (which on *some* Unix systems means that *all* writes append to
-   the end of the file regardless of the current seek position).  If *mode*
-   is omitted, it defaults to ``'r'``.  See below for more possible values
-   of *mode*.
+   
+   *filename* is either a string giving the name (and the path if the
+   file isn't in 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``.)
+
+   *mode* is an optional string that specifies the mode in which the file is
+   opened. It defaults to ``'r'`` which means open for reading in text mode.
+   Other common values are ``'w'`` for writing (truncating the file if
+   it already exists), and ``'a'`` for appending (which on *some* Unix
+   systems means that *all* writes append to the end of the file
+   regardless of the current seek position). In text mode, if *encoding*
+   is not specified the encoding used is platform dependent. (For reading
+   and writing raw bytes use binary mode and leave *encoding*
+   unspecified.) The available modes are:
+
+   * 'r' open for reading (default)
+   * 'w' open for writing, truncating the file first
+   * 'a' open for writing, appending to the end if the file exists
+   * 'b' binary mode
+   * 't' text mode (default)
+   * '+' open the file for updating (implies both reading and writing)
+   * 'U' universal newline mode (for backwards compatibility;
+     unnecessary in new code)
+
+   The most commonly-used values of *mode* are ``'r'`` for reading, ``'w'`` for
+   writing (truncating the file if it already exists), and ``'a'`` for appending
+   (which on *some* Unix systems means that *all* writes append to the end of the
+   file regardless of the current seek position).  If *mode* is omitted, it
+   defaults to ``'r'``.  The default is to use text mode, which may convert
+   ``'\n'`` characters to a platform-specific representation on writing and back
+   on reading.  Thus, when opening a binary file, you should append ``'b'`` to
+   the *mode* value to open the file in binary mode, which will improve
+   portability.  (Appending ``'b'`` is useful even on systems that don't treat
+   binary and text files differently, where it serves as documentation.)  See below
+   for more possible values of *mode*.
 
    Python distinguishes between files opened in binary and text modes, even
    when the underlying operating system doesn't.  Files opened in binary
-   mode (appending ``'b'`` to the *mode* argument to :func:``open``) return
-   contents as bytes objects without any decoding.  In text mode (the
-   default, or when ``'t'`` is appended to the *mode* argument) the contents
-   of the file are returned as strings, the bytes having been first decoded
-   using the encoding specified by :func:`sys.getfilesystemencoding`.
+   mode (appending ``'b'`` to the *mode* argument) return contents as
+   ``bytes`` objects without any decoding.  In text mode (the default,
+   or when ``'t'`` is appended to the *mode* argument) the contents of
+   the file are returned as strings, the bytes having been first decoded
+   using a platform-dependent encoding or using the specified *encoding*
+   if given.
+
+   *buffering* is an optional integer used to set the buffering policy. By
+   default full buffering is on. Pass 0 to switch buffering off (only
+   allowed in binary mode), 1 to set line buffering, and an integer > 1
+   for full buffering.
+    
+   *encoding* is an optional string that specifies the file's encoding when
+   reading or writing in text mode---this argument should not be used in
+   binary mode. The default encoding is platform dependent, but any encoding
+   supported by Python can be used. (See the :mod:`codecs` module for
+   the list of supported encodings.)
+
+   *errors* is an optional string that specifies how encoding errors are to be
+   handled---this argument should not be used in binary mode. Pass
+   ``'strict'`` to raise a :exc:`ValueError` exception if there is an encoding
+   error (the default of ``None`` has the same effect), or pass ``'ignore'``
+   to ignore errors. (Note that ignoring encoding errors can lead to
+   data loss.) See the documentation for :func:`codecs.register` for a
+   list of the permitted encoding error strings.
+
+   *newline* is an optional string that specifies the newline character(s).
+   When reading, if *newline* is ``None``, universal newlines mode is enabled.
+   Lines read in univeral newlines mode can end in ``'\n'``, ``'\r'``,
+   or ``'\r\n'``, and these are translated into ``'\n'``. If *newline*
+   is ``''``, universal newline mode is enabled, but line endings are
+   not translated. If any other string is given, lines are assumed to be
+   terminated by that string, and no translating is done. When writing,
+   if *newline* is ``None``, any ``'\n'`` characters written are
+   translated to the system default line separator, :attr:`os.linesep`.
+   If *newline* is ``''``, no translation takes place. If *newline* is
+   any of the other standard values, any ``'\n'`` characters written are
+   translated to the given string.
+
+   *closefd* is an optional Boolean which specifies whether to keep the
+   underlying file descriptor open. It must be ``True`` (the default) if
+   a filename is given.
 
    .. index::
       single: line-buffered I/O
@@ -728,40 +791,21 @@
       single: text mode
       module: sys
 
-   The optional *bufsize* argument specifies the file's desired buffer size:
-   0 means unbuffered, 1 means line buffered, any other positive value means
-   use a buffer of (approximately) that size.  A negative *bufsize* means to
-   use the system default, which is usually line buffered for tty devices
-   and fully buffered for other files.  If omitted, the system default is
-   used. [#]_
-
-   Modes ``'r+'``, ``'w+'`` and ``'a+'`` open the file for updating (note
-   that ``'w+'`` truncates the file).
-
-   When a file is opened in text mode it is also opened in universal
-   newlines mode.  Unlike earlier versions of Python it's no longer
-   necessary to add a ``'U'`` value to the *mode* argument to enable this
-   mode.  Consequently, in files opened in text mode lines may be terminated
-   with ``'\n'``, ``'\r'``, or ``'\r\n'``. All three external
-   representations are seen as ``'\n'`` by the Python program.  File objects
-   opened in text mode also have a :attr:`newlines` attribute which has a
-   value of ``None`` (if no newlines have been seen yet), ``'\n'``,
-   ``'\r'``, ``'\r\n'``, or a tuple containing all the newline types seen.
-
-   See also the :mod:`fileinput` module, the file-related functions in the
-   :mod:`os` module, and the :mod:`os.path` module.
+   See also the file handling modules, such as,
+   :mod:`fileinput`, :mod:`os`, :mod:`os.path`, :mod:`tempfile`, and
+   :mod:`shutil`.
 
 
+.. XXX works for bytes too, but should it?
 .. function:: ord(c)
 
    Given a string of length one, return an integer representing the Unicode code
-   point of the character when the argument is a unicode object, or the value of
-   the byte when the argument is an 8-bit string. For example, ``ord('a')`` returns
-   the integer ``97``, ``ord(u'\u2020')`` returns ``8224``.  This is the inverse of
-   :func:`chr` for 8-bit strings and of :func:`unichr` for unicode objects.  If a
-   unicode argument is given and Python was built with UCS2 Unicode, then the
-   character's code point must be in the range [0..65535] inclusive; otherwise the
-   string length is two, and a :exc:`TypeError` will be raised.
+   point of the character.  For example, ``ord('a')`` returns the integer ``97``
+   and ``ord('\u2020')`` returns ``8224``.  This is the inverse of :func:`chr`.
+
+   If the argument length is not one, a :exc:`TypeError` will be raised.  (If
+   Python was built with UCS2 Unicode, then the character's code point must be
+   in the range [0..65535] inclusive; otherwise the string length is two!)
 
 
 .. function:: pow(x, y[, z])
@@ -771,7 +815,7 @@
    form ``pow(x, y)`` is equivalent to using the power operator: ``x**y``.
 
    The arguments must have numeric types.  With mixed operand types, the coercion
-   rules for binary arithmetic operators apply.  For int and long int operands, the
+   rules for binary arithmetic operators apply.  For :class:`int` operands, the
    result has the same type as the operands (after coercion) unless the second
    argument is negative; in that case, all arguments are converted to float and a
    float result is delivered.  For example, ``10**2`` returns ``100``, but
@@ -785,6 +829,22 @@
    accidents.)
 
 
+.. function:: print([object, ...][, sep=' '][, end='\n'][, file=sys.stdout])
+
+   Print *object*\(s) to the stream *file*, separated by *sep* and followed by
+   *end*.  *sep*, *end* and *file*, if present, must be given as keyword
+   arguments.
+
+   All non-keyword arguments are converted to strings like :func:`str` does and
+   written to the stream, separated by *sep* and followed by *end*.  Both *sep*
+   and *end* must be strings; they can also be ``None``, which means to use the
+   default values.  If no *object* is given, :func:`print` will just write
+   *end*.
+
+   The *file* argument must be an object with a ``write(string)`` method; if it
+   is not present or ``None``, :data:`sys.stdout` will be used.
+
+
 .. function:: property([fget[, fset[, fdel[, doc]]]])
 
    Return a property attribute.
@@ -802,7 +862,7 @@
 
    If given, *doc* will be the docstring of the property attribute. Otherwise, the
    property will copy *fget*'s docstring (if it exists).  This makes it possible to
-   create read-only properties easily using :func:`property` as a decorator::
+   create read-only properties easily using :func:`property` as a :term:`decorator`::
 
       class Parrot(object):
           def __init__(self):
@@ -820,15 +880,15 @@
 .. XXX does accept objects with __index__ too
 .. function:: range([start,] stop[, step])
 
-   This is a versatile function to create iterators containing arithmetic
-   progressions.  It is most often used in :keyword:`for` loops.  The arguments
-   must be integers.  If the *step* argument is omitted, it defaults to ``1``.
-   If the *start* argument is omitted, it defaults to ``0``.  The full form
-   returns an iterator of plain integers ``[start, start + step, start + 2 *
-   step, ...]``.  If *step* is positive, the last element is the largest ``start
-   + i * step`` less than *stop*; if *step* is negative, the last element is the
-   smallest ``start + i * step`` greater than *stop*.  *step* must not be zero
-   (or else :exc:`ValueError` is raised).  Example::
+   This is a versatile function to create lists containing arithmetic progressions.
+   It is most often used in :keyword:`for` loops.  The arguments must be plain
+   integers.  If the *step* argument is omitted, it defaults to ``1``.  If the
+   *start* argument is omitted, it defaults to ``0``.  The full form returns a list
+   of plain integers ``[start, start + step, start + 2 * step, ...]``.  If *step*
+   is positive, the last element is the largest ``start + i * step`` less than
+   *stop*; if *step* is negative, the last element is the smallest ``start + i *
+   step`` greater than *stop*.  *step* must not be zero (or else :exc:`ValueError`
+   is raised).  Example:
 
       >>> list(range(10))
       [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
@@ -857,18 +917,20 @@
 
 .. function:: reversed(seq)
 
-   Return a reverse iterator.  *seq* must be an object which supports the sequence
-   protocol (the :meth:`__len__` method and the :meth:`__getitem__` method with
-   integer arguments starting at ``0``).
+   Return a reverse :term:`iterator`.  *seq* must be an object which has
+   a :meth:`__reversed__` method or supports the sequence protocol (the
+   :meth:`__len__` method and the :meth:`__getitem__` method with integer
+   arguments starting at ``0``).
 
 
 .. function:: round(x[, n])
 
    Return the floating point value *x* rounded to *n* digits after the decimal
-   point.  If *n* is omitted, it defaults to zero. The result is a floating point
-   number.  Values are rounded to the closest multiple of 10 to the power minus
-   *n*; if two multiples are equally close, rounding is done away from 0 (so. for
-   example, ``round(0.5)`` is ``1.0`` and ``round(-0.5)`` is ``-1.0``).
+   point.  If *n* is omitted, it defaults to zero.  Values are rounded to the
+   closest multiple of 10 to the power minus *n*; if two multiples are equally
+   close, rounding is done toward the even choice (so, for example, both
+   ``round(0.5)`` and ``round(-0.5)`` are ``0``, and ``round(1.5)`` is
+   ``2``). Delegates to ``x.__round__(n)``.
 
 
 .. function:: set([iterable])
@@ -877,9 +939,6 @@
    Return a new set, optionally with elements are taken from *iterable*.
    The set type is described in :ref:`types-set`.
 
-   For other containers see the built in :class:`dict`, :class:`list`, and
-   :class:`tuple` classes, and the :mod:`collections` module.
-
 
 .. function:: setattr(object, name, value)
 
@@ -894,7 +953,7 @@
 
    .. index:: single: Numerical Python
 
-   Return a slice object representing the set of indices specified by
+   Return a :term:`slice` object representing the set of indices specified by
    ``range(start, stop, step)``.  The *start* and *step* arguments default to
    ``None``.  Slice objects have read-only data attributes :attr:`start`,
    :attr:`stop` and :attr:`step` which merely return the argument values (or their
@@ -904,30 +963,18 @@
    ``a[start:stop:step]`` or ``a[start:stop, i]``.
 
 
-.. function:: sorted(iterable[, cmp[, key[, reverse]]])
+.. function:: sorted(iterable[, key[, reverse]])
 
    Return a new sorted list from the items in *iterable*.
 
-   The optional arguments *cmp*, *key*, and *reverse* have the same meaning as
-   those for the :meth:`list.sort` method (described in section
-   :ref:`typesseq-mutable`).
-
-   *cmp* specifies a custom comparison function of two arguments (iterable
-   elements) which should return a negative, zero or positive number depending on
-   whether the first argument is considered smaller than, equal to, or larger than
-   the second argument: ``cmp=lambda x,y: cmp(x.lower(), y.lower())``
+   Has two optional arguments which must be specified as keyword arguments.
 
    *key* specifies a function of one argument that is used to extract a comparison
-   key from each list element: ``key=str.lower``
+   key from each list element: ``key=str.lower``.  The default value is ``None``.
 
    *reverse* is a boolean value.  If set to ``True``, then the list elements are
    sorted as if each comparison were reversed.
 
-   In general, the *key* and *reverse* conversion processes are much faster than
-   specifying an equivalent *cmp* function.  This is because *cmp* is called
-   multiple times for each list element while *key* and *reverse* touch each
-   element only once.
-
 
 .. function:: staticmethod(function)
 
@@ -940,8 +987,8 @@
           @staticmethod
           def f(arg1, arg2, ...): ...
 
-   The ``@staticmethod`` form is a function decorator -- see the description of
-   function definitions in :ref:`function` for details.
+   The ``@staticmethod`` form is a function :term:`decorator` -- see the
+   description of function definitions in :ref:`function` for details.
 
    It can be called either on the class (such as ``C.f()``) or on an instance (such
    as ``C().f()``).  The instance is ignored except for its class.
@@ -993,25 +1040,31 @@
    sequence of strings is by calling ``''.join(sequence)``.
 
 
-.. function:: super(type[, object-or-type])
+.. function:: super([type[, object-or-type]])
 
-   .. XXX need to document PEP "new super"
+   .. XXX updated as per http://www.artima.com/weblogs/viewpost.jsp?thread=208549 but needs checking
 
-   Return the superclass of *type*.  If the second argument is omitted the super
-   object returned is unbound.  If the second argument is an object,
-   ``isinstance(obj, type)`` must be true.  If the second argument is a type,
+   Return the superclass of *type*.
+   
+   Calling :func:`super()` without arguments is equivalent to
+   ``super(this_class, first_arg)``. If called with one
+   argument the super object returned is unbound.  If called with two
+   arguments and the second argument is an object, ``isinstance(obj,
+   type)`` must be true.  If the second argument is a type,
    ``issubclass(type2, type)`` must be true.
 
    A typical use for calling a cooperative superclass method is::
 
       class C(B):
-          def meth(self, arg):
-              super(C, self).meth(arg)
+          def method(self, arg):
+              super().method(arg)    # This does the same thing as: super(C, self).method(arg)
 
    Note that :func:`super` is implemented as part of the binding process for
-   explicit dotted attribute lookups such as ``super(C, self).__getitem__(name)``.
+   explicit dotted attribute lookups such as ``super().__getitem__(name)``.
    Accordingly, :func:`super` is undefined for implicit lookups using statements or
-   operators such as ``super(C, self)[name]``.
+   operators such as ``super()[name]``. Also, :func:`super` is not
+   limited to use inside methods: under the hood it searches the stack
+   frame for the class (``__class__``) and the first argument.
 
 
 .. function:: tuple([iterable])
@@ -1023,9 +1076,7 @@
    3])`` returns ``(1, 2, 3)``.  If no argument is given, returns a new empty
    tuple, ``()``.
 
-   :class:`tuple` is an immutable sequence type, as documented in
-   :ref:`typesseq`. For other containers see the built in :class:`dict`,
-   :class:`list`, and :class:`set` classes, and the :mod:`collections` module.
+   :class:`tuple` is an immutable sequence type, as documented in :ref:`typesseq`. 
 
 
 .. function:: type(object)
@@ -1046,12 +1097,12 @@
    :noindex:
 
    Return a new type object.  This is essentially a dynamic form of the
-   :keyword:`class` statement. The *name* string is the class name and becomes
-   the :attr:`__name__` attribute; the *bases* tuple itemizes the base classes
-   and becomes the :attr:`__bases__` attribute; and the *dict* dictionary is the
-   namespace containing definitions for class body and becomes the
-   :attr:`__dict__` attribute.  For example, the following two statements create
-   identical :class:`type` objects::
+   :keyword:`class` statement. The *name* string is the class name and becomes the
+   :attr:`__name__` attribute; the *bases* tuple itemizes the base classes and
+   becomes the :attr:`__bases__` attribute; and the *dict* dictionary is the
+   namespace containing definitions for class body and becomes the :attr:`__dict__`
+   attribute.  For example, the following two statements create identical
+   :class:`type` objects:
 
       >>> class X(object):
       ...     a = 1
@@ -1068,16 +1119,30 @@
    the effects on the corresponding symbol table are undefined. [#]_
 
 
-.. function:: zip([iterable, ...])
+.. function:: zip(*iterables)
 
-   This function returns an iterator of tuples, where the *i*-th tuple contains
-   the *i*-th element from each of the argument sequences or iterables.  The
-   iterator stops when the shortest argument sequence is exhausted.  When there
-   are multiple arguments which are all of the same length, :func:`zip` is
-   similar to :func:`map` with an initial argument of ``None``.  With a single
-   sequence argument, it returns an iterator of 1-tuples.  With no arguments, it
-   returns an empty iterator.
+   Make an iterator that aggregates elements from each of the iterables. 
 
+   Returns an iterator of tuples, where the *i*-th tuple contains
+   the *i*-th element from each of the argument sequences or iterables.  The
+   iterator stops when the shortest input iterable is exhausted. With a single
+   iterable argument, it returns an iterator of 1-tuples.  With no arguments, 
+   it returns an empty iterator.  Equivalent to::
+
+      def zip(*iterables):
+          # zip('ABCD', 'xy') --> Ax By
+          iterables = map(iter, iterables)
+          while iterables:
+              result = [it.next() for it in iterables]
+              yield tuple(result)
+
+   The left-to-right evaluation order of the iterables is guaranteed. This
+   makes possible an idiom for clustering a data series into n-length groups
+   using ``zip(*[iter(s)]*n)``.
+
+   :func:`zip` should only be used with unequal length inputs when you don't
+   care about trailing, unmatched values from the longer iterables.  If those
+   values are important, use :func:`itertools.zip_longest` instead.
 
 .. rubric:: Footnotes
 

Modified: python/branches/py3k-importlib/Doc/library/functools.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/functools.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/functools.rst	Thu Mar 27 00:48:05 2008
@@ -44,8 +44,9 @@
    some portion of a function's arguments and/or keywords resulting in a new object
    with a simplified signature.  For example, :func:`partial` can be used to create
    a callable that behaves like the :func:`int` function where the *base* argument
-   defaults to two::
+   defaults to two:
 
+      >>> from functools import partial
       >>> basetwo = partial(int, base=2)
       >>> basetwo.__doc__ = 'Convert base 2 string to an int.'
       >>> basetwo('10010')
@@ -76,9 +77,9 @@
    *WRAPPER_UPDATES* (which updates the wrapper function's *__dict__*, i.e. the
    instance dictionary).
 
-   The main intended use for this function is in decorator functions which wrap the
-   decorated function and return the wrapper. If the wrapper function is not
-   updated, the metadata of the returned function will reflect the wrapper
+   The main intended use for this function is in :term:`decorator` functions which
+   wrap the decorated function and return the wrapper. If the wrapper function is
+   not updated, the metadata of the returned function will reflect the wrapper
    definition rather than the original function definition, which is typically less
    than helpful.
 
@@ -87,8 +88,9 @@
 
    This is a convenience function for invoking ``partial(update_wrapper,
    wrapped=wrapped, assigned=assigned, updated=updated)`` as a function decorator
-   when defining a wrapper function. For example::
+   when defining a wrapper function. For example:
 
+      >>> from functools import wraps
       >>> def my_decorator(f):
       ...     @wraps(f)
       ...     def wrapper(*args, **kwds):

Modified: python/branches/py3k-importlib/Doc/library/gc.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/gc.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/gc.rst	Thu Mar 27 00:48:05 2008
@@ -131,7 +131,7 @@
 
    A list of objects which the collector found to be unreachable but could not be
    freed (uncollectable objects).  By default, this list contains only objects with
-   :meth:`__del__` methods. [#]_ Objects that have :meth:`__del__` methods and are
+   :meth:`__del__` methods. Objects that have :meth:`__del__` methods and are
    part of a reference cycle cause the entire reference cycle to be uncollectable,
    including objects not necessarily in the cycle but reachable only from it.
    Python doesn't collect such cycles automatically because, in general, it isn't
@@ -169,18 +169,6 @@
    the ``garbage`` list.
 
 
-.. data:: DEBUG_INSTANCES
-
-   When :const:`DEBUG_COLLECTABLE` or :const:`DEBUG_UNCOLLECTABLE` is set, print
-   information about instance objects found.
-
-
-.. data:: DEBUG_OBJECTS
-
-   When :const:`DEBUG_COLLECTABLE` or :const:`DEBUG_UNCOLLECTABLE` is set, print
-   information about objects other than instance objects found.
-
-
 .. data:: DEBUG_SAVEALL
 
    When set, all unreachable objects found will be appended to *garbage* rather
@@ -191,10 +179,6 @@
 
    The debugging flags necessary for the collector to print information about a
    leaking program (equal to ``DEBUG_COLLECTABLE | DEBUG_UNCOLLECTABLE |
-   DEBUG_INSTANCES | DEBUG_OBJECTS | DEBUG_SAVEALL``).
+   DEBUG_SAVEALL``).
 
 .. rubric:: Footnotes
-
-.. [#] Prior to Python 2.2, the list contained all instance objects in unreachable
-   cycles,  not only those with :meth:`__del__` methods.
-

Modified: python/branches/py3k-importlib/Doc/library/gensuitemodule.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/gensuitemodule.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/gensuitemodule.rst	Thu Mar 27 00:48:05 2008
@@ -6,9 +6,7 @@
    :platform: Mac
    :synopsis: Create a stub package from an OSA dictionary
 .. sectionauthor:: Jack Jansen <Jack.Jansen at cwi.nl>
-
-
-.. % \moduleauthor{Jack Jansen?}{email}
+.. moduleauthor:: Jack Jansen
 
 The :mod:`gensuitemodule` module creates a Python package implementing stub code
 for the AppleScript suites that are implemented by a specific application,

Modified: python/branches/py3k-importlib/Doc/library/getopt.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/getopt.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/getopt.rst	Thu Mar 27 00:48:05 2008
@@ -9,9 +9,9 @@
 
 This module helps scripts to parse the command line arguments in ``sys.argv``.
 It supports the same conventions as the Unix :cfunc:`getopt` function (including
-the special meanings of arguments of the form '``-``' and '``--``'). Long
+the special meanings of arguments of the form '``-``' and '``--``').  Long
 options similar to those supported by GNU software may be used as well via an
-optional third argument. This module provides a single function and an
+optional third argument. This module provides two functions and an
 exception:
 
 
@@ -77,7 +77,7 @@
 
    Alias for :exc:`GetoptError`; for backward compatibility.
 
-An example using only Unix style options::
+An example using only Unix style options:
 
    >>> import getopt
    >>> args = '-a -b -cfoo -d bar a1 a2'.split()
@@ -89,7 +89,7 @@
    >>> args
    ['a1', 'a2']
 
-Using long option names is equally easy::
+Using long option names is equally easy:
 
    >>> s = '--condition=foo --testing --output-file abc.def -x a1 a2'
    >>> args = s.split()
@@ -98,8 +98,7 @@
    >>> optlist, args = getopt.getopt(args, 'x', [
    ...     'condition=', 'output-file=', 'testing'])
    >>> optlist
-   [('--condition', 'foo'), ('--testing', ''), ('--output-file', 'abc.def'), ('-x',
-    '')]
+   [('--condition', 'foo'), ('--testing', ''), ('--output-file', 'abc.def'), ('-x', '')]
    >>> args
    ['a1', 'a2']
 

Modified: python/branches/py3k-importlib/Doc/library/getpass.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/getpass.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/getpass.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`getpass` --- Portable password input
 ==========================================
 
@@ -6,9 +5,7 @@
    :synopsis: Portable reading of passwords and retrieval of the userid.
 .. moduleauthor:: Piers Lauder <piers at cs.su.oz.au>
 .. sectionauthor:: Fred L. Drake, Jr. <fdrake at acm.org>
-
-
-.. % Windows (& Mac?) support by Guido van Rossum.
+.. Windows (& Mac?) support by Guido van Rossum.
 
 The :mod:`getpass` module provides two functions:
 

Modified: python/branches/py3k-importlib/Doc/library/gettext.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/gettext.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/gettext.rst	Thu Mar 27 00:48:05 2008
@@ -136,9 +136,9 @@
 greater convenience than the GNU :program:`gettext` API.  It is the recommended
 way of localizing your Python applications and modules.  :mod:`gettext` defines
 a "translations" class which implements the parsing of GNU :file:`.mo` format
-files, and has methods for returning either standard 8-bit strings or Unicode
-strings. Instances of this "translations" class can also install themselves  in
-the built-in namespace as the function :func:`_`.
+files, and has methods for returning strings. Instances of this "translations"
+class can also install themselves in the built-in namespace as the function
+:func:`_`.
 
 
 .. function:: find(domain[, localedir[,  languages[, all]]])
@@ -257,8 +257,7 @@
 .. method:: NullTranslations.ugettext(message)
 
    If a fallback has been set, forward :meth:`ugettext` to the fallback. Otherwise,
-   return the translated message as a Unicode string. Overridden in derived
-   classes.
+   return the translated message as a string. Overridden in derived classes.
 
 
 .. method:: NullTranslations.ngettext(singular, plural, n)
@@ -276,7 +275,7 @@
 .. method:: NullTranslations.ungettext(singular, plural, n)
 
    If a fallback has been set, forward :meth:`ungettext` to the fallback.
-   Otherwise, return the translated message as a Unicode string. Overridden in
+   Otherwise, return the translated message as a  string. Overridden in
    derived classes.
 
 
@@ -347,8 +346,8 @@
 ``None`` if not found.  If the charset encoding is specified, then all message
 ids and message strings read from the catalog are converted to Unicode using
 this encoding.  The :meth:`ugettext` method always returns a Unicode, while the
-:meth:`gettext` returns an encoded 8-bit string.  For the message id arguments
-of both methods, either Unicode strings or 8-bit strings containing only
+:meth:`gettext` returns an encoded bytestring.  For the message id arguments
+of both methods, either Unicode strings or bytestrings containing only
 US-ASCII characters are acceptable.  Note that the Unicode version of the
 methods (i.e. :meth:`ugettext` and :meth:`ungettext`) are the recommended
 interface to use for internationalized Python programs.
@@ -366,7 +365,7 @@
 .. method:: GNUTranslations.gettext(message)
 
    Look up the *message* id in the catalog and return the corresponding message
-   string, as an 8-bit string encoded with the catalog's charset encoding, if
+   string, as a bytestring encoded with the catalog's charset encoding, if
    known.  If there is no entry in the catalog for the *message* id, and a fallback
    has been set, the look up is forwarded to the fallback's :meth:`gettext` method.
    Otherwise, the *message* id is returned.
@@ -382,7 +381,7 @@
 .. method:: GNUTranslations.ugettext(message)
 
    Look up the *message* id in the catalog and return the corresponding message
-   string, as a Unicode string.  If there is no entry in the catalog for the
+   string, as a string.  If there is no entry in the catalog for the
    *message* id, and a fallback has been set, the look up is forwarded to the
    fallback's :meth:`ugettext` method.  Otherwise, the *message* id is returned.
 
@@ -391,7 +390,7 @@
 
    Do a plural-forms lookup of a message id.  *singular* is used as the message id
    for purposes of lookup in the catalog, while *n* is used to determine which
-   plural form to use.  The returned message string is an 8-bit string encoded with
+   plural form to use.  The returned message string is a bytestring encoded with
    the catalog's charset encoding, if known.
 
    If the message id is not found in the catalog, and a fallback is specified, the
@@ -410,7 +409,7 @@
 
    Do a plural-forms lookup of a message id.  *singular* is used as the message id
    for purposes of lookup in the catalog, while *n* is used to determine which
-   plural form to use.  The returned message string is a Unicode string.
+   plural form to use.  The returned message string is a string.
 
    If the message id is not found in the catalog, and a fallback is specified, the
    request is forwarded to the fallback's :meth:`ungettext` method.  Otherwise,

Modified: python/branches/py3k-importlib/Doc/library/glob.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/glob.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/glob.rst	Thu Mar 27 00:48:05 2008
@@ -28,8 +28,8 @@
 
 .. function:: iglob(pathname)
 
-   Return an iterator which yields the same values as :func:`glob` without actually
-   storing them all simultaneously.
+   Return an :term:`iterator` which yields the same values as :func:`glob`
+   without actually storing them all simultaneously.
 
 
 For example, consider a directory containing only the following files:

Modified: python/branches/py3k-importlib/Doc/library/gzip.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/gzip.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/gzip.rst	Thu Mar 27 00:48:05 2008
@@ -15,6 +15,9 @@
 programs, such  as those produced by :program:`compress` and :program:`pack`,
 are not supported by this module.
 
+For other archive formats, see the :mod:`bz2`, :mod:`zipfile`, and
+:mod:`tarfile` modules.
+
 The module defines the following items:
 
 

Modified: python/branches/py3k-importlib/Doc/library/hashlib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/hashlib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/hashlib.rst	Thu Mar 27 00:48:05 2008
@@ -19,6 +19,10 @@
 "message digest" are interchangeable.  Older algorithms were called message
 digests.  The modern term is secure hash.
 
+.. note::
+   If you want the adler32 or crc32 hash functions they are available in
+   the :mod:`zlib` module.
+
 .. warning::
 
    Some algorithms have known hash collision weaknesses, see the FAQ at the end.
@@ -52,8 +56,12 @@
    >>> m.update(b" the spammish repetition")
    >>> m.digest()
    b'\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9'
+   >>> m.digest_size
+   16
+   >>> m.block_size
+   64
 
-More condensed::
+More condensed:
 
    >>> hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest()
    b'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'
@@ -63,7 +71,7 @@
 hashes as well as any other algorithms that your OpenSSL library may offer.  The
 named constructors are much faster than :func:`new` and should be preferred.
 
-Using :func:`new` with an algorithm provided by OpenSSL::
+Using :func:`new` with an algorithm provided by OpenSSL:
 
    >>> h = hashlib.new('ripemd160')
    >>> h.update(b"Nobody inspects the spammish repetition")
@@ -76,7 +84,11 @@
 
 .. data:: digest_size
 
-   The size of the resulting digest in bytes.
+   The size of the resulting hash in bytes.
+
+.. data:: block_size
+
+   The internal block size of the hash algorithm in bytes.
 
 A hash object has the following methods:
 

Modified: python/branches/py3k-importlib/Doc/library/heapq.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/heapq.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/heapq.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`heapq` --- Heap queue algorithm
 =====================================
 
@@ -8,9 +7,6 @@
 .. sectionauthor:: Guido van Rossum <guido at python.org>
 .. sectionauthor:: François Pinard
 
-
-.. % Theoretical explanation:
-
 This module provides an implementation of the heap queue algorithm, also known
 as the priority queue algorithm.
 
@@ -47,6 +43,13 @@
    Pop and return the smallest item from the *heap*, maintaining the heap
    invariant.  If the heap is empty, :exc:`IndexError` is raised.
 
+.. function:: heappushpop(heap, item)
+
+   Push *item* on the heap, then pop and return the smallest item from the
+   *heap*.  The combined action runs more efficiently than :func:`heappush`
+   followed by a separate call to :func:`heappop`.
+
+   .. versionadded:: 2.6
 
 .. function:: heapify(x)
 
@@ -65,7 +68,7 @@
       if item > heap[0]:
           item = heapreplace(heap, item)
 
-Example of use::
+Example of use:
 
    >>> from heapq import heappush, heappop
    >>> heap = []
@@ -82,7 +85,6 @@
    >>> data.sort()
    >>> data == ordered
    True
-   >>>
 
 The module also offers three general purpose functions based on heaps.
 
@@ -90,8 +92,8 @@
 .. function:: merge(*iterables)
 
    Merge multiple sorted inputs into a single sorted output (for example, merge
-   timestamped entries from multiple log files).  Returns an iterator over over the
-   sorted values.
+   timestamped entries from multiple log files).  Returns an :term:`iterator`
+   over over the sorted values.
 
    Similar to ``sorted(itertools.chain(*iterables))`` but returns an iterable, does
    not pull the data into memory all at once, and assumes that each of the input

Modified: python/branches/py3k-importlib/Doc/library/idle.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/idle.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/idle.rst	Thu Mar 27 00:48:05 2008
@@ -1,20 +1,16 @@
 .. _idle:
 
-Idle
+IDLE
 ====
 
 .. moduleauthor:: Guido van Rossum <guido at Python.org>
 
-
-.. % \declaremodule{standard}{idle}
-.. % \modulesynopsis{A Python Integrated Development Environment}
-
 .. index::
-   single: Idle
+   single: IDLE
    single: Python Editor
    single: Integrated Development Environment
 
-Idle is the Python IDE built with the :mod:`Tkinter` GUI toolkit.
+IDLE is the Python IDE built with the :mod:`Tkinter` GUI toolkit.
 
 IDLE has the following features:
 

Modified: python/branches/py3k-importlib/Doc/library/imaplib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/imaplib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/imaplib.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`imaplib` --- IMAP4 protocol client
 ========================================
 
@@ -6,6 +5,10 @@
    :synopsis: IMAP4 protocol client (requires sockets).
 .. moduleauthor:: Piers Lauder <piers at communitysolutions.com.au>
 .. sectionauthor:: Piers Lauder <piers at communitysolutions.com.au>
+.. revised by ESR, January 2000
+.. changes for IMAP4_SSL by Tino Lange <Tino.Lange at isg.de>, March 2002
+.. changes for IMAP4_stream by Piers Lauder <piers at communitysolutions.com.au>,
+   November 2002
 
 
 .. index::
@@ -13,14 +16,6 @@
    pair: IMAP4_SSL; protocol
    pair: IMAP4_stream; protocol
 
-.. % Based on HTML documentation by Piers Lauder
-.. % <piers at communitysolutions.com.au>;
-.. % converted by Fred L. Drake, Jr. <fdrake at acm.org>.
-.. % Revised by ESR, January 2000.
-.. % Changes for IMAP4_SSL by Tino Lange <Tino.Lange at isg.de>, March 2002
-.. % Changes for IMAP4_stream by Piers Lauder
-.. % <piers at communitysolutions.com.au>, November 2002
-
 This module defines three classes, :class:`IMAP4`, :class:`IMAP4_SSL` and
 :class:`IMAP4_stream`, which encapsulate a connection to an IMAP4 server and
 implement a large subset of the IMAP4rev1 client protocol as defined in
@@ -121,7 +116,7 @@
 
    Documents describing the protocol, and sources and binaries  for servers
    implementing it, can all be found at the University of Washington's *IMAP
-   Information Center* (http://www.cac.washington.edu/imap/).
+   Information Center* (http://www.washington.edu/imap/).
 
 
 .. _imap4-objects:

Modified: python/branches/py3k-importlib/Doc/library/imp.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/imp.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/imp.rst	Thu Mar 27 00:48:05 2008
@@ -123,6 +123,81 @@
    function does nothing.
 
 
+.. function:: reload(module)
+
+   Reload a previously imported *module*.  The argument must be a module object, so
+   it must have been successfully imported before.  This is useful if you have
+   edited the module source file using an external editor and want to try out the
+   new version without leaving the Python interpreter.  The return value is the
+   module object (the same as the *module* argument).
+
+   When ``reload(module)`` is executed:
+
+   * Python modules' code is recompiled and the module-level code reexecuted,
+     defining a new set of objects which are bound to names in the module's
+     dictionary.  The ``init`` function of extension modules is not called a second
+     time.
+
+   * As with all other objects in Python the old objects are only reclaimed after
+     their reference counts drop to zero.
+
+   * The names in the module namespace are updated to point to any new or changed
+     objects.
+
+   * Other references to the old objects (such as names external to the module) are
+     not rebound to refer to the new objects and must be updated in each namespace
+     where they occur if that is desired.
+
+   There are a number of other caveats:
+
+   If a module is syntactically correct but its initialization fails, the first
+   :keyword:`import` statement for it does not bind its name locally, but does
+   store a (partially initialized) module object in ``sys.modules``.  To reload the
+   module you must first :keyword:`import` it again (this will bind the name to the
+   partially initialized module object) before you can :func:`reload` it.
+
+   When a module is reloaded, its dictionary (containing the module's global
+   variables) is retained.  Redefinitions of names will override the old
+   definitions, so this is generally not a problem.  If the new version of a module
+   does not define a name that was defined by the old version, the old definition
+   remains.  This feature can be used to the module's advantage if it maintains a
+   global table or cache of objects --- with a :keyword:`try` statement it can test
+   for the table's presence and skip its initialization if desired::
+
+      try:
+          cache
+      except NameError:
+          cache = {}
+
+   It is legal though generally not very useful to reload built-in or dynamically
+   loaded modules, except for :mod:`sys`, :mod:`__main__` and :mod:`__builtin__`.
+   In many cases, however, extension modules are not designed to be initialized
+   more than once, and may fail in arbitrary ways when reloaded.
+
+   If a module imports objects from another module using :keyword:`from` ...
+   :keyword:`import` ..., calling :func:`reload` for the other module does not
+   redefine the objects imported from it --- one way around this is to re-execute
+   the :keyword:`from` statement, another is to use :keyword:`import` and qualified
+   names (*module*.*name*) instead.
+
+   If a module instantiates instances of a class, reloading the module that defines
+   the class does not affect the method definitions of the instances --- they
+   continue to use the old class definition.  The same is true for derived classes.
+
+
+.. function:: acquire_lock()
+
+   Acquires the interpreter's import lock for the current thread.  This lock should
+   be used by import hooks to ensure thread-safety when importing modules. On
+   platforms without threads, this function does nothing.
+
+
+.. function:: release_lock()
+
+   Release the interpreter's import lock. On platforms without threads, this
+   function does nothing.
+
+
 The following constants with integer values, defined in this module, are used to
 indicate the search result of :func:`find_module`.
 

Modified: python/branches/py3k-importlib/Doc/library/imputil.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/imputil.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/imputil.rst	Thu Mar 27 00:48:05 2008
@@ -108,7 +108,7 @@
 
 ::
 
-   import sys, imp, __builtin__
+   import sys, imp, builtins
 
    # Replacement for __import__()
    def import_hook(name, globals=None, locals=None, fromlist=None):
@@ -218,12 +218,12 @@
 
 
    # Save the original hooks
-   original_import = __builtin__.__import__
-   original_reload = __builtin__.reload
+   original_import = builtins.__import__
+   original_reload = builtins.reload
 
    # Now install our hooks
-   __builtin__.__import__ = import_hook
-   __builtin__.reload = reload_hook
+   builtins.__import__ = import_hook
+   builtins.reload = reload_hook
 
 .. index::
    module: knee

Modified: python/branches/py3k-importlib/Doc/library/inspect.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/inspect.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/inspect.rst	Thu Mar 27 00:48:05 2008
@@ -26,7 +26,7 @@
 -----------------
 
 The :func:`getmembers` function retrieves the members of an object such as a
-class or module. The eleven functions whose names begin with "is" are mainly
+class or module. The sixteen functions whose names begin with "is" are mainly
 provided as convenient choices for the second argument to :func:`getmembers`.
 They also help you determine when you can expect to find the following special
 attributes:
@@ -49,14 +49,11 @@
 |           | __name__        | name with which this      |
 |           |                 | method was defined        |
 +-----------+-----------------+---------------------------+
-|           | im_class        | class object that asked   |
-|           |                 | for this method           |
-+-----------+-----------------+---------------------------+
-|           | im_func         | function object           |
+|           | __func__        | function object           |
 |           |                 | containing implementation |
 |           |                 | of method                 |
 +-----------+-----------------+---------------------------+
-|           | im_self         | instance to which this    |
+|           | __self__        | instance to which this    |
 |           |                 | method is bound, or       |
 |           |                 | ``None``                  |
 +-----------+-----------------+---------------------------+
@@ -67,7 +64,7 @@
 +-----------+-----------------+---------------------------+
 |           | __code__        | code object containing    |
 |           |                 | compiled function         |
-|           |                 | bytecode                  |
+|           |                 | :term:`bytecode`          |
 +-----------+-----------------+---------------------------+
 |           | __defaults__    | tuple of any default      |
 |           |                 | values for arguments      |
@@ -183,10 +180,16 @@
    name.  If the optional *predicate* argument is supplied, only members for which
    the predicate returns a true value are included.
 
+   .. note::
+
+      :func:`getmembers` does not return metaclass attributes when the argument
+      is a class (this behavior is inherited from the :func:`dir` function).
+
 
 .. function:: getmoduleinfo(path)
 
-   Return a tuple of values that describe how Python will interpret the file
+   Returns a :term:`named tuple` ``ModuleInfo(name, suffix, mode,
+   module_type)`` of values that describe how Python will interpret the file
    identified by *path* if it is a module, or ``None`` if it would not be
    identified as a module.  The return tuple is ``(name, suffix, mode, mtype)``,
    where *name* is the name of the module without the name of any enclosing
@@ -223,7 +226,17 @@
 
 .. function:: isfunction(object)
 
-   Return true if the object is a Python function or unnamed (lambda) function.
+   Return true if the object is a Python function or unnamed (:term:`lambda`) function.
+
+
+.. function:: isgeneratorfunction(object)
+
+   Return true if the object is a Python generator function.
+
+
+.. function:: isgenerator(object)
+
+   Return true if the object is a generator.
 
 
 .. function:: istraceback(object)
@@ -250,33 +263,38 @@
 
    Return true if the object is a user-defined or built-in function or method.
 
+.. function:: isabstract(object)
+
+   Return true if the object is an abstract base class.
+
 
 .. function:: ismethoddescriptor(object)
 
-   Return true if the object is a method descriptor, but not if ismethod() or
-   isclass() or isfunction() are true.
+   Return true if the object is a method descriptor, but not if :func:`ismethod`
+   or :func:`isclass` or :func:`isfunction` are true.
 
-   This is new as of Python 2.2, and, for example, is true of int.__add__. An
-   object passing this test has a __get__ attribute but not a __set__ attribute,
-   but beyond that the set of attributes varies.  __name__ is usually sensible, and
-   __doc__ often is.
-
-   Methods implemented via descriptors that also pass one of the other tests return
-   false from the ismethoddescriptor() test, simply because the other tests promise
-   more -- you can, e.g., count on having the im_func attribute (etc) when an
-   object passes ismethod().
+   This is new as of Python 2.2, and, for example, is true of
+   ``int.__add__``. An object passing this test has a :attr:`__get__` attribute
+   but not a :attr:`__set__` attribute, but beyond that the set of attributes
+   varies.  :attr:`__name__` is usually sensible, and :attr:`__doc__` often is.
+
+   Methods implemented via descriptors that also pass one of the other tests
+   return false from the :func:`ismethoddescriptor` test, simply because the
+   other tests promise more -- you can, e.g., count on having the
+   :attr:`__func__` attribute (etc) when an object passes :func:`ismethod`.
 
 
 .. function:: isdatadescriptor(object)
 
    Return true if the object is a data descriptor.
 
-   Data descriptors have both a __get__ and a __set__ attribute.  Examples are
-   properties (defined in Python), getsets, and members.  The latter two are
-   defined in C and there are more specific tests available for those types, which
-   is robust across Python implementations.  Typically, data descriptors will also
-   have __name__ and __doc__ attributes (properties, getsets, and members have both
-   of these attributes), but this is not guaranteed.
+   Data descriptors have both a :attr:`__get__` and a :attr:`__set__` attribute.
+   Examples are properties (defined in Python), getsets, and members.  The
+   latter two are defined in C and there are more specific tests available for
+   those types, which is robust across Python implementations.  Typically, data
+   descriptors will also have :attr:`__name__` and :attr:`__doc__` attributes
+   (properties, getsets, and members have both of these attributes), but this is
+   not guaranteed.
 
 
 .. function:: isgetsetdescriptor(object)
@@ -293,8 +311,8 @@
    Return true if the object is a member descriptor.
 
    Member descriptors are attributes defined in extension modules via
-   ``PyMemberDef`` structures.  For Python implementations without such types, this
-   method will always return ``False``.
+   ``PyMemberDef`` structures.  For Python implementations without such types,
+   this method will always return ``False``.
 
 
 .. _inspect-source:
@@ -374,8 +392,9 @@
 
 .. function:: getargspec(func)
 
-   Get the names and default values of a function's arguments. A tuple of four
-   things is returned: ``(args, varargs, varkw, defaults)``. *args* is a list of
+   Get the names and default values of a function's arguments. A 
+   :term:`named tuple` ``ArgSpec(args, varargs, keywords,
+   defaults)`` is returned. *args* is a list of
    the argument names. *varargs* and *varkw* are the names of the ``*`` and
    ``**`` arguments or ``None``. *defaults* is a tuple of default argument
    values or None if there are no default arguments; if this tuple has *n*
@@ -388,10 +407,10 @@
 
 .. function:: getfullargspec(func)
 
-   Get the names and default values of a function's arguments.  A tuple of seven
-   things is returned:
+   Get the names and default values of a function's arguments.  A :term:`named tuple`
+   is returned:
 
-   ``(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations)``
+   ``FullArgSpec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations)``
 
    *args* is a list of the argument names.  *varargs* and *varkw* are the names
    of the ``*`` and ``**`` arguments or ``None``.  *defaults* is an n-tuple of
@@ -405,8 +424,8 @@
 
 .. function:: getargvalues(frame)
 
-   Get information about arguments passed into a particular frame. A tuple of four
-   things is returned: ``(args, varargs, varkw, locals)``. *args* is a list of the
+   Get information about arguments passed into a particular frame. A :term:`named tuple` 
+   ``ArgInfo(args, varargs, keywords, locals)`` is returned. *args* is a list of the
    argument names (it may contain nested lists). *varargs* and *varkw* are the
    names of the ``*`` and ``**`` arguments or ``None``. *locals* is the locals
    dictionary of the given frame.
@@ -473,8 +492,8 @@
 
 .. function:: getframeinfo(frame[, context])
 
-   Get information about a frame or traceback object.  A 5-tuple is returned, the
-   last five elements of the frame's frame record.
+   Get information about a frame or traceback object.  A :term:`named tuple` 
+   ``Traceback(filename, lineno, function, code_context, index)`` is returned.
 
 
 .. function:: getouterframes(frame[, context])

Modified: python/branches/py3k-importlib/Doc/library/itertools.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/itertools.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/itertools.rst	Thu Mar 27 00:48:05 2008
@@ -8,7 +8,12 @@
 .. sectionauthor:: Raymond Hettinger <python at rcn.com>
 
 
-This module implements a number of iterator building blocks inspired by
+.. testsetup::
+
+   from itertools import *
+
+
+This module implements a number of :term:`iterator` building blocks inspired by
 constructs from the Haskell and SML programming languages.  Each has been recast
 in a form suitable for Python.
 
@@ -22,9 +27,8 @@
 to construct more specialized tools succinctly and efficiently in pure Python.
 
 For instance, SML provides a tabulation tool: ``tabulate(f)`` which produces a
-sequence ``f(0), f(1), ...``.  This toolbox provides :func:`imap` and
-:func:`count` which can be combined to form ``imap(f, count())`` and produce an
-equivalent result.
+sequence ``f(0), f(1), ...``.  But, this effect can be achieved in Python
+by combining :func:`map` and :func:`count` to form ``map(f, count())``.
 
 Likewise, the functional tools are designed to work well with the high-speed
 functions provided by the :mod:`operator` module.
@@ -69,27 +73,88 @@
    Equivalent to::
 
       def chain(*iterables):
+          # chain('ABC', 'DEF') --> A B C D E F
           for it in iterables:
               for element in it:
                   yield element
 
 
+.. function:: itertools.chain.from_iterable(iterable)
+
+   Alternate constructor for :func:`chain`.  Gets chained inputs from a 
+   single iterable argument that is evaluated lazily.  Equivalent to::
+
+      @classmethod
+      def from_iterable(iterables):
+          # chain.from_iterable(['ABC', 'DEF']) --> A B C D E F
+          for it in iterables:
+              for element in it:
+                  yield element
+
+   .. versionadded:: 2.6
+
+
+.. function:: combinations(iterable, r)
+
+   Return successive *r* length combinations of elements in the *iterable*.
+
+   Combinations are emitted in lexicographic sort order.  So, if the 
+   input *iterable* is sorted, the combination tuples will be produced
+   in sorted order.  
+
+   Elements are treated as unique based on their position, not on their
+   value.  So if the input elements are unique, there will be no repeat
+   values in each combination.
+
+   Each result tuple is ordered to match the input order.  So, every
+   combination is a subsequence of the input *iterable*.
+
+   Equivalent to::
+
+        def combinations(iterable, r):
+            # combinations('ABCD', 2) --> AB AC AD BC BD CD
+            # combinations(range(4), 3) --> 012 013 023 123
+            pool = tuple(iterable)
+            n = len(pool)
+            indices = range(r)
+            yield tuple(pool[i] for i in indices)
+            while 1:
+                for i in reversed(range(r)):
+                    if indices[i] != i + n - r:
+                        break
+                else:
+                    return
+                indices[i] += 1
+                for j in range(i+1, r):
+                    indices[j] = indices[j-1] + 1
+                yield tuple(pool[i] for i in indices)
+
+   The code for :func:`combinations` can be also expressed as a subsequence
+   of :func:`permutations` after filtering entries where the elements are not
+   in sorted order (according to their position in the input pool)::
+
+        def combinations(iterable, r):
+            pool = tuple(iterable)
+            n = len(pool)
+            for indices in permutations(range(n), r):
+                if sorted(indices) == list(indices):
+                    yield tuple(pool[i] for i in indices)
+
+   .. versionadded:: 2.6
+
 .. function:: count([n])
 
    Make an iterator that returns consecutive integers starting with *n*. If not
-   specified *n* defaults to zero.   Does not currently support python long
-   integers.  Often used as an argument to :func:`imap` to generate consecutive
-   data points. Also, used with :func:`izip` to add sequence numbers.  Equivalent
-   to::
+   specified *n* defaults to zero.   Often used as an argument to :func:`map` to
+   generate consecutive data points. Also, used with :func:`zip` to add sequence
+   numbers.  Equivalent to::
 
       def count(n=0):
+          # count(10) --> 10 11 12 13 14 ...
           while True:
               yield n
               n += 1
 
-   Note, :func:`count` does not check for overflow and will return negative numbers
-   after exceeding ``sys.maxint``.  This behavior may change in the future.
-
 
 .. function:: cycle(iterable)
 
@@ -98,6 +163,7 @@
    indefinitely.  Equivalent to::
 
       def cycle(iterable):
+          # cycle('ABCD') --> A B C D A B C D A B C D ...
           saved = []
           for element in iterable:
               yield element
@@ -118,6 +184,7 @@
    start-up time.  Equivalent to::
 
       def dropwhile(predicate, iterable):
+          # dropwhile(lambda x: x<5, [1,4,6,4,1]) --> 6 4 1
           iterable = iter(iterable)
           for x in iterable:
               if not predicate(x):
@@ -156,12 +223,14 @@
    :func:`groupby` is equivalent to::
 
       class groupby(object):
+          # [k for k, g in groupby('AAAABBBCCDAABBB')] --> A B C D A B
+          # [(list(g)) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D
           def __init__(self, iterable, key=None):
               if key is None:
                   key = lambda x: x
               self.keyfunc = key
               self.it = iter(iterable)
-              self.tgtkey = self.currkey = self.currvalue = []
+              self.tgtkey = self.currkey = self.currvalue = object()
           def __iter__(self):
               return self
           def __next__(self):
@@ -177,27 +246,14 @@
                   self.currkey = self.keyfunc(self.currvalue)
 
 
-.. function:: ifilter(predicate, iterable)
-
-   Make an iterator that filters elements from iterable returning only those for
-   which the predicate is ``True``. If *predicate* is ``None``, return the items
-   that are true. Equivalent to::
-
-      def ifilter(predicate, iterable):
-          if predicate is None:
-              predicate = bool
-          for x in iterable:
-              if predicate(x):
-                  yield x
-
-
-.. function:: ifilterfalse(predicate, iterable)
+.. function:: filterfalse(predicate, iterable)
 
    Make an iterator that filters elements from iterable returning only those for
    which the predicate is ``False``. If *predicate* is ``None``, return the items
    that are false. Equivalent to::
 
-      def ifilterfalse(predicate, iterable):
+      def filterfalse(predicate, iterable):
+          # filterfalse(lambda x: x%2, range(10)) --> 0 2 4 6 8
           if predicate is None:
               predicate = bool
           for x in iterable:
@@ -205,26 +261,6 @@
                   yield x
 
 
-.. function:: imap(function, *iterables)
-
-   Make an iterator that computes the function using arguments from each of the
-   iterables.  If *function* is set to ``None``, then :func:`imap` returns the
-   arguments as a tuple.  Like :func:`map` but stops when the shortest iterable is
-   exhausted instead of filling in ``None`` for shorter iterables.  The reason for
-   the difference is that infinite iterator arguments are typically an error for
-   :func:`map` (because the output is fully evaluated) but represent a common and
-   useful way of supplying arguments to :func:`imap`. Equivalent to::
-
-      def imap(function, *iterables):
-          iterables = map(iter, iterables)
-          while True:
-              args = [next(i) for i in iterables]
-              if function is None:
-                  yield tuple(args)
-              else:
-                  yield function(*args)
-
-
 .. function:: islice(iterable, [start,] stop [, step])
 
    Make an iterator that returns selected elements from the iterable. If *start* is
@@ -238,8 +274,12 @@
    multi-line report may list a name field on every third line).  Equivalent to::
 
       def islice(iterable, *args):
+          # islice('ABCDEFG', 2) --> A B
+          # islice('ABCDEFG', 2, 4) --> C D
+          # islice('ABCDEFG', 2, None) --> C D E F G
+          # islice('ABCDEFG', 0, None, 2) --> A C E G
           s = slice(*args)
-          it = iter(range(s.start or 0, s.stop or sys.maxint, s.step or 1))
+          it = range(s.start or 0, s.stop or sys.maxsize, s.step or 1)
           nexti = next(it)
           for i, element in enumerate(iterable):
               if i == nexti:
@@ -250,69 +290,124 @@
    then the step defaults to one.
 
 
-.. function:: izip(*iterables)
-
-   Make an iterator that aggregates elements from each of the iterables. Like
-   :func:`zip` except that it returns an iterator instead of a list.  Used for
-   lock-step iteration over several iterables at a time.  Equivalent to::
-
-      def izip(*iterables):
-          iterables = map(iter, iterables)
-          while iterables:
-              result = [next(it) for it in iterables]
-              yield tuple(result)
-
-   When no iterables are specified, return a zero length iterator.
-
-   Note, the left-to-right evaluation order of the iterables is guaranteed. This
-   makes possible an idiom for clustering a data series into n-length groups using
-   ``izip(*[iter(s)]*n)``.  For data that doesn't fit n-length groups exactly, the
-   last tuple can be pre-padded with fill values using ``izip(*[chain(s,
-   [None]*(n-1))]*n)``.
-
-   Note, when :func:`izip` is used with unequal length inputs, subsequent
-   iteration over the longer iterables cannot reliably be continued after
-   :func:`izip` terminates.  Potentially, up to one entry will be missing from
-   each of the left-over iterables. This occurs because a value is fetched from
-   each iterator in- turn, but the process ends when one of the iterators
-   terminates.  This leaves the last fetched values in limbo (they cannot be
-   returned in a final, incomplete tuple and they are cannot be pushed back into
-   the iterator for retrieval with ``next(it)``).  In general, :func:`izip`
-   should only be used with unequal length inputs when you don't care about
-   trailing, unmatched values from the longer iterables.
-
-
-.. function:: izip_longest(*iterables[, fillvalue])
+.. function:: zip_longest(*iterables[, fillvalue])
 
    Make an iterator that aggregates elements from each of the iterables. If the
    iterables are of uneven length, missing values are filled-in with *fillvalue*.
    Iteration continues until the longest iterable is exhausted.  Equivalent to::
 
-      def izip_longest(*args, **kwds):
-          fillvalue = kwds.get('fillvalue')
+      def zip_longest(*args, fillvalue=None):
+          # zip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
           def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
               yield counter()         # yields the fillvalue, or raises IndexError
           fillers = repeat(fillvalue)
           iters = [chain(it, sentinel(), fillers) for it in args]
           try:
-              for tup in izip(*iters):
+              for tup in zip(*iters):
                   yield tup
           except IndexError:
               pass
 
-   If one of the iterables is potentially infinite, then the :func:`izip_longest`
+   If one of the iterables is potentially infinite, then the :func:`zip_longest`
    function should be wrapped with something that limits the number of calls (for
    example :func:`islice` or :func:`takewhile`).
 
 
+.. function:: permutations(iterable[, r])
+
+   Return successive *r* length permutations of elements in the *iterable*.
+
+   If *r* is not specified or is ``None``, then *r* defaults to the length
+   of the *iterable* and all possible full-length permutations 
+   are generated.
+
+   Permutations are emitted in lexicographic sort order.  So, if the 
+   input *iterable* is sorted, the permutation tuples will be produced
+   in sorted order.  
+
+   Elements are treated as unique based on their position, not on their
+   value.  So if the input elements are unique, there will be no repeat
+   values in each permutation.
+
+   Equivalent to::
+
+        def permutations(iterable, r=None):
+            # permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC
+            # permutations(range(3)) --> 012 021 102 120 201 210
+            pool = tuple(iterable)
+            n = len(pool)
+            r = n if r is None else r
+            indices = range(n)
+            cycles = range(n, n-r, -1)
+            yield tuple(pool[i] for i in indices[:r])
+            while n:
+                for i in reversed(range(r)):
+                    cycles[i] -= 1
+                    if cycles[i] == 0:
+                        indices[i:] = indices[i+1:] + indices[i:i+1]
+                        cycles[i] = n - i
+                    else:
+                        j = cycles[i]
+                        indices[i], indices[-j] = indices[-j], indices[i]
+                        yield tuple(pool[i] for i in indices[:r])
+                        break
+                else:
+                    return
+
+   The code for :func:`permutations` can be also expressed as a subsequence of 
+   :func:`product`, filtered to exclude entries with repeated elements (those
+   from the same position in the input pool)::
+
+        def permutations(iterable, r=None):
+            pool = tuple(iterable)
+            n = len(pool)
+            r = n if r is None else r
+            for indices in product(range(n), repeat=r):
+                if len(set(indices)) == r:
+                    yield tuple(pool[i] for i in indices)
+
+   .. versionadded:: 2.6
+
+.. function:: product(*iterables[, repeat])
+
+   Cartesian product of input iterables.
+
+   Equivalent to nested for-loops in a generator expression. For example,
+   ``product(A, B)`` returns the same as ``((x,y) for x in A for y in B)``.
+
+   The leftmost iterators correspond to the outermost for-loop, so the output
+   tuples cycle like an odometer (with the rightmost element changing on every 
+   iteration).  This results in a lexicographic ordering so that if the 
+   inputs iterables are sorted, the product tuples are emitted
+   in sorted order.
+
+   To compute the product of an iterable with itself, specify the number of
+   repetitions with the optional *repeat* keyword argument.  For example,
+   ``product(A, repeat=4)`` means the same as ``product(A, A, A, A)``.
+
+   This function is equivalent to the following code, except that the
+   actual implementation does not build up intermediate results in memory::
+
+       def product(*args, repeat=1):
+           # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
+           # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
+           pools = map(tuple, args) * repeat
+           result = [[]]
+           for pool in pools:
+               result = [x+[y] for x in result for y in pool]
+           for prod in result:
+               yield tuple(prod)
+
+
 .. function:: repeat(object[, times])
 
    Make an iterator that returns *object* over and over again. Runs indefinitely
-   unless the *times* argument is specified. Used as argument to :func:`imap` for
-   invariant parameters to the called function.  Also used with :func:`izip` to
+   unless the *times* argument is specified. Used as argument to :func:`map` for
+   invariant parameters to the called function.  Also used with :func:`zip` to
    create an invariant part of a tuple record.  Equivalent to::
 
       def repeat(object, times=None):
+          # repeat(10, 3) --> 10 10 10
           if times is None:
               while True:
                   yield object
@@ -323,16 +418,20 @@
 
 .. function:: starmap(function, iterable)
 
-   Make an iterator that computes the function using arguments tuples obtained from
-   the iterable.  Used instead of :func:`imap` when argument parameters are already
+   Make an iterator that computes the function using arguments obtained from
+   the iterable.  Used instead of :func:`map` when argument parameters are already
    grouped in tuples from a single iterable (the data has been "pre-zipped").  The
-   difference between :func:`imap` and :func:`starmap` parallels the distinction
+   difference between :func:`map` and :func:`starmap` parallels the distinction
    between ``function(a,b)`` and ``function(*c)``. Equivalent to::
 
       def starmap(function, iterable):
-          iterable = iter(iterable)
-          while True:
-              yield function(*next(iterable))
+          # starmap(pow, [(2,5), (3,2), (10,3)]) --> 32 9 1000
+          for args in iterable:
+              yield function(*args)
+
+   .. versionchanged:: 2.6
+      Previously, :func:`starmap` required the function arguments to be tuples.
+      Now, any iterable is allowed.
 
 
 .. function:: takewhile(predicate, iterable)
@@ -341,6 +440,7 @@
    predicate is true.  Equivalent to::
 
       def takewhile(predicate, iterable):
+          # takewhile(lambda x: x<5, [1,4,6,4,1]) --> 1 4
           for x in iterable:
               if predicate(x):
                   yield x
@@ -354,14 +454,13 @@
    is equivalent to::
 
       def tee(iterable):
-          def gen(next, data={}, cnt=[0]):
+          def gen(next, data={}):
               for i in count():
-                  if i == cnt[0]:
-                      item = data[i] = next()
-                      cnt[0] += 1
+                  if i in data:
+                      yield data.pop(i)
                   else:
-                      item = data.pop(i)
-                  yield item
+                      data[i] = next()
+                      yield data[i]
           it = iter(iterable)
           return (gen(it.__next__), gen(it.__next__))
 
@@ -381,35 +480,9 @@
 --------
 
 The following examples show common uses for each tool and demonstrate ways they
-can be combined. ::
+can be combined.
 
-   >>> amounts = [120.15, 764.05, 823.14]
-   >>> for checknum, amount in izip(count(1200), amounts):
-   ...     print('Check %d is for $%.2f' % (checknum, amount))
-   ...
-   Check 1200 is for $120.15
-   Check 1201 is for $764.05
-   Check 1202 is for $823.14
-
-   >>> import operator
-   >>> for cube in imap(operator.pow, range(1,5), repeat(3)):
-   ...    print(cube)
-   ...
-   1
-   8
-   27
-   64
-
-   >>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura',
-   ...                '', 'martin', '', 'walter', '', 'mark']
-   >>> for name in islice(reportlines, 3, None, 2):
-   ...    print(name.title())
-   ...
-   Alex
-   Laura
-   Martin
-   Walter
-   Mark
+.. doctest::
 
    # Show a dictionary sorted and grouped by value
    >>> from operator import itemgetter
@@ -451,44 +524,49 @@
 rather than bringing the whole iterable into memory all at once. Code volume is
 kept small by linking the tools together in a functional style which helps
 eliminate temporary variables.  High speed is retained by preferring
-"vectorized" building blocks over the use of for-loops and generators which
-incur interpreter overhead. ::
+"vectorized" building blocks over the use of for-loops and :term:`generator`\s
+which incur interpreter overhead.
+
+.. testcode::
 
    def take(n, seq):
        return list(islice(seq, n))
 
    def enumerate(iterable):
-       return izip(count(), iterable)
+       return zip(count(), iterable)
 
    def tabulate(function):
        "Return function(0), function(1), ..."
-       return imap(function, count())
+       return map(function, count())
+
+   def items(mapping):
+       return zip(mapping.keys(), mapping.values())
 
    def nth(iterable, n):
        "Returns the nth item or raise StopIteration"
-       return islice(iterable, n, None).next()
+       return next(islice(iterable, n, None))
 
    def all(seq, pred=None):
        "Returns True if pred(x) is true for every element in the iterable"
-       for elem in ifilterfalse(pred, seq):
+       for elem in filterfalse(pred, seq):
            return False
        return True
 
    def any(seq, pred=None):
        "Returns True if pred(x) is true for at least one element in the iterable"
-       for elem in ifilter(pred, seq):
+       for elem in filter(pred, seq):
            return True
        return False
 
    def no(seq, pred=None):
        "Returns True if pred(x) is false for every element in the iterable"
-       for elem in ifilter(pred, seq):
+       for elem in filter(pred, seq):
            return False
        return True
 
    def quantify(seq, pred=None):
        "Count how many times the predicate is true in the sequence"
-       return sum(imap(pred, seq))
+       return sum(map(pred, seq))
 
    def padnone(seq):
        """Returns the sequence elements and then returns None indefinitely.
@@ -499,13 +577,13 @@
 
    def ncycles(seq, n):
        "Returns the sequence elements n times"
-       return chain(*repeat(seq, n))
+       return chain.from_iterable(repeat(seq, n))
 
    def dotproduct(vec1, vec2):
-       return sum(imap(operator.mul, vec1, vec2))
+       return sum(map(operator.mul, vec1, vec2))
 
    def flatten(listOfLists):
-       return list(chain(*listOfLists))
+       return list(chain.from_iterable(listOfLists))
 
    def repeatfunc(func, times=None, *args):
        """Repeat calls to func with specified arguments.
@@ -514,18 +592,43 @@
        """
        if times is None:
            return starmap(func, repeat(args))
-       else:
-           return starmap(func, repeat(args, times))
+       return starmap(func, repeat(args, times))
 
    def pairwise(iterable):
        "s -> (s0,s1), (s1,s2), (s2, s3), ..."
        a, b = tee(iterable)
-       next(b, None)
-       return izip(a, b)
+       for elem in b:
+           break
+       return zip(a, b)
 
-   def grouper(n, iterable, padvalue=None):
+   def grouper(n, iterable, fillvalue=None):
        "grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
-       return izip(*[chain(iterable, repeat(padvalue, n-1))]*n)
-
+       args = [iter(iterable)] * n
+       return zip_longest(*args, fillvalue=fillvalue)
 
+   def roundrobin(*iterables):
+       "roundrobin('abc', 'd', 'ef') --> 'a', 'd', 'e', 'b', 'f', 'c'"
+       # Recipe credited to George Sakkis
+       pending = len(iterables)
+       nexts = cycle(iter(it).__next__ for it in iterables)
+       while pending:
+           try:
+               for next in nexts:
+                   yield next()
+           except StopIteration:
+               pending -= 1
+               nexts = cycle(islice(nexts, pending))
+
+   def powerset(iterable):
+       "powerset('ab') --> set([]), set(['a']), set(['b']), set(['a', 'b'])"
+       # Recipe credited to Eric Raymond
+       pairs = [(2**i, x) for i, x in enumerate(iterable)]
+       for n in xrange(2**len(pairs)):
+           yield set(x for m, x in pairs if m&n)
+
+   def compress(data, selectors):
+       "compress('abcdef', [1,0,1,0,1,1]) --> a c e f"
+       for d, s in zip(data, selectors):
+           if s:
+               yield d
 

Modified: python/branches/py3k-importlib/Doc/library/logging.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/logging.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/logging.rst	Thu Mar 27 00:48:05 2008
@@ -9,10 +9,6 @@
 .. sectionauthor:: Vinay Sajip <vinay_sajip at red-dove.com>
 
 
-.. % These apply to all modules, and may be given more than once:
-
-
-
 .. index:: pair: Errors; logging
 
 This module defines functions and classes which implement a flexible error
@@ -20,7 +16,7 @@
 
 Logging is performed by calling methods on instances of the :class:`Logger`
 class (hereafter called :dfn:`loggers`). Each instance has a name, and they are
-conceptually arranged in a name space hierarchy using dots (periods) as
+conceptually arranged in a namespace hierarchy using dots (periods) as
 separators. For example, a logger named "scan" is the parent of loggers
 "scan.text", "scan.html" and "scan.pdf". Logger names can be anything you want,
 and indicate the area of an application in which a logged message originates.
@@ -34,6 +30,400 @@
 constrained to use these levels: you can specify your own and use a more general
 :class:`Logger` method, :meth:`log`, which takes an explicit level argument.
 
+
+Logging tutorial
+----------------
+
+The key benefit of having the logging API provided by a standard library module
+is that all Python modules can participate in logging, so your application log
+can include messages from third-party modules.
+
+It is, of course, possible to log messages with different verbosity levels or to
+different destinations.  Support for writing log messages to files, HTTP
+GET/POST locations, email via SMTP, generic sockets, or OS-specific logging
+mechanisms are all supported by the standard module.  You can also create your
+own log destination class if you have special requirements not met by any of the
+built-in classes.
+
+Simple examples
+^^^^^^^^^^^^^^^
+
+.. sectionauthor:: Doug Hellmann
+.. (see <http://blog.doughellmann.com/2007/05/pymotw-logging.html>)
+
+Most applications are probably going to want to log to a file, so let's start
+with that case. Using the :func:`basicConfig` function, we can set up the
+default handler so that debug messages are written to a file::
+
+   import logging
+   LOG_FILENAME = '/tmp/logging_example.out'
+   logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,)
+
+   logging.debug('This message should go to the log file')
+
+And now if we open the file and look at what we have, we should find the log
+message::
+
+   DEBUG:root:This message should go to the log file
+
+If you run the script repeatedly, the additional log messages are appended to
+the file.  To create a new file each time, you can pass a filemode argument to
+:func:`basicConfig` with a value of ``'w'``.  Rather than managing the file size
+yourself, though, it is simpler to use a :class:`RotatingFileHandler`::
+
+   import glob
+   import logging
+   import logging.handlers
+
+   LOG_FILENAME = '/tmp/logging_rotatingfile_example.out'
+
+   # Set up a specific logger with our desired output level
+   my_logger = logging.getLogger('MyLogger')
+   my_logger.setLevel(logging.DEBUG)
+
+   # Add the log message handler to the logger
+   handler = logging.handlers.RotatingFileHandler(
+                 LOG_FILENAME, maxBytes=20, backupCount=5)
+
+   my_logger.addHandler(handler)
+
+   # Log some messages
+   for i in range(20):
+       my_logger.debug('i = %d' % i)
+
+   # See what files are created
+   logfiles = glob.glob('%s*' % LOG_FILENAME)
+
+   for filename in logfiles:
+       print(filename)
+
+The result should be 6 separate files, each with part of the log history for the
+application::
+
+   /tmp/logging_rotatingfile_example.out
+   /tmp/logging_rotatingfile_example.out.1
+   /tmp/logging_rotatingfile_example.out.2
+   /tmp/logging_rotatingfile_example.out.3
+   /tmp/logging_rotatingfile_example.out.4
+   /tmp/logging_rotatingfile_example.out.5
+
+The most current file is always :file:`/tmp/logging_rotatingfile_example.out`,
+and each time it reaches the size limit it is renamed with the suffix
+``.1``. Each of the existing backup files is renamed to increment the suffix
+(``.1`` becomes ``.2``, etc.)  and the ``.5`` file is erased.
+
+Obviously this example sets the log length much much too small as an extreme
+example.  You would want to set *maxBytes* to an appropriate value.
+
+Another useful feature of the logging API is the ability to produce different
+messages at different log levels.  This allows you to instrument your code with
+debug messages, for example, but turning the log level down so that those debug
+messages are not written for your production system.  The default levels are
+``CRITICAL``, ``ERROR``, ``WARNING``, ``INFO``, ``DEBUG`` and ``UNSET``.
+
+The logger, handler, and log message call each specify a level.  The log message
+is only emitted if the handler and logger are configured to emit messages of
+that level or lower.  For example, if a message is ``CRITICAL``, and the logger
+is set to ``ERROR``, the message is emitted.  If a message is a ``WARNING``, and
+the logger is set to produce only ``ERROR``\s, the message is not emitted::
+
+   import logging
+   import sys
+
+   LEVELS = {'debug': logging.DEBUG,
+             'info': logging.INFO,
+             'warning': logging.WARNING,
+             'error': logging.ERROR,
+             'critical': logging.CRITICAL}
+
+   if len(sys.argv) > 1:
+       level_name = sys.argv[1]
+       level = LEVELS.get(level_name, logging.NOTSET)
+       logging.basicConfig(level=level)
+
+   logging.debug('This is a debug message')
+   logging.info('This is an info message')
+   logging.warning('This is a warning message')
+   logging.error('This is an error message')
+   logging.critical('This is a critical error message')
+
+Run the script with an argument like 'debug' or 'warning' to see which messages
+show up at different levels::
+
+   $ python logging_level_example.py debug
+   DEBUG:root:This is a debug message
+   INFO:root:This is an info message
+   WARNING:root:This is a warning message
+   ERROR:root:This is an error message
+   CRITICAL:root:This is a critical error message
+
+   $ python logging_level_example.py info
+   INFO:root:This is an info message
+   WARNING:root:This is a warning message
+   ERROR:root:This is an error message
+   CRITICAL:root:This is a critical error message
+
+You will notice that these log messages all have ``root`` embedded in them.  The
+logging module supports a hierarchy of loggers with different names.  An easy
+way to tell where a specific log message comes from is to use a separate logger
+object for each of your modules.  Each new logger "inherits" the configuration
+of its parent, and log messages sent to a logger include the name of that
+logger.  Optionally, each logger can be configured differently, so that messages
+from different modules are handled in different ways.  Let's look at a simple
+example of how to log from different modules so it is easy to trace the source
+of the message::
+
+   import logging
+
+   logging.basicConfig(level=logging.WARNING)
+
+   logger1 = logging.getLogger('package1.module1')
+   logger2 = logging.getLogger('package2.module2')
+
+   logger1.warning('This message comes from one module')
+   logger2.warning('And this message comes from another module')
+
+And the output::
+
+   $ python logging_modules_example.py
+   WARNING:package1.module1:This message comes from one module
+   WARNING:package2.module2:And this message comes from another module
+
+There are many more options for configuring logging, including different log
+message formatting options, having messages delivered to multiple destinations,
+and changing the configuration of a long-running application on the fly using a
+socket interface.  All of these options are covered in depth in the library
+module documentation.
+
+Loggers
+^^^^^^^
+
+The logging library takes a modular approach and offers the several categories
+of components: loggers, handlers, filters, and formatters.  Loggers expose the
+interface that application code directly uses.  Handlers send the log records to
+the appropriate destination. Filters provide a finer grained facility for
+determining which log records to send on to a handler.  Formatters specify the
+layout of the resultant log record.
+
+:class:`Logger` objects have a threefold job.  First, they expose several
+methods to application code so that applications can log messages at runtime.
+Second, logger objects determine which log messages to act upon based upon
+severity (the default filtering facility) or filter objects.  Third, logger
+objects pass along relevant log messages to all interested log handlers.
+
+The most widely used methods on logger objects fall into two categories:
+configuration and message sending.
+
+* :meth:`Logger.setLevel` specifies the lowest-severity log message a logger
+  will handle, where debug is the lowest built-in severity level and critical is
+  the highest built-in severity.  For example, if the severity level is info,
+  the logger will handle only info, warning, error, and critical messages and
+  will ignore debug messages.
+
+* :meth:`Logger.addFilter` and :meth:`Logger.removeFilter` add and remove filter
+  objects from the logger object.  This tutorial does not address filters.
+
+With the logger object configured, the following methods create log messages:
+
+* :meth:`Logger.debug`, :meth:`Logger.info`, :meth:`Logger.warning`,
+  :meth:`Logger.error`, and :meth:`Logger.critical` all create log records with
+  a message and a level that corresponds to their respective method names. The
+  message is actually a format string, which may contain the standard string
+  substitution syntax of :const:`%s`, :const:`%d`, :const:`%f`, and so on.  The
+  rest of their arguments is a list of objects that correspond with the
+  substitution fields in the message.  With regard to :const:`**kwargs`, the
+  logging methods care only about a keyword of :const:`exc_info` and use it to
+  determine whether to log exception information.
+
+* :meth:`Logger.exception` creates a log message similar to
+  :meth:`Logger.error`.  The difference is that :meth:`Logger.exception` dumps a
+  stack trace along with it.  Call this method only from an exception handler.
+
+* :meth:`Logger.log` takes a log level as an explicit argument.  This is a
+  little more verbose for logging messages than using the log level convenience
+  methods listed above, but this is how to log at custom log levels.
+
+:func:`getLogger` returns a reference to a logger instance with the specified
+if it it is provided, or ``root`` if not.  The names are period-separated
+hierarchical structures.  Multiple calls to :func:`getLogger` with the same name
+will return a reference to the same logger object.  Loggers that are further
+down in the hierarchical list are children of loggers higher up in the list.
+For example, given a logger with a name of ``foo``, loggers with names of
+``foo.bar``, ``foo.bar.baz``, and ``foo.bam`` are all children of ``foo``.
+Child loggers propagate messages up to their parent loggers.  Because of this,
+it is unnecessary to define and configure all the loggers an application uses.
+It is sufficient to configure a top-level logger and create child loggers as
+needed.
+
+
+Handlers
+^^^^^^^^
+
+:class:`Handler` objects are responsible for dispatching the appropriate log
+messages (based on the log messages' severity) to the handler's specified
+destination.  Logger objects can add zero or more handler objects to themselves
+with an :func:`addHandler` method.  As an example scenario, an application may
+want to send all log messages to a log file, all log messages of error or higher
+to stdout, and all messages of critical to an email address.  This scenario
+requires three individual handlers where each handler is responsible for sending
+messages of a specific severity to a specific location.
+
+The standard library includes quite a few handler types; this tutorial uses only
+:class:`StreamHandler` and :class:`FileHandler` in its examples.
+
+There are very few methods in a handler for application developers to concern
+themselves with.  The only handler methods that seem relevant for application
+developers who are using the built-in handler objects (that is, not creating
+custom handlers) are the following configuration methods:
+
+* The :meth:`Handler.setLevel` method, just as in logger objects, specifies the
+  lowest severity that will be dispatched to the appropriate destination.  Why
+  are there two :func:`setLevel` methods?  The level set in the logger
+  determines which severity of messages it will pass to its handlers.  The level
+  set in each handler determines which messages that handler will send on.
+  :func:`setFormatter` selects a Formatter object for this handler to use.
+
+* :func:`addFilter` and :func:`removeFilter` respectively configure and
+  deconfigure filter objects on handlers.
+
+Application code should not directly instantiate and use handlers.  Instead, the
+:class:`Handler` class is a base class that defines the interface that all
+Handlers should have and establishes some default behavior that child classes
+can use (or override).
+
+
+Formatters
+^^^^^^^^^^
+
+Formatter objects configure the final order, structure, and contents of the log
+message.  Unlike the base :class:`logging.Handler` class, application code may
+instantiate formatter classes, although you could likely subclass the formatter
+if your application needs special behavior.  The constructor takes two optional
+arguments: a message format string and a date format string.  If there is no
+message format string, the default is to use the raw message.  If there is no
+date format string, the default date format is::
+
+    %Y-%m-%d %H:%M:%S
+
+with the milliseconds tacked on at the end.
+
+The message format string uses ``%(<dictionary key>)s`` styled string
+substitution; the possible keys are documented in :ref:`formatter-objects`.
+
+The following message format string will log the time in a human-readable
+format, the severity of the message, and the contents of the message, in that
+order::
+
+    "%(asctime)s - %(levelname)s - %(message)s"
+
+
+Configuring Logging
+^^^^^^^^^^^^^^^^^^^
+
+Programmers can configure logging either by creating loggers, handlers, and
+formatters explicitly in a main module with the configuration methods listed
+above (using Python code), or by creating a logging config file.  The following
+code is an example of configuring a very simple logger, a console handler, and a
+simple formatter in a Python module::
+
+    import logging
+
+    # create logger
+    logger = logging.getLogger("simple_example")
+    logger.setLevel(logging.DEBUG)
+    # create console handler and set level to debug
+    ch = logging.StreamHandler()
+    ch.setLevel(logging.DEBUG)
+    # create formatter
+    formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
+    # add formatter to ch
+    ch.setFormatter(formatter)
+    # add ch to logger
+    logger.addHandler(ch)
+
+    # "application" code
+    logger.debug("debug message")
+    logger.info("info message")
+    logger.warn("warn message")
+    logger.error("error message")
+    logger.critical("critical message")
+
+Running this module from the command line produces the following output::
+
+    $ python simple_logging_module.py
+    2005-03-19 15:10:26,618 - simple_example - DEBUG - debug message
+    2005-03-19 15:10:26,620 - simple_example - INFO - info message
+    2005-03-19 15:10:26,695 - simple_example - WARNING - warn message
+    2005-03-19 15:10:26,697 - simple_example - ERROR - error message
+    2005-03-19 15:10:26,773 - simple_example - CRITICAL - critical message
+
+The following Python module creates a logger, handler, and formatter nearly
+identical to those in the example listed above, with the only difference being
+the names of the objects::
+
+    import logging
+    import logging.config
+
+    logging.config.fileConfig("logging.conf")
+
+    # create logger
+    logger = logging.getLogger("simpleExample")
+
+    # "application" code
+    logger.debug("debug message")
+    logger.info("info message")
+    logger.warn("warn message")
+    logger.error("error message")
+    logger.critical("critical message")
+
+Here is the logging.conf file::
+
+    [loggers]
+    keys=root,simpleExample
+
+    [handlers]
+    keys=consoleHandler
+
+    [formatters]
+    keys=simpleFormatter
+
+    [logger_root]
+    level=DEBUG
+    handlers=consoleHandler
+
+    [logger_simpleExample]
+    level=DEBUG
+    handlers=consoleHandler
+    qualname=simpleExample
+    propagate=0
+
+    [handler_consoleHandler]
+    class=StreamHandler
+    level=DEBUG
+    formatter=simpleFormatter
+    args=(sys.stdout,)
+
+    [formatter_simpleFormatter]
+    format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
+    datefmt=
+
+The output is nearly identical to that of the non-config-file-based example::
+
+    $ python simple_logging_config.py
+    2005-03-19 15:38:55,977 - simpleExample - DEBUG - debug message
+    2005-03-19 15:38:55,979 - simpleExample - INFO - info message
+    2005-03-19 15:38:56,054 - simpleExample - WARNING - warn message
+    2005-03-19 15:38:56,055 - simpleExample - ERROR - error message
+    2005-03-19 15:38:56,130 - simpleExample - CRITICAL - critical message
+
+You can see that the config file approach has a few advantages over the Python
+code approach, mainly separation of configuration and code and the ability of
+noncoders to easily modify the logging properties.
+
+
+Logging Levels
+--------------
+
 The numeric values of logging levels are given in the following table. These are
 primarily of interest if you want to define your own levels, and need them to
 have specific values relative to the predefined levels. If you define a level
@@ -298,7 +688,8 @@
 
    Does basic configuration for the logging system by creating a
    :class:`StreamHandler` with a default :class:`Formatter` and adding it to the
-   root logger. The functions :func:`debug`, :func:`info`, :func:`warning`,
+   root logger. The function does nothing if any handlers have been defined for
+   the root logger. The functions :func:`debug`, :func:`info`, :func:`warning`,
    :func:`error` and :func:`critical` will call :func:`basicConfig` automatically
    if no handlers are defined for the root logger.
 
@@ -333,7 +724,8 @@
 .. function:: shutdown()
 
    Informs the logging system to perform an orderly shutdown by flushing and
-   closing all handlers.
+   closing all handlers. This should be called at application exit and no
+   further use of the logging system should be made after this call.
 
 
 .. function:: setLoggerClass(klass)
@@ -351,7 +743,7 @@
       The proposal which described this feature for inclusion in the Python standard
       library.
 
-   `Original Python :mod:`logging` package <http://www.red-dove.com/python_logging.html>`_
+   `Original Python logging package <http://www.red-dove.com/python_logging.html>`_
       This is the original source for the :mod:`logging` package.  The version of the
       package available from this site is suitable for use with Python 1.5.2, 2.1.x
       and 2.2.x, which do not include the :mod:`logging` package in the standard
@@ -430,7 +822,7 @@
 
       FORMAT = "%(asctime)-15s %(clientip)s %(user)-8s %(message)s"
       logging.basicConfig(format=FORMAT)
-      dict = { 'clientip' : '192.168.0.1', 'user' : 'fbloggs' }
+      d = { 'clientip' : '192.168.0.1', 'user' : 'fbloggs' }
       logger = logging.getLogger("tcpserver")
       logger.warning("Protocol problem: %s", "connection reset", extra=d)
 
@@ -727,6 +1119,132 @@
 combination of handlers you choose.
 
 
+.. _context-info:
+
+Adding contextual information to your logging output
+----------------------------------------------------
+
+Sometimes you want logging output to contain contextual information in
+addition to the parameters passed to the logging call. For example, in a
+networked application, it may be desirable to log client-specific information
+in the log (e.g. remote client's username, or IP address). Although you could
+use the *extra* parameter to achieve this, it's not always convenient to pass
+the information in this way. While it might be tempting to create
+:class:`Logger` instances on a per-connection basis, this is not a good idea
+because these instances are not garbage collected. While this is not a problem
+in practice, when the number of :class:`Logger` instances is dependent on the
+level of granularity you want to use in logging an application, it could
+be hard to manage if the number of :class:`Logger` instances becomes
+effectively unbounded.
+
+An easy way in which you can pass contextual information to be output along
+with logging event information is to use the :class:`LoggerAdapter` class.
+This class is designed to look like a :class:`Logger`, so that you can call
+:meth:`debug`, :meth:`info`, :meth:`warning`, :meth:`error`,
+:meth:`exception`, :meth:`critical` and :meth:`log`. These methods have the
+same signatures as their counterparts in :class:`Logger`, so you can use the
+two types of instances interchangeably.
+
+When you create an instance of :class:`LoggerAdapter`, you pass it a
+:class:`Logger` instance and a dict-like object which contains your contextual
+information. When you call one of the logging methods on an instance of
+:class:`LoggerAdapter`, it delegates the call to the underlying instance of
+:class:`Logger` passed to its constructor, and arranges to pass the contextual
+information in the delegated call. Here's a snippet from the code of
+:class:`LoggerAdapter`::
+
+    def debug(self, msg, *args, **kwargs):
+        """
+        Delegate a debug call to the underlying logger, after adding
+        contextual information from this adapter instance.
+        """
+        msg, kwargs = self.process(msg, kwargs)
+        self.logger.debug(msg, *args, **kwargs)
+
+The :meth:`process` method of :class:`LoggerAdapter` is where the contextual
+information is added to the logging output. It's passed the message and
+keyword arguments of the logging call, and it passes back (potentially)
+modified versions of these to use in the call to the underlying logger. The
+default implementation of this method leaves the message alone, but inserts
+an "extra" key in the keyword argument whose value is the dict-like object
+passed to the constructor. Of course, if you had passed an "extra" keyword
+argument in the call to the adapter, it will be silently overwritten.
+
+The advantage of using "extra" is that the values in the dict-like object are
+merged into the :class:`LogRecord` instance's __dict__, allowing you to use
+customized strings with your :class:`Formatter` instances which know about
+the keys of the dict-like object. If you need a different method, e.g. if you
+want to prepend or append the contextual information to the message string,
+you just need to subclass :class:`LoggerAdapter` and override :meth:`process`
+to do what you need. Here's an example script which uses this class, which
+also illustrates what dict-like behaviour is needed from an arbitrary
+"dict-like" object for use in the constructor::
+
+   import logging
+
+   class ConnInfo:
+       """
+       An example class which shows how an arbitrary class can be used as
+       the 'extra' context information repository passed to a LoggerAdapter.
+       """
+
+       def __getitem__(self, name):
+           """
+           To allow this instance to look like a dict.
+           """
+           from random import choice
+           if name == "ip":
+               result = choice(["127.0.0.1", "192.168.0.1"])
+           elif name == "user":
+               result = choice(["jim", "fred", "sheila"])
+           else:
+               result = self.__dict__.get(name, "?")
+           return result
+
+       def __iter__(self):
+           """
+           To allow iteration over keys, which will be merged into
+           the LogRecord dict before formatting and output.
+           """
+           keys = ["ip", "user"]
+           keys.extend(self.__dict__.keys())
+           return keys.__iter__()
+
+   if __name__ == "__main__":
+       from random import choice
+       levels = (logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL)
+       a1 = logging.LoggerAdapter(logging.getLogger("a.b.c"),
+                                  { "ip" : "123.231.231.123", "user" : "sheila" })
+       logging.basicConfig(level=logging.DEBUG,
+                           format="%(asctime)-15s %(name)-5s %(levelname)-8s IP: %(ip)-15s User: %(user)-8s %(message)s")
+       a1.debug("A debug message")
+       a1.info("An info message with %s", "some parameters")
+       a2 = logging.LoggerAdapter(logging.getLogger("d.e.f"), ConnInfo())
+       for x in range(10):
+           lvl = choice(levels)
+           lvlname = logging.getLevelName(lvl)
+           a2.log(lvl, "A message at %s level with %d %s", lvlname, 2, "parameters")
+
+When this script is run, the output should look something like this::
+
+   2008-01-18 14:49:54,023 a.b.c DEBUG    IP: 123.231.231.123 User: sheila   A debug message
+   2008-01-18 14:49:54,023 a.b.c INFO     IP: 123.231.231.123 User: sheila   An info message with some parameters
+   2008-01-18 14:49:54,023 d.e.f CRITICAL IP: 192.168.0.1     User: jim      A message at CRITICAL level with 2 parameters
+   2008-01-18 14:49:54,033 d.e.f INFO     IP: 192.168.0.1     User: jim      A message at INFO level with 2 parameters
+   2008-01-18 14:49:54,033 d.e.f WARNING  IP: 192.168.0.1     User: sheila   A message at WARNING level with 2 parameters
+   2008-01-18 14:49:54,033 d.e.f ERROR    IP: 127.0.0.1       User: fred     A message at ERROR level with 2 parameters
+   2008-01-18 14:49:54,033 d.e.f ERROR    IP: 127.0.0.1       User: sheila   A message at ERROR level with 2 parameters
+   2008-01-18 14:49:54,033 d.e.f WARNING  IP: 192.168.0.1     User: sheila   A message at WARNING level with 2 parameters
+   2008-01-18 14:49:54,033 d.e.f WARNING  IP: 192.168.0.1     User: jim      A message at WARNING level with 2 parameters
+   2008-01-18 14:49:54,033 d.e.f INFO     IP: 192.168.0.1     User: fred     A message at INFO level with 2 parameters
+   2008-01-18 14:49:54,033 d.e.f WARNING  IP: 192.168.0.1     User: sheila   A message at WARNING level with 2 parameters
+   2008-01-18 14:49:54,033 d.e.f WARNING  IP: 127.0.0.1       User: jim      A message at WARNING level with 2 parameters
+
+.. versionadded:: 2.6
+
+The :class:`LoggerAdapter` class was not present in previous versions.
+
+
 .. _network-logging:
 
 Sending and receiving logging events across a network
@@ -1000,12 +1518,13 @@
 :class:`StreamHandler`.
 
 
-.. class:: FileHandler(filename[, mode[, encoding]])
+.. class:: FileHandler(filename[, mode[, encoding[, delay]]])
 
    Returns a new instance of the :class:`FileHandler` class. The specified file is
    opened and used as the stream for logging. If *mode* is not specified,
    :const:`'a'` is used.  If *encoding* is not *None*, it is used to open the file
-   with that encoding.  By default, the file grows indefinitely.
+   with that encoding.  If *delay* is true, then file opening is deferred until the
+   first call to :meth:`emit`. By default, the file grows indefinitely.
 
 
 .. method:: FileHandler.close()
@@ -1039,12 +1558,13 @@
 this value.
 
 
-.. class:: WatchedFileHandler(filename[,mode[, encoding]])
+.. class:: WatchedFileHandler(filename[,mode[, encoding[, delay]]])
 
    Returns a new instance of the :class:`WatchedFileHandler` class. The specified
    file is opened and used as the stream for logging. If *mode* is not specified,
    :const:`'a'` is used.  If *encoding* is not *None*, it is used to open the file
-   with that encoding.  By default, the file grows indefinitely.
+   with that encoding.  If *delay* is true, then file opening is deferred until the
+   first call to :meth:`emit`.  By default, the file grows indefinitely.
 
 
 .. method:: WatchedFileHandler.emit(record)
@@ -1061,11 +1581,13 @@
 module, supports rotation of disk log files.
 
 
-.. class:: RotatingFileHandler(filename[, mode[, maxBytes[, backupCount]]])
+.. class:: RotatingFileHandler(filename[, mode[, maxBytes[, backupCount[, encoding[, delay]]]]])
 
    Returns a new instance of the :class:`RotatingFileHandler` class. The specified
    file is opened and used as the stream for logging. If *mode* is not specified,
-   ``'a'`` is used. By default, the file grows indefinitely.
+   ``'a'`` is used.  If *encoding* is not *None*, it is used to open the file
+   with that encoding.  If *delay* is true, then file opening is deferred until the
+   first call to :meth:`emit`.  By default, the file grows indefinitely.
 
    You can use the *maxBytes* and *backupCount* values to allow the file to
    :dfn:`rollover` at a predetermined size. When the size is about to be exceeded,
@@ -1099,7 +1621,7 @@
 timed intervals.
 
 
-.. class:: TimedRotatingFileHandler(filename [,when [,interval [,backupCount]]])
+.. class:: TimedRotatingFileHandler(filename [,when [,interval [,backupCount[, encoding[, delay]]]]])
 
    Returns a new instance of the :class:`TimedRotatingFileHandler` class. The
    specified file is opened and used as the stream for logging. On rotating it also
@@ -1109,27 +1631,28 @@
    You can use the *when* to specify the type of *interval*. The list of possible
    values is, note that they are not case sensitive:
 
-   +----------+-----------------------+
-   | Value    | Type of interval      |
-   +==========+=======================+
-   | S        | Seconds               |
-   +----------+-----------------------+
-   | M        | Minutes               |
-   +----------+-----------------------+
-   | H        | Hours                 |
-   +----------+-----------------------+
-   | D        | Days                  |
-   +----------+-----------------------+
-   | W        | Week day (0=Monday)   |
-   +----------+-----------------------+
-   | midnight | Roll over at midnight |
-   +----------+-----------------------+
-
-   If *backupCount* is non-zero, the system will save old log files by appending
-   extensions to the filename. The extensions are date-and-time based, using the
-   strftime format ``%Y-%m-%d_%H-%M-%S`` or a leading portion thereof, depending on
-   the rollover interval. At most *backupCount* files will be kept, and if more
-   would be created when rollover occurs, the oldest one is deleted.
+   +----------------+-----------------------+
+   | Value          | Type of interval      |
+   +================+=======================+
+   | ``'S'``        | Seconds               |
+   +----------------+-----------------------+
+   | ``'M'``        | Minutes               |
+   +----------------+-----------------------+
+   | ``'H'``        | Hours                 |
+   +----------------+-----------------------+
+   | ``'D'``        | Days                  |
+   +----------------+-----------------------+
+   | ``'W'``        | Week day (0=Monday)   |
+   +----------------+-----------------------+
+   | ``'midnight'`` | Roll over at midnight |
+   +----------------+-----------------------+
+
+   The system will save old log files by appending extensions to the filename.
+   The extensions are date-and-time based, using the strftime format
+   ``%Y-%m-%d_%H-%M-%S`` or a leading portion thereof, depending on the rollover
+   interval. If *backupCount* is nonzero, at most *backupCount* files will be
+   kept, and if more would be created when rollover occurs, the oldest one is
+   deleted.
 
 
 .. method:: TimedRotatingFileHandler.doRollover()
@@ -1446,6 +1969,8 @@
    Sends the record to the Web server as an URL-encoded dictionary.
 
 
+.. _formatter-objects:
+
 Formatter Objects
 -----------------
 
@@ -1534,7 +2059,13 @@
    record is computed using *msg* % *args*. If the formatting string contains
    ``'(asctime)'``, :meth:`formatTime` is called to format the event time. If there
    is exception information, it is formatted using :meth:`formatException` and
-   appended to the message.
+   appended to the message. Note that the formatted exception information is cached
+   in attribute *exc_text*. This is useful because the exception information can
+   be pickled and sent across the wire, but you should be careful if you have more
+   than one :class:`Formatter` subclass which customizes the formatting of exception
+   information. In this case, you will have to clear the cached value after a
+   formatter has done its formatting, so that the next formatter to handle the event
+   doesn't use the cached value but recalculates it afresh.
 
 
 .. method:: Formatter.formatTime(record[, datefmt])
@@ -1608,6 +2139,36 @@
    Returns the message for this :class:`LogRecord` instance after merging any
    user-supplied arguments with the message.
 
+LoggerAdapter Objects
+---------------------
+
+.. versionadded:: 2.6
+
+:class:`LoggerAdapter` instances are used to conveniently pass contextual
+information into logging calls. For a usage example , see the section on
+`adding contextual information to your logging output`__.
+
+__ context-info_
+
+.. class:: LoggerAdapter(logger, extra)
+
+  Returns an instance of :class:`LoggerAdapter` initialized with an
+  underlying :class:`Logger` instance and a dict-like object.
+
+.. method:: LoggerAdapter.process(msg, kwargs)
+
+  Modifies the message and/or keyword arguments passed to a logging call in
+  order to insert contextual information. This implementation takes the
+  object passed as *extra* to the constructor and adds it to *kwargs* using
+  key 'extra'. The return value is a (*msg*, *kwargs*) tuple which has the
+  (possibly modified) versions of the arguments passed in.
+
+In addition to the above, :class:`LoggerAdapter` supports all the logging
+methods of :class:`Logger`, i.e. :meth:`debug`, :meth:`info`, :meth:`warning`,
+:meth:`error`, :meth:`exception`, :meth:`critical` and :meth:`log`. These
+methods have the same signatures as their counterparts in :class:`Logger`, so
+you can use the two types of instances interchangeably.
+
 
 Thread Safety
 -------------
@@ -1627,8 +2188,6 @@
 Configuration functions
 ^^^^^^^^^^^^^^^^^^^^^^^
 
-.. % 
-
 The following functions configure the logging module. They are located in the
 :mod:`logging.config` module.  Their use is optional --- you can configure the
 logging module using these functions or by making calls to the main API (defined
@@ -1654,15 +2213,17 @@
    sent as a file suitable for processing by :func:`fileConfig`. Returns a
    :class:`Thread` instance on which you can call :meth:`start` to start the
    server, and which you can :meth:`join` when appropriate. To stop the server,
-   call :func:`stopListening`. To send a configuration to the socket, read in the
-   configuration file and send it to the socket as a string of bytes preceded by a
-   four-byte length packed in binary using struct.\ ``pack('>L', n)``.
+   call :func:`stopListening`.
+
+   To send a configuration to the socket, read in the configuration file and
+   send it to the socket as a string of bytes preceded by a four-byte length
+   string packed in binary using ``struct.pack('>L', n)``.
 
 
 .. function:: stopListening()
 
-   Stops the listening server which was created with a call to :func:`listen`. This
-   is typically called before calling :meth:`join` on the return value from
+   Stops the listening server which was created with a call to :func:`listen`.
+   This is typically called before calling :meth:`join` on the return value from
    :func:`listen`.
 
 
@@ -1671,8 +2232,6 @@
 Configuration file format
 ^^^^^^^^^^^^^^^^^^^^^^^^^
 
-.. % 
-
 The configuration file format understood by :func:`fileConfig` is based on
 ConfigParser functionality. The file must contain sections called ``[loggers]``,
 ``[handlers]`` and ``[formatters]`` which identify by name the entities of each
@@ -1812,16 +2371,206 @@
    class=logging.Formatter
 
 The ``format`` entry is the overall format string, and the ``datefmt`` entry is
-the :func:`strftime`\ -compatible date/time format string. If empty, the package
-substitutes ISO8601 format date/times, which is almost equivalent to specifying
-the date format string "The ISO8601 format also specifies milliseconds, which
-are appended to the result of using the above format string, with a comma
-separator. An example time in ISO8601 format is ``2003-01-23 00:29:50,411``.
-
-.. % Y-%m-%d %H:%M:%S".
+the :func:`strftime`\ -compatible date/time format string.  If empty, the
+package substitutes ISO8601 format date/times, which is almost equivalent to
+specifying the date format string ``"%Y-%m-%d %H:%M:%S"``.  The ISO8601 format
+also specifies milliseconds, which are appended to the result of using the above
+format string, with a comma separator.  An example time in ISO8601 format is
+``2003-01-23 00:29:50,411``.
 
 The ``class`` entry is optional.  It indicates the name of the formatter's class
 (as a dotted module and class name.)  This option is useful for instantiating a
 :class:`Formatter` subclass.  Subclasses of :class:`Formatter` can present
 exception tracebacks in an expanded or condensed format.
 
+
+Configuration server example
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Here is an example of a module using the logging configuration server::
+
+    import logging
+    import logging.config
+    import time
+    import os
+
+    # read initial config file
+    logging.config.fileConfig("logging.conf")
+
+    # create and start listener on port 9999
+    t = logging.config.listen(9999)
+    t.start()
+
+    logger = logging.getLogger("simpleExample")
+
+    try:
+        # loop through logging calls to see the difference
+        # new configurations make, until Ctrl+C is pressed
+        while True:
+            logger.debug("debug message")
+            logger.info("info message")
+            logger.warn("warn message")
+            logger.error("error message")
+            logger.critical("critical message")
+            time.sleep(5)
+    except KeyboardInterrupt:
+        # cleanup
+        logging.config.stopListening()
+        t.join()
+
+And here is a script that takes a filename and sends that file to the server,
+properly preceded with the binary-encoded length, as the new logging
+configuration::
+
+    #!/usr/bin/env python
+    import socket, sys, struct
+
+    data_to_send = open(sys.argv[1], "r").read()
+
+    HOST = 'localhost'
+    PORT = 9999
+    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    print("connecting...")
+    s.connect((HOST, PORT))
+    print("sending config...")
+    s.send(struct.pack(">L", len(data_to_send)))
+    s.send(data_to_send)
+    s.close()
+    print("complete")
+
+
+More examples
+-------------
+
+Multiple handlers and formatters
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Loggers are plain Python objects.  The :func:`addHandler` method has no minimum
+or maximum quota for the number of handlers you may add.  Sometimes it will be
+beneficial for an application to log all messages of all severities to a text
+file while simultaneously logging errors or above to the console.  To set this
+up, simply configure the appropriate handlers.  The logging calls in the
+application code will remain unchanged.  Here is a slight modification to the
+previous simple module-based configuration example::
+
+    import logging
+
+    logger = logging.getLogger("simple_example")
+    logger.setLevel(logging.DEBUG)
+    # create file handler which logs even debug messages
+    fh = logging.FileHandler("spam.log")
+    fh.setLevel(logging.DEBUG)
+    # create console handler with a higher log level
+    ch = logging.StreamHandler()
+    ch.setLevel(logging.ERROR)
+    # create formatter and add it to the handlers
+    formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
+    ch.setFormatter(formatter)
+    fh.setFormatter(formatter)
+    # add the handlers to logger
+    logger.addHandler(ch)
+    logger.addHandler(fh)
+
+    # "application" code
+    logger.debug("debug message")
+    logger.info("info message")
+    logger.warn("warn message")
+    logger.error("error message")
+    logger.critical("critical message")
+
+Notice that the "application" code does not care about multiple handlers.  All
+that changed was the addition and configuration of a new handler named *fh*.
+
+The ability to create new handlers with higher- or lower-severity filters can be
+very helpful when writing and testing an application.  Instead of using many
+``print`` statements for debugging, use ``logger.debug``: Unlike the print
+statements, which you will have to delete or comment out later, the logger.debug
+statements can remain intact in the source code and remain dormant until you
+need them again.  At that time, the only change that needs to happen is to
+modify the severity level of the logger and/or handler to debug.
+
+
+Using logging in multiple modules
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+It was mentioned above that multiple calls to
+``logging.getLogger('someLogger')`` return a reference to the same logger
+object.  This is true not only within the same module, but also across modules
+as long as it is in the same Python interpreter process.  It is true for
+references to the same object; additionally, application code can define and
+configure a parent logger in one module and create (but not configure) a child
+logger in a separate module, and all logger calls to the child will pass up to
+the parent.  Here is a main module::
+
+    import logging
+    import auxiliary_module
+
+    # create logger with "spam_application"
+    logger = logging.getLogger("spam_application")
+    logger.setLevel(logging.DEBUG)
+    # create file handler which logs even debug messages
+    fh = logging.FileHandler("spam.log")
+    fh.setLevel(logging.DEBUG)
+    # create console handler with a higher log level
+    ch = logging.StreamHandler()
+    ch.setLevel(logging.ERROR)
+    # create formatter and add it to the handlers
+    formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
+    fh.setFormatter(formatter)
+    ch.setFormatter(formatter)
+    # add the handlers to the logger
+    logger.addHandler(fh)
+    logger.addHandler(ch)
+
+    logger.info("creating an instance of auxiliary_module.Auxiliary")
+    a = auxiliary_module.Auxiliary()
+    logger.info("created an instance of auxiliary_module.Auxiliary")
+    logger.info("calling auxiliary_module.Auxiliary.do_something")
+    a.do_something()
+    logger.info("finished auxiliary_module.Auxiliary.do_something")
+    logger.info("calling auxiliary_module.some_function()")
+    auxiliary_module.some_function()
+    logger.info("done with auxiliary_module.some_function()")
+
+Here is the auxiliary module::
+
+    import logging
+
+    # create logger
+    module_logger = logging.getLogger("spam_application.auxiliary")
+
+    class Auxiliary:
+        def __init__(self):
+            self.logger = logging.getLogger("spam_application.auxiliary.Auxiliary")
+            self.logger.info("creating an instance of Auxiliary")
+        def do_something(self):
+            self.logger.info("doing something")
+            a = 1 + 1
+            self.logger.info("done doing something")
+
+    def some_function():
+        module_logger.info("received a call to \"some_function\"")
+
+The output looks like this::
+
+    2005-03-23 23:47:11,663 - spam_application - INFO -
+       creating an instance of auxiliary_module.Auxiliary
+    2005-03-23 23:47:11,665 - spam_application.auxiliary.Auxiliary - INFO -
+       creating an instance of Auxiliary
+    2005-03-23 23:47:11,665 - spam_application - INFO -
+       created an instance of auxiliary_module.Auxiliary
+    2005-03-23 23:47:11,668 - spam_application - INFO -
+       calling auxiliary_module.Auxiliary.do_something
+    2005-03-23 23:47:11,668 - spam_application.auxiliary.Auxiliary - INFO -
+       doing something
+    2005-03-23 23:47:11,669 - spam_application.auxiliary.Auxiliary - INFO -
+       done doing something
+    2005-03-23 23:47:11,670 - spam_application - INFO -
+       finished auxiliary_module.Auxiliary.do_something
+    2005-03-23 23:47:11,671 - spam_application - INFO -
+       calling auxiliary_module.some_function()
+    2005-03-23 23:47:11,672 - spam_application.auxiliary - INFO -
+       received a call to "some_function"
+    2005-03-23 23:47:11,673 - spam_application - INFO -
+       done with auxiliary_module.some_function()
+

Modified: python/branches/py3k-importlib/Doc/library/mailbox.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/mailbox.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/mailbox.rst	Thu Mar 27 00:48:05 2008
@@ -403,7 +403,7 @@
       Notes on Maildir by its inventor. Includes an updated name-creation scheme and
       details on "info" semantics.
 
-   `maildir man page from Courier <http://www.courier-mta.org/?maildir.html>`_
+   `maildir man page from Courier <http://www.courier-mta.org/maildir.html>`_
       Another specification of the format. Describes a common extension for supporting
       folders.
 
@@ -432,7 +432,7 @@
 original format, which is sometimes referred to as :dfn:`mboxo`. This means that
 the :mailheader:`Content-Length` header, if present, is ignored and that any
 occurrences of "From " at the beginning of a line in a message body are
-transformed to ">From " when storing the message, although occurences of ">From
+transformed to ">From " when storing the message, although occurrences of ">From
 " are not transformed to "From " when reading the message.
 
 Some :class:`Mailbox` methods implemented by :class:`mbox` deserve special
@@ -460,7 +460,7 @@
    `mbox man page from tin <http://www.tin.org/bin/man.cgi?section=5&topic=mbox>`_
       Another specification of the format, with details on locking.
 
-   `Configuring Netscape Mail on Unix: Why The Content-Length Format is Bad <http://home.netscape.com/eng/mozilla/2.0/relnotes/demo/content-length.html>`_
+   `Configuring Netscape Mail on Unix: Why The Content-Length Format is Bad <http://www.jwz.org/doc/content-length.html>`_
       An argument for using the original mbox format rather than a variation.
 
    `"mbox" is a family of several mutually incompatible mailbox formats <http://homepages.tesco.net./~J.deBoynePollard/FGA/mail-mbox-formats.html>`_
@@ -580,7 +580,7 @@
 
 .. method:: MH.close()
 
-   :class:`MH` instances do not keep any open files, so this method is equivelant
+   :class:`MH` instances do not keep any open files, so this method is equivalent
    to :meth:`unlock`.
 
 
@@ -664,7 +664,7 @@
    `Format of Version 5 Babyl Files <http://quimby.gnus.org/notes/BABYL>`_
       A specification of the Babyl format.
 
-   `Reading Mail with Rmail <http://www.gnu.org/software/emacs/manual/html_node/Rmail.html>`_
+   `Reading Mail with Rmail <http://www.gnu.org/software/emacs/manual/html_node/emacs/Rmail.html>`_
       The Rmail manual, with some information on Babyl semantics.
 
 
@@ -805,7 +805,7 @@
 
       A message is typically moved from :file:`new` to :file:`cur` after its mailbox
       has been accessed, whether or not the message is has been read. A message
-      ``msg`` has been read if ``"S" not in msg.get_flags()`` is ``True``.
+      ``msg`` has been read if ``"S" in msg.get_flags()`` is ``True``.
 
 
 .. method:: MaildirMessage.set_subdir(subdir)
@@ -1540,10 +1540,6 @@
    :class:`UnixMailbox` except that individual messages are separated by only
    ``From`` lines.
 
-   For more information, see `Configuring Netscape Mail on Unix: Why the
-   Content-Length Format is Bad
-   <http://home.netscape.com/eng/mozilla/2.0/relnotes/demo/content-length.html>`_.
-
 
 .. class:: PortableUnixMailbox(fp[, factory])
 
@@ -1629,7 +1625,7 @@
    destination = mailbox.MH('~/Mail')
    destination.lock()
    for message in mailbox.Babyl('~/RMAIL'):
-       destination.add(MHMessage(message))
+       destination.add(mailbox.MHMessage(message))
    destination.flush()
    destination.unlock()
 
@@ -1643,7 +1639,7 @@
 
    list_names = ('python-list', 'python-dev', 'python-bugs')
 
-   boxes = dict((name, mailbox.mbox('~/email/%s' % name)) for name in list_names)
+   boxes = {name: mailbox.mbox('~/email/%s' % name) for name in list_names}
    inbox = mailbox.Maildir('~/Maildir', factory=None)
 
    for key in inbox.iterkeys():

Modified: python/branches/py3k-importlib/Doc/library/marshal.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/marshal.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/marshal.rst	Thu Mar 27 00:48:05 2008
@@ -25,7 +25,9 @@
 writing the "pseudo-compiled" code for Python modules of :file:`.pyc` files.
 Therefore, the Python maintainers reserve the right to modify the marshal format
 in backward incompatible ways should the need arise.  If you're serializing and
-de-serializing Python objects, use the :mod:`pickle` module instead.
+de-serializing Python objects, use the :mod:`pickle` module instead -- the
+performance is comparable, version independence is guaranteed, and pickle
+supports a substantially wider range of objects than marshal.
 
 .. warning::
 
@@ -35,24 +37,13 @@
 
 Not all Python object types are supported; in general, only objects whose value
 is independent from a particular invocation of Python can be written and read by
-this module.  The following types are supported: ``None``, integers, long
-integers, floating point numbers, strings, Unicode objects, tuples, lists,
+this module.  The following types are supported: ``None``, integers,
+floating point numbers, strings, bytes, bytearrays, tuples, lists, sets,
 dictionaries, and code objects, where it should be understood that tuples, lists
 and dictionaries are only supported as long as the values contained therein are
 themselves supported; and recursive lists and dictionaries should not be written
 (they will cause infinite loops).
 
-.. warning::
-   
-   On machines where C's ``long int`` type has more than 32 bits (such as the
-   DEC Alpha), it is possible to create plain Python integers that are longer
-   than 32 bits. If such an integer is marshaled and read back in on a machine
-   where C's ``long int`` type has only 32 bits, a Python long integer object
-   is returned instead.  While of a different type, the numeric value is the
-   same.  (This behavior is new in Python 2.2.  In earlier versions, all but the
-   least-significant 32 bits of the value were lost, and a warning message was
-   printed.)
-
 There are functions that read/write files as well as functions operating on
 strings.
 

Modified: python/branches/py3k-importlib/Doc/library/math.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/math.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/math.rst	Thu Mar 27 00:48:05 2008
@@ -26,8 +26,15 @@
 
 .. function:: ceil(x)
 
-   Return the ceiling of *x* as a float, the smallest integer value greater than or
-   equal to *x*.
+   Return the ceiling of *x* as a float, the smallest integer value greater than
+   or equal to *x*. If *x* is not a float, delegates to ``x.__ceil__()``, which
+   should return an :class:`Integral` value.
+
+
+.. function:: copysign(x, y)
+
+   Return *x* with the sign of *y*. ``copysign`` copies the sign bit of an IEEE
+   754 float, ``copysign(1, -0.0)`` returns *-1.0*.
 
 
 .. function:: fabs(x)
@@ -37,8 +44,9 @@
 
 .. function:: floor(x)
 
-   Return the floor of *x* as a float, the largest integer value less than or equal
-   to *x*.
+   Return the floor of *x* as a float, the largest integer value less than or
+   equal to *x*. If *x* is not a float, delegates to ``x.__floor__()``, which
+   should return an :class:`Integral` value.
 
 
 .. function:: fmod(x, y)
@@ -64,6 +72,19 @@
    apart" the internal representation of a float in a portable way.
 
 
+.. function:: isinf(x)
+
+   Checks if the float *x* is positive or negative infinite.
+
+
+.. function:: isnan(x)
+
+   Checks if the float *x* is a NaN (not a number). NaNs are part of the
+   IEEE 754 standards. Operation like but not limited to ``inf * 0``, 
+   ``inf / inf`` or any operation involving a NaN, e.g. ``nan * 1``, return
+   a NaN.
+
+
 .. function:: ldexp(x, i)
 
    Return ``x * (2**i)``.  This is essentially the inverse of function
@@ -75,6 +96,14 @@
    Return the fractional and integer parts of *x*.  Both results carry the sign of
    *x*, and both are floats.
 
+
+.. function:: trunc(x)
+
+   Return the :class:`Real` value *x* truncated to an :class:`Integral` (usually
+   a long integer). Delegates to ``x.__trunc__()``.
+
+   .. versionadded:: 2.6
+
 Note that :func:`frexp` and :func:`modf` have a different call/return pattern
 than their C equivalents: they take a single argument and return a pair of
 values, rather than returning their second return value through an 'output

Modified: python/branches/py3k-importlib/Doc/library/mhlib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/mhlib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/mhlib.rst	Thu Mar 27 00:48:05 2008
@@ -1,13 +1,9 @@
-
 :mod:`mhlib` --- Access to MH mailboxes
 =======================================
 
 .. module:: mhlib
    :synopsis: Manipulate MH mailboxes from Python.
-
-
-.. % LaTeX'ized from the comments in the module by Skip Montanaro
-.. % <skip at mojam.com>.
+.. sectionauthor:: Skip Montanaro <skip at pobox.com>
 
 The :mod:`mhlib` module provides a Python interface to MH folders and their
 contents.

Modified: python/branches/py3k-importlib/Doc/library/mimetools.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/mimetools.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/mimetools.rst	Thu Mar 27 00:48:05 2008
@@ -73,7 +73,7 @@
    Module :mod:`multifile`
       Support for reading files which contain distinct parts, such as MIME data.
 
-   http://www.cs.uu.nl/wais/html/na-dir/mail/mime-faq/.html
+   http://faqs.cs.uu.nl/na-dir/mail/mime-faq/.html
       The MIME Frequently Asked Questions document.  For an overview of MIME, see the
       answer to question 1.1 in Part 1 of this document.
 

Modified: python/branches/py3k-importlib/Doc/library/mimetypes.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/mimetypes.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/mimetypes.rst	Thu Mar 27 00:48:05 2008
@@ -41,7 +41,7 @@
 
    Optional *strict* is a flag specifying whether the list of known MIME types
    is limited to only the official types `registered with IANA
-   <http://www.isi.edu/in-notes/iana/assignments/media-types>`_ are recognized.
+   <http://www.iana.org/assignments/media-types/>`_ are recognized.
    When *strict* is true (the default), only the IANA types are supported; when
    *strict* is false, some additional non-standard but commonly used MIME types
    are also recognized.
@@ -96,8 +96,8 @@
    extension is already known, the new type will replace the old one. When the type
    is already known the extension will be added to the list of known extensions.
 
-   When *strict* is the mapping will added to the official MIME types, otherwise to
-   the non-standard ones.
+   When *strict* is True (the default), the mapping will added to the official MIME
+   types, otherwise to the non-standard ones.
 
 
 .. data:: inited

Modified: python/branches/py3k-importlib/Doc/library/mmap.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/mmap.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/mmap.rst	Thu Mar 27 00:48:05 2008
@@ -15,7 +15,7 @@
 and write data starting at the current file position, and :meth:`seek` through
 the file to different positions.
 
-A memory-mapped file is created by the :func:`mmap` function, which is different
+A memory-mapped file is created by the :class:`mmap` constructor, which is different
 on Unix and on Windows.  In either case you must provide a file descriptor for a
 file opened for update. If you wish to map an existing Python file object, use
 its :meth:`fileno` method to obtain the correct value for the *fileno*
@@ -23,7 +23,7 @@
 which returns a file descriptor directly (the file still needs to be closed when
 done).
 
-For both the Unix and Windows versions of the function, *access* may be
+For both the Unix and Windows versions of the constructor, *access* may be
 specified as an optional keyword parameter. *access* accepts one of three
 values: :const:`ACCESS_READ`, :const:`ACCESS_WRITE`, or :const:`ACCESS_COPY` to
 specify readonly, write-through or copy-on-write memory respectively. *access*
@@ -37,11 +37,10 @@
 
 To map anonymous memory, -1 should be passed as the fileno along with the length.
 
-
-.. function:: mmap(fileno, length[, tagname[, access]])
+.. class:: mmap(fileno, length[, tagname[, access[, offset]]])
 
    **(Windows version)** Maps *length* bytes from the file specified by the file
-   handle *fileno*, and returns a mmap object.  If *length* is larger than the
+   handle *fileno*, and creates a mmap object.  If *length* is larger than the
    current size of the file, the file is extended to contain *length* bytes.  If
    *length* is ``0``, the maximum length of the map is the current size of the
    file, except that if the file is empty Windows raises an exception (you cannot
@@ -54,13 +53,17 @@
    the mapping is created without a name.  Avoiding the use of the tag parameter
    will assist in keeping your code portable between Unix and Windows.
 
+   *offset* may be specified as a non-negative integer offset. mmap references will 
+   be relative to the offset from the beginning of the file. *offset* defaults to 0.
+   *offset* must be a multiple of the ALLOCATIONGRANULARITY.
+
 
-.. function:: mmap(fileno, length[, flags[, prot[, access]]])
+.. class:: mmap(fileno, length[, flags[, prot[, access[, offset]]]])
    :noindex:
 
    **(Unix version)** Maps *length* bytes from the file specified by the file
    descriptor *fileno*, and returns a mmap object.  If *length* is ``0``, the
-   maximum length of the map will be the current size of the file when :func:`mmap`
+   maximum length of the map will be the current size of the file when :class:`mmap`
    is called.
 
    *flags* specifies the nature of the mapping. :const:`MAP_PRIVATE` creates a
@@ -77,6 +80,53 @@
    parameter.  It is an error to specify both *flags*, *prot* and *access*.  See
    the description of *access* above for information on how to use this parameter.
 
+   *offset* may be specified as a non-negative integer offset. mmap references will 
+   be relative to the offset from the beginning of the file. *offset* defaults to 0.
+   *offset* must be a multiple of the PAGESIZE or ALLOCATIONGRANULARITY.
+   
+   This example shows a simple way of using :class:`mmap`::
+
+      import mmap
+
+      # write a simple example file
+      with open("hello.txt", "w") as f:
+          f.write("Hello Python!\n")
+
+      with open("hello.txt", "r+") as f:
+          # memory-map the file, size 0 means whole file
+          map = mmap.mmap(f.fileno(), 0)
+          # read content via standard file methods
+          print(map.readline())  # prints "Hello Python!"
+          # read content via slice notation
+          print(map[:5])  # prints "Hello"
+          # update content using slice notation;
+          # note that new content must have same size
+          map[6:] = " world!\n"
+          # ... and read again using standard file methods
+          map.seek(0)
+          print(map.readline())  # prints "Hello  world!"
+          # close the map
+          map.close()
+
+
+   The next example demonstrates how to create an anonymous map and exchange
+   data between the parent and child processes::
+
+      import mmap
+      import os
+
+      map = mmap.mmap(-1, 13)
+      map.write("Hello world!")
+
+      pid = os.fork()
+
+      if pid == 0: # In a child process
+          map.seek(0)
+          print(map.readline())
+
+          map.close()
+
+
 Memory-mapped file objects support the following methods:
 
 
@@ -86,11 +136,12 @@
    an exception being raised.
 
 
-.. method:: mmap.find(string[, start])
+.. method:: mmap.find(string[, start[, end]])
 
-   Returns the lowest index in the object where the substring *string* is found.
-   Returns ``-1`` on failure.  *start* is the index at which the search begins, and
-   defaults to zero.
+   Returns the lowest index in the object where the substring *string* is found,
+   such that *string* is contained in the range [*start*, *end*]. Optional
+   arguments *start* and *end* are interpreted as in slice notation.
+   Returns ``-1`` on failure.
 
 
 .. method:: mmap.flush([offset, size])
@@ -135,6 +186,14 @@
    :exc:`TypeError` exception.
 
 
+.. method:: mmap.rfind(string[, start[, end]])
+
+   Returns the highest index in the object where the substring *string* is
+   found, such that *string* is contained in the range [*start*,
+   *end*]. Optional arguments *start* and *end* are interpreted as in slice
+   notation.  Returns ``-1`` on failure.
+
+
 .. method:: mmap.seek(pos[, whence])
 
    Set the file's current position.  *whence* argument is optional and defaults to
@@ -169,3 +228,4 @@
    created with :const:`ACCESS_READ`, then writing to it will throw a
    :exc:`TypeError` exception.
 
+

Modified: python/branches/py3k-importlib/Doc/library/modulefinder.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/modulefinder.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/modulefinder.rst	Thu Mar 27 00:48:05 2008
@@ -48,3 +48,65 @@
 
    Analyze the contents of the *pathname* file, which must contain  Python code.
 
+.. attribute:: ModuleFinder.modules
+
+   A dictionary mapping module names to modules. See :ref:`modulefinder-example`
+
+
+.. _modulefinder-example:
+
+Example usage of :class:`ModuleFinder`
+--------------------------------------
+
+The script that is going to get analyzed later on (bacon.py)::
+
+   import re, itertools
+
+   try:
+       import baconhameggs
+   except ImportError:
+       pass
+
+   try:
+       import guido.python.ham
+   except ImportError:
+       pass
+
+
+The script that will output the report of bacon.py::
+
+   from modulefinder import ModuleFinder
+
+   finder = ModuleFinder()
+   finder.run_script('bacon.py')
+
+   print 'Loaded modules:'
+   for name, mod in finder.modules.iteritems():
+       print '%s: ' % name,
+       print ','.join(mod.globalnames.keys()[:3])
+
+   print '-'*50
+   print 'Modules not imported:'
+   print '\n'.join(finder.badmodules.iterkeys())
+
+Sample output (may vary depending on the architecture)::
+
+    Loaded modules:
+    _types:
+    copy_reg:  _inverted_registry,_slotnames,__all__
+    sre_compile:  isstring,_sre,_optimize_unicode
+    _sre:
+    sre_constants:  REPEAT_ONE,makedict,AT_END_LINE
+    sys:
+    re:  __module__,finditer,_expand
+    itertools:
+    __main__:  re,itertools,baconhameggs
+    sre_parse:  __getslice__,_PATTERNENDERS,SRE_FLAG_UNICODE
+    array:
+    types:  __module__,IntType,TypeType
+    ---------------------------------------------------
+    Modules not imported:
+    guido.python.ham
+    baconhameggs
+
+

Modified: python/branches/py3k-importlib/Doc/library/msilib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/msilib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/msilib.rst	Thu Mar 27 00:48:05 2008
@@ -40,7 +40,7 @@
    exposed.
 
 
-.. function:: UUIDCreate()
+.. function:: UuidCreate()
 
    Return the string representation of a new unique identifier. This wraps the
    Windows API functions :cfunc:`UuidCreate` and :cfunc:`UuidToString`.
@@ -65,7 +65,7 @@
 
 .. function:: init_database(name, schema, ProductName, ProductCode, ProductVersion, Manufacturer)
 
-   Create and return a new database *name*, initialize it  with *schema*,  and set
+   Create and return a new database *name*, initialize it with *schema*, and set
    the properties *ProductName*, *ProductCode*, *ProductVersion*, and
    *Manufacturer*.
 
@@ -77,11 +77,17 @@
    function returns.
 
 
-.. function:: add_data(database, records)
+.. function:: add_data(database, table, records)
 
-   Add all *records* to *database*.  *records* should be a list of tuples, each one
-   containing all fields of a record according to the schema of the table.  For
-   optional fields, ``None`` can be passed.
+   Add all *records* to the table named *table* in *database*.
+
+   The *table* argument must be one of the predefined tables in the MSI schema,
+   e.g. ``'Feature'``, ``'File'``, ``'Component'``, ``'Dialog'``, ``'Control'``,
+   etc.
+
+   *records* should be a list of tuples, each one containing all fields of a
+   record according to the schema of the table.  For optional fields,
+   ``None`` can be passed.
 
    Field values can be int or long numbers, strings, or instances of the Binary
    class.
@@ -147,7 +153,7 @@
 
 .. seealso::
 
-   `MSIOpenView <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msiopenview.asp>`_
+   `MSIDatabaseOpenView <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msidatabaseopenview.asp>`_
    `MSIDatabaseCommit <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msidatabasecommit.asp>`_
    `MSIGetSummaryInformation <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msigetsummaryinformation.asp>`_
 

Modified: python/branches/py3k-importlib/Doc/library/msvcrt.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/msvcrt.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/msvcrt.rst	Thu Mar 27 00:48:05 2008
@@ -16,6 +16,10 @@
 Further documentation on these functions can be found in the Platform API
 documentation.
 
+The module implements both the normal and wide char variants of the console I/O
+api. The normal API deals only with ASCII characters and is of limited use
+for internationalized applications. The wide char API should be used where 
+ever possible
 
 .. _msvcrt-files:
 
@@ -63,7 +67,7 @@
 .. function:: open_osfhandle(handle, flags)
 
    Create a C runtime file descriptor from the file handle *handle*.  The *flags*
-   parameter should be a bit-wise OR of :const:`os.O_APPEND`, :const:`os.O_RDONLY`,
+   parameter should be a bitwise OR of :const:`os.O_APPEND`, :const:`os.O_RDONLY`,
    and :const:`os.O_TEXT`.  The returned file descriptor may be used as a parameter
    to :func:`os.fdopen` to create a file object.
 
@@ -94,6 +98,11 @@
    return the keycode.  The :kbd:`Control-C` keypress cannot be read with this
    function.
 
+   
+.. function:: getwch()
+
+   Wide char variant of :func:`getch`, returning a Unicode value.
+   
 
 .. function:: getche()
 
@@ -101,16 +110,31 @@
    printable character.
 
 
+.. function:: getwche()
+
+   Wide char variant of :func:`getche`, returning a Unicode value.
+   
+
 .. function:: putch(char)
 
    Print the character *char* to the console without buffering.
 
+   
+.. function:: putwch(unicode_char)
+
+   Wide char variant of :func:`putch`, accepting a Unicode value.
+   
 
 .. function:: ungetch(char)
 
    Cause the character *char* to be "pushed back" into the console buffer; it will
    be the next character read by :func:`getch` or :func:`getche`.
 
+   
+.. function:: ungetwch(unicode_char)
+
+   Wide char variant of :func:`ungetch`, accepting a Unicode value.
+   
 
 .. _msvcrt-other:
 

Modified: python/branches/py3k-importlib/Doc/library/multifile.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/multifile.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/multifile.rst	Thu Mar 27 00:48:05 2008
@@ -155,7 +155,7 @@
 :class:`MultiFile` Example
 --------------------------
 
-.. sectionauthor:: Skip Montanaro <skip at mojam.com>
+.. sectionauthor:: Skip Montanaro <skip at pobox.com>
 
 
 ::

Deleted: /python/branches/py3k-importlib/Doc/library/new.rst
==============================================================================
--- /python/branches/py3k-importlib/Doc/library/new.rst	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,53 +0,0 @@
-
-:mod:`new` --- Creation of runtime internal objects
-===================================================
-
-.. module:: new
-   :synopsis: Interface to the creation of runtime implementation objects.
-.. sectionauthor:: Moshe Zadka <moshez at zadka.site.co.il>
-
-
-The :mod:`new` module allows an interface to the interpreter object creation
-functions. This is for use primarily in marshal-type functions, when a new
-object needs to be created "magically" and not by using the regular creation
-functions. This module provides a low-level interface to the interpreter, so
-care must be exercised when using this module. It is possible to supply
-non-sensical arguments which crash the interpreter when the object is used.
-
-The :mod:`new` module defines the following functions:
-
-
-.. function:: instancemethod(function, instance, class)
-
-   This function will return a method object, bound to *instance*, or unbound if
-   *instance* is ``None``.  *function* must be callable.
-
-
-.. function:: function(code, globals[, name[, argdefs[, closure]]])
-
-   Returns a (Python) function with the given code and globals. If *name* is given,
-   it must be a string or ``None``.  If it is a string, the function will have the
-   given name, otherwise the function name will be taken from ``code.co_name``.  If
-   *argdefs* is given, it must be a tuple and will be used to determine the default
-   values of parameters.  If *closure* is given, it must be ``None`` or a tuple of
-   cell objects containing objects to bind to the names in ``code.co_freevars``.
-
-
-.. function:: code(argcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, lnotab)
-
-   This function is an interface to the :cfunc:`PyCode_New` C function.
-
-   .. XXX This is still undocumented!!!
-
-
-.. function:: module(name[, doc])
-
-   This function returns a new module object with name *name*. *name* must be a
-   string. The optional *doc* argument can have any type.
-
-
-.. function:: classobj(name, baseclasses, dict)
-
-   This function returns a new class object, with name *name*, derived from
-   *baseclasses* (which should be a tuple of classes) and with namespace *dict*.
-   Alias for the built-in :class:`type`.

Modified: python/branches/py3k-importlib/Doc/library/nntplib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/nntplib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/nntplib.rst	Thu Mar 27 00:48:05 2008
@@ -309,8 +309,6 @@
    is supplied, then the returned *list* is an empty list. This is an optional NNTP
    extension, and may not be supported by all servers.
 
-   .. % XXX huh?  Should that be (name, description)?
-
    RFC2980 says "It is suggested that this extension be deprecated".  Use
    :meth:`descriptions` or :meth:`description` instead.
 

Modified: python/branches/py3k-importlib/Doc/library/numeric.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/numeric.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/numeric.rst	Thu Mar 27 00:48:05 2008
@@ -6,19 +6,22 @@
 ********************************
 
 The modules described in this chapter provide numeric and math-related functions
-and data types. The :mod:`math` and :mod:`cmath` contain  various mathematical
-functions for floating-point and complex numbers. For users more interested in
-decimal accuracy than in speed, the  :mod:`decimal` module supports exact
-representations of  decimal numbers.
+and data types. The :mod:`numbers` module defines an abstract hierarchy of
+numeric types. The :mod:`math` and :mod:`cmath` modules contain various
+mathematical functions for floating-point and complex numbers. For users more
+interested in decimal accuracy than in speed, the :mod:`decimal` module supports
+exact representations of decimal numbers.
 
 The following modules are documented in this chapter:
 
 
 .. toctree::
 
+   numbers.rst
    math.rst
    cmath.rst
    decimal.rst
+   fractions.rst
    random.rst
    itertools.rst
    functools.rst

Modified: python/branches/py3k-importlib/Doc/library/objects.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/objects.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/objects.rst	Thu Mar 27 00:48:05 2008
@@ -16,7 +16,7 @@
 in a separate  symbol table.  This table is searched last when the interpreter
 looks up the meaning of a name, so local and global user-defined names can
 override built-in names.  Built-in types are described together here for easy
-reference. [#]_
+reference.
 
 The tables in this chapter document the priorities of operators by listing them
 in order of ascending priority (within a table) and grouping operators that have
@@ -25,8 +25,3 @@
 have no real choice.)  See :ref:`operator-summary` for the complete picture on
 operator priorities.
 
-.. rubric:: Footnotes
-
-.. [#] Most descriptions sorely lack explanations of the exceptions that may be raised
-   --- this will be fixed in a future version of this manual.
-

Modified: python/branches/py3k-importlib/Doc/library/operator.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/operator.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/operator.rst	Thu Mar 27 00:48:05 2008
@@ -6,6 +6,11 @@
 .. sectionauthor:: Skip Montanaro <skip at automatrix.com>
 
 
+.. testsetup::
+   
+   import operator
+   from operator import itemgetter
+
 
 The :mod:`operator` module exports a set of functions implemented in C
 corresponding to the intrinsic operators of Python.  For example,
@@ -93,13 +98,6 @@
    Return the bitwise and of *a* and *b*.
 
 
-.. function:: div(a, b)
-              __div__(a, b)
-
-   Return ``a / b`` when ``__future__.division`` is not in effect.  This is
-   also known as "classic" division.
-
-
 .. function:: floordiv(a, b)
               __floordiv__(a, b)
 
@@ -171,8 +169,8 @@
 .. function:: truediv(a, b)
               __truediv__(a, b)
 
-   Return ``a / b`` when ``__future__.division`` is in effect.  This is also
-   known as "true" division.
+   Return ``a / b`` where 2/3 is .66 rather than 0.  This is also known as
+   "true" division.
 
 
 .. function:: xor(a, b)
@@ -211,7 +209,7 @@
 
    Remove the value of *a* at index *b*.
 
-
+ 
 .. function:: delslice(a, b, c)
               __delslice__(a, b, c)
 
@@ -241,14 +239,6 @@
    Return ``a * b`` where *a* is a sequence and *b* is an integer.
 
 
-.. function:: sequenceIncludes(...)
-
-   .. deprecated:: 2.0
-      Use :func:`contains` instead.
-
-   Alias for :func:`contains`.
-
-
 .. function:: setitem(a, b, c)
               __setitem__(a, b, c)
 
@@ -260,12 +250,13 @@
 
    Set the slice of *a* from index *b* to index *c-1* to the sequence *v*.
 
+
 Many operations have an "in-place" version.  The following functions provide a
 more primitive access to in-place operators than the usual syntax does; for
-example, the statement ``x += y`` is equivalent to ``x = operator.iadd(x, y)``.
-Another way to put it is to say that ``z = operator.iadd(x, y)`` is equivalent
-to the compound statement ``z = x; z += y``.
-
+example, the :term:`statement` ``x += y`` is equivalent to
+``x = operator.iadd(x, y)``.  Another way to put it is to say that
+``z = operator.iadd(x, y)`` is equivalent to the compound statement
+``z = x; z += y``.
 
 .. function:: iadd(a, b)
               __iadd__(a, b)
@@ -285,13 +276,6 @@
    ``a = iconcat(a, b)`` is equivalent to ``a += b`` for *a* and *b* sequences.
 
 
-.. function:: idiv(a, b)
-              __idiv__(a, b)
-
-   ``a = idiv(a, b)`` is equivalent to ``a /= b`` when ``__future__.division`` is
-   not in effect.
-
-
 .. function:: ifloordiv(a, b)
               __ifloordiv__(a, b)
 
@@ -350,8 +334,7 @@
 .. function:: itruediv(a, b)
               __itruediv__(a, b)
 
-   ``a = itruediv(a, b)`` is equivalent to ``a /= b`` when ``__future__.division``
-   is in effect.
+   ``a = itruediv(a, b)`` is equivalent to ``a /= b``.
 
 
 .. function:: ixor(a, b)
@@ -363,11 +346,12 @@
 The :mod:`operator` module also defines a few predicates to test the type of
 objects.
 
+.. XXX just remove them?
 .. note::
 
-   Be careful not to misinterpret the results of these functions; only
-   :func:`isCallable` has any measure of reliability with instance objects.
-   For example::
+   Be careful not to misinterpret the results of these functions; none have any
+   measure of reliability with instance objects.
+   For example:
 
       >>> class C:
       ...     pass
@@ -379,21 +363,10 @@
 
 .. note::
 
-   Python 3 is expected to introduce abstract base classes for
-   collection types, so it should be possible to write, for example,
-   ``isinstance(obj, collections.Mapping)`` and ``isinstance(obj,
+   Since there are now abstract classes for collection types, you should write,
+   for example, ``isinstance(obj, collections.Mapping)`` and ``isinstance(obj,
    collections.Sequence)``.
 
-.. function:: isCallable(obj)
-
-   .. deprecated:: 2.0
-      Use the :func:`callable` built-in function instead.
-
-   Returns true if the object *obj* can be called like a function, otherwise it
-   returns false.  True is returned for functions, bound and unbound methods, class
-   objects, and instance objects which support the :meth:`__call__` method.
-
-
 .. function:: isMappingType(obj)
 
    Returns true if the object *obj* supports the mapping interface. This is true for
@@ -431,13 +404,12 @@
       useful than it otherwise might be.
 
 Example: Build a dictionary that maps the ordinals from ``0`` to ``255`` to
-their character equivalents. ::
+their character equivalents.
 
-   >>> import operator
    >>> d = {}
    >>> keys = range(256)
    >>> vals = map(chr, keys)
-   >>> map(operator.setitem, [d]*len(keys), keys, vals)
+   >>> map(operator.setitem, [d]*len(keys), keys, vals)   # doctest: +SKIP
 
 .. XXX: find a better, readable, example
 
@@ -451,28 +423,60 @@
 
    Return a callable object that fetches *attr* from its operand. If more than one
    attribute is requested, returns a tuple of attributes. After,
-   ``f=attrgetter('name')``, the call ``f(b)`` returns ``b.name``.  After,
-   ``f=attrgetter('name', 'date')``, the call ``f(b)`` returns ``(b.name,
+   ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``.  After,
+   ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns ``(b.name,
    b.date)``.
 
+   The attribute names can also contain dots; after ``f = attrgetter('date.month')``,
+   the call ``f(b)`` returns ``b.date.month``.
 
 .. function:: itemgetter(item[, args...])
 
-   Return a callable object that fetches *item* from its operand. If more than one
-   item is requested, returns a tuple of items. After, ``f=itemgetter(2)``, the
-   call ``f(b)`` returns ``b[2]``. After, ``f=itemgetter(2,5,3)``, the call
-   ``f(b)`` returns ``(b[2], b[5], b[3])``.
-
-
-Examples::
-
-   >>> from operator import itemgetter
-   >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)]
-   >>> getcount = itemgetter(1)
-   >>> map(getcount, inventory)
-   [3, 2, 5, 1]
-   >>> sorted(inventory, key=getcount)
-   [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
+   Return a callable object that fetches *item* from its operand using the
+   operand's :meth:`__getitem__` method.  If multiple items are specified,
+   returns a tuple of lookup values.  Equivalent to::
+
+        def itemgetter(*items):
+            if len(items) == 1:
+                item = items[0]
+                def g(obj):
+                    return obj[item]
+            else:
+                def g(obj):
+                    return tuple(obj[item] for item in items)
+            return g
+   
+   The items can be any type accepted by the operand's :meth:`__getitem__` 
+   method.  Dictionaries accept any hashable value.  Lists, tuples, and 
+   strings accept an index or a slice:
+
+      >>> itemgetter(1)('ABCDEFG')
+      'B'
+      >>> itemgetter(1,3,5)('ABCDEFG')
+      ('B', 'D', 'F')
+      >>> itemgetter(slice(2,None))('ABCDEFG')
+      'CDEFG'
+
+   .. versionadded:: 2.4
+
+   Example of using :func:`itemgetter` to retrieve specific fields from a
+   tuple record:
+
+       >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)]
+       >>> getcount = itemgetter(1)
+       >>> map(getcount, inventory)
+       [3, 2, 5, 1]
+       >>> sorted(inventory, key=getcount)
+       [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
+
+
+.. function:: methodcaller(name[, args...])
+
+   Return a callable object that calls the method *name* on its operand.  If
+   additional arguments and/or keyword arguments are given, they will be given
+   to the method as well.  After ``f = methodcaller('name')``, the call ``f(b)``
+   returns ``b.name()``.  After ``f = methodcaller('name', 'foo', bar=1)``, the
+   call ``f(b)`` returns ``b.name('foo', bar=1)``.
 
 
 .. _operator-map:
@@ -492,11 +496,7 @@
 +-----------------------+-------------------------+---------------------------------+
 | Containment Test      | ``obj in seq``          | ``contains(seq, obj)``          |
 +-----------------------+-------------------------+---------------------------------+
-| Division              | ``a / b``               | ``div(a, b)`` (without          |
-|                       |                         | ``__future__.division``)        |
-+-----------------------+-------------------------+---------------------------------+
-| Division              | ``a / b``               | ``truediv(a, b)`` (with         |
-|                       |                         | ``__future__.division``)        |
+| Division              | ``a / b``               | ``truediv(a, b)``               |
 +-----------------------+-------------------------+---------------------------------+
 | Division              | ``a // b``              | ``floordiv(a, b)``              |
 +-----------------------+-------------------------+---------------------------------+

Modified: python/branches/py3k-importlib/Doc/library/optparse.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/optparse.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/optparse.rst	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,3 @@
-.. % THIS FILE IS AUTO-GENERATED!  DO NOT EDIT!
-.. % (Your changes will be lost the next time it is generated.)
-
-
 :mod:`optparse` --- More powerful command line option parser
 ============================================================
 
@@ -18,9 +14,6 @@
 to specify options in the conventional GNU/POSIX syntax, and additionally
 generates usage and help messages for you.
 
-.. % An intro blurb used only when generating LaTeX docs for the Python
-.. % manual (based on README.txt).
-
 Here's an example of using ``optparse`` in a simple script::
 
    from optparse import OptionParser
@@ -70,8 +63,6 @@
 where the value of *yourscript* is determined at runtime (normally from
 ``sys.argv[0]``).
 
-.. % $Id: intro.txt 413 2004-09-28 00:59:13Z greg $
-
 
 .. _optparse-background:
 
@@ -233,8 +224,6 @@
 implementation becomes.  Too much flexibility has drawbacks as well, of course;
 too many options can overwhelm users and make your code much harder to maintain.
 
-.. % $Id: tao.txt 413 2004-09-28 00:59:13Z greg $
-
 
 .. _optparse-tutorial:
 
@@ -364,7 +353,7 @@
 long option strings, :mod:`optparse` looks at the first short option string: the
 default destination for ``"-f"`` is ``f``.
 
-:mod:`optparse` also includes built-in ``long`` and ``complex`` types.  Adding
+:mod:`optparse` also includes the built-in ``complex`` type.  Adding
 types is covered in section :ref:`optparse-extending-optparse`.
 
 
@@ -546,6 +535,35 @@
   default value.  If an option has no default value (or the default value is
   ``None``), ``%default`` expands to ``none``.
 
+When dealing with many options, it is convenient to group these
+options for better help output.  An :class:`OptionParser` can contain
+several option groups, each of which can contain several options.
+
+Continuing with the parser defined above, adding an
+:class:`OptionGroup` to a parser is easy::
+
+    group = OptionGroup(parser, "Dangerous Options",
+			"Caution: use these options at your own risk.  "
+			"It is believed that some of them bite.")
+    group.add_option("-g", action="store_true", help="Group option.")
+    parser.add_option_group(group)
+
+This would result in the following help output::
+
+    usage:  [options] arg1 arg2
+
+    options:
+      -h, --help           show this help message and exit
+      -v, --verbose        make lots of noise [default]
+      -q, --quiet          be vewwy quiet (I'm hunting wabbits)
+      -fFILE, --file=FILE  write output to FILE
+      -mMODE, --mode=MODE  interaction mode: one of 'novice', 'intermediate'
+			   [default], 'expert'
+
+      Dangerous Options:
+	Caution: use of these options is at your own risk.  It is believed that
+	some of them bite.
+	-g                 Group option.
 
 .. _optparse-printing-version-string:
 
@@ -652,8 +670,6 @@
    if __name__ == "__main__":
        main()
 
-.. % $Id: tutorial.txt 515 2006-06-10 15:37:45Z gward $
-
 
 .. _optparse-reference-guide:
 
@@ -950,7 +966,7 @@
 * ``append_const`` [required: ``const``; relevant: :attr:`dest`]
 
   Like ``store_const``, but the value ``const`` is appended to :attr:`dest`; as
-  with ``append``, :attr:`dest` defaults to ``None``, and an an empty list is
+  with ``append``, :attr:`dest` defaults to ``None``, and an empty list is
   automatically created the first time the option is encountered.
 
 * ``count`` [relevant: :attr:`dest`]
@@ -1103,27 +1119,27 @@
 Standard option types
 ^^^^^^^^^^^^^^^^^^^^^
 
-:mod:`optparse` has six built-in option types: ``string``, ``int``, ``long``,
+:mod:`optparse` has five built-in option types: ``string``, ``int``,
 ``choice``, ``float`` and ``complex``.  If you need to add new option types, see
 section :ref:`optparse-extending-optparse`.
 
 Arguments to string options are not checked or converted in any way: the text on
 the command line is stored in the destination (or passed to the callback) as-is.
 
-Integer arguments (type ``int`` or ``long``) are parsed as follows:
+Integer arguments (type ``int``) are parsed as follows:
 
 * if the number starts with ``0x``, it is parsed as a hexadecimal number
 
 * if the number starts with ``0``, it is parsed as an octal number
 
-* if the number starts with ``0b``, is is parsed as a binary number
+* if the number starts with ``0b``, it is parsed as a binary number
 
 * otherwise, the number is parsed as a decimal number
 
 
-The conversion is done by calling either ``int()`` or ``long()`` with the
-appropriate base (2, 8, 10, or 16).  If this fails, so will :mod:`optparse`,
-although with a more useful error message.
+The conversion is done by calling ``int()`` with the appropriate base (2, 8, 10,
+or 16).  If this fails, so will :mod:`optparse`, although with a more useful
+error message.
 
 ``float`` and ``complex`` option arguments are converted directly with
 ``float()`` and ``complex()``, with similar error-handling.
@@ -1329,8 +1345,6 @@
      parser.add_option("--novice", action="store_const",
                        dest="mode", const="novice")
 
-.. % $Id: reference.txt 519 2006-06-11 14:39:11Z gward $
-
 
 .. _optparse-option-callbacks:
 
@@ -1615,7 +1629,7 @@
                value.append(arg)
                del rargs[0]
 
-        setattr(parser.values, option.dest, value)
+       setattr(parser.values, option.dest, value)
 
    [...]
    parser.add_option("-c", "--callback",
@@ -1626,8 +1640,6 @@
 (probably causing an error), rather than as arguments to ``"-c"``.  Fixing this
 is left as an exercise for the reader.
 
-.. % $Id: callbacks.txt 415 2004-09-30 02:26:17Z greg $
-
 
 .. _optparse-extending-optparse:
 
@@ -1818,6 +1830,3 @@
   about setting a default value for the option destinations in question; they can
   just leave the default as None and :meth:`ensure_value` will take care of
   getting it right when it's needed.
-
-.. % $Id: extending.txt 517 2006-06-10 16:18:11Z gward $
-

Modified: python/branches/py3k-importlib/Doc/library/os.path.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/os.path.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/os.path.rst	Thu Mar 27 00:48:05 2008
@@ -130,7 +130,9 @@
 
 .. function:: isabs(path)
 
-   Return ``True`` if *path* is an absolute pathname (begins with a slash).
+   Return ``True`` if *path* is an absolute pathname.  On Unix, that means it
+   begins with a slash, on Windows that it begins with a (back)slash after chopping
+   off a potential drive letter.
 
 
 .. function:: isfile(path)
@@ -279,12 +281,12 @@
 
    .. note::
 
-      The newer :func:`os.walk` generator supplies similar functionality and can be
-      easier to use.
+      The newer :func:`os.walk` :term:`generator` supplies similar functionality
+      and can be easier to use.
 
 
 .. data:: supports_unicode_filenames
 
    True if arbitrary Unicode strings can be used as file names (within limitations
-   imposed by the file system), and if :func:`os.listdir` returns Unicode strings
-   for a Unicode argument.
+   imposed by the file system), and if :func:`os.listdir` returns strings that
+   contain characters that cannot be represented by ASCII.

Modified: python/branches/py3k-importlib/Doc/library/os.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/os.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/os.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`os` --- Miscellaneous operating system interfaces
 =======================================================
 
@@ -6,51 +5,32 @@
    :synopsis: Miscellaneous operating system interfaces.
 
 
-This module provides a more portable way of using operating system dependent
-functionality than importing a operating system dependent built-in module like
-:mod:`posix` or :mod:`nt`. If you just want to read or write a file see
-:func:`open`, if you want to manipulate paths, see the :mod:`os.path`
-module, and if you want to read all the lines in all the files on the
-command line see the :mod:`fileinput` module.
-
-This module searches for an operating system dependent built-in module like
-:mod:`mac` or :mod:`posix` and exports the same functions and data as found
-there.  The design of all Python's built-in operating system dependent modules
-is such that as long as the same functionality is available, it uses the same
-interface; for example, the function ``os.stat(path)`` returns stat information
-about *path* in the same format (which happens to have originated with the POSIX
+This module provides a portable way of using operating system dependent
+functionality.  If you just want to read or write a file see :func:`open`, if
+you want to manipulate paths, see the :mod:`os.path` module, and if you want to
+read all the lines in all the files on the command line see the :mod:`fileinput`
+module.  For creating temporary files and directories see the :mod:`tempfile`
+module, and for high-level file and directory handling see the :mod:`shutil`
+module.
+
+The design of all built-in operating system dependent modules of Python is such
+that as long as the same functionality is available, it uses the same interface;
+for example, the function ``os.stat(path)`` returns stat information about
+*path* in the same format (which happens to have originated with the POSIX
 interface).
 
 Extensions peculiar to a particular operating system are also available through
 the :mod:`os` module, but using them is of course a threat to portability!
 
-Note that after the first time :mod:`os` is imported, there is *no* performance
-penalty in using functions from :mod:`os` instead of directly from the operating
-system dependent built-in module, so there should be *no* reason not to use
-:mod:`os`!
+.. note::
 
-The :mod:`os` module contains many functions and data values. The items below
-and in the following sub-sections are all available directly from the :mod:`os`
-module.
+   All functions in this module raise :exc:`OSError` in the case of invalid or
+   inaccessible file names and paths, or other arguments that have the correct
+   type, but are not accepted by the operating system.
 
 .. exception:: error
 
-   .. index:: module: errno
-
-   This exception is raised when a function returns a system-related error (not for
-   illegal argument types or other incidental errors). This is also known as the
-   built-in exception :exc:`OSError`.  The accompanying value is a pair containing
-   the numeric error code from :cdata:`errno` and the corresponding string, as
-   would be printed by the C function :cfunc:`perror`.  See the module
-   :mod:`errno`, which contains names for the error codes defined by the underlying
-   operating system.
-
-   When exceptions are classes, this exception carries two attributes,
-   :attr:`errno` and :attr:`strerror`.  The first holds the value of the C
-   :cdata:`errno` variable, and the latter holds the corresponding error message
-   from :cfunc:`strerror`.  For exceptions that involve a file system path (such as
-   :func:`chdir` or :func:`unlink`), the exception instance will contain a third
-   attribute, :attr:`filename`, which is the file name passed to the function.
+   An alias for the built-in :exc:`OSError` exception.
 
 
 .. data:: name
@@ -107,9 +87,10 @@
    passed to the appropriate process-creation functions to cause  child processes
    to use a modified environment.
 
-   If the platform supports the :func:`unsetenv` function, you can  delete items in
+   If the platform supports the :func:`unsetenv` function, you can delete items in
    this mapping to unset environment variables. :func:`unsetenv` will be called
-   automatically when an item is deleted from ``os.environ``.
+   automatically when an item is deleted from ``os.environ``, and when
+   one of the :meth:`pop` or :meth:`clear` methods is called.
 
 
 .. function:: chdir(path)
@@ -129,7 +110,7 @@
 .. function:: getegid()
 
    Return the effective group id of the current process.  This corresponds to the
-   'set id' bit on the file being executed in the current process. Availability:
+   "set id" bit on the file being executed in the current process. Availability:
    Unix.
 
 
@@ -137,7 +118,7 @@
 
    .. index:: single: user; effective id
 
-   Return the current process' effective user id. Availability: Unix.
+   Return the current process's effective user id. Availability: Unix.
 
 
 .. function:: getgid()
@@ -159,7 +140,7 @@
    process.  For most purposes, it is more useful to use the environment variable
    :envvar:`LOGNAME` to find out who the user is, or
    ``pwd.getpwuid(os.getuid())[0]`` to get the login name of the currently
-   effective user ID. Availability: Unix.
+   effective user id. Availability: Unix.
 
 
 .. function:: getpgid(pid)
@@ -193,7 +174,7 @@
 
    .. index:: single: user; id
 
-   Return the current process' user id. Availability: Unix.
+   Return the current process's user id. Availability: Unix.
 
 
 .. function:: getenv(varname[, value])
@@ -242,20 +223,20 @@
 
    Set the list of supplemental group ids associated with the current process to
    *groups*. *groups* must be a sequence, and each element must be an integer
-   identifying a group. This operation is typical available only to the superuser.
+   identifying a group. This operation is typically available only to the superuser.
    Availability: Unix.
 
 
 .. function:: setpgrp()
 
-   Calls the system call :cfunc:`setpgrp` or :cfunc:`setpgrp(0, 0)` depending on
+   Call the system call :cfunc:`setpgrp` or :cfunc:`setpgrp(0, 0)` depending on
    which version is implemented (if any).  See the Unix manual for the semantics.
    Availability: Unix.
 
 
 .. function:: setpgid(pid, pgrp)
 
-   Calls the system call :cfunc:`setpgid` to set the process group id of the
+   Call the system call :cfunc:`setpgid` to set the process group id of the
    process with id *pid* to the process group with id *pgrp*.  See the Unix manual
    for the semantics. Availability: Unix.
 
@@ -272,13 +253,13 @@
 
 .. function:: getsid(pid)
 
-   Calls the system call :cfunc:`getsid`.  See the Unix manual for the semantics.
+   Call the system call :cfunc:`getsid`.  See the Unix manual for the semantics.
    Availability: Unix.
 
 
 .. function:: setsid()
 
-   Calls the system call :cfunc:`setsid`.  See the Unix manual for the semantics.
+   Call the system call :cfunc:`setsid`.  See the Unix manual for the semantics.
    Availability: Unix.
 
 
@@ -286,11 +267,10 @@
 
    .. index:: single: user; id, setting
 
-   Set the current process' user id. Availability: Unix.
-
-.. % placed in this section since it relates to errno.... a little weak
+   Set the current process's user id. Availability: Unix.
 
 
+.. placed in this section since it relates to errno.... a little weak
 .. function:: strerror(code)
 
    Return the error message corresponding to the error code in *code*.
@@ -299,7 +279,7 @@
 
 .. function:: umask(mask)
 
-   Set the current numeric umask and returns the previous umask. Availability:
+   Set the current numeric umask and return the previous umask. Availability:
    Unix, Windows.
 
 
@@ -371,14 +351,6 @@
       This function is obsolete.  Use the :mod:`subprocess` module.
 
 
-.. function:: tmpfile()
-
-   Return a new file object opened in update mode (``w+b``).  The file has no
-   directory entries associated with it and will be automatically deleted once
-   there are no file descriptors for the file. Availability: Macintosh, Unix,
-   Windows.
-
-
 .. _os-fd-ops:
 
 File Descriptor Operations
@@ -406,6 +378,24 @@
       :func:`fdopen`, use its :meth:`close` method.
 
 
+.. function:: closerange(fd_low, fd_high)
+
+   Close all file descriptors from *fd_low* (inclusive) to *fd_high* (exclusive),
+   ignoring errors. Availability: Macintosh, Unix, Windows. Equivalent to::
+
+      for fd in xrange(fd_low, fd_high):
+          try:
+              os.close(fd)
+          except OSError:
+              pass
+
+
+.. function:: device_encoding(fd)
+
+   Return a string describing the encoding of the device associated with *fd*
+   if it is connected to a terminal; else return :const:`None`.
+
+
 .. function:: dup(fd)
 
    Return a duplicate of file descriptor *fd*. Availability: Macintosh, Unix,
@@ -418,6 +408,19 @@
    Availability: Macintosh, Unix, Windows.
 
 
+.. function:: fchmod(fd, mode)
+
+   Change the mode of the file given by *fd* to the numeric *mode*.  See the docs
+   for :func:`chmod` for possible values of *mode*.  Availability: Unix.
+
+
+.. function:: fchown(fd, uid, gid)
+
+   Change the owner and group id of the file given by *fd* to the numeric *uid*
+   and *gid*.  To leave one of the ids unchanged, set it to -1.
+   Availability: Unix.
+
+
 .. function:: fdatasync(fd)
 
    Force write of file with filedescriptor *fd* to disk. Does not force update of
@@ -478,9 +481,10 @@
 
 .. function:: lseek(fd, pos, how)
 
-   Set the current position of file descriptor *fd* to position *pos*, modified by
-   *how*: ``0`` to set the position relative to the beginning of the file; ``1`` to
-   set it relative to the current position; ``2`` to set it relative to the end of
+   Set the current position of file descriptor *fd* to position *pos*, modified
+   by *how*: :const:`SEEK_SET` or ``0`` to set the position relative to the
+   beginning of the file; :const:`SEEK_CUR` or ``1`` to set it relative to the
+   current position; :const:`os.SEEK_END` or ``2`` to set it relative to the end of
    the file. Availability: Macintosh, Unix, Windows.
 
 
@@ -509,7 +513,7 @@
 
    Open a new pseudo-terminal pair. Return a pair of file descriptors ``(master,
    slave)`` for the pty and the tty, respectively. For a (slightly) more portable
-   approach, use the :mod:`pty` module. Availability: Macintosh, Some flavors of
+   approach, use the :mod:`pty` module. Availability: Macintosh, some flavors of
    Unix.
 
 
@@ -530,7 +534,7 @@
       This function is intended for low-level I/O and must be applied to a file
       descriptor as returned by :func:`open` or :func:`pipe`.  To read a "file object"
       returned by the built-in function :func:`open` or by :func:`popen` or
-      :func:`fdopen`, or ``sys.stdin``, use its :meth:`read` or :meth:`readline`
+      :func:`fdopen`, or :data:`sys.stdin`, use its :meth:`read` or :meth:`readline`
       methods.
 
 
@@ -549,7 +553,7 @@
 .. function:: ttyname(fd)
 
    Return a string which specifies the terminal device associated with
-   file-descriptor *fd*.  If *fd* is not associated with a terminal device, an
+   file descriptor *fd*.  If *fd* is not associated with a terminal device, an
    exception is raised. Availability:Macintosh, Unix.
 
 
@@ -563,7 +567,7 @@
       This function is intended for low-level I/O and must be applied to a file
       descriptor as returned by :func:`open` or :func:`pipe`.  To write a "file
       object" returned by the built-in function :func:`open` or by :func:`popen` or
-      :func:`fdopen`, or ``sys.stdout`` or ``sys.stderr``, use its :meth:`write`
+      :func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its :meth:`write`
       method.
 
 The following data items are available for use in constructing the *flags*
@@ -581,7 +585,7 @@
           O_TRUNC
 
    Options for the *flag* argument to the :func:`open` function. These can be
-   bit-wise OR'd together. Availability: Macintosh, Unix, Windows.
+   combined using the bitwise OR operator ``|``. Availability: Macintosh, Unix, Windows.
 
 
 .. data:: O_DSYNC
@@ -598,14 +602,7 @@
 
 
 .. data:: O_BINARY
-
-   Option for the *flag* argument to the :func:`open` function. This can be
-   bit-wise OR'd together with those listed above. Availability: Windows.
-
-   .. % XXX need to check on the availability of this one.
-
-
-.. data:: O_NOINHERIT
+          O_NOINHERIT
           O_SHORT_LIVED
           O_TEMPORARY
           O_RANDOM
@@ -613,7 +610,16 @@
           O_TEXT
 
    Options for the *flag* argument to the :func:`open` function. These can be
-   bit-wise OR'd together. Availability: Windows.
+   combined using the bitwise OR operator ``|``. Availability: Windows.
+
+
+.. data:: O_DIRECT
+          O_DIRECTORY
+          O_NOFOLLOW
+          O_NOATIME
+
+   Options for the *flag* argument to the :func:`open` function. These are
+   GNU extensions and not present if they are not defined by the C library.
 
 
 .. data:: SEEK_SET
@@ -629,7 +635,6 @@
 Files and Directories
 ---------------------
 
-
 .. function:: access(path, mode)
 
    Use the real uid/gid to test for access to *path*.  Note that most operations
@@ -696,13 +701,13 @@
 
 .. function:: getcwd()
 
-   Return a string representing the current working directory. Availability:
-   Macintosh, Unix, Windows.
+   Return a bytestring representing the current working directory.
+   Availability: Macintosh, Unix, Windows.
 
 
 .. function:: getcwdu()
 
-   Return a Unicode object representing the current working directory.
+   Return a string representing the current working directory.
    Availability: Macintosh, Unix, Windows.
 
 
@@ -734,7 +739,7 @@
 .. function:: chmod(path, mode)
 
    Change the mode of *path* to the numeric *mode*. *mode* may take one of the
-   following values (as defined in the :mod:`stat` module) or bitwise or-ed
+   following values (as defined in the :mod:`stat` module) or bitwise ORed
    combinations of them:
 
    * ``stat.S_ISUID``
@@ -779,9 +784,16 @@
    follow symbolic links. Availability: Unix.
 
 
+.. function:: lchmod(path, mode)
+
+   Change the mode of *path* to the numeric *mode*. If path is a symlink, this
+   affects the symlink rather than the target. See the docs for :func:`chmod`
+   for possible values of *mode*.  Availability: Unix.
+
+
 .. function:: lchown(path, uid, gid)
 
-   Change the owner and group id of *path* to the numeric *uid* and gid. This
+   Change the owner and group id of *path* to the numeric *uid* and *gid*. This
    function will not follow symbolic links. Availability: Macintosh, Unix.
 
 
@@ -803,8 +815,9 @@
 
 .. function:: lstat(path)
 
-   Like :func:`stat`, but do not follow symbolic links. Availability: Macintosh,
-   Unix.
+   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.
 
 
 .. function:: mkfifo(path[, mode])
@@ -834,19 +847,19 @@
 
 .. function:: major(device)
 
-   Extracts the device major number from a raw device number (usually the
+   Extract the device major number from a raw device number (usually the
    :attr:`st_dev` or :attr:`st_rdev` field from :ctype:`stat`).
 
 
 .. function:: minor(device)
 
-   Extracts the device minor number from a raw device number (usually the
+   Extract the device minor number from a raw device number (usually the
    :attr:`st_dev` or :attr:`st_rdev` field from :ctype:`stat`).
 
 
 .. function:: makedev(major, minor)
 
-   Composes a raw device number from the major and minor device numbers.
+   Compose a raw device number from the major and minor device numbers.
 
 
 .. function:: mkdir(path[, mode])
@@ -855,6 +868,9 @@
    ``0777`` (octal).  On some systems, *mode* is ignored.  Where it is used, the
    current umask value is first masked out. Availability: Macintosh, Unix, Windows.
 
+   It is also possible to create temporary directories; see the
+   :mod:`tempfile` module's :func:`tempfile.mkdtemp` function.
+
 
 .. function:: makedirs(path[, mode])
 
@@ -871,7 +887,7 @@
    .. note::
 
       :func:`makedirs` will become confused if the path elements to create include
-      *os.pardir*.
+      :data:`os.pardir`.
 
    This function handles UNC paths correctly.
 
@@ -928,7 +944,7 @@
 
    .. index:: single: directory; deleting
 
-   Removes directories recursively.  Works like :func:`rmdir` except that, if the
+   Remove directories recursively.  Works like :func:`rmdir` except that, if the
    leaf directory is successfully removed, :func:`removedirs`  tries to
    successively remove every parent directory mentioned in  *path* until an error
    is raised (which is ignored, because it generally means that a parent directory
@@ -942,7 +958,7 @@
 
    Rename the file or directory *src* to *dst*.  If *dst* is a directory,
    :exc:`OSError` will be raised.  On Unix, if *dst* exists and is a file, it will
-   be removed silently if the user has permission.  The operation may fail on some
+   be replaced silently if the user has permission.  The operation may fail on some
    Unix flavors if *src* and *dst* are on different filesystems.  If successful,
    the renaming will be an atomic operation (this is a POSIX requirement).  On
    Windows, if *dst* already exists, :exc:`OSError` will be raised even if it is a
@@ -974,7 +990,7 @@
    object whose attributes correspond to the members of the :ctype:`stat`
    structure, namely: :attr:`st_mode` (protection bits), :attr:`st_ino` (inode
    number), :attr:`st_dev` (device), :attr:`st_nlink` (number of hard links),
-   :attr:`st_uid` (user ID of owner), :attr:`st_gid` (group ID of owner),
+   :attr:`st_uid` (user id of owner), :attr:`st_gid` (group id of owner),
    :attr:`st_size` (size of file, in bytes), :attr:`st_atime` (time of most recent
    access), :attr:`st_mtime` (time of most recent content modification),
    :attr:`st_ctime` (platform dependent; time of most recent metadata change on
@@ -988,10 +1004,6 @@
       926L
       >>>
 
-   If :func:`stat_float_times` returns true, the time values are floats, measuring
-   seconds. Fractions of a second may be reported if the system supports that. On
-   Mac OS, the times are always floats. See :func:`stat_float_times` for further
-   discussion.
 
    On some Unix systems (such as Linux), the following attributes may also be
    available: :attr:`st_blocks` (number of blocks allocated for file),
@@ -1077,53 +1089,6 @@
    Create a symbolic link pointing to *src* named *dst*. Availability: Unix.
 
 
-.. function:: tempnam([dir[, prefix]])
-
-   Return a unique path name that is reasonable for creating a temporary file.
-   This will be an absolute path that names a potential directory entry in the
-   directory *dir* or a common location for temporary files if *dir* is omitted or
-   ``None``.  If given and not ``None``, *prefix* is used to provide a short prefix
-   to the filename.  Applications are responsible for properly creating and
-   managing files created using paths returned by :func:`tempnam`; no automatic
-   cleanup is provided. On Unix, the environment variable :envvar:`TMPDIR`
-   overrides *dir*, while on Windows the :envvar:`TMP` is used.  The specific
-   behavior of this function depends on the C library implementation; some aspects
-   are underspecified in system documentation.
-
-   .. warning::
-
-      Use of :func:`tempnam` is vulnerable to symlink attacks; consider using
-      :func:`tmpfile` (section :ref:`os-newstreams`) instead.
-
-   Availability: Macintosh, Unix, Windows.
-
-
-.. function:: tmpnam()
-
-   Return a unique path name that is reasonable for creating a temporary file.
-   This will be an absolute path that names a potential directory entry in a common
-   location for temporary files.  Applications are responsible for properly
-   creating and managing files created using paths returned by :func:`tmpnam`; no
-   automatic cleanup is provided.
-
-   .. warning::
-
-      Use of :func:`tmpnam` is vulnerable to symlink attacks; consider using
-      :func:`tmpfile` (section :ref:`os-newstreams`) instead.
-
-   Availability: Unix, Windows.  This function probably shouldn't be used on
-   Windows, though: Microsoft's implementation of :func:`tmpnam` always creates a
-   name in the root directory of the current drive, and that's generally a poor
-   location for a temp file (depending on privileges, you may not even be able to
-   open a file using this name).
-
-
-.. data:: TMP_MAX
-
-   The maximum number of unique names that :func:`tmpnam` will generate before
-   reusing names.
-
-
 .. function:: unlink(path)
 
    Remove the file *path*.  This is the same function as :func:`remove`; the
@@ -1152,8 +1117,8 @@
       single: directory; walking
       single: directory; traversal
 
-   :func:`walk` generates the file names in a directory tree, by walking the tree
-   either top down or bottom up. For each directory in the tree rooted at directory
+   Generate the file names in a directory tree by walking the tree
+   either top-down or bottom-up. For each directory in the tree rooted at directory
    *top* (including *top* itself), it yields a 3-tuple ``(dirpath, dirnames,
    filenames)``.
 
@@ -1164,34 +1129,34 @@
    (which begins with *top*) to a file or directory in *dirpath*, do
    ``os.path.join(dirpath, name)``.
 
-   If optional argument *topdown* is true or not specified, the triple for a
+   If optional argument *topdown* is ``True`` or not specified, the triple for a
    directory is generated before the triples for any of its subdirectories
-   (directories are generated top down).  If *topdown* is false, the triple for a
+   (directories are generated top-down).  If *topdown* is ``False``, the triple for a
    directory is generated after the triples for all of its subdirectories
-   (directories are generated bottom up).
+   (directories are generated bottom-up).
 
-   When *topdown* is true, the caller can modify the *dirnames* list in-place
+   When *topdown* is ``True``, the caller can modify the *dirnames* list in-place
    (perhaps using :keyword:`del` or slice assignment), and :func:`walk` will only
    recurse into the subdirectories whose names remain in *dirnames*; this can be
    used to prune the search, impose a specific order of visiting, or even to inform
    :func:`walk` about directories the caller creates or renames before it resumes
-   :func:`walk` again.  Modifying *dirnames* when *topdown* is false is
+   :func:`walk` again.  Modifying *dirnames* when *topdown* is ``False`` is
    ineffective, because in bottom-up mode the directories in *dirnames* are
    generated before *dirpath* itself is generated.
 
-   By default errors from the ``os.listdir()`` call are ignored.  If optional
+   By default errors from the :func:`listdir` call are ignored.  If optional
    argument *onerror* is specified, it should be a function; it will be called with
    one argument, an :exc:`OSError` instance.  It can report the error to continue
    with the walk, or raise the exception to abort the walk.  Note that the filename
    is available as the ``filename`` attribute of the exception object.
 
    By default, :func:`walk` will not walk down into symbolic links that resolve to
-   directories. Set *followlinks* to True to visit directories pointed to by
+   directories. Set *followlinks* to ``True`` to visit directories pointed to by
    symlinks, on systems that support them.
 
    .. note::
 
-      Be aware that setting *followlinks* to true can lead to infinite recursion if a
+      Be aware that setting *followlinks* to ``True`` can lead to infinite recursion if a
       link points to a parent directory of itself. :func:`walk` does not keep track of
       the directories it visited already.
 
@@ -1214,10 +1179,10 @@
           if 'CVS' in dirs:
               dirs.remove('CVS')  # don't visit CVS directories
 
-   In the next example, walking the tree bottom up is essential: :func:`rmdir`
+   In the next example, walking the tree bottom-up is essential: :func:`rmdir`
    doesn't allow deleting a directory before the directory is empty::
 
-      # Delete everything reachable from the directory named in 'top',
+      # Delete everything reachable from the directory named in "top",
       # assuming there are no symbolic links.
       # CAUTION:  This is dangerous!  For example, if top == '/', it
       # could delete all your disk files.
@@ -1265,19 +1230,19 @@
 
    These functions all execute a new program, replacing the current process; they
    do not return.  On Unix, the new executable is loaded into the current process,
-   and will have the same process ID as the caller.  Errors will be reported as
+   and will have the same process id as the caller.  Errors will be reported as
    :exc:`OSError` exceptions.
 
-   The ``'l'`` and ``'v'`` variants of the :func:`exec\*` functions differ in how
-   command-line arguments are passed.  The ``'l'`` variants are perhaps the easiest
+   The "l" and "v" variants of the :func:`exec\*` functions differ in how
+   command-line arguments are passed.  The "l" variants are perhaps the easiest
    to work with if the number of parameters is fixed when the code is written; the
    individual parameters simply become additional parameters to the :func:`execl\*`
-   functions.  The ``'v'`` variants are good when the number of parameters is
+   functions.  The "v" variants are good when the number of parameters is
    variable, with the arguments being passed in a list or tuple as the *args*
    parameter.  In either case, the arguments to the child process should start with
    the name of the command being run, but this is not enforced.
 
-   The variants which include a ``'p'`` near the end (:func:`execlp`,
+   The variants which include a "p" near the end (:func:`execlp`,
    :func:`execlpe`, :func:`execvp`, and :func:`execvpe`) will use the
    :envvar:`PATH` environment variable to locate the program *file*.  When the
    environment is being replaced (using one of the :func:`exec\*e` variants,
@@ -1288,7 +1253,7 @@
    path.
 
    For :func:`execle`, :func:`execlpe`, :func:`execve`, and :func:`execvpe` (note
-   that these all end in ``'e'``), the *env* parameter must be a mapping which is
+   that these all end in "e"), the *env* parameter must be a mapping which is
    used to define the environment variables for the new process; the :func:`execl`,
    :func:`execlp`, :func:`execv`, and :func:`execvp` all cause the new process to
    inherit the environment of the current process. Availability: Macintosh, Unix,
@@ -1305,7 +1270,7 @@
       The standard way to exit is ``sys.exit(n)``. :func:`_exit` should normally only
       be used in the child process after a :func:`fork`.
 
-The following exit codes are a defined, and can be used with :func:`_exit`,
+The following exit codes are defined and can be used with :func:`_exit`,
 although they are not required.  These are typically used for system programs
 written in Python, such as a mail server's external command delivery program.
 
@@ -1421,8 +1386,9 @@
 
 .. function:: fork()
 
-   Fork a child process.  Return ``0`` in the child, the child's process id in the
-   parent. Availability: Macintosh, Unix.
+   Fork a child process.  Return ``0`` in the child and the child's process id in the
+   parent.  If an error occurs :exc:`OSError` is raised.
+   Availability: Macintosh, Unix.
 
 
 .. function:: forkpty()
@@ -1431,7 +1397,8 @@
    terminal. Return a pair of ``(pid, fd)``, where *pid* is ``0`` in the child, the
    new child's process id in the parent, and *fd* is the file descriptor of the
    master end of the pseudo-terminal.  For a more portable approach, use the
-   :mod:`pty` module. Availability: Macintosh, Some flavors of Unix.
+   :mod:`pty` module.  If an error occurs :exc:`OSError` is raised.
+   Availability: Macintosh, some flavors of Unix.
 
 
 .. function:: kill(pid, sig)
@@ -1490,22 +1457,22 @@
    spawning new processes and retrieving their results; using that module is
    preferable to using these functions.)
 
-   If *mode* is :const:`P_NOWAIT`, this function returns the process ID of the new
+   If *mode* is :const:`P_NOWAIT`, this function returns the process id of the new
    process; if *mode* is :const:`P_WAIT`, returns the process's exit code if it
    exits normally, or ``-signal``, where *signal* is the signal that killed the
-   process.  On Windows, the process ID will actually be the process handle, so can
+   process.  On Windows, the process id will actually be the process handle, so can
    be used with the :func:`waitpid` function.
 
-   The ``'l'`` and ``'v'`` variants of the :func:`spawn\*` functions differ in how
-   command-line arguments are passed.  The ``'l'`` variants are perhaps the easiest
+   The "l" and "v" variants of the :func:`spawn\*` functions differ in how
+   command-line arguments are passed.  The "l" variants are perhaps the easiest
    to work with if the number of parameters is fixed when the code is written; the
    individual parameters simply become additional parameters to the
-   :func:`spawnl\*` functions.  The ``'v'`` variants are good when the number of
+   :func:`spawnl\*` functions.  The "v" variants are good when the number of
    parameters is variable, with the arguments being passed in a list or tuple as
    the *args* parameter.  In either case, the arguments to the child process must
    start with the name of the command being run.
 
-   The variants which include a second ``'p'`` near the end (:func:`spawnlp`,
+   The variants which include a second "p" near the end (:func:`spawnlp`,
    :func:`spawnlpe`, :func:`spawnvp`, and :func:`spawnvpe`) will use the
    :envvar:`PATH` environment variable to locate the program *file*.  When the
    environment is being replaced (using one of the :func:`spawn\*e` variants,
@@ -1516,7 +1483,7 @@
    appropriate absolute or relative path.
 
    For :func:`spawnle`, :func:`spawnlpe`, :func:`spawnve`, and :func:`spawnvpe`
-   (note that these all end in ``'e'``), the *env* parameter must be a mapping
+   (note that these all end in "e"), the *env* parameter must be a mapping
    which is used to define the environment variables for the new process; the
    :func:`spawnl`, :func:`spawnlp`, :func:`spawnv`, and :func:`spawnvp` all cause
    the new process to inherit the environment of the current process.
@@ -1539,7 +1506,7 @@
 
    Possible values for the *mode* parameter to the :func:`spawn\*` family of
    functions.  If either of these values is given, the :func:`spawn\*` functions
-   will return as soon as the new process has been created, with the process ID as
+   will return as soon as the new process has been created, with the process id as
    the return value. Availability: Macintosh, Unix, Windows.
 
 
@@ -1590,8 +1557,8 @@
 
    Execute the command (a string) in a subshell.  This is implemented by calling
    the Standard C function :cfunc:`system`, and has the same limitations.  Changes
-   to ``posix.environ``, ``sys.stdin``, etc. are not reflected in the environment
-   of the executed command.
+   to :data:`os.environ`, :data:`sys.stdin`, etc. are not reflected in the
+   environment of the executed command.
 
    On Unix, the return value is the exit status of the process encoded in the
    format specified for :func:`wait`.  Note that POSIX does not specify the meaning
@@ -1619,7 +1586,7 @@
    user time, children's system time, and elapsed real time since a fixed point in
    the past, in that order.  See the Unix manual page :manpage:`times(2)` or the
    corresponding Windows Platform API documentation. Availability: Macintosh, Unix,
-   Windows.
+   Windows.  On Windows, only the first two items are filled, the others are zero.
 
 
 .. function:: wait()
@@ -1702,32 +1669,32 @@
 
 .. function:: WCOREDUMP(status)
 
-   Returns ``True`` if a core dump was generated for the process, otherwise it
-   returns ``False``. Availability: Macintosh, Unix.
+   Return ``True`` if a core dump was generated for the process, otherwise
+   return ``False``. Availability: Macintosh, Unix.
 
 
 .. function:: WIFCONTINUED(status)
 
-   Returns ``True`` if the process has been continued from a job control stop,
-   otherwise it returns ``False``. Availability: Unix.
+   Return ``True`` if the process has been continued from a job control stop,
+   otherwise return ``False``. Availability: Unix.
 
 
 .. function:: WIFSTOPPED(status)
 
-   Returns ``True`` if the process has been stopped, otherwise it returns
+   Return ``True`` if the process has been stopped, otherwise return
    ``False``. Availability: Unix.
 
 
 .. function:: WIFSIGNALED(status)
 
-   Returns ``True`` if the process exited due to a signal, otherwise it returns
+   Return ``True`` if the process exited due to a signal, otherwise return
    ``False``. Availability: Macintosh, Unix.
 
 
 .. function:: WIFEXITED(status)
 
-   Returns ``True`` if the process exited using the :manpage:`exit(2)` system call,
-   otherwise it returns ``False``. Availability: Macintosh, Unix.
+   Return ``True`` if the process exited using the :manpage:`exit(2)` system call,
+   otherwise return ``False``. Availability: Macintosh, Unix.
 
 
 .. function:: WEXITSTATUS(status)
@@ -1784,8 +1751,8 @@
 
 .. function:: getloadavg()
 
-   Return the number of processes in the system run queue averaged over the last 1,
-   5, and 15 minutes or raises :exc:`OSError` if the load  average was
+   Return the number of processes in the system run queue averaged over the last
+   1, 5, and 15 minutes or raises :exc:`OSError` if the load average was
    unobtainable.
 
 
@@ -1804,7 +1771,7 @@
    defined for those names by the host operating system. This can be used to
    determine the set of names known to the system. Availability: Macintosh, Unix.
 
-The follow data values are used to support path manipulation operations.  These
+The following data values are used to support path manipulation operations.  These
 are defined for all platforms.
 
 Higher-level operations on pathnames are defined in the :mod:`os.path` module.

Modified: python/branches/py3k-importlib/Doc/library/ossaudiodev.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/ossaudiodev.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/ossaudiodev.rst	Thu Mar 27 00:48:05 2008
@@ -11,33 +11,33 @@
 OSS is available for a wide range of open-source and commercial Unices, and is
 the standard audio interface for Linux and recent versions of FreeBSD.
 
-.. % Things will get more complicated for future Linux versions, since
-.. % ALSA is in the standard kernel as of 2.5.x.  Presumably if you
-.. % use ALSA, you'll have to make sure its OSS compatibility layer
-.. % is active to use ossaudiodev, but you're gonna need it for the vast
-.. % majority of Linux audio apps anyways.
-.. % 
-.. % Sounds like things are also complicated for other BSDs.  In response
-.. % to my python-dev query, Thomas Wouters said:
-.. % 
-.. % > Likewise, googling shows OpenBSD also uses OSS/Free -- the commercial
-.. % > OSS installation manual tells you to remove references to OSS/Free from the
-.. % > kernel :)
-.. % 
-.. % but Aleksander Piotrowsk actually has an OpenBSD box, and he quotes
-.. % from its <soundcard.h>:
-.. % >  * WARNING!  WARNING!
-.. % >  * This is an OSS (Linux) audio emulator.
-.. % >  * Use the Native NetBSD API for developing new code, and this
-.. % >  * only for compiling Linux programs.
-.. % 
-.. % There's also an ossaudio manpage on OpenBSD that explains things
-.. % further.  Presumably NetBSD and OpenBSD have a different standard
-.. % audio interface.  That's the great thing about standards, there are so
-.. % many to choose from ... ;-)
-.. % 
-.. % This probably all warrants a footnote or two, but I don't understand
-.. % things well enough right now to write it!   --GPW
+.. Things will get more complicated for future Linux versions, since
+   ALSA is in the standard kernel as of 2.5.x.  Presumably if you
+   use ALSA, you'll have to make sure its OSS compatibility layer
+   is active to use ossaudiodev, but you're gonna need it for the vast
+   majority of Linux audio apps anyways.
+   
+   Sounds like things are also complicated for other BSDs.  In response
+   to my python-dev query, Thomas Wouters said:
+   
+   > Likewise, googling shows OpenBSD also uses OSS/Free -- the commercial
+   > OSS installation manual tells you to remove references to OSS/Free from the
+   > kernel :)
+   
+   but Aleksander Piotrowsk actually has an OpenBSD box, and he quotes
+   from its <soundcard.h>:
+   >  * WARNING!  WARNING!
+   >  * This is an OSS (Linux) audio emulator.
+   >  * Use the Native NetBSD API for developing new code, and this
+   >  * only for compiling Linux programs.
+   
+   There's also an ossaudio manpage on OpenBSD that explains things
+   further.  Presumably NetBSD and OpenBSD have a different standard
+   audio interface.  That's the great thing about standards, there are so
+   many to choose from ... ;-)
+   
+   This probably all warrants a footnote or two, but I don't understand
+   things well enough right now to write it!   --GPW
 
 
 .. seealso::
@@ -87,6 +87,10 @@
    second is required.  This is a historical artifact for compatibility with the
    older :mod:`linuxaudiodev` module which :mod:`ossaudiodev` supersedes.
 
+   .. XXX it might also be motivated
+      by my unfounded-but-still-possibly-true belief that the default
+      audio device varies unpredictably across operating systems.  -GW
+
 
 .. function:: openmixer([device])
 

Modified: python/branches/py3k-importlib/Doc/library/othergui.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/othergui.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/othergui.rst	Thu Mar 27 00:48:05 2008
@@ -5,7 +5,6 @@
 
 There are an number of extension widget sets to :mod:`Tkinter`.
 
-
 .. seealso::
 
    `Python megawidgets <http://pmw.sourceforge.net/>`_
@@ -29,26 +28,22 @@
       since they can operate directly on Python data structures, without having to
       transfer data through the Tk/Tcl layer.
 
-      .. % 
 
 The major cross-platform (Windows, Mac OS X, Unix-like) GUI toolkits that are
 also available for Python:
 
-
 .. seealso::
 
    `PyGTK <http://www.pygtk.org/>`_
       is a set of bindings for the `GTK <http://www.gtk.org/>`_ widget set. It
-      provides an object oriented interface that is slightly higher level than the C
-      one. It comes with many more widgets than Tkinter provides, and
-      has good Python-specific reference documentation. There are also `bindings
-      <http://www.daa.com.au/~james/gnome/>`_ to  `GNOME <http://www.gnome.org>`_.
-      One well known PyGTK application is
-      `PythonCAD <http://www.pythoncad.org/>`_. An
-      online `tutorial <http://www.pygtk.org/pygtk2tutorial/index.html>`_ is
-      available.
+      provides an object oriented interface that is slightly higher level than
+      the C one. It comes with many more widgets than Tkinter provides, and has
+      good Python-specific reference documentation. There are also bindings to
+      `GNOME <http://www.gnome.org>`_.  One well known PyGTK application is
+      `PythonCAD <http://www.pythoncad.org/>`_. An online `tutorial
+      <http://www.pygtk.org/pygtk2tutorial/index.html>`_ is available.
 
-   `PyQt <//http://www.riverbankcomputing.co.uk/pyqt/index.php>`_
+   `PyQt <http://www.riverbankcomputing.co.uk/pyqt/index.php>`_
       PyQt is a :program:`sip`\ -wrapped binding to the Qt toolkit.  Qt is an
       extensive C++ GUI application development framework that is
       available for Unix, Windows and Mac OS X. :program:`sip` is a tool
@@ -63,14 +58,14 @@
    `wxPython <http://www.wxpython.org>`_
       wxPython is a cross-platform GUI toolkit for Python that is built around
       the popular `wxWidgets <http://www.wxwidgets.org/>`_ (formerly wxWindows)
-      C++ toolkit.  It provides a native look and feel for applications on
+      C++ toolkit.  It provides a native look and feel for applications on
       Windows, Mac OS X, and Unix systems by using each platform's native
-      widgets where ever possible, (GTK+ on Unix-like systems).  In addition to
+      widgets where ever possible, (GTK+ on Unix-like systems).  In addition to
       an extensive set of widgets, wxPython provides classes for online
       documentation and context sensitive help, printing, HTML viewing,
       low-level device context drawing, drag and drop, system clipboard access,
       an XML-based resource format and more, including an ever growing library
-      of user-contributed modules.  wxPython has a book, `wxPython in Action
+      of user-contributed modules.  wxPython has a book, `wxPython in Action
       <http://www.amazon.com/exec/obidos/ASIN/1932394621>`_, by Noel Rappin and
       Robin Dunn.
 

Modified: python/branches/py3k-importlib/Doc/library/parser.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/parser.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/parser.rst	Thu Mar 27 00:48:05 2008
@@ -8,13 +8,12 @@
 .. sectionauthor:: Fred L. Drake, Jr. <fdrake at acm.org>
 
 
-.. % Copyright 1995 Virginia Polytechnic Institute and State University
-.. % and Fred L. Drake, Jr.  This copyright notice must be distributed on
-.. % all copies, but this document otherwise may be distributed as part
-.. % of the Python distribution.  No fee may be charged for this document
-.. % in any representation, either on paper or electronically.  This
-.. % restriction does not affect other elements in a distributed package
-.. % in any way.
+.. Copyright 1995 Virginia Polytechnic Institute and State University and Fred
+   L. Drake, Jr.  This copyright notice must be distributed on all copies, but
+   this document otherwise may be distributed as part of the Python
+   distribution.  No fee may be charged for this document in any representation,
+   either on paper or electronically.  This restriction does not affect other
+   elements in a distributed package in any way.
 
 .. index:: single: parsing; Python source code
 
@@ -321,7 +320,7 @@
 .. index:: builtin: compile
 
 The parser modules allows operations to be performed on the parse tree of Python
-source code before the bytecode is generated, and provides for inspection of the
+source code before the :term:`bytecode` is generated, and provides for inspection of the
 parse tree for information gathering purposes. Two examples are presented.  The
 simple example demonstrates emulation of the :func:`compile` built-in function
 and the complex example shows the use of a parse tree for information discovery.

Modified: python/branches/py3k-importlib/Doc/library/pdb.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/pdb.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/pdb.rst	Thu Mar 27 00:48:05 2008
@@ -103,9 +103,12 @@
    being debugged (e.g. when an assertion fails).
 
 
-.. function:: post_mortem(traceback)
+.. function:: post_mortem([traceback])
 
-   Enter post-mortem debugging of the given *traceback* object.
+   Enter post-mortem debugging of the given *traceback* object.  If no 
+   *traceback* is given, it uses the one of the exception that is currently
+   being handled (an exception must be being handled if the default is to be
+   used).
 
 
 .. function:: pm()
@@ -239,7 +242,7 @@
    Specifying any command resuming execution (currently continue, step, next,
    return, jump, quit and their abbreviations) terminates the command list (as if
    that command was immediately followed by end). This is because any time you
-   resume execution (even with a simple next or step), you may encounter· another
+   resume execution (even with a simple next or step), you may encounter another
    breakpoint--which could have its own command list, leading to ambiguities about
    which list to execute.
 
@@ -323,7 +326,7 @@
       (Pdb)
 
 run [*args* ...]
-   Restart the debugged python program. If an argument is supplied, it is splitted
+   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".
 

Modified: python/branches/py3k-importlib/Doc/library/pickle.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/pickle.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/pickle.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`pickle` --- Python object serialization
 =============================================
 
@@ -12,10 +11,8 @@
 
 .. module:: pickle
    :synopsis: Convert Python objects to streams of bytes and back.
-
-
-.. % Substantial improvements by Jim Kerr <jbkerr at sr.hp.com>.
-.. % Rewritten by Barry Warsaw <barry at zope.com>
+.. sectionauthor:: Jim Kerr <jbkerr at sr.hp.com>.
+.. sectionauthor:: Barry Warsaw <barry at zope.com>
 
 The :mod:`pickle` module implements a fundamental, but powerful algorithm for
 serializing and de-serializing a Python object structure.  "Pickling" is the
@@ -122,7 +119,7 @@
   earlier versions of Python.
 
 * Protocol version 2 was introduced in Python 2.3.  It provides much more
-  efficient pickling of new-style classes.
+  efficient pickling of :term:`new-style class`\es.
 
 Refer to :pep:`307` for more information.
 
@@ -328,9 +325,9 @@
 
 * ``None``, ``True``, and ``False``
 
-* integers, long integers, floating point numbers, complex numbers
+* integers, floating point numbers, complex numbers
 
-* normal and Unicode strings
+* strings, bytes, bytearrays
 
 * tuples, lists, sets, and dictionaries containing only picklable objects
 
@@ -418,8 +415,8 @@
 protocol 2.  Implementing this method is needed if the type establishes some
 internal invariants when the instance is created, or if the memory allocation is
 affected by the values passed to the :meth:`__new__` method for the type (as it
-is for tuples and strings).  Instances of a new-style type :class:`C` are
-created using ::
+is for tuples and strings).  Instances of a :term:`new-style class` :class:`C`
+are created using ::
 
    obj = C.__new__(C, *args)
 
@@ -447,13 +444,18 @@
 
 .. warning::
 
-   For new-style classes, if :meth:`__getstate__` returns a false value, the
-   :meth:`__setstate__` method will not be called.
+   For :term:`new-style class`\es, if :meth:`__getstate__` returns a false
+   value, the :meth:`__setstate__` method will not be called.
 
 
 Pickling and unpickling extension types
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
+.. index::
+   single: __reduce__() (pickle protocol)
+   single: __reduce_ex__() (pickle protocol)
+   single: __safe_for_unpickling__ (pickle protocol)
+
 When the :class:`Pickler` encounters an object of a type it knows nothing about
 --- such as an extension type --- it looks in two places for a hint of how to
 pickle it.  One alternative is for the object to implement a :meth:`__reduce__`
@@ -529,6 +531,10 @@
 Pickling and unpickling external objects
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
+.. index::
+   single: persistent_id (pickle protocol)
+   single: persistent_load (pickle protocol)
+
 For the benefit of object persistence, the :mod:`pickle` module supports the
 notion of a reference to an object outside the pickled data stream.  Such
 objects are referenced by a "persistent id", which is just an arbitrary string
@@ -607,10 +613,10 @@
 [#]_  Setting :attr:`persistent_load` to a list is usually used in conjunction
 with the :meth:`noload` method on the Unpickler.
 
-.. % BAW: Both pickle and cPickle support something called
-.. % inst_persistent_id() which appears to give unknown types a second
-.. % shot at producing a persistent id.  Since Jim Fulton can't remember
-.. % why it was added or what it's for, I'm leaving it undocumented.
+.. BAW: Both pickle and cPickle support something called inst_persistent_id()
+   which appears to give unknown types a second shot at producing a persistent
+   id.  Since Jim Fulton can't remember why it was added or what it's for, I'm
+   leaving it undocumented.
 
 
 .. _pickle-sub:
@@ -618,6 +624,10 @@
 Subclassing Unpicklers
 ----------------------
 
+.. index::
+   single: load_global() (pickle protocol)
+   single: find_global() (pickle protocol)
+
 By default, unpickling will import any class that it finds in the pickle data.
 You can control exactly what gets unpickled and what gets called by customizing
 your unpickler.  Unfortunately, exactly how you do this is different depending
@@ -662,7 +672,7 @@
    import pickle
 
    data1 = {'a': [1, 2.0, 3, 4+6j],
-            'b': ('string', u'Unicode string'),
+            'b': ("string", "string using Unicode features \u0394"),
             'c': None}
 
    selfref_list = [1, 2, 3]

Modified: python/branches/py3k-importlib/Doc/library/pickletools.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/pickletools.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/pickletools.rst	Thu Mar 27 00:48:05 2008
@@ -27,9 +27,16 @@
 
 .. function:: genops(pickle)
 
-   Provides an iterator over all of the opcodes in a pickle, returning a sequence
-   of ``(opcode, arg, pos)`` triples. *opcode* is an instance of an
-   :class:`OpcodeInfo` class; *arg*  is the decoded value, as a Python object, of
-   the opcode's argument;  *pos* is the position at which this opcode is located.
+   Provides an :term:`iterator` over all of the opcodes in a pickle, returning a
+   sequence of ``(opcode, arg, pos)`` triples.  *opcode* is an instance of an
+   :class:`OpcodeInfo` class; *arg* is the decoded value, as a Python object, of
+   the opcode's argument; *pos* is the position at which this opcode is located.
    *pickle* can be a string or a file-like object.
 
+.. function:: optimize(picklestring)
+
+   Returns a new equivalent pickle string after eliminating unused ``PUT``
+   opcodes. The optimized pickle is shorter, takes less transmission time,
+   requires less storage space, and unpickles more efficiently.
+
+   .. versionadded:: 2.6

Modified: python/branches/py3k-importlib/Doc/library/pkgutil.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/pkgutil.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/pkgutil.rst	Thu Mar 27 00:48:05 2008
@@ -34,8 +34,7 @@
    returned.  Items are only appended to the copy at the end.
 
    It is assumed that ``sys.path`` is a sequence.  Items of ``sys.path`` that are
-   not (Unicode or 8-bit) strings referring to existing directories are ignored.
-   Unicode items on ``sys.path`` that cause errors when used as filenames may cause
-   this function to raise an exception (in line with :func:`os.path.isdir`
-   behavior).
+   not strings referring to existing directories are ignored. Unicode items on
+   ``sys.path`` that cause errors when used as filenames may cause this function
+   to raise an exception (in line with :func:`os.path.isdir` behavior).
 

Modified: python/branches/py3k-importlib/Doc/library/platform.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/platform.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/platform.rst	Thu Mar 27 00:48:05 2008
@@ -187,23 +187,21 @@
 
    .. note::
 
-      This function only works if Mark Hammond's :mod:`win32all` package is installed
-      and (obviously) only runs on Win32 compatible platforms.
+      Note: this function works best with Mark Hammond's
+      :mod:`win32all` package installed, but also on Python 2.3 and
+      later (support for this was added in Python 2.6). It obviously
+      only runs on Win32 compatible platforms.
 
 
 Win95/98 specific
 ^^^^^^^^^^^^^^^^^
 
-
 .. function:: popen(cmd, mode='r', bufsize=None)
 
    Portable :func:`popen` interface.  Find a working popen implementation
    preferring :func:`win32pipe.popen`.  On Windows NT, :func:`win32pipe.popen`
    should work; on Windows 9x it hangs due to bugs in the MS C library.
 
-   .. % This KnowledgeBase article appears to be missing...
-   .. % See also \ulink{MS KnowledgeBase article Q150956}{}.
-
 
 Mac OS Platform
 ---------------
@@ -226,13 +224,31 @@
 --------------
 
 
-.. function:: dist(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake'))
+.. function:: dist(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...))
 
    Tries to determine the name of the OS distribution name Returns a tuple
    ``(distname, version, id)`` which defaults to the args given as parameters.
 
-.. % Document linux_distribution()?
+   ``supported_dists`` may be given to define the set of Linux
+   distributions to look for. It defaults to a list of currently
+   supported Linux distributions identified by their release file
+   name.
+
+.. function:: linux_distribution(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...), full_distribution_name=1)
+
+   Tries to determine the name of the Linux OS distribution name.
+
+   ``supported_dists`` may be given to define the set of Linux
+   distributions to look for. It defaults to a list of currently
+   supported Linux distributions identified by their release file
+   name.
+
+   If ``full_distribution_name`` is true (default), the full
+   distribution read from the OS is returned. Otherwise the short name
+   taken from ``supported_dists`` is used.
 
+   Returns a tuple ``(distname,version,id)`` which defaults to the
+   args given as parameters.
 
 .. function:: libc_ver(executable=sys.executable, lib='', version='', chunksize=2048)
 
@@ -241,7 +257,7 @@
    version)`` which default to the given parameters in case the lookup fails.
 
    Note that this function has intimate knowledge of how different libc versions
-   add symbols to the executable is probably only useable for executables compiled
+   add symbols to the executable is probably only usable for executables compiled
    using :program:`gcc`.
 
    The file is read and scanned in chunks of *chunksize* bytes.

Modified: python/branches/py3k-importlib/Doc/library/poplib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/poplib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/poplib.rst	Thu Mar 27 00:48:05 2008
@@ -4,16 +4,11 @@
 
 .. module:: poplib
    :synopsis: POP3 protocol client (requires sockets).
-
+.. sectionauthor:: Andrew T. Csillag
+.. revised by ESR, January 2000
 
 .. index:: pair: POP3; protocol
 
-.. % By Andrew T. Csillag
-.. % Even though I put it into LaTeX, I cannot really claim that I wrote
-.. % it since I just stole most of it from the poplib.py source code and
-.. % the imaplib ``chapter''.
-.. % Revised by ESR, January 2000
-
 This module defines a class, :class:`POP3`, which encapsulates a connection to a
 POP3 server and implements the protocol as defined in :rfc:`1725`.  The
 :class:`POP3` class supports both the minimal and optional command sets.

Modified: python/branches/py3k-importlib/Doc/library/posix.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/posix.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/posix.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`posix` --- The most common POSIX system calls
 ===================================================
 
@@ -22,13 +21,8 @@
 :mod:`os` provides some additional functionality, such as automatically calling
 :func:`putenv` when an entry in ``os.environ`` is changed.
 
-The descriptions below are very terse; refer to the corresponding Unix manual
-(or POSIX documentation) entry for more information. Arguments called *path*
-refer to a pathname given as a string.
-
 Errors are reported as exceptions; the usual exceptions are given for type
-errors, while errors reported by the system calls raise :exc:`error` (a synonym
-for the standard exception :exc:`OSError`), described below.
+errors, while errors reported by the system calls raise :exc:`OSError`.
 
 
 .. _posix-large-files:
@@ -42,17 +36,15 @@
 
 .. sectionauthor:: Steve Clift <clift at mail.anacapa.net>
 
-
-Several operating systems (including AIX, HPUX, Irix and Solaris) provide
-support for files that are larger than 2 Gb from a C programming model where
+Several operating systems (including AIX, HP-UX, Irix and Solaris) provide
+support for files that are larger than 2 GB from a C programming model where
 :ctype:`int` and :ctype:`long` are 32-bit values. This is typically accomplished
 by defining the relevant size and offset types as 64-bit values. Such files are
 sometimes referred to as :dfn:`large files`.
 
 Large file support is enabled in Python when the size of an :ctype:`off_t` is
 larger than a :ctype:`long` and the :ctype:`long long` type is available and is
-at least as large as an :ctype:`off_t`. Python longs are then used to represent
-file sizes, offsets and other values that can exceed the range of a Python int.
+at least as large as an :ctype:`off_t`.
 It may be necessary to configure and compile Python with certain compiler flags
 to enable this mode. For example, it is enabled by default with recent versions
 of Irix, but with Solaris 2.6 and 2.7 you need to do something like::
@@ -68,16 +60,16 @@
 
 .. _posix-contents:
 
-Module Contents
----------------
-
-Module :mod:`posix` defines the following data item:
+Notable Module Contents
+-----------------------
 
+In addition to many functions described in the :mod:`os` module documentation,
+:mod:`posix` defines the following data item:
 
 .. data:: environ
 
-   A dictionary representing the string environment at the time the interpreter was
-   started. For example, ``environ['HOME']`` is the pathname of your home
+   A dictionary representing the string environment at the time the interpreter
+   was started.  For example, ``environ['HOME']`` is the pathname of your home
    directory, equivalent to ``getenv("HOME")`` in C.
 
    Modifying this dictionary does not affect the string environment passed on by
@@ -91,7 +83,3 @@
       updates the environment on modification.  Note also that updating ``os.environ``
       will render this dictionary obsolete.  Use of the :mod:`os` module version of
       this is recommended over direct access to the :mod:`posix` module.
-
-Additional contents of this module should only be accessed via the :mod:`os`
-module; refer to the documentation for that module for further information.
-

Modified: python/branches/py3k-importlib/Doc/library/pprint.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/pprint.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/pprint.rst	Thu Mar 27 00:48:05 2008
@@ -22,9 +22,12 @@
 
 Dictionaries are sorted by key before the display is computed.
 
+.. versionchanged:: 2.6
+   Added support for :class:`set` and :class:`frozenset`.
+
 The :mod:`pprint` module defines one class:
 
-.. % First the implementation class:
+.. First the implementation class:
 
 
 .. class:: PrettyPrinter(...)
@@ -43,37 +46,29 @@
    the depth of the objects being formatted.  The desired output width is
    constrained using the *width* parameter; the default is 80 characters.  If a
    structure cannot be formatted within the constrained width, a best effort will
-   be made. ::
+   be made.
 
-      >>> import pprint, sys
-      >>> stuff = sys.path[:]
+      >>> import pprint
+      >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
       >>> stuff.insert(0, stuff[:])
       >>> pp = pprint.PrettyPrinter(indent=4)
       >>> pp.pprint(stuff)
-      [   [   '',
-              '/usr/local/lib/python1.5',
-              '/usr/local/lib/python1.5/test',
-              '/usr/local/lib/python1.5/sunos5',
-              '/usr/local/lib/python1.5/sharedmodules',
-              '/usr/local/lib/python1.5/tkinter'],
-          '',
-          '/usr/local/lib/python1.5',
-          '/usr/local/lib/python1.5/test',
-          '/usr/local/lib/python1.5/sunos5',
-          '/usr/local/lib/python1.5/sharedmodules',
-          '/usr/local/lib/python1.5/tkinter']
-      >>>
-      >>> import parser
-      >>> tup = parser.ast2tuple(
-      ...     parser.suite(open('pprint.py').read()))[1][1][1]
+      [   [   'spam', 'eggs', 'lumberjack', 'knights', 'ni'],
+          'spam',
+          'eggs',
+          'lumberjack',
+          'knights',
+          'ni']
+      >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead',
+      ... ('parrot', ('fresh fruit',))))))))
       >>> pp = pprint.PrettyPrinter(depth=6)
       >>> pp.pprint(tup)
-      (266, (267, (307, (287, (288, (...))))))
+      ('spam',
+       ('eggs', ('lumberjack', ('knights', ('ni', ('dead', ('parrot', (...,))))))))
 
 The :class:`PrettyPrinter` class supports several derivative functions:
 
-.. % Now the derivative functions:
-
+.. Now the derivative functions:
 
 .. function:: pformat(object[, indent[, width[, depth]]])
 
@@ -89,18 +84,18 @@
    in the interactive interpreter instead of the :func:`print` function for
    inspecting values (you can even reassign ``print = pprint.pprint`` for use
    within a scope).  *indent*, *width* and *depth* will be passed to the
-   :class:`PrettyPrinter` constructor as formatting parameters. ::
+   :class:`PrettyPrinter` constructor as formatting parameters.
 
-      >>> stuff = sys.path[:]
+      >>> import pprint
+      >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
       >>> stuff.insert(0, stuff)
       >>> pprint.pprint(stuff)
-      [<Recursion on list with id=869440>,
-       '',
-       '/usr/local/lib/python1.5',
-       '/usr/local/lib/python1.5/test',
-       '/usr/local/lib/python1.5/sunos5',
-       '/usr/local/lib/python1.5/sharedmodules',
-       '/usr/local/lib/python1.5/tkinter']
+      [<Recursion on list with id=...>,
+       'spam',
+       'eggs',
+       'lumberjack',
+       'knights',
+       'ni']
 
 
 .. function:: isreadable(object)
@@ -109,7 +104,7 @@
 
    Determine if the formatted representation of *object* is "readable," or can be
    used to reconstruct the value using :func:`eval`.  This always returns ``False``
-   for recursive objects. ::
+   for recursive objects.
 
       >>> pprint.isreadable(stuff)
       False
@@ -119,8 +114,8 @@
 
    Determine if *object* requires a recursive representation.
 
-One more support function is also defined:
 
+One more support function is also defined:
 
 .. function:: saferepr(object)
 
@@ -129,15 +124,8 @@
    recursive reference will be represented as ``<Recursion on typename with
    id=number>``.  The representation is not otherwise formatted.
 
-.. % This example is outside the {funcdesc} to keep it from running over
-.. % the right margin.
-
-::
-
    >>> pprint.saferepr(stuff)
-   "[<Recursion on list with id=682968>, '', '/usr/local/lib/python1.5', '/usr/loca
-   l/lib/python1.5/test', '/usr/local/lib/python1.5/sunos5', '/usr/local/lib/python
-   1.5/sharedmodules', '/usr/local/lib/python1.5/tkinter']"
+   "[<Recursion on list with id=...>, 'spam', 'eggs', 'lumberjack', 'knights', 'ni']"
 
 
 .. _prettyprinter-objects:
@@ -200,3 +188,40 @@
    is no requested limit.  This argument should be passed unmodified to recursive
    calls. The fourth argument, *level*, gives the current level; recursive calls
    should be passed a value less than that of the current call.
+
+
+.. _pprint-example:
+
+pprint Example
+--------------
+
+This example demonstrates several uses of the :func:`pprint` function and its parameters.
+
+   >>> import pprint
+   >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead',
+   ... ('parrot', ('fresh fruit',))))))))
+   >>> stuff = ['a' * 10, tup, ['a' * 30, 'b' * 30], ['c' * 20, 'd' * 20]]
+   >>> pprint.pprint(stuff)
+   ['aaaaaaaaaa',
+    ('spam',
+     ('eggs',
+      ('lumberjack',
+       ('knights', ('ni', ('dead', ('parrot', ('fresh fruit',)))))))),
+    ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
+    ['cccccccccccccccccccc', 'dddddddddddddddddddd']]
+   >>> pprint.pprint(stuff, depth=3)
+   ['aaaaaaaaaa',
+    ('spam', ('eggs', ('lumberjack', (...)))),
+    ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
+    ['cccccccccccccccccccc', 'dddddddddddddddddddd']]
+   >>> pprint.pprint(stuff, width=60)
+   ['aaaaaaaaaa',
+    ('spam',
+     ('eggs',
+      ('lumberjack',
+       ('knights',
+        ('ni', ('dead', ('parrot', ('fresh fruit',)))))))),
+    ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
+     'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
+    ['cccccccccccccccccccc', 'dddddddddddddddddddd']]
+

Modified: python/branches/py3k-importlib/Doc/library/profile.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/profile.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/profile.rst	Thu Mar 27 00:48:05 2008
@@ -72,47 +72,47 @@
 :mod:`cProfile` is really a compatibility layer on top of the internal
 :mod:`_lsprof` module.
 
-.. % \section{How Is This Profiler Different From The Old Profiler?}
-.. % \nodename{Profiler Changes}
-.. % 
-.. % (This section is of historical importance only; the old profiler
-.. % discussed here was last seen in Python 1.1.)
-.. % 
-.. % The big changes from old profiling module are that you get more
-.. % information, and you pay less CPU time.  It's not a trade-off, it's a
-.. % trade-up.
-.. % 
-.. % To be specific:
-.. % 
-.. % \begin{description}
-.. % 
-.. % \item[Bugs removed:]
-.. % Local stack frame is no longer molested, execution time is now charged
-.. % to correct functions.
-.. % 
-.. % \item[Accuracy increased:]
-.. % Profiler execution time is no longer charged to user's code,
-.. % calibration for platform is supported, file reads are not done \emph{by}
-.. % profiler \emph{during} profiling (and charged to user's code!).
-.. % 
-.. % \item[Speed increased:]
-.. % Overhead CPU cost was reduced by more than a factor of two (perhaps a
-.. % factor of five), lightweight profiler module is all that must be
-.. % loaded, and the report generating module (\module{pstats}) is not needed
-.. % during profiling.
-.. % 
-.. % \item[Recursive functions support:]
-.. % Cumulative times in recursive functions are correctly calculated;
-.. % recursive entries are counted.
-.. % 
-.. % \item[Large growth in report generating UI:]
-.. % Distinct profiles runs can be added together forming a comprehensive
-.. % report; functions that import statistics take arbitrary lists of
-.. % files; sorting criteria is now based on keywords (instead of 4 integer
-.. % options); reports shows what functions were profiled as well as what
-.. % profile file was referenced; output format has been improved.
-.. % 
-.. % \end{description}
+.. \section{How Is This Profiler Different From The Old Profiler?}
+   \nodename{Profiler Changes}
+   
+   (This section is of historical importance only; the old profiler
+   discussed here was last seen in Python 1.1.)
+   
+   The big changes from old profiling module are that you get more
+   information, and you pay less CPU time.  It's not a trade-off, it's a
+   trade-up.
+   
+   To be specific:
+   
+   \begin{description}
+   
+   \item[Bugs removed:]
+   Local stack frame is no longer molested, execution time is now charged
+   to correct functions.
+   
+   \item[Accuracy increased:]
+   Profiler execution time is no longer charged to user's code,
+   calibration for platform is supported, file reads are not done \emph{by}
+   profiler \emph{during} profiling (and charged to user's code!).
+   
+   \item[Speed increased:]
+   Overhead CPU cost was reduced by more than a factor of two (perhaps a
+   factor of five), lightweight profiler module is all that must be
+   loaded, and the report generating module (\module{pstats}) is not needed
+   during profiling.
+   
+   \item[Recursive functions support:]
+   Cumulative times in recursive functions are correctly calculated;
+   recursive entries are counted.
+   
+   \item[Large growth in report generating UI:]
+   Distinct profiles runs can be added together forming a comprehensive
+   report; functions that import statistics take arbitrary lists of
+   files; sorting criteria is now based on keywords (instead of 4 integer
+   options); reports shows what functions were profiled as well as what
+   profile file was referenced; output format has been improved.
+   
+   \end{description}
 
 
 .. _profile-instant:
@@ -172,7 +172,7 @@
 string that is printed. The third method printed out all the statistics.  You
 might try the following sort calls:
 
-.. % (this is to comply with the semantics of the old profiler).
+.. (this is to comply with the semantics of the old profiler).
 
 ::
 
@@ -363,6 +363,8 @@
    a single report.  If additional files need to be combined with data in an
    existing :class:`Stats` object, the :meth:`add` method can be used.
 
+   .. (such as the old system profiler).
+
 
 .. _profile-stats:
 
@@ -457,7 +459,7 @@
    (numeric) is used, only one sort key (the numeric key) will be used, and
    additional arguments will be silently ignored.
 
-   .. % For compatibility with the old profiler,
+   .. For compatibility with the old profiler,
 
 
 .. method:: Stats.reverse_order()
@@ -466,8 +468,7 @@
    within the object.  Note that by default ascending vs descending order is
    properly selected based on the sort key of choice.
 
-   .. % This method is provided primarily for
-   .. % compatibility with the old profiler.
+   .. This method is provided primarily for compatibility with the old profiler.
 
 
 .. method:: Stats.print_stats([restriction, ...])
@@ -512,7 +513,7 @@
      non-parenthesized number repeats the cumulative time spent in the function
      at the right.
 
-   * With :mod:`cProfile`, each caller is preceeded by three numbers: the number of
+   * With :mod:`cProfile`, each caller is preceded by three numbers: the number of
      times this specific call was made, and the total and cumulative times spent in
      the current function while it was invoked by this specific caller.
 

Modified: python/branches/py3k-importlib/Doc/library/pty.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/pty.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/pty.rst	Thu Mar 27 00:48:05 2008
@@ -43,6 +43,6 @@
    reading from the controlling terminal.
 
    The functions *master_read* and *stdin_read* should be functions which read from
-   a file-descriptor. The defaults try to read 1024 bytes each time they are
+   a file descriptor. The defaults try to read 1024 bytes each time they are
    called.
 

Modified: python/branches/py3k-importlib/Doc/library/py_compile.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/py_compile.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/py_compile.rst	Thu Mar 27 00:48:05 2008
@@ -3,11 +3,8 @@
 
 .. module:: py_compile
    :synopsis: Generate byte-code files from Python source files.
-
-.. % Documentation based on module docstrings, by Fred L. Drake, Jr.
-.. % <fdrake at acm.org>
-
-
+.. sectionauthor:: Fred L. Drake, Jr. <fdrake at acm.org>
+.. documentation based on module docstrings
 
 .. index:: pair: file; byte-code
 
@@ -45,7 +42,12 @@
    structure to locate source files; it only compiles files named explicitly.
 
 When this module is run as a script, the :func:`main` is used to compile all the
-files named on the command line.
+files named on the command line.  The exit status is nonzero if one of the files
+could not be compiled.
+
+.. versionchanged:: 2.6
+
+   Added the nonzero exit status.
 
 
 .. seealso::

Modified: python/branches/py3k-importlib/Doc/library/pyclbr.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/pyclbr.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/pyclbr.rst	Thu Mar 27 00:48:05 2008
@@ -19,12 +19,12 @@
 .. function:: readmodule(module[, path])
 
    Read a module and return a dictionary mapping class names to class descriptor
-   objects.  The parameter *module* should be the name of a module as a string; it
-   may be the name of a module within a package.  The *path* parameter should be a
-   sequence, and is used to augment the value of ``sys.path``, which is used to
-   locate module source code.
+   objects.  The parameter *module* should be the name of a module as a string;
+   it may be the name of a module within a package.  The *path* parameter should
+   be a sequence, and is used to augment the value of ``sys.path``, which is
+   used to locate module source code.
 
-   .. % The 'inpackage' parameter appears to be for internal use only....
+   .. The 'inpackage' parameter appears to be for internal use only....
 
 
 .. function:: readmodule_ex(module[, path])
@@ -35,7 +35,7 @@
    the key ``'__path__'`` in the returned dictionary has as its value a list which
    contains the package search path.
 
-   .. % The 'inpackage' parameter appears to be for internal use only....
+   .. The 'inpackage' parameter appears to be for internal use only....
 
 
 .. _pyclbr-class-objects:

Modified: python/branches/py3k-importlib/Doc/library/pydoc.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/pydoc.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/pydoc.rst	Thu Mar 27 00:48:05 2008
@@ -57,7 +57,7 @@
 Python interpreter and typed ``import spam``.
 
 Module docs for core modules are assumed to reside in
-http://www.python.org/doc/current/lib/.  This can be overridden by setting the
+http://docs.python.org/library/.  This can be overridden by setting the
 :envvar:`PYTHONDOCS` environment variable to a different URL or to a local
 directory containing the Library Reference Manual pages.
 

Modified: python/branches/py3k-importlib/Doc/library/pyexpat.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/pyexpat.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/pyexpat.rst	Thu Mar 27 00:48:05 2008
@@ -7,14 +7,13 @@
 .. moduleauthor:: Paul Prescod <paul at prescod.net>
 
 
-.. % Markup notes:
-.. % 
-.. % Many of the attributes of the XMLParser objects are callbacks.
-.. % Since signature information must be presented, these are described
-.. % using the methoddesc environment.  Since they are attributes which
-.. % are set by client code, in-text references to these attributes
-.. % should be marked using the \member macro and should not include the
-.. % parentheses used when marking functions and methods.
+.. Markup notes:
+
+   Many of the attributes of the XMLParser objects are callbacks.  Since
+   signature information must be presented, these are described using the method
+   directive.  Since they are attributes which are set by client code, in-text
+   references to these attributes should be marked using the :member: role.
+
 
 .. index:: single: Expat
 
@@ -63,7 +62,7 @@
    must be a string naming the encoding  used by the XML data.  Expat doesn't
    support as many encodings as Python does, and its repertoire of encodings can't
    be extended; it supports UTF-8, UTF-16, ISO-8859-1 (Latin1), and ASCII.  If
-   *encoding* is given it will override the implicit or explicit encoding of the
+   *encoding* [1]_ is given it will override the implicit or explicit encoding of the
    document.
 
    Expat can optionally do XML namespace processing for you, enabled by providing a
@@ -178,8 +177,13 @@
 
 .. attribute:: xmlparser.buffer_size
 
-   The size of the buffer used when :attr:`buffer_text` is true.  This value cannot
-   be changed at this time.
+   The size of the buffer used when :attr:`buffer_text` is true.  
+   A new buffer size can be set by assigning a new integer value 
+   to this attribute.  
+   When the size is changed, the buffer will be flushed.
+
+   .. versionchanged:: 2.6
+      The buffer size can now be changed.
 
 
 .. attribute:: xmlparser.buffer_text
@@ -844,3 +848,11 @@
 .. data:: XML_ERROR_SUSPEND_PE
    :noindex:
 
+
+.. 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
+   and http://www.iana.org/assignments/character-sets .
+

Modified: python/branches/py3k-importlib/Doc/library/python.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/python.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/python.rst	Thu Mar 27 00:48:05 2008
@@ -13,7 +13,8 @@
 .. toctree::
 
    sys.rst
-   __builtin__.rst
+   builtins.rst
+   future_builtins.rst
    __main__.rst
    warnings.rst
    contextlib.rst

Modified: python/branches/py3k-importlib/Doc/library/queue.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/queue.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/queue.rst	Thu Mar 27 00:48:05 2008
@@ -6,24 +6,54 @@
    :synopsis: A synchronized queue class.
 
 
-The :mod:`Queue` module implements a multi-producer, multi-consumer FIFO queue.
+The :mod:`Queue` module implements multi-producer, multi-consumer queues.
 It is especially useful in threaded programming when information must be
 exchanged safely between multiple threads.  The :class:`Queue` class in this
 module implements all the required locking semantics.  It depends on the
 availability of thread support in Python; see the :mod:`threading`
 module.
 
-The :mod:`Queue` module defines the following class and exception:
+Implements three types of queue whose only difference is the order that
+the entries are retrieved.  In a FIFO queue, the first tasks added are
+the first retrieved. In a LIFO queue, the most recently added entry is
+the first retrieved (operating like a stack).  With a priority queue,
+the entries are kept sorted (using the :mod:`heapq` module) and the
+lowest valued entry is retrieved first.
 
+The :mod:`Queue` module defines the following classes and exceptions:
 
 .. class:: Queue(maxsize)
 
-   Constructor for the class.  *maxsize* is an integer that sets the upperbound
+   Constructor for a FIFO queue.  *maxsize* is an integer that sets the upperbound
    limit on the number of items that can be placed in the queue.  Insertion will
    block once this size has been reached, until queue items are consumed.  If
    *maxsize* is less than or equal to zero, the queue size is infinite.
 
 
+.. class:: LifoQueue(maxsize)
+
+   Constructor for a LIFO queue.  *maxsize* is an integer that sets the upperbound
+   limit on the number of items that can be placed in the queue.  Insertion will
+   block once this size has been reached, until queue items are consumed.  If
+   *maxsize* is less than or equal to zero, the queue size is infinite.
+
+   .. versionadded:: 2.6
+
+
+.. class:: PriorityQueue(maxsize)
+
+   Constructor for a priority queue.  *maxsize* is an integer that sets the upperbound
+   limit on the number of items that can be placed in the queue.  Insertion will
+   block once this size has been reached, until queue items are consumed.  If
+   *maxsize* is less than or equal to zero, the queue size is infinite.
+
+   The lowest valued entries are retrieved first (the lowest valued entry is the
+   one returned by ``sorted(list(entries))[0]``).  A typical pattern for entries
+   is a tuple in the form: ``(priority_number, data)``.
+
+   .. versionadded:: 2.6
+
+
 .. exception:: Empty
 
    Exception raised when non-blocking :meth:`get` (or :meth:`get_nowait`) is called
@@ -41,28 +71,15 @@
 Queue Objects
 -------------
 
-Class :class:`Queue` implements queue objects and has the methods described
-below.  This class can be derived from in order to implement other queue
-organizations (e.g. stack) but the inheritable interface is not described here.
-See the source code for details.  The public methods are:
+Queue objects (:class:`Queue`, :class:`LifoQueue`, or :class:`PriorityQueue`)
+provide the public methods described below.  
 
 
 .. method:: Queue.qsize()
 
-   Return the approximate size of the queue.  Because of multithreading semantics,
-   this number is not reliable.
-
-
-.. method:: Queue.empty()
-
-   Return ``True`` if the queue is empty, ``False`` otherwise. Because of
-   multithreading semantics, this is not reliable.
-
-
-.. method:: Queue.full()
-
-   Return ``True`` if the queue is full, ``False`` otherwise. Because of
-   multithreading semantics, this is not reliable.
+   Return the approximate size of the queue.  Note, qsize() > 0 doesn't
+   guarantee that a subsequent get() will not block, nor will qsize() < maxsize
+   guarantee that put() will not block.
 
 
 .. method:: Queue.put(item[, block[, timeout]])

Modified: python/branches/py3k-importlib/Doc/library/random.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/random.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/random.rst	Thu Mar 27 00:48:05 2008
@@ -28,25 +28,14 @@
 
 The functions supplied by this module are actually bound methods of a hidden
 instance of the :class:`random.Random` class.  You can instantiate your own
-instances of :class:`Random` to get generators that don't share state.  This is
-especially useful for multi-threaded programs, creating a different instance of
-:class:`Random` for each thread, and using the :meth:`jumpahead` method to make
-it likely that the generated sequences seen by each thread don't overlap.
+instances of :class:`Random` to get generators that don't share state.
 
 Class :class:`Random` can also be subclassed if you want to use a different
 basic generator of your own devising: in that case, override the :meth:`random`,
-:meth:`seed`, :meth:`getstate`, :meth:`setstate` and :meth:`jumpahead` methods.
+:meth:`seed`, :meth:`getstate`, and :meth:`setstate`.
 Optionally, a new generator can supply a :meth:`getrandombits` method --- this
 allows :meth:`randrange` to produce selections over an arbitrarily large range.
 
-As an example of subclassing, the :mod:`random` module provides the
-:class:`WichmannHill` class that implements an alternative generator in pure
-Python.  The class provides a backward compatible way to reproduce results from
-earlier versions of Python, which used the Wichmann-Hill algorithm as the core
-generator.  Note that this Wichmann-Hill generator can no longer be recommended:
-its period is too short by contemporary standards, and the sequence generated is
-known to fail some stringent randomness tests.  See the references below for a
-recent variant that repairs these flaws.
 
 Bookkeeping functions:
 
@@ -54,14 +43,14 @@
 .. function:: seed([x])
 
    Initialize the basic random number generator. Optional argument *x* can be any
-   hashable object. If *x* is omitted or ``None``, current system time is used;
+   :term:`hashable` object. If *x* is omitted or ``None``, current system time is used;
    current system time is also used to initialize the generator when the module is
    first imported.  If randomness sources are provided by the operating system,
    they are used instead of the system time (see the :func:`os.urandom` function
    for details on availability).
 
-   If *x* is not ``None`` or an int or long, ``hash(x)`` is used instead. If *x* is
-   an int or long, *x* is used directly.
+   If *x* is not ``None`` or an int, ``hash(x)`` is used instead. If *x* is an
+   int, *x* is used directly.
 
 
 .. function:: getstate()
@@ -69,6 +58,8 @@
    Return an object capturing the current internal state of the generator.  This
    object can be passed to :func:`setstate` to restore the state.
 
+   State values produced in Python 2.6 cannot be loaded into earlier versions.
+
 
 .. function:: setstate(state)
 
@@ -82,7 +73,7 @@
    Change the internal state to one different from and likely far away from the
    current state.  *n* is a non-negative integer which is used to scramble the
    current state vector.  This is most useful in multi-threaded programs, in
-   conjuction with multiple instances of the :class:`Random` class:
+   conjunction with multiple instances of the :class:`Random` class:
    :meth:`setstate` or :meth:`seed` can be used to force all instances into the
    same internal state, and then :meth:`jumpahead` can be used to force the
    instances' states far apart.
@@ -90,8 +81,8 @@
 
 .. function:: getrandbits(k)
 
-   Returns a python :class:`long` int with *k* random bits. This method is supplied
-   with the MersenneTwister generator and some other generators may also provide it
+   Returns a python integer with *k* random bits. This method is supplied with
+   the MersenneTwister generator and some other generators may also provide it
    as an optional part of the API. When available, :meth:`getrandbits` enables
    :meth:`randrange` to handle arbitrarily large ranges.
 
@@ -131,8 +122,8 @@
 
 .. function:: sample(population, k)
 
-   Return a *k* length list of unique elements chosen from the population sequence.
-   Used for random sampling without replacement.
+   Return a *k* length list of unique elements chosen from the population sequence
+   or set. Used for random sampling without replacement.
 
    Returns a new list containing elements from the population while leaving the
    original population unchanged.  The resulting list is in selection order so that
@@ -140,7 +131,7 @@
    (the sample) to be partitioned into grand prize and second place winners (the
    subslices).
 
-   Members of the population need not be hashable or unique.  If the population
+   Members of the population need not be :term:`hashable` or unique.  If the population
    contains repeats, then each occurrence is a possible selection in the sample.
 
    To choose a sample from a range of integers, use an :func:`range` object as an
@@ -162,6 +153,15 @@
 
    Return a random floating point number *N* such that ``a <= N < b``.
 
+.. function:: triangular(low, high, mode)
+
+   Return a random floating point number *N* such that ``low <= N < high``
+   and with the specified *mode* between those bounds.
+
+   If *mode* is not specified or is ``None``, it defaults to the midpoint
+   between the upper and lower bounds, producing a symmetric distribution.
+
+   The default values for *low* and *high* are zero and one.
 
 .. function:: betavariate(alpha, beta)
 
@@ -222,24 +222,6 @@
 
 Alternative Generators:
 
-.. class:: WichmannHill([seed])
-
-   Class that implements the Wichmann-Hill algorithm as the core generator. Has all
-   of the same methods as :class:`Random` plus the :meth:`whseed` method described
-   below.  Because this class is implemented in pure Python, it is not threadsafe
-   and may require locks between calls.  The period of the generator is
-   6,953,607,871,644 which is small enough to require care that two independent
-   random sequences do not overlap.
-
-
-.. function:: whseed([x])
-
-   This is obsolete, supplied for bit-level compatibility with versions of Python
-   prior to 2.1. See :func:`seed` for details.  :func:`whseed` does not guarantee
-   that distinct integer arguments yield distinct internal states, and can yield no
-   more than about 2\*\*24 distinct internal states in all.
-
-
 .. class:: SystemRandom([seed])
 
    Class that uses the :func:`os.urandom` function for generating random numbers
@@ -279,11 +261,4 @@
    equidistributed uniform pseudorandom number generator", ACM Transactions on
    Modeling and Computer Simulation Vol. 8, No. 1, January pp.3-30 1998.
 
-   Wichmann, B. A. & Hill, I. D., "Algorithm AS 183: An efficient and portable
-   pseudo-random number generator", Applied Statistics 31 (1982) 188-190.
-
-   http://www.npl.co.uk/ssfm/download/abstracts.html#196
-      A modern variation of the Wichmann-Hill generator that greatly increases the
-      period, and passes now-standard statistical tests that the original generator
-      failed.
 

Modified: python/branches/py3k-importlib/Doc/library/re.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/re.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/re.rst	Thu Mar 27 00:48:05 2008
@@ -28,14 +28,19 @@
 patterns; backslashes are not handled in any special way in a string literal
 prefixed with ``'r'``.  So ``r"\n"`` is a two-character string containing
 ``'\'`` and ``'n'``, while ``"\n"`` is a one-character string containing a
-newline. Usually patterns will be expressed in Python code using this raw string
-notation.
+newline.  Usually patterns will be expressed in Python code using this raw
+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
+fine-tuning parameters.
 
 .. seealso::
 
    Mastering Regular Expressions
       Book on regular expressions by Jeffrey Friedl, published by O'Reilly.  The
-      second  edition of the book no longer covers Python at all,  but the first
+      second edition of the book no longer covers Python at all, but the first
       edition covered writing good regular expression patterns in great detail.
 
 
@@ -60,8 +65,7 @@
 above, or almost any textbook about compiler construction.
 
 A brief explanation of the format of regular expressions follows.  For further
-information and a gentler presentation, consult the Regular Expression HOWTO,
-accessible from http://www.python.org/doc/howto/.
+information and a gentler presentation, consult the :ref:`regex-howto`.
 
 Regular expressions can contain both special and ordinary characters. Most
 ordinary characters, like ``'A'``, ``'a'``, or ``'0'``, are the simplest regular
@@ -79,8 +83,6 @@
 
 The special characters are:
 
-.. % 
-
 ``'.'``
    (Dot.)  In the default mode, this matches any character except a newline.  If
    the :const:`DOTALL` flag has been specified, this matches any character
@@ -95,7 +97,9 @@
    string, and in :const:`MULTILINE` mode also matches before a newline.  ``foo``
    matches both 'foo' and 'foobar', while the regular expression ``foo$`` matches
    only 'foo'.  More interestingly, searching for ``foo.$`` in ``'foo1\nfoo2\n'``
-   matches 'foo2' normally, but 'foo1' in :const:`MULTILINE` mode.
+   matches 'foo2' normally, but 'foo1' in :const:`MULTILINE` mode; searching for
+   a single ``$`` in ``'foo\n'`` will find two (empty) matches: one just before
+   the newline, and one at the end of the string.
 
 ``'*'``
    Causes the resulting RE to match 0 or more repetitions of the preceding RE, as
@@ -260,14 +264,14 @@
    ``abc`` or ``a|b`` are allowed, but ``a*`` and ``a{3,4}`` are not.  Note that
    patterns which start with positive lookbehind assertions will never match at the
    beginning of the string being searched; you will most likely want to use the
-   :func:`search` function rather than the :func:`match` function::
+   :func:`search` function rather than the :func:`match` function:
 
       >>> import re
       >>> m = re.search('(?<=abc)def', 'abcdef')
       >>> m.group(0)
       'def'
 
-   This example looks for a word following a hyphen::
+   This example looks for a word following a hyphen:
 
       >>> m = re.search('(?<=-)\w+', 'spam-egg')
       >>> m.group(0)
@@ -292,8 +296,6 @@
 If the ordinary character is not on the list, then the resulting RE will match
 the second character.  For example, ``\$`` matches the character ``'$'``.
 
-.. % 
-
 ``\number``
    Matches the contents of the group of the same number.  Groups are numbered
    starting from 1.  For example, ``(.+) \1`` matches ``'the the'`` or ``'55 55'``,
@@ -379,9 +381,6 @@
 a group reference.  As for string literals, octal escapes are always at most
 three digits in length.
 
-.. % Note the lack of a period in the section title; it causes problems
-.. % with readers of the GNU info version.  See http://www.python.org/sf/581414.
-
 
 .. _matching-searching:
 
@@ -403,15 +402,9 @@
 regardless of mode, or at the starting position given by the optional *pos*
 argument regardless of whether a newline precedes it.
 
-.. % Examples from Tim Peters:
-
-::
-
-   re.compile("a").match("ba", 1)           # succeeds
-   re.compile("^a").search("ba", 1)         # fails; 'a' not at start
-   re.compile("^a").search("\na", 1)        # fails; 'a' not at start
-   re.compile("^a", re.M).search("\na", 1)  # succeeds
-   re.compile("^a", re.M).search("ba", 1)   # fails; no preceding \n
+   >>> re.match("c", "abcdef")  # No match
+   >>> re.search("c", "abcdef") # Match
+   <_sre.SRE_Match object at ...>
 
 
 .. _contents-of-module-re:
@@ -427,8 +420,8 @@
 
 .. function:: compile(pattern[, flags])
 
-   Compile a regular expression pattern into a regular expression object, which can
-   be used for matching using its :func:`match` and :func:`search` methods,
+   Compile a regular expression pattern into a regular expression object, which
+   can be used for matching using its :func:`match` and :func:`search` methods,
    described below.
 
    The expression's behaviour can be modified by specifying a *flags* value.
@@ -444,13 +437,12 @@
 
       result = re.match(pat, str)
 
-   but the version using :func:`compile` is more efficient when the expression will
-   be used several times in a single program.
+   but the version using :func:`compile` is more efficient when the expression
+   will be used several times in a single program.
 
-   .. % (The compiled version of the last pattern passed to
-   .. % \function{re.match()} or \function{re.search()} is cached, so
-   .. % programs that use only a single regular expression at a time needn't
-   .. % worry about compiling regular expressions.)
+   .. (The compiled version of the last pattern passed to :func:`re.match` or
+      :func:`re.search` is cached, so programs that use only a single regular
+      expression at a time needn't worry about compiling regular expressions.)
 
 
 .. data:: I
@@ -463,8 +455,8 @@
 .. data:: L
           LOCALE
 
-   Make ``\w``, ``\W``, ``\b``, ``\B``, ``\s`` and ``\S`` dependent on the current
-   locale.
+   Make ``\w``, ``\W``, ``\b``, ``\B``, ``\s`` and ``\S`` dependent on the
+   current locale.
 
 
 .. data:: M
@@ -501,12 +493,13 @@
    character class or preceded by an unescaped backslash, all characters from the
    leftmost such ``'#'`` through the end of the line are ignored.
 
-   This means that the two following regular expression objects are equal::
+   That means that the two following regular expression objects that match a
+   decimal number are functionally equal::
 
-      re.compile(r""" [a-z]+   # some letters
-                      \.\.     # two dots
-                      [a-z]*   # perhaps more letters""")
-      re.compile(r"[a-z]+\.\.[a-z]*")
+      a = re.compile(r"""\d +  # the integral part
+                         \.    # the decimal point
+                         \d *  # some fractional digits""", re.X)
+      b = re.compile(r"\d+\.\d*")
 
 
 .. function:: search(pattern, string[, flags])
@@ -527,7 +520,8 @@
 
    .. note::
 
-      If you want to locate a match anywhere in *string*, use :meth:`search` instead.
+      If you want to locate a match anywhere in *string*, use :meth:`search`
+      instead.
 
 
 .. function:: split(pattern, string[, maxsplit=0])
@@ -536,8 +530,7 @@
    used in *pattern*, then the text of all groups in the pattern are also returned
    as part of the resulting list. If *maxsplit* is nonzero, at most *maxsplit*
    splits occur, and the remainder of the string is returned as the final element
-   of the list.  (Incompatibility note: in the original Python 1.5 release,
-   *maxsplit* was ignored.  This has been fixed in later releases.) ::
+   of the list. ::
 
       >>> re.split('\W+', 'Words, words, words.')
       ['Words', 'words', 'words', '']
@@ -546,27 +539,40 @@
       >>> re.split('\W+', 'Words, words, words.', 1)
       ['Words', 'words, words.']
 
+   If there are capturing groups in the separator and it matches at the start of
+   the string, the result will start with an empty string.  The same holds for
+   the end of the string:
+
+      >>> re.split('(\W+)', '...words, words...')
+      ['', '...', 'words', ', ', 'words', '...', '']
+
+   That way, separator components are always found at the same relative
+   indices within the result list (e.g., if there's one capturing group
+   in the separator, the 0th, the 2nd and so forth).
+
    Note that *split* will never split a string on an empty pattern match.
-   For example ::
+   For example:
 
       >>> re.split('x*', 'foo')
       ['foo']
       >>> re.split("(?m)^$", "foo\n\nbar\n")
       ['foo\n\nbar\n']
 
+
 .. function:: findall(pattern, string[, flags])
 
-   Return a list of all non-overlapping matches of *pattern* in *string*.  If one
-   or more groups are present in the pattern, return a list of groups; this will be
-   a list of tuples if the pattern has more than one group.  Empty matches are
-   included in the result unless they touch the beginning of another match.
+   Return all non-overlapping matches of *pattern* in *string*, as a list of
+   strings.  If one or more groups are present in the pattern, return a list of
+   groups; this will be a list of tuples if the pattern has more than one group.
+   Empty matches are included in the result unless they touch the beginning of
+   another match.
 
 
 .. function:: finditer(pattern, string[, flags])
 
-   Return an iterator over all non-overlapping matches for the RE *pattern* in
-   *string*.  For each match, the iterator returns a match object.  Empty matches
-   are included in the result unless they touch the beginning of another match.
+   Return an :term:`iterator` yielding :class:`MatchObject` instances over all
+   non-overlapping matches for the RE *pattern* in *string*.  Empty matches are
+   included in the result unless they touch the beginning of another match.
 
 
 .. function:: sub(pattern, repl, string[, count])
@@ -578,7 +584,7 @@
    converted to a single newline character, ``\r`` is converted to a linefeed, and
    so forth.  Unknown escapes such as ``\j`` are left alone.  Backreferences, such
    as ``\6``, are replaced with the substring matched by group 6 in the pattern.
-   For example::
+   For example:
 
       >>> re.sub(r'def\s+([a-zA-Z_][a-zA-Z_0-9]*)\s*\(\s*\):',
       ...        r'static PyObject*\npy_\1(void)\n{',
@@ -587,7 +593,7 @@
 
    If *repl* is a function, it is called for every non-overlapping occurrence of
    *pattern*.  The function takes a single match object argument, and returns the
-   replacement string.  For example::
+   replacement string.  For example:
 
       >>> def dashrepl(matchobj):
       ...     if matchobj.group(0) == '-': return ' '
@@ -654,7 +660,8 @@
 
    .. note::
 
-      If you want to locate a match anywhere in *string*, use :meth:`search` instead.
+      If you want to locate a match anywhere in *string*, use :meth:`search`
+      instead.
 
    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
@@ -669,6 +676,11 @@
    expression object, ``rx.match(string, 0, 50)`` is equivalent to
    ``rx.match(string[:50], 0)``.
 
+      >>> 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.search(string[, pos[, endpos]])
 
@@ -729,7 +741,9 @@
 Match Objects
 -------------
 
-:class:`MatchObject` instances support the following methods and attributes:
+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)
@@ -755,34 +769,75 @@
    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<int>\d+)\.(\d*)", '3.14')
+   A moderately complicated example:
 
-   After performing this match, ``m.group(1)`` is ``'3'``, as is
-   ``m.group('int')``, and ``m.group(2)`` is ``'14'``.
+      >>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcom Reynolds")
+      >>> m.group('first_name')
+      'Malcom'
+      >>> m.group('last_name')
+      'Reynolds'
+
+   Named groups can also be referred to by their index:
+
+      >>> m.group(1)
+      'Malcom'
+      >>> 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])
 
    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.)
+   did not participate in the match; it defaults to ``None``.
+
+   For example:
+
+      >>> 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:
+
+      >>> 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])
 
    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``.
+   participate in the match; it defaults to ``None``.  For example:
+
+      >>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcom Reynolds")
+      >>> m.groupdict()
+      {'first_name': 'Malcom', 'last_name': 'Reynolds'}
 
 
 .. method:: MatchObject.start([group])
@@ -801,12 +856,19 @@
    ``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:
+
+      >>> 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])
 
    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)``.  Again, *group* defaults to zero.
+   ``(-1, -1)``.  *group* defaults to zero, the entire match.
 
 
 .. attribute:: MatchObject.pos
@@ -852,7 +914,66 @@
 Examples
 --------
 
-**Simulating scanf()**
+
+Checking For a Pair
+^^^^^^^^^^^^^^^^^^^
+
+In this example, we'll use the following helper function to display match
+objects a little more gracefully:
+
+.. testcode::
+
+   def displaymatch(match):
+       if match is None:
+           return None
+       return '<Match: %r, groups=%r>' % (match.group(), match.groups())
+
+Suppose you are writing a poker program where a player's hand is represented as
+a 5-character string with each character representing a card, "a" for ace, "k"
+for king, "q" for queen, j for jack, "0" for 10, and "1" through "9"
+representing the card with that value.
+
+To see if a given string is a valid hand, one could do the following:
+
+   >>> valid = re.compile(r"[0-9akqj]{5}$")
+   >>> displaymatch(valid.match("ak05q"))  # Valid.
+   "<Match: 'ak05q', groups=()>"
+   >>> displaymatch(valid.match("ak05e"))  # Invalid.
+   >>> displaymatch(valid.match("ak0"))    # Invalid.
+   >>> displaymatch(valid.match("727ak"))  # Valid.
+   "<Match: '727ak', groups=()>"
+
+That last hand, ``"727ak"``, contained a pair, or two of the same valued cards.
+To match this with a regular expression, one could use backreferences as such:
+
+   >>> pair = re.compile(r".*(.).*\1")
+   >>> displaymatch(pair.match("717ak"))     # Pair of 7s.
+   "<Match: '717', groups=('7',)>"
+   >>> displaymatch(pair.match("718ak"))     # No pairs.
+   >>> displaymatch(pair.match("354aa"))     # Pair of aces.
+   "<Match: '354aa', groups=('a',)>"
+
+To find out what card the pair consists of, one could use the :func:`group`
+method of :class:`MatchObject` in the following manner:
+
+.. doctest::
+
+   >>> pair.match("717ak").group(1)
+   '7'
+   
+   # Error because re.match() returns None, which doesn't have a group() method:
+   >>> pair.match("718ak").group(1)
+   Traceback (most recent call last):
+     File "<pyshell#23>", line 1, in <module>
+       re.match(r".*(.).*\1", "718ak").group(1)
+   AttributeError: 'NoneType' object has no attribute 'group'
+   
+   >>> pair.match("354aa").group(1)
+   'a'
+
+
+Simulating scanf()
+^^^^^^^^^^^^^^^^^^
 
 .. index:: single: scanf()
 
@@ -896,13 +1017,14 @@
 
    (\S+) - (\d+) errors, (\d+) warnings
 
-**Avoiding recursion**
+
+Avoiding recursion
+^^^^^^^^^^^^^^^^^^
 
 If you create regular expressions that require the engine to perform a lot of
 recursion, you may encounter a :exc:`RuntimeError` exception with the message
 ``maximum recursion limit`` exceeded. For example, ::
 
-   >>> import re
    >>> s = 'Begin ' + 1000*'a very long string ' + 'end'
    >>> re.match('Begin (\w| )*? end', s).end()
    Traceback (most recent call last):
@@ -918,3 +1040,165 @@
 being recast as ``Begin [a-zA-Z0-9_ ]*?end``.  As a further benefit, such
 regular expressions will run faster than their recursive equivalents.
 
+
+search() vs. match()
+^^^^^^^^^^^^^^^^^^^^
+
+In a nutshell, :func:`match` only attempts to match a pattern at the beginning
+of a string where :func:`search` will match a pattern anywhere in a string.
+For example:
+
+   >>> re.match("o", "dog")  # No match as "o" is not the first letter of "dog".
+   >>> re.search("o", "dog") # Match as search() looks everywhere in the string.
+   <_sre.SRE_Match object at ...>
+
+.. note::
+
+   The following applies only to regular expression objects like those created
+   with ``re.compile("pattern")``, not the primitives ``re.match(pattern,
+   string)`` or ``re.search(pattern, string)``.
+
+:func:`match` has an optional second parameter that gives an index in the string
+where the search is to start:
+
+   >>> pattern = re.compile("o")
+   >>> pattern.match("dog")      # No match as "o" is not at the start of "dog."
+
+   # Equivalent to the above expression as 0 is the default starting index:
+   >>> pattern.match("dog", 0)
+
+   # Match as "o" is the 2nd character of "dog" (index 0 is the first):
+   >>> pattern.match("dog", 1)
+   <_sre.SRE_Match object at ...>
+   >>> pattern.match("dog", 2)   # No match as "o" is not the 3rd character of "dog."
+
+
+Making a Phonebook
+^^^^^^^^^^^^^^^^^^
+
+:func:`split` splits a string into a list delimited by the passed pattern.  The 
+method is invaluable for converting textual data into data structures that can be
+easily read and modified by Python as demonstrated in the following example that
+creates a phonebook.
+
+First, here is the input.  Normally it may come from a file, here we are using
+triple-quoted string syntax:
+
+   >>> input = """Ross McFluff: 834.345.1254 155 Elm Street
+   ... 
+   ... Ronald Heathmore: 892.345.3428 436 Finley Avenue
+   ... Frank Burger: 925.541.7625 662 South Dogwood Way
+   ...
+   ...
+   ... Heather Albrecht: 548.326.4584 919 Park Place"""
+
+The entries are separated by one or more newlines. Now we convert the string
+into a list with each nonempty line having its own entry:
+
+.. doctest::
+   :options: +NORMALIZE_WHITESPACE
+
+   >>> entries = re.split("\n+", input)
+   >>> entries
+   ['Ross McFluff: 834.345.1254 155 Elm Street',
+   'Ronald Heathmore: 892.345.3428 436 Finley Avenue',
+   'Frank Burger: 925.541.7625 662 South Dogwood Way',
+   'Heather Albrecht: 548.326.4584 919 Park Place']
+
+Finally, split each entry into a list with first name, last name, telephone
+number, and address.  We use the ``maxsplit`` parameter of :func:`split`
+because the address has spaces, our splitting pattern, in it:
+
+.. doctest::
+   :options: +NORMALIZE_WHITESPACE
+
+   >>> [re.split(":? ", entry, 3) for entry in entries]
+   [['Ross', 'McFluff', '834.345.1254', '155 Elm Street'],
+   ['Ronald', 'Heathmore', '892.345.3428', '436 Finley Avenue'],
+   ['Frank', 'Burger', '925.541.7625', '662 South Dogwood Way'],
+   ['Heather', 'Albrecht', '548.326.4584', '919 Park Place']]
+
+The ``:?`` pattern matches the colon after the last name, so that it does not
+occur in the result list.  With a ``maxsplit`` of ``4``, we could separate the
+house number from the street name:
+
+.. doctest::
+   :options: +NORMALIZE_WHITESPACE
+
+   >>> [re.split(":? ", entry, 4) for entry in entries]
+   [['Ross', 'McFluff', '834.345.1254', '155', 'Elm Street'],
+   ['Ronald', 'Heathmore', '892.345.3428', '436', 'Finley Avenue'],
+   ['Frank', 'Burger', '925.541.7625', '662', 'South Dogwood Way'],
+   ['Heather', 'Albrecht', '548.326.4584', '919', 'Park Place']]
+
+
+Text Munging
+^^^^^^^^^^^^
+
+:func:`sub` replaces every occurrence of a pattern with a string or the
+result of a function.  This example demonstrates using :func:`sub` with
+a function to "munge" text, or randomize the order of all the characters
+in each word of a sentence except for the first and last characters::
+
+   >>> def repl(m):
+   ...   inner_word = list(m.group(2))
+   ...   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)
+   'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.'
+   >>> re.sub("(\w)(\w+)(\w)", repl, text)
+   'Pofsroser Aodlambelk, plasee reoprt yuor asnebces potlmrpy.'
+
+
+Finding all Adverbs
+^^^^^^^^^^^^^^^^^^^
+
+:func:`findall` matches *all* occurrences of a pattern, not just the first
+one as :func:`search` does.  For example, if one was a writer and wanted to
+find all of the adverbs in some text, he or she might use :func:`findall` in
+the following manner:
+
+   >>> text = "He was carefully disguised but captured quickly by police."
+   >>> re.findall(r"\w+ly", text)
+   ['carefully', 'quickly']
+
+
+Finding all Adverbs and their Positions
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+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 = "He was carefully disguised but captured quickly by police."
+   >>> for m in re.finditer(r"\w+ly", text):
+   ...     print('%02d-%02d: %s' % (m.start(), m.end(), m.group(0)))
+   07-16: carefully
+   40-47: quickly
+
+
+Raw String Notation
+^^^^^^^^^^^^^^^^^^^
+
+Raw string notation (``r"text"``) keeps regular expressions sane.  Without it,
+every backslash (``'\'``) in a regular expression would have to be prefixed with
+another one to escape it.  For example, the two following lines of code are
+functionally identical:
+
+   >>> re.match(r"\W(.)\1\W", " ff ")
+   <_sre.SRE_Match object at ...>
+   >>> re.match("\\W(.)\\1\\W", " ff ")
+   <_sre.SRE_Match object at ...>
+
+When one wants to match a literal backslash, it must be escaped in the regular
+expression.  With raw string notation, this means ``r"\\"``.  Without raw string
+notation, one must use ``"\\\\"``, making the following lines of code
+functionally identical:
+
+   >>> re.match(r"\\", r"\\")
+   <_sre.SRE_Match object at ...>
+   >>> re.match("\\\\", r"\\")
+   <_sre.SRE_Match object at ...>

Modified: python/branches/py3k-importlib/Doc/library/readline.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/readline.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/readline.rst	Thu Mar 27 00:48:05 2008
@@ -5,7 +5,7 @@
 .. module:: readline
    :platform: Unix
    :synopsis: GNU readline support for Python.
-.. sectionauthor:: Skip Montanaro <skip at mojam.com>
+.. sectionauthor:: Skip Montanaro <skip at pobox.com>
 
 
 The :mod:`readline` module defines a number of functions to facilitate
@@ -132,7 +132,6 @@
 
    Get the type of completion being attempted.
 
-   .. versionadded:: 2.6
 
 .. function:: get_begidx()
 
@@ -153,6 +152,7 @@
 
    Get the readline word delimiters for tab-completion.
 
+
 .. function:: set_completion_display_matches_hook([function])
 
    Set or remove the completion display function.  If *function* is
@@ -162,7 +162,6 @@
    ``function(substitution, [matches], longest_match_length)`` once
    each time matches need to be displayed.
 
-   .. versionadded:: 2.6
 
 .. function:: add_history(line)
 

Modified: python/branches/py3k-importlib/Doc/library/repr.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/repr.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/repr.rst	Thu Mar 27 00:48:05 2008
@@ -65,7 +65,7 @@
 
 .. attribute:: Repr.maxlong
 
-   Maximum number of characters in the representation for a long integer.  Digits
+   Maximum number of characters in the representation for an integer.  Digits
    are dropped from the middle.  The default is ``40``.
 
 

Modified: python/branches/py3k-importlib/Doc/library/rlcompleter.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/rlcompleter.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/rlcompleter.rst	Thu Mar 27 00:48:05 2008
@@ -55,7 +55,7 @@
    Return the *state*th completion for *text*.
 
    If called for *text* that doesn't include a period character (``'.'``), it will
-   complete from names currently defined in :mod:`__main__`, :mod:`__builtin__` and
+   complete from names currently defined in :mod:`__main__`, :mod:`builtins` and
    keywords (as defined by the :mod:`keyword` module).
 
    If called for a dotted name, it will try to evaluate anything without obvious

Modified: python/branches/py3k-importlib/Doc/library/robotparser.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/robotparser.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/robotparser.rst	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,7 @@
 
 .. module:: robotparser
    :synopsis: Loads a robots.txt file and answers questions about fetchability of other URLs.
-.. sectionauthor:: Skip Montanaro <skip at mojam.com>
+.. sectionauthor:: Skip Montanaro <skip at pobox.com>
 
 
 .. index::
@@ -15,9 +15,8 @@
 
 This module provides a single class, :class:`RobotFileParser`, which answers
 questions about whether or not a particular user agent can fetch a URL on the
-Web site that published the :file:`robots.txt` file.  For more details on  the
-structure of :file:`robots.txt` files, see
-http://www.robotstxt.org/wc/norobots.html.
+Web site that published the :file:`robots.txt` file.  For more details on the
+structure of :file:`robots.txt` files, see http://www.robotstxt.org/orig.html.
 
 
 .. class:: RobotFileParser()

Modified: python/branches/py3k-importlib/Doc/library/runpy.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/runpy.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/runpy.rst	Thu Mar 27 00:48:05 2008
@@ -46,7 +46,7 @@
    does not make filename information available, this variable is set to ``None``.
 
    ``__builtins__`` is automatically initialised with a reference to the top level
-   namespace of the :mod:`__builtin__` module.
+   namespace of the :mod:`builtins` module.
 
    If the argument *alter_sys* is supplied and evaluates to ``True``, then
    ``sys.argv[0]`` is updated with the value of ``__file__`` and

Modified: python/branches/py3k-importlib/Doc/library/sched.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/sched.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/sched.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`sched` --- Event scheduler
 ================================
 
@@ -6,9 +5,6 @@
    :synopsis: General purpose event scheduler.
 .. sectionauthor:: Moshe Zadka <moshez at zadka.site.co.il>
 
-
-.. % LaTeXed and enhanced from comments in file
-
 .. index:: single: event scheduling
 
 The :mod:`sched` module defines a class which implements a general purpose event
@@ -29,7 +25,7 @@
 Example::
 
    >>> import sched, time
-   >>> s=sched.scheduler(time.time, time.sleep)
+   >>> s = sched.scheduler(time.time, time.sleep)
    >>> def print_time(): print("From print_time", time.time())
    ...
    >>> def print_some_times():
@@ -45,13 +41,39 @@
    From print_time 930343700.273
    930343700.276
 
+In multi-threaded environments, the :class:`scheduler` class has limitations
+with respect to thread-safety, inability to insert a new task before 
+the one currently pending in a running scheduler, and holding up the main
+thread until the event queue is empty.  Instead, the preferred approach
+is to use the :class:`threading.Timer` class instead.
+
+Example::
+
+    >>> import time
+    >>> from threading import Timer
+    >>> def print_time():
+    ...     print "From print_time", time.time()
+    ...
+    >>> def print_some_times():
+    ...     print time.time()
+    ...     Timer(5, print_time, ()).start()
+    ...     Timer(10, print_time, ()).start()
+    ...     time.sleep(11)	# sleep while time-delay events execute
+    ...     print time.time()     
+    ...
+    >>> print_some_times()
+    930343690.257
+    From print_time 930343695.274
+    From print_time 930343700.273
+    930343701.301
+
 
 .. _scheduler-objects:
 
 Scheduler Objects
 -----------------
 
-:class:`scheduler` instances have the following methods:
+:class:`scheduler` instances have the following methods and attributes:
 
 
 .. method:: scheduler.enterabs(time, priority, action, argument)
@@ -102,3 +124,10 @@
    the calling code is responsible for canceling  events which are no longer
    pertinent.
 
+.. attribute:: scheduler.queue
+
+   Read-only attribute returning a list of upcoming events in the order they
+   will be run.  Each event is shown as a :term:`named tuple` with the
+   following fields:  time, priority, action, argument.
+
+   .. versionadded:: 2.6

Modified: python/branches/py3k-importlib/Doc/library/select.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/select.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/select.rst	Thu Mar 27 00:48:05 2008
@@ -7,10 +7,12 @@
 
 
 This module provides access to the :cfunc:`select` and :cfunc:`poll` functions
-available in most operating systems.  Note that on Windows, it only works for
-sockets; on other operating systems, it also works for other file types (in
-particular, on Unix, it works on pipes).  It cannot be used on regular files to
-determine whether a file has grown since it was last read.
+available in most operating systems, :cfunc:`epoll` available on Linux 2.5+ and
+:cfunc:`kqueue` available on most BSD.
+Note that on Windows, it only works for sockets; on other operating systems,
+it also works for other file types (in particular, on Unix, it works on pipes).
+It cannot be used on regular files to determine whether a file has grown since
+it was last read.
 
 The module defines the following:
 
@@ -22,6 +24,16 @@
    string, as would be printed by the C function :cfunc:`perror`.
 
 
+.. function:: epoll([sizehint=-1])
+
+   (Only supported on Linux 2.5.44 and newer.)  Returns an edge polling object,
+   which can be used as Edge or Level Triggered interface for I/O events; see
+   section :ref:`epoll-objects` below for the methods supported by epolling
+   objects.
+
+   .. versionadded:: 2.6
+
+
 .. function:: poll()
 
    (Not supported by all operating systems.)  Returns a polling object, which
@@ -30,6 +42,22 @@
    by polling objects.
 
 
+.. function:: kqueue()
+
+   (Only supported on BSD.)  Returns a kernel queue object object; see section
+   :ref:`kqueue-objects` below for the methods supported by kqueue objects.
+
+   .. versionadded:: 2.6
+
+
+.. function:: kqueue(ident, filter=KQ_FILTER_READ, flags=KQ_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.
+
+   .. versionadded:: 2.6
+
+
 .. function:: select(iwtd, owtd, ewtd[, timeout])
 
    This is a straightforward interface to the Unix :cfunc:`select` system call.
@@ -58,8 +86,6 @@
    class yourself, as long as it has an appropriate :meth:`fileno` method (that
    really returns a file descriptor, not just a random integer).
 
-   .. % 
-
    .. note::
 
       .. index:: single: WinSock
@@ -69,6 +95,81 @@
       not handle file descriptors that don't originate from WinSock.
 
 
+.. _epoll-objects:
+
+Edge and Level Trigger Polling (epoll) Objects
+----------------------------------------------
+
+   http://linux.die.net/man/4/epoll
+
+   *eventmask*
+
+   +-----------------------+-----------------------------------------------+
+   | Constant              | Meaning                                       |
+   +=======================+===============================================+
+   | :const:`EPOLLIN`      | Available for read                            |
+   +-----------------------+-----------------------------------------------+
+   | :const:`EPOLLOUT`     | Available for write                           |
+   +-----------------------+-----------------------------------------------+
+   | :const:`EPOLLPRI`     | Urgent data for read                          |
+   +-----------------------+-----------------------------------------------+
+   | :const:`EPOLLERR`     | Error condition happend on the assoc. fd      |
+   +-----------------------+-----------------------------------------------+
+   | :const:`EPOLLHUP`     | Hang up happend on the assoc. fd              |
+   +-----------------------+-----------------------------------------------+
+   | :const:`EPOLLET`      | Set Edge Trigger behavior, the default is     |
+   |                       | Level Trigger behavior                        |
+   +-----------------------+-----------------------------------------------+
+   | :const:`EPOLLONESHOT` | Set one-shot behavior. After one event is     |
+   |                       | pulled out, the fd is internally disabled     |
+   +-----------------------+-----------------------------------------------+
+   | :const:`EPOLLRDNORM`  | ???                                           |
+   +-----------------------+-----------------------------------------------+
+   | :const:`EPOLLRDBAND`  | ???                                           |
+   +-----------------------+-----------------------------------------------+
+   | :const:`EPOLLWRNORM`  | ???                                           |
+   +-----------------------+-----------------------------------------------+
+   | :const:`EPOLLWRBAND`  | ???                                           |
+   +-----------------------+-----------------------------------------------+
+   | :const:`EPOLLMSG`     | ???                                           |
+   +-----------------------+-----------------------------------------------+
+
+
+.. method:: epoll.close()
+
+   Close the control file descriptor of the epoll object.
+
+
+.. method:: epoll.fileno()
+
+   Return the file descriptor number of the control fd.
+
+
+.. method:: epoll.fromfd(fd)
+
+   Create an epoll object from a given file descriptor.
+
+
+.. method:: epoll.register(fd[, eventmask])
+
+   Register a fd descriptor with the epoll object.
+
+
+.. method:: epoll.modify(fd, eventmask)
+
+   Modify a register file descriptor.
+
+
+.. method:: epoll.unregister(fd)
+
+   Remove a registered file descriptor from the epoll object.
+
+
+.. method:: epoll.poll([timeout=-1[, maxevents=-1]])
+
+   Wait for events. timeout in seconds (float)
+
+
 .. _poll-objects:
 
 Polling Objects
@@ -116,6 +217,16 @@
    the same effect as registering the descriptor exactly once.
 
 
+.. 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
+   that was never registered causes an :exc:`IOError` exception with errno
+   :const:`ENOENT` to be raised.
+
+   .. versionadded:: 2.6
+
+
 .. method:: poll.unregister(fd)
 
    Remove a file descriptor being tracked by a polling object.  Just like the
@@ -139,3 +250,184 @@
    returning. If *timeout* is omitted, negative, or :const:`None`, the call will
    block until there is an event for this poll object.
 
+
+.. _kqueue-objects:
+
+Kqueue Objects
+--------------
+
+.. method:: kqueue.close()
+
+   Close the control file descriptor of the kqueue object.
+
+
+.. method:: kqueue.fileno()
+
+   Return the file descriptor number of the control fd.
+
+
+.. method:: epoll.fromfd(fd)
+
+   Create a kqueue object from a given file descriptor.
+
+
+.. method:: control(changelist, max_events=0[, timeout=None]) -> eventlist
+
+   Low level interface to kevent
+
+   - changelist must be an iterable of kevent object or None
+   - max_events must be 0 or a positive integer
+   - timeout in seconds (floats possible)
+
+
+.. _kevent-objects:
+
+Kevent Objects
+--------------
+
+http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
+
+.. attribute:: kevent.ident
+
+   Value used to identify the event. The interpretation depends on the filter
+   but it's usually the file descriptor. In the constructor ident can either
+   be an int or an object with a fileno() function. kevent stores the integer
+   internally.
+
+.. attribute:: kevent.filter
+
+   Name of the kernel filter
+
+   +---------------------------+---------------------------------------------+
+   | Constant                  | Meaning                                     |
+   +===========================+=============================================+
+   | :const:`KQ_FILTER_READ`   | Takes a descriptor and returns whenever     |
+   |                           | there is data available to read             |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_FILTER_WRITE`  | Takes a descriptor and returns whenever     |
+   |                           | there is data available to read             |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_FILTER_AIO`    | AIO requests                                |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_FILTER_VNODE`  | Returns when one or more of the requested   |
+   |                           | events watched in *fflag* occurs            |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_FILTER_PROC`   | Watch for events on a process id            |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_FILTER_NETDEV` | Watch for events on a network device        |
+   |                           | [not available on Mac OS X]                 |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_FILTER_SIGNAL` | Returns whenever the watched signal is      |
+   |                           | delivered to the process                    |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_FILTER_TIMER`  | Establishes an arbitrary timer              |
+   +---------------------------+---------------------------------------------+
+
+.. attribute:: kevent.flags
+
+   Filter action
+
+   +---------------------------+---------------------------------------------+
+   | Constant                  | Meaning                                     |
+   +===========================+=============================================+
+   | :const:`KQ_EV_ADD`        | Adds or modifies an event                   |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_EV_DELETE`     | Removes an event from the queue             |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_EV_ENABLE`     | Permitscontrol() to returns the event       |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_EV_DISABLE`    | Disablesevent                               |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_EV_ONESHOT`    | Removes event after first occurence         |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_EV_CLEAR`      | Reset the state after an event is retrieved |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_EV_SYSFLAGS`   | internal event                              |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_EV_FLAG1`      | internal event                              |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_EV_EOF`        | Filter specific EOF condition               |
+   +---------------------------+---------------------------------------------+
+   | :const:`KQ_EV_ERROR`      | See return values                           |
+   +---------------------------+---------------------------------------------+
+
+
+.. attribute:: kevent.fflags
+
+   Filter specific flags
+
+
+   *:const:`KQ_FILTER_READ` and  :const:`KQ_FILTER_WRITE` filter flags*
+
+   +----------------------------+--------------------------------------------+
+   | Constant                   | Meaning                                    |
+   +============================+============================================+
+   | :const:`KQ_NOTE_LOWAT`     | low water mark of a socket buffer          |
+   +----------------------------+--------------------------------------------+
+
+
+   *:const:`KQ_FILTER_VNODE` filter flags*
+
+   +----------------------------+--------------------------------------------+
+   | Constant                   | Meaning                                    |
+   +============================+============================================+
+   | :const:`KQ_NOTE_DELETE`    | *unlink()* was called                      |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_WRITE`     | a write occured                            |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_EXTEND`    | the file was extended                      |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_ATTRIB`    | an attribute was changed                   |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_LINK`      | the link count has changed                 |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_RENAME`    | the file was renamed                       |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_REVOKE`    | access to the file was revoked             |
+   +----------------------------+--------------------------------------------+
+
+
+   *:const:`KQ_FILTER_PROC` filter flags*
+
+   +----------------------------+--------------------------------------------+
+   | Constant                   | Meaning                                    |
+   +============================+============================================+
+   | :const:`KQ_NOTE_EXIT`      | the process has exited                     |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_FORK`      | the process has called *fork()*            |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_EXEC`      | the process has executed a new process     |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_PCTRLMASK` | internal filter flag                       |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_PDATAMASK` | internal filter flag                       |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_TRACK`     | follow a process across *fork()*           |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_CHILD`     | returned on the child process for          |
+   |                            | *NOTE_TRACK*                               |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_TRACKERR`  | unable to attach to a child                |
+   +----------------------------+--------------------------------------------+
+
+   *:const:`KQ_FILTER_NETDEV` filter flags* [not available on Mac OS X]
+
+   +----------------------------+--------------------------------------------+
+   | Constant                   | Meaning                                    |
+   +============================+============================================+
+   | :const:`KQ_NOTE_LINKUP`    | link is up                                 |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_LINKDOWN`  | link is down                               |
+   +----------------------------+--------------------------------------------+
+   | :const:`KQ_NOTE_LINKINV`   | link state is invalid                      |
+   +----------------------------+--------------------------------------------+
+
+
+.. attribute:: kevent.data
+
+   Filter specific data
+
+
+.. attribute:: kevent.udata
+
+   User defined value

Modified: python/branches/py3k-importlib/Doc/library/shutil.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/shutil.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/shutil.rst	Thu Mar 27 00:48:05 2008
@@ -5,9 +5,7 @@
 .. module:: shutil
    :synopsis: High-level file operations, including copying.
 .. sectionauthor:: Fred L. Drake, Jr. <fdrake at acm.org>
-
-
-.. % partly based on the docstrings
+.. partly based on the docstrings
 
 .. index::
    single: file; copying
@@ -15,19 +13,25 @@
 
 The :mod:`shutil` module offers a number of high-level operations on files and
 collections of files.  In particular, functions are provided  which support file
-copying and removal.
+copying and removal. For operations on individual files, see also the
+:mod:`os` module.
 
 .. warning::
+
+   Even the higher-level file copying functions (:func:`copy`, :func:`copy2`)
+   can't copy all file metadata.
    
-   On MacOS, the resource fork and other metadata are not used.  For file copies,
-   this means that resources will be lost and  file type and creator codes will
-   not be correct.
+   On POSIX platforms, this means that file owner and group are lost as well
+   as ACLs.  On MacOS, the resource fork and other metadata are not used.
+   This means that resources will be lost and file type and creator codes will
+   not be correct. On Windows, file owners, ACLs and alternate data streams
+   are not copied.
 
 
 .. function:: copyfile(src, dst)
 
-   Copy the contents of the file named *src* to a file named *dst*.  The
-   destination location must be writable; otherwise,  an :exc:`IOError` exception
+   Copy the contents (no metadata) of the file named *src* to a file named *dst*.
+   The destination location must be writable; otherwise,  an :exc:`IOError` exception
    will be raised. If *dst* already exists, it will be replaced.   Special files
    such as character or block devices and pipes cannot be copied with this
    function.  *src* and *dst* are path names given as strings.
@@ -89,31 +93,37 @@
 
    .. index:: single: directory; deleting
 
-   Delete an entire directory tree (*path* must point to a directory). If
-   *ignore_errors* is true, errors resulting from failed removals will be ignored;
-   if false or omitted, such errors are handled by calling a handler specified by
-   *onerror* or, if that is omitted, they raise an exception.
-
-   If *onerror* is provided, it must be a callable that accepts three parameters:
-   *function*, *path*, and *excinfo*. The first parameter, *function*, is the
-   function which raised the exception; it will be :func:`os.listdir`,
-   :func:`os.remove` or :func:`os.rmdir`.  The second parameter, *path*, will be
-   the path name passed to *function*.  The third parameter, *excinfo*, will be the
-   exception information return by :func:`sys.exc_info`.  Exceptions raised by
-   *onerror* will not be caught.
+   Delete an entire directory tree; *path* must point to a directory (but not a
+   symbolic link to a directory).  If *ignore_errors* is true, errors resulting
+   from failed removals will be ignored; if false or omitted, such errors are
+   handled by calling a handler specified by *onerror* or, if that is omitted,
+   they raise an exception.
+
+   If *onerror* is provided, it must be a callable that accepts three
+   parameters: *function*, *path*, and *excinfo*. The first parameter,
+   *function*, is the function which raised the exception; it will be
+   :func:`os.path.islink`, :func:`os.listdir`, :func:`os.remove` or
+   :func:`os.rmdir`.  The second parameter, *path*, will be the path name passed
+   to *function*.  The third parameter, *excinfo*, will be the exception
+   information return by :func:`sys.exc_info`.  Exceptions raised by *onerror*
+   will not be caught.
+
+   .. versionchanged:: 2.6
+      Explicitly check for *path* being a symbolic link and raise :exc:`OSError`
+      in that case.
 
 
 .. function:: move(src, dst)
 
    Recursively move a file or directory to another location.
 
-   If the destination is on our current filesystem, then simply use rename.
+   If the destination is on the current filesystem, then simply use rename.
    Otherwise, copy src to the dst and then remove src.
 
 
 .. exception:: Error
 
-   This exception collects exceptions that raised during a mult-file operation. For
+   This exception collects exceptions that raised during a multi-file operation. For
    :func:`copytree`, the exception argument is a list of 3-tuples (*srcname*,
    *dstname*, *exception*).
 

Modified: python/branches/py3k-importlib/Doc/library/signal.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/signal.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/signal.rst	Thu Mar 27 00:48:05 2008
@@ -110,6 +110,35 @@
    :manpage:`signal(2)`.)
 
 
+.. function:: set_wakeup_fd(fd)
+
+   Set the wakeup fd to *fd*.  When a signal is received, a ``'\0'`` byte is
+   written to the fd.  This can be used by a library to wakeup a poll or select
+   call, allowing the signal to be fully processed.
+
+   The old wakeup fd is returned.  *fd* must be non-blocking.  It is up to the
+   library to remove any bytes before calling poll or select again.
+
+   When threads are enabled, this function can only be called from the main thread;
+   attempting to call it from other threads will cause a :exc:`ValueError`
+   exception to be raised.
+
+
+
+.. function:: siginterrupt(signalnum, flag)
+
+   Change system call restart behaviour: if *flag* is :const:`False`, system calls
+   will be restarted when interrupted by signal *signalnum*, otherwise system calls will
+   be interrupted. Returns nothing. Availability: Unix, Mac (see the man page
+   :manpage:`siginterrupt(3)` for further information).
+   
+   Note that installing a signal handler with :func:`signal` will reset the restart
+   behaviour to interruptible by implicitly calling :cfunc:`siginterrupt` with a true *flag*
+   value for the given signal.
+
+   .. versionadded:: 2.6
+
+
 .. function:: signal(signalnum, handler)
 
    Set the handler for signal *signalnum* to the function *handler*.  *handler* can

Modified: python/branches/py3k-importlib/Doc/library/simplexmlrpcserver.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/simplexmlrpcserver.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/simplexmlrpcserver.rst	Thu Mar 27 00:48:05 2008
@@ -101,7 +101,7 @@
    Registers the XML-RPC multicall function system.multicall.
 
 
-.. attribute:: SimpleXMLRPCServer.rpc_paths
+.. attribute:: SimpleXMLRPCRequestHandler.rpc_paths
 
    An attribute value that must be a tuple listing valid path portions of the URL
    for receiving XML-RPC requests.  Requests posted to other paths will result in a
@@ -109,12 +109,22 @@
    considered valid. The default value is ``('/', '/RPC2')``.
 
 
-Example::
+.. _simplexmlrpcserver-example:
+
+SimpleXMLRPCServer Example
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+Server code::
 
    from SimpleXMLRPCServer import SimpleXMLRPCServer
+   from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
+
+   # Restrict to a particular path.
+   class RequestHandler(SimpleXMLRPCRequestHandler):
+       rpc_paths = ('/RPC2',)
 
    # Create server
-   server = SimpleXMLRPCServer(("localhost", 8000))
+   server = SimpleXMLRPCServer(("localhost", 8000),
+                               requestHandler=RequestHandler)
    server.register_introspection_functions()
 
    # Register pow() function; this will use the value of 
@@ -137,7 +147,7 @@
    # Run the server's main loop
    server.serve_forever()
 
-The following client code will call the methods made available by  the preceding
+The following client code will call the methods made available by the preceding
 server::
 
    import xmlrpclib
@@ -145,7 +155,7 @@
    s = xmlrpclib.ServerProxy('http://localhost:8000')
    print(s.pow(2,3))  # Returns 2**3 = 8
    print(s.add(2,3))  # Returns 5
-   print(s.div(5,2))  # Returns 5//2 = 2
+   print(s.mul(5,2))  # Returns 5*2 = 10
 
    # Print list of available methods
    print(s.system.listMethods())

Modified: python/branches/py3k-importlib/Doc/library/smtplib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/smtplib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/smtplib.rst	Thu Mar 27 00:48:05 2008
@@ -184,6 +184,16 @@
    necessary to call this method explicitly.  It will be implicitly called by
    :meth:`sendmail` when necessary.
 
+.. method:: SMTP.ehlo_or_helo_if_needed()
+
+   This method call :meth:`ehlo` and or :meth:`helo` if there has been no
+   previous ``EHLO`` or ``HELO`` command this session.  It tries ESMTP ``EHLO``
+   first.
+
+   :exc:SMTPHeloError
+     The server didn't reply properly to the ``HELO`` greeting.
+
+   .. versionadded:: 2.6
 
 .. method:: SMTP.has_extn(name)
 
@@ -230,6 +240,22 @@
    If *keyfile* and *certfile* are provided, these are passed to the :mod:`socket`
    module's :func:`ssl` function.
 
+   If there has been no previous ``EHLO`` or ``HELO`` command this session,
+   this method tries ESMTP ``EHLO`` first.
+
+   .. versionchanged:: 2.6
+
+   :exc:`SMTPHeloError`
+      The server didn't reply properly to the ``HELO`` greeting.
+
+   :exc:`SMTPException`
+     The server does not support the STARTTLS extension.
+
+   .. versionchanged:: 2.6
+
+   :exc:`RuntimeError`
+     SSL/TLS support is not available to your python interpreter.
+
 
 .. method:: SMTP.sendmail(from_addr, to_addrs, msg[, mail_options, rcpt_options])
 
@@ -306,14 +332,8 @@
 
    import smtplib
 
-   def raw_input(prompt):
-       import sys
-       sys.stdout.write(prompt)
-       sys.stdout.flush()
-       return sys.stdin.readline()
-
    def prompt(prompt):
-       return raw_input(prompt).strip()
+       return input(prompt).strip()
 
    fromaddr = prompt("From: ")
    toaddrs  = prompt("To: ").split()
@@ -324,7 +344,7 @@
           % (fromaddr, ", ".join(toaddrs)))
    while True:
        try:
-           line = raw_input()
+           line = input()
        except EOFError:
            break
        if not line:

Modified: python/branches/py3k-importlib/Doc/library/sndhdr.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/sndhdr.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/sndhdr.rst	Thu Mar 27 00:48:05 2008
@@ -5,9 +5,7 @@
 .. module:: sndhdr
    :synopsis: Determine type of a sound file.
 .. sectionauthor:: Fred L. Drake, Jr. <fdrake at acm.org>
-
-
-.. % Based on comments in the module source file.
+.. Based on comments in the module source file.
 
 .. index::
    single: A-LAW

Modified: python/branches/py3k-importlib/Doc/library/socket.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/socket.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/socket.rst	Thu Mar 27 00:48:05 2008
@@ -23,7 +23,7 @@
 socket-related system calls are also a valuable source of information on the
 details of socket semantics.  For Unix, refer to the manual pages; for Windows,
 see the WinSock (or Winsock 2) specification. For IPv6-ready APIs, readers may
-want to refer to :rfc:`2553` titled Basic Socket Interface Extensions for IPv6.
+want to refer to :rfc:`3493` titled Basic Socket Interface Extensions for IPv6.
 
 .. index:: object: socket
 
@@ -65,6 +65,27 @@
 
 AF_NETLINK sockets are represented as  pairs ``pid, groups``.
 
+
+Linux-only support for TIPC is also available using the :const:`AF_TIPC`
+address family. TIPC is an open, non-IP based networked protocol designed
+for use in clustered computer environments.  Addresses are represented by a
+tuple, and the fields depend on the address type. The general tuple form is
+``(addr_type, v1, v2, v3 [, scope])``, where:
+
+   - *addr_type* is one of TIPC_ADDR_NAMESEQ, TIPC_ADDR_NAME, or
+     TIPC_ADDR_ID.
+   - *scope* is one of TIPC_ZONE_SCOPE, TIPC_CLUSTER_SCOPE, and
+     TIPC_NODE_SCOPE.
+   - If *addr_type* is TIPC_ADDR_NAME, then *v1* is the server type, *v2* is
+     the port identifier, and *v3* should be 0.
+
+     If *addr_type* is TIPC_ADDR_NAMESEQ, then *v1* is the server type, *v2*
+     is the lower port number, and *v3* is the upper port number.
+
+     If *addr_type* is TIPC_ADDR_ID, then *v1* is the node, *v2* is the
+     reference, and *v3* should be set to 0.
+
+
 All errors raise exceptions.  The normal exceptions for invalid argument types
 and out-of-memory conditions can be raised; errors related to socket or address
 semantics raise the error :exc:`socket.error`.
@@ -85,9 +106,6 @@
    accompanying :exc:`os.error`. See the module :mod:`errno`, which contains names
    for the error codes defined by the underlying operating system.
 
-   .. versionchanged:: 2.6
-      :exc:`socket.error` is now a child class of :exc:`IOError`.
-
 
 .. exception:: herror
 
@@ -158,6 +176,18 @@
    in the Unix header files are defined; for a few symbols, default values are
    provided.
 
+.. data:: SIO_*
+          RCVALL_*
+          
+   Constants for Windows' WSAIoctl(). The constants are used as arguments to the
+   :meth:`ioctl` method of socket objects.
+   
+
+.. data:: TIPC_*
+
+   TIPC related constants, matching the ones exported by the C socket API. See
+   the TIPC documentation for more information.
+
 
 .. data:: has_ipv6
 
@@ -527,6 +557,14 @@
    contents of the buffer (see the optional built-in module :mod:`struct` for a way
    to decode C structures encoded as strings).
 
+   
+.. method:: socket.ioctl(control, option)
+
+   :platform: Windows 
+   
+   The :meth:`ioctl` method is a limited interface to the WSAIoctl system
+   interface. Please refer to the MSDN documentation for more information.
+   
 
 .. method:: socket.listen(backlog)
 
@@ -545,7 +583,7 @@
    file object and socket object may be closed or garbage-collected independently.
    The socket must be in blocking mode (it can not have a timeout). The optional
    *mode* and *bufsize* arguments are interpreted the same way as by the built-in
-   :func:`file` function; see :ref:`built-in-funcs` for more information.
+   :func:`file` function.
 
 
 .. method:: socket.recv(bufsize[, flags])
@@ -825,3 +863,28 @@
    s.close()
    print('Received', repr(data))
 
+   
+The last example shows how to write a very simple network sniffer with raw
+sockets on Windows. The example requires administrator priviliges to modify
+the interface::
+
+   import socket
+
+   # the public network interface
+   HOST = socket.gethostbyname(socket.gethostname())
+   
+   # create a raw socket and bind it to the public interface
+   s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
+   s.bind((HOST, 0))
+   
+   # Include IP headers
+   s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
+   
+   # receive all packages
+   s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
+   
+   # receive a package
+   print s.recvfrom(65565)
+   
+   # disabled promiscuous mode
+   s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)

Modified: python/branches/py3k-importlib/Doc/library/socketserver.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/socketserver.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/socketserver.rst	Thu Mar 27 00:48:05 2008
@@ -44,7 +44,7 @@
 not exit until all threads created by :class:`ThreadingMixIn` have exited.
 
 Server classes have the same external methods and attributes, no matter what
-network protocol they use:
+network protocol they use.
 
 
 Server Creation Notes
@@ -113,11 +113,11 @@
 finished requests and to use :func:`select` to decide which request to work on
 next (or whether to handle a new incoming request).  This is particularly
 important for stream services where each client can potentially be connected for
-a long time (if threads or subprocesses cannot be used).
+a long time (if threads or subprocesses cannot be used). See :mod:`asyncore` for
+another way to manage this.
 
-.. % XXX should data and methods be intermingled, or separate?
-.. % how should the distinction between class and instance variables be
-.. % drawn?
+.. XXX should data and methods be intermingled, or separate?
+   how should the distinction between class and instance variables be drawn?
 
 
 Server Objects
@@ -133,16 +133,24 @@
 
 .. function:: handle_request()
 
-   Process a single request.  This function calls the following methods in order:
-   :meth:`get_request`, :meth:`verify_request`, and :meth:`process_request`.  If
-   the user-provided :meth:`handle` method of the handler class raises an
-   exception, the server's :meth:`handle_error` method will be called.
+   Process a single request.  This function calls the following methods in
+   order: :meth:`get_request`, :meth:`verify_request`, and
+   :meth:`process_request`.  If the user-provided :meth:`handle` method of the
+   handler class raises an exception, the server's :meth:`handle_error` method
+   will be called.  If no request is received within :attr:`self.timeout`
+   seconds, :meth:`handle_timeout` will be called and :meth:`handle_request`
+   will return.
 
 
-.. function:: serve_forever()
+.. function:: serve_forever(poll_interval=0.5)
 
-   Handle an infinite number of requests.  This simply calls :meth:`handle_request`
-   inside an infinite loop.
+   Handle requests until an explicit :meth:`shutdown` request.  Polls for
+   shutdown every *poll_interval* seconds.
+
+
+.. function:: shutdown()
+
+   Tells the :meth:`serve_forever` loop to stop and waits until it does.
 
 
 .. data:: address_family
@@ -171,8 +179,7 @@
 
 The server classes support the following class variables:
 
-.. % XXX should class variables be covered before instance variables, or
-.. % vice versa?
+.. XXX should class variables be covered before instance variables, or vice versa?
 
 
 .. data:: allow_reuse_address
@@ -195,12 +202,18 @@
    The type of socket used by the server; :const:`socket.SOCK_STREAM` and
    :const:`socket.SOCK_DGRAM` are two possible values.
 
+.. data:: timeout
+
+   Timeout duration, measured in seconds, or :const:`None` if no timeout is
+   desired.  If :meth:`handle_request` receives no incoming requests within the
+   timeout period, the :meth:`handle_timeout` method is called.
+
 There are various server methods that can be overridden by subclasses of base
 server classes like :class:`TCPServer`; these methods aren't useful to external
 users of the server object.
 
-.. % should the default implementations of these be documented, or should
-.. % it be assumed that the user will look at SocketServer.py?
+.. XXX should the default implementations of these be documented, or should
+   it be assumed that the user will look at SocketServer.py?
 
 
 .. function:: finish_request()
@@ -222,6 +235,13 @@
    method raises an exception.  The default action is to print the traceback to
    standard output and continue handling further requests.
 
+.. function:: handle_timeout()
+
+   This function is called when the :attr:`timeout` attribute has been set to a 
+   value other than :const:`None` and the timeout period has passed with no 
+   requests being received.  The default action for forking servers is
+   to collect the status of any child processes that have exited, while
+   in threading servers this method does nothing.
 
 .. function:: process_request(request, client_address)
 
@@ -230,9 +250,9 @@
    or thread to handle the request; the :class:`ForkingMixIn` and
    :class:`ThreadingMixIn` classes do this.
 
-.. % Is there any point in documenting the following two functions?
-.. % What would the purpose of overriding them be: initializing server
-.. % instance variables, adding new network families?
+.. Is there any point in documenting the following two functions?
+   What would the purpose of overriding them be: initializing server
+   instance variables, adding new network families?
 
 
 .. function:: server_activate()

Modified: python/branches/py3k-importlib/Doc/library/sqlite3.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/sqlite3.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/sqlite3.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`sqlite3` --- DB-API 2.0 interface for SQLite databases
 ============================================================
 
@@ -69,10 +68,10 @@
             ):
        c.execute('insert into stocks values (?,?,?,?,?)', t)
 
-To retrieve data after executing a SELECT statement, you can either  treat the
-cursor as an iterator, call the cursor's :meth:`fetchone` method to retrieve a
-single matching row,  or call :meth:`fetchall` to get a list of the matching
-rows.
+To retrieve data after executing a SELECT statement, you can either treat the
+cursor as an :term:`iterator`, call the cursor's :meth:`fetchone` method to
+retrieve a single matching row, or call :meth:`fetchall` to get a list of the
+matching rows.
 
 This example uses the iterator form::
 
@@ -184,8 +183,8 @@
 
    Registers a callable to convert the custom Python type *type* into one of
    SQLite's supported types. The callable *callable* accepts as single parameter
-   the Python value, and must return a value of the following types: int, long,
-   float, str (UTF-8 encoded), unicode or buffer.
+   the Python value, and must return a value of the following types: int,
+   float, str, bytes (UTF-8 encoded) or buffer.
 
 
 .. function:: complete_statement(sql)
@@ -259,8 +258,8 @@
    parameters the function accepts, and *func* is a Python callable that is called
    as the SQL function.
 
-   The function can return any of the types supported by SQLite: unicode, str, int,
-   long, float, buffer and None.
+   The function can return any of the types supported by SQLite: bytes, str, int,
+   float, buffer and None.
 
    Example:
 
@@ -276,7 +275,7 @@
    final result of the aggregate.
 
    The ``finalize`` method can return any of the types supported by SQLite:
-   unicode, str, int, long, float, buffer and None.
+   bytes, str, int, float, buffer and None.
 
    Example:
 
@@ -349,19 +348,19 @@
    memory overhead. It will probably be better than your own custom
    dictionary-based approach or even a db_row based solution.
 
-   .. % XXX what's a db_row-based solution?
+   .. XXX what's a db_row-based solution?
 
 
 .. attribute:: Connection.text_factory
 
    Using this attribute you can control what objects are returned for the TEXT data
-   type. By default, this attribute is set to :class:`unicode` and the
-   :mod:`sqlite3` module will return Unicode objects for TEXT. If you want to
-   return bytestrings instead, you can set it to :class:`str`.
-
-   For efficiency reasons, there's also a way to return Unicode objects only for
-   non-ASCII data, and bytestrings otherwise. To activate it, set this attribute to
-   :const:`sqlite3.OptimizedUnicode`.
+   type. By default, this attribute is set to :class:`str` and the
+   :mod:`sqlite3` module will return strings for TEXT. If you want to
+   return bytestrings instead, you can set it to :class:`bytes`.
+
+   For efficiency reasons, there's also a way to return :class:`str` objects
+   only for non-ASCII data, and :class:`bytes` otherwise. To activate it, set
+   this attribute to :const:`sqlite3.OptimizedUnicode`.
 
    You can also set it to any other callable that accepts a single bytestring
    parameter and returns the resulting object.
@@ -387,7 +386,7 @@
 
 .. method:: Cursor.execute(sql, [parameters])
 
-   Executes a SQL statement. The SQL statement may be parametrized (i. e.
+   Executes an SQL statement. The SQL statement may be parametrized (i. e.
    placeholders instead of SQL literals). The :mod:`sqlite3` module supports two
    kinds of placeholders: question marks (qmark style) and named placeholders
    (named style).
@@ -408,13 +407,13 @@
 
 .. method:: Cursor.executemany(sql, seq_of_parameters)
 
-   Executes a SQL command against all parameter sequences or mappings found in the
-   sequence *sql*. The :mod:`sqlite3` module also allows using an iterator yielding
-   parameters instead of a sequence.
+   Executes an SQL command against all parameter sequences or mappings found in
+   the sequence *sql*.  The :mod:`sqlite3` module also allows using an
+   :term:`iterator` yielding parameters instead of a sequence.
 
    .. literalinclude:: ../includes/sqlite3/executemany_1.py
 
-   Here's a shorter example using a generator:
+   Here's a shorter example using a :term:`generator`:
 
    .. literalinclude:: ../includes/sqlite3/executemany_2.py
 
@@ -425,13 +424,42 @@
    at once. It issues a COMMIT statement first, then executes the SQL script it
    gets as a parameter.
 
-   *sql_script* can be a bytestring or a Unicode string.
+   *sql_script* can be an instance of :class:`str` or :class:`bytes`.
 
    Example:
 
    .. literalinclude:: ../includes/sqlite3/executescript.py
 
 
+.. method:: Cursor.fetchone() 
+          
+   Fetches the next row of a query result set, returning a single sequence,
+   or ``None`` when no more data is available.
+
+
+.. method:: Cursor.fetchmany([size=cursor.arraysize])
+          
+   Fetches the next set of rows of a query result, returning a list.  An empty
+   list is returned when no more rows are available.
+   
+   The number of rows to fetch per call is specified by the *size* parameter.
+   If it is not given, the cursor's arraysize determines the number of rows
+   to be fetched. The method should try to fetch as many rows as indicated by
+   the size parameter. If this is not possible due to the specified number of
+   rows not being available, fewer rows may be returned.
+   
+   Note there are performance considerations involved with the *size* parameter.
+   For optimal performance, it is usually best to use the arraysize attribute.
+   If the *size* parameter is used, then it is best for it to retain the same
+   value from one :meth:`fetchmany` call to the next.
+            
+.. method:: Cursor.fetchall() 
+
+   Fetches all (remaining) rows of a query result, returning a list.  Note that
+   the cursor's arraysize attribute can affect the performance of this operation.
+   An empty list is returned when no rows are available.
+
+
 .. attribute:: Cursor.rowcount
 
    Although the :class:`Cursor` class of the :mod:`sqlite3` module implements this
@@ -465,23 +493,21 @@
 
 The following Python types can thus be sent to SQLite without any problem:
 
-+------------------------+-------------+
-| Python type            | SQLite type |
-+========================+=============+
-| ``None``               | NULL        |
-+------------------------+-------------+
-| ``int``                | INTEGER     |
-+------------------------+-------------+
-| ``long``               | INTEGER     |
-+------------------------+-------------+
-| ``float``              | REAL        |
-+------------------------+-------------+
-| ``str (UTF8-encoded)`` | TEXT        |
-+------------------------+-------------+
-| ``unicode``            | TEXT        |
-+------------------------+-------------+
-| ``buffer``             | BLOB        |
-+------------------------+-------------+
++-------------------------------+-------------+
+| Python type                   | SQLite type |
++===============================+=============+
+| ``None``                      | NULL        |
++-------------------------------+-------------+
+| :class:`int`                  | INTEGER     |
++-------------------------------+-------------+
+| :class:`float`                | REAL        |
++-------------------------------+-------------+
+| :class:`bytes` (UTF8-encoded) | TEXT        |
++-------------------------------+-------------+
+| :class:`str`                  | TEXT        |
++-------------------------------+-------------+
+| :class:`buffer`               | BLOB        |
++-------------------------------+-------------+
 
 This is how SQLite types are converted to Python types by default:
 
@@ -490,11 +516,11 @@
 +=============+=============================================+
 | ``NULL``    | None                                        |
 +-------------+---------------------------------------------+
-| ``INTEGER`` | int or long, depending on size              |
+| ``INTEGER`` | int                                         |
 +-------------+---------------------------------------------+
 | ``REAL``    | float                                       |
 +-------------+---------------------------------------------+
-| ``TEXT``    | depends on text_factory, unicode by default |
+| ``TEXT``    | depends on text_factory, str by default     |
 +-------------+---------------------------------------------+
 | ``BLOB``    | buffer                                      |
 +-------------+---------------------------------------------+
@@ -510,8 +536,8 @@
 
 As described before, SQLite supports only a limited set of types natively. To
 use other Python types with SQLite, you must **adapt** them to one of the
-sqlite3 module's supported types for SQLite: one of NoneType, int, long, float,
-str, unicode, buffer.
+sqlite3 module's supported types for SQLite: one of NoneType, int, float,
+str, bytes, buffer.
 
 The :mod:`sqlite3` module uses Python object adaptation, as described in
 :pep:`246` for this.  The protocol to use is :class:`PrepareProtocol`.

Modified: python/branches/py3k-importlib/Doc/library/ssl.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/ssl.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/ssl.rst	Thu Mar 27 00:48:05 2008
@@ -51,7 +51,7 @@
    network connection.  This error is a subtype of :exc:`socket.error`, which
    in turn is a subtype of :exc:`IOError`.
 
-.. function:: wrap_socket (sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version={see docs}, ca_certs=None)
+.. function:: wrap_socket (sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version={see docs}, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True)
 
    Takes an instance ``sock`` of :class:`socket.socket`, and returns an instance of :class:`ssl.SSLSocket`, a subtype
    of :class:`socket.socket`, which wraps the underlying socket in an SSL context.
@@ -109,15 +109,28 @@
 
        ========================  =========  =========  ==========  =========
         *client* / **server**    **SSLv2**  **SSLv3**  **SSLv23**  **TLSv1**
+       ------------------------  ---------  ---------  ----------  ---------
         *SSLv2*                    yes        no         yes*        no
         *SSLv3*                    yes        yes        yes         no
         *SSLv23*                   yes        no         yes         no
         *TLSv1*                    no         no         yes         yes
        ========================  =========  =========  ==========  =========
 
-   `*` In some older versions of OpenSSL (for instance, 0.9.7l on OS X 10.4),
+   In some older versions of OpenSSL (for instance, 0.9.7l on OS X 10.4),
    an SSLv2 client could not connect to an SSLv23 server.
 
+   The parameter ``do_handshake_on_connect`` specifies whether to do the SSL
+   handshake automatically after doing a :meth:`socket.connect`, or whether the
+   application program will call it explicitly, by invoking the :meth:`SSLSocket.do_handshake`
+   method.  Calling :meth:`SSLSocket.do_handshake` explicitly gives the program control over
+   the blocking behavior of the socket I/O involved in the handshake.
+
+   The parameter ``suppress_ragged_eofs`` specifies how the :meth:`SSLSocket.read`
+   method should signal unexpected EOF from the other end of the connection.  If specified
+   as :const:`True` (the default), it returns a normal EOF in response to unexpected
+   EOF errors raised from the underlying socket; if :const:`False`, it will raise
+   the exceptions back the caller.
+
 .. function:: RAND_status()
 
    Returns True if the SSL pseudo-random number generator has been
@@ -223,7 +236,7 @@
 
 .. data:: PROTOCOL_TLSv1
 
-   Selects SSL version 2 as the channel encryption protocol.  This is
+   Selects TLS version 1 as the channel encryption protocol.  This is
    the most modern version, and probably the best choice for maximum
    protection, if both sides can speak it.
 
@@ -231,15 +244,41 @@
 SSLSocket Objects
 -----------------
 
-.. method:: SSLSocket.read([nbytes=1024])
+.. method:: SSLSocket.read(nbytes=1024, buffer=None)
 
    Reads up to ``nbytes`` bytes from the SSL-encrypted channel and returns them.
+   If the ``buffer`` is specified, it will attempt to read into the buffer
+   the minimum of the size of the buffer and ``nbytes``, if that is specified.
+   If no buffer is specified, an immutable buffer is allocated and returned
+   with the data read from the socket.
 
 .. method:: SSLSocket.write(data)
 
    Writes the ``data`` to the other side of the connection, using the
    SSL channel to encrypt.  Returns the number of bytes written.
 
+.. method:: SSLSocket.do_handshake()
+
+   Performs the SSL setup handshake.  If the socket is non-blocking,
+   this method may raise :exc:`SSLError` with the value of the exception
+   instance's ``args[0]``
+   being either :const:`SSL_ERROR_WANT_READ` or
+   :const:`SSL_ERROR_WANT_WRITE`, and should be called again until
+   it stops raising those exceptions.  Here's an example of how to do
+   that::
+
+        while True:
+            try:
+                sock.do_handshake()
+                break
+            except ssl.SSLError as err:
+                if err.args[0] == ssl.SSL_ERROR_WANT_READ:
+                    select.select([sock], [], [])
+                elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
+                    select.select([], [sock], [])
+                else:
+                    raise
+
 .. method:: SSLSocket.getpeercert(binary_form=False)
 
    If there is no certificate for the peer on the other end of the

Modified: python/branches/py3k-importlib/Doc/library/statvfs.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/statvfs.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/statvfs.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`statvfs` --- Constants used with :func:`os.statvfs`
 =========================================================
 
@@ -7,8 +6,6 @@
 .. sectionauthor:: Moshe Zadka <moshez at zadka.site.co.il>
 
 
-.. % LaTeX'ed from comments in module
-
 The :mod:`statvfs` module defines constants so interpreting the result if
 :func:`os.statvfs`, which returns a tuple, can be made without remembering
 "magic numbers."  Each of the constants defined in this module is the *index* of

Modified: python/branches/py3k-importlib/Doc/library/stdtypes.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/stdtypes.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/stdtypes.rst	Thu Mar 27 00:48:05 2008
@@ -141,25 +141,25 @@
 
 This table summarizes the comparison operations:
 
-+------------+-------------------------+-------+
-| Operation  | Meaning                 | Notes |
-+============+=========================+=======+
-| ``<``      | strictly less than      |       |
-+------------+-------------------------+-------+
-| ``<=``     | less than or equal      |       |
-+------------+-------------------------+-------+
-| ``>``      | strictly greater than   |       |
-+------------+-------------------------+-------+
-| ``>=``     | greater than or equal   |       |
-+------------+-------------------------+-------+
-| ``==``     | equal                   |       |
-+------------+-------------------------+-------+
-| ``!=``     | not equal               |       |
-+------------+-------------------------+-------+
-| ``is``     | object identity         |       |
-+------------+-------------------------+-------+
-| ``is not`` | negated object identity |       |
-+------------+-------------------------+-------+
++------------+-------------------------+
+| Operation  | Meaning                 |
++============+=========================+
+| ``<``      | strictly less than      |
++------------+-------------------------+
+| ``<=``     | less than or equal      |
++------------+-------------------------+
+| ``>``      | strictly greater than   |
++------------+-------------------------+
+| ``>=``     | greater than or equal   |
++------------+-------------------------+
+| ``==``     | equal                   |
++------------+-------------------------+
+| ``!=``     | not equal               |
++------------+-------------------------+
+| ``is``     | object identity         |
++------------+-------------------------+
+| ``is not`` | negated object identity |
++------------+-------------------------+
 
 .. index::
    pair: object; numeric
@@ -246,7 +246,6 @@
 .. index::
    single: arithmetic
    builtin: int
-   builtin: long
    builtin: float
    builtin: complex
 
@@ -286,7 +285,7 @@
 +---------------------+---------------------------------+-------+--------------------+
 | ``int(x)``          | *x* converted to integer        | \(3)  | :func:`int`        |
 +---------------------+---------------------------------+-------+--------------------+
-| ``float(x)``        | *x* converted to floating point |       | :func:`float`      |
+| ``float(x)``        | *x* converted to floating point | \(4)  | :func:`float`      |
 +---------------------+---------------------------------+-------+--------------------+
 | ``complex(re, im)`` | a complex number with real part |       | :func:`complex`    |
 |                     | *re*, imaginary part *im*.      |       |                    |
@@ -297,9 +296,9 @@
 +---------------------+---------------------------------+-------+--------------------+
 | ``divmod(x, y)``    | the pair ``(x // y, x % y)``    | \(2)  | :func:`divmod`     |
 +---------------------+---------------------------------+-------+--------------------+
-| ``pow(x, y)``       | *x* to the power *y*            |       | :func:`pow`        |
+| ``pow(x, y)``       | *x* to the power *y*            | \(5)  | :func:`pow`        |
 +---------------------+---------------------------------+-------+--------------------+
-| ``x ** y``          | *x* to the power *y*            |       |                    |
+| ``x ** y``          | *x* to the power *y*            | \(5)  |                    |
 +---------------------+---------------------------------+-------+--------------------+
 
 .. index::
@@ -326,11 +325,38 @@
       pair: numeric; conversions
       pair: C; language
 
-   Conversion from floating point to (long or plain) integer may round or truncate
+   Conversion from floating point to integer may round or truncate
    as in C; see functions :func:`floor` and :func:`ceil` in the :mod:`math` module
    for well-defined conversions.
 
-.. % XXXJH exceptions: overflow (when? what operations?) zerodivision
+(4)
+   float also accepts the strings "nan" and "inf" with an optional prefix "+" 
+   or "-" for Not a Number (NaN) and positive or negative infinity.
+
+(5)
+   Python defines ``pow(0, 0)`` and ``0 ** 0`` to be ``1``, as is common for
+   programming languages.
+
+   
+
+All :class:`numbers.Real` types (:class:`int` and
+:class:`float`) also include the following operations:
+
++--------------------+--------------------------------+--------+
+| Operation          | Result                         | Notes  |
++====================+================================+========+
+| ``trunc(x)``       | *x* truncated to Integral      |        |
++--------------------+--------------------------------+--------+
+| ``round(x[, n])``  | *x* rounded to n digits,       |        |
+|                    | rounding half to even. If n is |        |
+|                    | omitted, it defaults to 0.     |        |
++--------------------+--------------------------------+--------+
+| ``math.floor(x)``  | the greatest Integral <= *x*   |        |
++--------------------+--------------------------------+--------+
+| ``math.ceil(x)``   | the least Integral >= *x*      |        |
++--------------------+--------------------------------+--------+
+
+.. XXXJH exceptions: overflow (when? what operations?) zerodivision
 
 
 .. _bitstring-ops:
@@ -344,7 +370,7 @@
 Negative numbers are treated as their 2's complement value (this assumes a
 sufficiently large number of bits that no overflow occurs during the operation).
 
-The priorities of the binary bit-wise operations are all lower than the numeric
+The priorities of the binary bitwise operations are all lower than the numeric
 operations and higher than the comparisons; the unary operation ``~`` has the
 same priority as the other unary numeric operations (``+`` and ``-``).
 
@@ -363,9 +389,9 @@
 | ``x & y``  | bitwise :dfn:`and` of *x* and  |          |
 |            | *y*                            |          |
 +------------+--------------------------------+----------+
-| ``x << n`` | *x* shifted left by *n* bits   | (1), (2) |
+| ``x << n`` | *x* shifted left by *n* bits   | (1)(2)   |
 +------------+--------------------------------+----------+
-| ``x >> n`` | *x* shifted right by *n* bits  | (1), (3) |
+| ``x >> n`` | *x* shifted right by *n* bits  | (1)(3)   |
 +------------+--------------------------------+----------+
 | ``~x``     | the bits of *x* inverted       |          |
 +------------+--------------------------------+----------+
@@ -409,6 +435,7 @@
 One method needs to be defined for container objects to provide iteration
 support:
 
+.. XXX duplicated in reference/datamodel!
 
 .. method:: container.__iter__()
 
@@ -449,51 +476,54 @@
 continue to do so on subsequent calls.  Implementations that do not obey this
 property are deemed broken.
 
-Python's generators provide a convenient way to implement the iterator protocol.
-If a container object's :meth:`__iter__` method is implemented as a generator,
-it will automatically return an iterator object (technically, a generator
-object) supplying the :meth:`__iter__` and :meth:`__next__` methods.
+Python's :term:`generator`\s provide a convenient way to implement the iterator
+protocol.  If a container object's :meth:`__iter__` method is implemented as a
+generator, it will automatically return an iterator object (technically, a
+generator object) supplying the :meth:`__iter__` and :meth:`__next__` methods.
 
 
 .. _typesseq:
 
-Sequence Types --- :class:`str`, :class:`bytes`, :class:`list`, :class:`tuple`, :class:`buffer`, :class:`range`
-===============================================================================================================
+Sequence Types --- :class:`str`, :class:`bytes`, :class:`bytearray`, :class:`list`, :class:`tuple`, :class:`range`
+==================================================================================================================
 
-There are five sequence types: strings, byte sequences, lists, tuples, buffers,
-and range objects.  (For other containers see the built in :class:`dict`,
-:class:`list`, :class:`set`, and :class:`tuple` classes, and the
+There are five sequence types: strings, byte sequences, byte arrays, lists,
+tuples, and range objects.  (For other containers see the built-in
+:class:`dict`, :class:`list`, :class:`set`, and :class:`tuple` classes, and the
 :mod:`collections` module.)
 
 .. index::
    object: sequence
    object: string
    object: bytes
+   object: buffer
    object: tuple
    object: list
-   object: buffer
    object: range
 
-String literals are written in single or double quotes: ``'xyzzy'``,
-``"frobozz"``.  See :ref:`strings` for more about string literals.  In addition
-to the functionality described here, there are also string-specific methods
-described in the :ref:`string-methods` section.  Bytes objects can be
-constructed from literals too; use a ``b`` prefix with normal string syntax:
-``b'xyzzy'``.
+Strings contain Unicode characters.  Their literals are written in single or
+double quotes: ``'xyzzy'``, ``"frobozz"``.  See :ref:`strings` for more about
+string literals.  In addition to the functionality described here, there are
+also string-specific methods described in the :ref:`string-methods` section.
+
+Bytes and bytearray objects contain single bytes -- the former is immutable
+while the latter is a mutable sequence.  Bytes objects can be constructed from
+literals too; use a ``b`` prefix with normal string syntax: ``b'xyzzy'``.  To
+construct byte arrays, use the :func:`bytearray` function.
 
 .. warning::
 
    While string objects are sequences of characters (represented by strings of
-   length 1), bytes objects are sequences of *integers* (between 0 and 255),
-   representing the ASCII value of single bytes.  That means that for a bytes
-   object *b*, ``b[0]`` will be an integer, while ``b[0:1]`` will be a bytes
-   object of length 1.
+   length 1), bytes and bytearray objects are sequences of *integers* (between 0
+   and 255), representing the ASCII value of single bytes.  That means that for
+   a bytes or bytearray object *b*, ``b[0]`` will be an integer, while ``b[0:1]``
+   will be a bytes or bytearray object of length 1.
 
    Also, while in previous Python versions, byte strings and Unicode strings
    could be exchanged for each other rather freely (barring encoding issues),
-   strings and bytes are completely separate concepts.  There's no implicit
-   en-/decoding if you pass and object of the wrong type or try to e.g. compare
-   a string with a bytes object.
+   strings and bytes are now completely separate concepts.  There's no implicit
+   en-/decoding if you pass and object of the wrong type.  A string always
+   compares unequal to a bytes or bytearray object.
 
 Lists are constructed with square brackets, separating items with commas: ``[a,
 b, c]``.  Tuples are constructed by the comma operator (not within square
@@ -501,19 +531,14 @@
 the enclosing parentheses, such as ``a, b, c`` or ``()``.  A single item tuple
 must have a trailing comma, such as ``(d,)``.
 
-Buffer objects are not directly supported by Python syntax, but can be created
-by calling the builtin function :func:`buffer`.  They don't support
-concatenation or repetition.
-
-Objects of type range are similar to buffers in that there is no specific syntax
-to create them, but they are created using the :func:`range` function.  They
-don't support slicing, concatenation or repetition, and using ``in``, ``not
-in``, :func:`min` or :func:`max` on them is inefficient.
+Objects of type range are created using the :func:`range` function.  They don't
+support slicing, concatenation or repetition, and using ``in``, ``not in``,
+:func:`min` or :func:`max` on them is inefficient.
 
 Most sequence types support the following operations.  The ``in`` and ``not in``
 operations have the same priorities as the comparison operations.  The ``+`` and
 ``*`` operations have the same priority as the corresponding numeric operations.
-[#]_
+[#]_ Additional methods are provided for :ref:`typesseq-mutable`.
 
 This table lists the sequence operations sorted in ascending priority
 (operations in the same box have the same priority).  In the table, *s* and *t*
@@ -536,9 +561,9 @@
 +------------------+--------------------------------+----------+
 | ``s[i]``         | *i*'th item of *s*, origin 0   | \(3)     |
 +------------------+--------------------------------+----------+
-| ``s[i:j]``       | slice of *s* from *i* to *j*   | (3), (4) |
+| ``s[i:j]``       | slice of *s* from *i* to *j*   | (3)(4)   |
 +------------------+--------------------------------+----------+
-| ``s[i:j:k]``     | slice of *s* from *i* to *j*   | (3), (5) |
+| ``s[i:j:k]``     | slice of *s* from *i* to *j*   | (3)(5)   |
 |                  | with step *k*                  |          |
 +------------------+--------------------------------+----------+
 | ``len(s)``       | length of *s*                  |          |
@@ -548,10 +573,10 @@
 | ``max(s)``       | largest item of *s*            |          |
 +------------------+--------------------------------+----------+
 
-Sequence types also support comparisons. In particular, tuples and lists are
-compared lexicographically by comparing corresponding elements. This means that
+Sequence types also support comparisons.  In particular, tuples and lists are
+compared lexicographically by comparing corresponding elements.  This means that
 to compare equal, every element must compare equal and the two sequences must be
-of the same type and have the same length. (For full details see
+of the same type and have the same length.  (For full details see
 :ref:`comparisons` in the language reference.)
 
 .. index::
@@ -576,7 +601,7 @@
    Values of *n* less than ``0`` are treated as ``0`` (which yields an empty
    sequence of the same type as *s*).  Note also that the copies are shallow;
    nested structures are not copied.  This often haunts new Python programmers;
-   consider::
+   consider:
 
       >>> lists = [[]] * 3
       >>> lists
@@ -588,7 +613,7 @@
    What has happened is that ``[[]]`` is a one-element list containing an empty
    list, so all three elements of ``[[]] * 3`` are (pointers to) this single empty
    list.  Modifying any of the elements of ``lists`` modifies this single list.
-   You can create a list of different lists this way::
+   You can create a list of different lists this way:
 
       >>> lists = [[] for i in range(3)]
       >>> lists[0].append(3)
@@ -599,8 +624,8 @@
 
 (3)
    If *i* or *j* is negative, the index is relative to the end of the string:
-   ``len(s) + i`` or ``len(s) + j`` is substituted.  But note that ``-0`` is still
-   ``0``.
+   ``len(s) + i`` or ``len(s) + j`` is substituted.  But note that ``-0`` is
+   still ``0``.
 
 (4)
    The slice of *s* from *i* to *j* is defined as the sequence of items with index
@@ -611,7 +636,7 @@
 
 (5)
    The slice of *s* from *i* to *j* with step *k* is defined as the sequence of
-   items with index  ``x = i + n*k`` such that 0 ≤n < (j-i)/(k).  In other words,
+   items with index  ``x = i + n*k`` such that ``0 <= n < (j-i)/k``.  In other words,
    the indices are ``i``, ``i+k``, ``i+2*k``, ``i+3*k`` and so on, stopping when
    *j* is reached (but never including *j*).  If *i* or *j* is greater than
    ``len(s)``, use ``len(s)``.  If *i* or *j* are omitted or ``None``, they become
@@ -656,9 +681,9 @@
 
 .. method:: str.count(sub[, start[, end]])
 
-   Return the number of occurrences of substring *sub* in string S\
-   ``[start:end]``.  Optional arguments *start* and *end* are interpreted as in
-   slice notation.
+   Return the number of occurrences of substring *sub* in the range [*start*,
+   *end*].  Optional arguments *start* and *end* are interpreted as in slice
+   notation.
 
 
 .. method:: str.encode([encoding[, errors]])
@@ -683,8 +708,11 @@
 
 .. method:: str.expandtabs([tabsize])
 
-   Return a copy of the string where all tab characters are expanded using spaces.
-   If *tabsize* is not given, a tab size of ``8`` characters is assumed.
+   Return a copy of the string where all tab characters are replaced by one or
+   more spaces, depending on the current column and the given tab size.  The
+   column number is reset to zero after each newline occurring in the string.
+   If *tabsize* is not given, a tab size of ``8`` characters is assumed.  This
+   doesn't understand other non-printing characters or escape sequences.
 
 
 .. method:: str.find(sub[, start[, end]])
@@ -769,8 +797,8 @@
 
    Return a string which is the concatenation of the values in the sequence
    *seq*. Non-string values in *seq* will be converted to a string using their
-   respective ``str()`` value. If there are any :class:`bytes` objects in
-   *seq*, a :exc:`TypeError` will be raised. The separator between elements is
+   respective ``str()`` value.  If there are any :class:`bytes` objects in
+   *seq*, a :exc:`TypeError` will be raised.  The separator between elements is
    the string providing this method.
 
 
@@ -791,7 +819,7 @@
    Return a copy of the string with leading characters removed.  The *chars*
    argument is a string specifying the set of characters to be removed.  If omitted
    or ``None``, the *chars* argument defaults to removing whitespace.  The *chars*
-   argument is not a prefix; rather, all combinations of its values are stripped::
+   argument is not a prefix; rather, all combinations of its values are stripped:
 
       >>> '   spacious   '.lstrip()
       'spacious   '
@@ -799,6 +827,21 @@
       'example.com'
 
 
+.. method:: str.maketrans(x[, y[, z]])
+
+   This static method returns a translation table usable for :meth:`str.translate`.
+
+   If there is only one argument, it must be a dictionary mapping Unicode
+   ordinals (integers) or characters (strings of length 1) to Unicode ordinals,
+   strings (of arbitrary lengths) or None.  Character keys will then be
+   converted to ordinals.
+
+   If there are two arguments, they must be strings of equal length, and in the
+   resulting dictionary, each character in x will be mapped to the character at
+   the same position in y.  If there is a third argument, it must be a string,
+   whose characters will be mapped to None in the result.
+
+
 .. method:: str.partition(sep)
 
    Split the string at the first occurrence of *sep*, and return a 3-tuple
@@ -856,7 +899,7 @@
    Return a copy of the string with trailing characters removed.  The *chars*
    argument is a string specifying the set of characters to be removed.  If omitted
    or ``None``, the *chars* argument defaults to removing whitespace.  The *chars*
-   argument is not a suffix; rather, all combinations of its values are stripped::
+   argument is not a suffix; rather, all combinations of its values are stripped:
 
       >>> '   spacious   '.rstrip()
       '   spacious'
@@ -870,19 +913,23 @@
    string.  If *maxsplit* is given, at most *maxsplit* splits are done (thus,
    the list will have at most ``maxsplit+1`` elements).  If *maxsplit* is not
    specified, then there is no limit on the number of splits (all possible
-   splits are made).  Consecutive delimiters are not grouped together and are
+   splits are made).
+
+   If *sep* is given, consecutive delimiters are not grouped together and are
    deemed to delimit empty strings (for example, ``'1,,2'.split(',')`` returns
    ``['1', '', '2']``).  The *sep* argument may consist of multiple characters
-   (for example, ``'1, 2, 3'.split(', ')`` returns ``['1', '2', '3']``).
+   (for example, ``'1<>2<>3'.split('<>')`` returns ``['1', '2', '3']``).
    Splitting an empty string with a specified separator returns ``['']``.
 
    If *sep* is not specified or is ``None``, a different splitting algorithm is
-   applied.  First, whitespace characters (spaces, tabs, newlines, returns, and
-   formfeeds) are stripped from both ends.  Then, words are separated by arbitrary
-   length strings of whitespace characters. Consecutive whitespace delimiters are
-   treated as a single delimiter (``'1  2  3'.split()`` returns ``['1', '2',
-   '3']``). Splitting an empty string or a string consisting of just whitespace
-   returns an empty list.
+   applied: runs of consecutive whitespace are regarded as a single separator,
+   and the result will contain no empty strings at the start or end if the
+   string has leading or trailing whitespace.  Consequently, splitting an empty
+   string or a string consisting of just whitespace with a ``None`` separator
+   returns ``[]``.
+
+   For example, ``' 1  2   3  '.split()`` returns ``['1', '2', '3']``, and
+   ``'  1  2   3  '.split(None, 1)`` returns ``['1', '2   3  ']``.
 
 
 .. method:: str.splitlines([keepends])
@@ -906,7 +953,7 @@
    The *chars* argument is a string specifying the set of characters to be removed.
    If omitted or ``None``, the *chars* argument defaults to removing whitespace.
    The *chars* argument is not a prefix or suffix; rather, all combinations of its
-   values are stripped::
+   values are stripped:
 
       >>> '   spacious   '.strip()
       'spacious'
@@ -929,15 +976,21 @@
 .. method:: str.translate(map)
 
    Return a copy of the *s* where all characters have been mapped through the
-   *map* which must be a dictionary of characters (strings of length 1) or
-   Unicode ordinals (integers) to Unicode ordinals, strings or ``None``.
-   Unmapped characters are left untouched. Characters mapped to ``None`` are
-   deleted.
+   *map* which must be a dictionary of Unicode ordinals(integers) to Unicode
+   ordinals, strings or ``None``.  Unmapped characters are left untouched.
+   Characters mapped to ``None`` are deleted.
+
+   A *map* for :meth:`translate` is usually best created by
+   :meth:`str.maketrans`.
+
+   You can use the :func:`maketrans` helper function in the :mod:`string` module to
+   create a translation table. For string objects, set the *table* argument to
+   ``None`` for translations that only delete characters:
 
    .. note::
 
-      A more flexible approach is to create a custom character mapping codec
-      using the :mod:`codecs` module (see :mod:`encodings.cp1251` for an
+      An even more flexible approach is to create a custom character mapping
+      codec using the :mod:`codecs` module (see :mod:`encodings.cp1251` for an
       example).
 
 
@@ -948,8 +1001,26 @@
 
 .. method:: str.zfill(width)
 
-   Return the numeric string left filled with zeros in a string of length *width*.
-   The original string is returned if *width* is less than ``len(s)``.
+   Return the numeric string left filled with zeros in a string of length
+   *width*.  A sign prefix is handled correctly.  The original string is
+   returned if *width* is less than ``len(s)``.
+
+
+.. method:: str.isnumeric()
+
+   Return ``True`` if there are only numeric characters in S, ``False``
+   otherwise. Numeric characters include digit characters, and all characters
+   that have the Unicode numeric value property, e.g. U+2155,
+   VULGAR FRACTION ONE FIFTH.
+
+   
+.. method:: str.isdecimal()
+
+   Return ``True`` if there are only decimal characters in S, ``False``
+   otherwise. Decimal characters include digit characters, and all characters
+   that that can be used to form decimal-radix numbers, e.g. U+0660,
+   ARABIC-INDIC DIGIT ZERO.
+   
 
 
 .. _old-string-formatting:
@@ -1012,10 +1083,11 @@
 When the right argument is a dictionary (or other mapping type), then the
 formats in the string *must* include a parenthesised mapping key into that
 dictionary inserted immediately after the ``'%'`` character. The mapping key
-selects the value to be formatted from the mapping.  For example::
+selects the value to be formatted from the mapping.  For example:
+
 
-   >>> print('%(language)s has %(#)03d quote types.' %
-             {'language': "Python", "#": 2})
+   >>> print('%(language)s has %(#)03d quote types.' % \
+   ...       {'language': "Python", "#": 2})
    Python has 002 quote types.
 
 In this case no ``*`` specifiers may occur in a format (since they require a
@@ -1124,6 +1196,8 @@
 Since Python strings have an explicit length, ``%s`` conversions do not assume
 that ``'\0'`` is the end of the string.
 
+.. XXX Examples?
+
 For safety reasons, floating point precisions are clipped to 50; ``%f``
 conversions for numbers whose absolute value is over 1e25 are replaced by ``%g``
 conversions. [#]_  All other errors raise exceptions.
@@ -1160,16 +1234,16 @@
 .. index::
    triple: mutable; sequence; types
    object: list
-   object: bytes
+   object: bytearray
 
-List and bytes objects support additional operations that allow in-place
+List and bytearray objects support additional operations that allow in-place
 modification of the object.  Other mutable sequence types (when added to the
 language) should also support these operations.  Strings and tuples are
 immutable sequence types: such objects cannot be modified once created. The
 following operations are defined on mutable sequence types (where *x* is an
 arbitrary object).
 
-Note that while lists allow their items to be of any type, bytes object
+Note that while lists allow their items to be of any type, bytearray object
 "items" are all integers in the range 0 <= x < 256.
 
 +------------------------------+--------------------------------+---------------------+
@@ -1213,8 +1287,7 @@
 | ``s.reverse()``              | reverses the items of *s* in   | \(6)                |
 |                              | place                          |                     |
 +------------------------------+--------------------------------+---------------------+
-| ``s.sort([cmp[, key[,        | sort the items of *s* in place | (6), (7)            |
-| reverse]]])``                |                                |                     |
+| ``s.sort([key[, reverse]])`` | sort the items of *s* in place | (6), (7), (8)       |
 +------------------------------+--------------------------------+---------------------+
 
 .. index::
@@ -1263,85 +1336,60 @@
    sequence.
 
 (7)
-   :meth:`sort` is not supported by bytes objects.
-
    The :meth:`sort` method takes optional arguments for controlling the
-   comparisons.
-
-   *cmp* specifies a custom comparison function of two arguments (list items) which
-   should return a negative, zero or positive number depending on whether the first
-   argument is considered smaller than, equal to, or larger than the second
-   argument: ``cmp=lambda x,y: cmp(x.lower(), y.lower())``
+   comparisons.  Each must be specified as a keyword argument.
 
    *key* specifies a function of one argument that is used to extract a comparison
-   key from each list element: ``key=str.lower``
+   key from each list element: ``key=str.lower``.  The default value is ``None``.
 
    *reverse* is a boolean value.  If set to ``True``, then the list elements are
    sorted as if each comparison were reversed.
 
-   In general, the *key* and *reverse* conversion processes are much faster than
-   specifying an equivalent *cmp* function.  This is because *cmp* is called
-   multiple times for each list element while *key* and *reverse* touch each
-   element only once.
-
-   Starting with Python 2.3, the :meth:`sort` method is guaranteed to be stable.  A
+   The :meth:`sort` method is guaranteed to be stable.  A
    sort is stable if it guarantees not to change the relative order of elements
    that compare equal --- this is helpful for sorting in multiple passes (for
    example, sort by department, then by salary grade).
 
    While a list is being sorted, the effect of attempting to mutate, or even
-   inspect, the list is undefined.  The C implementation of Python 2.3 and newer
+   inspect, the list is undefined.  The C implementation 
    makes the list appear empty for the duration, and raises :exc:`ValueError` if it
    can detect that the list has been mutated during a sort.
 
+(8)
+   :meth:`sort` is not supported by :class:`bytearray` objects.
 
 .. _bytes-methods:
 
-Bytes Methods
--------------
+Bytes and Byte Array Methods
+----------------------------
 
 .. index:: pair: bytes; methods
+           pair: bytearray; methods
 
-In addition to the operations on mutable sequence types (see
-:ref:`typesseq-mutable`), bytes objects, being "mutable ASCII strings" have
-further useful methods also found on strings.
-
-.. XXX "count" is documented as a mutable sequence method differently above
-.. XXX perhaps just split bytes and list methods
-
-.. method:: bytes.count(sub[, start[, end]])
+Bytes and bytearray objects, being "strings of bytes", have all methods found on
+strings, with the exception of :func:`encode`, :func:`format` and
+:func:`isidentifier`, which do not make sense with these types.  For converting
+the objects to strings, they have a :func:`decode` method.
 
-   In contrast to the standard sequence ``count`` method, this returns the
-   number of occurrences of substring (not item) *sub* in the slice
-   ``[start:end]``.  Optional arguments *start* and *end* are interpreted as in
-   slice notation.
-
-
-.. method:: bytes.decode([encoding[, errors]])
-
-   Decode the bytes using the codec registered for *encoding*. *encoding*
-   defaults to the default string encoding.  *errors* may be given to set a
-   different error handling scheme.  The default is ``'strict'``, meaning that
-   encoding errors raise :exc:`UnicodeError`.  Other possible values are
-   ``'ignore'``, ``'replace'`` and any other name registered via
-   :func:`codecs.register_error`, see section :ref:`codec-base-classes`.
+Wherever one of these methods needs to interpret the bytes as characters
+(e.g. the :func:`is...` methods), the ASCII character set is assumed.
 
+.. note::
 
-.. method:: bytes.endswith(suffix[, start[, end]])
+   The methods on bytes and bytearray objects don't accept strings as their
+   arguments, just as the methods on strings don't accept bytes as their
+   arguments.  For example, you have to write ::
 
-   Return ``True`` if the bytes object ends with the specified *suffix*,
-   otherwise return ``False``.  *suffix* can also be a tuple of suffixes to look
-   for.  With optional *start*, test beginning at that position.  With optional
-   *end*, stop comparing at that position.
+      a = "abc"
+      b = a.replace("a", "f")
 
+   and ::
 
-.. method:: bytes.find(sub[, start[, end]])
+      a = b"abc"
+      b = a.replace(b"a", b"f")
 
-   Return the lowest index in the string where substring *sub* is found, such that
-   *sub* is contained in the range [*start*, *end*].  Optional arguments *start*
-   and *end* are interpreted as in slice notation.  Return ``-1`` if *sub* is not
-   found.
 
+The bytes and bytearray types have an additional class method:
 
 .. method:: bytes.fromhex(string)
 
@@ -1354,113 +1402,9 @@
       >>> bytes.fromhex('f0 f1f2  ')
       b'\xf0\xf1\xf2'
 
+.. XXX verify/document translate() semantics!
 
-.. method:: bytes.index(sub[, start[, end]])
-
-   Like :meth:`find`, but raise :exc:`ValueError` when the substring is not found.
-
-
-.. method:: bytes.join(seq)
-
-   Return a bytes object which is the concatenation of the bytes objects in the
-   sequence *seq*.  The separator between elements is the bytes object providing
-   this method.
-
-
-.. method:: bytes.lstrip(which)
-
-   Return a copy of the bytes object with leading bytes removed.  The *which*
-   argument is a bytes object specifying the set of bytes to be removed.  As
-   with :meth:`str.lstrip`, the *which* argument is not a prefix; rather, all
-   combinations of its values are stripped.
-
-
-.. method:: bytes.partition(sep)
-
-   Split the bytes object at the first occurrence of *sep*, and return a 3-tuple
-   containing the part before the separator, the separator itself, and the part
-   after the separator.  If the separator is not found, return a 3-tuple
-   containing the bytes object itself, followed by two empty strings.
-
-
-.. method:: bytes.replace(old, new[, count])
-
-   Return a copy of the bytes object with all occurrences of substring *old*
-   replaced by *new*.  If the optional argument *count* is given, only the first
-   *count* occurrences are replaced.
-
-
-.. method:: bytes.rfind(sub[, start[, end]])
-
-   Return the highest index in the string where substring *sub* is found, such
-   that *sub* is contained within the slice ``[start:end]``.  Optional arguments
-   *start* and *end* are interpreted as in slice notation.  Return ``-1`` on
-   failure.
-
-
-.. method:: bytes.rindex(sub[, start[, end]])
-
-   Like :meth:`rfind` but raises :exc:`ValueError` when the substring *sub* is
-   not found.
-
-
-.. method:: bytes.rpartition(sep)
-
-   Split the bytes object at the last occurrence of *sep*, and return a 3-tuple
-   containing the part before the separator, the separator itself, and the part
-   after the separator.  If the separator is not found, return a 3-tuple
-   containing two empty strings, followed by the string itself.
-
-
-.. method:: bytes.rsplit(sep[, maxsplit])
-
-   Return a list of substrings, using *sep* as the delimiter.  If *maxsplit* is
-   given, at most *maxsplit* splits are done, the *rightmost* ones.  Except for
-   splitting from the right, :meth:`rsplit` behaves like :meth:`split` which is
-   described in detail below.
-
-
-.. method:: bytes.rstrip(which)
-
-   Return a copy of the bytes object with trailing bytes removed.  The *which*
-   argument is a bytes object specifying the set of bytes to be removed.  As
-   with :meth:`str.rstrip`, The *chars* argument is not a suffix; rather, all
-   combinations of its values are stripped.
-
-
-.. method:: bytes.split(sep[, maxsplit])
-
-   Return a list of substrings, using *sep* as the delimiter.  If *maxsplit* is
-   given, at most *maxsplit* splits are done (thus, the list will have at most
-   ``maxsplit+1`` elements).  If *maxsplit* is not specified, then there is no
-   limit on the number of splits (all possible splits are made).  Consecutive
-   delimiters are not grouped together and are deemed to delimit empty strings
-   (for example, ``b'1,,2'.split(b',')`` returns ``[b'1', b'', b'2']``).  The
-   *sep* argument may consist of multiple bytes (for example, ``b'1, 2,
-   3'.split(b', ')`` returns ``[b'1', b'2', b'3']``).  Splitting an empty string
-   with a specified separator returns ``[b'']``.
-
-
-.. method:: bytes.startswith(prefix[, start[, end]])
-
-   Return ``True`` if the bytes object starts with the *prefix*, otherwise
-   return ``False``.  *prefix* can also be a tuple of prefixes to look for.
-   With optional *start*, test string beginning at that position.  With optional
-   *end*, stop comparing string at that position.
-
-
-.. method:: bytes.strip(which)
-
-   Return a copy of the bytes object with leading and trailing bytes found in
-   *which* removed.  The *which* argument is a bytes object specifying the set
-   of characters to be removed.  The *which* argument is not a prefix or suffix;
-   rather, all combinations of its values are stripped::
-
-      >>> b'www.example.com'.strip(b'cmowz.')
-      b'example'
-
-
-.. method:: bytes.translate(table[, delete])
+   .. method:: bytes.translate(table[, delete])
 
    Return a copy of the bytes object where all bytes occurring in the optional
    argument *delete* are removed, and the remaining bytes have been mapped
@@ -1484,7 +1428,7 @@
 
 .. index:: object: set
 
-A :dfn:`set` object is an unordered collection of distinct hashable objects.
+A :dfn:`set` object is an unordered collection of distinct :term:`hashable` objects.
 Common uses include membership testing, removing duplicates from a sequence, and
 computing mathematical operations such as intersection, union, difference, and
 symmetric difference.
@@ -1500,7 +1444,7 @@
 The :class:`set` type is mutable --- the contents can be changed using methods
 like :meth:`add` and :meth:`remove`.  Since it is mutable, it has no hash value
 and cannot be used as either a dictionary key or as an element of another set.
-The :class:`frozenset` type is immutable and hashable --- its contents cannot be
+The :class:`frozenset` type is immutable and :term:`hashable` --- its contents cannot be
 altered after it is created; it can therefore be used as a dictionary key or as
 an element of another set.
 
@@ -1529,6 +1473,11 @@
 
    Test *x* for non-membership in *s*.
 
+.. method:: set.isdisjoint(other)
+
+   Return True if the set has no elements in common with *other*.
+   Sets are disjoint if and only if their interesection is the empty set.
+
 .. method:: set.issubset(other)
             set <= other
 
@@ -1600,8 +1549,7 @@
 Since sets only define partial ordering (subset relationships), the output of
 the :meth:`list.sort` method is undefined for lists of sets.
 
-Set elements are like dictionary keys; they need to define both :meth:`__hash__`
-and :meth:`__eq__` methods.
+Set elements, like dictionary keys, must be :term:`hashable`.
 
 Binary operations that mix :class:`set` instances with :class:`frozenset` return
 the type of the first operand.  For example: ``frozenset('ab') | set('bc')``
@@ -1672,20 +1620,20 @@
    statement: del
    builtin: len
 
-A :dfn:`mapping` object maps immutable values to arbitrary objects.  Mappings
-are mutable objects.  There is currently only one standard mapping type, the
-:dfn:`dictionary`.
-(For other containers see the built in :class:`list`,
-:class:`set`, and :class:`tuple` classes, and the :mod:`collections`
-module.)
-
-A dictionary's keys are *almost* arbitrary values.  Only values containing
-lists, dictionaries or other mutable types (that are compared by value rather
-than by object identity) may not be used as keys.  Numeric types used for keys
-obey the normal rules for numeric comparison: if two numbers compare equal (such
-as ``1`` and ``1.0``) then they can be used interchangeably to index the same
-dictionary entry. (Note however, that since computers store floating-point
-numbers as approximations it is usually unwise to use them as dictionary keys.)
+A :dfn:`mapping` object maps :term:`hashable` values to arbitrary objects.
+Mappings are mutable objects.  There is currently only one standard mapping
+type, the :dfn:`dictionary`.  (For other containers see the built in
+:class:`list`, :class:`set`, and :class:`tuple` classes, and the
+:mod:`collections` module.)
+
+A dictionary's keys are *almost* arbitrary values.  Values that are not
+:term:`hashable`, that is, values containing lists, dictionaries or other
+mutable types (that are compared by value rather than by object identity) may
+not be used as keys.  Numeric types used for keys obey the normal rules for
+numeric comparison: if two numbers compare equal (such as ``1`` and ``1.0``)
+then they can be used interchangeably to index the same dictionary entry.  (Note
+however, that since computers store floating-point numbers as approximations it
+is usually unwise to use them as dictionary keys.)
 
 Dictionaries can be created by placing a comma-separated list of ``key: value``
 pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:
@@ -1930,11 +1878,13 @@
 .. XXX this is quite out of date, must be updated with "io" module
 
 File objects are implemented using C's ``stdio`` package and can be
-created with the built-in :func:`file` and (more usually) :func:`open`
-constructors described in the :ref:`built-in-funcs` section. [#]_ File
+created with the built-in :func:`open` function.  File
 objects are also returned by some other built-in functions and methods,
 such as :func:`os.popen` and :func:`os.fdopen` and the :meth:`makefile`
-method of socket objects.
+method of socket objects. Temporary files can be created using the
+:mod:`tempfile` module, and high-level file operations such as copying,
+moving, and deleting files and directories can be achieved with the
+:mod:`shutil` module.
 
 When a file operation fails for an I/O-related reason, the exception
 :exc:`IOError` is raised.  This includes situations where the operation is not
@@ -1952,7 +1902,7 @@
 
    As of Python 2.5, you can avoid having to call this method explicitly if you use
    the :keyword:`with` statement.  For example, the following code will
-   automatically close ``f`` when the :keyword:`with` block is exited::
+   automatically close *f* when the :keyword:`with` block is exited::
 
       from __future__ import with_statement
 
@@ -1987,8 +1937,7 @@
 .. method:: file.fileno()
 
    .. index::
-      single: file descriptor
-      single: descriptor, file
+      pair: file; descriptor
       module: fcntl
 
    Return the integer "file descriptor" that is used by the underlying
@@ -2071,7 +2020,12 @@
    argument is optional and defaults to  ``os.SEEK_SET`` or ``0`` (absolute file
    positioning); other values are ``os.SEEK_CUR`` or ``1`` (seek relative to the
    current position) and ``os.SEEK_END`` or ``2``  (seek relative to the file's
-   end).  There is no return value.  Note that if the file is opened for appending
+   end).  There is no return value.
+   
+   For example, ``f.seek(2, os.SEEK_CUR)`` advances the position by two and
+   ``f.seek(-3, os.SEEK_END)`` sets the position to the third to last.
+
+   Note that if the file is opened for appending
    (mode ``'a'`` or ``'a+'``), any :meth:`seek` operations will be undone at the
    next write.  If the file is only opened for writing in append mode (mode
    ``'a'``), this method is essentially a no-op, but it remains useful for files
@@ -2106,9 +2060,13 @@
 
 .. method:: file.write(str)
 
-   Write a string to the file.  There is no return value.  Due to buffering, the
-   string may not actually show up in the file until the :meth:`flush` or
-   :meth:`close` method is called.
+   Write a string to the file.  Due to buffering, the string may not actually
+   show up in the file until the :meth:`flush` or :meth:`close` method is
+   called.
+
+   The meaning of the return value is not defined for every file-like object.
+   Some (mostly low-level) file-like objects may return the number of bytes
+   actually written, others return ``None``.
 
 
 .. method:: file.writelines(sequence)
@@ -2137,13 +2095,13 @@
 .. XXX does this still apply?
 .. attribute:: file.encoding
 
-   The encoding that this file uses. When Unicode strings are written to a file,
+   The encoding that this file uses. When strings are written to a file,
    they will be converted to byte strings using this encoding. In addition, when
    the file is connected to a terminal, the attribute gives the encoding that the
    terminal is likely to use (that  information might be incorrect if the user has
    misconfigured the  terminal). The attribute is read-only and may not be present
    on all file-like objects. It may also be ``None``, in which case the file uses
-   the system default encoding for converting Unicode strings.
+   the system default encoding for converting strings.
 
 
 .. attribute:: file.mode
@@ -2204,7 +2162,7 @@
    the context expression in a :keyword:`with` statement.
 
    An example of a context manager that returns a related object is the one
-   returned by ``decimal.Context.get_manager()``. These managers set the active
+   returned by :func:`decimal.localcontext`. These managers set the active
    decimal context to a copy of the original decimal context and then return the
    copy. This allows changes to be made to the current decimal context in the body
    of the :keyword:`with` statement without affecting code outside the
@@ -2213,7 +2171,7 @@
 
 .. method:: contextmanager.__exit__(exc_type, exc_val, exc_tb)
 
-   Exit the runtime context and return a Boolean flag indicating if any expection
+   Exit the runtime context and return a Boolean flag indicating if any exception
    that occurred should be suppressed. If an exception occurred while executing the
    body of the :keyword:`with` statement, the arguments contain the exception type,
    value and traceback information. Otherwise, all three arguments are ``None``.
@@ -2237,8 +2195,8 @@
 their implementation of the context management protocol. See the
 :mod:`contextlib` module for some examples.
 
-Python's generators and the ``contextlib.contextfactory`` decorator provide a
-convenient way to implement these protocols.  If a generator function is
+Python's :term:`generator`\s and the ``contextlib.contextfactory`` :term:`decorator`
+provide a convenient way to implement these protocols.  If a generator function is
 decorated with the ``contextlib.contextfactory`` decorator, it will return a
 context manager implementing the necessary :meth:`__enter__` and
 :meth:`__exit__` methods, rather than the iterator produced by an undecorated
@@ -2319,23 +2277,19 @@
 instance methods.  Built-in methods are described with the types that support
 them.
 
-The implementation adds two special read-only attributes to class instance
-methods: ``m.im_self`` is the object on which the method operates, and
-``m.im_func`` is the function implementing the method.  Calling ``m(arg-1,
-arg-2, ..., arg-n)`` is completely equivalent to calling ``m.im_func(m.im_self,
-arg-1, arg-2, ..., arg-n)``.
-
-Class instance methods are either *bound* or *unbound*, referring to whether the
-method was accessed through an instance or a class, respectively.  When a method
-is unbound, its ``im_self`` attribute will be ``None`` and if called, an
-explicit ``self`` object must be passed as the first argument.  In this case,
-``self`` must be an instance of the unbound method's class (or a subclass of
-that class), otherwise a :exc:`TypeError` is raised.
-
-Like function objects, methods objects support getting arbitrary attributes.
-However, since method attributes are actually stored on the underlying function
-object (``meth.im_func``), setting method attributes on either bound or unbound
-methods is disallowed.  Attempting to set a method attribute results in a
+If you access a method (a function defined in a class namespace) through an
+instance, you get a special object: a :dfn:`bound method` (also called
+:dfn:`instance method`) object. When called, it will add the ``self`` argument
+to the argument list.  Bound methods have two special read-only attributes:
+``m.__self__`` is the object on which the method operates, and ``m.__func__`` is
+the function implementing the method.  Calling ``m(arg-1, arg-2, ..., arg-n)``
+is completely equivalent to calling ``m.__func__(m.__self__, arg-1, arg-2, ...,
+arg-n)``.
+
+Like function objects, bound method objects support getting arbitrary
+attributes.  However, since method attributes are actually stored on the
+underlying function object (``meth.__func__``), setting method attributes on
+bound methods is disallowed.  Attempting to set a method attribute results in a
 :exc:`TypeError` being raised.  In order to set a method attribute, you need to
 explicitly set it on the underlying function object::
 
@@ -2344,7 +2298,7 @@
            pass
 
    c = C()
-   c.method.im_func.whoami = 'my name is c'
+   c.method.__func__.whoami = 'my name is c'
 
 See :ref:`types` for more information.
 
@@ -2494,9 +2448,6 @@
    strings of meaningless digits without hampering correct use and without having
    to know the exact precision of floating point values on a particular machine.
 
-.. [#] :func:`file` is new in Python 2.2.  The older built-in :func:`open` is an alias
-   for :func:`file`.
-
 .. [#] The advantage of leaving the newline on is that returning an empty string is
    then an unambiguous EOF indication.  It is also possible (in cases where it
    might matter, for example, if you want to make an exact copy of a file while

Modified: python/branches/py3k-importlib/Doc/library/string.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/string.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/string.rst	Thu Mar 27 00:48:05 2008
@@ -230,8 +230,8 @@
 value to a string before calling :meth:`__format__`, the normal formatting logic
 is bypassed.
 
-Two conversion flags are currently supported: ``'!s'`` which calls :func:`str()`
-on the value, and ``'!r'`` which calls :func:`repr()`.
+Two conversion flags are currently supported: ``'!s'`` which calls :func:`str`
+on the value, and ``'!r'`` which calls :func:`repr`.
 
 Some examples::
 
@@ -289,7 +289,7 @@
 although some of the formatting options are only supported by the numeric types.
 
 A general convention is that an empty format string (``""``) produces the same
-result as if you had called :func:`str()` on the value.
+result as if you had called :func:`str` on the value.
 
 The general form of a *standard format specifier* is:
 
@@ -484,7 +484,7 @@
    This is the object passed to the constructor's *template* argument.  In general,
    you shouldn't change it, but read-only access is not enforced.
 
-Here is an example of how to use a Template::
+Here is an example of how to use a Template:
 
    >>> from string import Template
    >>> s = Template('$who likes $what')
@@ -538,7 +538,7 @@
 String functions
 ----------------
 
-The following functions are available to operate on string and Unicode objects.
+The following functions are available to operate on string objects.
 They are not available as string methods.
 
 

Modified: python/branches/py3k-importlib/Doc/library/stringio.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/stringio.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/stringio.rst	Thu Mar 27 00:48:05 2008
@@ -1,3 +1,4 @@
+.. XXX this whole file is outdated
 
 :mod:`StringIO` --- Read and write strings as files
 ===================================================
@@ -9,7 +10,7 @@
 This module implements a file-like class, :class:`StringIO`, that reads and
 writes a string buffer (also known as *memory files*).  See the description of
 file objects for operations (section :ref:`bltin-file-objects`). (For
-standard strings, see :class:`str` and :class:`unicode`.)
+standard strings, see :class:`str`.)
 
 
 .. class:: StringIO([buffer])
@@ -19,20 +20,13 @@
    :class:`StringIO` will start empty. In both cases, the initial file position
    starts at zero.
 
-   The :class:`StringIO` object can accept either Unicode or 8-bit strings, but
-   mixing the two may take some care.  If both are used, 8-bit strings that cannot
-   be interpreted as 7-bit ASCII (that use the 8th bit) will cause a
-   :exc:`UnicodeError` to be raised when :meth:`getvalue` is called.
-
 The following methods of :class:`StringIO` objects require special mention:
 
 
 .. method:: StringIO.getvalue()
 
    Retrieve the entire contents of the "file" at any time before the
-   :class:`StringIO` object's :meth:`close` method is called.  See the note above
-   for information about mixing Unicode and 8-bit strings; such mixing can cause
-   this method to raise :exc:`UnicodeError`.
+   :class:`StringIO` object's :meth:`close` method is called.
 
 
 .. method:: StringIO.close()
@@ -75,11 +69,11 @@
 original :mod:`StringIO` module in that case.
 
 Unlike the memory files implemented by the :mod:`StringIO` module, those
-provided by this module are not able to accept Unicode strings that cannot be
-encoded as plain ASCII strings.
+provided by this module are not able to accept strings that cannot be
+encoded in plain ASCII.
 
-Calling :func:`StringIO` with a Unicode string parameter populates
-the object with the buffer representation of the Unicode string, instead of
+Calling :func:`StringIO` with a string parameter populates
+the object with the buffer representation of the string, instead of
 encoding the string. 
 
 Another difference from the :mod:`StringIO` module is that calling

Modified: python/branches/py3k-importlib/Doc/library/struct.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/struct.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/struct.rst	Thu Mar 27 00:48:05 2008
@@ -73,7 +73,7 @@
 +--------+-------------------------+--------------------+-------+
 | ``B``  | :ctype:`unsigned char`  | integer            |       |
 +--------+-------------------------+--------------------+-------+
-| ``t``  | :ctype:`_Bool`          | bool               | \(1)  |
+| ``?``  | :ctype:`_Bool`          | bool               | \(1)  |
 +--------+-------------------------+--------------------+-------+
 | ``h``  | :ctype:`short`          | integer            |       |
 +--------+-------------------------+--------------------+-------+
@@ -81,15 +81,15 @@
 +--------+-------------------------+--------------------+-------+
 | ``i``  | :ctype:`int`            | integer            |       |
 +--------+-------------------------+--------------------+-------+
-| ``I``  | :ctype:`unsigned int`   | long               |       |
+| ``I``  | :ctype:`unsigned int`   | integer            |       |
 +--------+-------------------------+--------------------+-------+
 | ``l``  | :ctype:`long`           | integer            |       |
 +--------+-------------------------+--------------------+-------+
-| ``L``  | :ctype:`unsigned long`  | long               |       |
+| ``L``  | :ctype:`unsigned long`  | integer            |       |
 +--------+-------------------------+--------------------+-------+
-| ``q``  | :ctype:`long long`      | long               | \(2)  |
+| ``q``  | :ctype:`long long`      | integer            | \(2)  |
 +--------+-------------------------+--------------------+-------+
-| ``Q``  | :ctype:`unsigned long   | long               | \(2)  |
+| ``Q``  | :ctype:`unsigned long   | integer            | \(2)  |
 |        | long`                   |                    |       |
 +--------+-------------------------+--------------------+-------+
 | ``f``  | :ctype:`float`          | float              |       |
@@ -106,7 +106,7 @@
 Notes:
 
 (1)
-   The ``'t'`` conversion code corresponds to the :ctype:`_Bool` type defined by
+   The ``'?'`` conversion code corresponds to the :ctype:`_Bool` type defined by
    C99. If this type is not available, it is simulated using a :ctype:`char`. In
    standard mode, it is always represented by one byte.
 
@@ -139,18 +139,9 @@
 used.  Note that for :func:`unpack`, the ``'p'`` format character consumes count
 bytes, but that the string returned can never contain more than 255 characters.
 
-For the ``'I'``, ``'L'``, ``'q'`` and ``'Q'`` format characters, the return
-value is a Python long integer.
 
-For the ``'P'`` format character, the return value is a Python integer or long
-integer, depending on the size needed to hold a pointer when it has been cast to
-an integer type.  A *NULL* pointer will always be returned as the Python integer
-``0``. When packing pointer-sized values, Python integer or long integer objects
-may be used.  For example, the Alpha and Merced processors use 64-bit pointer
-values, meaning a Python long integer will be used to hold the pointer; other
-platforms use 32-bit pointers and will use a Python integer.
 
-For the ``'t'`` format character, the return value is either :const:`True` or
+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.
 Either 0 or 1 in the native or standard bool representation will be packed, and
 any non-zero value will be True when unpacking.
@@ -184,7 +175,7 @@
 processors are little-endian.
 
 Native size and alignment are determined using the C compiler's
-:keyword:`sizeof` expression.  This is always combined with native byte order.
+``sizeof`` expression.  This is always combined with native byte order.
 
 Standard size and alignment are as follows: no alignment is required for any
 type (so you have to use pad bytes); :ctype:`short` is 2 bytes; :ctype:`int` and

Modified: python/branches/py3k-importlib/Doc/library/subprocess.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/subprocess.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/subprocess.rst	Thu Mar 27 00:48:05 2008
@@ -172,12 +172,14 @@
 
 .. method:: Popen.poll()
 
-   Check if child process has terminated.  Returns returncode attribute.
+   Check if child process has terminated.  Set and return :attr:`returncode`
+   attribute.
 
 
 .. method:: Popen.wait()
 
-   Wait for child process to terminate.  Returns returncode attribute.
+   Wait for child process to terminate.  Set and return :attr:`returncode`
+   attribute.
 
 
 .. method:: Popen.communicate(input=None)
@@ -187,15 +189,20 @@
    *input* argument should be a string to be sent to the child process, or
    ``None``, if no data should be sent to the child.
 
-   communicate() returns a tuple (stdout, stderr).
+   :meth:`communicate` returns a tuple ``(stdout, stderr)``.
+
+   Note that if you want to send data to the process's stdin, you need to create
+   the Popen object with ``stdin=PIPE``.  Similarly, to get anything other than
+   ``None`` in the result tuple, you need to give ``stdout=PIPE`` and/or
+   ``stderr=PIPE`` too.
 
    .. note::
 
-      The data read is buffered in memory, so do not use this method if the data size
-      is large or unlimited.
+      The data read is buffered in memory, so do not use this method if the data
+      size is large or unlimited.
 
-The following attributes are also available:
 
+The following attributes are also available:
 
 .. attribute:: Popen.stdin
 
@@ -222,9 +229,12 @@
 
 .. attribute:: Popen.returncode
 
-   The child return code.  A ``None`` value indicates that the process hasn't
-   terminated yet.  A negative value -N indicates that the child was terminated by
-   signal N (Unix only).
+   The child return code, set by :meth:`poll` and :meth:`wait` (and indirectly
+   by :meth:`communicate`).  A ``None`` value indicates that the process
+   hasn't terminated yet.
+   
+   A negative value ``-N`` indicates that the child was terminated by signal
+   ``N`` (Unix only).
 
 
 Replacing Older Functions with the subprocess Module

Modified: python/branches/py3k-importlib/Doc/library/sys.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/sys.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/sys.rst	Thu Mar 27 00:48:05 2008
@@ -54,6 +54,32 @@
    A string containing the copyright pertaining to the Python interpreter.
 
 
+.. function:: _compact_freelists()
+
+   Compact the free list of floats by deallocating unused blocks.
+   It can reduce the memory usage of the Python process several tenth of
+   thousands of integers or floats have been allocated at once.
+
+   The return value is a tuple of tuples each containing three elements,
+   amount of used objects, total block count before the blocks are deallocated
+   and amount of freed blocks. 
+
+   This function should be used for specialized purposes only.
+
+   .. versionadded:: 2.6
+
+
+.. function:: _clear_type_cache()
+
+   Clear the internal type cache. The type cache is used to speed up attribute
+   and method lookups. Use the function *only* to drop unnecessary references
+   during reference leak debugging.
+
+   This function should be used for internal and specialized purposes only.
+
+   .. versionadded:: 2.6
+
+
 .. function:: _current_frames()
 
    Return a dictionary mapping each thread's identifier to the topmost stack frame
@@ -78,11 +104,11 @@
 .. function:: displayhook(value)
 
    If *value* is not ``None``, this function prints it to ``sys.stdout``, and saves
-   it in ``__builtin__._``.
+   it in ``builtins._``.
 
-   ``sys.displayhook`` is called on the result of evaluating an expression entered
-   in an interactive Python session.  The display of these values can be customized
-   by assigning another one-argument function to ``sys.displayhook``.
+   ``sys.displayhook`` is called on the result of evaluating an :term:`expression`
+   entered in an interactive Python session.  The display of these values can be
+   customized by assigning another one-argument function to ``sys.displayhook``.
 
 
 .. function:: excepthook(type, value, traceback)
@@ -184,6 +210,86 @@
    error occurs.
 
 
+.. data:: flags
+
+   The struct sequence *flags* exposes the status of command line flags. The
+   attributes are read only.
+
+   +------------------------------+------------------------------------------+
+   | attribute                    | flag                                     |
+   +==============================+==========================================+
+   | :const:`debug`               | -d                                       |
+   +------------------------------+------------------------------------------+
+   | :const:`py3k_warning`        | -3                                       |
+   +------------------------------+------------------------------------------+
+   | :const:`division_warning`    | -Q                                       |
+   +------------------------------+------------------------------------------+
+   | :const:`division_new`        | -Qnew                                    |
+   +------------------------------+------------------------------------------+
+   | :const:`inspect`             | -i                                       |
+   +------------------------------+------------------------------------------+
+   | :const:`interactive`         | -i                                       |
+   +------------------------------+------------------------------------------+
+   | :const:`optimize`            | -O or -OO                                |
+   +------------------------------+------------------------------------------+
+   | :const:`dont_write_bytecode` | -B                                       |
+   +------------------------------+------------------------------------------+
+   | :const:`no_site`             | -S                                       |
+   +------------------------------+------------------------------------------+
+   | :const:`ignore_environment`  | -E                                       |
+   +------------------------------+------------------------------------------+
+   | :const:`tabcheck`            | -t or -tt                                |
+   +------------------------------+------------------------------------------+
+   | :const:`verbose`             | -v                                       |
+   +------------------------------+------------------------------------------+
+   | :const:`unicode`             | -U                                       |
+   +------------------------------+------------------------------------------+
+
+   .. versionadded:: 2.6
+
+
+.. data:: float_info
+
+   A structseq holding information about the float type. It contains low level
+   information about the precision and internal representation. Please study
+   your system's :file:`float.h` for more information.
+
+   +---------------------+--------------------------------------------------+
+   | attribute           |  explanation                                     |
+   +=====================+==================================================+
+   | :const:`epsilon`    | Difference between 1 and the next representable  |
+   |                     | floating point number                            |
+   +---------------------+--------------------------------------------------+
+   | :const:`dig`        | digits (see :file:`float.h`)                     |
+   +---------------------+--------------------------------------------------+
+   | :const:`mant_dig`   | mantissa digits (see :file:`float.h`)            |
+   +---------------------+--------------------------------------------------+
+   | :const:`max`        | maximum representable finite float               |
+   +---------------------+--------------------------------------------------+
+   | :const:`max_exp`    | maximum int e such that radix**(e-1) is in the   |
+   |                     | range of finite representable floats             |
+   +---------------------+--------------------------------------------------+
+   | :const:`max_10_exp` | maximum int e such that 10**e is in the          |
+   |                     | range of finite representable floats             |
+   +---------------------+--------------------------------------------------+
+   | :const:`min`        | Minimum positive normalizer float                |
+   +---------------------+--------------------------------------------------+
+   | :const:`min_exp`    | minimum int e such that radix**(e-1) is a        |
+   |                     | normalized float                                 |
+   +---------------------+--------------------------------------------------+
+   | :const:`min_10_exp` | minimum int e such that 10**e is a normalized    |
+   |                     | float                                            |
+   +---------------------+--------------------------------------------------+
+   | :const:`radix`      | radix of exponent                                |
+   +---------------------+--------------------------------------------------+
+   | :const:`rounds`     | addition rounds (see :file:`float.h`)            |
+   +---------------------+--------------------------------------------------+
+
+   .. note::
+
+      The information in the table is simplified.
+
+
 .. function:: getcheckinterval()
 
    Return the interpreter's "check interval"; see :func:`setcheckinterval`.
@@ -246,6 +352,35 @@
    This function should be used for internal and specialized purposes only.
 
 
+.. function:: getprofile()
+
+   .. index::
+      single: profile function
+      single: profiler
+
+   Get the profiler function as set by :func:`setprofile`.
+
+   .. versionadded:: 2.6
+
+
+.. function:: gettrace()
+
+   .. index::
+      single: trace function
+      single: debugger
+
+   Get the trace function as set by :func:`settrace`.
+
+   .. note::
+
+      The :func:`gettrace` function is intended only for implementing debuggers,
+      profilers, coverage tools and the like. Its behavior is part of the
+      implementation platform, rather than part of the language definition,
+      and thus may not be available in all Python implementations.
+
+   .. versionadded:: 2.6
+
+
 .. function:: getwindowsversion()
 
    Return a tuple containing five components, describing the Windows version
@@ -323,11 +458,11 @@
    etc.)
 
 
-.. data:: maxint
+.. data:: maxsize
 
-   The largest positive integer supported by Python's regular integer type.  This
-   is at least 2\*\*31-1.  The largest negative integer is ``-maxint-1`` --- the
-   asymmetry results from the use of 2's complement binary arithmetic.
+   An integer giving the maximum value a variable of type :ctype:`Py_ssize_t` can
+   take.  It's usually ``2**31 - 1`` on a 32-bit platform and ``2**63 - 1`` on a
+   64-bit platform.
 
 
 .. data:: maxunicode
@@ -364,9 +499,26 @@
 
 .. data:: platform
 
-   This string contains a platform identifier, e.g. ``'sunos5'`` or ``'linux1'``.
-   This can be used to append platform-specific components to ``path``, for
-   instance.
+   This string contains a platform identifier that can be used to append
+   platform-specific components to :data:`sys.path`, for instance.
+
+   For Unix systems, this is the lowercased OS name as returned by ``uname -s``
+   with the first part of the version as returned by ``uname -r`` appended,
+   e.g. ``'sunos5'`` or ``'linux2'``, *at the time when Python was built*.
+   For other systems, the values are:
+
+   ================ ===========================
+   System           :data:`platform` value
+   ================ ===========================
+   Windows          ``'win32'``
+   Windows/Cygwin   ``'cygwin'``
+   MacOS X          ``'darwin'``
+   MacOS 9          ``'mac'``
+   OS/2             ``'os2'``
+   OS/2 EMX         ``'os2emx'``
+   RiscOS           ``'riscos'``
+   AtheOS           ``'atheos'``
+   ================ ===========================
 
 
 .. data:: prefix
@@ -396,6 +548,17 @@
    implement a dynamic prompt.
 
 
+.. data:: dont_write_bytecode
+
+   If this is true, Python won't try to write ``.pyc`` or ``.pyo`` files on the
+   import of source modules.  This value is initially set to ``True`` or ``False``
+   depending on the ``-B`` command line option and the ``PYTHONDONTWRITEBYTECODE``
+   environment variable, but you can set it yourself to control bytecode file
+   generation.
+
+   .. versionadded:: 2.6
+
+
 .. function:: setcheckinterval(interval)
 
    Set the interpreter's "check interval".  This integer value determines how often
@@ -414,9 +577,8 @@
    implementation and, where needed, by :mod:`sitecustomize`.  Once used by the
    :mod:`site` module, it is removed from the :mod:`sys` module's namespace.
 
-   .. % Note that \refmodule{site} is not imported if
-   .. % the \programopt{-S} option is passed to the interpreter, in which
-   .. % case this function will remain available.
+   .. Note that :mod:`site` is not imported if the :option:`-S` option is passed
+      to the interpreter, in which case this function will remain available.
 
 
 .. function:: setdlopenflags(n)
@@ -494,14 +656,16 @@
           stderr
 
    File objects corresponding to the interpreter's standard input, output and error
-   streams.  ``stdin`` is used for all interpreter input except for scripts.
-   ``stdout`` is used for the output of :func:`print` and expression statements.
-   The interpreter's own prompts and (almost all of) its error messages go to
-   ``stderr``.  ``stdout`` and ``stderr`` needn't be built-in file objects: any
-   object is acceptable as long as it has a :meth:`write` method that takes a
-   string argument.  (Changing these objects doesn't affect the standard I/O
-   streams of processes executed by :func:`os.popen`, :func:`os.system` or the
-   :func:`exec\*` family of functions in the :mod:`os` module.)
+   streams.  ``stdin`` is used for all interpreter input except for scripts but
+   including calls to :func:`input`.  ``stdout`` is used for
+   the output of :func:`print` and :term:`expression` statements and for the
+   prompts of :func:`input`. The interpreter's own prompts
+   and (almost all of) its error messages go to ``stderr``.  ``stdout`` and
+   ``stderr`` needn't be built-in file objects: any object is acceptable as long
+   as it has a :meth:`write` method that takes a string argument.  (Changing these 
+   objects doesn't affect the standard I/O streams of processes executed by
+   :func:`os.popen`, :func:`os.system` or the :func:`exec\*` family of functions in
+   the :mod:`os` module.)
 
 
 .. data:: __stdin__
@@ -513,6 +677,13 @@
    could be useful to restore the actual files to known working file objects in
    case they have been overwritten with a broken object.
 
+  .. note::
+
+    Under some conditions ``stdin``, ``stdout`` and ``stderr`` as well as the
+    original values ``__stdin__``, ``__stdout__`` and ``__stderr__`` can be
+    None. It is usually the case for Windows GUI apps that aren't connected to
+    a console and Python apps started with :program:`pythonw`.
+
 
 .. data:: tracebacklimit
 
@@ -571,3 +742,4 @@
    Module :mod:`site`
       This describes how to use .pth files to extend ``sys.path``.
 
+

Modified: python/branches/py3k-importlib/Doc/library/tabnanny.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/tabnanny.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/tabnanny.rst	Thu Mar 27 00:48:05 2008
@@ -8,9 +8,7 @@
 .. moduleauthor:: Tim Peters <tim_one at users.sourceforge.net>
 .. sectionauthor:: Peter Funk <pf at artcom-gmbh.de>
 
-
-.. % rudimentary documentation based on module comments, by Peter Funk
-.. % <pf at artcom-gmbh.de>
+.. rudimentary documentation based on module comments
 
 For the time being this module is intended to be called as a script. However it
 is possible to import it into an IDE and use the function :func:`check`
@@ -55,14 +53,11 @@
    This function is used by :func:`check` as a callback parameter to the function
    :func:`tokenize.tokenize`.
 
-.. % XXX FIXME: Document \function{errprint},
-.. % \function{format_witnesses} \class{Whitespace}
-.. % check_equal, indents
-.. % \function{reset_globals}
+.. XXX document errprint, format_witnesses, Whitespace, check_equal, indents,
+   reset_globals
 
 
 .. seealso::
 
    Module :mod:`tokenize`
       Lexical scanner for Python source code.
-

Modified: python/branches/py3k-importlib/Doc/library/tarfile.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/tarfile.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/tarfile.rst	Thu Mar 27 00:48:05 2008
@@ -11,10 +11,13 @@
 .. sectionauthor:: Lars Gustäbel <lars at gustaebel.de>
 
 
-The :mod:`tarfile` module makes it possible to read and create tar archives.
+The :mod:`tarfile` module makes it possible to read and write tar
+archives, including those using gzip or bz2 compression.
+(:file:`.zip` files can be read and written using the :mod:`zipfile` module.)
+
 Some facts and figures:
 
-* reads and writes :mod:`gzip` and :mod:`bzip2` compressed archives.
+* reads and writes :mod:`gzip` and :mod:`bz2` compressed archives.
 
 * read/write support for the POSIX.1-1988 (ustar) format.
 
@@ -202,10 +205,6 @@
    `GNU tar manual, Basic Tar Format <http://www.gnu.org/software/tar/manual/html_node/tar_134.html#SEC134>`_
       Documentation for tar archive files, including GNU tar extensions.
 
-.. % -----------------
-.. % TarFile Objects
-.. % -----------------
-
 
 .. _tarfile-objects:
 
@@ -418,10 +417,6 @@
    A dictionary containing key-value pairs of pax global headers.
 
 
-.. % -----------------
-.. % TarInfo Objects
-.. % -----------------
-
 
 .. _tarinfo-objects:
 
@@ -571,10 +566,6 @@
 
    Return :const:`True` if it is one of character device, block device or FIFO.
 
-.. % ------------------------
-.. % Examples
-.. % ------------------------
-
 
 .. _tar-examples:
 
@@ -632,10 +623,6 @@
        tar.extract(tarinfo)
    tar.close()
 
-.. % ------------
-.. % Tar format
-.. % ------------
-
 
 .. _tar-formats:
 
@@ -676,11 +663,6 @@
 * The SunOS tar extended format. This format is a variant of the POSIX.1-2001
   pax format, but is not compatible.
 
-.. % ----------------
-.. % Unicode issues
-.. % ----------------
-
-
 .. _tar-unicode:
 
 Unicode issues

Modified: python/branches/py3k-importlib/Doc/library/telnetlib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/telnetlib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/telnetlib.rst	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,7 @@
 
 .. module:: telnetlib
    :synopsis: Telnet client class.
-.. sectionauthor:: Skip Montanaro <skip at mojam.com>
+.. sectionauthor:: Skip Montanaro <skip at pobox.com>
 
 
 .. index:: single: protocol; Telnet
@@ -211,16 +211,10 @@
 A simple example illustrating typical use::
 
    import getpass
-   import sys
    import telnetlib
 
-   def raw_input(prompt):
-       sys.stdout.write(prompt)
-       sys.stdout.flush()
-       return sys.stdin.readline()
-
    HOST = "localhost"
-   user = raw_input("Enter your remote account: ")
+   user = input("Enter your remote account: ")
    password = getpass.getpass()
 
    tn = telnetlib.Telnet(HOST)

Modified: python/branches/py3k-importlib/Doc/library/tempfile.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/tempfile.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/tempfile.rst	Thu Mar 27 00:48:05 2008
@@ -34,7 +34,7 @@
 
 .. function:: TemporaryFile([mode='w+b'[, bufsize=-1[, suffix[, prefix[, dir]]]]])
 
-   Return a file (or file-like) object that can be used as a temporary storage
+   Return a file-like object that can be used as a temporary storage
    area.  The file is created using :func:`mkstemp`. It will be destroyed as soon
    as it is closed (including an implicit close when the object is garbage
    collected).  Under Unix, the directory entry for the file is removed immediately
@@ -49,6 +49,11 @@
 
    The *dir*, *prefix* and *suffix* parameters are passed to :func:`mkstemp`.
 
+   The returned object is a true file object on POSIX platforms.  On other
+   platforms, it is a file-like object whose :attr:`file` attribute is the
+   underlying true file object. This file-like object can be used in a :keyword:`with`
+   statement, just like a normal file.
+
 
 .. function:: NamedTemporaryFile([mode='w+b'[, bufsize=-1[, suffix[, prefix[, dir[, delete]]]]]])
 
@@ -59,6 +64,9 @@
    the file a second time, while the named temporary file is still open, varies
    across platforms (it can be so used on Unix; it cannot on Windows NT or later).
    If *delete* is true (the default), the file is deleted as soon as it is closed.
+   The returned object is always a file-like object whose :attr:`file` attribute
+   is the underlying true file object. This file-like object can be used in a :keyword:`with`
+   statement, just like a normal file.
 
 
 .. function:: SpooledTemporaryFile([max_size=0, [mode='w+b'[, bufsize=-1[, suffix[, prefix[, dir]]]]]])
@@ -71,6 +79,11 @@
    The resulting file has one additional method, :func:`rollover`, which causes the
    file to roll over to an on-disk file regardless of its size.
 
+   The returned object is a file-like object whose :attr:`_file` attribute
+   is either a :class:`StringIO` object or a true file object, depending on
+   whether :func:`rollover` has been called. This file-like object can be used in a
+   :keyword:`with` statement, just like a normal file.
+
 
 .. function:: mkstemp([suffix[, prefix[, dir[, text]]]])
 

Modified: python/branches/py3k-importlib/Doc/library/termios.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/termios.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/termios.rst	Thu Mar 27 00:48:05 2008
@@ -90,12 +90,6 @@
 :keyword:`finally` statement to ensure that the old tty attributes are restored
 exactly no matter what happens::
 
-   def raw_input(prompt):
-       import sys
-       sys.stdout.write(prompt)
-       sys.stdout.flush()
-       return sys.stdin.readline()
-
    def getpass(prompt = "Password: "):
        import termios, sys
        fd = sys.stdin.fileno()
@@ -104,7 +98,7 @@
        new[3] = new[3] & ~termios.ECHO          # lflags
        try:
            termios.tcsetattr(fd, termios.TCSADRAIN, new)
-           passwd = raw_input(prompt)
+           passwd = input(prompt)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old)
        return passwd

Modified: python/branches/py3k-importlib/Doc/library/test.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/test.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/test.rst	Thu Mar 27 00:48:05 2008
@@ -33,8 +33,6 @@
 Writing Unit Tests for the :mod:`test` package
 ----------------------------------------------
 
-.. % 
-
 It is preferred that tests that use the :mod:`unittest` module follow a few
 guidelines. One is to name the test module by starting it with ``test_`` and end
 it with the name of the module being tested. The test methods in the test module
@@ -302,7 +300,7 @@
 
    This is a context manager than runs the :keyword:`with` statement body using
    a :class:`StringIO.StringIO` object as sys.stdout.  That object can be
-   retrieved using the ``as`` clause of the with statement.
+   retrieved using the ``as`` clause of the :keyword:`with` statement.
 
    Example use::
 

Modified: python/branches/py3k-importlib/Doc/library/thread.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/thread.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/thread.rst	Thu Mar 27 00:48:05 2008
@@ -63,12 +63,13 @@
    Raise the :exc:`SystemExit` exception.  When not caught, this will cause the
    thread to exit silently.
 
-.. % \begin{funcdesc}{exit_prog}{status}
-.. % Exit all threads and report the value of the integer argument
-.. % \var{status} as the exit status of the entire program.
-.. % \strong{Caveat:} code in pending \keyword{finally} clauses, in this thread
-.. % or in other threads, is not executed.
-.. % \end{funcdesc}
+..
+   function:: exit_prog(status)
+
+      Exit all threads and report the value of the integer argument
+      *status* as the exit status of the entire program.
+      **Caveat:** code in pending :keyword:`finally` clauses, in this thread
+      or in other threads, is not executed.
 
 
 .. function:: allocate_lock()
@@ -131,7 +132,6 @@
 In addition to these methods, lock objects can also be used via the
 :keyword:`with` statement, e.g.::
 
-   from __future__ import with_statement
    import thread
 
    a_lock = thread.allocate_lock()

Modified: python/branches/py3k-importlib/Doc/library/threading.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/threading.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/threading.rst	Thu Mar 27 00:48:05 2008
@@ -615,18 +615,19 @@
 
    When the *timeout* argument is present and not ``None``, it should be a floating
    point number specifying a timeout for the operation in seconds (or fractions
-   thereof). As :meth:`join` always  returns ``None``, you must call
-   :meth:`isAlive` to decide whether  a timeout happened.
+   thereof). As :meth:`join` always returns ``None``, you must call :meth:`isAlive`
+   after :meth:`join` to decide whether a timeout happened -- if the thread is
+   still alive, the :meth:`join` call timed out.
 
    When the *timeout* argument is not present or ``None``, the operation will block
    until the thread terminates.
 
    A thread can be :meth:`join`\ ed many times.
 
-   :meth:`join` may throw a :exc:`RuntimeError`, if an attempt is made to join the
-   current thread as that would cause a deadlock. It is also an error to
-   :meth:`join` a thread before it has been started and attempts to do so raises
-   same exception.
+   :meth:`join` raises a :exc:`RuntimeError` if an attempt is made to join
+   the current thread as that would cause a deadlock. It is also an error to
+   :meth:`join` a thread before it has been started and attempts to do so
+   raises the same exception.
 
 
 .. method:: Thread.getName()
@@ -716,7 +717,6 @@
 :class:`Semaphore`, and :class:`BoundedSemaphore` objects may be used as
 :keyword:`with` statement context managers.  For example::
 
-   from __future__ import with_statement
    import threading
 
    some_rlock = threading.RLock()
@@ -724,3 +724,26 @@
    with some_rlock:
        print("some_rlock is locked while this executes")
 
+
+.. _threaded-imports:
+
+Importing in threaded code
+--------------------------
+
+While the import machinery is thread safe, there are two key
+restrictions on threaded imports due to inherent limitations in the way
+that thread safety is provided:
+
+* Firstly, other than in the main module, an import should not have the
+  side effect of spawning a new thread and then waiting for that thread in
+  any way. Failing to abide by this restriction can lead to a deadlock if
+  the spawned thread directly or indirectly attempts to import a module.
+* Secondly, all import attempts must be completed before the interpreter
+  starts shutting itself down. This can be most easily achieved by only
+  performing imports from non-daemon threads created through the threading
+  module. Daemon threads and threads created directly with the thread
+  module will require some other form of synchronization to ensure they do
+  not attempt imports after system shutdown has commenced. Failure to
+  abide by this restriction will lead to intermittent exceptions and
+  crashes during interpreter shutdown (as the late imports attempt to
+  access machinery which is no longer in a valid state).

Modified: python/branches/py3k-importlib/Doc/library/time.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/time.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/time.rst	Thu Mar 27 00:48:05 2008
@@ -350,11 +350,12 @@
    The default values used to fill in any missing data when more accurate values
    cannot be inferred are ``(1900, 1, 1, 0, 0, 0, 0, 1, -1)``.
 
-   For example::
+   For example:
 
       >>> import time
-      >>> time.strptime("30 Nov 00", "%d %b %y")
-      (2000, 11, 30, 0, 0, 0, 3, 335, -1)
+      >>> time.strptime("30 Nov 00", "%d %b %y")   # doctest: +NORMALIZE_WHITESPACE
+      time.struct_time(tm_year=2000, tm_mon=11, tm_mday=30, tm_hour=0, tm_min=0,
+                       tm_sec=0, tm_wday=3, tm_yday=335, tm_isdst=-1)
 
    Support for the ``%Z`` directive is based on the values contained in ``tzname``
    and whether ``daylight`` is true.  Because of this, it is platform-specific

Modified: python/branches/py3k-importlib/Doc/library/timeit.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/timeit.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/timeit.rst	Thu Mar 27 00:48:05 2008
@@ -85,11 +85,12 @@
 
    .. note::
 
-      By default, :meth:`timeit` temporarily turns off garbage collection during the
-      timing.  The advantage of this approach is that it makes independent timings
-      more comparable.  This disadvantage is that GC may be an important component of
-      the performance of the function being measured.  If so, GC can be re-enabled as
-      the first statement in the *setup* string.  For example::
+      By default, :meth:`timeit` temporarily turns off :term:`garbage collection`
+      during the timing.  The advantage of this approach is that it makes
+      independent timings more comparable.  This disadvantage is that GC may be
+      an important component of the performance of the function being measured.
+      If so, GC can be re-enabled as the first statement in the *setup* string.
+      For example::
 
          timeit.Timer('for i in range(10): oct(i)', 'gc.enable()').timeit()
 

Modified: python/branches/py3k-importlib/Doc/library/tix.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/tix.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/tix.rst	Thu Mar 27 00:48:05 2008
@@ -35,7 +35,7 @@
    `Tix Programming Guide <http://tix.sourceforge.net/dist/current/docs/tix-book/tix.book.html>`_
       On-line version of the programmer's reference material.
 
-   `Tix Development Applications <http://tix.sourceforge.net/Tide/>`_
+   `Tix Development Applications <http://tix.sourceforge.net/Tixapps/src/Tide.html>`_
       Tix applications for development of Tix and Tkinter programs. Tide applications
       work under Tk or Tkinter, and include :program:`TixInspect`, an inspector to
       remotely modify and debug Tix/Tk/Tkinter applications.
@@ -88,7 +88,7 @@
 demo of all the :mod:`Tix` widgets in the :file:`Demo/tix` directory of the
 standard distribution.
 
-.. % The Python sample code is still being added to Python, hence commented out
+.. The Python sample code is still being added to Python, hence commented out
 
 
 Basic Widgets
@@ -103,8 +103,8 @@
    widget to which a Balloon widget has been bound, a small pop-up window with a
    descriptive message will be shown on the screen.
 
-.. % Python Demo of:
-.. % \ulink{Balloon}{http://tix.sourceforge.net/dist/current/demos/samples/Balloon.tcl}
+.. Python Demo of:
+.. \ulink{Balloon}{http://tix.sourceforge.net/dist/current/demos/samples/Balloon.tcl}
 
 
 .. class:: ButtonBox()
@@ -113,8 +113,8 @@
    <http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixButtonBox.htm>`_
    widget creates a box of buttons, such as is commonly used for ``Ok Cancel``.
 
-.. % Python Demo of:
-.. % \ulink{ButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/BtnBox.tcl}
+.. Python Demo of:
+.. \ulink{ButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/BtnBox.tcl}
 
 
 .. class:: ComboBox()
@@ -125,8 +125,8 @@
    choice by either typing in the entry subwdget or selecting from the listbox
    subwidget.
 
-.. % Python Demo of:
-.. % \ulink{ComboBox}{http://tix.sourceforge.net/dist/current/demos/samples/ComboBox.tcl}
+.. Python Demo of:
+.. \ulink{ComboBox}{http://tix.sourceforge.net/dist/current/demos/samples/ComboBox.tcl}
 
 
 .. class:: Control()
@@ -138,8 +138,8 @@
    the entry. The new value will be checked against the user-defined upper and
    lower limits.
 
-.. % Python Demo of:
-.. % \ulink{Control}{http://tix.sourceforge.net/dist/current/demos/samples/Control.tcl}
+.. Python Demo of:
+.. \ulink{Control}{http://tix.sourceforge.net/dist/current/demos/samples/Control.tcl}
 
 
 .. class:: LabelEntry()
@@ -149,8 +149,8 @@
    widget packages an entry widget and a label into one mega widget. It can be used
    be used to simplify the creation of "entry-form" type of interface.
 
-.. % Python Demo of:
-.. % \ulink{LabelEntry}{http://tix.sourceforge.net/dist/current/demos/samples/LabEntry.tcl}
+.. Python Demo of:
+.. \ulink{LabelEntry}{http://tix.sourceforge.net/dist/current/demos/samples/LabEntry.tcl}
 
 
 .. class:: LabelFrame()
@@ -161,8 +161,8 @@
    widgets inside a LabelFrame widget, one creates the new widgets relative to the
    :attr:`frame` subwidget and manage them inside the :attr:`frame` subwidget.
 
-.. % Python Demo of:
-.. % \ulink{LabelFrame}{http://tix.sourceforge.net/dist/current/demos/samples/LabFrame.tcl}
+.. Python Demo of:
+.. \ulink{LabelFrame}{http://tix.sourceforge.net/dist/current/demos/samples/LabFrame.tcl}
 
 
 .. class:: Meter()
@@ -172,8 +172,8 @@
    can be used to show the progress of a background job which may take a long time
    to execute.
 
-.. % Python Demo of:
-.. % \ulink{Meter}{http://tix.sourceforge.net/dist/current/demos/samples/Meter.tcl}
+.. Python Demo of:
+.. \ulink{Meter}{http://tix.sourceforge.net/dist/current/demos/samples/Meter.tcl}
 
 
 .. class:: OptionMenu()
@@ -182,8 +182,8 @@
    <http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixOptionMenu.htm>`_
    creates a menu button of options.
 
-.. % Python Demo of:
-.. % \ulink{OptionMenu}{http://tix.sourceforge.net/dist/current/demos/samples/OptMenu.tcl}
+.. Python Demo of:
+.. \ulink{OptionMenu}{http://tix.sourceforge.net/dist/current/demos/samples/OptMenu.tcl}
 
 
 .. class:: PopupMenu()
@@ -194,8 +194,8 @@
    of the :mod:`Tix` :class:`PopupMenu` widget is it requires less application code
    to manipulate.
 
-.. % Python Demo of:
-.. % \ulink{PopupMenu}{http://tix.sourceforge.net/dist/current/demos/samples/PopMenu.tcl}
+.. Python Demo of:
+.. \ulink{PopupMenu}{http://tix.sourceforge.net/dist/current/demos/samples/PopMenu.tcl}
 
 
 .. class:: Select()
@@ -205,8 +205,8 @@
    is a container of button subwidgets. It can be used to provide radio-box or
    check-box style of selection options for the user.
 
-.. % Python Demo of:
-.. % \ulink{Select}{http://tix.sourceforge.net/dist/current/demos/samples/Select.tcl}
+.. Python Demo of:
+.. \ulink{Select}{http://tix.sourceforge.net/dist/current/demos/samples/Select.tcl}
 
 
 .. class:: StdButtonBox()
@@ -215,8 +215,8 @@
    <http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixStdButtonBox.htm>`_
    widget is a group of standard buttons for Motif-like dialog boxes.
 
-.. % Python Demo of:
-.. % \ulink{StdButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/StdBBox.tcl}
+.. Python Demo of:
+.. \ulink{StdButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/StdBBox.tcl}
 
 
 File Selectors
@@ -231,8 +231,8 @@
    sub-directories. The user can choose one of the directories displayed in the
    list or change to another directory.
 
-.. % Python Demo of:
-.. % \ulink{DirList}{http://tix.sourceforge.net/dist/current/demos/samples/DirList.tcl}
+.. Python Demo of:
+.. \ulink{DirList}{http://tix.sourceforge.net/dist/current/demos/samples/DirList.tcl}
 
 
 .. class:: DirTree()
@@ -243,8 +243,8 @@
    sub-directories. The user can choose one of the directories displayed in the
    list or change to another directory.
 
-.. % Python Demo of:
-.. % \ulink{DirTree}{http://tix.sourceforge.net/dist/current/demos/samples/DirTree.tcl}
+.. Python Demo of:
+.. \ulink{DirTree}{http://tix.sourceforge.net/dist/current/demos/samples/DirTree.tcl}
 
 
 .. class:: DirSelectDialog()
@@ -255,8 +255,8 @@
    can use this dialog window to navigate through the file system to select the
    desired directory.
 
-.. % Python Demo of:
-.. % \ulink{DirSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/DirDlg.tcl}
+.. Python Demo of:
+.. \ulink{DirSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/DirDlg.tcl}
 
 
 .. class:: DirSelectBox()
@@ -276,8 +276,8 @@
    :class:`ExFileSelectBox` widget is very similar to the standard file dialog on
    MS Windows 3.1.
 
-.. % Python Demo of:
-.. % \ulink{ExFileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/EFileDlg.tcl}
+.. Python Demo of:
+.. \ulink{ExFileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/EFileDlg.tcl}
 
 
 .. class:: FileSelectBox()
@@ -289,8 +289,8 @@
    selected into a :class:`ComboBox` widget so that they can be quickly selected
    again.
 
-.. % Python Demo of:
-.. % \ulink{FileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/FileDlg.tcl}
+.. Python Demo of:
+.. \ulink{FileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/FileDlg.tcl}
 
 
 .. class:: FileEntry()
@@ -301,8 +301,8 @@
    manually. Alternatively, the user can press the button widget that sits next to
    the entry, which will bring up a file selection dialog.
 
-.. % Python Demo of:
-.. % \ulink{FileEntry}{http://tix.sourceforge.net/dist/current/demos/samples/FileEnt.tcl}
+.. Python Demo of:
+.. \ulink{FileEntry}{http://tix.sourceforge.net/dist/current/demos/samples/FileEnt.tcl}
 
 
 Hierachical ListBox
@@ -317,8 +317,8 @@
    file system directory trees. The list entries are indented and connected by
    branch lines according to their places in the hierarchy.
 
-.. % Python Demo of:
-.. % \ulink{HList}{http://tix.sourceforge.net/dist/current/demos/samples/HList1.tcl}
+.. Python Demo of:
+.. \ulink{HList}{http://tix.sourceforge.net/dist/current/demos/samples/HList1.tcl}
 
 
 .. class:: CheckList()
@@ -329,12 +329,12 @@
    similarly to the Tk checkbutton or radiobutton widgets, except it is capable of
    handling many more items than checkbuttons or radiobuttons.
 
-.. % Python Demo of:
-.. % \ulink{ CheckList}{http://tix.sourceforge.net/dist/current/demos/samples/ChkList.tcl}
-.. % Python Demo of:
-.. % \ulink{ScrolledHList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList.tcl}
-.. % Python Demo of:
-.. % \ulink{ScrolledHList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList2.tcl}
+.. Python Demo of:
+.. \ulink{ CheckList}{http://tix.sourceforge.net/dist/current/demos/samples/ChkList.tcl}
+.. Python Demo of:
+.. \ulink{ScrolledHList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList.tcl}
+.. Python Demo of:
+.. \ulink{ScrolledHList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList2.tcl}
 
 
 .. class:: Tree()
@@ -344,10 +344,10 @@
    can be used to display hierarchical data in a tree form. The user can adjust the
    view of the tree by opening or closing parts of the tree.
 
-.. % Python Demo of:
-.. % \ulink{Tree}{http://tix.sourceforge.net/dist/current/demos/samples/Tree.tcl}
-.. % Python Demo of:
-.. % \ulink{Tree (Dynamic)}{http://tix.sourceforge.net/dist/current/demos/samples/DynTree.tcl}
+.. Python Demo of:
+.. \ulink{Tree}{http://tix.sourceforge.net/dist/current/demos/samples/Tree.tcl}
+.. Python Demo of:
+.. \ulink{Tree (Dynamic)}{http://tix.sourceforge.net/dist/current/demos/samples/DynTree.tcl}
 
 
 Tabular ListBox
@@ -364,18 +364,18 @@
    in a two dimensional format and (2) you can use graphical images as well as
    multiple colors and fonts for the list entries.
 
-.. % Python Demo of:
-.. % \ulink{ScrolledTList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/STList1.tcl}
-.. % Python Demo of:
-.. % \ulink{ScrolledTList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/STList2.tcl}
-.. % Grid has yet to be added to Python
-.. % \subsubsection{Grid Widget}
-.. % Python Demo of:
-.. % \ulink{Simple Grid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid0.tcl}
-.. % Python Demo of:
-.. % \ulink{ScrolledGrid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid1.tcl}
-.. % Python Demo of:
-.. % \ulink{Editable Grid}{http://tix.sourceforge.net/dist/current/demos/samples/EditGrid.tcl}
+.. Python Demo of:
+.. \ulink{ScrolledTList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/STList1.tcl}
+.. Python Demo of:
+.. \ulink{ScrolledTList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/STList2.tcl}
+.. Grid has yet to be added to Python
+.. \subsubsection{Grid Widget}
+.. Python Demo of:
+.. \ulink{Simple Grid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid0.tcl}
+.. Python Demo of:
+.. \ulink{ScrolledGrid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid1.tcl}
+.. Python Demo of:
+.. \ulink{Editable Grid}{http://tix.sourceforge.net/dist/current/demos/samples/EditGrid.tcl}
 
 
 Manager Widgets
@@ -390,8 +390,8 @@
    The panes can be arranged either vertically or horizontally.  The user changes
    the sizes of the panes by dragging the resize handle between two panes.
 
-.. % Python Demo of:
-.. % \ulink{PanedWindow}{http://tix.sourceforge.net/dist/current/demos/samples/PanedWin.tcl}
+.. Python Demo of:
+.. \ulink{PanedWindow}{http://tix.sourceforge.net/dist/current/demos/samples/PanedWin.tcl}
 
 
 .. class:: ListNoteBook()
@@ -404,8 +404,8 @@
    can be shown. The user can navigate through these pages by choosing the name of
    the desired page in the :attr:`hlist` subwidget.
 
-.. % Python Demo of:
-.. % \ulink{ListNoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/ListNBK.tcl}
+.. Python Demo of:
+.. \ulink{ListNoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/ListNBK.tcl}
 
 
 .. class:: NoteBook()
@@ -417,18 +417,18 @@
    these pages can be shown. The user can navigate through these pages by choosing
    the visual "tabs" at the top of the NoteBook widget.
 
-.. % Python Demo of:
-.. % \ulink{NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/NoteBook.tcl}
+.. Python Demo of:
+.. \ulink{NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/NoteBook.tcl}
 
-.. % \subsubsection{Scrolled Widgets}
-.. % Python Demo of:
-.. % \ulink{ScrolledListBox}{http://tix.sourceforge.net/dist/current/demos/samples/SListBox.tcl}
-.. % Python Demo of:
-.. % \ulink{ScrolledText}{http://tix.sourceforge.net/dist/current/demos/samples/SText.tcl}
-.. % Python Demo of:
-.. % \ulink{ScrolledWindow}{http://tix.sourceforge.net/dist/current/demos/samples/SWindow.tcl}
-.. % Python Demo of:
-.. % \ulink{Canvas Object View}{http://tix.sourceforge.net/dist/current/demos/samples/CObjView.tcl}
+.. \subsubsection{Scrolled Widgets}
+.. Python Demo of:
+.. \ulink{ScrolledListBox}{http://tix.sourceforge.net/dist/current/demos/samples/SListBox.tcl}
+.. Python Demo of:
+.. \ulink{ScrolledText}{http://tix.sourceforge.net/dist/current/demos/samples/SText.tcl}
+.. Python Demo of:
+.. \ulink{ScrolledWindow}{http://tix.sourceforge.net/dist/current/demos/samples/SWindow.tcl}
+.. Python Demo of:
+.. \ulink{Canvas Object View}{http://tix.sourceforge.net/dist/current/demos/samples/CObjView.tcl}
 
 
 Image Types
@@ -440,10 +440,10 @@
   capabilities to all :mod:`Tix` and :mod:`Tkinter` widgets to create color images
   from XPM files.
 
-  .. % Python Demo of:
-  .. % \ulink{XPM Image In Button}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm.tcl}
-  .. % Python Demo of:
-  .. % \ulink{XPM Image In Menu}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm1.tcl}
+  .. Python Demo of:
+  .. \ulink{XPM Image In Button}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm.tcl}
+  .. Python Demo of:
+  .. \ulink{XPM Image In Menu}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm1.tcl}
 
 * `Compound
   <http://tix.sourceforge.net/dist/current/man/html/TixCmd/compound.htm>`_ image
@@ -453,14 +453,14 @@
   display a bitmap and a text string simultaneously in a Tk :class:`Button`
   widget.
 
-  .. % Python Demo of:
-  .. % \ulink{Compound Image In Buttons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg.tcl}
-  .. % Python Demo of:
-  .. % \ulink{Compound Image In NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg2.tcl}
-  .. % Python Demo of:
-  .. % \ulink{Compound Image Notebook Color Tabs}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg4.tcl}
-  .. % Python Demo of:
-  .. % \ulink{Compound Image Icons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg3.tcl}
+  .. Python Demo of:
+  .. \ulink{Compound Image In Buttons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg.tcl}
+  .. Python Demo of:
+  .. \ulink{Compound Image In NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg2.tcl}
+  .. Python Demo of:
+  .. \ulink{Compound Image Notebook Color Tabs}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg4.tcl}
+  .. Python Demo of:
+  .. \ulink{Compound Image Icons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg3.tcl}
 
 
 Miscellaneous Widgets

Modified: python/branches/py3k-importlib/Doc/library/tk.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/tk.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/tk.rst	Thu Mar 27 00:48:05 2008
@@ -36,8 +36,8 @@
    idle.rst
    othergui.rst
 
-.. % Other sections I have in mind are
-.. % Tkinter internals
-.. % Freezing Tkinter applications
+.. Other sections I have in mind are
+   Tkinter internals
+   Freezing Tkinter applications
 
 

Modified: python/branches/py3k-importlib/Doc/library/tkinter.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/tkinter.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/tkinter.rst	Thu Mar 27 00:48:05 2008
@@ -21,7 +21,7 @@
    `An Introduction to Tkinter <http://www.pythonware.com/library/an-introduction-to-tkinter.htm>`_
       Fredrik Lundh's on-line reference material.
 
-   `Tkinter reference: a GUI for Python <http://www.nmt.edu/tcc/help/pubs/lang.html>`_
+   `Tkinter reference: a GUI for Python <http://infohost.nmt.edu/tcc/help/pubs/lang.html>`_
       On-line reference material.
 
    `Tkinter for JPython <http://jtkinter.sourceforge.net>`_
@@ -59,7 +59,7 @@
    widget of Tk which usually is the main window of an application. Each instance
    has its own associated Tcl interpreter.
 
-   .. % FIXME: The following keyword arguments are currently recognized:
+   .. FIXME: The following keyword arguments are currently recognized:
 
 
 .. function:: Tcl(screenName=None, baseName=None, className='Tk', useTk=0)
@@ -114,8 +114,6 @@
 Tkinter.  Rather, it is intended as a stop gap, providing some introductory
 orientation on the system.
 
-.. % Converted to LaTeX by Mike Clarkson.
-
 Credits:
 
 * Tkinter was written by Steen Lumholt and Guido van Rossum.
@@ -218,8 +216,6 @@
 programmers almost always refer to the classes at the very bottom of the
 hierarchy.
 
-.. % BriefTclTk.html
-
 Notes:
 
 * These classes are provided for the purposes of organizing certain functions
@@ -334,13 +330,6 @@
 How Tk and Tkinter are Related
 ------------------------------
 
-.. % Relationship.html
-
-.. note::
-
-   This was derived from a graphical image; the image will be used more directly in
-   a subsequent version of this document.
-
 From the top down:
 
 Your App Here (Python)
@@ -453,8 +442,6 @@
 
 .. index:: single: packing (widgets)
 
-.. % Packer.html
-
 The packer is one of Tk's geometry-management mechanisms.    Geometry managers
 are used to specify the relative positioning of the positioning of widgets
 within their container - their mutual *master*.  In contrast to the more
@@ -463,8 +450,6 @@
 *filling*, etc - and works everything out to determine the exact placement
 coordinates for you.
 
-.. % See also \citetitle[classes/ClassPacker.html]{the Packer class interface}.
-
 The size of any *master* widget is determined by the size of the "slave widgets"
 inside.  The packer is used to control where slave widgets appear inside the
 master into which they are packed.  You can pack widgets into frames, and frames
@@ -521,8 +506,6 @@
 ``value``.  This connection works both ways: if the variable changes for any
 reason, the widget it's connected to will be updated to reflect the new value.
 
-.. % VarCouplings.html
-
 Unfortunately, in the current implementation of :mod:`Tkinter` it is not
 possible to hand over an arbitrary Python variable to a widget through a
 ``variable`` or ``textvariable`` option.  The only kinds of variables for which
@@ -569,8 +552,6 @@
 
 .. index:: single: window manager (widgets)
 
-.. % WindowMgr.html
-
 In Tk, there is a utility command, ``wm``, for interacting with the window
 manager.  Options to the ``wm`` command allow you to control things like titles,
 placement, icon bitmaps, and the like.  In :mod:`Tkinter`, these commands have
@@ -585,8 +566,6 @@
 This method begins with an underscore to denote the fact that this function is
 part of the implementation, and not an interface to Tk functionality.
 
-.. % See also \citetitle[classes/ClassWm.html]{the Wm class interface}.
-
 Here are some examples of typical usage::
 
    from Tkinter import *
@@ -614,8 +593,6 @@
 
 .. index:: single: Tk Option Data Types
 
-.. % OptionTypes.html
-
 anchor
    Legal values are points of the compass: ``"n"``, ``"ne"``, ``"e"``, ``"se"``,
    ``"s"``, ``"sw"``, ``"w"``, ``"nw"``, and also ``"center"``.
@@ -695,8 +672,6 @@
    single: bind (widgets)
    single: events (widgets)
 
-.. % Bindings.html
-
 The bind method from the widget command allows you to watch for certain events
 and to have a callback function trigger when that event type occurs.  The form
 of the bind method is::
@@ -752,8 +727,6 @@
 point at a specific place in a Text widget, or to particular characters in an
 Entry widget, or to particular menu items in a Menu widget.
 
-.. % Index.html
-
 Entry widget indexes (index, view index, etc.)
    Entry widgets have options that refer to character positions in the text being
    displayed.  You can use these :mod:`Tkinter` functions to access these special

Modified: python/branches/py3k-importlib/Doc/library/tokenize.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/tokenize.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/tokenize.rst	Thu Mar 27 00:48:05 2008
@@ -9,50 +9,34 @@
 
 
 The :mod:`tokenize` module provides a lexical scanner for Python source code,
-implemented in Python.  The scanner in this module returns comments as tokens as
-well, making it useful for implementing "pretty-printers," including colorizers
-for on-screen displays.
+implemented in Python.  The scanner in this module returns comments as tokens
+as well, making it useful for implementing "pretty-printers," including
+colorizers for on-screen displays.
 
-The primary entry point is a generator:
+The primary entry point is a :term:`generator`:
 
 
-.. function:: generate_tokens(readline)
+.. function:: tokenize(readline)
 
-   The :func:`generate_tokens` generator requires one argment, *readline*, which
+   The :func:`tokenize` generator requires one argument, *readline*, which
    must be a callable object which provides the same interface as the
    :meth:`readline` method of built-in file objects (see section
-   :ref:`bltin-file-objects`).  Each call to the function should return one line of
-   input as a string.
+   :ref:`bltin-file-objects`).  Each call to the function should return one 
+   line of input as bytes.
 
-   The generator produces 5-tuples with these members: the token type; the token
-   string; a 2-tuple ``(srow, scol)`` of ints specifying the row and column where
-   the token begins in the source; a 2-tuple ``(erow, ecol)`` of ints specifying
-   the row and column where the token ends in the source; and the line on which the
-   token was found. The line passed is the *logical* line; continuation lines are
-   included.
-
-
-An older entry point is retained for backward compatibility:
-
-.. function:: tokenize(readline[, tokeneater])
-
-   The :func:`tokenize` function accepts two parameters: one representing the input
-   stream, and one providing an output mechanism for :func:`tokenize`.
-
-   The first parameter, *readline*, must be a callable object which provides the
-   same interface as the :meth:`readline` method of built-in file objects (see
-   section :ref:`bltin-file-objects`).  Each call to the function should return one
-   line of input as a string. Alternately, *readline* may be a callable object that
-   signals completion by raising :exc:`StopIteration`.
-
-   The second parameter, *tokeneater*, must also be a callable object.  It is
-   called once for each token, with five arguments, corresponding to the tuples
-   generated by :func:`generate_tokens`.
+   The generator produces 5-tuples with these members: the token type; the 
+   token string; a 2-tuple ``(srow, scol)`` of ints specifying the row and 
+   column where the token begins in the source; a 2-tuple ``(erow, ecol)`` of 
+   ints specifying the row and column where the token ends in the source; and 
+   the line on which the token was found. The line passed is the *logical* 
+   line; continuation lines are included.
+   
+   tokenize determines the source encoding of the file by looking for a utf-8
+   bom or encoding cookie, according to :pep:`263`.
 
 
 All constants from the :mod:`token` module are also exported from
-:mod:`tokenize`, as are two additional token type values that might be passed to
-the *tokeneater* function by :func:`tokenize`:
+:mod:`tokenize`, as are three additional token type values:
 
 .. data:: COMMENT
 
@@ -62,55 +46,95 @@
 .. data:: NL
 
    Token value used to indicate a non-terminating newline.  The NEWLINE token
-   indicates the end of a logical line of Python code; NL tokens are generated when
-   a logical line of code is continued over multiple physical lines.
+   indicates the end of a logical line of Python code; NL tokens are generated 
+   when a logical line of code is continued over multiple physical lines.
 
-Another function is provided to reverse the tokenization process. This is useful
-for creating tools that tokenize a script, modify the token stream, and write
-back the modified script.
 
+.. data:: ENCODING
 
-.. function:: untokenize(iterable)
+    Token value that indicates the encoding used to decode the source bytes 
+    into text. The first token returned by :func:`tokenize` will always be an 
+    ENCODING token.
+
+
+Another function is provided to reverse the tokenization process. This is 
+useful for creating tools that tokenize a script, modify the token stream, and 
+write back the modified script.
 
-   Converts tokens back into Python source code.  The *iterable* must return
-   sequences with at least two elements, the token type and the token string.  Any
-   additional sequence elements are ignored.
-
-   The reconstructed script is returned as a single string.  The result is
-   guaranteed to tokenize back to match the input so that the conversion is
-   lossless and round-trips are assured.  The guarantee applies only to the token
-   type and token string as the spacing between tokens (column positions) may
-   change.
 
+.. function:: untokenize(iterable)
+
+    Converts tokens back into Python source code.  The *iterable* must return
+    sequences with at least two elements, the token type and the token string. 
+    Any additional sequence elements are ignored.
+    
+    The reconstructed script is returned as a single string.  The result is
+    guaranteed to tokenize back to match the input so that the conversion is
+    lossless and round-trips are assured.  The guarantee applies only to the 
+    token type and token string as the spacing between tokens (column 
+    positions) may change.
+    
+    It returns bytes, encoded using the ENCODING token, which is the first 
+    token sequence output by :func:`tokenize`.
+
+
+:func:`tokenize` needs to detect the encoding of source files it tokenizes. The
+function it uses to do this is available:
+
+.. function:: detect_encoding(readline)
+
+    The :func:`detect_encoding` function is used to detect the encoding that 
+    should be used to decode a Python source file. It requires one argment, 
+    readline, in the same way as the :func:`tokenize` generator.
+    
+    It will call readline a maximum of twice, and return the encoding used
+    (as a string) and a list of any lines (not decoded from bytes) it has read
+    in.
+    
+    It detects the encoding from the presence of a utf-8 bom or an encoding
+    cookie as specified in pep-0263. If both a bom and a cookie are present,
+    but disagree, a SyntaxError will be raised.
+    
+    If no encoding is specified, then the default of 'utf-8' will be returned. 
 
+    
 Example of a script re-writer that transforms float literals into Decimal
 objects::
 
-   def decistmt(s):
-       """Substitute Decimals for floats in a string of statements.
+    def decistmt(s):
+        """Substitute Decimals for floats in a string of statements.
+    
+        >>> from decimal import Decimal
+        >>> s = 'print(+21.3e-5*-.1234/81.7)'
+        >>> decistmt(s)
+        "print (+Decimal ('21.3e-5')*-Decimal ('.1234')/Decimal ('81.7'))"
+    
+        The format of the exponent is inherited from the platform C library.
+        Known cases are "e-007" (Windows) and "e-07" (not Windows).  Since
+        we're only showing 12 digits, and the 13th isn't close to 5, the
+        rest of the output should be platform-independent.
+    
+        >>> exec(s) #doctest: +ELLIPSIS
+        -3.21716034272e-0...7
+    
+        Output from calculations with Decimal should be identical across all
+        platforms.
+    
+        >>> exec(decistmt(s))
+        -3.217160342717258261933904529E-7
+        """
+        result = []
+        g = tokenize(BytesIO(s.encode('utf-8')).readline) # tokenize the string
+        for toknum, tokval, _, _, _  in g:
+            if toknum == NUMBER and '.' in tokval:  # replace NUMBER tokens
+                result.extend([
+                    (NAME, 'Decimal'),
+                    (OP, '('),
+                    (STRING, repr(tokval)),
+                    (OP, ')')
+                ])
+            else:
+                result.append((toknum, tokval))
+        return untokenize(result).decode('utf-8')
 
-       >>> from decimal import Decimal
-       >>> s = 'print(+21.3e-5*-.1234/81.7)'
-       >>> decistmt(s)
-       "print(+Decimal ('21.3e-5')*-Decimal ('.1234')/Decimal ('81.7'))"
-
-       >>> exec(s)
-       -3.21716034272e-007
-       >>> exec(decistmt(s))
-       -3.217160342717258261933904529E-7
-
-       """
-       result = []
-       g = generate_tokens(StringIO(s).readline)   # tokenize the string
-       for toknum, tokval, _, _, _  in g:
-           if toknum == NUMBER and '.' in tokval:  # replace NUMBER tokens
-               result.extend([
-                   (NAME, 'Decimal'),
-                   (OP, '('),
-                   (STRING, repr(tokval)),
-                   (OP, ')')
-               ])
-           else:
-               result.append((toknum, tokval))
-       return untokenize(result)
 

Modified: python/branches/py3k-importlib/Doc/library/trace.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/trace.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/trace.rst	Thu Mar 27 00:48:05 2008
@@ -64,12 +64,14 @@
    stdout for each file processed.
 
 :option:`--ignore-module`
-   Ignore the named module and its submodules (if it is a package).  May be given
+   Accepts comma separated list of module names. Ignore each of the named
+   module and its submodules (if it is a package).  May be given 
    multiple times.
 
 :option:`--ignore-dir`
-   Ignore all modules and packages in the named directory and subdirectories.  May
-   be given multiple times.
+   Ignore all modules and packages in the named directory and subdirectories
+   (multiple directories can be joined by os.pathsep).  May be given multiple
+   times. 
 
 
 .. _trace-api:
@@ -78,7 +80,7 @@
 ---------------------
 
 
-.. class:: Trace([count=1[, trace=1[, countfuncs=0[, countcallers=0[, ignoremods=()[, ignoredirs=()[, infile=None[, outfile=None]]]]]]]])
+.. class:: Trace([count=1[, trace=1[, countfuncs=0[, countcallers=0[, ignoremods=()[, ignoredirs=()[, infile=None[, outfile=None[, timing=False]]]]]]]]])
 
    Create an object to trace execution of a single statement or expression. All
    parameters are optional.  *count* enables counting of line numbers. *trace*
@@ -87,7 +89,8 @@
    *ignoremods* is a list of modules or packages to ignore.  *ignoredirs* is a list
    of directories whose modules or packages should be ignored.  *infile* is the
    file from which to read stored count information.  *outfile* is a file in which
-   to write updated count information.
+   to write updated count information. *timing* enables a timestamp relative
+   to when tracing was started to be displayed.
 
 
 .. method:: Trace.run(cmd)

Modified: python/branches/py3k-importlib/Doc/library/traceback.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/traceback.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/traceback.rst	Thu Mar 27 00:48:05 2008
@@ -42,7 +42,7 @@
 
 .. function:: print_exc([limit[, file]])
 
-   This is a shorthand for ``print_exception(*sys.exc_info()``.
+   This is a shorthand for ``print_exception(*sys.exc_info())``.
 
 
 .. function:: format_exc([limit])
@@ -132,8 +132,8 @@
 
 .. _traceback-example:
 
-Traceback Example
------------------
+Traceback Examples
+------------------
 
 This simple example implements a basic read-eval-print loop, similar to (but
 less useful than) the standard Python interactive interpreter loop.  For a more
@@ -143,7 +143,7 @@
    import sys, traceback
 
    def run_user_code(envdir):
-       source = raw_input(">>> ")
+       source = input(">>> ")
        try:
            exec(source, envdir)
        except:
@@ -156,3 +156,124 @@
    while True:
        run_user_code(envdir)
 
+
+The following example demonstrates the different ways to print and format the
+exception and traceback::
+
+   import sys, traceback
+
+   def lumberjack():
+       bright_side_of_death()
+   
+   def bright_side_of_death():
+       return tuple()[0]
+   
+   try:
+       lumberjack()
+   except:
+       exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
+       print("*** print_tb:")
+       traceback.print_tb(exceptionTraceback, limit=1, file=sys.stdout)
+       print("*** print_exception:")
+       traceback.print_exception(exceptionType, exceptionValue, exceptionTraceback,
+                                 limit=2, file=sys.stdout)
+       print("*** print_exc:")
+       traceback.print_exc()
+       print("*** format_exc, first and last line:")
+       formatted_lines = traceback.format_exc().splitlines()
+       print(formatted_lines[0])
+       print(formatted_lines[-1])
+       print("*** format_exception:")
+       print(repr(traceback.format_exception(exceptionType, exceptionValue,
+                                             exceptionTraceback)))
+       print("*** extract_tb:")
+       print(repr(traceback.extract_tb(exceptionTraceback)))
+       print("*** format_tb:")
+       print(repr(traceback.format_tb(exceptionTraceback)))
+       print("*** tb_lineno:", traceback.tb_lineno(exceptionTraceback))
+   print("*** print_last:")
+   traceback.print_last()
+
+
+The output for the example would look similar to this::
+
+   *** print_tb:
+     File "<doctest>", line 9, in <module>
+       lumberjack()
+   *** print_exception:
+   Traceback (most recent call last):
+     File "<doctest>", line 9, in <module>
+       lumberjack()
+     File "<doctest>", line 3, in lumberjack
+       bright_side_of_death()
+   IndexError: tuple index out of range
+   *** print_exc:
+   Traceback (most recent call last):
+     File "<doctest>", line 9, in <module>
+       lumberjack()
+     File "<doctest>", line 3, in lumberjack
+       bright_side_of_death()
+   IndexError: tuple index out of range
+   *** format_exc, first and last line:
+   Traceback (most recent call last):
+   IndexError: tuple index out of range
+   *** format_exception:
+   ['Traceback (most recent call last):\n',
+    '  File "<doctest>", line 9, in <module>\n    lumberjack()\n',
+    '  File "<doctest>", line 3, in lumberjack\n    bright_side_of_death()\n',
+    '  File "<doctest>", line 6, in bright_side_of_death\n    return tuple()[0]\n',
+    'IndexError: tuple index out of range\n']
+   *** extract_tb:
+   [('<doctest>', 9, '<module>', 'lumberjack()'),
+    ('<doctest>', 3, 'lumberjack', 'bright_side_of_death()'),
+    ('<doctest>', 6, 'bright_side_of_death', 'return tuple()[0]')]
+   *** format_tb:
+   ['  File "<doctest>", line 9, in <module>\n    lumberjack()\n',
+    '  File "<doctest>", line 3, in lumberjack\n    bright_side_of_death()\n',
+    '  File "<doctest>", line 6, in bright_side_of_death\n    return tuple()[0]\n']
+   *** tb_lineno: 2
+   *** print_last:
+   Traceback (most recent call last):
+     File "<doctest>", line 9, in <module>
+       lumberjack()
+     File "<doctest>", line 3, in lumberjack
+       bright_side_of_death()
+   IndexError: tuple index out of range
+
+
+The following example shows the different ways to print and format the stack::
+
+   >>> import traceback
+   >>> def another_function():
+   ...     lumberstack()
+   ... 
+   >>> def lumberstack():
+   ...     traceback.print_stack()
+   ...     print(repr(traceback.extract_stack()))
+   ...     print(repr(traceback.format_stack()))
+   ... 
+   >>> another_function()
+     File "<doctest>", line 10, in <module>
+       another_function()
+     File "<doctest>", line 3, in another_function
+       lumberstack()
+     File "<doctest>", line 6, in lumberstack
+       traceback.print_stack()
+   [('<doctest>', 10, '<module>', 'another_function()'),
+    ('<doctest>', 3, 'another_function', 'lumberstack()'),
+    ('<doctest>', 7, 'lumberstack', 'print(repr(traceback.extract_stack()))')]
+   ['  File "<doctest>", line 10, in <module>\n    another_function()\n',
+    '  File "<doctest>", line 3, in another_function\n    lumberstack()\n',
+    '  File "<doctest>", line 8, in lumberstack\n    print(repr(traceback.format_stack()))\n']
+
+
+This last example demonstrates the final few formatting functions::
+
+   >>> import traceback
+   >>> format_list([('spam.py', 3, '<module>', 'spam.eggs()'),
+   ...              ('eggs.py', 42, 'eggs', 'return "bacon"')])
+   ['  File "spam.py", line 3, in <module>\n    spam.eggs()\n',
+    '  File "eggs.py", line 42, in eggs\n    return "bacon"\n']
+   >>> theError = IndexError('tuple indx out of range')
+   >>> traceback.format_exception_only(type(theError), theError)
+   ['IndexError: tuple index out of range\n']

Modified: python/branches/py3k-importlib/Doc/library/turtle.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/turtle.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/turtle.rst	Thu Mar 27 00:48:05 2008
@@ -285,5 +285,5 @@
 .. method:: Turtle.degrees([fullcircle])
 
    *fullcircle* is by default 360. This can cause the pen to have any angular units
-   whatever: give *fullcircle* 2\*$Ï€ for radians, or 400 for gradians.
+   whatever: give *fullcircle* ``2*pi`` for radians, or 400 for gradians.
 

Modified: python/branches/py3k-importlib/Doc/library/types.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/types.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/types.rst	Thu Mar 27 00:48:05 2008
@@ -33,77 +33,10 @@
        else:
           mylist.remove(item)
 
-The module defines the following names:
-
-
-.. data:: NoneType
-
-   The type of ``None``.
-
-
-.. data:: TypeType
-          ClassType
-
-   .. index:: builtin: type
-
-   The type of type objects (such as returned by :func:`type`) and user-defined
-   classes without metaclass; alias of the built-in :class:`type`.
-
-
-.. data:: ObjectType
-
-   Alias of the built-in :func:`object`.
-
-
-.. data:: BooleanType
-
-   The type of the :class:`bool` values ``True`` and ``False``; alias of the
-   built-in :class:`bool`.
-
-
-.. data:: IntType
-          LongType
-
-   The type of integers (e.g. ``1``); alias of the built-in :class:`int`.
-
-
-.. data:: FloatType
-
-   The type of floating point numbers (e.g. ``1.0``); alias of the built-in
-   :class:`float`.
-
-
-.. data:: ComplexType
-
-   The type of complex numbers (e.g. ``1.0j``); alias of the built-in
-   :class:`complex`.  This is not defined if Python was built without complex
-   number support.
-
-
-.. data:: StringType
-
-   The type of character strings (e.g. ``'Spam'``); alias of the built-in
-   :class:`str`.
-
-
-.. data:: TupleType
-
-   The type of tuples (e.g. ``(1, 2, 3, 'Spam')``); alias of the built-in
-   :class:`tuple`.
-
-
-.. data:: ListType
-
-   The type of lists (e.g. ``[0, 1, 2, 3]``); alias of the built-in
-   :class:`list`.
-
-
-.. data:: DictType
-          DictionaryType
-
-   The type of dictionaries (e.g. ``{'Bacon': 1, 'Ham': 0}``); alias of the
-   built-in :class:`dict`.
+Starting in Python 3.0 all types that are also available as builtins are no
+longer exposed through the types module.
 
+The module defines the following names:
 
 .. data:: FunctionType
           LambdaType
@@ -113,8 +46,8 @@
 
 .. data:: GeneratorType
 
-   The type of generator-iterator objects, produced by calling a generator
-   function.
+   The type of :term:`generator`-iterator objects, produced by calling a
+   generator function.
 
 
 .. data:: CodeType
@@ -125,7 +58,6 @@
 
 
 .. data:: MethodType
-          UnboundMethdType
 
    The type of methods of user-defined class instances.
 
@@ -141,19 +73,6 @@
    The type of modules.
 
 
-.. data:: SliceType
-
-   .. index:: builtin: slice
-
-   The type of objects returned by :func:`slice`; alias of the built-in
-   :class:`slice`.
-
-
-.. data:: EllipsisType
-
-   The type of ``Ellipsis``.
-
-
 .. data:: TracebackType
 
    The type of traceback objects such as found in ``sys.exc_info()[2]``.
@@ -165,24 +84,6 @@
    traceback object.
 
 
-.. XXX!
-.. data:: BufferType
-
-   .. index:: builtin: buffer
-
-   The type of buffer objects created by the :func:`buffer` function.
-
-
-.. data:: DictProxyType
-
-   The type of dict proxies, such as ``TypeType.__dict__``.
-
-
-.. data:: NotImplementedType
-
-   The type of ``NotImplemented``
-
-
 .. data:: GetSetDescriptorType
 
    The type of objects defined in extension modules with ``PyGetSetDef``, such as

Modified: python/branches/py3k-importlib/Doc/library/undoc.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/undoc.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/undoc.rst	Thu Mar 27 00:48:05 2008
@@ -61,18 +61,6 @@
    :synopsis: Rudimentary decoder for AppleSingle format files.
 
 
-
-:mod:`buildtools` --- Helper module for BuildApplet and Friends
----------------------------------------------------------------
-
-.. module:: buildtools
-   :platform: Mac
-   :synopsis: Helper module for BuildApplet, BuildApplication and macfreeze.
-
-
-.. deprecated:: 2.4
-
-
 :mod:`icopen` --- Internet Config replacement for :meth:`open`
 --------------------------------------------------------------
 
@@ -169,3 +157,27 @@
 in the build tree and either rebuilding Python if the modules are statically
 linked, or building and installing the shared object if using dynamically-loaded
 extensions.
+
+.. (lib-old is empty as of Python 2.5)
+
+   Those which are written in Python will be installed into the directory
+   \file{lib-old/} installed as part of the standard library.  To use
+   these, the directory must be added to \code{sys.path}, possibly using
+   \envvar{PYTHONPATH}.
+
+:mod:`timing`
+   --- Measure time intervals to high resolution (use :func:`time.clock` instead).
+
+
+SGI-specific Extension modules
+==============================
+
+The following are SGI specific, and may be out of touch with the current version
+of reality.
+
+:mod:`cl`
+   --- Interface to the SGI compression library.
+
+:mod:`sv`
+   --- Interface to the "simple video" board on SGI Indigo (obsolete hardware).
+

Modified: python/branches/py3k-importlib/Doc/library/unicodedata.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/unicodedata.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/unicodedata.rst	Thu Mar 27 00:48:05 2008
@@ -27,72 +27,72 @@
 .. function:: lookup(name)
 
    Look up character by name.  If a character with the given name is found, return
-   the corresponding Unicode character.  If not found, :exc:`KeyError` is raised.
+   the corresponding character.  If not found, :exc:`KeyError` is raised.
 
 
-.. function:: name(unichr[, default])
+.. function:: name(chr[, default])
 
-   Returns the name assigned to the Unicode character *unichr* as a string. If no
+   Returns the name assigned to the character *chr* as a string. If no
    name is defined, *default* is returned, or, if not given, :exc:`ValueError` is
    raised.
 
 
-.. function:: decimal(unichr[, default])
+.. function:: decimal(chr[, default])
 
-   Returns the decimal value assigned to the Unicode character *unichr* as integer.
+   Returns the decimal value assigned to the character *chr* as integer.
    If no such value is defined, *default* is returned, or, if not given,
    :exc:`ValueError` is raised.
 
 
-.. function:: digit(unichr[, default])
+.. function:: digit(chr[, default])
 
-   Returns the digit value assigned to the Unicode character *unichr* as integer.
+   Returns the digit value assigned to the character *chr* as integer.
    If no such value is defined, *default* is returned, or, if not given,
    :exc:`ValueError` is raised.
 
 
-.. function:: numeric(unichr[, default])
+.. function:: numeric(chr[, default])
 
-   Returns the numeric value assigned to the Unicode character *unichr* as float.
+   Returns the numeric value assigned to the character *chr* as float.
    If no such value is defined, *default* is returned, or, if not given,
    :exc:`ValueError` is raised.
 
 
-.. function:: category(unichr)
+.. function:: category(chr)
 
-   Returns the general category assigned to the Unicode character *unichr* as
+   Returns the general category assigned to the character *chr* as
    string.
 
 
-.. function:: bidirectional(unichr)
+.. function:: bidirectional(chr)
 
-   Returns the bidirectional category assigned to the Unicode character *unichr* as
+   Returns the bidirectional category assigned to the character *chr* as
    string. If no such value is defined, an empty string is returned.
 
 
-.. function:: combining(unichr)
+.. function:: combining(chr)
 
-   Returns the canonical combining class assigned to the Unicode character *unichr*
+   Returns the canonical combining class assigned to the character *chr*
    as integer. Returns ``0`` if no combining class is defined.
 
 
-.. function:: east_asian_width(unichr)
+.. function:: east_asian_width(chr)
 
-   Returns the east asian width assigned to the Unicode character *unichr* as
+   Returns the east asian width assigned to the character *chr* as
    string.
 
 
-.. function:: mirrored(unichr)
+.. function:: mirrored(chr)
 
-   Returns the mirrored property assigned to the Unicode character *unichr* as
+   Returns the mirrored property assigned to the character *chr* as
    integer. Returns ``1`` if the character has been identified as a "mirrored"
    character in bidirectional text, ``0`` otherwise.
 
 
-.. function:: decomposition(unichr)
+.. function:: decomposition(chr)
 
-   Returns the character decomposition mapping assigned to the Unicode character
-   *unichr* as string. An empty string is returned in case no such mapping is
+   Returns the character decomposition mapping assigned to the character
+   *chr* as string. An empty string is returned in case no such mapping is
    defined.
 
 
@@ -142,20 +142,21 @@
    Unicode database version 3.2 instead, for applications that require this
    specific version of the Unicode database (such as IDNA).
 
-Examples::
+Examples:
 
+   >>> import unicodedata
    >>> unicodedata.lookup('LEFT CURLY BRACKET')
    u'{'
-   >>> unicodedata.name(u'/')
+   >>> unicodedata.name('/')
    'SOLIDUS'
-   >>> unicodedata.decimal(u'9')
+   >>> unicodedata.decimal('9')
    9
-   >>> unicodedata.decimal(u'a')
+   >>> unicodedata.decimal('a')
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: not a decimal
-   >>> unicodedata.category(u'A')  # 'L'etter, 'u'ppercase
+   >>> unicodedata.category('A')  # 'L'etter, 'u'ppercase
    'Lu'   
-   >>> unicodedata.bidirectional(u'\u0660') # 'A'rabic, 'N'umber
+   >>> unicodedata.bidirectional('\u0660') # 'A'rabic, 'N'umber
    'AN'
 

Modified: python/branches/py3k-importlib/Doc/library/unittest.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/unittest.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/unittest.rst	Thu Mar 27 00:48:05 2008
@@ -562,6 +562,7 @@
 
 .. method:: TestCase.assert_(expr[, msg])
             TestCase.failUnless(expr[, msg])
+            TestCase.assertTrue(expr[, msg])
 
    Signal a test failure if *expr* is false; the explanation for the error will be
    *msg* if given, otherwise it will be :const:`None`.
@@ -618,6 +619,7 @@
 
 
 .. method:: TestCase.failIf(expr[, msg])
+            TestCase.assertFalse(expr[, msg])
 
    The inverse of the :meth:`failUnless` method is the :meth:`failIf` method.  This
    signals a test failure if *expr* is true, with *msg* or :const:`None` for the
@@ -804,8 +806,9 @@
    Called when the test case *test* raises an unexpected exception *err* is a tuple
    of the form returned by :func:`sys.exc_info`: ``(type, value, traceback)``.
 
-   The default implementation appends ``(test, err)`` to the instance's ``errors``
-   attribute.
+   The default implementation appends a tuple ``(test, formatted_err)`` to the
+   instance's ``errors`` attribute, where *formatted_err* is a formatted
+   traceback derived from *err*.
 
 
 .. method:: TestResult.addFailure(test, err)
@@ -813,8 +816,9 @@
    Called when the test case *test* signals a failure. *err* is a tuple of the form
    returned by :func:`sys.exc_info`:  ``(type, value, traceback)``.
 
-   The default implementation appends ``(test, err)`` to the instance's
-   ``failures`` attribute.
+   The default implementation appends a tuple ``(test, formatted_err)`` to the
+   instance's ``failures`` attribute, where *formatted_err* is a formatted
+   traceback derived from *err*.
 
 
 .. method:: TestResult.addSuccess(test)

Modified: python/branches/py3k-importlib/Doc/library/urllib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/urllib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/urllib.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`urllib` --- Open arbitrary resources by URL
 =================================================
 
@@ -17,8 +16,8 @@
 instead of filenames.  Some restrictions apply --- it can only open URLs for
 reading, and no seek operations are available.
 
-It defines the following public functions:
-
+High-level interface
+--------------------
 
 .. function:: urlopen(url[, data[, proxies]])
 
@@ -28,16 +27,17 @@
    a server somewhere on the network.  If the connection cannot be made the
    :exc:`IOError` exception is raised.  If all went well, a file-like object is
    returned.  This supports the following methods: :meth:`read`, :meth:`readline`,
-   :meth:`readlines`, :meth:`fileno`, :meth:`close`, :meth:`info` and
-   :meth:`geturl`.  It also has proper support for the iterator protocol. One
+   :meth:`readlines`, :meth:`fileno`, :meth:`close`, :meth:`info`, :meth:`getcode` and
+   :meth:`geturl`.  It also has proper support for the :term:`iterator` protocol. One
    caveat: the :meth:`read` method, if the size argument is omitted or negative,
    may not read until the end of the data stream; there is no good way to determine
    that the entire stream from a socket has been read in the general case.
 
-   Except for the :meth:`info` and :meth:`geturl` methods, these methods have the
-   same interface as for file objects --- see section :ref:`bltin-file-objects` in
-   this manual.  (It is not a built-in file object, however, so it can't be used at
-   those few places where a true built-in file object is required.)
+   Except for the :meth:`info`, :meth:`getcode` and :meth:`geturl` methods,
+   these methods have the same interface as for file objects --- see section
+   :ref:`bltin-file-objects` in this manual.  (It is not a built-in file object,
+   however, so it can't be used at those few places where a true built-in file
+   object is required.)
 
    .. index:: module: mimetools
 
@@ -59,6 +59,9 @@
    the client was redirected to.  The :meth:`geturl` method can be used to get at
    this redirected URL.
 
+   The :meth:`getcode` method returns the HTTP status code that was sent with the
+   response, or ``None`` if the URL is no HTTP URL.
+
    If the *url* uses the :file:`http:` scheme identifier, the optional *data*
    argument may be given to specify a ``POST`` request (normally the request type
    is ``GET``).  The *data* argument must be in standard
@@ -76,6 +79,11 @@
       % python
       ...
 
+   The :envvar:`no_proxy` environment variable can be used to specify hosts which
+   shouldn't be reached via proxy; if set, it should be a comma-separated list
+   of hostname suffixes, optionally with ``:port`` appended, for example
+   ``cern.ch,ncsa.uiuc.edu,some.host:8080``.
+
    In a Windows environment, if no proxy environment variables are set, proxy
    settings are obtained from the registry's Internet Settings section.
 
@@ -99,10 +107,6 @@
       filehandle = urllib.urlopen(some_url, proxies=None)
       filehandle = urllib.urlopen(some_url)
 
-   The :func:`urlopen` function does not support explicit proxy specification.  If
-   you need to override environmental proxy settings, use :class:`URLopener`, or a
-   subclass such as :class:`FancyURLopener`.
-
    Proxies which require authentication for use are not currently supported; this
    is considered an implementation limitation.
 
@@ -174,6 +178,9 @@
    :func:`urlretrieve`.
 
 
+Utility functions
+-----------------
+
 .. function:: quote(string[, safe])
 
    Replace special characters in *string* using the ``%xx`` escape. Letters,
@@ -235,6 +242,9 @@
    to decode *path*.
 
 
+URL Opener objects
+------------------
+
 .. class:: URLopener([proxies[, **x509]])
 
    Base class for opening and reading URLs.  Unless you need to support opening
@@ -260,6 +270,48 @@
    :class:`URLopener` objects will raise an :exc:`IOError` exception if the server
    returns an error code.
 
+    .. method:: open(fullurl[, data])
+
+       Open *fullurl* using the appropriate protocol.  This method sets up cache and
+       proxy information, then calls the appropriate open method with its input
+       arguments.  If the scheme is not recognized, :meth:`open_unknown` is called.
+       The *data* argument has the same meaning as the *data* argument of
+       :func:`urlopen`.
+
+
+    .. method:: open_unknown(fullurl[, data])
+
+       Overridable interface to open unknown URL types.
+
+
+    .. method:: retrieve(url[, filename[, reporthook[, data]]])
+
+       Retrieves the contents of *url* and places it in *filename*.  The return value
+       is a tuple consisting of a local filename and either a
+       :class:`mimetools.Message` object containing the response headers (for remote
+       URLs) or ``None`` (for local URLs).  The caller must then open and read the
+       contents of *filename*.  If *filename* is not given and the URL refers to a
+       local file, the input filename is returned.  If the URL is non-local and
+       *filename* is not given, the filename is the output of :func:`tempfile.mktemp`
+       with a suffix that matches the suffix of the last path component of the input
+       URL.  If *reporthook* is given, it must be a function accepting three numeric
+       parameters.  It will be called after each chunk of data is read from the
+       network.  *reporthook* is ignored for local URLs.
+
+       If the *url* uses the :file:`http:` scheme identifier, the optional *data*
+       argument may be given to specify a ``POST`` request (normally the request type
+       is ``GET``).  The *data* argument must in standard
+       :mimetype:`application/x-www-form-urlencoded` format; see the :func:`urlencode`
+       function below.
+
+
+    .. attribute:: version
+
+       Variable that specifies the user agent of the opener object.  To get
+       :mod:`urllib` to tell servers that it is a particular user agent, set this in a
+       subclass as a class variable or in the constructor before calling the base
+       constructor.
+
 
 .. class:: FancyURLopener(...)
 
@@ -289,6 +341,18 @@
       users for the required information on the controlling terminal.  A subclass may
       override this method to support more appropriate behavior if needed.
 
+    The :class:`FancyURLopener` class offers one additional method that should be
+    overloaded to provide the appropriate behavior:
+
+    .. method:: prompt_user_passwd(host, realm)
+
+       Return information needed to authenticate the user at the given host in the
+       specified security realm.  The return value should be a tuple, ``(user,
+       password)``, which can be used for basic authentication.
+
+       The implementation prompts for this information on the terminal; an application
+       should override this method to use an appropriate interaction model in the local
+       environment.
 
 .. exception:: ContentTooShortError(msg[, content])
 
@@ -297,7 +361,9 @@
    *Content-Length* header). The :attr:`content` attribute stores the downloaded
    (and supposedly truncated) data.
 
-Restrictions:
+
+:mod:`urllib` Restrictions
+--------------------------
 
   .. index::
      pair: HTTP; protocol
@@ -358,75 +424,6 @@
   module :mod:`urlparse`.
 
 
-.. _urlopener-objs:
-
-URLopener Objects
------------------
-
-.. sectionauthor:: Skip Montanaro <skip at mojam.com>
-
-
-:class:`URLopener` and :class:`FancyURLopener` objects have the following
-attributes.
-
-
-.. method:: URLopener.open(fullurl[, data])
-
-   Open *fullurl* using the appropriate protocol.  This method sets up cache and
-   proxy information, then calls the appropriate open method with its input
-   arguments.  If the scheme is not recognized, :meth:`open_unknown` is called.
-   The *data* argument has the same meaning as the *data* argument of
-   :func:`urlopen`.
-
-
-.. method:: URLopener.open_unknown(fullurl[, data])
-
-   Overridable interface to open unknown URL types.
-
-
-.. method:: URLopener.retrieve(url[, filename[, reporthook[, data]]])
-
-   Retrieves the contents of *url* and places it in *filename*.  The return value
-   is a tuple consisting of a local filename and either a
-   :class:`mimetools.Message` object containing the response headers (for remote
-   URLs) or ``None`` (for local URLs).  The caller must then open and read the
-   contents of *filename*.  If *filename* is not given and the URL refers to a
-   local file, the input filename is returned.  If the URL is non-local and
-   *filename* is not given, the filename is the output of :func:`tempfile.mktemp`
-   with a suffix that matches the suffix of the last path component of the input
-   URL.  If *reporthook* is given, it must be a function accepting three numeric
-   parameters.  It will be called after each chunk of data is read from the
-   network.  *reporthook* is ignored for local URLs.
-
-   If the *url* uses the :file:`http:` scheme identifier, the optional *data*
-   argument may be given to specify a ``POST`` request (normally the request type
-   is ``GET``).  The *data* argument must in standard
-   :mimetype:`application/x-www-form-urlencoded` format; see the :func:`urlencode`
-   function below.
-
-
-.. attribute:: URLopener.version
-
-   Variable that specifies the user agent of the opener object.  To get
-   :mod:`urllib` to tell servers that it is a particular user agent, set this in a
-   subclass as a class variable or in the constructor before calling the base
-   constructor.
-
-The :class:`FancyURLopener` class offers one additional method that should be
-overloaded to provide the appropriate behavior:
-
-
-.. method:: FancyURLopener.prompt_user_passwd(host, realm)
-
-   Return information needed to authenticate the user at the given host in the
-   specified security realm.  The return value should be a tuple, ``(user,
-   password)``, which can be used for basic authentication.
-
-   The implementation prompts for this information on the terminal; an application
-   should override this method to use an appropriate interaction model in the local
-   environment.
-
-
 .. _urllib-examples:
 
 Examples

Modified: python/branches/py3k-importlib/Doc/library/urllib2.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/urllib2.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/urllib2.rst	Thu Mar 27 00:48:05 2008
@@ -33,10 +33,12 @@
 
    This function returns a file-like object with two additional methods:
 
-   * :meth:`geturl` --- return the URL of the resource retrieved
+   * :meth:`geturl` --- return the URL of the resource retrieved, commonly used to
+     determine if a redirect was followed
 
-   * :meth:`info` --- return the meta-information of the page, as a dictionary-like
-     object
+   * :meth:`info` --- return the meta-information of the page, such as headers, in
+     the form of an ``httplib.HTTPMessage`` instance
+     (see `Quick Reference to HTTP Headers <http://www.cs.tut.fi/~jkorpela/http.html>`_)
 
    Raises :exc:`URLError` on errors.
 
@@ -81,18 +83,32 @@
    The handlers raise this exception (or derived exceptions) when they run into a
    problem.  It is a subclass of :exc:`IOError`.
 
+   .. attribute:: reason
+
+      The reason for this error.  It can be a message string or another exception
+      instance (:exc:`socket.error` for remote URLs, :exc:`OSError` for local
+      URLs).
+
 
 .. exception:: HTTPError
 
-   A subclass of :exc:`URLError`, it can also function as a non-exceptional
-   file-like return value (the same thing that :func:`urlopen` returns).  This
-   is useful when handling exotic HTTP errors, such as requests for
-   authentication.
+   Though being an exception (a subclass of :exc:`URLError`), an :exc:`HTTPError`
+   can also function as a non-exceptional file-like return value (the same thing
+   that :func:`urlopen` returns).  This is useful when handling exotic HTTP
+   errors, such as requests for authentication.
+
+   .. attribute:: code
+
+      An HTTP status code as defined in `RFC 2616 <http://www.faqs.org/rfcs/rfc2616.html>`_. 
+      This numeric value corresponds to a value found in the dictionary of
+      codes as found in :attr:`BaseHTTPServer.BaseHTTPRequestHandler.responses`.
+
+
 
 The following classes are provided:
 
 
-.. class:: Request(url[, data][, headers] [, origin_req_host][, unverifiable])
+.. class:: Request(url[, data][, headers][, origin_req_host][, unverifiable])
 
    This class is an abstraction of a URL request.
 
@@ -107,7 +123,12 @@
    returns a string in this format.
 
    *headers* should be a dictionary, and will be treated as if :meth:`add_header`
-   was called with each key and value as arguments.
+   was called with each key and value as arguments.  This is often used to "spoof"
+   the ``User-Agent`` header, which is used by a browser to identify itself --
+   some HTTP servers only allow requests coming from common browsers as opposed
+   to scripts.  For example, Mozilla Firefox may identify itself as ``"Mozilla/5.0
+   (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11"``, while :mod:`urllib2`'s
+   default user agent string is ``"Python-urllib/2.6"`` (on Python 2.6).
 
    The final two arguments are only of interest for correct handling of third-party
    HTTP cookies:
@@ -158,6 +179,7 @@
    Cause requests to go through a proxy. If *proxies* is given, it must be a
    dictionary mapping protocol names to URLs of proxies. The default is to read the
    list of proxies from the environment variables :envvar:`<protocol>_proxy`.
+   To disable autodetected proxy pass an empty dictionary.
 
 
 .. class:: HTTPPasswordMgr()

Modified: python/branches/py3k-importlib/Doc/library/urlparse.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/urlparse.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/urlparse.rst	Thu Mar 27 00:48:05 2008
@@ -35,12 +35,13 @@
    smaller parts (for example, the network location is a single string), and %
    escapes are not expanded. The delimiters as shown above are not part of the
    result, except for a leading slash in the *path* component, which is retained if
-   present.  For example::
+   present.  For example:
 
       >>> from urlparse import urlparse
       >>> o = urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')
-      >>> o
-      ('http', 'www.cwi.nl:80', '/%7Eguido/Python.html', '', '', '')
+      >>> o   # doctest: +NORMALIZE_WHITESPACE
+      ParseResult(scheme='http', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html',
+                  params='', query='', fragment='')
       >>> o.scheme
       'http'
       >>> o.port
@@ -151,7 +152,7 @@
    Construct a full ("absolute") URL by combining a "base URL" (*base*) with
    another URL (*url*).  Informally, this uses components of the base URL, in
    particular the addressing scheme, the network location and (part of) the path,
-   to provide missing components in the relative URL.  For example::
+   to provide missing components in the relative URL.  For example:
 
       >>> from urlparse import urljoin
       >>> urljoin('http://www.cwi.nl/%7Eguido/Python.html', 'FAQ.html')
@@ -165,7 +166,7 @@
       If *url* is an absolute URL (that is, starting with ``//`` or ``scheme://``),
       the *url*'s host name and/or scheme will be present in the result.  For example:
 
-   ::
+   .. doctest::
 
       >>> urljoin('http://www.cwi.nl/%7Eguido/Python.html',
       ...         '//www.python.org/%7Eguido')
@@ -216,7 +217,7 @@
    and fragment identifiers will be removed.
 
    The result of this method is a fixpoint if passed back through the original
-   parsing function::
+   parsing function:
 
       >>> import urlparse
       >>> url = 'HTTP://www.Python.org/doc/#'

Deleted: /python/branches/py3k-importlib/Doc/library/userdict.rst
==============================================================================
--- /python/branches/py3k-importlib/Doc/library/userdict.rst	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,185 +0,0 @@
-
-:mod:`UserDict` --- Class wrapper for dictionary objects
-========================================================
-
-.. module:: UserDict
-   :synopsis: Class wrapper for dictionary objects.
-
-
-The module defines a mixin,  :class:`DictMixin`, defining all dictionary methods
-for classes that already have a minimum mapping interface.  This greatly
-simplifies writing classes that need to be substitutable for dictionaries (such
-as the shelve module).
-
-This also module defines a class, :class:`UserDict`, that acts as a wrapper
-around dictionary objects.  The need for this class has been largely supplanted
-by the ability to subclass directly from :class:`dict` (a feature that became
-available starting with Python version 2.2).  Prior to the introduction of
-:class:`dict`, the :class:`UserDict` class was used to create dictionary-like
-sub-classes that obtained new behaviors by overriding existing methods or adding
-new ones.
-
-The :mod:`UserDict` module defines the :class:`UserDict` class and
-:class:`DictMixin`:
-
-
-.. class:: UserDict([initialdata])
-
-   Class that simulates a dictionary.  The instance's contents are kept in a
-   regular dictionary, which is accessible via the :attr:`data` attribute of
-   :class:`UserDict` instances.  If *initialdata* is provided, :attr:`data` is
-   initialized with its contents; note that a reference to *initialdata* will not
-   be kept, allowing it be used for other purposes.
-
-   .. note::
-
-      For backward compatibility, instances of :class:`UserDict` are not
-      iterable.
-
-
-.. class:: IterableUserDict([initialdata])
-
-   Subclass of :class:`UserDict` that supports direct iteration (e.g.  ``for key in
-   myDict``).
-
-In addition to supporting the methods and operations of mappings (see section
-:ref:`typesmapping`), :class:`UserDict` and :class:`IterableUserDict` instances
-provide the following attribute:
-
-
-.. attribute:: IterableUserDict.data
-
-   A real dictionary used to store the contents of the :class:`UserDict` class.
-
-
-.. class:: DictMixin()
-
-   Mixin defining all dictionary methods for classes that already have a minimum
-   dictionary interface including :meth:`__getitem__`, :meth:`__setitem__`,
-   :meth:`__delitem__`, and :meth:`keys`.
-
-   This mixin should be used as a superclass.  Adding each of the above methods
-   adds progressively more functionality.  For instance, defining all but
-   :meth:`__delitem__` will preclude only :meth:`pop` and :meth:`popitem` from the
-   full interface.
-
-   In addition to the four base methods, progressively more efficiency comes
-   with defining :meth:`__contains__` and :meth:`__iter__`.
-
-   Since the mixin has no knowledge of the subclass constructor, it does not define
-   :meth:`__init__` or :meth:`copy`.
-
-
-:mod:`UserList` --- Class wrapper for list objects
-==================================================
-
-.. module:: UserList
-   :synopsis: Class wrapper for list objects.
-
-
-.. note::
-
-   This module is available for backward compatibility only.  If you are writing
-   code that does not need to work with versions of Python earlier than Python 2.2,
-   please consider subclassing directly from the built-in :class:`list` type.
-
-This module defines a class that acts as a wrapper around list objects.  It is a
-useful base class for your own list-like classes, which can inherit from them
-and override existing methods or add new ones.  In this way one can add new
-behaviors to lists.
-
-The :mod:`UserList` module defines the :class:`UserList` class:
-
-
-.. class:: UserList([list])
-
-   Class that simulates a list.  The instance's contents are kept in a regular
-   list, which is accessible via the :attr:`data` attribute of
-   :class:`UserList`
-   instances.  The instance's contents are initially set to a copy of *list*,
-   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 (see
-section :ref:`typesseq`), :class:`UserList` instances provide the following
-attribute:
-
-
-.. attribute:: UserList.data
-
-   A real Python 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
-argument.  List operations which return a new sequence attempt to create an
-instance of the actual implementation class.  To do so, it assumes that the
-constructor can be called with a single parameter, which is a sequence object
-used as a data source.
-
-If a derived class does not wish to comply with this requirement, all of the
-special methods supported by this class will need to be overridden; please
-consult the sources for information about the methods which need to be provided
-in that case.
-
-
-:mod:`UserString` --- Class wrapper for string objects
-======================================================
-
-.. module:: UserString
-   :synopsis: Class wrapper for string objects.
-.. moduleauthor:: Peter Funk <pf at artcom-gmbh.de>
-.. sectionauthor:: Peter Funk <pf at artcom-gmbh.de>
-
-
-.. note::
-
-   This :class:`UserString` class from this module is available for backward
-   compatibility only.  If you are writing code that does not need to work with
-   versions of Python earlier than Python 2.2, please consider subclassing directly
-   from the built-in :class:`str` type instead of using :class:`UserString` (there
-   is no built-in equivalent to :class:`MutableString`).
-
-This module defines a class that acts as a wrapper around string objects.  It is
-a useful base class for your own string-like classes, which can inherit from
-them and override existing methods or add new ones.  In this way one can add new
-behaviors to strings.
-
-It should be noted that these classes are highly inefficient compared to real
-string or Unicode objects; this is especially the case for
-:class:`MutableString`.
-
-The :mod:`UserString` module defines the following classes:
-
-
-.. class:: UserString([sequence])
-
-   Class that simulates a string or a Unicode string object.  The instance's
-   content is kept in a regular string or Unicode string object, which is
-   accessible via the :attr:`data` attribute of :class:`UserString` instances.  The
-   instance's contents are initially set to a copy of *sequence*.  *sequence* can
-   be either a regular Python string or Unicode string, an instance of
-   :class:`UserString` (or a subclass) or an arbitrary sequence which can be
-   converted into a string using the built-in :func:`str` function.
-
-
-.. class:: MutableString([sequence])
-
-   This class is derived from the :class:`UserString` above and redefines strings
-   to be *mutable*.  Mutable strings can't be used as dictionary keys, because
-   dictionaries require *immutable* objects as keys.  The main intention of this
-   class is to serve as an educational example for inheritance and necessity to
-   remove (override) the :meth:`__hash__` method in order to trap attempts to use a
-   mutable object as dictionary key, which would be otherwise very error prone and
-   hard to track down.
-
-In addition to supporting the methods and operations of string and Unicode
-objects (see section :ref:`string-methods`), :class:`UserString` instances
-provide the following attribute:
-
-
-.. attribute:: MutableString.data
-
-   A real Python string or Unicode object used to store the content of the
-   :class:`UserString` class.
-

Modified: python/branches/py3k-importlib/Doc/library/warnings.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/warnings.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/warnings.rst	Thu Mar 27 00:48:05 2008
@@ -80,6 +80,10 @@
 | :exc:`UnicodeWarning`            | Base category for warnings related to         |
 |                                  | Unicode.                                      |
 +----------------------------------+-----------------------------------------------+
+| :exc:`BytesWarning`              | Base category for warnings related to         |
+|                                  | :class:`bytes` and :class:`buffer`.           |
++----------------------------------+-----------------------------------------------+
+
 
 While these are technically built-in exceptions, they are documented here,
 because conceptually they belong to the warnings mechanism.
@@ -194,8 +198,8 @@
 
    *module_globals*, if supplied, should be the global namespace in use by the code
    for which the warning is issued.  (This argument is used to support displaying
-   source for modules found in zipfiles or other non-filesystem import sources, and
-   was added in Python 2.5.)
+   source for modules found in zipfiles or other non-filesystem import
+   sources).
 
 
 .. function:: showwarning(message, category, filename, lineno[, file])

Modified: python/branches/py3k-importlib/Doc/library/wave.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/wave.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/wave.rst	Thu Mar 27 00:48:05 2008
@@ -1,13 +1,10 @@
-.. % Documentations stolen and LaTeX'ed from comments in file.
-
-
 :mod:`wave` --- Read and write WAV files
 ========================================
 
 .. module:: wave
    :synopsis: Provide an interface to the WAV sound format.
 .. sectionauthor:: Moshe Zadka <moshez at zadka.site.co.il>
-
+.. Documentations stolen from comments in file.
 
 The :mod:`wave` module provides a convenient interface to the WAV sound format.
 It does not support compression/decompression, but it does support mono/stereo.

Modified: python/branches/py3k-importlib/Doc/library/weakref.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/weakref.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/weakref.rst	Thu Mar 27 00:48:05 2008
@@ -13,42 +13,53 @@
 The :mod:`weakref` module allows the Python programmer to create :dfn:`weak
 references` to objects.
 
-.. % When making changes to the examples in this file, be sure to update
-.. % Lib/test/test_weakref.py::libreftest too!
+.. When making changes to the examples in this file, be sure to update
+   Lib/test/test_weakref.py::libreftest too!
 
 In the following, the term :dfn:`referent` means the object which is referred to
 by a weak reference.
 
 A weak reference to an object is not enough to keep the object alive: when the
-only remaining references to a referent are weak references, garbage collection
-is free to destroy the referent and reuse its memory for something else.  A
-primary use for weak references is to implement caches or mappings holding large
-objects, where it's desired that a large object not be kept alive solely because
-it appears in a cache or mapping.  For example, if you have a number of large
-binary image objects, you may wish to associate a name with each.  If you used a
-Python dictionary to map names to images, or images to names, the image objects
-would remain alive just because they appeared as values or keys in the
-dictionaries.  The :class:`WeakKeyDictionary` and :class:`WeakValueDictionary`
-classes supplied by the :mod:`weakref` module are an alternative, using weak
-references to construct mappings that don't keep objects alive solely because
-they appear in the mapping objects.  If, for example, an image object is a value
-in a :class:`WeakValueDictionary`, then when the last remaining references to
-that image object are the weak references held by weak mappings, garbage
-collection can reclaim the object, and its corresponding entries in weak
-mappings are simply deleted.
+only remaining references to a referent are weak references,
+:term:`garbage collection` is free to destroy the referent and reuse its memory
+for something else.  A primary use for weak references is to implement caches or
+mappings holding large objects, where it's desired that a large object not be
+kept alive solely because it appears in a cache or mapping.
+
+For example, if you have a number of large binary image objects, you may wish to
+associate a name with each.  If you used a Python dictionary to map names to
+images, or images to names, the image objects would remain alive just because
+they appeared as values or keys in the dictionaries.  The
+:class:`WeakKeyDictionary` and :class:`WeakValueDictionary` classes supplied by
+the :mod:`weakref` module are an alternative, using weak references to construct
+mappings that don't keep objects alive solely because they appear in the mapping
+objects.  If, for example, an image object is a value in a
+:class:`WeakValueDictionary`, then when the last remaining references to that
+image object are the weak references held by weak mappings, garbage collection
+can reclaim the object, and its corresponding entries in weak mappings are
+simply deleted.
 
 :class:`WeakKeyDictionary` and :class:`WeakValueDictionary` use weak references
 in their implementation, setting up callback functions on the weak references
 that notify the weak dictionaries when a key or value has been reclaimed by
-garbage collection.  Most programs should find that using one of these weak
-dictionary types is all they need -- it's not usually necessary to create your
-own weak references directly.  The low-level machinery used by the weak
-dictionary implementations is exposed by the :mod:`weakref` module for the
-benefit of advanced uses.
+garbage collection.  :class:`WeakSet` implements the :class:`set` interface,
+but keeps weak references to its elements, just like a
+:class:`WeakKeyDictionary` does.
+
+Most programs should find that using one of these weak container types is all
+they need -- it's not usually necessary to create your own weak references
+directly.  The low-level machinery used by the weak dictionary implementations
+is exposed by the :mod:`weakref` module for the benefit of advanced uses.
+
+.. note::
+
+   Weak references to an object are cleared before the object's :meth:`__del__`
+   is called, to ensure that the weak reference callback (if any) finds the
+   object still alive.
 
 Not all objects can be weakly referenced; those objects which can include class
-instances, functions written in Python (but not in C), methods (both bound and
-unbound), sets, frozensets, file objects, generators, type objects, DBcursor
+instances, functions written in Python (but not in C), instance methods, sets,
+frozensets, file objects, :term:`generator`\s, type objects, :class:`DBcursor`
 objects from the :mod:`bsddb` module, sockets, arrays, deques, and regular
 expression pattern objects.
 
@@ -58,7 +69,7 @@
    class Dict(dict):
        pass
 
-   obj = Dict(red=1, green=2, blue=3)   # this object is weak referencable
+   obj = Dict(red=1, green=2, blue=3)   # this object is weak referenceable
 
 Extension types can easily be made to support weak references; see
 :ref:`weakref-support`.
@@ -82,7 +93,7 @@
    but cannot be propagated; they are handled in exactly the same way as exceptions
    raised from an object's :meth:`__del__` method.
 
-   Weak references are hashable if the *object* is hashable.  They will maintain
+   Weak references are :term:`hashable` if the *object* is hashable.  They will maintain
    their hash value even after the *object* was deleted.  If :func:`hash` is called
    the first time only after the *object* was deleted, the call will raise
    :exc:`TypeError`.
@@ -101,7 +112,7 @@
    the proxy in most contexts instead of requiring the explicit dereferencing used
    with weak reference objects.  The returned object will have a type of either
    ``ProxyType`` or ``CallableProxyType``, depending on whether *object* is
-   callable.  Proxy objects are not hashable regardless of the referent; this
+   callable.  Proxy objects are not :term:`hashable` regardless of the referent; this
    avoids a number of problems related to their fundamentally mutable nature, and
    prevent their use as dictionary keys.  *callback* is the same as the parameter
    of the same name to the :func:`ref` function.
@@ -127,11 +138,11 @@
 
    .. note::
 
-      Caution:  Because a :class:`WeakKeyDictionary` is built on top of a Python
+      Caution: Because a :class:`WeakKeyDictionary` is built on top of a Python
       dictionary, it must not change size when iterating over it.  This can be
-      difficult to ensure for a :class:`WeakKeyDictionary` because actions performed
-      by the program during iteration may cause items in the dictionary to vanish "by
-      magic" (as a side effect of garbage collection).
+      difficult to ensure for a :class:`WeakKeyDictionary` because actions
+      performed by the program during iteration may cause items in the
+      dictionary to vanish "by magic" (as a side effect of garbage collection).
 
 :class:`WeakKeyDictionary` objects have the following additional methods.  These
 expose the internal references directly.  The references are not guaranteed to
@@ -143,7 +154,7 @@
 
 .. method:: WeakKeyDictionary.iterkeyrefs()
 
-   Return an iterator that yields the weak references to the keys.
+   Return an :term:`iterator` that yields the weak references to the keys.
 
 
 .. method:: WeakKeyDictionary.keyrefs()
@@ -171,7 +182,7 @@
 
 .. method:: WeakValueDictionary.itervaluerefs()
 
-   Return an iterator that yields the weak references to the values.
+   Return an :term:`iterator` that yields the weak references to the values.
 
 
 .. method:: WeakValueDictionary.valuerefs()
@@ -179,6 +190,12 @@
    Return a list of weak references to the values.
 
 
+.. class:: WeakSet([elements])
+
+   Set class that keeps weak references to its elements.  An element will be
+   discarded when no strong reference to it exists any more.
+
+
 .. data:: ReferenceType
 
    The type object for weak references objects.
@@ -220,7 +237,7 @@
 ----------------------
 
 Weak reference objects have no attributes or methods, but do allow the referent
-to be obtained, if it still exists, by calling it::
+to be obtained, if it still exists, by calling it:
 
    >>> import weakref
    >>> class Object:
@@ -233,7 +250,7 @@
    True
 
 If the referent no longer exists, calling the reference object returns
-:const:`None`::
+:const:`None`:
 
    >>> del o, o2
    >>> print(r())
@@ -297,7 +314,7 @@
 other data structures without forcing the objects to remain alive, but the
 objects can still be retrieved by ID if they do.
 
-.. % Example contributed by Tim Peters.
+.. Example contributed by Tim Peters.
 
 ::
 

Modified: python/branches/py3k-importlib/Doc/library/windows.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/windows.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/windows.rst	Thu Mar 27 00:48:05 2008
@@ -1,3 +1,4 @@
+.. _mswin-specific-services:
 
 ****************************
 MS Windows Specific Services

Modified: python/branches/py3k-importlib/Doc/library/winsound.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/winsound.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/winsound.rst	Thu Mar 27 00:48:05 2008
@@ -32,7 +32,7 @@
 
    Call the underlying :cfunc:`PlaySound` function from the Platform API.  The
    *sound* parameter may be a filename, audio data as a string, or ``None``.  Its
-   interpretation depends on the value of *flags*, which can be a bit-wise ORed
+   interpretation depends on the value of *flags*, which can be a bitwise ORed
    combination of the constants described below.  If the system indicates an error,
    :exc:`RuntimeError` is raised.
 

Modified: python/branches/py3k-importlib/Doc/library/wsgiref.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/wsgiref.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/wsgiref.rst	Thu Mar 27 00:48:05 2008
@@ -27,7 +27,7 @@
 See http://www.wsgi.org for more information about WSGI, and links to tutorials
 and other resources.
 
-.. % XXX If you're just trying to write a web application...
+.. XXX If you're just trying to write a web application...
 
 
 :mod:`wsgiref.util` -- WSGI environment utilities
@@ -112,6 +112,30 @@
    applications to set up dummy environments.  It should NOT be used by actual WSGI
    servers or applications, since the data is fake!
 
+   Example usage::
+
+      from wsgiref.util import setup_testing_defaults
+      from wsgiref.simple_server import make_server
+
+      # A relatively simple WSGI application. It's going to print out the
+      # environment dictionary after being updated by setup_testing_defaults
+      def simple_app(environ, start_response):
+          setup_testing_defaults(environ)
+
+          status = '200 OK'
+          headers = [('Content-type', 'text/plain')]
+
+          start_response(status, headers)
+
+          ret = ["%s: %s\n" % (key, value)
+                 for key, value in environ.iteritems()]
+          return ret
+
+      httpd = make_server('', 8000, simple_app)
+      print "Serving on port 8000..."
+      httpd.serve_forever()
+
+
 In addition to the environment functions above, the :mod:`wsgiref.util` module
 also provides these miscellaneous utilities:
 
@@ -124,7 +148,7 @@
 
 .. class:: FileWrapper(filelike [, blksize=8192])
 
-   A wrapper to convert a file-like object to an iterator.  The resulting objects
+   A wrapper to convert a file-like object to an :term:`iterator`.  The resulting objects
    support both :meth:`__getitem__` and :meth:`__iter__` iteration styles, for
    compatibility with Python 2.1 and Jython. As the object is iterated over, the
    optional *blksize* parameter will be repeatedly passed to the *filelike*
@@ -135,6 +159,19 @@
    :meth:`close` method, and it will invoke the *filelike* object's :meth:`close`
    method when called.
 
+   Example usage::
+
+      from StringIO import StringIO
+      from wsgiref.util import FileWrapper
+
+      # We're using a StringIO-buffer for as the file-like object
+      filelike = StringIO("This is an example file-like object"*10)
+      wrapper = FileWrapper(filelike, blksize=5)
+
+      for chunk in wrapper: 
+          print(chunk)
+
+
 
 :mod:`wsgiref.headers` -- WSGI response header tools
 ----------------------------------------------------
@@ -250,7 +287,7 @@
       httpd.serve_forever()
 
       # Alternative: serve one request, then exit
-      ##httpd.handle_request()
+      httpd.handle_request()
 
 
 .. function:: demo_app(environ, start_response)
@@ -371,6 +408,29 @@
    ``sys.stderr`` (*not* ``wsgi.errors``, unless they happen to be the same
    object).
 
+   Example usage::
+
+      from wsgiref.validate import validator
+      from wsgiref.simple_server import make_server
+
+      # Our callable object which is intentionally not compilant to the 
+      # standard, so the validator is going to break
+      def simple_app(environ, start_response):
+          status = '200 OK' # HTTP Status
+          headers = [('Content-type', 'text/plain')] # HTTP Headers
+          start_response(status, headers)
+
+          # This is going to break because we need to return a list, and
+          # the validator is going to inform us
+          return "Hello World"
+
+      # This is the application wrapped in a validator
+      validator_app = validator(simple_app)
+
+      httpd = make_server('', 8000, validator_app)
+      print("Listening on port 8000....")
+      httpd.serve_forever()
+
 
 :mod:`wsgiref.handlers` -- server/gateway base classes
 ------------------------------------------------------
@@ -637,3 +697,30 @@
       If :attr:`origin_server` is true, this string attribute is used to set the HTTP
       version of the response set to the client.  It defaults to ``"1.0"``.
 
+
+Examples
+--------
+
+This is a working "Hello World" WSGI application::
+
+   from wsgiref.simple_server import make_server
+
+   # Every WSGI application must have an application object - a callable
+   # object that accepts two arguments. For that purpose, we're going to
+   # use a function (note that you're not limited to a function, you can
+   # use a class for example). The first argument passed to the function
+   # is a dictionary containing CGI-style envrironment variables and the
+   # second variable is the callable object (see PEP333)
+   def hello_world_app(environ, start_response):
+       status = '200 OK' # HTTP Status
+       headers = [('Content-type', 'text/plain')] # HTTP Headers
+       start_response(status, headers)
+
+       # The returned object is going to be printed
+       return ["Hello World"]
+
+   httpd = make_server('', 8000, hello_world_app)
+   print("Serving on port 8000...")
+
+   # Serve until process is killed
+   httpd.serve_forever()

Modified: python/branches/py3k-importlib/Doc/library/xml.dom.minidom.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/xml.dom.minidom.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/xml.dom.minidom.rst	Thu Mar 27 00:48:05 2008
@@ -147,7 +147,7 @@
    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* argument, the result is a byte string in the
+   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".
@@ -201,22 +201,22 @@
 
 * Operations are used as methods. Since the DOM uses only :keyword:`in`
   parameters, the arguments are passed in normal order (from left to right).
-  There are no optional arguments. :keyword:`void` operations return ``None``.
+  There are no optional arguments. ``void`` operations return ``None``.
 
 * IDL attributes map to instance attributes. For compatibility with the OMG IDL
   language mapping for Python, an attribute ``foo`` can also be accessed through
-  accessor methods :meth:`_get_foo` and :meth:`_set_foo`.  :keyword:`readonly`
+  accessor methods :meth:`_get_foo` and :meth:`_set_foo`.  ``readonly``
   attributes must not be changed; this is not enforced at runtime.
 
 * The types ``short int``, ``unsigned int``, ``unsigned long long``, and
   ``boolean`` all map to Python integer objects.
 
 * The type ``DOMString`` maps to Python strings. :mod:`xml.dom.minidom` supports
-  either byte or Unicode strings, but will normally produce Unicode strings.
+  either bytes or strings, but will normally produce strings.
   Values of type ``DOMString`` may also be ``None`` where allowed to have the IDL
   ``null`` value by the DOM specification from the W3C.
 
-* :keyword:`const` declarations map to variables in their respective scope (e.g.
+* ``const`` declarations map to variables in their respective scope (e.g.
   ``xml.dom.minidom.Node.PROCESSING_INSTRUCTION_NODE``); they must not be changed.
 
 * ``DOMException`` is currently not supported in :mod:`xml.dom.minidom`.
@@ -252,3 +252,9 @@
 Most of these reflect information in the XML document that is not of general
 utility to most DOM users.
 
+.. 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
+   and http://www.iana.org/assignments/character-sets .

Modified: python/branches/py3k-importlib/Doc/library/xml.dom.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/xml.dom.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/xml.dom.rst	Thu Mar 27 00:48:05 2008
@@ -29,19 +29,22 @@
 
 The Document Object Model is being defined by the W3C in stages, or "levels" in
 their terminology.  The Python mapping of the API is substantially based on the
-DOM Level 2 recommendation.  The mapping of the Level 3 specification, currently
-only available in draft form, is being developed by the `Python XML Special
-Interest Group <http://www.python.org/sigs/xml-sig/>`_ as part of the `PyXML
-package <http://pyxml.sourceforge.net/>`_.  Refer to the documentation bundled
-with that package for information on the current state of DOM Level 3 support.
-
-.. % What if your needs are somewhere between SAX and the DOM?  Perhaps
-.. % you cannot afford to load the entire tree in memory but you find the
-.. % SAX model somewhat cumbersome and low-level.  There is also a module
-.. % called xml.dom.pulldom that allows you to build trees of only the
-.. % parts of a document that you need structured access to.  It also has
-.. % features that allow you to find your way around the DOM.
-.. % See http://www.prescod.net/python/pulldom
+DOM Level 2 recommendation.
+
+.. XXX PyXML is dead...
+.. The mapping of the Level 3 specification, currently
+   only available in draft form, is being developed by the `Python XML Special
+   Interest Group <http://www.python.org/sigs/xml-sig/>`_ as part of the `PyXML
+   package <http://pyxml.sourceforge.net/>`_.  Refer to the documentation bundled
+   with that package for information on the current state of DOM Level 3 support.
+
+.. What if your needs are somewhere between SAX and the DOM?  Perhaps
+   you cannot afford to load the entire tree in memory but you find the
+   SAX model somewhat cumbersome and low-level.  There is also a module
+   called xml.dom.pulldom that allows you to build trees of only the
+   parts of a document that you need structured access to.  It also has
+   features that allow you to find your way around the DOM.
+   See http://www.prescod.net/python/pulldom
 
 DOM applications typically start by parsing some XML into a DOM.  How this is
 accomplished is not covered at all by DOM Level 1, and Level 2 provides only
@@ -74,10 +77,6 @@
    `Document Object Model (DOM) Level 1 Specification <http://www.w3.org/TR/REC-DOM-Level-1/>`_
       The W3C recommendation for the DOM supported by :mod:`xml.dom.minidom`.
 
-   `PyXML <http://pyxml.sourceforge.net>`_
-      Users that require a full-featured implementation of DOM should use the PyXML
-      package.
-
    `Python Language Mapping Specification <http://www.omg.org/docs/formal/02-11-05.pdf>`_
       This specifies the mapping from OMG IDL to Python.
 
@@ -149,7 +148,7 @@
 within the class rather than at the module level to conform with the DOM
 specifications.
 
-.. % Should the Node documentation go here?
+.. Should the Node documentation go here?
 
 
 .. _dom-objects:
@@ -364,8 +363,9 @@
 
 .. method:: Node.appendChild(newChild)
 
-   Add a new child node to this node at the end of the list of children, returning
-   *newChild*.
+   Add a new child node to this node at the end of the list of
+   children, returning *newChild*. If the node was already in
+   in the tree, it is removed first.
 
 
 .. method:: Node.insertBefore(newChild, refChild)
@@ -506,7 +506,7 @@
 ^^^^^^^^^^^^^^^^
 
 A :class:`Document` represents an entire XML document, including its constituent
-elements, attributes, processing instructions, comments etc.  Remeber that it
+elements, attributes, processing instructions, comments etc.  Remember that it
 inherits properties from :class:`Node`.
 
 
@@ -641,8 +641,8 @@
 
 .. method:: Element.removeAttribute(name)
 
-   Remove an attribute by name.  No exception is raised if there is no matching
-   attribute.
+   Remove an attribute by name.  If there is no matching attribute, a
+   :exc:`NotFoundErr` is raised.
 
 
 .. method:: Element.removeAttributeNode(oldAttr)
@@ -893,7 +893,7 @@
 
    This is raised if data is specified for a node which does not support data.
 
-   .. % XXX  a better explanation is needed!
+   .. XXX  a better explanation is needed!
 
 
 .. exception:: NoModificationAllowedErr
@@ -906,7 +906,7 @@
 
    Raised when an invalid or illegal string is specified.
 
-   .. % XXX  how is this different from InvalidCharacterErr ???
+   .. XXX  how is this different from InvalidCharacterErr?
 
 
 .. exception:: WrongDocumentErr
@@ -985,11 +985,11 @@
 +------------------+-------------------------------------------+
 
 Additionally, the :class:`DOMString` defined in the recommendation is mapped to
-a Python string or Unicode string.  Applications should be able to handle
+a bytes or string object.  Applications should be able to handle
 Unicode whenever a string is returned from the DOM.
 
-The IDL :keyword:`null` value is mapped to ``None``, which may be accepted or
-provided by the implementation whenever :keyword:`null` is allowed by the API.
+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:
@@ -998,7 +998,7 @@
 ^^^^^^^^^^^^^^^^
 
 The mapping from OMG IDL to Python defines accessor functions for IDL
-:keyword:`attribute` declarations in much the way the Java mapping does.
+``attribute`` declarations in much the way the Java mapping does.
 Mapping the IDL declarations ::
 
    readonly attribute string someValue;
@@ -1017,13 +1017,13 @@
 objects are accessed via CORBA. While this does require some additional
 consideration for CORBA DOM clients, the implementers with experience using DOM
 over CORBA from Python do not consider this a problem.  Attributes that are
-declared :keyword:`readonly` may not restrict write access in all DOM
+declared ``readonly`` may not restrict write access in all DOM
 implementations.
 
 In the Python DOM API, accessor functions are not required.  If provided, they
 should take the form defined by the Python IDL mapping, but these methods are
 considered unnecessary since the attributes are accessible directly from Python.
-"Set" accessors should never be provided for :keyword:`readonly` attributes.
+"Set" accessors should never be provided for ``readonly`` attributes.
 
 The IDL definitions do not fully embody the requirements of the W3C DOM API,
 such as the notion of certain objects, such as the return value of

Modified: python/branches/py3k-importlib/Doc/library/xml.etree.elementtree.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/xml.etree.elementtree.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/xml.etree.elementtree.rst	Thu Mar 27 00:48:05 2008
@@ -31,6 +31,9 @@
 
 A C implementation of this API is available as :mod:`xml.etree.cElementTree`.
 
+See http://effbot.org/zone/element-index.htm for tutorials and links to other
+docs. Fredrik Lundh's page is also the location of the development version of the 
+xml.etree.ElementTree.
 
 .. _elementtree-functions:
 
@@ -40,10 +43,11 @@
 
 .. function:: Comment([text])
 
-   Comment element factory.  This factory function creates a special element that
-   will be serialized as an XML comment. The comment string can be either an 8-bit
-   ASCII string or a Unicode string. *text* is a string containing the comment
-   string. Returns an element instance representing a comment.
+   Comment element factory.  This factory function creates a special element
+   that will be serialized as an XML comment. The comment string can be either
+   an ASCII-only :class:`bytes` object or a :class:`str` object. *text* is a
+   string containing the comment string. Returns an element instance
+   representing a comment.
 
 
 .. function:: dump(elem)
@@ -64,10 +68,11 @@
    dependent, but it will always be compatible with the _ElementInterface class in
    this module.
 
-   The element name, attribute names, and attribute values can be either 8-bit
-   ASCII strings or Unicode strings. *tag* is the element name. *attrib* is an
-   optional dictionary, containing element attributes. *extra* contains additional
-   attributes, given as keyword arguments. Returns an element instance.
+   The element name, attribute names, and attribute values can be either an
+   ASCII-only :class:`bytes` object or a :class:`str` object. *tag* is the
+   element name. *attrib* is an optional dictionary, containing element
+   attributes. *extra* contains additional attributes, given as keyword
+   arguments. Returns an element instance.
 
 
 .. function:: fromstring(text)
@@ -87,7 +92,7 @@
    Parses an XML section into an element tree incrementally, and reports what's
    going on to the user. *source* is a filename or file object containing XML data.
    *events* is a list of events to report back.  If omitted, only "end" events are
-   reported. Returns an iterator providing ``(event, elem)`` pairs.
+   reported. Returns an :term:`iterator` providing ``(event, elem)`` pairs.
 
 
 .. function:: parse(source[, parser])
@@ -111,11 +116,11 @@
    Subelement factory.  This function creates an element instance, and appends it
    to an existing element.
 
-   The element name, attribute names, and attribute values can be either 8-bit
-   ASCII strings or Unicode strings. *parent* is the parent element. *tag* is the
-   subelement name. *attrib* is an optional dictionary, containing element
-   attributes. *extra* contains additional attributes, given as keyword arguments.
-   Returns an element instance.
+   The element name, attribute names, and attribute values can be an ASCII-only
+   :class:`bytes` object or a :class:`str` object. *parent* is the parent
+   element. *tag* is the subelement name. *attrib* is an optional dictionary,
+   containing element attributes. *extra* contains additional attributes, given
+   as keyword arguments. Returns an element instance.
 
 
 .. function:: tostring(element[, encoding])
@@ -272,7 +277,7 @@
 with subelements: :meth:`__delitem__`, :meth:`__getitem__`, :meth:`__setitem__`,
 :meth:`__len__`.
 
-Caution: Because Element objects do not define a :meth:`__nonzero__` method,
+Caution: Because Element objects do not define a :meth:`__bool__` method,
 elements with no subelements will test as ``False``. ::
 
    element = root.find('foo')
@@ -316,7 +321,7 @@
 .. method:: ElementTree.findall(path)
 
    Finds all toplevel elements with the given tag. Same as getroot().findall(path).
-   *path* is the element to look for. Returns a list or iterator containing all
+   *path* is the element to look for. Returns a list or :term:`iterator` containing all
    matching elements, in document order.
 
 
@@ -352,9 +357,36 @@
 .. method:: ElementTree.write(file[, encoding])
 
    Writes the element tree to a file, as XML. *file* is a file name, or a file
-   object opened for writing. *encoding* is the output encoding (default is
+   object opened for writing. *encoding* [1]_ is the output encoding (default is
    US-ASCII).
 
+This is the XML file that is going to be manipulated::
+
+    <html>
+        <head>
+            <title>Example page</title>
+        </head>
+        <body>
+            <p>Moved to <a href="http://example.org/">example.org</a> 
+            or <a href="http://example.com/">example.com</a>.</p>
+        </body>
+    </html>
+
+Example of changing the attribute "target" of every link in first paragraph::
+
+    >>> from xml.etree.ElementTree import ElementTree
+    >>> tree = ElementTree()
+    >>> tree.parse("index.xhtml")
+    <Element html at b7d3f1ec>
+    >>> p = tree.find("body/p")     # Finds first occurrence of tag p in body
+    >>> p
+    <Element p at 8416e0c>
+    >>> links = p.getiterator("a")  # Returns list of all links
+    >>> links
+    [<Element a at b7d4f9ec>, <Element a at b7d4fb0c>]
+    >>> for i in links:             # Iterates through all found links
+    ...     i.attrib["target"] = "blank"
+    >>> tree.write("output.xhtml")
 
 .. _elementtree-qname-objects:
 
@@ -389,14 +421,14 @@
 
 .. method:: TreeBuilder.close()
 
-   Flushes the parser buffers, and returns the toplevel documen element. Returns an
+   Flushes the parser buffers, and returns the toplevel document element. Returns an
    Element instance.
 
 
 .. method:: TreeBuilder.data(data)
 
    Adds text to the current element. *data* is a string.  This should be either an
-   8-bit string containing ASCII text, or a Unicode string.
+   ASCII-only :class:`bytes` object or a :class:`str` object.
 
 
 .. method:: TreeBuilder.end(tag)
@@ -440,3 +472,50 @@
 
    Feeds data to the parser. *data* is encoded data.
 
+:meth:`XMLTreeBuilder.feed` calls *target*\'s :meth:`start` method
+for each opening tag, its :meth:`end` method for each closing tag,
+and data is processed by method :meth:`data`. :meth:`XMLTreeBuilder.close` 
+calls *target*\'s method :meth:`close`. 
+:class:`XMLTreeBuilder` can be used not only for building a tree structure. 
+This is an example of counting the maximum depth of an XML file::
+
+    >>> from xml.etree.ElementTree import XMLTreeBuilder
+    >>> class MaxDepth:                     # The target object of the parser
+    ...     maxDepth = 0
+    ...     depth = 0
+    ...     def start(self, tag, attrib):   # Called for each opening tag.
+    ...         self.depth += 1 
+    ...         if self.depth > self.maxDepth:
+    ...             self.maxDepth = self.depth
+    ...     def end(self, tag):             # Called for each closing tag.
+    ...         self.depth -= 1
+    ...     def data(self, data):   
+    ...         pass            # We do not need to do anything with data.
+    ...     def close(self):    # Called when all data has been parsed.
+    ...         return self.maxDepth
+    ... 
+    >>> target = MaxDepth()
+    >>> parser = XMLTreeBuilder(target=target)
+    >>> exampleXml = """
+    ... <a>
+    ...   <b>
+    ...   </b>
+    ...   <b>
+    ...     <c>
+    ...       <d>
+    ...       </d>
+    ...     </c>
+    ...   </b>
+    ... </a>"""
+    >>> parser.feed(exampleXml)
+    >>> parser.close()
+    4
+
+
+.. 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
+   and http://www.iana.org/assignments/character-sets .
+

Modified: python/branches/py3k-importlib/Doc/library/xml.etree.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/xml.etree.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/xml.etree.rst	Thu Mar 27 00:48:05 2008
@@ -12,7 +12,7 @@
 this package contains the :mod:`ElementTree`,  :mod:`ElementPath`, and
 :mod:`ElementInclude` modules from the full  ElementTree distribution.
 
-.. % XXX To be continued!
+.. XXX To be continued!
 
 
 .. seealso::

Modified: python/branches/py3k-importlib/Doc/library/xml.sax.handler.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/xml.sax.handler.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/xml.sax.handler.rst	Thu Mar 27 00:48:05 2008
@@ -205,7 +205,7 @@
    information to the application to expand prefixes in those contexts itself, if
    necessary.
 
-   .. % XXX This is not really the default, is it? MvL
+   .. XXX This is not really the default, is it? MvL
 
    Note that :meth:`startPrefixMapping` and :meth:`endPrefixMapping` events are not
    guaranteed to be properly nested relative to each-other: all
@@ -281,8 +281,8 @@
    must come from the same external entity so that the Locator provides useful
    information.
 
-   *content* may be a Unicode string or a byte string; the ``expat`` reader module
-   produces always Unicode strings.
+   *content* may be a string or bytes instance; the ``expat`` reader module
+   always produces strings.
 
    .. note::
 

Modified: python/branches/py3k-importlib/Doc/library/xml.sax.reader.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/xml.sax.reader.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/xml.sax.reader.rst	Thu Mar 27 00:48:05 2008
@@ -307,7 +307,7 @@
 .. method:: InputSource.setCharacterStream(charfile)
 
    Set the character stream for this input source. (The stream must be a Python 1.6
-   Unicode-wrapped file-like that performs conversion to Unicode strings.)
+   Unicode-wrapped file-like that performs conversion to strings.)
 
    If there is a character stream specified, the SAX parser will ignore any byte
    stream and will not attempt to open a URI connection to the system identifier.
@@ -348,8 +348,8 @@
 
    Return the value of attribute *name*.
 
-.. % getValueByQName, getNameByQName, getQNameByName, getQNames available
-.. % here already, but documented only for derived class.
+.. getValueByQName, getNameByQName, getQNameByName, getQNames available
+.. here already, but documented only for derived class.
 
 
 .. _attributes-ns-objects:

Modified: python/branches/py3k-importlib/Doc/library/xml.sax.utils.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/xml.sax.utils.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/xml.sax.utils.rst	Thu Mar 27 00:48:05 2008
@@ -19,7 +19,8 @@
 
    You can escape other strings of data by passing a dictionary as the optional
    *entities* parameter.  The keys and values must all be strings; each key will be
-   replaced with its corresponding value.
+   replaced with its corresponding value.  The characters ``'&'``, ``'<'`` and
+   ``'>'`` are always escaped, even if *entities* is provided.
 
 
 .. function:: unescape(data[, entities])
@@ -28,7 +29,8 @@
 
    You can unescape other strings of data by passing a dictionary as the optional
    *entities* parameter.  The keys and values must all be strings; each key will be
-   replaced with its corresponding value.
+   replaced with its corresponding value.  ``'&amp'``, ``'&lt;'``, and ``'&gt;'``
+   are always unescaped, even if *entities* is provided.
 
 
 .. function:: quoteattr(data[, entities])

Modified: python/branches/py3k-importlib/Doc/library/xmlrpclib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/xmlrpclib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/xmlrpclib.rst	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-
 :mod:`xmlrpclib` --- XML-RPC client access
 ==========================================
 
@@ -8,8 +7,8 @@
 .. sectionauthor:: Eric S. Raymond <esr at snark.thyrsus.com>
 
 
-.. % Not everything is documented yet.  It might be good to describe
-.. % Marshaller, Unmarshaller, getparser, dumps, loads, and Transport.
+.. XXX Not everything is documented yet.  It might be good to describe
+   Marshaller, Unmarshaller, getparser, dumps, loads, and Transport.
 
 XML-RPC is a Remote Procedure Call method that uses XML passed via HTTP as a
 transport.  With it, a client can call methods with parameters on a remote
@@ -33,10 +32,7 @@
    all clients and servers; see http://ontosys.com/xml-rpc/extensions.php for a
    description.  The *use_datetime* flag can be used to cause date/time values to
    be presented as :class:`datetime.datetime` objects; this is false by default.
-   :class:`datetime.datetime`, :class:`datetime.date` and :class:`datetime.time`
-   objects may be passed to calls.  :class:`datetime.date` objects are converted
-   with a time of "00:00:00". :class:`datetime.time` objects are converted using
-   today's date.
+   :class:`datetime.datetime` objects may be passed to calls.
 
    Both the HTTP and HTTPS transports support the URL syntax extension for HTTP
    Basic Authentication: ``http://user:pass@host:port/path``.  The  ``user:pass``
@@ -80,9 +76,7 @@
    +---------------------------------+---------------------------------------------+
    | :const:`dates`                  | in seconds since the epoch (pass in an      |
    |                                 | instance of the :class:`DateTime` class) or |
-   |                                 | a :class:`datetime.datetime`,               |
-   |                                 | :class:`datetime.date` or                   |
-   |                                 | :class:`datetime.time` instance             |
+   |                                 | a :class:`datetime.datetime` instance.      |
    +---------------------------------+---------------------------------------------+
    | :const:`binary data`            | pass in an instance of the :class:`Binary`  |
    |                                 | wrapper class                               |
@@ -111,12 +105,11 @@
 .. seealso::
 
    `XML-RPC HOWTO <http://www.tldp.org/HOWTO/XML-RPC-HOWTO/index.html>`_
-      A good description of XML operation and client software in several languages.
+      A good description of XML-RPC operation and client software in several languages.
       Contains pretty much everything an XML-RPC client developer needs to know.
 
-   `XML-RPC Hacks page <http://xmlrpc-c.sourceforge.net/hacks.php>`_
-      Extensions for various open-source libraries to support introspection and
-      multicall.
+   `XML-RPC Introspection <http://xmlrpc-c.sourceforge.net/introspection.html>`_
+      Describes the XML-RPC protocol extension for introspection.
 
 
 .. _serverproxy-objects:
@@ -168,11 +161,6 @@
    no such string is available, an empty string is returned. The documentation
    string may contain HTML markup.
 
-Introspection methods are currently supported by servers written in PHP, C and
-Microsoft .NET. Partial introspection support is included in recent updates to
-UserLand Frontier. Introspection support for Perl, Python and Java is available
-at the `XML-RPC Hacks <http://xmlrpc-c.sourceforge.net/hacks.php>`_ page.
-
 
 .. _boolean-objects:
 
@@ -192,16 +180,36 @@
 
    Write the XML-RPC encoding of this Boolean item to the out stream object.
 
+A working example follows. The server code::
+
+   import xmlrpclib
+   from SimpleXMLRPCServer import SimpleXMLRPCServer
+
+   def is_even(n):
+       return n%2 == 0
+
+   server = SimpleXMLRPCServer(("localhost", 8000))
+   print("Listening on port 8000...")
+   server.register_function(is_even, "is_even")
+   server.serve_forever()
+
+The client code for the preceding server::
+
+   import xmlrpclib
+
+   proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
+   print("3 is even: %s" % str(proxy.is_even(3)))
+   print("100 is even: %s" % str(proxy.is_even(100)))
 
 .. _datetime-objects:
 
 DateTime Objects
 ----------------
 
-This class may be initialized with seconds since the epoch, a time tuple, an ISO
-8601 time/date string, or a :class:`datetime.datetime`, :class:`datetime.date`
-or :class:`datetime.time` instance.  It has the following methods, supported
-mainly for internal use by the marshalling/unmarshalling code:
+This class may be initialized with seconds since the epoch, a time
+tuple, an ISO 8601 time/date string, or a :class:`datetime.datetime`
+instance.  It has the following methods, supported mainly for internal
+use by the marshalling/unmarshalling code:
 
 
 .. method:: DateTime.decode(string)
@@ -217,6 +225,32 @@
 It also supports certain of Python's built-in operators through  :meth:`__cmp__`
 and :meth:`__repr__` methods.
 
+A working example follows. The server code::
+
+   import datetime
+   from SimpleXMLRPCServer import SimpleXMLRPCServer
+   import xmlrpclib
+
+   def today():
+       today = datetime.datetime.today()
+       return xmlrpclib.DateTime(today)
+
+   server = SimpleXMLRPCServer(("localhost", 8000))
+   print("Listening on port 8000...")
+   server.register_function(today, "today")
+   server.serve_forever()
+
+The client code for the preceding server::
+
+   import xmlrpclib
+   import datetime
+
+   proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
+
+   today = proxy.today()
+   # convert the ISO8601 string to a datetime object
+   converted = datetime.datetime.strptime(today.value, "%Y%m%dT%H:%M:%S")
+   print("Today: %s" % converted.strftime("%d.%m.%Y, %H:%M"))
 
 .. _binary-objects:
 
@@ -249,6 +283,31 @@
 It also supports certain of Python's built-in operators through a
 :meth:`__cmp__` method.
 
+Example usage of the binary objects.  We're going to transfer an image over
+XMLRPC::
+
+   from SimpleXMLRPCServer import SimpleXMLRPCServer
+   import xmlrpclib
+
+   def python_logo():
+        handle = open("python_logo.jpg")
+        return xmlrpclib.Binary(handle.read())
+        handle.close()
+
+   server = SimpleXMLRPCServer(("localhost", 8000))
+   print("Listening on port 8000...")
+   server.register_function(python_logo, 'python_logo')
+
+   server.serve_forever()
+
+The client gets the image and saves it to a file::
+
+   import xmlrpclib
+
+   proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
+   handle = open("fetched_python_logo.jpg", "w")
+   handle.write(proxy.python_logo().data)
+   handle.close()
 
 .. _fault-objects:
 
@@ -268,6 +327,35 @@
 
    A string containing a diagnostic message associated with the fault.
 
+In the following example we're going to intentionally cause a :exc:`Fault` by
+returning a complex type object.  The server code::
+
+   from SimpleXMLRPCServer import SimpleXMLRPCServer
+
+   # A marshalling error is going to occur because we're returning a
+   # complex number
+   def add(x,y):
+       return x+y+0j
+
+   server = SimpleXMLRPCServer(("localhost", 8000))
+   print("Listening on port 8000...")
+   server.register_function(add, 'add')
+
+   server.serve_forever()
+
+The client code for the preceding server::
+
+   import xmlrpclib
+
+   proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
+   try:
+       proxy.add(2, 5)
+   except xmlrpclib.Fault, err:
+       print("A fault occured")
+       print("Fault code: %d" % err.faultCode)
+       print("Fault string: %s" % err.faultString)
+
+
 
 .. _protocol-error-objects:
 
@@ -299,6 +387,22 @@
    A dict containing the headers of the HTTP/HTTPS request that triggered the
    error.
 
+In the following example we're going to intentionally cause a :exc:`ProtocolError`
+by providing an invalid URI::
+
+   import xmlrpclib
+
+   # create a ServerProxy with an invalid URI
+   proxy = xmlrpclib.ServerProxy("http://invalidaddress/")
+
+   try:
+       proxy.some_method()
+   except xmlrpclib.ProtocolError, err:
+       print("A protocol error occured")
+       print("URL: %s" % err.url)
+       print("HTTP/HTTPS headers: %s" % err.headers)
+       print("Error code: %d" % err.errcode)
+       print("Error message: %s" % err.errmsg)
 
 MultiCall Objects
 -----------------
@@ -314,14 +418,48 @@
    return ``None``, and only store the call name and parameters in the
    :class:`MultiCall` object. Calling the object itself causes all stored calls to
    be transmitted as a single ``system.multicall`` request. The result of this call
-   is a generator; iterating over this generator yields the individual results.
+   is a :term:`generator`; iterating over this generator yields the individual
+   results.
+
+A usage example of this class follows.  The server code ::
+
+   from SimpleXMLRPCServer import SimpleXMLRPCServer
 
-A usage example of this class is ::
+   def add(x,y):
+       return x+y
 
-   multicall = MultiCall(server_proxy)
-   multicall.add(2,3)
-   multicall.get_address("Guido")
-   add_result, address = multicall()
+   def subtract(x, y):
+       return x-y
+
+   def multiply(x, y):
+       return x*y
+
+   def divide(x, y):
+       return x/y
+
+   # A simple server with simple arithmetic functions
+   server = SimpleXMLRPCServer(("localhost", 8000))
+   print("Listening on port 8000...")
+   server.register_multicall_functions()
+   server.register_function(add, 'add')
+   server.register_function(subtract, 'subtract')
+   server.register_function(multiply, 'multiply')
+   server.register_function(divide, 'divide')
+   server.serve_forever()
+
+The client code for the preceding server::
+
+   import xmlrpclib
+
+   proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
+   multicall = xmlrpclib.MultiCall(proxy)
+   multicall.add(7,3)
+   multicall.subtract(7,3)
+   multicall.multiply(7,3)
+   multicall.divide(7,3)
+   result = multicall()
+
+   print("7+3=%d, 7-3=%d, 7*3=%d, 7/3=%d" % tuple(result))
 
 
 Convenience Functions
@@ -352,10 +490,7 @@
    ``None`` if no method name is present in the packet. If the XML-RPC packet
    represents a fault condition, this function will raise a :exc:`Fault` exception.
    The *use_datetime* flag can be used to cause date/time values to be presented as
-   :class:`datetime.datetime` objects; this is false by default. Note that even if
-   you call an XML-RPC method with :class:`datetime.date` or :class:`datetime.time`
-   objects, they are converted to :class:`DateTime` objects internally, so only
-   :class:`datetime.datetime` objects will be returned.
+   :class:`datetime.datetime` objects; this is false by default.
 
 
 .. _xmlrpc-client-example:
@@ -379,11 +514,9 @@
        print("ERROR", v)
 
 To access an XML-RPC server through a proxy, you need to define  a custom
-transport.  The following example,  written by NoboNobo, shows how:
-
-.. % fill in original author's name if we ever learn it
+transport.  The following example shows how:
 
-.. % Example taken from http://lowlife.jp/nobonobo/wiki/xmlrpcwithproxy.html
+.. Example taken from http://lowlife.jp/nobonobo/wiki/xmlrpcwithproxy.html
 
 ::
 
@@ -406,3 +539,10 @@
    server = xmlrpclib.Server('http://time.xmlrpc.com/RPC2', transport=p)
    print(server.currentTime.getCurrentTime())
 
+
+Example of Client and Server Usage
+----------------------------------
+
+See :ref:`simplexmlrpcserver-example`.
+
+

Modified: python/branches/py3k-importlib/Doc/library/zipfile.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/zipfile.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/zipfile.rst	Thu Mar 27 00:48:05 2008
@@ -7,23 +7,25 @@
 .. moduleauthor:: James C. Ahlstrom <jim at interet.com>
 .. sectionauthor:: James C. Ahlstrom <jim at interet.com>
 
-
-.. % LaTeX markup by Fred L. Drake, Jr. <fdrake at acm.org>
-
 The ZIP file format is a common archive and compression standard. This module
 provides tools to create, read, write, append, and list a ZIP file.  Any
 advanced use of this module will require an understanding of the format, as
 defined in `PKZIP Application Note
-<http://www.pkware.com/business_and_developers/developer/appnote/>`_.
+<http://www.pkware.com/documents/casestudies/APPNOTE.TXT>`_.
 
-This module does not currently handle ZIP files which have appended comments, or
-multi-disk ZIP files. It can handle ZIP files that use the ZIP64 extensions
-(that is ZIP files that are more than 4 GByte in size).  It supports decryption
-of encrypted files in ZIP archives, but it cannot currently create an encrypted
-file.
+This module does not currently handle multi-disk ZIP files, or ZIP files
+which have appended comments (although it correctly handles comments
+added to individual archive members---for which see the :ref:`zipinfo-objects`
+documentation). It can handle ZIP files that use the ZIP64 extensions
+(that is ZIP files that are more than 4 GByte in size).  It supports
+decryption of encrypted files in ZIP archives, but it currently cannot
+create an encrypted file.  Decryption is extremely slow as it is
+implemented in native python rather than C.
 
-The available attributes of this module are:
+For other archive formats, see the :mod:`bz2`, :mod:`gzip`, and
+:mod:`tarfile` modules.
 
+The module defines the following items:
 
 .. exception:: BadZipfile
 
@@ -79,7 +81,7 @@
 
 .. seealso::
 
-   `PKZIP Application Note <http://www.pkware.com/business_and_developers/developer/appnote/>`_
+   `PKZIP Application Note <http://www.pkware.com/documents/casestudies/APPNOTE.TXT>`_
       Documentation on the ZIP file format by Phil Katz, the creator of the format and
       algorithms used.
 
@@ -172,6 +174,27 @@
       operate independently of the  ZipFile.
 
 
+.. method:: ZipFile.extract(member[, path[, pwd]])
+
+   Extract a member from the archive to the current working directory, using its
+   full name.  Its file information is extracted as accurately as possible.
+   *path* specifies a different directory to extract to.   *member* can be a
+   filename or a :class:`ZipInfo` object.  *pwd* is the password used for
+   encrypted files.
+
+   .. versionadded:: 2.6
+
+
+.. method:: ZipFile.extractall([path[, members[, pwd]]])
+
+   Extract all members from the archive to the current working directory.  *path* 
+   specifies a different directory to extract to.  *members* is optional and must
+   be a subset of the list returned by :meth:`namelist`.  *pwd* is the password
+   used for encrypted files.
+
+   .. versionadded:: 2.6
+
+
 .. method:: ZipFile.printdir()
 
    Print a table of contents for the archive to ``sys.stdout``.
@@ -236,6 +259,13 @@
    created with mode ``'r'``  will raise a :exc:`RuntimeError`.  Calling
    :meth:`writestr` on a closed ZipFile will raise a :exc:`RuntimeError`.
 
+   .. note::
+
+      When passing a :class:`ZipInfo` instance as the *zinfo_or_acrname* parameter, 
+      the compression method used will be that specified in the *compress_type* 
+      member of the given :class:`ZipInfo` instance.  By default, the 
+      :class:`ZipInfo` constructor sets this member to :const:`ZIP_STORED`.
+
 The following data attribute is also available:
 
 
@@ -331,7 +361,7 @@
 .. attribute:: ZipInfo.extra
 
    Expansion field data.  The `PKZIP Application Note
-   <http://www.pkware.com/business_and_developers/developer/appnote/>`_ contains
+   <http://www.pkware.com/documents/casestudies/APPNOTE.TXT>`_ contains
    some comments on the internal structure of the data contained in this string.
 
 

Modified: python/branches/py3k-importlib/Doc/library/zipimport.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/zipimport.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/zipimport.rst	Thu Mar 27 00:48:05 2008
@@ -27,24 +27,9 @@
 corresponding :file:`.pyc` or :file:`.pyo` file, meaning that if a ZIP archive
 doesn't contain :file:`.pyc` files, importing may be rather slow.
 
-The available attributes of this module are:
-
-
-.. exception:: ZipImportError
-
-   Exception raised by zipimporter objects. It's a subclass of :exc:`ImportError`,
-   so it can be caught as :exc:`ImportError`, too.
-
-
-.. class:: zipimporter
-
-   The class for importing ZIP files.  See section :ref:`zipimporter-objects`
-   for constructor details.
-
-
 .. seealso::
 
-   `PKZIP Application Note <http://www.pkware.com/business_and_developers/developer/appnote/>`_
+   `PKZIP Application Note <http://www.pkware.com/documents/casestudies/APPNOTE.TXT>`_
       Documentation on the ZIP file format by Phil Katz, the creator of the format and
       algorithms used.
 
@@ -57,18 +42,33 @@
       The PEP to add the import hooks that help this module work.
 
 
+This module defines an exception:
+
+.. exception:: ZipImportError
+
+   Exception raised by zipimporter objects. It's a subclass of :exc:`ImportError`,
+   so it can be caught as :exc:`ImportError`, too.
+
+
 .. _zipimporter-objects:
 
 zipimporter Objects
 -------------------
 
+:class:`zipimporter` is the class for importing ZIP files.
 
 .. class:: zipimporter(archivepath)
 
-   Create a new zipimporter instance. *archivepath* must be a path to a zipfile.
+   Create a new zipimporter instance. *archivepath* must be a path to a ZIP file.
    :exc:`ZipImportError` is raised if *archivepath* doesn't point to a valid ZIP
    archive.
 
+   *archivepath* can also contain a path within the ZIP file -- the importer
+   object will then look under that path instead of the ZIP file root.  For
+   example, an *archivepath* of :file:`foo/bar.zip/lib` will look for modules
+   in the :file:`lib` directory inside the ZIP file :file:`foo/bar.zip`
+   (provided that it exists).
+
 
 .. method:: zipimporter.find_module(fullname[, path])
 
@@ -110,11 +110,22 @@
    :exc:`ZipImportError` if it wasn't found.
 
 
-Examples
---------
+.. attribute:: zipimporter.archive
+
+   The file name of the importer's associated ZIP file.
+
+
+.. attribute:: zipimporter.prefix
+
+   The path within the ZIP file where modules are searched; see
+   :class:`zipimporter` for details.
+
 
 .. _zipimport-examples:
 
+Examples
+--------
+
 Here is an example that imports a module from a ZIP archive - note that the
 :mod:`zipimport` module is not explicitly used. ::
 

Modified: python/branches/py3k-importlib/Doc/library/zlib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/zlib.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/zlib.rst	Thu Mar 27 00:48:05 2008
@@ -19,6 +19,10 @@
 consult the zlib manual at http://www.zlib.net/manual.html for authoritative
 information.
 
+For reading and writing ``.gz`` files see the :mod:`gzip` module. For
+other archive formats, see the :mod:`bz2`, :mod:`zipfile`, and
+:mod:`tarfile` modules.
+
 The available exception and functions in this module are:
 
 
@@ -38,6 +42,8 @@
    the algorithm is designed for use as a checksum algorithm, it is not suitable
    for use as a general hash algorithm.
 
+   Always returns an unsigned 32-bit integer.
+
 
 .. function:: compress(string[, level])
 
@@ -70,7 +76,7 @@
    the algorithm is designed for use as a checksum algorithm, it is not suitable
    for use as a general hash algorithm.
 
-   .. % 
+   Always returns an unsigned 32-bit integer.
 
 
 .. function:: decompress(string[, wbits[, bufsize]])

Modified: python/branches/py3k-importlib/Doc/license.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/license.rst	(original)
+++ python/branches/py3k-importlib/Doc/license.rst	Thu Mar 27 00:48:05 2008
@@ -120,7 +120,7 @@
    analyze, test, perform and/or display publicly, prepare derivative works,
    distribute, and otherwise use Python |release| alone or in any derivative
    version, provided, however, that PSF's License Agreement and PSF's notice of
-   copyright, i.e., "Copyright © 2001-2007 Python Software Foundation; All Rights
+   copyright, i.e., "Copyright © 2001-2008 Python Software Foundation; All Rights
    Reserved" are retained in Python |release| alone or in any derivative version
    prepared by Licensee.
 
@@ -347,7 +347,7 @@
 
 The :mod:`socket` module uses the functions, :func:`getaddrinfo`, and
 :func:`getnameinfo`, which are coded in separate source files from the WIDE
-Project, http://www.wide.ad.jp/about/index.html. ::
+Project, http://www.wide.ad.jp/. ::
 
    Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
    All rights reserved.
@@ -599,3 +599,58 @@
    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
    OF THIS SOFTWARE.
 
+
+test_epoll
+----------
+
+The :mod:`test_epoll` contains the following notice::
+
+  Copyright (c) 2001-2006 Twisted Matrix Laboratories.
+
+  Permission is hereby granted, free of charge, to any person obtaining
+  a copy of this software and associated documentation files (the
+  "Software"), to deal in the Software without restriction, including
+  without limitation the rights to use, copy, modify, merge, publish,
+  distribute, sublicense, and/or sell copies of the Software, and to
+  permit persons to whom the Software is furnished to do so, subject to
+  the following conditions:
+
+  The above copyright notice and this permission notice shall be
+  included in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Select kqueue
+-------------
+
+The :mod:`select` and contains the following notice for the kqueue interface::
+
+  Copyright (c) 2000 Doug White, 2006 James Knight, 2007 Christian Heimes
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+
+  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.

Modified: python/branches/py3k-importlib/Doc/reference/compound_stmts.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/reference/compound_stmts.rst	(original)
+++ python/branches/py3k-importlib/Doc/reference/compound_stmts.rst	Thu Mar 27 00:48:05 2008
@@ -52,6 +52,7 @@
                 : | `with_stmt`
                 : | `funcdef`
                 : | `classdef`
+                : | `decorated`
    suite: `stmt_list` NEWLINE | NEWLINE INDENT `statement`+ DEDENT
    statement: `stmt_list` NEWLINE | `compound_stmt`
    stmt_list: `simple_stmt` (";" `simple_stmt`)* [";"]
@@ -72,11 +73,16 @@
 
 
 .. _if:
+.. _elif:
+.. _else:
 
 The :keyword:`if` statement
 ===========================
 
-.. index:: statement: if
+.. index::
+   statement: if
+   keyword: elif
+   keyword: else
            keyword: elif
            keyword: else
 
@@ -103,6 +109,7 @@
    statement: while
    keyword: else
    pair: loop; statement
+   keyword: else
 
 The :keyword:`while` statement is used for repeated execution as long as an
 expression is true:
@@ -137,6 +144,9 @@
    keyword: else
    pair: target; list
    pair: loop; statement
+   keyword: in
+   keyword: else
+   pair: target; list
    object: sequence
 
 The :keyword:`for` statement is used to iterate over the elements of a sequence
@@ -200,11 +210,16 @@
 
 
 .. _try:
+.. _except:
+.. _finally:
 
 The :keyword:`try` statement
 ============================
 
-.. index:: statement: try
+.. index::
+   statement: try
+   keyword: except
+   keyword: finally
 .. index:: keyword: except
 
 The :keyword:`try` statement specifies exception handlers and/or cleanup code
@@ -219,7 +234,8 @@
    try2_stmt: "try" ":" `suite`
             : "finally" ":" `suite`
 
-The :keyword:`except` clause(s) specify one or more exception handlers.  When no
+
+The :keyword:`except` clause(s) specify one or more exception handlers. When no
 exception occurs in the :keyword:`try` clause, no exception handler is executed.
 When an exception occurs in the :keyword:`try` suite, a search for an exception
 handler is started.  This search inspects the except clauses in turn until one
@@ -326,6 +342,7 @@
 
 
 .. _with:
+.. _as:
 
 The :keyword:`with` statement
 =============================
@@ -374,6 +391,10 @@
    location for the kind of exit that was taken.
 
 
+   In Python 2.5, the :keyword:`with` statement is only allowed when the
+   ``with_statement`` feature has been enabled.  It is always enabled in
+   Python 2.6.
+
 .. seealso::
 
    :pep:`0343` - The "with" statement
@@ -382,13 +403,16 @@
 
 
 .. _function:
+.. _def:
 
 Function definitions
 ====================
 
 .. index::
-   pair: function; definition
    statement: def
+   pair: function; definition
+   pair: function; name
+   pair: name; binding
    object: user-defined function
    object: function
    pair: function; name
@@ -401,6 +425,7 @@
    funcdef: [`decorators`] "def" `funcname` "(" [`parameter_list`] ")" ["->" `expression`]? ":" `suite`
    decorators: `decorator`+
    decorator: "@" `dotted_name` ["(" [`argument_list` [","]] ")"] NEWLINE
+   funcdef: "def" `funcname` "(" [`parameter_list`] ")" ":" `suite`
    dotted_name: `identifier` ("." `identifier`)*
    parameter_list: (`defparameter` ",")*
                  : (  "*" [`parameter`] ("," `defparameter`)*
@@ -421,7 +446,7 @@
 The function definition does not execute the function body; this gets executed
 only when the function is called.
 
-A function definition may be wrapped by one or more decorator expressions.
+A function definition may be wrapped by one or more :term:`decorator` expressions.
 Decorator expressions are evaluated when the function is defined, in the scope
 that contains the function definition.  The result must be a callable, which is
 invoked with the function object as the only argument. The returned value is
@@ -507,13 +532,13 @@
 =================
 
 .. index::
-   pair: class; definition
-   statement: class
    object: class
-   single: inheritance
+   statement: class
+   pair: class; definition
    pair: class; name
    pair: name; binding
    pair: execution; frame
+   single: inheritance
 
 A class definition defines a class object (see section :ref:`types`):
 
@@ -548,13 +573,13 @@
    Foo = f1(arg)(f2(Foo))
 
 **Programmer's note:** Variables defined in the class definition are class
-variables; they are shared by all instances.  To define instance variables, they
-must be given a value in the :meth:`__init__` method or in another method.  Both
-class and instance variables are accessible through the notation
-"``self.name``", and an instance variable hides a class variable with the same
-name when accessed in this way.  Class variables with immutable values can be
-used as defaults for instance variables. Descriptors can be used to create
-instance variables with different implementation details.
+can be set in a method with ``self.name = value``.  Both class and instance
+variables are accessible through the notation "``self.name``", and an instance
+variable hides a class variable with the same name when accessed in this way.
+Class variables can be used as defaults for instance variables, but using
+mutable values there can lead to unexpected results.  For :term:`new-style
+class`\es, descriptors can be used to create instance variables with different
+implementation details.
 
 .. XXX add link to descriptor docs above
 
@@ -562,11 +587,15 @@
 
    :pep:`3129` - Class Decorators
 
+Class definitions, like function definitions, may be wrapped by one or
+more :term:`decorator` expressions.  The evaluation rules for the
+decorator expressions are the same as for functions.  The result must
+be a class object, which is then bound to the class name.
 
 
 .. rubric:: Footnotes
 
-.. [#] The exception is propogated to the invocation stack only if there is no
+.. [#] The exception is propagated to the invocation stack only if there is no
    :keyword:`finally` clause that negates the exception.
 
 .. [#] Currently, control "flows off the end" except in the case of an exception or the

Modified: python/branches/py3k-importlib/Doc/reference/datamodel.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/reference/datamodel.rst	(original)
+++ python/branches/py3k-importlib/Doc/reference/datamodel.rst	Thu Mar 27 00:48:05 2008
@@ -152,7 +152,7 @@
    object is accessed through the literal ``...`` or the built-in name
    ``Ellipsis``.  Its truth value is true.
 
-Numbers
+:class:`numbers.Number`
    .. index:: object: numeric
 
    These are created by numeric literals and returned as results by arithmetic
@@ -164,31 +164,19 @@
    Python distinguishes between integers, floating point numbers, and complex
    numbers:
 
-   Integers
+   :class:`numbers.Integral`
       .. index:: object: integer
 
       These represent elements from the mathematical set of integers (positive and
       negative).
 
-      There are three types of integers:
+      There are two types of integers:
 
       Plain integers
          .. index::
             object: plain integer
             single: OverflowError (built-in exception)
 
-         These represent numbers in the range -2147483648 through 2147483647. (The range
-         may be larger on machines with a larger natural word size, but not smaller.)
-         When the result of an operation would fall outside this range, the result is
-         normally returned as a long integer (in some cases, the exception
-         :exc:`OverflowError` is raised instead). For the purpose of shift and mask
-         operations, integers are assumed to have a binary, 2's complement notation using
-         32 or more bits, and hiding no bits from the user (i.e., all 4294967296
-         different bit patterns correspond to different values).
-
-      Long integers
-         .. index:: object: long integer
-
          These represent numbers in an unlimited range, subject to available (virtual)
          memory only.  For the purpose of shift and mask operations, a binary
          representation is assumed, and negative numbers are represented in a variant of
@@ -210,15 +198,11 @@
       .. index:: pair: integer; representation
 
       The rules for integer representation are intended to give the most meaningful
-      interpretation of shift and mask operations involving negative integers and the
-      least surprises when switching between the plain and long integer domains.  Any
+      interpretation of shift and mask operations involving negative integers.  Any
       operation except left shift, if it yields a result in the plain integer domain
-      without causing overflow, will yield the same result in the long integer domain
-      or when using mixed operands.
+      without causing overflow, will yield the same result when using mixed operands.
 
-      .. % Integers
-
-   Floating point numbers
+   :class:`numbers.Real` (:class:`float`)
       .. index::
          object: floating point
          pair: floating point; number
@@ -233,7 +217,7 @@
       overhead of using objects in Python, so there is no reason to complicate the
       language with two kinds of floating point numbers.
 
-   Complex numbers
+   :class:`numbers.Complex`
       .. index::
          object: complex
          pair: complex; number
@@ -243,8 +227,6 @@
       The real and imaginary parts of a complex number ``z`` can be retrieved through
       the read-only attributes ``z.real`` and ``z.imag``.
 
-   .. % Numbers
-
 Sequences
    .. index::
       builtin: len
@@ -316,8 +298,6 @@
          parentheses must be usable for grouping of expressions).  An empty
          tuple can be formed by an empty pair of parentheses.
 
-      .. % Immutable sequences
-
    Mutable sequences
       .. index::
          object: mutable sequence
@@ -355,10 +335,6 @@
       The extension module :mod:`array` provides an additional example of a
       mutable sequence type.
 
-      .. % Mutable sequences
-
-   .. % Sequences
-
 Set types
    .. index::
       builtin: len
@@ -388,11 +364,10 @@
    Frozen sets
       .. index:: object: frozenset
 
-      These represent an immutable set. They are created by the built-in
-      :func:`frozenset` constructor. As a frozenset is immutable and hashable, it can
-      be used again as an element of another set, or as a dictionary key.
-
-   .. % Set types
+      These represent an immutable set.  They are created by the built-in
+      :func:`frozenset` constructor.  As a frozenset is immutable and
+      :term:`hashable`, it can be used again as an element of another set, or as
+      a dictionary key.
 
 Mappings
    .. index::
@@ -431,8 +406,6 @@
       The extension modules :mod:`dbm`, :mod:`gdbm`, and :mod:`bsddb` provide
       additional examples of mapping types.
 
-   .. % Mapping types
-
 Callable types
    .. index::
       object: callable
@@ -528,97 +501,78 @@
          single: __kwdefaults__ (function attribute)
          pair: global; namespace
 
-   User-defined methods
+   Instance methods
       .. index::
          object: method
          object: user-defined method
          pair: user-defined; method
 
-      A user-defined method object combines a class, a class instance (or ``None``)
-      and any callable object (normally a user-defined function).
+      An instance method object combines a class, a class instance and any
+      callable object (normally a user-defined function).
 
-      Special read-only attributes: :attr:`im_self` is the class instance object,
-      :attr:`im_func` is the function object; :attr:`im_class` is the class of
-      :attr:`im_self` for bound methods or the class that asked for the method for
-      unbound methods; :attr:`__doc__` is the method's documentation (same as
-      ``im_func.__doc__``); :attr:`__name__` is the method name (same as
-      ``im_func.__name__``); :attr:`__module__` is the name of the module the method
-      was defined in, or ``None`` if unavailable.
+      .. versionchanged:: 2.6
+         For 3.0 forward-compatibility, :attr:`im_func` is also available as
+         :attr:`__func__`, and :attr:`im_self` as :attr:`__self__`.
 
       .. index::
+         single: __func__ (method attribute)
+         single: __self__ (method attribute)
          single: __doc__ (method attribute)
          single: __name__ (method attribute)
          single: __module__ (method attribute)
-         single: im_func (method attribute)
-         single: im_self (method attribute)
+
+      Special read-only attributes: :attr:`__self__` is the class instance object,
+      :attr:`__func__` is the function object; :attr:`__doc__` is the method's
+      documentation (same as ``__func__.__doc__``); :attr:`__name__` is the
+      method name (same as ``__func__.__name__``); :attr:`__module__` is the
+      name of the module the method was defined in, or ``None`` if unavailable.
 
       Methods also support accessing (but not setting) the arbitrary function
       attributes on the underlying function object.
 
-      User-defined method objects may be created when getting an attribute of a class
-      (perhaps via an instance of that class), if that attribute is a user-defined
-      function object, an unbound user-defined method object, or a class method
-      object. When the attribute is a user-defined method object, a new method object
-      is only created if the class from which it is being retrieved is the same as, or
-      a derived class of, the class stored in the original method object; otherwise,
-      the original method object is used as it is.
-
-      .. index::
-         single: im_class (method attribute)
-         single: im_func (method attribute)
-         single: im_self (method attribute)
-
-      When a user-defined method object is created by retrieving a user-defined
-      function object from a class, its :attr:`im_self` attribute is ``None``
-      and the method object is said to be unbound. When one is created by
-      retrieving a user-defined function object from a class via one of its
-      instances, its :attr:`im_self` attribute is the instance, and the method
-      object is said to be bound. In either case, the new method's
-      :attr:`im_class` attribute is the class from which the retrieval takes
-      place, and its :attr:`im_func` attribute is the original function object.
-
-      .. index:: single: im_func (method attribute)
-
-      When a user-defined method object is created by retrieving another method object
-      from a class or instance, the behaviour is the same as for a function object,
-      except that the :attr:`im_func` attribute of the new instance is not the
-      original method object but its :attr:`im_func` attribute.
-
-      .. index::
-         single: im_class (method attribute)
-         single: im_func (method attribute)
-         single: im_self (method attribute)
-
-      When a user-defined method object is created by retrieving a class method object
-      from a class or instance, its :attr:`im_self` attribute is the class itself (the
-      same as the :attr:`im_class` attribute), and its :attr:`im_func` attribute is
-      the function object underlying the class method.
-
-      When an unbound user-defined method object is called, the underlying function
-      (:attr:`im_func`) is called, with the restriction that the first argument must
-      be an instance of the proper class (:attr:`im_class`) or of a derived class
-      thereof.
-
-      When a bound user-defined method object is called, the underlying function
-      (:attr:`im_func`) is called, inserting the class instance (:attr:`im_self`) in
-      front of the argument list.  For instance, when :class:`C` is a class which
-      contains a definition for a function :meth:`f`, and ``x`` is an instance of
-      :class:`C`, calling ``x.f(1)`` is equivalent to calling ``C.f(x, 1)``.
-
-      When a user-defined method object is derived from a class method object, the
-      "class instance" stored in :attr:`im_self` will actually be the class itself, so
-      that calling either ``x.f(1)`` or ``C.f(1)`` is equivalent to calling ``f(C,1)``
-      where ``f`` is the underlying function.
-
-      Note that the transformation from function object to (unbound or bound) method
-      object happens each time the attribute is retrieved from the class or instance.
-      In some cases, a fruitful optimization is to assign the attribute to a local
-      variable and call that local variable. Also notice that this transformation only
-      happens for user-defined functions; other callable objects (and all non-callable
-      objects) are retrieved without transformation.  It is also important to note
-      that user-defined functions which are attributes of a class instance are not
-      converted to bound methods; this *only* happens when the function is an
-      attribute of the class.
+      User-defined method objects may be created when getting an attribute of a
+      class (perhaps via an instance of that class), if that attribute is a
+      user-defined function object or a class method object.
+      
+      When an instance method object is created by retrieving a user-defined
+      function object from a class via one of its instances, its
+      :attr:`__self__` attribute is the instance, and the method object is said
+      to be bound.  The new method's :attr:`__func__` attribute is the original
+      function object.
+
+      When a user-defined method object is created by retrieving another method
+      object from a class or instance, the behaviour is the same as for a
+      function object, except that the :attr:`__func__` attribute of the new
+      instance is not the original method object but its :attr:`__func__`
+      attribute.
+
+      When an instance method object is created by retrieving a class method
+      object from a class or instance, its :attr:`__self__` attribute is the
+      class itself, and its :attr:`__func__` attribute is the function object
+      underlying the class method.
+
+      When an instance method object is called, the underlying function
+      (:attr:`__func__`) is called, inserting the class instance
+      (:attr:`__self__`) in front of the argument list.  For instance, when
+      :class:`C` is a class which contains a definition for a function
+      :meth:`f`, and ``x`` is an instance of :class:`C`, calling ``x.f(1)`` is
+      equivalent to calling ``C.f(x, 1)``.
+
+      When an instance method object is derived from a class method object, the
+      "class instance" stored in :attr:`__self__` will actually be the class
+      itself, so that calling either ``x.f(1)`` or ``C.f(1)`` is equivalent to
+      calling ``f(C,1)`` where ``f`` is the underlying function.
+
+      Note that the transformation from function object to instance method
+      object happens each time the attribute is retrieved from the instance.  In
+      some cases, a fruitful optimization is to assign the attribute to a local
+      variable and call that local variable. Also notice that this
+      transformation only happens for user-defined functions; other callable
+      objects (and all non-callable objects) are retrieved without
+      transformation.  It is also important to note that user-defined functions
+      which are attributes of a class instance are not converted to bound
+      methods; this *only* happens when the function is an attribute of the
+      class.
 
    Generator functions
       .. index::
@@ -688,8 +642,6 @@
    object used to initialize the module (since it isn't needed once the
    initialization is done).
 
-   .. % 
-
    Attribute assignment updates the module's namespace dictionary, e.g., ``m.x =
    1`` is equivalent to ``m.__dict__["x"] = 1``.
 
@@ -735,16 +687,12 @@
       pair: class; attribute
 
    When a class attribute reference (for class :class:`C`, say) would yield a
-   user-defined function object or an unbound user-defined method object whose
-   associated class is either :class:`C` or one of its base classes, it is
-   transformed into an unbound user-defined method object whose :attr:`im_class`
-   attribute is :class:`C`. When it would yield a class method object, it is
-   transformed into a bound user-defined method object whose :attr:`im_class`
-   and :attr:`im_self` attributes are both :class:`C`.  When it would yield a
-   static method object, it is transformed into the object wrapped by the static
-   method object. See section :ref:`descriptors` for another way in which
-   attributes retrieved from a class may differ from those actually contained in
-   its :attr:`__dict__`.
+   class method object, it is transformed into an instance method object whose
+   :attr:`__self__` attributes is :class:`C`.  When it would yield a static
+   method object, it is transformed into the object wrapped by the static method
+   object. See section :ref:`descriptors` for another way in which attributes
+   retrieved from a class may differ from those actually contained in its
+   :attr:`__dict__`.
 
    .. index:: triple: class; attribute; assignment
 
@@ -776,22 +724,19 @@
       pair: class; instance
       pair: class instance; attribute
 
-   A class instance is created by calling a class object (see above). A class
-   instance has a namespace implemented as a dictionary which is the first place in
-   which attribute references are searched.  When an attribute is not found there,
-   and the instance's class has an attribute by that name, the search continues
-   with the class attributes.  If a class attribute is found that is a user-defined
-   function object or an unbound user-defined method object whose associated class
-   is the class (call it :class:`C`) of the instance for which the attribute
-   reference was initiated or one of its bases, it is transformed into a bound
-   user-defined method object whose :attr:`im_class` attribute is :class:`C` and
-   whose :attr:`im_self` attribute is the instance. Static method and class method
-   objects are also transformed, as if they had been retrieved from class
-   :class:`C`; see above under "Classes". See section :ref:`descriptors` for
-   another way in which attributes of a class retrieved via its instances may
-   differ from the objects actually stored in the class's :attr:`__dict__`. If no
-   class attribute is found, and the object's class has a :meth:`__getattr__`
-   method, that is called to satisfy the lookup.
+   A class instance is created by calling a class object (see above).  A class
+   instance has a namespace implemented as a dictionary which is the first place
+   in which attribute references are searched.  When an attribute is not found
+   there, and the instance's class has an attribute by that name, the search
+   continues with the class attributes.  If a class attribute is found that is a
+   user-defined function object, it is transformed into an instance method
+   object whose :attr:`__self__` attribute is the instance.  Static method and
+   class method objects are also transformed; see above under "Classes".  See
+   section :ref:`descriptors` for another way in which attributes of a class
+   retrieved via its instances may differ from the objects actually stored in
+   the class's :attr:`__dict__`.  If no class attribute is found, and the
+   object's class has a :meth:`__getattr__` method, that is called to satisfy
+   the lookup.
 
    .. index:: triple: class instance; attribute; assignment
 
@@ -852,7 +797,7 @@
          single: bytecode
          object: code
 
-      Code objects represent *byte-compiled* executable Python code, or *bytecode*.
+      Code objects represent *byte-compiled* executable Python code, or :term:`bytecode`.
       The difference between a code object and a function object is that the function
       object contains an explicit reference to the function's globals (the module in
       which it was defined), while a code object contains no context; also the default
@@ -873,7 +818,7 @@
       used by the bytecode; :attr:`co_names` is a tuple containing the names used by
       the bytecode; :attr:`co_filename` is the filename from which the code was
       compiled; :attr:`co_firstlineno` is the first line number of the function;
-      :attr:`co_lnotab` is a string encoding the mapping from byte code offsets to
+      :attr:`co_lnotab` is a string encoding the mapping from bytecode offsets to
       line numbers (for details see the source code of the interpreter);
       :attr:`co_stacksize` is the required stack size (including local variables);
       :attr:`co_flags` is an integer encoding a number of flags for the interpreter.
@@ -960,7 +905,6 @@
          pair: exception; handler
          pair: execution; stack
          single: exc_info (in module sys)
-         single: exc_traceback (in module sys)
          single: last_traceback (in module sys)
          single: sys.exc_info
          single: sys.last_traceback
@@ -1035,9 +979,44 @@
       described above, under "User-defined methods". Class method objects are created
       by the built-in :func:`classmethod` constructor.
 
-   .. % Internal types
 
-.. % =========================================================================
+.. _newstyle:
+
+New-style and classic classes
+=============================
+
+Classes and instances come in two flavors: old-style or classic, and new-style.
+
+Up to Python 2.1, old-style classes were the only flavour available to the user.
+The concept of (old-style) class is unrelated to the concept of type: if *x* is
+an instance of an old-style class, then ``x.__class__`` designates the class of
+*x*, but ``type(x)`` is always ``<type 'instance'>``.  This reflects the fact
+that all old-style instances, independently of their class, are implemented with
+a single built-in type, called ``instance``.
+
+New-style classes were introduced in Python 2.2 to unify classes and types.  A
+new-style class is neither more nor less than a user-defined type.  If *x* is an
+instance of a new-style class, then ``type(x)`` is the same as ``x.__class__``.
+
+The major motivation for introducing new-style classes is to provide a unified
+object model with a full meta-model.  It also has a number of immediate
+benefits, like the ability to subclass most built-in types, or the introduction
+of "descriptors", which enable computed properties.
+
+For compatibility reasons, classes are still old-style by default.  New-style
+classes are created by specifying another new-style class (i.e. a type) as a
+parent class, or the "top-level type" :class:`object` if no other parent is
+needed.  The behaviour of new-style classes differs from that of old-style
+classes in a number of important details in addition to what :func:`type`
+returns.  Some of these changes are fundamental to the new object model, like
+the way special methods are invoked.  Others are "fixes" that could not be
+implemented before for compatibility concerns, like the method resolution order
+in case of multiple inheritance.
+
+This manual is not up-to-date with respect to new-style classes.  For now,
+please see http://www.python.org/doc/newstyle/ for more information.
+
+.. XXX remove old style classes from docs
 
 
 .. _specialnames:
@@ -1110,7 +1089,8 @@
    :meth:`__init__` method will not be invoked.
 
    :meth:`__new__` is intended mainly to allow subclasses of immutable types (like
-   int, str, or tuple) to customize instance creation.
+   int, str, or tuple) to customize instance creation.  It is also commonly
+   overridden in custom metaclasses in order to customize class creation.
 
 
 .. method:: object.__init__(self[, ...])
@@ -1241,6 +1221,9 @@
             object.__gt__(self, other)
             object.__ge__(self, other)
 
+   .. index::
+      single: comparisons
+
    These are the so-called "rich comparison" methods, and are called for comparison
    operators in preference to :meth:`__cmp__` below. The correspondence between
    operator symbols and method names is as follows: ``x<y`` calls ``x.__lt__(y)``,
@@ -1255,14 +1238,16 @@
    context (e.g., in the condition of an ``if`` statement), Python will call
    :func:`bool` on the value to determine if the result is true or false.
 
-   There are no implied relationships among the comparison operators. The truth of
-   ``x==y`` does not imply that ``x!=y`` is false.  Accordingly, when defining
-   :meth:`__eq__`, one should also define :meth:`__ne__` so that the operators will
-   behave as expected.
-
-   There are no reflected (swapped-argument) versions of these methods (to be used
-   when the left argument does not support the operation but the right argument
-   does); rather, :meth:`__lt__` and :meth:`__gt__` are each other's reflection,
+   There are no implied relationships among the comparison operators. The truth
+   of ``x==y`` does not imply that ``x!=y`` is false.  Accordingly, when
+   defining :meth:`__eq__`, one should also define :meth:`__ne__` so that the
+   operators will behave as expected.  See the paragraph on :meth:`__hash__` for
+   some important notes on creating :term:`hashable` objects which support
+   custom comparison operations and are usable as dictionary keys.
+
+   There are no swapped-argument versions of these methods (to be used when the
+   left argument does not support the operation but the right argument does);
+   rather, :meth:`__lt__` and :meth:`__gt__` are each other's reflection,
    :meth:`__le__` and :meth:`__ge__` are each other's reflection, and
    :meth:`__eq__` and :meth:`__ne__` are their own reflection.
 
@@ -1275,14 +1260,14 @@
       builtin: cmp
       single: comparisons
 
-   Called by comparison operations if rich comparison (see above) is not defined.
-   Should return a negative integer if ``self < other``, zero if ``self == other``,
-   a positive integer if ``self > other``.  If no :meth:`__cmp__`, :meth:`__eq__`
-   or :meth:`__ne__` operation is defined, class instances are compared by object
-   identity ("address").  See also the description of :meth:`__hash__` for some
-   important notes on creating objects which support custom comparison operations
-   and are usable as dictionary keys. (Note: the restriction that exceptions are
-   not propagated by :meth:`__cmp__` has been removed since Python 1.5.)
+   Called by comparison operations if rich comparison (see above) is not
+   defined.  Should return a negative integer if ``self < other``, zero if
+   ``self == other``, a positive integer if ``self > other``.  If no
+   :meth:`__cmp__`, :meth:`__eq__` or :meth:`__ne__` operation is defined, class
+   instances are compared by object identity ("address").  See also the
+   description of :meth:`__hash__` for some important notes on creating
+   :term:`hashable` objects which support custom comparison operations and are
+   usable as dictionary keys.
 
 
 .. method:: object.__hash__(self)
@@ -1292,22 +1277,25 @@
       builtin: hash
       single: __cmp__() (object method)
 
-   Called for the key object for dictionary  operations, and by the built-in
-   function :func:`hash`.  Should return a 32-bit integer usable as a hash value
+   Called for the key object for dictionary operations, and by the built-in
+   function :func:`hash`.  Should return an integer usable as a hash value
    for dictionary operations.  The only required property is that objects which
    compare equal have the same hash value; it is advised to somehow mix together
    (e.g., using exclusive or) the hash values for the components of the object that
-   also play a part in comparison of objects.  If a class does not define a
-   :meth:`__cmp__` method it should not define a :meth:`__hash__` operation either;
-   if it defines :meth:`__cmp__` or :meth:`__eq__` but not :meth:`__hash__`, its
-   instances will not be usable as dictionary keys.  If a class defines mutable
-   objects and implements a :meth:`__cmp__` or :meth:`__eq__` method, it should not
-   implement :meth:`__hash__`, since the dictionary implementation requires that a
-   key's hash value is immutable (if the object's hash value changes, it will be in
-   the wrong hash bucket).
+   also play a part in comparison of objects.
 
-   :meth:`__hash__` may also return a long integer object; the 32-bit integer is
-   then derived from the hash of that object.
+   If a class does not define a :meth:`__cmp__` or :meth:`__eq__` method it
+   should not define a :meth:`__hash__` operation either; if it defines
+   :meth:`__cmp__` or :meth:`__eq__` but not :meth:`__hash__`, its instances
+   will not be usable as dictionary keys.  If a class defines mutable objects
+   and implements a :meth:`__cmp__` or :meth:`__eq__` method, it should not
+   implement :meth:`__hash__`, since the dictionary implementation requires that
+   a key's hash value is immutable (if the object's hash value changes, it will
+   be in the wrong hash bucket).
+
+   User-defined classes have :meth:`__cmp__` and :meth:`__hash__` methods
+   by default; with them, all objects compare unequal and ``x.__hash__()``
+   returns ``id(x)``.
 
 
 .. method:: object.__bool__(self)
@@ -1524,7 +1512,7 @@
   *__slots__*.
 
 * *__slots__* do not work for classes derived from "variable-length" built-in
-  types such as :class:`long`, :class:`str` and :class:`tuple`.
+  types such as :class:`int`, :class:`str` and :class:`tuple`.
 
 * Any non-string iterable may be assigned to *__slots__*. Mappings may also be
   used; however, in the future, special meaning may be assigned to the values
@@ -1543,7 +1531,7 @@
 result of ``type(name, bases, dict)``.
 
 When the class definition is read, if *__metaclass__* is defined then the
-callable assigned to it will be called instead of :func:`type`. The allows
+callable assigned to it will be called instead of :func:`type`. This allows
 classes or functions to be written which monitor or alter the class creation
 process:
 
@@ -1552,7 +1540,21 @@
 * Returning an instance of another class -- essentially performing the role of a
   factory function.
 
-.. XXX needs to be updated for the "new metaclasses" PEP
+These steps will have to be performed in the metaclass's :meth:`__new__` method
+-- :meth:`type.__new__` can then be called from this method to create a class
+with different properties.  This example adds a new element to the class
+dictionary before creating the class::
+
+  class metacls(type):
+      def __new__(mcs, name, bases, dict):
+          dict['foo'] = 'metacls was here'
+          return type.__new__(mcs, name, bases, dict)
+
+You can of course also override other class methods (or add new methods); for
+example defining a custom :meth:`__call__` method in the metaclass allows custom
+behavior when the class is called, e.g. not always creating a new instance.
+
+
 .. data:: __metaclass__
 
    This variable can be any callable accepting arguments for ``name``, ``bases``,
@@ -1696,6 +1698,20 @@
    Iterator objects also need to implement this method; they are required to return
    themselves.  For more information on iterator objects, see :ref:`typeiter`.
 
+
+.. method:: object.__reversed__(self)
+
+   Called (if present) by the :func:`reversed` builtin to implement
+   reverse iteration.  It should return a new iterator object that iterates
+   over all the objects in the container in reverse order.
+
+   If the :meth:`__reversed__` method is not provided, the
+   :func:`reversed` builtin will fall back to using the sequence protocol
+   (:meth:`__len__` and :meth:`__getitem__`).  Objects should normally
+   only provide :meth:`__reversed__` if they do not support the sequence
+   protocol and an efficient implementation of reverse iteration is possible.
+
+
 The membership test operators (:keyword:`in` and :keyword:`not in`) are normally
 implemented as an iteration through a sequence.  However, container objects can
 supply the following special method with a more efficient implementation, which
@@ -1842,24 +1858,22 @@
 
 .. method:: object.__complex__(self)
             object.__int__(self)
-            object.__long__(self)
             object.__float__(self)
 
    .. index::
       builtin: complex
       builtin: int
-      builtin: long
       builtin: float
 
-   Called to implement the built-in functions :func:`complex`, :func:`int`,
-   :func:`long`, and :func:`float`.  Should return a value of the appropriate type.
+   Called to implement the built-in functions :func:`complex`, :func:`int`
+   and :func:`float`.  Should return a value of the appropriate type.
 
 
 .. method:: object.__index__(self)
 
    Called to implement :func:`operator.index`.  Also called whenever Python needs
    an integer object (such as in slicing, or in the built-in :func:`bin`,
-   :func:`hex` and :func:`oct` functions). Must return an integer (int or long).
+   :func:`hex` and :func:`oct` functions). Must return an integer.
 
 
 .. _context-managers:
@@ -1913,6 +1927,18 @@
 
 .. rubric:: Footnotes
 
+.. [#] Since Python 2.2, a gradual merging of types and classes has been started that
+   makes this and a few other assertions made in this manual not 100% accurate and
+   complete: for example, it *is* now possible in some cases to change an object's
+   type, under certain controlled conditions.  Until this manual undergoes
+   extensive revision, it must now be taken as authoritative only regarding
+   "classic classes", that are still the default, for compatibility purposes, in
+   Python 2.2 and 2.3.  For more information, see
+   http://www.python.org/doc/newstyle/.
+
+.. [#] This, and other statements, are only roughly true for instances of new-style
+   classes.
+
 .. [#] A descriptor can define any combination of :meth:`__get__`,
    :meth:`__set__` and :meth:`__delete__`.  If it does not define :meth:`__get__`,
    then accessing the attribute even on an instance will return the descriptor

Modified: python/branches/py3k-importlib/Doc/reference/executionmodel.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/reference/executionmodel.rst	(original)
+++ python/branches/py3k-importlib/Doc/reference/executionmodel.rst	Thu Mar 27 00:48:05 2008
@@ -50,7 +50,13 @@
 definition occurs in a function block, the scope extends to any blocks contained
 within the defining one, unless a contained block introduces a different binding
 for the name.  The scope of names defined in a class block is limited to the
-class block; it does not extend to the code blocks of methods.
+class block; it does not extend to the code blocks of methods -- this includes
+generator expressions since they are implemented using a function scope.  This
+means that the following will fail::
+
+   class A:
+       a = 42
+       b = list(a + i for i in range(10))
 
 .. index:: single: environment
 
@@ -105,7 +111,7 @@
 specified in the statement refer to the binding of that name in the top-level
 namespace.  Names are resolved in the top-level namespace by searching the
 global namespace, i.e. the namespace of the module containing the code block,
-and the builtin namespace, the namespace of the module :mod:`__builtin__`.  The
+and the builtin namespace, the namespace of the module :mod:`builtins`.  The
 global namespace is searched first.  If the name is not found there, the builtin
 namespace is searched.  The global statement must precede all uses of the name.
 
@@ -117,8 +123,8 @@
 found by looking up the name ``__builtins__`` in its global namespace; this
 should be a dictionary or a module (in the latter case the module's dictionary
 is used).  By default, when in the :mod:`__main__` module, ``__builtins__`` is
-the built-in module :mod:`__builtin__` (note: no 's'); when in any other module,
-``__builtins__`` is an alias for the dictionary of the :mod:`__builtin__` module
+the built-in module :mod:`builtins`; when in any other module,
+``__builtins__`` is an alias for the dictionary of the :mod:`builtins` module
 itself.  ``__builtins__`` can be set to a user-created dictionary to create a
 weak form of restricted execution.
 
@@ -126,7 +132,7 @@
 
    Users should not touch ``__builtins__``; it is strictly an implementation
    detail.  Users wanting to override values in the built-in namespace should
-   :keyword:`import` the :mod:`__builtin__` (no 's') module and modify its
+   :keyword:`import` the :mod:`builtins` module and modify its
    attributes appropriately.
 
 .. index:: module: __main__

Modified: python/branches/py3k-importlib/Doc/reference/expressions.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/reference/expressions.rst	(original)
+++ python/branches/py3k-importlib/Doc/reference/expressions.rst	Thu Mar 27 00:48:05 2008
@@ -232,6 +232,20 @@
 constructed from the elements resulting from the comprehension.
 
 
+Variables used in the generator expression are evaluated lazily in a separate
+scope when the :meth:`next` method is called for the generator object (in the
+same fashion as for normal generators).  However, the :keyword:`in` expression
+of the leftmost :keyword:`for` clause is immediately evaluated in the current
+scope so that an error produced by it can be seen before any other possible
+error in the code that handles the generator expression.  Subsequent
+:keyword:`for` and :keyword:`if` clauses cannot be evaluated immediately since
+they may depend on the previous :keyword:`for` loop.  For example:
+``(x*y for x in range(10) for y in bar(x))``.
+
+The parentheses can be omitted on calls with only one argument. See section
+:ref:`calls` for the detail.
+
+
 .. _dict:
 
 Dictionary displays
@@ -267,7 +281,7 @@
            hashable
 
 Restrictions on the types of the key values are listed earlier in section
-:ref:`types`.  (To summarize, the key type should be hashable, which excludes
+:ref:`types`.  (To summarize, the key type should be :term:`hashable`, which excludes
 all mutable objects.)  Clashes between duplicate keys are not detected; the last
 datum (textually rightmost in the display) stored for a given key value
 prevails.
@@ -380,7 +394,7 @@
    generator, or raises :exc:`StopIteration` if the generator exits without
    yielding another value.  When :meth:`send` is called to start the generator,
    it must be called with :const:`None` as the argument, because there is no
-   :keyword:`yield` expression that could receieve the value.
+   :keyword:`yield` expression that could receive the value.
 
 
 .. method:: generator.throw(type[, value[, traceback]])
@@ -413,9 +427,6 @@
    ...         while True:
    ...             try:
    ...                 value = (yield value)
-   ...             except GeneratorExit:
-   ...                 # never catch GeneratorExit
-   ...                 raise
    ...             except Exception, e:
    ...                 value = e
    ...     finally:
@@ -655,7 +666,7 @@
 
 If the syntax ``*expression`` appears in the function call, ``expression`` must
 evaluate to a sequence.  Elements from this sequence are treated as if they were
-additional positional arguments; if there are postional arguments *x1*,...,*xN*
+additional positional arguments; if there are positional arguments *x1*,...,*xN*
 , and ``expression`` evaluates to a sequence *y1*,...,*yM*, this is equivalent
 to a call with M+N positional arguments *x1*,...,*xN*,*y1*,...,*yM*.
 
@@ -771,7 +782,8 @@
 ``10**-2`` returns ``0.01``.
 
 Raising ``0.0`` to a negative power results in a :exc:`ZeroDivisionError`.
-Raising a negative number to a fractional power results in a :exc:`ValueError`.
+Raising a negative number to a fractional power results in a :class:`complex`
+number. (In earlier versions it raised a :exc:`ValueError`.)
 
 
 .. _unary:
@@ -781,9 +793,9 @@
 
 .. index::
    triple: unary; arithmetic; operation
-   triple: unary; bit-wise; operation
+   triple: unary; bitwise; operation
 
-All unary arithmetic (and bit-wise) operations have the same priority:
+All unary arithmetic (and bitwise) operations have the same priority:
 
 .. productionlist::
    u_expr: `power` | "-" `u_expr` | "+" `u_expr` | "~" `u_expr`
@@ -800,9 +812,10 @@
 
 .. index:: single: inversion
 
-The unary ``~`` (invert) operator yields the bit-wise inversion of its integer
-argument.  The bit-wise inversion of ``x`` is defined as ``-(x+1)``.  It only
-applies to integral numbers.
+
+The unary ``~`` (invert) operator yields the bitwise inversion of its plain or
+long integer argument.  The bitwise inversion of ``x`` is defined as
+``-(x+1)``.  It only applies to integral numbers.
 
 .. index:: exception: TypeError
 
@@ -907,10 +920,10 @@
 
 .. _bitwise:
 
-Binary bit-wise operations
-==========================
+Binary bitwise operations
+=========================
 
-.. index:: triple: binary; bit-wise; operation
+.. index:: triple: binary; bitwise; operation
 
 Each of the three bitwise operations has a different priority level:
 
@@ -919,20 +932,20 @@
    xor_expr: `and_expr` | `xor_expr` "^" `and_expr`
    or_expr: `xor_expr` | `or_expr` "|" `xor_expr`
 
-.. index:: pair: bit-wise; and
+.. index:: pair: bitwise; and
 
 The ``&`` operator yields the bitwise AND of its arguments, which must be
 integers.
 
 .. index::
-   pair: bit-wise; xor
+   pair: bitwise; xor
    pair: exclusive; or
 
 The ``^`` operator yields the bitwise XOR (exclusive OR) of its arguments, which
 must be integers.
 
 .. index::
-   pair: bit-wise; or
+   pair: bitwise; or
    pair: inclusive; or
 
 The ``|`` operator yields the bitwise (inclusive) OR of its arguments, which
@@ -940,6 +953,10 @@
 
 
 .. _comparisons:
+.. _is:
+.. _isnot:
+.. _in:
+.. _notin:
 
 Comparisons
 ===========
@@ -1061,6 +1078,9 @@
 
 
 .. _booleans:
+.. _and:
+.. _or:
+.. _not:
 
 Boolean operations
 ==================
@@ -1273,7 +1293,9 @@
 .. [#] While comparisons between strings make sense at the byte level, they may
    be counter-intuitive to users.  For example, the strings ``"\u00C7"`` and
    ``"\u0327\u0043"`` compare differently, even though they both represent the
-   same unicode character (LATIN CAPTITAL LETTER C WITH CEDILLA).
+   same unicode character (LATIN CAPTITAL LETTER C WITH CEDILLA).  To compare
+   strings in a human recognizable way, compare using
+   :func:`unicodedata.normalize`.
 
 .. [#] The implementation computes this efficiently, without constructing lists
    or sorting.

Modified: python/branches/py3k-importlib/Doc/reference/index.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/reference/index.rst	(original)
+++ python/branches/py3k-importlib/Doc/reference/index.rst	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 interfaces available to C/C++ programmers in detail.
 
 .. toctree::
-   :maxdepth: 3
+   :maxdepth: 2
 
    introduction.rst
    lexical_analysis.rst

Modified: python/branches/py3k-importlib/Doc/reference/introduction.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/reference/introduction.rst	(original)
+++ python/branches/py3k-importlib/Doc/reference/introduction.rst	Thu Mar 27 00:48:05 2008
@@ -58,9 +58,9 @@
 
 Python for .NET
    This implementation actually uses the CPython implementation, but is a managed
-   .NET application and makes .NET libraries available.  This was created by Brian
+   .NET application and makes .NET libraries available.  It was created by Brian
    Lloyd.  For more information, see the `Python for .NET home page
-   <http://www.zope.org/Members/Brian/PythonNet>`_.
+   <http://pythonnet.sourceforge.net>`_.
 
 IronPython
    An alternate Python for .NET.  Unlike Python.NET, this is a complete Python

Modified: python/branches/py3k-importlib/Doc/reference/lexical_analysis.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/reference/lexical_analysis.rst	(original)
+++ python/branches/py3k-importlib/Doc/reference/lexical_analysis.rst	Thu Mar 27 00:48:05 2008
@@ -100,8 +100,7 @@
 encoding is used for all lexical analysis, including string literals, comments
 and identifiers. The encoding declaration must appear on a line of its own.
 
-A list of standard encodings can be found in the section
-:ref:`standard-encodings`.
+.. XXX there should be a list of supported encodings.
 
 
 .. _explicit-joining:
@@ -286,10 +285,8 @@
 
 .. productionlist::
    identifier: `id_start` `id_continue`*
-   id_start: <all characters in general categories Lu, Ll, Lt, Lm, Lo, Nl,
-              the underscore, and characters with the Other_ID_Start property>
-   id_continue: <all characters in `id_start`, plus characters in the categories
-                 Mn, Mc, Nd, Pc and others with the Other_ID_Continue property>
+   id_start: <all characters in general categories Lu, Ll, Lt, Lm, Lo, Nl, the underscore, and characters with the Other_ID_Start property>
+   id_continue: <all characters in `id_start`, plus characters in the categories Mn, Mc, Nd, Pc and others with the Other_ID_Continue property>
 
 The Unicode category codes mentioned above stand for:
 
@@ -311,6 +308,8 @@
 4.1 can be found at
 http://www.dcl.hpi.uni-potsdam.de/home/loewis/table-3131.html.
 
+See :pep:`3131` for further details.
+
 .. _keywords:
 
 Keywords
@@ -344,7 +343,7 @@
 ``_*``
    Not imported by ``from module import *``.  The special identifier ``_`` is used
    in the interactive interpreter to store the result of the last evaluation; it is
-   stored in the :mod:`__builtin__` module.  When not in interactive mode, ``_``
+   stored in the :mod:`builtins` module.  When not in interactive mode, ``_``
    has no special meaning and is not defined. See section :ref:`import`.
 
    .. note::
@@ -503,7 +502,7 @@
 
 (4)
    Individual code units which form parts of a surrogate pair can be encoded using
-   this escape sequence.
+   this escape sequence. Unlike in Standard C, exactly two hex digits are required.
 
 (5)
    Any Unicode character can be encoded this way, but characters outside the Basic
@@ -567,12 +566,12 @@
 Numeric literals
 ----------------
 
-.. index:: number, numeric literal, integer literal, plain integer literal
-   long integer literal, floating point literal, hexadecimal literal
+.. index:: number, numeric literal, integer literal
+   floating point literal, hexadecimal literal
    octal literal, binary literal, decimal literal, imaginary literal, complex literal
 
-There are four types of numeric literals: plain integers, long integers,
-floating point numbers, and imaginary numbers.  There are no complex literals
+There are three types of numeric literals: plain integers, floating point
+numbers, and imaginary numbers.  There are no complex literals
 (complex numbers can be formed by adding a real number and an imaginary number).
 
 Note that numeric literals do not include a sign; a phrase like ``-1`` is

Modified: python/branches/py3k-importlib/Doc/reference/simple_stmts.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/reference/simple_stmts.rst	(original)
+++ python/branches/py3k-importlib/Doc/reference/simple_stmts.rst	Thu Mar 27 00:48:05 2008
@@ -33,7 +33,9 @@
 Expression statements
 =====================
 
-.. index:: pair: expression; statement
+.. index::
+   pair: expression; statement
+   pair: expression; list
 .. index:: pair: expression; list
 
 Expression statements are used (mostly interactively) to compute and write a
@@ -143,6 +145,19 @@
   count for the object previously bound to the name to reach zero, causing the
   object to be deallocated and its destructor (if it has one) to be called.
 
+  .. index:: single: destructor
+
+  The name is rebound if it was already bound.  This may cause the reference count
+  for the object previously bound to the name to reach zero, causing the object to
+  be deallocated and its destructor (if it has one) to be called.
+
+* If the target is a target list enclosed in parentheses or in square brackets:
+  The object must be a sequence with the same number of items as there are targets
+  in the target list, and its items are assigned, from left to right, to the
+  corresponding targets.
+
+  .. index:: pair: attribute; assignment
+
 * If the target is an attribute reference: The primary expression in the
   reference is evaluated.  It should yield an object with assignable attributes;
   if this is not the case, :exc:`TypeError` is raised.  That object is then
@@ -290,22 +305,22 @@
 The extended form, ``assert expression1, expression2``, is equivalent to ::
 
    if __debug__:
-      if not expression1: raise AssertionError, expression2
+      if not expression1: raise AssertionError(expression2)
 
 .. index::
    single: __debug__
    exception: AssertionError
 
-These equivalences assume that ``__debug__`` and :exc:`AssertionError` refer to
+These equivalences assume that :const:`__debug__` and :exc:`AssertionError` refer to
 the built-in variables with those names.  In the current implementation, the
-built-in variable ``__debug__`` is ``True`` under normal circumstances,
+built-in variable :const:`__debug__` is ``True`` under normal circumstances,
 ``False`` when optimization is requested (command line option -O).  The current
 code generator emits no code for an assert statement when optimization is
 requested at compile time.  Note that it is unnecessary to include the source
 code for the expression that failed in the error message; it will be displayed
 as part of the stack trace.
 
-Assignments to ``__debug__`` are illegal.  The value for the built-in variable
+Assignments to :const:`__debug__` are illegal.  The value for the built-in variable
 is determined when the interpreter starts.
 
 
@@ -314,7 +329,9 @@
 The :keyword:`pass` statement
 =============================
 
-.. index:: statement: pass
+.. index::
+   statement: pass
+   pair: null; operation
            pair: null; operation
 
 .. productionlist::
@@ -334,9 +351,10 @@
 The :keyword:`del` statement
 ============================
 
-.. index:: statement: del
-           pair: deletion; target
-           triple: deletion; target; list
+.. index::
+   statement: del
+   pair: deletion; target
+   triple: deletion; target; list
 
 .. productionlist::
    del_stmt: "del" `target_list`
@@ -373,9 +391,10 @@
 The :keyword:`return` statement
 ===============================
 
-.. index:: statement: return
-           pair: function; definition
-           pair: class; definition
+.. index::
+   statement: return
+   pair: function; definition
+   pair: class; definition
 
 .. productionlist::
    return_stmt: "return" [`expression_list`]
@@ -405,23 +424,34 @@
 The :keyword:`yield` statement
 ==============================
 
+.. index::
+   statement: yield
+   single: generator; function
+   single: generator; iterator
+   single: function; generator
+   exception: StopIteration
+
 .. productionlist::
    yield_stmt: `yield_expression`
 
-The yield statement is nothing but a yield expression used as a statement,
-see :ref:`yieldexpr`.
-
+The :keyword:`yield` statement is only used when defining a generator function,
+and is only used in the body of the generator function. Using a :keyword:`yield`
+statement in a function definition is sufficient to cause that definition to
+create a generator function instead of a normal function.
+>>>>>>> .merge-right.r59773
 
 .. _raise:
 
 The :keyword:`raise` statement
 ==============================
 
-.. index:: statement: raise
-           pair: raising; exception
+.. index::
+   statement: raise
+   single: exception
+   pair: raising; exception
 
 .. productionlist::
-   raise_stmt: "raise" [`expression` ["from" `expression`]]
+   raise_stmt: "raise" [`expression` ["," `expression` ["," `expression`]]]
 
 If no expressions are present, :keyword:`raise` re-raises the last exception
 that was active in the current scope.  If no exception is active in the current
@@ -463,10 +493,11 @@
 The :keyword:`break` statement
 ==============================
 
-.. index:: statement: break
-           statement: for
-           statement: while
-           pair: loop; statement
+.. index::
+   statement: break
+   statement: for
+   statement: while
+   pair: loop; statement
 
 .. productionlist::
    break_stmt: "break"
@@ -496,22 +527,28 @@
 The :keyword:`continue` statement
 =================================
 
-.. index:: statement: continue
-           statement: for
-           statement: while
-           pair: loop; statement
-           keyword: finally
+.. index::
+   statement: continue
+   statement: for
+   statement: while
+   pair: loop; statement
+   keyword: finally
 
 .. productionlist::
    continue_stmt: "continue"
 
 :keyword:`continue` may only occur syntactically nested in a :keyword:`for` or
 :keyword:`while` loop, but not nested in a function or class definition or
-:keyword:`finally` statement within that loop. [#]_ It continues with the next
+:keyword:`finally` clause within that loop.  It continues with the next
 cycle of the nearest enclosing loop.
 
+When :keyword:`continue` passes control out of a :keyword:`try` statement with a
+:keyword:`finally` clause, that :keyword:`finally` clause is executed before
+really starting the next loop cycle.
+
 
 .. _import:
+.. _from:
 
 The :keyword:`import` statement
 ===============================
@@ -617,6 +654,7 @@
 
 .. index::
    keyword: from
+   statement: from
    triple: hierarchical; module; names
    single: packages
    single: __init__.py
@@ -717,13 +755,13 @@
 The :keyword:`global` statement
 ===============================
 
-.. index:: statement: global
+.. index::
+   statement: global
+   triple: global; name; binding
 
 .. productionlist::
    global_stmt: "global" `identifier` ("," `identifier`)*
 
-.. index:: triple: global; name; binding
-
 The :keyword:`global` statement is a declaration which holds for the entire
 current code block.  It means that the listed identifiers are to be interpreted
 as globals.  It would be impossible to assign to a global variable without
@@ -765,12 +803,36 @@
 .. productionlist::
    nonlocal_stmt: "nonlocal" `identifier` ("," `identifier`)*
 
-XXX: To be documented.
+.. XXX add when implemented
+                : ["=" (`target_list` "=")+ `expression_list`]
+                : | "nonlocal" `identifier` `augop` `expression_list`
+
+The :keyword:`nonlocal` statement causes the listed identifiers to refer to 
+previously bound variables in the nearest enclosing scope.  This is important 
+because the default behavior for binding is to search the local namespace 
+first.  The statement allows encapsulated code to rebind variables outside of
+the local scope besides the global (module) scope.
+
+.. XXX not implemented
+   The :keyword:`nonlocal` statement may prepend an assignment or augmented
+   assignment, but not an expression.
+
+Names listed in a :keyword:`nonlocal` statement, unlike to those listed in a
+:keyword:`global` statement, must refer to pre-existing bindings in an
+enclosing scope (the scope in which a new binding should be created cannot
+be determined unambiguously).
+
+Names listed in a :keyword:`nonlocal` statement must not collide with 
+pre-existing bindings in the local scope.
+
+.. seealso::
+
+   :pep:`3104` - Access to Names in Outer Scopes
+      The specification for the :keyword:`nonlocal` statement.
 
 
 .. rubric:: Footnotes
 
 .. [#] It may occur within an :keyword:`except` or :keyword:`else` clause.  The
-   restriction on occurring in the :keyword:`try` clause is implementor's laziness
-   and will eventually be lifted.
-
+   restriction on occurring in the :keyword:`try` clause is implementor's
+   laziness and will eventually be lifted.

Modified: python/branches/py3k-importlib/Doc/reference/toplevel_components.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/reference/toplevel_components.rst	(original)
+++ python/branches/py3k-importlib/Doc/reference/toplevel_components.rst	Thu Mar 27 00:48:05 2008
@@ -23,13 +23,13 @@
 .. index::
    module: sys
    module: __main__
-   module: __builtin__
+   module: builtins
 
 While a language specification need not prescribe how the language interpreter
 is invoked, it is useful to have a notion of a complete Python program.  A
 complete Python program is executed in a minimally initialized environment: all
 built-in and standard modules are available, but none have been initialized,
-except for :mod:`sys` (various system services), :mod:`__builtin__` (built-in
+except for :mod:`sys` (various system services), :mod:`builtins` (built-in
 functions, exceptions and ``None``) and :mod:`__main__`.  The latter is used to
 provide the local and global namespace for execution of the complete program.
 

Modified: python/branches/py3k-importlib/Doc/tools/sphinx-build.py
==============================================================================
--- python/branches/py3k-importlib/Doc/tools/sphinx-build.py	(original)
+++ python/branches/py3k-importlib/Doc/tools/sphinx-build.py	Thu Mar 27 00:48:05 2008
@@ -11,11 +11,12 @@
 
 if __name__ == '__main__':
 
-    if not (2, 5, 1) <= sys.version_info[:3] < (3, 0, 0):
+    if sys.version_info[:3] < (2, 4, 0):
         sys.stderr.write("""\
-Error: Sphinx needs to be executed with Python 2.5.1 or newer (not 3.0 though).
-If you run this from the Makefile, you can set the PYTHON variable to the path
-of an alternative interpreter executable, e.g., ``make html PYTHON=python2.5``.)
+Error: Sphinx needs to be executed with Python 2.4 or newer (not 3.0 though).
+(If you run this from the Makefile, you can set the PYTHON variable
+to the path of an alternative interpreter executable, e.g.,
+``make html PYTHON=python2.5``).
 """)
         sys.exit(1)
 

Modified: python/branches/py3k-importlib/Doc/tutorial/appetite.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/appetite.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/appetite.rst	Thu Mar 27 00:48:05 2008
@@ -75,8 +75,6 @@
 more detail.  Since the best way to learn a language is to use it, the tutorial
 invites you to play with the Python interpreter as you read.
 
-.. % \section{Where From Here \label{where}}
-
 In the next chapter, the mechanics of using the interpreter are explained.  This
 is rather mundane information, but essential for trying out the examples shown
 later.

Modified: python/branches/py3k-importlib/Doc/tutorial/classes.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/classes.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/classes.rst	Thu Mar 27 00:48:05 2008
@@ -98,7 +98,7 @@
 invocation of the interpreter, either read from a script file or interactively,
 are considered part of a module called :mod:`__main__`, so they have their own
 global namespace.  (The built-in names actually also live in a module; this is
-called :mod:`__builtin__`.)
+called :mod:`builtins`.)
 
 The local namespace for a function is created when the function is called, and
 deleted when the function returns or raises an exception that is not handled
@@ -124,6 +124,8 @@
 a variable will simply create a *new* local variable in the innermost scope,
 leaving the identically named outer variable unchanged).
 
+.. XXX mention nonlocal
+
 Usually, the local scope references the local names of the (textually) current
 function.  Outside functions, the local scope references the same namespace as
 the global scope: the module's namespace. Class definitions place yet another
@@ -137,14 +139,65 @@
 time, so don't rely on dynamic name resolution!  (In fact, local variables are
 already determined statically.)
 
-A special quirk of Python is that assignments always go into the innermost
-scope.  Assignments do not copy data --- they just bind names to objects.  The
-same is true for deletions: the statement ``del x`` removes the binding of ``x``
-from the namespace referenced by the local scope.  In fact, all operations that
-introduce new names use the local scope: in particular, import statements and
-function definitions bind the module or function name in the local scope.  (The
-:keyword:`global` statement can be used to indicate that particular variables
-live in the global scope.)
+A special quirk of Python is that -- if no :keyword:`global` or
+:keyword:`nonlocal` statement is in effect -- assignments to names always go
+into the innermost scope.  Assignments do not copy data --- they just bind names
+to objects.  The same is true for deletions: the statement ``del x`` removes the
+binding of ``x`` from the namespace referenced by the local scope.  In fact, all
+operations that introduce new names use the local scope: in particular, import
+statements and function definitions bind the module or function name in the
+local scope.  (The :keyword:`global` statement can be used to indicate that
+particular variables live in the global scope.)
+
+The :keyword:`global` statement can be used to indicate that particular
+variables live in the global scope and should be rebound there; the
+:keyword:`nonlocal` statement indicates that particular variables live in
+an enclosing scope and should be rebound there.
+
+.. _tut-scopeexample:
+
+Scopes and Namespaces Example
+-----------------------------
+
+This is an example demonstrating how to reference the different scopes and
+namespaces, and how :keyword:`global` and :keyword:`nonlocal` affect variable
+binding::
+
+   def scope_test():
+       def do_local():
+           spam = "local spam"
+       def do_nonlocal():
+           nonlocal spam
+           spam = "nonlocal spam"
+       def do_global():
+           global spam
+           spam = "global spam"
+   
+       spam = "test spam"
+       do_local()
+       print("After local assignment:", spam)
+       do_nonlocal()
+       print("After nonlocal assignment:", spam)
+       do_global()
+       print("After global assignment:", spam)
+
+   scope_test()
+   print("In global scope:", spam)
+
+The output of the example code is::
+
+   After local assignment: test spam
+   After nonlocal assignment: nonlocal spam
+   After global assignment: nonlocal spam
+   In global scope: global spam
+
+Note how the *local* assignment (which is default) didn't change *scope_test*\'s
+binding of *spam*.  The :keyword:`nonlocal` assignment changed *scope_test*\'s
+binding of *spam*, and the :keyword:`global` assignment changed the module-level
+binding.
+
+You can also see that there was no previous binding for *spam* before the
+:keyword:`global` assignment.
 
 
 .. _tut-firstclasses:
@@ -342,7 +395,7 @@
 Random Remarks
 ==============
 
-.. % [These should perhaps be placed more carefully...]
+.. These should perhaps be placed more carefully...
 
 Data attributes override method attributes with the same name; to avoid
 accidental name conflicts, which may cause hard-to-find bugs in large programs,
@@ -418,6 +471,9 @@
 defined in this global scope, and in the next section we'll find some good
 reasons why a method would want to reference its own class!
 
+Each value is an object, and therefore has a *class* (also called its *type*).
+It is stored as ``object.__class__``.
+
 
 .. _tut-inheritance:
 
@@ -458,7 +514,7 @@
 have no special privileges when calling other methods of the same object, a
 method of a base class that calls another method defined in the same base class
 may end up calling a method of a derived class that overrides it.  (For C++
-programmers: all methods in Python are effectively :keyword:`virtual`.)
+programmers: all methods in Python are effectively ``virtual``.)
 
 An overriding method in a derived class may in fact want to extend rather than
 simply replace the base class method of the same name. There is a simple way to
@@ -467,6 +523,19 @@
 only works if the base class is defined or imported directly in the global
 scope.)
 
+Python has two builtin functions that work with inheritance:
+
+* Use :func:`isinstance` to check an object's type: ``isinstance(obj, int)``
+  will be ``True`` only if ``obj.__class__`` is :class:`int` or some class
+  derived from :class:`int`.
+
+* Use :func:`issubclass` to check class inheritance: ``issubclass(bool, int)``
+  is ``True`` since :class:`bool` is a subclass of :class:`int`.  However,
+  ``issubclass(unicode, str)`` is ``False`` since :class:`unicode` is not a
+  subclass of :class:`str` (they only share a common ancestor,
+  :class:`basestring`).
+  
+
 
 .. _tut-multiple:
 
@@ -497,7 +566,7 @@
 single-inheritance languages.
 
 Dynamic ordering is necessary because all cases of multiple inheritance exhibit
-one or more diamond relationships (where one at least one of the parent classes
+one or more diamond relationships (where at least one of the parent classes
 can be accessed through multiple paths from the bottommost class).  For example,
 all classes inherit from :class:`object`, so any case of multiple inheritance
 provides more than one path to reach :class:`object`.  To keep the base classes
@@ -569,15 +638,13 @@
 can define a class with methods :meth:`read` and :meth:`readline` that get the
 data from a string buffer instead, and pass it as an argument.
 
-.. % (Unfortunately, this
-.. % technique has its limitations: a class can't define operations that
-.. % are accessed by special syntax such as sequence subscripting or
-.. % arithmetic operators, and assigning such a ``pseudo-file'' to
-.. % \code{sys.stdin} will not cause the interpreter to read further input
-.. % from it.)
+.. (Unfortunately, this technique has its limitations: a class can't define
+   operations that are accessed by special syntax such as sequence subscripting
+   or arithmetic operators, and assigning such a "pseudo-file" to sys.stdin will
+   not cause the interpreter to read further input from it.)
 
-Instance method objects have attributes, too: ``m.im_self`` is the instance
-object with the method :meth:`m`, and ``m.im_func`` is the function object
+Instance method objects have attributes, too: ``m.__self__`` is the instance
+object with the method :meth:`m`, and ``m.__func__`` is the function object
 corresponding to the method.
 
 
@@ -707,12 +774,12 @@
 Generators
 ==========
 
-Generators are a simple and powerful tool for creating iterators.  They are
-written like regular functions but use the :keyword:`yield` statement whenever
-they want to return data.  Each time :func:`next` is called on it, the generator
-resumes where it left-off (it remembers all the data values and which statement
-was last executed).  An example shows that generators can be trivially easy to
-create::
+:term:`Generator`\s are a simple and powerful tool for creating iterators.  They
+are written like regular functions but use the :keyword:`yield` statement
+whenever they want to return data.  Each time :func:`next` is called on it, the
+generator resumes where it left-off (it remembers all the data values and which
+statement was last executed).  An example shows that generators can be trivially
+easy to create::
 
    def reverse(data):
        for index in range(len(data)-1, -1, -1):
@@ -765,7 +832,7 @@
    260
 
    >>> from math import pi, sin
-   >>> sine_table = dict((x, sin(x*pi/180)) for x in range(0, 91))
+   >>> sine_table = {x: sin(x*pi/180) for x in range(0, 91)}
 
    >>> unique_words = set(word  for line in page  for word in line.split())
 

Modified: python/branches/py3k-importlib/Doc/tutorial/controlflow.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/controlflow.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/controlflow.rst	Thu Mar 27 00:48:05 2008
@@ -31,11 +31,8 @@
 There can be zero or more :keyword:`elif` parts, and the :keyword:`else` part is
 optional.  The keyword ':keyword:`elif`' is short for 'else if', and is useful
 to avoid excessive indentation.  An  :keyword:`if` ... :keyword:`elif` ...
-:keyword:`elif` ... sequence is a substitute for the :keyword:`switch` or
-:keyword:`case` statements found in other languages.
-
-.. % Weird spacings happen here if the wrapping of the source text
-.. % gets changed in the wrong way.
+:keyword:`elif` ... sequence is a substitute for the ``switch`` or
+``case`` statements found in other languages.
 
 
 .. _tut-for:
@@ -53,8 +50,8 @@
 iterates over the items of any sequence (a list or a string), in the order that
 they appear in the sequence.  For example (no pun intended):
 
-.. % One suggestion was to give a real C example here, but that may only
-.. % serve to confuse non-C programmers.
+.. One suggestion was to give a real C example here, but that may only serve to
+   confuse non-C programmers.
 
 ::
 
@@ -238,10 +235,11 @@
 The *execution* of a function introduces a new symbol table used for the local
 variables of the function.  More precisely, all variable assignments in a
 function store the value in the local symbol table; whereas variable references
-first look in the local symbol table, then in the global symbol table, and then
-in the table of built-in names. Thus,  global variables cannot be directly
-assigned a value within a function (unless named in a :keyword:`global`
-statement), although they may be referenced.
+first look in the local symbol table, then in the local symbol tables of
+enclosing functions, then in the global symbol table, and finally in the table
+of built-in names. Thus, global variables cannot be directly assigned a value
+within a function (unless named in a :keyword:`global` statement), although they
+may be referenced.
 
 The actual parameters (arguments) to a function call are introduced in the local
 symbol table of the called function when it is called; thus, arguments are
@@ -266,8 +264,9 @@
 technically speaking, procedures do return a value, albeit a rather boring one.
 This value is called ``None`` (it's a built-in name).  Writing the value
 ``None`` is normally suppressed by the interpreter if it would be the only value
-written.  You can see it if you really want to::
+written.  You can see it if you really want to using :func:`print`::
 
+   >>> fib(0)
    >>> print(fib(0))
    None
 
@@ -459,10 +458,9 @@
    shopkeeper : Michael Palin
    sketch : Cheese Shop Sketch
 
-Note that the :meth:`sort` method of the list of keyword argument names is
-called before printing the contents of the ``keywords`` dictionary; if this is
-not done, the order in which the arguments are printed is undefined.
-
+Note that the list of keyword argument names is created by sorting the result
+of the keywords dictionary's ``keys()`` method before printing its contents;
+if this is not done, the order in which the arguments are printed is undefined.
 
 .. _tut-arbitraryargs:
 
@@ -598,10 +596,57 @@
        No, really, it doesn't do anything.
 
 
+.. _tut-codingstyle:
+
+Intermezzo: Coding Style
+========================
+
+.. sectionauthor:: Georg Brandl <georg at python.org>
+.. index:: pair: coding; style
+
+Now that you are about to write longer, more complex pieces of Python, it is a
+good time to talk about *coding style*.  Most languages can be written (or more
+concise, *formatted*) in different styles; some are more readable than others.
+Making it easy for others to read your code is always a good idea, and adopting
+a nice coding style helps tremendously for that.
+
+For Python, :pep:`8` has emerged as the style guide that most projects adher to;
+it promotes a very readable and eye-pleasing coding style.  Every Python
+developer should read it at some point; here are the most important points
+extracted for you:
+
+* Use 4-space indentation, and no tabs.
+
+  4 spaces are a good compromise between small indentation (allows greater
+  nesting depth) and large indentation (easier to read).  Tabs introduce
+  confusion, and are best left out.
+
+* Wrap lines so that they don't exceed 79 characters.
+
+  This helps users with small displays and makes it possible to have several
+  code files side-by-side on larger displays.
+
+* Use blank lines to separate functions and classes, and larger blocks of
+  code inside functions.
+
+* When possible, put comments on a line of their own.
+
+* Use docstrings.
+
+* Use spaces around operators and after commas, but not directly inside
+  bracketing constructs: ``a = f(1, 2) + g(3, 4)``.
+
+* Name your classes and functions consistently; the convention is to use
+  ``CamelCase`` for classes and ``lower_case_with_underscores`` for functions
+  and methods.  Always use ``self`` as the name for the first method argument.
+
+* Don't use fancy encodings if your code is meant to be used in international
+  environments.  Plain ASCII works best in any case.
+
 
 .. rubric:: Footnotes
 
-.. [#] Actually, *call by object reference* would be a better description, since if a
-   mutable object is passed, the caller will see any changes the callee makes to it
-   (items inserted into a list).
+.. [#] Actually, *call by object reference* would be a better description,
+   since if a mutable object is passed, the caller will see any changes the
+   callee makes to it (items inserted into a list).
 

Modified: python/branches/py3k-importlib/Doc/tutorial/datastructures.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/datastructures.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/datastructures.rst	Thu Mar 27 00:48:05 2008
@@ -83,17 +83,20 @@
 
 
 .. method:: list.append(x)
+   :noindex:
 
    Add an item to the end of the list; equivalent to ``a[len(a):] = [x]``.
 
 
 .. method:: list.extend(L)
+   :noindex:
 
    Extend the list by appending all the items in the given list; equivalent to
    ``a[len(a):] = L``.
 
 
 .. method:: list.insert(i, x)
+   :noindex:
 
    Insert an item at a given position.  The first argument is the index of the
    element before which to insert, so ``a.insert(0, x)`` inserts at the front of
@@ -101,12 +104,14 @@
 
 
 .. method:: list.remove(x)
+   :noindex:
 
    Remove the first item from the list whose value is *x*. It is an error if there
    is no such item.
 
 
 .. method:: list.pop([i])
+   :noindex:
 
    Remove the item at the given position in the list, and return it.  If no index
    is specified, ``a.pop()`` removes and returns the last item in the list.  (The
@@ -116,22 +121,26 @@
 
 
 .. method:: list.index(x)
+   :noindex:
 
    Return the index in the list of the first item whose value is *x*. It is an
    error if there is no such item.
 
 
 .. method:: list.count(x)
+   :noindex:
 
    Return the number of times *x* appears in the list.
 
 
 .. method:: list.sort()
+   :noindex:
 
    Sort the items of the list, in place.
 
 
 .. method:: list.reverse()
+   :noindex:
 
    Reverse the elements of the list, in place.
 
@@ -273,10 +282,52 @@
 
 List comprehensions can be applied to complex expressions and nested functions::
 
-   >>> [str(round(355/113.0, i)) for i in range(1, 6)]
+   >>> [str(round(355/113, i)) for i in range(1, 6)]
    ['3.1', '3.14', '3.142', '3.1416', '3.14159']
 
 
+Nested List Comprehensions
+--------------------------
+
+If you've got the stomach for it, list comprehensions can be nested. They are a
+powerful tool but -- like all powerful tools -- they need to be used carefully,
+if at all.
+
+Consider the following example of a 3x3 matrix held as a list containing three 
+lists, one list per row::
+
+    >>> mat = [
+    ...        [1, 2, 3],
+    ...        [4, 5, 6],
+    ...        [7, 8, 9],
+    ...       ]
+
+Now, if you wanted to swap rows and columns, you could use a list 
+comprehension::
+
+    >>> print [[row[i] for row in mat] for i in [0, 1, 2]]
+    [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
+
+Special care has to be taken for the *nested* list comprehension:
+
+    To avoid apprehension when nesting list comprehensions, read from right to
+    left.
+
+A more verbose version of this snippet shows the flow explicitly::
+
+    for i in [0, 1, 2]:
+        for row in mat:
+            print row[i],
+        print
+
+In real world, you should prefer builtin functions to complex flow statements. 
+The :func:`zip` function would do a great job for this use case::
+
+    >>> zip(*mat)
+    [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
+
+See :ref:`tut-unpacking-arguments` for details on the asterisk in this line.
+
 .. _tut-del:
 
 The :keyword:`del` statement
@@ -308,6 +359,70 @@
 
 
 
+Tuples and Sequences
+====================
+
+We saw that lists and strings have many common properties, such as indexing and
+slicing operations.  They are two examples of *sequence* data types (see
+:ref:`typesseq`).  Since Python is an evolving language, other sequence data
+types may be added.  There is also another standard sequence data type: the
+*tuple*.
+
+A tuple consists of a number of values separated by commas, for instance::
+
+   >>> t = 12345, 54321, 'hello!'
+   >>> t[0]
+   12345
+   >>> t
+   (12345, 54321, 'hello!')
+   >>> # Tuples may be nested:
+   ... u = t, (1, 2, 3, 4, 5)
+   >>> u
+   ((12345, 54321, 'hello!'), (1, 2, 3, 4, 5))
+
+As you see, on output tuples are always enclosed in parentheses, so that nested
+tuples are interpreted correctly; they may be input with or without surrounding
+parentheses, although often parentheses are necessary anyway (if the tuple is
+part of a larger expression).
+
+Tuples have many uses.  For example: (x, y) coordinate pairs, employee records
+from a database, etc.  Tuples, like strings, are immutable: it is not possible
+to assign to the individual items of a tuple (you can simulate much of the same
+effect with slicing and concatenation, though).  It is also possible to create
+tuples which contain mutable objects, such as lists.
+
+A special problem is the construction of tuples containing 0 or 1 items: the
+syntax has some extra quirks to accommodate these.  Empty tuples are constructed
+by an empty pair of parentheses; a tuple with one item is constructed by
+following a value with a comma (it is not sufficient to enclose a single value
+in parentheses). Ugly, but effective.  For example::
+
+   >>> empty = ()
+   >>> singleton = 'hello',    # <-- note trailing comma
+   >>> len(empty)
+   0
+   >>> len(singleton)
+   1
+   >>> singleton
+   ('hello',)
+
+The statement ``t = 12345, 54321, 'hello!'`` is an example of *tuple packing*:
+the values ``12345``, ``54321`` and ``'hello!'`` are packed together in a tuple.
+The reverse operation is also possible::
+
+   >>> x, y, z = t
+
+This is called, appropriately enough, *sequence unpacking*. Sequence unpacking
+requires the list of variables on the left to have the same number of elements
+as the length of the sequence.  Note that multiple assignment is really just a
+combination of tuple packing and sequence unpacking!
+
+There is a small bit of asymmetry here:  packing multiple values always creates
+a tuple, and unpacking works for any sequence.
+
+.. XXX Add a bit on the difference between tuples and lists.
+
+
 .. _tut-sets:
 
 Sets
@@ -331,6 +446,9 @@
    >>> fruit = set(basket)               # create a set without duplicates
    >>> fruit
    {'orange', 'pear', 'apple', 'banana'}
+   >>> fruit = {'orange', 'apple'}       # {} syntax is equivalent to [] for lists
+   >>> fruit
+   {'orange', 'apple'}
    >>> 'orange' in fruit                 # fast membership testing
    True
    >>> 'crabgrass' in fruit
@@ -351,6 +469,11 @@
    >>> a ^ b                              # letters in a or b but not both
    {'r', 'd', 'b', 'm', 'z', 'l'}
 
+Like for lists, there is a set comprehension syntax::
+
+   >>> a = {x for x in 'abracadabra' if x not in 'abc'}
+   >>> a
+   {'r', 'd'}
 
 
 
@@ -412,12 +535,12 @@
 
    >>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
    {'sape': 4139, 'jack': 4098, 'guido': 4127}
-   >>> dict([(x, x**2) for x in (2, 4, 6)])     # use a list comprehension
-   {2: 4, 4: 16, 6: 36}
 
-Later in the tutorial, we will learn about Generator Expressions which are even
-better suited for the task of supplying key-values pairs to the :func:`dict`
-constructor.
+In addition, dict comprehensions can be used to create dictionaries from
+arbitrary key and value expressions::
+
+   >>> {x: x**2 for x in (2, 4, 6)}
+   {2: 4, 4: 16, 6: 36}
 
 When the keys are simple strings, it is sometimes easier to specify pairs using
 keyword arguments::
@@ -426,9 +549,8 @@
    {'sape': 4139, 'jack': 4098, 'guido': 4127}
 
 
+.. XXX Find out the right way to do these DUBOIS
 .. _tut-loopidioms:
-.. % 
-   Find out the right way to do these DUBOIS
 
 Looping Techniques
 ==================

Modified: python/branches/py3k-importlib/Doc/tutorial/errors.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/errors.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/errors.rst	Thu Mar 27 00:48:05 2008
@@ -131,8 +131,8 @@
        f = open('myfile.txt')
        s = f.readline()
        i = int(s.strip())
-   except IOError as e:
-       print("I/O error(%s): %s" % (e.errno, e.strerror))
+   except IOError as (errno, strerror):
+       print "I/O error(%s): %s" % (errno, strerror)
    except ValueError:
        print("Could not convert data to an integer.")
    except:

Modified: python/branches/py3k-importlib/Doc/tutorial/inputoutput.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/inputoutput.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/inputoutput.rst	Thu Mar 27 00:48:05 2008
@@ -180,11 +180,9 @@
 :func:`open` returns a file object, and is most commonly used with two
 arguments: ``open(filename, mode)``.
 
-.. % Opening files
-
 ::
 
-   >>> f=open('/tmp/workfile', 'w')
+   >>> f = open('/tmp/workfile', 'w')
    >>> print(f)
    <open file '/tmp/workfile', mode 'w' at 80a0960>
 
@@ -197,16 +195,15 @@
 writing. The *mode* argument is optional; ``'r'`` will be assumed if it's
 omitted.
 
-``'b'`` appended to the mode opens the file in binary mode, so there are
-also modes like ``'rb'``, ``'wb'``, and ``'r+b'``.  Python distinguishes
-between text and binary files.  Binary files are read and written without
-any data transformation.  In text mode, platform-specific newline
-representations are automatically converted to newlines when read and
-newline characters are automatically converted to the proper
-platform-specific representation when written.  This makes writing portable
-code which reads or writes text files easier.  In addition, when reading
-from or writing to text files, the data are automatically decoded or
-encoding, respectively, using the encoding associated with the file.
+On Windows and the Macintosh, ``'b'`` appended to the mode opens the file in
+binary mode, so there are also modes like ``'rb'``, ``'wb'``, and ``'r+b'``.
+Windows makes a distinction between text and binary files; the end-of-line
+characters in text files are automatically altered slightly when data is read or
+written.  This behind-the-scenes modification to file data is fine for ASCII
+text files, but it'll corrupt binary data like that in :file:`JPEG` or
+:file:`EXE` files.  Be very careful to use binary mode when reading and writing
+such files.  On Unix, it doesn't hurt to append a ``'b'`` to the mode, so
+you can use it platform-independently for all binary files.
 
 This behind-the-scenes modification to file data is fine for text files, but
 will corrupt binary data like that in :file:`JPEG` or :file:`EXE` files.  Be

Modified: python/branches/py3k-importlib/Doc/tutorial/interactive.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/interactive.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/interactive.rst	Thu Mar 27 00:48:05 2008
@@ -123,7 +123,7 @@
    # bound to the Esc key by default (you can change it - see readline docs).
    #
    # Store the file in ~/.pystartup, and set an environment variable to point
-   # to it:  "export PYTHONSTARTUP=/max/home/itamar/.pystartup" in bash.
+   # to it:  "export PYTHONSTARTUP=/home/user/.pystartup" in bash.
    #
    # Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the
    # full path to your home directory.

Modified: python/branches/py3k-importlib/Doc/tutorial/interpreter.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/interpreter.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/interpreter.rst	Thu Mar 27 00:48:05 2008
@@ -169,6 +169,12 @@
 
    $ chmod +x myscript.py
 
+On Windows systems, there is no notion of an "executable mode".  The Python
+installer automatically associates ``.py`` files with ``python.exe`` so that
+a double-click on a Python file will run it as a script.  The extension can
+also be ``.pyw``, in that case, the console window that normally appears is
+suppressed.
+
 
 Source Code Encoding
 --------------------
@@ -212,8 +218,8 @@
 file containing your start-up commands.  This is similar to the :file:`.profile`
 feature of the Unix shells.
 
-.. % XXX This should probably be dumped in an appendix, since most people
-.. % don't use Python interactively in non-trivial ways.
+.. XXX This should probably be dumped in an appendix, since most people
+   don't use Python interactively in non-trivial ways.
 
 This file is only read in interactive sessions, not when Python reads commands
 from a script, and not when :file:`/dev/tty` is given as the explicit source of

Modified: python/branches/py3k-importlib/Doc/tutorial/introduction.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/introduction.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/introduction.rst	Thu Mar 27 00:48:05 2008
@@ -13,9 +13,9 @@
 
 Many of the examples in this manual, even those entered at the interactive
 prompt, include comments.  Comments in Python start with the hash character,
-``'#'``, and extend to the end of the physical line.  A comment may appear at
+``#``, and extend to the end of the physical line.  A comment may appear at
 the start of a line or following whitespace or code, but not within a string
-literal.  A hash  character within a string literal is just a hash character.
+literal.  A hash character within a string literal is just a hash character.
 
 Some examples::
 
@@ -507,8 +507,9 @@
 
 The built-in function :func:`len` also applies to lists::
 
+   >>> a = ['a', 'b', 'c', 'd']
    >>> len(a)
-   8
+   4
 
 It is possible to nest lists (create lists containing other lists), for
 example::
@@ -547,8 +548,8 @@
    ... # the sum of two elements defines the next
    ... a, b = 0, 1
    >>> while b < 10:
-   ...       print(b)
-   ...       a, b = b, a+b
+   ...     print(b)
+   ...     a, b = b, a+b
    ... 
    1
    1
@@ -607,5 +608,3 @@
  Note that nothing appeared after the loop ended, until we printed
  a newline.
 
-
-

Modified: python/branches/py3k-importlib/Doc/tutorial/modules.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/modules.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/modules.rst	Thu Mar 27 00:48:05 2008
@@ -191,8 +191,8 @@
 * When the Python interpreter is invoked with the :option:`-O` flag, optimized
   code is generated and stored in :file:`.pyo` files.  The optimizer currently
   doesn't help much; it only removes :keyword:`assert` statements.  When
-  :option:`-O` is used, *all* bytecode is optimized; ``.pyc`` files are ignored
-  and ``.py`` files are compiled to optimized bytecode.
+  :option:`-O` is used, *all* :term:`bytecode` is optimized; ``.pyc`` files are
+  ignored and ``.py`` files are compiled to optimized bytecode.
 
 * Passing two :option:`-O` flags to the Python interpreter (:option:`-OO`) will
   cause the bytecode compiler to perform optimizations that could in some rare
@@ -223,11 +223,6 @@
 * The module :mod:`compileall` can create :file:`.pyc` files (or :file:`.pyo`
   files when :option:`-O` is used) for all modules in a directory.
 
-* If using Python in a parallel processing system with a shared file system,
-  you need to patch Python to disable the creation of the compiled files 
-  because otherwise the multiple Python interpreters will encounter race 
-  conditions in creating them.
-
 
 .. _tut-standardmodules:
 
@@ -246,11 +241,7 @@
 provided on Windows systems. One particular module deserves some attention:
 :mod:`sys`, which is built into every Python interpreter.  The variables
 ``sys.ps1`` and ``sys.ps2`` define the strings used as primary and secondary
-prompts:
-
-.. % 
-
-::
+prompts::
 
    >>> import sys
    >>> sys.ps1
@@ -308,14 +299,14 @@
 
 Note that it lists all types of names: variables, modules, functions, etc.
 
-.. index:: module: __builtin__
+.. index:: module: builtins
 
 :func:`dir` does not list the names of built-in functions and variables.  If you
 want a list of those, they are defined in the standard module
-:mod:`__builtin__`::
+:mod:`builtins`::
 
-   >>> import __builtin__
-   >>> dir(__builtin__)
+   >>> import builtins
+   >>> dir(builtins)
 
    ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'Buffer
    Error', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Excep   
@@ -455,8 +446,6 @@
 file names with a capitalized first letter.)  The DOS 8+3 filename restriction
 adds another interesting problem for long module names.
 
-.. % The \code{__all__} Attribute
-
 The only solution is for the package author to provide an explicit index of the
 package.  The import statement uses the following convention: if a package's
 :file:`__init__.py` code defines a list named ``__all__``, it is taken to be the

Modified: python/branches/py3k-importlib/Doc/tutorial/stdlib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/stdlib.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/stdlib.rst	Thu Mar 27 00:48:05 2008
@@ -121,7 +121,7 @@
 floating point math::
 
    >>> import math
-   >>> math.cos(math.pi / 4.0)
+   >>> math.cos(math.pi / 4)
    0.70710678118654757
    >>> math.log(1024, 2)
    10.0
@@ -264,7 +264,7 @@
        >>> print(average([20, 30, 70]))
        40.0
        """
-       return sum(values, 0.0) / len(values)
+       return sum(values) / len(values)
 
    import doctest
    doctest.testmod()   # automatically validate the embedded tests

Modified: python/branches/py3k-importlib/Doc/tutorial/stdlib2.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/stdlib2.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/stdlib2.rst	Thu Mar 27 00:48:05 2008
@@ -104,16 +104,11 @@
 renaming utility for a photo browser may elect to use percent signs for
 placeholders such as the current date, image sequence number, or file format::
 
-   >>> import time, os.path, sys
-   >>> def raw_input(prompt):
-   ...     sys.stdout.write(prompt)
-   ...     sys.stdout.flush()
-   ...     return sys.stdin.readline()
-   ... 
+   >>> import time, os.path
    >>> photofiles = ['img_1074.jpg', 'img_1076.jpg', 'img_1077.jpg']
    >>> class BatchRename(Template):
    ...     delimiter = '%'
-   >>> fmt = raw_input('Enter rename style (%d-date %n-seqnum %f-format):  ')
+   >>> fmt = input('Enter rename style (%d-date %n-seqnum %f-format):  ')
    Enter rename style (%d-date %n-seqnum %f-format):  Ashley_%n%f
 
    >>> t = BatchRename(fmt)
@@ -139,8 +134,10 @@
 
 The :mod:`struct` module provides :func:`pack` and :func:`unpack` functions for
 working with variable length binary record formats.  The following example shows
-how to loop through header information in a ZIP file (with pack codes ``"H"``
-and ``"L"`` representing two and four byte unsigned numbers respectively)::
+how to loop through header information in a ZIP file without using the
+:mod:`zipfile` module.  Pack codes ``"H"`` and ``"I"`` represent two and four
+byte unsigned numbers respectively.  The ``"<"`` indicates that they are
+standard size and in little-endian byte order::
 
    import struct
 
@@ -148,7 +145,7 @@
    start = 0
    for i in range(3):                      # show the first 3 file headers
        start += 14
-       fields = struct.unpack('LLLHH', data[start:start+16])
+       fields = struct.unpack('<IIIHH', data[start:start+16])
        crc32, comp_size, uncomp_size, filenamesize, extra_size = fields
 
        start += 16
@@ -244,8 +241,8 @@
 ===============
 
 Python does automatic memory management (reference counting for most objects and
-garbage collection to eliminate cycles).  The memory is freed shortly after the
-last reference to it has been eliminated.
+:term:`garbage collection` to eliminate cycles).  The memory is freed shortly
+after the last reference to it has been eliminated.
 
 This approach works fine for most applications but occasionally there is a need
 to track objects only as long as they are being used by something else.
@@ -272,7 +269,7 @@
    0
    >>> d['primary']                # entry was automatically removed
    Traceback (most recent call last):
-     File "<pyshell#108>", line 1, in -toplevel-
+     File "<stdin>", line 1, in <module>
        d['primary']                # entry was automatically removed
      File "C:/python30/lib/weakref.py", line 46, in __getitem__
        o = self.data[key]()

Modified: python/branches/py3k-importlib/Doc/tutorial/whatnow.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/whatnow.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/whatnow.rst	Thu Mar 27 00:48:05 2008
@@ -38,9 +38,9 @@
 
 * http://docs.python.org:  Fast access to Python's  documentation.
 
-* http://cheeseshop.python.org:  The Python Package Index, nicknamed the Cheese
-  Shop,  is an index of user-created Python modules that are available for
-  download.  Once you begin releasing code, you can register it  here so that
+* http://pypi.python.org: The Python Package Index, previously also nicknamed
+  the Cheese Shop, is an index of user-created Python modules that are available
+  for download.  Once you begin releasing code, you can register it here so that
   others can find it.
 
 * http://aspn.activestate.com/ASPN/Python/Cookbook/: The Python Cookbook is a
@@ -66,8 +66,8 @@
 many of the questions that come up again and again, and may already contain the
 solution for your problem.
 
-.. % Postings figure based on average of last six months activity as
-.. % reported by www.egroups.com; Jan. 2000 - June 2000: 21272 msgs / 182
-.. % days = 116.9 msgs / day and steadily increasing.
+.. Postings figure based on average of last six months activity as
+   reported by www.egroups.com; Jan. 2000 - June 2000: 21272 msgs / 182
+   days = 116.9 msgs / day and steadily increasing. (XXX up to date figures?) 
 
 

Modified: python/branches/py3k-importlib/Doc/whatsnew/2.0.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/whatsnew/2.0.rst	(original)
+++ python/branches/py3k-importlib/Doc/whatsnew/2.0.rst	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,7 @@
 
 .. |release| replace:: 1.02
 
-.. % $Id: whatsnew20.tex 51211 2006-08-11 14:57:12Z thomas.wouters $
+.. $Id: whatsnew20.tex 50964 2006-07-30 03:03:43Z fred.drake $
 
 
 Introduction
@@ -26,7 +26,7 @@
 paid to spend their days fixing bugs, and also due to the improved communication
 resulting  from moving to SourceForge.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 What About Python 1.6?
@@ -50,7 +50,7 @@
 features described in this document are only in 2.0, because a lot of work was
 done between May and September.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 New Development Process
@@ -134,7 +134,7 @@
 from PEP 201, "Lockstep Iteration", to PEP 225, "Elementwise/Objectwise
 Operators".
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Unicode
@@ -255,7 +255,7 @@
 used in testing and future-proofing your Python code, since some future version
 of Python may drop support for 8-bit strings and provide only Unicode strings.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 List Comprehensions
@@ -342,7 +342,7 @@
 was then discussed for a seemingly endless time on the python-dev mailing list
 and kept up-to-date by Skip Montanaro.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Augmented Assignment
@@ -360,7 +360,7 @@
 :class:`Number` class stores a number and supports using += to create a new
 instance with an incremented value.
 
-.. % The empty groups below prevent conversion to guillemets.
+.. The empty groups below prevent conversion to guillemets.
 
 ::
 
@@ -383,7 +383,7 @@
 and PHP also support them.  The augmented assignment patch was implemented by
 Thomas Wouters.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 String Methods
@@ -426,7 +426,7 @@
 module, with the arguments reversed. In other words, ``s.join(seq)`` is
 equivalent to the old ``string.join(seq, s)``.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Garbage Collection of Cycles
@@ -488,7 +488,7 @@
 the relevant discussion, especially in the threads titled "Reference cycle
 collection for Python" and "Finalization again".
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Other Core Changes
@@ -565,8 +565,8 @@
 :meth:`__cmp__` method encountered an error, since the resulting exception would
 simply be silently swallowed.
 
-.. % Starting URL:
-.. % http://www.python.org/pipermail/python-dev/2000-April/004834.html
+.. Starting URL:
+.. http://www.python.org/pipermail/python-dev/2000-April/004834.html
 
 Work has been done on porting Python to 64-bit Windows on the Itanium processor,
 mostly by Trent Mick of ActiveState.  (Confusingly, ``sys.platform`` is still
@@ -641,7 +641,7 @@
 value for a given platform can be found by running a new script,
 :file:`Misc/find_recursionlimit.py`.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Porting to 2.0
@@ -728,13 +728,13 @@
 exceptions was translated from Python to a built-in C module, written by Barry
 Warsaw and Fredrik Lundh.
 
-.. % Commented out for now -- I don't think anyone will care.
-.. % The pattern and match objects provided by SRE are C types, not Python
-.. % class instances as in 1.5.  This means you can no longer inherit from
-.. % \class{RegexObject} or \class{MatchObject}, but that shouldn't be much
-.. % of a problem since no one should have been doing that in the first
-.. % place.
-.. % ======================================================================
+.. Commented out for now -- I don't think anyone will care.
+   The pattern and match objects provided by SRE are C types, not Python
+   class instances as in 1.5.  This means you can no longer inherit from
+   \class{RegexObject} or \class{MatchObject}, but that shouldn't be much
+   of a problem since no one should have been doing that in the first
+   place.
+.. ======================================================================
 
 
 Extending/Embedding Changes
@@ -805,7 +805,7 @@
 A wrapper API was added for Unix-style signal handlers. :func:`PyOS_getsig` gets
 a signal handler and :func:`PyOS_setsig` will set a new handler.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Distutils: Making Modules Easy to Install
@@ -875,7 +875,7 @@
 All this is documented in a new manual, *Distributing Python Modules*, that
 joins the basic set of Python documentation.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 XML Modules
@@ -1024,7 +1024,7 @@
 
 * The :mod:`sgmlop` parser accelerator module, written by Fredrik Lundh.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Module changes
@@ -1069,7 +1069,7 @@
 partially funded by Hewlett Packard, supports matching against both 8-bit
 strings and Unicode strings.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 New modules
@@ -1145,7 +1145,7 @@
   import hooks, in comparison to the existing :mod:`ihooks` module.  (Implemented
   by Greg Stein, with much discussion on python-dev along the way.)
 
-.. % ======================================================================
+.. ======================================================================
 
 
 IDLE Improvements
@@ -1179,7 +1179,7 @@
 * Three new keystroke commands: Check module (Alt-F5), Import module (F5) and
   Run script (Ctrl-F5).
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Deleted and Deprecated Modules

Modified: python/branches/py3k-importlib/Doc/whatsnew/2.1.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/whatsnew/2.1.rst	(original)
+++ python/branches/py3k-importlib/Doc/whatsnew/2.1.rst	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,7 @@
 
 .. |release| replace:: 1.01
 
-.. % $Id: whatsnew21.tex 51211 2006-08-11 14:57:12Z thomas.wouters $
+.. $Id: whatsnew21.tex 50964 2006-07-30 03:03:43Z fred.drake $
 
 
 Introduction
@@ -29,7 +29,7 @@
 
 The final release of Python 2.1 was made on April 17, 2001.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 227: Nested Scopes
@@ -123,7 +123,7 @@
    :pep:`227` - Statically Nested Scopes
       Written and implemented by Jeremy Hylton.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 236: __future__ Directives
@@ -153,7 +153,7 @@
    :pep:`236` - Back to the :mod:`__future__`
       Written by Tim Peters, and primarily implemented by Jeremy Hylton.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 207: Rich Comparisons
@@ -223,7 +223,7 @@
       Written by Guido van Rossum, heavily based on earlier work by David Ascher, and
       implemented by Guido van Rossum.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 230: Warning Framework
@@ -295,7 +295,7 @@
    :pep:`230` - Warning Framework
       Written and implemented by Guido van Rossum.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 229: New Build System
@@ -335,7 +335,7 @@
    :pep:`229` - Using Distutils to Build Python
       Written and implemented by A.M. Kuchling.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 205: Weak References
@@ -416,7 +416,7 @@
    :pep:`205` - Weak References
       Written and implemented by Fred L. Drake, Jr.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 232: Function Attributes
@@ -454,7 +454,7 @@
    :pep:`232` - Function Attributes
       Written and implemented by Barry Warsaw.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 235: Importing Modules on Case-Insensitive Platforms
@@ -472,7 +472,7 @@
 insensitive matching can be requested by setting the :envvar:`PYTHONCASEOK`
 environment variable before starting the Python interpreter.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 217: Interactive Display Hook
@@ -502,7 +502,7 @@
    :pep:`217` - Display Hook for Interactive Use
       Written and implemented by Moshe Zadka.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 208: New Coercion Model
@@ -534,7 +534,7 @@
       Marc-André Lemburg.  Read this to understand the fine points of how numeric
       operations will now be processed at the C level.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 241: Metadata in Python Packages
@@ -574,7 +574,7 @@
       Written by Sean Reifschneider, this draft PEP describes a proposed mechanism for
       uploading  Python packages to a central server.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 New and Improved Modules
@@ -677,7 +677,7 @@
   implementation.  Use it for debugging, and resist the temptation to put it into
   production code.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Other Changes and Fixes
@@ -782,7 +782,7 @@
 edits, and other tweaks, too lengthy to be worth itemizing; see the CVS logs for
 the full details if you want them.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Acknowledgements

Modified: python/branches/py3k-importlib/Doc/whatsnew/2.2.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/whatsnew/2.2.rst	(original)
+++ python/branches/py3k-importlib/Doc/whatsnew/2.2.rst	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,7 @@
 
 .. |release| replace:: 1.02
 
-.. % $Id: whatsnew22.tex 37315 2004-09-10 19:33:00Z akuchling $
+.. $Id: whatsnew22.tex 37315 2004-09-10 19:33:00Z akuchling $
 
 
 Introduction
@@ -36,7 +36,7 @@
       "What's So Special About Python 2.2?" is also about the new 2.2 features, and
       was written by Cameron Laird and Kathryn Soraiz.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEPs 252 and 253: Type and Class Changes
@@ -414,7 +414,7 @@
 resort to it after all other avenues have been exhausted, including posting a
 question to python-list or python-dev.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 234: Iterators
@@ -535,7 +535,7 @@
       Written by Ka-Ping Yee and GvR; implemented  by the Python Labs crew, mostly by
       GvR and Tim Peters.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 255: Simple Generators
@@ -662,7 +662,7 @@
       Written by Neil Schemenauer, Tim Peters, Magnus Lie Hetland.  Implemented mostly
       by Neil Schemenauer and Tim Peters, with other fixes from the Python Labs crew.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 237: Unifying Long Integers and Integers
@@ -702,7 +702,7 @@
       Written by Moshe Zadka and Guido van Rossum.  Implemented mostly by Guido van
       Rossum.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 238: Changing the Division Operator
@@ -770,7 +770,7 @@
    :pep:`238` - Changing the Division Operator
       Written by Moshe Zadka and  Guido van Rossum.  Implemented by Guido van Rossum..
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Unicode Changes
@@ -832,7 +832,7 @@
    :pep:`261` - Support for 'wide' Unicode characters
       Written by Paul Prescod.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 227: Nested Scopes
@@ -927,7 +927,7 @@
    :pep:`227` - Statically Nested Scopes
       Written and implemented by Jeremy Hylton.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 New and Improved Modules
@@ -1042,7 +1042,7 @@
   scheduling an activity to happen at some future time.  (Contributed by Itamar
   Shtull-Trauring.)
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Interpreter Changes and Fixes
@@ -1122,7 +1122,7 @@
   takes 2 parameters instead of 3.  The third argument was never used, and can
   simply be discarded when porting code from earlier versions to Python 2.2.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Other Changes and Fixes
@@ -1155,23 +1155,23 @@
   left commented out in :file:`setup.py`.  People who want to experiment with
   these modules can uncomment them manually.
 
-  .. % Jack's original comments:
-  .. % The main change is the possibility to build Python as a
-  .. % framework. This installs a self-contained Python installation plus the
-  .. % OSX framework "glue" into /Library/Frameworks/Python.framework (or
-  .. % another location of choice). For now there is little immedeate added
-  .. % benefit to this (actually, there is the disadvantage that you have to
-  .. % change your PATH to be able to find Python), but it is the basis for
-  .. % creating a fullblown Python application, porting the MacPython IDE,
-  .. % possibly using Python as a standard OSA scripting language and much
-  .. % more. You enable this with "configure --enable-framework".
-  .. % The other change is that most MacPython toolbox modules, which
-  .. % interface to all the MacOS APIs such as windowing, quicktime,
-  .. % scripting, etc. have been ported. Again, most of these are not of
-  .. % immedeate use, as they need a full application to be really useful, so
-  .. % they have been commented out in setup.py. People wanting to experiment
-  .. % can uncomment them. Gestalt and Internet Config modules are enabled by
-  .. % default.
+  .. Jack's original comments:
+     The main change is the possibility to build Python as a
+     framework. This installs a self-contained Python installation plus the
+     OSX framework "glue" into /Library/Frameworks/Python.framework (or
+     another location of choice). For now there is little immedeate added
+     benefit to this (actually, there is the disadvantage that you have to
+     change your PATH to be able to find Python), but it is the basis for
+     creating a fullblown Python application, porting the MacPython IDE,
+     possibly using Python as a standard OSA scripting language and much
+     more. You enable this with "configure --enable-framework".
+     The other change is that most MacPython toolbox modules, which
+     interface to all the MacOS APIs such as windowing, quicktime,
+     scripting, etc. have been ported. Again, most of these are not of
+     immedeate use, as they need a full application to be really useful, so
+     they have been commented out in setup.py. People wanting to experiment
+     can uncomment them. Gestalt and Internet Config modules are enabled by
+     default.
 
 * Keyword arguments passed to builtin functions that don't take them now cause a
   :exc:`TypeError` exception to be raised, with the message "*function* takes no
@@ -1253,7 +1253,7 @@
   unpredictably depending on the platform.  A call such as ``pow(2.0, 8.0, 7.0)``
   will now raise a :exc:`TypeError` exception.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Acknowledgements

Modified: python/branches/py3k-importlib/Doc/whatsnew/2.3.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/whatsnew/2.3.rst	(original)
+++ python/branches/py3k-importlib/Doc/whatsnew/2.3.rst	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,7 @@
 
 .. |release| replace:: 1.01
 
-.. % $Id: whatsnew23.tex 55005 2007-04-27 19:54:29Z guido.van.rossum $
+.. $Id: whatsnew23.tex 54631 2007-03-31 11:58:36Z georg.brandl $
 
 This article explains the new features in Python 2.3.  Python 2.3 was released
 on July 29, 2003.
@@ -34,7 +34,7 @@
 complete implementation and design rationale, refer to the PEP for a particular
 new feature.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 218: A Standard Set Datatype
@@ -117,7 +117,7 @@
       PEP written by Greg V. Wilson. Implemented by Greg V. Wilson, Alex Martelli, and
       GvR.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _section-generators:
@@ -248,7 +248,7 @@
       Written by Neil Schemenauer, Tim Peters, Magnus Lie Hetland.  Implemented mostly
       by Neil Schemenauer and Tim Peters, with other fixes from the Python Labs crew.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _section-encodings:
@@ -282,7 +282,7 @@
       Written by Marc-André Lemburg and Martin von Löwis; implemented by Suzuki Hisao
       and Martin von Löwis.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 273: Importing Modules from ZIP Archives
@@ -329,7 +329,7 @@
       Just van Rossum  that uses the import hooks described in :pep:`302`. See section
       :ref:`section-pep302` for a description of the new import hooks.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 277: Unicode file name support for Windows NT
@@ -363,7 +363,7 @@
       Written by Neil Hodgson; implemented by Neil Hodgson, Martin von Löwis, and Mark
       Hammond.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 278: Universal Newline Support
@@ -398,7 +398,7 @@
    :pep:`278` - Universal Newline Support
       Written and implemented by Jack Jansen.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _section-enumerate:
@@ -430,7 +430,7 @@
    :pep:`279` - The enumerate() built-in function
       Written and implemented by Raymond D. Hettinger.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 282: The logging Package
@@ -536,7 +536,7 @@
    :pep:`282` - A Logging System
       Written by Vinay Sajip and Trent Mick; implemented by Vinay Sajip.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _section-bool:
@@ -608,7 +608,7 @@
    :pep:`285` - Adding a bool type
       Written and implemented by GvR.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 293: Codec Error Handling Callbacks
@@ -640,7 +640,7 @@
    :pep:`293` - Codec Error Handling Callbacks
       Written and implemented by Walter Dörwald.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _section-pep301:
@@ -689,7 +689,7 @@
    :pep:`301` - Package Index and Metadata for Distutils
       Written and implemented by Richard Jones.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _section-pep302:
@@ -755,7 +755,7 @@
    :pep:`302` - New Import Hooks
       Written by Just van Rossum and Paul Moore. Implemented by Just van Rossum.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _section-pep305:
@@ -801,7 +801,7 @@
       Written and implemented  by Kevin Altis, Dave Cole, Andrew McNamara, Skip
       Montanaro, Cliff Wells.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _section-pep307:
@@ -844,7 +844,7 @@
    :pep:`307` - Extensions to the pickle protocol
       Written and implemented  by Guido van Rossum and Tim Peters.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _section-slices:
@@ -954,7 +954,7 @@
 consistent with Python 2.2, where :class:`int`, :class:`str`, etc., underwent
 the same change.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Other Language Changes
@@ -1042,8 +1042,6 @@
   objects available in the :mod:`types` module.) For example, you can create a new
   module object with the following code:
 
-  .. % XXX should new.py use PendingDeprecationWarning?
-
   ::
 
      >>> import types
@@ -1115,7 +1113,7 @@
   assigned to :attr:`__bases__` along the lines of those relating to assigning to
   an instance's :attr:`__class__` attribute.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 String Changes
@@ -1179,7 +1177,7 @@
   the usual way when the only reference to them is from the internal dictionary of
   interned strings.  (Implemented by Oren Tirosh.)
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Optimizations
@@ -1211,7 +1209,7 @@
 The net result of the 2.3 optimizations is that Python 2.3 runs the  pystone
 benchmark around 25% faster than Python 2.2.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 New, Improved, and Deprecated Modules
@@ -1566,8 +1564,6 @@
   http://mail.python.org/pipermail/python-dev/2002-December/031107.html for a more
   detailed explanation of this change.  (Implemented by Martin von Löwis.)
 
-  .. % 
-
 * Calling Tcl methods through :mod:`_tkinter` no longer  returns only strings.
   Instead, if Tcl returns other objects those objects are converted to their
   Python equivalent, if one exists, or wrapped with a :class:`_tkinter.Tcl_Obj`
@@ -1671,7 +1667,7 @@
   To implement this change, the :mod:`stringprep` module, the  ``mkstringprep``
   tool and the ``punycode`` encoding have been added.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Date/Time Type
@@ -1726,7 +1722,7 @@
 For more information, refer to the module's reference documentation.
 (Contributed by Tim Peters.)
 
-.. % ======================================================================
+.. ======================================================================
 
 
 The optparse Module
@@ -1791,7 +1787,7 @@
 Optik was written by Greg Ward, with suggestions from the readers of the Getopt
 SIG.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _section-pymalloc:
@@ -1864,7 +1860,7 @@
       of the file :file:`Objects/obmalloc.c` in the Python source code.  The above
       link points to the file within the SourceForge CVS browser.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Build and C API Changes
@@ -1926,7 +1922,7 @@
   the type name leading up to the final period will no longer have the desired
   effect.  For more detail, read the API reference documentation or the  source.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Port-Specific Changes
@@ -1952,7 +1948,7 @@
 Other new platforms now supported by Python include AtheOS
 (http://www.atheos.cx/), GNU/Hurd, and OpenVMS.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _section-other:
@@ -2003,7 +1999,7 @@
   executed next.  A ``jump`` command has been added to the :mod:`pdb` debugger
   taking advantage of this new feature. (Implemented by Richie Hindle.)
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Porting to Python 2.3
@@ -2042,8 +2038,6 @@
   desired upper bits. For example, to clear just the top bit (bit 31), you could
   write ``0xffffffffL &~(1L<<31)``.
 
-  .. % The empty groups below prevent conversion to guillemets.
-
 * You can no longer disable assertions by assigning to ``__debug__``.
 
 * The Distutils :func:`setup` function has gained various new keyword arguments
@@ -2065,7 +2059,7 @@
 * Names of extension types defined by the modules included with Python now
   contain the module and a ``'.'`` in front of the type name.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _acks:

Modified: python/branches/py3k-importlib/Doc/whatsnew/2.4.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/whatsnew/2.4.rst	(original)
+++ python/branches/py3k-importlib/Doc/whatsnew/2.4.rst	Thu Mar 27 00:48:05 2008
@@ -6,10 +6,10 @@
 
 .. |release| replace:: 1.02
 
-.. % $Id: whatsnew24.tex 55005 2007-04-27 19:54:29Z guido.van.rossum $
-.. % Don't write extensive text for new sections; I'll do that.
-.. % Feel free to add commented-out reminders of things that need
-.. % to be covered.  --amk
+.. $Id: whatsnew24.tex 54632 2007-03-31 11:59:54Z georg.brandl $
+.. Don't write extensive text for new sections; I'll do that.
+.. Feel free to add commented-out reminders of things that need
+.. to be covered.  --amk
 
 This article explains the new features in Python 2.4.1, released on March 30,
 2005.
@@ -29,7 +29,7 @@
 referred to the PEP for a particular new feature for explanations of the
 implementation and design rationale.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 218: Built-In Set Objects
@@ -83,7 +83,7 @@
       Originally proposed by Greg Wilson and ultimately implemented by Raymond
       Hettinger.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 237: Unifying Long Integers and Integers
@@ -108,7 +108,7 @@
       Original PEP written by Moshe Zadka and GvR.  The changes for 2.4 were
       implemented by  Kalle Svensson.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 289: Generator Expressions
@@ -165,7 +165,7 @@
       Proposed by Raymond Hettinger and implemented by Jiwon Seo with early efforts
       steered by Hye-Shik Chang.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 292: Simpler String Substitutions
@@ -199,25 +199,19 @@
 
 If a key is missing from the dictionary, the :meth:`substitute` method will
 raise a :exc:`KeyError`.  There's also a :meth:`safe_substitute` method that
-ignores missing keys:
-
-.. % $ Terminate $-mode for Emacs
-
-::
+ignores missing keys::
 
    >>> t = string.Template('$page: $title')
    >>> t.safe_substitute({'page':3})
    '3: $title'
 
-.. % $ Terminate math-mode for Emacs
-
 
 .. seealso::
 
    :pep:`292` - Simpler String Substitutions
       Written and implemented  by Barry Warsaw.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 318: Decorators for Functions and Methods
@@ -346,7 +340,7 @@
    http://www.python.org/moin/PythonDecoratorLibrary
       This Wiki page contains several examples of decorators.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 322: Reverse Iteration
@@ -382,7 +376,7 @@
    :pep:`322` - Reverse Iteration
       Written and implemented by Raymond Hettinger.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 324: New subprocess Module
@@ -468,7 +462,7 @@
       Written and implemented by Peter Ã…strand, with assistance from Fredrik Lundh and
       others.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 327: Decimal Data Type
@@ -698,7 +692,7 @@
       proposed as a standard, and underlies the new Python decimal type.  Much of this
       material was written by Mike Cowlishaw, designer of the Rexx language.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 328: Multi-line Imports
@@ -734,7 +728,7 @@
    :pep:`328` - Imports: Multi-Line and Absolute/Relative
       Written by Aahz.  Multi-line imports were implemented by Dima Dorfman.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 PEP 331: Locale-Independent Float/String Conversions
@@ -773,7 +767,7 @@
    :pep:`331` - Locale-Independent Float/String Conversions
       Written by Christian R. Reis, and implemented by Gustavo Carneiro.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Other Language Changes
@@ -932,7 +926,7 @@
 * :const:`None` is now a constant; code that binds a new value to  the name
   ``None`` is now a syntax error. (Contributed by Raymond Hettinger.)
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Optimizations
@@ -983,15 +977,13 @@
 measurement of Python's performance.  Your own applications may show greater or
 smaller benefits from Python 2.4.)
 
-.. % pystone is almost useless for comparing different versions of Python;
-.. % instead, it excels at predicting relative Python performance on
-.. % different machines.
-.. % So, this section would be more informative if it used other tools
-.. % such as pybench and parrotbench.  For a more application oriented
-.. % benchmark, try comparing the timings of test_decimal.py under 2.3
-.. % and 2.4.
+.. pystone is almost useless for comparing different versions of Python;
+   instead, it excels at predicting relative Python performance on different
+   machines.  So, this section would be more informative if it used other tools
+   such as pybench and parrotbench.  For a more application oriented benchmark,
+   try comparing the timings of test_decimal.py under 2.3 and 2.4.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 New, Improved, and Deprecated Modules
@@ -1322,9 +1314,9 @@
 * The :mod:`mpz`, :mod:`rotor`, and :mod:`xreadlines` modules have  been
   removed.
 
-.. % ======================================================================
-.. % whole new modules get described in subsections here
-.. % =====================
+.. ======================================================================
+.. whole new modules get described in subsections here
+.. =====================
 
 
 cookielib
@@ -1348,7 +1340,7 @@
 
 This module was contributed by John J. Lee.
 
-.. % ==================
+.. ==================
 
 
 doctest
@@ -1447,7 +1439,7 @@
        +rather
    **********************************************************************
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Build and C API Changes
@@ -1500,7 +1492,7 @@
 * The :ctype:`tracebackobject` type has been renamed to
   :ctype:`PyTracebackObject`.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Port-Specific Changes
@@ -1509,7 +1501,7 @@
 * The Windows port now builds under MSVC++ 7.1 as well as version 6.
   (Contributed by Martin von Löwis.)
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Porting to Python 2.4
@@ -1556,7 +1548,7 @@
   for certain illegal values; previously these errors would pass silently.  For
   example, you can no longer set a handler on the :const:`SIGKILL` signal.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _acks:

Modified: python/branches/py3k-importlib/Doc/whatsnew/2.5.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/whatsnew/2.5.rst	(original)
+++ python/branches/py3k-importlib/Doc/whatsnew/2.5.rst	Thu Mar 27 00:48:05 2008
@@ -6,8 +6,8 @@
 
 .. |release| replace:: 1.01
 
-.. % $Id: whatsnew25.tex 56611 2007-07-29 08:26:10Z georg.brandl $
-.. % Fix XXX comments
+.. $Id: whatsnew25.tex 56611 2007-07-29 08:26:10Z georg.brandl $
+.. Fix XXX comments
 
 This article explains the new features in Python 2.5.  The final release of
 Python 2.5 is scheduled for August 2006; :pep:`356` describes the planned
@@ -45,7 +45,7 @@
 Comments, suggestions, and error reports for this document are welcome; please
 e-mail them to the author or open a bug in the Python bug tracker.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _pep-308:
@@ -123,7 +123,7 @@
       PEP written by Guido van Rossum and Raymond D. Hettinger; implemented by Thomas
       Wouters.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _pep-309:
@@ -201,7 +201,7 @@
       PEP proposed and written by Peter Harris; implemented by Hye-Shik Chang and Nick
       Coghlan, with adaptations by Raymond Hettinger.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _pep-314:
@@ -248,7 +248,7 @@
       PEP proposed and written by A.M. Kuchling, Richard Jones, and Fred Drake;
       implemented by Richard Jones and Fred Drake.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _pep-328:
@@ -333,7 +333,7 @@
    http://codespeak.net/py/current/doc/index.html
       The py library by Holger Krekel, which contains the :mod:`py.std` package.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _pep-338:
@@ -359,7 +359,7 @@
    :pep:`338` - Executing modules as scripts
       PEP written and  implemented by Nick Coghlan.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _pep-341:
@@ -407,7 +407,7 @@
    :pep:`341` - Unifying try-except and try-finally
       PEP written by Georg Brandl;  implementation by Thomas Lee.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _pep-342:
@@ -553,7 +553,7 @@
    http://www.sidhe.org/~dan/blog/archives/000178.html
       An explanation of coroutines from a Perl point of view, written by Dan Sugalski.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _pep-343:
@@ -803,7 +803,7 @@
 
    The documentation  for the :mod:`contextlib` module.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _pep-352:
@@ -862,7 +862,7 @@
    :pep:`352` - Required Superclass for Exceptions
       PEP written by  Brett Cannon and Guido van Rossum; implemented by Brett Cannon.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _pep-353:
@@ -921,7 +921,7 @@
    :pep:`353` - Using ssize_t as the index type
       PEP written and implemented by Martin von Löwis.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _pep-357:
@@ -964,7 +964,7 @@
    :pep:`357` - Allowing Any Object to be Used for Slicing
       PEP written  and implemented by Travis Oliphant.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _other-lang:
@@ -1024,7 +1024,7 @@
 
   (Implemented by Georg Brandl following a suggestion by Tom Lynn.)
 
-  .. % RFE #1491485
+  .. RFE #1491485
 
 * The :func:`min` and :func:`max` built-in functions gained a ``key`` keyword
   parameter analogous to the ``key`` argument for :meth:`sort`.  This parameter
@@ -1055,7 +1055,7 @@
   return non-negative numbers, and users often seem to use ``id(self)`` in
   :meth:`__hash__` methods (though this is discouraged).
 
-  .. % Bug #1536021
+  .. Bug #1536021
 
 * ASCII is now the default encoding for modules.  It's now  a syntax error if a
   module contains string literals with 8-bit characters but doesn't have an
@@ -1106,7 +1106,7 @@
 
   (Implemented by Brett Cannon.)
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _interactive:
@@ -1129,7 +1129,7 @@
 and :option:`--version`; on Windows,  it also accepts the :option:`/?` option
 for displaying a help message. (Implemented by Georg Brandl.)
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _opts:
@@ -1155,14 +1155,14 @@
   Andrew Dalke at the NeedForSpeed sprint. Character maps were improved by Walter
   Dörwald and Martin von Löwis.)
 
-  .. % Patch 1313939, 1359618
+  .. Patch 1313939, 1359618
 
 * The :func:`long(str, base)` function is now faster on long digit strings
   because fewer intermediate results are calculated.  The peak is for strings of
   around 800--1000 digits where  the function is 6 times faster. (Contributed by
   Alan McIntyre and committed at the NeedForSpeed sprint.)
 
-  .. % Patch 1442927
+  .. Patch 1442927
 
 * It's now illegal to mix iterating over a file  with ``for line in file`` and
   calling  the file object's :meth:`read`/:meth:`readline`/:meth:`readlines`
@@ -1172,7 +1172,7 @@
   methods will now trigger a :exc:`ValueError` from the :meth:`read\*` method.
   (Implemented by Thomas Wouters.)
 
-  .. % Patch 1397960
+  .. Patch 1397960
 
 * The :mod:`struct` module now compiles structure format  strings into an
   internal representation and caches this representation, yielding a 20% speedup.
@@ -1194,8 +1194,8 @@
   sprint.)  Frame objects are also slightly smaller, which may improve cache
   locality and reduce memory usage a bit.  (Contributed by Neal Norwitz.)
 
-  .. % Patch 876206
-  .. % Patch 1337051
+  .. Patch 876206
+  .. Patch 1337051
 
 * Python's built-in exceptions are now new-style classes, a change that speeds
   up instantiation considerably.  Exception handling in Python 2.5 is therefore
@@ -1206,9 +1206,9 @@
   that the interpreter makes fewer  :cfunc:`open` and :cfunc:`stat` calls on
   startup. (Contributed by Martin von Löwis and Georg Brandl.)
 
-  .. % Patch 921466
+  .. Patch 921466
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _modules:
@@ -1234,7 +1234,7 @@
   entire input was fed to the non-incremental codec. See the :mod:`codecs` module
   documentation for details. (Designed and implemented by Walter Dörwald.)
 
-  .. % Patch  1436130
+  .. Patch  1436130
 
 * The :mod:`collections` module gained a new type, :class:`defaultdict`, that
   subclasses the standard :class:`dict` type.  The new type mostly behaves like a
@@ -1331,12 +1331,12 @@
   easier to use non-ASCII characters in  tests contained within a docstring.
   (Contributed by Bjorn Tillenius.)
 
-  .. % Patch 1080727
+  .. Patch 1080727
 
 * The :mod:`email` package has been updated to version 4.0. (Contributed by
   Barry Warsaw.)
 
-  .. % XXX need to provide some more detail here
+  .. XXX need to provide some more detail here
 
 * The :mod:`fileinput` module was made more flexible. Unicode filenames are now
   supported, and a *mode* parameter that defaults to ``"r"`` was added to the
@@ -1394,7 +1394,7 @@
 
   (Contributed by Georg Brandl.)
 
-  .. % Patch 1180296
+  .. Patch 1180296
 
 * The :mod:`mailbox` module underwent a massive rewrite to add the capability to
   modify mailboxes in addition to reading them.  A new set of classes that include
@@ -1462,7 +1462,7 @@
   :attr:`st_birthtime`. The :attr:`st_flags` member is also available, if the
   platform supports it. (Contributed by Antti Louko and  Diego Pettenò.)
 
-  .. % (Patch 1180695, 1212117)
+  .. (Patch 1180695, 1212117)
 
 * The Python debugger provided by the :mod:`pdb` module can now store lists of
   commands to execute when a breakpoint is reached and execution stops.  Once
@@ -1471,7 +1471,7 @@
   include commands that resume execution, such as ``continue`` or ``next``.
   (Contributed by Grégoire Dooms.)
 
-  .. % Patch 790710
+  .. Patch 790710
 
 * The :mod:`pickle` and :mod:`cPickle` modules no longer accept a return value
   of ``None`` from the :meth:`__reduce__` method; the method must return a tuple
@@ -1512,14 +1512,14 @@
   :mod:`readline` module and therefore now works on non-Unix platforms. (Patch
   from Robert Kiendl.)
 
-  .. % Patch #1472854
+  .. Patch #1472854
 
 * The :mod:`SimpleXMLRPCServer` and :mod:`DocXMLRPCServer`  classes now have a
   :attr:`rpc_paths` attribute that constrains XML-RPC operations to a limited set
   of URL paths; the default is to allow only ``'/'`` and ``'/RPC2'``.  Setting
   :attr:`rpc_paths` to ``None`` or an empty tuple disables  this path checking.
 
-  .. % Bug #1473048
+  .. Bug #1473048
 
 * The :mod:`socket` module now supports :const:`AF_NETLINK` sockets on Linux,
   thanks to a patch from Philippe Biondi.   Netlink sockets are a Linux-specific
@@ -1585,7 +1585,7 @@
   The compression used for a tarfile opened in stream mode can now be autodetected
   using the mode ``'r|*'``. (Contributed by Lars Gustäbel.)
 
-  .. % patch 918101
+  .. patch 918101
 
 * The :mod:`threading` module now lets you set the stack size used when new
   threads are created. The :func:`stack_size([*size*])` function returns the
@@ -1593,7 +1593,7 @@
   sets a new value.  Not all platforms support changing the stack size, but
   Windows, POSIX threading, and OS/2 all do. (Contributed by Andrew MacIntyre.)
 
-  .. % Patch 1454481
+  .. Patch 1454481
 
 * The :mod:`unicodedata` module has been updated to use version 4.1.0 of the
   Unicode character database.  Version 3.2.0 is required  by some specifications,
@@ -1643,29 +1643,29 @@
   of additional browsers were added to the supported list such as Firefox, Opera,
   Konqueror, and elinks.  (Contributed by Oleg Broytmann and Georg Brandl.)
 
-  .. % Patch #754022
+  .. Patch #754022
 
 * The :mod:`xmlrpclib` module now supports returning  :class:`datetime` objects
   for the XML-RPC date type.  Supply  ``use_datetime=True`` to the :func:`loads`
   function or the :class:`Unmarshaller` class to enable this feature. (Contributed
   by Skip Montanaro.)
 
-  .. % Patch 1120353
+  .. Patch 1120353
 
 * The :mod:`zipfile` module now supports the ZIP64 version of the  format,
   meaning that a .zip archive can now be larger than 4 GiB and can contain
   individual files larger than 4 GiB.  (Contributed by Ronald Oussoren.)
 
-  .. % Patch 1446489
+  .. Patch 1446489
 
 * The :mod:`zlib` module's :class:`Compress` and :class:`Decompress` objects now
   support a :meth:`copy` method that makes a copy of the  object's internal state
   and returns a new  :class:`Compress` or :class:`Decompress` object.
   (Contributed by Chris AtLee.)
 
-  .. % Patch 1435422
+  .. Patch 1435422
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _module-ctypes:
@@ -1746,7 +1746,7 @@
 
    The documentation  for the :mod:`ctypes` module.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _module-etree:
@@ -1863,7 +1863,7 @@
    http://effbot.org/zone/element-index.htm
       Official documentation for ElementTree.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _module-hashlib:
@@ -1917,7 +1917,7 @@
 
    The documentation  for the :mod:`hashlib` module.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _module-sqlite:
@@ -2026,7 +2026,7 @@
    :pep:`249` - Database API Specification 2.0
       PEP written by Marc-André Lemburg.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _module-wsgiref:
@@ -2039,7 +2039,7 @@
 The :mod:`wsgiref` package is a reference implementation of the WSGI
 specification.
 
-.. % XXX should this be in a PEP 333 section instead?
+.. XXX should this be in a PEP 333 section instead?
 
 The package includes a basic HTTP server that will run a WSGI application; this
 server is useful for debugging but isn't intended for  production use.  Setting
@@ -2054,8 +2054,8 @@
    httpd = simple_server.make_server(host, port, wsgi_app)
    httpd.serve_forever()
 
-.. % XXX discuss structure of WSGI applications?
-.. % XXX provide an example using Django or some other framework?
+.. XXX discuss structure of WSGI applications?
+.. XXX provide an example using Django or some other framework?
 
 
 .. seealso::
@@ -2066,7 +2066,7 @@
    :pep:`333` - Python Web Server Gateway Interface v1.0
       PEP written by Phillip J. Eby.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _build-api:
@@ -2125,8 +2125,8 @@
   Schemenauer, plus the participants in a number of AST sprints at conferences
   such as PyCon.
 
-  .. % List of names taken from Jeremy's python-dev post at
-  .. % http://mail.python.org/pipermail/python-dev/2005-October/057500.html
+  .. List of names taken from Jeremy's python-dev post at
+  .. http://mail.python.org/pipermail/python-dev/2005-October/057500.html
 
 * Evan Jones's patch to obmalloc, first described in a talk at PyCon DC 2005,
   was applied.  Python 2.4 allocated small objects in 256K-sized arenas, but never
@@ -2194,7 +2194,7 @@
      range = PyObject_CallFunction((PyObject*) &PyRange_Type, "lll", 
                                    start, stop, step);
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _ports:
@@ -2214,7 +2214,7 @@
   extension modules.  :file:`.pyd` is now the only filename extension that will be
   searched for.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _porting:
@@ -2269,7 +2269,7 @@
   allocated with  one family's :cfunc:`\*_Malloc` must be  freed with the
   corresponding family's :cfunc:`\*_Free` function.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _acks:

Modified: python/branches/py3k-importlib/Doc/whatsnew/2.6.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/whatsnew/2.6.rst	(original)
+++ python/branches/py3k-importlib/Doc/whatsnew/2.6.rst	Thu Mar 27 00:48:05 2008
@@ -2,54 +2,53 @@
   What's New in Python 2.6  
 ****************************
 
-.. % XXX mention switch to reST for documentation
-.. % XXX mention switch to Roundup for bug tracking
+.. XXX add trademark info for Apple, Microsoft, SourceForge.
 
 :Author: A.M. Kuchling
 :Release: |release|
 :Date: |today|
 
-.. % $Id: whatsnew26.tex 55963 2007-06-13 18:07:49Z guido.van.rossum $
-.. % Rules for maintenance:
-.. % 
-.. % * Anyone can add text to this document.  Do not spend very much time
-.. % on the wording of your changes, because your text will probably
-.. % get rewritten to some degree.
-.. % 
-.. % * The maintainer will go through Misc/NEWS periodically and add
-.. % changes; it's therefore more important to add your changes to
-.. % Misc/NEWS than to this file.
-.. % 
-.. % * This is not a complete list of every single change; completeness
-.. % is the purpose of Misc/NEWS.  Some changes I consider too small
-.. % or esoteric to include.  If such a change is added to the text,
-.. % I'll just remove it.  (This is another reason you shouldn't spend
-.. % too much time on writing your addition.)
-.. % 
-.. % * If you want to draw your new text to the attention of the
-.. % maintainer, add 'XXX' to the beginning of the paragraph or
-.. % section.
-.. % 
-.. % * It's OK to just add a fragmentary note about a change.  For
-.. % example: "XXX Describe the transmogrify() function added to the
-.. % socket module."  The maintainer will research the change and
-.. % write the necessary text.
-.. % 
-.. % * You can comment out your additions if you like, but it's not
-.. % necessary (especially when a final release is some months away).
-.. % 
-.. % * Credit the author of a patch or bugfix.   Just the name is
-.. % sufficient; the e-mail address isn't necessary.
-.. % 
-.. % * It's helpful to add the bug/patch number as a comment:
-.. % 
-.. % % Patch 12345
-.. % XXX Describe the transmogrify() function added to the socket
-.. % module.
-.. % (Contributed by P.Y. Developer.)
-.. % 
-.. % This saves the maintainer the effort of going through the SVN log
-.. % when researching a change.
+.. $Id: whatsnew26.tex 55746 2007-06-02 18:33:53Z neal.norwitz $
+   Rules for maintenance:
+   
+   * Anyone can add text to this document.  Do not spend very much time
+   on the wording of your changes, because your text will probably
+   get rewritten to some degree.
+   
+   * The maintainer will go through Misc/NEWS periodically and add
+   changes; it's therefore more important to add your changes to
+   Misc/NEWS than to this file.
+   
+   * This is not a complete list of every single change; completeness
+   is the purpose of Misc/NEWS.  Some changes I consider too small
+   or esoteric to include.  If such a change is added to the text,
+   I'll just remove it.  (This is another reason you shouldn't spend
+   too much time on writing your addition.)
+   
+   * If you want to draw your new text to the attention of the
+   maintainer, add 'XXX' to the beginning of the paragraph or
+   section.
+   
+   * It's OK to just add a fragmentary note about a change.  For
+   example: "XXX Describe the transmogrify() function added to the
+   socket module."  The maintainer will research the change and
+   write the necessary text.
+   
+   * You can comment out your additions if you like, but it's not
+   necessary (especially when a final release is some months away).
+   
+   * Credit the author of a patch or bugfix.   Just the name is
+   sufficient; the e-mail address isn't necessary.
+   
+   * It's helpful to add the bug/patch number as a comment:
+   
+   .. Patch 12345
+   XXX Describe the transmogrify() function added to the socket
+   module.
+   (Contributed by P.Y. Developer.)
+   
+   This saves the maintainer the effort of going through the SVN logs
+   when researching a change.
 
 This article explains the new features in Python 2.6.  No release date for
 Python 2.6 has been set; it will probably be released in mid 2008.
@@ -60,27 +59,50 @@
 complete implementation and design rationale, refer to the PEP for a particular
 new feature.
 
-.. % Compare with previous release in 2 - 3 sentences here.
-.. % add hyperlink when the documentation becomes available online.
+.. Compare with previous release in 2 - 3 sentences here.
+   add hyperlink when the documentation becomes available online.
 
-.. % ======================================================================
-.. % Large, PEP-level features and changes should be described here.
-.. % Should there be a new section here for 3k migration?
-.. % Or perhaps a more general section describing module changes/deprecation?
-.. % sets module deprecated
-.. % ======================================================================
+.. ========================================================================
+.. Large, PEP-level features and changes should be described here.
+.. Should there be a new section here for 3k migration?
+.. Or perhaps a more general section describing module changes/deprecation?
+.. ========================================================================
 
 Python 3.0
 ================
 
-.. % XXX add general comment about Python 3.0 features in 2.6
-
-.. % XXX mention -3 switch
+The development cycle for Python 2.6 also saw the release of the first
+alphas of Python 3.0, and the development of 3.0 has influenced 
+a number of features in 2.6.
+
+Python 3.0 is a far-ranging redesign of Python that breaks
+compatibility with the 2.x series.  This means that existing Python
+code will need a certain amount of conversion in order to run on
+Python 3.0.  However, not all the changes in 3.0 necessarily break
+compatibility.  In cases where new features won't cause existing code
+to break, they've been backported to 2.6 and are described in this
+document in the appropriate place.  Some of the 3.0-derived features 
+are:
+
+* A :meth:`__complex__` method for converting objects to a complex number.
+* Alternate syntax for catching exceptions: ``except TypeError as exc``.
+* The addition of :func:`functools.reduce` as a synonym for the built-in
+  :func:`reduce` function.
 
 A new command-line switch, :option:`-3`, enables warnings
 about features that will be removed in Python 3.0.  You can run code
 with this switch to see how much work will be necessary to port
-code to 3.0.
+code to 3.0.  The value of this switch is available 
+to Python code as the boolean variable ``sys.py3kwarning``,
+and to C extension code as :cdata:`Py_Py3kWarningFlag`.
+
+Python 3.0 adds several new built-in functions and change the
+semantics of some existing built-ins.  Entirely new functions such as
+:func:`bin` have simply been added to Python 2.6, but existing
+built-ins haven't been changed; instead, the :mod:`future_builtins`
+module has versions with the new 3.0 semantics.  Code written to be
+compatible with 3.0 can do ``from future_builtins import hex, map``
+as necessary.
 
 .. seealso::
 
@@ -88,12 +110,103 @@
    Python 3.0 and various features that have been accepted, rejected,
    or are still under consideration.
 
+
+Development Changes
+==================================================
+
+While 2.6 was being developed, the Python development process 
+underwent two significant changes: the developer group 
+switched from SourceForge's issue tracker to a customized 
+Roundup installation, and the documentation was converted from
+LaTeX to reStructured Text.
+
+
+New Issue Tracker: Roundup
+--------------------------------------------------
+
+For a long time, the Python developers have been growing increasingly
+annoyed by SourceForge's bug tracker.  SourceForge's hosted solution
+doesn't permit much customization; for example, it wasn't possible to
+customize the life cycle of issues.
+
+The infrastructure committee of the Python Software Foundation
+therefore posted a call for issue trackers, asking volunteers to set
+up different products and import some of the bugs and patches from
+SourceForge.  Four different trackers were examined: Atlassian's `Jira
+<XXX>`__, `Launchpad <http://www.launchpad.net>`__, ` `Roundup
+<XXX>`__, and Trac <XXX>`__.  The committee eventually settled on Jira
+and Roundup as the two candidates.  Jira is a commercial product that
+offers a no-cost hosted instance to free-software projects; Roundup 
+is an open-source project that requires volunteers
+to administer it and a server to host it.
+
+After posting a call for volunteers, a new Roundup installation was
+set up at http://bugs.python.org.  One installation of Roundup can
+host multiple trackers, and this server now also hosts issue trackers
+for Jython and for the Python web site.  It will surely find 
+other uses in the future.
+
+Hosting is kindly provided by `Upfront <XXX>`__ of XXX.  Martin von
+Loewis put a lot of effort into importing existing bugs and patches
+from SourceForge; his scripts for this import are at XXX.
+
+.. seealso::
+
+  XXX Roundup web site.
+
+  bugs.python.org
+
+  bugs.jython.org
+
+  Python web site bug tracker
+
+
+New Documentation Format: ReStructured Text
+--------------------------------------------------
+
+Since the Python project's inception around 1989, the documentation
+had been written using LaTeX.  At that time, most documentation was
+printed out for later study, not viewed online. LaTeX was widely used
+because it provided attractive printed output while remaining
+straightforward to write, once the basic rules of the markup have been
+learned.
+
+LaTeX is still used today for writing technical publications destined
+for printing, but the landscape for programming tools has shifted.  We
+no longer print out reams of documentation; instead, we browse through
+it online and HTML has become the most important format to support.
+Unfortunately, converting LaTeX to HTML is fairly complicated, and
+Fred L. Drake Jr., the Python documentation editor for many years,
+spent a lot of time wrestling the conversion process into shape.
+Occasionally people would suggest converting the documentation into 
+SGML or, later, XML, but performing a good conversion is a major task 
+and no one pursued the task to completion.
+
+During the 2.6 development cycle, Georg Brandl put a substantial 
+effort into building a new toolchain called Sphinx 
+for processing the documentation.
+The input format is reStructured Text, 
+a markup commonly used in the Python community that supports
+custom extensions  and directives.   Sphinx concentrates 
+on HTML output, producing attractively styled 
+and modern HTML, but printed output is still supported through 
+conversion to LaTeX as an output format.
+
+.. seealso::
+
+   `Docutils <http://docutils.sf.net>`__: The fundamental
+   reStructured Text parser and toolset.
+
+   :ref:`documenting-index`: Describes how to write for 
+   Python's documentation.
+
+
 PEP 343: The 'with' statement
 =============================
 
 The previous version, Python 2.5, added the ':keyword:`with`'
 statement an optional feature, to be enabled by a ``from __future__
-import generators`` directive.  In 2.6 the statement no longer need to
+import with_statement`` directive.  In 2.6 the statement no longer needs to
 be specially enabled; this means that :keyword:`with` is now always a
 keyword.  The rest of this section is a copy of the corresponding 
 section from "What's New in Python 2.5" document; if you read
@@ -187,7 +300,7 @@
   methods.
 
 * The context manager's :meth:`__enter__` method is called.  The value returned
-  is assigned to *VAR*.  If no ``'as VAR'`` clause is present, the value is simply
+  is assigned to *VAR*.  If no ``as VAR`` clause is present, the value is simply
   discarded.
 
 * The code in *BLOCK* is executed.
@@ -227,11 +340,11 @@
 
    class DatabaseConnection:
        # Database interface
-       def cursor (self):
+       def cursor(self):
            "Returns a cursor object and starts a new transaction"
-       def commit (self):
+       def commit(self):
            "Commits current transaction"
-       def rollback (self):
+       def rollback(self):
            "Rolls back current transaction"
 
 The :meth:`__enter__` method is pretty easy, having only to start a new
@@ -241,7 +354,7 @@
 
    class DatabaseConnection:
        ...
-       def __enter__ (self):
+       def __enter__(self):
            # Code to start a new transaction
            cursor = self.cursor()
            return cursor
@@ -258,7 +371,7 @@
 
    class DatabaseConnection:
        ...
-       def __exit__ (self, type, value, tb):
+       def __exit__(self, type, value, tb):
            if tb is None:
                # No exception, so commit
                self.commit()
@@ -291,7 +404,7 @@
    from contextlib import contextmanager
 
    @contextmanager
-   def db_transaction (connection):
+   def db_transaction(connection):
        cursor = connection.cursor()
        try:
            yield cursor
@@ -335,7 +448,190 @@
 
    The documentation  for the :mod:`contextlib` module.
 
-.. % ======================================================================
+.. ======================================================================
+
+.. _pep-0366:
+
+PEP 366: Explicit Relative Imports From a Main Module
+============================================================
+
+Python's :option:`-m` switch allows running a module as a script.
+When you ran a module that was located inside a package, relative
+imports didn't work correctly.
+
+The fix in Python 2.6 adds a :attr:`__package__` attribute to modules.
+When present, relative imports will be relative to the value of this
+attribute instead of the :attr:`__name__` attribute.  PEP 302-style
+importers can then set :attr:`__package__`.  The :mod:`runpy` module
+that implements the :option:`-m` switch now does this, so relative imports
+can now be used in scripts running from inside a package.
+
+.. ======================================================================
+
+.. ::
+
+    .. _pep-0370:
+
+    PEP 370: XXX
+    =====================================================
+
+    When you run Python, the module search page ``sys.modules`` usually
+    includes a directory whose path ends in ``"site-packages"``.  This
+    directory is intended to hold locally-installed packages available to
+    all users on a machine or using a particular site installation.
+
+    Python 2.6 introduces a convention for user-specific site directories.
+
+    .. seealso::
+
+       :pep:`370` - XXX
+
+       PEP written by XXX; implemented by Christian Heimes.
+
+  
+.. ======================================================================
+
+.. _pep-3101:
+
+PEP 3101: Advanced String Formatting
+=====================================================
+
+In Python 3.0, the `%` operator is supplemented by a more powerful
+string formatting method, :meth:`format`.  Support for the
+:meth:`format` method has been backported to Python 2.6.
+
+In 2.6, both 8-bit and Unicode strings have a `.format()` method that
+treats the string as a template and takes the arguments to be formatted.
+The formatting template uses curly brackets (`{`, `}`) as special characters::
+
+     # Substitute positional argument 0 into the string.
+     "User ID: {0}".format("root") -> "User ID: root"
+
+     # Use the named keyword arguments
+     uid = 'root'
+     
+     'User ID: {uid}   Last seen: {last_login}'.format(uid='root',
+            last_login = '5 Mar 2008 07:20') ->
+       'User ID: root   Last seen: 5 Mar 2008 07:20'
+
+Curly brackets can be escaped by doubling them::
+
+     format("Empty dict: {{}}") -> "Empty dict: {}"
+
+Field names can be integers indicating positional arguments, such as 
+``{0}``, ``{1}``, etc. or names of keyword arguments.  You can also 
+supply compound field names that read attributes or access dictionary keys::
+
+    import sys
+    'Platform: {0.platform}\nPython version: {0.version}'.format(sys) ->
+        'Platform: darwin\n
+         Python version: 2.6a1+ (trunk:61261M, Mar  5 2008, 20:29:41) \n
+         [GCC 4.0.1 (Apple Computer, Inc. build 5367)]'
+
+     import mimetypes
+     'Content-type: {0[.mp4]}'.format(mimetypes.types_map) ->
+       'Content-type: video/mp4'
+
+Note that when using dictionary-style notation such as ``[.mp4]``, you
+don't need to put any quotation marks around the string; it will look
+up the value using ``.mp4`` as the key.  Strings beginning with a
+number will be converted to an integer.  You can't write more
+complicated expressions inside a format string.
+
+So far we've shown how to specify which field to substitute into the
+resulting string.  The precise formatting used is also controllable by
+adding a colon followed by a format specifier.  For example::
+
+     # Field 0: left justify, pad to 15 characters
+     # Field 1: right justify, pad to 6 characters
+     fmt = '{0:15} ${1:>6}'
+     fmt.format('Registration', 35) ->
+       'Registration    $    35'
+     fmt.format('Tutorial', 50) ->
+       'Tutorial        $    50'
+     fmt.format('Banquet', 125) ->
+       'Banquet         $   125'
+
+Format specifiers can reference other fields through nesting::
+
+    fmt = '{0:{1}}'
+    fmt.format('Invoice #1234', width) ->
+      'Invoice #1234                      '
+    fmt.format('Invoice #1234', 15) ->
+      'Invoice #1234  '
+
+The alignment of a field within the desired width can be specified:
+
+================ ============================================
+Character        Effect
+================ ============================================
+< (default)      Left-align
+>                Right-align
+^                Center
+=                (For numeric types only) Pad after the sign.
+================ ============================================
+
+Format data types::
+
+     ... XXX take table from PEP 3101
+
+Classes and types can define a __format__ method to control how it's 
+formatted.  It receives a single argument, the format specifier::
+
+   def __format__(self, format_spec):
+       if isinstance(format_spec, unicode):
+           return unicode(str(self))
+       else:
+           return str(self)
+
+There's also a format() built-in that will format a single value.  It calls
+the type's :meth:`__format__` method with the provided specifier::
+
+    >>> format(75.6564, '.2f')
+    '75.66'
+
+.. seealso::
+
+   :pep:`3101` - Advanced String Formatting
+      PEP written by Talin.
+
+.. ======================================================================
+
+.. _pep-3105:
+
+PEP 3105: ``print`` As a Function
+=====================================================
+
+The ``print`` statement becomes the :func:`print` function in Python 3.0.
+Making :func:`print` a function makes it easier to replace within a
+module by doing 'def print(...)' or importing a new 
+function from somewhere else. 
+
+Python 2.6 has a ``__future__`` import that removes ``print`` as language 
+syntax, letting you use the functional form instead.  For example::
+
+    XXX need to check
+    from __future__ import print_function
+    print('# of entries', len(dictionary), file=sys.stderr)
+
+The signature of the new function is::
+
+    def print(*args, sep=' ', end='\n', file=None)
+
+The parameters are:
+
+ * **args**: positional arguments whose values will be printed out.
+ * **sep**: the separator, which will be printed between arguments.
+ * **end**: the ending text, which will be printed after all of the 
+   arguments have been output.
+ * **file**: the file object to which the output will be sent.
+
+.. seealso::
+
+   :pep:`3105` - Make print a function
+      PEP written by Georg Brandl.
+
+.. ======================================================================
 
 .. _pep-3110:
 
@@ -385,32 +681,231 @@
    :pep:`3110` - Catching Exceptions in Python 3000
       PEP written and implemented by Collin Winter.
 
-.. % ======================================================================
+.. ======================================================================
+
+.. _pep-3112:
+
+PEP 3112: Byte Literals
+=====================================================
+
+Python 3.0 adopts Unicode as the language's fundamental string type, and
+denotes 8-bit literals differently, either as ``b'string'`` 
+or using a :class:`bytes` constructor.  For future compatibility, 
+Python 2.6 adds :class:`bytes` as a synonym for the :class:`str` type,
+and it also supports the ``b''`` notation.
+
+.. seealso::
+
+   :pep:`3112` - Bytes literals in Python 3000
+      PEP written by Jason Orendorff; backported to 2.6 by Christian Heimes.
+
+.. ======================================================================
 
 .. _pep-3119:
 
 PEP 3119: Abstract Base Classes
 =====================================================
 
-XXX
+XXX write this -- this section is currently just brief notes.
+
+How to identify a file object?
+
+ABCs are a collection of classes describing various interfaces.
+Classes can derive from an ABC to indicate they support that ABC's
+interface.  Concrete classes should obey the semantics specified by 
+an ABC, but Python can't check this; it's up to the implementor.
+
+A metaclass lets you declare that an existing class or type
+derives from a particular ABC.  You can even 
+
+class AppendableSequence:
+    __metaclass__ = ABCMeta
+
+AppendableSequence.register(list)
+assert issubclass(list, AppendableSequence)
+assert isinstance([], AppendableSequence)
+
+ at abstractmethod decorator -- you can't instantiate classes w/
+an abstract method.
+
+::
+
+    @abstractproperty decorator
+    @abstractproperty
+    def readonly(self):
+       return self._x
+
 
 .. seealso::
 
    :pep:`3119` - Introducing Abstract Base Classes
       PEP written by Guido van Rossum and Talin.
       Implemented by XXX.
-      Backported to 2.6 by Benjamin Aranguren (with Alex Martelli).
+      Backported to 2.6 by Benjamin Aranguren, with Alex Martelli.
+
+.. ======================================================================
+
+.. _pep-3127:
+
+PEP 3127: Integer Literal Support and Syntax
+=====================================================
+
+XXX write this -- this section is currently just brief notes.
+
+Python 3.0 changes the syntax for octal integer literals, and 
+adds supports for binary integers: 0o instad of 0,
+and 0b for binary.  Python 2.6 doesn't support this, but a bin()
+builtin was added.
+
+XXX changes to the hex/oct builtins
+
+
+New bin() built-in returns the binary form of a number.
+
+.. seealso::
+
+   :pep:`3127` - Integer Literal Support and Syntax
+      PEP written by Patrick Maupin.
+
+.. ======================================================================
+
+.. _pep-3129:
+
+PEP 3129: Class Decorators
+=====================================================
+
+Decorators have been extended from functions to classes.  It's now legal to
+write::
+
+  @foo
+  @bar
+  class A:
+    pass
+
+This is equivalent to::
+
+  class A:
+    pass
+
+  A = foo(bar(A))
+
+XXX need to find a good motivating example.    
+
+.. seealso::
+
+   :pep:`3129` - Class Decorators
+      PEP written by Collin Winter.
+
+.. ======================================================================
+
+.. _pep-3141:
+
+PEP 3141: A Type Hierarchy for Numbers
+=====================================================
+
+In Python 3.0, several abstract base classes for numeric types,
+inspired by Scheme's numeric tower, are being added.
+This change was backported to 2.6 as the :mod:`numbers` module.
+
+The most general ABC is :class:`Number`.  It defines no operations at
+all, and only exists to allow checking if an object is a number by
+doing ``isinstance(obj, Number)``.
+
+Numbers are further divided into :class:`Exact` and :class:`Inexact`.
+Exact numbers can represent values precisely and operations never
+round off the results or introduce tiny errors that may break the
+commutativity and associativity properties; inexact numbers may
+perform such rounding or introduce small errors.  Integers, long
+integers, and rational numbers are exact, while floating-point 
+and complex numbers are inexact.
+
+:class:`Complex` is a subclass of :class:`Number`.  Complex numbers
+can undergo the basic operations of addition, subtraction,
+multiplication, division, and exponentiation, and you can retrieve the
+real and imaginary parts and obtain a number's conjugate.  Python's built-in 
+complex type is an implementation of :class:`Complex`.
+
+:class:`Real` further derives from :class:`Complex`, and adds 
+operations that only work on real numbers: :func:`floor`, :func:`trunc`, 
+rounding, taking the remainder mod N, floor division, 
+and comparisons.  
+
+:class:`Rational` numbers derive from :class:`Real`, have
+:attr:`numerator` and :attr:`denominator` properties, and can be
+converted to floats.  Python 2.6 adds a simple rational-number class,
+:class:`Fraction`, in the :mod:`fractions` module.  (It's called 
+:class:`Fraction` instead of :class:`Rational` to avoid 
+a name clash with :class:`numbers.Rational`.)
+
+:class:`Integral` numbers derive from :class:`Rational`, and
+can be shifted left and right with ``<<`` and ``>>``, 
+combined using bitwise operations such as ``&`` and ``|``, 
+and can be used as array indexes and slice boundaries.
+
+In Python 3.0, the PEP slightly redefines the existing built-ins
+:func:`round`, :func:`math.floor`, :func:`math.ceil`, and adds a new
+one, :func:`math.trunc`, that's been backported to Python 2.6. 
+:func:`math.trunc` rounds toward zero, returning the closest 
+:class:`Integral` that's between the function's argument and zero.
+
+.. seealso::
+
+   :pep:`3141` - A Type Hierarchy for Numbers
+      PEP written by Jeffrey Yasskin.
+
+  XXX link: Discusses Scheme's numeric tower.
+
+  
+
+The :mod:`fractions` Module
+--------------------------------------------------
+
+To fill out the hierarchy of numeric types, a rational-number class
+has been added as the :mod:`fractions` module.  Rational numbers are
+represented as a fraction, and can exactly represent
+numbers such as two-thirds that floating-point numbers can only
+approximate.
+
+The :class:`Fraction` constructor takes two :class:`Integral` values
+that will be the numerator and denominator of the resulting fraction. ::
+
+    >>> from fractions import Fraction
+    >>> a = Fraction(2, 3)
+    >>> b = Fraction(2, 5)
+    >>> float(a), float(b)
+    (0.66666666666666663, 0.40000000000000002)
+    >>> a+b
+    Fraction(16, 15)
+    >>> a/b
+    Fraction(5, 3)
+
+To help in converting floating-point numbers to rationals, 
+the float type now has a :meth:`as_integer_ratio()` method that returns 
+the numerator and denominator for a fraction that evaluates to the same
+floating-point value::
+
+    >>> (2.5) .as_integer_ratio()
+    (5, 2)
+    >>> (3.1415) .as_integer_ratio()
+    (7074029114692207L, 2251799813685248L)
+    >>> (1./3) .as_integer_ratio()
+    (6004799503160661L, 18014398509481984L)
+
+Note that values that can only be approximated by floating-point
+numbers, such as 1./3, are not simplified to the number being
+approximated; the fraction attempts to match the floating-point value
+**exactly**.
+
+The :mod:`fractions` module is based upon an implementation by Sjoerd
+Mullender that was in Python's :file:`Demo/classes/` directory for a
+long time.  This implementation was significantly updated by Jeffrey
+Yasskin.
 
 Other Language Changes
 ======================
 
 Here are all of the changes that Python 2.6 makes to the core Python language.
 
-* Changes to the :class:`Exception` interface
-  as dictated by :pep:`352` continue to be made.  For 2.6, 
-  the :attr:`message` attribute is being deprecated in favor of the
-  :attr:`args` attribute.
-
 * When calling a function using the ``**`` syntax to provide keyword
   arguments, you are no longer required to use a Python dictionary;
   any mapping will now work::
@@ -424,55 +919,179 @@
     >>> f(**ud)
     ['a', 'b']
 
-  .. % Patch 1686487
+  .. Patch 1686487
+
+* The built-in types now have improved support for extended slicing syntax,
+  where various combinations of ``(start, stop, step)`` are supplied.
+  Previously, the support was partial and certain corner cases wouldn't work.
+  (Implemented by Thomas Wouters.)
+
+  .. Revision 57619
+
+* Properties now have three attributes, :attr:`getter`,
+  :attr:`setter` and :attr:`deleter`, that are useful shortcuts for
+  adding or modifying a getter, setter or deleter function to an 
+  existing property. You would use them like this::
+
+    class C(object):
+	@property                                                              
+	def x(self): 
+	    return self._x                                            
+
+	@x.setter                                                              
+	def x(self, value): 
+	    self._x = value                                    
+
+	@x.deleter                                                             
+	def x(self): 
+	    del self._x             
+
+    class D(C):
+        @C.x.getter
+        def x(self):
+            return self._x * 2
+
+        @x.setter
+        def x(self, value):
+            self._x = value / 2
+
+
+* C functions and methods that use 
+  :cfunc:`PyComplex_AsCComplex` will now accept arguments that 
+  have a :meth:`__complex__` method.  In particular, the functions in the 
+  :mod:`cmath` module will now accept objects with this method.
+  This is a backport of a Python 3.0 change.
+  (Contributed by Mark Dickinson.)
+
+  .. Patch #1675423
+
+  A numerical nicety: when creating a complex number from two floats
+  on systems that support signed zeros (-0 and +0), the 
+  :func:`complex` constructor will now preserve the sign 
+  of the zero.
+
+  .. Patch 1507
+
+* More floating-point features were also added.  The :func:`float` function
+  will now turn the strings ``+nan`` and ``-nan`` into the corresponding
+  IEEE 754 Not A Number values, and ``+inf`` and ``-inf`` into 
+  positive or negative infinity.  This works on any platform with 
+  IEEE 754 semantics.  (Contributed by Christian Heimes.)
+
+  .. Patch 1635
+
+  Other functions in the :mod:`math` module, :func:`isinf` and
+  :func:`isnan`, return true if their floating-point argument is
+  infinite or Not A Number.
+
+  .. Patch 1640
+
+  The ``math.copysign(x, y)`` function
+  copies the sign bit of an IEEE 754 number, returning the absolute
+  value of *x* combined with the sign bit of *y*.  For example,
+  ``math.copysign(1, -0.0)`` returns -1.0.  (Contributed by Christian
+  Heimes.)
+
+* Changes to the :class:`Exception` interface
+  as dictated by :pep:`352` continue to be made.  For 2.6, 
+  the :attr:`message` attribute is being deprecated in favor of the
+  :attr:`args` attribute.
+
+* The :exc:`GeneratorExit` exception now subclasses 
+  :exc:`BaseException` instead of :exc:`Exception`.  This means 
+  that an exception handler that does ``except Exception:``
+  will not inadvertently catch :exc:`GeneratorExit`. 
+  (Contributed by Chad Austin.)
+
+  .. Patch #1537
+
+* Generator objects now have a :attr:`gi_code` attribute that refers to 
+  the original code object backing the generator.  
+  (Contributed by Collin Winter.)
+
+  .. Patch #1473257
 
 * The :func:`compile` built-in function now accepts keyword arguments
-  as well as positional parameters.  (Contributed by XXX.)
+  as well as positional parameters.  (Contributed by Thomas Wouters.)
 
-  .. % Patch 1444529
+  .. Patch 1444529
 
 * The :func:`complex` constructor now accepts strings containing 
   parenthesized complex numbers, letting ``complex(repr(cmplx))``
   will now round-trip values.  For example, ``complex('(3+4j)')``
   now returns the value (3+4j).
 
-  .. % Patch 1491866
+  .. Patch 1491866
 
 * The string :meth:`translate` method now accepts ``None`` as the 
   translation table parameter, which is treated as the identity 
   transformation.   This makes it easier to carry out operations
   that only delete characters.  (Contributed by Bengt Richter.)
 
-  .. % Patch 1193128
+  .. Patch 1193128
 
 * The built-in :func:`dir` function now checks for a :meth:`__dir__`
   method on the objects it receives.  This method must return a list
   of strings containing the names of valid attributes for the object,
   and lets the object control the value that :func:`dir` produces.
   Objects that have :meth:`__getattr__` or :meth:`__getattribute__` 
-  methods.
+  methods can use this to advertise pseudo-attributes they will honor.
 
-  .. % Patch 1591665
+  .. Patch 1591665
+
+* Instance method objects have new attributes for the object and function
+  comprising the method; the new synonym for :attr:`im_self` is
+  :attr:`__self__`, and :attr:`im_func` is also available as :attr:`__func__`.
+  The old names are still supported in Python 2.6; they're gone in 3.0.
 
 * An obscure change: when you use the the :func:`locals` function inside a
   :keyword:`class` statement, the resulting dictionary no longer returns free
   variables.  (Free variables, in this case, are variables referred to in the
   :keyword:`class` statement  that aren't attributes of the class.)
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Optimizations
 -------------
 
+* Type objects now have a cache of methods that can reduce
+  the amount of work required to find the correct method implementation
+  for a particular class; once cached, the interpreter doesn't need to
+  traverse base classes to figure out the right method to call.  
+  The cache is cleared if a base class or the class itself is modified, 
+  so the cache should remain correct even in the face of Python's dynamic 
+  nature.
+  (Original optimization implemented by Armin Rigo, updated for 
+  Python 2.6 by Kevin Jacobs.) 
+
+  .. Patch 1700288
+
+* All of the functions in the :mod:`struct` module have been rewritten in
+  C, thanks to work at the Need For Speed sprint.
+  (Contributed by Raymond Hettinger.)
+
 * Internally, a bit is now set in type objects to indicate some of the standard
   built-in types.  This speeds up checking if an object is a subclass of one of
   these types.  (Contributed by Neal Norwitz.)
 
+* Unicode strings now uses faster code for detecting
+  whitespace and line breaks; this speeds up the :meth:`split` method 
+  by about 25% and :meth:`splitlines` by 35%.
+  (Contributed by Antoine Pitrou.)  Memory usage is reduced
+  by using pymalloc for the Unicode string's data.
+
+* The ``with`` statement now stores the :meth:`__exit__` method on the stack,
+  producing a small speedup.  (Implemented by Nick Coghlan.)
+
+* To reduce memory usage, the garbage collector will now clear internal
+  free lists when garbage-collecting the highest generation of objects.
+  This may return memory to the OS sooner.
+
 The net result of the 2.6 optimizations is that Python 2.6 runs the pystone
 benchmark around XX% faster than Python 2.5.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 New, Improved, and Deprecated Modules
@@ -483,48 +1102,158 @@
 by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more
 complete list of changes, or look through the CVS logs for all the details.
 
-* A new data type in the :mod:`collections` module: :class:`NamedTuple(typename,
+* The :mod:`bsddb.dbshelve` module now uses the highest pickling protocol
+  available, instead of restricting itself to protocol 1.
+  (Contributed by W. Barnes.)
+
+  .. Patch 1551443
+
+* A new data type in the :mod:`collections` module: :class:`namedtuple(typename,
   fieldnames)` is a factory function that creates subclasses of the standard tuple
   whose fields are accessible by name as well as index.  For example::
 
-     var_type = collections.NamedTuple('variable', 
-                  'id name type size')
-     var = var_type(1, 'frequency', 'int', 4)
+     >>> var_type = collections.namedtuple('variable', 
+     ...             'id name type size')
+     # Names are separated by spaces or commas.
+     # 'id, name, type, size' would also work.
+     >>> var_type._fields
+     ('id', 'name', 'type', 'size')
+
+     >>> var = var_type(1, 'frequency', 'int', 4)
+     >>> print var[0], var.id		# Equivalent
+     1 1
+     >>> print var[2], var.type          # Equivalent
+     int int
+     >>> var._asdict()
+     {'size': 4, 'type': 'int', 'id': 1, 'name': 'frequency'}
+     >>> v2 = var._replace(name='amplitude')
+     >>> v2
+     variable(id=1, name='amplitude', type='int', size=4)
+
+  Where the new :class:`namedtuple` type proved suitable, the standard
+  library has been modified to return them.  For example, 
+  the :meth:`Decimal.as_tuple` method now returns a named tuple with 
+  :attr:`sign`, :attr:`digits`, and :attr:`exponent` fields.
+
+  (Contributed by Raymond Hettinger.)
 
-     print var[0], var.id		# Equivalent
-     print var[2], var.type          # Equivalent
+* Another change to the :mod:`collections` module is that the 
+  :class:`deque` type now supports an optional *maxlen* parameter;
+  if supplied, the deque's size will be restricted to no more 
+  than *maxlen* items.  Adding more items to a full deque causes
+  old items to be discarded.
+
+  ::
+
+    >>> from collections import deque
+    >>> dq=deque(maxlen=3)
+    >>> dq
+    deque([], maxlen=3)
+    >>> dq.append(1) ; dq.append(2) ; dq.append(3)
+    >>> dq
+    deque([1, 2, 3], maxlen=3)
+    >>> dq.append(4)
+    >>> dq
+    deque([2, 3, 4], maxlen=3)
 
   (Contributed by Raymond Hettinger.)
 
+* The :mod:`ctypes` module now supports a :class:`c_bool` datatype 
+  that represents the C99 ``bool`` type.  (Contributed by David Remahl.)
+
+  .. Patch 1649190
+
+  The :mod:`ctypes` string, buffer and array types also have improved
+  support for extended slicing syntax,
+  where various combinations of ``(start, stop, step)`` are supplied.
+  (Implemented by Thomas Wouters.)
+
+  .. Revision 57769
+
 * A new method in the :mod:`curses` module: for a window, :meth:`chgat` changes
-  the display characters for a  certain number of characters on a single line. ::
+  the display characters for a  certain number of characters on a single line.
+  (Contributed by Fabian Kreutz.)
+  ::
 
      # Boldface text starting at y=0,x=21 
      # and affecting the rest of the line.
      stdscr.chgat(0,21, curses.A_BOLD)  
 
-  (Contributed by Fabian Kreutz.)
+  The :class:`Textbox` class in the :mod:`curses.textpad` module
+  now supports editing in insert mode as well as overwrite mode.
+  Insert mode is enabled by supplying a true value for the *insert_mode*
+  parameter when creating the :class:`Textbox` instance.
+
+* The :mod:`datetime` module's :meth:`strftime` methods now support a
+  ``%f`` format code that expands to the number of microseconds in the
+  object, zero-padded on
+  the left to six places.  (Contributed by XXX.)
+
+  .. Patch 1158
+
+* The :mod:`decimal` module was updated to version 1.66 of 
+  `the General Decimal Specification <http://www2.hursley.ibm.com/decimal/decarith.html>`__.  New features
+  include some methods for some basic mathematical functions such as
+  :meth:`exp` and :meth:`log10`::
+
+    >>> Decimal(1).exp()
+    Decimal("2.718281828459045235360287471")
+    >>> Decimal("2.7182818").ln()
+    Decimal("0.9999999895305022877376682436")
+    >>> Decimal(1000).log10()
+    Decimal("3")
+
+  The :meth:`as_tuple` method of :class:`Decimal` objects now returns a 
+  named tuple with :attr:`sign`, :attr:`digits`, and :attr:`exponent` fields.
+  
+  (Implemented by Facundo Batista and Mark Dickinson.  Named tuple
+  support added by Raymond Hettinger.)
+
+* The :mod:`difflib` module's :class:`SequenceMatcher` class 
+  now returns named tuples representing matches. 
+  In addition to behaving like tuples, the returned values
+  also have :attr:`a`, :attr:`b`, and :attr:`size` attributes.
+  (Contributed by Raymond Hettinger.)
 
 * An optional ``timeout`` parameter was added to the
   :class:`ftplib.FTP` class constructor as well as the :meth:`connect`
   method, specifying a timeout measured in seconds.  (Added by Facundo
-  Batista.)
+  Batista.)  Also, the :class:`FTP` class's 
+  :meth:`storbinary` and :meth:`storlines`
+  now take an optional *callback* parameter that will be called with 
+  each block of data after the data has been sent.
+  (Contributed by Phil Schwartz.)
+
+  .. Patch 1221598
+
+* The :func:`reduce` built-in function is also available in the 
+  :mod:`functools` module.  In Python 3.0, the built-in is dropped and it's
+  only available from :mod:`functools`; currently there are no plans
+  to drop the built-in in the 2.x series.  (Patched by 
+  Christian Heimes.)
+
+  .. Patch 1739906
 
 * The :func:`glob.glob` function can now return Unicode filenames if 
   a Unicode path was used and Unicode filenames are matched within the directory.
 
-  .. % Patch #1001604
+  .. Patch #1001604
 
 * The :mod:`gopherlib` module has been removed.
 
-* A new function in the :mod:`heapq` module: ``merge(iter1, iter2, ...)``
-  takes any number of iterables that return data  *in sorted order*,  and  returns
-  a new iterator that returns the contents of all the iterators, also in sorted
-  order.  For example::
+* A new function in the :mod:`heapq` module: ``merge(iter1, iter2, ...)`` 
+  takes any number of iterables that return data *in sorted
+  order*, and returns a new iterator that returns the contents of all
+  the iterators, also in sorted order.  For example::
 
      heapq.merge([1, 3, 5, 9], [2, 8, 16]) ->
        [1, 2, 3, 5, 8, 9, 16]
 
+  Another new function, ``heappushpop(heap, item)``,
+  pushes *item* onto *heap*, then pops off and returns the smallest item. 
+  This is more efficient than making a call to :func:`heappush` and then
+  :func:`heappop`.
+
   (Contributed by Raymond Hettinger.)
 
 * An optional ``timeout`` parameter was added to the
@@ -532,30 +1261,157 @@
   class constructors, specifying a timeout measured in seconds.
   (Added by Facundo Batista.)
 
-* A new function in the :mod:`itertools` module: ``izip_longest(iter1, iter2,
-  ...[, fillvalue])`` makes tuples from each of the elements; if some of the
-  iterables are shorter than others, the missing values  are set to *fillvalue*.
-  For example::
+* Most of the :mod:`inspect` module's functions, such as 
+  :func:`getmoduleinfo` and :func:`getargs`, now return named tuples.  
+  In addition to behaving like tuples, the elements of the  return value
+  can also be accessed as attributes.
+  (Contributed by Raymond Hettinger.)
+
+  Some new functions in the module include 
+  :func:`isgenerator`, :func:`isgeneratorfunction`, 
+  and :func:`isabstract`.
+
+* The :mod:`itertools` module gained several new functions.
+
+  ``izip_longest(iter1, iter2, ...[, fillvalue])`` makes tuples from
+  each of the elements; if some of the iterables are shorter than
+  others, the missing values are set to *fillvalue*.  For example::
 
      itertools.izip_longest([1,2,3], [1,2,3,4,5]) ->
        [(1, 1), (2, 2), (3, 3), (None, 4), (None, 5)]
 
-  (Contributed by Raymond Hettinger.)
+  ``product(iter1, iter2, ..., [repeat=N])`` returns the Cartesian product
+  of the supplied iterables, a set of tuples containing
+  every possible combination of the elements returned from each iterable. ::
+
+     itertools.product([1,2,3], [4,5,6]) ->
+       [(1, 4), (1, 5), (1, 6), 
+	(2, 4), (2, 5), (2, 6), 
+	(3, 4), (3, 5), (3, 6)]
+
+  The optional *repeat* keyword argument is used for taking the
+  product of an iterable or a set of iterables with themselves, 
+  repeated *N* times.  With a single iterable argument, *N*-tuples
+  are returned::
+
+     itertools.product([1,2], repeat=3)) ->
+       [(1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2), 
+        (2, 1, 1), (2, 1, 2), (2, 2, 1), (2, 2, 2)]
+
+  With two iterables, *2N*-tuples are returned. ::
+
+     itertools(product([1,2], [3,4], repeat=2) ->
+       [(1, 3, 1, 3), (1, 3, 1, 4), (1, 3, 2, 3), (1, 3, 2, 4), 
+        (1, 4, 1, 3), (1, 4, 1, 4), (1, 4, 2, 3), (1, 4, 2, 4), 
+        (2, 3, 1, 3), (2, 3, 1, 4), (2, 3, 2, 3), (2, 3, 2, 4), 
+        (2, 4, 1, 3), (2, 4, 1, 4), (2, 4, 2, 3), (2, 4, 2, 4)]
+
+  ``combinations(iterable, r)`` returns sub-sequences of length *r* from
+  the elements of *iterable*. ::
+
+    itertools.combinations('123', 2) ->
+      [('1', '2'), ('1', '3'), ('2', '3')]
+
+    itertools.combinations('123', 3) ->
+      [('1', '2', '3')]
+
+    itertools.combinations('1234', 3) ->
+      [('1', '2', '3'), ('1', '2', '4'), ('1', '3', '4'), 
+       ('2', '3', '4')]
+
+  ``permutations(iter[, r])`` returns all the permutations of length *r* of
+  the iterable's elements.  If *r* is not specified, it will default to the 
+  number of elements produced by the iterable.
+
+    itertools.permutations([1,2,3,4], 2) ->
+      [(1, 2), (1, 3), (1, 4), 
+       (2, 1), (2, 3), (2, 4), 
+       (3, 1), (3, 2), (3, 4), 
+       (4, 1), (4, 2), (4, 3)]
+
+  ``itertools.chain(*iterables)` is an existing function in
+  :mod:`itertools` that gained a new constructor in Python 2.6.
+  ``itertools.chain.from_iterable(iterable)`` takes a single 
+  iterable that should return other iterables.  :func:`chain` will
+  then return all the elements of the first iterable, then
+  all the elements of the second, and so on. ::
+
+    chain.from_iterable([[1,2,3], [4,5,6]]) ->
+       [1, 2, 3, 4, 5, 6]
+  
+  (All contributed by Raymond Hettinger.)
+
+* The :mod:`logging` module's :class:`FileHandler` class 
+  and its subclasses :class:`WatchedFileHandler`, :class:`RotatingFileHandler`,
+  and :class:`TimedRotatingFileHandler` now 
+  have an optional *delay* parameter to its constructor.  If *delay* 
+  is true, opening of the log file is deferred until the first
+  :meth:`emit` call is made.  (Contributed by Vinay Sajip.)
 
 * The :mod:`macfs` module has been removed.  This in turn required the
   :func:`macostools.touched` function to be removed because it depended on the
   :mod:`macfs` module.
 
-  .. % Patch #1490190
+  .. Patch #1490190
+
+* :class:`mmap` objects now have a :meth:`rfind` method that finds
+  a substring, beginning at the end of the string and searching
+  backwards.  The :meth:`find` method
+  also gained an *end* parameter containing the index at which to stop
+  the forward search.
+  (Contributed by John Lenton.)
+
+* The :mod:`new` module has been removed from Python 3.0.
+  Importing it therefore
+  triggers a warning message when Python is running in 3.0-warning
+  mode.
+
+* The :mod:`operator` module gained a 
+  :func:`methodcaller` function that takes a name and an optional 
+  set of arguments, returning a callable that will call 
+  the named function on any arguments passed to it.  For example::
+
+    >>> # Equivalent to lambda s: s.replace('old', 'new')
+    >>> replacer = operator.methodcaller('replace', 'old', 'new')
+    >>> replacer('old wine in old bottles')
+    'new wine in new bottles'
+   
+  (Contributed by Georg Brandl, after a suggestion by Gregory Petrosyan.)
+
+  The :func:`attrgetter` function now accepts dotted names and performs
+  the corresponding attribute lookups::
+
+    >>> inst_name = operator.attrgetter('__class__.__name__')
+    >>> inst_name('')
+    'str'
+    >>> inst_name(help)
+    '_Helper'
+
+  (Contributed by Georg Brandl, after a suggestion by Barry Warsaw.)
+
+* New functions in the :mod:`os` module include 
+  ``fchmod(fd, mode)``,   ``fchown(fd, uid, gid)``,  
+  and ``lchmod(path, mode)``, on operating systems that support these
+  functions. :func:`fchmod` and :func:`fchown` let you change the mode
+  and ownership of an opened file, and :func:`lchmod` changes the mode
+  of a symlink.
 
-* The :func:`os.walk` function now has a "followlinks" parameter. If
+  (Contributed by Georg Brandl and Christian Heimes.)
+
+* The :func:`os.walk` function now has a ``followlinks`` parameter. If
   set to True, it will follow symlinks pointing to directories and
   visit the directory's contents.  For backward compatibility, the
   parameter's default value is false.  Note that the function can fall
   into an infinite recursion if there's a symlink that points to a
   parent directory.
        
-  .. % Patch 1273829
+  .. Patch 1273829
+
+* The ``os.environ`` object's :meth:`clear` method will now unset the 
+  environment variables using :func:`os.unsetenv` in addition to clearing
+  the object's keys.  (Contributed by Martin Horcicka.)
+
+  .. Patch #1181 
 
 * In the :mod:`os.path` module, the :func:`splitext` function
   has been changed to not split on leading period characters.
@@ -563,20 +1419,32 @@
   For example, ``os.path.splitext('.ipython')``
   now returns ``('.ipython', '')`` instead of ``('', '.ipython')``.
 
-  .. % Bug #115886
+  .. Bug #115886
 
   A new function, :func:`relpath(path, start)` returns a relative path
   from the ``start`` path, if it's supplied, or from the current
   working directory to the destination ``path``.  (Contributed by
   Richard Barran.)
 
-  .. % Patch 1339796
+  .. Patch 1339796
 
   On Windows, :func:`os.path.expandvars` will now expand environment variables 
   in the form "%var%", and "~user" will be expanded into the 
-  user's home directory path.  (Contributed by XXX.)
+  user's home directory path.  (Contributed by Josiah Carlson.)
+
+  .. Patch 957650
 
-  .. % Patch 957650
+* The Python debugger provided by the :mod:`pdb` module 
+  gained a new command: "run" restarts the Python program being debugged,
+  and can optionally take new command-line arguments for the program.
+  (Contributed by Rocky Bernstein.)
+
+  .. Patch #1393667
+
+* The :mod:`pickletools` module now has an :func:`optimize` function 
+  that takes a string containing a pickle and removes some unused 
+  opcodes, returning a shorter pickle that contains the same data structure.
+  (Contributed by Raymond Hettinger.)
 
 * New functions in the :mod:`posix` module: :func:`chflags` and :func:`lchflags`
   are wrappers for the corresponding system calls (where they're available).
@@ -585,8 +1453,81 @@
   changed and :const:`UF_APPEND` to indicate that data can only be appended to the
   file.  (Contributed by M. Levinson.)
 
+  ``os.closerange(*low*, *high*)`` efficiently closes all file descriptors
+  from *low* to *high*, ignoring any errors and not including *high* itself.
+  This function is now used by the :mod:`subprocess` module to make starting
+  processes faster.  (Contributed by Georg Brandl.)
+
+  .. Patch #1663329  
+
+* The :mod:`pyexpat` module's :class:`Parser` objects now allow setting
+  their :attr:`buffer_size` attribute to change the size of the buffer 
+  used to hold character data.
+  (Contributed by Achim Gaedke.)
+
+  .. Patch 1137
+
+* The :mod:`Queue` module now provides queue classes that retrieve entries
+  in different orders.  The :class:`PriorityQueue` class stores 
+  queued items in a heap and retrieves them in priority order, 
+  and :class:`LifoQueue` retrieves the most recently added entries first,
+  meaning that it behaves like a stack.
+  (Contributed by Raymond Hettinger.)
+
+* The :mod:`random` module's :class:`Random` objects can
+  now be pickled on a 32-bit system and unpickled on a 64-bit
+  system, and vice versa.  Unfortunately, this change also means
+  that Python 2.6's :class:`Random` objects can't be unpickled correctly
+  on earlier versions of Python.
+  (Contributed by Shawn Ligocki.)
+
+  .. Issue 1727780
+
+* Long regular expression searches carried out by the  :mod:`re`
+  module will now check for signals being delivered, so especially
+  long searches can now be interrupted.
+  (Contributed by Josh Hoyt and Ralf Schmitt.)
+
+  .. Patch 846388
+
 * The :mod:`rgbimg` module has been removed.
 
+* The :mod:`sched` module's :class:`scheduler` instances now 
+  have a read-only :attr:`queue` attribute that returns the 
+  contents of the scheduler's queue, represented as a list of
+  named tuples with the fields ``(time, priority, action, argument)``.
+  (Contributed by Raymond Hettinger XXX check.)
+
+  .. Patch 1861
+
+* The :mod:`sets` module has been deprecated; it's better to 
+  use the built-in :class:`set` and :class:`frozenset` types.
+
+* Integrating signal handling with GUI handling event loops 
+  like those used by Tkinter or GTk+ has long been a problem; most
+  software ends up polling, waking up every fraction of a second.
+  The :mod:`signal` module can now make this more efficient.
+  Calling ``signal.set_wakeup_fd(fd)`` sets a file descriptor
+  to be used; when a signal is received, a byte is written to that 
+  file descriptor.  There's also a C-level function,
+  :cfunc:`PySignal_SetWakeupFd`, for setting the descriptor.
+
+  Event loops will use this by opening a pipe to create two descriptors,
+  one for reading and one for writing.  The writeable descriptor
+  will be passed to :func:`set_wakeup_fd`, and the readable descriptor
+  will be added to the list of descriptors monitored by the event loop via
+  :cfunc:`select` or :cfunc:`poll`.
+  On receiving a signal, a byte will be written and the main event loop 
+  will be woken up, without the need to poll.
+
+  (Contributed by Adam Olsen.)
+
+  .. Patch 1583
+
+  The :func:`siginterrupt` function is now available from Python code,
+  and allows changing whether signals can interrupt system calls or not.
+  (Contributed by Ralf Schmitt.)
+
 * The :mod:`smtplib` module now supports SMTP over SSL thanks to the
   addition of the :class:`SMTP_SSL` class. This class supports an
   interface identical to the existing :class:`SMTP` class.   Both 
@@ -602,7 +1543,66 @@
   added by Facundo Batista; LMTP implemented by Leif
   Hedstrom.)
 
-  .. % Patch #957003
+  .. Patch #957003
+
+* In the :mod:`smtplib` module, SMTP.starttls() now complies with :rfc:`3207`
+  and forgets any knowledge obtained from the server not obtained from
+  the TLS negotiation itself.  (Patch contributed by Bill Fenner.)
+
+  .. Issue 829951
+
+* The :mod:`socket` module now supports TIPC (http://tipc.sf.net),
+  a high-performance non-IP-based protocol designed for use in clustered
+  environments.  TIPC addresses are 4- or 5-tuples.
+  (Contributed by Alberto Bertogli.)
+
+  .. Patch #1646
+
+* The base classes in the :mod:`SocketServer` module now support
+  calling a :meth:`handle_timeout` method after a span of inactivity 
+  specified by the server's :attr:`timeout` attribute.  (Contributed 
+  by Michael Pomraning.)
+
+  .. Patch #742598
+
+* The :mod:`struct` module now supports the C99 :ctype:`_Bool` type,
+  using the format character ``'?'``. 
+  (Contributed by David Remahl.)
+ 
+* A new variable in the :mod:`sys` module,
+  :attr:`float_info`, is an object
+  containing information about the platform's floating-point support
+  derived from the :file:`float.h` file.  Attributes of this object
+  include 
+  :attr:`mant_dig` (number of digits in the mantissa), :attr:`epsilon`
+  (smallest difference between 1.0 and the next largest value
+  representable), and several others.  (Contributed by Christian Heimes.)
+
+  .. Patch 1534
+
+  Another new variable, :attr:`dont_write_bytecode`, controls whether Python
+  writes any :file:`.pyc` or :file:`.pyo` files on importing a module.
+  If this variable is true, the compiled files are not written.  The
+  variable is initially set on start-up by supplying the :option:`-B`
+  switch to the Python interpreter, or by setting the
+  :envvar:`PYTHONDONTWRITEBYTECODE` environment variable before
+  running the interpreter.  Python code can subsequently 
+  change the value of this variable to control whether bytecode files
+  are written or not.
+  (Contributed by Neal Norwitz and Georg Brandl.)
+
+  Information about the command-line arguments supplied to the Python 
+  interpreter are available as attributes of a ``sys.flags`` named 
+  tuple.  For example, the :attr:`verbose` attribute is true if Python 
+  was executed in verbose mode, :attr:`debug` is true in debugging mode, etc.
+  These attributes are all read-only.
+  (Contributed by Christian Heimes.)
+
+  It's now possible to determine the current profiler and tracer functions
+  by calling :func:`sys.getprofile` and :func:`sys.gettrace`.  
+  (Contributed by Georg Brandl.)
+
+  .. Patch #1648
 
 * The :mod:`tarfile` module now supports POSIX.1-2001 (pax) and
   POSIX.1-1988 (ustar) format tarfiles, in addition to the GNU tar
@@ -638,7 +1638,19 @@
   behaviour can now be changed by passing ``delete=False`` to the 
   constructor.  (Contributed by Damien Miller.)
 
-  .. % Patch #1537850
+  .. Patch #1537850
+
+  A new class, :class:`SpooledTemporaryFile`, behaves like 
+  a temporary file but stores its data in memory until a maximum size is 
+  exceeded.  On reaching that limit, the contents will be written to 
+  an on-disk temporary file.  (Contributed by Dustin J. Mitchell.)
+
+  The :class:`NamedTemporaryFile` and :class:`SpooledTemporaryFile` classes
+  both work as context managers, so you can write 
+  ``with tempfile.NamedTemporaryFile() as tmp: ...``.
+  (Contributed by Alexander Belopolsky.)
+
+  .. Issue #2021
 
 * The :mod:`test.test_support` module now contains a
   :func:`EnvironmentVarGuard`
@@ -675,7 +1687,9 @@
        whitespace.
     >>> 
 
-  .. % Patch #1581073
+  (Contributed by Dwayne Bailey.)
+
+  .. Patch #1581073
 
 * The :mod:`timeit` module now accepts callables as well as strings 
   for the statement being timed and for the setup code.
@@ -685,7 +1699,7 @@
   ``timeit(stmt, setup, time, number)`` create an instance and call
   the corresponding method. (Contributed by Erik Demaine.)
 
-  .. % Patch #1533909
+  .. Patch #1533909
 
 * An optional ``timeout`` parameter was added to the
   :func:`urllib.urlopen` function and the
@@ -701,10 +1715,107 @@
 
   (Added by Facundo Batista.) 
 
-.. % ======================================================================
-.. % whole new modules get described in \subsections here
+* The XML-RPC classes :class:`SimpleXMLRPCServer` and :class:`DocXMLRPCServer`
+  classes can now be prevented from immediately opening and binding to
+  their socket by passing True as the ``bind_and_activate``
+  constructor parameter.  This can be used to modify the instance's
+  :attr:`allow_reuse_address` attribute before calling the 
+  :meth:`server_bind` and :meth:`server_activate` methods to 
+  open the socket and begin listening for connections.
+  (Contributed by Peter Parente.)
+
+  .. Patch 1599845
+
+  :class:`SimpleXMLRPCServer` also has a :attr:`_send_traceback_header`
+  attribute; if true, the exception and formatted traceback are returned 
+  as HTTP headers "X-Exception" and "X-Traceback".  This feature is 
+  for debugging purposes only and should not be used on production servers
+  because the tracebacks could possibly reveal passwords or other sensitive
+  information.  (Contributed by Alan McIntyre as part of his 
+  project for Google's Summer of Code 2007.)
+
+* The :mod:`zipfile` module's :class:`ZipFile` class now has 
+  :meth:`extract` and :meth:`extractall` methods that will unpack 
+  a single file or all the files in the archive to the current directory, or 
+  to a specified directory::
+
+    z = zipfile.ZipFile('python-251.zip')
+
+    # Unpack a single file, writing it relative to the /tmp directory.
+    z.extract('Python/sysmodule.c', '/tmp')
+
+    # Unpack all the files in the archive.
+    z.extractall()
+
+  (Contributed by Alan McIntyre.)
+
+  .. Patch 467924
+
+.. ======================================================================
+.. whole new modules get described in subsections here
 
-.. % ======================================================================
+Improved SSL Support
+--------------------------------------------------
+
+Bill Janssen made extensive improvements to Python 2.6's support for
+SSL.
+
+XXX use ssl.sslsocket - subclass of socket.socket.
+
+XXX Can specify if certificate is required, and obtain certificate info
+by calling getpeercert method.
+
+XXX sslwrap() behaves like socket.ssl
+
+XXX Certain features require the OpenSSL package to be installed, notably
+  the 'openssl' binary.
+
+.. seealso::
+
+   SSL module documentation.
+
+
+.. ======================================================================
+
+plistlib: A Property-List Parser
+--------------------------------------------------
+
+A commonly-used format on MacOS X is the ``.plist`` format, 
+which stores basic data types (numbers, strings, lists, 
+and dictionaries) and serializes them into an XML-based format.
+(It's a lot like the XML-RPC serialization of data types.)
+
+Despite being primarily used on MacOS X, the format 
+has nothing Mac-specific about it and the Python implementation works
+on any platform that Python supports, so the :mod:`plistlib` module
+has been promoted to the standard library.
+
+Using the module is simple::
+
+    import sys
+    import plistlib
+    import datetime
+
+    # Create data structure
+    data_struct = dict(lastAccessed=datetime.datetime.now(),
+		       version=1,
+		       categories=('Personal', 'Shared', 'Private'))
+
+    # Create string containing XML.
+    plist_str = plistlib.writePlistToString(data_struct)
+    new_struct = plistlib.readPlistFromString(plist_str)
+    print data_struct
+    print new_struct
+
+    # Write data structure to a file and read it back.
+    plistlib.writePlist(data_struct, '/tmp/customizations.plist')
+    new_struct = plistlib.readPlist('/tmp/customizations.plist')
+
+    # read/writePlist accepts file-like objects as well as paths.
+    plistlib.writePlist(data_struct, sys.stdout)
+   
+
+.. ======================================================================
 
 
 Build and C API Changes
@@ -712,17 +1823,102 @@
 
 Changes to Python's build process and to the C API include:
 
-* Detailed changes are listed here.
-
-.. % ======================================================================
-
+* Python 2.6 can be built with Microsoft Visual Studio 2008.
+  See the :file:`PCbuild9` directory for the build files.
+  (Implemented by Christian Heimes.)
+
+* Python now can only be compiled with C89 compilers (after 19
+  years!).  This means that the Python source tree can now drop its
+  own implementations of :cfunc:`memmove` and :cfunc:`strerror`, which
+  are in the C89 standard library.
+
+* The BerkeleyDB module now has a C API object, available as 
+  ``bsddb.db.api``.   This object can be used by other C extensions
+  that wish to use the :mod:`bsddb` module for their own purposes.
+  (Contributed by Duncan Grisby.)
+
+  .. Patch 1551895
+
+* Several functions return information about the platform's 
+  floating-point support.  :cfunc:`PyFloat_GetMax` returns
+  the maximum representable floating point value,
+  and :cfunc:`PyFloat_GetMin` returns the minimum 
+  positive value.  :cfunc:`PyFloat_GetInfo` returns a dictionary 
+  containing more information from the :file:`float.h` file, such as
+  ``"mant_dig"`` (number of digits in the mantissa), ``"epsilon"``
+  (smallest difference between 1.0 and the next largest value
+  representable), and several others.
+  (Contributed by Christian Heimes.)
+
+  .. Issue 1534
+
+* Python's C API now includes two functions for case-insensitive string
+  comparisons, ``PyOS_stricmp(char*, char*)``
+  and ``PyOS_strnicmp(char*, char*, Py_ssize_t)``.
+  (Contributed by Christian Heimes.)
+
+  .. Issue 1635
+
+* Some macros were renamed in both 3.0 and 2.6 to make it clearer that
+  they are macros,
+  not functions.  :cmacro:`Py_Size()` became :cmacro:`Py_SIZE()`,
+  :cmacro:`Py_Type()` became :cmacro:`Py_TYPE()`, and
+  :cmacro:`Py_Refcnt()` became :cmacro:`Py_REFCNT()`.  
+  The mixed-case macros are still available
+  in Python 2.6 for backward compatibility.
+
+  .. Issue 1629
+
+* Distutils now places C extensions it builds in a 
+  different directory when running on a debug version of Python.
+  (Contributed by Collin Winter.)
+
+  .. Patch 1530959
+
+* Several basic data types, such as integers and strings, maintain
+  internal free lists of objects that can be re-used.  The data
+  structures for these free lists now follow a naming convention: the
+  variable is always named ``free_list``, the counter is always named
+  ``numfree``, and a macro :cmacro:`Py<typename>_MAXFREELIST` is
+  always defined.
+
+.. ======================================================================
+
+
+Port-Specific Changes: Windows
+-----------------------------------
+
+* The :mod:`msvcrt` module now supports 
+  both the normal and wide char variants of the console I/O
+  API.  The :func:`getwch` function reads a keypress and returns a Unicode 
+  value, as does the :func:`getwche` function.  The :func:`putwch` function
+  takes a Unicode character and writes it to the console.
+  (Contributed by Christian Heimes.)
 
-Port-Specific Changes
----------------------
+* :func:`os.path.expandvars` will now expand environment variables 
+  in the form "%var%", and "~user" will be expanded into the 
+  user's home directory path.  (Contributed by Josiah Carlson.)
 
-Platform-specific changes go here.
+* The :mod:`socket` module's socket objects now have an 
+  :meth:`ioctl` method that provides a limited interface to the 
+  :cfunc:`WSAIoctl` system interface.
+
+* The :mod:`_winreg` module now has a function, 
+  :func:`ExpandEnvironmentStrings`, 
+  that expands environment variable references such as ``%NAME%``
+  in an input string.  The handle objects provided by this
+  module now support the context protocol, so they can be used 
+  in :keyword:`with` statements. (Contributed by Christian Heimes.)
+
+* The new default compiler on Windows is Visual Studio 2008 (VS 9.0). The 
+  build directories for Visual Studio 2003 (VS7.1) and 2005 (VS8.0)
+  were moved into the PC/ directory. The new PCbuild directory supports
+  cross compilation for X64, debug builds and Profile Guided Optimization
+  (PGO). PGO builds are roughly 10% faster than normal builds.
+  (Contributed by Christian Heimes with help from Amaury Forgeot d'Arc and
+  Martin von Loewis.)
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _section-other:
@@ -730,28 +1926,76 @@
 Other Changes and Fixes
 =======================
 
-As usual, there were a bunch of other improvements and bugfixes scattered
-throughout the source tree.  A search through the change logs finds there were
-XXX patches applied and YYY bugs fixed between Python 2.5 and 2.6.  Both figures
-are likely to be underestimates.
+As usual, there were a bunch of other improvements and bugfixes
+scattered throughout the source tree.  A search through the change
+logs finds there were XXX patches applied and YYY bugs fixed between
+Python 2.5 and 2.6.  Both figures are likely to be underestimates.
 
 Some of the more notable changes are:
 
-* Details go here.
+* It's now possible to prevent Python from writing any :file:`.pyc` 
+  or :file:`.pyo` files by either supplying the :option:`-B` switch
+  or setting the :envvar:`PYTHONDONTWRITEBYTECODE` environment variable
+  to any non-empty string when running the Python interpreter.  These
+  are also used to set the :data:`sys.dont_write_bytecode` attribute;
+  Python code can change this variable to control whether bytecode
+  files are subsequently written.
+  (Contributed by Neal Norwitz and Georg Brandl.)
 
-.. % ======================================================================
+.. ======================================================================
 
 
 Porting to Python 2.6
 =====================
 
-This section lists previously described changes that may require changes to your
+This section lists previously described changes, and a few
+esoteric bugfixes, that may require changes to your
 code:
 
-* The :mod:`socket` module exception :exc:`socket.error` now inherits from 
-  :exc:`IOError`.
+* The :meth:`__init__` method of :class:`collections.deque`
+  now clears any existing contents of the deque
+  before adding elements from the iterable.  This change makes the
+  behavior match that of ``list.__init__()``.  
+
+* The :class:`Decimal` constructor now accepts leading and trailing 
+  whitespace when passed a string.  Previously it would raise an
+  :exc:`InvalidOperation` exception.  On the other hand, the
+  :meth:`create_decimal` method of :class:`Context` objects now
+  explicitly disallows extra whitespace, raising a 
+  :exc:`ConversionSyntax` exception.
+
+* Due to an implementation accident, if you passed a file path to 
+  the built-in  :func:`__import__` function, it would actually import
+  the specified file.  This was never intended to work, however, and 
+  the implementation now explicitly checks for this case and raises 
+  an :exc:`ImportError`.
+
+* The :mod:`socket` module exception :exc:`socket.error` now inherits
+  from :exc:`IOError`.  Previously it wasn't a subclass of
+  :exc:`StandardError` but now it is, through :exc:`IOError`.
+  (Implemented by Gregory P. Smith.)
+
+  .. Issue 1706815
+
+* The :mod:`xmlrpclib` module no longer automatically converts
+  :class:`datetime.date` and :class:`datetime.time` to the 
+  :class:`xmlrpclib.DateTime` type; the conversion semantics were
+  not necessarily correct for all applications.  Code using
+  :mod:`xmlrpclib` should convert :class:`date` and :class:`time` 
+  instances.
+
+  .. Issue 1330538
+
+* In 3.0-warning mode, inequality comparisons between two dictionaries
+  or two objects that don't implement comparison methods are reported
+  as warnings.  ``dict1 == dict2`` still works, but ``dict1 < dict2``
+  is being phased out.
+  
+  Comparisons between cells, which are an implementation detail of Python's
+  scoping rules, also cause warnings because such comparisons are forbidden
+  entirely in 3.0.
 
-.. % ======================================================================
+.. ======================================================================
 
 
 .. _acks:

Modified: python/branches/py3k-importlib/Doc/whatsnew/3.0.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/whatsnew/3.0.rst	(original)
+++ python/branches/py3k-importlib/Doc/whatsnew/3.0.rst	Thu Mar 27 00:48:05 2008
@@ -79,7 +79,7 @@
 remains syntactically valid that trips people up.  I'm also omitting
 changes to rarely used features.)
 
-* The ``print`` statement has been replaced with a ``print()`` function,
+* The ``print`` statement has been replaced with a :func:`print` function,
   with keyword arguments to replace most of the special syntax of the
   old ``print`` statement (PEP 3105).  Examples::
 
@@ -106,9 +106,9 @@
 
    There are <4294967296> possibilities!
 
-  Notes about the ``print()`` function:
+  Notes about the :func:`print` function:
 
-  * The ``print()`` function doesn't support the "softspace" feature of
+  * The :func:`print` function doesn't support the "softspace" feature of
     the old ``print`` statement.  For example, in Python 2.x,
     ``print "A\n", "B"`` would write ``"A\nB\n"``; but in Python 3.0,
     ``print("A\n", "B")`` writes ``"A\n B\n"``.
@@ -118,7 +118,7 @@
     ``print(x)`` instead!
 
   * When using the ``2to3`` source-to-source conversion tool, all
-    ``print`` statements are autmatically converted to ``print()``
+    ``print`` statements are autmatically converted to :func:`print`
     function calls, so this is mostly a non-issue for larger projects.
 
 * Python 3.0 uses strings and bytes instead of the Unicode strings and
@@ -131,93 +131,110 @@
   that if a file is opened using an incorrect mode or encoding, I/O
   will likely fail.
 
-* Bytes aren't hashable, and don't support certain operations like
-  ``b.lower()``, ``b.strip()`` or ``b.split()``.
-  For the latter two, use ``b.strip(b" \t\r\n\f")`` or
-  ``b.split(b" \t\r\n\f")``.
-
-* ``map()`` and ``filter()`` return iterators.  A quick fix is e.g.
+* :func:`map` and :func:`filter` return iterators.  A quick fix is e.g.
   ``list(map(...))``, but a better fix is often to use a list
-  comprehension (especially when the original code uses ``lambda``).
-  Particularly tricky is ``map()`` invoked for the side effects of the
+  comprehension (especially when the original code uses :keyword:`lambda`).
+  Particularly tricky is :func:`map` invoked for the side effects of the
   function; the correct transformation is to use a for-loop.
 
-* ``dict`` methods ``.keys()``, ``.items()`` and ``.values()`` return
-  views instead of lists.  For example, this no longer works:
-  ``k = d.keys(); k.sort()``.  Use ``k = sorted(d)`` instead.
+* :class:`dict` methods :meth:`dict.keys`, :meth:`dict.items` and
+  :meth:`dict.values` return views instead of lists.  For example, this no
+  longer works: ``k = d.keys(); k.sort()``.  Use ``k = sorted(d)`` instead.
+
+* :meth:`builtin.sorted` and :meth:`list.sort` no longer accept the *cmp*
+  argument providing a comparison function.  Use the *key* argument
+  instead. N.B. the *key* and *reverse* arguments are now "keyword-only".
 
 * ``1/2`` returns a float.  Use ``1//2`` to get the truncating behavior.
 
-* Code that unconditionally strips the trailing ``L`` from the ``repr()``
-  of a long integer will chop off the last digit instead.
+* The :func:`repr` of a long integer doesn't include the trailing ``L``
+  anymore, so code that unconditionally strips that character will
+  chop off the last digit instead.
 
 
 Strings and Bytes
 =================
 
-* There is only one string type; its name is ``str`` but its behavior
-  and implementation are more like ``unicode`` in 2.x.
+* There is only one string type; its name is :class:`str` but its behavior and
+  implementation are like :class:`unicode` in 2.x.
+
+* The :class:`basestring` superclass has been removed. The ``2to3`` tool
+  replaces every occurence of :class:`basestring` with :class:`str`.
 
-* PEP 358: There is a new type, ``bytes``, to represent binary data
-  (and encoded text, which is treated as binary data until you decide
-  to decode it).  The ``str`` and ``bytes`` types cannot be mixed; you
-  must always explicitly convert between them, using the ``.encode()``
-  (str -> bytes) or ``.decode()`` (bytes -> str) methods.  Comparing a
-  bytes and a str instance for equality raises a TypeError; this
-  catches common mistakes.
+* PEP 3137: There is a new type, :class:`bytes`, to represent binary data (and
+  encoded text, which is treated as binary data until you decide to decode it).
+  The :class:`str` and :class:`bytes` types cannot be mixed; you must always
+  explicitly convert between them, using the :meth:`str.encode` (str -> bytes)
+  or :meth:`bytes.decode` (bytes -> str) methods.
 
-* PEP 3112: Bytes literals.  E.g. b"abc".
+.. XXX add bytearray
+
+* PEP 3112: Bytes literals, e.g. ``b"abc"``, create :class:`bytes` instances.
 
 * PEP 3120: UTF-8 default source encoding.
 
-* PEP 3131: Non-ASCII identifiers.  (However, the standard library
-  remains ASCII-only with the exception of contributor names in
-  comments.)
+* PEP 3131: Non-ASCII identifiers.  (However, the standard library remains
+  ASCII-only with the exception of contributor names in comments.)
 
 * PEP 3116: New I/O Implementation.  The API is nearly 100% backwards
-  compatible, but completely reimplemented (currently mostly in
-  Python).  Also, binary files use bytes instead of strings.
+  compatible, but completely reimplemented (currently mostly in Python).  Also,
+  binary files use bytes instead of strings.
 
-* The ``StringIO`` and ``cStringIO`` modules are gone.  Instead,
-  import ``StringIO`` or ``BytesIO`` from the ``io`` module.
+* The :mod:`StringIO` and :mod:`cStringIO` modules are gone.  Instead, import
+  :class:`io.StringIO` or :class:`io.BytesIO`.
 
 
 PEP 3101: A New Approach to String Formatting
 =============================================
 
-XXX
+.. XXX expand this
+
+* A new system for built-in string formatting operations replaces the ``%``
+  string formatting operator.
 
 
-PEP 3106: Revamping ``.keys()``, ``.items()`` and ``.values()``
-===============================================================
+PEP 3106: Revamping dict :meth:`dict.keys`, :meth:`dict.items` and :meth:`dict.values`
+======================================================================================
 
-XXX
+.. XXX expand this
+
+* The :meth:`dict.iterkeys`, :meth:`dict.itervalues` and :meth:`dict.iteritems`
+  methods have been removed.
+
+* :meth:`dict.keys`, :meth:`dict.values` and :meth:`dict.items` return objects
+  with set behavior that reference the underlying dict.
 
 
 PEP 3107: Function Annotations
 ==============================
 
-XXX
+.. XXX expand this
+
+* A standardized way of annotating a function's parameters and return values.
 
 
 Exception Stuff
 ===============
 
-* PEP 352: Exceptions must derive from BaseException.  This is the
-  root of the exception hierarchy.
+* PEP 352: Exceptions must derive from :exc:`BaseException`.  This is the root
+  of the exception hierarchy.
 
-* StandardException was removed (already in 2.6).
+* :exc:`StandardError` was removed (already in 2.6).
 
-* Dropping sequence behavior (slicing!) and ``.message`` attribute of
+* Dropping sequence behavior (slicing!) and :attr:`message` attribute of
   exception instances.
 
-* PEP 3109: Raising exceptions.  You must now use ``raise
-  Exception(args)`` instead of ``raise Exception, args``.
+* PEP 3109: Raising exceptions.  You must now use ``raise Exception(args)``
+  instead of ``raise Exception, args``.
 
 * PEP 3110: Catching exceptions.
 
-* PEP 3134: Exception chaining.  (The ``__context__`` feature from the
-  PEP hasn't been implemented yet in 3.0a1.)
+* PEP 3134: Exception chaining.  (The :attr:`__context__` feature from the PEP
+  hasn't been implemented yet in 3.0a2.)
+
+* A few exception messages are improved when Windows fails to load an extension
+  module.  For example, ``error code 193`` is now ``%1 is not a valid Win32
+  application``.  Strings now deal with non-English locales.
 
 
 New Class and Metaclass Stuff
@@ -241,76 +258,97 @@
 Here are most of the changes that Python 3.0 makes to the core Python
 language and built-in functions.
 
-* Removed backticks (use ``repr()`` instead).
+* Removed backticks (use :func:`repr` instead).
 
 * Removed ``<>`` (use ``!=`` instead).
 
-* ``as`` and ``with`` are keywords.
+* ``!=`` now returns the opposite of ``==``, unless ``==`` returns
+  ``NotImplemented``.
 
-* PEP 237: ``long`` renamed to ``int``.  That is, there is only one
-  built-in integral type, named ``int``; but it behaves like the old
-  ``long`` type.
+* :keyword:`as` and :keyword:`with` are keywords.
+
+* ``True``, ``False``, and ``None`` are keywords.
+
+* PEP 237: :class:`long` renamed to :class:`int`.  That is, there is only one
+  built-in integral type, named :class:`int`; but it behaves like the old
+  :class:`long` type, with the exception that the literal suffix ``L`` is
+  neither supported by the parser nor produced by :func:`repr` anymore.
+  :data:`sys.maxint` was also removed since the int type has no maximum value
+  anymore.
 
 * PEP 238: int division returns a float.
 
-* The ordering operators behave differently: for example, ``x < y``
-  where ``x`` and ``y`` have incompatible types raises ``TypeError``
-  instead of returning a pseudo-random boolean.
-
-* ``__getslice__()`` and friends killed.  The syntax ``a[i:j]`` now
-  translates to ``a.__getitem__(slice(i, j))`` (or ``__setitem__``
-  or ``__delitem__``, depending on context).
-
-* PEP 3102: Keyword-only arguments.  Named parameters occurring after
-  ``*args`` in the parameter list *must* be specified using keyword
-  syntax in the call.  You can also use a bare ``*`` in the parameter
-  list to indicate that you don't accept a variable-length argument
-  list, but you do have keyword-only arguments.
+* The ordering operators behave differently: for example, ``x < y`` where ``x``
+  and ``y`` have incompatible types raises :exc:`TypeError` instead of returning
+  a pseudo-random boolean.
+
+* :meth:`__getslice__` and friends killed.  The syntax ``a[i:j]`` now translates
+  to ``a.__getitem__(slice(i, j))`` (or :meth:`__setitem__` or
+  :meth:`__delitem__`, depending on context).
+
+* PEP 3102: Keyword-only arguments.  Named parameters occurring after ``*args``
+  in the parameter list *must* be specified using keyword syntax in the call.
+  You can also use a bare ``*`` in the parameter list to indicate that you don't
+  accept a variable-length argument list, but you do have keyword-only
+  arguments.
 
-* PEP 3104: ``nonlocal`` statement.  Using ``nonlocal x`` you can now
+* PEP 3104: :keyword:`nonlocal` statement.  Using ``nonlocal x`` you can now
   assign directly to a variable in an outer (but non-global) scope.
 
-* PEP 3111: ``raw_input()`` renamed to ``input()``.  That is, the new
-  ``input()`` function reads a line from ``sys.stdin`` and returns it
-  with the trailing newline stripped.  It raises ``EOFError`` if the
-  input is terminated prematurely.  To get the old behavior of
-  ``input()``, use ``eval(input())``.
-
-* ``xrange()`` renamed to ``range()``.
-
-* PEP 3113: Tuple parameter unpacking removed.  You can no longer write
-  ``def foo(a, (b, c)): ...``.  Use ``def foo(a, b_c): b, c = b_c``
-  instead.
-
-* PEP 3114: ``.next()`` renamed to ``.__next__()``, new builtin
-  ``next()`` to call the ``__next__()`` method on an object.
-
-* PEP 3127: New octal literals; binary literals and ``bin()``.
-  Instead of ``0666``, you write ``0o666``.  The oct() function is
-  modified accordingly.  Also, ``0b1010`` equals 10, and ``bin(10)``
-  returns ``"0b1010"``.  ``0666`` is now a ``SyntaxError``.
-
-* PEP 3132: Extended Iterable Unpacking.  You can now write things
-  like ``a, b, *rest = some_sequence``.  And even ``*rest, a =
-  stuff``.  The ``rest`` object is always a list; the right-hand
-  side may be any iterable.
-
-* PEP 3135: New ``super()``.  You can now invoke ``super()`` without
-  arguments and the right class and instance will automatically be
-  chosen.  With arguments, its behavior is unchanged.
+* PEP 3111: :func:`raw_input` renamed to :func:`input`.  That is, the new
+  :func:`input` function reads a line from :data:`sys.stdin` and returns it with
+  the trailing newline stripped.  It raises :exc:`EOFError` if the input is
+  terminated prematurely.  To get the old behavior of :func:`input`, use
+  ``eval(input())``.
+
+* :func:`xrange` renamed to :func:`range`.
+
+* PEP 3113: Tuple parameter unpacking removed.  You can no longer write ``def
+  foo(a, (b, c)): ...``.  Use ``def foo(a, b_c): b, c = b_c`` instead.
+
+* PEP 3114: ``.next()`` renamed to :meth:`__next__`, new builtin :func:`next` to
+  call the :meth:`__next__` method on an object.
+
+* PEP 3127: New octal literals; binary literals and :func:`bin`.  Instead of
+  ``0666``, you write ``0o666``.  The :func:`oct` function is modified
+  accordingly.  Also, ``0b1010`` equals 10, and ``bin(10)`` returns
+  ``"0b1010"``.  ``0666`` is now a :exc:`SyntaxError`.
+
+* PEP 3132: Extended Iterable Unpacking.  You can now write things like ``a, b,
+  *rest = some_sequence``.  And even ``*rest, a = stuff``.  The ``rest`` object
+  is always a list; the right-hand side may be any iterable.
+
+* PEP 3135: New :func:`super`.  You can now invoke :func:`super` without
+  arguments and the right class and instance will automatically be chosen.  With
+  arguments, its behavior is unchanged.
 
-* ``zip()``, ``map()`` and ``filter()`` return iterators.
+* :func:`zip`, :func:`map` and :func:`filter` return iterators.
 
-* ``string.letters`` and its friends (``.lowercase`` and
-  ``.uppercase``) are gone.  Use ``string.ascii_letters``
+* :data:`string.letters` and its friends (:data:`string.lowercase` and
+  :data:`string.uppercase`) are gone.  Use :data:`string.ascii_letters`
   etc. instead.
 
-* Removed: ``apply()``, ``callable()``, ``coerce()``, ``execfile()``,
-  ``file()``, ``reduce()``, ``reload()``.
+* Removed: :func:`apply`, :func:`callable`, :func:`coerce`, :func:`execfile`,
+  :func:`file`, :func:`reduce`, :func:`reload`.
 
-* Removed: ``dict.has_key()``.
+* Removed: :meth:`dict.has_key` -- use the ``in`` operator instead.
 
-* ``exec`` is now a function.
+* :func:`exec` is now a function.
+
+* There is a new free format floating point representation, which is based on
+  "Floating-Point Printer Sample Code", by Robert G. Burger.  ``repr(11./5)``
+  now returns ``2.2`` instead of ``2.2000000000000002``.
+
+* The :meth:`__oct__` and :meth:`__hex__` special methods are removed --
+  :func:`oct` and :func:`hex` use :meth:`__index__` now to convert the argument
+  to an integer.
+
+* Support is removed for :attr:`__members__` and :attr:`__methods__`.
+
+* Renamed the boolean conversion C-level slot and method: ``nb_nonzero`` is now
+  ``nb_bool`` and :meth:`__nonzero__` is now :meth:`__bool__`.
+
+* Removed :data:`sys.maxint`. Use :data:`sys.maxsize`.
 
 
 .. ======================================================================
@@ -321,10 +359,10 @@
 
 * Detailed changes are listed here.
 
-The net result of the 3.0 generalizations is that Python 3.0 runs the
-pystone benchmark around 33% slower than Python 2.5.  There's room for
-improvement; we expect to be optimizing string and integer operations
-significantly before the final 3.0 release!
+The net result of the 3.0 generalizations is that Python 3.0 runs the pystone
+benchmark around 33% slower than Python 2.5.  There's room for improvement; we
+expect to be optimizing string and integer operations significantly before the
+final 3.0 release!
 
 .. ======================================================================
 
@@ -332,15 +370,31 @@
 New, Improved, and Deprecated Modules
 =====================================
 
-As usual, Python's standard library received a number of enhancements
-and bug fixes.  Here's a partial list of the most notable changes,
-sorted alphabetically by module name. Consult the :file:`Misc/NEWS`
-file in the source tree for a more complete list of changes, or look
-through the Subversion logs for all the details.
+As usual, Python's standard library received a number of enhancements and bug
+fixes.  Here's a partial list of the most notable changes, sorted alphabetically
+by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more
+complete list of changes, or look through the Subversion logs for all the
+details.
 
-* The ``cPickle`` module is gone.  Use ``pickle`` instead.  Eventually
+* The :mod:`cPickle` module is gone.  Use :mod:`pickle` instead.  Eventually
   we'll have a transparent accelerator module.
 
+* The :mod:`imageop` module is gone.
+
+* The :mod:`audiodev`, :mod:`Bastion`, :mod:`bsddb185`, :mod:`exceptions`,
+  :mod:`linuxaudiodev`, :mod:`md5`, :mod:`MimeWriter`, :mod:`mimify`,
+  :mod:`popen2`, :mod:`rexec`, :mod:`sets`, :mod:`sha`, :mod:`stringold`,
+  :mod:`strop`, :mod:`sunaudiodev`, :mod:`timing`, and :mod:`xmllib` modules are
+  gone.
+
+* The :mod:`new` module is gone.
+
+* The functions :func:`os.tmpnam`, :func:`os.tempnam` and :func:`os.tmpfile`
+  have been removed in favor of the :mod:`tempfile` module.
+
+* The :mod:`tokenize` module has been changed to work with bytes.  The main
+  entry point is now :func:`tokenize.tokenize`, instead of generate_tokens.
+
 .. ======================================================================
 .. whole new modules get described in subsections here
 
@@ -356,7 +410,16 @@
 
 * PEP 3121: Extension Module Initialization & Finalization.
 
-* PEP 3123: Making ``PyObject_HEAD`` conform to standard C.
+* PEP 3123: Making :cmacro:`PyObject_HEAD` conform to standard C.
+
+* No more C API support for restricted execution.
+
+* :cfunc:`PyNumber_Coerce`, :cfunc:`PyNumber_CoerceEx`, :cfunc:`PyMember_Get`,
+  and :cfunc:`PyMember_Set` C APIs are removed.
+
+* New C API :cfunc:`PyImport_ImportModuleNoBlock`, works like
+  :cfunc:`PyImport_ImportModule` but won't block on the import lock (returning
+  an error instead).
 
 .. ======================================================================
 
@@ -366,6 +429,7 @@
 
 Platform-specific changes go here.
 
+
 .. ======================================================================
 
 
@@ -394,6 +458,9 @@
 
 * Everything is all in the details!
 
+* Developers can include :file:`intobject.h` after :file:`Python.h` for
+  some ``PyInt_`` aliases.
+
 .. ======================================================================
 
 

Modified: python/branches/py3k-importlib/Include/Python.h
==============================================================================
--- python/branches/py3k-importlib/Include/Python.h	(original)
+++ python/branches/py3k-importlib/Include/Python.h	Thu Mar 27 00:48:05 2008
@@ -66,7 +66,6 @@
 
 #include "bytesobject.h"
 #include "unicodeobject.h"
-#include "intobject.h"
 #include "longobject.h"
 #include "longintrepr.h"
 #include "boolobject.h"
@@ -115,6 +114,7 @@
 #include "eval.h"
 
 #include "pystrtod.h"
+#include "pystrcmp.h"
 
 /* _Py_Mangle is defined in compile.c */
 PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);

Modified: python/branches/py3k-importlib/Include/abstract.h
==============================================================================
--- python/branches/py3k-importlib/Include/abstract.h	(original)
+++ python/branches/py3k-importlib/Include/abstract.h	Thu Mar 27 00:48:05 2008
@@ -259,7 +259,7 @@
 	 string representation on success, NULL on failure.  This is
 	 the equivalent of the Python expression: repr(o).
 
-	 Called by the repr() built-in function and by reverse quotes.
+	 Called by the repr() built-in function.
 
        */
 
@@ -271,20 +271,7 @@
 	 string representation on success, NULL on failure.  This is
 	 the equivalent of the Python expression: str(o).)
 
-	 Called by the str() built-in function and by the print
-	 statement.
-
-       */
-
-     /* Implemented elsewhere:
-
-     PyObject *PyObject_Unicode(PyObject *o);
-
-	 Compute the unicode representation of object, o.  Returns the
-	 unicode representation on success, NULL on failure.  This is
-	 the equivalent of the Python expression: unistr(o).)
-
-	 Called by the unistr() built-in function.
+	 Called by the str() and print() built-in functions.
 
        */
 
@@ -423,25 +410,12 @@
      PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
 #define PyObject_Length PyObject_Size
 
-     PyAPI_FUNC(Py_ssize_t) _PyObject_LengthHint(PyObject *o);
+     PyAPI_FUNC(Py_ssize_t) _PyObject_LengthHint(PyObject *o, Py_ssize_t);
 
        /*
-         Return the size of object o.  If the object, o, provides
-	 both sequence and mapping protocols, the sequence size is
-	 returned. On error, -1 is returned.  If the object provides
-	 a __length_hint__() method, its value is returned.  This is an
-	 internal undocumented API provided for performance reasons;
-	 for compatibility, don't use it outside the core.  This is the
-	 equivalent to the Python expression: 
-		try:
-			return len(o)
-		except (AttributeError, TypeError):
-			exc_type, exc_value, exc_tb = sys.exc_info()
-			try:
-				return o.__length_hint__()
-			except:
-				pass
-			raise exc_type, exc_value, exc_tb
+         Guess the size of object o using len(o) or o.__length_hint__().
+         If neither of those return a non-negative value, then return the
+         default value.  This function never fails. All exceptions are cleared.
        */
 
      PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);
@@ -596,11 +570,11 @@
 	   error (i.e. the object does not have a buffer interface or
 	   it is not working).
 
-	   If fortran is 'F', then if the object is multi-dimensional,
+	   If fort is 'F', then if the object is multi-dimensional,
 	   then the data will be copied into the array in
 	   Fortran-style (first dimension varies the fastest).  If
-	   fortran is 'C', then the data will be copied into the array
-	   in C-style (last dimension varies the fastest).  If fortran
+	   fort is 'C', then the data will be copied into the array
+	   in C-style (last dimension varies the fastest).  If fort
 	   is 'A', then it does not matter and the copy will be made
 	   in whatever way is more efficient.
 
@@ -611,7 +585,7 @@
         /* Copy the data from the src buffer to the buffer of destination
          */
 
-     PyAPI_FUNC(int) PyBuffer_IsContiguous(Py_buffer *view, char fortran);
+     PyAPI_FUNC(int) PyBuffer_IsContiguous(Py_buffer *view, char fort);
 
 
      PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims, 
@@ -621,7 +595,7 @@
 	     					    char fort);
 
        	/*  Fill the strides array with byte-strides of a contiguous
-            (Fortran-style if fortran is 'F' or C-style otherwise)
+            (Fortran-style if fort is 'F' or C-style otherwise)
             array of the given shape with the given number of bytes
             per element.
         */
@@ -637,6 +611,13 @@
          */
 
 
+     PyAPI_FUNC(PyObject *) PyObject_Format(PyObject* obj,
+					    PyObject *format_spec);
+       /*
+	 Takes an arbitrary object and returns the result of
+	 calling obj.__format__(format_spec).
+       */
+
 /* Iterators */
 
      PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
@@ -819,6 +800,19 @@
      PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
 
        /*
+         Returns the Integral instance converted to an int. The
+         instance is expected to be int or long or have an __int__
+         method. Steals integral's reference. error_format will be
+         used to create the TypeError if integral isn't actually an
+         Integral instance. error_format should be a format string
+         that can accept a char* naming integral's type.
+       */
+
+     PyAPI_FUNC(PyObject *) _PyNumber_ConvertIntegralToInt(
+             PyObject *integral,
+             const char* error_format);
+
+       /*
         Returns the object converted to Py_ssize_t by going through
         PyNumber_Index first.  If an overflow error occurs while
         converting the int-or-long to Py_ssize_t, then the second argument
@@ -1096,7 +1090,7 @@
        */
 
 #define PySequence_ITEM(o, i)\
-	( Py_Type(o)->tp_as_sequence->sq_item(o, i) )
+	( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) )
        /* Assume tp_as_sequence and sq_item exist and that i does not
 	  need to be corrected for a negative index
        */     

Modified: python/branches/py3k-importlib/Include/boolobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/boolobject.h	(original)
+++ python/branches/py3k-importlib/Include/boolobject.h	Thu Mar 27 00:48:05 2008
@@ -9,7 +9,7 @@
 
 PyAPI_DATA(PyTypeObject) PyBool_Type;
 
-#define PyBool_Check(x) (Py_Type(x) == &PyBool_Type)
+#define PyBool_Check(x) (Py_TYPE(x) == &PyBool_Type)
 
 /* Py_False and Py_True are the only two bools in existence.
 Don't forget to apply Py_INCREF() when returning either!!! */

Modified: python/branches/py3k-importlib/Include/bytesobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/bytesobject.h	(original)
+++ python/branches/py3k-importlib/Include/bytesobject.h	Thu Mar 27 00:48:05 2008
@@ -29,10 +29,11 @@
 
 /* Type object */
 PyAPI_DATA(PyTypeObject) PyBytes_Type;
+PyAPI_DATA(PyTypeObject) PyBytesIter_Type;
 
 /* Type check macros */
 #define PyBytes_Check(self) PyObject_TypeCheck(self, &PyBytes_Type)
-#define PyBytes_CheckExact(self) (Py_Type(self) == &PyBytes_Type)
+#define PyBytes_CheckExact(self) (Py_TYPE(self) == &PyBytes_Type)
 
 /* Direct API functions */
 PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *);
@@ -44,7 +45,7 @@
 
 /* Macros, trading safety for speed */
 #define PyBytes_AS_STRING(self) (assert(PyBytes_Check(self)),((PyBytesObject *)(self))->ob_bytes)
-#define PyBytes_GET_SIZE(self)  (assert(PyBytes_Check(self)),Py_Size(self))
+#define PyBytes_GET_SIZE(self)  (assert(PyBytes_Check(self)),Py_SIZE(self))
 
 #ifdef __cplusplus
 }

Modified: python/branches/py3k-importlib/Include/cStringIO.h
==============================================================================
--- python/branches/py3k-importlib/Include/cStringIO.h	(original)
+++ python/branches/py3k-importlib/Include/cStringIO.h	Thu Mar 27 00:48:05 2008
@@ -60,9 +60,9 @@
 
 /* These can be used to test if you have one */
 #define PycStringIO_InputCheck(O) \
-  (Py_Type(O)==PycStringIO->InputType)
+  (Py_TYPE(O)==PycStringIO->InputType)
 #define PycStringIO_OutputCheck(O) \
-  (Py_Type(O)==PycStringIO->OutputType)
+  (Py_TYPE(O)==PycStringIO->OutputType)
 
 #ifdef __cplusplus
 }

Modified: python/branches/py3k-importlib/Include/cellobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/cellobject.h	(original)
+++ python/branches/py3k-importlib/Include/cellobject.h	Thu Mar 27 00:48:05 2008
@@ -13,7 +13,7 @@
 
 PyAPI_DATA(PyTypeObject) PyCell_Type;
 
-#define PyCell_Check(op) (Py_Type(op) == &PyCell_Type)
+#define PyCell_Check(op) (Py_TYPE(op) == &PyCell_Type)
 
 PyAPI_FUNC(PyObject *) PyCell_New(PyObject *);
 PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *);

Modified: python/branches/py3k-importlib/Include/ceval.h
==============================================================================
--- python/branches/py3k-importlib/Include/ceval.h	(original)
+++ python/branches/py3k-importlib/Include/ceval.h	Thu Mar 27 00:48:05 2008
@@ -51,7 +51,7 @@
 	     _Py_CheckRecursiveCall(where))
 #define Py_LeaveRecursiveCall()				\
     do{ if((--PyThreadState_GET()->recursion_depth) <   \
-	   _Py_CheckRecursionLimit - 50);               \
+	   _Py_CheckRecursionLimit - 50)                \
 	  PyThreadState_GET()->overflowed = 0;          \
     } while(0)
 PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where);

Modified: python/branches/py3k-importlib/Include/classobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/classobject.h	(original)
+++ python/branches/py3k-importlib/Include/classobject.h	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,4 @@
-/* Former class object interface -- now only (un)bound methods are here  */
+/* Former class object interface -- now only bound methods are here  */
 
 /* Revealing some structures (not for general use) */
 
@@ -11,8 +11,7 @@
 typedef struct {
     PyObject_HEAD
     PyObject *im_func;   /* The callable object implementing the method */
-    PyObject *im_self;   /* The instance it is bound to, or NULL */
-    PyObject *im_class;  /* The class that asked for the method */
+    PyObject *im_self;   /* The instance it is bound to */
     PyObject *im_weakreflist; /* List of weak references */
 } PyMethodObject;
 
@@ -20,11 +19,10 @@
 
 #define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type)
 
-PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
+PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *);
 
 PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *);
 PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
-PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *);
 
 /* Macros for direct access to these values. Type checks are *not*
    done, so use with care. */
@@ -32,8 +30,25 @@
         (((PyMethodObject *)meth) -> im_func)
 #define PyMethod_GET_SELF(meth) \
 	(((PyMethodObject *)meth) -> im_self)
-#define PyMethod_GET_CLASS(meth) \
-	(((PyMethodObject *)meth) -> im_class)
+
+PyAPI_FUNC(int) PyMethod_ClearFreeList(void);
+
+typedef struct {
+	PyObject_HEAD
+	PyObject *func;
+} PyInstanceMethodObject;
+
+PyAPI_DATA(PyTypeObject) PyInstanceMethod_Type;
+
+#define PyInstanceMethod_Check(op) ((op)->ob_type == &PyInstanceMethod_Type)
+
+PyAPI_FUNC(PyObject *) PyInstanceMethod_New(PyObject *);
+PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *);
+
+/* Macros for direct access to these values. Type checks are *not*
+   done, so use with care. */
+#define PyInstanceMethod_GET_FUNCTION(meth) \
+        (((PyInstanceMethodObject *)meth) -> func)
 
 #ifdef __cplusplus
 }

Modified: python/branches/py3k-importlib/Include/cobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/cobject.h	(original)
+++ python/branches/py3k-importlib/Include/cobject.h	Thu Mar 27 00:48:05 2008
@@ -16,7 +16,7 @@
 
 PyAPI_DATA(PyTypeObject) PyCObject_Type;
 
-#define PyCObject_Check(op) (Py_Type(op) == &PyCObject_Type)
+#define PyCObject_Check(op) (Py_TYPE(op) == &PyCObject_Type)
 
 /* Create a PyCObject from a pointer to a C object and an optional
    destructor function.  If the second argument is non-null, then it

Modified: python/branches/py3k-importlib/Include/code.h
==============================================================================
--- python/branches/py3k-importlib/Include/code.h	(original)
+++ python/branches/py3k-importlib/Include/code.h	Thu Mar 27 00:48:05 2008
@@ -48,6 +48,7 @@
 #define CO_FUTURE_DIVISION    	0x2000
 #define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */
 #define CO_FUTURE_WITH_STATEMENT  0x8000
+#define CO_FUTURE_PRINT_FUNCTION  0x10000
 #endif
 
 /* This should be defined if a future statement modifies the syntax.
@@ -59,7 +60,7 @@
 
 PyAPI_DATA(PyTypeObject) PyCode_Type;
 
-#define PyCode_Check(op) (Py_Type(op) == &PyCode_Type)
+#define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type)
 #define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))
 
 /* Public interface */
@@ -72,7 +73,7 @@
 
 /* for internal use only */
 #define _PyCode_GETCODEPTR(co, pp) \
-	((*Py_Type((co)->co_code)->tp_as_buffer->bf_getreadbuffer) \
+	((*Py_TYPE((co)->co_code)->tp_as_buffer->bf_getreadbuffer) \
 	 ((co)->co_code, 0, (void **)(pp)))
 
 typedef struct _addr_pair {

Modified: python/branches/py3k-importlib/Include/compile.h
==============================================================================
--- python/branches/py3k-importlib/Include/compile.h	(original)
+++ python/branches/py3k-importlib/Include/compile.h	Thu Mar 27 00:48:05 2008
@@ -24,6 +24,7 @@
 #define FUTURE_DIVISION "division"
 #define FUTURE_ABSOLUTE_IMPORT "absolute_import"
 #define FUTURE_WITH_STATEMENT "with_statement"
+#define FUTURE_PRINT_FUNCTION "print_function"
 
 struct _mod; /* Declare the existence of this type */
 PyAPI_FUNC(PyCodeObject *) PyAST_Compile(struct _mod *, const char *,

Modified: python/branches/py3k-importlib/Include/complexobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/complexobject.h	(original)
+++ python/branches/py3k-importlib/Include/complexobject.h	Thu Mar 27 00:48:05 2008
@@ -43,7 +43,7 @@
 PyAPI_DATA(PyTypeObject) PyComplex_Type;
 
 #define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type)
-#define PyComplex_CheckExact(op) (Py_Type(op) == &PyComplex_Type)
+#define PyComplex_CheckExact(op) (Py_TYPE(op) == &PyComplex_Type)
 
 PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);
 PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag);

Modified: python/branches/py3k-importlib/Include/datetime.h
==============================================================================
--- python/branches/py3k-importlib/Include/datetime.h	(original)
+++ python/branches/py3k-importlib/Include/datetime.h	Thu Mar 27 00:48:05 2008
@@ -166,19 +166,19 @@
 
 /* Macros for type checking when building the Python core. */
 #define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType)
-#define PyDate_CheckExact(op) (Py_Type(op) == &PyDateTime_DateType)
+#define PyDate_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateType)
 
 #define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType)
-#define PyDateTime_CheckExact(op) (Py_Type(op) == &PyDateTime_DateTimeType)
+#define PyDateTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateTimeType)
 
 #define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType)
-#define PyTime_CheckExact(op) (Py_Type(op) == &PyDateTime_TimeType)
+#define PyTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TimeType)
 
 #define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType)
-#define PyDelta_CheckExact(op) (Py_Type(op) == &PyDateTime_DeltaType)
+#define PyDelta_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DeltaType)
 
 #define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType)
-#define PyTZInfo_CheckExact(op) (Py_Type(op) == &PyDateTime_TZInfoType)
+#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TZInfoType)
 
 #else
 
@@ -198,19 +198,19 @@
 
 /* Macros for type checking when not building the Python core. */
 #define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType)
-#define PyDate_CheckExact(op) (Py_Type(op) == PyDateTimeAPI->DateType)
+#define PyDate_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateType)
 
 #define PyDateTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateTimeType)
-#define PyDateTime_CheckExact(op) (Py_Type(op) == PyDateTimeAPI->DateTimeType)
+#define PyDateTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateTimeType)
 
 #define PyTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TimeType)
-#define PyTime_CheckExact(op) (Py_Type(op) == PyDateTimeAPI->TimeType)
+#define PyTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TimeType)
 
 #define PyDelta_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DeltaType)
-#define PyDelta_CheckExact(op) (Py_Type(op) == PyDateTimeAPI->DeltaType)
+#define PyDelta_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DeltaType)
 
 #define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType)
-#define PyTZInfo_CheckExact(op) (Py_Type(op) == PyDateTimeAPI->TZInfoType)
+#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TZInfoType)
 
 /* Macros for accessing constructors in a simplified fashion. */
 #define PyDate_FromDate(year, month, day) \

Modified: python/branches/py3k-importlib/Include/descrobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/descrobject.h	(original)
+++ python/branches/py3k-importlib/Include/descrobject.h	Thu Mar 27 00:48:05 2008
@@ -67,7 +67,12 @@
 	void *d_wrapped; /* This can be any function pointer */
 } PyWrapperDescrObject;
 
+PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type;
+PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
+PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
+PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
 PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
+PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
 
 PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
 PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
@@ -77,7 +82,7 @@
 					       struct PyGetSetDef *);
 PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
 						struct wrapperbase *, void *);
-#define PyDescr_IsData(d) (Py_Type(d)->tp_descr_set != NULL)
+#define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL)
 
 PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
 PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);

Modified: python/branches/py3k-importlib/Include/dictobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/dictobject.h	(original)
+++ python/branches/py3k-importlib/Include/dictobject.h	Thu Mar 27 00:48:05 2008
@@ -89,10 +89,23 @@
 };
 
 PyAPI_DATA(PyTypeObject) PyDict_Type;
+PyAPI_DATA(PyTypeObject) PyDictIterKey_Type;
+PyAPI_DATA(PyTypeObject) PyDictIterValue_Type;
+PyAPI_DATA(PyTypeObject) PyDictIterItem_Type;
+PyAPI_DATA(PyTypeObject) PyDictKeys_Type;
+PyAPI_DATA(PyTypeObject) PyDictItems_Type;
+PyAPI_DATA(PyTypeObject) PyDictValues_Type;
 
 #define PyDict_Check(op) \
-                 PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_DICT_SUBCLASS)
-#define PyDict_CheckExact(op) (Py_Type(op) == &PyDict_Type)
+                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
+#define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
+#define PyDictKeys_Check(op) (Py_TYPE(op) == &PyDictKeys_Type)
+#define PyDictItems_Check(op) (Py_TYPE(op) == &PyDictItems_Type)
+#define PyDictValues_Check(op) (Py_TYPE(op) == &PyDictValues_Type)
+/* This excludes Values, since they are not sets. */
+# define PyDictViewSet_Check(op) \
+	(PyDictKeys_Check(op) || PyDictItems_Check(op))
+
 
 PyAPI_FUNC(PyObject *) PyDict_New(void);
 PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);
@@ -110,6 +123,7 @@
 PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp);
 PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key);
 PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, long hash);
+PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
 
 /* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */
 PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other);

Modified: python/branches/py3k-importlib/Include/fileobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/fileobject.h	(original)
+++ python/branches/py3k-importlib/Include/fileobject.h	Thu Mar 27 00:48:05 2008
@@ -8,7 +8,8 @@
 
 #define PY_STDIOTEXTMODE "b"
 
-PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *, int (*)(FILE*));
+PyAPI_FUNC(PyObject *) PyFile_FromFd(int, char *, char *, int, char *, char *,
+				     char *, int);
 PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
 PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
 PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
@@ -19,6 +20,14 @@
    If non-NULL, this is different than the default encoding for strings
 */
 PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
+PyAPI_DATA(const int) Py_HasFileSystemDefaultEncoding;
+
+/* Internal API
+
+   The std printer acts as a preliminary sys.stderr until the new io
+   infrastructure is in place. */
+PyAPI_FUNC(PyObject *) PyFile_NewStdPrinter(int);
+PyAPI_DATA(PyTypeObject) PyStdPrinter_Type;
 
 #ifdef __cplusplus
 }

Modified: python/branches/py3k-importlib/Include/floatobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/floatobject.h	(original)
+++ python/branches/py3k-importlib/Include/floatobject.h	Thu Mar 27 00:48:05 2008
@@ -19,7 +19,11 @@
 PyAPI_DATA(PyTypeObject) PyFloat_Type;
 
 #define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)
-#define PyFloat_CheckExact(op) (Py_Type(op) == &PyFloat_Type)
+#define PyFloat_CheckExact(op) (Py_TYPE(op) == &PyFloat_Type)
+
+PyAPI_FUNC(double) PyFloat_GetMax(void);
+PyAPI_FUNC(double) PyFloat_GetMin(void);
+PyAPI_FUNC(PyObject *) PyFloat_GetInfo(void);
 
 /* Return Python float from string PyObject. */
 PyAPI_FUNC(PyObject *) PyFloat_FromString(PyObject*);
@@ -72,6 +76,10 @@
  */
 PyAPI_FUNC(int) _PyFloat_Repr(double x, char *p, size_t len);
 
+/* Used to get the important decimal digits of a double */
+PyAPI_FUNC(int) _PyFloat_Digits(char *buf, double v, int *signum);
+PyAPI_FUNC(void) _PyFloat_DigitsInit(void);
+
 /* The unpack routines read 4 or 8 bytes, starting at p.  le is a bool
  * argument, true if the string is in little-endian format (exponent
  * last, at p+3 or p+7), false if big-endian (exponent first, at p).
@@ -83,6 +91,9 @@
 PyAPI_FUNC(double) _PyFloat_Unpack4(const unsigned char *p, int le);
 PyAPI_FUNC(double) _PyFloat_Unpack8(const unsigned char *p, int le);
 
+/* free list api */
+PyAPI_FUNC(void) PyFloat_CompactFreeList(size_t *, size_t *, size_t *);
+
 #ifdef __cplusplus
 }
 #endif

Modified: python/branches/py3k-importlib/Include/frameobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/frameobject.h	(original)
+++ python/branches/py3k-importlib/Include/frameobject.h	Thu Mar 27 00:48:05 2008
@@ -51,7 +51,7 @@
 
 PyAPI_DATA(PyTypeObject) PyFrame_Type;
 
-#define PyFrame_Check(op) (Py_Type(op) == &PyFrame_Type)
+#define PyFrame_Check(op) (Py_TYPE(op) == &PyFrame_Type)
 
 PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
                                        PyObject *, PyObject *);
@@ -73,6 +73,8 @@
 PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
 PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
 
+PyAPI_FUNC(int) PyFrame_ClearFreeList(void);
+
 #ifdef __cplusplus
 }
 #endif

Modified: python/branches/py3k-importlib/Include/funcobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/funcobject.h	(original)
+++ python/branches/py3k-importlib/Include/funcobject.h	Thu Mar 27 00:48:05 2008
@@ -41,7 +41,7 @@
 
 PyAPI_DATA(PyTypeObject) PyFunction_Type;
 
-#define PyFunction_Check(op) (Py_Type(op) == &PyFunction_Type)
+#define PyFunction_Check(op) (Py_TYPE(op) == &PyFunction_Type)
 
 PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *);
 PyAPI_FUNC(PyObject *) PyFunction_GetCode(PyObject *);

Modified: python/branches/py3k-importlib/Include/genobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/genobject.h	(original)
+++ python/branches/py3k-importlib/Include/genobject.h	Thu Mar 27 00:48:05 2008
@@ -18,6 +18,9 @@
 
 	/* True if generator is being executed. */
 	int gi_running;
+    
+	/* The code object backing the generator */
+	PyObject *gi_code;
 
 	/* List of weak reference. */
 	PyObject *gi_weakreflist;
@@ -26,7 +29,7 @@
 PyAPI_DATA(PyTypeObject) PyGen_Type;
 
 #define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type)
-#define PyGen_CheckExact(op) (Py_Type(op) == &PyGen_Type)
+#define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type)
 
 PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *);
 PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *);

Modified: python/branches/py3k-importlib/Include/import.h
==============================================================================
--- python/branches/py3k-importlib/Include/import.h	(original)
+++ python/branches/py3k-importlib/Include/import.h	Thu Mar 27 00:48:05 2008
@@ -14,16 +14,14 @@
 PyAPI_FUNC(PyObject *) PyImport_GetModuleDict(void);
 PyAPI_FUNC(PyObject *) PyImport_AddModule(const char *name);
 PyAPI_FUNC(PyObject *) PyImport_ImportModule(const char *name);
+PyAPI_FUNC(PyObject *) PyImport_ImportModuleNoBlock(const char *);
 PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel(char *name,
 	PyObject *globals, PyObject *locals, PyObject *fromlist, int level);
 
-/* For DLL compatibility */
-#undef PyImport_ImportModuleEx
-PyAPI_FUNC(PyObject *) PyImport_ImportModuleEx(
-	char *name, PyObject *globals, PyObject *locals, PyObject *fromlist);
 #define PyImport_ImportModuleEx(n, g, l, f) \
 	PyImport_ImportModuleLevel(n, g, l, f, -1)
 
+PyAPI_FUNC(PyObject *) PyImport_GetImporter(PyObject *path);
 PyAPI_FUNC(PyObject *) PyImport_Import(PyObject *name);
 PyAPI_FUNC(PyObject *) PyImport_ReloadModule(PyObject *m);
 PyAPI_FUNC(void) PyImport_Cleanup(void);
@@ -42,6 +40,7 @@
     void (*initfunc)(void);
 };
 
+PyAPI_DATA(PyTypeObject) PyNullImporter_Type;
 PyAPI_DATA(struct _inittab *) PyImport_Inittab;
 
 PyAPI_FUNC(int) PyImport_AppendInittab(char *name, void (*initfunc)(void));

Modified: python/branches/py3k-importlib/Include/intobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/intobject.h	(original)
+++ python/branches/py3k-importlib/Include/intobject.h	Thu Mar 27 00:48:05 2008
@@ -1,18 +1,9 @@
+/* Integer object interface
 
-/* Integer object interface */
-
-/*
-PyIntObject represents a (long) integer.  This is an immutable object;
-an integer cannot change its value after creation.
-
-There are functions to create new integer objects, to test an object
-for integer-ness, and to get the integer value.  The latter functions
-returns -1 and sets errno to EBADF if the object is not an PyIntObject.
-None of the functions should be applied to nil objects.
-
-The type PyIntObject is (unfortunately) exposed here so we can declare
-_Py_TrueStruct and _Py_ZeroStruct in boolobject.h; don't use this.
-*/
+   This header files exists to make porting code to Python 3.0 easier. It
+   defines aliases from PyInt_* to PyLong_*. Only PyInt_GetMax() and
+   PyInt_CheckExact() remain in longobject.h.
+ */
 
 #ifndef Py_INTOBJECT_H
 #define Py_INTOBJECT_H
@@ -20,18 +11,9 @@
 extern "C" {
 #endif
 
-/*
-typedef struct {
-    PyObject_HEAD
-    long ob_ival;
-} PyIntObject;
-
-PyAPI_DATA(PyTypeObject) PyInt_Type;
-*/
+#warning "DeprecationWarning: intobject.h is going to be removed in 3.1"
 
 #define PyInt_Check(op) PyLong_Check(op)
-#define PyInt_CheckExact(op) (PyLong_CheckExact(op) && _PyLong_FitsInLong(op))
-
 #define PyInt_FromString PyLong_FromString
 #define PyInt_FromUnicode PyLong_FromUnicode
 #define PyInt_FromLong PyLong_FromLong
@@ -41,16 +23,7 @@
 #define PyInt_AsSsize_t PyLong_AsSsize_t
 #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
 #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
-
-PyAPI_FUNC(long) PyInt_GetMax(void);
-
-#define PyInt_AS_LONG(op) PyLong_AsLong(op)
-
-/* These aren't really part of the Int object, but they're handy; the protos
- * are necessary for systems that need the magic of PyAPI_FUNC.
- */
-PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int);
-PyAPI_FUNC(long) PyOS_strtol(char *, char **, int);
+#define PyInt_AS_LONG PyLong_AS_LONG
 
 #ifdef __cplusplus
 }

Modified: python/branches/py3k-importlib/Include/iterobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/iterobject.h	(original)
+++ python/branches/py3k-importlib/Include/iterobject.h	Thu Mar 27 00:48:05 2008
@@ -6,19 +6,18 @@
 #endif
 
 PyAPI_DATA(PyTypeObject) PySeqIter_Type;
+PyAPI_DATA(PyTypeObject) PyCallIter_Type;
+PyAPI_DATA(PyTypeObject) PyCmpWrapper_Type;
 
-#define PySeqIter_Check(op) (Py_Type(op) == &PySeqIter_Type)
+#define PySeqIter_Check(op) (Py_TYPE(op) == &PySeqIter_Type)
 
 PyAPI_FUNC(PyObject *) PySeqIter_New(PyObject *);
 
-PyAPI_DATA(PyTypeObject) PyCallIter_Type;
 
-#define PyCallIter_Check(op) (Py_Type(op) == &PyCallIter_Type)
+#define PyCallIter_Check(op) (Py_TYPE(op) == &PyCallIter_Type)
 
 PyAPI_FUNC(PyObject *) PyCallIter_New(PyObject *, PyObject *);
 
-PyObject* _PyZip_CreateIter(PyObject* args);
-
 #ifdef __cplusplus
 }
 #endif

Modified: python/branches/py3k-importlib/Include/listobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/listobject.h	(original)
+++ python/branches/py3k-importlib/Include/listobject.h	Thu Mar 27 00:48:05 2008
@@ -39,10 +39,13 @@
 } PyListObject;
 
 PyAPI_DATA(PyTypeObject) PyList_Type;
+PyAPI_DATA(PyTypeObject) PyListIter_Type;
+PyAPI_DATA(PyTypeObject) PyListRevIter_Type;
+PyAPI_DATA(PyTypeObject) PySortWrapper_Type;
 
 #define PyList_Check(op) \
-		PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_LIST_SUBCLASS)
-#define PyList_CheckExact(op) (Py_Type(op) == &PyList_Type)
+		PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
+#define PyList_CheckExact(op) (Py_TYPE(op) == &PyList_Type)
 
 PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);
 PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *);
@@ -60,7 +63,7 @@
 /* Macro, trading safety for speed */
 #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
 #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
-#define PyList_GET_SIZE(op)    Py_Size(op)
+#define PyList_GET_SIZE(op)    Py_SIZE(op)
 
 #ifdef __cplusplus
 }

Modified: python/branches/py3k-importlib/Include/longobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/longobject.h	(original)
+++ python/branches/py3k-importlib/Include/longobject.h	Thu Mar 27 00:48:05 2008
@@ -12,8 +12,8 @@
 PyAPI_DATA(PyTypeObject) PyLong_Type;
 
 #define PyLong_Check(op) \
-		PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_LONG_SUBCLASS)
-#define PyLong_CheckExact(op) (Py_Type(op) == &PyLong_Type)
+		PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)
+#define PyLong_CheckExact(op) (Py_TYPE(op) == &PyLong_Type)
 
 PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
 PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);
@@ -21,11 +21,25 @@
 PyAPI_FUNC(PyObject *) PyLong_FromSsize_t(Py_ssize_t);
 PyAPI_FUNC(PyObject *) PyLong_FromDouble(double);
 PyAPI_FUNC(long) PyLong_AsLong(PyObject *);
+PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *);
 PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);
 PyAPI_FUNC(size_t) PyLong_AsSize_t(PyObject *);
 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
 
+/* It may be useful in the future. I've added it in the PyInt -> PyLong
+   cleanup to keep the extra information. [CH] */
+#define PyLong_AS_LONG(op) PyLong_AsLong(op)
+
+/* Used by socketmodule.c */
+#if SIZEOF_SOCKET_T <= SIZEOF_LONG
+#define PyLong_FromSocket_t(fd) PyLong_FromLong((SOCKET_T)(fd))
+#define PyLong_AsSocket_t(fd) (SOCKET_T)PyLong_AsLong(fd)
+#else
+#define PyLong_FromSocket_t(fd) PyLong_FromLongLong(((SOCKET_T)(fd));
+#define PyLong_AsSocket_t(fd) (SOCKET_T)PyLong_AsLongLong(fd)
+#endif
+
 /* For use by intobject.c only */
 PyAPI_DATA(int) _PyLong_DigitValue[256];
 
@@ -36,7 +50,6 @@
    be multiplied by SHIFT!  There may not be enough room in an int to store
    e*SHIFT directly. */
 PyAPI_FUNC(double) _PyLong_AsScaledDouble(PyObject *vv, int *e);
-  PyAPI_FUNC(int) _PyLong_FitsInLong(PyObject* vv);
 
 PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
 PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
@@ -114,6 +127,12 @@
    appending a base prefix of 0[box] if base is 2, 8 or 16. */
 PyAPI_FUNC(PyObject *) _PyLong_Format(PyObject *aa, int base);
 
+/* These aren't really part of the long object, but they're handy. The
+   functions are in Python/mystrtoul.c.
+ */
+PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int);
+PyAPI_FUNC(long) PyOS_strtol(char *, char **, int);
+
 #ifdef __cplusplus
 }
 #endif

Modified: python/branches/py3k-importlib/Include/memoryobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/memoryobject.h	(original)
+++ python/branches/py3k-importlib/Include/memoryobject.h	Thu Mar 27 00:48:05 2008
@@ -16,7 +16,7 @@
 
 PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
 
-#define PyMemory_Check(op) (Py_Type(op) == &PyMemoryView_Type)
+#define PyMemory_Check(op) (Py_TYPE(op) == &PyMemoryView_Type)
 #define PyMemoryView(op) (((PyMemoryViewObject *)(op))->view)
 
 #define Py_END_OF_MEMORY	(-1)

Modified: python/branches/py3k-importlib/Include/methodobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/methodobject.h	(original)
+++ python/branches/py3k-importlib/Include/methodobject.h	Thu Mar 27 00:48:05 2008
@@ -13,7 +13,7 @@
 
 PyAPI_DATA(PyTypeObject) PyCFunction_Type;
 
-#define PyCFunction_Check(op) (Py_Type(op) == &PyCFunction_Type)
+#define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type)
 
 typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
 typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
@@ -85,6 +85,8 @@
     PyObject    *m_module; /* The __module__ attribute, can be anything */
 } PyCFunctionObject;
 
+PyAPI_FUNC(int) PyCFunction_ClearFreeList(void);
+
 #ifdef __cplusplus
 }
 #endif

Modified: python/branches/py3k-importlib/Include/modsupport.h
==============================================================================
--- python/branches/py3k-importlib/Include/modsupport.h	(original)
+++ python/branches/py3k-importlib/Include/modsupport.h	Thu Mar 27 00:48:05 2008
@@ -40,7 +40,8 @@
 PyAPI_FUNC(int) PyModule_AddObject(PyObject *, const char *, PyObject *);
 PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);
 PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);
-
+#define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
+#define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c)
 
 #define PYTHON_API_VERSION 1013
 #define PYTHON_API_STRING "1013"

Modified: python/branches/py3k-importlib/Include/moduleobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/moduleobject.h	(original)
+++ python/branches/py3k-importlib/Include/moduleobject.h	Thu Mar 27 00:48:05 2008
@@ -10,7 +10,7 @@
 PyAPI_DATA(PyTypeObject) PyModule_Type;
 
 #define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type)
-#define PyModule_CheckExact(op) (Py_Type(op) == &PyModule_Type)
+#define PyModule_CheckExact(op) (Py_TYPE(op) == &PyModule_Type)
 
 PyAPI_FUNC(PyObject *) PyModule_New(const char *);
 PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *);

Modified: python/branches/py3k-importlib/Include/object.h
==============================================================================
--- python/branches/py3k-importlib/Include/object.h	(original)
+++ python/branches/py3k-importlib/Include/object.h	Thu Mar 27 00:48:05 2008
@@ -109,9 +109,9 @@
 	Py_ssize_t ob_size; /* Number of items in variable part */
 } PyVarObject;
 
-#define Py_Refcnt(ob)		(((PyObject*)(ob))->ob_refcnt)
-#define Py_Type(ob)		(((PyObject*)(ob))->ob_type)
-#define Py_Size(ob)		(((PyVarObject*)(ob))->ob_size)
+#define Py_REFCNT(ob)		(((PyObject*)(ob))->ob_refcnt)
+#define Py_TYPE(ob)		(((PyObject*)(ob))->ob_type)
+#define Py_SIZE(ob)		(((PyVarObject*)(ob))->ob_size)
 
 /*
 Type objects contain a string containing the type name (to help somewhat
@@ -277,7 +277,6 @@
 typedef struct {
      getbufferproc bf_getbuffer;
      releasebufferproc bf_releasebuffer;
-     inquiry bf_multisegment;
 } PyBufferProcs;
 
 typedef void (*freefunc)(void *);
@@ -374,6 +373,9 @@
 	PyObject *tp_weaklist;
 	destructor tp_del;
 
+	/* Type attribute cache version tag. Added in version 2.6 */
+	unsigned int tp_version_tag;
+
 #ifdef COUNT_ALLOCS
 	/* these must be last and never explicitly initialized */
 	Py_ssize_t tp_allocs;
@@ -404,37 +406,35 @@
 
 /* access macro to the members which are floating "behind" the object */
 #define PyHeapType_GET_MEMBERS(etype) \
-    ((PyMemberDef *)(((char *)etype) + Py_Type(etype)->tp_basicsize))
+    ((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))
 
 
 /* Generic type check */
 PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
 #define PyObject_TypeCheck(ob, tp) \
-	(Py_Type(ob) == (tp) || PyType_IsSubtype(Py_Type(ob), (tp)))
+	(Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
 
 PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
 PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
 PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
 
 #define PyType_Check(op) \
-	PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_TYPE_SUBCLASS)
-#define PyType_CheckExact(op) (Py_Type(op) == &PyType_Type)
+	PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
+#define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type)
 
 PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
 PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
 PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
 					       PyObject *, PyObject *);
 PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
+PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
 
 /* Generic operations on objects */
 PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
 PyAPI_FUNC(void) _Py_BreakPoint(void);
 PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
 PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);
-PyAPI_FUNC(PyObject *) PyObject_ReprStr8(PyObject *);
-PyAPI_FUNC(PyObject *) _PyObject_Str(PyObject *);
 PyAPI_FUNC(PyObject *) PyObject_Str(PyObject *);
-PyAPI_FUNC(PyObject *) PyObject_Unicode(PyObject *);
 PyAPI_FUNC(int) PyObject_Compare(PyObject *, PyObject *);
 PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
 PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
@@ -461,8 +461,8 @@
 extern int _PyObject_SlotCompare(PyObject *, PyObject *);
 
 
-/* PyObject_Dir(obj) acts like Python __builtin__.dir(obj), returning a
-   list of strings.  PyObject_Dir(NULL) is like __builtin__.dir(),
+/* PyObject_Dir(obj) acts like Python builtins.dir(obj), returning a
+   list of strings.  PyObject_Dir(NULL) is like builtins.dir(),
    returning the names of the current locals.  In this case, if there are
    no current locals, NULL is returned, and PyErr_Occurred() is false.
 */
@@ -478,7 +478,7 @@
 PyAPI_FUNC(long) _Py_HashPointer(void*);
 
 /* Helper for passing objects to printf and the like */
-#define PyObject_REPR(obj) PyString_AS_STRING(PyObject_ReprStr8(obj))
+#define PyObject_REPR(obj) PyUnicode_AsString(PyObject_Repr(obj))
 
 /* Flag bits for printing: */
 #define Py_PRINT_RAW	1	/* No string quotes etc. */
@@ -528,6 +528,13 @@
 #define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
 #endif
 
+/* Objects support type attribute cache */
+#define Py_TPFLAGS_HAVE_VERSION_TAG   (1L<<18)
+#define Py_TPFLAGS_VALID_VERSION_TAG  (1L<<19)
+
+/* Type is abstract and cannot be instantiated */
+#define Py_TPFLAGS_IS_ABSTRACT (1L<<20)
+
 /* These flags are used to determine if a type is a subclass. */
 #define Py_TPFLAGS_INT_SUBCLASS		(1L<<23)
 #define Py_TPFLAGS_LONG_SUBCLASS	(1L<<24)
@@ -541,6 +548,7 @@
 
 #define Py_TPFLAGS_DEFAULT  ( \
                              Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
+                             Py_TPFLAGS_HAVE_VERSION_TAG | \
                             0)
 
 #define PyType_HasFeature(t,f)  (((t)->tp_flags & (f)) != 0)
@@ -615,9 +623,9 @@
 #ifdef COUNT_ALLOCS
 PyAPI_FUNC(void) inc_count(PyTypeObject *);
 PyAPI_FUNC(void) dec_count(PyTypeObject *);
-#define _Py_INC_TPALLOCS(OP)	inc_count(Py_Type(OP))
-#define _Py_INC_TPFREES(OP)	dec_count(Py_Type(OP))
-#define _Py_DEC_TPFREES(OP)	Py_Type(OP)->tp_frees--
+#define _Py_INC_TPALLOCS(OP)	inc_count(Py_TYPE(OP))
+#define _Py_INC_TPFREES(OP)	dec_count(Py_TYPE(OP))
+#define _Py_DEC_TPFREES(OP)	Py_TYPE(OP)->tp_frees--
 #define _Py_COUNT_ALLOCS_COMMA	,
 #else
 #define _Py_INC_TPALLOCS(OP)
@@ -642,13 +650,13 @@
 #define _Py_NewReference(op) (				\
 	_Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA	\
 	_Py_INC_REFTOTAL  _Py_REF_DEBUG_COMMA		\
-	Py_Refcnt(op) = 1)
+	Py_REFCNT(op) = 1)
 
 #define _Py_ForgetReference(op) _Py_INC_TPFREES(op)
 
 #define _Py_Dealloc(op) (				\
 	_Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA	\
-	(*Py_Type(op)->tp_dealloc)((PyObject *)(op)))
+	(*Py_TYPE(op)->tp_dealloc)((PyObject *)(op)))
 #endif /* !Py_TRACE_REFS */
 
 #define Py_INCREF(op) (				\

Modified: python/branches/py3k-importlib/Include/objimpl.h
==============================================================================
--- python/branches/py3k-importlib/Include/objimpl.h	(original)
+++ python/branches/py3k-importlib/Include/objimpl.h	Thu Mar 27 00:48:05 2008
@@ -151,9 +151,9 @@
 /* Macros trading binary compatibility for speed. See also pymem.h.
    Note that these macros expect non-NULL object pointers.*/
 #define PyObject_INIT(op, typeobj) \
-	( Py_Type(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
+	( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
 #define PyObject_INIT_VAR(op, typeobj, size) \
-	( Py_Size(op) = (size), PyObject_INIT((op), (typeobj)) )
+	( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) )
 
 #define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
 
@@ -228,8 +228,8 @@
 #define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
 
 /* Test if an object has a GC head */
-#define PyObject_IS_GC(o) (PyType_IS_GC(Py_Type(o)) && \
-	(Py_Type(o)->tp_is_gc == NULL || Py_Type(o)->tp_is_gc(o)))
+#define PyObject_IS_GC(o) (PyType_IS_GC(Py_TYPE(o)) && \
+	(Py_TYPE(o)->tp_is_gc == NULL || Py_TYPE(o)->tp_is_gc(o)))
 
 PyAPI_FUNC(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, Py_ssize_t);
 #define PyObject_GC_Resize(type, op, n) \
@@ -323,7 +323,7 @@
 #define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0)
 
 #define PyObject_GET_WEAKREFS_LISTPTR(o) \
-	((PyObject **) (((char *) (o)) + Py_Type(o)->tp_weaklistoffset))
+	((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset))
 
 #ifdef __cplusplus
 }

Modified: python/branches/py3k-importlib/Include/opcode.h
==============================================================================
--- python/branches/py3k-importlib/Include/opcode.h	(original)
+++ python/branches/py3k-importlib/Include/opcode.h	Thu Mar 27 00:48:05 2008
@@ -36,6 +36,7 @@
 #define INPLACE_FLOOR_DIVIDE 28
 #define INPLACE_TRUE_DIVIDE 29
 
+#define STORE_MAP	54
 #define INPLACE_ADD	55
 #define INPLACE_SUBTRACT	56
 #define INPLACE_MULTIPLY	57
@@ -65,7 +66,7 @@
 
 #define RETURN_VALUE	83
 #define IMPORT_STAR	84
-#define MAKE_BYTES	85
+
 #define YIELD_VALUE	86
 #define POP_BLOCK	87
 #define END_FINALLY	88

Modified: python/branches/py3k-importlib/Include/patchlevel.h
==============================================================================
--- python/branches/py3k-importlib/Include/patchlevel.h	(original)
+++ python/branches/py3k-importlib/Include/patchlevel.h	Thu Mar 27 00:48:05 2008
@@ -19,10 +19,10 @@
 #define PY_MINOR_VERSION	0
 #define PY_MICRO_VERSION	0
 #define PY_RELEASE_LEVEL	PY_RELEASE_LEVEL_ALPHA
-#define PY_RELEASE_SERIAL	1
+#define PY_RELEASE_SERIAL	3
 
 /* Version as a string */
-#define PY_VERSION		"3.0a1"
+#define PY_VERSION		"3.0a3+"
 
 /* Subversion Revision number of this file (not of the repository) */
 #define PY_PATCHLEVEL_REVISION  "$Revision$"

Modified: python/branches/py3k-importlib/Include/py_curses.h
==============================================================================
--- python/branches/py3k-importlib/Include/py_curses.h	(original)
+++ python/branches/py3k-importlib/Include/py_curses.h	Thu Mar 27 00:48:05 2008
@@ -73,7 +73,7 @@
 	WINDOW *win;
 } PyCursesWindowObject;
 
-#define PyCursesWindow_Check(v)	 (Py_Type(v) == &PyCursesWindow_Type)
+#define PyCursesWindow_Check(v)	 (Py_TYPE(v) == &PyCursesWindow_Type)
 
 #ifdef CURSES_MODULE
 /* This section is used when compiling _cursesmodule.c */
@@ -90,7 +90,7 @@
 
 #define import_curses() \
 { \
-  PyObject *module = PyImport_ImportModule("_curses"); \
+  PyObject *module = PyImport_ImportModuleNoBlock("_curses"); \
   if (module != NULL) { \
     PyObject *module_dict = PyModule_GetDict(module); \
     PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
@@ -139,7 +139,7 @@
 static PyObject *PyCurses_ ## X (PyObject *self) \
 { \
  PyCursesInitialised \
- return PyInt_FromLong((long) X()); }
+ return PyLong_FromLong((long) X()); }
 
 
 #define NoArgReturnStringFunction(X) \

Modified: python/branches/py3k-importlib/Include/pydebug.h
==============================================================================
--- python/branches/py3k-importlib/Include/pydebug.h	(original)
+++ python/branches/py3k-importlib/Include/pydebug.h	Thu Mar 27 00:48:05 2008
@@ -11,11 +11,13 @@
 PyAPI_DATA(int) Py_InspectFlag;
 PyAPI_DATA(int) Py_OptimizeFlag;
 PyAPI_DATA(int) Py_NoSiteFlag;
+PyAPI_DATA(int) Py_BytesWarningFlag;
 PyAPI_DATA(int) Py_UseClassExceptionsFlag;
 PyAPI_DATA(int) Py_FrozenFlag;
 PyAPI_DATA(int) Py_TabcheckFlag;
 PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
 PyAPI_DATA(int) Py_DivisionWarningFlag;
+PyAPI_DATA(int) Py_DontWriteBytecodeFlag;
 
 /* this is a wrapper around getenv() that pays attention to
    Py_IgnoreEnvironmentFlag.  It should be used for getting variables like

Modified: python/branches/py3k-importlib/Include/pyerrors.h
==============================================================================
--- python/branches/py3k-importlib/Include/pyerrors.h	(original)
+++ python/branches/py3k-importlib/Include/pyerrors.h	Thu Mar 27 00:48:05 2008
@@ -152,6 +152,8 @@
 PyAPI_DATA(PyObject *) PyExc_VMSError;
 #endif
 
+PyAPI_DATA(PyObject *) PyExc_BufferError;
+
 PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst;
 PyAPI_DATA(PyObject *) PyExc_RecursionErrorInst;
 
@@ -165,6 +167,7 @@
 PyAPI_DATA(PyObject *) PyExc_FutureWarning;
 PyAPI_DATA(PyObject *) PyExc_ImportWarning;
 PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;
+PyAPI_DATA(PyObject *) PyExc_BytesWarning;
 
 
 /* Convenience functions */
@@ -226,6 +229,9 @@
 PyAPI_FUNC(int) PyErr_CheckSignals(void);
 PyAPI_FUNC(void) PyErr_SetInterrupt(void);
 
+/* In signalmodule.c */
+int PySignal_SetWakeupFd(int fd);
+
 /* Support for adding program text to SyntaxErrors */
 PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
 PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);

Modified: python/branches/py3k-importlib/Include/pyport.h
==============================================================================
--- python/branches/py3k-importlib/Include/pyport.h	(original)
+++ python/branches/py3k-importlib/Include/pyport.h	Thu Mar 27 00:48:05 2008
@@ -111,6 +111,10 @@
 /* Smallest negative value of type Py_ssize_t. */
 #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
 
+#if SIZEOF_PID_T > SIZEOF_LONG
+#   error "Python doesn't support sizeof(pid_t) > sizeof(long)"
+#endif
+
 /* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
  * format to convert an argument with the width of a size_t or Py_ssize_t.
  * C99 introduced "z" for this purpose, but not all platforms support that;
@@ -332,6 +336,24 @@
 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
 #endif
 
+/* High precision defintion of pi and e (Euler)
+ * The values are taken from libc6's math.h.
+ */
+#ifndef Py_MATH_PIl
+#define Py_MATH_PIl 3.1415926535897932384626433832795029L
+#endif
+#ifndef Py_MATH_PI
+#define Py_MATH_PI 3.14159265358979323846
+#endif
+
+#ifndef Py_MATH_El
+#define Py_MATH_El 2.7182818284590452353602874713526625L
+#endif
+
+#ifndef Py_MATH_E
+#define Py_MATH_E 2.7182818284590452354
+#endif
+
 /* Py_IS_NAN(X)
  * Return 1 if float or double arg is a NaN, else 0.
  * Caution:
@@ -341,8 +363,12 @@
  *     a platform where it doesn't work.
  */
 #ifndef Py_IS_NAN
+#ifdef HAVE_ISNAN
+#define Py_IS_NAN(X) isnan(X)
+#else
 #define Py_IS_NAN(X) ((X) != (X))
 #endif
+#endif
 
 /* Py_IS_INFINITY(X)
  * Return 1 if float or double arg is an infinity, else 0.
@@ -353,8 +379,12 @@
  *    Override in pyconfig.h if you have a better spelling on your platform.
  */
 #ifndef Py_IS_INFINITY
+#ifdef HAVE_ISINF
+#define Py_IS_INFINITY(X) isinf(X)
+#else
 #define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))
 #endif
+#endif
 
 /* Py_IS_FINITE(X)
  * Return 1 if float or double arg is neither infinite nor NAN, else 0.
@@ -362,8 +392,12 @@
  * macro for this particular test is useful
  */
 #ifndef Py_IS_FINITE
+#ifdef HAVE_FINITE
+#define Py_IS_FINITE(X) finite(X)
+#else
 #define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
 #endif
+#endif
 
 /* HUGE_VAL is supposed to expand to a positive double infinity.  Python
  * uses Py_HUGE_VAL instead because some platforms are broken in this
@@ -376,6 +410,15 @@
 #define Py_HUGE_VAL HUGE_VAL
 #endif
 
+/* Py_NAN
+ * A value that evaluates to a NaN. On IEEE 754 platforms INF*0 or
+ * INF/INF works. Define Py_NO_NAN in pyconfig.h if your platform
+ * doesn't support NaNs.
+ */
+#if !defined(Py_NAN) && !defined(Py_NO_NAN)
+#define Py_NAN (Py_HUGE_VAL * 0.)
+#endif
+
 /* Py_OVERFLOWED(X)
  * Return 1 iff a libm function overflowed.  Set errno to 0 before calling
  * a libm function, and invoke this macro after, passing the function
@@ -511,7 +554,7 @@
    functions, even though they are included in libutil. */
 #include <termios.h>
 extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
-extern int forkpty(int *, char *, struct termios *, struct winsize *);
+extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
 #endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */
 #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
 

Modified: python/branches/py3k-importlib/Include/pythonrun.h
==============================================================================
--- python/branches/py3k-importlib/Include/pythonrun.h	(original)
+++ python/branches/py3k-importlib/Include/pythonrun.h	Thu Mar 27 00:48:05 2008
@@ -127,7 +127,6 @@
 PyAPI_FUNC(void) _PyExc_Init(void);
 PyAPI_FUNC(void) _PyImportHooks_Init(void);
 PyAPI_FUNC(int) _PyFrame_Init(void);
-PyAPI_FUNC(int) _PyInt_Init(void);
 PyAPI_FUNC(void) _PyFloat_Init(void);
 PyAPI_FUNC(int) PyBytes_Init(void);
 
@@ -137,12 +136,12 @@
 PyAPI_FUNC(void) PyMethod_Fini(void);
 PyAPI_FUNC(void) PyFrame_Fini(void);
 PyAPI_FUNC(void) PyCFunction_Fini(void);
+PyAPI_FUNC(void) PyDict_Fini(void);
 PyAPI_FUNC(void) PyTuple_Fini(void);
 PyAPI_FUNC(void) PyList_Fini(void);
 PyAPI_FUNC(void) PySet_Fini(void);
 PyAPI_FUNC(void) PyString_Fini(void);
 PyAPI_FUNC(void) PyBytes_Fini(void);
-PyAPI_FUNC(void) PyInt_Fini(void);
 PyAPI_FUNC(void) PyFloat_Fini(void);
 PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
 

Modified: python/branches/py3k-importlib/Include/rangeobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/rangeobject.h	(original)
+++ python/branches/py3k-importlib/Include/rangeobject.h	Thu Mar 27 00:48:05 2008
@@ -16,8 +16,10 @@
 */
 
 PyAPI_DATA(PyTypeObject) PyRange_Type;
+PyAPI_DATA(PyTypeObject) PyRangeIter_Type;
+PyAPI_DATA(PyTypeObject) PyLongRangeIter_Type;
 
-#define PyRange_Check(op) (Py_Type(op) == &PyRange_Type)
+#define PyRange_Check(op) (Py_TYPE(op) == &PyRange_Type)
 
 #ifdef __cplusplus
 }

Modified: python/branches/py3k-importlib/Include/setobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/setobject.h	(original)
+++ python/branches/py3k-importlib/Include/setobject.h	Thu Mar 27 00:48:05 2008
@@ -58,6 +58,7 @@
 
 PyAPI_DATA(PyTypeObject) PySet_Type;
 PyAPI_DATA(PyTypeObject) PyFrozenSet_Type;
+PyAPI_DATA(PyTypeObject) PySetIter_Type;
 
 /* Invariants for frozensets:
  *     data is immutable.
@@ -66,13 +67,19 @@
  *     hash is -1
  */
 
-#define PyFrozenSet_CheckExact(ob) (Py_Type(ob) == &PyFrozenSet_Type)
+#define PyFrozenSet_CheckExact(ob) (Py_TYPE(ob) == &PyFrozenSet_Type)
 #define PyAnySet_CheckExact(ob) \
-	(Py_Type(ob) == &PySet_Type || Py_Type(ob) == &PyFrozenSet_Type)
+	(Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type)
 #define PyAnySet_Check(ob) \
-	(Py_Type(ob) == &PySet_Type || Py_Type(ob) == &PyFrozenSet_Type || \
-	  PyType_IsSubtype(Py_Type(ob), &PySet_Type) || \
-	  PyType_IsSubtype(Py_Type(ob), &PyFrozenSet_Type))
+	(Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type || \
+	  PyType_IsSubtype(Py_TYPE(ob), &PySet_Type) || \
+	  PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type))
+#define PySet_Check(ob) \
+	(Py_TYPE(ob) == &PySet_Type || \
+	PyType_IsSubtype(Py_TYPE(ob), &PySet_Type))
+#define   PyFrozenSet_Check(ob) \
+	(Py_TYPE(ob) == &PyFrozenSet_Type || \
+	  PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type))
 
 PyAPI_FUNC(PyObject *) PySet_New(PyObject *);
 PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *);
@@ -82,7 +89,6 @@
 PyAPI_FUNC(int) PySet_Contains(PyObject *anyset, PyObject *key);
 PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key);
 PyAPI_FUNC(int) PySet_Add(PyObject *set, PyObject *key);
-PyAPI_FUNC(int) _PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **key);
 PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash);
 PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set);
 PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);

Modified: python/branches/py3k-importlib/Include/sliceobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/sliceobject.h	(original)
+++ python/branches/py3k-importlib/Include/sliceobject.h	Thu Mar 27 00:48:05 2008
@@ -26,7 +26,7 @@
 
 PyAPI_DATA(PyTypeObject) PySlice_Type;
 
-#define PySlice_Check(op) (Py_Type(op) == &PySlice_Type)
+#define PySlice_Check(op) (Py_TYPE(op) == &PySlice_Type)
 
 PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop,
                                   PyObject* step);

Modified: python/branches/py3k-importlib/Include/stringobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/stringobject.h	(original)
+++ python/branches/py3k-importlib/Include/stringobject.h	Thu Mar 27 00:48:05 2008
@@ -25,35 +25,26 @@
 */
 
 /* Caching the hash (ob_shash) saves recalculation of a string's hash value.
-   Interning strings (ob_sstate) tries to ensure that only one string
-   object with a given value exists, so equality tests can be one pointer
-   comparison.  This is generally restricted to strings that "look like"
-   Python identifiers, although the sys.intern() function can be used to force
-   interning of any string.
-   Together, these sped the interpreter by up to 20%. */
+   This significantly speeds up dict lookups. */
 
 typedef struct {
     PyObject_VAR_HEAD
     long ob_shash;
-    int ob_sstate;
     char ob_sval[1];
 
     /* Invariants:
      *     ob_sval contains space for 'ob_size+1' elements.
      *     ob_sval[ob_size] == 0.
      *     ob_shash is the hash of the string or -1 if not computed yet.
-     *     ob_sstate != 0 iff the string object is in stringobject.c's
-     *       'interned' dictionary; in this case the two references
-     *       from 'interned' to this object are *not counted* in ob_refcnt.
      */
 } PyStringObject;
 
-PyAPI_DATA(PyTypeObject) PyBaseString_Type;
 PyAPI_DATA(PyTypeObject) PyString_Type;
+PyAPI_DATA(PyTypeObject) PyStringIter_Type;
 
 #define PyString_Check(op) \
-                 PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_STRING_SUBCLASS)
-#define PyString_CheckExact(op) (Py_Type(op) == &PyString_Type)
+                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS)
+#define PyString_CheckExact(op) (Py_TYPE(op) == &PyString_Type)
 
 PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);
 PyAPI_FUNC(PyObject *) PyString_FromString(const char *);
@@ -67,104 +58,27 @@
 PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);
 PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);
 PyAPI_FUNC(int) _PyString_Resize(PyObject **, Py_ssize_t);
-PyAPI_FUNC(int) _PyString_Eq(PyObject *, PyObject*);
 PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);
 PyAPI_FUNC(PyObject *) _PyString_FormatLong(PyObject*, int, int,
 						  int, char**, int*);
-PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t, 
+PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t,
 						   const char *, Py_ssize_t,
 						   const char *);
 
-PyAPI_FUNC(void) PyString_InternInPlace(PyObject **);
-PyAPI_FUNC(void) PyString_InternImmortal(PyObject **);
-PyAPI_FUNC(PyObject *) PyString_InternFromString(const char *);
-PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);
-
-/* Use only if you know it's a string */
-#define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate)
-
 /* Macro, trading safety for speed */
-#define PyString_AS_STRING(op) (assert(PyString_Check(op)),(((PyStringObject *)(op))->ob_sval))
-#define PyString_GET_SIZE(op)  (assert(PyString_Check(op)),Py_Size(op))
+#define PyString_AS_STRING(op) (assert(PyString_Check(op)), \
+                                (((PyStringObject *)(op))->ob_sval))
+#define PyString_GET_SIZE(op)  (assert(PyString_Check(op)),Py_SIZE(op))
 
 /* _PyString_Join(sep, x) is like sep.join(x).  sep must be PyStringObject*,
    x must be an iterable object. */
 PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);
 
-/* --- Generic Codecs ----------------------------------------------------- */
-
-/* Create an object by decoding the encoded string s of the
-   given size. */
-
-PyAPI_FUNC(PyObject*) PyString_Decode(
-    const char *s,              /* encoded string */
-    Py_ssize_t size,            /* size of buffer */
-    const char *encoding,       /* encoding */
-    const char *errors          /* error handling */
-    );
-
-/* Encodes a char buffer of the given size and returns a 
-   Python object. */
-
-PyAPI_FUNC(PyObject*) PyString_Encode(
-    const char *s,              /* string char buffer */
-    Py_ssize_t size,            /* number of chars to encode */
-    const char *encoding,       /* encoding */
-    const char *errors          /* error handling */
-    );
-
-/* Encodes a string object and returns the result as Python 
-   object. */
-
-PyAPI_FUNC(PyObject*) PyString_AsEncodedObject(
-    PyObject *str,	 	/* string object */
-    const char *encoding,	/* encoding */
-    const char *errors		/* error handling */
-    );
-
-/* Encodes a string object and returns the result as Python string
-   object.   
-   
-   If the codec returns an Unicode object, the object is converted
-   back to a string using the default encoding.
-
-   DEPRECATED - use PyString_AsEncodedObject() instead. */
-
-PyAPI_FUNC(PyObject*) PyString_AsEncodedString(
-    PyObject *str,	 	/* string object */
-    const char *encoding,	/* encoding */
-    const char *errors		/* error handling */
-    );
-
-/* Decodes a string object and returns the result as Python 
-   object. */
-
-PyAPI_FUNC(PyObject*) PyString_AsDecodedObject(
-    PyObject *str,	 	/* string object */
-    const char *encoding,	/* encoding */
-    const char *errors		/* error handling */
-    );
-
-/* Decodes a string object and returns the result as Python string
-   object.  
-   
-   If the codec returns an Unicode object, the object is converted
-   back to a string using the default encoding.
-
-   DEPRECATED - use PyString_AsDecodedObject() instead. */
-
-PyAPI_FUNC(PyObject*) PyString_AsDecodedString(
-    PyObject *str,	 	/* string object */
-    const char *encoding,	/* encoding */
-    const char *errors		/* error handling */
-    );
-
 /* Provides access to the internal data buffer and size of a string
    object or the default encoded version of an Unicode object. Passing
    NULL as *len parameter will force the string buffer to be
    0-terminated (passing a string with embedded NULL characters will
    cause an exception).  */
-
 PyAPI_FUNC(int) PyString_AsStringAndSize(
     register PyObject *obj,	/* string or Unicode object */
     register char **s,		/* pointer to buffer variable */
@@ -172,7 +86,13 @@
 				   (only possible for 0-terminated
 				   strings) */
     );
-    
+
+/* Flags used by string formatting */
+#define F_LJUST (1<<0)
+#define F_SIGN	(1<<1)
+#define F_BLANK (1<<2)
+#define F_ALT	(1<<3)
+#define F_ZERO	(1<<4)
 
 #ifdef __cplusplus
 }

Modified: python/branches/py3k-importlib/Include/structmember.h
==============================================================================
--- python/branches/py3k-importlib/Include/structmember.h	(original)
+++ python/branches/py3k-importlib/Include/structmember.h	Thu Mar 27 00:48:05 2008
@@ -54,6 +54,9 @@
 /* Added by Jack: strings contained in the structure */
 #define T_STRING_INPLACE	13
 
+/* Added by Lillo: bools contained in the structure (assumed char) */
+#define T_BOOL		14
+
 #define T_OBJECT_EX	16	/* Like T_OBJECT, but raises AttributeError
 				   when the value is NULL, instead of
 				   converting to None. */
@@ -69,8 +72,8 @@
 /* Flags */
 #define READONLY	1
 #define READ_RESTRICTED	2
-#define WRITE_RESTRICTED 4
-#define RESTRICTED	(READ_RESTRICTED | WRITE_RESTRICTED)
+#define PY_WRITE_RESTRICTED 4
+#define RESTRICTED	(READ_RESTRICTED | PY_WRITE_RESTRICTED)
 
 
 /* Current API, use this */

Modified: python/branches/py3k-importlib/Include/symtable.h
==============================================================================
--- python/branches/py3k-importlib/Include/symtable.h	(original)
+++ python/branches/py3k-importlib/Include/symtable.h	Thu Mar 27 00:48:05 2008
@@ -53,7 +53,7 @@
 
 PyAPI_DATA(PyTypeObject) PySTEntry_Type;
 
-#define PySTEntry_Check(op) (Py_Type(op) == &PySTEntry_Type)
+#define PySTEntry_Check(op) (Py_TYPE(op) == &PySTEntry_Type)
 
 PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *);
 

Modified: python/branches/py3k-importlib/Include/traceback.h
==============================================================================
--- python/branches/py3k-importlib/Include/traceback.h	(original)
+++ python/branches/py3k-importlib/Include/traceback.h	Thu Mar 27 00:48:05 2008
@@ -22,7 +22,7 @@
 
 /* Reveal traceback type so we can typecheck traceback objects */
 PyAPI_DATA(PyTypeObject) PyTraceBack_Type;
-#define PyTraceBack_Check(v) (Py_Type(v) == &PyTraceBack_Type)
+#define PyTraceBack_Check(v) (Py_TYPE(v) == &PyTraceBack_Type)
 
 #ifdef __cplusplus
 }

Modified: python/branches/py3k-importlib/Include/tupleobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/tupleobject.h	(original)
+++ python/branches/py3k-importlib/Include/tupleobject.h	Thu Mar 27 00:48:05 2008
@@ -32,10 +32,11 @@
 } PyTupleObject;
 
 PyAPI_DATA(PyTypeObject) PyTuple_Type;
+PyAPI_DATA(PyTypeObject) PyTupleIter_Type;
 
 #define PyTuple_Check(op) \
-                 PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_TUPLE_SUBCLASS)
-#define PyTuple_CheckExact(op) (Py_Type(op) == &PyTuple_Type)
+                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
+#define PyTuple_CheckExact(op) (Py_TYPE(op) == &PyTuple_Type)
 
 PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size);
 PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *);
@@ -47,11 +48,13 @@
 
 /* Macro, trading safety for speed */
 #define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
-#define PyTuple_GET_SIZE(op)    Py_Size(op)
+#define PyTuple_GET_SIZE(op)    Py_SIZE(op)
 
 /* Macro, *only* to be used to fill in brand new tuples */
 #define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
 
+PyAPI_FUNC(int) PyTuple_ClearFreeList(void);
+
 #ifdef __cplusplus
 }
 #endif

Modified: python/branches/py3k-importlib/Include/unicodeobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/unicodeobject.h	(original)
+++ python/branches/py3k-importlib/Include/unicodeobject.h	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,8 @@
 #ifndef Py_UNICODEOBJECT_H
 #define Py_UNICODEOBJECT_H
 
+#include <stdarg.h>
+
 /*
 
 Unicode implementation based on original code by Fredrik Lundh,
@@ -58,6 +60,9 @@
 
 /* --- Internal Unicode Format -------------------------------------------- */
 
+/* Python 3.x requires unicode */
+#define Py_USING_UNICODE 
+
 /* FIXME: MvL's new implementation assumes that Py_UNICODE_SIZE is
    properly set, but the default rules below doesn't set it.  I'll
    sort this out some other day -- fredrik at pythonware.com */
@@ -155,6 +160,7 @@
 # define PyUnicode_DecodeCharmap PyUnicodeUCS2_DecodeCharmap
 # define PyUnicode_DecodeLatin1 PyUnicodeUCS2_DecodeLatin1
 # define PyUnicode_DecodeFSDefault PyUnicodeUCS2_DecodeFSDefault
+# define PyUnicode_DecodeFSDefaultAndSize PyUnicodeUCS2_DecodeFSDefaultAndSize
 # define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS2_DecodeRawUnicodeEscape
 # define PyUnicode_DecodeUTF32 PyUnicodeUCS2_DecodeUTF32
 # define PyUnicode_DecodeUTF32Stateful PyUnicodeUCS2_DecodeUTF32Stateful
@@ -204,6 +210,7 @@
 # define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS2_AsDefaultEncodedString
 # define _PyUnicode_Fini _PyUnicodeUCS2_Fini
 # define _PyUnicode_Init _PyUnicodeUCS2_Init
+# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist
 # define _PyUnicode_IsAlpha _PyUnicodeUCS2_IsAlpha
 # define _PyUnicode_IsDecimalDigit _PyUnicodeUCS2_IsDecimalDigit
 # define _PyUnicode_IsDigit _PyUnicodeUCS2_IsDigit
@@ -247,6 +254,7 @@
 # define PyUnicode_DecodeCharmap PyUnicodeUCS4_DecodeCharmap
 # define PyUnicode_DecodeLatin1 PyUnicodeUCS4_DecodeLatin1
 # define PyUnicode_DecodeFSDefault PyUnicodeUCS4_DecodeFSDefault
+# define PyUnicode_DecodeFSDefaultAndSize PyUnicodeUCS4_DecodeFSDefaultAndSize
 # define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS4_DecodeRawUnicodeEscape
 # define PyUnicode_DecodeUTF32 PyUnicodeUCS4_DecodeUTF32
 # define PyUnicode_DecodeUTF32Stateful PyUnicodeUCS4_DecodeUTF32Stateful
@@ -296,6 +304,7 @@
 # define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS4_AsDefaultEncodedString
 # define _PyUnicode_Fini _PyUnicodeUCS4_Fini
 # define _PyUnicode_Init _PyUnicodeUCS4_Init
+# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist
 # define _PyUnicode_IsAlpha _PyUnicodeUCS4_IsAlpha
 # define _PyUnicode_IsDecimalDigit _PyUnicodeUCS4_IsDecimalDigit
 # define _PyUnicode_IsDigit _PyUnicodeUCS4_IsDigit
@@ -351,7 +360,14 @@
 
 #else
 
-#define Py_UNICODE_ISSPACE(ch) _PyUnicode_IsWhitespace(ch)
+/* Since splitting on whitespace is an important use case, and whitespace
+   in most situations is solely ASCII whitespace, we optimize for the common
+   case by using a quick look-up table with an inlined check.
+ */
+extern const unsigned char _Py_ascii_whitespace[];
+
+#define Py_UNICODE_ISSPACE(ch) \
+	((ch) < 128U ? _Py_ascii_whitespace[(ch)] : _PyUnicode_IsWhitespace(ch))
 
 #define Py_UNICODE_ISLOWER(ch) _PyUnicode_IsLowercase(ch)
 #define Py_UNICODE_ISUPPER(ch) _PyUnicode_IsUppercase(ch)
@@ -399,6 +415,8 @@
 extern "C" {
 #endif
 
+PyAPI_FUNC(int) PyUnicode_ClearFreeList(void);
+
 /* --- Unicode Type ------------------------------------------------------- */
 
 typedef struct {
@@ -415,14 +433,15 @@
 } PyUnicodeObject;
 
 PyAPI_DATA(PyTypeObject) PyUnicode_Type;
+PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type;
 
 #define SSTATE_NOT_INTERNED 0
 #define SSTATE_INTERNED_MORTAL 1
 #define SSTATE_INTERNED_IMMORTAL 2
 
 #define PyUnicode_Check(op) \
-                 PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_UNICODE_SUBCLASS)
-#define PyUnicode_CheckExact(op) (Py_Type(op) == &PyUnicode_Type)
+                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
+#define PyUnicode_CheckExact(op) (Py_TYPE(op) == &PyUnicode_Type)
 
 /* Fast access macros */
 #define PyUnicode_GET_SIZE(op) \
@@ -657,6 +676,12 @@
     const char *s               /* encoded string */
     );
 
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefaultAndSize(
+    const char *s,               /* encoded string */
+    Py_ssize_t size              /* size */
+    );
+
+
 /* Return a char* holding the UTF-8 encoded value of the
    Unicode object.
 
@@ -743,6 +768,13 @@
     const char *errors		/* error handling */
     );
 
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7Stateful(
+    const char *string, 	/* UTF-7 encoded string */
+    Py_ssize_t length,	 	/* size of string */
+    const char *errors,		/* error handling */
+    Py_ssize_t *consumed	/* bytes consumed */
+    );
+
 PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7(
     const Py_UNICODE *data, 	/* Unicode char buffer */
     Py_ssize_t length,	 	/* number of Py_UNICODE chars to encode */

Modified: python/branches/py3k-importlib/Include/weakrefobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/weakrefobject.h	(original)
+++ python/branches/py3k-importlib/Include/weakrefobject.h	Thu Mar 27 00:48:05 2008
@@ -44,10 +44,10 @@
 
 #define PyWeakref_CheckRef(op) PyObject_TypeCheck(op, &_PyWeakref_RefType)
 #define PyWeakref_CheckRefExact(op) \
-        (Py_Type(op) == &_PyWeakref_RefType)
+        (Py_TYPE(op) == &_PyWeakref_RefType)
 #define PyWeakref_CheckProxy(op) \
-        ((Py_Type(op) == &_PyWeakref_ProxyType) || \
-         (Py_Type(op) == &_PyWeakref_CallableProxyType))
+        ((Py_TYPE(op) == &_PyWeakref_ProxyType) || \
+         (Py_TYPE(op) == &_PyWeakref_CallableProxyType))
 
 /* This macro calls PyWeakref_CheckRef() last since that can involve a
    function call; this makes it more likely that the function call

Modified: python/branches/py3k-importlib/LICENSE
==============================================================================
--- python/branches/py3k-importlib/LICENSE	(original)
+++ python/branches/py3k-importlib/LICENSE	Thu Mar 27 00:48:05 2008
@@ -55,7 +55,7 @@
     2.4.4           2.4.3       2006        PSF         yes
     2.5             2.4         2006        PSF         yes
     2.5.1           2.5         2007        PSF         yes
-    2.6             2.5         unreleased  PSF         yes
+    2.6             2.5         2008        PSF         yes
     3.0             2.6         2007        PSF         yes
 
 Footnotes:
@@ -92,7 +92,7 @@
 prepare derivative works, distribute, and otherwise use Python
 alone or in any derivative version, provided, however, that PSF's
 License Agreement and PSF's notice of copyright, i.e., "Copyright (c)
-2001, 2002, 2003, 2004, 2005, 2006, 2007 Python Software Foundation; 
+2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Python Software Foundation; 
 All Rights Reserved" are retained in Python alone or in any derivative 
 version prepared by Licensee.
 

Modified: python/branches/py3k-importlib/Lib/BaseHTTPServer.py
==============================================================================
--- python/branches/py3k-importlib/Lib/BaseHTTPServer.py	(original)
+++ python/branches/py3k-importlib/Lib/BaseHTTPServer.py	Thu Mar 27 00:48:05 2008
@@ -77,7 +77,7 @@
 import mimetools
 import SocketServer
 
-# Default error message
+# Default error message template
 DEFAULT_ERROR_MESSAGE = """\
 <head>
 <title>Error response</title>
@@ -90,6 +90,8 @@
 </body>
 """
 
+DEFAULT_ERROR_CONTENT_TYPE = "text/html;charset=utf-8"
+
 def _quote_html(html):
     return html.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
 
@@ -217,6 +219,9 @@
     # where each string is of the form name[/version].
     server_version = "BaseHTTP/" + __version__
 
+    error_message_format = DEFAULT_ERROR_MESSAGE
+    error_content_type = DEFAULT_ERROR_CONTENT_TYPE
+
     def parse_request(self):
         """Parse a request (internal).
 
@@ -356,13 +361,11 @@
         content = (self.error_message_format %
                    {'code': code, 'message': _quote_html(message), 'explain': explain})
         self.send_response(code, message)
-        self.send_header("Content-Type", "text/html")
+        self.send_header("Content-Type", self.error_content_type)
         self.send_header('Connection', 'close')
         self.end_headers()
         if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
-            self.wfile.write(content)
-
-    error_message_format = DEFAULT_ERROR_MESSAGE
+            self.wfile.write(content.encode('UTF-8', 'replace'))
 
     def send_response(self, code, message=None):
         """Send the response header and log the response code.
@@ -378,8 +381,8 @@
             else:
                 message = ''
         if self.request_version != 'HTTP/0.9':
-            self.wfile.write("%s %d %s\r\n" %
-                             (self.protocol_version, code, message))
+            self.wfile.write(("%s %d %s\r\n" %
+                              (self.protocol_version, code, message)).encode('ASCII', 'strict'))
             # print (self.protocol_version, code, message)
         self.send_header('Server', self.version_string())
         self.send_header('Date', self.date_time_string())
@@ -387,7 +390,7 @@
     def send_header(self, keyword, value):
         """Send a MIME header."""
         if self.request_version != 'HTTP/0.9':
-            self.wfile.write("%s: %s\r\n" % (keyword, value))
+            self.wfile.write(("%s: %s\r\n" % (keyword, value)).encode('ASCII', 'strict'))
 
         if keyword.lower() == 'connection':
             if value.lower() == 'close':
@@ -398,7 +401,7 @@
     def end_headers(self):
         """Send the blank line ending the MIME headers."""
         if self.request_version != 'HTTP/0.9':
-            self.wfile.write("\r\n")
+            self.wfile.write(b"\r\n")
 
     def log_request(self, code='-', size='-'):
         """Log an accepted request.

Modified: python/branches/py3k-importlib/Lib/ConfigParser.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ConfigParser.py	(original)
+++ python/branches/py3k-importlib/Lib/ConfigParser.py	Thu Mar 27 00:48:05 2008
@@ -235,8 +235,12 @@
         """Create a new section in the configuration.
 
         Raise DuplicateSectionError if a section by the specified name
-        already exists.
+        already exists. Raise ValueError if name is DEFAULT or any of it's
+        case-insensitive variants.
         """
+        if section.lower() == "default":
+            raise ValueError('Invalid section name: %s' % section)
+
         if section in self._sections:
             raise DuplicateSectionError(section)
         self._sections[section] = self._dict()
@@ -271,7 +275,7 @@
 
         Return list of successfully read files.
         """
-        if isinstance(filenames, basestring):
+        if isinstance(filenames, str):
             filenames = [filenames]
         read_ok = []
         for filename in filenames:
@@ -652,7 +656,7 @@
 
     def set(self, section, option, value):
         """Set an option.  Extend ConfigParser.set: check for string values."""
-        if not isinstance(value, basestring):
+        if not isinstance(value, str):
             raise TypeError("option values must be strings")
         # check for bad percent signs:
         # first, replace all "good" interpolations

Modified: python/branches/py3k-importlib/Lib/DocXMLRPCServer.py
==============================================================================
--- python/branches/py3k-importlib/Lib/DocXMLRPCServer.py	(original)
+++ python/branches/py3k-importlib/Lib/DocXMLRPCServer.py	Thu Mar 27 00:48:05 2008
@@ -30,7 +30,7 @@
         results = []
         here = 0
 
-        # XXX Note that this regular expressions does not allow for the
+        # XXX Note that this regular expression does not allow for the
         # hyperlinking of arbitrary strings being used as method
         # names. Only methods with names consisting of word characters
         # and '.'s are hyperlinked.
@@ -52,7 +52,7 @@
                 url = 'http://www.rfc-editor.org/rfc/rfc%d.txt' % int(rfc)
                 results.append('<a href="%s">%s</a>' % (url, escape(all)))
             elif pep:
-                url = 'http://www.python.org/peps/pep-%04d.html' % int(pep)
+                url = 'http://www.python.org/dev/peps/pep-%04d/' % int(pep)
                 results.append('<a href="%s">%s</a>' % (url, escape(all)))
             elif text[end:end+1] == '(':
                 results.append(self.namelink(name, methods, funcs, classes))
@@ -64,17 +64,18 @@
         results.append(escape(text[here:]))
         return ''.join(results)
 
-    def docroutine(self, object, name=None, mod=None,
+    def docroutine(self, object, name, mod=None,
                    funcs={}, classes={}, methods={}, cl=None):
         """Produce HTML documentation for a function or method object."""
 
         anchor = (cl and cl.__name__ or '') + '-' + name
         note = ''
 
-        title = '<a name="%s"><strong>%s</strong></a>' % (anchor, name)
+        title = '<a name="%s"><strong>%s</strong></a>' % (
+            self.escape(anchor), self.escape(name))
 
         if inspect.ismethod(object):
-            args, varargs, varkw, defaults = inspect.getargspec(object.im_func)
+            args, varargs, varkw, defaults = inspect.getargspec(object)
             # exclude the argument bound to the instance, it will be
             # confusing to the non-Python user
             argspec = inspect.formatargspec (
@@ -113,6 +114,7 @@
             fdict[key] = '#-' + key
             fdict[value] = fdict[key]
 
+        server_name = self.escape(server_name)
         head = '<big><big><strong>%s</strong></big></big>' % server_name
         result = self.heading(head, '#ffffff', '#7799ee')
 
@@ -121,12 +123,11 @@
         result = result + '<p>%s</p>\n' % doc
 
         contents = []
-        method_items = methods.items()
-        method_items.sort()
+        method_items = sorted(methods.items())
         for key, value in method_items:
             contents.append(self.docroutine(value, key, funcs=fdict))
         result = result + self.bigsection(
-            'Methods', '#ffffff', '#eeaa77', pydoc.join(contents))
+            'Methods', '#ffffff', '#eeaa77', ''.join(contents))
 
         return result
 
@@ -237,7 +238,7 @@
         self.send_header("Content-type", "text/html")
         self.send_header("Content-length", str(len(response)))
         self.end_headers()
-        self.wfile.write(response)
+        self.wfile.write(response.encode())
 
         # shut down the connection
         self.wfile.flush()
@@ -280,29 +281,3 @@
     def __init__(self):
         CGIXMLRPCRequestHandler.__init__(self)
         XMLRPCDocGenerator.__init__(self)
-
-if __name__ == '__main__':
-    def deg_to_rad(deg):
-        """deg_to_rad(90) => 1.5707963267948966
-
-        Converts an angle in degrees to an angle in radians"""
-        import math
-        return deg * math.pi / 180
-
-    server = DocXMLRPCServer(("localhost", 8000))
-
-    server.set_server_title("Math Server")
-    server.set_server_name("Math XML-RPC Server")
-    server.set_server_documentation("""This server supports various mathematical functions.
-
-You can use it from Python as follows:
-
->>> from xmlrpclib import ServerProxy
->>> s = ServerProxy("http://localhost:8000")
->>> s.deg_to_rad(90.0)
-1.5707963267948966""")
-
-    server.register_function(deg_to_rad)
-    server.register_introspection_functions()
-
-    server.serve_forever()

Modified: python/branches/py3k-importlib/Lib/HTMLParser.py
==============================================================================
--- python/branches/py3k-importlib/Lib/HTMLParser.py	(original)
+++ python/branches/py3k-importlib/Lib/HTMLParser.py	Thu Mar 27 00:48:05 2008
@@ -8,7 +8,7 @@
 # and CDATA (character data -- only end tags are special).
 
 
-import markupbase
+import _markupbase
 import re
 
 # Regular expressions used for parsing
@@ -64,7 +64,7 @@
         return result
 
 
-class HTMLParser(markupbase.ParserBase):
+class HTMLParser(_markupbase.ParserBase):
     """Find tags and other markup and call handler functions.
 
     Usage:
@@ -96,7 +96,7 @@
         self.rawdata = ''
         self.lasttag = '???'
         self.interesting = interesting_normal
-        markupbase.ParserBase.reset(self)
+        _markupbase.ParserBase.reset(self)
 
     def feed(self, data):
         """Feed data to the parser.

Modified: python/branches/py3k-importlib/Lib/Queue.py
==============================================================================
--- python/branches/py3k-importlib/Lib/Queue.py	(original)
+++ python/branches/py3k-importlib/Lib/Queue.py	Thu Mar 27 00:48:05 2008
@@ -2,8 +2,9 @@
 
 from time import time as _time
 from collections import deque
+import heapq
 
-__all__ = ['Empty', 'Full', 'Queue']
+__all__ = ['Empty', 'Full', 'Queue', 'PriorityQueue', 'LifoQueue']
 
 class Empty(Exception):
     "Exception raised by Queue.get(block=0)/get_nowait()."
@@ -23,6 +24,7 @@
             import threading
         except ImportError:
             import dummy_threading as threading
+        self.maxsize = maxsize
         self._init(maxsize)
         # mutex must be held whenever the queue is mutating.  All methods
         # that acquire mutex must release it before returning.  mutex
@@ -88,20 +90,6 @@
         self.mutex.release()
         return n
 
-    def empty(self):
-        """Return True if the queue is empty, False otherwise (not reliable!)."""
-        self.mutex.acquire()
-        n = self._empty()
-        self.mutex.release()
-        return n
-
-    def full(self):
-        """Return True if the queue is full, False otherwise (not reliable!)."""
-        self.mutex.acquire()
-        n = self._full()
-        self.mutex.release()
-        return n
-
     def put(self, item, block=True, timeout=None):
         """Put an item into the queue.
 
@@ -115,21 +103,22 @@
         """
         self.not_full.acquire()
         try:
-            if not block:
-                if self._full():
-                    raise Full
-            elif timeout is None:
-                while self._full():
-                    self.not_full.wait()
-            else:
-                if timeout < 0:
-                    raise ValueError("'timeout' must be a positive number")
-                endtime = _time() + timeout
-                while self._full():
-                    remaining = endtime - _time()
-                    if remaining <= 0.0:
+            if self.maxsize > 0:
+                if not block:
+                    if self._qsize() == self.maxsize:
                         raise Full
-                    self.not_full.wait(remaining)
+                elif timeout is None:
+                    while self._qsize() == self.maxsize:
+                        self.not_full.wait()
+                elif timeout < 0:
+                    raise ValueError("'timeout' must be a positive number")
+                else:
+                    endtime = _time() + timeout
+                    while self._qsize() == self.maxsize:
+                        remaining = endtime - _time()
+                        if remaining <= 0.0:
+                            raise Full
+                        self.not_full.wait(remaining)
             self._put(item)
             self.unfinished_tasks += 1
             self.not_empty.notify()
@@ -158,16 +147,16 @@
         self.not_empty.acquire()
         try:
             if not block:
-                if self._empty():
+                if not self._qsize():
                     raise Empty
             elif timeout is None:
-                while self._empty():
+                while not self._qsize():
                     self.not_empty.wait()
+            elif timeout < 0:
+                raise ValueError("'timeout' must be a positive number")
             else:
-                if timeout < 0:
-                    raise ValueError("'timeout' must be a positive number")
                 endtime = _time() + timeout
-                while self._empty():
+                while not self._qsize():
                     remaining = endtime - _time()
                     if remaining <= 0.0:
                         raise Empty
@@ -192,20 +181,11 @@
 
     # Initialize the queue representation
     def _init(self, maxsize):
-        self.maxsize = maxsize
         self.queue = deque()
 
-    def _qsize(self):
+    def _qsize(self, len=len):
         return len(self.queue)
 
-    # Check whether the queue is empty
-    def _empty(self):
-        return not self.queue
-
-    # Check whether the queue is full
-    def _full(self):
-        return self.maxsize > 0 and len(self.queue) == self.maxsize
-
     # Put a new item in the queue
     def _put(self, item):
         self.queue.append(item)
@@ -213,3 +193,38 @@
     # Get an item from the queue
     def _get(self):
         return self.queue.popleft()
+
+
+class PriorityQueue(Queue):
+    '''Variant of Queue that retrieves open entries in priority order (lowest first).
+
+    Entries are typically tuples of the form:  (priority number, data).
+    '''
+
+    def _init(self, maxsize):
+        self.queue = []
+
+    def _qsize(self, len=len):
+        return len(self.queue)
+
+    def _put(self, item, heappush=heapq.heappush):
+        heappush(self.queue, item)
+
+    def _get(self, heappop=heapq.heappop):
+        return heappop(self.queue)
+
+
+class LifoQueue(Queue):
+    '''Variant of Queue that retrieves most recently added entries first.'''
+
+    def _init(self, maxsize):
+        self.queue = []
+
+    def _qsize(self, len=len):
+        return len(self.queue)
+
+    def _put(self, item):
+        self.queue.append(item)
+
+    def _get(self):
+        return self.queue.pop()

Modified: python/branches/py3k-importlib/Lib/SimpleHTTPServer.py
==============================================================================
--- python/branches/py3k-importlib/Lib/SimpleHTTPServer.py	(original)
+++ python/branches/py3k-importlib/Lib/SimpleHTTPServer.py	Thu Mar 27 00:48:05 2008
@@ -14,7 +14,6 @@
 import posixpath
 import BaseHTTPServer
 import urllib
-import urlparse
 import cgi
 import shutil
 import mimetypes
@@ -110,8 +109,9 @@
         list.sort(key=lambda a: a.lower())
         f = StringIO()
         displaypath = cgi.escape(urllib.unquote(self.path))
-        f.write("<title>Directory listing for %s</title>\n" % displaypath)
-        f.write("<h2>Directory listing for %s</h2>\n" % displaypath)
+        f.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">')
+        f.write("<html>\n<title>Directory listing for %s</title>\n" % displaypath)
+        f.write("<body>\n<h2>Directory listing for %s</h2>\n" % displaypath)
         f.write("<hr>\n<ul>\n")
         for name in list:
             fullname = os.path.join(path, name)
@@ -125,7 +125,7 @@
                 # Note: a link to a directory displays with @ and links with /
             f.write('<li><a href="%s">%s</a>\n'
                     % (urllib.quote(linkname), cgi.escape(displayname)))
-        f.write("</ul>\n<hr>\n")
+        f.write("</ul>\n<hr>\n</body>\n</html>\n")
         length = f.tell()
         f.seek(0)
         self.send_response(200)
@@ -143,7 +143,8 @@
 
         """
         # abandon query parameters
-        path = urlparse.urlparse(path)[2]
+        path = path.split('?',1)[0]
+        path = path.split('#',1)[0]
         path = posixpath.normpath(urllib.unquote(path))
         words = path.split('/')
         words = filter(None, words)

Modified: python/branches/py3k-importlib/Lib/SimpleXMLRPCServer.py
==============================================================================
--- python/branches/py3k-importlib/Lib/SimpleXMLRPCServer.py	(original)
+++ python/branches/py3k-importlib/Lib/SimpleXMLRPCServer.py	Thu Mar 27 00:48:05 2008
@@ -464,7 +464,8 @@
 
             self.end_headers()
         else:
-            # got a valid XML RPC response
+            # Got a valid XML RPC response; convert to bytes first
+            response = response.encode("utf-8")
             self.send_response(200)
             self.send_header("Content-type", "text/xml")
             self.send_header("Content-length", str(len(response)))
@@ -478,7 +479,7 @@
     def report_404 (self):
             # Report a 404 error
         self.send_response(404)
-        response = 'No such page'
+        response = b'No such page'
         self.send_header("Content-type", "text/plain")
         self.send_header("Content-length", str(len(response)))
         self.end_headers()

Modified: python/branches/py3k-importlib/Lib/SocketServer.py
==============================================================================
--- python/branches/py3k-importlib/Lib/SocketServer.py	(original)
+++ python/branches/py3k-importlib/Lib/SocketServer.py	Thu Mar 27 00:48:05 2008
@@ -130,8 +130,13 @@
 
 
 import socket
+import select
 import sys
 import os
+try:
+    import threading
+except ImportError:
+    import dummy_threading as threading
 
 __all__ = ["TCPServer","UDPServer","ForkingUDPServer","ForkingTCPServer",
            "ThreadingUDPServer","ThreadingTCPServer","BaseRequestHandler",
@@ -149,7 +154,8 @@
     Methods for the caller:
 
     - __init__(server_address, RequestHandlerClass)
-    - serve_forever()
+    - serve_forever(poll_interval=0.5)
+    - shutdown()
     - handle_request()  # if you do not use serve_forever()
     - fileno() -> int   # for select()
 
@@ -158,6 +164,7 @@
     - server_bind()
     - server_activate()
     - get_request() -> request, client_address
+    - handle_timeout()
     - verify_request(request, client_address)
     - server_close()
     - process_request(request, client_address)
@@ -171,6 +178,7 @@
     Class variables that may be overridden by derived classes or
     instances:
 
+    - timeout
     - address_family
     - socket_type
     - allow_reuse_address
@@ -182,10 +190,14 @@
 
     """
 
+    timeout = None
+
     def __init__(self, server_address, RequestHandlerClass):
         """Constructor.  May be extended, do not override."""
         self.server_address = server_address
         self.RequestHandlerClass = RequestHandlerClass
+        self.__is_shut_down = threading.Event()
+        self.__serving = False
 
     def server_activate(self):
         """Called by constructor to activate the server.
@@ -195,16 +207,40 @@
         """
         pass
 
-    def serve_forever(self):
-        """Handle one request at a time until doomsday."""
-        while 1:
-            self.handle_request()
+    def serve_forever(self, poll_interval=0.5):
+        """Handle one request at a time until shutdown.
+
+        Polls for shutdown every poll_interval seconds. Ignores
+        self.timeout. If you need to do periodic tasks, do them in
+        another thread.
+        """
+        self.__serving = True
+        self.__is_shut_down.clear()
+        while self.__serving:
+            # XXX: Consider using another file descriptor or
+            # connecting to the socket to wake this up instead of
+            # polling. Polling reduces our responsiveness to a
+            # shutdown request and wastes cpu at all other times.
+            r, w, e = select.select([self], [], [], poll_interval)
+            if r:
+                self._handle_request_noblock()
+        self.__is_shut_down.set()
+
+    def shutdown(self):
+        """Stops the serve_forever loop.
+
+        Blocks until the loop has finished. This must be called while
+        serve_forever() is running in another thread, or it will
+        deadlock.
+        """
+        self.__serving = False
+        self.__is_shut_down.wait()
 
     # The distinction between handling, getting, processing and
     # finishing a request is fairly arbitrary.  Remember:
     #
     # - handle_request() is the top-level call.  It calls
-    #   get_request(), verify_request() and process_request()
+    #   select, get_request(), verify_request() and process_request()
     # - get_request() is different for stream or datagram sockets
     # - process_request() is the place that may fork a new process
     #   or create a new thread to finish the request
@@ -212,7 +248,30 @@
     #   this constructor will handle the request all by itself
 
     def handle_request(self):
-        """Handle one request, possibly blocking."""
+        """Handle one request, possibly blocking.
+
+        Respects self.timeout.
+        """
+        # Support people who used socket.settimeout() to escape
+        # handle_request before self.timeout was available.
+        timeout = self.socket.gettimeout()
+        if timeout is None:
+            timeout = self.timeout
+        elif self.timeout is not None:
+            timeout = min(timeout, self.timeout)
+        fd_sets = select.select([self], [], [], timeout)
+        if not fd_sets[0]:
+            self.handle_timeout()
+            return
+        self._handle_request_noblock()
+
+    def _handle_request_noblock(self):
+        """Handle one request, without blocking.
+
+        I assume that select.select has returned that the socket is
+        readable before this function was called, so there should be
+        no risk of blocking in get_request().
+        """
         try:
             request, client_address = self.get_request()
         except socket.error:
@@ -224,6 +283,13 @@
                 self.handle_error(request, client_address)
                 self.close_request(request)
 
+    def handle_timeout(self):
+        """Called if no new request arrives within self.timeout.
+
+        Overridden by ForkingMixIn.
+        """
+        pass
+
     def verify_request(self, request, client_address):
         """Verify the request.  May be overridden.
 
@@ -280,7 +346,8 @@
     Methods for the caller:
 
     - __init__(server_address, RequestHandlerClass, bind_and_activate=True)
-    - serve_forever()
+    - serve_forever(poll_interval=0.5)
+    - shutdown()
     - handle_request()  # if you don't use serve_forever()
     - fileno() -> int   # for select()
 
@@ -289,6 +356,7 @@
     - server_bind()
     - server_activate()
     - get_request() -> request, client_address
+    - handle_timeout()
     - verify_request(request, client_address)
     - process_request(request, client_address)
     - close_request(request)
@@ -301,6 +369,7 @@
     Class variables that may be overridden by derived classes or
     instances:
 
+    - timeout
     - address_family
     - socket_type
     - request_queue_size (only for stream sockets)
@@ -405,25 +474,49 @@
 
     """Mix-in class to handle each request in a new process."""
 
+    timeout = 300
     active_children = None
     max_children = 40
 
     def collect_children(self):
-        """Internal routine to wait for died children."""
-        while self.active_children:
-            if len(self.active_children) < self.max_children:
-                options = os.WNOHANG
-            else:
-                # If the maximum number of children are already
-                # running, block while waiting for a child to exit
-                options = 0
+        """Internal routine to wait for children that have exited."""
+        if self.active_children is None: return
+        while len(self.active_children) >= self.max_children:
+            # XXX: This will wait for any child process, not just ones
+            # spawned by this library. This could confuse other
+            # libraries that expect to be able to wait for their own
+            # children.
             try:
-                pid, status = os.waitpid(0, options)
+                pid, status = os.waitpid(0, options=0)
             except os.error:
                 pid = None
-            if not pid: break
+            if pid not in self.active_children: continue
             self.active_children.remove(pid)
 
+        # XXX: This loop runs more system calls than it ought
+        # to. There should be a way to put the active_children into a
+        # process group and then use os.waitpid(-pgid) to wait for any
+        # of that set, but I couldn't find a way to allocate pgids
+        # that couldn't collide.
+        for child in self.active_children:
+            try:
+                pid, status = os.waitpid(child, os.WNOHANG)
+            except os.error:
+                pid = None
+            if not pid: continue
+            try:
+                self.active_children.remove(pid)
+            except ValueError as e:
+                raise ValueError('%s. x=%d and list=%r' % (e.message, pid,
+                                                           self.active_children))
+
+    def handle_timeout(self):
+        """Wait for zombies after self.timeout seconds of inactivity.
+
+        May be extended, do not override.
+        """
+        self.collect_children()
+
     def process_request(self, request, client_address):
         """Fork a new subprocess to process the request."""
         self.collect_children()
@@ -470,7 +563,6 @@
 
     def process_request(self, request, client_address):
         """Start a new thread to process the request."""
-        import threading
         t = threading.Thread(target = self.process_request_thread,
                              args = (request, client_address))
         if self.daemon_threads:

Deleted: /python/branches/py3k-importlib/Lib/UserDict.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/UserDict.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,181 +0,0 @@
-"""A more or less complete user-defined wrapper around dictionary objects."""
-
-class UserDict:
-    def __init__(self, dict=None, **kwargs):
-        self.data = {}
-        if dict is not None:
-            self.update(dict)
-        if len(kwargs):
-            self.update(kwargs)
-    def __repr__(self): return repr(self.data)
-    def __eq__(self, dict):
-        if isinstance(dict, UserDict):
-            return self.data == dict.data
-        else:
-            return self.data == dict
-    def __ne__(self, dict):
-        if isinstance(dict, UserDict):
-            return self.data != dict.data
-        else:
-            return self.data != dict
-    def __len__(self): return len(self.data)
-    def __getitem__(self, key):
-        if key in self.data:
-            return self.data[key]
-        if hasattr(self.__class__, "__missing__"):
-            return self.__class__.__missing__(self, key)
-        raise KeyError(key)
-    def __setitem__(self, key, item): self.data[key] = item
-    def __delitem__(self, key): del self.data[key]
-    def clear(self): self.data.clear()
-    def copy(self):
-        if self.__class__ is UserDict:
-            return UserDict(self.data.copy())
-        import copy
-        data = self.data
-        try:
-            self.data = {}
-            c = copy.copy(self)
-        finally:
-            self.data = data
-        c.update(self)
-        return c
-    def keys(self): return self.data.keys()
-    def items(self): return self.data.items()
-    def values(self): return self.data.values()
-    def update(self, dict=None, **kwargs):
-        if dict is None:
-            pass
-        elif isinstance(dict, UserDict):
-            self.data.update(dict.data)
-        elif isinstance(dict, type({})) or not hasattr(dict, 'items'):
-            self.data.update(dict)
-        else:
-            for k, v in dict.items():
-                self[k] = v
-        if len(kwargs):
-            self.data.update(kwargs)
-    def get(self, key, failobj=None):
-        if key not in self:
-            return failobj
-        return self[key]
-    def setdefault(self, key, failobj=None):
-        if key not in self:
-            self[key] = failobj
-        return self[key]
-    def pop(self, key, *args):
-        return self.data.pop(key, *args)
-    def popitem(self):
-        return self.data.popitem()
-    def __contains__(self, key):
-        return key in self.data
-    @classmethod
-    def fromkeys(cls, iterable, value=None):
-        d = cls()
-        for key in iterable:
-            d[key] = value
-        return d
-
-class IterableUserDict(UserDict):
-    def __iter__(self):
-        return iter(self.data)
-
-class DictMixin:
-    # Mixin defining all dictionary methods for classes that already have
-    # a minimum dictionary interface including getitem, setitem, delitem,
-    # and keys. Without knowledge of the subclass constructor, the mixin
-    # does not define __init__() or copy().  In addition to the four base
-    # methods, progressively more efficiency comes with defining
-    # __contains__(), __iter__(), and iteritems().
-
-    # XXX It would make more sense to expect __iter__ to be primitive.
-
-    # second level definitions support higher levels
-    def __iter__(self):
-        for k in self.keys():
-            yield k
-    def __contains__(self, key):
-        try:
-            value = self[key]
-        except KeyError:
-            return False
-        return True
-
-    # third level takes advantage of second level definitions
-    def iterkeys(self):
-        return self.__iter__()
-    def iteritems(self):
-        for k in self:
-            yield (k, self[k])
-
-    # fourth level uses definitions from lower levels
-    def itervalues(self):
-        for _, v in self.iteritems():
-            yield v
-    def values(self):
-        return [v for _, v in self.iteritems()]
-    def items(self):
-        return list(self.iteritems())
-    def clear(self):
-        for key in list(self.iterkeys()):
-            del self[key]
-    def setdefault(self, key, default=None):
-        try:
-            return self[key]
-        except KeyError:
-            self[key] = default
-        return default
-    def pop(self, key, *args):
-        if len(args) > 1:
-            raise TypeError("pop expected at most 2 arguments, got "
-                            + repr(1 + len(args)))
-        try:
-            value = self[key]
-        except KeyError:
-            if args:
-                return args[0]
-            raise
-        del self[key]
-        return value
-    def popitem(self):
-        try:
-            k, v = next(self.iteritems())
-        except StopIteration:
-            raise KeyError('container is empty')
-        del self[k]
-        return (k, v)
-    def update(self, other=None, **kwargs):
-        # Make progressively weaker assumptions about "other"
-        if other is None:
-            pass
-        elif hasattr(other, 'iteritems'):  # iteritems saves memory and lookups
-            for k, v in other.iteritems():
-                self[k] = v
-        elif hasattr(other, 'items'):  # items may also save memory and lookups
-            for k, v in other.items():
-                self[k] = v
-        elif hasattr(other, 'keys'):
-            for k in other.keys():
-                self[k] = other[k]
-        else:
-            for k, v in other:
-                self[k] = v
-        if kwargs:
-            self.update(kwargs)
-    def get(self, key, default=None):
-        try:
-            return self[key]
-        except KeyError:
-            return default
-    def __repr__(self):
-        return repr(dict(self.iteritems()))
-    def __eq__(self, other):
-        if isinstance(other, DictMixin):
-            other = dict(other.iteritems())
-        return dict(self.iteritems()) == other
-    def __ne__(self, other):
-        if isinstance(other, DictMixin):
-            other = dict(other.iteritems())
-        return dict(self.iteritems()) != other
-    def __len__(self):
-        return len(self.keys())

Deleted: /python/branches/py3k-importlib/Lib/UserList.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/UserList.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,71 +0,0 @@
-"""A more or less complete user-defined wrapper around list objects."""
-
-class UserList:
-    def __init__(self, initlist=None):
-        self.data = []
-        if initlist is not None:
-            # XXX should this accept an arbitrary sequence?
-            if type(initlist) == type(self.data):
-                self.data[:] = initlist
-            elif isinstance(initlist, UserList):
-                self.data[:] = initlist.data[:]
-            else:
-                self.data = list(initlist)
-    def __repr__(self): return repr(self.data)
-    def __lt__(self, other): return self.data <  self.__cast(other)
-    def __le__(self, other): return self.data <= self.__cast(other)
-    def __eq__(self, other): return self.data == self.__cast(other)
-    def __ne__(self, other): return self.data != self.__cast(other)
-    def __gt__(self, other): return self.data >  self.__cast(other)
-    def __ge__(self, other): return self.data >= self.__cast(other)
-    def __cast(self, other):
-        if isinstance(other, UserList): return other.data
-        else: return other
-    def __cmp__(self, other):
-        return cmp(self.data, self.__cast(other))
-    def __contains__(self, item): return item in self.data
-    def __len__(self): return len(self.data)
-    def __getitem__(self, i): return self.data[i]
-    def __setitem__(self, i, item): self.data[i] = item
-    def __delitem__(self, i): del self.data[i]
-    def __add__(self, other):
-        if isinstance(other, UserList):
-            return self.__class__(self.data + other.data)
-        elif isinstance(other, type(self.data)):
-            return self.__class__(self.data + other)
-        else:
-            return self.__class__(self.data + list(other))
-    def __radd__(self, other):
-        if isinstance(other, UserList):
-            return self.__class__(other.data + self.data)
-        elif isinstance(other, type(self.data)):
-            return self.__class__(other + self.data)
-        else:
-            return self.__class__(list(other) + self.data)
-    def __iadd__(self, other):
-        if isinstance(other, UserList):
-            self.data += other.data
-        elif isinstance(other, type(self.data)):
-            self.data += other
-        else:
-            self.data += list(other)
-        return self
-    def __mul__(self, n):
-        return self.__class__(self.data*n)
-    __rmul__ = __mul__
-    def __imul__(self, n):
-        self.data *= n
-        return self
-    def append(self, item): self.data.append(item)
-    def insert(self, i, item): self.data.insert(i, item)
-    def pop(self, i=-1): return self.data.pop(i)
-    def remove(self, item): self.data.remove(item)
-    def count(self, item): return self.data.count(item)
-    def index(self, item, *args): return self.data.index(item, *args)
-    def reverse(self): self.data.reverse()
-    def sort(self, *args, **kwds): self.data.sort(*args, **kwds)
-    def extend(self, other):
-        if isinstance(other, UserList):
-            self.data.extend(other.data)
-        else:
-            self.data.extend(other)

Deleted: /python/branches/py3k-importlib/Lib/UserString.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/UserString.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,241 +0,0 @@
-#!/usr/bin/env python
-## vim:ts=4:et:nowrap
-"""A user-defined wrapper around string objects
-
-Note: string objects have grown methods in Python 1.6
-This module requires Python 1.6 or later.
-"""
-import sys
-
-__all__ = ["UserString","MutableString"]
-
-class UserString:
-    def __init__(self, seq):
-        if isinstance(seq, basestring):
-            self.data = seq
-        elif isinstance(seq, UserString):
-            self.data = seq.data[:]
-        else:
-            self.data = str(seq)
-    def __str__(self): return str(self.data)
-    def __repr__(self): return repr(self.data)
-    def __int__(self): return int(self.data)
-    def __long__(self): return int(self.data)
-    def __float__(self): return float(self.data)
-    def __complex__(self): return complex(self.data)
-    def __hash__(self): return hash(self.data)
-
-    def __eq__(self, string):
-        if isinstance(string, UserString):
-            return self.data == string.data
-        else:
-            return self.data == string
-    def __ne__(self, string):
-        if isinstance(string, UserString):
-            return self.data != string.data
-        else:
-            return self.data != string
-    def __lt__(self, string):
-        if isinstance(string, UserString):
-            return self.data < string.data
-        else:
-            return self.data < string
-    def __le__(self, string):
-        if isinstance(string, UserString):
-            return self.data <= string.data
-        else:
-            return self.data <= string
-    def __gt__(self, string):
-        if isinstance(string, UserString):
-            return self.data > string.data
-        else:
-            return self.data > string
-    def __ge__(self, string):
-        if isinstance(string, UserString):
-            return self.data >= string.data
-        else:
-            return self.data >= string
-
-    def __contains__(self, char):
-        if isinstance(char, UserString):
-            char = char.data
-        return char in self.data
-
-    def __len__(self): return len(self.data)
-    def __getitem__(self, index): return self.__class__(self.data[index])
-    def __add__(self, other):
-        if isinstance(other, UserString):
-            return self.__class__(self.data + other.data)
-        elif isinstance(other, basestring):
-            return self.__class__(self.data + other)
-        else:
-            return self.__class__(self.data + str(other))
-    def __radd__(self, other):
-        if isinstance(other, basestring):
-            return self.__class__(other + self.data)
-        else:
-            return self.__class__(str(other) + self.data)
-    def __mul__(self, n):
-        return self.__class__(self.data*n)
-    __rmul__ = __mul__
-    def __mod__(self, args):
-        return self.__class__(self.data % args)
-
-    # the following methods are defined in alphabetical order:
-    def capitalize(self): return self.__class__(self.data.capitalize())
-    def center(self, width, *args):
-        return self.__class__(self.data.center(width, *args))
-    def count(self, sub, start=0, end=sys.maxint):
-        if isinstance(sub, UserString):
-            sub = sub.data
-        return self.data.count(sub, start, end)
-    def decode(self, encoding=None, errors=None): # XXX improve this?
-        if encoding:
-            if errors:
-                return self.__class__(self.data.decode(encoding, errors))
-            else:
-                return self.__class__(self.data.decode(encoding))
-        else:
-            return self.__class__(self.data.decode())
-    def encode(self, encoding=None, errors=None): # XXX improve this?
-        if encoding:
-            if errors:
-                return self.__class__(self.data.encode(encoding, errors))
-            else:
-                return self.__class__(self.data.encode(encoding))
-        else:
-            return self.__class__(self.data.encode())
-    def endswith(self, suffix, start=0, end=sys.maxint):
-        return self.data.endswith(suffix, start, end)
-    def expandtabs(self, tabsize=8):
-        return self.__class__(self.data.expandtabs(tabsize))
-    def find(self, sub, start=0, end=sys.maxint):
-        if isinstance(sub, UserString):
-            sub = sub.data
-        return self.data.find(sub, start, end)
-    def index(self, sub, start=0, end=sys.maxint):
-        return self.data.index(sub, start, end)
-    def isalpha(self): return self.data.isalpha()
-    def isalnum(self): return self.data.isalnum()
-    def isdecimal(self): return self.data.isdecimal()
-    def isdigit(self): return self.data.isdigit()
-    def islower(self): return self.data.islower()
-    def isnumeric(self): return self.data.isnumeric()
-    def isspace(self): return self.data.isspace()
-    def istitle(self): return self.data.istitle()
-    def isupper(self): return self.data.isupper()
-    def join(self, seq): return self.data.join(seq)
-    def ljust(self, width, *args):
-        return self.__class__(self.data.ljust(width, *args))
-    def lower(self): return self.__class__(self.data.lower())
-    def lstrip(self, chars=None): return self.__class__(self.data.lstrip(chars))
-    def partition(self, sep):
-        return self.data.partition(sep)
-    def replace(self, old, new, maxsplit=-1):
-        if isinstance(old, UserString):
-            old = old.data
-        if isinstance(new, UserString):
-            new = new.data
-        return self.__class__(self.data.replace(old, new, maxsplit))
-    def rfind(self, sub, start=0, end=sys.maxint):
-        return self.data.rfind(sub, start, end)
-    def rindex(self, sub, start=0, end=sys.maxint):
-        return self.data.rindex(sub, start, end)
-    def rjust(self, width, *args):
-        return self.__class__(self.data.rjust(width, *args))
-    def rpartition(self, sep):
-        return self.data.rpartition(sep)
-    def rstrip(self, chars=None): return self.__class__(self.data.rstrip(chars))
-    def split(self, sep=None, maxsplit=-1):
-        return self.data.split(sep, maxsplit)
-    def rsplit(self, sep=None, maxsplit=-1):
-        return self.data.rsplit(sep, maxsplit)
-    def splitlines(self, keepends=0): return self.data.splitlines(keepends)
-    def startswith(self, prefix, start=0, end=sys.maxint):
-        return self.data.startswith(prefix, start, end)
-    def strip(self, chars=None): return self.__class__(self.data.strip(chars))
-    def swapcase(self): return self.__class__(self.data.swapcase())
-    def title(self): return self.__class__(self.data.title())
-    def translate(self, *args):
-        return self.__class__(self.data.translate(*args))
-    def upper(self): return self.__class__(self.data.upper())
-    def zfill(self, width): return self.__class__(self.data.zfill(width))
-
-class MutableString(UserString):
-    """mutable string objects
-
-    Python strings are immutable objects.  This has the advantage, that
-    strings may be used as dictionary keys.  If this property isn't needed
-    and you insist on changing string values in place instead, you may cheat
-    and use MutableString.
-
-    But the purpose of this class is an educational one: to prevent
-    people from inventing their own mutable string class derived
-    from UserString and than forget thereby to remove (override) the
-    __hash__ method inherited from UserString.  This would lead to
-    errors that would be very hard to track down.
-
-    A faster and better solution is to rewrite your program using lists."""
-    def __init__(self, string=""):
-        self.data = string
-    def __hash__(self):
-        raise TypeError("unhashable type (it is mutable)")
-    def __setitem__(self, index, sub):
-        if isinstance(index, slice):
-            if isinstance(sub, UserString):
-                sub = sub.data
-            elif not isinstance(sub, basestring):
-                sub = str(sub)
-            start, stop, step = index.indices(len(self.data))
-            if step == -1:
-                start, stop = stop+1, start+1
-                sub = sub[::-1]
-            elif step != 1:
-                # XXX(twouters): I guess we should be reimplementing
-                # the extended slice assignment/deletion algorithm here...
-                raise TypeError("invalid step in slicing assignment")
-            start = min(start, stop)
-            self.data = self.data[:start] + sub + self.data[stop:]
-        else:
-            if index < 0:
-                index += len(self.data)
-            if index < 0 or index >= len(self.data): raise IndexError
-            self.data = self.data[:index] + sub + self.data[index+1:]
-    def __delitem__(self, index):
-        if isinstance(index, slice):
-            start, stop, step = index.indices(len(self.data))
-            if step == -1:
-                start, stop = stop+1, start+1
-            elif step != 1:
-                # XXX(twouters): see same block in __setitem__
-                raise TypeError("invalid step in slicing deletion")
-            start = min(start, stop)
-            self.data = self.data[:start] + self.data[stop:]
-        else:
-            if index < 0:
-                index += len(self.data)
-            if index < 0 or index >= len(self.data): raise IndexError
-            self.data = self.data[:index] + self.data[index+1:]
-    def immutable(self):
-        return UserString(self.data)
-    def __iadd__(self, other):
-        if isinstance(other, UserString):
-            self.data += other.data
-        elif isinstance(other, basestring):
-            self.data += other
-        else:
-            self.data += str(other)
-        return self
-    def __imul__(self, n):
-        self.data *= n
-        return self
-
-if __name__ == "__main__":
-    # execute the regression test to stdout, if called as a script:
-    import os
-    called_in_dir, called_as = os.path.split(sys.argv[0])
-    called_as, py = os.path.splitext(called_as)
-    if '-q' in sys.argv:
-        from test import test_support
-        test_support.verbose = 0
-    __import__('test.test_' + called_as.lower())

Modified: python/branches/py3k-importlib/Lib/__future__.py
==============================================================================
--- python/branches/py3k-importlib/Lib/__future__.py	(original)
+++ python/branches/py3k-importlib/Lib/__future__.py	Thu Mar 27 00:48:05 2008
@@ -53,6 +53,7 @@
     "division",
     "absolute_import",
     "with_statement",
+    "print_function",
 ]
 
 __all__ = ["all_feature_names"] + all_feature_names
@@ -66,6 +67,7 @@
 CO_FUTURE_DIVISION   = 0x2000   # division
 CO_FUTURE_ABSOLUTE_IMPORT = 0x4000 # perform absolute imports by default
 CO_FUTURE_WITH_STATEMENT  = 0x8000   # with statement
+CO_FUTURE_PRINT_FUNCTION  = 0x10000   # print function
 
 class _Feature:
     def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
@@ -114,3 +116,7 @@
 with_statement = _Feature((2, 5, 0, "alpha", 1),
                           (2, 6, 0, "alpha", 0),
                           CO_FUTURE_WITH_STATEMENT)
+
+print_function = _Feature((2, 6, 0, "alpha", 2),
+                          (3, 0, 0, "alpha", 0),
+                          CO_FUTURE_PRINT_FUNCTION)

Modified: python/branches/py3k-importlib/Lib/_abcoll.py
==============================================================================
--- python/branches/py3k-importlib/Lib/_abcoll.py	(original)
+++ python/branches/py3k-importlib/Lib/_abcoll.py	Thu Mar 27 00:48:05 2008
@@ -16,8 +16,38 @@
            "Mapping", "MutableMapping",
            "MappingView", "KeysView", "ItemsView", "ValuesView",
            "Sequence", "MutableSequence",
+           "ByteString",
+           "bytearray_iterator", "bytes_iterator", "dict_itemiterator",
+           "dict_items", "dict_keyiterator", "dict_keys", "dict_proxy",
+           "dict_valueiterator", "dict_values", "list_iterator",
+           "list_reverseiterator", "range_iterator", "set_iterator",
+           "str_iterator", "tuple_iterator", "zip_iterator",
            ]
 
+
+### collection related types which are not exposed through builtin ###
+## iterators ##
+bytes_iterator = type(iter(b''))
+bytearray_iterator = type(iter(bytearray()))
+#callable_iterator = ???
+dict_keyiterator = type(iter({}.keys()))
+dict_valueiterator = type(iter({}.values()))
+dict_itemiterator = type(iter({}.items()))
+list_iterator = type(iter([]))
+list_reverseiterator = type(iter(reversed([])))
+range_iterator = type(iter(range(0)))
+set_iterator = type(iter(set()))
+str_iterator = type(iter(""))
+tuple_iterator = type(iter(()))
+zip_iterator = type(iter(zip()))
+## views ##
+dict_keys = type({}.keys())
+dict_values = type({}.values())
+dict_items = type({}.items())
+## misc ##
+dict_proxy = type(type.__dict__)
+
+
 ### ONE-TRICK PONIES ###
 
 class Hashable(metaclass=ABCMeta):
@@ -51,10 +81,8 @@
                 return True
         return NotImplemented
 
-Iterable.register(bytes)
 
-
-class Iterator(metaclass=ABCMeta):
+class Iterator(Iterable):
 
     @abstractmethod
     def __next__(self):
@@ -70,6 +98,19 @@
                 return True
         return NotImplemented
 
+Iterator.register(bytes_iterator)
+Iterator.register(bytearray_iterator)
+#Iterator.register(callable_iterator)
+Iterator.register(dict_keyiterator)
+Iterator.register(dict_valueiterator)
+Iterator.register(dict_itemiterator)
+Iterator.register(list_iterator)
+Iterator.register(list_reverseiterator)
+Iterator.register(range_iterator)
+Iterator.register(set_iterator)
+Iterator.register(str_iterator)
+Iterator.register(tuple_iterator)
+Iterator.register(zip_iterator)
 
 class Sized(metaclass=ABCMeta):
 
@@ -102,7 +143,7 @@
 class Callable(metaclass=ABCMeta):
 
     @abstractmethod
-    def __contains__(self, x):
+    def __call__(self, *args, **kwds):
         return False
 
     @classmethod
@@ -116,7 +157,7 @@
 ### SETS ###
 
 
-class Set(metaclass=ABCMeta):
+class Set(Sized, Iterable, Container):
 
     """A set is a finite, iterable container.
 
@@ -128,19 +169,6 @@
     then the other operations will automatically follow suit.
     """
 
-    @abstractmethod
-    def __contains__(self, value):
-        return False
-
-    @abstractmethod
-    def __iter__(self):
-        while False:
-            yield None
-
-    @abstractmethod
-    def __len__(self):
-        return 0
-
     def __le__(self, other):
         if not isinstance(other, Set):
             return NotImplemented
@@ -156,24 +184,49 @@
             return NotImplemented
         return len(self) < len(other) and self.__le__(other)
 
+    def __gt__(self, other):
+        if not isinstance(other, Set):
+            return NotImplemented
+        return other < self
+
+    def __ge__(self, other):
+        if not isinstance(other, Set):
+            return NotImplemented
+        return other <= self
+
     def __eq__(self, other):
         if not isinstance(other, Set):
             return NotImplemented
         return len(self) == len(other) and self.__le__(other)
 
+    def __ne__(self, other):
+        return not (self == other)
+
     @classmethod
     def _from_iterable(cls, it):
-        return frozenset(it)
+        '''Construct an instance of the class from any iterable input.
+
+        Must override this method if the class constructor signature
+        does not accept an iterable for an input.
+        '''
+        return cls(it)
 
     def __and__(self, other):
         if not isinstance(other, Iterable):
             return NotImplemented
         return self._from_iterable(value for value in other if value in self)
 
+    def isdisjoint(self, other):
+        for value in other:
+            if value in self:
+                return False
+        return True
+
     def __or__(self, other):
         if not isinstance(other, Iterable):
             return NotImplemented
-        return self._from_iterable(itertools.chain(self, other))
+        chain = (e for s in (self, other) for e in s)
+        return self._from_iterable(chain)
 
     def __sub__(self, other):
         if not isinstance(other, Set):
@@ -205,7 +258,7 @@
         freedom for __eq__ or __hash__.  We match the algorithm used
         by the built-in frozenset type.
         """
-        MAX = sys.maxint
+        MAX = sys.maxsize
         MASK = 2 * MAX + 1
         n = len(self)
         h = 1927868237 * (n + 1)
@@ -237,6 +290,12 @@
         """Return True if it was deleted, False if not there."""
         raise NotImplementedError
 
+    def remove(self, value):
+        """Remove an element. If not a member, raise a KeyError."""
+        if value not in self:
+            raise KeyError(value)
+        self.discard(value)
+
     def pop(self):
         """Return the popped value.  Raise KeyError if empty."""
         it = iter(self)
@@ -247,16 +306,6 @@
         self.discard(value)
         return value
 
-    def toggle(self, value):
-        """Return True if it was added, False if deleted."""
-        # XXX This implementation is not thread-safe
-        if value in self:
-            self.discard(value)
-            return False
-        else:
-            self.add(value)
-            return True
-
     def clear(self):
         """This is slow (creates N new iterators!) but effective."""
         try:
@@ -277,9 +326,13 @@
         return self
 
     def __ixor__(self, it: Iterable):
-        # This calls toggle(), so if that is overridded, we call the override
+        if not isinstance(it, Set):
+            it = self._from_iterable(it)
         for value in it:
-            self.toggle(it)
+            if value in self:
+                self.discard(value)
+            else:
+                self.add(value)
         return self
 
     def __isub__(self, it: Iterable):
@@ -293,7 +346,7 @@
 ### MAPPINGS ###
 
 
-class Mapping(metaclass=ABCMeta):
+class Mapping(Sized, Iterable, Container):
 
     @abstractmethod
     def __getitem__(self, key):
@@ -313,15 +366,6 @@
         else:
             return True
 
-    @abstractmethod
-    def __len__(self):
-        return 0
-
-    @abstractmethod
-    def __iter__(self):
-        while False:
-            yield None
-
     def keys(self):
         return KeysView(self)
 
@@ -331,8 +375,15 @@
     def values(self):
         return ValuesView(self)
 
+    def __eq__(self, other):
+        return isinstance(other, Mapping) and \
+               dict(self.items()) == dict(other.items())
+
+    def __ne__(self, other):
+        return not (self == other)
+
 
-class MappingView(metaclass=ABCMeta):
+class MappingView(Sized):
 
     def __init__(self, mapping):
         self._mapping = mapping
@@ -350,7 +401,7 @@
         for key in self._mapping:
             yield key
 
-KeysView.register(type({}.keys()))
+KeysView.register(dict_keys)
 
 
 class ItemsView(MappingView, Set):
@@ -368,7 +419,7 @@
         for key in self._mapping:
             yield (key, self._mapping[key])
 
-ItemsView.register(type({}.items()))
+ItemsView.register(dict_items)
 
 
 class ValuesView(MappingView):
@@ -383,7 +434,7 @@
         for key in self._mapping:
             yield self._mapping[key]
 
-ValuesView.register(type({}.values()))
+ValuesView.register(dict_values)
 
 
 class MutableMapping(Mapping):
@@ -438,13 +489,20 @@
         for key, value in kwds.items():
             self[key] = value
 
+    def setdefault(self, key, default=None):
+        try:
+            return self[key]
+        except KeyError:
+            self[key] = default
+        return default
+
 MutableMapping.register(dict)
 
 
 ### SEQUENCES ###
 
 
-class Sequence(metaclass=ABCMeta):
+class Sequence(Sized, Iterable, Container):
 
     """All the operations on a read-only sequence.
 
@@ -456,19 +514,15 @@
     def __getitem__(self, index):
         raise IndexError
 
-    @abstractmethod
-    def __len__(self):
-        return 0
-
     def __iter__(self):
         i = 0
-        while True:
-            try:
+        try:
+            while True:
                 v = self[i]
-            except IndexError:
-                break
-            yield v
-            i += 1
+                yield v
+                i += 1
+        except IndexError:
+            return
 
     def __contains__(self, value):
         for v in self:
@@ -490,8 +544,18 @@
         return sum(1 for v in self if v == value)
 
 Sequence.register(tuple)
-Sequence.register(basestring)
-Sequence.register(memoryview)
+Sequence.register(str)
+
+
+class ByteString(Sequence):
+
+    """This unifies bytes and bytearray.
+
+    XXX Should add all their methods.
+    """
+
+ByteString.register(bytes)
+ByteString.register(bytearray)
 
 
 class MutableSequence(Sequence):
@@ -532,4 +596,4 @@
         self.extend(values)
 
 MutableSequence.register(list)
-MutableSequence.register(bytes)
+MutableSequence.register(bytearray)  # Multiply inheriting, see ByteString

Modified: python/branches/py3k-importlib/Lib/_strptime.py
==============================================================================
--- python/branches/py3k-importlib/Lib/_strptime.py	(original)
+++ python/branches/py3k-importlib/Lib/_strptime.py	Thu Mar 27 00:48:05 2008
@@ -22,7 +22,7 @@
 except:
     from dummy_thread import allocate_lock as _thread_allocate_lock
 
-__all__ = ['strptime']
+__all__ = []
 
 def _getlang():
     # Figure out what the current language is set to.
@@ -190,6 +190,7 @@
         base.__init__({
             # The " \d" part of the regex is to make %c from ANSI C work
             'd': r"(?P<d>3[0-1]|[1-2]\d|0[1-9]|[1-9]| [1-9])",
+            'f': r"(?P<f>[0-9]{1,6})",
             'H': r"(?P<H>2[0-3]|[0-1]\d|\d)",
             'I': r"(?P<I>1[0-2]|0[1-9]|[1-9])",
             'j': r"(?P<j>36[0-6]|3[0-5]\d|[1-2]\d\d|0[1-9]\d|00[1-9]|[1-9]\d|0[1-9]|[1-9])",
@@ -291,7 +292,7 @@
         return 1 + days_to_week + day_of_week
 
 
-def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
+def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
     """Return a time struct based on the input string and the format string."""
     global _TimeRE_cache, _regex_cache
     with _cache_lock:
@@ -327,7 +328,7 @@
                           data_string[found.end():])
     year = 1900
     month = day = 1
-    hour = minute = second = 0
+    hour = minute = second = fraction = 0
     tz = -1
     # Default to -1 to signify that values not known; not critical to have,
     # though
@@ -384,6 +385,11 @@
             minute = int(found_dict['M'])
         elif group_key == 'S':
             second = int(found_dict['S'])
+        elif group_key == 'f':
+            s = found_dict['f']
+            # Pad to always return microseconds.
+            s += "0" * (6 - len(s))
+            fraction = int(s)
         elif group_key == 'A':
             weekday = locale_time.f_weekday.index(found_dict['A'].lower())
         elif group_key == 'a':
@@ -440,6 +446,9 @@
         day = datetime_result.day
     if weekday == -1:
         weekday = datetime_date(year, month, day).weekday()
-    return time.struct_time((year, month, day,
-                             hour, minute, second,
-                             weekday, julian, tz))
+    return (time.struct_time((year, month, day,
+                              hour, minute, second,
+                              weekday, julian, tz)), fraction)
+
+def _strptime_time(data_string, format="%a %b %d %H:%M:%S %Y"):
+    return _strptime(data_string, format)[0]

Modified: python/branches/py3k-importlib/Lib/abc.py
==============================================================================
--- python/branches/py3k-importlib/Lib/abc.py	(original)
+++ python/branches/py3k-importlib/Lib/abc.py	Thu Mar 27 00:48:05 2008
@@ -3,6 +3,7 @@
 
 """Abstract Base Classes (ABCs) according to PEP 3119."""
 
+from _weakrefset import WeakSet
 
 def abstractmethod(funcobj):
     """A decorator indicating abstract methods.
@@ -51,50 +52,6 @@
     __isabstractmethod__ = True
 
 
-class _Abstract(object):
-
-    """Helper class inserted into the bases by ABCMeta (using _fix_bases()).
-
-    You should never need to explicitly subclass this class.
-    """
-
-    def __new__(cls, *args, **kwds):
-        am = cls.__dict__.get("__abstractmethods__")
-        if am:
-            raise TypeError("Can't instantiate abstract class %s "
-                            "with abstract methods %s" %
-                            (cls.__name__, ", ".join(sorted(am))))
-        if (args or kwds) and cls.__init__ is object.__init__:
-            raise TypeError("Can't pass arguments to __new__ "
-                            "without overriding __init__")
-        return super().__new__(cls)
-
-    @classmethod
-    def __subclasshook__(cls, subclass):
-        """Abstract classes can override this to customize issubclass().
-
-        This is invoked early on by __subclasscheck__() below.  It
-        should return True, False or NotImplemented.  If it returns
-        NotImplemented, the normal algorithm is used.  Otherwise, it
-        overrides the normal algorithm (and the outcome is cached).
-        """
-        return NotImplemented
-
-
-def _fix_bases(bases):
-    """Helper method that inserts _Abstract in the bases if needed."""
-    for base in bases:
-        if issubclass(base, _Abstract):
-            # _Abstract is already a base (maybe indirectly)
-            return bases
-    if object in bases:
-        # Replace object with _Abstract
-        return tuple([_Abstract if base is object else base
-                      for base in bases])
-    # Append _Abstract to the end
-    return bases + (_Abstract,)
-
-
 class ABCMeta(type):
 
     """Metaclass for defining Abstract Base Classes (ABCs).
@@ -117,7 +74,6 @@
     _abc_invalidation_counter = 0
 
     def __new__(mcls, name, bases, namespace):
-        bases = _fix_bases(bases)
         cls = super().__new__(mcls, name, bases, namespace)
         # Compute set of abstract method names
         abstracts = {name
@@ -128,11 +84,11 @@
                 value = getattr(cls, name, None)
                 if getattr(value, "__isabstractmethod__", False):
                     abstracts.add(name)
-        cls.__abstractmethods__ = abstracts
+        cls.__abstractmethods__ = frozenset(abstracts)
         # Set up inheritance registry
-        cls._abc_registry = set()
-        cls._abc_cache = set()
-        cls._abc_negative_cache = set()
+        cls._abc_registry = WeakSet()
+        cls._abc_cache = WeakSet()
+        cls._abc_negative_cache = WeakSet()
         cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
         return cls
 
@@ -161,8 +117,19 @@
 
     def __instancecheck__(cls, instance):
         """Override for isinstance(instance, cls)."""
-        return any(cls.__subclasscheck__(c)
-                   for c in {instance.__class__, type(instance)})
+        # Inline the cache checking
+        subclass = instance.__class__
+        if subclass in cls._abc_cache:
+            return True
+        subtype = type(instance)
+        if subtype is subclass:
+            if (cls._abc_negative_cache_version ==
+                ABCMeta._abc_invalidation_counter and
+                subclass in cls._abc_negative_cache):
+                return False
+            # Fall back to the subclass check.
+            return cls.__subclasscheck__(subclass)
+        return any(cls.__subclasscheck__(c) for c in {subclass, subtype})
 
     def __subclasscheck__(cls, subclass):
         """Override for issubclass(subclass, cls)."""
@@ -172,7 +139,7 @@
         # Check negative cache; may have to invalidate
         if cls._abc_negative_cache_version < ABCMeta._abc_invalidation_counter:
             # Invalidate the negative cache
-            cls._abc_negative_cache = set()
+            cls._abc_negative_cache = WeakSet()
             cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
         elif subclass in cls._abc_negative_cache:
             return False
@@ -186,7 +153,7 @@
                 cls._abc_negative_cache.add(subclass)
             return ok
         # Check if it's a direct subclass
-        if cls in subclass.__mro__:
+        if cls in getattr(subclass, '__mro__', ()):
             cls._abc_cache.add(subclass)
             return True
         # Check if it's a subclass of a registered class (recursive)

Modified: python/branches/py3k-importlib/Lib/aifc.py
==============================================================================
--- python/branches/py3k-importlib/Lib/aifc.py	(original)
+++ python/branches/py3k-importlib/Lib/aifc.py	Thu Mar 27 00:48:05 2008
@@ -135,7 +135,7 @@
 """
 
 import struct
-import __builtin__
+import builtins
 
 __all__ = ["Error","open","openfp"]
 
@@ -336,7 +336,7 @@
 
     def __init__(self, f):
         if type(f) == type(''):
-            f = __builtin__.open(f, 'rb')
+            f = builtins.open(f, 'rb')
         # else, assume it is an open file object already
         self.initfp(f)
 
@@ -557,7 +557,7 @@
     def __init__(self, f):
         if type(f) == type(''):
             filename = f
-            f = __builtin__.open(f, 'wb')
+            f = builtins.open(f, 'wb')
         else:
             # else, assume it is an open file object already
             filename = '???'

Modified: python/branches/py3k-importlib/Lib/asyncore.py
==============================================================================
--- python/branches/py3k-importlib/Lib/asyncore.py	(original)
+++ python/branches/py3k-importlib/Lib/asyncore.py	Thu Mar 27 00:48:05 2008
@@ -120,7 +120,7 @@
             try:
                 r, w, e = select.select(r, w, e, timeout)
             except select.error as err:
-                if err[0] != EINTR:
+                if err.args[0] != EINTR:
                     raise
                 else:
                     return
@@ -166,7 +166,7 @@
         try:
             r = pollster.poll(timeout)
         except select.error as err:
-            if err[0] != EINTR:
+            if err.args[0] != EINTR:
                 raise
             r = []
         for fd, flags in r:
@@ -321,7 +321,7 @@
             conn, addr = self.socket.accept()
             return conn, addr
         except socket.error as why:
-            if why[0] == EWOULDBLOCK:
+            if why.args[0] == EWOULDBLOCK:
                 pass
             else:
                 raise
@@ -331,7 +331,7 @@
             result = self.socket.send(data)
             return result
         except socket.error as why:
-            if why[0] == EWOULDBLOCK:
+            if why.args[0] == EWOULDBLOCK:
                 return 0
             else:
                 raise
@@ -349,7 +349,7 @@
                 return data
         except socket.error as why:
             # winsock sometimes throws ENOTCONN
-            if why[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN]:
+            if why.args[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN]:
                 self.handle_close()
                 return b''
             else:

Modified: python/branches/py3k-importlib/Lib/base64.py
==============================================================================
--- python/branches/py3k-importlib/Lib/base64.py	(original)
+++ python/branches/py3k-importlib/Lib/base64.py	Thu Mar 27 00:48:05 2008
@@ -27,10 +27,13 @@
     ]
 
 
+bytes_types = (bytes, bytearray)  # Types acceptable as binary data
+
+
 def _translate(s, altchars):
-    if not isinstance(s, bytes):
+    if not isinstance(s, bytes_types):
         raise TypeError("expected bytes, not %s" % s.__class__.__name__)
-    translation = bytes(range(256))
+    translation = bytearray(range(256))
     for k, v in altchars.items():
         translation[ord(k)] = v[0]
     return s.translate(translation)
@@ -49,12 +52,12 @@
 
     The encoded byte string is returned.
     """
-    if not isinstance(s, bytes):
+    if not isinstance(s, bytes_types):
         s = bytes(s, "ascii")
     # Strip off the trailing newline
     encoded = binascii.b2a_base64(s)[:-1]
     if altchars is not None:
-        if not isinstance(altchars, bytes):
+        if not isinstance(altchars, bytes_types):
             altchars = bytes(altchars, "ascii")
         assert len(altchars) == 2, repr(altchars)
         return _translate(encoded, {'+': altchars[0:1], '/': altchars[1:2]})
@@ -72,10 +75,10 @@
     s were incorrectly padded or if there are non-alphabet characters
     present in the string.
     """
-    if not isinstance(s, bytes):
+    if not isinstance(s, bytes_types):
         s = bytes(s)
     if altchars is not None:
-        if not isinstance(altchars, bytes):
+        if not isinstance(altchars, bytes_types):
             altchars = bytes(altchars, "ascii")
         assert len(altchars) == 2, repr(altchars)
         s = _translate(s, {chr(altchars[0]): b'+', chr(altchars[1]): b'/'})
@@ -144,7 +147,7 @@
 
     s is the byte string to encode.  The encoded byte string is returned.
     """
-    if not isinstance(s, bytes):
+    if not isinstance(s, bytes_types):
         s = bytes(s)
     quanta, leftover = divmod(len(s), 5)
     # Pad the last quantum with zero bits if necessary
@@ -201,7 +204,7 @@
     the input is incorrectly padded or if there are non-alphabet
     characters present in the input.
     """
-    if not isinstance(s, bytes):
+    if not isinstance(s, bytes_types):
         s = bytes(s)
     quanta, leftover = divmod(len(s), 8)
     if leftover:
@@ -210,12 +213,12 @@
     # False, or the character to map the digit 1 (one) to.  It should be
     # either L (el) or I (eye).
     if map01:
-        if not isinstance(map01, bytes):
+        if not isinstance(map01, bytes_types):
             map01 = bytes(map01)
         assert len(map01) == 1, repr(map01)
-        s = _translate(s, {'0': b'O', '1': map01})
+        s = _translate(s, {b'0': b'O', b'1': map01})
     if casefold:
-        s = bytes(str(s, "ascii").upper(), "ascii")
+        s = s.upper()
     # Strip off pad characters from the right.  We need to count the pad
     # characters because this will tell us how many null bytes to remove from
     # the end of the decoded string.
@@ -266,7 +269,7 @@
 
     s is the byte string to encode.  The encoded byte string is returned.
     """
-    return bytes(str(binascii.hexlify(s), "ascii").upper(), "ascii")
+    return binascii.hexlify(s).upper()
 
 
 def b16decode(s, casefold=False):
@@ -280,10 +283,10 @@
     s were incorrectly padded or if there are non-alphabet characters
     present in the string.
     """
-    if not isinstance(s, bytes):
+    if not isinstance(s, bytes_types):
         s = bytes(s)
     if casefold:
-        s = bytes(str(s, "ascii").upper(), "ascii")
+        s = s.upper()
     if re.search('[^0-9A-F]', s):
         raise binascii.Error('Non-base16 digit found')
     return binascii.unhexlify(s)
@@ -327,7 +330,7 @@
 
     Argument and return value are bytes.
     """
-    if not isinstance(s, bytes):
+    if not isinstance(s, bytes_types):
         raise TypeError("expected bytes, not %s" % s.__class__.__name__)
     pieces = []
     for i in range(0, len(s), MAXBINSIZE):
@@ -341,7 +344,7 @@
 
     Argument and return value are bytes.
     """
-    if not isinstance(s, bytes):
+    if not isinstance(s, bytes_types):
         raise TypeError("expected bytes, not %s" % s.__class__.__name__)
     return binascii.a2b_base64(s)
 

Modified: python/branches/py3k-importlib/Lib/binhex.py
==============================================================================
--- python/branches/py3k-importlib/Lib/binhex.py	(original)
+++ python/branches/py3k-importlib/Lib/binhex.py	Thu Mar 27 00:48:05 2008
@@ -169,7 +169,7 @@
 class BinHex:
     def __init__(self, name_finfo_dlen_rlen, ofp):
         name, finfo, dlen, rlen = name_finfo_dlen_rlen
-        if isinstance(ofp, basestring):
+        if isinstance(ofp, str):
             ofname = ofp
             ofp = io.open(ofname, 'wb')
             if os.name == 'mac':
@@ -371,7 +371,7 @@
 
 class HexBin:
     def __init__(self, ifp):
-        if isinstance(ifp, basestring):
+        if isinstance(ifp, str):
             ifp = io.open(ifp, 'rb')
         #
         # Find initial colon.

Modified: python/branches/py3k-importlib/Lib/bsddb/__init__.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/__init__.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/__init__.py	Thu Mar 27 00:48:05 2008
@@ -64,10 +64,10 @@
 
 #----------------------------------------------------------------------
 
-import sys, os, UserDict
+import sys, os, collections
 from weakref import ref
 
-class _iter_mixin(UserDict.DictMixin):
+class _iter_mixin(collections.MutableMapping):
     def _make_iter_cursor(self):
         cur = _DeadlockWrap(self.db.cursor)
         key = id(cur)
@@ -170,6 +170,9 @@
     def __del__(self):
         self.close()
 
+    def __repr__(self):
+        return repr(dict(self.iteritems()))
+
     def _checkCursor(self):
         if self.dbc is None:
             self.dbc = _DeadlockWrap(self.db.cursor)
@@ -289,7 +292,7 @@
     def _cursor_refs(self):
         return self.db._cursor_refs
 
-class StringKeys(UserDict.DictMixin, _ExposedProperties):
+class StringKeys(collections.MutableMapping, _ExposedProperties):
     """Wrapper around DB object that automatically encodes
     all keys as UTF-8; the keys must be strings."""
 
@@ -357,7 +360,7 @@
     def sync(self):
         return self.db.sync()
 
-class StringValues(UserDict.DictMixin, _ExposedProperties):
+class StringValues(collections.MutableMapping, _ExposedProperties):
     """Wrapper around DB object that automatically encodes
     and decodes all values as UTF-8; input values must be strings."""
 

Modified: python/branches/py3k-importlib/Lib/bsddb/dbobj.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/dbobj.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/dbobj.py	Thu Mar 27 00:48:05 2008
@@ -24,10 +24,9 @@
 from . import db
 
 try:
-    from UserDict import DictMixin
+    from collections import MutableMapping
 except ImportError:
-    # DictMixin is new in Python 2.3
-    class DictMixin: pass
+    class MutableMapping: pass
 
 class DBEnv:
     def __init__(self, *args, **kwargs):
@@ -113,7 +112,7 @@
             return self._cobj.lsn_reset(*args, **kwargs)
 
 
-class DB(DictMixin):
+class DB(MutableMapping):
     def __init__(self, dbenv, *args, **kwargs):
         # give it the proper DBEnv C object that its expecting
         self._cobj = db.DB(dbenv._cobj, *args, **kwargs)
@@ -127,6 +126,8 @@
         self._cobj[key] = value
     def __delitem__(self, arg):
         del self._cobj[arg]
+    def __iter__(self):
+        return iter(self.keys())
 
     def append(self, *args, **kwargs):
         return self._cobj.append(*args, **kwargs)

Modified: python/branches/py3k-importlib/Lib/bsddb/dbshelve.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/dbshelve.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/dbshelve.py	Thu Mar 27 00:48:05 2008
@@ -30,11 +30,20 @@
 #------------------------------------------------------------------------
 
 import pickle
-try:
-    from UserDict import DictMixin
-except ImportError:
-    # DictMixin is new in Python 2.3
-    class DictMixin: pass
+import sys
+
+#At version 2.3 cPickle switched to using protocol instead of bin
+if sys.version_info[:3] >= (2, 3, 0):
+    HIGHEST_PROTOCOL = pickle.HIGHEST_PROTOCOL
+    def _dumps(object, protocol):
+        return pickle.dumps(object, protocol=protocol)
+    from collections import MutableMapping
+else:
+    HIGHEST_PROTOCOL = None
+    def _dumps(object, protocol):
+        return pickle.dumps(object, bin=protocol)
+    class MutableMapping: pass
+
 from . import db
 
 _unspecified = object()
@@ -80,14 +89,17 @@
 class DBShelveError(db.DBError): pass
 
 
-class DBShelf(DictMixin):
+class DBShelf(MutableMapping):
     """A shelf to hold pickled objects, built upon a bsddb DB object.  It
     automatically pickles/unpickles data objects going to/from the DB.
     """
     def __init__(self, dbenv=None):
         self.db = db.DB(dbenv)
         self._closed = True
-        self.binary = 1
+        if HIGHEST_PROTOCOL:
+            self.protocol = HIGHEST_PROTOCOL
+        else:
+            self.protocol = 1
 
 
     def __del__(self):
@@ -114,7 +126,7 @@
 
 
     def __setitem__(self, key, value):
-        data = pickle.dumps(value, self.binary)
+        data = _dumps(value, self.protocol)
         self.db[key] = data
 
 
@@ -128,6 +140,8 @@
         else:
             return self.db.keys()
 
+    def __iter__(self):
+        return iter(self.keys())
 
     def open(self, *args, **kwargs):
         self.db.open(*args, **kwargs)
@@ -169,7 +183,7 @@
     # Other methods
 
     def __append(self, value, txn=None):
-        data = pickle.dumps(value, self.binary)
+        data = _dumps(value, self.protocol)
         return self.db.append(data, txn)
 
     def append(self, value, txn=None):
@@ -200,19 +214,19 @@
         return pickle.loads(data)
 
     def get_both(self, key, value, txn=None, flags=0):
-        data = pickle.dumps(value, self.binary)
+        data = _dumps(value, self.protocol)
         data = self.db.get(key, data, txn, flags)
         return pickle.loads(data)
 
 
     def cursor(self, txn=None, flags=0):
         c = DBShelfCursor(self.db.cursor(txn, flags))
-        c.binary = self.binary
+        c.protocol = self.protocol
         return c
 
 
     def put(self, key, value, txn=None, flags=0):
-        data = pickle.dumps(value, self.binary)
+        data = _dumps(value, self.protocol)
         return self.db.put(key, data, txn, flags)
 
 
@@ -252,11 +266,13 @@
     #----------------------------------------------
 
     def dup(self, flags=0):
-        return DBShelfCursor(self.dbc.dup(flags))
+        c = DBShelfCursor(self.dbc.dup(flags))
+        c.protocol = self.protocol
+        return c
 
 
     def put(self, key, value, flags=0):
-        data = pickle.dumps(value, self.binary)
+        data = _dumps(value, self.protocol)
         return self.dbc.put(key, data, flags)
 
 
@@ -274,7 +290,7 @@
         return self._extract(rec)
 
     def get_3(self, key, value, flags):
-        data = pickle.dumps(value, self.binary)
+        data = _dumps(value, self.protocol)
         rec = self.dbc.get(key, flags)
         return self._extract(rec)
 
@@ -291,7 +307,7 @@
 
 
     def get_both(self, key, value, flags=0):
-        data = pickle.dumps(value, self.binary)
+        data = _dumps(value, self.protocol)
         rec = self.dbc.get_both(key, flags)
         return self._extract(rec)
 

Modified: python/branches/py3k-importlib/Lib/bsddb/dbtables.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/dbtables.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/dbtables.py	Thu Mar 27 00:48:05 2008
@@ -20,7 +20,7 @@
 import re
 import sys
 import copy
-import xdrlib
+import struct
 import random
 import pickle
 
@@ -88,6 +88,15 @@
     def __call__(self, s):
         return self.re.match(s.decode(self.encoding))
 
+def CmpToKey(mycmp):
+    'Convert a cmp= function into a key= function'
+    class K(object):
+        def __init__(self, obj, *args):
+            self.obj = obj
+        def __lt__(self, other):
+            return mycmp(self.obj, other.obj) == -1
+    return K
+
 #
 # keys used to store database metadata
 #
@@ -255,7 +264,7 @@
                                                  flags=DB_RMW))
             tablelist.append(table)
             # delete 1st, in case we opened with DB_DUP
-            self.db.delete(_E(_table_names_key), txn)
+            self.db.delete(_E(_table_names_key), txn=txn)
             self.db.put(_E(_table_names_key), pickle.dumps(tablelist, 1), txn=txn)
 
             txn.commit()
@@ -330,7 +339,7 @@
                 # store the table's new extended column list
                 if newcolumnlist != oldcolumnlist :
                     # delete the old one first since we opened with DB_DUP
-                    self.db.delete(columnlist_key, txn)
+                    self.db.delete(columnlist_key, txn=txn)
                     self.db.put(columnlist_key,
                                 pickle.dumps(newcolumnlist, 1),
                                 txn=txn)
@@ -362,12 +371,12 @@
         unique = 0
         while not unique:
             # Generate a random 64-bit row ID string
-            # (note: this code has <64 bits of randomness
+            # (note: might have <64 bits of true randomness
             # but it's plenty for our database id needs!)
-            p = xdrlib.Packer()
-            p.pack_int(int(random.random()*2147483647))
-            p.pack_int(int(random.random()*2147483647))
-            newid = p.get_buffer()
+            blist = []
+            for x in range(_rowid_str_len):
+                blist.append(random.randint(0,255))
+            newid = bytes(blist)
 
             # Guarantee uniqueness by adding this key to the database
             try:
@@ -451,10 +460,10 @@
                         try:
                             dataitem = self.db.get(
                                 _data_key(table, column, rowid),
-                                txn)
+                                txn=txn)
                             self.db.delete(
                                 _data_key(table, column, rowid),
-                                txn)
+                                txn=txn)
                         except DBNotFoundError:
                              # XXXXXXX row key somehow didn't exist, assume no
                              # error
@@ -497,13 +506,13 @@
                         try:
                             self.db.delete(_data_key(table, column,
                                                      rowid.encode("latin-1")),
-                                           txn)
+                                           txn=txn)
                         except DBNotFoundError:
                             # XXXXXXX column may not exist, assume no error
                             pass
 
                     try:
-                        self.db.delete(_rowid_key(table, rowid.encode("latin-1")), txn)
+                        self.db.delete(_rowid_key(table, rowid.encode("latin-1")), txn=txn)
                     except DBNotFoundError:
                         # XXXXXXX row key somehow didn't exist, assume no error
                         pass
@@ -587,7 +596,7 @@
             return 0
 
         conditionlist = list(conditions.items())
-        conditionlist.sort(cmp_conditions)
+        conditionlist.sort(key=CmpToKey(cmp_conditions))
 
         # Apply conditions to column data to find what we want
         cur = self.db.cursor()
@@ -659,7 +668,7 @@
             txn = self.env.txn_begin()
 
             # delete the column list
-            self.db.delete(_columns_key(table), txn)
+            self.db.delete(_columns_key(table), txn=txn)
 
             cur = self.db.cursor(txn)
 
@@ -698,7 +707,7 @@
                 # hmm, it wasn't there, oh well, that's what we want.
                 pass
             # delete 1st, incase we opened with DB_DUP
-            self.db.delete(_E(_table_names_key), txn)
+            self.db.delete(_E(_table_names_key), txn=txn)
             self.db.put(_E(_table_names_key), pickle.dumps(tablelist, 1), txn=txn)
 
             txn.commit()

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_1413192.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_1413192.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_1413192.py	Thu Mar 27 00:48:05 2008
@@ -5,6 +5,9 @@
 
 import shutil
 import tempfile
+from test.test_support import catch_warning
+import warnings
+
 try:
     # For Pythons w/distutils and add-on pybsddb
     from bsddb3 import db
@@ -32,8 +35,11 @@
         del self.the_txn
 
 
-context = Context()
-del context
+with catch_warning():
+    warnings.filterwarnings('ignore', 'DBTxn aborted in destructor')
+    context = Context()
+    del context
+
 
 # try not to leave a turd
 try:

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_associate.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_associate.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_associate.py	Thu Mar 27 00:48:05 2008
@@ -24,6 +24,11 @@
     # For Python 2.3
     from bsddb import db, dbshelve
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
+
 
 #----------------------------------------------------------------------
 
@@ -92,15 +97,22 @@
 class AssociateErrorTestCase(unittest.TestCase):
     def setUp(self):
         self.filename = self.__class__.__name__ + '.db'
-        self.homeDir = tempfile.mkdtemp()
+        homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        self.homeDir = homeDir
+        try:
+            os.mkdir(homeDir)
+        except os.error:
+            import glob
+            files = glob.glob(os.path.join(self.homeDir, '*'))
+            for file in files:
+                os.remove(file)
         self.env = db.DBEnv()
         self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
 
     def tearDown(self):
         self.env.close()
         self.env = None
-        shutil.rmtree(self.homeDir)
-
+        test_support.rmtree(self.homeDir)
 
     def test00_associateDBError(self):
         if verbose:
@@ -141,7 +153,15 @@
 
     def setUp(self):
         self.filename = self.__class__.__name__ + '.db'
-        self.homeDir = tempfile.mkdtemp()
+        homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        self.homeDir = homeDir
+        try:
+            os.mkdir(homeDir)
+        except os.error:
+            import glob
+            files = glob.glob(os.path.join(self.homeDir, '*'))
+            for file in files:
+                os.remove(file)
         self.env = db.DBEnv()
         self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL |
                                db.DB_INIT_LOCK | db.DB_THREAD | self.envFlags)

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_basics.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_basics.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_basics.py	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,6 @@
 import os
 import sys
 import errno
-import shutil
 import string
 import tempfile
 from pprint import pprint
@@ -21,6 +20,10 @@
     from bsddb import db
 
 from bsddb.test.test_all import verbose
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
 
 DASH = b'-'
 letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -54,7 +57,10 @@
 
     def setUp(self):
         if self.useEnv:
-            self.homeDir = tempfile.mkdtemp()
+            homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+            self.homeDir = homeDir
+            test_support.rmtree(homeDir)
+            os.mkdir(homeDir)
             try:
                 self.env = db.DBEnv()
                 self.env.set_lg_max(1024*1024)
@@ -68,7 +74,7 @@
                 tempfile.tempdir = old_tempfile_tempdir
             # Yes, a bare except is intended, since we're re-raising the exc.
             except:
-                shutil.rmtree(self.homeDir)
+                test_support.rmtree(homeDir)
                 raise
         else:
             self.env = None
@@ -93,7 +99,8 @@
         self.d.close()
         if self.env is not None:
             self.env.close()
-            shutil.rmtree(self.homeDir)
+            test_support.rmtree(self.homeDir)
+            ## XXX(nnorwitz): is this comment stil valid?
             ## Make a new DBEnv to remove the env files from the home dir.
             ## (It can't be done while the env is open, nor after it has been
             ## closed, so we make a new one to do it.)

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_compare.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_compare.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_compare.py	Thu Mar 27 00:48:05 2008
@@ -6,6 +6,7 @@
 import sys, os, re
 from io import StringIO
 import tempfile
+from . import test_all
 
 import unittest
 try:
@@ -15,6 +16,11 @@
     # For Python 2.3
     from bsddb import db, dbshelve
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
+
 lexical_cmp = cmp
 
 def lowercase_cmp(left, right):
@@ -31,10 +37,20 @@
 _expected_lowercase_test_data = [s.encode('ascii') for s in
         ('', 'a', 'aaa', 'b', 'c', 'CC', 'cccce', 'ccccf', 'CCCP')]
 
+
+def CmpToKey(mycmp):
+    'Convert a cmp= function into a key= function'
+    class K(object):
+        def __init__(self, obj, *args):
+            self.obj = obj
+        def __lt__(self, other):
+            return mycmp(self.obj, other.obj) == -1
+    return K
+
 class ComparatorTests (unittest.TestCase):
     def comparator_test_helper (self, comparator, expected_data):
         data = expected_data[:]
-        data.sort (comparator)
+        data.sort (key=CmpToKey(comparator))
         self.failUnless (data == expected_data,
                          "comparator `%s' is not right: %s vs. %s"
                          % (comparator, expected_data, data))
@@ -55,7 +71,12 @@
 
     def setUp (self):
         self.filename = self.__class__.__name__ + '.db'
-        self.homeDir = tempfile.mkdtemp()
+        homeDir = os.path.join (tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        self.homeDir = homeDir
+        try:
+            os.mkdir (homeDir)
+        except os.error:
+            pass
 
         env = db.DBEnv ()
         env.open (self.homeDir,
@@ -68,7 +89,7 @@
         if self.env is not None:
             self.env.close ()
             self.env = None
-        shutil.rmtree(self.homeDir)
+        test_support.rmtree(self.homeDir)
 
     def addDataToDB (self, data):
         i = 0

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_cursor_pget_bug.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_cursor_pget_bug.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_cursor_pget_bug.py	Thu Mar 27 00:48:05 2008
@@ -1,10 +1,16 @@
 import unittest
+import tempfile
 import sys, os, glob
 import shutil
 import tempfile
 
 from bsddb import db
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
+
 
 #----------------------------------------------------------------------
 
@@ -13,7 +19,11 @@
     db_name = 'test-cursor_pget.db'
 
     def setUp(self):
-        self.homeDir = tempfile.mkdtemp()
+        self.homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        try:
+            os.mkdir(self.homeDir)
+        except os.error:
+            pass
         self.env = db.DBEnv()
         self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
         self.primary_db = db.DB(self.env)
@@ -34,7 +44,7 @@
         del self.secondary_db
         del self.primary_db
         del self.env
-        shutil.rmtree(self.homeDir)
+        test_support.rmtree(self.homeDir)
 
     def test_pget(self):
         cursor = self.secondary_db.cursor()

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_dbobj.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_dbobj.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_dbobj.py	Thu Mar 27 00:48:05 2008
@@ -2,7 +2,6 @@
 import shutil
 import sys, os
 import unittest
-import glob
 import tempfile
 
 try:
@@ -12,6 +11,11 @@
     # For Python 2.3
     from bsddb import db, dbobj
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
+
 
 #----------------------------------------------------------------------
 
@@ -20,14 +24,17 @@
     db_name = 'test-dbobj.db'
 
     def setUp(self):
-        self.homeDir = tempfile.mkdtemp()
+        homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        self.homeDir = homeDir
+        try: os.mkdir(homeDir)
+        except os.error: pass
 
     def tearDown(self):
         if hasattr(self, 'db'):
             del self.db
         if hasattr(self, 'env'):
             del self.env
-        shutil.rmtree(self.homeDir)
+        test_support.rmtree(self.homeDir)
 
     def test01_both(self):
         class TestDBEnv(dbobj.DBEnv): pass

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_dbshelve.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_dbshelve.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_dbshelve.py	Thu Mar 27 00:48:05 2008
@@ -9,6 +9,11 @@
 
 from bsddb import db, dbshelve
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
+
 from bsddb.test.test_all import verbose
 
 
@@ -45,10 +50,7 @@
 
     def tearDown(self):
         self.do_close()
-        try:
-            os.remove(self.filename)
-        except os.error:
-            pass
+        test_support.unlink(self.filename)
 
     def mk(self, key):
         """Turn key into an appropriate key type for this db"""
@@ -262,6 +264,10 @@
         self.do_open()
 
     def do_open(self):
+        self.homeDir = homeDir = os.path.join(
+            tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        try: os.mkdir(homeDir)
+        except os.error: pass
         self.env = db.DBEnv()
         self.env.open(self.homeDir, self.envflags | db.DB_INIT_MPOOL | db.DB_CREATE)
 
@@ -276,8 +282,7 @@
 
     def tearDown(self):
         self.do_close()
-        shutil.rmtree(self.homeDir)
-
+        test_support.rmtree(self.homeDir)
 
 
 class EnvBTreeShelveTestCase(BasicEnvShelveTestCase):

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_dbtables.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_dbtables.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_dbtables.py	Thu Mar 27 00:48:05 2008
@@ -20,7 +20,6 @@
 #
 # $Id$
 
-import shutil
 import sys, os, re
 import pickle
 import tempfile
@@ -35,6 +34,10 @@
     # For Python 2.3
     from bsddb import db, dbtables
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
 
 
 #----------------------------------------------------------------------
@@ -43,13 +46,17 @@
     db_name = 'test-table.db'
 
     def setUp(self):
-        self.homeDir = tempfile.mkdtemp()
+        homeDir = tempfile.mkdtemp()
+        self.testHomeDir = homeDir
+        try: os.mkdir(homeDir)
+        except os.error: pass
+
         self.tdb = dbtables.bsdTableDB(
-            filename='tabletest.db', dbhome=self.homeDir, create=1)
+            filename='tabletest.db', dbhome=homeDir, create=1)
 
     def tearDown(self):
         self.tdb.close()
-        shutil.rmtree(self.homeDir)
+        test_support.rmtree(self.testHomeDir)
 
     def test01(self):
         tabname = "test01"

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_env_close.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_env_close.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_env_close.py	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,6 @@
 import shutil
 import sys
 import tempfile
-import glob
 import unittest
 
 try:
@@ -16,6 +15,11 @@
     # For Python 2.3
     from bsddb import db
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
+
 from bsddb.test.test_all import verbose
 
 # We're going to get warnings in this module about trying to close the db when
@@ -34,15 +38,15 @@
 
 class DBEnvClosedEarlyCrash(unittest.TestCase):
     def setUp(self):
-        self.homeDir = tempfile.mkdtemp()
-        old_tempfile_tempdir = tempfile.tempdir
+        self.homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        try: os.mkdir(self.homeDir)
+        except os.error: pass
         tempfile.tempdir = self.homeDir
         self.filename = os.path.split(tempfile.mktemp())[1]
-        tempfile.tempdir = old_tempfile_tempdir
+        tempfile.tempdir = None
 
     def tearDown(self):
-        shutil.rmtree(self.homeDir)
-
+        test_support.rmtree(self.homeDir)
 
     def test01_close_dbenv_before_db(self):
         dbenv = db.DBEnv()

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_join.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_join.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_join.py	Thu Mar 27 00:48:05 2008
@@ -18,6 +18,10 @@
 
 from bsddb import db, dbshelve, StringKeys
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
 
 #----------------------------------------------------------------------
 
@@ -48,13 +52,16 @@
 
     def setUp(self):
         self.filename = self.__class__.__name__ + '.db'
-        self.homeDir = tempfile.mkdtemp()
+        homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        self.homeDir = homeDir
+        try: os.mkdir(homeDir)
+        except os.error: pass
         self.env = db.DBEnv()
         self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL | db.DB_INIT_LOCK )
 
     def tearDown(self):
         self.env.close()
-        shutil.rmtree(self.homeDir)
+        test_support.rmtree(self.homeDir)
 
     def test01_join(self):
         if verbose:

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_lock.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_lock.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_lock.py	Thu Mar 27 00:48:05 2008
@@ -2,11 +2,9 @@
 TestCases for testing the locking sub-system.
 """
 
-import shutil
-import sys, os
+import sys
 import tempfile
 import time
-from pprint import pprint
 
 try:
     from threading import Thread, currentThread
@@ -25,21 +23,26 @@
     # For Python 2.3
     from bsddb import db
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
+
 
 #----------------------------------------------------------------------
 
 class LockingTestCase(unittest.TestCase):
 
     def setUp(self):
-        self.homeDir = tempfile.mkdtemp()
+        self.homeDir = tempfile.mkdtemp('.test_lock')
         self.env = db.DBEnv()
         self.env.open(self.homeDir, db.DB_THREAD | db.DB_INIT_MPOOL |
-                      db.DB_INIT_LOCK | db.DB_CREATE)
+                                    db.DB_INIT_LOCK | db.DB_CREATE)
 
 
     def tearDown(self):
         self.env.close()
-        shutil.rmtree(self.homeDir)
+        test_support.rmtree(self.homeDir)
 
 
     def test01_simple(self):
@@ -57,8 +60,8 @@
         self.env.lock_put(lock)
         if verbose:
             print("Released lock: %s" % lock)
-
-
+        if db.version() >= (4,0):
+            self.env.lock_id_free(anID)
 
 
     def test02_threaded(self):
@@ -119,6 +122,8 @@
         self.env.lock_put(lock)
         if verbose:
             print("%s: Released %s lock: %s" % (name, lt, lock))
+        if db.version() >= (4,0):
+            self.env.lock_id_free(anID)
 
 
 #----------------------------------------------------------------------

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_misc.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_misc.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_misc.py	Thu Mar 27 00:48:05 2008
@@ -11,27 +11,34 @@
     # For Pythons w/distutils pybsddb
     from bsddb3 import db, dbshelve, hashopen
 except ImportError:
-    # For Python 2.3
+    # For the bundled bsddb
     from bsddb import db, dbshelve, hashopen
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
+
 #----------------------------------------------------------------------
 
 class MiscTestCase(unittest.TestCase):
     def setUp(self):
         self.filename = self.__class__.__name__ + '.db'
-        self.homeDir = tempfile.mkdtemp()
-
-    def tearDown(self):
+        homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        self.homeDir = homeDir
         try:
-            os.remove(self.filename)
+            os.mkdir(homeDir)
         except OSError:
             pass
-        shutil.rmtree(self.homeDir)
+
+    def tearDown(self):
+        test_support.unlink(self.filename)
+        test_support.rmtree(self.homeDir)
 
     def test01_badpointer(self):
         dbs = dbshelve.open(self.filename)
         dbs.close()
-        self.assertRaises(db.DBError, dbs.get, "foo")
+        self.assertRaises(db.DBError, dbs.get, b"foo")
 
     def test02_db_home(self):
         env = db.DBEnv()
@@ -46,6 +53,73 @@
         rp = repr(db)
         self.assertEquals(rp, "{}")
 
+    # http://sourceforge.net/tracker/index.php?func=detail&aid=1708868&group_id=13900&atid=313900
+    #
+    # See the bug report for details.
+    #
+    # The problem was that make_key_dbt() was not allocating a copy of
+    # string keys but FREE_DBT() was always being told to free it when the
+    # database was opened with DB_THREAD.
+    def test04_double_free_make_key_dbt(self):
+        try:
+            db1 = db.DB()
+            db1.open(self.filename, None, db.DB_BTREE,
+                     db.DB_CREATE | db.DB_THREAD)
+
+            curs = db1.cursor()
+            t = curs.get(b"/foo", db.DB_SET)
+            # double free happened during exit from DBC_get
+        finally:
+            db1.close()
+            os.unlink(self.filename)
+
+    def test05_key_with_null_bytes(self):
+        try:
+            db1 = db.DB()
+            db1.open(self.filename, None, db.DB_HASH, db.DB_CREATE)
+            db1[b'a'] = b'eh?'
+            db1[b'a\x00'] = b'eh zed.'
+            db1[b'a\x00a'] = b'eh zed eh?'
+            db1[b'aaa'] = b'eh eh eh!'
+            keys = db1.keys()
+            keys.sort()
+            self.assertEqual([b'a', b'a\x00', b'a\x00a', b'aaa'], keys)
+            self.assertEqual(db1[b'a'], b'eh?')
+            self.assertEqual(db1[b'a\x00'], b'eh zed.')
+            self.assertEqual(db1[b'a\x00a'], b'eh zed eh?')
+            self.assertEqual(db1[b'aaa'], b'eh eh eh!')
+        finally:
+            db1.close()
+            os.unlink(self.filename)
+
+    def test_DB_set_flags_persists(self):
+        if db.version() < (4,2):
+            # The get_flags API required for this to work is only available
+            # in BerkeleyDB >= 4.2
+            return
+        try:
+            db1 = db.DB()
+            db1.set_flags(db.DB_DUPSORT)
+            db1.open(self.filename, db.DB_HASH, db.DB_CREATE)
+            db1[b'a'] = b'eh'
+            db1[b'a'] = b'A'
+            self.assertEqual([(b'a', b'A')], db1.items())
+            db1.put(b'a', b'Aa')
+            self.assertEqual([(b'a', b'A'), (b'a', b'Aa')], db1.items())
+            db1.close()
+            db1 = db.DB()
+            # no set_flags call, we're testing that it reads and obeys
+            # the flags on open.
+            db1.open(self.filename, db.DB_HASH)
+            self.assertEqual([(b'a', b'A'), (b'a', b'Aa')], db1.items())
+            # if it read the flags right this will replace all values
+            # for key b'a' instead of adding a new one.  (as a dict should)
+            db1[b'a'] = b'new A'
+            self.assertEqual([(b'a', b'new A')], db1.items())
+        finally:
+            db1.close()
+            os.unlink(self.filename)
+
 
 #----------------------------------------------------------------------
 

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_pickle.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_pickle.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_pickle.py	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,7 @@
 import pickle
 import tempfile
 import unittest
-import glob
+import tempfile
 
 try:
     # For Pythons w/distutils pybsddb
@@ -13,6 +13,11 @@
     # For Python 2.3
     from bsddb import db
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
+
 
 #----------------------------------------------------------------------
 
@@ -21,14 +26,17 @@
     db_name = 'test-dbobj.db'
 
     def setUp(self):
-        self.homeDir = tempfile.mkdtemp()
+        homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        self.homeDir = homeDir
+        try: os.mkdir(homeDir)
+        except os.error: pass
 
     def tearDown(self):
         if hasattr(self, 'db'):
             del self.db
         if hasattr(self, 'env'):
             del self.env
-        shutil.rmtree(self.homeDir)
+        test_support.rmtree(self.homeDir)
 
     def _base_test_pickle_DBError(self, pickle):
         self.env = db.DBEnv()

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_recno.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_recno.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_recno.py	Thu Mar 27 00:48:05 2008
@@ -18,6 +18,11 @@
     # For Python 2.3
     from bsddb import db
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
+
 letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
 
 
@@ -26,14 +31,12 @@
 class SimpleRecnoTestCase(unittest.TestCase):
     def setUp(self):
         self.filename = tempfile.mktemp()
-        self.homeDir = tempfile.mkdtemp()
+        self.homeDir = None
 
     def tearDown(self):
-        try:
-            os.remove(self.filename)
-        except OSError as e:
-            if e.errno != errno.EEXIST: raise
-        shutil.rmtree(self.homeDir)
+        test_support.unlink(self.filename)
+        if self.homeDir:
+            test_support.rmtree(self.homeDir)
 
     def test01_basic(self):
         d = db.DB()
@@ -206,7 +209,11 @@
         just a line in the file, but you can set a different record delimiter
         if needed.
         """
-        source = os.path.join(self.homeDir, 'test_recno.txt')
+        homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        self.homeDir = homeDir
+        source = os.path.join(homeDir, 'test_recno.txt')
+        if not os.path.isdir(homeDir):
+            os.mkdir(homeDir)
         f = open(source, 'w') # create the file
         f.close()
 

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_sequence.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_sequence.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_sequence.py	Thu Mar 27 00:48:05 2008
@@ -3,7 +3,6 @@
 import shutil
 import sys
 import tempfile
-import glob
 
 try:
     # For Pythons w/distutils pybsddb
@@ -12,16 +11,23 @@
     from bsddb import db
 
 from bsddb.test.test_all import verbose
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
 
 
 class DBSequenceTest(unittest.TestCase):
     def setUp(self):
         self.int_32_max = 0x100000000
-        self.homeDir = tempfile.mkdtemp()
-        old_tempfile_tempdir = tempfile.tempdir
+        self.homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        try:
+            os.mkdir(self.homeDir)
+        except os.error:
+            pass
         tempfile.tempdir = self.homeDir
         self.filename = os.path.split(tempfile.mktemp())[1]
-        tempfile.tempdir = old_tempfile_tempdir
+        tempfile.tempdir = None
 
         self.dbenv = db.DBEnv()
         self.dbenv.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL, 0o666)
@@ -39,7 +45,7 @@
             self.dbenv.close()
             del self.dbenv
 
-        shutil.rmtree(self.homeDir)
+        test_support.rmtree(self.homeDir)
 
     def test_get(self):
         self.seq = db.DBSequence(self.d, flags=0)

Modified: python/branches/py3k-importlib/Lib/bsddb/test/test_thread.py
==============================================================================
--- python/branches/py3k-importlib/Lib/bsddb/test/test_thread.py	(original)
+++ python/branches/py3k-importlib/Lib/bsddb/test/test_thread.py	Thu Mar 27 00:48:05 2008
@@ -5,7 +5,6 @@
 import sys
 import time
 import errno
-import shutil
 import tempfile
 from pprint import pprint
 from random import random
@@ -34,6 +33,11 @@
     # For Python 2.3
     from bsddb import db, dbutils
 
+try:
+    from bsddb3 import test_support
+except ImportError:
+    from test import test_support
+
 
 #----------------------------------------------------------------------
 
@@ -47,7 +51,12 @@
         if verbose:
             dbutils._deadlock_VerboseFile = sys.stdout
 
-        self.homeDir = tempfile.mkdtemp()
+        homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
+        self.homeDir = homeDir
+        try:
+            os.mkdir(homeDir)
+        except OSError as e:
+            if e.errno != errno.EEXIST: raise
         self.env = db.DBEnv()
         self.setEnvOpts()
         self.env.open(self.homeDir, self.envflags | db.DB_CREATE)
@@ -61,7 +70,7 @@
     def tearDown(self):
         self.d.close()
         self.env.close()
-        shutil.rmtree(self.homeDir)
+        test_support.rmtree(self.homeDir)
 
     def setEnvOpts(self):
         pass

Modified: python/branches/py3k-importlib/Lib/cProfile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/cProfile.py	(original)
+++ python/branches/py3k-importlib/Lib/cProfile.py	Thu Mar 27 00:48:05 2008
@@ -153,7 +153,7 @@
 # ____________________________________________________________
 
 def label(code):
-    if isinstance(code, basestring):
+    if isinstance(code, str):
         return ('~', 0, code)    # built-in functions ('~' sorts at the end)
     else:
         return (code.co_filename, code.co_firstlineno, code.co_name)

Modified: python/branches/py3k-importlib/Lib/calendar.py
==============================================================================
--- python/branches/py3k-importlib/Lib/calendar.py	(original)
+++ python/branches/py3k-importlib/Lib/calendar.py	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,9 @@
 set the first day of the week (0=Monday, 6=Sunday)."""
 
 from __future__ import with_statement
-import sys, datetime, locale
+import sys
+import datetime
+import locale as _locale
 
 __all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
            "firstweekday", "isleap", "leapdays", "weekday", "monthrange",
@@ -177,8 +179,8 @@
 
     def itermonthdays(self, year, month):
         """
-        Like itermonthdates(), but will yield day numbers tuples. For days
-        outside the specified month the day number is 0.
+        Like itermonthdates(), but will yield day numbers. For days outside
+        the specified month the day number is 0.
         """
         for date in self.itermonthdates(year, month):
             if date.month != month:
@@ -261,7 +263,7 @@
         """
         Print a single week (no newline).
         """
-        print(self.week(theweek, width), end=' ')
+        print(self.formatweek(theweek, width), end=' ')
 
     def formatday(self, day, weekday, width):
         """
@@ -485,11 +487,11 @@
         self.locale = locale
 
     def __enter__(self):
-        self.oldlocale = locale.setlocale(locale.LC_TIME, self.locale)
-        return locale.getlocale(locale.LC_TIME)[1]
+        self.oldlocale = _locale.setlocale(_locale.LC_TIME, self.locale)
+        return _locale.getlocale(_locale.LC_TIME)[1]
 
     def __exit__(self, *args):
-        locale.setlocale(locale.LC_TIME, self.oldlocale)
+        _locale.setlocale(_locale.LC_TIME, self.oldlocale)
 
 
 class LocaleTextCalendar(TextCalendar):
@@ -503,7 +505,7 @@
     def __init__(self, firstweekday=0, locale=None):
         TextCalendar.__init__(self, firstweekday)
         if locale is None:
-            locale = locale.getdefaultlocale()
+            locale = _locale.getdefaultlocale()
         self.locale = locale
 
     def formatweekday(self, day, width):
@@ -537,7 +539,7 @@
     def __init__(self, firstweekday=0, locale=None):
         HTMLCalendar.__init__(self, firstweekday)
         if locale is None:
-            locale = locale.getdefaultlocale()
+            locale = _locale.getdefaultlocale()
         self.locale = locale
 
     def formatweekday(self, day):
@@ -658,9 +660,11 @@
         parser.error("if --locale is specified --encoding is required")
         sys.exit(1)
 
+    locale = options.locale, options.encoding
+
     if options.type == "html":
         if options.locale:
-            cal = LocaleHTMLCalendar(locale=options.locale)
+            cal = LocaleHTMLCalendar(locale=locale)
         else:
             cal = HTMLCalendar()
         encoding = options.encoding
@@ -676,7 +680,7 @@
             sys.exit(1)
     else:
         if options.locale:
-            cal = LocaleTextCalendar(locale=options.locale)
+            cal = LocaleTextCalendar(locale=locale)
         else:
             cal = TextCalendar()
         optdict = dict(w=options.width, l=options.lines)

Modified: python/branches/py3k-importlib/Lib/cgi.py
==============================================================================
--- python/branches/py3k-importlib/Lib/cgi.py	(original)
+++ python/branches/py3k-importlib/Lib/cgi.py	Thu Mar 27 00:48:05 2008
@@ -40,7 +40,7 @@
 import urllib
 import mimetools
 import rfc822
-import UserDict
+import collections
 from io import StringIO
 
 __all__ = ["MiniFieldStorage", "FieldStorage", "FormContentDict",
@@ -781,7 +781,7 @@
 # Backwards Compatibility Classes
 # ===============================
 
-class FormContentDict(UserDict.UserDict):
+class FormContentDict(collections.Mapping):
     """Form content as dictionary with a list of values per field.
 
     form = FormContentDict()
@@ -800,6 +800,15 @@
                                       strict_parsing=strict_parsing)
         self.query_string = environ['QUERY_STRING']
 
+    def __len__(self):
+        return len(self.dict)
+
+    def __iter__(self):
+        return iter(self.dict)
+
+    def __getitem__(self, key):
+        return self.dict[key]
+
 
 class SvFormContentDict(FormContentDict):
     """Form content as dictionary expecting a single value per field.

Modified: python/branches/py3k-importlib/Lib/cmd.py
==============================================================================
--- python/branches/py3k-importlib/Lib/cmd.py	(original)
+++ python/branches/py3k-importlib/Lib/cmd.py	Thu Mar 27 00:48:05 2008
@@ -356,7 +356,7 @@
             return
 
         nonstrings = [i for i in range(len(list))
-                        if not isinstance(list[i], basestring)]
+                        if not isinstance(list[i], str)]
         if nonstrings:
             raise TypeError("list[i] not a string for i in %s"
                             % ", ".join(map(str, nonstrings)))

Modified: python/branches/py3k-importlib/Lib/code.py
==============================================================================
--- python/branches/py3k-importlib/Lib/code.py	(original)
+++ python/branches/py3k-importlib/Lib/code.py	Thu Mar 27 00:48:05 2008
@@ -253,13 +253,12 @@
         The returned line does not include the trailing newline.
         When the user enters the EOF key sequence, EOFError is raised.
 
-        The base implementation uses sys.stdin.readline(); a subclass
-        may replace this with a different implementation.
+        The base implementation uses the built-in function
+        input(); a subclass may replace this with a different
+        implementation.
 
         """
-        sys.stdout.write(prompt)
-        sys.stdout.flush()
-        return sys.stdin.readline()
+        return input(prompt)
 
 
 

Modified: python/branches/py3k-importlib/Lib/codecs.py
==============================================================================
--- python/branches/py3k-importlib/Lib/codecs.py	(original)
+++ python/branches/py3k-importlib/Lib/codecs.py	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,7 @@
 
 """#"
 
-import __builtin__, sys
+import builtins, sys
 
 ### Registry and builtin stateless codec functions
 
@@ -237,7 +237,7 @@
     """
     def __init__(self, errors='strict'):
         """
-        Creates a IncrementalDecoder instance.
+        Create a IncrementalDecoder instance.
 
         The IncrementalDecoder may use different error handling schemes by
         providing the errors keyword argument. See the module docstring
@@ -247,26 +247,35 @@
 
     def decode(self, input, final=False):
         """
-        Decodes input and returns the resulting object.
+        Decode input and returns the resulting object.
         """
         raise NotImplementedError
 
     def reset(self):
         """
-        Resets the decoder to the initial state.
+        Reset the decoder to the initial state.
         """
 
     def getstate(self):
         """
-        Return the current state of the decoder. This must be a
-        (buffered_input, additional_state_info) tuple.
+        Return the current state of the decoder.
+
+        This must be a (buffered_input, additional_state_info) tuple.
+        buffered_input must be a bytes object containing bytes that
+        were passed to decode() that have not yet been converted.
+        additional_state_info must be a non-negative integer
+        representing the state of the decoder WITHOUT yet having
+        processed the contents of buffered_input.  In the initial state
+        and after reset(), getstate() must return (b"", 0).
         """
         return (b"", 0)
 
     def setstate(self, state):
         """
-        Set the current state of the decoder. state must have been
-        returned by getstate().
+        Set the current state of the decoder.
+
+        state must have been returned by getstate().  The effect of
+        setstate((b"", 0)) must be equivalent to reset().
         """
 
 class BufferedIncrementalDecoder(IncrementalDecoder):
@@ -858,7 +867,7 @@
        'b' not in mode:
         # Force opening of the file in binary mode
         mode = mode + 'b'
-    file = __builtin__.open(filename, mode, buffering)
+    file = builtins.open(filename, mode, buffering)
     if encoding is None:
         return file
     info = lookup(encoding)

Modified: python/branches/py3k-importlib/Lib/collections.py
==============================================================================
--- python/branches/py3k-importlib/Lib/collections.py	(original)
+++ python/branches/py3k-importlib/Lib/collections.py	Thu Mar 27 00:48:05 2008
@@ -1,78 +1,420 @@
-__all__ = ['deque', 'defaultdict', 'NamedTuple']
-
-from _collections import deque, defaultdict
-from operator import itemgetter as _itemgetter
-import sys as _sys
-
+__all__ = ['deque', 'defaultdict', 'namedtuple', 'UserDict']
 # For bootstrapping reasons, the collection ABCs are defined in _abcoll.py.
 # They should however be considered an integral part of collections.py.
 from _abcoll import *
 import _abcoll
 __all__ += _abcoll.__all__
 
+from _collections import deque, defaultdict
+from operator import itemgetter as _itemgetter
+from keyword import iskeyword as _iskeyword
+import sys as _sys
+
+################################################################################
+### namedtuple
+################################################################################
 
-def NamedTuple(typename, s, verbose=False):
+def namedtuple(typename, field_names, verbose=False):
     """Returns a new subclass of tuple with named fields.
 
-    >>> Point = NamedTuple('Point', 'x y')
+    >>> Point = namedtuple('Point', 'x y')
     >>> Point.__doc__                   # docstring for the new class
     'Point(x, y)'
     >>> p = Point(11, y=22)             # instantiate with positional args or keywords
-    >>> p[0] + p[1]                     # works just like the tuple (11, 22)
+    >>> p[0] + p[1]                     # indexable like a plain tuple
     33
-    >>> x, y = p                        # unpacks just like a tuple
+    >>> x, y = p                        # unpack like a regular tuple
     >>> x, y
     (11, 22)
     >>> p.x + p.y                       # fields also accessable by name
     33
-    >>> p                               # readable __repr__ with name=value style
-    Point(x=11, y=22)
-    >>> p.__replace__('x', 100)         # __replace__() is like str.replace() but targets a named field
-    Point(x=100, y=22)
-    >>> d = dict(zip(p.__fields__, p))  # use __fields__ to make a dictionary
+    >>> d = p._asdict()                 # convert to a dictionary
     >>> d['x']
     11
+    >>> Point(**d)                      # convert from a dictionary
+    Point(x=11, y=22)
+    >>> p._replace(x=100)               # _replace() is like str.replace() but targets named fields
+    Point(x=100, y=22)
 
     """
 
-    field_names = tuple(s.replace(',', ' ').split())    # names separated by spaces and/or commas
-    if not ''.join((typename,) + field_names).replace('_', '').isalnum():
-        raise ValueError('Type names and field names can only contain alphanumeric characters and underscores')
+    # Parse and validate the field names.  Validation serves two purposes,
+    # generating informative error messages and preventing template injection attacks.
+    if isinstance(field_names, str):
+        field_names = field_names.replace(',', ' ').split() # names separated by whitespace and/or commas
+    field_names = tuple(field_names)
+    for name in (typename,) + field_names:
+        if not all(c.isalnum() or c=='_' for c in name):
+            raise ValueError('Type names and field names can only contain alphanumeric characters and underscores: %r' % name)
+        if _iskeyword(name):
+            raise ValueError('Type names and field names cannot be a keyword: %r' % name)
+        if name[0].isdigit():
+            raise ValueError('Type names and field names cannot start with a number: %r' % name)
+    seen_names = set()
+    for name in field_names:
+        if name.startswith('_'):
+            raise ValueError('Field names cannot start with an underscore: %r' % name)
+        if name in seen_names:
+            raise ValueError('Encountered duplicate field name: %r' % name)
+        seen_names.add(name)
+
+    # Create and fill-in the class template
+    numfields = len(field_names)
     argtxt = repr(field_names).replace("'", "")[1:-1]   # tuple repr without parens or quotes
     reprtxt = ', '.join('%s=%%r' % name for name in field_names)
+    dicttxt = ', '.join('%r: t[%d]' % (name, pos) for pos, name in enumerate(field_names))
     template = '''class %(typename)s(tuple):
-        '%(typename)s(%(argtxt)s)'
-        __slots__ = ()
-        __fields__ = %(field_names)r
+        '%(typename)s(%(argtxt)s)' \n
+        __slots__ = () \n
+        _fields = %(field_names)r \n
         def __new__(cls, %(argtxt)s):
-            return tuple.__new__(cls, (%(argtxt)s))
+            return tuple.__new__(cls, (%(argtxt)s)) \n
+        @classmethod
+        def _make(cls, iterable, new=tuple.__new__, len=len):
+            'Make a new %(typename)s object from a sequence or iterable'
+            result = new(cls, iterable)
+            if len(result) != %(numfields)d:
+                raise TypeError('Expected %(numfields)d arguments, got %%d' %% len(result))
+            return result \n
         def __repr__(self):
-            return '%(typename)s(%(reprtxt)s)' %% self
-        def __replace__(self, field, value):
-            'Return a new %(typename)s object replacing one field with a new value'
-            return %(typename)s(**dict(list(zip(%(field_names)r, self)) + [(field, value)]))  \n''' % locals()
+            return '%(typename)s(%(reprtxt)s)' %% self \n
+        def _asdict(t):
+            'Return a new dict which maps field names to their values'
+            return {%(dicttxt)s} \n
+        def _replace(self, **kwds):
+            'Return a new %(typename)s object replacing specified fields with new values'
+            result = self._make(map(kwds.pop, %(field_names)r, self))
+            if kwds:
+                raise ValueError('Got unexpected field names: %%r' %% kwds.keys())
+            return result \n\n''' % locals()
     for i, name in enumerate(field_names):
         template += '        %s = property(itemgetter(%d))\n' % (name, i)
     if verbose:
         print(template)
-    m = dict(itemgetter=_itemgetter)
-    exec(template, m)
-    result = m[typename]
+
+    # Execute the template string in a temporary namespace
+    namespace = dict(itemgetter=_itemgetter)
+    try:
+        exec(template, namespace)
+    except SyntaxError as e:
+        raise SyntaxError(e.msg + ':\n' + template) from e
+    result = namespace[typename]
+
+    # For pickling to work, the __module__ variable needs to be set to the frame
+    # where the named tuple is created.  Bypass this step in enviroments where
+    # sys._getframe is not defined (Jython for example).
     if hasattr(_sys, '_getframe'):
         result.__module__ = _sys._getframe(1).f_globals['__name__']
-    return result
 
+    return result
 
 
 
+################################################################################
+### UserDict
+################################################################################
+
+class UserDict(MutableMapping):
+
+    # Start by filling-out the abstract methods
+    def __init__(self, dict=None, **kwargs):
+        self.data = {}
+        if dict is not None:
+            self.update(dict)
+        if len(kwargs):
+            self.update(kwargs)
+    def __len__(self): return len(self.data)
+    def __getitem__(self, key):
+        if key in self.data:
+            return self.data[key]
+        if hasattr(self.__class__, "__missing__"):
+            return self.__class__.__missing__(self, key)
+        raise KeyError(key)
+    def __setitem__(self, key, item): self.data[key] = item
+    def __delitem__(self, key): del self.data[key]
+    def __iter__(self):
+        return iter(self.data)
+
+    # Modify __contains__ to work correctly when __missing__ is present
+    def __contains__(self, key):
+        return key in self.data
+
+    # Now, add the methods in dicts but not in MutableMapping
+    def __repr__(self): return repr(self.data)
+    def copy(self):
+        if self.__class__ is UserDict:
+            return UserDict(self.data.copy())
+        import copy
+        data = self.data
+        try:
+            self.data = {}
+            c = copy.copy(self)
+        finally:
+            self.data = data
+        c.update(self)
+        return c
+    @classmethod
+    def fromkeys(cls, iterable, value=None):
+        d = cls()
+        for key in iterable:
+            d[key] = value
+        return d
+
+
+
+################################################################################
+### UserList
+################################################################################
+
+class UserList(MutableSequence):
+    """A more or less complete user-defined wrapper around list objects."""
+    def __init__(self, initlist=None):
+        self.data = []
+        if initlist is not None:
+            # XXX should this accept an arbitrary sequence?
+            if type(initlist) == type(self.data):
+                self.data[:] = initlist
+            elif isinstance(initlist, UserList):
+                self.data[:] = initlist.data[:]
+            else:
+                self.data = list(initlist)
+    def __repr__(self): return repr(self.data)
+    def __lt__(self, other): return self.data <  self.__cast(other)
+    def __le__(self, other): return self.data <= self.__cast(other)
+    def __eq__(self, other): return self.data == self.__cast(other)
+    def __ne__(self, other): return self.data != self.__cast(other)
+    def __gt__(self, other): return self.data >  self.__cast(other)
+    def __ge__(self, other): return self.data >= self.__cast(other)
+    def __cast(self, other):
+        return other.data if isinstance(other, UserList) else other
+    def __cmp__(self, other):
+        return cmp(self.data, self.__cast(other))
+    def __contains__(self, item): return item in self.data
+    def __len__(self): return len(self.data)
+    def __getitem__(self, i): return self.data[i]
+    def __setitem__(self, i, item): self.data[i] = item
+    def __delitem__(self, i): del self.data[i]
+    def __add__(self, other):
+        if isinstance(other, UserList):
+            return self.__class__(self.data + other.data)
+        elif isinstance(other, type(self.data)):
+            return self.__class__(self.data + other)
+        return self.__class__(self.data + list(other))
+    def __radd__(self, other):
+        if isinstance(other, UserList):
+            return self.__class__(other.data + self.data)
+        elif isinstance(other, type(self.data)):
+            return self.__class__(other + self.data)
+        return self.__class__(list(other) + self.data)
+    def __iadd__(self, other):
+        if isinstance(other, UserList):
+            self.data += other.data
+        elif isinstance(other, type(self.data)):
+            self.data += other
+        else:
+            self.data += list(other)
+        return self
+    def __mul__(self, n):
+        return self.__class__(self.data*n)
+    __rmul__ = __mul__
+    def __imul__(self, n):
+        self.data *= n
+        return self
+    def append(self, item): self.data.append(item)
+    def insert(self, i, item): self.data.insert(i, item)
+    def pop(self, i=-1): return self.data.pop(i)
+    def remove(self, item): self.data.remove(item)
+    def count(self, item): return self.data.count(item)
+    def index(self, item, *args): return self.data.index(item, *args)
+    def reverse(self): self.data.reverse()
+    def sort(self, *args, **kwds): self.data.sort(*args, **kwds)
+    def extend(self, other):
+        if isinstance(other, UserList):
+            self.data.extend(other.data)
+        else:
+            self.data.extend(other)
+
+
+
+################################################################################
+### UserString
+################################################################################
+
+class UserString(Sequence):
+    def __init__(self, seq):
+        if isinstance(seq, str):
+            self.data = seq
+        elif isinstance(seq, UserString):
+            self.data = seq.data[:]
+        else:
+            self.data = str(seq)
+    def __str__(self): return str(self.data)
+    def __repr__(self): return repr(self.data)
+    def __int__(self): return int(self.data)
+    def __long__(self): return int(self.data)
+    def __float__(self): return float(self.data)
+    def __complex__(self): return complex(self.data)
+    def __hash__(self): return hash(self.data)
+
+    def __eq__(self, string):
+        if isinstance(string, UserString):
+            return self.data == string.data
+        return self.data == string
+    def __ne__(self, string):
+        if isinstance(string, UserString):
+            return self.data != string.data
+        return self.data != string
+    def __lt__(self, string):
+        if isinstance(string, UserString):
+            return self.data < string.data
+        return self.data < string
+    def __le__(self, string):
+        if isinstance(string, UserString):
+            return self.data <= string.data
+        return self.data <= string
+    def __gt__(self, string):
+        if isinstance(string, UserString):
+            return self.data > string.data
+        return self.data > string
+    def __ge__(self, string):
+        if isinstance(string, UserString):
+            return self.data >= string.data
+        return self.data >= string
+
+    def __contains__(self, char):
+        if isinstance(char, UserString):
+            char = char.data
+        return char in self.data
+
+    def __len__(self): return len(self.data)
+    def __getitem__(self, index): return self.__class__(self.data[index])
+    def __add__(self, other):
+        if isinstance(other, UserString):
+            return self.__class__(self.data + other.data)
+        elif isinstance(other, str):
+            return self.__class__(self.data + other)
+        return self.__class__(self.data + str(other))
+    def __radd__(self, other):
+        if isinstance(other, str):
+            return self.__class__(other + self.data)
+        return self.__class__(str(other) + self.data)
+    def __mul__(self, n):
+        return self.__class__(self.data*n)
+    __rmul__ = __mul__
+    def __mod__(self, args):
+        return self.__class__(self.data % args)
+
+    # the following methods are defined in alphabetical order:
+    def capitalize(self): return self.__class__(self.data.capitalize())
+    def center(self, width, *args):
+        return self.__class__(self.data.center(width, *args))
+    def count(self, sub, start=0, end=_sys.maxsize):
+        if isinstance(sub, UserString):
+            sub = sub.data
+        return self.data.count(sub, start, end)
+    def encode(self, encoding=None, errors=None): # XXX improve this?
+        if encoding:
+            if errors:
+                return self.__class__(self.data.encode(encoding, errors))
+            return self.__class__(self.data.encode(encoding))
+        return self.__class__(self.data.encode())
+    def endswith(self, suffix, start=0, end=_sys.maxsize):
+        return self.data.endswith(suffix, start, end)
+    def expandtabs(self, tabsize=8):
+        return self.__class__(self.data.expandtabs(tabsize))
+    def find(self, sub, start=0, end=_sys.maxsize):
+        if isinstance(sub, UserString):
+            sub = sub.data
+        return self.data.find(sub, start, end)
+    def format(self, *args, **kwds):
+        return self.data.format(*args, **kwds)
+    def index(self, sub, start=0, end=_sys.maxsize):
+        return self.data.index(sub, start, end)
+    def isalpha(self): return self.data.isalpha()
+    def isalnum(self): return self.data.isalnum()
+    def isdecimal(self): return self.data.isdecimal()
+    def isdigit(self): return self.data.isdigit()
+    def isidentifier(self): return self.data.isidentifier()
+    def islower(self): return self.data.islower()
+    def isnumeric(self): return self.data.isnumeric()
+    def isspace(self): return self.data.isspace()
+    def istitle(self): return self.data.istitle()
+    def isupper(self): return self.data.isupper()
+    def join(self, seq): return self.data.join(seq)
+    def ljust(self, width, *args):
+        return self.__class__(self.data.ljust(width, *args))
+    def lower(self): return self.__class__(self.data.lower())
+    def lstrip(self, chars=None): return self.__class__(self.data.lstrip(chars))
+    def partition(self, sep):
+        return self.data.partition(sep)
+    def replace(self, old, new, maxsplit=-1):
+        if isinstance(old, UserString):
+            old = old.data
+        if isinstance(new, UserString):
+            new = new.data
+        return self.__class__(self.data.replace(old, new, maxsplit))
+    def rfind(self, sub, start=0, end=_sys.maxsize):
+        return self.data.rfind(sub, start, end)
+    def rindex(self, sub, start=0, end=_sys.maxsize):
+        return self.data.rindex(sub, start, end)
+    def rjust(self, width, *args):
+        return self.__class__(self.data.rjust(width, *args))
+    def rpartition(self, sep):
+        return self.data.rpartition(sep)
+    def rstrip(self, chars=None):
+        return self.__class__(self.data.rstrip(chars))
+    def split(self, sep=None, maxsplit=-1):
+        return self.data.split(sep, maxsplit)
+    def rsplit(self, sep=None, maxsplit=-1):
+        return self.data.rsplit(sep, maxsplit)
+    def splitlines(self, keepends=0): return self.data.splitlines(keepends)
+    def startswith(self, prefix, start=0, end=_sys.maxsize):
+        return self.data.startswith(prefix, start, end)
+    def strip(self, chars=None): return self.__class__(self.data.strip(chars))
+    def swapcase(self): return self.__class__(self.data.swapcase())
+    def title(self): return self.__class__(self.data.title())
+    def translate(self, *args):
+        return self.__class__(self.data.translate(*args))
+    def upper(self): return self.__class__(self.data.upper())
+    def zfill(self, width): return self.__class__(self.data.zfill(width))
+
+
+
+################################################################################
+### Simple tests
+################################################################################
 
 if __name__ == '__main__':
     # verify that instances can be pickled
     from pickle import loads, dumps
-    Point = NamedTuple('Point', 'x, y', True)
+    Point = namedtuple('Point', 'x, y', True)
     p = Point(x=10, y=20)
     assert p == loads(dumps(p))
 
+    # test and demonstrate ability to override methods
+    class Point(namedtuple('Point', 'x y')):
+        __slots__ = ()
+        @property
+        def hypot(self):
+            return (self.x ** 2 + self.y ** 2) ** 0.5
+        def __str__(self):
+            return 'Point: x=%6.3f  y=%6.3f  hypot=%6.3f' % (self.x, self.y, self.hypot)
+
+    for p in Point(3, 4), Point(14, 5/7.):
+        print (p)
+
+    class Point(namedtuple('Point', 'x y')):
+        'Point class with optimized _make() and _replace() without error-checking'
+        __slots__ = ()
+        _make = classmethod(tuple.__new__)
+        def _replace(self, _map=map, **kwds):
+            return self._make(_map(kwds.get, ('x', 'y'), self))
+
+    print(Point(11, 22)._replace(x=100))
+
+    Point3D = namedtuple('Point3D', Point._fields + ('z',))
+    print(Point3D.__doc__)
+
     import doctest
-    TestResults = NamedTuple('TestResults', 'failed attempted')
+    TestResults = namedtuple('TestResults', 'failed attempted')
     print(TestResults(*doctest.testmod()))

Modified: python/branches/py3k-importlib/Lib/compileall.py
==============================================================================
--- python/branches/py3k-importlib/Lib/compileall.py	(original)
+++ python/branches/py3k-importlib/Lib/compileall.py	Thu Mar 27 00:48:05 2008
@@ -125,7 +125,7 @@
         print("-d destdir: purported directory name for error messages")
         print("   if no directory arguments, -l sys.path is assumed")
         print("-x regexp: skip files matching the regular expression regexp")
-        print("   the regexp is search for in the full path of the file")
+        print("   the regexp is searched for in the full path of the file")
         sys.exit(2)
     maxlevels = 10
     ddir = None

Modified: python/branches/py3k-importlib/Lib/contextlib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/contextlib.py	(original)
+++ python/branches/py3k-importlib/Lib/contextlib.py	Thu Mar 27 00:48:05 2008
@@ -25,6 +25,10 @@
             else:
                 raise RuntimeError("generator didn't stop")
         else:
+            if value is None:
+                # Need to force instantiation so we can reliably
+                # tell if we get the same exception back
+                value = type()
             try:
                 self.gen.throw(type, value, traceback)
                 raise RuntimeError("generator didn't stop after throw()")

Modified: python/branches/py3k-importlib/Lib/cookielib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/cookielib.py	(original)
+++ python/branches/py3k-importlib/Lib/cookielib.py	Thu Mar 27 00:48:05 2008
@@ -367,7 +367,7 @@
     [[('Basic', None), ('realm', '"foobar"')]]
 
     """
-    assert not isinstance(header_values, basestring)
+    assert not isinstance(header_values, str)
     result = []
     for text in header_values:
         orig_text = text
@@ -1255,8 +1255,7 @@
 
         """
         # add cookies in order of most specific (ie. longest) path first
-        def decreasing_size(a, b): return cmp(len(b.path), len(a.path))
-        cookies.sort(decreasing_size)
+        cookies.sort(key=lambda a: len(a.path), reverse=True)
 
         version_set = False
 

Modified: python/branches/py3k-importlib/Lib/copy.py
==============================================================================
--- python/branches/py3k-importlib/Lib/copy.py	(original)
+++ python/branches/py3k-importlib/Lib/copy.py	Thu Mar 27 00:48:05 2008
@@ -187,7 +187,7 @@
     d[complex] = _deepcopy_atomic
 except NameError:
     pass
-d[str8] = _deepcopy_atomic
+d[bytes] = _deepcopy_atomic
 d[str] = _deepcopy_atomic
 try:
     d[types.CodeType] = _deepcopy_atomic

Modified: python/branches/py3k-importlib/Lib/copy_reg.py
==============================================================================
--- python/branches/py3k-importlib/Lib/copy_reg.py	(original)
+++ python/branches/py3k-importlib/Lib/copy_reg.py	Thu Mar 27 00:48:05 2008
@@ -114,7 +114,7 @@
             if "__slots__" in c.__dict__:
                 slots = c.__dict__['__slots__']
                 # if class has a single slot, it can be given as a string
-                if isinstance(slots, basestring):
+                if isinstance(slots, str):
                     slots = (slots,)
                 for name in slots:
                     # special descriptors

Modified: python/branches/py3k-importlib/Lib/csv.py
==============================================================================
--- python/branches/py3k-importlib/Lib/csv.py	(original)
+++ python/branches/py3k-importlib/Lib/csv.py	Thu Mar 27 00:48:05 2008
@@ -72,6 +72,8 @@
         self.restkey = restkey          # key to catch long rows
         self.restval = restval          # default value for short rows
         self.reader = reader(f, dialect, *args, **kwds)
+        self.dialect = dialect
+        self.line_num = 0
 
     def __iter__(self):
         return self
@@ -81,6 +83,7 @@
         if self.fieldnames is None:
             self.fieldnames = row
             row = next(self.reader)
+        self.line_num = self.reader.line_num
 
         # unlike the basic reader, we prefer not to return blanks,
         # because we will typically wind up with a dict full of None

Modified: python/branches/py3k-importlib/Lib/ctypes/__init__.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/__init__.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/__init__.py	Thu Mar 27 00:48:05 2008
@@ -21,19 +21,12 @@
 
 DEFAULT_MODE = RTLD_LOCAL
 if _os.name == "posix" and _sys.platform == "darwin":
-    import gestalt
-
-    # gestalt.gestalt("sysv") returns the version number of the
-    # currently active system file as BCD.
-    # On OS X 10.4.6 -> 0x1046
-    # On OS X 10.2.8 -> 0x1028
-    # See also http://www.rgaros.nl/gestalt/
-    #
     # On OS X 10.3, we use RTLD_GLOBAL as default mode
     # because RTLD_LOCAL does not work at least on some
-    # libraries.
+    # libraries.  OS X 10.3 is Darwin 7, so we check for
+    # that.
 
-    if gestalt.gestalt("sysv") < 0x1040:
+    if int(_os.uname()[2].split('.')[0]) < 8:
         DEFAULT_MODE = RTLD_GLOBAL
 
 from _ctypes import FUNCFLAG_CDECL as _FUNCFLAG_CDECL, \
@@ -52,11 +45,11 @@
 """
 
 def create_string_buffer(init, size=None):
-    """create_string_buffer(aString) -> character array
+    """create_string_buffer(aBytes) -> character array
     create_string_buffer(anInteger) -> character array
     create_string_buffer(aString, anInteger) -> character array
     """
-    if isinstance(init, str):
+    if isinstance(init, (str, bytes)):
         if size is None:
             size = len(init)+1
         buftype = c_char * size
@@ -189,7 +182,7 @@
 _check_size(c_double)
 
 class c_longdouble(_SimpleCData):
-    _type_ = "D"
+    _type_ = "g"
 if sizeof(c_longdouble) == sizeof(c_double):
     c_longdouble = c_double
 
@@ -244,7 +237,7 @@
 _check_size(c_void_p)
 
 class c_bool(_SimpleCData):
-    _type_ = "t"
+    _type_ = "?"
 
 # This cache maps types to pointers to them.
 _pointer_type_cache = {}
@@ -355,8 +348,8 @@
     def __repr__(self):
         return "<%s '%s', handle %x at %x>" % \
                (self.__class__.__name__, self._name,
-                (self._handle & (_sys.maxint*2 + 1)),
-                id(self) & (_sys.maxint*2 + 1))
+                (self._handle & (_sys.maxsize*2 + 1)),
+                id(self) & (_sys.maxsize*2 + 1))
 
     def __getattr__(self, name):
         if name.startswith('__') and name.endswith('__'):

Modified: python/branches/py3k-importlib/Lib/ctypes/test/__init__.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/__init__.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/__init__.py	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,4 @@
-import glob, os, sys, unittest, getopt, time
+import os, sys, unittest, getopt, time
 
 use_resources = []
 

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_array_in_pointer.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_array_in_pointer.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_array_in_pointer.py	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,7 @@
 def dump(obj):
     # helper function to dump memory contents in hex, with a hyphen
     # between the bytes.
-    h = str(hexlify(memoryview(obj)))
+    h = hexlify(memoryview(obj)).decode()
     return re.sub(r"(..)", r"\1-", h)[:-1]
 
 

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_arrays.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_arrays.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_arrays.py	Thu Mar 27 00:48:05 2008
@@ -57,11 +57,8 @@
 
         self.failUnlessEqual(len(ca), 3)
 
-        # slicing is now supported, but not extended slicing (3-argument)!
-        from operator import getslice, delitem
-        self.assertRaises(TypeError, getslice, ca, 0, 1, -1)
-
         # cannot delete items
+        from operator import delitem
         self.assertRaises(TypeError, delitem, ca, 0)
 
     def test_numeric_arrays(self):
@@ -94,12 +91,12 @@
         # Failed with 0.9.8, reported by JUrner
         p = create_string_buffer("foo")
         sz = (c_char * 3).from_address(addressof(p))
-        self.failUnlessEqual(sz[:], "foo")
-        self.failUnlessEqual(sz[::], "foo")
-        self.failUnlessEqual(sz[::-1], "oof")
-        self.failUnlessEqual(sz[::3], "f")
-        self.failUnlessEqual(sz[1:4:2], "o")
-        self.failUnlessEqual(sz.value, "foo")
+        self.failUnlessEqual(sz[:], b"foo")
+        self.failUnlessEqual(sz[::], b"foo")
+        self.failUnlessEqual(sz[::-1], b"oof")
+        self.failUnlessEqual(sz[::3], b"f")
+        self.failUnlessEqual(sz[1:4:2], b"o")
+        self.failUnlessEqual(sz.value, b"foo")
 
     try:
         create_unicode_buffer
@@ -116,5 +113,19 @@
             self.failUnlessEqual(sz[1:4:2], "o")
             self.failUnlessEqual(sz.value, "foo")
 
+    def test_cache(self):
+        # Array types are cached internally in the _ctypes extension,
+        # in a WeakValueDictionary.  Make sure the array type is
+        # removed from the cache when the itemtype goes away.  This
+        # test will not fail, but will show a leak in the testsuite.
+
+        # Create a new type:
+        class my_int(c_int):
+            pass
+        # Create a new array type based on it:
+        t1 = my_int * 1
+        t2 = my_int * 1
+        self.failUnless(t1 is t2)
+
 if __name__ == '__main__':
     unittest.main()

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_buffers.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_buffers.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_buffers.py	Thu Mar 27 00:48:05 2008
@@ -14,11 +14,11 @@
         self.failUnlessEqual(sizeof(b), 4 * sizeof(c_char))
         self.failUnless(type(b[0]) is bytes)
         self.failUnlessEqual(b[0], b"a")
-        self.failUnlessEqual(b[:], "abc\0")
-        self.failUnlessEqual(b[::], "abc\0")
-        self.failUnlessEqual(b[::-1], "\0cba")
-        self.failUnlessEqual(b[::2], "ac")
-        self.failUnlessEqual(b[::5], "a")
+        self.failUnlessEqual(b[:], b"abc\0")
+        self.failUnlessEqual(b[::], b"abc\0")
+        self.failUnlessEqual(b[::-1], b"\0cba")
+        self.failUnlessEqual(b[::2], b"ac")
+        self.failUnlessEqual(b[::5], b"a")
 
     def test_string_conversion(self):
         b = create_string_buffer("abc")
@@ -26,11 +26,11 @@
         self.failUnlessEqual(sizeof(b), 4 * sizeof(c_char))
         self.failUnless(type(b[0]) is bytes)
         self.failUnlessEqual(b[0], b"a")
-        self.failUnlessEqual(b[:], "abc\0")
-        self.failUnlessEqual(b[::], "abc\0")
-        self.failUnlessEqual(b[::-1], "\0cba")
-        self.failUnlessEqual(b[::2], "ac")
-        self.failUnlessEqual(b[::5], "a")
+        self.failUnlessEqual(b[:], b"abc\0")
+        self.failUnlessEqual(b[::], b"abc\0")
+        self.failUnlessEqual(b[::-1], b"\0cba")
+        self.failUnlessEqual(b[::2], b"ac")
+        self.failUnlessEqual(b[::5], b"a")
 
     try:
         c_wchar

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_byteswap.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_byteswap.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_byteswap.py	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,7 @@
 from ctypes import *
 
 def bin(s):
-    return str(hexlify(memoryview(s))).upper()
+    return hexlify(memoryview(s)).decode().upper()
 
 # Each *simple* type that supports different byte orders has an
 # __ctype_be__ attribute that specifies the same type in BIG ENDIAN

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_callbacks.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_callbacks.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_callbacks.py	Thu Mar 27 00:48:05 2008
@@ -14,7 +14,7 @@
         return args[-1]
 
     def check_type(self, typ, arg):
-        PROTO = self.functype.im_func(typ, typ)
+        PROTO = self.functype.__func__(typ, typ)
         result = PROTO(self.callback)(arg)
         if typ == c_float:
             self.failUnlessAlmostEqual(result, arg, places=5)
@@ -22,7 +22,7 @@
             self.failUnlessEqual(self.got_args, (arg,))
             self.failUnlessEqual(result, arg)
 
-        PROTO = self.functype.im_func(typ, c_byte, typ)
+        PROTO = self.functype.__func__(typ, c_byte, typ)
         result = PROTO(self.callback)(-3, arg)
         if typ == c_float:
             self.failUnlessAlmostEqual(result, arg, places=5)
@@ -110,12 +110,12 @@
         # functions, the type must have a non-NULL stgdict->setfunc.
         # POINTER(c_double), for example, is not supported.
 
-        prototype = self.functype.im_func(POINTER(c_double))
+        prototype = self.functype.__func__(POINTER(c_double))
         # The type is checked when the prototype is called
         self.assertRaises(TypeError, prototype, lambda: None)
 
     def test_unsupported_restype_2(self):
-        prototype = self.functype.im_func(object)
+        prototype = self.functype.__func__(object)
         self.assertRaises(TypeError, prototype, lambda: None)
 
 try:

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_cfuncs.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_cfuncs.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_cfuncs.py	Thu Mar 27 00:48:05 2008
@@ -158,17 +158,17 @@
         self.failUnlessEqual(self._dll.tf_bd(0, 42.), 14.)
         self.failUnlessEqual(self.S(), 42)
 
-##    def test_longdouble(self):
-##        self._dll.tf_D.restype = c_longdouble
-##        self._dll.tf_D.argtypes = (c_longdouble,)
-##        self.failUnlessEqual(self._dll.tf_D(42.), 14.)
-##        self.failUnlessEqual(self.S(), 42)
-
-##    def test_longdouble_plus(self):
-##        self._dll.tf_bD.restype = c_longdouble
-##        self._dll.tf_bD.argtypes = (c_byte, c_longdouble)
-##        self.failUnlessEqual(self._dll.tf_bD(0, 42.), 14.)
-##        self.failUnlessEqual(self.S(), 42)
+    def test_longdouble(self):
+        self._dll.tf_D.restype = c_longdouble
+        self._dll.tf_D.argtypes = (c_longdouble,)
+        self.failUnlessEqual(self._dll.tf_D(42.), 14.)
+        self.failUnlessEqual(self.S(), 42)
+
+    def test_longdouble_plus(self):
+        self._dll.tf_bD.restype = c_longdouble
+        self._dll.tf_bD.argtypes = (c_byte, c_longdouble)
+        self.failUnlessEqual(self._dll.tf_bD(0, 42.), 14.)
+        self.failUnlessEqual(self.S(), 42)
 
     def test_callwithresult(self):
         def process_result(result):

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_checkretval.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_checkretval.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_checkretval.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,4 @@
 import unittest
-import sys
 
 from ctypes import *
 

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_find.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_find.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_find.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 import unittest
-import os, sys
+import sys
 from ctypes import *
 from ctypes.util import find_library
 from ctypes.test import is_resource_enabled

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_functions.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_functions.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_functions.py	Thu Mar 27 00:48:05 2008
@@ -143,17 +143,17 @@
         self.failUnlessEqual(result, -21)
         self.failUnlessEqual(type(result), float)
 
-##    def test_longdoubleresult(self):
-##        f = dll._testfunc_D_bhilfD
-##        f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_longdouble]
-##        f.restype = c_longdouble
-##        result = f(1, 2, 3, 4, 5.0, 6.0)
-##        self.failUnlessEqual(result, 21)
-##        self.failUnlessEqual(type(result), float)
-
-##        result = f(-1, -2, -3, -4, -5.0, -6.0)
-##        self.failUnlessEqual(result, -21)
-##        self.failUnlessEqual(type(result), float)
+    def test_longdoubleresult(self):
+        f = dll._testfunc_D_bhilfD
+        f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_longdouble]
+        f.restype = c_longdouble
+        result = f(1, 2, 3, 4, 5.0, 6.0)
+        self.failUnlessEqual(result, 21)
+        self.failUnlessEqual(type(result), float)
+
+        result = f(-1, -2, -3, -4, -5.0, -6.0)
+        self.failUnlessEqual(result, -21)
+        self.failUnlessEqual(type(result), float)
 
     def test_longlongresult(self):
         try:

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_libc.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_libc.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_libc.py	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-import sys, os
 import unittest
 
 from ctypes import *
@@ -24,7 +23,7 @@
 
         chars = create_string_buffer("spam, spam, and spam")
         lib.my_qsort(chars, len(chars)-1, sizeof(c_char), comparefunc(sort))
-        self.failUnlessEqual(chars.raw, "   ,,aaaadmmmnpppsss\x00")
+        self.failUnlessEqual(chars.raw, b"   ,,aaaadmmmnpppsss\x00")
 
 if __name__ == "__main__":
     unittest.main()

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_memfunctions.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_memfunctions.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_memfunctions.py	Thu Mar 27 00:48:05 2008
@@ -9,21 +9,21 @@
         a = create_string_buffer(1000000)
         p = b"Hello, World"
         result = memmove(a, p, len(p))
-        self.failUnlessEqual(a.value, "Hello, World")
+        self.failUnlessEqual(a.value, b"Hello, World")
 
-        self.failUnlessEqual(string_at(result), "Hello, World")
-        self.failUnlessEqual(string_at(result, 5), "Hello")
-        self.failUnlessEqual(string_at(result, 16), "Hello, World\0\0\0\0")
-        self.failUnlessEqual(string_at(result, 0), "")
+        self.failUnlessEqual(string_at(result), b"Hello, World")
+        self.failUnlessEqual(string_at(result, 5), b"Hello")
+        self.failUnlessEqual(string_at(result, 16), b"Hello, World\0\0\0\0")
+        self.failUnlessEqual(string_at(result, 0), b"")
 
     def test_memset(self):
         a = create_string_buffer(1000000)
         result = memset(a, ord('x'), 16)
-        self.failUnlessEqual(a.value, "xxxxxxxxxxxxxxxx")
+        self.failUnlessEqual(a.value, b"xxxxxxxxxxxxxxxx")
 
-        self.failUnlessEqual(string_at(result), "xxxxxxxxxxxxxxxx")
-        self.failUnlessEqual(string_at(a), "xxxxxxxxxxxxxxxx")
-        self.failUnlessEqual(string_at(a, 20), "xxxxxxxxxxxxxxxx\0\0\0\0")
+        self.failUnlessEqual(string_at(result), b"xxxxxxxxxxxxxxxx")
+        self.failUnlessEqual(string_at(a), b"xxxxxxxxxxxxxxxx")
+        self.failUnlessEqual(string_at(a, 20), b"xxxxxxxxxxxxxxxx\0\0\0\0")
 
     def test_cast(self):
         a = (c_ubyte * 32)(*map(ord, "abcdef"))
@@ -46,8 +46,8 @@
         self.failUnlessEqual(2, sys.getrefcount(s))
         self.failUnless(s, "foo bar")
 
-        self.failUnlessEqual(string_at(b"foo bar", 7), "foo bar")
-        self.failUnlessEqual(string_at(b"foo bar", 3), "foo")
+        self.failUnlessEqual(string_at(b"foo bar", 7), b"foo bar")
+        self.failUnlessEqual(string_at(b"foo bar", 3), b"foo")
 
     try:
         create_unicode_buffer

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_numbers.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_numbers.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_numbers.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,6 @@
 from ctypes import *
 import unittest
-import sys, struct
+import struct
 
 def valid_ranges(*types):
     # given a sequence of numeric types, collect their _type_
@@ -105,15 +105,31 @@
     def test_floats(self):
         # c_float and c_double can be created from
         # Python int, long and float
+        class FloatLike(object):
+            def __float__(self):
+                return 2.0
+        f = FloatLike()
         for t in float_types:
             self.failUnlessEqual(t(2.0).value, 2.0)
             self.failUnlessEqual(t(2).value, 2.0)
             self.failUnlessEqual(t(2).value, 2.0)
+            self.failUnlessEqual(t(f).value, 2.0)
 
     def test_integers(self):
-        # integers cannot be constructed from floats
+        class FloatLike(object):
+            def __float__(self):
+                return 2.0
+        f = FloatLike()
+        class IntLike(object):
+            def __int__(self):
+                return 2
+        i = IntLike()
+        # integers cannot be constructed from floats,
+        # but from integer-like objects
         for t in signed_types + unsigned_types:
             self.assertRaises(TypeError, t, 3.14)
+            self.assertRaises(TypeError, t, f)
+            self.failUnlessEqual(t(i).value, 2)
 
     def test_sizes(self):
         for t in signed_types + unsigned_types + float_types + bool_types:

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_prototypes.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_prototypes.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_prototypes.py	Thu Mar 27 00:48:05 2008
@@ -48,6 +48,24 @@
         func.restype = c_long
         func.argtypes = None
 
+    def test_paramflags(self):
+        # function returns c_void_p result,
+        # and has a required parameter named 'input'
+        prototype = CFUNCTYPE(c_void_p, c_void_p)
+        func = prototype(("_testfunc_p_p", testdll),
+                         ((1, "input"),))
+
+        try:
+            func()
+        except TypeError as details:
+            self.failUnlessEqual(str(details), "required argument 'input' missing")
+        else:
+            self.fail("TypeError not raised")
+
+        self.failUnlessEqual(func(None), None)
+        self.failUnlessEqual(func(input=None), None)
+
+
     def test_int_pointer_arg(self):
         func = testdll._testfunc_p_p
         func.restype = c_long

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_python_api.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_python_api.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_python_api.py	Thu Mar 27 00:48:05 2008
@@ -23,13 +23,13 @@
         PyString_FromStringAndSize.restype = py_object
         PyString_FromStringAndSize.argtypes = c_char_p, c_py_ssize_t
 
-        self.failUnlessEqual(PyString_FromStringAndSize("abcdefghi", 3), "abc")
+        self.failUnlessEqual(PyString_FromStringAndSize(b"abcdefghi", 3), b"abc")
 
     def test_PyString_FromString(self):
         pythonapi.PyString_FromString.restype = py_object
         pythonapi.PyString_FromString.argtypes = (c_char_p,)
 
-        s = "abc"
+        s = b"abc"
         refcnt = grc(s)
         pyob = pythonapi.PyString_FromString(s)
         self.failUnlessEqual(grc(s), refcnt)
@@ -73,10 +73,10 @@
 
         buf = c_buffer(256)
         PyOS_snprintf(buf, sizeof(buf), "Hello from %s", b"ctypes")
-        self.failUnlessEqual(buf.value, "Hello from ctypes")
+        self.failUnlessEqual(buf.value, b"Hello from ctypes")
 
         PyOS_snprintf(buf, sizeof(buf), "Hello from %s (%d, %d, %d)", b"ctypes", 1, 2, 3)
-        self.failUnlessEqual(buf.value, "Hello from ctypes (1, 2, 3)")
+        self.failUnlessEqual(buf.value, b"Hello from ctypes (1, 2, 3)")
 
         # not enough arguments
         self.failUnlessRaises(TypeError, PyOS_snprintf, buf)

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_returnfuncptrs.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_returnfuncptrs.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_returnfuncptrs.py	Thu Mar 27 00:48:05 2008
@@ -14,7 +14,9 @@
         strchr = get_strchr()
         self.failUnlessEqual(strchr("abcdef", "b"), "bcdef")
         self.failUnlessEqual(strchr("abcdef", "x"), None)
-        self.assertRaises(ArgumentError, strchr, "abcdef", 3)
+        self.failUnlessEqual(strchr("abcdef", 98), "bcdef")
+        self.failUnlessEqual(strchr("abcdef", 107), None)
+        self.assertRaises(ArgumentError, strchr, "abcdef", 3.0)
         self.assertRaises(TypeError, strchr, "abcdef")
 
     def test_without_prototype(self):
@@ -28,7 +30,7 @@
         strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(addr)
         self.failUnless(strchr("abcdef", "b"), "bcdef")
         self.failUnlessEqual(strchr("abcdef", "x"), None)
-        self.assertRaises(ArgumentError, strchr, "abcdef", 3)
+        self.assertRaises(ArgumentError, strchr, "abcdef", 3.0)
         self.assertRaises(TypeError, strchr, "abcdef")
 
 if __name__ == "__main__":

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_slicing.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_slicing.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_slicing.py	Thu Mar 27 00:48:05 2008
@@ -45,21 +45,17 @@
         b[33::-3] = range(12)
         self.failUnlessEqual(a[:], b)
 
-        from operator import setslice, setitem
+        from operator import setitem
 
         # TypeError: int expected instead of str instance
-        self.assertRaises(TypeError, setslice, a, 0, 5, "abcde")
         self.assertRaises(TypeError, setitem, a, slice(0, 5), "abcde")
         # TypeError: int expected instead of str instance
-        self.assertRaises(TypeError, setslice, a, 0, 5, ["a", "b", "c", "d", "e"])
         self.assertRaises(TypeError, setitem, a, slice(0, 5),
                           ["a", "b", "c", "d", "e"])
         # TypeError: int expected instead of float instance
-        self.assertRaises(TypeError, setslice, a, 0, 5, [1, 2, 3, 4, 3.14])
         self.assertRaises(TypeError, setitem, a, slice(0, 5),
                           [1, 2, 3, 4, 3.14])
         # ValueError: Can only assign sequence of same size
-        self.assertRaises(ValueError, setslice, a, 0, 5, range(32))
         self.assertRaises(ValueError, setitem, a, slice(0, 5), range(32))
 
     def test_char_ptr(self):
@@ -86,8 +82,6 @@
         self.assertRaises(ValueError, operator.getitem,
                           res, slice(-5, None, None))
 
-        self.assertRaises(TypeError, operator.setslice,
-                          res, 0, 5, "abcde")
         self.assertRaises(TypeError, operator.setitem,
                           res, slice(0, 5), "abcde")
         dll.my_free(res)
@@ -115,13 +109,13 @@
         dll.my_strdup.errcheck = errcheck
         try:
             res = dll.my_strdup(s)
-            self.failUnlessEqual(res, str(s))
+            self.failUnlessEqual(res, s.decode())
         finally:
             del dll.my_strdup.errcheck
 
 
     def test_char_array(self):
-        s = "abcdefghijklmnopqrstuvwxyz\0"
+        s = b"abcdefghijklmnopqrstuvwxyz\0"
 
         p = (c_char * 27)(*s)
         self.failUnlessEqual(p[:], s)
@@ -150,8 +144,6 @@
             self.failUnlessEqual(res[len(s)-1:5:-7], s[:5:-7])
 
             import operator
-            self.assertRaises(TypeError, operator.setslice,
-                              res, 0, 5, "abcde")
             self.assertRaises(TypeError, operator.setitem,
                               res, slice(0, 5), "abcde")
             dll.my_free(res)

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_strings.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_strings.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_strings.py	Thu Mar 27 00:48:05 2008
@@ -6,20 +6,20 @@
         BUF = c_char * 4
 
         buf = BUF("a", "b", "c")
-        self.failUnlessEqual(buf.value, "abc")
-        self.failUnlessEqual(buf.raw, "abc\000")
+        self.failUnlessEqual(buf.value, b"abc")
+        self.failUnlessEqual(buf.raw, b"abc\000")
 
         buf.value = "ABCD"
-        self.failUnlessEqual(buf.value, "ABCD")
-        self.failUnlessEqual(buf.raw, "ABCD")
+        self.failUnlessEqual(buf.value, b"ABCD")
+        self.failUnlessEqual(buf.raw, b"ABCD")
 
         buf.value = "x"
-        self.failUnlessEqual(buf.value, "x")
-        self.failUnlessEqual(buf.raw, "x\000CD")
+        self.failUnlessEqual(buf.value, b"x")
+        self.failUnlessEqual(buf.raw, b"x\000CD")
 
         buf[1] = "Z"
-        self.failUnlessEqual(buf.value, "xZCD")
-        self.failUnlessEqual(buf.raw, "xZCD")
+        self.failUnlessEqual(buf.value, b"xZCD")
+        self.failUnlessEqual(buf.raw, b"xZCD")
 
         self.assertRaises(ValueError, setattr, buf, "value", "aaaaaaaa")
         self.assertRaises(TypeError, setattr, buf, "value", 42)
@@ -27,8 +27,8 @@
     def test_c_buffer_value(self):
         buf = c_buffer(32)
 
-        buf.value = "Hello, World"
-        self.failUnlessEqual(buf.value, "Hello, World")
+        buf.value = b"Hello, World"
+        self.failUnlessEqual(buf.value, b"Hello, World")
 
         self.failUnlessRaises(TypeError, setattr, buf, "value", memoryview(b"Hello, World"))
         self.assertRaises(TypeError, setattr, buf, "value", memoryview(b"abc"))
@@ -38,7 +38,7 @@
         buf = c_buffer(32)
 
         buf.raw = memoryview(b"Hello, World")
-        self.failUnlessEqual(buf.value, "Hello, World")
+        self.failUnlessEqual(buf.value, b"Hello, World")
         self.assertRaises(TypeError, setattr, buf, "value", memoryview(b"abc"))
         self.assertRaises(ValueError, setattr, buf, "raw", memoryview(b"x" * 100))
 

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_structures.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_structures.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_structures.py	Thu Mar 27 00:48:05 2008
@@ -215,6 +215,15 @@
         # too long
         self.assertRaises(ValueError, Person, "1234567", 5)
 
+    def test_conflicting_initializers(self):
+        class POINT(Structure):
+            _fields_ = [("x", c_int), ("y", c_int)]
+        # conflicting positional and keyword args
+        self.assertRaises(TypeError, POINT, 2, 3, x=4)
+        self.assertRaises(TypeError, POINT, 2, 3, y=4)
+
+        # too many initializers
+        self.assertRaises(TypeError, POINT, 2, 3, 4)
 
     def test_keyword_initializers(self):
         class POINT(Structure):
@@ -305,9 +314,9 @@
         self.failUnlessEqual(cls, RuntimeError)
         if issubclass(Exception, object):
             self.failUnlessEqual(msg,
-                                 "(Phone) <type 'ValueError'>: too many initializers")
+                                 "(Phone) <type 'TypeError'>: too many initializers")
         else:
-            self.failUnlessEqual(msg, "(Phone) ValueError: too many initializers")
+            self.failUnlessEqual(msg, "(Phone) TypeError: too many initializers")
 
 
     def get_except(self, func, *args):

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_unicode.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_unicode.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_unicode.py	Thu Mar 27 00:48:05 2008
@@ -111,18 +111,18 @@
 
             ctypes.set_conversion_mode("ascii", "replace")
             buf = ctypes.create_string_buffer("ab\xe4\xf6\xfc")
-            self.failUnlessEqual(buf[:], "ab???\0")
-            self.failUnlessEqual(buf[::], "ab???\0")
-            self.failUnlessEqual(buf[::-1], "\0???ba")
-            self.failUnlessEqual(buf[::2], "a??")
-            self.failUnlessEqual(buf[6:5:-1], "")
+            self.failUnlessEqual(buf[:], b"ab???\0")
+            self.failUnlessEqual(buf[::], b"ab???\0")
+            self.failUnlessEqual(buf[::-1], b"\0???ba")
+            self.failUnlessEqual(buf[::2], b"a??")
+            self.failUnlessEqual(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.failUnlessEqual(buf[:], "ab\0\0\0\0")
-            self.failUnlessEqual(buf[::], "ab\0\0\0\0")
-            self.failUnlessEqual(buf[::-1], "\0\0\0\0ba")
+            self.failUnlessEqual(buf[:], b"ab\0\0\0\0")
+            self.failUnlessEqual(buf[::], b"ab\0\0\0\0")
+            self.failUnlessEqual(buf[::-1], b"\0\0\0\0ba")
 
 if __name__ == '__main__':
     unittest.main()

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_values.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_values.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_values.py	Thu Mar 27 00:48:05 2008
@@ -10,12 +10,18 @@
 class ValuesTestCase(unittest.TestCase):
 
     def test_an_integer(self):
+        # This test checks and changes an integer stored inside the
+        # _ctypes_test dll/shared lib.
         ctdll = CDLL(_ctypes_test.__file__)
         an_integer = c_int.in_dll(ctdll, "an_integer")
         x = an_integer.value
         self.failUnlessEqual(x, ctdll.get_an_integer())
         an_integer.value *= 2
         self.failUnlessEqual(x*2, ctdll.get_an_integer())
+        # To avoid test failures when this test is repeated several
+        # times the original value must be restored
+        an_integer.value = x
+        self.failUnlessEqual(x, ctdll.get_an_integer())
 
     def test_undefined(self):
         ctdll = CDLL(_ctypes_test.__file__)

Modified: python/branches/py3k-importlib/Lib/ctypes/util.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/util.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/util.py	Thu Mar 27 00:48:05 2008
@@ -50,8 +50,10 @@
               '$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
         try:
             f = os.popen(cmd)
-            trace = f.read()
-            f.close()
+            try:
+                trace = f.read()
+            finally:
+                f.close()
         finally:
             try:
                 os.unlink(ccout)
@@ -70,7 +72,12 @@
             if not f:
                 return None
             cmd = "/usr/ccs/bin/dump -Lpv 2>/dev/null " + f
-            res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', os.popen(cmd).read())
+            f = os.popen(cmd)
+            try:
+                data = f.read()
+            finally:
+                f.close()
+            res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', data)
             if not res:
                 return None
             return res.group(1)
@@ -80,7 +87,12 @@
             if not f:
                 return None
             cmd = "objdump -p -j .dynamic 2>/dev/null " + f
-            res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read())
+            f = os.popen(cmd)
+            try:
+                data = f.read()
+            finally:
+                f.close()
+            res = re.search(r'\sSONAME\s+([^\s]+)', data)
             if not res:
                 return None
             return res.group(1)
@@ -98,16 +110,20 @@
                     nums.insert(0, int(parts.pop()))
             except ValueError:
                 pass
-            return nums or [ sys.maxint ]
+            return nums or [ sys.maxsize ]
 
         def find_library(name):
             ename = re.escape(name)
             expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
-            res = re.findall(expr,
-                             os.popen('/sbin/ldconfig -r 2>/dev/null').read())
+            f = os.popen('/sbin/ldconfig -r 2>/dev/null')
+            try:
+                data = f.read()
+            finally:
+                f.close()
+            res = re.findall(expr, data)
             if not res:
                 return _get_soname(_findLib_gcc(name))
-            res.sort(cmp= lambda x,y: cmp(_num_version(x), _num_version(y)))
+            res.sort(key=_num_version)
             return res[-1]
 
     else:
@@ -115,12 +131,21 @@
         def _findLib_ldconfig(name):
             # XXX assuming GLIBC's ldconfig (with option -p)
             expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
-            res = re.search(expr,
-                            os.popen('/sbin/ldconfig -p 2>/dev/null').read())
+            f = os.popen('/sbin/ldconfig -p 2>/dev/null')
+            try:
+                data = f.read()
+            finally:
+                f.close()
+            res = re.search(expr, data)
             if not res:
                 # Hm, this works only for libs needed by the python executable.
                 cmd = 'ldd %s 2>/dev/null' % sys.executable
-                res = re.search(expr, os.popen(cmd).read())
+                f = os.popen(cmd)
+                try:
+                    data = f.read()
+                finally:
+                    f.close()
+                res = re.search(expr, data)
                 if not res:
                     return None
             return res.group(0)

Modified: python/branches/py3k-importlib/Lib/curses/__init__.py
==============================================================================
--- python/branches/py3k-importlib/Lib/curses/__init__.py	(original)
+++ python/branches/py3k-importlib/Lib/curses/__init__.py	Thu Mar 27 00:48:05 2008
@@ -14,6 +14,8 @@
 
 from _curses import *
 from curses.wrapper import wrapper
+import os as _os
+import sys as _sys
 
 # Some constants, most notably the ACS_* ones, are only added to the C
 # _curses module's dictionary after initscr() is called.  (Some
@@ -25,6 +27,10 @@
 
 def initscr():
     import _curses, curses
+    # we call setupterm() here because it raises an error
+    # instead of calling exit() in error cases.
+    setupterm(term=_os.environ.get("TERM", "unknown"),
+              fd=_sys.__stdout__.fileno())
     stdscr = _curses.initscr()
     for key, value in _curses.__dict__.items():
         if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):

Modified: python/branches/py3k-importlib/Lib/curses/textpad.py
==============================================================================
--- python/branches/py3k-importlib/Lib/curses/textpad.py	(original)
+++ python/branches/py3k-importlib/Lib/curses/textpad.py	Thu Mar 27 00:48:05 2008
@@ -39,8 +39,9 @@
     KEY_LEFT = Ctrl-B, KEY_RIGHT = Ctrl-F, KEY_UP = Ctrl-P, KEY_DOWN = Ctrl-N
     KEY_BACKSPACE = Ctrl-h
     """
-    def __init__(self, win):
+    def __init__(self, win, insert_mode=False):
         self.win = win
+        self.insert_mode = insert_mode
         (self.maxy, self.maxx) = win.getmaxyx()
         self.maxy = self.maxy - 1
         self.maxx = self.maxx - 1
@@ -49,9 +50,10 @@
         win.keypad(1)
 
     def _end_of_line(self, y):
-        "Go to the location of the first blank on the given line."
+        """Go to the location of the first blank on the given line,
+        returning the index of the last non-blank character."""
         last = self.maxx
-        while 1:
+        while True:
             if ascii.ascii(self.win.inch(y, last)) != ascii.SP:
                 last = min(self.maxx, last+1)
                 break
@@ -60,19 +62,31 @@
             last = last - 1
         return last
 
+    def _insert_printable_char(self, ch):
+        (y, x) = self.win.getyx()
+        if y < self.maxy or x < self.maxx:
+            if self.insert_mode:
+                oldch = self.win.inch()
+            # The try-catch ignores the error we trigger from some curses
+            # versions by trying to write into the lowest-rightmost spot
+            # in the window.
+            try:
+                self.win.addch(ch)
+            except curses.error:
+                pass
+            if self.insert_mode:
+                (backy, backx) = self.win.getyx()
+                if ascii.isprint(oldch):
+                    self._insert_printable_char(oldch)
+                    self.win.move(backy, backx)
+
     def do_command(self, ch):
         "Process a single editing command."
         (y, x) = self.win.getyx()
         self.lastcmd = ch
         if ascii.isprint(ch):
             if y < self.maxy or x < self.maxx:
-                # The try-catch ignores the error we trigger from some curses
-                # versions by trying to write into the lowest-rightmost spot
-                # in the window.
-                try:
-                    self.win.addch(ch)
-                except curses.error:
-                    pass
+                self._insert_printable_char(ch)
         elif ch == ascii.SOH:                           # ^a
             self.win.move(y, 0)
         elif ch in (ascii.STX,curses.KEY_LEFT, ascii.BS,curses.KEY_BACKSPACE):
@@ -139,7 +153,7 @@
             if stop == 0 and self.stripspaces:
                 continue
             for x in range(self.maxx+1):
-                if self.stripspaces and x == stop:
+                if self.stripspaces and x > stop:
                     break
                 result = result + chr(ascii.ascii(self.win.inch(y, x)))
             if self.maxy > 0:

Modified: python/branches/py3k-importlib/Lib/curses/wrapper.py
==============================================================================
--- python/branches/py3k-importlib/Lib/curses/wrapper.py	(original)
+++ python/branches/py3k-importlib/Lib/curses/wrapper.py	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,7 @@
 
 """
 
-import sys, curses
+import curses
 
 def wrapper(func, *args, **kwds):
     """Wrapper function that initializes curses and calls another function,

Modified: python/branches/py3k-importlib/Lib/decimal.py
==============================================================================
--- python/branches/py3k-importlib/Lib/decimal.py	(original)
+++ python/branches/py3k-importlib/Lib/decimal.py	Thu Mar 27 00:48:05 2008
@@ -35,26 +35,26 @@
 useful for financial applications or for contexts where users have
 expectations that are at odds with binary floating point (for instance,
 in binary floating point, 1.00 % 0.1 gives 0.09999999999999995 instead
-of the expected Decimal("0.00") returned by decimal floating point).
+of the expected Decimal('0.00') returned by decimal floating point).
 
 Here are some examples of using the decimal module:
 
 >>> from decimal import *
 >>> setcontext(ExtendedContext)
 >>> Decimal(0)
-Decimal("0")
->>> Decimal("1")
-Decimal("1")
->>> Decimal("-.0123")
-Decimal("-0.0123")
+Decimal('0')
+>>> Decimal('1')
+Decimal('1')
+>>> Decimal('-.0123')
+Decimal('-0.0123')
 >>> Decimal(123456)
-Decimal("123456")
->>> Decimal("123.45e12345678901234567890")
-Decimal("1.2345E+12345678901234567892")
->>> Decimal("1.33") + Decimal("1.27")
-Decimal("2.60")
->>> Decimal("12.34") + Decimal("3.87") - Decimal("18.41")
-Decimal("-2.20")
+Decimal('123456')
+>>> Decimal('123.45e12345678901234567890')
+Decimal('1.2345E+12345678901234567892')
+>>> Decimal('1.33') + Decimal('1.27')
+Decimal('2.60')
+>>> Decimal('12.34') + Decimal('3.87') - Decimal('18.41')
+Decimal('-2.20')
 >>> dig = Decimal(1)
 >>> print(dig / Decimal(3))
 0.333333333
@@ -91,7 +91,7 @@
 >>> print(c.flags[InvalidOperation])
 0
 >>> c.divide(Decimal(0), Decimal(0))
-Decimal("NaN")
+Decimal('NaN')
 >>> c.traps[InvalidOperation] = 1
 >>> print(c.flags[InvalidOperation])
 1
@@ -134,8 +134,15 @@
     'setcontext', 'getcontext', 'localcontext'
 ]
 
+import numbers as _numbers
 import copy as _copy
 
+try:
+    from collections import namedtuple as _namedtuple
+    DecimalTuple = _namedtuple('DecimalTuple', 'sign digits exponent')
+except ImportError:
+    DecimalTuple = lambda *args: args
+
 # Rounding
 ROUND_DOWN = 'ROUND_DOWN'
 ROUND_HALF_UP = 'ROUND_HALF_UP'
@@ -146,10 +153,6 @@
 ROUND_HALF_DOWN = 'ROUND_HALF_DOWN'
 ROUND_05UP = 'ROUND_05UP'
 
-# Rounding decision (not part of the public API)
-NEVER_ROUND = 'NEVER_ROUND'    # Round in division (non-divmod), sqrt ONLY
-ALWAYS_ROUND = 'ALWAYS_ROUND'  # Every operation rounds at end.
-
 # Errors
 
 class DecimalException(ArithmeticError):
@@ -187,7 +190,6 @@
     number of zero digits are appended to the coefficient ("fold-down").
     """
 
-
 class InvalidOperation(DecimalException):
     """An invalid operation was performed.
 
@@ -213,14 +215,10 @@
     """
     def handle(self, context, *args):
         if args:
-            if args[0] == 1:  # sNaN, must drop 's' but keep diagnostics
-                ans = Decimal((args[1]._sign, args[1]._int, 'n'))
-                return ans._fix_nan(context)
-            elif args[0] == 2:
-                return Decimal( (args[1], args[2], 'n') )
+            ans = _dec_from_triple(args[0]._sign, args[0]._int, 'n', True)
+            return ans._fix_nan(context)
         return NaN
 
-
 class ConversionSyntax(InvalidOperation):
     """Trying to convert badly formed string.
 
@@ -280,7 +278,6 @@
     The inexact signal may be tested (or trapped) to determine if a given
     operation (or sequence of operations) was inexact.
     """
-    pass
 
 class InvalidContext(InvalidOperation):
     """Invalid context.  Unknown rounding, for example.
@@ -307,7 +304,6 @@
     The rounded signal may be tested (or trapped) to determine if a given
     operation (or sequence of operations) caused a loss of precision.
     """
-    pass
 
 class Subnormal(DecimalException):
     """Exponent < Emin before rounding.
@@ -319,7 +315,6 @@
     The subnormal signal may be tested (or trapped) to determine if a given
     or operation (or sequence of operations) yielded a subnormal result.
     """
-    pass
 
 class Overflow(Inexact, Rounded):
     """Numerical overflow.
@@ -341,7 +336,7 @@
     the result is the same as for round-down if the sign of the intermediate
     result is 0, or is [1,inf] otherwise.  In all cases, Inexact and Rounded
     will also be raised.
-   """
+    """
 
     def handle(self, context, sign, *args):
         if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN,
@@ -350,13 +345,13 @@
         if sign == 0:
             if context.rounding == ROUND_CEILING:
                 return Infsign[sign]
-            return Decimal((sign, (9,)*context.prec,
-                            context.Emax-context.prec+1))
+            return _dec_from_triple(sign, '9'*context.prec,
+                            context.Emax-context.prec+1)
         if sign == 1:
             if context.rounding == ROUND_FLOOR:
                 return Infsign[sign]
-            return Decimal( (sign, (9,)*context.prec,
-                             context.Emax-context.prec+1))
+            return _dec_from_triple(sign, '9'*context.prec,
+                             context.Emax-context.prec+1)
 
 
 class Underflow(Inexact, Rounded, Subnormal):
@@ -509,7 +504,7 @@
 
 ##### Decimal class #######################################################
 
-class Decimal(object):
+class Decimal(_numbers.Real):
     """Floating point class for decimal arithmetic."""
 
     __slots__ = ('_exp','_int','_sign', '_is_special')
@@ -522,31 +517,67 @@
         """Create a decimal point instance.
 
         >>> Decimal('3.14')              # string input
-        Decimal("3.14")
+        Decimal('3.14')
         >>> Decimal((0, (3, 1, 4), -2))  # tuple (sign, digit_tuple, exponent)
-        Decimal("3.14")
+        Decimal('3.14')
         >>> Decimal(314)                 # int
-        Decimal("314")
+        Decimal('314')
         >>> Decimal(Decimal(314))        # another decimal instance
-        Decimal("314")
+        Decimal('314')
+        >>> Decimal('  3.14  \\n')        # leading and trailing whitespace okay
+        Decimal('3.14')
         """
 
+        # Note that the coefficient, self._int, is actually stored as
+        # a string rather than as a tuple of digits.  This speeds up
+        # the "digits to integer" and "integer to digits" conversions
+        # that are used in almost every arithmetic operation on
+        # Decimals.  This is an internal detail: the as_tuple function
+        # and the Decimal constructor still deal with tuples of
+        # digits.
+
         self = object.__new__(cls)
-        self._is_special = False
 
-        # From an internal working value
-        if isinstance(value, _WorkRep):
-            self._sign = value.sign
-            self._int = tuple(map(int, str(value.int)))
-            self._exp = int(value.exp)
-            return self
+        # From a string
+        # REs insist on real strings, so we can too.
+        if isinstance(value, str):
+            m = _parser(value.strip())
+            if m is None:
+                if context is None:
+                    context = getcontext()
+                return context._raise_error(ConversionSyntax,
+                                "Invalid literal for Decimal: %r" % value)
 
-        # From another decimal
-        if isinstance(value, Decimal):
-            self._exp  = value._exp
-            self._sign = value._sign
-            self._int  = value._int
-            self._is_special  = value._is_special
+            if m.group('sign') == "-":
+                self._sign = 1
+            else:
+                self._sign = 0
+            intpart = m.group('int')
+            if intpart is not None:
+                # finite number
+                fracpart = m.group('frac')
+                exp = int(m.group('exp') or '0')
+                if fracpart is not None:
+                    self._int = (intpart+fracpart).lstrip('0') or '0'
+                    self._exp = exp - len(fracpart)
+                else:
+                    self._int = intpart.lstrip('0') or '0'
+                    self._exp = exp
+                self._is_special = False
+            else:
+                diag = m.group('diag')
+                if diag is not None:
+                    # NaN
+                    self._int = diag.lstrip('0')
+                    if m.group('signal'):
+                        self._exp = 'N'
+                    else:
+                        self._exp = 'n'
+                else:
+                    # infinity
+                    self._int = '0'
+                    self._exp = 'F'
+                self._is_special = True
             return self
 
         # From an integer
@@ -556,73 +587,82 @@
             else:
                 self._sign = 1
             self._exp = 0
-            self._int = tuple(map(int, str(abs(value))))
+            self._int = str(abs(value))
+            self._is_special = False
+            return self
+
+        # From another decimal
+        if isinstance(value, Decimal):
+            self._exp  = value._exp
+            self._sign = value._sign
+            self._int  = value._int
+            self._is_special  = value._is_special
+            return self
+
+        # From an internal working value
+        if isinstance(value, _WorkRep):
+            self._sign = value.sign
+            self._int = str(value.int)
+            self._exp = int(value.exp)
+            self._is_special = False
             return self
 
         # tuple/list conversion (possibly from as_tuple())
         if isinstance(value, (list,tuple)):
             if len(value) != 3:
-                raise ValueError('Invalid arguments')
-            if value[0] not in (0,1):
-                raise ValueError('Invalid sign')
-            for digit in value[1]:
-                if not isinstance(digit, int) or digit < 0:
-                    raise ValueError("The second value in the tuple must be "
-                                "composed of non negative integer elements.")
+                raise ValueError('Invalid tuple size in creation of Decimal '
+                                 'from list or tuple.  The list or tuple '
+                                 'should have exactly three elements.')
+            # process sign.  The isinstance test rejects floats
+            if not (isinstance(value[0], int) and value[0] in (0,1)):
+                raise ValueError("Invalid sign.  The first value in the tuple "
+                                 "should be an integer; either 0 for a "
+                                 "positive number or 1 for a negative number.")
             self._sign = value[0]
-            self._int  = tuple(value[1])
-            if value[2] in ('F','n','N'):
+            if value[2] == 'F':
+                # infinity: value[1] is ignored
+                self._int = '0'
                 self._exp = value[2]
                 self._is_special = True
             else:
-                self._exp  = int(value[2])
+                # process and validate the digits in value[1]
+                digits = []
+                for digit in value[1]:
+                    if isinstance(digit, int) and 0 <= digit <= 9:
+                        # skip leading zeros
+                        if digits or digit != 0:
+                            digits.append(digit)
+                    else:
+                        raise ValueError("The second value in the tuple must "
+                                         "be composed of integers in the range "
+                                         "0 through 9.")
+                if value[2] in ('n', 'N'):
+                    # NaN: digits form the diagnostic
+                    self._int = ''.join(map(str, digits))
+                    self._exp = value[2]
+                    self._is_special = True
+                elif isinstance(value[2], int):
+                    # finite number: digits give the coefficient
+                    self._int = ''.join(map(str, digits or [0]))
+                    self._exp = value[2]
+                    self._is_special = False
+                else:
+                    raise ValueError("The third value in the tuple must "
+                                     "be an integer, or one of the "
+                                     "strings 'F', 'n', 'N'.")
             return self
 
         if isinstance(value, float):
             raise TypeError("Cannot convert float to Decimal.  " +
                             "First convert the float to a string")
 
-        # Other argument types may require the context during interpretation
-        if context is None:
-            context = getcontext()
-
-        # From a string
-        # REs insist on real strings, so we can too.
-        if isinstance(value, basestring):
-            if _isinfinity(value):
-                self._exp = 'F'
-                self._int = (0,)
-                self._is_special = True
-                if _isinfinity(value) == 1:
-                    self._sign = 0
-                else:
-                    self._sign = 1
-                return self
-            if _isnan(value):
-                sig, sign, diag = _isnan(value)
-                self._is_special = True
-                if sig == 1:
-                    self._exp = 'n'  # qNaN
-                else:  # sig == 2
-                    self._exp = 'N'  # sNaN
-                self._sign = sign
-                self._int = tuple(map(int, diag))  # Diagnostic info
-                return self
-            try:
-                self._sign, self._int, self._exp = _string2exact(value)
-            except ValueError:
-                self._is_special = True
-                return context._raise_error(ConversionSyntax,
-                                   "Invalid literal for Decimal: %r" % value)
-            return self
-
         raise TypeError("Cannot convert %r to Decimal" % value)
 
     def _isnan(self):
         """Returns whether the number is not actually one.
 
         0 if a number
-        1 if NaN  (it could be a normal quiet NaN or a phantom one)
+        1 if NaN
         2 if sNaN
         """
         if self._is_special:
@@ -668,38 +708,63 @@
 
             if self_is_nan == 2:
                 return context._raise_error(InvalidOperation, 'sNaN',
-                                        1, self)
+                                        self)
             if other_is_nan == 2:
                 return context._raise_error(InvalidOperation, 'sNaN',
-                                        1, other)
+                                        other)
             if self_is_nan:
                 return self._fix_nan(context)
 
             return other._fix_nan(context)
         return 0
 
+    def _compare_check_nans(self, other, context):
+        """Version of _check_nans used for the signaling comparisons
+        compare_signal, __le__, __lt__, __ge__, __gt__.
+
+        Signal InvalidOperation if either self or other is a (quiet
+        or signaling) NaN.  Signaling NaNs take precedence over quiet
+        NaNs.
+
+        Return 0 if neither operand is a NaN.
+
+        """
+        if context is None:
+            context = getcontext()
+
+        if self._is_special or other._is_special:
+            if self.is_snan():
+                return context._raise_error(InvalidOperation,
+                                            'comparison involving sNaN',
+                                            self)
+            elif other.is_snan():
+                return context._raise_error(InvalidOperation,
+                                            'comparison involving sNaN',
+                                            other)
+            elif self.is_qnan():
+                return context._raise_error(InvalidOperation,
+                                            'comparison involving NaN',
+                                            self)
+            elif other.is_qnan():
+                return context._raise_error(InvalidOperation,
+                                            'comparison involving NaN',
+                                            other)
+        return 0
+
     def __bool__(self):
-        """return True if the number is non-zero.
+        """Return True if self is nonzero; otherwise return False.
 
-        False if self == 0
-        True if self != 0
+        NaNs and infinities are considered nonzero.
         """
-        if self._is_special:
-            return True
-        return sum(self._int) != 0
+        return self._is_special or self._int != '0'
 
-    def __cmp__(self, other):
-        other = _convert_other(other)
-        if other is NotImplemented:
-            # Never return NotImplemented
-            return 1
+    def _cmp(self, other):
+        """Compare the two non-NaN decimal instances self and other.
 
-        if self._is_special or other._is_special:
-            # check for nans, without raising on a signaling nan
-            if self._isnan() or other._isnan():
-                return 1  # Comparison involving NaN's always reports self > other
+        Returns -1 if self < other, 0 if self == other and 1
+        if self > other.  This routine is for internal use only."""
 
-            # INF = INF
+        if self._is_special or other._is_special:
             return cmp(self._isinfinity(), other._isinfinity())
 
         # check for zeros;  note that cmp(0, -0) should return 0
@@ -720,43 +785,80 @@
         self_adjusted = self.adjusted()
         other_adjusted = other.adjusted()
         if self_adjusted == other_adjusted:
-            self_padded = self._int + (0,)*(self._exp - other._exp)
-            other_padded = other._int + (0,)*(other._exp - self._exp)
+            self_padded = self._int + '0'*(self._exp - other._exp)
+            other_padded = other._int + '0'*(other._exp - self._exp)
             return cmp(self_padded, other_padded) * (-1)**self._sign
         elif self_adjusted > other_adjusted:
             return (-1)**self._sign
         else: # self_adjusted < other_adjusted
             return -((-1)**self._sign)
 
+    # Note: The Decimal standard doesn't cover rich comparisons for
+    # Decimals.  In particular, the specification is silent on the
+    # subject of what should happen for a comparison involving a NaN.
+    # We take the following approach:
+    #
+    #   == comparisons involving a NaN always return False
+    #   != comparisons involving a NaN always return True
+    #   <, >, <= and >= comparisons involving a (quiet or signaling)
+    #      NaN signal InvalidOperation, and return False if the
+    #      InvalidOperation is not trapped.
+    #
+    # This behavior is designed to conform as closely as possible to
+    # that specified by IEEE 754.
+
     def __eq__(self, other):
-        if not isinstance(other, (Decimal, int)):
-            return NotImplemented
-        return self.__cmp__(other) == 0
+        other = _convert_other(other)
+        if other is NotImplemented:
+            return other
+        if self.is_nan() or other.is_nan():
+            return False
+        return self._cmp(other) == 0
 
     def __ne__(self, other):
-        if not isinstance(other, (Decimal, int)):
-            return NotImplemented
-        return self.__cmp__(other) != 0
+        other = _convert_other(other)
+        if other is NotImplemented:
+            return other
+        if self.is_nan() or other.is_nan():
+            return True
+        return self._cmp(other) != 0
 
-    def __lt__(self, other):
-        if not isinstance(other, (Decimal, int)):
-            return NotImplemented
-        return self.__cmp__(other) < 0
 
-    def __le__(self, other):
-        if not isinstance(other, (Decimal, int)):
-            return NotImplemented
-        return self.__cmp__(other) <= 0
+    def __lt__(self, other, context=None):
+        other = _convert_other(other)
+        if other is NotImplemented:
+            return other
+        ans = self._compare_check_nans(other, context)
+        if ans:
+            return False
+        return self._cmp(other) < 0
 
-    def __gt__(self, other):
-        if not isinstance(other, (Decimal, int)):
-            return NotImplemented
-        return self.__cmp__(other) > 0
+    def __le__(self, other, context=None):
+        other = _convert_other(other)
+        if other is NotImplemented:
+            return other
+        ans = self._compare_check_nans(other, context)
+        if ans:
+            return False
+        return self._cmp(other) <= 0
 
-    def __ge__(self, other):
-        if not isinstance(other, (Decimal, int)):
-            return NotImplemented
-        return self.__cmp__(other) >= 0
+    def __gt__(self, other, context=None):
+        other = _convert_other(other)
+        if other is NotImplemented:
+            return other
+        ans = self._compare_check_nans(other, context)
+        if ans:
+            return False
+        return self._cmp(other) > 0
+
+    def __ge__(self, other, context=None):
+        other = _convert_other(other)
+        if other is NotImplemented:
+            return other
+        ans = self._compare_check_nans(other, context)
+        if ans:
+            return False
+        return self._cmp(other) >= 0
 
     def compare(self, other, context=None):
         """Compares one to another.
@@ -775,13 +877,15 @@
             if ans:
                 return ans
 
-        return Decimal(self.__cmp__(other))
+        return Decimal(self._cmp(other))
 
     def __hash__(self):
         """x.__hash__() <==> hash(x)"""
         # Decimal integers must hash the same as the ints
-        # Non-integer decimals are normalized and hashed as strings
-        # Normalization assures that hash(100E-1) == hash(10)
+        #
+        # The hash of a nonspecial noninteger Decimal must depend only
+        # on the value of that Decimal, and not on its representation.
+        # For example: hash(Decimal('100E-1')) == hash(Decimal('10')).
         if self._is_special:
             if self._isnan():
                 raise TypeError('Cannot hash a NaN value.')
@@ -797,19 +901,25 @@
             # 2**64-1.  So we can replace hash((-1)**s*c*10**e) with
             # hash((-1)**s*c*pow(10, e, 2**64-1).
             return hash((-1)**op.sign*op.int*pow(10, op.exp, 2**64-1))
-        return hash(str(self.normalize()))
+        # The value of a nonzero nonspecial Decimal instance is
+        # faithfully represented by the triple consisting of its sign,
+        # its adjusted exponent, and its coefficient with trailing
+        # zeros removed.
+        return hash((self._sign,
+                     self._exp+len(self._int),
+                     self._int.rstrip('0')))
 
     def as_tuple(self):
         """Represents the number as a triple tuple.
 
         To show the internals exactly as they are.
         """
-        return (self._sign, self._int, self._exp)
+        return DecimalTuple(self._sign, tuple(map(int, self._int)), self._exp)
 
     def __repr__(self):
         """Represents the number as an instance of Decimal."""
         # Invariant:  eval(repr(d)) == d
-        return 'Decimal("%s")' % str(self)
+        return "Decimal('%s')" % str(self)
 
     def __str__(self, eng=False, context=None):
         """Return string representation of the number in scientific notation.
@@ -817,81 +927,51 @@
         Captures all of the information in the underlying representation.
         """
 
+        sign = ['', '-'][self._sign]
         if self._is_special:
-            if self._isnan():
-                minus = '-'*self._sign
-                if self._int == (0,):
-                    info = ''
-                else:
-                    info = ''.join(map(str, self._int))
-                if self._isnan() == 2:
-                    return minus + 'sNaN' + info
-                return minus + 'NaN' + info
-            if self._isinfinity():
-                minus = '-'*self._sign
-                return minus + 'Infinity'
-
-        if context is None:
-            context = getcontext()
-
-        tmp = list(map(str, self._int))
-        numdigits = len(self._int)
-        leftdigits = self._exp + numdigits
-        if eng and not self:  # self = 0eX wants 0[.0[0]]eY, not [[0]0]0eY
-            if self._exp < 0 and self._exp >= -6:  # short, no need for e/E
-                s = '-'*self._sign + '0.' + '0'*(abs(self._exp))
-                return s
-            # exp is closest mult. of 3 >= self._exp
-            exp = ((self._exp - 1)// 3 + 1) * 3
-            if exp != self._exp:
-                s = '0.'+'0'*(exp - self._exp)
-            else:
-                s = '0'
-            if exp != 0:
-                if context.capitals:
-                    s += 'E'
-                else:
-                    s += 'e'
-                if exp > 0:
-                    s += '+'  # 0.0e+3, not 0.0e3
-                s += str(exp)
-            s = '-'*self._sign + s
-            return s
-        if eng:
-            dotplace = (leftdigits-1)%3+1
-            adjexp = leftdigits -1 - (leftdigits-1)%3
-        else:
-            adjexp = leftdigits-1
+            if self._exp == 'F':
+                return sign + 'Infinity'
+            elif self._exp == 'n':
+                return sign + 'NaN' + self._int
+            else: # self._exp == 'N'
+                return sign + 'sNaN' + self._int
+
+        # number of digits of self._int to left of decimal point
+        leftdigits = self._exp + len(self._int)
+
+        # dotplace is number of digits of self._int to the left of the
+        # decimal point in the mantissa of the output string (that is,
+        # after adjusting the exponent)
+        if self._exp <= 0 and leftdigits > -6:
+            # no exponent required
+            dotplace = leftdigits
+        elif not eng:
+            # usual scientific notation: 1 digit on left of the point
             dotplace = 1
-        if self._exp == 0:
-            pass
-        elif self._exp < 0 and adjexp >= 0:
-            tmp.insert(leftdigits, '.')
-        elif self._exp < 0 and adjexp >= -6:
-            tmp[0:0] = ['0'] * int(-leftdigits)
-            tmp.insert(0, '0.')
-        else:
-            if numdigits > dotplace:
-                tmp.insert(dotplace, '.')
-            elif numdigits < dotplace:
-                tmp.extend(['0']*(dotplace-numdigits))
-            if adjexp:
-                if not context.capitals:
-                    tmp.append('e')
-                else:
-                    tmp.append('E')
-                    if adjexp > 0:
-                        tmp.append('+')
-                tmp.append(str(adjexp))
-        if eng:
-            while tmp[0:1] == ['0']:
-                tmp[0:1] = []
-            if len(tmp) == 0 or tmp[0] == '.' or tmp[0].lower() == 'e':
-                tmp[0:0] = ['0']
-        if self._sign:
-            tmp.insert(0, '-')
+        elif self._int == '0':
+            # engineering notation, zero
+            dotplace = (leftdigits + 1) % 3 - 1
+        else:
+            # engineering notation, nonzero
+            dotplace = (leftdigits - 1) % 3 + 1
+
+        if dotplace <= 0:
+            intpart = '0'
+            fracpart = '.' + '0'*(-dotplace) + self._int
+        elif dotplace >= len(self._int):
+            intpart = self._int+'0'*(dotplace-len(self._int))
+            fracpart = ''
+        else:
+            intpart = self._int[:dotplace]
+            fracpart = '.' + self._int[dotplace:]
+        if leftdigits == dotplace:
+            exp = ''
+        else:
+            if context is None:
+                context = getcontext()
+            exp = ['e', 'E'][context.capitals] + "%+d" % (leftdigits-dotplace)
 
-        return ''.join(tmp)
+        return sign + intpart + fracpart + exp
 
     def to_eng_string(self, context=None):
         """Convert to engineering-type string.
@@ -915,15 +995,13 @@
 
         if not self:
             # -Decimal('0') is Decimal('0'), not Decimal('-0')
-            ans = self.copy_sign(Dec_0)
+            ans = self.copy_abs()
         else:
             ans = self.copy_negate()
 
         if context is None:
             context = getcontext()
-        if context._rounding_decision == ALWAYS_ROUND:
-            return ans._fix(context)
-        return ans
+        return ans._fix(context)
 
     def __pos__(self, context=None):
         """Returns a copy, unless it is a sNaN.
@@ -937,32 +1015,29 @@
 
         if not self:
             # + (-0) = 0
-            ans = self.copy_sign(Dec_0)
+            ans = self.copy_abs()
         else:
             ans = Decimal(self)
 
         if context is None:
             context = getcontext()
-        if context._rounding_decision == ALWAYS_ROUND:
-            return ans._fix(context)
-        return ans
+        return ans._fix(context)
 
-    def __abs__(self, round=1, context=None):
+    def __abs__(self, round=True, context=None):
         """Returns the absolute value of self.
 
-        If the second argument is 0, do not round.
+        If the keyword argument 'round' is false, do not round.  The
+        expression self.__abs__(round=False) is equivalent to
+        self.copy_abs().
         """
+        if not round:
+            return self.copy_abs()
+
         if self._is_special:
             ans = self._check_nans(context=context)
             if ans:
                 return ans
 
-        if not round:
-            if context is None:
-                context = getcontext()
-            context = context._shallow_copy()
-            context._set_rounding_decision(NEVER_ROUND)
-
         if self._sign:
             ans = self.__neg__(context=context)
         else:
@@ -995,8 +1070,6 @@
             if other._isinfinity():
                 return Decimal(other)  # Can't both be infinity here
 
-        shouldround = context._rounding_decision == ALWAYS_ROUND
-
         exp = min(self._exp, other._exp)
         negativezero = 0
         if context.rounding == ROUND_FLOOR and self._sign != other._sign:
@@ -1007,34 +1080,30 @@
             sign = min(self._sign, other._sign)
             if negativezero:
                 sign = 1
-            ans = Decimal( (sign, (0,), exp))
-            if shouldround:
-                ans = ans._fix(context)
+            ans = _dec_from_triple(sign, '0', exp)
+            ans = ans._fix(context)
             return ans
         if not self:
             exp = max(exp, other._exp - context.prec-1)
             ans = other._rescale(exp, context.rounding)
-            if shouldround:
-                ans = ans._fix(context)
+            ans = ans._fix(context)
             return ans
         if not other:
             exp = max(exp, self._exp - context.prec-1)
             ans = self._rescale(exp, context.rounding)
-            if shouldround:
-                ans = ans._fix(context)
+            ans = ans._fix(context)
             return ans
 
         op1 = _WorkRep(self)
         op2 = _WorkRep(other)
-        op1, op2 = _normalize(op1, op2, shouldround, context.prec)
+        op1, op2 = _normalize(op1, op2, context.prec)
 
         result = _WorkRep()
         if op1.sign != op2.sign:
             # Equal and opposite
             if op1.int == op2.int:
-                ans = Decimal((negativezero, (0,), exp))
-                if shouldround:
-                    ans = ans._fix(context)
+                ans = _dec_from_triple(negativezero, '0', exp)
+                ans = ans._fix(context)
                 return ans
             if op1.int < op2.int:
                 op1, op2 = op2, op1
@@ -1059,8 +1128,7 @@
 
         result.exp = op1.exp
         ans = Decimal(result)
-        if shouldround:
-            ans = ans._fix(context)
+        ans = ans._fix(context)
         return ans
 
     __radd__ = __add__
@@ -1087,29 +1155,6 @@
 
         return other.__sub__(self, context=context)
 
-    def _increment(self):
-        """Special case of add, adding 1eExponent
-
-        Since it is common, (rounding, for example) this adds
-        (sign)*one E self._exp to the number more efficiently than add.
-
-        Assumes that self is nonspecial.
-
-        For example:
-        Decimal('5.624e10')._increment() == Decimal('5.625e10')
-        """
-        L = list(self._int)
-        L[-1] += 1
-        spot = len(L)-1
-        while L[spot] == 10:
-            L[spot] = 0
-            if spot == 0:
-                L[0:0] = [1]
-                break
-            L[spot-1] += 1
-            spot -= 1
-        return Decimal((self._sign, L, self._exp))
-
     def __mul__(self, other, context=None):
         """Return self * other.
 
@@ -1140,36 +1185,29 @@
                 return Infsign[resultsign]
 
         resultexp = self._exp + other._exp
-        shouldround = context._rounding_decision == ALWAYS_ROUND
 
         # Special case for multiplying by zero
         if not self or not other:
-            ans = Decimal((resultsign, (0,), resultexp))
-            if shouldround:
-                # Fixing in case the exponent is out of bounds
-                ans = ans._fix(context)
+            ans = _dec_from_triple(resultsign, '0', resultexp)
+            # Fixing in case the exponent is out of bounds
+            ans = ans._fix(context)
             return ans
 
         # Special case for multiplying by power of 10
-        if self._int == (1,):
-            ans = Decimal((resultsign, other._int, resultexp))
-            if shouldround:
-                ans = ans._fix(context)
+        if self._int == '1':
+            ans = _dec_from_triple(resultsign, other._int, resultexp)
+            ans = ans._fix(context)
             return ans
-        if other._int == (1,):
-            ans = Decimal((resultsign, self._int, resultexp))
-            if shouldround:
-                ans = ans._fix(context)
+        if other._int == '1':
+            ans = _dec_from_triple(resultsign, self._int, resultexp)
+            ans = ans._fix(context)
             return ans
 
         op1 = _WorkRep(self)
         op2 = _WorkRep(other)
 
-        ans = Decimal((resultsign,
-                       tuple(map(int, str(op1.int * op2.int))),
-                       resultexp))
-        if shouldround:
-            ans = ans._fix(context)
+        ans = _dec_from_triple(resultsign, str(op1.int * op2.int), resultexp)
+        ans = ans._fix(context)
 
         return ans
     __rmul__ = __mul__
@@ -1198,7 +1236,7 @@
 
             if other._isinfinity():
                 context._raise_error(Clamped, 'Division by infinity')
-                return Decimal((sign, (0,), context.Etiny()))
+                return _dec_from_triple(sign, '0', context.Etiny())
 
         # Special cases for zeroes
         if not other:
@@ -1230,7 +1268,7 @@
                     coeff //= 10
                     exp += 1
 
-        ans = Decimal((sign, list(map(int, str(coeff))), exp))
+        ans = _dec_from_triple(sign, str(coeff), exp)
         return ans._fix(context)
 
     def _divide(self, other, context):
@@ -1247,7 +1285,7 @@
 
         expdiff = self.adjusted() - other.adjusted()
         if not self or other._isinfinity() or expdiff <= -2:
-            return (Decimal((sign, (0,), 0)),
+            return (_dec_from_triple(sign, '0', 0),
                     self._rescale(ideal_exp, context.rounding))
         if expdiff <= context.prec:
             op1 = _WorkRep(self)
@@ -1258,9 +1296,8 @@
                 op2.int *= 10**(op2.exp - op1.exp)
             q, r = divmod(op1.int, op2.int)
             if q < 10**context.prec:
-                return (Decimal((sign, list(map(int, str(q))), 0)),
-                        Decimal((self._sign, list(map(int, str(r))),
-                                ideal_exp)))
+                return (_dec_from_triple(sign, str(q), 0),
+                        _dec_from_triple(self._sign, str(r), ideal_exp))
 
         # Here the quotient is too large to be representable
         ans = context._raise_error(DivisionImpossible,
@@ -1307,8 +1344,7 @@
                         context._raise_error(InvalidOperation, 'x % 0'))
 
         quotient, remainder = self._divide(other, context)
-        if context._rounding_decision == ALWAYS_ROUND:
-            remainder = remainder._fix(context)
+        remainder = remainder._fix(context)
         return quotient, remainder
 
     def __rdivmod__(self, other, context=None):
@@ -1342,8 +1378,7 @@
                 return context._raise_error(DivisionUndefined, '0 % 0')
 
         remainder = self._divide(other, context)[1]
-        if context._rounding_decision == ALWAYS_ROUND:
-            remainder = remainder._fix(context)
+        remainder = remainder._fix(context)
         return remainder
 
     def __rmod__(self, other, context=None):
@@ -1388,7 +1423,7 @@
         # self = 0 -> remainder = self, with ideal exponent
         ideal_exponent = min(self._exp, other._exp)
         if not self:
-            ans = Decimal((self._sign, (0,), ideal_exponent))
+            ans = _dec_from_triple(self._sign, '0', ideal_exponent)
             return ans._fix(context)
 
         # catch most cases of large or small quotient
@@ -1425,7 +1460,7 @@
             sign = 1-sign
             r = -r
 
-        ans = Decimal((sign, list(map(int, str(r))), ideal_exponent))
+        ans = _dec_from_triple(sign, str(r), ideal_exponent)
         return ans._fix(context)
 
     def __floordiv__(self, other, context=None):
@@ -1477,9 +1512,25 @@
                 raise OverflowError("Cannot convert infinity to int")
         s = (-1)**self._sign
         if self._exp >= 0:
-            return s*int(''.join(map(str, self._int)))*10**self._exp
+            return s*int(self._int)*10**self._exp
         else:
-            return s*int(''.join(map(str, self._int))[:self._exp] or '0')
+            return s*int(self._int[:self._exp] or '0')
+
+    __trunc__ = __int__
+
+    @property
+    def real(self):
+        return self
+
+    @property
+    def imag(self):
+        return Decimal(0)
+
+    def conjugate(self):
+        return self
+
+    def __complex__(self):
+        return complex(float(self))
 
     def _fix_nan(self, context):
         """Decapitate the payload of a NaN to fit the context"""
@@ -1489,11 +1540,8 @@
         # precision-1 if _clamp=1.
         max_payload_len = context.prec - context._clamp
         if len(payload) > max_payload_len:
-            pos = len(payload)-max_payload_len
-            while pos < len(payload) and payload[pos] == 0:
-                pos += 1
-            payload = payload[pos:]
-            return Decimal((self._sign, payload, self._exp))
+            payload = payload[len(payload)-max_payload_len:].lstrip('0')
+            return _dec_from_triple(self._sign, payload, self._exp, True)
         return Decimal(self)
 
     def _fix(self, context):
@@ -1506,9 +1554,6 @@
         context - context used.
         """
 
-        if context is None:
-            context = getcontext()
-
         if self._is_special:
             if self._isnan():
                 # decapitate payload if necessary
@@ -1526,7 +1571,7 @@
             new_exp = min(max(self._exp, Etiny), exp_max)
             if new_exp != self._exp:
                 context._raise_error(Clamped)
-                return Decimal((self._sign, (0,), new_exp))
+                return _dec_from_triple(self._sign, '0', new_exp)
             else:
                 return Decimal(self)
 
@@ -1546,8 +1591,18 @@
         # round if self has too many digits
         if self._exp < exp_min:
             context._raise_error(Rounded)
-            ans = self._rescale(exp_min, context.rounding)
-            if ans != self:
+            digits = len(self._int) + self._exp - exp_min
+            if digits < 0:
+                self = _dec_from_triple(self._sign, '1', exp_min-1)
+                digits = 0
+            this_function = getattr(self, self._pick_rounding_function[context.rounding])
+            changed = this_function(digits)
+            coeff = self._int[:digits] or '0'
+            if changed == 1:
+                coeff = str(int(coeff)+1)
+            ans = _dec_from_triple(self._sign, coeff, exp_min)
+
+            if changed:
                 context._raise_error(Inexact)
                 if self_is_subnormal:
                     context._raise_error(Underflow)
@@ -1558,7 +1613,8 @@
                     # we get here only if rescaling rounds the
                     # cofficient up to exactly 10**context.prec
                     if ans._exp < Etop:
-                        ans = Decimal((ans._sign, ans._int[:-1], ans._exp+1))
+                        ans = _dec_from_triple(ans._sign,
+                                                   ans._int[:-1], ans._exp+1)
                     else:
                         # Inexact and Rounded have already been raised
                         ans = context._raise_error(Overflow, 'above Emax',
@@ -1568,8 +1624,8 @@
         # fold down if _clamp == 1 and self has too few digits
         if context._clamp == 1 and self._exp > Etop:
             context._raise_error(Clamped)
-            self_padded = self._int + (0,)*(self._exp - Etop)
-            return Decimal((self._sign, self_padded, Etop))
+            self_padded = self._int + '0'*(self._exp - Etop)
+            return _dec_from_triple(self._sign, self_padded, Etop)
 
         # here self was representable to begin with; return unchanged
         return Decimal(self)
@@ -1579,66 +1635,77 @@
     # for each of the rounding functions below:
     #   self is a finite, nonzero Decimal
     #   prec is an integer satisfying 0 <= prec < len(self._int)
-    # the rounded result will have exponent self._exp + len(self._int) - prec;
+    #
+    # each function returns either -1, 0, or 1, as follows:
+    #   1 indicates that self should be rounded up (away from zero)
+    #   0 indicates that self should be truncated, and that all the
+    #     digits to be truncated are zeros (so the value is unchanged)
+    #  -1 indicates that there are nonzero digits to be truncated
 
     def _round_down(self, prec):
         """Also known as round-towards-0, truncate."""
-        newexp = self._exp + len(self._int) - prec
-        return Decimal((self._sign, self._int[:prec] or (0,), newexp))
+        if _all_zeros(self._int, prec):
+            return 0
+        else:
+            return -1
+
+    def __round__(self):
+        return self._round_down(0)
 
     def _round_up(self, prec):
         """Rounds away from 0."""
-        newexp = self._exp + len(self._int) - prec
-        tmp = Decimal((self._sign, self._int[:prec] or (0,), newexp))
-        for digit in self._int[prec:]:
-            if digit != 0:
-                return tmp._increment()
-        return tmp
+        return -self._round_down(prec)
 
     def _round_half_up(self, prec):
         """Rounds 5 up (away from 0)"""
-        if self._int[prec] >= 5:
-            return self._round_up(prec)
+        if self._int[prec] in '56789':
+            return 1
+        elif _all_zeros(self._int, prec):
+            return 0
         else:
-            return self._round_down(prec)
+            return -1
 
     def _round_half_down(self, prec):
         """Round 5 down"""
-        if self._int[prec] == 5:
-            for digit in self._int[prec+1:]:
-                if digit != 0:
-                    break
-            else:
-                return self._round_down(prec)
-        return self._round_half_up(prec)
+        if _exact_half(self._int, prec):
+            return -1
+        else:
+            return self._round_half_up(prec)
 
     def _round_half_even(self, prec):
         """Round 5 to even, rest to nearest."""
-        if prec and self._int[prec-1] & 1:
-            return self._round_half_up(prec)
+        if _exact_half(self._int, prec) and \
+                (prec == 0 or self._int[prec-1] in '02468'):
+            return -1
         else:
-            return self._round_half_down(prec)
+            return self._round_half_up(prec)
 
     def _round_ceiling(self, prec):
         """Rounds up (not away from 0 if negative.)"""
         if self._sign:
             return self._round_down(prec)
         else:
-            return self._round_up(prec)
+            return -self._round_down(prec)
+
+    def __ceil__(self):
+        return self._round_ceiling(0)
 
     def _round_floor(self, prec):
         """Rounds down (not towards 0 if negative)"""
         if not self._sign:
             return self._round_down(prec)
         else:
-            return self._round_up(prec)
+            return -self._round_down(prec)
+
+    def __floor__(self):
+        return self._round_floor(0)
 
     def _round_05up(self, prec):
         """Round down unless digit prec-1 is 0 or 5."""
-        if prec == 0 or self._int[prec-1] in (0, 5):
-            return self._round_up(prec)
-        else:
+        if prec and self._int[prec-1] not in '05':
             return self._round_down(prec)
+        else:
+            return -self._round_down(prec)
 
     def fma(self, other, third, context=None):
         """Fused multiply-add.
@@ -1652,24 +1719,37 @@
         """
 
         other = _convert_other(other, raiseit=True)
-        third = _convert_other(third, raiseit=True)
-
-        if context is None:
-            context = getcontext()
 
-        # do self*other in fresh context with no traps and no rounding
-        mul_context = Context(traps=[], flags=[],
-                              _rounding_decision=NEVER_ROUND)
-        product = self.__mul__(other, mul_context)
-
-        if mul_context.flags[InvalidOperation]:
-            # reraise in current context
-            return context._raise_error(InvalidOperation,
-                                        'invalid multiplication in fma',
-                                        1, product)
+        # compute product; raise InvalidOperation if either operand is
+        # a signaling NaN or if the product is zero times infinity.
+        if self._is_special or other._is_special:
+            if context is None:
+                context = getcontext()
+            if self._exp == 'N':
+                return context._raise_error(InvalidOperation, 'sNaN', self)
+            if other._exp == 'N':
+                return context._raise_error(InvalidOperation, 'sNaN', other)
+            if self._exp == 'n':
+                product = self
+            elif other._exp == 'n':
+                product = other
+            elif self._exp == 'F':
+                if not other:
+                    return context._raise_error(InvalidOperation,
+                                                'INF * 0 in fma')
+                product = Infsign[self._sign ^ other._sign]
+            elif other._exp == 'F':
+                if not self:
+                    return context._raise_error(InvalidOperation,
+                                                '0 * INF in fma')
+                product = Infsign[self._sign ^ other._sign]
+        else:
+            product = _dec_from_triple(self._sign ^ other._sign,
+                                       str(int(self._int) * int(other._int)),
+                                       self._exp + other._exp)
 
-        ans = product.__add__(third, context)
-        return ans
+        third = _convert_other(third, raiseit=True)
+        return product.__add__(third, context)
 
     def _power_modulo(self, other, modulo, context=None):
         """Three argument version of __pow__"""
@@ -1691,13 +1771,13 @@
         if self_is_nan or other_is_nan or modulo_is_nan:
             if self_is_nan == 2:
                 return context._raise_error(InvalidOperation, 'sNaN',
-                                        1, self)
+                                        self)
             if other_is_nan == 2:
                 return context._raise_error(InvalidOperation, 'sNaN',
-                                        1, other)
+                                        other)
             if modulo_is_nan == 2:
                 return context._raise_error(InvalidOperation, 'sNaN',
-                                        1, modulo)
+                                        modulo)
             if self_is_nan:
                 return self._fix_nan(context)
             if other_is_nan:
@@ -1753,7 +1833,7 @@
             base = pow(base, 10, modulo)
         base = pow(base, exponent.int, modulo)
 
-        return Decimal((sign, list(map(int, str(base))), 0))
+        return _dec_from_triple(sign, str(base), 0)
 
     def _power_exact(self, other, p):
         """Attempt to compute self**other exactly.
@@ -1843,7 +1923,7 @@
                 zeros = min(exponent-ideal_exponent, p-1)
             else:
                 zeros = 0
-            return Decimal((0, (1,) + (0,)*zeros, exponent-zeros))
+            return _dec_from_triple(0, '1' + '0'*zeros, exponent-zeros)
 
         # case where y is negative: xc must be either a power
         # of 2 or a power of 5.
@@ -1904,7 +1984,7 @@
             if xc >= 10**p:
                 return None
             xe = -e-xe
-            return Decimal((0, list(map(int, str(xc))), xe))
+            return _dec_from_triple(0, str(xc), xe)
 
         # now y is positive; find m and n such that y = m/n
         if ye >= 0:
@@ -1966,7 +2046,7 @@
             zeros = min(xe-ideal_exponent, p-len(str_xc))
         else:
             zeros = 0
-        return Decimal((0, list(map(int, str_xc))+[0,]*zeros, xe-zeros))
+        return _dec_from_triple(0, str_xc+'0'*zeros, xe-zeros)
 
     def __pow__(self, other, modulo=None, context=None):
         """Return self ** other [ % modulo].
@@ -2027,12 +2107,12 @@
                     return context._raise_error(InvalidOperation,
                         'x ** y with x negative and y not an integer')
             # negate self, without doing any unwanted rounding
-            self = Decimal((0, self._int, self._exp))
+            self = self.copy_negate()
 
         # 0**(+ve or Inf)= 0; 0**(-ve or -Inf) = Infinity
         if not self:
             if other._sign == 0:
-                return Decimal((result_sign, (0,), 0))
+                return _dec_from_triple(result_sign, '0', 0)
             else:
                 return Infsign[result_sign]
 
@@ -2041,7 +2121,7 @@
             if other._sign == 0:
                 return Infsign[result_sign]
             else:
-                return Decimal((result_sign, (0,), 0))
+                return _dec_from_triple(result_sign, '0', 0)
 
         # 1**other = 1, but the choice of exponent and the flags
         # depend on the exponent of self, and on whether other is a
@@ -2068,7 +2148,7 @@
                 context._raise_error(Rounded)
                 exp = 1-context.prec
 
-            return Decimal((result_sign, (1,)+(0,)*-exp, exp))
+            return _dec_from_triple(result_sign, '1'+'0'*-exp, exp)
 
         # compute adjusted exponent of self
         self_adj = self.adjusted()
@@ -2077,7 +2157,7 @@
         # self ** -infinity is infinity if self < 1, 0 if self > 1
         if other._isinfinity():
             if (other._sign == 0) == (self_adj < 0):
-                return Decimal((result_sign, (0,), 0))
+                return _dec_from_triple(result_sign, '0', 0)
             else:
                 return Infsign[result_sign]
 
@@ -2095,19 +2175,19 @@
             # self > 1 and other +ve, or self < 1 and other -ve
             # possibility of overflow
             if bound >= len(str(context.Emax)):
-                ans = Decimal((result_sign, (1,), context.Emax+1))
+                ans = _dec_from_triple(result_sign, '1', context.Emax+1)
         else:
             # self > 1 and other -ve, or self < 1 and other +ve
             # possibility of underflow to 0
             Etiny = context.Etiny()
             if bound >= len(str(-Etiny)):
-                ans = Decimal((result_sign, (1,), Etiny-1))
+                ans = _dec_from_triple(result_sign, '1', Etiny-1)
 
         # try for an exact result with precision +1
         if ans is None:
             ans = self._power_exact(other, context.prec + 1)
             if ans is not None and result_sign == 1:
-                ans = Decimal((1, ans._int, ans._exp))
+                ans = _dec_from_triple(1, ans._int, ans._exp)
 
         # usual case: inexact result, x**y computed directly as exp(y*log(x))
         if ans is None:
@@ -2128,7 +2208,7 @@
                     break
                 extra += 3
 
-            ans = Decimal((result_sign, list(map(int, str(coeff))), exp))
+            ans = _dec_from_triple(result_sign, str(coeff), exp)
 
         # the specification says that for non-integer other we need to
         # raise Inexact, even when the result is actually exact.  In
@@ -2140,7 +2220,8 @@
             # pad with zeros up to length context.prec+1 if necessary
             if len(ans._int) <= context.prec:
                 expdiff = context.prec+1 - len(ans._int)
-                ans = Decimal((ans._sign, ans._int+(0,)*expdiff, ans._exp-expdiff))
+                ans = _dec_from_triple(ans._sign, ans._int+'0'*expdiff,
+                                       ans._exp-expdiff)
             if ans.adjusted() < context.Emin:
                 context._raise_error(Underflow)
 
@@ -2172,14 +2253,14 @@
             return dup
 
         if not dup:
-            return Decimal( (dup._sign, (0,), 0) )
+            return _dec_from_triple(dup._sign, '0', 0)
         exp_max = [context.Emax, context.Etop()][context._clamp]
         end = len(dup._int)
         exp = dup._exp
-        while dup._int[end-1] == 0 and exp < exp_max:
+        while dup._int[end-1] == '0' and exp < exp_max:
             exp += 1
             end -= 1
-        return Decimal( (dup._sign, dup._int[:end], exp) )
+        return _dec_from_triple(dup._sign, dup._int[:end], exp)
 
     def quantize(self, exp, rounding=None, context=None, watchexp=True):
         """Quantize self so its exponent is the same as that of exp.
@@ -2220,7 +2301,7 @@
                    'target exponent out of bounds in quantize')
 
         if not self:
-            ans = Decimal((self._sign, (0,), exp._exp))
+            ans = _dec_from_triple(self._sign, '0', exp._exp)
             return ans._fix(context)
 
         self_adjusted = self.adjusted()
@@ -2252,15 +2333,18 @@
         return ans
 
     def same_quantum(self, other):
-        """Test whether self and other have the same exponent.
+        """Return True if self and other have the same exponent; otherwise
+        return False.
 
-        same as self._exp == other._exp, except NaN == sNaN
+        If either operand is a special value, the following rules are used:
+           * return True if both operands are infinities
+           * return True if both operands are NaNs
+           * otherwise, return False.
         """
+        other = _convert_other(other, raiseit=True)
         if self._is_special or other._is_special:
-            if self._isnan() or other._isnan():
-                return self._isnan() and other._isnan() and True
-            if self._isinfinity() or other._isinfinity():
-                return self._isinfinity() and other._isinfinity() and True
+            return (self.is_nan() and other.is_nan() or
+                    self.is_infinite() and other.is_infinite())
         return self._exp == other._exp
 
     def _rescale(self, exp, rounding):
@@ -2277,20 +2361,48 @@
         if self._is_special:
             return Decimal(self)
         if not self:
-            return Decimal((self._sign, (0,), exp))
+            return _dec_from_triple(self._sign, '0', exp)
 
         if self._exp >= exp:
             # pad answer with zeros if necessary
-            return Decimal((self._sign, self._int + (0,)*(self._exp - exp), exp))
+            return _dec_from_triple(self._sign,
+                                        self._int + '0'*(self._exp - exp), exp)
 
         # too many digits; round and lose data.  If self.adjusted() <
         # exp-1, replace self by 10**(exp-1) before rounding
         digits = len(self._int) + self._exp - exp
         if digits < 0:
-            self = Decimal((self._sign, (1,), exp-1))
+            self = _dec_from_triple(self._sign, '1', exp-1)
             digits = 0
         this_function = getattr(self, self._pick_rounding_function[rounding])
-        return this_function(digits)
+        changed = this_function(digits)
+        coeff = self._int[:digits] or '0'
+        if changed == 1:
+            coeff = str(int(coeff)+1)
+        return _dec_from_triple(self._sign, coeff, exp)
+
+    def _round(self, places, rounding):
+        """Round a nonzero, nonspecial Decimal to a fixed number of
+        significant figures, using the given rounding mode.
+
+        Infinities, NaNs and zeros are returned unaltered.
+
+        This operation is quiet: it raises no flags, and uses no
+        information from the context.
+
+        """
+        if places <= 0:
+            raise ValueError("argument should be at least 1 in _round")
+        if self._is_special or not self:
+            return Decimal(self)
+        ans = self._rescale(self.adjusted()+1-places, rounding)
+        # it can happen that the rescale alters the adjusted exponent;
+        # for example when rounding 99.97 to 3 significant figures.
+        # When this happens we end up with an extra 0 at the end of
+        # the number; a second rescale fixes this.
+        if ans.adjusted() != self.adjusted():
+            ans = ans._rescale(ans.adjusted()+1-places, rounding)
+        return ans
 
     def to_integral_exact(self, rounding=None, context=None):
         """Rounds to a nearby integer.
@@ -2310,7 +2422,7 @@
         if self._exp >= 0:
             return Decimal(self)
         if not self:
-            return Decimal((self._sign, (0,), 0))
+            return _dec_from_triple(self._sign, '0', 0)
         if context is None:
             context = getcontext()
         if rounding is None:
@@ -2352,7 +2464,7 @@
 
         if not self:
             # exponent = self._exp // 2.  sqrt(-0) = -0
-            ans = Decimal((self._sign, (0,), self._exp // 2))
+            ans = _dec_from_triple(self._sign, '0', self._exp // 2)
             return ans._fix(context)
 
         if context is None:
@@ -2429,7 +2541,7 @@
             if n % 5 == 0:
                 n += 1
 
-        ans = Decimal((0, list(map(int, str(n))), e))
+        ans = _dec_from_triple(0, str(n), e)
 
         # round, and fit to current context
         context = context._shallow_copy()
@@ -2462,7 +2574,7 @@
                     return other._fix_nan(context)
                 return self._check_nans(other, context)
 
-        c = self.__cmp__(other)
+        c = self._cmp(other)
         if c == 0:
             # If both operands are finite and equal in numerical value
             # then an ordering is applied:
@@ -2479,9 +2591,7 @@
         else:
             ans = self
 
-        if context._rounding_decision == ALWAYS_ROUND:
-            return ans._fix(context)
-        return ans
+        return ans._fix(context)
 
     def min(self, other, context=None):
         """Returns the smaller value.
@@ -2506,7 +2616,7 @@
                     return other._fix_nan(context)
                 return self._check_nans(other, context)
 
-        c = self.__cmp__(other)
+        c = self._cmp(other)
         if c == 0:
             c = self.compare_total(other)
 
@@ -2515,9 +2625,7 @@
         else:
             ans = other
 
-        if context._rounding_decision == ALWAYS_ROUND:
-            return ans._fix(context)
-        return ans
+        return ans._fix(context)
 
     def _isinteger(self):
         """Returns whether self is an integer"""
@@ -2526,13 +2634,13 @@
         if self._exp >= 0:
             return True
         rest = self._int[self._exp:]
-        return rest == (0,)*len(rest)
+        return rest == '0'*len(rest)
 
     def _iseven(self):
         """Returns True if self is even.  Assumes self is an integer."""
         if not self or self._exp > 0:
             return True
-        return self._int[-1+self._exp] & 1 == 0
+        return self._int[-1+self._exp] in '02468'
 
     def adjusted(self):
         """Return the adjusted exponent of self"""
@@ -2556,23 +2664,10 @@
         It's pretty much like compare(), but all NaNs signal, with signaling
         NaNs taking precedence over quiet NaNs.
         """
-        if context is None:
-            context = getcontext()
-
-        self_is_nan = self._isnan()
-        other_is_nan = other._isnan()
-        if self_is_nan == 2:
-            return context._raise_error(InvalidOperation, 'sNaN',
-                                        1, self)
-        if other_is_nan == 2:
-            return context._raise_error(InvalidOperation, 'sNaN',
-                                        1, other)
-        if self_is_nan:
-            return context._raise_error(InvalidOperation, 'NaN in compare_signal',
-                                        1, self)
-        if other_is_nan:
-            return context._raise_error(InvalidOperation, 'NaN in compare_signal',
-                                        1, other)
+        other = _convert_other(other, raiseit = True)
+        ans = self._compare_check_nans(other, context)
+        if ans:
+            return ans
         return self.compare(other, context=context)
 
     def compare_total(self, other):
@@ -2654,18 +2749,19 @@
 
     def copy_abs(self):
         """Returns a copy with the sign set to 0. """
-        return Decimal((0, self._int, self._exp))
+        return _dec_from_triple(0, self._int, self._exp, self._is_special)
 
     def copy_negate(self):
         """Returns a copy with the sign inverted."""
         if self._sign:
-            return Decimal((0, self._int, self._exp))
+            return _dec_from_triple(0, self._int, self._exp, self._is_special)
         else:
-            return Decimal((1, self._int, self._exp))
+            return _dec_from_triple(1, self._int, self._exp, self._is_special)
 
     def copy_sign(self, other):
         """Returns self with the sign of other."""
-        return Decimal((other._sign, self._int, self._exp))
+        return _dec_from_triple(other._sign, self._int,
+                                self._exp, self._is_special)
 
     def exp(self, context=None):
         """Returns e ** self."""
@@ -2704,16 +2800,16 @@
         # larger exponent the result either overflows or underflows.
         if self._sign == 0 and adj > len(str((context.Emax+1)*3)):
             # overflow
-            ans = Decimal((0, (1,), context.Emax+1))
+            ans = _dec_from_triple(0, '1', context.Emax+1)
         elif self._sign == 1 and adj > len(str((-context.Etiny()+1)*3)):
             # underflow to 0
-            ans = Decimal((0, (1,), context.Etiny()-1))
+            ans = _dec_from_triple(0, '1', context.Etiny()-1)
         elif self._sign == 0 and adj < -p:
             # p+1 digits; final round will raise correct flags
-            ans = Decimal((0, (1,) + (0,)*(p-1) + (1,), -p))
+            ans = _dec_from_triple(0, '1' + '0'*(p-1) + '1', -p)
         elif self._sign == 1 and adj < -p-1:
             # p+1 digits; final round will raise correct flags
-            ans = Decimal((0, (9,)*(p+1), -p-1))
+            ans = _dec_from_triple(0, '9'*(p+1), -p-1)
         # general case
         else:
             op = _WorkRep(self)
@@ -2731,7 +2827,7 @@
                     break
                 extra += 3
 
-            ans = Decimal((0, list(map(int, str(coeff))), exp))
+            ans = _dec_from_triple(0, str(coeff), exp)
 
         # at this stage, ans should round correctly with *any*
         # rounding mode, not just with ROUND_HALF_EVEN
@@ -2743,84 +2839,60 @@
         return ans
 
     def is_canonical(self):
-        """Returns 1 if self is canonical; otherwise returns 0."""
-        return Dec_p1
+        """Return True if self is canonical; otherwise return False.
+
+        Currently, the encoding of a Decimal instance is always
+        canonical, so this method returns True for any Decimal.
+        """
+        return True
 
     def is_finite(self):
-        """Returns 1 if self is finite, otherwise returns 0.
+        """Return True if self is finite; otherwise return False.
 
-        For it to be finite, it must be neither infinite nor a NaN.
+        A Decimal instance is considered finite if it is neither
+        infinite nor a NaN.
         """
-        if self._is_special:
-            return Dec_0
-        else:
-            return Dec_p1
+        return not self._is_special
 
     def is_infinite(self):
-        """Returns 1 if self is an Infinite, otherwise returns 0."""
-        if self._isinfinity():
-            return Dec_p1
-        else:
-            return Dec_0
+        """Return True if self is infinite; otherwise return False."""
+        return self._exp == 'F'
 
     def is_nan(self):
-        """Returns 1 if self is qNaN or sNaN, otherwise returns 0."""
-        if self._isnan():
-            return Dec_p1
-        else:
-            return Dec_0
+        """Return True if self is a qNaN or sNaN; otherwise return False."""
+        return self._exp in ('n', 'N')
 
     def is_normal(self, context=None):
-        """Returns 1 if self is a normal number, otherwise returns 0."""
-        if self._is_special:
-            return Dec_0
-        if not self:
-            return Dec_0
+        """Return True if self is a normal number; otherwise return False."""
+        if self._is_special or not self:
+            return False
         if context is None:
             context = getcontext()
-        if context.Emin <= self.adjusted() <= context.Emax:
-            return Dec_p1
-        else:
-            return Dec_0
+        return context.Emin <= self.adjusted() <= context.Emax
 
     def is_qnan(self):
-        """Returns 1 if self is a quiet NaN, otherwise returns 0."""
-        if self._isnan() == 1:
-            return Dec_p1
-        else:
-            return Dec_0
+        """Return True if self is a quiet NaN; otherwise return False."""
+        return self._exp == 'n'
 
     def is_signed(self):
-        """Returns 1 if self is negative, otherwise returns 0."""
-        return Decimal(self._sign)
+        """Return True if self is negative; otherwise return False."""
+        return self._sign == 1
 
     def is_snan(self):
-        """Returns 1 if self is a signaling NaN, otherwise returns 0."""
-        if self._isnan() == 2:
-            return Dec_p1
-        else:
-            return Dec_0
+        """Return True if self is a signaling NaN; otherwise return False."""
+        return self._exp == 'N'
 
     def is_subnormal(self, context=None):
-        """Returns 1 if self is subnormal, otherwise returns 0."""
-        if self._is_special:
-            return Dec_0
-        if not self:
-            return Dec_0
+        """Return True if self is subnormal; otherwise return False."""
+        if self._is_special or not self:
+            return False
         if context is None:
             context = getcontext()
-
-        r = self._exp + len(self._int)
-        if r <= context.Emin:
-            return Dec_p1
-        return Dec_0
+        return self.adjusted() < context.Emin
 
     def is_zero(self):
-        """Returns 1 if self is a zero, otherwise returns 0."""
-        if self:
-            return Dec_0
-        else:
-            return Dec_p1
+        """Return True if self is a zero; otherwise return False."""
+        return not self._is_special and self._int == '0'
 
     def _ln_exp_bound(self):
         """Compute a lower bound for the adjusted exponent of self.ln().
@@ -2889,7 +2961,7 @@
             if coeff % (5*10**(len(str(abs(coeff)))-p-1)):
                 break
             places += 3
-        ans = Decimal((int(coeff<0), list(map(int, str(abs(coeff)))), -places))
+        ans = _dec_from_triple(int(coeff<0), str(abs(coeff)), -places)
 
         context = context._shallow_copy()
         rounding = context._set_rounding(ROUND_HALF_EVEN)
@@ -2952,7 +3024,7 @@
                                         'log10 of a negative value')
 
         # log10(10**n) = n
-        if self._int[0] == 1 and self._int[1:] == (0,)*(len(self._int) - 1):
+        if self._int[0] == '1' and self._int[1:] == '0'*(len(self._int) - 1):
             # answer may need rounding
             ans = Decimal(self._exp + len(self._int) - 1)
         else:
@@ -2970,8 +3042,7 @@
                 if coeff % (5*10**(len(str(abs(coeff)))-p-1)):
                     break
                 places += 3
-            ans = Decimal((int(coeff<0), list(map(int, str(abs(coeff)))),
-                          -places))
+            ans = _dec_from_triple(int(coeff<0), str(abs(coeff)), -places)
 
         context = context._shallow_copy()
         rounding = context._set_rounding(ROUND_HALF_EVEN)
@@ -3011,26 +3082,26 @@
     def _islogical(self):
         """Return True if self is a logical operand.
 
-        For being logical, it must be a finite numbers with a sign of 0,
+        For being logical, it must be a finite number with a sign of 0,
         an exponent of 0, and a coefficient whose digits must all be
         either 0 or 1.
         """
         if self._sign != 0 or self._exp != 0:
             return False
         for dig in self._int:
-            if dig not in (0, 1):
+            if dig not in '01':
                 return False
         return True
 
     def _fill_logical(self, context, opa, opb):
         dif = context.prec - len(opa)
         if dif > 0:
-            opa = (0,)*dif + opa
+            opa = '0'*dif + opa
         elif dif < 0:
             opa = opa[-context.prec:]
         dif = context.prec - len(opb)
         if dif > 0:
-            opb = (0,)*dif + opb
+            opb = '0'*dif + opb
         elif dif < 0:
             opb = opb[-context.prec:]
         return opa, opb
@@ -3046,22 +3117,15 @@
         (opa, opb) = self._fill_logical(context, self._int, other._int)
 
         # make the operation, and clean starting zeroes
-        result = [a&b for a,b in zip(opa,opb)]
-        for i,d in enumerate(result):
-            if d == 1:
-                break
-        result = tuple(result[i:])
-
-        # if empty, we must have at least a zero
-        if not result:
-            result = (0,)
-        return Decimal((0, result, 0))
+        result = "".join([str(int(a)&int(b)) for a,b in zip(opa,opb)])
+        return _dec_from_triple(0, result.lstrip('0') or '0', 0)
 
     def logical_invert(self, context=None):
         """Invert all its digits."""
         if context is None:
             context = getcontext()
-        return self.logical_xor(Decimal((0,(1,)*context.prec,0)), context)
+        return self.logical_xor(_dec_from_triple(0,'1'*context.prec,0),
+                                context)
 
     def logical_or(self, other, context=None):
         """Applies an 'or' operation between self and other's digits."""
@@ -3074,16 +3138,8 @@
         (opa, opb) = self._fill_logical(context, self._int, other._int)
 
         # make the operation, and clean starting zeroes
-        result = [a|b for a,b in zip(opa,opb)]
-        for i,d in enumerate(result):
-            if d == 1:
-                break
-        result = tuple(result[i:])
-
-        # if empty, we must have at least a zero
-        if not result:
-            result = (0,)
-        return Decimal((0, result, 0))
+        result = "".join(str(int(a)|int(b)) for a,b in zip(opa,opb))
+        return _dec_from_triple(0, result.lstrip('0') or '0', 0)
 
     def logical_xor(self, other, context=None):
         """Applies an 'xor' operation between self and other's digits."""
@@ -3096,16 +3152,8 @@
         (opa, opb) = self._fill_logical(context, self._int, other._int)
 
         # make the operation, and clean starting zeroes
-        result = [a^b for a,b in zip(opa,opb)]
-        for i,d in enumerate(result):
-            if d == 1:
-                break
-        result = tuple(result[i:])
-
-        # if empty, we must have at least a zero
-        if not result:
-            result = (0,)
-        return Decimal((0, result, 0))
+        result = "".join(str(int(a)^int(b)) for a,b in zip(opa,opb))
+        return _dec_from_triple(0, result.lstrip('0') or '0', 0)
 
     def max_mag(self, other, context=None):
         """Compares the values numerically with their sign ignored."""
@@ -3126,7 +3174,7 @@
                     return other._fix_nan(context)
                 return self._check_nans(other, context)
 
-        c = self.copy_abs().__cmp__(other.copy_abs())
+        c = self.copy_abs()._cmp(other.copy_abs())
         if c == 0:
             c = self.compare_total(other)
 
@@ -3135,9 +3183,7 @@
         else:
             ans = self
 
-        if context._rounding_decision == ALWAYS_ROUND:
-            return ans._fix(context)
-        return ans
+        return ans._fix(context)
 
     def min_mag(self, other, context=None):
         """Compares the values numerically with their sign ignored."""
@@ -3158,7 +3204,7 @@
                     return other._fix_nan(context)
                 return self._check_nans(other, context)
 
-        c = self.copy_abs().__cmp__(other.copy_abs())
+        c = self.copy_abs()._cmp(other.copy_abs())
         if c == 0:
             c = self.compare_total(other)
 
@@ -3167,9 +3213,7 @@
         else:
             ans = other
 
-        if context._rounding_decision == ALWAYS_ROUND:
-            return ans._fix(context)
-        return ans
+        return ans._fix(context)
 
     def next_minus(self, context=None):
         """Returns the largest representable number smaller than itself."""
@@ -3183,7 +3227,7 @@
         if self._isinfinity() == -1:
             return negInf
         if self._isinfinity() == 1:
-            return Decimal((0, (9,)*context.prec, context.Etop()))
+            return _dec_from_triple(0, '9'*context.prec, context.Etop())
 
         context = context.copy()
         context._set_rounding(ROUND_FLOOR)
@@ -3191,7 +3235,8 @@
         new_self = self._fix(context)
         if new_self != self:
             return new_self
-        return self.__sub__(Decimal((0, (1,), context.Etiny()-1)), context)
+        return self.__sub__(_dec_from_triple(0, '1', context.Etiny()-1),
+                            context)
 
     def next_plus(self, context=None):
         """Returns the smallest representable number larger than itself."""
@@ -3205,7 +3250,7 @@
         if self._isinfinity() == 1:
             return Inf
         if self._isinfinity() == -1:
-            return Decimal((1, (9,)*context.prec, context.Etop()))
+            return _dec_from_triple(1, '9'*context.prec, context.Etop())
 
         context = context.copy()
         context._set_rounding(ROUND_CEILING)
@@ -3213,7 +3258,8 @@
         new_self = self._fix(context)
         if new_self != self:
             return new_self
-        return self.__add__(Decimal((0, (1,), context.Etiny()-1)), context)
+        return self.__add__(_dec_from_triple(0, '1', context.Etiny()-1),
+                            context)
 
     def next_toward(self, other, context=None):
         """Returns the number closest to self, in the direction towards other.
@@ -3233,9 +3279,9 @@
         if ans:
             return ans
 
-        comparison = self.__cmp__(other)
+        comparison = self._cmp(other)
         if comparison == 0:
-            return Decimal((other._sign, self._int, self._exp))
+            return self.copy_sign(other)
 
         if comparison == -1:
             ans = self.next_plus(context)
@@ -3265,8 +3311,8 @@
         """Returns an indication of the class of self.
 
         The class is one of the following strings:
-          -sNaN
-          -NaN
+          sNaN
+          NaN
           -Infinity
           -Normal
           -Subnormal
@@ -3329,19 +3375,12 @@
         rotdig = self._int
         topad = context.prec - len(rotdig)
         if topad:
-            rotdig = ((0,)*topad) + rotdig
+            rotdig = '0'*topad + rotdig
 
         # let's rotate!
         rotated = rotdig[torot:] + rotdig[:torot]
-
-        # clean starting zeroes
-        for i,d in enumerate(rotated):
-            if d != 0:
-                break
-        rotated = rotated[i:]
-
-        return Decimal((self._sign, rotated, self._exp))
-
+        return _dec_from_triple(self._sign,
+                                rotated.lstrip('0') or '0', self._exp)
 
     def scaleb (self, other, context=None):
         """Returns self operand after adding the second value to its exp."""
@@ -3362,7 +3401,7 @@
         if self._isinfinity():
             return Decimal(self)
 
-        d = Decimal((self._sign, self._int, self._exp + int(other)))
+        d = _dec_from_triple(self._sign, self._int, self._exp + int(other))
         d = d._fix(context)
         return d
 
@@ -3390,26 +3429,17 @@
         rotdig = self._int
         topad = context.prec - len(rotdig)
         if topad:
-            rotdig = ((0,)*topad) + rotdig
+            rotdig = '0'*topad + rotdig
 
         # let's shift!
         if torot < 0:
             rotated = rotdig[:torot]
         else:
-            rotated = (rotdig + ((0,) * torot))
+            rotated = rotdig + '0'*torot
             rotated = rotated[-context.prec:]
 
-        # clean starting zeroes
-        if rotated:
-            for i,d in enumerate(rotated):
-                if d != 0:
-                    break
-            rotated = rotated[i:]
-        else:
-            rotated = (0,)
-
-        return Decimal((self._sign, rotated, self._exp))
-
+        return _dec_from_triple(self._sign,
+                                    rotated.lstrip('0') or '0', self._exp)
 
     # Support for pickling, copy, and deepcopy
     def __reduce__(self):
@@ -3425,6 +3455,111 @@
             return self     # My components are also immutable
         return self.__class__(str(self))
 
+    # PEP 3101 support.  See also _parse_format_specifier and _format_align
+    def __format__(self, specifier, context=None):
+        """Format a Decimal instance according to the given specifier.
+
+        The specifier should be a standard format specifier, with the
+        form described in PEP 3101.  Formatting types 'e', 'E', 'f',
+        'F', 'g', 'G', and '%' are supported.  If the formatting type
+        is omitted it defaults to 'g' or 'G', depending on the value
+        of context.capitals.
+
+        At this time the 'n' format specifier type (which is supposed
+        to use the current locale) is not supported.
+        """
+
+        # Note: PEP 3101 says that if the type is not present then
+        # there should be at least one digit after the decimal point.
+        # We take the liberty of ignoring this requirement for
+        # Decimal---it's presumably there to make sure that
+        # format(float, '') behaves similarly to str(float).
+        if context is None:
+            context = getcontext()
+
+        spec = _parse_format_specifier(specifier)
+
+        # special values don't care about the type or precision...
+        if self._is_special:
+            return _format_align(str(self), spec)
+
+        # a type of None defaults to 'g' or 'G', depending on context
+        # if type is '%', adjust exponent of self accordingly
+        if spec['type'] is None:
+            spec['type'] = ['g', 'G'][context.capitals]
+        elif spec['type'] == '%':
+            self = _dec_from_triple(self._sign, self._int, self._exp+2)
+
+        # round if necessary, taking rounding mode from the context
+        rounding = context.rounding
+        precision = spec['precision']
+        if precision is not None:
+            if spec['type'] in 'eE':
+                self = self._round(precision+1, rounding)
+            elif spec['type'] in 'gG':
+                if len(self._int) > precision:
+                    self = self._round(precision, rounding)
+            elif spec['type'] in 'fF%':
+                self = self._rescale(-precision, rounding)
+        # special case: zeros with a positive exponent can't be
+        # represented in fixed point; rescale them to 0e0.
+        elif not self and self._exp > 0 and spec['type'] in 'fF%':
+            self = self._rescale(0, rounding)
+
+        # figure out placement of the decimal point
+        leftdigits = self._exp + len(self._int)
+        if spec['type'] in 'fF%':
+            dotplace = leftdigits
+        elif spec['type'] in 'eE':
+            if not self and precision is not None:
+                dotplace = 1 - precision
+            else:
+                dotplace = 1
+        elif spec['type'] in 'gG':
+            if self._exp <= 0 and leftdigits > -6:
+                dotplace = leftdigits
+            else:
+                dotplace = 1
+
+        # figure out main part of numeric string...
+        if dotplace <= 0:
+            num = '0.' + '0'*(-dotplace) + self._int
+        elif dotplace >= len(self._int):
+            # make sure we're not padding a '0' with extra zeros on the right
+            assert dotplace==len(self._int) or self._int != '0'
+            num = self._int + '0'*(dotplace-len(self._int))
+        else:
+            num = self._int[:dotplace] + '.' + self._int[dotplace:]
+
+        # ...then the trailing exponent, or trailing '%'
+        if leftdigits != dotplace or spec['type'] in 'eE':
+            echar = {'E': 'E', 'e': 'e', 'G': 'E', 'g': 'e'}[spec['type']]
+            num = num + "{0}{1:+}".format(echar, leftdigits-dotplace)
+        elif spec['type'] == '%':
+            num = num + '%'
+
+        # add sign
+        if self._sign == 1:
+            num = '-' + num
+        return _format_align(num, spec)
+
+
+def _dec_from_triple(sign, coefficient, exponent, special=False):
+    """Create a decimal instance directly, without any validation,
+    normalization (e.g. removal of leading zeros) or argument
+    conversion.
+
+    This function is for *internal use only*.
+    """
+
+    self = object.__new__(Decimal)
+    self._sign = sign
+    self._int = coefficient
+    self._exp = exponent
+    self._is_special = special
+
+    return self
+
 ##### Context class #######################################################
 
 
@@ -3460,11 +3595,10 @@
     Contains:
     prec - precision (for use in rounding, division, square roots..)
     rounding - rounding type (how you round)
-    _rounding_decision - ALWAYS_ROUND, NEVER_ROUND -- do you round?
     traps - If traps[exception] = 1, then the exception is
                     raised when it is caused.  Otherwise, a value is
                     substituted in.
-    flags  - When an exception is caused, flags[exception] is incremented.
+    flags  - When an exception is caused, flags[exception] is set.
              (Whether or not the trap_enabler is set)
              Should be reset by user of Decimal instance.
     Emin -   Minimum exponent
@@ -3476,7 +3610,6 @@
 
     def __init__(self, prec=None, rounding=None,
                  traps=None, flags=None,
-                 _rounding_decision=None,
                  Emin=None, Emax=None,
                  capitals=None, _clamp=0,
                  _ignored_flags=None):
@@ -3514,16 +3647,16 @@
 
     def _shallow_copy(self):
         """Returns a shallow copy from self."""
-        nc = Context(self.prec, self.rounding, self.traps, self.flags,
-                         self._rounding_decision, self.Emin, self.Emax,
-                         self.capitals, self._clamp, self._ignored_flags)
+        nc = Context(self.prec, self.rounding, self.traps,
+                     self.flags, self.Emin, self.Emax,
+                     self.capitals, self._clamp, self._ignored_flags)
         return nc
 
     def copy(self):
         """Returns a deep copy from self."""
         nc = Context(self.prec, self.rounding, self.traps.copy(),
-                self.flags.copy(), self._rounding_decision, self.Emin,
-                self.Emax, self.capitals, self._clamp, self._ignored_flags)
+                     self.flags.copy(), self.Emin, self.Emax,
+                     self.capitals, self._clamp, self._ignored_flags)
         return nc
     __copy__ = copy
 
@@ -3531,16 +3664,16 @@
         """Handles an error
 
         If the flag is in _ignored_flags, returns the default response.
-        Otherwise, it increments the flag, then, if the corresponding
+        Otherwise, it sets the flag, then, if the corresponding
         trap_enabler is set, it reaises the exception.  Otherwise, it returns
-        the default value after incrementing the flag.
+        the default value after setting the flag.
         """
         error = _condition_map.get(condition, condition)
         if error in self._ignored_flags:
             # Don't touch the flag
             return error().handle(self, *args)
 
-        self.flags[error] += 1
+        self.flags[error] = 1
         if not self.traps[error]:
             # The errors define how to handle themselves.
             return condition().handle(self, *args)
@@ -3580,27 +3713,6 @@
         """Returns maximum exponent (= Emax - prec + 1)"""
         return int(self.Emax - self.prec + 1)
 
-    def _set_rounding_decision(self, type):
-        """Sets the rounding decision.
-
-        Sets the rounding decision, and returns the current (previous)
-        rounding decision.  Often used like:
-
-        context = context._shallow_copy()
-        # That so you don't change the calling context
-        # if an error occurs in the middle (say DivisionImpossible is raised).
-
-        rounding = context._set_rounding_decision(NEVER_ROUND)
-        instance = instance / Decimal(2)
-        context._set_rounding_decision(rounding)
-
-        This will make it not round for that operation.
-        """
-
-        rounding = self._rounding_decision
-        self._rounding_decision = type
-        return rounding
-
     def _set_rounding(self, type):
         """Sets the rounding type.
 
@@ -3621,7 +3733,16 @@
         return rounding
 
     def create_decimal(self, num='0'):
-        """Creates a new Decimal instance but using self as context."""
+        """Creates a new Decimal instance but using self as context.
+
+        This method implements the to-number operation of the
+        IBM Decimal specification."""
+
+        if isinstance(num, str) and num != num.strip():
+            return self._raise_error(ConversionSyntax,
+                                     "no trailing or leading whitespace is "
+                                     "permitted.")
+
         d = Decimal(num, context=self)
         if d._isnan() and len(d._int) > self.prec - self._clamp:
             return self._raise_error(ConversionSyntax,
@@ -3637,13 +3758,13 @@
         the plus operation on the operand.
 
         >>> ExtendedContext.abs(Decimal('2.1'))
-        Decimal("2.1")
+        Decimal('2.1')
         >>> ExtendedContext.abs(Decimal('-100'))
-        Decimal("100")
+        Decimal('100')
         >>> ExtendedContext.abs(Decimal('101.5'))
-        Decimal("101.5")
+        Decimal('101.5')
         >>> ExtendedContext.abs(Decimal('-101.5'))
-        Decimal("101.5")
+        Decimal('101.5')
         """
         return a.__abs__(context=self)
 
@@ -3651,9 +3772,9 @@
         """Return the sum of the two operands.
 
         >>> ExtendedContext.add(Decimal('12'), Decimal('7.00'))
-        Decimal("19.00")
+        Decimal('19.00')
         >>> ExtendedContext.add(Decimal('1E+2'), Decimal('1.01E+4'))
-        Decimal("1.02E+4")
+        Decimal('1.02E+4')
         """
         return a.__add__(b, context=self)
 
@@ -3667,7 +3788,7 @@
         received object already is in its canonical form.
 
         >>> ExtendedContext.canonical(Decimal('2.50'))
-        Decimal("2.50")
+        Decimal('2.50')
         """
         return a.canonical(context=self)
 
@@ -3686,17 +3807,17 @@
         zero or negative zero, or '1' if the result is greater than zero.
 
         >>> ExtendedContext.compare(Decimal('2.1'), Decimal('3'))
-        Decimal("-1")
+        Decimal('-1')
         >>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.1'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.10'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.compare(Decimal('3'), Decimal('2.1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.compare(Decimal('2.1'), Decimal('-3'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.compare(Decimal('-3'), Decimal('2.1'))
-        Decimal("-1")
+        Decimal('-1')
         """
         return a.compare(b, context=self)
 
@@ -3708,21 +3829,21 @@
 
         >>> c = ExtendedContext
         >>> c.compare_signal(Decimal('2.1'), Decimal('3'))
-        Decimal("-1")
+        Decimal('-1')
         >>> c.compare_signal(Decimal('2.1'), Decimal('2.1'))
-        Decimal("0")
+        Decimal('0')
         >>> c.flags[InvalidOperation] = 0
         >>> print(c.flags[InvalidOperation])
         0
         >>> c.compare_signal(Decimal('NaN'), Decimal('2.1'))
-        Decimal("NaN")
+        Decimal('NaN')
         >>> print(c.flags[InvalidOperation])
         1
         >>> c.flags[InvalidOperation] = 0
         >>> print(c.flags[InvalidOperation])
         0
         >>> c.compare_signal(Decimal('sNaN'), Decimal('2.1'))
-        Decimal("NaN")
+        Decimal('NaN')
         >>> print(c.flags[InvalidOperation])
         1
         """
@@ -3736,17 +3857,17 @@
         representations.
 
         >>> ExtendedContext.compare_total(Decimal('12.73'), Decimal('127.9'))
-        Decimal("-1")
+        Decimal('-1')
         >>> ExtendedContext.compare_total(Decimal('-127'),  Decimal('12'))
-        Decimal("-1")
+        Decimal('-1')
         >>> ExtendedContext.compare_total(Decimal('12.30'), Decimal('12.3'))
-        Decimal("-1")
+        Decimal('-1')
         >>> ExtendedContext.compare_total(Decimal('12.30'), Decimal('12.30'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.compare_total(Decimal('12.3'),  Decimal('12.300'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.compare_total(Decimal('12.3'),  Decimal('NaN'))
-        Decimal("-1")
+        Decimal('-1')
         """
         return a.compare_total(b)
 
@@ -3761,9 +3882,9 @@
         """Returns a copy of the operand with the sign set to 0.
 
         >>> ExtendedContext.copy_abs(Decimal('2.1'))
-        Decimal("2.1")
+        Decimal('2.1')
         >>> ExtendedContext.copy_abs(Decimal('-100'))
-        Decimal("100")
+        Decimal('100')
         """
         return a.copy_abs()
 
@@ -3771,9 +3892,9 @@
         """Returns a copy of the decimal objet.
 
         >>> ExtendedContext.copy_decimal(Decimal('2.1'))
-        Decimal("2.1")
+        Decimal('2.1')
         >>> ExtendedContext.copy_decimal(Decimal('-1.00'))
-        Decimal("-1.00")
+        Decimal('-1.00')
         """
         return Decimal(a)
 
@@ -3781,9 +3902,9 @@
         """Returns a copy of the operand with the sign inverted.
 
         >>> ExtendedContext.copy_negate(Decimal('101.5'))
-        Decimal("-101.5")
+        Decimal('-101.5')
         >>> ExtendedContext.copy_negate(Decimal('-101.5'))
-        Decimal("101.5")
+        Decimal('101.5')
         """
         return a.copy_negate()
 
@@ -3794,13 +3915,13 @@
         equal to the sign of the second operand.
 
         >>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('7.33'))
-        Decimal("1.50")
+        Decimal('1.50')
         >>> ExtendedContext.copy_sign(Decimal('-1.50'), Decimal('7.33'))
-        Decimal("1.50")
+        Decimal('1.50')
         >>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('-7.33'))
-        Decimal("-1.50")
+        Decimal('-1.50')
         >>> ExtendedContext.copy_sign(Decimal('-1.50'), Decimal('-7.33'))
-        Decimal("-1.50")
+        Decimal('-1.50')
         """
         return a.copy_sign(b)
 
@@ -3808,25 +3929,25 @@
         """Decimal division in a specified context.
 
         >>> ExtendedContext.divide(Decimal('1'), Decimal('3'))
-        Decimal("0.333333333")
+        Decimal('0.333333333')
         >>> ExtendedContext.divide(Decimal('2'), Decimal('3'))
-        Decimal("0.666666667")
+        Decimal('0.666666667')
         >>> ExtendedContext.divide(Decimal('5'), Decimal('2'))
-        Decimal("2.5")
+        Decimal('2.5')
         >>> ExtendedContext.divide(Decimal('1'), Decimal('10'))
-        Decimal("0.1")
+        Decimal('0.1')
         >>> ExtendedContext.divide(Decimal('12'), Decimal('12'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.divide(Decimal('8.00'), Decimal('2'))
-        Decimal("4.00")
+        Decimal('4.00')
         >>> ExtendedContext.divide(Decimal('2.400'), Decimal('2.0'))
-        Decimal("1.20")
+        Decimal('1.20')
         >>> ExtendedContext.divide(Decimal('1000'), Decimal('100'))
-        Decimal("10")
+        Decimal('10')
         >>> ExtendedContext.divide(Decimal('1000'), Decimal('1'))
-        Decimal("1000")
+        Decimal('1000')
         >>> ExtendedContext.divide(Decimal('2.40E+6'), Decimal('2'))
-        Decimal("1.20E+6")
+        Decimal('1.20E+6')
         """
         return a.__truediv__(b, context=self)
 
@@ -3834,11 +3955,11 @@
         """Divides two numbers and returns the integer part of the result.
 
         >>> ExtendedContext.divide_int(Decimal('2'), Decimal('3'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.divide_int(Decimal('10'), Decimal('3'))
-        Decimal("3")
+        Decimal('3')
         >>> ExtendedContext.divide_int(Decimal('1'), Decimal('0.3'))
-        Decimal("3")
+        Decimal('3')
         """
         return a.__floordiv__(b, context=self)
 
@@ -3852,17 +3973,17 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> c.exp(Decimal('-Infinity'))
-        Decimal("0")
+        Decimal('0')
         >>> c.exp(Decimal('-1'))
-        Decimal("0.367879441")
+        Decimal('0.367879441')
         >>> c.exp(Decimal('0'))
-        Decimal("1")
+        Decimal('1')
         >>> c.exp(Decimal('1'))
-        Decimal("2.71828183")
+        Decimal('2.71828183')
         >>> c.exp(Decimal('0.693147181'))
-        Decimal("2.00000000")
+        Decimal('2.00000000')
         >>> c.exp(Decimal('+Infinity'))
-        Decimal("Infinity")
+        Decimal('Infinity')
         """
         return a.exp(context=self)
 
@@ -3874,147 +3995,154 @@
         multiplication, using add, all with only one final rounding.
 
         >>> ExtendedContext.fma(Decimal('3'), Decimal('5'), Decimal('7'))
-        Decimal("22")
+        Decimal('22')
         >>> ExtendedContext.fma(Decimal('3'), Decimal('-5'), Decimal('7'))
-        Decimal("-8")
+        Decimal('-8')
         >>> ExtendedContext.fma(Decimal('888565290'), Decimal('1557.96930'), Decimal('-86087.7578'))
-        Decimal("1.38435736E+12")
+        Decimal('1.38435736E+12')
         """
         return a.fma(b, c, context=self)
 
     def is_canonical(self, a):
-        """Returns 1 if the operand is canonical; otherwise returns 0.
+        """Return True if the operand is canonical; otherwise return False.
+
+        Currently, the encoding of a Decimal instance is always
+        canonical, so this method returns True for any Decimal.
 
         >>> ExtendedContext.is_canonical(Decimal('2.50'))
-        Decimal("1")
+        True
         """
-        return Dec_p1
+        return a.is_canonical()
 
     def is_finite(self, a):
-        """Returns 1 if the operand is finite, otherwise returns 0.
+        """Return True if the operand is finite; otherwise return False.
 
-        For it to be finite, it must be neither infinite nor a NaN.
+        A Decimal instance is considered finite if it is neither
+        infinite nor a NaN.
 
         >>> ExtendedContext.is_finite(Decimal('2.50'))
-        Decimal("1")
+        True
         >>> ExtendedContext.is_finite(Decimal('-0.3'))
-        Decimal("1")
+        True
         >>> ExtendedContext.is_finite(Decimal('0'))
-        Decimal("1")
+        True
         >>> ExtendedContext.is_finite(Decimal('Inf'))
-        Decimal("0")
+        False
         >>> ExtendedContext.is_finite(Decimal('NaN'))
-        Decimal("0")
+        False
         """
         return a.is_finite()
 
     def is_infinite(self, a):
-        """Returns 1 if the operand is an Infinite, otherwise returns 0.
+        """Return True if the operand is infinite; otherwise return False.
 
         >>> ExtendedContext.is_infinite(Decimal('2.50'))
-        Decimal("0")
+        False
         >>> ExtendedContext.is_infinite(Decimal('-Inf'))
-        Decimal("1")
+        True
         >>> ExtendedContext.is_infinite(Decimal('NaN'))
-        Decimal("0")
+        False
         """
         return a.is_infinite()
 
     def is_nan(self, a):
-        """Returns 1 if the operand is qNaN or sNaN, otherwise returns 0.
+        """Return True if the operand is a qNaN or sNaN;
+        otherwise return False.
 
         >>> ExtendedContext.is_nan(Decimal('2.50'))
-        Decimal("0")
+        False
         >>> ExtendedContext.is_nan(Decimal('NaN'))
-        Decimal("1")
+        True
         >>> ExtendedContext.is_nan(Decimal('-sNaN'))
-        Decimal("1")
+        True
         """
         return a.is_nan()
 
     def is_normal(self, a):
-        """Returns 1 if the operand is a normal number, otherwise returns 0.
+        """Return True if the operand is a normal number;
+        otherwise return False.
 
         >>> c = ExtendedContext.copy()
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> c.is_normal(Decimal('2.50'))
-        Decimal("1")
+        True
         >>> c.is_normal(Decimal('0.1E-999'))
-        Decimal("0")
+        False
         >>> c.is_normal(Decimal('0.00'))
-        Decimal("0")
+        False
         >>> c.is_normal(Decimal('-Inf'))
-        Decimal("0")
+        False
         >>> c.is_normal(Decimal('NaN'))
-        Decimal("0")
+        False
         """
         return a.is_normal(context=self)
 
     def is_qnan(self, a):
-        """Returns 1 if the operand is a quiet NaN, otherwise returns 0.
+        """Return True if the operand is a quiet NaN; otherwise return False.
 
         >>> ExtendedContext.is_qnan(Decimal('2.50'))
-        Decimal("0")
+        False
         >>> ExtendedContext.is_qnan(Decimal('NaN'))
-        Decimal("1")
+        True
         >>> ExtendedContext.is_qnan(Decimal('sNaN'))
-        Decimal("0")
+        False
         """
         return a.is_qnan()
 
     def is_signed(self, a):
-        """Returns 1 if the operand is negative, otherwise returns 0.
+        """Return True if the operand is negative; otherwise return False.
 
         >>> ExtendedContext.is_signed(Decimal('2.50'))
-        Decimal("0")
+        False
         >>> ExtendedContext.is_signed(Decimal('-12'))
-        Decimal("1")
+        True
         >>> ExtendedContext.is_signed(Decimal('-0'))
-        Decimal("1")
+        True
         """
         return a.is_signed()
 
     def is_snan(self, a):
-        """Returns 1 if the operand is a signaling NaN, otherwise returns 0.
+        """Return True if the operand is a signaling NaN;
+        otherwise return False.
 
         >>> ExtendedContext.is_snan(Decimal('2.50'))
-        Decimal("0")
+        False
         >>> ExtendedContext.is_snan(Decimal('NaN'))
-        Decimal("0")
+        False
         >>> ExtendedContext.is_snan(Decimal('sNaN'))
-        Decimal("1")
+        True
         """
         return a.is_snan()
 
     def is_subnormal(self, a):
-        """Returns 1 if the operand is subnormal, otherwise returns 0.
+        """Return True if the operand is subnormal; otherwise return False.
 
         >>> c = ExtendedContext.copy()
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> c.is_subnormal(Decimal('2.50'))
-        Decimal("0")
+        False
         >>> c.is_subnormal(Decimal('0.1E-999'))
-        Decimal("1")
+        True
         >>> c.is_subnormal(Decimal('0.00'))
-        Decimal("0")
+        False
         >>> c.is_subnormal(Decimal('-Inf'))
-        Decimal("0")
+        False
         >>> c.is_subnormal(Decimal('NaN'))
-        Decimal("0")
+        False
         """
         return a.is_subnormal(context=self)
 
     def is_zero(self, a):
-        """Returns 1 if the operand is a zero, otherwise returns 0.
+        """Return True if the operand is a zero; otherwise return False.
 
         >>> ExtendedContext.is_zero(Decimal('0'))
-        Decimal("1")
+        True
         >>> ExtendedContext.is_zero(Decimal('2.50'))
-        Decimal("0")
+        False
         >>> ExtendedContext.is_zero(Decimal('-0E+2'))
-        Decimal("1")
+        True
         """
         return a.is_zero()
 
@@ -4025,15 +4153,15 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> c.ln(Decimal('0'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         >>> c.ln(Decimal('1.000'))
-        Decimal("0")
+        Decimal('0')
         >>> c.ln(Decimal('2.71828183'))
-        Decimal("1.00000000")
+        Decimal('1.00000000')
         >>> c.ln(Decimal('10'))
-        Decimal("2.30258509")
+        Decimal('2.30258509')
         >>> c.ln(Decimal('+Infinity'))
-        Decimal("Infinity")
+        Decimal('Infinity')
         """
         return a.ln(context=self)
 
@@ -4044,19 +4172,19 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> c.log10(Decimal('0'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         >>> c.log10(Decimal('0.001'))
-        Decimal("-3")
+        Decimal('-3')
         >>> c.log10(Decimal('1.000'))
-        Decimal("0")
+        Decimal('0')
         >>> c.log10(Decimal('2'))
-        Decimal("0.301029996")
+        Decimal('0.301029996')
         >>> c.log10(Decimal('10'))
-        Decimal("1")
+        Decimal('1')
         >>> c.log10(Decimal('70'))
-        Decimal("1.84509804")
+        Decimal('1.84509804')
         >>> c.log10(Decimal('+Infinity'))
-        Decimal("Infinity")
+        Decimal('Infinity')
         """
         return a.log10(context=self)
 
@@ -4069,13 +4197,13 @@
         value of that digit and without limiting the resulting exponent).
 
         >>> ExtendedContext.logb(Decimal('250'))
-        Decimal("2")
+        Decimal('2')
         >>> ExtendedContext.logb(Decimal('2.50'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logb(Decimal('0.03'))
-        Decimal("-2")
+        Decimal('-2')
         >>> ExtendedContext.logb(Decimal('0'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         """
         return a.logb(context=self)
 
@@ -4085,17 +4213,17 @@
         The operands must be both logical numbers.
 
         >>> ExtendedContext.logical_and(Decimal('0'), Decimal('0'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_and(Decimal('0'), Decimal('1'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_and(Decimal('1'), Decimal('0'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_and(Decimal('1'), Decimal('1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.logical_and(Decimal('1100'), Decimal('1010'))
-        Decimal("1000")
+        Decimal('1000')
         >>> ExtendedContext.logical_and(Decimal('1111'), Decimal('10'))
-        Decimal("10")
+        Decimal('10')
         """
         return a.logical_and(b, context=self)
 
@@ -4105,13 +4233,13 @@
         The operand must be a logical number.
 
         >>> ExtendedContext.logical_invert(Decimal('0'))
-        Decimal("111111111")
+        Decimal('111111111')
         >>> ExtendedContext.logical_invert(Decimal('1'))
-        Decimal("111111110")
+        Decimal('111111110')
         >>> ExtendedContext.logical_invert(Decimal('111111111'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_invert(Decimal('101010101'))
-        Decimal("10101010")
+        Decimal('10101010')
         """
         return a.logical_invert(context=self)
 
@@ -4121,17 +4249,17 @@
         The operands must be both logical numbers.
 
         >>> ExtendedContext.logical_or(Decimal('0'), Decimal('0'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_or(Decimal('0'), Decimal('1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.logical_or(Decimal('1'), Decimal('0'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.logical_or(Decimal('1'), Decimal('1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.logical_or(Decimal('1100'), Decimal('1010'))
-        Decimal("1110")
+        Decimal('1110')
         >>> ExtendedContext.logical_or(Decimal('1110'), Decimal('10'))
-        Decimal("1110")
+        Decimal('1110')
         """
         return a.logical_or(b, context=self)
 
@@ -4141,17 +4269,17 @@
         The operands must be both logical numbers.
 
         >>> ExtendedContext.logical_xor(Decimal('0'), Decimal('0'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_xor(Decimal('0'), Decimal('1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.logical_xor(Decimal('1'), Decimal('0'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.logical_xor(Decimal('1'), Decimal('1'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_xor(Decimal('1100'), Decimal('1010'))
-        Decimal("110")
+        Decimal('110')
         >>> ExtendedContext.logical_xor(Decimal('1111'), Decimal('10'))
-        Decimal("1101")
+        Decimal('1101')
         """
         return a.logical_xor(b, context=self)
 
@@ -4159,19 +4287,19 @@
         """max compares two values numerically and returns the maximum.
 
         If either operand is a NaN then the general rules apply.
-        Otherwise, the operands are compared as as though by the compare
+        Otherwise, the operands are compared as though by the compare
         operation.  If they are numerically equal then the left-hand operand
         is chosen as the result.  Otherwise the maximum (closer to positive
         infinity) of the two operands is chosen as the result.
 
         >>> ExtendedContext.max(Decimal('3'), Decimal('2'))
-        Decimal("3")
+        Decimal('3')
         >>> ExtendedContext.max(Decimal('-10'), Decimal('3'))
-        Decimal("3")
+        Decimal('3')
         >>> ExtendedContext.max(Decimal('1.0'), Decimal('1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.max(Decimal('7'), Decimal('NaN'))
-        Decimal("7")
+        Decimal('7')
         """
         return a.max(b, context=self)
 
@@ -4183,19 +4311,19 @@
         """min compares two values numerically and returns the minimum.
 
         If either operand is a NaN then the general rules apply.
-        Otherwise, the operands are compared as as though by the compare
+        Otherwise, the operands are compared as though by the compare
         operation.  If they are numerically equal then the left-hand operand
         is chosen as the result.  Otherwise the minimum (closer to negative
         infinity) of the two operands is chosen as the result.
 
         >>> ExtendedContext.min(Decimal('3'), Decimal('2'))
-        Decimal("2")
+        Decimal('2')
         >>> ExtendedContext.min(Decimal('-10'), Decimal('3'))
-        Decimal("-10")
+        Decimal('-10')
         >>> ExtendedContext.min(Decimal('1.0'), Decimal('1'))
-        Decimal("1.0")
+        Decimal('1.0')
         >>> ExtendedContext.min(Decimal('7'), Decimal('NaN'))
-        Decimal("7")
+        Decimal('7')
         """
         return a.min(b, context=self)
 
@@ -4211,9 +4339,9 @@
         has the same exponent as the operand.
 
         >>> ExtendedContext.minus(Decimal('1.3'))
-        Decimal("-1.3")
+        Decimal('-1.3')
         >>> ExtendedContext.minus(Decimal('-1.3'))
-        Decimal("1.3")
+        Decimal('1.3')
         """
         return a.__neg__(context=self)
 
@@ -4226,15 +4354,15 @@
         of the two operands.
 
         >>> ExtendedContext.multiply(Decimal('1.20'), Decimal('3'))
-        Decimal("3.60")
+        Decimal('3.60')
         >>> ExtendedContext.multiply(Decimal('7'), Decimal('3'))
-        Decimal("21")
+        Decimal('21')
         >>> ExtendedContext.multiply(Decimal('0.9'), Decimal('0.8'))
-        Decimal("0.72")
+        Decimal('0.72')
         >>> ExtendedContext.multiply(Decimal('0.9'), Decimal('-0'))
-        Decimal("-0.0")
+        Decimal('-0.0')
         >>> ExtendedContext.multiply(Decimal('654321'), Decimal('654321'))
-        Decimal("4.28135971E+11")
+        Decimal('4.28135971E+11')
         """
         return a.__mul__(b, context=self)
 
@@ -4245,13 +4373,13 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> ExtendedContext.next_minus(Decimal('1'))
-        Decimal("0.999999999")
+        Decimal('0.999999999')
         >>> c.next_minus(Decimal('1E-1007'))
-        Decimal("0E-1007")
+        Decimal('0E-1007')
         >>> ExtendedContext.next_minus(Decimal('-1.00000003'))
-        Decimal("-1.00000004")
+        Decimal('-1.00000004')
         >>> c.next_minus(Decimal('Infinity'))
-        Decimal("9.99999999E+999")
+        Decimal('9.99999999E+999')
         """
         return a.next_minus(context=self)
 
@@ -4262,13 +4390,13 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> ExtendedContext.next_plus(Decimal('1'))
-        Decimal("1.00000001")
+        Decimal('1.00000001')
         >>> c.next_plus(Decimal('-1E-1007'))
-        Decimal("-0E-1007")
+        Decimal('-0E-1007')
         >>> ExtendedContext.next_plus(Decimal('-1.00000003'))
-        Decimal("-1.00000002")
+        Decimal('-1.00000002')
         >>> c.next_plus(Decimal('-Infinity'))
-        Decimal("-9.99999999E+999")
+        Decimal('-9.99999999E+999')
         """
         return a.next_plus(context=self)
 
@@ -4284,19 +4412,19 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> c.next_toward(Decimal('1'), Decimal('2'))
-        Decimal("1.00000001")
+        Decimal('1.00000001')
         >>> c.next_toward(Decimal('-1E-1007'), Decimal('1'))
-        Decimal("-0E-1007")
+        Decimal('-0E-1007')
         >>> c.next_toward(Decimal('-1.00000003'), Decimal('0'))
-        Decimal("-1.00000002")
+        Decimal('-1.00000002')
         >>> c.next_toward(Decimal('1'), Decimal('0'))
-        Decimal("0.999999999")
+        Decimal('0.999999999')
         >>> c.next_toward(Decimal('1E-1007'), Decimal('-100'))
-        Decimal("0E-1007")
+        Decimal('0E-1007')
         >>> c.next_toward(Decimal('-1.00000003'), Decimal('-10'))
-        Decimal("-1.00000004")
+        Decimal('-1.00000004')
         >>> c.next_toward(Decimal('0.00'), Decimal('-0.0000'))
-        Decimal("-0.00")
+        Decimal('-0.00')
         """
         return a.next_toward(b, context=self)
 
@@ -4307,17 +4435,17 @@
         result.
 
         >>> ExtendedContext.normalize(Decimal('2.1'))
-        Decimal("2.1")
+        Decimal('2.1')
         >>> ExtendedContext.normalize(Decimal('-2.0'))
-        Decimal("-2")
+        Decimal('-2')
         >>> ExtendedContext.normalize(Decimal('1.200'))
-        Decimal("1.2")
+        Decimal('1.2')
         >>> ExtendedContext.normalize(Decimal('-120'))
-        Decimal("-1.2E+2")
+        Decimal('-1.2E+2')
         >>> ExtendedContext.normalize(Decimal('120.00'))
-        Decimal("1.2E+2")
+        Decimal('1.2E+2')
         >>> ExtendedContext.normalize(Decimal('0.00'))
-        Decimal("0")
+        Decimal('0')
         """
         return a.normalize(context=self)
 
@@ -4376,9 +4504,9 @@
         has the same exponent as the operand.
 
         >>> ExtendedContext.plus(Decimal('1.3'))
-        Decimal("1.3")
+        Decimal('1.3')
         >>> ExtendedContext.plus(Decimal('-1.3'))
-        Decimal("-1.3")
+        Decimal('-1.3')
         """
         return a.__pos__(context=self)
 
@@ -4408,46 +4536,46 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> c.power(Decimal('2'), Decimal('3'))
-        Decimal("8")
+        Decimal('8')
         >>> c.power(Decimal('-2'), Decimal('3'))
-        Decimal("-8")
+        Decimal('-8')
         >>> c.power(Decimal('2'), Decimal('-3'))
-        Decimal("0.125")
+        Decimal('0.125')
         >>> c.power(Decimal('1.7'), Decimal('8'))
-        Decimal("69.7575744")
+        Decimal('69.7575744')
         >>> c.power(Decimal('10'), Decimal('0.301029996'))
-        Decimal("2.00000000")
+        Decimal('2.00000000')
         >>> c.power(Decimal('Infinity'), Decimal('-1'))
-        Decimal("0")
+        Decimal('0')
         >>> c.power(Decimal('Infinity'), Decimal('0'))
-        Decimal("1")
+        Decimal('1')
         >>> c.power(Decimal('Infinity'), Decimal('1'))
-        Decimal("Infinity")
+        Decimal('Infinity')
         >>> c.power(Decimal('-Infinity'), Decimal('-1'))
-        Decimal("-0")
+        Decimal('-0')
         >>> c.power(Decimal('-Infinity'), Decimal('0'))
-        Decimal("1")
+        Decimal('1')
         >>> c.power(Decimal('-Infinity'), Decimal('1'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         >>> c.power(Decimal('-Infinity'), Decimal('2'))
-        Decimal("Infinity")
+        Decimal('Infinity')
         >>> c.power(Decimal('0'), Decimal('0'))
-        Decimal("NaN")
+        Decimal('NaN')
 
         >>> c.power(Decimal('3'), Decimal('7'), Decimal('16'))
-        Decimal("11")
+        Decimal('11')
         >>> c.power(Decimal('-3'), Decimal('7'), Decimal('16'))
-        Decimal("-11")
+        Decimal('-11')
         >>> c.power(Decimal('-3'), Decimal('8'), Decimal('16'))
-        Decimal("1")
+        Decimal('1')
         >>> c.power(Decimal('3'), Decimal('7'), Decimal('-16'))
-        Decimal("11")
+        Decimal('11')
         >>> c.power(Decimal('23E12345'), Decimal('67E189'), Decimal('123456789'))
-        Decimal("11729830")
+        Decimal('11729830')
         >>> c.power(Decimal('-0'), Decimal('17'), Decimal('1729'))
-        Decimal("-0")
+        Decimal('-0')
         >>> c.power(Decimal('-23'), Decimal('0'), Decimal('65537'))
-        Decimal("1")
+        Decimal('1')
         """
         return a.__pow__(b, modulo, context=self)
 
@@ -4470,35 +4598,35 @@
         if the result is subnormal and inexact.
 
         >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.001'))
-        Decimal("2.170")
+        Decimal('2.170')
         >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.01'))
-        Decimal("2.17")
+        Decimal('2.17')
         >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.1'))
-        Decimal("2.2")
+        Decimal('2.2')
         >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('1e+0'))
-        Decimal("2")
+        Decimal('2')
         >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('1e+1'))
-        Decimal("0E+1")
+        Decimal('0E+1')
         >>> ExtendedContext.quantize(Decimal('-Inf'), Decimal('Infinity'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         >>> ExtendedContext.quantize(Decimal('2'), Decimal('Infinity'))
-        Decimal("NaN")
+        Decimal('NaN')
         >>> ExtendedContext.quantize(Decimal('-0.1'), Decimal('1'))
-        Decimal("-0")
+        Decimal('-0')
         >>> ExtendedContext.quantize(Decimal('-0'), Decimal('1e+5'))
-        Decimal("-0E+5")
+        Decimal('-0E+5')
         >>> ExtendedContext.quantize(Decimal('+35236450.6'), Decimal('1e-2'))
-        Decimal("NaN")
+        Decimal('NaN')
         >>> ExtendedContext.quantize(Decimal('-35236450.6'), Decimal('1e-2'))
-        Decimal("NaN")
+        Decimal('NaN')
         >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e-1'))
-        Decimal("217.0")
+        Decimal('217.0')
         >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e-0'))
-        Decimal("217")
+        Decimal('217')
         >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e+1'))
-        Decimal("2.2E+2")
+        Decimal('2.2E+2')
         >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e+2'))
-        Decimal("2E+2")
+        Decimal('2E+2')
         """
         return a.quantize(b, context=self)
 
@@ -4506,7 +4634,7 @@
         """Just returns 10, as this is Decimal, :)
 
         >>> ExtendedContext.radix()
-        Decimal("10")
+        Decimal('10')
         """
         return Decimal(10)
 
@@ -4523,17 +4651,17 @@
         remainder cannot be calculated).
 
         >>> ExtendedContext.remainder(Decimal('2.1'), Decimal('3'))
-        Decimal("2.1")
+        Decimal('2.1')
         >>> ExtendedContext.remainder(Decimal('10'), Decimal('3'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.remainder(Decimal('-10'), Decimal('3'))
-        Decimal("-1")
+        Decimal('-1')
         >>> ExtendedContext.remainder(Decimal('10.2'), Decimal('1'))
-        Decimal("0.2")
+        Decimal('0.2')
         >>> ExtendedContext.remainder(Decimal('10'), Decimal('0.3'))
-        Decimal("0.1")
+        Decimal('0.1')
         >>> ExtendedContext.remainder(Decimal('3.6'), Decimal('1.3'))
-        Decimal("1.0")
+        Decimal('1.0')
         """
         return a.__mod__(b, context=self)
 
@@ -4548,19 +4676,19 @@
         remainder cannot be calculated).
 
         >>> ExtendedContext.remainder_near(Decimal('2.1'), Decimal('3'))
-        Decimal("-0.9")
+        Decimal('-0.9')
         >>> ExtendedContext.remainder_near(Decimal('10'), Decimal('6'))
-        Decimal("-2")
+        Decimal('-2')
         >>> ExtendedContext.remainder_near(Decimal('10'), Decimal('3'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.remainder_near(Decimal('-10'), Decimal('3'))
-        Decimal("-1")
+        Decimal('-1')
         >>> ExtendedContext.remainder_near(Decimal('10.2'), Decimal('1'))
-        Decimal("0.2")
+        Decimal('0.2')
         >>> ExtendedContext.remainder_near(Decimal('10'), Decimal('0.3'))
-        Decimal("0.1")
+        Decimal('0.1')
         >>> ExtendedContext.remainder_near(Decimal('3.6'), Decimal('1.3'))
-        Decimal("-0.3")
+        Decimal('-0.3')
         """
         return a.remainder_near(b, context=self)
 
@@ -4574,15 +4702,15 @@
         positive or to the right otherwise.
 
         >>> ExtendedContext.rotate(Decimal('34'), Decimal('8'))
-        Decimal("400000003")
+        Decimal('400000003')
         >>> ExtendedContext.rotate(Decimal('12'), Decimal('9'))
-        Decimal("12")
+        Decimal('12')
         >>> ExtendedContext.rotate(Decimal('123456789'), Decimal('-2'))
-        Decimal("891234567")
+        Decimal('891234567')
         >>> ExtendedContext.rotate(Decimal('123456789'), Decimal('0'))
-        Decimal("123456789")
+        Decimal('123456789')
         >>> ExtendedContext.rotate(Decimal('123456789'), Decimal('+2'))
-        Decimal("345678912")
+        Decimal('345678912')
         """
         return a.rotate(b, context=self)
 
@@ -4607,11 +4735,11 @@
         """Returns the first operand after adding the second value its exp.
 
         >>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('-2'))
-        Decimal("0.0750")
+        Decimal('0.0750')
         >>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('0'))
-        Decimal("7.50")
+        Decimal('7.50')
         >>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('3'))
-        Decimal("7.50E+3")
+        Decimal('7.50E+3')
         """
         return a.scaleb (b, context=self)
 
@@ -4626,15 +4754,15 @@
         coefficient are zeros.
 
         >>> ExtendedContext.shift(Decimal('34'), Decimal('8'))
-        Decimal("400000000")
+        Decimal('400000000')
         >>> ExtendedContext.shift(Decimal('12'), Decimal('9'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.shift(Decimal('123456789'), Decimal('-2'))
-        Decimal("1234567")
+        Decimal('1234567')
         >>> ExtendedContext.shift(Decimal('123456789'), Decimal('0'))
-        Decimal("123456789")
+        Decimal('123456789')
         >>> ExtendedContext.shift(Decimal('123456789'), Decimal('+2'))
-        Decimal("345678900")
+        Decimal('345678900')
         """
         return a.shift(b, context=self)
 
@@ -4645,23 +4773,23 @@
         algorithm.
 
         >>> ExtendedContext.sqrt(Decimal('0'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.sqrt(Decimal('-0'))
-        Decimal("-0")
+        Decimal('-0')
         >>> ExtendedContext.sqrt(Decimal('0.39'))
-        Decimal("0.624499800")
+        Decimal('0.624499800')
         >>> ExtendedContext.sqrt(Decimal('100'))
-        Decimal("10")
+        Decimal('10')
         >>> ExtendedContext.sqrt(Decimal('1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.sqrt(Decimal('1.0'))
-        Decimal("1.0")
+        Decimal('1.0')
         >>> ExtendedContext.sqrt(Decimal('1.00'))
-        Decimal("1.0")
+        Decimal('1.0')
         >>> ExtendedContext.sqrt(Decimal('7'))
-        Decimal("2.64575131")
+        Decimal('2.64575131')
         >>> ExtendedContext.sqrt(Decimal('10'))
-        Decimal("3.16227766")
+        Decimal('3.16227766')
         >>> ExtendedContext.prec
         9
         """
@@ -4671,11 +4799,11 @@
         """Return the difference between the two operands.
 
         >>> ExtendedContext.subtract(Decimal('1.3'), Decimal('1.07'))
-        Decimal("0.23")
+        Decimal('0.23')
         >>> ExtendedContext.subtract(Decimal('1.3'), Decimal('1.30'))
-        Decimal("0.00")
+        Decimal('0.00')
         >>> ExtendedContext.subtract(Decimal('1.3'), Decimal('2.07'))
-        Decimal("-0.77")
+        Decimal('-0.77')
         """
         return a.__sub__(b, context=self)
 
@@ -4704,21 +4832,21 @@
         context.
 
         >>> ExtendedContext.to_integral_exact(Decimal('2.1'))
-        Decimal("2")
+        Decimal('2')
         >>> ExtendedContext.to_integral_exact(Decimal('100'))
-        Decimal("100")
+        Decimal('100')
         >>> ExtendedContext.to_integral_exact(Decimal('100.0'))
-        Decimal("100")
+        Decimal('100')
         >>> ExtendedContext.to_integral_exact(Decimal('101.5'))
-        Decimal("102")
+        Decimal('102')
         >>> ExtendedContext.to_integral_exact(Decimal('-101.5'))
-        Decimal("-102")
+        Decimal('-102')
         >>> ExtendedContext.to_integral_exact(Decimal('10E+5'))
-        Decimal("1.0E+6")
+        Decimal('1.0E+6')
         >>> ExtendedContext.to_integral_exact(Decimal('7.89E+77'))
-        Decimal("7.89E+77")
+        Decimal('7.89E+77')
         >>> ExtendedContext.to_integral_exact(Decimal('-Inf'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         """
         return a.to_integral_exact(context=self)
 
@@ -4732,21 +4860,21 @@
         be set.  The rounding mode is taken from the context.
 
         >>> ExtendedContext.to_integral_value(Decimal('2.1'))
-        Decimal("2")
+        Decimal('2')
         >>> ExtendedContext.to_integral_value(Decimal('100'))
-        Decimal("100")
+        Decimal('100')
         >>> ExtendedContext.to_integral_value(Decimal('100.0'))
-        Decimal("100")
+        Decimal('100')
         >>> ExtendedContext.to_integral_value(Decimal('101.5'))
-        Decimal("102")
+        Decimal('102')
         >>> ExtendedContext.to_integral_value(Decimal('-101.5'))
-        Decimal("-102")
+        Decimal('-102')
         >>> ExtendedContext.to_integral_value(Decimal('10E+5'))
-        Decimal("1.0E+6")
+        Decimal('1.0E+6')
         >>> ExtendedContext.to_integral_value(Decimal('7.89E+77'))
-        Decimal("7.89E+77")
+        Decimal('7.89E+77')
         >>> ExtendedContext.to_integral_value(Decimal('-Inf'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         """
         return a.to_integral_value(context=self)
 
@@ -4766,10 +4894,7 @@
             self.exp = None
         elif isinstance(value, Decimal):
             self.sign = value._sign
-            cum = 0
-            for digit  in value._int:
-                cum = cum * 10 + digit
-            self.int = cum
+            self.int = int(value._int)
             self.exp = value._exp
         else:
             # assert isinstance(value, tuple)
@@ -4784,7 +4909,7 @@
 
 
 
-def _normalize(op1, op2, shouldround = 0, prec = 0):
+def _normalize(op1, op2, prec = 0):
     """Normalizes op1, op2 to have the same exp and length of coefficient.
 
     Done during addition.
@@ -4801,13 +4926,12 @@
     # as adding any positive quantity smaller than 10**exp; similarly
     # for subtraction.  So if other is smaller than 10**exp we replace
     # it with 10**exp.  This avoids tmp.exp - other.exp getting too large.
-    if shouldround:
-        tmp_len = len(str(tmp.int))
-        other_len = len(str(other.int))
-        exp = tmp.exp + min(-1, tmp_len - prec - 2)
-        if other_len + other.exp - 1 < exp:
-            other.int = 1
-            other.exp = exp
+    tmp_len = len(str(tmp.int))
+    other_len = len(str(other.int))
+    exp = tmp.exp + min(-1, tmp_len - prec - 2)
+    if other_len + other.exp - 1 < exp:
+        other.int = 1
+        other.exp = exp
 
     tmp.int *= 10 ** (tmp.exp - other.exp)
     tmp.exp = other.exp
@@ -4937,7 +5061,7 @@
             c = _div_nearest(c, 10**-k)
 
         log_d = _ilog(c, M) # error < 5 + 22 = 27
-        log_10 = _ilog(10*M, M) # error < 15
+        log_10 = _log10_digits(p) # error < 1
         log_d = _div_nearest(log_d*M, log_10)
         log_tenpower = f*M # exact
     else:
@@ -4975,24 +5099,58 @@
         # p <= 0: just approximate the whole thing by 0; error < 2.31
         log_d = 0
 
-    # compute approximation to 10**p*f*log(10), with error < 17
+    # compute approximation to f*10**p*log(10), with error < 11.
     if f:
-        sign_f = [-1, 1][f > 0]
-        if p >= 0:
-            M = 10**p * abs(f)
-        else:
-            M = _div_nearest(abs(f), 10**-p) # M = 10**p*|f|, error <= 0.5
-
-        if M:
-            f_log_ten = sign_f*_ilog(10*M, M)   # M*log(10), error <= 1.2 + 15 < 17
+        extra = len(str(abs(f)))-1
+        if p + extra >= 0:
+            # error in f * _log10_digits(p+extra) < |f| * 1 = |f|
+            # after division, error < |f|/10**extra + 0.5 < 10 + 0.5 < 11
+            f_log_ten = _div_nearest(f*_log10_digits(p+extra), 10**extra)
         else:
             f_log_ten = 0
     else:
         f_log_ten = 0
 
-    # error in sum < 17+27 = 44; error after division < 0.44 + 0.5 < 1
+    # error in sum < 11+27 = 38; error after division < 0.38 + 0.5 < 1
     return _div_nearest(f_log_ten + log_d, 100)
 
+class _Log10Memoize(object):
+    """Class to compute, store, and allow retrieval of, digits of the
+    constant log(10) = 2.302585....  This constant is needed by
+    Decimal.ln, Decimal.log10, Decimal.exp and Decimal.__pow__."""
+    def __init__(self):
+        self.digits = "23025850929940456840179914546843642076011014886"
+
+    def getdigits(self, p):
+        """Given an integer p >= 0, return floor(10**p)*log(10).
+
+        For example, self.getdigits(3) returns 2302.
+        """
+        # digits are stored as a string, for quick conversion to
+        # integer in the case that we've already computed enough
+        # digits; the stored digits should always be correct
+        # (truncated, not rounded to nearest).
+        if p < 0:
+            raise ValueError("p should be nonnegative")
+
+        if p >= len(self.digits):
+            # compute p+3, p+6, p+9, ... digits; continue until at
+            # least one of the extra digits is nonzero
+            extra = 3
+            while True:
+                # compute p+extra digits, correct to within 1ulp
+                M = 10**(p+extra+2)
+                digits = str(_div_nearest(_ilog(10*M, M), 100))
+                if digits[-extra:] != '0'*extra:
+                    break
+                extra += 3
+            # keep all reliable digits so far; remove trailing zeros
+            # and next nonzero digit
+            self.digits = digits.rstrip('0')[:-1]
+        return int(self.digits[:p+1])
+
+_log10_digits = _Log10Memoize().getdigits
+
 def _iexp(x, M, L=8):
     """Given integers x and M, M > 0, such that x/M is small in absolute
     value, compute an integer approximation to M*exp(x/M).  For 0 <=
@@ -5034,7 +5192,7 @@
     """Compute an approximation to exp(c*10**e), with p decimal places of
     precision.
 
-    Returns d, f such that:
+    Returns integers d, f such that:
 
       10**(p-1) <= d <= 10**p, and
       (d-1)*10**f < exp(c*10**e) < (d+1)*10**f
@@ -5047,19 +5205,18 @@
     # we'll call iexp with M = 10**(p+2), giving p+3 digits of precision
     p += 2
 
-    # compute log10 with extra precision = adjusted exponent of c*10**e
+    # compute log(10) with extra precision = adjusted exponent of c*10**e
     extra = max(0, e + len(str(c)) - 1)
     q = p + extra
-    log10 = _dlog(10, 0, q)  # error <= 1
 
-    # compute quotient c*10**e/(log10/10**q) = c*10**(e+q)/log10,
+    # compute quotient c*10**e/(log(10)) = c*10**(e+q)/(log(10)*10**q),
     # rounding down
     shift = e+q
     if shift >= 0:
         cshift = c*10**shift
     else:
         cshift = c//10**-shift
-    quot, rem = divmod(cshift, log10)
+    quot, rem = divmod(cshift, _log10_digits(q))
 
     # reduce remainder back to original precision
     rem = _div_nearest(rem, 10**extra)
@@ -5133,53 +5290,6 @@
         raise TypeError("Unable to convert %s to Decimal" % other)
     return NotImplemented
 
-_infinity_map = {
-    'inf' : 1,
-    'infinity' : 1,
-    '+inf' : 1,
-    '+infinity' : 1,
-    '-inf' : -1,
-    '-infinity' : -1
-}
-
-def _isinfinity(num):
-    """Determines whether a string or float is infinity.
-
-    +1 for negative infinity; 0 for finite ; +1 for positive infinity
-    """
-    num = str(num).lower()
-    return _infinity_map.get(num, 0)
-
-def _isnan(num):
-    """Determines whether a string or float is NaN
-
-    (1, sign, diagnostic info as string) => NaN
-    (2, sign, diagnostic info as string) => sNaN
-    0 => not a NaN
-    """
-    num = str(num).lower()
-    if not num:
-        return 0
-
-    # Get the sign, get rid of trailing [+-]
-    sign = 0
-    if num[0] == '+':
-        num = num[1:]
-    elif num[0] == '-':  # elif avoids '+-nan'
-        num = num[1:]
-        sign = 1
-
-    if num.startswith('nan'):
-        if len(num) > 3 and not num[3:].isdigit():  # diagnostic info
-            return 0
-        return (1, sign, num[3:].lstrip('0'))
-    if num.startswith('snan'):
-        if len(num) > 4 and not num[4:].isdigit():
-            return 0
-        return (2, sign, num[4:].lstrip('0'))
-    return 0
-
-
 ##### Setup Specific Contexts ############################################
 
 # The default context prototype used by Context()
@@ -5189,7 +5299,6 @@
         prec=28, rounding=ROUND_HALF_EVEN,
         traps=[DivisionByZero, Overflow, InvalidOperation],
         flags=[],
-        _rounding_decision=ALWAYS_ROUND,
         Emax=999999999,
         Emin=-999999999,
         capitals=1
@@ -5213,91 +5322,185 @@
 )
 
 
-##### Useful Constants (internal use only) ################################
-
-# Reusable defaults
-Inf = Decimal('Inf')
-negInf = Decimal('-Inf')
-NaN = Decimal('NaN')
-Dec_0 = Decimal(0)
-Dec_p1 = Decimal(1)
-Dec_n1 = Decimal(-1)
-Dec_p2 = Decimal(2)
-Dec_n2 = Decimal(-2)
-
-# Infsign[sign] is infinity w/ that sign
-Infsign = (Inf, negInf)
-
-
 ##### crud for parsing strings #############################################
-import re
-
-# There's an optional sign at the start, and an optional exponent
-# at the end.  The exponent has an optional sign and at least one
-# digit.  In between, must have either at least one digit followed
-# by an optional fraction, or a decimal point followed by at least
-# one digit.  Yuck.
+#
+# Regular expression used for parsing numeric strings.  Additional
+# comments:
+#
+# 1. Uncomment the two '\s*' lines to allow leading and/or trailing
+# whitespace.  But note that the specification disallows whitespace in
+# a numeric string.
+#
+# 2. For finite numbers (not infinities and NaNs) the body of the
+# number between the optional sign and the optional exponent must have
+# at least one decimal digit, possibly after the decimal point.  The
+# lookahead expression '(?=\d|\.\d)' checks this.
+#
+# As the flag UNICODE is not enabled here, we're explicitly avoiding any
+# other meaning for \d than the numbers [0-9].
 
-_parser = re.compile(r"""
+import re
+_parser = re.compile(r"""     # A numeric string consists of:
 #    \s*
-    (?P<sign>[-+])?
+    (?P<sign>[-+])?           # an optional sign, followed by either...
     (
-        (?P<int>\d+) (\. (?P<frac>\d*))?
+        (?=\d|\.\d)           # ...a number (with at least one digit)
+        (?P<int>\d*)          # consisting of a (possibly empty) integer part
+        (\.(?P<frac>\d*))?    # followed by an optional fractional part
+        (E(?P<exp>[-+]?\d+))? # followed by an optional exponent, or...
+    |
+        Inf(inity)?           # ...an infinity, or...
     |
-        \. (?P<onlyfrac>\d+)
+        (?P<signal>s)?        # ...an (optionally signaling)
+        NaN                   # NaN
+        (?P<diag>\d*)         # with (possibly empty) diagnostic information.
     )
-    ([eE](?P<exp>[-+]? \d+))?
 #    \s*
-    $
-""", re.VERBOSE).match  # Uncomment the \s* to allow leading or trailing spaces.
+    \Z
+""", re.VERBOSE | re.IGNORECASE).match
+
+_all_zeros = re.compile('0*$').match
+_exact_half = re.compile('50*$').match
+
+##### PEP3101 support functions ##############################################
+# The functions parse_format_specifier and format_align have little to do
+# with the Decimal class, and could potentially be reused for other pure
+# Python numeric classes that want to implement __format__
+#
+# A format specifier for Decimal looks like:
+#
+#   [[fill]align][sign][0][minimumwidth][.precision][type]
+#
+
+_parse_format_specifier_regex = re.compile(r"""\A
+(?:
+   (?P<fill>.)?
+   (?P<align>[<>=^])
+)?
+(?P<sign>[-+ ])?
+(?P<zeropad>0)?
+(?P<minimumwidth>(?!0)\d+)?
+(?:\.(?P<precision>0|(?!0)\d+))?
+(?P<type>[eEfFgG%])?
+\Z
+""", re.VERBOSE)
 
 del re
 
-def _string2exact(s):
-    """Return sign, n, p s.t.
+def _parse_format_specifier(format_spec):
+    """Parse and validate a format specifier.
+
+    Turns a standard numeric format specifier into a dict, with the
+    following entries:
+
+      fill: fill character to pad field to minimum width
+      align: alignment type, either '<', '>', '=' or '^'
+      sign: either '+', '-' or ' '
+      minimumwidth: nonnegative integer giving minimum width
+      precision: nonnegative integer giving precision, or None
+      type: one of the characters 'eEfFgG%', or None
+      unicode: either True or False (always True for Python 3.x)
 
-    Float string value == -1**sign * n * 10**p exactly
     """
-    m = _parser(s)
+    m = _parse_format_specifier_regex.match(format_spec)
     if m is None:
-        raise ValueError("invalid literal for Decimal: %r" % s)
+        raise ValueError("Invalid format specifier: " + format_spec)
 
-    if m.group('sign') == "-":
-        sign = 1
-    else:
-        sign = 0
+    # get the dictionary
+    format_dict = m.groupdict()
 
-    exp = m.group('exp')
-    if exp is None:
-        exp = 0
-    else:
-        exp = int(exp)
+    # defaults for fill and alignment
+    fill = format_dict['fill']
+    align = format_dict['align']
+    if format_dict.pop('zeropad') is not None:
+        # in the face of conflict, refuse the temptation to guess
+        if fill is not None and fill != '0':
+            raise ValueError("Fill character conflicts with '0'"
+                             " in format specifier: " + format_spec)
+        if align is not None and align != '=':
+            raise ValueError("Alignment conflicts with '0' in "
+                             "format specifier: " + format_spec)
+        fill = '0'
+        align = '='
+    format_dict['fill'] = fill or ' '
+    format_dict['align'] = align or '<'
+
+    if format_dict['sign'] is None:
+        format_dict['sign'] = '-'
+
+    # turn minimumwidth and precision entries into integers.
+    # minimumwidth defaults to 0; precision remains None if not given
+    format_dict['minimumwidth'] = int(format_dict['minimumwidth'] or '0')
+    if format_dict['precision'] is not None:
+        format_dict['precision'] = int(format_dict['precision'])
+
+    # if format type is 'g' or 'G' then a precision of 0 makes little
+    # sense; convert it to 1.  Same if format type is unspecified.
+    if format_dict['precision'] == 0:
+        if format_dict['type'] in 'gG' or format_dict['type'] is None:
+            format_dict['precision'] = 1
+
+    # record whether return type should be str or unicode
+    format_dict['unicode'] = True
+
+    return format_dict
+
+def _format_align(body, spec_dict):
+    """Given an unpadded, non-aligned numeric string, add padding and
+    aligment to conform with the given format specifier dictionary (as
+    output from parse_format_specifier).
+
+    It's assumed that if body is negative then it starts with '-'.
+    Any leading sign ('-' or '+') is stripped from the body before
+    applying the alignment and padding rules, and replaced in the
+    appropriate position.
 
-    intpart = m.group('int')
-    if intpart is None:
-        intpart = ""
-        fracpart = m.group('onlyfrac')
+    """
+    # figure out the sign; we only examine the first character, so if
+    # body has leading whitespace the results may be surprising.
+    if len(body) > 0 and body[0] in '-+':
+        sign = body[0]
+        body = body[1:]
     else:
-        fracpart = m.group('frac')
-        if fracpart is None:
-            fracpart = ""
-
-    exp -= len(fracpart)
-
-    mantissa = intpart + fracpart
-    tmp = list(map(int, mantissa))
-    backup = tmp
-    while tmp and tmp[0] == 0:
-        del tmp[0]
-
-    # It's a zero
-    if not tmp:
-        if backup:
-            return (sign, tuple(backup), exp)
-        return (sign, (0,), exp)
-    mantissa = tuple(tmp)
+        sign = ''
+
+    if sign != '-':
+        if spec_dict['sign'] in ' +':
+            sign = spec_dict['sign']
+        else:
+            sign = ''
+
+    # how much extra space do we have to play with?
+    minimumwidth = spec_dict['minimumwidth']
+    fill = spec_dict['fill']
+    padding = fill*(max(minimumwidth - (len(sign+body)), 0))
+
+    align = spec_dict['align']
+    if align == '<':
+        result = padding + sign + body
+    elif align == '>':
+        result = sign + body + padding
+    elif align == '=':
+        result = sign + padding + body
+    else: #align == '^'
+        half = len(padding)//2
+        result = padding[:half] + sign + body + padding[half:]
+
+    return result
+
+##### Useful Constants (internal use only) ################################
+
+# Reusable defaults
+Inf = Decimal('Inf')
+negInf = Decimal('-Inf')
+NaN = Decimal('NaN')
+Dec_0 = Decimal(0)
+Dec_p1 = Decimal(1)
+Dec_n1 = Decimal(-1)
+
+# Infsign[sign] is infinity w/ that sign
+Infsign = (Inf, negInf)
 
-    return (sign, mantissa, exp)
 
 
 if __name__ == '__main__':

Modified: python/branches/py3k-importlib/Lib/difflib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/difflib.py	(original)
+++ python/branches/py3k-importlib/Lib/difflib.py	Thu Mar 27 00:48:05 2008
@@ -30,9 +30,12 @@
 
 __all__ = ['get_close_matches', 'ndiff', 'restore', 'SequenceMatcher',
            'Differ','IS_CHARACTER_JUNK', 'IS_LINE_JUNK', 'context_diff',
-           'unified_diff', 'HtmlDiff']
+           'unified_diff', 'HtmlDiff', 'Match']
 
 import heapq
+from collections import namedtuple as _namedtuple
+
+Match = _namedtuple('Match', 'a b size')
 
 def _calculate_ratio(matches, length):
     if length:
@@ -363,7 +366,7 @@
 
         >>> s = SequenceMatcher(None, " abcd", "abcd abcd")
         >>> s.find_longest_match(0, 5, 0, 9)
-        (0, 4, 5)
+        Match(a=0, b=4, size=5)
 
         If isjunk is defined, first the longest matching block is
         determined as above, but with the additional restriction that no
@@ -379,13 +382,13 @@
 
         >>> s = SequenceMatcher(lambda x: x==" ", " abcd", "abcd abcd")
         >>> s.find_longest_match(0, 5, 0, 9)
-        (1, 0, 4)
+        Match(a=1, b=0, size=4)
 
         If no blocks match, return (alo, blo, 0).
 
         >>> s = SequenceMatcher(None, "ab", "c")
         >>> s.find_longest_match(0, 2, 0, 1)
-        (0, 0, 0)
+        Match(a=0, b=0, size=0)
         """
 
         # CAUTION:  stripping common prefix or suffix would be incorrect.
@@ -452,7 +455,7 @@
               a[besti+bestsize] == b[bestj+bestsize]:
             bestsize = bestsize + 1
 
-        return besti, bestj, bestsize
+        return Match(besti, bestj, bestsize)
 
     def get_matching_blocks(self):
         """Return list of triples describing matching subsequences.
@@ -469,8 +472,8 @@
         triple with n==0.
 
         >>> s = SequenceMatcher(None, "abxcd", "abcd")
-        >>> s.get_matching_blocks()
-        [(0, 0, 2), (3, 2, 2), (5, 4, 0)]
+        >>> list(s.get_matching_blocks())
+        [Match(a=0, b=0, size=2), Match(a=3, b=2, size=2), Match(a=5, b=4, size=0)]
         """
 
         if self.matching_blocks is not None:
@@ -523,7 +526,7 @@
 
         non_adjacent.append( (la, lb, 0) )
         self.matching_blocks = non_adjacent
-        return self.matching_blocks
+        return map(Match._make, self.matching_blocks)
 
     def get_opcodes(self):
         """Return list of 5-tuples describing how to turn a into b.

Modified: python/branches/py3k-importlib/Lib/dis.py
==============================================================================
--- python/branches/py3k-importlib/Lib/dis.py	(original)
+++ python/branches/py3k-importlib/Lib/dis.py	Thu Mar 27 00:48:05 2008
@@ -18,8 +18,8 @@
     if x is None:
         distb()
         return
-    if hasattr(x, 'im_func'):
-        x = x.im_func
+    if hasattr(x, '__func__'):
+        x = x.__func__
     if hasattr(x, '__code__'):
         x = x.__code__
     if hasattr(x, '__dict__'):
@@ -117,8 +117,7 @@
     extended_arg = 0
     free = None
     while i < n:
-        c = code[i]
-        op = ord(c)
+        op = code[i]
         if i in linestarts:
             if i > 0:
                 print()
@@ -134,7 +133,7 @@
         print(opname[op].ljust(20), end=' ')
         i = i+1
         if op >= HAVE_ARGUMENT:
-            oparg = ord(code[i]) + ord(code[i+1])*256 + extended_arg
+            oparg = code[i] + code[i+1]*256 + extended_arg
             extended_arg = 0
             i = i+2
             if op == EXTENDED_ARG:
@@ -162,8 +161,7 @@
     n = len(code)
     i = 0
     while i < n:
-        c = code[i]
-        op = ord(c)
+        op = code[i]
         if i == lasti: print('-->', end=' ')
         else: print('   ', end=' ')
         if i in labels: print('>>', end=' ')
@@ -172,7 +170,7 @@
         print(opname[op].ljust(15), end=' ')
         i = i+1
         if op >= HAVE_ARGUMENT:
-            oparg = ord(code[i]) + ord(code[i+1])*256
+            oparg = code[i] + code[i+1]*256
             i = i+2
             print(repr(oparg).rjust(5), end=' ')
             if op in hasconst:
@@ -208,11 +206,10 @@
     n = len(code)
     i = 0
     while i < n:
-        c = code[i]
-        op = ord(c)
+        op = code[i]
         i = i+1
         if op >= HAVE_ARGUMENT:
-            oparg = ord(code[i]) + ord(code[i+1])*256
+            oparg = code[i] + code[i+1]*256
             i = i+2
             label = -1
             if op in hasjrel:
@@ -230,8 +227,8 @@
     Generate pairs (offset, lineno) as described in Python/compile.c.
 
     """
-    byte_increments = [ord(c) for c in code.co_lnotab[0::2]]
-    line_increments = [ord(c) for c in code.co_lnotab[1::2]]
+    byte_increments = list(code.co_lnotab[0::2])
+    line_increments = list(code.co_lnotab[1::2])
 
     lastlineno = None
     lineno = code.co_firstlineno

Modified: python/branches/py3k-importlib/Lib/distutils/__init__.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/__init__.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/__init__.py	Thu Mar 27 00:48:05 2008
@@ -18,4 +18,4 @@
 # In general, major and minor version should loosely follow the Python
 # version number the distutils code was shipped with.
 #
-__version__ = "2.5.1"
+__version__ = "2.6.0"

Modified: python/branches/py3k-importlib/Lib/distutils/bcppcompiler.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/bcppcompiler.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/bcppcompiler.py	Thu Mar 27 00:48:05 2008
@@ -14,7 +14,7 @@
 __revision__ = "$Id$"
 
 
-import sys, os
+import os
 from distutils.errors import \
      DistutilsExecError, DistutilsPlatformError, \
      CompileError, LibError, LinkError, UnknownFileError

Modified: python/branches/py3k-importlib/Lib/distutils/ccompiler.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/ccompiler.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/ccompiler.py	Thu Mar 27 00:48:05 2008
@@ -147,14 +147,14 @@
         # discovered at run-time, since there are many different ways to do
         # basically the same things with Unix C compilers.
 
-        for key, value in kwargs.items():
+        for key in kwargs:
             if key not in self.executables:
-                raise ValueError("unknown executable '%s' for class %s" % \
+                raise ValueError("unknown executable '%s' for class %s" %
                       (key, self.__class__.__name__))
-            self.set_executable(key, value)
+            self.set_executable(key, kwargs[key])
 
     def set_executable(self, key, value):
-        if isinstance(value, basestring):
+        if isinstance(value, str):
             setattr(self, key, split_quoted(value))
         else:
             setattr(self, key, value)
@@ -175,8 +175,8 @@
         for defn in definitions:
             if not (isinstance(defn, tuple) and
                     (len(defn) in (1, 2) and
-                      (isinstance (defn[1], basestring) or defn[1] is None)) and
-                    isinstance (defn[0], basestring)):
+                      (isinstance (defn[1], str) or defn[1] is None)) and
+                    isinstance (defn[0], str)):
                 raise TypeError(("invalid macro definition '%s': " % defn) + \
                       "must be tuple (string,), (string, string), or " + \
                       "(string, None)")
@@ -318,7 +318,7 @@
         """
         if outdir is None:
             outdir = self.output_dir
-        elif not isinstance(outdir, basestring):
+        elif not isinstance(outdir, str):
             raise TypeError("'output_dir' must be a string or None")
 
         if macros is None:
@@ -415,7 +415,7 @@
         """
         if output_dir is None:
             output_dir = self.output_dir
-        elif not isinstance(output_dir, basestring):
+        elif not isinstance(output_dir, str):
             raise TypeError("'output_dir' must be a string or None")
 
         if macros is None:
@@ -494,7 +494,7 @@
 
         if output_dir is None:
             output_dir = self.output_dir
-        elif not isinstance(output_dir, basestring):
+        elif not isinstance(output_dir, str):
             raise TypeError("'output_dir' must be a string or None")
 
         return (objects, output_dir)

Modified: python/branches/py3k-importlib/Lib/distutils/cmd.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/cmd.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/cmd.py	Thu Mar 27 00:48:05 2008
@@ -213,7 +213,7 @@
         if val is None:
             setattr(self, option, default)
             return default
-        elif not isinstance(val, basestring):
+        elif not isinstance(val, str):
             raise DistutilsOptionError("'%s' must be a %s (got `%s`)"
                                        % (option, what, val))
         return val
@@ -233,11 +233,11 @@
         val = getattr(self, option)
         if val is None:
             return
-        elif isinstance(val, basestring):
+        elif isinstance(val, str):
             setattr(self, option, re.split(r',\s*|\s+', val))
         else:
             if isinstance(val, list):
-                ok = all(isinstance(v, basestring) for v in val)
+                ok = all(isinstance(v, str) for v in val)
             else:
                 ok = False
             if not ok:
@@ -390,7 +390,7 @@
 
 
         # Allow 'infiles' to be a single string
-        if isinstance(infiles, basestring):
+        if isinstance(infiles, str):
             infiles = (infiles,)
         elif not isinstance(infiles, (list, tuple)):
             raise TypeError(

Modified: python/branches/py3k-importlib/Lib/distutils/command/bdist_dumb.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/bdist_dumb.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/bdist_dumb.py	Thu Mar 27 00:48:05 2008
@@ -9,7 +9,7 @@
 import os
 from distutils.core import Command
 from distutils.util import get_platform
-from distutils.dir_util import create_tree, remove_tree, ensure_relative
+from distutils.dir_util import remove_tree, ensure_relative
 from distutils.errors import *
 from distutils.sysconfig import get_python_version
 from distutils import log

Modified: python/branches/py3k-importlib/Lib/distutils/command/bdist_rpm.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/bdist_rpm.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/bdist_rpm.py	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,6 @@
 __revision__ = "$Id$"
 
 import sys, os
-import glob
 from distutils.core import Command
 from distutils.debug import DEBUG
 from distutils.util import get_platform

Modified: python/branches/py3k-importlib/Lib/distutils/command/bdist_wininst.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/bdist_wininst.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/bdist_wininst.py	Thu Mar 27 00:48:05 2008
@@ -304,5 +304,5 @@
         directory = os.path.dirname(__file__)
         # we must use a wininst-x.y.exe built with the same C compiler
         # used for python.  XXX What about mingw, borland, and so on?
-        filename = os.path.join(directory, "wininst-%s.exe" % bv)
+        filename = os.path.join(directory, "wininst-%.1f.exe" % bv)
         return open(filename, "rb").read()

Modified: python/branches/py3k-importlib/Lib/distutils/command/build.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/build.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/build.py	Thu Mar 27 00:48:05 2008
@@ -66,6 +66,12 @@
     def finalize_options(self):
         plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
 
+        # Make it so Python 2.x and Python 2.x with --with-pydebug don't
+        # share the same build directories. Doing so confuses the build
+        # process for C modules
+        if hasattr(sys, 'gettotalrefcount'):
+            plat_specifier += '-pydebug'
+
         # 'build_purelib' and 'build_platlib' just default to 'lib' and
         # 'lib.<plat>' under the base build directory.  We only use one of
         # them for a given distribution, though --

Modified: python/branches/py3k-importlib/Lib/distutils/command/build_clib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/build_clib.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/build_clib.py	Thu Mar 27 00:48:05 2008
@@ -86,7 +86,7 @@
 
         if self.include_dirs is None:
             self.include_dirs = self.distribution.include_dirs or []
-        if isinstance(self.include_dirs, basestring):
+        if isinstance(self.include_dirs, str):
             self.include_dirs = self.include_dirs.split(os.pathsep)
 
         # XXX same as for build_ext -- what about 'self.define' and
@@ -134,7 +134,7 @@
                 raise DistutilsSetupError(
                       "each element of 'libraries' must a 2-tuple")
 
-            if isinstance(lib[0], basestring):
+            if isinstance(lib[0], str):
                 raise DistutilsSetupError(
                       "first element of each tuple in 'libraries' "
                       "must be a string (the library name)")

Modified: python/branches/py3k-importlib/Lib/distutils/command/build_ext.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/build_ext.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/build_ext.py	Thu Mar 27 00:48:05 2008
@@ -14,6 +14,10 @@
 from distutils.extension import Extension
 from distutils import log
 
+if os.name == 'nt':
+    from distutils.msvccompiler import get_build_version
+    MSVC_VERSION = int(get_build_version())
+
 # An extension name is just a dot-separated list of Python NAMEs (ie.
 # the same as a fully-qualified module name).
 extension_name_re = re.compile \
@@ -133,7 +137,7 @@
         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, basestring):
+        if isinstance(self.include_dirs, str):
             self.include_dirs = self.include_dirs.split(os.pathsep)
 
         # Put the Python "system" include dir at the end, so that
@@ -142,7 +146,7 @@
         if plat_py_include != py_include:
             self.include_dirs.append(plat_py_include)
 
-        if isinstance(self.libraries, basestring):
+        if isinstance(self.libraries, str):
             self.libraries = [self.libraries]
 
         # Life is easier if we're not forever checking for None, so
@@ -151,12 +155,12 @@
             self.libraries = []
         if self.library_dirs is None:
             self.library_dirs = []
-        elif isinstance(self.library_dirs, basestring):
+        elif isinstance(self.library_dirs, str):
             self.library_dirs = self.library_dirs.split(os.pathsep)
 
         if self.rpath is None:
             self.rpath = []
-        elif isinstance(self.rpath, basestring):
+        elif isinstance(self.rpath, str):
             self.rpath = self.rpath.split(os.pathsep)
 
         # for extensions under windows use different directories
@@ -172,7 +176,15 @@
             # Append the source distribution include and library directories,
             # this allows distutils on windows to work in the source tree
             self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC'))
-            self.library_dirs.append(os.path.join(sys.exec_prefix, 'PCBuild'))
+            if MSVC_VERSION == 9:
+                self.library_dirs.append(os.path.join(sys.exec_prefix,
+                                         'PCbuild'))
+            elif MSVC_VERSION == 8:
+                self.library_dirs.append(os.path.join(sys.exec_prefix,
+                                         'PC', 'VS8.0', 'win32release'))
+            else:
+                self.library_dirs.append(os.path.join(sys.exec_prefix,
+                                         'PC', 'VS7.1'))
 
         # OS/2 (EMX) doesn't support Debug vs Release builds, but has the
         # import libraries in its "Config" subdirectory
@@ -309,7 +321,7 @@
                        "each element of 'ext_modules' option must be an "
                        "Extension instance or 2-tuple")
 
-            if not (isinstance(ext_name, basestring) and
+            if not (isinstance(ext_name, str) and
                     extension_name_re.match(ext_name)):
                 raise DistutilsSetupError(
                        "first element of each tuple in 'ext_modules' "

Modified: python/branches/py3k-importlib/Lib/distutils/command/build_py.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/build_py.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/build_py.py	Thu Mar 27 00:48:05 2008
@@ -325,7 +325,7 @@
         return outputs
 
     def build_module(self, module, module_file, package):
-        if isinstance(package, basestring):
+        if isinstance(package, str):
             package = package.split('.')
         elif not isinstance(package, (list, tuple)):
             raise TypeError(
@@ -383,3 +383,38 @@
         if self.optimize > 0:
             byte_compile(files, optimize=self.optimize,
                          force=self.force, prefix=prefix, dry_run=self.dry_run)
+
+class build_py_2to3(build_py):
+    def run(self):
+        self.updated_files = []
+
+        # Base class code
+        if self.py_modules:
+            self.build_modules()
+        if self.packages:
+            self.build_packages()
+            self.build_package_data()
+
+        # 2to3
+        from lib2to3.refactor import RefactoringTool
+        class Options:
+            pass
+        o = Options()
+        o.doctests_only = False
+        o.fix = []
+        o.list_fixes = []
+        o.print_function = False
+        o.verbose = False
+        o.write = True
+        r = RefactoringTool(o)
+        r.refactor_args(self.updated_files)
+
+        # Remaining base class code
+        self.byte_compile(self.get_outputs(include_bytecode=0))
+
+    def build_module(self, module, module_file, package):
+        res = build_py.build_module(self, module, module_file, package)
+        if res[1]:
+            # file was copied
+            self.updated_files.append(res[0])
+        return res

Modified: python/branches/py3k-importlib/Lib/distutils/command/build_scripts.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/build_scripts.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/build_scripts.py	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,7 @@
 
 __revision__ = "$Id$"
 
-import sys, os, re
+import os, re
 from stat import ST_MODE
 from distutils import sysconfig
 from distutils.core import Command
@@ -110,7 +110,8 @@
                 if f:
                     f.close()
             else:
-                f.close()
+                if f:
+                    f.close()
                 self.copy_file(script, outfile)
 
         if os.name == 'posix':

Modified: python/branches/py3k-importlib/Lib/distutils/command/config.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/config.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/config.py	Thu Mar 27 00:48:05 2008
@@ -69,17 +69,17 @@
     def finalize_options(self):
         if self.include_dirs is None:
             self.include_dirs = self.distribution.include_dirs or []
-        elif isinstance(self.include_dirs, basestring):
+        elif isinstance(self.include_dirs, str):
             self.include_dirs = self.include_dirs.split(os.pathsep)
 
         if self.libraries is None:
             self.libraries = []
-        elif isinstance(self.libraries, basestring):
+        elif isinstance(self.libraries, str):
             self.libraries = [self.libraries]
 
         if self.library_dirs is None:
             self.library_dirs = []
-        elif isinstance(self.library_dirs, basestring):
+        elif isinstance(self.library_dirs, str):
             self.library_dirs = self.library_dirs.split(os.pathsep)
 
     def run(self):
@@ -204,7 +204,7 @@
         self._check_compiler()
         (src, out) = self._preprocess(body, headers, include_dirs, lang)
 
-        if isinstance(pattern, basestring):
+        if isinstance(pattern, str):
             pattern = re.compile(pattern)
 
         file = open(out)

Modified: python/branches/py3k-importlib/Lib/distutils/command/install.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/install.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/install.py	Thu Mar 27 00:48:05 2008
@@ -14,7 +14,6 @@
 from distutils.file_util import write_file
 from distutils.util import convert_path, subst_vars, change_root
 from distutils.errors import DistutilsOptionError
-from glob import glob
 
 if sys.version < "2.2":
     WINDOWS_SCHEME = {
@@ -449,7 +448,7 @@
             self.extra_path = self.distribution.extra_path
 
         if self.extra_path is not None:
-            if isinstance(self.extra_path, basestring):
+            if isinstance(self.extra_path, str):
                 self.extra_path = self.extra_path.split(',')
 
             if len(self.extra_path) == 1:

Modified: python/branches/py3k-importlib/Lib/distutils/command/install_data.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/install_data.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/install_data.py	Thu Mar 27 00:48:05 2008
@@ -45,7 +45,7 @@
     def run(self):
         self.mkpath(self.install_dir)
         for f in self.data_files:
-            if isinstance(f, basestring):
+            if isinstance(f, str):
                 # it's a simple file, so copy it
                 f = convert_path(f)
                 if self.warn_dir:

Modified: python/branches/py3k-importlib/Lib/distutils/command/install_headers.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/install_headers.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/install_headers.py	Thu Mar 27 00:48:05 2008
@@ -5,7 +5,6 @@
 
 __revision__ = "$Id$"
 
-import os
 from distutils.core import Command
 
 

Modified: python/branches/py3k-importlib/Lib/distutils/command/register.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/register.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/register.py	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,7 @@
 
 __revision__ = "$Id$"
 
-import sys, os, urllib2, getpass, urlparse
+import os, string, urllib2, getpass, urlparse
 import io, ConfigParser
 
 from distutils.core import Command

Modified: python/branches/py3k-importlib/Lib/distutils/command/sdist.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/sdist.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/command/sdist.py	Thu Mar 27 00:48:05 2008
@@ -325,14 +325,14 @@
           * the build tree (typically "build")
           * the release tree itself (only an issue if we ran "sdist"
             previously with --keep-temp, or it aborted)
-          * any RCS, CVS and .svn directories
+          * any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories
         """
         build = self.get_finalized_command('build')
         base_dir = self.distribution.get_fullname()
 
         self.filelist.exclude_pattern(None, prefix=build.build_base)
         self.filelist.exclude_pattern(None, prefix=base_dir)
-        self.filelist.exclude_pattern(r'/(RCS|CVS|\.svn)/.*', is_regex=1)
+        self.filelist.exclude_pattern(r'(^|/)(RCS|CVS|\.svn|\.hg|\.git|\.bzr|_darcs)/.*', is_regex=1)
 
     def write_manifest(self):
         """Write the file list in 'self.filelist' (presumably as filled in
@@ -357,6 +357,7 @@
             if line[-1] == '\n':
                 line = line[0:-1]
             self.filelist.append(line)
+        manifest.close()
 
     def make_release_tree(self, base_dir, files):
         """Create the directory tree that will become the source

Deleted: /python/branches/py3k-importlib/Lib/distutils/command/wininst-6.exe
==============================================================================
Binary file. No diff available.

Deleted: /python/branches/py3k-importlib/Lib/distutils/command/wininst-8.exe
==============================================================================
Binary file. No diff available.

Modified: python/branches/py3k-importlib/Lib/distutils/cygwinccompiler.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/cygwinccompiler.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/cygwinccompiler.py	Thu Mar 27 00:48:05 2008
@@ -54,6 +54,29 @@
 from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
 from distutils import log
 
+def get_msvcr():
+    """Include the appropriate MSVC runtime library if Python was built
+    with MSVC 7.0 or later.
+    """
+    msc_pos = sys.version.find('MSC v.')
+    if msc_pos != -1:
+        msc_ver = sys.version[msc_pos+6:msc_pos+10]
+        if msc_ver == '1300':
+            # MSVC 7.0
+            return ['msvcr70']
+        elif msc_ver == '1310':
+            # MSVC 7.1
+            return ['msvcr71']
+        elif msc_ver == '1400':
+            # VS2005 / MSVC 8.0
+            return ['msvcr80']
+        elif msc_ver == '1500':
+            # VS2008 / MSVC 9.0
+            return ['msvcr90']
+        else:
+            raise ValueError("Unknown MS Compiler version %i " % msc_Ver)
+
+
 class CygwinCCompiler (UnixCCompiler):
 
     compiler_type = 'cygwin'
@@ -119,18 +142,9 @@
             self.warn(
                 "Consider upgrading to a newer version of gcc")
         else:
-            self.dll_libraries=[]
             # Include the appropriate MSVC runtime library if Python was built
-            # with MSVC 7.0 or 7.1.
-            msc_pos = sys.version.find('MSC v.')
-            if msc_pos != -1:
-                msc_ver = sys.version[msc_pos+6:msc_pos+10]
-                if msc_ver == '1300':
-                    # MSVC 7.0
-                    self.dll_libraries = ['msvcr70']
-                elif msc_ver == '1310':
-                    # MSVC 7.1
-                    self.dll_libraries = ['msvcr71']
+            # with MSVC 7.0 or later.
+            self.dll_libraries = get_msvcr()
 
     # __init__ ()
 
@@ -317,16 +331,8 @@
         self.dll_libraries=[]
 
         # Include the appropriate MSVC runtime library if Python was built
-        # with MSVC 7.0 or 7.1.
-        msc_pos = sys.version.find('MSC v.')
-        if msc_pos != -1:
-            msc_ver = sys.version[msc_pos+6:msc_pos+10]
-            if msc_ver == '1300':
-                # MSVC 7.0
-                self.dll_libraries = ['msvcr70']
-            elif msc_ver == '1310':
-                # MSVC 7.1
-                self.dll_libraries = ['msvcr71']
+        # with MSVC 7.0 or later.
+        self.dll_libraries = get_msvcr()
 
     # __init__ ()
 

Modified: python/branches/py3k-importlib/Lib/distutils/dir_util.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/dir_util.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/dir_util.py	Thu Mar 27 00:48:05 2008
@@ -28,7 +28,7 @@
     global _path_created
 
     # Detect a common bug -- name is None
-    if not isinstance(name, basestring):
+    if not isinstance(name, str):
         raise DistutilsInternalError(
               "mkpath: 'name' must be a string (got %r)" % (name,))
 

Modified: python/branches/py3k-importlib/Lib/distutils/dist.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/dist.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/dist.py	Thu Mar 27 00:48:05 2008
@@ -580,13 +580,13 @@
 
         keywords = self.metadata.keywords
         if keywords is not None:
-            if isinstance(keywords, basestring):
+            if isinstance(keywords, str):
                 keywordlist = keywords.split(',')
                 self.metadata.keywords = [x.strip() for x in keywordlist]
 
         platforms = self.metadata.platforms
         if platforms is not None:
-            if isinstance(platforms, basestring):
+            if isinstance(platforms, str):
                 platformlist = platforms.split(',')
                 self.metadata.platforms = [x.strip() for x in platformlist]
 
@@ -874,7 +874,7 @@
                 neg_opt = {}
 
             try:
-                is_string = isinstance(value, basestring)
+                is_string = isinstance(value, str)
                 if option in neg_opt and is_string:
                     setattr(command_obj, neg_opt[option], not strtobool(value))
                 elif option in bool_opts and is_string:

Modified: python/branches/py3k-importlib/Lib/distutils/extension.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/extension.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/extension.py	Thu Mar 27 00:48:05 2008
@@ -102,9 +102,9 @@
                   language=None,
                   **kw                      # To catch unknown keywords
                  ):
-        assert isinstance(name, basestring), "'name' must be a string"
+        assert isinstance(name, str), "'name' must be a string"
         assert (isinstance(sources, list) and
-                all(isinstance(v, basestring) for v in sources)), \
+                all(isinstance(v, str) for v in sources)), \
                 "'sources' must be a list of strings"
 
         self.name = name

Modified: python/branches/py3k-importlib/Lib/distutils/fancy_getopt.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/fancy_getopt.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/fancy_getopt.py	Thu Mar 27 00:48:05 2008
@@ -154,12 +154,12 @@
                 raise ValueError("invalid option tuple: %r" % (option,))
 
             # Type- and value-check the option names
-            if not isinstance(long, basestring) or len(long) < 2:
+            if not isinstance(long, str) or len(long) < 2:
                 raise DistutilsGetoptError(("invalid long option '%s': "
                        "must be a string of length >= 2") % long)
 
             if (not ((short is None) or
-                     (isinstance(short, basestring) and len(short) == 1))):
+                     (isinstance(short, str) and len(short) == 1))):
                 raise DistutilsGetoptError("invalid short option '%s': "
                        "must a single character or None" % short)
 

Modified: python/branches/py3k-importlib/Lib/distutils/file_util.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/file_util.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/file_util.py	Thu Mar 27 00:48:05 2008
@@ -139,7 +139,7 @@
             macostools.copy(src, dst, 0, preserve_times)
         except os.error as exc:
             raise DistutilsFileError(
-                  "could not copy '%s' to '%s': %s" % (src, dst, exc[-1]))
+                  "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)

Modified: python/branches/py3k-importlib/Lib/distutils/filelist.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/filelist.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/filelist.py	Thu Mar 27 00:48:05 2008
@@ -8,7 +8,6 @@
 
 import os, re
 import fnmatch
-from glob import glob
 from distutils.util import convert_path
 from distutils.errors import DistutilsTemplateError, DistutilsInternalError
 from distutils import log
@@ -301,7 +300,7 @@
     or just returned as-is (assumes it's a regex object).
     """
     if is_regex:
-        if isinstance(pattern, basestring):
+        if isinstance(pattern, str):
             return re.compile(pattern)
         else:
             return pattern

Modified: python/branches/py3k-importlib/Lib/distutils/msvccompiler.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/msvccompiler.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/msvccompiler.py	Thu Mar 27 00:48:05 2008
@@ -93,10 +93,10 @@
     return d
 
 def convert_mbcs(s):
-    enc = getattr(s, "encode", None)
-    if enc is not None:
+    dec = getattr(s, "decode", None)
+    if dec is not None:
         try:
-            s = enc("mbcs")
+            s = dec("mbcs")
         except UnicodeError:
             pass
     return s
@@ -632,3 +632,11 @@
             p = self.get_msvc_paths(name)
         if p:
             os.environ[name] = ';'.join(p)
+
+
+if get_build_version() >= 8.0:
+    log.debug("Importing new compiler from distutils.msvc9compiler")
+    OldMSVCCompiler = MSVCCompiler
+    from distutils.msvc9compiler import MSVCCompiler
+    from distutils.msvc9compiler import get_build_architecture
+    from distutils.msvc9compiler import MacroExpander

Modified: python/branches/py3k-importlib/Lib/distutils/spawn.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/spawn.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/spawn.py	Thu Mar 27 00:48:05 2008
@@ -67,7 +67,7 @@
         except OSError as exc:
             # this seems to happen when the command isn't found
             raise DistutilsExecError(
-                  "command '%s' failed: %s" % (cmd[0], exc[-1]))
+                  "command '%s' failed: %s" % (cmd[0], exc.args[-1]))
         if rc != 0:
             # and this reflects the command running but failing
             raise DistutilsExecError(
@@ -88,7 +88,7 @@
         except OSError as exc:
             # this seems to happen when the command isn't found
             raise DistutilsExecError(
-                  "command '%s' failed: %s" % (cmd[0], exc[-1]))
+                  "command '%s' failed: %s" % (cmd[0], exc.args[-1]))
         if rc != 0:
             # and this reflects the command running but failing
             print("command '%s' failed with exit status %d" % (cmd[0], rc))
@@ -124,7 +124,7 @@
                 if exc.errno == errno.EINTR:
                     continue
                 raise DistutilsExecError(
-                      "command '%s' failed: %s" % (cmd[0], exc[-1]))
+                      "command '%s' failed: %s" % (cmd[0], exc.args[-1]))
             if os.WIFSIGNALED(status):
                 raise DistutilsExecError(
                       "command '%s' terminated by signal %d"

Modified: python/branches/py3k-importlib/Lib/distutils/sysconfig.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/sysconfig.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/sysconfig.py	Thu Mar 27 00:48:05 2008
@@ -22,13 +22,32 @@
 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.
-
-argv0_path = os.path.dirname(os.path.abspath(sys.executable))
-python_build = os.path.isfile(os.path.join(argv0_path, "Modules", "Setup"))
-
+# Setup.local is available for Makefile builds including VPATH builds,
+# Setup.dist is available on Windows
+def _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_version():
     """Return a string containing the major and minor Python version,
@@ -177,7 +196,10 @@
 def get_config_h_filename():
     """Return full pathname of installed pyconfig.h file."""
     if python_build:
-        inc_dir = argv0_path
+        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':
@@ -402,6 +424,8 @@
 
     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

Modified: python/branches/py3k-importlib/Lib/distutils/tests/test_dist.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/tests/test_dist.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/tests/test_dist.py	Thu Mar 27 00:48:05 2008
@@ -3,10 +3,8 @@
 import distutils.cmd
 import distutils.dist
 import os
-import shutil
 import io
 import sys
-import tempfile
 import unittest
 
 from test.test_support import TESTFN

Modified: python/branches/py3k-importlib/Lib/distutils/unixccompiler.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/unixccompiler.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/unixccompiler.py	Thu Mar 27 00:48:05 2008
@@ -16,7 +16,6 @@
 __revision__ = "$Id$"
 
 import os, sys
-from copy import copy
 
 from distutils import sysconfig
 from distutils.dep_util import newer
@@ -211,7 +210,7 @@
 
         lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
                                    libraries)
-        if not isinstance(output_dir, (basestring, type(None))):
+        if not isinstance(output_dir, (str, type(None))):
             raise TypeError("'output_dir' must be a string or None")
         if output_dir is not None:
             output_filename = os.path.join(output_dir, output_filename)

Modified: python/branches/py3k-importlib/Lib/distutils/util.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/util.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/util.py	Thu Mar 27 00:48:05 2008
@@ -269,7 +269,7 @@
             # include the filename in the exception object!
             error = prefix + "%s" % exc.strerror
     else:
-        error = prefix + str(exc[-1])
+        error = prefix + str(exc.args[-1])
 
     return error
 

Modified: python/branches/py3k-importlib/Lib/doctest.py
==============================================================================
--- python/branches/py3k-importlib/Lib/doctest.py	(original)
+++ python/branches/py3k-importlib/Lib/doctest.py	Thu Mar 27 00:48:05 2008
@@ -99,6 +99,9 @@
 import unittest, difflib, pdb, tempfile
 import warnings
 from io import StringIO
+from collections import namedtuple
+
+TestResults = namedtuple('TestResults', 'failed attempted')
 
 # There are 4 basic classes:
 #  - Example: a <source, want> pair, plus an intra-docstring line number.
@@ -209,8 +212,11 @@
         filename = _module_relative_path(package, filename)
         if hasattr(package, '__loader__'):
             if hasattr(package.__loader__, 'get_data'):
-                return (package.__loader__.get_data(filename).decode(encoding),
-                        filename)
+                file_contents = package.__loader__.get_data(filename)
+                file_contents = file_contents.decode(encoding)
+                # get_data() opens files as 'rb', so one must do the equivalent
+                # conversion as universal newlines would do.
+                return file_contents.replace(os.linesep, '\n'), filename
     return open(filename, encoding=encoding).read(), filename
 
 def _indent(s, indent=4):
@@ -312,8 +318,21 @@
     """
     def __init__(self, out):
         self.__out = out
+        self.__debugger_used = False
         pdb.Pdb.__init__(self, stdout=out)
 
+    def set_trace(self, frame=None):
+        self.__debugger_used = True
+        if frame is None:
+            frame = sys._getframe().f_back
+        pdb.Pdb.set_trace(self, frame)
+
+    def set_continue(self):
+        # Calling set_continue unconditionally would break unit test
+        # coverage reporting, as Bdb.set_continue calls sys.settrace(None).
+        if self.__debugger_used:
+            pdb.Pdb.set_continue(self)
+
     def trace_dispatch(self, *args):
         # Redirect stdout to the given stream.
         save_stdout = sys.stdout
@@ -443,7 +462,7 @@
         Create a new DocTest containing the given examples.  The
         DocTest's globals are initialized with a copy of `globs`.
         """
-        assert not isinstance(examples, basestring), \
+        assert not isinstance(examples, str), \
                "DocTest no longer accepts str; use DocTestParser instead"
         self.examples = examples
         self.docstring = docstring
@@ -875,13 +894,13 @@
         # Look for tests in a module's __test__ dictionary.
         if inspect.ismodule(obj) and self._recurse:
             for valname, val in getattr(obj, '__test__', {}).items():
-                if not isinstance(valname, basestring):
+                if not isinstance(valname, str):
                     raise ValueError("DocTestFinder.find: __test__ keys "
                                      "must be strings: %r" %
                                      (type(valname),))
                 if not (inspect.isfunction(val) or inspect.isclass(val) or
                         inspect.ismethod(val) or inspect.ismodule(val) or
-                        isinstance(val, basestring)):
+                        isinstance(val, str)):
                     raise ValueError("DocTestFinder.find: __test__ values "
                                      "must be strings, functions, methods, "
                                      "classes, or modules: %r" %
@@ -897,7 +916,7 @@
                 if isinstance(val, staticmethod):
                     val = getattr(obj, valname)
                 if isinstance(val, classmethod):
-                    val = getattr(obj, valname).im_func
+                    val = getattr(obj, valname).__func__
 
                 # Recurse to methods, properties, and nested classes.
                 if ((inspect.isfunction(val) or inspect.isclass(val) or
@@ -914,7 +933,7 @@
         """
         # Extract the object's docstring.  If it doesn't have one,
         # then return None (no test for this object).
-        if isinstance(obj, basestring):
+        if isinstance(obj, str):
             docstring = obj
         else:
             try:
@@ -922,7 +941,7 @@
                     docstring = ''
                 else:
                     docstring = obj.__doc__
-                    if not isinstance(docstring, basestring):
+                    if not isinstance(docstring, str):
                         docstring = str(docstring)
             except (TypeError, AttributeError):
                 docstring = ''
@@ -969,7 +988,7 @@
                     break
 
         # Find the line number for functions & methods.
-        if inspect.ismethod(obj): obj = obj.im_func
+        if inspect.ismethod(obj): obj = obj.__func__
         if inspect.isfunction(obj): obj = obj.__code__
         if inspect.istraceback(obj): obj = obj.tb_frame
         if inspect.isframe(obj): obj = obj.f_code
@@ -1008,10 +1027,10 @@
         >>> tests.sort(key = lambda test: test.name)
         >>> for test in tests:
         ...     print(test.name, '->', runner.run(test))
-        _TestClass -> (0, 2)
-        _TestClass.__init__ -> (0, 2)
-        _TestClass.get -> (0, 2)
-        _TestClass.square -> (0, 1)
+        _TestClass -> TestResults(failed=0, attempted=2)
+        _TestClass.__init__ -> TestResults(failed=0, attempted=2)
+        _TestClass.get -> TestResults(failed=0, attempted=2)
+        _TestClass.square -> TestResults(failed=0, attempted=1)
 
     The `summarize` method prints a summary of all the test cases that
     have been run by the runner, and returns an aggregated `(f, t)`
@@ -1026,7 +1045,7 @@
         7 tests in 4 items.
         7 passed and 0 failed.
         Test passed.
-        (0, 7)
+        TestResults(failed=0, attempted=7)
 
     The aggregated number of tried examples and failed examples is
     also available via the `tries` and `failures` attributes:
@@ -1269,7 +1288,7 @@
 
         # Record and return the number of failures and tries.
         self.__record_outcome(test, failures, tries)
-        return failures, tries
+        return TestResults(failures, tries)
 
     def __record_outcome(self, test, f, t):
         """
@@ -1401,7 +1420,7 @@
             print("***Test Failed***", totalf, "failures.")
         elif verbose:
             print("Test passed.")
-        return totalf, totalt
+        return TestResults(totalf, totalt)
 
     #/////////////////////////////////////////////////////////////////
     # Backward compatibility cruft to maintain doctest.master.
@@ -1672,7 +1691,7 @@
          ...      ''', {}, 'foo', 'foo.py', 0)
 
          >>> runner.run(test)
-         (0, 1)
+         TestResults(failed=0, attempted=1)
 
          >>> test.globs
          {}
@@ -1802,7 +1821,7 @@
     else:
         master.merge(runner)
 
-    return runner.failures, runner.tries
+    return TestResults(runner.failures, runner.tries)
 
 def testfile(filename, module_relative=True, name=None, package=None,
              globs=None, verbose=None, report=True, optionflags=0,
@@ -1923,7 +1942,7 @@
     else:
         master.merge(runner)
 
-    return runner.failures, runner.tries
+    return TestResults(runner.failures, runner.tries)
 
 def run_docstring_examples(f, globs, verbose=False, name="NoName",
                            compileflags=None, optionflags=0):
@@ -1982,7 +2001,7 @@
         (f,t) = self.testrunner.run(test)
         if self.verbose:
             print(f, "of", t, "examples failed in string", name)
-        return (f,t)
+        return TestResults(f,t)
 
     def rundoc(self, object, name=None, module=None):
         f = t = 0
@@ -1991,19 +2010,19 @@
         for test in tests:
             (f2, t2) = self.testrunner.run(test)
             (f,t) = (f+f2, t+t2)
-        return (f,t)
+        return TestResults(f,t)
 
     def rundict(self, d, name, module=None):
-        import new
-        m = new.module(name)
+        import types
+        m = types.ModuleType(name)
         m.__dict__.update(d)
         if module is None:
             module = False
         return self.rundoc(m, name, module)
 
     def run__test__(self, d, name):
-        import new
-        m = new.module(name)
+        import types
+        m = types.ModuleType(name)
         m.__test__ = d
         return self.rundoc(m, name)
 
@@ -2635,12 +2654,15 @@
                 sys.path.insert(0, dirname)
                 m = __import__(filename[:-3])
                 del sys.path[0]
-                testmod(m)
+                failures, _ = testmod(m)
             else:
-                testfile(filename, module_relative=False)
+                failures, _ = testfile(filename, module_relative=False)
+            if failures:
+                return 1
     else:
         r = unittest.TextTestRunner()
         r.run(DocTestSuite())
+    return 0
 
 if __name__ == "__main__":
-    _test()
+    sys.exit(_test())

Modified: python/branches/py3k-importlib/Lib/dumbdbm.py
==============================================================================
--- python/branches/py3k-importlib/Lib/dumbdbm.py	(original)
+++ python/branches/py3k-importlib/Lib/dumbdbm.py	Thu Mar 27 00:48:05 2008
@@ -23,14 +23,13 @@
 
 import io as _io
 import os as _os
-import __builtin__
-import UserDict
+import collections
 
 _BLOCKSIZE = 512
 
 error = IOError                         # For anydbm
 
-class _Database(UserDict.DictMixin):
+class _Database(collections.MutableMapping):
 
     # The on-disk directory and data files can remain in mutually
     # inconsistent states for an arbitrarily long time (see comments
@@ -163,7 +162,7 @@
         if not isinstance(key, bytes):
             raise TypeError("keys must be bytes")
         key = key.decode("latin-1") # hashable bytes
-        if not isinstance(val, (str8, bytes)):
+        if not isinstance(val, (bytes, bytearray)):
             raise TypeError("values must be byte strings")
         if key not in self._index:
             self._addkey(key, self._addval(val))

Modified: python/branches/py3k-importlib/Lib/email/base64mime.py
==============================================================================
--- python/branches/py3k-importlib/Lib/email/base64mime.py	(original)
+++ python/branches/py3k-importlib/Lib/email/base64mime.py	Thu Mar 27 00:48:05 2008
@@ -35,7 +35,6 @@
     'header_length',
     ]
 
-import re
 
 from base64 import b64encode
 from binascii import b2a_base64, a2b_base64
@@ -70,7 +69,7 @@
     # Return empty headers unchanged
     if not header_bytes:
         return str(header_bytes)
-    encoded = b64encode(header_bytes)
+    encoded = b64encode(header_bytes).decode("ascii")
     return '=?%s?b?%s?=' % (charset, encoded)
 
 
@@ -93,7 +92,7 @@
     for i in range(0, len(s), max_unencoded):
         # BAW: should encode() inherit b2a_base64()'s dubious behavior in
         # adding a newline to the encoded string?
-        enc = str(b2a_base64(s[i:i + max_unencoded]))
+        enc = b2a_base64(s[i:i + max_unencoded]).decode("ascii")
         if enc.endswith(NL) and eol != NL:
             enc = enc[:-1] + eol
         encvec.append(enc)

Modified: python/branches/py3k-importlib/Lib/email/feedparser.py
==============================================================================
--- python/branches/py3k-importlib/Lib/email/feedparser.py	(original)
+++ python/branches/py3k-importlib/Lib/email/feedparser.py	Thu Mar 27 00:48:05 2008
@@ -365,7 +365,7 @@
                                 self._last.epilogue = epilogue[:-end]
                     else:
                         payload = self._last.get_payload()
-                        if isinstance(payload, basestring):
+                        if isinstance(payload, str):
                             mo = NLCRE_eol.search(payload)
                             if mo:
                                 payload = payload[:-len(mo.group(0))]

Modified: python/branches/py3k-importlib/Lib/email/generator.py
==============================================================================
--- python/branches/py3k-importlib/Lib/email/generator.py	(original)
+++ python/branches/py3k-importlib/Lib/email/generator.py	Thu Mar 27 00:48:05 2008
@@ -151,7 +151,7 @@
         payload = msg.get_payload()
         if payload is None:
             return
-        if not isinstance(payload, basestring):
+        if not isinstance(payload, str):
             raise TypeError('string payload expected: %s' % type(payload))
         if self._mangle_from_:
             payload = fcre.sub('>From ', payload)
@@ -168,7 +168,7 @@
         subparts = msg.get_payload()
         if subparts is None:
             subparts = []
-        elif isinstance(subparts, basestring):
+        elif isinstance(subparts, str):
             # e.g. a non-strict parse of a message with no starting boundary.
             self._fp.write(subparts)
             return
@@ -288,7 +288,7 @@
         for part in msg.walk():
             maintype = part.get_content_maintype()
             if maintype == 'text':
-                print(part.get_payload(decode=True), file=self)
+                print(part.get_payload(decode=False), file=self)
             elif maintype == 'multipart':
                 # Just skip this
                 pass
@@ -307,13 +307,13 @@
 
 
 # Helper
-_width = len(repr(sys.maxint-1))
+_width = len(repr(sys.maxsize-1))
 _fmt = '%%0%dd' % _width
 
 def _make_boundary(text=None):
     # Craft a random boundary.  If text is given, ensure that the chosen
     # boundary doesn't appear in the text.
-    token = random.randrange(sys.maxint)
+    token = random.randrange(sys.maxsize)
     boundary = ('=' * 15) + (_fmt % token) + '=='
     if text is None:
         return boundary

Modified: python/branches/py3k-importlib/Lib/email/iterators.py
==============================================================================
--- python/branches/py3k-importlib/Lib/email/iterators.py	(original)
+++ python/branches/py3k-importlib/Lib/email/iterators.py	Thu Mar 27 00:48:05 2008
@@ -39,7 +39,7 @@
     """
     for subpart in msg.walk():
         payload = subpart.get_payload(decode=decode)
-        if isinstance(payload, basestring):
+        if isinstance(payload, str):
             for line in StringIO(payload):
                 yield line
 

Modified: python/branches/py3k-importlib/Lib/email/mime/multipart.py
==============================================================================
--- python/branches/py3k-importlib/Lib/email/mime/multipart.py	(original)
+++ python/branches/py3k-importlib/Lib/email/mime/multipart.py	Thu Mar 27 00:48:05 2008
@@ -34,6 +34,12 @@
         keyword arguments (or passed into the _params argument).
         """
         MIMEBase.__init__(self, 'multipart', _subtype, **_params)
+
+        # Initialise _payload to an empty list as the Message superclass's
+        # implementation of is_multipart assumes that _payload is a list for
+        # multipart messages.
+        self._payload = []
+
         if _subparts:
             for p in _subparts:
                 self.attach(p)

Modified: python/branches/py3k-importlib/Lib/email/test/data/msg_15.txt
==============================================================================
--- python/branches/py3k-importlib/Lib/email/test/data/msg_15.txt	(original)
+++ python/branches/py3k-importlib/Lib/email/test/data/msg_15.txt	Thu Mar 27 00:48:05 2008
@@ -9,7 +9,7 @@
 Content-type: multipart/mixed;
    boundary="MS_Mac_OE_3071477847_720252_MIME_Part"
 
-> Denne meddelelse er i MIME-format. Da dit postl¾sningsprogram ikke forstŒr dette format, kan del af eller hele meddelelsen v¾re ul¾selig.
+> Denne meddelelse er i MIME-format. Da dit postl
 
 --MS_Mac_OE_3071477847_720252_MIME_Part
 Content-type: multipart/alternative;

Modified: python/branches/py3k-importlib/Lib/email/test/test_email.py
==============================================================================
--- python/branches/py3k-importlib/Lib/email/test/test_email.py	(original)
+++ python/branches/py3k-importlib/Lib/email/test/test_email.py	Thu Mar 27 00:48:05 2008
@@ -1892,6 +1892,9 @@
         eq(msg.get_payload(0), text1)
         eq(msg.get_payload(1), text2)
 
+    def test_default_multipart_constructor(self):
+        msg = MIMEMultipart()
+        self.assertTrue(msg.is_multipart())
 
 
 # A general test of parser->model->generator idempotency.  IOW, read a message
@@ -2448,9 +2451,7 @@
 
     def test_crlf_separation(self):
         eq = self.assertEqual
-        # XXX When Guido fixes TextIOWrapper.read() to act just like
-        # .readlines(), open this in 'rb' mode with newlines='\n'.
-        with openfile('msg_26.txt', mode='rb') as fp:
+        with openfile('msg_26.txt', newline='\n') as fp:
             msg = Parser().parse(fp)
         eq(len(msg.get_payload()), 2)
         part1 = msg.get_payload(0)

Modified: python/branches/py3k-importlib/Lib/encodings/__init__.py
==============================================================================
--- python/branches/py3k-importlib/Lib/encodings/__init__.py	(original)
+++ python/branches/py3k-importlib/Lib/encodings/__init__.py	Thu Mar 27 00:48:05 2008
@@ -52,6 +52,8 @@
         non-ASCII characters, these must be Latin-1 compatible.
 
     """
+    if isinstance(encoding, bytes):
+        encoding = str(encoding, "ascii")
     chars = []
     punct = False
     for c in encoding:

Modified: python/branches/py3k-importlib/Lib/encodings/aliases.py
==============================================================================
--- python/branches/py3k-importlib/Lib/encodings/aliases.py	(original)
+++ python/branches/py3k-importlib/Lib/encodings/aliases.py	Thu Mar 27 00:48:05 2008
@@ -33,9 +33,9 @@
     'us'                 : 'ascii',
     'us_ascii'           : 'ascii',
 
-    # base64_codec codec
-    'base64'             : 'base64_codec',
-    'base_64'            : 'base64_codec',
+    ## base64_codec codec
+    #'base64'             : 'base64_codec',
+    #'base_64'            : 'base64_codec',
 
     # big5 codec
     'big5_tw'            : 'big5',
@@ -45,8 +45,8 @@
     'big5_hkscs'         : 'big5hkscs',
     'hkscs'              : 'big5hkscs',
 
-    # bz2_codec codec
-    'bz2'                : 'bz2_codec',
+    ## bz2_codec codec
+    #'bz2'                : 'bz2_codec',
 
     # cp037 codec
     '037'                : 'cp037',
@@ -243,8 +243,8 @@
     'cp936'              : 'gbk',
     'ms936'              : 'gbk',
 
-    # hex_codec codec
-    'hex'                : 'hex_codec',
+    ## hex_codec codec
+    #'hex'                : 'hex_codec',
 
     # hp_roman8 codec
     'roman8'             : 'hp_roman8',
@@ -444,13 +444,13 @@
     'cp154'              : 'ptcp154',
     'cyrillic-asian'     : 'ptcp154',
 
-    # quopri_codec codec
-    'quopri'             : 'quopri_codec',
-    'quoted_printable'   : 'quopri_codec',
-    'quotedprintable'    : 'quopri_codec',
+    ## quopri_codec codec
+    #'quopri'             : 'quopri_codec',
+    #'quoted_printable'   : 'quopri_codec',
+    #'quotedprintable'    : 'quopri_codec',
 
-    # rot_13 codec
-    'rot13'              : 'rot_13',
+    ## rot_13 codec
+    #'rot13'              : 'rot_13',
 
     # shift_jis codec
     'csshiftjis'         : 'shift_jis',
@@ -512,11 +512,11 @@
     'utf8_ucs2'          : 'utf_8',
     'utf8_ucs4'          : 'utf_8',
 
-    # uu_codec codec
-    'uu'                 : 'uu_codec',
+    ## uu_codec codec
+    #'uu'                 : 'uu_codec',
 
-    # zlib_codec codec
-    'zip'                : 'zlib_codec',
-    'zlib'               : 'zlib_codec',
+    ## zlib_codec codec
+    #'zip'                : 'zlib_codec',
+    #'zlib'               : 'zlib_codec',
 
 }

Deleted: /python/branches/py3k-importlib/Lib/encodings/bz2_codec.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/encodings/bz2_codec.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,102 +0,0 @@
-""" Python 'bz2_codec' Codec - bz2 compression encoding
-
-    Unlike most of the other codecs which target Unicode, this codec
-    will return Python string objects for both encode and decode.
-
-    Adapted by Raymond Hettinger from zlib_codec.py which was written
-    by Marc-Andre Lemburg (mal at lemburg.com).
-
-"""
-import codecs
-import bz2 # this codec needs the optional bz2 module !
-
-### Codec APIs
-
-def bz2_encode(input,errors='strict'):
-
-    """ Encodes the object input and returns a tuple (output
-        object, length consumed).
-
-        errors defines the error handling to apply. It defaults to
-        'strict' handling which is the only currently supported
-        error handling for this codec.
-
-    """
-    assert errors == 'strict'
-    output = bz2.compress(input)
-    return (output, len(input))
-
-def bz2_decode(input,errors='strict'):
-
-    """ Decodes the object input and returns a tuple (output
-        object, length consumed).
-
-        input must be an object which provides the bf_getreadbuf
-        buffer slot. Python strings, buffer objects and memory
-        mapped files are examples of objects providing this slot.
-
-        errors defines the error handling to apply. It defaults to
-        'strict' handling which is the only currently supported
-        error handling for this codec.
-
-    """
-    assert errors == 'strict'
-    output = bz2.decompress(input)
-    return (output, len(input))
-
-class Codec(codecs.Codec):
-
-    def encode(self, input, errors='strict'):
-        return bz2_encode(input, errors)
-    def decode(self, input, errors='strict'):
-        return bz2_decode(input, errors)
-
-class IncrementalEncoder(codecs.IncrementalEncoder):
-    def __init__(self, errors='strict'):
-        assert errors == 'strict'
-        self.errors = errors
-        self.compressobj = bz2.BZ2Compressor()
-
-    def encode(self, input, final=False):
-        if final:
-            c = self.compressobj.compress(input)
-            return c + self.compressobj.flush()
-        else:
-            return self.compressobj.compress(input)
-
-    def reset(self):
-        self.compressobj = bz2.BZ2Compressor()
-
-class IncrementalDecoder(codecs.IncrementalDecoder):
-    def __init__(self, errors='strict'):
-        assert errors == 'strict'
-        self.errors = errors
-        self.decompressobj = bz2.BZ2Decompressor()
-
-    def decode(self, input, final=False):
-        try:
-            return self.decompressobj.decompress(input)
-        except EOFError:
-            return ''
-
-    def reset(self):
-        self.decompressobj = bz2.BZ2Decompressor()
-
-class StreamWriter(Codec,codecs.StreamWriter):
-    pass
-
-class StreamReader(Codec,codecs.StreamReader):
-    pass
-
-### encodings module API
-
-def getregentry():
-    return codecs.CodecInfo(
-        name="bz2",
-        encode=bz2_encode,
-        decode=bz2_decode,
-        incrementalencoder=IncrementalEncoder,
-        incrementaldecoder=IncrementalDecoder,
-        streamwriter=StreamWriter,
-        streamreader=StreamReader,
-    )

Modified: python/branches/py3k-importlib/Lib/encodings/idna.py
==============================================================================
--- python/branches/py3k-importlib/Lib/encodings/idna.py	(original)
+++ python/branches/py3k-importlib/Lib/encodings/idna.py	Thu Mar 27 00:48:05 2008
@@ -151,9 +151,9 @@
             raise UnicodeError("unsupported error handling "+errors)
 
         if not input:
-            return b"", 0
+            return b'', 0
 
-        result = b""
+        result = bytearray()
         labels = dots.split(input)
         if labels and not labels[-1]:
             trailing_dot = b'.'
@@ -165,7 +165,7 @@
                 # Join with U+002E
                 result.extend(b'.')
             result.extend(ToASCII(label))
-        return result+trailing_dot, len(input)
+        return bytes(result+trailing_dot), len(input)
 
     def decode(self, input, errors='strict'):
 
@@ -216,7 +216,7 @@
                 if labels:
                     trailing_dot = b'.'
 
-        result = b""
+        result = bytearray()
         size = 0
         for label in labels:
             if size:
@@ -228,7 +228,7 @@
 
         result += trailing_dot
         size += len(trailing_dot)
-        return (result, size)
+        return (bytes(result), size)
 
 class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
     def _buffer_decode(self, input, errors, final):

Modified: python/branches/py3k-importlib/Lib/encodings/punycode.py
==============================================================================
--- python/branches/py3k-importlib/Lib/encodings/punycode.py	(original)
+++ python/branches/py3k-importlib/Lib/encodings/punycode.py	Thu Mar 27 00:48:05 2008
@@ -10,7 +10,7 @@
 
 def segregate(str):
     """3.1 Basic code point segregation"""
-    base = b""
+    base = bytearray()
     extended = set()
     for c in str:
         if ord(c) < 128:
@@ -18,7 +18,7 @@
         else:
             extended.add(c)
     extended = sorted(extended)
-    return (base, extended)
+    return bytes(base), extended
 
 def selective_len(str, max):
     """Return the length of str, considering only characters below max."""
@@ -78,13 +78,13 @@
 digits = b"abcdefghijklmnopqrstuvwxyz0123456789"
 def generate_generalized_integer(N, bias):
     """3.3 Generalized variable-length integers"""
-    result = b""
+    result = bytearray()
     j = 0
     while 1:
         t = T(j, bias)
         if N < t:
             result.append(digits[N])
-            return result
+            return bytes(result)
         result.append(digits[t + ((N - t) % (36 - t))])
         N = (N - t) // (36 - t)
         j += 1
@@ -107,13 +107,13 @@
 def generate_integers(baselen, deltas):
     """3.4 Bias adaptation"""
     # Punycode parameters: initial bias = 72, damp = 700, skew = 38
-    result = b""
+    result = bytearray()
     bias = 72
     for points, delta in enumerate(deltas):
         s = generate_generalized_integer(delta, bias)
         result.extend(s)
         bias = adapt(delta, points==0, baselen+points+1)
-    return result
+    return bytes(result)
 
 def punycode_encode(text):
     base, extended = segregate(text)

Modified: python/branches/py3k-importlib/Lib/encodings/utf_7.py
==============================================================================
--- python/branches/py3k-importlib/Lib/encodings/utf_7.py	(original)
+++ python/branches/py3k-importlib/Lib/encodings/utf_7.py	Thu Mar 27 00:48:05 2008
@@ -6,34 +6,31 @@
 
 ### Codec APIs
 
-class Codec(codecs.Codec):
+encode = codecs.utf_7_encode
 
-    # Note: Binding these as C functions will result in the class not
-    # converting them to methods. This is intended.
-    encode = codecs.utf_7_encode
-    decode = codecs.utf_7_decode
+def decode(input, errors='strict'):
+    return codecs.utf_7_decode(input, errors, True)
 
 class IncrementalEncoder(codecs.IncrementalEncoder):
     def encode(self, input, final=False):
         return codecs.utf_7_encode(input, self.errors)[0]
 
 class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
-    def _buffer_decode(self, input, errors, final):
-        return codecs.utf_7_decode(input, self.errors)
+    _buffer_decode = codecs.utf_7_decode
 
-class StreamWriter(Codec,codecs.StreamWriter):
-    pass
+class StreamWriter(codecs.StreamWriter):
+    encode = codecs.utf_7_encode
 
-class StreamReader(Codec,codecs.StreamReader):
-    pass
+class StreamReader(codecs.StreamReader):
+    decode = codecs.utf_7_decode
 
 ### encodings module API
 
 def getregentry():
     return codecs.CodecInfo(
         name='utf-7',
-        encode=Codec.encode,
-        decode=Codec.decode,
+        encode=encode,
+        decode=decode,
         incrementalencoder=IncrementalEncoder,
         incrementaldecoder=IncrementalDecoder,
         streamreader=StreamReader,

Modified: python/branches/py3k-importlib/Lib/encodings/utf_8_sig.py
==============================================================================
--- python/branches/py3k-importlib/Lib/encodings/utf_8_sig.py	(original)
+++ python/branches/py3k-importlib/Lib/encodings/utf_8_sig.py	Thu Mar 27 00:48:05 2008
@@ -103,12 +103,18 @@
             pass
 
     def decode(self, input, errors='strict'):
-        if len(input) < 3 and codecs.BOM_UTF8.startswith(input):
-            # not enough data to decide if this is a BOM
-            # => try again on the next call
-            return ("", 0)
+        if len(input) < 3:
+            if codecs.BOM_UTF8.startswith(input):
+                # not enough data to decide if this is a BOM
+                # => try again on the next call
+                return ("", 0)
+        elif input[:3] == codecs.BOM_UTF8:
+            self.decode = codecs.utf_8_decode
+            (output, consumed) = codecs.utf_8_decode(input[3:],errors)
+            return (output, consumed+3)
+        # (else) no BOM present
         self.decode = codecs.utf_8_decode
-        return decode(input, errors)
+        return codecs.utf_8_decode(input, errors)
 
 ### encodings module API
 

Modified: python/branches/py3k-importlib/Lib/filecmp.py
==============================================================================
--- python/branches/py3k-importlib/Lib/filecmp.py	(original)
+++ python/branches/py3k-importlib/Lib/filecmp.py	Thu Mar 27 00:48:05 2008
@@ -12,7 +12,7 @@
 import os
 import stat
 import warnings
-from itertools import ifilter, ifilterfalse, imap, izip
+from itertools import filterfalse
 
 __all__ = ["cmp","dircmp","cmpfiles"]
 
@@ -130,11 +130,11 @@
         self.right_list.sort()
 
     def phase1(self): # Compute common names
-        a = dict(izip(imap(os.path.normcase, self.left_list), self.left_list))
-        b = dict(izip(imap(os.path.normcase, self.right_list), self.right_list))
-        self.common = list(map(a.__getitem__, ifilter(b.__contains__, a)))
-        self.left_only = list(map(a.__getitem__, ifilterfalse(b.__contains__, a)))
-        self.right_only = list(map(b.__getitem__, ifilterfalse(a.__contains__, b)))
+        a = dict(zip(map(os.path.normcase, self.left_list), self.left_list))
+        b = dict(zip(map(os.path.normcase, self.right_list), self.right_list))
+        self.common = list(map(a.__getitem__, filter(b.__contains__, a)))
+        self.left_only = list(map(a.__getitem__, filterfalse(b.__contains__, a)))
+        self.right_only = list(map(b.__getitem__, filterfalse(a.__contains__, b)))
 
     def phase2(self): # Distinguish files, directories, funnies
         self.common_dirs = []
@@ -149,12 +149,12 @@
             try:
                 a_stat = os.stat(a_path)
             except os.error as why:
-                # print 'Can\'t stat', a_path, ':', why[1]
+                # print('Can\'t stat', a_path, ':', why.args[1])
                 ok = 0
             try:
                 b_stat = os.stat(b_path)
             except os.error as why:
-                # print 'Can\'t stat', b_path, ':', why[1]
+                # print('Can\'t stat', b_path, ':', why.args[1])
                 ok = 0
 
             if ok:
@@ -276,7 +276,7 @@
 # Return a copy with items that occur in skip removed.
 #
 def _filter(flist, skip):
-    return list(ifilterfalse(skip.__contains__, flist))
+    return list(filterfalse(skip.__contains__, flist))
 
 
 # Demonstration and testing.

Modified: python/branches/py3k-importlib/Lib/fileinput.py
==============================================================================
--- python/branches/py3k-importlib/Lib/fileinput.py	(original)
+++ python/branches/py3k-importlib/Lib/fileinput.py	Thu Mar 27 00:48:05 2008
@@ -196,7 +196,7 @@
 
     def __init__(self, files=None, inplace=0, backup="", bufsize=0,
                  mode="r", openhook=None):
-        if isinstance(files, basestring):
+        if isinstance(files, str):
             files = (files,)
         else:
             if files is None:
@@ -326,9 +326,11 @@
                     except OSError:
                         self._output = open(self._filename, "w")
                     else:
-                        fd = os.open(self._filename,
-                                     os.O_CREAT | os.O_WRONLY | os.O_TRUNC,
-                                     perm)
+                        mode = os.O_CREAT | os.O_WRONLY | os.O_TRUNC
+                        if hasattr(os, 'O_BINARY'):
+                            mode |= os.O_BINARY
+
+                        fd = os.open(self._filename, mode, perm)
                         self._output = os.fdopen(fd, "w")
                         try:
                             if hasattr(os, 'chmod'):

Modified: python/branches/py3k-importlib/Lib/formatter.py
==============================================================================
--- python/branches/py3k-importlib/Lib/formatter.py	(original)
+++ python/branches/py3k-importlib/Lib/formatter.py	Thu Mar 27 00:48:05 2008
@@ -433,10 +433,7 @@
         fp = open(sys.argv[1])
     else:
         fp = sys.stdin
-    while 1:
-        line = fp.readline()
-        if not line:
-            break
+    for line in fp:
         if line == '\n':
             f.end_paragraph(1)
         else:

Modified: python/branches/py3k-importlib/Lib/ftplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ftplib.py	(original)
+++ python/branches/py3k-importlib/Lib/ftplib.py	Thu Mar 27 00:48:05 2008
@@ -32,6 +32,7 @@
 # Changes and improvements suggested by Steve Majewski.
 # Modified by Jack to work on the mac.
 # Modified by Siebren to support docstrings and PASV.
+# Modified by Phil Schwartz to add storbinary and storlines callbacks.
 #
 
 import os
@@ -313,7 +314,7 @@
         expected size may be None if it could not be determined.
 
         Optional `rest' argument can be a string that is sent as the
-        argument to a RESTART command.  This is essentially a server
+        argument to a REST command.  This is essentially a server
         marker used to tell the server to skip over any data up to the
         given marker.
         """
@@ -376,14 +377,18 @@
         return resp
 
     def retrbinary(self, cmd, callback, blocksize=8192, rest=None):
-        """Retrieve data in binary mode.
+        """Retrieve data in binary mode.  A new port is created for you.
 
-        `cmd' is a RETR command.  `callback' is a callback function is
-        called for each block.  No more than `blocksize' number of
-        bytes will be read from the socket.  Optional `rest' is passed
-        to transfercmd().
+        Args:
+          cmd: A RETR command.
+          callback: A single parameter callable to be called on each
+                    block of data read.
+          blocksize: The maximum number of bytes to read from the
+                     socket at one time.  [default: 8192]
+          rest: Passed to transfercmd().  [default: None]
 
-        A new port is created for you.  Return the response code.
+        Returns:
+          The response code.
         """
         self.voidcmd('TYPE I')
         conn = self.transfercmd(cmd, rest)
@@ -396,11 +401,17 @@
         return self.voidresp()
 
     def retrlines(self, cmd, callback = None):
-        '''Retrieve data in line mode.
-        The argument is a RETR or LIST command.
-        The callback function (2nd argument) is called for each line,
-        with trailing CRLF stripped.  This creates a new port for you.
-        print_line() is the default callback.'''
+        """Retrieve data in line mode.  A new port is created for you.
+
+        Args:
+          cmd: A RETR, LIST, NLST, or MLSD command.
+          callback: An optional single parameter callable that is called
+                    for each line with the trailing CRLF stripped.
+                    [default: print_line()]
+
+        Returns:
+          The response code.
+        """
         if callback is None: callback = print_line
         resp = self.sendcmd('TYPE A')
         conn = self.transfercmd(cmd)
@@ -419,19 +430,42 @@
         conn.close()
         return self.voidresp()
 
-    def storbinary(self, cmd, fp, blocksize=8192):
-        '''Store a file in binary mode.'''
+    def storbinary(self, cmd, fp, blocksize=8192, callback=None):
+        """Store a file in binary mode.  A new port is created for you.
+
+        Args:
+          cmd: A STOR command.
+          fp: A file-like object with a read(num_bytes) method.
+          blocksize: The maximum data size to read from fp and send over
+                     the connection at once.  [default: 8192]
+          callback: An optional single parameter callable that is called on
+                    on each block of data after it is sent.  [default: None]
+
+        Returns:
+          The response code.
+        """
         self.voidcmd('TYPE I')
         conn = self.transfercmd(cmd)
         while 1:
             buf = fp.read(blocksize)
             if not buf: break
             conn.sendall(buf)
+            if callback: callback(buf)
         conn.close()
         return self.voidresp()
 
-    def storlines(self, cmd, fp):
-        '''Store a file in line mode.'''
+    def storlines(self, cmd, fp, callback=None):
+        """Store a file in line mode.  A new port is created for you.
+
+        Args:
+          cmd: A STOR command.
+          fp: A file-like object with a readline() method.
+          callback: An optional single parameter callable that is called on
+                    on each line after it is sent.  [default: None]
+
+        Returns:
+          The response code.
+        """
         self.voidcmd('TYPE A')
         conn = self.transfercmd(cmd)
         while 1:
@@ -441,6 +475,7 @@
                 if buf[-1] in CRLF: buf = buf[:-1]
                 buf = buf + CRLF
             conn.sendall(buf)
+            if callback: callback(buf)
         conn.close()
         return self.voidresp()
 
@@ -505,7 +540,7 @@
 
     def size(self, filename):
         '''Retrieve the size of a file.'''
-        # Note that the RFC doesn't say anything about 'SIZE'
+        # The SIZE command is defined in RFC-3659
         resp = self.sendcmd('SIZE ' + filename)
         if resp[:3] == '213':
             s = resp[3:].strip()

Modified: python/branches/py3k-importlib/Lib/getpass.py
==============================================================================
--- python/branches/py3k-importlib/Lib/getpass.py	(original)
+++ python/branches/py3k-importlib/Lib/getpass.py	Thu Mar 27 00:48:05 2008
@@ -49,10 +49,10 @@
         return default_getpass(prompt, stream)
     import msvcrt
     for c in prompt:
-        msvcrt.putch(c)
+        msvcrt.putwch(c)
     pw = ""
     while 1:
-        c = msvcrt.getch()
+        c = msvcrt.getwch()
         if c == '\r' or c == '\n':
             break
         if c == '\003':
@@ -61,8 +61,8 @@
             pw = pw[:-1]
         else:
             pw = pw + c
-    msvcrt.putch('\r')
-    msvcrt.putch('\n')
+    msvcrt.putwch('\r')
+    msvcrt.putwch('\n')
     return pw
 
 
@@ -78,6 +78,7 @@
     prompt = str(prompt)
     if prompt:
         stream.write(prompt)
+        stream.flush()
     line = sys.stdin.readline()
     if not line:
         raise EOFError

Modified: python/branches/py3k-importlib/Lib/gettext.py
==============================================================================
--- python/branches/py3k-importlib/Lib/gettext.py	(original)
+++ python/branches/py3k-importlib/Lib/gettext.py	Thu Mar 27 00:48:05 2008
@@ -236,18 +236,18 @@
         self._output_charset = charset
 
     def install(self, str=False, names=None):
-        import __builtin__
-        __builtin__.__dict__['_'] = str and self.ugettext or self.gettext
+        import builtins
+        builtins.__dict__['_'] = str and self.ugettext or self.gettext
         if hasattr(names, "__contains__"):
             if "gettext" in names:
-                __builtin__.__dict__['gettext'] = __builtin__.__dict__['_']
+                builtins.__dict__['gettext'] = builtins.__dict__['_']
             if "ngettext" in names:
-                __builtin__.__dict__['ngettext'] = (str and self.ungettext
+                builtins.__dict__['ngettext'] = (str and self.ungettext
                                                              or self.ngettext)
             if "lgettext" in names:
-                __builtin__.__dict__['lgettext'] = self.lgettext
+                builtins.__dict__['lgettext'] = self.lgettext
             if "lngettext" in names:
-                __builtin__.__dict__['lngettext'] = self.lngettext
+                builtins.__dict__['lngettext'] = self.lngettext
 
 
 class GNUTranslations(NullTranslations):
@@ -291,8 +291,8 @@
             if mlen == 0:
                 # Catalog description
                 lastk = k = None
-                for b_item in tmsg.split(os.linesep.encode("ascii")):
-                    item = str(b_item).strip()
+                for b_item in tmsg.split('\n'.encode("ascii")):
+                    item = b_item.decode().strip()
                     if not item:
                         continue
                     if ':' in item:

Modified: python/branches/py3k-importlib/Lib/glob.py
==============================================================================
--- python/branches/py3k-importlib/Lib/glob.py	(original)
+++ python/branches/py3k-importlib/Lib/glob.py	Thu Mar 27 00:48:05 2008
@@ -57,7 +57,7 @@
     except os.error:
         return []
     if pattern[0] != '.':
-        names = filter(lambda x: x[0] != '.', names)
+        names = [x for x in names if x[0] != '.']
     return fnmatch.filter(names, pattern)
 
 def glob0(dirname, basename):

Modified: python/branches/py3k-importlib/Lib/gzip.py
==============================================================================
--- python/branches/py3k-importlib/Lib/gzip.py	(original)
+++ python/branches/py3k-importlib/Lib/gzip.py	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,7 @@
 
 import struct, sys, time
 import zlib
-import __builtin__
+import builtins
 
 __all__ = ["GzipFile","open"]
 
@@ -17,7 +17,6 @@
 
 def U32(i):
     """Return i as an unsigned integer, assuming it fits in 32 bits.
-
     If it's >= 2GB when viewed as a 32-bit unsigned int, return a long.
     """
     if i < 0:
@@ -25,19 +24,16 @@
     return i
 
 def LOWU32(i):
-    """Return the low-order 32 bits of an int, as a non-negative int."""
+    """Return the low-order 32 bits, as a non-negative int"""
     return i & 0xFFFFFFFF
 
-def write32(output, value):
-    output.write(struct.pack("<l", value))
-
 def write32u(output, value):
     # The L format writes the bit pattern correctly whether signed
     # or unsigned.
     output.write(struct.pack("<L", value))
 
 def read32(input):
-    return struct.unpack("<l", input.read(4))[0]
+    return struct.unpack("<I", input.read(4))[0]
 
 def open(filename, mode="rb", compresslevel=9):
     """Shorthand for GzipFile(filename, mode, compresslevel).
@@ -92,7 +88,7 @@
         if mode and 'b' not in mode:
             mode += 'b'
         if fileobj is None:
-            fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb')
+            fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
         if filename is None:
             if hasattr(fileobj, 'name'): filename = fileobj.name
             else: filename = ''
@@ -141,7 +137,7 @@
 
     def _init_write(self, filename):
         self.name = filename
-        self.crc = zlib.crc32("")
+        self.crc = zlib.crc32("") & 0xffffffff
         self.size = 0
         self.writebuf = []
         self.bufsize = 0
@@ -168,7 +164,7 @@
             self.fileobj.write(fname + b'\000')
 
     def _init_read(self):
-        self.crc = zlib.crc32("")
+        self.crc = zlib.crc32("") & 0xffffffff
         self.size = 0
 
     def _read_gzip_header(self):
@@ -214,7 +210,7 @@
             raise ValueError("write() on closed GzipFile object")
         if len(data) > 0:
             self.size = self.size + len(data)
-            self.crc = zlib.crc32(data, self.crc)
+            self.crc = zlib.crc32(data, self.crc) & 0xffffffff
             self.fileobj.write( self.compress.compress(data) )
             self.offset += len(data)
 
@@ -306,7 +302,7 @@
             self._new_member = True
 
     def _add_read_data(self, data):
-        self.crc = zlib.crc32(data, self.crc)
+        self.crc = zlib.crc32(data, self.crc) & 0xffffffff
         self.extrabuf = self.extrabuf + data
         self.extrasize = self.extrasize + len(data)
         self.size = self.size + len(data)
@@ -319,24 +315,19 @@
         # stored is the true file size mod 2**32.
         self.fileobj.seek(-8, 1)
         crc32 = read32(self.fileobj)
-        isize = U32(read32(self.fileobj))   # may exceed 2GB
-        if U32(crc32) != U32(self.crc):
-            raise IOError("CRC check failed")
-        elif isize != LOWU32(self.size):
+        isize = read32(self.fileobj)  # may exceed 2GB
+        if crc32 != self.crc:
+            raise IOError("CRC check failed %s != %s" % (hex(crc32),
+                                                         hex(self.crc)))
+        elif isize != (self.size & 0xffffffff):
             raise IOError("Incorrect length of data produced")
 
     def close(self):
         if self.mode == WRITE:
             self.fileobj.write(self.compress.flush())
-            # The native zlib crc is an unsigned 32-bit integer, but
-            # the Python wrapper implicitly casts that to a signed C
-            # long.  So, on a 32-bit box self.crc may "look negative",
-            # while the same crc on a 64-bit box may "look positive".
-            # To avoid irksome warnings from the `struct` module, force
-            # it to look positive on all boxes.
-            write32u(self.fileobj, LOWU32(self.crc))
+            write32u(self.fileobj, self.crc)
             # self.size may exceed 2GB, or even 4GB
-            write32u(self.fileobj, LOWU32(self.size))
+            write32u(self.fileobj, self.size & 0xffffffff)
             self.fileobj = None
         elif self.mode == READ:
             self.fileobj = None
@@ -409,7 +400,7 @@
 
     def readline(self, size=-1):
         if size < 0:
-            size = sys.maxint
+            size = sys.maxsize
             readsize = self.min_readsize
         else:
             readsize = size
@@ -441,7 +432,7 @@
     def readlines(self, sizehint=0):
         # Negative numbers result in reading all the lines
         if sizehint <= 0:
-            sizehint = sys.maxint
+            sizehint = sys.maxsize
         L = []
         while sizehint > 0:
             line = self.readline()
@@ -487,13 +478,13 @@
                     print("filename doesn't end in .gz:", repr(arg))
                     continue
                 f = open(arg, "rb")
-                g = __builtin__.open(arg[:-3], "wb")
+                g = builtins.open(arg[:-3], "wb")
         else:
             if arg == "-":
                 f = sys.stdin
                 g = GzipFile(filename="", mode="wb", fileobj=sys.stdout)
             else:
-                f = __builtin__.open(arg, "rb")
+                f = builtins.open(arg, "rb")
                 g = open(arg + ".gz", "wb")
         while True:
             chunk = f.read(1024)

Modified: python/branches/py3k-importlib/Lib/hashlib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/hashlib.py	(original)
+++ python/branches/py3k-importlib/Lib/hashlib.py	Thu Mar 27 00:48:05 2008
@@ -18,6 +18,9 @@
 More algorithms may be available on your platform but the above are
 guaranteed to exist.
 
+NOTE: If you want the adler32 or crc32 hash functions they are available in
+the zlib module.
+
 Choose your hash function wisely.  Some have known collision weaknesses.
 sha384 and sha512 will be slow on 32 bit platforms.
 

Modified: python/branches/py3k-importlib/Lib/heapq.py
==============================================================================
--- python/branches/py3k-importlib/Lib/heapq.py	(original)
+++ python/branches/py3k-importlib/Lib/heapq.py	Thu Mar 27 00:48:05 2008
@@ -127,9 +127,9 @@
 """
 
 __all__ = ['heappush', 'heappop', 'heapify', 'heapreplace', 'merge',
-           'nlargest', 'nsmallest']
+           'nlargest', 'nsmallest', 'heappushpop']
 
-from itertools import islice, repeat, count, izip, tee
+from itertools import islice, repeat, count, tee
 from operator import itemgetter, neg
 import bisect
 
@@ -165,6 +165,13 @@
     _siftup(heap, 0)
     return returnitem
 
+def heappushpop(heap, item):
+    """Fast version of a heappush followed by a heappop."""
+    if heap and item > heap[0]:
+        item, heap[0] = heap[0], item
+        _siftup(heap, 0)
+    return item
+
 def heapify(x):
     """Transform list into a heap, in-place, in O(len(heap)) time."""
     n = len(x)
@@ -186,13 +193,9 @@
     if not result:
         return result
     heapify(result)
-    _heapreplace = heapreplace
-    sol = result[0]         # sol --> smallest of the nlargest
+    _heappushpop = heappushpop
     for elem in it:
-        if elem <= sol:
-            continue
-        _heapreplace(result, elem)
-        sol = result[0]
+        heappushpop(result, elem)
     result.sort(reverse=True)
     return result
 
@@ -304,7 +307,7 @@
 
 # If available, use C implementation
 try:
-    from _heapq import heappush, heappop, heapify, heapreplace, nlargest, nsmallest
+    from _heapq import heappush, heappop, heapify, heapreplace, nlargest, nsmallest, heappushpop
 except ImportError:
     pass
 
@@ -351,7 +354,8 @@
     Equivalent to:  sorted(iterable, key=key)[:n]
     """
     in1, in2 = tee(iterable)
-    it = izip(map(key, in1), count(), in2)                  # decorate
+    keys = in1 if key is None else map(key, in1)
+    it = zip(keys, count(), in2)                           # decorate
     result = _nsmallest(n, it)
     return list(map(itemgetter(2), result))                 # undecorate
 
@@ -362,7 +366,8 @@
     Equivalent to:  sorted(iterable, key=key, reverse=True)[:n]
     """
     in1, in2 = tee(iterable)
-    it = izip(map(key, in1), map(neg, count()), in2)        # decorate
+    keys = in1 if key is None else map(key, in1)
+    it = zip(keys, map(neg, count()), in2)                 # decorate
     result = _nlargest(n, it)
     return list(map(itemgetter(2), result))                 # undecorate
 

Modified: python/branches/py3k-importlib/Lib/hmac.py
==============================================================================
--- python/branches/py3k-importlib/Lib/hmac.py	(original)
+++ python/branches/py3k-importlib/Lib/hmac.py	Thu Mar 27 00:48:05 2008
@@ -3,6 +3,8 @@
 Implements the HMAC algorithm as described by RFC 2104.
 """
 
+import warnings as _warnings
+
 trans_5C = bytes((x ^ 0x5C) for x in range(256))
 trans_36 = bytes((x ^ 0x36) for x in range(256))
 
@@ -16,7 +18,7 @@
 _secret_backdoor_key = []
 
 class HMAC:
-    """RFC2104 HMAC class.
+    """RFC 2104 HMAC class.  Also complies with RFC 4231.
 
     This supports the API for Cryptographic Hash Functions (PEP 247).
     """
@@ -37,7 +39,8 @@
         if key is _secret_backdoor_key: # cheap
             return
 
-        assert isinstance(key, bytes), repr(key)
+        if not isinstance(key, bytes):
+            raise TypeError("expected bytes, but got %r" % type(key).__name__)
 
         if digestmod is None:
             import hashlib
@@ -52,7 +55,21 @@
         self.inner = self.digest_cons()
         self.digest_size = self.inner.digest_size
 
-        blocksize = self.blocksize
+        if hasattr(self.inner, 'block_size'):
+            blocksize = self.inner.block_size
+            if blocksize < 16:
+                # Very low blocksize, most likely a legacy value like
+                # Lib/sha.py and Lib/md5.py have.
+                _warnings.warn('block_size of %d seems too small; using our '
+                               'default of %d.' % (blocksize, self.blocksize),
+                               RuntimeWarning, 2)
+                blocksize = self.blocksize
+        else:
+            _warnings.warn('No block_size attribute on given digest object; '
+                           'Assuming %d.' % (self.blocksize),
+                           RuntimeWarning, 2)
+            blocksize = self.blocksize
+
         if len(key) > blocksize:
             key = self.digest_cons(key).digest()
 
@@ -68,7 +85,8 @@
     def update(self, msg):
         """Update this hashing object with the string msg.
         """
-        assert isinstance(msg, bytes), repr(msg)
+        if not isinstance(msg, bytes):
+            raise TypeError("expected bytes, but got %r" % type(msg).__name__)
         self.inner.update(msg)
 
     def copy(self):

Modified: python/branches/py3k-importlib/Lib/htmlentitydefs.py
==============================================================================
--- python/branches/py3k-importlib/Lib/htmlentitydefs.py	(original)
+++ python/branches/py3k-importlib/Lib/htmlentitydefs.py	Thu Mar 27 00:48:05 2008
@@ -265,9 +265,6 @@
 
 for (name, codepoint) in name2codepoint.items():
     codepoint2name[codepoint] = name
-    if codepoint <= 0xff:
-        entitydefs[name] = chr(codepoint)
-    else:
-        entitydefs[name] = '&#%d;' % codepoint
+    entitydefs[name] = chr(codepoint)
 
 del name, codepoint

Modified: python/branches/py3k-importlib/Lib/httplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/httplib.py	(original)
+++ python/branches/py3k-importlib/Lib/httplib.py	Thu Mar 27 00:48:05 2008
@@ -66,7 +66,6 @@
 Req-sent-unread-response       _CS_REQ_SENT       <response_class>
 """
 
-import errno
 import io
 import mimetools
 import socket
@@ -449,7 +448,12 @@
             try:
                 self.length = int(length)
             except ValueError:
-                pass
+                self.length = None
+            else:
+                if self.length < 0:  # ignore nonsensical negative lengths
+                    self.length = None
+        else:
+            self.length = None
 
         # does the body have a fixed length? (of zero)
         if (status == NO_CONTENT or status == NOT_MODIFIED or
@@ -478,7 +482,7 @@
         # Some HTTP/1.0 implementations have support for persistent
         # connections, using rules different than HTTP/1.1.
 
-        # For older HTTP, Keep-Alive indiciates persistent connection.
+        # For older HTTP, Keep-Alive indicates persistent connection.
         if self.msg.getheader("keep-alive"):
             return False
 
@@ -527,7 +531,7 @@
 
     def read(self, amt=None):
         if self.fp is None:
-            return ""
+            return b""
 
         if self.chunked:
             return self._read_chunked(amt)
@@ -553,23 +557,30 @@
         s = self.fp.read(amt)
         if self.length is not None:
             self.length -= len(s)
-
+            if not self.length:
+                self.close()
         return s
 
     def _read_chunked(self, amt):
         assert self.chunked != _UNKNOWN
         chunk_left = self.chunk_left
-        value = ""
+        value = b""
 
         # XXX This accumulates chunks by repeated string concatenation,
         # which is not efficient as the number or size of chunks gets big.
         while True:
             if chunk_left is None:
                 line = self.fp.readline()
-                i = line.find(";")
+                i = line.find(b";")
                 if i >= 0:
                     line = line[:i] # strip chunk-extensions
-                chunk_left = int(line, 16)
+                try:
+                    chunk_left = int(line, 16)
+                except ValueError:
+                    # close the connection as protocol synchronisation is
+                    # probably lost
+                    self.close()
+                    raise IncompleteRead(value)
                 if chunk_left == 0:
                     break
             if amt is None:
@@ -595,7 +606,11 @@
         ### note: we shouldn't have any trailers!
         while True:
             line = self.fp.readline()
-            if line == "\r\n":
+            if not line:
+                # a vanishingly small number of sites EOF without
+                # sending the trailer
+                break
+            if line == b"\r\n":
                 break
 
         # we read everything; close the "file"
@@ -826,6 +841,7 @@
                     if self.port == HTTP_PORT:
                         self.putheader('Host', host_enc)
                     else:
+                        host_enc = host_enc.decode("ascii")
                         self.putheader('Host', "%s:%s" % (host_enc, self.port))
 
             # note: we are assuming that clients will not attempt to set these
@@ -859,8 +875,12 @@
         if self.__state != _CS_REQ_STARTED:
             raise CannotSendHeader()
 
-        header = '%s: %s' % (header, value)
-        self._output(header.encode('ascii'))
+        if hasattr(header, 'encode'):
+            header = header.encode('ascii')
+        if hasattr(value, 'encode'):
+            value = value.encode('ascii')
+        header = header + b': ' + value
+        self._output(header)
 
     def endheaders(self):
         """Indicate that the last header line has been sent to the server."""

Modified: python/branches/py3k-importlib/Lib/idlelib/AutoComplete.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/AutoComplete.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/AutoComplete.py	Thu Mar 27 00:48:05 2008
@@ -27,7 +27,7 @@
 
     menudefs = [
         ('edit', [
-            ("Show completions", "<<force-open-completions>>"),
+            ("Show Completions", "<<force-open-completions>>"),
         ])
     ]
 

Modified: python/branches/py3k-importlib/Lib/idlelib/AutoCompleteWindow.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/AutoCompleteWindow.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/AutoCompleteWindow.py	Thu Mar 27 00:48:05 2008
@@ -283,20 +283,9 @@
             self._selection_changed()
             return "break"
 
-        elif keysym == "Return" and not state:
-            # If start is a prefix of the selection, or there was an indication
-            # that the user used the completion window, put the selected
-            # completion in the text, and close the list.
-            # Otherwise, close the window and let the event through.
-            cursel = int(self.listbox.curselection()[0])
-            if self.completions[cursel][:len(self.start)] == self.start or \
-               self.userwantswindow:
-                self._change_start(self.completions[cursel])
-                self.hide_window()
-                return "break"
-            else:
-                self.hide_window()
-                return
+        elif keysym == "Return":
+            self.hide_window()
+            return
 
         elif (self.mode == COMPLETE_ATTRIBUTES and keysym in
               ("period", "space", "parenleft", "parenright", "bracketleft",

Modified: python/branches/py3k-importlib/Lib/idlelib/CallTips.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/CallTips.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/CallTips.py	Thu Mar 27 00:48:05 2008
@@ -116,7 +116,7 @@
 def _find_constructor(class_ob):
     "Find the nearest __init__() in the class tree."
     try:
-        return class_ob.__init__.im_func
+        return class_ob.__init__.__func__
     except AttributeError:
         for base in class_ob.__bases__:
             init = _find_constructor(base)
@@ -133,7 +133,7 @@
             if fob is None:
                 fob = lambda: None
         elif isinstance(ob, types.MethodType):
-            fob = ob.im_func
+            fob = ob.__func__
         else:
             fob = ob
         if isinstance(fob, (types.FunctionType, types.LambdaType)):
@@ -183,7 +183,7 @@
             name = t.__name__
             # exercise fetch_tip(), not just get_argspec()
             try:
-                qualified_name = "%s.%s" % (t.im_class.__name__, name)
+                qualified_name = "%s.%s" % (t.__self__.__class__.__name__, name)
             except AttributeError:
                 qualified_name = name
             argspec = ct.fetch_tip(qualified_name)

Modified: python/branches/py3k-importlib/Lib/idlelib/CodeContext.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/CodeContext.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/CodeContext.py	Thu Mar 27 00:48:05 2008
@@ -12,7 +12,7 @@
 import Tkinter
 from Tkconstants import TOP, LEFT, X, W, SUNKEN
 import re
-from sys import maxint as INFINITY
+from sys import maxsize as INFINITY
 from idlelib.configHandler import idleConf
 
 BLOCKOPENERS = set(["class", "def", "elif", "else", "except", "finally", "for",

Modified: python/branches/py3k-importlib/Lib/idlelib/ColorDelegator.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/ColorDelegator.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/ColorDelegator.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,7 @@
 import time
 import re
 import keyword
-import __builtin__
+import builtins
 from Tkinter import *
 from idlelib.Delegator import Delegator
 from idlelib.configHandler import idleConf
@@ -14,7 +14,7 @@
 
 def make_pat():
     kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
-    builtinlist = [str(name) for name in dir(__builtin__)
+    builtinlist = [str(name) for name in dir(builtins)
                                         if not name.startswith('_')]
     # self.file = open("file") :
     # 1st 'file' colorized normal, 2nd as builtin, 3rd as string

Modified: python/branches/py3k-importlib/Lib/idlelib/EditorWindow.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/EditorWindow.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/EditorWindow.py	Thu Mar 27 00:48:05 2008
@@ -109,16 +109,6 @@
         self.width = idleConf.GetOption('main','EditorWindow','width')
         self.text = text = MultiCallCreator(Text)(
                 text_frame, name='text', padx=5, wrap='none',
-                foreground=idleConf.GetHighlight(currentTheme,
-                        'normal',fgBg='fg'),
-                background=idleConf.GetHighlight(currentTheme,
-                        'normal',fgBg='bg'),
-                highlightcolor=idleConf.GetHighlight(currentTheme,
-                        'hilite',fgBg='fg'),
-                highlightbackground=idleConf.GetHighlight(currentTheme,
-                        'hilite',fgBg='bg'),
-                insertbackground=idleConf.GetHighlight(currentTheme,
-                        'cursor',fgBg='fg'),
                 width=self.width,
                 height=idleConf.GetOption('main','EditorWindow','height') )
         self.top.focused_widget = self.text
@@ -225,7 +215,6 @@
         # Making the initial values larger slows things down more often.
         self.num_context_lines = 50, 500, 5000000
         self.per = per = self.Percolator(text)
-        self.color = None
         self.undo = undo = self.UndoDelegator()
         per.insertfilter(undo)
         text.undo_block_start = undo.undo_block_start
@@ -236,6 +225,7 @@
         io.set_filename_change_hook(self.filename_change_hook)
         self.good_load = False
         self.set_indentation_params(False)
+        self.color = None # initialized below in self.ResetColorizer
         if filename:
             if os.path.exists(filename) and not os.path.isdir(filename):
                 if io.loadfile(filename):
@@ -247,6 +237,7 @@
                         per.insertfilter(color)
             else:
                 io.set_filename(filename)
+        self.ResetColorizer()
         self.saved_change_hook()
         self.update_recent_files_list()
         self.load_extensions()
@@ -386,7 +377,7 @@
 
     def help_dialog(self, event=None):
         fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt')
-        textView.TextViewer(self.top,'Help',fn)
+        textView.view_file(self.top,'Help',fn)
 
     def python_docs(self, event=None):
         if sys.platform[:3] == 'win':
@@ -408,6 +399,7 @@
 
     def paste(self,event):
         self.text.event_generate("<<Paste>>")
+        self.text.see("insert")
         return "break"
 
     def select_all(self, event=None):
@@ -549,7 +541,8 @@
 
     def close_hook(self):
         if self.flist:
-            self.flist.close_edit(self)
+            self.flist.unregister_maybe_terminate(self)
+            self.flist = None
 
     def set_close_hook(self, close_hook):
         self.close_hook = close_hook
@@ -559,36 +552,42 @@
             self.flist.filename_changed_edit(self)
         self.saved_change_hook()
         self.top.update_windowlist_registry(self)
-        if self.ispythonsource(self.io.filename):
-            self.addcolorizer()
-        else:
-            self.rmcolorizer()
+        self.ResetColorizer()
 
-    def addcolorizer(self):
+    def _addcolorizer(self):
         if self.color:
             return
-        self.per.removefilter(self.undo)
-        self.color = self.ColorDelegator()
-        self.per.insertfilter(self.color)
-        self.per.insertfilter(self.undo)
+        if self.ispythonsource(self.io.filename):
+            self.color = self.ColorDelegator()
+        # can add more colorizers here...
+        if self.color:
+            self.per.removefilter(self.undo)
+            self.per.insertfilter(self.color)
+            self.per.insertfilter(self.undo)
 
-    def rmcolorizer(self):
+    def _rmcolorizer(self):
         if not self.color:
             return
         self.color.removecolors()
-        self.per.removefilter(self.undo)
         self.per.removefilter(self.color)
         self.color = None
-        self.per.insertfilter(self.undo)
 
     def ResetColorizer(self):
-        "Update the colour theme if it is changed"
-        # Called from configDialog.py
-        if self.color:
-            self.color = self.ColorDelegator()
-            self.per.insertfilter(self.color)
+        "Update the colour theme"
+        # Called from self.filename_change_hook and from configDialog.py
+        self._rmcolorizer()
+        self._addcolorizer()
         theme = idleConf.GetOption('main','Theme','name')
-        self.text.config(idleConf.GetHighlight(theme, "normal"))
+        normal_colors = idleConf.GetHighlight(theme, 'normal')
+        cursor_color = idleConf.GetHighlight(theme, 'cursor', fgBg='fg')
+        select_colors = idleConf.GetHighlight(theme, 'hilite')
+        self.text.config(
+            foreground=normal_colors['foreground'],
+            background=normal_colors['background'],
+            insertbackground=cursor_color,
+            selectforeground=select_colors['foreground'],
+            selectbackground=select_colors['background'],
+            )
 
     IDENTCHARS = string.ascii_letters + string.digits + "_"
 
@@ -828,22 +827,21 @@
         if self.io.filename:
             self.update_recent_files_list(new_file=self.io.filename)
         WindowList.unregister_callback(self.postwindowsmenu)
-        if self.close_hook:
-            self.close_hook()
-        self.flist = None
-        colorizing = 0
         self.unload_extensions()
-        self.io.close(); self.io = None
-        self.undo = None # XXX
+        self.io.close()
+        self.io = None
+        self.undo = None
         if self.color:
-            colorizing = self.color.colorizing
-            doh = colorizing and self.top
-            self.color.close(doh) # Cancel colorization
+            self.color.close(False)
+            self.color = None
         self.text = None
         self.tkinter_vars = None
-        self.per.close(); self.per = None
-        if not colorizing:
-            self.top.destroy()
+        self.per.close()
+        self.per = None
+        self.top.destroy()
+        if self.close_hook:
+            # unless override: unregister from flist, terminate if last window
+            self.close_hook()
 
     def load_extensions(self):
         self.extensions = {}
@@ -1439,7 +1437,9 @@
         _tokenize.tabsize = self.tabwidth
         try:
             try:
-                _tokenize.tokenize(self.readline, self.tokeneater)
+                tokens = _tokenize.generate_tokens(self.readline)
+                for token in tokens:
+                    self.tokeneater(*token)
             except _tokenize.TokenError:
                 # since we cut off the tokenizer early, we can trigger
                 # spurious errors
@@ -1501,6 +1501,7 @@
         filename = None
     edit = EditorWindow(root=root, filename=filename)
     edit.set_close_hook(root.quit)
+    edit.text.bind("<<close-all-windows>>", edit.close_event)
     root.mainloop()
     root.destroy()
 

Modified: python/branches/py3k-importlib/Lib/idlelib/FileList.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/FileList.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/FileList.py	Thu Mar 27 00:48:05 2008
@@ -55,7 +55,7 @@
                 break
         return "break"
 
-    def close_edit(self, edit):
+    def unregister_maybe_terminate(self, edit):
         try:
             key = self.inversedict[edit]
         except KeyError:

Modified: python/branches/py3k-importlib/Lib/idlelib/FormatParagraph.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/FormatParagraph.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/FormatParagraph.py	Thu Mar 27 00:48:05 2008
@@ -75,6 +75,7 @@
         else:
             text.mark_set("insert", last)
         text.see("insert")
+        return "break"
 
 def find_paragraph(text, mark):
     lineno, col = map(int, mark.split("."))

Modified: python/branches/py3k-importlib/Lib/idlelib/IOBinding.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/IOBinding.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/IOBinding.py	Thu Mar 27 00:48:05 2008
@@ -485,13 +485,23 @@
             self.text.insert("end-1c", "\n")
 
     def print_window(self, event):
+        m = tkMessageBox.Message(
+            title="Print",
+            message="Print to Default Printer",
+            icon=tkMessageBox.QUESTION,
+            type=tkMessageBox.OKCANCEL,
+            default=tkMessageBox.OK,
+            master=self.text)
+        reply = m.show()
+        if reply != tkMessageBox.OK:
+            self.text.focus_set()
+            return "break"
         tempfilename = None
         saved = self.get_saved()
         if saved:
             filename = self.filename
         # shell undo is reset after every prompt, looks saved, probably isn't
         if not saved or filename is None:
-            # XXX KBK 08Jun03 Wouldn't it be better to ask the user to save?
             (tfd, tempfilename) = tempfile.mkstemp(prefix='IDLE_tmp_')
             filename = tempfilename
             os.close(tfd)

Modified: python/branches/py3k-importlib/Lib/idlelib/MultiCall.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/MultiCall.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/MultiCall.py	Thu Mar 27 00:48:05 2008
@@ -30,7 +30,6 @@
 """
 
 import sys
-import os
 import re
 import Tkinter
 
@@ -125,7 +124,7 @@
     statelist = []
     for state in states:
         substates = list(set(state & x for x in states))
-        substates.sort(lambda a,b: nbits(b) - nbits(a))
+        substates.sort(key=nbits, reverse=True)
         statelist.append(substates)
     return statelist
 

Modified: python/branches/py3k-importlib/Lib/idlelib/NEWS.txt
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/NEWS.txt	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/NEWS.txt	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,22 @@
+What's New in IDLE 3.0a3?
+=========================
+
+*Release date: 29-Feb-2008*
+
+- help() was not paging to the shell.  Issue1650.
+
+- CodeContext was not importing.
+
+- Corrected two 3.0 compatibility errors reported by Mark Summerfield:
+  http://mail.python.org/pipermail/python-3000/2007-December/011491.html
+
+- Shell was not colorizing due to bug introduced at r57998,  Bug 1586.
+
+
 What's New in IDLE 3.0a2?
 =========================
 
-*Release date: XX-XXX-2007*
+*Release date: 06-Dec-2007*
 
 - Windows EOL sequence not converted correctly, encoding error.
   Caused file save to fail. Bug 1130.
@@ -28,7 +43,45 @@
 What's New in IDLE 2.6a1?
 =========================
 
-*Release date: XX-XXX-200X*  UNRELEASED, but merged into 3.0a1
+*Release date: XX-XXX-200X*  UNRELEASED, but merged into 3.0
+
+- Configured selection highlighting colors were ignored; updating highlighting
+  in the config dialog would cause non-Python files to be colored as if they
+  were Python source; improve use of ColorDelagator.  Patch 1334. Tal Einat.
+
+- ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
+
+- There was an error on exit if no sys.exitfunc was defined. Issue 1647.
+
+- Could not open files in .idlerc directory if latter was hidden on Windows.
+  Issue 1743, Issue 1862.
+
+- Configure Dialog: improved layout for keybinding.  Patch 1457 Tal Einat.
+
+- tabpage.py updated: tabbedPages.py now supports multiple dynamic rows
+  of tabs.  Patch 1612746 Tal Einat.
+
+- Add confirmation dialog before printing.  Patch 1717170 Tal Einat.
+
+- Show paste position if > 80 col.  Patch 1659326 Tal Einat.
+
+- Update cursor color without restarting.  Patch 1725576 Tal Einat.
+
+- Allow keyboard interrupt only when user code is executing in subprocess.
+  Patch 1225 Tal Einat (reworked from IDLE-Spoon).
+
+- configDialog cleanup. Patch 1730217 Tal Einat.
+
+- textView cleanup. Patch 1718043 Tal Einat.
+
+- Clean up EditorWindow close.
+
+- Patch 1693258: Fix for duplicate "preferences" menu-OS X. Backport of r56204.
+
+- OSX: Avoid crash for those versions of Tcl/Tk which don't have a console
+
+- Bug in idlelib.MultiCall: Options dialog was crashing IDLE if there was an
+  option in config-extensions w/o a value. Patch #1672481, Tal Einat
 
 - Corrected some bugs in AutoComplete.  Also, Page Up/Down in ACW implemented;
   mouse and cursor selection in ACWindow implemented; double Tab inserts
@@ -51,6 +104,8 @@
 - Bug #813342: Start the IDLE subprocess with -Qnew if the parent
   is started with that option.
 
+- Honor the "Cancel" action in the save dialog (Debian bug #299092)
+
 - Some syntax errors were being caught by tokenize during the tabnanny
   check, resulting in obscure error messages.  Do the syntax check
   first.  Bug 1562716, 1562719

Modified: python/branches/py3k-importlib/Lib/idlelib/OutputWindow.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/OutputWindow.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/OutputWindow.py	Thu Mar 27 00:48:05 2008
@@ -35,7 +35,7 @@
     # Act as output file
 
     def write(self, s, tags=(), mark="insert"):
-        if isinstance(s, (bytes, str8)):
+        if isinstance(s, (bytes, bytes)):
             s = s.decode(IOBinding.encoding, "replace")
         self.text.insert(mark, s, tags)
         self.text.see(mark)

Modified: python/branches/py3k-importlib/Lib/idlelib/PyParse.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/PyParse.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/PyParse.py	Thu Mar 27 00:48:05 2008
@@ -94,15 +94,16 @@
 # Build translation table to map uninteresting chars to "x", open
 # brackets to "(", and close brackets to ")".
 
-_tran = ['x'] * 256
+_tran = {}
+for i in range(256):
+    _tran[i] = 'x'
 for ch in "({[":
     _tran[ord(ch)] = '('
 for ch in ")}]":
     _tran[ord(ch)] = ')'
 for ch in "\"'\\\n#":
     _tran[ord(ch)] = ch
-_tran = ''.join(_tran)
-del ch
+del i, ch
 
 class Parser:
 

Modified: python/branches/py3k-importlib/Lib/idlelib/PyShell.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/PyShell.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/PyShell.py	Thu Mar 27 00:48:05 2008
@@ -296,9 +296,6 @@
             "stdout": idleConf.GetHighlight(theme, "stdout"),
             "stderr": idleConf.GetHighlight(theme, "stderr"),
             "console": idleConf.GetHighlight(theme, "console"),
-            ### KBK 10Aug07: None tag doesn't seem to serve a purpose and
-            ### breaks in py3k.  Comment out for now.
-            #None: idleConf.GetHighlight(theme, "normal"),
         })
 
 class ModifiedUndoDelegator(UndoDelegator):
@@ -814,6 +811,8 @@
         text.bind("<<open-stack-viewer>>", self.open_stack_viewer)
         text.bind("<<toggle-debugger>>", self.toggle_debugger)
         text.bind("<<toggle-jit-stack-viewer>>", self.toggle_jit_stack_viewer)
+        self.color = color = self.ColorDelegator()
+        self.per.insertfilter(color)
         if use_subprocess:
             text.bind("<<view-restart>>", self.view_restart_mark)
             text.bind("<<restart-shell>>", self.restart_shell)
@@ -829,6 +828,14 @@
             sys.stdout = self.stdout
             sys.stderr = self.stderr
             sys.stdin = self
+        try:
+            # page help() text to shell.
+            import pydoc # import must be done here to capture i/o rebinding.
+            # XXX KBK 27Dec07 use a textView someday, but must work w/o subproc
+            pydoc.pager = pydoc.plainpager
+        except:
+            sys.stderr = sys.__stderr__
+            raise
         #
         self.history = self.History(self.text)
         #

Modified: python/branches/py3k-importlib/Lib/idlelib/RemoteDebugger.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/RemoteDebugger.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/RemoteDebugger.py	Thu Mar 27 00:48:05 2008
@@ -20,7 +20,6 @@
 
 """
 
-import sys
 import types
 from idlelib import rpc
 from idlelib import Debugger
@@ -172,7 +171,7 @@
     def dict_item(self, did, key):
         dict = dicttable[did]
         value = dict[key]
-        value = repr(value) ### can't pickle module '__builtin__'
+        value = repr(value) ### can't pickle module 'builtins'
         return value
 
 #----------end class IdbAdapter----------

Modified: python/branches/py3k-importlib/Lib/idlelib/ScriptBinding.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/ScriptBinding.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/ScriptBinding.py	Thu Mar 27 00:48:05 2008
@@ -55,11 +55,11 @@
     def check_module_event(self, event):
         filename = self.getfilename()
         if not filename:
-            return
+            return 'break'
         if not self.checksyntax(filename):
-            return
+            return 'break'
         if not self.tabnanny(filename):
-            return
+            return 'break'
 
     def tabnanny(self, filename):
         f = open(filename, 'r')
@@ -120,12 +120,12 @@
         """
         filename = self.getfilename()
         if not filename:
-            return
+            return 'break'
         code = self.checksyntax(filename)
         if not code:
-            return
+            return 'break'
         if not self.tabnanny(filename):
-            return
+            return 'break'
         shell = self.shell
         interp = shell.interp
         if PyShell.use_subprocess:
@@ -148,6 +148,7 @@
         #         go to __stderr__.  With subprocess, they go to the shell.
         #         Need to change streams in PyShell.ModifiedInterpreter.
         interp.runcode(code)
+        return 'break'
 
     def getfilename(self):
         """Get source filename.  If not saved, offer to save (or create) file

Modified: python/branches/py3k-importlib/Lib/idlelib/TreeWidget.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/TreeWidget.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/TreeWidget.py	Thu Mar 27 00:48:05 2008
@@ -15,7 +15,6 @@
 # - optimize tree redraw after expand of subnode
 
 import os
-import sys
 from Tkinter import *
 import imp
 
@@ -398,7 +397,7 @@
             names = os.listdir(self.path)
         except os.error:
             return []
-        names.sort(lambda a, b: cmp(os.path.normcase(a), os.path.normcase(b)))
+        names.sort(key = os.path.normcase)
         sublist = []
         for name in names:
             item = FileTreeItem(os.path.join(self.path, name))

Modified: python/branches/py3k-importlib/Lib/idlelib/UndoDelegator.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/UndoDelegator.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/UndoDelegator.py	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-import sys
 import string
 from Tkinter import *
 

Modified: python/branches/py3k-importlib/Lib/idlelib/WidgetRedirector.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/WidgetRedirector.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/WidgetRedirector.py	Thu Mar 27 00:48:05 2008
@@ -1,17 +1,38 @@
 from Tkinter import *
 
-
 class WidgetRedirector:
 
-    """Support for redirecting arbitrary widget subcommands."""
+    """Support for redirecting arbitrary widget subcommands.
+
+    Some Tk operations don't normally pass through Tkinter.  For example, if a
+    character is inserted into a Text widget by pressing a key, a default Tk
+    binding to the widget's 'insert' operation is activated, and the Tk library
+    processes the insert without calling back into Tkinter.
+
+    Although a binding to <Key> could be made via Tkinter, what we really want
+    to do is to hook the Tk 'insert' operation itself.
+
+    When a widget is instantiated, a Tcl command is created whose name is the
+    same as the pathname widget._w.  This command is used to invoke the various
+    widget operations, e.g. insert (for a Text widget). We are going to hook
+    this command and provide a facility ('register') to intercept the widget
+    operation.
+
+    In IDLE, the function being registered provides access to the top of a
+    Percolator chain.  At the bottom of the chain is a call to the original
+    Tk widget operation.
 
+    """
     def __init__(self, widget):
-        self.dict = {}
-        self.widget = widget
-        self.tk = tk = widget.tk
-        w = widget._w
+        self._operations = {}
+        self.widget = widget            # widget instance
+        self.tk = tk = widget.tk        # widget's root
+        w = widget._w                   # widget's (full) Tk pathname
         self.orig = w + "_orig"
+        # Rename the Tcl command within Tcl:
         tk.call("rename", w, self.orig)
+        # Create a new Tcl command whose name is the widget's pathname, and
+        # whose action is to dispatch on the operation passed to the widget:
         tk.createcommand(w, self.dispatch)
 
     def __repr__(self):
@@ -19,74 +40,87 @@
                                              self.widget._w)
 
     def close(self):
-        for name in list(self.dict.keys()):
-            self.unregister(name)
+        for operation in list(self._operations):
+            self.unregister(operation)
         widget = self.widget; del self.widget
         orig = self.orig; del self.orig
         tk = widget.tk
         w = widget._w
         tk.deletecommand(w)
+        # restore the original widget Tcl command:
         tk.call("rename", orig, w)
 
-    def register(self, name, function):
-        if name in self.dict:
-            previous = dict[name]
-        else:
-            previous = OriginalCommand(self, name)
-        self.dict[name] = function
-        setattr(self.widget, name, function)
-        return previous
-
-    def unregister(self, name):
-        if name in self.dict:
-            function = self.dict[name]
-            del self.dict[name]
-            if hasattr(self.widget, name):
-                delattr(self.widget, name)
+    def register(self, operation, function):
+        self._operations[operation] = function
+        setattr(self.widget, operation, function)
+        return OriginalCommand(self, operation)
+
+    def unregister(self, operation):
+        if operation in self._operations:
+            function = self._operations[operation]
+            del self._operations[operation]
+            if hasattr(self.widget, operation):
+                delattr(self.widget, operation)
             return function
         else:
             return None
 
-    def dispatch(self, cmd, *args):
-        m = self.dict.get(cmd)
+    def dispatch(self, operation, *args):
+        '''Callback from Tcl which runs when the widget is referenced.
+
+        If an operation has been registered in self._operations, apply the
+        associated function to the args passed into Tcl. Otherwise, pass the
+        operation through to Tk via the original Tcl function.
+
+        Note that if a registered function is called, the operation is not
+        passed through to Tk.  Apply the function returned by self.register()
+        to *args to accomplish that.  For an example, see ColorDelegator.py.
+
+        '''
+        m = self._operations.get(operation)
         try:
             if m:
                 return m(*args)
             else:
-                return self.tk.call((self.orig, cmd) + args)
+                return self.tk.call((self.orig, operation) + args)
         except TclError:
             return ""
 
 
 class OriginalCommand:
 
-    def __init__(self, redir, name):
+    def __init__(self, redir, operation):
         self.redir = redir
-        self.name = name
+        self.operation = operation
         self.tk = redir.tk
         self.orig = redir.orig
         self.tk_call = self.tk.call
-        self.orig_and_name = (self.orig, self.name)
+        self.orig_and_operation = (self.orig, self.operation)
 
     def __repr__(self):
-        return "OriginalCommand(%r, %r)" % (self.redir, self.name)
+        return "OriginalCommand(%r, %r)" % (self.redir, self.operation)
 
     def __call__(self, *args):
-        return self.tk_call(self.orig_and_name + args)
+        return self.tk_call(self.orig_and_operation + args)
 
 
 def main():
     root = Tk()
+    root.wm_protocol("WM_DELETE_WINDOW", root.quit)
     text = Text()
     text.pack()
     text.focus_set()
     redir = WidgetRedirector(text)
-    global orig_insert
+    global previous_tcl_fcn
     def my_insert(*args):
         print("insert", args)
-        orig_insert(*args)
-    orig_insert = redir.register("insert", my_insert)
+        previous_tcl_fcn(*args)
+    previous_tcl_fcn = redir.register("insert", my_insert)
+    root.mainloop()
+    redir.unregister("insert")  # runs after first 'close window'
+    redir.close()
     root.mainloop()
+    root.destroy()
 
 if __name__ == "__main__":
     main()

Modified: python/branches/py3k-importlib/Lib/idlelib/aboutDialog.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/aboutDialog.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/aboutDialog.py	Thu Mar 27 00:48:05 2008
@@ -111,45 +111,31 @@
         idle_credits_b.pack(side=LEFT, padx=10, pady=10)
 
     def ShowLicense(self):
-        self.display_printer_text(license, 'About - License')
+        self.display_printer_text('About - License', license)
 
     def ShowCopyright(self):
-        self.display_printer_text(copyright, 'About - Copyright')
+        self.display_printer_text('About - Copyright', copyright)
 
     def ShowPythonCredits(self):
-        self.display_printer_text(credits, 'About - Python Credits')
+        self.display_printer_text('About - Python Credits', credits)
 
     def ShowIDLECredits(self):
-        self.ViewFile('About - Credits','CREDITS.txt')
+        self.display_file_text('About - Credits', 'CREDITS.txt', 'iso-8859-1')
 
     def ShowIDLEAbout(self):
-        self.ViewFile('About - Readme', 'README.txt')
+        self.display_file_text('About - Readme', 'README.txt')
 
     def ShowIDLENEWS(self):
-        self.ViewFile('About - NEWS', 'NEWS.txt')
+        self.display_file_text('About - NEWS', 'NEWS.txt')
 
-    def display_printer_text(self, printer, title):
+    def display_printer_text(self, title, printer):
         printer._Printer__setup()
-        data = '\n'.join(printer._Printer__lines)
-        textView.TextViewer(self, title, None, data)
+        text = '\n'.join(printer._Printer__lines)
+        textView.view_text(self, title, text)
 
-    def ViewFile(self, viewTitle, viewFile, encoding=None):
-        fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), viewFile)
-        if encoding:
-            import codecs
-            try:
-                textFile = codecs.open(fn, 'r')
-            except IOError:
-                import tkMessageBox
-                tkMessageBox.showerror(title='File Load Error',
-                                       message='Unable to load file %r .' % (fn,),
-                                       parent=self)
-                return
-            else:
-                data = textFile.read()
-        else:
-            data = None
-        textView.TextViewer(self, viewTitle, fn, data=data)
+    def display_file_text(self, title, filename, encoding=None):
+        fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
+        textView.view_file(self, title, fn, encoding)
 
     def Ok(self, event=None):
         self.destroy()

Modified: python/branches/py3k-importlib/Lib/idlelib/configDialog.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/configDialog.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/configDialog.py	Thu Mar 27 00:48:05 2008
@@ -15,7 +15,7 @@
 
 from idlelib.configHandler import idleConf
 from idlelib.dynOptionMenuWidget import DynOptionMenu
-from idlelib.tabpage import TabPageSet
+from idlelib.tabbedpages import TabbedPageSet
 from idlelib.keybindingDialog import GetKeysDialog
 from idlelib.configSectionNameDialog import GetCfgSectionNameDialog
 from idlelib.configHelpSourceEdit import GetHelpSourceDialog
@@ -24,6 +24,8 @@
 
     def __init__(self,parent,title):
         Toplevel.__init__(self, parent)
+        self.wm_withdraw()
+
         self.configure(borderwidth=5)
         self.geometry("+%d+%d" % (parent.winfo_rootx()+20,
                 parent.winfo_rooty()+30))
@@ -58,31 +60,37 @@
         #self.bind('<F1>',self.Help) #context help
         self.LoadConfigs()
         self.AttachVarCallbacks() #avoid callbacks during LoadConfigs
+
+        self.wm_deiconify()
         self.wait_window()
 
     def CreateWidgets(self):
-        self.tabPages = TabPageSet(self,
-                pageNames=['Fonts/Tabs','Highlighting','Keys','General'])
-        self.tabPages.ChangePage()#activates default (first) page
-        frameActionButtons = Frame(self)
+        self.tabPages = TabbedPageSet(self,
+                page_names=['Fonts/Tabs','Highlighting','Keys','General'])
+        frameActionButtons = Frame(self,pady=2)
         #action buttons
         self.buttonHelp = Button(frameActionButtons,text='Help',
-                command=self.Help,takefocus=FALSE)
+                command=self.Help,takefocus=FALSE,
+                padx=6,pady=3)
         self.buttonOk = Button(frameActionButtons,text='Ok',
-                command=self.Ok,takefocus=FALSE)
+                command=self.Ok,takefocus=FALSE,
+                padx=6,pady=3)
         self.buttonApply = Button(frameActionButtons,text='Apply',
-                command=self.Apply,takefocus=FALSE)
+                command=self.Apply,takefocus=FALSE,
+                padx=6,pady=3)
         self.buttonCancel = Button(frameActionButtons,text='Cancel',
-                command=self.Cancel,takefocus=FALSE)
+                command=self.Cancel,takefocus=FALSE,
+                padx=6,pady=3)
         self.CreatePageFontTab()
         self.CreatePageHighlight()
         self.CreatePageKeys()
         self.CreatePageGeneral()
-        self.buttonHelp.pack(side=RIGHT,padx=5,pady=5)
-        self.buttonOk.pack(side=LEFT,padx=5,pady=5)
-        self.buttonApply.pack(side=LEFT,padx=5,pady=5)
-        self.buttonCancel.pack(side=LEFT,padx=5,pady=5)
+        self.buttonHelp.pack(side=RIGHT,padx=5)
+        self.buttonOk.pack(side=LEFT,padx=5)
+        self.buttonApply.pack(side=LEFT,padx=5)
+        self.buttonCancel.pack(side=LEFT,padx=5)
         frameActionButtons.pack(side=BOTTOM)
+        Frame(self, height=2, borderwidth=0).pack(side=BOTTOM)
         self.tabPages.pack(side=TOP,expand=TRUE,fill=BOTH)
 
     def CreatePageFontTab(self):
@@ -94,16 +102,17 @@
         self.editFont=tkFont.Font(self,('courier',10,'normal'))
         ##widget creation
         #body frame
-        frame=self.tabPages.pages['Fonts/Tabs']['page']
+        frame=self.tabPages.pages['Fonts/Tabs'].frame
         #body section frames
-        frameFont=Frame(frame,borderwidth=2,relief=GROOVE)
-        frameIndent=Frame(frame,borderwidth=2,relief=GROOVE)
+        frameFont=LabelFrame(frame,borderwidth=2,relief=GROOVE,
+                             text=' Base Editor Font ')
+        frameIndent=LabelFrame(frame,borderwidth=2,relief=GROOVE,
+                               text=' Indentation Width ')
         #frameFont
-        labelFontTitle=Label(frameFont,text='Set Base Editor Font')
         frameFontName=Frame(frameFont)
         frameFontParam=Frame(frameFont)
         labelFontNameTitle=Label(frameFontName,justify=LEFT,
-                text='Font :')
+                text='Font Face :')
         self.listFontName=Listbox(frameFontName,height=5,takefocus=FALSE,
                 exportselection=FALSE)
         self.listFontName.bind('<ButtonRelease-1>',self.OnListFontButtonRelease)
@@ -124,14 +133,13 @@
         labelSpaceNumTitle=Label(frameIndentSize, justify=LEFT,
                                  text='Python Standard: 4 Spaces!')
         self.scaleSpaceNum=Scale(frameIndentSize, variable=self.spaceNum,
-                                 label='Indentation Width', orient='horizontal',
+                                 orient='horizontal',
                                  tickinterval=2, from_=2, to=16)
         #widget packing
         #body
-        frameFont.pack(side=LEFT,padx=5,pady=10,expand=TRUE,fill=BOTH)
-        frameIndent.pack(side=LEFT,padx=5,pady=10,fill=Y)
+        frameFont.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH)
+        frameIndent.pack(side=LEFT,padx=5,pady=5,fill=Y)
         #frameFont
-        labelFontTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
         frameFontName.pack(side=TOP,padx=5,pady=5,fill=X)
         frameFontParam.pack(side=TOP,padx=5,pady=5,fill=X)
         labelFontNameTitle.pack(side=TOP,anchor=W)
@@ -143,7 +151,7 @@
         frameFontSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
         self.labelFontSample.pack(expand=TRUE,fill=BOTH)
         #frameIndent
-        frameIndentSize.pack(side=TOP,padx=5,pady=5,fill=BOTH)
+        frameIndentSize.pack(side=TOP,fill=X)
         labelSpaceNumTitle.pack(side=TOP,anchor=W,padx=5)
         self.scaleSpaceNum.pack(side=TOP,padx=5,fill=X)
         return frame
@@ -158,10 +166,12 @@
         self.highlightTarget=StringVar(self)
         ##widget creation
         #body frame
-        frame=self.tabPages.pages['Highlighting']['page']
+        frame=self.tabPages.pages['Highlighting'].frame
         #body section frames
-        frameCustom=Frame(frame,borderwidth=2,relief=GROOVE)
-        frameTheme=Frame(frame,borderwidth=2,relief=GROOVE)
+        frameCustom=LabelFrame(frame,borderwidth=2,relief=GROOVE,
+                               text=' Custom Highlighting ')
+        frameTheme=LabelFrame(frame,borderwidth=2,relief=GROOVE,
+                              text=' Highlighting Theme ')
         #frameCustom
         self.textHighlightSample=Text(frameCustom,relief=SOLID,borderwidth=1,
             font=('courier',12,''),cursor='hand2',width=21,height=10,
@@ -189,7 +199,6 @@
         text.config(state=DISABLED)
         self.frameColourSet=Frame(frameCustom,relief=SOLID,borderwidth=1)
         frameFgBg=Frame(frameCustom)
-        labelCustomTitle=Label(frameCustom,text='Set Custom Highlighting')
         buttonSetColour=Button(self.frameColourSet,text='Choose Colour for :',
             command=self.GetColour,highlightthickness=0)
         self.optMenuHighlightTarget=DynOptionMenu(self.frameColourSet,
@@ -202,7 +211,6 @@
         buttonSaveCustomTheme=Button(frameCustom,
             text='Save as New Custom Theme',command=self.SaveAsNewTheme)
         #frameTheme
-        labelThemeTitle=Label(frameTheme,text='Select a Highlighting Theme')
         labelTypeTitle=Label(frameTheme,text='Select : ')
         self.radioThemeBuiltin=Radiobutton(frameTheme,variable=self.themeIsBuiltin,
             value=1,command=self.SetThemeType,text='a Built-in Theme')
@@ -216,10 +224,9 @@
                 command=self.DeleteCustomTheme)
         ##widget packing
         #body
-        frameCustom.pack(side=LEFT,padx=5,pady=10,expand=TRUE,fill=BOTH)
-        frameTheme.pack(side=LEFT,padx=5,pady=10,fill=Y)
+        frameCustom.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH)
+        frameTheme.pack(side=LEFT,padx=5,pady=5,fill=Y)
         #frameCustom
-        labelCustomTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
         self.frameColourSet.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=X)
         frameFgBg.pack(side=TOP,padx=5,pady=0)
         self.textHighlightSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,
@@ -230,7 +237,6 @@
         self.radioBg.pack(side=RIGHT,anchor=W)
         buttonSaveCustomTheme.pack(side=BOTTOM,fill=X,padx=5,pady=5)
         #frameTheme
-        labelThemeTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
         labelTypeTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
         self.radioThemeBuiltin.pack(side=TOP,anchor=W,padx=5)
         self.radioThemeCustom.pack(side=TOP,anchor=W,padx=5,pady=2)
@@ -248,13 +254,14 @@
         self.keyBinding=StringVar(self)
         ##widget creation
         #body frame
-        frame=self.tabPages.pages['Keys']['page']
+        frame=self.tabPages.pages['Keys'].frame
         #body section frames
-        frameCustom=Frame(frame,borderwidth=2,relief=GROOVE)
-        frameKeySets=Frame(frame,borderwidth=2,relief=GROOVE)
+        frameCustom=LabelFrame(frame,borderwidth=2,relief=GROOVE,
+                               text=' Custom Key Bindings ')
+        frameKeySets=LabelFrame(frame,borderwidth=2,relief=GROOVE,
+                           text=' Key Set ')
         #frameCustom
         frameTarget=Frame(frameCustom)
-        labelCustomTitle=Label(frameCustom,text='Set Custom Key Bindings')
         labelTargetTitle=Label(frameTarget,text='Action - Key(s)')
         scrollTargetY=Scrollbar(frameTarget)
         scrollTargetX=Scrollbar(frameTarget,orient=HORIZONTAL)
@@ -267,28 +274,26 @@
         self.listBindings.config(xscrollcommand=scrollTargetX.set)
         self.buttonNewKeys=Button(frameCustom,text='Get New Keys for Selection',
             command=self.GetNewKeys,state=DISABLED)
-        buttonSaveCustomKeys=Button(frameCustom,
-                text='Save as New Custom Key Set',command=self.SaveAsNewKeySet)
         #frameKeySets
-        labelKeysTitle=Label(frameKeySets,text='Select a Key Set')
-        labelTypeTitle=Label(frameKeySets,text='Select : ')
-        self.radioKeysBuiltin=Radiobutton(frameKeySets,variable=self.keysAreBuiltin,
-            value=1,command=self.SetKeysType,text='a Built-in Key Set')
-        self.radioKeysCustom=Radiobutton(frameKeySets,variable=self.keysAreBuiltin,
-            value=0,command=self.SetKeysType,text='a Custom Key Set')
-        self.optMenuKeysBuiltin=DynOptionMenu(frameKeySets,
+        frames = [Frame(frameKeySets, padx=2, pady=2, borderwidth=0)
+                  for i in range(2)]
+        self.radioKeysBuiltin=Radiobutton(frames[0],variable=self.keysAreBuiltin,
+            value=1,command=self.SetKeysType,text='Use a Built-in Key Set')
+        self.radioKeysCustom=Radiobutton(frames[0],variable=self.keysAreBuiltin,
+            value=0,command=self.SetKeysType,text='Use a Custom Key Set')
+        self.optMenuKeysBuiltin=DynOptionMenu(frames[0],
             self.builtinKeys,None,command=None)
-        self.optMenuKeysCustom=DynOptionMenu(frameKeySets,
+        self.optMenuKeysCustom=DynOptionMenu(frames[0],
             self.customKeys,None,command=None)
-        self.buttonDeleteCustomKeys=Button(frameKeySets,text='Delete Custom Key Set',
+        self.buttonDeleteCustomKeys=Button(frames[1],text='Delete Custom Key Set',
                 command=self.DeleteCustomKeys)
+        buttonSaveCustomKeys=Button(frames[1],
+                text='Save as New Custom Key Set',command=self.SaveAsNewKeySet)
         ##widget packing
         #body
-        frameCustom.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH)
-        frameKeySets.pack(side=LEFT,padx=5,pady=5,fill=Y)
+        frameCustom.pack(side=BOTTOM,padx=5,pady=5,expand=TRUE,fill=BOTH)
+        frameKeySets.pack(side=BOTTOM,padx=5,pady=5,fill=BOTH)
         #frameCustom
-        labelCustomTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
-        buttonSaveCustomKeys.pack(side=BOTTOM,fill=X,padx=5,pady=5)
         self.buttonNewKeys.pack(side=BOTTOM,fill=X,padx=5,pady=5)
         frameTarget.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH)
         #frame target
@@ -299,13 +304,14 @@
         scrollTargetY.grid(row=1,column=1,sticky=NS)
         scrollTargetX.grid(row=2,column=0,sticky=EW)
         #frameKeySets
-        labelKeysTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
-        labelTypeTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
-        self.radioKeysBuiltin.pack(side=TOP,anchor=W,padx=5)
-        self.radioKeysCustom.pack(side=TOP,anchor=W,padx=5,pady=2)
-        self.optMenuKeysBuiltin.pack(side=TOP,fill=X,padx=5,pady=5)
-        self.optMenuKeysCustom.pack(side=TOP,fill=X,anchor=W,padx=5,pady=5)
-        self.buttonDeleteCustomKeys.pack(side=TOP,fill=X,padx=5,pady=5)
+        self.radioKeysBuiltin.grid(row=0, column=0, sticky=W+NS)
+        self.radioKeysCustom.grid(row=1, column=0, sticky=W+NS)
+        self.optMenuKeysBuiltin.grid(row=0, column=1, sticky=NSEW)
+        self.optMenuKeysCustom.grid(row=1, column=1, sticky=NSEW)
+        self.buttonDeleteCustomKeys.pack(side=LEFT,fill=X,expand=True,padx=2)
+        buttonSaveCustomKeys.pack(side=LEFT,fill=X,expand=True,padx=2)
+        frames[0].pack(side=TOP, fill=BOTH, expand=True)
+        frames[1].pack(side=TOP, fill=X, expand=True, pady=2)
         return frame
 
     def CreatePageGeneral(self):
@@ -320,23 +326,24 @@
         self.helpBrowser=StringVar(self)
         #widget creation
         #body
-        frame=self.tabPages.pages['General']['page']
+        frame=self.tabPages.pages['General'].frame
         #body section frames
-        frameRun=Frame(frame,borderwidth=2,relief=GROOVE)
-        frameSave=Frame(frame,borderwidth=2,relief=GROOVE)
+        frameRun=LabelFrame(frame,borderwidth=2,relief=GROOVE,
+                            text=' Startup Preferences ')
+        frameSave=LabelFrame(frame,borderwidth=2,relief=GROOVE,
+                             text=' Autosave Preferences ')
         frameWinSize=Frame(frame,borderwidth=2,relief=GROOVE)
         frameParaSize=Frame(frame,borderwidth=2,relief=GROOVE)
         frameEncoding=Frame(frame,borderwidth=2,relief=GROOVE)
-        frameHelp=Frame(frame,borderwidth=2,relief=GROOVE)
+        frameHelp=LabelFrame(frame,borderwidth=2,relief=GROOVE,
+                             text=' Additional Help Sources ')
         #frameRun
-        labelRunTitle=Label(frameRun,text='Startup Preferences')
         labelRunChoiceTitle=Label(frameRun,text='At Startup')
         radioStartupEdit=Radiobutton(frameRun,variable=self.startupEdit,
             value=1,command=self.SetKeysType,text="Open Edit Window")
         radioStartupShell=Radiobutton(frameRun,variable=self.startupEdit,
             value=0,command=self.SetKeysType,text='Open Shell Window')
         #frameSave
-        labelSaveTitle=Label(frameSave,text='Autosave Preference')
         labelRunSaveTitle=Label(frameSave,text='At Start of Run (F5)  ')
         radioSaveAsk=Radiobutton(frameSave,variable=self.autoSave,
             value=0,command=self.SetKeysType,text="Prompt to Save")
@@ -367,7 +374,6 @@
         #frameHelp
         frameHelpList=Frame(frameHelp)
         frameHelpListButtons=Frame(frameHelpList)
-        labelHelpListTitle=Label(frameHelpList,text='Additional Help Sources:')
         scrollHelpList=Scrollbar(frameHelpList)
         self.listHelp=Listbox(frameHelpList,height=5,takefocus=FALSE,
                 exportselection=FALSE)
@@ -389,12 +395,10 @@
         frameEncoding.pack(side=TOP,padx=5,pady=5,fill=X)
         frameHelp.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
         #frameRun
-        labelRunTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
         labelRunChoiceTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
         radioStartupShell.pack(side=RIGHT,anchor=W,padx=5,pady=5)
         radioStartupEdit.pack(side=RIGHT,anchor=W,padx=5,pady=5)
         #frameSave
-        labelSaveTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
         labelRunSaveTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
         radioSaveAuto.pack(side=RIGHT,anchor=W,padx=5,pady=5)
         radioSaveAsk.pack(side=RIGHT,anchor=W,padx=5,pady=5)
@@ -415,7 +419,6 @@
         #frameHelp
         frameHelpListButtons.pack(side=RIGHT,padx=5,pady=5,fill=Y)
         frameHelpList.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
-        labelHelpListTitle.pack(side=TOP,anchor=W)
         scrollHelpList.pack(side=RIGHT,anchor=W,fill=Y)
         self.listHelp.pack(side=LEFT,anchor=E,expand=TRUE,fill=BOTH)
         self.buttonHelpListEdit.pack(side=TOP,anchor=W,pady=5)
@@ -977,16 +980,11 @@
         self.SetThemeType()
         ##load theme element option menu
         themeNames = list(self.themeElements.keys())
-        themeNames.sort(self.__ThemeNameIndexCompare)
+        themeNames.sort(key=lambda x: self.themeElements[x][1])
         self.optMenuHighlightTarget.SetMenu(themeNames,themeNames[0])
         self.PaintThemeSample()
         self.SetHighlightTarget()
 
-    def __ThemeNameIndexCompare(self,a,b):
-        if self.themeElements[a][1]<self.themeElements[b][1]: return -1
-        elif self.themeElements[a][1]==self.themeElements[b][1]: return 0
-        else: return 1
-
     def LoadKeyCfg(self):
         ##current keys type radiobutton
         self.keysAreBuiltin.set(idleConf.GetOption('main','Keys','default',

Modified: python/branches/py3k-importlib/Lib/idlelib/configHandler.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/configHandler.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/configHandler.py	Thu Mar 27 00:48:05 2008
@@ -139,7 +139,12 @@
 
         """
         if not self.IsEmpty():
-            cfgFile=open(self.file,'w')
+            fname = self.file
+            try:
+                cfgFile = open(fname, 'w')
+            except IOError:
+                os.unlink(fname)
+                cfgFile = open(fname, 'w')
             self.write(cfgFile)
         else:
             self.RemoveFile()
@@ -637,17 +642,9 @@
                 helpPath=value[1].strip()
             if menuItem and helpPath: #neither are empty strings
                 helpSources.append( (menuItem,helpPath,option) )
-        helpSources.sort(self.__helpsort)
+        helpSources.sort(key=lambda x: x[2])
         return helpSources
 
-    def __helpsort(self, h1, h2):
-        if int(h1[2]) < int(h2[2]):
-            return -1
-        elif int(h1[2]) > int(h2[2]):
-            return 1
-        else:
-            return 0
-
     def GetAllExtraHelpSourcesList(self):
         """
         Returns a list of tuples containing the details of all additional help

Modified: python/branches/py3k-importlib/Lib/idlelib/idlever.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/idlever.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/idlever.py	Thu Mar 27 00:48:05 2008
@@ -1 +1 @@
-IDLE_VERSION = "3.0a1"
+IDLE_VERSION = "3.0a3"

Modified: python/branches/py3k-importlib/Lib/idlelib/keybindingDialog.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/keybindingDialog.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/keybindingDialog.py	Thu Mar 27 00:48:05 2008
@@ -3,7 +3,7 @@
 """
 from Tkinter import *
 import tkMessageBox
-import string, os
+import string
 
 class GetKeysDialog(Toplevel):
     def __init__(self,parent,title,action,currentKeySequences):

Modified: python/branches/py3k-importlib/Lib/idlelib/run.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/run.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/run.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,4 @@
 import sys
-import os
 import linecache
 import time
 import socket
@@ -38,10 +37,11 @@
 
 # Thread shared globals: Establish a queue between a subthread (which handles
 # the socket) and the main thread (which runs user code), plus global
-# completion and exit flags:
+# completion, exit and interruptable (the main thread) flags:
 
 exit_now = False
 quitting = False
+interruptable = False
 
 def main(del_exitfunc=False):
     """Start the Python execution server in a subprocess
@@ -115,8 +115,8 @@
             server = MyRPCServer(address, MyHandler)
             break
         except socket.error as err:
-            print("IDLE Subprocess: socket error: "\
-                                        + err[1] + ", retrying....", file=sys.__stderr__)
+            print("IDLE Subprocess: socket error: " + err.args[1] +
+                  ", retrying....", file=sys.__stderr__)
     else:
         print("IDLE Subprocess: Connection to "\
                                "IDLE GUI failed, exiting.", file=sys.__stderr__)
@@ -131,14 +131,15 @@
     import tkMessageBox
     root = Tkinter.Tk()
     root.withdraw()
-    if err[0] == 61: # connection refused
+    if err.args[0] == 61: # connection refused
         msg = "IDLE's subprocess can't connect to %s:%d.  This may be due "\
               "to your personal firewall configuration.  It is safe to "\
               "allow this internal connection because no data is visible on "\
               "external ports." % address
         tkMessageBox.showerror("IDLE Subprocess Error", msg, parent=root)
     else:
-        tkMessageBox.showerror("IDLE Subprocess Error", "Socket Error: %s" % err[1])
+        tkMessageBox.showerror("IDLE Subprocess Error",
+                               "Socket Error: %s" % err.args[1])
     root.destroy()
 
 def print_exception():
@@ -245,6 +246,9 @@
         sys.stdin = self.console = self.get_remote_proxy("stdin")
         sys.stdout = self.get_remote_proxy("stdout")
         sys.stderr = self.get_remote_proxy("stderr")
+        # page help() text to shell.
+        import pydoc # import must be done here to capture i/o binding
+        pydoc.pager = pydoc.plainpager
         from idlelib import IOBinding
         sys.stdin.encoding = sys.stdout.encoding = \
                              sys.stderr.encoding = IOBinding.encoding
@@ -277,9 +281,14 @@
         self.autocomplete = AutoComplete.AutoComplete()
 
     def runcode(self, code):
+        global interruptable
         try:
             self.usr_exc_info = None
-            exec(code, self.locals)
+            interruptable = True
+            try:
+                exec(code, self.locals)
+            finally:
+                interruptable = False
         except:
             self.usr_exc_info = sys.exc_info()
             if quitting:
@@ -293,7 +302,8 @@
             flush_stdout()
 
     def interrupt_the_server(self):
-        thread.interrupt_main()
+        if interruptable:
+            thread.interrupt_main()
 
     def start_the_debugger(self, gui_adap_oid):
         return RemoteDebugger.start_debugger(self.rpchandler, gui_adap_oid)

Deleted: /python/branches/py3k-importlib/Lib/idlelib/tabpage.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/idlelib/tabpage.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,113 +0,0 @@
-"""
-a couple of classes for implementing partial tabbed-page like behaviour
-"""
-
-from Tkinter import *
-
-class InvalidTabPage(Exception): pass
-class AlreadyExists(Exception): pass
-
-class PageTab(Frame):
-    """
-    a 'page tab' like framed button
-    """
-    def __init__(self,parent):
-        Frame.__init__(self, parent,borderwidth=2,relief=RIDGE)
-        self.button=Radiobutton(self,padx=5,pady=5,takefocus=FALSE,
-                indicatoron=FALSE,highlightthickness=0,
-                borderwidth=0,selectcolor=self.cget('bg'))
-        self.button.pack()
-
-class TabPageSet(Frame):
-    """
-    a set of 'pages' with TabButtons for controlling their display
-    """
-    def __init__(self,parent,pageNames=[],**kw):
-        """
-        pageNames - a list of strings, each string will be the dictionary key
-        to a page's data, and the name displayed on the page's tab. Should be
-        specified in desired page order. The first page will be the default
-        and first active page.
-        """
-        Frame.__init__(self, parent, kw)
-        self.grid_location(0,0)
-        self.columnconfigure(0,weight=1)
-        self.rowconfigure(1,weight=1)
-        self.tabBar=Frame(self)
-        self.tabBar.grid(row=0,column=0,sticky=EW)
-        self.activePage=StringVar(self)
-        self.defaultPage=''
-        self.pages={}
-        for name in pageNames:
-            self.AddPage(name)
-
-    def ChangePage(self,pageName=None):
-        if pageName:
-            if pageName in self.pages:
-                self.activePage.set(pageName)
-            else:
-                raise InvalidTabPage('Invalid TabPage Name')
-        ## pop up the active 'tab' only
-        for page in self.pages:
-            self.pages[page]['tab'].config(relief=RIDGE)
-        self.pages[self.GetActivePage()]['tab'].config(relief=RAISED)
-        ## switch page
-        self.pages[self.GetActivePage()]['page'].lift()
-
-    def GetActivePage(self):
-        return self.activePage.get()
-
-    def AddPage(self,pageName):
-        if pageName in self.pages.keys():
-            raise AlreadyExists('TabPage Name Already Exists')
-        self.pages[pageName]={'tab':PageTab(self.tabBar),
-                'page':Frame(self,borderwidth=2,relief=RAISED)}
-        self.pages[pageName]['tab'].button.config(text=pageName,
-                command=self.ChangePage,variable=self.activePage,
-                value=pageName)
-        self.pages[pageName]['tab'].pack(side=LEFT)
-        self.pages[pageName]['page'].grid(row=1,column=0,sticky=NSEW)
-        if len(self.pages)==1: # adding first page
-            self.defaultPage=pageName
-            self.activePage.set(self.defaultPage)
-            self.ChangePage()
-
-    def RemovePage(self,pageName):
-        if not pageName in self.pages:
-            raise InvalidTabPage('Invalid TabPage Name')
-        self.pages[pageName]['tab'].pack_forget()
-        self.pages[pageName]['page'].grid_forget()
-        self.pages[pageName]['tab'].destroy()
-        self.pages[pageName]['page'].destroy()
-        del(self.pages[pageName])
-        # handle removing last remaining, or default, or active page
-        if not self.pages: # removed last remaining page
-            self.defaultPage=''
-            return
-        if pageName==self.defaultPage: # set a new default page
-            self.defaultPage=\
-                self.tabBar.winfo_children()[0].button.cget('text')
-        if pageName==self.GetActivePage(): # set a new active page
-            self.activePage.set(self.defaultPage)
-        self.ChangePage()
-
-if __name__ == '__main__':
-    #test dialog
-    root=Tk()
-    tabPage=TabPageSet(root,pageNames=['Foobar','Baz'])
-    tabPage.pack(expand=TRUE,fill=BOTH)
-    Label(tabPage.pages['Foobar']['page'],text='Foo',pady=20).pack()
-    Label(tabPage.pages['Foobar']['page'],text='Bar',pady=20).pack()
-    Label(tabPage.pages['Baz']['page'],text='Baz').pack()
-    entryPgName=Entry(root)
-    buttonAdd=Button(root,text='Add Page',
-            command=lambda:tabPage.AddPage(entryPgName.get()))
-    buttonRemove=Button(root,text='Remove Page',
-            command=lambda:tabPage.RemovePage(entryPgName.get()))
-    labelPgName=Label(root,text='name of page to add/remove:')
-    buttonAdd.pack(padx=5,pady=5)
-    buttonRemove.pack(padx=5,pady=5)
-    labelPgName.pack(padx=5)
-    entryPgName.pack(padx=5)
-    tabPage.ChangePage()
-    root.mainloop()

Modified: python/branches/py3k-importlib/Lib/idlelib/textView.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/textView.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/textView.py	Thu Mar 27 00:48:05 2008
@@ -6,13 +6,12 @@
 import tkMessageBox
 
 class TextViewer(Toplevel):
+    """A simple text viewer dialog for IDLE
+
     """
-    simple text viewer dialog for idle
-    """
-    def __init__(self, parent, title, fileName, data=None):
-        """If data exists, load it into viewer, otherwise try to load file.
+    def __init__(self, parent, title, text):
+        """Show the given text in a scrollable window with a 'close' button
 
-        fileName - string, should be an absoulute filename
         """
         Toplevel.__init__(self, parent)
         self.configure(borderwidth=5)
@@ -33,23 +32,10 @@
         #key bindings for this dialog
         self.bind('<Return>',self.Ok) #dismiss dialog
         self.bind('<Escape>',self.Ok) #dismiss dialog
-        if data:
-            self.textView.insert(0.0, data)
-        else:
-            self.LoadTextFile(fileName)
+        self.textView.insert(0.0, text)
         self.textView.config(state=DISABLED)
         self.wait_window()
 
-    def LoadTextFile(self, fileName):
-        textFile = None
-        try:
-            textFile = open(fileName, 'r')
-        except IOError:
-            tkMessageBox.showerror(title='File Load Error',
-                    message='Unable to load file %r .' % (fileName,))
-        else:
-            self.textView.insert(0.0,textFile.read())
-
     def CreateWidgets(self):
         frameText = Frame(self, relief=SUNKEN, height=700)
         frameButtons = Frame(self)
@@ -70,9 +56,38 @@
     def Ok(self, event=None):
         self.destroy()
 
+
+def view_text(parent, title, text):
+    TextViewer(parent, title, text)
+
+def view_file(parent, title, filename, encoding=None):
+    try:
+        if encoding:
+            import codecs
+            textFile = codecs.open(filename, 'r')
+        else:
+            textFile = open(filename, 'r')
+    except IOError:
+        import tkMessageBox
+        tkMessageBox.showerror(title='File Load Error',
+                               message='Unable to load file %r .' % filename,
+                               parent=parent)
+    else:
+        return view_text(parent, title, textFile.read())
+
+
 if __name__ == '__main__':
     #test the dialog
     root=Tk()
-    Button(root,text='View',
-            command=lambda:TextViewer(root,'Text','./textView.py')).pack()
+    root.title('textView test')
+    filename = './textView.py'
+    text = file(filename, 'r').read()
+    btn1 = Button(root, text='view_text',
+                 command=lambda:view_text(root, 'view_text', text))
+    btn1.pack(side=LEFT)
+    btn2 = Button(root, text='view_file',
+                  command=lambda:view_file(root, 'view_file', filename))
+    btn2.pack(side=LEFT)
+    close = Button(root, text='Close', command=root.destroy)
+    close.pack(side=RIGHT)
     root.mainloop()

Modified: python/branches/py3k-importlib/Lib/ihooks.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ihooks.py	(original)
+++ python/branches/py3k-importlib/Lib/ihooks.py	Thu Mar 27 00:48:05 2008
@@ -49,7 +49,7 @@
 """
 
 
-import __builtin__
+import builtins
 import imp
 import os
 import sys
@@ -375,18 +375,18 @@
         # XXX Should this try to clear the module's namespace?
 
     def install(self):
-        self.save_import_module = __builtin__.__import__
-        if not hasattr(__builtin__, 'unload'):
-            __builtin__.unload = None
-        self.save_unload = __builtin__.unload
-        __builtin__.__import__ = self.import_module
-        __builtin__.unload = self.unload
+        self.save_import_module = builtins.__import__
+        if not hasattr(builtins, 'unload'):
+            builtins.unload = None
+        self.save_unload = builtins.unload
+        builtins.__import__ = self.import_module
+        builtins.unload = self.unload
 
     def uninstall(self):
-        __builtin__.__import__ = self.save_import_module
-        __builtin__.unload = self.save_unload
-        if not __builtin__.unload:
-            del __builtin__.unload
+        builtins.__import__ = self.save_import_module
+        builtins.unload = self.save_unload
+        if not builtins.unload:
+            del builtins.unload
 
 
 class ModuleImporter(BasicModuleImporter):

Modified: python/branches/py3k-importlib/Lib/imaplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/imaplib.py	(original)
+++ python/branches/py3k-importlib/Lib/imaplib.py	Thu Mar 27 00:48:05 2008
@@ -1145,9 +1145,10 @@
             """
             self.host = host
             self.port = port
-            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-            self.sock.connect((host, port))
-            self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
+            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            sock.connect((host, port))
+            self.sock = ssl.wrap_socket(sock, self.keyfile, self.certfile)
+            self.file = self.sock.makefile('rb')
 
 
         def read(self, size):
@@ -1156,11 +1157,11 @@
             chunks = []
             read = 0
             while read < size:
-                data = self.sslobj.read(size-read)
+                data = self.sslobj.read(min(size-read, 16384))
                 read += len(data)
                 chunks.append(data)
 
-            return ''.join(chunks)
+            return b''.join(chunks)
 
 
         def readline(self):
@@ -1169,7 +1170,7 @@
             while 1:
                 char = self.sslobj.read(1)
                 line.append(char)
-                if char == "\n": return ''.join(line)
+                if char == b"\n": return b''.join(line)
 
 
         def send(self, data):
@@ -1201,7 +1202,7 @@
 
             ssl = ssl.wrap_socket(<instance>.socket)
             """
-            return self.sslobj
+            return self.sock
 
     __all__.append("IMAP4_SSL")
 

Modified: python/branches/py3k-importlib/Lib/imputil.py
==============================================================================
--- python/branches/py3k-importlib/Lib/imputil.py	(original)
+++ python/branches/py3k-importlib/Lib/imputil.py	Thu Mar 27 00:48:05 2008
@@ -13,7 +13,7 @@
 # note: avoid importing non-builtin modules
 import imp                      ### not available in JPython?
 import sys
-import __builtin__
+import builtins
 
 # for the DirectoryImporter
 import struct
@@ -26,7 +26,7 @@
 class ImportManager:
     "Manage the import process."
 
-    def install(self, namespace=vars(__builtin__)):
+    def install(self, namespace=vars(builtins)):
         "Install this ImportManager into the specified namespace."
 
         if isinstance(namespace, _ModuleType):
@@ -404,7 +404,7 @@
     codestring = open(pathname, 'rU').read()
     if codestring and codestring[-1] != '\n':
         codestring = codestring + '\n'
-    code = __builtin__.compile(codestring, pathname, 'exec')
+    code = builtins.compile(codestring, pathname, 'exec')
 
     # try to cache the compiled code
     try:

Modified: python/branches/py3k-importlib/Lib/inspect.py
==============================================================================
--- python/branches/py3k-importlib/Lib/inspect.py	(original)
+++ python/branches/py3k-importlib/Lib/inspect.py	Thu Mar 27 00:48:05 2008
@@ -7,8 +7,9 @@
 
 Here are some of the useful functions provided by this module:
 
-    ismodule(), isclass(), ismethod(), isfunction(), istraceback(),
-        isframe(), iscode(), isbuiltin(), isroutine() - check object types
+    ismodule(), isclass(), ismethod(), isfunction(), isgeneratorfunction(),
+        isgenerator(), istraceback(), isframe(), iscode(), isbuiltin(),
+        isroutine() - check object types
     getmembers() - get members of an object that satisfy a given condition
 
     getfile(), getsourcefile(), getsource() - find an object's source code
@@ -29,8 +30,24 @@
 __author__ = 'Ka-Ping Yee <ping at lfw.org>'
 __date__ = '1 Jan 2001'
 
-import sys, os, types, re, dis, imp, tokenize, linecache
+import sys
+import os
+import types
+import string
+import re
+import dis
+import imp
+import tokenize
+import linecache
+from abc import ABCMeta
 from operator import attrgetter
+from collections import namedtuple
+# These constants are from Include/code.h.
+CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS = 0x1, 0x2, 0x4, 0x8
+CO_NESTED, CO_GENERATOR, CO_NOFREE = 0x10, 0x20, 0x40
+
+# See Include/object.h
+TPFLAGS_IS_ABSTRACT = 1 << 20
 
 # ----------------------------------------------------------- type-checking
 def ismodule(object):
@@ -55,9 +72,8 @@
     Instance method objects provide these attributes:
         __doc__         documentation string
         __name__        name with which this method was defined
-        im_class        class object in which this method belongs
-        im_func         function object containing implementation of method
-        im_self         instance to which this method is bound, or None"""
+        __func__        function object containing implementation of method
+        __self__        instance to which this method is bound"""
     return isinstance(object, types.MethodType)
 
 def ismethoddescriptor(object):
@@ -73,7 +89,7 @@
     Methods implemented via descriptors that also pass one of the other
     tests return false from the ismethoddescriptor() test, simply because
     the other tests promise more -- you can, e.g., count on having the
-    im_func attribute (etc) when an object passes ismethod()."""
+    __func__ attribute (etc) when an object passes ismethod()."""
     return (hasattr(object, "__get__")
             and not hasattr(object, "__set__") # else it's a data descriptor
             and not ismethod(object)           # mutual exclusion
@@ -137,6 +153,33 @@
         __kwdefaults__  dict of keyword only parameters with defaults"""
     return isinstance(object, types.FunctionType)
 
+def isgeneratorfunction(object):
+    """Return true if the object is a user-defined generator function.
+
+    Generator function objects provides same attributes as functions.
+
+    See isfunction.__doc__ for attributes listing."""
+    if (isfunction(object) or ismethod(object)) and \
+        object.__code__.co_flags & CO_GENERATOR:
+        return True
+
+def isgenerator(object):
+    """Return true if the object is a generator.
+
+    Generator objects provide these attributes:
+        __iter__        defined to support interation over container
+        close           raises a new GeneratorExit exception inside the
+                        generator to terminate the iteration
+        gi_code         code object
+        gi_frame        frame object or possibly None once the generator has
+                        been exhausted
+        gi_running      set to 1 when generator is executing, 0 otherwise
+        next            return the next item from the container
+        send            resumes the generator and "sends" a value that becomes
+                        the result of the current yield-expression
+        throw           used to raise an exception inside the generator"""
+    return isinstance(object, types.GeneratorType)
+
 def istraceback(object):
     """Return true if the object is a traceback.
 
@@ -198,6 +241,14 @@
             or ismethod(object)
             or ismethoddescriptor(object))
 
+def isgenerator(object):
+    """Return true if the object is a generator object."""
+    return isinstance(object, types.GeneratorType)
+
+def isabstract(object):
+    """Return true if the object is an abstract base class (ABC)."""
+    return object.__flags__ & TPFLAGS_IS_ABSTRACT
+
 def getmembers(object, predicate=None):
     """Return all members of an object as (name, value) pairs sorted by name.
     Optionally, only return members that satisfy a given predicate."""
@@ -209,6 +260,8 @@
     results.sort()
     return results
 
+Attribute = namedtuple('Attribute', 'name kind defining_class object')
+
 def classify_class_attrs(cls):
     """Return list of attribute-descriptor tuples.
 
@@ -269,13 +322,13 @@
             kind = "class method"
         elif isinstance(obj, property):
             kind = "property"
-        elif (ismethod(obj_via_getattr) or
+        elif (isfunction(obj_via_getattr) or
               ismethoddescriptor(obj_via_getattr)):
             kind = "method"
         else:
             kind = "data"
 
-        result.append((name, kind, homecls, obj))
+        result.append(Attribute(name, kind, homecls, obj))
 
     return result
 
@@ -313,7 +366,7 @@
         doc = object.__doc__
     except AttributeError:
         return None
-    if not isinstance(doc, basestring):
+    if not isinstance(doc, str):
         return None
     try:
         lines = doc.expandtabs().split('\n')
@@ -321,7 +374,7 @@
         return None
     else:
         # Find minimum indentation of any non-blank lines after first line.
-        margin = sys.maxint
+        margin = sys.maxsize
         for line in lines[1:]:
             content = len(line.lstrip())
             if content:
@@ -330,7 +383,7 @@
         # Remove indentation.
         if lines:
             lines[0] = lines[0].lstrip()
-        if margin < sys.maxint:
+        if margin < sys.maxsize:
             for i in range(1, len(lines)): lines[i] = lines[i][margin:]
         # Remove any trailing or leading blank lines.
         while lines and not lines[-1]:
@@ -351,7 +404,7 @@
             return object.__file__
         raise TypeError('arg is a built-in class')
     if ismethod(object):
-        object = object.im_func
+        object = object.__func__
     if isfunction(object):
         object = object.__code__
     if istraceback(object):
@@ -363,6 +416,8 @@
     raise TypeError('arg is not a module, class, method, '
                     'function, traceback, frame, or code object')
 
+ModuleInfo = namedtuple('ModuleInfo', 'name suffix mode module_type')
+
 def getmoduleinfo(path):
     """Get the module name, suffix, mode, and module type for a given file."""
     filename = os.path.basename(path)
@@ -371,7 +426,7 @@
     suffixes.sort() # try longest suffixes first, in case they overlap
     for neglen, suffix, mode, mtype in suffixes:
         if filename[neglen:] == suffix:
-            return filename[:neglen], suffix, mode, mtype
+            return ModuleInfo(filename[:neglen], suffix, mode, mtype)
 
 def getmodulename(path):
     """Return the module name for a given file, or None."""
@@ -445,7 +500,7 @@
         if mainobject is object:
             return main
     # Check builtins
-    builtin = sys.modules['__builtin__']
+    builtin = sys.modules['builtins']
     if hasattr(builtin, object.__name__):
         builtinobject = getattr(builtin, object.__name__)
         if builtinobject is object:
@@ -494,7 +549,7 @@
             raise IOError('could not find class definition')
 
     if ismethod(object):
-        object = object.im_func
+        object = object.__func__
     if isfunction(object):
         object = object.__code__
     if istraceback(object):
@@ -602,7 +657,9 @@
     """Extract the block of code at the top of the given list of lines."""
     blockfinder = BlockFinder()
     try:
-        tokenize.tokenize(iter(lines).__next__, blockfinder.tokeneater)
+        tokens = tokenize.generate_tokens(iter(lines).__next__)
+        for _token in tokens:
+            blockfinder.tokeneater(*_token)
     except (EndOfBlock, IndentationError):
         pass
     return lines[:blockfinder.last]
@@ -666,8 +723,7 @@
     return walktree(roots, children, None)
 
 # ------------------------------------------------ argument list extraction
-# These constants are from Python's compile.h.
-CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS = 1, 2, 4, 8
+Arguments = namedtuple('Arguments', 'args, varargs, varkw')
 
 def getargs(co):
     """Get information about the arguments accepted by a code object.
@@ -677,7 +733,7 @@
     lists. Keyword-only arguments are appended. 'varargs' and 'varkw'
     are the names of the * and ** arguments or None."""
     args, varargs, kwonlyargs, varkw = _getfullargs(co)
-    return args + kwonlyargs, varargs, varkw
+    return Arguments(args + kwonlyargs, varargs, varkw)
 
 def _getfullargs(co):
     """Get information about the arguments accepted by a code object.
@@ -707,6 +763,9 @@
         varkw = co.co_varnames[nargs]
     return args, varargs, kwonlyargs, varkw
 
+
+ArgSpec = namedtuple('ArgSpec', 'args varargs keywords defaults')
+
 def getargspec(func):
     """Get the names and default values of a function's arguments.
 
@@ -726,7 +785,10 @@
     if kwonlyargs or ann:
         raise ValueError("Function has keyword-only arguments or annotations"
                          ", use getfullargspec() API which can support them")
-    return (args, varargs, varkw, defaults)
+    return ArgSpec(args, varargs, varkw, defaults)
+
+FullArgSpec = namedtuple('FullArgSpec',
+    'args, varargs, varkw, defaults, kwonlyargs, kwdefaults, annotations')
 
 def getfullargspec(func):
     """Get the names and default values of a function's arguments.
@@ -744,13 +806,15 @@
     """
 
     if ismethod(func):
-        func = func.im_func
+        func = func.__func__
     if not isfunction(func):
         raise TypeError('arg is not a Python function')
     args, varargs, kwonlyargs, varkw = _getfullargs(func.__code__)
-    return (args, varargs, varkw, func.__defaults__,
+    return FullArgSpec(args, varargs, varkw, func.__defaults__,
             kwonlyargs, func.__kwdefaults__, func.__annotations__)
 
+ArgInfo = namedtuple('ArgInfo', 'args varargs keywords locals')
+
 def getargvalues(frame):
     """Get information about arguments passed into a particular frame.
 
@@ -776,7 +840,7 @@
 
 def formatannotation(annotation, base_module=None):
     if isinstance(annotation, type):
-        if annotation.__module__ in ('__builtin__', base_module):
+        if annotation.__module__ in ('builtins', base_module):
             return annotation.__name__
         return annotation.__module__+'.'+annotation.__name__
     return repr(annotation)
@@ -860,6 +924,9 @@
     return '(' + ', '.join(specs) + ')'
 
 # -------------------------------------------------- stack frame extraction
+
+Traceback = namedtuple('Traceback', 'filename lineno function code_context index')
+
 def getframeinfo(frame, context=1):
     """Get information about a frame or traceback object.
 
@@ -891,7 +958,7 @@
     else:
         lines = index = None
 
-    return (filename, lineno, frame.f_code.co_name, lines, index)
+    return Traceback(filename, lineno, frame.f_code.co_name, lines, index)
 
 def getlineno(frame):
     """Get the line number from a frame object, allowing for optimization."""

Modified: python/branches/py3k-importlib/Lib/io.py
==============================================================================
--- python/branches/py3k-importlib/Lib/io.py	(original)
+++ python/branches/py3k-importlib/Lib/io.py	Thu Mar 27 00:48:05 2008
@@ -49,8 +49,9 @@
         self.characters_written = characters_written
 
 
-def open(file, mode="r", buffering=None, encoding=None, newline=None):
-    """Replacement for the built-in open function.
+def open(file, mode="r", buffering=None, encoding=None, errors=None,
+         newline=None, closefd=True):
+    r"""Replacement for the built-in open function.
 
     Args:
       file: string giving the name of the file to be opened;
@@ -60,6 +61,7 @@
                  can be: 0 = unbuffered, 1 = line buffered,
                  larger = fully buffered.
       encoding: optional string giving the text encoding.
+      errors: optional string giving the encoding error handling.
       newline: optional newlines specifier; must be None, '', '\n', '\r'
                or '\r\n'; all other values are illegal.  It controls the
                handling of line endings.  It works as follows:
@@ -81,9 +83,12 @@
           other legal values, any `'\n'` characters written are
           translated to the given string.
 
+      closefd: optional argument to keep the underlying file descriptor
+               open when the file is closed.  It must not be false when
+               a filename is given.
+
     (*) If a file descriptor is given, it is closed when the returned
-    I/O object is closed.  If you don't want this to happen, use
-    os.dup() to create a duplicate file descriptor.
+    I/O object is closed, unless closefd=False is given.
 
     Mode strings characters:
       'r': open for reading (default)
@@ -95,7 +100,7 @@
       'U': universal newline mode (for backwards compatibility)
 
     Constraints:
-      - encoding must not be given when a binary mode is given
+      - encoding or errors must not be given when a binary mode is given
       - buffering must not be zero when a text mode is given
 
     Returns:
@@ -103,14 +108,16 @@
       binary stream, a buffered binary stream, or a buffered text
       stream, open for reading and/or writing.
     """
-    if not isinstance(file, (basestring, int)):
+    if not isinstance(file, (str, int)):
         raise TypeError("invalid file: %r" % file)
-    if not isinstance(mode, basestring):
+    if not isinstance(mode, str):
         raise TypeError("invalid mode: %r" % mode)
     if buffering is not None and not isinstance(buffering, int):
         raise TypeError("invalid buffering: %r" % buffering)
-    if encoding is not None and not isinstance(encoding, basestring):
+    if encoding is not None and not isinstance(encoding, str):
         raise TypeError("invalid encoding: %r" % encoding)
+    if errors is not None and not isinstance(errors, str):
+        raise TypeError("invalid errors: %r" % errors)
     modes = set(mode)
     if modes - set("arwb+tU") or len(mode) > len(modes):
         raise ValueError("invalid mode: %r" % mode)
@@ -132,17 +139,22 @@
         raise ValueError("must have exactly one of read/write/append mode")
     if binary and encoding is not None:
         raise ValueError("binary mode doesn't take an encoding argument")
+    if binary and errors is not None:
+        raise ValueError("binary mode doesn't take an errors argument")
     if binary and newline is not None:
         raise ValueError("binary mode doesn't take a newline argument")
     raw = FileIO(file,
                  (reading and "r" or "") +
                  (writing and "w" or "") +
                  (appending and "a" or "") +
-                 (updating and "+" or ""))
+                 (updating and "+" or ""),
+                 closefd)
     if buffering is None:
         buffering = -1
-    if buffering < 0 and raw.isatty():
-        buffering = 1
+    line_buffering = False
+    if buffering == 1 or buffering < 0 and raw.isatty():
+        buffering = -1
+        line_buffering = True
     if buffering < 0:
         buffering = DEFAULT_BUFFER_SIZE
         try:
@@ -172,11 +184,33 @@
         buffer.name = file
         buffer.mode = mode
         return buffer
-    text = TextIOWrapper(buffer, encoding, newline)
+    text = TextIOWrapper(buffer, encoding, errors, newline, line_buffering)
     text.name = file
     text.mode = mode
     return text
 
+class _DocDescriptor:
+    """Helper for builtins.open.__doc__
+    """
+    def __get__(self, obj, typ):
+        return (
+            "open(file, mode='r', buffering=None, encoding=None, "
+                 "errors=None, newline=None, closefd=True)\n\n" +
+            open.__doc__)
+
+class OpenWrapper:
+    """Wrapper for builtins.open
+
+    Trick so that open won't become a bound method when stored
+    as a class variable (as dumbdbm does).
+
+    See initstdio() in Python/pythonrun.c.
+    """
+    __doc__ = _DocDescriptor()
+
+    def __new__(cls, *args, **kwargs):
+        return open(*args, **kwargs)
+
 
 class UnsupportedOperation(ValueError, IOError):
     pass
@@ -331,6 +365,7 @@
 
     def __enter__(self) -> "IOBase":  # That's a forward reference
         """Context management protocol.  Returns self."""
+        self._checkClosed()
         return self
 
     def __exit__(self, *args) -> None:
@@ -362,7 +397,7 @@
         """For backwards compatibility, a (slowish) readline()."""
         if hasattr(self, "peek"):
             def nreadahead():
-                readahead = self.peek(1, unsafe=True)
+                readahead = self.peek(1)
                 if not readahead:
                     return 1
                 n = (readahead.find(b"\n") + 1) or len(readahead)
@@ -374,7 +409,7 @@
                 return 1
         if limit is None:
             limit = -1
-        res = bytes()
+        res = bytearray()
         while limit < 0 or len(res) < limit:
             b = self.read(nreadahead())
             if not b:
@@ -382,7 +417,7 @@
             res += b
             if res.endswith(b"\n"):
                 break
-        return res
+        return bytes(res)
 
     def __iter__(self):
         self._checkClosed()
@@ -437,20 +472,20 @@
             n = -1
         if n < 0:
             return self.readall()
-        b = bytes(n.__index__())
+        b = bytearray(n.__index__())
         n = self.readinto(b)
         del b[n:]
-        return b
+        return bytes(b)
 
     def readall(self):
         """readall() -> bytes.  Read until EOF, using multiple read() call."""
-        res = bytes()
+        res = bytearray()
         while True:
             data = self.read(DEFAULT_BUFFER_SIZE)
             if not data:
                 break
             res += data
-        return res
+        return bytes(res)
 
     def readinto(self, b: bytes) -> int:
         """readinto(b: bytes) -> int.  Read up to len(b) bytes into b.
@@ -585,6 +620,11 @@
         return self.raw.tell()
 
     def truncate(self, pos=None):
+        # Flush the stream.  We're mixing buffered I/O with lower-level I/O,
+        # and a flush may be necessary to synch both views of the current
+        # file state.
+        self.flush()
+
         if pos is None:
             pos = self.tell()
         return self.raw.truncate(pos)
@@ -633,14 +673,14 @@
     # XXX More docs
 
     def __init__(self, initial_bytes=None):
-        buffer = b""
+        buf = bytearray()
         if initial_bytes is not None:
-            buffer += initial_bytes
-        self._buffer = buffer
+            buf += initial_bytes
+        self._buffer = buf
         self._pos = 0
 
     def getvalue(self):
-        return self._buffer
+        return bytes(self._buffer)
 
     def read(self, n=None):
         if n is None:
@@ -650,7 +690,7 @@
         newpos = min(len(self._buffer), self._pos + n)
         b = self._buffer[self._pos : newpos]
         self._pos = newpos
-        return b
+        return bytes(b)
 
     def read1(self, n):
         return self.read(n)
@@ -672,6 +712,10 @@
         return n
 
     def seek(self, pos, whence=0):
+        try:
+            pos = pos.__index__()
+        except AttributeError as err:
+            raise TypeError("an integer is required") from err
         if whence == 0:
             self._pos = max(0, pos)
         elif whence == 1:
@@ -741,14 +785,12 @@
             out = nodata_val
         return out
 
-    def peek(self, n=0, *, unsafe=False):
+    def peek(self, n=0):
         """Returns buffered bytes without advancing the position.
 
         The argument indicates a desired minimal number of bytes; we
         do at most one raw read to satisfy it.  We never return more
         than self.buffer_size.
-
-        Unless unsafe=True is passed, we return a copy.
         """
         want = min(n, self.buffer_size)
         have = len(self._read_buf)
@@ -757,21 +799,17 @@
             current = self.raw.read(to_read)
             if current:
                 self._read_buf += current
-        result = self._read_buf
-        if unsafe:
-            result = result[:]
-        return result
+        return self._read_buf
 
     def read1(self, n):
-        """Reads up to n bytes.
+        """Reads up to n bytes, with at most one read() system call.
 
-        Returns up to n bytes.  If at least one byte is buffered,
-        we only return buffered bytes.  Otherwise, we do one
-        raw read.
+        Returns up to n bytes.  If at least one byte is buffered, we
+        only return buffered bytes.  Otherwise, we do one raw read.
         """
         if n <= 0:
             return b""
-        self.peek(1, unsafe=True)
+        self.peek(1)
         return self.read(min(n, len(self._read_buf)))
 
     def tell(self):
@@ -797,7 +835,7 @@
         self.max_buffer_size = (2*buffer_size
                                 if max_buffer_size is None
                                 else max_buffer_size)
-        self._write_buf = b""
+        self._write_buf = bytearray()
 
     def write(self, b):
         if self.closed:
@@ -886,8 +924,8 @@
     def write(self, b):
         return self.writer.write(b)
 
-    def peek(self, n=0, *, unsafe=False):
-        return self.reader.peek(n, unsafe=unsafe)
+    def peek(self, n=0):
+        return self.reader.peek(n)
 
     def read1(self, n):
         return self.reader.read1(n)
@@ -947,9 +985,9 @@
         self.flush()
         return BufferedReader.readinto(self, b)
 
-    def peek(self, n=0, *, unsafe=False):
+    def peek(self, n=0):
         self.flush()
-        return BufferedReader.peek(self, n, unsafe=unsafe)
+        return BufferedReader.peek(self, n)
 
     def read1(self, n):
         self.flush()
@@ -1015,6 +1053,85 @@
         return None
 
 
+class IncrementalNewlineDecoder(codecs.IncrementalDecoder):
+    """Codec used when reading a file in universal newlines mode.
+    It wraps another incremental decoder, translating \\r\\n and \\r into \\n.
+    It also records the types of newlines encountered.
+    When used with translate=False, it ensures that the newline sequence is
+    returned in one piece.
+    """
+    def __init__(self, decoder, translate, errors='strict'):
+        codecs.IncrementalDecoder.__init__(self, errors=errors)
+        self.buffer = b''
+        self.translate = translate
+        self.decoder = decoder
+        self.seennl = 0
+
+    def decode(self, input, final=False):
+        # decode input (with the eventual \r from a previous pass)
+        if self.buffer:
+            input = self.buffer + input
+
+        output = self.decoder.decode(input, final=final)
+
+        # retain last \r even when not translating data:
+        # then readline() is sure to get \r\n in one pass
+        if output.endswith("\r") and not final:
+            output = output[:-1]
+            self.buffer = b'\r'
+        else:
+            self.buffer = b''
+
+        # Record which newlines are read
+        crlf = output.count('\r\n')
+        cr = output.count('\r') - crlf
+        lf = output.count('\n') - crlf
+        self.seennl |= (lf and self._LF) | (cr and self._CR) \
+                    | (crlf and self._CRLF)
+
+        if self.translate:
+            if crlf:
+                output = output.replace("\r\n", "\n")
+            if cr:
+                output = output.replace("\r", "\n")
+
+        return output
+
+    def getstate(self):
+        buf, flag = self.decoder.getstate()
+        return buf + self.buffer, flag
+
+    def setstate(self, state):
+        buf, flag = state
+        if buf.endswith(b'\r'):
+            self.buffer = b'\r'
+            buf = buf[:-1]
+        else:
+            self.buffer = b''
+        self.decoder.setstate((buf, flag))
+
+    def reset(self):
+        self.seennl = 0
+        self.buffer = b''
+        self.decoder.reset()
+
+    _LF = 1
+    _CR = 2
+    _CRLF = 4
+
+    @property
+    def newlines(self):
+        return (None,
+                "\n",
+                "\r",
+                ("\r", "\n"),
+                "\r\n",
+                ("\n", "\r\n"),
+                ("\r", "\r\n"),
+                ("\r", "\n", "\r\n")
+               )[self.seennl]
+
+
 class TextIOWrapper(TextIOBase):
 
     """Buffered text stream.
@@ -1024,7 +1141,8 @@
 
     _CHUNK_SIZE = 128
 
-    def __init__(self, buffer, encoding=None, newline=None):
+    def __init__(self, buffer, encoding=None, errors=None, newline=None,
+                 line_buffering=False):
         if newline not in (None, "", "\n", "\r", "\r\n"):
             raise ValueError("illegal newline value: %r" % (newline,))
         if encoding is None:
@@ -1041,31 +1159,56 @@
                 else:
                     encoding = locale.getpreferredencoding()
 
+        if not isinstance(encoding, str):
+            raise ValueError("invalid encoding: %r" % encoding)
+
+        if errors is None:
+            errors = "strict"
+        else:
+            if not isinstance(errors, str):
+                raise ValueError("invalid errors: %r" % errors)
+
         self.buffer = buffer
+        self._line_buffering = line_buffering
         self._encoding = encoding
+        self._errors = errors
         self._readuniversal = not newline
         self._readtranslate = newline is None
         self._readnl = newline
         self._writetranslate = newline != ''
         self._writenl = newline or os.linesep
-        self._seennl = 0
+        self._encoder = None
         self._decoder = None
-        self._pending = ""
-        self._snapshot = None
+        self._decoded_chars = ''  # buffer for text returned from decoder
+        self._decoded_chars_used = 0  # offset into _decoded_chars for read()
+        self._snapshot = None  # info for reconstructing decoder state
         self._seekable = self._telling = self.buffer.seekable()
 
+    # self._snapshot is either None, or a tuple (dec_flags, next_input)
+    # where dec_flags is the second (integer) item of the decoder state
+    # and next_input is the chunk of input bytes that comes next after the
+    # snapshot point.  We use this to reconstruct decoder states in tell().
+
+    # Naming convention:
+    #   - "bytes_..." for integer variables that count input bytes
+    #   - "chars_..." for integer variables that count decoded characters
+
+    def __repr__(self):
+        return '<TIOW %x>' % id(self)
+
     @property
     def encoding(self):
         return self._encoding
 
-    # A word about _snapshot.  This attribute is either None, or a
-    # tuple (decoder_state, readahead, pending) where decoder_state is
-    # the second (integer) item of the decoder state, readahead is the
-    # chunk of bytes that was read, and pending is the characters that
-    # were rendered by the decoder after feeding it those bytes.  We
-    # use this to reconstruct intermediate decoder states in tell().
+    @property
+    def errors(self):
+        return self._errors
 
-    def _seekable(self):
+    @property
+    def line_buffering(self):
+        return self._line_buffering
+
+    def seekable(self):
         return self._seekable
 
     def flush(self):
@@ -1092,147 +1235,250 @@
     def write(self, s: str):
         if self.closed:
             raise ValueError("write to closed file")
-        if not isinstance(s, basestring):
+        if not isinstance(s, str):
             raise TypeError("can't write %s to text stream" %
                             s.__class__.__name__)
-        haslf = "\n" in s
+        length = len(s)
+        haslf = (self._writetranslate or self._line_buffering) and "\n" in s
         if haslf and self._writetranslate and self._writenl != "\n":
             s = s.replace("\n", self._writenl)
+        encoder = self._encoder or self._get_encoder()
         # XXX What if we were just reading?
-        b = s.encode(self._encoding)
+        b = encoder.encode(s)
         self.buffer.write(b)
-        if haslf and self.isatty():
+        if self._line_buffering and (haslf or "\r" in s):
             self.flush()
-        self._snapshot = self._decoder = None
-        return len(s)
+        self._snapshot = None
+        if self._decoder:
+            self._decoder.reset()
+        return length
+
+    def _get_encoder(self):
+        make_encoder = codecs.getincrementalencoder(self._encoding)
+        self._encoder = make_encoder(self._errors)
+        return self._encoder
 
     def _get_decoder(self):
         make_decoder = codecs.getincrementaldecoder(self._encoding)
-        if make_decoder is None:
-            raise IOError("Can't find an incremental decoder for encoding %s" %
-                          self._encoding)
-        decoder = self._decoder = make_decoder()  # XXX: errors
+        decoder = make_decoder(self._errors)
+        if self._readuniversal:
+            decoder = IncrementalNewlineDecoder(decoder, self._readtranslate)
+        self._decoder = decoder
         return decoder
 
+    # The following three methods implement an ADT for _decoded_chars.
+    # Text returned from the decoder is buffered here until the client
+    # requests it by calling our read() or readline() method.
+    def _set_decoded_chars(self, chars):
+        """Set the _decoded_chars buffer."""
+        self._decoded_chars = chars
+        self._decoded_chars_used = 0
+
+    def _get_decoded_chars(self, n=None):
+        """Advance into the _decoded_chars buffer."""
+        offset = self._decoded_chars_used
+        if n is None:
+            chars = self._decoded_chars[offset:]
+        else:
+            chars = self._decoded_chars[offset:offset + n]
+        self._decoded_chars_used += len(chars)
+        return chars
+
+    def _rewind_decoded_chars(self, n):
+        """Rewind the _decoded_chars buffer."""
+        if self._decoded_chars_used < n:
+            raise AssertionError("rewind decoded_chars out of bounds")
+        self._decoded_chars_used -= n
+
     def _read_chunk(self):
+        """
+        Read and decode the next chunk of data from the BufferedReader.
+
+        The return value is True unless EOF was reached.  The decoded string
+        is placed in self._decoded_chars (replacing its previous value).
+        The entire input chunk is sent to the decoder, though some of it
+        may remain buffered in the decoder, yet to be converted.
+        """
+
         if self._decoder is None:
             raise ValueError("no decoder")
-        if not self._telling:
-            readahead = self.buffer.read1(self._CHUNK_SIZE)
-            pending = self._decoder.decode(readahead, not readahead)
-            return readahead, pending
-        decoder_buffer, decoder_state = self._decoder.getstate()
-        readahead = self.buffer.read1(self._CHUNK_SIZE)
-        pending = self._decoder.decode(readahead, not readahead)
-        self._snapshot = (decoder_state, decoder_buffer + readahead, pending)
-        return readahead, pending
-
-    def _encode_decoder_state(self, ds, pos):
-        x = 0
-        for i in bytes(ds):
-            x = x<<8 | i
-        return (x<<64) | pos
-
-    def _decode_decoder_state(self, pos):
-        x, pos = divmod(pos, 1<<64)
-        if not x:
-            return None, pos
-        b = b""
-        while x:
-            b.append(x&0xff)
-            x >>= 8
-        return str(b[::-1]), pos
+
+        if self._telling:
+            # To prepare for tell(), we need to snapshot a point in the
+            # file where the decoder's input buffer is empty.
+
+            dec_buffer, dec_flags = self._decoder.getstate()
+            # Given this, we know there was a valid snapshot point
+            # len(dec_buffer) bytes ago with decoder state (b'', dec_flags).
+
+        # Read a chunk, decode it, and put the result in self._decoded_chars.
+        input_chunk = self.buffer.read1(self._CHUNK_SIZE)
+        eof = not input_chunk
+        self._set_decoded_chars(self._decoder.decode(input_chunk, eof))
+
+        if self._telling:
+            # At the snapshot point, len(dec_buffer) bytes before the read,
+            # the next input to be decoded is dec_buffer + input_chunk.
+            self._snapshot = (dec_flags, dec_buffer + input_chunk)
+
+        return not eof
+
+    def _pack_cookie(self, position, dec_flags=0,
+                           bytes_to_feed=0, need_eof=0, chars_to_skip=0):
+        # The meaning of a tell() cookie is: seek to position, set the
+        # decoder flags to dec_flags, read bytes_to_feed bytes, feed them
+        # into the decoder with need_eof as the EOF flag, then skip
+        # chars_to_skip characters of the decoded result.  For most simple
+        # decoders, tell() will often just give a byte offset in the file.
+        return (position | (dec_flags<<64) | (bytes_to_feed<<128) |
+               (chars_to_skip<<192) | bool(need_eof)<<256)
+
+    def _unpack_cookie(self, bigint):
+        rest, position = divmod(bigint, 1<<64)
+        rest, dec_flags = divmod(rest, 1<<64)
+        rest, bytes_to_feed = divmod(rest, 1<<64)
+        need_eof, chars_to_skip = divmod(rest, 1<<64)
+        return position, dec_flags, bytes_to_feed, need_eof, chars_to_skip
 
     def tell(self):
         if not self._seekable:
-            raise IOError("Underlying stream is not seekable")
+            raise IOError("underlying stream is not seekable")
         if not self._telling:
-            raise IOError("Telling position disabled by next() call")
+            raise IOError("telling position disabled by next() call")
         self.flush()
         position = self.buffer.tell()
         decoder = self._decoder
         if decoder is None or self._snapshot is None:
-            if self._pending:
-                raise ValueError("pending data")
+            if self._decoded_chars:
+                # This should never happen.
+                raise AssertionError("pending decoded text")
             return position
-        decoder_state, readahead, pending = self._snapshot
-        position -= len(readahead)
-        needed = len(pending) - len(self._pending)
-        if not needed:
-            return self._encode_decoder_state(decoder_state, position)
+
+        # Skip backward to the snapshot point (see _read_chunk).
+        dec_flags, next_input = self._snapshot
+        position -= len(next_input)
+
+        # How many decoded characters have been used up since the snapshot?
+        chars_to_skip = self._decoded_chars_used
+        if chars_to_skip == 0:
+            # We haven't moved from the snapshot point.
+            return self._pack_cookie(position, dec_flags)
+
+        # Starting from the snapshot position, we will walk the decoder
+        # forward until it gives us enough decoded characters.
         saved_state = decoder.getstate()
         try:
-            decoder.setstate((b"", decoder_state))
-            n = 0
-            bb = bytes(1)
-            for i, bb[0] in enumerate(readahead):
-                n += len(decoder.decode(bb))
-                if n >= needed:
-                    decoder_buffer, decoder_state = decoder.getstate()
-                    return self._encode_decoder_state(
-                        decoder_state,
-                        position + (i+1) - len(decoder_buffer))
-            raise IOError("Can't reconstruct logical file position")
+            # Note our initial start point.
+            decoder.setstate((b'', dec_flags))
+            start_pos = position
+            start_flags, bytes_fed, chars_decoded = dec_flags, 0, 0
+            need_eof = 0
+
+            # Feed the decoder one byte at a time.  As we go, note the
+            # nearest "safe start point" before the current location
+            # (a point where the decoder has nothing buffered, so seek()
+            # can safely start from there and advance to this location).
+            next_byte = bytearray(1)
+            for next_byte[0] in next_input:
+                bytes_fed += 1
+                chars_decoded += len(decoder.decode(next_byte))
+                dec_buffer, dec_flags = decoder.getstate()
+                if not dec_buffer and chars_decoded <= chars_to_skip:
+                    # Decoder buffer is empty, so this is a safe start point.
+                    start_pos += bytes_fed
+                    chars_to_skip -= chars_decoded
+                    start_flags, bytes_fed, chars_decoded = dec_flags, 0, 0
+                if chars_decoded >= chars_to_skip:
+                    break
+            else:
+                # We didn't get enough decoded data; signal EOF to get more.
+                chars_decoded += len(decoder.decode(b'', final=True))
+                need_eof = 1
+                if chars_decoded < chars_to_skip:
+                    raise IOError("can't reconstruct logical file position")
+
+            # The returned cookie corresponds to the last safe start point.
+            return self._pack_cookie(
+                start_pos, start_flags, bytes_fed, need_eof, chars_to_skip)
         finally:
             decoder.setstate(saved_state)
 
-    def seek(self, pos, whence=0):
+    def seek(self, cookie, whence=0):
         if not self._seekable:
-            raise IOError("Underlying stream is not seekable")
-        if whence == 1:
-            if pos != 0:
-                raise IOError("Can't do nonzero cur-relative seeks")
-            pos = self.tell()
+            raise IOError("underlying stream is not seekable")
+        if whence == 1: # seek relative to current position
+            if cookie != 0:
+                raise IOError("can't do nonzero cur-relative seeks")
+            # Seeking to the current position should attempt to
+            # sync the underlying buffer with the current position.
             whence = 0
-        if whence == 2:
-            if pos != 0:
-                raise IOError("Can't do nonzero end-relative seeks")
+            cookie = self.tell()
+        if whence == 2: # seek relative to end of file
+            if cookie != 0:
+                raise IOError("can't do nonzero end-relative seeks")
             self.flush()
-            pos = self.buffer.seek(0, 2)
+            position = self.buffer.seek(0, 2)
+            self._set_decoded_chars('')
             self._snapshot = None
-            self._pending = ""
-            self._decoder = None
-            return pos
+            if self._decoder:
+                self._decoder.reset()
+            return position
         if whence != 0:
-            raise ValueError("Invalid whence (%r, should be 0, 1 or 2)" %
+            raise ValueError("invalid whence (%r, should be 0, 1 or 2)" %
                              (whence,))
-        if pos < 0:
-            raise ValueError("Negative seek position %r" % (pos,))
+        if cookie < 0:
+            raise ValueError("negative seek position %r" % (cookie,))
         self.flush()
-        orig_pos = pos
-        ds, pos = self._decode_decoder_state(pos)
-        if not ds:
-            self.buffer.seek(pos)
-            self._snapshot = None
-            self._pending = ""
-            self._decoder = None
-            return pos
-        decoder = self._decoder or self._get_decoder()
-        decoder.set_state(("", ds))
-        self.buffer.seek(pos)
-        self._snapshot = (ds, b"", "")
-        self._pending = ""
-        self._decoder = decoder
-        return orig_pos
+
+        # The strategy of seek() is to go back to the safe start point
+        # and replay the effect of read(chars_to_skip) from there.
+        start_pos, dec_flags, bytes_to_feed, need_eof, chars_to_skip = \
+            self._unpack_cookie(cookie)
+
+        # Seek back to the safe start point.
+        self.buffer.seek(start_pos)
+        self._set_decoded_chars('')
+        self._snapshot = None
+
+        # Restore the decoder to its state from the safe start point.
+        if self._decoder or dec_flags or chars_to_skip:
+            self._decoder = self._decoder or self._get_decoder()
+            self._decoder.setstate((b'', dec_flags))
+            self._snapshot = (dec_flags, b'')
+
+        if chars_to_skip:
+            # Just like _read_chunk, feed the decoder and save a snapshot.
+            input_chunk = self.buffer.read(bytes_to_feed)
+            self._set_decoded_chars(
+                self._decoder.decode(input_chunk, need_eof))
+            self._snapshot = (dec_flags, input_chunk)
+
+            # Skip chars_to_skip of the decoded characters.
+            if len(self._decoded_chars) < chars_to_skip:
+                raise IOError("can't restore logical file position")
+            self._decoded_chars_used = chars_to_skip
+
+        return cookie
 
     def read(self, n=None):
         if n is None:
             n = -1
         decoder = self._decoder or self._get_decoder()
-        res = self._pending
         if n < 0:
-            res += decoder.decode(self.buffer.read(), True)
-            self._pending = ""
+            # Read everything.
+            result = (self._get_decoded_chars() +
+                      decoder.decode(self.buffer.read(), final=True))
+            self._set_decoded_chars('')
             self._snapshot = None
-            return self._replacenl(res)
+            return result
         else:
-            while len(res) < n:
-                readahead, pending = self._read_chunk()
-                res += pending
-                if not readahead:
-                    break
-            self._pending = res[n:]
-            return self._replacenl(res[:n])
+            # Keep reading chunks until we have n characters to return.
+            eof = False
+            result = self._get_decoded_chars(n)
+            while len(result) < n and not eof:
+                eof = not self._read_chunk()
+                result += self._get_decoded_chars(n - len(result))
+            return result
 
     def __next__(self):
         self._telling = False
@@ -1244,161 +1490,108 @@
         return line
 
     def readline(self, limit=None):
-        if limit is not None:
-            # XXX Hack to support limit argument, for backwards compatibility
-            line = self.readline()
-            if len(line) <= limit:
-                return line
-            line, self._pending = line[:limit], line[limit:] + self._pending
-            return line
+        if limit is None:
+            limit = -1
+
+        # Grab all the decoded text (we will rewind any extra bits later).
+        line = self._get_decoded_chars()
 
-        line = self._pending
         start = 0
-        cr_eof = False
         decoder = self._decoder or self._get_decoder()
 
         pos = endpos = None
-        ending = None
         while True:
-            if self._readuniversal:
+            if self._readtranslate:
+                # Newlines are already translated, only search for \n
+                pos = line.find('\n', start)
+                if pos >= 0:
+                    endpos = pos + 1
+                    break
+                else:
+                    start = len(line)
+
+            elif self._readuniversal:
                 # Universal newline search. Find any of \r, \r\n, \n
+                # The decoder ensures that \r\n are not split in two pieces
 
                 # In C we'd look for these in parallel of course.
                 nlpos = line.find("\n", start)
                 crpos = line.find("\r", start)
                 if crpos == -1:
                     if nlpos == -1:
+                        # Nothing found
                         start = len(line)
                     else:
                         # Found \n
-                        pos = nlpos
-                        endpos = pos + 1
-                        ending = self._LF
+                        endpos = nlpos + 1
                         break
                 elif nlpos == -1:
-                    if crpos == len(line) - 1:
-                        # Found \r at end of buffer, must keep reading
-                        start = crpos
-                        cr_eof = True
-                    else:
-                        # Found lone \r
-                        ending = self._CR
-                        pos = crpos
-                        endpos = pos + 1
-                        break
+                    # Found lone \r
+                    endpos = crpos + 1
+                    break
                 elif nlpos < crpos:
                     # Found \n
-                    pos = nlpos
-                    endpos = pos + 1
-                    ending = self._LF
+                    endpos = nlpos + 1
                     break
                 elif nlpos == crpos + 1:
                     # Found \r\n
-                    ending = self._CRLF
-                    pos = crpos
-                    endpos = pos + 2
+                    endpos = crpos + 2
                     break
                 else:
                     # Found \r
-                    pos = crpos
-                    endpos = pos + 1
-                    ending = self._CR
+                    endpos = crpos + 1
                     break
             else:
                 # non-universal
                 pos = line.find(self._readnl)
                 if pos >= 0:
-                    endpos = pos+len(self._readnl)
-                    ending = self._nlflag(self._readnl)
+                    endpos = pos + len(self._readnl)
                     break
 
+            if limit >= 0 and len(line) >= limit:
+                endpos = limit  # reached length limit
+                break
+
             # No line ending seen yet - get more data
             more_line = ''
-            while True:
-                readahead, pending = self._read_chunk()
-                more_line = pending
-                if more_line or not readahead:
+            while self._read_chunk():
+                if self._decoded_chars:
                     break
-            if more_line:
-                line += more_line
+            if self._decoded_chars:
+                line += self._get_decoded_chars()
             else:
                 # end of file
-                self._pending = ''
+                self._set_decoded_chars('')
                 self._snapshot = None
-                if cr_eof:
-                    self._seennl |= self._CR
-                    return line[:-1] + '\n'
-                else:
-                    return line
+                return line
 
-        self._pending = line[endpos:]
-        if self._readtranslate:
-            self._seennl |= ending
-            if ending != self._LF:
-                return line[:pos] + '\n'
-            else:
-                return line[:endpos]
-        else:
-            return line[:endpos]
+        if limit >= 0 and endpos > limit:
+            endpos = limit  # don't exceed limit
 
-    def _replacenl(self, data):
-        # Replace newlines in data as needed and record that they have
-        # been seen.
-        if not self._readtranslate:
-            return data
-        if self._readuniversal:
-            crlf = data.count('\r\n')
-            cr = data.count('\r') - crlf
-            lf = data.count('\n') - crlf
-            self._seennl |= (lf and self._LF) | (cr and self._CR) \
-                         | (crlf and self._CRLF)
-            if crlf:
-                data = data.replace("\r\n", "\n")
-            if cr:
-                data = data.replace("\r", "\n")
-        elif self._readnl == '\n':
-            # Only need to detect if \n was seen.
-            if data.count('\n'):
-                self._seennl |= self._LF
-        else:
-            newdata = data.replace(self._readnl, '\n')
-            if newdata is not data:
-                self._seennl |= self._nlflag(self._readnl)
-            data = newdata
-        return data
+        # Rewind _decoded_chars to just after the line ending we found.
+        self._rewind_decoded_chars(len(line) - endpos)
+        return line[:endpos]
 
-    _LF = 1
-    _CR = 2
-    _CRLF = 4
     @property
     def newlines(self):
-        return (None,
-                "\n",
-                "\r",
-                ("\r", "\n"),
-                "\r\n",
-                ("\n", "\r\n"),
-                ("\r", "\r\n"),
-                ("\r", "\n", "\r\n")
-               )[self._seennl]
-
-    def _nlflag(self, nlstr):
-        return [None, "\n", "\r", None, "\r\n"].index(nlstr)
+        return self._decoder.newlines if self._decoder else None
 
 class StringIO(TextIOWrapper):
 
     # XXX This is really slow, but fully functional
 
-    def __init__(self, initial_value="", encoding="utf-8", newline="\n"):
+    def __init__(self, initial_value="", encoding="utf-8",
+                 errors="strict", newline="\n"):
         super(StringIO, self).__init__(BytesIO(),
                                        encoding=encoding,
+                                       errors=errors,
                                        newline=newline)
         if initial_value:
-            if not isinstance(initial_value, basestring):
+            if not isinstance(initial_value, str):
                 initial_value = str(initial_value)
             self.write(initial_value)
             self.seek(0)
 
     def getvalue(self):
         self.flush()
-        return self.buffer.getvalue().decode(self._encoding)
+        return self.buffer.getvalue().decode(self._encoding, self._errors)

Modified: python/branches/py3k-importlib/Lib/keyword.py
==============================================================================
--- python/branches/py3k-importlib/Lib/keyword.py	(original)
+++ python/branches/py3k-importlib/Lib/keyword.py	Thu Mar 27 00:48:05 2008
@@ -64,9 +64,7 @@
     fp = open(iptfile)
     strprog = re.compile('"([^"]+)"')
     lines = []
-    while 1:
-        line = fp.readline()
-        if not line: break
+    for line in fp:
         if '{1, "' in line:
             match = strprog.search(line)
             if match:

Modified: python/branches/py3k-importlib/Lib/lib-tk/FixTk.py
==============================================================================
--- python/branches/py3k-importlib/Lib/lib-tk/FixTk.py	(original)
+++ python/branches/py3k-importlib/Lib/lib-tk/FixTk.py	Thu Mar 27 00:48:05 2008
@@ -11,6 +11,10 @@
 # the real Tcl library will do.
 
 prefix = os.path.join(sys.prefix,"tcl")
+if not os.path.exists(prefix):
+    # devdir/../tcltk/lib
+    prefix = os.path.join(sys.prefix, os.path.pardir, "tcltk", "lib")
+    prefix = os.path.abspath(prefix)
 # if this does not exist, no further search is needed
 if os.path.exists(prefix):
     if "TCL_LIBRARY" not in os.environ:

Modified: python/branches/py3k-importlib/Lib/lib-tk/Tkinter.py
==============================================================================
--- python/branches/py3k-importlib/Lib/lib-tk/Tkinter.py	(original)
+++ python/branches/py3k-importlib/Lib/lib-tk/Tkinter.py	Thu Mar 27 00:48:05 2008
@@ -255,7 +255,7 @@
     def get(self):
         """Return value of variable as string."""
         value = self._tk.globalgetvar(self._name)
-        if isinstance(value, basestring):
+        if isinstance(value, str):
             return value
         return str(value)
 
@@ -1081,7 +1081,7 @@
         f = CallWrapper(func, subst, self).__call__
         name = repr(id(f))
         try:
-            func = func.im_func
+            func = func.__func__
         except AttributeError:
             pass
         try:
@@ -2977,7 +2977,7 @@
         return self.tk.call(self._w, "image", "names")
     def index(self, index):
         """Return the index in the form line.char for INDEX."""
-        return self.tk.call(self._w, 'index', index)
+        return str(self.tk.call(self._w, 'index', index))
     def insert(self, index, chars, *args):
         """Insert CHARS before the characters at INDEX. An additional
         tag can be given in ARGS. Additional CHARS and tags can follow in ARGS."""

Modified: python/branches/py3k-importlib/Lib/lib-tk/tkSimpleDialog.py
==============================================================================
--- python/branches/py3k-importlib/Lib/lib-tk/tkSimpleDialog.py	(original)
+++ python/branches/py3k-importlib/Lib/lib-tk/tkSimpleDialog.py	Thu Mar 27 00:48:05 2008
@@ -26,7 +26,6 @@
 '''
 
 from Tkinter import *
-import os
 
 class Dialog(Toplevel):
 

Modified: python/branches/py3k-importlib/Lib/locale.py
==============================================================================
--- python/branches/py3k-importlib/Lib/locale.py	(original)
+++ python/branches/py3k-importlib/Lib/locale.py	Thu Mar 27 00:48:05 2008
@@ -12,6 +12,7 @@
 """
 
 import sys, encodings, encodings.aliases
+from builtins import str as _builtin_str
 
 # Try importing the _locale module.
 #
@@ -25,6 +26,18 @@
            "normalize", "LC_CTYPE", "LC_COLLATE", "LC_TIME", "LC_MONETARY",
            "LC_NUMERIC", "LC_ALL", "CHAR_MAX"]
 
+def _strcoll(a,b):
+    """ strcoll(string,string) -> int.
+        Compares two strings according to the locale.
+    """
+    return cmp(a,b)
+
+def _strxfrm(s):
+    """ strxfrm(string) -> string.
+        Returns a string that behaves for cmp locale-aware.
+    """
+    return s
+
 try:
 
     from _locale import *
@@ -75,17 +88,11 @@
             raise Error('_locale emulation only supports "C" locale')
         return 'C'
 
-    def strcoll(a,b):
-        """ strcoll(string,string) -> int.
-            Compares two strings according to the locale.
-        """
-        return cmp(a,b)
-
-    def strxfrm(s):
-        """ strxfrm(string) -> string.
-            Returns a string that behaves for cmp locale-aware.
-        """
-        return s
+# These may or may not exist in _locale, so be sure to set them.
+if 'strxfrm' not in globals():
+    strxfrm = _strxfrm
+if 'strcoll' not in globals():
+    strcoll = _strcoll
 
 ### Number formatting APIs
 
@@ -472,7 +479,7 @@
         category may be given as one of the LC_* values.
 
     """
-    if locale and not isinstance(locale, basestring):
+    if locale and not isinstance(locale, _builtin_str):
         # convert to string
         locale = normalize(_build_localename(locale))
     return _setlocale(category, locale)
@@ -504,7 +511,11 @@
         def getpreferredencoding(do_setlocale = True):
             """Return the charset that the user is likely using,
             by looking at environment variables."""
-            return getdefaultlocale()[1]
+            res = getdefaultlocale()[1]
+            if res is None:
+                # LANG not set, default conservatively to ASCII
+                res = 'ascii'
+            return res
     else:
         def getpreferredencoding(do_setlocale = True):
             """Return the charset that the user is likely using,

Modified: python/branches/py3k-importlib/Lib/logging/__init__.py
==============================================================================
--- python/branches/py3k-importlib/Lib/logging/__init__.py	(original)
+++ python/branches/py3k-importlib/Lib/logging/__init__.py	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,4 @@
-# Copyright 2001-2007 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2008 by Vinay Sajip. All Rights Reserved.
 #
 # Permission to use, copy, modify, and distribute this software and its
 # documentation for any purpose and without fee is hereby granted,
@@ -18,15 +18,16 @@
 Logging package for Python. Based on PEP 282 and comments thereto in
 comp.lang.python, and influenced by Apache's log4j system.
 
-Should work under Python versions >= 1.5.2, except that source line
-information is not available unless 'sys._getframe()' is.
-
-Copyright (C) 2001-2007 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2008 Vinay Sajip. All Rights Reserved.
 
 To use, simply 'import logging' and log away!
 """
 
 import sys, os, time, io, traceback
+__all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
+           'FATAL', 'FileHandler', 'Filter', 'Filterer', 'Formatter', 'Handler',
+           'INFO', 'LogRecord', 'Logger', 'Manager', 'NOTSET', 'PlaceHolder',
+           'RootLogger', 'StreamHandler', 'WARN', 'WARNING']
 
 try:
     import codecs
@@ -41,8 +42,8 @@
 
 __author__  = "Vinay Sajip <vinay_sajip at red-dove.com>"
 __status__  = "production"
-__version__ = "0.5.0.2"
-__date__    = "16 February 2007"
+__version__ = "0.5.0.5"
+__date__    = "24 January 2008"
 
 #---------------------------------------------------------------------------
 #   Miscellaneous module data
@@ -236,7 +237,7 @@
         # 'Value is %d' instead of 'Value is 0'.
         # For the use case of passing a dictionary, this should not be a
         # problem.
-        if args and (len(args) == 1) and args[0] and isinstance(args[0], dict):
+        if args and len(args) == 1 and isinstance(args[0], dict) and args[0]:
             args = args[0]
         self.args = args
         self.levelname = getLevelName(level)
@@ -281,7 +282,7 @@
             msg = str(self.msg)
         else:
             msg = self.msg
-            if not isinstance(msg, basestring):
+            if not isinstance(msg, str):
                 try:
                     msg = str(self.msg)
                 except UnicodeError:
@@ -730,7 +731,8 @@
         """
         Flushes the stream.
         """
-        self.stream.flush()
+        if self.stream:
+            self.stream.flush()
 
     def emit(self, record):
         """
@@ -762,7 +764,7 @@
     """
     A handler class which writes formatted logging records to disk files.
     """
-    def __init__(self, filename, mode='a', encoding=None):
+    def __init__(self, filename, mode='a', encoding=None, delay=0):
         """
         Open the specified file and use it as the stream for logging.
         """
@@ -773,16 +775,21 @@
         self.baseFilename = os.path.abspath(filename)
         self.mode = mode
         self.encoding = encoding
-        stream = self._open()
-        StreamHandler.__init__(self, stream)
+        if delay:
+            self.stream = None
+        else:
+            stream = self._open()
+            StreamHandler.__init__(self, stream)
 
     def close(self):
         """
         Closes the stream.
         """
-        self.flush()
-        self.stream.close()
-        StreamHandler.close(self)
+        if self.stream:
+            self.flush()
+            self.stream.close()
+            StreamHandler.close(self)
+            self.stream = None
 
     def _open(self):
         """
@@ -795,6 +802,18 @@
             stream = codecs.open(self.baseFilename, self.mode, self.encoding)
         return stream
 
+    def emit(self, record):
+        """
+        Emit a record.
+
+        If the stream was not opened because 'delay' was specified in the
+        constructor, open it before calling the superclass's emit.
+        """
+        if self.stream is None:
+            stream = self._open()
+            StreamHandler.__init__(self, stream)
+        StreamHandler.emit(self, record)
+
 #---------------------------------------------------------------------------
 #   Manager classes and functions
 #---------------------------------------------------------------------------
@@ -1076,7 +1095,7 @@
         specialized LogRecords.
         """
         rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
-        if extra:
+        if extra is not None:
             for key in extra:
                 if (key in ["message", "asctime"]) or (key in rv.__dict__):
                     raise KeyError("Attempt to overwrite %r in LogRecord" % key)
@@ -1189,6 +1208,96 @@
 
 _loggerClass = Logger
 
+class LoggerAdapter:
+    """
+    An adapter for loggers which makes it easier to specify contextual
+    information in logging output.
+    """
+
+    def __init__(self, logger, extra):
+        """
+        Initialize the adapter with a logger and a dict-like object which
+        provides contextual information. This constructor signature allows
+        easy stacking of LoggerAdapters, if so desired.
+
+        You can effectively pass keyword arguments as shown in the
+        following example:
+
+        adapter = LoggerAdapter(someLogger, dict(p1=v1, p2="v2"))
+        """
+        self.logger = logger
+        self.extra = extra
+
+    def process(self, msg, kwargs):
+        """
+        Process the logging message and keyword arguments passed in to
+        a logging call to insert contextual information. You can either
+        manipulate the message itself, the keyword args or both. Return
+        the message and kwargs modified (or not) to suit your needs.
+
+        Normally, you'll only need to override this one method in a
+        LoggerAdapter subclass for your specific needs.
+        """
+        kwargs["extra"] = self.extra
+        return msg, kwargs
+
+    def debug(self, msg, *args, **kwargs):
+        """
+        Delegate a debug call to the underlying logger, after adding
+        contextual information from this adapter instance.
+        """
+        msg, kwargs = self.process(msg, kwargs)
+        self.logger.debug(msg, *args, **kwargs)
+
+    def info(self, msg, *args, **kwargs):
+        """
+        Delegate an info call to the underlying logger, after adding
+        contextual information from this adapter instance.
+        """
+        msg, kwargs = self.process(msg, kwargs)
+        self.logger.info(msg, *args, **kwargs)
+
+    def warning(self, msg, *args, **kwargs):
+        """
+        Delegate a warning call to the underlying logger, after adding
+        contextual information from this adapter instance.
+        """
+        msg, kwargs = self.process(msg, kwargs)
+        self.logger.warning(msg, *args, **kwargs)
+
+    def error(self, msg, *args, **kwargs):
+        """
+        Delegate an error call to the underlying logger, after adding
+        contextual information from this adapter instance.
+        """
+        msg, kwargs = self.process(msg, kwargs)
+        self.logger.error(msg, *args, **kwargs)
+
+    def exception(self, msg, *args, **kwargs):
+        """
+        Delegate an exception call to the underlying logger, after adding
+        contextual information from this adapter instance.
+        """
+        msg, kwargs = self.process(msg, kwargs)
+        kwargs["exc_info"] = 1
+        self.logger.error(msg, *args, **kwargs)
+
+    def critical(self, msg, *args, **kwargs):
+        """
+        Delegate a critical call to the underlying logger, after adding
+        contextual information from this adapter instance.
+        """
+        msg, kwargs = self.process(msg, kwargs)
+        self.logger.critical(msg, *args, **kwargs)
+
+    def log(self, level, msg, *args, **kwargs):
+        """
+        Delegate a log call to the underlying logger, after adding
+        contextual information from this adapter instance.
+        """
+        msg, kwargs = self.process(msg, kwargs)
+        self.logger.log(level, msg, *args, **kwargs)
+
 root = RootLogger(WARNING)
 Logger.root = root
 Logger.manager = Manager(Logger.root)
@@ -1245,7 +1354,7 @@
         hdlr.setFormatter(fmt)
         root.addHandler(hdlr)
         level = kwargs.get("level")
-        if level:
+        if level is not None:
             root.setLevel(level)
 
 #---------------------------------------------------------------------------

Modified: python/branches/py3k-importlib/Lib/logging/config.py
==============================================================================
--- python/branches/py3k-importlib/Lib/logging/config.py	(original)
+++ python/branches/py3k-importlib/Lib/logging/config.py	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,4 @@
-# Copyright 2001-2005 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2007 by Vinay Sajip. All Rights Reserved.
 #
 # Permission to use, copy, modify, and distribute this software and its
 # documentation for any purpose and without fee is hereby granted,
@@ -19,10 +19,7 @@
 is based on PEP 282 and comments thereto in comp.lang.python, and influenced
 by Apache's log4j system.
 
-Should work under Python versions >= 1.5.2, except that source line
-information is not available unless 'sys._getframe()' is.
-
-Copyright (C) 2001-2004 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2007 Vinay Sajip. All Rights Reserved.
 
 To use, simply 'import logging' and log away!
 """
@@ -203,6 +200,14 @@
     #which were in the previous configuration but
     #which are not in the new configuration.
     existing = list(root.manager.loggerDict.keys())
+    #The list needs to be sorted so that we can
+    #avoid disabling child loggers of explicitly
+    #named loggers. With a sorted list it is easier
+    #to find the child loggers.
+    existing.sort()
+    #We'll keep the list of existing loggers
+    #which are children of named loggers here...
+    child_loggers = []
     #now set up the new ones...
     for log in llist:
         sectname = "logger_%s" % log
@@ -214,6 +219,14 @@
             propagate = 1
         logger = logging.getLogger(qn)
         if qn in existing:
+            i = existing.index(qn)
+            prefixed = qn + "."
+            pflen = len(prefixed)
+            num_existing = len(existing)
+            i = i + 1 # look at the entry after qn
+            while (i < num_existing) and (existing[i][:pflen] == prefixed):
+                child_loggers.append(existing[i])
+                i = i + 1
             existing.remove(qn)
         if "level" in opts:
             level = cp.get(sectname, "level")
@@ -231,8 +244,16 @@
     #Disable any old loggers. There's no point deleting
     #them as other threads may continue to hold references
     #and by disabling them, you stop them doing any logging.
+    #However, don't disable children of named loggers, as that's
+    #probably not what was intended by the user.
     for log in existing:
-        root.manager.loggerDict[log].disabled = 1
+        logger = root.manager.loggerDict[log]
+        if log in child_loggers:
+            logger.level = logging.NOTSET
+            logger.handlers = []
+            logger.propagate = 1
+        else:
+            logger.disabled = 1
 
 
 def listen(port=DEFAULT_LOGGING_CONFIG_PORT):

Modified: python/branches/py3k-importlib/Lib/logging/handlers.py
==============================================================================
--- python/branches/py3k-importlib/Lib/logging/handlers.py	(original)
+++ python/branches/py3k-importlib/Lib/logging/handlers.py	Thu Mar 27 00:48:05 2008
@@ -19,16 +19,12 @@
 based on PEP 282 and comments thereto in comp.lang.python, and influenced by
 Apache's log4j system.
 
-Should work under Python versions >= 1.5.2, except that source line
-information is not available unless 'sys._getframe()' is.
-
 Copyright (C) 2001-2007 Vinay Sajip. All Rights Reserved.
 
 To use, simply 'import logging' and log away!
 """
 
-import sys, logging, socket, os, struct, time, glob
-import pickle
+import logging, socket, os, pickle, struct, time, glob
 from stat import ST_DEV, ST_INO
 
 try:
@@ -54,13 +50,13 @@
     Not meant to be instantiated directly.  Instead, use RotatingFileHandler
     or TimedRotatingFileHandler.
     """
-    def __init__(self, filename, mode, encoding=None):
+    def __init__(self, filename, mode, encoding=None, delay=0):
         """
         Use the specified filename for streamed logging
         """
         if codecs is None:
             encoding = None
-        logging.FileHandler.__init__(self, filename, mode, encoding)
+        logging.FileHandler.__init__(self, filename, mode, encoding, delay)
         self.mode = mode
         self.encoding = encoding
 
@@ -85,7 +81,7 @@
     Handler for logging to a set of files, which switches from one file
     to the next when the current file reaches a certain size.
     """
-    def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None):
+    def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=0):
         """
         Open the specified file and use it as the stream for logging.
 
@@ -108,7 +104,7 @@
         """
         if maxBytes > 0:
             mode = 'a' # doesn't make sense otherwise!
-        BaseRotatingHandler.__init__(self, filename, mode, encoding)
+        BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
         self.maxBytes = maxBytes
         self.backupCount = backupCount
 
@@ -157,8 +153,8 @@
     If backupCount is > 0, when rollover is done, no more than backupCount
     files are kept - the oldest ones are deleted.
     """
-    def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None):
-        BaseRotatingHandler.__init__(self, filename, 'a', encoding)
+    def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None, delay=0):
+        BaseRotatingHandler.__init__(self, filename, 'a', encoding, delay)
         self.when = when.upper()
         self.backupCount = backupCount
         # Calculate the real rollover interval, which is just the number of
@@ -229,13 +225,16 @@
             #         Days to rollover is 6 - 5 + 3, or 4.  In this case, it's the
             #         number of days left in the current week (1) plus the number
             #         of days in the next week until the rollover day (3).
+            # The calculations described in 2) and 3) above need to have a day added.
+            # This is because the above time calculation takes us to midnight on this
+            # day, i.e. the start of the next day.
             if when.startswith('W'):
                 day = t[6] # 0 is Monday
-                if day > self.dayOfWeek:
-                    daysToWait = (day - self.dayOfWeek) - 1
-                    self.rolloverAt = self.rolloverAt + (daysToWait * (60 * 60 * 24))
-                if day < self.dayOfWeek:
-                    daysToWait = (6 - self.dayOfWeek) + day
+                if day != self.dayOfWeek:
+                    if day < self.dayOfWeek:
+                        daysToWait = self.dayOfWeek - day
+                    else:
+                        daysToWait = 6 - day + self.dayOfWeek + 1
                     self.rolloverAt = self.rolloverAt + (daysToWait * (60 * 60 * 24))
 
         #print "Will rollover at %d, %d seconds from now" % (self.rolloverAt, self.rolloverAt - currentTime)
@@ -300,10 +299,13 @@
     This handler is based on a suggestion and patch by Chad J.
     Schroeder.
     """
-    def __init__(self, filename, mode='a', encoding=None):
-        logging.FileHandler.__init__(self, filename, mode, encoding)
-        stat = os.stat(self.baseFilename)
-        self.dev, self.ino = stat[ST_DEV], stat[ST_INO]
+    def __init__(self, filename, mode='a', encoding=None, delay=0):
+        logging.FileHandler.__init__(self, filename, mode, encoding, delay)
+        if not os.path.exists(self.baseFilename):
+            self.dev, self.ino = -1, -1
+        else:
+            stat = os.stat(self.baseFilename)
+            self.dev, self.ino = stat[ST_DEV], stat[ST_INO]
 
     def emit(self, record):
         """
@@ -319,7 +321,7 @@
         else:
             stat = os.stat(self.baseFilename)
             changed = (stat[ST_DEV] != self.dev) or (stat[ST_INO] != self.ino)
-        if changed:
+        if changed and self.stream is not None:
             self.stream.flush()
             self.stream.close()
             self.stream = self._open()

Modified: python/branches/py3k-importlib/Lib/mailbox.py
==============================================================================
--- python/branches/py3k-importlib/Lib/mailbox.py	(original)
+++ python/branches/py3k-importlib/Lib/mailbox.py	Thu Mar 27 00:48:05 2008
@@ -313,7 +313,10 @@
         subpath = self._lookup(key)
         f = open(os.path.join(self._path, subpath), 'r')
         try:
-            msg = MaildirMessage(f)
+            if self._factory:
+                msg = self._factory(f)
+            else:
+                msg = MaildirMessage(f)
         finally:
             f.close()
         subdir, name = os.path.split(subpath)
@@ -333,7 +336,7 @@
 
     def get_file(self, key):
         """Return a file-like representation or raise a KeyError."""
-        f = open(os.path.join(self._path, self._lookup(key)), 'rb')
+        f = open(os.path.join(self._path, self._lookup(key)), 'r')
         return _ProxyFile(f)
 
     def iterkeys(self):
@@ -936,7 +939,7 @@
     def get_file(self, key):
         """Return a file-like representation or raise a KeyError."""
         try:
-            f = open(os.path.join(self._path, str(key)), 'rb')
+            f = open(os.path.join(self._path, str(key)), 'r')
         except IOError as e:
             if e.errno == errno.ENOENT:
                 raise KeyError('No message with key: %s' % key)
@@ -1762,11 +1765,11 @@
 
     def read(self, size=None):
         """Read bytes."""
-        return str(self._read(size, self._file.read))
+        return self._read(size, self._file.read)
 
     def readline(self, size=None):
         """Read a line."""
-        return str(self._read(size, self._file.readline))
+        return self._read(size, self._file.readline)
 
     def readlines(self, sizehint=None):
         """Read multiple lines."""

Deleted: /python/branches/py3k-importlib/Lib/markupbase.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/markupbase.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,392 +0,0 @@
-"""Shared support for scanning document type declarations in HTML and XHTML.
-
-This module is used as a foundation for the HTMLParser and sgmllib
-modules (indirectly, for htmllib as well).  It has no documented
-public API and should not be used directly.
-
-"""
-
-import re
-
-_declname_match = re.compile(r'[a-zA-Z][-_.a-zA-Z0-9]*\s*').match
-_declstringlit_match = re.compile(r'(\'[^\']*\'|"[^"]*")\s*').match
-_commentclose = re.compile(r'--\s*>')
-_markedsectionclose = re.compile(r']\s*]\s*>')
-
-# An analysis of the MS-Word extensions is available at
-# http://www.planetpublish.com/xmlarena/xap/Thursday/WordtoXML.pdf
-
-_msmarkedsectionclose = re.compile(r']\s*>')
-
-del re
-
-
-class ParserBase:
-    """Parser base class which provides some common support methods used
-    by the SGML/HTML and XHTML parsers."""
-
-    def __init__(self):
-        if self.__class__ is ParserBase:
-            raise RuntimeError(
-                "markupbase.ParserBase must be subclassed")
-
-    def error(self, message):
-        raise NotImplementedError(
-            "subclasses of ParserBase must override error()")
-
-    def reset(self):
-        self.lineno = 1
-        self.offset = 0
-
-    def getpos(self):
-        """Return current line number and offset."""
-        return self.lineno, self.offset
-
-    # Internal -- update line number and offset.  This should be
-    # called for each piece of data exactly once, in order -- in other
-    # words the concatenation of all the input strings to this
-    # function should be exactly the entire input.
-    def updatepos(self, i, j):
-        if i >= j:
-            return j
-        rawdata = self.rawdata
-        nlines = rawdata.count("\n", i, j)
-        if nlines:
-            self.lineno = self.lineno + nlines
-            pos = rawdata.rindex("\n", i, j) # Should not fail
-            self.offset = j-(pos+1)
-        else:
-            self.offset = self.offset + j-i
-        return j
-
-    _decl_otherchars = ''
-
-    # Internal -- parse declaration (for use by subclasses).
-    def parse_declaration(self, i):
-        # This is some sort of declaration; in "HTML as
-        # deployed," this should only be the document type
-        # declaration ("<!DOCTYPE html...>").
-        # ISO 8879:1986, however, has more complex
-        # declaration syntax for elements in <!...>, including:
-        # --comment--
-        # [marked section]
-        # name in the following list: ENTITY, DOCTYPE, ELEMENT,
-        # ATTLIST, NOTATION, SHORTREF, USEMAP,
-        # LINKTYPE, LINK, IDLINK, USELINK, SYSTEM
-        rawdata = self.rawdata
-        j = i + 2
-        assert rawdata[i:j] == "<!", "unexpected call to parse_declaration"
-        if rawdata[j:j+1] == ">":
-            # the empty comment <!>
-            return j + 1
-        if rawdata[j:j+1] in ("-", ""):
-            # Start of comment followed by buffer boundary,
-            # or just a buffer boundary.
-            return -1
-        # A simple, practical version could look like: ((name|stringlit) S*) + '>'
-        n = len(rawdata)
-        if rawdata[j:j+2] == '--': #comment
-            # Locate --.*-- as the body of the comment
-            return self.parse_comment(i)
-        elif rawdata[j] == '[': #marked section
-            # Locate [statusWord [...arbitrary SGML...]] as the body of the marked section
-            # Where statusWord is one of TEMP, CDATA, IGNORE, INCLUDE, RCDATA
-            # Note that this is extended by Microsoft Office "Save as Web" function
-            # to include [if...] and [endif].
-            return self.parse_marked_section(i)
-        else: #all other declaration elements
-            decltype, j = self._scan_name(j, i)
-        if j < 0:
-            return j
-        if decltype == "doctype":
-            self._decl_otherchars = ''
-        while j < n:
-            c = rawdata[j]
-            if c == ">":
-                # end of declaration syntax
-                data = rawdata[i+2:j]
-                if decltype == "doctype":
-                    self.handle_decl(data)
-                else:
-                    self.unknown_decl(data)
-                return j + 1
-            if c in "\"'":
-                m = _declstringlit_match(rawdata, j)
-                if not m:
-                    return -1 # incomplete
-                j = m.end()
-            elif c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
-                name, j = self._scan_name(j, i)
-            elif c in self._decl_otherchars:
-                j = j + 1
-            elif c == "[":
-                # this could be handled in a separate doctype parser
-                if decltype == "doctype":
-                    j = self._parse_doctype_subset(j + 1, i)
-                elif decltype in ("attlist", "linktype", "link", "element"):
-                    # must tolerate []'d groups in a content model in an element declaration
-                    # also in data attribute specifications of attlist declaration
-                    # also link type declaration subsets in linktype declarations
-                    # also link attribute specification lists in link declarations
-                    self.error("unsupported '[' char in %s declaration" % decltype)
-                else:
-                    self.error("unexpected '[' char in declaration")
-            else:
-                self.error(
-                    "unexpected %r char in declaration" % rawdata[j])
-            if j < 0:
-                return j
-        return -1 # incomplete
-
-    # Internal -- parse a marked section
-    # Override this to handle MS-word extension syntax <![if word]>content<![endif]>
-    def parse_marked_section(self, i, report=1):
-        rawdata= self.rawdata
-        assert rawdata[i:i+3] == '<![', "unexpected call to parse_marked_section()"
-        sectName, j = self._scan_name( i+3, i )
-        if j < 0:
-            return j
-        if sectName in ("temp", "cdata", "ignore", "include", "rcdata"):
-            # look for standard ]]> ending
-            match= _markedsectionclose.search(rawdata, i+3)
-        elif sectName in ("if", "else", "endif"):
-            # look for MS Office ]> ending
-            match= _msmarkedsectionclose.search(rawdata, i+3)
-        else:
-            self.error('unknown status keyword %r in marked section' % rawdata[i+3:j])
-        if not match:
-            return -1
-        if report:
-            j = match.start(0)
-            self.unknown_decl(rawdata[i+3: j])
-        return match.end(0)
-
-    # Internal -- parse comment, return length or -1 if not terminated
-    def parse_comment(self, i, report=1):
-        rawdata = self.rawdata
-        if rawdata[i:i+4] != '<!--':
-            self.error('unexpected call to parse_comment()')
-        match = _commentclose.search(rawdata, i+4)
-        if not match:
-            return -1
-        if report:
-            j = match.start(0)
-            self.handle_comment(rawdata[i+4: j])
-        return match.end(0)
-
-    # Internal -- scan past the internal subset in a <!DOCTYPE declaration,
-    # returning the index just past any whitespace following the trailing ']'.
-    def _parse_doctype_subset(self, i, declstartpos):
-        rawdata = self.rawdata
-        n = len(rawdata)
-        j = i
-        while j < n:
-            c = rawdata[j]
-            if c == "<":
-                s = rawdata[j:j+2]
-                if s == "<":
-                    # end of buffer; incomplete
-                    return -1
-                if s != "<!":
-                    self.updatepos(declstartpos, j + 1)
-                    self.error("unexpected char in internal subset (in %r)" % s)
-                if (j + 2) == n:
-                    # end of buffer; incomplete
-                    return -1
-                if (j + 4) > n:
-                    # end of buffer; incomplete
-                    return -1
-                if rawdata[j:j+4] == "<!--":
-                    j = self.parse_comment(j, report=0)
-                    if j < 0:
-                        return j
-                    continue
-                name, j = self._scan_name(j + 2, declstartpos)
-                if j == -1:
-                    return -1
-                if name not in ("attlist", "element", "entity", "notation"):
-                    self.updatepos(declstartpos, j + 2)
-                    self.error(
-                        "unknown declaration %r in internal subset" % name)
-                # handle the individual names
-                meth = getattr(self, "_parse_doctype_" + name)
-                j = meth(j, declstartpos)
-                if j < 0:
-                    return j
-            elif c == "%":
-                # parameter entity reference
-                if (j + 1) == n:
-                    # end of buffer; incomplete
-                    return -1
-                s, j = self._scan_name(j + 1, declstartpos)
-                if j < 0:
-                    return j
-                if rawdata[j] == ";":
-                    j = j + 1
-            elif c == "]":
-                j = j + 1
-                while j < n and rawdata[j].isspace():
-                    j = j + 1
-                if j < n:
-                    if rawdata[j] == ">":
-                        return j
-                    self.updatepos(declstartpos, j)
-                    self.error("unexpected char after internal subset")
-                else:
-                    return -1
-            elif c.isspace():
-                j = j + 1
-            else:
-                self.updatepos(declstartpos, j)
-                self.error("unexpected char %r in internal subset" % c)
-        # end of buffer reached
-        return -1
-
-    # Internal -- scan past <!ELEMENT declarations
-    def _parse_doctype_element(self, i, declstartpos):
-        name, j = self._scan_name(i, declstartpos)
-        if j == -1:
-            return -1
-        # style content model; just skip until '>'
-        rawdata = self.rawdata
-        if '>' in rawdata[j:]:
-            return rawdata.find(">", j) + 1
-        return -1
-
-    # Internal -- scan past <!ATTLIST declarations
-    def _parse_doctype_attlist(self, i, declstartpos):
-        rawdata = self.rawdata
-        name, j = self._scan_name(i, declstartpos)
-        c = rawdata[j:j+1]
-        if c == "":
-            return -1
-        if c == ">":
-            return j + 1
-        while 1:
-            # scan a series of attribute descriptions; simplified:
-            #   name type [value] [#constraint]
-            name, j = self._scan_name(j, declstartpos)
-            if j < 0:
-                return j
-            c = rawdata[j:j+1]
-            if c == "":
-                return -1
-            if c == "(":
-                # an enumerated type; look for ')'
-                if ")" in rawdata[j:]:
-                    j = rawdata.find(")", j) + 1
-                else:
-                    return -1
-                while rawdata[j:j+1].isspace():
-                    j = j + 1
-                if not rawdata[j:]:
-                    # end of buffer, incomplete
-                    return -1
-            else:
-                name, j = self._scan_name(j, declstartpos)
-            c = rawdata[j:j+1]
-            if not c:
-                return -1
-            if c in "'\"":
-                m = _declstringlit_match(rawdata, j)
-                if m:
-                    j = m.end()
-                else:
-                    return -1
-                c = rawdata[j:j+1]
-                if not c:
-                    return -1
-            if c == "#":
-                if rawdata[j:] == "#":
-                    # end of buffer
-                    return -1
-                name, j = self._scan_name(j + 1, declstartpos)
-                if j < 0:
-                    return j
-                c = rawdata[j:j+1]
-                if not c:
-                    return -1
-            if c == '>':
-                # all done
-                return j + 1
-
-    # Internal -- scan past <!NOTATION declarations
-    def _parse_doctype_notation(self, i, declstartpos):
-        name, j = self._scan_name(i, declstartpos)
-        if j < 0:
-            return j
-        rawdata = self.rawdata
-        while 1:
-            c = rawdata[j:j+1]
-            if not c:
-                # end of buffer; incomplete
-                return -1
-            if c == '>':
-                return j + 1
-            if c in "'\"":
-                m = _declstringlit_match(rawdata, j)
-                if not m:
-                    return -1
-                j = m.end()
-            else:
-                name, j = self._scan_name(j, declstartpos)
-                if j < 0:
-                    return j
-
-    # Internal -- scan past <!ENTITY declarations
-    def _parse_doctype_entity(self, i, declstartpos):
-        rawdata = self.rawdata
-        if rawdata[i:i+1] == "%":
-            j = i + 1
-            while 1:
-                c = rawdata[j:j+1]
-                if not c:
-                    return -1
-                if c.isspace():
-                    j = j + 1
-                else:
-                    break
-        else:
-            j = i
-        name, j = self._scan_name(j, declstartpos)
-        if j < 0:
-            return j
-        while 1:
-            c = self.rawdata[j:j+1]
-            if not c:
-                return -1
-            if c in "'\"":
-                m = _declstringlit_match(rawdata, j)
-                if m:
-                    j = m.end()
-                else:
-                    return -1    # incomplete
-            elif c == ">":
-                return j + 1
-            else:
-                name, j = self._scan_name(j, declstartpos)
-                if j < 0:
-                    return j
-
-    # Internal -- scan a name token and the new position and the token, or
-    # return -1 if we've reached the end of the buffer.
-    def _scan_name(self, i, declstartpos):
-        rawdata = self.rawdata
-        n = len(rawdata)
-        if i == n:
-            return None, -1
-        m = _declname_match(rawdata, i)
-        if m:
-            s = m.group()
-            name = s.strip()
-            if (i + len(s)) == n:
-                return None, -1  # end of buffer
-            return name.lower(), m.end()
-        else:
-            self.updatepos(declstartpos, i)
-            self.error("expected name token at %r"
-                       % rawdata[declstartpos:declstartpos+20])
-
-    # To be overridden -- handlers for unknown objects
-    def unknown_decl(self, data):
-        pass

Modified: python/branches/py3k-importlib/Lib/mhlib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/mhlib.py	(original)
+++ python/branches/py3k-importlib/Lib/mhlib.py	Thu Mar 27 00:48:05 2008
@@ -365,7 +365,7 @@
             try:
                 count = int(tail)
             except (ValueError, OverflowError):
-                # Can't use sys.maxint because of i+count below
+                # Can't use sys.maxsize because of i+count below
                 count = len(all)
             try:
                 anchor = self._parseindex(head, all)
@@ -428,7 +428,7 @@
             try:
                 return int(seq)
             except (OverflowError, ValueError):
-                return sys.maxint
+                return sys.maxsize
         if seq in ('cur', '.'):
             return self.getcurrent()
         if seq == 'first':

Modified: python/branches/py3k-importlib/Lib/mimetypes.py
==============================================================================
--- python/branches/py3k-importlib/Lib/mimetypes.py	(original)
+++ python/branches/py3k-importlib/Lib/mimetypes.py	Thu Mar 27 00:48:05 2008
@@ -393,6 +393,7 @@
         '.movie'  : 'video/x-sgi-movie',
         '.mp2'    : 'audio/mpeg',
         '.mp3'    : 'audio/mpeg',
+        '.mp4'    : 'video/mp4',
         '.mpa'    : 'video/mpeg',
         '.mpe'    : 'video/mpeg',
         '.mpeg'   : 'video/mpeg',

Modified: python/branches/py3k-importlib/Lib/modulefinder.py
==============================================================================
--- python/branches/py3k-importlib/Lib/modulefinder.py	(original)
+++ python/branches/py3k-importlib/Lib/modulefinder.py	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,7 @@
 import marshal
 import os
 import sys
-import new
+import types
 import struct
 
 if hasattr(sys.__stdout__, "newlines"):
@@ -16,12 +16,13 @@
     # remain compatible with Python  < 2.3
     READ_MODE = "r"
 
-LOAD_CONST = chr(dis.opname.index('LOAD_CONST'))
-IMPORT_NAME = chr(dis.opname.index('IMPORT_NAME'))
-STORE_NAME = chr(dis.opname.index('STORE_NAME'))
-STORE_GLOBAL = chr(dis.opname.index('STORE_GLOBAL'))
+# XXX Clean up once str8's cstor matches bytes.
+LOAD_CONST = bytes([dis.opname.index('LOAD_CONST')])
+IMPORT_NAME = bytes([dis.opname.index('IMPORT_NAME')])
+STORE_NAME = bytes([dis.opname.index('STORE_NAME')])
+STORE_GLOBAL = bytes([dis.opname.index('STORE_GLOBAL')])
 STORE_OPS = [STORE_NAME, STORE_GLOBAL]
-HAVE_ARGUMENT = chr(dis.HAVE_ARGUMENT)
+HAVE_ARGUMENT = bytes([dis.HAVE_ARGUMENT])
 
 # Modulefinder does a good job at simulating Python's, but it can not
 # handle __path__ modifications packages make at runtime.  Therefore there
@@ -367,7 +368,7 @@
         consts = co.co_consts
         LOAD_LOAD_AND_IMPORT = LOAD_CONST + LOAD_CONST + IMPORT_NAME
         while code:
-            c = code[0]
+            c = bytes([code[0]])
             if c in STORE_OPS:
                 oparg, = unpack('<H', code[1:3])
                 yield "store", (names[oparg],)
@@ -588,7 +589,7 @@
             if isinstance(consts[i], type(co)):
                 consts[i] = self.replace_paths_in_code(consts[i])
 
-        return new.code(co.co_argcount, co.co_nlocals, co.co_stacksize,
+        return types.CodeType(co.co_argcount, co.co_nlocals, co.co_stacksize,
                          co.co_flags, co.co_code, tuple(consts), co.co_names,
                          co.co_varnames, new_filename, co.co_name,
                          co.co_firstlineno, co.co_lnotab,

Modified: python/branches/py3k-importlib/Lib/msilib/__init__.py
==============================================================================
--- python/branches/py3k-importlib/Lib/msilib/__init__.py	(original)
+++ python/branches/py3k-importlib/Lib/msilib/__init__.py	Thu Mar 27 00:48:05 2008
@@ -101,7 +101,7 @@
             field = value[i]
             if isinstance(field, int):
                 r.SetInteger(i+1,field)
-            elif isinstance(field, basestring):
+            elif isinstance(field, str):
                 r.SetString(i+1,field)
             elif field is None:
                 pass

Modified: python/branches/py3k-importlib/Lib/msilib/schema.py
==============================================================================
--- python/branches/py3k-importlib/Lib/msilib/schema.py	(original)
+++ python/branches/py3k-importlib/Lib/msilib/schema.py	Thu Mar 27 00:48:05 2008
@@ -649,7 +649,7 @@
 ('File','File','N',None, None, None, None, 'Identifier',None, 'Primary key, non-localized token, must match identifier in cabinet.  For uncompressed files, this field is ignored.',),
 ('File','Component_','N',None, None, 'Component',1,'Identifier',None, 'Foreign key referencing Component that controls the file.',),
 ('File','FileName','N',None, None, None, None, 'Filename',None, 'File name used for installation, may be localized.  This may contain a "short name|long name" pair.',),
-('File','FileSize','N',0,2147483647,None, None, None, None, 'Size of file in bytes (long integer).',),
+('File','FileSize','N',0,2147483647,None, None, None, None, 'Size of file in bytes (integer).',),
 ('File','Language','Y',None, None, None, None, 'Language',None, 'List of decimal language Ids, comma-separated if more than one.',),
 ('File','Version','Y',None, None, 'File',1,'Version',None, 'Version string for versioned files;  Blank for unversioned files.',),
 ('CCPSearch','Signature_','N',None, None, 'Signature;RegLocator;IniLocator;DrLocator;CompLocator',1,'Identifier',None, 'The Signature_ represents a unique file signature and is also the foreign key in the Signature,  RegLocator, IniLocator, CompLocator and the DrLocator tables.',),
@@ -852,10 +852,10 @@
 ('MsiDigitalSignature','SignObject','N',None, None, None, None, 'Text',None, 'Foreign key to Media table',),
 ('MsiFileHash','File_','N',None, None, 'File',1,'Identifier',None, 'Primary key, foreign key into File table referencing file with this hash',),
 ('MsiFileHash','Options','N',0,32767,None, None, None, None, 'Various options and attributes for this hash.',),
-('MsiFileHash','HashPart1','N',None, None, None, None, None, None, 'Size of file in bytes (long integer).',),
-('MsiFileHash','HashPart2','N',None, None, None, None, None, None, 'Size of file in bytes (long integer).',),
-('MsiFileHash','HashPart3','N',None, None, None, None, None, None, 'Size of file in bytes (long integer).',),
-('MsiFileHash','HashPart4','N',None, None, None, None, None, None, 'Size of file in bytes (long integer).',),
+('MsiFileHash','HashPart1','N',None, None, None, None, None, None, 'Size of file in bytes (integer).',),
+('MsiFileHash','HashPart2','N',None, None, None, None, None, None, 'Size of file in bytes (integer).',),
+('MsiFileHash','HashPart3','N',None, None, None, None, None, None, 'Size of file in bytes (integer).',),
+('MsiFileHash','HashPart4','N',None, None, None, None, None, None, 'Size of file in bytes (integer).',),
 ('MsiPatchHeaders','StreamRef','N',None, None, None, None, 'Identifier',None, 'Primary key. A unique identifier for the row.',),
 ('MsiPatchHeaders','Header','N',None, None, None, None, 'Binary',None, 'Binary stream. The patch header, used for patch validation.',),
 ('ODBCAttribute','Value','Y',None, None, None, None, 'Text',None, 'Value for ODBC driver attribute',),
@@ -883,7 +883,7 @@
 ('Patch','Attributes','N',0,32767,None, None, None, None, 'Integer containing bit flags representing patch attributes',),
 ('Patch','File_','N',None, None, None, None, 'Identifier',None, 'Primary key, non-localized token, foreign key to File table, must match identifier in cabinet.',),
 ('Patch','Header','Y',None, None, None, None, 'Binary',None, 'Binary stream. The patch header, used for patch validation.',),
-('Patch','PatchSize','N',0,2147483647,None, None, None, None, 'Size of patch in bytes (long integer).',),
+('Patch','PatchSize','N',0,2147483647,None, None, None, None, 'Size of patch in bytes (integer).',),
 ('Patch','StreamRef_','Y',None, None, None, None, 'Identifier',None, 'Identifier. Foreign key to the StreamRef column of the MsiPatchHeaders table.',),
 ('PatchPackage','Media_','N',0,32767,None, None, None, None, 'Foreign key to DiskId column of Media table. Indicates the disk containing the patch package.',),
 ('PatchPackage','PatchId','N',None, None, None, None, 'Guid',None, 'A unique string GUID representing this patch.',),
@@ -978,7 +978,7 @@
 ('Signature','MinSize','Y',0,2147483647,None, None, None, None, 'The minimum size of the file.',),
 ('Signature','MinVersion','Y',None, None, None, None, 'Text',None, 'The minimum version of the file.',),
 ('TextStyle','TextStyle','N',None, None, None, None, 'Identifier',None, 'Name of the style. The primary key of this table. This name is embedded in the texts to indicate a style change.',),
-('TextStyle','Color','Y',0,16777215,None, None, None, None, 'A long integer indicating the color of the string in the RGB format (Red, Green, Blue each 0-255, RGB = R + 256*G + 256^2*B).',),
+('TextStyle','Color','Y',0,16777215,None, None, None, None, 'An integer indicating the color of the string in the RGB format (Red, Green, Blue each 0-255, RGB = R + 256*G + 256^2*B).',),
 ('TextStyle','FaceName','N',None, None, None, None, 'Text',None, 'A string indicating the name of the font used. Required. The string must be at most 31 characters long.',),
 ('TextStyle','Size','N',0,32767,None, None, None, None, 'The size of the font used. This size is given in our units (1/12 of the system font height). Assuming that the system font is set to 12 point size, this is equivalent to the point size.',),
 ('TextStyle','StyleBits','Y',0,15,None, None, None, None, 'A combination of style bits.',),

Modified: python/branches/py3k-importlib/Lib/netrc.py
==============================================================================
--- python/branches/py3k-importlib/Lib/netrc.py	(original)
+++ python/branches/py3k-importlib/Lib/netrc.py	Thu Mar 27 00:48:05 2008
@@ -26,9 +26,12 @@
                 file = os.path.join(os.environ['HOME'], ".netrc")
             except KeyError:
                 raise IOError("Could not find .netrc: $HOME is not set")
-        fp = open(file)
         self.hosts = {}
         self.macros = {}
+        with open(file) as fp:
+            self._parse(file, fp)
+
+    def _parse(self, file, fp):
         lexer = shlex.shlex(fp)
         lexer.wordchars += r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
         while 1:

Deleted: /python/branches/py3k-importlib/Lib/new.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/new.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,11 +0,0 @@
-"""Create new objects of various types.  Deprecated.
-
-This module is no longer required except for backward compatibility.
-Objects of most types can now be created by calling the type object.
-"""
-
-classobj = type
-from types import FunctionType as function
-from types import MethodType as instancemethod
-from types import ModuleType as module
-from types import CodeType as code

Modified: python/branches/py3k-importlib/Lib/ntpath.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ntpath.py	(original)
+++ python/branches/py3k-importlib/Lib/ntpath.py	Thu Mar 27 00:48:05 2008
@@ -6,8 +6,8 @@
 """
 
 import os
-import stat
 import sys
+import stat
 import genericpath
 from genericpath import *
 
@@ -254,12 +254,10 @@
     except os.error:
         return
     func(arg, top, names)
-    exceptions = ('.', '..')
     for name in names:
-        if name not in exceptions:
-            name = join(top, name)
-            if isdir(name):
-                walk(name, func, arg)
+        name = join(top, name)
+        if isdir(name):
+            walk(name, func, arg)
 
 
 # Expand paths beginning with '~' or '~user'.
@@ -492,4 +490,6 @@
         i += 1
 
     rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
+    if not rel_list:
+        return curdir
     return join(*rel_list)

Modified: python/branches/py3k-importlib/Lib/numbers.py
==============================================================================
--- python/branches/py3k-importlib/Lib/numbers.py	(original)
+++ python/branches/py3k-importlib/Lib/numbers.py	Thu Mar 27 00:48:05 2008
@@ -7,10 +7,7 @@
 
 from abc import ABCMeta, abstractmethod, abstractproperty
 
-__all__ = ["Number", "Exact", "Inexact",
-           "Complex", "Real", "Rational", "Integral",
-           ]
-
+__all__ = ["Number", "Complex", "Real", "Rational", "Integral"]
 
 class Number(metaclass=ABCMeta):
     """All numbers inherit from this class.
@@ -20,30 +17,13 @@
     """
 
 
-class Exact(Number):
-    """Operations on instances of this type are exact.
-
-    As long as the result of a homogenous operation is of the same
-    type, you can assume that it was computed exactly, and there are
-    no round-off errors. Laws like commutativity and associativity
-    hold.
-    """
-
-Exact.register(int)
-
-
-class Inexact(Number):
-    """Operations on instances of this type are inexact.
-
-    Given X, an instance of Inexact, it is possible that (X + -X) + 3
-    == 3, but X + (-X + 3) == 0. The exact form this error takes will
-    vary by type, but it's generally unsafe to compare this type for
-    equality.
-    """
-
-Inexact.register(complex)
-Inexact.register(float)
-
+## Notes on Decimal
+## ----------------
+## Decimal has all of the methods specified by the Real abc, but it should
+## not be registered as a Real because decimals do not interoperate with
+## binary floats (i.e.  Decimal('3.14') + 2.71828 is undefined).  But,
+## abstract reals are expected to interoperate (i.e. R1 + R2 should be
+## expected to work if R1 and R2 are both Reals).
 
 class Complex(Number):
     """Complex defines the operations that work on the builtin complex type.
@@ -95,9 +75,10 @@
         """-self"""
         raise NotImplementedError
 
+    @abstractmethod
     def __pos__(self):
         """+self"""
-        return self
+        raise NotImplementedError
 
     def __sub__(self, other):
         """self - other"""
@@ -118,18 +99,18 @@
         raise NotImplementedError
 
     @abstractmethod
-    def __div__(self, other):
-        """self / other"""
+    def __truediv__(self, other):
+        """self / other: Should promote to float when necessary."""
         raise NotImplementedError
 
     @abstractmethod
-    def __rdiv__(self, other):
+    def __rtruediv__(self, other):
         """other / self"""
         raise NotImplementedError
 
     @abstractmethod
     def __pow__(self, exponent):
-        """Like division, self**exponent should promote to complex when necessary."""
+        """self**exponent; should promote to float or complex when necessary."""
         raise NotImplementedError
 
     @abstractmethod
@@ -154,6 +135,7 @@
 
     def __ne__(self, other):
         """self != other"""
+        # The default __ne__ doesn't negate __eq__ until 3.0.
         return not (self == other)
 
 Complex.register(complex)
@@ -180,8 +162,30 @@
         """trunc(self): Truncates self to an Integral.
 
         Returns an Integral i such that:
-          * i>0 iff self>0
-          * abs(i) <= abs(self).
+          * i>0 iff self>0;
+          * abs(i) <= abs(self);
+          * for any Integral j satisfying the first two conditions,
+            abs(i) >= abs(j) [i.e. i has "maximal" abs among those].
+        i.e. "truncate towards 0".
+        """
+        raise NotImplementedError
+
+    @abstractmethod
+    def __floor__(self):
+        """Finds the greatest Integral <= self."""
+        raise NotImplementedError
+
+    @abstractmethod
+    def __ceil__(self):
+        """Finds the least Integral >= self."""
+        raise NotImplementedError
+
+    @abstractmethod
+    def __round__(self, ndigits:"Integral"=None):
+        """Rounds self to ndigits decimal places, defaulting to 0.
+
+        If ndigits is omitted or None, returns an Integral, otherwise
+        returns a Real. Rounds half toward even.
         """
         raise NotImplementedError
 
@@ -241,7 +245,7 @@
     @property
     def real(self):
         """Real numbers are their real component."""
-        return self
+        return +self
 
     @property
     def imag(self):
@@ -250,12 +254,12 @@
 
     def conjugate(self):
         """Conjugate is a no-op for Reals."""
-        return self
+        return +self
 
 Real.register(float)
 
 
-class Rational(Real, Exact):
+class Rational(Real):
     """.numerator and .denominator should be in lowest terms."""
 
     @abstractproperty
@@ -268,7 +272,13 @@
 
     # Concrete implementation of Real's conversion to float.
     def __float__(self):
-        """float(self) = self.numerator / self.denominator"""
+        """float(self) = self.numerator / self.denominator
+
+        It's important that this conversion use the integer's "true"
+        division rather than casting one side to float before dividing
+        so that ratios of huge integers convert without overflowing.
+
+        """
         return self.numerator / self.denominator
 
 
@@ -358,7 +368,7 @@
     @property
     def numerator(self):
         """Integers are their own numerators."""
-        return self
+        return +self
 
     @property
     def denominator(self):

Modified: python/branches/py3k-importlib/Lib/opcode.py
==============================================================================
--- python/branches/py3k-importlib/Lib/opcode.py	(original)
+++ python/branches/py3k-importlib/Lib/opcode.py	Thu Mar 27 00:48:05 2008
@@ -71,6 +71,7 @@
 def_op('INPLACE_FLOOR_DIVIDE', 28)
 def_op('INPLACE_TRUE_DIVIDE', 29)
 
+def_op('STORE_MAP', 54)
 def_op('INPLACE_ADD', 55)
 def_op('INPLACE_SUBTRACT', 56)
 def_op('INPLACE_MULTIPLY', 57)
@@ -111,7 +112,7 @@
 name_op('DELETE_NAME', 91)      # ""
 def_op('UNPACK_SEQUENCE', 92)   # Number of tuple items
 jrel_op('FOR_ITER', 93)
-
+def_op('UNPACK_EX', 94)
 name_op('STORE_ATTR', 95)       # Index in name list
 name_op('DELETE_ATTR', 96)      # ""
 name_op('STORE_GLOBAL', 97)     # ""
@@ -123,7 +124,7 @@
 def_op('BUILD_TUPLE', 102)      # Number of tuple items
 def_op('BUILD_LIST', 103)       # Number of list items
 def_op('BUILD_SET', 104)        # Number of set items
-def_op('BUILD_MAP', 105)        # Always zero for now
+def_op('BUILD_MAP', 105)        # Number of dict entries (upto 255)
 name_op('LOAD_ATTR', 106)       # Index in name list
 def_op('COMPARE_OP', 107)       # Comparison operator
 hascompare.append(107)

Modified: python/branches/py3k-importlib/Lib/optparse.py
==============================================================================
--- python/branches/py3k-importlib/Lib/optparse.py	(original)
+++ python/branches/py3k-importlib/Lib/optparse.py	Thu Mar 27 00:48:05 2008
@@ -636,13 +636,13 @@
         else:
             # Allow type objects or builtin type conversion functions
             # (int, str, etc.) as an alternative to their names.  (The
-            # complicated check of __builtin__ is only necessary for
+            # complicated check of builtins is only necessary for
             # Python 2.1 and earlier, and is short-circuited by the
             # first check on modern Pythons.)
-            import __builtin__
+            import builtins
             if ( isinstance(self.type, type) or
                  (hasattr(self.type, "__name__") and
-                  getattr(__builtin__, self.type.__name__, None) is self.type) ):
+                  getattr(builtins, self.type.__name__, None) is self.type) ):
                 self.type = self.type.__name__
 
             if self.type == "str":
@@ -815,9 +815,6 @@
 SUPPRESS_HELP = "SUPPRESS"+"HELP"
 SUPPRESS_USAGE = "SUPPRESS"+"USAGE"
 
-def isbasestring(x):
-    return isinstance(x, basestring)
-
 class Values:
 
     def __init__(self, defaults=None):
@@ -994,7 +991,7 @@
         """add_option(Option)
            add_option(opt_str, ..., kwarg=val, ...)
         """
-        if isbasestring(args[0]):
+        if isinstance(args[0], str):
             option = self.option_class(*args, **kwargs)
         elif len(args) == 1 and not kwargs:
             option = args[0]
@@ -1294,7 +1291,7 @@
         defaults = self.defaults.copy()
         for option in self._get_all_options():
             default = defaults.get(option.dest)
-            if isbasestring(default):
+            if isinstance(default, str):
                 opt_str = option.get_opt_string()
                 defaults[option.dest] = option.check_value(opt_str, default)
 
@@ -1305,7 +1302,7 @@
 
     def add_option_group(self, *args, **kwargs):
         # XXX lots of overlap with OptionContainer.add_option()
-        if isbasestring(args[0]):
+        if isinstance(args[0], str):
             group = OptionGroup(self, *args, **kwargs)
         elif len(args) == 1 and not kwargs:
             group = args[0]

Modified: python/branches/py3k-importlib/Lib/os.py
==============================================================================
--- python/branches/py3k-importlib/Lib/os.py	(original)
+++ python/branches/py3k-importlib/Lib/os.py	Thu Mar 27 00:48:05 2008
@@ -22,7 +22,7 @@
 
 #'
 
-import sys
+import sys, errno
 
 _names = sys.builtin_module_names
 
@@ -140,7 +140,6 @@
     recursive.
 
     """
-    from errno import EEXIST
     head, tail = path.split(name)
     if not tail:
         head, tail = path.split(head)
@@ -149,7 +148,7 @@
             makedirs(head, mode)
         except OSError as e:
             # be happy if someone already created the path
-            if e.errno != EEXIST:
+            if e.errno != errno.EEXIST:
                 raise
         if tail == curdir:           # xxx/newdir/. exists if xxx/newdir exists
             return
@@ -353,8 +352,6 @@
 __all__.extend(["execl","execle","execlp","execlpe","execvp","execvpe"])
 
 def _execvpe(file, args, env=None):
-    from errno import ENOENT, ENOTDIR
-
     if env is not None:
         func = execve
         argrest = (args, env)
@@ -381,7 +378,7 @@
         except error as e:
             last_exc = e
             tb = sys.exc_info()[2]
-            if (e.errno != ENOENT and e.errno != ENOTDIR
+            if (e.errno != errno.ENOENT and e.errno != errno.ENOTDIR
                 and saved_exc is None):
                 saved_exc = e
                 saved_tb = tb
@@ -636,7 +633,7 @@
 
 # Supply os.popen()
 def popen(cmd, mode="r", buffering=None):
-    if not isinstance(cmd, basestring):
+    if not isinstance(cmd, str):
         raise TypeError("invalid cmd type (%s, expected string)" % type(cmd))
     if mode not in ("r", "w"):
         raise ValueError("invalid mode %r" % mode)

Modified: python/branches/py3k-importlib/Lib/pdb.py
==============================================================================
--- python/branches/py3k-importlib/Lib/pdb.py	(original)
+++ python/branches/py3k-importlib/Lib/pdb.py	Thu Mar 27 00:48:05 2008
@@ -198,7 +198,15 @@
         globals = self.curframe.f_globals
         try:
             code = compile(line + '\n', '<stdin>', 'single')
-            exec(code, globals, locals)
+            save_stdout = sys.stdout
+            save_stdin = sys.stdin
+            try:
+                sys.stdin = self.stdin
+                sys.stdout = self.stdout
+                exec(code, globals, locals)
+            finally:
+                sys.stdout = save_stdout
+                sys.stdin = save_stdin
         except:
             t, v = sys.exc_info()[:2]
             if type(t) == type(''):
@@ -345,8 +353,8 @@
                 except:
                     func = arg
                 try:
-                    if hasattr(func, 'im_func'):
-                        func = func.im_func
+                    if hasattr(func, '__func__'):
+                        func = func.__func__
                     code = func.__code__
                     #use co_name to identify the bkpt (function names
                     #could be aliased, but co_name is invariant)
@@ -656,7 +664,7 @@
         sys.settrace(None)
         globals = self.curframe.f_globals
         locals = self.curframe.f_locals
-        p = Pdb()
+        p = Pdb(self.completekey, self.stdin, self.stdout)
         p.prompt = "(%s) " % self.prompt.strip()
         print("ENTERING RECURSIVE DEBUGGER", file=self.stdout)
         sys.call_tracing(p.run, (arg, globals, locals))
@@ -789,7 +797,7 @@
             print('Function', code.co_name, file=self.stdout)
             return
         # Is it an instance method?
-        try: code = value.im_func.__code__
+        try: code = value.__func__.__code__
         except: pass
         if code:
             print('Method', code.co_name, file=self.stdout)
@@ -909,12 +917,7 @@
 With a space separated list of breakpoint numbers, clear
 those breakpoints.  Without argument, clear all breaks (but
 first ask confirmation).  With a filename:lineno argument,
-clear all breaks at that line in that file.
-
-Note that the argument is different from previous versions of
-the debugger (in python distributions 1.5.1 and before) where
-a linenumber was used instead of either filename:lineno or
-breakpoint numbers.""", file=self.stdout)
+clear all breaks at that line in that file.""", file=self.stdout)
 
     def help_tbreak(self):
         print("""tbreak  same arguments as break, but breakpoint is
@@ -1190,7 +1193,16 @@
 
 # Post-Mortem interface
 
-def post_mortem(t):
+def post_mortem(t=None):
+    # handling the default
+    if t is None:
+        # sys.exc_info() returns (type, value, traceback) if an exception is
+        # being handled, otherwise it returns None
+        t = sys.exc_info()[2]
+        if t is None:
+            raise ValueError("A valid traceback must be passed if no "
+                                               "exception is being handled")
+
     p = Pdb()
     p.reset()
     while t.tb_next is not None:

Modified: python/branches/py3k-importlib/Lib/pickle.py
==============================================================================
--- python/branches/py3k-importlib/Lib/pickle.py	(original)
+++ python/branches/py3k-importlib/Lib/pickle.py	Thu Mar 27 00:48:05 2008
@@ -38,20 +38,26 @@
 __all__ = ["PickleError", "PicklingError", "UnpicklingError", "Pickler",
            "Unpickler", "dump", "dumps", "load", "loads"]
 
+# Shortcut for use in isinstance testing
+bytes_types = (bytes, bytearray, memoryview)
+
 # These are purely informational; no code uses these.
-format_version = "2.0"                  # File format version we write
+format_version = "3.0"                  # File format version we write
 compatible_formats = ["1.0",            # Original protocol 0
                       "1.1",            # Protocol 0 with INST added
                       "1.2",            # Original protocol 1
                       "1.3",            # Protocol 1 with BINFLOAT added
                       "2.0",            # Protocol 2
+                      "3.0",            # Protocol 3
                       ]                 # Old format versions we can read
 
 # This is the highest protocol number we know how to read.
-HIGHEST_PROTOCOL = 2
+HIGHEST_PROTOCOL = 3
 
 # The protocol we write by default.  May be less than HIGHEST_PROTOCOL.
-DEFAULT_PROTOCOL = 2
+# We intentionally write a protocol that Python 2.x cannot read;
+# there are too many issues with that.
+DEFAULT_PROTOCOL = 3
 
 # Why use struct.pack() for pickling but marshal.loads() for
 # unpickling?  struct.pack() is 40% faster than marshal.dumps(), but
@@ -158,6 +164,10 @@
 
 _tuplesize2code = [EMPTY_TUPLE, TUPLE1, TUPLE2, TUPLE3]
 
+# Protocol 3 (Python 3.x)
+
+BINBYTES       = b'B'   # push bytes; counted binary string argument
+SHORT_BINBYTES = b'C'   #  "     "   ;    "      "       "      " < 256 bytes
 
 __all__.extend([x for x in dir() if re.match("[A-Z][A-Z0-9_]+$",x)])
 
@@ -307,7 +317,7 @@
                                         (t.__name__, obj))
 
         # Check for string returned by reduce(), meaning "save as global"
-        if isinstance(rv, basestring):
+        if isinstance(rv, str):
             self.save_global(obj, rv)
             return
 
@@ -491,20 +501,19 @@
             self.write(FLOAT + repr(obj).encode("ascii") + b'\n')
     dispatch[float] = save_float
 
-    def save_string(self, obj, pack=struct.pack):
-        if self.bin:
-            n = len(obj)
-            if n < 256:
-                self.write(SHORT_BINSTRING + bytes([n]) + bytes(obj))
-            else:
-                self.write(BINSTRING + pack("<i", n) + bytes(obj))
+    def save_bytes(self, obj, pack=struct.pack):
+        if self.proto < 3:
+            self.save_reduce(bytes, (list(obj),))
+            return
+        n = len(obj)
+        if n < 256:
+            self.write(SHORT_BINBYTES + bytes([n]) + bytes(obj))
         else:
-            # Strip leading 's' due to repr() of str8() returning s'...'
-            self.write(STRING + repr(obj).lstrip("s").encode("ascii") + b'\n')
+            self.write(BINBYTES + pack("<i", n) + bytes(obj))
         self.memoize(obj)
-    dispatch[str8] = save_string
+    dispatch[bytes] = save_bytes
 
-    def save_unicode(self, obj, pack=struct.pack):
+    def save_str(self, obj, pack=struct.pack):
         if self.bin:
             encoded = obj.encode('utf-8')
             n = len(encoded)
@@ -515,7 +524,7 @@
             self.write(UNICODE + bytes(obj.encode('raw-unicode-escape')) +
                        b'\n')
         self.memoize(obj)
-    dispatch[str] = save_unicode
+    dispatch[str] = save_str
 
     def save_tuple(self, obj):
         write = self.write
@@ -772,7 +781,7 @@
 
 class Unpickler:
 
-    def __init__(self, file):
+    def __init__(self, file, *, encoding="ASCII", errors="strict"):
         """This takes a binary file for reading a pickle data stream.
 
         The protocol version of the pickle is detected automatically, so no
@@ -784,10 +793,16 @@
         Thus file-like object can be a binary file object opened for
         reading, a BytesIO object, or any other custom object that
         meets this interface.
+
+        Optional keyword arguments are encoding and errors, which are
+        used to decode 8-bit string instances pickled by Python 2.x.
+        These default to 'ASCII' and 'strict', respectively.
         """
         self.readline = file.readline
         self.read = file.read
         self.memo = {}
+        self.encoding = encoding
+        self.errors = errors
 
     def load(self):
         """Read a pickled object representation from the open file.
@@ -804,7 +819,7 @@
                 key = read(1)
                 if not key:
                     raise EOFError
-                assert isinstance(key, bytes)
+                assert isinstance(key, bytes_types)
                 dispatch[key[0]](self)
         except _Stop as stopinst:
             return stopinst.value
@@ -828,7 +843,7 @@
 
     def load_proto(self):
         proto = ord(self.read(1))
-        if not 0 <= proto <= 2:
+        if not 0 <= proto <= HIGHEST_PROTOCOL:
             raise ValueError("unsupported pickle protocol: %d" % proto)
     dispatch[PROTO[0]] = load_proto
 
@@ -906,7 +921,8 @@
     dispatch[BINFLOAT[0]] = load_binfloat
 
     def load_string(self):
-        rep = self.readline()[:-1]
+        orig = self.readline()
+        rep = orig[:-1]
         for q in (b'"', b"'"): # double or single quote
             if rep.startswith(q):
                 if not rep.endswith(q):
@@ -914,15 +930,22 @@
                 rep = rep[len(q):-len(q)]
                 break
         else:
-            raise ValueError("insecure string pickle")
-        self.append(str(codecs.escape_decode(rep)[0], "latin-1"))
+            raise ValueError("insecure string pickle: %r" % orig)
+        self.append(codecs.escape_decode(rep)[0])
     dispatch[STRING[0]] = load_string
 
     def load_binstring(self):
         len = mloads(b'i' + self.read(4))
-        self.append(str(self.read(len), "latin-1"))
+        data = self.read(len)
+        value = str(data, self.encoding, self.errors)
+        self.append(value)
     dispatch[BINSTRING[0]] = load_binstring
 
+    def load_binbytes(self):
+        len = mloads(b'i' + self.read(4))
+        self.append(self.read(len))
+    dispatch[BINBYTES[0]] = load_binbytes
+
     def load_unicode(self):
         self.append(str(self.readline()[:-1], 'raw-unicode-escape'))
     dispatch[UNICODE[0]] = load_unicode
@@ -934,9 +957,16 @@
 
     def load_short_binstring(self):
         len = ord(self.read(1))
-        self.append(str(self.read(len), "latin-1"))
+        data = bytes(self.read(len))
+        value = str(data, self.encoding, self.errors)
+        self.append(value)
     dispatch[SHORT_BINSTRING[0]] = load_short_binstring
 
+    def load_short_binbytes(self):
+        len = ord(self.read(1))
+        self.append(bytes(self.read(len)))
+    dispatch[SHORT_BINBYTES[0]] = load_short_binbytes
+
     def load_tuple(self):
         k = self.marker()
         self.stack[k:] = [tuple(self.stack[k+1:])]
@@ -1063,9 +1093,9 @@
 
     def find_class(self, module, name):
         # Subclasses may override this
-        if isinstance(module, bytes):
+        if isinstance(module, bytes_types):
             module = module.decode("utf-8")
-        if isinstance(name, bytes):
+        if isinstance(name, bytes_types):
             name = name.decode("utf-8")
         __import__(module)
         mod = sys.modules[module]
@@ -1099,7 +1129,7 @@
     dispatch[DUP[0]] = load_dup
 
     def load_get(self):
-        self.append(self.memo[str(self.readline())[:-1]])
+        self.append(self.memo[self.readline()[:-1].decode("ascii")])
     dispatch[GET[0]] = load_get
 
     def load_binget(self):
@@ -1113,7 +1143,7 @@
     dispatch[LONG_BINGET[0]] = load_long_binget
 
     def load_put(self):
-        self.memo[str(self.readline()[:-1])] = self.stack[-1]
+        self.memo[self.readline()[:-1].decode("ascii")] = self.stack[-1]
     dispatch[PUT[0]] = load_put
 
     def load_binput(self):
@@ -1298,7 +1328,7 @@
     f = io.BytesIO()
     Pickler(f, protocol).dump(obj)
     res = f.getvalue()
-    assert isinstance(res, bytes)
+    assert isinstance(res, bytes_types)
     return res
 
 def load(file):

Modified: python/branches/py3k-importlib/Lib/pickletools.py
==============================================================================
--- python/branches/py3k-importlib/Lib/pickletools.py	(original)
+++ python/branches/py3k-importlib/Lib/pickletools.py	Thu Mar 27 00:48:05 2008
@@ -11,10 +11,12 @@
 '''
 
 import codecs
+import pickle
+import re
 
-__all__ = ['dis',
-           'genops',
-          ]
+__all__ = ['dis', 'genops', 'optimize']
+
+bytes_types = pickle.bytes_types
 
 # Other ideas:
 #
@@ -307,7 +309,7 @@
             raise ValueError("no string quotes around %r" % data)
 
     if decode:
-        data = str(codecs.escape_decode(data)[0])
+        data = codecs.escape_decode(data)[0].decode("ascii")
     return data
 
 stringnl = ArgumentDescriptor(
@@ -321,7 +323,7 @@
                    """)
 
 def read_stringnl_noescape(f):
-    return read_stringnl(f, decode=False, stripquotes=False)
+    return read_stringnl(f, stripquotes=False)
 
 stringnl_noescape = ArgumentDescriptor(
                         name='stringnl_noescape',
@@ -701,7 +703,7 @@
     )
 
     def __init__(self, name, obtype, doc):
-        assert isinstance(name, basestring)
+        assert isinstance(name, str)
         self.name = name
 
         assert isinstance(obtype, type) or isinstance(obtype, tuple)
@@ -710,7 +712,7 @@
                 assert isinstance(contained, type)
         self.obtype = obtype
 
-        assert isinstance(doc, basestring)
+        assert isinstance(doc, str)
         self.doc = doc
 
     def __repr__(self):
@@ -744,14 +746,19 @@
               doc="A Python float object.")
 
 pystring = StackObject(
-               name='str',
-               obtype=str,
-               doc="A Python string object.")
+               name='string',
+               obtype=bytes,
+               doc="A Python (8-bit) string object.")
+
+pybytes = StackObject(
+               name='bytes',
+               obtype=bytes,
+               doc="A Python bytes object.")
 
 pyunicode = StackObject(
-                name='unicode',
+                name='str',
                 obtype=str,
-                doc="A Python Unicode string object.")
+                doc="A Python (Unicode) string object.")
 
 pynone = StackObject(
              name="None",
@@ -846,10 +853,10 @@
 
     def __init__(self, name, code, arg,
                  stack_before, stack_after, proto, doc):
-        assert isinstance(name, basestring)
+        assert isinstance(name, str)
         self.name = name
 
-        assert isinstance(code, basestring)
+        assert isinstance(code, str)
         assert len(code) == 1
         self.code = code
 
@@ -866,10 +873,10 @@
             assert isinstance(x, StackObject)
         self.stack_after = stack_after
 
-        assert isinstance(proto, int) and 0 <= proto <= 2
+        assert isinstance(proto, int) and 0 <= proto <= 3
         self.proto = proto
 
-        assert isinstance(doc, basestring)
+        assert isinstance(doc, str)
         self.doc = doc
 
 I = OpcodeInfo
@@ -993,7 +1000,9 @@
 
       The argument is a repr-style string, with bracketing quote characters,
       and perhaps embedded escapes.  The argument extends until the next
-      newline character.
+      newline character.  (Actually, they are decoded into a str instance
+      using the encoding given to the Unpickler constructor. or the default,
+      'ASCII'.)
       """),
 
     I(name='BINSTRING',
@@ -1006,7 +1015,9 @@
 
       There are two arguments:  the first is a 4-byte little-endian signed int
       giving the number of bytes in the string, and the second is that many
-      bytes, which are taken literally as the string content.
+      bytes, which are taken literally as the string content.  (Actually,
+      they are decoded into a str instance using the encoding given to the
+      Unpickler constructor. or the default, 'ASCII'.)
       """),
 
     I(name='SHORT_BINSTRING',
@@ -1019,6 +1030,36 @@
 
       There are two arguments:  the first is a 1-byte unsigned int giving
       the number of bytes in the string, and the second is that many bytes,
+      which are taken literally as the string content.  (Actually, they
+      are decoded into a str instance using the encoding given to the
+      Unpickler constructor. or the default, 'ASCII'.)
+      """),
+
+    # Bytes (protocol 3 only; older protocols don't support bytes at all)
+
+    I(name='BINBYTES',
+      code='B',
+      arg=string4,
+      stack_before=[],
+      stack_after=[pybytes],
+      proto=3,
+      doc="""Push a Python bytes object.
+
+      There are two arguments:  the first is a 4-byte little-endian signed int
+      giving the number of bytes in the string, and the second is that many
+      bytes, which are taken literally as the bytes content.
+      """),
+
+    I(name='SHORT_BINBYTES',
+      code='C',
+      arg=string1,
+      stack_before=[],
+      stack_after=[pybytes],
+      proto=1,
+      doc="""Push a Python string object.
+
+      There are two arguments:  the first is a 1-byte unsigned int giving
+      the number of bytes in the string, and the second is that many bytes,
       which are taken literally as the string content.
       """),
 
@@ -1735,7 +1776,6 @@
 del d
 
 def assure_pickle_consistency(verbose=False):
-    import pickle, re
 
     copy = code2op.copy()
     for name in pickle.__all__:
@@ -1803,7 +1843,7 @@
     to query its current position) pos is None.
     """
 
-    if isinstance(pickle, bytes):
+    if isinstance(pickle, bytes_types):
         import io
         pickle = io.BytesIO(pickle)
 
@@ -1833,6 +1873,33 @@
             break
 
 ##############################################################################
+# A pickle optimizer.
+
+def optimize(p):
+    'Optimize a pickle string by removing unused PUT opcodes'
+    gets = set()            # set of args used by a GET opcode
+    puts = []               # (arg, startpos, stoppos) for the PUT opcodes
+    prevpos = None          # set to pos if previous opcode was a PUT
+    for opcode, arg, pos in genops(p):
+        if prevpos is not None:
+            puts.append((prevarg, prevpos, pos))
+            prevpos = None
+        if 'PUT' in opcode.name:
+            prevarg, prevpos = arg, pos
+        elif 'GET' in opcode.name:
+            gets.add(arg)
+
+    # Copy the pickle string except for PUTS without a corresponding GET
+    s = []
+    i = 0
+    for arg, start, stop in puts:
+        j = stop if (arg in gets) else start
+        s.append(p[i:j])
+        i = stop
+    s.append(p[i:])
+    return b''.join(s)
+
+##############################################################################
 # A symbolic pickle disassembler.
 
 def dis(pickle, out=None, memo=None, indentlevel=4):
@@ -1978,9 +2045,9 @@
 
 _dis_test = r"""
 >>> import pickle
->>> x = [1, 2, (3, 4), {str8('abc'): "def"}]
->>> pkl = pickle.dumps(x, 0)
->>> dis(pkl)
+>>> x = [1, 2, (3, 4), {b'abc': "def"}]
+>>> pkl0 = pickle.dumps(x, 0)
+>>> dis(pkl0)
     0: (    MARK
     1: l        LIST       (MARK at 0)
     2: p    PUT        0
@@ -1997,19 +2064,32 @@
    25: (    MARK
    26: d        DICT       (MARK at 25)
    27: p    PUT        2
-   30: S    STRING     'abc'
-   37: p    PUT        3
-   40: V    UNICODE    'def'
-   45: p    PUT        4
-   48: s    SETITEM
-   49: a    APPEND
-   50: .    STOP
+   30: c    GLOBAL     'builtins bytes'
+   46: p    PUT        3
+   49: (    MARK
+   50: (        MARK
+   51: l            LIST       (MARK at 50)
+   52: p        PUT        4
+   55: L        LONG       97
+   59: a        APPEND
+   60: L        LONG       98
+   64: a        APPEND
+   65: L        LONG       99
+   69: a        APPEND
+   70: t        TUPLE      (MARK at 49)
+   71: p    PUT        5
+   74: R    REDUCE
+   75: V    UNICODE    'def'
+   80: p    PUT        6
+   83: s    SETITEM
+   84: a    APPEND
+   85: .    STOP
 highest protocol among opcodes = 0
 
 Try again with a "binary" pickle.
 
->>> pkl = pickle.dumps(x, 1)
->>> dis(pkl)
+>>> pkl1 = pickle.dumps(x, 1)
+>>> dis(pkl1)
     0: ]    EMPTY_LIST
     1: q    BINPUT     0
     3: (    MARK
@@ -2022,13 +2102,24 @@
    14: q        BINPUT     1
    16: }        EMPTY_DICT
    17: q        BINPUT     2
-   19: U        SHORT_BINSTRING 'abc'
-   24: q        BINPUT     3
-   26: X        BINUNICODE 'def'
-   34: q        BINPUT     4
-   36: s        SETITEM
-   37: e        APPENDS    (MARK at 3)
-   38: .    STOP
+   19: c        GLOBAL     'builtins bytes'
+   35: q        BINPUT     3
+   37: (        MARK
+   38: ]            EMPTY_LIST
+   39: q            BINPUT     4
+   41: (            MARK
+   42: K                BININT1    97
+   44: K                BININT1    98
+   46: K                BININT1    99
+   48: e                APPENDS    (MARK at 41)
+   49: t            TUPLE      (MARK at 37)
+   50: q        BINPUT     5
+   52: R        REDUCE
+   53: X        BINUNICODE 'def'
+   61: q        BINPUT     6
+   63: s        SETITEM
+   64: e        APPENDS    (MARK at 3)
+   65: .    STOP
 highest protocol among opcodes = 1
 
 Exercise the INST/OBJ/BUILD family.
@@ -2051,25 +2142,25 @@
    33: (    MARK
    34: c        GLOBAL     'pickletools _Example'
    56: p        PUT        2
-   59: c        GLOBAL     '__builtin__ object'
-   79: p        PUT        3
-   82: N        NONE
-   83: t        TUPLE      (MARK at 33)
-   84: p    PUT        4
-   87: R    REDUCE
-   88: p    PUT        5
-   91: (    MARK
-   92: d        DICT       (MARK at 91)
-   93: p    PUT        6
-   96: V    UNICODE    'value'
-  103: p    PUT        7
-  106: L    LONG       42
-  110: s    SETITEM
-  111: b    BUILD
-  112: a    APPEND
-  113: g    GET        5
-  116: a    APPEND
-  117: .    STOP
+   59: c        GLOBAL     'builtins object'
+   76: p        PUT        3
+   79: N        NONE
+   80: t        TUPLE      (MARK at 33)
+   81: p    PUT        4
+   84: R    REDUCE
+   85: p    PUT        5
+   88: (    MARK
+   89: d        DICT       (MARK at 88)
+   90: p    PUT        6
+   93: V    UNICODE    'value'
+  100: p    PUT        7
+  103: L    LONG       42
+  107: s    SETITEM
+  108: b    BUILD
+  109: a    APPEND
+  110: g    GET        5
+  113: a    APPEND
+  114: .    STOP
 highest protocol among opcodes = 0
 
 >>> dis(pickle.dumps(x, 1))
@@ -2081,23 +2172,23 @@
    31: (        MARK
    32: c            GLOBAL     'pickletools _Example'
    54: q            BINPUT     2
-   56: c            GLOBAL     '__builtin__ object'
-   76: q            BINPUT     3
-   78: N            NONE
-   79: t            TUPLE      (MARK at 31)
-   80: q        BINPUT     4
-   82: R        REDUCE
-   83: q        BINPUT     5
-   85: }        EMPTY_DICT
-   86: q        BINPUT     6
-   88: X        BINUNICODE 'value'
-   98: q        BINPUT     7
-  100: K        BININT1    42
-  102: s        SETITEM
-  103: b        BUILD
-  104: h        BINGET     5
-  106: e        APPENDS    (MARK at 3)
-  107: .    STOP
+   56: c            GLOBAL     'builtins object'
+   73: q            BINPUT     3
+   75: N            NONE
+   76: t            TUPLE      (MARK at 31)
+   77: q        BINPUT     4
+   79: R        REDUCE
+   80: q        BINPUT     5
+   82: }        EMPTY_DICT
+   83: q        BINPUT     6
+   85: X        BINUNICODE 'value'
+   95: q        BINPUT     7
+   97: K        BININT1    42
+   99: s        SETITEM
+  100: b        BUILD
+  101: h        BINGET     5
+  103: e        APPENDS    (MARK at 3)
+  104: .    STOP
 highest protocol among opcodes = 1
 
 Try "the canonical" recursive-object test.

Modified: python/branches/py3k-importlib/Lib/pkgutil.py
==============================================================================
--- python/branches/py3k-importlib/Lib/pkgutil.py	(original)
+++ python/branches/py3k-importlib/Lib/pkgutil.py	Thu Mar 27 00:48:05 2008
@@ -516,7 +516,7 @@
     path = path[:] # Start with a copy of the existing path
 
     for dir in sys.path:
-        if not isinstance(dir, basestring) or not os.path.isdir(dir):
+        if not isinstance(dir, str) or not os.path.isdir(dir):
             continue
         subdir = os.path.join(dir, pname)
         # XXX This may still add duplicate entries to path on

Modified: python/branches/py3k-importlib/Lib/plat-freebsd6/IN.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-freebsd6/IN.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-freebsd6/IN.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,28 @@
 # Generated by h2py from /usr/include/netinet/in.h
 
 # Included from sys/cdefs.h
+__GNUCLIKE_ASM = 3
+__GNUCLIKE_ASM = 2
+__GNUCLIKE___TYPEOF = 1
+__GNUCLIKE___OFFSETOF = 1
+__GNUCLIKE___SECTION = 1
+__GNUCLIKE_ATTRIBUTE_MODE_DI = 1
+__GNUCLIKE_CTOR_SECTION_HANDLING = 1
+__GNUCLIKE_BUILTIN_CONSTANT_P = 1
+__GNUCLIKE_BUILTIN_VARARGS = 1
+__GNUCLIKE_BUILTIN_STDARG = 1
+__GNUCLIKE_BUILTIN_VAALIST = 1
+__GNUC_VA_LIST_COMPATIBILITY = 1
+__GNUCLIKE_BUILTIN_NEXT_ARG = 1
+__GNUCLIKE_BUILTIN_MEMCPY = 1
+__CC_SUPPORTS_INLINE = 1
+__CC_SUPPORTS___INLINE = 1
+__CC_SUPPORTS___INLINE__ = 1
+__CC_SUPPORTS___FUNC__ = 1
+__CC_SUPPORTS_WARNING = 1
+__CC_SUPPORTS_VARADIC_XXX = 1
+__CC_SUPPORTS_DYNAMIC_ARRAY_INIT = 1
+__CC_INT_IS_32BIT = 1
 def __P(protos): return protos
 
 def __STRING(x): return #x
@@ -29,6 +51,8 @@
 
 def __predict_false(exp): return (exp)
 
+def __format_arg(fmtarg): return __attribute__((__format_arg__ (fmtarg)))
+
 def __FBSDID(s): return __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
 
 def __RCSID(s): return __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
@@ -86,8 +110,6 @@
 BIG_ENDIAN = _BIG_ENDIAN
 PDP_ENDIAN = _PDP_ENDIAN
 BYTE_ORDER = _BYTE_ORDER
-__INTEL_COMPILER_with_FreeBSD_endian = 1
-__INTEL_COMPILER_with_FreeBSD_endian = 1
 def __word_swap_int_var(x): return \
 
 def __word_swap_int_const(x): return \
@@ -96,12 +118,16 @@
 
 def __byte_swap_int_var(x): return \
 
-def __byte_swap_int_var(x): return \
-
 def __byte_swap_int_const(x): return \
 
 def __byte_swap_int(x): return __byte_swap_int_var(x)
 
+def __byte_swap_long_var(x): return \
+
+def __byte_swap_long_const(x): return \
+
+def __byte_swap_long(x): return __byte_swap_long_var(x)
+
 def __byte_swap_word_var(x): return \
 
 def __byte_swap_word_const(x): return \
@@ -229,47 +255,50 @@
 IPPROTO_APES = 99
 IPPROTO_GMTP = 100
 IPPROTO_IPCOMP = 108
+IPPROTO_SCTP = 132
 IPPROTO_PIM = 103
+IPPROTO_CARP = 112
 IPPROTO_PGM = 113
 IPPROTO_PFSYNC = 240
 IPPROTO_OLD_DIVERT = 254
 IPPROTO_MAX = 256
 IPPROTO_DONE = 257
 IPPROTO_DIVERT = 258
+IPPROTO_SPACER = 32767
 IPPORT_RESERVED = 1024
 IPPORT_HIFIRSTAUTO = 49152
 IPPORT_HILASTAUTO = 65535
 IPPORT_RESERVEDSTART = 600
 IPPORT_MAX = 65535
-def IN_CLASSA(i): return (((u_int32_t)(i) & (-2147483648)) == 0)
+def IN_CLASSA(i): return (((u_int32_t)(i) & 0x80000000) == 0)
 
-IN_CLASSA_NET = (-16777216)
+IN_CLASSA_NET = 0xff000000
 IN_CLASSA_NSHIFT = 24
 IN_CLASSA_HOST = 0x00ffffff
 IN_CLASSA_MAX = 128
-def IN_CLASSB(i): return (((u_int32_t)(i) & (-1073741824)) == (-2147483648))
+def IN_CLASSB(i): return (((u_int32_t)(i) & 0xc0000000) == 0x80000000)
 
-IN_CLASSB_NET = (-65536)
+IN_CLASSB_NET = 0xffff0000
 IN_CLASSB_NSHIFT = 16
 IN_CLASSB_HOST = 0x0000ffff
 IN_CLASSB_MAX = 65536
-def IN_CLASSC(i): return (((u_int32_t)(i) & (-536870912)) == (-1073741824))
+def IN_CLASSC(i): return (((u_int32_t)(i) & 0xe0000000) == 0xc0000000)
 
-IN_CLASSC_NET = (-256)
+IN_CLASSC_NET = 0xffffff00
 IN_CLASSC_NSHIFT = 8
 IN_CLASSC_HOST = 0x000000ff
-def IN_CLASSD(i): return (((u_int32_t)(i) & (-268435456)) == (-536870912))
+def IN_CLASSD(i): return (((u_int32_t)(i) & 0xf0000000) == 0xe0000000)
 
-IN_CLASSD_NET = (-268435456)
+IN_CLASSD_NET = 0xf0000000
 IN_CLASSD_NSHIFT = 28
 IN_CLASSD_HOST = 0x0fffffff
 def IN_MULTICAST(i): return IN_CLASSD(i)
 
-def IN_EXPERIMENTAL(i): return (((u_int32_t)(i) & (-268435456)) == (-268435456))
+def IN_EXPERIMENTAL(i): return (((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
 
-def IN_BADCLASS(i): return (((u_int32_t)(i) & (-268435456)) == (-268435456))
+def IN_BADCLASS(i): return (((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
 
-INADDR_NONE = (-1)
+INADDR_NONE = 0xffffffff
 IN_LOOPBACKNET = 127
 IP_OPTIONS = 1
 IP_HDRINCL = 2
@@ -311,6 +340,8 @@
 IP_DUMMYNET_FLUSH = 62
 IP_DUMMYNET_GET = 64
 IP_RECVTTL = 65
+IP_MINTTL = 66
+IP_DONTFRAG = 67
 IP_DEFAULT_MULTICAST_TTL = 1
 IP_DEFAULT_MULTICAST_LOOP = 1
 IP_MAX_MEMBERSHIPS = 20
@@ -339,7 +370,7 @@
 
 
 # Included from netinet6/in6.h
-__KAME_VERSION = "20010528/FreeBSD"
+__KAME_VERSION = "FreeBSD"
 IPV6PORT_RESERVED = 1024
 IPV6PORT_ANONMIN = 49152
 IPV6PORT_ANONMAX = 65535
@@ -348,8 +379,8 @@
 INET6_ADDRSTRLEN = 46
 IPV6_ADDR_INT32_ONE = 1
 IPV6_ADDR_INT32_TWO = 2
-IPV6_ADDR_INT32_MNL = (-16711680)
-IPV6_ADDR_INT32_MLL = (-16646144)
+IPV6_ADDR_INT32_MNL = 0xff010000
+IPV6_ADDR_INT32_MLL = 0xff020000
 IPV6_ADDR_INT32_SMP = 0x0000ffff
 IPV6_ADDR_INT16_ULL = 0xfe80
 IPV6_ADDR_INT16_USL = 0xfec0
@@ -358,7 +389,7 @@
 IPV6_ADDR_INT32_TWO = 0x02000000
 IPV6_ADDR_INT32_MNL = 0x000001ff
 IPV6_ADDR_INT32_MLL = 0x000002ff
-IPV6_ADDR_INT32_SMP = (-65536)
+IPV6_ADDR_INT32_SMP = 0xffff0000
 IPV6_ADDR_INT16_ULL = 0x80fe
 IPV6_ADDR_INT16_USL = 0xc0fe
 IPV6_ADDR_INT16_MLL = 0x02ff
@@ -511,5 +542,10 @@
 IPV6CTL_RIP6STATS = 36
 IPV6CTL_PREFER_TEMPADDR = 37
 IPV6CTL_ADDRCTLPOLICY = 38
+IPV6CTL_USE_DEFAULTZONE = 39
 IPV6CTL_MAXFRAGS = 41
-IPV6CTL_MAXID = 42
+IPV6CTL_IFQ = 42
+IPV6CTL_ISATAPRTR = 43
+IPV6CTL_MCAST_PMTU = 44
+IPV6CTL_STEALTH = 45
+IPV6CTL_MAXID = 46

Modified: python/branches/py3k-importlib/Lib/plat-freebsd7/IN.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-freebsd7/IN.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-freebsd7/IN.py	Thu Mar 27 00:48:05 2008
@@ -10,9 +10,9 @@
 __GNUCLIKE_CTOR_SECTION_HANDLING = 1
 __GNUCLIKE_BUILTIN_CONSTANT_P = 1
 __GNUCLIKE_BUILTIN_VARARGS = 1
+__GNUCLIKE_BUILTIN_STDARG = 1
 __GNUCLIKE_BUILTIN_VAALIST = 1
 __GNUC_VA_LIST_COMPATIBILITY = 1
-__GNUCLIKE_BUILTIN_STDARG = 1
 __GNUCLIKE_BUILTIN_NEXT_ARG = 1
 __GNUCLIKE_BUILTIN_MEMCPY = 1
 __CC_SUPPORTS_INLINE = 1
@@ -51,6 +51,8 @@
 
 def __predict_false(exp): return (exp)
 
+def __format_arg(fmtarg): return __attribute__((__format_arg__ (fmtarg)))
+
 def __FBSDID(s): return __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
 
 def __RCSID(s): return __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
@@ -247,6 +249,7 @@
 IPPROTO_APES = 99
 IPPROTO_GMTP = 100
 IPPROTO_IPCOMP = 108
+IPPROTO_SCTP = 132
 IPPROTO_PIM = 103
 IPPROTO_CARP = 112
 IPPROTO_PGM = 113
@@ -289,6 +292,10 @@
 
 def IN_BADCLASS(i): return (((u_int32_t)(i) & (-268435456)) == (-268435456))
 
+def IN_LINKLOCAL(i): return (((u_int32_t)(i) & (-65536)) == (-1442971648))
+
+def IN_LOCAL_GROUP(i): return (((u_int32_t)(i) & (-256)) == (-536870912))
+
 INADDR_NONE = (-1)
 IN_LOOPBACKNET = 127
 IP_OPTIONS = 1
@@ -326,14 +333,35 @@
 IP_FW_ZERO = 53
 IP_FW_GET = 54
 IP_FW_RESETLOG = 55
+IP_FW_NAT_CFG = 56
+IP_FW_NAT_DEL = 57
+IP_FW_NAT_GET_CONFIG = 58
+IP_FW_NAT_GET_LOG = 59
 IP_DUMMYNET_CONFIGURE = 60
 IP_DUMMYNET_DEL = 61
 IP_DUMMYNET_FLUSH = 62
 IP_DUMMYNET_GET = 64
 IP_RECVTTL = 65
+IP_MINTTL = 66
+IP_DONTFRAG = 67
+IP_ADD_SOURCE_MEMBERSHIP = 70
+IP_DROP_SOURCE_MEMBERSHIP = 71
+IP_BLOCK_SOURCE = 72
+IP_UNBLOCK_SOURCE = 73
+IP_MSFILTER = 74
+MCAST_JOIN_GROUP = 80
+MCAST_LEAVE_GROUP = 81
+MCAST_JOIN_SOURCE_GROUP = 82
+MCAST_LEAVE_SOURCE_GROUP = 83
+MCAST_BLOCK_SOURCE = 84
+MCAST_UNBLOCK_SOURCE = 85
 IP_DEFAULT_MULTICAST_TTL = 1
 IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MAX_MEMBERSHIPS = 20
+IP_MIN_MEMBERSHIPS = 31
+IP_MAX_MEMBERSHIPS = 4095
+IP_MAX_SOURCE_FILTER = 1024
+MCAST_INCLUDE = 1
+MCAST_EXCLUDE = 2
 IP_PORTRANGE_DEFAULT = 0
 IP_PORTRANGE_HIGH = 1
 IP_PORTRANGE_LOW = 2
@@ -359,7 +387,7 @@
 
 
 # Included from netinet6/in6.h
-__KAME_VERSION = "20010528/FreeBSD"
+__KAME_VERSION = "FreeBSD"
 IPV6PORT_RESERVED = 1024
 IPV6PORT_ANONMIN = 49152
 IPV6PORT_ANONMAX = 65535
@@ -430,6 +458,8 @@
 
 def IN6_IS_SCOPE_LINKLOCAL(a): return \
 
+def IN6_IS_SCOPE_EMBED(a): return \
+
 def IFA6_IS_DEPRECATED(a): return \
 
 def IFA6_IS_INVALID(a): return \
@@ -488,6 +518,7 @@
 IPV6_TCLASS = 61
 IPV6_DONTFRAG = 62
 IPV6_PREFER_TEMPADDR = 63
+IPV6_MSFILTER = 74
 IPV6_RTHDR_LOOSE = 0
 IPV6_RTHDR_STRICT = 1
 IPV6_RTHDR_TYPE_0 = 0
@@ -531,5 +562,10 @@
 IPV6CTL_RIP6STATS = 36
 IPV6CTL_PREFER_TEMPADDR = 37
 IPV6CTL_ADDRCTLPOLICY = 38
+IPV6CTL_USE_DEFAULTZONE = 39
 IPV6CTL_MAXFRAGS = 41
-IPV6CTL_MAXID = 42
+IPV6CTL_IFQ = 42
+IPV6CTL_ISATAPRTR = 43
+IPV6CTL_MCAST_PMTU = 44
+IPV6CTL_STEALTH = 45
+IPV6CTL_MAXID = 46

Modified: python/branches/py3k-importlib/Lib/plat-mac/EasyDialogs.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-mac/EasyDialogs.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-mac/EasyDialogs.py	Thu Mar 27 00:48:05 2008
@@ -651,7 +651,7 @@
         rr = Nav.NavChooseFile(args)
         good = 1
     except Nav.error as arg:
-        if arg[0] != -128: # userCancelledErr
+        if arg.args[0] != -128: # userCancelledErr
             raise Nav.error(arg)
         return None
     if not rr.validRecord or not rr.selection:
@@ -704,7 +704,7 @@
         rr = Nav.NavPutFile(args)
         good = 1
     except Nav.error as arg:
-        if arg[0] != -128: # userCancelledErr
+        if arg.args[0] != -128: # userCancelledErr
             raise Nav.error(arg)
         return None
     if not rr.validRecord or not rr.selection:
@@ -764,7 +764,7 @@
         rr = Nav.NavChooseFolder(args)
         good = 1
     except Nav.error as arg:
-        if arg[0] != -128: # userCancelledErr
+        if arg.args[0] != -128: # userCancelledErr
             raise Nav.error(arg)
         return None
     if not rr.validRecord or not rr.selection:

Modified: python/branches/py3k-importlib/Lib/plat-mac/MiniAEFrame.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-mac/MiniAEFrame.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-mac/MiniAEFrame.py	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,6 @@
         only suitable for the simplest of AppleEvent servers.
 """
 
-import sys
 import traceback
 import MacOS
 from Carbon import AE

Modified: python/branches/py3k-importlib/Lib/plat-mac/aepack.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-mac/aepack.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-mac/aepack.py	Thu Mar 27 00:48:05 2008
@@ -20,7 +20,6 @@
 import io
 import aetypes
 from aetypes import mkenum, ObjectSpecifier
-import os
 
 # These ones seem to be missing from AppleEvents
 # (they're in AERegistry.h)
@@ -98,7 +97,7 @@
         return AE.AECreateDesc(b'long', struct.pack('l', x))
     if isinstance(x, float):
         return AE.AECreateDesc(b'doub', struct.pack('d', x))
-    if isinstance(x, (bytes, str8)):
+    if isinstance(x, (bytes, bytearray)):
         return AE.AECreateDesc(b'TEXT', x)
     if isinstance(x, str):
         # See http://developer.apple.com/documentation/Carbon/Reference/Apple_Event_Manager/Reference/reference.html#//apple_ref/doc/constant_group/typeUnicodeText

Modified: python/branches/py3k-importlib/Lib/plat-mac/aetools.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-mac/aetools.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-mac/aetools.py	Thu Mar 27 00:48:05 2008
@@ -86,7 +86,7 @@
         try:
             desc = ae.AEGetAttributeDesc(key, '****')
         except (AE.Error, MacOS.Error) as msg:
-            if msg[0] != -1701 and msg[0] != -1704:
+            if msg.args[0] not in (-1701, -1704):
                 raise
             continue
         attributes[key] = unpack(desc, formodulename)

Modified: python/branches/py3k-importlib/Lib/plat-mac/aetypes.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-mac/aetypes.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-mac/aetypes.py	Thu Mar 27 00:48:05 2008
@@ -22,7 +22,18 @@
     four_chars must contain only ASCII characters.
 
     """
-    return ("%-4.4s" % str(four_chars)).encode("latin-1")
+    if isinstance(four_chars, (bytes, bytearray)):
+        b = bytes(four_chars[:4])
+        n = len(b)
+        if n < 4:
+            b += b' ' * (4 - n)
+        return b
+    else:
+        s = str(four_chars)[:4]
+        n = len(s)
+        if n < 4:
+            s += ' ' * (4 - n)
+        return bytes(s, "latin-1")  # MacRoman?
 
 class Unknown:
     """An uninterpreted AE object"""
@@ -47,7 +58,7 @@
         return "Enum(%r)" % (self.enum,)
 
     def __str__(self):
-        return self.enum.strip(b' ')
+        return self.enum.decode("latin-1").strip(" ")
 
     def __aepack__(self):
         return pack(self.enum, typeEnumeration)
@@ -559,7 +570,7 @@
         return "selector for element %s of %s"%(self.__class__.__name__, str(self.fr))
 
 template = """
-class %s(ComponentItem): want = '%s'
+class %s(ComponentItem): want = %r
 """
 
 exec(template % ("Text", b'text'))

Modified: python/branches/py3k-importlib/Lib/plat-mac/bgenlocations.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-mac/bgenlocations.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-mac/bgenlocations.py	Thu Mar 27 00:48:05 2008
@@ -5,7 +5,7 @@
 # but mac-style for MacPython, whether running on OS9 or OSX.
 #
 
-import sys, os
+import os
 
 Error = "bgenlocations.Error"
 #

Modified: python/branches/py3k-importlib/Lib/plat-mac/gensuitemodule.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-mac/gensuitemodule.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-mac/gensuitemodule.py	Thu Mar 27 00:48:05 2008
@@ -191,7 +191,7 @@
     try:
         aedescobj, launched = OSATerminology.GetAppTerminology(fullname)
     except MacOS.Error as arg:
-        if arg[0] in (-1701, -192): # errAEDescNotFound, resNotFound
+        if arg.args[0] in (-1701, -192): # errAEDescNotFound, resNotFound
             if verbose:
                 print("GetAppTerminology failed with errAEDescNotFound/resNotFound, trying manually", file=verbose)
             aedata, sig = getappterminology(fullname, verbose=verbose)

Modified: python/branches/py3k-importlib/Lib/plat-mac/ic.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-mac/ic.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-mac/ic.py	Thu Mar 27 00:48:05 2008
@@ -41,31 +41,31 @@
 def _decode_default(data, key):
     if len(data) == 0:
         return data
-    if ord(data[0]) == len(data)-1:
+    if data[0] == len(data)-1:
         # Assume Pstring
         return data[1:]
     return ICOpaqueData(data)
 
 
 def _decode_multistr(data, key):
-    numstr = ord(data[0]) << 8 | ord(data[1])
+    numstr = data[0] << 8 | data[1]
     rv = []
     ptr = 2
     for i in range(numstr):
-        strlen = ord(data[ptr])
+        strlen = data[ptr]
         str = data[ptr+1:ptr+strlen+1]
         rv.append(str)
         ptr = ptr + strlen + 1
     return rv
 
 def _decode_fontrecord(data, key):
-    size = ord(data[0]) << 8 | ord(data[1])
-    face = ord(data[2])
-    namelen = ord(data[4])
+    size = data[0] << 8 | data[1]
+    face = data[2]
+    namelen = data[4]
     return size, face, data[5:5+namelen]
 
 def _decode_boolean(data, key):
-    return ord(data[0])
+    return data[0]
 
 def _decode_text(data, key):
     return data
@@ -74,7 +74,7 @@
     return data[:256], data[256:]
 
 def _decode_appspec(data, key):
-    namelen = ord(data[4])
+    namelen = data[4]
     return data[0:4], data[5:5+namelen]
 
 def _code_default(data, key):

Modified: python/branches/py3k-importlib/Lib/plat-mac/icopen.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-mac/icopen.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-mac/icopen.py	Thu Mar 27 00:48:05 2008
@@ -37,9 +37,9 @@
 effect.
 """
 
-import __builtin__
+import builtins
 
-_builtin_open = globals().get('_builtin_open', __builtin__.open)
+_builtin_open = globals().get('_builtin_open', builtins.open)
 
 def _open_with_typer(*args):
     file = _builtin_open(*args)
@@ -55,7 +55,7 @@
             pass
     return file
 
-__builtin__.open = _open_with_typer
+builtins.open = _open_with_typer
 
 """
 open('test.py')

Modified: python/branches/py3k-importlib/Lib/plat-mac/macostools.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-mac/macostools.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-mac/macostools.py	Thu Mar 27 00:48:05 2008
@@ -7,9 +7,7 @@
 from Carbon import Res
 from Carbon import File, Files
 import os
-import sys
 import MacOS
-import time
 try:
     openrf = MacOS.openrf
 except AttributeError:

Deleted: /python/branches/py3k-importlib/Lib/plat-mac/plistlib.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/plat-mac/plistlib.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,469 +0,0 @@
-"""plistlib.py -- a tool to generate and parse MacOSX .plist files.
-
-The PropertList (.plist) file format is a simple XML pickle supporting
-basic object types, like dictionaries, lists, numbers and strings.
-Usually the top level object is a dictionary.
-
-To write out a plist file, use the writePlist(rootObject, pathOrFile)
-function. 'rootObject' is the top level object, 'pathOrFile' is a
-filename or a (writable) file object.
-
-To parse a plist from a file, use the readPlist(pathOrFile) function,
-with a file name or a (readable) file object as the only argument. It
-returns the top level object (again, usually a dictionary).
-
-To work with plist data in bytes objects, you can use readPlistFromBytes()
-and writePlistToBytes().
-
-Values can be strings, integers, floats, booleans, tuples, lists,
-dictionaries, Data or datetime.datetime objects. String values (including
-dictionary keys) may be unicode strings -- they will be written out as
-UTF-8.
-
-The <data> plist type is supported through the Data class. This is a
-thin wrapper around a Python bytes object.
-
-Generate Plist example:
-
-    pl = dict(
-        aString="Doodah",
-        aList=["A", "B", 12, 32.1, [1, 2, 3]],
-        aFloat = 0.1,
-        anInt = 728,
-        aDict=dict(
-            anotherString="<hello & hi there!>",
-            aUnicodeValue=u'M\xe4ssig, Ma\xdf',
-            aTrueValue=True,
-            aFalseValue=False,
-        ),
-        someData = Data(b"<binary gunk>"),
-        someMoreData = Data(b"<lots of binary gunk>" * 10),
-        aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
-    )
-    # unicode keys are possible, but a little awkward to use:
-    pl[u'\xc5benraa'] = "That was a unicode key."
-    writePlist(pl, fileName)
-
-Parse Plist example:
-
-    pl = readPlist(pathOrFile)
-    print pl["aKey"]
-"""
-
-
-__all__ = [
-    "readPlist", "writePlist", "readPlistFromBytes", "writePlistToBytes",
-    "readPlistFromResource", "writePlistToResource",
-    "Plist", "Data", "Dict"
-]
-# Note: the Plist and Dict classes have been deprecated.
-
-import binascii
-import datetime
-from io import BytesIO
-import re
-
-
-def readPlist(pathOrFile):
-    """Read a .plist file. 'pathOrFile' may either be a file name or a
-    (readable) file object. Return the unpacked root object (which
-    usually is a dictionary).
-    """
-    didOpen = False
-    if isinstance(pathOrFile, str):
-        pathOrFile = open(pathOrFile, 'rb')
-        didOpen = True
-    p = PlistParser()
-    rootObject = p.parse(pathOrFile)
-    if didOpen:
-        pathOrFile.close()
-    return rootObject
-
-
-def writePlist(rootObject, pathOrFile):
-    """Write 'rootObject' to a .plist file. 'pathOrFile' may either be a
-    file name or a (writable) file object.
-    """
-    didOpen = False
-    if isinstance(pathOrFile, str):
-        pathOrFile = open(pathOrFile, 'wb')
-        didOpen = True
-    writer = PlistWriter(pathOrFile)
-    writer.writeln("<plist version=\"1.0\">")
-    writer.writeValue(rootObject)
-    writer.writeln("</plist>")
-    if didOpen:
-        pathOrFile.close()
-
-
-def readPlistFromBytes(data):
-    """Read a plist data from a bytes object. Return the root object.
-    """
-    return readPlist(BytesIO(data))
-
-
-def writePlistToBytes(rootObject):
-    """Return 'rootObject' as a plist-formatted bytes object.
-    """
-    f = BytesIO()
-    writePlist(rootObject, f)
-    return f.getvalue()
-
-
-def readPlistFromResource(path, restype='plst', resid=0):
-    """Read plst resource from the resource fork of path.
-    """
-    from Carbon.File import FSRef, FSGetResourceForkName
-    from Carbon.Files import fsRdPerm
-    from Carbon import Res
-    fsRef = FSRef(path)
-    resNum = Res.FSOpenResourceFile(fsRef, FSGetResourceForkName(), fsRdPerm)
-    Res.UseResFile(resNum)
-    plistData = Res.Get1Resource(restype, resid).data
-    Res.CloseResFile(resNum)
-    return readPlistFromString(plistData)
-
-
-def writePlistToResource(rootObject, path, restype='plst', resid=0):
-    """Write 'rootObject' as a plst resource to the resource fork of path.
-    """
-    from Carbon.File import FSRef, FSGetResourceForkName
-    from Carbon.Files import fsRdWrPerm
-    from Carbon import Res
-    plistData = writePlistToString(rootObject)
-    fsRef = FSRef(path)
-    resNum = Res.FSOpenResourceFile(fsRef, FSGetResourceForkName(), fsRdWrPerm)
-    Res.UseResFile(resNum)
-    try:
-        Res.Get1Resource(restype, resid).RemoveResource()
-    except Res.Error:
-        pass
-    res = Res.Resource(plistData)
-    res.AddResource(restype, resid, '')
-    res.WriteResource()
-    Res.CloseResFile(resNum)
-
-
-class DumbXMLWriter:
-    def __init__(self, file, indentLevel=0, indent="\t"):
-        self.file = file
-        self.stack = []
-        self.indentLevel = indentLevel
-        self.indent = indent
-
-    def beginElement(self, element):
-        self.stack.append(element)
-        self.writeln("<%s>" % element)
-        self.indentLevel += 1
-
-    def endElement(self, element):
-        assert self.indentLevel > 0
-        assert self.stack.pop() == element
-        self.indentLevel -= 1
-        self.writeln("</%s>" % element)
-
-    def simpleElement(self, element, value=None):
-        if value is not None:
-            value = _escapeAndEncode(value)
-            self.writeln("<%s>%s</%s>" % (element, value, element))
-        else:
-            self.writeln("<%s/>" % element)
-
-    def writeln(self, line):
-        if line:
-            # plist has fixed encoding of utf-8
-            if isinstance(line, str):
-                line = line.encode('utf-8')
-            self.file.write(self.indentLevel * self.indent)
-            self.file.write(line)
-        self.file.write(b'\n')
-
-
-# Contents should conform to a subset of ISO 8601
-# (in particular, YYYY '-' MM '-' DD 'T' HH ':' MM ':' SS 'Z'.  Smaller units may be omitted with
-#  a loss of precision)
-_dateParser = re.compile(r"(?P<year>\d\d\d\d)(?:-(?P<month>\d\d)(?:-(?P<day>\d\d)(?:T(?P<hour>\d\d)(?::(?P<minute>\d\d)(?::(?P<second>\d\d))?)?)?)?)?Z")
-
-def _dateFromString(s):
-    order = ('year', 'month', 'day', 'hour', 'minute', 'second')
-    gd = _dateParser.match(s).groupdict()
-    lst = []
-    for key in order:
-        val = gd[key]
-        if val is None:
-            break
-        lst.append(int(val))
-    return datetime.datetime(*lst)
-
-def _dateToString(d):
-    return '%04d-%02d-%02dT%02d:%02d:%02dZ' % (
-        d.year, d.month, d.day,
-        d.hour, d.minute, d.second
-    )
-
-
-# Regex to find any control chars, except for \t \n and \r
-_controlCharPat = re.compile(
-    r"[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f"
-    r"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]")
-
-def _escapeAndEncode(text):
-    m = _controlCharPat.search(text)
-    if m is not None:
-        raise ValueError("strings can't contains control characters; "
-                         "use plistlib.Data instead")
-    text = text.replace("\r\n", "\n")       # convert DOS line endings
-    text = text.replace("\r", "\n")         # convert Mac line endings
-    text = text.replace("&", "&amp;")       # escape '&'
-    text = text.replace("<", "&lt;")        # escape '<'
-    text = text.replace(">", "&gt;")        # escape '>'
-    return text.encode("utf-8")             # encode as UTF-8
-
-
-PLISTHEADER = b"""\
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-"""
-
-class PlistWriter(DumbXMLWriter):
-
-    def __init__(self, file, indentLevel=0, indent=b"\t", writeHeader=1):
-        if writeHeader:
-            file.write(PLISTHEADER)
-        DumbXMLWriter.__init__(self, file, indentLevel, indent)
-
-    def writeValue(self, value):
-        if isinstance(value, str):
-            self.simpleElement("string", value)
-        elif isinstance(value, bool):
-            # must switch for bool before int, as bool is a
-            # subclass of int...
-            if value:
-                self.simpleElement("true")
-            else:
-                self.simpleElement("false")
-        elif isinstance(value, int):
-            self.simpleElement("integer", str(value))
-        elif isinstance(value, float):
-            self.simpleElement("real", repr(value))
-        elif isinstance(value, dict):
-            self.writeDict(value)
-        elif isinstance(value, Data):
-            self.writeData(value)
-        elif isinstance(value, datetime.datetime):
-            self.simpleElement("date", _dateToString(value))
-        elif isinstance(value, (tuple, list)):
-            self.writeArray(value)
-        else:
-            raise TypeError("unsuported type: %s" % type(value))
-
-    def writeData(self, data):
-        self.beginElement("data")
-        self.indentLevel -= 1
-        maxlinelength = 76 - len(self.indent.replace(b"\t", b" " * 8) *
-                                 self.indentLevel)
-        for line in data.asBase64(maxlinelength).split(b"\n"):
-            if line:
-                self.writeln(line)
-        self.indentLevel += 1
-        self.endElement("data")
-
-    def writeDict(self, d):
-        self.beginElement("dict")
-        items = sorted(d.items())
-        for key, value in items:
-            if not isinstance(key, str):
-                raise TypeError("keys must be strings")
-            self.simpleElement("key", key)
-            self.writeValue(value)
-        self.endElement("dict")
-
-    def writeArray(self, array):
-        self.beginElement("array")
-        for value in array:
-            self.writeValue(value)
-        self.endElement("array")
-
-
-class _InternalDict(dict):
-
-    # This class is needed while Dict is scheduled for deprecation:
-    # we only need to warn when a *user* instantiates Dict or when
-    # the "attribute notation for dict keys" is used.
-
-    def __getattr__(self, attr):
-        try:
-            value = self[attr]
-        except KeyError:
-            raise AttributeError(attr)
-        from warnings import warn
-        warn("Attribute access from plist dicts is deprecated, use d[key] "
-             "notation instead", PendingDeprecationWarning)
-        return value
-
-    def __setattr__(self, attr, value):
-        from warnings import warn
-        warn("Attribute access from plist dicts is deprecated, use d[key] "
-             "notation instead", PendingDeprecationWarning)
-        self[attr] = value
-
-    def __delattr__(self, attr):
-        try:
-            del self[attr]
-        except KeyError:
-            raise AttributeError(attr)
-        from warnings import warn
-        warn("Attribute access from plist dicts is deprecated, use d[key] "
-             "notation instead", PendingDeprecationWarning)
-
-class Dict(_InternalDict):
-
-    def __init__(self, **kwargs):
-        from warnings import warn
-        warn("The plistlib.Dict class is deprecated, use builtin dict instead",
-             PendingDeprecationWarning)
-        super().__init__(**kwargs)
-
-
-class Plist(_InternalDict):
-
-    """This class has been deprecated. Use readPlist() and writePlist()
-    functions instead, together with regular dict objects.
-    """
-
-    def __init__(self, **kwargs):
-        from warnings import warn
-        warn("The Plist class is deprecated, use the readPlist() and "
-             "writePlist() functions instead", PendingDeprecationWarning)
-        super().__init__(**kwargs)
-
-    def fromFile(cls, pathOrFile):
-        """Deprecated. Use the readPlist() function instead."""
-        rootObject = readPlist(pathOrFile)
-        plist = cls()
-        plist.update(rootObject)
-        return plist
-    fromFile = classmethod(fromFile)
-
-    def write(self, pathOrFile):
-        """Deprecated. Use the writePlist() function instead."""
-        writePlist(self, pathOrFile)
-
-
-def _encodeBase64(s, maxlinelength=76):
-    # copied from base64.encodestring(), with added maxlinelength argument
-    maxbinsize = (maxlinelength//4)*3
-    pieces = []
-    for i in range(0, len(s), maxbinsize):
-        chunk = s[i : i + maxbinsize]
-        pieces.append(binascii.b2a_base64(chunk))
-    return b''.join(pieces)
-
-class Data:
-
-    """Wrapper for binary data."""
-
-    def __init__(self, data):
-        if not isinstance(data, bytes):
-            raise TypeError("data must be as bytes")
-        self.data = data
-
-    @classmethod
-    def fromBase64(cls, data):
-        # base64.decodestring just calls binascii.a2b_base64;
-        # it seems overkill to use both base64 and binascii.
-        return cls(binascii.a2b_base64(data))
-
-    def asBase64(self, maxlinelength=76):
-        return _encodeBase64(self.data, maxlinelength)
-
-    def __eq__(self, other):
-        if isinstance(other, self.__class__):
-            return self.data == other.data
-        elif isinstance(other, str):
-            return self.data == other
-        else:
-            return id(self) == id(other)
-
-    def __repr__(self):
-        return "%s(%s)" % (self.__class__.__name__, repr(self.data))
-
-
-class PlistParser:
-
-    def __init__(self):
-        self.stack = []
-        self.currentKey = None
-        self.root = None
-
-    def parse(self, fileobj):
-        from xml.parsers.expat import ParserCreate
-        parser = ParserCreate()
-        parser.StartElementHandler = self.handleBeginElement
-        parser.EndElementHandler = self.handleEndElement
-        parser.CharacterDataHandler = self.handleData
-        parser.ParseFile(fileobj)
-        return self.root
-
-    def handleBeginElement(self, element, attrs):
-        self.data = []
-        handler = getattr(self, "begin_" + element, None)
-        if handler is not None:
-            handler(attrs)
-
-    def handleEndElement(self, element):
-        handler = getattr(self, "end_" + element, None)
-        if handler is not None:
-            handler()
-
-    def handleData(self, data):
-        self.data.append(data)
-
-    def addObject(self, value):
-        if self.currentKey is not None:
-            self.stack[-1][self.currentKey] = value
-            self.currentKey = None
-        elif not self.stack:
-            # this is the root object
-            self.root = value
-        else:
-            self.stack[-1].append(value)
-
-    def getData(self):
-        data = ''.join(self.data)
-        self.data = []
-        return data
-
-    # element handlers
-
-    def begin_dict(self, attrs):
-        d = _InternalDict()
-        self.addObject(d)
-        self.stack.append(d)
-    def end_dict(self):
-        self.stack.pop()
-
-    def end_key(self):
-        self.currentKey = self.getData()
-
-    def begin_array(self, attrs):
-        a = []
-        self.addObject(a)
-        self.stack.append(a)
-    def end_array(self):
-        self.stack.pop()
-
-    def end_true(self):
-        self.addObject(True)
-    def end_false(self):
-        self.addObject(False)
-    def end_integer(self):
-        self.addObject(int(self.getData()))
-    def end_real(self):
-        self.addObject(float(self.getData()))
-    def end_string(self):
-        self.addObject(self.getData())
-    def end_data(self):
-        self.addObject(Data.fromBase64(self.getData().encode("utf-8")))
-    def end_date(self):
-        self.addObject(_dateFromString(self.getData()))

Modified: python/branches/py3k-importlib/Lib/plat-mac/terminalcommand.py
==============================================================================
--- python/branches/py3k-importlib/Lib/plat-mac/terminalcommand.py	(original)
+++ python/branches/py3k-importlib/Lib/plat-mac/terminalcommand.py	Thu Mar 27 00:48:05 2008
@@ -36,7 +36,7 @@
     try:
         theEvent.AESend(SEND_MODE, kAENormalPriority, kAEDefaultTimeout)
     except AE.Error as why:
-        if why[0] != -600:  # Terminal.app not yet running
+        if why.args[0] != -600:  # Terminal.app not yet running
             raise
         os.system(START_TERMINAL)
         time.sleep(1)

Modified: python/branches/py3k-importlib/Lib/platform.py
==============================================================================
--- python/branches/py3k-importlib/Lib/platform.py	(original)
+++ python/branches/py3k-importlib/Lib/platform.py	Thu Mar 27 00:48:05 2008
@@ -12,8 +12,6 @@
 #    If you find problems, please submit bug reports/patches via the
 #    Python SourceForge Project Page and assign them to "lemburg".
 #
-#    Note: Please keep this module compatible to Python 1.5.2.
-#
 #    Still needed:
 #    * more support for WinCE
 #    * support for MS-DOS (PythonDX ?)
@@ -91,7 +89,7 @@
 
 __copyright__ = """
     Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal at lemburg.com
-    Copyright (c) 2000-2007, eGenix.com Software GmbH; mailto:info at egenix.com
+    Copyright (c) 2000-2008, eGenix.com Software GmbH; mailto:info at egenix.com
 
     Permission to use, copy, modify, and distribute this software and its
     documentation for any purpose and without fee or royalty is hereby granted,
@@ -240,9 +238,10 @@
 # and http://data.linux-ntfs.org/rpm/whichrpm
 # and http://www.die.net/doc/linux/man/man1/lsb_release.1.html
 
-_supported_dists = ('SuSE', 'debian', 'fedora', 'redhat', 'centos',
-                    'mandrake', 'rocks', 'slackware', 'yellowdog',
-                    'gentoo', 'UnitedLinux', 'turbolinux')
+_supported_dists = (
+    'SuSE', 'debian', 'fedora', 'redhat', 'centos',
+    'mandrake', 'mandriva', 'rocks', 'slackware', 'yellowdog', 'gentoo',
+    'UnitedLinux', 'turbolinux')
 
 def _parse_release_file(firstline):
 
@@ -526,7 +525,13 @@
         In case this fails, default is returned.
 
     """
-    from win32api import RegQueryValueEx
+    try:
+        # Use win32api if available
+        from win32api import RegQueryValueEx
+    except ImportError:
+        # On Python 2.0 and later, emulate using _winreg
+        import _winreg
+        RegQueryValueEx = _winreg.QueryValueEx
     try:
         return RegQueryValueEx(key,name)
     except:
@@ -546,9 +551,9 @@
         means the OS version uses debugging code, i.e. code that
         checks arguments, ranges, etc. (Thomas Heller).
 
-        Note: this function only works if Mark Hammond's win32
-        package is installed and obviously only runs on Win32
-        compatible platforms.
+        Note: this function works best with Mark Hammond's win32
+        package installed, but also on Python 2.3 and later. It
+        obviously only runs on Win32 compatible platforms.
 
     """
     # XXX Is there any way to find out the processor type on WinXX ?
@@ -562,11 +567,29 @@
     # Import the needed APIs
     try:
         import win32api
+        from win32api import RegQueryValueEx, RegOpenKeyEx, \
+             RegCloseKey, GetVersionEx
+        from win32con import HKEY_LOCAL_MACHINE, VER_PLATFORM_WIN32_NT, \
+             VER_PLATFORM_WIN32_WINDOWS, VER_NT_WORKSTATION
     except ImportError:
-        return release,version,csd,ptype
-    from win32api import RegQueryValueEx,RegOpenKeyEx,RegCloseKey,GetVersionEx
-    from win32con import HKEY_LOCAL_MACHINE,VER_PLATFORM_WIN32_NT,\
-                         VER_PLATFORM_WIN32_WINDOWS
+        # Emulate the win32api module using Python APIs
+        try:
+            sys.getwindowsversion
+        except AttributeError:
+            # No emulation possible, so return the defaults...
+            return release,version,csd,ptype
+        else:
+            # Emulation using _winreg (added in Python 2.0) and
+            # sys.getwindowsversion() (added in Python 2.3)
+            import _winreg
+            GetVersionEx = sys.getwindowsversion
+            RegQueryValueEx = _winreg.QueryValueEx
+            RegOpenKeyEx = _winreg.OpenKeyEx
+            RegCloseKey = _winreg.CloseKey
+            HKEY_LOCAL_MACHINE = _winreg.HKEY_LOCAL_MACHINE
+            VER_PLATFORM_WIN32_WINDOWS = 1
+            VER_PLATFORM_WIN32_NT = 2
+            VER_NT_WORKSTATION = 1
 
     # Find out the registry key and some general version infos
     maj,min,buildno,plat,csd = GetVersionEx()
@@ -603,11 +626,18 @@
         elif maj == 6:
             if min == 0:
                 # Per http://msdn2.microsoft.com/en-us/library/ms724429.aspx
-                productType = GetVersionEx(1)[8]
-                if productType == 1: # VER_NT_WORKSTATION
+                try:
+                    productType = GetVersionEx(1)[8]
+                except TypeError:
+                    # sys.getwindowsversion() doesn't take any arguments, so
+                    # we cannot detect 2008 Server that way.
+                    # XXX Add some other means of detecting 2008 Server ?!
                     release = 'Vista'
                 else:
-                    release = '2008Server'
+                    if productType == VER_NT_WORKSTATION:
+                        release = 'Vista'
+                    else:
+                        release = '2008Server'
             else:
                 release = 'post2008Server'
     else:
@@ -618,9 +648,9 @@
 
     # Open the registry key
     try:
-        keyCurVer = RegOpenKeyEx(HKEY_LOCAL_MACHINE,regkey)
+        keyCurVer = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey)
         # Get a value to make sure the key exists...
-        RegQueryValueEx(keyCurVer,'SystemRoot')
+        RegQueryValueEx(keyCurVer, 'SystemRoot')
     except:
         return release,version,csd,ptype
 
@@ -857,28 +887,12 @@
         # Still not working...
         return default
 
-# os.path.abspath is new in Python 1.5.2:
-if not hasattr(os.path,'abspath'):
-
-    def _abspath(path,
-
-                 isabs=os.path.isabs,join=os.path.join,getcwd=os.getcwd,
-                 normpath=os.path.normpath):
-
-        if not isabs(path):
-            path = join(getcwd(), path)
-        return normpath(path)
-
-else:
-
-    _abspath = os.path.abspath
-
 def _follow_symlinks(filepath):
 
     """ In case filepath is a symlink, follow it until a
         real file is reached.
     """
-    filepath = _abspath(filepath)
+    filepath = os.path.abspath(filepath)
     while os.path.islink(filepath):
         filepath = os.path.normpath(
             os.path.join(filepath,os.readlink(filepath)))
@@ -1061,10 +1075,12 @@
             release,version,csd,ptype = win32_ver()
             if release and version:
                 use_syscmd_ver = 0
-            # XXX Should try to parse the PROCESSOR_* environment variables
+            # Try to use the PROCESSOR_* environment variables
             # available on Win XP and later; see
             # http://support.microsoft.com/kb/888731 and
             # http://www.geocities.com/rick_lively/MANUALS/ENV/MSWIN/PROCESSI.HTM
+            machine = os.environ.get('PROCESSOR_ARCHITECTURE', '')
+            processor = os.environ.get('PROCESSOR_IDENTIFIER', machine)
 
         # Try the 'ver' system command available on some
         # platforms

Modified: python/branches/py3k-importlib/Lib/posixpath.py
==============================================================================
--- python/branches/py3k-importlib/Lib/posixpath.py	(original)
+++ python/branches/py3k-importlib/Lib/posixpath.py	Thu Mar 27 00:48:05 2008
@@ -178,8 +178,8 @@
 def ismount(path):
     """Test whether a path is a mount point"""
     try:
-        s1 = os.stat(path)
-        s2 = os.stat(join(path, '..'))
+        s1 = os.lstat(path)
+        s2 = os.lstat(join(path, '..'))
     except os.error:
         return False # It doesn't exist -- so not a mount point :-)
     dev1 = s1.st_dev
@@ -398,4 +398,6 @@
     i = len(commonprefix([start_list, path_list]))
 
     rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
+    if not rel_list:
+        return curdir
     return join(*rel_list)

Modified: python/branches/py3k-importlib/Lib/pprint.py
==============================================================================
--- python/branches/py3k-importlib/Lib/pprint.py	(original)
+++ python/branches/py3k-importlib/Lib/pprint.py	Thu Mar 27 00:48:05 2008
@@ -159,17 +159,35 @@
                 write('}')
                 return
 
-            if (issubclass(typ, list) and r is list.__repr__) or \
-               (issubclass(typ, tuple) and r is tuple.__repr__):
+            if ((issubclass(typ, list) and r is list.__repr__) or
+                (issubclass(typ, tuple) and r is tuple.__repr__) or
+                (issubclass(typ, set) and r is set.__repr__) or
+                (issubclass(typ, frozenset) and r is frozenset.__repr__)
+               ):
+                length = _len(object)
                 if issubclass(typ, list):
                     write('[')
                     endchar = ']'
+                elif issubclass(typ, set):
+                    if not length:
+                        write('set()')
+                        return
+                    write('{')
+                    endchar = '}'
+                    object = sorted(object)
+                elif issubclass(typ, frozenset):
+                    if not length:
+                        write('frozenset()')
+                        return
+                    write('frozenset({')
+                    endchar = '})'
+                    object = sorted(object)
+                    indent += 10
                 else:
                     write('(')
                     endchar = ')'
                 if self._indent_per_level > 1:
                     write((self._indent_per_level - 1) * ' ')
-                length = _len(object)
                 if length:
                     context[objid] = 1
                     indent = indent + self._indent_per_level

Modified: python/branches/py3k-importlib/Lib/pstats.py
==============================================================================
--- python/branches/py3k-importlib/Lib/pstats.py	(original)
+++ python/branches/py3k-importlib/Lib/pstats.py	Thu Mar 27 00:48:05 2008
@@ -116,7 +116,7 @@
 
     def load_stats(self, arg):
         if not arg:  self.stats = {}
-        elif isinstance(arg, basestring):
+        elif isinstance(arg, str):
             f = open(arg, 'rb')
             self.stats = marshal.load(f)
             f.close()
@@ -238,7 +238,7 @@
             stats_list.append((cc, nc, tt, ct) + func +
                               (func_std_string(func), func))
 
-        stats_list.sort(TupleComp(sort_tuple).compare)
+        stats_list.sort(key=CmpToKey(TupleComp(sort_tuple).compare))
 
         self.fcn_list = fcn_list = []
         for tuple in stats_list:
@@ -470,6 +470,16 @@
                 return direction
         return 0
 
+def CmpToKey(mycmp):
+    'Convert a cmp= function into a key= function'
+    class K(object):
+        def __init__(self, obj):
+            self.obj = obj
+        def __lt__(self, other):
+            return mycmp(self.obj, other.obj) == -1
+    return K
+
+
 #**************************************************************************
 # func_name is a triple (file:string, line:int, name:string)
 
@@ -511,7 +521,8 @@
         new_callers[func] = caller
     for func, caller in source.items():
         if func in new_callers:
-            new_callers[func] = caller + new_callers[func]
+            new_callers[func] = tuple([i[0] + i[1] for i in
+                                       zip(caller, new_callers[func])])
         else:
             new_callers[func] = caller
     return new_callers
@@ -617,8 +628,8 @@
             if line:
                 try:
                     self.stats = Stats(line)
-                except IOError as args:
-                    print(args[1], file=self.stream)
+                except IOError as err:
+                    print(err.args[1], file=self.stream)
                     return
                 self.prompt = line + "% "
             elif len(self.prompt) > 2:

Modified: python/branches/py3k-importlib/Lib/py_compile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/py_compile.py	(original)
+++ python/branches/py3k-importlib/Lib/py_compile.py	Thu Mar 27 00:48:05 2008
@@ -3,7 +3,7 @@
 This module has intimate knowledge of the format of .pyc files.
 """
 
-import __builtin__
+import builtins
 import imp
 import marshal
 import os
@@ -88,7 +88,7 @@
                 break
             m = re.match(r".*\bcoding:\s*(\S+)\b", line)
             if m:
-                return str(m.group(1))
+                return m.group(1).decode("ascii")
         return default
     finally:
         f.close()
@@ -139,7 +139,7 @@
     if codestring and codestring[-1] != '\n':
         codestring = codestring + '\n'
     try:
-        codeobject = __builtin__.compile(codestring, dfile or file,'exec')
+        codeobject = builtins.compile(codestring, dfile or file,'exec')
     except Exception as err:
         py_exc = PyCompileError(err.__class__, err, dfile or file)
         if doraise:
@@ -171,11 +171,15 @@
     """
     if args is None:
         args = sys.argv[1:]
+    rv = 0
     for filename in args:
         try:
             compile(filename, doraise=True)
         except PyCompileError as err:
+            # return value to indicate at least one failure
+            rv = 1
             sys.stderr.write(err.msg)
+    return rv
 
 if __name__ == "__main__":
-    main()
+    sys.exit(main())

Modified: python/branches/py3k-importlib/Lib/pyclbr.py
==============================================================================
--- python/branches/py3k-importlib/Lib/pyclbr.py	(original)
+++ python/branches/py3k-importlib/Lib/pyclbr.py	Thu Mar 27 00:48:05 2008
@@ -324,8 +324,7 @@
         path = []
     dict = readmodule_ex(mod, path)
     objs = dict.values()
-    objs.sort(lambda a, b: cmp(getattr(a, 'lineno', 0),
-                               getattr(b, 'lineno', 0)))
+    objs.sort(key=lambda a: getattr(a, 'lineno', 0))
     for obj in objs:
         if isinstance(obj, Class):
             print("class", obj.name, obj.super, obj.lineno)

Modified: python/branches/py3k-importlib/Lib/pydoc.py
==============================================================================
--- python/branches/py3k-importlib/Lib/pydoc.py	(original)
+++ python/branches/py3k-importlib/Lib/pydoc.py	Thu Mar 27 00:48:05 2008
@@ -27,7 +27,7 @@
 
 Module docs for core modules are assumed to be in
 
-    http://www.python.org/doc/current/lib/
+    http://docs.python.org/library/
 
 This can be overridden by setting the PYTHONDOCS environment variable
 to a different URL or to a local directory containing the Library
@@ -52,7 +52,7 @@
 #     the current directory is changed with os.chdir(), an incorrect
 #     path will be displayed.
 
-import sys, imp, os, re, inspect, __builtin__, pkgutil
+import sys, imp, os, re, inspect, builtins, pkgutil
 from repr import Repr
 try:
     from collections import deque
@@ -341,7 +341,7 @@
             file = '(built-in)'
 
         docloc = os.environ.get("PYTHONDOCS",
-                                "http://www.python.org/doc/current/lib")
+                                "http://docs.python.org/library")
         basedir = os.path.join(sys.exec_prefix, "lib",
                                "python"+sys.version[0:3])
         if (isinstance(object, type(os)) and
@@ -350,11 +350,10 @@
                                  'thread', 'zipimport') or
              (file.startswith(basedir) and
               not file.startswith(os.path.join(basedir, 'site-packages'))))):
-            htmlfile = "module-%s.html" % object.__name__
             if docloc.startswith("http://"):
-                docloc = "%s/%s" % (docloc.rstrip("/"), htmlfile)
+                docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__)
             else:
-                docloc = os.path.join(docloc, htmlfile)
+                docloc = os.path.join(docloc, object.__name__ + ".html")
         else:
             docloc = None
         return docloc
@@ -537,7 +536,7 @@
                 url = 'http://www.rfc-editor.org/rfc/rfc%d.txt' % int(rfc)
                 results.append('<a href="%s">%s</a>' % (url, escape(all)))
             elif pep:
-                url = 'http://www.python.org/peps/pep-%04d.html' % int(pep)
+                url = 'http://www.python.org/dev/peps/pep-%04d/' % int(pep)
                 results.append('<a href="%s">%s</a>' % (url, escape(all)))
             elif text[end:end+1] == '(':
                 results.append(self.namelink(name, methods, funcs, classes))
@@ -661,7 +660,7 @@
             contents = self.multicolumn(
                 modules, lambda t: self.modulelink(t[1]))
             result = result + self.bigsection(
-                'Modules', '#fffff', '#aa55cc', contents)
+                'Modules', '#ffffff', '#aa55cc', contents)
 
         if classes:
             classlist = [value for (key, value) in classes]
@@ -787,7 +786,7 @@
                 thisclass = attrs[0][2]
             attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)
 
-            if thisclass is __builtin__.object:
+            if thisclass is builtins.object:
                 attrs = inherited
                 continue
             elif thisclass is object:
@@ -798,10 +797,7 @@
             tag += ':<br>\n'
 
             # Sort attrs by name.
-            try:
-                attrs.sort(key=lambda t: t[0])
-            except TypeError:
-                attrs.sort(lambda t1, t2: cmp(t1[0], t2[0]))    # 2.3 compat
+            attrs.sort(key=lambda t: t[0])
 
             # Pump out the attrs, segregated by kind.
             attrs = spill('Methods %s' % tag, attrs,
@@ -848,17 +844,17 @@
         note = ''
         skipdocs = 0
         if inspect.ismethod(object):
-            imclass = object.im_class
+            imclass = object.__self__.__class__
             if cl:
                 if imclass is not cl:
                     note = ' from ' + self.classlink(imclass, mod)
             else:
-                if object.im_self is not None:
+                if object.__self__ is not None:
                     note = ' method of %s instance' % self.classlink(
-                        object.im_self.__class__, mod)
+                        object.__self__.__class__, mod)
                 else:
                     note = ' unbound %s method' % self.classlink(imclass,mod)
-            object = object.im_func
+            object = object.__func__
 
         if name == realname:
             title = '<a name="%s"><strong>%s</strong></a>' % (anchor, realname)
@@ -1056,9 +1052,11 @@
             if visiblename(key, all):
                 data.append((key, value))
 
+        modpkgs = []
+        modpkgs_names = set()
         if hasattr(object, '__path__'):
-            modpkgs = []
             for importer, modname, ispkg in pkgutil.iter_modules(object.__path__):
+                modpkgs_names.add(modname)
                 if ispkg:
                     modpkgs.append(modname + ' (package)')
                 else:
@@ -1068,6 +1066,16 @@
             result = result + self.section(
                 'PACKAGE CONTENTS', '\n'.join(modpkgs))
 
+        # Detect submodules as sometimes created by C extensions
+        submodules = []
+        for key, value in inspect.getmembers(object, inspect.ismodule):
+            if value.__name__.startswith(name + '.') and key not in modpkgs_names:
+                submodules.append(key)
+        if submodules:
+            submodules.sort()
+            result = result + self.section(
+                'SUBMODULES', join(submodules, '\n'))
+
         if classes:
             classlist = [value for key, value in classes]
             contents = [self.formattree(
@@ -1184,7 +1192,7 @@
                 thisclass = attrs[0][2]
             attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)
 
-            if thisclass is __builtin__.object:
+            if thisclass is builtins.object:
                 attrs = inherited
                 continue
             elif thisclass is object:
@@ -1192,7 +1200,6 @@
             else:
                 tag = "inherited from %s" % classname(thisclass,
                                                       object.__module__)
-            filter(lambda t: not t[0].startswith('_'), attrs)
 
             # Sort attrs by name.
             attrs.sort()
@@ -1227,17 +1234,17 @@
         note = ''
         skipdocs = 0
         if inspect.ismethod(object):
-            imclass = object.im_class
+            imclass = object.__self__.__class__
             if cl:
                 if imclass is not cl:
                     note = ' from ' + classname(imclass, mod)
             else:
-                if object.im_self is not None:
+                if object.__self__ is not None:
                     note = ' method of %s instance' % classname(
-                        object.im_self.__class__, mod)
+                        object.__self__.__class__, mod)
                 else:
                     note = ' unbound %s method' % classname(imclass,mod)
-            object = object.im_func
+            object = object.__func__
 
         if name == realname:
             title = self.bold(realname)
@@ -1450,8 +1457,8 @@
             except AttributeError: return None
         return object
     else:
-        if hasattr(__builtin__, path):
-            return getattr(__builtin__, path)
+        if hasattr(builtins, path):
+            return getattr(builtins, path)
 
 # --------------------------------------- interactive interpreter interface
 
@@ -1532,11 +1539,6 @@
         writedoc(modname)
     return
 
-def raw_input(prompt):
-    sys.stdout.write(prompt)
-    sys.stdout.flush()
-    return sys.stdin.readline()
-
 class Helper:
     keywords = {
         'and': 'BOOLEAN',
@@ -1706,9 +1708,9 @@
             self.help(request)
 
     def getline(self, prompt):
-        """Read one line, using raw_input when available."""
+        """Read one line, using input() when appropriate."""
         if self.input is sys.stdin:
-            return raw_input(prompt)
+            return input(prompt)
         else:
             self.output.write(prompt)
             self.output.flush()
@@ -1734,7 +1736,7 @@
 Welcome to Python %s!  This is the online help utility.
 
 If this is your first time using Python, you should definitely check out
-the tutorial on the Internet at http://www.python.org/doc/tut/.
+the tutorial on the Internet at http://docs.python.org/tutorial/.
 
 Enter the name of any module, keyword, or topic to get help on writing
 Python programs and using Python modules.  To quit this help utility and
@@ -1839,7 +1841,9 @@
                     modname = modname[:-9] + ' (package)'
                 if modname.find('.') < 0:
                     modules[modname] = 1
-            ModuleScanner().run(callback)
+            def onerror(modname):
+                callback(None, modname, None)
+            ModuleScanner().run(callback, onerror=onerror)
             self.list(modules.keys())
             self.output.write('''
 Enter any module name to get more help.  Or, type "modules spam" to search
@@ -1875,7 +1879,7 @@
 class ModuleScanner:
     """An interruptible scanner that searches module synopses."""
 
-    def run(self, callback, key=None, completer=None):
+    def run(self, callback, key=None, completer=None, onerror=None):
         if key: key = key.lower()
         self.quit = False
         seen = {}
@@ -1892,7 +1896,7 @@
                     if name.lower().find(key) >= 0:
                         callback(None, modname, desc)
 
-        for importer, modname, ispkg in pkgutil.walk_packages():
+        for importer, modname, ispkg in pkgutil.walk_packages(onerror=onerror):
             if self.quit:
                 break
             if key is None:
@@ -1949,9 +1953,9 @@
         def send_document(self, title, contents):
             try:
                 self.send_response(200)
-                self.send_header('Content-Type', 'text/html')
+                self.send_header('Content-Type', 'text/html; charset=UTF-8')
                 self.end_headers()
-                self.wfile.write(html.page(title, contents))
+                self.wfile.write(html.page(title, contents).encode('utf-8'))
             except IOError: pass
 
         def do_GET(self):
@@ -1975,8 +1979,7 @@
 '#ffffff', '#7799ee')
                 def bltinlink(name):
                     return '<a href="%s.html">%s</a>' % (name, name)
-                names = filter(lambda x: x != '__main__',
-                               sys.builtin_module_names)
+                names = [x for x in sys.builtin_module_names if x != '__main__']
                 contents = html.multicolumn(names, bltinlink)
                 indices = ['<p>' + html.bigsection(
                     'Built-in Modules', '#ffffff', '#ee77aa', contents)]

Modified: python/branches/py3k-importlib/Lib/quopri.py
==============================================================================
--- python/branches/py3k-importlib/Lib/quopri.py	(original)
+++ python/branches/py3k-importlib/Lib/quopri.py	Thu Mar 27 00:48:05 2008
@@ -227,12 +227,14 @@
                 sys.stderr.write("%s: can't open (%s)\n" % (file, msg))
                 sts = 1
                 continue
-        if deco:
-            decode(fp, sys.stdout.buffer)
-        else:
-            encode(fp, sys.stdout.buffer, tabs)
-        if fp is not sys.stdin:
-            fp.close()
+        try:
+            if deco:
+                decode(fp, sys.stdout.buffer)
+            else:
+                encode(fp, sys.stdout.buffer, tabs)
+        finally:
+            if file != '-':
+                fp.close()
     if sts:
         sys.exit(sts)
 

Modified: python/branches/py3k-importlib/Lib/random.py
==============================================================================
--- python/branches/py3k-importlib/Lib/random.py	(original)
+++ python/branches/py3k-importlib/Lib/random.py	Thu Mar 27 00:48:05 2008
@@ -13,6 +13,7 @@
     distributions on the real line:
     ------------------------------
            uniform
+           triangular
            normal (Gaussian)
            lognormal
            negative exponential
@@ -30,14 +31,12 @@
 
 * The period is 2**19937-1.
 * It is one of the most extensively tested generators in existence.
-* Without a direct way to compute N steps forward, the semantics of
-  jumpahead(n) are weakened to simply jump to another distant state and rely
-  on the large period to avoid overlapping sequences.
 * The random() method is implemented in C, executes in a single Python step,
   and is, therefore, threadsafe.
 
 """
 
+from __future__ import division
 from warnings import warn as _warn
 from types import MethodType as _MethodType, BuiltinMethodType as _BuiltinMethodType
 from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
@@ -47,9 +46,9 @@
 
 __all__ = ["Random","seed","random","uniform","randint","choice","sample",
            "randrange","shuffle","normalvariate","lognormvariate",
-           "expovariate","vonmisesvariate","gammavariate",
+           "expovariate","vonmisesvariate","gammavariate","triangular",
            "gauss","betavariate","paretovariate","weibullvariate",
-           "getstate","setstate","jumpahead", "WichmannHill", "getrandbits",
+           "getstate","setstate", "getrandbits",
            "SystemRandom"]
 
 NV_MAGICCONST = 4 * _exp(-0.5)/_sqrt(2.0)
@@ -70,20 +69,17 @@
     """Random number generator base class used by bound module functions.
 
     Used to instantiate instances of Random to get generators that don't
-    share state.  Especially useful for multi-threaded programs, creating
-    a different instance of Random for each thread, and using the jumpahead()
-    method to ensure that the generated sequences seen by each thread don't
-    overlap.
+    share state.
 
     Class Random can also be subclassed if you want to use a different basic
     generator of your own devising: in that case, override the following
-    methods:  random(), seed(), getstate(), setstate() and jumpahead().
+    methods:  random(), seed(), getstate(), and setstate().
     Optionally, implement a getrandombits() method so that randrange()
     can cover arbitrarily large ranges.
 
     """
 
-    VERSION = 2     # used by getstate/setstate
+    VERSION = 3     # used by getstate/setstate
 
     def __init__(self, x=None):
         """Initialize an instance.
@@ -120,9 +116,20 @@
     def setstate(self, state):
         """Restore internal state from object returned by getstate()."""
         version = state[0]
-        if version == 2:
+        if version == 3:
             version, internalstate, self.gauss_next = state
             super().setstate(internalstate)
+        elif version == 2:
+            version, internalstate, self.gauss_next = state
+            # In version 2, the state was saved as signed ints, which causes
+            #   inconsistencies between 32/64-bit systems. The state is
+            #   really unsigned 32-bit ints, so we convert negative ints from
+            #   version 2 to positive longs for version 3.
+            try:
+                internalstate = tuple( x % (2**32) for x in internalstate )
+            except ValueError as e:
+                raise TypeError from e
+            super(Random, self).setstate(internalstate)
         else:
             raise ValueError("state with version %s passed to "
                              "Random.setstate() of version %s" %
@@ -262,7 +269,7 @@
             x[i], x[j] = x[j], x[i]
 
     def sample(self, population, k):
-        """Chooses k unique random elements from a population sequence.
+        """Chooses k unique random elements from a population sequence or set.
 
         Returns a new list containing elements from the population while
         leaving the original population unchanged.  The resulting list is
@@ -279,15 +286,6 @@
         large population:   sample(range(10000000), 60)
         """
 
-        # XXX Although the documentation says `population` is "a sequence",
-        # XXX attempts are made to cater to any iterable with a __len__
-        # XXX method.  This has had mixed success.  Examples from both
-        # XXX sides:  sets work fine, and should become officially supported;
-        # XXX dicts are much harder, and have failed in various subtle
-        # XXX ways across attempts.  Support for mapping types should probably
-        # XXX be dropped (and users should pass mapping.keys() or .values()
-        # XXX explicitly).
-
         # Sampling without replacement entails tracking either potential
         # selections (the pool) in a list or previous selections in a set.
 
@@ -298,37 +296,35 @@
         # preferred since the list takes less space than the
         # set and it doesn't suffer from frequent reselections.
 
+        if isinstance(population, (set, frozenset)):
+            population = tuple(population)
+        if not hasattr(population, '__getitem__') or hasattr(population, 'keys'):
+            raise TypeError("Population must be a sequence or set.  For dicts, use dict.keys().")
+        random = self.random
         n = len(population)
         if not 0 <= k <= n:
-            raise ValueError("sample larger than population")
-        random = self.random
+            raise ValueError("Sample larger than population")
         _int = int
         result = [None] * k
         setsize = 21        # size of a small set minus size of an empty list
         if k > 5:
             setsize += 4 ** _ceil(_log(k * 3, 4)) # table size for big sets
-        if n <= setsize or hasattr(population, "keys"):
-            # An n-length list is smaller than a k-length set, or this is a
-            # mapping type so the other algorithm wouldn't work.
+        if n <= setsize:
+            # An n-length list is smaller than a k-length set
             pool = list(population)
             for i in range(k):         # invariant:  non-selected at [0,n-i)
                 j = _int(random() * (n-i))
                 result[i] = pool[j]
                 pool[j] = pool[n-i-1]   # move non-selected item into vacancy
         else:
-            try:
-                selected = set()
-                selected_add = selected.add
-                for i in range(k):
+            selected = set()
+            selected_add = selected.add
+            for i in range(k):
+                j = _int(random() * n)
+                while j in selected:
                     j = _int(random() * n)
-                    while j in selected:
-                        j = _int(random() * n)
-                    selected_add(j)
-                    result[i] = population[j]
-            except (TypeError, KeyError):   # handle (at least) sets
-                if isinstance(population, list):
-                    raise
-                return self.sample(tuple(population), k)
+                selected_add(j)
+                result[i] = population[j]
         return result
 
 ## -------------------- real-valued distributions  -------------------
@@ -339,6 +335,25 @@
         """Get a random number in the range [a, b)."""
         return a + (b-a) * self.random()
 
+## -------------------- triangular --------------------
+
+    def triangular(self, low=0.0, high=1.0, mode=None):
+        """Triangular distribution.
+
+        Continuous distribution bounded by given lower and upper limits,
+        and having a given mode value in-between.
+
+        http://en.wikipedia.org/wiki/Triangular_distribution
+
+        """
+        u = self.random()
+        c = 0.5 if mode is None else (mode - low) / (high - low)
+        if u > c:
+            u = 1.0 - u
+            c = 1.0 - c
+            low, high = high, low
+        return low + (high - low) * (u * c) ** 0.5
+
 ## -------------------- normal distribution --------------------
 
     def normalvariate(self, mu, sigma):
@@ -604,156 +619,6 @@
         u = 1.0 - self.random()
         return alpha * pow(-_log(u), 1.0/beta)
 
-## -------------------- Wichmann-Hill -------------------
-
-class WichmannHill(Random):
-
-    VERSION = 1     # used by getstate/setstate
-
-    def seed(self, a=None):
-        """Initialize internal state from hashable object.
-
-        None or no argument seeds from current time or from an operating
-        system specific randomness source if available.
-
-        If a is not None or an int or long, hash(a) is used instead.
-
-        If a is an int or long, a is used directly.  Distinct values between
-        0 and 27814431486575L inclusive are guaranteed to yield distinct
-        internal states (this guarantee is specific to the default
-        Wichmann-Hill generator).
-        """
-
-        if a is None:
-            try:
-                a = int(_hexlify(_urandom(16)), 16)
-            except NotImplementedError:
-                import time
-                a = int(time.time() * 256) # use fractional seconds
-
-        if not isinstance(a, int):
-            a = hash(a)
-
-        a, x = divmod(a, 30268)
-        a, y = divmod(a, 30306)
-        a, z = divmod(a, 30322)
-        self._seed = int(x)+1, int(y)+1, int(z)+1
-
-        self.gauss_next = None
-
-    def random(self):
-        """Get the next random number in the range [0.0, 1.0)."""
-
-        # Wichman-Hill random number generator.
-        #
-        # Wichmann, B. A. & Hill, I. D. (1982)
-        # Algorithm AS 183:
-        # An efficient and portable pseudo-random number generator
-        # Applied Statistics 31 (1982) 188-190
-        #
-        # see also:
-        #        Correction to Algorithm AS 183
-        #        Applied Statistics 33 (1984) 123
-        #
-        #        McLeod, A. I. (1985)
-        #        A remark on Algorithm AS 183
-        #        Applied Statistics 34 (1985),198-200
-
-        # This part is thread-unsafe:
-        # BEGIN CRITICAL SECTION
-        x, y, z = self._seed
-        x = (171 * x) % 30269
-        y = (172 * y) % 30307
-        z = (170 * z) % 30323
-        self._seed = x, y, z
-        # END CRITICAL SECTION
-
-        # Note:  on a platform using IEEE-754 double arithmetic, this can
-        # never return 0.0 (asserted by Tim; proof too long for a comment).
-        return (x/30269.0 + y/30307.0 + z/30323.0) % 1.0
-
-    def getstate(self):
-        """Return internal state; can be passed to setstate() later."""
-        return self.VERSION, self._seed, self.gauss_next
-
-    def setstate(self, state):
-        """Restore internal state from object returned by getstate()."""
-        version = state[0]
-        if version == 1:
-            version, self._seed, self.gauss_next = state
-        else:
-            raise ValueError("state with version %s passed to "
-                             "Random.setstate() of version %s" %
-                             (version, self.VERSION))
-
-    def jumpahead(self, n):
-        """Act as if n calls to random() were made, but quickly.
-
-        n is an int, greater than or equal to 0.
-
-        Example use:  If you have 2 threads and know that each will
-        consume no more than a million random numbers, create two Random
-        objects r1 and r2, then do
-            r2.setstate(r1.getstate())
-            r2.jumpahead(1000000)
-        Then r1 and r2 will use guaranteed-disjoint segments of the full
-        period.
-        """
-
-        if not n >= 0:
-            raise ValueError("n must be >= 0")
-        x, y, z = self._seed
-        x = int(x * pow(171, n, 30269)) % 30269
-        y = int(y * pow(172, n, 30307)) % 30307
-        z = int(z * pow(170, n, 30323)) % 30323
-        self._seed = x, y, z
-
-    def __whseed(self, x=0, y=0, z=0):
-        """Set the Wichmann-Hill seed from (x, y, z).
-
-        These must be integers in the range [0, 256).
-        """
-
-        if not type(x) == type(y) == type(z) == int:
-            raise TypeError('seeds must be integers')
-        if not (0 <= x < 256 and 0 <= y < 256 and 0 <= z < 256):
-            raise ValueError('seeds must be in range(0, 256)')
-        if 0 == x == y == z:
-            # Initialize from current time
-            import time
-            t = int(time.time() * 256)
-            t = int((t&0xffffff) ^ (t>>24))
-            t, x = divmod(t, 256)
-            t, y = divmod(t, 256)
-            t, z = divmod(t, 256)
-        # Zero is a poor seed, so substitute 1
-        self._seed = (x or 1, y or 1, z or 1)
-
-        self.gauss_next = None
-
-    def whseed(self, a=None):
-        """Seed from hashable object's hash code.
-
-        None or no argument seeds from current time.  It is not guaranteed
-        that objects with distinct hash codes lead to distinct internal
-        states.
-
-        This is obsolete, provided for compatibility with the seed routine
-        used prior to Python 2.1.  Use the .seed() method instead.
-        """
-
-        if a is None:
-            self.__whseed()
-            return
-        a = hash(a)
-        a, x = divmod(a, 256)
-        a, y = divmod(a, 256)
-        a, z = divmod(a, 256)
-        x = (x + a) % 256 or 1
-        y = (y + a) % 256 or 1
-        z = (z + a) % 256 or 1
-        self.__whseed(x, y, z)
-
 ## --------------- Operating System Random Source  ------------------
 
 class SystemRandom(Random):
@@ -778,10 +643,9 @@
         x = int(_hexlify(_urandom(bytes)), 16)
         return x >> (bytes * 8 - k)             # trim excess bits
 
-    def _stub(self, *args, **kwds):
+    def seed(self, *args, **kwds):
         "Stub method.  Not used for a system random number generator."
         return None
-    seed = jumpahead = _stub
 
     def _notimplemented(self, *args, **kwds):
         "Method should not be called for a system random number generator."
@@ -828,6 +692,7 @@
     _test_generator(N, gammavariate, (200.0, 1.0))
     _test_generator(N, gauss, (0.0, 1.0))
     _test_generator(N, betavariate, (3.0, 3.0))
+    _test_generator(N, triangular, (0.0, 1.0, 1.0/3.0))
 
 # Create one instance, seeded from current time, and export its methods
 # as module-level functions.  The functions share state across all uses
@@ -839,6 +704,7 @@
 seed = _inst.seed
 random = _inst.random
 uniform = _inst.uniform
+triangular = _inst.triangular
 randint = _inst.randint
 choice = _inst.choice
 randrange = _inst.randrange
@@ -855,7 +721,6 @@
 weibullvariate = _inst.weibullvariate
 getstate = _inst.getstate
 setstate = _inst.setstate
-jumpahead = _inst.jumpahead
 getrandbits = _inst.getrandbits
 
 if __name__ == '__main__':

Modified: python/branches/py3k-importlib/Lib/re.py
==============================================================================
--- python/branches/py3k-importlib/Lib/re.py	(original)
+++ python/branches/py3k-importlib/Lib/re.py	Thu Mar 27 00:48:05 2008
@@ -29,7 +29,8 @@
 The special characters are:
     "."      Matches any character except a newline.
     "^"      Matches the start of the string.
-    "$"      Matches the end of the string.
+    "$"      Matches the end of the string or just before the newline at
+             the end of the string.
     "*"      Matches 0 or more (greedy) repetitions of the preceding RE.
              Greedy means that it will match as many repetitions as possible.
     "+"      Matches 1 or more (greedy) repetitions of the preceding RE.
@@ -37,7 +38,7 @@
     *?,+?,?? Non-greedy versions of the previous three special characters.
     {m,n}    Matches from m to n repetitions of the preceding RE.
     {m,n}?   Non-greedy version of the above.
-    "\\"      Either escapes special characters or signals a special sequence.
+    "\\"     Either escapes special characters or signals a special sequence.
     []       Indicates a set of characters.
              A "^" as the first character indicates a complementing set.
     "|"      A|B, creates an RE that will match either A or B.
@@ -50,6 +51,10 @@
     (?#...)  A comment; ignored.
     (?=...)  Matches if ... matches next, but doesn't consume the string.
     (?!...)  Matches if ... doesn't match next.
+    (?<=...) Matches if preceded by ... (must be fixed length).
+    (?<!...) Matches if not preceded by ... (must be fixed length).
+    (?(id/name)yes|no) Matches yes pattern if the group with id/name matched,
+                       the (optional) no pattern otherwise.
 
 The special sequences consist of "\\" and a character from the list
 below.  If the ordinary character is not on the list, then the
@@ -76,6 +81,7 @@
     subn     Same as sub, but also return the number of substitutions made.
     split    Split a string by the occurrences of a pattern.
     findall  Find all occurrences of a pattern in a string.
+    finditer Return an iterator yielding a match object for each match.
     compile  Compile a pattern into a RegexObject.
     purge    Clear the regular expression cache.
     escape   Backslash all non-alphanumerics in a string.
@@ -83,8 +89,10 @@
 Some of the functions in this module takes flags as optional parameters:
     I  IGNORECASE  Perform case-insensitive matching.
     L  LOCALE      Make \w, \W, \b, \B, dependent on the current locale.
-    M  MULTILINE   "^" matches the beginning of lines as well as the string.
-                   "$" matches the end of lines as well as the string.
+    M  MULTILINE   "^" matches the beginning of lines (after a newline)
+                   as well as the string.
+                   "$" matches the end of lines (before a newline) as well
+                   as the end of the string.
     S  DOTALL      "." matches any character at all, including the newline.
     X  VERBOSE     Ignore whitespace and comments for nicer looking RE's.
     U  UNICODE     Make \w, \W, \b, \B, dependent on the Unicode locale.
@@ -224,6 +232,8 @@
         return p
     pattern, flags = key
     if isinstance(pattern, _pattern_type):
+        if flags:
+            raise ValueError('Cannot process flags argument with a compiled pattern')
         return pattern
     if not sre_compile.isstring(pattern):
         raise TypeError("first argument must be string or compiled pattern")
@@ -284,8 +294,8 @@
             p.append(sre_parse.SubPattern(s, [
                 (SUBPATTERN, (len(p)+1, sre_parse.parse(phrase, flags))),
                 ]))
+        s.groups = len(p)+1
         p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
-        s.groups = len(p)
         self.scanner = sre_compile.compile(p)
     def scan(self, string):
         result = []

Modified: python/branches/py3k-importlib/Lib/repr.py
==============================================================================
--- python/branches/py3k-importlib/Lib/repr.py	(original)
+++ python/branches/py3k-importlib/Lib/repr.py	Thu Mar 27 00:48:05 2008
@@ -2,7 +2,7 @@
 
 __all__ = ["Repr","repr"]
 
-import __builtin__
+import builtins
 from itertools import islice
 
 class Repr:
@@ -84,16 +84,16 @@
         return '{%s}' % (s,)
 
     def repr_str(self, x, level):
-        s = __builtin__.repr(x[:self.maxstring])
+        s = builtins.repr(x[:self.maxstring])
         if len(s) > self.maxstring:
             i = max(0, (self.maxstring-3)//2)
             j = max(0, self.maxstring-3-i)
-            s = __builtin__.repr(x[:i] + x[len(x)-j:])
+            s = builtins.repr(x[:i] + x[len(x)-j:])
             s = s[:i] + '...' + s[len(s)-j:]
         return s
 
     def repr_int(self, x, level):
-        s = __builtin__.repr(x) # XXX Hope this isn't too slow...
+        s = builtins.repr(x) # XXX Hope this isn't too slow...
         if len(s) > self.maxlong:
             i = max(0, (self.maxlong-3)//2)
             j = max(0, self.maxlong-3-i)
@@ -102,7 +102,7 @@
 
     def repr_instance(self, x, level):
         try:
-            s = __builtin__.repr(x)
+            s = builtins.repr(x)
             # Bugs in x.__repr__() can cause arbitrary
             # exceptions -- then make up something
         except Exception:

Modified: python/branches/py3k-importlib/Lib/rlcompleter.py
==============================================================================
--- python/branches/py3k-importlib/Lib/rlcompleter.py	(original)
+++ python/branches/py3k-importlib/Lib/rlcompleter.py	Thu Mar 27 00:48:05 2008
@@ -33,7 +33,7 @@
 
 """
 
-import __builtin__
+import builtins
 import __main__
 
 __all__ = ["Completer"]
@@ -97,7 +97,7 @@
         matches = []
         n = len(text)
         for list in [keyword.kwlist,
-                     __builtin__.__dict__,
+                     builtins.__dict__,
                      self.namespace]:
             for word in list:
                 if word[:n] == text and word != "__builtins__":
@@ -119,7 +119,7 @@
         import re
         m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text)
         if not m:
-            return
+            return []
         expr, attr = m.group(1, 3)
         object = eval(expr, self.namespace)
         words = dir(object)

Modified: python/branches/py3k-importlib/Lib/runpy.py
==============================================================================
--- python/branches/py3k-importlib/Lib/runpy.py	(original)
+++ python/branches/py3k-importlib/Lib/runpy.py	Thu Mar 27 00:48:05 2008
@@ -23,19 +23,20 @@
 
 def _run_code(code, run_globals, init_globals=None,
               mod_name=None, mod_fname=None,
-              mod_loader=None):
+              mod_loader=None, pkg_name=None):
     """Helper for _run_module_code"""
     if init_globals is not None:
         run_globals.update(init_globals)
     run_globals.update(__name__ = mod_name,
                        __file__ = mod_fname,
-                       __loader__ = mod_loader)
+                       __loader__ = mod_loader,
+                       __package__ = pkg_name)
     exec(code, run_globals)
     return run_globals
 
 def _run_module_code(code, init_globals=None,
                     mod_name=None, mod_fname=None,
-                    mod_loader=None):
+                    mod_loader=None, pkg_name=None):
     """Helper for run_module"""
     # Set up the top level namespace dictionary
     temp_module = imp.new_module(mod_name)
@@ -49,7 +50,8 @@
     sys.modules[mod_name] = temp_module
     try:
         _run_code(code, mod_globals, init_globals,
-                    mod_name, mod_fname, mod_loader)
+                    mod_name, mod_fname,
+                    mod_loader, pkg_name)
     finally:
         sys.argv[0] = saved_argv0
         if restore_module:
@@ -87,6 +89,9 @@
 
 
 # XXX ncoghlan: Should this be documented and made public?
+# (Current thoughts: don't repeat the mistake that lead to its
+# creation when run_module() no longer met the needs of
+# mainmodule.c, but couldn't be changed because it was public)
 def _run_module_as_main(mod_name, set_argv0=True):
     """Runs the designated module in the __main__ namespace
 
@@ -94,12 +99,26 @@
            __file__
            __loader__
     """
-    loader, code, fname = _get_module_details(mod_name)
+    try:
+        loader, code, fname = _get_module_details(mod_name)
+    except ImportError as exc:
+        # Try to provide a good error message
+        # for directories, zip files and the -m switch
+        if set_argv0:
+            # For -m switch, just disply the exception
+            info = str(exc)
+        else:
+            # For directories/zipfiles, let the user
+            # know what the code was looking for
+            info = "can't find '__main__.py' in %r" % sys.argv[0]
+        msg = "%s: %s" % (sys.executable, info)
+        sys.exit(msg)
+    pkg_name = mod_name.rpartition('.')[0]
     main_globals = sys.modules["__main__"].__dict__
     if set_argv0:
         sys.argv[0] = fname
     return _run_code(code, main_globals, None,
-                     "__main__", fname, loader)
+                     "__main__", fname, loader, pkg_name)
 
 def run_module(mod_name, init_globals=None,
                run_name=None, alter_sys=False):
@@ -110,13 +129,14 @@
     loader, code, fname = _get_module_details(mod_name)
     if run_name is None:
         run_name = mod_name
+    pkg_name = mod_name.rpartition('.')[0]
     if alter_sys:
         return _run_module_code(code, init_globals, run_name,
-                                fname, loader)
+                                fname, loader, pkg_name)
     else:
         # Leave the sys module alone
-        return _run_code(code, {}, init_globals,
-                         run_name, fname, loader)
+        return _run_code(code, {}, init_globals, run_name,
+                         fname, loader, pkg_name)
 
 
 if __name__ == "__main__":

Modified: python/branches/py3k-importlib/Lib/sched.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sched.py	(original)
+++ python/branches/py3k-importlib/Lib/sched.py	Thu Mar 27 00:48:05 2008
@@ -16,11 +16,11 @@
 Events are specified by tuples (time, priority, action, argument).
 As in UNIX, lower priority numbers mean higher priority; in this
 way the queue can be maintained as a priority queue.  Execution of the
-event means calling the action function, passing it the argument.
-Remember that in Python, multiple function arguments can be packed
-in a tuple.   The action function may be an instance method so it
+event means calling the action function, passing it the argument
+sequence in "argument" (remember that in Python, multiple function
+arguments are be packed in a sequence).
+The action function may be an instance method so it
 has another way to reference private data (besides global variables).
-Parameterless functions or methods cannot be used, however.
 """
 
 # XXX The timefunc and delayfunc should have been defined as methods
@@ -29,14 +29,17 @@
 # XXX the global state of your particular time and delay functions.
 
 import heapq
+from collections import namedtuple
 
 __all__ = ["scheduler"]
 
+Event = namedtuple('Event', 'time, priority, action, argument')
+
 class scheduler:
     def __init__(self, timefunc, delayfunc):
         """Initialize a new instance, passing the time and delay
         functions"""
-        self.queue = []
+        self._queue = []
         self.timefunc = timefunc
         self.delayfunc = delayfunc
 
@@ -47,8 +50,8 @@
         if necessary.
 
         """
-        event = time, priority, action, argument
-        heapq.heappush(self.queue, event)
+        event = Event(time, priority, action, argument)
+        heapq.heappush(self._queue, event)
         return event # The ID
 
     def enter(self, delay, priority, action, argument):
@@ -67,12 +70,12 @@
         If the event is not in the queue, this raises RuntimeError.
 
         """
-        self.queue.remove(event)
-        heapq.heapify(self.queue)
+        self._queue.remove(event)
+        heapq.heapify(self._queue)
 
     def empty(self):
         """Check whether the queue is empty."""
-        return not self.queue
+        return not self._queue
 
     def run(self):
         """Execute events until the queue is empty.
@@ -89,7 +92,7 @@
         exceptions are not caught but the scheduler's state remains
         well-defined so run() may be called again.
 
-        A questionably hack is added to allow other threads to run:
+        A questionable hack is added to allow other threads to run:
         just after an event is executed, a delay of 0 is executed, to
         avoid monopolizing the CPU when other threads are also
         runnable.
@@ -97,7 +100,7 @@
         """
         # localize variable access to minimize overhead
         # and to improve thread safety
-        q = self.queue
+        q = self._queue
         delayfunc = self.delayfunc
         timefunc = self.timefunc
         pop = heapq.heappop
@@ -111,7 +114,21 @@
                 # Verify that the event was not removed or altered
                 # by another thread after we last looked at q[0].
                 if event is checked_event:
-                    void = action(*argument)
+                    action(*argument)
                     delayfunc(0)   # Let other threads run
                 else:
                     heapq.heappush(event)
+
+    @property
+    def queue(self):
+        """An ordered list of upcoming events.
+
+        Events are named tuples with fields for:
+            time, priority, action, arguments
+
+        """
+        # Use heapq to sort the queue rather than using 'sorted(self._queue)'.
+        # With heapq, two events scheduled at the same time will show in
+        # the actual order they would be retrieved.
+        events = self._queue[:]
+        return map(heapq.heappop, [events]*len(events))

Modified: python/branches/py3k-importlib/Lib/sgmllib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sgmllib.py	(original)
+++ python/branches/py3k-importlib/Lib/sgmllib.py	Thu Mar 27 00:48:05 2008
@@ -9,7 +9,7 @@
 # not supported at all.
 
 
-import markupbase
+import _markupbase
 import re
 
 __all__ = ["SGMLParser", "SGMLParseError"]
@@ -52,7 +52,7 @@
 # chunks).  Entity references are passed by calling
 # self.handle_entityref() with the entity reference as argument.
 
-class SGMLParser(markupbase.ParserBase):
+class SGMLParser(_markupbase.ParserBase):
     # Definition of entities -- derived classes may override
     entity_or_charref = re.compile('&(?:'
       '([a-zA-Z][-.a-zA-Z0-9]*)|#([0-9]+)'
@@ -71,7 +71,7 @@
         self.lasttag = '???'
         self.nomoretags = 0
         self.literal = 0
-        markupbase.ParserBase.reset(self)
+        _markupbase.ParserBase.reset(self)
 
     def setnomoretags(self):
         """Enter literal mode (CDATA) till EOF.

Modified: python/branches/py3k-importlib/Lib/shelve.py
==============================================================================
--- python/branches/py3k-importlib/Lib/shelve.py	(original)
+++ python/branches/py3k-importlib/Lib/shelve.py	Thu Mar 27 00:48:05 2008
@@ -59,12 +59,12 @@
 from pickle import Pickler, Unpickler
 from io import BytesIO
 
-import UserDict
+import collections
 import warnings
 
 __all__ = ["Shelf","BsdDbShelf","DbfilenameShelf","open"]
 
-class Shelf(UserDict.DictMixin):
+class Shelf(collections.MutableMapping):
     """Base class for shelf implementations.
 
     This is initialized with a dictionary-like object.
@@ -75,13 +75,13 @@
                  keyencoding="utf-8"):
         self.dict = dict
         if protocol is None:
-            protocol = 0
+            protocol = 2
         self._protocol = protocol
         self.writeback = writeback
         self.cache = {}
         self.keyencoding = "utf-8"
 
-    def keys(self):
+    def __iter__(self):
         for k in self.dict.keys():
             yield k.decode(self.keyencoding)
 

Modified: python/branches/py3k-importlib/Lib/shlex.py
==============================================================================
--- python/branches/py3k-importlib/Lib/shlex.py	(original)
+++ python/branches/py3k-importlib/Lib/shlex.py	Thu Mar 27 00:48:05 2008
@@ -18,7 +18,7 @@
 class shlex:
     "A lexical analyzer class for simple shell-like syntaxes."
     def __init__(self, instream=None, infile=None, posix=False):
-        if isinstance(instream, basestring):
+        if isinstance(instream, str):
             instream = StringIO(instream)
         if instream is not None:
             self.instream = instream
@@ -61,7 +61,7 @@
 
     def push_source(self, newstream, newfile=None):
         "Push an input source onto the lexer's input source stack."
-        if isinstance(newstream, basestring):
+        if isinstance(newstream, str):
             newstream = StringIO(newstream)
         self.filestack.appendleft((self.infile, self.instream, self.lineno))
         self.infile = newfile
@@ -247,7 +247,7 @@
         if newfile[0] == '"':
             newfile = newfile[1:-1]
         # This implements cpp-like semantics for relative-path inclusion.
-        if isinstance(self.infile, basestring) and not os.path.isabs(newfile):
+        if isinstance(self.infile, str) and not os.path.isabs(newfile):
             newfile = os.path.join(os.path.dirname(self.infile), newfile)
         return (newfile, open(newfile, "r"))
 

Modified: python/branches/py3k-importlib/Lib/shutil.py
==============================================================================
--- python/branches/py3k-importlib/Lib/shutil.py	(original)
+++ python/branches/py3k-importlib/Lib/shutil.py	Thu Mar 27 00:48:05 2008
@@ -156,6 +156,14 @@
     elif onerror is None:
         def onerror(*args):
             raise
+    try:
+        if os.path.islink(path):
+            # symlinks to directories are forbidden, see bug #1669
+            raise OSError("Cannot call rmtree on a symbolic link")
+    except OSError:
+        onerror(os.path.islink, path, sys.exc_info())
+        # can't continue even if onerror hook returns
+        return
     names = []
     try:
         names = os.listdir(path)
@@ -179,26 +187,44 @@
     except os.error:
         onerror(os.rmdir, path, sys.exc_info())
 
+
+def _basename(path):
+    # A basename() variant which first strips the trailing slash, if present.
+    # Thus we always get the last component of the path, even for directories.
+    return os.path.basename(path.rstrip(os.path.sep))
+
 def move(src, dst):
-    """Recursively move a file or directory to another location.
+    """Recursively move a file or directory to another location. This is
+    similar to the Unix "mv" command.
 
-    If the destination is on our current filesystem, then simply use
-    rename.  Otherwise, copy src to the dst and then remove src.
+    If the destination is a directory or a symlink to a directory, the source
+    is moved inside the directory. The destination path must not already
+    exist.
+
+    If the destination already exists but is not a directory, it may be
+    overwritten depending on os.rename() semantics.
+
+    If the destination is on our current filesystem, then rename() is used.
+    Otherwise, src is copied to the destination and then removed.
     A lot more could be done here...  A look at a mv.c shows a lot of
     the issues this implementation glosses over.
 
     """
-
+    real_dst = dst
+    if os.path.isdir(dst):
+        real_dst = os.path.join(dst, _basename(src))
+        if os.path.exists(real_dst):
+            raise Error("Destination path '%s' already exists" % real_dst)
     try:
-        os.rename(src, dst)
+        os.rename(src, real_dst)
     except OSError:
         if os.path.isdir(src):
             if destinsrc(src, dst):
                 raise Error("Cannot move a directory '%s' into itself '%s'." % (src, dst))
-            copytree(src, dst, symlinks=True)
+            copytree(src, real_dst, symlinks=True)
             rmtree(src)
         else:
-            copy2(src,dst)
+            copy2(src, real_dst)
             os.unlink(src)
 
 def destinsrc(src, dst):

Modified: python/branches/py3k-importlib/Lib/site.py
==============================================================================
--- python/branches/py3k-importlib/Lib/site.py	(original)
+++ python/branches/py3k-importlib/Lib/site.py	Thu Mar 27 00:48:05 2008
@@ -4,12 +4,6 @@
 * This module is automatically imported during initialization. *
 ****************************************************************
 
-In earlier versions of Python (up to 1.5a3), scripts or modules that
-needed to use site-specific modules would place ``import site''
-somewhere near the top of their code.  Because of the automatic
-import, this is no longer necessary (but code that does it still
-works).
-
 This will append site-specific paths to the module search path.  On
 Unix (including Mac OSX), it starts with sys.prefix and
 sys.exec_prefix (if different) and appends
@@ -60,7 +54,7 @@
 
 import sys
 import os
-import __builtin__
+import builtins
 
 
 def makepath(*paths):
@@ -102,6 +96,8 @@
     (especially for Guido :-)"""
     from distutils.util import get_platform
     s = "build/lib.%s-%.3s" % (get_platform(), sys.version)
+    if hasattr(sys, 'gettotalrefcount'):
+        s += '-pydebug'
     s = os.path.join(os.path.dirname(sys.path[-1]), s)
     sys.path.append(s)
 
@@ -247,12 +243,17 @@
             # Shells like IDLE catch the SystemExit, but listen when their
             # stdin wrapper is closed.
             try:
-                sys.stdin.close()
+                fd = -1
+                if hasattr(sys.stdin, "fileno"):
+                    fd = sys.stdin.fileno()
+                if fd != 0:
+                    # Don't close stdin if it wraps fd 0
+                    sys.stdin.close()
             except:
                 pass
             raise SystemExit(code)
-    __builtin__.quit = Quitter('quit')
-    __builtin__.exit = Quitter('exit')
+    builtins.quit = Quitter('quit')
+    builtins.exit = Quitter('exit')
 
 
 class _Printer(object):
@@ -310,27 +311,25 @@
                 lineno += self.MAXLINES
                 key = None
                 while key is None:
-                    sys.stdout.write(prompt)
-                    sys.stdout.flush()
-                    key = sys.stdin.readline()
+                    key = input(prompt)
                     if key not in ('', 'q'):
                         key = None
                 if key == 'q':
                     break
 
 def setcopyright():
-    """Set 'copyright' and 'credits' in __builtin__"""
-    __builtin__.copyright = _Printer("copyright", sys.copyright)
+    """Set 'copyright' and 'credits' in builtins"""
+    builtins.copyright = _Printer("copyright", sys.copyright)
     if sys.platform[:4] == 'java':
-        __builtin__.credits = _Printer(
+        builtins.credits = _Printer(
             "credits",
             "Jython is maintained by the Jython developers (www.jython.org).")
     else:
-        __builtin__.credits = _Printer("credits", """\
+        builtins.credits = _Printer("credits", """\
     Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
     for supporting Python development.  See www.python.org for more information.""")
     here = os.path.dirname(os.__file__)
-    __builtin__.license = _Printer(
+    builtins.license = _Printer(
         "license", "See http://www.python.org/%.3s/license.html" % sys.version,
         ["LICENSE.txt", "LICENSE"],
         [os.path.join(here, os.pardir), here, os.curdir])
@@ -350,7 +349,7 @@
         return pydoc.help(*args, **kwds)
 
 def sethelper():
-    __builtin__.help = _Helper()
+    builtins.help = _Helper()
 
 def aliasmbcs():
     """On Windows, some default encodings are not provided by Python,
@@ -402,23 +401,6 @@
             (err.__class__.__name__, err))
 
 
-def installnewio():
-    """Install new I/O library as default."""
-    import io
-    # Hack to avoid a nasty recursion issue when Python is invoked
-    # in verbose mode: pre-import the Latin-1 and UTF-8 codecs
-    from encodings import latin_1, utf_8
-    # Trick so that open won't become a bound method when stored
-    # as a class variable (as dumbdbm does)
-    class open:
-        def __new__(cls, *args, **kwds):
-            return io.open(*args, **kwds)
-    __builtin__.open = open
-    sys.__stdin__ = sys.stdin = io.open(0, "r", newline='\n')
-    sys.__stdout__ = sys.stdout = io.open(1, "w", newline='\n')
-    sys.__stderr__ = sys.stderr = io.open(2, "w", newline='\n')
-
-
 def main():
     abs__file__()
     paths_in_sys = removeduppaths()
@@ -433,7 +415,6 @@
     sethelper()
     aliasmbcs()
     setencoding()
-    installnewio()
     execsitecustomize()
     # Remove sys.setdefaultencoding() so that users cannot change the
     # encoding after initialization.  The test for presence is needed when

Modified: python/branches/py3k-importlib/Lib/smtpd.py
==============================================================================
--- python/branches/py3k-importlib/Lib/smtpd.py	(original)
+++ python/branches/py3k-importlib/Lib/smtpd.py	Thu Mar 27 00:48:05 2008
@@ -221,7 +221,7 @@
 
     def smtp_MAIL(self, arg):
         print('===> MAIL', arg, file=DEBUGSTREAM)
-        address = self.__getaddr('FROM:', arg)
+        address = self.__getaddr('FROM:', arg) if arg else None
         if not address:
             self.push('501 Syntax: MAIL FROM:<address>')
             return
@@ -237,7 +237,7 @@
         if not self.__mailfrom:
             self.push('503 Error: need MAIL command')
             return
-        address = self.__getaddr('TO:', arg)
+        address = self.__getaddr('TO:', arg) if arg else None
         if not address:
             self.push('501 Syntax: RCPT TO: <address>')
             return

Modified: python/branches/py3k-importlib/Lib/smtplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/smtplib.py	(original)
+++ python/branches/py3k-importlib/Lib/smtplib.py	Thu Mar 27 00:48:05 2008
@@ -174,6 +174,7 @@
             chr = None
             while chr != b"\n":
                 chr = self.sslobj.read(1)
+                if not chr: break
                 str += chr
             return str
 
@@ -264,11 +265,11 @@
         """
         self.debuglevel = debuglevel
 
-    def _get_socket(self, port, host, timeout):
+    def _get_socket(self, host, port, timeout):
         # This makes it simpler for SMTP_SSL to use the SMTP connect code
         # and just alter the socket connection bit.
         if self.debuglevel > 0: print('connect:', (host, port), file=stderr)
-        return socket.create_connection((port, host), timeout)
+        return socket.create_connection((host, port), timeout)
 
     def connect(self, host='localhost', port = 0):
         """Connect to a host on a given port.
@@ -295,12 +296,14 @@
         if self.debuglevel > 0: print("connect:", msg, file=stderr)
         return (code, msg)
 
-    def send(self, str):
-        """Send `str' to the server."""
-        if self.debuglevel > 0: print('send:', repr(str), file=stderr)
-        if self.sock:
+    def send(self, s):
+        """Send `s' to the server."""
+        if self.debuglevel > 0: print('send:', repr(s), file=stderr)
+        if hasattr(self, 'sock') and self.sock:
+            if isinstance(s, str):
+                s = s.encode("ascii")
             try:
-                self.sock.sendall(str)
+                self.sock.sendall(s)
             except socket.error:
                 self.close()
                 raise SMTPServerDisconnected('Server not connected')
@@ -487,12 +490,29 @@
     vrfy=verify
 
     def expn(self, address):
-        """SMTP 'verify' command -- checks for address validity."""
+        """SMTP 'expn' command -- expands a mailing list."""
         self.putcmd("expn", quoteaddr(address))
         return self.getreply()
 
     # some useful methods
 
+    def ehlo_or_helo_if_needed(self):
+        """Call self.ehlo() and/or self.helo() if needed.
+
+        If there has been no previous EHLO or HELO command this session, this
+        method tries ESMTP EHLO first.
+
+        This method may raise the following exceptions:
+
+         SMTPHeloError            The server didn't reply properly to
+                                  the helo greeting.
+        """
+        if self.helo_resp is None and self.ehlo_resp is None:
+            if not (200 <= self.ehlo()[0] <= 299):
+                (code, resp) = self.helo()
+                if not (200 <= code <= 299):
+                    raise SMTPHeloError(code, resp)
+
     def login(self, user, password):
         """Log in on an SMTP server that requires authentication.
 
@@ -528,11 +548,7 @@
         AUTH_CRAM_MD5 = "CRAM-MD5"
         AUTH_LOGIN = "LOGIN"
 
-        if self.helo_resp is None and self.ehlo_resp is None:
-            if not (200 <= self.ehlo()[0] <= 299):
-                (code, resp) = self.helo()
-                if not (200 <= code <= 299):
-                    raise SMTPHeloError(code, resp)
+        self.ehlo_or_helo_if_needed()
 
         if not self.has_extn("auth"):
             raise SMTPException("SMTP AUTH extension not supported by server.")
@@ -578,18 +594,37 @@
     def starttls(self, keyfile = None, certfile = None):
         """Puts the connection to the SMTP server into TLS mode.
 
+        If there has been no previous EHLO or HELO command this session, this
+        method tries ESMTP EHLO first.
+
         If the server supports TLS, this will encrypt the rest of the SMTP
         session. If you provide the keyfile and certfile parameters,
         the identity of the SMTP server and client can be checked. This,
         however, depends on whether the socket module really checks the
         certificates.
+
+        This method may raise the following exceptions:
+
+         SMTPHeloError            The server didn't reply properly to
+                                  the helo greeting.
         """
+        self.ehlo_or_helo_if_needed()
+        if not self.has_extn("starttls"):
+            raise SMTPException("STARTTLS extension not supported by server.")
         (resp, reply) = self.docmd("STARTTLS")
         if resp == 220:
             if not _have_ssl:
                 raise RuntimeError("No SSL support included in this Python")
             self.sock = ssl.wrap_socket(self.sock, keyfile, certfile)
             self.file = SSLFakeFile(self.sock)
+            # RFC 3207:
+            # The client MUST discard any knowledge obtained from
+            # the server, such as the list of SMTP service extensions,
+            # which was not obtained from the TLS negotiation itself.
+            self.helo_resp = None
+            self.ehlo_resp = None
+            self.esmtp_features = {}
+            self.does_esmtp = 0
         return (resp, reply)
 
     def sendmail(self, from_addr, to_addrs, msg, mail_options=[],
@@ -649,11 +684,7 @@
         empty dictionary.
 
         """
-        if self.helo_resp is None and self.ehlo_resp is None:
-            if not (200 <= self.ehlo()[0] <= 299):
-                (code,resp) = self.helo()
-                if not (200 <= code <= 299):
-                    raise SMTPHeloError(code, resp)
+        self.ehlo_or_helo_if_needed()
         esmtp_opts = []
         if self.does_esmtp:
             # Hmmm? what's this? -ddm
@@ -668,7 +699,7 @@
             self.rset()
             raise SMTPSenderRefused(code, resp, from_addr)
         senderrs={}
-        if isinstance(to_addrs, basestring):
+        if isinstance(to_addrs, str):
             to_addrs = [to_addrs]
         for each in to_addrs:
             (code,resp)=self.rcpt(each, rcpt_options)

Modified: python/branches/py3k-importlib/Lib/socket.py
==============================================================================
--- python/branches/py3k-importlib/Lib/socket.py	(original)
+++ python/branches/py3k-importlib/Lib/socket.py	Thu Mar 27 00:48:05 2008
@@ -21,7 +21,6 @@
 htons(), htonl() -- convert 16, 32 bit int from host to network byte order
 inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format
 inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)
-ssl() -- secure socket layer support (only available if configured)
 socket.getdefaulttimeout() -- get the default timeout value
 socket.setdefaulttimeout() -- set the default timeout value
 create_connection() -- connects to an address, with an optional timeout
@@ -46,36 +45,6 @@
 import _socket
 from _socket import *
 
-try:
-    import _ssl
-    import ssl as _realssl
-except ImportError:
-    # no SSL support
-    pass
-else:
-    def ssl(sock, keyfile=None, certfile=None):
-        # we do an internal import here because the ssl
-        # module imports the socket module
-        warnings.warn("socket.ssl() is deprecated.  Use ssl.wrap_socket() instead.",
-                      DeprecationWarning, stacklevel=2)
-        return _realssl.sslwrap_simple(sock, keyfile, certfile)
-
-    # we need to import the same constants we used to...
-    from _ssl import SSLError as sslerror
-    from _ssl import \
-         RAND_add, \
-         RAND_egd, \
-         RAND_status, \
-         SSL_ERROR_ZERO_RETURN, \
-         SSL_ERROR_WANT_READ, \
-         SSL_ERROR_WANT_WRITE, \
-         SSL_ERROR_WANT_X509_LOOKUP, \
-         SSL_ERROR_SYSCALL, \
-         SSL_ERROR_SSL, \
-         SSL_ERROR_WANT_CONNECT, \
-         SSL_ERROR_EOF, \
-         SSL_ERROR_INVALID_ERROR_CODE
-
 import os, sys, io
 
 try:
@@ -110,95 +79,50 @@
     __all__.append("errorTab")
 
 
-# True if os.dup() can duplicate socket descriptors.
-# (On Windows at least, os.dup only works on files)
-_can_dup_socket = hasattr(_socket.socket, "dup")
-
-if _can_dup_socket:
-    def fromfd(fd, family=AF_INET, type=SOCK_STREAM, proto=0):
-        nfd = os.dup(fd)
-        return socket(family, type, proto, fileno=nfd)
-
-class SocketCloser:
-
-    """Helper to manage socket close() logic for makefile().
-
-    The OS socket should not be closed until the socket and all
-    of its makefile-children are closed.  If the refcount is zero
-    when socket.close() is called, this is easy: Just close the
-    socket.  If the refcount is non-zero when socket.close() is
-    called, then the real close should not occur until the last
-    makefile-child is closed.
-    """
-
-    def __init__(self, sock):
-        self._sock = sock
-        self._makefile_refs = 0
-        # Test whether the socket is open.
-        try:
-            sock.fileno()
-            self._socket_open = True
-        except error:
-            self._socket_open = False
-
-    def socket_close(self):
-        self._socket_open = False
-        self.close()
-
-    def makefile_open(self):
-        self._makefile_refs += 1
-
-    def makefile_close(self):
-        self._makefile_refs -= 1
-        self.close()
-
-    def close(self):
-        if not (self._socket_open or self._makefile_refs):
-            self._sock._real_close()
-
-
 class socket(_socket.socket):
 
     """A subclass of _socket.socket adding the makefile() method."""
 
-    __slots__ = ["__weakref__", "_closer"]
-    if not _can_dup_socket:
-        __slots__.append("_base")
+    __slots__ = ["__weakref__", "_io_refs", "_closed"]
 
     def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None):
-        if fileno is None:
-            _socket.socket.__init__(self, family, type, proto)
-        else:
-            _socket.socket.__init__(self, family, type, proto, fileno)
-        # Defer creating a SocketCloser until makefile() is actually called.
-        self._closer = None
+        _socket.socket.__init__(self, family, type, proto, fileno)
+        self._io_refs = 0
+        self._closed = False
 
     def __repr__(self):
         """Wrap __repr__() to reveal the real class name."""
         s = _socket.socket.__repr__(self)
         if s.startswith("<socket object"):
-            s = "<%s.%s%s" % (self.__class__.__module__,
-                              self.__class__.__name__,
-                              s[7:])
+            s = "<%s.%s%s%s" % (self.__class__.__module__,
+                                self.__class__.__name__,
+                                (self._closed and " [closed] ") or "",
+                                s[7:])
         return s
 
+    def dup(self):
+        """dup() -> socket object
+
+        Return a new socket object connected to the same system resource.
+        """
+        fd = dup(self.fileno())
+        sock = self.__class__(self.family, self.type, self.proto, fileno=fd)
+        sock.settimeout(self.gettimeout())
+        return sock
+
     def accept(self):
-        """Wrap accept() to give the connection the right type."""
-        conn, addr = _socket.socket.accept(self)
-        fd = conn.fileno()
-        nfd = fd
-        if _can_dup_socket:
-            nfd = os.dup(fd)
-        wrapper = socket(self.family, self.type, self.proto, fileno=nfd)
-        if fd == nfd:
-            wrapper._base = conn  # Keep the base alive
-        else:
-            conn.close()
-        return wrapper, addr
+        """accept() -> (socket object, address info)
+
+        Wait for an incoming connection.  Return a new socket
+        representing the connection, and the address of the client.
+        For IP sockets, the address info is a pair (hostaddr, port).
+        """
+        fd, addr = self._accept()
+        return socket(self.family, self.type, self.proto, fileno=fd), addr
 
     def makefile(self, mode="r", buffering=None, *,
                  encoding=None, newline=None):
-        """Return an I/O stream connected to the socket.
+        """makefile(...) -> an I/O stream connected to the socket
 
         The arguments are as for io.open() after the filename,
         except the only mode characters supported are 'r', 'w' and 'b'.
@@ -216,9 +140,8 @@
             rawmode += "r"
         if writing:
             rawmode += "w"
-        if self._closer is None:
-            self._closer = SocketCloser(self)
-        raw = SocketIO(self, rawmode, self._closer)
+        raw = SocketIO(self, rawmode)
+        self._io_refs += 1
         if buffering is None:
             buffering = -1
         if buffering < 0:
@@ -245,24 +168,28 @@
         text.mode = mode
         return text
 
+    def _decref_socketios(self):
+        if self._io_refs > 0:
+            self._io_refs -= 1
+        if self._closed:
+            self.close()
+
+    def _real_close(self):
+        _socket.socket.close(self)
+
     def close(self):
-        if self._closer is None:
+        self._closed = True
+        if self._io_refs <= 0:
             self._real_close()
-        else:
-            self._closer.socket_close()
 
-    # _real_close calls close on the _socket.socket base class.
+def fromfd(fd, family, type, proto=0):
+    """ fromfd(fd, family, type[, proto]) -> socket object
 
-    if not _can_dup_socket:
-        def _real_close(self):
-            _socket.socket.close(self)
-            base = getattr(self, "_base", None)
-            if base is not None:
-                self._base = None
-                base.close()
-    else:
-        def _real_close(self):
-            _socket.socket.close(self)
+    Create a socket object from a duplicate of the given file
+    descriptor.  The remaining arguments are the same as for socket().
+    """
+    nfd = dup(fd)
+    return socket(family, type, proto, nfd)
 
 
 class SocketIO(io.RawIOBase):
@@ -275,16 +202,14 @@
 
     # XXX More docs
 
-    def __init__(self, sock, mode, closer):
+    def __init__(self, sock, mode):
         if mode not in ("r", "w", "rw"):
             raise ValueError("invalid mode: %r" % mode)
         io.RawIOBase.__init__(self)
         self._sock = sock
         self._mode = mode
-        self._closer = closer
         self._reading = "r" in mode
         self._writing = "w" in mode
-        closer.makefile_open()
 
     def readinto(self, b):
         self._checkClosed()
@@ -308,9 +233,11 @@
     def close(self):
         if self.closed:
             return
-        self._closer.makefile_close()
         io.RawIOBase.close(self)
 
+    def __del__(self):
+        self._sock._decref_socketios()
+
 
 def getfqdn(name=''):
     """Get fully qualified domain name from name.

Modified: python/branches/py3k-importlib/Lib/sqlite3/dbapi2.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sqlite3/dbapi2.py	(original)
+++ python/branches/py3k-importlib/Lib/sqlite3/dbapi2.py	Thu Mar 27 00:48:05 2008
@@ -60,13 +60,13 @@
         return val.isoformat(" ")
 
     def convert_date(val):
-        return datetime.date(*map(int, val.split("-")))
+        return datetime.date(*map(int, val.split(b"-")))
 
     def convert_timestamp(val):
-        datepart, timepart = val.split(" ")
-        year, month, day = map(int, datepart.split("-"))
-        timepart_full = timepart.split(".")
-        hours, minutes, seconds = map(int, timepart_full[0].split(":"))
+        datepart, timepart = val.split(b" ")
+        year, month, day = map(int, datepart.split(b"-"))
+        timepart_full = timepart.split(b".")
+        hours, minutes, seconds = map(int, timepart_full[0].split(b":"))
         if len(timepart_full) == 2:
             microseconds = int(timepart_full[1])
         else:

Modified: python/branches/py3k-importlib/Lib/sqlite3/test/factory.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sqlite3/test/factory.py	(original)
+++ python/branches/py3k-importlib/Lib/sqlite3/test/factory.py	Thu Mar 27 00:48:05 2008
@@ -163,8 +163,8 @@
         germany = "Deutchland"
         a_row = self.con.execute("select ?", (austria,)).fetchone()
         d_row = self.con.execute("select ?", (germany,)).fetchone()
-        self.failUnless(type(a_row[0]) == str, "type of non-ASCII row must be unicode")
-        self.failUnless(type(d_row[0]) == str8, "type of ASCII-only row must be str8")
+        self.failUnless(type(a_row[0]) == str, "type of non-ASCII row must be str")
+        self.failUnless(type(d_row[0]) == str, "type of ASCII-only row must be str")
 
     def tearDown(self):
         self.con.close()

Modified: python/branches/py3k-importlib/Lib/sqlite3/test/hooks.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sqlite3/test/hooks.py	(original)
+++ python/branches/py3k-importlib/Lib/sqlite3/test/hooks.py	Thu Mar 27 00:48:05 2008
@@ -21,7 +21,7 @@
 #    misrepresented as being the original software.
 # 3. This notice may not be removed or altered from any source distribution.
 
-import os, unittest
+import unittest
 import sqlite3 as sqlite
 
 class CollationTests(unittest.TestCase):

Modified: python/branches/py3k-importlib/Lib/sqlite3/test/regression.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sqlite3/test/regression.py	(original)
+++ python/branches/py3k-importlib/Lib/sqlite3/test/regression.py	Thu Mar 27 00:48:05 2008
@@ -79,6 +79,20 @@
         cur.fetchone()
         cur.fetchone()
 
+    def CheckErrorMsgDecodeError(self):
+        # When porting the module to Python 3.0, the error message about
+        # decoding errors disappeared. This verifies they're back again.
+        failure = None
+        try:
+            self.con.execute("select 'xxx' || ? || 'yyy' colname", (bytes(bytearray([250])),)).fetchone()
+            failure = "should have raised an OperationalError with detailed description"
+        except sqlite.OperationalError as e:
+            msg = e.args[0]
+            if not msg.startswith("Could not decode to UTF-8 column 'colname' with text 'xxx"):
+                failure = "OperationalError did not have expected description text"
+        if failure:
+            self.fail(failure)
+
 def suite():
     regression_suite = unittest.makeSuite(RegressionTests, "Check")
     return unittest.TestSuite((regression_suite,))

Modified: python/branches/py3k-importlib/Lib/sqlite3/test/transactions.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sqlite3/test/transactions.py	(original)
+++ python/branches/py3k-importlib/Lib/sqlite3/test/transactions.py	Thu Mar 27 00:48:05 2008
@@ -31,7 +31,7 @@
     def setUp(self):
         try:
             os.remove(get_db_path())
-        except:
+        except OSError:
             pass
 
         self.con1 = sqlite.connect(get_db_path(), timeout=0.1)
@@ -47,7 +47,10 @@
         self.cur2.close()
         self.con2.close()
 
-        os.unlink(get_db_path())
+        try:
+            os.unlink(get_db_path())
+        except OSError:
+            pass
 
     def CheckDMLdoesAutoCommitBefore(self):
         self.cur1.execute("create table test(i)")

Modified: python/branches/py3k-importlib/Lib/sqlite3/test/types.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sqlite3/test/types.py	(original)
+++ python/branches/py3k-importlib/Lib/sqlite3/test/types.py	Thu Mar 27 00:48:05 2008
@@ -62,11 +62,12 @@
         self.failUnlessEqual(row[0], val)
 
     def CheckBlob(self):
-        val = memoryview(b"Guglhupf")
+        sample = b"Guglhupf"
+        val = memoryview(sample)
         self.cur.execute("insert into test(b) values (?)", (val,))
         self.cur.execute("select b from test")
         row = self.cur.fetchone()
-        self.failUnlessEqual(row[0], val)
+        self.failUnlessEqual(row[0], sample)
 
     def CheckUnicodeExecute(self):
         self.cur.execute("select 'Österreich'")
@@ -76,6 +77,10 @@
 class DeclTypesTests(unittest.TestCase):
     class Foo:
         def __init__(self, _val):
+            if isinstance(_val, bytes):
+                # sqlite3 always calls __init__ with a bytes created from a
+                # UTF-8 string when __conform__ was used to store the object.
+                _val = _val.decode('utf8')
             self.val = _val
 
         def __cmp__(self, other):
@@ -203,11 +208,12 @@
 
     def CheckBlob(self):
         # default
-        val = memoryview(b"Guglhupf")
+        sample = b"Guglhupf"
+        val = memoryview(sample)
         self.cur.execute("insert into test(bin) values (?)", (val,))
         self.cur.execute("select bin from test")
         row = self.cur.fetchone()
-        self.failUnlessEqual(row[0], val)
+        self.failUnlessEqual(row[0], sample)
 
 class ColNamesTests(unittest.TestCase):
     def setUp(self):
@@ -215,13 +221,11 @@
         self.cur = self.con.cursor()
         self.cur.execute("create table test(x foo)")
 
-        sqlite.converters["FOO"] = lambda x: "[%s]" % x
-        sqlite.converters["BAR"] = lambda x: "<%s>" % x
+        sqlite.converters["BAR"] = lambda x: b"<" + x + b">"
         sqlite.converters["EXC"] = lambda x: 5/0
         sqlite.converters["B1B1"] = lambda x: "MARKER"
 
     def tearDown(self):
-        del sqlite.converters["FOO"]
         del sqlite.converters["BAR"]
         del sqlite.converters["EXC"]
         del sqlite.converters["B1B1"]
@@ -248,14 +252,14 @@
         self.cur.execute("insert into test(x) values (?)", ("xxx",))
         self.cur.execute('select x as "x [bar]" from test')
         val = self.cur.fetchone()[0]
-        self.failUnlessEqual(val, "<xxx>")
+        self.failUnlessEqual(val, b"<xxx>")
 
         # Check if the stripping of colnames works. Everything after the first
         # whitespace should be stripped.
         self.failUnlessEqual(self.cur.description[0][0], "x")
 
     def CheckCaseInConverterName(self):
-        self.cur.execute("""select 'other' as "x [b1b1]\"""")
+        self.cur.execute("select 'other' as \"x [b1b1]\"")
         val = self.cur.fetchone()[0]
         self.failUnlessEqual(val, "MARKER")
 
@@ -337,8 +341,7 @@
         if sqlite.sqlite_version_info < (3, 1):
             return
 
-        # SQLite's current_timestamp uses UTC time, while datetime.datetime.now() uses local time.
-        now = datetime.datetime.now()
+        now = datetime.datetime.utcnow()
         self.cur.execute("insert into test(ts) values (current_timestamp)")
         self.cur.execute("select ts from test")
         ts = self.cur.fetchone()[0]

Modified: python/branches/py3k-importlib/Lib/sqlite3/test/userfunctions.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sqlite3/test/userfunctions.py	(original)
+++ python/branches/py3k-importlib/Lib/sqlite3/test/userfunctions.py	Thu Mar 27 00:48:05 2008
@@ -198,7 +198,7 @@
         cur.execute("select returnblob()")
         val = cur.fetchone()[0]
         self.failUnlessEqual(type(val), bytes)
-        self.failUnlessEqual(val, memoryview(b"blob"))
+        self.failUnlessEqual(val, b"blob")
 
     def CheckFuncException(self):
         cur = self.con.cursor()

Modified: python/branches/py3k-importlib/Lib/sre_compile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sre_compile.py	(original)
+++ python/branches/py3k-importlib/Lib/sre_compile.py	Thu Mar 27 00:48:05 2008
@@ -472,7 +472,7 @@
     code[skip] = len(code) - skip
 
 def isstring(obj):
-    return isinstance(obj, basestring)
+    return isinstance(obj, (str, bytes))
 
 def _code(p, flags):
 
@@ -516,7 +516,7 @@
         indexgroup[i] = k
 
     return _sre.compile(
-        pattern, flags, code,
+        pattern, flags | p.pattern.flags, code,
         p.pattern.groups-1,
         groupindex, indexgroup
         )

Modified: python/branches/py3k-importlib/Lib/sre_parse.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sre_parse.py	(original)
+++ python/branches/py3k-importlib/Lib/sre_parse.py	Thu Mar 27 00:48:05 2008
@@ -152,7 +152,7 @@
         REPEATCODES = (MIN_REPEAT, MAX_REPEAT)
         for op, av in self.data:
             if op is BRANCH:
-                i = sys.maxint
+                i = sys.maxsize
                 j = 0
                 for av in av[1]:
                     l, h = av.getwidth()
@@ -177,7 +177,7 @@
                 hi = hi + 1
             elif op == SUCCESS:
                 break
-        self.width = int(min(lo, sys.maxint)), int(min(hi, sys.maxint))
+        self.width = int(min(lo, sys.maxsize)), int(min(hi, sys.maxsize))
         return self.width
 
 class Tokenizer:
@@ -189,12 +189,18 @@
         if self.index >= len(self.string):
             self.next = None
             return
-        char = self.string[self.index]
-        if char[0] == "\\":
+        char = self.string[self.index:self.index+1]
+        # Special case for the str8, since indexing returns a integer
+        # XXX This is only needed for test_bug_926075 in test_re.py
+        if char and isinstance(char, bytes):
+            char = chr(char[0])
+        if char == "\\":
             try:
                 c = self.string[self.index + 1]
             except IndexError:
                 raise error("bogus escape (end of line)")
+            if isinstance(self.string, bytes):
+                char = chr(c)
             char = char + c
         self.index = self.index + len(char)
         self.next = char

Modified: python/branches/py3k-importlib/Lib/ssl.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ssl.py	(original)
+++ python/branches/py3k-importlib/Lib/ssl.py	Thu Mar 27 00:48:05 2008
@@ -1,10 +1,7 @@
 # Wrapper module for _ssl, providing some additional facilities
 # implemented in Python.  Written by Bill Janssen.
 
-raise ImportError("ssl.py is temporarily out of order")
-
-"""\
-This module provides some more Pythonic support for SSL.
+"""This module provides some more Pythonic support for SSL.
 
 Object types:
 
@@ -57,39 +54,61 @@
 PROTOCOL_TLSv1
 """
 
-import os, sys, textwrap
+import textwrap
 
 import _ssl             # if we can't import it, let the error propagate
 
 from _ssl import SSLError
 from _ssl import CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED
-from _ssl import PROTOCOL_SSLv2, PROTOCOL_SSLv3, PROTOCOL_SSLv23, PROTOCOL_TLSv1
+from _ssl import (PROTOCOL_SSLv2, PROTOCOL_SSLv3, PROTOCOL_SSLv23,
+                  PROTOCOL_TLSv1)
 from _ssl import RAND_status, RAND_egd, RAND_add
-from _ssl import \
-     SSL_ERROR_ZERO_RETURN, \
-     SSL_ERROR_WANT_READ, \
-     SSL_ERROR_WANT_WRITE, \
-     SSL_ERROR_WANT_X509_LOOKUP, \
-     SSL_ERROR_SYSCALL, \
-     SSL_ERROR_SSL, \
-     SSL_ERROR_WANT_CONNECT, \
-     SSL_ERROR_EOF, \
-     SSL_ERROR_INVALID_ERROR_CODE
+from _ssl import (
+    SSL_ERROR_ZERO_RETURN,
+    SSL_ERROR_WANT_READ,
+    SSL_ERROR_WANT_WRITE,
+    SSL_ERROR_WANT_X509_LOOKUP,
+    SSL_ERROR_SYSCALL,
+    SSL_ERROR_SSL,
+    SSL_ERROR_WANT_CONNECT,
+    SSL_ERROR_EOF,
+    SSL_ERROR_INVALID_ERROR_CODE,
+    )
 
-from socket import socket
+from socket import socket, AF_INET, SOCK_STREAM, error
 from socket import getnameinfo as _getnameinfo
+from socket import error as socket_error
+from socket import dup as _dup
 import base64        # for DER-to-PEM translation
+import traceback
 
-class SSLSocket (socket):
+class SSLSocket(socket):
 
     """This class implements a subtype of socket.socket that wraps
     the underlying OS socket in an SSL context when necessary, and
     provides read and write methods over that channel."""
 
-    def __init__(self, sock, keyfile=None, certfile=None,
+    def __init__(self, sock=None, keyfile=None, certfile=None,
                  server_side=False, cert_reqs=CERT_NONE,
-                 ssl_version=PROTOCOL_SSLv23, ca_certs=None):
-        socket.__init__(self, _sock=sock._sock)
+                 ssl_version=PROTOCOL_SSLv23, ca_certs=None,
+                 do_handshake_on_connect=True,
+                 family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None,
+                 suppress_ragged_eofs=True):
+
+        if sock is not None:
+            socket.__init__(self,
+                            family=sock.family,
+                            type=sock.type,
+                            proto=sock.proto,
+                            fileno=_dup(sock.fileno()))
+            sock.close()
+        elif fileno is not None:
+            socket.__init__(self, fileno=fileno)
+        else:
+            socket.__init__(self, family=family, type=type, proto=proto)
+
+        self._closed = False
+
         if certfile and not keyfile:
             keyfile = certfile
         # see if it's connected
@@ -100,99 +119,200 @@
             self._sslobj = None
         else:
             # yes, create the SSL object
-            self._sslobj = _ssl.sslwrap(self._sock, server_side,
-                                        keyfile, certfile,
-                                        cert_reqs, ssl_version, ca_certs)
+            try:
+                self._sslobj = _ssl.sslwrap(self, server_side,
+                                            keyfile, certfile,
+                                            cert_reqs, ssl_version, ca_certs)
+                if do_handshake_on_connect:
+                    timeout = self.gettimeout()
+                    if timeout == 0.0:
+                        # non-blocking
+                        raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
+                    self.do_handshake()
+
+            except socket_error as x:
+                self.close()
+                raise x
+
         self.keyfile = keyfile
         self.certfile = certfile
         self.cert_reqs = cert_reqs
         self.ssl_version = ssl_version
         self.ca_certs = ca_certs
+        self.do_handshake_on_connect = do_handshake_on_connect
+        self.suppress_ragged_eofs = suppress_ragged_eofs
 
-    def read(self, len=1024):
+    def dup(self):
+        raise NotImplemented("Can't dup() %s instances" %
+                             self.__class__.__name__)
+
+    def _checkClosed(self, msg=None):
+        # raise an exception here if you wish to check for spurious closes
+        pass
 
+    def read(self, len=0, buffer=None):
         """Read up to LEN bytes and return them.
         Return zero-length string on EOF."""
 
-        return self._sslobj.read(len)
+        self._checkClosed()
+        try:
+            if buffer:
+                v = self._sslobj.read(buffer, len)
+            else:
+                v = self._sslobj.read(len or 1024)
+            return v
+        except SSLError as x:
+            if x.args[0] == SSL_ERROR_EOF and self.suppress_ragged_eofs:
+                if buffer:
+                    return 0
+                else:
+                    return b''
+            else:
+                raise
 
     def write(self, data):
-
         """Write DATA to the underlying SSL channel.  Returns
         number of bytes of DATA actually transmitted."""
 
+        self._checkClosed()
         return self._sslobj.write(data)
 
     def getpeercert(self, binary_form=False):
-
         """Returns a formatted version of the data in the
         certificate provided by the other end of the SSL channel.
         Return None if no certificate was provided, {} if a
         certificate was provided, but not validated."""
 
+        self._checkClosed()
         return self._sslobj.peer_certificate(binary_form)
 
-    def cipher (self):
-
+    def cipher(self):
+        self._checkClosed()
         if not self._sslobj:
             return None
         else:
             return self._sslobj.cipher()
 
-    def send (self, data, flags=0):
+    def send(self, data, flags=0):
+        self._checkClosed()
         if self._sslobj:
             if flags != 0:
                 raise ValueError(
                     "non-zero flags not allowed in calls to send() on %s" %
                     self.__class__)
-            return self._sslobj.write(data)
+            while True:
+                try:
+                    v = self._sslobj.write(data)
+                except SSLError as x:
+                    if x.args[0] == SSL_ERROR_WANT_READ:
+                        return 0
+                    elif x.args[0] == SSL_ERROR_WANT_WRITE:
+                        return 0
+                    else:
+                        raise
+                else:
+                    return v
         else:
             return socket.send(self, data, flags)
 
-    def send_to (self, data, addr, flags=0):
+    def send_to(self, data, addr, flags=0):
+        self._checkClosed()
         if self._sslobj:
             raise ValueError("send_to not allowed on instances of %s" %
                              self.__class__)
         else:
             return socket.send_to(self, data, addr, flags)
 
-    def sendall (self, data, flags=0):
+    def sendall(self, data, flags=0):
+        self._checkClosed()
         if self._sslobj:
-            if flags != 0:
-                raise ValueError(
-                    "non-zero flags not allowed in calls to sendall() on %s" %
-                    self.__class__)
-            return self._sslobj.write(data)
+            amount = len(data)
+            count = 0
+            while (count < amount):
+                v = self.send(data[count:])
+                count += v
+            return amount
         else:
             return socket.sendall(self, data, flags)
 
-    def recv (self, buflen=1024, flags=0):
+    def recv(self, buflen=1024, flags=0):
+        self._checkClosed()
         if self._sslobj:
             if flags != 0:
                 raise ValueError(
-                    "non-zero flags not allowed in calls to sendall() on %s" %
-                    self.__class__)
-            return self._sslobj.read(data, buflen)
+                  "non-zero flags not allowed in calls to recv_into() on %s" %
+                  self.__class__)
+            while True:
+                try:
+                    return self.read(buflen)
+                except SSLError as x:
+                    if x.args[0] == SSL_ERROR_WANT_READ:
+                        continue
+                    else:
+                        raise x
         else:
             return socket.recv(self, buflen, flags)
 
-    def recv_from (self, addr, buflen=1024, flags=0):
+    def recv_into(self, buffer, nbytes=None, flags=0):
+        self._checkClosed()
+        if buffer and (nbytes is None):
+            nbytes = len(buffer)
+        elif nbytes is None:
+            nbytes = 1024
+        if self._sslobj:
+            if flags != 0:
+                raise ValueError(
+                  "non-zero flags not allowed in calls to recv_into() on %s" %
+                  self.__class__)
+            while True:
+                try:
+                    v = self.read(nbytes, buffer)
+                    return v
+                except SSLError as x:
+                    if x.args[0] == SSL_ERROR_WANT_READ:
+                        continue
+                    else:
+                        raise x
+        else:
+            return socket.recv_into(self, buffer, nbytes, flags)
+
+    def recv_from(self, addr, buflen=1024, flags=0):
+        self._checkClosed()
         if self._sslobj:
             raise ValueError("recv_from not allowed on instances of %s" %
                              self.__class__)
         else:
             return socket.recv_from(self, addr, buflen, flags)
 
+    def pending(self):
+        self._checkClosed()
+        if self._sslobj:
+            return self._sslobj.pending()
+        else:
+            return 0
+
     def shutdown(self, how):
+        self._checkClosed()
         self._sslobj = None
         socket.shutdown(self, how)
 
-    def close(self):
+    def _real_close(self):
         self._sslobj = None
-        socket.close(self)
+        # self._closed = True
+        socket._real_close(self)
 
-    def connect(self, addr):
+    def do_handshake(self, block=False):
+        """Perform a TLS/SSL handshake."""
 
+        timeout = self.gettimeout()
+        try:
+            if timeout == 0.0 and block:
+                self.settimeout(None)
+            self._sslobj.do_handshake()
+        finally:
+            self.settimeout(timeout)
+
+    def connect(self, addr):
         """Connects to remote ADDR, and then wraps the connection in
         an SSL channel."""
 
@@ -201,276 +321,52 @@
         if self._sslobj:
             raise ValueError("attempt to connect already-connected SSLSocket!")
         socket.connect(self, addr)
-        self._sslobj = _ssl.sslwrap(self._sock, False, self.keyfile, self.certfile,
+        self._sslobj = _ssl.sslwrap(self, False, self.keyfile, self.certfile,
                                     self.cert_reqs, self.ssl_version,
                                     self.ca_certs)
+        try:
+            if self.do_handshake_on_connect:
+                self.do_handshake()
+        except:
+            self._sslobj = None
+            raise
 
     def accept(self):
-
         """Accepts a new connection from a remote client, and returns
         a tuple containing that new connection wrapped with a server-side
         SSL channel, and the address of the remote client."""
 
         newsock, addr = socket.accept(self)
-        return (SSLSocket(newsock, True, self.keyfile, self.certfile,
-                          self.cert_reqs, self.ssl_version,
-                          self.ca_certs), addr)
-
-
-    def makefile(self, mode='r', bufsize=-1):
-
-        """Ouch.  Need to make and return a file-like object that
-        works with the SSL connection."""
-
-        if self._sslobj:
-            return SSLFileStream(self._sslobj, mode, bufsize)
-        else:
-            return socket.makefile(self, mode, bufsize)
-
-
-class SSLFileStream:
-
-    """A class to simulate a file stream on top of a socket.
-    Most of this is just lifted from the socket module, and
-    adjusted to work with an SSL stream instead of a socket."""
-
-
-    default_bufsize = 8192
-    name = "<SSL stream>"
-
-    __slots__ = ["mode", "bufsize", "softspace",
-                 # "closed" is a property, see below
-                 "_sslobj", "_rbufsize", "_wbufsize", "_rbuf", "_wbuf",
-                 "_close", "_fileno"]
-
-    def __init__(self, sslobj, mode='rb', bufsize=-1, close=False):
-        self._sslobj = sslobj
-        self.mode = mode # Not actually used in this version
-        if bufsize < 0:
-            bufsize = self.default_bufsize
-        self.bufsize = bufsize
-        self.softspace = False
-        if bufsize == 0:
-            self._rbufsize = 1
-        elif bufsize == 1:
-            self._rbufsize = self.default_bufsize
-        else:
-            self._rbufsize = bufsize
-        self._wbufsize = bufsize
-        self._rbuf = "" # A string
-        self._wbuf = [] # A list of strings
-        self._close = close
-        self._fileno = -1
-
-    def _getclosed(self):
-        return self._sslobj is None
-    closed = property(_getclosed, doc="True if the file is closed")
-
-    def fileno(self):
-        return self._fileno
-
-    def close(self):
-        try:
-            if self._sslobj:
-                self.flush()
-        finally:
-            if self._close and self._sslobj:
-                self._sslobj.close()
-            self._sslobj = None
+        return (SSLSocket(sock=newsock,
+                          keyfile=self.keyfile, certfile=self.certfile,
+                          server_side=True,
+                          cert_reqs=self.cert_reqs,
+                          ssl_version=self.ssl_version,
+                          ca_certs=self.ca_certs,
+                          do_handshake_on_connect=
+                              self.do_handshake_on_connect),
+                addr)
 
     def __del__(self):
-        try:
-            self.close()
-        except:
-            # close() may fail if __init__ didn't complete
-            pass
-
-    def flush(self):
-        if self._wbuf:
-            buffer = "".join(self._wbuf)
-            self._wbuf = []
-            count = 0
-            while (count < len(buffer)):
-                written = self._sslobj.write(buffer)
-                count += written
-                buffer = buffer[written:]
-
-    def write(self, data):
-        data = str(data) # XXX Should really reject non-string non-buffers
-        if not data:
-            return
-        self._wbuf.append(data)
-        if (self._wbufsize == 0 or
-            self._wbufsize == 1 and '\n' in data or
-            self._get_wbuf_len() >= self._wbufsize):
-            self.flush()
-
-    def writelines(self, list):
-        # XXX We could do better here for very long lists
-        # XXX Should really reject non-string non-buffers
-        self._wbuf.extend(filter(None, map(str, list)))
-        if (self._wbufsize <= 1 or
-            self._get_wbuf_len() >= self._wbufsize):
-            self.flush()
-
-    def _get_wbuf_len(self):
-        buf_len = 0
-        for x in self._wbuf:
-            buf_len += len(x)
-        return buf_len
-
-    def read(self, size=-1):
-        data = self._rbuf
-        if size < 0:
-            # Read until EOF
-            buffers = []
-            if data:
-                buffers.append(data)
-            self._rbuf = ""
-            if self._rbufsize <= 1:
-                recv_size = self.default_bufsize
-            else:
-                recv_size = self._rbufsize
-            while True:
-                data = self._sslobj.read(recv_size)
-                if not data:
-                    break
-                buffers.append(data)
-            return "".join(buffers)
-        else:
-            # Read until size bytes or EOF seen, whichever comes first
-            buf_len = len(data)
-            if buf_len >= size:
-                self._rbuf = data[size:]
-                return data[:size]
-            buffers = []
-            if data:
-                buffers.append(data)
-            self._rbuf = ""
-            while True:
-                left = size - buf_len
-                recv_size = max(self._rbufsize, left)
-                data = self._sslobj.read(recv_size)
-                if not data:
-                    break
-                buffers.append(data)
-                n = len(data)
-                if n >= left:
-                    self._rbuf = data[left:]
-                    buffers[-1] = data[:left]
-                    break
-                buf_len += n
-            return "".join(buffers)
-
-    def readline(self, size=-1):
-        data = self._rbuf
-        if size < 0:
-            # Read until \n or EOF, whichever comes first
-            if self._rbufsize <= 1:
-                # Speed up unbuffered case
-                assert data == ""
-                buffers = []
-                while data != "\n":
-                    data = self._sslobj.read(1)
-                    if not data:
-                        break
-                    buffers.append(data)
-                return "".join(buffers)
-            nl = data.find('\n')
-            if nl >= 0:
-                nl += 1
-                self._rbuf = data[nl:]
-                return data[:nl]
-            buffers = []
-            if data:
-                buffers.append(data)
-            self._rbuf = ""
-            while True:
-                data = self._sslobj.read(self._rbufsize)
-                if not data:
-                    break
-                buffers.append(data)
-                nl = data.find('\n')
-                if nl >= 0:
-                    nl += 1
-                    self._rbuf = data[nl:]
-                    buffers[-1] = data[:nl]
-                    break
-            return "".join(buffers)
-        else:
-            # Read until size bytes or \n or EOF seen, whichever comes first
-            nl = data.find('\n', 0, size)
-            if nl >= 0:
-                nl += 1
-                self._rbuf = data[nl:]
-                return data[:nl]
-            buf_len = len(data)
-            if buf_len >= size:
-                self._rbuf = data[size:]
-                return data[:size]
-            buffers = []
-            if data:
-                buffers.append(data)
-            self._rbuf = ""
-            while True:
-                data = self._sslobj.read(self._rbufsize)
-                if not data:
-                    break
-                buffers.append(data)
-                left = size - buf_len
-                nl = data.find('\n', 0, left)
-                if nl >= 0:
-                    nl += 1
-                    self._rbuf = data[nl:]
-                    buffers[-1] = data[:nl]
-                    break
-                n = len(data)
-                if n >= left:
-                    self._rbuf = data[left:]
-                    buffers[-1] = data[:left]
-                    break
-                buf_len += n
-            return "".join(buffers)
-
-    def readlines(self, sizehint=0):
-        total = 0
-        list = []
-        while True:
-            line = self.readline()
-            if not line:
-                break
-            list.append(line)
-            total += len(line)
-            if sizehint and total >= sizehint:
-                break
-        return list
-
-    # Iterator protocols
-
-    def __iter__(self):
-        return self
-
-    def next(self):
-        line = self.readline()
-        if not line:
-            raise StopIteration
-        return line
-
-
+        # sys.stderr.write("__del__ on %s\n" % repr(self))
+        self._real_close()
 
 
 def wrap_socket(sock, keyfile=None, certfile=None,
                 server_side=False, cert_reqs=CERT_NONE,
-                ssl_version=PROTOCOL_SSLv23, ca_certs=None):
+                ssl_version=PROTOCOL_SSLv23, ca_certs=None,
+                do_handshake_on_connect=True,
+                suppress_ragged_eofs=True):
 
-    return SSLSocket(sock, keyfile=keyfile, certfile=certfile,
+    return SSLSocket(sock=sock, keyfile=keyfile, certfile=certfile,
                      server_side=server_side, cert_reqs=cert_reqs,
-                     ssl_version=ssl_version, ca_certs=ca_certs)
+                     ssl_version=ssl_version, ca_certs=ca_certs,
+                     do_handshake_on_connect=do_handshake_on_connect,
+                     suppress_ragged_eofs=suppress_ragged_eofs)
 
 # some utility functions
 
 def cert_time_to_seconds(cert_time):
-
     """Takes a date-time string in standard ASN1_print form
     ("MON DAY 24HOUR:MINUTE:SEC YEAR TIMEZONE") and return
     a Python time value in seconds past the epoch."""
@@ -482,23 +378,15 @@
 PEM_FOOTER = "-----END CERTIFICATE-----"
 
 def DER_cert_to_PEM_cert(der_cert_bytes):
-
     """Takes a certificate in binary DER format and returns the
     PEM version of it as a string."""
 
-    if hasattr(base64, 'standard_b64encode'):
-        # preferred because older API gets line-length wrong
-        f = base64.standard_b64encode(der_cert_bytes)
-        return (PEM_HEADER + '\n' +
-                textwrap.fill(f, 64) +
-                PEM_FOOTER + '\n')
-    else:
-        return (PEM_HEADER + '\n' +
-                base64.encodestring(der_cert_bytes) +
-                PEM_FOOTER + '\n')
+    f = str(base64.standard_b64encode(der_cert_bytes), 'ASCII', 'strict')
+    return (PEM_HEADER + '\n' +
+            textwrap.fill(f, 64) + '\n' +
+            PEM_FOOTER + '\n')
 
 def PEM_cert_to_DER_cert(pem_cert_string):
-
     """Takes a certificate in ASCII PEM format and returns the
     DER-encoded version of it as a byte sequence"""
 
@@ -509,10 +397,9 @@
         raise ValueError("Invalid PEM encoding; must end with %s"
                          % PEM_FOOTER)
     d = pem_cert_string.strip()[len(PEM_HEADER):-len(PEM_FOOTER)]
-    return base64.decodestring(d)
-
-def get_server_certificate (addr, ssl_version=PROTOCOL_SSLv3, ca_certs=None):
+    return base64.decodestring(d.encode('ASCII', 'strict'))
 
+def get_server_certificate(addr, ssl_version=PROTOCOL_SSLv3, ca_certs=None):
     """Retrieve the certificate from the server at the specified address,
     and return it as a PEM-encoded string.
     If 'ca_certs' is specified, validate the server cert against it.
@@ -530,7 +417,7 @@
     s.close()
     return DER_cert_to_PEM_cert(dercert)
 
-def get_protocol_name (protocol_code):
+def get_protocol_name(protocol_code):
     if protocol_code == PROTOCOL_TLSv1:
         return "TLSv1"
     elif protocol_code == PROTOCOL_SSLv23:
@@ -541,15 +428,3 @@
         return "SSLv3"
     else:
         return "<unknown>"
-
-
-# a replacement for the old socket.ssl function
-
-def sslwrap_simple (sock, keyfile=None, certfile=None):
-
-    """A replacement for the old socket.ssl function.  Designed
-    for compability with Python 2.5 and earlier.  Will disappear in
-    Python 3.0."""
-
-    return _ssl.sslwrap(sock._sock, 0, keyfile, certfile, CERT_NONE,
-                        PROTOCOL_SSLv23, None)

Modified: python/branches/py3k-importlib/Lib/stat.py
==============================================================================
--- python/branches/py3k-importlib/Lib/stat.py	(original)
+++ python/branches/py3k-importlib/Lib/stat.py	Thu Mar 27 00:48:05 2008
@@ -3,12 +3,7 @@
 Suggested usage: from stat import *
 """
 
-# XXX Strictly spoken, this module may have to be adapted for each POSIX
-# implementation; in practice, however, the numeric constants used by
-# stat() are almost universal (even for stat() emulations on non-UNIX
-# systems like MS-DOS).
-
-# Indices for stat struct members in tuple returned by os.stat()
+# Indices for stat struct members in the tuple returned by os.stat()
 
 ST_MODE  = 0
 ST_INO   = 1

Modified: python/branches/py3k-importlib/Lib/string.py
==============================================================================
--- python/branches/py3k-importlib/Lib/string.py	(original)
+++ python/branches/py3k-importlib/Lib/string.py	Thu Mar 27 00:48:05 2008
@@ -41,7 +41,7 @@
 
 
 # Construct a translation map for bytes.translate
-def maketrans(frm, to):
+def maketrans(frm: bytes, to: bytes) -> bytes:
     """maketrans(frm, to) -> bytes
 
     Return a translation table (a bytes object of length 256)
@@ -53,10 +53,10 @@
         raise ValueError("maketrans arguments must have same length")
     if not (isinstance(frm, bytes) and isinstance(to, bytes)):
         raise TypeError("maketrans arguments must be bytes objects")
-    L = bytes(range(256))
+    L = bytearray(range(256))
     for i, c in enumerate(frm):
         L[c] = to[i]
-    return L
+    return bytes(L)
 
 
 ####################################################################

Modified: python/branches/py3k-importlib/Lib/struct.py
==============================================================================
--- python/branches/py3k-importlib/Lib/struct.py	(original)
+++ python/branches/py3k-importlib/Lib/struct.py	Thu Mar 27 00:48:05 2008
@@ -1,109 +1,2 @@
-"""
-Functions to convert between Python values and C structs.
-Python strings are used to hold the data representing the C struct
-and also as format strings to describe the layout of data in the C struct.
-
-The optional first format char indicates byte order, size and alignment:
- @: native order, size & alignment (default)
- =: native order, std. size & alignment
- <: little-endian, std. size & alignment
- >: big-endian, std. size & alignment
- !: same as >
-
-The remaining chars indicate types of args and must match exactly;
-these can be preceded by a decimal repeat count:
- x: pad byte (no data); c:char; b:signed byte; B:unsigned byte;
- h:short; H:unsigned short; i:int; I:unsigned int;
- l:long; L:unsigned long; f:float; d:double.
-Special cases (preceding decimal count indicates length):
- s:string (array of char); p: pascal string (with count byte).
-Special case (only available in native format):
- P:an integer type that is wide enough to hold a pointer.
-Special case (not in native mode unless 'long long' in platform C):
- q:long long; Q:unsigned long long
-Whitespace between formats is ignored.
-
-The variable struct.error is an exception raised on errors.
-"""
-
-# XXX Move the bytes and str8 casts into the _struct module
-
-__version__ = '3.0'
-
-
-from _struct import Struct as _Struct, error
-
-class Struct(_Struct):
-    def __init__(self, fmt):
-        if isinstance(fmt, str):
-            fmt = str8(fmt)
-        _Struct.__init__(self, fmt)
-
-_MAXCACHE = 100
-_cache = {}
-
-def _compile(fmt):
-    # Internal: compile struct pattern
-    if len(_cache) >= _MAXCACHE:
-        _cache.clear()
-    s = Struct(fmt)
-    _cache[fmt] = s
-    return s
-
-def calcsize(fmt):
-    """
-    Return size of C struct described by format string fmt.
-    See struct.__doc__ for more on format strings.
-    """
-    try:
-        o = _cache[fmt]
-    except KeyError:
-        o = _compile(fmt)
-    return o.size
-
-def pack(fmt, *args):
-    """
-    Return string containing values v1, v2, ... packed according to fmt.
-    See struct.__doc__ for more on format strings.
-    """
-    try:
-        o = _cache[fmt]
-    except KeyError:
-        o = _compile(fmt)
-    return bytes(o.pack(*args))
-
-def pack_into(fmt, buf, offset, *args):
-    """
-    Pack the values v1, v2, ... according to fmt, write
-    the packed bytes into the writable buffer buf starting at offset.
-    See struct.__doc__ for more on format strings.
-    """
-    try:
-        o = _cache[fmt]
-    except KeyError:
-        o = _compile(fmt)
-    o.pack_into(buf, offset, *args)
-
-def unpack(fmt, s):
-    """
-    Unpack the string, containing packed C structure data, according
-    to fmt.  Requires len(string)==calcsize(fmt).
-    See struct.__doc__ for more on format strings.
-    """
-    try:
-        o = _cache[fmt]
-    except KeyError:
-        o = _compile(fmt)
-    return o.unpack(s)
-
-def unpack_from(fmt, buf, offset=0):
-    """
-    Unpack the buffer, containing packed C structure data, according to
-    fmt starting at offset. Requires len(buffer[offset:]) >= calcsize(fmt).
-    See struct.__doc__ for more on format strings.
-    """
-    try:
-        o = _cache[fmt]
-    except KeyError:
-        o = _compile(fmt)
-    return o.unpack_from(buf, offset)
+from _struct import *
+from _struct import _clearcache

Modified: python/branches/py3k-importlib/Lib/subprocess.py
==============================================================================
--- python/branches/py3k-importlib/Lib/subprocess.py	(original)
+++ python/branches/py3k-importlib/Lib/subprocess.py	Thu Mar 27 00:48:05 2008
@@ -289,6 +289,7 @@
 import io
 import os
 import traceback
+import gc
 
 # Exception classes used by this module.
 class CalledProcessError(Exception):
@@ -344,7 +345,7 @@
 
 def _cleanup():
     for inst in _active[:]:
-        res = inst.poll(_deadstate=sys.maxint)
+        res = inst.poll(_deadstate=sys.maxsize)
         if res is not None and res >= 0:
             try:
                 _active.remove(inst)
@@ -397,8 +398,8 @@
 
     2) A string surrounded by double quotation marks is
        interpreted as a single argument, regardless of white space
-       contained within.  A quoted string can be embedded in an
-       argument.
+       or pipe characters contained within.  A quoted string can be
+       embedded in an argument.
 
     3) A double quotation mark preceded by a backslash is
        interpreted as a literal double quotation mark.
@@ -424,7 +425,7 @@
         if result:
             result.append(' ')
 
-        needquote = (" " in arg) or ("\t" in arg) or arg == ""
+        needquote = (" " in arg) or ("\t" in arg) or ("|" in arg) or not arg
         if needquote:
             result.append('"')
 
@@ -433,7 +434,7 @@
                 # Don't know if we need to double yet.
                 bs_buf.append(c)
             elif c == '"':
-                # Double backspaces.
+                # Double backslashes.
                 result.append('\\' * len(bs_buf)*2)
                 bs_buf = []
                 result.append('\\"')
@@ -444,7 +445,7 @@
                     bs_buf = []
                 result.append(c)
 
-        # Add remaining backspaces, if any.
+        # Add remaining backslashes, if any.
         if bs_buf:
             result.extend(bs_buf)
 
@@ -552,10 +553,9 @@
                 self.stderr = io.TextIOWrapper(self.stderr)
 
 
-    def _translate_newlines(self, data):
-        data = data.replace(b"\r\n", b"\n")
-        data = data.replace(b"\r", b"\n")
-        return str(data)
+    def _translate_newlines(self, data, encoding):
+        data = data.replace(b"\r\n", b"\n").replace(b"\r", b"\n")
+        return data.decode(encoding)
 
 
     def __del__(self, sys=sys):
@@ -563,7 +563,7 @@
             # We didn't get to successfully create a child process.
             return
         # In case the child hasn't been waited on, check if it's done.
-        self.poll(_deadstate=sys.maxint)
+        self.poll(_deadstate=sys.maxsize)
         if self.returncode is None and _active is not None:
             # Child is still running, keep us alive until we can wait on it.
             _active.append(self)
@@ -698,7 +698,7 @@
                            errread, errwrite):
             """Execute program (MS Windows version)"""
 
-            if not isinstance(args, basestring):
+            if not isinstance(args, str):
                 args = list2cmdline(args)
 
             # Process startup details
@@ -809,6 +809,8 @@
 
             if self.stdin:
                 if input is not None:
+                    if isinstance(input, str):
+                        input = input.encode()
                     self.stdin.write(input)
                 self.stdin.close()
 
@@ -823,16 +825,6 @@
             if stderr is not None:
                 stderr = stderr[0]
 
-            # Translate newlines, if requested.  We cannot let the file
-            # object do the translation: It is based on stdio, which is
-            # impossible to combine with select (unless forcing no
-            # buffering).
-            if self.universal_newlines:
-                if stdout is not None:
-                    stdout = self._translate_newlines(stdout)
-                if stderr is not None:
-                    stderr = self._translate_newlines(stderr)
-
             self.wait()
             return (stdout, stderr)
 
@@ -896,13 +888,8 @@
 
 
         def _close_fds(self, but):
-            for i in range(3, MAXFD):
-                if i == but:
-                    continue
-                try:
-                    os.close(i)
-                except:
-                    pass
+            os.closerange(3, but)
+            os.closerange(but + 1, MAXFD)
 
 
         def _execute_child(self, args, executable, preexec_fn, close_fds,
@@ -913,7 +900,7 @@
                            errread, errwrite):
             """Execute program (POSIX version)"""
 
-            if isinstance(args, basestring):
+            if isinstance(args, str):
                 args = [args]
             else:
                 args = list(args)
@@ -930,7 +917,16 @@
             errpipe_read, errpipe_write = os.pipe()
             self._set_cloexec_flag(errpipe_write)
 
-            self.pid = os.fork()
+            gc_was_enabled = gc.isenabled()
+            # Disable gc to avoid bug where gc -> file_dealloc ->
+            # write to stderr -> hang.  http://bugs.python.org/issue1336
+            gc.disable()
+            try:
+                self.pid = os.fork()
+            except:
+                if gc_was_enabled:
+                    gc.enable()
+                raise
             self._child_created = True
             if self.pid == 0:
                 # Child
@@ -958,7 +954,8 @@
                         os.close(p2cread)
                     if c2pwrite is not None and c2pwrite not in (p2cread, 1):
                         os.close(c2pwrite)
-                    if errwrite is not None and errwrite not in (p2cread, c2pwrite, 2):
+                    if (errwrite is not None and
+                        errwrite not in (p2cread, c2pwrite, 2)):
                         os.close(errwrite)
 
                     # Close all other fds, if asked for
@@ -990,6 +987,8 @@
                 os._exit(255)
 
             # Parent
+            if gc_was_enabled:
+                gc.enable()
             os.close(errpipe_write)
             if p2cread is not None and p2cwrite is not None:
                 os.close(p2cread)
@@ -1044,8 +1043,7 @@
             if self.stdin:
                 if isinstance(input, str): # Unicode
                     input = input.encode("utf-8") # XXX What else?
-                if not isinstance(input, (bytes, str8)):
-                    input = bytes(input)
+                input = bytes(input)
             read_set = []
             write_set = []
             stdout = None # Return
@@ -1070,6 +1068,9 @@
             while read_set or write_set:
                 rlist, wlist, xlist = select.select(read_set, write_set, [])
 
+                # XXX Rewrite these to use non-blocking I/O on the
+                # file objects; they are no longer using C stdio!
+
                 if self.stdin in wlist:
                     # When select has indicated that the file is writable,
                     # we can write up to PIPE_BUF bytes without risk
@@ -1097,19 +1098,19 @@
 
             # All data exchanged.  Translate lists into strings.
             if stdout is not None:
-                stdout = b''.join(stdout)
+                stdout = b"".join(stdout)
             if stderr is not None:
-                stderr = b''.join(stderr)
+                stderr = b"".join(stderr)
 
-            # Translate newlines, if requested.  We cannot let the file
-            # object do the translation: It is based on stdio, which is
-            # impossible to combine with select (unless forcing no
-            # buffering).
+            # Translate newlines, if requested.
+            # This also turns bytes into strings.
             if self.universal_newlines:
                 if stdout is not None:
-                    stdout = self._translate_newlines(stdout)
+                    stdout = self._translate_newlines(stdout,
+                                                      self.stdout.encoding)
                 if stderr is not None:
-                    stderr = self._translate_newlines(stderr)
+                    stderr = self._translate_newlines(stderr,
+                                                      self.stderr.encoding)
 
             self.wait()
             return (stdout, stderr)

Modified: python/branches/py3k-importlib/Lib/sunau.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sunau.py	(original)
+++ python/branches/py3k-importlib/Lib/sunau.py	Thu Mar 27 00:48:05 2008
@@ -153,8 +153,8 @@
 
     def __init__(self, f):
         if type(f) == type(''):
-            import __builtin__
-            f = __builtin__.open(f, 'rb')
+            import builtins
+            f = builtins.open(f, 'rb')
         self.initfp(f)
 
     def __del__(self):
@@ -282,8 +282,8 @@
 
     def __init__(self, f):
         if type(f) == type(''):
-            import __builtin__
-            f = __builtin__.open(f, 'wb')
+            import builtins
+            f = builtins.open(f, 'wb')
         self.initfp(f)
 
     def __del__(self):

Modified: python/branches/py3k-importlib/Lib/tarfile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/tarfile.py	(original)
+++ python/branches/py3k-importlib/Lib/tarfile.py	Thu Mar 27 00:48:05 2008
@@ -1,9 +1,8 @@
 #!/usr/bin/env python
-# -*- coding: iso-8859-1 -*-
 #-------------------------------------------------------------------
 # tarfile.py
 #-------------------------------------------------------------------
-# Copyright (C) 2002 Lars Gustäbel <lars at gustaebel.de>
+# Copyright (C) 2002 Lars Gustaebel <lars at gustaebel.de>
 # All rights reserved.
 #
 # Permission  is  hereby granted,  free  of charge,  to  any person
@@ -31,13 +30,12 @@
 """
 
 __version__ = "$Revision$"
-# $Source$
 
 version     = "0.9.0"
-__author__  = "Lars Gustäbel (lars at gustaebel.de)"
+__author__  = "Lars Gust\u00e4bel (lars at gustaebel.de)"
 __date__    = "$Date$"
 __cvsid__   = "$Id$"
-__credits__ = "Gustavo Niemeyer, Niels Gustäbel, Richard Townsend."
+__credits__ = "Gustavo Niemeyer, Niels Gust\u00e4bel, Richard Townsend."
 
 #---------
 # Imports
@@ -67,7 +65,7 @@
 # from tarfile import *
 __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"]
 
-from __builtin__ import open as _open # Since 'open' is TarFile.open
+from builtins import open as _open # Since 'open' is TarFile.open
 
 #---------------------------------------------------------
 # tar constants
@@ -224,7 +222,7 @@
             # this could raise OverflowError.
             n = struct.unpack("L", struct.pack("l", n))[0]
 
-        s = b""
+        s = bytearray()
         for i in range(digits - 1):
             s.insert(0, n & 0o377)
             n >>= 8
@@ -1544,7 +1542,8 @@
         self.closed = False
         self.members = []       # list of members as TarInfo objects
         self._loaded = False    # flag if all members have been read
-        self.offset = 0         # current position in the archive file
+        self.offset = self.fileobj.tell()
+                                # current position in the archive file
         self.inodes = {}        # dictionary caching the inodes of
                                 # archive members already added
 
@@ -2006,27 +2005,23 @@
 
         for tarinfo in members:
             if tarinfo.isdir():
-                # Extract directory with a safe mode, so that
-                # all files below can be extracted as well.
-                try:
-                    os.makedirs(os.path.join(path, tarinfo.name), 0o700)
-                except EnvironmentError:
-                    pass
+                # Extract directories with a safe mode.
                 directories.append(tarinfo)
-            else:
-                self.extract(tarinfo, path)
+                tarinfo = copy.copy(tarinfo)
+                tarinfo.mode = 0o700
+            self.extract(tarinfo, path)
 
         # Reverse sort directories.
-        directories.sort(lambda a, b: cmp(a.name, b.name))
+        directories.sort(key=lambda a: a.name)
         directories.reverse()
 
         # Set correct owner, mtime and filemode on directories.
         for tarinfo in directories:
-            path = os.path.join(path, tarinfo.name)
+            dirpath = os.path.join(path, tarinfo.name)
             try:
-                self.chown(tarinfo, path)
-                self.utime(tarinfo, path)
-                self.chmod(tarinfo, path)
+                self.chown(tarinfo, dirpath)
+                self.utime(tarinfo, dirpath)
+                self.chmod(tarinfo, dirpath)
             except ExtractError as e:
                 if self.errorlevel > 1:
                     raise
@@ -2041,7 +2036,7 @@
         """
         self._check("r")
 
-        if isinstance(member, basestring):
+        if isinstance(member, str):
             tarinfo = self.getmember(member)
         else:
             tarinfo = member
@@ -2077,7 +2072,7 @@
         """
         self._check("r")
 
-        if isinstance(member, basestring):
+        if isinstance(member, str):
             tarinfo = self.getmember(member)
         else:
             tarinfo = member
@@ -2119,6 +2114,8 @@
         # Create all upper directories.
         upperdirs = os.path.dirname(targetpath)
         if upperdirs and not os.path.exists(upperdirs):
+            # Create directories that are not part of the archive with
+            # default permissions.
             os.makedirs(upperdirs)
 
         if tarinfo.islnk() or tarinfo.issym():
@@ -2155,7 +2152,9 @@
         """Make a directory called targetpath.
         """
         try:
-            os.mkdir(targetpath)
+            # Use a safe mode for the directory, the real mode is set
+            # later in _extract_member().
+            os.mkdir(targetpath, 0o700)
         except EnvironmentError as e:
             if e.errno != errno.EEXIST:
                 raise

Modified: python/branches/py3k-importlib/Lib/tempfile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/tempfile.py	(original)
+++ python/branches/py3k-importlib/Lib/tempfile.py	Thu Mar 27 00:48:05 2008
@@ -201,7 +201,7 @@
                 del fp, fd
                 return dir
             except (OSError, IOError) as e:
-                if e[0] != _errno.EEXIST:
+                if e.args[0] != _errno.EEXIST:
                     break # no point trying more names in this directory
                 pass
     raise IOError(_errno.ENOENT,
@@ -363,6 +363,7 @@
 
     raise IOError(_errno.EEXIST, "No usable temporary filename found")
 
+
 class _TemporaryFileWrapper:
     """Temporary file wrapper
 
@@ -378,17 +379,29 @@
         self.delete = delete
 
     def __getattr__(self, name):
+        # Attribute lookups are delegated to the underlying file
+        # and cached for non-numeric results
+        # (i.e. methods are cached, closed and friends are not)
         file = self.__dict__['file']
         a = getattr(file, name)
-        if type(a) != type(0):
+        if not isinstance(a, int):
             setattr(self, name, a)
         return a
 
+    # The underlying __enter__ method returns the wrong object
+    # (self.file) so override it to return the wrapper
+    def __enter__(self):
+        self.file.__enter__()
+        return self
+
+    # iter() doesn't use __getattr__ to find the __iter__ method
+    def __iter__(self):
+        return iter(self.file)
+
     # NT provides delete-on-close as a primitive, so we don't need
     # the wrapper to do anything special.  We still use it so that
     # file.name is useful (i.e. not "(fdopen)") with NamedTemporaryFile.
     if _os.name != 'nt':
-
         # Cache the unlinker so we don't get spurious errors at
         # shutdown when the module-level "os" is None'd out.  Note
         # that this must be referenced as self.unlink, because the
@@ -406,6 +419,14 @@
         def __del__(self):
             self.close()
 
+        # Need to trap __exit__ as well to ensure the file gets
+        # deleted when used in a with statement
+        def __exit__(self, exc, value, tb):
+            result = self.file.__exit__(exc, value, tb)
+            self.close()
+            return result
+
+
 def NamedTemporaryFile(mode='w+b', buffering=-1, encoding=None,
                        newline=None, suffix="", prefix=template,
                        dir=None, delete=True):
@@ -495,7 +516,10 @@
         if 'b' in mode:
             self._file = _io.BytesIO()
         else:
-            self._file = _io.StringIO(encoding=encoding, newline=newline)
+            # Setting newline="\n" avoids newline translation;
+            # this is important because otherwise on Windows we'd
+            # hget double newline translation upon rollover().
+            self._file = _io.StringIO(encoding=encoding, newline="\n")
         self._max_size = max_size
         self._rolled = False
         self._TemporaryFileArgs = {'mode': mode, 'buffering': buffering,
@@ -520,6 +544,20 @@
 
         self._rolled = True
 
+    # The method caching trick from NamedTemporaryFile
+    # won't work here, because _file may change from a
+    # _StringIO instance to a real file. So we list
+    # all the methods directly.
+
+    # Context management protocol
+    def __enter__(self):
+        if self._file.closed:
+            raise ValueError("Cannot enter context with closed file")
+        return self
+
+    def __exit__(self, exc, value, tb):
+        self._file.close()
+
     # file protocol
     def __iter__(self):
         return self._file.__iter__()

Modified: python/branches/py3k-importlib/Lib/test/README
==============================================================================
--- python/branches/py3k-importlib/Lib/test/README	(original)
+++ python/branches/py3k-importlib/Lib/test/README	Thu Mar 27 00:48:05 2008
@@ -3,7 +3,7 @@
 +++++++++++++++++++++++++++++++
 
 :Author: Skip Montanaro
-:Contact: skip at mojam.com
+:Contact: skip at pobox.com
 
 Introduction
 ============
@@ -382,15 +382,6 @@
       statement is *not* correct Python syntax.
 
 
-Python and C statement coverage results are currently available at
-
-    http://www.musi-cal.com/~skip/python/Python/dist/src/
-
-As of this writing (July, 2000) these results are being generated nightly.
-You can refer to the summaries and the test coverage output files to see
-where coverage is adequate or lacking and write test cases to beef up the
-coverage.
-
 Some Non-Obvious regrtest Features
 ==================================
     * Automagic test detection:  When you create a new test file

Modified: python/branches/py3k-importlib/Lib/test/cjkencodings_test.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/cjkencodings_test.py	(original)
+++ python/branches/py3k-importlib/Lib/test/cjkencodings_test.py	Thu Mar 27 00:48:05 2008
@@ -64,8 +64,10 @@
 b"\xab\x96\xe7\x9a\x84\xe5\x95\x8f\xe9\xa1\x8c\xe5\xb0\xb1\xe6\x98"
 b"\xaf\x3a\x0a\x0a"),
 'big5hkscs': (
-b"\x88\x45\x88\x5c\x8a\x73\x8b\xda\x8d\xd8\x0a",
-b"\xf0\xa0\x84\x8c\xc4\x9a\xe9\xb5\xae\xe7\xbd\x93\xe6\xb4\x86\x0a"),
+b"\x88\x45\x88\x5c\x8a\x73\x8b\xda\x8d\xd8\x0a\x88\x66\x88\x62\x88"
+b"\xa7\x20\x88\xa7\x88\xa3\x0a",
+b"\xf0\xa0\x84\x8c\xc4\x9a\xe9\xb5\xae\xe7\xbd\x93\xe6\xb4\x86\x0a"
+b"\xc3\x8a\xc3\x8a\xcc\x84\xc3\xaa\x20\xc3\xaa\xc3\xaa\xcc\x84\x0a"),
 'cp949': (
 b"\x8c\x63\xb9\xe6\xb0\xa2\xc7\xcf\x20\xbc\x84\xbd\xc3\xc4\xdd\xb6"
 b"\xf3\x0a\x0a\xa8\xc0\xa8\xc0\xb3\xb3\x21\x21\x20\xec\xd7\xce\xfa"

Modified: python/branches/py3k-importlib/Lib/test/crashers/borrowed_ref_2.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/crashers/borrowed_ref_2.py	(original)
+++ python/branches/py3k-importlib/Lib/test/crashers/borrowed_ref_2.py	Thu Mar 27 00:48:05 2008
@@ -33,6 +33,6 @@
 i = 0
 del a
 while 1:
-    c.d = 42         # segfaults in PyMethod_New(im_func=D.__set__, im_self=d)
+    c.d = 42         # segfaults in PyMethod_New(__func__=D.__set__, __self__=d)
     lst[i] = c.g     # consume the free list of instancemethod objects
     i += 1

Deleted: /python/branches/py3k-importlib/Lib/test/crashers/file_threads.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/crashers/file_threads.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,8 +0,0 @@
-# An example for http://bugs.python.org/issue815646
-
-import thread
-
-while 1:
-    f = open("/tmp/dupa", "w")
-    thread.start_new_thread(f.close, ())
-    f.close()

Deleted: /python/branches/py3k-importlib/Lib/test/crashers/loosing_dict_ref.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/crashers/loosing_dict_ref.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,21 +0,0 @@
-
-# http://python.org/sf/1303614
-
-class Strange(object):
-    def __hash__(self):
-        return hash('hello')
-
-    def __eq__(self, other):
-        x.__dict__ = {}   # the old x.__dict__ is deallocated
-        return False
-
-
-class X(object):
-    pass
-
-if __name__ == '__main__':
-    v = 123
-    x = X()
-    x.__dict__ = {Strange(): 42,
-                  'hello': v+456}
-    x.hello  # segfault: the above dict is accessed after it's deallocated

Deleted: /python/branches/py3k-importlib/Lib/test/crashers/weakref_in_del.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/crashers/weakref_in_del.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,17 +0,0 @@
-import weakref
-
-# http://python.org/sf/1377858
-# Fixed for new-style classes in 2.5c1.
-
-ref = None
-
-def test_weakref_in_del():
-    class Target():
-        def __del__(self):
-            global ref
-            ref = weakref.ref(self)
-
-    w = Target()
-
-if __name__ == '__main__':
-    test_weakref_in_del()

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/abs.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/abs.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/abs.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests primarily tests the existence of the operator.
 -- Additon, subtraction, rounding, and more overflows are tested

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/add.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/add.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/add.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   9
 rounding:    half_up
@@ -1122,6 +1122,15 @@
 addx1117 add -1e-4 +1e-383   -> -0.00009999999999999999  Rounded Inexact
 addx1118 add -1e-5 +1e-383   -> -0.000009999999999999999  Rounded Inexact
 addx1119 add -1e-6 +1e-383   -> -9.999999999999999E-7  Rounded Inexact
+addx1120 add +1e-383 -1e+2   -> -99.99999999999999 Rounded Inexact
+addx1121 add +1e-383 -1e+1   -> -9.999999999999999  Rounded Inexact
+addx1123 add +1e-383    -1   -> -0.9999999999999999  Rounded Inexact
+addx1124 add +1e-383 -1e-1   -> -0.09999999999999999  Rounded Inexact
+addx1125 add +1e-383 -1e-2   -> -0.009999999999999999  Rounded Inexact
+addx1126 add +1e-383 -1e-3   -> -0.0009999999999999999  Rounded Inexact
+addx1127 add +1e-383 -1e-4   -> -0.00009999999999999999  Rounded Inexact
+addx1128 add +1e-383 -1e-5   -> -0.000009999999999999999  Rounded Inexact
+addx1129 add +1e-383 -1e-6   -> -9.999999999999999E-7  Rounded Inexact
 
 rounding:     down
 precision:    7
@@ -1658,17 +1667,19 @@
 addx6057 add '1E+2' '1E+4' -> '1.01E+4'
 
 -- from above
-addx6061 add 1 '0.1' -> '1.1'
-addx6062 add 1 '0.01' -> '1.01'
-addx6063 add 1 '0.001' -> '1.001'
-addx6064 add 1 '0.0001' -> '1.0001'
-addx6065 add 1 '0.00001' -> '1.00001'
-addx6066 add 1 '0.000001' -> '1.000001'
-addx6067 add 1 '0.0000001' -> '1.0000001'
-addx6068 add 1 '0.00000001' -> '1.00000001'
+addx6060 add 1 '0.1' -> '1.1'
+addx6061 add 1 '0.01' -> '1.01'
+addx6062 add 1 '0.001' -> '1.001'
+addx6063 add 1 '0.0001' -> '1.0001'
+addx6064 add 1 '0.00001' -> '1.00001'
+addx6065 add 1 '0.000001' -> '1.000001'
+addx6066 add 1 '0.0000001' -> '1.0000001'
+addx6067 add 1 '0.00000001' -> '1.00000001'
 
 -- cancellation to integer
-addx6069 add 99999999999999123456789 -99999999999999E+9 -> 123456789
+addx6068 add 99999999999999123456789 -99999999999999E+9 -> 123456789
+-- similar from FMA fun
+addx6069 add "-1234567890123455.234567890123454" "1234567890123456" -> 0.765432109876546
 
 -- some funny zeros [in case of bad signum]
 addx6070 add 1  0    -> 1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/and.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/and.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/and.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/base.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/base.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/base.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 extended:    1
 
 -- This file tests base conversions from string to a decimal number

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/clamp.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/clamp.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/clamp.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests uses the same limits as the 8-byte concrete
 -- representation, but applies clamping without using format-specific

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/class.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/class.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/class.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- [New 2006.11.27]
 

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/compare.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/compare.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/compare.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Note that we cannot assume add/subtract tests cover paths adequately,
 -- here, because the code might be quite different (comparison cannot

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/comparetotal.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/comparetotal.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/comparetotal.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Note that we cannot assume add/subtract tests cover paths adequately,
 -- here, because the code might be quite different (comparison cannot

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/comparetotmag.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/comparetotmag.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/comparetotmag.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Note that it cannot be assumed that add/subtract tests cover paths
 -- for this operation adequately, here, because the code might be

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/copy.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/copy.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/copy.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/copyabs.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/copyabs.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/copyabs.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/copynegate.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/copynegate.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/copynegate.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/copysign.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/copysign.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/copysign.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAbs.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAbs.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAbs.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAdd.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAdd.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAdd.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests are for decDoubles only; all arguments are
 -- representable in a decDouble
@@ -1029,6 +1029,16 @@
 ddadd71707 add 130E-2   -1E0    -> 0.30
 ddadd71708 add 1E2      -1E4    -> -9.9E+3
 
+-- query from Vincent Kulandaisamy
+rounding: ceiling
+ddadd71801  add  7.8822773805862E+277    -5.1757503820663E-21 -> 7.882277380586200E+277 Inexact Rounded
+ddadd71802  add  7.882277380586200E+277  12.341               -> 7.882277380586201E+277 Inexact Rounded
+ddadd71803  add  7.882277380586201E+277  2.7270545046613E-31  -> 7.882277380586202E+277 Inexact Rounded
+
+ddadd71811  add                   12.341 -5.1757503820663E-21 -> 12.34100000000000      Inexact Rounded
+ddadd71812  add        12.34100000000000 2.7270545046613E-31  -> 12.34100000000001      Inexact Rounded
+ddadd71813  add        12.34100000000001 7.8822773805862E+277 -> 7.882277380586201E+277 Inexact Rounded
+
 -- Gappy coefficients; check residue handling even with full coefficient gap
 rounding: half_even
 

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAnd.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAnd.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAnd.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddBase.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddBase.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddBase.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This file tests base conversions from string to a decimal number
 -- and back to a string (in Scientific form)

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCanonical.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCanonical.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCanonical.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This file tests that copy operations leave uncanonical operands
 -- unchanged, and vice versa

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddClass.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddClass.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddClass.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- [New 2006.11.27]
 precision:   16

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompare.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompare.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompare.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Note that we cannot assume add/subtract tests cover paths adequately,
 -- here, because the code might be quite different (comparison cannot

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareSig.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareSig.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareSig.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Note that we cannot assume add/subtract tests cover paths adequately,
 -- here, because the code might be quite different (comparison cannot

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareTotal.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareTotal.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareTotal.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Note that we cannot assume add/subtract tests cover paths adequately,
 -- here, because the code might be quite different (comparison cannot

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareTotalMag.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareTotalMag.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareTotalMag.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Note that we cannot assume add/subtract tests cover paths adequately,
 -- here, because the code might be quite different (comparison cannot

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopy.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopy.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopy.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decDoubles.
 precision:   16

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopyAbs.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopyAbs.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopyAbs.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decDoubles.
 precision:   16

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopyNegate.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopyNegate.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopyNegate.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decDoubles.
 precision:   16

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopySign.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopySign.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopySign.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decDoubles.
 precision:   16

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddDivide.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddDivide.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddDivide.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddDivideInt.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddDivideInt.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddDivideInt.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddEncode.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddEncode.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddEncode.decTest	Thu Mar 27 00:48:05 2008
@@ -18,7 +18,7 @@
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
 -- [Previously called decimal64.decTest]
-version: 2.56
+version: 2.57
 
 -- This set of tests is for the eight-byte concrete representation.
 -- Its characteristics are:
@@ -485,3 +485,6 @@
 decd829 apply  #2238000115afb55b ->  4294967295
 decd830 apply  #2238000115afb57a ->  4294967296
 decd831 apply  #2238000115afb57b ->  4294967297
+
+-- for narrowing
+decd840 apply  #2870000000000000 ->  2.000000000000000E-99

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddFMA.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddFMA.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddFMA.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384
@@ -1663,6 +1663,34 @@
 ddfma375088 fma  1  12345678 1E-34                   -> 12345678.00000001 Inexact Rounded
 ddfma375089 fma  1  12345678 1E-35                   -> 12345678.00000001 Inexact Rounded
 
+-- desctructive subtraction (from remainder tests)
+
+-- +++ some of these will be off-by-one remainder vs remainderNear
+
+ddfma4000  fma  -1234567890123454   1.000000000000001    1234567890123456  ->  0.765432109876546
+ddfma4001  fma  -1234567890123443    1.00000000000001    1234567890123456  ->  0.65432109876557
+ddfma4002  fma  -1234567890123332     1.0000000000001    1234567890123456  ->  0.5432109876668
+ddfma4003  fma   -308641972530863   4.000000000000001    1234567890123455  ->  2.691358027469137
+ddfma4004  fma   -308641972530863   4.000000000000001    1234567890123456  ->  3.691358027469137
+ddfma4005  fma   -246913578024696     4.9999999999999    1234567890123456  ->  0.6913578024696
+ddfma4006  fma   -246913578024691    4.99999999999999    1234567890123456  ->  3.46913578024691
+ddfma4007  fma   -246913578024691   4.999999999999999    1234567890123456  ->  1.246913578024691
+ddfma4008  fma   -246913578024691   5.000000000000001    1234567890123456  ->  0.753086421975309
+ddfma4009  fma   -246913578024690    5.00000000000001    1234567890123456  ->  3.53086421975310
+ddfma4010  fma   -246913578024686     5.0000000000001    1234567890123456  ->  1.3086421975314
+ddfma4011  fma  -1234567890123455   1.000000000000001    1234567890123456  ->  -0.234567890123455
+ddfma4012  fma  -1234567890123444    1.00000000000001    1234567890123456  ->  -0.34567890123444
+ddfma4013  fma  -1234567890123333     1.0000000000001    1234567890123456  ->  -0.4567890123333
+ddfma4014  fma   -308641972530864   4.000000000000001    1234567890123455  ->  -1.308641972530864
+ddfma4015  fma   -308641972530864   4.000000000000001    1234567890123456  ->  -0.308641972530864
+ddfma4016  fma   -246913578024696     4.9999999999999    1234567890123456  ->  0.6913578024696
+ddfma4017  fma   -246913578024692    4.99999999999999    1234567890123456  ->  -1.53086421975308
+ddfma4018  fma   -246913578024691   4.999999999999999    1234567890123456  ->  1.246913578024691
+ddfma4019  fma   -246913578024691   5.000000000000001    1234567890123456  ->  0.753086421975309
+ddfma4020  fma   -246913578024691    5.00000000000001    1234567890123456  ->  -1.46913578024691
+ddfma4021  fma   -246913578024686     5.0000000000001    1234567890123456  ->  1.3086421975314
+
+
 -- Null tests
 ddfma39990 fma  1  10  # -> NaN Invalid_operation
 ddfma39991 fma  1   # 10 -> NaN Invalid_operation

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddInvert.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddInvert.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddInvert.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddLogB.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddLogB.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddLogB.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMax.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMax.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMax.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- we assume that base comparison is tested in compare.decTest, so
 -- these mainly cover special cases and rounding

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMaxMag.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMaxMag.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMaxMag.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- we assume that base comparison is tested in compare.decTest, so
 -- these mainly cover special cases and rounding

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMin.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMin.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMin.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- we assume that base comparison is tested in compare.decTest, so
 -- these mainly cover special cases and rounding

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMinMag.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMinMag.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMinMag.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- we assume that base comparison is tested in compare.decTest, so
 -- these mainly cover special cases and rounding

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMinus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMinus.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMinus.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decDoubles.
 precision:   16

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMultiply.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMultiply.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMultiply.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests are for decDoubles only; all arguments are
 -- representable in a decDouble
@@ -454,9 +454,92 @@
 -- hugest
 ddmul909 multiply  9999999999999999 9999999999999999 -> 9.999999999999998E+31 Inexact Rounded
 
+-- power-of-ten edge cases
+ddmul1001 multiply  1      10               -> 10
+ddmul1002 multiply  1      100              -> 100
+ddmul1003 multiply  1      1000             -> 1000
+ddmul1004 multiply  1      10000            -> 10000
+ddmul1005 multiply  1      100000           -> 100000
+ddmul1006 multiply  1      1000000          -> 1000000
+ddmul1007 multiply  1      10000000         -> 10000000
+ddmul1008 multiply  1      100000000        -> 100000000
+ddmul1009 multiply  1      1000000000       -> 1000000000
+ddmul1010 multiply  1      10000000000      -> 10000000000
+ddmul1011 multiply  1      100000000000     -> 100000000000
+ddmul1012 multiply  1      1000000000000    -> 1000000000000
+ddmul1013 multiply  1      10000000000000   -> 10000000000000
+ddmul1014 multiply  1      100000000000000  -> 100000000000000
+ddmul1015 multiply  1      1000000000000000 -> 1000000000000000
+ddmul1021 multiply  10     1                -> 10
+ddmul1022 multiply  10     10               -> 100
+ddmul1023 multiply  10     100              -> 1000
+ddmul1024 multiply  10     1000             -> 10000
+ddmul1025 multiply  10     10000            -> 100000
+ddmul1026 multiply  10     100000           -> 1000000
+ddmul1027 multiply  10     1000000          -> 10000000
+ddmul1028 multiply  10     10000000         -> 100000000
+ddmul1029 multiply  10     100000000        -> 1000000000
+ddmul1030 multiply  10     1000000000       -> 10000000000
+ddmul1031 multiply  10     10000000000      -> 100000000000
+ddmul1032 multiply  10     100000000000     -> 1000000000000
+ddmul1033 multiply  10     1000000000000    -> 10000000000000
+ddmul1034 multiply  10     10000000000000   -> 100000000000000
+ddmul1035 multiply  10     100000000000000  -> 1000000000000000
+ddmul1041 multiply  100    0.1              -> 10.0
+ddmul1042 multiply  100    1                -> 100
+ddmul1043 multiply  100    10               -> 1000
+ddmul1044 multiply  100    100              -> 10000
+ddmul1045 multiply  100    1000             -> 100000
+ddmul1046 multiply  100    10000            -> 1000000
+ddmul1047 multiply  100    100000           -> 10000000
+ddmul1048 multiply  100    1000000          -> 100000000
+ddmul1049 multiply  100    10000000         -> 1000000000
+ddmul1050 multiply  100    100000000        -> 10000000000
+ddmul1051 multiply  100    1000000000       -> 100000000000
+ddmul1052 multiply  100    10000000000      -> 1000000000000
+ddmul1053 multiply  100    100000000000     -> 10000000000000
+ddmul1054 multiply  100    1000000000000    -> 100000000000000
+ddmul1055 multiply  100    10000000000000   -> 1000000000000000
+ddmul1061 multiply  1000   0.01             -> 10.00
+ddmul1062 multiply  1000   0.1              -> 100.0
+ddmul1063 multiply  1000   1                -> 1000
+ddmul1064 multiply  1000   10               -> 10000
+ddmul1065 multiply  1000   100              -> 100000
+ddmul1066 multiply  1000   1000             -> 1000000
+ddmul1067 multiply  1000   10000            -> 10000000
+ddmul1068 multiply  1000   100000           -> 100000000
+ddmul1069 multiply  1000   1000000          -> 1000000000
+ddmul1070 multiply  1000   10000000         -> 10000000000
+ddmul1071 multiply  1000   100000000        -> 100000000000
+ddmul1072 multiply  1000   1000000000       -> 1000000000000
+ddmul1073 multiply  1000   10000000000      -> 10000000000000
+ddmul1074 multiply  1000   100000000000     -> 100000000000000
+ddmul1075 multiply  1000   1000000000000    -> 1000000000000000
+ddmul1081 multiply  10000  0.001            -> 10.000
+ddmul1082 multiply  10000  0.01             -> 100.00
+ddmul1083 multiply  10000  0.1              -> 1000.0
+ddmul1084 multiply  10000  1                -> 10000
+ddmul1085 multiply  10000  10               -> 100000
+ddmul1086 multiply  10000  100              -> 1000000
+ddmul1087 multiply  10000  1000             -> 10000000
+ddmul1088 multiply  10000  10000            -> 100000000
+ddmul1089 multiply  10000  100000           -> 1000000000
+ddmul1090 multiply  10000  1000000          -> 10000000000
+ddmul1091 multiply  10000  10000000         -> 100000000000
+ddmul1092 multiply  10000  100000000        -> 1000000000000
+ddmul1093 multiply  10000  1000000000       -> 10000000000000
+ddmul1094 multiply  10000  10000000000      -> 100000000000000
+ddmul1095 multiply  10000  100000000000     -> 1000000000000000
+
+ddmul1097 multiply  10000   99999999999     ->  999999999990000
+ddmul1098 multiply  10000   99999999999     ->  999999999990000
+
+
+
+
 -- Null tests
-ddmul990 multiply 10  # -> NaN Invalid_operation
-ddmul991 multiply  # 10 -> NaN Invalid_operation
+ddmul9990 multiply 10  # -> NaN Invalid_operation
+ddmul9991 multiply  # 10 -> NaN Invalid_operation
 
 
 

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextMinus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextMinus.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextMinus.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decDoubles.
 precision:   16

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextPlus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextPlus.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextPlus.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decDoubles.
 precision:   16

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextToward.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextToward.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextToward.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decDoubles.
 precision:   16

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddOr.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddOr.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddOr.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddPlus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddPlus.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddPlus.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decDoubles.
 precision:   16

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddQuantize.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddQuantize.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddQuantize.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Most of the tests here assume a "regular pattern", where the
 -- sign and coefficient are +1.

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddReduce.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddReduce.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddReduce.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRemainder.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRemainder.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRemainder.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384
@@ -581,6 +581,19 @@
 ddrem1057 remainder -1e-277  1e+311 -> -1E-277
 ddrem1058 remainder -1e-277 -1e+311 -> -1E-277
 
+-- destructive subtract
+ddrem1101 remainder  1234567890123456  1.000000000000001  ->  0.765432109876546
+ddrem1102 remainder  1234567890123456   1.00000000000001  ->   0.65432109876557
+ddrem1103 remainder  1234567890123456    1.0000000000001  ->    0.5432109876668
+ddrem1104 remainder  1234567890123455  4.000000000000001  ->  2.691358027469137
+ddrem1105 remainder  1234567890123456  4.000000000000001  ->  3.691358027469137
+ddrem1106 remainder  1234567890123456    4.9999999999999  ->    0.6913578024696
+ddrem1107 remainder  1234567890123456   4.99999999999999  ->   3.46913578024691
+ddrem1108 remainder  1234567890123456  4.999999999999999  ->  1.246913578024691
+ddrem1109 remainder  1234567890123456  5.000000000000001  ->  0.753086421975309
+ddrem1110 remainder  1234567890123456   5.00000000000001  ->   3.53086421975310
+ddrem1111 remainder  1234567890123456    5.0000000000001  ->    1.3086421975314
+
 -- Null tests
 ddrem1000 remainder 10  # -> NaN Invalid_operation
 ddrem1001 remainder  # 10 -> NaN Invalid_operation

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRemainderNear.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRemainderNear.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRemainderNear.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384
@@ -599,6 +599,7 @@
 
 ddrmn980 remaindernear 123e1 1000E299 -> 1.23E+3  -- 123E+1 internally
 
+
 -- overflow and underflow tests [from divide]
 ddrmn1051 remaindernear  1e+277  1e-311 ->  NaN Division_impossible
 ddrmn1052 remaindernear  1e+277 -1e-311 ->  NaN Division_impossible
@@ -609,6 +610,19 @@
 ddrmn1057 remaindernear -1e-277  1e+311 -> -1E-277
 ddrmn1058 remaindernear -1e-277 -1e+311 -> -1E-277
 
+-- destructive subtract
+ddrmn1100 remainderNear  1234567890123456  1.000000000000001  ->  -0.234567890123455
+ddrmn1101 remainderNear  1234567890123456   1.00000000000001  ->   -0.34567890123444
+ddrmn1102 remainderNear  1234567890123456    1.0000000000001  ->    -0.4567890123333
+ddrmn1103 remainderNear  1234567890123455  4.000000000000001  ->  -1.308641972530864
+ddrmn1104 remainderNear  1234567890123456  4.000000000000001  ->  -0.308641972530864
+ddrmn1115 remainderNear  1234567890123456    4.9999999999999  ->     0.6913578024696
+ddrmn1116 remainderNear  1234567890123456   4.99999999999999  ->   -1.53086421975308
+ddrmn1117 remainderNear  1234567890123456  4.999999999999999  ->   1.246913578024691
+ddrmn1118 remainderNear  1234567890123456  5.000000000000001  ->   0.753086421975309
+ddrmn1119 remainderNear  1234567890123456   5.00000000000001  ->   -1.46913578024691
+ddrmn1110 remainderNear  1234567890123456    5.0000000000001  ->     1.3086421975314
+
 -- Null tests
 ddrmn1000 remaindernear 10  # -> NaN Invalid_operation
 ddrmn1001 remaindernear  # 10 -> NaN Invalid_operation

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRotate.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRotate.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRotate.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddSameQuantum.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddSameQuantum.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddSameQuantum.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decDoubles.
 precision:   16

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddScaleB.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddScaleB.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddScaleB.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddShift.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddShift.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddShift.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddSubtract.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddSubtract.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddSubtract.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests are for decDoubles only; all arguments are
 -- representable in a decDouble

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddToIntegral.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddToIntegral.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddToIntegral.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests tests the extended specification 'round-to-integral
 -- value-exact' operations (from IEEE 854, later modified in 754r).

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ddXor.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ddXor.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ddXor.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 precision:   16
 maxExponent: 384

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/decDouble.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/decDouble.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/decDouble.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- decDouble tests
 dectest: ddAbs

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/decQuad.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/decQuad.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/decQuad.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- decQuad tests
 dectest: dqAbs

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/decSingle.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/decSingle.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/decSingle.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- decSingle tests
 dectest: dsBase

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/divide.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/divide.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/divide.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/divideint.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/divideint.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/divideint.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAbs.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAbs.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAbs.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAdd.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAdd.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAdd.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests are for decQuads only; all arguments are
 -- representable in a decQuad

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAnd.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAnd.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAnd.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqBase.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqBase.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqBase.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This file tests base conversions from string to a decimal number
 -- and back to a string (in Scientific form)

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCanonical.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCanonical.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCanonical.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This file tests that copy operations leave uncanonical operands
 -- unchanged, and vice versa

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqClass.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqClass.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqClass.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- [New 2006.11.27]
 

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompare.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompare.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompare.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Note that we cannot assume add/subtract tests cover paths adequately,
 -- here, because the code might be quite different (comparison cannot

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareSig.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareSig.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareSig.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Note that we cannot assume add/subtract tests cover paths adequately,
 -- here, because the code might be quite different (comparison cannot

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareTotal.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareTotal.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareTotal.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Note that we cannot assume add/subtract tests cover paths adequately,
 -- here, because the code might be quite different (comparison cannot

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareTotalMag.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareTotalMag.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareTotalMag.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Note that we cannot assume add/subtract tests cover paths adequately,
 -- here, because the code might be quite different (comparison cannot

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopy.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopy.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopy.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decQuads.
 extended:    1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopyAbs.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopyAbs.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopyAbs.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decQuads.
 extended:    1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopyNegate.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopyNegate.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopyNegate.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decQuads.
 extended:    1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopySign.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopySign.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopySign.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decQuads.
 extended:    1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqDivide.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqDivide.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqDivide.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqDivideInt.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqDivideInt.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqDivideInt.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqEncode.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqEncode.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqEncode.decTest	Thu Mar 27 00:48:05 2008
@@ -18,7 +18,7 @@
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
 -- [Previously called decimal128.decTest]
-version: 2.56
+version: 2.57
 
 -- This set of tests is for the sixteen-byte concrete representation.
 -- Its characteristics are:
@@ -468,3 +468,10 @@
 decq829 apply  #22080000000000000000000115afb55b ->  4294967295
 decq830 apply  #22080000000000000000000115afb57a ->  4294967296
 decq831 apply  #22080000000000000000000115afb57b ->  4294967297
+
+-- VG testcase
+decq840 apply    #2080000000000000F294000000172636 -> 8.81125000000001349436E-1548
+decq841 apply    #20800000000000008000000000000000 -> 8.000000000000000000E-1550
+decq842 apply    #1EF98490000000010F6E4E0000000000 -> 7.049000000000010795488000000000000E-3097
+decq843 multiply #20800000000000008000000000000000 #2080000000000000F294000000172636 -> #1EF98490000000010F6E4E0000000000 Rounded
+

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqFMA.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqFMA.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqFMA.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1
@@ -1754,6 +1754,31 @@
 dqadd375088 fma  1  12398765432112345678945678 1E-34                   -> 12398765432112345678945678.00000001 Inexact Rounded
 dqadd375089 fma  1  12398765432112345678945678 1E-35                   -> 12398765432112345678945678.00000001 Inexact Rounded
 
+-- Destructive subtract (from remainder tests)
+
+-- +++ some of these will be off-by-one remainder vs remainderNear
+
+dqfma4000  fma  -1234567890123456789012345678901233   1.000000000000000000000000000000001    1234567890123456789012345678901234  ->  -0.234567890123456789012345678901233
+dqfma4001  fma  -1234567890123456789012345678901222    1.00000000000000000000000000000001    1234567890123456789012345678901234  ->  -0.34567890123456789012345678901222
+dqfma4002  fma  -1234567890123456789012345678901111     1.0000000000000000000000000000001    1234567890123456789012345678901234  ->  -0.4567890123456789012345678901111
+dqfma4003  fma   -308641972530864197253086419725314   4.000000000000000000000000000000001    1234567890123456789012345678901255  ->  -1.308641972530864197253086419725314
+dqfma4004  fma   -308641972530864197253086419725308   4.000000000000000000000000000000001    1234567890123456789012345678901234  ->  1.691358027469135802746913580274692
+dqfma4005  fma   -246913578024691357802469135780252     4.9999999999999999999999999999999    1234567890123456789012345678901234  ->  -1.3086421975308642197530864219748
+dqfma4006  fma   -246913578024691357802469135780247    4.99999999999999999999999999999999    1234567890123456789012345678901234  ->  1.46913578024691357802469135780247
+dqfma4007  fma   -246913578024691357802469135780247   4.999999999999999999999999999999999    1234567890123456789012345678901234  ->  -0.753086421975308642197530864219753
+dqfma4008  fma   -246913578024691357802469135780247   5.000000000000000000000000000000001    1234567890123456789012345678901234  ->  -1.246913578024691357802469135780247
+dqfma4009  fma   -246913578024691357802469135780246    5.00000000000000000000000000000001    1234567890123456789012345678901234  ->  1.53086421975308642197530864219754
+dqfma4010  fma   -246913578024691357802469135780242     5.0000000000000000000000000000001    1234567890123456789012345678901234  ->  -0.6913578024691357802469135780242
+dqfma4011  fma  -1234567890123456789012345678901232   1.000000000000000000000000000000001    1234567890123456789012345678901234  ->  0.765432109876543210987654321098768
+dqfma4012  fma  -1234567890123456789012345678901221    1.00000000000000000000000000000001    1234567890123456789012345678901234  ->  0.65432109876543210987654321098779
+dqfma4013  fma  -1234567890123456789012345678901110     1.0000000000000000000000000000001    1234567890123456789012345678901234  ->  0.5432109876543210987654321098890
+dqfma4014  fma   -308641972530864197253086419725313   4.000000000000000000000000000000001    1234567890123456789012345678901255  ->  2.691358027469135802746913580274687
+dqfma4015  fma   -308641972530864197253086419725308   4.000000000000000000000000000000001    1234567890123456789012345678901234  ->  1.691358027469135802746913580274692
+dqfma4016  fma   -246913578024691357802469135780251     4.9999999999999999999999999999999    1234567890123456789012345678901234  ->  3.6913578024691357802469135780251
+dqfma4017  fma   -246913578024691357802469135780247    4.99999999999999999999999999999999    1234567890123456789012345678901234  ->  1.46913578024691357802469135780247
+dqfma4018  fma   -246913578024691357802469135780246   4.999999999999999999999999999999999    1234567890123456789012345678901234  ->  4.246913578024691357802469135780246
+dqfma4019  fma   -246913578024691357802469135780241     5.0000000000000000000000000000001    1234567890123456789012345678901234  ->  4.3086421975308642197530864219759
+
 -- Null tests
 dqadd39990 fma  1  10  # -> NaN Invalid_operation
 dqadd39991 fma  1   # 10 -> NaN Invalid_operation

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqInvert.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqInvert.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqInvert.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqLogB.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqLogB.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqLogB.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMax.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMax.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMax.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- we assume that base comparison is tested in compare.decTest, so
 -- these mainly cover special cases and rounding

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMaxMag.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMaxMag.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMaxMag.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- we assume that base comparison is tested in compare.decTest, so
 -- these mainly cover special cases and rounding

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMin.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMin.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMin.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- we assume that base comparison is tested in compare.decTest, so
 -- these mainly cover special cases and rounding

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMinMag.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMinMag.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMinMag.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- we assume that base comparison is tested in compare.decTest, so
 -- these mainly cover special cases and rounding

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMinus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMinus.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMinus.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decQuads.
 extended:    1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMultiply.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMultiply.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMultiply.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests are for decQuads only; all arguments are
 -- representable in a decQuad
@@ -456,18 +456,134 @@
 
 -- hugest
 dqmul909 multiply 9999999999999999999999999999999999 9999999999999999999999999999999999 -> 9.999999999999999999999999999999998E+67 Inexact Rounded
+-- VG case
+dqmul910 multiply 8.81125000000001349436E-1548 8.000000000000000000E-1550 -> 7.049000000000010795488000000000000E-3097 Rounded
 
 -- Examples from SQL proposal (Krishna Kulkarni)
 precision:   34
 rounding:    half_up
 maxExponent: 6144
 minExponent: -6143
-dqmul1001  multiply 130E-2  120E-2 -> 1.5600
-dqmul1002  multiply 130E-2  12E-1  -> 1.560
-dqmul1003  multiply 130E-2  1E0    -> 1.30
-dqmul1004  multiply 1E2     1E4    -> 1E+6
+dqmul911  multiply 130E-2  120E-2 -> 1.5600
+dqmul912  multiply 130E-2  12E-1  -> 1.560
+dqmul913  multiply 130E-2  1E0    -> 1.30
+dqmul914  multiply 1E2     1E4    -> 1E+6
+
+-- power-of-ten edge cases
+dqmul1001 multiply  1      10               -> 10
+dqmul1002 multiply  1      100              -> 100
+dqmul1003 multiply  1      1000             -> 1000
+dqmul1004 multiply  1      10000            -> 10000
+dqmul1005 multiply  1      100000           -> 100000
+dqmul1006 multiply  1      1000000          -> 1000000
+dqmul1007 multiply  1      10000000         -> 10000000
+dqmul1008 multiply  1      100000000        -> 100000000
+dqmul1009 multiply  1      1000000000       -> 1000000000
+dqmul1010 multiply  1      10000000000      -> 10000000000
+dqmul1011 multiply  1      100000000000     -> 100000000000
+dqmul1012 multiply  1      1000000000000    -> 1000000000000
+dqmul1013 multiply  1      10000000000000   -> 10000000000000
+dqmul1014 multiply  1      100000000000000  -> 100000000000000
+dqmul1015 multiply  1      1000000000000000 -> 1000000000000000
+
+dqmul1016 multiply  1      1000000000000000000 -> 1000000000000000000
+dqmul1017 multiply  1      100000000000000000000000000 -> 100000000000000000000000000
+dqmul1018 multiply  1      1000000000000000000000000000 -> 1000000000000000000000000000
+dqmul1019 multiply  1      10000000000000000000000000000 -> 10000000000000000000000000000
+dqmul1020 multiply  1      1000000000000000000000000000000000 -> 1000000000000000000000000000000000
+
+dqmul1021 multiply  10     1                -> 10
+dqmul1022 multiply  10     10               -> 100
+dqmul1023 multiply  10     100              -> 1000
+dqmul1024 multiply  10     1000             -> 10000
+dqmul1025 multiply  10     10000            -> 100000
+dqmul1026 multiply  10     100000           -> 1000000
+dqmul1027 multiply  10     1000000          -> 10000000
+dqmul1028 multiply  10     10000000         -> 100000000
+dqmul1029 multiply  10     100000000        -> 1000000000
+dqmul1030 multiply  10     1000000000       -> 10000000000
+dqmul1031 multiply  10     10000000000      -> 100000000000
+dqmul1032 multiply  10     100000000000     -> 1000000000000
+dqmul1033 multiply  10     1000000000000    -> 10000000000000
+dqmul1034 multiply  10     10000000000000   -> 100000000000000
+dqmul1035 multiply  10     100000000000000  -> 1000000000000000
+
+dqmul1036 multiply  10     100000000000000000 -> 1000000000000000000
+dqmul1037 multiply  10     10000000000000000000000000 -> 100000000000000000000000000
+dqmul1038 multiply  10     100000000000000000000000000 -> 1000000000000000000000000000
+dqmul1039 multiply  10     1000000000000000000000000000 -> 10000000000000000000000000000
+dqmul1040 multiply  10     100000000000000000000000000000000 -> 1000000000000000000000000000000000
+
+dqmul1041 multiply  100    0.1              -> 10.0
+dqmul1042 multiply  100    1                -> 100
+dqmul1043 multiply  100    10               -> 1000
+dqmul1044 multiply  100    100              -> 10000
+dqmul1045 multiply  100    1000             -> 100000
+dqmul1046 multiply  100    10000            -> 1000000
+dqmul1047 multiply  100    100000           -> 10000000
+dqmul1048 multiply  100    1000000          -> 100000000
+dqmul1049 multiply  100    10000000         -> 1000000000
+dqmul1050 multiply  100    100000000        -> 10000000000
+dqmul1051 multiply  100    1000000000       -> 100000000000
+dqmul1052 multiply  100    10000000000      -> 1000000000000
+dqmul1053 multiply  100    100000000000     -> 10000000000000
+dqmul1054 multiply  100    1000000000000    -> 100000000000000
+dqmul1055 multiply  100    10000000000000   -> 1000000000000000
+
+dqmul1056 multiply  100    10000000000000000 -> 1000000000000000000
+dqmul1057 multiply  100    1000000000000000000000000 -> 100000000000000000000000000
+dqmul1058 multiply  100    10000000000000000000000000 -> 1000000000000000000000000000
+dqmul1059 multiply  100    100000000000000000000000000 -> 10000000000000000000000000000
+dqmul1060 multiply  100    10000000000000000000000000000000 -> 1000000000000000000000000000000000
+
+dqmul1061 multiply  1000   0.01             -> 10.00
+dqmul1062 multiply  1000   0.1              -> 100.0
+dqmul1063 multiply  1000   1                -> 1000
+dqmul1064 multiply  1000   10               -> 10000
+dqmul1065 multiply  1000   100              -> 100000
+dqmul1066 multiply  1000   1000             -> 1000000
+dqmul1067 multiply  1000   10000            -> 10000000
+dqmul1068 multiply  1000   100000           -> 100000000
+dqmul1069 multiply  1000   1000000          -> 1000000000
+dqmul1070 multiply  1000   10000000         -> 10000000000
+dqmul1071 multiply  1000   100000000        -> 100000000000
+dqmul1072 multiply  1000   1000000000       -> 1000000000000
+dqmul1073 multiply  1000   10000000000      -> 10000000000000
+dqmul1074 multiply  1000   100000000000     -> 100000000000000
+dqmul1075 multiply  1000   1000000000000    -> 1000000000000000
+
+dqmul1076 multiply  1000   1000000000000000 -> 1000000000000000000
+dqmul1077 multiply  1000   100000000000000000000000 -> 100000000000000000000000000
+dqmul1078 multiply  1000   1000000000000000000000000 -> 1000000000000000000000000000
+dqmul1079 multiply  1000   10000000000000000000000000 -> 10000000000000000000000000000
+dqmul1080 multiply  1000   1000000000000000000000000000000 -> 1000000000000000000000000000000000
+
+dqmul1081 multiply  10000  0.001            -> 10.000
+dqmul1082 multiply  10000  0.01             -> 100.00
+dqmul1083 multiply  10000  0.1              -> 1000.0
+dqmul1084 multiply  10000  1                -> 10000
+dqmul1085 multiply  10000  10               -> 100000
+dqmul1086 multiply  10000  100              -> 1000000
+dqmul1087 multiply  10000  1000             -> 10000000
+dqmul1088 multiply  10000  10000            -> 100000000
+dqmul1089 multiply  10000  100000           -> 1000000000
+dqmul1090 multiply  10000  1000000          -> 10000000000
+dqmul1091 multiply  10000  10000000         -> 100000000000
+dqmul1092 multiply  10000  100000000        -> 1000000000000
+dqmul1093 multiply  10000  1000000000       -> 10000000000000
+dqmul1094 multiply  10000  10000000000      -> 100000000000000
+dqmul1095 multiply  10000  100000000000     -> 1000000000000000
+
+dqmul1096 multiply  10000  100000000000000 -> 1000000000000000000
+dqmul1097 multiply  10000  10000000000000000000000 -> 100000000000000000000000000
+dqmul1098 multiply  10000  100000000000000000000000 -> 1000000000000000000000000000
+dqmul1099 multiply  10000  1000000000000000000000000 -> 10000000000000000000000000000
+dqmul1100 multiply  10000  100000000000000000000000000000 -> 1000000000000000000000000000000000
+
+dqmul1107 multiply  10000   99999999999     ->  999999999990000
+dqmul1108 multiply  10000   99999999999     ->  999999999990000
 
 -- Null tests
-dqmul990 multiply 10  # -> NaN Invalid_operation
-dqmul991 multiply  # 10 -> NaN Invalid_operation
+dqmul9990 multiply 10  # -> NaN Invalid_operation
+dqmul9991 multiply  # 10 -> NaN Invalid_operation
 

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextMinus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextMinus.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextMinus.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decQuads.
 extended:    1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextPlus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextPlus.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextPlus.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decQuads.
 extended:    1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextToward.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextToward.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextToward.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decQuads.
 extended:    1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqOr.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqOr.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqOr.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqPlus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqPlus.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqPlus.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decQuads.
 extended:    1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqQuantize.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqQuantize.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqQuantize.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Most of the tests here assume a "regular pattern", where the
 -- sign and coefficient are +1.

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqReduce.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqReduce.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqReduce.decTest	Thu Mar 27 00:48:05 2008
@@ -18,7 +18,7 @@
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
 
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRemainder.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRemainder.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRemainder.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1
@@ -580,6 +580,17 @@
 -- Gyuris example
 dqrem1070 remainder 8.336804418094040989630006819881709E-6143 8.336804418094040989630006819889000E-6143 -> 8.336804418094040989630006819881709E-6143
 
+-- destructive subtract
+dqrem1120  remainder  1234567890123456789012345678901234  1.000000000000000000000000000000001  ->  0.765432109876543210987654321098768
+dqrem1121  remainder  1234567890123456789012345678901234   1.00000000000000000000000000000001  ->   0.65432109876543210987654321098779
+dqrem1122  remainder  1234567890123456789012345678901234    1.0000000000000000000000000000001  ->    0.5432109876543210987654321098890
+dqrem1123  remainder  1234567890123456789012345678901255  4.000000000000000000000000000000001  ->  2.691358027469135802746913580274687
+dqrem1124  remainder  1234567890123456789012345678901234  4.000000000000000000000000000000001  ->  1.691358027469135802746913580274692
+dqrem1125  remainder  1234567890123456789012345678901234    4.9999999999999999999999999999999  ->    3.6913578024691357802469135780251
+dqrem1126  remainder  1234567890123456789012345678901234   4.99999999999999999999999999999999  ->   1.46913578024691357802469135780247
+dqrem1127  remainder  1234567890123456789012345678901234  4.999999999999999999999999999999999  ->  4.246913578024691357802469135780246
+dqrem1128  remainder  1234567890123456789012345678901234    5.0000000000000000000000000000001  ->    4.3086421975308642197530864219759
+
 -- Null tests
 dqrem1000 remainder 10  # -> NaN Invalid_operation
 dqrem1001 remainder  # 10 -> NaN Invalid_operation

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRemainderNear.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRemainderNear.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRemainderNear.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1
@@ -612,6 +612,19 @@
 -- Gyuris example
 dqrmn1070 remainder 8.336804418094040989630006819881709E-6143 8.336804418094040989630006819889000E-6143 -> 8.336804418094040989630006819881709E-6143
 
+-- destructive subtract
+dqrmn1101  remaindernear  1234567890123456789012345678901234  1.000000000000000000000000000000001  ->  -0.234567890123456789012345678901233
+dqrmn1102  remaindernear  1234567890123456789012345678901234   1.00000000000000000000000000000001  ->   -0.34567890123456789012345678901222
+dqrmn1103  remaindernear  1234567890123456789012345678901234    1.0000000000000000000000000000001  ->    -0.4567890123456789012345678901111
+dqrmn1104  remaindernear  1234567890123456789012345678901255  4.000000000000000000000000000000001  ->  -1.308641972530864197253086419725314
+dqrmn1105  remaindernear  1234567890123456789012345678901234  4.000000000000000000000000000000001  ->   1.691358027469135802746913580274692
+dqrmn1106  remaindernear  1234567890123456789012345678901234    4.9999999999999999999999999999999  ->    -1.3086421975308642197530864219748
+dqrmn1107  remaindernear  1234567890123456789012345678901234   4.99999999999999999999999999999999  ->    1.46913578024691357802469135780247
+dqrmn1108  remaindernear  1234567890123456789012345678901234  4.999999999999999999999999999999999  ->  -0.753086421975308642197530864219753
+dqrmn1109  remaindernear  1234567890123456789012345678901234  5.000000000000000000000000000000001  ->  -1.246913578024691357802469135780247
+dqrmn1110  remaindernear  1234567890123456789012345678901234   5.00000000000000000000000000000001  ->    1.53086421975308642197530864219754
+dqrmn1111  remaindernear  1234567890123456789012345678901234    5.0000000000000000000000000000001  ->    -0.6913578024691357802469135780242
+
 -- Null tests
 dqrmn1000 remaindernear 10  # -> NaN Invalid_operation
 dqrmn1001 remaindernear  # 10 -> NaN Invalid_operation

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRotate.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRotate.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRotate.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqSameQuantum.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqSameQuantum.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqSameQuantum.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- All operands and results are decQuads.
 extended:    1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqScaleB.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqScaleB.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqScaleB.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqShift.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqShift.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqShift.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqSubtract.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqSubtract.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqSubtract.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests are for decQuads only; all arguments are
 -- representable in a decQuad

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqToIntegral.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqToIntegral.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqToIntegral.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests tests the extended specification 'round-to-integral
 -- value-exact' operations (from IEEE 854, later modified in 754r).

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dqXor.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dqXor.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dqXor.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 clamp:       1

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dsBase.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dsBase.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dsBase.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This file tests base conversions from string to a decimal number
 -- and back to a string (in Scientific form)
@@ -1058,4 +1058,5 @@
 dsbas1107 toSci +1E-383 ->  0E-101 Inexact Rounded Subnormal Underflow Clamped
 dsbas1108 toSci +9.999999999999999E+384 ->  Infinity Overflow Inexact Rounded
 
-
+-- narrowing case
+dsbas1110 toSci 2.000000000000000E-99 -> 2.00E-99 Rounded Subnormal

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/dsEncode.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/dsEncode.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/dsEncode.decTest	Thu Mar 27 00:48:05 2008
@@ -18,7 +18,7 @@
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
 -- [Previously called decimal32.decTest]
-version: 2.56
+version: 2.57
 
 -- This set of tests is for the four-byte concrete representation.
 -- Its characteristics are:
@@ -367,3 +367,6 @@
 decs786 apply   #225002ff       -> 999
 decs787 apply   #225003ff       -> 999
 
+-- narrowing case
+decs790 apply 2.00E-99 -> #00000100 Subnormal
+decs791 apply #00000100 -> 2.00E-99 Subnormal

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/exp.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/exp.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/exp.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Tests of the exponential funtion.  Currently all testcases here
 -- show results which are correctly rounded (within <= 0.5 ulp).

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/extra.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/extra.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/extra.decTest	Thu Mar 27 00:48:05 2008
@@ -154,6 +154,2112 @@
 extr1302 fma 0E123 -Inf sNaN789 -> NaN Invalid_operation
 extr1302 fma -Inf 0E-456 sNaN148 -> NaN Invalid_operation
 
+-- Tests for the is_* boolean operations
+precision: 9
+maxExponent: 999
+minExponent: -999
+
+bool0000 iscanonical 0E-2000 -> 1
+bool0001 iscanonical -0E-2000 -> 1
+bool0002 iscanonical 0E-1008 -> 1
+bool0003 iscanonical -0E-1008 -> 1
+bool0004 iscanonical 0E-1007 -> 1
+bool0005 iscanonical -0E-1007 -> 1
+bool0006 iscanonical 0E-1006 -> 1
+bool0007 iscanonical -0E-1006 -> 1
+bool0008 iscanonical 0E-1000 -> 1
+bool0009 iscanonical -0E-1000 -> 1
+bool0010 iscanonical 0E-999 -> 1
+bool0011 iscanonical -0E-999 -> 1
+bool0012 iscanonical 0E-998 -> 1
+bool0013 iscanonical -0E-998 -> 1
+bool0014 iscanonical 0E-100 -> 1
+bool0015 iscanonical -0E-100 -> 1
+bool0016 iscanonical 0.000000 -> 1
+bool0017 iscanonical -0.000000 -> 1
+bool0018 iscanonical 0.000 -> 1
+bool0019 iscanonical -0.000 -> 1
+bool0020 iscanonical 0.00 -> 1
+bool0021 iscanonical -0.00 -> 1
+bool0022 iscanonical 0.0 -> 1
+bool0023 iscanonical -0.0 -> 1
+bool0024 iscanonical 0 -> 1
+bool0025 iscanonical -0 -> 1
+bool0026 iscanonical 0E+1 -> 1
+bool0027 iscanonical -0E+1 -> 1
+bool0028 iscanonical 0E+2 -> 1
+bool0029 iscanonical -0E+2 -> 1
+bool0030 iscanonical 0E+3 -> 1
+bool0031 iscanonical -0E+3 -> 1
+bool0032 iscanonical 0E+6 -> 1
+bool0033 iscanonical -0E+6 -> 1
+bool0034 iscanonical 0E+100 -> 1
+bool0035 iscanonical -0E+100 -> 1
+bool0036 iscanonical 0E+990 -> 1
+bool0037 iscanonical -0E+990 -> 1
+bool0038 iscanonical 0E+991 -> 1
+bool0039 iscanonical -0E+991 -> 1
+bool0040 iscanonical 0E+992 -> 1
+bool0041 iscanonical -0E+992 -> 1
+bool0042 iscanonical 0E+998 -> 1
+bool0043 iscanonical -0E+998 -> 1
+bool0044 iscanonical 0E+999 -> 1
+bool0045 iscanonical -0E+999 -> 1
+bool0046 iscanonical 0E+1000 -> 1
+bool0047 iscanonical -0E+1000 -> 1
+bool0048 iscanonical 0E+2000 -> 1
+bool0049 iscanonical -0E+2000 -> 1
+bool0050 iscanonical 1E-2000 -> 1
+bool0051 iscanonical -1E-2000 -> 1
+bool0052 iscanonical 1E-1008 -> 1
+bool0053 iscanonical -1E-1008 -> 1
+bool0054 iscanonical 1E-1007 -> 1
+bool0055 iscanonical -1E-1007 -> 1
+bool0056 iscanonical 1E-1006 -> 1
+bool0057 iscanonical -1E-1006 -> 1
+bool0058 iscanonical 1E-1000 -> 1
+bool0059 iscanonical -1E-1000 -> 1
+bool0060 iscanonical 1E-999 -> 1
+bool0061 iscanonical -1E-999 -> 1
+bool0062 iscanonical 1E-998 -> 1
+bool0063 iscanonical -1E-998 -> 1
+bool0064 iscanonical 1E-100 -> 1
+bool0065 iscanonical -1E-100 -> 1
+bool0066 iscanonical 0.000001 -> 1
+bool0067 iscanonical -0.000001 -> 1
+bool0068 iscanonical 0.001 -> 1
+bool0069 iscanonical -0.001 -> 1
+bool0070 iscanonical 0.01 -> 1
+bool0071 iscanonical -0.01 -> 1
+bool0072 iscanonical 0.1 -> 1
+bool0073 iscanonical -0.1 -> 1
+bool0074 iscanonical 1 -> 1
+bool0075 iscanonical -1 -> 1
+bool0076 iscanonical 1E+1 -> 1
+bool0077 iscanonical -1E+1 -> 1
+bool0078 iscanonical 1E+2 -> 1
+bool0079 iscanonical -1E+2 -> 1
+bool0080 iscanonical 1E+3 -> 1
+bool0081 iscanonical -1E+3 -> 1
+bool0082 iscanonical 1E+6 -> 1
+bool0083 iscanonical -1E+6 -> 1
+bool0084 iscanonical 1E+100 -> 1
+bool0085 iscanonical -1E+100 -> 1
+bool0086 iscanonical 1E+990 -> 1
+bool0087 iscanonical -1E+990 -> 1
+bool0088 iscanonical 1E+991 -> 1
+bool0089 iscanonical -1E+991 -> 1
+bool0090 iscanonical 1E+992 -> 1
+bool0091 iscanonical -1E+992 -> 1
+bool0092 iscanonical 1E+998 -> 1
+bool0093 iscanonical -1E+998 -> 1
+bool0094 iscanonical 1E+999 -> 1
+bool0095 iscanonical -1E+999 -> 1
+bool0096 iscanonical 1E+1000 -> 1
+bool0097 iscanonical -1E+1000 -> 1
+bool0098 iscanonical 1E+2000 -> 1
+bool0099 iscanonical -1E+2000 -> 1
+bool0100 iscanonical 9E-2000 -> 1
+bool0101 iscanonical -9E-2000 -> 1
+bool0102 iscanonical 9E-1008 -> 1
+bool0103 iscanonical -9E-1008 -> 1
+bool0104 iscanonical 9E-1007 -> 1
+bool0105 iscanonical -9E-1007 -> 1
+bool0106 iscanonical 9E-1006 -> 1
+bool0107 iscanonical -9E-1006 -> 1
+bool0108 iscanonical 9E-1000 -> 1
+bool0109 iscanonical -9E-1000 -> 1
+bool0110 iscanonical 9E-999 -> 1
+bool0111 iscanonical -9E-999 -> 1
+bool0112 iscanonical 9E-998 -> 1
+bool0113 iscanonical -9E-998 -> 1
+bool0114 iscanonical 9E-100 -> 1
+bool0115 iscanonical -9E-100 -> 1
+bool0116 iscanonical 0.000009 -> 1
+bool0117 iscanonical -0.000009 -> 1
+bool0118 iscanonical 0.009 -> 1
+bool0119 iscanonical -0.009 -> 1
+bool0120 iscanonical 0.09 -> 1
+bool0121 iscanonical -0.09 -> 1
+bool0122 iscanonical 0.9 -> 1
+bool0123 iscanonical -0.9 -> 1
+bool0124 iscanonical 9 -> 1
+bool0125 iscanonical -9 -> 1
+bool0126 iscanonical 9E+1 -> 1
+bool0127 iscanonical -9E+1 -> 1
+bool0128 iscanonical 9E+2 -> 1
+bool0129 iscanonical -9E+2 -> 1
+bool0130 iscanonical 9E+3 -> 1
+bool0131 iscanonical -9E+3 -> 1
+bool0132 iscanonical 9E+6 -> 1
+bool0133 iscanonical -9E+6 -> 1
+bool0134 iscanonical 9E+100 -> 1
+bool0135 iscanonical -9E+100 -> 1
+bool0136 iscanonical 9E+990 -> 1
+bool0137 iscanonical -9E+990 -> 1
+bool0138 iscanonical 9E+991 -> 1
+bool0139 iscanonical -9E+991 -> 1
+bool0140 iscanonical 9E+992 -> 1
+bool0141 iscanonical -9E+992 -> 1
+bool0142 iscanonical 9E+998 -> 1
+bool0143 iscanonical -9E+998 -> 1
+bool0144 iscanonical 9E+999 -> 1
+bool0145 iscanonical -9E+999 -> 1
+bool0146 iscanonical 9E+1000 -> 1
+bool0147 iscanonical -9E+1000 -> 1
+bool0148 iscanonical 9E+2000 -> 1
+bool0149 iscanonical -9E+2000 -> 1
+bool0150 iscanonical 9.99999999E-2000 -> 1
+bool0151 iscanonical -9.99999999E-2000 -> 1
+bool0152 iscanonical 9.99999999E-1008 -> 1
+bool0153 iscanonical -9.99999999E-1008 -> 1
+bool0154 iscanonical 9.99999999E-1007 -> 1
+bool0155 iscanonical -9.99999999E-1007 -> 1
+bool0156 iscanonical 9.99999999E-1006 -> 1
+bool0157 iscanonical -9.99999999E-1006 -> 1
+bool0158 iscanonical 9.99999999E-1000 -> 1
+bool0159 iscanonical -9.99999999E-1000 -> 1
+bool0160 iscanonical 9.99999999E-999 -> 1
+bool0161 iscanonical -9.99999999E-999 -> 1
+bool0162 iscanonical 9.99999999E-998 -> 1
+bool0163 iscanonical -9.99999999E-998 -> 1
+bool0164 iscanonical 9.99999999E-100 -> 1
+bool0165 iscanonical -9.99999999E-100 -> 1
+bool0166 iscanonical 0.00000999999999 -> 1
+bool0167 iscanonical -0.00000999999999 -> 1
+bool0168 iscanonical 0.00999999999 -> 1
+bool0169 iscanonical -0.00999999999 -> 1
+bool0170 iscanonical 0.0999999999 -> 1
+bool0171 iscanonical -0.0999999999 -> 1
+bool0172 iscanonical 0.999999999 -> 1
+bool0173 iscanonical -0.999999999 -> 1
+bool0174 iscanonical 9.99999999 -> 1
+bool0175 iscanonical -9.99999999 -> 1
+bool0176 iscanonical 99.9999999 -> 1
+bool0177 iscanonical -99.9999999 -> 1
+bool0178 iscanonical 999.999999 -> 1
+bool0179 iscanonical -999.999999 -> 1
+bool0180 iscanonical 9999.99999 -> 1
+bool0181 iscanonical -9999.99999 -> 1
+bool0182 iscanonical 9999999.99 -> 1
+bool0183 iscanonical -9999999.99 -> 1
+bool0184 iscanonical 9.99999999E+100 -> 1
+bool0185 iscanonical -9.99999999E+100 -> 1
+bool0186 iscanonical 9.99999999E+990 -> 1
+bool0187 iscanonical -9.99999999E+990 -> 1
+bool0188 iscanonical 9.99999999E+991 -> 1
+bool0189 iscanonical -9.99999999E+991 -> 1
+bool0190 iscanonical 9.99999999E+992 -> 1
+bool0191 iscanonical -9.99999999E+992 -> 1
+bool0192 iscanonical 9.99999999E+998 -> 1
+bool0193 iscanonical -9.99999999E+998 -> 1
+bool0194 iscanonical 9.99999999E+999 -> 1
+bool0195 iscanonical -9.99999999E+999 -> 1
+bool0196 iscanonical 9.99999999E+1000 -> 1
+bool0197 iscanonical -9.99999999E+1000 -> 1
+bool0198 iscanonical 9.99999999E+2000 -> 1
+bool0199 iscanonical -9.99999999E+2000 -> 1
+bool0200 iscanonical Infinity -> 1
+bool0201 iscanonical -Infinity -> 1
+bool0202 iscanonical NaN -> 1
+bool0203 iscanonical -NaN -> 1
+bool0204 iscanonical NaN123 -> 1
+bool0205 iscanonical -NaN123 -> 1
+bool0206 iscanonical sNaN -> 1
+bool0207 iscanonical -sNaN -> 1
+bool0208 iscanonical sNaN123 -> 1
+bool0209 iscanonical -sNaN123 -> 1
+bool0210 isfinite 0E-2000 -> 1
+bool0211 isfinite -0E-2000 -> 1
+bool0212 isfinite 0E-1008 -> 1
+bool0213 isfinite -0E-1008 -> 1
+bool0214 isfinite 0E-1007 -> 1
+bool0215 isfinite -0E-1007 -> 1
+bool0216 isfinite 0E-1006 -> 1
+bool0217 isfinite -0E-1006 -> 1
+bool0218 isfinite 0E-1000 -> 1
+bool0219 isfinite -0E-1000 -> 1
+bool0220 isfinite 0E-999 -> 1
+bool0221 isfinite -0E-999 -> 1
+bool0222 isfinite 0E-998 -> 1
+bool0223 isfinite -0E-998 -> 1
+bool0224 isfinite 0E-100 -> 1
+bool0225 isfinite -0E-100 -> 1
+bool0226 isfinite 0.000000 -> 1
+bool0227 isfinite -0.000000 -> 1
+bool0228 isfinite 0.000 -> 1
+bool0229 isfinite -0.000 -> 1
+bool0230 isfinite 0.00 -> 1
+bool0231 isfinite -0.00 -> 1
+bool0232 isfinite 0.0 -> 1
+bool0233 isfinite -0.0 -> 1
+bool0234 isfinite 0 -> 1
+bool0235 isfinite -0 -> 1
+bool0236 isfinite 0E+1 -> 1
+bool0237 isfinite -0E+1 -> 1
+bool0238 isfinite 0E+2 -> 1
+bool0239 isfinite -0E+2 -> 1
+bool0240 isfinite 0E+3 -> 1
+bool0241 isfinite -0E+3 -> 1
+bool0242 isfinite 0E+6 -> 1
+bool0243 isfinite -0E+6 -> 1
+bool0244 isfinite 0E+100 -> 1
+bool0245 isfinite -0E+100 -> 1
+bool0246 isfinite 0E+990 -> 1
+bool0247 isfinite -0E+990 -> 1
+bool0248 isfinite 0E+991 -> 1
+bool0249 isfinite -0E+991 -> 1
+bool0250 isfinite 0E+992 -> 1
+bool0251 isfinite -0E+992 -> 1
+bool0252 isfinite 0E+998 -> 1
+bool0253 isfinite -0E+998 -> 1
+bool0254 isfinite 0E+999 -> 1
+bool0255 isfinite -0E+999 -> 1
+bool0256 isfinite 0E+1000 -> 1
+bool0257 isfinite -0E+1000 -> 1
+bool0258 isfinite 0E+2000 -> 1
+bool0259 isfinite -0E+2000 -> 1
+bool0260 isfinite 1E-2000 -> 1
+bool0261 isfinite -1E-2000 -> 1
+bool0262 isfinite 1E-1008 -> 1
+bool0263 isfinite -1E-1008 -> 1
+bool0264 isfinite 1E-1007 -> 1
+bool0265 isfinite -1E-1007 -> 1
+bool0266 isfinite 1E-1006 -> 1
+bool0267 isfinite -1E-1006 -> 1
+bool0268 isfinite 1E-1000 -> 1
+bool0269 isfinite -1E-1000 -> 1
+bool0270 isfinite 1E-999 -> 1
+bool0271 isfinite -1E-999 -> 1
+bool0272 isfinite 1E-998 -> 1
+bool0273 isfinite -1E-998 -> 1
+bool0274 isfinite 1E-100 -> 1
+bool0275 isfinite -1E-100 -> 1
+bool0276 isfinite 0.000001 -> 1
+bool0277 isfinite -0.000001 -> 1
+bool0278 isfinite 0.001 -> 1
+bool0279 isfinite -0.001 -> 1
+bool0280 isfinite 0.01 -> 1
+bool0281 isfinite -0.01 -> 1
+bool0282 isfinite 0.1 -> 1
+bool0283 isfinite -0.1 -> 1
+bool0284 isfinite 1 -> 1
+bool0285 isfinite -1 -> 1
+bool0286 isfinite 1E+1 -> 1
+bool0287 isfinite -1E+1 -> 1
+bool0288 isfinite 1E+2 -> 1
+bool0289 isfinite -1E+2 -> 1
+bool0290 isfinite 1E+3 -> 1
+bool0291 isfinite -1E+3 -> 1
+bool0292 isfinite 1E+6 -> 1
+bool0293 isfinite -1E+6 -> 1
+bool0294 isfinite 1E+100 -> 1
+bool0295 isfinite -1E+100 -> 1
+bool0296 isfinite 1E+990 -> 1
+bool0297 isfinite -1E+990 -> 1
+bool0298 isfinite 1E+991 -> 1
+bool0299 isfinite -1E+991 -> 1
+bool0300 isfinite 1E+992 -> 1
+bool0301 isfinite -1E+992 -> 1
+bool0302 isfinite 1E+998 -> 1
+bool0303 isfinite -1E+998 -> 1
+bool0304 isfinite 1E+999 -> 1
+bool0305 isfinite -1E+999 -> 1
+bool0306 isfinite 1E+1000 -> 1
+bool0307 isfinite -1E+1000 -> 1
+bool0308 isfinite 1E+2000 -> 1
+bool0309 isfinite -1E+2000 -> 1
+bool0310 isfinite 9E-2000 -> 1
+bool0311 isfinite -9E-2000 -> 1
+bool0312 isfinite 9E-1008 -> 1
+bool0313 isfinite -9E-1008 -> 1
+bool0314 isfinite 9E-1007 -> 1
+bool0315 isfinite -9E-1007 -> 1
+bool0316 isfinite 9E-1006 -> 1
+bool0317 isfinite -9E-1006 -> 1
+bool0318 isfinite 9E-1000 -> 1
+bool0319 isfinite -9E-1000 -> 1
+bool0320 isfinite 9E-999 -> 1
+bool0321 isfinite -9E-999 -> 1
+bool0322 isfinite 9E-998 -> 1
+bool0323 isfinite -9E-998 -> 1
+bool0324 isfinite 9E-100 -> 1
+bool0325 isfinite -9E-100 -> 1
+bool0326 isfinite 0.000009 -> 1
+bool0327 isfinite -0.000009 -> 1
+bool0328 isfinite 0.009 -> 1
+bool0329 isfinite -0.009 -> 1
+bool0330 isfinite 0.09 -> 1
+bool0331 isfinite -0.09 -> 1
+bool0332 isfinite 0.9 -> 1
+bool0333 isfinite -0.9 -> 1
+bool0334 isfinite 9 -> 1
+bool0335 isfinite -9 -> 1
+bool0336 isfinite 9E+1 -> 1
+bool0337 isfinite -9E+1 -> 1
+bool0338 isfinite 9E+2 -> 1
+bool0339 isfinite -9E+2 -> 1
+bool0340 isfinite 9E+3 -> 1
+bool0341 isfinite -9E+3 -> 1
+bool0342 isfinite 9E+6 -> 1
+bool0343 isfinite -9E+6 -> 1
+bool0344 isfinite 9E+100 -> 1
+bool0345 isfinite -9E+100 -> 1
+bool0346 isfinite 9E+990 -> 1
+bool0347 isfinite -9E+990 -> 1
+bool0348 isfinite 9E+991 -> 1
+bool0349 isfinite -9E+991 -> 1
+bool0350 isfinite 9E+992 -> 1
+bool0351 isfinite -9E+992 -> 1
+bool0352 isfinite 9E+998 -> 1
+bool0353 isfinite -9E+998 -> 1
+bool0354 isfinite 9E+999 -> 1
+bool0355 isfinite -9E+999 -> 1
+bool0356 isfinite 9E+1000 -> 1
+bool0357 isfinite -9E+1000 -> 1
+bool0358 isfinite 9E+2000 -> 1
+bool0359 isfinite -9E+2000 -> 1
+bool0360 isfinite 9.99999999E-2000 -> 1
+bool0361 isfinite -9.99999999E-2000 -> 1
+bool0362 isfinite 9.99999999E-1008 -> 1
+bool0363 isfinite -9.99999999E-1008 -> 1
+bool0364 isfinite 9.99999999E-1007 -> 1
+bool0365 isfinite -9.99999999E-1007 -> 1
+bool0366 isfinite 9.99999999E-1006 -> 1
+bool0367 isfinite -9.99999999E-1006 -> 1
+bool0368 isfinite 9.99999999E-1000 -> 1
+bool0369 isfinite -9.99999999E-1000 -> 1
+bool0370 isfinite 9.99999999E-999 -> 1
+bool0371 isfinite -9.99999999E-999 -> 1
+bool0372 isfinite 9.99999999E-998 -> 1
+bool0373 isfinite -9.99999999E-998 -> 1
+bool0374 isfinite 9.99999999E-100 -> 1
+bool0375 isfinite -9.99999999E-100 -> 1
+bool0376 isfinite 0.00000999999999 -> 1
+bool0377 isfinite -0.00000999999999 -> 1
+bool0378 isfinite 0.00999999999 -> 1
+bool0379 isfinite -0.00999999999 -> 1
+bool0380 isfinite 0.0999999999 -> 1
+bool0381 isfinite -0.0999999999 -> 1
+bool0382 isfinite 0.999999999 -> 1
+bool0383 isfinite -0.999999999 -> 1
+bool0384 isfinite 9.99999999 -> 1
+bool0385 isfinite -9.99999999 -> 1
+bool0386 isfinite 99.9999999 -> 1
+bool0387 isfinite -99.9999999 -> 1
+bool0388 isfinite 999.999999 -> 1
+bool0389 isfinite -999.999999 -> 1
+bool0390 isfinite 9999.99999 -> 1
+bool0391 isfinite -9999.99999 -> 1
+bool0392 isfinite 9999999.99 -> 1
+bool0393 isfinite -9999999.99 -> 1
+bool0394 isfinite 9.99999999E+100 -> 1
+bool0395 isfinite -9.99999999E+100 -> 1
+bool0396 isfinite 9.99999999E+990 -> 1
+bool0397 isfinite -9.99999999E+990 -> 1
+bool0398 isfinite 9.99999999E+991 -> 1
+bool0399 isfinite -9.99999999E+991 -> 1
+bool0400 isfinite 9.99999999E+992 -> 1
+bool0401 isfinite -9.99999999E+992 -> 1
+bool0402 isfinite 9.99999999E+998 -> 1
+bool0403 isfinite -9.99999999E+998 -> 1
+bool0404 isfinite 9.99999999E+999 -> 1
+bool0405 isfinite -9.99999999E+999 -> 1
+bool0406 isfinite 9.99999999E+1000 -> 1
+bool0407 isfinite -9.99999999E+1000 -> 1
+bool0408 isfinite 9.99999999E+2000 -> 1
+bool0409 isfinite -9.99999999E+2000 -> 1
+bool0410 isfinite Infinity -> 0
+bool0411 isfinite -Infinity -> 0
+bool0412 isfinite NaN -> 0
+bool0413 isfinite -NaN -> 0
+bool0414 isfinite NaN123 -> 0
+bool0415 isfinite -NaN123 -> 0
+bool0416 isfinite sNaN -> 0
+bool0417 isfinite -sNaN -> 0
+bool0418 isfinite sNaN123 -> 0
+bool0419 isfinite -sNaN123 -> 0
+bool0420 isinfinite 0E-2000 -> 0
+bool0421 isinfinite -0E-2000 -> 0
+bool0422 isinfinite 0E-1008 -> 0
+bool0423 isinfinite -0E-1008 -> 0
+bool0424 isinfinite 0E-1007 -> 0
+bool0425 isinfinite -0E-1007 -> 0
+bool0426 isinfinite 0E-1006 -> 0
+bool0427 isinfinite -0E-1006 -> 0
+bool0428 isinfinite 0E-1000 -> 0
+bool0429 isinfinite -0E-1000 -> 0
+bool0430 isinfinite 0E-999 -> 0
+bool0431 isinfinite -0E-999 -> 0
+bool0432 isinfinite 0E-998 -> 0
+bool0433 isinfinite -0E-998 -> 0
+bool0434 isinfinite 0E-100 -> 0
+bool0435 isinfinite -0E-100 -> 0
+bool0436 isinfinite 0.000000 -> 0
+bool0437 isinfinite -0.000000 -> 0
+bool0438 isinfinite 0.000 -> 0
+bool0439 isinfinite -0.000 -> 0
+bool0440 isinfinite 0.00 -> 0
+bool0441 isinfinite -0.00 -> 0
+bool0442 isinfinite 0.0 -> 0
+bool0443 isinfinite -0.0 -> 0
+bool0444 isinfinite 0 -> 0
+bool0445 isinfinite -0 -> 0
+bool0446 isinfinite 0E+1 -> 0
+bool0447 isinfinite -0E+1 -> 0
+bool0448 isinfinite 0E+2 -> 0
+bool0449 isinfinite -0E+2 -> 0
+bool0450 isinfinite 0E+3 -> 0
+bool0451 isinfinite -0E+3 -> 0
+bool0452 isinfinite 0E+6 -> 0
+bool0453 isinfinite -0E+6 -> 0
+bool0454 isinfinite 0E+100 -> 0
+bool0455 isinfinite -0E+100 -> 0
+bool0456 isinfinite 0E+990 -> 0
+bool0457 isinfinite -0E+990 -> 0
+bool0458 isinfinite 0E+991 -> 0
+bool0459 isinfinite -0E+991 -> 0
+bool0460 isinfinite 0E+992 -> 0
+bool0461 isinfinite -0E+992 -> 0
+bool0462 isinfinite 0E+998 -> 0
+bool0463 isinfinite -0E+998 -> 0
+bool0464 isinfinite 0E+999 -> 0
+bool0465 isinfinite -0E+999 -> 0
+bool0466 isinfinite 0E+1000 -> 0
+bool0467 isinfinite -0E+1000 -> 0
+bool0468 isinfinite 0E+2000 -> 0
+bool0469 isinfinite -0E+2000 -> 0
+bool0470 isinfinite 1E-2000 -> 0
+bool0471 isinfinite -1E-2000 -> 0
+bool0472 isinfinite 1E-1008 -> 0
+bool0473 isinfinite -1E-1008 -> 0
+bool0474 isinfinite 1E-1007 -> 0
+bool0475 isinfinite -1E-1007 -> 0
+bool0476 isinfinite 1E-1006 -> 0
+bool0477 isinfinite -1E-1006 -> 0
+bool0478 isinfinite 1E-1000 -> 0
+bool0479 isinfinite -1E-1000 -> 0
+bool0480 isinfinite 1E-999 -> 0
+bool0481 isinfinite -1E-999 -> 0
+bool0482 isinfinite 1E-998 -> 0
+bool0483 isinfinite -1E-998 -> 0
+bool0484 isinfinite 1E-100 -> 0
+bool0485 isinfinite -1E-100 -> 0
+bool0486 isinfinite 0.000001 -> 0
+bool0487 isinfinite -0.000001 -> 0
+bool0488 isinfinite 0.001 -> 0
+bool0489 isinfinite -0.001 -> 0
+bool0490 isinfinite 0.01 -> 0
+bool0491 isinfinite -0.01 -> 0
+bool0492 isinfinite 0.1 -> 0
+bool0493 isinfinite -0.1 -> 0
+bool0494 isinfinite 1 -> 0
+bool0495 isinfinite -1 -> 0
+bool0496 isinfinite 1E+1 -> 0
+bool0497 isinfinite -1E+1 -> 0
+bool0498 isinfinite 1E+2 -> 0
+bool0499 isinfinite -1E+2 -> 0
+bool0500 isinfinite 1E+3 -> 0
+bool0501 isinfinite -1E+3 -> 0
+bool0502 isinfinite 1E+6 -> 0
+bool0503 isinfinite -1E+6 -> 0
+bool0504 isinfinite 1E+100 -> 0
+bool0505 isinfinite -1E+100 -> 0
+bool0506 isinfinite 1E+990 -> 0
+bool0507 isinfinite -1E+990 -> 0
+bool0508 isinfinite 1E+991 -> 0
+bool0509 isinfinite -1E+991 -> 0
+bool0510 isinfinite 1E+992 -> 0
+bool0511 isinfinite -1E+992 -> 0
+bool0512 isinfinite 1E+998 -> 0
+bool0513 isinfinite -1E+998 -> 0
+bool0514 isinfinite 1E+999 -> 0
+bool0515 isinfinite -1E+999 -> 0
+bool0516 isinfinite 1E+1000 -> 0
+bool0517 isinfinite -1E+1000 -> 0
+bool0518 isinfinite 1E+2000 -> 0
+bool0519 isinfinite -1E+2000 -> 0
+bool0520 isinfinite 9E-2000 -> 0
+bool0521 isinfinite -9E-2000 -> 0
+bool0522 isinfinite 9E-1008 -> 0
+bool0523 isinfinite -9E-1008 -> 0
+bool0524 isinfinite 9E-1007 -> 0
+bool0525 isinfinite -9E-1007 -> 0
+bool0526 isinfinite 9E-1006 -> 0
+bool0527 isinfinite -9E-1006 -> 0
+bool0528 isinfinite 9E-1000 -> 0
+bool0529 isinfinite -9E-1000 -> 0
+bool0530 isinfinite 9E-999 -> 0
+bool0531 isinfinite -9E-999 -> 0
+bool0532 isinfinite 9E-998 -> 0
+bool0533 isinfinite -9E-998 -> 0
+bool0534 isinfinite 9E-100 -> 0
+bool0535 isinfinite -9E-100 -> 0
+bool0536 isinfinite 0.000009 -> 0
+bool0537 isinfinite -0.000009 -> 0
+bool0538 isinfinite 0.009 -> 0
+bool0539 isinfinite -0.009 -> 0
+bool0540 isinfinite 0.09 -> 0
+bool0541 isinfinite -0.09 -> 0
+bool0542 isinfinite 0.9 -> 0
+bool0543 isinfinite -0.9 -> 0
+bool0544 isinfinite 9 -> 0
+bool0545 isinfinite -9 -> 0
+bool0546 isinfinite 9E+1 -> 0
+bool0547 isinfinite -9E+1 -> 0
+bool0548 isinfinite 9E+2 -> 0
+bool0549 isinfinite -9E+2 -> 0
+bool0550 isinfinite 9E+3 -> 0
+bool0551 isinfinite -9E+3 -> 0
+bool0552 isinfinite 9E+6 -> 0
+bool0553 isinfinite -9E+6 -> 0
+bool0554 isinfinite 9E+100 -> 0
+bool0555 isinfinite -9E+100 -> 0
+bool0556 isinfinite 9E+990 -> 0
+bool0557 isinfinite -9E+990 -> 0
+bool0558 isinfinite 9E+991 -> 0
+bool0559 isinfinite -9E+991 -> 0
+bool0560 isinfinite 9E+992 -> 0
+bool0561 isinfinite -9E+992 -> 0
+bool0562 isinfinite 9E+998 -> 0
+bool0563 isinfinite -9E+998 -> 0
+bool0564 isinfinite 9E+999 -> 0
+bool0565 isinfinite -9E+999 -> 0
+bool0566 isinfinite 9E+1000 -> 0
+bool0567 isinfinite -9E+1000 -> 0
+bool0568 isinfinite 9E+2000 -> 0
+bool0569 isinfinite -9E+2000 -> 0
+bool0570 isinfinite 9.99999999E-2000 -> 0
+bool0571 isinfinite -9.99999999E-2000 -> 0
+bool0572 isinfinite 9.99999999E-1008 -> 0
+bool0573 isinfinite -9.99999999E-1008 -> 0
+bool0574 isinfinite 9.99999999E-1007 -> 0
+bool0575 isinfinite -9.99999999E-1007 -> 0
+bool0576 isinfinite 9.99999999E-1006 -> 0
+bool0577 isinfinite -9.99999999E-1006 -> 0
+bool0578 isinfinite 9.99999999E-1000 -> 0
+bool0579 isinfinite -9.99999999E-1000 -> 0
+bool0580 isinfinite 9.99999999E-999 -> 0
+bool0581 isinfinite -9.99999999E-999 -> 0
+bool0582 isinfinite 9.99999999E-998 -> 0
+bool0583 isinfinite -9.99999999E-998 -> 0
+bool0584 isinfinite 9.99999999E-100 -> 0
+bool0585 isinfinite -9.99999999E-100 -> 0
+bool0586 isinfinite 0.00000999999999 -> 0
+bool0587 isinfinite -0.00000999999999 -> 0
+bool0588 isinfinite 0.00999999999 -> 0
+bool0589 isinfinite -0.00999999999 -> 0
+bool0590 isinfinite 0.0999999999 -> 0
+bool0591 isinfinite -0.0999999999 -> 0
+bool0592 isinfinite 0.999999999 -> 0
+bool0593 isinfinite -0.999999999 -> 0
+bool0594 isinfinite 9.99999999 -> 0
+bool0595 isinfinite -9.99999999 -> 0
+bool0596 isinfinite 99.9999999 -> 0
+bool0597 isinfinite -99.9999999 -> 0
+bool0598 isinfinite 999.999999 -> 0
+bool0599 isinfinite -999.999999 -> 0
+bool0600 isinfinite 9999.99999 -> 0
+bool0601 isinfinite -9999.99999 -> 0
+bool0602 isinfinite 9999999.99 -> 0
+bool0603 isinfinite -9999999.99 -> 0
+bool0604 isinfinite 9.99999999E+100 -> 0
+bool0605 isinfinite -9.99999999E+100 -> 0
+bool0606 isinfinite 9.99999999E+990 -> 0
+bool0607 isinfinite -9.99999999E+990 -> 0
+bool0608 isinfinite 9.99999999E+991 -> 0
+bool0609 isinfinite -9.99999999E+991 -> 0
+bool0610 isinfinite 9.99999999E+992 -> 0
+bool0611 isinfinite -9.99999999E+992 -> 0
+bool0612 isinfinite 9.99999999E+998 -> 0
+bool0613 isinfinite -9.99999999E+998 -> 0
+bool0614 isinfinite 9.99999999E+999 -> 0
+bool0615 isinfinite -9.99999999E+999 -> 0
+bool0616 isinfinite 9.99999999E+1000 -> 0
+bool0617 isinfinite -9.99999999E+1000 -> 0
+bool0618 isinfinite 9.99999999E+2000 -> 0
+bool0619 isinfinite -9.99999999E+2000 -> 0
+bool0620 isinfinite Infinity -> 1
+bool0621 isinfinite -Infinity -> 1
+bool0622 isinfinite NaN -> 0
+bool0623 isinfinite -NaN -> 0
+bool0624 isinfinite NaN123 -> 0
+bool0625 isinfinite -NaN123 -> 0
+bool0626 isinfinite sNaN -> 0
+bool0627 isinfinite -sNaN -> 0
+bool0628 isinfinite sNaN123 -> 0
+bool0629 isinfinite -sNaN123 -> 0
+bool0630 isnan 0E-2000 -> 0
+bool0631 isnan -0E-2000 -> 0
+bool0632 isnan 0E-1008 -> 0
+bool0633 isnan -0E-1008 -> 0
+bool0634 isnan 0E-1007 -> 0
+bool0635 isnan -0E-1007 -> 0
+bool0636 isnan 0E-1006 -> 0
+bool0637 isnan -0E-1006 -> 0
+bool0638 isnan 0E-1000 -> 0
+bool0639 isnan -0E-1000 -> 0
+bool0640 isnan 0E-999 -> 0
+bool0641 isnan -0E-999 -> 0
+bool0642 isnan 0E-998 -> 0
+bool0643 isnan -0E-998 -> 0
+bool0644 isnan 0E-100 -> 0
+bool0645 isnan -0E-100 -> 0
+bool0646 isnan 0.000000 -> 0
+bool0647 isnan -0.000000 -> 0
+bool0648 isnan 0.000 -> 0
+bool0649 isnan -0.000 -> 0
+bool0650 isnan 0.00 -> 0
+bool0651 isnan -0.00 -> 0
+bool0652 isnan 0.0 -> 0
+bool0653 isnan -0.0 -> 0
+bool0654 isnan 0 -> 0
+bool0655 isnan -0 -> 0
+bool0656 isnan 0E+1 -> 0
+bool0657 isnan -0E+1 -> 0
+bool0658 isnan 0E+2 -> 0
+bool0659 isnan -0E+2 -> 0
+bool0660 isnan 0E+3 -> 0
+bool0661 isnan -0E+3 -> 0
+bool0662 isnan 0E+6 -> 0
+bool0663 isnan -0E+6 -> 0
+bool0664 isnan 0E+100 -> 0
+bool0665 isnan -0E+100 -> 0
+bool0666 isnan 0E+990 -> 0
+bool0667 isnan -0E+990 -> 0
+bool0668 isnan 0E+991 -> 0
+bool0669 isnan -0E+991 -> 0
+bool0670 isnan 0E+992 -> 0
+bool0671 isnan -0E+992 -> 0
+bool0672 isnan 0E+998 -> 0
+bool0673 isnan -0E+998 -> 0
+bool0674 isnan 0E+999 -> 0
+bool0675 isnan -0E+999 -> 0
+bool0676 isnan 0E+1000 -> 0
+bool0677 isnan -0E+1000 -> 0
+bool0678 isnan 0E+2000 -> 0
+bool0679 isnan -0E+2000 -> 0
+bool0680 isnan 1E-2000 -> 0
+bool0681 isnan -1E-2000 -> 0
+bool0682 isnan 1E-1008 -> 0
+bool0683 isnan -1E-1008 -> 0
+bool0684 isnan 1E-1007 -> 0
+bool0685 isnan -1E-1007 -> 0
+bool0686 isnan 1E-1006 -> 0
+bool0687 isnan -1E-1006 -> 0
+bool0688 isnan 1E-1000 -> 0
+bool0689 isnan -1E-1000 -> 0
+bool0690 isnan 1E-999 -> 0
+bool0691 isnan -1E-999 -> 0
+bool0692 isnan 1E-998 -> 0
+bool0693 isnan -1E-998 -> 0
+bool0694 isnan 1E-100 -> 0
+bool0695 isnan -1E-100 -> 0
+bool0696 isnan 0.000001 -> 0
+bool0697 isnan -0.000001 -> 0
+bool0698 isnan 0.001 -> 0
+bool0699 isnan -0.001 -> 0
+bool0700 isnan 0.01 -> 0
+bool0701 isnan -0.01 -> 0
+bool0702 isnan 0.1 -> 0
+bool0703 isnan -0.1 -> 0
+bool0704 isnan 1 -> 0
+bool0705 isnan -1 -> 0
+bool0706 isnan 1E+1 -> 0
+bool0707 isnan -1E+1 -> 0
+bool0708 isnan 1E+2 -> 0
+bool0709 isnan -1E+2 -> 0
+bool0710 isnan 1E+3 -> 0
+bool0711 isnan -1E+3 -> 0
+bool0712 isnan 1E+6 -> 0
+bool0713 isnan -1E+6 -> 0
+bool0714 isnan 1E+100 -> 0
+bool0715 isnan -1E+100 -> 0
+bool0716 isnan 1E+990 -> 0
+bool0717 isnan -1E+990 -> 0
+bool0718 isnan 1E+991 -> 0
+bool0719 isnan -1E+991 -> 0
+bool0720 isnan 1E+992 -> 0
+bool0721 isnan -1E+992 -> 0
+bool0722 isnan 1E+998 -> 0
+bool0723 isnan -1E+998 -> 0
+bool0724 isnan 1E+999 -> 0
+bool0725 isnan -1E+999 -> 0
+bool0726 isnan 1E+1000 -> 0
+bool0727 isnan -1E+1000 -> 0
+bool0728 isnan 1E+2000 -> 0
+bool0729 isnan -1E+2000 -> 0
+bool0730 isnan 9E-2000 -> 0
+bool0731 isnan -9E-2000 -> 0
+bool0732 isnan 9E-1008 -> 0
+bool0733 isnan -9E-1008 -> 0
+bool0734 isnan 9E-1007 -> 0
+bool0735 isnan -9E-1007 -> 0
+bool0736 isnan 9E-1006 -> 0
+bool0737 isnan -9E-1006 -> 0
+bool0738 isnan 9E-1000 -> 0
+bool0739 isnan -9E-1000 -> 0
+bool0740 isnan 9E-999 -> 0
+bool0741 isnan -9E-999 -> 0
+bool0742 isnan 9E-998 -> 0
+bool0743 isnan -9E-998 -> 0
+bool0744 isnan 9E-100 -> 0
+bool0745 isnan -9E-100 -> 0
+bool0746 isnan 0.000009 -> 0
+bool0747 isnan -0.000009 -> 0
+bool0748 isnan 0.009 -> 0
+bool0749 isnan -0.009 -> 0
+bool0750 isnan 0.09 -> 0
+bool0751 isnan -0.09 -> 0
+bool0752 isnan 0.9 -> 0
+bool0753 isnan -0.9 -> 0
+bool0754 isnan 9 -> 0
+bool0755 isnan -9 -> 0
+bool0756 isnan 9E+1 -> 0
+bool0757 isnan -9E+1 -> 0
+bool0758 isnan 9E+2 -> 0
+bool0759 isnan -9E+2 -> 0
+bool0760 isnan 9E+3 -> 0
+bool0761 isnan -9E+3 -> 0
+bool0762 isnan 9E+6 -> 0
+bool0763 isnan -9E+6 -> 0
+bool0764 isnan 9E+100 -> 0
+bool0765 isnan -9E+100 -> 0
+bool0766 isnan 9E+990 -> 0
+bool0767 isnan -9E+990 -> 0
+bool0768 isnan 9E+991 -> 0
+bool0769 isnan -9E+991 -> 0
+bool0770 isnan 9E+992 -> 0
+bool0771 isnan -9E+992 -> 0
+bool0772 isnan 9E+998 -> 0
+bool0773 isnan -9E+998 -> 0
+bool0774 isnan 9E+999 -> 0
+bool0775 isnan -9E+999 -> 0
+bool0776 isnan 9E+1000 -> 0
+bool0777 isnan -9E+1000 -> 0
+bool0778 isnan 9E+2000 -> 0
+bool0779 isnan -9E+2000 -> 0
+bool0780 isnan 9.99999999E-2000 -> 0
+bool0781 isnan -9.99999999E-2000 -> 0
+bool0782 isnan 9.99999999E-1008 -> 0
+bool0783 isnan -9.99999999E-1008 -> 0
+bool0784 isnan 9.99999999E-1007 -> 0
+bool0785 isnan -9.99999999E-1007 -> 0
+bool0786 isnan 9.99999999E-1006 -> 0
+bool0787 isnan -9.99999999E-1006 -> 0
+bool0788 isnan 9.99999999E-1000 -> 0
+bool0789 isnan -9.99999999E-1000 -> 0
+bool0790 isnan 9.99999999E-999 -> 0
+bool0791 isnan -9.99999999E-999 -> 0
+bool0792 isnan 9.99999999E-998 -> 0
+bool0793 isnan -9.99999999E-998 -> 0
+bool0794 isnan 9.99999999E-100 -> 0
+bool0795 isnan -9.99999999E-100 -> 0
+bool0796 isnan 0.00000999999999 -> 0
+bool0797 isnan -0.00000999999999 -> 0
+bool0798 isnan 0.00999999999 -> 0
+bool0799 isnan -0.00999999999 -> 0
+bool0800 isnan 0.0999999999 -> 0
+bool0801 isnan -0.0999999999 -> 0
+bool0802 isnan 0.999999999 -> 0
+bool0803 isnan -0.999999999 -> 0
+bool0804 isnan 9.99999999 -> 0
+bool0805 isnan -9.99999999 -> 0
+bool0806 isnan 99.9999999 -> 0
+bool0807 isnan -99.9999999 -> 0
+bool0808 isnan 999.999999 -> 0
+bool0809 isnan -999.999999 -> 0
+bool0810 isnan 9999.99999 -> 0
+bool0811 isnan -9999.99999 -> 0
+bool0812 isnan 9999999.99 -> 0
+bool0813 isnan -9999999.99 -> 0
+bool0814 isnan 9.99999999E+100 -> 0
+bool0815 isnan -9.99999999E+100 -> 0
+bool0816 isnan 9.99999999E+990 -> 0
+bool0817 isnan -9.99999999E+990 -> 0
+bool0818 isnan 9.99999999E+991 -> 0
+bool0819 isnan -9.99999999E+991 -> 0
+bool0820 isnan 9.99999999E+992 -> 0
+bool0821 isnan -9.99999999E+992 -> 0
+bool0822 isnan 9.99999999E+998 -> 0
+bool0823 isnan -9.99999999E+998 -> 0
+bool0824 isnan 9.99999999E+999 -> 0
+bool0825 isnan -9.99999999E+999 -> 0
+bool0826 isnan 9.99999999E+1000 -> 0
+bool0827 isnan -9.99999999E+1000 -> 0
+bool0828 isnan 9.99999999E+2000 -> 0
+bool0829 isnan -9.99999999E+2000 -> 0
+bool0830 isnan Infinity -> 0
+bool0831 isnan -Infinity -> 0
+bool0832 isnan NaN -> 1
+bool0833 isnan -NaN -> 1
+bool0834 isnan NaN123 -> 1
+bool0835 isnan -NaN123 -> 1
+bool0836 isnan sNaN -> 1
+bool0837 isnan -sNaN -> 1
+bool0838 isnan sNaN123 -> 1
+bool0839 isnan -sNaN123 -> 1
+bool0840 isnormal 0E-2000 -> 0
+bool0841 isnormal -0E-2000 -> 0
+bool0842 isnormal 0E-1008 -> 0
+bool0843 isnormal -0E-1008 -> 0
+bool0844 isnormal 0E-1007 -> 0
+bool0845 isnormal -0E-1007 -> 0
+bool0846 isnormal 0E-1006 -> 0
+bool0847 isnormal -0E-1006 -> 0
+bool0848 isnormal 0E-1000 -> 0
+bool0849 isnormal -0E-1000 -> 0
+bool0850 isnormal 0E-999 -> 0
+bool0851 isnormal -0E-999 -> 0
+bool0852 isnormal 0E-998 -> 0
+bool0853 isnormal -0E-998 -> 0
+bool0854 isnormal 0E-100 -> 0
+bool0855 isnormal -0E-100 -> 0
+bool0856 isnormal 0.000000 -> 0
+bool0857 isnormal -0.000000 -> 0
+bool0858 isnormal 0.000 -> 0
+bool0859 isnormal -0.000 -> 0
+bool0860 isnormal 0.00 -> 0
+bool0861 isnormal -0.00 -> 0
+bool0862 isnormal 0.0 -> 0
+bool0863 isnormal -0.0 -> 0
+bool0864 isnormal 0 -> 0
+bool0865 isnormal -0 -> 0
+bool0866 isnormal 0E+1 -> 0
+bool0867 isnormal -0E+1 -> 0
+bool0868 isnormal 0E+2 -> 0
+bool0869 isnormal -0E+2 -> 0
+bool0870 isnormal 0E+3 -> 0
+bool0871 isnormal -0E+3 -> 0
+bool0872 isnormal 0E+6 -> 0
+bool0873 isnormal -0E+6 -> 0
+bool0874 isnormal 0E+100 -> 0
+bool0875 isnormal -0E+100 -> 0
+bool0876 isnormal 0E+990 -> 0
+bool0877 isnormal -0E+990 -> 0
+bool0878 isnormal 0E+991 -> 0
+bool0879 isnormal -0E+991 -> 0
+bool0880 isnormal 0E+992 -> 0
+bool0881 isnormal -0E+992 -> 0
+bool0882 isnormal 0E+998 -> 0
+bool0883 isnormal -0E+998 -> 0
+bool0884 isnormal 0E+999 -> 0
+bool0885 isnormal -0E+999 -> 0
+bool0886 isnormal 0E+1000 -> 0
+bool0887 isnormal -0E+1000 -> 0
+bool0888 isnormal 0E+2000 -> 0
+bool0889 isnormal -0E+2000 -> 0
+bool0890 isnormal 1E-2000 -> 0
+bool0891 isnormal -1E-2000 -> 0
+bool0892 isnormal 1E-1008 -> 0
+bool0893 isnormal -1E-1008 -> 0
+bool0894 isnormal 1E-1007 -> 0
+bool0895 isnormal -1E-1007 -> 0
+bool0896 isnormal 1E-1006 -> 0
+bool0897 isnormal -1E-1006 -> 0
+bool0898 isnormal 1E-1000 -> 0
+bool0899 isnormal -1E-1000 -> 0
+bool0900 isnormal 1E-999 -> 1
+bool0901 isnormal -1E-999 -> 1
+bool0902 isnormal 1E-998 -> 1
+bool0903 isnormal -1E-998 -> 1
+bool0904 isnormal 1E-100 -> 1
+bool0905 isnormal -1E-100 -> 1
+bool0906 isnormal 0.000001 -> 1
+bool0907 isnormal -0.000001 -> 1
+bool0908 isnormal 0.001 -> 1
+bool0909 isnormal -0.001 -> 1
+bool0910 isnormal 0.01 -> 1
+bool0911 isnormal -0.01 -> 1
+bool0912 isnormal 0.1 -> 1
+bool0913 isnormal -0.1 -> 1
+bool0914 isnormal 1 -> 1
+bool0915 isnormal -1 -> 1
+bool0916 isnormal 1E+1 -> 1
+bool0917 isnormal -1E+1 -> 1
+bool0918 isnormal 1E+2 -> 1
+bool0919 isnormal -1E+2 -> 1
+bool0920 isnormal 1E+3 -> 1
+bool0921 isnormal -1E+3 -> 1
+bool0922 isnormal 1E+6 -> 1
+bool0923 isnormal -1E+6 -> 1
+bool0924 isnormal 1E+100 -> 1
+bool0925 isnormal -1E+100 -> 1
+bool0926 isnormal 1E+990 -> 1
+bool0927 isnormal -1E+990 -> 1
+bool0928 isnormal 1E+991 -> 1
+bool0929 isnormal -1E+991 -> 1
+bool0930 isnormal 1E+992 -> 1
+bool0931 isnormal -1E+992 -> 1
+bool0932 isnormal 1E+998 -> 1
+bool0933 isnormal -1E+998 -> 1
+bool0934 isnormal 1E+999 -> 1
+bool0935 isnormal -1E+999 -> 1
+bool0936 isnormal 1E+1000 -> 0
+bool0937 isnormal -1E+1000 -> 0
+bool0938 isnormal 1E+2000 -> 0
+bool0939 isnormal -1E+2000 -> 0
+bool0940 isnormal 9E-2000 -> 0
+bool0941 isnormal -9E-2000 -> 0
+bool0942 isnormal 9E-1008 -> 0
+bool0943 isnormal -9E-1008 -> 0
+bool0944 isnormal 9E-1007 -> 0
+bool0945 isnormal -9E-1007 -> 0
+bool0946 isnormal 9E-1006 -> 0
+bool0947 isnormal -9E-1006 -> 0
+bool0948 isnormal 9E-1000 -> 0
+bool0949 isnormal -9E-1000 -> 0
+bool0950 isnormal 9E-999 -> 1
+bool0951 isnormal -9E-999 -> 1
+bool0952 isnormal 9E-998 -> 1
+bool0953 isnormal -9E-998 -> 1
+bool0954 isnormal 9E-100 -> 1
+bool0955 isnormal -9E-100 -> 1
+bool0956 isnormal 0.000009 -> 1
+bool0957 isnormal -0.000009 -> 1
+bool0958 isnormal 0.009 -> 1
+bool0959 isnormal -0.009 -> 1
+bool0960 isnormal 0.09 -> 1
+bool0961 isnormal -0.09 -> 1
+bool0962 isnormal 0.9 -> 1
+bool0963 isnormal -0.9 -> 1
+bool0964 isnormal 9 -> 1
+bool0965 isnormal -9 -> 1
+bool0966 isnormal 9E+1 -> 1
+bool0967 isnormal -9E+1 -> 1
+bool0968 isnormal 9E+2 -> 1
+bool0969 isnormal -9E+2 -> 1
+bool0970 isnormal 9E+3 -> 1
+bool0971 isnormal -9E+3 -> 1
+bool0972 isnormal 9E+6 -> 1
+bool0973 isnormal -9E+6 -> 1
+bool0974 isnormal 9E+100 -> 1
+bool0975 isnormal -9E+100 -> 1
+bool0976 isnormal 9E+990 -> 1
+bool0977 isnormal -9E+990 -> 1
+bool0978 isnormal 9E+991 -> 1
+bool0979 isnormal -9E+991 -> 1
+bool0980 isnormal 9E+992 -> 1
+bool0981 isnormal -9E+992 -> 1
+bool0982 isnormal 9E+998 -> 1
+bool0983 isnormal -9E+998 -> 1
+bool0984 isnormal 9E+999 -> 1
+bool0985 isnormal -9E+999 -> 1
+bool0986 isnormal 9E+1000 -> 0
+bool0987 isnormal -9E+1000 -> 0
+bool0988 isnormal 9E+2000 -> 0
+bool0989 isnormal -9E+2000 -> 0
+bool0990 isnormal 9.99999999E-2000 -> 0
+bool0991 isnormal -9.99999999E-2000 -> 0
+bool0992 isnormal 9.99999999E-1008 -> 0
+bool0993 isnormal -9.99999999E-1008 -> 0
+bool0994 isnormal 9.99999999E-1007 -> 0
+bool0995 isnormal -9.99999999E-1007 -> 0
+bool0996 isnormal 9.99999999E-1006 -> 0
+bool0997 isnormal -9.99999999E-1006 -> 0
+bool0998 isnormal 9.99999999E-1000 -> 0
+bool0999 isnormal -9.99999999E-1000 -> 0
+bool1000 isnormal 9.99999999E-999 -> 1
+bool1001 isnormal -9.99999999E-999 -> 1
+bool1002 isnormal 9.99999999E-998 -> 1
+bool1003 isnormal -9.99999999E-998 -> 1
+bool1004 isnormal 9.99999999E-100 -> 1
+bool1005 isnormal -9.99999999E-100 -> 1
+bool1006 isnormal 0.00000999999999 -> 1
+bool1007 isnormal -0.00000999999999 -> 1
+bool1008 isnormal 0.00999999999 -> 1
+bool1009 isnormal -0.00999999999 -> 1
+bool1010 isnormal 0.0999999999 -> 1
+bool1011 isnormal -0.0999999999 -> 1
+bool1012 isnormal 0.999999999 -> 1
+bool1013 isnormal -0.999999999 -> 1
+bool1014 isnormal 9.99999999 -> 1
+bool1015 isnormal -9.99999999 -> 1
+bool1016 isnormal 99.9999999 -> 1
+bool1017 isnormal -99.9999999 -> 1
+bool1018 isnormal 999.999999 -> 1
+bool1019 isnormal -999.999999 -> 1
+bool1020 isnormal 9999.99999 -> 1
+bool1021 isnormal -9999.99999 -> 1
+bool1022 isnormal 9999999.99 -> 1
+bool1023 isnormal -9999999.99 -> 1
+bool1024 isnormal 9.99999999E+100 -> 1
+bool1025 isnormal -9.99999999E+100 -> 1
+bool1026 isnormal 9.99999999E+990 -> 1
+bool1027 isnormal -9.99999999E+990 -> 1
+bool1028 isnormal 9.99999999E+991 -> 1
+bool1029 isnormal -9.99999999E+991 -> 1
+bool1030 isnormal 9.99999999E+992 -> 1
+bool1031 isnormal -9.99999999E+992 -> 1
+bool1032 isnormal 9.99999999E+998 -> 1
+bool1033 isnormal -9.99999999E+998 -> 1
+bool1034 isnormal 9.99999999E+999 -> 1
+bool1035 isnormal -9.99999999E+999 -> 1
+bool1036 isnormal 9.99999999E+1000 -> 0
+bool1037 isnormal -9.99999999E+1000 -> 0
+bool1038 isnormal 9.99999999E+2000 -> 0
+bool1039 isnormal -9.99999999E+2000 -> 0
+bool1040 isnormal Infinity -> 0
+bool1041 isnormal -Infinity -> 0
+bool1042 isnormal NaN -> 0
+bool1043 isnormal -NaN -> 0
+bool1044 isnormal NaN123 -> 0
+bool1045 isnormal -NaN123 -> 0
+bool1046 isnormal sNaN -> 0
+bool1047 isnormal -sNaN -> 0
+bool1048 isnormal sNaN123 -> 0
+bool1049 isnormal -sNaN123 -> 0
+bool1050 isqnan 0E-2000 -> 0
+bool1051 isqnan -0E-2000 -> 0
+bool1052 isqnan 0E-1008 -> 0
+bool1053 isqnan -0E-1008 -> 0
+bool1054 isqnan 0E-1007 -> 0
+bool1055 isqnan -0E-1007 -> 0
+bool1056 isqnan 0E-1006 -> 0
+bool1057 isqnan -0E-1006 -> 0
+bool1058 isqnan 0E-1000 -> 0
+bool1059 isqnan -0E-1000 -> 0
+bool1060 isqnan 0E-999 -> 0
+bool1061 isqnan -0E-999 -> 0
+bool1062 isqnan 0E-998 -> 0
+bool1063 isqnan -0E-998 -> 0
+bool1064 isqnan 0E-100 -> 0
+bool1065 isqnan -0E-100 -> 0
+bool1066 isqnan 0.000000 -> 0
+bool1067 isqnan -0.000000 -> 0
+bool1068 isqnan 0.000 -> 0
+bool1069 isqnan -0.000 -> 0
+bool1070 isqnan 0.00 -> 0
+bool1071 isqnan -0.00 -> 0
+bool1072 isqnan 0.0 -> 0
+bool1073 isqnan -0.0 -> 0
+bool1074 isqnan 0 -> 0
+bool1075 isqnan -0 -> 0
+bool1076 isqnan 0E+1 -> 0
+bool1077 isqnan -0E+1 -> 0
+bool1078 isqnan 0E+2 -> 0
+bool1079 isqnan -0E+2 -> 0
+bool1080 isqnan 0E+3 -> 0
+bool1081 isqnan -0E+3 -> 0
+bool1082 isqnan 0E+6 -> 0
+bool1083 isqnan -0E+6 -> 0
+bool1084 isqnan 0E+100 -> 0
+bool1085 isqnan -0E+100 -> 0
+bool1086 isqnan 0E+990 -> 0
+bool1087 isqnan -0E+990 -> 0
+bool1088 isqnan 0E+991 -> 0
+bool1089 isqnan -0E+991 -> 0
+bool1090 isqnan 0E+992 -> 0
+bool1091 isqnan -0E+992 -> 0
+bool1092 isqnan 0E+998 -> 0
+bool1093 isqnan -0E+998 -> 0
+bool1094 isqnan 0E+999 -> 0
+bool1095 isqnan -0E+999 -> 0
+bool1096 isqnan 0E+1000 -> 0
+bool1097 isqnan -0E+1000 -> 0
+bool1098 isqnan 0E+2000 -> 0
+bool1099 isqnan -0E+2000 -> 0
+bool1100 isqnan 1E-2000 -> 0
+bool1101 isqnan -1E-2000 -> 0
+bool1102 isqnan 1E-1008 -> 0
+bool1103 isqnan -1E-1008 -> 0
+bool1104 isqnan 1E-1007 -> 0
+bool1105 isqnan -1E-1007 -> 0
+bool1106 isqnan 1E-1006 -> 0
+bool1107 isqnan -1E-1006 -> 0
+bool1108 isqnan 1E-1000 -> 0
+bool1109 isqnan -1E-1000 -> 0
+bool1110 isqnan 1E-999 -> 0
+bool1111 isqnan -1E-999 -> 0
+bool1112 isqnan 1E-998 -> 0
+bool1113 isqnan -1E-998 -> 0
+bool1114 isqnan 1E-100 -> 0
+bool1115 isqnan -1E-100 -> 0
+bool1116 isqnan 0.000001 -> 0
+bool1117 isqnan -0.000001 -> 0
+bool1118 isqnan 0.001 -> 0
+bool1119 isqnan -0.001 -> 0
+bool1120 isqnan 0.01 -> 0
+bool1121 isqnan -0.01 -> 0
+bool1122 isqnan 0.1 -> 0
+bool1123 isqnan -0.1 -> 0
+bool1124 isqnan 1 -> 0
+bool1125 isqnan -1 -> 0
+bool1126 isqnan 1E+1 -> 0
+bool1127 isqnan -1E+1 -> 0
+bool1128 isqnan 1E+2 -> 0
+bool1129 isqnan -1E+2 -> 0
+bool1130 isqnan 1E+3 -> 0
+bool1131 isqnan -1E+3 -> 0
+bool1132 isqnan 1E+6 -> 0
+bool1133 isqnan -1E+6 -> 0
+bool1134 isqnan 1E+100 -> 0
+bool1135 isqnan -1E+100 -> 0
+bool1136 isqnan 1E+990 -> 0
+bool1137 isqnan -1E+990 -> 0
+bool1138 isqnan 1E+991 -> 0
+bool1139 isqnan -1E+991 -> 0
+bool1140 isqnan 1E+992 -> 0
+bool1141 isqnan -1E+992 -> 0
+bool1142 isqnan 1E+998 -> 0
+bool1143 isqnan -1E+998 -> 0
+bool1144 isqnan 1E+999 -> 0
+bool1145 isqnan -1E+999 -> 0
+bool1146 isqnan 1E+1000 -> 0
+bool1147 isqnan -1E+1000 -> 0
+bool1148 isqnan 1E+2000 -> 0
+bool1149 isqnan -1E+2000 -> 0
+bool1150 isqnan 9E-2000 -> 0
+bool1151 isqnan -9E-2000 -> 0
+bool1152 isqnan 9E-1008 -> 0
+bool1153 isqnan -9E-1008 -> 0
+bool1154 isqnan 9E-1007 -> 0
+bool1155 isqnan -9E-1007 -> 0
+bool1156 isqnan 9E-1006 -> 0
+bool1157 isqnan -9E-1006 -> 0
+bool1158 isqnan 9E-1000 -> 0
+bool1159 isqnan -9E-1000 -> 0
+bool1160 isqnan 9E-999 -> 0
+bool1161 isqnan -9E-999 -> 0
+bool1162 isqnan 9E-998 -> 0
+bool1163 isqnan -9E-998 -> 0
+bool1164 isqnan 9E-100 -> 0
+bool1165 isqnan -9E-100 -> 0
+bool1166 isqnan 0.000009 -> 0
+bool1167 isqnan -0.000009 -> 0
+bool1168 isqnan 0.009 -> 0
+bool1169 isqnan -0.009 -> 0
+bool1170 isqnan 0.09 -> 0
+bool1171 isqnan -0.09 -> 0
+bool1172 isqnan 0.9 -> 0
+bool1173 isqnan -0.9 -> 0
+bool1174 isqnan 9 -> 0
+bool1175 isqnan -9 -> 0
+bool1176 isqnan 9E+1 -> 0
+bool1177 isqnan -9E+1 -> 0
+bool1178 isqnan 9E+2 -> 0
+bool1179 isqnan -9E+2 -> 0
+bool1180 isqnan 9E+3 -> 0
+bool1181 isqnan -9E+3 -> 0
+bool1182 isqnan 9E+6 -> 0
+bool1183 isqnan -9E+6 -> 0
+bool1184 isqnan 9E+100 -> 0
+bool1185 isqnan -9E+100 -> 0
+bool1186 isqnan 9E+990 -> 0
+bool1187 isqnan -9E+990 -> 0
+bool1188 isqnan 9E+991 -> 0
+bool1189 isqnan -9E+991 -> 0
+bool1190 isqnan 9E+992 -> 0
+bool1191 isqnan -9E+992 -> 0
+bool1192 isqnan 9E+998 -> 0
+bool1193 isqnan -9E+998 -> 0
+bool1194 isqnan 9E+999 -> 0
+bool1195 isqnan -9E+999 -> 0
+bool1196 isqnan 9E+1000 -> 0
+bool1197 isqnan -9E+1000 -> 0
+bool1198 isqnan 9E+2000 -> 0
+bool1199 isqnan -9E+2000 -> 0
+bool1200 isqnan 9.99999999E-2000 -> 0
+bool1201 isqnan -9.99999999E-2000 -> 0
+bool1202 isqnan 9.99999999E-1008 -> 0
+bool1203 isqnan -9.99999999E-1008 -> 0
+bool1204 isqnan 9.99999999E-1007 -> 0
+bool1205 isqnan -9.99999999E-1007 -> 0
+bool1206 isqnan 9.99999999E-1006 -> 0
+bool1207 isqnan -9.99999999E-1006 -> 0
+bool1208 isqnan 9.99999999E-1000 -> 0
+bool1209 isqnan -9.99999999E-1000 -> 0
+bool1210 isqnan 9.99999999E-999 -> 0
+bool1211 isqnan -9.99999999E-999 -> 0
+bool1212 isqnan 9.99999999E-998 -> 0
+bool1213 isqnan -9.99999999E-998 -> 0
+bool1214 isqnan 9.99999999E-100 -> 0
+bool1215 isqnan -9.99999999E-100 -> 0
+bool1216 isqnan 0.00000999999999 -> 0
+bool1217 isqnan -0.00000999999999 -> 0
+bool1218 isqnan 0.00999999999 -> 0
+bool1219 isqnan -0.00999999999 -> 0
+bool1220 isqnan 0.0999999999 -> 0
+bool1221 isqnan -0.0999999999 -> 0
+bool1222 isqnan 0.999999999 -> 0
+bool1223 isqnan -0.999999999 -> 0
+bool1224 isqnan 9.99999999 -> 0
+bool1225 isqnan -9.99999999 -> 0
+bool1226 isqnan 99.9999999 -> 0
+bool1227 isqnan -99.9999999 -> 0
+bool1228 isqnan 999.999999 -> 0
+bool1229 isqnan -999.999999 -> 0
+bool1230 isqnan 9999.99999 -> 0
+bool1231 isqnan -9999.99999 -> 0
+bool1232 isqnan 9999999.99 -> 0
+bool1233 isqnan -9999999.99 -> 0
+bool1234 isqnan 9.99999999E+100 -> 0
+bool1235 isqnan -9.99999999E+100 -> 0
+bool1236 isqnan 9.99999999E+990 -> 0
+bool1237 isqnan -9.99999999E+990 -> 0
+bool1238 isqnan 9.99999999E+991 -> 0
+bool1239 isqnan -9.99999999E+991 -> 0
+bool1240 isqnan 9.99999999E+992 -> 0
+bool1241 isqnan -9.99999999E+992 -> 0
+bool1242 isqnan 9.99999999E+998 -> 0
+bool1243 isqnan -9.99999999E+998 -> 0
+bool1244 isqnan 9.99999999E+999 -> 0
+bool1245 isqnan -9.99999999E+999 -> 0
+bool1246 isqnan 9.99999999E+1000 -> 0
+bool1247 isqnan -9.99999999E+1000 -> 0
+bool1248 isqnan 9.99999999E+2000 -> 0
+bool1249 isqnan -9.99999999E+2000 -> 0
+bool1250 isqnan Infinity -> 0
+bool1251 isqnan -Infinity -> 0
+bool1252 isqnan NaN -> 1
+bool1253 isqnan -NaN -> 1
+bool1254 isqnan NaN123 -> 1
+bool1255 isqnan -NaN123 -> 1
+bool1256 isqnan sNaN -> 0
+bool1257 isqnan -sNaN -> 0
+bool1258 isqnan sNaN123 -> 0
+bool1259 isqnan -sNaN123 -> 0
+bool1260 issigned 0E-2000 -> 0
+bool1261 issigned -0E-2000 -> 1
+bool1262 issigned 0E-1008 -> 0
+bool1263 issigned -0E-1008 -> 1
+bool1264 issigned 0E-1007 -> 0
+bool1265 issigned -0E-1007 -> 1
+bool1266 issigned 0E-1006 -> 0
+bool1267 issigned -0E-1006 -> 1
+bool1268 issigned 0E-1000 -> 0
+bool1269 issigned -0E-1000 -> 1
+bool1270 issigned 0E-999 -> 0
+bool1271 issigned -0E-999 -> 1
+bool1272 issigned 0E-998 -> 0
+bool1273 issigned -0E-998 -> 1
+bool1274 issigned 0E-100 -> 0
+bool1275 issigned -0E-100 -> 1
+bool1276 issigned 0.000000 -> 0
+bool1277 issigned -0.000000 -> 1
+bool1278 issigned 0.000 -> 0
+bool1279 issigned -0.000 -> 1
+bool1280 issigned 0.00 -> 0
+bool1281 issigned -0.00 -> 1
+bool1282 issigned 0.0 -> 0
+bool1283 issigned -0.0 -> 1
+bool1284 issigned 0 -> 0
+bool1285 issigned -0 -> 1
+bool1286 issigned 0E+1 -> 0
+bool1287 issigned -0E+1 -> 1
+bool1288 issigned 0E+2 -> 0
+bool1289 issigned -0E+2 -> 1
+bool1290 issigned 0E+3 -> 0
+bool1291 issigned -0E+3 -> 1
+bool1292 issigned 0E+6 -> 0
+bool1293 issigned -0E+6 -> 1
+bool1294 issigned 0E+100 -> 0
+bool1295 issigned -0E+100 -> 1
+bool1296 issigned 0E+990 -> 0
+bool1297 issigned -0E+990 -> 1
+bool1298 issigned 0E+991 -> 0
+bool1299 issigned -0E+991 -> 1
+bool1300 issigned 0E+992 -> 0
+bool1301 issigned -0E+992 -> 1
+bool1302 issigned 0E+998 -> 0
+bool1303 issigned -0E+998 -> 1
+bool1304 issigned 0E+999 -> 0
+bool1305 issigned -0E+999 -> 1
+bool1306 issigned 0E+1000 -> 0
+bool1307 issigned -0E+1000 -> 1
+bool1308 issigned 0E+2000 -> 0
+bool1309 issigned -0E+2000 -> 1
+bool1310 issigned 1E-2000 -> 0
+bool1311 issigned -1E-2000 -> 1
+bool1312 issigned 1E-1008 -> 0
+bool1313 issigned -1E-1008 -> 1
+bool1314 issigned 1E-1007 -> 0
+bool1315 issigned -1E-1007 -> 1
+bool1316 issigned 1E-1006 -> 0
+bool1317 issigned -1E-1006 -> 1
+bool1318 issigned 1E-1000 -> 0
+bool1319 issigned -1E-1000 -> 1
+bool1320 issigned 1E-999 -> 0
+bool1321 issigned -1E-999 -> 1
+bool1322 issigned 1E-998 -> 0
+bool1323 issigned -1E-998 -> 1
+bool1324 issigned 1E-100 -> 0
+bool1325 issigned -1E-100 -> 1
+bool1326 issigned 0.000001 -> 0
+bool1327 issigned -0.000001 -> 1
+bool1328 issigned 0.001 -> 0
+bool1329 issigned -0.001 -> 1
+bool1330 issigned 0.01 -> 0
+bool1331 issigned -0.01 -> 1
+bool1332 issigned 0.1 -> 0
+bool1333 issigned -0.1 -> 1
+bool1334 issigned 1 -> 0
+bool1335 issigned -1 -> 1
+bool1336 issigned 1E+1 -> 0
+bool1337 issigned -1E+1 -> 1
+bool1338 issigned 1E+2 -> 0
+bool1339 issigned -1E+2 -> 1
+bool1340 issigned 1E+3 -> 0
+bool1341 issigned -1E+3 -> 1
+bool1342 issigned 1E+6 -> 0
+bool1343 issigned -1E+6 -> 1
+bool1344 issigned 1E+100 -> 0
+bool1345 issigned -1E+100 -> 1
+bool1346 issigned 1E+990 -> 0
+bool1347 issigned -1E+990 -> 1
+bool1348 issigned 1E+991 -> 0
+bool1349 issigned -1E+991 -> 1
+bool1350 issigned 1E+992 -> 0
+bool1351 issigned -1E+992 -> 1
+bool1352 issigned 1E+998 -> 0
+bool1353 issigned -1E+998 -> 1
+bool1354 issigned 1E+999 -> 0
+bool1355 issigned -1E+999 -> 1
+bool1356 issigned 1E+1000 -> 0
+bool1357 issigned -1E+1000 -> 1
+bool1358 issigned 1E+2000 -> 0
+bool1359 issigned -1E+2000 -> 1
+bool1360 issigned 9E-2000 -> 0
+bool1361 issigned -9E-2000 -> 1
+bool1362 issigned 9E-1008 -> 0
+bool1363 issigned -9E-1008 -> 1
+bool1364 issigned 9E-1007 -> 0
+bool1365 issigned -9E-1007 -> 1
+bool1366 issigned 9E-1006 -> 0
+bool1367 issigned -9E-1006 -> 1
+bool1368 issigned 9E-1000 -> 0
+bool1369 issigned -9E-1000 -> 1
+bool1370 issigned 9E-999 -> 0
+bool1371 issigned -9E-999 -> 1
+bool1372 issigned 9E-998 -> 0
+bool1373 issigned -9E-998 -> 1
+bool1374 issigned 9E-100 -> 0
+bool1375 issigned -9E-100 -> 1
+bool1376 issigned 0.000009 -> 0
+bool1377 issigned -0.000009 -> 1
+bool1378 issigned 0.009 -> 0
+bool1379 issigned -0.009 -> 1
+bool1380 issigned 0.09 -> 0
+bool1381 issigned -0.09 -> 1
+bool1382 issigned 0.9 -> 0
+bool1383 issigned -0.9 -> 1
+bool1384 issigned 9 -> 0
+bool1385 issigned -9 -> 1
+bool1386 issigned 9E+1 -> 0
+bool1387 issigned -9E+1 -> 1
+bool1388 issigned 9E+2 -> 0
+bool1389 issigned -9E+2 -> 1
+bool1390 issigned 9E+3 -> 0
+bool1391 issigned -9E+3 -> 1
+bool1392 issigned 9E+6 -> 0
+bool1393 issigned -9E+6 -> 1
+bool1394 issigned 9E+100 -> 0
+bool1395 issigned -9E+100 -> 1
+bool1396 issigned 9E+990 -> 0
+bool1397 issigned -9E+990 -> 1
+bool1398 issigned 9E+991 -> 0
+bool1399 issigned -9E+991 -> 1
+bool1400 issigned 9E+992 -> 0
+bool1401 issigned -9E+992 -> 1
+bool1402 issigned 9E+998 -> 0
+bool1403 issigned -9E+998 -> 1
+bool1404 issigned 9E+999 -> 0
+bool1405 issigned -9E+999 -> 1
+bool1406 issigned 9E+1000 -> 0
+bool1407 issigned -9E+1000 -> 1
+bool1408 issigned 9E+2000 -> 0
+bool1409 issigned -9E+2000 -> 1
+bool1410 issigned 9.99999999E-2000 -> 0
+bool1411 issigned -9.99999999E-2000 -> 1
+bool1412 issigned 9.99999999E-1008 -> 0
+bool1413 issigned -9.99999999E-1008 -> 1
+bool1414 issigned 9.99999999E-1007 -> 0
+bool1415 issigned -9.99999999E-1007 -> 1
+bool1416 issigned 9.99999999E-1006 -> 0
+bool1417 issigned -9.99999999E-1006 -> 1
+bool1418 issigned 9.99999999E-1000 -> 0
+bool1419 issigned -9.99999999E-1000 -> 1
+bool1420 issigned 9.99999999E-999 -> 0
+bool1421 issigned -9.99999999E-999 -> 1
+bool1422 issigned 9.99999999E-998 -> 0
+bool1423 issigned -9.99999999E-998 -> 1
+bool1424 issigned 9.99999999E-100 -> 0
+bool1425 issigned -9.99999999E-100 -> 1
+bool1426 issigned 0.00000999999999 -> 0
+bool1427 issigned -0.00000999999999 -> 1
+bool1428 issigned 0.00999999999 -> 0
+bool1429 issigned -0.00999999999 -> 1
+bool1430 issigned 0.0999999999 -> 0
+bool1431 issigned -0.0999999999 -> 1
+bool1432 issigned 0.999999999 -> 0
+bool1433 issigned -0.999999999 -> 1
+bool1434 issigned 9.99999999 -> 0
+bool1435 issigned -9.99999999 -> 1
+bool1436 issigned 99.9999999 -> 0
+bool1437 issigned -99.9999999 -> 1
+bool1438 issigned 999.999999 -> 0
+bool1439 issigned -999.999999 -> 1
+bool1440 issigned 9999.99999 -> 0
+bool1441 issigned -9999.99999 -> 1
+bool1442 issigned 9999999.99 -> 0
+bool1443 issigned -9999999.99 -> 1
+bool1444 issigned 9.99999999E+100 -> 0
+bool1445 issigned -9.99999999E+100 -> 1
+bool1446 issigned 9.99999999E+990 -> 0
+bool1447 issigned -9.99999999E+990 -> 1
+bool1448 issigned 9.99999999E+991 -> 0
+bool1449 issigned -9.99999999E+991 -> 1
+bool1450 issigned 9.99999999E+992 -> 0
+bool1451 issigned -9.99999999E+992 -> 1
+bool1452 issigned 9.99999999E+998 -> 0
+bool1453 issigned -9.99999999E+998 -> 1
+bool1454 issigned 9.99999999E+999 -> 0
+bool1455 issigned -9.99999999E+999 -> 1
+bool1456 issigned 9.99999999E+1000 -> 0
+bool1457 issigned -9.99999999E+1000 -> 1
+bool1458 issigned 9.99999999E+2000 -> 0
+bool1459 issigned -9.99999999E+2000 -> 1
+bool1460 issigned Infinity -> 0
+bool1461 issigned -Infinity -> 1
+bool1462 issigned NaN -> 0
+bool1463 issigned -NaN -> 1
+bool1464 issigned NaN123 -> 0
+bool1465 issigned -NaN123 -> 1
+bool1466 issigned sNaN -> 0
+bool1467 issigned -sNaN -> 1
+bool1468 issigned sNaN123 -> 0
+bool1469 issigned -sNaN123 -> 1
+bool1470 issnan 0E-2000 -> 0
+bool1471 issnan -0E-2000 -> 0
+bool1472 issnan 0E-1008 -> 0
+bool1473 issnan -0E-1008 -> 0
+bool1474 issnan 0E-1007 -> 0
+bool1475 issnan -0E-1007 -> 0
+bool1476 issnan 0E-1006 -> 0
+bool1477 issnan -0E-1006 -> 0
+bool1478 issnan 0E-1000 -> 0
+bool1479 issnan -0E-1000 -> 0
+bool1480 issnan 0E-999 -> 0
+bool1481 issnan -0E-999 -> 0
+bool1482 issnan 0E-998 -> 0
+bool1483 issnan -0E-998 -> 0
+bool1484 issnan 0E-100 -> 0
+bool1485 issnan -0E-100 -> 0
+bool1486 issnan 0.000000 -> 0
+bool1487 issnan -0.000000 -> 0
+bool1488 issnan 0.000 -> 0
+bool1489 issnan -0.000 -> 0
+bool1490 issnan 0.00 -> 0
+bool1491 issnan -0.00 -> 0
+bool1492 issnan 0.0 -> 0
+bool1493 issnan -0.0 -> 0
+bool1494 issnan 0 -> 0
+bool1495 issnan -0 -> 0
+bool1496 issnan 0E+1 -> 0
+bool1497 issnan -0E+1 -> 0
+bool1498 issnan 0E+2 -> 0
+bool1499 issnan -0E+2 -> 0
+bool1500 issnan 0E+3 -> 0
+bool1501 issnan -0E+3 -> 0
+bool1502 issnan 0E+6 -> 0
+bool1503 issnan -0E+6 -> 0
+bool1504 issnan 0E+100 -> 0
+bool1505 issnan -0E+100 -> 0
+bool1506 issnan 0E+990 -> 0
+bool1507 issnan -0E+990 -> 0
+bool1508 issnan 0E+991 -> 0
+bool1509 issnan -0E+991 -> 0
+bool1510 issnan 0E+992 -> 0
+bool1511 issnan -0E+992 -> 0
+bool1512 issnan 0E+998 -> 0
+bool1513 issnan -0E+998 -> 0
+bool1514 issnan 0E+999 -> 0
+bool1515 issnan -0E+999 -> 0
+bool1516 issnan 0E+1000 -> 0
+bool1517 issnan -0E+1000 -> 0
+bool1518 issnan 0E+2000 -> 0
+bool1519 issnan -0E+2000 -> 0
+bool1520 issnan 1E-2000 -> 0
+bool1521 issnan -1E-2000 -> 0
+bool1522 issnan 1E-1008 -> 0
+bool1523 issnan -1E-1008 -> 0
+bool1524 issnan 1E-1007 -> 0
+bool1525 issnan -1E-1007 -> 0
+bool1526 issnan 1E-1006 -> 0
+bool1527 issnan -1E-1006 -> 0
+bool1528 issnan 1E-1000 -> 0
+bool1529 issnan -1E-1000 -> 0
+bool1530 issnan 1E-999 -> 0
+bool1531 issnan -1E-999 -> 0
+bool1532 issnan 1E-998 -> 0
+bool1533 issnan -1E-998 -> 0
+bool1534 issnan 1E-100 -> 0
+bool1535 issnan -1E-100 -> 0
+bool1536 issnan 0.000001 -> 0
+bool1537 issnan -0.000001 -> 0
+bool1538 issnan 0.001 -> 0
+bool1539 issnan -0.001 -> 0
+bool1540 issnan 0.01 -> 0
+bool1541 issnan -0.01 -> 0
+bool1542 issnan 0.1 -> 0
+bool1543 issnan -0.1 -> 0
+bool1544 issnan 1 -> 0
+bool1545 issnan -1 -> 0
+bool1546 issnan 1E+1 -> 0
+bool1547 issnan -1E+1 -> 0
+bool1548 issnan 1E+2 -> 0
+bool1549 issnan -1E+2 -> 0
+bool1550 issnan 1E+3 -> 0
+bool1551 issnan -1E+3 -> 0
+bool1552 issnan 1E+6 -> 0
+bool1553 issnan -1E+6 -> 0
+bool1554 issnan 1E+100 -> 0
+bool1555 issnan -1E+100 -> 0
+bool1556 issnan 1E+990 -> 0
+bool1557 issnan -1E+990 -> 0
+bool1558 issnan 1E+991 -> 0
+bool1559 issnan -1E+991 -> 0
+bool1560 issnan 1E+992 -> 0
+bool1561 issnan -1E+992 -> 0
+bool1562 issnan 1E+998 -> 0
+bool1563 issnan -1E+998 -> 0
+bool1564 issnan 1E+999 -> 0
+bool1565 issnan -1E+999 -> 0
+bool1566 issnan 1E+1000 -> 0
+bool1567 issnan -1E+1000 -> 0
+bool1568 issnan 1E+2000 -> 0
+bool1569 issnan -1E+2000 -> 0
+bool1570 issnan 9E-2000 -> 0
+bool1571 issnan -9E-2000 -> 0
+bool1572 issnan 9E-1008 -> 0
+bool1573 issnan -9E-1008 -> 0
+bool1574 issnan 9E-1007 -> 0
+bool1575 issnan -9E-1007 -> 0
+bool1576 issnan 9E-1006 -> 0
+bool1577 issnan -9E-1006 -> 0
+bool1578 issnan 9E-1000 -> 0
+bool1579 issnan -9E-1000 -> 0
+bool1580 issnan 9E-999 -> 0
+bool1581 issnan -9E-999 -> 0
+bool1582 issnan 9E-998 -> 0
+bool1583 issnan -9E-998 -> 0
+bool1584 issnan 9E-100 -> 0
+bool1585 issnan -9E-100 -> 0
+bool1586 issnan 0.000009 -> 0
+bool1587 issnan -0.000009 -> 0
+bool1588 issnan 0.009 -> 0
+bool1589 issnan -0.009 -> 0
+bool1590 issnan 0.09 -> 0
+bool1591 issnan -0.09 -> 0
+bool1592 issnan 0.9 -> 0
+bool1593 issnan -0.9 -> 0
+bool1594 issnan 9 -> 0
+bool1595 issnan -9 -> 0
+bool1596 issnan 9E+1 -> 0
+bool1597 issnan -9E+1 -> 0
+bool1598 issnan 9E+2 -> 0
+bool1599 issnan -9E+2 -> 0
+bool1600 issnan 9E+3 -> 0
+bool1601 issnan -9E+3 -> 0
+bool1602 issnan 9E+6 -> 0
+bool1603 issnan -9E+6 -> 0
+bool1604 issnan 9E+100 -> 0
+bool1605 issnan -9E+100 -> 0
+bool1606 issnan 9E+990 -> 0
+bool1607 issnan -9E+990 -> 0
+bool1608 issnan 9E+991 -> 0
+bool1609 issnan -9E+991 -> 0
+bool1610 issnan 9E+992 -> 0
+bool1611 issnan -9E+992 -> 0
+bool1612 issnan 9E+998 -> 0
+bool1613 issnan -9E+998 -> 0
+bool1614 issnan 9E+999 -> 0
+bool1615 issnan -9E+999 -> 0
+bool1616 issnan 9E+1000 -> 0
+bool1617 issnan -9E+1000 -> 0
+bool1618 issnan 9E+2000 -> 0
+bool1619 issnan -9E+2000 -> 0
+bool1620 issnan 9.99999999E-2000 -> 0
+bool1621 issnan -9.99999999E-2000 -> 0
+bool1622 issnan 9.99999999E-1008 -> 0
+bool1623 issnan -9.99999999E-1008 -> 0
+bool1624 issnan 9.99999999E-1007 -> 0
+bool1625 issnan -9.99999999E-1007 -> 0
+bool1626 issnan 9.99999999E-1006 -> 0
+bool1627 issnan -9.99999999E-1006 -> 0
+bool1628 issnan 9.99999999E-1000 -> 0
+bool1629 issnan -9.99999999E-1000 -> 0
+bool1630 issnan 9.99999999E-999 -> 0
+bool1631 issnan -9.99999999E-999 -> 0
+bool1632 issnan 9.99999999E-998 -> 0
+bool1633 issnan -9.99999999E-998 -> 0
+bool1634 issnan 9.99999999E-100 -> 0
+bool1635 issnan -9.99999999E-100 -> 0
+bool1636 issnan 0.00000999999999 -> 0
+bool1637 issnan -0.00000999999999 -> 0
+bool1638 issnan 0.00999999999 -> 0
+bool1639 issnan -0.00999999999 -> 0
+bool1640 issnan 0.0999999999 -> 0
+bool1641 issnan -0.0999999999 -> 0
+bool1642 issnan 0.999999999 -> 0
+bool1643 issnan -0.999999999 -> 0
+bool1644 issnan 9.99999999 -> 0
+bool1645 issnan -9.99999999 -> 0
+bool1646 issnan 99.9999999 -> 0
+bool1647 issnan -99.9999999 -> 0
+bool1648 issnan 999.999999 -> 0
+bool1649 issnan -999.999999 -> 0
+bool1650 issnan 9999.99999 -> 0
+bool1651 issnan -9999.99999 -> 0
+bool1652 issnan 9999999.99 -> 0
+bool1653 issnan -9999999.99 -> 0
+bool1654 issnan 9.99999999E+100 -> 0
+bool1655 issnan -9.99999999E+100 -> 0
+bool1656 issnan 9.99999999E+990 -> 0
+bool1657 issnan -9.99999999E+990 -> 0
+bool1658 issnan 9.99999999E+991 -> 0
+bool1659 issnan -9.99999999E+991 -> 0
+bool1660 issnan 9.99999999E+992 -> 0
+bool1661 issnan -9.99999999E+992 -> 0
+bool1662 issnan 9.99999999E+998 -> 0
+bool1663 issnan -9.99999999E+998 -> 0
+bool1664 issnan 9.99999999E+999 -> 0
+bool1665 issnan -9.99999999E+999 -> 0
+bool1666 issnan 9.99999999E+1000 -> 0
+bool1667 issnan -9.99999999E+1000 -> 0
+bool1668 issnan 9.99999999E+2000 -> 0
+bool1669 issnan -9.99999999E+2000 -> 0
+bool1670 issnan Infinity -> 0
+bool1671 issnan -Infinity -> 0
+bool1672 issnan NaN -> 0
+bool1673 issnan -NaN -> 0
+bool1674 issnan NaN123 -> 0
+bool1675 issnan -NaN123 -> 0
+bool1676 issnan sNaN -> 1
+bool1677 issnan -sNaN -> 1
+bool1678 issnan sNaN123 -> 1
+bool1679 issnan -sNaN123 -> 1
+bool1680 issubnormal 0E-2000 -> 0
+bool1681 issubnormal -0E-2000 -> 0
+bool1682 issubnormal 0E-1008 -> 0
+bool1683 issubnormal -0E-1008 -> 0
+bool1684 issubnormal 0E-1007 -> 0
+bool1685 issubnormal -0E-1007 -> 0
+bool1686 issubnormal 0E-1006 -> 0
+bool1687 issubnormal -0E-1006 -> 0
+bool1688 issubnormal 0E-1000 -> 0
+bool1689 issubnormal -0E-1000 -> 0
+bool1690 issubnormal 0E-999 -> 0
+bool1691 issubnormal -0E-999 -> 0
+bool1692 issubnormal 0E-998 -> 0
+bool1693 issubnormal -0E-998 -> 0
+bool1694 issubnormal 0E-100 -> 0
+bool1695 issubnormal -0E-100 -> 0
+bool1696 issubnormal 0.000000 -> 0
+bool1697 issubnormal -0.000000 -> 0
+bool1698 issubnormal 0.000 -> 0
+bool1699 issubnormal -0.000 -> 0
+bool1700 issubnormal 0.00 -> 0
+bool1701 issubnormal -0.00 -> 0
+bool1702 issubnormal 0.0 -> 0
+bool1703 issubnormal -0.0 -> 0
+bool1704 issubnormal 0 -> 0
+bool1705 issubnormal -0 -> 0
+bool1706 issubnormal 0E+1 -> 0
+bool1707 issubnormal -0E+1 -> 0
+bool1708 issubnormal 0E+2 -> 0
+bool1709 issubnormal -0E+2 -> 0
+bool1710 issubnormal 0E+3 -> 0
+bool1711 issubnormal -0E+3 -> 0
+bool1712 issubnormal 0E+6 -> 0
+bool1713 issubnormal -0E+6 -> 0
+bool1714 issubnormal 0E+100 -> 0
+bool1715 issubnormal -0E+100 -> 0
+bool1716 issubnormal 0E+990 -> 0
+bool1717 issubnormal -0E+990 -> 0
+bool1718 issubnormal 0E+991 -> 0
+bool1719 issubnormal -0E+991 -> 0
+bool1720 issubnormal 0E+992 -> 0
+bool1721 issubnormal -0E+992 -> 0
+bool1722 issubnormal 0E+998 -> 0
+bool1723 issubnormal -0E+998 -> 0
+bool1724 issubnormal 0E+999 -> 0
+bool1725 issubnormal -0E+999 -> 0
+bool1726 issubnormal 0E+1000 -> 0
+bool1727 issubnormal -0E+1000 -> 0
+bool1728 issubnormal 0E+2000 -> 0
+bool1729 issubnormal -0E+2000 -> 0
+bool1730 issubnormal 1E-2000 -> 1
+bool1731 issubnormal -1E-2000 -> 1
+bool1732 issubnormal 1E-1008 -> 1
+bool1733 issubnormal -1E-1008 -> 1
+bool1734 issubnormal 1E-1007 -> 1
+bool1735 issubnormal -1E-1007 -> 1
+bool1736 issubnormal 1E-1006 -> 1
+bool1737 issubnormal -1E-1006 -> 1
+bool1738 issubnormal 1E-1000 -> 1
+bool1739 issubnormal -1E-1000 -> 1
+bool1740 issubnormal 1E-999 -> 0
+bool1741 issubnormal -1E-999 -> 0
+bool1742 issubnormal 1E-998 -> 0
+bool1743 issubnormal -1E-998 -> 0
+bool1744 issubnormal 1E-100 -> 0
+bool1745 issubnormal -1E-100 -> 0
+bool1746 issubnormal 0.000001 -> 0
+bool1747 issubnormal -0.000001 -> 0
+bool1748 issubnormal 0.001 -> 0
+bool1749 issubnormal -0.001 -> 0
+bool1750 issubnormal 0.01 -> 0
+bool1751 issubnormal -0.01 -> 0
+bool1752 issubnormal 0.1 -> 0
+bool1753 issubnormal -0.1 -> 0
+bool1754 issubnormal 1 -> 0
+bool1755 issubnormal -1 -> 0
+bool1756 issubnormal 1E+1 -> 0
+bool1757 issubnormal -1E+1 -> 0
+bool1758 issubnormal 1E+2 -> 0
+bool1759 issubnormal -1E+2 -> 0
+bool1760 issubnormal 1E+3 -> 0
+bool1761 issubnormal -1E+3 -> 0
+bool1762 issubnormal 1E+6 -> 0
+bool1763 issubnormal -1E+6 -> 0
+bool1764 issubnormal 1E+100 -> 0
+bool1765 issubnormal -1E+100 -> 0
+bool1766 issubnormal 1E+990 -> 0
+bool1767 issubnormal -1E+990 -> 0
+bool1768 issubnormal 1E+991 -> 0
+bool1769 issubnormal -1E+991 -> 0
+bool1770 issubnormal 1E+992 -> 0
+bool1771 issubnormal -1E+992 -> 0
+bool1772 issubnormal 1E+998 -> 0
+bool1773 issubnormal -1E+998 -> 0
+bool1774 issubnormal 1E+999 -> 0
+bool1775 issubnormal -1E+999 -> 0
+bool1776 issubnormal 1E+1000 -> 0
+bool1777 issubnormal -1E+1000 -> 0
+bool1778 issubnormal 1E+2000 -> 0
+bool1779 issubnormal -1E+2000 -> 0
+bool1780 issubnormal 9E-2000 -> 1
+bool1781 issubnormal -9E-2000 -> 1
+bool1782 issubnormal 9E-1008 -> 1
+bool1783 issubnormal -9E-1008 -> 1
+bool1784 issubnormal 9E-1007 -> 1
+bool1785 issubnormal -9E-1007 -> 1
+bool1786 issubnormal 9E-1006 -> 1
+bool1787 issubnormal -9E-1006 -> 1
+bool1788 issubnormal 9E-1000 -> 1
+bool1789 issubnormal -9E-1000 -> 1
+bool1790 issubnormal 9E-999 -> 0
+bool1791 issubnormal -9E-999 -> 0
+bool1792 issubnormal 9E-998 -> 0
+bool1793 issubnormal -9E-998 -> 0
+bool1794 issubnormal 9E-100 -> 0
+bool1795 issubnormal -9E-100 -> 0
+bool1796 issubnormal 0.000009 -> 0
+bool1797 issubnormal -0.000009 -> 0
+bool1798 issubnormal 0.009 -> 0
+bool1799 issubnormal -0.009 -> 0
+bool1800 issubnormal 0.09 -> 0
+bool1801 issubnormal -0.09 -> 0
+bool1802 issubnormal 0.9 -> 0
+bool1803 issubnormal -0.9 -> 0
+bool1804 issubnormal 9 -> 0
+bool1805 issubnormal -9 -> 0
+bool1806 issubnormal 9E+1 -> 0
+bool1807 issubnormal -9E+1 -> 0
+bool1808 issubnormal 9E+2 -> 0
+bool1809 issubnormal -9E+2 -> 0
+bool1810 issubnormal 9E+3 -> 0
+bool1811 issubnormal -9E+3 -> 0
+bool1812 issubnormal 9E+6 -> 0
+bool1813 issubnormal -9E+6 -> 0
+bool1814 issubnormal 9E+100 -> 0
+bool1815 issubnormal -9E+100 -> 0
+bool1816 issubnormal 9E+990 -> 0
+bool1817 issubnormal -9E+990 -> 0
+bool1818 issubnormal 9E+991 -> 0
+bool1819 issubnormal -9E+991 -> 0
+bool1820 issubnormal 9E+992 -> 0
+bool1821 issubnormal -9E+992 -> 0
+bool1822 issubnormal 9E+998 -> 0
+bool1823 issubnormal -9E+998 -> 0
+bool1824 issubnormal 9E+999 -> 0
+bool1825 issubnormal -9E+999 -> 0
+bool1826 issubnormal 9E+1000 -> 0
+bool1827 issubnormal -9E+1000 -> 0
+bool1828 issubnormal 9E+2000 -> 0
+bool1829 issubnormal -9E+2000 -> 0
+bool1830 issubnormal 9.99999999E-2000 -> 1
+bool1831 issubnormal -9.99999999E-2000 -> 1
+bool1832 issubnormal 9.99999999E-1008 -> 1
+bool1833 issubnormal -9.99999999E-1008 -> 1
+bool1834 issubnormal 9.99999999E-1007 -> 1
+bool1835 issubnormal -9.99999999E-1007 -> 1
+bool1836 issubnormal 9.99999999E-1006 -> 1
+bool1837 issubnormal -9.99999999E-1006 -> 1
+bool1838 issubnormal 9.99999999E-1000 -> 1
+bool1839 issubnormal -9.99999999E-1000 -> 1
+bool1840 issubnormal 9.99999999E-999 -> 0
+bool1841 issubnormal -9.99999999E-999 -> 0
+bool1842 issubnormal 9.99999999E-998 -> 0
+bool1843 issubnormal -9.99999999E-998 -> 0
+bool1844 issubnormal 9.99999999E-100 -> 0
+bool1845 issubnormal -9.99999999E-100 -> 0
+bool1846 issubnormal 0.00000999999999 -> 0
+bool1847 issubnormal -0.00000999999999 -> 0
+bool1848 issubnormal 0.00999999999 -> 0
+bool1849 issubnormal -0.00999999999 -> 0
+bool1850 issubnormal 0.0999999999 -> 0
+bool1851 issubnormal -0.0999999999 -> 0
+bool1852 issubnormal 0.999999999 -> 0
+bool1853 issubnormal -0.999999999 -> 0
+bool1854 issubnormal 9.99999999 -> 0
+bool1855 issubnormal -9.99999999 -> 0
+bool1856 issubnormal 99.9999999 -> 0
+bool1857 issubnormal -99.9999999 -> 0
+bool1858 issubnormal 999.999999 -> 0
+bool1859 issubnormal -999.999999 -> 0
+bool1860 issubnormal 9999.99999 -> 0
+bool1861 issubnormal -9999.99999 -> 0
+bool1862 issubnormal 9999999.99 -> 0
+bool1863 issubnormal -9999999.99 -> 0
+bool1864 issubnormal 9.99999999E+100 -> 0
+bool1865 issubnormal -9.99999999E+100 -> 0
+bool1866 issubnormal 9.99999999E+990 -> 0
+bool1867 issubnormal -9.99999999E+990 -> 0
+bool1868 issubnormal 9.99999999E+991 -> 0
+bool1869 issubnormal -9.99999999E+991 -> 0
+bool1870 issubnormal 9.99999999E+992 -> 0
+bool1871 issubnormal -9.99999999E+992 -> 0
+bool1872 issubnormal 9.99999999E+998 -> 0
+bool1873 issubnormal -9.99999999E+998 -> 0
+bool1874 issubnormal 9.99999999E+999 -> 0
+bool1875 issubnormal -9.99999999E+999 -> 0
+bool1876 issubnormal 9.99999999E+1000 -> 0
+bool1877 issubnormal -9.99999999E+1000 -> 0
+bool1878 issubnormal 9.99999999E+2000 -> 0
+bool1879 issubnormal -9.99999999E+2000 -> 0
+bool1880 issubnormal Infinity -> 0
+bool1881 issubnormal -Infinity -> 0
+bool1882 issubnormal NaN -> 0
+bool1883 issubnormal -NaN -> 0
+bool1884 issubnormal NaN123 -> 0
+bool1885 issubnormal -NaN123 -> 0
+bool1886 issubnormal sNaN -> 0
+bool1887 issubnormal -sNaN -> 0
+bool1888 issubnormal sNaN123 -> 0
+bool1889 issubnormal -sNaN123 -> 0
+bool1890 iszero 0E-2000 -> 1
+bool1891 iszero -0E-2000 -> 1
+bool1892 iszero 0E-1008 -> 1
+bool1893 iszero -0E-1008 -> 1
+bool1894 iszero 0E-1007 -> 1
+bool1895 iszero -0E-1007 -> 1
+bool1896 iszero 0E-1006 -> 1
+bool1897 iszero -0E-1006 -> 1
+bool1898 iszero 0E-1000 -> 1
+bool1899 iszero -0E-1000 -> 1
+bool1900 iszero 0E-999 -> 1
+bool1901 iszero -0E-999 -> 1
+bool1902 iszero 0E-998 -> 1
+bool1903 iszero -0E-998 -> 1
+bool1904 iszero 0E-100 -> 1
+bool1905 iszero -0E-100 -> 1
+bool1906 iszero 0.000000 -> 1
+bool1907 iszero -0.000000 -> 1
+bool1908 iszero 0.000 -> 1
+bool1909 iszero -0.000 -> 1
+bool1910 iszero 0.00 -> 1
+bool1911 iszero -0.00 -> 1
+bool1912 iszero 0.0 -> 1
+bool1913 iszero -0.0 -> 1
+bool1914 iszero 0 -> 1
+bool1915 iszero -0 -> 1
+bool1916 iszero 0E+1 -> 1
+bool1917 iszero -0E+1 -> 1
+bool1918 iszero 0E+2 -> 1
+bool1919 iszero -0E+2 -> 1
+bool1920 iszero 0E+3 -> 1
+bool1921 iszero -0E+3 -> 1
+bool1922 iszero 0E+6 -> 1
+bool1923 iszero -0E+6 -> 1
+bool1924 iszero 0E+100 -> 1
+bool1925 iszero -0E+100 -> 1
+bool1926 iszero 0E+990 -> 1
+bool1927 iszero -0E+990 -> 1
+bool1928 iszero 0E+991 -> 1
+bool1929 iszero -0E+991 -> 1
+bool1930 iszero 0E+992 -> 1
+bool1931 iszero -0E+992 -> 1
+bool1932 iszero 0E+998 -> 1
+bool1933 iszero -0E+998 -> 1
+bool1934 iszero 0E+999 -> 1
+bool1935 iszero -0E+999 -> 1
+bool1936 iszero 0E+1000 -> 1
+bool1937 iszero -0E+1000 -> 1
+bool1938 iszero 0E+2000 -> 1
+bool1939 iszero -0E+2000 -> 1
+bool1940 iszero 1E-2000 -> 0
+bool1941 iszero -1E-2000 -> 0
+bool1942 iszero 1E-1008 -> 0
+bool1943 iszero -1E-1008 -> 0
+bool1944 iszero 1E-1007 -> 0
+bool1945 iszero -1E-1007 -> 0
+bool1946 iszero 1E-1006 -> 0
+bool1947 iszero -1E-1006 -> 0
+bool1948 iszero 1E-1000 -> 0
+bool1949 iszero -1E-1000 -> 0
+bool1950 iszero 1E-999 -> 0
+bool1951 iszero -1E-999 -> 0
+bool1952 iszero 1E-998 -> 0
+bool1953 iszero -1E-998 -> 0
+bool1954 iszero 1E-100 -> 0
+bool1955 iszero -1E-100 -> 0
+bool1956 iszero 0.000001 -> 0
+bool1957 iszero -0.000001 -> 0
+bool1958 iszero 0.001 -> 0
+bool1959 iszero -0.001 -> 0
+bool1960 iszero 0.01 -> 0
+bool1961 iszero -0.01 -> 0
+bool1962 iszero 0.1 -> 0
+bool1963 iszero -0.1 -> 0
+bool1964 iszero 1 -> 0
+bool1965 iszero -1 -> 0
+bool1966 iszero 1E+1 -> 0
+bool1967 iszero -1E+1 -> 0
+bool1968 iszero 1E+2 -> 0
+bool1969 iszero -1E+2 -> 0
+bool1970 iszero 1E+3 -> 0
+bool1971 iszero -1E+3 -> 0
+bool1972 iszero 1E+6 -> 0
+bool1973 iszero -1E+6 -> 0
+bool1974 iszero 1E+100 -> 0
+bool1975 iszero -1E+100 -> 0
+bool1976 iszero 1E+990 -> 0
+bool1977 iszero -1E+990 -> 0
+bool1978 iszero 1E+991 -> 0
+bool1979 iszero -1E+991 -> 0
+bool1980 iszero 1E+992 -> 0
+bool1981 iszero -1E+992 -> 0
+bool1982 iszero 1E+998 -> 0
+bool1983 iszero -1E+998 -> 0
+bool1984 iszero 1E+999 -> 0
+bool1985 iszero -1E+999 -> 0
+bool1986 iszero 1E+1000 -> 0
+bool1987 iszero -1E+1000 -> 0
+bool1988 iszero 1E+2000 -> 0
+bool1989 iszero -1E+2000 -> 0
+bool1990 iszero 9E-2000 -> 0
+bool1991 iszero -9E-2000 -> 0
+bool1992 iszero 9E-1008 -> 0
+bool1993 iszero -9E-1008 -> 0
+bool1994 iszero 9E-1007 -> 0
+bool1995 iszero -9E-1007 -> 0
+bool1996 iszero 9E-1006 -> 0
+bool1997 iszero -9E-1006 -> 0
+bool1998 iszero 9E-1000 -> 0
+bool1999 iszero -9E-1000 -> 0
+bool2000 iszero 9E-999 -> 0
+bool2001 iszero -9E-999 -> 0
+bool2002 iszero 9E-998 -> 0
+bool2003 iszero -9E-998 -> 0
+bool2004 iszero 9E-100 -> 0
+bool2005 iszero -9E-100 -> 0
+bool2006 iszero 0.000009 -> 0
+bool2007 iszero -0.000009 -> 0
+bool2008 iszero 0.009 -> 0
+bool2009 iszero -0.009 -> 0
+bool2010 iszero 0.09 -> 0
+bool2011 iszero -0.09 -> 0
+bool2012 iszero 0.9 -> 0
+bool2013 iszero -0.9 -> 0
+bool2014 iszero 9 -> 0
+bool2015 iszero -9 -> 0
+bool2016 iszero 9E+1 -> 0
+bool2017 iszero -9E+1 -> 0
+bool2018 iszero 9E+2 -> 0
+bool2019 iszero -9E+2 -> 0
+bool2020 iszero 9E+3 -> 0
+bool2021 iszero -9E+3 -> 0
+bool2022 iszero 9E+6 -> 0
+bool2023 iszero -9E+6 -> 0
+bool2024 iszero 9E+100 -> 0
+bool2025 iszero -9E+100 -> 0
+bool2026 iszero 9E+990 -> 0
+bool2027 iszero -9E+990 -> 0
+bool2028 iszero 9E+991 -> 0
+bool2029 iszero -9E+991 -> 0
+bool2030 iszero 9E+992 -> 0
+bool2031 iszero -9E+992 -> 0
+bool2032 iszero 9E+998 -> 0
+bool2033 iszero -9E+998 -> 0
+bool2034 iszero 9E+999 -> 0
+bool2035 iszero -9E+999 -> 0
+bool2036 iszero 9E+1000 -> 0
+bool2037 iszero -9E+1000 -> 0
+bool2038 iszero 9E+2000 -> 0
+bool2039 iszero -9E+2000 -> 0
+bool2040 iszero 9.99999999E-2000 -> 0
+bool2041 iszero -9.99999999E-2000 -> 0
+bool2042 iszero 9.99999999E-1008 -> 0
+bool2043 iszero -9.99999999E-1008 -> 0
+bool2044 iszero 9.99999999E-1007 -> 0
+bool2045 iszero -9.99999999E-1007 -> 0
+bool2046 iszero 9.99999999E-1006 -> 0
+bool2047 iszero -9.99999999E-1006 -> 0
+bool2048 iszero 9.99999999E-1000 -> 0
+bool2049 iszero -9.99999999E-1000 -> 0
+bool2050 iszero 9.99999999E-999 -> 0
+bool2051 iszero -9.99999999E-999 -> 0
+bool2052 iszero 9.99999999E-998 -> 0
+bool2053 iszero -9.99999999E-998 -> 0
+bool2054 iszero 9.99999999E-100 -> 0
+bool2055 iszero -9.99999999E-100 -> 0
+bool2056 iszero 0.00000999999999 -> 0
+bool2057 iszero -0.00000999999999 -> 0
+bool2058 iszero 0.00999999999 -> 0
+bool2059 iszero -0.00999999999 -> 0
+bool2060 iszero 0.0999999999 -> 0
+bool2061 iszero -0.0999999999 -> 0
+bool2062 iszero 0.999999999 -> 0
+bool2063 iszero -0.999999999 -> 0
+bool2064 iszero 9.99999999 -> 0
+bool2065 iszero -9.99999999 -> 0
+bool2066 iszero 99.9999999 -> 0
+bool2067 iszero -99.9999999 -> 0
+bool2068 iszero 999.999999 -> 0
+bool2069 iszero -999.999999 -> 0
+bool2070 iszero 9999.99999 -> 0
+bool2071 iszero -9999.99999 -> 0
+bool2072 iszero 9999999.99 -> 0
+bool2073 iszero -9999999.99 -> 0
+bool2074 iszero 9.99999999E+100 -> 0
+bool2075 iszero -9.99999999E+100 -> 0
+bool2076 iszero 9.99999999E+990 -> 0
+bool2077 iszero -9.99999999E+990 -> 0
+bool2078 iszero 9.99999999E+991 -> 0
+bool2079 iszero -9.99999999E+991 -> 0
+bool2080 iszero 9.99999999E+992 -> 0
+bool2081 iszero -9.99999999E+992 -> 0
+bool2082 iszero 9.99999999E+998 -> 0
+bool2083 iszero -9.99999999E+998 -> 0
+bool2084 iszero 9.99999999E+999 -> 0
+bool2085 iszero -9.99999999E+999 -> 0
+bool2086 iszero 9.99999999E+1000 -> 0
+bool2087 iszero -9.99999999E+1000 -> 0
+bool2088 iszero 9.99999999E+2000 -> 0
+bool2089 iszero -9.99999999E+2000 -> 0
+bool2090 iszero Infinity -> 0
+bool2091 iszero -Infinity -> 0
+bool2092 iszero NaN -> 0
+bool2093 iszero -NaN -> 0
+bool2094 iszero NaN123 -> 0
+bool2095 iszero -NaN123 -> 0
+bool2096 iszero sNaN -> 0
+bool2097 iszero -sNaN -> 0
+bool2098 iszero sNaN123 -> 0
+bool2099 iszero -sNaN123 -> 0
+
 ------------------------------------------------------------------------
 -- The following tests (pwmx0 through pwmx440) are for the            --
 -- three-argument version of power:                                   --

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/fma.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/fma.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/fma.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/inexact.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/inexact.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/inexact.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/invert.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/invert.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/invert.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/ln.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/ln.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/ln.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   16

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/log10.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/log10.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/log10.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This emphasises the testing of notable cases, as they will often
 -- have unusual paths (especially the 10**n results).

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/logb.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/logb.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/logb.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This emphasises the testing of notable cases, as they will often
 -- have unusual paths (especially the 10**n results).

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/max.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/max.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/max.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- we assume that base comparison is tested in compare.decTest, so
 -- these mainly cover special cases and rounding

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/maxmag.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/maxmag.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/maxmag.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- we assume that base comparison is tested in compare.decTest, so
 -- these mainly cover special cases and rounding

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/min.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/min.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/min.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- we assume that base comparison is tested in compare.decTest, so
 -- these mainly cover special cases and rounding

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/minmag.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/minmag.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/minmag.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- we assume that base comparison is tested in compare.decTest, so
 -- these mainly cover special cases and rounding

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/minus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/minus.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/minus.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests primarily tests the existence of the operator.
 -- Subtraction, rounding, and more overflows are tested elsewhere.

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/multiply.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/multiply.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/multiply.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/nextminus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/nextminus.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/nextminus.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/nextplus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/nextplus.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/nextplus.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/nexttoward.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/nexttoward.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/nexttoward.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/or.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/or.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/or.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/plus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/plus.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/plus.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests primarily tests the existence of the operator.
 -- Addition and rounding, and most overflows, are tested elsewhere.

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/power.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/power.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/power.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- In addition to the power operator testcases here, see also the file
 -- powersqrt.decTest which includes all the tests from

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/powersqrt.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/powersqrt.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/powersqrt.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- These testcases are taken from squareroot.decTest but are
 -- evaluated using the power operator.  The differences in results

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/quantize.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/quantize.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/quantize.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- Most of the tests here assume a "regular pattern", where the
 -- sign and coefficient are +1.

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/randomBound32.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/randomBound32.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/randomBound32.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.55
+version: 2.57
 
 -- These testcases test calculations at precisions 31, 32, and 33, to
 -- exercise the boundaries around 2**5

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/randoms.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/randoms.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/randoms.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 maxexponent: 999999999

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/reduce.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/reduce.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/reduce.decTest	Thu Mar 27 00:48:05 2008
@@ -19,7 +19,7 @@
 ------------------------------------------------------------------------
 -- [This used to be called normalize.]
 
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/remainder.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/remainder.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/remainder.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/remainderNear.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/remainderNear.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/remainderNear.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.55
+version: 2.57
 
 extended:    1
 precision:   9
@@ -413,6 +413,18 @@
 rmnx606 remaindernear  31.5 3  -> 1.5    -- i=10
 rmnx607 remaindernear  34.5 3  -> -1.5   -- i=11
 
+-- zero signs
+rmnx650 remaindernear  1  1 ->  0
+rmnx651 remaindernear -1  1 -> -0
+rmnx652 remaindernear  1 -1 ->  0
+rmnx653 remaindernear -1 -1 -> -0
+rmnx654 remaindernear  0  1 ->  0
+rmnx655 remaindernear -0  1 -> -0
+rmnx656 remaindernear  0 -1 ->  0
+rmnx657 remaindernear -0 -1 -> -0
+rmnx658 remaindernear  0.00  1  ->  0.00
+rmnx659 remaindernear -0.00  1  -> -0.00
+
 -- Specials
 rmnx680 remaindernear  Inf  -Inf   ->  NaN Invalid_operation
 rmnx681 remaindernear  Inf  -1000  ->  NaN Invalid_operation

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/rescale.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/rescale.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/rescale.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- [obsolete]   Quantize.decTest has the improved version
 

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/rotate.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/rotate.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/rotate.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/rounding.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/rounding.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/rounding.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- These tests require that implementations take account of residues in
 -- order to get correct results for some rounding modes.  Rather than

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/samequantum.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/samequantum.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/samequantum.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/scaleb.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/scaleb.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/scaleb.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/shift.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/shift.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/shift.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/squareroot.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/squareroot.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/squareroot.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/subtract.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/subtract.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/subtract.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/testall.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/testall.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/testall.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- core tests (using Extended: 1) --------------------------------------
 dectest: base

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegral.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegral.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegral.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests tests the extended specification 'round-to-integral
 -- value' operation (from IEEE 854, later modified in 754r).

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegralx.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegralx.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegralx.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 -- This set of tests tests the extended specification 'round-to-integral
 -- value' operation (from IEEE 854, later modified in 754r).

Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/xor.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/xor.decTest	(original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/xor.decTest	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 --   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
 --   mfc at uk.ibm.com                                                   --
 ------------------------------------------------------------------------
-version: 2.56
+version: 2.57
 
 extended:    1
 precision:   9

Modified: python/branches/py3k-importlib/Lib/test/exception_hierarchy.txt
==============================================================================
--- python/branches/py3k-importlib/Lib/test/exception_hierarchy.txt	(original)
+++ python/branches/py3k-importlib/Lib/test/exception_hierarchy.txt	Thu Mar 27 00:48:05 2008
@@ -1,8 +1,8 @@
 BaseException
  +-- SystemExit
  +-- KeyboardInterrupt
+ +-- GeneratorExit
  +-- Exception
-      +-- GeneratorExit
       +-- StopIteration
       +-- ArithmeticError
       |    +-- FloatingPointError
@@ -44,5 +44,6 @@
            +-- SyntaxWarning
            +-- UserWarning
            +-- FutureWarning
-	   +-- ImportWarning
-	   +-- UnicodeWarning
+           +-- ImportWarning
+           +-- UnicodeWarning
+           +-- BytesWarning

Modified: python/branches/py3k-importlib/Lib/test/fork_wait.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/fork_wait.py	(original)
+++ python/branches/py3k-importlib/Lib/test/fork_wait.py	Thu Mar 27 00:48:05 2008
@@ -10,7 +10,6 @@
 """
 
 import os, sys, time, thread, unittest
-from test.test_support import TestSkipped
 
 LONGSLEEP = 2
 SHORTSLEEP = 0.5

Modified: python/branches/py3k-importlib/Lib/test/inspect_fodder2.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/inspect_fodder2.py	(original)
+++ python/branches/py3k-importlib/Lib/test/inspect_fodder2.py	Thu Mar 27 00:48:05 2008
@@ -96,4 +96,12 @@
             "doc"
             return 42
     return X
-method_in_dynamic_class = f().g.im_func
+method_in_dynamic_class = f().g
+
+#line 101
+def keyworded(*arg1, arg2=1):
+    pass
+
+#line 105
+def annotated(arg1: list):
+    pass

Modified: python/branches/py3k-importlib/Lib/test/list_tests.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/list_tests.py	(original)
+++ python/branches/py3k-importlib/Lib/test/list_tests.py	Thu Mar 27 00:48:05 2008
@@ -5,9 +5,17 @@
 import sys
 import os
 
-import unittest
 from test import test_support, seq_tests
 
+def CmpToKey(mycmp):
+    'Convert a cmp= function into a key= function'
+    class K(object):
+        def __init__(self, obj):
+            self.obj = obj
+        def __lt__(self, other):
+            return mycmp(self.obj, other.obj) == -1
+    return K
+
 class CommonTest(seq_tests.CommonTest):
 
     def test_init(self):
@@ -388,8 +396,8 @@
         self.assertEqual(a.index(0, -3), 3)
         self.assertEqual(a.index(0, 3, 4), 3)
         self.assertEqual(a.index(0, -3, -2), 3)
-        self.assertEqual(a.index(0, -4*sys.maxint, 4*sys.maxint), 2)
-        self.assertRaises(ValueError, a.index, 0, 4*sys.maxint,-4*sys.maxint)
+        self.assertEqual(a.index(0, -4*sys.maxsize, 4*sys.maxsize), 2)
+        self.assertRaises(ValueError, a.index, 0, 4*sys.maxsize,-4*sys.maxsize)
         self.assertRaises(ValueError, a.index, 2, 0, -10)
         a.remove(0)
         self.assertRaises(ValueError, a.index, 2, 0, 4)
@@ -430,23 +438,21 @@
 
         def revcmp(a, b):
             return cmp(b, a)
-        u.sort(revcmp)
+        u.sort(key=CmpToKey(revcmp))
         self.assertEqual(u, self.type2test([2,1,0,-1,-2]))
 
         # The following dumps core in unpatched Python 1.5:
         def myComparison(x,y):
             return cmp(x%3, y%7)
         z = self.type2test(range(12))
-        z.sort(myComparison)
+        z.sort(key=CmpToKey(myComparison))
 
         self.assertRaises(TypeError, z.sort, 2)
 
         def selfmodifyingComparison(x,y):
             z.append(1)
             return cmp(x, y)
-        self.assertRaises(ValueError, z.sort, selfmodifyingComparison)
-
-        self.assertRaises(TypeError, z.sort, lambda x, y: 's')
+        self.assertRaises(ValueError, z.sort, key=CmpToKey(selfmodifyingComparison))
 
         self.assertRaises(TypeError, z.sort, 42, 42, 42, 42)
 
@@ -521,7 +527,5 @@
         # Bug #1242657
         class F(object):
             def __iter__(self):
-                yield 23
-            def __len__(self):
                 raise KeyboardInterrupt
         self.assertRaises(KeyboardInterrupt, list, F())

Modified: python/branches/py3k-importlib/Lib/test/mapping_tests.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/mapping_tests.py	(original)
+++ python/branches/py3k-importlib/Lib/test/mapping_tests.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,6 @@
 # tests common to dict and UserDict
 import unittest
-import UserDict
+import collections
 
 
 class BasicTestMappingProtocol(unittest.TestCase):
@@ -438,11 +438,11 @@
         # self.assert_(type(dictlike.fromkeys('a')) is dictlike)
         class mydict(self.type2test):
             def __new__(cls):
-                return UserDict.UserDict()
+                return collections.UserDict()
         ud = mydict.fromkeys('ab')
         self.assertEqual(ud, {'a':None, 'b':None})
         # FIXME: the following won't work with UserDict, because it's an old style class
-        # self.assert_(isinstance(ud, UserDict.UserDict))
+        # self.assert_(isinstance(ud, collections.UserDict))
         self.assertRaises(TypeError, dict.fromkeys)
 
         class Exc(Exception): pass
@@ -574,10 +574,10 @@
         TestMappingProtocol.test_fromkeys(self)
         class mydict(self.type2test):
             def __new__(cls):
-                return UserDict.UserDict()
+                return collections.UserDict()
         ud = mydict.fromkeys('ab')
         self.assertEqual(ud, {'a':None, 'b':None})
-        self.assert_(isinstance(ud, UserDict.UserDict))
+        self.assert_(isinstance(ud, collections.UserDict))
 
     def test_pop(self):
         TestMappingProtocol.test_pop(self)

Modified: python/branches/py3k-importlib/Lib/test/outstanding_bugs.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/outstanding_bugs.py	(original)
+++ python/branches/py3k-importlib/Lib/test/outstanding_bugs.py	Thu Mar 27 00:48:05 2008
@@ -45,9 +45,77 @@
             self.assertEquals(aptr, 1)
             self.assertEquals(bptr, 0)
 
+# test_io
+import io
+class TextIOWrapperTest(unittest.TestCase):
+
+    def setUp(self):
+        self.testdata = b"AAA\r\nBBB\rCCC\r\nDDD\nEEE\r\n"
+        self.normalized = b"AAA\nBBB\nCCC\nDDD\nEEE\n".decode("ASCII")
+
+    def tearDown(self):
+        test_support.unlink(test_support.TESTFN)
+
+
+    def test_issue1395_1(self):
+        txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII")
+
+        # read one char at a time
+        reads = ""
+        while True:
+            c = txt.read(1)
+            if not c:
+                break
+            reads += c
+        self.assertEquals(reads, self.normalized)
+
+    def test_issue1395_2(self):
+        txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII")
+        txt._CHUNK_SIZE = 4
+
+        reads = ""
+        while True:
+            c = txt.read(4)
+            if not c:
+                break
+            reads += c
+        self.assertEquals(reads, self.normalized)
+
+    def test_issue1395_3(self):
+        txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII")
+        txt._CHUNK_SIZE = 4
+
+        reads = txt.read(4)
+        reads += txt.read(4)
+        reads += txt.readline()
+        reads += txt.readline()
+        reads += txt.readline()
+        self.assertEquals(reads, self.normalized)
+
+    def test_issue1395_4(self):
+        txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII")
+        txt._CHUNK_SIZE = 4
+
+        reads = txt.read(4)
+        reads += txt.read()
+        self.assertEquals(reads, self.normalized)
+
+    def test_issue1395_5(self):
+        txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ASCII")
+        txt._CHUNK_SIZE = 4
+
+        reads = txt.read(4)
+        pos = txt.tell()
+        txt.seek(0)
+        txt.seek(pos)
+        self.assertEquals(txt.read(4), "BBB\n")
+
+
 
 def test_main():
-    test_support.run_unittest(TestDifflibLongestMatch)
+    test_support.run_unittest(
+        TestDifflibLongestMatch,
+        TextIOWrapperTest)
 
 if __name__ == "__main__":
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/pickletester.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/pickletester.py	(original)
+++ python/branches/py3k-importlib/Lib/test/pickletester.py	Thu Mar 27 00:48:05 2008
@@ -5,6 +5,8 @@
 
 from test.test_support import TestFailed, TESTFN, run_with_locale
 
+from pickle import bytes_types
+
 # Tests that try a number of pickle protocols should have a
 #     for proto in protocols:
 # kind of outer loop.
@@ -87,149 +89,137 @@
 # DATA0 .. DATA2 are the pickles we expect under the various protocols, for
 # the object returned by create_data().
 
-# break into multiple strings to avoid confusing font-lock-mode
-DATA0 = b"""(lp1
-I0
-aL1L
-aF2
-ac__builtin__
-complex
-p2
-""" + \
-b"""(F3
-F0
-tRp3
-aI1
-aI-1
-aI255
-aI-255
-aI-256
-aI65535
-aI-65535
-aI-65536
-aI2147483647
-aI-2147483647
-aI-2147483648
-a""" + \
-b"""(S'abc'
-p4
-g4
-""" + \
-b"""(i__main__
-C
-p5
-""" + \
-b"""(dp6
-S'foo'
-p7
-I1
-sS'bar'
-p8
-I2
-sbg5
-tp9
-ag9
-aI5
-a.
-"""
+DATA0 = (
+    b'(lp0\nL0\naL1\naF2.0\nac'
+    b'builtins\ncomplex\n'
+    b'p1\n(F3.0\nF0.0\ntp2\nRp'
+    b'3\naL1\naL-1\naL255\naL-'
+    b'255\naL-256\naL65535\na'
+    b'L-65535\naL-65536\naL2'
+    b'147483647\naL-2147483'
+    b'647\naL-2147483648\na('
+    b'Vabc\np4\ng4\nccopy_reg'
+    b'\n_reconstructor\np5\n('
+    b'c__main__\nC\np6\ncbu'
+    b'iltins\nobject\np7\nNt'
+    b'p8\nRp9\n(dp10\nVfoo\np1'
+    b'1\nL1\nsVbar\np12\nL2\nsb'
+    b'g9\ntp13\nag13\naL5\na.'
+)
 
-# Disassembly of DATA0.
+# Disassembly of DATA0
 DATA0_DIS = """\
     0: (    MARK
     1: l        LIST       (MARK at 0)
-    2: p    PUT        1
-    5: I    INT        0
+    2: p    PUT        0
+    5: L    LONG       0
     8: a    APPEND
-    9: L    LONG       1L
-   13: a    APPEND
-   14: F    FLOAT      2.0
-   17: a    APPEND
-   18: c    GLOBAL     '__builtin__ complex'
-   39: p    PUT        2
-   42: (    MARK
-   43: F        FLOAT      3.0
-   46: F        FLOAT      0.0
-   49: t        TUPLE      (MARK at 42)
-   50: R    REDUCE
-   51: p    PUT        3
-   54: a    APPEND
-   55: I    INT        1
-   58: a    APPEND
-   59: I    INT        -1
-   63: a    APPEND
-   64: I    INT        255
-   69: a    APPEND
-   70: I    INT        -255
-   76: a    APPEND
-   77: I    INT        -256
-   83: a    APPEND
-   84: I    INT        65535
+    9: L    LONG       1
+   12: a    APPEND
+   13: F    FLOAT      2.0
+   18: a    APPEND
+   19: c    GLOBAL     'builtins complex'
+   40: p    PUT        1
+   43: (    MARK
+   44: F        FLOAT      3.0
+   49: F        FLOAT      0.0
+   54: t        TUPLE      (MARK at 43)
+   55: p    PUT        2
+   58: R    REDUCE
+   59: p    PUT        3
+   62: a    APPEND
+   63: L    LONG       1
+   66: a    APPEND
+   67: L    LONG       -1
+   71: a    APPEND
+   72: L    LONG       255
+   77: a    APPEND
+   78: L    LONG       -255
+   84: a    APPEND
+   85: L    LONG       -256
    91: a    APPEND
-   92: I    INT        -65535
-  100: a    APPEND
-  101: I    INT        -65536
-  109: a    APPEND
-  110: I    INT        2147483647
-  122: a    APPEND
-  123: I    INT        -2147483647
-  136: a    APPEND
-  137: I    INT        -2147483648
-  150: a    APPEND
-  151: (    MARK
-  152: S        STRING     'abc'
-  159: p        PUT        4
-  162: g        GET        4
-  165: (        MARK
-  166: i            INST       '__main__ C' (MARK at 165)
-  178: p        PUT        5
-  181: (        MARK
-  182: d            DICT       (MARK at 181)
-  183: p        PUT        6
-  186: S        STRING     'foo'
-  193: p        PUT        7
-  196: I        INT        1
-  199: s        SETITEM
-  200: S        STRING     'bar'
-  207: p        PUT        8
-  210: I        INT        2
-  213: s        SETITEM
-  214: b        BUILD
-  215: g        GET        5
-  218: t        TUPLE      (MARK at 151)
-  219: p    PUT        9
-  222: a    APPEND
-  223: g    GET        9
-  226: a    APPEND
-  227: I    INT        5
-  230: a    APPEND
-  231: .    STOP
+   92: L    LONG       65535
+   99: a    APPEND
+  100: L    LONG       -65535
+  108: a    APPEND
+  109: L    LONG       -65536
+  117: a    APPEND
+  118: L    LONG       2147483647
+  130: a    APPEND
+  131: L    LONG       -2147483647
+  144: a    APPEND
+  145: L    LONG       -2147483648
+  158: a    APPEND
+  159: (    MARK
+  160: V        UNICODE    'abc'
+  165: p        PUT        4
+  168: g        GET        4
+  171: c        GLOBAL     'copy_reg _reconstructor'
+  196: p        PUT        5
+  199: (        MARK
+  200: c            GLOBAL     '__main__ C'
+  212: p            PUT        6
+  215: c            GLOBAL     'builtins object'
+  235: p            PUT        7
+  238: N            NONE
+  239: t            TUPLE      (MARK at 199)
+  240: p        PUT        8
+  243: R        REDUCE
+  244: p        PUT        9
+  247: (        MARK
+  248: d            DICT       (MARK at 247)
+  249: p        PUT        10
+  253: V        UNICODE    'foo'
+  258: p        PUT        11
+  262: L        LONG       1
+  265: s        SETITEM
+  266: V        UNICODE    'bar'
+  271: p        PUT        12
+  275: L        LONG       2
+  278: s        SETITEM
+  279: b        BUILD
+  280: g        GET        9
+  283: t        TUPLE      (MARK at 159)
+  284: p    PUT        13
+  288: a    APPEND
+  289: g    GET        13
+  293: a    APPEND
+  294: L    LONG       5
+  297: a    APPEND
+  298: .    STOP
 highest protocol among opcodes = 0
 """
 
-DATA1 = (b']q\x01(K\x00L1L\nG@\x00\x00\x00\x00\x00\x00\x00'
-         b'c__builtin__\ncomplex\nq\x02(G@\x08\x00\x00\x00\x00\x00'
-         b'\x00G\x00\x00\x00\x00\x00\x00\x00\x00tRq\x03K\x01J\xff\xff'
-         b'\xff\xffK\xffJ\x01\xff\xff\xffJ\x00\xff\xff\xffM\xff\xff'
-         b'J\x01\x00\xff\xffJ\x00\x00\xff\xffJ\xff\xff\xff\x7fJ\x01\x00'
-         b'\x00\x80J\x00\x00\x00\x80(U\x03abcq\x04h\x04(c__main__\n'
-         b'C\nq\x05oq\x06}q\x07(U\x03fooq\x08K\x01U\x03barq\tK\x02ubh'
-         b'\x06tq\nh\nK\x05e.'
-        )
+DATA1 = (
+    b']q\x00(K\x00K\x01G@\x00\x00\x00\x00\x00\x00\x00c'
+    b'builtins\ncomplex\nq\x01'
+    b'(G@\x08\x00\x00\x00\x00\x00\x00G\x00\x00\x00\x00\x00\x00\x00\x00t'
+    b'q\x02Rq\x03K\x01J\xff\xff\xff\xffK\xffJ\x01\xff\xff\xffJ'
+    b'\x00\xff\xff\xffM\xff\xffJ\x01\x00\xff\xffJ\x00\x00\xff\xffJ\xff\xff'
+    b'\xff\x7fJ\x01\x00\x00\x80J\x00\x00\x00\x80(X\x03\x00\x00\x00ab'
+    b'cq\x04h\x04ccopy_reg\n_reco'
+    b'nstructor\nq\x05(c__main'
+    b'__\nC\nq\x06cbuiltins\n'
+    b'object\nq\x07Ntq\x08Rq\t}q\n('
+    b'X\x03\x00\x00\x00fooq\x0bK\x01X\x03\x00\x00\x00bar'
+    b'q\x0cK\x02ubh\ttq\rh\rK\x05e.'
+)
 
-# Disassembly of DATA1.
+# Disassembly of DATA1
 DATA1_DIS = """\
     0: ]    EMPTY_LIST
-    1: q    BINPUT     1
+    1: q    BINPUT     0
     3: (    MARK
     4: K        BININT1    0
-    6: L        LONG       1L
-   10: G        BINFLOAT   2.0
-   19: c        GLOBAL     '__builtin__ complex'
-   40: q        BINPUT     2
-   42: (        MARK
-   43: G            BINFLOAT   3.0
-   52: G            BINFLOAT   0.0
-   61: t            TUPLE      (MARK at 42)
+    6: K        BININT1    1
+    8: G        BINFLOAT   2.0
+   17: c        GLOBAL     'builtins complex'
+   38: q        BINPUT     1
+   40: (        MARK
+   41: G            BINFLOAT   3.0
+   50: G            BINFLOAT   0.0
+   59: t            TUPLE      (MARK at 40)
+   60: q        BINPUT     2
    62: R        REDUCE
    63: q        BINPUT     3
    65: K        BININT1    1
@@ -244,97 +234,110 @@
   102: J        BININT     -2147483647
   107: J        BININT     -2147483648
   112: (        MARK
-  113: U            SHORT_BINSTRING 'abc'
-  118: q            BINPUT     4
-  120: h            BINGET     4
-  122: (            MARK
-  123: c                GLOBAL     '__main__ C'
-  135: q                BINPUT     5
-  137: o                OBJ        (MARK at 122)
-  138: q            BINPUT     6
-  140: }            EMPTY_DICT
-  141: q            BINPUT     7
-  143: (            MARK
-  144: U                SHORT_BINSTRING 'foo'
-  149: q                BINPUT     8
-  151: K                BININT1    1
-  153: U                SHORT_BINSTRING 'bar'
-  158: q                BINPUT     9
-  160: K                BININT1    2
-  162: u                SETITEMS   (MARK at 143)
-  163: b            BUILD
-  164: h            BINGET     6
-  166: t            TUPLE      (MARK at 112)
-  167: q        BINPUT     10
-  169: h        BINGET     10
-  171: K        BININT1    5
-  173: e        APPENDS    (MARK at 3)
-  174: .    STOP
+  113: X            BINUNICODE 'abc'
+  121: q            BINPUT     4
+  123: h            BINGET     4
+  125: c            GLOBAL     'copy_reg _reconstructor'
+  150: q            BINPUT     5
+  152: (            MARK
+  153: c                GLOBAL     '__main__ C'
+  165: q                BINPUT     6
+  167: c                GLOBAL     'builtins object'
+  187: q                BINPUT     7
+  189: N                NONE
+  190: t                TUPLE      (MARK at 152)
+  191: q            BINPUT     8
+  193: R            REDUCE
+  194: q            BINPUT     9
+  196: }            EMPTY_DICT
+  197: q            BINPUT     10
+  199: (            MARK
+  200: X                BINUNICODE 'foo'
+  208: q                BINPUT     11
+  210: K                BININT1    1
+  212: X                BINUNICODE 'bar'
+  220: q                BINPUT     12
+  222: K                BININT1    2
+  224: u                SETITEMS   (MARK at 199)
+  225: b            BUILD
+  226: h            BINGET     9
+  228: t            TUPLE      (MARK at 112)
+  229: q        BINPUT     13
+  231: h        BINGET     13
+  233: K        BININT1    5
+  235: e        APPENDS    (MARK at 3)
+  236: .    STOP
 highest protocol among opcodes = 1
 """
 
-DATA2 = (b'\x80\x02]q\x01(K\x00\x8a\x01\x01G@\x00\x00\x00\x00\x00\x00\x00'
-         b'c__builtin__\ncomplex\nq\x02G@\x08\x00\x00\x00\x00\x00\x00G\x00'
-         b'\x00\x00\x00\x00\x00\x00\x00\x86Rq\x03K\x01J\xff\xff\xff\xffK'
-         b'\xffJ\x01\xff\xff\xffJ\x00\xff\xff\xffM\xff\xffJ\x01\x00\xff\xff'
-         b'J\x00\x00\xff\xffJ\xff\xff\xff\x7fJ\x01\x00\x00\x80J\x00\x00\x00'
-         b'\x80(U\x03abcq\x04h\x04(c__main__\nC\nq\x05oq\x06}q\x07(U\x03foo'
-         b'q\x08K\x01U\x03barq\tK\x02ubh\x06tq\nh\nK\x05e.')
+DATA2 = (
+    b'\x80\x02]q\x00(K\x00K\x01G@\x00\x00\x00\x00\x00\x00\x00c'
+    b'builtins\ncomplex\n'
+    b'q\x01G@\x08\x00\x00\x00\x00\x00\x00G\x00\x00\x00\x00\x00\x00\x00\x00'
+    b'\x86q\x02Rq\x03K\x01J\xff\xff\xff\xffK\xffJ\x01\xff\xff\xff'
+    b'J\x00\xff\xff\xffM\xff\xffJ\x01\x00\xff\xffJ\x00\x00\xff\xffJ\xff'
+    b'\xff\xff\x7fJ\x01\x00\x00\x80J\x00\x00\x00\x80(X\x03\x00\x00\x00a'
+    b'bcq\x04h\x04c__main__\nC\nq\x05'
+    b')\x81q\x06}q\x07(X\x03\x00\x00\x00fooq\x08K\x01'
+    b'X\x03\x00\x00\x00barq\tK\x02ubh\x06tq\nh'
+    b'\nK\x05e.'
+)
 
-# Disassembly of DATA2.
+# Disassembly of DATA2
 DATA2_DIS = """\
     0: \x80 PROTO      2
     2: ]    EMPTY_LIST
-    3: q    BINPUT     1
+    3: q    BINPUT     0
     5: (    MARK
     6: K        BININT1    0
-    8: \x8a     LONG1      1L
-   11: G        BINFLOAT   2.0
-   20: c        GLOBAL     '__builtin__ complex'
-   41: q        BINPUT     2
-   43: G        BINFLOAT   3.0
-   52: G        BINFLOAT   0.0
-   61: \x86     TUPLE2
-   62: R        REDUCE
-   63: q        BINPUT     3
-   65: K        BININT1    1
-   67: J        BININT     -1
-   72: K        BININT1    255
-   74: J        BININT     -255
-   79: J        BININT     -256
-   84: M        BININT2    65535
-   87: J        BININT     -65535
-   92: J        BININT     -65536
-   97: J        BININT     2147483647
-  102: J        BININT     -2147483647
-  107: J        BININT     -2147483648
-  112: (        MARK
-  113: U            SHORT_BINSTRING 'abc'
-  118: q            BINPUT     4
-  120: h            BINGET     4
-  122: (            MARK
-  123: c                GLOBAL     '__main__ C'
-  135: q                BINPUT     5
-  137: o                OBJ        (MARK at 122)
-  138: q            BINPUT     6
-  140: }            EMPTY_DICT
-  141: q            BINPUT     7
-  143: (            MARK
-  144: U                SHORT_BINSTRING 'foo'
-  149: q                BINPUT     8
-  151: K                BININT1    1
-  153: U                SHORT_BINSTRING 'bar'
-  158: q                BINPUT     9
-  160: K                BININT1    2
-  162: u                SETITEMS   (MARK at 143)
-  163: b            BUILD
-  164: h            BINGET     6
-  166: t            TUPLE      (MARK at 112)
-  167: q        BINPUT     10
-  169: h        BINGET     10
-  171: K        BININT1    5
-  173: e        APPENDS    (MARK at 5)
-  174: .    STOP
+    8: K        BININT1    1
+   10: G        BINFLOAT   2.0
+   19: c        GLOBAL     'builtins complex'
+   40: q        BINPUT     1
+   42: G        BINFLOAT   3.0
+   51: G        BINFLOAT   0.0
+   60: \x86     TUPLE2
+   61: q        BINPUT     2
+   63: R        REDUCE
+   64: q        BINPUT     3
+   66: K        BININT1    1
+   68: J        BININT     -1
+   73: K        BININT1    255
+   75: J        BININT     -255
+   80: J        BININT     -256
+   85: M        BININT2    65535
+   88: J        BININT     -65535
+   93: J        BININT     -65536
+   98: J        BININT     2147483647
+  103: J        BININT     -2147483647
+  108: J        BININT     -2147483648
+  113: (        MARK
+  114: X            BINUNICODE 'abc'
+  122: q            BINPUT     4
+  124: h            BINGET     4
+  126: c            GLOBAL     '__main__ C'
+  138: q            BINPUT     5
+  140: )            EMPTY_TUPLE
+  141: \x81         NEWOBJ
+  142: q            BINPUT     6
+  144: }            EMPTY_DICT
+  145: q            BINPUT     7
+  147: (            MARK
+  148: X                BINUNICODE 'foo'
+  156: q                BINPUT     8
+  158: K                BININT1    1
+  160: X                BINUNICODE 'bar'
+  168: q                BINPUT     9
+  170: K                BININT1    2
+  172: u                SETITEMS   (MARK at 147)
+  173: b            BUILD
+  174: h            BINGET     6
+  176: t            TUPLE      (MARK at 113)
+  177: q        BINPUT     10
+  179: h        BINGET     10
+  181: K        BININT1    5
+  183: e        APPENDS    (MARK at 5)
+  184: .    STOP
 highest protocol among opcodes = 2
 """
 
@@ -393,11 +396,14 @@
             got = self.loads(s)
             self.assertEqual(expected, got)
 
-    def test_load_from_canned_string(self):
-        expected = self._testdata
-        for canned in DATA0, DATA1, DATA2:
-            got = self.loads(canned)
-            self.assertEqual(expected, got)
+    def test_load_from_data0(self):
+        self.assertEqual(self._testdata, self.loads(DATA0))
+
+    def test_load_from_data1(self):
+        self.assertEqual(self._testdata, self.loads(DATA1))
+
+    def test_load_from_data2(self):
+        self.assertEqual(self._testdata, self.loads(DATA2))
 
     # There are gratuitous differences between pickles produced by
     # pickle and cPickle, largely because cPickle starts PUT indices at
@@ -484,10 +490,16 @@
                 u2 = self.loads(p)
                 self.assertEqual(u2, u)
 
+    def test_bytes(self):
+        for proto in protocols:
+            for u in b'', b'xyz', b'xyz'*100:
+                p = self.dumps(u)
+                self.assertEqual(self.loads(p), u)
+
     def test_ints(self):
         import sys
         for proto in protocols:
-            n = sys.maxint
+            n = sys.maxsize
             while n:
                 for expected in (-n, n):
                     s = self.dumps(expected, proto)
@@ -526,8 +538,8 @@
 
     @run_with_locale('LC_ALL', 'de_DE', 'fr_FR')
     def test_float_format(self):
-        # make sure that floats are formatted locale independent
-        self.assertEqual(self.dumps(1.2)[0:3], b'F1.')
+        # make sure that floats are formatted locale independent with proto 0
+        self.assertEqual(self.dumps(1.2, 0)[0:3], b'F1.')
 
     def test_reduce(self):
         pass
@@ -618,6 +630,12 @@
                            (2, 2): pickle.TUPLE2,
                            (2, 3): pickle.TUPLE3,
                            (2, 4): pickle.TUPLE,
+
+                           (3, 0): pickle.EMPTY_TUPLE,
+                           (3, 1): pickle.TUPLE1,
+                           (3, 2): pickle.TUPLE2,
+                           (3, 3): pickle.TUPLE3,
+                           (3, 4): pickle.TUPLE,
                           }
         a = ()
         b = (1,)
@@ -637,14 +655,17 @@
         expected_opcode = {(0, None): pickle.NONE,
                            (1, None): pickle.NONE,
                            (2, None): pickle.NONE,
+                           (3, None): pickle.NONE,
 
                            (0, True): pickle.INT,
                            (1, True): pickle.INT,
                            (2, True): pickle.NEWTRUE,
+                           (3, True): pickle.NEWTRUE,
 
                            (0, False): pickle.INT,
                            (1, False): pickle.INT,
                            (2, False): pickle.NEWFALSE,
+                           (3, False): pickle.NEWFALSE,
                           }
         for proto in protocols:
             for x in None, False, True:
@@ -762,7 +783,7 @@
         x = dict.fromkeys(range(n))
         for proto in protocols:
             s = self.dumps(x, proto)
-            assert isinstance(s, bytes)
+            assert isinstance(s, bytes_types)
             y = self.loads(s)
             self.assertEqual(x, y)
             num_setitems = count_opcode(pickle.SETITEMS, s)
@@ -949,7 +970,7 @@
 
     def test_highest_protocol(self):
         # Of course this needs to be changed when HIGHEST_PROTOCOL changes.
-        self.assertEqual(self.module.HIGHEST_PROTOCOL, 2)
+        self.assertEqual(self.module.HIGHEST_PROTOCOL, 3)
 
     def test_callapi(self):
         from io import BytesIO
@@ -996,3 +1017,21 @@
         self.assertEqual(self.loads(self.dumps(L, 1)), L)
         self.assertEqual(self.id_count, 5)
         self.assertEqual(self.load_count, 5)
+
+if __name__ == "__main__":
+    # Print some stuff that can be used to rewrite DATA{0,1,2}
+    from pickletools import dis
+    x = create_data()
+    for i in range(3):
+        p = pickle.dumps(x, i)
+        print("DATA{0} = (".format(i))
+        for j in range(0, len(p), 20):
+            b = bytes(p[j:j+20])
+            print("    {0!r}".format(b))
+        print(")")
+        print()
+        print("# Disassembly of DATA{0}".format(i))
+        print("DATA{0}_DIS = \"\"\"\\".format(i))
+        dis(p)
+        print("\"\"\"")
+        print()

Modified: python/branches/py3k-importlib/Lib/test/pydocfodder.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/pydocfodder.py	(original)
+++ python/branches/py3k-importlib/Lib/test/pydocfodder.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,7 @@
 """Something just to look at via pydoc."""
 
+import types
+
 class A_classic:
     "A classic class."
     def A_method(self):
@@ -208,3 +210,7 @@
             del inst.desc[self.attr]
 
     x = property(get_desc('x'), set_desc('x'), del_desc('x'), 'prop x')
+
+
+submodule = types.ModuleType(__name__ + '.submodule',
+    """A submodule, which should appear in its parent's summary""")

Modified: python/branches/py3k-importlib/Lib/test/regex_tests.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/regex_tests.py	(original)
+++ python/branches/py3k-importlib/Lib/test/regex_tests.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,4 @@
 # Regex test suite and benchmark suite v1.5a2
-# Due to the use of r"aw" strings, this file will
-# only work with Python 1.5 or higher.
 
 # The 3 possible outcomes for each pattern
 [SUCCEED, FAIL, SYNTAX_ERROR] = range(3)

Modified: python/branches/py3k-importlib/Lib/test/regrtest.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/regrtest.py	(original)
+++ python/branches/py3k-importlib/Lib/test/regrtest.py	Thu Mar 27 00:48:05 2008
@@ -12,10 +12,9 @@
 -w: verbose2   -- re-run failed tests in verbose mode
 -d: debug      -- print traceback for failed tests
 -q: quiet      -- don't print anything except if a test fails
--g: generate   -- write the output file for a test instead of comparing it
 -x: exclude    -- arguments are tests to *exclude*
 -s: single     -- run only a single test (see below)
--S: start      -- start running all the tests with the specified one first
+-S: slow       -- print the slowest 10 tests
 -r: random     -- randomize test execution order
 -f: fromfile   -- read names of tests to run from a file (see below)
 -l: findleaks  -- if GC is available detect tests that leak memory
@@ -127,20 +126,22 @@
 option '-uall,-bsddb'.
 """
 
-import os
-import sys
 import getopt
+import os
 import random
-import warnings
 import re
 import io
+import sys
+import time
 import traceback
+import warnings
+from inspect import isabstract
 
 # I see no other way to suppress these warnings;
 # putting them in test_grammar.py has no effect:
 warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
                         ".*test.test_grammar$")
-if sys.maxint > 0x7fffffff:
+if sys.maxsize > 0x7fffffff:
     # Also suppress them in <string>, because for 64-bit platforms,
     # that's where test_grammar.py hides them.
     warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
@@ -185,8 +186,7 @@
 def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
          exclude=False, single=False, randomize=False, fromfile=None,
          findleaks=False, use_resources=None, trace=False, coverdir='coverage',
-         runleaks=False, huntrleaks=None, verbose2=False, debug=False,
-         start=None):
+         runleaks=False, huntrleaks=False, verbose2=False, print_slow=False):
     """Execute a test suite.
 
     This also parses command-line options and modifies its behavior
@@ -203,17 +203,17 @@
     command-line will be used.  If that's empty, too, then all *.py
     files beginning with test_ will be used.
 
-    The other default arguments (verbose, quiet, generate, exclude, single,
-    randomize, findleaks, use_resources, trace and coverdir) allow programmers
-    calling main() directly to set the values that would normally be set by
-    flags on the command line.
+    The other default arguments (verbose, quiet, generate, exclude,
+    single, randomize, findleaks, use_resources, trace, coverdir, and
+    print_slow) allow programmers calling main() directly to set the
+    values that would normally be set by flags on the command line.
     """
 
     test_support.record_original_stdout(sys.stdout)
     try:
-        opts, args = getopt.getopt(sys.argv[1:], 'dhvgqxsS:rf:lu:t:TD:NLR:wM:n',
-                                   ['help', 'verbose', 'quiet', 'generate',
-                                    'exclude', 'single', 'random', 'fromfile',
+        opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsSrf:lu:t:TD:NLR:wM:n',
+                                   ['help', 'verbose', 'quiet', 'exclude',
+                                    'single', 'slow', 'random', 'fromfile',
                                     'findleaks', 'use=', 'threshold=', 'trace',
                                     'coverdir=', 'nocoverdir', 'runleaks',
                                     'huntrleaks=', 'verbose2', 'memlimit=',
@@ -225,6 +225,8 @@
     # Defaults
     if use_resources is None:
         use_resources = []
+    debug = False
+    start = None
     for o, a in opts:
         if o in ('-h', '--help'):
             print(__doc__)
@@ -238,14 +240,14 @@
         elif o in ('-q', '--quiet'):
             quiet = True;
             verbose = 0
-        elif o in ('-g', '--generate'):
-            generate = True
         elif o in ('-x', '--exclude'):
             exclude = True
         elif o in ('-S', '--start'):
             start = a
         elif o in ('-s', '--single'):
             single = True
+        elif o in ('-S', '--slow'):
+            print_slow = True
         elif o in ('-r', '--randomize'):
             randomize = True
         elif o in ('-f', '--fromfile'):
@@ -278,6 +280,9 @@
                 huntrleaks[1] = int(huntrleaks[1])
             if len(huntrleaks) == 2 or not huntrleaks[2]:
                 huntrleaks[2:] = ["reflog.txt"]
+            # Avoid false positives due to the character cache in
+            # stringobject.c filling slowly with random data
+            warm_char_cache()
         elif o in ('-M', '--memlimit'):
             test_support.set_memlimit(a)
         elif o in ('-u', '--use'):
@@ -357,9 +362,9 @@
 
     # Strip .py extensions.
     if args:
-        args = map(removepy, args)
+        args = list(map(removepy, args))
     if tests:
-        tests = map(removepy, tests)
+        tests = list(map(removepy, tests))
 
     stdtests = STDTESTS[:]
     nottests = NOTTESTS.copy()
@@ -384,6 +389,7 @@
         import trace
         tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix],
                              trace=False, count=True)
+    test_times = []
     test_support.verbose = verbose      # Tell tests to be moderately quiet
     test_support.use_resources = use_resources
     save_modules = sys.modules.keys()
@@ -394,12 +400,13 @@
         if trace:
             # If we're tracing code coverage, then we don't exit with status
             # if on a false return value from main.
-            tracer.runctx('runtest(test, generate, verbose, quiet, testdir)',
+            tracer.runctx('runtest(test, generate, verbose, quiet,'
+                          '        test_times, testdir)',
                           globals=globals(), locals=vars())
         else:
             try:
-                ok = runtest(test, generate, verbose, quiet, testdir,
-                             huntrleaks)
+                ok = runtest(test, generate, verbose, quiet, test_times,
+                             testdir, huntrleaks)
             except KeyboardInterrupt:
                 # print a newline separate from the ^C
                 print()
@@ -440,6 +447,11 @@
         if verbose:
             print("CAUTION:  stdout isn't compared in verbose mode:")
             print("a test that passes in verbose mode may fail without it.")
+    if print_slow:
+        test_times.sort(reverse=True)
+        print("10 slowest tests:")
+        for time, test in test_times[:10]:
+            print("%s: %.1fs" % (test, time))
     if bad:
         print(count(len(bad), "test"), "failed:")
         printlist(bad)
@@ -467,8 +479,8 @@
             print("Re-running test %r in verbose mode" % test)
             sys.stdout.flush()
             try:
-                test_support.verbose = 1
-                ok = runtest(test, generate, 1, quiet, testdir,
+                test_support.verbose = True
+                ok = runtest(test, generate, True, quiet, test_times, testdir,
                              huntrleaks, debug)
             except KeyboardInterrupt:
                 # print a newline separate from the ^C
@@ -533,15 +545,14 @@
     tests.sort()
     return stdtests + tests
 
-def runtest(test, generate, verbose, quiet, testdir=None,
-            huntrleaks=None, debug=False):
+def runtest(test, generate, verbose, quiet, test_times,
+            testdir=None, huntrleaks=False, debug=False):
     """Run a single test.
 
     test -- the name of the test
-    generate -- if true, generate output, instead of running the test
-                and comparing it to a previously created output file
     verbose -- if true, print more messages
     quiet -- if true, don't print 'skipped' messages (probably redundant)
+    test_times -- a list of (time, test_name) pairs
     testdir -- test directory
     huntrleaks -- run multiple times to test for leaks; requires a debug
                   build; a triple corresponding to -R's three arguments
@@ -555,18 +566,16 @@
     """
 
     try:
-        return runtest_inner(test, generate, verbose, quiet, testdir,
-                             huntrleaks, debug)
+        return runtest_inner(test, generate, verbose, quiet, test_times,
+                             testdir, huntrleaks)
     finally:
         cleanup_test_droppings(test, verbose)
 
-def runtest_inner(test, generate, verbose, quiet,
-                     testdir=None, huntrleaks=None, debug=False):
+def runtest_inner(test, generate, verbose, quiet, test_times,
+                  testdir=None, huntrleaks=False, debug=False):
     test_support.unload(test)
     if not testdir:
         testdir = findtestdir()
-    outputdir = os.path.join(testdir, "output")
-    outputfile = os.path.join(outputdir, test)
     if verbose:
         cfp = None
     else:
@@ -583,17 +592,19 @@
             else:
                 # Always import it from the test package
                 abstest = 'test.' + test
+            start_time = time.time()
             the_package = __import__(abstest, globals(), locals(), [])
             the_module = getattr(the_package, test)
-            # Most tests run to completion simply as a side-effect of
-            # being imported.  For the benefit of tests that can't run
-            # that way (like test_threaded_import), explicitly invoke
-            # their test_main() function (if it exists).
+            # Old tests run to completion simply as a side-effect of
+            # being imported.  For tests based on unittest or doctest,
+            # explicitly invoke their test_main() function (if it exists).
             indirect_test = getattr(the_module, "test_main", None)
             if indirect_test is not None:
                 indirect_test()
             if huntrleaks:
                 dash_R(the_module, test, indirect_test, huntrleaks)
+            test_time = time.time() - start_time
+            test_times.append((test_time, test))
         finally:
             sys.stdout = save_stdout
     except test_support.ResourceDenied as msg:
@@ -624,27 +635,7 @@
         if not cfp:
             return 1
         output = cfp.getvalue()
-        if generate:
-            if output == test + "\n":
-                if os.path.exists(outputfile):
-                    # Write it since it already exists (and the contents
-                    # may have changed), but let the user know it isn't
-                    # needed:
-                    print("output file", outputfile, \
-                          "is no longer needed; consider removing it")
-                else:
-                    # We don't need it, so don't create it.
-                    return 1
-            fp = open(outputfile, "w")
-            fp.write(output)
-            fp.close()
-            return 1
-        if os.path.exists(outputfile):
-            fp = open(outputfile, "r")
-            expected = fp.read()
-            fp.close()
-        else:
-            expected = test + "\n"
+        expected = test + "\n"
         if output == expected or huntrleaks:
             return 1
         print("test", test, "produced unexpected output:")
@@ -696,9 +687,12 @@
     fs = warnings.filters[:]
     ps = copy_reg.dispatch_table.copy()
     pic = sys.path_importer_cache.copy()
-    abcs = {obj: obj._abc_registry.copy()
-            for abc in [getattr(_abcoll, a) for a in _abcoll.__all__]
-            for obj in abc.__subclasses__() + [abc]}
+    abcs = {}
+    for abc in [getattr(_abcoll, a) for a in _abcoll.__all__]:
+        if not isabstract(abc):
+            continue
+        for obj in abc.__subclasses__() + [abc]:
+            abcs[obj] = obj._abc_registry.copy()
 
     if indirect_test:
         def run_the_test():
@@ -736,6 +730,7 @@
     import urlparse, urllib, urllib2, mimetypes, doctest
     import struct, filecmp, _abcoll
     from distutils.dir_util import _path_created
+    from weakref import WeakSet
 
     # Restore some original values.
     warnings.filters[:] = fs
@@ -744,10 +739,15 @@
     sys.path_importer_cache.clear()
     sys.path_importer_cache.update(pic)
 
+    # clear type cache
+    sys._clear_type_cache()
+
     # Clear ABC registries, restoring previously saved ABC registries.
     for abc in [getattr(_abcoll, a) for a in _abcoll.__all__]:
+        if not isabstract(abc):
+            continue
         for obj in abc.__subclasses__() + [abc]:
-            obj._abc_registry = abcs.get(obj, {}).copy()
+            obj._abc_registry = abcs.get(obj, WeakSet()).copy()
             obj._abc_cache.clear()
             obj._abc_negative_cache.clear()
 
@@ -761,13 +761,18 @@
     dircache.reset()
     linecache.clearcache()
     mimetypes._default_mime_types()
-    struct._cache.clear()
     filecmp._cache.clear()
+    struct._clearcache()
     doctest.master = None
 
     # Collect cyclic trash.
     gc.collect()
 
+def warm_char_cache():
+    s = bytes(range(256))
+    for i in range(256):
+        s[i:i+1]
+
 def reportdiff(expected, output):
     import difflib
     print("*" * 70)
@@ -849,9 +854,6 @@
 #     test_pep277
 #         The _ExpectedSkips constructor adds this to the set of expected
 #         skips if not os.path.supports_unicode_filenames.
-#     test_socket_ssl
-#         Controlled by test_socket_ssl.skip_expected.  Requires the network
-#         resource, and a socket module with ssl support.
 #     test_timeout
 #         Controlled by test_timeout.skip_expected.  Requires the network
 #         resource and a socket module.
@@ -871,10 +873,12 @@
         test_dl
         test_fcntl
         test_fork1
+        test_epoll
         test_gdbm
         test_grp
         test_ioctl
         test_largefile
+        test_kqueue
         test_mhlib
         test_openpty
         test_ossaudiodev
@@ -885,6 +889,7 @@
         test_pwd
         test_resource
         test_signal
+        test_syslog
         test_threadsignals
         test_wait3
         test_wait4
@@ -894,6 +899,7 @@
         test_curses
         test_dl
         test_largefile
+        test_kqueue
         test_ossaudiodev
         """,
    'mac':
@@ -909,10 +915,12 @@
         test_dl
         test_fcntl
         test_fork1
+        test_epoll
         test_grp
         test_ioctl
         test_largefile
         test_locale
+        test_kqueue
         test_mmap
         test_openpty
         test_ossaudiodev
@@ -930,7 +938,9 @@
         """
         test_bsddb
         test_dl
+        test_epoll
         test_largefile
+        test_kqueue
         test_minidom
         test_openpty
         test_pyexpat
@@ -941,7 +951,9 @@
         """
         test_bsddb
         test_dl
+        test_epoll
         test_largefile
+        test_kqueue
         test_minidom
         test_openpty
         test_pyexpat
@@ -954,9 +966,11 @@
         test_bsddb
         test_dl
         test_fork1
+        test_epoll
         test_gettext
         test_largefile
         test_locale
+        test_kqueue
         test_minidom
         test_openpty
         test_pyexpat
@@ -974,9 +988,11 @@
         test_bsddb
         test_bsddb3
         test_curses
+        test_epoll
         test_gdbm
         test_largefile
         test_locale
+        test_minidom
         test_ossaudiodev
         test_poll
         """,
@@ -985,6 +1001,8 @@
         test_bsddb
         test_curses
         test_dbm
+        test_epoll
+        test_kqueue
         test_gdbm
         test_gzip
         test_openpty
@@ -996,10 +1014,12 @@
         test_bsddb
         test_curses
         test_dl
+        test_epoll
         test_gdbm
         test_gzip
         test_largefile
         test_locale
+        test_kqueue
         test_minidom
         test_openpty
         test_pyexpat
@@ -1012,8 +1032,10 @@
         test_curses
         test_dl
         test_gdbm
+        test_epoll
         test_largefile
         test_locale
+        test_kqueue
         test_mhlib
         test_mmap
         test_poll
@@ -1024,7 +1046,9 @@
         test_bsddb3
         test_curses
         test_dbm
+        test_epoll
         test_ioctl
+        test_kqueue
         test_largefile
         test_locale
         test_ossaudiodev
@@ -1037,6 +1061,8 @@
         test_commands
         test_curses
         test_dl
+        test_epoll
+        test_kqueue
         test_largefile
         test_mhlib
         test_mmap
@@ -1050,12 +1076,12 @@
         """
         test_bsddb
         test_bsddb3
+        test_epoll
         test_gdbm
         test_locale
         test_ossaudiodev
         test_pep277
         test_pty
-        test_socket_ssl
         test_socketserver
         test_tcl
         test_timeout
@@ -1067,8 +1093,10 @@
         test_bsddb3
         test_bz2
         test_dl
+        test_epoll
         test_gdbm
         test_gzip
+        test_kqueue
         test_ossaudiodev
         test_tcl
         test_zipimport
@@ -1080,6 +1108,7 @@
         test_bsddb3
         test_ctypes
         test_dl
+        test_epoll
         test_gdbm
         test_locale
         test_normalization
@@ -1094,6 +1123,7 @@
         test_ctypes
         test_curses
         test_dl
+        test_epoll
         test_gdbm
         test_locale
         test_ossaudiodev
@@ -1104,6 +1134,7 @@
 _expectations['freebsd5'] = _expectations['freebsd4']
 _expectations['freebsd6'] = _expectations['freebsd4']
 _expectations['freebsd7'] = _expectations['freebsd4']
+_expectations['freebsd8'] = _expectations['freebsd4']
 
 class _ExpectedSkips:
     def __init__(self):
@@ -1115,17 +1146,22 @@
             s = _expectations[sys.platform]
             self.expected = set(s.split())
 
+            # These are broken tests, for now skipped on every platform.
+            # XXX Fix these!
+            self.expected.add('test_cProfile')
+
             # expected to be skipped on every platform, even Linux
             if not os.path.supports_unicode_filenames:
                 self.expected.add('test_pep277')
 
-            try:
-                from test import test_socket_ssl
-            except ImportError:
-                pass
-            else:
-                if test_socket_ssl.skip_expected:
-                    self.expected.add('test_socket_ssl')
+            # doctest, profile and cProfile tests fail when the codec for the
+            # fs encoding isn't built in because PyUnicode_Decode() adds two
+            # calls into Python.
+            encs = ("utf-8", "latin-1", "ascii", "mbcs", "utf-16", "utf-32")
+            if sys.getfilesystemencoding().lower() not in encs:
+                self.expected.add('test_profile')
+                self.expected.add('test_cProfile')
+                self.expected.add('test_doctest')
 
             if test_timeout.skip_expected:
                 self.expected.add('test_timeout')

Modified: python/branches/py3k-importlib/Lib/test/seq_tests.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/seq_tests.py	(original)
+++ python/branches/py3k-importlib/Lib/test/seq_tests.py	Thu Mar 27 00:48:05 2008
@@ -3,7 +3,7 @@
 """
 
 import unittest
-from test import test_support
+import sys
 
 # Various iterables
 # This is used for checking the constructor (here and in test_deque.py)
@@ -79,10 +79,10 @@
     def __next__(self):
         raise StopIteration
 
-from itertools import chain, imap
+from itertools import chain
 def itermulti(seqn):
     'Test multiple tiers of iterators'
-    return chain(imap(lambda x:x, iterfunc(IterGen(Sequence(seqn)))))
+    return chain(map(lambda x:x, iterfunc(IterGen(Sequence(seqn)))))
 
 class CommonTest(unittest.TestCase):
     # The type to be tested
@@ -304,6 +304,13 @@
             self.assertEqual(self.type2test(s)*(-4), self.type2test([]))
             self.assertEqual(id(s), id(s*1))
 
+    def test_bigrepeat(self):
+        x = self.type2test([0])
+        x *= 2**16
+        self.assertRaises(MemoryError, x.__mul__, 2**16)
+        if hasattr(x, '__imul__'):
+            self.assertRaises(MemoryError, x.__imul__, 2**16)
+
     def test_subscript(self):
         a = self.type2test([10, 11])
         self.assertEqual(a.__getitem__(0), 10)
@@ -319,3 +326,64 @@
         self.assertEqual(a.__getitem__(slice(3,5)), self.type2test([]))
         self.assertRaises(ValueError, a.__getitem__, slice(0, 10, 0))
         self.assertRaises(TypeError, a.__getitem__, 'x')
+
+    def test_count(self):
+        a = self.type2test([0, 1, 2])*3
+        self.assertEqual(a.count(0), 3)
+        self.assertEqual(a.count(1), 3)
+        self.assertEqual(a.count(3), 0)
+
+        self.assertRaises(TypeError, a.count)
+
+        class BadExc(Exception):
+            pass
+
+        class BadCmp:
+            def __eq__(self, other):
+                if other == 2:
+                    raise BadExc()
+                return False
+
+        self.assertRaises(BadExc, a.count, BadCmp())
+
+    def test_index(self):
+        u = self.type2test([0, 1])
+        self.assertEqual(u.index(0), 0)
+        self.assertEqual(u.index(1), 1)
+        self.assertRaises(ValueError, u.index, 2)
+
+        u = self.type2test([-2, -1, 0, 0, 1, 2])
+        self.assertEqual(u.count(0), 2)
+        self.assertEqual(u.index(0), 2)
+        self.assertEqual(u.index(0, 2), 2)
+        self.assertEqual(u.index(-2, -10), 0)
+        self.assertEqual(u.index(0, 3), 3)
+        self.assertEqual(u.index(0, 3, 4), 3)
+        self.assertRaises(ValueError, u.index, 2, 0, -10)
+
+        self.assertRaises(TypeError, u.index)
+
+        class BadExc(Exception):
+            pass
+
+        class BadCmp:
+            def __eq__(self, other):
+                if other == 2:
+                    raise BadExc()
+                return False
+
+        a = self.type2test([0, 1, 2, 3])
+        self.assertRaises(BadExc, a.index, BadCmp())
+
+        a = self.type2test([-2, -1, 0, 0, 1, 2])
+        self.assertEqual(a.index(0), 2)
+        self.assertEqual(a.index(0, 2), 2)
+        self.assertEqual(a.index(0, -4), 2)
+        self.assertEqual(a.index(-2, -10), 0)
+        self.assertEqual(a.index(0, 3), 3)
+        self.assertEqual(a.index(0, -3), 3)
+        self.assertEqual(a.index(0, 3, 4), 3)
+        self.assertEqual(a.index(0, -3, -2), 3)
+        self.assertEqual(a.index(0, -4*sys.maxsize, 4*sys.maxsize), 2)
+        self.assertRaises(ValueError, a.index, 0, 4*sys.maxsize,-4*sys.maxsize)
+        self.assertRaises(ValueError, a.index, 2, 0, -10)

Modified: python/branches/py3k-importlib/Lib/test/string_tests.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/string_tests.py	(original)
+++ python/branches/py3k-importlib/Lib/test/string_tests.py	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,7 @@
 
 import unittest, string, sys, struct
 from test import test_support
-from UserList import UserList
+from collections import UserList
 
 class Sequence:
     def __init__(self, seq='wxyz'): self.seq = seq
@@ -146,6 +146,13 @@
         self.checkequal(3, 'abc', 'find', '', 3)
         self.checkequal(-1, 'abc', 'find', '', 4)
 
+        # to check the ability to pass None as defaults
+        self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a')
+        self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4)
+        self.checkequal(-1, 'rrarrrrrrrrra', 'find', 'a', 4, 6)
+        self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4, None)
+        self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a', None, 6)
+
         self.checkraises(TypeError, 'hello', 'find')
         self.checkraises(TypeError, 'hello', 'find', 42)
 
@@ -183,6 +190,13 @@
         self.checkequal(3, 'abc', 'rfind', '', 3)
         self.checkequal(-1, 'abc', 'rfind', '', 4)
 
+        # to check the ability to pass None as defaults
+        self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a')
+        self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4)
+        self.checkequal(-1, 'rrarrrrrrrrra', 'rfind', 'a', 4, 6)
+        self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4, None)
+        self.checkequal( 2, 'rrarrrrrrrrra', 'rfind', 'a', None, 6)
+
         self.checkraises(TypeError, 'hello', 'rfind')
         self.checkraises(TypeError, 'hello', 'rfind', 42)
 
@@ -197,6 +211,13 @@
         self.checkraises(ValueError, 'abcdefghi', 'index', 'ghi', 8)
         self.checkraises(ValueError, 'abcdefghi', 'index', 'ghi', -1)
 
+        # to check the ability to pass None as defaults
+        self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a')
+        self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4)
+        self.checkraises(ValueError, 'rrarrrrrrrrra', 'index', 'a', 4, 6)
+        self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4, None)
+        self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a', None, 6)
+
         self.checkraises(TypeError, 'hello', 'index')
         self.checkraises(TypeError, 'hello', 'index', 42)
 
@@ -212,6 +233,13 @@
         self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, 8)
         self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, -1)
 
+        # to check the ability to pass None as defaults
+        self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a')
+        self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4)
+        self.checkraises(ValueError, 'rrarrrrrrrrra', 'rindex', 'a', 4, 6)
+        self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4, None)
+        self.checkequal( 2, 'rrarrrrrrrrra', 'rindex', 'a', None, 6)
+
         self.checkraises(TypeError, 'hello', 'rindex')
         self.checkraises(TypeError, 'hello', 'rindex', 42)
 
@@ -237,9 +265,9 @@
 
         self.checkraises(TypeError, 'hello', 'expandtabs', 42, 42)
         # This test is only valid when sizeof(int) == sizeof(void*) == 4.
-        if sys.maxint < (1 << 32) and struct.calcsize('P') == 4:
+        if sys.maxsize < (1 << 32) and struct.calcsize('P') == 4:
             self.checkraises(OverflowError,
-                             '\ta\n\tb', 'expandtabs', sys.maxint)
+                             '\ta\n\tb', 'expandtabs', sys.maxsize)
 
     def test_split(self):
         # by a char
@@ -250,7 +278,7 @@
         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', 3)
         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', 4)
         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|',
-                        sys.maxint-2)
+                        sys.maxsize-2)
         self.checkequal(['a|b|c|d'], 'a|b|c|d', 'split', '|', 0)
         self.checkequal(['a', '', 'b||c||d'], 'a||b||c||d', 'split', '|', 2)
         self.checkequal(['endcase ', ''], 'endcase |', 'split', '|')
@@ -269,7 +297,7 @@
         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', 3)
         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', 4)
         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//',
-                        sys.maxint-10)
+                        sys.maxsize-10)
         self.checkequal(['a//b//c//d'], 'a//b//c//d', 'split', '//', 0)
         self.checkequal(['a', '', 'b////c////d'], 'a////b////c////d', 'split', '//', 2)
         self.checkequal(['endcase ', ''], 'endcase test', 'split', 'test')
@@ -306,7 +334,7 @@
         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 3)
         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 4)
         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|',
-                        sys.maxint-100)
+                        sys.maxsize-100)
         self.checkequal(['a|b|c|d'], 'a|b|c|d', 'rsplit', '|', 0)
         self.checkequal(['a||b||c', '', 'd'], 'a||b||c||d', 'rsplit', '|', 2)
         self.checkequal(['', ' begincase'], '| begincase', 'rsplit', '|')
@@ -326,7 +354,7 @@
         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 3)
         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 4)
         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//',
-                        sys.maxint-5)
+                        sys.maxsize-5)
         self.checkequal(['a//b//c//d'], 'a//b//c//d', 'rsplit', '//', 0)
         self.checkequal(['a////b////c', '', 'd'], 'a////b////c////d', 'rsplit', '//', 2)
         self.checkequal(['', ' begincase'], 'test begincase', 'rsplit', 'test')
@@ -364,7 +392,7 @@
         EQ("", "", "replace", "A", "")
         EQ("", "", "replace", "A", "A")
         EQ("", "", "replace", "", "", 100)
-        EQ("", "", "replace", "", "", sys.maxint)
+        EQ("", "", "replace", "", "", sys.maxsize)
 
         # interleave (from=="", 'to' gets inserted everywhere)
         EQ("A", "A", "replace", "", "")
@@ -373,7 +401,7 @@
         EQ("*-#A*-#", "A", "replace", "", "*-#")
         EQ("*-A*-A*-", "AA", "replace", "", "*-")
         EQ("*-A*-A*-", "AA", "replace", "", "*-", -1)
-        EQ("*-A*-A*-", "AA", "replace", "", "*-", sys.maxint)
+        EQ("*-A*-A*-", "AA", "replace", "", "*-", sys.maxsize)
         EQ("*-A*-A*-", "AA", "replace", "", "*-", 4)
         EQ("*-A*-A*-", "AA", "replace", "", "*-", 3)
         EQ("*-A*-A", "AA", "replace", "", "*-", 2)
@@ -384,7 +412,7 @@
         EQ("", "A", "replace", "A", "")
         EQ("", "AAA", "replace", "A", "")
         EQ("", "AAA", "replace", "A", "", -1)
-        EQ("", "AAA", "replace", "A", "", sys.maxint)
+        EQ("", "AAA", "replace", "A", "", sys.maxsize)
         EQ("", "AAA", "replace", "A", "", 4)
         EQ("", "AAA", "replace", "A", "", 3)
         EQ("A", "AAA", "replace", "A", "", 2)
@@ -393,7 +421,7 @@
         EQ("", "AAAAAAAAAA", "replace", "A", "")
         EQ("BCD", "ABACADA", "replace", "A", "")
         EQ("BCD", "ABACADA", "replace", "A", "", -1)
-        EQ("BCD", "ABACADA", "replace", "A", "", sys.maxint)
+        EQ("BCD", "ABACADA", "replace", "A", "", sys.maxsize)
         EQ("BCD", "ABACADA", "replace", "A", "", 5)
         EQ("BCD", "ABACADA", "replace", "A", "", 4)
         EQ("BCDA", "ABACADA", "replace", "A", "", 3)
@@ -416,7 +444,7 @@
         EQ("thaet", "thaet", "replace", "the", "")
         EQ("here and re", "here and there", "replace", "the", "")
         EQ("here and re and re", "here and there and there",
-           "replace", "the", "", sys.maxint)
+           "replace", "the", "", sys.maxsize)
         EQ("here and re and re", "here and there and there",
            "replace", "the", "", -1)
         EQ("here and re and re", "here and there and there",
@@ -441,7 +469,7 @@
         # single character replace in place (len(from)==len(to)==1)
         EQ("Who goes there?", "Who goes there?", "replace", "o", "o")
         EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O")
-        EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", sys.maxint)
+        EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", sys.maxsize)
         EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", -1)
         EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", 3)
         EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", 2)
@@ -458,7 +486,7 @@
 
         # substring replace in place (len(from)==len(to) > 1)
         EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**")
-        EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", sys.maxint)
+        EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", sys.maxsize)
         EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", -1)
         EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", 4)
         EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", 3)
@@ -472,7 +500,7 @@
         # replace single character (len(from)==1, len(to)>1)
         EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK")
         EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", -1)
-        EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", sys.maxint)
+        EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", sys.maxsize)
         EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", 2)
         EQ("ReyKKjavik", "Reykjavik", "replace", "k", "KK", 1)
         EQ("Reykjavik", "Reykjavik", "replace", "k", "KK", 0)
@@ -484,7 +512,7 @@
         EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
            "replace", "spam", "ham")
         EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
-           "replace", "spam", "ham", sys.maxint)
+           "replace", "spam", "ham", sys.maxsize)
         EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
            "replace", "spam", "ham", -1)
         EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
@@ -504,8 +532,8 @@
 
         # XXX Commented out. Is there any reason to support buffer objects
         # as arguments for str.replace()?  GvR
-##         ba = buffer('a')
-##         bb = buffer('b')
+##         ba = bytearray('a')
+##         bb = bytearray('b')
 ##         EQ("bbc", "abc", "replace", ba, bb)
 ##         EQ("aac", "abc", "replace", bb, ba)
 
@@ -539,7 +567,7 @@
 
     def test_replace_overflow(self):
         # Check for overflow checking on 32 bit machines
-        if sys.maxint != 2147483647 or struct.calcsize("P") > 4:
+        if sys.maxsize != 2147483647 or struct.calcsize("P") > 4:
             return
         A2_16 = "A" * (2**16)
         self.checkraises(OverflowError, A2_16, "replace", "", A2_16)
@@ -603,7 +631,7 @@
         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 3)
         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 4)
         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None,
-                        sys.maxint-1)
+                        sys.maxsize-1)
         self.checkequal(['a b c d'], 'a b c d', 'split', None, 0)
         self.checkequal(['a b c d'], '  a b c d', 'split', None, 0)
         self.checkequal(['a', 'b', 'c  d'], 'a  b  c  d', 'split', None, 2)
@@ -634,7 +662,7 @@
         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 3)
         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 4)
         self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None,
-                        sys.maxint-20)
+                        sys.maxsize-20)
         self.checkequal(['a b c d'], 'a b c d', 'rsplit', None, 0)
         self.checkequal(['a b c d'], 'a b c d  ', 'rsplit', None, 0)
         self.checkequal(['a  b', 'c', 'd'], 'a  b  c  d', 'rsplit', None, 2)
@@ -988,14 +1016,14 @@
         self.checkequal('abc', 'a', 'join', ('abc',))
         self.checkequal('z', 'a', 'join', UserList(['z']))
         self.checkequal('a.b.c', '.', 'join', ['a', 'b', 'c'])
-        self.checkequal('a.b.3', '.', 'join', ['a', 'b', 3])
+        self.assertRaises(TypeError, '.'.join, ['a', 'b', 3])
         for i in [5, 25, 125]:
             self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join',
                  ['a' * i] * i)
             self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join',
                  ('a' * i,) * i)
 
-        self.checkequal(str(BadSeq1()), ' ', 'join', BadSeq1())
+        #self.checkequal(str(BadSeq1()), ' ', 'join', BadSeq1())
         self.checkequal('a b c', ' ', 'join', BadSeq2())
 
         self.checkraises(TypeError, ' ', 'join')
@@ -1025,7 +1053,13 @@
             # unicode raises ValueError, str raises OverflowError
             self.checkraises((ValueError, OverflowError), '%c', '__mod__', ordinal)
 
+        longvalue = sys.maxsize + 10
+        slongvalue = str(longvalue)
+        if slongvalue[-1] in ("L","l"): slongvalue = slongvalue[:-1]
         self.checkequal(' 42', '%3ld', '__mod__', 42)
+        self.checkequal('42', '%d', '__mod__', 42.0)
+        self.checkequal(slongvalue, '%d', '__mod__', longvalue)
+        self.checkcall('%d', '__mod__', float(longvalue))
         self.checkequal('0042.00', '%07.2f', '__mod__', 42)
         self.checkequal('0042.00', '%07.2F', '__mod__', 42)
 
@@ -1035,6 +1069,8 @@
         self.checkraises(TypeError, '%c', '__mod__', (None,))
         self.checkraises(ValueError, '%(foo', '__mod__', {})
         self.checkraises(TypeError, '%(foo)s %(bar)s', '__mod__', ('foo', 42))
+        self.checkraises(TypeError, '%d', '__mod__', "42") # not numeric
+        self.checkraises(TypeError, '%d', '__mod__', (42+0j)) # no int/long conversion provided
 
         # argument names with properly nested brackets are supported
         self.checkequal('bar', '%((foo))s', '__mod__', {'(foo)': 'bar'})
@@ -1143,16 +1179,16 @@
             s2 = "".join([s1])
             self.assert_(s1 is s2)
 
-        elif t is str8:
-            s1 = subclass("abcd")
-            s2 = "".join([s1])
-            self.assert_(s1 is not s2)
-            self.assert_(type(s2) is str) # promotes!
-
-            s1 = t("abcd")
-            s2 = "".join([s1])
-            self.assert_(s1 is not s2)
-            self.assert_(type(s2) is str) # promotes!
+##         elif t is str8:
+##             s1 = subclass("abcd")
+##             s2 = "".join([s1])
+##             self.assert_(s1 is not s2)
+##             self.assert_(type(s2) is str) # promotes!
+
+##             s1 = t("abcd")
+##             s2 = "".join([s1])
+##             self.assert_(s1 is not s2)
+##             self.assert_(type(s2) is str) # promotes!
 
         else:
             self.fail("unexpected type for MixinStrUnicodeTest %r" % t)

Modified: python/branches/py3k-importlib/Lib/test/test___all__.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test___all__.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test___all__.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 import unittest
-from test.test_support import verbose, run_unittest
+from test.test_support import run_unittest
 import sys
 
 
@@ -36,7 +36,6 @@
         self.check_all("Queue")
         self.check_all("SimpleHTTPServer")
         self.check_all("SocketServer")
-        self.check_all("UserString")
         self.check_all("aifc")
         self.check_all("base64")
         self.check_all("bdb")

Modified: python/branches/py3k-importlib/Lib/test/test___future__.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test___future__.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test___future__.py	Thu Mar 27 00:48:05 2008
@@ -39,7 +39,7 @@
                 a(isinstance(major, int), "%s major isn't int"  % name)
                 a(isinstance(minor, int), "%s minor isn't int" % name)
                 a(isinstance(micro, int), "%s micro isn't int" % name)
-                a(isinstance(level, basestring),
+                a(isinstance(level, str),
                     "%s level isn't string" % name)
                 a(level in GOOD_SERIALS,
                        "%s level string has unknown value" % name)

Modified: python/branches/py3k-importlib/Lib/test/test__locale.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test__locale.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test__locale.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 from test.test_support import verbose, TestSkipped, run_unittest
-from _locale import (setlocale, LC_NUMERIC, RADIXCHAR, THOUSEP, nl_langinfo,
+from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, RADIXCHAR, THOUSEP, nl_langinfo,
                     localeconv, Error)
 import unittest
 from platform import uname
@@ -28,10 +28,10 @@
 class _LocaleTests(unittest.TestCase):
 
     def setUp(self):
-        self.oldlocale = setlocale(LC_NUMERIC)
+        self.oldlocale = setlocale(LC_ALL)
 
     def tearDown(self):
-        setlocale(LC_NUMERIC, self.oldlocale)
+        setlocale(LC_ALL, self.oldlocale)
 
     # Want to know what value was calculated, what it was compared against,
     # what function was used for the calculation, what type of data was used,
@@ -58,6 +58,7 @@
         for loc in candidate_locales:
             try:
                 setlocale(LC_NUMERIC, loc)
+                setlocale(LC_CTYPE, loc)
             except Error:
                 continue
             for li, lc in ((RADIXCHAR, "decimal_point"),
@@ -69,6 +70,7 @@
         for loc in candidate_locales:
             try:
                 setlocale(LC_NUMERIC, loc)
+                setlocale(LC_CTYPE, loc)
             except Error:
                 continue
             for li, lc in ((RADIXCHAR, "decimal_point"),
@@ -80,6 +82,7 @@
         for loc in candidate_locales:
             try:
                 setlocale(LC_NUMERIC, loc)
+                setlocale(LC_CTYPE, loc)
             except Error:
                 continue
             for li, lc in ((RADIXCHAR, "decimal_point"),
@@ -102,6 +105,7 @@
         for loc in candidate_locales:
             try:
                 setlocale(LC_NUMERIC, loc)
+                setlocale(LC_CTYPE, loc)
             except Error:
                 continue
 

Modified: python/branches/py3k-importlib/Lib/test/test_abc.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_abc.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_abc.py	Thu Mar 27 00:48:05 2008
@@ -3,11 +3,11 @@
 
 """Unit tests for abc.py."""
 
-import sys
 import unittest
 from test import test_support
 
 import abc
+from inspect import isabstract
 
 
 class TestABC(unittest.TestCase):
@@ -42,24 +42,36 @@
                 def bar(self): pass  # concrete
             self.assertEqual(C.__abstractmethods__, {"foo"})
             self.assertRaises(TypeError, C)  # because foo is abstract
+            self.assert_(isabstract(C))
             class D(C):
                 def bar(self): pass  # concrete override of concrete
             self.assertEqual(D.__abstractmethods__, {"foo"})
             self.assertRaises(TypeError, D)  # because foo is still abstract
+            self.assert_(isabstract(D))
             class E(D):
                 def foo(self): pass
             self.assertEqual(E.__abstractmethods__, set())
             E()  # now foo is concrete, too
+            self.failIf(isabstract(E))
             class F(E):
                 @abstractthing
                 def bar(self): pass  # abstract override of concrete
             self.assertEqual(F.__abstractmethods__, {"bar"})
             self.assertRaises(TypeError, F)  # because bar is abstract now
+            self.assert_(isabstract(F))
+
+    def test_subclass_oldstyle_class(self):
+        class A:
+            __metaclass__ = abc.ABCMeta
+        class OldstyleClass:
+            pass
+        self.assertFalse(issubclass(OldstyleClass, A))
+        self.assertFalse(issubclass(A, OldstyleClass))
 
     def test_registration_basics(self):
         class A(metaclass=abc.ABCMeta):
             pass
-        class B:
+        class B(object):
             pass
         b = B()
         self.assertEqual(issubclass(B, A), False)
@@ -73,6 +85,16 @@
         self.assertEqual(issubclass(C, A), True)
         self.assertEqual(isinstance(c, A), True)
 
+    def test_isinstance_invalidation(self):
+        class A(metaclass=abc.ABCMeta):
+            pass
+        class B:
+            pass
+        b = B()
+        self.assertEqual(isinstance(b, A), False)
+        A.register(B)
+        self.assertEqual(isinstance(b, A), True)
+
     def test_registration_builtins(self):
         class A(metaclass=abc.ABCMeta):
             pass
@@ -81,9 +103,11 @@
         self.assertEqual(issubclass(int, A), True)
         class B(A):
             pass
-        B.register(basestring)
+        B.register(str)
+        class C(str): pass
         self.assertEqual(isinstance("", A), True)
         self.assertEqual(issubclass(str, A), True)
+        self.assertEqual(issubclass(C, A), True)
 
     def test_registration_edge_cases(self):
         class A(metaclass=abc.ABCMeta):
@@ -92,7 +116,7 @@
         class A1(A):
             pass
         self.assertRaises(RuntimeError, A1.register, A)  # cycles not allowed
-        class B:
+        class B(object):
             pass
         A1.register(B)  # ok
         A1.register(B)  # should pass silently
@@ -133,7 +157,7 @@
     def test_all_new_methods_are_called(self):
         class A(metaclass=abc.ABCMeta):
             pass
-        class B:
+        class B(object):
             counter = 0
             def __new__(cls):
                 B.counter += 1

Modified: python/branches/py3k-importlib/Lib/test/test_abstract_numbers.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_abstract_numbers.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_abstract_numbers.py	Thu Mar 27 00:48:05 2008
@@ -1,18 +1,16 @@
 """Unit tests for numbers.py."""
 
+import math
+import operator
 import unittest
-from test import test_support
-from numbers import Number
-from numbers import Exact, Inexact
 from numbers import Complex, Real, Rational, Integral
-import operator
+from numbers import Number
+from test import test_support
 
 class TestNumbers(unittest.TestCase):
     def test_int(self):
         self.failUnless(issubclass(int, Integral))
         self.failUnless(issubclass(int, Complex))
-        self.failUnless(issubclass(int, Exact))
-        self.failIf(issubclass(int, Inexact))
 
         self.assertEqual(7, int(7).real)
         self.assertEqual(0, int(7).imag)
@@ -23,8 +21,6 @@
     def test_float(self):
         self.failIf(issubclass(float, Rational))
         self.failUnless(issubclass(float, Real))
-        self.failIf(issubclass(float, Exact))
-        self.failUnless(issubclass(float, Inexact))
 
         self.assertEqual(7.3, float(7.3).real)
         self.assertEqual(0, float(7.3).imag)
@@ -33,11 +29,10 @@
     def test_complex(self):
         self.failIf(issubclass(complex, Real))
         self.failUnless(issubclass(complex, Complex))
-        self.failIf(issubclass(complex, Exact))
-        self.failUnless(issubclass(complex, Inexact))
 
         c1, c2 = complex(3, 2), complex(4,1)
-        self.assertRaises(TypeError, trunc, c1)
+        # XXX: This is not ideal, but see the comment in math_trunc().
+        self.assertRaises(TypeError, math.trunc, c1)
         self.assertRaises(TypeError, operator.mod, c1, c2)
         self.assertRaises(TypeError, divmod, c1, c2)
         self.assertRaises(TypeError, operator.floordiv, c1, c2)

Modified: python/branches/py3k-importlib/Lib/test/test_applesingle.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_applesingle.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_applesingle.py	Thu Mar 27 00:48:05 2008
@@ -5,7 +5,6 @@
 import Carbon.File
 import MacOS
 import os
-import sys
 from test import test_support
 import struct
 import applesingle

Modified: python/branches/py3k-importlib/Lib/test/test_ast.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_ast.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_ast.py	Thu Mar 27 00:48:05 2008
@@ -1,8 +1,8 @@
-import sys, itertools
+import sys
 import _ast
 
 def to_tuple(t):
-    if t is None or isinstance(t, (basestring, int, int, complex)):
+    if t is None or isinstance(t, (str, int, complex)):
         return t
     elif isinstance(t, list):
         return [to_tuple(e) for e in t]
@@ -142,7 +142,7 @@
     for input, output, kind in ((exec_tests, exec_results, "exec"),
                                 (single_tests, single_results, "single"),
                                 (eval_tests, eval_results, "eval")):
-        for i, o in itertools.izip(input, output):
+        for i, o in zip(input, output):
             ast_tree = compile(i, "?", kind, 0x400)
             tup = to_tuple(ast_tree)
             assert tup == o, ("kind=%r\ninput=%r\nexpected=%r\ngot=%r" %

Modified: python/branches/py3k-importlib/Lib/test/test_asynchat.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_asynchat.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_asynchat.py	Thu Mar 27 00:48:05 2008
@@ -15,12 +15,17 @@
     # client each send
     chunk_size = 1
 
+    def __init__(self, event):
+        threading.Thread.__init__(self)
+        self.event = event
+
     def run(self):
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         global PORT
         PORT = test_support.bind_port(sock, HOST, PORT)
         sock.listen(1)
+        self.event.set()
         conn, client = sock.accept()
         self.buffer = b""
         # collect data until quit message is seen
@@ -74,6 +79,16 @@
         self.buffer = b""
 
 
+def start_echo_server():
+    event = threading.Event()
+    s = echo_server(event)
+    s.start()
+    event.wait()
+    event.clear()
+    time.sleep(0.01) # Give server time to start accepting.
+    return s, event
+
+
 class TestAsynchat(unittest.TestCase):
     usepoll = False
 
@@ -84,10 +99,13 @@
         pass
 
     def line_terminator_check(self, term, server_chunk):
-        s = echo_server()
+        event = threading.Event()
+        s = echo_server(event)
         s.chunk_size = server_chunk
         s.start()
-        time.sleep(0.5) # Give server time to initialize
+        event.wait()
+        event.clear()
+        time.sleep(0.01) # Give server time to start accepting.
         c = echo_client(term)
         c.push(b"hello ")
         c.push(bytes("world%s" % term, "ascii"))
@@ -105,23 +123,21 @@
     def test_line_terminator1(self):
         # test one-character terminator
         for l in (1,2,3):
-            self.line_terminator_check(b'\n', l)
+            self.line_terminator_check('\n', l)
 
     def test_line_terminator2(self):
         # test two-character terminator
         for l in (1,2,3):
-            self.line_terminator_check(b'\r\n', l)
+            self.line_terminator_check('\r\n', l)
 
     def test_line_terminator3(self):
         # test three-character terminator
         for l in (1,2,3):
-            self.line_terminator_check(b'qqq', l)
+            self.line_terminator_check('qqq', l)
 
     def numeric_terminator_check(self, termlen):
         # Try reading a fixed number of bytes
-        s = echo_server()
-        s.start()
-        time.sleep(0.5) # Give server time to initialize
+        s, event = start_echo_server()
         c = echo_client(termlen)
         data = b"hello world, I'm not dead yet!\n"
         c.push(data)
@@ -141,9 +157,7 @@
 
     def test_none_terminator(self):
         # Try reading a fixed number of bytes
-        s = echo_server()
-        s.start()
-        time.sleep(0.5) # Give server time to initialize
+        s, event = start_echo_server()
         c = echo_client(None)
         data = b"hello world, I'm not dead yet!\n"
         c.push(data)
@@ -155,9 +169,7 @@
         self.assertEqual(c.buffer, data)
 
     def test_simple_producer(self):
-        s = echo_server()
-        s.start()
-        time.sleep(0.5) # Give server time to initialize
+        s, event = start_echo_server()
         c = echo_client(b'\n')
         data = b"hello world\nI'm not dead yet!\n"
         p = asynchat.simple_producer(data+SERVER_QUIT, buffer_size=8)
@@ -168,9 +180,7 @@
         self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
 
     def test_string_producer(self):
-        s = echo_server()
-        s.start()
-        time.sleep(0.5) # Give server time to initialize
+        s, event = start_echo_server()
         c = echo_client(b'\n')
         data = b"hello world\nI'm not dead yet!\n"
         c.push_with_producer(data+SERVER_QUIT)
@@ -181,9 +191,7 @@
 
     def test_empty_line(self):
         # checks that empty lines are handled correctly
-        s = echo_server()
-        s.start()
-        time.sleep(0.5) # Give server time to initialize
+        s, event = start_echo_server()
         c = echo_client(b'\n')
         c.push(b"hello world\n\nI'm not dead yet!\n")
         c.push(SERVER_QUIT)
@@ -194,9 +202,7 @@
                          [b"hello world", b"", b"I'm not dead yet!"])
 
     def test_close_when_done(self):
-        s = echo_server()
-        s.start()
-        time.sleep(0.5) # Give server time to initialize
+        s, event = start_echo_server()
         c = echo_client(b'\n')
         c.push(b"hello world\nI'm not dead yet!\n")
         c.push(SERVER_QUIT)

Modified: python/branches/py3k-importlib/Lib/test/test_asyncore.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_asyncore.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_asyncore.py	Thu Mar 27 00:48:05 2008
@@ -70,7 +70,6 @@
             r, w, e = select.select([conn], [], [])
             if r:
                 data = conn.recv(10)
-                assert isinstance(data, bytes)
                 # keep everything except for the newline terminator
                 buf.write(data.replace(b'\n', b''))
                 if b'\n' in data:

Modified: python/branches/py3k-importlib/Lib/test/test_audioop.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_audioop.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_audioop.py	Thu Mar 27 00:48:05 2008
@@ -87,7 +87,7 @@
         print('add')
     data2 = []
     for d in data:
-        str = bytes(len(d))
+        str = bytearray(len(d))
         for i,b in enumerate(d):
             str[i] = 2*b
         data2.append(str)
@@ -177,7 +177,7 @@
         print('mul')
     data2 = []
     for d in data:
-        str = bytes(len(d))
+        str = bytearray(len(d))
         for i,b in enumerate(d):
             str[i] = 2*b
         data2.append(str)
@@ -207,7 +207,7 @@
 def testtomono(data):
     if verbose:
         print('tomono')
-    data2 = b''
+    data2 = bytearray()
     for d in data[0]:
         data2.append(d)
         data2.append(d)
@@ -218,7 +218,7 @@
 def testtostereo(data):
     if verbose:
         print('tostereo')
-    data2 = b''
+    data2 = bytearray()
     for d in data[0]:
         data2.append(d)
         data2.append(d)
@@ -271,7 +271,7 @@
     if not rv:
         print('Test FAILED for audioop.'+name+'()')
 
-def testall():
+def test_main():
     data = [gendata1(), gendata2(), gendata4()]
     names = dir(audioop)
     # We know there is a routine 'add'
@@ -281,4 +281,8 @@
             routines.append(n)
     for n in routines:
         testone(n, data)
-testall()
+
+
+
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_bigmem.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_bigmem.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_bigmem.py	Thu Mar 27 00:48:05 2008
@@ -64,13 +64,15 @@
         self.assertEquals(s.count('i'), 1)
         self.assertEquals(s.count('j'), 0)
 
-    @bigmemtest(minsize=0, memuse=1)
+    @bigmemtest(minsize=_2G + 2, memuse=3)
     def test_decode(self, size):
-        pass
+        s = b'.' * size
+        self.assertEquals(len(s.decode('utf-8')), size)
 
-    @bigmemtest(minsize=0, memuse=1)
+    @bigmemtest(minsize=_2G + 2, memuse=3)
     def test_encode(self, size):
-        pass
+        s = '.' * size
+        self.assertEquals(len(s.encode('utf-8')), size)
 
     @bigmemtest(minsize=_2G, memuse=2)
     def test_endswith(self, size):

Modified: python/branches/py3k-importlib/Lib/test/test_binascii.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_binascii.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_binascii.py	Thu Mar 27 00:48:05 2008
@@ -56,7 +56,7 @@
             a = binascii.b2a_base64(b)
             lines.append(a)
 
-        fillers = bytes()
+        fillers = bytearray()
         valid = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/"
         for i in range(256):
             if i not in valid:
@@ -64,7 +64,7 @@
         def addnoise(line):
             noise = fillers
             ratio = len(line) // len(noise)
-            res = bytes()
+            res = bytearray()
             while line and noise:
                 if len(line) // len(noise) > ratio:
                     c, line = line[0], line[1:]
@@ -72,7 +72,7 @@
                     c, noise = noise[0], noise[1:]
                 res.append(c)
             return res + noise + line
-        res = bytes()
+        res = bytearray()
         for line in map(addnoise, lines):
             b = binascii.a2b_base64(line)
             res += b

Modified: python/branches/py3k-importlib/Lib/test/test_bisect.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_bisect.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_bisect.py	Thu Mar 27 00:48:05 2008
@@ -1,91 +1,113 @@
+import sys
 import unittest
 from test import test_support
-from bisect import bisect_right, bisect_left, insort_left, insort_right, insort, bisect
-from UserList import UserList
+from collections import UserList
+
+# We do a bit of trickery here to be able to test both the C implementation
+# and the Python implementation of the module.
+
+# Make it impossible to import the C implementation anymore.
+sys.modules['_bisect'] = 0
+# We must also handle the case that bisect was imported before.
+if 'bisect' in sys.modules:
+    del sys.modules['bisect']
+
+# Now we can import the module and get the pure Python implementation.
+import bisect as py_bisect
+
+# Restore everything to normal.
+del sys.modules['_bisect']
+del sys.modules['bisect']
+
+# This is now the module with the C implementation.
+import bisect as c_bisect
+
 
 class TestBisect(unittest.TestCase):
+    module = None
 
-    precomputedCases = [
-        (bisect_right, [], 1, 0),
-        (bisect_right, [1], 0, 0),
-        (bisect_right, [1], 1, 1),
-        (bisect_right, [1], 2, 1),
-        (bisect_right, [1, 1], 0, 0),
-        (bisect_right, [1, 1], 1, 2),
-        (bisect_right, [1, 1], 2, 2),
-        (bisect_right, [1, 1, 1], 0, 0),
-        (bisect_right, [1, 1, 1], 1, 3),
-        (bisect_right, [1, 1, 1], 2, 3),
-        (bisect_right, [1, 1, 1, 1], 0, 0),
-        (bisect_right, [1, 1, 1, 1], 1, 4),
-        (bisect_right, [1, 1, 1, 1], 2, 4),
-        (bisect_right, [1, 2], 0, 0),
-        (bisect_right, [1, 2], 1, 1),
-        (bisect_right, [1, 2], 1.5, 1),
-        (bisect_right, [1, 2], 2, 2),
-        (bisect_right, [1, 2], 3, 2),
-        (bisect_right, [1, 1, 2, 2], 0, 0),
-        (bisect_right, [1, 1, 2, 2], 1, 2),
-        (bisect_right, [1, 1, 2, 2], 1.5, 2),
-        (bisect_right, [1, 1, 2, 2], 2, 4),
-        (bisect_right, [1, 1, 2, 2], 3, 4),
-        (bisect_right, [1, 2, 3], 0, 0),
-        (bisect_right, [1, 2, 3], 1, 1),
-        (bisect_right, [1, 2, 3], 1.5, 1),
-        (bisect_right, [1, 2, 3], 2, 2),
-        (bisect_right, [1, 2, 3], 2.5, 2),
-        (bisect_right, [1, 2, 3], 3, 3),
-        (bisect_right, [1, 2, 3], 4, 3),
-        (bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 0, 0),
-        (bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1, 1),
-        (bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1.5, 1),
-        (bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2, 3),
-        (bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2.5, 3),
-        (bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3, 6),
-        (bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3.5, 6),
-        (bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 4, 10),
-        (bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 5, 10),
-
-        (bisect_left, [], 1, 0),
-        (bisect_left, [1], 0, 0),
-        (bisect_left, [1], 1, 0),
-        (bisect_left, [1], 2, 1),
-        (bisect_left, [1, 1], 0, 0),
-        (bisect_left, [1, 1], 1, 0),
-        (bisect_left, [1, 1], 2, 2),
-        (bisect_left, [1, 1, 1], 0, 0),
-        (bisect_left, [1, 1, 1], 1, 0),
-        (bisect_left, [1, 1, 1], 2, 3),
-        (bisect_left, [1, 1, 1, 1], 0, 0),
-        (bisect_left, [1, 1, 1, 1], 1, 0),
-        (bisect_left, [1, 1, 1, 1], 2, 4),
-        (bisect_left, [1, 2], 0, 0),
-        (bisect_left, [1, 2], 1, 0),
-        (bisect_left, [1, 2], 1.5, 1),
-        (bisect_left, [1, 2], 2, 1),
-        (bisect_left, [1, 2], 3, 2),
-        (bisect_left, [1, 1, 2, 2], 0, 0),
-        (bisect_left, [1, 1, 2, 2], 1, 0),
-        (bisect_left, [1, 1, 2, 2], 1.5, 2),
-        (bisect_left, [1, 1, 2, 2], 2, 2),
-        (bisect_left, [1, 1, 2, 2], 3, 4),
-        (bisect_left, [1, 2, 3], 0, 0),
-        (bisect_left, [1, 2, 3], 1, 0),
-        (bisect_left, [1, 2, 3], 1.5, 1),
-        (bisect_left, [1, 2, 3], 2, 1),
-        (bisect_left, [1, 2, 3], 2.5, 2),
-        (bisect_left, [1, 2, 3], 3, 2),
-        (bisect_left, [1, 2, 3], 4, 3),
-        (bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 0, 0),
-        (bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1, 0),
-        (bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1.5, 1),
-        (bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2, 1),
-        (bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2.5, 3),
-        (bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3, 3),
-        (bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3.5, 6),
-        (bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 4, 6),
-        (bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 5, 10)
-    ]
+    def setUp(self):
+        self.precomputedCases = [
+            (self.module.bisect_right, [], 1, 0),
+            (self.module.bisect_right, [1], 0, 0),
+            (self.module.bisect_right, [1], 1, 1),
+            (self.module.bisect_right, [1], 2, 1),
+            (self.module.bisect_right, [1, 1], 0, 0),
+            (self.module.bisect_right, [1, 1], 1, 2),
+            (self.module.bisect_right, [1, 1], 2, 2),
+            (self.module.bisect_right, [1, 1, 1], 0, 0),
+            (self.module.bisect_right, [1, 1, 1], 1, 3),
+            (self.module.bisect_right, [1, 1, 1], 2, 3),
+            (self.module.bisect_right, [1, 1, 1, 1], 0, 0),
+            (self.module.bisect_right, [1, 1, 1, 1], 1, 4),
+            (self.module.bisect_right, [1, 1, 1, 1], 2, 4),
+            (self.module.bisect_right, [1, 2], 0, 0),
+            (self.module.bisect_right, [1, 2], 1, 1),
+            (self.module.bisect_right, [1, 2], 1.5, 1),
+            (self.module.bisect_right, [1, 2], 2, 2),
+            (self.module.bisect_right, [1, 2], 3, 2),
+            (self.module.bisect_right, [1, 1, 2, 2], 0, 0),
+            (self.module.bisect_right, [1, 1, 2, 2], 1, 2),
+            (self.module.bisect_right, [1, 1, 2, 2], 1.5, 2),
+            (self.module.bisect_right, [1, 1, 2, 2], 2, 4),
+            (self.module.bisect_right, [1, 1, 2, 2], 3, 4),
+            (self.module.bisect_right, [1, 2, 3], 0, 0),
+            (self.module.bisect_right, [1, 2, 3], 1, 1),
+            (self.module.bisect_right, [1, 2, 3], 1.5, 1),
+            (self.module.bisect_right, [1, 2, 3], 2, 2),
+            (self.module.bisect_right, [1, 2, 3], 2.5, 2),
+            (self.module.bisect_right, [1, 2, 3], 3, 3),
+            (self.module.bisect_right, [1, 2, 3], 4, 3),
+            (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 0, 0),
+            (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1, 1),
+            (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1.5, 1),
+            (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2, 3),
+            (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2.5, 3),
+            (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3, 6),
+            (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3.5, 6),
+            (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 4, 10),
+            (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 5, 10),
+
+            (self.module.bisect_left, [], 1, 0),
+            (self.module.bisect_left, [1], 0, 0),
+            (self.module.bisect_left, [1], 1, 0),
+            (self.module.bisect_left, [1], 2, 1),
+            (self.module.bisect_left, [1, 1], 0, 0),
+            (self.module.bisect_left, [1, 1], 1, 0),
+            (self.module.bisect_left, [1, 1], 2, 2),
+            (self.module.bisect_left, [1, 1, 1], 0, 0),
+            (self.module.bisect_left, [1, 1, 1], 1, 0),
+            (self.module.bisect_left, [1, 1, 1], 2, 3),
+            (self.module.bisect_left, [1, 1, 1, 1], 0, 0),
+            (self.module.bisect_left, [1, 1, 1, 1], 1, 0),
+            (self.module.bisect_left, [1, 1, 1, 1], 2, 4),
+            (self.module.bisect_left, [1, 2], 0, 0),
+            (self.module.bisect_left, [1, 2], 1, 0),
+            (self.module.bisect_left, [1, 2], 1.5, 1),
+            (self.module.bisect_left, [1, 2], 2, 1),
+            (self.module.bisect_left, [1, 2], 3, 2),
+            (self.module.bisect_left, [1, 1, 2, 2], 0, 0),
+            (self.module.bisect_left, [1, 1, 2, 2], 1, 0),
+            (self.module.bisect_left, [1, 1, 2, 2], 1.5, 2),
+            (self.module.bisect_left, [1, 1, 2, 2], 2, 2),
+            (self.module.bisect_left, [1, 1, 2, 2], 3, 4),
+            (self.module.bisect_left, [1, 2, 3], 0, 0),
+            (self.module.bisect_left, [1, 2, 3], 1, 0),
+            (self.module.bisect_left, [1, 2, 3], 1.5, 1),
+            (self.module.bisect_left, [1, 2, 3], 2, 1),
+            (self.module.bisect_left, [1, 2, 3], 2.5, 2),
+            (self.module.bisect_left, [1, 2, 3], 3, 2),
+            (self.module.bisect_left, [1, 2, 3], 4, 3),
+            (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 0, 0),
+            (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1, 0),
+            (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1.5, 1),
+            (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2, 1),
+            (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2.5, 3),
+            (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3, 3),
+            (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3.5, 6),
+            (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 4, 6),
+            (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 5, 10)
+        ]
 
     def test_precomputed(self):
         for func, data, elem, expected in self.precomputedCases:
@@ -98,12 +120,12 @@
             data = [randrange(0, n, 2) for j in range(i)]
             data.sort()
             elem = randrange(-1, n+1)
-            ip = bisect_left(data, elem)
+            ip = self.module.bisect_left(data, elem)
             if ip < len(data):
                 self.failUnless(elem <= data[ip])
             if ip > 0:
                 self.failUnless(data[ip-1] < elem)
-            ip = bisect_right(data, elem)
+            ip = self.module.bisect_right(data, elem)
             if ip < len(data):
                 self.failUnless(elem < data[ip])
             if ip > 0:
@@ -117,32 +139,39 @@
                     hi = min(len(data), hi)
                     ip = func(data, elem, lo, hi)
                     self.failUnless(lo <= ip <= hi)
-                    if func is bisect_left and ip < hi:
+                    if func is self.module.bisect_left and ip < hi:
                         self.failUnless(elem <= data[ip])
-                    if func is bisect_left and ip > lo:
+                    if func is self.module.bisect_left and ip > lo:
                         self.failUnless(data[ip-1] < elem)
-                    if func is bisect_right and ip < hi:
+                    if func is self.module.bisect_right and ip < hi:
                         self.failUnless(elem < data[ip])
-                    if func is bisect_right and ip > lo:
+                    if func is self.module.bisect_right and ip > lo:
                         self.failUnless(data[ip-1] <= elem)
                     self.assertEqual(ip, max(lo, min(hi, expected)))
 
     def test_backcompatibility(self):
-        self.assertEqual(bisect, bisect_right)
+        self.assertEqual(self.module.bisect, self.module.bisect_right)
 
     def test_keyword_args(self):
         data = [10, 20, 30, 40, 50]
-        self.assertEqual(bisect_left(a=data, x=25, lo=1, hi=3), 2)
-        self.assertEqual(bisect_right(a=data, x=25, lo=1, hi=3), 2)
-        self.assertEqual(bisect(a=data, x=25, lo=1, hi=3), 2)
-        insort_left(a=data, x=25, lo=1, hi=3)
-        insort_right(a=data, x=25, lo=1, hi=3)
-        insort(a=data, x=25, lo=1, hi=3)
+        self.assertEqual(self.module.bisect_left(a=data, x=25, lo=1, hi=3), 2)
+        self.assertEqual(self.module.bisect_right(a=data, x=25, lo=1, hi=3), 2)
+        self.assertEqual(self.module.bisect(a=data, x=25, lo=1, hi=3), 2)
+        self.module.insort_left(a=data, x=25, lo=1, hi=3)
+        self.module.insort_right(a=data, x=25, lo=1, hi=3)
+        self.module.insort(a=data, x=25, lo=1, hi=3)
         self.assertEqual(data, [10, 20, 25, 25, 25, 30, 40, 50])
 
+class TestBisectPython(TestBisect):
+    module = py_bisect
+
+class TestBisectC(TestBisect):
+    module = c_bisect
+
 #==============================================================================
 
 class TestInsort(unittest.TestCase):
+    module = None
 
     def test_vsBuiltinSort(self, n=500):
         from random import choice
@@ -150,14 +179,20 @@
             for i in range(n):
                 digit = choice("0123456789")
                 if digit in "02468":
-                    f = insort_left
+                    f = self.module.insort_left
                 else:
-                    f = insort_right
+                    f = self.module.insort_right
                 f(insorted, digit)
         self.assertEqual(sorted(insorted), insorted)
 
     def test_backcompatibility(self):
-        self.assertEqual(insort, insort_right)
+        self.assertEqual(self.module.insort, self.module.insort_right)
+
+class TestInsortPython(TestInsort):
+    module = py_bisect
+
+class TestInsortC(TestInsort):
+    module = c_bisect
 
 #==============================================================================
 
@@ -183,32 +218,44 @@
     __ne__ = __lt__
 
 class TestErrorHandling(unittest.TestCase):
+    module = None
 
     def test_non_sequence(self):
-        for f in (bisect_left, bisect_right, insort_left, insort_right):
+        for f in (self.module.bisect_left, self.module.bisect_right,
+                  self.module.insort_left, self.module.insort_right):
             self.assertRaises(TypeError, f, 10, 10)
 
     def test_len_only(self):
-        for f in (bisect_left, bisect_right, insort_left, insort_right):
+        for f in (self.module.bisect_left, self.module.bisect_right,
+                  self.module.insort_left, self.module.insort_right):
             self.assertRaises(TypeError, f, LenOnly(), 10)
 
     def test_get_only(self):
-        for f in (bisect_left, bisect_right, insort_left, insort_right):
+        for f in (self.module.bisect_left, self.module.bisect_right,
+                  self.module.insort_left, self.module.insort_right):
             self.assertRaises(TypeError, f, GetOnly(), 10)
 
     def test_cmp_err(self):
         seq = [CmpErr(), CmpErr(), CmpErr()]
-        for f in (bisect_left, bisect_right, insort_left, insort_right):
+        for f in (self.module.bisect_left, self.module.bisect_right,
+                  self.module.insort_left, self.module.insort_right):
             self.assertRaises(ZeroDivisionError, f, seq, 10)
 
     def test_arg_parsing(self):
-        for f in (bisect_left, bisect_right, insort_left, insort_right):
+        for f in (self.module.bisect_left, self.module.bisect_right,
+                  self.module.insort_left, self.module.insort_right):
             self.assertRaises(TypeError, f, 10)
 
+class TestErrorHandlingPython(TestErrorHandling):
+    module = py_bisect
+
+class TestErrorHandlingC(TestErrorHandling):
+    module = c_bisect
+
 #==============================================================================
 
 libreftest = """
-Example from the Library Reference:  Doc/lib/libbisect.tex
+Example from the Library Reference:  Doc/library/bisect.rst
 
 The bisect() function is generally useful for categorizing numeric data.
 This example uses bisect() to look up a letter grade for an exam total
@@ -234,12 +281,10 @@
 
 def test_main(verbose=None):
     from test import test_bisect
-    from types import BuiltinFunctionType
-    import sys
 
-    test_classes = [TestBisect, TestInsort]
-    if isinstance(bisect_left, BuiltinFunctionType):
-        test_classes.append(TestErrorHandling)
+    test_classes = [TestBisectPython, TestBisectC,
+                    TestInsortPython, TestInsortC,
+                    TestErrorHandlingPython, TestErrorHandlingC]
 
     test_support.run_unittest(*test_classes)
     test_support.run_doctest(test_bisect, verbose)

Modified: python/branches/py3k-importlib/Lib/test/test_bsddb3.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_bsddb3.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_bsddb3.py	Thu Mar 27 00:48:05 2008
@@ -2,10 +2,12 @@
 """
 Run all test cases.
 """
+import os
 import sys
+import tempfile
+import time
 import unittest
-import test.test_support
-from test.test_support import requires, run_unittest, unlink
+from test.test_support import requires, verbose, run_unittest, unlink, rmtree
 
 # When running as a script instead of within the regrtest framework, skip the
 # requires test, since it's obvious we want to run them.
@@ -22,6 +24,30 @@
     sys.argv.remove('silent')
 
 
+class TimingCheck(unittest.TestCase):
+
+    """This class is not a real test.  Its purpose is to print a message
+    periodically when the test runs slowly.  This will prevent the buildbots
+    from timing out on slow machines."""
+
+    # How much time in seconds before printing a 'Still working' message.
+    # Since this is run at most once between each test module, use a smaller
+    # interval than other tests.
+    _PRINT_WORKING_MSG_INTERVAL = 4 * 60
+
+    # next_time is used as a global variable that survives each instance.
+    # This is necessary since a new instance will be created for each test.
+    next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
+
+    def testCheckElapsedTime(self):
+        # Print still working message since these tests can be really slow.
+        now = time.time()
+        if self.next_time <= now:
+            TimingCheck.next_time = now + self._PRINT_WORKING_MSG_INTERVAL
+            sys.__stdout__.write('  test_bsddb3 still working, be patient...\n')
+            sys.__stdout__.flush()
+
+
 def suite():
     try:
         # this is special, it used to segfault the interpreter
@@ -56,12 +82,22 @@
         module = __import__("bsddb.test."+name, globals(), locals(), name)
         #print module,name
         alltests.addTest(module.test_suite())
+        alltests.addTest(unittest.makeSuite(TimingCheck))
     return alltests
 
 
 # For invocation through regrtest
 def test_main():
     run_unittest(suite())
+    db_home = os.path.join(tempfile.gettempdir(), 'db_home')
+    # The only reason to remove db_home is in case if there is an old
+    # one lying around.  This might be by a different user, so just
+    # ignore errors.  We should always make a unique name now.
+    try:
+        rmtree(db_home)
+    except:
+        pass
+    rmtree('db_home%d' % os.getpid())
 
 # For invocation as a script
 if __name__ == '__main__':

Modified: python/branches/py3k-importlib/Lib/test/test_bufio.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_bufio.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_bufio.py	Thu Mar 27 00:48:05 2008
@@ -13,6 +13,9 @@
         # Write s + "\n" + s to file, then open it and ensure that successive
         # .readline()s deliver what we wrote.
 
+        # Ensure we can open TESTFN for writing.
+        test_support.unlink(test_support.TESTFN)
+
         # Since C doesn't guarantee we can write/read arbitrary bytes in text
         # files, use binary mode.
         f = open(test_support.TESTFN, "wb")
@@ -31,11 +34,7 @@
             self.assert_(not line) # Must be at EOF
             f.close()
         finally:
-            try:
-                import os
-                os.unlink(test_support.TESTFN)
-            except:
-                pass
+            test_support.unlink(test_support.TESTFN)
 
     def drive_one(self, pattern):
         for length in lengths:

Modified: python/branches/py3k-importlib/Lib/test/test_builtin.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_builtin.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_builtin.py	Thu Mar 27 00:48:05 2008
@@ -5,7 +5,7 @@
                               run_with_locale
 from operator import neg
 
-import sys, warnings, random, UserDict, io
+import sys, warnings, random, collections, io, fractions
 warnings.filterwarnings("ignore", "hex../oct.. of negative int",
                         FutureWarning, __name__)
 warnings.filterwarnings("ignore", "integer argument expected",
@@ -49,7 +49,7 @@
     def write(self, line):
         pass
 
-L = [
+test_conv_no_sign = [
         ('0', 0),
         ('1', 1),
         ('9', 9),
@@ -60,7 +60,7 @@
         (' 314', 314),
         ('314 ', 314),
         ('  \t\t  314  \t\t  ', 314),
-        (repr(sys.maxint), sys.maxint),
+        (repr(sys.maxsize), sys.maxsize),
         ('  1x', ValueError),
         ('  1  ', 1),
         ('  1\02  ', ValueError),
@@ -71,6 +71,28 @@
         (chr(0x200), ValueError),
 ]
 
+test_conv_sign = [
+        ('0', 0),
+        ('1', 1),
+        ('9', 9),
+        ('10', 10),
+        ('99', 99),
+        ('100', 100),
+        ('314', 314),
+        (' 314', ValueError),
+        ('314 ', 314),
+        ('  \t\t  314  \t\t  ', ValueError),
+        (repr(sys.maxsize), sys.maxsize),
+        ('  1x', ValueError),
+        ('  1  ', ValueError),
+        ('  1\02  ', ValueError),
+        ('', ValueError),
+        (' ', ValueError),
+        ('  \t\t  ', ValueError),
+        (str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
+        (chr(0x200), ValueError),
+]
+
 class TestFailingBool:
     def __bool__(self):
         raise RuntimeError
@@ -97,7 +119,7 @@
         self.assertEqual(abs(0), 0)
         self.assertEqual(abs(1234), 1234)
         self.assertEqual(abs(-1234), 1234)
-        self.assertTrue(abs(-sys.maxint-1) > 0)
+        self.assertTrue(abs(-sys.maxsize-1) > 0)
         # float
         self.assertEqual(abs(0.0), 0.0)
         self.assertEqual(abs(3.14), 3.14)
@@ -138,9 +160,9 @@
         self.assertEqual(any(x > 42 for x in S), False)
 
     def test_neg(self):
-        x = -sys.maxint-1
+        x = -sys.maxsize-1
         self.assert_(isinstance(x, int))
-        self.assertEqual(-x, sys.maxint+1)
+        self.assertEqual(-x, sys.maxsize+1)
 
     # XXX(nnorwitz): This test case for callable should probably be removed.
     def test_callable(self):
@@ -188,7 +210,7 @@
         # verify that circular objects are not handled
         a = []; a.append(a)
         b = []; b.append(b)
-        from UserList import UserList
+        from collections import UserList
         c = UserList(); c.append(c)
         self.assertRaises(RuntimeError, cmp, a, b)
         self.assertRaises(RuntimeError, cmp, b, c)
@@ -200,8 +222,8 @@
 
     def test_compile(self):
         compile('print(1)\n', '', 'exec')
-##         bom = b'\xef\xbb\xbf'
-##         compile(bom + b'print(1)\n', '', 'exec')
+        bom = b'\xef\xbb\xbf'
+        compile(bom + b'print(1)\n', '', 'exec')
         compile(source='pass', filename='?', mode='exec')
         compile(dont_inherit=0, filename='tmp', source='0', mode='eval')
         compile('pass', '?', dont_inherit=1, mode='exec')
@@ -306,8 +328,8 @@
         self.assertEqual(divmod(12, -7), (-2, -2))
         self.assertEqual(divmod(-12, -7), (1, -5))
 
-        self.assertEqual(divmod(-sys.maxint-1, -1),
-                         (sys.maxint+1, 0))
+        self.assertEqual(divmod(-sys.maxsize-1, -1),
+                         (sys.maxsize+1, 0))
 
         self.assert_(not fcmp(divmod(3.25, 1.0), (3.0, 0.25)))
         self.assert_(not fcmp(divmod(-3.25, 1.0), (-4.0, 0.75)))
@@ -327,11 +349,12 @@
         self.assertEqual(eval('c', globals, locals), 300)
         globals = {'a': 1, 'b': 2}
         locals = {'b': 200, 'c': 300}
-##         bom = b'\xef\xbb\xbf'
-##         self.assertEqual(eval(bom + b'a', globals, locals), 1)
+        bom = b'\xef\xbb\xbf'
+        self.assertEqual(eval(bom + b'a', globals, locals), 1)
         self.assertEqual(eval('"\xe5"', globals), "\xe5")
         self.assertRaises(TypeError, eval)
         self.assertRaises(TypeError, eval, ())
+        self.assertRaises(SyntaxError, eval, bom[:2] + b'a')
 
     def test_general_eval(self):
         # Tests that general mappings can be used for the locals argument
@@ -377,7 +400,7 @@
 
         # Verify locals stores (used by list comps)
         eval('[locals() for i in (2,3)]', g, d)
-        eval('[locals() for i in (2,3)]', g, UserDict.UserDict())
+        eval('[locals() for i in (2,3)]', g, collections.UserDict())
 
         class SpreadSheet:
             "Sample application showing nested, calculated lookups."
@@ -518,24 +541,58 @@
         self.assertRaises(TypeError, float, Foo4(42))
 
     def test_format(self):
-        class A:
-            def __init__(self, x):
-                self.x = x
-            def __format__(self, format_spec):
-                return str(self.x) + format_spec
+        # Test the basic machinery of the format() builtin.  Don't test
+        #  the specifics of the various formatters
+        self.assertEqual(format(3, ''), '3')
 
-        # class that returns a bad type from __format__
-        class B:
-            def __format__(self, format_spec):
-                return 1.0
+        # Returns some classes to use for various tests.  There's
+        #  an old-style version, and a new-style version
+        def classes_new():
+            class A(object):
+                def __init__(self, x):
+                    self.x = x
+                def __format__(self, format_spec):
+                    return str(self.x) + format_spec
+            class DerivedFromA(A):
+                pass
 
-        # class that is derived from string, used
-        #  as a format spec
-        class C(str):
-            pass
+            class Simple(object): pass
+            class DerivedFromSimple(Simple):
+                def __init__(self, x):
+                    self.x = x
+                def __format__(self, format_spec):
+                    return str(self.x) + format_spec
+            class DerivedFromSimple2(DerivedFromSimple): pass
+            return A, DerivedFromA, DerivedFromSimple, DerivedFromSimple2
+
+        # In 3.0, classes_classic has the same meaning as classes_new
+        def classes_classic():
+            class A:
+                def __init__(self, x):
+                    self.x = x
+                def __format__(self, format_spec):
+                    return str(self.x) + format_spec
+            class DerivedFromA(A):
+                pass
 
-        self.assertEqual(format(3, ''), '3')
-        self.assertEqual(format(A(3), 'spec'), '3spec')
+            class Simple: pass
+            class DerivedFromSimple(Simple):
+                def __init__(self, x):
+                    self.x = x
+                def __format__(self, format_spec):
+                    return str(self.x) + format_spec
+            class DerivedFromSimple2(DerivedFromSimple): pass
+            return A, DerivedFromA, DerivedFromSimple, DerivedFromSimple2
+
+        def class_test(A, DerivedFromA, DerivedFromSimple, DerivedFromSimple2):
+            self.assertEqual(format(A(3), 'spec'), '3spec')
+            self.assertEqual(format(DerivedFromA(4), 'spec'), '4spec')
+            self.assertEqual(format(DerivedFromSimple(5), 'abc'), '5abc')
+            self.assertEqual(format(DerivedFromSimple2(10), 'abcdef'),
+                             '10abcdef')
+
+        class_test(*classes_new())
+        class_test(*classes_classic())
 
         def empty_format_spec(value):
             # test that:
@@ -555,10 +612,61 @@
         empty_format_spec(None)
 
         # TypeError because self.__format__ returns the wrong type
-        self.assertRaises(TypeError, format, B(), "")
+        class BadFormatResult:
+            def __format__(self, format_spec):
+                return 1.0
+        self.assertRaises(TypeError, format, BadFormatResult(), "")
+
+        # TypeError because format_spec is not unicode or str
+        self.assertRaises(TypeError, format, object(), 4)
+        self.assertRaises(TypeError, format, object(), object())
+
+        # tests for object.__format__ really belong elsewhere, but
+        #  there's no good place to put them
+        x = object().__format__('')
+        self.assert_(x.startswith('<object object at'))
+
+        # first argument to object.__format__ must be string
+        self.assertRaises(TypeError, object().__format__, 3)
+        self.assertRaises(TypeError, object().__format__, object())
+        self.assertRaises(TypeError, object().__format__, None)
 
         # make sure we can take a subclass of str as a format spec
-        self.assertEqual(format(0, C('10')), '         0')
+        class DerivedFromStr(str): pass
+        self.assertEqual(format(0, DerivedFromStr('10')), '         0')
+
+    def test_floatasratio(self):
+        for f, ratio in [
+                (0.875, (7, 8)),
+                (-0.875, (-7, 8)),
+                (0.0, (0, 1)),
+                (11.5, (23, 2)),
+            ]:
+            self.assertEqual(f.as_integer_ratio(), ratio)
+
+        for i in range(10000):
+            f = random.random()
+            f *= 10 ** random.randint(-100, 100)
+            n, d = f.as_integer_ratio()
+            self.assertEqual(float(n).__truediv__(d), f)
+
+        R = fractions.Fraction
+        self.assertEqual(R(0, 1),
+                         R(*float(0.0).as_integer_ratio()))
+        self.assertEqual(R(5, 2),
+                         R(*float(2.5).as_integer_ratio()))
+        self.assertEqual(R(1, 2),
+                         R(*float(0.5).as_integer_ratio()))
+        self.assertEqual(R(4728779608739021, 2251799813685248),
+                         R(*float(2.1).as_integer_ratio()))
+        self.assertEqual(R(-4728779608739021, 2251799813685248),
+                         R(*float(-2.1).as_integer_ratio()))
+        self.assertEqual(R(-2100, 1),
+                         R(*float(-2100.0).as_integer_ratio()))
+
+        self.assertRaises(OverflowError, float('inf').as_integer_ratio)
+        self.assertRaises(OverflowError, float('-inf').as_integer_ratio)
+        self.assertRaises(ValueError, float('nan').as_integer_ratio)
 
     def test_getattr(self):
         import sys
@@ -580,7 +688,7 @@
         self.assertEqual(hash(1), hash(1))
         self.assertEqual(hash(1), hash(1.0))
         hash('spam')
-        self.assertEqual(hash('spam'), hash(str8('spam')))
+        self.assertEqual(hash('spam'), hash(b'spam'))
         hash((0,1,2,3))
         def f(): pass
         self.assertRaises(TypeError, hash, [])
@@ -631,8 +739,18 @@
         # Different base:
         self.assertEqual(int("10",16), 16)
         # Test conversion from strings and various anomalies
-        for s, v in L:
-            for sign in "", "+", "-":
+        # Testing with no sign at front
+        for s, v in test_conv_no_sign:
+            for prefix in "", " ", "\t", "  \t\t  ":
+                ss = prefix + s
+                vv = v
+                try:
+                    self.assertEqual(int(ss), vv)
+                except v:
+                    pass
+        # No whitespaces allowed between + or - sign and the number
+        for s, v in test_conv_sign:
+            for sign in "+", "-":
                 for prefix in "", " ", "\t", "  \t\t  ":
                     ss = prefix + sign + s
                     vv = v
@@ -643,12 +761,12 @@
                     except v:
                         pass
 
-        s = repr(-1-sys.maxint)
+        s = repr(-1-sys.maxsize)
         x = int(s)
-        self.assertEqual(x+1, -sys.maxint)
+        self.assertEqual(x+1, -sys.maxsize)
         self.assert_(isinstance(x, int))
         # should return long
-        self.assertEqual(int(s[1:]), sys.maxint+1)
+        self.assertEqual(int(s[1:]), sys.maxsize+1)
 
         # should return long
         x = int(1e100)
@@ -660,7 +778,7 @@
         # SF bug 434186:  0x80000000/2 != 0x80000000>>1.
         # Worked by accident in Windows release build, but failed in debug build.
         # Failed in all Linux builds.
-        x = -1-sys.maxint
+        x = -1-sys.maxsize
         self.assertEqual(x >> 1, x//2)
 
         self.assertRaises(ValueError, int, '123\0')
@@ -701,6 +819,11 @@
         self.assertEqual(int('0O123', 8), 83)
         self.assertEqual(int('0B100', 2), 4)
 
+        # Bug 1679: "0x" is not a valid hex literal
+        self.assertRaises(ValueError, int, "0x", 16)
+        self.assertRaises(ValueError, int, "0x", 0)
+
+
         # SF bug 1334662: int(string, base) wrong answers
         # Various representations of 2**32 evaluated to 0
         # rather than 2**32 in previous versions
@@ -781,6 +904,14 @@
 
     def test_intconversion(self):
         # Test __int__()
+        class ClassicMissingMethods:
+            pass
+        self.assertRaises(TypeError, int, ClassicMissingMethods())
+
+        class MissingMethods(object):
+            pass
+        self.assertRaises(TypeError, int, MissingMethods())
+
         class Foo0:
             def __int__(self):
                 return 42
@@ -812,6 +943,49 @@
         self.assertEqual(int(Foo4()), 42)
         self.assertRaises(TypeError, int, Foo5())
 
+        class Classic:
+            pass
+        for base in (object, Classic):
+            class IntOverridesTrunc(base):
+                def __int__(self):
+                    return 42
+                def __trunc__(self):
+                    return -12
+            self.assertEqual(int(IntOverridesTrunc()), 42)
+
+            class JustTrunc(base):
+                def __trunc__(self):
+                    return 42
+            self.assertEqual(int(JustTrunc()), 42)
+
+            for trunc_result_base in (object, Classic):
+                class Integral(trunc_result_base):
+                    def __int__(self):
+                        return 42
+
+                class TruncReturnsNonInt(base):
+                    def __trunc__(self):
+                        return Integral()
+                self.assertEqual(int(TruncReturnsNonInt()), 42)
+
+                class NonIntegral(trunc_result_base):
+                    def __trunc__(self):
+                        # Check that we avoid infinite recursion.
+                        return NonIntegral()
+
+                class TruncReturnsNonIntegral(base):
+                    def __trunc__(self):
+                        return NonIntegral()
+                try:
+                    int(TruncReturnsNonIntegral())
+                except TypeError as e:
+                    self.assertEquals(str(e),
+                                      "__trunc__ returned non-Integral"
+                                      " (type NonIntegral)")
+                else:
+                    self.fail("Failed to raise TypeError with %s" %
+                              ((base, trunc_result_base),))
+
     def test_iter(self):
         self.assertRaises(TypeError, iter)
         self.assertRaises(TypeError, iter, 42, 42)
@@ -880,12 +1054,12 @@
         self.assertEqual(list(''), [])
         self.assertEqual(list('spam'), ['s', 'p', 'a', 'm'])
 
-        if sys.maxint == 0x7fffffff:
+        if sys.maxsize == 0x7fffffff:
             # This test can currently only work on 32-bit machines.
             # XXX If/when PySequence_Length() returns a ssize_t, it should be
             # XXX re-enabled.
             # Verify clearing of bug #556025.
-            # This assumes that the max data size (sys.maxint) == max
+            # This assumes that the max data size (sys.maxsize) == max
             # address size this also assumes that the address size is at
             # least 4 bytes with 8 byte addresses, the bug is not well
             # tested
@@ -895,7 +1069,7 @@
             # thread for the details:
 
             #     http://sources.redhat.com/ml/newlib/2002/msg00369.html
-            self.assertRaises(MemoryError, list, range(sys.maxint // 2))
+            self.assertRaises(MemoryError, list, range(sys.maxsize // 2))
 
         # This code used to segfault in Py2.4a3
         x = []
@@ -1015,7 +1189,6 @@
         self.assertEqual(int('2br45qc', 35), 4294967297)
         self.assertEqual(int('1z141z5', 36), 4294967297)
 
-
     def test_longconversion(self):
         # Test __long__()
         class Foo0:
@@ -1053,18 +1226,6 @@
 
     def test_map(self):
         self.assertEqual(
-            list(map(None, 'hello')),
-            [('h',), ('e',), ('l',), ('l',), ('o',)]
-        )
-        self.assertEqual(
-            list(map(None, 'abcd', 'efg')),
-            [('a', 'e'), ('b', 'f'), ('c', 'g')]
-        )
-        self.assertEqual(
-            list(map(None, range(3))),
-            [(0,), (1,), (2,)]
-        )
-        self.assertEqual(
             list(map(lambda x: x*x, range(1,4))),
             [1, 4, 9]
         )
@@ -1099,17 +1260,9 @@
             [1+4+1, 3+9+1, 7+2+0]
         )
         self.assertEqual(
-            list(map(None, Squares(10))),
-            [(0,), (1,), (4,), (9,), (16,), (25,), (36,), (49,), (64,), (81,)]
-        )
-        self.assertEqual(
             list(map(int, Squares(10))),
             [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
         )
-        self.assertEqual(
-            list(map(None, Squares(3), Squares(2))),
-            [(0,0), (1,1)]
-        )
         def Max(a, b):
             if a is None:
                 return b
@@ -1122,7 +1275,6 @@
         )
         self.assertRaises(TypeError, map)
         self.assertRaises(TypeError, map, lambda x: x, 42)
-        self.assertEqual(list(map(None, [42])), [(42,)])
         class BadSeq:
             def __iter__(self):
                 raise ValueError
@@ -1383,9 +1535,9 @@
         self.assertEqual(list(range(0, 2**100, -1)), [])
         self.assertEqual(list(range(0, 2**100, -1)), [])
 
-        a = int(10 * sys.maxint)
-        b = int(100 * sys.maxint)
-        c = int(50 * sys.maxint)
+        a = int(10 * sys.maxsize)
+        b = int(100 * sys.maxsize)
+        c = int(50 * sys.maxsize)
 
         self.assertEqual(list(range(a, a+2)), [a, a+1])
         self.assertEqual(list(range(a+2, a, -1)), [a+2, a+1])
@@ -1427,10 +1579,10 @@
         self.assertRaises(TypeError, range, 0, "spam")
         self.assertRaises(TypeError, range, 0, 42, "spam")
 
-        #NEAL self.assertRaises(OverflowError, range, -sys.maxint, sys.maxint)
-        #NEAL self.assertRaises(OverflowError, range, 0, 2*sys.maxint)
+        #NEAL self.assertRaises(OverflowError, range, -sys.maxsize, sys.maxsize)
+        #NEAL self.assertRaises(OverflowError, range, 0, 2*sys.maxsize)
 
-        self.assertRaises(OverflowError, len, range(0, sys.maxint**10))
+        self.assertRaises(OverflowError, len, range(0, sys.maxsize**10))
 
     def test_input(self):
         self.write_testfile()
@@ -1598,37 +1750,6 @@
                 raise ValueError
         self.assertRaises(ValueError, sum, BadSeq())
 
-    def test_trunc(self):
-
-        self.assertEqual(trunc(1), 1)
-        self.assertEqual(trunc(-1), -1)
-        self.assertEqual(type(trunc(1)), int)
-        self.assertEqual(type(trunc(1.5)), int)
-        self.assertEqual(trunc(1.5), 1)
-        self.assertEqual(trunc(-1.5), -1)
-        self.assertEqual(trunc(1.999999), 1)
-        self.assertEqual(trunc(-1.999999), -1)
-        self.assertEqual(trunc(-0.999999), -0)
-        self.assertEqual(trunc(-100.999), -100)
-
-        class TestTrunc:
-            def __trunc__(self):
-                return 23
-
-        class TestNoTrunc:
-            pass
-
-        self.assertEqual(trunc(TestTrunc()), 23)
-
-        self.assertRaises(TypeError, trunc)
-        self.assertRaises(TypeError, trunc, 1, 2)
-        self.assertRaises(TypeError, trunc, TestNoTrunc())
-
-        t = TestNoTrunc()
-        t.__trunc__ = lambda *args: args
-        self.assertRaises(TypeError, trunc, t)
-        self.assertRaises(TypeError, trunc, t, 0)
-
     def test_tuple(self):
         self.assertEqual(tuple(()), ())
         t0_3 = (0, 1, 2, 3)
@@ -1708,6 +1829,15 @@
                     return i
         self.assertRaises(ValueError, list, zip(BadSeq(), BadSeq()))
 
+    def test_bin(self):
+        self.assertEqual(bin(0), '0b0')
+        self.assertEqual(bin(1), '0b1')
+        self.assertEqual(bin(-1), '-0b1')
+        self.assertEqual(bin(2**65), '0b1' + '0' * 65)
+        self.assertEqual(bin(2**65-1), '0b' + '1' * 65)
+        self.assertEqual(bin(-(2**65)), '-0b1' + '0' * 65)
+        self.assertEqual(bin(-(2**65-1)), '-0b' + '1' * 65)
+
 class TestSorted(unittest.TestCase):
 
     def test_basic(self):
@@ -1719,9 +1849,6 @@
 
         data.reverse()
         random.shuffle(copy)
-        self.assertEqual(data, sorted(copy, cmp=lambda x, y: (x < y) - (x > y)))
-        self.assertNotEqual(data, copy)
-        random.shuffle(copy)
         self.assertEqual(data, sorted(copy, key=lambda x: -x))
         self.assertNotEqual(data, copy)
         random.shuffle(copy)

Modified: python/branches/py3k-importlib/Lib/test/test_bytes.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_bytes.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_bytes.py	Thu Mar 27 00:48:05 2008
@@ -1,40 +1,54 @@
-"""Unit tests for the bytes type."""
+"""Unit tests for the bytes and bytearray types.
+
+XXX This is a mess.  Common tests should be moved to buffer_tests.py,
+which itself ought to be unified with string_tests.py (and the latter
+should be modernized).
+"""
 
 import os
 import re
 import sys
+import copy
 import pickle
 import tempfile
 import unittest
+import warnings
 import test.test_support
 import test.string_tests
+import test.buffer_tests
+
 
+class BaseBytesTest(unittest.TestCase):
 
-class BytesTest(unittest.TestCase):
+    def setUp(self):
+        self.warning_filters = warnings.filters[:]
+
+    def tearDown(self):
+        warnings.filters = self.warning_filters
 
     def test_basics(self):
-        b = bytes()
-        self.assertEqual(type(b), bytes)
-        self.assertEqual(b.__class__, bytes)
+        b = self.type2test()
+        self.assertEqual(type(b), self.type2test)
+        self.assertEqual(b.__class__, self.type2test)
 
     def test_empty_sequence(self):
-        b = bytes()
+        b = self.type2test()
         self.assertEqual(len(b), 0)
         self.assertRaises(IndexError, lambda: b[0])
         self.assertRaises(IndexError, lambda: b[1])
-        self.assertRaises(IndexError, lambda: b[sys.maxint])
-        self.assertRaises(IndexError, lambda: b[sys.maxint+1])
+        self.assertRaises(IndexError, lambda: b[sys.maxsize])
+        self.assertRaises(IndexError, lambda: b[sys.maxsize+1])
         self.assertRaises(IndexError, lambda: b[10**100])
         self.assertRaises(IndexError, lambda: b[-1])
         self.assertRaises(IndexError, lambda: b[-2])
-        self.assertRaises(IndexError, lambda: b[-sys.maxint])
-        self.assertRaises(IndexError, lambda: b[-sys.maxint-1])
-        self.assertRaises(IndexError, lambda: b[-sys.maxint-2])
+        self.assertRaises(IndexError, lambda: b[-sys.maxsize])
+        self.assertRaises(IndexError, lambda: b[-sys.maxsize-1])
+        self.assertRaises(IndexError, lambda: b[-sys.maxsize-2])
         self.assertRaises(IndexError, lambda: b[-10**100])
 
     def test_from_list(self):
         ints = list(range(256))
-        b = bytes(i for i in ints)
+        b = self.type2test(i for i in ints)
         self.assertEqual(len(b), 256)
         self.assertEqual(list(b), ints)
 
@@ -44,44 +58,45 @@
                 self.i = i
             def __index__(self):
                 return self.i
-        b = bytes([C(), C(1), C(254), C(255)])
+        b = self.type2test([C(), C(1), C(254), C(255)])
         self.assertEqual(list(b), [0, 1, 254, 255])
-        self.assertRaises(ValueError, bytes, [C(-1)])
-        self.assertRaises(ValueError, bytes, [C(256)])
+        self.assertRaises(ValueError, bytearray, [C(-1)])
+        self.assertRaises(ValueError, bytearray, [C(256)])
+
+    def test_from_ssize(self):
+        self.assertEqual(bytearray(0), b'')
+        self.assertEqual(bytearray(1), b'\x00')
+        self.assertEqual(bytearray(5), b'\x00\x00\x00\x00\x00')
+        self.assertRaises(ValueError, bytearray, -1)
+
+        self.assertEqual(bytearray('0', 'ascii'), b'0')
+        self.assertEqual(bytearray(b'0'), b'0')
 
     def test_constructor_type_errors(self):
-        self.assertRaises(TypeError, bytes, 0.0)
+        self.assertRaises(TypeError, self.type2test, 0.0)
         class C:
             pass
-        self.assertRaises(TypeError, bytes, ["0"])
-        self.assertRaises(TypeError, bytes, [0.0])
-        self.assertRaises(TypeError, bytes, [None])
-        self.assertRaises(TypeError, bytes, [C()])
+        self.assertRaises(TypeError, self.type2test, ["0"])
+        self.assertRaises(TypeError, self.type2test, [0.0])
+        self.assertRaises(TypeError, self.type2test, [None])
+        self.assertRaises(TypeError, self.type2test, [C()])
 
     def test_constructor_value_errors(self):
-        self.assertRaises(ValueError, bytes, [-1])
-        self.assertRaises(ValueError, bytes, [-sys.maxint])
-        self.assertRaises(ValueError, bytes, [-sys.maxint-1])
-        self.assertRaises(ValueError, bytes, [-sys.maxint-2])
-        self.assertRaises(ValueError, bytes, [-10**100])
-        self.assertRaises(ValueError, bytes, [256])
-        self.assertRaises(ValueError, bytes, [257])
-        self.assertRaises(ValueError, bytes, [sys.maxint])
-        self.assertRaises(ValueError, bytes, [sys.maxint+1])
-        self.assertRaises(ValueError, bytes, [10**100])
-
-    def test_repr(self):
-        self.assertEqual(repr(bytes()), "b''")
-        self.assertEqual(repr(bytes([0])), "b'\\x00'")
-        self.assertEqual(repr(bytes([0, 1, 254, 255])),
-                         "b'\\x00\\x01\\xfe\\xff'")
-        self.assertEqual(repr(b"abc"), "b'abc'")
-        self.assertEqual(repr(b"'"), "b'\\''")
+        self.assertRaises(ValueError, self.type2test, [-1])
+        self.assertRaises(ValueError, self.type2test, [-sys.maxsize])
+        self.assertRaises(ValueError, self.type2test, [-sys.maxsize-1])
+        self.assertRaises(ValueError, self.type2test, [-sys.maxsize-2])
+        self.assertRaises(ValueError, self.type2test, [-10**100])
+        self.assertRaises(ValueError, self.type2test, [256])
+        self.assertRaises(ValueError, self.type2test, [257])
+        self.assertRaises(ValueError, self.type2test, [sys.maxsize])
+        self.assertRaises(ValueError, self.type2test, [sys.maxsize+1])
+        self.assertRaises(ValueError, self.type2test, [10**100])
 
     def test_compare(self):
-        b1 = bytes([1, 2, 3])
-        b2 = bytes([1, 2, 3])
-        b3 = bytes([1, 3])
+        b1 = self.type2test([1, 2, 3])
+        b2 = self.type2test([1, 2, 3])
+        b3 = self.type2test([1, 3])
 
         self.assertEqual(b1, b2)
         self.failUnless(b2 != b3)
@@ -102,97 +117,26 @@
         self.failIf(b3 <= b2)
 
     def test_compare_to_str(self):
-        self.assertEqual(b"abc" == str8("abc"), True)
-        self.assertEqual(b"ab" != str8("abc"), True)
-        self.assertEqual(b"ab" <= str8("abc"), True)
-        self.assertEqual(b"ab" < str8("abc"), True)
-        self.assertEqual(b"abc" >= str8("ab"), True)
-        self.assertEqual(b"abc" > str8("ab"), True)
-
-        self.assertEqual(b"abc" != str8("abc"), False)
-        self.assertEqual(b"ab" == str8("abc"), False)
-        self.assertEqual(b"ab" > str8("abc"), False)
-        self.assertEqual(b"ab" >= str8("abc"), False)
-        self.assertEqual(b"abc" < str8("ab"), False)
-        self.assertEqual(b"abc" <= str8("ab"), False)
-
-        self.assertEqual(str8("abc") == b"abc", True)
-        self.assertEqual(str8("ab") != b"abc", True)
-        self.assertEqual(str8("ab") <= b"abc", True)
-        self.assertEqual(str8("ab") < b"abc", True)
-        self.assertEqual(str8("abc") >= b"ab", True)
-        self.assertEqual(str8("abc") > b"ab", True)
-
-        self.assertEqual(str8("abc") != b"abc", False)
-        self.assertEqual(str8("ab") == b"abc", False)
-        self.assertEqual(str8("ab") > b"abc", False)
-        self.assertEqual(str8("ab") >= b"abc", False)
-        self.assertEqual(str8("abc") < b"ab", False)
-        self.assertEqual(str8("abc") <= b"ab", False)
-
+        warnings.simplefilter('ignore', BytesWarning)
         # Byte comparisons with unicode should always fail!
         # Test this for all expected byte orders and Unicode character sizes
-        self.assertEqual(b"\0a\0b\0c" == "abc", False)
-        self.assertEqual(b"\0\0\0a\0\0\0b\0\0\0c" == "abc", False)
-        self.assertEqual(b"a\0b\0c\0" == "abc", False)
-        self.assertEqual(b"a\0\0\0b\0\0\0c\0\0\0" == "abc", False)
-        self.assertEqual(bytes() == str(), False)
-        self.assertEqual(bytes() != str(), True)
-
-    def test_nohash(self):
-        self.assertRaises(TypeError, hash, bytes())
-
-    def test_doc(self):
-        self.failUnless(bytes.__doc__ != None)
-        self.failUnless(bytes.__doc__.startswith("bytes("))
-
-    def test_buffer_api(self):
-        short_sample = b"Hello world\n"
-        sample = short_sample + b"x"*(20 - len(short_sample))
-        tfn = tempfile.mktemp()
-        try:
-            # Prepare
-            with open(tfn, "wb") as f:
-                f.write(short_sample)
-            # Test readinto
-            with open(tfn, "rb") as f:
-                b = b"x"*20
-                n = f.readinto(b)
-            self.assertEqual(n, len(short_sample))
-            self.assertEqual(list(b), list(sample))
-            # Test writing in binary mode
-            with open(tfn, "wb") as f:
-                f.write(b)
-            with open(tfn, "rb") as f:
-                self.assertEqual(f.read(), sample)
-            # Text mode is ambiguous; don't test
-        finally:
-            try:
-                os.remove(tfn)
-            except os.error:
-                pass
+        self.assertEqual(self.type2test(b"\0a\0b\0c") == "abc", False)
+        self.assertEqual(self.type2test(b"\0\0\0a\0\0\0b\0\0\0c") == "abc", False)
+        self.assertEqual(self.type2test(b"a\0b\0c\0") == "abc", False)
+        self.assertEqual(self.type2test(b"a\0\0\0b\0\0\0c\0\0\0") == "abc", False)
+        self.assertEqual(self.type2test() == str(), False)
+        self.assertEqual(self.type2test() != str(), True)
 
     def test_reversed(self):
         input = list(map(ord, "Hello"))
-        b = bytes(input)
+        b = self.type2test(input)
         output = list(reversed(b))
         input.reverse()
         self.assertEqual(output, input)
 
-    def test_reverse(self):
-        b = b'hello'
-        self.assertEqual(b.reverse(), None)
-        self.assertEqual(b, b'olleh')
-        b = b'hello1' # test even number of items
-        b.reverse()
-        self.assertEqual(b, b'1olleh')
-        b = bytes()
-        b.reverse()
-        self.assertFalse(b)
-
     def test_getslice(self):
         def by(s):
-            return bytes(map(ord, s))
+            return self.type2test(map(ord, s))
         b = by("Hello, world")
 
         self.assertEqual(b[:5], by("Hello"))
@@ -213,33 +157,362 @@
     def test_extended_getslice(self):
         # Test extended slicing by comparing with list slicing.
         L = list(range(255))
-        b = bytes(L)
+        b = self.type2test(L)
         indices = (0, None, 1, 3, 19, 100, -1, -2, -31, -100)
         for start in indices:
             for stop in indices:
                 # Skip step 0 (invalid)
                 for step in indices[1:]:
-                    self.assertEqual(b[start:stop:step], bytes(L[start:stop:step]))
+                    self.assertEqual(b[start:stop:step], self.type2test(L[start:stop:step]))
+
+    def test_encoding(self):
+        sample = "Hello world\n\u1234\u5678\u9abc\udef0"
+        for enc in ("utf8", "utf16"):
+            b = self.type2test(sample, enc)
+            self.assertEqual(b, self.type2test(sample.encode(enc)))
+        self.assertRaises(UnicodeEncodeError, self.type2test, sample, "latin1")
+        b = self.type2test(sample, "latin1", "ignore")
+        self.assertEqual(b, self.type2test(sample[:-4], "utf-8"))
+
+    def test_decode(self):
+        sample = "Hello world\n\u1234\u5678\u9abc\def0\def0"
+        for enc in ("utf8", "utf16"):
+            b = self.type2test(sample, enc)
+            self.assertEqual(b.decode(enc), sample)
+        sample = "Hello world\n\x80\x81\xfe\xff"
+        b = self.type2test(sample, "latin1")
+        self.assertRaises(UnicodeDecodeError, b.decode, "utf8")
+        self.assertEqual(b.decode("utf8", "ignore"), "Hello world\n")
+
+    def test_from_int(self):
+        b = self.type2test(0)
+        self.assertEqual(b, self.type2test())
+        b = self.type2test(10)
+        self.assertEqual(b, self.type2test([0]*10))
+        b = self.type2test(10000)
+        self.assertEqual(b, self.type2test([0]*10000))
+
+    def test_concat(self):
+        b1 = self.type2test(b"abc")
+        b2 = self.type2test(b"def")
+        self.assertEqual(b1 + b2, b"abcdef")
+        self.assertEqual(b1 + bytes(b"def"), b"abcdef")
+        self.assertEqual(bytes(b"def") + b1, b"defabc")
+        self.assertRaises(TypeError, lambda: b1 + "def")
+        self.assertRaises(TypeError, lambda: "abc" + b2)
+
+    def test_repeat(self):
+        for b in b"abc", self.type2test(b"abc"):
+            self.assertEqual(b * 3, b"abcabcabc")
+            self.assertEqual(b * 0, b"")
+            self.assertEqual(b * -1, b"")
+            self.assertRaises(TypeError, lambda: b * 3.14)
+            self.assertRaises(TypeError, lambda: 3.14 * b)
+            # XXX Shouldn't bytes and bytearray agree on what to raise?
+            self.assertRaises((OverflowError, MemoryError),
+                              lambda: b * sys.maxsize)
+
+    def test_repeat_1char(self):
+        self.assertEqual(self.type2test(b'x')*100, self.type2test([ord('x')]*100))
+
+    def test_contains(self):
+        b = self.type2test(b"abc")
+        self.failUnless(ord('a') in b)
+        self.failUnless(int(ord('a')) in b)
+        self.failIf(200 in b)
+        self.failIf(200 in b)
+        self.assertRaises(ValueError, lambda: 300 in b)
+        self.assertRaises(ValueError, lambda: -1 in b)
+        self.assertRaises(TypeError, lambda: None in b)
+        self.assertRaises(TypeError, lambda: float(ord('a')) in b)
+        self.assertRaises(TypeError, lambda: "a" in b)
+        for f in bytes, bytearray:
+            self.failUnless(f(b"") in b)
+            self.failUnless(f(b"a") in b)
+            self.failUnless(f(b"b") in b)
+            self.failUnless(f(b"c") in b)
+            self.failUnless(f(b"ab") in b)
+            self.failUnless(f(b"bc") in b)
+            self.failUnless(f(b"abc") in b)
+            self.failIf(f(b"ac") in b)
+            self.failIf(f(b"d") in b)
+            self.failIf(f(b"dab") in b)
+            self.failIf(f(b"abd") in b)
+
+    def test_fromhex(self):
+        self.assertRaises(TypeError, self.type2test.fromhex)
+        self.assertRaises(TypeError, self.type2test.fromhex, 1)
+        self.assertEquals(self.type2test.fromhex(''), self.type2test())
+        b = bytearray([0x1a, 0x2b, 0x30])
+        self.assertEquals(self.type2test.fromhex('1a2B30'), b)
+        self.assertEquals(self.type2test.fromhex('  1A 2B  30   '), b)
+        self.assertEquals(self.type2test.fromhex('0000'), b'\0\0')
+        self.assertRaises(TypeError, self.type2test.fromhex, b'1B')
+        self.assertRaises(ValueError, self.type2test.fromhex, 'a')
+        self.assertRaises(ValueError, self.type2test.fromhex, 'rt')
+        self.assertRaises(ValueError, self.type2test.fromhex, '1a b cd')
+        self.assertRaises(ValueError, self.type2test.fromhex, '\x00')
+        self.assertRaises(ValueError, self.type2test.fromhex, '12   \x00   34')
+
+    def test_join(self):
+        self.assertEqual(self.type2test(b"").join([]), b"")
+        self.assertEqual(self.type2test(b"").join([b""]), b"")
+        for lst in [[b"abc"], [b"a", b"bc"], [b"ab", b"c"], [b"a", b"b", b"c"]]:
+            lst = list(map(self.type2test, lst))
+            self.assertEqual(self.type2test(b"").join(lst), b"abc")
+            self.assertEqual(self.type2test(b"").join(tuple(lst)), b"abc")
+            self.assertEqual(self.type2test(b"").join(iter(lst)), b"abc")
+        self.assertEqual(self.type2test(b".").join([b"ab", b"cd"]), b"ab.cd")
+        # XXX more...
+
+    def test_index(self):
+        b = self.type2test(b'parrot')
+        self.assertEqual(b.index('p'), 0)
+        self.assertEqual(b.index('rr'), 2)
+        self.assertEqual(b.index('t'), 5)
+        self.assertRaises(ValueError, lambda: b.index('w'))
+
+    def test_count(self):
+        b = self.type2test(b'mississippi')
+        self.assertEqual(b.count(b'i'), 4)
+        self.assertEqual(b.count(b'ss'), 2)
+        self.assertEqual(b.count(b'w'), 0)
+
+    def test_startswith(self):
+        b = self.type2test(b'hello')
+        self.assertFalse(self.type2test().startswith(b"anything"))
+        self.assertTrue(b.startswith(b"hello"))
+        self.assertTrue(b.startswith(b"hel"))
+        self.assertTrue(b.startswith(b"h"))
+        self.assertFalse(b.startswith(b"hellow"))
+        self.assertFalse(b.startswith(b"ha"))
+
+    def test_endswith(self):
+        b = self.type2test(b'hello')
+        self.assertFalse(bytearray().endswith(b"anything"))
+        self.assertTrue(b.endswith(b"hello"))
+        self.assertTrue(b.endswith(b"llo"))
+        self.assertTrue(b.endswith(b"o"))
+        self.assertFalse(b.endswith(b"whello"))
+        self.assertFalse(b.endswith(b"no"))
+
+    def test_find(self):
+        b = self.type2test(b'mississippi')
+        self.assertEqual(b.find(b'ss'), 2)
+        self.assertEqual(b.find(b'ss', 3), 5)
+        self.assertEqual(b.find(b'ss', 1, 7), 2)
+        self.assertEqual(b.find(b'ss', 1, 3), -1)
+        self.assertEqual(b.find(b'w'), -1)
+        self.assertEqual(b.find(b'mississippian'), -1)
+
+    def test_rfind(self):
+        b = self.type2test(b'mississippi')
+        self.assertEqual(b.rfind(b'ss'), 5)
+        self.assertEqual(b.rfind(b'ss', 3), 5)
+        self.assertEqual(b.rfind(b'ss', 0, 6), 2)
+        self.assertEqual(b.rfind(b'w'), -1)
+        self.assertEqual(b.rfind(b'mississippian'), -1)
+
+    def test_index(self):
+        b = self.type2test(b'world')
+        self.assertEqual(b.index(b'w'), 0)
+        self.assertEqual(b.index(b'orl'), 1)
+        self.assertRaises(ValueError, b.index, b'worm')
+        self.assertRaises(ValueError, b.index, b'ldo')
+
+    def test_rindex(self):
+        # XXX could be more rigorous
+        b = self.type2test(b'world')
+        self.assertEqual(b.rindex(b'w'), 0)
+        self.assertEqual(b.rindex(b'orl'), 1)
+        self.assertRaises(ValueError, b.rindex, b'worm')
+        self.assertRaises(ValueError, b.rindex, b'ldo')
+
+    def test_replace(self):
+        b = self.type2test(b'mississippi')
+        self.assertEqual(b.replace(b'i', b'a'), b'massassappa')
+        self.assertEqual(b.replace(b'ss', b'x'), b'mixixippi')
+
+    def test_split(self):
+        b = self.type2test(b'mississippi')
+        self.assertEqual(b.split(b'i'), [b'm', b'ss', b'ss', b'pp', b''])
+        self.assertEqual(b.split(b'ss'), [b'mi', b'i', b'ippi'])
+        self.assertEqual(b.split(b'w'), [b])
+
+    def test_split_whitespace(self):
+        for b in (b'  arf  barf  ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf',
+                  b'arf\fbarf', b'arf\vbarf'):
+            b = self.type2test(b)
+            self.assertEqual(b.split(), [b'arf', b'barf'])
+            self.assertEqual(b.split(None), [b'arf', b'barf'])
+            self.assertEqual(b.split(None, 2), [b'arf', b'barf'])
+        for b in (b'a\x1Cb', b'a\x1Db', b'a\x1Eb', b'a\x1Fb'):
+            b = self.type2test(b)
+            self.assertEqual(b.split(), [b])
+        self.assertEqual(self.type2test(b'  a  bb  c  ').split(None, 0), [b'a  bb  c  '])
+        self.assertEqual(self.type2test(b'  a  bb  c  ').split(None, 1), [b'a', b'bb  c  '])
+        self.assertEqual(self.type2test(b'  a  bb  c  ').split(None, 2), [b'a', b'bb', b'c  '])
+        self.assertEqual(self.type2test(b'  a  bb  c  ').split(None, 3), [b'a', b'bb', b'c'])
+
+    def test_split_string_error(self):
+        self.assertRaises(TypeError, self.type2test(b'a b').split, ' ')
+
+    def test_rsplit(self):
+        b = self.type2test(b'mississippi')
+        self.assertEqual(b.rsplit(b'i'), [b'm', b'ss', b'ss', b'pp', b''])
+        self.assertEqual(b.rsplit(b'ss'), [b'mi', b'i', b'ippi'])
+        self.assertEqual(b.rsplit(b'w'), [b])
+
+    def test_rsplit_whitespace(self):
+        for b in (b'  arf  barf  ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf',
+                  b'arf\fbarf', b'arf\vbarf'):
+            b = self.type2test(b)
+            self.assertEqual(b.rsplit(), [b'arf', b'barf'])
+            self.assertEqual(b.rsplit(None), [b'arf', b'barf'])
+            self.assertEqual(b.rsplit(None, 2), [b'arf', b'barf'])
+        self.assertEqual(self.type2test(b'  a  bb  c  ').rsplit(None, 0), [b'  a  bb  c'])
+        self.assertEqual(self.type2test(b'  a  bb  c  ').rsplit(None, 1), [b'  a  bb', b'c'])
+        self.assertEqual(self.type2test(b'  a  bb  c  ').rsplit(None, 2), [b'  a', b'bb', b'c'])
+        self.assertEqual(self.type2test(b'  a  bb  c  ').rsplit(None, 3), [b'a', b'bb', b'c'])
+
+    def test_rsplit_string_error(self):
+        self.assertRaises(TypeError, self.type2test(b'a b').rsplit, ' ')
+
+    def test_rsplit_unicodewhitespace(self):
+        b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F")
+        self.assertEqual(b.split(), [b'\x1c\x1d\x1e\x1f'])
+        self.assertEqual(b.rsplit(), [b'\x1c\x1d\x1e\x1f'])
+
+    def test_partition(self):
+        b = self.type2test(b'mississippi')
+        self.assertEqual(b.partition(b'ss'), (b'mi', b'ss', b'issippi'))
+        self.assertEqual(b.rpartition(b'w'), (b'', b'', b'mississippi'))
+
+    def test_rpartition(self):
+        b = self.type2test(b'mississippi')
+        self.assertEqual(b.rpartition(b'ss'), (b'missi', b'ss', b'ippi'))
+        self.assertEqual(b.rpartition(b'i'), (b'mississipp', b'i', b''))
+
+    def test_pickling(self):
+        for proto in range(pickle.HIGHEST_PROTOCOL):
+            for b in b"", b"a", b"abc", b"\xffab\x80", b"\0\0\377\0\0":
+                b = self.type2test(b)
+                ps = pickle.dumps(b, proto)
+                q = pickle.loads(ps)
+                self.assertEqual(b, q)
+
+    def test_strip(self):
+        b = self.type2test(b'mississippi')
+        self.assertEqual(b.strip(b'i'), b'mississipp')
+        self.assertEqual(b.strip(b'm'), b'ississippi')
+        self.assertEqual(b.strip(b'pi'), b'mississ')
+        self.assertEqual(b.strip(b'im'), b'ssissipp')
+        self.assertEqual(b.strip(b'pim'), b'ssiss')
+        self.assertEqual(b.strip(b), b'')
+
+    def test_lstrip(self):
+        b = self.type2test(b'mississippi')
+        self.assertEqual(b.lstrip(b'i'), b'mississippi')
+        self.assertEqual(b.lstrip(b'm'), b'ississippi')
+        self.assertEqual(b.lstrip(b'pi'), b'mississippi')
+        self.assertEqual(b.lstrip(b'im'), b'ssissippi')
+        self.assertEqual(b.lstrip(b'pim'), b'ssissippi')
+
+    def test_rstrip(self):
+        b = self.type2test(b'mississippi')
+        self.assertEqual(b.rstrip(b'i'), b'mississipp')
+        self.assertEqual(b.rstrip(b'm'), b'mississippi')
+        self.assertEqual(b.rstrip(b'pi'), b'mississ')
+        self.assertEqual(b.rstrip(b'im'), b'mississipp')
+        self.assertEqual(b.rstrip(b'pim'), b'mississ')
+
+    def test_strip_whitespace(self):
+        b = self.type2test(b' \t\n\r\f\vabc \t\n\r\f\v')
+        self.assertEqual(b.strip(), b'abc')
+        self.assertEqual(b.lstrip(), b'abc \t\n\r\f\v')
+        self.assertEqual(b.rstrip(), b' \t\n\r\f\vabc')
+
+    def test_strip_bytearray(self):
+        self.assertEqual(self.type2test(b'abc').strip(memoryview(b'ac')), b'b')
+        self.assertEqual(self.type2test(b'abc').lstrip(memoryview(b'ac')), b'bc')
+        self.assertEqual(self.type2test(b'abc').rstrip(memoryview(b'ac')), b'ab')
+
+    def test_strip_string_error(self):
+        self.assertRaises(TypeError, self.type2test(b'abc').strip, 'b')
+        self.assertRaises(TypeError, self.type2test(b'abc').lstrip, 'b')
+        self.assertRaises(TypeError, self.type2test(b'abc').rstrip, 'b')
+
+    def test_ord(self):
+        b = self.type2test(b'\0A\x7f\x80\xff')
+        self.assertEqual([ord(b[i:i+1]) for i in range(len(b))],
+                         [0, 65, 127, 128, 255])
+
+
+class BytesTest(BaseBytesTest):
+    type2test = bytes
+
+class ByteArrayTest(BaseBytesTest):
+    type2test = bytearray
+
+    def test_nohash(self):
+        self.assertRaises(TypeError, hash, bytearray())
+
+    def test_bytearray_api(self):
+        short_sample = b"Hello world\n"
+        sample = short_sample + b"\0"*(20 - len(short_sample))
+        tfn = tempfile.mktemp()
+        try:
+            # Prepare
+            with open(tfn, "wb") as f:
+                f.write(short_sample)
+            # Test readinto
+            with open(tfn, "rb") as f:
+                b = bytearray(20)
+                n = f.readinto(b)
+            self.assertEqual(n, len(short_sample))
+            self.assertEqual(list(b), list(sample))
+            # Test writing in binary mode
+            with open(tfn, "wb") as f:
+                f.write(b)
+            with open(tfn, "rb") as f:
+                self.assertEqual(f.read(), sample)
+            # Text mode is ambiguous; don't test
+        finally:
+            try:
+                os.remove(tfn)
+            except os.error:
+                pass
+
+    def test_reverse(self):
+        b = bytearray(b'hello')
+        self.assertEqual(b.reverse(), None)
+        self.assertEqual(b, b'olleh')
+        b = bytearray(b'hello1') # test even number of items
+        b.reverse()
+        self.assertEqual(b, b'1olleh')
+        b = bytearray()
+        b.reverse()
+        self.assertFalse(b)
 
     def test_regexps(self):
         def by(s):
-            return bytes(map(ord, s))
+            return bytearray(map(ord, s))
         b = by("Hello, world")
         self.assertEqual(re.findall(r"\w+", b), [by("Hello"), by("world")])
 
     def test_setitem(self):
-        b = bytes([1, 2, 3])
+        b = bytearray([1, 2, 3])
         b[1] = 100
-        self.assertEqual(b, bytes([1, 100, 3]))
+        self.assertEqual(b, bytearray([1, 100, 3]))
         b[-1] = 200
-        self.assertEqual(b, bytes([1, 100, 200]))
+        self.assertEqual(b, bytearray([1, 100, 200]))
         class C:
             def __init__(self, i=0):
                 self.i = i
             def __index__(self):
                 return self.i
         b[0] = C(10)
-        self.assertEqual(b, bytes([10, 100, 200]))
+        self.assertEqual(b, bytearray([10, 100, 200]))
         try:
             b[3] = 0
             self.fail("Didn't raise IndexError")
@@ -267,35 +540,35 @@
             pass
 
     def test_delitem(self):
-        b = bytes(range(10))
+        b = bytearray(range(10))
         del b[0]
-        self.assertEqual(b, bytes(range(1, 10)))
+        self.assertEqual(b, bytearray(range(1, 10)))
         del b[-1]
-        self.assertEqual(b, bytes(range(1, 9)))
+        self.assertEqual(b, bytearray(range(1, 9)))
         del b[4]
-        self.assertEqual(b, bytes([1, 2, 3, 4, 6, 7, 8]))
+        self.assertEqual(b, bytearray([1, 2, 3, 4, 6, 7, 8]))
 
     def test_setslice(self):
-        b = bytes(range(10))
+        b = bytearray(range(10))
         self.assertEqual(list(b), list(range(10)))
 
-        b[0:5] = bytes([1, 1, 1, 1, 1])
-        self.assertEqual(b, bytes([1, 1, 1, 1, 1, 5, 6, 7, 8, 9]))
+        b[0:5] = bytearray([1, 1, 1, 1, 1])
+        self.assertEqual(b, bytearray([1, 1, 1, 1, 1, 5, 6, 7, 8, 9]))
 
         del b[0:-5]
-        self.assertEqual(b, bytes([5, 6, 7, 8, 9]))
+        self.assertEqual(b, bytearray([5, 6, 7, 8, 9]))
 
-        b[0:0] = bytes([0, 1, 2, 3, 4])
-        self.assertEqual(b, bytes(range(10)))
+        b[0:0] = bytearray([0, 1, 2, 3, 4])
+        self.assertEqual(b, bytearray(range(10)))
 
-        b[-7:-3] = bytes([100, 101])
-        self.assertEqual(b, bytes([0, 1, 2, 100, 101, 7, 8, 9]))
+        b[-7:-3] = bytearray([100, 101])
+        self.assertEqual(b, bytearray([0, 1, 2, 100, 101, 7, 8, 9]))
 
         b[3:5] = [3, 4, 5, 6]
-        self.assertEqual(b, bytes(range(10)))
+        self.assertEqual(b, bytearray(range(10)))
 
         b[3:0] = [42, 42, 42]
-        self.assertEqual(b, bytes([0, 1, 2, 42, 42, 42, 3, 4, 5, 6, 7, 8, 9]))
+        self.assertEqual(b, bytearray([0, 1, 2, 42, 42, 42, 3, 4, 5, 6, 7, 8, 9]))
 
     def test_extended_set_del_slice(self):
         indices = (0, None, 1, 3, 19, 300, -1, -2, -31, -300)
@@ -304,93 +577,34 @@
                 # Skip invalid step 0
                 for step in indices[1:]:
                     L = list(range(255))
-                    b = bytes(L)
+                    b = bytearray(L)
                     # Make sure we have a slice of exactly the right length,
                     # but with different data.
                     data = L[start:stop:step]
                     data.reverse()
                     L[start:stop:step] = data
                     b[start:stop:step] = data
-                    self.assertEquals(b, bytes(L))
+                    self.assertEquals(b, bytearray(L))
 
                     del L[start:stop:step]
                     del b[start:stop:step]
-                    self.assertEquals(b, bytes(L))
+                    self.assertEquals(b, bytearray(L))
 
     def test_setslice_trap(self):
         # This test verifies that we correctly handle assigning self
         # to a slice of self (the old Lambert Meertens trap).
-        b = bytes(range(256))
+        b = bytearray(range(256))
         b[8:] = b
-        self.assertEqual(b, bytes(list(range(8)) + list(range(256))))
-
-    def test_encoding(self):
-        sample = "Hello world\n\u1234\u5678\u9abc\udef0"
-        for enc in ("utf8", "utf16"):
-            b = bytes(sample, enc)
-            self.assertEqual(b, bytes(sample.encode(enc)))
-        self.assertRaises(UnicodeEncodeError, bytes, sample, "latin1")
-        b = bytes(sample, "latin1", "ignore")
-        self.assertEqual(b, bytes(sample[:-4], "utf-8"))
-
-    def test_decode(self):
-        sample = "Hello world\n\u1234\u5678\u9abc\def0\def0"
-        for enc in ("utf8", "utf16"):
-            b = bytes(sample, enc)
-            self.assertEqual(b.decode(enc), sample)
-        sample = "Hello world\n\x80\x81\xfe\xff"
-        b = bytes(sample, "latin1")
-        self.assertRaises(UnicodeDecodeError, b.decode, "utf8")
-        self.assertEqual(b.decode("utf8", "ignore"), "Hello world\n")
-
-    def test_from_buffer(self):
-        sample = str8("Hello world\n\x80\x81\xfe\xff")
-        buf = memoryview(sample)
-        b = bytes(buf)
-        self.assertEqual(b, bytes(map(ord, sample)))
-
-    def test_to_str(self):
-        sample = "Hello world\n\x80\x81\xfe\xff"
-        b = bytes(sample, "utf-8")
-        self.assertEqual(str(b), sample)
-
-    def test_from_int(self):
-        b = bytes(0)
-        self.assertEqual(b, bytes())
-        b = bytes(10)
-        self.assertEqual(b, bytes([0]*10))
-        b = bytes(10000)
-        self.assertEqual(b, bytes([0]*10000))
-
-    def test_concat(self):
-        b1 = b"abc"
-        b2 = b"def"
-        self.assertEqual(b1 + b2, b"abcdef")
-        self.assertEqual(b1 + str8("def"), b"abcdef")
-        self.assertEqual(str8("def") + b1, b"defabc")
-        self.assertRaises(TypeError, lambda: b1 + "def")
-        self.assertRaises(TypeError, lambda: "abc" + b2)
-
-    def test_repeat(self):
-        b = b"abc"
-        self.assertEqual(b * 3, b"abcabcabc")
-        self.assertEqual(b * 0, bytes())
-        self.assertEqual(b * -1, bytes())
-        self.assertRaises(TypeError, lambda: b * 3.14)
-        self.assertRaises(TypeError, lambda: 3.14 * b)
-        self.assertRaises(MemoryError, lambda: b * sys.maxint)
-
-    def test_repeat_1char(self):
-        self.assertEqual(b'x'*100, bytes([ord('x')]*100))
+        self.assertEqual(b, bytearray(list(range(8)) + list(range(256))))
 
     def test_iconcat(self):
-        b = b"abc"
+        b = bytearray(b"abc")
         b1 = b
         b += b"def"
         self.assertEqual(b, b"abcdef")
         self.assertEqual(b, b1)
         self.failUnless(b is b1)
-        b += str8("xyz")
+        b += b"xyz"
         self.assertEqual(b, b"abcdefxyz")
         try:
             b += ""
@@ -400,7 +614,7 @@
             self.fail("bytes += unicode didn't raise TypeError")
 
     def test_irepeat(self):
-        b = b"abc"
+        b = bytearray(b"abc")
         b1 = b
         b *= 3
         self.assertEqual(b, b"abcabcabc")
@@ -408,38 +622,15 @@
         self.failUnless(b is b1)
 
     def test_irepeat_1char(self):
-        b = b"x"
+        b = bytearray(b"x")
         b1 = b
         b *= 100
-        self.assertEqual(b, bytes([ord("x")]*100))
+        self.assertEqual(b, b"x"*100)
         self.assertEqual(b, b1)
         self.failUnless(b is b1)
 
-    def test_contains(self):
-        b = b"abc"
-        self.failUnless(ord('a') in b)
-        self.failUnless(int(ord('a')) in b)
-        self.failIf(200 in b)
-        self.failIf(200 in b)
-        self.assertRaises(ValueError, lambda: 300 in b)
-        self.assertRaises(ValueError, lambda: -1 in b)
-        self.assertRaises(TypeError, lambda: None in b)
-        self.assertRaises(TypeError, lambda: float(ord('a')) in b)
-        self.assertRaises(TypeError, lambda: "a" in b)
-        self.failUnless(b"" in b)
-        self.failUnless(b"a" in b)
-        self.failUnless(b"b" in b)
-        self.failUnless(b"c" in b)
-        self.failUnless(b"ab" in b)
-        self.failUnless(b"bc" in b)
-        self.failUnless(b"abc" in b)
-        self.failIf(b"ac" in b)
-        self.failIf(b"d" in b)
-        self.failIf(b"dab" in b)
-        self.failIf(b"abd" in b)
-
     def test_alloc(self):
-        b = bytes()
+        b = bytearray()
         alloc = b.__alloc__()
         self.assert_(alloc >= 0)
         seq = [alloc]
@@ -449,280 +640,198 @@
             self.assert_(alloc >= len(b))
             if alloc not in seq:
                 seq.append(alloc)
-        #print seq
-
-    def test_fromhex(self):
-        self.assertRaises(TypeError, bytes.fromhex)
-        self.assertRaises(TypeError, bytes.fromhex, 1)
-        self.assertEquals(bytes.fromhex(''), bytes())
-        b = bytes([0x1a, 0x2b, 0x30])
-        self.assertEquals(bytes.fromhex('1a2B30'), b)
-        self.assertEquals(bytes.fromhex('  1A 2B  30   '), b)
-        self.assertEquals(bytes.fromhex(memoryview(b'')), bytes())
-        self.assertEquals(bytes.fromhex(memoryview(b'0000')), bytes([0, 0]))
-        self.assertRaises(ValueError, bytes.fromhex, 'a')
-        self.assertRaises(ValueError, bytes.fromhex, 'rt')
-        self.assertRaises(ValueError, bytes.fromhex, '1a b cd')
-        self.assertRaises(ValueError, bytes.fromhex, '\x00')
-        self.assertRaises(ValueError, bytes.fromhex, '12   \x00   34')
-
-    def test_join(self):
-        self.assertEqual(b"".join([]), bytes())
-        self.assertEqual(b"".join([bytes()]), bytes())
-        for lst in [[b"abc"], [b"a", b"bc"], [b"ab", b"c"], [b"a", b"b", b"c"]]:
-            self.assertEqual(b"".join(lst), b"abc")
-            self.assertEqual(b"".join(tuple(lst)), b"abc")
-            self.assertEqual(b"".join(iter(lst)), b"abc")
-        self.assertEqual(b".".join([b"ab", b"cd"]), b"ab.cd")
-        # XXX more...
-
-    def test_literal(self):
-        tests =  [
-            (b"Wonderful spam", "Wonderful spam"),
-            (br"Wonderful spam too", "Wonderful spam too"),
-            (b"\xaa\x00\000\200", "\xaa\x00\000\200"),
-            (br"\xaa\x00\000\200", r"\xaa\x00\000\200"),
-        ]
-        for b, s in tests:
-            self.assertEqual(b, bytes(s, 'latin-1'))
-        for c in range(128, 256):
-            self.assertRaises(SyntaxError, eval,
-                              'b"%s"' % chr(c))
 
     def test_extend(self):
         orig = b'hello'
-        a = bytes(orig)
+        a = bytearray(orig)
         a.extend(a)
         self.assertEqual(a, orig + orig)
         self.assertEqual(a[5:], orig)
+        a = bytearray(b'')
+        # Test iterators that don't have a __length_hint__
+        a.extend(map(int, orig * 25))
+        a.extend(int(x) for x in orig * 25)
+        self.assertEqual(a, orig * 50)
+        self.assertEqual(a[-5:], orig)
+        a = bytearray(b'')
+        a.extend(iter(map(int, orig * 50)))
+        self.assertEqual(a, orig * 50)
+        self.assertEqual(a[-5:], orig)
+        a = bytearray(b'')
+        a.extend(list(map(int, orig * 50)))
+        self.assertEqual(a, orig * 50)
+        self.assertEqual(a[-5:], orig)
+        a = bytearray(b'')
+        self.assertRaises(ValueError, a.extend, [0, 1, 2, 256])
+        self.assertRaises(ValueError, a.extend, [0, 1, 2, -1])
+        self.assertEqual(len(a), 0)
 
     def test_remove(self):
-        b = b'hello'
+        b = bytearray(b'hello')
         b.remove(ord('l'))
         self.assertEqual(b, b'helo')
         b.remove(ord('l'))
         self.assertEqual(b, b'heo')
         self.assertRaises(ValueError, lambda: b.remove(ord('l')))
         self.assertRaises(ValueError, lambda: b.remove(400))
-        self.assertRaises(ValueError, lambda: b.remove('e'))
+        self.assertRaises(TypeError, lambda: b.remove('e'))
         # remove first and last
         b.remove(ord('o'))
         b.remove(ord('h'))
         self.assertEqual(b, b'e')
+        self.assertRaises(TypeError, lambda: b.remove(b'e'))
 
     def test_pop(self):
-        b = b'world'
+        b = bytearray(b'world')
         self.assertEqual(b.pop(), ord('d'))
         self.assertEqual(b.pop(0), ord('w'))
         self.assertEqual(b.pop(-2), ord('r'))
         self.assertRaises(IndexError, lambda: b.pop(10))
-        self.assertRaises(OverflowError, lambda: bytes().pop())
+        self.assertRaises(OverflowError, lambda: bytearray().pop())
 
     def test_nosort(self):
-        self.assertRaises(AttributeError, lambda: bytes().sort())
-
-    def test_index(self):
-        b = b'parrot'
-        self.assertEqual(b.index('p'), 0)
-        self.assertEqual(b.index('rr'), 2)
-        self.assertEqual(b.index('t'), 5)
-        self.assertRaises(ValueError, lambda: b.index('w'))
-
-    def test_count(self):
-        b = b'mississippi'
-        self.assertEqual(b.count(b'i'), 4)
-        self.assertEqual(b.count(b'ss'), 2)
-        self.assertEqual(b.count(b'w'), 0)
+        self.assertRaises(AttributeError, lambda: bytearray().sort())
 
     def test_append(self):
-        b = b'hell'
+        b = bytearray(b'hell')
         b.append(ord('o'))
         self.assertEqual(b, b'hello')
         self.assertEqual(b.append(100), None)
-        b = bytes()
+        b = bytearray()
         b.append(ord('A'))
         self.assertEqual(len(b), 1)
+        self.assertRaises(TypeError, lambda: b.append(b'o'))
 
     def test_insert(self):
-        b = b'msssspp'
+        b = bytearray(b'msssspp')
         b.insert(1, ord('i'))
         b.insert(4, ord('i'))
         b.insert(-2, ord('i'))
         b.insert(1000, ord('i'))
         self.assertEqual(b, b'mississippi')
+        self.assertRaises(TypeError, lambda: b.insert(0, b'1'))
 
-    def test_startswith(self):
-        b = b'hello'
-        self.assertFalse(bytes().startswith(b"anything"))
-        self.assertTrue(b.startswith(b"hello"))
-        self.assertTrue(b.startswith(b"hel"))
-        self.assertTrue(b.startswith(b"h"))
-        self.assertFalse(b.startswith(b"hellow"))
-        self.assertFalse(b.startswith(b"ha"))
-
-    def test_endswith(self):
-        b = b'hello'
-        self.assertFalse(bytes().endswith(b"anything"))
-        self.assertTrue(b.endswith(b"hello"))
-        self.assertTrue(b.endswith(b"llo"))
-        self.assertTrue(b.endswith(b"o"))
-        self.assertFalse(b.endswith(b"whello"))
-        self.assertFalse(b.endswith(b"no"))
+    def test_partition_bytearray_doesnt_share_nullstring(self):
+        a, b, c = bytearray(b"x").partition(b"y")
+        self.assertEqual(b, b"")
+        self.assertEqual(c, b"")
+        self.assert_(b is not c)
+        b += b"!"
+        self.assertEqual(c, b"")
+        a, b, c = bytearray(b"x").partition(b"y")
+        self.assertEqual(b, b"")
+        self.assertEqual(c, b"")
+        # Same for rpartition
+        b, c, a = bytearray(b"x").rpartition(b"y")
+        self.assertEqual(b, b"")
+        self.assertEqual(c, b"")
+        self.assert_(b is not c)
+        b += b"!"
+        self.assertEqual(c, b"")
+        c, b, a = bytearray(b"x").rpartition(b"y")
+        self.assertEqual(b, b"")
+        self.assertEqual(c, b"")
+
+
+class AssortedBytesTest(unittest.TestCase):
+    #
+    # Test various combinations of bytes and bytearray
+    #
+
+    def setUp(self):
+        self.warning_filters = warnings.filters[:]
+
+    def tearDown(self):
+        warnings.filters = self.warning_filters
+
+    def test_repr_str(self):
+        warnings.simplefilter('ignore', BytesWarning)
+        for f in str, repr:
+            self.assertEqual(f(bytearray()), "bytearray(b'')")
+            self.assertEqual(f(bytearray([0])), "bytearray(b'\\x00')")
+            self.assertEqual(f(bytearray([0, 1, 254, 255])),
+                             "bytearray(b'\\x00\\x01\\xfe\\xff')")
+            self.assertEqual(f(b"abc"), "b'abc'")
+            self.assertEqual(f(b"'"), '''b"'"''') # '''
+            self.assertEqual(f(b"'\""), r"""b'\'"'""") # '
+
+    def test_compare_bytes_to_bytearray(self):
+        self.assertEqual(b"abc" == bytes(b"abc"), True)
+        self.assertEqual(b"ab" != bytes(b"abc"), True)
+        self.assertEqual(b"ab" <= bytes(b"abc"), True)
+        self.assertEqual(b"ab" < bytes(b"abc"), True)
+        self.assertEqual(b"abc" >= bytes(b"ab"), True)
+        self.assertEqual(b"abc" > bytes(b"ab"), True)
+
+        self.assertEqual(b"abc" != bytes(b"abc"), False)
+        self.assertEqual(b"ab" == bytes(b"abc"), False)
+        self.assertEqual(b"ab" > bytes(b"abc"), False)
+        self.assertEqual(b"ab" >= bytes(b"abc"), False)
+        self.assertEqual(b"abc" < bytes(b"ab"), False)
+        self.assertEqual(b"abc" <= bytes(b"ab"), False)
+
+        self.assertEqual(bytes(b"abc") == b"abc", True)
+        self.assertEqual(bytes(b"ab") != b"abc", True)
+        self.assertEqual(bytes(b"ab") <= b"abc", True)
+        self.assertEqual(bytes(b"ab") < b"abc", True)
+        self.assertEqual(bytes(b"abc") >= b"ab", True)
+        self.assertEqual(bytes(b"abc") > b"ab", True)
+
+        self.assertEqual(bytes(b"abc") != b"abc", False)
+        self.assertEqual(bytes(b"ab") == b"abc", False)
+        self.assertEqual(bytes(b"ab") > b"abc", False)
+        self.assertEqual(bytes(b"ab") >= b"abc", False)
+        self.assertEqual(bytes(b"abc") < b"ab", False)
+        self.assertEqual(bytes(b"abc") <= b"ab", False)
 
-    def test_find(self):
-        b = b'mississippi'
-        self.assertEqual(b.find(b'ss'), 2)
-        self.assertEqual(b.find(b'ss', 3), 5)
-        self.assertEqual(b.find(b'ss', 1, 7), 2)
-        self.assertEqual(b.find(b'ss', 1, 3), -1)
-        self.assertEqual(b.find(b'w'), -1)
-        self.assertEqual(b.find(b'mississippian'), -1)
-
-    def test_rfind(self):
-        b = b'mississippi'
-        self.assertEqual(b.rfind(b'ss'), 5)
-        self.assertEqual(b.rfind(b'ss', 3), 5)
-        self.assertEqual(b.rfind(b'ss', 0, 6), 2)
-        self.assertEqual(b.rfind(b'w'), -1)
-        self.assertEqual(b.rfind(b'mississippian'), -1)
+    def test_doc(self):
+        self.failUnless(bytearray.__doc__ != None)
+        self.failUnless(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)
+        self.failUnless(bytes.__doc__ != None)
+        self.failUnless(bytes.__doc__.startswith("bytes("), bytes.__doc__)
 
-    def test_index(self):
-        b = b'world'
-        self.assertEqual(b.index(b'w'), 0)
-        self.assertEqual(b.index(b'orl'), 1)
-        self.assertRaises(ValueError, b.index, b'worm')
-        self.assertRaises(ValueError, b.index, b'ldo')
+    def test_from_bytearray(self):
+        sample = bytes(b"Hello world\n\x80\x81\xfe\xff")
+        buf = memoryview(sample)
+        b = bytearray(buf)
+        self.assertEqual(b, bytearray(sample))
 
-    def test_rindex(self):
-        # XXX could be more rigorous
-        b = b'world'
-        self.assertEqual(b.rindex(b'w'), 0)
-        self.assertEqual(b.rindex(b'orl'), 1)
-        self.assertRaises(ValueError, b.rindex, b'worm')
-        self.assertRaises(ValueError, b.rindex, b'ldo')
+    def test_to_str(self):
+        warnings.simplefilter('ignore', BytesWarning)
+        self.assertEqual(str(b''), "b''")
+        self.assertEqual(str(b'x'), "b'x'")
+        self.assertEqual(str(b'\x80'), "b'\\x80'")
+        self.assertEqual(str(bytearray(b'')), "bytearray(b'')")
+        self.assertEqual(str(bytearray(b'x')), "bytearray(b'x')")
+        self.assertEqual(str(bytearray(b'\x80')), "bytearray(b'\\x80')")
 
-    def test_replace(self):
-        b = b'mississippi'
-        self.assertEqual(b.replace(b'i', b'a'), b'massassappa')
-        self.assertEqual(b.replace(b'ss', b'x'), b'mixixippi')
+    def test_literal(self):
+        tests =  [
+            (b"Wonderful spam", "Wonderful spam"),
+            (br"Wonderful spam too", "Wonderful spam too"),
+            (b"\xaa\x00\000\200", "\xaa\x00\000\200"),
+            (br"\xaa\x00\000\200", r"\xaa\x00\000\200"),
+        ]
+        for b, s in tests:
+            self.assertEqual(b, bytearray(s, 'latin-1'))
+        for c in range(128, 256):
+            self.assertRaises(SyntaxError, eval,
+                              'b"%s"' % chr(c))
 
     def test_translate(self):
         b = b'hello'
-        rosetta = bytes(range(0, 256))
+        rosetta = bytearray(range(0, 256))
         rosetta[ord('o')] = ord('e')
         c = b.translate(rosetta, b'l')
         self.assertEqual(b, b'hello')
         self.assertEqual(c, b'hee')
 
-    def test_split(self):
-        b = b'mississippi'
-        self.assertEqual(b.split(b'i'), [b'm', b'ss', b'ss', b'pp', b''])
-        self.assertEqual(b.split(b'ss'), [b'mi', b'i', b'ippi'])
-        self.assertEqual(b.split(b'w'), [b])
-
-    def test_split_whitespace(self):
-        for b in (b'  arf  barf  ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf',
-                  b'arf\fbarf', b'arf\vbarf'):
-            self.assertEqual(b.split(), [b'arf', b'barf'])
-            self.assertEqual(b.split(None), [b'arf', b'barf'])
-            self.assertEqual(b.split(None, 2), [b'arf', b'barf'])
-        self.assertEqual(b'  a  bb  c  '.split(None, 0), [b'a  bb  c  '])
-        self.assertEqual(b'  a  bb  c  '.split(None, 1), [b'a', b'bb  c  '])
-        self.assertEqual(b'  a  bb  c  '.split(None, 2), [b'a', b'bb', b'c  '])
-        self.assertEqual(b'  a  bb  c  '.split(None, 3), [b'a', b'bb', b'c'])
-
-    def test_split_buffer(self):
+    def test_split_bytearray(self):
         self.assertEqual(b'a b'.split(memoryview(b' ')), [b'a', b'b'])
 
-    def test_split_string_error(self):
-        self.assertRaises(TypeError, b'a b'.split, ' ')
-
-    def test_rsplit(self):
-        b = b'mississippi'
-        self.assertEqual(b.rsplit(b'i'), [b'm', b'ss', b'ss', b'pp', b''])
-        self.assertEqual(b.rsplit(b'ss'), [b'mi', b'i', b'ippi'])
-        self.assertEqual(b.rsplit(b'w'), [b])
-
-    def test_rsplit_whitespace(self):
-        for b in (b'  arf  barf  ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf',
-                  b'arf\fbarf', b'arf\vbarf'):
-            self.assertEqual(b.rsplit(), [b'arf', b'barf'])
-            self.assertEqual(b.rsplit(None), [b'arf', b'barf'])
-            self.assertEqual(b.rsplit(None, 2), [b'arf', b'barf'])
-        self.assertEqual(b'  a  bb  c  '.rsplit(None, 0), [b'  a  bb  c'])
-        self.assertEqual(b'  a  bb  c  '.rsplit(None, 1), [b'  a  bb', b'c'])
-        self.assertEqual(b'  a  bb  c  '.rsplit(None,2), [b'  a', b'bb', b'c'])
-        self.assertEqual(b'  a  bb  c  '.rsplit(None, 3), [b'a', b'bb', b'c'])
-
-    def test_rplit_buffer(self):
+    def test_rsplit_bytearray(self):
         self.assertEqual(b'a b'.rsplit(memoryview(b' ')), [b'a', b'b'])
 
-    def test_rplit_string_error(self):
-        self.assertRaises(TypeError, b'a b'.rsplit, ' ')
-
-    def test_partition(self):
-        b = b'mississippi'
-        self.assertEqual(b.partition(b'ss'), (b'mi', b'ss', b'issippi'))
-        self.assertEqual(b.rpartition(b'w'), (b'', b'', b'mississippi'))
-
-    def test_rpartition(self):
-        b = b'mississippi'
-        self.assertEqual(b.rpartition(b'ss'), (b'missi', b'ss', b'ippi'))
-        self.assertEqual(b.rpartition(b'i'), (b'mississipp', b'i', b''))
-
-    def test_pickling(self):
-        for proto in range(pickle.HIGHEST_PROTOCOL):
-            for b in b"", b"a", b"abc", b"\xffab\x80", b"\0\0\377\0\0":
-                ps = pickle.dumps(b, proto)
-                q = pickle.loads(ps)
-                self.assertEqual(b, q)
-
-    def test_strip(self):
-        b = b'mississippi'
-        self.assertEqual(b.strip(b'i'), b'mississipp')
-        self.assertEqual(b.strip(b'm'), b'ississippi')
-        self.assertEqual(b.strip(b'pi'), b'mississ')
-        self.assertEqual(b.strip(b'im'), b'ssissipp')
-        self.assertEqual(b.strip(b'pim'), b'ssiss')
-        self.assertEqual(b.strip(b), b'')
-
-    def test_lstrip(self):
-        b = b'mississippi'
-        self.assertEqual(b.lstrip(b'i'), b'mississippi')
-        self.assertEqual(b.lstrip(b'm'), b'ississippi')
-        self.assertEqual(b.lstrip(b'pi'), b'mississippi')
-        self.assertEqual(b.lstrip(b'im'), b'ssissippi')
-        self.assertEqual(b.lstrip(b'pim'), b'ssissippi')
-
-    def test_rstrip(self):
-        b = b'mississippi'
-        self.assertEqual(b.rstrip(b'i'), b'mississipp')
-        self.assertEqual(b.rstrip(b'm'), b'mississippi')
-        self.assertEqual(b.rstrip(b'pi'), b'mississ')
-        self.assertEqual(b.rstrip(b'im'), b'mississipp')
-        self.assertEqual(b.rstrip(b'pim'), b'mississ')
-
-    def test_strip_whitespace(self):
-        b = b' \t\n\r\f\vabc \t\n\r\f\v'
-        self.assertEqual(b.strip(), b'abc')
-        self.assertEqual(b.lstrip(), b'abc \t\n\r\f\v')
-        self.assertEqual(b.rstrip(), b' \t\n\r\f\vabc')
-
-    def test_strip_buffer(self):
-        self.assertEqual(b'abc'.strip(memoryview(b'ac')), b'b')
-        self.assertEqual(b'abc'.lstrip(memoryview(b'ac')), b'bc')
-        self.assertEqual(b'abc'.rstrip(memoryview(b'ac')), b'ab')
-
-    def test_strip_string_error(self):
-        self.assertRaises(TypeError, b'abc'.strip, 'b')
-        self.assertRaises(TypeError, b'abc'.lstrip, 'b')
-        self.assertRaises(TypeError, b'abc'.rstrip, 'b')
-
-    def test_ord(self):
-        b = b'\0A\x7f\x80\xff'
-        self.assertEqual([ord(b[i:i+1]) for i in range(len(b))],
-                         [0, 65, 127, 128, 255])
-
     # Optimizations:
     # __iter__? (optimization)
     # __reversed__? (optimization)
@@ -734,9 +843,28 @@
     # Unfortunately they are all bundled with tests that
     # are not appropriate for bytes
 
+    # I've started porting some of those into bytearray_tests.py, we should port
+    # the rest that make sense (the code can be cleaned up to use modern
+    # unittest methods at the same time).
+
+class BytearrayPEP3137Test(unittest.TestCase,
+                       test.buffer_tests.MixinBytesBufferCommonTests):
+    def marshal(self, x):
+        return bytearray(x)
+
+    def test_returns_new_copy(self):
+        val = self.marshal(b'1234')
+        # On immutable types these MAY return a reference to themselves
+        # but on mutable types like bytearray they MUST return a new copy.
+        for methname in ('zfill', 'rjust', 'ljust', 'center'):
+            method = getattr(val, methname)
+            newval = method(3)
+            self.assertEqual(val, newval)
+            self.assertTrue(val is not newval,
+                            methname+' returned self on a mutable object')
 
-class BytesAsStringTest(test.string_tests.BaseTest):
-    type2test = bytes
+
+class FixedStringTest(test.string_tests.BaseTest):
 
     def fixtype(self, obj):
         if isinstance(obj, str):
@@ -755,12 +883,99 @@
     def test_lower(self):
         pass
 
+class ByteArrayAsStringTest(FixedStringTest):
+    type2test = bytearray
+
+class BytesAsStringTest(FixedStringTest):
+    type2test = bytes
+
+
+class ByteArraySubclass(bytearray):
+    pass
+
+class ByteArraySubclassTest(unittest.TestCase):
+
+    def test_basic(self):
+        self.assert_(issubclass(ByteArraySubclass, bytearray))
+        self.assert_(isinstance(ByteArraySubclass(), bytearray))
+
+        a, b = b"abcd", b"efgh"
+        _a, _b = ByteArraySubclass(a), ByteArraySubclass(b)
+
+        # test comparison operators with subclass instances
+        self.assert_(_a == _a)
+        self.assert_(_a != _b)
+        self.assert_(_a < _b)
+        self.assert_(_a <= _b)
+        self.assert_(_b >= _a)
+        self.assert_(_b > _a)
+        self.assert_(_a is not a)
+
+        # test concat of subclass instances
+        self.assertEqual(a + b, _a + _b)
+        self.assertEqual(a + b, a + _b)
+        self.assertEqual(a + b, _a + b)
+
+        # test repeat
+        self.assert_(a*5 == _a*5)
+
+    def test_join(self):
+        # Make sure join returns a NEW object for single item sequences
+        # involving a subclass.
+        # Make sure that it is of the appropriate type.
+        s1 = ByteArraySubclass(b"abcd")
+        s2 = bytearray().join([s1])
+        self.assert_(s1 is not s2)
+        self.assert_(type(s2) is bytearray, type(s2))
+
+        # Test reverse, calling join on subclass
+        s3 = s1.join([b"abcd"])
+        self.assert_(type(s3) is bytearray)
+
+    def test_pickle(self):
+        a = ByteArraySubclass(b"abcd")
+        a.x = 10
+        a.y = ByteArraySubclass(b"efgh")
+        for proto in range(pickle.HIGHEST_PROTOCOL):
+            b = pickle.loads(pickle.dumps(a, proto))
+            self.assertNotEqual(id(a), id(b))
+            self.assertEqual(a, b)
+            self.assertEqual(a.x, b.x)
+            self.assertEqual(a.y, b.y)
+            self.assertEqual(type(a), type(b))
+            self.assertEqual(type(a.y), type(b.y))
+
+    def test_copy(self):
+        a = ByteArraySubclass(b"abcd")
+        a.x = 10
+        a.y = ByteArraySubclass(b"efgh")
+        for copy_method in (copy.copy, copy.deepcopy):
+            b = copy_method(a)
+            self.assertNotEqual(id(a), id(b))
+            self.assertEqual(a, b)
+            self.assertEqual(a.x, b.x)
+            self.assertEqual(a.y, b.y)
+            self.assertEqual(type(a), type(b))
+            self.assertEqual(type(a.y), type(b.y))
+
+    def test_init_override(self):
+        class subclass(bytearray):
+            def __init__(self, newarg=1, *args, **kwargs):
+                bytearray.__init__(self, *args, **kwargs)
+        x = subclass(4, source=b"abcd")
+        self.assertEqual(x, b"abcd")
+        x = subclass(newarg=4, source=b"abcd")
+        self.assertEqual(x, b"abcd")
+
 
 def test_main():
     test.test_support.run_unittest(BytesTest)
+    test.test_support.run_unittest(ByteArrayTest)
+    test.test_support.run_unittest(AssortedBytesTest)
     test.test_support.run_unittest(BytesAsStringTest)
-
+    test.test_support.run_unittest(ByteArrayAsStringTest)
+    test.test_support.run_unittest(ByteArraySubclassTest)
+    test.test_support.run_unittest(BytearrayPEP3137Test)
 
 if __name__ == "__main__":
-    ##test_main()
-    unittest.main()
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_bz2.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_bz2.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_bz2.py	Thu Mar 27 00:48:05 2008
@@ -160,12 +160,12 @@
 
     def testWriteMethodsOnReadOnlyFile(self):
         bz2f = BZ2File(self.filename, "w")
-        bz2f.write("abc")
+        bz2f.write(b"abc")
         bz2f.close()
 
         bz2f = BZ2File(self.filename, "r")
-        self.assertRaises(IOError, bz2f.write, "a")
-        self.assertRaises(IOError, bz2f.writelines, ["a"])
+        self.assertRaises(IOError, bz2f.write, b"a")
+        self.assertRaises(IOError, bz2f.writelines, [b"a"])
 
     def testSeekForward(self):
         # "Test BZ2File.seek(150, 0)"
@@ -307,7 +307,7 @@
         # "Calling BZ2Decompressor.decompress() after EOS must raise EOFError"
         bz2d = BZ2Decompressor()
         text = bz2d.decompress(self.DATA)
-        self.assertRaises(EOFError, bz2d.decompress, "anything")
+        self.assertRaises(EOFError, bz2d.decompress, b"anything")
 
 
 class FuncTest(BaseTest):

Modified: python/branches/py3k-importlib/Lib/test/test_cProfile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_cProfile.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_cProfile.py	Thu Mar 27 00:48:05 2008
@@ -119,5 +119,11 @@
         ticks += 1
         raise AttributeError
 
+
+def test_main():
+    from test.test_support import TestSkipped
+    raise TestSkipped('test_cProfile test is current broken')
+
+
 if __name__ == "__main__":
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_cfgparser.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_cfgparser.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_cfgparser.py	Thu Mar 27 00:48:05 2008
@@ -1,11 +1,11 @@
 import ConfigParser
 import io
 import unittest
-import UserDict
+import collections
 
 from test import test_support
 
-class SortedDict(UserDict.UserDict):
+class SortedDict(collections.UserDict):
     def items(self):
         return sorted(self.data.items())
 
@@ -436,6 +436,14 @@
         self.assertRaises(TypeError, cf.set, "sect", "option2", 1.0)
         self.assertRaises(TypeError, cf.set, "sect", "option2", object())
 
+    def test_add_section_default_1(self):
+        cf = self.newconfig()
+        self.assertRaises(ValueError, cf.add_section, "default")
+
+    def test_add_section_default_2(self):
+        cf = self.newconfig()
+        self.assertRaises(ValueError, cf.add_section, "DEFAULT")
+
 class SortedTestCase(RawConfigParserTestCase):
     def newconfig(self, defaults=None):
         self.cf = self.config_class(defaults=defaults, dict_type=SortedDict)

Modified: python/branches/py3k-importlib/Lib/test/test_class.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_class.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_class.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 "Test the functionality of Python classes implementing operators."
 
 import unittest
-import sys
 
 from test import test_support
 
@@ -552,7 +551,7 @@
         self.assertEquals(hash(B.f), hash(A.f))
 
         # the following triggers a SystemError in 2.4
-        a = A(hash(A.f.im_func)^(-1))
+        a = A(hash(A.f)^(-1))
         hash(a.f)
 
 def test_main():

Modified: python/branches/py3k-importlib/Lib/test/test_cmd_line.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_cmd_line.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_cmd_line.py	Thu Mar 27 00:48:05 2008
@@ -1,3 +1,6 @@
+# Tests invocation of the interpreter with various command line arguments
+# All tests are executed with environment variables ignored
+# See test_cmd_line_script.py for testing of script execution
 
 import test.test_support, unittest
 import sys
@@ -10,18 +13,25 @@
                             stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
 
 def _kill_python(p):
+    return _kill_python_and_exit_code(p)[0]
+
+def _kill_python_and_exit_code(p):
     p.stdin.close()
     data = p.stdout.read()
     p.stdout.close()
     # try to cleanup the child so we don't appear to leak when running
     # with regrtest -R.  This should be a no-op on Windows.
     subprocess._cleanup()
-    return data
+    returncode = p.wait()
+    return data, returncode
 
 class CmdLineTest(unittest.TestCase):
     def start_python(self, *args):
+        return self.start_python_and_exit_code(*args)[0]
+
+    def start_python_and_exit_code(self, *args):
         p = _spawn_python(*args)
-        return _kill_python(p)
+        return _kill_python_and_exit_code(p)
 
     def exit_code(self, *args):
         cmd_line = [sys.executable, '-E']
@@ -58,6 +68,17 @@
         version = ('Python %d.%d' % sys.version_info[:2]).encode("ascii")
         self.assertTrue(self.start_python('-V').startswith(version))
 
+    def test_verbose(self):
+        # -v causes imports to write to stderr.  If the write to
+        # stderr itself causes an import to happen (for the output
+        # codec), a recursion loop can occur.
+        data, rc = self.start_python_and_exit_code('-v')
+        self.assertEqual(rc, 0)
+        self.assertTrue(b'stack overflow' not in data)
+        data, rc = self.start_python_and_exit_code('-vv')
+        self.assertEqual(rc, 0)
+        self.assertTrue(b'stack overflow' not in data)
+
     def test_run_module(self):
         # Test expected operation of the '-m' switch
         # Switch needs an argument

Modified: python/branches/py3k-importlib/Lib/test/test_codeccallbacks.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_codeccallbacks.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_codeccallbacks.py	Thu Mar 27 00:48:05 2008
@@ -33,13 +33,13 @@
 # A UnicodeDecodeError object without an end attribute
 class NoEndUnicodeDecodeError(UnicodeDecodeError):
     def __init__(self):
-        UnicodeDecodeError.__init__(self, "ascii", b"", 0, 1, "bad")
+        UnicodeDecodeError.__init__(self, "ascii", bytearray(b""), 0, 1, "bad")
         del self.end
 
 # A UnicodeDecodeError object with a bad object attribute
 class BadObjectUnicodeDecodeError(UnicodeDecodeError):
     def __init__(self):
-        UnicodeDecodeError.__init__(self, "ascii", b"", 0, 1, "bad")
+        UnicodeDecodeError.__init__(self, "ascii", bytearray(b""), 0, 1, "bad")
         self.object = []
 
 # A UnicodeTranslateError object without a start attribute
@@ -140,17 +140,17 @@
             sin += chr(sys.maxunicode)
         sout = b"a\\xac\\u1234\\u20ac\\u8000"
         if sys.maxunicode > 0xffff:
-            sout += bytes("\\U%08x" % sys.maxunicode)
+            sout += bytes("\\U%08x" % sys.maxunicode, "ascii")
         self.assertEqual(sin.encode("ascii", "backslashreplace"), sout)
 
         sout = b"a\xac\\u1234\\u20ac\\u8000"
         if sys.maxunicode > 0xffff:
-            sout += bytes("\\U%08x" % sys.maxunicode)
+            sout += bytes("\\U%08x" % sys.maxunicode, "ascii")
         self.assertEqual(sin.encode("latin-1", "backslashreplace"), sout)
 
         sout = b"a\xac\\u1234\xa4\\u8000"
         if sys.maxunicode > 0xffff:
-            sout += bytes("\\U%08x" % sys.maxunicode)
+            sout += bytes("\\U%08x" % sys.maxunicode, "ascii")
         self.assertEqual(sin.encode("iso-8859-15", "backslashreplace"), sout)
 
     def test_decoderelaxedutf8(self):
@@ -181,7 +181,7 @@
         # mapped through the encoding again. This means, that
         # to be able to use e.g. the "replace" handler, the
         # charmap has to have a mapping for "?".
-        charmap = dict((ord(c), str8(2*c.upper())) for c in "abcdefgh")
+        charmap = dict((ord(c), bytes(2*c.upper(), 'ascii')) for c in "abcdefgh")
         sin = "abc"
         sout = b"AABBCC"
         self.assertEquals(codecs.charmap_encode(sin, "strict", charmap)[0], sout)
@@ -189,7 +189,7 @@
         sin = "abcA"
         self.assertRaises(UnicodeError, codecs.charmap_encode, sin, "strict", charmap)
 
-        charmap[ord("?")] = str8("XYZ")
+        charmap[ord("?")] = b"XYZ"
         sin = "abcDEF"
         sout = b"AABBCCXYZXYZXYZ"
         self.assertEquals(codecs.charmap_encode(sin, "replace", charmap)[0], sout)
@@ -309,7 +309,7 @@
         # check with one argument too much
         self.assertRaises(TypeError, exctype, *(args + ["too much"]))
         # check with one argument of the wrong type
-        wrongargs = [ "spam", str8("eggs"), b"spam", 42, 1.0, None ]
+        wrongargs = [ "spam", b"eggs", b"spam", 42, 1.0, None ]
         for i in range(len(args)):
             for wrongarg in wrongargs:
                 if type(wrongarg) is type(args[i]):
@@ -363,12 +363,12 @@
     def test_unicodedecodeerror(self):
         self.check_exceptionobjectargs(
             UnicodeDecodeError,
-            ["ascii", b"g\xfcrk", 1, 2, "ouch"],
+            ["ascii", bytearray(b"g\xfcrk"), 1, 2, "ouch"],
             "'ascii' codec can't decode byte 0xfc in position 1: ouch"
         )
         self.check_exceptionobjectargs(
             UnicodeDecodeError,
-            ["ascii", b"g\xfcrk", 1, 3, "ouch"],
+            ["ascii", bytearray(b"g\xfcrk"), 1, 3, "ouch"],
             "'ascii' codec can't decode bytes in position 1-2: ouch"
         )
 
@@ -442,7 +442,7 @@
         )
         self.assertEquals(
             codecs.ignore_errors(
-                UnicodeDecodeError("ascii", b"\xff", 0, 1, "ouch")),
+                UnicodeDecodeError("ascii", bytearray(b"\xff"), 0, 1, "ouch")),
             ("", 1)
         )
         self.assertEquals(
@@ -482,7 +482,7 @@
         )
         self.assertEquals(
             codecs.replace_errors(
-                UnicodeDecodeError("ascii", b"\xff", 0, 1, "ouch")),
+                UnicodeDecodeError("ascii", bytearray(b"\xff"), 0, 1, "ouch")),
             ("\ufffd", 1)
         )
         self.assertEquals(
@@ -508,7 +508,7 @@
         self.assertRaises(
             TypeError,
             codecs.xmlcharrefreplace_errors,
-            UnicodeDecodeError("ascii", b"\xff", 0, 1, "ouch")
+            UnicodeDecodeError("ascii", bytearray(b"\xff"), 0, 1, "ouch")
         )
         self.assertRaises(
             TypeError,
@@ -542,7 +542,7 @@
         self.assertRaises(
             TypeError,
             codecs.backslashreplace_errors,
-            UnicodeDecodeError("ascii", b"\xff", 0, 1, "ouch")
+            UnicodeDecodeError("ascii", bytearray(b"\xff"), 0, 1, "ouch")
         )
         self.assertRaises(
             TypeError,
@@ -792,7 +792,7 @@
         class D(dict):
             def __getitem__(self, key):
                 raise ValueError
-        self.assertRaises(ValueError, "\xff".translate, D())
+        #self.assertRaises(ValueError, "\xff".translate, D())
         self.assertRaises(TypeError, "\xff".translate, {0xff: sys.maxunicode+1})
         self.assertRaises(TypeError, "\xff".translate, {0xff: ()})
 

Modified: python/branches/py3k-importlib/Lib/test/test_codecmaps_hk.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_codecmaps_hk.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_codecmaps_hk.py	Thu Mar 27 00:48:05 2008
@@ -11,10 +11,11 @@
 class TestBig5HKSCSMap(test_multibytecodec_support.TestBase_Mapping,
                        unittest.TestCase):
     encoding = 'big5hkscs'
-    mapfileurl = 'http://people.freebsd.org/~perky/i18n/BIG5HKSCS.TXT'
+    mapfileurl = 'http://people.freebsd.org/~perky/i18n/BIG5HKSCS-2004.TXT'
 
 def test_main():
     test_support.run_unittest(__name__)
 
 if __name__ == "__main__":
+    test_support.use_resources = ['urlfetch']
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_codecs.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_codecs.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_codecs.py	Thu Mar 27 00:48:05 2008
@@ -59,7 +59,7 @@
 class ReadTest(unittest.TestCase, MixInCheckStateHandling):
     def check_partial(self, input, partialresults):
         # get a StreamReader for the encoding and feed the bytestring version
-        # of input to the reader byte by byte. Read every available from
+        # of input to the reader byte by byte. Read everything available from
         # the StreamReader and check that the results equal the appropriate
         # entries from partialresults.
         q = Queue(b"")
@@ -544,7 +544,17 @@
 class UTF7Test(ReadTest):
     encoding = "utf-7"
 
-    # No test_partial() yet, because UTF-7 doesn't support it.
+    def test_partial(self):
+        self.check_partial(
+            "a+-b",
+            [
+                "a",
+                "a",
+                "a+",
+                "a+-",
+                "a+-b",
+            ]
+        )
 
 class UTF16ExTest(unittest.TestCase):
 
@@ -618,10 +628,53 @@
         s = "spam"
         self.assertEqual(d.decode(s.encode("utf-8-sig")), s)
 
-    def test_decoder_state(self):
-        u = "\x00\x7f\x80\xff\u0100\u07ff\u0800\uffff\U0010ffff"
-        self.check_state_handling_decode(self.encoding,
-                                         u, u.encode(self.encoding))
+    def test_stream_bom(self):
+        unistring = "ABC\u00A1\u2200XYZ"
+        bytestring = codecs.BOM_UTF8 + b"ABC\xC2\xA1\xE2\x88\x80XYZ"
+
+        reader = codecs.getreader("utf-8-sig")
+        for sizehint in [None] + list(range(1, 11)) + \
+                        [64, 128, 256, 512, 1024]:
+            istream = reader(io.BytesIO(bytestring))
+            ostream = io.StringIO()
+            while 1:
+                if sizehint is not None:
+                    data = istream.read(sizehint)
+                else:
+                    data = istream.read()
+
+                if not data:
+                    break
+                ostream.write(data)
+
+            got = ostream.getvalue()
+            self.assertEqual(got, unistring)
+
+    def test_stream_bare(self):
+        unistring = "ABC\u00A1\u2200XYZ"
+        bytestring = b"ABC\xC2\xA1\xE2\x88\x80XYZ"
+
+        reader = codecs.getreader("utf-8-sig")
+        for sizehint in [None] + list(range(1, 11)) + \
+                        [64, 128, 256, 512, 1024]:
+            istream = reader(io.BytesIO(bytestring))
+            ostream = io.StringIO()
+            while 1:
+                if sizehint is not None:
+                    data = istream.read(sizehint)
+                else:
+                    data = istream.read()
+
+                if not data:
+                    break
+                ostream.write(data)
+
+            got = ostream.getvalue()
+            self.assertEqual(got, unistring)
+
+class EscapeDecodeTest(unittest.TestCase):
+    def test_empty(self):
+        self.assertEquals(codecs.escape_decode(""), ("", 0))
 
 class RecodingTest(unittest.TestCase):
     def test_recoding(self):
@@ -802,9 +855,10 @@
         if sys.maxunicode > 0xffff:
             codecs.register_error("UnicodeInternalTest", codecs.ignore_errors)
             decoder = codecs.getdecoder("unicode_internal")
-            ab = "ab".encode("unicode_internal")
-            ignored = decoder(bytes("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:])),
-                "UnicodeInternalTest")
+            ab = "ab".encode("unicode_internal").decode()
+            ignored = decoder(bytes("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:]),
+                                    "ascii"),
+                              "UnicodeInternalTest")
             self.assertEquals(("ab", 12), ignored)
 
 # From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html
@@ -1264,7 +1318,9 @@
                 encodedresult = b""
                 for c in s:
                     writer.write(c)
-                    encodedresult += q.read()
+                    chunk = q.read()
+                    self.assert_(type(chunk) is bytes, type(chunk))
+                    encodedresult += chunk
                 q = Queue(b"")
                 reader = codecs.getreader(encoding)(q)
                 decodedresult = ""

Modified: python/branches/py3k-importlib/Lib/test/test_coding.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_coding.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_coding.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,7 @@
 
 import test.test_support, unittest
-import os
+from test.test_support import TESTFN
+import os, sys
 
 class CodingTest(unittest.TestCase):
     def test_bad_coding(self):
@@ -26,6 +27,28 @@
         exec('# coding: cp949\na = 5\n', d)
         self.assertEqual(d['a'], 5)
 
+    def test_file_parse(self):
+        # issue1134: all encodings outside latin-1 and utf-8 fail on
+        # multiline strings and long lines (>512 columns)
+        if TESTFN in sys.modules:
+            del sys.modules[TESTFN]
+        sys.path.insert(0, ".")
+        filename = TESTFN + ".py"
+        f = open(filename, "w")
+        try:
+            f.write("# -*- coding: cp1252 -*-\n")
+            f.write("'''A short string\n")
+            f.write("'''\n")
+            f.write("'A very long string %s'\n" % ("X" * 1000))
+            f.close()
+
+            __import__(TESTFN)
+        finally:
+            f.close()
+            os.remove(TESTFN+".py")
+            os.remove(TESTFN+".pyc")
+            sys.path.pop(0)
+
 def test_main():
     test.test_support.run_unittest(CodingTest)
 

Modified: python/branches/py3k-importlib/Lib/test/test_collections.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_collections.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_collections.py	Thu Mar 27 00:48:05 2008
@@ -1,30 +1,45 @@
 """Unit tests for collections.py."""
 
-import unittest
+import unittest, doctest
 from test import test_support
-from collections import NamedTuple
+from collections import namedtuple
 from collections import Hashable, Iterable, Iterator
 from collections import Sized, Container, Callable
 from collections import Set, MutableSet
 from collections import Mapping, MutableMapping
 from collections import Sequence, MutableSequence
+from collections import ByteString
 
 
 class TestNamedTuple(unittest.TestCase):
 
     def test_factory(self):
-        Point = NamedTuple('Point', 'x y')
+        Point = namedtuple('Point', 'x y')
         self.assertEqual(Point.__name__, 'Point')
         self.assertEqual(Point.__doc__, 'Point(x, y)')
         self.assertEqual(Point.__slots__, ())
         self.assertEqual(Point.__module__, __name__)
         self.assertEqual(Point.__getitem__, tuple.__getitem__)
-        self.assertRaises(ValueError, NamedTuple, 'abc%', 'def ghi')
-        self.assertRaises(ValueError, NamedTuple, 'abc', 'def g%hi')
-        NamedTuple('Point0', 'x1 y2')   # Verify that numbers are allowed in names
+        self.assertEqual(Point._fields, ('x', 'y'))
+
+        self.assertRaises(ValueError, namedtuple, 'abc%', 'efg ghi')       # type has non-alpha char
+        self.assertRaises(ValueError, namedtuple, 'class', 'efg ghi')      # type has keyword
+        self.assertRaises(ValueError, namedtuple, '9abc', 'efg ghi')       # type starts with digit
+
+        self.assertRaises(ValueError, namedtuple, 'abc', 'efg g%hi')       # field with non-alpha char
+        self.assertRaises(ValueError, namedtuple, 'abc', 'abc class')      # field has keyword
+        self.assertRaises(ValueError, namedtuple, 'abc', '8efg 9ghi')      # field starts with digit
+        self.assertRaises(ValueError, namedtuple, 'abc', '_efg ghi')       # field with leading underscore
+        self.assertRaises(ValueError, namedtuple, 'abc', 'efg efg ghi')    # duplicate field
+
+        namedtuple('Point0', 'x1 y2')   # Verify that numbers are allowed in names
+        namedtuple('_', 'a b c')        # Test leading underscores in a typename
+
+        self.assertRaises(TypeError, Point._make, [11])                     # catch too few args
+        self.assertRaises(TypeError, Point._make, [11, 22, 33])             # catch too many args
 
     def test_instance(self):
-        Point = NamedTuple('Point', 'x y')
+        Point = namedtuple('Point', 'x y')
         p = Point(11, 22)
         self.assertEqual(p, Point(x=11, y=22))
         self.assertEqual(p, Point(11, y=22))
@@ -38,16 +53,30 @@
         self.assertEqual(repr(p), 'Point(x=11, y=22)')
         self.assert_('__dict__' not in dir(p))                              # verify instance has no dict
         self.assert_('__weakref__' not in dir(p))
-        self.assertEqual(p.__fields__, ('x', 'y'))                          # test __fields__ attribute
-        self.assertEqual(p.__replace__('x', 1), (1, 22))                    # test __replace__ method
+        self.assertEqual(p, Point._make([11, 22]))                          # test _make classmethod
+        self.assertEqual(p._fields, ('x', 'y'))                             # test _fields attribute
+        self.assertEqual(p._replace(x=1), (1, 22))                          # test _replace method
+        self.assertEqual(p._asdict(), dict(x=11, y=22))                     # test _asdict method
+
+        try:
+            p._replace(x=1, error=2)
+        except ValueError:
+            pass
+        else:
+            self._fail('Did not detect an incorrect fieldname')
 
         # verify that field string can have commas
-        Point = NamedTuple('Point', 'x, y')
+        Point = namedtuple('Point', 'x, y')
+        p = Point(x=11, y=22)
+        self.assertEqual(repr(p), 'Point(x=11, y=22)')
+
+        # verify that fieldspec can be a non-string sequence
+        Point = namedtuple('Point', ('x', 'y'))
         p = Point(x=11, y=22)
         self.assertEqual(repr(p), 'Point(x=11, y=22)')
 
     def test_tupleness(self):
-        Point = NamedTuple('Point', 'x y')
+        Point = namedtuple('Point', 'x y')
         p = Point(11, 22)
 
         self.assert_(isinstance(p, tuple))
@@ -66,17 +95,48 @@
         self.assertRaises(AttributeError, eval, 'p.z', locals())
 
     def test_odd_sizes(self):
-        Zero = NamedTuple('Zero', '')
+        Zero = namedtuple('Zero', '')
         self.assertEqual(Zero(), ())
-        Dot = NamedTuple('Dot', 'd')
-        self.assertEqual(Dot(1), (1,))
+        self.assertEqual(Zero._make([]), ())
+        self.assertEqual(repr(Zero()), 'Zero()')
+        self.assertEqual(Zero()._asdict(), {})
+        self.assertEqual(Zero()._fields, ())
 
+        Dot = namedtuple('Dot', 'd')
+        self.assertEqual(Dot(1), (1,))
+        self.assertEqual(Dot._make([1]), (1,))
+        self.assertEqual(Dot(1).d, 1)
+        self.assertEqual(repr(Dot(1)), 'Dot(d=1)')
+        self.assertEqual(Dot(1)._asdict(), {'d':1})
+        self.assertEqual(Dot(1)._replace(d=999), (999,))
+        self.assertEqual(Dot(1)._fields, ('d',))
+
+        # n = 10000
+        n = 254 # SyntaxError: more than 255 arguments:
+        import string, random
+        names = [''.join([random.choice(string.ascii_letters) for j in range(10)]) for i in range(n)]
+        Big = namedtuple('Big', names)
+        b = Big(*range(n))
+        self.assertEqual(b, tuple(range(n)))
+        self.assertEqual(Big._make(range(n)), tuple(range(n)))
+        for pos, name in enumerate(names):
+            self.assertEqual(getattr(b, name), pos)
+        repr(b)                                 # make sure repr() doesn't blow-up
+        d = b._asdict()
+        d_expected = dict(zip(names, range(n)))
+        self.assertEqual(d, d_expected)
+        b2 = b._replace(**dict([(names[1], 999),(names[-5], 42)]))
+        b2_expected = list(range(n))
+        b2_expected[1] = 999
+        b2_expected[-5] = 42
+        self.assertEqual(b2, tuple(b2_expected))
+        self.assertEqual(b._fields, tuple(names))
 
 class TestOneTrickPonyABCs(unittest.TestCase):
 
     def test_Hashable(self):
         # Check some non-hashables
-        non_samples = [bytes(), list(), set(), dict()]
+        non_samples = [bytearray(), list(), set(), dict()]
         for x in non_samples:
             self.failIf(isinstance(x, Hashable), repr(x))
             self.failIf(issubclass(type(x), Hashable), repr(type(x)))
@@ -85,7 +145,7 @@
                    int(), float(), complex(),
                    str(),
                    tuple(), frozenset(),
-                   int, list, object, type,
+                   int, list, object, type, bytes()
                    ]
         for x in samples:
             self.failUnless(isinstance(x, Hashable), repr(x))
@@ -235,21 +295,33 @@
         for sample in [tuple, list, bytes, str]:
             self.failUnless(isinstance(sample(), Sequence))
             self.failUnless(issubclass(sample, Sequence))
-        self.failUnless(issubclass(basestring, Sequence))
+        self.failUnless(issubclass(str, Sequence))
+
+    def test_ByteString(self):
+        for sample in [bytes, bytearray]:
+            self.failUnless(isinstance(sample(), ByteString))
+            self.failUnless(issubclass(sample, ByteString))
+        for sample in [str, list, tuple]:
+            self.failIf(isinstance(sample(), ByteString))
+            self.failIf(issubclass(sample, ByteString))
+        self.failIf(isinstance(memoryview(b""), ByteString))
+        self.failIf(issubclass(memoryview, ByteString))
 
     def test_MutableSequence(self):
-        for sample in [tuple, str]:
+        for sample in [tuple, str, bytes]:
             self.failIf(isinstance(sample(), MutableSequence))
             self.failIf(issubclass(sample, MutableSequence))
-        for sample in [list, bytes]:
+        for sample in [list, bytearray]:
             self.failUnless(isinstance(sample(), MutableSequence))
             self.failUnless(issubclass(sample, MutableSequence))
-        self.failIf(issubclass(basestring, MutableSequence))
+        self.failIf(issubclass(str, MutableSequence))
 
+import doctest, collections
+NamedTupleDocs = doctest.DocTestSuite(module=collections)
 
 def test_main(verbose=None):
     import collections as CollectionsModule
-    test_classes = [TestNamedTuple, TestOneTrickPonyABCs, TestCollectionABCs]
+    test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs, TestCollectionABCs]
     test_support.run_unittest(*test_classes)
     test_support.run_doctest(CollectionsModule, verbose)
 

Modified: python/branches/py3k-importlib/Lib/test/test_compare.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_compare.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_compare.py	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-import sys
 import unittest
 from test import test_support
 
@@ -16,6 +15,13 @@
     def __eq__(self, other):
         return self.arg == other
 
+class Anything:
+    def __eq__(self, other):
+        return True
+
+    def __ne__(self, other):
+        return False
+
 class ComparisonTest(unittest.TestCase):
     set1 = [2, 2.0, 2, 2+0j, Cmp(2.0)]
     set2 = [[1], (3,), None, Empty()]
@@ -45,6 +51,15 @@
         self.assertTrue(a == b)
         self.assertFalse(a != b)
 
+    def test_issue_1393(self):
+        x = lambda: None
+        self.assertEqual(x, Anything())
+        self.assertEqual(Anything(), x)
+        y = object()
+        self.assertEqual(y, Anything())
+        self.assertEqual(Anything(), y)
+
+
 def test_main():
     test_support.run_unittest(ComparisonTest)
 

Modified: python/branches/py3k-importlib/Lib/test/test_compile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_compile.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_compile.py	Thu Mar 27 00:48:05 2008
@@ -7,10 +7,10 @@
     def test_debug_assignment(self):
         # catch assignments to __debug__
         self.assertRaises(SyntaxError, compile, '__debug__ = 1', '?', 'single')
-        import __builtin__
-        prev = __builtin__.__debug__
-        setattr(__builtin__, '__debug__', 'sure')
-        setattr(__builtin__, '__debug__', prev)
+        import builtins
+        prev = builtins.__debug__
+        setattr(builtins, '__debug__', 'sure')
+        setattr(builtins, '__debug__', prev)
 
     def test_argument_handling(self):
         # detect duplicate positional and keyword arguments
@@ -157,7 +157,7 @@
         s256 = "".join(["\n"] * 256 + ["spam"])
         co = compile(s256, 'fn', 'exec')
         self.assertEqual(co.co_firstlineno, 257)
-        self.assertEqual(co.co_lnotab, '')
+        self.assertEqual(co.co_lnotab, bytes())
 
     def test_literals_with_leading_zeroes(self):
         for arg in ["077787", "0xj", "0x.", "0e",  "090000000000000",
@@ -194,24 +194,24 @@
 
     def test_unary_minus(self):
         # Verify treatment of unary minus on negative numbers SF bug #660455
-        if sys.maxint == 2147483647:
+        if sys.maxsize == 2147483647:
             # 32-bit machine
             all_one_bits = '0xffffffff'
             self.assertEqual(eval(all_one_bits), 4294967295)
             self.assertEqual(eval("-" + all_one_bits), -4294967295)
-        elif sys.maxint == 9223372036854775807:
+        elif sys.maxsize == 9223372036854775807:
             # 64-bit machine
             all_one_bits = '0xffffffffffffffff'
             self.assertEqual(eval(all_one_bits), 18446744073709551615)
             self.assertEqual(eval("-" + all_one_bits), -18446744073709551615)
         else:
             self.fail("How many bits *does* this machine have???")
-        # Verify treatment of contant folding on -(sys.maxint+1)
+        # Verify treatment of contant folding on -(sys.maxsize+1)
         # i.e. -2147483648 on 32 bit platforms.  Should return int, not long.
-        self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 1)), int))
-        self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 2)), int))
+        self.assertTrue(isinstance(eval("%s" % (-sys.maxsize - 1)), int))
+        self.assertTrue(isinstance(eval("%s" % (-sys.maxsize - 2)), int))
 
-    if sys.maxint == 9223372036854775807:
+    if sys.maxsize == 9223372036854775807:
         def test_32_63_bit_values(self):
             a = +4294967296  # 1 << 32
             b = -4294967296  # 1 << 32

Modified: python/branches/py3k-importlib/Lib/test/test_complex.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_complex.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_complex.py	Thu Mar 27 00:48:05 2008
@@ -2,7 +2,10 @@
 from test import test_support
 
 from random import random
+from math import atan2
 
+INF = float("inf")
+NAN = float("nan")
 # These tests ensure that complex math does the right thing
 
 class ComplexTest(unittest.TestCase):
@@ -207,6 +210,18 @@
         self.assertAlmostEqual(complex(real=17+23j, imag=23), 17+46j)
         self.assertAlmostEqual(complex(real=1+2j, imag=3+4j), -3+5j)
 
+        # check that the sign of a zero in the real or imaginary part
+        # is preserved when constructing from two floats.  (These checks
+        # are harmless on systems without support for signed zeros.)
+        def split_zeros(x):
+            """Function that produces different results for 0. and -0."""
+            return atan2(x, -1.)
+
+        self.assertEqual(split_zeros(complex(1., 0.).imag), split_zeros(0.))
+        self.assertEqual(split_zeros(complex(1., -0.).imag), split_zeros(-0.))
+        self.assertEqual(split_zeros(complex(0., 1.).real), split_zeros(0.))
+        self.assertEqual(split_zeros(complex(-0., 1.).real), split_zeros(-0.))
+
         c = 3.14 + 1j
         self.assert_(complex(c) is c)
         del c
@@ -303,6 +318,18 @@
         self.assertEqual(-6j,complex(repr(-6j)))
         self.assertEqual(6j,complex(repr(6j)))
 
+        self.assertEqual(repr(complex(1., INF)), "(1+inf*j)")
+        self.assertEqual(repr(complex(1., -INF)), "(1-inf*j)")
+        self.assertEqual(repr(complex(INF, 1)), "(inf+1j)")
+        self.assertEqual(repr(complex(-INF, INF)), "(-inf+inf*j)")
+        self.assertEqual(repr(complex(NAN, 1)), "(nan+1j)")
+        self.assertEqual(repr(complex(1, NAN)), "(1+nan*j)")
+        self.assertEqual(repr(complex(NAN, NAN)), "(nan+nan*j)")
+
+        self.assertEqual(repr(complex(0, INF)), "inf*j")
+        self.assertEqual(repr(complex(0, -INF)), "-inf*j")
+        self.assertEqual(repr(complex(0, NAN)), "nan*j")
+
     def test_neg(self):
         self.assertEqual(-(1+6j), -1-6j)
 
@@ -325,6 +352,13 @@
             except (OSError, IOError):
                 pass
 
+    if float.__getformat__("double").startswith("IEEE"):
+        def test_plus_minus_0j(self):
+            # test that -0j and 0j literals are not identified
+            z1, z2 = 0j, -0j
+            self.assertEquals(atan2(z1.imag, -1.), atan2(0., -1.))
+            self.assertEquals(atan2(z2.imag, -1.), atan2(-0., -1.))
+
 def test_main():
     test_support.run_unittest(ComplexTest)
 

Modified: python/branches/py3k-importlib/Lib/test/test_contains.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_contains.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_contains.py	Thu Mar 27 00:48:05 2008
@@ -1,103 +1,88 @@
-from test.test_support import TestFailed
+from test.test_support import run_unittest
+import unittest
 
-class base_set:
 
+class base_set:
     def __init__(self, el):
         self.el = el
 
 class set(base_set):
-
     def __contains__(self, el):
         return self.el == el
 
 class seq(base_set):
-
     def __getitem__(self, n):
         return [self.el][n]
 
-def check(ok, *args):
-    if not ok:
-        raise TestFailed(" ".join(map(str, args)))
-
-a = base_set(1)
-b = set(1)
-c = seq(1)
-
-check(1 in b, "1 not in set(1)")
-check(0 not in b, "0 in set(1)")
-check(1 in c, "1 not in seq(1)")
-check(0 not in c, "0 in seq(1)")
-
-try:
-    1 in a
-    check(0, "in base_set did not raise error")
-except TypeError:
-    pass
-
-try:
-    1 not in a
-    check(0, "not in base_set did not raise error")
-except TypeError:
-    pass
-
-# Test char in string
-
-check('c' in 'abc', "'c' not in 'abc'")
-check('d' not in 'abc', "'d' in 'abc'")
-
-check('' in '', "'' not in ''")
-check('' in 'abc', "'' not in 'abc'")
-
-try:
-    None in 'abc'
-    check(0, "None in 'abc' did not raise error")
-except TypeError:
-    pass
-
-
-# A collection of tests on builtin sequence types
-a = list(range(10))
-for i in a:
-    check(i in a, "%r not in %r" % (i, a))
-check(16 not in a, "16 not in %r" % (a,))
-check(a not in a, "%s not in %r" % (a, a))
-
-a = tuple(a)
-for i in a:
-    check(i in a, "%r not in %r" % (i, a))
-check(16 not in a, "16 not in %r" % (a,))
-check(a not in a, "%r not in %r" % (a, a))
-
-class Deviant1:
-    """Behaves strangely when compared
-
-    This class is designed to make sure that the contains code
-    works when the list is modified during the check.
-    """
-
-    aList = list(range(15))
-
-    def __cmp__(self, other):
-        if other == 12:
-            self.aList.remove(12)
-            self.aList.remove(13)
-            self.aList.remove(14)
-        return 1
-
-check(Deviant1() not in Deviant1.aList, "Deviant1 failed")
-
-class Deviant2:
-    """Behaves strangely when compared
-
-    This class raises an exception during comparison.  That in
-    turn causes the comparison to fail with a TypeError.
-    """
-
-    def __cmp__(self, other):
-        if other == 4:
-            raise RuntimeError("gotcha")
-
-try:
-    check(Deviant2() not in a, "oops")
-except TypeError:
-    pass
+class TestContains(unittest.TestCase):
+    def test_common_tests(self):
+        a = base_set(1)
+        b = set(1)
+        c = seq(1)
+        self.assert_(1 in b)
+        self.assert_(0 not in b)
+        self.assert_(1 in c)
+        self.assert_(0 not in c)
+        self.assertRaises(TypeError, lambda: 1 in a)
+        self.assertRaises(TypeError, lambda: 1 not in a)
+
+        # test char in string
+        self.assert_('c' in 'abc')
+        self.assert_('d' not in 'abc')
+
+        self.assert_('' in '')
+        self.assert_('' in 'abc')
+
+        self.assertRaises(TypeError, lambda: None in 'abc')
+
+    def test_builtin_sequence_types(self):
+        # a collection of tests on builtin sequence types
+        a = range(10)
+        for i in a:
+            self.assert_(i in a)
+        self.assert_(16 not in a)
+        self.assert_(a not in a)
+
+        a = tuple(a)
+        for i in a:
+            self.assert_(i in a)
+        self.assert_(16 not in a)
+        self.assert_(a not in a)
+
+        class Deviant1:
+            """Behaves strangely when compared
+
+            This class is designed to make sure that the contains code
+            works when the list is modified during the check.
+            """
+            aList = range(15)
+            def __cmp__(self, other):
+                if other == 12:
+                    self.aList.remove(12)
+                    self.aList.remove(13)
+                    self.aList.remove(14)
+                return 1
+
+        self.assert_(Deviant1() not in Deviant1.aList)
+
+        class Deviant2:
+            """Behaves strangely when compared
+
+            This class raises an exception during comparison.  That in
+            turn causes the comparison to fail with a TypeError.
+            """
+            def __cmp__(self, other):
+                if other == 4:
+                    raise RuntimeError("gotcha")
+
+        try:
+            self.assert_(Deviant2() not in a)
+        except TypeError:
+            pass
+
+
+def test_main():
+    run_unittest(TestContains)
+
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_copy.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_copy.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_copy.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,5 @@
 """Unit tests for the copy module."""
 
-import sys
 import copy
 import copy_reg
 

Modified: python/branches/py3k-importlib/Lib/test/test_crypt.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_crypt.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_crypt.py	Thu Mar 27 00:48:05 2008
@@ -1,11 +1,16 @@
-#! /usr/bin/env python
-"""Simple test script for cryptmodule.c
-   Roger E. Masse
-"""
-
-from test.test_support import verbose
+from test import test_support
+import unittest
 import crypt
 
-c = crypt.crypt('mypassword', 'ab')
-if verbose:
-    print('Test encryption: ', c)
+class CryptTestCase(unittest.TestCase):
+
+    def test_crypt(self):
+        c = crypt.crypt('mypassword', 'ab')
+        if test_support.verbose:
+            print('Test encryption: ', c)
+
+def test_main():
+    test_support.run_unittest(CryptTestCase)
+
+if __name__ == "__main__":
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_csv.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_csv.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_csv.py	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,7 @@
 import sys
 import os
 import unittest
-from io import StringIO
+from io import StringIO, BytesIO
 from tempfile import TemporaryFile
 import csv
 import gc
@@ -211,6 +211,10 @@
                           ['ab\0c'], None, strict = 1)
         self._read_test(['"ab"c'], [['abc']], doublequote = 0)
 
+        self.assertRaises(csv.Error, self._read_test,
+                          [b'ab\0c'], None)
+
+
     def test_read_eol(self):
         self._read_test(['a,b'], [['a','b']])
         self._read_test(['a,b\n'], [['a','b']])
@@ -375,7 +379,7 @@
 
 class TestCsvBase(unittest.TestCase):
     def readerAssertEqual(self, input, expected_result):
-        with TemporaryFile("w+") as fileobj:
+        with TemporaryFile("w+", newline='') as fileobj:
             fileobj.write(input)
             fileobj.seek(0)
             reader = csv.reader(fileobj, dialect = self.dialect)

Modified: python/branches/py3k-importlib/Lib/test/test_curses.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_curses.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_curses.py	Thu Mar 27 00:48:05 2008
@@ -269,13 +269,12 @@
     curses.wrapper(main)
     unit_tests()
 else:
+    # testing setupterm() inside initscr/endwin
+    # causes terminal breakage
+    curses.setupterm(fd=sys.__stdout__.fileno())
     try:
-        # testing setupterm() inside initscr/endwin
-        # causes terminal breakage
-        curses.setupterm(fd=sys.__stdout__.fileno())
         stdscr = curses.initscr()
         main(stdscr)
     finally:
         curses.endwin()
-
     unit_tests()

Modified: python/branches/py3k-importlib/Lib/test/test_datetime.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_datetime.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_datetime.py	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,6 @@
 """
 
 import os
-import sys
 import pickle
 import unittest
 
@@ -851,29 +850,29 @@
 
     def test_format(self):
         dt = self.theclass(2007, 9, 10)
-        self.assertEqual(format(dt, ''), str(dt))
+        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(format(a, ''), 'A')
+        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(format(b, ''), str(dt))
+        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(format(dt, fmt), dt.strftime(fmt))
-            self.assertEqual(format(a, fmt), dt.strftime(fmt))
-            self.assertEqual(format(b, fmt), 'B')
+            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):
         self.assert_(isinstance(self.theclass.min, self.theclass))
@@ -1093,7 +1092,7 @@
             self.assertEqual(orig, derived)
 
     def test_backdoor_resistance(self):
-        # For fast unpickling, the constructor accepts a pickle string.
+        # 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
@@ -1101,17 +1100,17 @@
         # 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 = '1995-03-25'
+        base = b'1995-03-25'
         if not issubclass(self.theclass, datetime):
             base = base[:4]
-        for month_byte in '9', chr(0), chr(13), '\xff':
+        for month_byte in b'9', b'\0', b'\r', b'\xff':
             self.assertRaises(TypeError, self.theclass,
                                          base[:2] + month_byte + base[3:])
         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(bytes(base[:2] + chr(ord_byte) + base[3:], "ascii"))
+            self.theclass(base[:2] + bytes([ord_byte]) + base[3:])
 
 #############################################################################
 # datetime tests
@@ -1178,31 +1177,29 @@
 
     def test_format(self):
         dt = self.theclass(2007, 9, 10, 4, 5, 1, 123)
-        self.assertEqual(format(dt, ''), str(dt))
+        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(format(a, ''), 'A')
+        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(format(b, ''), str(dt))
+        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(format(dt, fmt), dt.strftime(fmt))
-            self.assertEqual(format(a, fmt), dt.strftime(fmt))
-            self.assertEqual(format(b, fmt), 'B')
-
-
+            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.
@@ -1524,11 +1521,12 @@
         self.failUnless(abs(from_timestamp - from_now) <= tolerance)
 
     def test_strptime(self):
-        import time
+        import _strptime
 
-        string = '2004-12-01 13:02:47'
-        format = '%Y-%m-%d %H:%M:%S'
-        expected = self.theclass(*(time.strptime(string, format)[0:6]))
+        string = '2004-12-01 13:02:47.197'
+        format = '%Y-%m-%d %H:%M:%S.%f'
+        result, frac = _strptime._strptime(string, format)
+        expected = self.theclass(*(result[0:6]+(frac,)))
         got = self.theclass.strptime(string, format)
         self.assertEqual(expected, got)
 
@@ -1556,9 +1554,9 @@
 
     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)
-        self.assertEqual(t.strftime("%m %d %y %S %M %H %j"),
-                                    "12 31 04 33 22 06 366")
+        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)
@@ -1831,33 +1829,33 @@
 
     def test_strftime(self):
         t = self.theclass(1, 2, 3, 4)
-        self.assertEqual(t.strftime('%H %M %S'), "01 02 03")
+        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(format(t, ''), str(t))
+        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(format(a, ''), 'A')
+        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(format(b, ''), str(t))
+        self.assertEqual(b.__format__(''), str(t))
 
         for fmt in ['%H %M %S',
                     ]:
-            self.assertEqual(format(t, fmt), t.strftime(fmt))
-            self.assertEqual(format(a, fmt), t.strftime(fmt))
-            self.assertEqual(format(b, fmt), 'B')
+            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")

Modified: python/branches/py3k-importlib/Lib/test/test_dbm.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_dbm.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_dbm.py	Thu Mar 27 00:48:05 2008
@@ -1,56 +1,40 @@
-#! /usr/bin/env python
-"""Test script for the dbm module
-   Roger E. Masse
-"""
+from test import test_support
+import unittest
 import os
 import random
 import dbm
 from dbm import error
-from test.test_support import verbose, verify, TestSkipped, TESTFN
 
-# make filename unique to allow multiple concurrent tests
-# and to minimize the likelihood of a problem from an old file
-filename = TESTFN
-
-def cleanup():
-    for suffix in ['', '.pag', '.dir', '.db']:
-        try:
-            os.unlink(filename + suffix)
-        except OSError as e:
-            (errno, strerror) = e.errno, e.strerror
-            # if we can't delete the file because of permissions,
-            # nothing will work, so skip the test
-            if errno == 1:
-                raise TestSkipped('unable to remove: ' + filename + suffix)
-
-def test_keys():
-    d = dbm.open(filename, 'c')
-    verify(d.keys() == [])
-    d[b'a'] = b'b'
-    d[b'12345678910'] = b'019237410982340912840198242'
-    d.keys()
-    if b'a' in d:
-        if verbose:
-            print('Test dbm keys: ', d.keys())
-
-    d.close()
-
-def test_modes():
-    d = dbm.open(filename, 'r')
-    d.close()
-    d = dbm.open(filename, 'rw')
-    d.close()
-    d = dbm.open(filename, 'w')
-    d.close()
-    d = dbm.open(filename, 'n')
-    d.close()
-
-cleanup()
-try:
-    test_keys()
-    test_modes()
-except:
-    cleanup()
-    raise
+class DbmTestCase(unittest.TestCase):
 
-cleanup()
+    def setUp(self):
+        self.filename = test_support.TESTFN
+        self.d = dbm.open(self.filename, 'c')
+        self.d.close()
+
+    def tearDown(self):
+        for suffix in ['', '.pag', '.dir', '.db']:
+            test_support.unlink(self.filename + suffix)
+
+    def test_keys(self):
+        self.d = dbm.open(self.filename, 'c')
+        self.assert_(self.d.keys() == [])
+        self.d['a'] = 'b'
+        self.d['12345678910'] = '019237410982340912840198242'
+        self.d.keys()
+        self.assert_(b'a' in self.d)
+        self.d.close()
+
+    def test_modes(self):
+        for mode in ['r', 'rw', 'w', 'n']:
+            try:
+                self.d = dbm.open(self.filename, mode)
+                self.d.close()
+            except dbm.error:
+                self.fail()
+
+def test_main():
+    test_support.run_unittest(DbmTestCase)
+
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_decimal.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_decimal.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_decimal.py	Thu Mar 27 00:48:05 2008
@@ -25,10 +25,11 @@
 """
 from __future__ import with_statement
 
-import unittest
 import glob
+import math
 import os, sys
 import pickle, copy
+import unittest
 from decimal import *
 from test.test_support import (TestSkipped, run_unittest, run_doctest,
                                is_resource_enabled)
@@ -95,35 +96,61 @@
 
 # Name adapter to be able to change the Decimal and Context
 # interface without changing the test files from Cowlishaw
-nameAdapter = {'toeng':'to_eng_string',
-               'tosci':'to_sci_string',
-               'samequantum':'same_quantum',
-               'tointegral':'to_integral_value',
-               'tointegralx':'to_integral_exact',
-               'remaindernear':'remainder_near',
-               'divideint':'divide_int',
-               'squareroot':'sqrt',
+nameAdapter = {'and':'logical_and',
                'apply':'_apply',
                'class':'number_class',
                'comparesig':'compare_signal',
                'comparetotal':'compare_total',
                'comparetotmag':'compare_total_mag',
-               'copyabs':'copy_abs',
                'copy':'copy_decimal',
+               'copyabs':'copy_abs',
                'copynegate':'copy_negate',
                'copysign':'copy_sign',
-               'and':'logical_and',
-               'or':'logical_or',
-               'xor':'logical_xor',
+               'divideint':'divide_int',
                'invert':'logical_invert',
+               'iscanonical':'is_canonical',
+               'isfinite':'is_finite',
+               'isinfinite':'is_infinite',
+               'isnan':'is_nan',
+               'isnormal':'is_normal',
+               'isqnan':'is_qnan',
+               'issigned':'is_signed',
+               'issnan':'is_snan',
+               'issubnormal':'is_subnormal',
+               'iszero':'is_zero',
                'maxmag':'max_mag',
                'minmag':'min_mag',
                'nextminus':'next_minus',
                'nextplus':'next_plus',
                'nexttoward':'next_toward',
+               'or':'logical_or',
                'reduce':'normalize',
+               'remaindernear':'remainder_near',
+               'samequantum':'same_quantum',
+               'squareroot':'sqrt',
+               'toeng':'to_eng_string',
+               'tointegral':'to_integral_value',
+               'tointegralx':'to_integral_exact',
+               'tosci':'to_sci_string',
+               'xor':'logical_xor',
               }
 
+# The following functions return True/False rather than a Decimal instance
+
+LOGICAL_FUNCTIONS = (
+    'is_canonical',
+    'is_finite',
+    'is_infinite',
+    'is_nan',
+    'is_normal',
+    'is_qnan',
+    'is_signed',
+    'is_snan',
+    'is_subnormal',
+    'is_zero',
+    'same_quantum',
+    )
+
 # For some operations (currently exp, ln, log10, power), the decNumber
 # reference implementation imposes additional restrictions on the
 # context and operands.  These restrictions are not part of the
@@ -321,7 +348,7 @@
             print("--", self.context)
         try:
             result = str(funct(*vals))
-            if fname == 'same_quantum':
+            if fname in LOGICAL_FUNCTIONS:
                 result = str(int(eval(result))) # 'True', 'False' -> '1', '0'
         except Signals as error:
             self.fail("Raised %s in %s" % (error, s))
@@ -403,6 +430,10 @@
         #just not a number
         self.assertEqual(str(Decimal('ugly')), 'NaN')
 
+        #leading and trailing whitespace permitted
+        self.assertEqual(str(Decimal('1.3E4 \n')), '1.3E+4')
+        self.assertEqual(str(Decimal('  -7.89')), '-7.89')
+
     def test_explicit_from_tuples(self):
 
         #zero
@@ -426,13 +457,19 @@
 
         #bad sign
         self.assertRaises(ValueError, Decimal, (8, (4, 3, 4, 9, 1), 2) )
+        self.assertRaises(ValueError, Decimal, (0., (4, 3, 4, 9, 1), 2) )
+        self.assertRaises(ValueError, Decimal, (Decimal(1), (4, 3, 4, 9, 1), 2))
 
         #bad exp
         self.assertRaises(ValueError, Decimal, (1, (4, 3, 4, 9, 1), 'wrong!') )
+        self.assertRaises(ValueError, Decimal, (1, (4, 3, 4, 9, 1), 0.) )
+        self.assertRaises(ValueError, Decimal, (1, (4, 3, 4, 9, 1), '1') )
 
         #bad coefficients
         self.assertRaises(ValueError, Decimal, (1, (4, 3, 4, None, 1), 2) )
         self.assertRaises(ValueError, Decimal, (1, (4, -3, 4, 9, 1), 2) )
+        self.assertRaises(ValueError, Decimal, (1, (4, 10, 4, 9, 1), 2) )
+        self.assertRaises(ValueError, Decimal, (1, (4, 3, 4, 'a', 1), 2) )
 
     def test_explicit_from_Decimal(self):
 
@@ -485,6 +522,10 @@
         self.assertEqual(str(d), '456789')
         d = nc.create_decimal('456789')
         self.assertEqual(str(d), '4.57E+5')
+        # leading and trailing whitespace should result in a NaN;
+        # spaces are already checked in Cowlishaw's test-suite, so
+        # here we just check that a trailing newline results in a NaN
+        self.assertEqual(str(nc.create_decimal('3.14\n')), 'NaN')
 
         # from tuples
         d = Decimal( (1, (4, 3, 4, 9, 1, 3, 5, 3, 4), -25) )
@@ -569,6 +610,98 @@
             self.assertEqual(eval('Decimal(10)' + sym + 'E()'),
                              '10' + rop + 'str')
 
+class DecimalFormatTest(unittest.TestCase):
+    '''Unit tests for the format function.'''
+    def test_formatting(self):
+        # triples giving a format, a Decimal, and the expected result
+        test_values = [
+            ('e', '0E-15', '0e-15'),
+            ('e', '2.3E-15', '2.3e-15'),
+            ('e', '2.30E+2', '2.30e+2'), # preserve significant zeros
+            ('e', '2.30000E-15', '2.30000e-15'),
+            ('e', '1.23456789123456789e40', '1.23456789123456789e+40'),
+            ('e', '1.5', '1.5e+0'),
+            ('e', '0.15', '1.5e-1'),
+            ('e', '0.015', '1.5e-2'),
+            ('e', '0.0000000000015', '1.5e-12'),
+            ('e', '15.0', '1.50e+1'),
+            ('e', '-15', '-1.5e+1'),
+            ('e', '0', '0e+0'),
+            ('e', '0E1', '0e+1'),
+            ('e', '0.0', '0e-1'),
+            ('e', '0.00', '0e-2'),
+            ('.6e', '0E-15', '0.000000e-9'),
+            ('.6e', '0', '0.000000e+6'),
+            ('.6e', '9.999999', '9.999999e+0'),
+            ('.6e', '9.9999999', '1.000000e+1'),
+            ('.6e', '-1.23e5', '-1.230000e+5'),
+            ('.6e', '1.23456789e-3', '1.234568e-3'),
+            ('f', '0', '0'),
+            ('f', '0.0', '0.0'),
+            ('f', '0E-2', '0.00'),
+            ('f', '0.00E-8', '0.0000000000'),
+            ('f', '0E1', '0'), # loses exponent information
+            ('f', '3.2E1', '32'),
+            ('f', '3.2E2', '320'),
+            ('f', '3.20E2', '320'),
+            ('f', '3.200E2', '320.0'),
+            ('f', '3.2E-6', '0.0000032'),
+            ('.6f', '0E-15', '0.000000'), # all zeros treated equally
+            ('.6f', '0E1', '0.000000'),
+            ('.6f', '0', '0.000000'),
+            ('.0f', '0', '0'), # no decimal point
+            ('.0f', '0e-2', '0'),
+            ('.0f', '3.14159265', '3'),
+            ('.1f', '3.14159265', '3.1'),
+            ('.4f', '3.14159265', '3.1416'),
+            ('.6f', '3.14159265', '3.141593'),
+            ('.7f', '3.14159265', '3.1415926'), # round-half-even!
+            ('.8f', '3.14159265', '3.14159265'),
+            ('.9f', '3.14159265', '3.141592650'),
+
+            ('g', '0', '0'),
+            ('g', '0.0', '0.0'),
+            ('g', '0E1', '0e+1'),
+            ('G', '0E1', '0E+1'),
+            ('g', '0E-5', '0.00000'),
+            ('g', '0E-6', '0.000000'),
+            ('g', '0E-7', '0e-7'),
+            ('g', '-0E2', '-0e+2'),
+            ('.0g', '3.14159265', '3'),  # 0 sig fig -> 1 sig fig
+            ('.1g', '3.14159265', '3'),
+            ('.2g', '3.14159265', '3.1'),
+            ('.5g', '3.14159265', '3.1416'),
+            ('.7g', '3.14159265', '3.141593'),
+            ('.8g', '3.14159265', '3.1415926'), # round-half-even!
+            ('.9g', '3.14159265', '3.14159265'),
+            ('.10g', '3.14159265', '3.14159265'), # don't pad
+
+            ('%', '0E1', '0%'),
+            ('%', '0E0', '0%'),
+            ('%', '0E-1', '0%'),
+            ('%', '0E-2', '0%'),
+            ('%', '0E-3', '0.0%'),
+            ('%', '0E-4', '0.00%'),
+
+            ('.3%', '0', '0.000%'), # all zeros treated equally
+            ('.3%', '0E10', '0.000%'),
+            ('.3%', '0E-10', '0.000%'),
+            ('.3%', '2.34', '234.000%'),
+            ('.3%', '1.234567', '123.457%'),
+            ('.0%', '1.23', '123%'),
+
+            ('e', 'NaN', 'NaN'),
+            ('f', '-NaN123', '-NaN123'),
+            ('+g', 'NaN456', '+NaN456'),
+            ('.3e', 'Inf', 'Infinity'),
+            ('.16f', '-Inf', '-Infinity'),
+            ('.0g', '-sNaN', '-sNaN'),
+
+            ('', '1.00', '1.00'),
+            ]
+        for fmt, d, result in test_values:
+            self.assertEqual(format(Decimal(d), fmt), result)
+
 class DecimalArithmeticOperatorsTest(unittest.TestCase):
     '''Unit tests for all arithmetic operators, binary and unary.'''
 
@@ -792,27 +925,46 @@
         self.assertEqual(-Decimal(45), Decimal(-45))           #  -
         self.assertEqual(abs(Decimal(45)), abs(Decimal(-45)))  # abs
 
+    def test_nan_comparisons(self):
+        n = Decimal('NaN')
+        s = Decimal('sNaN')
+        i = Decimal('Inf')
+        f = Decimal('2')
+        for x, y in [(n, n), (n, i), (i, n), (n, f), (f, n),
+                     (s, n), (n, s), (s, i), (i, s), (s, f), (f, s), (s, s)]:
+            self.assert_(x != y)
+            self.assert_(not (x == y))
+            self.assert_(not (x < y))
+            self.assert_(not (x <= y))
+            self.assert_(not (x > y))
+            self.assert_(not (x >= y))
 
 # The following are two functions used to test threading in the next class
 
 def thfunc1(cls):
     d1 = Decimal(1)
     d3 = Decimal(3)
-    cls.assertEqual(d1/d3, Decimal('0.333333333'))
+    test1 = d1/d3
     cls.synchro.wait()
-    cls.assertEqual(d1/d3, Decimal('0.333333333'))
+    test2 = d1/d3
     cls.finish1.set()
+
+    cls.assertEqual(test1, Decimal('0.333333333'))
+    cls.assertEqual(test2, Decimal('0.333333333'))
     return
 
 def thfunc2(cls):
     d1 = Decimal(1)
     d3 = Decimal(3)
-    cls.assertEqual(d1/d3, Decimal('0.333333333'))
+    test1 = d1/d3
     thiscontext = getcontext()
     thiscontext.prec = 18
-    cls.assertEqual(d1/d3, Decimal('0.333333333333333333'))
+    test2 = d1/d3
     cls.synchro.set()
     cls.finish2.set()
+
+    cls.assertEqual(test1, Decimal('0.333333333'))
+    cls.assertEqual(test2, Decimal('0.333333333333333333'))
     return
 
 
@@ -939,6 +1091,23 @@
         self.assert_(hash(Decimal('Inf')))
         self.assert_(hash(Decimal('-Inf')))
 
+        # check that the value of the hash doesn't depend on the
+        # current context (issue #1757)
+        c = getcontext()
+        old_precision = c.prec
+        x = Decimal("123456789.1")
+
+        c.prec = 6
+        h1 = hash(x)
+        c.prec = 10
+        h2 = hash(x)
+        c.prec = 16
+        h3 = hash(x)
+
+        self.assertEqual(h1, h2)
+        self.assertEqual(h1, h3)
+        c.prec = old_precision
+
     def test_min_and_max_methods(self):
 
         d1 = Decimal('15.32')
@@ -969,7 +1138,7 @@
 
         d = Decimal('15.32')
         self.assertEqual(str(d), '15.32')               # str
-        self.assertEqual(repr(d), 'Decimal("15.32")')   # repr
+        self.assertEqual(repr(d), "Decimal('15.32')")   # repr
 
     def test_tonum_methods(self):
         #Test float, int and long methods.
@@ -1025,6 +1194,28 @@
         d = Decimal("Infinity")
         self.assertEqual(d.as_tuple(), (0, (0,), 'F') )
 
+        #leading zeros in coefficient should be stripped
+        d = Decimal( (0, (0, 0, 4, 0, 5, 3, 4), -2) )
+        self.assertEqual(d.as_tuple(), (0, (4, 0, 5, 3, 4), -2) )
+        d = Decimal( (1, (0, 0, 0), 37) )
+        self.assertEqual(d.as_tuple(), (1, (0,), 37))
+        d = Decimal( (1, (), 37) )
+        self.assertEqual(d.as_tuple(), (1, (0,), 37))
+
+        #leading zeros in NaN diagnostic info should be stripped
+        d = Decimal( (0, (0, 0, 4, 0, 5, 3, 4), 'n') )
+        self.assertEqual(d.as_tuple(), (0, (4, 0, 5, 3, 4), 'n') )
+        d = Decimal( (1, (0, 0, 0), 'N') )
+        self.assertEqual(d.as_tuple(), (1, (), 'N') )
+        d = Decimal( (1, (), 'n') )
+        self.assertEqual(d.as_tuple(), (1, (), 'n') )
+
+        #coefficient in infinity should be ignored
+        d = Decimal( (0, (4, 5, 3, 4), 'F') )
+        self.assertEqual(d.as_tuple(), (0, (0,), 'F'))
+        d = Decimal( (1, (0, 2, 7, 1), 'F') )
+        self.assertEqual(d.as_tuple(), (1, (0,), 'F'))
+
     def test_immutability_operations(self):
         # Do operations and check that it didn't change change internal objects.
 
@@ -1057,11 +1248,17 @@
         checkSameDec("__abs__")
         checkSameDec("__add__", True)
         checkSameDec("__divmod__", True)
-        checkSameDec("__cmp__", True)
+        checkSameDec("__eq__", True)
+        checkSameDec("__ne__", True)
+        checkSameDec("__le__", True)
+        checkSameDec("__lt__", True)
+        checkSameDec("__ge__", True)
+        checkSameDec("__gt__", True)
         checkSameDec("__float__")
         checkSameDec("__floordiv__", True)
         checkSameDec("__hash__")
         checkSameDec("__int__")
+        checkSameDec("__trunc__")
         checkSameDec("__mod__", True)
         checkSameDec("__mul__", True)
         checkSameDec("__neg__")
@@ -1125,6 +1322,16 @@
             r = d.to_integral(ROUND_DOWN)
             self.assertEqual(Decimal(int(d)), r)
 
+    def test_trunc(self):
+        for x in range(-250, 250):
+            s = '%0.2f' % (x / 100.0)
+            # should work the same as for floats
+            self.assertEqual(int(Decimal(s)), int(float(s)))
+            # should work the same as to_integral in the ROUND_DOWN mode
+            d = Decimal(s)
+            r = d.to_integral(ROUND_DOWN)
+            self.assertEqual(Decimal(math.trunc(d)), r)
+
 class ContextAPItests(unittest.TestCase):
 
     def test_pickle(self):
@@ -1242,6 +1449,7 @@
             DecimalExplicitConstructionTest,
             DecimalImplicitConstructionTest,
             DecimalArithmeticOperatorsTest,
+            DecimalFormatTest,
             DecimalUseOfContextTest,
             DecimalUsabilityTest,
             DecimalPythonAPItests,

Modified: python/branches/py3k-importlib/Lib/test/test_defaultdict.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_defaultdict.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_defaultdict.py	Thu Mar 27 00:48:05 2008
@@ -141,6 +141,29 @@
         else:
             self.fail("expected KeyError")
 
+    def test_recursive_repr(self):
+        # Issue2045: stack overflow when default_factory is a bound method
+        class sub(defaultdict):
+            def __init__(self):
+                self.default_factory = self._factory
+            def _factory(self):
+                return []
+        d = sub()
+        self.assert_(repr(d).startswith(
+            "defaultdict(<bound method sub._factory of defaultdict(..."))
+
+        # NOTE: printing a subclass of a builtin type does not call its
+        # tp_print slot. So this part is essentially the same test as above.
+        tfn = tempfile.mktemp()
+        try:
+            f = open(tfn, "w+")
+            try:
+                print(d, file=f)
+            finally:
+                f.close()
+        finally:
+            os.remove(tfn)
+
 
 def test_main():
     test_support.run_unittest(TestDefaultDict)

Modified: python/branches/py3k-importlib/Lib/test/test_deque.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_deque.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_deque.py	Thu Mar 27 00:48:05 2008
@@ -29,8 +29,8 @@
 class TestBasic(unittest.TestCase):
 
     def test_basics(self):
-        d = deque(range(100))
-        d.__init__(range(100, 200))
+        d = deque(range(-5125, -5000))
+        d.__init__(range(200))
         for i in range(200, 400):
             d.append(i)
         for i in reversed(range(-200, 0)):
@@ -47,6 +47,26 @@
         self.assertEqual(right, list(range(150, 400)))
         self.assertEqual(list(d), list(range(50, 150)))
 
+    def test_maxlen(self):
+        self.assertRaises(ValueError, deque, 'abc', -1)
+        self.assertRaises(ValueError, deque, 'abc', -2)
+        d = deque(range(10), maxlen=3)
+        self.assertEqual(repr(d), 'deque([7, 8, 9], maxlen=3)')
+        self.assertEqual(list(d), [7, 8, 9])
+        self.assertEqual(d, deque(range(10), 3))
+        d.append(10)
+        self.assertEqual(list(d), [8, 9, 10])
+        d.appendleft(7)
+        self.assertEqual(list(d), [7, 8, 9])
+        d.extend([10, 11])
+        self.assertEqual(list(d), [9, 10, 11])
+        d.extendleft([8, 7])
+        self.assertEqual(list(d), [7, 8, 9])
+        d = deque(range(200), maxlen=10)
+        d.append(d)
+        d = deque(range(10), maxlen=None)
+        self.assertEqual(repr(d), 'deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])')
+
     def test_comparisons(self):
         d = deque('xabc'); d.popleft()
         for e in [d, deque('abc'), deque('ab'), deque(), list(d)]:
@@ -254,7 +274,7 @@
             os.remove(test_support.TESTFN)
 
     def test_init(self):
-        self.assertRaises(TypeError, deque, 'abc', 2);
+        self.assertRaises(TypeError, deque, 'abc', 2, 3);
         self.assertRaises(TypeError, deque, 1);
 
     def test_hash(self):
@@ -340,13 +360,13 @@
             self.assertNotEqual(id(d), id(e))
             self.assertEqual(list(d), list(e))
 
-    def test_pickle_recursive(self):
-        d = deque('abc')
-        d.append(d)
-        for i in (0, 1, 2):
-            e = pickle.loads(pickle.dumps(d, i))
-            self.assertNotEqual(id(d), id(e))
-            self.assertEqual(id(e), id(e[-1]))
+##    def test_pickle_recursive(self):
+##        d = deque('abc')
+##        d.append(d)
+##        for i in (0, 1, 2):
+##            e = pickle.loads(pickle.dumps(d, i))
+##            self.assertNotEqual(id(d), id(e))
+##            self.assertEqual(id(e), id(e[-1]))
 
     def test_deepcopy(self):
         mut = [10]
@@ -413,8 +433,8 @@
 class TestSubclass(unittest.TestCase):
 
     def test_basics(self):
-        d = Deque(range(100))
-        d.__init__(range(100, 200))
+        d = Deque(range(25))
+        d.__init__(range(200))
         for i in range(200, 400):
             d.append(i)
         for i in reversed(range(-200, 0)):
@@ -452,24 +472,40 @@
         self.assertEqual(type(d), type(e))
         self.assertEqual(list(d), list(e))
 
-    def test_pickle(self):
-        d = Deque('abc')
-        d.append(d)
+        d = Deque('abcde', maxlen=4)
 
-        e = pickle.loads(pickle.dumps(d))
+        e = d.__copy__()
+        self.assertEqual(type(d), type(e))
+        self.assertEqual(list(d), list(e))
+
+        e = Deque(d)
+        self.assertEqual(type(d), type(e))
+        self.assertEqual(list(d), list(e))
+
+        s = pickle.dumps(d)
+        e = pickle.loads(s)
         self.assertNotEqual(id(d), id(e))
         self.assertEqual(type(d), type(e))
-        dd = d.pop()
-        ee = e.pop()
-        self.assertEqual(id(e), id(ee))
-        self.assertEqual(d, e)
-
-        d.x = d
-        e = pickle.loads(pickle.dumps(d))
-        self.assertEqual(id(e), id(e.x))
+        self.assertEqual(list(d), list(e))
 
-        d = DequeWithBadIter('abc')
-        self.assertRaises(TypeError, pickle.dumps, d)
+##    def test_pickle(self):
+##        d = Deque('abc')
+##        d.append(d)
+##
+##        e = pickle.loads(pickle.dumps(d))
+##        self.assertNotEqual(id(d), id(e))
+##        self.assertEqual(type(d), type(e))
+##        dd = d.pop()
+##        ee = e.pop()
+##        self.assertEqual(id(e), id(ee))
+##        self.assertEqual(d, e)
+##
+##        d.x = d
+##        e = pickle.loads(pickle.dumps(d))
+##        self.assertEqual(id(e), id(e.x))
+##
+##        d = DequeWithBadIter('abc')
+##        self.assertRaises(TypeError, pickle.dumps, d)
 
     def test_weakref(self):
         d = deque('gallahad')

Modified: python/branches/py3k-importlib/Lib/test/test_descr.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_descr.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_descr.py	Thu Mar 27 00:48:05 2008
@@ -1,4078 +1,3997 @@
-# Test enhancements related to descriptors and new-style classes
+import types
+import unittest
+import warnings
 
-from test.test_support import verify, vereq, verbose, TestFailed, TESTFN
-from test.test_support import get_original_stdout
 from copy import deepcopy
-import types
-import new
+from test import test_support
+
+
+class OperatorsTest(unittest.TestCase):
+
+    def __init__(self, *args, **kwargs):
+        unittest.TestCase.__init__(self, *args, **kwargs)
+        self.binops = {
+            'add': '+',
+            'sub': '-',
+            'mul': '*',
+            'div': '/',
+            'divmod': 'divmod',
+            'pow': '**',
+            'lshift': '<<',
+            'rshift': '>>',
+            'and': '&',
+            'xor': '^',
+            'or': '|',
+            'cmp': 'cmp',
+            'lt': '<',
+            'le': '<=',
+            'eq': '==',
+            'ne': '!=',
+            'gt': '>',
+            'ge': '>=',
+        }
+
+        for name, expr in list(self.binops.items()):
+            if expr.islower():
+                expr = expr + "(a, b)"
+            else:
+                expr = 'a %s b' % expr
+            self.binops[name] = expr
+
+        self.unops = {
+            'pos': '+',
+            'neg': '-',
+            'abs': 'abs',
+            'invert': '~',
+            'int': 'int',
+            'float': 'float',
+            'oct': 'oct',
+            'hex': 'hex',
+        }
+
+        for name, expr in list(self.unops.items()):
+            if expr.islower():
+                expr = expr + "(a)"
+            else:
+                expr = '%s a' % expr
+            self.unops[name] = expr
+
+    def unop_test(self, a, res, expr="len(a)", meth="__len__"):
+        d = {'a': a}
+        self.assertEqual(eval(expr, d), res)
+        t = type(a)
+        m = getattr(t, meth)
+
+        # Find method in parent class
+        while meth not in t.__dict__:
+            t = t.__bases__[0]
+
+        self.assertEqual(m, t.__dict__[meth])
+        self.assertEqual(m(a), res)
+        bm = getattr(a, meth)
+        self.assertEqual(bm(), res)
+
+    def binop_test(self, a, b, res, expr="a+b", meth="__add__"):
+        d = {'a': a, 'b': b}
+
+        # XXX Hack so this passes before 2.3 when -Qnew is specified.
+        if meth == "__div__" and 1/2 == 0.5:
+            meth = "__truediv__"
+
+        if meth == '__divmod__': pass
+
+        self.assertEqual(eval(expr, d), res)
+        t = type(a)
+        m = getattr(t, meth)
+        while meth not in t.__dict__:
+            t = t.__bases__[0]
+        self.assertEqual(m, t.__dict__[meth])
+        self.assertEqual(m(a, b), res)
+        bm = getattr(a, meth)
+        self.assertEqual(bm(b), res)
+
+    def sliceop_test(self, a, b, c, res, expr="a[b:c]", meth="__getitem__"):
+        d = {'a': a, 'b': b, 'c': c}
+        self.assertEqual(eval(expr, d), res)
+        t = type(a)
+        m = getattr(t, meth)
+        while meth not in t.__dict__:
+            t = t.__bases__[0]
+        self.assertEqual(m, t.__dict__[meth])
+        self.assertEqual(m(a, slice(b, c)), res)
+        bm = getattr(a, meth)
+        self.assertEqual(bm(slice(b, c)), res)
+
+    def setop_test(self, a, b, res, stmt="a+=b", meth="__iadd__"):
+        d = {'a': deepcopy(a), 'b': b}
+        exec(stmt, d)
+        self.assertEqual(d['a'], res)
+        t = type(a)
+        m = getattr(t, meth)
+        while meth not in t.__dict__:
+            t = t.__bases__[0]
+        self.assertEqual(m, t.__dict__[meth])
+        d['a'] = deepcopy(a)
+        m(d['a'], b)
+        self.assertEqual(d['a'], res)
+        d['a'] = deepcopy(a)
+        bm = getattr(d['a'], meth)
+        bm(b)
+        self.assertEqual(d['a'], res)
+
+    def set2op_test(self, a, b, c, res, stmt="a[b]=c", meth="__setitem__"):
+        d = {'a': deepcopy(a), 'b': b, 'c': c}
+        exec(stmt, d)
+        self.assertEqual(d['a'], res)
+        t = type(a)
+        m = getattr(t, meth)
+        while meth not in t.__dict__:
+            t = t.__bases__[0]
+        self.assertEqual(m, t.__dict__[meth])
+        d['a'] = deepcopy(a)
+        m(d['a'], b, c)
+        self.assertEqual(d['a'], res)
+        d['a'] = deepcopy(a)
+        bm = getattr(d['a'], meth)
+        bm(b, c)
+        self.assertEqual(d['a'], res)
+
+    def setsliceop_test(self, a, b, c, d, res, stmt="a[b:c]=d", meth="__setitem__"):
+        dictionary = {'a': deepcopy(a), 'b': b, 'c': c, 'd': d}
+        exec(stmt, dictionary)
+        self.assertEqual(dictionary['a'], res)
+        t = type(a)
+        while meth not in t.__dict__:
+            t = t.__bases__[0]
+        m = getattr(t, meth)
+        self.assertEqual(m, t.__dict__[meth])
+        dictionary['a'] = deepcopy(a)
+        m(dictionary['a'], slice(b, c), d)
+        self.assertEqual(dictionary['a'], res)
+        dictionary['a'] = deepcopy(a)
+        bm = getattr(dictionary['a'], meth)
+        bm(slice(b, c), d)
+        self.assertEqual(dictionary['a'], res)
+
+    def test_lists(self):
+        # Testing list operations...
+        # Asserts are within individual test methods
+        self.binop_test([1], [2], [1,2], "a+b", "__add__")
+        self.binop_test([1,2,3], 2, 1, "b in a", "__contains__")
+        self.binop_test([1,2,3], 4, 0, "b in a", "__contains__")
+        self.binop_test([1,2,3], 1, 2, "a[b]", "__getitem__")
+        self.sliceop_test([1,2,3], 0, 2, [1,2], "a[b:c]", "__getitem__")
+        self.setop_test([1], [2], [1,2], "a+=b", "__iadd__")
+        self.setop_test([1,2], 3, [1,2,1,2,1,2], "a*=b", "__imul__")
+        self.unop_test([1,2,3], 3, "len(a)", "__len__")
+        self.binop_test([1,2], 3, [1,2,1,2,1,2], "a*b", "__mul__")
+        self.binop_test([1,2], 3, [1,2,1,2,1,2], "b*a", "__rmul__")
+        self.set2op_test([1,2], 1, 3, [1,3], "a[b]=c", "__setitem__")
+        self.setsliceop_test([1,2,3,4], 1, 3, [5,6], [1,5,6,4], "a[b:c]=d",
+                        "__setitem__")
+
+    def test_dicts(self):
+        # Testing dict operations...
+        ## self.binop_test({1:2}, {2:1}, -1, "cmp(a,b)", "__cmp__")
+        self.binop_test({1:2,3:4}, 1, 1, "b in a", "__contains__")
+        self.binop_test({1:2,3:4}, 2, 0, "b in a", "__contains__")
+        self.binop_test({1:2,3:4}, 1, 2, "a[b]", "__getitem__")
+
+        d = {1:2, 3:4}
+        l1 = []
+        for i in list(d.keys()):
+            l1.append(i)
+        l = []
+        for i in iter(d):
+            l.append(i)
+        self.assertEqual(l, l1)
+        l = []
+        for i in d.__iter__():
+            l.append(i)
+        self.assertEqual(l, l1)
+        l = []
+        for i in dict.__iter__(d):
+            l.append(i)
+        self.assertEqual(l, l1)
+        d = {1:2, 3:4}
+        self.unop_test(d, 2, "len(a)", "__len__")
+        self.assertEqual(eval(repr(d), {}), d)
+        self.assertEqual(eval(d.__repr__(), {}), d)
+        self.set2op_test({1:2,3:4}, 2, 3, {1:2,2:3,3:4}, "a[b]=c",
+                        "__setitem__")
+
+    # Tests for unary and binary operators
+    def number_operators(self, a, b, skip=[]):
+        dict = {'a': a, 'b': b}
+
+        for name, expr in list(self.binops.items()):
+            if name not in skip:
+                name = "__%s__" % name
+                if hasattr(a, name):
+                    res = eval(expr, dict)
+                    self.binop_test(a, b, res, expr, name)
+
+        for name, expr in list(self.unops.items()):
+            if name not in skip:
+                name = "__%s__" % name
+                if hasattr(a, name):
+                    res = eval(expr, dict)
+                    self.unop_test(a, res, expr, name)
+
+    def test_ints(self):
+        # Testing int operations...
+        self.number_operators(100, 3)
+        # The following crashes in Python 2.2
+        self.assertEqual((1).__bool__(), 1)
+        self.assertEqual((0).__bool__(), 0)
+        # This returns 'NotImplemented' in Python 2.2
+        class C(int):
+            def __add__(self, other):
+                return NotImplemented
+        self.assertEqual(C(5), 5)
+        try:
+            C() + ""
+        except TypeError:
+            pass
+        else:
+            self.fail("NotImplemented should have caused TypeError")
+
+    def test_longs(self):
+        # Testing long operations...
+        self.number_operators(100, 3)
+
+    def test_floats(self):
+        # Testing float operations...
+        self.number_operators(100.0, 3.0)
+
+    def test_complexes(self):
+        # Testing complex operations...
+        self.number_operators(100.0j, 3.0j, skip=['lt', 'le', 'gt', 'ge',
+                                                  'int', 'long', 'float',
+                                                  'divmod', 'mod'])
+
+        class Number(complex):
+            __slots__ = ['prec']
+            def __new__(cls, *args, **kwds):
+                result = complex.__new__(cls, *args)
+                result.prec = kwds.get('prec', 12)
+                return result
+            def __repr__(self):
+                prec = self.prec
+                if self.imag == 0.0:
+                    return "%.*g" % (prec, self.real)
+                if self.real == 0.0:
+                    return "%.*gj" % (prec, self.imag)
+                return "(%.*g+%.*gj)" % (prec, self.real, prec, self.imag)
+            __str__ = __repr__
+
+        a = Number(3.14, prec=6)
+        self.assertEqual(repr(a), "3.14")
+        self.assertEqual(a.prec, 6)
+
+        a = Number(a, prec=2)
+        self.assertEqual(repr(a), "3.1")
+        self.assertEqual(a.prec, 2)
+
+        a = Number(234.5)
+        self.assertEqual(repr(a), "234.5")
+        self.assertEqual(a.prec, 12)
+
+    def test_spam_lists(self):
+        # Testing spamlist operations...
+        import copy, xxsubtype as spam
+
+        def spamlist(l, memo=None):
+            import xxsubtype as spam
+            return spam.spamlist(l)
+
+        # This is an ugly hack:
+        copy._deepcopy_dispatch[spam.spamlist] = spamlist
+
+        self.binop_test(spamlist([1]), spamlist([2]), spamlist([1,2]), "a+b",
+                       "__add__")
+        self.binop_test(spamlist([1,2,3]), 2, 1, "b in a", "__contains__")
+        self.binop_test(spamlist([1,2,3]), 4, 0, "b in a", "__contains__")
+        self.binop_test(spamlist([1,2,3]), 1, 2, "a[b]", "__getitem__")
+        self.sliceop_test(spamlist([1,2,3]), 0, 2, spamlist([1,2]), "a[b:c]",
+                          "__getitem__")
+        self.setop_test(spamlist([1]), spamlist([2]), spamlist([1,2]), "a+=b",
+                        "__iadd__")
+        self.setop_test(spamlist([1,2]), 3, spamlist([1,2,1,2,1,2]), "a*=b",
+                        "__imul__")
+        self.unop_test(spamlist([1,2,3]), 3, "len(a)", "__len__")
+        self.binop_test(spamlist([1,2]), 3, spamlist([1,2,1,2,1,2]), "a*b",
+                        "__mul__")
+        self.binop_test(spamlist([1,2]), 3, spamlist([1,2,1,2,1,2]), "b*a",
+                        "__rmul__")
+        self.set2op_test(spamlist([1,2]), 1, 3, spamlist([1,3]), "a[b]=c",
+                         "__setitem__")
+        self.setsliceop_test(spamlist([1,2,3,4]), 1, 3, spamlist([5,6]),
+                             spamlist([1,5,6,4]), "a[b:c]=d", "__setitem__")
+        # Test subclassing
+        class C(spam.spamlist):
+            def foo(self): return 1
+        a = C()
+        self.assertEqual(a, [])
+        self.assertEqual(a.foo(), 1)
+        a.append(100)
+        self.assertEqual(a, [100])
+        self.assertEqual(a.getstate(), 0)
+        a.setstate(42)
+        self.assertEqual(a.getstate(), 42)
+
+    def test_spam_dicts(self):
+        # Testing spamdict operations...
+        import copy, xxsubtype as spam
+        def spamdict(d, memo=None):
+            import xxsubtype as spam
+            sd = spam.spamdict()
+            for k, v in list(d.items()):
+                sd[k] = v
+            return sd
+        # This is an ugly hack:
+        copy._deepcopy_dispatch[spam.spamdict] = spamdict
+
+        ## self.binop_test(spamdict({1:2}), spamdict({2:1}), -1, "cmp(a,b)",
+        ##                 "__cmp__")
+        self.binop_test(spamdict({1:2,3:4}), 1, 1, "b in a", "__contains__")
+        self.binop_test(spamdict({1:2,3:4}), 2, 0, "b in a", "__contains__")
+        self.binop_test(spamdict({1:2,3:4}), 1, 2, "a[b]", "__getitem__")
+        d = spamdict({1:2,3:4})
+        l1 = []
+        for i in list(d.keys()):
+            l1.append(i)
+        l = []
+        for i in iter(d):
+            l.append(i)
+        self.assertEqual(l, l1)
+        l = []
+        for i in d.__iter__():
+            l.append(i)
+        self.assertEqual(l, l1)
+        l = []
+        for i in type(spamdict({})).__iter__(d):
+            l.append(i)
+        self.assertEqual(l, l1)
+        straightd = {1:2, 3:4}
+        spamd = spamdict(straightd)
+        self.unop_test(spamd, 2, "len(a)", "__len__")
+        self.unop_test(spamd, repr(straightd), "repr(a)", "__repr__")
+        self.set2op_test(spamdict({1:2,3:4}), 2, 3, spamdict({1:2,2:3,3:4}),
+                   "a[b]=c", "__setitem__")
+        # Test subclassing
+        class C(spam.spamdict):
+            def foo(self): return 1
+        a = C()
+        self.assertEqual(list(a.items()), [])
+        self.assertEqual(a.foo(), 1)
+        a['foo'] = 'bar'
+        self.assertEqual(list(a.items()), [('foo', 'bar')])
+        self.assertEqual(a.getstate(), 0)
+        a.setstate(100)
+        self.assertEqual(a.getstate(), 100)
+
+class ClassPropertiesAndMethods(unittest.TestCase):
+
+    def test_python_dicts(self):
+        # Testing Python subclass of dict...
+        self.assert_(issubclass(dict, dict))
+        self.assert_(isinstance({}, dict))
+        d = dict()
+        self.assertEqual(d, {})
+        self.assert_(d.__class__ is dict)
+        self.assert_(isinstance(d, dict))
+        class C(dict):
+            state = -1
+            def __init__(self_local, *a, **kw):
+                if a:
+                    self.assertEqual(len(a), 1)
+                    self_local.state = a[0]
+                if kw:
+                    for k, v in list(kw.items()):
+                        self_local[v] = k
+            def __getitem__(self, key):
+                return self.get(key, 0)
+            def __setitem__(self_local, key, value):
+                self.assert_(isinstance(key, type(0)))
+                dict.__setitem__(self_local, key, value)
+            def setstate(self, state):
+                self.state = state
+            def getstate(self):
+                return self.state
+        self.assert_(issubclass(C, dict))
+        a1 = C(12)
+        self.assertEqual(a1.state, 12)
+        a2 = C(foo=1, bar=2)
+        self.assertEqual(a2[1] == 'foo' and a2[2], 'bar')
+        a = C()
+        self.assertEqual(a.state, -1)
+        self.assertEqual(a.getstate(), -1)
+        a.setstate(0)
+        self.assertEqual(a.state, 0)
+        self.assertEqual(a.getstate(), 0)
+        a.setstate(10)
+        self.assertEqual(a.state, 10)
+        self.assertEqual(a.getstate(), 10)
+        self.assertEqual(a[42], 0)
+        a[42] = 24
+        self.assertEqual(a[42], 24)
+        N = 50
+        for i in range(N):
+            a[i] = C()
+            for j in range(N):
+                a[i][j] = i*j
+        for i in range(N):
+            for j in range(N):
+                self.assertEqual(a[i][j], i*j)
+
+    def test_python_lists(self):
+        # Testing Python subclass of list...
+        class C(list):
+            def __getitem__(self, i):
+                if isinstance(i, slice):
+                    return i.start, i.stop
+                return list.__getitem__(self, i) + 100
+        a = C()
+        a.extend([0,1,2])
+        self.assertEqual(a[0], 100)
+        self.assertEqual(a[1], 101)
+        self.assertEqual(a[2], 102)
+        self.assertEqual(a[100:200], (100,200))
+
+    def test_metaclass(self):
+        # Testing __metaclass__...
+        class C(metaclass=type):
+            def __init__(self):
+                self.__state = 0
+            def getstate(self):
+                return self.__state
+            def setstate(self, state):
+                self.__state = state
+        a = C()
+        self.assertEqual(a.getstate(), 0)
+        a.setstate(10)
+        self.assertEqual(a.getstate(), 10)
+        class _metaclass(type):
+            def myself(cls): return cls
+        class D(metaclass=_metaclass):
+            pass
+        self.assertEqual(D.myself(), D)
+        d = D()
+        self.assertEqual(d.__class__, D)
+        class M1(type):
+            def __new__(cls, name, bases, dict):
+                dict['__spam__'] = 1
+                return type.__new__(cls, name, bases, dict)
+        class C(metaclass=M1):
+            pass
+        self.assertEqual(C.__spam__, 1)
+        c = C()
+        self.assertEqual(c.__spam__, 1)
+
+        class _instance(object):
+            pass
+        class M2(object):
+            @staticmethod
+            def __new__(cls, name, bases, dict):
+                self = object.__new__(cls)
+                self.name = name
+                self.bases = bases
+                self.dict = dict
+                return self
+            def __call__(self):
+                it = _instance()
+                # Early binding of methods
+                for key in self.dict:
+                    if key.startswith("__"):
+                        continue
+                    setattr(it, key, self.dict[key].__get__(it, self))
+                return it
+        class C(metaclass=M2):
+            def spam(self):
+                return 42
+        self.assertEqual(C.name, 'C')
+        self.assertEqual(C.bases, ())
+        self.assert_('spam' in C.dict)
+        c = C()
+        self.assertEqual(c.spam(), 42)
+
+        # More metaclass examples
+
+        class autosuper(type):
+            # Automatically add __super to the class
+            # This trick only works for dynamic classes
+            def __new__(metaclass, name, bases, dict):
+                cls = super(autosuper, metaclass).__new__(metaclass,
+                                                          name, bases, dict)
+                # Name mangling for __super removes leading underscores
+                while name[:1] == "_":
+                    name = name[1:]
+                if name:
+                    name = "_%s__super" % name
+                else:
+                    name = "__super"
+                setattr(cls, name, super(cls))
+                return cls
+        class A(metaclass=autosuper):
+            def meth(self):
+                return "A"
+        class B(A):
+            def meth(self):
+                return "B" + self.__super.meth()
+        class C(A):
+            def meth(self):
+                return "C" + self.__super.meth()
+        class D(C, B):
+            def meth(self):
+                return "D" + self.__super.meth()
+        self.assertEqual(D().meth(), "DCBA")
+        class E(B, C):
+            def meth(self):
+                return "E" + self.__super.meth()
+        self.assertEqual(E().meth(), "EBCA")
+
+        class autoproperty(type):
+            # Automatically create property attributes when methods
+            # named _get_x and/or _set_x are found
+            def __new__(metaclass, name, bases, dict):
+                hits = {}
+                for key, val in dict.items():
+                    if key.startswith("_get_"):
+                        key = key[5:]
+                        get, set = hits.get(key, (None, None))
+                        get = val
+                        hits[key] = get, set
+                    elif key.startswith("_set_"):
+                        key = key[5:]
+                        get, set = hits.get(key, (None, None))
+                        set = val
+                        hits[key] = get, set
+                for key, (get, set) in hits.items():
+                    dict[key] = property(get, set)
+                return super(autoproperty, metaclass).__new__(metaclass,
+                                                            name, bases, dict)
+        class A(metaclass=autoproperty):
+            def _get_x(self):
+                return -self.__x
+            def _set_x(self, x):
+                self.__x = -x
+        a = A()
+        self.assert_(not hasattr(a, "x"))
+        a.x = 12
+        self.assertEqual(a.x, 12)
+        self.assertEqual(a._A__x, -12)
+
+        class multimetaclass(autoproperty, autosuper):
+            # Merge of multiple cooperating metaclasses
+            pass
+        class A(metaclass=multimetaclass):
+            def _get_x(self):
+                return "A"
+        class B(A):
+            def _get_x(self):
+                return "B" + self.__super._get_x()
+        class C(A):
+            def _get_x(self):
+                return "C" + self.__super._get_x()
+        class D(C, B):
+            def _get_x(self):
+                return "D" + self.__super._get_x()
+        self.assertEqual(D().x, "DCBA")
+
+        # Make sure type(x) doesn't call x.__class__.__init__
+        class T(type):
+            counter = 0
+            def __init__(self, *args):
+                T.counter += 1
+        class C(metaclass=T):
+            pass
+        self.assertEqual(T.counter, 1)
+        a = C()
+        self.assertEqual(type(a), C)
+        self.assertEqual(T.counter, 1)
+
+        class C(object): pass
+        c = C()
+        try: c()
+        except TypeError: pass
+        else: self.fail("calling object w/o call method should raise "
+                        "TypeError")
+
+        # Testing code to find most derived baseclass
+        class A(type):
+            def __new__(*args, **kwargs):
+                return type.__new__(*args, **kwargs)
+
+        class B(object):
+            pass
+
+        class C(object, metaclass=A):
+            pass
+
+        # The most derived metaclass of D is A rather than type.
+        class D(B, C):
+            pass
+
+    def test_module_subclasses(self):
+        # Testing Python subclass of module...
+        log = []
+        import types, sys
+        MT = type(sys)
+        class MM(MT):
+            def __init__(self, name):
+                MT.__init__(self, name)
+            def __getattribute__(self, name):
+                log.append(("getattr", name))
+                return MT.__getattribute__(self, name)
+            def __setattr__(self, name, value):
+                log.append(("setattr", name, value))
+                MT.__setattr__(self, name, value)
+            def __delattr__(self, name):
+                log.append(("delattr", name))
+                MT.__delattr__(self, name)
+        a = MM("a")
+        a.foo = 12
+        x = a.foo
+        del a.foo
+        self.assertEqual(log, [("setattr", "foo", 12),
+                               ("getattr", "foo"),
+                               ("delattr", "foo")])
+
+        # http://python.org/sf/1174712
+        try:
+            class Module(types.ModuleType, str):
+                pass
+        except TypeError:
+            pass
+        else:
+            self.fail("inheriting from ModuleType and str at the same time "
+                      "should fail")
+
+    def test_multiple_inheritance(self):
+        # Testing multiple inheritance...
+        class C(object):
+            def __init__(self):
+                self.__state = 0
+            def getstate(self):
+                return self.__state
+            def setstate(self, state):
+                self.__state = state
+        a = C()
+        self.assertEqual(a.getstate(), 0)
+        a.setstate(10)
+        self.assertEqual(a.getstate(), 10)
+        class D(dict, C):
+            def __init__(self):
+                type({}).__init__(self)
+                C.__init__(self)
+        d = D()
+        self.assertEqual(list(d.keys()), [])
+        d["hello"] = "world"
+        self.assertEqual(list(d.items()), [("hello", "world")])
+        self.assertEqual(d["hello"], "world")
+        self.assertEqual(d.getstate(), 0)
+        d.setstate(10)
+        self.assertEqual(d.getstate(), 10)
+        self.assertEqual(D.__mro__, (D, dict, C, object))
+
+        # SF bug #442833
+        class Node(object):
+            def __int__(self):
+                return int(self.foo())
+            def foo(self):
+                return "23"
+        class Frag(Node, list):
+            def foo(self):
+                return "42"
+        self.assertEqual(Node().__int__(), 23)
+        self.assertEqual(int(Node()), 23)
+        self.assertEqual(Frag().__int__(), 42)
+        self.assertEqual(int(Frag()), 42)
+
+    def test_diamond_inheritence(self):
+        # Testing multiple inheritance special cases...
+        class A(object):
+            def spam(self): return "A"
+        self.assertEqual(A().spam(), "A")
+        class B(A):
+            def boo(self): return "B"
+            def spam(self): return "B"
+        self.assertEqual(B().spam(), "B")
+        self.assertEqual(B().boo(), "B")
+        class C(A):
+            def boo(self): return "C"
+        self.assertEqual(C().spam(), "A")
+        self.assertEqual(C().boo(), "C")
+        class D(B, C): pass
+        self.assertEqual(D().spam(), "B")
+        self.assertEqual(D().boo(), "B")
+        self.assertEqual(D.__mro__, (D, B, C, A, object))
+        class E(C, B): pass
+        self.assertEqual(E().spam(), "B")
+        self.assertEqual(E().boo(), "C")
+        self.assertEqual(E.__mro__, (E, C, B, A, object))
+        # MRO order disagreement
+        try:
+            class F(D, E): pass
+        except TypeError:
+            pass
+        else:
+            self.fail("expected MRO order disagreement (F)")
+        try:
+            class G(E, D): pass
+        except TypeError:
+            pass
+        else:
+            self.fail("expected MRO order disagreement (G)")
+
+    # see thread python-dev/2002-October/029035.html
+    def test_ex5_from_c3_switch(self):
+        # Testing ex5 from C3 switch discussion...
+        class A(object): pass
+        class B(object): pass
+        class C(object): pass
+        class X(A): pass
+        class Y(A): pass
+        class Z(X,B,Y,C): pass
+        self.assertEqual(Z.__mro__, (Z, X, B, Y, A, C, object))
+
+    # see "A Monotonic Superclass Linearization for Dylan",
+    # by Kim Barrett et al. (OOPSLA 1996)
+    def test_monotonicity(self):
+        # Testing MRO monotonicity...
+        class Boat(object): pass
+        class DayBoat(Boat): pass
+        class WheelBoat(Boat): pass
+        class EngineLess(DayBoat): pass
+        class SmallMultihull(DayBoat): pass
+        class PedalWheelBoat(EngineLess,WheelBoat): pass
+        class SmallCatamaran(SmallMultihull): pass
+        class Pedalo(PedalWheelBoat,SmallCatamaran): pass
+
+        self.assertEqual(PedalWheelBoat.__mro__,
+              (PedalWheelBoat, EngineLess, DayBoat, WheelBoat, Boat, object))
+        self.assertEqual(SmallCatamaran.__mro__,
+              (SmallCatamaran, SmallMultihull, DayBoat, Boat, object))
+        self.assertEqual(Pedalo.__mro__,
+              (Pedalo, PedalWheelBoat, EngineLess, SmallCatamaran,
+               SmallMultihull, DayBoat, WheelBoat, Boat, object))
+
+    # see "A Monotonic Superclass Linearization for Dylan",
+    # by Kim Barrett et al. (OOPSLA 1996)
+    def test_consistency_with_epg(self):
+        # Testing consistentcy with EPG...
+        class Pane(object): pass
+        class ScrollingMixin(object): pass
+        class EditingMixin(object): pass
+        class ScrollablePane(Pane,ScrollingMixin): pass
+        class EditablePane(Pane,EditingMixin): pass
+        class EditableScrollablePane(ScrollablePane,EditablePane): pass
+
+        self.assertEqual(EditableScrollablePane.__mro__,
+              (EditableScrollablePane, ScrollablePane, EditablePane, Pane,
+                ScrollingMixin, EditingMixin, object))
+
+    def test_mro_disagreement(self):
+        # Testing error messages for MRO disagreement...
+        mro_err_msg = """Cannot create a consistent method resolution
+order (MRO) for bases """
+
+        def raises(exc, expected, callable, *args):
+            try:
+                callable(*args)
+            except exc as msg:
+                if not str(msg).startswith(expected):
+                    self.fail("Message %r, expected %r" % (str(msg), expected))
+            else:
+                self.fail("Expected %s" % exc)
+
+        class A(object): pass
+        class B(A): pass
+        class C(object): pass
+
+        # Test some very simple errors
+        raises(TypeError, "duplicate base class A",
+               type, "X", (A, A), {})
+        raises(TypeError, mro_err_msg,
+               type, "X", (A, B), {})
+        raises(TypeError, mro_err_msg,
+               type, "X", (A, C, B), {})
+        # Test a slightly more complex error
+        class GridLayout(object): pass
+        class HorizontalGrid(GridLayout): pass
+        class VerticalGrid(GridLayout): pass
+        class HVGrid(HorizontalGrid, VerticalGrid): pass
+        class VHGrid(VerticalGrid, HorizontalGrid): pass
+        raises(TypeError, mro_err_msg,
+               type, "ConfusedGrid", (HVGrid, VHGrid), {})
+
+    def test_object_class(self):
+        # Testing object class...
+        a = object()
+        self.assertEqual(a.__class__, object)
+        self.assertEqual(type(a), object)
+        b = object()
+        self.assertNotEqual(a, b)
+        self.assertFalse(hasattr(a, "foo"))
+        try:
+            a.foo = 12
+        except (AttributeError, TypeError):
+            pass
+        else:
+            self.fail("object() should not allow setting a foo attribute")
+        self.assertFalse(hasattr(object(), "__dict__"))
+
+        class Cdict(object):
+            pass
+        x = Cdict()
+        self.assertEqual(x.__dict__, {})
+        x.foo = 1
+        self.assertEqual(x.foo, 1)
+        self.assertEqual(x.__dict__, {'foo': 1})
+
+    def test_slots(self):
+        # Testing __slots__...
+        class C0(object):
+            __slots__ = []
+        x = C0()
+        self.assertFalse(hasattr(x, "__dict__"))
+        self.assertFalse(hasattr(x, "foo"))
+
+        class C1(object):
+            __slots__ = ['a']
+        x = C1()
+        self.assertFalse(hasattr(x, "__dict__"))
+        self.assertFalse(hasattr(x, "a"))
+        x.a = 1
+        self.assertEqual(x.a, 1)
+        x.a = None
+        self.assertEqual(x.a, None)
+        del x.a
+        self.assertFalse(hasattr(x, "a"))
+
+        class C3(object):
+            __slots__ = ['a', 'b', 'c']
+        x = C3()
+        self.assertFalse(hasattr(x, "__dict__"))
+        self.assertFalse(hasattr(x, 'a'))
+        self.assertFalse(hasattr(x, 'b'))
+        self.assertFalse(hasattr(x, 'c'))
+        x.a = 1
+        x.b = 2
+        x.c = 3
+        self.assertEqual(x.a, 1)
+        self.assertEqual(x.b, 2)
+        self.assertEqual(x.c, 3)
+
+        class C4(object):
+            """Validate name mangling"""
+            __slots__ = ['__a']
+            def __init__(self, value):
+                self.__a = value
+            def get(self):
+                return self.__a
+        x = C4(5)
+        self.assertFalse(hasattr(x, '__dict__'))
+        self.assertFalse(hasattr(x, '__a'))
+        self.assertEqual(x.get(), 5)
+        try:
+            x.__a = 6
+        except AttributeError:
+            pass
+        else:
+            self.fail("Double underscored names not mangled")
+
+        # Make sure slot names are proper identifiers
+        try:
+            class C(object):
+                __slots__ = [None]
+        except TypeError:
+            pass
+        else:
+            self.fail("[None] slots not caught")
+        try:
+            class C(object):
+                __slots__ = ["foo bar"]
+        except TypeError:
+            pass
+        else:
+            self.fail("['foo bar'] slots not caught")
+        try:
+            class C(object):
+                __slots__ = ["foo\0bar"]
+        except TypeError:
+            pass
+        else:
+            self.fail("['foo\\0bar'] slots not caught")
+        try:
+            class C(object):
+                __slots__ = ["1"]
+        except TypeError:
+            pass
+        else:
+            self.fail("['1'] slots not caught")
+        try:
+            class C(object):
+                __slots__ = [""]
+        except TypeError:
+            pass
+        else:
+            self.fail("[''] slots not caught")
+        class C(object):
+            __slots__ = ["a", "a_b", "_a", "A0123456789Z"]
+        # XXX(nnorwitz): was there supposed to be something tested
+        # from the class above?
+
+        # Test a single string is not expanded as a sequence.
+        class C(object):
+            __slots__ = "abc"
+        c = C()
+        c.abc = 5
+        self.assertEqual(c.abc, 5)
+
+        # Test unicode slot names
+        # Test a single unicode string is not expanded as a sequence.
+        class C(object):
+            __slots__ = "abc"
+        c = C()
+        c.abc = 5
+        self.assertEqual(c.abc, 5)
+
+        # _unicode_to_string used to modify slots in certain circumstances
+        slots = ("foo", "bar")
+        class C(object):
+            __slots__ = slots
+        x = C()
+        x.foo = 5
+        self.assertEqual(x.foo, 5)
+        self.assert_(type(slots[0]) is str)
+        # this used to leak references
+        try:
+            class C(object):
+                __slots__ = [chr(128)]
+        except (TypeError, UnicodeEncodeError):
+            pass
+        else:
+            raise TestFailed("[chr(128)] slots not caught")
+
+        # Test leaks
+        class Counted(object):
+            counter = 0    # counts the number of instances alive
+            def __init__(self):
+                Counted.counter += 1
+            def __del__(self):
+                Counted.counter -= 1
+        class C(object):
+            __slots__ = ['a', 'b', 'c']
+        x = C()
+        x.a = Counted()
+        x.b = Counted()
+        x.c = Counted()
+        self.assertEqual(Counted.counter, 3)
+        del x
+        self.assertEqual(Counted.counter, 0)
+        class D(C):
+            pass
+        x = D()
+        x.a = Counted()
+        x.z = Counted()
+        self.assertEqual(Counted.counter, 2)
+        del x
+        self.assertEqual(Counted.counter, 0)
+        class E(D):
+            __slots__ = ['e']
+        x = E()
+        x.a = Counted()
+        x.z = Counted()
+        x.e = Counted()
+        self.assertEqual(Counted.counter, 3)
+        del x
+        self.assertEqual(Counted.counter, 0)
+
+        # Test cyclical leaks [SF bug 519621]
+        class F(object):
+            __slots__ = ['a', 'b']
+        log = []
+        s = F()
+        s.a = [Counted(), s]
+        self.assertEqual(Counted.counter, 1)
+        s = None
+        import gc
+        gc.collect()
+        self.assertEqual(Counted.counter, 0)
+
+        # Test lookup leaks [SF bug 572567]
+        import sys,gc
+        class G(object):
+            def __cmp__(self, other):
+                return 0
+        g = G()
+        orig_objects = len(gc.get_objects())
+        for i in range(10):
+            g==g
+        new_objects = len(gc.get_objects())
+        self.assertEqual(orig_objects, new_objects)
+        class H(object):
+            __slots__ = ['a', 'b']
+            def __init__(self):
+                self.a = 1
+                self.b = 2
+            def __del__(self_):
+                self.assertEqual(self_.a, 1)
+                self.assertEqual(self_.b, 2)
+
+        save_stderr = sys.stderr
+        sys.stderr = sys.stdout
+        h = H()
+        try:
+            del h
+        finally:
+            sys.stderr = save_stderr
+
+    def test_slots_special(self):
+        # Testing __dict__ and __weakref__ in __slots__...
+        class D(object):
+            __slots__ = ["__dict__"]
+        a = D()
+        self.assert_(hasattr(a, "__dict__"))
+        self.assertFalse(hasattr(a, "__weakref__"))
+        a.foo = 42
+        self.assertEqual(a.__dict__, {"foo": 42})
+
+        class W(object):
+            __slots__ = ["__weakref__"]
+        a = W()
+        self.assert_(hasattr(a, "__weakref__"))
+        self.assertFalse(hasattr(a, "__dict__"))
+        try:
+            a.foo = 42
+        except AttributeError:
+            pass
+        else:
+            self.fail("shouldn't be allowed to set a.foo")
+
+        class C1(W, D):
+            __slots__ = []
+        a = C1()
+        self.assert_(hasattr(a, "__dict__"))
+        self.assert_(hasattr(a, "__weakref__"))
+        a.foo = 42
+        self.assertEqual(a.__dict__, {"foo": 42})
+
+        class C2(D, W):
+            __slots__ = []
+        a = C2()
+        self.assert_(hasattr(a, "__dict__"))
+        self.assert_(hasattr(a, "__weakref__"))
+        a.foo = 42
+        self.assertEqual(a.__dict__, {"foo": 42})
+
+    def test_slots_descriptor(self):
+        # Issue2115: slot descriptors did not correctly check
+        # the type of the given object
+        import abc
+        class MyABC(metaclass=abc.ABCMeta):
+            __slots__ = "a"
+
+        class Unrelated(object):
+            pass
+        MyABC.register(Unrelated)
+
+        u = Unrelated()
+        self.assert_(isinstance(u, MyABC))
+
+        # This used to crash
+        self.assertRaises(TypeError, MyABC.a.__set__, u, 3)
+
+    def test_dynamics(self):
+        # Testing class attribute propagation...
+        class D(object):
+            pass
+        class E(D):
+            pass
+        class F(D):
+            pass
+        D.foo = 1
+        self.assertEqual(D.foo, 1)
+        # Test that dynamic attributes are inherited
+        self.assertEqual(E.foo, 1)
+        self.assertEqual(F.foo, 1)
+        # Test dynamic instances
+        class C(object):
+            pass
+        a = C()
+        self.assertFalse(hasattr(a, "foobar"))
+        C.foobar = 2
+        self.assertEqual(a.foobar, 2)
+        C.method = lambda self: 42
+        self.assertEqual(a.method(), 42)
+        C.__repr__ = lambda self: "C()"
+        self.assertEqual(repr(a), "C()")
+        C.__int__ = lambda self: 100
+        self.assertEqual(int(a), 100)
+        self.assertEqual(a.foobar, 2)
+        self.assertFalse(hasattr(a, "spam"))
+        def mygetattr(self, name):
+            if name == "spam":
+                return "spam"
+            raise AttributeError
+        C.__getattr__ = mygetattr
+        self.assertEqual(a.spam, "spam")
+        a.new = 12
+        self.assertEqual(a.new, 12)
+        def mysetattr(self, name, value):
+            if name == "spam":
+                raise AttributeError
+            return object.__setattr__(self, name, value)
+        C.__setattr__ = mysetattr
+        try:
+            a.spam = "not spam"
+        except AttributeError:
+            pass
+        else:
+            self.fail("expected AttributeError")
+        self.assertEqual(a.spam, "spam")
+        class D(C):
+            pass
+        d = D()
+        d.foo = 1
+        self.assertEqual(d.foo, 1)
+
+        # Test handling of int*seq and seq*int
+        class I(int):
+            pass
+        self.assertEqual("a"*I(2), "aa")
+        self.assertEqual(I(2)*"a", "aa")
+        self.assertEqual(2*I(3), 6)
+        self.assertEqual(I(3)*2, 6)
+        self.assertEqual(I(3)*I(2), 6)
+
+        # Test handling of long*seq and seq*long
+        class L(int):
+            pass
+        self.assertEqual("a"*L(2), "aa")
+        self.assertEqual(L(2)*"a", "aa")
+        self.assertEqual(2*L(3), 6)
+        self.assertEqual(L(3)*2, 6)
+        self.assertEqual(L(3)*L(2), 6)
+
+        # Test comparison of classes with dynamic metaclasses
+        class dynamicmetaclass(type):
+            pass
+        class someclass(metaclass=dynamicmetaclass):
+            pass
+        self.assertNotEqual(someclass, object)
+
+    def test_errors(self):
+        # Testing errors...
+        try:
+            class C(list, dict):
+                pass
+        except TypeError:
+            pass
+        else:
+            self.fail("inheritance from both list and dict should be illegal")
+
+        try:
+            class C(object, None):
+                pass
+        except TypeError:
+            pass
+        else:
+            self.fail("inheritance from non-type should be illegal")
+        class Classic:
+            pass
+
+        try:
+            class C(type(len)):
+                pass
+        except TypeError:
+            pass
+        else:
+            self.fail("inheritance from CFunction should be illegal")
+
+        try:
+            class C(object):
+                __slots__ = 1
+        except TypeError:
+            pass
+        else:
+            self.fail("__slots__ = 1 should be illegal")
+
+        try:
+            class C(object):
+                __slots__ = [1]
+        except TypeError:
+            pass
+        else:
+            self.fail("__slots__ = [1] should be illegal")
+
+        class M1(type):
+            pass
+        class M2(type):
+            pass
+        class A1(object, metaclass=M1):
+            pass
+        class A2(object, metaclass=M2):
+            pass
+        try:
+            class B(A1, A2):
+                pass
+        except TypeError:
+            pass
+        else:
+            self.fail("finding the most derived metaclass should have failed")
+
+    def test_classmethods(self):
+        # Testing class methods...
+        class C(object):
+            def foo(*a): return a
+            goo = classmethod(foo)
+        c = C()
+        self.assertEqual(C.goo(1), (C, 1))
+        self.assertEqual(c.goo(1), (C, 1))
+        self.assertEqual(c.foo(1), (c, 1))
+        class D(C):
+            pass
+        d = D()
+        self.assertEqual(D.goo(1), (D, 1))
+        self.assertEqual(d.goo(1), (D, 1))
+        self.assertEqual(d.foo(1), (d, 1))
+        self.assertEqual(D.foo(d, 1), (d, 1))
+        # Test for a specific crash (SF bug 528132)
+        def f(cls, arg): return (cls, arg)
+        ff = classmethod(f)
+        self.assertEqual(ff.__get__(0, int)(42), (int, 42))
+        self.assertEqual(ff.__get__(0)(42), (int, 42))
+
+        # Test super() with classmethods (SF bug 535444)
+        self.assertEqual(C.goo.__self__, C)
+        self.assertEqual(D.goo.__self__, D)
+        self.assertEqual(super(D,D).goo.__self__, D)
+        self.assertEqual(super(D,d).goo.__self__, D)
+        self.assertEqual(super(D,D).goo(), (D,))
+        self.assertEqual(super(D,d).goo(), (D,))
+
+        # Verify that argument is checked for callability (SF bug 753451)
+        try:
+            classmethod(1).__get__(1)
+        except TypeError:
+            pass
+        else:
+            self.fail("classmethod should check for callability")
+
+        # Verify that classmethod() doesn't allow keyword args
+        try:
+            classmethod(f, kw=1)
+        except TypeError:
+            pass
+        else:
+            self.fail("classmethod shouldn't accept keyword args")
+
+    def test_classmethods_in_c(self):
+        # Testing C-based class methods...
+        import xxsubtype as spam
+        a = (1, 2, 3)
+        d = {'abc': 123}
+        x, a1, d1 = spam.spamlist.classmeth(*a, **d)
+        self.assertEqual(x, spam.spamlist)
+        self.assertEqual(a, a1)
+        self.assertEqual(d, d1)
+        x, a1, d1 = spam.spamlist().classmeth(*a, **d)
+        self.assertEqual(x, spam.spamlist)
+        self.assertEqual(a, a1)
+        self.assertEqual(d, d1)
+
+    def test_staticmethods(self):
+        # Testing static methods...
+        class C(object):
+            def foo(*a): return a
+            goo = staticmethod(foo)
+        c = C()
+        self.assertEqual(C.goo(1), (1,))
+        self.assertEqual(c.goo(1), (1,))
+        self.assertEqual(c.foo(1), (c, 1,))
+        class D(C):
+            pass
+        d = D()
+        self.assertEqual(D.goo(1), (1,))
+        self.assertEqual(d.goo(1), (1,))
+        self.assertEqual(d.foo(1), (d, 1))
+        self.assertEqual(D.foo(d, 1), (d, 1))
+
+    def test_staticmethods_in_c(self):
+        # Testing C-based static methods...
+        import xxsubtype as spam
+        a = (1, 2, 3)
+        d = {"abc": 123}
+        x, a1, d1 = spam.spamlist.staticmeth(*a, **d)
+        self.assertEqual(x, None)
+        self.assertEqual(a, a1)
+        self.assertEqual(d, d1)
+        x, a1, d2 = spam.spamlist().staticmeth(*a, **d)
+        self.assertEqual(x, None)
+        self.assertEqual(a, a1)
+        self.assertEqual(d, d1)
+
+    def test_classic(self):
+        # Testing classic classes...
+        class C:
+            def foo(*a): return a
+            goo = classmethod(foo)
+        c = C()
+        self.assertEqual(C.goo(1), (C, 1))
+        self.assertEqual(c.goo(1), (C, 1))
+        self.assertEqual(c.foo(1), (c, 1))
+        class D(C):
+            pass
+        d = D()
+        self.assertEqual(D.goo(1), (D, 1))
+        self.assertEqual(d.goo(1), (D, 1))
+        self.assertEqual(d.foo(1), (d, 1))
+        self.assertEqual(D.foo(d, 1), (d, 1))
+        class E: # *not* subclassing from C
+            foo = C.foo
+        self.assertEqual(E().foo.__func__, C.foo) # i.e., unbound
+        self.assert_(repr(C.foo.__get__(C())).startswith("<bound method "))
+
+    def test_compattr(self):
+        # Testing computed attributes...
+        class C(object):
+            class computed_attribute(object):
+                def __init__(self, get, set=None, delete=None):
+                    self.__get = get
+                    self.__set = set
+                    self.__delete = delete
+                def __get__(self, obj, type=None):
+                    return self.__get(obj)
+                def __set__(self, obj, value):
+                    return self.__set(obj, value)
+                def __delete__(self, obj):
+                    return self.__delete(obj)
+            def __init__(self):
+                self.__x = 0
+            def __get_x(self):
+                x = self.__x
+                self.__x = x+1
+                return x
+            def __set_x(self, x):
+                self.__x = x
+            def __delete_x(self):
+                del self.__x
+            x = computed_attribute(__get_x, __set_x, __delete_x)
+        a = C()
+        self.assertEqual(a.x, 0)
+        self.assertEqual(a.x, 1)
+        a.x = 10
+        self.assertEqual(a.x, 10)
+        self.assertEqual(a.x, 11)
+        del a.x
+        self.assertEqual(hasattr(a, 'x'), 0)
+
+    def test_newslots(self):
+        # Testing __new__ slot override...
+        class C(list):
+            def __new__(cls):
+                self = list.__new__(cls)
+                self.foo = 1
+                return self
+            def __init__(self):
+                self.foo = self.foo + 2
+        a = C()
+        self.assertEqual(a.foo, 3)
+        self.assertEqual(a.__class__, C)
+        class D(C):
+            pass
+        b = D()
+        self.assertEqual(b.foo, 3)
+        self.assertEqual(b.__class__, D)
+
+    def test_altmro(self):
+        # Testing mro() and overriding it...
+        class A(object):
+            def f(self): return "A"
+        class B(A):
+            pass
+        class C(A):
+            def f(self): return "C"
+        class D(B, C):
+            pass
+        self.assertEqual(D.mro(), [D, B, C, A, object])
+        self.assertEqual(D.__mro__, (D, B, C, A, object))
+        self.assertEqual(D().f(), "C")
+
+        class PerverseMetaType(type):
+            def mro(cls):
+                L = type.mro(cls)
+                L.reverse()
+                return L
+        class X(D,B,C,A, metaclass=PerverseMetaType):
+            pass
+        self.assertEqual(X.__mro__, (object, A, C, B, D, X))
+        self.assertEqual(X().f(), "A")
+
+        try:
+            class _metaclass(type):
+                def mro(self):
+                    return [self, dict, object]
+            class X(object, metaclass=_metaclass):
+                pass
+        except TypeError:
+            pass
+        else:
+            self.fail("devious mro() return not caught")
+
+        try:
+            class _metaclass(type):
+                def mro(self):
+                    return [1]
+            class X(object, metaclass=_metaclass):
+                pass
+        except TypeError:
+            pass
+        else:
+            self.fail("non-class mro() return not caught")
+
+        try:
+            class _metaclass(type):
+                def mro(self):
+                    return 1
+            class X(object, metaclass=_metaclass):
+                pass
+        except TypeError:
+            pass
+        else:
+            self.fail("non-sequence mro() return not caught")
+
+    def test_overloading(self):
+        # Testing operator overloading...
+
+        class B(object):
+            "Intermediate class because object doesn't have a __setattr__"
+
+        class C(B):
+            def __getattr__(self, name):
+                if name == "foo":
+                    return ("getattr", name)
+                else:
+                    raise AttributeError
+            def __setattr__(self, name, value):
+                if name == "foo":
+                    self.setattr = (name, value)
+                else:
+                    return B.__setattr__(self, name, value)
+            def __delattr__(self, name):
+                if name == "foo":
+                    self.delattr = name
+                else:
+                    return B.__delattr__(self, name)
+
+            def __getitem__(self, key):
+                return ("getitem", key)
+            def __setitem__(self, key, value):
+                self.setitem = (key, value)
+            def __delitem__(self, key):
+                self.delitem = key
+
+        a = C()
+        self.assertEqual(a.foo, ("getattr", "foo"))
+        a.foo = 12
+        self.assertEqual(a.setattr, ("foo", 12))
+        del a.foo
+        self.assertEqual(a.delattr, "foo")
+
+        self.assertEqual(a[12], ("getitem", 12))
+        a[12] = 21
+        self.assertEqual(a.setitem, (12, 21))
+        del a[12]
+        self.assertEqual(a.delitem, 12)
+
+        self.assertEqual(a[0:10], ("getitem", slice(0, 10)))
+        a[0:10] = "foo"
+        self.assertEqual(a.setitem, (slice(0, 10), "foo"))
+        del a[0:10]
+        self.assertEqual(a.delitem, (slice(0, 10)))
+
+    def test_methods(self):
+        # Testing methods...
+        class C(object):
+            def __init__(self, x):
+                self.x = x
+            def foo(self):
+                return self.x
+        c1 = C(1)
+        self.assertEqual(c1.foo(), 1)
+        class D(C):
+            boo = C.foo
+            goo = c1.foo
+        d2 = D(2)
+        self.assertEqual(d2.foo(), 2)
+        self.assertEqual(d2.boo(), 2)
+        self.assertEqual(d2.goo(), 1)
+        class E(object):
+            foo = C.foo
+        self.assertEqual(E().foo.__func__, C.foo) # i.e., unbound
+        self.assert_(repr(C.foo.__get__(C(1))).startswith("<bound method "))
+
+    def test_specials(self):
+        # Testing special operators...
+        # Test operators like __hash__ for which a built-in default exists
 
-def veris(a, b):
-    if a is not b:
-        raise TestFailed("%r is %r" % (a, b))
-
-def testunop(a, res, expr="len(a)", meth="__len__"):
-    if verbose: print("checking", expr)
-    dict = {'a': a}
-    vereq(eval(expr, dict), res)
-    t = type(a)
-    m = getattr(t, meth)
-    while meth not in t.__dict__:
-        t = t.__bases__[0]
-    vereq(m, t.__dict__[meth])
-    vereq(m(a), res)
-    bm = getattr(a, meth)
-    vereq(bm(), res)
-
-def testbinop(a, b, res, expr="a+b", meth="__add__"):
-    if verbose: print("checking", expr)
-    dict = {'a': a, 'b': b}
-
-    vereq(eval(expr, dict), res)
-    t = type(a)
-    m = getattr(t, meth)
-    while meth not in t.__dict__:
-        t = t.__bases__[0]
-    vereq(m, t.__dict__[meth])
-    vereq(m(a, b), res)
-    bm = getattr(a, meth)
-    vereq(bm(b), res)
-
-def testsliceop(a, b, c, res, expr="a[b:c]", meth="__getitem__"):
-    if verbose: print("checking", expr)
-    dict = {'a': a, 'b': b, 'c': c}
-    vereq(eval(expr, dict), res)
-    t = type(a)
-    m = getattr(t, meth)
-    while meth not in t.__dict__:
-        t = t.__bases__[0]
-    vereq(m, t.__dict__[meth])
-    vereq(m(a, slice(b, c)), res)
-    bm = getattr(a, meth)
-    vereq(bm(slice(b, c)), res)
-
-def testsetop(a, b, res, stmt="a+=b", meth="__iadd__"):
-    if verbose: print("checking", stmt)
-    dict = {'a': deepcopy(a), 'b': b}
-    exec(stmt, dict)
-    vereq(dict['a'], res)
-    t = type(a)
-    m = getattr(t, meth)
-    while meth not in t.__dict__:
-        t = t.__bases__[0]
-    vereq(m, t.__dict__[meth])
-    dict['a'] = deepcopy(a)
-    m(dict['a'], b)
-    vereq(dict['a'], res)
-    dict['a'] = deepcopy(a)
-    bm = getattr(dict['a'], meth)
-    bm(b)
-    vereq(dict['a'], res)
-
-def testset2op(a, b, c, res, stmt="a[b]=c", meth="__setitem__"):
-    if verbose: print("checking", stmt)
-    dict = {'a': deepcopy(a), 'b': b, 'c': c}
-    exec(stmt, dict)
-    vereq(dict['a'], res)
-    t = type(a)
-    m = getattr(t, meth)
-    while meth not in t.__dict__:
-        t = t.__bases__[0]
-    vereq(m, t.__dict__[meth])
-    dict['a'] = deepcopy(a)
-    m(dict['a'], b, c)
-    vereq(dict['a'], res)
-    dict['a'] = deepcopy(a)
-    bm = getattr(dict['a'], meth)
-    bm(b, c)
-    vereq(dict['a'], res)
-
-def testsetsliceop(a, b, c, d, res, stmt="a[b:c]=d", meth="__setitem__"):
-    if verbose: print("checking", stmt)
-    dict = {'a': deepcopy(a), 'b': b, 'c': c, 'd': d}
-    exec(stmt, dict)
-    vereq(dict['a'], res)
-    t = type(a)
-    while meth not in t.__dict__:
-        t = t.__bases__[0]
-    m = getattr(t, meth)
-    vereq(m, t.__dict__[meth])
-    dict['a'] = deepcopy(a)
-    m(dict['a'], slice(b, c), d)
-    vereq(dict['a'], res)
-    dict['a'] = deepcopy(a)
-    bm = getattr(dict['a'], meth)
-    bm(slice(b, c), d)
-    vereq(dict['a'], res)
-
-def class_docstrings():
-    class Classic:
-        "A classic docstring."
-    vereq(Classic.__doc__, "A classic docstring.")
-    vereq(Classic.__dict__['__doc__'], "A classic docstring.")
-
-    class Classic2:
-        pass
-    verify(Classic2.__doc__ is None)
-
-    class NewStatic(object):
-        "Another docstring."
-    vereq(NewStatic.__doc__, "Another docstring.")
-    vereq(NewStatic.__dict__['__doc__'], "Another docstring.")
-
-    class NewStatic2(object):
-        pass
-    verify(NewStatic2.__doc__ is None)
-
-    class NewDynamic(object):
-        "Another docstring."
-    vereq(NewDynamic.__doc__, "Another docstring.")
-    vereq(NewDynamic.__dict__['__doc__'], "Another docstring.")
-
-    class NewDynamic2(object):
-        pass
-    verify(NewDynamic2.__doc__ is None)
-
-def lists():
-    if verbose: print("Testing list operations...")
-    testbinop([1], [2], [1,2], "a+b", "__add__")
-    testbinop([1,2,3], 2, 1, "b in a", "__contains__")
-    testbinop([1,2,3], 4, 0, "b in a", "__contains__")
-    testbinop([1,2,3], 1, 2, "a[b]", "__getitem__")
-    testsliceop([1,2,3], 0, 2, [1,2], "a[b:c]", "__getitem__")
-    testsetop([1], [2], [1,2], "a+=b", "__iadd__")
-    testsetop([1,2], 3, [1,2,1,2,1,2], "a*=b", "__imul__")
-    testunop([1,2,3], 3, "len(a)", "__len__")
-    testbinop([1,2], 3, [1,2,1,2,1,2], "a*b", "__mul__")
-    testbinop([1,2], 3, [1,2,1,2,1,2], "b*a", "__rmul__")
-    testset2op([1,2], 1, 3, [1,3], "a[b]=c", "__setitem__")
-    testsetsliceop([1,2,3,4], 1, 3, [5,6], [1,5,6,4], "a[b:c]=d",
-                   "__setitem__")
-
-def dicts():
-    if verbose: print("Testing dict operations...")
-    ##testbinop({1:2}, {2:1}, -1, "cmp(a,b)", "__cmp__")
-    testbinop({1:2,3:4}, 1, 1, "b in a", "__contains__")
-    testbinop({1:2,3:4}, 2, 0, "b in a", "__contains__")
-    testbinop({1:2,3:4}, 1, 2, "a[b]", "__getitem__")
-    d = {1:2,3:4}
-    l1 = []
-    for i in d.keys(): l1.append(i)
-    l = []
-    for i in iter(d): l.append(i)
-    vereq(l, l1)
-    l = []
-    for i in d.__iter__(): l.append(i)
-    vereq(l, l1)
-    l = []
-    for i in dict.__iter__(d): l.append(i)
-    vereq(l, l1)
-    d = {1:2, 3:4}
-    testunop(d, 2, "len(a)", "__len__")
-    vereq(eval(repr(d), {}), d)
-    vereq(eval(d.__repr__(), {}), d)
-    testset2op({1:2,3:4}, 2, 3, {1:2,2:3,3:4}, "a[b]=c", "__setitem__")
-
-def dict_constructor():
-    if verbose:
-        print("Testing dict constructor ...")
-    d = dict()
-    vereq(d, {})
-    d = dict({})
-    vereq(d, {})
-    d = dict({1: 2, 'a': 'b'})
-    vereq(d, {1: 2, 'a': 'b'})
-    vereq(d, dict(d.items()))
-    vereq(d, dict(d.items()))
-    d = dict({'one':1, 'two':2})
-    vereq(d, dict(one=1, two=2))
-    vereq(d, dict(**d))
-    vereq(d, dict({"one": 1}, two=2))
-    vereq(d, dict([("two", 2)], one=1))
-    vereq(d, dict([("one", 100), ("two", 200)], **d))
-    verify(d is not dict(**d))
-    for badarg in 0, 0, 0j, "0", [0], (0,):
-        try:
-            dict(badarg)
-        except TypeError:
-            pass
-        except ValueError:
-            if badarg == "0":
-                # It's a sequence, and its elements are also sequences (gotta
-                # love strings <wink>), but they aren't of length 2, so this
-                # one seemed better as a ValueError than a TypeError.
+        # Test the default behavior for static classes
+        class C(object):
+            def __getitem__(self, i):
+                if 0 <= i < 10: return i
+                raise IndexError
+        c1 = C()
+        c2 = C()
+        self.assert_(not not c1) # What?
+        self.assertNotEqual(id(c1), id(c2))
+        hash(c1)
+        hash(c2)
+        ## self.assertEqual(cmp(c1, c2), cmp(id(c1), id(c2)))
+        self.assertEqual(c1, c1)
+        self.assert_(c1 != c2)
+        self.assert_(not c1 != c1)
+        self.assert_(not c1 == c2)
+        # Note that the module name appears in str/repr, and that varies
+        # depending on whether this test is run standalone or from a framework.
+        self.assert_(str(c1).find('C object at ') >= 0)
+        self.assertEqual(str(c1), repr(c1))
+        self.assert_(-1 not in c1)
+        for i in range(10):
+            self.assert_(i in c1)
+        self.assertFalse(10 in c1)
+        # Test the default behavior for dynamic classes
+        class D(object):
+            def __getitem__(self, i):
+                if 0 <= i < 10: return i
+                raise IndexError
+        d1 = D()
+        d2 = D()
+        self.assert_(not not d1)
+        self.assertNotEqual(id(d1), id(d2))
+        hash(d1)
+        hash(d2)
+        ## self.assertEqual(cmp(d1, d2), cmp(id(d1), id(d2)))
+        self.assertEqual(d1, d1)
+        self.assertNotEqual(d1, d2)
+        self.assert_(not d1 != d1)
+        self.assert_(not d1 == d2)
+        # Note that the module name appears in str/repr, and that varies
+        # depending on whether this test is run standalone or from a framework.
+        self.assert_(str(d1).find('D object at ') >= 0)
+        self.assertEqual(str(d1), repr(d1))
+        self.assert_(-1 not in d1)
+        for i in range(10):
+            self.assert_(i in d1)
+        self.assertFalse(10 in d1)
+        # Test overridden behavior for static classes
+        class Proxy(object):
+            def __init__(self, x):
+                self.x = x
+            def __bool__(self):
+                return not not self.x
+            def __hash__(self):
+                return hash(self.x)
+            def __eq__(self, other):
+                return self.x == other
+            def __ne__(self, other):
+                return self.x != other
+            def __cmp__(self, other):
+                return cmp(self.x, other.x)
+            def __str__(self):
+                return "Proxy:%s" % self.x
+            def __repr__(self):
+                return "Proxy(%r)" % self.x
+            def __contains__(self, value):
+                return value in self.x
+        p0 = Proxy(0)
+        p1 = Proxy(1)
+        p_1 = Proxy(-1)
+        self.assertFalse(p0)
+        self.assert_(not not p1)
+        self.assertEqual(hash(p0), hash(0))
+        self.assertEqual(p0, p0)
+        self.assertNotEqual(p0, p1)
+        self.assert_(not p0 != p0)
+        self.assertEqual(not p0, p1)
+        self.assertEqual(cmp(p0, p1), -1)
+        self.assertEqual(cmp(p0, p0), 0)
+        self.assertEqual(cmp(p0, p_1), 1)
+        self.assertEqual(str(p0), "Proxy:0")
+        self.assertEqual(repr(p0), "Proxy(0)")
+        p10 = Proxy(range(10))
+        self.assertFalse(-1 in p10)
+        for i in range(10):
+            self.assert_(i in p10)
+        self.assertFalse(10 in p10)
+        # Test overridden behavior for dynamic classes
+        class DProxy(object):
+            def __init__(self, x):
+                self.x = x
+            def __bool__(self):
+                return not not self.x
+            def __hash__(self):
+                return hash(self.x)
+            def __eq__(self, other):
+                return self.x == other
+            def __ne__(self, other):
+                return self.x != other
+            def __cmp__(self, other):
+                return cmp(self.x, other.x)
+            def __str__(self):
+                return "DProxy:%s" % self.x
+            def __repr__(self):
+                return "DProxy(%r)" % self.x
+            def __contains__(self, value):
+                return value in self.x
+        p0 = DProxy(0)
+        p1 = DProxy(1)
+        p_1 = DProxy(-1)
+        self.assertFalse(p0)
+        self.assert_(not not p1)
+        self.assertEqual(hash(p0), hash(0))
+        self.assertEqual(p0, p0)
+        self.assertNotEqual(p0, p1)
+        self.assertNotEqual(not p0, p0)
+        self.assertEqual(not p0, p1)
+        self.assertEqual(cmp(p0, p1), -1)
+        self.assertEqual(cmp(p0, p0), 0)
+        self.assertEqual(cmp(p0, p_1), 1)
+        self.assertEqual(str(p0), "DProxy:0")
+        self.assertEqual(repr(p0), "DProxy(0)")
+        p10 = DProxy(range(10))
+        self.assertFalse(-1 in p10)
+        for i in range(10):
+            self.assert_(i in p10)
+        self.assertFalse(10 in p10)
+
+        ## # Safety test for __cmp__
+        ## def unsafecmp(a, b):
+        ##     try:
+        ##         a.__class__.__cmp__(a, b)
+        ##     except TypeError:
+        ##         pass
+        ##     else:
+        ##         self.fail("shouldn't allow %s.__cmp__(%r, %r)" % (
+        ##             a.__class__, a, b))
+        ##
+        ## unsafecmp("123", "123")
+        ## unsafecmp("123", "123")
+        ## unsafecmp(1, 1.0)
+        ## unsafecmp(1.0, 1)
+        ## unsafecmp(1, 1)
+        ## unsafecmp(1, 1)
+
+    def test_weakrefs(self):
+        # Testing weak references...
+        import weakref
+        class C(object):
+            pass
+        c = C()
+        r = weakref.ref(c)
+        self.assertEqual(r(), c)
+        del c
+        self.assertEqual(r(), None)
+        del r
+        class NoWeak(object):
+            __slots__ = ['foo']
+        no = NoWeak()
+        try:
+            weakref.ref(no)
+        except TypeError as msg:
+            self.assert_(str(msg).find("weak reference") >= 0)
+        else:
+            self.fail("weakref.ref(no) should be illegal")
+        class Weak(object):
+            __slots__ = ['foo', '__weakref__']
+        yes = Weak()
+        r = weakref.ref(yes)
+        self.assertEqual(r(), yes)
+        del yes
+        self.assertEqual(r(), None)
+        del r
+
+    def test_properties(self):
+        # Testing property...
+        class C(object):
+            def getx(self):
+                return self.__x
+            def setx(self, value):
+                self.__x = value
+            def delx(self):
+                del self.__x
+            x = property(getx, setx, delx, doc="I'm the x property.")
+        a = C()
+        self.assertFalse(hasattr(a, "x"))
+        a.x = 42
+        self.assertEqual(a._C__x, 42)
+        self.assertEqual(a.x, 42)
+        del a.x
+        self.assertFalse(hasattr(a, "x"))
+        self.assertFalse(hasattr(a, "_C__x"))
+        C.x.__set__(a, 100)
+        self.assertEqual(C.x.__get__(a), 100)
+        C.x.__delete__(a)
+        self.assertFalse(hasattr(a, "x"))
+
+        raw = C.__dict__['x']
+        self.assert_(isinstance(raw, property))
+
+        attrs = dir(raw)
+        self.assert_("__doc__" in attrs)
+        self.assert_("fget" in attrs)
+        self.assert_("fset" in attrs)
+        self.assert_("fdel" in attrs)
+
+        self.assertEqual(raw.__doc__, "I'm the x property.")
+        self.assert_(raw.fget is C.__dict__['getx'])
+        self.assert_(raw.fset is C.__dict__['setx'])
+        self.assert_(raw.fdel is C.__dict__['delx'])
+
+        for attr in "__doc__", "fget", "fset", "fdel":
+            try:
+                setattr(raw, attr, 42)
+            except AttributeError as msg:
+                if str(msg).find('readonly') < 0:
+                    self.fail("when setting readonly attr %r on a property, "
+                              "got unexpected AttributeError msg %r" % (attr, str(msg)))
+            else:
+                self.fail("expected AttributeError from trying to set readonly %r "
+                          "attr on a property" % attr)
+
+        class D(object):
+            __getitem__ = property(lambda s: 1/0)
+
+        d = D()
+        try:
+            for i in d:
+                str(i)
+        except ZeroDivisionError:
+            pass
+        else:
+            self.fail("expected ZeroDivisionError from bad property")
+
+        class E(object):
+            def getter(self):
+                "getter method"
+                return 0
+            def setter(self_, value):
+                "setter method"
+                pass
+            prop = property(getter)
+            self.assertEqual(prop.__doc__, "getter method")
+            prop2 = property(fset=setter)
+            self.assertEqual(prop2.__doc__, None)
+
+        # this segfaulted in 2.5b2
+        try:
+            import _testcapi
+        except ImportError:
+            pass
+        else:
+            class X(object):
+                p = property(_testcapi.test_with_docstring)
+
+    def test_properties_plus(self):
+        class C(object):
+            foo = property(doc="hello")
+            @foo.getter
+            def foo(self):
+                return self._foo
+            @foo.setter
+            def foo(self, value):
+                self._foo = abs(value)
+            @foo.deleter
+            def foo(self):
+                del self._foo
+        c = C()
+        self.assertEqual(C.foo.__doc__, "hello")
+        self.assertFalse(hasattr(c, "foo"))
+        c.foo = -42
+        self.assert_(hasattr(c, '_foo'))
+        self.assertEqual(c._foo, 42)
+        self.assertEqual(c.foo, 42)
+        del c.foo
+        self.assertFalse(hasattr(c, '_foo'))
+        self.assertFalse(hasattr(c, "foo"))
+
+        class D(C):
+            @C.foo.deleter
+            def foo(self):
+                try:
+                    del self._foo
+                except AttributeError:
+                    pass
+        d = D()
+        d.foo = 24
+        self.assertEqual(d.foo, 24)
+        del d.foo
+        del d.foo
+
+        class E(object):
+            @property
+            def foo(self):
+                return self._foo
+            @foo.setter
+            def foo(self, value):
+                raise RuntimeError
+            @foo.setter
+            def foo(self, value):
+                self._foo = abs(value)
+            @foo.deleter
+            def foo(self, value=None):
+                del self._foo
+
+        e = E()
+        e.foo = -42
+        self.assertEqual(e.foo, 42)
+        del e.foo
+
+        class F(E):
+            @E.foo.deleter
+            def foo(self):
+                del self._foo
+            @foo.setter
+            def foo(self, value):
+                self._foo = max(0, value)
+        f = F()
+        f.foo = -10
+        self.assertEqual(f.foo, 0)
+        del f.foo
+
+    def test_dict_constructors(self):
+        # Testing dict constructor ...
+        d = dict()
+        self.assertEqual(d, {})
+        d = dict({})
+        self.assertEqual(d, {})
+        d = dict({1: 2, 'a': 'b'})
+        self.assertEqual(d, {1: 2, 'a': 'b'})
+        self.assertEqual(d, dict(list(d.items())))
+        self.assertEqual(d, dict(iter(d.items())))
+        d = dict({'one':1, 'two':2})
+        self.assertEqual(d, dict(one=1, two=2))
+        self.assertEqual(d, dict(**d))
+        self.assertEqual(d, dict({"one": 1}, two=2))
+        self.assertEqual(d, dict([("two", 2)], one=1))
+        self.assertEqual(d, dict([("one", 100), ("two", 200)], **d))
+        self.assertEqual(d, dict(**d))
+
+        for badarg in 0, 0, 0j, "0", [0], (0,):
+            try:
+                dict(badarg)
+            except TypeError:
+                pass
+            except ValueError:
+                if badarg == "0":
+                    # It's a sequence, and its elements are also sequences (gotta
+                    # love strings <wink>), but they aren't of length 2, so this
+                    # one seemed better as a ValueError than a TypeError.
+                    pass
+                else:
+                    self.fail("no TypeError from dict(%r)" % badarg)
+            else:
+                self.fail("no TypeError from dict(%r)" % badarg)
+
+        try:
+            dict({}, {})
+        except TypeError:
+            pass
+        else:
+            self.fail("no TypeError from dict({}, {})")
+
+        class Mapping:
+            # Lacks a .keys() method; will be added later.
+            dict = {1:2, 3:4, 'a':1j}
+
+        try:
+            dict(Mapping())
+        except TypeError:
+            pass
+        else:
+            self.fail("no TypeError from dict(incomplete mapping)")
+
+        Mapping.keys = lambda self: list(self.dict.keys())
+        Mapping.__getitem__ = lambda self, i: self.dict[i]
+        d = dict(Mapping())
+        self.assertEqual(d, Mapping.dict)
+
+        # Init from sequence of iterable objects, each producing a 2-sequence.
+        class AddressBookEntry:
+            def __init__(self, first, last):
+                self.first = first
+                self.last = last
+            def __iter__(self):
+                return iter([self.first, self.last])
+
+        d = dict([AddressBookEntry('Tim', 'Warsaw'),
+                  AddressBookEntry('Barry', 'Peters'),
+                  AddressBookEntry('Tim', 'Peters'),
+                  AddressBookEntry('Barry', 'Warsaw')])
+        self.assertEqual(d, {'Barry': 'Warsaw', 'Tim': 'Peters'})
+
+        d = dict(zip(range(4), range(1, 5)))
+        self.assertEqual(d, dict([(i, i+1) for i in range(4)]))
+
+        # Bad sequence lengths.
+        for bad in [('tooshort',)], [('too', 'long', 'by 1')]:
+            try:
+                dict(bad)
+            except ValueError:
                 pass
             else:
-                raise TestFailed("no TypeError from dict(%r)" % badarg)
+                self.fail("no ValueError from dict(%r)" % bad)
+
+    def test_dir(self):
+        # Testing dir() ...
+        junk = 12
+        self.assertEqual(dir(), ['junk', 'self'])
+        del junk
+
+        # Just make sure these don't blow up!
+        for arg in 2, 2, 2j, 2e0, [2], "2", b"2", (2,), {2:2}, type, self.test_dir:
+            dir(arg)
+
+        # Test dir on new-style classes.  Since these have object as a
+        # base class, a lot more gets sucked in.
+        def interesting(strings):
+            return [s for s in strings if not s.startswith('_')]
+
+        class C(object):
+            Cdata = 1
+            def Cmethod(self): pass
+
+        cstuff = ['Cdata', 'Cmethod']
+        self.assertEqual(interesting(dir(C)), cstuff)
+
+        c = C()
+        self.assertEqual(interesting(dir(c)), cstuff)
+        ## self.assert_('__self__' in dir(C.Cmethod))
+
+        c.cdata = 2
+        c.cmethod = lambda self: 0
+        self.assertEqual(interesting(dir(c)), cstuff + ['cdata', 'cmethod'])
+        ## self.assert_('__self__' in dir(c.Cmethod))
+
+        class A(C):
+            Adata = 1
+            def Amethod(self): pass
+
+        astuff = ['Adata', 'Amethod'] + cstuff
+        self.assertEqual(interesting(dir(A)), astuff)
+        ## self.assert_('__self__' in dir(A.Amethod))
+        a = A()
+        self.assertEqual(interesting(dir(a)), astuff)
+        a.adata = 42
+        a.amethod = lambda self: 3
+        self.assertEqual(interesting(dir(a)), astuff + ['adata', 'amethod'])
+        ## self.assert_('__self__' in dir(a.Amethod))
+
+        # Try a module subclass.
+        import sys
+        class M(type(sys)):
+            pass
+        minstance = M("m")
+        minstance.b = 2
+        minstance.a = 1
+        names = [x for x in dir(minstance) if x not in ["__name__", "__doc__"]]
+        self.assertEqual(names, ['a', 'b'])
+
+        class M2(M):
+            def getdict(self):
+                return "Not a dict!"
+            __dict__ = property(getdict)
+
+        m2instance = M2("m2")
+        m2instance.b = 2
+        m2instance.a = 1
+        self.assertEqual(m2instance.__dict__, "Not a dict!")
+        try:
+            dir(m2instance)
+        except TypeError:
+            pass
+
+        # Two essentially featureless objects, just inheriting stuff from
+        # object.
+        self.assertEqual(dir(None), dir(Ellipsis))
+
+        # Nasty test case for proxied objects
+        class Wrapper(object):
+            def __init__(self, obj):
+                self.__obj = obj
+            def __repr__(self):
+                return "Wrapper(%s)" % repr(self.__obj)
+            def __getitem__(self, key):
+                return Wrapper(self.__obj[key])
+            def __len__(self):
+                return len(self.__obj)
+            def __getattr__(self, name):
+                return Wrapper(getattr(self.__obj, name))
+
+        class C(object):
+            def __getclass(self):
+                return Wrapper(type(self))
+            __class__ = property(__getclass)
+
+        dir(C()) # This used to segfault
+
+    def test_supers(self):
+        # Testing super...
+
+        class A(object):
+            def meth(self, a):
+                return "A(%r)" % a
+
+        self.assertEqual(A().meth(1), "A(1)")
+
+        class B(A):
+            def __init__(self):
+                self.__super = super(B, self)
+            def meth(self, a):
+                return "B(%r)" % a + self.__super.meth(a)
+
+        self.assertEqual(B().meth(2), "B(2)A(2)")
+
+        class C(A):
+            def meth(self, a):
+                return "C(%r)" % a + self.__super.meth(a)
+        C._C__super = super(C)
+
+        self.assertEqual(C().meth(3), "C(3)A(3)")
+
+        class D(C, B):
+            def meth(self, a):
+                return "D(%r)" % a + super(D, self).meth(a)
+
+        self.assertEqual(D().meth(4), "D(4)C(4)B(4)A(4)")
+
+        # Test for subclassing super
+
+        class mysuper(super):
+            def __init__(self, *args):
+                return super(mysuper, self).__init__(*args)
+
+        class E(D):
+            def meth(self, a):
+                return "E(%r)" % a + mysuper(E, self).meth(a)
+
+        self.assertEqual(E().meth(5), "E(5)D(5)C(5)B(5)A(5)")
+
+        class F(E):
+            def meth(self, a):
+                s = self.__super # == mysuper(F, self)
+                return "F(%r)[%s]" % (a, s.__class__.__name__) + s.meth(a)
+        F._F__super = mysuper(F)
+
+        self.assertEqual(F().meth(6), "F(6)[mysuper]E(6)D(6)C(6)B(6)A(6)")
+
+        # Make sure certain errors are raised
+
+        try:
+            super(D, 42)
+        except TypeError:
+            pass
+        else:
+            self.fail("shouldn't allow super(D, 42)")
+
+        try:
+            super(D, C())
+        except TypeError:
+            pass
+        else:
+            self.fail("shouldn't allow super(D, C())")
+
+        try:
+            super(D).__get__(12)
+        except TypeError:
+            pass
+        else:
+            self.fail("shouldn't allow super(D).__get__(12)")
+
+        try:
+            super(D).__get__(C())
+        except TypeError:
+            pass
+        else:
+            self.fail("shouldn't allow super(D).__get__(C())")
+
+        # Make sure data descriptors can be overridden and accessed via super
+        # (new feature in Python 2.3)
+
+        class DDbase(object):
+            def getx(self): return 42
+            x = property(getx)
+
+        class DDsub(DDbase):
+            def getx(self): return "hello"
+            x = property(getx)
+
+        dd = DDsub()
+        self.assertEqual(dd.x, "hello")
+        self.assertEqual(super(DDsub, dd).x, 42)
+
+        # Ensure that super() lookup of descriptor from classmethod
+        # works (SF ID# 743627)
+
+        class Base(object):
+            aProp = property(lambda self: "foo")
+
+        class Sub(Base):
+            @classmethod
+            def test(klass):
+                return super(Sub,klass).aProp
+
+        self.assertEqual(Sub.test(), Base.aProp)
+
+        # Verify that super() doesn't allow keyword args
+        try:
+            super(Base, kw=1)
+        except TypeError:
+            pass
+        else:
+            self.assertEqual("super shouldn't accept keyword args")
+
+    def test_basic_inheritance(self):
+        # Testing inheritance from basic types...
+
+        class hexint(int):
+            def __repr__(self):
+                return hex(self)
+            def __add__(self, other):
+                return hexint(int.__add__(self, other))
+            # (Note that overriding __radd__ doesn't work,
+            # because the int type gets first dibs.)
+        self.assertEqual(repr(hexint(7) + 9), "0x10")
+        self.assertEqual(repr(hexint(1000) + 7), "0x3ef")
+        a = hexint(12345)
+        self.assertEqual(a, 12345)
+        self.assertEqual(int(a), 12345)
+        self.assert_(int(a).__class__ is int)
+        self.assertEqual(hash(a), hash(12345))
+        self.assert_((+a).__class__ is int)
+        self.assert_((a >> 0).__class__ is int)
+        self.assert_((a << 0).__class__ is int)
+        self.assert_((hexint(0) << 12).__class__ is int)
+        self.assert_((hexint(0) >> 12).__class__ is int)
+
+        class octlong(int):
+            __slots__ = []
+            def __str__(self):
+                s = oct(self)
+                if s[-1] == 'L':
+                    s = s[:-1]
+                return s
+            def __add__(self, other):
+                return self.__class__(super(octlong, self).__add__(other))
+            __radd__ = __add__
+        self.assertEqual(str(octlong(3) + 5), "0o10")
+        # (Note that overriding __radd__ here only seems to work
+        # because the example uses a short int left argument.)
+        self.assertEqual(str(5 + octlong(3000)), "0o5675")
+        a = octlong(12345)
+        self.assertEqual(a, 12345)
+        self.assertEqual(int(a), 12345)
+        self.assertEqual(hash(a), hash(12345))
+        self.assert_(int(a).__class__ is int)
+        self.assert_((+a).__class__ is int)
+        self.assert_((-a).__class__ is int)
+        self.assert_((-octlong(0)).__class__ is int)
+        self.assert_((a >> 0).__class__ is int)
+        self.assert_((a << 0).__class__ is int)
+        self.assert_((a - 0).__class__ is int)
+        self.assert_((a * 1).__class__ is int)
+        self.assert_((a ** 1).__class__ is int)
+        self.assert_((a // 1).__class__ is int)
+        self.assert_((1 * a).__class__ is int)
+        self.assert_((a | 0).__class__ is int)
+        self.assert_((a ^ 0).__class__ is int)
+        self.assert_((a & -1).__class__ is int)
+        self.assert_((octlong(0) << 12).__class__ is int)
+        self.assert_((octlong(0) >> 12).__class__ is int)
+        self.assert_(abs(octlong(0)).__class__ is int)
+
+        # Because octlong overrides __add__, we can't check the absence of +0
+        # optimizations using octlong.
+        class longclone(int):
+            pass
+        a = longclone(1)
+        self.assert_((a + 0).__class__ is int)
+        self.assert_((0 + a).__class__ is int)
+
+        # Check that negative clones don't segfault
+        a = longclone(-1)
+        self.assertEqual(a.__dict__, {})
+        self.assertEqual(int(a), -1)  # self.assert_ PyNumber_Long() copies the sign bit
+
+        class precfloat(float):
+            __slots__ = ['prec']
+            def __init__(self, value=0.0, prec=12):
+                self.prec = int(prec)
+            def __repr__(self):
+                return "%.*g" % (self.prec, self)
+        self.assertEqual(repr(precfloat(1.1)), "1.1")
+        a = precfloat(12345)
+        self.assertEqual(a, 12345.0)
+        self.assertEqual(float(a), 12345.0)
+        self.assert_(float(a).__class__ is float)
+        self.assertEqual(hash(a), hash(12345.0))
+        self.assert_((+a).__class__ is float)
+
+        class madcomplex(complex):
+            def __repr__(self):
+                return "%.17gj%+.17g" % (self.imag, self.real)
+        a = madcomplex(-3, 4)
+        self.assertEqual(repr(a), "4j-3")
+        base = complex(-3, 4)
+        self.assertEqual(base.__class__, complex)
+        self.assertEqual(a, base)
+        self.assertEqual(complex(a), base)
+        self.assertEqual(complex(a).__class__, complex)
+        a = madcomplex(a)  # just trying another form of the constructor
+        self.assertEqual(repr(a), "4j-3")
+        self.assertEqual(a, base)
+        self.assertEqual(complex(a), base)
+        self.assertEqual(complex(a).__class__, complex)
+        self.assertEqual(hash(a), hash(base))
+        self.assertEqual((+a).__class__, complex)
+        self.assertEqual((a + 0).__class__, complex)
+        self.assertEqual(a + 0, base)
+        self.assertEqual((a - 0).__class__, complex)
+        self.assertEqual(a - 0, base)
+        self.assertEqual((a * 1).__class__, complex)
+        self.assertEqual(a * 1, base)
+        self.assertEqual((a / 1).__class__, complex)
+        self.assertEqual(a / 1, base)
+
+        class madtuple(tuple):
+            _rev = None
+            def rev(self):
+                if self._rev is not None:
+                    return self._rev
+                L = list(self)
+                L.reverse()
+                self._rev = self.__class__(L)
+                return self._rev
+        a = madtuple((1,2,3,4,5,6,7,8,9,0))
+        self.assertEqual(a, (1,2,3,4,5,6,7,8,9,0))
+        self.assertEqual(a.rev(), madtuple((0,9,8,7,6,5,4,3,2,1)))
+        self.assertEqual(a.rev().rev(), madtuple((1,2,3,4,5,6,7,8,9,0)))
+        for i in range(512):
+            t = madtuple(range(i))
+            u = t.rev()
+            v = u.rev()
+            self.assertEqual(v, t)
+        a = madtuple((1,2,3,4,5))
+        self.assertEqual(tuple(a), (1,2,3,4,5))
+        self.assert_(tuple(a).__class__ is tuple)
+        self.assertEqual(hash(a), hash((1,2,3,4,5)))
+        self.assert_(a[:].__class__ is tuple)
+        self.assert_((a * 1).__class__ is tuple)
+        self.assert_((a * 0).__class__ is tuple)
+        self.assert_((a + ()).__class__ is tuple)
+        a = madtuple(())
+        self.assertEqual(tuple(a), ())
+        self.assert_(tuple(a).__class__ is tuple)
+        self.assert_((a + a).__class__ is tuple)
+        self.assert_((a * 0).__class__ is tuple)
+        self.assert_((a * 1).__class__ is tuple)
+        self.assert_((a * 2).__class__ is tuple)
+        self.assert_(a[:].__class__ is tuple)
+
+        class madstring(str):
+            _rev = None
+            def rev(self):
+                if self._rev is not None:
+                    return self._rev
+                L = list(self)
+                L.reverse()
+                self._rev = self.__class__("".join(L))
+                return self._rev
+        s = madstring("abcdefghijklmnopqrstuvwxyz")
+        self.assertEqual(s, "abcdefghijklmnopqrstuvwxyz")
+        self.assertEqual(s.rev(), madstring("zyxwvutsrqponmlkjihgfedcba"))
+        self.assertEqual(s.rev().rev(), madstring("abcdefghijklmnopqrstuvwxyz"))
+        for i in range(256):
+            s = madstring("".join(map(chr, range(i))))
+            t = s.rev()
+            u = t.rev()
+            self.assertEqual(u, s)
+        s = madstring("12345")
+        self.assertEqual(str(s), "12345")
+        self.assert_(str(s).__class__ is str)
+
+        base = "\x00" * 5
+        s = madstring(base)
+        self.assertEqual(s, base)
+        self.assertEqual(str(s), base)
+        self.assert_(str(s).__class__ is str)
+        self.assertEqual(hash(s), hash(base))
+        self.assertEqual({s: 1}[base], 1)
+        self.assertEqual({base: 1}[s], 1)
+        self.assert_((s + "").__class__ is str)
+        self.assertEqual(s + "", base)
+        self.assert_(("" + s).__class__ is str)
+        self.assertEqual("" + s, base)
+        self.assert_((s * 0).__class__ is str)
+        self.assertEqual(s * 0, "")
+        self.assert_((s * 1).__class__ is str)
+        self.assertEqual(s * 1, base)
+        self.assert_((s * 2).__class__ is str)
+        self.assertEqual(s * 2, base + base)
+        self.assert_(s[:].__class__ is str)
+        self.assertEqual(s[:], base)
+        self.assert_(s[0:0].__class__ is str)
+        self.assertEqual(s[0:0], "")
+        self.assert_(s.strip().__class__ is str)
+        self.assertEqual(s.strip(), base)
+        self.assert_(s.lstrip().__class__ is str)
+        self.assertEqual(s.lstrip(), base)
+        self.assert_(s.rstrip().__class__ is str)
+        self.assertEqual(s.rstrip(), base)
+        identitytab = {}
+        self.assert_(s.translate(identitytab).__class__ is str)
+        self.assertEqual(s.translate(identitytab), base)
+        self.assert_(s.replace("x", "x").__class__ is str)
+        self.assertEqual(s.replace("x", "x"), base)
+        self.assert_(s.ljust(len(s)).__class__ is str)
+        self.assertEqual(s.ljust(len(s)), base)
+        self.assert_(s.rjust(len(s)).__class__ is str)
+        self.assertEqual(s.rjust(len(s)), base)
+        self.assert_(s.center(len(s)).__class__ is str)
+        self.assertEqual(s.center(len(s)), base)
+        self.assert_(s.lower().__class__ is str)
+        self.assertEqual(s.lower(), base)
+
+        class madunicode(str):
+            _rev = None
+            def rev(self):
+                if self._rev is not None:
+                    return self._rev
+                L = list(self)
+                L.reverse()
+                self._rev = self.__class__("".join(L))
+                return self._rev
+        u = madunicode("ABCDEF")
+        self.assertEqual(u, "ABCDEF")
+        self.assertEqual(u.rev(), madunicode("FEDCBA"))
+        self.assertEqual(u.rev().rev(), madunicode("ABCDEF"))
+        base = "12345"
+        u = madunicode(base)
+        self.assertEqual(str(u), base)
+        self.assert_(str(u).__class__ is str)
+        self.assertEqual(hash(u), hash(base))
+        self.assertEqual({u: 1}[base], 1)
+        self.assertEqual({base: 1}[u], 1)
+        self.assert_(u.strip().__class__ is str)
+        self.assertEqual(u.strip(), base)
+        self.assert_(u.lstrip().__class__ is str)
+        self.assertEqual(u.lstrip(), base)
+        self.assert_(u.rstrip().__class__ is str)
+        self.assertEqual(u.rstrip(), base)
+        self.assert_(u.replace("x", "x").__class__ is str)
+        self.assertEqual(u.replace("x", "x"), base)
+        self.assert_(u.replace("xy", "xy").__class__ is str)
+        self.assertEqual(u.replace("xy", "xy"), base)
+        self.assert_(u.center(len(u)).__class__ is str)
+        self.assertEqual(u.center(len(u)), base)
+        self.assert_(u.ljust(len(u)).__class__ is str)
+        self.assertEqual(u.ljust(len(u)), base)
+        self.assert_(u.rjust(len(u)).__class__ is str)
+        self.assertEqual(u.rjust(len(u)), base)
+        self.assert_(u.lower().__class__ is str)
+        self.assertEqual(u.lower(), base)
+        self.assert_(u.upper().__class__ is str)
+        self.assertEqual(u.upper(), base)
+        self.assert_(u.capitalize().__class__ is str)
+        self.assertEqual(u.capitalize(), base)
+        self.assert_(u.title().__class__ is str)
+        self.assertEqual(u.title(), base)
+        self.assert_((u + "").__class__ is str)
+        self.assertEqual(u + "", base)
+        self.assert_(("" + u).__class__ is str)
+        self.assertEqual("" + u, base)
+        self.assert_((u * 0).__class__ is str)
+        self.assertEqual(u * 0, "")
+        self.assert_((u * 1).__class__ is str)
+        self.assertEqual(u * 1, base)
+        self.assert_((u * 2).__class__ is str)
+        self.assertEqual(u * 2, base + base)
+        self.assert_(u[:].__class__ is str)
+        self.assertEqual(u[:], base)
+        self.assert_(u[0:0].__class__ is str)
+        self.assertEqual(u[0:0], "")
+
+        class sublist(list):
+            pass
+        a = sublist(range(5))
+        self.assertEqual(a, list(range(5)))
+        a.append("hello")
+        self.assertEqual(a, list(range(5)) + ["hello"])
+        a[5] = 5
+        self.assertEqual(a, list(range(6)))
+        a.extend(range(6, 20))
+        self.assertEqual(a, list(range(20)))
+        a[-5:] = []
+        self.assertEqual(a, list(range(15)))
+        del a[10:15]
+        self.assertEqual(len(a), 10)
+        self.assertEqual(a, list(range(10)))
+        self.assertEqual(list(a), list(range(10)))
+        self.assertEqual(a[0], 0)
+        self.assertEqual(a[9], 9)
+        self.assertEqual(a[-10], 0)
+        self.assertEqual(a[-1], 9)
+        self.assertEqual(a[:5], list(range(5)))
+
+        ## class CountedInput(file):
+        ##    """Counts lines read by self.readline().
+        ##
+        ##     self.lineno is the 0-based ordinal of the last line read, up to
+        ##     a maximum of one greater than the number of lines in the file.
+        ##
+        ##     self.ateof is true if and only if the final "" line has been read,
+        ##     at which point self.lineno stops incrementing, and further calls
+        ##     to readline() continue to return "".
+        ##     """
+        ##
+        ##     lineno = 0
+        ##     ateof = 0
+        ##     def readline(self):
+        ##         if self.ateof:
+        ##             return ""
+        ##         s = file.readline(self)
+        ##         # Next line works too.
+        ##         # s = super(CountedInput, self).readline()
+        ##         self.lineno += 1
+        ##         if s == "":
+        ##             self.ateof = 1
+        ##        return s
+        ##
+        ## f = file(name=test_support.TESTFN, mode='w')
+        ## lines = ['a\n', 'b\n', 'c\n']
+        ## try:
+        ##     f.writelines(lines)
+        ##     f.close()
+        ##     f = CountedInput(test_support.TESTFN)
+        ##     for (i, expected) in zip(range(1, 5) + [4], lines + 2 * [""]):
+        ##         got = f.readline()
+        ##         self.assertEqual(expected, got)
+        ##         self.assertEqual(f.lineno, i)
+        ##         self.assertEqual(f.ateof, (i > len(lines)))
+        ##     f.close()
+        ## finally:
+        ##     try:
+        ##         f.close()
+        ##     except:
+        ##         pass
+        ##     test_support.unlink(test_support.TESTFN)
+
+    def test_keywords(self):
+        # Testing keyword args to basic type constructors ...
+        self.assertEqual(int(x=1), 1)
+        self.assertEqual(float(x=2), 2.0)
+        self.assertEqual(int(x=3), 3)
+        self.assertEqual(complex(imag=42, real=666), complex(666, 42))
+        self.assertEqual(str(object=500), '500')
+        self.assertEqual(str(object=b'abc', errors='strict'), 'abc')
+        self.assertEqual(tuple(sequence=range(3)), (0, 1, 2))
+        self.assertEqual(list(sequence=(0, 1, 2)), list(range(3)))
+        # note: as of Python 2.3, dict() no longer has an "items" keyword arg
+
+        for constructor in (int, float, int, complex, str, str,
+                            tuple, list):
+            try:
+                constructor(bogus_keyword_arg=1)
+            except TypeError:
+                pass
+            else:
+                self.fail("expected TypeError from bogus keyword argument to %r"
+                            % constructor)
+
+    def test_str_subclass_as_dict_key(self):
+        # Testing a str subclass used as dict key ..
+
+        class cistr(str):
+            """Sublcass of str that computes __eq__ case-insensitively.
+
+            Also computes a hash code of the string in canonical form.
+            """
+
+            def __init__(self, value):
+                self.canonical = value.lower()
+                self.hashcode = hash(self.canonical)
+
+            def __eq__(self, other):
+                if not isinstance(other, cistr):
+                    other = cistr(other)
+                return self.canonical == other.canonical
+
+            def __hash__(self):
+                return self.hashcode
+
+        self.assertEqual(cistr('ABC'), 'abc')
+        self.assertEqual('aBc', cistr('ABC'))
+        self.assertEqual(str(cistr('ABC')), 'ABC')
+
+        d = {cistr('one'): 1, cistr('two'): 2, cistr('tHree'): 3}
+        self.assertEqual(d[cistr('one')], 1)
+        self.assertEqual(d[cistr('tWo')], 2)
+        self.assertEqual(d[cistr('THrEE')], 3)
+        self.assert_(cistr('ONe') in d)
+        self.assertEqual(d.get(cistr('thrEE')), 3)
+
+    def test_classic_comparisons(self):
+        # Testing classic comparisons...
+        class classic:
+            pass
+
+        for base in (classic, int, object):
+            class C(base):
+                def __init__(self, value):
+                    self.value = int(value)
+                def __eq__(self, other):
+                    if isinstance(other, C):
+                        return self.value == other.value
+                    if isinstance(other, int) or isinstance(other, int):
+                        return self.value == other
+                    return NotImplemented
+                def __ne__(self, other):
+                    if isinstance(other, C):
+                        return self.value != other.value
+                    if isinstance(other, int) or isinstance(other, int):
+                        return self.value != other
+                    return NotImplemented
+                def __lt__(self, other):
+                    if isinstance(other, C):
+                        return self.value < other.value
+                    if isinstance(other, int) or isinstance(other, int):
+                        return self.value < other
+                    return NotImplemented
+                def __le__(self, other):
+                    if isinstance(other, C):
+                        return self.value <= other.value
+                    if isinstance(other, int) or isinstance(other, int):
+                        return self.value <= other
+                    return NotImplemented
+                def __gt__(self, other):
+                    if isinstance(other, C):
+                        return self.value > other.value
+                    if isinstance(other, int) or isinstance(other, int):
+                        return self.value > other
+                    return NotImplemented
+                def __ge__(self, other):
+                    if isinstance(other, C):
+                        return self.value >= other.value
+                    if isinstance(other, int) or isinstance(other, int):
+                        return self.value >= other
+                    return NotImplemented
+
+            c1 = C(1)
+            c2 = C(2)
+            c3 = C(3)
+            self.assertEqual(c1, 1)
+            c = {1: c1, 2: c2, 3: c3}
+            for x in 1, 2, 3:
+                for y in 1, 2, 3:
+                    ## self.assert_(cmp(c[x], c[y]) == cmp(x, y), "x=%d, y=%d" % (x, y))
+                    for op in "<", "<=", "==", "!=", ">", ">=":
+                        self.assert_(eval("c[x] %s c[y]" % op) == eval("x %s y" % op),
+                               "x=%d, y=%d" % (x, y))
+                    ## self.assert_(cmp(c[x], y) == cmp(x, y), "x=%d, y=%d" % (x, y))
+                    ## self.assert_(cmp(x, c[y]) == cmp(x, y), "x=%d, y=%d" % (x, y))
+
+    def test_rich_comparisons(self):
+        # Testing rich comparisons...
+        class Z(complex):
+            pass
+        z = Z(1)
+        self.assertEqual(z, 1+0j)
+        self.assertEqual(1+0j, z)
+        class ZZ(complex):
+            def __eq__(self, other):
+                try:
+                    return abs(self - other) <= 1e-6
+                except:
+                    return NotImplemented
+        zz = ZZ(1.0000003)
+        self.assertEqual(zz, 1+0j)
+        self.assertEqual(1+0j, zz)
+
+        class classic:
+            pass
+        for base in (classic, int, object, list):
+            class C(base):
+                def __init__(self, value):
+                    self.value = int(value)
+                def __cmp__(self_, other):
+                    self.fail("shouldn't call __cmp__")
+                def __eq__(self, other):
+                    if isinstance(other, C):
+                        return self.value == other.value
+                    if isinstance(other, int) or isinstance(other, int):
+                        return self.value == other
+                    return NotImplemented
+                def __ne__(self, other):
+                    if isinstance(other, C):
+                        return self.value != other.value
+                    if isinstance(other, int) or isinstance(other, int):
+                        return self.value != other
+                    return NotImplemented
+                def __lt__(self, other):
+                    if isinstance(other, C):
+                        return self.value < other.value
+                    if isinstance(other, int) or isinstance(other, int):
+                        return self.value < other
+                    return NotImplemented
+                def __le__(self, other):
+                    if isinstance(other, C):
+                        return self.value <= other.value
+                    if isinstance(other, int) or isinstance(other, int):
+                        return self.value <= other
+                    return NotImplemented
+                def __gt__(self, other):
+                    if isinstance(other, C):
+                        return self.value > other.value
+                    if isinstance(other, int) or isinstance(other, int):
+                        return self.value > other
+                    return NotImplemented
+                def __ge__(self, other):
+                    if isinstance(other, C):
+                        return self.value >= other.value
+                    if isinstance(other, int) or isinstance(other, int):
+                        return self.value >= other
+                    return NotImplemented
+            c1 = C(1)
+            c2 = C(2)
+            c3 = C(3)
+            self.assertEqual(c1, 1)
+            c = {1: c1, 2: c2, 3: c3}
+            for x in 1, 2, 3:
+                for y in 1, 2, 3:
+                    for op in "<", "<=", "==", "!=", ">", ">=":
+                        self.assert_(eval("c[x] %s c[y]" % op) == eval("x %s y" % op),
+                               "x=%d, y=%d" % (x, y))
+                        self.assert_(eval("c[x] %s y" % op) == eval("x %s y" % op),
+                               "x=%d, y=%d" % (x, y))
+                        self.assert_(eval("x %s c[y]" % op) == eval("x %s y" % op),
+                               "x=%d, y=%d" % (x, y))
+
+    def test_descrdoc(self):
+        # Testing descriptor doc strings...
+        from _fileio import _FileIO
+        def check(descr, what):
+            self.assertEqual(descr.__doc__, what)
+        check(_FileIO.closed, "True if the file is closed") # getset descriptor
+        check(complex.real, "the real part of a complex number") # member descriptor
+
+    def test_doc_descriptor(self):
+        # Testing __doc__ descriptor...
+        # SF bug 542984
+        class DocDescr(object):
+            def __get__(self, object, otype):
+                if object:
+                    object = object.__class__.__name__ + ' instance'
+                if otype:
+                    otype = otype.__name__
+                return 'object=%s; type=%s' % (object, otype)
+        class OldClass:
+            __doc__ = DocDescr()
+        class NewClass(object):
+            __doc__ = DocDescr()
+        self.assertEqual(OldClass.__doc__, 'object=None; type=OldClass')
+        self.assertEqual(OldClass().__doc__, 'object=OldClass instance; type=OldClass')
+        self.assertEqual(NewClass.__doc__, 'object=None; type=NewClass')
+        self.assertEqual(NewClass().__doc__, 'object=NewClass instance; type=NewClass')
+
+    def test_set_class(self):
+        # Testing __class__ assignment...
+        class C(object): pass
+        class D(object): pass
+        class E(object): pass
+        class F(D, E): pass
+        for cls in C, D, E, F:
+            for cls2 in C, D, E, F:
+                x = cls()
+                x.__class__ = cls2
+                self.assert_(x.__class__ is cls2)
+                x.__class__ = cls
+                self.assert_(x.__class__ is cls)
+        def cant(x, C):
+            try:
+                x.__class__ = C
+            except TypeError:
+                pass
+            else:
+                self.fail("shouldn't allow %r.__class__ = %r" % (x, C))
+            try:
+                delattr(x, "__class__")
+            except TypeError:
+                pass
+            else:
+                self.fail("shouldn't allow del %r.__class__" % x)
+        cant(C(), list)
+        cant(list(), C)
+        cant(C(), 1)
+        cant(C(), object)
+        cant(object(), list)
+        cant(list(), object)
+        class Int(int): __slots__ = []
+        cant(2, Int)
+        cant(Int(), int)
+        cant(True, int)
+        cant(2, bool)
+        o = object()
+        cant(o, type(1))
+        cant(o, type(None))
+        del o
+        class G(object):
+            __slots__ = ["a", "b"]
+        class H(object):
+            __slots__ = ["b", "a"]
+        class I(object):
+            __slots__ = ["a", "b"]
+        class J(object):
+            __slots__ = ["c", "b"]
+        class K(object):
+            __slots__ = ["a", "b", "d"]
+        class L(H):
+            __slots__ = ["e"]
+        class M(I):
+            __slots__ = ["e"]
+        class N(J):
+            __slots__ = ["__weakref__"]
+        class P(J):
+            __slots__ = ["__dict__"]
+        class Q(J):
+            pass
+        class R(J):
+            __slots__ = ["__dict__", "__weakref__"]
+
+        for cls, cls2 in ((G, H), (G, I), (I, H), (Q, R), (R, Q)):
+            x = cls()
+            x.a = 1
+            x.__class__ = cls2
+            self.assert_(x.__class__ is cls2,
+                   "assigning %r as __class__ for %r silently failed" % (cls2, x))
+            self.assertEqual(x.a, 1)
+            x.__class__ = cls
+            self.assert_(x.__class__ is cls,
+                   "assigning %r as __class__ for %r silently failed" % (cls, x))
+            self.assertEqual(x.a, 1)
+        for cls in G, J, K, L, M, N, P, R, list, Int:
+            for cls2 in G, J, K, L, M, N, P, R, list, Int:
+                if cls is cls2:
+                    continue
+                cant(cls(), cls2)
+
+    def test_set_dict(self):
+        # Testing __dict__ assignment...
+        class C(object): pass
+        a = C()
+        a.__dict__ = {'b': 1}
+        self.assertEqual(a.b, 1)
+        def cant(x, dict):
+            try:
+                x.__dict__ = dict
+            except (AttributeError, TypeError):
+                pass
+            else:
+                self.fail("shouldn't allow %r.__dict__ = %r" % (x, dict))
+        cant(a, None)
+        cant(a, [])
+        cant(a, 1)
+        del a.__dict__ # Deleting __dict__ is allowed
+
+        class Base(object):
+            pass
+        def verify_dict_readonly(x):
+            """
+            x has to be an instance of a class inheriting from Base.
+            """
+            cant(x, {})
+            try:
+                del x.__dict__
+            except (AttributeError, TypeError):
+                pass
+            else:
+                self.fail("shouldn't allow del %r.__dict__" % x)
+            dict_descr = Base.__dict__["__dict__"]
+            try:
+                dict_descr.__set__(x, {})
+            except (AttributeError, TypeError):
+                pass
+            else:
+                self.fail("dict_descr allowed access to %r's dict" % x)
+
+        # Classes don't allow __dict__ assignment and have readonly dicts
+        class Meta1(type, Base):
+            pass
+        class Meta2(Base, type):
+            pass
+        class D(object, metaclass=Meta1):
+            pass
+        class E(object, metaclass=Meta2):
+            pass
+        for cls in C, D, E:
+            verify_dict_readonly(cls)
+            class_dict = cls.__dict__
+            try:
+                class_dict["spam"] = "eggs"
+            except TypeError:
+                pass
+            else:
+                self.fail("%r's __dict__ can be modified" % cls)
+
+        # Modules also disallow __dict__ assignment
+        class Module1(types.ModuleType, Base):
+            pass
+        class Module2(Base, types.ModuleType):
+            pass
+        for ModuleType in Module1, Module2:
+            mod = ModuleType("spam")
+            verify_dict_readonly(mod)
+            mod.__dict__["spam"] = "eggs"
+
+        # Exception's __dict__ can be replaced, but not deleted
+        class Exception1(Exception, Base):
+            pass
+        class Exception2(Base, Exception):
+            pass
+        for ExceptionType in Exception, Exception1, Exception2:
+            e = ExceptionType()
+            e.__dict__ = {"a": 1}
+            self.assertEqual(e.a, 1)
+            try:
+                del e.__dict__
+            except (TypeError, AttributeError):
+                pass
+            else:
+                self.fail("%r's __dict__ can be deleted" % e)
+
+    def test_pickles(self):
+        # Testing pickling and copying new-style classes and objects...
+        import pickle
+
+        def sorteditems(d):
+            L = list(d.items())
+            L.sort()
+            return L
+
+        global C
+        class C(object):
+            def __init__(self, a, b):
+                super(C, self).__init__()
+                self.a = a
+                self.b = b
+            def __repr__(self):
+                return "C(%r, %r)" % (self.a, self.b)
+
+        global C1
+        class C1(list):
+            def __new__(cls, a, b):
+                return super(C1, cls).__new__(cls)
+            def __getnewargs__(self):
+                return (self.a, self.b)
+            def __init__(self, a, b):
+                self.a = a
+                self.b = b
+            def __repr__(self):
+                return "C1(%r, %r)<%r>" % (self.a, self.b, list(self))
+
+        global C2
+        class C2(int):
+            def __new__(cls, a, b, val=0):
+                return super(C2, cls).__new__(cls, val)
+            def __getnewargs__(self):
+                return (self.a, self.b, int(self))
+            def __init__(self, a, b, val=0):
+                self.a = a
+                self.b = b
+            def __repr__(self):
+                return "C2(%r, %r)<%r>" % (self.a, self.b, int(self))
+
+        global C3
+        class C3(object):
+            def __init__(self, foo):
+                self.foo = foo
+            def __getstate__(self):
+                return self.foo
+            def __setstate__(self, foo):
+                self.foo = foo
+
+        global C4classic, C4
+        class C4classic: # classic
+            pass
+        class C4(C4classic, object): # mixed inheritance
+            pass
+
+        for bin in 0, 1:
+            for cls in C, C1, C2:
+                s = pickle.dumps(cls, bin)
+                cls2 = pickle.loads(s)
+                self.assert_(cls2 is cls)
+
+            a = C1(1, 2); a.append(42); a.append(24)
+            b = C2("hello", "world", 42)
+            s = pickle.dumps((a, b), bin)
+            x, y = pickle.loads(s)
+            self.assertEqual(x.__class__, a.__class__)
+            self.assertEqual(sorteditems(x.__dict__), sorteditems(a.__dict__))
+            self.assertEqual(y.__class__, b.__class__)
+            self.assertEqual(sorteditems(y.__dict__), sorteditems(b.__dict__))
+            self.assertEqual(repr(x), repr(a))
+            self.assertEqual(repr(y), repr(b))
+            # Test for __getstate__ and __setstate__ on new style class
+            u = C3(42)
+            s = pickle.dumps(u, bin)
+            v = pickle.loads(s)
+            self.assertEqual(u.__class__, v.__class__)
+            self.assertEqual(u.foo, v.foo)
+            # Test for picklability of hybrid class
+            u = C4()
+            u.foo = 42
+            s = pickle.dumps(u, bin)
+            v = pickle.loads(s)
+            self.assertEqual(u.__class__, v.__class__)
+            self.assertEqual(u.foo, v.foo)
+
+        # Testing copy.deepcopy()
+        import copy
+        for cls in C, C1, C2:
+            cls2 = copy.deepcopy(cls)
+            self.assert_(cls2 is cls)
+
+        a = C1(1, 2); a.append(42); a.append(24)
+        b = C2("hello", "world", 42)
+        x, y = copy.deepcopy((a, b))
+        self.assertEqual(x.__class__, a.__class__)
+        self.assertEqual(sorteditems(x.__dict__), sorteditems(a.__dict__))
+        self.assertEqual(y.__class__, b.__class__)
+        self.assertEqual(sorteditems(y.__dict__), sorteditems(b.__dict__))
+        self.assertEqual(repr(x), repr(a))
+        self.assertEqual(repr(y), repr(b))
+
+    def test_pickle_slots(self):
+        # Testing pickling of classes with __slots__ ...
+        import pickle
+        # Pickling of classes with __slots__ but without __getstate__ should fail
+        # (if using protocol 0 or 1)
+        global B, C, D, E
+        class B(object):
+            pass
+        for base in [object, B]:
+            class C(base):
+                __slots__ = ['a']
+            class D(C):
+                pass
+            try:
+                pickle.dumps(C(), 0)
+            except TypeError:
+                pass
+            else:
+                self.fail("should fail: pickle C instance - %s" % base)
+            try:
+                pickle.dumps(C(), 0)
+            except TypeError:
+                pass
+            else:
+                self.fail("should fail: pickle D instance - %s" % base)
+            # Give C a nice generic __getstate__ and __setstate__
+            class C(base):
+                __slots__ = ['a']
+                def __getstate__(self):
+                    try:
+                        d = self.__dict__.copy()
+                    except AttributeError:
+                        d = {}
+                    for cls in self.__class__.__mro__:
+                        for sn in cls.__dict__.get('__slots__', ()):
+                            try:
+                                d[sn] = getattr(self, sn)
+                            except AttributeError:
+                                pass
+                    return d
+                def __setstate__(self, d):
+                    for k, v in list(d.items()):
+                        setattr(self, k, v)
+            class D(C):
+                pass
+            # Now it should work
+            x = C()
+            y = pickle.loads(pickle.dumps(x))
+            self.assertEqual(hasattr(y, 'a'), 0)
+            x.a = 42
+            y = pickle.loads(pickle.dumps(x))
+            self.assertEqual(y.a, 42)
+            x = D()
+            x.a = 42
+            x.b = 100
+            y = pickle.loads(pickle.dumps(x))
+            self.assertEqual(y.a + y.b, 142)
+            # A subclass that adds a slot should also work
+            class E(C):
+                __slots__ = ['b']
+            x = E()
+            x.a = 42
+            x.b = "foo"
+            y = pickle.loads(pickle.dumps(x))
+            self.assertEqual(y.a, x.a)
+            self.assertEqual(y.b, x.b)
+
+    def test_binary_operator_override(self):
+        # Testing overrides of binary operations...
+        class I(int):
+            def __repr__(self):
+                return "I(%r)" % int(self)
+            def __add__(self, other):
+                return I(int(self) + int(other))
+            __radd__ = __add__
+            def __pow__(self, other, mod=None):
+                if mod is None:
+                    return I(pow(int(self), int(other)))
+                else:
+                    return I(pow(int(self), int(other), int(mod)))
+            def __rpow__(self, other, mod=None):
+                if mod is None:
+                    return I(pow(int(other), int(self), mod))
+                else:
+                    return I(pow(int(other), int(self), int(mod)))
+
+        self.assertEqual(repr(I(1) + I(2)), "I(3)")
+        self.assertEqual(repr(I(1) + 2), "I(3)")
+        self.assertEqual(repr(1 + I(2)), "I(3)")
+        self.assertEqual(repr(I(2) ** I(3)), "I(8)")
+        self.assertEqual(repr(2 ** I(3)), "I(8)")
+        self.assertEqual(repr(I(2) ** 3), "I(8)")
+        self.assertEqual(repr(pow(I(2), I(3), I(5))), "I(3)")
+        class S(str):
+            def __eq__(self, other):
+                return self.lower() == other.lower()
+
+    def test_subclass_propagation(self):
+        # Testing propagation of slot functions to subclasses...
+        class A(object):
+            pass
+        class B(A):
+            pass
+        class C(A):
+            pass
+        class D(B, C):
+            pass
+        d = D()
+        orig_hash = hash(d) # related to id(d) in platform-dependent ways
+        A.__hash__ = lambda self: 42
+        self.assertEqual(hash(d), 42)
+        C.__hash__ = lambda self: 314
+        self.assertEqual(hash(d), 314)
+        B.__hash__ = lambda self: 144
+        self.assertEqual(hash(d), 144)
+        D.__hash__ = lambda self: 100
+        self.assertEqual(hash(d), 100)
+        del D.__hash__
+        self.assertEqual(hash(d), 144)
+        del B.__hash__
+        self.assertEqual(hash(d), 314)
+        del C.__hash__
+        self.assertEqual(hash(d), 42)
+        del A.__hash__
+        self.assertEqual(hash(d), orig_hash)
+        d.foo = 42
+        d.bar = 42
+        self.assertEqual(d.foo, 42)
+        self.assertEqual(d.bar, 42)
+        def __getattribute__(self, name):
+            if name == "foo":
+                return 24
+            return object.__getattribute__(self, name)
+        A.__getattribute__ = __getattribute__
+        self.assertEqual(d.foo, 24)
+        self.assertEqual(d.bar, 42)
+        def __getattr__(self, name):
+            if name in ("spam", "foo", "bar"):
+                return "hello"
+            raise AttributeError(name)
+        B.__getattr__ = __getattr__
+        self.assertEqual(d.spam, "hello")
+        self.assertEqual(d.foo, 24)
+        self.assertEqual(d.bar, 42)
+        del A.__getattribute__
+        self.assertEqual(d.foo, 42)
+        del d.foo
+        self.assertEqual(d.foo, "hello")
+        self.assertEqual(d.bar, 42)
+        del B.__getattr__
+        try:
+            d.foo
+        except AttributeError:
+            pass
+        else:
+            self.fail("d.foo should be undefined now")
+
+        # Test a nasty bug in recurse_down_subclasses()
+        import gc
+        class A(object):
+            pass
+        class B(A):
+            pass
+        del B
+        gc.collect()
+        A.__setitem__ = lambda *a: None # crash
+
+    def test_buffer_inheritance(self):
+        # Testing that buffer interface is inherited ...
+
+        import binascii
+        # SF bug [#470040] ParseTuple t# vs subclasses.
+
+        class MyStr(str):
+            pass
+        base = 'abc'
+        m = MyStr(base)
+        # b2a_hex uses the buffer interface to get its argument's value, via
+        # PyArg_ParseTuple 't#' code.
+        self.assertEqual(binascii.b2a_hex(m), binascii.b2a_hex(base))
+
+        # It's not clear that unicode will continue to support the character
+        # buffer interface, and this test will fail if that's taken away.
+        class MyUni(str):
+            pass
+        base = 'abc'
+        m = MyUni(base)
+        self.assertEqual(binascii.b2a_hex(m), binascii.b2a_hex(base))
+
+        class MyInt(int):
+            pass
+        m = MyInt(42)
+        try:
+            binascii.b2a_hex(m)
+            self.fail('subclass of int should not have a buffer interface')
+        except TypeError:
+            pass
+
+    def test_str_of_str_subclass(self):
+        # Testing __str__ defined in subclass of str ...
+        import binascii
+        import io
+
+        class octetstring(str):
+            def __str__(self):
+                return binascii.b2a_hex(self).decode("ascii")
+            def __repr__(self):
+                return self + " repr"
+
+        o = octetstring('A')
+        self.assertEqual(type(o), octetstring)
+        self.assertEqual(type(str(o)), str)
+        self.assertEqual(type(repr(o)), str)
+        self.assertEqual(ord(o), 0x41)
+        self.assertEqual(str(o), '41')
+        self.assertEqual(repr(o), 'A repr')
+        self.assertEqual(o.__str__(), '41')
+        self.assertEqual(o.__repr__(), 'A repr')
+
+        capture = io.StringIO()
+        # Calling str() or not exercises different internal paths.
+        print(o, file=capture)
+        print(str(o), file=capture)
+        self.assertEqual(capture.getvalue(), '41\n41\n')
+        capture.close()
+
+    def test_keyword_arguments(self):
+        # Testing keyword arguments to __init__, __call__...
+        def f(a): return a
+        self.assertEqual(f.__call__(a=42), 42)
+        a = []
+        list.__init__(a, sequence=[0, 1, 2])
+        self.assertEqual(a, [0, 1, 2])
+
+    def test_recursive_call(self):
+        # Testing recursive __call__() by setting to instance of class...
+        class A(object):
+            pass
+
+        A.__call__ = A()
+        try:
+            A()()
+        except RuntimeError:
+            pass
         else:
-            raise TestFailed("no TypeError from dict(%r)" % badarg)
+            self.fail("Recursion limit should have been reached for __call__()")
 
-    try:
-        dict({}, {})
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("no TypeError from dict({}, {})")
-
-    class Mapping:
-        # Lacks a .keys() method; will be added later.
-        dict = {1:2, 3:4, 'a':1j}
-
-    try:
-        dict(Mapping())
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("no TypeError from dict(incomplete mapping)")
-
-    Mapping.keys = lambda self: self.dict.keys()
-    Mapping.__getitem__ = lambda self, i: self.dict[i]
-    d = dict(Mapping())
-    vereq(d, Mapping.dict)
-
-    # Init from sequence of iterable objects, each producing a 2-sequence.
-    class AddressBookEntry:
-        def __init__(self, first, last):
-            self.first = first
-            self.last = last
-        def __iter__(self):
-            return iter([self.first, self.last])
-
-    d = dict([AddressBookEntry('Tim', 'Warsaw'),
-              AddressBookEntry('Barry', 'Peters'),
-              AddressBookEntry('Tim', 'Peters'),
-              AddressBookEntry('Barry', 'Warsaw')])
-    vereq(d, {'Barry': 'Warsaw', 'Tim': 'Peters'})
-
-    d = dict(zip(range(4), range(1, 5)))
-    vereq(d, dict([(i, i+1) for i in range(4)]))
-
-    # Bad sequence lengths.
-    for bad in [('tooshort',)], [('too', 'long', 'by 1')]:
-        try:
-            dict(bad)
-        except ValueError:
-            pass
-        else:
-            raise TestFailed("no ValueError from dict(%r)" % bad)
-
-def test_dir():
-    if verbose:
-        print("Testing dir() ...")
-    junk = 12
-    vereq(dir(), ['junk'])
-    del junk
-
-    # Just make sure these don't blow up!
-    for arg in 2, 2, 2j, 2e0, [2], "2", b"2", (2,), {2:2}, type, test_dir:
-        dir(arg)
-
-    # Test dir on custom classes. Since these have object as a
-    # base class, a lot of stuff gets sucked in.
-    def interesting(strings):
-        return [s for s in strings if not s.startswith('_')]
-
-    class C(object):
-        Cdata = 1
-        def Cmethod(self): pass
-
-    cstuff = ['Cdata', 'Cmethod']
-    vereq(interesting(dir(C)), cstuff)
-
-    c = C()
-    vereq(interesting(dir(c)), cstuff)
-    verify('im_self' in dir(C.Cmethod))
-
-    c.cdata = 2
-    c.cmethod = lambda self: 0
-    vereq(interesting(dir(c)), cstuff + ['cdata', 'cmethod'])
-    verify('im_self' in dir(c.Cmethod))
-
-    class A(C):
-        Adata = 1
-        def Amethod(self): pass
-
-    astuff = ['Adata', 'Amethod'] + cstuff
-    vereq(interesting(dir(A)), astuff)
-    verify('im_self' in dir(A.Amethod))
-    a = A()
-    vereq(interesting(dir(a)), astuff)
-    a.adata = 42
-    a.amethod = lambda self: 3
-    vereq(interesting(dir(a)), astuff + ['adata', 'amethod'])
-    verify('im_self' in dir(a.Amethod))
-
-    # Try a module subclass.
-    import sys
-    class M(type(sys)):
-        pass
-    minstance = M("m")
-    minstance.b = 2
-    minstance.a = 1
-    names = [x for x in dir(minstance) if x not in ["__name__", "__doc__"]]
-    vereq(names, ['a', 'b'])
-
-    class M2(M):
-        def getdict(self):
-            return "Not a dict!"
-        __dict__ = property(getdict)
-
-    m2instance = M2("m2")
-    m2instance.b = 2
-    m2instance.a = 1
-    vereq(m2instance.__dict__, "Not a dict!")
-    try:
-        dir(m2instance)
-    except TypeError:
-        pass
-
-    # Two essentially featureless objects, just inheriting stuff from
-    # object.
-    vereq(dir(None), dir(Ellipsis))
-
-    # Nasty test case for proxied objects
-    class Wrapper(object):
-        def __init__(self, obj):
-            self.__obj = obj
-        def __repr__(self):
-            return "Wrapper(%s)" % repr(self.__obj)
-        def __getitem__(self, key):
-            return Wrapper(self.__obj[key])
-        def __len__(self):
-            return len(self.__obj)
-        def __getattr__(self, name):
-            return Wrapper(getattr(self.__obj, name))
+    def test_delete_hook(self):
+        # Testing __del__ hook...
+        log = []
+        class C(object):
+            def __del__(self):
+                log.append(1)
+        c = C()
+        self.assertEqual(log, [])
+        del c
+        self.assertEqual(log, [1])
+
+        class D(object): pass
+        d = D()
+        try: del d[0]
+        except TypeError: pass
+        else: self.fail("invalid del() didn't raise TypeError")
 
-    class C(object):
-        def __getclass(self):
-            return Wrapper(type(self))
-        __class__ = property(__getclass)
-
-    dir(C()) # This used to segfault
-
-binops = {
-    'add': '+',
-    'sub': '-',
-    'mul': '*',
-    'div': '/',
-    'mod': '%',
-    'divmod': 'divmod',
-    'pow': '**',
-    'lshift': '<<',
-    'rshift': '>>',
-    'and': '&',
-    'xor': '^',
-    'or': '|',
-    'cmp': 'cmp',
-    'lt': '<',
-    'le': '<=',
-    'eq': '==',
-    'ne': '!=',
-    'gt': '>',
-    'ge': '>=',
-    }
-
-for name, expr in binops.items():
-    if expr.islower():
-        expr = expr + "(a, b)"
-    else:
-        expr = 'a %s b' % expr
-    binops[name] = expr
-
-unops = {
-    'pos': '+',
-    'neg': '-',
-    'abs': 'abs',
-    'invert': '~',
-    'int': 'int',
-    'float': 'float',
-    'oct': 'oct',
-    'hex': 'hex',
-    }
-
-for name, expr in unops.items():
-    if expr.islower():
-        expr = expr + "(a)"
-    else:
-        expr = '%s a' % expr
-    unops[name] = expr
-
-def numops(a, b, skip=[]):
-    dict = {'a': a, 'b': b}
-    for name, expr in binops.items():
-        if name not in skip:
-            name = "__%s__" % name
-            if hasattr(a, name):
-                res = eval(expr, dict)
-                testbinop(a, b, res, expr, name)
-    for name, expr in unops.items():
-        if name not in skip:
-            name = "__%s__" % name
-            if hasattr(a, name):
-                res = eval(expr, dict)
-                testunop(a, res, expr, name)
-
-def ints():
-    if verbose: print("Testing int operations...")
-    numops(100, 3)
-    # The following crashes in Python 2.2
-    vereq((1).__bool__(), True)
-    vereq((0).__bool__(), False)
-    # This returns 'NotImplemented' in Python 2.2
-    class C(int):
-        def __add__(self, other):
-            return NotImplemented
-    vereq(C(5), 5)
-    try:
-        C() + ""
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("NotImplemented should have caused TypeError")
-
-def longs():
-    if verbose: print("Testing long operations...")
-    numops(100, 3)
-
-def floats():
-    if verbose: print("Testing float operations...")
-    numops(100.0, 3.0)
-
-def complexes():
-    if verbose: print("Testing complex operations...")
-    numops(100.0j, 3.0j,
-           skip=['lt', 'le', 'gt', 'ge', 'int', 'long', 'float',
-                 'divmod', 'mod'])
-    class Number(complex):
-        __slots__ = ['prec']
-        def __new__(cls, *args, **kwds):
-            result = complex.__new__(cls, *args)
-            result.prec = kwds.get('prec', 12)
-            return result
-        def __repr__(self):
-            prec = self.prec
-            if self.imag == 0.0:
-                return "%.*g" % (prec, self.real)
-            if self.real == 0.0:
-                return "%.*gj" % (prec, self.imag)
-            return "(%.*g+%.*gj)" % (prec, self.real, prec, self.imag)
-        __str__ = __repr__
-
-    a = Number(3.14, prec=6)
-    vereq(repr(a), "3.14")
-    vereq(a.prec, 6)
-
-    a = Number(a, prec=2)
-    vereq(repr(a), "3.1")
-    vereq(a.prec, 2)
-
-    a = Number(234.5)
-    vereq(repr(a), "234.5")
-    vereq(a.prec, 12)
-
-def spamlists():
-    if verbose: print("Testing spamlist operations...")
-    import copy, xxsubtype as spam
-    def spamlist(l, memo=None):
-        import xxsubtype as spam
-        return spam.spamlist(l)
-    # This is an ugly hack:
-    copy._deepcopy_dispatch[spam.spamlist] = spamlist
-
-    testbinop(spamlist([1]), spamlist([2]), spamlist([1,2]), "a+b", "__add__")
-    testbinop(spamlist([1,2,3]), 2, 1, "b in a", "__contains__")
-    testbinop(spamlist([1,2,3]), 4, 0, "b in a", "__contains__")
-    testbinop(spamlist([1,2,3]), 1, 2, "a[b]", "__getitem__")
-    testsliceop(spamlist([1,2,3]), 0, 2, spamlist([1,2]),
-                "a[b:c]", "__getitem__")
-    testsetop(spamlist([1]), spamlist([2]), spamlist([1,2]),
-              "a+=b", "__iadd__")
-    testsetop(spamlist([1,2]), 3, spamlist([1,2,1,2,1,2]), "a*=b", "__imul__")
-    testunop(spamlist([1,2,3]), 3, "len(a)", "__len__")
-    testbinop(spamlist([1,2]), 3, spamlist([1,2,1,2,1,2]), "a*b", "__mul__")
-    testbinop(spamlist([1,2]), 3, spamlist([1,2,1,2,1,2]), "b*a", "__rmul__")
-    testset2op(spamlist([1,2]), 1, 3, spamlist([1,3]), "a[b]=c", "__setitem__")
-    testsetsliceop(spamlist([1,2,3,4]), 1, 3, spamlist([5,6]),
-                   spamlist([1,5,6,4]), "a[b:c]=d", "__setitem__")
-    # Test subclassing
-    class C(spam.spamlist):
-        def foo(self): return 1
-    a = C()
-    vereq(a, [])
-    vereq(a.foo(), 1)
-    a.append(100)
-    vereq(a, [100])
-    vereq(a.getstate(), 0)
-    a.setstate(42)
-    vereq(a.getstate(), 42)
-
-def spamdicts():
-    if verbose: print("Testing spamdict operations...")
-    import copy, xxsubtype as spam
-    def spamdict(d, memo=None):
-        import xxsubtype as spam
-        sd = spam.spamdict()
-        for k, v in d.items(): sd[k] = v
-        return sd
-    # This is an ugly hack:
-    copy._deepcopy_dispatch[spam.spamdict] = spamdict
-
-    ##testbinop(spamdict({1:2}), spamdict({2:1}), -1, "cmp(a,b)", "__cmp__")
-    testbinop(spamdict({1:2,3:4}), 1, 1, "b in a", "__contains__")
-    testbinop(spamdict({1:2,3:4}), 2, 0, "b in a", "__contains__")
-    testbinop(spamdict({1:2,3:4}), 1, 2, "a[b]", "__getitem__")
-    d = spamdict({1:2,3:4})
-    l1 = []
-    for i in d.keys(): l1.append(i)
-    l = []
-    for i in iter(d): l.append(i)
-    vereq(l, l1)
-    l = []
-    for i in d.__iter__(): l.append(i)
-    vereq(l, l1)
-    l = []
-    for i in type(spamdict({})).__iter__(d): l.append(i)
-    vereq(l, l1)
-    straightd = {1:2, 3:4}
-    spamd = spamdict(straightd)
-    testunop(spamd, 2, "len(a)", "__len__")
-    testunop(spamd, repr(straightd), "repr(a)", "__repr__")
-    testset2op(spamdict({1:2,3:4}), 2, 3, spamdict({1:2,2:3,3:4}),
-               "a[b]=c", "__setitem__")
-    # Test subclassing
-    class C(spam.spamdict):
-        def foo(self): return 1
-    a = C()
-    vereq(list(a.items()), [])
-    vereq(a.foo(), 1)
-    a['foo'] = 'bar'
-    vereq(list(a.items()), [('foo', 'bar')])
-    vereq(a.getstate(), 0)
-    a.setstate(100)
-    vereq(a.getstate(), 100)
-
-def pydicts():
-    if verbose: print("Testing Python subclass of dict...")
-    verify(issubclass(dict, dict))
-    verify(isinstance({}, dict))
-    d = dict()
-    vereq(d, {})
-    verify(d.__class__ is dict)
-    verify(isinstance(d, dict))
-    class C(dict):
-        state = -1
-        def __init__(self, *a, **kw):
-            if a:
-                vereq(len(a), 1)
-                self.state = a[0]
-            if kw:
-                for k, v in kw.items(): self[v] = k
-        def __getitem__(self, key):
-            return self.get(key, 0)
-        def __setitem__(self, key, value):
-            verify(isinstance(key, type(0)))
-            dict.__setitem__(self, key, value)
-        def setstate(self, state):
-            self.state = state
-        def getstate(self):
-            return self.state
-    verify(issubclass(C, dict))
-    a1 = C(12)
-    vereq(a1.state, 12)
-    a2 = C(foo=1, bar=2)
-    vereq(a2[1] == 'foo' and a2[2], 'bar')
-    a = C()
-    vereq(a.state, -1)
-    vereq(a.getstate(), -1)
-    a.setstate(0)
-    vereq(a.state, 0)
-    vereq(a.getstate(), 0)
-    a.setstate(10)
-    vereq(a.state, 10)
-    vereq(a.getstate(), 10)
-    vereq(a[42], 0)
-    a[42] = 24
-    vereq(a[42], 24)
-    if verbose: print("pydict stress test ...")
-    N = 50
-    for i in range(N):
-        a[i] = C()
-        for j in range(N):
-            a[i][j] = i*j
-    for i in range(N):
-        for j in range(N):
-            vereq(a[i][j], i*j)
-
-def pylists():
-    if verbose: print("Testing Python subclass of list...")
-    class C(list):
-        def __getitem__(self, i):
-            if isinstance(i, slice):
-                return (i.start, i.stop)
-            return list.__getitem__(self, i) + 100
-    a = C()
-    a.extend([0,1,2])
-    vereq(a[0], 100)
-    vereq(a[1], 101)
-    vereq(a[2], 102)
-    vereq(a[100:200], (100,200))
-
-def metaclass():
-    if verbose: print("Testing metaclass...")
-    class C(metaclass=type):
-        def __init__(self):
-            self.__state = 0
-        def getstate(self):
-            return self.__state
-        def setstate(self, state):
-            self.__state = state
-    a = C()
-    vereq(a.getstate(), 0)
-    a.setstate(10)
-    vereq(a.getstate(), 10)
-    class _metaclass(type):
-        def myself(cls): return cls
-    class D(metaclass=_metaclass):
-        pass
-    vereq(D.myself(), D)
-    d = D()
-    verify(d.__class__ is D)
-    class M1(type):
-        def __new__(cls, name, bases, dict):
-            dict['__spam__'] = 1
-            return type.__new__(cls, name, bases, dict)
-    class C(metaclass=M1):
-        pass
-    vereq(C.__spam__, 1)
-    c = C()
-    vereq(c.__spam__, 1)
-
-    class _instance(object):
-        pass
-    class M2(object):
-        @staticmethod
-        def __new__(cls, name, bases, dict):
-            self = object.__new__(cls)
-            self.name = name
-            self.bases = bases
-            self.dict = dict
-            return self
-        def __call__(self):
-            it = _instance()
-            # Early binding of methods
-            for key in self.dict:
-                if key.startswith("__"):
-                    continue
-                setattr(it, key, self.dict[key].__get__(it, self))
-            return it
-    class C(metaclass=M2):
-        def spam(self):
-            return 42
-    vereq(C.name, 'C')
-    vereq(C.bases, ())
-    verify('spam' in C.dict)
-    c = C()
-    vereq(c.spam(), 42)
-
-    # More metaclass examples
-
-    class autosuper(type):
-        # Automatically add __super to the class
-        # This trick only works for dynamic classes
-        def __new__(metaclass, name, bases, dict):
-            cls = super(autosuper, metaclass).__new__(metaclass,
-                                                      name, bases, dict)
-            # Name mangling for __super removes leading underscores
-            while name[:1] == "_":
-                name = name[1:]
-            if name:
-                name = "_%s__super" % name
-            else:
-                name = "__super"
-            setattr(cls, name, super(cls))
-            return cls
-    class A(metaclass=autosuper):
-        def meth(self):
-            return "A"
-    class B(A):
-        def meth(self):
-            return "B" + self.__super.meth()
-    class C(A):
-        def meth(self):
-            return "C" + self.__super.meth()
-    class D(C, B):
-        def meth(self):
-            return "D" + self.__super.meth()
-    vereq(D().meth(), "DCBA")
-    class E(B, C):
-        def meth(self):
-            return "E" + self.__super.meth()
-    vereq(E().meth(), "EBCA")
-
-    class autoproperty(type):
-        # Automatically create property attributes when methods
-        # named _get_x and/or _set_x are found
-        def __new__(metaclass, name, bases, dict):
-            hits = {}
-            for key, val in dict.items():
-                if key.startswith("_get_"):
-                    key = key[5:]
-                    get, set = hits.get(key, (None, None))
-                    get = val
-                    hits[key] = get, set
-                elif key.startswith("_set_"):
-                    key = key[5:]
-                    get, set = hits.get(key, (None, None))
-                    set = val
-                    hits[key] = get, set
-            for key, (get, set) in hits.items():
-                dict[key] = property(get, set)
-            return super(autoproperty, metaclass).__new__(metaclass,
-                                                        name, bases, dict)
-    class A(metaclass=autoproperty):
-        def _get_x(self):
-            return -self.__x
-        def _set_x(self, x):
-            self.__x = -x
-    a = A()
-    verify(not hasattr(a, "x"))
-    a.x = 12
-    vereq(a.x, 12)
-    vereq(a._A__x, -12)
-
-    class multimetaclass(autoproperty, autosuper):
-        # Merge of multiple cooperating metaclasses
-        pass
-    class A(metaclass=multimetaclass):
-        def _get_x(self):
-            return "A"
-    class B(A):
-        def _get_x(self):
-            return "B" + self.__super._get_x()
-    class C(A):
-        def _get_x(self):
-            return "C" + self.__super._get_x()
-    class D(C, B):
-        def _get_x(self):
-            return "D" + self.__super._get_x()
-    vereq(D().x, "DCBA")
-
-    # Make sure type(x) doesn't call x.__class__.__init__
-    class T(type):
-        counter = 0
-        def __init__(self, *args):
-            T.counter += 1
-    class C(metaclass=T):
-        pass
-    vereq(T.counter, 1)
-    a = C()
-    vereq(type(a), C)
-    vereq(T.counter, 1)
-
-    class C(object): pass
-    c = C()
-    try: c()
-    except TypeError: pass
-    else: raise TestFailed("calling object w/o call method should raise TypeError")
-
-    # Testing code to find most derived baseclass
-    class A(type):
-        def __new__(*args, **kwargs):
-            return type.__new__(*args, **kwargs)
-
-    class B(object):
-        pass
-
-    class C(object, metaclass=A):
-        pass
-
-    # The most derived metaclass of D is A rather than type.
-    class D(B, C):
-        pass
-
-
-def pymods():
-    if verbose: print("Testing Python subclass of module...")
-    log = []
-    import sys
-    MT = type(sys)
-    class MM(MT):
-        def __init__(self, name):
-            MT.__init__(self, name)
-        def __getattribute__(self, name):
-            log.append(("getattr", name))
-            return MT.__getattribute__(self, name)
-        def __setattr__(self, name, value):
-            log.append(("setattr", name, value))
-            MT.__setattr__(self, name, value)
-        def __delattr__(self, name):
-            log.append(("delattr", name))
-            MT.__delattr__(self, name)
-    a = MM("a")
-    a.foo = 12
-    x = a.foo
-    del a.foo
-    vereq(log, [("setattr", "foo", 12),
-                ("getattr", "foo"),
-                ("delattr", "foo")])
-
-    # http://python.org/sf/1174712
-    try:
-        class Module(types.ModuleType, str):
-            pass
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("inheriting from ModuleType and str at the "
-                          "same time should fail")
-
-def multi():
-    if verbose: print("Testing multiple inheritance...")
-    class C(object):
-        def __init__(self):
-            self.__state = 0
-        def getstate(self):
-            return self.__state
-        def setstate(self, state):
-            self.__state = state
-    a = C()
-    vereq(a.getstate(), 0)
-    a.setstate(10)
-    vereq(a.getstate(), 10)
-    class D(dict, C):
-        def __init__(self):
-            type({}).__init__(self)
-            C.__init__(self)
-    d = D()
-    vereq(list(d.keys()), [])
-    d["hello"] = "world"
-    vereq(list(d.items()), [("hello", "world")])
-    vereq(d["hello"], "world")
-    vereq(d.getstate(), 0)
-    d.setstate(10)
-    vereq(d.getstate(), 10)
-    vereq(D.__mro__, (D, dict, C, object))
-
-    # SF bug #442833
-    class Node(object):
-        def __int__(self):
-            return int(self.foo())
-        def foo(self):
-            return "23"
-    class Frag(Node, list):
-        def foo(self):
-            return "42"
-    vereq(Node().__int__(), 23)
-    vereq(int(Node()), 23)
-    vereq(Frag().__int__(), 42)
-    vereq(int(Frag()), 42)
-
-def diamond():
-    if verbose: print("Testing multiple inheritance special cases...")
-    class A(object):
-        def spam(self): return "A"
-    vereq(A().spam(), "A")
-    class B(A):
-        def boo(self): return "B"
-        def spam(self): return "B"
-    vereq(B().spam(), "B")
-    vereq(B().boo(), "B")
-    class C(A):
-        def boo(self): return "C"
-    vereq(C().spam(), "A")
-    vereq(C().boo(), "C")
-    class D(B, C): pass
-    vereq(D().spam(), "B")
-    vereq(D().boo(), "B")
-    vereq(D.__mro__, (D, B, C, A, object))
-    class E(C, B): pass
-    vereq(E().spam(), "B")
-    vereq(E().boo(), "C")
-    vereq(E.__mro__, (E, C, B, A, object))
-    # MRO order disagreement
-    try:
-        class F(D, E): pass
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("expected MRO order disagreement (F)")
-    try:
-        class G(E, D): pass
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("expected MRO order disagreement (G)")
-
-
-# see thread python-dev/2002-October/029035.html
-def ex5():
-    if verbose: print("Testing ex5 from C3 switch discussion...")
-    class A(object): pass
-    class B(object): pass
-    class C(object): pass
-    class X(A): pass
-    class Y(A): pass
-    class Z(X,B,Y,C): pass
-    vereq(Z.__mro__, (Z, X, B, Y, A, C, object))
-
-# see "A Monotonic Superclass Linearization for Dylan",
-# by Kim Barrett et al. (OOPSLA 1996)
-def monotonicity():
-    if verbose: print("Testing MRO monotonicity...")
-    class Boat(object): pass
-    class DayBoat(Boat): pass
-    class WheelBoat(Boat): pass
-    class EngineLess(DayBoat): pass
-    class SmallMultihull(DayBoat): pass
-    class PedalWheelBoat(EngineLess,WheelBoat): pass
-    class SmallCatamaran(SmallMultihull): pass
-    class Pedalo(PedalWheelBoat,SmallCatamaran): pass
-
-    vereq(PedalWheelBoat.__mro__,
-          (PedalWheelBoat, EngineLess, DayBoat, WheelBoat, Boat,
-           object))
-    vereq(SmallCatamaran.__mro__,
-          (SmallCatamaran, SmallMultihull, DayBoat, Boat, object))
-
-    vereq(Pedalo.__mro__,
-          (Pedalo, PedalWheelBoat, EngineLess, SmallCatamaran,
-           SmallMultihull, DayBoat, WheelBoat, Boat, object))
-
-# see "A Monotonic Superclass Linearization for Dylan",
-# by Kim Barrett et al. (OOPSLA 1996)
-def consistency_with_epg():
-    if verbose: print("Testing consistentcy with EPG...")
-    class Pane(object): pass
-    class ScrollingMixin(object): pass
-    class EditingMixin(object): pass
-    class ScrollablePane(Pane,ScrollingMixin): pass
-    class EditablePane(Pane,EditingMixin): pass
-    class EditableScrollablePane(ScrollablePane,EditablePane): pass
-
-    vereq(EditableScrollablePane.__mro__,
-          (EditableScrollablePane, ScrollablePane, EditablePane,
-           Pane, ScrollingMixin, EditingMixin, object))
+    def test_hash_inheritance(self):
+        # Testing hash of mutable subclasses...
 
-mro_err_msg = """Cannot create a consistent method resolution
-order (MRO) for bases """
+        class mydict(dict):
+            pass
+        d = mydict()
+        try:
+            hash(d)
+        except TypeError:
+            pass
+        else:
+            self.fail("hash() of dict subclass should fail")
 
-def mro_disagreement():
-    if verbose: print("Testing error messages for MRO disagreement...")
-    def raises(exc, expected, callable, *args):
-        try:
-            callable(*args)
-        except exc as msg:
-            if not str(msg).startswith(expected):
-                raise TestFailed("Message %r, expected %r" % (str(msg),
-                                                               expected))
-        else:
-            raise TestFailed("Expected %s" % exc)
-    class A(object): pass
-    class B(A): pass
-    class C(object): pass
-    # Test some very simple errors
-    raises(TypeError, "duplicate base class A",
-           type, "X", (A, A), {})
-    raises(TypeError, mro_err_msg,
-           type, "X", (A, B), {})
-    raises(TypeError, mro_err_msg,
-           type, "X", (A, C, B), {})
-    # Test a slightly more complex error
-    class GridLayout(object): pass
-    class HorizontalGrid(GridLayout): pass
-    class VerticalGrid(GridLayout): pass
-    class HVGrid(HorizontalGrid, VerticalGrid): pass
-    class VHGrid(VerticalGrid, HorizontalGrid): pass
-    raises(TypeError, mro_err_msg,
-           type, "ConfusedGrid", (HVGrid, VHGrid), {})
-
-def objects():
-    if verbose: print("Testing object class...")
-    a = object()
-    vereq(a.__class__, object)
-    vereq(type(a), object)
-    b = object()
-    verify(a is not b)
-    verify(not hasattr(a, "foo"))
-    try:
-        a.foo = 12
-    except (AttributeError, TypeError):
-        pass
-    else:
-        verify(0, "object() should not allow setting a foo attribute")
-    verify(not hasattr(object(), "__dict__"))
-
-    class Cdict(object):
-        pass
-    x = Cdict()
-    vereq(x.__dict__, {})
-    x.foo = 1
-    vereq(x.foo, 1)
-    vereq(x.__dict__, {'foo': 1})
-
-def slots():
-    if verbose: print("Testing __slots__...")
-    class C0(object):
-        __slots__ = []
-    x = C0()
-    verify(not hasattr(x, "__dict__"))
-    verify(not hasattr(x, "foo"))
-
-    class C1(object):
-        __slots__ = ['a']
-    x = C1()
-    verify(not hasattr(x, "__dict__"))
-    verify(not hasattr(x, "a"))
-    x.a = 1
-    vereq(x.a, 1)
-    x.a = None
-    veris(x.a, None)
-    del x.a
-    verify(not hasattr(x, "a"))
-
-    class C3(object):
-        __slots__ = ['a', 'b', 'c']
-    x = C3()
-    verify(not hasattr(x, "__dict__"))
-    verify(not hasattr(x, 'a'))
-    verify(not hasattr(x, 'b'))
-    verify(not hasattr(x, 'c'))
-    x.a = 1
-    x.b = 2
-    x.c = 3
-    vereq(x.a, 1)
-    vereq(x.b, 2)
-    vereq(x.c, 3)
-
-    class C4(object):
-        """Validate name mangling"""
-        __slots__ = ['__a']
-        def __init__(self, value):
-            self.__a = value
-        def get(self):
-            return self.__a
-    x = C4(5)
-    verify(not hasattr(x, '__dict__'))
-    verify(not hasattr(x, '__a'))
-    vereq(x.get(), 5)
-    try:
-        x.__a = 6
-    except AttributeError:
-        pass
-    else:
-        raise TestFailed("Double underscored names not mangled")
+        class mylist(list):
+            pass
+        d = mylist()
+        try:
+            hash(d)
+        except TypeError:
+            pass
+        else:
+            self.fail("hash() of list subclass should fail")
 
-    # Make sure slot names are proper identifiers
-    try:
-        class C(object):
-            __slots__ = [None]
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("[None] slots not caught")
-    try:
-        class C(object):
-            __slots__ = ["foo bar"]
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("['foo bar'] slots not caught")
-    try:
-        class C(object):
-            __slots__ = ["foo\0bar"]
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("['foo\\0bar'] slots not caught")
-    try:
+    def test_str_operations(self):
+        try: 'a' + 5
+        except TypeError: pass
+        else: self.fail("'' + 5 doesn't raise TypeError")
+
+        try: ''.split('')
+        except ValueError: pass
+        else: self.fail("''.split('') doesn't raise ValueError")
+
+        try: ''.join([0])
+        except TypeError: pass
+        else: self.fail("''.join([0]) doesn't raise TypeError")
+
+        try: ''.rindex('5')
+        except ValueError: pass
+        else: self.fail("''.rindex('5') doesn't raise ValueError")
+
+        try: '%(n)s' % None
+        except TypeError: pass
+        else: self.fail("'%(n)s' % None doesn't raise TypeError")
+
+        try: '%(n' % {}
+        except ValueError: pass
+        else: self.fail("'%(n' % {} '' doesn't raise ValueError")
+
+        try: '%*s' % ('abc')
+        except TypeError: pass
+        else: self.fail("'%*s' % ('abc') doesn't raise TypeError")
+
+        try: '%*.*s' % ('abc', 5)
+        except TypeError: pass
+        else: self.fail("'%*.*s' % ('abc', 5) doesn't raise TypeError")
+
+        try: '%s' % (1, 2)
+        except TypeError: pass
+        else: self.fail("'%s' % (1, 2) doesn't raise TypeError")
+
+        try: '%' % None
+        except ValueError: pass
+        else: self.fail("'%' % None doesn't raise ValueError")
+
+        self.assertEqual('534253'.isdigit(), 1)
+        self.assertEqual('534253x'.isdigit(), 0)
+        self.assertEqual('%c' % 5, '\x05')
+        self.assertEqual('%c' % '5', '5')
+
+    def test_deepcopy_recursive(self):
+        # Testing deepcopy of recursive objects...
+        class Node:
+            pass
+        a = Node()
+        b = Node()
+        a.b = b
+        b.a = a
+        z = deepcopy(a) # This blew up before
+
+    def test_unintialized_modules(self):
+        # Testing uninitialized module objects...
+        from types import ModuleType as M
+        m = M.__new__(M)
+        str(m)
+        self.assertEqual(hasattr(m, "__name__"), 0)
+        self.assertEqual(hasattr(m, "__file__"), 0)
+        self.assertEqual(hasattr(m, "foo"), 0)
+        self.assertEqual(m.__dict__, None)
+        m.foo = 1
+        self.assertEqual(m.__dict__, {"foo": 1})
+
+    def test_funny_new(self):
+        # Testing __new__ returning something unexpected...
         class C(object):
-            __slots__ = ["1"]
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("['1'] slots not caught")
-    try:
+            def __new__(cls, arg):
+                if isinstance(arg, str): return [1, 2, 3]
+                elif isinstance(arg, int): return object.__new__(D)
+                else: return object.__new__(cls)
+        class D(C):
+            def __init__(self, arg):
+                self.foo = arg
+        self.assertEqual(C("1"), [1, 2, 3])
+        self.assertEqual(D("1"), [1, 2, 3])
+        d = D(None)
+        self.assertEqual(d.foo, None)
+        d = C(1)
+        self.assertEqual(isinstance(d, D), True)
+        self.assertEqual(d.foo, 1)
+        d = D(1)
+        self.assertEqual(isinstance(d, D), True)
+        self.assertEqual(d.foo, 1)
+
+    def test_imul_bug(self):
+        # Testing for __imul__ problems...
+        # SF bug 544647
         class C(object):
-            __slots__ = [""]
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("[''] slots not caught")
-    class C(object):
-        __slots__ = ["a", "a_b", "_a", "A0123456789Z"]
-    # XXX(nnorwitz): was there supposed to be something tested
-    # from the class above?
-
-    # Test a single string is not expanded as a sequence.
-    class C(object):
-        __slots__ = "abc"
-    c = C()
-    c.abc = 5
-    vereq(c.abc, 5)
-
-    # Test unicode slot names
-    # Test a single unicode string is not expanded as a sequence.
-    class C(object):
-        __slots__ = "abc"
-    c = C()
-    c.abc = 5
-    vereq(c.abc, 5)
-
-    # _unicode_to_string used to modify slots in certain circumstances
-    slots = ("foo", "bar")
-    class C(object):
-        __slots__ = slots
-    x = C()
-    x.foo = 5
-    vereq(x.foo, 5)
-    veris(type(slots[0]), str)
-    # this used to leak references
-    try:
+            def __imul__(self, other):
+                return (self, other)
+        x = C()
+        y = x
+        y *= 1.0
+        self.assertEqual(y, (x, 1.0))
+        y = x
+        y *= 2
+        self.assertEqual(y, (x, 2))
+        y = x
+        y *= 3
+        self.assertEqual(y, (x, 3))
+        y = x
+        y *= 1<<100
+        self.assertEqual(y, (x, 1<<100))
+        y = x
+        y *= None
+        self.assertEqual(y, (x, None))
+        y = x
+        y *= "foo"
+        self.assertEqual(y, (x, "foo"))
+
+    def test_copy_setstate(self):
+        # Testing that copy.*copy() correctly uses __setstate__...
+        import copy
         class C(object):
-            __slots__ = [chr(128)]
-    except (TypeError, UnicodeEncodeError):
-        pass
-    else:
-        raise TestFailed("[unichr(128)] slots not caught")
-
-    # Test leaks
-    class Counted(object):
-        counter = 0    # counts the number of instances alive
-        def __init__(self):
-            Counted.counter += 1
-        def __del__(self):
-            Counted.counter -= 1
-    class C(object):
-        __slots__ = ['a', 'b', 'c']
-    x = C()
-    x.a = Counted()
-    x.b = Counted()
-    x.c = Counted()
-    vereq(Counted.counter, 3)
-    del x
-    vereq(Counted.counter, 0)
-    class D(C):
-        pass
-    x = D()
-    x.a = Counted()
-    x.z = Counted()
-    vereq(Counted.counter, 2)
-    del x
-    vereq(Counted.counter, 0)
-    class E(D):
-        __slots__ = ['e']
-    x = E()
-    x.a = Counted()
-    x.z = Counted()
-    x.e = Counted()
-    vereq(Counted.counter, 3)
-    del x
-    vereq(Counted.counter, 0)
-
-    # Test cyclical leaks [SF bug 519621]
-    class F(object):
-        __slots__ = ['a', 'b']
-    log = []
-    s = F()
-    s.a = [Counted(), s]
-    vereq(Counted.counter, 1)
-    s = None
-    import gc
-    gc.collect()
-    vereq(Counted.counter, 0)
-
-    # Test lookup leaks [SF bug 572567]
-    import sys,gc
-    class G(object):
-        def __cmp__(self, other):
-            return 0
-    g = G()
-    orig_objects = len(gc.get_objects())
-    for i in range(10):
-        g==g
-    new_objects = len(gc.get_objects())
-    vereq(orig_objects, new_objects)
-    class H(object):
-        __slots__ = ['a', 'b']
-        def __init__(self):
-            self.a = 1
-            self.b = 2
-        def __del__(self):
-            assert self.a == 1
-            assert self.b == 2
-
-    save_stderr = sys.stderr
-    sys.stderr = sys.stdout
-    h = H()
-    try:
-        del h
-    finally:
-        sys.stderr = save_stderr
-
-def slotspecials():
-    if verbose: print("Testing __dict__ and __weakref__ in __slots__...")
-
-    class D(object):
-        __slots__ = ["__dict__"]
-    a = D()
-    verify(hasattr(a, "__dict__"))
-    verify(not hasattr(a, "__weakref__"))
-    a.foo = 42
-    vereq(a.__dict__, {"foo": 42})
-
-    class W(object):
-        __slots__ = ["__weakref__"]
-    a = W()
-    verify(hasattr(a, "__weakref__"))
-    verify(not hasattr(a, "__dict__"))
-    try:
-        a.foo = 42
-    except AttributeError:
-        pass
-    else:
-        raise TestFailed("shouldn't be allowed to set a.foo")
-
-    class C1(W, D):
-        __slots__ = []
-    a = C1()
-    verify(hasattr(a, "__dict__"))
-    verify(hasattr(a, "__weakref__"))
-    a.foo = 42
-    vereq(a.__dict__, {"foo": 42})
-
-    class C2(D, W):
-        __slots__ = []
-    a = C2()
-    verify(hasattr(a, "__dict__"))
-    verify(hasattr(a, "__weakref__"))
-    a.foo = 42
-    vereq(a.__dict__, {"foo": 42})
-
-# MRO order disagreement
-#
-#    class C3(C1, C2):
-#        __slots__ = []
-#
-#    class C4(C2, C1):
-#        __slots__ = []
-
-def dynamics():
-    if verbose: print("Testing class attribute propagation...")
-    class D(object):
-        pass
-    class E(D):
-        pass
-    class F(D):
-        pass
-    D.foo = 1
-    vereq(D.foo, 1)
-    # Test that dynamic attributes are inherited
-    vereq(E.foo, 1)
-    vereq(F.foo, 1)
-    # Test dynamic instances
-    class C(object):
-        pass
-    a = C()
-    verify(not hasattr(a, "foobar"))
-    C.foobar = 2
-    vereq(a.foobar, 2)
-    C.method = lambda self: 42
-    vereq(a.method(), 42)
-    C.__repr__ = lambda self: "C()"
-    vereq(repr(a), "C()")
-    C.__int__ = lambda self: 100
-    vereq(int(a), 100)
-    vereq(a.foobar, 2)
-    verify(not hasattr(a, "spam"))
-    def mygetattr(self, name):
-        if name == "spam":
-            return "spam"
-        raise AttributeError
-    C.__getattr__ = mygetattr
-    vereq(a.spam, "spam")
-    a.new = 12
-    vereq(a.new, 12)
-    def mysetattr(self, name, value):
-        if name == "spam":
-            raise AttributeError
-        return object.__setattr__(self, name, value)
-    C.__setattr__ = mysetattr
-    try:
-        a.spam = "not spam"
-    except AttributeError:
-        pass
-    else:
-        verify(0, "expected AttributeError")
-    vereq(a.spam, "spam")
-    class D(C):
-        pass
-    d = D()
-    d.foo = 1
-    vereq(d.foo, 1)
-
-    # Test handling of int*seq and seq*int
-    class I(int):
-        pass
-    vereq("a"*I(2), "aa")
-    vereq(I(2)*"a", "aa")
-    vereq(2*I(3), 6)
-    vereq(I(3)*2, 6)
-    vereq(I(3)*I(2), 6)
-
-    # Test handling of long*seq and seq*long
-    class L(int):
-        pass
-    vereq("a"*L(2), "aa")
-    vereq(L(2)*"a", "aa")
-    vereq(2*L(3), 6)
-    vereq(L(3)*2, 6)
-    vereq(L(3)*L(2), 6)
-
-    # Test comparison of classes with dynamic metaclasses
-    class dynamicmetaclass(type):
-        pass
-    class someclass(metaclass=dynamicmetaclass):
-        pass
-    verify(someclass != object)
-
-def errors():
-    if verbose: print("Testing errors...")
-
-    try:
-        class C(list, dict):
-            pass
-    except TypeError:
-        pass
-    else:
-        verify(0, "inheritance from both list and dict should be illegal")
-
-    try:
-        class C(object, None):
-            pass
-    except TypeError:
-        pass
-    else:
-        verify(0, "inheritance from non-type should be illegal")
-    class Classic:
-        pass
-
-    try:
-        class C(type(len)):
-            pass
-    except TypeError:
-        pass
-    else:
-        verify(0, "inheritance from CFunction should be illegal")
+            def __init__(self, foo=None):
+                self.foo = foo
+                self.__foo = foo
+            def setfoo(self, foo=None):
+                self.foo = foo
+            def getfoo(self):
+                return self.__foo
+            def __getstate__(self):
+                return [self.foo]
+            def __setstate__(self_, lst):
+                self.assertEqual(len(lst), 1)
+                self_.__foo = self_.foo = lst[0]
+        a = C(42)
+        a.setfoo(24)
+        self.assertEqual(a.foo, 24)
+        self.assertEqual(a.getfoo(), 42)
+        b = copy.copy(a)
+        self.assertEqual(b.foo, 24)
+        self.assertEqual(b.getfoo(), 24)
+        b = copy.deepcopy(a)
+        self.assertEqual(b.foo, 24)
+        self.assertEqual(b.getfoo(), 24)
+
+    def test_slices(self):
+        # Testing cases with slices and overridden __getitem__ ...
+
+        # Strings
+        self.assertEqual("hello"[:4], "hell")
+        self.assertEqual("hello"[slice(4)], "hell")
+        self.assertEqual(str.__getitem__("hello", slice(4)), "hell")
+        class S(str):
+            def __getitem__(self, x):
+                return str.__getitem__(self, x)
+        self.assertEqual(S("hello")[:4], "hell")
+        self.assertEqual(S("hello")[slice(4)], "hell")
+        self.assertEqual(S("hello").__getitem__(slice(4)), "hell")
+        # Tuples
+        self.assertEqual((1,2,3)[:2], (1,2))
+        self.assertEqual((1,2,3)[slice(2)], (1,2))
+        self.assertEqual(tuple.__getitem__((1,2,3), slice(2)), (1,2))
+        class T(tuple):
+            def __getitem__(self, x):
+                return tuple.__getitem__(self, x)
+        self.assertEqual(T((1,2,3))[:2], (1,2))
+        self.assertEqual(T((1,2,3))[slice(2)], (1,2))
+        self.assertEqual(T((1,2,3)).__getitem__(slice(2)), (1,2))
+        # Lists
+        self.assertEqual([1,2,3][:2], [1,2])
+        self.assertEqual([1,2,3][slice(2)], [1,2])
+        self.assertEqual(list.__getitem__([1,2,3], slice(2)), [1,2])
+        class L(list):
+            def __getitem__(self, x):
+                return list.__getitem__(self, x)
+        self.assertEqual(L([1,2,3])[:2], [1,2])
+        self.assertEqual(L([1,2,3])[slice(2)], [1,2])
+        self.assertEqual(L([1,2,3]).__getitem__(slice(2)), [1,2])
+        # Now do lists and __setitem__
+        a = L([1,2,3])
+        a[slice(1, 3)] = [3,2]
+        self.assertEqual(a, [1,3,2])
+        a[slice(0, 2, 1)] = [3,1]
+        self.assertEqual(a, [3,1,2])
+        a.__setitem__(slice(1, 3), [2,1])
+        self.assertEqual(a, [3,2,1])
+        a.__setitem__(slice(0, 2, 1), [2,3])
+        self.assertEqual(a, [2,3,1])
 
-    try:
-        class C(object):
-            __slots__ = 1
-    except TypeError:
-        pass
-    else:
-        verify(0, "__slots__ = 1 should be illegal")
+    def test_subtype_resurrection(self):
+        # Testing resurrection of new-style instance...
 
-    try:
         class C(object):
-            __slots__ = [1]
-    except TypeError:
-        pass
-    else:
-        verify(0, "__slots__ = [1] should be illegal")
-
-    class M1(type):
-        pass
-    class M2(type):
-        pass
-    class A1(object, metaclass=M1):
-        pass
-    class A2(object, metaclass=M2):
-        pass
-    try:
-        class B(A1, A2):
-            pass
-    except TypeError:
-        pass
-    else:
-        verify(0, "finding the most derived metaclass should have failed")
-
-def classmethods():
-    if verbose: print("Testing class methods...")
-    class C(object):
-        def foo(*a): return a
-        goo = classmethod(foo)
-    c = C()
-    vereq(C.goo(1), (C, 1))
-    vereq(c.goo(1), (C, 1))
-    vereq(c.foo(1), (c, 1))
-    class D(C):
-        pass
-    d = D()
-    vereq(D.goo(1), (D, 1))
-    vereq(d.goo(1), (D, 1))
-    vereq(d.foo(1), (d, 1))
-    vereq(D.foo(d, 1), (d, 1))
-    # Test for a specific crash (SF bug 528132)
-    def f(cls, arg): return (cls, arg)
-    ff = classmethod(f)
-    vereq(ff.__get__(0, int)(42), (int, 42))
-    vereq(ff.__get__(0)(42), (int, 42))
-
-    # Test super() with classmethods (SF bug 535444)
-    veris(C.goo.im_self, C)
-    veris(D.goo.im_self, D)
-    veris(super(D,D).goo.im_self, D)
-    veris(super(D,d).goo.im_self, D)
-    vereq(super(D,D).goo(), (D,))
-    vereq(super(D,d).goo(), (D,))
-
-    # Verify that argument is checked for callability (SF bug 753451)
-    try:
-        classmethod(1).__get__(1)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("classmethod should check for callability")
-
-    # Verify that classmethod() doesn't allow keyword args
-    try:
-        classmethod(f, kw=1)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("classmethod shouldn't accept keyword args")
-
-def classmethods_in_c():
-    if verbose: print("Testing C-based class methods...")
-    import xxsubtype as spam
-    a = (1, 2, 3)
-    d = {'abc': 123}
-    x, a1, d1 = spam.spamlist.classmeth(*a, **d)
-    veris(x, spam.spamlist)
-    vereq(a, a1)
-    vereq(d, d1)
-    x, a1, d1 = spam.spamlist().classmeth(*a, **d)
-    veris(x, spam.spamlist)
-    vereq(a, a1)
-    vereq(d, d1)
-
-def staticmethods():
-    if verbose: print("Testing static methods...")
-    class C(object):
-        def foo(*a): return a
-        goo = staticmethod(foo)
-    c = C()
-    vereq(C.goo(1), (1,))
-    vereq(c.goo(1), (1,))
-    vereq(c.foo(1), (c, 1,))
-    class D(C):
-        pass
-    d = D()
-    vereq(D.goo(1), (1,))
-    vereq(d.goo(1), (1,))
-    vereq(d.foo(1), (d, 1))
-    vereq(D.foo(d, 1), (d, 1))
-
-def staticmethods_in_c():
-    if verbose: print("Testing C-based static methods...")
-    import xxsubtype as spam
-    a = (1, 2, 3)
-    d = {"abc": 123}
-    x, a1, d1 = spam.spamlist.staticmeth(*a, **d)
-    veris(x, None)
-    vereq(a, a1)
-    vereq(d, d1)
-    x, a1, d2 = spam.spamlist().staticmeth(*a, **d)
-    veris(x, None)
-    vereq(a, a1)
-    vereq(d, d1)
-
-def classic():
-    if verbose: print("Testing classic classes...")
-    class C:
-        def foo(*a): return a
-        goo = classmethod(foo)
-    c = C()
-    vereq(C.goo(1), (C, 1))
-    vereq(c.goo(1), (C, 1))
-    vereq(c.foo(1), (c, 1))
-    class D(C):
-        pass
-    d = D()
-    vereq(D.goo(1), (D, 1))
-    vereq(d.goo(1), (D, 1))
-    vereq(d.foo(1), (d, 1))
-    vereq(D.foo(d, 1), (d, 1))
-    class E: # *not* subclassing from C
-        foo = C.foo
-    vereq(E().foo, C.foo) # i.e., unbound
-    verify(repr(C.foo.__get__(C())).startswith("<bound method "))
-
-def compattr():
-    if verbose: print("Testing computed attributes...")
-    class C(object):
-        class computed_attribute(object):
-            def __init__(self, get, set=None, delete=None):
-                self.__get = get
-                self.__set = set
-                self.__delete = delete
-            def __get__(self, obj, type=None):
-                return self.__get(obj)
-            def __set__(self, obj, value):
-                return self.__set(obj, value)
-            def __delete__(self, obj):
-                return self.__delete(obj)
-        def __init__(self):
-            self.__x = 0
-        def __get_x(self):
-            x = self.__x
-            self.__x = x+1
-            return x
-        def __set_x(self, x):
-            self.__x = x
-        def __delete_x(self):
-            del self.__x
-        x = computed_attribute(__get_x, __set_x, __delete_x)
-    a = C()
-    vereq(a.x, 0)
-    vereq(a.x, 1)
-    a.x = 10
-    vereq(a.x, 10)
-    vereq(a.x, 11)
-    del a.x
-    vereq(hasattr(a, 'x'), 0)
-
-def newslot():
-    if verbose: print("Testing __new__ slot override...")
-    class C(list):
-        def __new__(cls):
-            self = list.__new__(cls)
-            self.foo = 1
-            return self
-        def __init__(self):
-            self.foo = self.foo + 2
-    a = C()
-    vereq(a.foo, 3)
-    verify(a.__class__ is C)
-    class D(C):
-        pass
-    b = D()
-    vereq(b.foo, 3)
-    verify(b.__class__ is D)
-
-def altmro():
-    if verbose: print("Testing mro() and overriding it...")
-    class A(object):
-        def f(self): return "A"
-    class B(A):
-        pass
-    class C(A):
-        def f(self): return "C"
-    class D(B, C):
-        pass
-    vereq(D.mro(), [D, B, C, A, object])
-    vereq(D.__mro__, (D, B, C, A, object))
-    vereq(D().f(), "C")
-
-    class PerverseMetaType(type):
-        def mro(cls):
-            L = type.mro(cls)
-            L.reverse()
-            return L
-    class X(D,B,C,A, metaclass=PerverseMetaType):
-        pass
-    vereq(X.__mro__, (object, A, C, B, D, X))
-    vereq(X().f(), "A")
+            container = []
 
-    try:
-        class _metaclass(type):
-            def mro(self):
-                return [self, dict, object]
-        class X(object, metaclass=_metaclass):
+            def __del__(self):
+                # resurrect the instance
+                C.container.append(self)
+
+        c = C()
+        c.attr = 42
+
+        # The most interesting thing here is whether this blows up, due to flawed
+        # GC tracking logic in typeobject.c's call_finalizer() (a 2.2.1 bug).
+        del c
+
+        # If that didn't blow up, it's also interesting to see whether clearing
+        # the last container slot works:  that will attempt to delete c again,
+        # which will cause c to get appended back to the container again "during"
+        # the del.
+        del C.container[-1]
+        self.assertEqual(len(C.container), 1)
+        self.assertEqual(C.container[-1].attr, 42)
+
+        # Make c mortal again, so that the test framework with -l doesn't report
+        # it as a leak.
+        del C.__del__
+
+    def test_slots_trash(self):
+        # Testing slot trash...
+        # Deallocating deeply nested slotted trash caused stack overflows
+        class trash(object):
+            __slots__ = ['x']
+            def __init__(self, x):
+                self.x = x
+        o = None
+        for i in range(50000):
+            o = trash(o)
+        del o
+
+    def test_slots_multiple_inheritance(self):
+        # SF bug 575229, multiple inheritance w/ slots dumps core
+        class A(object):
+            __slots__=()
+        class B(object):
             pass
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("devious mro() return not caught")
+        class C(A,B) :
+            __slots__=()
+        self.assertEqual(C.__basicsize__, B.__basicsize__)
+        self.assert_(hasattr(C, '__dict__'))
+        self.assert_(hasattr(C, '__weakref__'))
+        C().x = 2
+
+    def test_rmul(self):
+        # Testing correct invocation of __rmul__...
+        # SF patch 592646
+        class C(object):
+            def __mul__(self, other):
+                return "mul"
+            def __rmul__(self, other):
+                return "rmul"
+        a = C()
+        self.assertEqual(a*2, "mul")
+        self.assertEqual(a*2.2, "mul")
+        self.assertEqual(2*a, "rmul")
+        self.assertEqual(2.2*a, "rmul")
+
+    def test_ipow(self):
+        # Testing correct invocation of __ipow__...
+        # [SF bug 620179]
+        class C(object):
+            def __ipow__(self, other):
+                pass
+        a = C()
+        a **= 2
 
-    try:
-        class _metaclass(type):
-            def mro(self):
-                return [1]
-        class X(object, metaclass=_metaclass):
-            pass
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("non-class mro() return not caught")
+    def test_mutable_bases(self):
+        # Testing mutable bases...
 
-    try:
-        class _metaclass(type):
-            def mro(self):
+        # stuff that should work:
+        class C(object):
+            pass
+        class C2(object):
+            def __getattribute__(self, attr):
+                if attr == 'a':
+                    return 2
+                else:
+                    return super(C2, self).__getattribute__(attr)
+            def meth(self):
                 return 1
-        class X(object, metaclass=_metaclass):
+        class D(C):
+            pass
+        class E(D):
             pass
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("non-sequence mro() return not caught")
+        d = D()
+        e = E()
+        D.__bases__ = (C,)
+        D.__bases__ = (C2,)
+        self.assertEqual(d.meth(), 1)
+        self.assertEqual(e.meth(), 1)
+        self.assertEqual(d.a, 2)
+        self.assertEqual(e.a, 2)
+        self.assertEqual(C2.__subclasses__(), [D])
 
+        # stuff that shouldn't:
+        class L(list):
+            pass
 
-def overloading():
-    if verbose: print("Testing operator overloading...")
+        try:
+            L.__bases__ = (dict,)
+        except TypeError:
+            pass
+        else:
+            self.fail("shouldn't turn list subclass into dict subclass")
 
-    class B(object):
-        "Intermediate class because object doesn't have a __setattr__"
+        try:
+            list.__bases__ = (dict,)
+        except TypeError:
+            pass
+        else:
+            self.fail("shouldn't be able to assign to list.__bases__")
 
-    class C(B):
+        try:
+            D.__bases__ = (C2, list)
+        except TypeError:
+            pass
+        else:
+            assert 0, "best_base calculation found wanting"
 
-        def __getattr__(self, name):
-            if name == "foo":
-                return ("getattr", name)
-            else:
-                raise AttributeError
-        def __setattr__(self, name, value):
-            if name == "foo":
-                self.setattr = (name, value)
-            else:
-                return B.__setattr__(self, name, value)
-        def __delattr__(self, name):
-            if name == "foo":
-                self.delattr = name
-            else:
-                return B.__delattr__(self, name)
+        try:
+            del D.__bases__
+        except TypeError:
+            pass
+        else:
+            self.fail("shouldn't be able to delete .__bases__")
 
-        def __getitem__(self, key):
-            return ("getitem", key)
-        def __setitem__(self, key, value):
-            self.setitem = (key, value)
-        def __delitem__(self, key):
-            self.delitem = key
-
-    a = C()
-    vereq(a.foo, ("getattr", "foo"))
-    a.foo = 12
-    vereq(a.setattr, ("foo", 12))
-    del a.foo
-    vereq(a.delattr, "foo")
-
-    vereq(a[12], ("getitem", 12))
-    a[12] = 21
-    vereq(a.setitem, (12, 21))
-    del a[12]
-    vereq(a.delitem, 12)
-
-    vereq(a[0:10], ("getitem", slice(0, 10)))
-    a[0:10] = "foo"
-    vereq(a.setitem, (slice(0, 10), "foo"))
-    del a[0:10]
-    vereq(a.delitem, slice(0, 10))
-
-def methods():
-    if verbose: print("Testing methods...")
-    class C(object):
-        def __init__(self, x):
-            self.x = x
-        def foo(self):
-            return self.x
-    c1 = C(1)
-    vereq(c1.foo(), 1)
-    class D(C):
-        boo = C.foo
-        goo = c1.foo
-    d2 = D(2)
-    vereq(d2.foo(), 2)
-    vereq(d2.boo(), 2)
-    vereq(d2.goo(), 1)
-    class E(object):
-        foo = C.foo
-    vereq(E().foo, C.foo) # i.e., unbound
-    verify(repr(C.foo.__get__(C(1))).startswith("<bound method "))
-
-def specials():
-    # Test operators like __hash__ for which a built-in default exists
-    if verbose: print("Testing special operators...")
-    # Test the default behavior for static classes
-    class C(object):
-        def __getitem__(self, i):
-            if 0 <= i < 10: return i
-            raise IndexError
-    c1 = C()
-    c2 = C()
-    verify(not not c1)
-    verify(id(c1) != id(c2))
-    hash(c1)
-    hash(c2)
-    ##vereq(cmp(c1, c2), cmp(id(c1), id(c2)))
-    vereq(c1, c1)
-    verify(c1 != c2)
-    verify(not c1 != c1)
-    verify(not c1 == c2)
-    # Note that the module name appears in str/repr, and that varies
-    # depending on whether this test is run standalone or from a framework.
-    verify(str(c1).find('C object at ') >= 0)
-    vereq(str(c1), repr(c1))
-    verify(-1 not in c1)
-    for i in range(10):
-        verify(i in c1)
-    verify(10 not in c1)
-    # Test the default behavior for dynamic classes
-    class D(object):
-        def __getitem__(self, i):
-            if 0 <= i < 10: return i
-            raise IndexError
-    d1 = D()
-    d2 = D()
-    verify(not not d1)
-    verify(id(d1) != id(d2))
-    hash(d1)
-    hash(d2)
-    ##vereq(cmp(d1, d2), cmp(id(d1), id(d2)))
-    vereq(d1, d1)
-    verify(d1 != d2)
-    verify(not d1 != d1)
-    verify(not d1 == d2)
-    # Note that the module name appears in str/repr, and that varies
-    # depending on whether this test is run standalone or from a framework.
-    verify(str(d1).find('D object at ') >= 0)
-    vereq(str(d1), repr(d1))
-    verify(-1 not in d1)
-    for i in range(10):
-        verify(i in d1)
-    verify(10 not in d1)
-    # Test overridden behavior for static classes
-    class Proxy(object):
-        def __init__(self, x):
-            self.x = x
-        def __bool__(self):
-            return not not self.x
-        def __hash__(self):
-            return hash(self.x)
-        def __eq__(self, other):
-            return self.x == other
-        def __ne__(self, other):
-            return self.x != other
-        def __cmp__(self, other):
-            return cmp(self.x, other.x)
-        def __str__(self):
-            return "Proxy:%s" % self.x
-        def __repr__(self):
-            return "Proxy(%r)" % self.x
-        def __contains__(self, value):
-            return value in self.x
-    p0 = Proxy(0)
-    p1 = Proxy(1)
-    p_1 = Proxy(-1)
-    verify(not p0)
-    verify(not not p1)
-    vereq(hash(p0), hash(0))
-    vereq(p0, p0)
-    verify(p0 != p1)
-    verify(not p0 != p0)
-    vereq(not p0, p1)
-    vereq(cmp(p0, p1), -1)
-    vereq(cmp(p0, p0), 0)
-    vereq(cmp(p0, p_1), 1)
-    vereq(str(p0), "Proxy:0")
-    vereq(repr(p0), "Proxy(0)")
-    p10 = Proxy(range(10))
-    verify(-1 not in p10)
-    for i in range(10):
-        verify(i in p10)
-    verify(10 not in p10)
-    # Test overridden behavior for dynamic classes
-    class DProxy(object):
-        def __init__(self, x):
-            self.x = x
-        def __bool__(self):
-            return not not self.x
-        def __hash__(self):
-            return hash(self.x)
-        def __eq__(self, other):
-            return self.x == other
-        def __ne__(self, other):
-            return self.x != other
-        def __cmp__(self, other):
-            return cmp(self.x, other.x)
-        def __str__(self):
-            return "DProxy:%s" % self.x
-        def __repr__(self):
-            return "DProxy(%r)" % self.x
-        def __contains__(self, value):
-            return value in self.x
-    p0 = DProxy(0)
-    p1 = DProxy(1)
-    p_1 = DProxy(-1)
-    verify(not p0)
-    verify(not not p1)
-    vereq(hash(p0), hash(0))
-    vereq(p0, p0)
-    verify(p0 != p1)
-    verify(not p0 != p0)
-    vereq(not p0, p1)
-    vereq(cmp(p0, p1), -1)
-    vereq(cmp(p0, p0), 0)
-    vereq(cmp(p0, p_1), 1)
-    vereq(str(p0), "DProxy:0")
-    vereq(repr(p0), "DProxy(0)")
-    p10 = DProxy(range(10))
-    verify(-1 not in p10)
-    for i in range(10):
-        verify(i in p10)
-    verify(10 not in p10)
-##     # Safety test for __cmp__
-##     def unsafecmp(a, b):
-##         try:
-##             a.__class__.__cmp__(a, b)
-##         except TypeError:
-##             pass
-##         else:
-##             raise TestFailed, "shouldn't allow %s.__cmp__(%r, %r)" % (
-##                 a.__class__, a, b)
-##     unsafecmp(u"123", "123")
-##     unsafecmp("123", u"123")
-##     unsafecmp(1, 1.0)
-##     unsafecmp(1.0, 1)
-##     unsafecmp(1, 1L)
-##     unsafecmp(1L, 1)
-
-def recursions():
-    if verbose:
-        print("Testing recursion checks ...")
-
-##     class Letter(str):
-##         def __new__(cls, letter):
-##             if letter == 'EPS':
-##                 return str.__new__(cls)
-##             return str.__new__(cls, letter)
-##         def __str__(self):
-##             if not self:
-##                 return 'EPS'
-##             return self
-##     # sys.stdout needs to be the original to trigger the recursion bug
-##     import sys
-##     test_stdout = sys.stdout
-##     sys.stdout = get_original_stdout()
-##     try:
-##         # nothing should actually be printed, this should raise an exception
-##         print(Letter('w'))
-##     except RuntimeError:
-##         pass
-##     else:
-##         raise TestFailed, "expected a RuntimeError for print recursion"
-##     sys.stdout = test_stdout
-
-    # Bug #1202533.
-    class A(object):
-        pass
-    A.__mul__ = new.instancemethod(lambda self, x: self * x, None, A)
-    try:
-        A()*2
-    except RuntimeError:
-        pass
-    else:
-        raise TestFailed("expected a RuntimeError")
-
-def weakrefs():
-    if verbose: print("Testing weak references...")
-    import weakref
-    class C(object):
-        pass
-    c = C()
-    r = weakref.ref(c)
-    verify(r() is c)
-    del c
-    verify(r() is None)
-    del r
-    class NoWeak(object):
-        __slots__ = ['foo']
-    no = NoWeak()
-    try:
-        weakref.ref(no)
-    except TypeError as msg:
-        verify(str(msg).find("weak reference") >= 0)
-    else:
-        verify(0, "weakref.ref(no) should be illegal")
-    class Weak(object):
-        __slots__ = ['foo', '__weakref__']
-    yes = Weak()
-    r = weakref.ref(yes)
-    verify(r() is yes)
-    del yes
-    verify(r() is None)
-    del r
-
-def properties():
-    if verbose: print("Testing property...")
-    class C(object):
-        def getx(self):
-            return self.__x
-        def setx(self, value):
-            self.__x = value
-        def delx(self):
-            del self.__x
-        x = property(getx, setx, delx, doc="I'm the x property.")
-    a = C()
-    verify(not hasattr(a, "x"))
-    a.x = 42
-    vereq(a._C__x, 42)
-    vereq(a.x, 42)
-    del a.x
-    verify(not hasattr(a, "x"))
-    verify(not hasattr(a, "_C__x"))
-    C.x.__set__(a, 100)
-    vereq(C.x.__get__(a), 100)
-    C.x.__delete__(a)
-    verify(not hasattr(a, "x"))
-
-    raw = C.__dict__['x']
-    verify(isinstance(raw, property))
-
-    attrs = dir(raw)
-    verify("__doc__" in attrs)
-    verify("fget" in attrs)
-    verify("fset" in attrs)
-    verify("fdel" in attrs)
-
-    vereq(raw.__doc__, "I'm the x property.")
-    verify(raw.fget is C.__dict__['getx'])
-    verify(raw.fset is C.__dict__['setx'])
-    verify(raw.fdel is C.__dict__['delx'])
-
-    for attr in "__doc__", "fget", "fset", "fdel":
-        try:
-            setattr(raw, attr, 42)
-        except AttributeError as msg:
-            if str(msg).find('readonly') < 0:
-                raise TestFailed("when setting readonly attr %r on a "
-                                 "property, got unexpected AttributeError "
-                                 "msg %r" % (attr, str(msg)))
-        else:
-            raise TestFailed("expected AttributeError from trying to set "
-                             "readonly %r attr on a property" % attr)
-
-    class D(object):
-        __getitem__ = property(lambda s: 1/0)
-
-    d = D()
-    try:
-        for i in d:
-            str(i)
-    except ZeroDivisionError:
-        pass
-    else:
-        raise TestFailed("expected ZeroDivisionError from bad property")
-
-    class E(object):
-        def getter(self):
-            "getter method"
-            return 0
-        def setter(self, value):
-            "setter method"
-            pass
-        prop = property(getter)
-        vereq(prop.__doc__, "getter method")
-        prop2 = property(fset=setter)
-        vereq(prop2.__doc__, None)
-
-    # this segfaulted in 2.5b2
-    try:
-        import _testcapi
-    except ImportError:
-        pass
-    else:
-        class X(object):
-            p = property(_testcapi.test_with_docstring)
-
-
-def supers():
-    if verbose: print("Testing super...")
-
-    class A(object):
-        def meth(self, a):
-            return "A(%r)" % a
-
-    vereq(A().meth(1), "A(1)")
-
-    class B(A):
-        def __init__(self):
-            self.__super = super(B, self)
-        def meth(self, a):
-            return "B(%r)" % a + self.__super.meth(a)
-
-    vereq(B().meth(2), "B(2)A(2)")
-
-    class C(A):
-        def meth(self, a):
-            return "C(%r)" % a + self.__super.meth(a)
-    C._C__super = super(C)
-
-    vereq(C().meth(3), "C(3)A(3)")
-
-    class D(C, B):
-        def meth(self, a):
-            return "D(%r)" % a + super(D, self).meth(a)
-
-    vereq(D().meth(4), "D(4)C(4)B(4)A(4)")
-
-    # Test for subclassing super
-
-    class mysuper(super):
-        def __init__(self, *args):
-            return super(mysuper, self).__init__(*args)
-
-    class E(D):
-        def meth(self, a):
-            return "E(%r)" % a + mysuper(E, self).meth(a)
-
-    vereq(E().meth(5), "E(5)D(5)C(5)B(5)A(5)")
-
-    class F(E):
-        def meth(self, a):
-            s = self.__super # == mysuper(F, self)
-            return "F(%r)[%s]" % (a, s.__class__.__name__) + s.meth(a)
-    F._F__super = mysuper(F)
-
-    vereq(F().meth(6), "F(6)[mysuper]E(6)D(6)C(6)B(6)A(6)")
-
-    # Make sure certain errors are raised
-
-    try:
-        super(D, 42)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't allow super(D, 42)")
-
-    try:
-        super(D, C())
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't allow super(D, C())")
-
-    try:
-        super(D).__get__(12)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't allow super(D).__get__(12)")
-
-    try:
-        super(D).__get__(C())
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't allow super(D).__get__(C())")
-
-    # Make sure data descriptors can be overridden and accessed via super
-    # (new feature in Python 2.3)
-
-    class DDbase(object):
-        def getx(self): return 42
-        x = property(getx)
-
-    class DDsub(DDbase):
-        def getx(self): return "hello"
-        x = property(getx)
-
-    dd = DDsub()
-    vereq(dd.x, "hello")
-    vereq(super(DDsub, dd).x, 42)
-
-    # Ensure that super() lookup of descriptor from classmethod
-    # works (SF ID# 743627)
-
-    class Base(object):
-        aProp = property(lambda self: "foo")
-
-    class Sub(Base):
-        @classmethod
-        def test(klass):
-            return super(Sub,klass).aProp
-
-    veris(Sub.test(), Base.aProp)
-
-    # Verify that super() doesn't allow keyword args
-    try:
-        super(Base, kw=1)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("super shouldn't accept keyword args")
-
-def inherits():
-    if verbose: print("Testing inheritance from basic types...")
-
-    class hexint(int):
-        def __repr__(self):
-            return hex(self)
-        def __add__(self, other):
-            return hexint(int.__add__(self, other))
-        # (Note that overriding __radd__ doesn't work,
-        # because the int type gets first dibs.)
-    vereq(repr(hexint(7) + 9), "0x10")
-    vereq(repr(hexint(1000) + 7), "0x3ef")
-    a = hexint(12345)
-    vereq(a, 12345)
-    vereq(int(a), 12345)
-    verify(int(a).__class__ is int)
-    vereq(hash(a), hash(12345))
-    verify((+a).__class__ is int)
-    verify((a >> 0).__class__ is int)
-    verify((a << 0).__class__ is int)
-    verify((hexint(0) << 12).__class__ is int)
-    verify((hexint(0) >> 12).__class__ is int)
-
-    class octlong(int):
-        __slots__ = []
-        def __str__(self):
-            return oct(self)
-        def __add__(self, other):
-            return self.__class__(super(octlong, self).__add__(other))
-        __radd__ = __add__
-    vereq(str(octlong(3) + 5), "0o10")
-    # (Note that overriding __radd__ here only seems to work
-    # because the example uses a short int left argument.)
-    vereq(str(5 + octlong(3000)), "0o5675")
-    a = octlong(12345)
-    vereq(a, 12345)
-    vereq(int(a), 12345)
-    vereq(hash(a), hash(12345))
-    verify(int(a).__class__ is int)
-    verify((+a).__class__ is int)
-    verify((-a).__class__ is int)
-    verify((-octlong(0)).__class__ is int)
-    verify((a >> 0).__class__ is int)
-    verify((a << 0).__class__ is int)
-    verify((a - 0).__class__ is int)
-    verify((a * 1).__class__ is int)
-    verify((a ** 1).__class__ is int)
-    verify((a // 1).__class__ is int)
-    verify((1 * a).__class__ is int)
-    verify((a | 0).__class__ is int)
-    verify((a ^ 0).__class__ is int)
-    verify((a & -1).__class__ is int)
-    verify((octlong(0) << 12).__class__ is int)
-    verify((octlong(0) >> 12).__class__ is int)
-    verify(abs(octlong(0)).__class__ is int)
-
-    # Because octlong overrides __add__, we can't check the absence of +0
-    # optimizations using octlong.
-    class longclone(int):
-        pass
-    a = longclone(1)
-    verify((a + 0).__class__ is int)
-    verify((0 + a).__class__ is int)
-
-    # Check that negative clones don't segfault
-    a = longclone(-1)
-    vereq(a.__dict__, {})
-    vereq(int(a), -1)  # verify PyNumber_Long() copies the sign bit
-
-    class precfloat(float):
-        __slots__ = ['prec']
-        def __init__(self, value=0.0, prec=12):
-            self.prec = int(prec)
-        def __repr__(self):
-            return "%.*g" % (self.prec, self)
-    vereq(repr(precfloat(1.1)), "1.1")
-    a = precfloat(12345)
-    vereq(a, 12345.0)
-    vereq(float(a), 12345.0)
-    verify(float(a).__class__ is float)
-    vereq(hash(a), hash(12345.0))
-    verify((+a).__class__ is float)
-
-    class madcomplex(complex):
-        def __repr__(self):
-            return "%.17gj%+.17g" % (self.imag, self.real)
-    a = madcomplex(-3, 4)
-    vereq(repr(a), "4j-3")
-    base = complex(-3, 4)
-    veris(base.__class__, complex)
-    vereq(a, base)
-    vereq(complex(a), base)
-    veris(complex(a).__class__, complex)
-    a = madcomplex(a)  # just trying another form of the constructor
-    vereq(repr(a), "4j-3")
-    vereq(a, base)
-    vereq(complex(a), base)
-    veris(complex(a).__class__, complex)
-    vereq(hash(a), hash(base))
-    veris((+a).__class__, complex)
-    veris((a + 0).__class__, complex)
-    vereq(a + 0, base)
-    veris((a - 0).__class__, complex)
-    vereq(a - 0, base)
-    veris((a * 1).__class__, complex)
-    vereq(a * 1, base)
-    veris((a / 1).__class__, complex)
-    vereq(a / 1, base)
-
-    class madtuple(tuple):
-        _rev = None
-        def rev(self):
-            if self._rev is not None:
-                return self._rev
-            L = list(self)
-            L.reverse()
-            self._rev = self.__class__(L)
-            return self._rev
-    a = madtuple((1,2,3,4,5,6,7,8,9,0))
-    vereq(a, (1,2,3,4,5,6,7,8,9,0))
-    vereq(a.rev(), madtuple((0,9,8,7,6,5,4,3,2,1)))
-    vereq(a.rev().rev(), madtuple((1,2,3,4,5,6,7,8,9,0)))
-    for i in range(512):
-        t = madtuple(range(i))
-        u = t.rev()
-        v = u.rev()
-        vereq(v, t)
-    a = madtuple((1,2,3,4,5))
-    vereq(tuple(a), (1,2,3,4,5))
-    verify(tuple(a).__class__ is tuple)
-    vereq(hash(a), hash((1,2,3,4,5)))
-    verify(a[:].__class__ is tuple)
-    verify((a * 1).__class__ is tuple)
-    verify((a * 0).__class__ is tuple)
-    verify((a + ()).__class__ is tuple)
-    a = madtuple(())
-    vereq(tuple(a), ())
-    verify(tuple(a).__class__ is tuple)
-    verify((a + a).__class__ is tuple)
-    verify((a * 0).__class__ is tuple)
-    verify((a * 1).__class__ is tuple)
-    verify((a * 2).__class__ is tuple)
-    verify(a[:].__class__ is tuple)
-
-    class madstring(str):
-        _rev = None
-        def rev(self):
-            if self._rev is not None:
-                return self._rev
-            L = list(self)
-            L.reverse()
-            self._rev = self.__class__("".join(L))
-            return self._rev
-    s = madstring("abcdefghijklmnopqrstuvwxyz")
-    vereq(s, "abcdefghijklmnopqrstuvwxyz")
-    vereq(s.rev(), madstring("zyxwvutsrqponmlkjihgfedcba"))
-    vereq(s.rev().rev(), madstring("abcdefghijklmnopqrstuvwxyz"))
-    for i in range(256):
-        s = madstring("".join(map(chr, range(i))))
-        t = s.rev()
-        u = t.rev()
-        vereq(u, s)
-    s = madstring("12345")
-    vereq(str(s), "12345")
-    verify(str(s).__class__ is str)
-
-    base = "\x00" * 5
-    s = madstring(base)
-    vereq(s, base)
-    vereq(str(s), base)
-    verify(str(s).__class__ is str)
-    vereq(hash(s), hash(base))
-    vereq({s: 1}[base], 1)
-    vereq({base: 1}[s], 1)
-    verify((s + "").__class__ is str)
-    vereq(s + "", base)
-    verify(("" + s).__class__ is str)
-    vereq("" + s, base)
-    verify((s * 0).__class__ is str)
-    vereq(s * 0, "")
-    verify((s * 1).__class__ is str)
-    vereq(s * 1, base)
-    verify((s * 2).__class__ is str)
-    vereq(s * 2, base + base)
-    verify(s[:].__class__ is str)
-    vereq(s[:], base)
-    verify(s[0:0].__class__ is str)
-    vereq(s[0:0], "")
-    verify(s.strip().__class__ is str)
-    vereq(s.strip(), base)
-    verify(s.lstrip().__class__ is str)
-    vereq(s.lstrip(), base)
-    verify(s.rstrip().__class__ is str)
-    vereq(s.rstrip(), base)
-    identitytab = {}
-    verify(s.translate(identitytab).__class__ is str)
-    vereq(s.translate(identitytab), base)
-    verify(s.replace("x", "x").__class__ is str)
-    vereq(s.replace("x", "x"), base)
-    verify(s.ljust(len(s)).__class__ is str)
-    vereq(s.ljust(len(s)), base)
-    verify(s.rjust(len(s)).__class__ is str)
-    vereq(s.rjust(len(s)), base)
-    verify(s.center(len(s)).__class__ is str)
-    vereq(s.center(len(s)), base)
-    verify(s.lower().__class__ is str)
-    vereq(s.lower(), base)
-
-    class madunicode(str):
-        _rev = None
-        def rev(self):
-            if self._rev is not None:
-                return self._rev
-            L = list(self)
-            L.reverse()
-            self._rev = self.__class__("".join(L))
-            return self._rev
-    u = madunicode("ABCDEF")
-    vereq(u, "ABCDEF")
-    vereq(u.rev(), madunicode("FEDCBA"))
-    vereq(u.rev().rev(), madunicode("ABCDEF"))
-    base = "12345"
-    u = madunicode(base)
-    vereq(str(u), base)
-    verify(str(u).__class__ is str)
-    vereq(hash(u), hash(base))
-    vereq({u: 1}[base], 1)
-    vereq({base: 1}[u], 1)
-    verify(u.strip().__class__ is str)
-    vereq(u.strip(), base)
-    verify(u.lstrip().__class__ is str)
-    vereq(u.lstrip(), base)
-    verify(u.rstrip().__class__ is str)
-    vereq(u.rstrip(), base)
-    verify(u.replace("x", "x").__class__ is str)
-    vereq(u.replace("x", "x"), base)
-    verify(u.replace("xy", "xy").__class__ is str)
-    vereq(u.replace("xy", "xy"), base)
-    verify(u.center(len(u)).__class__ is str)
-    vereq(u.center(len(u)), base)
-    verify(u.ljust(len(u)).__class__ is str)
-    vereq(u.ljust(len(u)), base)
-    verify(u.rjust(len(u)).__class__ is str)
-    vereq(u.rjust(len(u)), base)
-    verify(u.lower().__class__ is str)
-    vereq(u.lower(), base)
-    verify(u.upper().__class__ is str)
-    vereq(u.upper(), base)
-    verify(u.capitalize().__class__ is str)
-    vereq(u.capitalize(), base)
-    verify(u.title().__class__ is str)
-    vereq(u.title(), base)
-    verify((u + "").__class__ is str)
-    vereq(u + "", base)
-    verify(("" + u).__class__ is str)
-    vereq("" + u, base)
-    verify((u * 0).__class__ is str)
-    vereq(u * 0, "")
-    verify((u * 1).__class__ is str)
-    vereq(u * 1, base)
-    verify((u * 2).__class__ is str)
-    vereq(u * 2, base + base)
-    verify(u[:].__class__ is str)
-    vereq(u[:], base)
-    verify(u[0:0].__class__ is str)
-    vereq(u[0:0], "")
-
-    class sublist(list):
-        pass
-    a = sublist(range(5))
-    vereq(a, list(range(5)))
-    a.append("hello")
-    vereq(a, list(range(5)) + ["hello"])
-    a[5] = 5
-    vereq(a, list(range(6)))
-    a.extend(range(6, 20))
-    vereq(a, list(range(20)))
-    a[-5:] = []
-    vereq(a, list(range(15)))
-    del a[10:15]
-    vereq(len(a), 10)
-    vereq(a, list(range(10)))
-    vereq(list(a), list(range(10)))
-    vereq(a[0], 0)
-    vereq(a[9], 9)
-    vereq(a[-10], 0)
-    vereq(a[-1], 9)
-    vereq(a[:5], list(range(5)))
-
-##     class CountedInput(file):
-##         """Counts lines read by self.readline().
-
-##         self.lineno is the 0-based ordinal of the last line read, up to
-##         a maximum of one greater than the number of lines in the file.
-
-##         self.ateof is true if and only if the final "" line has been read,
-##         at which point self.lineno stops incrementing, and further calls
-##         to readline() continue to return "".
-##         """
-
-##         lineno = 0
-##         ateof = 0
-##         def readline(self):
-##             if self.ateof:
-##                 return ""
-##             s = file.readline(self)
-##             # Next line works too.
-##             # s = super(CountedInput, self).readline()
-##             self.lineno += 1
-##             if s == "":
-##                 self.ateof = 1
-##             return s
-
-##     f = open(name=TESTFN, mode='w')
-##     lines = ['a\n', 'b\n', 'c\n']
-##     try:
-##         f.writelines(lines)
-##         f.close()
-##         f = CountedInput(TESTFN)
-##         for (i, expected) in zip(list(range(1, 5)) + [4], lines + 2 * [""]):
-##             got = f.readline()
-##             vereq(expected, got)
-##             vereq(f.lineno, i)
-##             vereq(f.ateof, (i > len(lines)))
-##         f.close()
-##     finally:
-##         try:
-##             f.close()
-##         except:
-##             pass
-##         try:
-##             import os
-##             os.unlink(TESTFN)
-##         except:
-##             pass
-
-def keywords():
-    if verbose:
-        print("Testing keyword args to basic type constructors ...")
-    vereq(int(x=1), 1)
-    vereq(float(x=2), 2.0)
-    vereq(int(x=3), 3)
-    vereq(complex(imag=42, real=666), complex(666, 42))
-    vereq(str(object=500), '500')
-    vereq(str(object=b'abc', errors='strict'), 'abc')
-    vereq(tuple(sequence=range(3)), (0, 1, 2))
-    vereq(list(sequence=(0, 1, 2)), list(range(3)))
-    # note: as of Python 2.3, dict() no longer has an "items" keyword arg
-
-    for constructor in (int, float, int, complex, str, str, tuple, list):
-        try:
-            constructor(bogus_keyword_arg=1)
-        except TypeError:
-            pass
-        else:
-            raise TestFailed("expected TypeError from bogus keyword "
-                             "argument to %r" % constructor)
-
-def str_subclass_as_dict_key():
-    if verbose:
-        print("Testing a str subclass used as dict key ..")
-
-    class cistr(str):
-        """Sublcass of str that computes __eq__ case-insensitively.
-
-        Also computes a hash code of the string in canonical form.
-        """
-
-        def __init__(self, value):
-            self.canonical = value.lower()
-            self.hashcode = hash(self.canonical)
-
-        def __eq__(self, other):
-            if not isinstance(other, cistr):
-                other = cistr(other)
-            return self.canonical == other.canonical
-
-        def __hash__(self):
-            return self.hashcode
-
-    vereq(cistr('ABC'), 'abc')
-    vereq('aBc', cistr('ABC'))
-    vereq(str(cistr('ABC')), 'ABC')
-
-    d = {cistr('one'): 1, cistr('two'): 2, cistr('tHree'): 3}
-    vereq(d[cistr('one')], 1)
-    vereq(d[cistr('tWo')], 2)
-    vereq(d[cistr('THrEE')], 3)
-    verify(cistr('ONe') in d)
-    vereq(d.get(cistr('thrEE')), 3)
-
-def classic_comparisons():
-    if verbose: print("Testing classic comparisons...")
-    class classic:
-        pass
-    for base in (classic, int, object):
-        if verbose: print("        (base = %s)" % base)
-        class C(base):
-            def __init__(self, value):
-                self.value = int(value)
-            def __eq__(self, other):
-                if isinstance(other, C):
-                    return self.value == other.value
-                if isinstance(other, int) or isinstance(other, int):
-                    return self.value == other
-                return NotImplemented
-            def __ne__(self, other):
-                if isinstance(other, C):
-                    return self.value != other.value
-                if isinstance(other, int) or isinstance(other, int):
-                    return self.value != other
-                return NotImplemented
-            def __lt__(self, other):
-                if isinstance(other, C):
-                    return self.value < other.value
-                if isinstance(other, int) or isinstance(other, int):
-                    return self.value < other
-                return NotImplemented
-            def __le__(self, other):
-                if isinstance(other, C):
-                    return self.value <= other.value
-                if isinstance(other, int) or isinstance(other, int):
-                    return self.value <= other
-                return NotImplemented
-            def __gt__(self, other):
-                if isinstance(other, C):
-                    return self.value > other.value
-                if isinstance(other, int) or isinstance(other, int):
-                    return self.value > other
-                return NotImplemented
-            def __ge__(self, other):
-                if isinstance(other, C):
-                    return self.value >= other.value
-                if isinstance(other, int) or isinstance(other, int):
-                    return self.value >= other
-                return NotImplemented
+        try:
+            D.__bases__ = ()
+        except TypeError as msg:
+            if str(msg) == "a new-style class can't have only classic bases":
+                self.fail("wrong error message for .__bases__ = ()")
+        else:
+            self.fail("shouldn't be able to set .__bases__ to ()")
 
-        c1 = C(1)
-        c2 = C(2)
-        c3 = C(3)
-        vereq(c1, 1)
-        c = {1: c1, 2: c2, 3: c3}
-        for x in 1, 2, 3:
-            for y in 1, 2, 3:
-                ##verify(cmp(c[x], c[y]) == cmp(x, y), "x=%d, y=%d" % (x, y))
-                for op in "<", "<=", "==", "!=", ">", ">=":
-                    verify(eval("c[x] %s c[y]" % op) == eval("x %s y" % op),
-                           "x=%d, y=%d" % (x, y))
-                ##verify(cmp(c[x], y) == cmp(x, y), "x=%d, y=%d" % (x, y))
-                ##verify(cmp(x, c[y]) == cmp(x, y), "x=%d, y=%d" % (x, y))
-
-def rich_comparisons():
-    if verbose:
-        print("Testing rich comparisons...")
-    class Z(complex):
-        pass
-    z = Z(1)
-    vereq(z, 1+0j)
-    vereq(1+0j, z)
-    class ZZ(complex):
-        def __eq__(self, other):
-            try:
-                return abs(self - other) <= 1e-6
-            except:
-                return NotImplemented
-    zz = ZZ(1.0000003)
-    vereq(zz, 1+0j)
-    vereq(1+0j, zz)
-
-    class classic:
-        pass
-    for base in (classic, int, object, list):
-        if verbose: print("        (base = %s)" % base)
-        class C(base):
-            def __init__(self, value):
-                self.value = int(value)
-            def __cmp__(self, other):
-                raise TestFailed("shouldn't call __cmp__")
-            def __eq__(self, other):
-                if isinstance(other, C):
-                    return self.value == other.value
-                if isinstance(other, int) or isinstance(other, int):
-                    return self.value == other
-                return NotImplemented
-            def __ne__(self, other):
-                if isinstance(other, C):
-                    return self.value != other.value
-                if isinstance(other, int) or isinstance(other, int):
-                    return self.value != other
-                return NotImplemented
-            def __lt__(self, other):
-                if isinstance(other, C):
-                    return self.value < other.value
-                if isinstance(other, int) or isinstance(other, int):
-                    return self.value < other
-                return NotImplemented
-            def __le__(self, other):
-                if isinstance(other, C):
-                    return self.value <= other.value
-                if isinstance(other, int) or isinstance(other, int):
-                    return self.value <= other
-                return NotImplemented
-            def __gt__(self, other):
-                if isinstance(other, C):
-                    return self.value > other.value
-                if isinstance(other, int) or isinstance(other, int):
-                    return self.value > other
-                return NotImplemented
-            def __ge__(self, other):
-                if isinstance(other, C):
-                    return self.value >= other.value
-                if isinstance(other, int) or isinstance(other, int):
-                    return self.value >= other
-                return NotImplemented
-        c1 = C(1)
-        c2 = C(2)
-        c3 = C(3)
-        vereq(c1, 1)
-        c = {1: c1, 2: c2, 3: c3}
-        for x in 1, 2, 3:
-            for y in 1, 2, 3:
-                for op in "<", "<=", "==", "!=", ">", ">=":
-                    verify(eval("c[x] %s c[y]" % op) == eval("x %s y" % op),
-                           "x=%d, y=%d" % (x, y))
-                    verify(eval("c[x] %s y" % op) == eval("x %s y" % op),
-                           "x=%d, y=%d" % (x, y))
-                    verify(eval("x %s c[y]" % op) == eval("x %s y" % op),
-                           "x=%d, y=%d" % (x, y))
-
-def descrdoc():
-    if verbose: print("Testing descriptor doc strings...")
-    from _fileio import _FileIO
-    def check(descr, what):
-        vereq(descr.__doc__, what)
-    check(_FileIO.closed, "True if the file is closed") # getset descriptor
-    check(complex.real, "the real part of a complex number") # member descriptor
-
-def setclass():
-    if verbose: print("Testing __class__ assignment...")
-    class C(object): pass
-    class D(object): pass
-    class E(object): pass
-    class F(D, E): pass
-    for cls in C, D, E, F:
-        for cls2 in C, D, E, F:
-            x = cls()
-            x.__class__ = cls2
-            verify(x.__class__ is cls2)
-            x.__class__ = cls
-            verify(x.__class__ is cls)
-    def cant(x, C):
         try:
-            x.__class__ = C
+            D.__bases__ = (D,)
         except TypeError:
             pass
         else:
-            raise TestFailed("shouldn't allow %r.__class__ = %r" % (x, C))
+            # actually, we'll have crashed by here...
+            self.fail("shouldn't be able to create inheritance cycles")
+
         try:
-            delattr(x, "__class__")
+            D.__bases__ = (C, C)
         except TypeError:
             pass
         else:
-            raise TestFailed("shouldn't allow del %r.__class__" % x)
-    cant(C(), list)
-    cant(list(), C)
-    cant(C(), 1)
-    cant(C(), object)
-    cant(object(), list)
-    cant(list(), object)
-    class Int(int): __slots__ = []
-    cant(2, Int)
-    cant(Int(), int)
-    cant(True, int)
-    cant(2, bool)
-    o = object()
-    cant(o, type(1))
-    cant(o, type(None))
-    del o
-    class G(object):
-        __slots__ = ["a", "b"]
-    class H(object):
-        __slots__ = ["b", "a"]
-    class I(object):
-        __slots__ = ["a", "b"]
-    class J(object):
-        __slots__ = ["c", "b"]
-    class K(object):
-        __slots__ = ["a", "b", "d"]
-    class L(H):
-        __slots__ = ["e"]
-    class M(I):
-        __slots__ = ["e"]
-    class N(J):
-        __slots__ = ["__weakref__"]
-    class P(J):
-        __slots__ = ["__dict__"]
-    class Q(J):
-        pass
-    class R(J):
-        __slots__ = ["__dict__", "__weakref__"]
+            self.fail("didn't detect repeated base classes")
 
-    for cls, cls2 in ((G, H), (G, I), (I, H), (Q, R), (R, Q)):
-        x = cls()
-        x.a = 1
-        x.__class__ = cls2
-        verify(x.__class__ is cls2,
-               "assigning %r as __class__ for %r silently failed" % (cls2, x))
-        vereq(x.a, 1)
-        x.__class__ = cls
-        verify(x.__class__ is cls,
-               "assigning %r as __class__ for %r silently failed" % (cls, x))
-        vereq(x.a, 1)
-    for cls in G, J, K, L, M, N, P, R, list, Int:
-        for cls2 in G, J, K, L, M, N, P, R, list, Int:
-            if cls is cls2:
-                continue
-            cant(cls(), cls2)
-
-def setdict():
-    if verbose: print("Testing __dict__ assignment...")
-    class C(object): pass
-    a = C()
-    a.__dict__ = {'b': 1}
-    vereq(a.b, 1)
-    def cant(x, dict):
         try:
-            x.__dict__ = dict
-        except (AttributeError, TypeError):
+            D.__bases__ = (E,)
+        except TypeError:
             pass
         else:
-            raise TestFailed("shouldn't allow %r.__dict__ = %r" % (x, dict))
-    cant(a, None)
-    cant(a, [])
-    cant(a, 1)
-    del a.__dict__ # Deleting __dict__ is allowed
-
-    class Base(object):
-        pass
-    def verify_dict_readonly(x):
-        """
-        x has to be an instance of a class inheriting from Base.
-        """
-        cant(x, {})
-        try:
-            del x.__dict__
-        except (AttributeError, TypeError):
+            self.fail("shouldn't be able to create inheritance cycles")
+
+    def test_mutable_bases_with_failing_mro(self):
+        # Testing mutable bases with failing mro...
+        class WorkOnce(type):
+            def __new__(self, name, bases, ns):
+                self.flag = 0
+                return super(WorkOnce, self).__new__(WorkOnce, name, bases, ns)
+            def mro(self):
+                if self.flag > 0:
+                    raise RuntimeError("bozo")
+                else:
+                    self.flag += 1
+                    return type.mro(self)
+
+        class WorkAlways(type):
+            def mro(self):
+                # this is here to make sure that .mro()s aren't called
+                # with an exception set (which was possible at one point).
+                # An error message will be printed in a debug build.
+                # What's a good way to test for this?
+                return type.mro(self)
+
+        class C(object):
+            pass
+
+        class C2(object):
+            pass
+
+        class D(C):
+            pass
+
+        class E(D):
+            pass
+
+        class F(D, metaclass=WorkOnce):
+            pass
+
+        class G(D, metaclass=WorkAlways):
             pass
+
+        # Immediate subclasses have their mro's adjusted in alphabetical
+        # order, so E's will get adjusted before adjusting F's fails.  We
+        # check here that E's gets restored.
+
+        E_mro_before = E.__mro__
+        D_mro_before = D.__mro__
+
+        try:
+            D.__bases__ = (C2,)
+        except RuntimeError:
+            self.assertEqual(E.__mro__, E_mro_before)
+            self.assertEqual(D.__mro__, D_mro_before)
         else:
-            raise TestFailed("shouldn't allow del %r.__dict__" % x)
-        dict_descr = Base.__dict__["__dict__"]
+            self.fail("exception not propagated")
+
+    def test_mutable_bases_catch_mro_conflict(self):
+        # Testing mutable bases catch mro conflict...
+        class A(object):
+            pass
+
+        class B(object):
+            pass
+
+        class C(A, B):
+            pass
+
+        class D(A, B):
+            pass
+
+        class E(C, D):
+            pass
+
         try:
-            dict_descr.__set__(x, {})
-        except (AttributeError, TypeError):
+            C.__bases__ = (B, A)
+        except TypeError:
             pass
         else:
-            raise TestFailed("dict_descr allowed access to %r's dict" % x)
+            self.fail("didn't catch MRO conflict")
 
-    # Classes don't allow __dict__ assignment and have readonly dicts
-    class Meta1(type, Base):
-        pass
-    class Meta2(Base, type):
-        pass
-    class D(object):
-        __metaclass__ = Meta1
-    class E(object):
-        __metaclass__ = Meta2
-    for cls in C, D, E:
-        verify_dict_readonly(cls)
-        class_dict = cls.__dict__
-        try:
-            class_dict["spam"] = "eggs"
-        except TypeError:
-            pass
-        else:
-            raise TestFailed("%r's __dict__ can be modified" % cls)
-
-    # Modules also disallow __dict__ assignment
-    class Module1(types.ModuleType, Base):
-        pass
-    class Module2(Base, types.ModuleType):
-        pass
-    for ModuleType in Module1, Module2:
-        mod = ModuleType("spam")
-        verify_dict_readonly(mod)
-        mod.__dict__["spam"] = "eggs"
-
-    # Exception's __dict__ can be replaced, but not deleted
-    class Exception1(Exception, Base):
-        pass
-    class Exception2(Base, Exception):
-        pass
-    for ExceptionType in Exception, Exception1, Exception2:
-        e = ExceptionType()
-        e.__dict__ = {"a": 1}
-        vereq(e.a, 1)
-        try:
-            del e.__dict__
-        except (TypeError, AttributeError):
-            pass
-        else:
-            raise TestFaied("%r's __dict__ can be deleted" % e)
-
-
-def pickles():
-    if verbose:
-        print("Testing pickling and copying new-style classes and objects...")
-    import pickle
-
-    def sorteditems(d):
-        return sorted(d.items())
-
-    global C
-    class C(object):
-        def __init__(self, a, b):
-            super(C, self).__init__()
-            self.a = a
-            self.b = b
-        def __repr__(self):
-            return "C(%r, %r)" % (self.a, self.b)
-
-    global C1
-    class C1(list):
-        def __new__(cls, a, b):
-            return super(C1, cls).__new__(cls)
-        def __getnewargs__(self):
-            return (self.a, self.b)
-        def __init__(self, a, b):
-            self.a = a
-            self.b = b
-        def __repr__(self):
-            return "C1(%r, %r)<%r>" % (self.a, self.b, list(self))
-
-    global C2
-    class C2(int):
-        def __new__(cls, a, b, val=0):
-            return super(C2, cls).__new__(cls, val)
-        def __getnewargs__(self):
-            return (self.a, self.b, int(self))
-        def __init__(self, a, b, val=0):
-            self.a = a
-            self.b = b
-        def __repr__(self):
-            return "C2(%r, %r)<%r>" % (self.a, self.b, int(self))
-
-    global C3
-    class C3(object):
-        def __init__(self, foo):
-            self.foo = foo
-        def __getstate__(self):
-            return self.foo
-        def __setstate__(self, foo):
-            self.foo = foo
-
-    global C4classic, C4
-    class C4classic: # classic
-        pass
-    class C4(C4classic, object): # mixed inheritance
-        pass
+    def test_mutable_names(self):
+        # Testing mutable names...
+        class C(object):
+            pass
 
-    for p in [pickle]:
-        for bin in 0, 1:
-            if verbose:
-                print(p.__name__, ["text", "binary"][bin])
+        # C.__module__ could be 'test_descr' or '__main__'
+        mod = C.__module__
 
-            for cls in C, C1, C2:
-                s = p.dumps(cls, bin)
-                cls2 = p.loads(s)
-                verify(cls2 is cls)
+        C.__name__ = 'D'
+        self.assertEqual((C.__module__, C.__name__), (mod, 'D'))
+
+        C.__name__ = 'D.E'
+        self.assertEqual((C.__module__, C.__name__), (mod, 'D.E'))
+
+    def test_subclass_right_op(self):
+        # Testing correct dispatch of subclass overloading __r<op>__...
+
+        # This code tests various cases where right-dispatch of a subclass
+        # should be preferred over left-dispatch of a base class.
+
+        # Case 1: subclass of int; this tests code in abstract.c::binary_op1()
+
+        class B(int):
+            def __floordiv__(self, other):
+                return "B.__floordiv__"
+            def __rfloordiv__(self, other):
+                return "B.__rfloordiv__"
+
+        self.assertEqual(B(1) // 1, "B.__floordiv__")
+        self.assertEqual(1 // B(1), "B.__rfloordiv__")
+
+        # Case 2: subclass of object; this is just the baseline for case 3
+
+        class C(object):
+            def __floordiv__(self, other):
+                return "C.__floordiv__"
+            def __rfloordiv__(self, other):
+                return "C.__rfloordiv__"
+
+        self.assertEqual(C() // 1, "C.__floordiv__")
+        self.assertEqual(1 // C(), "C.__rfloordiv__")
+
+        # Case 3: subclass of new-style class; here it gets interesting
 
-            a = C1(1, 2); a.append(42); a.append(24)
-            b = C2("hello", "world", 42)
-            s = p.dumps((a, b), bin)
-            x, y = p.loads(s)
-            vereq(x.__class__, a.__class__)
-            vereq(sorteditems(x.__dict__), sorteditems(a.__dict__))
-            vereq(y.__class__, b.__class__)
-            vereq(sorteditems(y.__dict__), sorteditems(b.__dict__))
-            vereq(repr(x), repr(a))
-            vereq(repr(y), repr(b))
-            if verbose:
-                print("a = x =", a)
-                print("b = y =", b)
-            # Test for __getstate__ and __setstate__ on new style class
-            u = C3(42)
-            s = p.dumps(u, bin)
-            v = p.loads(s)
-            veris(u.__class__, v.__class__)
-            vereq(u.foo, v.foo)
-            # Test for picklability of hybrid class
-            u = C4()
-            u.foo = 42
-            s = p.dumps(u, bin)
-            v = p.loads(s)
-            veris(u.__class__, v.__class__)
-            vereq(u.foo, v.foo)
-
-    # Testing copy.deepcopy()
-    if verbose:
-        print("deepcopy")
-    import copy
-    for cls in C, C1, C2:
-        cls2 = copy.deepcopy(cls)
-        verify(cls2 is cls)
-
-    a = C1(1, 2); a.append(42); a.append(24)
-    b = C2("hello", "world", 42)
-    x, y = copy.deepcopy((a, b))
-    vereq(x.__class__, a.__class__)
-    vereq(sorteditems(x.__dict__), sorteditems(a.__dict__))
-    vereq(y.__class__, b.__class__)
-    vereq(sorteditems(y.__dict__), sorteditems(b.__dict__))
-    vereq(repr(x), repr(a))
-    vereq(repr(y), repr(b))
-    if verbose:
-        print("a = x =", a)
-        print("b = y =", b)
-
-def pickleslots():
-    if verbose: print("Testing pickling of classes with __slots__ ...")
-    import pickle
-    # Pickling of classes with __slots__ but without __getstate__ should fail
-    # (when using protocols 0 or 1)
-    global B, C, D, E
-    class B(object):
-        pass
-    for base in [object, B]:
-        class C(base):
-            __slots__ = ['a']
         class D(C):
+            def __floordiv__(self, other):
+                return "D.__floordiv__"
+            def __rfloordiv__(self, other):
+                return "D.__rfloordiv__"
+
+        self.assertEqual(D() // C(), "D.__floordiv__")
+        self.assertEqual(C() // D(), "D.__rfloordiv__")
+
+        # Case 4: this didn't work right in 2.2.2 and 2.3a1
+
+        class E(C):
+            pass
+
+        self.assertEqual(E.__rfloordiv__, C.__rfloordiv__)
+
+        self.assertEqual(E() // 1, "C.__floordiv__")
+        self.assertEqual(1 // E(), "C.__rfloordiv__")
+        self.assertEqual(E() // C(), "C.__floordiv__")
+        self.assertEqual(C() // E(), "C.__floordiv__") # This one would fail
+
+    def test_meth_class_get(self):
+        # Testing __get__ method of METH_CLASS C methods...
+        # Full coverage of descrobject.c::classmethod_get()
+
+        # Baseline
+        arg = [1, 2, 3]
+        res = {1: None, 2: None, 3: None}
+        self.assertEqual(dict.fromkeys(arg), res)
+        self.assertEqual({}.fromkeys(arg), res)
+
+        # Now get the descriptor
+        descr = dict.__dict__["fromkeys"]
+
+        # More baseline using the descriptor directly
+        self.assertEqual(descr.__get__(None, dict)(arg), res)
+        self.assertEqual(descr.__get__({})(arg), res)
+
+        # Now check various error cases
+        try:
+            descr.__get__(None, None)
+        except TypeError:
             pass
+        else:
+            self.fail("shouldn't have allowed descr.__get__(None, None)")
         try:
-            pickle.dumps(C(), 0)
+            descr.__get__(42)
         except TypeError:
             pass
         else:
-            raise TestFailed("should fail: pickle C instance - %s" % base)
+            self.fail("shouldn't have allowed descr.__get__(42)")
         try:
-            pickle.dumps(C(), 0)
+            descr.__get__(None, 42)
         except TypeError:
             pass
         else:
-            raise TestFailed("should fail: pickle D instance - %s" % base)
-        # Give C a nice generic __getstate__ and __setstate__
-        class C(base):
-            __slots__ = ['a']
-            def __getstate__(self):
-                try:
-                    d = self.__dict__.copy()
-                except AttributeError:
-                    d = {}
-                for cls in self.__class__.__mro__:
-                    for sn in cls.__dict__.get('__slots__', ()):
-                        try:
-                            d[sn] = getattr(self, sn)
-                        except AttributeError:
-                            pass
-                return d
-            def __setstate__(self, d):
-                for k, v in d.items():
-                    setattr(self, k, v)
+            self.fail("shouldn't have allowed descr.__get__(None, 42)")
+        try:
+            descr.__get__(None, int)
+        except TypeError:
+            pass
+        else:
+            self.fail("shouldn't have allowed descr.__get__(None, int)")
+
+    def test_isinst_isclass(self):
+        # Testing proxy isinstance() and isclass()...
+        class Proxy(object):
+            def __init__(self, obj):
+                self.__obj = obj
+            def __getattribute__(self, name):
+                if name.startswith("_Proxy__"):
+                    return object.__getattribute__(self, name)
+                else:
+                    return getattr(self.__obj, name)
+        # Test with a classic class
+        class C:
+            pass
+        a = C()
+        pa = Proxy(a)
+        self.assert_(isinstance(a, C))  # Baseline
+        self.assert_(isinstance(pa, C)) # Test
+        # Test with a classic subclass
         class D(C):
             pass
-        # Now it should work
-        x = C()
-        y = pickle.loads(pickle.dumps(x))
-        vereq(hasattr(y, 'a'), 0)
-        x.a = 42
-        y = pickle.loads(pickle.dumps(x))
-        vereq(y.a, 42)
-        x = D()
-        x.a = 42
-        x.b = 100
-        y = pickle.loads(pickle.dumps(x))
-        vereq(y.a + y.b, 142)
-        # A subclass that adds a slot should also work
-        class E(C):
-            __slots__ = ['b']
-        x = E()
-        x.a = 42
-        x.b = "foo"
-        y = pickle.loads(pickle.dumps(x))
-        vereq(y.a, x.a)
-        vereq(y.b, x.b)
-
-def copies():
-    if verbose: print("Testing copy.copy() and copy.deepcopy()...")
-    import copy
-    class C(object):
-        pass
-
-    a = C()
-    a.foo = 12
-    b = copy.copy(a)
-    vereq(b.__dict__, a.__dict__)
-
-    a.bar = [1,2,3]
-    c = copy.copy(a)
-    vereq(c.bar, a.bar)
-    verify(c.bar is a.bar)
-
-    d = copy.deepcopy(a)
-    vereq(d.__dict__, a.__dict__)
-    a.bar.append(4)
-    vereq(d.bar, [1,2,3])
-
-def binopoverride():
-    if verbose: print("Testing overrides of binary operations...")
-    class I(int):
-        def __repr__(self):
-            return "I(%r)" % int(self)
-        def __add__(self, other):
-            return I(int(self) + int(other))
-        __radd__ = __add__
-        def __pow__(self, other, mod=None):
-            if mod is None:
-                return I(pow(int(self), int(other)))
-            else:
-                return I(pow(int(self), int(other), int(mod)))
-        def __rpow__(self, other, mod=None):
-            if mod is None:
-                return I(pow(int(other), int(self), mod))
-            else:
-                return I(pow(int(other), int(self), int(mod)))
+        a = D()
+        pa = Proxy(a)
+        self.assert_(isinstance(a, C))  # Baseline
+        self.assert_(isinstance(pa, C)) # Test
+        # Test with a new-style class
+        class C(object):
+            pass
+        a = C()
+        pa = Proxy(a)
+        self.assert_(isinstance(a, C))  # Baseline
+        self.assert_(isinstance(pa, C)) # Test
+        # Test with a new-style subclass
+        class D(C):
+            pass
+        a = D()
+        pa = Proxy(a)
+        self.assert_(isinstance(a, C))  # Baseline
+        self.assert_(isinstance(pa, C)) # Test
+
+    def test_proxy_super(self):
+        # Testing super() for a proxy object...
+        class Proxy(object):
+            def __init__(self, obj):
+                self.__obj = obj
+            def __getattribute__(self, name):
+                if name.startswith("_Proxy__"):
+                    return object.__getattribute__(self, name)
+                else:
+                    return getattr(self.__obj, name)
+
+        class B(object):
+            def f(self):
+                return "B.f"
+
+        class C(B):
+            def f(self):
+                return super(C, self).f() + "->C.f"
+
+        obj = C()
+        p = Proxy(obj)
+        self.assertEqual(C.__dict__["f"](p), "B.f->C.f")
 
-    vereq(repr(I(1) + I(2)), "I(3)")
-    vereq(repr(I(1) + 2), "I(3)")
-    vereq(repr(1 + I(2)), "I(3)")
-    vereq(repr(I(2) ** I(3)), "I(8)")
-    vereq(repr(2 ** I(3)), "I(8)")
-    vereq(repr(I(2) ** 3), "I(8)")
-    vereq(repr(pow(I(2), I(3), I(5))), "I(3)")
-    class S(str):
-        def __eq__(self, other):
-            return self.lower() == other.lower()
-
-def subclasspropagation():
-    if verbose: print("Testing propagation of slot functions to subclasses...")
-    class A(object):
-        pass
-    class B(A):
-        pass
-    class C(A):
-        pass
-    class D(B, C):
-        pass
-    d = D()
-    orig_hash = hash(d) # related to id(d) in platform-dependent ways
-    A.__hash__ = lambda self: 42
-    vereq(hash(d), 42)
-    C.__hash__ = lambda self: 314
-    vereq(hash(d), 314)
-    B.__hash__ = lambda self: 144
-    vereq(hash(d), 144)
-    D.__hash__ = lambda self: 100
-    vereq(hash(d), 100)
-    del D.__hash__
-    vereq(hash(d), 144)
-    del B.__hash__
-    vereq(hash(d), 314)
-    del C.__hash__
-    vereq(hash(d), 42)
-    del A.__hash__
-    vereq(hash(d), orig_hash)
-    d.foo = 42
-    d.bar = 42
-    vereq(d.foo, 42)
-    vereq(d.bar, 42)
-    def __getattribute__(self, name):
-        if name == "foo":
-            return 24
-        return object.__getattribute__(self, name)
-    A.__getattribute__ = __getattribute__
-    vereq(d.foo, 24)
-    vereq(d.bar, 42)
-    def __getattr__(self, name):
-        if name in ("spam", "foo", "bar"):
-            return "hello"
-        raise AttributeError(name)
-    B.__getattr__ = __getattr__
-    vereq(d.spam, "hello")
-    vereq(d.foo, 24)
-    vereq(d.bar, 42)
-    del A.__getattribute__
-    vereq(d.foo, 42)
-    del d.foo
-    vereq(d.foo, "hello")
-    vereq(d.bar, 42)
-    del B.__getattr__
-    try:
-        d.foo
-    except AttributeError:
-        pass
-    else:
-        raise TestFailed("d.foo should be undefined now")
-
-    # Test a nasty bug in recurse_down_subclasses()
-    import gc
-    class A(object):
-        pass
-    class B(A):
-        pass
-    del B
-    gc.collect()
-    A.__setitem__ = lambda *a: None # crash
-
-def buffer_inherit():
-    import binascii
-    # SF bug [#470040] ParseTuple t# vs subclasses.
-    if verbose:
-        print("Testing that buffer interface is inherited ...")
-
-    class MyStr(str):
-        pass
-    base = 'abc'
-    m = MyStr(base)
-    # b2a_hex uses the buffer interface to get its argument's value, via
-    # PyArg_ParseTuple 't#' code.
-    vereq(binascii.b2a_hex(m), binascii.b2a_hex(base))
-
-    # It's not clear that unicode will continue to support the character
-    # buffer interface, and this test will fail if that's taken away.
-    class MyUni(str):
-        pass
-    base = 'abc'
-    m = MyUni(base)
-    vereq(binascii.b2a_hex(m), binascii.b2a_hex(base))
-
-    class MyInt(int):
-        pass
-    m = MyInt(42)
-    try:
-        binascii.b2a_hex(m)
-        raise TestFailed('subclass of int should not have a buffer interface')
-    except TypeError:
-        pass
-
-def str_of_str_subclass():
-    import binascii
-    import io
-
-    if verbose:
-        print("Testing __str__ defined in subclass of str ...")
-
-    class octetstring(str):
-        def __str__(self):
-            return str(binascii.b2a_hex(self))
-        def __repr__(self):
-            return self + " repr"
-
-    o = octetstring('A')
-    vereq(type(o), octetstring)
-    vereq(type(str(o)), str)
-    vereq(type(repr(o)), str)
-    vereq(ord(o), 0x41)
-    vereq(str(o), '41')
-    vereq(repr(o), 'A repr')
-    vereq(o.__str__(), '41')
-    vereq(o.__repr__(), 'A repr')
-
-    capture = io.StringIO()
-    # Calling str() or not exercises different internal paths.
-    print(o, file=capture)
-    print(str(o), file=capture)
-    vereq(capture.getvalue(), '41\n41\n')
-    capture.close()
-
-def kwdargs():
-    if verbose: print("Testing keyword arguments to __init__, __call__...")
-    def f(a): return a
-    vereq(f.__call__(a=42), 42)
-    a = []
-    list.__init__(a, sequence=[0, 1, 2])
-    vereq(a, [0, 1, 2])
-
-def recursive__call__():
-    if verbose: print(("Testing recursive __call__() by setting to instance of "
-                        "class ..."))
-    class A(object):
-        pass
-
-    A.__call__ = A()
-    try:
-        A()()
-    except RuntimeError:
-        pass
-    else:
-        raise TestFailed("Recursion limit should have been reached for "
-                         "__call__()")
-
-def delhook():
-    if verbose: print("Testing __del__ hook...")
-    log = []
-    class C(object):
-        def __del__(self):
-            log.append(1)
-    c = C()
-    vereq(log, [])
-    del c
-    vereq(log, [1])
-
-    class D(object): pass
-    d = D()
-    try: del d[0]
-    except TypeError: pass
-    else: raise TestFailed("invalid del() didn't raise TypeError")
-
-def hashinherit():
-    if verbose: print("Testing hash of mutable subclasses...")
-
-    class mydict(dict):
-        pass
-    d = mydict()
-    try:
-        hash(d)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("hash() of dict subclass should fail")
-
-    class mylist(list):
-        pass
-    d = mylist()
-    try:
-        hash(d)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("hash() of list subclass should fail")
-
-def strops():
-    try: 'a' + 5
-    except TypeError: pass
-    else: raise TestFailed("'' + 5 doesn't raise TypeError")
-
-    try: ''.split('')
-    except ValueError: pass
-    else: raise TestFailed("''.split('') doesn't raise ValueError")
-
-    try: ''.rindex('5')
-    except ValueError: pass
-    else: raise TestFailed("''.rindex('5') doesn't raise ValueError")
-
-    try: '%(n)s' % None
-    except TypeError: pass
-    else: raise TestFailed("'%(n)s' % None doesn't raise TypeError")
-
-    try: '%(n' % {}
-    except ValueError: pass
-    else: raise TestFailed("'%(n' % {} '' doesn't raise ValueError")
-
-    try: '%*s' % ('abc')
-    except TypeError: pass
-    else: raise TestFailed("'%*s' % ('abc') doesn't raise TypeError")
-
-    try: '%*.*s' % ('abc', 5)
-    except TypeError: pass
-    else: raise TestFailed("'%*.*s' % ('abc', 5) doesn't raise TypeError")
-
-    try: '%s' % (1, 2)
-    except TypeError: pass
-    else: raise TestFailed("'%s' % (1, 2) doesn't raise TypeError")
-
-    try: '%' % None
-    except ValueError: pass
-    else: raise TestFailed("'%' % None doesn't raise ValueError")
-
-    vereq('534253'.isdigit(), 1)
-    vereq('534253x'.isdigit(), 0)
-    vereq('%c' % 5, '\x05')
-    vereq('%c' % '5', '5')
-
-def deepcopyrecursive():
-    if verbose: print("Testing deepcopy of recursive objects...")
-    class Node:
-        pass
-    a = Node()
-    b = Node()
-    a.b = b
-    b.a = a
-    z = deepcopy(a) # This blew up before
-
-def modules():
-    if verbose: print("Testing uninitialized module objects...")
-    from types import ModuleType as M
-    m = M.__new__(M)
-    str(m)
-    vereq(hasattr(m, "__name__"), 0)
-    vereq(hasattr(m, "__file__"), 0)
-    vereq(hasattr(m, "foo"), 0)
-    vereq(m.__dict__, None)
-    m.foo = 1
-    vereq(m.__dict__, {"foo": 1})
-
-def dictproxyiterkeys():
-    class C(object):
-        def meth(self):
-            pass
-    if verbose: print("Testing dict-proxy iterkeys...")
-    keys = [ key for key in C.__dict__.keys() ]
-    keys.sort()
-    vereq(keys, ['__dict__', '__doc__', '__module__', '__weakref__', 'meth'])
-
-def dictproxyitervalues():
-    class C(object):
-        def meth(self):
-            pass
-    if verbose: print("Testing dict-proxy itervalues...")
-    values = [ values for values in C.__dict__.values() ]
-    vereq(len(values), 5)
-
-def dictproxyiteritems():
-    class C(object):
-        def meth(self):
-            pass
-    if verbose: print("Testing dict-proxy iteritems...")
-    keys = [ key for (key, value) in C.__dict__.items() ]
-    keys.sort()
-    vereq(keys, ['__dict__', '__doc__', '__module__', '__weakref__', 'meth'])
-
-def funnynew():
-    if verbose: print("Testing __new__ returning something unexpected...")
-    class C(object):
-        def __new__(cls, arg):
-            if isinstance(arg, str): return [1, 2, 3]
-            elif isinstance(arg, int): return object.__new__(D)
-            else: return object.__new__(cls)
-    class D(C):
-        def __init__(self, arg):
-            self.foo = arg
-    vereq(C("1"), [1, 2, 3])
-    vereq(D("1"), [1, 2, 3])
-    d = D(None)
-    veris(d.foo, None)
-    d = C(1)
-    vereq(isinstance(d, D), True)
-    vereq(d.foo, 1)
-    d = D(1)
-    vereq(isinstance(d, D), True)
-    vereq(d.foo, 1)
-
-def imulbug():
-    # SF bug 544647
-    if verbose: print("Testing for __imul__ problems...")
-    class C(object):
-        def __imul__(self, other):
-            return (self, other)
-    x = C()
-    y = x
-    y *= 1.0
-    vereq(y, (x, 1.0))
-    y = x
-    y *= 2
-    vereq(y, (x, 2))
-    y = x
-    y *= 3
-    vereq(y, (x, 3))
-    y = x
-    y *= 1<<100
-    vereq(y, (x, 1<<100))
-    y = x
-    y *= None
-    vereq(y, (x, None))
-    y = x
-    y *= "foo"
-    vereq(y, (x, "foo"))
-
-def docdescriptor():
-    # SF bug 542984
-    if verbose: print("Testing __doc__ descriptor...")
-    class DocDescr(object):
-        def __get__(self, object, otype):
-            if object:
-                object = object.__class__.__name__ + ' instance'
-            if otype:
-                otype = otype.__name__
-            return 'object=%s; type=%s' % (object, otype)
-    class OldClass:
-        __doc__ = DocDescr()
-    class NewClass(object):
-        __doc__ = DocDescr()
-    vereq(OldClass.__doc__, 'object=None; type=OldClass')
-    vereq(OldClass().__doc__, 'object=OldClass instance; type=OldClass')
-    vereq(NewClass.__doc__, 'object=None; type=NewClass')
-    vereq(NewClass().__doc__, 'object=NewClass instance; type=NewClass')
-
-def copy_setstate():
-    if verbose:
-        print("Testing that copy.*copy() correctly uses __setstate__...")
-    import copy
-    class C(object):
-        def __init__(self, foo=None):
-            self.foo = foo
-            self.__foo = foo
-        def setfoo(self, foo=None):
-            self.foo = foo
-        def getfoo(self):
-            return self.__foo
-        def __getstate__(self):
-            return [self.foo]
-        def __setstate__(self, lst):
-            assert len(lst) == 1
-            self.__foo = self.foo = lst[0]
-    a = C(42)
-    a.setfoo(24)
-    vereq(a.foo, 24)
-    vereq(a.getfoo(), 42)
-    b = copy.copy(a)
-    vereq(b.foo, 24)
-    vereq(b.getfoo(), 24)
-    b = copy.deepcopy(a)
-    vereq(b.foo, 24)
-    vereq(b.getfoo(), 24)
-
-def slices():
-    if verbose:
-        print("Testing cases with slices and overridden __getitem__ ...")
-    # Strings
-    vereq("hello"[:4], "hell")
-    vereq("hello"[slice(4)], "hell")
-    vereq(str.__getitem__("hello", slice(4)), "hell")
-    class S(str):
-        def __getitem__(self, x):
-            return str.__getitem__(self, x)
-    vereq(S("hello")[:4], "hell")
-    vereq(S("hello")[slice(4)], "hell")
-    vereq(S("hello").__getitem__(slice(4)), "hell")
-    # Tuples
-    vereq((1,2,3)[:2], (1,2))
-    vereq((1,2,3)[slice(2)], (1,2))
-    vereq(tuple.__getitem__((1,2,3), slice(2)), (1,2))
-    class T(tuple):
-        def __getitem__(self, x):
-            return tuple.__getitem__(self, x)
-    vereq(T((1,2,3))[:2], (1,2))
-    vereq(T((1,2,3))[slice(2)], (1,2))
-    vereq(T((1,2,3)).__getitem__(slice(2)), (1,2))
-    # Lists
-    vereq([1,2,3][:2], [1,2])
-    vereq([1,2,3][slice(2)], [1,2])
-    vereq(list.__getitem__([1,2,3], slice(2)), [1,2])
-    class L(list):
-        def __getitem__(self, x):
-            return list.__getitem__(self, x)
-    vereq(L([1,2,3])[:2], [1,2])
-    vereq(L([1,2,3])[slice(2)], [1,2])
-    vereq(L([1,2,3]).__getitem__(slice(2)), [1,2])
-    # Now do lists and __setitem__
-    a = L([1,2,3])
-    a[slice(1, 3)] = [3,2]
-    vereq(a, [1,3,2])
-    a[slice(0, 2, 1)] = [3,1]
-    vereq(a, [3,1,2])
-    a.__setitem__(slice(1, 3), [2,1])
-    vereq(a, [3,2,1])
-    a.__setitem__(slice(0, 2, 1), [2,3])
-    vereq(a, [2,3,1])
-
-def subtype_resurrection():
-    if verbose:
-        print("Testing resurrection of new-style instance...")
-
-    class C(object):
-        container = []
-
-        def __del__(self):
-            # resurrect the instance
-            C.container.append(self)
-
-    c = C()
-    c.attr = 42
-    # The most interesting thing here is whether this blows up, due to flawed
-    #  GC tracking logic in typeobject.c's call_finalizer() (a 2.2.1 bug).
-    del c
-
-    # If that didn't blow up, it's also interesting to see whether clearing
-    # the last container slot works:  that will attempt to delete c again,
-    # which will cause c to get appended back to the container again "during"
-    # the del.
-    del C.container[-1]
-    vereq(len(C.container), 1)
-    vereq(C.container[-1].attr, 42)
-
-    # Make c mortal again, so that the test framework with -l doesn't report
-    # it as a leak.
-    del C.__del__
-
-def slottrash():
-    # Deallocating deeply nested slotted trash caused stack overflows
-    if verbose:
-        print("Testing slot trash...")
-    class trash(object):
-        __slots__ = ['x']
-        def __init__(self, x):
-            self.x = x
-    o = None
-    for i in range(50000):
-        o = trash(o)
-    del o
-
-def slotmultipleinheritance():
-    # SF bug 575229, multiple inheritance w/ slots dumps core
-    class A(object):
-        __slots__=()
-    class B(object):
-        pass
-    class C(A,B) :
-        __slots__=()
-    vereq(C.__basicsize__, B.__basicsize__)
-    verify(hasattr(C, '__dict__'))
-    verify(hasattr(C, '__weakref__'))
-    C().x = 2
-
-def testrmul():
-    # SF patch 592646
-    if verbose:
-        print("Testing correct invocation of __rmul__...")
-    class C(object):
-        def __mul__(self, other):
-            return "mul"
-        def __rmul__(self, other):
-            return "rmul"
-    a = C()
-    vereq(a*2, "mul")
-    vereq(a*2.2, "mul")
-    vereq(2*a, "rmul")
-    vereq(2.2*a, "rmul")
-
-def testipow():
-    # [SF bug 620179]
-    if verbose:
-        print("Testing correct invocation of __ipow__...")
-    class C(object):
-        def __ipow__(self, other):
-            pass
-    a = C()
-    a **= 2
-
-def do_this_first():
-    if verbose:
-        print("Testing SF bug 551412 ...")
-    # This dumps core when SF bug 551412 isn't fixed --
-    # but only when test_descr.py is run separately.
-    # (That can't be helped -- as soon as PyType_Ready()
-    # is called for PyLong_Type, the bug is gone.)
-    class UserLong(object):
-        def __pow__(self, *args):
-            pass
-    try:
-        pow(0, UserLong(), 0)
-    except:
-        pass
-
-    if verbose:
-        print("Testing SF bug 570483...")
-    # Another segfault only when run early
-    # (before PyType_Ready(tuple) is called)
-    type.mro(tuple)
-
-def test_mutable_bases():
-    if verbose:
-        print("Testing mutable bases...")
-    # stuff that should work:
-    class C(object):
-        pass
-    class C2(object):
-        def __getattribute__(self, attr):
-            if attr == 'a':
-                return 2
-            else:
-                return super(C2, self).__getattribute__(attr)
-        def meth(self):
-            return 1
-    class D(C):
-        pass
-    class E(D):
-        pass
-    d = D()
-    e = E()
-    D.__bases__ = (C,)
-    D.__bases__ = (C2,)
-    vereq(d.meth(), 1)
-    vereq(e.meth(), 1)
-    vereq(d.a, 2)
-    vereq(e.a, 2)
-    vereq(C2.__subclasses__(), [D])
-
-    # stuff that shouldn't:
-    class L(list):
-        pass
-
-    try:
-        L.__bases__ = (dict,)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't turn list subclass into dict subclass")
-
-    try:
-        list.__bases__ = (dict,)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't be able to assign to list.__bases__")
-
-    try:
-        D.__bases__ = (C2, list)
-    except TypeError:
-        pass
-    else:
-        assert 0, "best_base calculation found wanting"
-
-    try:
-        del D.__bases__
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't be able to delete .__bases__")
-
-    try:
-        D.__bases__ = ()
-    except TypeError as msg:
-        if str(msg) == "a new-style class can't have only classic bases":
-            raise TestFailed("wrong error message for .__bases__ = ()")
-    else:
-        raise TestFailed("shouldn't be able to set .__bases__ to ()")
-
-    try:
-        D.__bases__ = (D,)
-    except TypeError:
-        pass
-    else:
-        # actually, we'll have crashed by here...
-        raise TestFailed("shouldn't be able to create inheritance cycles")
-
-    try:
-        D.__bases__ = (C, C)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("didn't detect repeated base classes")
-
-    try:
-        D.__bases__ = (E,)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't be able to create inheritance cycles")
-
-def test_mutable_bases_with_failing_mro():
-    if verbose:
-        print("Testing mutable bases with failing mro...")
-    class WorkOnce(type):
-        def __new__(self, name, bases, ns):
-            self.flag = 0
-            return super(WorkOnce, self).__new__(WorkOnce, name, bases, ns)
-        def mro(self):
-            if self.flag > 0:
-                raise RuntimeError("bozo")
-            else:
-                self.flag += 1
-                return type.mro(self)
+    def test_carloverre(self):
+        # Testing prohibition of Carlo Verre's hack...
+        try:
+            object.__setattr__(str, "foo", 42)
+        except TypeError:
+            pass
+        else:
+            self.fail("Carlo Verre __setattr__ suceeded!")
+        try:
+            object.__delattr__(str, "lower")
+        except TypeError:
+            pass
+        else:
+            self.fail("Carlo Verre __delattr__ succeeded!")
+
+    def test_weakref_segfault(self):
+        # Testing weakref segfault...
+        # SF 742911
+        import weakref
 
-    class WorkAlways(type):
-        def mro(self):
-            # this is here to make sure that .mro()s aren't called
-            # with an exception set (which was possible at one point).
-            # An error message will be printed in a debug build.
-            # What's a good way to test for this?
-            return type.mro(self)
+        class Provoker:
+            def __init__(self, referrent):
+                self.ref = weakref.ref(referrent)
 
-    class C(object):
-        pass
+            def __del__(self):
+                x = self.ref()
 
-    class C2(object):
-        pass
+        class Oops(object):
+            pass
 
-    class D(C):
-        pass
+        o = Oops()
+        o.whatever = Provoker(o)
+        del o
+
+    def test_wrapper_segfault(self):
+        # SF 927248: deeply nested wrappers could cause stack overflow
+        f = lambda:None
+        for i in range(1000000):
+            f = f.__call__
+        f = None
+
+    def test_file_fault(self):
+        # Testing sys.stdout is changed in getattr...
+        import sys
+        class StdoutGuard:
+            def __getattr__(self, attr):
+                sys.stdout = sys.__stdout__
+                raise RuntimeError("Premature access to sys.stdout.%s" % attr)
+        sys.stdout = StdoutGuard()
+        try:
+            print("Oops!")
+        except RuntimeError:
+            pass
 
-    class E(D):
-        pass
+    def test_vicious_descriptor_nonsense(self):
+        # Testing vicious_descriptor_nonsense...
 
-    class F(D, metaclass=WorkOnce):
-        pass
+        # A potential segfault spotted by Thomas Wouters in mail to
+        # python-dev 2003-04-17, turned into an example & fixed by Michael
+        # Hudson just less than four months later...
+
+        class Evil(object):
+            def __hash__(self):
+                return hash('attr')
+            def __eq__(self, other):
+                del C.attr
+                return 0
 
-    class G(D, metaclass=WorkAlways):
-        pass
+        class Descr(object):
+            def __get__(self, ob, type=None):
+                return 1
 
-    # Immediate subclasses have their mro's adjusted in alphabetical
-    # order, so E's will get adjusted before adjusting F's fails.  We
-    # check here that E's gets restored.
+        class C(object):
+            attr = Descr()
 
-    E_mro_before = E.__mro__
-    D_mro_before = D.__mro__
+        c = C()
+        c.__dict__[Evil()] = 0
 
-    try:
-        D.__bases__ = (C2,)
-    except RuntimeError:
-        vereq(E.__mro__, E_mro_before)
-        vereq(D.__mro__, D_mro_before)
-    else:
-        raise TestFailed("exception not propagated")
-
-def test_mutable_bases_catch_mro_conflict():
-    if verbose:
-        print("Testing mutable bases catch mro conflict...")
-    class A(object):
-        pass
-
-    class B(object):
-        pass
-
-    class C(A, B):
-        pass
-
-    class D(A, B):
-        pass
-
-    class E(C, D):
-        pass
-
-    try:
-        C.__bases__ = (B, A)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("didn't catch MRO conflict")
-
-def mutable_names():
-    if verbose:
-        print("Testing mutable names...")
-    class C(object):
-        pass
-
-    # C.__module__ could be 'test_descr' or '__main__'
-    mod = C.__module__
-
-    C.__name__ = 'D'
-    vereq((C.__module__, C.__name__), (mod, 'D'))
-
-    C.__name__ = 'D.E'
-    vereq((C.__module__, C.__name__), (mod, 'D.E'))
-
-def subclass_right_op():
-    if verbose:
-        print("Testing correct dispatch of subclass overloading __r<op>__...")
-
-    # This code tests various cases where right-dispatch of a subclass
-    # should be preferred over left-dispatch of a base class.
-
-    # Case 1: subclass of int; this tests code in abstract.c::binary_op1()
-
-    class B(int):
-        def __floordiv__(self, other):
-            return "B.__floordiv__"
-        def __rfloordiv__(self, other):
-            return "B.__rfloordiv__"
-
-    vereq(B(1) // 1, "B.__floordiv__")
-    vereq(1 // B(1), "B.__rfloordiv__")
-
-    # Case 2: subclass of object; this is just the baseline for case 3
-
-    class C(object):
-        def __floordiv__(self, other):
-            return "C.__floordiv__"
-        def __rfloordiv__(self, other):
-            return "C.__rfloordiv__"
-
-    vereq(C() // 1, "C.__floordiv__")
-    vereq(1 // C(), "C.__rfloordiv__")
-
-    # Case 3: subclass of new-style class; here it gets interesting
-
-    class D(C):
-        def __floordiv__(self, other):
-            return "D.__floordiv__"
-        def __rfloordiv__(self, other):
-            return "D.__rfloordiv__"
-
-    vereq(D() // C(), "D.__floordiv__")
-    vereq(C() // D(), "D.__rfloordiv__")
-
-    # Case 4: this didn't work right in 2.2.2 and 2.3a1
-
-    class E(C):
-        pass
-
-    vereq(E.__rfloordiv__, C.__rfloordiv__)
-
-    vereq(E() // 1, "C.__floordiv__")
-    vereq(1 // E(), "C.__rfloordiv__")
-    vereq(E() // C(), "C.__floordiv__")
-    vereq(C() // E(), "C.__floordiv__") # This one would fail
-
-def dict_type_with_metaclass():
-    if verbose:
-        print("Testing type of __dict__ when metaclass set...")
-
-    class B(object):
-        pass
-    class M(type):
-        pass
-    class C(metaclass=M):
-        # In 2.3a1, C.__dict__ was a real dict rather than a dict proxy
-        pass
-    veris(type(C.__dict__), type(B.__dict__))
-
-def meth_class_get():
-    # Full coverage of descrobject.c::classmethod_get()
-    if verbose:
-        print("Testing __get__ method of METH_CLASS C methods...")
-    # Baseline
-    arg = [1, 2, 3]
-    res = {1: None, 2: None, 3: None}
-    vereq(dict.fromkeys(arg), res)
-    vereq({}.fromkeys(arg), res)
-    # Now get the descriptor
-    descr = dict.__dict__["fromkeys"]
-    # More baseline using the descriptor directly
-    vereq(descr.__get__(None, dict)(arg), res)
-    vereq(descr.__get__({})(arg), res)
-    # Now check various error cases
-    try:
-        descr.__get__(None, None)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't have allowed descr.__get__(None, None)")
-    try:
-        descr.__get__(42)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't have allowed descr.__get__(42)")
-    try:
-        descr.__get__(None, 42)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't have allowed descr.__get__(None, 42)")
-    try:
-        descr.__get__(None, int)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't have allowed descr.__get__(None, int)")
-
-def isinst_isclass():
-    if verbose:
-        print("Testing proxy isinstance() and isclass()...")
-    class Proxy(object):
-        def __init__(self, obj):
-            self.__obj = obj
-        def __getattribute__(self, name):
-            if name.startswith("_Proxy__"):
-                return object.__getattribute__(self, name)
-            else:
-                return getattr(self.__obj, name)
-    # Test with a classic class
-    class C:
-        pass
-    a = C()
-    pa = Proxy(a)
-    verify(isinstance(a, C))  # Baseline
-    verify(isinstance(pa, C)) # Test
-    # Test with a classic subclass
-    class D(C):
-        pass
-    a = D()
-    pa = Proxy(a)
-    verify(isinstance(a, C))  # Baseline
-    verify(isinstance(pa, C)) # Test
-    # Test with a new-style class
-    class C(object):
-        pass
-    a = C()
-    pa = Proxy(a)
-    verify(isinstance(a, C))  # Baseline
-    verify(isinstance(pa, C)) # Test
-    # Test with a new-style subclass
-    class D(C):
-        pass
-    a = D()
-    pa = Proxy(a)
-    verify(isinstance(a, C))  # Baseline
-    verify(isinstance(pa, C)) # Test
-
-def proxysuper():
-    if verbose:
-        print("Testing super() for a proxy object...")
-    class Proxy(object):
-        def __init__(self, obj):
-            self.__obj = obj
-        def __getattribute__(self, name):
-            if name.startswith("_Proxy__"):
-                return object.__getattribute__(self, name)
+        self.assertEqual(c.attr, 1)
+        # this makes a crash more likely:
+        import gc; gc.collect()
+        self.assertEqual(hasattr(c, 'attr'), False)
+
+    def test_init(self):
+        # SF 1155938
+        class Foo(object):
+            def __init__(self):
+                return 10
+        try:
+            Foo()
+        except TypeError:
+            pass
+        else:
+            self.fail("did not test __init__() for None return")
+
+    def test_method_wrapper(self):
+        # Testing method-wrapper objects...
+        # <type 'method-wrapper'> did not support any reflection before 2.5
+
+        return # XXX should methods really support __eq__?
+
+        l = []
+        self.assertEqual(l.__add__, l.__add__)
+        self.assertEqual(l.__add__, [].__add__)
+        self.assert_(l.__add__ != [5].__add__)
+        self.assert_(l.__add__ != l.__mul__)
+        self.assert_(l.__add__.__name__ == '__add__')
+        self.assert_(l.__add__.__self__ is l)
+        self.assert_(l.__add__.__objclass__ is list)
+        self.assertEqual(l.__add__.__doc__, list.__add__.__doc__)
+        try:
+            hash(l.__add__)
+        except TypeError:
+            pass
+        else:
+            self.fail("no TypeError from hash([].__add__)")
+
+        t = ()
+        t += (7,)
+        self.assertEqual(t.__add__, (7,).__add__)
+        self.assertEqual(hash(t.__add__), hash((7,).__add__))
+
+    def test_not_implemented(self):
+        # Testing NotImplemented...
+        # all binary methods should be able to return a NotImplemented
+        import sys
+        import types
+        import operator
+
+        def specialmethod(self, other):
+            return NotImplemented
+
+        def check(expr, x, y):
+            try:
+                exec(expr, {'x': x, 'y': y, 'operator': operator})
+            except TypeError:
+                pass
             else:
-                return getattr(self.__obj, name)
+                self.fail("no TypeError from %r" % (expr,))
 
-    class B(object):
-        def f(self):
-            return "B.f"
-
-    class C(B):
-        def f(self):
-            return super(C, self).f() + "->C.f"
-
-    obj = C()
-    p = Proxy(obj)
-    vereq(C.__dict__["f"](p), "B.f->C.f")
-
-def carloverre():
-    if verbose:
-        print("Testing prohibition of Carlo Verre's hack...")
-    try:
-        object.__setattr__(str, "foo", 42)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("Carlo Verre __setattr__ suceeded!")
-    try:
-        object.__delattr__(str, "lower")
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("Carlo Verre __delattr__ succeeded!")
-
-def weakref_segfault():
-    # SF 742911
-    if verbose:
-        print("Testing weakref segfault...")
-
-    import weakref
-
-    class Provoker:
-        def __init__(self, referrent):
-            self.ref = weakref.ref(referrent)
-
-        def __del__(self):
-            x = self.ref()
-
-    class Oops(object):
-        pass
-
-    o = Oops()
-    o.whatever = Provoker(o)
-    del o
-
-def wrapper_segfault():
-    # SF 927248: deeply nested wrappers could cause stack overflow
-    if verbose:
-        print("Testing wrapper segfault...")
-    f = lambda:None
-    for i in range(1000000):
-        f = f.__call__
-    f = None
-
-# Fix SF #762455, segfault when sys.stdout is changed in getattr
-def filefault():
-    if verbose:
-        print("Testing sys.stdout is changed in getattr...")
-    import sys
-    class StdoutGuard:
-        def __getattr__(self, attr):
-            sys.stdout = sys.__stdout__
-            raise RuntimeError("Premature access to sys.stdout.%s" % attr)
-    sys.stdout = StdoutGuard()
-    try:
-        print("Oops!")
-    except RuntimeError:
-        pass
-
-def vicious_descriptor_nonsense():
-    # A potential segfault spotted by Thomas Wouters in mail to
-    # python-dev 2003-04-17, turned into an example & fixed by Michael
-    # Hudson just less than four months later...
-    if verbose:
-        print("Testing vicious_descriptor_nonsense...")
-
-    class Evil(object):
-        def __hash__(self):
-            return hash('attr')
-        def __eq__(self, other):
-            del C.attr
-            return 0
-
-    class Descr(object):
-        def __get__(self, ob, type=None):
-            return 1
-
-    class C(object):
-        attr = Descr()
-
-    c = C()
-    c.__dict__[Evil()] = 0
-
-    vereq(c.attr, 1)
-    # this makes a crash more likely:
-    import gc; gc.collect()
-    vereq(hasattr(c, 'attr'), False)
-
-def test_init():
-    # SF 1155938
-    class Foo(object):
-        def __init__(self):
-            return 10
-    try:
-        Foo()
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("did not test __init__() for None return")
-
-def methodwrapper():
-    # <type 'method-wrapper'> did not support any reflection before 2.5
-    if verbose:
-        print("Testing method-wrapper objects...")
-
-    return # XXX should methods really support __eq__?
-
-    l = []
-    vereq(l.__add__, l.__add__)
-    vereq(l.__add__, [].__add__)
-    verify(l.__add__ != [5].__add__)
-    verify(l.__add__ != l.__mul__)
-    verify(l.__add__.__name__ == '__add__')
-    verify(l.__add__.__self__ is l)
-    verify(l.__add__.__objclass__ is list)
-    vereq(l.__add__.__doc__, list.__add__.__doc__)
-    try:
-        hash(l.__add__)
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("no TypeError from hash([].__add__)")
-
-    t = ()
-    t += (7,)
-    vereq(t.__add__, (7,).__add__)
-    vereq(hash(t.__add__), hash((7,).__add__))
-
-def notimplemented():
-    # all binary methods should be able to return a NotImplemented
-    if verbose:
-        print("Testing NotImplemented...")
-
-    import sys
-    import types
-    import operator
-
-    def specialmethod(self, other):
-        return NotImplemented
-
-    def check(expr, x, y):
-        try:
-            exec(expr, {'x': x, 'y': y, 'operator': operator})
-        except TypeError:
-            pass
-        else:
-            raise TestFailed("no TypeError from %r" % (expr,))
-
-    N1 = sys.maxint + 1    # might trigger OverflowErrors instead of TypeErrors
-    N2 = sys.maxint         # if sizeof(int) < sizeof(long), might trigger
-                            #   ValueErrors instead of TypeErrors
-    if 1:
-        metaclass = type
+        N1 = sys.maxsize + 1    # might trigger OverflowErrors instead of
+                                # TypeErrors
+        N2 = sys.maxsize         # if sizeof(int) < sizeof(long), might trigger
+                                #   ValueErrors instead of TypeErrors
         for name, expr, iexpr in [
                 ('__add__',      'x + y',                   'x += y'),
                 ('__sub__',      'x - y',                   'x -= y'),
                 ('__mul__',      'x * y',                   'x *= y'),
-                ('__truediv__',  'x / y',                   None),
-                ('__floordiv__', 'x // y',                  None),
+                ('__truediv__',  'operator.truediv(x, y)',  None),
+                ('__floordiv__', 'operator.floordiv(x, y)', None),
+                ('__div__',      'x / y',                   'x /= y'),
                 ('__mod__',      'x % y',                   'x %= y'),
                 ('__divmod__',   'divmod(x, y)',            None),
                 ('__pow__',      'x ** y',                  'x **= y'),
@@ -4080,147 +3999,102 @@
                 ('__rshift__',   'x >> y',                  'x >>= y'),
                 ('__and__',      'x & y',                   'x &= y'),
                 ('__or__',       'x | y',                   'x |= y'),
-                ('__xor__',      'x ^ y',                   'x ^= y'),
-                ]:
+                ('__xor__',      'x ^ y',                   'x ^= y')]:
             rname = '__r' + name[2:]
-            A = metaclass('A', (), {name: specialmethod})
-            B = metaclass('B', (), {rname: specialmethod})
+            A = type('A', (), {name: specialmethod})
             a = A()
-            b = B()
             check(expr, a, a)
-            check(expr, a, b)
-            check(expr, b, a)
-            check(expr, b, b)
             check(expr, a, N1)
             check(expr, a, N2)
-            check(expr, N1, b)
-            check(expr, N2, b)
             if iexpr:
                 check(iexpr, a, a)
-                check(iexpr, a, b)
-                check(iexpr, b, a)
-                check(iexpr, b, b)
                 check(iexpr, a, N1)
                 check(iexpr, a, N2)
                 iname = '__i' + name[2:]
-                C = metaclass('C', (), {iname: specialmethod})
+                C = type('C', (), {iname: specialmethod})
                 c = C()
                 check(iexpr, c, a)
-                check(iexpr, c, b)
                 check(iexpr, c, N1)
                 check(iexpr, c, N2)
 
-def test_assign_slice():
-    # ceval.c's assign_slice used to check for
-    # tp->tp_as_sequence->sq_slice instead of
-    # tp->tp_as_sequence->sq_ass_slice
-
-    class C(object):
-        def __setitem__(self, idx, value):
-            self.value = value
-
-    c = C()
-    c[1:2] = 3
-    vereq(c.value, 3)
+    def test_assign_slice(self):
+        # ceval.c's assign_slice used to check for
+        # tp->tp_as_sequence->sq_slice instead of
+        # tp->tp_as_sequence->sq_ass_slice
 
-def test_main():
-    weakref_segfault() # Must be first, somehow
-    wrapper_segfault() # NB This one is slow
-    do_this_first()
-    class_docstrings()
-    lists()
-    dicts()
-    dict_constructor()
-    test_dir()
-    ints()
-    longs()
-    floats()
-    complexes()
-    spamlists()
-    spamdicts()
-    pydicts()
-    pylists()
-    metaclass()
-    pymods()
-    multi()
-    mro_disagreement()
-    diamond()
-    ex5()
-    monotonicity()
-    consistency_with_epg()
-    objects()
-    slots()
-    slotspecials()
-    dynamics()
-    errors()
-    classmethods()
-    classmethods_in_c()
-    staticmethods()
-    staticmethods_in_c()
-    classic()
-    compattr()
-    newslot()
-    altmro()
-    overloading()
-    methods()
-    specials()
-    recursions()
-    weakrefs()
-    properties()
-    supers()
-    inherits()
-    keywords()
-    str_subclass_as_dict_key()
-    classic_comparisons()
-    rich_comparisons()
-    descrdoc()
-    setclass()
-    setdict()
-    pickles()
-    copies()
-    binopoverride()
-    subclasspropagation()
-    buffer_inherit()
-    str_of_str_subclass()
-    kwdargs()
-    recursive__call__()
-    delhook()
-    hashinherit()
-    strops()
-    deepcopyrecursive()
-    modules()
-    dictproxyiterkeys()
-    dictproxyitervalues()
-    dictproxyiteritems()
-    pickleslots()
-    funnynew()
-    imulbug()
-    docdescriptor()
-    copy_setstate()
-    slices()
-    subtype_resurrection()
-    slottrash()
-    slotmultipleinheritance()
-    testrmul()
-    testipow()
-    test_mutable_bases()
-    test_mutable_bases_with_failing_mro()
-    test_mutable_bases_catch_mro_conflict()
-    mutable_names()
-    subclass_right_op()
-    dict_type_with_metaclass()
-    meth_class_get()
-    isinst_isclass()
-    proxysuper()
-    carloverre()
-    filefault()
-    vicious_descriptor_nonsense()
-    test_init()
-    methodwrapper()
-    notimplemented()
-    test_assign_slice()
+        class C(object):
+            def __setitem__(self, idx, value):
+                self.value = value
+
+        c = C()
+        c[1:2] = 3
+        self.assertEqual(c.value, 3)
 
-    if verbose: print("All OK")
+
+class DictProxyTests(unittest.TestCase):
+    def setUp(self):
+        class C(object):
+            def meth(self):
+                pass
+        self.C = C
+
+    def test_iter_keys(self):
+        # Testing dict-proxy iterkeys...
+        keys = [ key for key in self.C.__dict__.keys() ]
+        keys.sort()
+        self.assertEquals(keys, ['__dict__', '__doc__', '__module__',
+            '__weakref__', 'meth'])
+
+    def test_iter_values(self):
+        # Testing dict-proxy itervalues...
+        values = [ values for values in self.C.__dict__.values() ]
+        self.assertEqual(len(values), 5)
+
+    def test_iter_items(self):
+        # Testing dict-proxy iteritems...
+        keys = [ key for (key, value) in self.C.__dict__.items() ]
+        keys.sort()
+        self.assertEqual(keys, ['__dict__', '__doc__', '__module__',
+            '__weakref__', 'meth'])
+
+    def test_dict_type_with_metaclass(self):
+        # Testing type of __dict__ when metaclass set...
+        class B(object):
+            pass
+        class M(type):
+            pass
+        class C(metaclass=M):
+            # In 2.3a1, C.__dict__ was a real dict rather than a dict proxy
+            pass
+        self.assertEqual(type(C.__dict__), type(B.__dict__))
+
+
+class PTypesLongInitTest(unittest.TestCase):
+    # This is in its own TestCase so that it can be run before any other tests.
+    def test_pytype_long_ready(self):
+        # Testing SF bug 551412 ...
+
+        # This dumps core when SF bug 551412 isn't fixed --
+        # but only when test_descr.py is run separately.
+        # (That can't be helped -- as soon as PyType_Ready()
+        # is called for PyLong_Type, the bug is gone.)
+        class UserLong(object):
+            def __pow__(self, *args):
+                pass
+        try:
+            pow(0, UserLong(), 0)
+        except:
+            pass
+
+        # Another segfault only when run early
+        # (before PyType_Ready(tuple) is called)
+        type.mro(tuple)
+
+
+def test_main():
+    # Run all local test cases, with PTypesLongInitTest first.
+    test_support.run_unittest(PTypesLongInitTest, OperatorsTest,
+                              ClassPropertiesAndMethods, DictProxyTests)
 
 if __name__ == "__main__":
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_descrtut.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_descrtut.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_descrtut.py	Thu Mar 27 00:48:05 2008
@@ -196,6 +196,7 @@
      '__setattr__',
      '__setitem__',
      '__str__',
+     '__subclasshook__',
      'append',
      'count',
      'extend',
@@ -444,9 +445,7 @@
 ...         B.foo(self)
 
 >>> C().foo()
-Traceback (most recent call last):
- ...
-TypeError: unbound method foo() must be called with B instance as first argument (got C instance instead)
+called A.foo()
 
 >>> class C(A):
 ...     def foo(self):

Modified: python/branches/py3k-importlib/Lib/test/test_dict.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_dict.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_dict.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,7 @@
 import unittest
 from test import test_support
 
-import sys, UserDict
+import sys, collections, random, string
 
 
 class DictTest(unittest.TestCase):
@@ -11,6 +11,17 @@
         self.assertEqual(dict(), {})
         self.assert_(dict() is not {})
 
+    def test_literal_constructor(self):
+        # check literal constructor for different sized dicts (to exercise the BUILD_MAP oparg
+        for n in (0, 1, 6, 256, 400):
+            items = [(''.join([random.choice(string.ascii_letters)
+                               for j in range(8)]),
+                      i)
+                     for i in range(n)]
+            random.shuffle(items)
+            dictliteral = '{' + ', '.join('%r: %d' % item for item in items) + '}'
+            self.assertEqual(eval(dictliteral), dict(items))
+
     def test_bool(self):
         self.assert_(not {})
         self.assert_({1: 2})
@@ -182,14 +193,6 @@
 
         self.assertRaises(ValueError, {}.update, [(1, 2, 3)])
 
-        # SF #1615701:  make d.update(m) honor __getitem__() and keys() in dict subclasses
-        class KeyUpperDict(dict):
-            def __getitem__(self, key):
-                return key.upper()
-        d.clear()
-        d.update(KeyUpperDict.fromkeys('abc'))
-        self.assertEqual(d, {'a':'A', 'b':'B', 'c':'C'})
-
     def test_fromkeys(self):
         self.assertEqual(dict.fromkeys('abc'), {'a':None, 'b':None, 'c':None})
         d = {}
@@ -208,10 +211,10 @@
         self.assert_(type(dictlike().fromkeys('a')) is dictlike)
         class mydict(dict):
             def __new__(cls):
-                return UserDict.UserDict()
+                return collections.UserDict()
         ud = mydict.fromkeys('ab')
         self.assertEqual(ud, {'a':None, 'b':None})
-        self.assert_(isinstance(ud, UserDict.UserDict))
+        self.assert_(isinstance(ud, collections.UserDict))
         self.assertRaises(TypeError, dict.fromkeys)
 
         class Exc(Exception): pass
@@ -236,6 +239,10 @@
 
         self.assertRaises(Exc, baddict2.fromkeys, [1])
 
+        # test fast path for dictionary inputs
+        d = dict(zip(range(6), range(6)))
+        self.assertEqual(dict.fromkeys(d, 0), dict(zip(range(6), [0]*6)))
+
     def test_copy(self):
         d = {1:1, 2:2, 3:3}
         self.assertEqual(d.copy(), {1:1, 2:2, 3:3})

Modified: python/branches/py3k-importlib/Lib/test/test_dis.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_dis.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_dis.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,6 @@
 # Minimal tests for dis module
 
-from test.test_support import verbose, run_unittest
+from test.test_support import run_unittest
 import unittest
 import sys
 import dis

Modified: python/branches/py3k-importlib/Lib/test/test_doctest.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_doctest.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_doctest.py	Thu Mar 27 00:48:05 2008
@@ -448,8 +448,8 @@
 functions, classes, and the `__test__` dictionary, if it exists:
 
     >>> # A module
-    >>> import new
-    >>> m = new.module('some_module')
+    >>> import types
+    >>> m = types.ModuleType('some_module')
     >>> def triple(val):
     ...     '''
     ...     >>> print(triple(11))
@@ -658,7 +658,7 @@
 of tried tests.
 
     >>> doctest.DocTestRunner(verbose=False).run(test)
-    (0, 3)
+    TestResults(failed=0, attempted=3)
 
 If any example produces incorrect output, then the test runner reports
 the failure and proceeds to the next example:
@@ -695,7 +695,7 @@
     Expecting:
         6
     ok
-    (1, 3)
+    TestResults(failed=1, attempted=3)
 """
     def verbose_flag(): r"""
 The `verbose` flag makes the test runner generate more detailed
@@ -726,7 +726,7 @@
     Expecting:
         6
     ok
-    (0, 3)
+    TestResults(failed=0, attempted=3)
 
 If the `verbose` flag is unspecified, then the output will be verbose
 iff `-v` appears in sys.argv:
@@ -737,7 +737,7 @@
     >>> # If -v does not appear in sys.argv, then output isn't verbose.
     >>> sys.argv = ['test']
     >>> doctest.DocTestRunner().run(test)
-    (0, 3)
+    TestResults(failed=0, attempted=3)
 
     >>> # If -v does appear in sys.argv, then output is verbose.
     >>> sys.argv = ['test', '-v']
@@ -756,7 +756,7 @@
     Expecting:
         6
     ok
-    (0, 3)
+    TestResults(failed=0, attempted=3)
 
     >>> # Restore sys.argv
     >>> sys.argv = old_argv
@@ -780,7 +780,7 @@
     ...     '''
     >>> test = doctest.DocTestFinder().find(f)[0]
     >>> doctest.DocTestRunner(verbose=False).run(test)
-    (0, 2)
+    TestResults(failed=0, attempted=2)
 
 An example may not generate output before it raises an exception; if
 it does, then the traceback message will not be recognized as
@@ -805,7 +805,7 @@
     Exception raised:
         ...
         ZeroDivisionError: integer division or modulo by zero
-    (1, 2)
+    TestResults(failed=1, attempted=2)
 
 Exception messages may contain newlines:
 
@@ -819,7 +819,7 @@
     ...     '''
     >>> test = doctest.DocTestFinder().find(f)[0]
     >>> doctest.DocTestRunner(verbose=False).run(test)
-    (0, 1)
+    TestResults(failed=0, attempted=1)
 
 If an exception is expected, but an exception with the wrong type or
 message is raised, then it is reported as a failure:
@@ -844,7 +844,7 @@
         Traceback (most recent call last):
         ...
         ValueError: message
-    (1, 1)
+    TestResults(failed=1, attempted=1)
 
 However, IGNORE_EXCEPTION_DETAIL can be used to allow a mismatch in the
 detail:
@@ -857,7 +857,7 @@
     ...     '''
     >>> test = doctest.DocTestFinder().find(f)[0]
     >>> doctest.DocTestRunner(verbose=False).run(test)
-    (0, 1)
+    TestResults(failed=0, attempted=1)
 
 But IGNORE_EXCEPTION_DETAIL does not allow a mismatch in the exception type:
 
@@ -881,7 +881,7 @@
         Traceback (most recent call last):
         ...
         ValueError: message
-    (1, 1)
+    TestResults(failed=1, attempted=1)
 
 If an exception is raised but not expected, then it is reported as an
 unexpected exception:
@@ -902,14 +902,14 @@
         Traceback (most recent call last):
         ...
         ZeroDivisionError: integer division or modulo by zero
-    (1, 1)
+    TestResults(failed=1, attempted=1)
 """
     def optionflags(): r"""
 Tests of `DocTestRunner`'s option flag handling.
 
 Several option flags can be used to customize the behavior of the test
 runner.  These are defined as module constants in doctest, and passed
-to the DocTestRunner constructor (multiple constants should be or-ed
+to the DocTestRunner constructor (multiple constants should be ORed
 together).
 
 The DONT_ACCEPT_TRUE_FOR_1 flag disables matches between True/False
@@ -921,7 +921,7 @@
     >>> # Without the flag:
     >>> test = doctest.DocTestFinder().find(f)[0]
     >>> doctest.DocTestRunner(verbose=False).run(test)
-    (0, 1)
+    TestResults(failed=0, attempted=1)
 
     >>> # With the flag:
     >>> test = doctest.DocTestFinder().find(f)[0]
@@ -936,7 +936,7 @@
         1
     Got:
         True
-    (1, 1)
+    TestResults(failed=1, attempted=1)
 
 The DONT_ACCEPT_BLANKLINE flag disables the match between blank lines
 and the '<BLANKLINE>' marker:
@@ -947,7 +947,7 @@
     >>> # Without the flag:
     >>> test = doctest.DocTestFinder().find(f)[0]
     >>> doctest.DocTestRunner(verbose=False).run(test)
-    (0, 1)
+    TestResults(failed=0, attempted=1)
 
     >>> # With the flag:
     >>> test = doctest.DocTestFinder().find(f)[0]
@@ -966,7 +966,7 @@
         a
     <BLANKLINE>
         b
-    (1, 1)
+    TestResults(failed=1, attempted=1)
 
 The NORMALIZE_WHITESPACE flag causes all sequences of whitespace to be
 treated as equal:
@@ -987,13 +987,13 @@
          3
     Got:
         1 2 3
-    (1, 1)
+    TestResults(failed=1, attempted=1)
 
     >>> # With the flag:
     >>> test = doctest.DocTestFinder().find(f)[0]
     >>> flags = doctest.NORMALIZE_WHITESPACE
     >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test)
-    (0, 1)
+    TestResults(failed=0, attempted=1)
 
     An example from the docs:
     >>> print(list(range(20))) #doctest: +NORMALIZE_WHITESPACE
@@ -1018,13 +1018,13 @@
         [0, 1, 2, ..., 14]
     Got:
         [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
-    (1, 1)
+    TestResults(failed=1, attempted=1)
 
     >>> # With the flag:
     >>> test = doctest.DocTestFinder().find(f)[0]
     >>> flags = doctest.ELLIPSIS
     >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test)
-    (0, 1)
+    TestResults(failed=0, attempted=1)
 
     ... also matches nothing:
 
@@ -1109,7 +1109,7 @@
         e
         f
         g
-    (1, 1)
+    TestResults(failed=1, attempted=1)
 
     >>> # With the flag:
     >>> test = doctest.DocTestFinder().find(f)[0]
@@ -1131,7 +1131,7 @@
          f
          g
         -h
-    (1, 1)
+    TestResults(failed=1, attempted=1)
 
 The REPORT_CDIFF flag causes failures that involve multi-line expected
 and actual outputs to be displayed using a context diff:
@@ -1163,7 +1163,7 @@
         + e
           f
           g
-    (1, 1)
+    TestResults(failed=1, attempted=1)
 
 
 The REPORT_NDIFF flag causes failures to use the difflib.Differ algorithm
@@ -1188,7 +1188,7 @@
         ?                       ^
         + a b  c d e f g h i   j k l m
         ?     +              ++    ^
-    (1, 1)
+    TestResults(failed=1, attempted=1)
 
 The REPORT_ONLY_FIRST_FAILURE supresses result output after the first
 failing example:
@@ -1218,7 +1218,7 @@
         200
     Got:
         2
-    (3, 5)
+    TestResults(failed=3, attempted=5)
 
 However, output from `report_start` is not supressed:
 
@@ -1241,7 +1241,7 @@
         200
     Got:
         2
-    (3, 5)
+    TestResults(failed=3, attempted=5)
 
 For the purposes of REPORT_ONLY_FIRST_FAILURE, unexpected exceptions
 count as failures:
@@ -1270,7 +1270,7 @@
     Exception raised:
         ...
         ValueError: 2
-    (3, 5)
+    TestResults(failed=3, attempted=5)
 
 New option flags can also be registered, via register_optionflag().  Here
 we reach into doctest's internals a bit.
@@ -1319,7 +1319,7 @@
         [0, 1, ..., 9]
     Got:
         [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
-    (1, 2)
+    TestResults(failed=1, attempted=2)
 
 To turn an option off for an example, follow that example with a
 comment of the form ``# doctest: -OPTION``:
@@ -1344,7 +1344,7 @@
         [0, 1, ..., 9]
     Got:
         [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
-    (1, 2)
+    TestResults(failed=1, attempted=2)
 
 Option directives affect only the example that they appear with; they
 do not change the options for surrounding examples:
@@ -1378,7 +1378,7 @@
         [0, 1, ..., 9]
     Got:
         [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
-    (2, 3)
+    TestResults(failed=2, attempted=3)
 
 Multiple options may be modified by a single option directive.  They
 may be separated by whitespace, commas, or both:
@@ -1401,7 +1401,7 @@
         [0, 1,  ...,   9]
     Got:
         [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
-    (1, 2)
+    TestResults(failed=1, attempted=2)
 
     >>> def f(x): r'''
     ...     >>> print(list(range(10)))      # Should fail
@@ -1421,7 +1421,7 @@
         [0, 1,  ...,   9]
     Got:
         [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
-    (1, 2)
+    TestResults(failed=1, attempted=2)
 
     >>> def f(x): r'''
     ...     >>> print(list(range(10)))      # Should fail
@@ -1441,7 +1441,7 @@
         [0, 1,  ...,   9]
     Got:
         [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
-    (1, 2)
+    TestResults(failed=1, attempted=2)
 
 The option directive may be put on the line following the source, as
 long as a continuation prompt is used:
@@ -1453,7 +1453,7 @@
     ...     '''
     >>> test = doctest.DocTestFinder().find(f)[0]
     >>> doctest.DocTestRunner(verbose=False).run(test)
-    (0, 1)
+    TestResults(failed=0, attempted=1)
 
 For examples with multi-line source, the option directive may appear
 at the end of any line:
@@ -1469,7 +1469,7 @@
     ...     '''
     >>> test = doctest.DocTestFinder().find(f)[0]
     >>> doctest.DocTestRunner(verbose=False).run(test)
-    (0, 2)
+    TestResults(failed=0, attempted=2)
 
 If more than one line of an example with multi-line source has an
 option directive, then they are combined:
@@ -1482,7 +1482,7 @@
     ...     '''
     >>> test = doctest.DocTestFinder().find(f)[0]
     >>> doctest.DocTestRunner(verbose=False).run(test)
-    (0, 1)
+    TestResults(failed=0, attempted=1)
 
 It is an error to have a comment of the form ``# doctest:`` that is
 *not* followed by words of the form ``+OPTION`` or ``-OPTION``, where
@@ -1616,7 +1616,7 @@
       (Pdb) print(x)
       42
       (Pdb) continue
-      (0, 2)
+      TestResults(failed=0, attempted=2)
 
       You can also put pdb.set_trace in a function called from a test:
 
@@ -1652,7 +1652,7 @@
       (Pdb) print(x)
       1
       (Pdb) continue
-      (0, 2)
+      TestResults(failed=0, attempted=2)
 
     During interactive debugging, source code is shown, even for
     doctest examples:
@@ -1709,7 +1709,7 @@
       Expected nothing
       Got:
           9
-      (1, 3)
+      TestResults(failed=1, attempted=3)
       """
 
 def test_pdb_set_trace_nested():
@@ -1795,7 +1795,7 @@
     (Pdb) print(foo)
     *** NameError: NameError("name 'foo' is not defined",)
     (Pdb) continue
-    (0, 2)
+    TestResults(failed=0, attempted=2)
 """
 
 def test_DocTestSuite():
@@ -1912,6 +1912,25 @@
          >>> suite.run(unittest.TestResult())
          <unittest.TestResult run=3 errors=0 failures=2>
 
+       Support for using a package's __loader__.get_data() is also
+       provided.
+
+         >>> import unittest, pkgutil, test
+         >>> added_loader = False
+         >>> if not hasattr(test, '__loader__'):
+         ...     test.__loader__ = pkgutil.get_loader(test)
+         ...     added_loader = True
+         >>> try:
+         ...     suite = doctest.DocFileSuite('test_doctest.txt',
+         ...                                  'test_doctest2.txt',
+         ...                                  'test_doctest4.txt',
+         ...                                  package='test')
+         ...     suite.run(unittest.TestResult())
+         ... finally:
+         ...     if added_loader:
+         ...         del test.__loader__
+         <unittest.TestResult run=3 errors=0 failures=2>
+
        '/' should be used as a path separator.  It will be converted
        to a native separator at run time:
 
@@ -1922,11 +1941,11 @@
        If DocFileSuite is used from an interactive session, then files
        are resolved relative to the directory of sys.argv[0]:
 
-         >>> import new, os.path, test.test_doctest
+         >>> import types, os.path, test.test_doctest
          >>> save_argv = sys.argv
          >>> sys.argv = [test.test_doctest.__file__]
          >>> suite = doctest.DocFileSuite('test_doctest.txt',
-         ...                              package=new.module('__main__'))
+         ...                              package=types.ModuleType('__main__'))
          >>> sys.argv = save_argv
 
        By setting `module_relative=False`, os-specific paths may be
@@ -1973,8 +1992,6 @@
 
        And, you can provide setUp and tearDown functions:
 
-       You can supply setUp and teatDoen functions:
-
          >>> def setUp(t):
          ...     import test.test_doctest
          ...     test.test_doctest.sillySetup = True
@@ -2139,7 +2156,7 @@
     1 items had failures:
        1 of   2 in test_doctest.txt
     ***Test Failed*** 1 failures.
-    (1, 2)
+    TestResults(failed=1, attempted=2)
     >>> doctest.master = None  # Reset master.
 
 (Note: we'll be clearing doctest.master after each call to
@@ -2150,7 +2167,7 @@
 
     >>> globs = {'favorite_color': 'blue'}
     >>> doctest.testfile('test_doctest.txt', globs=globs)
-    (0, 2)
+    TestResults(failed=0, attempted=2)
     >>> doctest.master = None  # Reset master.
 
     >>> extraglobs = {'favorite_color': 'red'}
@@ -2168,7 +2185,7 @@
     1 items had failures:
        1 of   2 in test_doctest.txt
     ***Test Failed*** 1 failures.
-    (1, 2)
+    TestResults(failed=1, attempted=2)
     >>> doctest.master = None  # Reset master.
 
 The file may be made relative to a given module or package, using the
@@ -2176,7 +2193,7 @@
 
     >>> doctest.testfile('test_doctest.txt', globs=globs,
     ...                  module_relative='test')
-    (0, 2)
+    TestResults(failed=0, attempted=2)
     >>> doctest.master = None  # Reset master.
 
 Verbosity can be increased with the optional `verbose` paremter:
@@ -2202,7 +2219,7 @@
     2 tests in 1 items.
     2 passed and 0 failed.
     Test passed.
-    (0, 2)
+    TestResults(failed=0, attempted=2)
     >>> doctest.master = None  # Reset master.
 
 The name of the test may be specified with the optional `name`
@@ -2213,7 +2230,7 @@
     **********************************************************************
     File "...", line 6, in newname
     ...
-    (1, 2)
+    TestResults(failed=1, attempted=2)
     >>> doctest.master = None  # Reset master.
 
 The summary report may be supressed with the optional `report`
@@ -2228,7 +2245,7 @@
     Exception raised:
         ...
         NameError: name 'favorite_color' is not defined
-    (1, 2)
+    TestResults(failed=1, attempted=2)
     >>> doctest.master = None  # Reset master.
 
 The optional keyword argument `raise_on_error` can be used to raise an
@@ -2260,11 +2277,11 @@
     1 items had failures:
        2 of   2 in test_doctest4.txt
     ***Test Failed*** 2 failures.
-    (2, 2)
+    TestResults(failed=2, attempted=2)
     >>> doctest.master = None  # Reset master.
 
     >>> doctest.testfile('test_doctest4.txt', encoding='utf-8')
-    (0, 2)
+    TestResults(failed=0, attempted=2)
     >>> doctest.master = None  # Reset master.
 """
 
@@ -2294,15 +2311,15 @@
     42
 Got:
     84
-(1, 2)
+TestResults(failed=1, attempted=2)
 >>> t.runstring(">>> x = x * 2\n>>> print(x)\n84\n", 'example2')
-(0, 2)
+TestResults(failed=0, attempted=2)
 >>> t.summarize()
 **********************************************************************
 1 items had failures:
    1 of   2 in XYZ
 ***Test Failed*** 1 failures.
-(1, 4)
+TestResults(failed=1, attempted=4)
 >>> t.summarize(verbose=1)
 1 items passed all tests:
    2 tests in example2
@@ -2312,7 +2329,7 @@
 4 tests in 2 items.
 3 passed and 1 failed.
 ***Test Failed*** 1 failures.
-(1, 4)
+TestResults(failed=1, attempted=4)
 """
 
 def old_test2(): r"""
@@ -2336,7 +2353,7 @@
             3
         ok
         0 of 2 examples failed in string Example
-        (0, 2)
+        TestResults(failed=0, attempted=2)
 """
 
 def old_test3(): r"""
@@ -2349,13 +2366,13 @@
         ...     return 32
         ...
         >>> t.rundoc(_f)  # expect 0 failures in 1 example
-        (0, 1)
+        TestResults(failed=0, attempted=1)
 """
 
 def old_test4(): """
-        >>> import new
-        >>> m1 = new.module('_m1')
-        >>> m2 = new.module('_m2')
+        >>> import types
+        >>> m1 = types.ModuleType('_m1')
+        >>> m2 = types.ModuleType('_m2')
         >>> test_data = \"""
         ... def _f():
         ...     '''>>> assert 1 == 1
@@ -2379,19 +2396,19 @@
         >>> from doctest import Tester
         >>> t = Tester(globs={}, verbose=0)
         >>> t.rundict(m1.__dict__, "rundict_test", m1)  # f2 and g2 and h2 skipped
-        (0, 4)
+        TestResults(failed=0, attempted=4)
 
         Once more, not excluding stuff outside m1:
 
         >>> t = Tester(globs={}, verbose=0)
         >>> t.rundict(m1.__dict__, "rundict_test_pvt")  # None are skipped.
-        (0, 8)
+        TestResults(failed=0, attempted=8)
 
         The exclusion of objects from outside the designated module is
         meant to be invoked automagically by testmod.
 
         >>> doctest.testmod(m1, verbose=False)
-        (0, 4)
+        TestResults(failed=0, attempted=4)
 """
 
 ######################################################################

Modified: python/branches/py3k-importlib/Lib/test/test_dumbdbm.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_dumbdbm.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_dumbdbm.py	Thu Mar 27 00:48:05 2008
@@ -113,9 +113,12 @@
         f[b'2'] = b'hello2'
         f.close()
 
-        # Mangle the file by adding \r before each newline
+        # Mangle the file by changing the line separator to Windows or Unix
         data = io.open(_fname + '.dir', 'rb').read()
-        data = data.replace(b'\n', b'\r\n')
+        if os.linesep == '\n':
+            data = data.replace(b'\n', b'\r\n')
+        else:
+            data = data.replace(b'\r\n', b'\n')
         io.open(_fname + '.dir', 'wb').write(data)
 
         f = dumbdbm.open(_fname)

Modified: python/branches/py3k-importlib/Lib/test/test_dummy_threading.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_dummy_threading.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_dummy_threading.py	Thu Mar 27 00:48:05 2008
@@ -1,72 +1,63 @@
-# Very rudimentary test of threading module
-
-# Create a bunch of threads, let each do some work, wait until all are done
-
-from test.test_support import verbose
-import random
+from test import test_support
+import unittest
 import dummy_threading as _threading
 import time
 
+class DummyThreadingTestCase(unittest.TestCase):
 
-class TestThread(_threading.Thread):
+    class TestThread(_threading.Thread):
 
-    def run(self):
+        def run(self):
+            global running
+            global sema
+            global mutex
+            # Uncomment if testing another module, such as the real 'threading'
+            # module.
+            #delay = random.random() * 2
+            delay = 0
+            if test_support.verbose:
+                print('task', self.getName(), 'will run for', delay, 'sec')
+            sema.acquire()
+            mutex.acquire()
+            running += 1
+            if test_support.verbose:
+                print(running, 'tasks are running')
+            mutex.release()
+            time.sleep(delay)
+            if test_support.verbose:
+                print('task', self.getName(), 'done')
+            mutex.acquire()
+            running -= 1
+            if test_support.verbose:
+                print(self.getName(), 'is finished.', running, 'tasks are running')
+            mutex.release()
+            sema.release()
+
+    def setUp(self):
+        self.numtasks = 10
+        global sema
+        sema = _threading.BoundedSemaphore(value=3)
+        global mutex
+        mutex = _threading.RLock()
         global running
-        # Uncomment if testing another module, such as the real 'threading'
-        # module.
-        #delay = random.random() * 2
-        delay = 0
-        if verbose:
-            print('task', self.getName(), 'will run for', delay, 'sec')
-        sema.acquire()
-        mutex.acquire()
-        running = running + 1
-        if verbose:
-            print(running, 'tasks are running')
-        mutex.release()
-        time.sleep(delay)
-        if verbose:
-            print('task', self.getName(), 'done')
-        mutex.acquire()
-        running = running - 1
-        if verbose:
-            print(self.getName(), 'is finished.', running, 'tasks are running')
-        mutex.release()
-        sema.release()
-
-def starttasks():
-    for i in range(numtasks):
-        t = TestThread(name="<thread %d>"%i)
-        threads.append(t)
-        t.start()
+        running = 0
+        self.threads = []
 
+    def test_tasks(self):
+        for i in range(self.numtasks):
+            t = self.TestThread(name="<thread %d>"%i)
+            self.threads.append(t)
+            t.start()
+
+        if test_support.verbose:
+            print('waiting for all tasks to complete')
+        for t in self.threads:
+            t.join()
+        if test_support.verbose:
+            print('all tasks done')
 
 def test_main():
-    # This takes about n/3 seconds to run (about n/3 clumps of tasks, times
-    # about 1 second per clump).
-    global numtasks
-    numtasks = 10
-
-    # no more than 3 of the 10 can run at once
-    global sema
-    sema = _threading.BoundedSemaphore(value=3)
-    global mutex
-    mutex = _threading.RLock()
-    global running
-    running = 0
-
-    global threads
-    threads = []
-
-    starttasks()
-
-    if verbose:
-        print('waiting for all tasks to complete')
-    for t in threads:
-        t.join()
-    if verbose:
-        print('all tasks done')
-
+    test_support.run_unittest(DummyThreadingTestCase)
 
 
 if __name__ == '__main__':

Modified: python/branches/py3k-importlib/Lib/test/test_email.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_email.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_email.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Copyright (C) 2001-2007 Python Software Foundation
 # email package unit tests
 
-import unittest
 # The specific tests now live in Lib/email/test
 from email.test.test_email import suite
 from test import test_support

Modified: python/branches/py3k-importlib/Lib/test/test_eof.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_eof.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_eof.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 #! /usr/bin/env python
 """test script for a few new invalid token catches"""
 
-import os
 import unittest
 from test import test_support
 

Modified: python/branches/py3k-importlib/Lib/test/test_errno.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_errno.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_errno.py	Thu Mar 27 00:48:05 2008
@@ -4,46 +4,37 @@
 """
 
 import errno
-from test.test_support import verbose
+from test import test_support
+import unittest
 
-errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV',
-          'EAFNOSUPPORT', 'EAGAIN', 'EALREADY', 'EBADE', 'EBADF',
-          'EBADFD', 'EBADMSG', 'EBADR', 'EBADRQC', 'EBADSLT',
-          'EBFONT', 'EBUSY', 'ECHILD', 'ECHRNG', 'ECOMM',
-          'ECONNABORTED', 'ECONNREFUSED', 'ECONNRESET',
-          'EDEADLK', 'EDEADLOCK', 'EDESTADDRREQ', 'EDOM',
-          'EDQUOT', 'EEXIST', 'EFAULT', 'EFBIG', 'EHOSTDOWN',
-          'EHOSTUNREACH', 'EIDRM', 'EILSEQ', 'EINPROGRESS',
-          'EINTR', 'EINVAL', 'EIO', 'EISCONN', 'EISDIR',
-          'EL2HLT', 'EL2NSYNC', 'EL3HLT', 'EL3RST', 'ELIBACC',
-          'ELIBBAD', 'ELIBEXEC', 'ELIBMAX', 'ELIBSCN', 'ELNRNG',
-          'ELOOP', 'EMFILE', 'EMLINK', 'EMSGSIZE', 'EMULTIHOP',
-          'ENAMETOOLONG', 'ENETDOWN', 'ENETRESET', 'ENETUNREACH',
-          'ENFILE', 'ENOANO', 'ENOBUFS', 'ENOCSI', 'ENODATA',
-          'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK',
-          'ENOMEM', 'ENOMSG', 'ENONET', 'ENOPKG', 'ENOPROTOOPT',
-          'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTBLK',
-          'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTOBACCO', 'ENOTSOCK',
-          'ENOTTY', 'ENOTUNIQ', 'ENXIO', 'EOPNOTSUPP',
-          'EOVERFLOW', 'EPERM', 'EPFNOSUPPORT', 'EPIPE',
-          'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE',
-          'ERANGE', 'EREMCHG', 'EREMOTE', 'ERESTART',
-          'EROFS', 'ESHUTDOWN', 'ESOCKTNOSUPPORT', 'ESPIPE',
-          'ESRCH', 'ESRMNT', 'ESTALE', 'ESTRPIPE', 'ETIME',
-          'ETIMEDOUT', 'ETOOMANYREFS', 'ETXTBSY', 'EUNATCH',
-          'EUSERS', 'EWOULDBLOCK', 'EXDEV', 'EXFULL']
-
-#
-# This is a wee bit bogus since the module only conditionally adds
-# errno constants if they have been defined by errno.h  However, this
-# test seems to work on SGI, Sparc & intel Solaris, and linux.
-#
-for error in errors:
-    try:
-        a = getattr(errno, error)
-    except AttributeError:
-        if verbose:
-            print('%s: not found' % error)
-    else:
-        if verbose:
-            print('%s: %d' % (error, a))
+std_c_errors = frozenset(['EDOM', 'ERANGE'])
+
+class ErrnoAttributeTests(unittest.TestCase):
+
+    def test_for_improper_attributes(self):
+        # No unexpected attributes should be on the module.
+        for error_code in std_c_errors:
+            self.assert_(hasattr(errno, error_code),
+                            "errno is missing %s" % error_code)
+
+    def test_using_errorcode(self):
+        # Every key value in errno.errorcode should be on the module.
+        for value in errno.errorcode.values():
+            self.assert_(hasattr(errno, value), 'no %s attr in errno' % value)
+
+
+class ErrorcodeTests(unittest.TestCase):
+
+    def test_attributes_in_errorcode(self):
+        for attribute in errno.__dict__.keys():
+            if attribute.isupper():
+                self.assert_(getattr(errno, attribute) in errno.errorcode,
+                             'no %s attr in errno.errorcode' % attribute)
+
+
+def test_main():
+    test_support.run_unittest(ErrnoAttributeTests, ErrorcodeTests)
+
+
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_exceptions.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_exceptions.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_exceptions.py	Thu Mar 27 00:48:05 2008
@@ -253,6 +253,12 @@
                                            'ordinal not in range'),
                  'encoding' : 'ascii', 'object' : 'a',
                  'start' : 0, 'reason' : 'ordinal not in range'}),
+            (UnicodeDecodeError, ('ascii', bytearray(b'\xff'), 0, 1,
+                                  'ordinal not in range'),
+                {'args' : ('ascii', bytearray(b'\xff'), 0, 1,
+                                           'ordinal not in range'),
+                 'encoding' : 'ascii', 'object' : b'\xff',
+                 'start' : 0, 'reason' : 'ordinal not in range'}),
             (UnicodeDecodeError, ('ascii', b'\xff', 0, 1,
                                   'ordinal not in range'),
                 {'args' : ('ascii', b'\xff', 0, 1,
@@ -278,11 +284,11 @@
             try:
                 e = exc(*args)
             except:
-                print("\nexc=%r, args=%r" % (exc, args))
+                print("\nexc=%r, args=%r" % (exc, args), file=sys.stderr)
                 raise
             else:
                 # Verify module name
-                self.assertEquals(type(e).__module__, '__builtin__')
+                self.assertEquals(type(e).__module__, 'builtins')
                 # Verify no ref leaks in Exc_str()
                 s = str(e)
                 for checkArgName in expected:

Modified: python/branches/py3k-importlib/Lib/test/test_extcall.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_extcall.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_extcall.py	Thu Mar 27 00:48:05 2008
@@ -1,285 +1,255 @@
-from test.test_support import verify, verbose, TestFailed, sortdict
-from UserList import UserList
-from UserDict import UserDict
-
-def e(a, b):
-    print(a, b)
-
-def f(*a, **k):
-    print(a, sortdict(k))
-
-def g(x, *y, **z):
-    print(x, y, sortdict(z))
-
-def h(j=1, a=2, h=3):
-    print(j, a, h)
-
-f()
-f(1)
-f(1, 2)
-f(1, 2, 3)
-
-f(1, 2, 3, *(4, 5))
-f(1, 2, 3, *[4, 5])
-f(1, 2, 3, *UserList([4, 5]))
-f(1, 2, 3, **{'a':4, 'b':5})
-f(1, 2, 3, *(4, 5), **{'a':6, 'b':7})
-f(1, 2, 3, x=4, y=5, *(6, 7), **{'a':8, 'b':9})
-
-
-f(1, 2, 3, **UserDict(a=4, b=5))
-f(1, 2, 3, *(4, 5), **UserDict(a=6, b=7))
-f(1, 2, 3, x=4, y=5, *(6, 7), **UserDict(a=8, b=9))
-
-
-# Verify clearing of SF bug #733667
-try:
-    e(c=3)
-except TypeError:
-    pass
-else:
-    print("should raise TypeError: e() got an unexpected keyword argument 'c'")
-
-try:
-    g()
-except TypeError as err:
-    print("TypeError:", err)
-else:
-    print("should raise TypeError: not enough arguments; expected 1, got 0")
-
-try:
-    g(*())
-except TypeError as err:
-    print("TypeError:", err)
-else:
-    print("should raise TypeError: not enough arguments; expected 1, got 0")
-
-try:
-    g(*(), **{})
-except TypeError as err:
-    print("TypeError:", err)
-else:
-    print("should raise TypeError: not enough arguments; expected 1, got 0")
-
-g(1)
-g(1, 2)
-g(1, 2, 3)
-g(1, 2, 3, *(4, 5))
-class Nothing: pass
-try:
-    g(*Nothing())
-except TypeError as attr:
-    pass
-else:
-    print("should raise TypeError")
-
-class Nothing:
-    def __len__(self):
-        return 5
-try:
-    g(*Nothing())
-except TypeError as attr:
-    pass
-else:
-    print("should raise TypeError")
-
-class Nothing:
-    def __len__(self):
-        return 5
-    def __getitem__(self, i):
-        if i < 3:
-            return i
-        else:
-            raise IndexError(i)
-g(*Nothing())
-
-class Nothing:
-    def __init__(self):
-        self.c = 0
-    def __iter__(self):
-        return self
-try:
-    g(*Nothing())
-except TypeError as attr:
-    pass
-else:
-    print("should raise TypeError")
-
-class Nothing:
-    def __init__(self):
-        self.c = 0
-    def __iter__(self):
-        return self
-    def __next__(self):
-        if self.c == 4:
-            raise StopIteration
-        c = self.c
-        self.c += 1
-        return c
-g(*Nothing())
-
-# make sure the function call doesn't stomp on the dictionary?
-d = {'a': 1, 'b': 2, 'c': 3}
-d2 = d.copy()
-verify(d == d2)
-g(1, d=4, **d)
-print(sortdict(d))
-print(sortdict(d2))
-verify(d == d2, "function call modified dictionary")
-
-# what about willful misconduct?
-def saboteur(**kw):
-    kw['x'] = locals() # yields a cyclic kw
-    return kw
-d = {}
-kw = saboteur(a=1, **d)
-verify(d == {})
-# break the cycle
-del kw['x']
-
-try:
-    g(1, 2, 3, **{'x':4, 'y':5})
-except TypeError as err:
-    print(err)
-else:
-    print("should raise TypeError: keyword parameter redefined")
-
-try:
-    g(1, 2, 3, a=4, b=5, *(6, 7), **{'a':8, 'b':9})
-except TypeError as err:
-    print(err)
-else:
-    print("should raise TypeError: keyword parameter redefined")
-
-try:
-    f(**{1:2})
-except TypeError as err:
-    print(err)
-else:
-    print("should raise TypeError: keywords must be strings")
-
-try:
-    h(**{'e': 2})
-except TypeError as err:
-    print(err)
-else:
-    print("should raise TypeError: unexpected keyword argument: e")
-
-try:
-    h(*h)
-except TypeError as err:
-    print(err)
-else:
-    print("should raise TypeError: * argument must be a tuple")
-
-try:
-    dir(*h)
-except TypeError as err:
-    print(err)
-else:
-    print("should raise TypeError: * argument must be a tuple")
-
-try:
-    None(*h)
-except TypeError as err:
-    print(err)
-else:
-    print("should raise TypeError: * argument must be a tuple")
-
-try:
-    h(**h)
-except TypeError as err:
-    print(err)
-else:
-    print("should raise TypeError: ** argument must be a dictionary")
-
-try:
-    dir(**h)
-except TypeError as err:
-    print(err)
-else:
-    print("should raise TypeError: ** argument must be a dictionary")
-
-try:
-    None(**h)
-except TypeError as err:
-    print(err)
-else:
-    print("should raise TypeError: ** argument must be a dictionary")
-
-try:
-    dir(b=1,**{'b':1})
-except TypeError as err:
-    print(err)
-else:
-    print("should raise TypeError: dir() got multiple values for keyword argument 'b'")
-
-def f2(*a, **b):
-    return a, b
-
-d = {}
-for i in range(512):
-    key = 'k%d' % i
-    d[key] = i
-a, b = f2(1, *(2, 3), **d)
-print(len(a), len(b), b == d)
-
-class Foo:
-    def method(self, arg1, arg2):
-        return arg1 + arg2
-
-x = Foo()
-print(Foo.method(*(x, 1, 2)))
-print(Foo.method(x, *(1, 2)))
-try:
-    print(Foo.method(*(1, 2, 3)))
-except TypeError as err:
-    pass
-else:
-    print('expected a TypeError for unbound method call')
-try:
-    print(Foo.method(1, *(2, 3)))
-except TypeError as err:
-    pass
-else:
-    print('expected a TypeError for unbound method call')
-
-# A PyCFunction that takes only positional parameters should allow an
-# empty keyword dictionary to pass without a complaint, but raise a
-# TypeError if the dictionary is non-empty.
-id(1, **{})
-try:
-    id(1, **{"foo": 1})
-except TypeError:
-    pass
-else:
-    raise TestFailed('expected TypeError; no exception raised')
-
-a, b, d, e, v, k = 'A', 'B', 'D', 'E', 'V', 'K'
-funcs = []
-maxargs = {}
-for args in ['', 'a', 'ab']:
-    for defargs in ['', 'd', 'de']:
-        for vararg in ['', 'v']:
-            for kwarg in ['', 'k']:
-                name = 'z' + args + defargs + vararg + kwarg
-                arglist = list(args) + ['%s="%s"' % (x, x) for x in defargs]
-                if vararg: arglist.append('*' + vararg)
-                if kwarg: arglist.append('**' + kwarg)
-                decl = (('def %s(%s): print("ok %s", a, b, d, e, v, ' +
-                         'type(k) is type ("") and k or sortdict(k))')
-                         % (name, ', '.join(arglist), name))
-                exec(decl)
-                func = eval(name)
-                funcs.append(func)
-                maxargs[func] = len(args + defargs)
-
-for name in ['za', 'zade', 'zabk', 'zabdv', 'zabdevk']:
-    func = eval(name)
-    for args in [(), (1, 2), (1, 2, 3, 4, 5)]:
-        for kwargs in ['', 'a', 'd', 'ad', 'abde']:
-            kwdict = {}
-            for k in kwargs: kwdict[k] = k + k
-            print(func.__name__, args, sortdict(kwdict), '->', end=' ')
-            try: func(*args, **kwdict)
-            except TypeError as err: print(err)
+"""Doctest for method/function calls.
+
+We're going the use these types for extra testing
+
+    >>> from collections import UserList
+    >>> from collections import UserDict
+
+We're defining four helper functions
+
+    >>> def e(a,b):
+    ...     print(a, b)
+
+    >>> def f(*a, **k):
+    ...     print(a, test_support.sortdict(k))
+
+    >>> def g(x, *y, **z):
+    ...     print(x, y, test_support.sortdict(z))
+
+    >>> def h(j=1, a=2, h=3):
+    ...     print(j, a, h)
+
+Argument list examples
+
+    >>> f()
+    () {}
+    >>> f(1)
+    (1,) {}
+    >>> f(1, 2)
+    (1, 2) {}
+    >>> f(1, 2, 3)
+    (1, 2, 3) {}
+    >>> f(1, 2, 3, *(4, 5))
+    (1, 2, 3, 4, 5) {}
+    >>> f(1, 2, 3, *[4, 5])
+    (1, 2, 3, 4, 5) {}
+    >>> f(1, 2, 3, *UserList([4, 5]))
+    (1, 2, 3, 4, 5) {}
+
+Here we add keyword arguments
+
+    >>> f(1, 2, 3, **{'a':4, 'b':5})
+    (1, 2, 3) {'a': 4, 'b': 5}
+    >>> f(1, 2, 3, *[4, 5], **{'a':6, 'b':7})
+    (1, 2, 3, 4, 5) {'a': 6, 'b': 7}
+    >>> f(1, 2, 3, x=4, y=5, *(6, 7), **{'a':8, 'b': 9})
+    (1, 2, 3, 6, 7) {'a': 8, 'b': 9, 'x': 4, 'y': 5}
+
+    >>> f(1, 2, 3, **UserDict(a=4, b=5))
+    (1, 2, 3) {'a': 4, 'b': 5}
+    >>> f(1, 2, 3, *(4, 5), **UserDict(a=6, b=7))
+    (1, 2, 3, 4, 5) {'a': 6, 'b': 7}
+    >>> f(1, 2, 3, x=4, y=5, *(6, 7), **UserDict(a=8, b=9))
+    (1, 2, 3, 6, 7) {'a': 8, 'b': 9, 'x': 4, 'y': 5}
+
+Examples with invalid arguments (TypeErrors). We're also testing the function
+names in the exception messages.
+
+Verify clearing of SF bug #733667
+
+    >>> e(c=4)
+    Traceback (most recent call last):
+      ...
+    TypeError: e() got an unexpected keyword argument 'c'
+
+    >>> g()
+    Traceback (most recent call last):
+      ...
+    TypeError: g() takes at least 1 positional argument (0 given)
+
+    >>> g(*())
+    Traceback (most recent call last):
+      ...
+    TypeError: g() takes at least 1 positional argument (0 given)
+
+    >>> g(*(), **{})
+    Traceback (most recent call last):
+      ...
+    TypeError: g() takes at least 1 positional argument (0 given)
+
+    >>> g(1)
+    1 () {}
+    >>> g(1, 2)
+    1 (2,) {}
+    >>> g(1, 2, 3)
+    1 (2, 3) {}
+    >>> g(1, 2, 3, *(4, 5))
+    1 (2, 3, 4, 5) {}
+
+    >>> class Nothing: pass
+    ...
+    >>> g(*Nothing())
+    Traceback (most recent call last):
+      ...
+    TypeError: g() argument after * must be a sequence, not Nothing
+
+    >>> class Nothing:
+    ...     def __len__(self): return 5
+    ...
+
+    >>> g(*Nothing())
+    Traceback (most recent call last):
+      ...
+    TypeError: g() argument after * must be a sequence, not Nothing
+
+    >>> class Nothing():
+    ...     def __len__(self): return 5
+    ...     def __getitem__(self, i):
+    ...         if i<3: return i
+    ...         else: raise IndexError(i)
+    ...
+
+    >>> g(*Nothing())
+    0 (1, 2) {}
+
+    >>> class Nothing:
+    ...     def __init__(self): self.c = 0
+    ...     def __iter__(self): return self
+    ...     def __next__(self):
+    ...         if self.c == 4:
+    ...             raise StopIteration
+    ...         c = self.c
+    ...         self.c += 1
+    ...         return c
+    ...
+
+    >>> g(*Nothing())
+    0 (1, 2, 3) {}
+
+Make sure that the function doesn't stomp the dictionary
+
+    >>> d = {'a': 1, 'b': 2, 'c': 3}
+    >>> d2 = d.copy()
+    >>> g(1, d=4, **d)
+    1 () {'a': 1, 'b': 2, 'c': 3, 'd': 4}
+    >>> d == d2
+    True
+
+What about willful misconduct?
+
+    >>> def saboteur(**kw):
+    ...     kw['x'] = 'm'
+    ...     return kw
+
+    >>> d = {}
+    >>> kw = saboteur(a=1, **d)
+    >>> d
+    {}
+
+
+    >>> g(1, 2, 3, **{'x': 4, 'y': 5})
+    Traceback (most recent call last):
+      ...
+    TypeError: g() got multiple values for keyword argument 'x'
+
+    >>> f(**{1:2})
+    Traceback (most recent call last):
+      ...
+    TypeError: f() keywords must be strings
+
+    >>> h(**{'e': 2})
+    Traceback (most recent call last):
+      ...
+    TypeError: h() got an unexpected keyword argument 'e'
+
+    >>> h(*h)
+    Traceback (most recent call last):
+      ...
+    TypeError: h() argument after * must be a sequence, not function
+
+    >>> dir(*h)
+    Traceback (most recent call last):
+      ...
+    TypeError: dir() argument after * must be a sequence, not function
+
+    >>> None(*h)
+    Traceback (most recent call last):
+      ...
+    TypeError: NoneType object argument after * must be a sequence, \
+not function
+
+    >>> h(**h)
+    Traceback (most recent call last):
+      ...
+    TypeError: h() argument after ** must be a mapping, not function
+
+    >>> dir(**h)
+    Traceback (most recent call last):
+      ...
+    TypeError: dir() argument after ** must be a mapping, not function
+
+    >>> None(**h)
+    Traceback (most recent call last):
+      ...
+    TypeError: NoneType object argument after ** must be a mapping, \
+not function
+
+    >>> dir(b=1, **{'b': 1})
+    Traceback (most recent call last):
+      ...
+    TypeError: dir() got multiple values for keyword argument 'b'
+
+Another helper function
+
+    >>> def f2(*a, **b):
+    ...     return a, b
+
+
+    >>> d = {}
+    >>> for i in range(512):
+    ...     key = 'k%d' % i
+    ...     d[key] = i
+    >>> a, b = f2(1, *(2,3), **d)
+    >>> len(a), len(b), b == d
+    (3, 512, True)
+
+    >>> class Foo:
+    ...     def method(self, arg1, arg2):
+    ...         return arg1+arg2
+
+    >>> x = Foo()
+    >>> Foo.method(*(x, 1, 2))
+    3
+    >>> Foo.method(x, *(1, 2))
+    3
+    >>> Foo.method(*(1, 2, 3))
+    5
+    >>> Foo.method(1, *[2, 3])
+    5
+
+A PyCFunction that takes only positional parameters shoud allow an
+empty keyword dictionary to pass without a complaint, but raise a
+TypeError if te dictionary is not empty
+
+    >>> try:
+    ...     silence = id(1, *{})
+    ...     True
+    ... except:
+    ...     False
+    True
+
+    >>> id(1, **{'foo': 1})
+    Traceback (most recent call last):
+      ...
+    TypeError: id() takes no keyword arguments
+
+"""
+
+from test import test_support
+
+def test_main():
+    from test import test_extcall # self import
+    test_support.run_doctest(test_extcall, True)
+
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_fcntl.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_fcntl.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_fcntl.py	Thu Mar 27 00:48:05 2008
@@ -1,69 +1,88 @@
-#! /usr/bin/env python
 """Test program for the fcntl C module.
-   OS/2+EMX doesn't support the file locking operations.
-   Roger E. Masse
-"""
-import struct
-import fcntl
-import os, sys
-from test.test_support import verbose, TESTFN
 
-filename = TESTFN
+OS/2+EMX doesn't support the file locking operations.
 
-try:
-    os.O_LARGEFILE
-except AttributeError:
-    start_len = "ll"
-else:
-    start_len = "qq"
-
-if sys.platform.startswith('atheos'):
-    start_len = "qq"
-
-if sys.platform in ('netbsd1', 'netbsd2', 'netbsd3',
-                    'Darwin1.2', 'darwin',
-                    'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
-                    'freebsd6', 'freebsd7',
-                    'bsdos2', 'bsdos3', 'bsdos4',
-                    'openbsd', 'openbsd2', 'openbsd3', 'openbsd4'):
-    if struct.calcsize('l') == 8:
-        off_t = 'l'
-        pid_t = 'i'
+"""
+import fcntl
+import os
+import struct
+import sys
+import unittest
+from test.test_support import verbose, TESTFN, unlink, run_unittest
+
+# TODO - Write tests for flock() and lockf().
+
+def get_lockdata():
+    if sys.platform.startswith('atheos'):
+        start_len = "qq"
     else:
-        off_t = 'lxxxx'
-        pid_t = 'l'
-    lockdata = struct.pack(off_t+off_t+pid_t+'hh', 0, 0, 0, fcntl.F_WRLCK, 0)
-elif sys.platform in ['aix3', 'aix4', 'hp-uxB', 'unixware7']:
-    lockdata = struct.pack('hhlllii', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
-elif sys.platform in ['os2emx']:
-    lockdata = None
-else:
-    lockdata = struct.pack('hh'+start_len+'hh', fcntl.F_WRLCK, 0, 0, 0, 0, 0)
-if lockdata:
-    if verbose:
-        print('struct.pack: ', repr(lockdata))
-
-# the example from the library docs
-f = open(filename, 'w')
-rv = fcntl.fcntl(f.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
-if verbose:
-    print('Status from fcntl with O_NONBLOCK: ', rv)
-
-if sys.platform not in ['os2emx']:
-    rv = fcntl.fcntl(f.fileno(), fcntl.F_SETLKW, lockdata)
-    if verbose:
-        print('String from fcntl with F_SETLKW: ', repr(rv))
-
-f.close()
-os.unlink(filename)
-
-
-# Again, but pass the file rather than numeric descriptor:
-f = open(filename, 'w')
-rv = fcntl.fcntl(f, fcntl.F_SETFL, os.O_NONBLOCK)
+        try:
+            os.O_LARGEFILE
+        except AttributeError:
+            start_len = "ll"
+        else:
+            start_len = "qq"
+
+    if sys.platform in ('netbsd1', 'netbsd2', 'netbsd3',
+                        'Darwin1.2', 'darwin',
+                        'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
+                        'freebsd6', 'freebsd7', 'freebsd8',
+                        'bsdos2', 'bsdos3', 'bsdos4',
+                        'openbsd', 'openbsd2', 'openbsd3', 'openbsd4'):
+        if struct.calcsize('l') == 8:
+            off_t = 'l'
+            pid_t = 'i'
+        else:
+            off_t = 'lxxxx'
+            pid_t = 'l'
+        lockdata = struct.pack(off_t + off_t + pid_t + 'hh', 0, 0, 0,
+                               fcntl.F_WRLCK, 0)
+    elif sys.platform in ['aix3', 'aix4', 'hp-uxB', 'unixware7']:
+        lockdata = struct.pack('hhlllii', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
+    elif sys.platform in ['os2emx']:
+        lockdata = None
+    else:
+        lockdata = struct.pack('hh'+start_len+'hh', fcntl.F_WRLCK, 0, 0, 0, 0, 0)
+    if lockdata:
+        if verbose:
+            print('struct.pack: ', repr(lockdata))
+    return lockdata
+
+lockdata = get_lockdata()
+
+class TestFcntl(unittest.TestCase):
+
+    def setUp(self):
+        self.f = None
+
+    def tearDown(self):
+        if not self.f.closed:
+            self.f.close()
+        unlink(TESTFN)
+
+    def test_fcntl_fileno(self):
+        # the example from the library docs
+        self.f = open(TESTFN, 'w')
+        rv = fcntl.fcntl(self.f.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
+        if verbose:
+            print('Status from fcntl with O_NONBLOCK: ', rv)
+        if sys.platform not in ['os2emx']:
+            rv = fcntl.fcntl(self.f.fileno(), fcntl.F_SETLKW, lockdata)
+            if verbose:
+                print('String from fcntl with F_SETLKW: ', repr(rv))
+        self.f.close()
+
+    def test_fcntl_file_descriptor(self):
+        # again, but pass the file rather than numeric descriptor
+        self.f = open(TESTFN, 'w')
+        rv = fcntl.fcntl(self.f, fcntl.F_SETFL, os.O_NONBLOCK)
+        if sys.platform not in ['os2emx']:
+            rv = fcntl.fcntl(self.f, fcntl.F_SETLKW, lockdata)
+        self.f.close()
+
 
-if sys.platform not in ['os2emx']:
-    rv = fcntl.fcntl(f, fcntl.F_SETLKW, lockdata)
+def test_main():
+    run_unittest(TestFcntl)
 
-f.close()
-os.unlink(filename)
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_file.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_file.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_file.py	Thu Mar 27 00:48:05 2008
@@ -5,7 +5,7 @@
 from weakref import proxy
 
 from test.test_support import TESTFN, findfile, run_unittest
-from UserList import UserList
+from collections import UserList
 
 class AutoFileTests(unittest.TestCase):
     # file tests for which a test file is automatically set up
@@ -157,7 +157,7 @@
                 s = str(msg)
                 if s.find(TESTFN) != -1 or s.find(bad_mode) == -1:
                     self.fail("bad error message for invalid mode: %s" % s)
-            # if msg[0] == 0, we're probably on Windows where there may be
+            # if msg.args[0] == 0, we're probably on Windows where there may be
             # no obvious way to discover why open() failed.
         else:
             f.close()
@@ -181,12 +181,13 @@
             self.assertEquals(d, s)
 
     def testTruncateOnWindows(self):
+        # SF bug <http://www.python.org/sf/801631>
+        # "file.truncate fault on windows"
+
         os.unlink(TESTFN)
+        f = open(TESTFN, 'wb')
 
-        def bug801631():
-            # SF bug <http://www.python.org/sf/801631>
-            # "file.truncate fault on windows"
-            f = open(TESTFN, 'wb')
+        try:
             f.write(b'12345678901')   # 11 bytes
             f.close()
 
@@ -205,10 +206,8 @@
             size = os.path.getsize(TESTFN)
             if size != 5:
                 self.fail("File size after ftruncate wrong %d" % size)
-
-        try:
-            bug801631()
         finally:
+            f.close()
             os.unlink(TESTFN)
 
     def testIteration(self):

Modified: python/branches/py3k-importlib/Lib/test/test_fileinput.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_fileinput.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_fileinput.py	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,7 @@
 import unittest
 from test.test_support import verbose, TESTFN, run_unittest
 from test.test_support import unlink as safe_unlink
-import sys, os, re
+import sys, re
 from io import StringIO
 from fileinput import FileInput, hook_encoded
 

Modified: python/branches/py3k-importlib/Lib/test/test_fileio.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_fileio.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_fileio.py	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,7 @@
 from weakref import proxy
 
 from test.test_support import TESTFN, findfile, run_unittest
-from UserList import UserList
+from collections import UserList
 
 import _fileio
 
@@ -172,7 +172,7 @@
                 s = str(msg)
                 if s.find(TESTFN) != -1 or s.find(bad_mode) == -1:
                     self.fail("bad error message for invalid mode: %s" % s)
-            # if msg[0] == 0, we're probably on Windows where there may be
+            # if msg.args[0] == 0, we're probably on Windows where there may be
             # no obvious way to discover why open() failed.
         else:
             f.close()

Modified: python/branches/py3k-importlib/Lib/test/test_float.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_float.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_float.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,14 @@
 
 import unittest, struct
+import os
 from test import test_support
 
+def isinf(x):
+    return x * 0.5 == x
+
+def isnan(x):
+    return x != x
+
 class FormatFunctionsTestCase(unittest.TestCase):
 
     def setUp(self):
@@ -126,13 +133,10 @@
         self.assertEqual(format(0.01, ''), '0.01')
         self.assertEqual(format(0.01, 'g'), '0.01')
 
-        self.assertEqual(format(0, 'f'), '0.000000')
 
         self.assertEqual(format(1.0, 'f'), '1.000000')
-        self.assertEqual(format(1, 'f'), '1.000000')
 
         self.assertEqual(format(-1.0, 'f'), '-1.000000')
-        self.assertEqual(format(-1, 'f'), '-1.000000')
 
         self.assertEqual(format( 1.0, ' f'), ' 1.000000')
         self.assertEqual(format(-1.0, ' f'), '-1.000000')
@@ -145,13 +149,105 @@
         # conversion to string should fail
         self.assertRaises(ValueError, format, 3.0, "s")
 
+        # other format specifiers shouldn't work on floats,
+        #  in particular int specifiers
+        for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
+                            [chr(x) for x in range(ord('A'), ord('Z')+1)]):
+            if not format_spec in 'eEfFgGn%':
+                self.assertRaises(ValueError, format, 0.0, format_spec)
+                self.assertRaises(ValueError, format, 1.0, format_spec)
+                self.assertRaises(ValueError, format, -1.0, format_spec)
+                self.assertRaises(ValueError, format, 1e100, format_spec)
+                self.assertRaises(ValueError, format, -1e100, format_spec)
+                self.assertRaises(ValueError, format, 1e-100, format_spec)
+                self.assertRaises(ValueError, format, -1e-100, format_spec)
+
+class ReprTestCase(unittest.TestCase):
+    def test_repr(self):
+        floats_file = open(os.path.join(os.path.split(__file__)[0],
+                           'floating_points.txt'))
+        for line in floats_file:
+            line = line.strip()
+            if not line or line.startswith('#'):
+                continue
+            v = eval(line)
+            self.assertEqual(v, eval(repr(v)))
+        floats_file.close()
+
+# Beginning with Python 2.6 float has cross platform compatible
+# ways to create and representate inf and nan
+class InfNanTest(unittest.TestCase):
+    def test_inf_from_str(self):
+        self.assert_(isinf(float("inf")))
+        self.assert_(isinf(float("+inf")))
+        self.assert_(isinf(float("-inf")))
+
+        self.assertEqual(repr(float("inf")), "inf")
+        self.assertEqual(repr(float("+inf")), "inf")
+        self.assertEqual(repr(float("-inf")), "-inf")
+
+        self.assertEqual(repr(float("INF")), "inf")
+        self.assertEqual(repr(float("+Inf")), "inf")
+        self.assertEqual(repr(float("-iNF")), "-inf")
+
+        self.assertEqual(str(float("inf")), "inf")
+        self.assertEqual(str(float("+inf")), "inf")
+        self.assertEqual(str(float("-inf")), "-inf")
+
+        self.assertRaises(ValueError, float, "info")
+        self.assertRaises(ValueError, float, "+info")
+        self.assertRaises(ValueError, float, "-info")
+        self.assertRaises(ValueError, float, "in")
+        self.assertRaises(ValueError, float, "+in")
+        self.assertRaises(ValueError, float, "-in")
+
+    def test_inf_as_str(self):
+        self.assertEqual(repr(1e300 * 1e300), "inf")
+        self.assertEqual(repr(-1e300 * 1e300), "-inf")
+
+        self.assertEqual(str(1e300 * 1e300), "inf")
+        self.assertEqual(str(-1e300 * 1e300), "-inf")
+
+    def test_nan_from_str(self):
+        self.assert_(isnan(float("nan")))
+        self.assert_(isnan(float("+nan")))
+        self.assert_(isnan(float("-nan")))
+
+        self.assertEqual(repr(float("nan")), "nan")
+        self.assertEqual(repr(float("+nan")), "nan")
+        self.assertEqual(repr(float("-nan")), "nan")
+
+        self.assertEqual(repr(float("NAN")), "nan")
+        self.assertEqual(repr(float("+NAn")), "nan")
+        self.assertEqual(repr(float("-NaN")), "nan")
+
+        self.assertEqual(str(float("nan")), "nan")
+        self.assertEqual(str(float("+nan")), "nan")
+        self.assertEqual(str(float("-nan")), "nan")
+
+        self.assertRaises(ValueError, float, "nana")
+        self.assertRaises(ValueError, float, "+nana")
+        self.assertRaises(ValueError, float, "-nana")
+        self.assertRaises(ValueError, float, "na")
+        self.assertRaises(ValueError, float, "+na")
+        self.assertRaises(ValueError, float, "-na")
+
+    def test_nan_as_str(self):
+        self.assertEqual(repr(1e300 * 1e300 * 0), "nan")
+        self.assertEqual(repr(-1e300 * 1e300 * 0), "nan")
+
+        self.assertEqual(str(1e300 * 1e300 * 0), "nan")
+        self.assertEqual(str(-1e300 * 1e300 * 0), "nan")
 
 def test_main():
     test_support.run_unittest(
         FormatFunctionsTestCase,
         UnknownFormatTestCase,
         IEEEFormatTestCase,
-        FormatTestCase)
+        FormatTestCase,
+        ReprTestCase,
+        InfNanTest,
+        )
 
 if __name__ == '__main__':
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_format.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_format.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_format.py	Thu Mar 27 00:48:05 2008
@@ -11,7 +11,7 @@
 overflowok = 1
 overflowrequired = 0
 
-def testformat(formatstr, args, output=None):
+def testformat(formatstr, args, output=None, limit=None):
     if verbose:
         if output:
             print("%r %% %r =? %r ..." %\
@@ -30,172 +30,183 @@
             if verbose:
                 print('no')
             print("overflow expected on %r %% %r" % (formatstr, args))
-        elif output and result != output:
+        elif output and limit is None and result != output:
             if verbose:
                 print('no')
             print("%r %% %r == %r != %r" %\
                 (formatstr, args, result, output))
+        # when 'limit' is specified, it determines how many characters
+        # must match exactly; lengths must always match.
+        # ex: limit=5, '12345678' matches '12345___'
+        # (mainly for floating point format tests for which an exact match
+        # can't be guaranteed due to rounding and representation errors)
+        elif output and limit is not None and (
+                len(result)!=len(output) or result[:limit]!=output[:limit]):
+            if verbose:
+                print('no')
+            print("%s %% %s == %s != %s" % \
+                  (repr(formatstr), repr(args), repr(result), repr(output)))
         else:
             if verbose:
                 print('yes')
 
-def testboth(formatstr, *args):
-    testformat(str8(formatstr), *args)
-    testformat(formatstr, *args)
-
-
-testboth("%.1d", (1,), "1")
-testboth("%.*d", (sys.maxint,1))  # expect overflow
-testboth("%.100d", (1,), '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
-testboth("%#.117x", (1,), '0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
-testboth("%#.118x", (1,), '0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
+testformat("%.1d", (1,), "1")
+testformat("%.*d", (sys.maxsize,1))  # expect overflow
+testformat("%.100d", (1,), '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
+testformat("%#.117x", (1,), '0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
+testformat("%#.118x", (1,), '0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
 
-testboth("%f", (1.0,), "1.000000")
+testformat("%f", (1.0,), "1.000000")
 # these are trying to test the limits of the internal magic-number-length
 # formatting buffer, if that number changes then these tests are less
 # effective
-testboth("%#.*g", (109, -1.e+49/3.))
-testboth("%#.*g", (110, -1.e+49/3.))
-testboth("%#.*g", (110, -1.e+100/3.))
+testformat("%#.*g", (109, -1.e+49/3.))
+testformat("%#.*g", (110, -1.e+49/3.))
+testformat("%#.*g", (110, -1.e+100/3.))
 
 # test some ridiculously large precision, expect overflow
-testboth('%12.*f', (123456, 1.0))
+testformat('%12.*f', (123456, 1.0))
 
 # check for internal overflow validation on length of precision
 overflowrequired = 1
-testboth("%#.*g", (110, -1.e+100/3.))
-testboth("%#.*G", (110, -1.e+100/3.))
-testboth("%#.*f", (110, -1.e+100/3.))
-testboth("%#.*F", (110, -1.e+100/3.))
+testformat("%#.*g", (110, -1.e+100/3.))
+testformat("%#.*G", (110, -1.e+100/3.))
+testformat("%#.*f", (110, -1.e+100/3.))
+testformat("%#.*F", (110, -1.e+100/3.))
 overflowrequired = 0
 
 # Formatting of long integers. Overflow is not ok
 overflowok = 0
-testboth("%x", 10, "a")
-testboth("%x", 100000000000, "174876e800")
-testboth("%o", 10, "12")
-testboth("%o", 100000000000, "1351035564000")
-testboth("%d", 10, "10")
-testboth("%d", 100000000000, "100000000000")
+testformat("%x", 10, "a")
+testformat("%x", 100000000000, "174876e800")
+testformat("%o", 10, "12")
+testformat("%o", 100000000000, "1351035564000")
+testformat("%d", 10, "10")
+testformat("%d", 100000000000, "100000000000")
 
 big = 123456789012345678901234567890
-testboth("%d", big, "123456789012345678901234567890")
-testboth("%d", -big, "-123456789012345678901234567890")
-testboth("%5d", -big, "-123456789012345678901234567890")
-testboth("%31d", -big, "-123456789012345678901234567890")
-testboth("%32d", -big, " -123456789012345678901234567890")
-testboth("%-32d", -big, "-123456789012345678901234567890 ")
-testboth("%032d", -big, "-0123456789012345678901234567890")
-testboth("%-032d", -big, "-123456789012345678901234567890 ")
-testboth("%034d", -big, "-000123456789012345678901234567890")
-testboth("%034d", big, "0000123456789012345678901234567890")
-testboth("%0+34d", big, "+000123456789012345678901234567890")
-testboth("%+34d", big, "   +123456789012345678901234567890")
-testboth("%34d", big, "    123456789012345678901234567890")
-testboth("%.2d", big, "123456789012345678901234567890")
-testboth("%.30d", big, "123456789012345678901234567890")
-testboth("%.31d", big, "0123456789012345678901234567890")
-testboth("%32.31d", big, " 0123456789012345678901234567890")
+testformat("%d", big, "123456789012345678901234567890")
+testformat("%d", -big, "-123456789012345678901234567890")
+testformat("%5d", -big, "-123456789012345678901234567890")
+testformat("%31d", -big, "-123456789012345678901234567890")
+testformat("%32d", -big, " -123456789012345678901234567890")
+testformat("%-32d", -big, "-123456789012345678901234567890 ")
+testformat("%032d", -big, "-0123456789012345678901234567890")
+testformat("%-032d", -big, "-123456789012345678901234567890 ")
+testformat("%034d", -big, "-000123456789012345678901234567890")
+testformat("%034d", big, "0000123456789012345678901234567890")
+testformat("%0+34d", big, "+000123456789012345678901234567890")
+testformat("%+34d", big, "   +123456789012345678901234567890")
+testformat("%34d", big, "    123456789012345678901234567890")
+testformat("%.2d", big, "123456789012345678901234567890")
+testformat("%.30d", big, "123456789012345678901234567890")
+testformat("%.31d", big, "0123456789012345678901234567890")
+testformat("%32.31d", big, " 0123456789012345678901234567890")
+testformat("%d", float(big), "123456________________________", 6)
 
 big = 0x1234567890abcdef12345  # 21 hex digits
-testboth("%x", big, "1234567890abcdef12345")
-testboth("%x", -big, "-1234567890abcdef12345")
-testboth("%5x", -big, "-1234567890abcdef12345")
-testboth("%22x", -big, "-1234567890abcdef12345")
-testboth("%23x", -big, " -1234567890abcdef12345")
-testboth("%-23x", -big, "-1234567890abcdef12345 ")
-testboth("%023x", -big, "-01234567890abcdef12345")
-testboth("%-023x", -big, "-1234567890abcdef12345 ")
-testboth("%025x", -big, "-0001234567890abcdef12345")
-testboth("%025x", big, "00001234567890abcdef12345")
-testboth("%0+25x", big, "+0001234567890abcdef12345")
-testboth("%+25x", big, "   +1234567890abcdef12345")
-testboth("%25x", big, "    1234567890abcdef12345")
-testboth("%.2x", big, "1234567890abcdef12345")
-testboth("%.21x", big, "1234567890abcdef12345")
-testboth("%.22x", big, "01234567890abcdef12345")
-testboth("%23.22x", big, " 01234567890abcdef12345")
-testboth("%-23.22x", big, "01234567890abcdef12345 ")
-testboth("%X", big, "1234567890ABCDEF12345")
-testboth("%#X", big, "0X1234567890ABCDEF12345")
-testboth("%#x", big, "0x1234567890abcdef12345")
-testboth("%#x", -big, "-0x1234567890abcdef12345")
-testboth("%#.23x", -big, "-0x001234567890abcdef12345")
-testboth("%#+.23x", big, "+0x001234567890abcdef12345")
-testboth("%# .23x", big, " 0x001234567890abcdef12345")
-testboth("%#+.23X", big, "+0X001234567890ABCDEF12345")
-testboth("%#-+.23X", big, "+0X001234567890ABCDEF12345")
-testboth("%#-+26.23X", big, "+0X001234567890ABCDEF12345")
-testboth("%#-+27.23X", big, "+0X001234567890ABCDEF12345 ")
-testboth("%#+27.23X", big, " +0X001234567890ABCDEF12345")
+testformat("%x", big, "1234567890abcdef12345")
+testformat("%x", -big, "-1234567890abcdef12345")
+testformat("%5x", -big, "-1234567890abcdef12345")
+testformat("%22x", -big, "-1234567890abcdef12345")
+testformat("%23x", -big, " -1234567890abcdef12345")
+testformat("%-23x", -big, "-1234567890abcdef12345 ")
+testformat("%023x", -big, "-01234567890abcdef12345")
+testformat("%-023x", -big, "-1234567890abcdef12345 ")
+testformat("%025x", -big, "-0001234567890abcdef12345")
+testformat("%025x", big, "00001234567890abcdef12345")
+testformat("%0+25x", big, "+0001234567890abcdef12345")
+testformat("%+25x", big, "   +1234567890abcdef12345")
+testformat("%25x", big, "    1234567890abcdef12345")
+testformat("%.2x", big, "1234567890abcdef12345")
+testformat("%.21x", big, "1234567890abcdef12345")
+testformat("%.22x", big, "01234567890abcdef12345")
+testformat("%23.22x", big, " 01234567890abcdef12345")
+testformat("%-23.22x", big, "01234567890abcdef12345 ")
+testformat("%X", big, "1234567890ABCDEF12345")
+testformat("%#X", big, "0X1234567890ABCDEF12345")
+testformat("%#x", big, "0x1234567890abcdef12345")
+testformat("%#x", -big, "-0x1234567890abcdef12345")
+testformat("%#.23x", -big, "-0x001234567890abcdef12345")
+testformat("%#+.23x", big, "+0x001234567890abcdef12345")
+testformat("%# .23x", big, " 0x001234567890abcdef12345")
+testformat("%#+.23X", big, "+0X001234567890ABCDEF12345")
+testformat("%#-+.23X", big, "+0X001234567890ABCDEF12345")
+testformat("%#-+26.23X", big, "+0X001234567890ABCDEF12345")
+testformat("%#-+27.23X", big, "+0X001234567890ABCDEF12345 ")
+testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345")
 # next one gets two leading zeroes from precision, and another from the
 # 0 flag and the width
-testboth("%#+027.23X", big, "+0X0001234567890ABCDEF12345")
+testformat("%#+027.23X", big, "+0X0001234567890ABCDEF12345")
 # same, except no 0 flag
-testboth("%#+27.23X", big, " +0X001234567890ABCDEF12345")
+testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345")
+testformat("%x", float(big), "123456_______________", 6)
 
 big = 0o12345670123456701234567012345670  # 32 octal digits
-testboth("%o", big, "12345670123456701234567012345670")
-testboth("%o", -big, "-12345670123456701234567012345670")
-testboth("%5o", -big, "-12345670123456701234567012345670")
-testboth("%33o", -big, "-12345670123456701234567012345670")
-testboth("%34o", -big, " -12345670123456701234567012345670")
-testboth("%-34o", -big, "-12345670123456701234567012345670 ")
-testboth("%034o", -big, "-012345670123456701234567012345670")
-testboth("%-034o", -big, "-12345670123456701234567012345670 ")
-testboth("%036o", -big, "-00012345670123456701234567012345670")
-testboth("%036o", big, "000012345670123456701234567012345670")
-testboth("%0+36o", big, "+00012345670123456701234567012345670")
-testboth("%+36o", big, "   +12345670123456701234567012345670")
-testboth("%36o", big, "    12345670123456701234567012345670")
-testboth("%.2o", big, "12345670123456701234567012345670")
-testboth("%.32o", big, "12345670123456701234567012345670")
-testboth("%.33o", big, "012345670123456701234567012345670")
-testboth("%34.33o", big, " 012345670123456701234567012345670")
-testboth("%-34.33o", big, "012345670123456701234567012345670 ")
-testboth("%o", big, "12345670123456701234567012345670")
-testboth("%#o", big, "0o12345670123456701234567012345670")
-testboth("%#o", -big, "-0o12345670123456701234567012345670")
-testboth("%#.34o", -big, "-0o0012345670123456701234567012345670")
-testboth("%#+.34o", big, "+0o0012345670123456701234567012345670")
-testboth("%# .34o", big, " 0o0012345670123456701234567012345670")
-testboth("%#-+.34o", big, "+0o0012345670123456701234567012345670")
-testboth("%#-+39.34o", big, "+0o0012345670123456701234567012345670  ")
-testboth("%#+39.34o", big, "  +0o0012345670123456701234567012345670")
+testformat("%o", big, "12345670123456701234567012345670")
+testformat("%o", -big, "-12345670123456701234567012345670")
+testformat("%5o", -big, "-12345670123456701234567012345670")
+testformat("%33o", -big, "-12345670123456701234567012345670")
+testformat("%34o", -big, " -12345670123456701234567012345670")
+testformat("%-34o", -big, "-12345670123456701234567012345670 ")
+testformat("%034o", -big, "-012345670123456701234567012345670")
+testformat("%-034o", -big, "-12345670123456701234567012345670 ")
+testformat("%036o", -big, "-00012345670123456701234567012345670")
+testformat("%036o", big, "000012345670123456701234567012345670")
+testformat("%0+36o", big, "+00012345670123456701234567012345670")
+testformat("%+36o", big, "   +12345670123456701234567012345670")
+testformat("%36o", big, "    12345670123456701234567012345670")
+testformat("%.2o", big, "12345670123456701234567012345670")
+testformat("%.32o", big, "12345670123456701234567012345670")
+testformat("%.33o", big, "012345670123456701234567012345670")
+testformat("%34.33o", big, " 012345670123456701234567012345670")
+testformat("%-34.33o", big, "012345670123456701234567012345670 ")
+testformat("%o", big, "12345670123456701234567012345670")
+testformat("%#o", big, "0o12345670123456701234567012345670")
+testformat("%#o", -big, "-0o12345670123456701234567012345670")
+testformat("%#.34o", -big, "-0o0012345670123456701234567012345670")
+testformat("%#+.34o", big, "+0o0012345670123456701234567012345670")
+testformat("%# .34o", big, " 0o0012345670123456701234567012345670")
+testformat("%#-+.34o", big, "+0o0012345670123456701234567012345670")
+testformat("%#-+39.34o", big, "+0o0012345670123456701234567012345670  ")
+testformat("%#+39.34o", big, "  +0o0012345670123456701234567012345670")
 # next one gets one leading zero from precision
-testboth("%.33o", big, "012345670123456701234567012345670")
+testformat("%.33o", big, "012345670123456701234567012345670")
 # one leading zero from precision
-testboth("%#.33o", big, "0o012345670123456701234567012345670")
+testformat("%#.33o", big, "0o012345670123456701234567012345670")
 # leading zero vanishes
-testboth("%#.32o", big, "0o12345670123456701234567012345670")
+testformat("%#.32o", big, "0o12345670123456701234567012345670")
 # one leading zero from precision, and another from '0' flag & width
-testboth("%034.33o", big, "0012345670123456701234567012345670")
+testformat("%034.33o", big, "0012345670123456701234567012345670")
 # max width includes base marker; padding zeroes come after marker
-testboth("%0#38.33o", big, "0o000012345670123456701234567012345670")
+testformat("%0#38.33o", big, "0o000012345670123456701234567012345670")
 # padding spaces come before marker
-testboth("%#36.33o", big, " 0o012345670123456701234567012345670")
+testformat("%#36.33o", big, " 0o012345670123456701234567012345670")
+testformat("%o", float(big), "123456__________________________", 6)
 
 # Some small ints, in both Python int and long flavors).
-testboth("%d", 42, "42")
-testboth("%d", -42, "-42")
-testboth("%#x", 1, "0x1")
-testboth("%#X", 1, "0X1")
-testboth("%#o", 1, "0o1")
-testboth("%#o", 1, "0o1")
-testboth("%#o", 0, "0o0")
-testboth("%#o", 0, "0o0")
-testboth("%o", 0, "0")
-testboth("%d", 0, "0")
-testboth("%#x", 0, "0x0")
-testboth("%#X", 0, "0X0")
-
-testboth("%x", 0x42, "42")
-testboth("%x", -0x42, "-42")
-
-testboth("%o", 0o42, "42")
-testboth("%o", -0o42, "-42")
-testboth("%o", 0o42, "42")
-testboth("%o", -0o42, "-42")
+testformat("%d", 42, "42")
+testformat("%d", -42, "-42")
+testformat("%#x", 1, "0x1")
+testformat("%#X", 1, "0X1")
+testformat("%#o", 1, "0o1")
+testformat("%#o", 1, "0o1")
+testformat("%#o", 0, "0o0")
+testformat("%#o", 0, "0o0")
+testformat("%o", 0, "0")
+testformat("%d", 0, "0")
+testformat("%#x", 0, "0x0")
+testformat("%#X", 0, "0X0")
+
+testformat("%x", 0x42, "42")
+testformat("%x", -0x42, "-42")
+testformat("%x", float(0x42), "42")
+
+testformat("%o", 0o42, "42")
+testformat("%o", -0o42, "-42")
+testformat("%o", 0o42, "42")
+testformat("%o", -0o42, "-42")
+testformat("%o", float(0o42), "42")
 
 # Test exception for unknown format characters
 if verbose:
@@ -223,7 +234,8 @@
 test_exc(str(b'abc %\u3000', 'raw-unicode-escape'), 1, ValueError,
          "unsupported format character '?' (0x3000) at index 5")
 
-test_exc('%d', '1', TypeError, "an integer is required")
+#test_exc('%d', '1', TypeError, "an integer is required")
+test_exc('%d', '1', TypeError, '%d format: a number is required, not str')
 test_exc('%g', '1', TypeError, "a float is required")
 test_exc('no format', '1', TypeError,
          "not all arguments converted during string formatting")

Modified: python/branches/py3k-importlib/Lib/test/test_frozen.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_frozen.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_frozen.py	Thu Mar 27 00:48:05 2008
@@ -7,34 +7,37 @@
 
 class FrozenTests(unittest.TestCase):
     def test_frozen(self):
-
-        with captured_stdout() as stdout:
-            try:
-                import __hello__
-            except ImportError as x:
-                self.fail("import __hello__ failed:" + str(x))
-
-            try:
-                import __phello__
-            except ImportError as x:
-                self.fail("import __phello__ failed:" + str(x))
-
-            try:
-                import __phello__.spam
-            except ImportError as x:
-                self.fail("import __phello__.spam failed:" + str(x))
-
-            if sys.platform != "mac":  # On the Mac this import does succeed.
-                try:
-                    import __phello__.foo
-                except ImportError:
-                    pass
-                else:
-                    self.fail("import __phello__.foo should have failed")
-
-        self.assertEquals(stdout.getvalue(),
-                          'Hello world...\nHello world...\nHello world...\n')
-
+        try:
+            import __hello__
+        except ImportError as x:
+            self.fail("import __hello__ failed:" + str(x))
+        self.assertEqual(__hello__.initialized, True)
+        self.assertEqual(len(dir(__hello__)), 6, dir(__hello__))
+
+        try:
+            import __phello__
+        except ImportError as x:
+            self.fail("import __phello__ failed:" + str(x))
+        self.assertEqual(__phello__.initialized, True)
+        if not "__phello__.spam" in sys.modules:
+            self.assertEqual(len(dir(__phello__)), 7, dir(__phello__))
+        else:
+            self.assertEqual(len(dir(__phello__)), 8, dir(__phello__))
+
+        try:
+            import __phello__.spam
+        except ImportError as x:
+            self.fail("import __phello__.spam failed:" + str(x))
+        self.assertEqual(__phello__.spam.initialized, True)
+        self.assertEqual(len(dir(__phello__.spam)), 6)
+        self.assertEqual(len(dir(__phello__)), 8)
+
+        try:
+            import __phello__.foo
+        except ImportError:
+            pass
+        else:
+            self.fail("import __phello__.foo should have failed")
 
 def test_main():
     run_unittest(FrozenTests)

Modified: python/branches/py3k-importlib/Lib/test/test_ftplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_ftplib.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_ftplib.py	Thu Mar 27 00:48:05 2008
@@ -6,34 +6,48 @@
 from unittest import TestCase
 from test import test_support
 
-def server(evt, ready):
+server_port = None
+
+# This function sets the evt 3 times:
+#  1) when the connection is ready to be accepted.
+#  2) when it is safe for the caller to close the connection
+#  3) when we have closed the socket
+def server(evt):
+    global server_port
     serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     serv.settimeout(3)
     serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-    serv.bind(("", 9091))
+    server_port = test_support.bind_port(serv, "", 9091)
     serv.listen(5)
-    ready.set()
+
+    # (1) Signal the caller that we are ready to accept the connection.
+    evt.set()
     try:
         conn, addr = serv.accept()
     except socket.timeout:
         pass
     else:
-        conn.send("1 Hola mundo\n")
+        conn.send(b"1 Hola mundo\n")
+        # (2) Signal the caller that it is safe to close the socket.
+        evt.set()
         conn.close()
     finally:
         serv.close()
+        # (3) Signal the caller that we are done.
         evt.set()
 
 class GeneralTests(TestCase):
 
     def setUp(self):
-        ftplib.FTP.port = 9091
         self.evt = threading.Event()
-        ready = threading.Event()
-        threading.Thread(target=server, args=(self.evt, ready)).start()
-        ready.wait()
+        threading.Thread(target=server, args=(self.evt,)).start()
+        # Wait for the server to be ready.
+        self.evt.wait()
+        self.evt.clear()
+        ftplib.FTP.port = server_port
 
     def tearDown(self):
+        # Wait on the closing of the socket (this shouldn't be necessary).
         self.evt.wait()
 
     def testBasic(self):
@@ -42,30 +56,35 @@
 
         # connects
         ftp = ftplib.FTP("localhost")
+        self.evt.wait()
         ftp.sock.close()
 
     def testTimeoutDefault(self):
         # default
         ftp = ftplib.FTP("localhost")
         self.assertTrue(ftp.sock.gettimeout() is None)
+        self.evt.wait()
         ftp.sock.close()
 
     def testTimeoutValue(self):
         # a value
         ftp = ftplib.FTP("localhost", timeout=30)
         self.assertEqual(ftp.sock.gettimeout(), 30)
+        self.evt.wait()
         ftp.sock.close()
 
     def testTimeoutConnect(self):
         ftp = ftplib.FTP()
         ftp.connect("localhost", timeout=30)
         self.assertEqual(ftp.sock.gettimeout(), 30)
+        self.evt.wait()
         ftp.sock.close()
 
     def testTimeoutDifferentOrder(self):
         ftp = ftplib.FTP(timeout=30)
         ftp.connect("localhost")
         self.assertEqual(ftp.sock.gettimeout(), 30)
+        self.evt.wait()
         ftp.sock.close()
 
     def testTimeoutDirectAccess(self):
@@ -73,6 +92,7 @@
         ftp.timeout = 30
         ftp.connect("localhost")
         self.assertEqual(ftp.sock.gettimeout(), 30)
+        self.evt.wait()
         ftp.sock.close()
 
     def testTimeoutNone(self):
@@ -84,10 +104,10 @@
         finally:
             socket.setdefaulttimeout(previous)
         self.assertEqual(ftp.sock.gettimeout(), 30)
+        self.evt.wait()
         ftp.close()
 
 
-
 def test_main(verbose=None):
     test_support.run_unittest(GeneralTests)
 

Modified: python/branches/py3k-importlib/Lib/test/test_funcattrs.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_funcattrs.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_funcattrs.py	Thu Mar 27 00:48:05 2008
@@ -1,383 +1,233 @@
-from test.test_support import verbose, TestFailed, verify
+from test import test_support
 import types
+import unittest
 
-class F:
-    def a(self):
-        pass
-
-def b():
-    'my docstring'
-    pass
-
-# __module__ is a special attribute
-verify(b.__module__ == __name__)
-verify(verify.__module__ == "test.test_support")
-
-# setting attributes on functions
-try:
-    b.publish
-except AttributeError: pass
-else: raise TestFailed('expected AttributeError')
-
-if b.__dict__ != {}:
-    raise TestFailed('expected unassigned func.__dict__ to be {}')
-
-b.publish = 1
-if b.publish != 1:
-    raise TestFailed('function attribute not set to expected value')
-
-docstring = 'its docstring'
-b.__doc__ = docstring
-if b.__doc__ != docstring:
-    raise TestFailed('problem with setting __doc__ attribute')
-
-if 'publish' not in dir(b):
-    raise TestFailed('attribute not in dir()')
-
-try:
-    del b.__dict__
-except TypeError: pass
-else: raise TestFailed('del func.__dict__ expected TypeError')
-
-b.publish = 1
-try:
-    b.__dict__ = None
-except TypeError: pass
-else: raise TestFailed('func.__dict__ = None expected TypeError')
-
-d = {'hello': 'world'}
-b.__dict__ = d
-if b.__dict__ is not d:
-    raise TestFailed('func.__dict__ assignment to dictionary failed')
-if b.hello != 'world':
-    raise TestFailed('attribute after func.__dict__ assignment failed')
-
-f1 = F()
-f2 = F()
-
-try:
-    F.a.publish
-except AttributeError: pass
-else: raise TestFailed('expected AttributeError')
-
-try:
-    f1.a.publish
-except AttributeError: pass
-else: raise TestFailed('expected AttributeError')
-
-# In Python 2.1 beta 1, we disallowed setting attributes on unbound methods
-# (it was already disallowed on bound methods).  See the PEP for details.
-try:
-    F.a.publish = 1
-except (AttributeError, TypeError): pass
-else: raise TestFailed('expected AttributeError or TypeError')
-
-# But setting it explicitly on the underlying function object is okay.
-F.a.im_func.publish = 1
-
-if F.a.publish != 1:
-    raise TestFailed('unbound method attribute not set to expected value')
-
-if f1.a.publish != 1:
-    raise TestFailed('bound method attribute access did not work')
-
-if f2.a.publish != 1:
-    raise TestFailed('bound method attribute access did not work')
-
-if 'publish' not in dir(F.a):
-    raise TestFailed('attribute not in dir()')
-
-try:
-    f1.a.publish = 0
-except (AttributeError, TypeError): pass
-else: raise TestFailed('expected AttributeError or TypeError')
-
-# See the comment above about the change in semantics for Python 2.1b1
-try:
-    F.a.myclass = F
-except (AttributeError, TypeError): pass
-else: raise TestFailed('expected AttributeError or TypeError')
-
-F.a.im_func.myclass = F
-
-f1.a.myclass
-f2.a.myclass
-f1.a.myclass
-F.a.myclass
-
-if f1.a.myclass is not f2.a.myclass or \
-       f1.a.myclass is not F.a.myclass:
-    raise TestFailed('attributes were not the same')
-
-# try setting __dict__
-try:
-    F.a.__dict__ = (1, 2, 3)
-except (AttributeError, TypeError): pass
-else: raise TestFailed('expected TypeError or AttributeError')
-
-F.a.im_func.__dict__ = {'one': 11, 'two': 22, 'three': 33}
-
-if f1.a.two != 22:
-    raise TestFailed('setting __dict__')
-
-from UserDict import UserDict
-d = UserDict({'four': 44, 'five': 55})
-
-try:
-    F.a.__dict__ = d
-except (AttributeError, TypeError): pass
-else: raise TestFailed
-
-if f2.a.one != f1.a.one != F.a.one != 11:
-    raise TestFailed
-
-# im_func may not be a Python method!
-import new
-F.id = new.instancemethod(id, None, F)
-
-eff = F()
-if eff.id() != id(eff):
-    raise TestFailed
-
-try:
-    F.id.foo
-except AttributeError: pass
-else: raise TestFailed
-
-try:
-    F.id.foo = 12
-except (AttributeError, TypeError): pass
-else: raise TestFailed
-
-try:
-    F.id.foo
-except AttributeError: pass
-else: raise TestFailed
-
-try:
-    eff.id.foo
-except AttributeError: pass
-else: raise TestFailed
-
-try:
-    eff.id.foo = 12
-except (AttributeError, TypeError): pass
-else: raise TestFailed
-
-try:
-    eff.id.foo
-except AttributeError: pass
-else: raise TestFailed
-
-# Regression test for a crash in pre-2.1a1
-def another():
-    pass
-
-try:
-    del another.__dict__
-except TypeError: pass
-else: raise TestFailed
-
-try:
-    del another.__dict__
-except TypeError: pass
-else: raise TestFailed
-
-try:
-    another.__dict__ = None
-except TypeError: pass
-else: raise TestFailed
-
-try:
-    del another.bar
-except AttributeError: pass
-else: raise TestFailed
-
-# This isn't specifically related to function attributes, but it does test a
-# core dump regression in funcobject.c
-del another.__defaults__
-
-def foo():
-    pass
-
-def bar():
-    pass
-
-def temp():
-    print(1)
-
-if foo==bar:
-    raise TestFailed
-
-d={}
-d[foo] = 1
-
-foo.__code__ = temp.__code__
-
-d[foo]
-
-# Test all predefined function attributes systematically
-
-def cantset(obj, name, value, exception=(AttributeError, TypeError)):
-    verify(hasattr(obj, name)) # Otherwise it's probably a typo
-    try:
-        setattr(obj, name, value)
-    except exception:
-        pass
-    else:
-        raise TestFailed("shouldn't be able to set %s to %r" % (name, value))
-    try:
-        delattr(obj, name)
-    except (AttributeError, TypeError):
-        pass
-    else:
-        raise TestFailed("shouldn't be able to del %s" % name)
-
-def test_func_closure():
-    a = 12
-    def f(): print(a)
-    c = f.__closure__
-    verify(isinstance(c, tuple))
-    verify(len(c) == 1)
-    verify(c[0].__class__.__name__ == "cell") # don't have a type object handy
-    cantset(f, "__closure__", c)
-
-def test_func_doc():
-    def f(): pass
-    verify(f.__doc__ is None)
-    f.__doc__ = "hello"
-    verify(f.__doc__ == "hello")
-    del f.__doc__
-    verify(f.__doc__ is None)
-
-def test_func_globals():
-    def f(): pass
-    verify(f.__globals__ is globals())
-    cantset(f, "__globals__", globals())
-
-def test_func_name():
-    def f(): pass
-    verify(f.__name__ == "f")
-    f.__name__ = "g"
-    verify(f.__name__ == "g")
-    cantset(f, "__globals__", 1)
-    cantset(f, "__name__", 1)
-    # test that you can access func.__name__ in restricted mode
-    s = """def f(): pass\nf.__name__"""
-    exec(s, {'__builtins__':{}})
-
-
-def test_func_code():
-    a = b = 24
-    def f(): pass
-    def g(): print(12)
-    def f1(): print(a)
-    def g1(): print(b)
-    def f2(): print(a, b)
-    verify(type(f.__code__) is types.CodeType)
-    f.__code__ = g.__code__
-    cantset(f, "__code__", None)
-    # can't change the number of free vars
-    cantset(f,  "__code__", f1.__code__, exception=ValueError)
-    cantset(f1, "__code__",  f.__code__, exception=ValueError)
-    cantset(f1, "__code__", f2.__code__, exception=ValueError)
-    f1.__code__ = g1.__code__
-
-def test_func_defaults():
-    def f(a, b): return (a, b)
-    verify(f.__defaults__ is None)
-    f.__defaults__ = (1, 2)
-    verify(f.__defaults__ == (1, 2))
-    verify(f(10) == (10, 2))
-    def g(a=1, b=2): return (a, b)
-    verify(g.__defaults__ == (1, 2))
-    del g.__defaults__
-    verify(g.__defaults__ is None)
-    try:
-        g()
-    except TypeError:
-        pass
-    else:
-        raise TestFailed("shouldn't be allowed to call g() w/o defaults")
-
-def test_func_dict():
-    def f(): pass
-    a = f.__dict__
-    verify(a == {})
-    f.hello = 'world'
-    verify(a == {'hello': 'world'})
-    verify(a is f.__dict__)
-    f.__dict__ = {'world': 'hello'}
-    verify(f.world == "hello")
-    verify(f.__dict__ == {'world': 'hello'})
-    cantset(f, "__dict__", None)
-
-def test_im_class():
-    class C:
-        def foo(self): pass
-    verify(C.foo.im_class is C)
-    verify(C().foo.im_class is C)
-    cantset(C.foo, "im_class", C)
-    cantset(C().foo, "im_class", C)
-
-def test_im_func():
-    def foo(self): pass
-    class C:
-        pass
-    C.foo = foo
-    verify(C.foo.im_func is foo)
-    verify(C().foo.im_func is foo)
-    cantset(C.foo, "im_func", foo)
-    cantset(C().foo, "im_func", foo)
-
-def test_im_self():
-    class C:
-        def foo(self): pass
-    verify(C.foo.im_self is None)
-    c = C()
-    verify(c.foo.im_self is c)
-    cantset(C.foo, "im_self", None)
-    cantset(c.foo, "im_self", c)
-
-def test_im_dict():
-    class C:
-        def foo(self): pass
-        foo.bar = 42
-    verify(C.foo.__dict__ == {'bar': 42})
-    verify(C().foo.__dict__ == {'bar': 42})
-    cantset(C.foo, "__dict__", C.foo.__dict__)
-    cantset(C().foo, "__dict__", C.foo.__dict__)
-
-def test_im_doc():
-    class C:
-        def foo(self): "hello"
-    verify(C.foo.__doc__ == "hello")
-    verify(C().foo.__doc__ == "hello")
-    cantset(C.foo, "__doc__", "hello")
-    cantset(C().foo, "__doc__", "hello")
-
-def test_im_name():
-    class C:
-        def foo(self): pass
-    verify(C.foo.__name__ == "foo")
-    verify(C().foo.__name__ == "foo")
-    cantset(C.foo, "__name__", "foo")
-    cantset(C().foo, "__name__", "foo")
-
-def testmore():
-    test_func_closure()
-    test_func_doc()
-    test_func_globals()
-    test_func_name()
-    test_func_code()
-    test_func_defaults()
-    test_func_dict()
-    # Tests for instance method attributes
-    test_im_class()
-    test_im_func()
-    test_im_self()
-    test_im_dict()
-    test_im_doc()
-    test_im_name()
+class FuncAttrsTest(unittest.TestCase):
+    def setUp(self):
+        class F:
+            def a(self):
+                pass
+        def b():
+            return 3
+        self.fi = F()
+        self.F = F
+        self.b = b
+
+    def cannot_set_attr(self, obj, name, value, exceptions):
+        try:
+            setattr(obj, name, value)
+        except exceptions:
+            pass
+        else:
+            self.fail("shouldn't be able to set %s to %r" % (name, value))
+        try:
+            delattr(obj, name)
+        except exceptions:
+            pass
+        else:
+            self.fail("shouldn't be able to del %s" % name)
+
+
+class FunctionPropertiesTest(FuncAttrsTest):
+    # Include the external setUp method that is common to all tests
+    def test_module(self):
+        self.assertEqual(self.b.__module__, __name__)
+
+    def test_dir_includes_correct_attrs(self):
+        self.b.known_attr = 7
+        self.assert_('known_attr' in dir(self.b),
+            "set attributes not in dir listing of method")
+        # Test on underlying function object of method
+        self.F.a.known_attr = 7
+        self.assert_('known_attr' in dir(self.fi.a), "set attribute on function "
+                     "implementations, should show up in next dir")
+
+    def test_duplicate_function_equality(self):
+        # Body of `duplicate' is the exact same as self.b
+        def duplicate():
+            'my docstring'
+            return 3
+        self.assertNotEqual(self.b, duplicate)
+
+    def test_copying___code__(self):
+        def test(): pass
+        self.assertEqual(test(), None)
+        test.__code__ = self.b.__code__
+        self.assertEqual(test(), 3) # self.b always returns 3, arbitrarily
+
+    def test___globals__(self):
+        self.assertEqual(self.b.__globals__, globals())
+        self.cannot_set_attr(self.b, '__globals__', 2, (AttributeError, TypeError))
+
+    def test___name__(self):
+        self.assertEqual(self.b.__name__, 'b')
+        self.b.__name__ = 'c'
+        self.assertEqual(self.b.__name__, 'c')
+        self.b.__name__ = 'd'
+        self.assertEqual(self.b.__name__, 'd')
+        # __name__ and __name__ must be a string
+        self.cannot_set_attr(self.b, '__name__', 7, TypeError)
+        # __name__ must be available when in restricted mode. Exec will raise
+        # AttributeError if __name__ is not available on f.
+        s = """def f(): pass\nf.__name__"""
+        exec(s, {'__builtins__': {}})
+        # Test on methods, too
+        self.assertEqual(self.fi.a.__name__, 'a')
+        self.cannot_set_attr(self.fi.a, "__name__", 'a', AttributeError)
+
+    def test___code__(self):
+        num_one, num_two = 7, 8
+        def a(): pass
+        def b(): return 12
+        def c(): return num_one
+        def d(): return num_two
+        def e(): return num_one, num_two
+        for func in [a, b, c, d, e]:
+            self.assertEqual(type(func.__code__), types.CodeType)
+        self.assertEqual(c(), 7)
+        self.assertEqual(d(), 8)
+        d.__code__ = c.__code__
+        self.assertEqual(c.__code__, d.__code__)
+        self.assertEqual(c(), 7)
+        # self.assertEqual(d(), 7)
+        try: b.__code__ = c.__code__
+        except ValueError: pass
+        else: self.fail(
+            "__code__ with different numbers of free vars should not be "
+            "possible")
+        try: e.__code__ = d.__code__
+        except ValueError: pass
+        else: self.fail(
+            "__code__ with different numbers of free vars should not be "
+            "possible")
+
+    def test_blank_func_defaults(self):
+        self.assertEqual(self.b.__defaults__, None)
+        del self.b.__defaults__
+        self.assertEqual(self.b.__defaults__, None)
+
+    def test_func_default_args(self):
+        def first_func(a, b):
+            return a+b
+        def second_func(a=1, b=2):
+            return a+b
+        self.assertEqual(first_func.__defaults__, None)
+        self.assertEqual(second_func.__defaults__, (1, 2))
+        first_func.__defaults__ = (1, 2)
+        self.assertEqual(first_func.__defaults__, (1, 2))
+        self.assertEqual(first_func(), 3)
+        self.assertEqual(first_func(3), 5)
+        self.assertEqual(first_func(3, 5), 8)
+        del second_func.__defaults__
+        self.assertEqual(second_func.__defaults__, None)
+        try: second_func()
+        except TypeError: pass
+        else: self.fail(
+            "func_defaults does not update; deleting it does not remove "
+            "requirement")
+
+class ImplicitReferencesTest(FuncAttrsTest):
+
+    def test___class__(self):
+        self.assertEqual(self.fi.a.__self__.__class__, self.F)
+        self.cannot_set_attr(self.fi.a, "__class__", self.F, TypeError)
+
+    def test___func__(self):
+        self.assertEqual(self.fi.a.__func__, self.F.a)
+        self.cannot_set_attr(self.fi.a, "__func__", self.F.a, AttributeError)
+
+    def test___self__(self):
+        self.assertEqual(self.fi.a.__self__, self.fi)
+        self.cannot_set_attr(self.fi.a, "__self__", self.fi, AttributeError)
+
+    def test___func___non_method(self):
+        # Behavior should be the same when a method is added via an attr
+        # assignment
+        self.fi.id = types.MethodType(id, self.fi)
+        self.assertEqual(self.fi.id(), id(self.fi))
+        # Test usage
+        try: self.fi.id.unknown_attr
+        except AttributeError: pass
+        else: self.fail("using unknown attributes should raise AttributeError")
+        # Test assignment and deletion
+        self.cannot_set_attr(self.fi.id, 'unknown_attr', 2, AttributeError)
+
+class ArbitraryFunctionAttrTest(FuncAttrsTest):
+    def test_set_attr(self):
+        self.b.known_attr = 7
+        self.assertEqual(self.b.known_attr, 7)
+        try: self.fi.a.known_attr = 7
+        except AttributeError: pass
+        else: self.fail("setting attributes on methods should raise error")
+
+    def test_delete_unknown_attr(self):
+        try: del self.b.unknown_attr
+        except AttributeError: pass
+        else: self.fail("deleting unknown attribute should raise TypeError")
+
+    def test_unset_attr(self):
+        for func in [self.b, self.fi.a]:
+            try:  func.non_existant_attr
+            except AttributeError: pass
+            else: self.fail("using unknown attributes should raise "
+                            "AttributeError")
+
+class FunctionDictsTest(FuncAttrsTest):
+    def test_setting_dict_to_invalid(self):
+        self.cannot_set_attr(self.b, '__dict__', None, TypeError)
+        from collections import UserDict
+        d = UserDict({'known_attr': 7})
+        self.cannot_set_attr(self.fi.a.__func__, '__dict__', d, TypeError)
+
+    def test_setting_dict_to_valid(self):
+        d = {'known_attr': 7}
+        self.b.__dict__ = d
+        # Test assignment
+        self.assertEqual(d, self.b.__dict__)
+        # ... and on all the different ways of referencing the method's func
+        self.F.a.__dict__ = d
+        self.assertEqual(d, self.fi.a.__func__.__dict__)
+        self.assertEqual(d, self.fi.a.__dict__)
+        # Test value
+        self.assertEqual(self.b.known_attr, 7)
+        self.assertEqual(self.b.__dict__['known_attr'], 7)
+        # ... and again, on all the different method's names
+        self.assertEqual(self.fi.a.__func__.known_attr, 7)
+        self.assertEqual(self.fi.a.known_attr, 7)
+
+    def test_delete___dict__(self):
+        try: del self.b.__dict__
+        except TypeError: pass
+        else: self.fail("deleting function dictionary should raise TypeError")
+
+    def test_unassigned_dict(self):
+        self.assertEqual(self.b.__dict__, {})
+
+    def test_func_as_dict_key(self):
+        value = "Some string"
+        d = {}
+        d[self.b] = value
+        self.assertEqual(d[self.b], value)
+
+class FunctionDocstringTest(FuncAttrsTest):
+    def test_set_docstring_attr(self):
+        self.assertEqual(self.b.__doc__, None)
+        docstr = "A test method that does nothing"
+        self.b.__doc__ = docstr
+        self.F.a.__doc__ = docstr
+        self.assertEqual(self.b.__doc__, docstr)
+        self.assertEqual(self.fi.a.__doc__, docstr)
+        self.cannot_set_attr(self.fi.a, "__doc__", docstr, AttributeError)
+
+    def test_delete_docstring(self):
+        self.b.__doc__ = "The docstring"
+        del self.b.__doc__
+        self.assertEqual(self.b.__doc__, None)
+
+def test_main():
+    test_support.run_unittest(FunctionPropertiesTest, ImplicitReferencesTest,
+                              ArbitraryFunctionAttrTest, FunctionDictsTest,
+                              FunctionDocstringTest)
 
-testmore()
+if __name__ == "__main__":
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_gc.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_gc.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_gc.py	Thu Mar 27 00:48:05 2008
@@ -236,21 +236,33 @@
         gc.disable()
         gc.set_threshold(*thresholds)
 
+    # The following two tests are fragile:
+    # They precisely count the number of allocations,
+    # which is highly implementation-dependent.
+    # For example:
+    # - disposed tuples are not freed, but reused
+    # - the call to assertEqual somehow avoids building its args tuple
     def test_get_count(self):
+        # Avoid future allocation of method object
+        assertEqual = self.assertEqual
         gc.collect()
-        self.assertEqual(gc.get_count(), (0, 0, 0))
+        assertEqual(gc.get_count(), (0, 0, 0))
         a = dict()
-        self.assertEqual(gc.get_count(), (1, 0, 0))
+        # since gc.collect(), we created two objects:
+        # the dict, and the tuple returned by get_count()
+        assertEqual(gc.get_count(), (2, 0, 0))
 
     def test_collect_generations(self):
+        # Avoid future allocation of method object
+        assertEqual = self.assertEqual
         gc.collect()
         a = dict()
         gc.collect(0)
-        self.assertEqual(gc.get_count(), (0, 1, 0))
+        assertEqual(gc.get_count(), (0, 1, 0))
         gc.collect(1)
-        self.assertEqual(gc.get_count(), (0, 0, 1))
+        assertEqual(gc.get_count(), (0, 0, 1))
         gc.collect(2)
-        self.assertEqual(gc.get_count(), (0, 0, 0))
+        assertEqual(gc.get_count(), (0, 0, 0))
 
     def test_trashcan(self):
         class Ouch:

Modified: python/branches/py3k-importlib/Lib/test/test_gdbm.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_gdbm.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_gdbm.py	Thu Mar 27 00:48:05 2008
@@ -1,46 +1,81 @@
-#! /usr/bin/env python
-"""Test script for the gdbm module
-   Roger E. Masse
-"""
-
 import gdbm
-from gdbm import error
-from test.test_support import verbose, verify, TestFailed, TESTFN
+import unittest
+import os
+from test.test_support import verbose, TESTFN, run_unittest, unlink
+
 
 filename = TESTFN
 
-g = gdbm.open(filename, 'c')
-verify(g.keys() == [])
-g[b'a'] = b'b'
-g[b'12345678910'] = b'019237410982340912840198242'
-a = g.keys()
-if verbose:
-    print('Test gdbm file keys: ', a)
-
-b'a' in g
-g.close()
-try:
-    g['a']
-except error:
-    pass
-else:
-    raise TestFailed("expected gdbm.error accessing closed database")
-g = gdbm.open(filename, 'r')
-g.close()
-g = gdbm.open(filename, 'w')
-g.close()
-g = gdbm.open(filename, 'n')
-g.close()
-try:
-    g = gdbm.open(filename, 'rx')
-    g.close()
-except error:
-    pass
-else:
-    raise TestFailed("expected gdbm.error when passing invalid open flags")
-
-try:
-    import os
-    os.unlink(filename)
-except:
-    pass
+class TestGdbm(unittest.TestCase):
+    def setUp(self):
+        self.g = None
+
+    def tearDown(self):
+        if self.g is not None:
+            self.g.close()
+        unlink(filename)
+
+    def test_key_methods(self):
+        self.g = gdbm.open(filename, 'c')
+        self.assertEqual(self.g.keys(), [])
+        self.g['a'] = 'b'
+        self.g['12345678910'] = '019237410982340912840198242'
+        key_set = set(self.g.keys())
+        self.assertEqual(key_set, set([b'a', b'12345678910']))
+        self.assert_(b'a' in self.g)
+        key = self.g.firstkey()
+        while key:
+            self.assert_(key in key_set)
+            key_set.remove(key)
+            key = self.g.nextkey(key)
+        self.assertRaises(KeyError, lambda: self.g['xxx'])
+
+    def test_error_conditions(self):
+        # Try to open a non-existent database.
+        unlink(filename)
+        self.assertRaises(gdbm.error, gdbm.open, filename, 'r')
+        # Try to access a closed database.
+        self.g = gdbm.open(filename, 'c')
+        self.g.close()
+        self.assertRaises(gdbm.error, lambda: self.g['a'])
+        # try pass an invalid open flag
+        self.assertRaises(gdbm.error, lambda: gdbm.open(filename, 'rx').close())
+
+    def test_flags(self):
+        # Test the flag parameter open() by trying all supported flag modes.
+        all = set(gdbm.open_flags)
+        # Test standard flags (presumably "crwn").
+        modes = all - set('fsu')
+        for mode in modes:
+            self.g = gdbm.open(filename, mode)
+            self.g.close()
+
+        # Test additional flags (presumably "fsu").
+        flags = all - set('crwn')
+        for mode in modes:
+            for flag in flags:
+                self.g = gdbm.open(filename, mode + flag)
+                self.g.close()
+
+    def test_reorganize(self):
+        self.g = gdbm.open(filename, 'c')
+        size0 = os.path.getsize(filename)
+
+        self.g['x'] = 'x' * 10000
+        size1 = os.path.getsize(filename)
+        self.assert_(size0 < size1)
+
+        del self.g['x']
+        # 'size' is supposed to be the same even after deleting an entry.
+        self.assertEqual(os.path.getsize(filename), size1)
+
+        self.g.reorganize()
+        size2 = os.path.getsize(filename)
+        self.assert_(size1 > size2 >= size0)
+
+
+def test_main():
+    run_unittest(TestGdbm)
+
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_generators.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_generators.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_generators.py	Thu Mar 27 00:48:05 2008
@@ -382,7 +382,7 @@
 >>> type(i)
 <type 'generator'>
 >>> [s for s in dir(i) if not s.startswith('_')]
-['close', 'gi_frame', 'gi_running', 'send', 'throw']
+['close', 'gi_code', 'gi_frame', 'gi_running', 'send', 'throw']
 >>> print(i.__next__.__doc__)
 x.__next__() <==> next(x)
 >>> iter(i) is i
@@ -444,7 +444,7 @@
 >>> roots = sets[:]
 
 >>> import random
->>> gen = random.WichmannHill(42)
+>>> gen = random.Random(42)
 >>> while 1:
 ...     for s in sets:
 ...         print(" %s->%s" % (s, s.find()), end='')
@@ -458,29 +458,29 @@
 ...     else:
 ...         break
  A->A B->B C->C D->D E->E F->F G->G H->H I->I J->J K->K L->L M->M
-merged D into G
- A->A B->B C->C D->G E->E F->F G->G H->H I->I J->J K->K L->L M->M
-merged C into F
- A->A B->B C->F D->G E->E F->F G->G H->H I->I J->J K->K L->L M->M
+merged I into A
+ A->A B->B C->C D->D E->E F->F G->G H->H I->A J->J K->K L->L M->M
+merged D into C
+ A->A B->B C->C D->C E->E F->F G->G H->H I->A J->J K->K L->L M->M
+merged K into H
+ A->A B->B C->C D->C E->E F->F G->G H->H I->A J->J K->H L->L M->M
 merged L into A
- A->A B->B C->F D->G E->E F->F G->G H->H I->I J->J K->K L->A M->M
-merged H into E
- A->A B->B C->F D->G E->E F->F G->G H->E I->I J->J K->K L->A M->M
-merged B into E
- A->A B->E C->F D->G E->E F->F G->G H->E I->I J->J K->K L->A M->M
+ A->A B->B C->C D->C E->E F->F G->G H->H I->A J->J K->H L->A M->M
+merged E into A
+ A->A B->B C->C D->C E->A F->F G->G H->H I->A J->J K->H L->A M->M
+merged B into G
+ A->A B->G C->C D->C E->A F->F G->G H->H I->A J->J K->H L->A M->M
+merged A into F
+ A->F B->G C->C D->C E->F F->F G->G H->H I->F J->J K->H L->F M->M
+merged H into G
+ A->F B->G C->C D->C E->F F->F G->G H->G I->F J->J K->G L->F M->M
+merged F into J
+ A->J B->G C->C D->C E->J F->J G->G H->G I->J J->J K->G L->J M->M
+merged M into C
+ A->J B->G C->C D->C E->J F->J G->G H->G I->J J->J K->G L->J M->C
 merged J into G
- A->A B->E C->F D->G E->E F->F G->G H->E I->I J->G K->K L->A M->M
-merged E into G
- A->A B->G C->F D->G E->G F->F G->G H->G I->I J->G K->K L->A M->M
-merged M into G
- A->A B->G C->F D->G E->G F->F G->G H->G I->I J->G K->K L->A M->G
-merged I into K
- A->A B->G C->F D->G E->G F->F G->G H->G I->K J->G K->K L->A M->G
-merged K into A
- A->A B->G C->F D->G E->G F->F G->G H->G I->A J->G K->A L->A M->G
-merged F into A
- A->A B->G C->A D->G E->G F->A G->G H->G I->A J->G K->A L->A M->G
-merged A into G
+ A->G B->G C->C D->C E->G F->G G->G H->G I->G J->G K->G L->G M->C
+merged C into G
  A->G B->G C->G D->G E->G F->G G->G H->G I->G J->G K->G L->G M->G
 
 """
@@ -899,6 +899,24 @@
 >>> print(next(g))
 Traceback (most recent call last):
 StopIteration
+
+
+Test the gi_code attribute
+
+>>> def f():
+...     yield 5
+...
+>>> g = f()
+>>> g.gi_code is f.__code__
+True
+>>> next(g)
+5
+>>> next(g)
+Traceback (most recent call last):
+StopIteration
+>>> g.gi_code is f.__code__
+True
+
 """
 
 # conjoin is a simple backtracking generator, named in honor of Icon's
@@ -1668,6 +1686,21 @@
 exiting
 
 
+GeneratorExit is not caught by except Exception:
+
+>>> def f():
+...     try: yield
+...     except Exception:
+...         print('except')
+...     finally:
+...         print('finally')
+
+>>> g = f()
+>>> next(g)
+>>> del g
+finally
+
+
 Now let's try some ill-behaved generators:
 
 >>> def f():

Modified: python/branches/py3k-importlib/Lib/test/test_getargs2.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_getargs2.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_getargs2.py	Thu Mar 27 00:48:05 2008
@@ -1,8 +1,8 @@
 import unittest
 from test import test_support
-import sys
+from _testcapi import getargs_keywords
 
-import warnings, re
+import warnings
 warnings.filterwarnings("ignore",
                         category=DeprecationWarning,
                         message=".*integer argument expected, got float",
@@ -249,9 +249,57 @@
                 raise ValueError
         self.assertRaises(TypeError, getargs_tuple, 1, seq())
 
+class Keywords_TestCase(unittest.TestCase):
+    def test_positional_args(self):
+        # using all positional args
+        self.assertEquals(
+            getargs_keywords((1,2), 3, (4,(5,6)), (7,8,9), 10),
+            (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+            )
+    def test_mixed_args(self):
+        # positional and keyword args
+        self.assertEquals(
+            getargs_keywords((1,2), 3, (4,(5,6)), arg4=(7,8,9), arg5=10),
+            (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+            )
+    def test_keyword_args(self):
+        # all keywords
+        self.assertEquals(
+            getargs_keywords(arg1=(1,2), arg2=3, arg3=(4,(5,6)), arg4=(7,8,9), arg5=10),
+            (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+            )
+    def test_optional_args(self):
+        # missing optional keyword args, skipping tuples
+        self.assertEquals(
+            getargs_keywords(arg1=(1,2), arg2=3, arg5=10),
+            (1, 2, 3, -1, -1, -1, -1, -1, -1, 10)
+            )
+    def test_required_args(self):
+        # required arg missing
+        try:
+            getargs_keywords(arg1=(1,2))
+        except TypeError as err:
+            self.assertEquals(str(err), "Required argument 'arg2' (pos 2) not found")
+        else:
+            self.fail('TypeError should have been raised')
+    def test_too_many_args(self):
+        try:
+            getargs_keywords((1,2),3,(4,(5,6)),(7,8,9),10,111)
+        except TypeError as err:
+            self.assertEquals(str(err), "function takes at most 5 arguments (6 given)")
+        else:
+            self.fail('TypeError should have been raised')
+    def test_invalid_keyword(self):
+        # extraneous keyword arg
+        try:
+            getargs_keywords((1,2),3,arg5=10,arg666=666)
+        except TypeError as err:
+            self.assertEquals(str(err), "'arg666' is an invalid keyword argument for this function")
+        else:
+            self.fail('TypeError should have been raised')
 
 def test_main():
-    tests = [Signed_TestCase, Unsigned_TestCase, Tuple_TestCase]
+    tests = [Signed_TestCase, Unsigned_TestCase, Tuple_TestCase, Keywords_TestCase]
     try:
         from _testcapi import getargs_L, getargs_K
     except ImportError:

Modified: python/branches/py3k-importlib/Lib/test/test_getopt.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_getopt.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_getopt.py	Thu Mar 27 00:48:05 2008
@@ -167,8 +167,8 @@
         ['a1', 'a2']
         """
 
-        import new
-        m = new.module("libreftest", s)
+        import types
+        m = types.ModuleType("libreftest", s)
         run_doctest(m, verbose)
 
 

Modified: python/branches/py3k-importlib/Lib/test/test_gettext.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_gettext.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_gettext.py	Thu Mar 27 00:48:05 2008
@@ -146,13 +146,13 @@
         t.install(str=True)
         eq(_('mullusk'), 'bacon')
         # Test installation of other methods
-        import __builtin__
+        import builtins
         t.install(str=True, names=["gettext", "lgettext"])
         eq(_, t.ugettext)
-        eq(__builtin__.gettext, t.ugettext)
+        eq(builtins.gettext, t.ugettext)
         eq(lgettext, t.lgettext)
-        del __builtin__.gettext
-        del __builtin__.lgettext
+        del builtins.gettext
+        del builtins.lgettext
 
 
 class GettextTestCase2(GettextBaseTest):
@@ -332,6 +332,7 @@
 
     def test_weird_metadata(self):
         info = self.t.info()
+        self.assertEqual(len(info), 9)
         self.assertEqual(info['last-translator'],
            'John Doe <jdoe at example.com>\nJane Foobar <jfoobar at example.com>')
 

Modified: python/branches/py3k-importlib/Lib/test/test_grammar.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_grammar.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_grammar.py	Thu Mar 27 00:48:05 2008
@@ -32,8 +32,10 @@
         self.assertEquals(0o377, 255)
         self.assertEquals(2147483647, 0o17777777777)
         self.assertEquals(0b1001, 9)
-        from sys import maxint
-        if maxint == 2147483647:
+        # "0x" is not a valid literal
+        self.assertRaises(SyntaxError, eval, "0x")
+        from sys import maxsize
+        if maxsize == 2147483647:
             self.assertEquals(-2147483647-1, -0o20000000000)
             # XXX -2147483648
             self.assert_(0o37777777777 > 0)
@@ -45,7 +47,7 @@
                     x = eval(s)
                 except OverflowError:
                     self.fail("OverflowError on huge integer literal %r" % s)
-        elif maxint == 9223372036854775807:
+        elif maxsize == 9223372036854775807:
             self.assertEquals(-9223372036854775807-1, -0o1000000000000000000000)
             self.assert_(0o1777777777777777777777 > 0)
             self.assert_(0xffffffffffffffff > 0)
@@ -58,7 +60,7 @@
                 except OverflowError:
                     self.fail("OverflowError on huge integer literal %r" % s)
         else:
-            self.fail('Weird maxint value %r' % maxint)
+            self.fail('Weird maxsize value %r' % maxsize)
 
     def testLongIntegers(self):
         x = 0
@@ -308,6 +310,10 @@
         def f(*, k=1): return closure
         def f() -> int: return closure
 
+        # Check ast errors in *args and *kwargs
+        check_syntax_error(self, "f(*g(1=2))")
+        check_syntax_error(self, "f(**g(1=2))")
+
     def testLambdef(self):
         ### lambdef: 'lambda' [varargslist] ':' test
         l1 = lambda : 0
@@ -498,6 +504,15 @@
         while 0: pass
         else: pass
 
+        # Issue1920: "while 0" is optimized away,
+        # ensure that the "else" clause is still present.
+        x = 0
+        while 0:
+            x = 1
+        else:
+            x = 2
+        self.assertEquals(x, 2)
+
     def testFor(self):
         # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite]
         for i in 1, 2, 3: pass

Modified: python/branches/py3k-importlib/Lib/test/test_grp.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_grp.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_grp.py	Thu Mar 27 00:48:05 2008
@@ -11,9 +11,9 @@
         # attributes promised by the docs
         self.assertEqual(len(value), 4)
         self.assertEqual(value[0], value.gr_name)
-        self.assert_(isinstance(value.gr_name, basestring))
+        self.assert_(isinstance(value.gr_name, str))
         self.assertEqual(value[1], value.gr_passwd)
-        self.assert_(isinstance(value.gr_passwd, basestring))
+        self.assert_(isinstance(value.gr_passwd, str))
         self.assertEqual(value[2], value.gr_gid)
         self.assert_(isinstance(value.gr_gid, int))
         self.assertEqual(value[3], value.gr_mem)
@@ -25,6 +25,9 @@
         for e in entries:
             self.check_value(e)
 
+        if len(entries) > 1000:  # Huge group file (NIS?) -- skip the rest
+            return
+
         for e in entries:
             e2 = grp.getgrgid(e.gr_gid)
             self.check_value(e2)

Modified: python/branches/py3k-importlib/Lib/test/test_gzip.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_gzip.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_gzip.py	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,7 @@
 
 import unittest
 from test import test_support
-import sys, os
+import os
 import gzip
 
 

Modified: python/branches/py3k-importlib/Lib/test/test_heapq.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_heapq.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_heapq.py	Thu Mar 27 00:48:05 2008
@@ -1,21 +1,32 @@
 """Unittests for heapq."""
 
-from heapq import heappush, heappop, heapify, heapreplace, merge, nlargest, nsmallest
 import random
 import unittest
 from test import test_support
 import sys
 
+# We do a bit of trickery here to be able to test both the C implementation
+# and the Python implementation of the module.
+
+# Make it impossible to import the C implementation anymore.
+sys.modules['_heapq'] = 0
+# We must also handle the case that heapq was imported before.
+if 'heapq' in sys.modules:
+    del sys.modules['heapq']
+
+# Now we can import the module and get the pure Python implementation.
+import heapq as py_heapq
+
+# Restore everything to normal.
+del sys.modules['_heapq']
+del sys.modules['heapq']
+
+# This is now the module with the C implementation.
+import heapq as c_heapq
 
-def heapiter(heap):
-    # An iterator returning a heap's elements, smallest-first.
-    try:
-        while 1:
-            yield heappop(heap)
-    except IndexError:
-        pass
 
 class TestHeap(unittest.TestCase):
+    module = None
 
     def test_push_pop(self):
         # 1) Push 256 random numbers and pop them off, verifying all's OK.
@@ -25,11 +36,11 @@
         for i in range(256):
             item = random.random()
             data.append(item)
-            heappush(heap, item)
+            self.module.heappush(heap, item)
             self.check_invariant(heap)
         results = []
         while heap:
-            item = heappop(heap)
+            item = self.module.heappop(heap)
             self.check_invariant(heap)
             results.append(item)
         data_sorted = data[:]
@@ -38,10 +49,10 @@
         # 2) Check that the invariant holds for a sorted array
         self.check_invariant(results)
 
-        self.assertRaises(TypeError, heappush, [])
+        self.assertRaises(TypeError, self.module.heappush, [])
         try:
-            self.assertRaises(TypeError, heappush, None, None)
-            self.assertRaises(TypeError, heappop, None)
+            self.assertRaises(TypeError, self.module.heappush, None, None)
+            self.assertRaises(TypeError, self.module.heappop, None)
         except AttributeError:
             pass
 
@@ -55,21 +66,29 @@
     def test_heapify(self):
         for size in range(30):
             heap = [random.random() for dummy in range(size)]
-            heapify(heap)
+            self.module.heapify(heap)
             self.check_invariant(heap)
 
-        self.assertRaises(TypeError, heapify, None)
+        self.assertRaises(TypeError, self.module.heapify, None)
 
     def test_naive_nbest(self):
         data = [random.randrange(2000) for i in range(1000)]
         heap = []
         for item in data:
-            heappush(heap, item)
+            self.module.heappush(heap, item)
             if len(heap) > 10:
-                heappop(heap)
+                self.module.heappop(heap)
         heap.sort()
         self.assertEqual(heap, sorted(data)[-10:])
 
+    def heapiter(self, heap):
+        # An iterator returning a heap's elements, smallest-first.
+        try:
+            while 1:
+                yield self.module.heappop(heap)
+        except IndexError:
+            pass
+
     def test_nbest(self):
         # Less-naive "N-best" algorithm, much faster (if len(data) is big
         # enough <wink>) than sorting all of data.  However, if we had a max
@@ -78,15 +97,43 @@
         # (10 log-time steps).
         data = [random.randrange(2000) for i in range(1000)]
         heap = data[:10]
-        heapify(heap)
+        self.module.heapify(heap)
         for item in data[10:]:
             if item > heap[0]:  # this gets rarer the longer we run
-                heapreplace(heap, item)
-        self.assertEqual(list(heapiter(heap)), sorted(data)[-10:])
+                self.module.heapreplace(heap, item)
+        self.assertEqual(list(self.heapiter(heap)), sorted(data)[-10:])
 
-        self.assertRaises(TypeError, heapreplace, None)
-        self.assertRaises(TypeError, heapreplace, None, None)
-        self.assertRaises(IndexError, heapreplace, [], None)
+        self.assertRaises(TypeError, self.module.heapreplace, None)
+        self.assertRaises(TypeError, self.module.heapreplace, None, None)
+        self.assertRaises(IndexError, self.module.heapreplace, [], None)
+
+    def test_nbest_with_pushpop(self):
+        data = [random.randrange(2000) for i in range(1000)]
+        heap = data[:10]
+        self.module.heapify(heap)
+        for item in data[10:]:
+            self.module.heappushpop(heap, item)
+        self.assertEqual(list(self.heapiter(heap)), sorted(data)[-10:])
+        self.assertEqual(self.module.heappushpop([], 'x'), 'x')
+
+    def test_heappushpop(self):
+        h = []
+        x = self.module.heappushpop(h, 10)
+        self.assertEqual((h, x), ([], 10))
+
+        h = [10]
+        x = self.module.heappushpop(h, 10.0)
+        self.assertEqual((h, x), ([10], 10.0))
+        self.assertEqual(type(h[0]), int)
+        self.assertEqual(type(x), float)
+
+        h = [10];
+        x = self.module.heappushpop(h, 9)
+        self.assertEqual((h, x), ([10], 9))
+
+        h = [10];
+        x = self.module.heappushpop(h, 11)
+        self.assertEqual((h, x), ([11], 10))
 
     def test_heapsort(self):
         # Exercise everything with repeated heapsort checks
@@ -95,12 +142,12 @@
             data = [random.randrange(25) for i in range(size)]
             if trial & 1:     # Half of the time, use heapify
                 heap = data[:]
-                heapify(heap)
+                self.module.heapify(heap)
             else:             # The rest of the time, use heappush
                 heap = []
                 for item in data:
-                    heappush(heap, item)
-            heap_sorted = [heappop(heap) for i in range(size)]
+                    self.module.heappush(heap, item)
+            heap_sorted = [self.module.heappop(heap) for i in range(size)]
             self.assertEqual(heap_sorted, sorted(data))
 
     def test_merge(self):
@@ -108,8 +155,8 @@
         for i in range(random.randrange(5)):
             row = sorted(random.randrange(1000) for j in range(random.randrange(10)))
             inputs.append(row)
-        self.assertEqual(sorted(chain(*inputs)), list(merge(*inputs)))
-        self.assertEqual(list(merge()), [])
+        self.assertEqual(sorted(chain(*inputs)), list(self.module.merge(*inputs)))
+        self.assertEqual(list(self.module.merge()), [])
 
     def test_merge_stability(self):
         class Int(int):
@@ -123,26 +170,33 @@
             inputs[stream].append(obj)
         for stream in inputs:
             stream.sort()
-        result = [i.pair for i in merge(*inputs)]
+        result = [i.pair for i in self.module.merge(*inputs)]
         self.assertEqual(result, sorted(result))
 
     def test_nsmallest(self):
         data = [(random.randrange(2000), i) for i in range(1000)]
         for f in (None, lambda x:  x[0] * 547 % 2000):
             for n in (0, 1, 2, 10, 100, 400, 999, 1000, 1100):
-                self.assertEqual(list(nsmallest(n, data)), sorted(data)[:n])
-                self.assertEqual(list(nsmallest(n, data, key=f)),
+                self.assertEqual(list(self.module.nsmallest(n, data)),
+                                 sorted(data)[:n])
+                self.assertEqual(list(self.module.nsmallest(n, data, key=f)),
                                  sorted(data, key=f)[:n])
 
     def test_nlargest(self):
         data = [(random.randrange(2000), i) for i in range(1000)]
         for f in (None, lambda x:  x[0] * 547 % 2000):
             for n in (0, 1, 2, 10, 100, 400, 999, 1000, 1100):
-                self.assertEqual(list(nlargest(n, data)),
+                self.assertEqual(list(self.module.nlargest(n, data)),
                                  sorted(data, reverse=True)[:n])
-                self.assertEqual(list(nlargest(n, data, key=f)),
+                self.assertEqual(list(self.module.nlargest(n, data, key=f)),
                                  sorted(data, key=f, reverse=True)[:n])
 
+class TestHeapPython(TestHeap):
+    module = py_heapq
+
+class TestHeapC(TestHeap):
+    module = c_heapq
+
 
 #==============================================================================
 
@@ -234,50 +288,55 @@
     def __next__(self):
         raise StopIteration
 
-from itertools import chain, imap
+from itertools import chain
 def L(seqn):
     'Test multiple tiers of iterators'
-    return chain(imap(lambda x:x, R(Ig(G(seqn)))))
+    return chain(map(lambda x:x, R(Ig(G(seqn)))))
 
 class TestErrorHandling(unittest.TestCase):
+    # only for C implementation
+    module = c_heapq
 
     def test_non_sequence(self):
-        for f in (heapify, heappop):
+        for f in (self.module.heapify, self.module.heappop):
             self.assertRaises(TypeError, f, 10)
-        for f in (heappush, heapreplace, nlargest, nsmallest):
+        for f in (self.module.heappush, self.module.heapreplace,
+                  self.module.nlargest, self.module.nsmallest):
             self.assertRaises(TypeError, f, 10, 10)
 
     def test_len_only(self):
-        for f in (heapify, heappop):
+        for f in (self.module.heapify, self.module.heappop):
             self.assertRaises(TypeError, f, LenOnly())
-        for f in (heappush, heapreplace):
+        for f in (self.module.heappush, self.module.heapreplace):
             self.assertRaises(TypeError, f, LenOnly(), 10)
-        for f in (nlargest, nsmallest):
+        for f in (self.module.nlargest, self.module.nsmallest):
             self.assertRaises(TypeError, f, 2, LenOnly())
 
     def test_get_only(self):
-        for f in (heapify, heappop):
+        for f in (self.module.heapify, self.module.heappop):
             self.assertRaises(TypeError, f, GetOnly())
-        for f in (heappush, heapreplace):
+        for f in (self.module.heappush, self.module.heapreplace):
             self.assertRaises(TypeError, f, GetOnly(), 10)
-        for f in (nlargest, nsmallest):
+        for f in (self.module.nlargest, self.module.nsmallest):
             self.assertRaises(TypeError, f, 2, GetOnly())
 
     def test_get_only(self):
         seq = [CmpErr(), CmpErr(), CmpErr()]
-        for f in (heapify, heappop):
+        for f in (self.module.heapify, self.module.heappop):
             self.assertRaises(ZeroDivisionError, f, seq)
-        for f in (heappush, heapreplace):
+        for f in (self.module.heappush, self.module.heapreplace):
             self.assertRaises(ZeroDivisionError, f, seq, 10)
-        for f in (nlargest, nsmallest):
+        for f in (self.module.nlargest, self.module.nsmallest):
             self.assertRaises(ZeroDivisionError, f, 2, seq)
 
     def test_arg_parsing(self):
-        for f in (heapify, heappop, heappush, heapreplace, nlargest, nsmallest):
+        for f in (self.module.heapify, self.module.heappop,
+                  self.module.heappush, self.module.heapreplace,
+                  self.module.nlargest, self.module.nsmallest):
             self.assertRaises(TypeError, f, 10)
 
     def test_iterable_args(self):
-        for f in  (nlargest, nsmallest):
+        for f in (self.module.nlargest, self.module.nsmallest):
             for s in ("123", "", range(1000), (1, 1.2), range(2000,2200,5)):
                 for g in (G, I, Ig, L, R):
                     self.assertEqual(list(f(2, g(s))), list(f(2,s)))
@@ -286,15 +345,14 @@
                 self.assertRaises(TypeError, f, 2, N(s))
                 self.assertRaises(ZeroDivisionError, f, 2, E(s))
 
+
 #==============================================================================
 
 
 def test_main(verbose=None):
     from types import BuiltinFunctionType
 
-    test_classes = [TestHeap]
-    if isinstance(heapify, BuiltinFunctionType):
-        test_classes.append(TestErrorHandling)
+    test_classes = [TestHeapPython, TestHeapC, TestErrorHandling]
     test_support.run_unittest(*test_classes)
 
     # verify reference counting

Deleted: /python/branches/py3k-importlib/Lib/test/test_hexoct.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/test_hexoct.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,116 +0,0 @@
-"""Test correct treatment of hex/oct constants.
-
-This is complex because of changes due to PEP 237.
-"""
-
-import sys
-platform_long_is_32_bits = sys.maxint == 2147483647
-
-import unittest
-from test import test_support
-
-import warnings
-warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
-                        "<string>")
-
-class TextHexOct(unittest.TestCase):
-
-    def test_hex_baseline(self):
-        # Baseline tests
-        self.assertEqual(0x0, 0)
-        self.assertEqual(0x10, 16)
-        if platform_long_is_32_bits:
-            self.assertEqual(0x7fffffff, 2147483647)
-        else:
-            self.assertEqual(0x7fffffffffffffff, 9223372036854775807)
-        # Ditto with a minus sign and parentheses
-        self.assertEqual(-(0x0), 0)
-        self.assertEqual(-(0x10), -16)
-        if platform_long_is_32_bits:
-            self.assertEqual(-(0x7fffffff), -2147483647)
-        else:
-            self.assertEqual(-(0x7fffffffffffffff), -9223372036854775807)
-        # Ditto with a minus sign and NO parentheses
-        self.assertEqual(-0x0, 0)
-        self.assertEqual(-0x10, -16)
-        if platform_long_is_32_bits:
-            self.assertEqual(-0x7fffffff, -2147483647)
-        else:
-            self.assertEqual(-0x7fffffffffffffff, -9223372036854775807)
-
-    def test_hex_unsigned(self):
-        if platform_long_is_32_bits:
-            # Positive constants
-            self.assertEqual(0x80000000, 2147483648)
-            self.assertEqual(0xffffffff, 4294967295)
-            # Ditto with a minus sign and parentheses
-            self.assertEqual(-(0x80000000), -2147483648)
-            self.assertEqual(-(0xffffffff), -4294967295)
-            # Ditto with a minus sign and NO parentheses
-            # This failed in Python 2.2 through 2.2.2 and in 2.3a1
-            self.assertEqual(-0x80000000, -2147483648)
-            self.assertEqual(-0xffffffff, -4294967295)
-        else:
-            # Positive constants
-            self.assertEqual(0x8000000000000000, 9223372036854775808)
-            self.assertEqual(0xffffffffffffffff, 18446744073709551615)
-            # Ditto with a minus sign and parentheses
-            self.assertEqual(-(0x8000000000000000), -9223372036854775808)
-            self.assertEqual(-(0xffffffffffffffff), -18446744073709551615)
-            # Ditto with a minus sign and NO parentheses
-            # This failed in Python 2.2 through 2.2.2 and in 2.3a1
-            self.assertEqual(-0x8000000000000000, -9223372036854775808)
-            self.assertEqual(-0xffffffffffffffff, -18446744073709551615)
-
-    def test_oct_baseline(self):
-        # Baseline tests
-        self.assertEqual(00, 0)
-        self.assertEqual(0o20, 16)
-        if platform_long_is_32_bits:
-            self.assertEqual(0o17777777777, 2147483647)
-        else:
-            self.assertEqual(0o777777777777777777777, 9223372036854775807)
-        # Ditto with a minus sign and parentheses
-        self.assertEqual(-(00), 0)
-        self.assertEqual(-(0o20), -16)
-        if platform_long_is_32_bits:
-            self.assertEqual(-(0o17777777777), -2147483647)
-        else:
-            self.assertEqual(-(0o777777777777777777777), -9223372036854775807)
-        # Ditto with a minus sign and NO parentheses
-        self.assertEqual(-00, 0)
-        self.assertEqual(-0o20, -16)
-        if platform_long_is_32_bits:
-            self.assertEqual(-0o17777777777, -2147483647)
-        else:
-            self.assertEqual(-0o777777777777777777777, -9223372036854775807)
-
-    def test_oct_unsigned(self):
-        if platform_long_is_32_bits:
-            # Positive constants
-            self.assertEqual(0o20000000000, 2147483648)
-            self.assertEqual(0o37777777777, 4294967295)
-            # Ditto with a minus sign and parentheses
-            self.assertEqual(-(0o20000000000), -2147483648)
-            self.assertEqual(-(0o37777777777), -4294967295)
-            # Ditto with a minus sign and NO parentheses
-            # This failed in Python 2.2 through 2.2.2 and in 2.3a1
-            self.assertEqual(-0o20000000000, -2147483648)
-            self.assertEqual(-0o37777777777, -4294967295)
-        else:
-            # Positive constants
-            self.assertEqual(0o1000000000000000000000, 9223372036854775808)
-            self.assertEqual(0o1777777777777777777777, 18446744073709551615)
-            # Ditto with a minus sign and parentheses
-            self.assertEqual(-(0o1000000000000000000000), -9223372036854775808)
-            self.assertEqual(-(0o1777777777777777777777), -18446744073709551615)
-            # Ditto with a minus sign and NO parentheses
-            # This failed in Python 2.2 through 2.2.2 and in 2.3a1
-            self.assertEqual(-0o1000000000000000000000, -9223372036854775808)
-            self.assertEqual(-0o1777777777777777777777, -18446744073709551615)
-
-def test_main():
-    test_support.run_unittest(TextHexOct)
-
-if __name__ == "__main__":
-    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_hmac.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_hmac.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_hmac.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,7 @@
 import hmac
-from hashlib import sha1
+import hashlib
 import unittest
+import warnings
 from test import test_support
 
 class TestVectorsTestCase(unittest.TestCase):
@@ -43,7 +44,7 @@
 
     def test_sha_vectors(self):
         def shatest(key, data, digest):
-            h = hmac.HMAC(key, data, digestmod=sha1)
+            h = hmac.HMAC(key, data, digestmod=hashlib.sha1)
             self.assertEqual(h.hexdigest().upper(), digest.upper())
 
         shatest(b"\x0b" * 20,
@@ -75,6 +76,159 @@
                  b"and Larger Than One Block-Size Data"),
                 "e8e99d0f45237d786d6bbaa7965c7808bbff1a91")
 
+    def _rfc4231_test_cases(self, hashfunc):
+        def hmactest(key, data, hexdigests):
+            h = hmac.HMAC(key, data, digestmod=hashfunc)
+            self.assertEqual(h.hexdigest().lower(), hexdigests[hashfunc])
+
+        # 4.2.  Test Case 1
+        hmactest(key = b'\x0b'*20,
+                 data = b'Hi There',
+                 hexdigests = {
+                   hashlib.sha224: '896fb1128abbdf196832107cd49df33f'
+                                   '47b4b1169912ba4f53684b22',
+                   hashlib.sha256: 'b0344c61d8db38535ca8afceaf0bf12b'
+                                   '881dc200c9833da726e9376c2e32cff7',
+                   hashlib.sha384: 'afd03944d84895626b0825f4ab46907f'
+                                   '15f9dadbe4101ec682aa034c7cebc59c'
+                                   'faea9ea9076ede7f4af152e8b2fa9cb6',
+                   hashlib.sha512: '87aa7cdea5ef619d4ff0b4241a1d6cb0'
+                                   '2379f4e2ce4ec2787ad0b30545e17cde'
+                                   'daa833b7d6b8a702038b274eaea3f4e4'
+                                   'be9d914eeb61f1702e696c203a126854',
+                 })
+
+        # 4.3.  Test Case 2
+        hmactest(key = b'Jefe',
+                 data = b'what do ya want for nothing?',
+                 hexdigests = {
+                   hashlib.sha224: 'a30e01098bc6dbbf45690f3a7e9e6d0f'
+                                   '8bbea2a39e6148008fd05e44',
+                   hashlib.sha256: '5bdcc146bf60754e6a042426089575c7'
+                                   '5a003f089d2739839dec58b964ec3843',
+                   hashlib.sha384: 'af45d2e376484031617f78d2b58a6b1b'
+                                   '9c7ef464f5a01b47e42ec3736322445e'
+                                   '8e2240ca5e69e2c78b3239ecfab21649',
+                   hashlib.sha512: '164b7a7bfcf819e2e395fbe73b56e0a3'
+                                   '87bd64222e831fd610270cd7ea250554'
+                                   '9758bf75c05a994a6d034f65f8f0e6fd'
+                                   'caeab1a34d4a6b4b636e070a38bce737',
+                 })
+
+        # 4.4.  Test Case 3
+        hmactest(key = b'\xaa'*20,
+                 data = b'\xdd'*50,
+                 hexdigests = {
+                   hashlib.sha224: '7fb3cb3588c6c1f6ffa9694d7d6ad264'
+                                   '9365b0c1f65d69d1ec8333ea',
+                   hashlib.sha256: '773ea91e36800e46854db8ebd09181a7'
+                                   '2959098b3ef8c122d9635514ced565fe',
+                   hashlib.sha384: '88062608d3e6ad8a0aa2ace014c8a86f'
+                                   '0aa635d947ac9febe83ef4e55966144b'
+                                   '2a5ab39dc13814b94e3ab6e101a34f27',
+                   hashlib.sha512: 'fa73b0089d56a284efb0f0756c890be9'
+                                   'b1b5dbdd8ee81a3655f83e33b2279d39'
+                                   'bf3e848279a722c806b485a47e67c807'
+                                   'b946a337bee8942674278859e13292fb',
+                 })
+
+        # 4.5.  Test Case 4
+        hmactest(key = bytes(x for x in range(0x01, 0x19+1)),
+                 data = b'\xcd'*50,
+                 hexdigests = {
+                   hashlib.sha224: '6c11506874013cac6a2abc1bb382627c'
+                                   'ec6a90d86efc012de7afec5a',
+                   hashlib.sha256: '82558a389a443c0ea4cc819899f2083a'
+                                   '85f0faa3e578f8077a2e3ff46729665b',
+                   hashlib.sha384: '3e8a69b7783c25851933ab6290af6ca7'
+                                   '7a9981480850009cc5577c6e1f573b4e'
+                                   '6801dd23c4a7d679ccf8a386c674cffb',
+                   hashlib.sha512: 'b0ba465637458c6990e5a8c5f61d4af7'
+                                   'e576d97ff94b872de76f8050361ee3db'
+                                   'a91ca5c11aa25eb4d679275cc5788063'
+                                   'a5f19741120c4f2de2adebeb10a298dd',
+                 })
+
+        # 4.7.  Test Case 6
+        hmactest(key = b'\xaa'*131,
+                 data = b'Test Using Larger Than Block-Siz'
+                        b'e Key - Hash Key First',
+                 hexdigests = {
+                   hashlib.sha224: '95e9a0db962095adaebe9b2d6f0dbce2'
+                                   'd499f112f2d2b7273fa6870e',
+                   hashlib.sha256: '60e431591ee0b67f0d8a26aacbf5b77f'
+                                   '8e0bc6213728c5140546040f0ee37f54',
+                   hashlib.sha384: '4ece084485813e9088d2c63a041bc5b4'
+                                   '4f9ef1012a2b588f3cd11f05033ac4c6'
+                                   '0c2ef6ab4030fe8296248df163f44952',
+                   hashlib.sha512: '80b24263c7c1a3ebb71493c1dd7be8b4'
+                                   '9b46d1f41b4aeec1121b013783f8f352'
+                                   '6b56d037e05f2598bd0fd2215d6a1e52'
+                                   '95e64f73f63f0aec8b915a985d786598',
+                 })
+
+        # 4.8.  Test Case 7
+        hmactest(key = b'\xaa'*131,
+                 data = b'This is a test using a larger th'
+                        b'an block-size key and a larger t'
+                        b'han block-size data. The key nee'
+                        b'ds to be hashed before being use'
+                        b'd by the HMAC algorithm.',
+                 hexdigests = {
+                   hashlib.sha224: '3a854166ac5d9f023f54d517d0b39dbd'
+                                   '946770db9c2b95c9f6f565d1',
+                   hashlib.sha256: '9b09ffa71b942fcb27635fbcd5b0e944'
+                                   'bfdc63644f0713938a7f51535c3a35e2',
+                   hashlib.sha384: '6617178e941f020d351e2f254e8fd32c'
+                                   '602420feb0b8fb9adccebb82461e99c5'
+                                   'a678cc31e799176d3860e6110c46523e',
+                   hashlib.sha512: 'e37b6a775dc87dbaa4dfa9f96e5e3ffd'
+                                   'debd71f8867289865df5a32d20cdc944'
+                                   'b6022cac3c4982b10d5eeb55c3e4de15'
+                                   '134676fb6de0446065c97440fa8c6a58',
+                 })
+
+    def test_sha224_rfc4231(self):
+        self._rfc4231_test_cases(hashlib.sha224)
+
+    def test_sha256_rfc4231(self):
+        self._rfc4231_test_cases(hashlib.sha256)
+
+    def test_sha384_rfc4231(self):
+        self._rfc4231_test_cases(hashlib.sha384)
+
+    def test_sha512_rfc4231(self):
+        self._rfc4231_test_cases(hashlib.sha512)
+
+    def test_legacy_block_size_warnings(self):
+        class MockCrazyHash(object):
+            """Ain't no block_size attribute here."""
+            def __init__(self, *args):
+                self._x = hashlib.sha1(*args)
+                self.digest_size = self._x.digest_size
+            def update(self, v):
+                self._x.update(v)
+            def digest(self):
+                return self._x.digest()
+
+        with test_support.catch_warning():
+            warnings.simplefilter('error', RuntimeWarning)
+            try:
+                hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash)
+            except RuntimeWarning:
+                pass
+            else:
+                self.fail('Expected warning about missing block_size')
+
+            MockCrazyHash.block_size = 1
+            try:
+                hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash)
+            except RuntimeWarning:
+                pass
+            else:
+                self.fail('Expected warning about small block_size')
+
+
 
 class ConstructorTestCase(unittest.TestCase):
 
@@ -95,9 +249,8 @@
 
     def test_withmodule(self):
         # Constructor call with text and digest module.
-        from hashlib import sha1
         try:
-            h = hmac.HMAC(b"key", b"", sha1)
+            h = hmac.HMAC(b"key", b"", hashlib.sha1)
         except:
             self.fail("Constructor call with hashlib.sha1 raised exception.")
 
@@ -106,7 +259,6 @@
     def test_default_is_md5(self):
         # Testing if HMAC defaults to MD5 algorithm.
         # NOTE: this whitebox test depends on the hmac class internals
-        import hashlib
         h = hmac.HMAC(b"key")
         self.assertEqual(h.digest_cons, hashlib.md5)
 

Modified: python/branches/py3k-importlib/Lib/test/test_htmlparser.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_htmlparser.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_htmlparser.py	Thu Mar 27 00:48:05 2008
@@ -2,7 +2,6 @@
 
 import HTMLParser
 import pprint
-import sys
 import unittest
 from test import test_support
 

Modified: python/branches/py3k-importlib/Lib/test/test_httplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_httplib.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_httplib.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,5 @@
 import httplib
 import io
-import sys
 import socket
 
 from unittest import TestCase
@@ -83,13 +82,25 @@
         resp = httplib.HTTPResponse(sock)
         resp.begin()
         self.assertEqual(resp.read(), b"Text")
-        resp.close()
+        self.assertTrue(resp.isclosed())
 
         body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText"
         sock = FakeSocket(body)
         resp = httplib.HTTPResponse(sock)
         self.assertRaises(httplib.BadStatusLine, resp.begin)
 
+    def test_partial_reads(self):
+        # if we have a lenght, the system knows when to close itself
+        # same behaviour than when we read the whole thing with read()
+        body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText"
+        sock = FakeSocket(body)
+        resp = httplib.HTTPResponse(sock)
+        resp.begin()
+        self.assertEqual(resp.read(2), b'Te')
+        self.assertFalse(resp.isclosed())
+        self.assertEqual(resp.read(2), b'xt')
+        self.assertTrue(resp.isclosed())
+
     def test_host_port(self):
         # Check invalid host_port
 
@@ -135,7 +146,6 @@
         resp.begin()
         if resp.read():
             self.fail("Did not expect response from HEAD request")
-        resp.close()
 
     def test_send_file(self):
         expected = (b'GET /foo HTTP/1.1\r\nHost: example.com\r\n'
@@ -146,7 +156,44 @@
         sock = FakeSocket(body)
         conn.sock = sock
         conn.request('GET', '/foo', body)
-        self.assertTrue(sock.data.startswith(expected))
+        self.assertTrue(sock.data.startswith(expected), '%r != %r' %
+                (sock.data[:len(expected)], expected))
+
+    def test_chunked(self):
+        chunked_start = (
+            'HTTP/1.1 200 OK\r\n'
+            'Transfer-Encoding: chunked\r\n\r\n'
+            'a\r\n'
+            'hello worl\r\n'
+            '1\r\n'
+            'd\r\n'
+        )
+        sock = FakeSocket(chunked_start + '0\r\n')
+        resp = httplib.HTTPResponse(sock, method="GET")
+        resp.begin()
+        self.assertEquals(resp.read(), b'hello world')
+        resp.close()
+
+        for x in ('', 'foo\r\n'):
+            sock = FakeSocket(chunked_start + x)
+            resp = httplib.HTTPResponse(sock, method="GET")
+            resp.begin()
+            try:
+                resp.read()
+            except httplib.IncompleteRead as i:
+                self.assertEquals(i.partial, b'hello world')
+            else:
+                self.fail('IncompleteRead expected')
+            finally:
+                resp.close()
+
+    def test_negative_content_length(self):
+        sock = FakeSocket('HTTP/1.1 200 OK\r\nContent-Length: -1\r\n\r\nHello\r\n')
+        resp = httplib.HTTPResponse(sock, method="GET")
+        resp.begin()
+        self.assertEquals(resp.read(), b'Hello\r\n')
+        resp.close()
+
 
 class OfflineTest(TestCase):
     def test_responses(self):

Modified: python/branches/py3k-importlib/Lib/test/test_imp.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_imp.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_imp.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,4 @@
 import imp
-import thread
 import unittest
 from test import test_support
 
@@ -38,9 +37,41 @@
                 self.fail("release_lock() without lock should raise "
                             "RuntimeError")
 
+class ImportTests(unittest.TestCase):
+
+    def test_find_module_encoding(self):
+        fd = imp.find_module("heapq")[0]
+        self.assertEqual(fd.encoding, "iso-8859-1")
+
+    def test_issue1267(self):
+        fp, filename, info  = imp.find_module("pydoc")
+        self.assertNotEqual(fp, None)
+        self.assertEqual(fp.encoding, "iso-8859-1")
+        self.assertEqual(fp.tell(), 0)
+        self.assertEqual(fp.readline(), '#!/usr/bin/env python\n')
+        fp.close()
+
+        fp, filename, info = imp.find_module("tokenize")
+        self.assertNotEqual(fp, None)
+        self.assertEqual(fp.encoding, "utf-8")
+        self.assertEqual(fp.tell(), 0)
+        self.assertEqual(fp.readline(),
+                         '"""Tokenization help for Python programs.\n')
+        fp.close()
+
+    def test_reload(self):
+        import marshal
+        imp.reload(marshal)
+        import string
+        imp.reload(string)
+        ## import sys
+        ## self.assertRaises(ImportError, reload, sys)
+
+
 def test_main():
     test_support.run_unittest(
                 LockTests,
+                ImportTests,
             )
 
 if __name__ == "__main__":

Modified: python/branches/py3k-importlib/Lib/test/test_import.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_import.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_import.py	Thu Mar 27 00:48:05 2008
@@ -3,10 +3,12 @@
 import unittest
 import os
 import random
+import shutil
 import sys
 import py_compile
 import warnings
-from test.test_support import unlink
+import imp
+from test.test_support import unlink, TESTFN, unload
 
 
 def remove_files(name):
@@ -53,6 +55,8 @@
             print("b =", b, file=f)
             f.close()
 
+            if TESTFN in sys.modules:
+                del sys.modules[TESTFN]
             try:
                 try:
                     mod = __import__(TESTFN)
@@ -157,8 +161,114 @@
             warnings.simplefilter('error', ImportWarning)
             self.assertRaises(ImportWarning, __import__, "site-packages")
 
+    def test_failing_reload(self):
+        # A failing reload should leave the module object in sys.modules.
+        source = TESTFN + ".py"
+        with open(source, "w") as f:
+            f.write("a = 1\nb=2\n")
+
+        sys.path.insert(0, os.curdir)
+        try:
+            mod = __import__(TESTFN)
+            self.assert_(TESTFN in sys.modules, "expected module in sys.modules")
+            self.assertEquals(mod.a, 1, "module has wrong attribute values")
+            self.assertEquals(mod.b, 2, "module has wrong attribute values")
+
+            # On WinXP, just replacing the .py file wasn't enough to
+            # convince reload() to reparse it.  Maybe the timestamp didn't
+            # move enough.  We force it to get reparsed by removing the
+            # compiled file too.
+            remove_files(TESTFN)
+
+            # Now damage the module.
+            with open(source, "w") as f:
+                f.write("a = 10\nb=20//0\n")
+
+            self.assertRaises(ZeroDivisionError, imp.reload, mod)
+            # But we still expect the module to be in sys.modules.
+            mod = sys.modules.get(TESTFN)
+            self.failIf(mod is None, "expected module to still be in sys.modules")
+
+            # We should have replaced a w/ 10, but the old b value should
+            # stick.
+            self.assertEquals(mod.a, 10, "module has wrong attribute values")
+            self.assertEquals(mod.b, 2, "module has wrong attribute values")
+
+        finally:
+            sys.path.pop(0)
+            remove_files(TESTFN)
+            if TESTFN in sys.modules:
+                del sys.modules[TESTFN]
+
+    def test_file_to_source(self):
+        # check if __file__ points to the source file where available
+        source = TESTFN + ".py"
+        with open(source, "w") as f:
+            f.write("test = None\n")
+
+        sys.path.insert(0, os.curdir)
+        try:
+            mod = __import__(TESTFN)
+            self.failUnless(mod.__file__.endswith('.py'))
+            os.remove(source)
+            del sys.modules[TESTFN]
+            mod = __import__(TESTFN)
+            ext = mod.__file__[-4:]
+            self.failUnless(ext in ('.pyc', '.pyo'), ext)
+        finally:
+            sys.path.pop(0)
+            remove_files(TESTFN)
+            if TESTFN in sys.modules:
+                del sys.modules[TESTFN]
+
+
+    def test_importbyfilename(self):
+        path = os.path.abspath(TESTFN)
+        try:
+            __import__(path)
+        except ImportError as err:
+            self.assertEqual("Import by filename is not supported.",
+                              err.args[0])
+        else:
+            self.fail("import by path didn't raise an exception")
+
+class PathsTests(unittest.TestCase):
+    SAMPLES = ('test', 'test\u00e4\u00f6\u00fc\u00df', 'test\u00e9\u00e8',
+               'test\u00b0\u00b3\u00b2')
+    path = TESTFN
+
+    def setUp(self):
+        os.mkdir(self.path)
+        self.syspath = sys.path[:]
+
+    def tearDown(self):
+        shutil.rmtree(self.path)
+        sys.path = self.syspath
+
+    # http://bugs.python.org/issue1293
+    def test_trailing_slash(self):
+        f = open(os.path.join(self.path, 'test_trailing_slash.py'), 'w')
+        f.write("testdata = 'test_trailing_slash'")
+        f.close()
+        sys.path.append(self.path+'/')
+        mod = __import__("test_trailing_slash")
+        self.assertEqual(mod.testdata, 'test_trailing_slash')
+        unload("test_trailing_slash")
+
+class RelativeImport(unittest.TestCase):
+    def tearDown(self):
+        try:
+            del sys.modules["test.relimport"]
+        except:
+            pass
+
+    def test_relimport_star(self):
+        # This will import * from .test_import.
+        from . import relimport
+        self.assertTrue(hasattr(relimport, "RelativeImport"))
+
 def test_main(verbose=None):
-    run_unittest(ImportTest)
+    run_unittest(ImportTest, PathsTests, RelativeImport)
 
 if __name__ == '__main__':
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_index.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_index.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_index.py	Thu Mar 27 00:48:05 2008
@@ -1,8 +1,6 @@
 import unittest
 from test import test_support
 import operator
-import sys
-from sys import maxint
 maxsize = test_support.MAX_Py_ssize_t
 minsize = -maxsize-1
 
@@ -180,7 +178,7 @@
     def test_getitem(self):
         class GetItem(object):
             def __len__(self):
-                return maxint #cannot return long here
+                return sys.maxsize
             def __getitem__(self, key):
                 return key
         x = GetItem()

Modified: python/branches/py3k-importlib/Lib/test/test_inspect.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_inspect.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_inspect.py	Thu Mar 27 00:48:05 2008
@@ -4,6 +4,7 @@
 import inspect
 import datetime
 import collections
+from os.path import normcase
 
 from test.test_support import TESTFN, run_unittest
 
@@ -12,16 +13,23 @@
 
 # Functions tested in this suite:
 # ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode,
-# isbuiltin, isroutine, getmembers, getdoc, getfile, getmodule,
-# getsourcefile, getcomments, getsource, getclasstree, getargspec,
-# getargvalues, formatargspec, formatargvalues, currentframe, stack, trace
-# isdatadescriptor
+# isbuiltin, isroutine, isgenerator, isgeneratorfunction, getmembers,
+# getdoc, getfile, getmodule, getsourcefile, getcomments, getsource,
+# getclasstree, getargspec, getargvalues, formatargspec, formatargvalues,
+# currentframe, stack, trace, isdatadescriptor
 
 modfile = mod.__file__
 if modfile.endswith(('c', 'o')):
     modfile = modfile[:-1]
 
-import __builtin__
+# Normalize file names: on Windows, the case of file names of compiled
+# modules depends on the path used to start the python executable.
+modfile = normcase(modfile)
+
+def revise(filename, *args):
+    return (normcase(filename),) + args
+
+import builtins
 
 try:
     1/0
@@ -33,23 +41,33 @@
 class IsTestBase(unittest.TestCase):
     predicates = set([inspect.isbuiltin, inspect.isclass, inspect.iscode,
                       inspect.isframe, inspect.isfunction, inspect.ismethod,
-                      inspect.ismodule, inspect.istraceback])
+                      inspect.ismodule, inspect.istraceback,
+                      inspect.isgenerator, inspect.isgeneratorfunction])
 
     def istest(self, predicate, exp):
         obj = eval(exp)
         self.failUnless(predicate(obj), '%s(%s)' % (predicate.__name__, exp))
 
         for other in self.predicates - set([predicate]):
+            if predicate == inspect.isgeneratorfunction and\
+               other == inspect.isfunction:
+                continue
             self.failIf(other(obj), 'not %s(%s)' % (other.__name__, exp))
 
+def generator_function_example(self):
+    for i in range(2):
+        yield i
+
 class TestPredicates(IsTestBase):
-    def test_thirteen(self):
+    def test_sixteen(self):
         count = len([x for x in dir(inspect) if x.startswith('is')])
-        # Doc/lib/libinspect.tex claims there are 13 such functions
-        expected = 13
+        # This test is here for remember you to update Doc/library/inspect.rst
+        # which claims there are 16 such functions
+        expected = 16
         err_msg = "There are %d (not %d) is* functions" % (count, expected)
         self.assertEqual(count, expected, err_msg)
 
+
     def test_excluding_predicates(self):
         self.istest(inspect.isbuiltin, 'sys.exit')
         self.istest(inspect.isbuiltin, '[].append')
@@ -57,11 +75,13 @@
         self.istest(inspect.iscode, 'mod.spam.__code__')
         self.istest(inspect.isframe, 'tb.tb_frame')
         self.istest(inspect.isfunction, 'mod.spam')
-        self.istest(inspect.ismethod, 'mod.StupidGit.abuse')
+        self.istest(inspect.isfunction, 'mod.StupidGit.abuse')
         self.istest(inspect.ismethod, 'git.argue')
         self.istest(inspect.ismodule, 'mod')
         self.istest(inspect.istraceback, 'tb')
         self.istest(inspect.isdatadescriptor, 'collections.defaultdict.default_factory')
+        self.istest(inspect.isgenerator, '(x for x in range(2))')
+        self.istest(inspect.isgeneratorfunction, 'generator_function_example')
         if hasattr(types, 'GetSetDescriptorType'):
             self.istest(inspect.isgetsetdescriptor,
                         'type(tb.tb_frame).f_locals')
@@ -88,23 +108,23 @@
 
     def test_stack(self):
         self.assert_(len(mod.st) >= 5)
-        self.assertEqual(mod.st[0][1:],
+        self.assertEqual(revise(*mod.st[0][1:]),
              (modfile, 16, 'eggs', ['    st = inspect.stack()\n'], 0))
-        self.assertEqual(mod.st[1][1:],
+        self.assertEqual(revise(*mod.st[1][1:]),
              (modfile, 9, 'spam', ['    eggs(b + d, c + f)\n'], 0))
-        self.assertEqual(mod.st[2][1:],
+        self.assertEqual(revise(*mod.st[2][1:]),
              (modfile, 43, 'argue', ['            spam(a, b, c)\n'], 0))
-        self.assertEqual(mod.st[3][1:],
+        self.assertEqual(revise(*mod.st[3][1:]),
              (modfile, 39, 'abuse', ['        self.argue(a, b, c)\n'], 0))
 
     def test_trace(self):
         self.assertEqual(len(git.tr), 3)
-        self.assertEqual(git.tr[0][1:], (modfile, 43, 'argue',
-                                         ['            spam(a, b, c)\n'], 0))
-        self.assertEqual(git.tr[1][1:], (modfile, 9, 'spam',
-                                         ['    eggs(b + d, c + f)\n'], 0))
-        self.assertEqual(git.tr[2][1:], (modfile, 18, 'eggs',
-                                         ['    q = y / 0\n'], 0))
+        self.assertEqual(revise(*git.tr[0][1:]),
+             (modfile, 43, 'argue', ['            spam(a, b, c)\n'], 0))
+        self.assertEqual(revise(*git.tr[1][1:]),
+             (modfile, 9, 'spam', ['    eggs(b + d, c + f)\n'], 0))
+        self.assertEqual(revise(*git.tr[2][1:]),
+             (modfile, 18, 'eggs', ['    q = y / 0\n'], 0))
 
     def test_frame(self):
         args, varargs, varkw, locals = inspect.getargvalues(mod.fr)
@@ -189,7 +209,7 @@
         # Do it again (check the caching isn't broken)
         self.assertEqual(inspect.getmodule(mod.StupidGit.abuse), mod)
         # Check a builtin
-        self.assertEqual(inspect.getmodule(str), sys.modules["__builtin__"])
+        self.assertEqual(inspect.getmodule(str), sys.modules["builtins"])
         # Check filename override
         self.assertEqual(inspect.getmodule(None, modfile), mod)
 
@@ -198,16 +218,16 @@
         self.assertSourceEqual(mod.StupidGit, 21, 46)
 
     def test_getsourcefile(self):
-        self.assertEqual(inspect.getsourcefile(mod.spam), modfile)
-        self.assertEqual(inspect.getsourcefile(git.abuse), modfile)
+        self.assertEqual(normcase(inspect.getsourcefile(mod.spam)), modfile)
+        self.assertEqual(normcase(inspect.getsourcefile(git.abuse)), modfile)
 
     def test_getfile(self):
         self.assertEqual(inspect.getfile(mod.StupidGit), mod.__file__)
 
     def test_getmodule_recursion(self):
-        from new import module
+        from types import ModuleType
         name = '__inspect_dummy'
-        m = sys.modules[name] = module(name)
+        m = sys.modules[name] = ModuleType(name)
         m.__file__ = "<string>" # hopefully not a real filename...
         m.__loader__ = "dummy"  # pretend the filename is understood by a loader
         exec("def x(): pass", m.__dict__)
@@ -219,7 +239,7 @@
     fodderFile = mod2
 
     def test_wrapped_decorator(self):
-        self.assertSourceEqual(mod2.wrapped, 16, 17)
+        self.assertSourceEqual(mod2.wrapped, 14, 17)
 
     def test_replacing_decorator(self):
         self.assertSourceEqual(mod2.gone, 9, 10)
@@ -306,9 +326,8 @@
         got = inspect.getmro(D)
         self.assertEqual(expected, got)
 
-    def assertArgSpecEquals(self, routine, args_e, varargs_e = None,
-                            varkw_e = None, defaults_e = None,
-                            formatted = None):
+    def assertArgSpecEquals(self, routine, args_e, varargs_e=None,
+                            varkw_e=None, defaults_e=None, formatted=None):
         args, varargs, varkw, defaults = inspect.getargspec(routine)
         self.assertEqual(args, args_e)
         self.assertEqual(varargs, varargs_e)
@@ -318,14 +337,48 @@
             self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults),
                              formatted)
 
+    def assertFullArgSpecEquals(self, routine, args_e, varargs_e=None,
+                                    varkw_e=None, defaults_e=None,
+                                    kwonlyargs_e=[], kwonlydefaults_e=None,
+                                    ann_e={}, formatted=None):
+        args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \
+            inspect.getfullargspec(routine)
+        self.assertEqual(args, args_e)
+        self.assertEqual(varargs, varargs_e)
+        self.assertEqual(varkw, varkw_e)
+        self.assertEqual(defaults, defaults_e)
+        self.assertEqual(kwonlyargs, kwonlyargs_e)
+        self.assertEqual(kwonlydefaults, kwonlydefaults_e)
+        self.assertEqual(ann, ann_e)
+        if formatted is not None:
+            self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults,
+                                                    kwonlyargs, kwonlydefaults, ann),
+                             formatted)
+
     def test_getargspec(self):
-        self.assertArgSpecEquals(mod.eggs, ['x', 'y'], formatted = '(x, y)')
+        self.assertArgSpecEquals(mod.eggs, ['x', 'y'], formatted='(x, y)')
 
         self.assertArgSpecEquals(mod.spam,
                                  ['a', 'b', 'c', 'd', 'e', 'f'],
                                  'g', 'h', (3, 4, 5),
                                  '(a, b, c, d=3, e=4, f=5, *g, **h)')
 
+        self.assertRaises(ValueError, self.assertArgSpecEquals,
+                          mod2.keyworded, [])
+
+        self.assertRaises(ValueError, self.assertArgSpecEquals,
+                          mod2.annotated, [])
+
+    def test_getfullargspec(self):
+        self.assertFullArgSpecEquals(mod2.keyworded, [], varargs_e='arg1',
+                                     kwonlyargs_e=['arg2'],
+                                     kwonlydefaults_e={'arg2':1},
+                                     formatted='(*arg1, arg2=1)')
+
+        self.assertFullArgSpecEquals(mod2.annotated, ['arg1'],
+                                     ann_e={'arg1' : list},
+                                     formatted='(arg1: list)')
+
     def test_getargspec_method(self):
         class A(object):
             def m(self):
@@ -354,7 +407,8 @@
         self.assert_(('s', 'static method', A) in attrs, 'missing static method')
         self.assert_(('c', 'class method', A) in attrs, 'missing class method')
         self.assert_(('p', 'property', A) in attrs, 'missing property')
-        self.assert_(('m', 'method', A) in attrs, 'missing plain method')
+        self.assert_(('m', 'method', A) in attrs,
+            'missing plain method: %r' % attrs)
         self.assert_(('m1', 'method', A) in attrs, 'missing plain method')
         self.assert_(('datablob', 'data', A) in attrs, 'missing data')
 

Modified: python/branches/py3k-importlib/Lib/test/test_io.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_io.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_io.py	Thu Mar 27 00:48:05 2008
@@ -8,6 +8,7 @@
 from itertools import chain
 from test import test_support
 
+import codecs
 import io  # The module under test
 
 
@@ -88,17 +89,19 @@
         self.assertEqual(f.tell(), 6)
         self.assertEqual(f.seek(-1, 1), 5)
         self.assertEqual(f.tell(), 5)
-        self.assertEqual(f.write(str8(" world\n\n\n")), 9)
+        self.assertEqual(f.write(bytearray(b" world\n\n\n")), 9)
         self.assertEqual(f.seek(0), 0)
         self.assertEqual(f.write(b"h"), 1)
         self.assertEqual(f.seek(-1, 2), 13)
         self.assertEqual(f.tell(), 13)
         self.assertEqual(f.truncate(12), 12)
         self.assertEqual(f.tell(), 13)
+        self.assertRaises(TypeError, f.seek, 0.0)
 
     def read_ops(self, f, buffered=False):
         data = f.read(5)
         self.assertEqual(data, b"hello")
+        data = bytearray(data)
         self.assertEqual(f.readinto(data), 5)
         self.assertEqual(data, b" worl")
         self.assertEqual(f.readinto(data), 2)
@@ -107,14 +110,15 @@
         self.assertEqual(f.seek(0), 0)
         self.assertEqual(f.read(20), b"hello world\n")
         self.assertEqual(f.read(1), b"")
-        self.assertEqual(f.readinto(b"x"), 0)
+        self.assertEqual(f.readinto(bytearray(b"x")), 0)
         self.assertEqual(f.seek(-6, 2), 6)
         self.assertEqual(f.read(5), b"world")
         self.assertEqual(f.read(0), b"")
-        self.assertEqual(f.readinto(b""), 0)
+        self.assertEqual(f.readinto(bytearray()), 0)
         self.assertEqual(f.seek(-6, 1), 5)
         self.assertEqual(f.read(5), b" worl")
         self.assertEqual(f.tell(), 10)
+        self.assertRaises(TypeError, f.seek, 0.0)
         if buffered:
             f.seek(0)
             self.assertEqual(f.read(), b"hello world\n")
@@ -259,6 +263,9 @@
         self.assertEqual(f.write(a), n)
         f.close()
 
+    def test_closefd(self):
+        self.assertRaises(ValueError, io.open, test_support.TESTFN, 'w',
+                          closefd=False)
 
 class MemorySeekTestMixin:
 
@@ -292,6 +299,7 @@
 
         bytesIo.seek(3)
         self.assertEquals(buf[3:], bytesIo.read())
+        self.assertRaises(TypeError, bytesIo.seek, 0.0)
 
     def testTell(self):
         buf = self.buftype("1234567890")
@@ -477,25 +485,209 @@
         rw.seek(2, 1)
         self.assertEquals(7, rw.tell())
         self.assertEquals(b"fl", rw.read(11))
+        self.assertRaises(TypeError, rw.seek, 0.0)
 
+# To fully exercise seek/tell, the StatefulIncrementalDecoder has these
+# properties:
+#   - A single output character can correspond to many bytes of input.
+#   - The number of input bytes to complete the character can be
+#     undetermined until the last input byte is received.
+#   - The number of input bytes can vary depending on previous input.
+#   - A single input byte can correspond to many characters of output.
+#   - The number of output characters can be undetermined until the
+#     last input byte is received.
+#   - The number of output characters can vary depending on previous input.
+
+class StatefulIncrementalDecoder(codecs.IncrementalDecoder):
+    """
+    For testing seek/tell behavior with a stateful, buffering decoder.
+
+    Input is a sequence of words.  Words may be fixed-length (length set
+    by input) or variable-length (period-terminated).  In variable-length
+    mode, extra periods are ignored.  Possible words are:
+      - 'i' followed by a number sets the input length, I (maximum 99).
+        When I is set to 0, words are space-terminated.
+      - 'o' followed by a number sets the output length, O (maximum 99).
+      - Any other word is converted into a word followed by a period on
+        the output.  The output word consists of the input word truncated
+        or padded out with hyphens to make its length equal to O.  If O
+        is 0, the word is output verbatim without truncating or padding.
+    I and O are initially set to 1.  When I changes, any buffered input is
+    re-scanned according to the new I.  EOF also terminates the last word.
+    """
+
+    def __init__(self, errors='strict'):
+        codecs.IncrementalDecoder.__init__(self, errors)
+        self.reset()
+
+    def __repr__(self):
+        return '<SID %x>' % id(self)
+
+    def reset(self):
+        self.i = 1
+        self.o = 1
+        self.buffer = bytearray()
+
+    def getstate(self):
+        i, o = self.i ^ 1, self.o ^ 1 # so that flags = 0 after reset()
+        return bytes(self.buffer), i*100 + o
+
+    def setstate(self, state):
+        buffer, io = state
+        self.buffer = bytearray(buffer)
+        i, o = divmod(io, 100)
+        self.i, self.o = i ^ 1, o ^ 1
+
+    def decode(self, input, final=False):
+        output = ''
+        for b in input:
+            if self.i == 0: # variable-length, terminated with period
+                if b == ord('.'):
+                    if self.buffer:
+                        output += self.process_word()
+                else:
+                    self.buffer.append(b)
+            else: # fixed-length, terminate after self.i bytes
+                self.buffer.append(b)
+                if len(self.buffer) == self.i:
+                    output += self.process_word()
+        if final and self.buffer: # EOF terminates the last word
+            output += self.process_word()
+        return output
+
+    def process_word(self):
+        output = ''
+        if self.buffer[0] == ord('i'):
+            self.i = min(99, int(self.buffer[1:] or 0)) # set input length
+        elif self.buffer[0] == ord('o'):
+            self.o = min(99, int(self.buffer[1:] or 0)) # set output length
+        else:
+            output = self.buffer.decode('ascii')
+            if len(output) < self.o:
+                output += '-'*self.o # pad out with hyphens
+            if self.o:
+                output = output[:self.o] # truncate to output length
+            output += '.'
+        self.buffer = bytearray()
+        return output
+
+class StatefulIncrementalDecoderTest(unittest.TestCase):
+    """
+    Make sure the StatefulIncrementalDecoder actually works.
+    """
+
+    test_cases = [
+        # I=1, O=1 (fixed-length input == fixed-length output)
+        (b'abcd', False, 'a.b.c.d.'),
+        # I=0, O=0 (variable-length input, variable-length output)
+        (b'oiabcd', True, 'abcd.'),
+        # I=0, O=0 (should ignore extra periods)
+        (b'oi...abcd...', True, 'abcd.'),
+        # I=0, O=6 (variable-length input, fixed-length output)
+        (b'i.o6.x.xyz.toolongtofit.', False, 'x-----.xyz---.toolon.'),
+        # I=2, O=6 (fixed-length input < fixed-length output)
+        (b'i.i2.o6xyz', True, 'xy----.z-----.'),
+        # I=6, O=3 (fixed-length input > fixed-length output)
+        (b'i.o3.i6.abcdefghijklmnop', True, 'abc.ghi.mno.'),
+        # I=0, then 3; O=29, then 15 (with longer output)
+        (b'i.o29.a.b.cde.o15.abcdefghijabcdefghij.i3.a.b.c.d.ei00k.l.m', True,
+         'a----------------------------.' +
+         'b----------------------------.' +
+         'cde--------------------------.' +
+         'abcdefghijabcde.' +
+         'a.b------------.' +
+         '.c.------------.' +
+         'd.e------------.' +
+         'k--------------.' +
+         'l--------------.' +
+         'm--------------.')
+    ]
+
+    def testDecoder(self):
+        # Try a few one-shot test cases.
+        for input, eof, output in self.test_cases:
+            d = StatefulIncrementalDecoder()
+            self.assertEquals(d.decode(input, eof), output)
+
+        # Also test an unfinished decode, followed by forcing EOF.
+        d = StatefulIncrementalDecoder()
+        self.assertEquals(d.decode(b'oiabcd'), '')
+        self.assertEquals(d.decode(b'', 1), 'abcd.')
 
 class TextIOWrapperTest(unittest.TestCase):
 
+    def setUp(self):
+        self.testdata = b"AAA\r\nBBB\rCCC\r\nDDD\nEEE\r\n"
+        self.normalized = b"AAA\nBBB\nCCC\nDDD\nEEE\n".decode("ascii")
+
     def tearDown(self):
         test_support.unlink(test_support.TESTFN)
 
+    def testLineBuffering(self):
+        r = io.BytesIO()
+        b = io.BufferedWriter(r, 1000)
+        t = io.TextIOWrapper(b, newline="\n", line_buffering=True)
+        t.write("X")
+        self.assertEquals(r.getvalue(), b"")  # No flush happened
+        t.write("Y\nZ")
+        self.assertEquals(r.getvalue(), b"XY\nZ")  # All got flushed
+        t.write("A\rB")
+        self.assertEquals(r.getvalue(), b"XY\nZA\rB")
+
+    def testEncodingErrorsReading(self):
+        # (1) default
+        b = io.BytesIO(b"abc\n\xff\n")
+        t = io.TextIOWrapper(b, encoding="ascii")
+        self.assertRaises(UnicodeError, t.read)
+        # (2) explicit strict
+        b = io.BytesIO(b"abc\n\xff\n")
+        t = io.TextIOWrapper(b, encoding="ascii", errors="strict")
+        self.assertRaises(UnicodeError, t.read)
+        # (3) ignore
+        b = io.BytesIO(b"abc\n\xff\n")
+        t = io.TextIOWrapper(b, encoding="ascii", errors="ignore")
+        self.assertEquals(t.read(), "abc\n\n")
+        # (4) replace
+        b = io.BytesIO(b"abc\n\xff\n")
+        t = io.TextIOWrapper(b, encoding="ascii", errors="replace")
+        self.assertEquals(t.read(), "abc\n\ufffd\n")
+
+    def testEncodingErrorsWriting(self):
+        # (1) default
+        b = io.BytesIO()
+        t = io.TextIOWrapper(b, encoding="ascii")
+        self.assertRaises(UnicodeError, t.write, "\xff")
+        # (2) explicit strict
+        b = io.BytesIO()
+        t = io.TextIOWrapper(b, encoding="ascii", errors="strict")
+        self.assertRaises(UnicodeError, t.write, "\xff")
+        # (3) ignore
+        b = io.BytesIO()
+        t = io.TextIOWrapper(b, encoding="ascii", errors="ignore",
+                             newline="\n")
+        t.write("abc\xffdef\n")
+        t.flush()
+        self.assertEquals(b.getvalue(), b"abcdef\n")
+        # (4) replace
+        b = io.BytesIO()
+        t = io.TextIOWrapper(b, encoding="ascii", errors="replace",
+                             newline="\n")
+        t.write("abc\xffdef\n")
+        t.flush()
+        self.assertEquals(b.getvalue(), b"abc?def\n")
+
     def testNewlinesInput(self):
         testdata = b"AAA\nBBB\nCCC\rDDD\rEEE\r\nFFF\r\nGGG"
         normalized = testdata.replace(b"\r\n", b"\n").replace(b"\r", b"\n")
         for newline, expected in [
-            (None, normalized.decode("ASCII").splitlines(True)),
-            ("", testdata.decode("ASCII").splitlines(True)),
+            (None, normalized.decode("ascii").splitlines(True)),
+            ("", testdata.decode("ascii").splitlines(True)),
             ("\n", ["AAA\n", "BBB\n", "CCC\rDDD\rEEE\r\n", "FFF\r\n", "GGG"]),
             ("\r\n", ["AAA\nBBB\nCCC\rDDD\rEEE\r\n", "FFF\r\n", "GGG"]),
             ("\r",  ["AAA\nBBB\nCCC\r", "DDD\r", "EEE\r", "\nFFF\r", "\nGGG"]),
             ]:
             buf = io.BytesIO(testdata)
-            txt = io.TextIOWrapper(buf, encoding="ASCII", newline=newline)
+            txt = io.TextIOWrapper(buf, encoding="ascii", newline=newline)
             self.assertEquals(txt.readlines(), expected)
             txt.seek(0)
             self.assertEquals(txt.read(), "".join(expected))
@@ -510,7 +702,7 @@
         tests = [(None, testdict[os.linesep])] + sorted(testdict.items())
         for newline, expected in tests:
             buf = io.BytesIO()
-            txt = io.TextIOWrapper(buf, encoding="ASCII", newline=newline)
+            txt = io.TextIOWrapper(buf, encoding="ascii", newline=newline)
             txt.write("AAA\nB")
             txt.write("BB\nCCC\n")
             txt.write("X\rY\r\nZ")
@@ -560,14 +752,14 @@
         testdata = b"AAA\nBBB\nCCC\rDDD\rEEE\r\nFFF\r\nGGG"
         normalized = testdata.replace(b"\r\n", b"\n").replace(b"\r", b"\n")
         for newline, expected in [
-            (None, normalized.decode("ASCII").splitlines(True)),
-            ("", testdata.decode("ASCII").splitlines(True)),
+            (None, normalized.decode("ascii").splitlines(True)),
+            ("", testdata.decode("ascii").splitlines(True)),
             ("\n", ["AAA\n", "BBB\n", "CCC\rDDD\rEEE\r\n", "FFF\r\n", "GGG"]),
             ("\r\n", ["AAA\nBBB\nCCC\rDDD\rEEE\r\n", "FFF\r\n", "GGG"]),
             ("\r",  ["AAA\nBBB\nCCC\r", "DDD\r", "EEE\r", "\nFFF\r", "\nGGG"]),
             ]:
             buf = io.BytesIO(testdata)
-            txt = io.TextIOWrapper(buf, encoding="ASCII", newline=newline)
+            txt = io.TextIOWrapper(buf, encoding="ascii", newline=newline)
             self.assertEquals(txt.readlines(), expected)
             txt.seek(0)
             self.assertEquals(txt.read(), "".join(expected))
@@ -592,7 +784,7 @@
                 ("\r\n", "\r\n", data_crlf),
                 ]:
                 buf = io.BytesIO()
-                txt = io.TextIOWrapper(buf, encoding="ASCII", newline=newline)
+                txt = io.TextIOWrapper(buf, encoding="ascii", newline=newline)
                 txt.write(data)
                 txt.close()
                 self.assertEquals(buf.getvalue(), expected)
@@ -684,7 +876,7 @@
         f.close()
         f = io.open(test_support.TESTFN, "r", encoding="utf-8")
         s = f.read(prefix_size)
-        self.assertEquals(s, str(prefix))
+        self.assertEquals(s, str(prefix, "ascii"))
         self.assertEquals(f.tell(), prefix_size)
         self.assertEquals(f.readline(), u_suffix)
 
@@ -700,6 +892,78 @@
         f.readline()
         f.tell()
 
+    def testSeekAndTell(self):
+        """Test seek/tell using the StatefulIncrementalDecoder."""
+
+        def lookupTestDecoder(name):
+            if self.codecEnabled and name == 'test_decoder':
+                return codecs.CodecInfo(
+                    name='test_decoder', encode=None, decode=None,
+                    incrementalencoder=None,
+                    streamreader=None, streamwriter=None,
+                    incrementaldecoder=StatefulIncrementalDecoder)
+
+        def testSeekAndTellWithData(data, min_pos=0):
+            """Tell/seek to various points within a data stream and ensure
+            that the decoded data returned by read() is consistent."""
+            f = io.open(test_support.TESTFN, 'wb')
+            f.write(data)
+            f.close()
+            f = io.open(test_support.TESTFN, encoding='test_decoder')
+            decoded = f.read()
+            f.close()
+
+            for i in range(min_pos, len(decoded) + 1): # seek positions
+                for j in [1, 5, len(decoded) - i]: # read lengths
+                    f = io.open(test_support.TESTFN, encoding='test_decoder')
+                    self.assertEquals(f.read(i), decoded[:i])
+                    cookie = f.tell()
+                    self.assertEquals(f.read(j), decoded[i:i + j])
+                    f.seek(cookie)
+                    self.assertEquals(f.read(), decoded[i:])
+                    f.close()
+
+        # Register a special incremental decoder for testing.
+        codecs.register(lookupTestDecoder)
+        self.codecEnabled = 1
+
+        # Run the tests.
+        try:
+            # Try each test case.
+            for input, _, _ in StatefulIncrementalDecoderTest.test_cases:
+                testSeekAndTellWithData(input)
+
+            # Position each test case so that it crosses a chunk boundary.
+            CHUNK_SIZE = io.TextIOWrapper._CHUNK_SIZE
+            for input, _, _ in StatefulIncrementalDecoderTest.test_cases:
+                offset = CHUNK_SIZE - len(input)//2
+                prefix = b'.'*offset
+                # Don't bother seeking into the prefix (takes too long).
+                min_pos = offset*2
+                testSeekAndTellWithData(prefix + input, min_pos)
+
+        # Ensure our test decoder won't interfere with subsequent tests.
+        finally:
+            self.codecEnabled = 0
+
+    def testEncodedWrites(self):
+        data = "1234567890"
+        tests = ("utf-16",
+                 "utf-16-le",
+                 "utf-16-be",
+                 "utf-32",
+                 "utf-32-le",
+                 "utf-32-be")
+        for encoding in tests:
+            buf = io.BytesIO()
+            f = io.TextIOWrapper(buf, encoding=encoding)
+            # Check if the BOM is written only once (see issue1753).
+            f.write(data)
+            f.write(data)
+            f.seek(0)
+            self.assertEquals(f.read(), data * 2)
+            self.assertEquals(buf.getvalue(), (data * 2).encode(encoding))
+
     def timingTest(self):
         timer = time.time
         enc = "utf8"
@@ -737,6 +1001,136 @@
                 print("Reading using readline(): %6.3f seconds" % (t3-t2))
                 print("Using readline()+tell():  %6.3f seconds" % (t4-t3))
 
+    def testReadOneByOne(self):
+        txt = io.TextIOWrapper(io.BytesIO(b"AA\r\nBB"))
+        reads = ""
+        while True:
+            c = txt.read(1)
+            if not c:
+                break
+            reads += c
+        self.assertEquals(reads, "AA\nBB")
+
+    # read in amounts equal to TextIOWrapper._CHUNK_SIZE which is 128.
+    def testReadByChunk(self):
+        # make sure "\r\n" straddles 128 char boundary.
+        txt = io.TextIOWrapper(io.BytesIO(b"A" * 127 + b"\r\nB"))
+        reads = ""
+        while True:
+            c = txt.read(128)
+            if not c:
+                break
+            reads += c
+        self.assertEquals(reads, "A"*127+"\nB")
+
+    def test_issue1395_1(self):
+        txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ascii")
+
+        # read one char at a time
+        reads = ""
+        while True:
+            c = txt.read(1)
+            if not c:
+                break
+            reads += c
+        self.assertEquals(reads, self.normalized)
+
+    def test_issue1395_2(self):
+        txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ascii")
+        txt._CHUNK_SIZE = 4
+
+        reads = ""
+        while True:
+            c = txt.read(4)
+            if not c:
+                break
+            reads += c
+        self.assertEquals(reads, self.normalized)
+
+    def test_issue1395_3(self):
+        txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ascii")
+        txt._CHUNK_SIZE = 4
+
+        reads = txt.read(4)
+        reads += txt.read(4)
+        reads += txt.readline()
+        reads += txt.readline()
+        reads += txt.readline()
+        self.assertEquals(reads, self.normalized)
+
+    def test_issue1395_4(self):
+        txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ascii")
+        txt._CHUNK_SIZE = 4
+
+        reads = txt.read(4)
+        reads += txt.read()
+        self.assertEquals(reads, self.normalized)
+
+    def test_issue1395_5(self):
+        txt = io.TextIOWrapper(io.BytesIO(self.testdata), encoding="ascii")
+        txt._CHUNK_SIZE = 4
+
+        reads = txt.read(4)
+        pos = txt.tell()
+        txt.seek(0)
+        txt.seek(pos)
+        self.assertEquals(txt.read(4), "BBB\n")
+
+    def test_issue2282(self):
+        buffer = io.BytesIO(self.testdata)
+        txt = io.TextIOWrapper(buffer, encoding="ascii")
+
+        self.assertEqual(buffer.seekable(), txt.seekable())
+
+    def test_newline_decoder(self):
+        import codecs
+        decoder = codecs.getincrementaldecoder("utf-8")()
+        decoder = io.IncrementalNewlineDecoder(decoder, translate=True)
+
+        self.assertEquals(decoder.decode(b'\xe8\xa2\x88'), "\u8888")
+
+        self.assertEquals(decoder.decode(b'\xe8'), "")
+        self.assertEquals(decoder.decode(b'\xa2'), "")
+        self.assertEquals(decoder.decode(b'\x88'), "\u8888")
+
+        self.assertEquals(decoder.decode(b'\xe8'), "")
+        self.assertRaises(UnicodeDecodeError, decoder.decode, b'', final=True)
+
+        decoder.setstate((b'', 0))
+        self.assertEquals(decoder.decode(b'\n'), "\n")
+        self.assertEquals(decoder.decode(b'\r'), "")
+        self.assertEquals(decoder.decode(b'', final=True), "\n")
+        self.assertEquals(decoder.decode(b'\r', final=True), "\n")
+
+        self.assertEquals(decoder.decode(b'\r'), "")
+        self.assertEquals(decoder.decode(b'a'), "\na")
+
+        self.assertEquals(decoder.decode(b'\r\r\n'), "\n\n")
+        self.assertEquals(decoder.decode(b'\r'), "")
+        self.assertEquals(decoder.decode(b'\r'), "\n")
+        self.assertEquals(decoder.decode(b'\na'), "\na")
+
+        self.assertEquals(decoder.decode(b'\xe8\xa2\x88\r\n'), "\u8888\n")
+        self.assertEquals(decoder.decode(b'\xe8\xa2\x88'), "\u8888")
+        self.assertEquals(decoder.decode(b'\n'), "\n")
+        self.assertEquals(decoder.decode(b'\xe8\xa2\x88\r'), "\u8888")
+        self.assertEquals(decoder.decode(b'\n'), "\n")
+
+        decoder = codecs.getincrementaldecoder("utf-8")()
+        decoder = io.IncrementalNewlineDecoder(decoder, translate=True)
+        self.assertEquals(decoder.newlines, None)
+        decoder.decode(b"abc\n\r")
+        self.assertEquals(decoder.newlines, '\n')
+        decoder.decode(b"\nabc")
+        self.assertEquals(decoder.newlines, ('\n', '\r\n'))
+        decoder.decode(b"abc\r")
+        self.assertEquals(decoder.newlines, ('\n', '\r\n'))
+        decoder.decode(b"abc")
+        self.assertEquals(decoder.newlines, ('\r', '\n', '\r\n'))
+        decoder.decode(b"abc\r")
+        decoder.reset()
+        self.assertEquals(decoder.decode(b"abc"), "abc")
+        self.assertEquals(decoder.newlines, None)
 
 # XXX Tests for open()
 

Modified: python/branches/py3k-importlib/Lib/test/test_ioctl.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_ioctl.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_ioctl.py	Thu Mar 27 00:48:05 2008
@@ -14,6 +14,11 @@
 except IOError:
     raise TestSkipped("Unable to open /dev/tty")
 
+try:
+    import pty
+except ImportError:
+    pty = None
+
 class IoctlTests(unittest.TestCase):
     def test_ioctl(self):
         # If this process has been put into the background, TIOCGPGRP returns
@@ -34,6 +39,30 @@
         self.assertEquals(r, 0)
         self.assert_(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
 
+    def test_ioctl_signed_unsigned_code_param(self):
+        if not pty:
+            raise TestSkipped('pty module required')
+        mfd, sfd = pty.openpty()
+        try:
+            if termios.TIOCSWINSZ < 0:
+                set_winsz_opcode_maybe_neg = termios.TIOCSWINSZ
+                set_winsz_opcode_pos = termios.TIOCSWINSZ & 0xffffffff
+            else:
+                set_winsz_opcode_pos = termios.TIOCSWINSZ
+                set_winsz_opcode_maybe_neg, = struct.unpack("i",
+                        struct.pack("I", termios.TIOCSWINSZ))
+
+            # We're just testing that these calls do not raise exceptions.
+            saved_winsz = fcntl.ioctl(mfd, termios.TIOCGWINSZ, "\0"*8)
+            our_winsz = struct.pack("HHHH",80,25,0,0)
+            # test both with a positive and potentially negative ioctl code
+            new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz)
+            new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz)
+            fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, saved_winsz)
+        finally:
+            os.close(mfd)
+            os.close(sfd)
+
 def test_main():
     run_unittest(IoctlTests)
 

Modified: python/branches/py3k-importlib/Lib/test/test_isinstance.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_isinstance.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_isinstance.py	Thu Mar 27 00:48:05 2008
@@ -242,7 +242,7 @@
         self.assertEqual(True, issubclass(NewSuper, (NewChild, (NewSuper,))))
 
         self.assertEqual(True, issubclass(int, (int, (float, int))))
-        self.assertEqual(True, issubclass(str, (str, (Child, NewChild, basestring))))
+        self.assertEqual(True, issubclass(str, (str, (Child, NewChild, str))))
 
     def test_subclass_recursion_limit(self):
         # make sure that issubclass raises RuntimeError before the C stack is

Modified: python/branches/py3k-importlib/Lib/test/test_iter.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_iter.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_iter.py	Thu Mar 27 00:48:05 2008
@@ -382,13 +382,10 @@
 
     # Test map()'s use of iterators.
     def test_builtin_map(self):
-        self.assertEqual(list(map(None, SequenceClass(5))),
-                         [(0,), (1,), (2,), (3,), (4,)])
         self.assertEqual(list(map(lambda x: x+1, SequenceClass(5))),
                          list(range(1, 6)))
 
         d = {"one": 1, "two": 2, "three": 3}
-        self.assertEqual(list(map(None, d)), [(k,) for k in d])
         self.assertEqual(list(map(lambda k, d=d: (k, d[k]), d)),
                          list(d.items()))
         dkeys = list(d.keys())
@@ -396,11 +393,6 @@
                      i,
                      i < len(d) and dkeys[i] or None)
                     for i in range(3)]
-        self.assertEqual(list(map(None,
-                                  d,
-                                  SequenceClass(5),
-                                  iter(d.keys()))),
-                         expected)
 
         f = open(TESTFN, "w")
         try:

Modified: python/branches/py3k-importlib/Lib/test/test_iterlen.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_iterlen.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_iterlen.py	Thu Mar 27 00:48:05 2008
@@ -45,8 +45,7 @@
 from test import test_support
 from itertools import repeat
 from collections import deque
-from UserList import UserList
-from __builtin__ import len as _len
+from builtins import len as _len
 
 n = 10
 
@@ -196,44 +195,6 @@
         d.extend(range(20))
         self.assertEqual(len(it), 0)
 
-class TestSeqIter(TestInvariantWithoutMutations):
-
-    def setUp(self):
-        self.it = iter(UserList(range(n)))
-
-    def test_mutation(self):
-        d = UserList(range(n))
-        it = iter(d)
-        next(it)
-        next(it)
-        self.assertEqual(len(it), n-2)
-        d.append(n)
-        self.assertEqual(len(it), n-1)  # grow with append
-        d[1:] = []
-        self.assertEqual(len(it), 0)
-        self.assertEqual(list(it), [])
-        d.extend(range(20))
-        self.assertEqual(len(it), 0)
-
-class TestSeqIterReversed(TestInvariantWithoutMutations):
-
-    def setUp(self):
-        self.it = reversed(UserList(range(n)))
-
-    def test_mutation(self):
-        d = UserList(range(n))
-        it = reversed(d)
-        next(it)
-        next(it)
-        self.assertEqual(len(it), n-2)
-        d.append(n)
-        self.assertEqual(len(it), n-2)  # ignore append
-        d[1:] = []
-        self.assertEqual(len(it), 0)
-        self.assertEqual(list(it), [])  # confirm invariant
-        d.extend(range(20))
-        self.assertEqual(len(it), 0)
-
 
 def test_main():
     unittests = [
@@ -249,8 +210,6 @@
         TestSet,
         TestList,
         TestListReversed,
-        TestSeqIter,
-        TestSeqIterReversed,
     ]
     test_support.run_unittest(*unittests)
 

Modified: python/branches/py3k-importlib/Lib/test/test_itertools.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_itertools.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_itertools.py	Thu Mar 27 00:48:05 2008
@@ -5,6 +5,7 @@
 import sys
 import operator
 import random
+from functools import reduce
 maxsize = test_support.MAX_Py_ssize_t
 minsize = -maxsize-1
 
@@ -43,21 +44,165 @@
     'Convenience function for partially consuming a long of infinite iterable'
     return list(islice(seq, n))
 
+def prod(iterable):
+    return reduce(operator.mul, iterable, 1)
+
+def fact(n):
+    'Factorial'
+    return prod(range(1, n+1))
+
 class TestBasicOps(unittest.TestCase):
     def test_chain(self):
-        self.assertEqual(list(chain('abc', 'def')), list('abcdef'))
-        self.assertEqual(list(chain('abc')), list('abc'))
-        self.assertEqual(list(chain('')), [])
-        self.assertEqual(take(4, chain('abc', 'def')), list('abcd'))
-        self.assertRaises(TypeError, chain, 2, 3)
+
+        def chain2(*iterables):
+            'Pure python version in the docs'
+            for it in iterables:
+                for element in it:
+                    yield element
+
+        for c in (chain, chain2):
+            self.assertEqual(list(c('abc', 'def')), list('abcdef'))
+            self.assertEqual(list(c('abc')), list('abc'))
+            self.assertEqual(list(c('')), [])
+            self.assertEqual(take(4, c('abc', 'def')), list('abcd'))
+            self.assertRaises(TypeError, list,c(2, 3))
+
+    def test_chain_from_iterable(self):
+        self.assertEqual(list(chain.from_iterable(['abc', 'def'])), list('abcdef'))
+        self.assertEqual(list(chain.from_iterable(['abc'])), list('abc'))
+        self.assertEqual(list(chain.from_iterable([''])), [])
+        self.assertEqual(take(4, chain.from_iterable(['abc', 'def'])), list('abcd'))
+        self.assertRaises(TypeError, list, chain.from_iterable([2, 3]))
+
+    def test_combinations(self):
+        self.assertRaises(TypeError, combinations, 'abc')   # missing r argument
+        self.assertRaises(TypeError, combinations, 'abc', 2, 1) # too many arguments
+        self.assertRaises(TypeError, combinations, None)        # pool is not iterable
+        self.assertRaises(ValueError, combinations, 'abc', -2)  # r is negative
+        self.assertRaises(ValueError, combinations, 'abc', 32)  # r is too big
+        self.assertEqual(list(combinations(range(4), 3)),
+                                           [(0,1,2), (0,1,3), (0,2,3), (1,2,3)])
+
+        def combinations1(iterable, r):
+            'Pure python version shown in the docs'
+            pool = tuple(iterable)
+            n = len(pool)
+            indices = list(range(r))
+            yield tuple(pool[i] for i in indices)
+            while 1:
+                for i in reversed(range(r)):
+                    if indices[i] != i + n - r:
+                        break
+                else:
+                    return
+                indices[i] += 1
+                for j in range(i+1, r):
+                    indices[j] = indices[j-1] + 1
+                yield tuple(pool[i] for i in indices)
+
+        def combinations2(iterable, r):
+            'Pure python version shown in the docs'
+            pool = tuple(iterable)
+            n = len(pool)
+            for indices in permutations(range(n), r):
+                if sorted(indices) == list(indices):
+                    yield tuple(pool[i] for i in indices)
+
+        for n in range(7):
+            values = [5*x-12 for x in range(n)]
+            for r in range(n+1):
+                result = list(combinations(values, r))
+                self.assertEqual(len(result), fact(n) / fact(r) / fact(n-r)) # right number of combs
+                self.assertEqual(len(result), len(set(result)))         # no repeats
+                self.assertEqual(result, sorted(result))                # lexicographic order
+                for c in result:
+                    self.assertEqual(len(c), r)                         # r-length combinations
+                    self.assertEqual(len(set(c)), r)                    # no duplicate elements
+                    self.assertEqual(list(c), sorted(c))                # keep original ordering
+                    self.assert_(all(e in values for e in c))           # elements taken from input iterable
+                    self.assertEqual(list(c),
+                                     [e for e in values if e in c])      # comb is a subsequence of the input iterable
+                self.assertEqual(result, list(combinations1(values, r))) # matches first pure python version
+                self.assertEqual(result, list(combinations2(values, r))) # matches first pure python version
+
+        # Test implementation detail:  tuple re-use
+        self.assertEqual(len(set(map(id, combinations('abcde', 3)))), 1)
+        self.assertNotEqual(len(set(map(id, list(combinations('abcde', 3))))), 1)
+
+    def test_permutations(self):
+        self.assertRaises(TypeError, permutations)              # too few arguments
+        self.assertRaises(TypeError, permutations, 'abc', 2, 1) # too many arguments
+        self.assertRaises(TypeError, permutations, None)        # pool is not iterable
+        self.assertRaises(ValueError, permutations, 'abc', -2)  # r is negative
+        self.assertRaises(ValueError, permutations, 'abc', 32)  # r is too big
+        self.assertRaises(TypeError, permutations, 'abc', 's')  # r is not an int or None
+        self.assertEqual(list(permutations(range(3), 2)),
+                                           [(0,1), (0,2), (1,0), (1,2), (2,0), (2,1)])
+
+        def permutations1(iterable, r=None):
+            'Pure python version shown in the docs'
+            pool = tuple(iterable)
+            n = len(pool)
+            r = n if r is None else r
+            indices = list(range(n))
+            cycles = list(range(n-r+1, n+1))[::-1]
+            yield tuple(pool[i] for i in indices[:r])
+            while n:
+                for i in reversed(range(r)):
+                    cycles[i] -= 1
+                    if cycles[i] == 0:
+                        indices[i:] = indices[i+1:] + indices[i:i+1]
+                        cycles[i] = n - i
+                    else:
+                        j = cycles[i]
+                        indices[i], indices[-j] = indices[-j], indices[i]
+                        yield tuple(pool[i] for i in indices[:r])
+                        break
+                else:
+                    return
+
+        def permutations2(iterable, r=None):
+            'Pure python version shown in the docs'
+            pool = tuple(iterable)
+            n = len(pool)
+            r = n if r is None else r
+            for indices in product(range(n), repeat=r):
+                if len(set(indices)) == r:
+                    yield tuple(pool[i] for i in indices)
+
+        for n in range(7):
+            values = [5*x-12 for x in range(n)]
+            for r in range(n+1):
+                result = list(permutations(values, r))
+                self.assertEqual(len(result), fact(n) / fact(n-r))      # right number of perms
+                self.assertEqual(len(result), len(set(result)))         # no repeats
+                self.assertEqual(result, sorted(result))                # lexicographic order
+                for p in result:
+                    self.assertEqual(len(p), r)                         # r-length permutations
+                    self.assertEqual(len(set(p)), r)                    # no duplicate elements
+                    self.assert_(all(e in values for e in p))           # elements taken from input iterable
+                self.assertEqual(result, list(permutations1(values, r))) # matches first pure python version
+                self.assertEqual(result, list(permutations2(values, r))) # matches first pure python version
+                if r == n:
+                    self.assertEqual(result, list(permutations(values, None))) # test r as None
+                    self.assertEqual(result, list(permutations(values)))       # test default r
+
+        # Test implementation detail:  tuple re-use
+        self.assertEqual(len(set(map(id, permutations('abcde', 3)))), 1)
+        self.assertNotEqual(len(set(map(id, list(permutations('abcde', 3))))), 1)
 
     def test_count(self):
         self.assertEqual(lzip('abc',count()), [('a', 0), ('b', 1), ('c', 2)])
         self.assertEqual(lzip('abc',count(3)), [('a', 3), ('b', 4), ('c', 5)])
         self.assertEqual(take(2, lzip('abc',count(3))), [('a', 3), ('b', 4)])
+        self.assertEqual(take(2, zip('abc',count(-1))), [('a', -1), ('b', 0)])
+        self.assertEqual(take(2, zip('abc',count(-3))), [('a', -3), ('b', -2)])
         self.assertRaises(TypeError, count, 2, 3)
         self.assertRaises(TypeError, count, 'a')
-        self.assertRaises(OverflowError, list, islice(count(maxsize-5), 10))
+        self.assertEqual(list(islice(count(maxsize-5), 10)),
+                         list(range(maxsize-5, maxsize+5)))
+        self.assertEqual(list(islice(count(-maxsize-5), 10)),
+                         list(range(-maxsize-5, -maxsize+5)))
         c = count(3)
         self.assertEqual(repr(c), 'count(3)')
         next(c)
@@ -66,6 +211,11 @@
         self.assertEqual(repr(c), 'count(-9)')
         next(c)
         self.assertEqual(next(c), -8)
+        for i in (-sys.maxsize-5, -sys.maxsize+5 ,-10, -1, 0, 10, sys.maxsize-5, sys.maxsize+5):
+            # Test repr (ignoring the L in longs)
+            r1 = repr(count(i)).replace('L', '')
+            r2 = 'count(%r)'.__mod__(i).replace('L', '')
+            self.assertEqual(r1, r2)
 
     def test_cycle(self):
         self.assertEqual(take(10, cycle('abc')), list('abcabcabca'))
@@ -163,48 +313,50 @@
         keyfunc.skip = 1
         self.assertRaises(ExpectedError, gulp, [None, None], keyfunc)
 
-    def test_ifilter(self):
-        self.assertEqual(list(ifilter(isEven, range(6))), [0,2,4])
-        self.assertEqual(list(ifilter(None, [0,1,0,2,0])), [1,2])
-        self.assertEqual(take(4, ifilter(isEven, count())), [0,2,4,6])
-        self.assertRaises(TypeError, ifilter)
-        self.assertRaises(TypeError, ifilter, lambda x:x)
-        self.assertRaises(TypeError, ifilter, lambda x:x, range(6), 7)
-        self.assertRaises(TypeError, ifilter, isEven, 3)
-        self.assertRaises(TypeError, next, ifilter(range(6), range(6)))
-
-    def test_ifilterfalse(self):
-        self.assertEqual(list(ifilterfalse(isEven, range(6))), [1,3,5])
-        self.assertEqual(list(ifilterfalse(None, [0,1,0,2,0])), [0,0,0])
-        self.assertEqual(take(4, ifilterfalse(isEven, count())), [1,3,5,7])
-        self.assertRaises(TypeError, ifilterfalse)
-        self.assertRaises(TypeError, ifilterfalse, lambda x:x)
-        self.assertRaises(TypeError, ifilterfalse, lambda x:x, range(6), 7)
-        self.assertRaises(TypeError, ifilterfalse, isEven, 3)
-        self.assertRaises(TypeError, next, ifilterfalse(range(6), range(6)))
-
-    def test_izip(self):
-        # XXX This is rather silly now that builtin zip() calls izip()...
-        ans = [(x,y) for x, y in izip('abc',count())]
+    def test_filter(self):
+        self.assertEqual(list(filter(isEven, range(6))), [0,2,4])
+        self.assertEqual(list(filter(None, [0,1,0,2,0])), [1,2])
+        self.assertEqual(list(filter(bool, [0,1,0,2,0])), [1,2])
+        self.assertEqual(take(4, filter(isEven, count())), [0,2,4,6])
+        self.assertRaises(TypeError, filter)
+        self.assertRaises(TypeError, filter, lambda x:x)
+        self.assertRaises(TypeError, filter, lambda x:x, range(6), 7)
+        self.assertRaises(TypeError, filter, isEven, 3)
+        self.assertRaises(TypeError, next, filter(range(6), range(6)))
+
+    def test_filterfalse(self):
+        self.assertEqual(list(filterfalse(isEven, range(6))), [1,3,5])
+        self.assertEqual(list(filterfalse(None, [0,1,0,2,0])), [0,0,0])
+        self.assertEqual(list(filterfalse(bool, [0,1,0,2,0])), [0,0,0])
+        self.assertEqual(take(4, filterfalse(isEven, count())), [1,3,5,7])
+        self.assertRaises(TypeError, filterfalse)
+        self.assertRaises(TypeError, filterfalse, lambda x:x)
+        self.assertRaises(TypeError, filterfalse, lambda x:x, range(6), 7)
+        self.assertRaises(TypeError, filterfalse, isEven, 3)
+        self.assertRaises(TypeError, next, filterfalse(range(6), range(6)))
+
+    def test_zip(self):
+        # XXX This is rather silly now that builtin zip() calls zip()...
+        ans = [(x,y) for x, y in zip('abc',count())]
         self.assertEqual(ans, [('a', 0), ('b', 1), ('c', 2)])
-        self.assertEqual(list(izip('abc', range(6))), lzip('abc', range(6)))
-        self.assertEqual(list(izip('abcdef', range(3))), lzip('abcdef', range(3)))
-        self.assertEqual(take(3,izip('abcdef', count())), lzip('abcdef', range(3)))
-        self.assertEqual(list(izip('abcdef')), lzip('abcdef'))
-        self.assertEqual(list(izip()), lzip())
-        self.assertRaises(TypeError, izip, 3)
-        self.assertRaises(TypeError, izip, range(3), 3)
+        self.assertEqual(list(zip('abc', range(6))), lzip('abc', range(6)))
+        self.assertEqual(list(zip('abcdef', range(3))), lzip('abcdef', range(3)))
+        self.assertEqual(take(3,zip('abcdef', count())), lzip('abcdef', range(3)))
+        self.assertEqual(list(zip('abcdef')), lzip('abcdef'))
+        self.assertEqual(list(zip()), lzip())
+        self.assertRaises(TypeError, zip, 3)
+        self.assertRaises(TypeError, zip, range(3), 3)
         # Check tuple re-use (implementation detail)
-        self.assertEqual([tuple(list(pair)) for pair in izip('abc', 'def')],
+        self.assertEqual([tuple(list(pair)) for pair in zip('abc', 'def')],
                          lzip('abc', 'def'))
-        self.assertEqual([pair for pair in izip('abc', 'def')],
+        self.assertEqual([pair for pair in zip('abc', 'def')],
                          lzip('abc', 'def'))
-        ids = list(map(id, izip('abc', 'def')))
+        ids = list(map(id, zip('abc', 'def')))
         self.assertEqual(min(ids), max(ids))
-        ids = list(map(id, list(izip('abc', 'def'))))
+        ids = list(map(id, list(zip('abc', 'def'))))
         self.assertEqual(len(dict.fromkeys(ids)), len(ids))
 
-    def test_iziplongest(self):
+    def test_ziplongest(self):
         for args in [
                 ['abc', range(6)],
                 [range(6), 'abc'],
@@ -214,25 +366,25 @@
             ]:
             target = [tuple([arg[i] if i < len(arg) else None for arg in args])
                       for i in range(max(map(len, args)))]
-            self.assertEqual(list(izip_longest(*args)), target)
-            self.assertEqual(list(izip_longest(*args, **{})), target)
+            self.assertEqual(list(zip_longest(*args)), target)
+            self.assertEqual(list(zip_longest(*args, **{})), target)
             target = [tuple((e is None and 'X' or e) for e in t) for t in target]   # Replace None fills with 'X'
-            self.assertEqual(list(izip_longest(*args, **dict(fillvalue='X'))), target)
+            self.assertEqual(list(zip_longest(*args, **dict(fillvalue='X'))), target)
 
-        self.assertEqual(take(3,izip_longest('abcdef', count())), list(zip('abcdef', range(3)))) # take 3 from infinite input
+        self.assertEqual(take(3,zip_longest('abcdef', count())), list(zip('abcdef', range(3)))) # take 3 from infinite input
 
-        self.assertEqual(list(izip_longest()), list(zip()))
-        self.assertEqual(list(izip_longest([])), list(zip([])))
-        self.assertEqual(list(izip_longest('abcdef')), list(zip('abcdef')))
-
-        self.assertEqual(list(izip_longest('abc', 'defg', **{})),
-                         list(map(None, list('abc')+[None], 'defg'))) # empty keyword dict
-        self.assertRaises(TypeError, izip_longest, 3)
-        self.assertRaises(TypeError, izip_longest, range(3), 3)
+        self.assertEqual(list(zip_longest()), list(zip()))
+        self.assertEqual(list(zip_longest([])), list(zip([])))
+        self.assertEqual(list(zip_longest('abcdef')), list(zip('abcdef')))
+
+        self.assertEqual(list(zip_longest('abc', 'defg', **{})),
+                         list(zip(list('abc')+[None], 'defg'))) # empty keyword dict
+        self.assertRaises(TypeError, zip_longest, 3)
+        self.assertRaises(TypeError, zip_longest, range(3), 3)
 
         for stmt in [
-            "izip_longest('abc', fv=1)",
-            "izip_longest('abc', fillvalue=1, bogus_keyword=None)",
+            "zip_longest('abc', fv=1)",
+            "zip_longest('abc', fillvalue=1, bogus_keyword=None)",
         ]:
             try:
                 eval(stmt, globals(), locals())
@@ -242,15 +394,77 @@
                 self.fail('Did not raise Type in:  ' + stmt)
 
         # Check tuple re-use (implementation detail)
-        self.assertEqual([tuple(list(pair)) for pair in izip_longest('abc', 'def')],
+        self.assertEqual([tuple(list(pair)) for pair in zip_longest('abc', 'def')],
                          list(zip('abc', 'def')))
-        self.assertEqual([pair for pair in izip_longest('abc', 'def')],
+        self.assertEqual([pair for pair in zip_longest('abc', 'def')],
                          list(zip('abc', 'def')))
-        ids = list(map(id, izip_longest('abc', 'def')))
+        ids = list(map(id, zip_longest('abc', 'def')))
         self.assertEqual(min(ids), max(ids))
-        ids = list(map(id, list(izip_longest('abc', 'def'))))
+        ids = list(map(id, list(zip_longest('abc', 'def'))))
         self.assertEqual(len(dict.fromkeys(ids)), len(ids))
 
+    def test_product(self):
+        for args, result in [
+            ([], [()]),                     # zero iterables
+            (['ab'], [('a',), ('b',)]),     # one iterable
+            ([range(2), range(3)], [(0,0), (0,1), (0,2), (1,0), (1,1), (1,2)]),     # two iterables
+            ([range(0), range(2), range(3)], []),           # first iterable with zero length
+            ([range(2), range(0), range(3)], []),           # middle iterable with zero length
+            ([range(2), range(3), range(0)], []),           # last iterable with zero length
+            ]:
+            self.assertEqual(list(product(*args)), result)
+            for r in range(4):
+                self.assertEqual(list(product(*(args*r))),
+                                 list(product(*args, **dict(repeat=r))))
+        self.assertEqual(len(list(product(*[range(7)]*6))), 7**6)
+        self.assertRaises(TypeError, product, range(6), None)
+
+        def product1(*args, **kwds):
+            pools = list(map(tuple, args)) * kwds.get('repeat', 1)
+            n = len(pools)
+            if n == 0:
+                yield ()
+                return
+            if any(len(pool) == 0 for pool in pools):
+                return
+            indices = [0] * n
+            yield tuple(pool[i] for pool, i in zip(pools, indices))
+            while 1:
+                for i in reversed(range(n)):  # right to left
+                    if indices[i] == len(pools[i]) - 1:
+                        continue
+                    indices[i] += 1
+                    for j in range(i+1, n):
+                        indices[j] = 0
+                    yield tuple(pool[i] for pool, i in zip(pools, indices))
+                    break
+                else:
+                    return
+
+        def product2(*args, **kwds):
+            'Pure python version used in docs'
+            pools = list(map(tuple, args)) * kwds.get('repeat', 1)
+            result = [[]]
+            for pool in pools:
+                result = [x+[y] for x in result for y in pool]
+            for prod in result:
+                yield tuple(prod)
+
+        argtypes = ['', 'abc', '', range(0), range(4), dict(a=1, b=2, c=3),
+                    set('abcdefg'), range(11), tuple(range(13))]
+        for i in range(100):
+            args = [random.choice(argtypes) for j in range(random.randrange(5))]
+            expected_len = prod(map(len, args))
+            self.assertEqual(len(list(product(*args))), expected_len)
+            self.assertEqual(list(product(*args)), list(product1(*args)))
+            self.assertEqual(list(product(*args)), list(product2(*args)))
+            args = map(iter, args)
+            self.assertEqual(len(list(product(*args))), expected_len)
+
+        # Test implementation detail:  tuple re-use
+        self.assertEqual(len(set(map(id, product('abc', 'def')))), 1)
+        self.assertNotEqual(len(set(map(id, list(product('abc', 'def'))))), 1)
+
     def test_repeat(self):
         self.assertEqual(lzip(range(3),repeat('a')),
                          [(0, 'a'), (1, 'a'), (2, 'a')])
@@ -268,29 +482,33 @@
         list(r)
         self.assertEqual(repr(r), 'repeat((1+0j), 0)')
 
-    def test_imap(self):
-        self.assertEqual(list(imap(operator.pow, range(3), range(1,7))),
+    def test_map(self):
+        self.assertEqual(list(map(operator.pow, range(3), range(1,7))),
                          [0**1, 1**2, 2**3])
-        self.assertEqual(list(imap(None, 'abc', range(5))),
+        def tupleize(*args):
+            return args
+        self.assertEqual(list(map(tupleize, 'abc', range(5))),
                          [('a',0),('b',1),('c',2)])
-        self.assertEqual(list(imap(None, 'abc', count())),
+        self.assertEqual(list(map(tupleize, 'abc', count())),
                          [('a',0),('b',1),('c',2)])
-        self.assertEqual(take(2,imap(None, 'abc', count())),
+        self.assertEqual(take(2,map(tupleize, 'abc', count())),
                          [('a',0),('b',1)])
-        self.assertEqual(list(imap(operator.pow, [])), [])
-        self.assertRaises(TypeError, imap)
-        self.assertRaises(TypeError, imap, operator.neg)
-        self.assertRaises(TypeError, next, imap(10, range(5)))
-        self.assertRaises(ValueError, next, imap(errfunc, [4], [5]))
-        self.assertRaises(TypeError, next, imap(onearg, [4], [5]))
+        self.assertEqual(list(map(operator.pow, [])), [])
+        self.assertRaises(TypeError, map)
+        self.assertRaises(TypeError, list, map(None, range(3), range(3)))
+        self.assertRaises(TypeError, map, operator.neg)
+        self.assertRaises(TypeError, next, map(10, range(5)))
+        self.assertRaises(ValueError, next, map(errfunc, [4], [5]))
+        self.assertRaises(TypeError, next, map(onearg, [4], [5]))
 
     def test_starmap(self):
         self.assertEqual(list(starmap(operator.pow, zip(range(3), range(1,7)))),
                          [0**1, 1**2, 2**3])
-        self.assertEqual(take(3, starmap(operator.pow, izip(count(), count(1)))),
+        self.assertEqual(take(3, starmap(operator.pow, zip(count(), count(1)))),
                          [0**1, 1**2, 2**3])
         self.assertEqual(list(starmap(operator.pow, [])), [])
-        self.assertRaises(TypeError, list, starmap(operator.pow, [[4,5]]))
+        self.assertEqual(list(starmap(operator.pow, [iter([4,5])])), [4**5])
+        self.assertRaises(TypeError, list, starmap(operator.pow, [None]))
         self.assertRaises(TypeError, starmap)
         self.assertRaises(TypeError, starmap, operator.pow, [(4,5)], 'extra')
         self.assertRaises(TypeError, next, starmap(10, [(4,5)]))
@@ -457,9 +675,9 @@
         self.assertRaises(ReferenceError, getattr, p, '__class__')
 
     def test_StopIteration(self):
-        self.assertRaises(StopIteration, next, izip())
+        self.assertRaises(StopIteration, next, zip())
 
-        for f in (chain, cycle, izip, groupby):
+        for f in (chain, cycle, zip, groupby):
             self.assertRaises(StopIteration, next, f([]))
             self.assertRaises(StopIteration, next, f(StopNow()))
 
@@ -475,10 +693,85 @@
 
         self.assertRaises(StopIteration, next, repeat(None, 0))
 
-        for f in (ifilter, ifilterfalse, imap, takewhile, dropwhile, starmap):
+        for f in (filter, filterfalse, map, takewhile, dropwhile, starmap):
             self.assertRaises(StopIteration, next, f(lambda x:x, []))
             self.assertRaises(StopIteration, next, f(lambda x:x, StopNow()))
 
+class TestExamples(unittest.TestCase):
+
+    def test_chain(self):
+        self.assertEqual(''.join(chain('ABC', 'DEF')), 'ABCDEF')
+
+    def test_chain_from_iterable(self):
+        self.assertEqual(''.join(chain.from_iterable(['ABC', 'DEF'])), 'ABCDEF')
+
+    def test_combinations(self):
+        self.assertEqual(list(combinations('ABCD', 2)),
+                         [('A','B'), ('A','C'), ('A','D'), ('B','C'), ('B','D'), ('C','D')])
+        self.assertEqual(list(combinations(range(4), 3)),
+                         [(0,1,2), (0,1,3), (0,2,3), (1,2,3)])
+
+    def test_count(self):
+        self.assertEqual(list(islice(count(10), 5)), [10, 11, 12, 13, 14])
+
+    def test_cycle(self):
+        self.assertEqual(list(islice(cycle('ABCD'), 12)), list('ABCDABCDABCD'))
+
+    def test_dropwhile(self):
+        self.assertEqual(list(dropwhile(lambda x: x<5, [1,4,6,4,1])), [6,4,1])
+
+    def test_groupby(self):
+        self.assertEqual([k for k, g in groupby('AAAABBBCCDAABBB')],
+                         list('ABCDAB'))
+        self.assertEqual([(list(g)) for k, g in groupby('AAAABBBCCD')],
+                         [list('AAAA'), list('BBB'), list('CC'), list('D')])
+
+    def test_filter(self):
+        self.assertEqual(list(filter(lambda x: x%2, range(10))), [1,3,5,7,9])
+
+    def test_filterfalse(self):
+        self.assertEqual(list(filterfalse(lambda x: x%2, range(10))), [0,2,4,6,8])
+
+    def test_map(self):
+        self.assertEqual(list(map(pow, (2,3,10), (5,2,3))), [32, 9, 1000])
+
+    def test_islice(self):
+        self.assertEqual(list(islice('ABCDEFG', 2)), list('AB'))
+        self.assertEqual(list(islice('ABCDEFG', 2, 4)), list('CD'))
+        self.assertEqual(list(islice('ABCDEFG', 2, None)), list('CDEFG'))
+        self.assertEqual(list(islice('ABCDEFG', 0, None, 2)), list('ACEG'))
+
+    def test_zip(self):
+        self.assertEqual(list(zip('ABCD', 'xy')), [('A', 'x'), ('B', 'y')])
+
+    def test_zip_longest(self):
+        self.assertEqual(list(zip_longest('ABCD', 'xy', fillvalue='-')),
+                         [('A', 'x'), ('B', 'y'), ('C', '-'), ('D', '-')])
+
+    def test_permutations(self):
+        self.assertEqual(list(permutations('ABCD', 2)),
+                         list(map(tuple, 'AB AC AD BA BC BD CA CB CD DA DB DC'.split())))
+        self.assertEqual(list(permutations(range(3))),
+                         [(0,1,2), (0,2,1), (1,0,2), (1,2,0), (2,0,1), (2,1,0)])
+
+    def test_product(self):
+        self.assertEqual(list(product('ABCD', 'xy')),
+                         list(map(tuple, 'Ax Ay Bx By Cx Cy Dx Dy'.split())))
+        self.assertEqual(list(product(range(2), repeat=3)),
+                        [(0,0,0), (0,0,1), (0,1,0), (0,1,1),
+                         (1,0,0), (1,0,1), (1,1,0), (1,1,1)])
+
+    def test_repeat(self):
+        self.assertEqual(list(repeat(10, 3)), [10, 10, 10])
+
+    def test_stapmap(self):
+        self.assertEqual(list(starmap(pow, [(2,5), (3,2), (10,3)])),
+                         [32, 9, 1000])
+
+    def test_takewhile(self):
+        self.assertEqual(list(takewhile(lambda x: x<5, [1,4,6,4,1])), [1,4])
+
+
 class TestGC(unittest.TestCase):
 
     def makecycle(self, iterator, container):
@@ -490,6 +783,14 @@
         a = []
         self.makecycle(chain(a), a)
 
+    def test_chain_from_iterable(self):
+        a = []
+        self.makecycle(chain.from_iterable([a]), a)
+
+    def test_combinations(self):
+        a = []
+        self.makecycle(combinations([1,2,a,3], 3), a)
+
     def test_cycle(self):
         a = []
         self.makecycle(cycle([a]*2), a)
@@ -502,26 +803,47 @@
         a = []
         self.makecycle(groupby([a]*2, lambda x:x), a)
 
-    def test_ifilter(self):
+    def test_issue2246(self):
+        # Issue 2246 -- the _grouper iterator was not included in GC
+        n = 10
+        keyfunc = lambda x: x
+        for i, j in groupby(range(n), key=keyfunc):
+            keyfunc.__dict__.setdefault('x',[]).append(j)
+
+    def test_filter(self):
+        a = []
+        self.makecycle(filter(lambda x:True, [a]*2), a)
+
+    def test_filterfalse(self):
         a = []
-        self.makecycle(ifilter(lambda x:True, [a]*2), a)
+        self.makecycle(filterfalse(lambda x:False, a), a)
 
-    def test_ifilterfalse(self):
+    def test_zip(self):
         a = []
-        self.makecycle(ifilterfalse(lambda x:False, a), a)
+        self.makecycle(zip([a]*2, [a]*3), a)
 
-    def test_izip(self):
+    def test_zip_longest(self):
         a = []
-        self.makecycle(izip([a]*2, [a]*3), a)
+        self.makecycle(zip_longest([a]*2, [a]*3), a)
+        b = [a, None]
+        self.makecycle(zip_longest([a]*2, [a]*3, fillvalue=b), a)
 
-    def test_imap(self):
+    def test_map(self):
         a = []
-        self.makecycle(imap(lambda x:x, [a]*2), a)
+        self.makecycle(map(lambda x:x, [a]*2), a)
 
     def test_islice(self):
         a = []
         self.makecycle(islice([a]*2, None), a)
 
+    def test_permutations(self):
+        a = []
+        self.makecycle(permutations([1,2,a,3], 3), a)
+
+    def test_product(self):
+        a = []
+        self.makecycle(product([1,2,a,3], repeat=3), a)
+
     def test_repeat(self):
         a = []
         self.makecycle(repeat(a), a)
@@ -608,7 +930,7 @@
 
 def L(seqn):
     'Test multiple tiers of iterators'
-    return chain(imap(lambda x:x, R(Ig(G(seqn)))))
+    return chain(map(lambda x:x, R(Ig(G(seqn)))))
 
 
 class TestVariousIteratorArgs(unittest.TestCase):
@@ -618,10 +940,16 @@
             for g in (G, I, Ig, S, L, R):
                 self.assertEqual(list(chain(g(s))), list(g(s)))
                 self.assertEqual(list(chain(g(s), g(s))), list(g(s))+list(g(s)))
-            self.assertRaises(TypeError, chain, X(s))
-            self.assertRaises(TypeError, chain, N(s))
+            self.assertRaises(TypeError, list, chain(X(s)))
+            self.assertRaises(TypeError, list, chain(N(s)))
             self.assertRaises(ZeroDivisionError, list, chain(E(s)))
 
+    def test_product(self):
+        for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
+            self.assertRaises(TypeError, product, X(s))
+            self.assertRaises(TypeError, product, N(s))
+            self.assertRaises(ZeroDivisionError, product, E(s))
+
     def test_cycle(self):
         for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
             for g in (G, I, Ig, S, L, R):
@@ -641,52 +969,52 @@
             self.assertRaises(TypeError, groupby, N(s))
             self.assertRaises(ZeroDivisionError, list, groupby(E(s)))
 
-    def test_ifilter(self):
+    def test_filter(self):
         for s in (range(10), range(0), range(1000), (7,11), range(2000,2200,5)):
             for g in (G, I, Ig, S, L, R):
-                self.assertEqual(list(ifilter(isEven, g(s))),
+                self.assertEqual(list(filter(isEven, g(s))),
                                  [x for x in g(s) if isEven(x)])
-            self.assertRaises(TypeError, ifilter, isEven, X(s))
-            self.assertRaises(TypeError, ifilter, isEven, N(s))
-            self.assertRaises(ZeroDivisionError, list, ifilter(isEven, E(s)))
+            self.assertRaises(TypeError, filter, isEven, X(s))
+            self.assertRaises(TypeError, filter, isEven, N(s))
+            self.assertRaises(ZeroDivisionError, list, filter(isEven, E(s)))
 
-    def test_ifilterfalse(self):
+    def test_filterfalse(self):
         for s in (range(10), range(0), range(1000), (7,11), range(2000,2200,5)):
             for g in (G, I, Ig, S, L, R):
-                self.assertEqual(list(ifilterfalse(isEven, g(s))),
+                self.assertEqual(list(filterfalse(isEven, g(s))),
                                  [x for x in g(s) if isOdd(x)])
-            self.assertRaises(TypeError, ifilterfalse, isEven, X(s))
-            self.assertRaises(TypeError, ifilterfalse, isEven, N(s))
-            self.assertRaises(ZeroDivisionError, list, ifilterfalse(isEven, E(s)))
+            self.assertRaises(TypeError, filterfalse, isEven, X(s))
+            self.assertRaises(TypeError, filterfalse, isEven, N(s))
+            self.assertRaises(ZeroDivisionError, list, filterfalse(isEven, E(s)))
 
-    def test_izip(self):
+    def test_zip(self):
         for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
             for g in (G, I, Ig, S, L, R):
-                self.assertEqual(list(izip(g(s))), lzip(g(s)))
-                self.assertEqual(list(izip(g(s), g(s))), lzip(g(s), g(s)))
-            self.assertRaises(TypeError, izip, X(s))
-            self.assertRaises(TypeError, izip, N(s))
-            self.assertRaises(ZeroDivisionError, list, izip(E(s)))
+                self.assertEqual(list(zip(g(s))), lzip(g(s)))
+                self.assertEqual(list(zip(g(s), g(s))), lzip(g(s), g(s)))
+            self.assertRaises(TypeError, zip, X(s))
+            self.assertRaises(TypeError, zip, N(s))
+            self.assertRaises(ZeroDivisionError, list, zip(E(s)))
 
-    def test_iziplongest(self):
+    def test_ziplongest(self):
         for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
             for g in (G, I, Ig, S, L, R):
-                self.assertEqual(list(izip_longest(g(s))), list(zip(g(s))))
-                self.assertEqual(list(izip_longest(g(s), g(s))), list(zip(g(s), g(s))))
-            self.assertRaises(TypeError, izip_longest, X(s))
-            self.assertRaises(TypeError, izip_longest, N(s))
-            self.assertRaises(ZeroDivisionError, list, izip_longest(E(s)))
+                self.assertEqual(list(zip_longest(g(s))), list(zip(g(s))))
+                self.assertEqual(list(zip_longest(g(s), g(s))), list(zip(g(s), g(s))))
+            self.assertRaises(TypeError, zip_longest, X(s))
+            self.assertRaises(TypeError, zip_longest, N(s))
+            self.assertRaises(ZeroDivisionError, list, zip_longest(E(s)))
 
-    def test_imap(self):
+    def test_map(self):
         for s in (range(10), range(0), range(100), (7,11), range(20,50,5)):
             for g in (G, I, Ig, S, L, R):
-                self.assertEqual(list(imap(onearg, g(s))),
+                self.assertEqual(list(map(onearg, g(s))),
                                  [onearg(x) for x in g(s)])
-                self.assertEqual(list(imap(operator.pow, g(s), g(s))),
+                self.assertEqual(list(map(operator.pow, g(s), g(s))),
                                  [x**x for x in g(s)])
-            self.assertRaises(TypeError, imap, onearg, X(s))
-            self.assertRaises(TypeError, imap, onearg, N(s))
-            self.assertRaises(ZeroDivisionError, list, imap(onearg, E(s)))
+            self.assertRaises(TypeError, map, onearg, X(s))
+            self.assertRaises(TypeError, map, onearg, N(s))
+            self.assertRaises(ZeroDivisionError, list, map(onearg, E(s)))
 
     def test_islice(self):
         for s in ("12345", "", range(1000), ('do', 1.2), range(2000,2200,5)):
@@ -763,8 +1091,8 @@
                 return value
             items = list(tuple2)
             items[1:1] = list(tuple1)
-            gen = imap(g, items)
-            z = izip(*[gen]*len(tuple1))
+            gen = map(g, items)
+            z = zip(*[gen]*len(tuple1))
             next(z)
 
         def f(t):
@@ -811,7 +1139,7 @@
 class SubclassWithKwargsTest(unittest.TestCase):
     def test_keywords_in_subclass(self):
         # count is not subclassable...
-        for cls in (repeat, izip, ifilter, ifilterfalse, chain, imap,
+        for cls in (repeat, zip, filter, filterfalse, chain, map,
                     starmap, islice, takewhile, dropwhile, cycle):
             class Subclass(cls):
                 def __init__(self, newarg=None, *args):
@@ -827,7 +1155,7 @@
 
 
 >>> amounts = [120.15, 764.05, 823.14]
->>> for checknum, amount in izip(count(1200), amounts):
+>>> for checknum, amount in zip(count(1200), amounts):
 ...     print('Check %d is for $%.2f' % (checknum, amount))
 ...
 Check 1200 is for $120.15
@@ -835,7 +1163,7 @@
 Check 1202 is for $823.14
 
 >>> import operator
->>> for cube in imap(operator.pow, range(1,4), repeat(3)):
+>>> for cube in map(operator.pow, range(1,4), repeat(3)):
 ...    print(cube)
 ...
 1
@@ -880,14 +1208,14 @@
 ...     return list(islice(seq, n))
 
 >>> def enumerate(iterable):
-...     return izip(count(), iterable)
+...     return zip(count(), iterable)
 
 >>> def tabulate(function):
 ...     "Return function(0), function(1), ..."
-...     return imap(function, count())
+...     return map(function, count())
 
 >>> def iteritems(mapping):
-...     return izip(mapping.keys(), mapping.values())
+...     return zip(mapping.keys(), mapping.values())
 
 >>> def nth(iterable, n):
 ...     "Returns the nth item"
@@ -895,25 +1223,25 @@
 
 >>> def all(seq, pred=None):
 ...     "Returns True if pred(x) is true for every element in the iterable"
-...     for elem in ifilterfalse(pred, seq):
+...     for elem in filterfalse(pred, seq):
 ...         return False
 ...     return True
 
 >>> def any(seq, pred=None):
 ...     "Returns True if pred(x) is true for at least one element in the iterable"
-...     for elem in ifilter(pred, seq):
+...     for elem in filter(pred, seq):
 ...         return True
 ...     return False
 
 >>> def no(seq, pred=None):
 ...     "Returns True if pred(x) is false for every element in the iterable"
-...     for elem in ifilter(pred, seq):
+...     for elem in filter(pred, seq):
 ...         return False
 ...     return True
 
 >>> def quantify(seq, pred=None):
 ...     "Count how many times the predicate is true in the sequence"
-...     return sum(imap(pred, seq))
+...     return sum(map(pred, seq))
 
 >>> def padnone(seq):
 ...     "Returns the sequence elements and then returns None indefinitely"
@@ -924,10 +1252,10 @@
 ...     return chain(*repeat(seq, n))
 
 >>> def dotproduct(vec1, vec2):
-...     return sum(imap(operator.mul, vec1, vec2))
+...     return sum(map(operator.mul, vec1, vec2))
 
 >>> def flatten(listOfLists):
-...     return list(chain(*listOfLists))
+...     return list(chain.from_iterable(listOfLists))
 
 >>> def repeatfunc(func, times=None, *args):
 ...     "Repeat calls to func with specified arguments."
@@ -944,7 +1272,39 @@
 ...         next(b)
 ...     except StopIteration:
 ...         pass
-...     return izip(a, b)
+...     return zip(a, b)
+
+>>> def grouper(n, iterable, fillvalue=None):
+...     "grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
+...     args = [iter(iterable)] * n
+...     kwds = dict(fillvalue=fillvalue)
+...     return zip_longest(*args, **kwds)
+
+>>> def roundrobin(*iterables):
+...     "roundrobin('abc', 'd', 'ef') --> 'a', 'd', 'e', 'b', 'f', 'c'"
+...     # Recipe credited to George Sakkis
+...     pending = len(iterables)
+...     nexts = cycle(iter(it).__next__ for it in iterables)
+...     while pending:
+...         try:
+...             for next in nexts:
+...                 yield next()
+...         except StopIteration:
+...             pending -= 1
+...             nexts = cycle(islice(nexts, pending))
+
+>>> def powerset(iterable):
+...     "powerset('ab') --> set([]), set(['a']), set(['b']), set(['a', 'b'])"
+...     # Recipe credited to Eric Raymond
+...     pairs = [(2**i, x) for i, x in enumerate(iterable)]
+...     for n in range(2**len(pairs)):
+...         yield set(x for m, x in pairs if m&n)
+
+>>> def compress(data, selectors):
+...     "compress('abcdef', [1,0,1,0,1,1]) --> a c e f"
+...     for d, s in zip(data, selectors):
+...         if s:
+...             yield d
 
 This is not part of the examples but it tests to make sure the definitions
 perform as purported.
@@ -990,7 +1350,7 @@
 [8, 8, 8, 8, 8]
 
 >>> import random
->>> take(5, imap(int, repeatfunc(random.random)))
+>>> take(5, map(int, repeatfunc(random.random)))
 [0, 0, 0, 0, 0]
 
 >>> list(pairwise('abcd'))
@@ -1011,6 +1371,18 @@
 >>> dotproduct([1,2,3], [4,5,6])
 32
 
+>>> list(grouper(3, 'abcdefg', 'x'))
+[('a', 'b', 'c'), ('d', 'e', 'f'), ('g', 'x', 'x')]
+
+>>> list(roundrobin('abc', 'd', 'ef'))
+['a', 'd', 'e', 'b', 'f', 'c']
+
+>>> list(map(sorted, powerset('ab')))
+[[], ['a'], ['b'], ['a', 'b']]
+
+>>> list(compress('abcdef', [1,0,1,0,1,1]))
+['a', 'c', 'e', 'f']
+
 """
 
 __test__ = {'libreftest' : libreftest}
@@ -1018,7 +1390,7 @@
 def test_main(verbose=None):
     test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
                     RegressionTests, LengthTransparency,
-                    SubclassWithKwargsTest)
+                    SubclassWithKwargsTest, TestExamples)
     test_support.run_unittest(*test_classes)
 
     # verify reference counting

Modified: python/branches/py3k-importlib/Lib/test/test_keywordonlyarg.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_keywordonlyarg.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_keywordonlyarg.py	Thu Mar 27 00:48:05 2008
@@ -48,6 +48,7 @@
         self.assertRaisesSyntaxError("def f(p1, *, p1=100):\n  pass\n")
         self.assertRaisesSyntaxError("def f(p1, *k1, k1=100):\n  pass\n")
         self.assertRaisesSyntaxError("def f(p1, *, k1, k1=100):\n  pass\n")
+        self.assertRaisesSyntaxError("def f(p1, *, **k1):\n  pass\n")
         self.assertRaisesSyntaxError("def f(p1, *, k1, **k1):\n  pass\n")
         self.assertRaisesSyntaxError("def f(p1, *, None, **k1):\n  pass\n")
         self.assertRaisesSyntaxError("def f(p, *, (k1, k2), **kw):\n  pass\n")
@@ -144,6 +145,15 @@
         except TypeError:
             pass
 
+    def test_kwonly_methods(self):
+        class Example:
+            def f(self, *, k1=1, k2=2):
+                return k1, k2
+
+        self.assertEqual(Example().f(k1=1, k2=2), (1, 2))
+        self.assertEqual(Example.f(Example(), k1=1, k2=2), (1, 2))
+        self.assertRaises(TypeError, Example.f, k1=1, k2=2)
+
 def test_main():
     run_unittest(KeywordOnlyArgTestCase)
 

Modified: python/branches/py3k-importlib/Lib/test/test_largefile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_largefile.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_largefile.py	Thu Mar 27 00:48:05 2008
@@ -1,12 +1,12 @@
-#!python
+"""Test largefile support on system where this makes sense.
+"""
 
-#----------------------------------------------------------------------
-# test largefile support on system where this makes sense
-#
-#----------------------------------------------------------------------
-
-from test import test_support
-import os, struct, stat, sys
+import os
+import stat
+import sys
+import unittest
+from test.test_support import run_unittest, TESTFN, verbose, requires, \
+                              TestSkipped, unlink
 
 try:
     import signal
@@ -17,154 +17,158 @@
 except (ImportError, AttributeError):
     pass
 
-
 # create >2GB file (2GB = 2147483648 bytes)
 size = 2500000000
-name = test_support.TESTFN
 
 
-# On Windows and Mac OSX this test comsumes large resources; It takes
-# a long time to build the >2GB file and takes >2GB of disk space
-# therefore the resource must be enabled to run this test.  If not,
-# nothing after this line stanza will be executed.
-if sys.platform[:3] == 'win' or sys.platform == 'darwin':
-    test_support.requires(
-        'largefile',
-        'test requires %s bytes and a long time to run' % str(size))
-else:
-    # Only run if the current filesystem supports large files.
-    # (Skip this test on Windows, since we now always support large files.)
-    f = open(test_support.TESTFN, 'wb')
-    try:
-        # 2**31 == 2147483648
-        f.seek(2147483649)
-        # Seeking is not enough of a test: you must write and flush, too!
-        f.write(b"x")
-        f.flush()
-    except (IOError, OverflowError):
-        f.close()
-        os.unlink(test_support.TESTFN)
-        raise test_support.TestSkipped(
-                                "filesystem does not have largefile support")
+class TestCase(unittest.TestCase):
+    """Test that each file function works as expected for a large
+    (i.e. > 2GB, do  we have to check > 4GB) files.
+
+    NOTE: the order of execution of the test methods is important! test_seek
+    must run first to create the test file. File cleanup must also be handled
+    outside the test instances because of this.
+
+    """
+
+    def test_seek(self):
+        if verbose:
+            print('create large file via seek (may be sparse file) ...')
+        with open(TESTFN, 'wb') as f:
+            f.write(b'z')
+            f.seek(0)
+            f.seek(size)
+            f.write(b'a')
+            f.flush()
+            if verbose:
+                print('check file size with os.fstat')
+            self.assertEqual(os.fstat(f.fileno())[stat.ST_SIZE], size+1)
+
+    def test_osstat(self):
+        if verbose:
+            print('check file size with os.stat')
+        self.assertEqual(os.stat(TESTFN)[stat.ST_SIZE], size+1)
+
+    def test_seek_read(self):
+        if verbose:
+            print('play around with seek() and read() with the built largefile')
+        with open(TESTFN, 'rb') as f:
+            self.assertEqual(f.tell(), 0)
+            self.assertEqual(f.read(1), b'z')
+            self.assertEqual(f.tell(), 1)
+            f.seek(0)
+            self.assertEqual(f.tell(), 0)
+            f.seek(0, 0)
+            self.assertEqual(f.tell(), 0)
+            f.seek(42)
+            self.assertEqual(f.tell(), 42)
+            f.seek(42, 0)
+            self.assertEqual(f.tell(), 42)
+            f.seek(42, 1)
+            self.assertEqual(f.tell(), 84)
+            f.seek(0, 1)
+            self.assertEqual(f.tell(), 84)
+            f.seek(0, 2)  # seek from the end
+            self.assertEqual(f.tell(), size + 1 + 0)
+            f.seek(-10, 2)
+            self.assertEqual(f.tell(), size + 1 - 10)
+            f.seek(-size-1, 2)
+            self.assertEqual(f.tell(), 0)
+            f.seek(size)
+            self.assertEqual(f.tell(), size)
+            # the 'a' that was written at the end of file above
+            self.assertEqual(f.read(1), b'a')
+            f.seek(-size-1, 1)
+            self.assertEqual(f.read(1), b'z')
+            self.assertEqual(f.tell(), 1)
+
+    def test_lseek(self):
+        if verbose:
+            print('play around with os.lseek() with the built largefile')
+        with open(TESTFN, 'rb') as f:
+            self.assertEqual(os.lseek(f.fileno(), 0, 0), 0)
+            self.assertEqual(os.lseek(f.fileno(), 42, 0), 42)
+            self.assertEqual(os.lseek(f.fileno(), 42, 1), 84)
+            self.assertEqual(os.lseek(f.fileno(), 0, 1), 84)
+            self.assertEqual(os.lseek(f.fileno(), 0, 2), size+1+0)
+            self.assertEqual(os.lseek(f.fileno(), -10, 2), size+1-10)
+            self.assertEqual(os.lseek(f.fileno(), -size-1, 2), 0)
+            self.assertEqual(os.lseek(f.fileno(), size, 0), size)
+            # the 'a' that was written at the end of file above
+            self.assertEqual(f.read(1), b'a')
+
+    def test_truncate(self):
+        if verbose:
+            print('try truncate')
+        with open(TESTFN, 'r+b') as f:
+            # this is already decided before start running the test suite
+            # but we do it anyway for extra protection
+            if not hasattr(f, 'truncate'):
+                raise TestSkipped("open().truncate() not available on this system")
+            f.seek(0, 2)
+            # else we've lost track of the true size
+            self.assertEqual(f.tell(), size+1)
+            # Cut it back via seek + truncate with no argument.
+            newsize = size - 10
+            f.seek(newsize)
+            f.truncate()
+            self.assertEqual(f.tell(), newsize)  # else pointer moved
+            f.seek(0, 2)
+            self.assertEqual(f.tell(), newsize)  # else wasn't truncated
+            # Ensure that truncate(smaller than true size) shrinks
+            # the file.
+            newsize -= 1
+            f.seek(42)
+            f.truncate(newsize)
+            self.assertEqual(f.tell(), 42)       # else pointer moved
+            f.seek(0, 2)
+            self.assertEqual(f.tell(), newsize)  # else wasn't truncated
+            # XXX truncate(larger than true size) is ill-defined
+            # across platform; cut it waaaaay back
+            f.seek(0)
+            f.truncate(1)
+            self.assertEqual(f.tell(), 0)       # else pointer moved
+            self.assertEqual(len(f.read()), 1)  # else wasn't truncated
+
+def test_main():
+    # On Windows and Mac OSX this test comsumes large resources; It
+    # takes a long time to build the >2GB file and takes >2GB of disk
+    # space therefore the resource must be enabled to run this test.
+    # If not, nothing after this line stanza will be executed.
+    if sys.platform[:3] == 'win' or sys.platform == 'darwin':
+        requires('largefile',
+                 'test requires %s bytes and a long time to run' % str(size))
     else:
-        f.close()
-
-
-def expect(got_this, expect_this):
-    if test_support.verbose:
-        print('%r =?= %r ...' % (got_this, expect_this), end=' ')
-    if got_this != expect_this:
-        if test_support.verbose:
-            print('no')
-        raise test_support.TestFailed('got %r, but expected %r'
-                                      % (got_this, expect_this))
-    else:
-        if test_support.verbose:
-            print('yes')
-
-
-# test that each file function works as expected for a large (i.e. >2GB, do
-# we have to check >4GB) files
-
-if test_support.verbose:
-    print('create large file via seek (may be sparse file) ...')
-f = open(name, 'wb')
-try:
-    f.write(b'z')
-    f.seek(0)
-    f.seek(size)
-    f.write(b'a')
-    f.flush()
-    if test_support.verbose:
-        print('check file size with os.fstat')
-    expect(os.fstat(f.fileno())[stat.ST_SIZE], size+1)
-finally:
-    f.close()
-if test_support.verbose:
-    print('check file size with os.stat')
-expect(os.stat(name)[stat.ST_SIZE], size+1)
-
-if test_support.verbose:
-    print('play around with seek() and read() with the built largefile')
-f = open(name, 'rb')
-try:
-    expect(f.tell(), 0)
-    expect(f.read(1), b'z')
-    expect(f.tell(), 1)
-    f.seek(0)
-    expect(f.tell(), 0)
-    f.seek(0, 0)
-    expect(f.tell(), 0)
-    f.seek(42)
-    expect(f.tell(), 42)
-    f.seek(42, 0)
-    expect(f.tell(), 42)
-    f.seek(42, 1)
-    expect(f.tell(), 84)
-    f.seek(0, 1)
-    expect(f.tell(), 84)
-    f.seek(0, 2) # seek from the end
-    expect(f.tell(), size + 1 + 0)
-    f.seek(-10, 2)
-    expect(f.tell(), size + 1 - 10)
-    f.seek(-size-1, 2)
-    expect(f.tell(), 0)
-    f.seek(size)
-    expect(f.tell(), size)
-    expect(f.read(1), b'a') # the 'a' that was written at the end of file above
-    f.seek(-size-1, 1)
-    expect(f.read(1), b'z')
-    expect(f.tell(), 1)
-finally:
-    f.close()
-
-if test_support.verbose:
-    print('play around with os.lseek() with the built largefile')
-f = open(name, 'rb')
-try:
-    expect(os.lseek(f.fileno(), 0, 0), 0)
-    expect(os.lseek(f.fileno(), 42, 0), 42)
-    expect(os.lseek(f.fileno(), 42, 1), 84)
-    expect(os.lseek(f.fileno(), 0, 1), 84)
-    expect(os.lseek(f.fileno(), 0, 2), size+1+0)
-    expect(os.lseek(f.fileno(), -10, 2), size+1-10)
-    expect(os.lseek(f.fileno(), -size-1, 2), 0)
-    expect(os.lseek(f.fileno(), size, 0), size)
-    expect(f.read(1), b'a') # the 'a' that was written at the end of file above
-finally:
-    f.close()
-
-if hasattr(f, 'truncate'):
-    if test_support.verbose:
-        print('try truncate')
-    f = open(name, 'r+b')
+        # Only run if the current filesystem supports large files.
+        # (Skip this test on Windows, since we now always support
+        # large files.)
+        f = open(TESTFN, 'wb')
+        try:
+            # 2**31 == 2147483648
+            f.seek(2147483649)
+            # Seeking is not enough of a test: you must write and
+            # flush, too!
+            f.write(b'x')
+            f.flush()
+        except (IOError, OverflowError):
+            f.close()
+            unlink(TESTFN)
+            raise TestSkipped("filesystem does not have largefile support")
+        else:
+            f.close()
+    suite = unittest.TestSuite()
+    suite.addTest(TestCase('test_seek'))
+    suite.addTest(TestCase('test_osstat'))
+    suite.addTest(TestCase('test_seek_read'))
+    suite.addTest(TestCase('test_lseek'))
+    with open(TESTFN, 'w') as f:
+        if hasattr(f, 'truncate'):
+            suite.addTest(TestCase('test_truncate'))
+    unlink(TESTFN)
     try:
-        f.seek(0, 2)
-        expect(f.tell(), size+1)    # else we've lost track of the true size
-        # Cut it back via seek + truncate with no argument.
-        newsize = size - 10
-        f.seek(newsize)
-        f.truncate()
-        expect(f.tell(), newsize)   # else pointer moved
-        f.seek(0, 2)
-        expect(f.tell(), newsize)   # else wasn't truncated
-        # Ensure that truncate(smaller than true size) shrinks the file.
-        newsize -= 1
-        f.seek(42)
-        f.truncate(newsize)
-        expect(f.tell(), 42)        # else pointer moved
-        f.seek(0, 2)
-        expect(f.tell(), newsize)   # else wasn't truncated
-
-        # XXX truncate(larger than true size) is ill-defined across platforms
-
-        # cut it waaaaay back
-        f.seek(0)
-        f.truncate(1)
-        expect(f.tell(), 0)         # else pointer moved
-        expect(len(f.read()), 1)    # else wasn't truncated
-
+        run_unittest(suite)
     finally:
-        f.close()
+        unlink(TESTFN)
 
-os.unlink(name)
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_list.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_list.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_list.py	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,4 @@
-import unittest
+import sys
 from test import test_support, list_tests
 
 class ListTest(list_tests.CommonTest):
@@ -18,6 +18,14 @@
         self.assertEqual(len([0]), 1)
         self.assertEqual(len([0, 1, 2]), 3)
 
+    def test_overflow(self):
+        lst = [4, 5, 6, 7]
+        n = int((sys.maxsize*2+2) // len(lst))
+        def mul(a, b): return a * b
+        def imul(a, b): a *= b
+        self.assertRaises((MemoryError, OverflowError), mul, lst, n)
+        self.assertRaises((MemoryError, OverflowError), imul, lst, n)
+
 def test_main(verbose=None):
     test_support.run_unittest(ListTest)
 

Modified: python/branches/py3k-importlib/Lib/test/test_locale.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_locale.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_locale.py	Thu Mar 27 00:48:05 2008
@@ -78,42 +78,3 @@
 
 finally:
     locale.setlocale(locale.LC_NUMERIC, oldlocale)
-
-
-# Test BSD Rune locale's bug for isctype functions.
-def teststrop(s, method, output):
-    s = str8(s)
-    if verbose:
-        print("%s.%s() =? %s ..." % (repr(s), method, repr(output)), end=' ')
-    result = getattr(s, method)()
-    if result != output:
-        if verbose:
-            print("no")
-        print("%s.%s() == %s != %s" % (repr(s), method, repr(result),
-                                       repr(output)))
-    elif verbose:
-        print("yes")
-
-try:
-    if sys.platform == 'sunos5':
-        # On Solaris, in en_US.UTF-8, \xa0 is a space
-        raise locale.Error
-    oldlocale = locale.setlocale(locale.LC_CTYPE)
-    locale.setlocale(locale.LC_CTYPE, 'en_US.UTF-8')
-except locale.Error:
-    pass
-else:
-    try:
-        teststrop('\x20', 'isspace', True)
-        teststrop('\xa0', 'isspace', False)
-        teststrop('\xa1', 'isspace', False)
-        teststrop('\xc0', 'isalpha', False)
-        teststrop('\xc0', 'isalnum', False)
-        teststrop('\xc0', 'isupper', False)
-        teststrop('\xc0', 'islower', False)
-        teststrop('\xec\xa0\xbc', 'split', ['\xec\xa0\xbc'])
-        teststrop('\xed\x95\xa0', 'strip', '\xed\x95\xa0')
-        teststrop('\xcc\x85', 'lower', '\xcc\x85')
-        teststrop('\xed\x95\xa0', 'upper', '\xed\x95\xa0')
-    finally:
-        locale.setlocale(locale.LC_CTYPE, oldlocale)

Modified: python/branches/py3k-importlib/Lib/test/test_logging.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_logging.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_logging.py	Thu Mar 27 00:48:05 2008
@@ -15,193 +15,281 @@
 # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
 # IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-#
-# This file is part of the Python logging distribution. See
-# http://www.red-dove.com/python_logging.html
-#
+
 """Test harness for the logging module. Run all tests.
 
 Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
 """
 
+import logging
+import logging.handlers
+import logging.config
+
+import copy
+import pickle
+import io
+import gc
+import os
+import re
 import select
-import os, sys, struct, pickle, io
-import socket, tempfile, threading, time
-import logging, logging.handlers, logging.config
-from test.test_support import run_with_locale
-
-BANNER = "-- %-10s %-6s ---------------------------------------------------\n"
-
-FINISH_UP = "Finish up, it's closing time. Messages should bear numbers 0 through 24."
-
-#----------------------------------------------------------------------------
-# Log receiver
-#----------------------------------------------------------------------------
-
-TIMEOUT         = 10
-
+import socket
 from SocketServer import ThreadingTCPServer, StreamRequestHandler
+import string
+import struct
+import sys
+import tempfile
+from test.test_support import captured_stdout, run_with_locale, run_unittest
+import textwrap
+import threading
+import time
+import types
+import unittest
+import weakref
+
+
+class BaseTest(unittest.TestCase):
+
+    """Base class for logging tests."""
+
+    log_format = "%(name)s -> %(levelname)s: %(message)s"
+    expected_log_pat = r"^([\w.]+) -> ([\w]+): ([\d]+)$"
+    message_num = 0
+
+    def setUp(self):
+        """Setup the default logging stream to an internal StringIO instance,
+        so that we can examine log output as we want."""
+        logger_dict = logging.getLogger().manager.loggerDict
+        logging._acquireLock()
+        try:
+            self.saved_handlers = logging._handlers.copy()
+            self.saved_handler_list = logging._handlerList[:]
+            self.saved_loggers = logger_dict.copy()
+            self.saved_level_names = logging._levelNames.copy()
+        finally:
+            logging._releaseLock()
 
-class LogRecordStreamHandler(StreamRequestHandler):
-    """
-    Handler for a streaming logging request. It basically logs the record
-    using whatever logging policy is configured locally.
-    """
-
-    def handle(self):
-        """
-        Handle multiple requests - each expected to be a 4-byte length,
-        followed by the LogRecord in pickle format. Logs the record
-        according to whatever policy is configured locally.
-        """
-        while 1:
-            try:
-                chunk = self.connection.recv(4)
-                if len(chunk) < 4:
-                    break
-                slen = struct.unpack(">L", chunk)[0]
-                chunk = self.connection.recv(slen)
-                while len(chunk) < slen:
-                    chunk = chunk + self.connection.recv(slen - len(chunk))
-                obj = self.unPickle(chunk)
-                record = logging.makeLogRecord(obj)
-                self.handleLogRecord(record)
-            except:
-                raise
-
-    def unPickle(self, data):
-        return pickle.loads(data)
-
-    def handleLogRecord(self, record):
-        logname = "logrecv.tcp." + record.name
-        #If the end-of-messages sentinel is seen, tell the server to terminate
-        if record.msg == FINISH_UP:
-            self.server.abort = 1
-        record.msg = record.msg + " (via " + logname + ")"
-        logger = logging.getLogger(logname)
-        logger.handle(record)
-
-# The server sets socketDataProcessed when it's done.
-socketDataProcessed = threading.Event()
-
-class LogRecordSocketReceiver(ThreadingTCPServer):
-    """
-    A simple-minded TCP socket-based logging receiver suitable for test
-    purposes.
-    """
-
-    allow_reuse_address = 1
+        self.root_logger = logging.getLogger("")
+        self.original_logging_level = self.root_logger.getEffectiveLevel()
 
-    def __init__(self, host='localhost',
-                             port=logging.handlers.DEFAULT_TCP_LOGGING_PORT,
-                     handler=LogRecordStreamHandler):
-        ThreadingTCPServer.__init__(self, (host, port), handler)
-        self.abort = 0
-        self.timeout = 1
+        self.stream = io.StringIO()
+        self.root_logger.setLevel(logging.DEBUG)
+        self.root_hdlr = logging.StreamHandler(self.stream)
+        self.root_formatter = logging.Formatter(self.log_format)
+        self.root_hdlr.setFormatter(self.root_formatter)
+        self.root_logger.addHandler(self.root_hdlr)
+
+    def tearDown(self):
+        """Remove our logging stream, and restore the original logging
+        level."""
+        self.stream.close()
+        self.root_logger.removeHandler(self.root_hdlr)
+        self.root_logger.setLevel(self.original_logging_level)
+        logging._acquireLock()
+        try:
+            logging._levelNames.clear()
+            logging._levelNames.update(self.saved_level_names)
+            logging._handlers.clear()
+            logging._handlers.update(self.saved_handlers)
+            logging._handlerList[:] = self.saved_handler_list
+            loggerDict = logging.getLogger().manager.loggerDict
+            loggerDict.clear()
+            loggerDict.update(self.saved_loggers)
+        finally:
+            logging._releaseLock()
 
-    def serve_until_stopped(self):
-        while not self.abort:
-            rd, wr, ex = select.select([self.socket.fileno()], [], [],
-                                       self.timeout)
-            if rd:
-                self.handle_request()
-        #notify the main thread that we're about to exit
-        socketDataProcessed.set()
-        # close the listen socket
-        self.server_close()
+    def assert_log_lines(self, expected_values, stream=None):
+        """Match the collected log lines against the regular expression
+        self.expected_log_pat, and compare the extracted group values to
+        the expected_values list of tuples."""
+        stream = stream or self.stream
+        pat = re.compile(self.expected_log_pat)
+        try:
+            stream.reset()
+            actual_lines = stream.readlines()
+        except AttributeError:
+            # StringIO.StringIO lacks a reset() method.
+            actual_lines = stream.getvalue().splitlines()
+        self.assertEquals(len(actual_lines), len(expected_values))
+        for actual, expected in zip(actual_lines, expected_values):
+            match = pat.search(actual)
+            if not match:
+                self.fail("Log line does not match expected pattern:\n" +
+                            actual)
+            self.assertEquals(tuple(match.groups()), expected)
+        s = stream.read()
+        if s:
+            self.fail("Remaining output at end of log stream:\n" + s)
+
+    def next_message(self):
+        """Generate a message consisting solely of an auto-incrementing
+        integer."""
+        self.message_num += 1
+        return "%d" % self.message_num
+
+
+class BuiltinLevelsTest(BaseTest):
+    """Test builtin levels and their inheritance."""
+
+    def test_flat(self):
+        #Logging levels in a flat logger namespace.
+        m = self.next_message
+
+        ERR = logging.getLogger("ERR")
+        ERR.setLevel(logging.ERROR)
+        INF = logging.getLogger("INF")
+        INF.setLevel(logging.INFO)
+        DEB = logging.getLogger("DEB")
+        DEB.setLevel(logging.DEBUG)
+
+        # These should log.
+        ERR.log(logging.CRITICAL, m())
+        ERR.error(m())
+
+        INF.log(logging.CRITICAL, m())
+        INF.error(m())
+        INF.warn(m())
+        INF.info(m())
+
+        DEB.log(logging.CRITICAL, m())
+        DEB.error(m())
+        DEB.warn (m())
+        DEB.info (m())
+        DEB.debug(m())
+
+        # These should not log.
+        ERR.warn(m())
+        ERR.info(m())
+        ERR.debug(m())
+
+        INF.debug(m())
+
+        self.assert_log_lines([
+            ('ERR', 'CRITICAL', '1'),
+            ('ERR', 'ERROR', '2'),
+            ('INF', 'CRITICAL', '3'),
+            ('INF', 'ERROR', '4'),
+            ('INF', 'WARNING', '5'),
+            ('INF', 'INFO', '6'),
+            ('DEB', 'CRITICAL', '7'),
+            ('DEB', 'ERROR', '8'),
+            ('DEB', 'WARNING', '9'),
+            ('DEB', 'INFO', '10'),
+            ('DEB', 'DEBUG', '11'),
+        ])
+
+    def test_nested_explicit(self):
+        # Logging levels in a nested namespace, all explicitly set.
+        m = self.next_message
+
+        INF = logging.getLogger("INF")
+        INF.setLevel(logging.INFO)
+        INF_ERR  = logging.getLogger("INF.ERR")
+        INF_ERR.setLevel(logging.ERROR)
+
+        # These should log.
+        INF_ERR.log(logging.CRITICAL, m())
+        INF_ERR.error(m())
+
+        # These should not log.
+        INF_ERR.warn(m())
+        INF_ERR.info(m())
+        INF_ERR.debug(m())
+
+        self.assert_log_lines([
+            ('INF.ERR', 'CRITICAL', '1'),
+            ('INF.ERR', 'ERROR', '2'),
+        ])
+
+    def test_nested_inherited(self):
+        #Logging levels in a nested namespace, inherited from parent loggers.
+        m = self.next_message
+
+        INF = logging.getLogger("INF")
+        INF.setLevel(logging.INFO)
+        INF_ERR  = logging.getLogger("INF.ERR")
+        INF_ERR.setLevel(logging.ERROR)
+        INF_UNDEF = logging.getLogger("INF.UNDEF")
+        INF_ERR_UNDEF = logging.getLogger("INF.ERR.UNDEF")
+        UNDEF = logging.getLogger("UNDEF")
+
+        # These should log.
+        INF_UNDEF.log(logging.CRITICAL, m())
+        INF_UNDEF.error(m())
+        INF_UNDEF.warn(m())
+        INF_UNDEF.info(m())
+        INF_ERR_UNDEF.log(logging.CRITICAL, m())
+        INF_ERR_UNDEF.error(m())
+
+        # These should not log.
+        INF_UNDEF.debug(m())
+        INF_ERR_UNDEF.warn(m())
+        INF_ERR_UNDEF.info(m())
+        INF_ERR_UNDEF.debug(m())
+
+        self.assert_log_lines([
+            ('INF.UNDEF', 'CRITICAL', '1'),
+            ('INF.UNDEF', 'ERROR', '2'),
+            ('INF.UNDEF', 'WARNING', '3'),
+            ('INF.UNDEF', 'INFO', '4'),
+            ('INF.ERR.UNDEF', 'CRITICAL', '5'),
+            ('INF.ERR.UNDEF', 'ERROR', '6'),
+        ])
+
+    def test_nested_with_virtual_parent(self):
+        # Logging levels when some parent does not exist yet.
+        m = self.next_message
+
+        INF = logging.getLogger("INF")
+        GRANDCHILD = logging.getLogger("INF.BADPARENT.UNDEF")
+        CHILD = logging.getLogger("INF.BADPARENT")
+        INF.setLevel(logging.INFO)
+
+        # These should log.
+        GRANDCHILD.log(logging.FATAL, m())
+        GRANDCHILD.info(m())
+        CHILD.log(logging.FATAL, m())
+        CHILD.info(m())
+
+        # These should not log.
+        GRANDCHILD.debug(m())
+        CHILD.debug(m())
+
+        self.assert_log_lines([
+            ('INF.BADPARENT.UNDEF', 'CRITICAL', '1'),
+            ('INF.BADPARENT.UNDEF', 'INFO', '2'),
+            ('INF.BADPARENT', 'CRITICAL', '3'),
+            ('INF.BADPARENT', 'INFO', '4'),
+        ])
+
+
+class BasicFilterTest(BaseTest):
+
+    """Test the bundled Filter class."""
+
+    def test_filter(self):
+        # Only messages satisfying the specified criteria pass through the
+        #  filter.
+        filter_ = logging.Filter("spam.eggs")
+        handler = self.root_logger.handlers[0]
+        try:
+            handler.addFilter(filter_)
+            spam = logging.getLogger("spam")
+            spam_eggs = logging.getLogger("spam.eggs")
+            spam_eggs_fish = logging.getLogger("spam.eggs.fish")
+            spam_bakedbeans = logging.getLogger("spam.bakedbeans")
+
+            spam.info(self.next_message())
+            spam_eggs.info(self.next_message())  # Good.
+            spam_eggs_fish.info(self.next_message())  # Good.
+            spam_bakedbeans.info(self.next_message())
+
+            self.assert_log_lines([
+                ('spam.eggs', 'INFO', '2'),
+                ('spam.eggs.fish', 'INFO', '3'),
+            ])
+        finally:
+            handler.removeFilter(filter_)
 
-    def process_request(self, request, client_address):
-        #import threading
-        t = threading.Thread(target = self.finish_request,
-                             args = (request, client_address))
-        t.start()
-
-def runTCP(tcpserver):
-    tcpserver.serve_until_stopped()
-
-#----------------------------------------------------------------------------
-# Test 0
-#----------------------------------------------------------------------------
-
-msgcount = 0
-
-def nextmessage():
-    global msgcount
-    rv = "Message %d" % msgcount
-    msgcount = msgcount + 1
-    return rv
-
-def test0():
-    ERR = logging.getLogger("ERR")
-    ERR.setLevel(logging.ERROR)
-    INF = logging.getLogger("INF")
-    INF.setLevel(logging.INFO)
-    INF_ERR  = logging.getLogger("INF.ERR")
-    INF_ERR.setLevel(logging.ERROR)
-    DEB = logging.getLogger("DEB")
-    DEB.setLevel(logging.DEBUG)
-
-    INF_UNDEF = logging.getLogger("INF.UNDEF")
-    INF_ERR_UNDEF = logging.getLogger("INF.ERR.UNDEF")
-    UNDEF = logging.getLogger("UNDEF")
-
-    GRANDCHILD = logging.getLogger("INF.BADPARENT.UNDEF")
-    CHILD = logging.getLogger("INF.BADPARENT")
-
-    #These should log
-    ERR.log(logging.FATAL, nextmessage())
-    ERR.error(nextmessage())
-
-    INF.log(logging.FATAL, nextmessage())
-    INF.error(nextmessage())
-    INF.warn(nextmessage())
-    INF.info(nextmessage())
-
-    INF_UNDEF.log(logging.FATAL, nextmessage())
-    INF_UNDEF.error(nextmessage())
-    INF_UNDEF.warn (nextmessage())
-    INF_UNDEF.info (nextmessage())
-
-    INF_ERR.log(logging.FATAL, nextmessage())
-    INF_ERR.error(nextmessage())
-
-    INF_ERR_UNDEF.log(logging.FATAL, nextmessage())
-    INF_ERR_UNDEF.error(nextmessage())
-
-    DEB.log(logging.FATAL, nextmessage())
-    DEB.error(nextmessage())
-    DEB.warn (nextmessage())
-    DEB.info (nextmessage())
-    DEB.debug(nextmessage())
-
-    UNDEF.log(logging.FATAL, nextmessage())
-    UNDEF.error(nextmessage())
-    UNDEF.warn (nextmessage())
-    UNDEF.info (nextmessage())
-
-    GRANDCHILD.log(logging.FATAL, nextmessage())
-    CHILD.log(logging.FATAL, nextmessage())
-
-    #These should not log
-    ERR.warn(nextmessage())
-    ERR.info(nextmessage())
-    ERR.debug(nextmessage())
-
-    INF.debug(nextmessage())
-    INF_UNDEF.debug(nextmessage())
-
-    INF_ERR.warn(nextmessage())
-    INF_ERR.info(nextmessage())
-    INF_ERR.debug(nextmessage())
-    INF_ERR_UNDEF.warn(nextmessage())
-    INF_ERR_UNDEF.info(nextmessage())
-    INF_ERR_UNDEF.debug(nextmessage())
-
-    INF.info(FINISH_UP)
-
-#----------------------------------------------------------------------------
-# Test 1
-#----------------------------------------------------------------------------
 
 #
 #   First, we define our levels. There can be as many as you want - the only
@@ -211,16 +299,16 @@
 #   mapping dictionary to convert between your application levels and the
 #   logging system.
 #
-SILENT      = 10
-TACITURN    = 9
-TERSE       = 8
-EFFUSIVE    = 7
-SOCIABLE    = 6
-VERBOSE     = 5
-TALKATIVE   = 4
-GARRULOUS   = 3
-CHATTERBOX  = 2
-BORING      = 1
+SILENT      = 120
+TACITURN    = 119
+TERSE       = 118
+EFFUSIVE    = 117
+SOCIABLE    = 116
+VERBOSE     = 115
+TALKATIVE   = 114
+GARRULOUS   = 113
+CHATTERBOX  = 112
+BORING      = 111
 
 LEVEL_RANGE = range(BORING, SILENT + 1)
 
@@ -241,444 +329,494 @@
     BORING      : 'Boring',
 }
 
-#
-#   Now, to demonstrate filtering: suppose for some perverse reason we only
-#   want to print out all except GARRULOUS messages. Let's create a filter for
-#   this purpose...
-#
-class SpecificLevelFilter(logging.Filter):
-    def __init__(self, lvl):
-        self.level = lvl
+class GarrulousFilter(logging.Filter):
 
-    def filter(self, record):
-        return self.level != record.levelno
+    """A filter which blocks garrulous messages."""
 
-class GarrulousFilter(SpecificLevelFilter):
-    def __init__(self):
-        SpecificLevelFilter.__init__(self, GARRULOUS)
+    def filter(self, record):
+        return record.levelno != GARRULOUS
 
-#
-#   Now, let's demonstrate filtering at the logger. This time, use a filter
-#   which excludes SOCIABLE and TACITURN messages. Note that GARRULOUS events
-#   are still excluded.
-#
 class VerySpecificFilter(logging.Filter):
+
+    """A filter which blocks sociable and taciturn messages."""
+
     def filter(self, record):
         return record.levelno not in [SOCIABLE, TACITURN]
 
-def message(s):
-    sys.stdout.write("%s\n" % s)
 
-SHOULD1 = "This should only be seen at the '%s' logging level (or lower)"
+class CustomLevelsAndFiltersTest(BaseTest):
 
-def test1():
-#
-#   Now, tell the logging system to associate names with our levels.
-#
-    for lvl in my_logging_levels.keys():
-        logging.addLevelName(lvl, my_logging_levels[lvl])
+    """Test various filtering possibilities with custom logging levels."""
 
-#
-#   Now, define a test function which logs an event at each of our levels.
-#
+    # Skip the logger name group.
+    expected_log_pat = r"^[\w.]+ -> ([\w]+): ([\d]+)$"
+
+    def setUp(self):
+        BaseTest.setUp(self)
+        for k, v in list(my_logging_levels.items()):
+            logging.addLevelName(k, v)
 
-    def doLog(log):
+    def log_at_all_levels(self, logger):
         for lvl in LEVEL_RANGE:
-            log.log(lvl, SHOULD1, logging.getLevelName(lvl))
+            logger.log(lvl, self.next_message())
 
-    log = logging.getLogger("")
-    hdlr = log.handlers[0]
-#
-#   Set the logging level to each different value and call the utility
-#   function to log events.
-#   In the output, you should see that each time round the loop, the number of
-#   logging events which are actually output decreases.
-#
-    for lvl in LEVEL_RANGE:
-        message("-- setting logging level to '%s' -----" %
-                        logging.getLevelName(lvl))
-        log.setLevel(lvl)
-        doLog(log)
-  #
-  #   Now, we demonstrate level filtering at the handler level. Tell the
-  #   handler defined above to filter at level 'SOCIABLE', and repeat the
-  #   above loop. Compare the output from the two runs.
-  #
-    hdlr.setLevel(SOCIABLE)
-    message("-- Filtering at handler level to SOCIABLE --")
-    for lvl in LEVEL_RANGE:
-        message("-- setting logging level to '%s' -----" %
-                      logging.getLevelName(lvl))
-        log.setLevel(lvl)
-        doLog(log)
-
-    hdlr.setLevel(0)    #turn off level filtering at the handler
-
-    garr = GarrulousFilter()
-    hdlr.addFilter(garr)
-    message("-- Filtering using GARRULOUS filter --")
-    for lvl in LEVEL_RANGE:
-        message("-- setting logging level to '%s' -----" %
-                        logging.getLevelName(lvl))
-        log.setLevel(lvl)
-        doLog(log)
-    spec = VerySpecificFilter()
-    log.addFilter(spec)
-    message("-- Filtering using specific filter for SOCIABLE, TACITURN --")
-    for lvl in LEVEL_RANGE:
-        message("-- setting logging level to '%s' -----" %
-                      logging.getLevelName(lvl))
-        log.setLevel(lvl)
-        doLog(log)
-
-    log.removeFilter(spec)
-    hdlr.removeFilter(garr)
-    #Undo the one level which clashes...for regression tests
-    logging.addLevelName(logging.DEBUG, "DEBUG")
-
-#----------------------------------------------------------------------------
-# Test 2
-#----------------------------------------------------------------------------
-
-MSG = "-- logging %d at INFO, messages should be seen every 10 events --"
-def test2():
-    logger = logging.getLogger("")
-    sh = logger.handlers[0]
-    sh.close()
-    logger.removeHandler(sh)
-    mh = logging.handlers.MemoryHandler(10,logging.WARNING, sh)
-    logger.setLevel(logging.DEBUG)
-    logger.addHandler(mh)
-    message("-- logging at DEBUG, nothing should be seen yet --")
-    logger.debug("Debug message")
-    message("-- logging at INFO, nothing should be seen yet --")
-    logger.info("Info message")
-    message("-- logging at WARNING, 3 messages should be seen --")
-    logger.warn("Warn message")
-    for i in range(102):
-        message(MSG % i)
-        logger.info("Info index = %d", i)
-    mh.close()
-    logger.removeHandler(mh)
-    logger.addHandler(sh)
-
-#----------------------------------------------------------------------------
-# Test 3
-#----------------------------------------------------------------------------
-
-FILTER = "a.b"
-
-def doLog3():
-    logging.getLogger("a").info("Info 1")
-    logging.getLogger("a.b").info("Info 2")
-    logging.getLogger("a.c").info("Info 3")
-    logging.getLogger("a.b.c").info("Info 4")
-    logging.getLogger("a.b.c.d").info("Info 5")
-    logging.getLogger("a.bb.c").info("Info 6")
-    logging.getLogger("b").info("Info 7")
-    logging.getLogger("b.a").info("Info 8")
-    logging.getLogger("c.a.b").info("Info 9")
-    logging.getLogger("a.bb").info("Info 10")
-
-def test3():
-    root = logging.getLogger()
-    root.setLevel(logging.DEBUG)
-    hand = root.handlers[0]
-    message("Unfiltered...")
-    doLog3()
-    message("Filtered with '%s'..." % FILTER)
-    filt = logging.Filter(FILTER)
-    hand.addFilter(filt)
-    doLog3()
-    hand.removeFilter(filt)
-
-#----------------------------------------------------------------------------
-# Test 4
-#----------------------------------------------------------------------------
-
-# config0 is a standard configuration.
-config0 = """
-[loggers]
-keys=root
-
-[handlers]
-keys=hand1
-
-[formatters]
-keys=form1
-
-[logger_root]
-level=NOTSET
-handlers=hand1
-
-[handler_hand1]
-class=StreamHandler
-level=NOTSET
-formatter=form1
-args=(sys.stdout,)
-
-[formatter_form1]
-format=%(levelname)s:%(name)s:%(message)s
-datefmt=
-"""
+    def test_logger_filter(self):
+        # Filter at logger level.
+        self.root_logger.setLevel(VERBOSE)
+        # Levels >= 'Verbose' are good.
+        self.log_at_all_levels(self.root_logger)
+        self.assert_log_lines([
+            ('Verbose', '5'),
+            ('Sociable', '6'),
+            ('Effusive', '7'),
+            ('Terse', '8'),
+            ('Taciturn', '9'),
+            ('Silent', '10'),
+        ])
+
+    def test_handler_filter(self):
+        # Filter at handler level.
+        self.root_logger.handlers[0].setLevel(SOCIABLE)
+        try:
+            # Levels >= 'Sociable' are good.
+            self.log_at_all_levels(self.root_logger)
+            self.assert_log_lines([
+                ('Sociable', '6'),
+                ('Effusive', '7'),
+                ('Terse', '8'),
+                ('Taciturn', '9'),
+                ('Silent', '10'),
+            ])
+        finally:
+            self.root_logger.handlers[0].setLevel(logging.NOTSET)
 
-# config1 adds a little to the standard configuration.
-config1 = """
-[loggers]
-keys=root,parser
-
-[handlers]
-keys=hand1
-
-[formatters]
-keys=form1
-
-[logger_root]
-level=NOTSET
-handlers=hand1
-
-[logger_parser]
-level=DEBUG
-handlers=hand1
-propagate=1
-qualname=compiler.parser
-
-[handler_hand1]
-class=StreamHandler
-level=NOTSET
-formatter=form1
-args=(sys.stdout,)
-
-[formatter_form1]
-format=%(levelname)s:%(name)s:%(message)s
-datefmt=
-"""
+    def test_specific_filters(self):
+        # Set a specific filter object on the handler, and then add another
+        #  filter object on the logger itself.
+        handler = self.root_logger.handlers[0]
+        specific_filter = None
+        garr = GarrulousFilter()
+        handler.addFilter(garr)
+        try:
+            self.log_at_all_levels(self.root_logger)
+            first_lines = [
+                # Notice how 'Garrulous' is missing
+                ('Boring', '1'),
+                ('Chatterbox', '2'),
+                ('Talkative', '4'),
+                ('Verbose', '5'),
+                ('Sociable', '6'),
+                ('Effusive', '7'),
+                ('Terse', '8'),
+                ('Taciturn', '9'),
+                ('Silent', '10'),
+            ]
+            self.assert_log_lines(first_lines)
+
+            specific_filter = VerySpecificFilter()
+            self.root_logger.addFilter(specific_filter)
+            self.log_at_all_levels(self.root_logger)
+            self.assert_log_lines(first_lines + [
+                # Not only 'Garrulous' is still missing, but also 'Sociable'
+                # and 'Taciturn'
+                ('Boring', '11'),
+                ('Chatterbox', '12'),
+                ('Talkative', '14'),
+                ('Verbose', '15'),
+                ('Effusive', '17'),
+                ('Terse', '18'),
+                ('Silent', '20'),
+        ])
+        finally:
+            if specific_filter:
+                self.root_logger.removeFilter(specific_filter)
+            handler.removeFilter(garr)
+
+
+class MemoryHandlerTest(BaseTest):
+
+    """Tests for the MemoryHandler."""
+
+    # Do not bother with a logger name group.
+    expected_log_pat = r"^[\w.]+ -> ([\w]+): ([\d]+)$"
+
+    def setUp(self):
+        BaseTest.setUp(self)
+        self.mem_hdlr = logging.handlers.MemoryHandler(10, logging.WARNING,
+                                                        self.root_hdlr)
+        self.mem_logger = logging.getLogger('mem')
+        self.mem_logger.propagate = 0
+        self.mem_logger.addHandler(self.mem_hdlr)
+
+    def tearDown(self):
+        self.mem_hdlr.close()
+
+    def test_flush(self):
+        # The memory handler flushes to its target handler based on specific
+        #  criteria (message count and message level).
+        self.mem_logger.debug(self.next_message())
+        self.assert_log_lines([])
+        self.mem_logger.info(self.next_message())
+        self.assert_log_lines([])
+        # This will flush because the level is >= logging.WARNING
+        self.mem_logger.warn(self.next_message())
+        lines = [
+            ('DEBUG', '1'),
+            ('INFO', '2'),
+            ('WARNING', '3'),
+        ]
+        self.assert_log_lines(lines)
+        for n in (4, 14):
+            for i in range(9):
+                self.mem_logger.debug(self.next_message())
+            self.assert_log_lines(lines)
+            # This will flush because it's the 10th message since the last
+            #  flush.
+            self.mem_logger.debug(self.next_message())
+            lines = lines + [('DEBUG', str(i)) for i in range(n, n + 10)]
+            self.assert_log_lines(lines)
 
-# config2 has a subtle configuration error that should be reported
-config2 = config1.replace("sys.stdout", "sys.stbout")
+        self.mem_logger.debug(self.next_message())
+        self.assert_log_lines(lines)
 
-# config3 has a less subtle configuration error
-config3 = config1.replace("formatter=form1", "formatter=misspelled_name")
 
-def test4():
-    for i in range(4):
-        conf = globals()['config%d' % i]
-        sys.stdout.write('config%d: ' % i)
-        loggerDict = logging.getLogger().manager.loggerDict
-        logging._acquireLock()
-        try:
-            saved_handlers = logging._handlers.copy()
-            saved_handler_list = logging._handlerList[:]
-            saved_loggers = loggerDict.copy()
-        finally:
-            logging._releaseLock()
+class ExceptionFormatter(logging.Formatter):
+    """A special exception formatter."""
+    def formatException(self, ei):
+        return "Got a [%s]" % ei[0].__name__
+
+
+class ConfigFileTest(BaseTest):
+
+    """Reading logging config from a .ini-style config file."""
+
+    expected_log_pat = r"^([\w]+) \+\+ ([\w]+)$"
+
+    # config0 is a standard configuration.
+    config0 = """
+    [loggers]
+    keys=root
+
+    [handlers]
+    keys=hand1
+
+    [formatters]
+    keys=form1
+
+    [logger_root]
+    level=WARNING
+    handlers=hand1
+
+    [handler_hand1]
+    class=StreamHandler
+    level=NOTSET
+    formatter=form1
+    args=(sys.stdout,)
+
+    [formatter_form1]
+    format=%(levelname)s ++ %(message)s
+    datefmt=
+    """
+
+    # config1 adds a little to the standard configuration.
+    config1 = """
+    [loggers]
+    keys=root,parser
+
+    [handlers]
+    keys=hand1
+
+    [formatters]
+    keys=form1
+
+    [logger_root]
+    level=WARNING
+    handlers=
+
+    [logger_parser]
+    level=DEBUG
+    handlers=hand1
+    propagate=1
+    qualname=compiler.parser
+
+    [handler_hand1]
+    class=StreamHandler
+    level=NOTSET
+    formatter=form1
+    args=(sys.stdout,)
+
+    [formatter_form1]
+    format=%(levelname)s ++ %(message)s
+    datefmt=
+    """
+
+    # config2 has a subtle configuration error that should be reported
+    config2 = config1.replace("sys.stdout", "sys.stbout")
+
+    # config3 has a less subtle configuration error
+    config3 = config1.replace("formatter=form1", "formatter=misspelled_name")
+
+    # config4 specifies a custom formatter class to be loaded
+    config4 = """
+    [loggers]
+    keys=root
+
+    [handlers]
+    keys=hand1
+
+    [formatters]
+    keys=form1
+
+    [logger_root]
+    level=NOTSET
+    handlers=hand1
+
+    [handler_hand1]
+    class=StreamHandler
+    level=NOTSET
+    formatter=form1
+    args=(sys.stdout,)
+
+    [formatter_form1]
+    class=""" + __name__ + """.ExceptionFormatter
+    format=%(levelname)s:%(name)s:%(message)s
+    datefmt=
+    """
+
+    def apply_config(self, conf):
         try:
             fn = tempfile.mktemp(".ini")
             f = open(fn, "w")
-            f.write(conf)
+            f.write(textwrap.dedent(conf))
             f.close()
-            try:
-                logging.config.fileConfig(fn)
-                #call again to make sure cleanup is correct
-                logging.config.fileConfig(fn)
-            except:
-                t = sys.exc_info()[0]
-                message(str(t))
-            else:
-                message('ok.')
-            os.remove(fn)
+            logging.config.fileConfig(fn)
         finally:
-            logging._acquireLock()
+            os.remove(fn)
+
+    def test_config0_ok(self):
+        # A simple config file which overrides the default settings.
+        with captured_stdout() as output:
+            self.apply_config(self.config0)
+            logger = logging.getLogger()
+            # Won't output anything
+            logger.info(self.next_message())
+            # Outputs a message
+            logger.error(self.next_message())
+            self.assert_log_lines([
+                ('ERROR', '2'),
+            ], stream=output)
+            # Original logger output is empty.
+            self.assert_log_lines([])
+
+    def test_config1_ok(self):
+        # A config file defining a sub-parser as well.
+        with captured_stdout() as output:
+            self.apply_config(self.config1)
+            logger = logging.getLogger("compiler.parser")
+            # Both will output a message
+            logger.info(self.next_message())
+            logger.error(self.next_message())
+            self.assert_log_lines([
+                ('INFO', '1'),
+                ('ERROR', '2'),
+            ], stream=output)
+            # Original logger output is empty.
+            self.assert_log_lines([])
+
+    def test_config2_failure(self):
+        # A simple config file which overrides the default settings.
+        self.assertRaises(Exception, self.apply_config, self.config2)
+
+    def test_config3_failure(self):
+        # A simple config file which overrides the default settings.
+        self.assertRaises(Exception, self.apply_config, self.config3)
+
+    def test_config4_ok(self):
+        # A config file specifying a custom formatter class.
+        with captured_stdout() as output:
+            self.apply_config(self.config4)
+            logger = logging.getLogger()
             try:
-                logging._handlers.clear()
-                logging._handlers.update(saved_handlers)
-                logging._handlerList[:] = saved_handler_list
-                loggerDict = logging.getLogger().manager.loggerDict
-                loggerDict.clear()
-                loggerDict.update(saved_loggers)
-            finally:
-                logging._releaseLock()
-
-#----------------------------------------------------------------------------
-# Test 5
-#----------------------------------------------------------------------------
-
-test5_config = """
-[loggers]
-keys=root
-
-[handlers]
-keys=hand1
-
-[formatters]
-keys=form1
-
-[logger_root]
-level=NOTSET
-handlers=hand1
-
-[handler_hand1]
-class=StreamHandler
-level=NOTSET
-formatter=form1
-args=(sys.stdout,)
-
-[formatter_form1]
-class=test.test_logging.FriendlyFormatter
-format=%(levelname)s:%(name)s:%(message)s
-datefmt=
-"""
+                raise RuntimeError()
+            except RuntimeError:
+                logging.exception("just testing")
+            sys.stdout.seek(0)
+            self.assertEquals(output.getvalue(),
+                "ERROR:root:just testing\nGot a [RuntimeError]\n")
+            # Original logger output is empty
+            self.assert_log_lines([])
 
-class FriendlyFormatter (logging.Formatter):
-    def formatException(self, ei):
-        return "%s... Don't panic!" % str(ei[0])
 
+class LogRecordStreamHandler(StreamRequestHandler):
 
-def test5():
-    loggerDict = logging.getLogger().manager.loggerDict
-    logging._acquireLock()
-    try:
-        saved_handlers = logging._handlers.copy()
-        saved_handler_list = logging._handlerList[:]
-        saved_loggers = loggerDict.copy()
-    finally:
-        logging._releaseLock()
-    try:
-        fn = tempfile.mktemp(".ini")
-        f = open(fn, "w")
-        f.write(test5_config)
-        f.close()
-        logging.config.fileConfig(fn)
-        try:
-            raise KeyError
-        except KeyError:
-            logging.exception("just testing")
-        os.remove(fn)
-        hdlr = logging.getLogger().handlers[0]
-        logging.getLogger().handlers.remove(hdlr)
-    finally:
-        logging._acquireLock()
+    """Handler for a streaming logging request. It saves the log message in the
+    TCP server's 'log_output' attribute."""
+
+    TCP_LOG_END = "!!!END!!!"
+
+    def handle(self):
+        """Handle multiple requests - each expected to be of 4-byte length,
+        followed by the LogRecord in pickle format. Logs the record
+        according to whatever policy is configured locally."""
+        while True:
+            chunk = self.connection.recv(4)
+            if len(chunk) < 4:
+                break
+            slen = struct.unpack(">L", chunk)[0]
+            chunk = self.connection.recv(slen)
+            while len(chunk) < slen:
+                chunk = chunk + self.connection.recv(slen - len(chunk))
+            obj = self.unpickle(chunk)
+            record = logging.makeLogRecord(obj)
+            self.handle_log_record(record)
+
+    def unpickle(self, data):
+        return pickle.loads(data)
+
+    def handle_log_record(self, record):
+        # If the end-of-messages sentinel is seen, tell the server to
+        #  terminate.
+        if self.TCP_LOG_END in record.msg:
+            self.server.abort = 1
+            return
+        self.server.log_output += record.msg + "\n"
+
+
+class LogRecordSocketReceiver(ThreadingTCPServer):
+
+    """A simple-minded TCP socket-based logging receiver suitable for test
+    purposes."""
+
+    allow_reuse_address = 1
+    log_output = ""
+
+    def __init__(self, host='localhost',
+                             port=logging.handlers.DEFAULT_TCP_LOGGING_PORT,
+                     handler=LogRecordStreamHandler):
+        ThreadingTCPServer.__init__(self, (host, port), handler)
+        self.abort = False
+        self.timeout = 0.1
+        self.finished = threading.Event()
+
+    def serve_until_stopped(self):
+        while not self.abort:
+            rd, wr, ex = select.select([self.socket.fileno()], [], [],
+                                       self.timeout)
+            if rd:
+                self.handle_request()
+        # Notify the main thread that we're about to exit
+        self.finished.set()
+        # close the listen socket
+        self.server_close()
+
+
+class SocketHandlerTest(BaseTest):
+
+    """Test for SocketHandler objects."""
+
+    def setUp(self):
+        """Set up a TCP server to receive log messages, and a SocketHandler
+        pointing to that server's address and port."""
+        BaseTest.setUp(self)
+        self.tcpserver = LogRecordSocketReceiver(port=0)
+        self.port = self.tcpserver.socket.getsockname()[1]
+        self.threads = [
+                threading.Thread(target=self.tcpserver.serve_until_stopped)]
+        for thread in self.threads:
+            thread.start()
+
+        self.sock_hdlr = logging.handlers.SocketHandler('localhost', self.port)
+        self.sock_hdlr.setFormatter(self.root_formatter)
+        self.root_logger.removeHandler(self.root_logger.handlers[0])
+        self.root_logger.addHandler(self.sock_hdlr)
+
+    def tearDown(self):
+        """Shutdown the TCP server."""
         try:
-            logging._handlers.clear()
-            logging._handlers.update(saved_handlers)
-            logging._handlerList[:] = saved_handler_list
-            loggerDict = logging.getLogger().manager.loggerDict
-            loggerDict.clear()
-            loggerDict.update(saved_loggers)
+            self.tcpserver.abort = True
+            del self.tcpserver
+            self.root_logger.removeHandler(self.sock_hdlr)
+            self.sock_hdlr.close()
+            for thread in self.threads:
+                thread.join(2.0)
         finally:
-            logging._releaseLock()
+            BaseTest.tearDown(self)
 
+    def get_output(self):
+        """Get the log output as received by the TCP server."""
+        # Signal the TCP receiver and wait for it to terminate.
+        self.root_logger.critical(LogRecordStreamHandler.TCP_LOG_END)
+        self.tcpserver.finished.wait(2.0)
+        return self.tcpserver.log_output
+
+    def test_output(self):
+        # The log message sent to the SocketHandler is properly received.
+        logger = logging.getLogger("tcp")
+        logger.error("spam")
+        logger.debug("eggs")
+        self.assertEquals(self.get_output(), "spam\neggs\n")
+
+
+class MemoryTest(BaseTest):
+
+    """Test memory persistence of logger objects."""
+
+    def setUp(self):
+        """Create a dict to remember potentially destroyed objects."""
+        BaseTest.setUp(self)
+        self._survivors = {}
+
+    def _watch_for_survival(self, *args):
+        """Watch the given objects for survival, by creating weakrefs to
+        them."""
+        for obj in args:
+            key = id(obj), repr(obj)
+            self._survivors[key] = weakref.ref(obj)
+
+    def _assert_survival(self):
+        """Assert that all objects watched for survival have survived."""
+        # Trigger cycle breaking.
+        gc.collect()
+        dead = []
+        for (id_, repr_), ref in list(self._survivors.items()):
+            if ref() is None:
+                dead.append(repr_)
+        if dead:
+            self.fail("%d objects should have survived "
+                "but have been destroyed: %s" % (len(dead), ", ".join(dead)))
+
+    def test_persistent_loggers(self):
+        # Logger objects are persistent and retain their configuration, even
+        #  if visible references are destroyed.
+        self.root_logger.setLevel(logging.INFO)
+        foo = logging.getLogger("foo")
+        self._watch_for_survival(foo)
+        foo.setLevel(logging.DEBUG)
+        self.root_logger.debug(self.next_message())
+        foo.debug(self.next_message())
+        self.assert_log_lines([
+            ('foo', 'DEBUG', '2'),
+        ])
+        del foo
+        # foo has survived.
+        self._assert_survival()
+        # foo has retained its settings.
+        bar = logging.getLogger("foo")
+        bar.debug(self.next_message())
+        self.assert_log_lines([
+            ('foo', 'DEBUG', '2'),
+            ('foo', 'DEBUG', '3'),
+        ])
 
-#----------------------------------------------------------------------------
-# Test Harness
-#----------------------------------------------------------------------------
-def banner(nm, typ):
-    sep = BANNER % (nm, typ)
-    sys.stdout.write(sep)
-    sys.stdout.flush()
-
-def test_main_inner():
-    rootLogger = logging.getLogger("")
-    rootLogger.setLevel(logging.DEBUG)
-    hdlr = logging.StreamHandler(sys.stdout)
-    fmt = logging.Formatter(logging.BASIC_FORMAT)
-    hdlr.setFormatter(fmt)
-    rootLogger.addHandler(hdlr)
-
-    # Find an unused port number
-    port = logging.handlers.DEFAULT_TCP_LOGGING_PORT
-    while port < logging.handlers.DEFAULT_TCP_LOGGING_PORT+100:
-        try:
-            tcpserver = LogRecordSocketReceiver(port=port)
-        except socket.error:
-            port += 1
-        else:
-            break
-    else:
-        raise ImportError("Could not find unused port")
-
-
-    #Set up a handler such that all events are sent via a socket to the log
-    #receiver (logrecv).
-    #The handler will only be added to the rootLogger for some of the tests
-    shdlr = logging.handlers.SocketHandler('localhost', port)
-
-    #Configure the logger for logrecv so events do not propagate beyond it.
-    #The sockLogger output is buffered in memory until the end of the test,
-    #and printed at the end.
-    sockOut = io.StringIO()
-    sockLogger = logging.getLogger("logrecv")
-    sockLogger.setLevel(logging.DEBUG)
-    sockhdlr = logging.StreamHandler(sockOut)
-    sockhdlr.setFormatter(logging.Formatter(
-                                   "%(name)s -> %(levelname)s: %(message)s"))
-    sockLogger.addHandler(sockhdlr)
-    sockLogger.propagate = 0
-
-    #Set up servers
-    threads = []
-    #sys.stdout.write("About to start TCP server...\n")
-    threads.append(threading.Thread(target=runTCP, args=(tcpserver,)))
-
-    for thread in threads:
-        thread.start()
-    try:
-        banner("log_test0", "begin")
-
-        rootLogger.addHandler(shdlr)
-        test0()
-        # XXX(nnorwitz): Try to fix timing related test failures.
-        # This sleep gives us some extra time to read messages.
-        # The test generally only fails on Solaris without this sleep.
-        time.sleep(2.0)
-        shdlr.close()
-        rootLogger.removeHandler(shdlr)
-
-        banner("log_test0", "end")
-
-        for t in range(1,6):
-            banner("log_test%d" % t, "begin")
-            globals()['test%d' % t]()
-            banner("log_test%d" % t, "end")
-
-    finally:
-        #wait for TCP receiver to terminate
-        socketDataProcessed.wait()
-        # ensure the server dies
-        tcpserver.abort = 1
-        for thread in threads:
-            thread.join(2.0)
-        banner("logrecv output", "begin")
-        sys.stdout.write(sockOut.getvalue())
-        sockOut.close()
-        sockLogger.removeHandler(sockhdlr)
-        sockhdlr.close()
-        banner("logrecv output", "end")
-        sys.stdout.flush()
-        try:
-            hdlr.close()
-        except:
-            pass
-        rootLogger.removeHandler(hdlr)
 
 # Set the locale to the platform-dependent default.  I have no idea
 # why the test does this, but in any case we save the current locale
 # first and restore it at the end.
 @run_with_locale('LC_ALL', '')
 def test_main():
-    # Save and restore the original root logger level across the tests.
-    # Otherwise, e.g., if any test using cookielib runs after test_logging,
-    # cookielib's debug-level logger tries to log messages, leading to
-    # confusing:
-    #    No handlers could be found for logger "cookielib"
-    # output while the tests are running.
-    root_logger = logging.getLogger("")
-    original_logging_level = root_logger.getEffectiveLevel()
-    try:
-        test_main_inner()
-    finally:
-        root_logger.setLevel(original_logging_level)
+    run_unittest(BuiltinLevelsTest, BasicFilterTest,
+                    CustomLevelsAndFiltersTest, MemoryHandlerTest,
+                    ConfigFileTest, SocketHandlerTest, MemoryTest)
 
 if __name__ == "__main__":
-    sys.stdout.write("test_logging\n")
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_long.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_long.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_long.py	Thu Mar 27 00:48:05 2008
@@ -233,48 +233,48 @@
         import sys
 
         # check the extremes in int<->long conversion
-        hugepos = sys.maxint
+        hugepos = sys.maxsize
         hugeneg = -hugepos - 1
         hugepos_aslong = int(hugepos)
         hugeneg_aslong = int(hugeneg)
-        self.assertEqual(hugepos, hugepos_aslong, "long(sys.maxint) != sys.maxint")
+        self.assertEqual(hugepos, hugepos_aslong, "long(sys.maxsize) != sys.maxsize")
         self.assertEqual(hugeneg, hugeneg_aslong,
-            "long(-sys.maxint-1) != -sys.maxint-1")
+            "long(-sys.maxsize-1) != -sys.maxsize-1")
 
         # long -> int should not fail for hugepos_aslong or hugeneg_aslong
         x = int(hugepos_aslong)
         try:
             self.assertEqual(x, hugepos,
-                  "converting sys.maxint to long and back to int fails")
+                  "converting sys.maxsize to long and back to int fails")
         except OverflowError:
-            self.fail("int(long(sys.maxint)) overflowed!")
+            self.fail("int(long(sys.maxsize)) overflowed!")
         if not isinstance(x, int):
-            raise TestFailed("int(long(sys.maxint)) should have returned int")
+            raise TestFailed("int(long(sys.maxsize)) should have returned int")
         x = int(hugeneg_aslong)
         try:
             self.assertEqual(x, hugeneg,
-                  "converting -sys.maxint-1 to long and back to int fails")
+                  "converting -sys.maxsize-1 to long and back to int fails")
         except OverflowError:
-            self.fail("int(long(-sys.maxint-1)) overflowed!")
+            self.fail("int(long(-sys.maxsize-1)) overflowed!")
         if not isinstance(x, int):
-            raise TestFailed("int(long(-sys.maxint-1)) should have "
+            raise TestFailed("int(long(-sys.maxsize-1)) should have "
                              "returned int")
         # but long -> int should overflow for hugepos+1 and hugeneg-1
         x = hugepos_aslong + 1
         try:
             y = int(x)
         except OverflowError:
-            self.fail("int(long(sys.maxint) + 1) mustn't overflow")
+            self.fail("int(long(sys.maxsize) + 1) mustn't overflow")
         self.assert_(isinstance(y, int),
-            "int(long(sys.maxint) + 1) should have returned long")
+            "int(long(sys.maxsize) + 1) should have returned long")
 
         x = hugeneg_aslong - 1
         try:
             y = int(x)
         except OverflowError:
-            self.fail("int(long(-sys.maxint-1) - 1) mustn't overflow")
+            self.fail("int(long(-sys.maxsize-1) - 1) mustn't overflow")
         self.assert_(isinstance(y, int),
-               "int(long(-sys.maxint-1) - 1) should have returned long")
+               "int(long(-sys.maxsize-1) - 1) should have returned long")
 
         class long2(int):
             pass
@@ -288,8 +288,8 @@
     def test_auto_overflow(self):
         import math, sys
 
-        special = [0, 1, 2, 3, sys.maxint-1, sys.maxint, sys.maxint+1]
-        sqrt = int(math.sqrt(sys.maxint))
+        special = [0, 1, 2, 3, sys.maxsize-1, sys.maxsize, sys.maxsize+1]
+        sqrt = int(math.sqrt(sys.maxsize))
         special.extend([sqrt-1, sqrt, sqrt+1])
         special.extend([-i for i in special])
 
@@ -462,7 +462,7 @@
         for t in 2.0**48, 2.0**50, 2.0**53:
             cases.extend([t - 1.0, t - 0.3, t, t + 0.3, t + 1.0,
                           int(t-1), int(t), int(t+1)])
-        cases.extend([0, 1, 2, sys.maxint, float(sys.maxint)])
+        cases.extend([0, 1, 2, sys.maxsize, float(sys.maxsize)])
         # 1L<<20000 should exceed all double formats.  long(1e200) is to
         # check that we get equality with 1e200 above.
         t = int(1e200)
@@ -482,7 +482,7 @@
                 eq(x > y, Rcmp > 0, Frm("%r > %r %d", x, y, Rcmp))
                 eq(x >= y, Rcmp >= 0, Frm("%r >= %r %d", x, y, Rcmp))
 
-    def test_format(self):
+    def test__format__(self):
         self.assertEqual(format(123456789, 'd'), '123456789')
         self.assertEqual(format(123456789, 'd'), '123456789')
 
@@ -526,16 +526,31 @@
         self.assertEqual(format(1234, "+b"), "+10011010010")
         self.assertEqual(format(-1234, "+b"), "-10011010010")
 
-        # conversion to float
-        self.assertEqual(format(0, 'f'), '0.000000')
-
         # make sure these are errors
         self.assertRaises(ValueError, format, 3, "1.3")  # precision disallowed
         self.assertRaises(ValueError, format, 3, "+c")   # sign not allowed
                                                          # with 'c'
-        self.assertRaises(ValueError, format, 3, "R")    # bogus format type
-        # conversion to string should fail
-        self.assertRaises(ValueError, format, 3, "s")
+
+        # ensure that only int and float type specifiers work
+        for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
+                            [chr(x) for x in range(ord('A'), ord('Z')+1)]):
+            if not format_spec in 'bcdoxXeEfFgGn%':
+                self.assertRaises(ValueError, format, 0, format_spec)
+                self.assertRaises(ValueError, format, 1, format_spec)
+                self.assertRaises(ValueError, format, -1, format_spec)
+                self.assertRaises(ValueError, format, 2**100, format_spec)
+                self.assertRaises(ValueError, format, -(2**100), format_spec)
+
+        # ensure that float type specifiers work; format converts
+        #  the int to a float
+        for format_spec in 'eEfFgGn%':
+            for value in [0, 1, -1, 100, -100, 1234567890, -1234567890]:
+                self.assertEqual(format(value, format_spec),
+                                 format(float(value), format_spec))
+
+    def test_nan_inf(self):
+        self.assertRaises(OverflowError, int, float('inf'))
+        self.assertRaises(OverflowError, int, float('nan'))
 
 def test_main():
     test_support.run_unittest(LongTest)

Modified: python/branches/py3k-importlib/Lib/test/test_mailbox.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_mailbox.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_mailbox.py	Thu Mar 27 00:48:05 2008
@@ -58,6 +58,7 @@
         self._box = self._factory(self._path)
 
     def tearDown(self):
+        self._box.close()
         self._delete_recursively(self._path)
 
     def test_add(self):
@@ -167,9 +168,11 @@
         # Get file representations of messages
         key0 = self._box.add(self._template % 0)
         key1 = self._box.add(_sample_message)
-        self.assertEqual(self._box.get_file(key0).read().replace(os.linesep, '\n'),
+        data0 = self._box.get_file(key0).read()
+        data1 = self._box.get_file(key1).read()
+        self.assertEqual(data0.replace(os.linesep, '\n'),
                          self._template % 0)
-        self.assertEqual(self._box.get_file(key1).read().replace(os.linesep, '\n'),
+        self.assertEqual(data1.replace(os.linesep, '\n'),
                          _sample_message)
 
     def test_iterkeys(self):
@@ -390,12 +393,14 @@
         self._box.add(contents[0])
         self._box.add(contents[1])
         self._box.add(contents[2])
+        oldbox = self._box
         method()
         self._box = self._factory(self._path)
         keys = self._box.keys()
         self.assertEqual(len(keys), 3)
         for key in keys:
             self.assert_(self._box.get_string(key) in contents)
+        oldbox.close()
 
     def test_dump_message(self):
         # Write message representations to disk
@@ -403,7 +408,7 @@
                       _sample_message, io.StringIO(_sample_message)):
             output = io.StringIO()
             self._box._dump_message(input, output)
-            self.assert_(output.getvalue() ==
+            self.assertEqual(output.getvalue(),
                          _sample_message.replace('\n', os.linesep))
         output = io.StringIO()
         self.assertRaises(TypeError,
@@ -501,6 +506,21 @@
         self.assertEqual(msg_returned.get_flags(), 'S')
         self.assertEqual(msg_returned.get_payload(), '3')
 
+    def test_consistent_factory(self):
+        # Add a message.
+        msg = mailbox.MaildirMessage(self._template % 0)
+        msg.set_subdir('cur')
+        msg.set_flags('RF')
+        key = self._box.add(msg)
+
+        # Create new mailbox with
+        class FakeMessage(mailbox.MaildirMessage):
+            pass
+        box = mailbox.Maildir(self._path, factory=FakeMessage)
+        box.colon = self._box.colon
+        msg2 = box.get_message(key)
+        self.assert_(isinstance(msg2, FakeMessage))
+
     def test_initialize_new(self):
         # Initialize a non-existent mailbox
         self.tearDown()
@@ -694,6 +714,7 @@
 class _TestMboxMMDF(TestMailbox):
 
     def tearDown(self):
+        self._box.close()
         self._delete_recursively(self._path)
         for lock_remnant in glob.glob(self._path + '.*'):
             test_support.unlink(lock_remnant)
@@ -916,6 +937,7 @@
     _factory = lambda self, path, factory=None: mailbox.Babyl(path, factory)
 
     def tearDown(self):
+        self._box.close()
         self._delete_recursively(self._path)
         for lock_remnant in glob.glob(self._path + '.*'):
             test_support.unlink(lock_remnant)
@@ -1483,69 +1505,73 @@
     def _test_read(self, proxy):
         # Read by byte
         proxy.seek(0)
-        self.assertEqual(proxy.read(), 'bar')
+        self.assertEqual(proxy.read(), b'bar')
         proxy.seek(1)
-        self.assertEqual(proxy.read(), 'ar')
+        self.assertEqual(proxy.read(), b'ar')
         proxy.seek(0)
-        self.assertEqual(proxy.read(2), 'ba')
+        self.assertEqual(proxy.read(2), b'ba')
         proxy.seek(1)
-        self.assertEqual(proxy.read(-1), 'ar')
+        self.assertEqual(proxy.read(-1), b'ar')
         proxy.seek(2)
-        self.assertEqual(proxy.read(1000), 'r')
+        self.assertEqual(proxy.read(1000), b'r')
 
     def _test_readline(self, proxy):
         # Read by line
+        linesep = os.linesep.encode()
         proxy.seek(0)
-        self.assertEqual(proxy.readline(), 'foo' + os.linesep)
-        self.assertEqual(proxy.readline(), 'bar' + os.linesep)
-        self.assertEqual(proxy.readline(), 'fred' + os.linesep)
-        self.assertEqual(proxy.readline(), 'bob')
+        self.assertEqual(proxy.readline(), b'foo' + linesep)
+        self.assertEqual(proxy.readline(), b'bar' + linesep)
+        self.assertEqual(proxy.readline(), b'fred' + linesep)
+        self.assertEqual(proxy.readline(), b'bob')
         proxy.seek(2)
-        self.assertEqual(proxy.readline(), 'o' + os.linesep)
+        self.assertEqual(proxy.readline(), b'o' + linesep)
         proxy.seek(6 + 2 * len(os.linesep))
-        self.assertEqual(proxy.readline(), 'fred' + os.linesep)
+        self.assertEqual(proxy.readline(), b'fred' + linesep)
         proxy.seek(6 + 2 * len(os.linesep))
-        self.assertEqual(proxy.readline(2), 'fr')
-        self.assertEqual(proxy.readline(-10), 'ed' + os.linesep)
+        self.assertEqual(proxy.readline(2), b'fr')
+        self.assertEqual(proxy.readline(-10), b'ed' + linesep)
 
     def _test_readlines(self, proxy):
         # Read multiple lines
+        linesep = os.linesep.encode()
         proxy.seek(0)
-        self.assertEqual(proxy.readlines(), ['foo' + os.linesep,
-                                           'bar' + os.linesep,
-                                           'fred' + os.linesep, 'bob'])
+        self.assertEqual(proxy.readlines(), [b'foo' + linesep,
+                                           b'bar' + linesep,
+                                           b'fred' + linesep, b'bob'])
         proxy.seek(0)
-        self.assertEqual(proxy.readlines(2), ['foo' + os.linesep])
-        proxy.seek(3 + len(os.linesep))
-        self.assertEqual(proxy.readlines(4 + len(os.linesep)),
-                     ['bar' + os.linesep, 'fred' + os.linesep])
+        self.assertEqual(proxy.readlines(2), [b'foo' + linesep])
+        proxy.seek(3 + len(linesep))
+        self.assertEqual(proxy.readlines(4 + len(linesep)),
+                     [b'bar' + linesep, b'fred' + linesep])
         proxy.seek(3)
-        self.assertEqual(proxy.readlines(1000), [os.linesep, 'bar' + os.linesep,
-                                               'fred' + os.linesep, 'bob'])
+        self.assertEqual(proxy.readlines(1000), [linesep, b'bar' + linesep,
+                                               b'fred' + linesep, b'bob'])
 
     def _test_iteration(self, proxy):
         # Iterate by line
+        linesep = os.linesep.encode()
         proxy.seek(0)
         iterator = iter(proxy)
-        self.assertEqual(next(iterator), 'foo' + os.linesep)
-        self.assertEqual(next(iterator), 'bar' + os.linesep)
-        self.assertEqual(next(iterator), 'fred' + os.linesep)
-        self.assertEqual(next(iterator), 'bob')
+        self.assertEqual(next(iterator), b'foo' + linesep)
+        self.assertEqual(next(iterator), b'bar' + linesep)
+        self.assertEqual(next(iterator), b'fred' + linesep)
+        self.assertEqual(next(iterator), b'bob')
         self.assertRaises(StopIteration, next, iterator)
 
     def _test_seek_and_tell(self, proxy):
         # Seek and use tell to check position
+        linesep = os.linesep.encode()
         proxy.seek(3)
         self.assertEqual(proxy.tell(), 3)
-        self.assertEqual(proxy.read(len(os.linesep)), os.linesep)
+        self.assertEqual(proxy.read(len(linesep)), linesep)
         proxy.seek(2, 1)
-        self.assertEqual(proxy.read(1 + len(os.linesep)), 'r' + os.linesep)
-        proxy.seek(-3 - len(os.linesep), 2)
-        self.assertEqual(proxy.read(3), 'bar')
+        self.assertEqual(proxy.read(1 + len(linesep)), b'r' + linesep)
+        proxy.seek(-3 - len(linesep), 2)
+        self.assertEqual(proxy.read(3), b'bar')
         proxy.seek(2, 0)
-        self.assertEqual(proxy.read(), 'o' + os.linesep + 'bar' + os.linesep)
+        self.assertEqual(proxy.read(), b'o' + linesep + b'bar' + linesep)
         proxy.seek(100)
-        self.assertEqual(proxy.read(), '')
+        self.failIf(proxy.read())
 
     def _test_close(self, proxy):
         # Close a file

Modified: python/branches/py3k-importlib/Lib/test/test_marshal.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_marshal.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_marshal.py	Thu Mar 27 00:48:05 2008
@@ -28,7 +28,7 @@
 class IntTestCase(unittest.TestCase, HelperMixin):
     def test_ints(self):
         # Test the full range of Python ints.
-        n = sys.maxint
+        n = sys.maxsize
         while n:
             for expected in (-n, n):
                 self.helper(expected)
@@ -39,7 +39,7 @@
         # we're running the test on a 32-bit box, of course.
 
         def to_little_endian_string(value, nbytes):
-            b = bytes()
+            b = bytearray()
             for i in range(nbytes):
                 b.append(value & 0xff)
                 value >>= 8
@@ -66,7 +66,7 @@
     def test_floats(self):
         # Test a few floats
         small = 1e-25
-        n = sys.maxint * 3.7e250
+        n = sys.maxsize * 3.7e250
         while n > small:
             for expected in (-n, n):
                 self.helper(float(expected))
@@ -81,7 +81,7 @@
         got = marshal.loads(s)
         self.assertEqual(f, got)
 
-        n = sys.maxint * 3.7e-250
+        n = sys.maxsize * 3.7e-250
         while n < small:
             for expected in (-n, n):
                 f = float(expected)
@@ -188,6 +188,17 @@
         last.append([0])
         self.assertRaises(ValueError, marshal.dumps, head)
 
+    def test_exact_type_match(self):
+        # Former bug:
+        #   >>> class Int(int): pass
+        #   >>> type(loads(dumps(Int())))
+        #   <type 'int'>
+        for typ in (int, float, complex, tuple, list, dict, set, frozenset):
+            # Note: str sublclasses are not tested because they get handled
+            # by marshal's routines for objects supporting the buffer API.
+            subtyp = type('subtyp', (typ,), {})
+            self.assertRaises(ValueError, marshal.dumps, subtyp())
+
 def test_main():
     test_support.run_unittest(IntTestCase,
                               FloatTestCase,

Modified: python/branches/py3k-importlib/Lib/test/test_math.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_math.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_math.py	Thu Mar 27 00:48:05 2008
@@ -51,6 +51,7 @@
 
     def testCeil(self):
         self.assertRaises(TypeError, math.ceil)
+        self.assertEquals(int, type(math.ceil(0.5)))
         self.ftest('ceil(0.5)', math.ceil(0.5), 1)
         self.ftest('ceil(1.0)', math.ceil(1.0), 1)
         self.ftest('ceil(1.5)', math.ceil(1.5), 2)
@@ -103,6 +104,7 @@
 
     def testFloor(self):
         self.assertRaises(TypeError, math.floor)
+        self.assertEquals(int, type(math.floor(0.5)))
         self.ftest('floor(0.5)', math.floor(0.5), 0)
         self.ftest('floor(1.0)', math.floor(1.0), 1)
         self.ftest('floor(1.5)', math.floor(1.5), 1)
@@ -231,6 +233,61 @@
         self.ftest('tanh(0)', math.tanh(0), 0)
         self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0)
 
+    def test_trunc(self):
+        self.assertEqual(math.trunc(1), 1)
+        self.assertEqual(math.trunc(-1), -1)
+        self.assertEqual(type(math.trunc(1)), int)
+        self.assertEqual(type(math.trunc(1.5)), int)
+        self.assertEqual(math.trunc(1.5), 1)
+        self.assertEqual(math.trunc(-1.5), -1)
+        self.assertEqual(math.trunc(1.999999), 1)
+        self.assertEqual(math.trunc(-1.999999), -1)
+        self.assertEqual(math.trunc(-0.999999), -0)
+        self.assertEqual(math.trunc(-100.999), -100)
+
+        class TestTrunc(object):
+            def __trunc__(self):
+                return 23
+
+        class TestNoTrunc(object):
+            pass
+
+        self.assertEqual(math.trunc(TestTrunc()), 23)
+
+        self.assertRaises(TypeError, math.trunc)
+        self.assertRaises(TypeError, math.trunc, 1, 2)
+        self.assertRaises(TypeError, math.trunc, TestNoTrunc())
+
+        # XXX Doesn't work because the method is looked up on
+        #     the type only.
+        #t = TestNoTrunc()
+        #t.__trunc__ = lambda *args: args
+        #self.assertEquals((), math.trunc(t))
+        #self.assertRaises(TypeError, math.trunc, t, 0)
+
+    def testCopysign(self):
+        self.assertEqual(math.copysign(1, 42), 1.0)
+        self.assertEqual(math.copysign(0., 42), 0.0)
+        self.assertEqual(math.copysign(1., -42), -1.0)
+        self.assertEqual(math.copysign(3, 0.), 3.0)
+        self.assertEqual(math.copysign(4., -0.), -4.0)
+
+    def testIsnan(self):
+        self.assert_(math.isnan(float("nan")))
+        self.assert_(math.isnan(float("inf")* 0.))
+        self.failIf(math.isnan(float("inf")))
+        self.failIf(math.isnan(0.))
+        self.failIf(math.isnan(1.))
+
+    def testIsinf(self):
+        self.assert_(math.isinf(float("inf")))
+        self.assert_(math.isinf(float("-inf")))
+        self.assert_(math.isinf(1E400))
+        self.assert_(math.isinf(-1E400))
+        self.failIf(math.isinf(float("nan")))
+        self.failIf(math.isinf(0.))
+        self.failIf(math.isinf(1.))
+
     # RED_FLAG 16-Oct-2000 Tim
     # While 2.0 is more consistent about exceptions than previous releases, it
     # still fails this part of the test on some platforms.  For now, we only

Modified: python/branches/py3k-importlib/Lib/test/test_minidom.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_minidom.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_minidom.py	Thu Mar 27 00:48:05 2008
@@ -3,7 +3,6 @@
 import os
 import sys
 import pickle
-import traceback
 from io import StringIO
 from test.test_support import verbose, run_unittest, TestSkipped
 import unittest
@@ -791,6 +790,14 @@
                 "testNormalize -- single empty node removed")
         doc.unlink()
 
+    def testBug1433694(self):
+        doc = parseString("<o><i/>t</o>")
+        node = doc.documentElement
+        node.childNodes[1].nodeValue = ""
+        node.normalize()
+        self.confirm(node.childNodes[-1].nextSibling == None,
+                     "Final child's .nextSibling should be None")
+
     def testSiblings(self):
         doc = parseString("<doc><?pi?>text?<elm/></doc>")
         root = doc.documentElement

Modified: python/branches/py3k-importlib/Lib/test/test_mmap.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_mmap.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_mmap.py	Thu Mar 27 00:48:05 2008
@@ -39,15 +39,15 @@
 
         self.assertEqual(len(m), 2*PAGESIZE)
 
-        self.assertEqual(m[0], b'\0')
+        self.assertEqual(m[0], 0)
         self.assertEqual(m[0:3], b'\0\0\0')
 
         # Modify the file's content
-        m[0] = b'3'
+        m[0] = b'3'[0]
         m[PAGESIZE +3: PAGESIZE +3+3] = b'bar'
 
         # Check that the modification worked
-        self.assertEqual(m[0], b'3')
+        self.assertEqual(m[0], b'3'[0])
         self.assertEqual(m[0:3], b'3\0\0')
         self.assertEqual(m[PAGESIZE-1 : PAGESIZE + 7], b'\0foobar\0')
 
@@ -252,6 +252,42 @@
                 self.assertEqual(m.find(slice + b'x'), -1)
         m.close()
 
+    def test_find_end(self):
+        # test the new 'end' parameter works as expected
+        f = open(TESTFN, 'w+')
+        data = 'one two ones'
+        n = len(data)
+        f.write(data)
+        f.flush()
+        m = mmap.mmap(f.fileno(), n)
+        f.close()
+
+        self.assertEqual(m.find('one'), 0)
+        self.assertEqual(m.find('ones'), 8)
+        self.assertEqual(m.find('one', 0, -1), 0)
+        self.assertEqual(m.find('one', 1), 8)
+        self.assertEqual(m.find('one', 1, -1), 8)
+        self.assertEqual(m.find('one', 1, -2), -1)
+
+
+    def test_rfind(self):
+        # test the new 'end' parameter works as expected
+        f = open(TESTFN, 'w+')
+        data = 'one two ones'
+        n = len(data)
+        f.write(data)
+        f.flush()
+        m = mmap.mmap(f.fileno(), n)
+        f.close()
+
+        self.assertEqual(m.rfind('one'), 8)
+        self.assertEqual(m.rfind('one '), 0)
+        self.assertEqual(m.rfind('one', 0, -1), 8)
+        self.assertEqual(m.rfind('one', 0, -2), 0)
+        self.assertEqual(m.rfind('one', 1, -1), 8)
+        self.assertEqual(m.rfind('one', 1, -2), -1)
+
+
     def test_double_close(self):
         # make sure a double close doesn't crash on Solaris (Bug# 665913)
         f = open(TESTFN, 'wb+')
@@ -297,11 +333,11 @@
         # anonymous mmap.mmap(-1, PAGE)
         m = mmap.mmap(-1, PAGESIZE)
         for x in range(PAGESIZE):
-            self.assertEqual(m[x], b'\0', "anonymously mmap'ed contents should be zero")
+            self.assertEqual(m[x], 0,
+                             "anonymously mmap'ed contents should be zero")
 
-        b = bytes(1)
         for x in range(PAGESIZE):
-            b[0] = x & 255
+            b = x & 0xff
             m[x] = b
             self.assertEqual(m[x], b)
 
@@ -339,6 +375,71 @@
                     m[start:stop:step] = data
                     self.assertEquals(m[:], bytes(L))
 
+    def make_mmap_file (self, f, halfsize):
+        # Write 2 pages worth of data to the file
+        f.write (b'\0' * halfsize)
+        f.write (b'foo')
+        f.write (b'\0' * (halfsize - 3))
+        f.flush ()
+        return mmap.mmap (f.fileno(), 0)
+
+    def test_offset (self):
+        f = open (TESTFN, 'w+b')
+
+        try: # unlink TESTFN no matter what
+            halfsize = mmap.ALLOCATIONGRANULARITY
+            m = self.make_mmap_file (f, halfsize)
+            m.close ()
+            f.close ()
+
+            mapsize = halfsize * 2
+            # Try invalid offset
+            f = open(TESTFN, "r+b")
+            for offset in [-2, -1, None]:
+                try:
+                    m = mmap.mmap(f.fileno(), mapsize, offset=offset)
+                    self.assertEqual(0, 1)
+                except (ValueError, TypeError, OverflowError):
+                    pass
+                else:
+                    self.assertEqual(0, 0)
+            f.close()
+
+            # Try valid offset, hopefully 8192 works on all OSes
+            f = open(TESTFN, "r+b")
+            m = mmap.mmap(f.fileno(), mapsize - halfsize, offset=halfsize)
+            self.assertEqual(m[0:3], b'foo')
+            f.close()
+            m.close()
+
+        finally:
+            f.close()
+            try:
+                os.unlink(TESTFN)
+            except OSError:
+                pass
+
+    def test_subclass(self):
+        class anon_mmap(mmap.mmap):
+            def __new__(klass, *args, **kwargs):
+                return mmap.mmap.__new__(klass, -1, *args, **kwargs)
+        anon_mmap(PAGESIZE)
+
+    def test_prot_readonly(self):
+        if not hasattr(mmap, 'PROT_READ'):
+            return
+        mapsize = 10
+        open(TESTFN, "wb").write(b"a"*mapsize)
+        f = open(TESTFN, "rb")
+        m = mmap.mmap(f.fileno(), mapsize, prot=mmap.PROT_READ)
+        self.assertRaises(TypeError, m.write, "foo")
+
+
+    def test_error(self):
+        self.assert_(issubclass(mmap.error, EnvironmentError))
+        self.assert_("mmap.error" in str(mmap.error))
+
+
 def test_main():
     run_unittest(MmapTests)
 

Modified: python/branches/py3k-importlib/Lib/test/test_module.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_module.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_module.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,6 @@
 # Test the module type
 import unittest
-from test.test_support import verbose, run_unittest
+from test.test_support import run_unittest
 
 import sys
 ModuleType = type(sys)

Modified: python/branches/py3k-importlib/Lib/test/test_modulefinder.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_modulefinder.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_modulefinder.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 import __future__
-import sys, os
+import os
 import unittest
 import distutils.dir_util
 import tempfile

Modified: python/branches/py3k-importlib/Lib/test/test_multibytecodec.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_multibytecodec.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_multibytecodec.py	Thu Mar 27 00:48:05 2008
@@ -40,7 +40,7 @@
 
     def test_errorcallback_longindex(self):
         dec = codecs.getdecoder('euc-kr')
-        myreplace  = lambda exc: ('', sys.maxint+1)
+        myreplace  = lambda exc: ('', sys.maxsize+1)
         codecs.register_error('test.cjktest', myreplace)
         self.assertRaises(IndexError, dec,
                           'apple\x92ham\x93spam', 'test.cjktest')

Modified: python/branches/py3k-importlib/Lib/test/test_multibytecodec_support.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_multibytecodec_support.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_multibytecodec_support.py	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,7 @@
 #   Common Unittest Routines for CJK codecs
 #
 
-import sys, codecs, os.path
+import sys, codecs
 import unittest, re
 from test import test_support
 from io import BytesIO
@@ -52,6 +52,10 @@
                 func = self.encode
             if expected:
                 result = func(source, scheme)[0]
+                if func is self.decode:
+                    self.assert_(type(result) is str, type(result))
+                else:
+                    self.assert_(type(result) is bytes, type(result))
                 self.assertEqual(result, expected)
             else:
                 self.assertRaises(UnicodeError, func, source, scheme)
@@ -110,7 +114,7 @@
                                      'test.cjktest'), (b'abcdxefgh', 9))
 
         def myreplace(exc):
-            return ('x', sys.maxint + 1)
+            return ('x', sys.maxsize + 1)
         codecs.register_error("test.cjktest", myreplace)
         self.assertRaises(IndexError, self.encode, self.unmappedunicode,
                           'test.cjktest')
@@ -272,7 +276,10 @@
 
     def __init__(self, *args, **kw):
         unittest.TestCase.__init__(self, *args, **kw)
-        self.open_mapping_file() # test it to report the error early
+        try:
+            self.open_mapping_file() # test it to report the error early
+        except IOError:
+            raise test_support.TestSkipped("Could not retrieve "+self.mapfileurl)
 
     def open_mapping_file(self):
         return test_support.open_urlresource(self.mapfileurl)

Modified: python/branches/py3k-importlib/Lib/test/test_netrc.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_netrc.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_netrc.py	Thu Mar 27 00:48:05 2008
@@ -21,25 +21,24 @@
 
 class NetrcTestCase(unittest.TestCase):
 
-    def setUp (self):
+    def setUp(self):
         mode = 'w'
         if sys.platform not in ['cygwin']:
             mode += 't'
         fp = open(temp_filename, mode)
         fp.write(TEST_NETRC)
         fp.close()
-        self.netrc = netrc.netrc(temp_filename)
 
-    def tearDown (self):
-        del self.netrc
+    def tearDown(self):
         os.unlink(temp_filename)
 
     def test_case_1(self):
-        self.assert_(self.netrc.macros == {'macro1':['line1\n', 'line2\n'],
+        nrc = netrc.netrc(temp_filename)
+        self.assert_(nrc.macros == {'macro1':['line1\n', 'line2\n'],
                                            'macro2':['line3\n', 'line4\n']}
                                            )
-        self.assert_(self.netrc.hosts['foo'] == ('log1', 'acct1', 'pass1'))
-        self.assert_(self.netrc.hosts['default'] == ('log2', None, 'pass2'))
+        self.assert_(nrc.hosts['foo'] == ('log1', 'acct1', 'pass1'))
+        self.assert_(nrc.hosts['default'] == ('log2', None, 'pass2'))
 
 def test_main():
     test_support.run_unittest(NetrcTestCase)

Deleted: /python/branches/py3k-importlib/Lib/test/test_new.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/test_new.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,158 +0,0 @@
-import unittest
-from test import test_support
-import sys, new
-
-class NewTest(unittest.TestCase):
-    def test_spam(self):
-        class Eggs:
-            def get_yolks(self):
-                return self.yolks
-
-        m = new.module('Spam')
-        m.Eggs = Eggs
-        sys.modules['Spam'] = m
-        import Spam
-
-        def get_more_yolks(self):
-            return self.yolks + 3
-
-        # new.classobj()
-        C = new.classobj('Spam', (Spam.Eggs,), {'get_more_yolks': get_more_yolks})
-
-        def break_yolks(self):
-            self.yolks = self.yolks - 2
-
-        # new.instancemethod()
-        c = C()
-        c.yolks = 3
-        im = new.instancemethod(break_yolks, c, C)
-
-        self.assertEqual(c.get_yolks(), 3,
-            'Broken call of hand-crafted class instance')
-        self.assertEqual(c.get_more_yolks(), 6,
-            'Broken call of hand-crafted class instance')
-
-        im()
-        self.assertEqual(c.get_yolks(), 1,
-            'Broken call of hand-crafted instance method')
-        self.assertEqual(c.get_more_yolks(), 4,
-            'Broken call of hand-crafted instance method')
-
-        im = new.instancemethod(break_yolks, c)
-        im()
-        self.assertEqual(c.get_yolks(), -1)
-
-        # Verify that dangerous instance method creation is forbidden
-        self.assertRaises(TypeError, new.instancemethod, break_yolks, None)
-
-        # Verify that instancemethod() doesn't allow keyword args
-        self.assertRaises(TypeError, new.instancemethod, break_yolks, c, kw=1)
-
-    def test_scope(self):
-        # It's unclear what the semantics should be for a code object compiled
-        # at module scope, but bound and run in a function.  In CPython, `c' is
-        # global (by accident?) while in Jython, `c' is local.  The intent of
-        # the test clearly is to make `c' global, so let's be explicit about it.
-        codestr = '''
-        global c
-        a = 1
-        b = 2
-        c = a + b
-        '''
-
-        codestr = "\n".join(l.strip() for l in codestr.splitlines())
-
-        ccode = compile(codestr, '<string>', 'exec')
-        # Jython doesn't have a __builtins__, so use a portable alternative
-        import __builtin__
-        g = {'c': 0, '__builtins__': __builtin__}
-
-        # this test could be more robust
-        func = new.function(ccode, g)
-        func()
-        self.assertEqual(g['c'], 3, 'Could not create a proper function object')
-
-    def test_function(self):
-        # test the various extended flavors of function.new
-        def f(x):
-            def g(y):
-                return x + y
-            return g
-        g = f(4)
-        new.function(f.__code__, {}, "blah")
-        g2 = new.function(g.__code__, {}, "blah", (2,), g.__closure__)
-        self.assertEqual(g2(), 6)
-        g3 = new.function(g.__code__, {}, "blah", None, g.__closure__)
-        self.assertEqual(g3(5), 9)
-        def test_closure(func, closure, exc):
-            self.assertRaises(exc, new.function, func.__code__, {}, "", None, closure)
-
-        test_closure(g, None, TypeError) # invalid closure
-        test_closure(g, (1,), TypeError) # non-cell in closure
-        test_closure(g, (1, 1), ValueError) # closure is wrong size
-        test_closure(f, g.__closure__, ValueError) # no closure needed
-
-    # Note: Jython will never have new.code()
-    if hasattr(new, 'code'):
-        def test_code(self):
-            # bogus test of new.code()
-            def f(a): pass
-
-            c = f.__code__
-            argcount = c.co_argcount
-            kwonlyargcount = c.co_kwonlyargcount
-            nlocals = c.co_nlocals
-            stacksize = c.co_stacksize
-            flags = c.co_flags
-            codestring = c.co_code
-            constants = c.co_consts
-            names = c.co_names
-            varnames = c.co_varnames
-            filename = c.co_filename
-            name = c.co_name
-            firstlineno = c.co_firstlineno
-            lnotab = c.co_lnotab
-            freevars = c.co_freevars
-            cellvars = c.co_cellvars
-
-            d = new.code(argcount, kwonlyargcount, nlocals, stacksize, flags,
-                         codestring, constants, names, varnames, filename,
-                         name, firstlineno, lnotab, freevars, cellvars)
-
-            # test backwards-compatibility version with no freevars or cellvars
-            d = new.code(argcount, kwonlyargcount, nlocals, stacksize,
-                         flags, codestring, constants, names, varnames,
-                         filename, name, firstlineno, lnotab)
-
-            # negative co_argcount used to trigger a SystemError
-            self.assertRaises(ValueError, new.code,
-                -argcount, kwonlyargcount, nlocals, stacksize, flags,
-                codestring, constants, names, varnames, filename, name,
-                firstlineno, lnotab)
-
-            # negative co_nlocals used to trigger a SystemError
-            self.assertRaises(ValueError, new.code,
-                argcount, kwonlyargcount, -nlocals, stacksize, flags,
-                codestring, constants, names, varnames, filename, name,
-                firstlineno, lnotab)
-
-            # non-string co_name used to trigger a Py_FatalError
-            self.assertRaises(TypeError, new.code,
-                argcount, kwonlyargcount, nlocals, stacksize, flags,
-                codestring, constants, (5,), varnames, filename, name,
-                firstlineno, lnotab)
-
-            # new.code used to be a way to mutate a tuple...
-            class S(str):
-                pass
-            t = (S("ab"),)
-            d = new.code(argcount, kwonlyargcount, nlocals, stacksize,
-                         flags, codestring, constants, t, varnames,
-                         filename, name, firstlineno, lnotab)
-            self.assert_(type(t[0]) is S, "eek, tuple changed under us!")
-
-def test_main():
-    test_support.run_unittest(NewTest)
-
-if __name__ == "__main__":
-    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_nis.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_nis.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_nis.py	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,4 @@
-from test.test_support import verbose, run_unittest
+from test import test_support
 import unittest
 import nis
 
@@ -8,8 +8,10 @@
             maps = nis.maps()
         except nis.error as msg:
             # NIS is probably not active, so this test isn't useful
-            if verbose:
-                self.fail("(failing because of verbose mode) %s" % msg)
+            if test_support.verbose:
+                print("Test Skipped:", msg)
+            # Can't raise TestSkipped as regrtest only recognizes the exception
+            #   import time.
             return
         try:
             # On some systems, this map is only accessible to the
@@ -35,7 +37,7 @@
                 break
 
 def test_main():
-    run_unittest(NisTests)
+    test_support.run_unittest(NisTests)
 
 if __name__ == '__main__':
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_ntpath.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_ntpath.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_ntpath.py	Thu Mar 27 00:48:05 2008
@@ -166,6 +166,7 @@
 tester('ntpath.relpath("a/b", "../c")', '..\\'+currentdir+'\\a\\b')
 tester('ntpath.relpath("a", "b/c")', '..\\..\\a')
 tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a')
+tester('ntpath.relpath("a", "a")', '.')
 
 if errors:
     raise TestFailed(str(errors) + " errors.")

Modified: python/branches/py3k-importlib/Lib/test/test_operator.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_operator.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_operator.py	Thu Mar 27 00:48:05 2008
@@ -137,15 +137,6 @@
         self.failUnless(operator.delitem(a, 1) is None)
         self.assert_(a == [4, 2, 1])
 
-    def test_delslice(self):
-        a = list(range(10))
-        self.failUnlessRaises(TypeError, operator.delslice, a)
-        self.failUnlessRaises(TypeError, operator.delslice, a, None, None)
-        self.failUnless(operator.delslice(a, 2, 8) is None)
-        self.assert_(a == [0, 1, 8, 9])
-        operator.delslice(a, 0, test_support.MAX_Py_ssize_t)
-        self.assertEqual(a, [])
-
     def test_floordiv(self):
         self.failUnlessRaises(TypeError, operator.floordiv, 5)
         self.failUnlessRaises(TypeError, operator.floordiv, None, None)
@@ -162,14 +153,6 @@
         self.failUnlessRaises(TypeError, operator.getitem, a, None)
         self.failUnless(operator.getitem(a, 2) == 2)
 
-    def test_getslice(self):
-        a = list(range(10))
-        self.failUnlessRaises(TypeError, operator.getslice)
-        self.failUnlessRaises(TypeError, operator.getslice, a, None, None)
-        self.failUnless(operator.getslice(a, 4, 6) == [4, 5])
-        b = operator.getslice(a, 0, test_support.MAX_Py_ssize_t)
-        self.assertEqual(b, a)
-
     def test_indexOf(self):
         self.failUnlessRaises(TypeError, operator.indexOf)
         self.failUnlessRaises(TypeError, operator.indexOf, None, None)
@@ -298,15 +281,6 @@
         self.assert_(a == [2, 1, 2])
         self.assertRaises(IndexError, operator.setitem, a, 4, 2)
 
-    def test_setslice(self):
-        a = list(range(4))
-        self.failUnlessRaises(TypeError, operator.setslice, a)
-        self.failUnlessRaises(TypeError, operator.setslice, a, None, None, None)
-        self.failUnless(operator.setslice(a, 1, 3, [2, 1]) is None)
-        self.assert_(a == [0, 2, 1, 3])
-        operator.setslice(a, 0, test_support.MAX_Py_ssize_t, [])
-        self.assertEqual(a, [])
-
     def test_sub(self):
         self.failUnlessRaises(TypeError, operator.sub)
         self.failUnlessRaises(TypeError, operator.sub, None, None)
@@ -364,9 +338,29 @@
         self.assertRaises(TypeError, operator.attrgetter('x', (), 'y'), record)
 
         class C(object):
-            def __getattr(self, name):
+            def __getattr__(self, name):
                 raise SyntaxError
-        self.failUnlessRaises(AttributeError, operator.attrgetter('foo'), C())
+        self.failUnlessRaises(SyntaxError, operator.attrgetter('foo'), C())
+
+        # recursive gets
+        a = A()
+        a.name = 'arthur'
+        a.child = A()
+        a.child.name = 'thomas'
+        f = operator.attrgetter('child.name')
+        self.assertEqual(f(a), 'thomas')
+        self.assertRaises(AttributeError, f, a.child)
+        f = operator.attrgetter('name', 'child.name')
+        self.assertEqual(f(a), ('arthur', 'thomas'))
+        f = operator.attrgetter('name', 'child.name', 'child.child.name')
+        self.assertRaises(AttributeError, f, a)
+
+        a.child.child = A()
+        a.child.child.name = 'johnson'
+        f = operator.attrgetter('child.child.name')
+        self.assertEqual(f(a), 'johnson')
+        f = operator.attrgetter('name', 'child.name', 'child.child.name')
+        self.assertEqual(f(a), ('arthur', 'thomas', 'johnson'))
 
     def test_itemgetter(self):
         a = 'ABCDE'
@@ -376,9 +370,9 @@
         self.assertRaises(IndexError, f, a)
 
         class C(object):
-            def __getitem(self, name):
+            def __getitem__(self, name):
                 raise SyntaxError
-        self.failUnlessRaises(TypeError, operator.itemgetter(42), C())
+        self.failUnlessRaises(SyntaxError, operator.itemgetter(42), C())
 
         f = operator.itemgetter('name')
         self.assertRaises(TypeError, f, a)
@@ -402,6 +396,24 @@
         self.assertEqual(operator.itemgetter(2,10,5)(data), ('2', '10', '5'))
         self.assertRaises(TypeError, operator.itemgetter(2, 'x', 5), data)
 
+    def test_methodcaller(self):
+        self.assertRaises(TypeError, operator.methodcaller)
+        class A:
+            def foo(self, *args, **kwds):
+                return args[0] + args[1]
+            def bar(self, f=42):
+                return f
+        a = A()
+        f = operator.methodcaller('foo')
+        self.assertRaises(IndexError, f, a)
+        f = operator.methodcaller('foo', 1, 2)
+        self.assertEquals(f(a), 3)
+        f = operator.methodcaller('bar')
+        self.assertEquals(f(a), 42)
+        self.assertRaises(TypeError, f, a, a)
+        f = operator.methodcaller('bar', f=5)
+        self.assertEquals(f(a), 5)
+
     def test_inplace(self):
         class C(object):
             def __iadd__     (self, other): return "iadd"

Modified: python/branches/py3k-importlib/Lib/test/test_optparse.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_optparse.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_optparse.py	Thu Mar 27 00:48:05 2008
@@ -15,7 +15,6 @@
 import unittest
 
 from io import StringIO
-from pprint import pprint
 from test import test_support
 
 

Modified: python/branches/py3k-importlib/Lib/test/test_os.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_os.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_os.py	Thu Mar 27 00:48:05 2008
@@ -8,9 +8,6 @@
 import sys
 from test import test_support
 
-warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, __name__)
-warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, __name__)
-
 # Tests creating TESTFN
 class FileTests(unittest.TestCase):
     def setUp(self):
@@ -23,6 +20,11 @@
         os.close(f)
         self.assert_(os.access(test_support.TESTFN, os.W_OK))
 
+    def test_closerange(self):
+        f = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR)
+        # close a fd that is open, and one that isn't
+        os.closerange(f, f+2)
+        self.assertRaises(OSError, os.write, f, "a")
 
 class TemporaryFileTests(unittest.TestCase):
     def setUp(self):
@@ -53,18 +55,56 @@
         self.check_tempfile(name)
 
         name = os.tempnam(test_support.TESTFN, "pfx")
-        self.assertEqual(os.path.basename(name)[:3], "pfx")
+        self.assert_(os.path.basename(name)[:3] == "pfx")
         self.check_tempfile(name)
 
     def test_tmpfile(self):
         if not hasattr(os, "tmpfile"):
             return
+        # As with test_tmpnam() below, the Windows implementation of tmpfile()
+        # attempts to create a file in the root directory of the current drive.
+        # On Vista and Server 2008, this test will always fail for normal users
+        # as writing to the root directory requires elevated privileges.  With
+        # XP and below, the semantics of tmpfile() are the same, but the user
+        # running the test is more likely to have administrative privileges on
+        # their account already.  If that's the case, then os.tmpfile() should
+        # work.  In order to make this test as useful as possible, rather than
+        # trying to detect Windows versions or whether or not the user has the
+        # right permissions, just try and create a file in the root directory
+        # and see if it raises a 'Permission denied' OSError.  If it does, then
+        # test that a subsequent call to os.tmpfile() raises the same error. If
+        # it doesn't, assume we're on XP or below and the user running the test
+        # has administrative privileges, and proceed with the test as normal.
+        if sys.platform == 'win32':
+            name = '\\python_test_os_test_tmpfile.txt'
+            if os.path.exists(name):
+                os.remove(name)
+            try:
+                fp = open(name, 'w')
+            except IOError as first:
+                # open() failed, assert tmpfile() fails in the same way.
+                # Although open() raises an IOError and os.tmpfile() raises an
+                # OSError(), 'args' will be (13, 'Permission denied') in both
+                # cases.
+                try:
+                    fp = os.tmpfile()
+                except OSError as second:
+                    self.assertEqual(first.args, second.args)
+                else:
+                    self.fail("expected os.tmpfile() to raise OSError")
+                return
+            else:
+                # open() worked, therefore, tmpfile() should work.  Close our
+                # dummy file and proceed with the test as normal.
+                fp.close()
+                os.remove(name)
+
         fp = os.tmpfile()
-        fp.write(b"foobar")
-        fp.seek(0)
+        fp.write("foobar")
+        fp.seek(0,0)
         s = fp.read()
         fp.close()
-        self.assertEquals(s, b"foobar")
+        self.assert_(s == "foobar")
 
     def test_tmpnam(self):
         import sys
@@ -264,25 +304,40 @@
 class EnvironTests(mapping_tests.BasicTestMappingProtocol):
     """check that os.environ object conform to mapping protocol"""
     type2test = None
-    def _reference(self):
-        return {"KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3"}
-    def _empty_mapping(self):
-        os.environ.clear()
-        return os.environ
+
     def setUp(self):
         self.__save = dict(os.environ)
-        os.environ.clear()
+        for key, value in self._reference().items():
+            os.environ[key] = value
+
     def tearDown(self):
         os.environ.clear()
         os.environ.update(self.__save)
 
+    def _reference(self):
+        return {"KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3"}
+
+    def _empty_mapping(self):
+        os.environ.clear()
+        return os.environ
+
     # Bug 1110478
     def test_update2(self):
+        os.environ.clear()
         if os.path.exists("/bin/sh"):
             os.environ.update(HELLO="World")
             value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip()
             self.assertEquals(value, "World")
 
+    def test_os_popen_iter(self):
+        if os.path.exists("/bin/sh"):
+            popen = os.popen("/bin/sh -c 'echo \"line1\nline2\nline3\"'")
+            it = iter(popen)
+            self.assertEquals(next(it), "line1\n")
+            self.assertEquals(next(it), "line2\n")
+            self.assertEquals(next(it), "line3\n")
+            self.assertRaises(StopIteration, next, it)
+
     # Verify environ keys and values from the OS are of the
     # correct str type.
     def test_keyvalue_types(self):
@@ -290,6 +345,10 @@
             self.assertEquals(type(key), str)
             self.assertEquals(type(val), str)
 
+    def test_items(self):
+        for key, value in self._reference().items():
+            self.assertEqual(os.environ.get(key), value)
+
 class WalkTests(unittest.TestCase):
     """Tests for os.walk()."""
 
@@ -483,7 +542,6 @@
 def test_main():
     test_support.run_unittest(
         FileTests,
-        TemporaryFileTests,
         StatAttributeTests,
         EnvironTests,
         WalkTests,

Modified: python/branches/py3k-importlib/Lib/test/test_ossaudiodev.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_ossaudiodev.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_ossaudiodev.py	Thu Mar 27 00:48:05 2008
@@ -1,14 +1,11 @@
 from test import test_support
 test_support.requires('audio')
 
-from test.test_support import verbose, findfile, TestSkipped
+from test.test_support import findfile, TestSkipped
 
 import errno
-import fcntl
 import ossaudiodev
-import os
 import sys
-import select
 import sunaudio
 import time
 import audioop

Modified: python/branches/py3k-importlib/Lib/test/test_parser.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_parser.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_parser.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 import parser
 import unittest
+import sys
 from test import test_support
 
 #
@@ -136,6 +137,7 @@
 
     def test_class_defs(self):
         self.check_suite("class foo():pass")
+        self.check_suite("class foo(object):pass")
 
     def test_import_from_statement(self):
         self.check_suite("from sys.path import *")
@@ -449,11 +451,31 @@
         st = parser.suite('a = "\\u1"')
         self.assertRaises(SyntaxError, parser.compilest, st)
 
+class ParserStackLimitTestCase(unittest.TestCase):
+    """try to push the parser to/over it's limits.
+    see http://bugs.python.org/issue1881 for a discussion
+    """
+    def _nested_expression(self, level):
+        return "["*level+"]"*level
+
+    def test_deeply_nested_list(self):
+        # XXX used to be 99 levels in 2.x
+        e = self._nested_expression(93)
+        st = parser.expr(e)
+        st.compile()
+
+    def test_trigger_memory_error(self):
+        e = self._nested_expression(100)
+        print("Expecting 's_push: parser stack overflow' in next line",
+              file=sys.stderr)
+        self.assertRaises(MemoryError, parser.expr, e)
+
 def test_main():
     test_support.run_unittest(
         RoundtripLegalSyntaxTestCase,
         IllegalSyntaxTestCase,
         CompileTestCase,
+        ParserStackLimitTestCase,
     )
 
 

Modified: python/branches/py3k-importlib/Lib/test/test_pep247.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_pep247.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_pep247.py	Thu Mar 27 00:48:05 2008
@@ -1,48 +1,68 @@
-#
-# Test suite to check compliance with PEP 247, the standard API for
-# hashing algorithms.
-#
+"""
+Test suite to check compilance with PEP 247, the standard API
+for hashing algorithms
+"""
 
 import hmac
+import unittest
+from hashlib import md5, sha1, sha224, sha256, sha384, sha512
+from test import test_support
+
+class Pep247Test(unittest.TestCase):
+
+    def check_module(self, module, key=None):
+        self.assert_(hasattr(module, 'digest_size'))
+        self.assert_(module.digest_size is None or module.digest_size > 0)
+        self.check_object(module.new, module.digest_size, key)
+
+    def check_object(self, cls, digest_size, key):
+        if key is not None:
+            obj1 = cls(key)
+            obj2 = cls(key, b'string')
+            h1 = cls(key, b'string').digest()
+            obj3 = cls(key)
+            obj3.update(b'string')
+            h2 = obj3.digest()
+        else:
+            obj1 = cls()
+            obj2 = cls(b'string')
+            h1 = cls(b'string').digest()
+            obj3 = cls()
+            obj3.update(b'string')
+            h2 = obj3.digest()
+        self.assertEquals(h1, h2)
+        self.assert_(hasattr(obj1, 'digest_size'))
+
+        if digest_size is not None:
+            self.assertEquals(obj1.digest_size, digest_size)
+
+        self.assertEquals(obj1.digest_size, len(h1))
+        obj1.update(b'string')
+        obj_copy = obj1.copy()
+        self.assertEquals(obj1.digest(), obj_copy.digest())
+        self.assertEquals(obj1.hexdigest(), obj_copy.hexdigest())
+
+        digest, hexdigest = obj1.digest(), obj1.hexdigest()
+        hd2 = ""
+        for byte in digest:
+            hd2 += '%02x' % byte
+        self.assertEquals(hd2, hexdigest)
+
+    def test_md5(self):
+        self.check_object(md5, None, None)
+
+    def test_sha(self):
+        self.check_object(sha1, None, None)
+        self.check_object(sha224, None, None)
+        self.check_object(sha256, None, None)
+        self.check_object(sha384, None, None)
+        self.check_object(sha512, None, None)
 
-def check_hash_module(module, key=None):
-    assert hasattr(module, 'digest_size'), "Must have digest_size"
-    assert (module.digest_size is None or
-            module.digest_size > 0), "digest_size must be None or positive"
-
-    if key is not None:
-        obj1 = module.new(key)
-        obj2 = module.new(key, "string")
-
-        h1 = module.new(key, "string").digest()
-        obj3 = module.new(key) ; obj3.update("string") ; h2 = obj3.digest()
-        assert h1 == h2, "Hashes must match"
-
-    else:
-        obj1 = module.new()
-        obj2 = module.new("string")
-
-        h1 = module.new("string").digest()
-        obj3 = module.new() ; obj3.update("string") ; h2 = obj3.digest()
-        assert h1 == h2, "Hashes must match"
-
-    assert hasattr(obj1, 'digest_size'), "Objects must have digest_size attr"
-    if module.digest_size is not None:
-        assert obj1.digest_size == module.digest_size, "digest_size must match"
-    assert obj1.digest_size == len(h1), "digest_size must match actual size"
-    obj1.update("string")
-    obj_copy = obj1.copy()
-    assert obj1.digest() == obj_copy.digest(), "Copied objects must match"
-    assert obj1.hexdigest() == obj_copy.hexdigest(), \
-           "Copied objects must match"
-    digest, hexdigest = obj1.digest(), obj1.hexdigest()
-    hd2 = ""
-    for byte in digest:
-        hd2 += "%02x" % ord(byte)
-    assert hd2 == hexdigest, "hexdigest doesn't appear correct"
-
-    print('Module', module.__name__, 'seems to comply with PEP 247')
+    def test_hmac(self):
+        self.check_module(hmac, key=b'abc')
 
+def test_main():
+    test_support.run_unittest(Pep247Test)
 
 if __name__ == '__main__':
-    check_hash_module(hmac, key='abc')
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_pep263.py
==============================================================================
Binary files. No diff available.

Modified: python/branches/py3k-importlib/Lib/test/test_pep277.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_pep277.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_pep277.py	Thu Mar 27 00:48:05 2008
@@ -36,7 +36,7 @@
         except OSError:
             pass
         for name in self.files:
-            f = open(name, 'w')
+            f = open(name, 'wb')
             f.write((name+'\n').encode("utf-8"))
             f.close()
             os.stat(name)
@@ -71,19 +71,19 @@
 
     def test_open(self):
         for name in self.files:
-            f = open(name, 'w')
+            f = open(name, 'wb')
             f.write((name+'\n').encode("utf-8"))
             f.close()
             os.stat(name)
 
     def test_listdir(self):
         f1 = os.listdir(test_support.TESTFN)
-        # Printing f1 is not appropriate, as specific filenames
-        # returned depend on the local encoding
-        f2 = os.listdir(str(test_support.TESTFN,
+        f2 = os.listdir(str(test_support.TESTFN.encode("utf-8"),
                                 sys.getfilesystemencoding()))
-        f2.sort()
-        print(f2)
+        sf2 = set("\\".join((str(test_support.TESTFN), f))
+                  for f in f2)
+        self.failUnlessEqual(len(f1), len(self.files))
+        self.failUnlessEqual(sf2, set(self.files))
 
     def test_rename(self):
         for name in self.files:
@@ -96,10 +96,9 @@
         oldwd = os.getcwd()
         os.mkdir(dirname)
         os.chdir(dirname)
-        f = open(filename, 'w')
+        f = open(filename, 'wb')
         f.write((filename + '\n').encode("utf-8"))
         f.close()
-        print(repr(filename))
         os.access(filename,os.R_OK)
         os.remove(filename)
         os.chdir(oldwd)

Modified: python/branches/py3k-importlib/Lib/test/test_pep352.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_pep352.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_pep352.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 import unittest
-import __builtin__
+import builtins
 import warnings
 from test.test_support import run_unittest
 import os
@@ -23,7 +23,7 @@
     def test_inheritance(self):
         # Make sure the inheritance hierarchy matches the documentation
         exc_set = set()
-        for object_ in __builtin__.__dict__.values():
+        for object_ in builtins.__dict__.values():
             try:
                 if issubclass(object_, BaseException):
                     exc_set.add(object_.__name__)
@@ -35,7 +35,7 @@
         try:
             superclass_name = inheritance_tree.readline().rstrip()
             try:
-                last_exc = getattr(__builtin__, superclass_name)
+                last_exc = getattr(builtins, superclass_name)
             except AttributeError:
                 self.fail("base class %s not a built-in" % superclass_name)
             self.failUnless(superclass_name in exc_set,
@@ -58,7 +58,7 @@
                     left_bracket = exc_name.index('[')
                     exc_name = exc_name[:left_bracket-1]  # cover space
                 try:
-                    exc = getattr(__builtin__, exc_name)
+                    exc = getattr(builtins, exc_name)
                 except AttributeError:
                     self.fail("%s not a built-in exception" % exc_name)
                 if last_depth < depth:

Modified: python/branches/py3k-importlib/Lib/test/test_pickle.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_pickle.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_pickle.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,4 @@
 import pickle
-import unittest
 import io
 
 from test import test_support
@@ -10,26 +9,22 @@
 
 class PickleTests(AbstractPickleTests, AbstractPickleModuleTests):
 
-    def dumps(self, arg, proto=0, fast=0):
-        # Ignore fast
+    module = pickle
+    error = KeyError
+
+    def dumps(self, arg, proto=None):
         return pickle.dumps(arg, proto)
 
     def loads(self, buf):
-        # Ignore fast
         return pickle.loads(buf)
 
-    module = pickle
-    error = KeyError
-
 class PicklerTests(AbstractPickleTests):
 
     error = KeyError
 
-    def dumps(self, arg, proto=0, fast=0):
+    def dumps(self, arg, proto=None):
         f = io.BytesIO()
         p = pickle.Pickler(f, proto)
-        if fast:
-            p.fast = fast
         p.dump(arg)
         f.seek(0)
         return bytes(f.read())
@@ -41,14 +36,12 @@
 
 class PersPicklerTests(AbstractPersistentPicklerTests):
 
-    def dumps(self, arg, proto=0, fast=0):
+    def dumps(self, arg, proto=None):
         class PersPickler(pickle.Pickler):
             def persistent_id(subself, obj):
                 return self.persistent_id(obj)
         f = io.BytesIO()
         p = PersPickler(f, proto)
-        if fast:
-            p.fast = fast
         p.dump(arg)
         f.seek(0)
         return f.read()

Modified: python/branches/py3k-importlib/Lib/test/test_pickletools.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_pickletools.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_pickletools.py	Thu Mar 27 00:48:05 2008
@@ -1,3 +1,24 @@
+import pickle
 import pickletools
 from test import test_support
-test_support.run_doctest(pickletools)
+from test.pickletester import AbstractPickleTests
+from test.pickletester import AbstractPickleModuleTests
+
+class OptimizedPickleTests(AbstractPickleTests, AbstractPickleModuleTests):
+
+    def dumps(self, arg, proto=None):
+        return pickletools.optimize(pickle.dumps(arg, proto))
+
+    def loads(self, buf):
+        return pickle.loads(buf)
+
+    module = pickle
+    error = KeyError
+
+def test_main():
+    test_support.run_unittest(OptimizedPickleTests)
+    test_support.run_doctest(pickletools)
+
+
+if __name__ == "__main__":
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_pkg.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_pkg.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_pkg.py	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,6 @@
 import os
 import tempfile
 import textwrap
-import traceback
 import unittest
 from test import test_support
 
@@ -43,14 +42,18 @@
 # from package import * (defined in __init__)
 
 
-class Test(unittest.TestCase):
+class TestPkg(unittest.TestCase):
 
     def setUp(self):
         self.root = None
         self.syspath = list(sys.path)
+        self.sysmodules = sys.modules.copy()
 
     def tearDown(self):
         sys.path[:] = self.syspath
+        sys.modules.clear()
+        sys.modules.update(self.sysmodules)
+        del self.sysmodules
         cleanout(self.root)
 
     def run_code(self, code):
@@ -188,11 +191,13 @@
         import t5
         self.assertEqual(fixdir(dir(t5)),
                          ['__doc__', '__file__', '__name__',
-                          '__path__', 'foo', 'string', 't5'])
+                          '__package__', '__path__', 'foo', 'string', 't5'])
         self.assertEqual(fixdir(dir(t5.foo)),
-                         ['__doc__', '__file__', '__name__', 'string'])
+                         ['__doc__', '__file__', '__name__', '__package__',
+                          'string'])
         self.assertEqual(fixdir(dir(t5.string)),
-                         ['__doc__', '__file__', '__name__', 'spam'])
+                         ['__doc__', '__file__', '__name__','__package__',
+                          'spam'])
 
     def test_6(self):
         hier = [
@@ -208,14 +213,14 @@
         import t6
         self.assertEqual(fixdir(dir(t6)),
                          ['__all__', '__doc__', '__file__',
-                          '__name__', '__path__'])
+                          '__name__', '__package__', '__path__'])
         s = """
             import t6
             from t6 import *
             self.assertEqual(fixdir(dir(t6)),
                              ['__all__', '__doc__', '__file__',
-                              '__name__', '__path__', 'eggs',
-                              'ham', 'spam'])
+                              '__name__', '__package__', '__path__',
+                              'eggs', 'ham', 'spam'])
             self.assertEqual(dir(), ['eggs', 'ham', 'self', 'spam', 't6'])
             """
         self.run_code(s)
@@ -241,17 +246,19 @@
         t7, sub, subsub = None, None, None
         import t7 as tas
         self.assertEqual(fixdir(dir(tas)),
-                         ['__doc__', '__file__', '__name__', '__path__'])
+                         ['__doc__', '__file__', '__name__',
+                          '__package__', '__path__'])
         self.failIf(t7)
         from t7 import sub as subpar
         self.assertEqual(fixdir(dir(subpar)),
-                         ['__doc__', '__file__', '__name__', '__path__'])
+                         ['__doc__', '__file__', '__name__',
+                          '__package__', '__path__'])
         self.failIf(t7)
         self.failIf(sub)
         from t7.sub import subsub as subsubsub
         self.assertEqual(fixdir(dir(subsubsub)),
-                         ['__doc__', '__file__', '__name__', '__path__',
-                          'spam'])
+                         ['__doc__', '__file__', '__name__',
+                         '__package__', '__path__', 'spam'])
         self.failIf(t7)
         self.failIf(sub)
         self.failIf(subsub)

Modified: python/branches/py3k-importlib/Lib/test/test_plistlib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_plistlib.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_plistlib.py	Thu Mar 27 00:48:05 2008
@@ -3,7 +3,6 @@
 import unittest
 import plistlib
 import os
-import time
 import datetime
 from test import test_support
 

Modified: python/branches/py3k-importlib/Lib/test/test_poll.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_poll.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_poll.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,6 @@
 # Test case for the os.poll() function
 
-import sys, os, select, random, unittest
+import os, select, random, unittest
 from test.test_support import TestSkipped, TESTFN, run_unittest
 
 try:
@@ -34,7 +34,8 @@
 
         for i in range(NUM_PIPES):
             rd, wr = os.pipe()
-            p.register(rd, select.POLLIN)
+            p.register(rd)
+            p.modify(rd, select.POLLIN)
             p.register(wr, select.POLLOUT)
             readers.append(rd)
             writers.append(wr)

Modified: python/branches/py3k-importlib/Lib/test/test_poplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_poplib.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_poplib.py	Thu Mar 27 00:48:05 2008
@@ -19,7 +19,7 @@
     except socket.timeout:
         pass
     else:
-        conn.send("+ Hola mundo\n")
+        conn.send(b"+ Hola mundo\n")
         conn.close()
     finally:
         serv.close()

Modified: python/branches/py3k-importlib/Lib/test/test_posix.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_posix.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_posix.py	Thu Mar 27 00:48:05 2008
@@ -9,7 +9,7 @@
 
 import time
 import os
-import sys
+import pwd
 import unittest
 import warnings
 warnings.filterwarnings('ignore', '.* potential security risk .*',
@@ -29,7 +29,7 @@
         # test posix functions which take no arguments and have
         # no side-effects which we need to cleanup (e.g., fork, wait, abort)
         NO_ARG_FUNCTIONS = [ "ctermid", "getcwd", "getcwdu", "uname",
-                             "times", "getloadavg", "tmpnam",
+                             "times", "getloadavg",
                              "getegid", "geteuid", "getgid", "getgroups",
                              "getpid", "getpgrp", "getppid", "getuid",
                            ]
@@ -142,6 +142,33 @@
         if hasattr(posix, 'stat'):
             self.assert_(posix.stat(test_support.TESTFN))
 
+    if hasattr(posix, 'chown'):
+        def test_chown(self):
+            # raise an OSError if the file does not exist
+            os.unlink(test_support.TESTFN)
+            self.assertRaises(OSError, posix.chown, test_support.TESTFN, -1, -1)
+
+            # re-create the file
+            open(test_support.TESTFN, 'w').close()
+            if os.getuid() == 0:
+                try:
+                    # Many linux distros have a nfsnobody user as MAX_UID-2
+                    # that makes a good test case for signedness issues.
+                    #   http://bugs.python.org/issue1747858
+                    # This part of the test only runs when run as root.
+                    # Only scary people run their tests as root.
+                    ent = pwd.getpwnam('nfsnobody')
+                    posix.chown(test_support.TESTFN, ent.pw_uid, ent.pw_gid)
+                except KeyError:
+                    pass
+            else:
+                # non-root cannot chown to root, raises OSError
+                self.assertRaises(OSError, posix.chown,
+                                  test_support.TESTFN, 0, 0)
+
+            # test a successful chown call
+            posix.chown(test_support.TESTFN, os.getuid(), os.getgid())
+
     def test_chdir(self):
         if hasattr(posix, 'chdir'):
             posix.chdir(os.curdir)
@@ -171,17 +198,6 @@
             os.close(reader)
             os.close(writer)
 
-    def test_tempnam(self):
-        if hasattr(posix, 'tempnam'):
-            self.assert_(posix.tempnam())
-            self.assert_(posix.tempnam(os.curdir))
-            self.assert_(posix.tempnam(os.curdir, 'blah'))
-
-    def test_tmpfile(self):
-        if hasattr(posix, 'tmpfile'):
-            fp = posix.tmpfile()
-            fp.close()
-
     def test_utime(self):
         if hasattr(posix, 'utime'):
             now = time.time()
@@ -204,6 +220,11 @@
             if hasattr(st, 'st_flags'):
                 posix.lchflags(test_support.TESTFN, st.st_flags)
 
+    def test_environ(self):
+        for k, v in posix.environ.items():
+            self.assertEqual(type(k), str)
+            self.assertEqual(type(v), str)
+
 def test_main():
     test_support.run_unittest(PosixTester)
 

Modified: python/branches/py3k-importlib/Lib/test/test_posixpath.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_posixpath.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_posixpath.py	Thu Mar 27 00:48:05 2008
@@ -335,15 +335,15 @@
         except ImportError:
             pass
         else:
-            self.assert_(isinstance(posixpath.expanduser("~/"), basestring))
+            self.assert_(isinstance(posixpath.expanduser("~/"), str))
             # if home directory == root directory, this test makes no sense
             if posixpath.expanduser("~") != '/':
                 self.assertEqual(
                     posixpath.expanduser("~") + "/",
                     posixpath.expanduser("~/")
                 )
-            self.assert_(isinstance(posixpath.expanduser("~root/"), basestring))
-            self.assert_(isinstance(posixpath.expanduser("~foo/"), basestring))
+            self.assert_(isinstance(posixpath.expanduser("~root/"), str))
+            self.assert_(isinstance(posixpath.expanduser("~foo/"), str))
 
         self.assertRaises(TypeError, posixpath.expanduser)
 
@@ -501,6 +501,7 @@
             self.assertEqual(posixpath.relpath("a", "../b"), "../"+curdir+"/a")
             self.assertEqual(posixpath.relpath("a/b", "../c"), "../"+curdir+"/a/b")
             self.assertEqual(posixpath.relpath("a", "b/c"), "../../a")
+            self.assertEqual(posixpath.relpath("a", "a"), ".")
         finally:
             os.getcwd = real_getcwd
 

Modified: python/branches/py3k-importlib/Lib/test/test_pprint.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_pprint.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_pprint.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,7 @@
 import pprint
 import test.test_support
 import unittest
+import test.test_set
 
 # list, tuple and dict subclasses that do or don't overwrite __repr__
 class list2(list):
@@ -189,6 +190,197 @@
  others.should.not.be: like.this}"""
         self.assertEqual(DottedPrettyPrinter().pformat(o), exp)
 
+    def test_set_reprs(self):
+        self.assertEqual(pprint.pformat(set()), 'set()')
+        self.assertEqual(pprint.pformat(set(range(3))), '{0, 1, 2}')
+        self.assertEqual(pprint.pformat(frozenset()), 'frozenset()')
+        self.assertEqual(pprint.pformat(frozenset(range(3))), 'frozenset({0, 1, 2})')
+        cube_repr_tgt = """\
+{frozenset(): frozenset({frozenset({2}), frozenset({0}), frozenset({1})}),
+ frozenset({0}): frozenset({frozenset(),
+                            frozenset({0, 2}),
+                            frozenset({0, 1})}),
+ frozenset({1}): frozenset({frozenset(),
+                            frozenset({1, 2}),
+                            frozenset({0, 1})}),
+ frozenset({2}): frozenset({frozenset(),
+                            frozenset({1, 2}),
+                            frozenset({0, 2})}),
+ frozenset({1, 2}): frozenset({frozenset({2}),
+                               frozenset({1}),
+                               frozenset({0, 1, 2})}),
+ frozenset({0, 2}): frozenset({frozenset({2}),
+                               frozenset({0}),
+                               frozenset({0, 1, 2})}),
+ frozenset({0, 1}): frozenset({frozenset({0}),
+                               frozenset({1}),
+                               frozenset({0, 1, 2})}),
+ frozenset({0, 1, 2}): frozenset({frozenset({1, 2}),
+                                  frozenset({0, 2}),
+                                  frozenset({0, 1})})}"""
+        cube = test.test_set.cube(3)
+        self.assertEqual(pprint.pformat(cube), cube_repr_tgt)
+        cubo_repr_tgt = """\
+{frozenset({frozenset({0, 2}), frozenset({0})}): frozenset({frozenset({frozenset({0,
+                                                                                  2}),
+                                                                       frozenset({0,
+                                                                                  1,
+                                                                                  2})}),
+                                                            frozenset({frozenset({0}),
+                                                                       frozenset({0,
+                                                                                  1})}),
+                                                            frozenset({frozenset(),
+                                                                       frozenset({0})}),
+                                                            frozenset({frozenset({2}),
+                                                                       frozenset({0,
+                                                                                  2})})}),
+ frozenset({frozenset({0, 1}), frozenset({1})}): frozenset({frozenset({frozenset({0,
+                                                                                  1}),
+                                                                       frozenset({0,
+                                                                                  1,
+                                                                                  2})}),
+                                                            frozenset({frozenset({0}),
+                                                                       frozenset({0,
+                                                                                  1})}),
+                                                            frozenset({frozenset({1}),
+                                                                       frozenset({1,
+                                                                                  2})}),
+                                                            frozenset({frozenset(),
+                                                                       frozenset({1})})}),
+ frozenset({frozenset({1, 2}), frozenset({1})}): frozenset({frozenset({frozenset({1,
+                                                                                  2}),
+                                                                       frozenset({0,
+                                                                                  1,
+                                                                                  2})}),
+                                                            frozenset({frozenset({2}),
+                                                                       frozenset({1,
+                                                                                  2})}),
+                                                            frozenset({frozenset(),
+                                                                       frozenset({1})}),
+                                                            frozenset({frozenset({1}),
+                                                                       frozenset({0,
+                                                                                  1})})}),
+ frozenset({frozenset({1, 2}), frozenset({2})}): frozenset({frozenset({frozenset({1,
+                                                                                  2}),
+                                                                       frozenset({0,
+                                                                                  1,
+                                                                                  2})}),
+                                                            frozenset({frozenset({1}),
+                                                                       frozenset({1,
+                                                                                  2})}),
+                                                            frozenset({frozenset({2}),
+                                                                       frozenset({0,
+                                                                                  2})}),
+                                                            frozenset({frozenset(),
+                                                                       frozenset({2})})}),
+ frozenset({frozenset(), frozenset({0})}): frozenset({frozenset({frozenset({0}),
+                                                                 frozenset({0,
+                                                                            1})}),
+                                                      frozenset({frozenset({0}),
+                                                                 frozenset({0,
+                                                                            2})}),
+                                                      frozenset({frozenset(),
+                                                                 frozenset({1})}),
+                                                      frozenset({frozenset(),
+                                                                 frozenset({2})})}),
+ frozenset({frozenset(), frozenset({1})}): frozenset({frozenset({frozenset(),
+                                                                 frozenset({0})}),
+                                                      frozenset({frozenset({1}),
+                                                                 frozenset({1,
+                                                                            2})}),
+                                                      frozenset({frozenset(),
+                                                                 frozenset({2})}),
+                                                      frozenset({frozenset({1}),
+                                                                 frozenset({0,
+                                                                            1})})}),
+ frozenset({frozenset({2}), frozenset()}): frozenset({frozenset({frozenset({2}),
+                                                                 frozenset({1,
+                                                                            2})}),
+                                                      frozenset({frozenset(),
+                                                                 frozenset({0})}),
+                                                      frozenset({frozenset(),
+                                                                 frozenset({1})}),
+                                                      frozenset({frozenset({2}),
+                                                                 frozenset({0,
+                                                                            2})})}),
+ frozenset({frozenset({0, 1, 2}), frozenset({0, 1})}): frozenset({frozenset({frozenset({1,
+                                                                                        2}),
+                                                                             frozenset({0,
+                                                                                        1,
+                                                                                        2})}),
+                                                                  frozenset({frozenset({0,
+                                                                                        2}),
+                                                                             frozenset({0,
+                                                                                        1,
+                                                                                        2})}),
+                                                                  frozenset({frozenset({0}),
+                                                                             frozenset({0,
+                                                                                        1})}),
+                                                                  frozenset({frozenset({1}),
+                                                                             frozenset({0,
+                                                                                        1})})}),
+ frozenset({frozenset({0}), frozenset({0, 1})}): frozenset({frozenset({frozenset(),
+                                                                       frozenset({0})}),
+                                                            frozenset({frozenset({0,
+                                                                                  1}),
+                                                                       frozenset({0,
+                                                                                  1,
+                                                                                  2})}),
+                                                            frozenset({frozenset({0}),
+                                                                       frozenset({0,
+                                                                                  2})}),
+                                                            frozenset({frozenset({1}),
+                                                                       frozenset({0,
+                                                                                  1})})}),
+ frozenset({frozenset({2}), frozenset({0, 2})}): frozenset({frozenset({frozenset({0,
+                                                                                  2}),
+                                                                       frozenset({0,
+                                                                                  1,
+                                                                                  2})}),
+                                                            frozenset({frozenset({2}),
+                                                                       frozenset({1,
+                                                                                  2})}),
+                                                            frozenset({frozenset({0}),
+                                                                       frozenset({0,
+                                                                                  2})}),
+                                                            frozenset({frozenset(),
+                                                                       frozenset({2})})}),
+ frozenset({frozenset({0, 1, 2}), frozenset({0, 2})}): frozenset({frozenset({frozenset({1,
+                                                                                        2}),
+                                                                             frozenset({0,
+                                                                                        1,
+                                                                                        2})}),
+                                                                  frozenset({frozenset({0,
+                                                                                        1}),
+                                                                             frozenset({0,
+                                                                                        1,
+                                                                                        2})}),
+                                                                  frozenset({frozenset({0}),
+                                                                             frozenset({0,
+                                                                                        2})}),
+                                                                  frozenset({frozenset({2}),
+                                                                             frozenset({0,
+                                                                                        2})})}),
+ frozenset({frozenset({1, 2}), frozenset({0, 1, 2})}): frozenset({frozenset({frozenset({0,
+                                                                                        2}),
+                                                                             frozenset({0,
+                                                                                        1,
+                                                                                        2})}),
+                                                                  frozenset({frozenset({0,
+                                                                                        1}),
+                                                                             frozenset({0,
+                                                                                        1,
+                                                                                        2})}),
+                                                                  frozenset({frozenset({2}),
+                                                                             frozenset({1,
+                                                                                        2})}),
+                                                                  frozenset({frozenset({1}),
+                                                                             frozenset({1,
+                                                                                        2})})})}"""
+
+        cubo = test.test_set.linegraph(cube)
+        self.assertEqual(pprint.pformat(cubo), cubo_repr_tgt)
+
 
 class DottedPrettyPrinter(pprint.PrettyPrinter):
 

Modified: python/branches/py3k-importlib/Lib/test/test_profile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_profile.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_profile.py	Thu Mar 27 00:48:05 2008
@@ -1,123 +1,133 @@
 """Test suite for the profile module."""
 
-import profile, pstats, sys
+import os
+import sys
+import pstats
+import unittest
+from difflib import unified_diff
+from io import StringIO
+from test.test_support import run_unittest
+
+import profile
+from test.profilee import testfunc, timer
+
+
+class ProfileTest(unittest.TestCase):
+
+    profilerclass = profile.Profile
+    methodnames = ['print_stats', 'print_callers', 'print_callees']
+    expected_output = {}
+
+    @classmethod
+    def do_profiling(cls):
+        results = []
+        prof = cls.profilerclass(timer, 0.001)
+        prof.runctx("testfunc()", globals(), locals())
+        results.append(timer())
+        for methodname in cls.methodnames:
+            s = StringIO()
+            stats = pstats.Stats(prof, stream=s)
+            stats.strip_dirs().sort_stats("stdname")
+            getattr(stats, methodname)()
+            output = s.getvalue().splitlines()
+            mod_name = testfunc.__module__.rsplit('.', 1)[1]
+            # Only compare against stats originating from the test file.
+            # Prevents outside code (e.g., the io module) from causing
+            # unexpected output.
+            output = [line.rstrip() for line in output if mod_name in line]
+            results.append('\n'.join(output))
+        return results
+
+    def test_cprofile(self):
+        results = self.do_profiling()
+        self.assertEqual(results[0], 43000)
+        for i, method in enumerate(self.methodnames):
+            if results[i+1] != self.expected_output[method]:
+                print("Stats.%s output for %s doesn't fit expectation!" %
+                      (method, self.profilerclass.__name__))
+                print('\n'.join(unified_diff(
+                                  results[i+1].split('\n'),
+                                  self.expected_output[method].split('\n'))))
+
+
+def regenerate_expected_output(filename, cls):
+    filename = filename.rstrip('co')
+    print('Regenerating %s...' % filename)
+    results = cls.do_profiling()
+
+    newfile = []
+    with open(filename, 'r') as f:
+        for line in f:
+            newfile.append(line)
+            if line.startswith('#--cut'):
+                break
+
+    with open(filename, 'w') as f:
+        f.writelines(newfile)
+        for i, method in enumerate(cls.methodnames):
+            f.write('%s.expected_output[%r] = """\\\n%s"""\n' % (
+                cls.__name__, method, results[i+1]))
+        f.write('\nif __name__ == "__main__":\n    main()\n')
 
-# In order to have reproducible time, we simulate a timer in the global
-# variable 'ticks', which represents simulated time in milliseconds.
-# (We can't use a helper function increment the timer since it would be
-# included in the profile and would appear to consume all the time.)
-ticks = 0
-
-# IMPORTANT: this is an output test.  *ALL* NUMBERS in the expected
-# output are relevant.  If you change the formatting of pstats,
-# please don't just regenerate output/test_profile without checking
-# very carefully that not a single number has changed.
 
 def test_main():
-    global ticks
-    ticks = 42000
-    prof = profile.Profile(timer)
-    prof.runctx("testfunc()", globals(), locals())
-    assert ticks == 43000, ticks
-    st = pstats.Stats(prof)
-    st.strip_dirs().sort_stats('stdname').print_stats()
-    st.print_callees()
-    st.print_callers()
-
-def timer():
-    return ticks*0.001
-
-def testfunc():
-    # 1 call
-    # 1000 ticks total: 270 ticks local, 730 ticks in subfunctions
-    global ticks
-    ticks += 99
-    helper()                            # 300
-    helper()                            # 300
-    ticks += 171
-    factorial(14)                       # 130
-
-def factorial(n):
-    # 23 calls total
-    # 170 ticks total, 150 ticks local
-    # 3 primitive calls, 130, 20 and 20 ticks total
-    # including 116, 17, 17 ticks local
-    global ticks
-    if n > 0:
-        ticks += n
-        return mul(n, factorial(n-1))
+    run_unittest(ProfileTest)
+
+def main():
+    if '-r' not in sys.argv:
+        test_main()
     else:
-        ticks += 11
-        return 1
+        regenerate_expected_output(__file__, ProfileTest)
+
 
-def mul(a, b):
-    # 20 calls
-    # 1 tick, local
-    global ticks
-    ticks += 1
-    return a * b
-
-def helper():
-    # 2 calls
-    # 300 ticks total: 20 ticks local, 260 ticks in subfunctions
-    global ticks
-    ticks += 1
-    helper1()                           # 30
-    ticks += 2
-    helper1()                           # 30
-    ticks += 6
-    helper2()                           # 50
-    ticks += 3
-    helper2()                           # 50
-    ticks += 2
-    helper2()                           # 50
-    ticks += 5
-    helper2_indirect()                  # 70
-    ticks += 1
-
-def helper1():
-    # 4 calls
-    # 30 ticks total: 29 ticks local, 1 tick in subfunctions
-    global ticks
-    ticks += 10
-    hasattr(C(), "foo")                 # 1
-    ticks += 19
-    lst = []
-    lst.append(42)                      # 0
-    sys.exc_info()                      # 0
-
-def helper2_indirect():
-    helper2()                           # 50
-    factorial(3)                        # 20
-
-def helper2():
-    # 8 calls
-    # 50 ticks local: 39 ticks local, 11 ticks in subfunctions
-    global ticks
-    ticks += 11
-    hasattr(C(), "bar")                 # 1
-    ticks += 13
-    subhelper()                         # 10
-    ticks += 15
-
-def subhelper():
-    # 8 calls
-    # 10 ticks total: 8 ticks local, 2 ticks in subfunctions
-    global ticks
-    ticks += 2
-    for i in range(2):                  # 0
-        try:
-            C().foo                     # 1 x 2
-        except AttributeError:
-            ticks += 3                  # 3 x 2
-
-class C:
-    def __getattr__(self, name):
-        # 28 calls
-        # 1 tick, local
-        global ticks
-        ticks += 1
-        raise AttributeError
+# Don't remove this comment. Everything below it is auto-generated.
+#--cut--------------------------------------------------------------------------
+ProfileTest.expected_output['print_stats'] = """\
+       28   27.972    0.999   27.972    0.999 profilee.py:110(__getattr__)
+        1  269.996  269.996  999.769  999.769 profilee.py:25(testfunc)
+     23/3  149.937    6.519  169.917   56.639 profilee.py:35(factorial)
+       20   19.980    0.999   19.980    0.999 profilee.py:48(mul)
+        2   39.986   19.993  599.830  299.915 profilee.py:55(helper)
+        4  115.984   28.996  119.964   29.991 profilee.py:73(helper1)
+        2   -0.006   -0.003  139.946   69.973 profilee.py:84(helper2_indirect)
+        8  311.976   38.997  399.912   49.989 profilee.py:88(helper2)
+        8   63.976    7.997   79.960    9.995 profilee.py:98(subhelper)"""
+ProfileTest.expected_output['print_callers'] = """\
+:0(append)                        <- profilee.py:73(helper1)(4)  119.964
+:0(exc_info)                      <- profilee.py:73(helper1)(4)  119.964
+:0(hasattr)                       <- profilee.py:73(helper1)(4)  119.964
+                                     profilee.py:88(helper2)(8)  399.912
+profilee.py:110(__getattr__)      <- :0(hasattr)(12)   11.964
+                                     profilee.py:98(subhelper)(16)   79.960
+profilee.py:25(testfunc)          <- <string>:1(<module>)(1)  999.767
+profilee.py:35(factorial)         <- profilee.py:25(testfunc)(1)  999.769
+                                     profilee.py:35(factorial)(20)  169.917
+                                     profilee.py:84(helper2_indirect)(2)  139.946
+profilee.py:48(mul)               <- profilee.py:35(factorial)(20)  169.917
+profilee.py:55(helper)            <- profilee.py:25(testfunc)(2)  999.769
+profilee.py:73(helper1)           <- profilee.py:55(helper)(4)  599.830
+profilee.py:84(helper2_indirect)  <- profilee.py:55(helper)(2)  599.830
+profilee.py:88(helper2)           <- profilee.py:55(helper)(6)  599.830
+                                     profilee.py:84(helper2_indirect)(2)  139.946
+profilee.py:98(subhelper)         <- profilee.py:88(helper2)(8)  399.912"""
+ProfileTest.expected_output['print_callees'] = """\
+:0(hasattr)                       -> profilee.py:110(__getattr__)(12)   27.972
+<string>:1(<module>)              -> profilee.py:25(testfunc)(1)  999.769
+profilee.py:110(__getattr__)      ->
+profilee.py:25(testfunc)          -> profilee.py:35(factorial)(1)  169.917
+                                     profilee.py:55(helper)(2)  599.830
+profilee.py:35(factorial)         -> profilee.py:35(factorial)(20)  169.917
+                                     profilee.py:48(mul)(20)   19.980
+profilee.py:48(mul)               ->
+profilee.py:55(helper)            -> profilee.py:73(helper1)(4)  119.964
+                                     profilee.py:84(helper2_indirect)(2)  139.946
+                                     profilee.py:88(helper2)(6)  399.912
+profilee.py:73(helper1)           -> :0(append)(4)   -0.004
+profilee.py:84(helper2_indirect)  -> profilee.py:35(factorial)(2)  169.917
+                                     profilee.py:88(helper2)(2)  399.912
+profilee.py:88(helper2)           -> :0(hasattr)(8)   11.964
+                                     profilee.py:98(subhelper)(8)   79.960
+profilee.py:98(subhelper)         -> profilee.py:110(__getattr__)(16)   27.972"""
 
 if __name__ == "__main__":
-    test_main()
+    main()

Modified: python/branches/py3k-importlib/Lib/test/test_profilehooks.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_profilehooks.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_profilehooks.py	Thu Mar 27 00:48:05 2008
@@ -4,6 +4,22 @@
 
 from test import test_support
 
+class TestGetProfile(unittest.TestCase):
+    def setUp(self):
+        sys.setprofile(None)
+
+    def tearDown(self):
+        sys.setprofile(None)
+
+    def test_empty(self):
+        assert sys.getprofile() == None
+
+    def test_setget(self):
+        def fn(*args):
+            pass
+
+        sys.setprofile(fn)
+        assert sys.getprofile() == fn
 
 class HookWatcher:
     def __init__(self):
@@ -31,7 +47,7 @@
 
     def get_events(self):
         """Remove calls to add_event()."""
-        disallowed = [ident(self.add_event.im_func), ident(ident)]
+        disallowed = [ident(self.add_event.__func__), ident(ident)]
         self.frames = None
 
         return [item for item in self.events if item[2] not in disallowed]
@@ -359,6 +375,7 @@
 
 def test_main():
     test_support.run_unittest(
+        TestGetProfile,
         ProfileHookTestCase,
         ProfileSimulatorTestCase
     )

Modified: python/branches/py3k-importlib/Lib/test/test_pty.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_pty.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_pty.py	Thu Mar 27 00:48:05 2008
@@ -157,7 +157,8 @@
                     break
                 if not data:
                     break
-                sys.stdout.write(data.replace('\r\n', '\n').decode('ascii'))
+                sys.stdout.write(str(data.replace(b'\r\n', b'\n'),
+                                     encoding='ascii'))
 
             ##line = os.read(master_fd, 80)
             ##lines = line.replace('\r\n', '\n').split('\n')

Modified: python/branches/py3k-importlib/Lib/test/test_pwd.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_pwd.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_pwd.py	Thu Mar 27 00:48:05 2008
@@ -13,19 +13,19 @@
         for e in entries:
             self.assertEqual(len(e), 7)
             self.assertEqual(e[0], e.pw_name)
-            self.assert_(isinstance(e.pw_name, basestring))
+            self.assert_(isinstance(e.pw_name, str))
             self.assertEqual(e[1], e.pw_passwd)
-            self.assert_(isinstance(e.pw_passwd, basestring))
+            self.assert_(isinstance(e.pw_passwd, str))
             self.assertEqual(e[2], e.pw_uid)
             self.assert_(isinstance(e.pw_uid, int))
             self.assertEqual(e[3], e.pw_gid)
             self.assert_(isinstance(e.pw_gid, int))
             self.assertEqual(e[4], e.pw_gecos)
-            self.assert_(isinstance(e.pw_gecos, basestring))
+            self.assert_(isinstance(e.pw_gecos, str))
             self.assertEqual(e[5], e.pw_dir)
-            self.assert_(isinstance(e.pw_dir, basestring))
+            self.assert_(isinstance(e.pw_dir, str))
             self.assertEqual(e[6], e.pw_shell)
-            self.assert_(isinstance(e.pw_shell, basestring))
+            self.assert_(isinstance(e.pw_shell, str))
 
             # The following won't work, because of duplicate entries
             # for one uid
@@ -35,6 +35,9 @@
             entriesbyname.setdefault(e.pw_name, []).append(e)
             entriesbyuid.setdefault(e.pw_uid, []).append(e)
 
+        if len(entries) > 1000:  # Huge passwd file (NIS?) -- skip the rest
+            return
+
         # check whether the entry returned by getpwuid()
         # for each uid is among those from getpwall() for this uid
         for e in entries:

Modified: python/branches/py3k-importlib/Lib/test/test_pyclbr.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_pyclbr.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_pyclbr.py	Thu Mar 27 00:48:05 2008
@@ -3,7 +3,7 @@
    Nick Mathewson
 '''
 from test.test_support import run_unittest
-import unittest, sys
+import sys
 from types import FunctionType, MethodType, BuiltinFunctionType
 import pyclbr
 from unittest import TestCase
@@ -40,7 +40,7 @@
         if key in ignore: return
         if key not in obj:
             print("***",key, file=sys.stderr)
-        self.failUnless(key in obj)
+        self.failUnless(key in obj, "%r in %r" % (key, obj))
 
     def assertEqualsOrIgnored(self, a, b, ignore):
         ''' succeed iff a == b or a in ignore or b in ignore '''
@@ -64,23 +64,17 @@
 
         def ismethod(oclass, obj, name):
             classdict = oclass.__dict__
-            if isinstance(obj, FunctionType):
-                if not isinstance(classdict[name], StaticMethodType):
+            if isinstance(obj, MethodType):
+                # could be a classmethod
+                if (not isinstance(classdict[name], ClassMethodType) or
+                    obj.__self__ is not oclass):
                     return False
-            else:
-                if not  isinstance(obj, MethodType):
-                    return False
-                if obj.im_self is not None:
-                    if (not isinstance(classdict[name], ClassMethodType) or
-                        obj.im_self is not oclass):
-                        return False
-                else:
-                    if not isinstance(classdict[name], FunctionType):
-                        return False
+            elif not isinstance(obj, FunctionType):
+                return False
 
             objname = obj.__name__
             if objname.startswith("__") and not objname.endswith("__"):
-                objname = "_%s%s" % (obj.im_class.__name__, objname)
+                objname = "_%s%s" % (oclass.__name__, objname)
             return objname == name
 
         # Make sure the toplevel functions and classes are the same.
@@ -146,15 +140,15 @@
 
     def test_easy(self):
         self.checkModule('pyclbr')
-        self.checkModule('doctest')
+        self.checkModule('doctest', ignore=("TestResults",))
         self.checkModule('rfc822')
-        self.checkModule('difflib')
+        self.checkModule('difflib', ignore=("Match",))
 
     def test_decorators(self):
         # XXX: See comment in pyclbr_input.py for a test that would fail
         #      if it were not commented out.
         #
-        self.checkModule('test.pyclbr_input')
+        self.checkModule('test.pyclbr_input', ignore=['om'])
 
     def test_others(self):
         cm = self.checkModule
@@ -164,6 +158,7 @@
         cm('cgi', ignore=('log',))      # set with = in module
         cm('mhlib')
         cm('urllib', ignore=('getproxies_registry',
+                             'proxy_bypass_registry',
                              'open_https',
                              '_https_connection',
                              'getproxies_internetconfig',)) # not on all platforms

Modified: python/branches/py3k-importlib/Lib/test/test_pyexpat.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_pyexpat.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_pyexpat.py	Thu Mar 27 00:48:05 2008
@@ -2,6 +2,7 @@
 # handler, are obscure and unhelpful.
 
 from io import BytesIO
+import sys
 import unittest
 
 import pyexpat
@@ -385,6 +386,130 @@
 
         self.assertRaises(Exception, parser.Parse, xml)
 
+class ChardataBufferTest(unittest.TestCase):
+    """
+    test setting of chardata buffer size
+    """
+
+    def test_1025_bytes(self):
+        self.assertEquals(self.small_buffer_test(1025), 2)
+
+    def test_1000_bytes(self):
+        self.assertEquals(self.small_buffer_test(1000), 1)
+
+    def test_wrong_size(self):
+        parser = expat.ParserCreate()
+        parser.buffer_text = 1
+        def f(size):
+            parser.buffer_size = size
+
+        self.assertRaises(ValueError, f, -1)
+        self.assertRaises(ValueError, f, 0)
+
+    def test_unchanged_size(self):
+        xml1 = ("<?xml version='1.0' encoding='iso8859'?><s>%s" % ('a' * 512))
+        xml2 = 'a'*512 + '</s>'
+        parser = expat.ParserCreate()
+        parser.CharacterDataHandler = self.counting_handler
+        parser.buffer_size = 512
+        parser.buffer_text = 1
+
+        # Feed 512 bytes of character data: the handler should be called
+        # once.
+        self.n = 0
+        parser.Parse(xml1)
+        self.assertEquals(self.n, 1)
+
+        # Reassign to buffer_size, but assign the same size.
+        parser.buffer_size = parser.buffer_size
+        self.assertEquals(self.n, 1)
+
+        # Try parsing rest of the document
+        parser.Parse(xml2)
+        self.assertEquals(self.n, 2)
+
+
+    def test_disabling_buffer(self):
+        xml1 = "<?xml version='1.0' encoding='iso8859'?><a>%s" % ('a' * 512)
+        xml2 = ('b' * 1024)
+        xml3 = "%s</a>" % ('c' * 1024)
+        parser = expat.ParserCreate()
+        parser.CharacterDataHandler = self.counting_handler
+        parser.buffer_text = 1
+        parser.buffer_size = 1024
+        self.assertEquals(parser.buffer_size, 1024)
+
+        # Parse one chunk of XML
+        self.n = 0
+        parser.Parse(xml1, 0)
+        self.assertEquals(parser.buffer_size, 1024)
+        self.assertEquals(self.n, 1)
+
+        # Turn off buffering and parse the next chunk.
+        parser.buffer_text = 0
+        self.assertFalse(parser.buffer_text)
+        self.assertEquals(parser.buffer_size, 1024)
+        for i in range(10):
+            parser.Parse(xml2, 0)
+        self.assertEquals(self.n, 11)
+
+        parser.buffer_text = 1
+        self.assertTrue(parser.buffer_text)
+        self.assertEquals(parser.buffer_size, 1024)
+        parser.Parse(xml3, 1)
+        self.assertEquals(self.n, 12)
+
+
+
+    def make_document(self, bytes):
+        return ("<?xml version='1.0'?><tag>" + bytes * 'a' + '</tag>')
+
+    def counting_handler(self, text):
+        self.n += 1
+
+    def small_buffer_test(self, buffer_len):
+        xml = "<?xml version='1.0' encoding='iso8859'?><s>%s</s>" % ('a' * buffer_len)
+        parser = expat.ParserCreate()
+        parser.CharacterDataHandler = self.counting_handler
+        parser.buffer_size = 1024
+        parser.buffer_text = 1
+
+        self.n = 0
+        parser.Parse(xml)
+        return self.n
+
+    def test_change_size_1(self):
+        xml1 = "<?xml version='1.0' encoding='iso8859'?><a><s>%s" % ('a' * 1024)
+        xml2 = "aaa</s><s>%s</s></a>" % ('a' * 1025)
+        parser = expat.ParserCreate()
+        parser.CharacterDataHandler = self.counting_handler
+        parser.buffer_text = 1
+        parser.buffer_size = 1024
+        self.assertEquals(parser.buffer_size, 1024)
+
+        self.n = 0
+        parser.Parse(xml1, 0)
+        parser.buffer_size *= 2
+        self.assertEquals(parser.buffer_size, 2048)
+        parser.Parse(xml2, 1)
+        self.assertEquals(self.n, 2)
+
+    def test_change_size_2(self):
+        xml1 = "<?xml version='1.0' encoding='iso8859'?><a>a<s>%s" % ('a' * 1023)
+        xml2 = "aaa</s><s>%s</s></a>" % ('a' * 1025)
+        parser = expat.ParserCreate()
+        parser.CharacterDataHandler = self.counting_handler
+        parser.buffer_text = 1
+        parser.buffer_size = 2048
+        self.assertEquals(parser.buffer_size, 2048)
+
+        self.n=0
+        parser.Parse(xml1, 0)
+        parser.buffer_size = parser.buffer_size // 2
+        self.assertEquals(parser.buffer_size, 1024)
+        parser.Parse(xml2, 1)
+        self.assertEquals(self.n, 4)
+
 
 def test_main():
     run_unittest(SetAttributeTest,
@@ -394,7 +519,8 @@
                  BufferTextTest,
                  HandlerExceptionTest,
                  PositionTest,
-                 sf1296433Test)
+                 sf1296433Test,
+                 ChardataBufferTest)
 
 if __name__ == "__main__":
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_queue.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_queue.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_queue.py	Thu Mar 27 00:48:05 2008
@@ -4,11 +4,14 @@
 import sys
 import threading
 import time
-
-from test.test_support import verify, TestFailed, verbose
+import unittest
+from test import test_support
 
 QUEUE_SIZE = 5
 
+def qfull(q):
+    return q.maxsize > 0 and q.qsize() == q.maxsize
+
 # A thread to run a function that unclogs a blocked Queue.
 class _TriggerThread(threading.Thread):
     def __init__(self, fn, args):
@@ -30,50 +33,177 @@
         self.startedEvent.set()
         self.fn(*self.args)
 
+
 # Execute a function that blocks, and in a separate thread, a function that
-# triggers the release.  Returns the result of the blocking function.
-# Caution:  block_func must guarantee to block until trigger_func is
-# called, and trigger_func must guarantee to change queue state so that
-# block_func can make enough progress to return.  In particular, a
-# block_func that just raises an exception regardless of whether trigger_func
-# is called will lead to timing-dependent sporadic failures, and one of
-# those went rarely seen but undiagnosed for years.  Now block_func
-# must be unexceptional.  If block_func is supposed to raise an exception,
-# call _doExceptionalBlockingTest() instead.
-def _doBlockingTest(block_func, block_args, trigger_func, trigger_args):
-    t = _TriggerThread(trigger_func, trigger_args)
-    t.start()
-    result = block_func(*block_args)
-    # If block_func returned before our thread made the call, we failed!
-    if not t.startedEvent.isSet():
-        raise TestFailed("blocking function '%r' appeared not to block" %
-                         block_func)
-    t.join(10) # make sure the thread terminates
-    if t.isAlive():
-        raise TestFailed("trigger function '%r' appeared to not return" %
-                         trigger_func)
-    return result
-
-# Call this instead if block_func is supposed to raise an exception.
-def _doExceptionalBlockingTest(block_func, block_args, trigger_func,
-                               trigger_args, expected_exception_class):
-    t = _TriggerThread(trigger_func, trigger_args)
-    t.start()
-    try:
-        try:
-            block_func(*block_args)
-        except expected_exception_class:
-            raise
+# triggers the release.  Returns the result of the blocking function.  Caution:
+# block_func must guarantee to block until trigger_func is called, and
+# trigger_func must guarantee to change queue state so that block_func can make
+# enough progress to return.  In particular, a block_func that just raises an
+# exception regardless of whether trigger_func is called will lead to
+# timing-dependent sporadic failures, and one of those went rarely seen but
+# undiagnosed for years.  Now block_func must be unexceptional.  If block_func
+# is supposed to raise an exception, call do_exceptional_blocking_test()
+# instead.
+
+class BlockingTestMixin:
+
+    def do_blocking_test(self, block_func, block_args, trigger_func, trigger_args):
+        self.t = _TriggerThread(trigger_func, trigger_args)
+        self.t.start()
+        self.result = block_func(*block_args)
+        # If block_func returned before our thread made the call, we failed!
+        if not self.t.startedEvent.isSet():
+            self.fail("blocking function '%r' appeared not to block" %
+                      block_func)
+        self.t.join(10) # make sure the thread terminates
+        if self.t.isAlive():
+            self.fail("trigger function '%r' appeared to not return" %
+                      trigger_func)
+        return self.result
+
+    # Call this instead if block_func is supposed to raise an exception.
+    def do_exceptional_blocking_test(self,block_func, block_args, trigger_func,
+                                   trigger_args, expected_exception_class):
+        self.t = _TriggerThread(trigger_func, trigger_args)
+        self.t.start()
+        try:
+            try:
+                block_func(*block_args)
+            except expected_exception_class:
+                raise
+            else:
+                self.fail("expected exception of kind %r" %
+                                 expected_exception_class)
+        finally:
+            self.t.join(10) # make sure the thread terminates
+            if self.t.isAlive():
+                self.fail("trigger function '%r' appeared to not return" %
+                                 trigger_func)
+            if not self.t.startedEvent.isSet():
+                self.fail("trigger thread ended but event never set")
+
+
+class BaseQueueTest(unittest.TestCase, BlockingTestMixin):
+    def setUp(self):
+        self.cum = 0
+        self.cumlock = threading.Lock()
+
+    def simple_queue_test(self, q):
+        if q.qsize():
+            raise RuntimeError("Call this function with an empty queue")
+        # I guess we better check things actually queue correctly a little :)
+        q.put(111)
+        q.put(333)
+        q.put(222)
+        target_order = dict(Queue = [111, 333, 222],
+                            LifoQueue = [222, 333, 111],
+                            PriorityQueue = [111, 222, 333])
+        actual_order = [q.get(), q.get(), q.get()]
+        self.assertEquals(actual_order, target_order[q.__class__.__name__],
+                          "Didn't seem to queue the correct data!")
+        for i in range(QUEUE_SIZE-1):
+            q.put(i)
+            self.assert_(q.qsize(), "Queue should not be empty")
+        self.assert_(not qfull(q), "Queue should not be full")
+        last = 2 * QUEUE_SIZE
+        full = 3 * 2 * QUEUE_SIZE
+        q.put(last)
+        self.assert_(qfull(q), "Queue should be full")
+        try:
+            q.put(full, block=0)
+            self.fail("Didn't appear to block with a full queue")
+        except Queue.Full:
+            pass
+        try:
+            q.put(full, timeout=0.01)
+            self.fail("Didn't appear to time-out with a full queue")
+        except Queue.Full:
+            pass
+        # Test a blocking put
+        self.do_blocking_test(q.put, (full,), q.get, ())
+        self.do_blocking_test(q.put, (full, True, 10), q.get, ())
+        # Empty it
+        for i in range(QUEUE_SIZE):
+            q.get()
+        self.assert_(not q.qsize(), "Queue should be empty")
+        try:
+            q.get(block=0)
+            self.fail("Didn't appear to block with an empty queue")
+        except Queue.Empty:
+            pass
+        try:
+            q.get(timeout=0.01)
+            self.fail("Didn't appear to time-out with an empty queue")
+        except Queue.Empty:
+            pass
+        # Test a blocking get
+        self.do_blocking_test(q.get, (), q.put, ('empty',))
+        self.do_blocking_test(q.get, (True, 10), q.put, ('empty',))
+
+
+    def worker(self, q):
+        while True:
+            x = q.get()
+            if x is None:
+                q.task_done()
+                return
+            with self.cumlock:
+                self.cum += x
+            q.task_done()
+
+    def queue_join_test(self, q):
+        self.cum = 0
+        for i in (0,1):
+            threading.Thread(target=self.worker, args=(q,)).start()
+        for i in range(100):
+            q.put(i)
+        q.join()
+        self.assertEquals(self.cum, sum(range(100)),
+                          "q.join() did not block until all tasks were done")
+        q.put(None)         # instruct the threads to close
+        q.join()                # verify that you can join twice
+
+    def test_queue_task_done(self):
+        # Test to make sure a queue task completed successfully.
+        q = self.type2test()
+        try:
+            q.task_done()
+        except ValueError:
+            pass
         else:
-            raise TestFailed("expected exception of kind %r" %
-                             expected_exception_class)
-    finally:
-        t.join(10) # make sure the thread terminates
-        if t.isAlive():
-            raise TestFailed("trigger function '%r' appeared to not return" %
-                             trigger_func)
-        if not t.startedEvent.isSet():
-            raise TestFailed("trigger thread ended but event never set")
+            self.fail("Did not detect task count going negative")
+
+    def test_queue_join(self):
+        # Test that a queue join()s successfully, and before anything else
+        # (done twice for insurance).
+        q = self.type2test()
+        self.queue_join_test(q)
+        self.queue_join_test(q)
+        try:
+            q.task_done()
+        except ValueError:
+            pass
+        else:
+            self.fail("Did not detect task count going negative")
+
+    def test_simple_queue(self):
+        # Do it a couple of times on the same queue.
+        # Done twice to make sure works with same instance reused.
+        q = self.type2test(QUEUE_SIZE)
+        self.simple_queue_test(q)
+        self.simple_queue_test(q)
+
+
+class QueueTest(BaseQueueTest):
+    type2test = Queue.Queue
+
+class LifoQueueTest(BaseQueueTest):
+    type2test = Queue.LifoQueue
+
+class PriorityQueueTest(BaseQueueTest):
+    type2test = Queue.PriorityQueue
+
+
 
 # A Queue subclass that can provoke failure at a moment's notice :)
 class FailingQueueException(Exception):
@@ -95,187 +225,101 @@
             raise FailingQueueException("You Lose")
         return Queue.Queue._get(self)
 
-def FailingQueueTest(q):
-    if not q.empty():
-        raise RuntimeError("Call this function with an empty queue")
-    for i in range(QUEUE_SIZE-1):
-        q.put(i)
-    # Test a failing non-blocking put.
-    q.fail_next_put = True
-    try:
-        q.put("oops", block=0)
-        raise TestFailed("The queue didn't fail when it should have")
-    except FailingQueueException:
-        pass
-    q.fail_next_put = True
-    try:
-        q.put("oops", timeout=0.1)
-        raise TestFailed("The queue didn't fail when it should have")
-    except FailingQueueException:
-        pass
-    q.put("last")
-    verify(q.full(), "Queue should be full")
-    # Test a failing blocking put
-    q.fail_next_put = True
-    try:
-        _doBlockingTest(q.put, ("full",), q.get, ())
-        raise TestFailed("The queue didn't fail when it should have")
-    except FailingQueueException:
-        pass
-    # Check the Queue isn't damaged.
-    # put failed, but get succeeded - re-add
-    q.put("last")
-    # Test a failing timeout put
-    q.fail_next_put = True
-    try:
-        _doExceptionalBlockingTest(q.put, ("full", True, 10), q.get, (),
-                                   FailingQueueException)
-        raise TestFailed("The queue didn't fail when it should have")
-    except FailingQueueException:
-        pass
-    # Check the Queue isn't damaged.
-    # put failed, but get succeeded - re-add
-    q.put("last")
-    verify(q.full(), "Queue should be full")
-    q.get()
-    verify(not q.full(), "Queue should not be full")
-    q.put("last")
-    verify(q.full(), "Queue should be full")
-    # Test a blocking put
-    _doBlockingTest( q.put, ("full",), q.get, ())
-    # Empty it
-    for i in range(QUEUE_SIZE):
-        q.get()
-    verify(q.empty(), "Queue should be empty")
-    q.put("first")
-    q.fail_next_get = True
-    try:
+class FailingQueueTest(unittest.TestCase, BlockingTestMixin):
+
+    def failing_queue_test(self, q):
+        if q.qsize():
+            raise RuntimeError("Call this function with an empty queue")
+        for i in range(QUEUE_SIZE-1):
+            q.put(i)
+        # Test a failing non-blocking put.
+        q.fail_next_put = True
+        try:
+            q.put("oops", block=0)
+            self.fail("The queue didn't fail when it should have")
+        except FailingQueueException:
+            pass
+        q.fail_next_put = True
+        try:
+            q.put("oops", timeout=0.1)
+            self.fail("The queue didn't fail when it should have")
+        except FailingQueueException:
+            pass
+        q.put("last")
+        self.assert_(qfull(q), "Queue should be full")
+        # Test a failing blocking put
+        q.fail_next_put = True
+        try:
+            self.do_blocking_test(q.put, ("full",), q.get, ())
+            self.fail("The queue didn't fail when it should have")
+        except FailingQueueException:
+            pass
+        # Check the Queue isn't damaged.
+        # put failed, but get succeeded - re-add
+        q.put("last")
+        # Test a failing timeout put
+        q.fail_next_put = True
+        try:
+            self.do_exceptional_blocking_test(q.put, ("full", True, 10), q.get, (),
+                                              FailingQueueException)
+            self.fail("The queue didn't fail when it should have")
+        except FailingQueueException:
+            pass
+        # Check the Queue isn't damaged.
+        # put failed, but get succeeded - re-add
+        q.put("last")
+        self.assert_(qfull(q), "Queue should be full")
         q.get()
-        raise TestFailed("The queue didn't fail when it should have")
-    except FailingQueueException:
-        pass
-    verify(not q.empty(), "Queue should not be empty")
-    q.fail_next_get = True
-    try:
-        q.get(timeout=0.1)
-        raise TestFailed("The queue didn't fail when it should have")
-    except FailingQueueException:
-        pass
-    verify(not q.empty(), "Queue should not be empty")
-    q.get()
-    verify(q.empty(), "Queue should be empty")
-    q.fail_next_get = True
-    try:
-        _doExceptionalBlockingTest(q.get, (), q.put, ('empty',),
-                                   FailingQueueException)
-        raise TestFailed("The queue didn't fail when it should have")
-    except FailingQueueException:
-        pass
-    # put succeeded, but get failed.
-    verify(not q.empty(), "Queue should not be empty")
-    q.get()
-    verify(q.empty(), "Queue should be empty")
-
-def SimpleQueueTest(q):
-    if not q.empty():
-        raise RuntimeError("Call this function with an empty queue")
-    # I guess we better check things actually queue correctly a little :)
-    q.put(111)
-    q.put(222)
-    verify(q.get() == 111 and q.get() == 222,
-           "Didn't seem to queue the correct data!")
-    for i in range(QUEUE_SIZE-1):
-        q.put(i)
-        verify(not q.empty(), "Queue should not be empty")
-    verify(not q.full(), "Queue should not be full")
-    q.put("last")
-    verify(q.full(), "Queue should be full")
-    try:
-        q.put("full", block=0)
-        raise TestFailed("Didn't appear to block with a full queue")
-    except Queue.Full:
-        pass
-    try:
-        q.put("full", timeout=0.01)
-        raise TestFailed("Didn't appear to time-out with a full queue")
-    except Queue.Full:
-        pass
-    # Test a blocking put
-    _doBlockingTest(q.put, ("full",), q.get, ())
-    _doBlockingTest(q.put, ("full", True, 10), q.get, ())
-    # Empty it
-    for i in range(QUEUE_SIZE):
+        self.assert_(not qfull(q), "Queue should not be full")
+        q.put("last")
+        self.assert_(qfull(q), "Queue should be full")
+        # Test a blocking put
+        self.do_blocking_test(q.put, ("full",), q.get, ())
+        # Empty it
+        for i in range(QUEUE_SIZE):
+            q.get()
+        self.assert_(not q.qsize(), "Queue should be empty")
+        q.put("first")
+        q.fail_next_get = True
+        try:
+            q.get()
+            self.fail("The queue didn't fail when it should have")
+        except FailingQueueException:
+            pass
+        self.assert_(q.qsize(), "Queue should not be empty")
+        q.fail_next_get = True
+        try:
+            q.get(timeout=0.1)
+            self.fail("The queue didn't fail when it should have")
+        except FailingQueueException:
+            pass
+        self.assert_(q.qsize(), "Queue should not be empty")
         q.get()
-    verify(q.empty(), "Queue should be empty")
-    try:
-        q.get(block=0)
-        raise TestFailed("Didn't appear to block with an empty queue")
-    except Queue.Empty:
-        pass
-    try:
-        q.get(timeout=0.01)
-        raise TestFailed("Didn't appear to time-out with an empty queue")
-    except Queue.Empty:
-        pass
-    # Test a blocking get
-    _doBlockingTest(q.get, (), q.put, ('empty',))
-    _doBlockingTest(q.get, (True, 10), q.put, ('empty',))
-
-cum = 0
-cumlock = threading.Lock()
-
-def worker(q):
-    global cum
-    while True:
-        x = q.get()
-        if x is None:
-            q.task_done()
-            return
-        cumlock.acquire()
+        self.assert_(not q.qsize(), "Queue should be empty")
+        q.fail_next_get = True
         try:
-            cum += x
-        finally:
-            cumlock.release()
-        q.task_done()
+            self.do_exceptional_blocking_test(q.get, (), q.put, ('empty',),
+                                              FailingQueueException)
+            self.fail("The queue didn't fail when it should have")
+        except FailingQueueException:
+            pass
+        # put succeeded, but get failed.
+        self.assert_(q.qsize(), "Queue should not be empty")
+        q.get()
+        self.assert_(not q.qsize(), "Queue should be empty")
 
-def QueueJoinTest(q):
-    global cum
-    cum = 0
-    for i in (0,1):
-        threading.Thread(target=worker, args=(q,)).start()
-    for i in range(100):
-        q.put(i)
-    q.join()
-    verify(cum==sum(range(100)), "q.join() did not block until all tasks were done")
-    for i in (0,1):
-        q.put(None)         # instruct the threads to close
-    q.join()                # verify that you can join twice
+    def test_failing_queue(self):
+        # Test to make sure a queue is functioning correctly.
+        # Done twice to the same instance.
+        q = FailingQueue(QUEUE_SIZE)
+        self.failing_queue_test(q)
+        self.failing_queue_test(q)
+
+
+def test_main():
+    test_support.run_unittest(QueueTest, LifoQueueTest, PriorityQueueTest,
+                              FailingQueueTest)
 
-def QueueTaskDoneTest(q):
-    try:
-        q.task_done()
-    except ValueError:
-        pass
-    else:
-        raise TestFailed("Did not detect task count going negative")
-
-def test():
-    q = Queue.Queue()
-    QueueTaskDoneTest(q)
-    QueueJoinTest(q)
-    QueueJoinTest(q)
-    QueueTaskDoneTest(q)
-
-    q = Queue.Queue(QUEUE_SIZE)
-    # Do it a couple of times on the same queue
-    SimpleQueueTest(q)
-    SimpleQueueTest(q)
-    if verbose:
-        print("Simple Queue tests seemed to work")
-    q = FailingQueue(QUEUE_SIZE)
-    FailingQueueTest(q)
-    FailingQueueTest(q)
-    if verbose:
-        print("Failing Queue tests seemed to work")
 
-test()
+if __name__ == "__main__":
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_random.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_random.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_random.py	Thu Mar 27 00:48:05 2008
@@ -42,21 +42,6 @@
         self.assertRaises(TypeError, self.gen.seed, 1, 2)
         self.assertRaises(TypeError, type(self.gen), [])
 
-    def test_jumpahead(self):
-        self.gen.seed()
-        state1 = self.gen.getstate()
-        self.gen.jumpahead(100)
-        state2 = self.gen.getstate()    # s/b distinct from state1
-        self.assertNotEqual(state1, state2)
-        self.gen.jumpahead(100)
-        state3 = self.gen.getstate()    # s/b distinct from state2
-        self.assertNotEqual(state2, state3)
-
-        self.assertRaises(TypeError, self.gen.jumpahead)  # needs an arg
-        self.assertRaises(TypeError, self.gen.jumpahead, "ick")  # wrong type
-        self.assertRaises(TypeError, self.gen.jumpahead, 2.3)  # wrong type
-        self.assertRaises(TypeError, self.gen.jumpahead, 2, 3)  # too many
-
     def test_sample(self):
         # For the entire allowable range of 0 <= k <= N, validate that
         # the sample is of the correct length and contains only unique items
@@ -99,26 +84,7 @@
         self.gen.sample(tuple('abcdefghijklmnopqrst'), 2)
 
     def test_sample_on_dicts(self):
-        self.gen.sample(dict.fromkeys('abcdefghijklmnopqrst'), 2)
-
-        # SF bug #1460340 -- random.sample can raise KeyError
-        a = dict.fromkeys(list(range(10)) +
-                          list(range(10,100,2)) +
-                          list(range(100,110)))
-        self.gen.sample(a, 3)
-
-        # A followup to bug #1460340:  sampling from a dict could return
-        # a subset of its keys or of its values, depending on the size of
-        # the subset requested.
-        N = 30
-        d = dict((i, complex(i, i)) for i in range(N))
-        for k in range(N+1):
-            samp = self.gen.sample(d, k)
-            # Verify that we got ints back (keys); the values are complex.
-            for x in samp:
-                self.assert_(type(x) is int)
-        samp.sort()
-        self.assertEqual(samp, list(range(N)))
+        self.assertRaises(TypeError, self.gen.sample, dict.fromkeys('abcdef'), 2)
 
     def test_gauss(self):
         # Ensure that the seed() method initializes all the hidden state.  In
@@ -144,47 +110,18 @@
         restoredseq = [newgen.random() for i in range(10)]
         self.assertEqual(origseq, restoredseq)
 
-class WichmannHill_TestBasicOps(TestBasicOps):
-    gen = random.WichmannHill()
-
-    def test_setstate_first_arg(self):
-        self.assertRaises(ValueError, self.gen.setstate, (2, None, None))
-
-    def test_strong_jumpahead(self):
-        # tests that jumpahead(n) semantics correspond to n calls to random()
-        N = 1000
-        s = self.gen.getstate()
-        self.gen.jumpahead(N)
-        r1 = self.gen.random()
-        # now do it the slow way
-        self.gen.setstate(s)
-        for i in range(N):
-            self.gen.random()
-        r2 = self.gen.random()
-        self.assertEqual(r1, r2)
-
-    def test_gauss_with_whseed(self):
-        # Ensure that the seed() method initializes all the hidden state.  In
-        # particular, through 2.2.1 it failed to reset a piece of state used
-        # by (and only by) the .gauss() method.
-
-        for seed in 1, 12, 123, 1234, 12345, 123456, 654321:
-            self.gen.whseed(seed)
-            x1 = self.gen.random()
-            y1 = self.gen.gauss(0, 1)
-
-            self.gen.whseed(seed)
-            x2 = self.gen.random()
-            y2 = self.gen.gauss(0, 1)
-
-            self.assertEqual(x1, x2)
-            self.assertEqual(y1, y2)
-
-    def test_bigrand(self):
-        # Verify warnings are raised when randrange is too large for random()
-        with test_support.catch_warning():
-            warnings.filterwarnings("error", "Underlying random")
-            self.assertRaises(UserWarning, self.gen.randrange, 2**60)
+    def test_bug_1727780(self):
+        # verify that version-2-pickles can be loaded
+        # fine, whether they are created on 32-bit or 64-bit
+        # platforms, and that version-3-pickles load fine.
+        files = [("randv2_32.pck", 780),
+                 ("randv2_64.pck", 866),
+                 ("randv3.pck", 343)]
+        for file, value in files:
+            f = open(test_support.findfile(file),"rb")
+            r = pickle.load(f)
+            f.close()
+            self.assertEqual(r.randrange(1000), value)
 
 class SystemRandom_TestBasicOps(TestBasicOps):
     gen = random.SystemRandom()
@@ -201,10 +138,6 @@
         # Doesn't need to do anything except not fail
         self.gen.seed(100)
 
-    def test_jumpahead(self):
-        # Doesn't need to do anything except not fail
-        self.gen.jumpahead(100)
-
     def test_gauss(self):
         self.gen.gauss_next = None
         self.gen.seed(100)
@@ -479,6 +412,7 @@
         g.random = x[:].pop; g.gammavariate(1.0, 1.0)
         g.random = x[:].pop; g.gammavariate(200.0, 1.0)
         g.random = x[:].pop; g.betavariate(3.0, 3.0)
+        g.random = x[:].pop; g.triangular(0.0, 1.0, 1.0/3.0)
 
     def test_avg_std(self):
         # Use integration to test distribution average and standard deviation.
@@ -488,6 +422,7 @@
         x = [i/float(N) for i in range(1,N)]
         for variate, args, mu, sigmasqrd in [
                 (g.uniform, (1.0,10.0), (10.0+1.0)/2, (10.0-1.0)**2/12),
+                (g.triangular, (0.0, 1.0, 1.0/3.0), 4.0/9.0, 7.0/9.0/18.0),
                 (g.expovariate, (1.5,), 1/1.5, 1/1.5**2),
                 (g.paretovariate, (5.0,), 5.0/(5.0-1),
                                   5.0/((5.0-1)**2*(5.0-2))),
@@ -528,8 +463,7 @@
 
 
 def test_main(verbose=None):
-    testclasses =    [WichmannHill_TestBasicOps,
-                      MersenneTwister_TestBasicOps,
+    testclasses =    [MersenneTwister_TestBasicOps,
                       TestDistributions,
                       TestModule]
 

Modified: python/branches/py3k-importlib/Lib/test/test_range.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_range.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_range.py	Thu Mar 27 00:48:05 2008
@@ -51,10 +51,10 @@
         self.assertRaises(TypeError, range, 0, "spam")
         self.assertRaises(TypeError, range, 0, 42, "spam")
 
-        self.assertEqual(len(range(0, sys.maxint, sys.maxint-1)), 2)
+        self.assertEqual(len(range(0, sys.maxsize, sys.maxsize-1)), 2)
 
-        r = range(-sys.maxint, sys.maxint, 2)
-        self.assertEqual(len(r), sys.maxint)
+        r = range(-sys.maxsize, sys.maxsize, 2)
+        self.assertEqual(len(r), sys.maxsize)
 
     def test_repr(self):
         self.assertEqual(repr(range(1)), 'range(0, 1)')

Modified: python/branches/py3k-importlib/Lib/test/test_re.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_re.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_re.py	Thu Mar 27 00:48:05 2008
@@ -83,33 +83,30 @@
         self.assertEqual(re.sub('\r\n', '\n', 'abc\r\ndef\r\n'),
                          'abc\ndef\n')
 
-# This test makes no sense until re supports bytes, and should then probably
-# test for the *in*ability to mix bytes and str this way :)
-#
-#    def test_bug_1140(self):
-#        # re.sub(x, y, b'') should return b'', not '', and
-#        # re.sub(x, y, '') should return '', not b''.
-#        # Also:
-#        # re.sub(x, y, str(x)) should return str(y), and
-#        # re.sub(x, y, bytes(x)) should return
-#        #     str(y) if isinstance(y, str) else unicode(y).
-#        for x in 'x', u'x':
-#            for y in 'y', u'y':
-#                z = re.sub(x, y, u'')
-#                self.assertEqual(z, u'')
-#                self.assertEqual(type(z), unicode)
-#                #
-#                z = re.sub(x, y, '')
-#                self.assertEqual(z, '')
-#                self.assertEqual(type(z), str)
-#                #
-#                z = re.sub(x, y, unicode(x))
-#                self.assertEqual(z, y)
-#                self.assertEqual(type(z), unicode)
-#                #
-#                z = re.sub(x, y, str(x))
-#                self.assertEqual(z, y)
-#                self.assertEqual(type(z), type(y))
+    def test_bug_1140(self):
+        # re.sub(x, y, b'') should return b'', not '', and
+        # re.sub(x, y, '') should return '', not b''.
+        # Also:
+        # re.sub(x, y, str(x)) should return str(y), and
+        # re.sub(x, y, bytes(x)) should return
+        #     str(y) if isinstance(y, str) else unicode(y).
+        for x in 'x',  b'x':
+            for y in 'y', b'y':
+                z = re.sub(x, y, b'')
+                self.assertEqual(z, b'')
+                self.assertEqual(type(z), bytes)
+                #
+                z = re.sub(x, y, '')
+                self.assertEqual(z, '')
+                self.assertEqual(type(z), str)
+
+    def test_bug_1661(self):
+        # Verify that flags do not get silently ignored with compiled patterns
+        pattern = re.compile('.')
+        self.assertRaises(ValueError, re.match, pattern, 'A', re.I)
+        self.assertRaises(ValueError, re.search, pattern, 'A', re.I)
+        self.assertRaises(ValueError, re.findall, pattern, 'A', re.I)
+        self.assertRaises(ValueError, re.compile, pattern, re.I)
 
     def test_sub_template_numeric_escape(self):
         # bug 776311 and friends
@@ -593,7 +590,7 @@
 
     def test_bug_926075(self):
         self.assert_(re.compile('bug_926075') is not
-                     re.compile(str8('bug_926075')))
+                     re.compile(b'bug_926075'))
 
     def test_bug_931848(self):
         pattern = eval('"[\u002E\u3002\uFF0E\uFF61]"')
@@ -623,6 +620,48 @@
             self.assertEqual(re.compile("bla").match(a), None)
             self.assertEqual(re.compile("").match(a).groups(), ())
 
+    def test_inline_flags(self):
+        # Bug #1700
+        upper_char = chr(0x1ea0) # Latin Capital Letter A with Dot Bellow
+        lower_char = chr(0x1ea1) # Latin Small Letter A with Dot Bellow
+
+        p = re.compile(upper_char, re.I | re.U)
+        q = p.match(lower_char)
+        self.assertNotEqual(q, None)
+
+        p = re.compile(lower_char, re.I | re.U)
+        q = p.match(upper_char)
+        self.assertNotEqual(q, None)
+
+        p = re.compile('(?i)' + upper_char, re.U)
+        q = p.match(lower_char)
+        self.assertNotEqual(q, None)
+
+        p = re.compile('(?i)' + lower_char, re.U)
+        q = p.match(upper_char)
+        self.assertNotEqual(q, None)
+
+        p = re.compile('(?iu)' + upper_char)
+        q = p.match(lower_char)
+        self.assertNotEqual(q, None)
+
+        p = re.compile('(?iu)' + lower_char)
+        q = p.match(upper_char)
+        self.assertNotEqual(q, None)
+
+    def test_dollar_matches_twice(self):
+        "$ matches the end of string, and just before the terminating \n"
+        pattern = re.compile('$')
+        self.assertEqual(pattern.sub('#', 'a\nb\n'), 'a\nb#\n#')
+        self.assertEqual(pattern.sub('#', 'a\nb\nc'), 'a\nb\nc#')
+        self.assertEqual(pattern.sub('#', '\n'), '#\n#')
+
+        pattern = re.compile('$', re.MULTILINE)
+        self.assertEqual(pattern.sub('#', 'a\nb\n' ), 'a#\nb#\n#' )
+        self.assertEqual(pattern.sub('#', 'a\nb\nc'), 'a#\nb#\nc#')
+        self.assertEqual(pattern.sub('#', '\n'), '#\n#')
+
+
 def run_re_tests():
     from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_ERROR
     if verbose:

Modified: python/branches/py3k-importlib/Lib/test/test_repr.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_repr.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_repr.py	Thu Mar 27 00:48:05 2008
@@ -280,8 +280,8 @@
 ''')
         from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux
         # Unbound methods first
-        eq(repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod),
-        '<unbound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod>')
+        self.failUnless(repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod).startswith(
+        '<function amethod'))
         # Bound method next
         iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
         self.failUnless(repr(iqux.amethod).startswith(

Modified: python/branches/py3k-importlib/Lib/test/test_resource.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_resource.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_resource.py	Thu Mar 27 00:48:05 2008
@@ -1,8 +1,8 @@
 import unittest
 from test import test_support
 
-
-import os, resource
+import resource
+import time
 
 # This test is checking a few specific problem spots with the resource module.
 
@@ -15,7 +15,6 @@
         self.assertRaises(TypeError, resource.setrlimit, 42, 42, 42)
 
     def test_fsize_ismax(self):
-
         try:
             (cur, max) = resource.getrlimit(resource.RLIMIT_FSIZE)
         except AttributeError:
@@ -54,6 +53,14 @@
                     try:
                         f.write(b"Y")
                         f.flush()
+                        # On some systems (e.g., Ubuntu on hppa) the flush()
+                        # doesn't always cause the exception, but the close()
+                        # does eventually.  Try flushing several times in
+                        # an attempt to ensure the file is really synced and
+                        # the exception raised.
+                        for i in range(5):
+                            time.sleep(.1)
+                            f.flush()
                     except IOError:
                         if not limit_set:
                             raise
@@ -63,10 +70,10 @@
                         resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
                 finally:
                     f.close()
-                    os.unlink(test_support.TESTFN)
             finally:
                 if limit_set:
                     resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
+                test_support.unlink(test_support.TESTFN)
 
     def test_fsize_toobig(self):
         # Be sure that setrlimit is checking for really large values

Modified: python/branches/py3k-importlib/Lib/test/test_rfc822.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_rfc822.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_rfc822.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,4 @@
 import rfc822
-import sys
 import unittest
 from test import test_support
 

Modified: python/branches/py3k-importlib/Lib/test/test_richcmp.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_richcmp.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_richcmp.py	Thu Mar 27 00:48:05 2008
@@ -85,6 +85,35 @@
             raise ValueError("Cannot compare vectors of different length")
         return other
 
+
+class SimpleOrder(object):
+    """
+    A simple class that defines order but not full comparison.
+    """
+
+    def __init__(self, value):
+        self.value = value
+
+    def __lt__(self, other):
+        if not isinstance(other, SimpleOrder):
+            return True
+        return self.value < other.value
+
+    def __gt__(self, other):
+        if not isinstance(other, SimpleOrder):
+            return False
+        return self.value > other.value
+
+
+class DumbEqualityWithoutHash(object):
+    """
+    A class that define __eq__, but no __hash__: it shouldn't be hashable.
+    """
+
+    def __eq__(self, other):
+        return False
+
+
 opmap = {
     "lt": (lambda a,b: a< b, operator.lt, operator.__lt__),
     "le": (lambda a,b: a<=b, operator.le, operator.__le__),
@@ -225,7 +254,7 @@
 
     def test_recursion(self):
         # Check that comparison for recursive objects fails gracefully
-        from UserList import UserList
+        from collections import UserList
         a = UserList()
         b = UserList()
         a.append(b)
@@ -330,8 +359,39 @@
         for op in opmap["lt"]:
             self.assertIs(op(x, y), True)
 
+
+class HashableTest(unittest.TestCase):
+    """
+    Test hashability of classes with rich operators defined.
+    """
+
+    def test_simpleOrderHashable(self):
+        """
+        A class that only defines __gt__ and/or __lt__ should be hashable.
+        """
+        a = SimpleOrder(1)
+        b = SimpleOrder(2)
+        self.assert_(a < b)
+        self.assert_(b > a)
+        self.assert_(a.__hash__ is not None)
+
+    def test_notHashableException(self):
+        """
+        If a class is not hashable, it should raise a TypeError with an
+        understandable message.
+        """
+        a = DumbEqualityWithoutHash()
+        try:
+            hash(a)
+        except TypeError as e:
+            self.assertEquals(str(e),
+                              "unhashable type: 'DumbEqualityWithoutHash'")
+        else:
+            raise test_support.TestFailed("Should not be here")
+
+
 def test_main():
-    test_support.run_unittest(VectorTest, NumberTest, MiscTest, DictTest, ListTest)
+    test_support.run_unittest(VectorTest, NumberTest, MiscTest, DictTest, ListTest, HashableTest)
 
 if __name__ == "__main__":
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_runpy.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_runpy.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_runpy.py	Thu Mar 27 00:48:05 2008
@@ -5,7 +5,12 @@
 import sys
 import tempfile
 from test.test_support import verbose, run_unittest, forget
-from runpy import _run_code, _run_module_code, _run_module_as_main, run_module
+from runpy import _run_code, _run_module_code, run_module
+
+# Note: This module can't safely test _run_module_as_main as it
+# runs its tests in the current process, which would mess with the
+# real __main__ module (usually test.regrtest)
+# See test_cmd_line_script for a test that executes that code path
 
 # Set up the test code and expected results
 
@@ -36,6 +41,7 @@
         self.failUnless(d["__name__"] is None)
         self.failUnless(d["__file__"] is None)
         self.failUnless(d["__loader__"] is None)
+        self.failUnless(d["__package__"] is None)
         self.failUnless(d["run_argv0"] is saved_argv0)
         self.failUnless("run_name" not in d)
         self.failUnless(sys.argv[0] is saved_argv0)
@@ -45,13 +51,15 @@
         name = "<Nonsense>"
         file = "Some other nonsense"
         loader = "Now you're just being silly"
+        package = '' # Treat as a top level module
         d1 = dict(initial=initial)
         saved_argv0 = sys.argv[0]
         d2 = _run_module_code(self.test_source,
                               d1,
                               name,
                               file,
-                              loader)
+                              loader,
+                              package)
         self.failUnless("result" not in d1)
         self.failUnless(d2["initial"] is initial)
         self.assertEqual(d2["result"], self.expected_result)
@@ -62,6 +70,7 @@
         self.failUnless(d2["__file__"] is file)
         self.failUnless(d2["run_argv0"] is file)
         self.failUnless(d2["__loader__"] is loader)
+        self.failUnless(d2["__package__"] is package)
         self.failUnless(sys.argv[0] is saved_argv0)
         self.failUnless(name not in sys.modules)
 
@@ -164,7 +173,7 @@
             self._del_pkg(pkg_dir, depth, mod_name)
         if verbose: print("Module executed successfully")
 
-    def _add_relative_modules(self, base_dir, depth):
+    def _add_relative_modules(self, base_dir, source, depth):
         if depth <= 1:
             raise ValueError("Relative module test needs depth > 1")
         pkg_name = "__runpy_pkg__"
@@ -190,7 +199,7 @@
         if verbose: print("  Added nephew module:", nephew_fname)
 
     def _check_relative_imports(self, depth, run_name=None):
-        contents = """\
+        contents = r"""\
 from __future__ import absolute_import
 from . import sibling
 from ..uncle.cousin import nephew
@@ -198,16 +207,21 @@
         pkg_dir, mod_fname, mod_name = (
                self._make_pkg(contents, depth))
         try:
-            self._add_relative_modules(pkg_dir, depth)
+            self._add_relative_modules(pkg_dir, contents, depth)
+            pkg_name = mod_name.rpartition('.')[0]
             if verbose: print("Running from source:", mod_name)
-            d1 = run_module(mod_name) # Read from source
+            d1 = run_module(mod_name, run_name=run_name) # Read from source
+            self.failUnless("__package__" in d1)
+            self.failUnless(d1["__package__"] == pkg_name)
             self.failUnless("sibling" in d1)
             self.failUnless("nephew" in d1)
             del d1 # Ensure __loader__ entry doesn't keep file open
             __import__(mod_name)
             os.remove(mod_fname)
             if verbose: print("Running from compiled:", mod_name)
-            d2 = run_module(mod_name) # Read from bytecode
+            d2 = run_module(mod_name, run_name=run_name) # Read from bytecode
+            self.failUnless("__package__" in d2)
+            self.failUnless(d2["__package__"] == pkg_name)
             self.failUnless("sibling" in d2)
             self.failUnless("nephew" in d2)
             del d2 # Ensure __loader__ entry doesn't keep file open
@@ -225,6 +239,11 @@
             if verbose: print("Testing relative imports at depth:", depth)
             self._check_relative_imports(depth)
 
+    def test_main_relative_import(self):
+        for depth in range(2, 5):
+            if verbose: print("Testing main relative imports at depth:", depth)
+            self._check_relative_imports(depth, "__main__")
+
 
 def test_main():
     run_unittest(RunModuleCodeTest)

Modified: python/branches/py3k-importlib/Lib/test/test_scope.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_scope.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_scope.py	Thu Mar 27 00:48:05 2008
@@ -166,6 +166,17 @@
         self.assertEqual(t.method_and_var(), "method")
         self.assertEqual(t.actual_global(), "global")
 
+    def testCellIsKwonlyArg(self):
+        # Issue 1409: Initialisation of a cell value,
+        # when it comes from a keyword-only parameter
+        def foo(*, a=17):
+            def bar():
+                return a + 5
+            return bar() + 3
+
+        self.assertEqual(foo(a=42), 50)
+        self.assertEqual(foo(), 25)
+
     def testRecursion(self):
 
         def f(x):
@@ -562,6 +573,13 @@
 
         f(4)()
 
+    def testFreeingCell(self):
+        # Test what happens when a finalizer accesses
+        # the cell where the object was stored.
+        class Special:
+            def __del__(self):
+                nestedcell_get()
+
     def testNonLocalFunction(self):
 
         def f(x):

Modified: python/branches/py3k-importlib/Lib/test/test_scriptpackages.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_scriptpackages.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_scriptpackages.py	Thu Mar 27 00:48:05 2008
@@ -1,9 +1,6 @@
 # Copyright (C) 2003 Python Software Foundation
 
 import unittest
-import os
-import sys
-import tempfile
 from test import test_support
 import aetools
 

Modified: python/branches/py3k-importlib/Lib/test/test_select.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_select.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_select.py	Thu Mar 27 00:48:05 2008
@@ -1,70 +1,52 @@
-# Testing select module
-from test.test_support import verbose, reap_children
+from test import test_support
+import unittest
 import select
 import os
+import sys
 
-# test some known error conditions
-try:
-    rfd, wfd, xfd = select.select(1, 2, 3)
-except TypeError:
-    pass
-else:
-    print('expected TypeError exception not raised')
-
-class Nope:
-    pass
-
-class Almost:
-    def fileno(self):
-        return 'fileno'
-
-try:
-    rfd, wfd, xfd = select.select([Nope()], [], [])
-except TypeError:
-    pass
-else:
-    print('expected TypeError exception not raised')
-
-try:
-    rfd, wfd, xfd = select.select([Almost()], [], [])
-except TypeError:
-    pass
-else:
-    print('expected TypeError exception not raised')
-
-try:
-    rfd, wfd, xfd = select.select([], [], [], 'not a number')
-except TypeError:
-    pass
-else:
-    print('expected TypeError exception not raised')
-
-
-def test():
-    import sys
-    if sys.platform[:3] in ('win', 'mac', 'os2'):
-        if verbose:
-            print("Can't test select easily on", sys.platform)
-        return
-    cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
-    p = os.popen(cmd, 'r')
-    for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
-        if verbose:
-            print('timeout =', tout)
-        rfd, wfd, xfd = select.select([p], [], [], tout)
-        if (rfd, wfd, xfd) == ([], [], []):
-            continue
-        if (rfd, wfd, xfd) == ([p], [], []):
-            line = p.readline()
-            if verbose:
-                print(repr(line))
-            if not line:
-                if verbose:
-                    print('EOF')
-                break
-            continue
-        print('Unexpected return values from select():', rfd, wfd, xfd)
-    p.close()
-    reap_children()
+class SelectTestCase(unittest.TestCase):
 
-test()
+    class Nope:
+        pass
+
+    class Almost:
+        def fileno(self):
+            return 'fileno'
+
+    def test_error_conditions(self):
+        self.assertRaises(TypeError, select.select, 1, 2, 3)
+        self.assertRaises(TypeError, select.select, [self.Nope()], [], [])
+        self.assertRaises(TypeError, select.select, [self.Almost()], [], [])
+        self.assertRaises(TypeError, select.select, [], [], [], "not a number")
+
+    def test_select(self):
+        if sys.platform[:3] in ('win', 'mac', 'os2', 'riscos'):
+            if test_support.verbose:
+                print("Can't test select easily on", sys.platform)
+            return
+        cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
+        p = os.popen(cmd, 'r')
+        for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
+            if test_support.verbose:
+                print('timeout =', tout)
+            rfd, wfd, xfd = select.select([p], [], [], tout)
+            if (rfd, wfd, xfd) == ([], [], []):
+                continue
+            if (rfd, wfd, xfd) == ([p], [], []):
+                line = p.readline()
+                if test_support.verbose:
+                    print(repr(line))
+                if not line:
+                    if test_support.verbose:
+                        print('EOF')
+                    break
+                continue
+            self.fail('Unexpected return values from select():', rfd, wfd, xfd)
+        p.close()
+
+def test_main():
+    test_support.run_unittest(SelectTestCase)
+    test_support.reap_children()
+
+if __name__ == "__main__":
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_set.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_set.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_set.py	Thu Mar 27 00:48:05 2008
@@ -7,6 +7,8 @@
 import os
 from random import randrange, shuffle
 import sys
+import warnings
+import collections
 
 class PassThru(Exception):
     pass
@@ -72,7 +74,7 @@
         self.assertEqual(type(u), self.thetype)
         self.assertRaises(PassThru, self.s.union, check_pass_thru())
         self.assertRaises(TypeError, self.s.union, [[]])
-        for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
+        for C in set, frozenset, dict.fromkeys, str, list, tuple:
             self.assertEqual(self.thetype('abcba').union(C('cdc')), set('abcd'))
             self.assertEqual(self.thetype('abcba').union(C('efgfe')), set('abcefg'))
             self.assertEqual(self.thetype('abcba').union(C('ccb')), set('abc'))
@@ -96,12 +98,26 @@
         self.assertEqual(self.s, self.thetype(self.word))
         self.assertEqual(type(i), self.thetype)
         self.assertRaises(PassThru, self.s.intersection, check_pass_thru())
-        for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
+        for C in set, frozenset, dict.fromkeys, str, list, tuple:
             self.assertEqual(self.thetype('abcba').intersection(C('cdc')), set('cc'))
             self.assertEqual(self.thetype('abcba').intersection(C('efgfe')), set(''))
             self.assertEqual(self.thetype('abcba').intersection(C('ccb')), set('bc'))
             self.assertEqual(self.thetype('abcba').intersection(C('ef')), set(''))
 
+    def test_isdisjoint(self):
+        def f(s1, s2):
+            'Pure python equivalent of isdisjoint()'
+            return not set(s1).intersection(s2)
+        for larg in '', 'a', 'ab', 'abc', 'ababac', 'cdc', 'cc', 'efgfe', 'ccb', 'ef':
+            s1 = self.thetype(larg)
+            for rarg in '', 'a', 'ab', 'abc', 'ababac', 'cdc', 'cc', 'efgfe', 'ccb', 'ef':
+                for C in set, frozenset, dict.fromkeys, str, list, tuple:
+                    s2 = C(rarg)
+                    actual = s1.isdisjoint(s2)
+                    expected = f(s1, s2)
+                    self.assertEqual(actual, expected)
+                    self.assert_(actual is True or actual is False)
+
     def test_and(self):
         i = self.s.intersection(self.otherword)
         self.assertEqual(self.s & set(self.otherword), i)
@@ -121,7 +137,7 @@
         self.assertEqual(type(i), self.thetype)
         self.assertRaises(PassThru, self.s.difference, check_pass_thru())
         self.assertRaises(TypeError, self.s.difference, [[]])
-        for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
+        for C in set, frozenset, dict.fromkeys, str, list, tuple:
             self.assertEqual(self.thetype('abcba').difference(C('cdc')), set('ab'))
             self.assertEqual(self.thetype('abcba').difference(C('efgfe')), set('abc'))
             self.assertEqual(self.thetype('abcba').difference(C('ccb')), set('a'))
@@ -146,7 +162,7 @@
         self.assertEqual(type(i), self.thetype)
         self.assertRaises(PassThru, self.s.symmetric_difference, check_pass_thru())
         self.assertRaises(TypeError, self.s.symmetric_difference, [[]])
-        for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
+        for C in set, frozenset, dict.fromkeys, str, list, tuple:
             self.assertEqual(self.thetype('abcba').symmetric_difference(C('cdc')), set('abd'))
             self.assertEqual(self.thetype('abcba').symmetric_difference(C('efgfe')), set('abcefg'))
             self.assertEqual(self.thetype('abcba').symmetric_difference(C('ccb')), set('a'))
@@ -390,7 +406,7 @@
         self.assertRaises(PassThru, self.s.update, check_pass_thru())
         self.assertRaises(TypeError, self.s.update, [[]])
         for p, q in (('cdc', 'abcd'), ('efgfe', 'abcefg'), ('ccb', 'abc'), ('ef', 'abcef')):
-            for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
+            for C in set, frozenset, dict.fromkeys, str, list, tuple:
                 s = self.thetype('abcba')
                 self.assertEqual(s.update(C(p)), None)
                 self.assertEqual(s, set(q))
@@ -411,7 +427,7 @@
         self.assertRaises(PassThru, self.s.intersection_update, check_pass_thru())
         self.assertRaises(TypeError, self.s.intersection_update, [[]])
         for p, q in (('cdc', 'c'), ('efgfe', ''), ('ccb', 'bc'), ('ef', '')):
-            for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
+            for C in set, frozenset, dict.fromkeys, str, list, tuple:
                 s = self.thetype('abcba')
                 self.assertEqual(s.intersection_update(C(p)), None)
                 self.assertEqual(s, set(q))
@@ -436,7 +452,7 @@
         self.assertRaises(TypeError, self.s.difference_update, [[]])
         self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]])
         for p, q in (('cdc', 'ab'), ('efgfe', 'abc'), ('ccb', 'a'), ('ef', 'abc')):
-            for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
+            for C in set, frozenset, dict.fromkeys, str, list, tuple:
                 s = self.thetype('abcba')
                 self.assertEqual(s.difference_update(C(p)), None)
                 self.assertEqual(s, set(q))
@@ -460,7 +476,7 @@
         self.assertRaises(PassThru, self.s.symmetric_difference_update, check_pass_thru())
         self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]])
         for p, q in (('cdc', 'abd'), ('efgfe', 'abcefg'), ('ccb', 'a'), ('ef', 'abcef')):
-            for C in set, frozenset, dict.fromkeys, str, str8, list, tuple:
+            for C in set, frozenset, dict.fromkeys, str, list, tuple:
                 s = self.thetype('abcba')
                 self.assertEqual(s.symmetric_difference_update(C(p)), None)
                 self.assertEqual(s, set(q))
@@ -701,6 +717,18 @@
         result = empty_set & self.set
         self.assertEqual(result, empty_set)
 
+    def test_self_isdisjoint(self):
+        result = self.set.isdisjoint(self.set)
+        self.assertEqual(result, not self.set)
+
+    def test_empty_isdisjoint(self):
+        result = self.set.isdisjoint(empty_set)
+        self.assertEqual(result, True)
+
+    def test_isdisjoint_empty(self):
+        result = empty_set.isdisjoint(self.set)
+        self.assertEqual(result, True)
+
     def test_self_symmetric_difference(self):
         result = self.set ^ self.set
         self.assertEqual(result, empty_set)
@@ -791,6 +819,44 @@
         self.length = 3
         self.repr   = None
 
+#------------------------------------------------------------------------------
+
+class TestBasicOpsString(TestBasicOps):
+    def setUp(self):
+        self.case   = "string set"
+        self.values = ["a", "b", "c"]
+        self.set    = set(self.values)
+        self.dup    = set(self.values)
+        self.length = 3
+        self.repr   = "{'a', 'c', 'b'}"
+
+#------------------------------------------------------------------------------
+
+class TestBasicOpsBytes(TestBasicOps):
+    def setUp(self):
+        self.case   = "string set"
+        self.values = [b"a", b"b", b"c"]
+        self.set    = set(self.values)
+        self.dup    = set(self.values)
+        self.length = 3
+        self.repr   = "{b'a', b'c', b'b'}"
+
+#------------------------------------------------------------------------------
+
+class TestBasicOpsMixedStringBytes(TestBasicOps):
+    def setUp(self):
+        self.warning_filters = warnings.filters[:]
+        warnings.simplefilter('ignore', BytesWarning)
+        self.case   = "string and bytes set"
+        self.values = ["a", "b", b"a", b"b"]
+        self.set    = set(self.values)
+        self.dup    = set(self.values)
+        self.length = 4
+        self.repr   = "{'a', b'a', 'b', b'b'}"
+
+    def tearDown(self):
+        warnings.filters = self.warning_filters
+
 #==============================================================================
 
 def baditer():
@@ -879,6 +945,22 @@
         result = self.set & set([8])
         self.assertEqual(result, empty_set)
 
+    def test_isdisjoint_subset(self):
+        result = self.set.isdisjoint(set((2, 4)))
+        self.assertEqual(result, False)
+
+    def test_isdisjoint_superset(self):
+        result = self.set.isdisjoint(set([2, 4, 6, 8]))
+        self.assertEqual(result, False)
+
+    def test_isdisjoint_overlap(self):
+        result = self.set.isdisjoint(set([3, 4, 5]))
+        self.assertEqual(result, False)
+
+    def test_isdisjoint_non_overlap(self):
+        result = self.set.isdisjoint(set([8]))
+        self.assertEqual(result, True)
+
     def test_sym_difference_subset(self):
         result = self.set ^ set((2, 4))
         self.assertEqual(result, set([6]))
@@ -1478,10 +1560,10 @@
     def __next__(self):
         raise StopIteration
 
-from itertools import chain, imap
+from itertools import chain
 def L(seqn):
     'Test multiple tiers of iterators'
-    return chain(imap(lambda x:x, R(Ig(G(seqn)))))
+    return chain(map(lambda x:x, R(Ig(G(seqn)))))
 
 class TestVariousIteratorArgs(unittest.TestCase):
 
@@ -1497,11 +1579,14 @@
     def test_inline_methods(self):
         s = set('november')
         for data in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5), 'december'):
-            for meth in (s.union, s.intersection, s.difference, s.symmetric_difference):
+            for meth in (s.union, s.intersection, s.difference, s.symmetric_difference, s.isdisjoint):
                 for g in (G, I, Ig, L, R):
                     expected = meth(data)
                     actual = meth(G(data))
-                    self.assertEqual(sorted(actual, key=repr), sorted(expected, key=repr))
+                    if isinstance(expected, bool):
+                        self.assertEqual(actual, expected)
+                    else:
+                        self.assertEqual(sorted(actual, key=repr), sorted(expected, key=repr))
                 self.assertRaises(TypeError, meth, X(s))
                 self.assertRaises(TypeError, meth, N(s))
                 self.assertRaises(ZeroDivisionError, meth, E(s))
@@ -1521,6 +1606,110 @@
                 self.assertRaises(TypeError, getattr(set('january'), methname), N(data))
                 self.assertRaises(ZeroDivisionError, getattr(set('january'), methname), E(data))
 
+# Application tests (based on David Eppstein's graph recipes ====================================
+
+def powerset(U):
+    """Generates all subsets of a set or sequence U."""
+    U = iter(U)
+    try:
+        x = frozenset([next(U)])
+        for S in powerset(U):
+            yield S
+            yield S | x
+    except StopIteration:
+        yield frozenset()
+
+def cube(n):
+    """Graph of n-dimensional hypercube."""
+    singletons = [frozenset([x]) for x in range(n)]
+    return dict([(x, frozenset([x^s for s in singletons]))
+                 for x in powerset(range(n))])
+
+def linegraph(G):
+    """Graph, the vertices of which are edges of G,
+    with two vertices being adjacent iff the corresponding
+    edges share a vertex."""
+    L = {}
+    for x in G:
+        for y in G[x]:
+            nx = [frozenset([x,z]) for z in G[x] if z != y]
+            ny = [frozenset([y,z]) for z in G[y] if z != x]
+            L[frozenset([x,y])] = frozenset(nx+ny)
+    return L
+
+def faces(G):
+    'Return a set of faces in G.  Where a face is a set of vertices on that face'
+    # currently limited to triangles,squares, and pentagons
+    f = set()
+    for v1, edges in G.items():
+        for v2 in edges:
+            for v3 in G[v2]:
+                if v1 == v3:
+                    continue
+                if v1 in G[v3]:
+                    f.add(frozenset([v1, v2, v3]))
+                else:
+                    for v4 in G[v3]:
+                        if v4 == v2:
+                            continue
+                        if v1 in G[v4]:
+                            f.add(frozenset([v1, v2, v3, v4]))
+                        else:
+                            for v5 in G[v4]:
+                                if v5 == v3 or v5 == v2:
+                                    continue
+                                if v1 in G[v5]:
+                                    f.add(frozenset([v1, v2, v3, v4, v5]))
+    return f
+
+
+class TestGraphs(unittest.TestCase):
+
+    def test_cube(self):
+
+        g = cube(3)                             # vert --> {v1, v2, v3}
+        vertices1 = set(g)
+        self.assertEqual(len(vertices1), 8)     # eight vertices
+        for edge in g.values():
+            self.assertEqual(len(edge), 3)      # each vertex connects to three edges
+        vertices2 = set(v for edges in g.values() for v in edges)
+        self.assertEqual(vertices1, vertices2)  # edge vertices in original set
+
+        cubefaces = faces(g)
+        self.assertEqual(len(cubefaces), 6)     # six faces
+        for face in cubefaces:
+            self.assertEqual(len(face), 4)      # each face is a square
+
+    def test_cuboctahedron(self):
+
+        # http://en.wikipedia.org/wiki/Cuboctahedron
+        # 8 triangular faces and 6 square faces
+        # 12 indentical vertices each connecting a triangle and square
+
+        g = cube(3)
+        cuboctahedron = linegraph(g)            # V( --> {V1, V2, V3, V4}
+        self.assertEqual(len(cuboctahedron), 12)# twelve vertices
+
+        vertices = set(cuboctahedron)
+        for edges in cuboctahedron.values():
+            self.assertEqual(len(edges), 4)     # each vertex connects to four other vertices
+        othervertices = set(edge for edges in cuboctahedron.values() for edge in edges)
+        self.assertEqual(vertices, othervertices)   # edge vertices in original set
+
+        cubofaces = faces(cuboctahedron)
+        facesizes = collections.defaultdict(int)
+        for face in cubofaces:
+            facesizes[len(face)] += 1
+        self.assertEqual(facesizes[3], 8)       # eight triangular faces
+        self.assertEqual(facesizes[4], 6)       # six square faces
+
+        for vertex in cuboctahedron:
+            edge = vertex                       # Cuboctahedron vertices are edges in Cube
+            self.assertEqual(len(edge), 2)      # Two cube vertices define an edge
+            for cubevert in edge:
+                self.assert_(cubevert in g)
+
+
 #==============================================================================
 
 def test_main(verbose=None):
@@ -1536,6 +1725,9 @@
         TestBasicOpsSingleton,
         TestBasicOpsTuple,
         TestBasicOpsTriple,
+        TestBasicOpsString,
+        TestBasicOpsBytes,
+        TestBasicOpsMixedStringBytes,
         TestBinaryOps,
         TestUpdateOps,
         TestMutate,
@@ -1557,6 +1749,7 @@
         TestCopyingNested,
         TestIdentities,
         TestVariousIteratorArgs,
+        TestGraphs,
         )
 
     test_support.run_unittest(*test_classes)

Modified: python/branches/py3k-importlib/Lib/test/test_sgmllib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_sgmllib.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_sgmllib.py	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-import htmlentitydefs
 import pprint
 import re
 import sgmllib
@@ -116,7 +115,7 @@
         try:
             events = self.get_events(source)
         except:
-            import sys
+            #import sys
             #print >>sys.stderr, pprint.pformat(self.events)
             raise
         if events != expected_events:

Modified: python/branches/py3k-importlib/Lib/test/test_shelve.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_shelve.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_shelve.py	Thu Mar 27 00:48:05 2008
@@ -2,13 +2,13 @@
 import shelve
 import glob
 from test import test_support
-from UserDict import DictMixin
+from collections import MutableMapping
 from test.test_anydbm import dbm_iterator
 
 def L1(s):
     return s.decode("latin-1")
 
-class byteskeydict(DictMixin):
+class byteskeydict(MutableMapping):
     "Mapping that supports bytes keys"
 
     def __init__(self):
@@ -23,10 +23,15 @@
     def __delitem__(self, key):
         del self.d[L1(key)]
 
+    def __len__(self):
+        return len(self.d)
+
     def iterkeys(self):
         for k in self.d.keys():
             yield k.encode("latin-1")
 
+    __iter__ = iterkeys
+
     def keys(self):
         return list(self.iterkeys())
 

Modified: python/branches/py3k-importlib/Lib/test/test_shutil.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_shutil.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_shutil.py	Thu Mar 27 00:48:05 2008
@@ -63,17 +63,6 @@
         self.assertRaises(OSError, shutil.rmtree, path)
         os.remove(path)
 
-    def test_dont_move_dir_in_itself(self):
-        src_dir = tempfile.mkdtemp()
-        try:
-            dst = os.path.join(src_dir, 'foo')
-            self.assertRaises(shutil.Error, shutil.move, src_dir, dst)
-        finally:
-            try:
-                os.rmdir(src_dir)
-            except:
-                pass
-
     def test_copytree_simple(self):
         def write_data(path, data):
             f = open(path, "w")
@@ -113,12 +102,11 @@
                 ):
                 if os.path.exists(path):
                     os.remove(path)
-            for path in (
-                    os.path.join(src_dir, 'test_dir'),
-                    os.path.join(dst_dir, 'test_dir'),
+            for path in (src_dir,
+                    os.path.abspath(os.path.join(dst_dir, os.path.pardir))
                 ):
                 if os.path.exists(path):
-                    os.removedirs(path)
+                    shutil.rmtree(path)
 
 
     if hasattr(os, "symlink"):
@@ -150,8 +138,136 @@
                 except OSError:
                     pass
 
+        def test_rmtree_on_symlink(self):
+            # bug 1669.
+            os.mkdir(TESTFN)
+            try:
+                src = os.path.join(TESTFN, 'cheese')
+                dst = os.path.join(TESTFN, 'shop')
+                os.mkdir(src)
+                os.symlink(src, dst)
+                self.assertRaises(OSError, shutil.rmtree, dst)
+            finally:
+                shutil.rmtree(TESTFN, ignore_errors=True)
+
+
+class TestMove(unittest.TestCase):
+
+    def setUp(self):
+        filename = "foo"
+        self.src_dir = tempfile.mkdtemp()
+        self.dst_dir = tempfile.mkdtemp()
+        self.src_file = os.path.join(self.src_dir, filename)
+        self.dst_file = os.path.join(self.dst_dir, filename)
+        # Try to create a dir in the current directory, hoping that it is
+        # not located on the same filesystem as the system tmp dir.
+        try:
+            self.dir_other_fs = tempfile.mkdtemp(
+                dir=os.path.dirname(__file__))
+            self.file_other_fs = os.path.join(self.dir_other_fs,
+                filename)
+        except OSError:
+            self.dir_other_fs = None
+        with open(self.src_file, "wb") as f:
+            f.write(b"spam")
+
+    def tearDown(self):
+        for d in (self.src_dir, self.dst_dir, self.dir_other_fs):
+            try:
+                if d:
+                    shutil.rmtree(d)
+            except:
+                pass
+
+    def _check_move_file(self, src, dst, real_dst):
+        contents = open(src, "rb").read()
+        shutil.move(src, dst)
+        self.assertEqual(contents, open(real_dst, "rb").read())
+        self.assertFalse(os.path.exists(src))
+
+    def _check_move_dir(self, src, dst, real_dst):
+        contents = sorted(os.listdir(src))
+        shutil.move(src, dst)
+        self.assertEqual(contents, sorted(os.listdir(real_dst)))
+        self.assertFalse(os.path.exists(src))
+
+    def test_move_file(self):
+        # Move a file to another location on the same filesystem.
+        self._check_move_file(self.src_file, self.dst_file, self.dst_file)
+
+    def test_move_file_to_dir(self):
+        # Move a file inside an existing dir on the same filesystem.
+        self._check_move_file(self.src_file, self.dst_dir, self.dst_file)
+
+    def test_move_file_other_fs(self):
+        # Move a file to an existing dir on another filesystem.
+        if not self.dir_other_fs:
+            # skip
+            return
+        self._check_move_file(self.src_file, self.file_other_fs,
+            self.file_other_fs)
+
+    def test_move_file_to_dir_other_fs(self):
+        # Move a file to another location on another filesystem.
+        if not self.dir_other_fs:
+            # skip
+            return
+        self._check_move_file(self.src_file, self.dir_other_fs,
+            self.file_other_fs)
+
+    def test_move_dir(self):
+        # Move a dir to another location on the same filesystem.
+        dst_dir = tempfile.mktemp()
+        try:
+            self._check_move_dir(self.src_dir, dst_dir, dst_dir)
+        finally:
+            try:
+                shutil.rmtree(dst_dir)
+            except:
+                pass
+
+    def test_move_dir_other_fs(self):
+        # Move a dir to another location on another filesystem.
+        if not self.dir_other_fs:
+            # skip
+            return
+        dst_dir = tempfile.mktemp(dir=self.dir_other_fs)
+        try:
+            self._check_move_dir(self.src_dir, dst_dir, dst_dir)
+        finally:
+            try:
+                shutil.rmtree(dst_dir)
+            except:
+                pass
+
+    def test_move_dir_to_dir(self):
+        # Move a dir inside an existing dir on the same filesystem.
+        self._check_move_dir(self.src_dir, self.dst_dir,
+            os.path.join(self.dst_dir, os.path.basename(self.src_dir)))
+
+    def test_move_dir_to_dir_other_fs(self):
+        # Move a dir inside an existing dir on another filesystem.
+        if not self.dir_other_fs:
+            # skip
+            return
+        self._check_move_dir(self.src_dir, self.dir_other_fs,
+            os.path.join(self.dir_other_fs, os.path.basename(self.src_dir)))
+
+    def test_existing_file_inside_dest_dir(self):
+        # A file with the same name inside the destination dir already exists.
+        with open(self.dst_file, "wb"):
+            pass
+        self.assertRaises(shutil.Error, shutil.move, self.src_file, self.dst_dir)
+
+    def test_dont_move_dir_in_itself(self):
+        # Moving a dir inside itself raises an Error.
+        dst = os.path.join(self.src_dir, "bar")
+        self.assertRaises(shutil.Error, shutil.move, self.src_dir, dst)
+
+
+
 def test_main():
-    test_support.run_unittest(TestShutil)
+    test_support.run_unittest(TestShutil, TestMove)
 
 if __name__ == '__main__':
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_signal.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_signal.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_signal.py	Thu Mar 27 00:48:05 2008
@@ -1,44 +1,34 @@
 import unittest
 from test import test_support
+from contextlib import closing, nested
+import pickle
+import select
 import signal
-import os, sys, time
+import subprocess
+import traceback
+import sys, os, time, errno
+
+if sys.platform[:3] in ('win', 'os2') or sys.platform == 'riscos':
+    raise test_support.TestSkipped("Can't test signal on %s" % \
+                                   sys.platform)
+
 
 class HandlerBCalled(Exception):
     pass
 
-class InterProcessSignalTests(unittest.TestCase):
-    MAX_DURATION = 20   # Entire test should last at most 20 sec.
 
-    # Set up a child to send signals to us (the parent) after waiting
-    # long enough to receive the alarm.  It seems we miss the alarm
-    # for some reason.  This will hopefully stop the hangs on
-    # Tru64/Alpha.  Alas, it doesn't.  Tru64 appears to miss all the
-    # signals at times, or seemingly random subsets of them, and
-    # nothing done in force_test_exit so far has actually helped.
-    def spawn_force_test_exit_process(self, parent_pid):
-        # Sigh, both imports seem necessary to avoid errors.
-        import os
-        fork_pid = os.fork()
-        if fork_pid:
-            # In parent.
-            return fork_pid
+def exit_subprocess():
+    """Use os._exit(0) to exit the current subprocess.
+
+    Otherwise, the test catches the SystemExit and continues executing
+    in parallel with the original test, so you wind up with an
+    exponential number of tests running concurrently.
+    """
+    os._exit(0)
 
-        # In child.
-        import os, time
-        try:
-            # Wait 5 seconds longer than the expected alarm to give enough
-            # time for the normal sequence of events to occur.  This is
-            # just a stop-gap to try to prevent the test from hanging.
-            time.sleep(self.MAX_DURATION + 5)
-            print("  child should not have to kill parent",
-                  file=sys.__stdout__)
-            for signame in "SIGHUP", "SIGUSR1", "SIGUSR2", "SIGALRM":
-                os.kill(parent_pid, getattr(signal, signame))
-                print("    child sent", signame, "to",
-                      parent_pid, file=sys.__stdout__)
-                time.sleep(1)
-        finally:
-            os._exit(0)
+
+class InterProcessSignalTests(unittest.TestCase):
+    MAX_DURATION = 20   # Entire test should last at most 20 sec.
 
     def handlerA(self, *args):
         self.a_called = True
@@ -51,127 +41,226 @@
             print("handlerB invoked", args)
         raise HandlerBCalled(*args)
 
-    def test_main(self):
-        self.assertEquals(signal.getsignal(signal.SIGHUP), self.handlerA)
-        self.assertEquals(signal.getsignal(signal.SIGUSR1), self.handlerB)
-        self.assertEquals(signal.getsignal(signal.SIGUSR2), signal.SIG_IGN)
-        self.assertEquals(signal.getsignal(signal.SIGALRM),
-                          signal.default_int_handler)
-
-        # Launch an external script to send us signals.
-        # We expect the external script to:
-        #    send HUP, which invokes handlerA to set a_called
-        #    send USR1, which invokes handlerB to set b_called and raise
-        #               HandlerBCalled
-        #    send USR2, which is ignored
-        #
-        # Then we expect the alarm to go off, and its handler raises
-        # KeyboardInterrupt, finally getting us out of the loop.
+    def wait(self, child):
+        """Wait for child to finish, ignoring EINTR."""
+        while True:
+            try:
+                child.wait()
+                return
+            except OSError as e:
+                if e.errno != errno.EINTR:
+                    raise
+
+    def run_test(self):
+        # Install handlers. This function runs in a sub-process, so we
+        # don't worry about re-setting the default handlers.
+        signal.signal(signal.SIGHUP, self.handlerA)
+        signal.signal(signal.SIGUSR1, self.handlerB)
+        signal.signal(signal.SIGUSR2, signal.SIG_IGN)
+        signal.signal(signal.SIGALRM, signal.default_int_handler)
 
-        if test_support.verbose:
-            verboseflag = '-x'
-        else:
-            verboseflag = '+x'
+        # Variables the signals will modify:
+        self.a_called = False
+        self.b_called = False
 
-        pid = self.pid
+        # Let the sub-processes know who to send signals to.
+        pid = os.getpid()
         if test_support.verbose:
             print("test runner's pid is", pid)
 
-        # Shell script that will send us asynchronous signals
-        script = """
-         (
-                set %(verboseflag)s
-                sleep 2
-                kill -HUP %(pid)d
-                sleep 2
-                kill -USR1 %(pid)d
-                sleep 2
-                kill -USR2 %(pid)d
-         ) &
-        """ % vars()
-
-        signal.alarm(self.MAX_DURATION)
-
-        handler_b_exception_raised = False
+        child = subprocess.Popen(['kill', '-HUP', str(pid)])
+        self.wait(child)
+        self.assertTrue(self.a_called)
+        self.assertFalse(self.b_called)
+        self.a_called = False
 
-        os.system(script)
         try:
+            child = subprocess.Popen(['kill', '-USR1', str(pid)])
+            # This wait should be interrupted by the signal's exception.
+            self.wait(child)
+            self.fail('HandlerBCalled exception not thrown')
+        except HandlerBCalled:
+            self.assertTrue(self.b_called)
+            self.assertFalse(self.a_called)
             if test_support.verbose:
-                print("starting pause() loop...")
-            while 1:
-                try:
-                    if test_support.verbose:
-                        print("call pause()...")
-                    signal.pause()
-                    if test_support.verbose:
-                        print("pause() returned")
-                except HandlerBCalled:
-                    handler_b_exception_raised = True
-                    if test_support.verbose:
-                        print("HandlerBCalled exception caught")
+                print("HandlerBCalled exception caught")
+
+        child = subprocess.Popen(['kill', '-USR2', str(pid)])
+        self.wait(child)  # Nothing should happen.
 
+        try:
+            signal.alarm(1)
+            # The race condition in pause doesn't matter in this case,
+            # since alarm is going to raise a KeyboardException, which
+            # will skip the call.
+            signal.pause()
         except KeyboardInterrupt:
             if test_support.verbose:
                 print("KeyboardInterrupt (the alarm() went off)")
-
-        self.assert_(self.a_called)
-        self.assert_(self.b_called)
-        self.assert_(handler_b_exception_raised)
-
-    def setUp(self):
-        # Install handlers.
-        self.hup = signal.signal(signal.SIGHUP, self.handlerA)
-        self.usr1 = signal.signal(signal.SIGUSR1, self.handlerB)
-        self.usr2 = signal.signal(signal.SIGUSR2, signal.SIG_IGN)
-        self.alrm = signal.signal(signal.SIGALRM,
-                                  signal.default_int_handler)
-        self.a_called = False
-        self.b_called = False
-        self.pid = os.getpid()
-        self.fork_pid = self.spawn_force_test_exit_process(self.pid)
-
-    def tearDown(self):
-        # Forcibly kill the child we created to ping us if there was a
-        # test error.
-        try:
-            # Make sure we don't kill ourself if there was a fork
-            # error.
-            if self.fork_pid > 0:
-                os.kill(self.fork_pid, signal.SIGKILL)
         except:
-            # If the child killed us, it has probably exited.  Killing
-            # a non-existent process will raise an error which we
-            # don't care about.
-            pass
-
-        # Restore handlers.
-        signal.alarm(0) # cancel alarm in case we died early
-        signal.signal(signal.SIGHUP, self.hup)
-        signal.signal(signal.SIGUSR1, self.usr1)
-        signal.signal(signal.SIGUSR2, self.usr2)
-        signal.signal(signal.SIGALRM, self.alrm)
+            self.fail('Some other exception woke us from pause: %s' %
+                      traceback.format_exc())
+        else:
+            self.fail('pause returned of its own accord')
+
+    def test_main(self):
+        # This function spawns a child process to insulate the main
+        # test-running process from all the signals. It then
+        # communicates with that child process over a pipe and
+        # re-raises information about any exceptions the child
+        # throws. The real work happens in self.run_test().
+        os_done_r, os_done_w = os.pipe()
+        with nested(closing(os.fdopen(os_done_r, 'rb')),
+                    closing(os.fdopen(os_done_w, 'wb'))) as (done_r, done_w):
+            child = os.fork()
+            if child == 0:
+                # In the child process; run the test and report results
+                # through the pipe.
+                try:
+                    done_r.close()
+                    # Have to close done_w again here because
+                    # exit_subprocess() will skip the enclosing with block.
+                    with closing(done_w):
+                        try:
+                            self.run_test()
+                        except:
+                            pickle.dump(traceback.format_exc(), done_w)
+                        else:
+                            pickle.dump(None, done_w)
+                except:
+                    print('Uh oh, raised from pickle.')
+                    traceback.print_exc()
+                finally:
+                    exit_subprocess()
+
+            done_w.close()
+            # Block for up to MAX_DURATION seconds for the test to finish.
+            r, w, x = select.select([done_r], [], [], self.MAX_DURATION)
+            if done_r in r:
+                tb = pickle.load(done_r)
+                if tb:
+                    self.fail(tb)
+            else:
+                os.kill(child, signal.SIGKILL)
+                self.fail('Test deadlocked after %d seconds.' %
+                          self.MAX_DURATION)
 
 
 class BasicSignalTests(unittest.TestCase):
+    def trivial_signal_handler(self, *args):
+        pass
+
     def test_out_of_range_signal_number_raises_error(self):
         self.assertRaises(ValueError, signal.getsignal, 4242)
 
-        def trivial_signal_handler(*args):
-            pass
-
         self.assertRaises(ValueError, signal.signal, 4242,
-                          trivial_signal_handler)
+                          self.trivial_signal_handler)
 
     def test_setting_signal_handler_to_none_raises_error(self):
         self.assertRaises(TypeError, signal.signal,
                           signal.SIGUSR1, None)
 
-def test_main():
-    if sys.platform[:3] in ('win', 'os2'):
-        raise test_support.TestSkipped("Can't test signal on %s" % \
-                                       sys.platform)
+    def test_getsignal(self):
+        hup = signal.signal(signal.SIGHUP, self.trivial_signal_handler)
+        self.assertEquals(signal.getsignal(signal.SIGHUP),
+                          self.trivial_signal_handler)
+        signal.signal(signal.SIGHUP, hup)
+        self.assertEquals(signal.getsignal(signal.SIGHUP), hup)
+
+
+class WakeupSignalTests(unittest.TestCase):
+    TIMEOUT_FULL = 10
+    TIMEOUT_HALF = 5
+
+    def test_wakeup_fd_early(self):
+        import select
+
+        signal.alarm(1)
+        before_time = time.time()
+        # We attempt to get a signal during the sleep,
+        # before select is called
+        time.sleep(self.TIMEOUT_FULL)
+        mid_time = time.time()
+        self.assert_(mid_time - before_time < self.TIMEOUT_HALF)
+        select.select([self.read], [], [], self.TIMEOUT_FULL)
+        after_time = time.time()
+        self.assert_(after_time - mid_time < self.TIMEOUT_HALF)
+
+    def test_wakeup_fd_during(self):
+        import select
+
+        signal.alarm(1)
+        before_time = time.time()
+        # We attempt to get a signal during the select call
+        self.assertRaises(select.error, select.select,
+            [self.read], [], [], self.TIMEOUT_FULL)
+        after_time = time.time()
+        self.assert_(after_time - before_time < self.TIMEOUT_HALF)
+
+    def setUp(self):
+        import fcntl
+
+        self.alrm = signal.signal(signal.SIGALRM, lambda x,y:None)
+        self.read, self.write = os.pipe()
+        flags = fcntl.fcntl(self.write, fcntl.F_GETFL, 0)
+        flags = flags | os.O_NONBLOCK
+        fcntl.fcntl(self.write, fcntl.F_SETFL, flags)
+        self.old_wakeup = signal.set_wakeup_fd(self.write)
+
+    def tearDown(self):
+        signal.set_wakeup_fd(self.old_wakeup)
+        os.close(self.read)
+        os.close(self.write)
+        signal.signal(signal.SIGALRM, self.alrm)
+
+class SiginterruptTest(unittest.TestCase):
+    signum = signal.SIGUSR1
+    def readpipe_interrupted(self, cb):
+        r, w = os.pipe()
+        ppid = os.getpid()
+        pid = os.fork()
+
+        oldhandler = signal.signal(self.signum, lambda x,y: None)
+        cb()
+        if pid==0:
+            # child code: sleep, kill, sleep. and then exit,
+            # which closes the pipe from which the parent process reads
+            try:
+                time.sleep(0.2)
+                os.kill(ppid, self.signum)
+                time.sleep(0.2)
+            finally:
+                exit_subprocess()
 
-    test_support.run_unittest(BasicSignalTests, InterProcessSignalTests)
+        try:
+            os.close(w)
+
+            try:
+                d=os.read(r, 1)
+                return False
+            except OSError as err:
+                if err.errno != errno.EINTR:
+                    raise
+                return True
+        finally:
+            signal.signal(self.signum, oldhandler)
+            os.waitpid(pid, 0)
+
+    def test_without_siginterrupt(self):
+        i=self.readpipe_interrupted(lambda: None)
+        self.assertEquals(i, True)
+
+    def test_siginterrupt_on(self):
+        i=self.readpipe_interrupted(lambda: signal.siginterrupt(self.signum, 1))
+        self.assertEquals(i, True)
+
+    def test_siginterrupt_off(self):
+        i=self.readpipe_interrupted(lambda: signal.siginterrupt(self.signum, 0))
+        self.assertEquals(i, False)
+
+def test_main():
+    test_support.run_unittest(BasicSignalTests, InterProcessSignalTests,
+        WakeupSignalTests, SiginterruptTest)
 
 
 if __name__ == "__main__":

Modified: python/branches/py3k-importlib/Lib/test/test_site.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_site.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_site.py	Thu Mar 27 00:48:05 2008
@@ -5,12 +5,11 @@
 
 """
 import unittest
-from test.test_support import TestSkipped, TestFailed, run_unittest, TESTFN
-import __builtin__
+from test.test_support import TestSkipped, run_unittest, TESTFN
+import builtins
 import os
 import sys
 import encodings
-import tempfile
 # Need to make sure to not import 'site' if someone specified ``-S`` at the
 # command-line.  Detect this by just making sure 'site' has not been imported
 # already.
@@ -162,7 +161,7 @@
         # as an absolute path.
         # Handled by abs__file__()
         site.abs__file__()
-        for module in (sys, os, __builtin__):
+        for module in (sys, os, builtins):
             try:
                 self.failUnless(os.path.isabs(module.__file__), repr(module))
             except AttributeError:
@@ -187,18 +186,18 @@
         pass
 
     def test_setting_quit(self):
-        # 'quit' and 'exit' should be injected into __builtin__
-        self.failUnless(hasattr(__builtin__, "quit"))
-        self.failUnless(hasattr(__builtin__, "exit"))
+        # 'quit' and 'exit' should be injected into builtins
+        self.failUnless(hasattr(builtins, "quit"))
+        self.failUnless(hasattr(builtins, "exit"))
 
     def test_setting_copyright(self):
-        # 'copyright' and 'credits' should be in __builtin__
-        self.failUnless(hasattr(__builtin__, "copyright"))
-        self.failUnless(hasattr(__builtin__, "credits"))
+        # 'copyright' and 'credits' should be in builtins
+        self.failUnless(hasattr(builtins, "copyright"))
+        self.failUnless(hasattr(builtins, "credits"))
 
     def test_setting_help(self):
-        # 'help' should be set in __builtin__
-        self.failUnless(hasattr(__builtin__, "help"))
+        # 'help' should be set in builtins
+        self.failUnless(hasattr(builtins, "help"))
 
     def test_aliasing_mbcs(self):
         if sys.platform == "win32":

Modified: python/branches/py3k-importlib/Lib/test/test_slice.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_slice.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_slice.py	Thu Mar 27 00:48:05 2008
@@ -92,7 +92,7 @@
         )
         self.assertEqual(slice(-100, 100, 2).indices(10), (0, 10,  2))
 
-        self.assertEqual(list(range(10))[::sys.maxint - 1], [0])
+        self.assertEqual(list(range(10))[::sys.maxsize - 1], [0])
 
         self.assertRaises(OverflowError, slice(None).indices, 1<<100)
 

Modified: python/branches/py3k-importlib/Lib/test/test_smtplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_smtplib.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_smtplib.py	Thu Mar 27 00:48:05 2008
@@ -18,14 +18,15 @@
 PORT = None
 
 def server(evt, buf):
+    serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    serv.settimeout(15)
+    serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+    serv.bind(("", 0))
+    global PORT
+    PORT = serv.getsockname()[1]
+    serv.listen(5)
+    evt.set()
     try:
-        serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        serv.settimeout(3)
-        serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-        serv.bind(("", 0))
-        global PORT
-        PORT = serv.getsockname()[1]
-        serv.listen(5)
         conn, addr = serv.accept()
     except socket.timeout:
         pass
@@ -38,7 +39,6 @@
                 buf = buf[sent:]
 
             n -= 1
-            time.sleep(0.01)
 
         conn.close()
     finally:
@@ -50,18 +50,10 @@
 
     def setUp(self):
         self.evt = threading.Event()
-        servargs = (self.evt, "220 Hola mundo\n")
+        servargs = (self.evt, b"220 Hola mundo\n")
         threading.Thread(target=server, args=servargs).start()
-
-        # wait until server thread has assigned a port number
-        n = 500
-        while PORT is None and n > 0:
-            time.sleep(0.01)
-            n -= 1
-
-        # wait a little longer (sometimes connections are refused
-        # on slow machines without this additional wait)
-        time.sleep(0.5)
+        self.evt.wait()
+        self.evt.clear()
 
     def tearDown(self):
         self.evt.wait()
@@ -76,28 +68,12 @@
         smtp = smtplib.SMTP("%s:%s" % (HOST, PORT))
         smtp.sock.close()
 
-    def testNotConnected(self):
-        # Test various operations on an unconnected SMTP object that
-        # should raise exceptions (at present the attempt in SMTP.send
-        # to reference the nonexistent 'sock' attribute of the SMTP object
-        # causes an AttributeError)
-        smtp = smtplib.SMTP()
-        self.assertRaises(AttributeError, smtp.ehlo)
-        self.assertRaises(AttributeError, smtp.send, 'test msg')
-
     def testLocalHostName(self):
         # check that supplied local_hostname is used
         smtp = smtplib.SMTP(HOST, PORT, local_hostname="testhost")
         self.assertEqual(smtp.local_hostname, "testhost")
         smtp.sock.close()
 
-    def testNonnumericPort(self):
-        # check that non-numeric port raises socket.error
-        self.assertRaises(socket.error, smtplib.SMTP,
-                          "localhost", "bogus")
-        self.assertRaises(socket.error, smtplib.SMTP,
-                          "localhost:bogus")
-
     def testTimeoutDefault(self):
         # default
         smtp = smtplib.SMTP(HOST, PORT)
@@ -127,6 +103,7 @@
     serv = server_class(("", 0), ('nowhere', -1))
     global PORT
     PORT = serv.getsockname()[1]
+    serv_evt.set()
 
     try:
         if hasattr(select, 'poll'):
@@ -149,12 +126,12 @@
     except socket.timeout:
         pass
     finally:
-        # allow some time for the client to read the result
-        time.sleep(0.5)
-        serv.close()
+        if not client_evt.isSet():
+            # allow some time for the client to read the result
+            time.sleep(0.5)
+            serv.close()
         asyncore.close_all()
         PORT = None
-        time.sleep(0.5)
         serv_evt.set()
 
 MSG_BEGIN = '---------- MESSAGE FOLLOWS ----------\n'
@@ -180,14 +157,8 @@
         threading.Thread(target=debugging_server, args=serv_args).start()
 
         # wait until server thread has assigned a port number
-        n = 500
-        while PORT is None and n > 0:
-            time.sleep(0.01)
-            n -= 1
-
-        # wait a little longer (sometimes connections are refused
-        # on slow machines without this additional wait)
-        time.sleep(0.5)
+        self.serv_evt.wait()
+        self.serv_evt.clear()
 
     def tearDown(self):
         # indicate that the client is finished
@@ -257,6 +228,26 @@
         self.assertEqual(self.output.getvalue(), mexpect)
 
 
+class NonConnectingTests(TestCase):
+
+    def testNotConnected(self):
+        # Test various operations on an unconnected SMTP object that
+        # should raise exceptions (at present the attempt in SMTP.send
+        # to reference the nonexistent 'sock' attribute of the SMTP object
+        # causes an AttributeError)
+        smtp = smtplib.SMTP()
+        self.assertRaises(smtplib.SMTPServerDisconnected, smtp.ehlo)
+        self.assertRaises(smtplib.SMTPServerDisconnected,
+                          smtp.send, 'test msg')
+
+    def testNonnumericPort(self):
+        # check that non-numeric port raises socket.error
+        self.assertRaises(socket.error, smtplib.SMTP,
+                          "localhost", "bogus")
+        self.assertRaises(socket.error, smtplib.SMTP,
+                          "localhost:bogus")
+
+
 # test response of client to a non-successful HELO message
 class BadHELOServerTests(TestCase):
 
@@ -268,16 +259,8 @@
         self.evt = threading.Event()
         servargs = (self.evt, b"199 no hello for you!\n")
         threading.Thread(target=server, args=servargs).start()
-
-        # wait until server thread has assigned a port number
-        n = 500
-        while PORT is None and n > 0:
-            time.sleep(0.01)
-            n -= 1
-
-        # wait a little longer (sometimes connections are refused
-        # on slow machines without this additional wait)
-        time.sleep(0.5)
+        self.evt.wait()
+        self.evt.clear()
 
     def tearDown(self):
         self.evt.wait()
@@ -354,14 +337,8 @@
         threading.Thread(target=debugging_server, args=serv_args).start()
 
         # wait until server thread has assigned a port number
-        n = 500
-        while PORT is None and n > 0:
-            time.sleep(0.01)
-            n -= 1
-
-        # wait a little longer (sometimes connections are refused
-        # on slow machines without this additional wait)
-        time.sleep(0.5)
+        self.serv_evt.wait()
+        self.serv_evt.clear()
 
     def tearDown(self):
         # indicate that the client is finished
@@ -371,11 +348,11 @@
 
     def testBasic(self):
         # smoke test
-        smtp = smtplib.SMTP(HOST, PORT, local_hostname='localhost', timeout=3)
+        smtp = smtplib.SMTP(HOST, PORT, local_hostname='localhost', timeout=15)
         smtp.quit()
 
     def testEHLO(self):
-        smtp = smtplib.SMTP(HOST, PORT, local_hostname='localhost', timeout=3)
+        smtp = smtplib.SMTP(HOST, PORT, local_hostname='localhost', timeout=15)
 
         # no features should be present before the EHLO
         self.assertEqual(smtp.esmtp_features, {})
@@ -396,7 +373,7 @@
         smtp.quit()
 
     def testVRFY(self):
-        smtp = smtplib.SMTP(HOST, PORT, local_hostname='localhost', timeout=3)
+        smtp = smtplib.SMTP(HOST, PORT, local_hostname='localhost', timeout=15)
 
         for email, name in sim_users.items():
             expected_known = (250, bytes('%s %s' %
@@ -411,7 +388,7 @@
         smtp.quit()
 
     def testEXPN(self):
-        smtp = smtplib.SMTP(HOST, PORT, local_hostname='localhost', timeout=3)
+        smtp = smtplib.SMTP(HOST, PORT, local_hostname='localhost', timeout=15)
 
         for listname, members in sim_lists.items():
             users = []
@@ -429,6 +406,7 @@
 
 def test_main(verbose=None):
     test_support.run_unittest(GeneralTests, DebuggingServerTests,
+                              NonConnectingTests,
                               BadHELOServerTests, SMTPSimTests)
 
 if __name__ == '__main__':

Modified: python/branches/py3k-importlib/Lib/test/test_socket.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_socket.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_socket.py	Thu Mar 27 00:48:05 2008
@@ -9,6 +9,8 @@
 import thread, threading
 import Queue
 import sys
+import os
+import array
 from weakref import proxy
 import signal
 
@@ -116,7 +118,7 @@
         self.__tearDown()
         self.done.wait()
 
-        if not self.queue.empty():
+        if self.queue.qsize():
             msg = self.queue.get()
             self.fail(msg)
 
@@ -286,7 +288,6 @@
 
     def testRefCountGetNameInfo(self):
         # Testing reference count for getnameinfo
-        import sys
         if hasattr(sys, "getrefcount"):
             try:
                 # On some versions, this loses a reference
@@ -338,7 +339,7 @@
         # I've ordered this by protocols that have both a tcp and udp
         # protocol, at least for modern Linuxes.
         if sys.platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
-                            'freebsd7', 'darwin'):
+                            'freebsd7', 'freebsd8', 'darwin'):
             # avoid the 'echo' service on this platform, as there is an
             # assumption breaking non-standard port/protocol entry
             services = ('daytime', 'qotd', 'domain')
@@ -498,7 +499,7 @@
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         sock.settimeout(1)
         sock.close()
-        self.assertRaises(socket.error, sock.send, "spam")
+        self.assertRaises(socket.error, sock.send, b"spam")
 
     def testNewAttributes(self):
         # testing .family, .type and .protocol
@@ -508,6 +509,15 @@
         self.assertEqual(sock.proto, 0)
         sock.close()
 
+    def test_sock_ioctl(self):
+        if os.name != "nt":
+            return
+        self.assert_(hasattr(socket.socket, 'ioctl'))
+        self.assert_(hasattr(socket, 'SIO_RCVALL'))
+        self.assert_(hasattr(socket, 'RCVALL_ON'))
+        self.assert_(hasattr(socket, 'RCVALL_OFF'))
+
+
 class BasicTCPTest(SocketConnectedTest):
 
     def __init__(self, methodName='runTest'):
@@ -575,6 +585,15 @@
     def _testFromFd(self):
         self.serv_conn.send(MSG)
 
+    def testDup(self):
+        # Testing dup()
+        sock = self.cli_conn.dup()
+        msg = sock.recv(1024)
+        self.assertEqual(msg, MSG)
+
+    def _testDup(self):
+        self.serv_conn.send(MSG)
+
     def testShutdown(self):
         # Testing shutdown()
         msg = self.cli_conn.recv(1024)
@@ -1094,6 +1113,85 @@
         buf = bytes(MSG)
         self.serv_conn.send(buf)
 
+
+TIPC_STYPE = 2000
+TIPC_LOWER = 200
+TIPC_UPPER = 210
+
+def isTipcAvailable():
+    """Check if the TIPC module is loaded
+
+    The TIPC module is not loaded automatically on Ubuntu and probably
+    other Linux distros.
+    """
+    if not hasattr(socket, "AF_TIPC"):
+        return False
+    if not os.path.isfile("/proc/modules"):
+        return False
+    with open("/proc/modules") as f:
+        for line in f:
+            if line.startswith("tipc "):
+                return True
+    if test_support.verbose:
+        print("TIPC module is not loaded, please 'sudo modprobe tipc'")
+    return False
+
+class TIPCTest (unittest.TestCase):
+    def testRDM(self):
+        srv = socket.socket(socket.AF_TIPC, socket.SOCK_RDM)
+        cli = socket.socket(socket.AF_TIPC, socket.SOCK_RDM)
+
+        srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+        srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE,
+                TIPC_LOWER, TIPC_UPPER)
+        srv.bind(srvaddr)
+
+        sendaddr = (socket.TIPC_ADDR_NAME, TIPC_STYPE,
+                TIPC_LOWER + int((TIPC_UPPER - TIPC_LOWER) / 2), 0)
+        cli.sendto(MSG, sendaddr)
+
+        msg, recvaddr = srv.recvfrom(1024)
+
+        self.assertEqual(cli.getsockname(), recvaddr)
+        self.assertEqual(msg, MSG)
+
+
+class TIPCThreadableTest (unittest.TestCase, ThreadableTest):
+    def __init__(self, methodName = 'runTest'):
+        unittest.TestCase.__init__(self, methodName = methodName)
+        ThreadableTest.__init__(self)
+
+    def setUp(self):
+        self.srv = socket.socket(socket.AF_TIPC, socket.SOCK_STREAM)
+        self.srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+        srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE,
+                TIPC_LOWER, TIPC_UPPER)
+        self.srv.bind(srvaddr)
+        self.srv.listen(5)
+        self.serverExplicitReady()
+        self.conn, self.connaddr = self.srv.accept()
+
+    def clientSetUp(self):
+        # The is a hittable race between serverExplicitReady() and the
+        # accept() call; sleep a little while to avoid it, otherwise
+        # we could get an exception
+        time.sleep(0.1)
+        self.cli = socket.socket(socket.AF_TIPC, socket.SOCK_STREAM)
+        addr = (socket.TIPC_ADDR_NAME, TIPC_STYPE,
+                TIPC_LOWER + int((TIPC_UPPER - TIPC_LOWER) / 2), 0)
+        self.cli.connect(addr)
+        self.cliaddr = self.cli.getsockname()
+
+    def testStream(self):
+        msg = self.conn.recv(1024)
+        self.assertEqual(msg, MSG)
+        self.assertEqual(self.cliaddr, self.connaddr)
+
+    def _testStream(self):
+        self.cli.send(MSG)
+        self.cli.close()
+
+
 def test_main():
     tests = [GeneralModuleTests, BasicTCPTest, TCPCloserTest, TCPTimeoutTest,
              TestExceptions, BufferIOTest, BasicTCPTest2]
@@ -1114,6 +1212,9 @@
         tests.append(BasicSocketPairTest)
     if sys.platform == 'linux2':
         tests.append(TestLinuxAbstractNamespace)
+    if isTipcAvailable():
+        tests.append(TIPCTest)
+        tests.append(TIPCThreadableTest)
 
     thread_info = test_support.threading_setup()
     test_support.run_unittest(*tests)

Deleted: /python/branches/py3k-importlib/Lib/test/test_socket_ssl.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/test_socket_ssl.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,237 +0,0 @@
-# Test just the SSL support in the socket module, in a moderately bogus way.
-
-import sys
-import unittest
-from test import test_support
-import socket
-import errno
-import threading
-import subprocess
-import time
-import os
-import urllib
-
-# Optionally test SSL support, if we have it in the tested platform
-skip_expected = not hasattr(socket, "ssl")
-
-class ConnectedTests(unittest.TestCase):
-
-    def testBasic(self):
-        socket.RAND_status()
-        try:
-            socket.RAND_egd(1)
-        except TypeError:
-            pass
-        else:
-            print("didn't raise TypeError")
-        socket.RAND_add("this is a random string", 75.0)
-
-        with test_support.transient_internet():
-            f = urllib.urlopen('https://sf.net')
-        buf = f.read()
-        f.close()
-
-    def testTimeout(self):
-        def error_msg(extra_msg):
-            print("""\
-        WARNING:  an attempt to connect to %r %s, in
-        test_timeout.  That may be legitimate, but is not the outcome we
-        hoped for.  If this message is seen often, test_timeout should be
-        changed to use a more reliable address.""" % (ADDR, extra_msg), file=sys.stderr)
-
-        # A service which issues a welcome banner (without need to write
-        # anything).
-        ADDR = "pop.gmail.com", 995
-
-        s = socket.socket()
-        s.settimeout(30.0)
-        try:
-            s.connect(ADDR)
-        except socket.timeout:
-            error_msg('timed out')
-            return
-        except socket.error as exc:  # In case connection is refused.
-            if exc.args[0] == errno.ECONNREFUSED:
-                error_msg('was refused')
-                return
-            else:
-                raise
-
-        ss = socket.ssl(s)
-        # Read part of return welcome banner twice.
-        ss.read(1)
-        ss.read(1)
-        s.close()
-
-class BasicTests(unittest.TestCase):
-
-    def testRudeShutdown(self):
-        # Some random port to connect to.
-        PORT = [9934]
-
-        listener_ready = threading.Event()
-        listener_gone = threading.Event()
-
-        # `listener` runs in a thread.  It opens a socket listening on
-        # PORT, and sits in an accept() until the main thread connects.
-        # Then it rudely closes the socket, and sets Event `listener_gone`
-        # to let the main thread know the socket is gone.
-        def listener():
-            s = socket.socket()
-            PORT[0] = test_support.bind_port(s, '', PORT[0])
-            s.listen(5)
-            listener_ready.set()
-            s.accept()
-            s = None # reclaim the socket object, which also closes it
-            listener_gone.set()
-
-        def connector():
-            listener_ready.wait()
-            s = socket.socket()
-            s.connect(('localhost', PORT[0]))
-            listener_gone.wait()
-            try:
-                ssl_sock = socket.ssl(s)
-            except socket.sslerror:
-                pass
-            else:
-                raise test_support.TestFailed(
-                      'connecting to closed SSL socket should have failed')
-
-        t = threading.Thread(target=listener)
-        t.start()
-        connector()
-        t.join()
-
-    def test_978833(self):
-        if test_support.verbose:
-            print("test_978833 ...")
-
-        import os, httplib, ssl
-        with test_support.transient_internet():
-            s = socket.socket(socket.AF_INET)
-            s.connect(("svn.python.org", 443))
-            fd = s.fileno()
-            sock = ssl.wrap_socket(s)
-            s = None
-            sock.close()
-            try:
-                os.fstat(fd)
-            except OSError:
-                pass
-            else:
-                raise test_support.TestFailed("Failed to close socket")
-
-class OpenSSLTests(unittest.TestCase):
-
-    def testBasic(self):
-        s = socket.socket()
-        s.connect(("localhost", 4433))
-        ss = socket.ssl(s)
-        ss.write("Foo\n")
-        i = ss.read(4)
-        self.assertEqual(i, "Foo\n")
-        s.close()
-
-    def testMethods(self):
-        # read & write is already tried in the Basic test
-        # now we'll try to get the server info about certificates
-        # this came from the certificate I used, one I found in /usr/share/openssl
-        info = "/C=PT/ST=Queensland/L=Lisboa/O=Neuronio, Lda./OU=Desenvolvimento/CN=brutus.neuronio.pt/emailAddress=sampo at iki.fi"
-
-        s = socket.socket()
-        s.connect(("localhost", 4433))
-        ss = socket.ssl(s)
-        cert = ss.server()
-        self.assertEqual(cert, info)
-        cert = ss.issuer()
-        self.assertEqual(cert, info)
-        s.close()
-
-
-class OpenSSLServer(threading.Thread):
-    def __init__(self):
-        self.s = None
-        self.keepServing = True
-        self._external()
-        if self.haveServer:
-            threading.Thread.__init__(self)
-
-    def _external(self):
-        # let's find the .pem files
-        curdir = os.path.dirname(__file__) or os.curdir
-        cert_file = os.path.join(curdir, "ssl_cert.pem")
-        if not os.access(cert_file, os.F_OK):
-            raise ValueError("No cert file found! (tried %r)" % cert_file)
-        key_file = os.path.join(curdir, "ssl_key.pem")
-        if not os.access(key_file, os.F_OK):
-            raise ValueError("No key file found! (tried %r)" % key_file)
-
-        try:
-            cmd = "openssl s_server -cert %s -key %s -quiet" % (cert_file, key_file)
-            self.s = subprocess.Popen(cmd.split(), stdin=subprocess.PIPE,
-                                       stdout=subprocess.PIPE,
-                                       stderr=subprocess.STDOUT)
-            time.sleep(1)
-        except:
-            self.haveServer = False
-        else:
-            # let's try if it is actually up
-            try:
-                s = socket.socket()
-                s.connect(("localhost", 4433))
-                s.close()
-                if self.s.stdout.readline() != "ERROR\n":
-                    raise ValueError
-            except:
-                self.haveServer = False
-            else:
-                self.haveServer = True
-
-    def run(self):
-        while self.keepServing:
-            time.sleep(.5)
-            l = self.s.stdout.readline()
-            self.s.stdin.write(l)
-
-    def shutdown(self):
-        self.keepServing = False
-        if not self.s:
-            return
-        if sys.platform == "win32":
-            subprocess.TerminateProcess(int(self.s._handle), -1)
-        else:
-            os.kill(self.s.pid, 15)
-
-def test_main():
-    if not hasattr(socket, "ssl"):
-        raise test_support.TestSkipped("socket module has no ssl support")
-
-    tests = [BasicTests]
-
-    if test_support.is_resource_enabled('network'):
-        tests.append(ConnectedTests)
-
-    # in these platforms we can kill the openssl process
-    if sys.platform in ("sunos5", "darwin", "linux1",
-                        "linux2", "win32", "hp-ux11"):
-
-        server = OpenSSLServer()
-        if server.haveServer:
-            tests.append(OpenSSLTests)
-            server.start()
-    else:
-        server = None
-
-    thread_info = test_support.threading_setup()
-
-    try:
-        test_support.run_unittest(*tests)
-    finally:
-        if server is not None and server.haveServer:
-            server.shutdown()
-
-    test_support.threading_cleanup(*thread_info)
-
-if __name__ == "__main__":
-    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_socketserver.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_socketserver.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_socketserver.py	Thu Mar 27 00:48:05 2008
@@ -1,44 +1,36 @@
-# Test suite for SocketServer.py
+"""
+Test suite for SocketServer.py.
+"""
 
-from test import test_support
-from test.test_support import (verbose, verify, TESTFN, TestSkipped,
-                               reap_children)
-test_support.requires('network')
-
-from SocketServer import *
-import socket
+import contextlib
 import errno
+import imp
+import os
 import select
-import time
+import signal
+import socket
+import tempfile
 import threading
-import os
+import time
+import unittest
+import SocketServer
+
+import test.test_support
+from test.test_support import reap_children, verbose, TestSkipped
+from test.test_support import TESTFN as TEST_FILE
 
-NREQ = 3
-DELAY = 0.5
+test.test_support.requires("network")
 
-class MyMixinHandler:
-    def handle(self):
-        time.sleep(DELAY)
-        line = self.rfile.readline()
-        time.sleep(DELAY)
-        self.wfile.write(line)
-
-class MyStreamHandler(MyMixinHandler, StreamRequestHandler):
-    pass
-
-class MyDatagramHandler(MyMixinHandler, DatagramRequestHandler):
-    pass
-
-class MyMixinServer:
-    def serve_a_few(self):
-        for i in range(NREQ):
-            self.handle_request()
-    def handle_error(self, request, client_address):
-        self.close_request(request)
-        self.server_close()
-        raise
+TEST_STR = b"hello world\n"
+HOST = "localhost"
 
-teststring = b"hello world\n"
+HAVE_UNIX_SOCKETS = hasattr(socket, "AF_UNIX")
+HAVE_FORKING = hasattr(os, "fork") and os.name != "os2"
+
+def signal_alarm(n):
+    """Call signal.alarm when it exists (i.e. not on Windows)."""
+    if hasattr(signal, 'alarm'):
+        signal.alarm(n)
 
 def receive(sock, n, timeout=20):
     r, w, x = select.select([sock], [], [], timeout)
@@ -47,177 +39,218 @@
     else:
         raise RuntimeError("timed out on %r" % (sock,))
 
-def testdgram(proto, addr):
-    s = socket.socket(proto, socket.SOCK_DGRAM)
-    s.sendto(teststring, addr)
-    buf = data = receive(s, 100)
-    while data and b'\n' not in buf:
-        data = receive(s, 100)
-        buf += data
-    verify(buf == teststring)
-    s.close()
-
-def teststream(proto, addr):
-    s = socket.socket(proto, socket.SOCK_STREAM)
-    s.connect(addr)
-    s.sendall(teststring)
-    buf = data = receive(s, 100)
-    while data and b'\n' not in buf:
-        data = receive(s, 100)
-        buf += data
-    verify(buf == teststring)
-    s.close()
-
-class ServerThread(threading.Thread):
-    def __init__(self, addr, svrcls, hdlrcls):
-        threading.Thread.__init__(self)
-        self.__addr = addr
-        self.__svrcls = svrcls
-        self.__hdlrcls = hdlrcls
-        self.ready = threading.Event()
-    def run(self):
-        class svrcls(MyMixinServer, self.__svrcls):
-            pass
-        if verbose: print("thread: creating server")
-        svr = svrcls(self.__addr, self.__hdlrcls)
-        # pull the address out of the server in case it changed
-        # this can happen if another process is using the port
-        addr = svr.server_address
-        if addr:
-            self.__addr = addr
-            if self.__addr != svr.socket.getsockname():
-                raise RuntimeError('server_address was %s, expected %s' %
-                                       (self.__addr, svr.socket.getsockname()))
-        self.ready.set()
-        if verbose: print("thread: serving three times")
-        svr.serve_a_few()
-        if verbose: print("thread: done")
-
-seed = 0
-def pickport():
-    global seed
-    seed += 1
-    return 10000 + (os.getpid() % 1000)*10 + seed
-
-host = "localhost"
-testfiles = []
-def pickaddr(proto):
-    if proto == socket.AF_INET:
-        return (host, pickport())
-    else:
-        fn = TESTFN + str(pickport())
-        if os.name == 'os2':
-            # AF_UNIX socket names on OS/2 require a specific prefix
-            # which can't include a drive letter and must also use
-            # backslashes as directory separators
-            if fn[1] == ':':
-                fn = fn[2:]
-            if fn[0] in (os.sep, os.altsep):
-                fn = fn[1:]
-            fn = os.path.join('\socket', fn)
-            if os.sep == '/':
-                fn = fn.replace(os.sep, os.altsep)
-            else:
-                fn = fn.replace(os.altsep, os.sep)
-        testfiles.append(fn)
-        return fn
-
-def cleanup():
-    for fn in testfiles:
-        try:
-            os.remove(fn)
-        except os.error:
-            pass
-    testfiles[:] = []
-
-def testloop(proto, servers, hdlrcls, testfunc):
-    for svrcls in servers:
-        addr = pickaddr(proto)
+if HAVE_UNIX_SOCKETS:
+    class ForkingUnixStreamServer(SocketServer.ForkingMixIn,
+                                  SocketServer.UnixStreamServer):
+        pass
+
+    class ForkingUnixDatagramServer(SocketServer.ForkingMixIn,
+                                    SocketServer.UnixDatagramServer):
+        pass
+
+
+ at contextlib.contextmanager
+def simple_subprocess(testcase):
+    pid = os.fork()
+    if pid == 0:
+        # Don't throw an exception; it would be caught by the test harness.
+        os._exit(72)
+    yield None
+    pid2, status = os.waitpid(pid, 0)
+    testcase.assertEquals(pid2, pid)
+    testcase.assertEquals(72 << 8, status)
+
+
+class SocketServerTest(unittest.TestCase):
+    """Test all socket servers."""
+
+    def setUp(self):
+        signal_alarm(20)  # Kill deadlocks after 20 seconds.
+        self.port_seed = 0
+        self.test_files = []
+
+    def tearDown(self):
+        signal_alarm(0)  # Didn't deadlock.
+        reap_children()
+
+        for fn in self.test_files:
+            try:
+                os.remove(fn)
+            except os.error:
+                pass
+        self.test_files[:] = []
+
+    def pickaddr(self, proto):
+        if proto == socket.AF_INET:
+            return (HOST, 0)
+        else:
+            # XXX: We need a way to tell AF_UNIX to pick its own name
+            # like AF_INET provides port==0.
+            dir = None
+            if os.name == 'os2':
+                dir = '\socket'
+            fn = tempfile.mktemp(prefix='unix_socket.', dir=dir)
+            if os.name == 'os2':
+                # AF_UNIX socket names on OS/2 require a specific prefix
+                # which can't include a drive letter and must also use
+                # backslashes as directory separators
+                if fn[1] == ':':
+                    fn = fn[2:]
+                if fn[0] in (os.sep, os.altsep):
+                    fn = fn[1:]
+                if os.sep == '/':
+                    fn = fn.replace(os.sep, os.altsep)
+                else:
+                    fn = fn.replace(os.altsep, os.sep)
+            self.test_files.append(fn)
+            return fn
+
+    def make_server(self, addr, svrcls, hdlrbase):
+        class MyServer(svrcls):
+            def handle_error(self, request, client_address):
+                self.close_request(request)
+                self.server_close()
+                raise
+
+        class MyHandler(hdlrbase):
+            def handle(self):
+                line = self.rfile.readline()
+                self.wfile.write(line)
+
+        if verbose: print("creating server")
+        server = MyServer(addr, MyHandler)
+        self.assertEquals(server.server_address, server.socket.getsockname())
+        return server
+
+    def run_server(self, svrcls, hdlrbase, testfunc):
+        server = self.make_server(self.pickaddr(svrcls.address_family),
+                                  svrcls, hdlrbase)
+        # We had the OS pick a port, so pull the real address out of
+        # the server.
+        addr = server.server_address
         if verbose:
             print("ADDR =", addr)
             print("CLASS =", svrcls)
-        t = ServerThread(addr, svrcls, hdlrcls)
-        if verbose: print("server created")
+
+        t = threading.Thread(
+            name='%s serving' % svrcls,
+            target=server.serve_forever,
+            # Short poll interval to make the test finish quickly.
+            # Time between requests is short enough that we won't wake
+            # up spuriously too many times.
+            kwargs={'poll_interval':0.01})
+        t.setDaemon(True)  # In case this function raises.
         t.start()
         if verbose: print("server running")
-        for i in range(NREQ):
-            t.ready.wait(10*DELAY)
-            if not t.ready.isSet():
-                raise RuntimeError("Server not ready within a reasonable time")
+        for i in range(3):
             if verbose: print("test client", i)
-            testfunc(proto, addr)
+            testfunc(svrcls.address_family, addr)
         if verbose: print("waiting for server")
+        server.shutdown()
         t.join()
         if verbose: print("done")
 
-class ForgivingTCPServer(TCPServer):
-    # prevent errors if another process is using the port we want
-    def server_bind(self):
-        host, default_port = self.server_address
-        # this code shamelessly stolen from test.test_support
-        # the ports were changed to protect the innocent
-        import sys
-        for port in [default_port, 3434, 8798, 23833]:
-            try:
-                self.server_address = host, port
-                TCPServer.server_bind(self)
-                break
-            except socket.error as e:
-                (err, msg) = e
-                if err != errno.EADDRINUSE:
-                    raise
-                print('  WARNING: failed to listen on port %d, trying another' % port, file=sys.__stderr__)
-
-tcpservers = [ForgivingTCPServer, ThreadingTCPServer]
-if hasattr(os, 'fork') and os.name not in ('os2',):
-    tcpservers.append(ForkingTCPServer)
-udpservers = [UDPServer, ThreadingUDPServer]
-if hasattr(os, 'fork') and os.name not in ('os2',):
-    udpservers.append(ForkingUDPServer)
-
-if not hasattr(socket, 'AF_UNIX'):
-    streamservers = []
-    dgramservers = []
-else:
-    class ForkingUnixStreamServer(ForkingMixIn, UnixStreamServer): pass
-    streamservers = [UnixStreamServer, ThreadingUnixStreamServer]
-    if hasattr(os, 'fork') and os.name not in ('os2',):
-        streamservers.append(ForkingUnixStreamServer)
-    class ForkingUnixDatagramServer(ForkingMixIn, UnixDatagramServer): pass
-    dgramservers = [UnixDatagramServer, ThreadingUnixDatagramServer]
-    if hasattr(os, 'fork') and os.name not in ('os2',):
-        dgramservers.append(ForkingUnixDatagramServer)
-
-def sloppy_cleanup():
-    # See http://python.org/sf/1540386
-    # We need to reap children here otherwise a child from one server
-    # can be left running for the next server and cause a test failure.
-    time.sleep(DELAY)
-    reap_children()
-
-def testall():
-    testloop(socket.AF_INET, tcpservers, MyStreamHandler, teststream)
-    sloppy_cleanup()
-    testloop(socket.AF_INET, udpservers, MyDatagramHandler, testdgram)
-    if hasattr(socket, 'AF_UNIX'):
-        sloppy_cleanup()
-        testloop(socket.AF_UNIX, streamservers, MyStreamHandler, teststream)
-        # Alas, on Linux (at least) recvfrom() doesn't return a meaningful
-        # client address so this cannot work:
-        ##testloop(socket.AF_UNIX, dgramservers, MyDatagramHandler, testdgram)
+    def stream_examine(self, proto, addr):
+        s = socket.socket(proto, socket.SOCK_STREAM)
+        s.connect(addr)
+        s.sendall(TEST_STR)
+        buf = data = receive(s, 100)
+        while data and b'\n' not in buf:
+            data = receive(s, 100)
+            buf += data
+        self.assertEquals(buf, TEST_STR)
+        s.close()
+
+    def dgram_examine(self, proto, addr):
+        s = socket.socket(proto, socket.SOCK_DGRAM)
+        s.sendto(TEST_STR, addr)
+        buf = data = receive(s, 100)
+        while data and b'\n' not in buf:
+            data = receive(s, 100)
+            buf += data
+        self.assertEquals(buf, TEST_STR)
+        s.close()
+
+    def test_TCPServer(self):
+        self.run_server(SocketServer.TCPServer,
+                        SocketServer.StreamRequestHandler,
+                        self.stream_examine)
+
+    def test_ThreadingTCPServer(self):
+        self.run_server(SocketServer.ThreadingTCPServer,
+                        SocketServer.StreamRequestHandler,
+                        self.stream_examine)
+
+    if HAVE_FORKING:
+        def test_ForkingTCPServer(self):
+            with simple_subprocess(self):
+                self.run_server(SocketServer.ForkingTCPServer,
+                                SocketServer.StreamRequestHandler,
+                                self.stream_examine)
+
+    if HAVE_UNIX_SOCKETS:
+        def test_UnixStreamServer(self):
+            self.run_server(SocketServer.UnixStreamServer,
+                            SocketServer.StreamRequestHandler,
+                            self.stream_examine)
+
+        def test_ThreadingUnixStreamServer(self):
+            self.run_server(SocketServer.ThreadingUnixStreamServer,
+                            SocketServer.StreamRequestHandler,
+                            self.stream_examine)
+
+        if HAVE_FORKING:
+            def test_ForkingUnixStreamServer(self):
+                with simple_subprocess(self):
+                    self.run_server(ForkingUnixStreamServer,
+                                    SocketServer.StreamRequestHandler,
+                                    self.stream_examine)
+
+    def test_UDPServer(self):
+        self.run_server(SocketServer.UDPServer,
+                        SocketServer.DatagramRequestHandler,
+                        self.dgram_examine)
+
+    def test_ThreadingUDPServer(self):
+        self.run_server(SocketServer.ThreadingUDPServer,
+                        SocketServer.DatagramRequestHandler,
+                        self.dgram_examine)
+
+    if HAVE_FORKING:
+        def test_ForkingUDPServer(self):
+            with simple_subprocess(self):
+                self.run_server(SocketServer.ForkingUDPServer,
+                                SocketServer.DatagramRequestHandler,
+                                self.dgram_examine)
+
+    # Alas, on Linux (at least) recvfrom() doesn't return a meaningful
+    # client address so this cannot work:
+
+    # if HAVE_UNIX_SOCKETS:
+    #     def test_UnixDatagramServer(self):
+    #         self.run_server(SocketServer.UnixDatagramServer,
+    #                         SocketServer.DatagramRequestHandler,
+    #                         self.dgram_examine)
+    #
+    #     def test_ThreadingUnixDatagramServer(self):
+    #         self.run_server(SocketServer.ThreadingUnixDatagramServer,
+    #                         SocketServer.DatagramRequestHandler,
+    #                         self.dgram_examine)
+    #
+    #     if HAVE_FORKING:
+    #         def test_ForkingUnixDatagramServer(self):
+    #             self.run_server(SocketServer.ForkingUnixDatagramServer,
+    #                             SocketServer.DatagramRequestHandler,
+    #                             self.dgram_examine)
+
 
 def test_main():
-    import imp
     if imp.lock_held():
-        # If the import lock is held, the threads will hang.
+        # If the import lock is held, the threads will hang
         raise TestSkipped("can't run when import lock is held")
 
-    reap_children()
-    try:
-        testall()
-    finally:
-        cleanup()
-    reap_children()
+    test.test_support.run_unittest(SocketServerTest)
 
 if __name__ == "__main__":
     test_main()
+    signal_alarm(3)  # Shutdown shouldn't take more than 3 seconds.

Modified: python/branches/py3k-importlib/Lib/test/test_sort.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_sort.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_sort.py	Thu Mar 27 00:48:05 2008
@@ -6,6 +6,15 @@
 verbose = test_support.verbose
 nerrors = 0
 
+def CmpToKey(mycmp):
+    'Convert a cmp= function into a key= function'
+    class K(object):
+        def __init__(self, obj):
+            self.obj = obj
+        def __lt__(self, other):
+            return mycmp(self.obj, other.obj) == -1
+    return K
+
 def check(tag, expected, raw, compare=None):
     global nerrors
 
@@ -14,7 +23,7 @@
 
     orig = raw[:]   # save input in case of error
     if compare:
-        raw.sort(compare)
+        raw.sort(key=CmpToKey(compare))
     else:
         raw.sort()
 
@@ -99,7 +108,7 @@
                 print("    Checking against an insane comparison function.")
                 print("        If the implementation isn't careful, this may segfault.")
             s = x[:]
-            s.sort(lambda a, b:  int(random.random() * 3) - 1)
+            s.sort(key=CmpToKey(lambda a, b:  int(random.random() * 3) - 1))
             check("an insane function left some permutation", x, s)
 
             x = [Complains(i) for i in x]
@@ -141,14 +150,6 @@
         L = [C() for i in range(50)]
         self.assertRaises(ValueError, L.sort)
 
-    def test_cmpNone(self):
-        # Testing None as a comparison function.
-
-        L = list(range(50))
-        random.shuffle(L)
-        L.sort(None)
-        self.assertEqual(L, list(range(50)))
-
     def test_undetected_mutation(self):
         # Python 2.4a1 did not always detect mutation
         memorywaster = []
@@ -158,12 +159,12 @@
                 L.pop()
                 return cmp(x, y)
             L = [1,2]
-            self.assertRaises(ValueError, L.sort, mutating_cmp)
+            self.assertRaises(ValueError, L.sort, key=CmpToKey(mutating_cmp))
             def mutating_cmp(x, y):
                 L.append(3)
                 del L[:]
                 return cmp(x, y)
-            self.assertRaises(ValueError, L.sort, mutating_cmp)
+            self.assertRaises(ValueError, L.sort, key=CmpToKey(mutating_cmp))
             memorywaster = [memorywaster]
 
 #==============================================================================
@@ -175,11 +176,11 @@
         copy = data[:]
         random.shuffle(data)
         data.sort(key=str.lower)
-        copy.sort(cmp=lambda x,y: cmp(x.lower(), y.lower()))
+        copy.sort(key=CmpToKey(lambda x,y: cmp(x.lower(), y.lower())))
 
     def test_baddecorator(self):
         data = 'The quick Brown fox Jumped over The lazy Dog'.split()
-        self.assertRaises(TypeError, data.sort, None, lambda x,y: 0)
+        self.assertRaises(TypeError, data.sort, key=lambda x,y: 0)
 
     def test_stability(self):
         data = [(random.randrange(100), i) for i in range(200)]
@@ -188,25 +189,11 @@
         copy.sort()                     # sort using both fields
         self.assertEqual(data, copy)    # should get the same result
 
-    def test_cmp_and_key_combination(self):
-        # Verify that the wrapper has been removed
-        def compare(x, y):
-            self.assertEqual(type(x), str)
-            self.assertEqual(type(x), str)
-            return cmp(x, y)
-        data = 'The quick Brown fox Jumped over The lazy Dog'.split()
-        data.sort(cmp=compare, key=str.lower)
-
-    def test_badcmp_with_key(self):
-        # Verify that the wrapper has been removed
-        data = 'The quick Brown fox Jumped over The lazy Dog'.split()
-        self.assertRaises(TypeError, data.sort, "bad", str.lower)
-
     def test_key_with_exception(self):
         # Verify that the wrapper has been removed
         data = list(range(-2, 2))
         dup = data[:]
-        self.assertRaises(ZeroDivisionError, data.sort, None, lambda x: 1/x)
+        self.assertRaises(ZeroDivisionError, data.sort, key=lambda x: 1/x)
         self.assertEqual(data, dup)
 
     def test_key_with_mutation(self):
@@ -254,14 +241,13 @@
         random.shuffle(data)
         data.sort(reverse=True)
         self.assertEqual(data, list(range(99,-1,-1)))
-        self.assertRaises(TypeError, data.sort, "wrong type")
 
     def test_reverse_stability(self):
         data = [(random.randrange(100), i) for i in range(200)]
         copy1 = data[:]
         copy2 = data[:]
-        data.sort(cmp=lambda x,y: cmp(x[0],y[0]), reverse=True)
-        copy1.sort(cmp=lambda x,y: cmp(y[0],x[0]))
+        data.sort(key=CmpToKey(lambda x,y: cmp(x[0],y[0])), reverse=True)
+        copy1.sort(key=CmpToKey(lambda x,y: cmp(y[0],x[0])))
         self.assertEqual(data, copy1)
         copy2.sort(key=lambda x: x[0], reverse=True)
         self.assertEqual(data, copy2)

Modified: python/branches/py3k-importlib/Lib/test/test_sqlite.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_sqlite.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_sqlite.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,4 @@
 from test.test_support import run_unittest, TestSkipped
-import unittest
 
 try:
     import _sqlite3

Modified: python/branches/py3k-importlib/Lib/test/test_ssl.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_ssl.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_ssl.py	Thu Mar 27 00:48:05 2008
@@ -4,6 +4,7 @@
 import unittest
 from test import test_support
 import socket
+import select
 import errno
 import subprocess
 import time
@@ -12,6 +13,7 @@
 import urllib, urlparse
 import shutil
 import traceback
+import asyncore
 
 from BaseHTTPServer import HTTPServer
 from SimpleHTTPServer import SimpleHTTPRequestHandler
@@ -37,7 +39,8 @@
 class BasicTests(unittest.TestCase):
 
     def testSSLconnect(self):
-        import os
+        if not test_support.is_resource_enabled('network'):
+            return
         s = ssl.wrap_socket(socket.socket(socket.AF_INET),
                             cert_reqs=ssl.CERT_NONE)
         s.connect(("svn.python.org", 443))
@@ -56,7 +59,6 @@
         finally:
             s.close()
 
-
     def testCrucialConstants(self):
         ssl.PROTOCOL_SSLv2
         ssl.PROTOCOL_SSLv23
@@ -97,11 +99,9 @@
         if (d1 != d2):
             raise test_support.TestFailed("PEM-to-DER or DER-to-PEM translation failed")
 
-
-class NetworkTests(unittest.TestCase):
+class NetworkedTests(unittest.TestCase):
 
     def testConnect(self):
-        import os
         s = ssl.wrap_socket(socket.socket(socket.AF_INET),
                             cert_reqs=ssl.CERT_NONE)
         s.connect(("svn.python.org", 443))
@@ -131,17 +131,44 @@
         finally:
             s.close()
 
+    def testNonBlockingHandshake(self):
+        s = socket.socket(socket.AF_INET)
+        s.connect(("svn.python.org", 443))
+        s.setblocking(False)
+        s = ssl.wrap_socket(s,
+                            cert_reqs=ssl.CERT_NONE,
+                            do_handshake_on_connect=False)
+        count = 0
+        while True:
+            try:
+                count += 1
+                s.do_handshake()
+                break
+            except ssl.SSLError as err:
+                if err.args[0] == ssl.SSL_ERROR_WANT_READ:
+                    select.select([s], [], [])
+                elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
+                    select.select([], [s], [])
+                else:
+                    raise
+        s.close()
+        if test_support.verbose:
+            sys.stdout.write("\nNeeded %d calls to do_handshake() to establish session.\n" % count)
+
     def testFetchServerCert(self):
 
         pem = ssl.get_server_certificate(("svn.python.org", 443))
         if not pem:
             raise test_support.TestFailed("No server certificate on svn.python.org:443!")
 
+        return
+
         try:
             pem = ssl.get_server_certificate(("svn.python.org", 443), ca_certs=CERTFILE)
-        except ssl.SSLError:
+        except ssl.SSLError as x:
             #should fail
-            pass
+            if test_support.verbose:
+                sys.stdout.write("%s\n" % x)
         else:
             raise test_support.TestFailed("Got server certificate %s for svn.python.org!" % pem)
 
@@ -168,10 +195,11 @@
             with and without the SSL wrapper around the socket connection, so
             that we can test the STARTTLS functionality."""
 
-            def __init__(self, server, connsock):
+            def __init__(self, server, connsock, addr):
                 self.server = server
                 self.running = False
                 self.sock = connsock
+                self.addr = addr
                 self.sock.setblocking(1)
                 self.sslconn = None
                 threading.Thread.__init__(self)
@@ -186,8 +214,7 @@
                                                    cert_reqs=self.server.certreqs)
                 except:
                     if self.server.chatty:
-                        handle_error("\n server:  bad connection attempt from " +
-                                     str(self.sock.getpeername()) + ":\n")
+                        handle_error("\n server:  bad connection attempt from " + repr(self.addr) + ":\n")
                     if not self.server.expect_bad_connects:
                         # here, we want to stop the server, because this shouldn't
                         # happen in the context of our test case
@@ -195,6 +222,7 @@
                         # normally, we'd just stop here, but for the test
                         # harness, we want to stop the server
                         self.server.stop()
+                    self.close()
                     return False
 
                 else:
@@ -236,19 +264,21 @@
                 while self.running:
                     try:
                         msg = self.read()
+                        amsg = (msg and str(msg, 'ASCII', 'strict')) or ''
                         if not msg:
                             # eof, so quit this handler
                             self.running = False
                             self.close()
-                        elif msg.strip() == 'over':
+                        elif amsg.strip() == 'over':
                             if test_support.verbose and self.server.connectionchatty:
                                 sys.stdout.write(" server: client closed connection\n")
                             self.close()
                             return
-                        elif self.server.starttls_server and msg.strip() == 'STARTTLS':
+                        elif (self.server.starttls_server and
+                              amsg.strip() == 'STARTTLS'):
                             if test_support.verbose and self.server.connectionchatty:
                                 sys.stdout.write(" server: read STARTTLS from client, sending OK...\n")
-                            self.write("OK\n")
+                            self.write("OK\n".encode("ASCII", "strict"))
                             if not self.wrap_conn():
                                 return
                         else:
@@ -257,8 +287,8 @@
                                 ctype = (self.sslconn and "encrypted") or "unencrypted"
                                 sys.stdout.write(" server: read %s (%s), sending back %s (%s)...\n"
                                                  % (repr(msg), ctype, repr(msg.lower()), ctype))
-                            self.write(msg.lower())
-                    except ssl.SSLError:
+                            self.write(amsg.lower().encode('ASCII', 'strict'))
+                    except socket.error:
                         if self.server.chatty:
                             handle_error("Test server failure:\n")
                         self.close()
@@ -311,8 +341,8 @@
                     newconn, connaddr = self.sock.accept()
                     if test_support.verbose and self.chatty:
                         sys.stdout.write(' server:  new connection from '
-                                         + str(connaddr) + '\n')
-                    handler = self.ConnectionHandler(self, newconn)
+                                         + repr(connaddr) + '\n')
+                    handler = self.ConnectionHandler(self, newconn, connaddr)
                     handler.start()
                 except socket.timeout:
                     pass
@@ -321,13 +351,14 @@
                 except:
                     if self.chatty:
                         handle_error("Test server failure:\n")
+            self.sock.close()
 
         def stop (self):
             self.active = False
-            self.sock.close()
 
+    class OurHTTPSServer(threading.Thread):
 
-    class AsyncoreHTTPSServer(threading.Thread):
+        # This one's based on HTTPServer, which is based on SocketServer
 
         class HTTPSServer(HTTPServer):
 
@@ -337,8 +368,15 @@
                 # we assume the certfile contains both private key and certificate
                 self.certfile = certfile
                 self.active = False
+                self.active_lock = threading.Lock()
                 self.allow_reuse_address = True
 
+            def __str__(self):
+                return ('<%s %s:%s>' %
+                        (self.__class__.__name__,
+                         self.server_name,
+                         self.server_port))
+
             def get_request (self):
                 # override this to wrap socket with SSL
                 sock, addr = self.socket.accept()
@@ -361,23 +399,32 @@
                 # We want this to run in a thread, so we use a slightly
                 # modified version of "forever".
                 self.active = True
-                while self.active:
+                while 1:
                     try:
-                        self.handle_request()
+                        # We need to lock while handling the request.
+                        # Another thread can close the socket after self.active
+                        # has been checked and before the request is handled.
+                        # This causes an exception when using the closed socket.
+                        with self.active_lock:
+                            if not self.active:
+                                break
+                            self.handle_request()
                     except socket.timeout:
                         pass
                     except KeyboardInterrupt:
                         self.server_close()
                         return
                     except:
-                        sys.stdout.write(''.join(traceback.format_exception(*sys.exc_info())));
+                        sys.stdout.write(''.join(traceback.format_exception(*sys.exc_info())))
+                        break
 
             def server_close(self):
                 # Again, we want this to run in a thread, so we need to override
                 # close to clear the "active" flag, so that serve_forever() will
                 # terminate.
-                HTTPServer.server_close(self)
-                self.active = False
+                with self.active_lock:
+                    HTTPServer.server_close(self)
+                    self.active = False
 
         class RootedHTTPRequestHandler(SimpleHTTPRequestHandler):
 
@@ -415,8 +462,8 @@
                 # we override this to suppress logging unless "verbose"
 
                 if test_support.verbose:
-                    sys.stdout.write(" server (%s, %d, %s):\n   [%s] %s\n" %
-                                     (self.server.server_name,
+                    sys.stdout.write(" server (%s:%d %s):\n   [%s] %s\n" %
+                                     (self.server.server_address,
                                       self.server.server_port,
                                       self.request.cipher(),
                                       self.log_date_time_string(),
@@ -433,9 +480,7 @@
             self.setDaemon(True)
 
         def __str__(self):
-            return '<%s %s:%d>' % (self.__class__.__name__,
-                                   self.server.server_name,
-                                   self.server.server_port)
+            return "<%s %s>" % (self.__class__.__name__, self.server)
 
         def start (self, flag=None):
             self.flag = flag
@@ -453,10 +498,97 @@
             self.server.server_close()
 
 
+    class AsyncoreEchoServer(threading.Thread):
+
+        # this one's based on asyncore.dispatcher
+
+        class EchoServer (asyncore.dispatcher):
+
+            class ConnectionHandler (asyncore.dispatcher_with_send):
+
+                def __init__(self, conn, certfile):
+                    self.socket = ssl.wrap_socket(conn, server_side=True,
+                                                  certfile=certfile,
+                                                  do_handshake_on_connect=False)
+                    asyncore.dispatcher_with_send.__init__(self, self.socket)
+                    # now we have to do the handshake
+                    # we'll just do it the easy way, and block the connection
+                    # till it's finished.  If we were doing it right, we'd
+                    # do this in multiple calls to handle_read...
+                    self.do_handshake(block=True)
+
+                def readable(self):
+                    if isinstance(self.socket, ssl.SSLSocket):
+                        while self.socket.pending() > 0:
+                            self.handle_read_event()
+                    return True
+
+                def handle_read(self):
+                    data = self.recv(1024)
+                    if test_support.verbose:
+                        sys.stdout.write(" server:  read %s from client\n" % repr(data))
+                    if not data:
+                        self.close()
+                    else:
+                        self.send(str(data, 'ASCII', 'strict').lower().encode('ASCII', 'strict'))
+
+                def handle_close(self):
+                    if test_support.verbose:
+                        sys.stdout.write(" server:  closed connection %s\n" % self.socket)
+
+                def handle_error(self):
+                    raise
+
+            def __init__(self, port, certfile):
+                self.port = port
+                self.certfile = certfile
+                asyncore.dispatcher.__init__(self)
+                self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
+                self.bind(('', port))
+                self.listen(5)
+
+            def handle_accept(self):
+                sock_obj, addr = self.accept()
+                if test_support.verbose:
+                    sys.stdout.write(" server:  new connection from %s:%s\n" %addr)
+                self.ConnectionHandler(sock_obj, self.certfile)
+
+            def handle_error(self):
+                raise
+
+        def __init__(self, port, certfile):
+            self.flag = None
+            self.active = False
+            self.server = self.EchoServer(port, certfile)
+            threading.Thread.__init__(self)
+            self.setDaemon(True)
+
+        def __str__(self):
+            return "<%s %s>" % (self.__class__.__name__, self.server)
+
+        def start (self, flag=None):
+            self.flag = flag
+            threading.Thread.start(self)
+
+        def run (self):
+            self.active = True
+            if self.flag:
+                self.flag.set()
+            while self.active:
+                try:
+                    asyncore.loop(1)
+                except:
+                    pass
+
+        def stop (self):
+            self.active = False
+            self.server.close()
+
     def badCertTest (certfile):
         server = ThreadedEchoServer(TESTPORT, CERTFILE,
                                     certreqs=ssl.CERT_REQUIRED,
-                                    cacerts=CERTFILE, chatty=False)
+                                    cacerts=CERTFILE, chatty=False,
+                                    connectionchatty=False)
         flag = threading.Event()
         server.start(flag)
         # wait for it to start
@@ -470,7 +602,7 @@
                 s.connect(('127.0.0.1', TESTPORT))
             except ssl.SSLError as x:
                 if test_support.verbose:
-                    sys.stdout.write("\nSSLError is %s\n" % x[1])
+                    sys.stdout.write("\nSSLError is %s\n" % x)
             else:
                 raise test_support.TestFailed(
                     "Use of invalid cert should have failed!")
@@ -479,15 +611,16 @@
             server.join()
 
     def serverParamsTest (certfile, protocol, certreqs, cacertsfile,
-                          client_certfile, client_protocol=None, indata="FOO\n",
-                          chatty=True, connectionchatty=False):
+                          client_certfile, client_protocol=None,
+                          indata="FOO\n",
+                          chatty=False, connectionchatty=False):
 
         server = ThreadedEchoServer(TESTPORT, certfile,
                                     certreqs=certreqs,
                                     ssl_version=protocol,
                                     cacerts=cacertsfile,
                                     chatty=chatty,
-                                    connectionchatty=connectionchatty)
+                                    connectionchatty=False)
         flag = threading.Event()
         server.start(flag)
         # wait for it to start
@@ -496,37 +629,38 @@
         if client_protocol is None:
             client_protocol = protocol
         try:
-            try:
-                s = ssl.wrap_socket(socket.socket(),
-                                    certfile=client_certfile,
-                                    ca_certs=cacertsfile,
-                                    cert_reqs=certreqs,
-                                    ssl_version=client_protocol)
-                s.connect(('127.0.0.1', TESTPORT))
-            except ssl.SSLError as x:
-                raise test_support.TestFailed("Unexpected SSL error:  " + str(x))
-            except Exception as x:
-                raise test_support.TestFailed("Unexpected exception:  " + str(x))
-            else:
-                if connectionchatty:
-                    if test_support.verbose:
-                        sys.stdout.write(
-                            " client:  sending %s...\n" % (repr(indata)))
-                s.write(indata)
-                outdata = s.read()
-                if connectionchatty:
-                    if test_support.verbose:
-                        sys.stdout.write(" client:  read %s\n" % repr(outdata))
-                if outdata != indata.lower():
-                    raise test_support.TestFailed(
-                        "bad data <<%s>> (%d) received; expected <<%s>> (%d)\n"
-                        % (outdata[:min(len(outdata),20)], len(outdata),
-                           indata[:min(len(indata),20)].lower(), len(indata)))
-                s.write("over\n")
-                if connectionchatty:
-                    if test_support.verbose:
-                        sys.stdout.write(" client:  closing connection.\n")
-                s.close()
+            s = ssl.wrap_socket(socket.socket(),
+                                server_side=False,
+                                certfile=client_certfile,
+                                ca_certs=cacertsfile,
+                                cert_reqs=certreqs,
+                                ssl_version=client_protocol)
+            s.connect(('127.0.0.1', TESTPORT))
+        except ssl.SSLError as x:
+            raise test_support.TestFailed("Unexpected SSL error:  " + str(x))
+        except Exception as x:
+            raise test_support.TestFailed("Unexpected exception:  " + str(x))
+        else:
+            if connectionchatty:
+                if test_support.verbose:
+                    sys.stdout.write(
+                        " client:  sending %s...\n" % (repr(indata)))
+            s.write(indata.encode('ASCII', 'strict'))
+            outdata = s.read()
+            if connectionchatty:
+                if test_support.verbose:
+                    sys.stdout.write(" client:  read %s\n" % repr(outdata))
+            outdata = str(outdata, 'ASCII', 'strict')
+            if outdata != indata.lower():
+                raise test_support.TestFailed(
+                    "bad data <<%s>> (%d) received; expected <<%s>> (%d)\n"
+                    % (repr(outdata[:min(len(outdata),20)]), len(outdata),
+                       repr(indata[:min(len(indata),20)].lower()), len(indata)))
+            s.write("over\n".encode("ASCII", "strict"))
+            if connectionchatty:
+                if test_support.verbose:
+                    sys.stdout.write(" client:  closing connection.\n")
+            s.close()
         finally:
             server.stop()
             server.join()
@@ -553,7 +687,8 @@
                               certtype))
         try:
             serverParamsTest(CERTFILE, server_protocol, certsreqs,
-                             CERTFILE, CERTFILE, client_protocol, chatty=False)
+                             CERTFILE, CERTFILE, client_protocol,
+                             chatty=False, connectionchatty=False)
         except test_support.TestFailed:
             if expectedToWork:
                 raise
@@ -565,47 +700,7 @@
                        ssl.get_protocol_name(server_protocol)))
 
 
-    class ConnectedTests(unittest.TestCase):
-
-        def testRudeShutdown(self):
-
-            listener_ready = threading.Event()
-            listener_gone = threading.Event()
-
-            # `listener` runs in a thread.  It opens a socket listening on
-            # PORT, and sits in an accept() until the main thread connects.
-            # Then it rudely closes the socket, and sets Event `listener_gone`
-            # to let the main thread know the socket is gone.
-            def listener():
-                s = socket.socket()
-                if hasattr(socket, 'SO_REUSEADDR'):
-                    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-                if hasattr(socket, 'SO_REUSEPORT'):
-                    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
-                s.bind(('127.0.0.1', TESTPORT))
-                s.listen(5)
-                listener_ready.set()
-                s.accept()
-                s = None # reclaim the socket object, which also closes it
-                listener_gone.set()
-
-            def connector():
-                listener_ready.wait()
-                s = socket.socket()
-                s.connect(('127.0.0.1', TESTPORT))
-                listener_gone.wait()
-                try:
-                    ssl_sock = ssl.wrap_socket(s)
-                except socket.sslerror:
-                    pass
-                else:
-                    raise test_support.TestFailed(
-                          'connecting to closed SSL socket should have failed')
-
-            t = threading.Thread(target=listener)
-            t.start()
-            connector()
-            t.join()
+    class ThreadedTests(unittest.TestCase):
 
         def testEcho (self):
 
@@ -656,7 +751,7 @@
                     if test_support.verbose:
                         sys.stdout.write(pprint.pformat(cert) + '\n')
                         sys.stdout.write("Connection cipher is " + str(cipher) + '.\n')
-                    if not cert.has_key('subject'):
+                    if 'subject' not in cert:
                         raise test_support.TestFailed(
                             "No subject field in certificate: %s." %
                             pprint.pformat(cert))
@@ -664,7 +759,7 @@
                         not in cert['subject']):
                         raise test_support.TestFailed(
                             "Missing or invalid 'organizationName' field in certificate subject; "
-                            "should be 'Python Software Foundation'.");
+                            "should be 'Python Software Foundation'.")
                     s.close()
             finally:
                 server.stop()
@@ -680,6 +775,46 @@
             badCertTest(os.path.join(os.path.dirname(__file__) or os.curdir,
                                      "badkey.pem"))
 
+        def testRudeShutdown(self):
+
+            listener_ready = threading.Event()
+            listener_gone = threading.Event()
+
+            # `listener` runs in a thread.  It opens a socket listening on
+            # PORT, and sits in an accept() until the main thread connects.
+            # Then it rudely closes the socket, and sets Event `listener_gone`
+            # to let the main thread know the socket is gone.
+            def listener():
+                s = socket.socket()
+                if hasattr(socket, 'SO_REUSEADDR'):
+                    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+                if hasattr(socket, 'SO_REUSEPORT'):
+                    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
+                s.bind(('127.0.0.1', TESTPORT))
+                s.listen(5)
+                listener_ready.set()
+                s.accept()
+                s = None # reclaim the socket object, which also closes it
+                listener_gone.set()
+
+            def connector():
+                listener_ready.wait()
+                s = socket.socket()
+                s.connect(('127.0.0.1', TESTPORT))
+                listener_gone.wait()
+                try:
+                    ssl_sock = ssl.wrap_socket(s)
+                except IOError:
+                    pass
+                else:
+                    raise test_support.TestFailed(
+                          'connecting to closed SSL socket should have failed')
+
+            t = threading.Thread(target=listener)
+            t.start()
+            connector()
+            t.join()
+
         def testProtocolSSL2(self):
             if test_support.verbose:
                 sys.stdout.write("\n")
@@ -759,42 +894,48 @@
                     if test_support.verbose:
                         sys.stdout.write("\n")
                     for indata in msgs:
+                        msg = indata.encode('ASCII', 'replace')
                         if test_support.verbose:
                             sys.stdout.write(
-                                " client:  sending %s...\n" % repr(indata))
+                                " client:  sending %s...\n" % repr(msg))
                         if wrapped:
-                            conn.write(indata)
+                            conn.write(msg)
                             outdata = conn.read()
                         else:
-                            s.send(indata)
+                            s.send(msg)
                             outdata = s.recv(1024)
                         if (indata == "STARTTLS" and
-                            outdata.strip().lower().startswith("ok")):
+                            str(outdata, 'ASCII', 'replace').strip().lower().startswith("ok")):
                             if test_support.verbose:
+                                msg = str(outdata, 'ASCII', 'replace')
                                 sys.stdout.write(
                                     " client:  read %s from server, starting TLS...\n"
-                                    % repr(outdata))
+                                    % repr(msg))
                             conn = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_TLSv1)
 
                             wrapped = True
                         else:
                             if test_support.verbose:
+                                msg = str(outdata, 'ASCII', 'replace')
                                 sys.stdout.write(
-                                    " client:  read %s from server\n" % repr(outdata))
+                                    " client:  read %s from server\n" % repr(msg))
                     if test_support.verbose:
                         sys.stdout.write(" client:  closing connection.\n")
                     if wrapped:
-                        conn.write("over\n")
+                        conn.write("over\n".encode("ASCII", "strict"))
                     else:
                         s.send("over\n")
+                if wrapped:
+                    conn.close()
+                else:
                     s.close()
             finally:
                 server.stop()
                 server.join()
 
-        def testAsyncore(self):
+        def testSocketServer(self):
 
-            server = AsyncoreHTTPSServer(TESTPORT, CERTFILE)
+            server = OurHTTPSServer(TESTPORT, CERTFILE)
             flag = threading.Event()
             server.start(flag)
             # wait for it to start
@@ -824,12 +965,55 @@
                 raise test_support.TestFailed(msg)
             else:
                 if not (d1 == d2):
+                    print("d1 is", len(d1), repr(d1))
+                    print("d2 is", len(d2), repr(d2))
                     raise test_support.TestFailed(
                         "Couldn't fetch data from HTTPS server")
             finally:
                 server.stop()
                 server.join()
 
+        def testAsyncoreServer(self):
+
+            if test_support.verbose:
+                sys.stdout.write("\n")
+
+            indata="FOO\n"
+            server = AsyncoreEchoServer(TESTPORT, CERTFILE)
+            flag = threading.Event()
+            server.start(flag)
+            # wait for it to start
+            flag.wait()
+            # try to connect
+            try:
+                s = ssl.wrap_socket(socket.socket())
+                s.connect(('127.0.0.1', TESTPORT))
+            except ssl.SSLError as x:
+                raise test_support.TestFailed("Unexpected SSL error:  " + str(x))
+            except Exception as x:
+                raise test_support.TestFailed("Unexpected exception:  " + str(x))
+            else:
+                if test_support.verbose:
+                    sys.stdout.write(
+                        " client:  sending %s...\n" % (repr(indata)))
+                s.sendall(indata.encode('ASCII', 'strict'))
+                outdata = s.recv()
+                if test_support.verbose:
+                    sys.stdout.write(" client:  read %s\n" % repr(outdata))
+                outdata = str(outdata, 'ASCII', 'strict')
+                if outdata != indata.lower():
+                    raise test_support.TestFailed(
+                        "bad data <<%s>> (%d) received; expected <<%s>> (%d)\n"
+                        % (repr(outdata[:min(len(outdata),20)]), len(outdata),
+                           repr(indata[:min(len(indata),20)].lower()), len(indata)))
+                s.write("over\n".encode("ASCII", "strict"))
+                if test_support.verbose:
+                    sys.stdout.write(" client:  closing connection.\n")
+                s.close()
+            finally:
+                server.stop()
+                server.join()
+
 
 def findtestsocket(start, end):
     def testbind(i):
@@ -863,6 +1047,7 @@
     if (not os.path.exists(CERTFILE) or
         not os.path.exists(SVN_PYTHON_ORG_ROOT_CERT)):
         raise test_support.TestFailed("Can't read certificate files!")
+
     TESTPORT = findtestsocket(10025, 12000)
     if not TESTPORT:
         raise test_support.TestFailed("Can't find open port to test servers on!")
@@ -870,12 +1055,12 @@
     tests = [BasicTests]
 
     if test_support.is_resource_enabled('network'):
-        tests.append(NetworkTests)
+        tests.append(NetworkedTests)
 
     if _have_threads:
         thread_info = test_support.threading_setup()
         if thread_info and test_support.is_resource_enabled('network'):
-            tests.append(ConnectedTests)
+            tests.append(ThreadedTests)
 
     test_support.run_unittest(*tests)
 

Deleted: /python/branches/py3k-importlib/Lib/test/test_str.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/test_str.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,106 +0,0 @@
-
-import unittest
-import struct
-import sys
-from test import test_support, string_tests
-
-
-class StrTest(
-    string_tests.CommonTest,
-    string_tests.MixinStrUnicodeUserStringTest,
-    string_tests.MixinStrUnicodeTest,
-    ):
-
-    type2test = str8
-
-    # We don't need to propagate to str
-    def fixtype(self, obj):
-        return obj
-
-    def test_formatting(self):
-        string_tests.MixinStrUnicodeUserStringTest.test_formatting(self)
-        self.assertRaises(OverflowError, '%c'.__mod__, 0x12341234)
-
-    def test_iterators(self):
-        # Make sure str objects have an __iter__ method
-        it = "abc".__iter__()
-        self.assertEqual(next(it), "a")
-        self.assertEqual(next(it), "b")
-        self.assertEqual(next(it), "c")
-        self.assertRaises(StopIteration, next, it)
-
-    def test_conversion(self):
-        # Make sure __str__() behaves properly
-
-        class Foo1:
-            def __str__(self):
-                return "foo"
-
-        class Foo2(object):
-            def __str__(self):
-                return "foo"
-
-        class Foo3(object):
-            def __str__(self):
-                return "foo"
-
-        class Foo4(str8):
-            def __str__(self):
-                return "foo"
-
-        class Foo5(str):
-            def __unicode__(self):
-                return "foo"
-
-        class Foo6(str8):
-            def __str__(self):
-                return "foos"
-
-            def __unicode__(self):
-                return "foou"
-
-        class Foo7(str):
-            def __str__(self):
-                return "foos"
-            def __unicode__(self):
-                return "foou"
-
-        class Foo8(str):
-            def __new__(cls, content=""):
-                return str.__new__(cls, 2*content)
-            def __str__(self):
-                return self
-
-        class Foo9(str8):
-            def __str__(self):
-                return "string"
-            def __unicode__(self):
-                return "not unicode"
-
-        self.assertEqual(str(Foo1()), "foo")
-        self.assertEqual(str(Foo2()), "foo")
-        self.assertEqual(str(Foo3()), "foo")
-        self.assertEqual(str(Foo4("bar")), "foo")
-        self.assertEqual(str(Foo5("bar")), "foo")
-        self.assertEqual(str8(Foo6("bar")), "foos")
-        self.assertEqual(str(Foo6("bar")), "foou")
-        self.assertEqual(str8(Foo7("bar")), "foos")
-        self.assertEqual(str(Foo7("bar")), "foou")
-        self.assertEqual(str(Foo8("foo")), "foofoo")
-        self.assertEqual(str8(Foo9("foo")), "string")
-        self.assertEqual(str(Foo9("foo")), "not unicode")
-
-    def test_expandtabs_overflows_gracefully(self):
-        # This test only affects 32-bit platforms because expandtabs can only take
-        # an int as the max value, not a 64-bit C long.  If expandtabs is changed
-        # to take a 64-bit long, this test should apply to all platforms.
-        if sys.maxint > (1 << 32) or struct.calcsize('P') != 4:
-            return
-        self.assertRaises(OverflowError, 't\tt\t'.expandtabs, sys.maxint)
-
-
-def test_main():
-    test_support.run_unittest(StrTest)
-
-if __name__ == "__main__":
-    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_strftime.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_strftime.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_strftime.py	Thu Mar 27 00:48:05 2008
@@ -1,158 +1,185 @@
-#! /usr/bin/env python
+"""
+Unittest for time.strftime
+"""
+
+import calendar
+import sys
+import os
+import re
+from test import test_support
+import time
+import unittest
 
-# Sanity checker for time.strftime
 
-import time, calendar, sys, os, re
-from test.test_support import verbose
-
-def main():
-    global verbose
-    # For C Python, these tests expect C locale, so we try to set that
-    # explicitly.  For Jython, Finn says we need to be in the US locale; my
-    # understanding is that this is the closest Java gets to C's "C" locale.
-    # Jython ought to supply an _locale module which Does The Right Thing, but
-    # this is the best we can do given today's state of affairs.
-    try:
-        import java
-        java.util.Locale.setDefault(java.util.Locale.US)
-    except ImportError:
-        # Can't do this first because it will succeed, even in Jython
-        import locale
-        locale.setlocale(locale.LC_TIME, 'C')
-    now = time.time()
-    strftest(now)
-    verbose = 0
-    # Try a bunch of dates and times,  chosen to vary through time of
-    # day and daylight saving time
-    for j in range(-5, 5):
-        for i in range(25):
-            strftest(now + (i + j*100)*23*3603)
+# helper functions
+def fixasctime(s):
+    if s[8] == ' ':
+        s = s[:8] + '0' + s[9:]
+    return s
 
 def escapestr(text, ampm):
-    """Escape text to deal with possible locale values that have regex
-    syntax while allowing regex syntax used for the comparison."""
+    """
+    Escape text to deal with possible locale values that have regex
+    syntax while allowing regex syntax used for comparison.
+    """
     new_text = re.escape(text)
     new_text = new_text.replace(re.escape(ampm), ampm)
-    new_text = new_text.replace("\%", "%")
-    new_text = new_text.replace("\:", ":")
-    new_text = new_text.replace("\?", "?")
+    new_text = new_text.replace('\%', '%')
+    new_text = new_text.replace('\:', ':')
+    new_text = new_text.replace('\?', '?')
     return new_text
 
-def strftest(now):
-    if verbose:
-        print("strftime test for", time.ctime(now))
-    nowsecs = str(int(now))[:-1]
-    gmt = time.gmtime(now)
-    now = time.localtime(now)
-
-    if now[3] < 12: ampm='(AM|am)'
-    else: ampm='(PM|pm)'
-
-    jan1 = time.localtime(time.mktime((now[0], 1, 1, 0, 0, 0, 0, 1, 0)))
-
-    try:
-        if now[8]: tz = time.tzname[1]
-        else: tz = time.tzname[0]
-    except AttributeError:
-        tz = ''
-
-    if now[3] > 12: clock12 = now[3] - 12
-    elif now[3] > 0: clock12 = now[3]
-    else: clock12 = 12
-
-    # Make sure any characters that could be taken as regex syntax is
-    # escaped in escapestr()
-    expectations = (
-        ('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'),
-        ('%A', calendar.day_name[now[6]], 'full weekday name'),
-        ('%b', calendar.month_abbr[now[1]], 'abbreviated month name'),
-        ('%B', calendar.month_name[now[1]], 'full month name'),
-        # %c see below
-        ('%d', '%02d' % now[2], 'day of month as number (00-31)'),
-        ('%H', '%02d' % now[3], 'hour (00-23)'),
-        ('%I', '%02d' % clock12, 'hour (01-12)'),
-        ('%j', '%03d' % now[7], 'julian day (001-366)'),
-        ('%m', '%02d' % now[1], 'month as number (01-12)'),
-        ('%M', '%02d' % now[4], 'minute, (00-59)'),
-        ('%p', ampm, 'AM or PM as appropriate'),
-        ('%S', '%02d' % now[5], 'seconds of current time (00-60)'),
-        ('%U', '%02d' % ((now[7] + jan1[6])//7),
-         'week number of the year (Sun 1st)'),
-        ('%w', '0?%d' % ((1+now[6]) % 7), 'weekday as a number (Sun 1st)'),
-        ('%W', '%02d' % ((now[7] + (jan1[6] - 1)%7)//7),
-         'week number of the year (Mon 1st)'),
-        # %x see below
-        ('%X', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
-        ('%y', '%02d' % (now[0]%100), 'year without century'),
-        ('%Y', '%d' % now[0], 'year with century'),
-        # %Z see below
-        ('%%', '%', 'single percent sign'),
-        )
 
-    nonstandard_expectations = (
-        # These are standard but don't have predictable output
-        ('%c', fixasctime(time.asctime(now)), 'near-asctime() format'),
-        ('%x', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)),
-         '%m/%d/%y %H:%M:%S'),
-        ('%Z', '%s' % tz, 'time zone name'),
-
-        # These are some platform specific extensions
-        ('%D', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)), 'mm/dd/yy'),
-        ('%e', '%2d' % now[2], 'day of month as number, blank padded ( 0-31)'),
-        ('%h', calendar.month_abbr[now[1]], 'abbreviated month name'),
-        ('%k', '%2d' % now[3], 'hour, blank padded ( 0-23)'),
-        ('%n', '\n', 'newline character'),
-        ('%r', '%02d:%02d:%02d %s' % (clock12, now[4], now[5], ampm),
-         '%I:%M:%S %p'),
-        ('%R', '%02d:%02d' % (now[3], now[4]), '%H:%M'),
-        ('%s', nowsecs, 'seconds since the Epoch in UCT'),
-        ('%t', '\t', 'tab character'),
-        ('%T', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
-        ('%3y', '%03d' % (now[0]%100),
-         'year without century rendered using fieldwidth'),
-        )
+class StrftimeTest(unittest.TestCase):
+
+    def _update_variables(self, now):
+        # we must update the local variables on every cycle
+        self.gmt = time.gmtime(now)
+        now = time.localtime(now)
 
-    if verbose:
-        print("Strftime test, platform: %s, Python version: %s" % \
-              (sys.platform, sys.version.split()[0]))
+        if now[3] < 12: self.ampm='(AM|am)'
+        else: self.ampm='(PM|pm)'
+
+        self.jan1 = time.localtime(time.mktime((now[0], 1, 1, 0, 0, 0, 0, 1, 0)))
 
-    for e in expectations:
         try:
-            result = time.strftime(e[0], now)
-        except ValueError as error:
-            print("Standard '%s' format gave error:" % e[0], error)
-            continue
-        if re.match(escapestr(e[1], ampm), result): continue
-        if not result or result[0] == '%':
-            print("Does not support standard '%s' format (%s)" % (e[0], e[2]))
-        else:
-            print("Conflict for %s (%s):" % (e[0], e[2]))
-            print("  Expected %s, but got %s" % (e[1], result))
+            if now[8]: self.tz = time.tzname[1]
+            else: self.tz = time.tzname[0]
+        except AttributeError:
+            self.tz = ''
+
+        if now[3] > 12: self.clock12 = now[3] - 12
+        elif now[3] > 0: self.clock12 = now[3]
+        else: self.clock12 = 12
+
+        self.now = now
 
-    for e in nonstandard_expectations:
+    def setUp(self):
         try:
-            result = time.strftime(e[0], now)
-        except ValueError as result:
-            if verbose:
-                print("Error for nonstandard '%s' format (%s): %s" % \
-                      (e[0], e[2], str(result)))
-            continue
-        if re.match(escapestr(e[1], ampm), result):
-            if verbose:
-                print("Supports nonstandard '%s' format (%s)" % (e[0], e[2]))
-        elif not result or result[0] == '%':
-            if verbose:
-                print("Does not appear to support '%s' format (%s)" % (e[0],
-                                                                       e[2]))
-        else:
-            if verbose:
-                print("Conflict for nonstandard '%s' format (%s):" % (e[0],
-                                                                      e[2]))
+            import java
+            java.util.Locale.setDefault(java.util.Locale.US)
+        except ImportError:
+            import locale
+            locale.setlocale(locale.LC_TIME, 'C')
+
+    def test_strftime(self):
+        now = time.time()
+        self._update_variables(now)
+        self.strftest1(now)
+        self.strftest2(now)
+
+        if test_support.verbose:
+            print("Strftime test, platform: %s, Python version: %s" % \
+                  (sys.platform, sys.version.split()[0]))
+
+        for j in range(-5, 5):
+            for i in range(25):
+                arg = now + (i+j*100)*23*3603
+                self._update_variables(arg)
+                self.strftest1(arg)
+                self.strftest2(arg)
+
+    def strftest1(self, now):
+        if test_support.verbose:
+            print("strftime test for", time.ctime(now))
+        now = self.now
+        # Make sure any characters that could be taken as regex syntax is
+        # escaped in escapestr()
+        expectations = (
+            ('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'),
+            ('%A', calendar.day_name[now[6]], 'full weekday name'),
+            ('%b', calendar.month_abbr[now[1]], 'abbreviated month name'),
+            ('%B', calendar.month_name[now[1]], 'full month name'),
+            # %c see below
+            ('%d', '%02d' % now[2], 'day of month as number (00-31)'),
+            ('%H', '%02d' % now[3], 'hour (00-23)'),
+            ('%I', '%02d' % self.clock12, 'hour (01-12)'),
+            ('%j', '%03d' % now[7], 'julian day (001-366)'),
+            ('%m', '%02d' % now[1], 'month as number (01-12)'),
+            ('%M', '%02d' % now[4], 'minute, (00-59)'),
+            ('%p', self.ampm, 'AM or PM as appropriate'),
+            ('%S', '%02d' % now[5], 'seconds of current time (00-60)'),
+            ('%U', '%02d' % ((now[7] + self.jan1[6])//7),
+             'week number of the year (Sun 1st)'),
+            ('%w', '0?%d' % ((1+now[6]) % 7), 'weekday as a number (Sun 1st)'),
+            ('%W', '%02d' % ((now[7] + (self.jan1[6] - 1)%7)//7),
+            'week number of the year (Mon 1st)'),
+            # %x see below
+            ('%X', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
+            ('%y', '%02d' % (now[0]%100), 'year without century'),
+            ('%Y', '%d' % now[0], 'year with century'),
+            # %Z see below
+            ('%%', '%', 'single percent sign'),
+        )
+
+        for e in expectations:
+            # musn't raise a value error
+            try:
+                result = time.strftime(e[0], now)
+            except ValueError as error:
+                print("Standard '%s' format gaver error:" % (e[0], error))
+                continue
+            if re.match(escapestr(e[1], self.ampm), result):
+                continue
+            if not result or result[0] == '%':
+                print("Does not support standard '%s' format (%s)" % \
+                       (e[0], e[2]))
+            else:
+                print("Conflict for %s (%s):" % (e[0], e[2]))
                 print("  Expected %s, but got %s" % (e[1], result))
 
-def fixasctime(s):
-    if s[8] == ' ':
-        s = s[:8] + '0' + s[9:]
-    return s
+    def strftest2(self, now):
+        nowsecs = str(int(now))[:-1]
+        now = self.now
+
+        nonstandard_expectations = (
+        # These are standard but don't have predictable output
+            ('%c', fixasctime(time.asctime(now)), 'near-asctime() format'),
+            ('%x', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)),
+            '%m/%d/%y %H:%M:%S'),
+            ('%Z', '%s' % self.tz, 'time zone name'),
+
+            # These are some platform specific extensions
+            ('%D', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)), 'mm/dd/yy'),
+            ('%e', '%2d' % now[2], 'day of month as number, blank padded ( 0-31)'),
+            ('%h', calendar.month_abbr[now[1]], 'abbreviated month name'),
+            ('%k', '%2d' % now[3], 'hour, blank padded ( 0-23)'),
+            ('%n', '\n', 'newline character'),
+            ('%r', '%02d:%02d:%02d %s' % (self.clock12, now[4], now[5], self.ampm),
+            '%I:%M:%S %p'),
+            ('%R', '%02d:%02d' % (now[3], now[4]), '%H:%M'),
+            ('%s', nowsecs, 'seconds since the Epoch in UCT'),
+            ('%t', '\t', 'tab character'),
+            ('%T', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
+            ('%3y', '%03d' % (now[0]%100),
+            'year without century rendered using fieldwidth'),
+        )
+
+
+        for e in nonstandard_expectations:
+            try:
+                result = time.strftime(e[0], now)
+            except ValueError as result:
+                msg = "Error for nonstandard '%s' format (%s): %s" % \
+                      (e[0], e[2], str(result))
+                if test_support.verbose:
+                    print(msg)
+                continue
+            if re.match(escapestr(e[1], self.ampm), result):
+                if test_support.verbose:
+                    print("Supports nonstandard '%s' format (%s)" % (e[0], e[2]))
+            elif not result or result[0] == '%':
+                if test_support.verbose:
+                    print("Does not appear to support '%s' format (%s)" % \
+                           (e[0], e[2]))
+            else:
+                if test_support.verbose:
+                    print("Conflict for nonstandard '%s' format (%s):" % \
+                           (e[0], e[2]))
+                    print("  Expected %s, but got %s" % (e[1], result))
+
+def test_main():
+    test_support.run_unittest(StrftimeTest)
 
-main()
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_strptime.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_strptime.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_strptime.py	Thu Mar 27 00:48:05 2008
@@ -208,11 +208,11 @@
 
     def test_ValueError(self):
         # Make sure ValueError is raised when match fails or format is bad
-        self.assertRaises(ValueError, _strptime.strptime, data_string="%d",
+        self.assertRaises(ValueError, _strptime._strptime_time, data_string="%d",
                           format="%A")
         for bad_format in ("%", "% ", "%e"):
             try:
-                _strptime.strptime("2005", bad_format)
+                _strptime._strptime_time("2005", bad_format)
             except ValueError:
                 continue
             except Exception as err:
@@ -223,12 +223,12 @@
 
     def test_unconverteddata(self):
         # Check ValueError is raised when there is unconverted data
-        self.assertRaises(ValueError, _strptime.strptime, "10 12", "%m")
+        self.assertRaises(ValueError, _strptime._strptime_time, "10 12", "%m")
 
     def helper(self, directive, position):
         """Helper fxn in testing."""
         strf_output = time.strftime("%" + directive, self.time_tuple)
-        strp_output = _strptime.strptime(strf_output, "%" + directive)
+        strp_output = _strptime._strptime_time(strf_output, "%" + directive)
         self.failUnless(strp_output[position] == self.time_tuple[position],
                         "testing of '%s' directive failed; '%s' -> %s != %s" %
                          (directive, strf_output, strp_output[position],
@@ -241,7 +241,7 @@
         # Must also make sure %y values are correct for bounds set by Open Group
         for century, bounds in ((1900, ('69', '99')), (2000, ('00', '68'))):
             for bound in bounds:
-                strp_output = _strptime.strptime(bound, '%y')
+                strp_output = _strptime._strptime_time(bound, '%y')
                 expected_result = century + int(bound)
                 self.failUnless(strp_output[0] == expected_result,
                                 "'y' test failed; passed in '%s' "
@@ -260,7 +260,7 @@
         # Test hour directives
         self.helper('H', 3)
         strf_output = time.strftime("%I %p", self.time_tuple)
-        strp_output = _strptime.strptime(strf_output, "%I %p")
+        strp_output = _strptime._strptime_time(strf_output, "%I %p")
         self.failUnless(strp_output[3] == self.time_tuple[3],
                         "testing of '%%I %%p' directive failed; '%s' -> %s != %s" %
                          (strf_output, strp_output[3], self.time_tuple[3]))
@@ -273,6 +273,12 @@
         # Test second directives
         self.helper('S', 5)
 
+    def test_fraction(self):
+        import datetime
+        now = datetime.datetime.now()
+        tup, frac = _strptime._strptime(str(now), format="%Y-%m-%d %H:%M:%S.%f")
+        self.assertEqual(frac, now.microsecond)
+
     def test_weekday(self):
         # Test weekday directives
         for directive in ('A', 'a', 'w'):
@@ -287,16 +293,16 @@
         # When gmtime() is used with %Z, entire result of strftime() is empty.
         # Check for equal timezone names deals with bad locale info when this
         # occurs; first found in FreeBSD 4.4.
-        strp_output = _strptime.strptime("UTC", "%Z")
+        strp_output = _strptime._strptime_time("UTC", "%Z")
         self.failUnlessEqual(strp_output.tm_isdst, 0)
-        strp_output = _strptime.strptime("GMT", "%Z")
+        strp_output = _strptime._strptime_time("GMT", "%Z")
         self.failUnlessEqual(strp_output.tm_isdst, 0)
         if sys.platform == "mac":
             # Timezones don't really work on MacOS9
             return
         time_tuple = time.localtime()
         strf_output = time.strftime("%Z")  #UTC does not have a timezone
-        strp_output = _strptime.strptime(strf_output, "%Z")
+        strp_output = _strptime._strptime_time(strf_output, "%Z")
         locale_time = _strptime.LocaleTime()
         if time.tzname[0] != time.tzname[1] or not time.daylight:
             self.failUnless(strp_output[8] == time_tuple[8],
@@ -320,7 +326,7 @@
             original_daylight = time.daylight
             time.tzname = (tz_name, tz_name)
             time.daylight = 1
-            tz_value = _strptime.strptime(tz_name, "%Z")[8]
+            tz_value = _strptime._strptime_time(tz_name, "%Z")[8]
             self.failUnlessEqual(tz_value, -1,
                     "%s lead to a timezone value of %s instead of -1 when "
                     "time.daylight set to %s and passing in %s" %
@@ -347,7 +353,7 @@
     def test_percent(self):
         # Make sure % signs are handled properly
         strf_output = time.strftime("%m %% %Y", self.time_tuple)
-        strp_output = _strptime.strptime(strf_output, "%m %% %Y")
+        strp_output = _strptime._strptime_time(strf_output, "%m %% %Y")
         self.failUnless(strp_output[0] == self.time_tuple[0] and
                          strp_output[1] == self.time_tuple[1],
                         "handling of percent sign failed")
@@ -355,17 +361,17 @@
     def test_caseinsensitive(self):
         # Should handle names case-insensitively.
         strf_output = time.strftime("%B", self.time_tuple)
-        self.failUnless(_strptime.strptime(strf_output.upper(), "%B"),
+        self.failUnless(_strptime._strptime_time(strf_output.upper(), "%B"),
                         "strptime does not handle ALL-CAPS names properly")
-        self.failUnless(_strptime.strptime(strf_output.lower(), "%B"),
+        self.failUnless(_strptime._strptime_time(strf_output.lower(), "%B"),
                         "strptime does not handle lowercase names properly")
-        self.failUnless(_strptime.strptime(strf_output.capitalize(), "%B"),
+        self.failUnless(_strptime._strptime_time(strf_output.capitalize(), "%B"),
                         "strptime does not handle capword names properly")
 
     def test_defaults(self):
         # Default return value should be (1900, 1, 1, 0, 0, 0, 0, 1, 0)
         defaults = (1900, 1, 1, 0, 0, 0, 0, 1, -1)
-        strp_output = _strptime.strptime('1', '%m')
+        strp_output = _strptime._strptime_time('1', '%m')
         self.failUnless(strp_output == defaults,
                         "Default values for strptime() are incorrect;"
                         " %s != %s" % (strp_output, defaults))
@@ -377,7 +383,7 @@
         # escaped.
         # Test instigated by bug #796149 .
         need_escaping = ".^$*+?{}\[]|)("
-        self.failUnless(_strptime.strptime(need_escaping, need_escaping))
+        self.failUnless(_strptime._strptime_time(need_escaping, need_escaping))
 
 class Strptime12AMPMTests(unittest.TestCase):
     """Test a _strptime regression in '%I %p' at 12 noon (12 PM)"""
@@ -386,8 +392,8 @@
         eq = self.assertEqual
         eq(time.strptime('12 PM', '%I %p')[3], 12)
         eq(time.strptime('12 AM', '%I %p')[3], 0)
-        eq(_strptime.strptime('12 PM', '%I %p')[3], 12)
-        eq(_strptime.strptime('12 AM', '%I %p')[3], 0)
+        eq(_strptime._strptime_time('12 PM', '%I %p')[3], 12)
+        eq(_strptime._strptime_time('12 AM', '%I %p')[3], 0)
 
 
 class JulianTests(unittest.TestCase):
@@ -397,7 +403,7 @@
         eq = self.assertEqual
         for i in range(1, 367):
             # use 2004, since it is a leap year, we have 366 days
-            eq(_strptime.strptime('%d 2004' % i, '%j %Y')[7], i)
+            eq(_strptime._strptime_time('%d 2004' % i, '%j %Y')[7], i)
 
 class CalculationTests(unittest.TestCase):
     """Test that strptime() fills in missing info correctly"""
@@ -408,7 +414,7 @@
     def test_julian_calculation(self):
         # Make sure that when Julian is missing that it is calculated
         format_string = "%Y %m %d %H %M %S %w %Z"
-        result = _strptime.strptime(time.strftime(format_string, self.time_tuple),
+        result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
                                     format_string)
         self.failUnless(result.tm_yday == self.time_tuple.tm_yday,
                         "Calculation of tm_yday failed; %s != %s" %
@@ -417,7 +423,7 @@
     def test_gregorian_calculation(self):
         # Test that Gregorian date can be calculated from Julian day
         format_string = "%Y %H %M %S %w %j %Z"
-        result = _strptime.strptime(time.strftime(format_string, self.time_tuple),
+        result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
                                     format_string)
         self.failUnless(result.tm_year == self.time_tuple.tm_year and
                          result.tm_mon == self.time_tuple.tm_mon and
@@ -431,7 +437,7 @@
     def test_day_of_week_calculation(self):
         # Test that the day of the week is calculated as needed
         format_string = "%Y %m %d %H %S %j %Z"
-        result = _strptime.strptime(time.strftime(format_string, self.time_tuple),
+        result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
                                     format_string)
         self.failUnless(result.tm_wday == self.time_tuple.tm_wday,
                         "Calculation of day of the week failed;"
@@ -445,7 +451,7 @@
                 format_string = "%%Y %%%s %%w" % directive
                 dt_date = datetime_date(*ymd_tuple)
                 strp_input = dt_date.strftime(format_string)
-                strp_output = _strptime.strptime(strp_input, format_string)
+                strp_output = _strptime._strptime_time(strp_input, format_string)
                 self.failUnless(strp_output[:3] == ymd_tuple,
                         "%s(%s) test failed w/ '%s': %s != %s (%s != %s)" %
                             (test_reason, directive, strp_input,
@@ -484,11 +490,11 @@
     def test_time_re_recreation(self):
         # Make sure cache is recreated when current locale does not match what
         # cached object was created with.
-        _strptime.strptime("10", "%d")
-        _strptime.strptime("2005", "%Y")
+        _strptime._strptime_time("10", "%d")
+        _strptime._strptime_time("2005", "%Y")
         _strptime._TimeRE_cache.locale_time.lang = "Ni"
         original_time_re = id(_strptime._TimeRE_cache)
-        _strptime.strptime("10", "%d")
+        _strptime._strptime_time("10", "%d")
         self.failIfEqual(original_time_re, id(_strptime._TimeRE_cache))
         self.failUnlessEqual(len(_strptime._regex_cache), 1)
 
@@ -502,7 +508,7 @@
         while len(_strptime._regex_cache) <= _strptime._CACHE_MAX_SIZE:
             _strptime._regex_cache[bogus_key] = None
             bogus_key += 1
-        _strptime.strptime("10", "%d")
+        _strptime._strptime_time("10", "%d")
         self.failUnlessEqual(len(_strptime._regex_cache), 1)
 
     def test_new_localetime(self):
@@ -510,7 +516,7 @@
         # is created.
         locale_time_id = id(_strptime._TimeRE_cache.locale_time)
         _strptime._TimeRE_cache.locale_time.lang = "Ni"
-        _strptime.strptime("10", "%d")
+        _strptime._strptime_time("10", "%d")
         self.failIfEqual(locale_time_id,
                          id(_strptime._TimeRE_cache.locale_time))
 
@@ -522,13 +528,13 @@
         except locale.Error:
             return
         try:
-            _strptime.strptime('10', '%d')
+            _strptime._strptime_time('10', '%d')
             # Get id of current cache object.
             first_time_re_id = id(_strptime._TimeRE_cache)
             try:
                 # Change the locale and force a recreation of the cache.
                 locale.setlocale(locale.LC_TIME, ('de_DE', 'UTF8'))
-                _strptime.strptime('10', '%d')
+                _strptime._strptime_time('10', '%d')
                 # Get the new cache object's id.
                 second_time_re_id = id(_strptime._TimeRE_cache)
                 # They should not be equal.

Modified: python/branches/py3k-importlib/Lib/test/test_struct.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_struct.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_struct.py	Thu Mar 27 00:48:05 2008
@@ -84,8 +84,8 @@
 if sz * 3 != struct.calcsize('iii'):
     raise TestFailed('inconsistent sizes')
 
-fmt = 'cbxxxxxxhhhhiillffdt'
-fmt3 = '3c3b18x12h6i6l6f3d3t'
+fmt = 'cbxxxxxxhhhhiillffd?'
+fmt3 = '3c3b18x12h6i6l6f3d3?'
 sz = struct.calcsize(fmt)
 sz3 = struct.calcsize(fmt3)
 if sz * 3 != sz3:
@@ -96,12 +96,12 @@
 simple_err(struct.pack, 'i', 3, 3, 3)
 simple_err(struct.pack, 'i', 'foo')
 simple_err(struct.pack, 'P', 'foo')
-simple_err(struct.unpack, 'd', 'flap')
+simple_err(struct.unpack, 'd', b'flap')
 s = struct.pack('ii', 1, 2)
 simple_err(struct.unpack, 'iii', s)
 simple_err(struct.unpack, 'i', s)
 
-c = 'a'
+c = b'a'
 b = 1
 h = 255
 i = 65535
@@ -111,7 +111,7 @@
 t = True
 
 for prefix in ('', '@', '<', '>', '=', '!'):
-    for format in ('xcbhilfdt', 'xcBHILfdt'):
+    for format in ('xcbhilfd?', 'xcBHILfd?'):
         format = prefix + format
         if verbose:
             print("trying:", format)
@@ -160,11 +160,11 @@
     ('f', -2.0, '\300\000\000\000', '\000\000\000\300', 0),
     ('d', -2.0, '\300\000\000\000\000\000\000\000',
                '\000\000\000\000\000\000\000\300', 0),
-        ('t', 0, '\0', '\0', 0),
-        ('t', 3, '\1', '\1', 1),
-        ('t', True, '\1', '\1', 0),
-        ('t', [], '\0', '\0', 1),
-        ('t', (1,), '\1', '\1', 1),
+        ('?', 0, '\0', '\0', 0),
+        ('?', 3, '\1', '\1', 1),
+        ('?', True, '\1', '\1', 0),
+        ('?', [], '\0', '\0', 1),
+        ('?', (1,), '\1', '\1', 1),
 ]
 
 for fmt, arg, big, lil, asy in tests:
@@ -183,6 +183,10 @@
             raise TestFailed("calcsize(%r) -> %d # expected %d" % (
                 xfmt, n, len(res)))
         rev = struct.unpack(xfmt, res)[0]
+        if isinstance(arg, str):
+            # Strings are returned as bytes since you can't know the encoding of
+            # the string when packed.
+            arg = bytes(arg, 'latin1')
         if rev != arg and not asy:
             raise TestFailed("unpack(%r, %r) -> (%r,) # expected (%r,)" % (
                 fmt, res, rev, arg))
@@ -424,14 +428,14 @@
 
 def test_p_code():
     for code, input, expected, expectedback in [
-            ('p','abc', '\x00', ''),
-            ('1p', 'abc', '\x00', ''),
-            ('2p', 'abc', '\x01a', 'a'),
-            ('3p', 'abc', '\x02ab', 'ab'),
-            ('4p', 'abc', '\x03abc', 'abc'),
-            ('5p', 'abc', '\x03abc\x00', 'abc'),
-            ('6p', 'abc', '\x03abc\x00\x00', 'abc'),
-            ('1000p', 'x'*1000, '\xff' + 'x'*999, 'x'*255)]:
+            ('p','abc', '\x00', b''),
+            ('1p', 'abc', '\x00', b''),
+            ('2p', 'abc', '\x01a', b'a'),
+            ('3p', 'abc', '\x02ab', b'ab'),
+            ('4p', 'abc', '\x03abc', b'abc'),
+            ('5p', 'abc', '\x03abc\x00', b'abc'),
+            ('6p', 'abc', '\x03abc\x00\x00', b'abc'),
+            ('1000p', 'x'*1000, '\xff' + 'x'*999, b'x'*255)]:
         expected = bytes(expected, "latin-1")
         got = struct.pack(code, input)
         if got != expected:
@@ -486,7 +490,7 @@
     except OverflowError:
         pass
     else:
-        TestFailed("expected OverflowError")
+        raise TestFailed("expected OverflowError")
 
 test_705836()
 
@@ -502,8 +506,8 @@
         deprecated_err(struct.pack, endian + 'B', 300)
         deprecated_err(struct.pack, endian + 'H', 70000)
 
-        deprecated_err(struct.pack, endian + 'I', sys.maxint * 4)
-        deprecated_err(struct.pack, endian + 'L', sys.maxint * 4)
+        deprecated_err(struct.pack, endian + 'I', sys.maxsize * 4)
+        deprecated_err(struct.pack, endian + 'L', sys.maxsize * 4)
 
 if PY_STRUCT_RANGE_CHECKING:
     test_1229380()
@@ -556,24 +560,28 @@
     test_string = b'abcd01234'
     fmt = '4s'
     s = struct.Struct(fmt)
-    for cls in (str, str8, bytes): # XXX + memoryview
+    for cls in (bytes, bytearray):
         if verbose:
             print("test_unpack_from using", cls.__name__)
         data = cls(test_string)
-        vereq(s.unpack_from(data), ('abcd',))
-        vereq(s.unpack_from(data, 2), ('cd01',))
-        vereq(s.unpack_from(data, 4), ('0123',))
+        if not isinstance(data, (bytes, bytearray)):
+            bytes_data = bytes(data, 'latin1')
+        else:
+            bytes_data = data
+        vereq(s.unpack_from(data), (b'abcd',))
+        vereq(s.unpack_from(data, 2), (b'cd01',))
+        vereq(s.unpack_from(data, 4), (b'0123',))
         for i in range(6):
-            vereq(s.unpack_from(data, i), (data[i:i+4],))
+            vereq(s.unpack_from(data, i), (bytes_data[i:i+4],))
         for i in range(6, len(test_string) + 1):
             simple_err(s.unpack_from, data, i)
-    for cls in (str, str8, bytes): # XXX + memoryview
+    for cls in (bytes, bytearray):
         data = cls(test_string)
-        vereq(struct.unpack_from(fmt, data), ('abcd',))
-        vereq(struct.unpack_from(fmt, data, 2), ('cd01',))
-        vereq(struct.unpack_from(fmt, data, 4), ('0123',))
+        vereq(struct.unpack_from(fmt, data), (b'abcd',))
+        vereq(struct.unpack_from(fmt, data, 2), (b'cd01',))
+        vereq(struct.unpack_from(fmt, data, 4), (b'0123',))
         for i in range(6):
-            vereq(struct.unpack_from(fmt, data, i), (data[i:i+4],))
+            vereq(struct.unpack_from(fmt, data, i), (bytes_data[i:i+4],))
         for i in range(6, len(test_string) + 1):
             simple_err(struct.unpack_from, fmt, data, i)
 
@@ -638,13 +646,13 @@
         false = (), [], [], '', 0
         true = [1], 'test', 5, -1, 0xffffffff+1, 0xffffffff/2
 
-        falseFormat = prefix + 't' * len(false)
+        falseFormat = prefix + '?' * len(false)
         if verbose:
             print('trying bool pack/unpack on', false, 'using format', falseFormat)
         packedFalse = struct.pack(falseFormat, *false)
         unpackedFalse = struct.unpack(falseFormat, packedFalse)
 
-        trueFormat = prefix + 't' * len(true)
+        trueFormat = prefix + '?' * len(true)
         if verbose:
             print('trying bool pack/unpack on', true, 'using format', trueFormat)
         packedTrue = struct.pack(trueFormat, *true)
@@ -663,10 +671,10 @@
                 raise TestFailed('%r did not unpack as false' % t)
 
         if prefix and verbose:
-            print('trying size of bool with format %r' % (prefix+'t'))
-        packed = struct.pack(prefix+'t', 1)
+            print('trying size of bool with format %r' % (prefix+'?'))
+        packed = struct.pack(prefix+'?', 1)
 
-        if len(packed) != struct.calcsize(prefix+'t'):
+        if len(packed) != struct.calcsize(prefix+'?'):
             raise TestFailed('packed length is not equal to calculated size')
 
         if len(packed) != 1 and prefix:
@@ -674,8 +682,8 @@
         elif not prefix and verbose:
             print('size of bool in native format is %i' % (len(packed)))
 
-        for c in str8('\x01\x7f\xff\x0f\xf0'):
-            if struct.unpack('>t', c)[0] is not True:
+        for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']:
+            if struct.unpack('>?', c)[0] is not True:
                 raise TestFailed('%c did not unpack as True' % c)
 
 test_bool()

Modified: python/branches/py3k-importlib/Lib/test/test_structmembers.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_structmembers.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_structmembers.py	Thu Mar 27 00:48:05 2008
@@ -8,52 +8,59 @@
 import warnings, unittest, sys
 from test import test_support
 
-ts=test_structmembersType(1,2,3,4,5,6,7,8,9.99999,10.1010101010)
+ts=test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8,
+                          9.99999, 10.1010101010)
 
 class ReadWriteTests(unittest.TestCase):
     def test_types(self):
-        ts.T_BYTE=CHAR_MAX
+        ts.T_BOOL = True
+        self.assertEquals(ts.T_BOOL, True)
+        ts.T_BOOL = False
+        self.assertEquals(ts.T_BOOL, False)
+        self.assertRaises(TypeError, setattr, ts, 'T_BOOL', 1)
+
+        ts.T_BYTE = CHAR_MAX
         self.assertEquals(ts.T_BYTE, CHAR_MAX)
-        ts.T_BYTE=CHAR_MIN
+        ts.T_BYTE = CHAR_MIN
         self.assertEquals(ts.T_BYTE, CHAR_MIN)
-        ts.T_UBYTE=UCHAR_MAX
+        ts.T_UBYTE = UCHAR_MAX
         self.assertEquals(ts.T_UBYTE, UCHAR_MAX)
 
-        ts.T_SHORT=SHRT_MAX
+        ts.T_SHORT = SHRT_MAX
         self.assertEquals(ts.T_SHORT, SHRT_MAX)
-        ts.T_SHORT=SHRT_MIN
+        ts.T_SHORT = SHRT_MIN
         self.assertEquals(ts.T_SHORT, SHRT_MIN)
-        ts.T_USHORT=USHRT_MAX
+        ts.T_USHORT = USHRT_MAX
         self.assertEquals(ts.T_USHORT, USHRT_MAX)
 
-        ts.T_INT=INT_MAX
+        ts.T_INT = INT_MAX
         self.assertEquals(ts.T_INT, INT_MAX)
-        ts.T_INT=INT_MIN
+        ts.T_INT = INT_MIN
         self.assertEquals(ts.T_INT, INT_MIN)
-        ts.T_UINT=UINT_MAX
+        ts.T_UINT = UINT_MAX
         self.assertEquals(ts.T_UINT, UINT_MAX)
 
-        ts.T_LONG=LONG_MAX
+        ts.T_LONG = LONG_MAX
         self.assertEquals(ts.T_LONG, LONG_MAX)
-        ts.T_LONG=LONG_MIN
+        ts.T_LONG = LONG_MIN
         self.assertEquals(ts.T_LONG, LONG_MIN)
-        ts.T_ULONG=ULONG_MAX
+        ts.T_ULONG = ULONG_MAX
         self.assertEquals(ts.T_ULONG, ULONG_MAX)
 
         ## T_LONGLONG and T_ULONGLONG may not be present on some platforms
         if hasattr(ts, 'T_LONGLONG'):
-            ts.T_LONGLONG=LLONG_MAX
+            ts.T_LONGLONG = LLONG_MAX
             self.assertEquals(ts.T_LONGLONG, LLONG_MAX)
-            ts.T_LONGLONG=LLONG_MIN
+            ts.T_LONGLONG = LLONG_MIN
             self.assertEquals(ts.T_LONGLONG, LLONG_MIN)
 
-            ts.T_ULONGLONG=ULLONG_MAX
+            ts.T_ULONGLONG = ULLONG_MAX
             self.assertEquals(ts.T_ULONGLONG, ULLONG_MAX)
 
             ## make sure these will accept a plain int as well as a long
-            ts.T_LONGLONG=3
+            ts.T_LONGLONG = 3
             self.assertEquals(ts.T_LONGLONG, 3)
-            ts.T_ULONGLONG=4
+            ts.T_ULONGLONG = 4
             self.assertEquals(ts.T_ULONGLONG, 4)
 
 
@@ -63,32 +70,32 @@
 
     def test_byte_max(self):
         with test_support.catch_warning() as w:
-            ts.T_BYTE=CHAR_MAX+1
+            ts.T_BYTE = CHAR_MAX+1
             self.has_warned(w)
 
     def test_byte_min(self):
         with test_support.catch_warning() as w:
-            ts.T_BYTE=CHAR_MIN-1
+            ts.T_BYTE = CHAR_MIN-1
             self.has_warned(w)
 
     def test_ubyte_max(self):
         with test_support.catch_warning() as w:
-            ts.T_UBYTE=UCHAR_MAX+1
+            ts.T_UBYTE = UCHAR_MAX+1
             self.has_warned(w)
 
     def test_short_max(self):
         with test_support.catch_warning() as w:
-            ts.T_SHORT=SHRT_MAX+1
+            ts.T_SHORT = SHRT_MAX+1
             self.has_warned(w)
 
     def test_short_min(self):
         with test_support.catch_warning() as w:
-            ts.T_SHORT=SHRT_MIN-1
+            ts.T_SHORT = SHRT_MIN-1
             self.has_warned(w)
 
     def test_ushort_max(self):
         with test_support.catch_warning() as w:
-            ts.T_USHORT=USHRT_MAX+1
+            ts.T_USHORT = USHRT_MAX+1
             self.has_warned(w)
 
 

Modified: python/branches/py3k-importlib/Lib/test/test_structseq.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_structseq.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_structseq.py	Thu Mar 27 00:48:05 2008
@@ -28,7 +28,11 @@
 
     def test_repr(self):
         t = time.gmtime()
-        repr(t)
+        self.assert_(repr(t))
+        t = time.gmtime(0)
+        self.assertEqual(repr(t),
+            "time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, "
+            "tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)")
 
     def test_concat(self):
         t1 = time.gmtime()

Modified: python/branches/py3k-importlib/Lib/test/test_subprocess.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_subprocess.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_subprocess.py	Thu Mar 27 00:48:05 2008
@@ -24,7 +24,8 @@
 # shutdown time.  That frustrates tests trying to check stderr produced
 # from a spawned Python process.
 def remove_stderr_debug_decorations(stderr):
-    return re.sub(r"\[\d+ refs\]\r?\n?$", "", str8(stderr))
+    return re.sub("\[\d+ refs\]\r?\n?$", "", stderr.decode()).encode()
+    #return re.sub(r"\[\d+ refs\]\r?\n?$", "", stderr)
 
 class ProcessTestCase(unittest.TestCase):
     def setUp(self):
@@ -77,9 +78,9 @@
         newenv = os.environ.copy()
         newenv["FRUIT"] = "banana"
         rc = subprocess.call([sys.executable, "-c",
-                          'import sys, os;' \
-                          'sys.exit(os.getenv("FRUIT")=="banana")'],
-                        env=newenv)
+                              'import sys, os;'
+                              'sys.exit(os.getenv("FRUIT")=="banana")'],
+                             env=newenv)
         self.assertEqual(rc, 1)
 
     def test_stdin_none(self):
@@ -180,7 +181,7 @@
                           'import sys; sys.stderr.write("strawberry")'],
                          stderr=subprocess.PIPE)
         self.assertEqual(remove_stderr_debug_decorations(p.stderr.read()),
-                         "strawberry")
+                         b"strawberry")
 
     def test_stderr_filedes(self):
         # stderr is set to open file descriptor
@@ -192,7 +193,7 @@
         p.wait()
         os.lseek(d, 0, 0)
         self.assertEqual(remove_stderr_debug_decorations(os.read(d, 1024)),
-                         "strawberry")
+                         b"strawberry")
 
     def test_stderr_fileobj(self):
         # stderr is set to open file object
@@ -203,36 +204,36 @@
         p.wait()
         tf.seek(0)
         self.assertEqual(remove_stderr_debug_decorations(tf.read()),
-                         "strawberry")
+                         b"strawberry")
 
     def test_stdout_stderr_pipe(self):
         # capture stdout and stderr to the same pipe
         p = subprocess.Popen([sys.executable, "-c",
-                          'import sys;' \
-                          'sys.stdout.write("apple");' \
-                          'sys.stdout.flush();' \
-                          'sys.stderr.write("orange")'],
-                         stdout=subprocess.PIPE,
-                         stderr=subprocess.STDOUT)
+                              'import sys;'
+                              'sys.stdout.write("apple");'
+                              'sys.stdout.flush();'
+                              'sys.stderr.write("orange")'],
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.STDOUT)
         output = p.stdout.read()
         stripped = remove_stderr_debug_decorations(output)
-        self.assertEqual(stripped, "appleorange")
+        self.assertEqual(stripped, b"appleorange")
 
     def test_stdout_stderr_file(self):
         # capture stdout and stderr to the same open file
         tf = tempfile.TemporaryFile()
         p = subprocess.Popen([sys.executable, "-c",
-                          'import sys;' \
-                          'sys.stdout.write("apple");' \
-                          'sys.stdout.flush();' \
-                          'sys.stderr.write("orange")'],
-                         stdout=tf,
-                         stderr=tf)
+                              'import sys;'
+                              'sys.stdout.write("apple");'
+                              'sys.stdout.flush();'
+                              'sys.stderr.write("orange")'],
+                             stdout=tf,
+                             stderr=tf)
         p.wait()
         tf.seek(0)
         output = tf.read()
         stripped = remove_stderr_debug_decorations(output)
-        self.assertEqual(stripped, "appleorange")
+        self.assertEqual(stripped, b"appleorange")
 
     def test_stdout_filedes_of_stdout(self):
         # stdout is set to 1 (#1531862).
@@ -241,7 +242,7 @@
         self.assertEquals(rc, 2)
 
     def test_cwd(self):
-        tmpdir = os.getenv("TEMP", "/tmp")
+        tmpdir = tempfile.gettempdir()
         # We cannot use os.path.realpath to canonicalize the path,
         # since it doesn't expand Tru64 {memb} strings. See bug 1063571.
         cwd = os.getcwd()
@@ -249,10 +250,10 @@
         tmpdir = os.getcwd()
         os.chdir(cwd)
         p = subprocess.Popen([sys.executable, "-c",
-                          'import sys,os;' \
-                          'sys.stdout.write(os.getcwd())'],
-                         stdout=subprocess.PIPE,
-                         cwd=tmpdir)
+                              'import sys,os;'
+                              'sys.stdout.write(os.getcwd())'],
+                             stdout=subprocess.PIPE,
+                             cwd=tmpdir)
         normcase = os.path.normcase
         self.assertEqual(normcase(p.stdout.read().decode("utf-8")),
                          normcase(tmpdir))
@@ -261,15 +262,16 @@
         newenv = os.environ.copy()
         newenv["FRUIT"] = "orange"
         p = subprocess.Popen([sys.executable, "-c",
-                          'import sys,os;' \
-                          'sys.stdout.write(os.getenv("FRUIT"))'],
-                         stdout=subprocess.PIPE,
-                         env=newenv)
+                              'import sys,os;'
+                              'sys.stdout.write(os.getenv("FRUIT"))'],
+                             stdout=subprocess.PIPE,
+                             env=newenv)
         self.assertEqual(p.stdout.read(), b"orange")
 
     def test_communicate_stdin(self):
         p = subprocess.Popen([sys.executable, "-c",
-                              'import sys; sys.exit(sys.stdin.read() == "pear")'],
+                              'import sys;'
+                              'sys.exit(sys.stdin.read() == "pear")'],
                              stdin=subprocess.PIPE)
         p.communicate(b"pear")
         self.assertEqual(p.returncode, 1)
@@ -294,16 +296,16 @@
 
     def test_communicate(self):
         p = subprocess.Popen([sys.executable, "-c",
-                          'import sys,os;' \
-                          'sys.stderr.write("pineapple");' \
-                          'sys.stdout.write(sys.stdin.read())'],
-                         stdin=subprocess.PIPE,
-                         stdout=subprocess.PIPE,
-                         stderr=subprocess.PIPE)
+                              'import sys,os;'
+                              'sys.stderr.write("pineapple");'
+                              'sys.stdout.write(sys.stdin.read())'],
+                             stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE)
         (stdout, stderr) = p.communicate("banana")
         self.assertEqual(stdout, b"banana")
         self.assertEqual(remove_stderr_debug_decorations(stderr),
-                         "pineapple")
+                         b"pineapple")
 
     def test_communicate_returns(self):
         # communicate() should return None if no redirection is active
@@ -325,13 +327,13 @@
         os.close(x)
         os.close(y)
         p = subprocess.Popen([sys.executable, "-c",
-                          'import sys,os;'
-                          'sys.stdout.write(sys.stdin.read(47));' \
-                          'sys.stderr.write("xyz"*%d);' \
-                          'sys.stdout.write(sys.stdin.read())' % pipe_buf],
-                         stdin=subprocess.PIPE,
-                         stdout=subprocess.PIPE,
-                         stderr=subprocess.PIPE)
+                              'import sys,os;'
+                              'sys.stdout.write(sys.stdin.read(47));'
+                              'sys.stderr.write("xyz"*%d);'
+                              'sys.stdout.write(sys.stdin.read())' % pipe_buf],
+                             stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE)
         string_to_write = b"abc"*pipe_buf
         (stdout, stderr) = p.communicate(string_to_write)
         self.assertEqual(stdout, string_to_write)
@@ -339,68 +341,69 @@
     def test_writes_before_communicate(self):
         # stdin.write before communicate()
         p = subprocess.Popen([sys.executable, "-c",
-                          'import sys,os;' \
-                          'sys.stdout.write(sys.stdin.read())'],
-                         stdin=subprocess.PIPE,
-                         stdout=subprocess.PIPE,
-                         stderr=subprocess.PIPE)
+                              'import sys,os;'
+                              'sys.stdout.write(sys.stdin.read())'],
+                             stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE)
         p.stdin.write(b"banana")
         (stdout, stderr) = p.communicate(b"split")
         self.assertEqual(stdout, b"bananasplit")
-        self.assertEqual(remove_stderr_debug_decorations(stderr), "")
+        self.assertEqual(remove_stderr_debug_decorations(stderr), b"")
 
     def test_universal_newlines(self):
         p = subprocess.Popen([sys.executable, "-c",
-                          'import sys,os;' + SETBINARY +
-                          'sys.stdout.write("line1\\n");'
-                          'sys.stdout.flush();'
-                          'sys.stdout.write("line2\\n");'
-                          'sys.stdout.flush();'
-                          'sys.stdout.write("line3\\r\\n");'
-                          'sys.stdout.flush();'
-                          'sys.stdout.write("line4\\r");'
-                          'sys.stdout.flush();'
-                          'sys.stdout.write("\\nline5");'
-                          'sys.stdout.flush();'
-                          'sys.stdout.write("\\nline6");'],
-                         stdout=subprocess.PIPE,
-                         universal_newlines=1)
+                              'import sys,os;' + SETBINARY +
+                              'sys.stdout.write("line1\\n");'
+                              'sys.stdout.flush();'
+                              'sys.stdout.write("line2\\n");'
+                              'sys.stdout.flush();'
+                              'sys.stdout.write("line3\\r\\n");'
+                              'sys.stdout.flush();'
+                              'sys.stdout.write("line4\\r");'
+                              'sys.stdout.flush();'
+                              'sys.stdout.write("\\nline5");'
+                              'sys.stdout.flush();'
+                              'sys.stdout.write("\\nline6");'],
+                             stdout=subprocess.PIPE,
+                             universal_newlines=1)
         stdout = p.stdout.read()
         self.assertEqual(stdout, "line1\nline2\nline3\nline4\nline5\nline6")
 
     def test_universal_newlines_communicate(self):
         # universal newlines through communicate()
         p = subprocess.Popen([sys.executable, "-c",
-                          'import sys,os;' + SETBINARY +
-                          'sys.stdout.write("line1\\n");'
-                          'sys.stdout.flush();'
-                          'sys.stdout.write("line2\\n");'
-                          'sys.stdout.flush();'
-                          'sys.stdout.write("line3\\r\\n");'
-                          'sys.stdout.flush();'
-                          'sys.stdout.write("line4\\r");'
-                          'sys.stdout.flush();'
-                          'sys.stdout.write("\\nline5");'
-                          'sys.stdout.flush();'
-                          'sys.stdout.write("\\nline6");'],
-                         stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-                         universal_newlines=1)
+                              'import sys,os;' + SETBINARY +
+                              'sys.stdout.write("line1\\n");'
+                              'sys.stdout.flush();'
+                              'sys.stdout.write("line2\\n");'
+                              'sys.stdout.flush();'
+                              'sys.stdout.write("line3\\r\\n");'
+                              'sys.stdout.flush();'
+                              'sys.stdout.write("line4\\r");'
+                              'sys.stdout.flush();'
+                              'sys.stdout.write("\\nline5");'
+                              'sys.stdout.flush();'
+                              'sys.stdout.write("\\nline6");'],
+                             stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+                             universal_newlines=1)
         (stdout, stderr) = p.communicate()
         self.assertEqual(stdout, "line1\nline2\nline3\nline4\nline5\nline6")
 
     def test_no_leaking(self):
         # Make sure we leak no resources
-        if not hasattr(test_support, "is_resource_enabled") \
-               or test_support.is_resource_enabled("subprocess") and not mswindows:
+        if (not hasattr(test_support, "is_resource_enabled") or
+            test_support.is_resource_enabled("subprocess") and not mswindows):
             max_handles = 1026 # too much for most UNIX systems
         else:
             max_handles = 65
         for i in range(max_handles):
             p = subprocess.Popen([sys.executable, "-c",
-                    "import sys;sys.stdout.write(sys.stdin.read())"],
-                    stdin=subprocess.PIPE,
-                    stdout=subprocess.PIPE,
-                    stderr=subprocess.PIPE)
+                                  "import sys;"
+                                  "sys.stdout.write(sys.stdin.read())"],
+                                 stdin=subprocess.PIPE,
+                                 stdout=subprocess.PIPE,
+                                 stderr=subprocess.PIPE)
             data = p.communicate("lime")[0]
             self.assertEqual(data, b"lime")
 
@@ -410,6 +413,8 @@
                          '"a b c" d e')
         self.assertEqual(subprocess.list2cmdline(['ab"c', '\\', 'd']),
                          'ab\\"c \\ d')
+        self.assertEqual(subprocess.list2cmdline(['ab"c', ' \\', 'd']),
+                         'ab\\"c " \\\\" d')
         self.assertEqual(subprocess.list2cmdline(['a\\\\\\b', 'de fg', 'h']),
                          'a\\\\\\b "de fg" h')
         self.assertEqual(subprocess.list2cmdline(['a\\"b', 'c', 'd']),
@@ -420,6 +425,8 @@
                          '"a\\\\b\\ c" d e')
         self.assertEqual(subprocess.list2cmdline(['ab', '']),
                          'ab ""')
+        self.assertEqual(subprocess.list2cmdline(['echo', 'foo|bar']),
+                         'echo "foo|bar"')
 
 
     def test_poll(self):
@@ -516,10 +523,11 @@
         def test_preexec(self):
             # preexec function
             p = subprocess.Popen([sys.executable, "-c",
-                              'import sys,os;' \
-                              'sys.stdout.write(os.getenv("FRUIT"))'],
-                             stdout=subprocess.PIPE,
-                             preexec_fn=lambda: os.putenv("FRUIT", "apple"))
+                                  'import sys,os;'
+                                  'sys.stdout.write(os.getenv("FRUIT"))'],
+                                 stdout=subprocess.PIPE,
+                                 preexec_fn=lambda: os.putenv("FRUIT",
+                                                              "apple"))
             self.assertEqual(p.stdout.read(), b"apple")
 
         def test_args_string(self):
@@ -630,7 +638,7 @@
             p = subprocess.Popen(["set"], shell=1,
                                  stdout=subprocess.PIPE,
                                  env=newenv)
-            self.assertNotEqual(p.stdout.read().find("physalis"), -1)
+            self.assertNotEqual(p.stdout.read().find(b"physalis"), -1)
 
         def test_shell_string(self):
             # Run command through the shell (string)
@@ -639,7 +647,7 @@
             p = subprocess.Popen("set", shell=1,
                                  stdout=subprocess.PIPE,
                                  env=newenv)
-            self.assertNotEqual(p.stdout.read().find("physalis"), -1)
+            self.assertNotEqual(p.stdout.read().find(b"physalis"), -1)
 
         def test_call_string(self):
             # call() function with string argument on Windows
@@ -654,4 +662,4 @@
         test_support.reap_children()
 
 if __name__ == "__main__":
-    test_main()
+    unittest.main()  # XXX test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_support.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_support.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_support.py	Thu Mar 27 00:48:05 2008
@@ -9,8 +9,8 @@
 import sys
 import os
 import os.path
+import shutil
 import warnings
-import types
 import unittest
 
 class Error(Exception):
@@ -65,6 +65,14 @@
     except OSError:
         pass
 
+def rmtree(path):
+    try:
+        shutil.rmtree(path)
+    except OSError as e:
+        # Unix returns ENOENT, Windows returns ESRCH.
+        if e.errno not in (errno.ENOENT, errno.ESRCH):
+            raise
+
 def forget(modname):
     '''"Forget" a module was ever imported by removing it from sys.modules and
     deleting any .pyc and .pyo files.'''
@@ -97,19 +105,29 @@
 
 def bind_port(sock, host='', preferred_port=54321):
     """Try to bind the sock to a port.  If we are running multiple
-    tests and we don't try multiple ports, the test can fails.  This
+    tests and we don't try multiple ports, the test can fail.  This
     makes the test more robust."""
 
-    # some random ports that hopefully no one is listening on.
-    for port in [preferred_port, 9907, 10243, 32999]:
+    # Find some random ports that hopefully no one is listening on.
+    # Ideally each test would clean up after itself and not continue listening
+    # on any ports.  However, this isn't the case.  The last port (0) is
+    # a stop-gap that asks the O/S to assign a port.  Whenever the warning
+    # message below is printed, the test that is listening on the port should
+    # be fixed to close the socket at the end of the test.
+    # Another reason why we can't use a port is another process (possibly
+    # another instance of the test suite) is using the same port.
+    for port in [preferred_port, 9907, 10243, 32999, 0]:
         try:
             sock.bind((host, port))
+            if port == 0:
+                port = sock.getsockname()[1]
             return port
         except socket.error as e:
             (err, msg) = e.args
             if err != errno.EADDRINUSE:
                 raise
-            print('  WARNING: failed to listen on port %d, trying another' % port, file=sys.__stderr__)
+            print('  WARNING: failed to listen on port %d, ' % port +
+                  'trying another', file=sys.__stderr__)
     raise TestFailed('unable to find port to listen on')
 
 FUZZ = 1e-6
@@ -170,9 +188,9 @@
         except UnicodeEncodeError:
             pass
         else:
-            print('WARNING: The filename %r CAN be encoded by the filesystem.  ' \
-            'Unicode filename tests may not be effective' \
-            % TESTFN_UNICODE_UNENCODEABLE)
+            print('WARNING: The filename %r CAN be encoded by the filesystem.  '
+                  'Unicode filename tests may not be effective'
+                  % TESTFN_UNICODE_UNENCODEABLE)
 
 # Make sure we can write to TESTFN, try in /tmp if we can't
 fp = None
@@ -415,7 +433,8 @@
     return decorator
 
 #=======================================================================
-# Big-memory-test support. Separate from 'resources' because memory use should be configurable.
+# Big-memory-test support. Separate from 'resources' because memory use
+# should be configurable.
 
 # Some handy shorthands. Note that these are used for byte-limits as well
 # as size-limits, in the various bigmem tests
@@ -519,8 +538,7 @@
         elif len(result.failures) == 1 and not result.errors:
             err = result.failures[0][1]
         else:
-            msg = "errors occurred; run in verbose mode for details"
-            raise TestFailed(msg)
+            err = "errors occurred; run in verbose mode for details"
         raise TestFailed(err)
 
 
@@ -529,7 +547,7 @@
     valid_types = (unittest.TestSuite, unittest.TestCase)
     suite = unittest.TestSuite()
     for cls in classes:
-        if isinstance(cls, basestring):
+        if isinstance(cls, str):
             if cls in sys.modules:
                 suite.addTest(unittest.findTestCases(sys.modules[cls]))
             else:
@@ -570,7 +588,8 @@
     finally:
         sys.stdout = save_stdout
     if verbose:
-        print('doctest (%s) ... %d tests with zero failures' % (module.__name__, t))
+        print('doctest (%s) ... %d tests with zero failures' %
+              (module.__name__, t))
     return f, t
 
 #=======================================================================

Modified: python/branches/py3k-importlib/Lib/test/test_sys.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_sys.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_sys.py	Thu Mar 27 00:48:05 2008
@@ -4,48 +4,50 @@
 
 class SysModuleTest(unittest.TestCase):
 
+    def setUp(self):
+        self.orig_stdout = sys.stdout
+        self.orig_stderr = sys.stderr
+        self.orig_displayhook = sys.displayhook
+
+    def tearDown(self):
+        sys.stdout = self.orig_stdout
+        sys.stderr = self.orig_stderr
+        sys.displayhook = self.orig_displayhook
+
     def test_original_displayhook(self):
-        import __builtin__
-        savestdout = sys.stdout
+        import builtins
         out = io.StringIO()
         sys.stdout = out
 
         dh = sys.__displayhook__
 
         self.assertRaises(TypeError, dh)
-        if hasattr(__builtin__, "_"):
-            del __builtin__._
+        if hasattr(builtins, "_"):
+            del builtins._
 
         dh(None)
         self.assertEqual(out.getvalue(), "")
-        self.assert_(not hasattr(__builtin__, "_"))
+        self.assert_(not hasattr(builtins, "_"))
         dh(42)
         self.assertEqual(out.getvalue(), "42\n")
-        self.assertEqual(__builtin__._, 42)
+        self.assertEqual(builtins._, 42)
 
         del sys.stdout
         self.assertRaises(RuntimeError, dh, 42)
 
-        sys.stdout = savestdout
-
     def test_lost_displayhook(self):
-        olddisplayhook = sys.displayhook
         del sys.displayhook
         code = compile("42", "<string>", "single")
         self.assertRaises(RuntimeError, eval, code)
-        sys.displayhook = olddisplayhook
 
     def test_custom_displayhook(self):
-        olddisplayhook = sys.displayhook
         def baddisplayhook(obj):
             raise ValueError
         sys.displayhook = baddisplayhook
         code = compile("42", "<string>", "single")
         self.assertRaises(ValueError, eval, code)
-        sys.displayhook = olddisplayhook
 
     def test_original_excepthook(self):
-        savestderr = sys.stderr
         err = io.StringIO()
         sys.stderr = err
 
@@ -57,7 +59,6 @@
         except ValueError as exc:
             eh(*sys.exc_info())
 
-        sys.stderr = savestderr
         self.assert_(err.getvalue().endswith("ValueError: 42\n"))
 
     # FIXME: testing the code for a lost or replaced excepthook in
@@ -126,7 +127,7 @@
     def test_getdefaultencoding(self):
         self.assertRaises(TypeError, sys.getdefaultencoding, 42)
         # can't check more than the type, as the user might have changed it
-        self.assert_(isinstance(sys.getdefaultencoding(), basestring))
+        self.assert_(isinstance(sys.getdefaultencoding(), str))
 
     # testing sys.settrace() is done in test_trace.py
     # testing sys.setprofile() is done in test_profile.py
@@ -182,7 +183,7 @@
         self.assertRaises(TypeError, sys._getframe, 42, 42)
         self.assertRaises(ValueError, sys._getframe, 2000000000)
         self.assert_(
-            SysModuleTest.test_getframe.im_func.__code__ \
+            SysModuleTest.test_getframe.__code__ \
             is sys._getframe().f_code
         )
 
@@ -275,15 +276,17 @@
         self.assert_(isinstance(sys.argv, list))
         self.assert_(sys.byteorder in ("little", "big"))
         self.assert_(isinstance(sys.builtin_module_names, tuple))
-        self.assert_(isinstance(sys.copyright, basestring))
-        self.assert_(isinstance(sys.exec_prefix, basestring))
-        self.assert_(isinstance(sys.executable, basestring))
+        self.assert_(isinstance(sys.copyright, str))
+        self.assert_(isinstance(sys.exec_prefix, str))
+        self.assert_(isinstance(sys.executable, str))
+        self.assertEqual(len(sys.float_info), 11)
+        self.assertEqual(sys.float_info.radix, 2)
         self.assert_(isinstance(sys.hexversion, int))
-        self.assert_(isinstance(sys.maxint, int))
+        self.assert_(isinstance(sys.maxsize, int))
         self.assert_(isinstance(sys.maxunicode, int))
-        self.assert_(isinstance(sys.platform, basestring))
-        self.assert_(isinstance(sys.prefix, basestring))
-        self.assert_(isinstance(sys.version, basestring))
+        self.assert_(isinstance(sys.platform, str))
+        self.assert_(isinstance(sys.prefix, str))
+        self.assert_(isinstance(sys.version, str))
         vi = sys.version_info
         self.assert_(isinstance(vi, tuple))
         self.assertEqual(len(vi), 5)
@@ -300,7 +303,7 @@
 
     def test_intern(self):
         self.assertRaises(TypeError, sys.intern)
-        s = str8("never interned before")
+        s = "never interned before"
         self.assert_(sys.intern(s) is s)
         s2 = s.swapcase().swapcase()
         self.assert_(sys.intern(s2) is s)
@@ -310,29 +313,40 @@
         # We don't want them in the interned dict and if they aren't
         # actually interned, we don't want to create the appearance
         # that they are by allowing intern() to succeeed.
-        class S(str8):
+        class S(str):
             def __hash__(self):
                 return 123
 
         self.assertRaises(TypeError, sys.intern, S("abc"))
 
-        s = "never interned as unicode before"
-        self.assert_(sys.intern(s) is s)
-        s2 = s.swapcase().swapcase()
-        self.assert_(sys.intern(s2) is s)
-
-        class U(str):
-            def __hash__(self):
-                return 123
-
-        self.assertRaises(TypeError, sys.intern, U("abc"))
-
-        # It's still safe to pass these strings to routines that
-        # call intern internally, e.g. PyObject_SetAttr().
-        s = U("abc")
-        setattr(s, s, s)
-        self.assertEqual(getattr(s, s), s)
 
+    def test_sys_flags(self):
+        self.failUnless(sys.flags)
+        attrs = ("debug", "division_warning",
+                 "inspect", "interactive", "optimize", "dont_write_bytecode",
+                 "no_site", "ignore_environment", "tabcheck", "verbose")
+        for attr in attrs:
+            self.assert_(hasattr(sys.flags, attr), attr)
+            self.assertEqual(type(getattr(sys.flags, attr)), int, attr)
+        self.assert_(repr(sys.flags))
+
+    def test_clear_type_cache(self):
+        sys._clear_type_cache()
+
+    def test_compact_freelists(self):
+        sys._compact_freelists()
+        r = sys._compact_freelists()
+        ## freed blocks shouldn't change
+        #self.assertEqual(r[0][2], 0)
+        ## fill freelists
+        #ints = list(range(10000))
+        #floats = [float(i) for i in ints]
+        #del ints
+        #del floats
+        ## should free more than 100 blocks
+        #r = sys._compact_freelists()
+        #self.assert_(r[0][1] > 100, r[0][1])
+        #self.assert_(r[0][2] > 100, r[0][2])
 
 def test_main():
     test.test_support.run_unittest(SysModuleTest)

Modified: python/branches/py3k-importlib/Lib/test/test_tarfile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_tarfile.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_tarfile.py	Thu Mar 27 00:48:05 2008
@@ -159,6 +159,38 @@
         tar = tarfile.open(fileobj=fobj, mode=self.mode)
         self.assertEqual(tar.name, None)
 
+    def test_fileobj_with_offset(self):
+        # Skip the first member and store values from the second member
+        # of the testtar.
+        tar = tarfile.open(self.tarname, mode=self.mode)
+        tar.next()
+        t = tar.next()
+        name = t.name
+        offset = t.offset
+        data = tar.extractfile(t).read()
+        tar.close()
+
+        # Open the testtar and seek to the offset of the second member.
+        if self.mode.endswith(":gz"):
+            _open = gzip.GzipFile
+        elif self.mode.endswith(":bz2"):
+            _open = bz2.BZ2File
+        else:
+            _open = open
+        fobj = _open(self.tarname, "rb")
+        fobj.seek(offset)
+
+        # Test if the tarfile starts with the second member.
+        tar = tar.open(self.tarname, mode="r:", fileobj=fobj)
+        t = tar.next()
+        self.assertEqual(t.name, name)
+        # Read to the end of fileobj and test if seeking back to the
+        # beginning works.
+        tar.getmembers()
+        self.assertEqual(tar.extractfile(t).read(), data,
+                "seek back did not work")
+        tar.close()
+
     def test_fail_comp(self):
         # For Gzip and Bz2 Tests: fail with a ReadError on an uncompressed file.
         if self.mode == "r:":
@@ -175,6 +207,15 @@
         self.assert_(tarinfo.type == tarfile.DIRTYPE,
                 "v7 dirtype failed")
 
+    def test_xstar_type(self):
+        # The xstar format stores extra atime and ctime fields inside the
+        # space reserved for the prefix field. The prefix field must be
+        # ignored in this case, otherwise it will mess up the name.
+        try:
+            self.tar.getmember("misc/regtype-xstar")
+        except KeyError:
+            self.fail("failed to find misc/regtype-xstar (mangled prefix?)")
+
     def test_check_members(self):
         for tarinfo in self.tar:
             self.assert_(int(tarinfo.mtime) == 0o7606136617,
@@ -211,6 +252,23 @@
         data = open(os.path.join(TEMPDIR, "ustar/symtype"), "rb").read()
         self.assertEqual(md5sum(data), md5_regtype)
 
+    def test_extractall(self):
+        # Test if extractall() correctly restores directory permissions
+        # and times (see issue1735).
+        if sys.platform == "win32":
+            # Win32 has no support for utime() on directories or
+            # fine grained permissions.
+            return
+
+        tar = tarfile.open(tarname, encoding="iso8859-1")
+        directories = [t for t in tar if t.isdir()]
+        tar.extractall(TEMPDIR, directories)
+        for tarinfo in directories:
+            path = os.path.join(TEMPDIR, tarinfo.name)
+            self.assertEqual(tarinfo.mode & 0o777, os.stat(path).st_mode & 0o777)
+            self.assertEqual(tarinfo.mtime, os.path.getmtime(path))
+        tar.close()
+
 
 class StreamReadTest(ReadTest):
 

Modified: python/branches/py3k-importlib/Lib/test/test_telnetlib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_telnetlib.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_telnetlib.py	Thu Mar 27 00:48:05 2008
@@ -7,13 +7,13 @@
 from test import test_support
 
 
-def server(evt, ready):
+def server(evt):
     serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     serv.settimeout(3)
     serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     serv.bind(("", 9091))
     serv.listen(5)
-    ready.set()
+    evt.set()
     try:
         conn, addr = serv.accept()
     except socket.timeout:
@@ -26,9 +26,10 @@
 
     def setUp(self):
         self.evt = threading.Event()
-        ready = threading.Event()
-        threading.Thread(target=server, args=(self.evt, ready)).start()
-        ready.wait()
+        threading.Thread(target=server, args=(self.evt,)).start()
+        self.evt.wait()
+        self.evt.clear()
+        time.sleep(.1)
 
     def tearDown(self):
         self.evt.wait()

Modified: python/branches/py3k-importlib/Lib/test/test_tempfile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_tempfile.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_tempfile.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,4 @@
 # tempfile.py unit tests.
-
 import tempfile
 import os
 import sys
@@ -143,7 +142,7 @@
 
         self.failIf(len(cand) == 0)
         for c in cand:
-            self.assert_(isinstance(c, basestring),
+            self.assert_(isinstance(c, str),
                          "%s is not a string" % c)
 
     def test_wanted_dirs(self):
@@ -299,7 +298,7 @@
         # On Windows a spawn* /path/ with embedded spaces shouldn't be quoted,
         # but an arg with embedded spaces should be decorated with double
         # quotes on each end
-        if sys.platform in ('win32'):
+        if sys.platform in ('win32',):
             decorated = '"%s"' % sys.executable
             tester = '"%s"' % tester
         else:
@@ -328,7 +327,7 @@
         # gettempprefix returns a nonempty prefix string
         p = tempfile.gettempprefix()
 
-        self.assert_(isinstance(p, basestring))
+        self.assert_(isinstance(p, str))
         self.assert_(len(p) > 0)
 
     def test_usable_template(self):
@@ -463,7 +462,7 @@
                 extant[i] = self.do_create(pre="aa")
         finally:
             for i in extant:
-                if(isinstance(i, basestring)):
+                if(isinstance(i, str)):
                     os.rmdir(i)
 
     def test_choose_directory(self):
@@ -619,7 +618,6 @@
 
     def test_multiple_close(self):
         # A NamedTemporaryFile can be closed many times without error
-
         f = tempfile.NamedTemporaryFile()
         f.write(b'abc\n')
         f.close()
@@ -629,6 +627,16 @@
         except:
             self.failOnException("close")
 
+    def test_context_manager(self):
+        # A NamedTemporaryFile can be used as a context manager
+        with tempfile.NamedTemporaryFile() as f:
+            self.failUnless(os.path.exists(f.name))
+        self.failIf(os.path.exists(f.name))
+        def use_closed():
+            with f:
+                pass
+        self.failUnlessRaises(ValueError, use_closed)
+
     # How to test the mode and bufsize parameters?
 
 test_classes.append(test_NamedTemporaryFile)
@@ -707,10 +715,23 @@
         self.failUnless(f.fileno() > 0)
         self.failUnless(f._rolled)
 
-    def test_multiple_close(self):
+    def test_multiple_close_before_rollover(self):
         # A SpooledTemporaryFile can be closed many times without error
         f = tempfile.SpooledTemporaryFile()
         f.write(b'abc\n')
+        self.failIf(f._rolled)
+        f.close()
+        try:
+            f.close()
+            f.close()
+        except:
+            self.failOnException("close")
+
+    def test_multiple_close_after_rollover(self):
+        # A SpooledTemporaryFile can be closed many times without error
+        f = tempfile.SpooledTemporaryFile(max_size=1)
+        f.write(b'abc\n')
+        self.failUnless(f._rolled)
         f.close()
         try:
             f.close()
@@ -759,6 +780,46 @@
         self.assertEqual(f.read(), "\u039B\r\n" + ("\u039B" * 20) + "\r\n")
         self.failUnless(f._rolled)
 
+    def test_context_manager_before_rollover(self):
+        # A SpooledTemporaryFile can be used as a context manager
+        with tempfile.SpooledTemporaryFile(max_size=1) as f:
+            self.failIf(f._rolled)
+            self.failIf(f.closed)
+        self.failUnless(f.closed)
+        def use_closed():
+            with f:
+                pass
+        self.failUnlessRaises(ValueError, use_closed)
+
+    def test_context_manager_during_rollover(self):
+        # A SpooledTemporaryFile can be used as a context manager
+        with tempfile.SpooledTemporaryFile(max_size=1) as f:
+            self.failIf(f._rolled)
+            f.write(b'abc\n')
+            f.flush()
+            self.failUnless(f._rolled)
+            self.failIf(f.closed)
+        self.failUnless(f.closed)
+        def use_closed():
+            with f:
+                pass
+        self.failUnlessRaises(ValueError, use_closed)
+
+    def test_context_manager_after_rollover(self):
+        # A SpooledTemporaryFile can be used as a context manager
+        f = tempfile.SpooledTemporaryFile(max_size=1)
+        f.write(b'abc\n')
+        f.flush()
+        self.failUnless(f._rolled)
+        with f:
+            self.failIf(f.closed)
+        self.failUnless(f.closed)
+        def use_closed():
+            with f:
+                pass
+        self.failUnlessRaises(ValueError, use_closed)
+
+
 test_classes.append(test_SpooledTemporaryFile)
 
 

Modified: python/branches/py3k-importlib/Lib/test/test_textwrap.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_textwrap.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_textwrap.py	Thu Mar 27 00:48:05 2008
@@ -23,7 +23,7 @@
             for i in range(len(textin)):
                 result.append("  %d: %r" % (i, textin[i]))
             result = '\n'.join(result)
-        elif isinstance(textin, basestring):
+        elif isinstance(textin, str):
             result = "  %s\n" % repr(textin)
         return result
 
@@ -385,6 +385,19 @@
                          '               o'],
                         subsequent_indent = ' '*15)
 
+        # bug 1146.  Prevent a long word to be wrongly wrapped when the
+        # preceding word is exactly one character shorter than the width
+        self.check_wrap(self.text, 12,
+                        ['Did you say ',
+                         '"supercalifr',
+                         'agilisticexp',
+                         'ialidocious?',
+                         '" How *do*',
+                         'you spell',
+                         'that odd',
+                         'word,',
+                         'anyways?'])
+
     def test_nobreak_long(self):
         # Test with break_long_words disabled
         self.wrapper.break_long_words = 0

Modified: python/branches/py3k-importlib/Lib/test/test_thread.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_thread.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_thread.py	Thu Mar 27 00:48:05 2008
@@ -1,160 +1,165 @@
-# Very rudimentary test of thread module
-
-# Create a bunch of threads, let each do some work, wait until all are done
-
-from test.test_support import verbose
+import os
+import unittest
 import random
+from test import test_support
 import thread
 import time
 
-mutex = thread.allocate_lock()
-rmutex = thread.allocate_lock() # for calls to random
-running = 0
-done = thread.allocate_lock()
-done.acquire()
-
-numtasks = 10
-
-def task(ident):
-    global running
-    rmutex.acquire()
-    delay = random.random() * numtasks
-    rmutex.release()
-    if verbose:
-        print('task', ident, 'will run for', round(delay, 1), 'sec')
-    time.sleep(delay)
-    if verbose:
-        print('task', ident, 'done')
-    mutex.acquire()
-    running = running - 1
-    if running == 0:
-        done.release()
-    mutex.release()
-
-next_ident = 0
-def newtask():
-    global next_ident, running
-    mutex.acquire()
-    next_ident = next_ident + 1
-    if verbose:
-        print('creating task', next_ident)
-    thread.start_new_thread(task, (next_ident,))
-    running = running + 1
-    mutex.release()
-
-for i in range(numtasks):
-    newtask()
-
-print('waiting for all tasks to complete')
-done.acquire()
-print('all tasks done')
-
-class barrier:
-    def __init__(self, n):
-        self.n = n
+
+NUMTASKS = 10
+NUMTRIPS = 3
+
+_print_mutex = thread.allocate_lock()
+
+def verbose_print(arg):
+    """Helper function for printing out debugging output."""
+    if test_support.verbose:
+        with _print_mutex:
+            print(arg)
+
+class BasicThreadTest(unittest.TestCase):
+
+    def setUp(self):
+        self.done_mutex = thread.allocate_lock()
+        self.done_mutex.acquire()
+        self.running_mutex = thread.allocate_lock()
+        self.random_mutex = thread.allocate_lock()
+        self.running = 0
+        self.next_ident = 0
+
+
+class ThreadRunningTests(BasicThreadTest):
+
+    def newtask(self):
+        with self.running_mutex:
+            self.next_ident += 1
+            verbose_print("creating task %s" % self.next_ident)
+            thread.start_new_thread(self.task, (self.next_ident,))
+            self.running += 1
+
+    def task(self, ident):
+        with self.random_mutex:
+            delay = random.random() / 10000.0
+        verbose_print("task %s will run for %sus" % (ident, round(delay*1e6)))
+        time.sleep(delay)
+        verbose_print("task %s done" % ident)
+        with self.running_mutex:
+            self.running -= 1
+            if self.running == 0:
+                self.done_mutex.release()
+
+    def test_starting_threads(self):
+        # Basic test for thread creation.
+        for i in range(NUMTASKS):
+            self.newtask()
+        verbose_print("waiting for tasks to complete...")
+        self.done_mutex.acquire()
+        verbose_print("all tasks done")
+
+    def test_stack_size(self):
+        # Various stack size tests.
+        self.assertEquals(thread.stack_size(), 0, "intial stack size is not 0")
+
+        thread.stack_size(0)
+        self.assertEquals(thread.stack_size(), 0, "stack_size not reset to default")
+
+        if os.name not in ("nt", "os2", "posix"):
+            return
+
+        tss_supported = True
+        try:
+            thread.stack_size(4096)
+        except ValueError:
+            verbose_print("caught expected ValueError setting "
+                            "stack_size(4096)")
+        except thread.error:
+            tss_supported = False
+            verbose_print("platform does not support changing thread stack "
+                            "size")
+
+        if tss_supported:
+            fail_msg = "stack_size(%d) failed - should succeed"
+            for tss in (262144, 0x100000, 0):
+                thread.stack_size(tss)
+                self.assertEquals(thread.stack_size(), tss, fail_msg % tss)
+                verbose_print("successfully set stack_size(%d)" % tss)
+
+            for tss in (262144, 0x100000):
+                verbose_print("trying stack_size = (%d)" % tss)
+                self.next_ident = 0
+                for i in range(NUMTASKS):
+                    self.newtask()
+
+                verbose_print("waiting for all tasks to complete")
+                self.done_mutex.acquire()
+                verbose_print("all tasks done")
+
+            thread.stack_size(0)
+
+
+class Barrier:
+    def __init__(self, num_threads):
+        self.num_threads = num_threads
         self.waiting = 0
-        self.checkin  = thread.allocate_lock()
-        self.checkout = thread.allocate_lock()
-        self.checkout.acquire()
+        self.checkin_mutex  = thread.allocate_lock()
+        self.checkout_mutex = thread.allocate_lock()
+        self.checkout_mutex.acquire()
 
     def enter(self):
-        checkin, checkout = self.checkin, self.checkout
-
-        checkin.acquire()
+        self.checkin_mutex.acquire()
         self.waiting = self.waiting + 1
-        if self.waiting == self.n:
-            self.waiting = self.n - 1
-            checkout.release()
+        if self.waiting == self.num_threads:
+            self.waiting = self.num_threads - 1
+            self.checkout_mutex.release()
             return
-        checkin.release()
+        self.checkin_mutex.release()
 
-        checkout.acquire()
+        self.checkout_mutex.acquire()
         self.waiting = self.waiting - 1
         if self.waiting == 0:
-            checkin.release()
+            self.checkin_mutex.release()
             return
-        checkout.release()
+        self.checkout_mutex.release()
 
-numtrips = 3
-def task2(ident):
-    global running
-    for i in range(numtrips):
-        if ident == 0:
-            # give it a good chance to enter the next
-            # barrier before the others are all out
-            # of the current one
-            delay = 0.001
-        else:
-            rmutex.acquire()
-            delay = random.random() * numtasks
-            rmutex.release()
-        if verbose:
-            print('task', ident, 'will run for', round(delay, 1), 'sec')
-        time.sleep(delay)
-        if verbose:
-            print('task', ident, 'entering barrier', i)
-        bar.enter()
-        if verbose:
-            print('task', ident, 'leaving barrier', i)
-    mutex.acquire()
-    running -= 1
-    # Must release mutex before releasing done, else the main thread can
-    # exit and set mutex to None as part of global teardown; then
-    # mutex.release() raises AttributeError.
-    finished = running == 0
-    mutex.release()
-    if finished:
-        done.release()
-
-print('\n*** Barrier Test ***')
-if done.acquire(0):
-    raise ValueError("'done' should have remained acquired")
-bar = barrier(numtasks)
-running = numtasks
-for i in range(numtasks):
-    thread.start_new_thread(task2, (i,))
-done.acquire()
-print('all tasks done')
-
-# not all platforms support changing thread stack size
-print('\n*** Changing thread stack size ***')
-if thread.stack_size() != 0:
-    raise ValueError("initial stack_size not 0")
-
-thread.stack_size(0)
-if thread.stack_size() != 0:
-    raise ValueError("stack_size not reset to default")
-
-from os import name as os_name
-if os_name in ("nt", "os2", "posix"):
-
-    tss_supported = 1
-    try:
-        thread.stack_size(4096)
-    except ValueError:
-        print('caught expected ValueError setting stack_size(4096)')
-    except thread.error:
-        tss_supported = 0
-        print('platform does not support changing thread stack size')
-
-    if tss_supported:
-        failed = lambda s, e: s != e
-        fail_msg = "stack_size(%d) failed - should succeed"
-        for tss in (262144, 0x100000, 0):
-            thread.stack_size(tss)
-            if failed(thread.stack_size(), tss):
-                raise ValueError(fail_msg % tss)
-            print('successfully set stack_size(%d)' % tss)
-
-        for tss in (262144, 0x100000):
-            print('trying stack_size = %d' % tss)
-            next_ident = 0
-            for i in range(numtasks):
-                newtask()
-
-            print('waiting for all tasks to complete')
-            done.acquire()
-            print('all tasks done')
 
-        # reset stack size to default
-        thread.stack_size(0)
+class BarrierTest(BasicThreadTest):
+
+    def test_barrier(self):
+        self.bar = Barrier(NUMTASKS)
+        self.running = NUMTASKS
+        for i in range(NUMTASKS):
+            thread.start_new_thread(self.task2, (i,))
+        verbose_print("waiting for tasks to end")
+        self.done_mutex.acquire()
+        verbose_print("tasks done")
+
+    def task2(self, ident):
+        for i in range(NUMTRIPS):
+            if ident == 0:
+                # give it a good chance to enter the next
+                # barrier before the others are all out
+                # of the current one
+                delay = 0
+            else:
+                with self.random_mutex:
+                    delay = random.random() / 10000.0
+            verbose_print("task %s will run for %sus" %
+                          (ident, round(delay * 1e6)))
+            time.sleep(delay)
+            verbose_print("task %s entering %s" % (ident, i))
+            self.bar.enter()
+            verbose_print("task %s leaving barrier" % ident)
+        with self.running_mutex:
+            self.running -= 1
+            # Must release mutex before releasing done, else the main thread can
+            # exit and set mutex to None as part of global teardown; then
+            # mutex.release() raises AttributeError.
+            finished = self.running == 0
+        if finished:
+            self.done_mutex.release()
+
+def test_main():
+    test_support.run_unittest(ThreadRunningTests, BarrierTest)
+
+if __name__ == "__main__":
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_threading.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_threading.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_threading.py	Thu Mar 27 00:48:05 2008
@@ -8,6 +8,7 @@
 import thread
 import time
 import unittest
+import weakref
 
 # A trivial mutable counter.
 class Counter(object):
@@ -29,32 +30,26 @@
         self.nrunning = nrunning
 
     def run(self):
-        delay = random.random() * 2
+        delay = random.random() / 10000.0
         if verbose:
             print('task', self.getName(), 'will run for', delay, 'sec')
 
-        self.sema.acquire()
+        with self.sema:
+            with self.mutex:
+                self.nrunning.inc()
+                if verbose:
+                    print(self.nrunning.get(), 'tasks are running')
+                self.testcase.assert_(self.nrunning.get() <= 3)
 
-        self.mutex.acquire()
-        self.nrunning.inc()
-        if verbose:
-            print(self.nrunning.get(), 'tasks are running')
-        self.testcase.assert_(self.nrunning.get() <= 3)
-        self.mutex.release()
-
-        time.sleep(delay)
-        if verbose:
-            print('task', self.getName(), 'done')
-
-        self.mutex.acquire()
-        self.nrunning.dec()
-        self.testcase.assert_(self.nrunning.get() >= 0)
-        if verbose:
-            print(self.getName(), 'is finished.', self.nrunning.get(), \
-                  'tasks are running')
-        self.mutex.release()
-
-        self.sema.release()
+            time.sleep(delay)
+            if verbose:
+                print('task', self.getName(), 'done')
+            with self.mutex:
+                self.nrunning.dec()
+                self.testcase.assert_(self.nrunning.get() >= 0)
+                if verbose:
+                    print('%s is finished. %d tasks are running' %
+                        self.getName(), self.nrunning.get())
 
 class ThreadTests(unittest.TestCase):
 
@@ -202,6 +197,89 @@
             t.join()
         # else the thread is still running, and we have no way to kill it
 
+    def test_finalize_runnning_thread(self):
+        # Issue 1402: the PyGILState_Ensure / _Release functions may be called
+        # very late on python exit: on deallocation of a running thread for
+        # example.
+        try:
+            import ctypes
+        except ImportError:
+            if verbose:
+                print("test_finalize_with_runnning_thread can't import ctypes")
+            return  # can't do anything
+
+        import subprocess
+        rc = subprocess.call([sys.executable, "-c", """if 1:
+            import ctypes, sys, time, thread
+
+            # This lock is used as a simple event variable.
+            ready = thread.allocate_lock()
+            ready.acquire()
+
+            # Module globals are cleared before __del__ is run
+            # So we save the functions in class dict
+            class C:
+                ensure = ctypes.pythonapi.PyGILState_Ensure
+                release = ctypes.pythonapi.PyGILState_Release
+                def __del__(self):
+                    state = self.ensure()
+                    self.release(state)
+
+            def waitingThread():
+                x = C()
+                ready.release()
+                time.sleep(100)
+
+            thread.start_new_thread(waitingThread, ())
+            ready.acquire()  # Be sure the other thread is waiting.
+            sys.exit(42)
+            """])
+        self.assertEqual(rc, 42)
+
+    def test_enumerate_after_join(self):
+        # Try hard to trigger #1703448: a thread is still returned in
+        # threading.enumerate() after it has been join()ed.
+        enum = threading.enumerate
+        old_interval = sys.getcheckinterval()
+        try:
+            for i in range(1, 1000):
+                t = threading.Thread(target=lambda: None)
+                t.start()
+                t.join()
+                l = enum()
+                self.assertFalse(t in l,
+                    "#1703448 triggered after %d trials: %s" % (i, l))
+        finally:
+            sys.setcheckinterval(old_interval)
+
+    def test_no_refcycle_through_target(self):
+        class RunSelfFunction(object):
+            def __init__(self, should_raise):
+                # The links in this refcycle from Thread back to self
+                # should be cleaned up when the thread completes.
+                self.should_raise = should_raise
+                self.thread = threading.Thread(target=self._run,
+                                               args=(self,),
+                                               kwargs={'yet_another':self})
+                self.thread.start()
+
+            def _run(self, other_ref, yet_another):
+                if self.should_raise:
+                    raise SystemExit
+
+        cyclic_object = RunSelfFunction(should_raise=False)
+        weak_cyclic_object = weakref.ref(cyclic_object)
+        cyclic_object.thread.join()
+        del cyclic_object
+        self.assertEquals(None, weak_cyclic_object())
+
+        raising_cyclic_object = RunSelfFunction(should_raise=True)
+        weak_raising_cyclic_object = weakref.ref(raising_cyclic_object)
+        raising_cyclic_object.thread.join()
+        del raising_cyclic_object
+        self.assertEquals(None, weak_raising_cyclic_object())
+
+
 class ThreadingExceptionTests(unittest.TestCase):
     # A RuntimeError should be raised if Thread.start() is called
     # multiple times.
@@ -224,7 +302,7 @@
 
     def test_semaphore_with_negative_value(self):
         self.assertRaises(ValueError, threading.Semaphore, value = -1)
-        self.assertRaises(ValueError, threading.Semaphore, value = -sys.maxint)
+        self.assertRaises(ValueError, threading.Semaphore, value = -sys.maxsize)
 
     def test_joining_current_thread(self):
         currentThread = threading.currentThread()

Modified: python/branches/py3k-importlib/Lib/test/test_threading_local.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_threading_local.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_threading_local.py	Thu Mar 27 00:48:05 2008
@@ -1,9 +1,51 @@
 import unittest
 from doctest import DocTestSuite
 from test import test_support
+import threading
+import weakref
+import gc
+
+class Weak(object):
+    pass
+
+def target(local, weaklist):
+    weak = Weak()
+    local.weak = weak
+    weaklist.append(weakref.ref(weak))
+
+class ThreadingLocalTest(unittest.TestCase):
+
+    def test_local_refs(self):
+        self._local_refs(20)
+        self._local_refs(50)
+        self._local_refs(100)
+
+    def _local_refs(self, n):
+        local = threading.local()
+        weaklist = []
+        for i in range(n):
+            t = threading.Thread(target=target, args=(local, weaklist))
+            t.start()
+            t.join()
+        del t
+
+        gc.collect()
+        self.assertEqual(len(weaklist), n)
+
+        # XXX threading.local keeps the local of the last stopped thread alive.
+        deadlist = [weak for weak in weaklist if weak() is None]
+        self.assertEqual(len(deadlist), n-1)
+
+        # Assignment to the same thread local frees it sometimes (!)
+        local.someothervar = None
+        gc.collect()
+        deadlist = [weak for weak in weaklist if weak() is None]
+        self.assert_(len(deadlist) in (n-1, n), (n, len(deadlist)))
 
 def test_main():
-    suite = DocTestSuite('_threading_local')
+    suite = unittest.TestSuite()
+    suite.addTest(DocTestSuite('_threading_local'))
+    suite.addTest(unittest.makeSuite(ThreadingLocalTest))
 
     try:
         from thread import _local

Modified: python/branches/py3k-importlib/Lib/test/test_timeout.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_timeout.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_timeout.py	Thu Mar 27 00:48:05 2008
@@ -107,16 +107,21 @@
         self.sock.close()
 
     def testConnectTimeout(self):
-        # Test connect() timeout
-        _timeout = 0.001
-        self.sock.settimeout(_timeout)
-
         # If we are too close to www.python.org, this test will fail.
         # Pick a host that should be farther away.
         if (socket.getfqdn().split('.')[-2:] == ['python', 'org'] or
             socket.getfqdn().split('.')[-2:-1] == ['xs4all']):
             self.addr_remote = ('tut.fi', 80)
 
+        # Lookup the IP address to avoid including the DNS lookup time
+        # with the connect time.  This avoids failing the assertion that
+        # the timeout occurred fast enough.
+        self.addr_remote = (socket.gethostbyname(self.addr_remote[0]), 80)
+
+        # Test connect() timeout
+        _timeout = 0.001
+        self.sock.settimeout(_timeout)
+
         _t1 = time.time()
         self.failUnlessRaises(socket.error, self.sock.connect,
                 self.addr_remote)

Modified: python/branches/py3k-importlib/Lib/test/test_tokenize.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_tokenize.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_tokenize.py	Thu Mar 27 00:48:05 2008
@@ -1,143 +1,551 @@
-"""Tests for the tokenize module.
+# -*- coding: utf-8 -*-
 
-The tests were originally written in the old Python style, where the
-test output was compared to a golden file.  This docstring represents
-the first steps towards rewriting the entire test as a doctest.
+doctests = """
+Tests for the tokenize module.
 
-The tests can be really simple.  Given a small fragment of source
-code, print out a table with the tokens.  The ENDMARK is omitted for
+The tests can be really simple. Given a small fragment of source
+code, print out a table with tokens. The ENDMARK is omitted for
 brevity.
 
->>> dump_tokens("1 + 1")
-NUMBER      '1'           (1, 0) (1, 1)
-OP          '+'           (1, 2) (1, 3)
-NUMBER      '1'           (1, 4) (1, 5)
-
-A comment generates a token here, unlike in the parser module.  The
-comment token is followed by an NL or a NEWLINE token, depending on
-whether the line contains the completion of a statement.
-
->>> dump_tokens("if False:\\n"
-...             "    # NL\\n"
-...             "    a    = False # NEWLINE\\n")
-NAME        'if'          (1, 0) (1, 2)
-NAME        'False'       (1, 3) (1, 8)
-OP          ':'           (1, 8) (1, 9)
-NEWLINE     '\\n'          (1, 9) (1, 10)
-COMMENT     '# NL'        (2, 4) (2, 8)
-NL          '\\n'          (2, 8) (2, 9)
-INDENT      '    '        (3, 0) (3, 4)
-NAME        'a'           (3, 4) (3, 5)
-OP          '='           (3, 9) (3, 10)
-NAME        'False'       (3, 11) (3, 16)
-COMMENT     '# NEWLINE'   (3, 17) (3, 26)
-NEWLINE     '\\n'          (3, 26) (3, 27)
-DEDENT      ''            (4, 0) (4, 0)
-
-' # Emacs hint
-
-There will be a bunch more tests of specific source patterns.
-
-The tokenize module also defines an untokenize function that should
-regenerate the original program text from the tokens.
-
-There are some standard formatting practices that are easy to get right.
-
->>> roundtrip("if x == 1:\\n"
-...           "    print(x)\\n")
-if x == 1:
-    print(x)
+    >>> dump_tokens("1 + 1")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NUMBER     '1'           (1, 0) (1, 1)
+    OP         '+'           (1, 2) (1, 3)
+    NUMBER     '1'           (1, 4) (1, 5)
+
+    >>> dump_tokens("if False:\\n"
+    ...             "    # NL\\n"
+    ...             "    True = False # NEWLINE\\n")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'if'          (1, 0) (1, 2)
+    NAME       'False'       (1, 3) (1, 8)
+    OP         ':'           (1, 8) (1, 9)
+    NEWLINE    '\\n'          (1, 9) (1, 10)
+    COMMENT    '# NL'        (2, 4) (2, 8)
+    NL         '\\n'          (2, 8) (2, 9)
+    INDENT     '    '        (3, 0) (3, 4)
+    NAME       'True'        (3, 4) (3, 8)
+    OP         '='           (3, 9) (3, 10)
+    NAME       'False'       (3, 11) (3, 16)
+    COMMENT    '# NEWLINE'   (3, 17) (3, 26)
+    NEWLINE    '\\n'          (3, 26) (3, 27)
+    DEDENT     ''            (4, 0) (4, 0)
+
+    >>> indent_error_file = \"""
+    ... def k(x):
+    ...     x += 2
+    ...   x += 5
+    ... \"""
+    >>> readline = BytesIO(indent_error_file.encode('utf-8')).readline
+    >>> for tok in tokenize(readline): pass
+    Traceback (most recent call last):
+        ...
+    IndentationError: unindent does not match any outer indentation level
+
+There are some standard formattig practises that are easy to get right.
+
+    >>> roundtrip("if x == 1:\\n"
+    ...           "    print(x)\\n")
+    True
+
+    >>> roundtrip("# This is a comment\\n# This also")
+    True
 
 Some people use different formatting conventions, which makes
-untokenize a little trickier.  Note that this test involves trailing
-whitespace after the colon.  Note that we use hex escapes to make the
+untokenize a little trickier. Note that this test involves trailing
+whitespace after the colon. Note that we use hex escapes to make the
 two trailing blanks apparent in the expected output.
 
->>> roundtrip("if   x  ==  1  :  \\n"
-...           "  print(x)\\n")
-if   x  ==  1  :\x20\x20
-  print(x)
-
-Comments need to go in the right place.
-
->>> roundtrip("if x == 1:\\n"
-...           "    # A comment by itself.\\n"
-...           "    print(x)  # Comment here, too.\\n"
-...           "    # Another comment.\\n"
-...           "after_if = True\\n")
-if x == 1:
-    # A comment by itself.
-    print(x)  # Comment here, too.
-    # Another comment.
-after_if = True
-
->>> roundtrip("if (x  # The comments need to go in the right place\\n"
-...           "    == 1):\\n"
-...           "    print('x == 1')\\n")
-if (x  # The comments need to go in the right place
-    == 1):
-    print('x == 1')
-
+    >>> roundtrip("if x == 1 : \\n"
+    ...           "  print(x)\\n")
+    True
+
+    >>> f = test_support.findfile("tokenize_tests.txt")
+    >>> roundtrip(open(f, 'rb'))
+    True
+
+    >>> roundtrip("if x == 1:\\n"
+    ...           "    # A comment by itself.\\n"
+    ...           "    print(x) # Comment here, too.\\n"
+    ...           "    # Another comment.\\n"
+    ...           "after_if = True\\n")
+    True
+
+    >>> roundtrip("if (x # The comments need to go in the right place\\n"
+    ...           "    == 1):\\n"
+    ...           "    print('x==1')\\n")
+    True
+
+    >>> roundtrip("class Test: # A comment here\\n"
+    ...           "  # A comment with weird indent\\n"
+    ...           "  after_com = 5\\n"
+    ...           "  def x(m): return m*5 # a one liner\\n"
+    ...           "  def y(m): # A whitespace after the colon\\n"
+    ...           "     return y*4 # 3-space indent\\n")
+    True
+
+Some error-handling code
+
+    >>> roundtrip("try: import somemodule\\n"
+    ...           "except ImportError: # comment\\n"
+    ...           "    print 'Can not import' # comment2\\n"
+    ...           "else:   print 'Loaded'\\n")
+    True
+
+Balancing continuation
+
+    >>> roundtrip("a = (3,4, \\n"
+    ...           "5,6)\\n"
+    ...           "y = [3, 4,\\n"
+    ...           "5]\\n"
+    ...           "z = {'a': 5,\\n"
+    ...           "'b':15, 'c':True}\\n"
+    ...           "x = len(y) + 5 - a[\\n"
+    ...           "3] - a[2]\\n"
+    ...           "+ len(z) - z[\\n"
+    ...           "'b']\\n")
+    True
+
+Ordinary integers and binary operators
+
+    >>> dump_tokens("0xff <= 255")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NUMBER     '0xff'        (1, 0) (1, 4)
+    OP         '<='          (1, 5) (1, 7)
+    NUMBER     '255'         (1, 8) (1, 11)
+    >>> dump_tokens("0b10 <= 255")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NUMBER     '0b10'        (1, 0) (1, 4)
+    OP         '<='          (1, 5) (1, 7)
+    NUMBER     '255'         (1, 8) (1, 11)
+    >>> dump_tokens("0o123 <= 0O123")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NUMBER     '0o123'       (1, 0) (1, 5)
+    OP         '<='          (1, 6) (1, 8)
+    NUMBER     '0O123'       (1, 9) (1, 14)
+    >>> dump_tokens("1234567 > ~0x15")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NUMBER     '1234567'     (1, 0) (1, 7)
+    OP         '>'           (1, 8) (1, 9)
+    OP         '~'           (1, 10) (1, 11)
+    NUMBER     '0x15'        (1, 11) (1, 15)
+    >>> dump_tokens("2134568 != 1231515")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NUMBER     '2134568'     (1, 0) (1, 7)
+    OP         '!='          (1, 8) (1, 10)
+    NUMBER     '1231515'     (1, 11) (1, 18)
+    >>> dump_tokens("(-124561-1) & 200000000")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    OP         '('           (1, 0) (1, 1)
+    OP         '-'           (1, 1) (1, 2)
+    NUMBER     '124561'      (1, 2) (1, 8)
+    OP         '-'           (1, 8) (1, 9)
+    NUMBER     '1'           (1, 9) (1, 10)
+    OP         ')'           (1, 10) (1, 11)
+    OP         '&'           (1, 12) (1, 13)
+    NUMBER     '200000000'   (1, 14) (1, 23)
+    >>> dump_tokens("0xdeadbeef != -1")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NUMBER     '0xdeadbeef'  (1, 0) (1, 10)
+    OP         '!='          (1, 11) (1, 13)
+    OP         '-'           (1, 14) (1, 15)
+    NUMBER     '1'           (1, 15) (1, 16)
+    >>> dump_tokens("0xdeadc0de & 12345")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NUMBER     '0xdeadc0de'  (1, 0) (1, 10)
+    OP         '&'           (1, 11) (1, 12)
+    NUMBER     '12345'       (1, 13) (1, 18)
+    >>> dump_tokens("0xFF & 0x15 | 1234")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NUMBER     '0xFF'        (1, 0) (1, 4)
+    OP         '&'           (1, 5) (1, 6)
+    NUMBER     '0x15'        (1, 7) (1, 11)
+    OP         '|'           (1, 12) (1, 13)
+    NUMBER     '1234'        (1, 14) (1, 18)
+
+Long integers
+
+    >>> dump_tokens("x = 0")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    NUMBER     '0'           (1, 4) (1, 5)
+    >>> dump_tokens("x = 0xfffffffffff")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    NUMBER     '0xffffffffff (1, 4) (1, 17)
+    >>> dump_tokens("x = 123141242151251616110")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    NUMBER     '123141242151 (1, 4) (1, 25)
+    >>> dump_tokens("x = -15921590215012591")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    OP         '-'           (1, 4) (1, 5)
+    NUMBER     '159215902150 (1, 5) (1, 22)
+
+Floating point numbers
+
+    >>> dump_tokens("x = 3.14159")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    NUMBER     '3.14159'     (1, 4) (1, 11)
+    >>> dump_tokens("x = 314159.")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    NUMBER     '314159.'     (1, 4) (1, 11)
+    >>> dump_tokens("x = .314159")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    NUMBER     '.314159'     (1, 4) (1, 11)
+    >>> dump_tokens("x = 3e14159")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    NUMBER     '3e14159'     (1, 4) (1, 11)
+    >>> dump_tokens("x = 3E123")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    NUMBER     '3E123'       (1, 4) (1, 9)
+    >>> dump_tokens("x+y = 3e-1230")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '+'           (1, 1) (1, 2)
+    NAME       'y'           (1, 2) (1, 3)
+    OP         '='           (1, 4) (1, 5)
+    NUMBER     '3e-1230'     (1, 6) (1, 13)
+    >>> dump_tokens("x = 3.14e159")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    NUMBER     '3.14e159'    (1, 4) (1, 12)
+
+String literals
+
+    >>> dump_tokens("x = ''; y = \\\"\\\"")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    STRING     "''"          (1, 4) (1, 6)
+    OP         ';'           (1, 6) (1, 7)
+    NAME       'y'           (1, 8) (1, 9)
+    OP         '='           (1, 10) (1, 11)
+    STRING     '""'          (1, 12) (1, 14)
+    >>> dump_tokens("x = '\\\"'; y = \\\"'\\\"")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    STRING     '\\'"\\''       (1, 4) (1, 7)
+    OP         ';'           (1, 7) (1, 8)
+    NAME       'y'           (1, 9) (1, 10)
+    OP         '='           (1, 11) (1, 12)
+    STRING     '"\\'"'        (1, 13) (1, 16)
+    >>> dump_tokens("x = \\\"doesn't \\\"shrink\\\", does it\\\"")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    STRING     '"doesn\\'t "' (1, 4) (1, 14)
+    NAME       'shrink'      (1, 14) (1, 20)
+    STRING     '", does it"' (1, 20) (1, 31)
+    >>> dump_tokens("x = 'abc' + 'ABC'")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    STRING     "'abc'"       (1, 4) (1, 9)
+    OP         '+'           (1, 10) (1, 11)
+    STRING     "'ABC'"       (1, 12) (1, 17)
+    >>> dump_tokens('y = "ABC" + "ABC"')
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'y'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    STRING     '"ABC"'       (1, 4) (1, 9)
+    OP         '+'           (1, 10) (1, 11)
+    STRING     '"ABC"'       (1, 12) (1, 17)
+    >>> dump_tokens("x = r'abc' + r'ABC' + R'ABC' + R'ABC'")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    STRING     "r'abc'"      (1, 4) (1, 10)
+    OP         '+'           (1, 11) (1, 12)
+    STRING     "r'ABC'"      (1, 13) (1, 19)
+    OP         '+'           (1, 20) (1, 21)
+    STRING     "R'ABC'"      (1, 22) (1, 28)
+    OP         '+'           (1, 29) (1, 30)
+    STRING     "R'ABC'"      (1, 31) (1, 37)
+    >>> dump_tokens('y = r"abc" + r"ABC" + R"ABC" + R"ABC"')
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'y'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    STRING     'r"abc"'      (1, 4) (1, 10)
+    OP         '+'           (1, 11) (1, 12)
+    STRING     'r"ABC"'      (1, 13) (1, 19)
+    OP         '+'           (1, 20) (1, 21)
+    STRING     'R"ABC"'      (1, 22) (1, 28)
+    OP         '+'           (1, 29) (1, 30)
+    STRING     'R"ABC"'      (1, 31) (1, 37)
+
+Operators
+
+    >>> dump_tokens("def d22(a, b, c=2, d=2, *k): pass")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'def'         (1, 0) (1, 3)
+    NAME       'd22'         (1, 4) (1, 7)
+    OP         '('           (1, 7) (1, 8)
+    NAME       'a'           (1, 8) (1, 9)
+    OP         ','           (1, 9) (1, 10)
+    NAME       'b'           (1, 11) (1, 12)
+    OP         ','           (1, 12) (1, 13)
+    NAME       'c'           (1, 14) (1, 15)
+    OP         '='           (1, 15) (1, 16)
+    NUMBER     '2'           (1, 16) (1, 17)
+    OP         ','           (1, 17) (1, 18)
+    NAME       'd'           (1, 19) (1, 20)
+    OP         '='           (1, 20) (1, 21)
+    NUMBER     '2'           (1, 21) (1, 22)
+    OP         ','           (1, 22) (1, 23)
+    OP         '*'           (1, 24) (1, 25)
+    NAME       'k'           (1, 25) (1, 26)
+    OP         ')'           (1, 26) (1, 27)
+    OP         ':'           (1, 27) (1, 28)
+    NAME       'pass'        (1, 29) (1, 33)
+    >>> dump_tokens("def d01v_(a=1, *k, **w): pass")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'def'         (1, 0) (1, 3)
+    NAME       'd01v_'       (1, 4) (1, 9)
+    OP         '('           (1, 9) (1, 10)
+    NAME       'a'           (1, 10) (1, 11)
+    OP         '='           (1, 11) (1, 12)
+    NUMBER     '1'           (1, 12) (1, 13)
+    OP         ','           (1, 13) (1, 14)
+    OP         '*'           (1, 15) (1, 16)
+    NAME       'k'           (1, 16) (1, 17)
+    OP         ','           (1, 17) (1, 18)
+    OP         '**'          (1, 19) (1, 21)
+    NAME       'w'           (1, 21) (1, 22)
+    OP         ')'           (1, 22) (1, 23)
+    OP         ':'           (1, 23) (1, 24)
+    NAME       'pass'        (1, 25) (1, 29)
+
+Comparison
+
+    >>> dump_tokens("if 1 < 1 > 1 == 1 >= 5 <= 0x15 <= 0x12 != " +
+    ...             "1 and 5 in 1 not in 1 is 1 or 5 is not 1: pass")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'if'          (1, 0) (1, 2)
+    NUMBER     '1'           (1, 3) (1, 4)
+    OP         '<'           (1, 5) (1, 6)
+    NUMBER     '1'           (1, 7) (1, 8)
+    OP         '>'           (1, 9) (1, 10)
+    NUMBER     '1'           (1, 11) (1, 12)
+    OP         '=='          (1, 13) (1, 15)
+    NUMBER     '1'           (1, 16) (1, 17)
+    OP         '>='          (1, 18) (1, 20)
+    NUMBER     '5'           (1, 21) (1, 22)
+    OP         '<='          (1, 23) (1, 25)
+    NUMBER     '0x15'        (1, 26) (1, 30)
+    OP         '<='          (1, 31) (1, 33)
+    NUMBER     '0x12'        (1, 34) (1, 38)
+    OP         '!='          (1, 39) (1, 41)
+    NUMBER     '1'           (1, 42) (1, 43)
+    NAME       'and'         (1, 44) (1, 47)
+    NUMBER     '5'           (1, 48) (1, 49)
+    NAME       'in'          (1, 50) (1, 52)
+    NUMBER     '1'           (1, 53) (1, 54)
+    NAME       'not'         (1, 55) (1, 58)
+    NAME       'in'          (1, 59) (1, 61)
+    NUMBER     '1'           (1, 62) (1, 63)
+    NAME       'is'          (1, 64) (1, 66)
+    NUMBER     '1'           (1, 67) (1, 68)
+    NAME       'or'          (1, 69) (1, 71)
+    NUMBER     '5'           (1, 72) (1, 73)
+    NAME       'is'          (1, 74) (1, 76)
+    NAME       'not'         (1, 77) (1, 80)
+    NUMBER     '1'           (1, 81) (1, 82)
+    OP         ':'           (1, 82) (1, 83)
+    NAME       'pass'        (1, 84) (1, 88)
+
+Shift
+
+    >>> dump_tokens("x = 1 << 1 >> 5")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    NUMBER     '1'           (1, 4) (1, 5)
+    OP         '<<'          (1, 6) (1, 8)
+    NUMBER     '1'           (1, 9) (1, 10)
+    OP         '>>'          (1, 11) (1, 13)
+    NUMBER     '5'           (1, 14) (1, 15)
+
+Additive
+
+    >>> dump_tokens("x = 1 - y + 15 - 1 + 0x124 + z + a[5]")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    NUMBER     '1'           (1, 4) (1, 5)
+    OP         '-'           (1, 6) (1, 7)
+    NAME       'y'           (1, 8) (1, 9)
+    OP         '+'           (1, 10) (1, 11)
+    NUMBER     '15'          (1, 12) (1, 14)
+    OP         '-'           (1, 15) (1, 16)
+    NUMBER     '1'           (1, 17) (1, 18)
+    OP         '+'           (1, 19) (1, 20)
+    NUMBER     '0x124'       (1, 21) (1, 26)
+    OP         '+'           (1, 27) (1, 28)
+    NAME       'z'           (1, 29) (1, 30)
+    OP         '+'           (1, 31) (1, 32)
+    NAME       'a'           (1, 33) (1, 34)
+    OP         '['           (1, 34) (1, 35)
+    NUMBER     '5'           (1, 35) (1, 36)
+    OP         ']'           (1, 36) (1, 37)
+
+Multiplicative
+
+    >>> dump_tokens("x = 1//1*1/5*12%0x12")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'x'           (1, 0) (1, 1)
+    OP         '='           (1, 2) (1, 3)
+    NUMBER     '1'           (1, 4) (1, 5)
+    OP         '//'          (1, 5) (1, 7)
+    NUMBER     '1'           (1, 7) (1, 8)
+    OP         '*'           (1, 8) (1, 9)
+    NUMBER     '1'           (1, 9) (1, 10)
+    OP         '/'           (1, 10) (1, 11)
+    NUMBER     '5'           (1, 11) (1, 12)
+    OP         '*'           (1, 12) (1, 13)
+    NUMBER     '12'          (1, 13) (1, 15)
+    OP         '%'           (1, 15) (1, 16)
+    NUMBER     '0x12'        (1, 16) (1, 20)
+
+Unary
+
+    >>> dump_tokens("~1 ^ 1 & 1 |1 ^ -1")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    OP         '~'           (1, 0) (1, 1)
+    NUMBER     '1'           (1, 1) (1, 2)
+    OP         '^'           (1, 3) (1, 4)
+    NUMBER     '1'           (1, 5) (1, 6)
+    OP         '&'           (1, 7) (1, 8)
+    NUMBER     '1'           (1, 9) (1, 10)
+    OP         '|'           (1, 11) (1, 12)
+    NUMBER     '1'           (1, 12) (1, 13)
+    OP         '^'           (1, 14) (1, 15)
+    OP         '-'           (1, 16) (1, 17)
+    NUMBER     '1'           (1, 17) (1, 18)
+    >>> dump_tokens("-1*1/1+1*1//1 - ---1**1")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    OP         '-'           (1, 0) (1, 1)
+    NUMBER     '1'           (1, 1) (1, 2)
+    OP         '*'           (1, 2) (1, 3)
+    NUMBER     '1'           (1, 3) (1, 4)
+    OP         '/'           (1, 4) (1, 5)
+    NUMBER     '1'           (1, 5) (1, 6)
+    OP         '+'           (1, 6) (1, 7)
+    NUMBER     '1'           (1, 7) (1, 8)
+    OP         '*'           (1, 8) (1, 9)
+    NUMBER     '1'           (1, 9) (1, 10)
+    OP         '//'          (1, 10) (1, 12)
+    NUMBER     '1'           (1, 12) (1, 13)
+    OP         '-'           (1, 14) (1, 15)
+    OP         '-'           (1, 16) (1, 17)
+    OP         '-'           (1, 17) (1, 18)
+    OP         '-'           (1, 18) (1, 19)
+    NUMBER     '1'           (1, 19) (1, 20)
+    OP         '**'          (1, 20) (1, 22)
+    NUMBER     '1'           (1, 22) (1, 23)
+
+Selector
+
+    >>> dump_tokens("import sys, time\\nx = sys.modules['time'].time()")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    NAME       'import'      (1, 0) (1, 6)
+    NAME       'sys'         (1, 7) (1, 10)
+    OP         ','           (1, 10) (1, 11)
+    NAME       'time'        (1, 12) (1, 16)
+    NEWLINE    '\\n'          (1, 16) (1, 17)
+    NAME       'x'           (2, 0) (2, 1)
+    OP         '='           (2, 2) (2, 3)
+    NAME       'sys'         (2, 4) (2, 7)
+    OP         '.'           (2, 7) (2, 8)
+    NAME       'modules'     (2, 8) (2, 15)
+    OP         '['           (2, 15) (2, 16)
+    STRING     "'time'"      (2, 16) (2, 22)
+    OP         ']'           (2, 22) (2, 23)
+    OP         '.'           (2, 23) (2, 24)
+    NAME       'time'        (2, 24) (2, 28)
+    OP         '('           (2, 28) (2, 29)
+    OP         ')'           (2, 29) (2, 30)
+
+Methods
+
+    >>> dump_tokens("@staticmethod\\ndef foo(x,y): pass")
+    ENCODING   'utf-8'       (0, 0) (0, 0)
+    OP         '@'           (1, 0) (1, 1)
+    NAME       'staticmethod (1, 1) (1, 13)
+    NEWLINE    '\\n'          (1, 13) (1, 14)
+    NAME       'def'         (2, 0) (2, 3)
+    NAME       'foo'         (2, 4) (2, 7)
+    OP         '('           (2, 7) (2, 8)
+    NAME       'x'           (2, 8) (2, 9)
+    OP         ','           (2, 9) (2, 10)
+    NAME       'y'           (2, 10) (2, 11)
+    OP         ')'           (2, 11) (2, 12)
+    OP         ':'           (2, 12) (2, 13)
+    NAME       'pass'        (2, 14) (2, 18)
+
+Backslash means line continuation, except for comments
+
+    >>> roundtrip("x=1+\\\\n"
+    ...           "1\\n"
+    ...           "# This is a comment\\\\n"
+    ...           "# This also\\n")
+    True
+    >>> roundtrip("# Comment \\\\nx = 0")
+    True
 """
 
-# ' Emacs hint
-
-import os, glob, random, time, sys
-import re
-from io import StringIO
-from test.test_support import (verbose, findfile, is_resource_enabled,
-                               TestFailed)
-from tokenize import (tokenize, generate_tokens, untokenize, tok_name,
-                      ENDMARKER, NUMBER, NAME, OP, STRING, COMMENT)
-
-# How much time in seconds can pass before we print a 'Still working' message.
-_PRINT_WORKING_MSG_INTERVAL = 5 * 60
-
-# Test roundtrip for `untokenize`.  `f` is a file path.  The source code in f
-# is tokenized, converted back to source code via tokenize.untokenize(),
-# and tokenized again from the latter.  The test fails if the second
-# tokenization doesn't match the first.
-def test_roundtrip(f):
-    ## print('Testing:', f)
-    # Get the encoding first
-    fobj = open(f, encoding="latin-1")
-    first2lines = fobj.readline() + fobj.readline()
-    fobj.close()
-    m = re.search(r"coding:\s*(\S+)", first2lines)
-    if m:
-        encoding = m.group(1)
-        ## print("    coding:", encoding)
-    else:
-        encoding = "utf-8"
-    fobj = open(f, encoding=encoding)
-    try:
-        fulltok = list(generate_tokens(fobj.readline))
-    finally:
-        fobj.close()
-
-    t1 = [tok[:2] for tok in fulltok]
-    newtext = untokenize(t1)
-    readline = iter(newtext.splitlines(1)).__next__
-    t2 = [tok[:2] for tok in generate_tokens(readline)]
-    if t1 != t2:
-        raise TestFailed("untokenize() roundtrip failed for %r" % f)
+from test import test_support
+from tokenize import (tokenize, _tokenize, untokenize, NUMBER, NAME, OP,
+                     STRING, ENDMARKER, tok_name, detect_encoding)
+from io import BytesIO
+from unittest import TestCase
+import os, sys, glob
 
 def dump_tokens(s):
     """Print out the tokens in s in a table format.
 
     The ENDMARKER is omitted.
     """
-    f = StringIO(s)
-    for type, token, start, end, line in generate_tokens(f.readline):
+    f = BytesIO(s.encode('utf-8'))
+    for type, token, start, end, line in tokenize(f.readline):
         if type == ENDMARKER:
             break
         type = tok_name[type]
-        print("%(type)-10.10s  %(token)-13.13r %(start)s %(end)s" % locals())
+        print("%(type)-10.10s %(token)-13.13r %(start)s %(end)s" % locals())
 
-def roundtrip(s):
-    f = StringIO(s)
-    source = untokenize(generate_tokens(f.readline))
-    print(source, end="")
+def roundtrip(f):
+    """
+    Test roundtrip for `untokenize`. `f` is an open file or a string.
+    The source code in f is tokenized, converted back to source code via
+    tokenize.untokenize(), and tokenized again from the latter. The test
+    fails if the second tokenization doesn't match the first.
+    """
+    if isinstance(f, str):
+        f = BytesIO(f.encode('utf-8'))
+    token_list = list(tokenize(f.readline))
+    f.close()
+    tokens1 = [tok[:2] for tok in token_list]
+    new_bytes = untokenize(tokens1)
+    readline = (line for line in new_bytes.splitlines(1)).__next__
+    tokens2 = [tok[:2] for tok in tokenize(readline)]
+    return tokens1 == tokens2
 
 # This is an example from the docs, set up as a doctest.
 def decistmt(s):
@@ -162,9 +570,8 @@
     >>> exec(decistmt(s))
     -3.217160342717258261933904529E-7
     """
-
     result = []
-    g = generate_tokens(StringIO(s).readline)   # tokenize the string
+    g = tokenize(BytesIO(s.encode('utf-8')).readline)   # tokenize the string
     for toknum, tokval, _, _, _  in g:
         if toknum == NUMBER and '.' in tokval:  # replace NUMBER tokens
             result.extend([
@@ -175,75 +582,249 @@
             ])
         else:
             result.append((toknum, tokval))
-    return untokenize(result)
+    return untokenize(result).decode('utf-8')
 
-def test_main():
-    if verbose:
-        print('starting...')
 
-    next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
+class TestTokenizerAdheresToPep0263(TestCase):
+    """
+    Test that tokenizer adheres to the coding behaviour stipulated in PEP 0263.
+    """
 
-    # This displays the tokenization of tokenize_tests.py to stdout, and
-    # regrtest.py checks that this equals the expected output (in the
-    # test/output/ directory).
-    f = open(findfile('tokenize_tests.txt'))
-    tokenize(f.readline)
-    f.close()
+    def _testFile(self, filename):
+        path = os.path.join(os.path.dirname(__file__), filename)
+        return roundtrip(open(path, 'rb'))
+
+    def test_utf8_coding_cookie_and_no_utf8_bom(self):
+        f = 'tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt'
+        self.assertTrue(self._testFile(f))
+
+    def test_latin1_coding_cookie_and_utf8_bom(self):
+        """
+        As per PEP 0263, if a file starts with a utf-8 BOM signature, the only
+        allowed encoding for the comment is 'utf-8'.  The text file used in
+        this test starts with a BOM signature, but specifies latin1 as the
+        coding, so verify that a SyntaxError is raised, which matches the
+        behaviour of the interpreter when it encounters a similar condition.
+        """
+        f = 'tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt'
+        self.failUnlessRaises(SyntaxError, self._testFile, f)
+
+    def test_no_coding_cookie_and_utf8_bom(self):
+        f = 'tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt'
+        self.assertTrue(self._testFile(f))
+
+    def test_utf8_coding_cookie_and_utf8_bom(self):
+        f = 'tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt'
+        self.assertTrue(self._testFile(f))
+
+
+class Test_Tokenize(TestCase):
+
+    def test__tokenize_decodes_with_specified_encoding(self):
+        literal = '"ЉЊЈЁЂ"'
+        line = literal.encode('utf-8')
+        first = False
+        def readline():
+            nonlocal first
+            if not first:
+                first = True
+                return line
+            else:
+                return b''
+
+        # skip the initial encoding token and the end token
+        tokens = list(_tokenize(readline, encoding='utf-8'))[1:-1]
+        expected_tokens = [(3, '"ЉЊЈЁЂ"', (1, 0), (1, 7), '"ЉЊЈЁЂ"')]
+        self.assertEquals(tokens, expected_tokens,
+                          "bytes not decoded with encoding")
+
+    def test__tokenize_does_not_decode_with_encoding_none(self):
+        literal = '"ЉЊЈЁЂ"'
+        first = False
+        def readline():
+            nonlocal first
+            if not first:
+                first = True
+                return literal
+            else:
+                return b''
+
+        # skip the end token
+        tokens = list(_tokenize(readline, encoding=None))[:-1]
+        expected_tokens = [(3, '"ЉЊЈЁЂ"', (1, 0), (1, 7), '"ЉЊЈЁЂ"')]
+        self.assertEquals(tokens, expected_tokens,
+                          "string not tokenized when encoding is None")
+
+
+class TestDetectEncoding(TestCase):
+
+    def get_readline(self, lines):
+        index = 0
+        def readline():
+            nonlocal index
+            if index == len(lines):
+                raise StopIteration
+            line = lines[index]
+            index += 1
+            return line
+        return readline
+
+    def test_no_bom_no_encoding_cookie(self):
+        lines = (
+            b'# something\n',
+            b'print(something)\n',
+            b'do_something(else)\n'
+        )
+        encoding, consumed_lines = detect_encoding(self.get_readline(lines))
+        self.assertEquals(encoding, 'utf-8')
+        self.assertEquals(consumed_lines, list(lines[:2]))
+
+    def test_bom_no_cookie(self):
+        lines = (
+            b'\xef\xbb\xbf# something\n',
+            b'print(something)\n',
+            b'do_something(else)\n'
+        )
+        encoding, consumed_lines = detect_encoding(self.get_readline(lines))
+        self.assertEquals(encoding, 'utf-8')
+        self.assertEquals(consumed_lines,
+                          [b'# something\n', b'print(something)\n'])
+
+    def test_cookie_first_line_no_bom(self):
+        lines = (
+            b'# -*- coding: latin-1 -*-\n',
+            b'print(something)\n',
+            b'do_something(else)\n'
+        )
+        encoding, consumed_lines = detect_encoding(self.get_readline(lines))
+        self.assertEquals(encoding, 'latin-1')
+        self.assertEquals(consumed_lines, [b'# -*- coding: latin-1 -*-\n'])
+
+    def test_matched_bom_and_cookie_first_line(self):
+        lines = (
+            b'\xef\xbb\xbf# coding=utf-8\n',
+            b'print(something)\n',
+            b'do_something(else)\n'
+        )
+        encoding, consumed_lines = detect_encoding(self.get_readline(lines))
+        self.assertEquals(encoding, 'utf-8')
+        self.assertEquals(consumed_lines, [b'# coding=utf-8\n'])
+
+    def test_mismatched_bom_and_cookie_first_line_raises_syntaxerror(self):
+        lines = (
+            b'\xef\xbb\xbf# vim: set fileencoding=ascii :\n',
+            b'print(something)\n',
+            b'do_something(else)\n'
+        )
+        readline = self.get_readline(lines)
+        self.assertRaises(SyntaxError, detect_encoding, readline)
+
+    def test_cookie_second_line_no_bom(self):
+        lines = (
+            b'#! something\n',
+            b'# vim: set fileencoding=ascii :\n',
+            b'print(something)\n',
+            b'do_something(else)\n'
+        )
+        encoding, consumed_lines = detect_encoding(self.get_readline(lines))
+        self.assertEquals(encoding, 'ascii')
+        expected = [b'#! something\n', b'# vim: set fileencoding=ascii :\n']
+        self.assertEquals(consumed_lines, expected)
+
+    def test_matched_bom_and_cookie_second_line(self):
+        lines = (
+            b'\xef\xbb\xbf#! something\n',
+            b'f# coding=utf-8\n',
+            b'print(something)\n',
+            b'do_something(else)\n'
+        )
+        encoding, consumed_lines = detect_encoding(self.get_readline(lines))
+        self.assertEquals(encoding, 'utf-8')
+        self.assertEquals(consumed_lines,
+                          [b'#! something\n', b'f# coding=utf-8\n'])
+
+    def test_mismatched_bom_and_cookie_second_line_raises_syntaxerror(self):
+        lines = (
+            b'\xef\xbb\xbf#! something\n',
+            b'# vim: set fileencoding=ascii :\n',
+            b'print(something)\n',
+            b'do_something(else)\n'
+        )
+        readline = self.get_readline(lines)
+        self.assertRaises(SyntaxError, detect_encoding, readline)
+
+    def test_short_files(self):
+        readline = self.get_readline((b'print(something)\n',))
+        encoding, consumed_lines = detect_encoding(readline)
+        self.assertEquals(encoding, 'utf-8')
+        self.assertEquals(consumed_lines, [b'print(something)\n'])
+
+        encoding, consumed_lines = detect_encoding(self.get_readline(()))
+        self.assertEquals(encoding, 'utf-8')
+        self.assertEquals(consumed_lines, [])
+
+        readline = self.get_readline((b'\xef\xbb\xbfprint(something)\n',))
+        encoding, consumed_lines = detect_encoding(readline)
+        self.assertEquals(encoding, 'utf-8')
+        self.assertEquals(consumed_lines, [b'print(something)\n'])
+
+        readline = self.get_readline((b'\xef\xbb\xbf',))
+        encoding, consumed_lines = detect_encoding(readline)
+        self.assertEquals(encoding, 'utf-8')
+        self.assertEquals(consumed_lines, [])
+
+
+class TestTokenize(TestCase):
+
+    def test_tokenize(self):
+        import tokenize as tokenize_module
+        encoding = object()
+        encoding_used = None
+        def mock_detect_encoding(readline):
+            return encoding, ['first', 'second']
+
+        def mock__tokenize(readline, encoding):
+            nonlocal encoding_used
+            encoding_used = encoding
+            out = []
+            while True:
+                next_line = readline()
+                if next_line:
+                    out.append(next_line)
+                    continue
+                return out
+
+        counter = 0
+        def mock_readline():
+            nonlocal counter
+            counter += 1
+            if counter == 5:
+                return b''
+            return counter
+
+        orig_detect_encoding = tokenize_module.detect_encoding
+        orig__tokenize = tokenize_module._tokenize
+        tokenize_module.detect_encoding = mock_detect_encoding
+        tokenize_module._tokenize = mock__tokenize
+        try:
+            results = tokenize(mock_readline)
+            self.assertEquals(list(results), ['first', 'second', 1, 2, 3, 4])
+        finally:
+            tokenize_module.detect_encoding = orig_detect_encoding
+            tokenize_module._tokenize = orig__tokenize
 
-    # Now run test_roundtrip() over tokenize_test.py too, and over all
-    # (if the "compiler" resource is enabled) or a small random sample (if
-    # "compiler" is not enabled) of the test*.py files.
-    f = findfile('tokenize_tests.txt')
-    test_roundtrip(f)
-
-    testdir = os.path.dirname(f) or os.curdir
-    testfiles = glob.glob(testdir + os.sep + 'test*.py')
-    if not is_resource_enabled('compiler'):
-        testfiles = random.sample(testfiles, 10)
-
-    for f in testfiles:
-        # Print still working message since this test can be really slow
-        if verbose:
-            print('    round trip: ', f, file=sys.__stdout__)
-        if next_time <= time.time():
-            next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
-            print('  test_main still working, be patient...', file=sys.__stdout__)
-            sys.__stdout__.flush()
-
-        test_roundtrip(f)
-
-    # Test detecton of IndentationError.
-    sampleBadText = """\
-def foo():
-    bar
-  baz
-"""
+        self.assertTrue(encoding_used, encoding)
 
-    try:
-        for tok in generate_tokens(StringIO(sampleBadText).readline):
-            pass
-    except IndentationError:
-        pass
-    else:
-        raise TestFailed("Did not detect IndentationError:")
-
-    # Run the doctests in this module.
-    from test import test_tokenize  # i.e., this module
-    from test.test_support import run_doctest
-    run_doctest(test_tokenize, verbose)
-
-    if verbose:
-        print('finished')
-
-def test_rarrow():
-    """
-    This function exists solely to test the tokenization of the RARROW
-    operator.
-
-    >>> tokenize(iter(['->']).__next__)   #doctest: +NORMALIZE_WHITESPACE
-    1,0-1,2:\tOP\t'->'
-    2,0-2,0:\tENDMARKER\t''
-    """
+
+__test__ = {"doctests" : doctests, 'decistmt': decistmt}
+
+def test_main():
+    from test import test_tokenize
+    test_support.run_doctest(test_tokenize, True)
+    test_support.run_unittest(TestTokenizerAdheresToPep0263)
+    test_support.run_unittest(Test_Tokenize)
+    test_support.run_unittest(TestDetectEncoding)
+    test_support.run_unittest(TestTokenize)
 
 if __name__ == "__main__":
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_trace.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_trace.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_trace.py	Thu Mar 27 00:48:05 2008
@@ -204,12 +204,44 @@
                             (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):
     def compare_events(self, line_offset, events, expected_events):
@@ -217,17 +249,19 @@
         if events != expected_events:
             self.fail(
                 "events did not match expectation:\n" +
-                "\n".join(difflib.ndiff(map(str, expected_events),
-                                        map(str, events))))
+                "\n".join(difflib.ndiff([str(x) for x in expected_events],
+                                        [str(x) for x in events])))
 
-
-    def run_test(self, func):
+    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, func.events)
+                            tracer.events, events)
+
+    def run_test(self, func):
+        self.run_and_compare(func, func.events)
 
     def run_test2(self, func):
         tracer = Tracer()
@@ -236,6 +270,20 @@
         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):
@@ -262,6 +310,72 @@
     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

Modified: python/branches/py3k-importlib/Lib/test/test_traceback.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_traceback.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_traceback.py	Thu Mar 27 00:48:05 2008
@@ -65,7 +65,7 @@
         err = traceback.format_exception_only(X, X())
         self.assertEqual(len(err), 1)
         str_value = '<unprintable %s object>' % X.__name__
-        if X.__module__ in ('__main__', '__builtin__'):
+        if X.__module__ in ('__main__', 'builtins'):
             str_name = X.__name__
         else:
             str_name = '.'.join([X.__module__, X.__name__])

Modified: python/branches/py3k-importlib/Lib/test/test_tuple.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_tuple.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_tuple.py	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-import unittest
 from test import test_support, seq_tests
 
 class TupleTest(seq_tests.CommonTest):

Modified: python/branches/py3k-importlib/Lib/test/test_typechecks.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_typechecks.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_typechecks.py	Thu Mar 27 00:48:05 2008
@@ -18,19 +18,13 @@
 
 
 class Integer(metaclass=ABC):
-
     __subclass__ = {int}
 
 
 class SubInt(Integer):
-
     pass
 
 
-class Evil:
-    def __instancecheck__(self, inst): return False
-
-
 class TypeChecksTest(unittest.TestCase):
 
     def testIsSubclassInternal(self):
@@ -60,12 +54,6 @@
         self.assertEqual(isinstance(SubInt(), SubInt), True)
         self.assertEqual(isinstance(42, SubInt), False)
 
-    def testInfiniteRecursionCaughtProperly(self):
-        e = Evil()
-        # This invokes isinstance() recursively, until the stack is exhausted.
-        self.assertRaises(RuntimeError, isinstance, e, Evil)
-        # XXX How to check the same situation for issubclass()?
-
 
 def test_main():
     test_support.run_unittest(TypeChecksTest)

Modified: python/branches/py3k-importlib/Lib/test/test_types.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_types.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_types.py	Thu Mar 27 00:48:05 2008
@@ -63,15 +63,15 @@
 
         try: 5 / 0
         except ZeroDivisionError: pass
-        else: self.fail("5 / 0L didn't raise ZeroDivisionError")
+        else: self.fail("5 / 0 didn't raise ZeroDivisionError")
 
         try: 5 // 0
         except ZeroDivisionError: pass
-        else: self.fail("5 // 0L didn't raise ZeroDivisionError")
+        else: self.fail("5 // 0 didn't raise ZeroDivisionError")
 
         try: 5 % 0
         except ZeroDivisionError: pass
-        else: self.fail("5 % 0L didn't raise ZeroDivisionError")
+        else: self.fail("5 % 0 didn't raise ZeroDivisionError")
 
     def test_numeric_types(self):
         if 0 != 0 or 0 != 0.0 or 0 != 0.0: self.fail('mixed comparisons')
@@ -80,7 +80,7 @@
             self.fail('int/long/float value not equal')
         # calling built-in types without argument must return 0
         if int() != 0: self.fail('int() does not return 0')
-        if int() != 0: self.fail('long() does not return 0L')
+        if int() != 0: self.fail('long() does not return 0')
         if float() != 0.0: self.fail('float() does not return 0.0')
         if int(1.9) == 1 == int(1.1) and int(-1.1) == -1 == int(-1.9): pass
         else: self.fail('int() does not round properly')
@@ -89,6 +89,29 @@
         if float(1) == 1.0 and float(-1) == -1.0 and float(0) == 0.0: pass
         else: self.fail('float() does not work properly')
 
+    def test_float_to_string(self):
+        def test(f, result):
+            self.assertEqual(f.__format__('e'), result)
+            self.assertEqual('%e' % f, result)
+
+        # test all 2 digit exponents, both with __format__ and with
+        #  '%' formatting
+        for i in range(-99, 100):
+            test(float('1.5e'+str(i)), '1.500000e{0:+03d}'.format(i))
+
+        # test some 3 digit exponents
+        self.assertEqual(1.5e100.__format__('e'), '1.500000e+100')
+        self.assertEqual('%e' % 1.5e100, '1.500000e+100')
+
+        self.assertEqual(1.5e101.__format__('e'), '1.500000e+101')
+        self.assertEqual('%e' % 1.5e101, '1.500000e+101')
+
+        self.assertEqual(1.5e-100.__format__('e'), '1.500000e-100')
+        self.assertEqual('%e' % 1.5e-100, '1.500000e-100')
+
+        self.assertEqual(1.5e-101.__format__('e'), '1.500000e-101')
+        self.assertEqual('%e' % 1.5e-101, '1.500000e-101')
+
     def test_normal_integers(self):
         # Ensure the first 256 integers are shared
         a = 256
@@ -105,7 +128,7 @@
         if not (xsize*ysize*zsize == zsize*xsize*ysize == 338912):
             self.fail('int mul commutativity')
         # And another.
-        m = -sys.maxint - 1
+        m = -sys.maxsize - 1
         for divisor in 1, 2, 4, 8, 16, 32:
             j = m // divisor
             prod = divisor * j
@@ -122,7 +145,7 @@
                 self.fail("expected type(%r) to be long, not %r" %
                                    (prod, type(prod)))
         # Check for expected * overflow to long.
-        m = sys.maxint
+        m = sys.maxsize
         for divisor in 1, 2, 4, 8, 16, 32:
             j = m // divisor + 1
             prod = divisor * j
@@ -137,7 +160,7 @@
         if (-12) + (-24) != -36: self.fail('long op')
         if not 12 < 24: self.fail('long op')
         if not -24 < -12: self.fail('long op')
-        x = sys.maxint
+        x = sys.maxsize
         if int(int(x)) != x: self.fail('long op')
         try: y = int(int(x)+1)
         except OverflowError: self.fail('long op')
@@ -203,6 +226,261 @@
         self.assertRaises(TypeError, type, 1, 2)
         self.assertRaises(TypeError, type, 1, 2, 3, 4)
 
+    def test_int__format__(self):
+        def test(i, format_spec, result):
+            # just make sure I'm not accidentally checking longs
+            assert type(i) == int
+            assert type(format_spec) == str
+            self.assertEqual(i.__format__(format_spec), result)
+
+        test(123456789, 'd', '123456789')
+        test(123456789, 'd', '123456789')
+
+        test(1, 'c', '\01')
+
+        # sign and aligning are interdependent
+        test(1, "-", '1')
+        test(-1, "-", '-1')
+        test(1, "-3", '  1')
+        test(-1, "-3", ' -1')
+        test(1, "+3", ' +1')
+        test(-1, "+3", ' -1')
+        test(1, " 3", '  1')
+        test(-1, " 3", ' -1')
+        test(1, " ", ' 1')
+        test(-1, " ", '-1')
+
+        # hex
+        test(3, "x", "3")
+        test(3, "X", "3")
+        test(1234, "x", "4d2")
+        test(-1234, "x", "-4d2")
+        test(1234, "8x", "     4d2")
+        test(-1234, "8x", "    -4d2")
+        test(1234, "x", "4d2")
+        test(-1234, "x", "-4d2")
+        test(-3, "x", "-3")
+        test(-3, "X", "-3")
+        test(int('be', 16), "x", "be")
+        test(int('be', 16), "X", "BE")
+        test(-int('be', 16), "x", "-be")
+        test(-int('be', 16), "X", "-BE")
+
+        # octal
+        test(3, "o", "3")
+        test(-3, "o", "-3")
+        test(65, "o", "101")
+        test(-65, "o", "-101")
+        test(1234, "o", "2322")
+        test(-1234, "o", "-2322")
+        test(1234, "-o", "2322")
+        test(-1234, "-o", "-2322")
+        test(1234, " o", " 2322")
+        test(-1234, " o", "-2322")
+        test(1234, "+o", "+2322")
+        test(-1234, "+o", "-2322")
+
+        # binary
+        test(3, "b", "11")
+        test(-3, "b", "-11")
+        test(1234, "b", "10011010010")
+        test(-1234, "b", "-10011010010")
+        test(1234, "-b", "10011010010")
+        test(-1234, "-b", "-10011010010")
+        test(1234, " b", " 10011010010")
+        test(-1234, " b", "-10011010010")
+        test(1234, "+b", "+10011010010")
+        test(-1234, "+b", "-10011010010")
+
+        # make sure these are errors
+
+        # precision disallowed
+        self.assertRaises(ValueError, 3 .__format__, "1.3")
+        # sign not allowed with 'c'
+        self.assertRaises(ValueError, 3 .__format__, "+c")
+        # format spec must be string
+        self.assertRaises(TypeError, 3 .__format__, None)
+        self.assertRaises(TypeError, 3 .__format__, 0)
+
+        # ensure that only int and float type specifiers work
+        for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
+                            [chr(x) for x in range(ord('A'), ord('Z')+1)]):
+            if not format_spec in 'bcdoxXeEfFgGn%':
+                self.assertRaises(ValueError, 0 .__format__, format_spec)
+                self.assertRaises(ValueError, 1 .__format__, format_spec)
+                self.assertRaises(ValueError, (-1) .__format__, format_spec)
+
+        # ensure that float type specifiers work; format converts
+        #  the int to a float
+        for format_spec in 'eEfFgGn%':
+            for value in [0, 1, -1, 100, -100, 1234567890, -1234567890]:
+                self.assertEqual(value.__format__(format_spec),
+                                 float(value).__format__(format_spec))
+
+    def test_long__format__(self):
+        def test(i, format_spec, result):
+            # make sure we're not accidentally checking ints
+            assert type(i) == int
+            assert type(format_spec) == str
+            self.assertEqual(i.__format__(format_spec), result)
+
+        test(10**100, 'd', '1' + '0' * 100)
+        test(10**100+100, 'd', '1' + '0' * 97 + '100')
+
+        test(123456789, 'd', '123456789')
+        test(123456789, 'd', '123456789')
+
+        # sign and aligning are interdependent
+        test(1, "-", '1')
+        test(-1, "-", '-1')
+        test(1, "-3", '  1')
+        test(-1, "-3", ' -1')
+        test(1, "+3", ' +1')
+        test(-1, "+3", ' -1')
+        test(1, " 3", '  1')
+        test(-1, " 3", ' -1')
+        test(1, " ", ' 1')
+        test(-1, " ", '-1')
+
+        test(1, 'c', '\01')
+
+        # hex
+        test(3, "x", "3")
+        test(3, "X", "3")
+        test(1234, "x", "4d2")
+        test(-1234, "x", "-4d2")
+        test(1234, "8x", "     4d2")
+        test(-1234, "8x", "    -4d2")
+        test(1234, "x", "4d2")
+        test(-1234, "x", "-4d2")
+        test(-3, "x", "-3")
+        test(-3, "X", "-3")
+
+        # octal
+        test(3, "o", "3")
+        test(-3, "o", "-3")
+        test(65, "o", "101")
+        test(-65, "o", "-101")
+        test(1234, "o", "2322")
+        test(-1234, "o", "-2322")
+        test(1234, "-o", "2322")
+        test(-1234, "-o", "-2322")
+        test(1234, " o", " 2322")
+        test(-1234, " o", "-2322")
+        test(1234, "+o", "+2322")
+        test(-1234, "+o", "-2322")
+
+        # binary
+        test(3, "b", "11")
+        test(-3, "b", "-11")
+        test(1234, "b", "10011010010")
+        test(-1234, "b", "-10011010010")
+        test(1234, "-b", "10011010010")
+        test(-1234, "-b", "-10011010010")
+        test(1234, " b", " 10011010010")
+        test(-1234, " b", "-10011010010")
+        test(1234, "+b", "+10011010010")
+        test(-1234, "+b", "-10011010010")
+
+        # make sure these are errors
+
+        # precision disallowed
+        self.assertRaises(ValueError, 3 .__format__, "1.3")
+        # sign not allowed with 'c'
+        self.assertRaises(ValueError, 3 .__format__, "+c")
+        # format spec must be string
+        self.assertRaises(TypeError, 3 .__format__, None)
+        self.assertRaises(TypeError, 3 .__format__, 0)
+
+        # ensure that only int and float type specifiers work
+        for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
+                            [chr(x) for x in range(ord('A'), ord('Z')+1)]):
+            if not format_spec in 'bcdoxXeEfFgGn%':
+                self.assertRaises(ValueError, 0 .__format__, format_spec)
+                self.assertRaises(ValueError, 1 .__format__, format_spec)
+                self.assertRaises(ValueError, (-1) .__format__, format_spec)
+
+        # ensure that float type specifiers work; format converts
+        #  the long to a float
+        for format_spec in 'eEfFgGn%':
+            for value in [0, 1, -1, 100, -100, 1234567890, -1234567890]:
+                self.assertEqual(value.__format__(format_spec),
+                                 float(value).__format__(format_spec))
+
+    def test_float__format__(self):
+        # these should be rewritten to use both format(x, spec) and
+        # x.__format__(spec)
+
+        def test(f, format_spec, result):
+            assert type(f) == float
+            assert type(format_spec) == str
+            self.assertEqual(f.__format__(format_spec), result)
+
+        test(0.0, 'f', '0.000000')
+
+        # the default is 'g', except for empty format spec
+        test(0.0, '', '0.0')
+        test(0.01, '', '0.01')
+        test(0.01, 'g', '0.01')
+
+        test( 1.0, ' g', ' 1')
+        test(-1.0, ' g', '-1')
+        test( 1.0, '+g', '+1')
+        test(-1.0, '+g', '-1')
+        test(1.1234e200, 'g', '1.1234e+200')
+        test(1.1234e200, 'G', '1.1234E+200')
+
+
+        test(1.0, 'f', '1.000000')
+
+        test(-1.0, 'f', '-1.000000')
+
+        test( 1.0, ' f', ' 1.000000')
+        test(-1.0, ' f', '-1.000000')
+        test( 1.0, '+f', '+1.000000')
+        test(-1.0, '+f', '-1.000000')
+        test(1.1234e90, 'f', '1.1234e+90')
+        test(1.1234e90, 'F', '1.1234e+90')
+        test(1.1234e200, 'f', '1.1234e+200')
+        test(1.1234e200, 'F', '1.1234e+200')
+
+        test( 1.0, 'e', '1.000000e+00')
+        test(-1.0, 'e', '-1.000000e+00')
+        test( 1.0, 'E', '1.000000E+00')
+        test(-1.0, 'E', '-1.000000E+00')
+        test(1.1234e20, 'e', '1.123400e+20')
+        test(1.1234e20, 'E', '1.123400E+20')
+
+        # No format code means use g, but must have a decimal
+        # and a number after the decimal.  This is tricky, because
+        # a totaly empty format specifier means something else.
+        # So, just use a sign flag
+        test(1e200, '+g', '+1e+200')
+        test(1e200, '+', '+1.0e+200')
+        test(1.1e200, '+g', '+1.1e+200')
+        test(1.1e200, '+', '+1.1e+200')
+
+        # % formatting
+        test(-1.0, '%', '-100.000000%')
+
+        # format spec must be string
+        self.assertRaises(TypeError, 3.0.__format__, None)
+        self.assertRaises(TypeError, 3.0.__format__, 0)
+
+        # other format specifiers shouldn't work on floats,
+        #  in particular int specifiers
+        for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
+                            [chr(x) for x in range(ord('A'), ord('Z')+1)]):
+            if not format_spec in 'eEfFgGn%':
+                self.assertRaises(ValueError, format, 0.0, format_spec)
+                self.assertRaises(ValueError, format, 1.0, format_spec)
+                self.assertRaises(ValueError, format, -1.0, format_spec)
+                self.assertRaises(ValueError, format, 1e100, format_spec)
+                self.assertRaises(ValueError, format, -1e100, format_spec)
+                self.assertRaises(ValueError, format, 1e-100, format_spec)
+                self.assertRaises(ValueError, format, -1e-100, format_spec)
+
+
 def test_main():
     run_unittest(TypesTests)
 

Modified: python/branches/py3k-importlib/Lib/test/test_unicode.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_unicode.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_unicode.py	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,11 @@
 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
 
 """#"
-import unittest, sys, struct, codecs, new
+import codecs
+import struct
+import sys
+import unittest
+import warnings
 from test import test_support, string_tests
 
 # Error handling (bad decoder return)
@@ -34,6 +38,12 @@
     ):
     type2test = str
 
+    def setUp(self):
+        self.warning_filters = warnings.filters[:]
+
+    def tearDown(self):
+        warnings.filters = self.warning_filters
+
     def checkequalnofix(self, result, object, methodname, *args):
         method = getattr(object, methodname)
         realresult = method(*args)
@@ -156,13 +166,34 @@
         self.assertRaises(ValueError, 'abcdefghi'.rindex,  'ghi', 0, 8)
         self.assertRaises(ValueError, 'abcdefghi'.rindex,  'ghi', 0, -1)
 
-    def test_translate(self):
-        self.checkequalnofix('bbbc', 'abababc', 'translate', {ord('a'):None})
-        self.checkequalnofix('iiic', 'abababc', 'translate', {ord('a'):None, ord('b'):ord('i')})
-        self.checkequalnofix('iiix', 'abababc', 'translate', {ord('a'):None, ord('b'):ord('i'), ord('c'):'x'})
-        self.checkequalnofix('<i><i><i>c', 'abababc', 'translate', {ord('a'):None, ord('b'):'<i>'})
-        self.checkequalnofix('c', 'abababc', 'translate', {ord('a'):None, ord('b'):''})
-        self.checkequalnofix('xyyx', 'xzx', 'translate', {ord('z'):'yy'})
+    def test_maketrans_translate(self):
+        # these work with plain translate()
+        self.checkequalnofix('bbbc', 'abababc', 'translate',
+                             {ord('a'): None})
+        self.checkequalnofix('iiic', 'abababc', 'translate',
+                             {ord('a'): None, ord('b'): ord('i')})
+        self.checkequalnofix('iiix', 'abababc', 'translate',
+                             {ord('a'): None, ord('b'): ord('i'), ord('c'): 'x'})
+        self.checkequalnofix('c', 'abababc', 'translate',
+                             {ord('a'): None, ord('b'): ''})
+        self.checkequalnofix('xyyx', 'xzx', 'translate',
+                             {ord('z'): 'yy'})
+        # this needs maketrans()
+        self.checkequalnofix('abababc', 'abababc', 'translate',
+                             {'b': '<i>'})
+        tbl = self.type2test.maketrans({'a': None, 'b': '<i>'})
+        self.checkequalnofix('<i><i><i>c', 'abababc', 'translate', tbl)
+        # test alternative way of calling maketrans()
+        tbl = self.type2test.maketrans('abc', 'xyz', 'd')
+        self.checkequalnofix('xyzzy', 'abdcdcbdddd', 'translate', tbl)
+
+        self.assertRaises(TypeError, self.type2test.maketrans)
+        self.assertRaises(ValueError, self.type2test.maketrans, 'abc', 'defg')
+        self.assertRaises(TypeError, self.type2test.maketrans, 2, 'def')
+        self.assertRaises(TypeError, self.type2test.maketrans, 'abc', 2)
+        self.assertRaises(TypeError, self.type2test.maketrans, 'abc', 'def', 2)
+        self.assertRaises(ValueError, self.type2test.maketrans, {'xy': 2})
+        self.assertRaises(TypeError, self.type2test.maketrans, {(1,): 2})
 
         self.assertRaises(TypeError, 'hello'.translate)
         self.assertRaises(TypeError, 'abababc'.translate, 'abc', 'xyz')
@@ -190,8 +221,10 @@
         self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
         self.checkequalnofix('abcd', '', 'join', ('a', 'b', 'c', 'd'))
         self.checkequalnofix('w x y z', ' ', 'join', string_tests.Sequence('wxyz'))
-        self.checkequalnofix('1 2 foo', ' ', 'join', [1, 2, MyWrapper('foo')])
-        self.checkraises(TypeError, ' ', 'join', [1, 2, 3, bytes()])
+        self.checkraises(TypeError, ' ', 'join', ['1', '2', MyWrapper('foo')])
+        self.checkraises(TypeError, ' ', 'join', ['1', '2', '3', bytes()])
+        self.checkraises(TypeError, ' ', 'join', [1, 2, 3])
+        self.checkraises(TypeError, ' ', 'join', ['1', '2', 3])
 
     def test_replace(self):
         string_tests.CommonTest.test_replace(self)
@@ -200,6 +233,13 @@
         self.checkequalnofix('one at two!three!', 'one!two!three!', 'replace', '!', '@', 1)
         self.assertRaises(TypeError, 'replace'.replace, "r", 42)
 
+    def test_bytes_comparison(self):
+        warnings.simplefilter('ignore', BytesWarning)
+        self.assertEqual('abc' == b'abc', False)
+        self.assertEqual('abc' != b'abc', True)
+        self.assertEqual('abc' == bytearray(b'abc'), False)
+        self.assertEqual('abc' != bytearray(b'abc'), True)
+
     def test_comparison(self):
         # Comparisons:
         self.assertEqual('abc', 'abc')
@@ -655,16 +695,6 @@
             'strings are converted to unicode'
         )
 
-        class UnicodeCompat:
-            def __init__(self, x):
-                self.x = x
-            def __unicode__(self):
-                return self.x
-
-        self.assertEqual(
-            str(UnicodeCompat('__unicode__ compatible objects are recognized')),
-            '__unicode__ compatible objects are recognized')
-
         class StringCompat:
             def __init__(self, x):
                 self.x = x
@@ -682,14 +712,6 @@
         self.assertEqual(str(o), 'unicode(obj) is compatible to str()')
         self.assertEqual(str(o), 'unicode(obj) is compatible to str()')
 
-        # %-formatting and .__unicode__()
-        self.assertEqual('%s' %
-                         UnicodeCompat("u'%s' % obj uses obj.__unicode__()"),
-                         "u'%s' % obj uses obj.__unicode__()")
-        self.assertEqual('%s' %
-                         UnicodeCompat("u'%s' % obj falls back to obj.__str__()"),
-                         "u'%s' % obj falls back to obj.__str__()")
-
         for obj in (123, 123.45, 123):
             self.assertEqual(str(obj), str(str(obj)))
 
@@ -951,12 +973,26 @@
         print('def\n', file=out)
 
     def test_ucs4(self):
-        if sys.maxunicode == 0xFFFF:
-            return
         x = '\U00100000'
         y = x.encode("raw-unicode-escape").decode("raw-unicode-escape")
         self.assertEqual(x, y)
 
+        # FIXME
+        #y = r'\U00100000'
+        #x = y.encode("raw-unicode-escape").decode("raw-unicode-escape")
+        #self.assertEqual(x, y)
+        #y = r'\U00010000'
+        #x = y.encode("raw-unicode-escape").decode("raw-unicode-escape")
+        #self.assertEqual(x, y)
+
+        #try:
+        #    '\U11111111'.decode("raw-unicode-escape")
+        #except UnicodeDecodeError as e:
+        #    self.assertEqual(e.start, 0)
+        #    self.assertEqual(e.end, 10)
+        #else:
+        #    self.fail("Should have raised UnicodeDecodeError")
+
     def test_conversion(self):
         # Make sure __unicode__() works properly
         class Foo0:
@@ -964,48 +1000,46 @@
                 return "foo"
 
         class Foo1:
-            def __unicode__(self):
+            def __str__(self):
                 return "foo"
 
         class Foo2(object):
-            def __unicode__(self):
+            def __str__(self):
                 return "foo"
 
         class Foo3(object):
-            def __unicode__(self):
+            def __str__(self):
                 return "foo"
 
         class Foo4(str):
-            def __unicode__(self):
+            def __str__(self):
                 return "foo"
 
         class Foo5(str):
-            def __unicode__(self):
+            def __str__(self):
                 return "foo"
 
         class Foo6(str):
             def __str__(self):
                 return "foos"
 
-            def __unicode__(self):
+            def __str__(self):
                 return "foou"
 
         class Foo7(str):
             def __str__(self):
                 return "foos"
-            def __unicode__(self):
+            def __str__(self):
                 return "foou"
 
         class Foo8(str):
             def __new__(cls, content=""):
                 return str.__new__(cls, 2*content)
-            def __unicode__(self):
+            def __str__(self):
                 return self
 
         class Foo9(str):
             def __str__(self):
-                return "string"
-            def __unicode__(self):
                 return "not unicode"
 
         self.assertEqual(str(Foo0()), "foo")
@@ -1035,9 +1069,9 @@
         # This test only affects 32-bit platforms because expandtabs can only take
         # an int as the max value, not a 64-bit C long.  If expandtabs is changed
         # to take a 64-bit long, this test should apply to all platforms.
-        if sys.maxint > (1 << 32) or struct.calcsize('P') != 4:
+        if sys.maxsize > (1 << 32) or struct.calcsize('P') != 4:
             return
-        self.assertRaises(OverflowError, 't\tt\t'.expandtabs, sys.maxint)
+        self.assertRaises(OverflowError, 't\tt\t'.expandtabs, sys.maxsize)
 
 
 def test_main():

Modified: python/branches/py3k-importlib/Lib/test/test_unicode_file.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_unicode_file.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_unicode_file.py	Thu Mar 27 00:48:05 2008
@@ -49,6 +49,22 @@
 
         self.failUnless(base in file_list)
 
+    # Do as many "equivalancy' tests as we can - ie, check that although we
+    # have different types for the filename, they refer to the same file.
+    def _do_equivalent(self, filename1, filename2):
+        # Note we only check "filename1 against filename2" - we don't bother
+        # checking "filename2 against 1", as we assume we are called again with
+        # the args reversed.
+        self.failUnless(type(filename1)!=type(filename2),
+                    "No point checking equivalent filenames of the same type")
+        # stat and lstat should return the same results.
+        self.failUnlessEqual(os.stat(filename1),
+                             os.stat(filename2))
+        self.failUnlessEqual(os.lstat(filename1),
+                             os.lstat(filename2))
+        # Copy/rename etc tests using equivalent filename
+        self._do_copyish(filename1, filename2)
+
     # Tests that copy, move, etc one file to another.
     def _do_copyish(self, filename1, filename2):
         # Should be able to rename the file using either name.
@@ -58,31 +74,20 @@
         os.rename(filename1 + ".new", filename2)
         self.failUnless(os.path.isfile(filename2))
 
-        # Try using shutil on the filenames.
-        try:
-            filename1==filename2
-        except UnicodeDecodeError:
-            # these filenames can't be compared - shutil.copy tries to do
-            # just that.  This is really a bug in 'shutil' - if one of shutil's
-            # 2 params are Unicode and the other isn't, it should coerce the
-            # string to Unicode with the filesystem encoding before comparison.
-            pass
-        else:
-            # filenames can be compared.
-            shutil.copy(filename1, filename2 + ".new")
-            os.unlink(filename1 + ".new") # remove using equiv name.
-            # And a couple of moves, one using each name.
-            shutil.move(filename1, filename2 + ".new")
-            self.failUnless(not os.path.exists(filename2))
-            shutil.move(filename1 + ".new", filename2)
-            self.failUnless(os.path.exists(filename1))
-            # Note - due to the implementation of shutil.move,
-            # it tries a rename first.  This only fails on Windows when on
-            # different file systems - and this test can't ensure that.
-            # So we test the shutil.copy2 function, which is the thing most
-            # likely to fail.
-            shutil.copy2(filename1, filename2 + ".new")
-            os.unlink(filename1 + ".new")
+        shutil.copy(filename1, filename2 + ".new")
+        os.unlink(filename1 + ".new") # remove using equiv name.
+        # And a couple of moves, one using each name.
+        shutil.move(filename1, filename2 + ".new")
+        self.failUnless(not os.path.exists(filename2))
+        shutil.move(filename1 + ".new", filename2)
+        self.failUnless(os.path.exists(filename1))
+        # Note - due to the implementation of shutil.move,
+        # it tries a rename first.  This only fails on Windows when on
+        # different file systems - and this test can't ensure that.
+        # So we test the shutil.copy2 function, which is the thing most
+        # likely to fail.
+        shutil.copy2(filename1, filename2 + ".new")
+        os.unlink(filename1 + ".new")
 
     def _do_directory(self, make_name, chdir_name, encoded):
         cwd = os.getcwd()
@@ -127,6 +132,16 @@
         finally:
             os.unlink(filename)
 
+    def _test_equivalent(self, filename1, filename2):
+        remove_if_exists(filename1)
+        self.failUnless(not os.path.exists(filename2))
+        f = file(filename1, "w")
+        f.close()
+        try:
+            self._do_equivalent(filename1, filename2)
+        finally:
+            os.unlink(filename1)
+
     # The 'test' functions are unittest entry points, and simply call our
     # _test functions with each of the filename combinations we wish to test
     def test_single_files(self):
@@ -135,6 +150,9 @@
             self._test_single(TESTFN_UNICODE_UNENCODEABLE)
 
     def test_directories(self):
+        # For all 'equivalent' combinations:
+        #  Make dir with encoded, chdir with unicode, checkdir with encoded
+        #  (or unicode/encoded/unicode, etc
         ext = ".dir"
         self._do_directory(TESTFN_UNICODE+ext, TESTFN_UNICODE+ext, False)
         # Our directory name that can't use a non-unicode name.

Modified: python/branches/py3k-importlib/Lib/test/test_unicodedata.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_unicodedata.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_unicodedata.py	Thu Mar 27 00:48:05 2008
@@ -176,7 +176,8 @@
 
     def test_east_asian_width(self):
         eaw = self.db.east_asian_width
-        self.assertRaises(TypeError, eaw, str8('a'))
+        self.assertRaises(TypeError, eaw, b'a')
+        self.assertRaises(TypeError, eaw, bytearray())
         self.assertRaises(TypeError, eaw, '')
         self.assertRaises(TypeError, eaw, 'ra')
         self.assertEqual(eaw('\x1e'), 'N')

Modified: python/branches/py3k-importlib/Lib/test/test_unittest.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_unittest.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_unittest.py	Thu Mar 27 00:48:05 2008
@@ -9,6 +9,7 @@
 from test import test_support
 import unittest
 from unittest import TestCase
+import types
 
 ### Support code
 ################################################################
@@ -153,8 +154,7 @@
 
     # "This method searches `module` for classes derived from TestCase"
     def test_loadTestsFromModule__TestCase_subclass(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class MyTestCase(unittest.TestCase):
             def test(self):
                 pass
@@ -171,8 +171,7 @@
     #
     # What happens if no tests are found (no TestCase instances)?
     def test_loadTestsFromModule__no_TestCase_instances(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
 
         loader = unittest.TestLoader()
         suite = loader.loadTestsFromModule(m)
@@ -183,8 +182,7 @@
     #
     # What happens if no tests are found (TestCases instances, but no tests)?
     def test_loadTestsFromModule__no_TestCase_tests(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class MyTestCase(unittest.TestCase):
             pass
         m.testcase_1 = MyTestCase
@@ -381,8 +379,7 @@
     # Does it raise an exception if the name resolves to an invalid
     # object?
     def test_loadTestsFromName__relative_bad_object(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         m.testcase_1 = object()
 
         loader = unittest.TestLoader()
@@ -396,8 +393,7 @@
     # "The specifier name is a ``dotted name'' that may
     # resolve either to ... a test case class"
     def test_loadTestsFromName__relative_TestCase_subclass(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class MyTestCase(unittest.TestCase):
             def test(self):
                 pass
@@ -413,8 +409,7 @@
     # within a test case class, or a callable object which returns a
     # TestCase or TestSuite instance."
     def test_loadTestsFromName__relative_TestSuite(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class MyTestCase(unittest.TestCase):
             def test(self):
                 pass
@@ -429,8 +424,7 @@
     # "The specifier name is a ``dotted name'' that may resolve ... to
     # ... a test method within a test case class"
     def test_loadTestsFromName__relative_testmethod(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class MyTestCase(unittest.TestCase):
             def test(self):
                 pass
@@ -451,8 +445,7 @@
     # resolve "a test method within a test case class" that doesn't exist
     # for the given name (relative to a provided module)?
     def test_loadTestsFromName__relative_invalid_testmethod(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class MyTestCase(unittest.TestCase):
             def test(self):
                 pass
@@ -469,8 +462,7 @@
     # "The specifier name is a ``dotted name'' that may resolve ... to
     # ... a callable object which returns a ... TestSuite instance"
     def test_loadTestsFromName__callable__TestSuite(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         testcase_1 = unittest.FunctionTestCase(lambda: None)
         testcase_2 = unittest.FunctionTestCase(lambda: None)
         def return_TestSuite():
@@ -485,8 +477,7 @@
     # "The specifier name is a ``dotted name'' that may resolve ... to
     # ... a callable object which returns a TestCase ... instance"
     def test_loadTestsFromName__callable__TestCase_instance(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         testcase_1 = unittest.FunctionTestCase(lambda: None)
         def return_TestCase():
             return testcase_1
@@ -502,8 +493,7 @@
     #
     # What happens if the callable returns something else?
     def test_loadTestsFromName__callable__wrong_type(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         def return_wrong():
             return 6
         m.return_wrong = return_wrong
@@ -751,8 +741,7 @@
     # Does it raise an exception if the name resolves to an invalid
     # object?
     def test_loadTestsFromNames__relative_bad_object(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         m.testcase_1 = object()
 
         loader = unittest.TestLoader()
@@ -766,8 +755,7 @@
     # "The specifier name is a ``dotted name'' that may resolve ... to
     # ... a test case class"
     def test_loadTestsFromNames__relative_TestCase_subclass(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class MyTestCase(unittest.TestCase):
             def test(self):
                 pass
@@ -783,8 +771,7 @@
     # "The specifier name is a ``dotted name'' that may resolve ... to
     # ... a TestSuite instance"
     def test_loadTestsFromNames__relative_TestSuite(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class MyTestCase(unittest.TestCase):
             def test(self):
                 pass
@@ -799,8 +786,7 @@
     # "The specifier name is a ``dotted name'' that may resolve ... to ... a
     # test method within a test case class"
     def test_loadTestsFromNames__relative_testmethod(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class MyTestCase(unittest.TestCase):
             def test(self):
                 pass
@@ -819,8 +805,7 @@
     # Does the method gracefully handle names that initially look like they
     # resolve to "a test method within a test case class" but don't?
     def test_loadTestsFromNames__relative_invalid_testmethod(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class MyTestCase(unittest.TestCase):
             def test(self):
                 pass
@@ -837,8 +822,7 @@
     # "The specifier name is a ``dotted name'' that may resolve ... to
     # ... a callable object which returns a ... TestSuite instance"
     def test_loadTestsFromNames__callable__TestSuite(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         testcase_1 = unittest.FunctionTestCase(lambda: None)
         testcase_2 = unittest.FunctionTestCase(lambda: None)
         def return_TestSuite():
@@ -855,8 +839,7 @@
     # "The specifier name is a ``dotted name'' that may resolve ... to
     # ... a callable object which returns a TestCase ... instance"
     def test_loadTestsFromNames__callable__TestCase_instance(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         testcase_1 = unittest.FunctionTestCase(lambda: None)
         def return_TestCase():
             return testcase_1
@@ -874,8 +857,7 @@
     #
     # Are staticmethods handled correctly?
     def test_loadTestsFromNames__callable__call_staticmethod(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class Test1(unittest.TestCase):
             def test(self):
                 pass
@@ -899,8 +881,7 @@
     #
     # What happens when the callable returns something else?
     def test_loadTestsFromNames__callable__wrong_type(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         def return_wrong():
             return 6
         m.return_wrong = return_wrong
@@ -1043,8 +1024,7 @@
     # Implicit in the documentation is that testMethodPrefix is respected by
     # all loadTestsFrom* methods.
     def test_testMethodPrefix__loadTestsFromModule(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class Foo(unittest.TestCase):
             def test_1(self): pass
             def test_2(self): pass
@@ -1067,8 +1047,7 @@
     # Implicit in the documentation is that testMethodPrefix is respected by
     # all loadTestsFrom* methods.
     def test_testMethodPrefix__loadTestsFromName(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class Foo(unittest.TestCase):
             def test_1(self): pass
             def test_2(self): pass
@@ -1091,8 +1070,7 @@
     # Implicit in the documentation is that testMethodPrefix is respected by
     # all loadTestsFrom* methods.
     def test_testMethodPrefix__loadTestsFromNames(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class Foo(unittest.TestCase):
             def test_1(self): pass
             def test_2(self): pass
@@ -1143,8 +1121,7 @@
         def reversed_cmp(x, y):
             return -cmp(x, y)
 
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class Foo(unittest.TestCase):
             def test_1(self): pass
             def test_2(self): pass
@@ -1162,8 +1139,7 @@
         def reversed_cmp(x, y):
             return -cmp(x, y)
 
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class Foo(unittest.TestCase):
             def test_1(self): pass
             def test_2(self): pass
@@ -1181,8 +1157,7 @@
         def reversed_cmp(x, y):
             return -cmp(x, y)
 
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class Foo(unittest.TestCase):
             def test_1(self): pass
             def test_2(self): pass
@@ -1254,8 +1229,7 @@
     # It is implicit in the documentation for TestLoader.suiteClass that
     # all TestLoader.loadTestsFrom* methods respect it. Let's make sure
     def test_suiteClass__loadTestsFromModule(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class Foo(unittest.TestCase):
             def test_1(self): pass
             def test_2(self): pass
@@ -1271,8 +1245,7 @@
     # It is implicit in the documentation for TestLoader.suiteClass that
     # all TestLoader.loadTestsFrom* methods respect it. Let's make sure
     def test_suiteClass__loadTestsFromName(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class Foo(unittest.TestCase):
             def test_1(self): pass
             def test_2(self): pass
@@ -1288,8 +1261,7 @@
     # It is implicit in the documentation for TestLoader.suiteClass that
     # all TestLoader.loadTestsFrom* methods respect it. Let's make sure
     def test_suiteClass__loadTestsFromNames(self):
-        import new
-        m = new.module('m')
+        m = types.ModuleType('m')
         class Foo(unittest.TestCase):
             def test_1(self): pass
             def test_2(self): pass
@@ -1718,7 +1690,7 @@
     def test_id(self):
         test = unittest.FunctionTestCase(lambda: None)
 
-        self.failUnless(isinstance(test.id(), basestring))
+        self.failUnless(isinstance(test.id(), str))
 
     # "Returns a one-line description of the test, or None if no description
     # has been provided. The default implementation of this method returns
@@ -2239,7 +2211,7 @@
             def runTest(self):
                 pass
 
-        self.failUnless(isinstance(Foo().id(), basestring))
+        self.failUnless(isinstance(Foo().id(), str))
 
     # "Returns a one-line description of the test, or None if no description
     # has been provided. The default implementation of this method returns

Modified: python/branches/py3k-importlib/Lib/test/test_univnewlines.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_univnewlines.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_univnewlines.py	Thu Mar 27 00:48:05 2008
@@ -93,6 +93,13 @@
     NEWLINE = '\r\n'
     DATA = DATA_CRLF
 
+    def test_tell(self):
+        fp = open(test_support.TESTFN, self.READMODE)
+        self.assertEqual(repr(fp.newlines), repr(None))
+        data = fp.readline()
+        pos = fp.tell()
+        self.assertEqual(repr(fp.newlines), repr(self.NEWLINE))
+
 class TestMixedNewlines(TestGenericUnivNewlines):
     NEWLINE = ('\r', '\n')
     DATA = DATA_MIXED

Modified: python/branches/py3k-importlib/Lib/test/test_unpack.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_unpack.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_unpack.py	Thu Mar 27 00:48:05 2008
@@ -122,7 +122,6 @@
 __test__ = {'doctests' : doctests}
 
 def test_main(verbose=False):
-    import sys
     from test import test_support
     from test import test_unpack
     test_support.run_doctest(test_unpack, verbose)

Modified: python/branches/py3k-importlib/Lib/test/test_unpack_ex.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_unpack_ex.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_unpack_ex.py	Thu Mar 27 00:48:05 2008
@@ -143,6 +143,23 @@
       ...
     SyntaxError: can use starred expression only as assignment target
 
+Some size constraints (all fail.)
+
+    >>> s = ", ".join("a%d" % i for i in range(1<<8)) + ", *rest = range(1<<8 + 1)"
+    >>> compile(s, 'test', 'exec') # doctest:+ELLIPSIS
+    Traceback (most recent call last):
+     ...
+    SyntaxError: too many expressions in star-unpacking assignment
+
+    >>> s = ", ".join("a%d" % i for i in range(1<<8 + 1)) + ", *rest = range(1<<8 + 2)"
+    >>> compile(s, 'test', 'exec') # doctest:+ELLIPSIS
+    Traceback (most recent call last):
+     ...
+    SyntaxError: too many expressions in star-unpacking assignment
+
+(there is an additional limit, on the number of expressions after the
+'*rest', but it's 1<<24 and testing it takes too much memory.)
+
 """
 
 __test__ = {'doctests' : doctests}

Modified: python/branches/py3k-importlib/Lib/test/test_urllib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_urllib.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_urllib.py	Thu Mar 27 00:48:05 2008
@@ -8,10 +8,6 @@
 import os
 import mimetools
 import tempfile
-import ftplib
-import threading
-import socket
-import time
 
 def hexescape(char):
     """Escape char as RFC 2396 specifies"""
@@ -47,7 +43,7 @@
     def test_interface(self):
         # Make sure object returned by urlopen() has the specified methods
         for attr in ("read", "readline", "readlines", "fileno",
-                     "close", "info", "geturl", "__iter__"):
+                     "close", "info", "geturl", "getcode", "__iter__"):
             self.assert_(hasattr(self.returned_obj, attr),
                          "object returned by urlopen() lacks %s attribute" %
                          attr)
@@ -87,6 +83,9 @@
     def test_geturl(self):
         self.assertEqual(self.returned_obj.geturl(), self.pathname)
 
+    def test_getcode(self):
+        self.assertEqual(self.returned_obj.getcode(), None)
+
     def test_iter(self):
         # Test iterator
         # Don't need to count number of iterations since test would fail the
@@ -123,13 +122,28 @@
             fp = urllib.urlopen("http://python.org/")
             self.assertEqual(fp.readline(), b"Hello!")
             self.assertEqual(fp.readline(), b"")
+            self.assertEqual(fp.geturl(), 'http://python.org/')
+            self.assertEqual(fp.getcode(), 200)
+        finally:
+            self.unfakehttp()
+
+    def test_read_bogus(self):
+        # urlopen() should raise IOError for many error codes.
+        self.fakehttp(b'''HTTP/1.1 401 Authentication Required
+Date: Wed, 02 Jan 2008 03:03:54 GMT
+Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
+Connection: close
+Content-Type: text/html; charset=iso-8859-1
+''')
+        try:
+            self.assertRaises(IOError, urllib.urlopen, "http://python.org/")
         finally:
             self.unfakehttp()
 
     def test_empty_socket(self):
         # urlopen() raises IOError if the underlying socket does not send any
         # data. (#1680230)
-        self.fakehttp(b"")
+        self.fakehttp(b'')
         try:
             self.assertRaises(IOError, urllib.urlopen, "http://something")
         finally:

Modified: python/branches/py3k-importlib/Lib/test/test_urllib2.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_urllib2.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_urllib2.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,7 @@
 import unittest
 from test import test_support
 
-import os, socket
+import os
 import io
 
 import urllib2
@@ -584,7 +584,7 @@
             self.assertEqual(int(headers["Content-length"]), len(data))
 
     def test_file(self):
-        import time, rfc822, socket
+        import rfc822, socket
         h = urllib2.FileHandler()
         o = h.parent = MockOpener()
 
@@ -817,6 +817,8 @@
                 method = getattr(h, "http_error_%s" % code)
                 req = Request(from_url, data)
                 req.add_header("Nonsense", "viking=withhold")
+                if data is not None:
+                    req.add_header("Content-Length", str(len(data)))
                 req.add_unredirected_header("Spam", "spam")
                 try:
                     method(req, MockFile(), code, "Blah",
@@ -829,6 +831,13 @@
                     self.assertEqual(o.req.get_method(), "GET")
                 except AttributeError:
                     self.assert_(not o.req.has_data())
+
+                # now it's a GET, there should not be headers regarding content
+                # (possibly dragged from before being a POST)
+                headers = [x.lower() for x in o.req.headers]
+                self.assertTrue("content-length" not in headers)
+                self.assertTrue("content-type" not in headers)
+
                 self.assertEqual(o.req.headers["Nonsense"],
                                  "viking=withhold")
                 self.assert_("Spam" not in o.req.headers)
@@ -897,13 +906,14 @@
         self.assertEqual([(handlers[0], "http_open")],
                          [tup[0:2] for tup in o.calls])
 
-    def test_basic_auth(self):
+    def test_basic_auth(self, quote_char='"'):
         opener = OpenerDirector()
         password_manager = MockPasswordManager()
         auth_handler = urllib2.HTTPBasicAuthHandler(password_manager)
         realm = "ACME Widget Store"
         http_handler = MockHTTPHandler(
-            401, 'WWW-Authenticate: Basic realm="%s"\r\n\r\n' % realm)
+            401, 'WWW-Authenticate: Basic realm=%s%s%s\r\n\r\n' %
+            (quote_char, realm, quote_char) )
         opener.add_handler(auth_handler)
         opener.add_handler(http_handler)
         self._test_basic_auth(opener, auth_handler, "Authorization",
@@ -912,6 +922,9 @@
                               "http://acme.example.com/protected",
                               )
 
+    def test_basic_auth_with_single_quoted_realm(self):
+        self.test_basic_auth(quote_char="'")
+
     def test_proxy_basic_auth(self):
         opener = OpenerDirector()
         ph = urllib2.ProxyHandler(dict(http="proxy.example.com:3128"))
@@ -979,7 +992,7 @@
     def _test_basic_auth(self, opener, auth_handler, auth_header,
                          realm, http_handler, password_manager,
                          request_url, protected_url):
-        import base64, httplib
+        import base64
         user, password = "wile", "coyote"
 
         # .add_password() fed through to password manager
@@ -999,7 +1012,8 @@
         self.assertEqual(len(http_handler.requests), 2)
         self.assertFalse(http_handler.requests[0].has_header(auth_header))
         userpass = bytes('%s:%s' % (user, password), "ascii")
-        auth_hdr_value = 'Basic ' + str(base64.encodestring(userpass)).strip()
+        auth_hdr_value = ('Basic ' +
+            base64.encodestring(userpass).strip().decode())
         self.assertEqual(http_handler.requests[1].get_header(auth_header),
                          auth_hdr_value)
 

Modified: python/branches/py3k-importlib/Lib/test/test_urllib2_localnet.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_urllib2_localnet.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_urllib2_localnet.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,5 @@
 #!/usr/bin/env python
 
-import sys
 import threading
 import urlparse
 import urllib2
@@ -139,7 +138,7 @@
         # not.
         #request_handler.send_header('Connection', 'close')
         request_handler.end_headers()
-        request_handler.wfile.write("Proxy Authentication Required.")
+        request_handler.wfile.write(b"Proxy Authentication Required.")
         return False
 
     def handle_request(self, request_handler):
@@ -210,9 +209,10 @@
             self.send_response(200, "OK")
             self.send_header("Content-Type", "text/html")
             self.end_headers()
-            self.wfile.write("You've reached %s!<BR>" % self.path)
-            self.wfile.write("Our apologies, but our server is down due to "
-                              "a sudden zombie invasion.")
+            self.wfile.write(bytes("You've reached %s!<BR>" % self.path,
+                                   "ascii"))
+            self.wfile.write(b"Our apologies, but our server is down due to "
+                             b"a sudden zombie invasion.")
 
 # Test cases
 

Modified: python/branches/py3k-importlib/Lib/test/test_urllib2net.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_urllib2net.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_urllib2net.py	Thu Mar 27 00:48:05 2008
@@ -10,6 +10,21 @@
 import os
 import mimetools
 
+
+def _urlopen_with_retry(host, *args, **kwargs):
+    # Connecting to remote hosts is flaky.  Make it more robust
+    # by retrying the connection several times.
+    for i in range(3):
+        try:
+            return urllib2.urlopen(host, *args, **kwargs)
+        except urllib2.URLError as e:
+            last_exc = e
+            continue
+        except:
+            raise
+    raise last_exc
+
+
 class URLTimeoutTest(unittest.TestCase):
 
     TIMEOUT = 10.0
@@ -21,7 +36,7 @@
         socket.setdefaulttimeout(None)
 
     def testURLread(self):
-        f = urllib2.urlopen("http://www.python.org/")
+        f = _urlopen_with_retry("http://www.python.org/")
         x = f.read()
 
 
@@ -42,7 +57,7 @@
 #
 #        # failure
 #        try:
-#            urllib2.urlopen(test_url)
+#            _urlopen_with_retry(test_url)
 #        except urllib2.HTTPError, exc:
 #            self.assertEqual(exc.code, 401)
 #        else:
@@ -54,7 +69,7 @@
 #                                  test_user, test_password)
 #        opener = urllib2.build_opener(auth_handler)
 #        f = opener.open('http://localhost/')
-#        response = urllib2.urlopen("http://www.python.org/")
+#        response = _urlopen_with_retry("http://www.python.org/")
 #
 #        # The 'userinfo' URL component is deprecated by RFC 3986 for security
 #        # reasons, let's not implement it!  (it's already implemented for proxy
@@ -73,7 +88,7 @@
         # underlying socket
 
         # delve deep into response to fetch socket._socketobject
-        response = urllib2.urlopen("http://www.python.org/")
+        response = _urlopen_with_retry("http://www.python.org/")
         abused_fileobject = response.fp
         httpresponse = abused_fileobject.raw
         self.assert_(httpresponse.__class__ is httplib.HTTPResponse)
@@ -100,7 +115,7 @@
 
     def test_basic(self):
         # Simple test expected to pass.
-        open_url = urllib2.urlopen("http://www.python.org/")
+        open_url = _urlopen_with_retry("http://www.python.org/")
         for attr in ("read", "close", "info", "geturl"):
             self.assert_(hasattr(open_url, attr), "object returned from "
                             "urlopen lacks the %s attribute" % attr)
@@ -111,7 +126,7 @@
 
     def test_info(self):
         # Test 'info'.
-        open_url = urllib2.urlopen("http://www.python.org/")
+        open_url = _urlopen_with_retry("http://www.python.org/")
         try:
             info_obj = open_url.info()
         finally:
@@ -124,7 +139,7 @@
     def test_geturl(self):
         # Make sure same URL as opened is returned by geturl.
         URL = "http://www.python.org/"
-        open_url = urllib2.urlopen(URL)
+        open_url = _urlopen_with_retry(URL)
         try:
             gotten_url = open_url.geturl()
         finally:
@@ -155,7 +170,7 @@
     def test_range (self):
         req = urllib2.Request("http://www.python.org",
                               headers={'Range': 'bytes=20-39'})
-        result = urllib2.urlopen(req)
+        result = _urlopen_with_retry(req)
         data = result.read()
         self.assertEqual(len(data), 20)
 
@@ -182,7 +197,7 @@
                 'file:'+sanepathname2url(os.path.abspath(TESTFN)),
                 ('file:///nonsensename/etc/passwd', None, urllib2.URLError),
                 ]
-            self._test_urls(urls, self._extra_handlers())
+            self._test_urls(urls, self._extra_handlers(), urllib2.urlopen)
         finally:
             os.remove(TESTFN)
 
@@ -224,7 +239,7 @@
 
 ##             self._test_urls(urls, self._extra_handlers()+[bauth, dauth])
 
-    def _test_urls(self, urls, handlers):
+    def _test_urls(self, urls, handlers, urlopen=_urlopen_with_retry):
         import socket
         import time
         import logging
@@ -239,7 +254,7 @@
                 req = expected_err = None
             debug(url)
             try:
-                f = urllib2.urlopen(url, req)
+                f = urlopen(url, req)
             except EnvironmentError as err:
                 debug(err)
                 if expected_err:
@@ -265,47 +280,47 @@
 
 class TimeoutTest(unittest.TestCase):
     def test_http_basic(self):
-        u = urllib2.urlopen("http://www.python.org")
+        u = _urlopen_with_retry("http://www.python.org")
         self.assertTrue(u.fp.raw.fp._sock.gettimeout() is None)
 
     def test_http_NoneWithdefault(self):
         prev = socket.getdefaulttimeout()
         socket.setdefaulttimeout(60)
         try:
-            u = urllib2.urlopen("http://www.python.org", timeout=None)
+            u = _urlopen_with_retry("http://www.python.org", timeout=None)
             self.assertTrue(u.fp.raw.fp._sock.gettimeout(), 60)
         finally:
             socket.setdefaulttimeout(prev)
 
     def test_http_Value(self):
-        u = urllib2.urlopen("http://www.python.org", timeout=120)
+        u = _urlopen_with_retry("http://www.python.org", timeout=120)
         self.assertEqual(u.fp.raw.fp._sock.gettimeout(), 120)
 
     def test_http_NoneNodefault(self):
-        u = urllib2.urlopen("http://www.python.org", timeout=None)
+        u = _urlopen_with_retry("http://www.python.org", timeout=None)
         self.assertTrue(u.fp.raw.fp._sock.gettimeout() is None)
 
+    FTP_HOST = "ftp://ftp.mirror.nl/pub/mirror/gnu/"
+
     def test_ftp_basic(self):
-        u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/")
+        u = _urlopen_with_retry(self.FTP_HOST)
         self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
 
     def test_ftp_NoneWithdefault(self):
         prev = socket.getdefaulttimeout()
         socket.setdefaulttimeout(60)
         try:
-            u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/",
-                                timeout=None)
+            u = _urlopen_with_retry(self.FTP_HOST, timeout=None)
             self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)
         finally:
             socket.setdefaulttimeout(prev)
 
     def test_ftp_NoneNodefault(self):
-        u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/",
-                            timeout=None)
+        u = _urlopen_with_retry(self.FTP_HOST, timeout=None)
         self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
 
     def test_ftp_Value(self):
-        u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/", timeout=60)
+        u = _urlopen_with_retry(self.FTP_HOST, timeout=60)
         self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)
 
 

Modified: python/branches/py3k-importlib/Lib/test/test_urllibnet.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_urllibnet.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_urllibnet.py	Thu Mar 27 00:48:05 2008
@@ -9,6 +9,22 @@
 import os
 import mimetools
 
+
+def _open_with_retry(func, host, *args, **kwargs):
+    # Connecting to remote hosts is flaky.  Make it more robust
+    # by retrying the connection several times.
+    last_exc = None
+    for i in range(3):
+        try:
+            return func(host, *args, **kwargs)
+        except IOError as err:
+            last_exc = err
+            continue
+        except:
+            raise
+    raise last_exc
+
+
 class URLTimeoutTest(unittest.TestCase):
 
     TIMEOUT = 10.0
@@ -20,7 +36,7 @@
         socket.setdefaulttimeout(None)
 
     def testURLread(self):
-        f = urllib.urlopen("http://www.python.org/")
+        f = _open_with_retry(urllib.urlopen, "http://www.python.org/")
         x = f.read()
 
 class urlopenNetworkTests(unittest.TestCase):
@@ -38,9 +54,12 @@
 
     """
 
+    def urlopen(self, *args):
+        return _open_with_retry(urllib.urlopen, *args)
+
     def test_basic(self):
         # Simple test expected to pass.
-        open_url = urllib.urlopen("http://www.python.org/")
+        open_url = self.urlopen("http://www.python.org/")
         for attr in ("read", "readline", "readlines", "fileno", "close",
                      "info", "geturl"):
             self.assert_(hasattr(open_url, attr), "object returned from "
@@ -52,7 +71,7 @@
 
     def test_readlines(self):
         # Test both readline and readlines.
-        open_url = urllib.urlopen("http://www.python.org/")
+        open_url = self.urlopen("http://www.python.org/")
         try:
             self.assert_(isinstance(open_url.readline(), bytes),
                          "readline did not return bytes")
@@ -63,7 +82,7 @@
 
     def test_info(self):
         # Test 'info'.
-        open_url = urllib.urlopen("http://www.python.org/")
+        open_url = self.urlopen("http://www.python.org/")
         try:
             info_obj = open_url.info()
         finally:
@@ -76,13 +95,23 @@
     def test_geturl(self):
         # Make sure same URL as opened is returned by geturl.
         URL = "http://www.python.org/"
-        open_url = urllib.urlopen(URL)
+        open_url = self.urlopen(URL)
         try:
             gotten_url = open_url.geturl()
         finally:
             open_url.close()
         self.assertEqual(gotten_url, URL)
 
+    def test_getcode(self):
+        # test getcode() with the fancy opener to get 404 error codes
+        URL = "http://www.python.org/XXXinvalidXXX"
+        open_url = urllib.FancyURLopener().open(URL)
+        try:
+            code = open_url.getcode()
+        finally:
+            open_url.close()
+        self.assertEqual(code, 404)
+
     def test_fileno(self):
         if (sys.platform in ('win32',) or
                 not hasattr(os, 'fdopen')):
@@ -90,7 +119,7 @@
             # test can't pass on Windows.
             return
         # Make sure fd returned by fileno is valid.
-        open_url = urllib.urlopen("http://www.python.org/")
+        open_url = self.urlopen("http://www.python.org/")
         fd = open_url.fileno()
         FILE = os.fdopen(fd)
         try:
@@ -115,9 +144,12 @@
 class urlretrieveNetworkTests(unittest.TestCase):
     """Tests urllib.urlretrieve using the network."""
 
+    def urlretrieve(self, *args):
+        return _open_with_retry(urllib.urlretrieve, *args)
+
     def test_basic(self):
         # Test basic functionality.
-        file_location,info = urllib.urlretrieve("http://www.python.org/")
+        file_location,info = self.urlretrieve("http://www.python.org/")
         self.assert_(os.path.exists(file_location), "file location returned by"
                         " urlretrieve is not a valid path")
         FILE = open(file_location)
@@ -130,8 +162,8 @@
 
     def test_specified_path(self):
         # Make sure that specifying the location of the file to write to works.
-        file_location,info = urllib.urlretrieve("http://www.python.org/",
-                                                test_support.TESTFN)
+        file_location,info = self.urlretrieve("http://www.python.org/",
+                                              test_support.TESTFN)
         self.assertEqual(file_location, test_support.TESTFN)
         self.assert_(os.path.exists(file_location))
         FILE = open(file_location)
@@ -143,7 +175,7 @@
 
     def test_header(self):
         # Make sure header returned as 2nd value from urlretrieve is good.
-        file_location, header = urllib.urlretrieve("http://www.python.org/")
+        file_location, header = self.urlretrieve("http://www.python.org/")
         os.unlink(file_location)
         self.assert_(isinstance(header, mimetools.Message),
                      "header is not an instance of mimetools.Message")

Modified: python/branches/py3k-importlib/Lib/test/test_urlparse.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_urlparse.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_urlparse.py	Thu Mar 27 00:48:05 2008
@@ -254,6 +254,24 @@
         self.assertEqual(p.port, 80)
         self.assertEqual(p.geturl(), url)
 
+        # Addressing issue1698, which suggests Username can contain
+        # "@" characters.  Though not RFC compliant, many ftp sites allow
+        # and request email addresses as usernames.
+
+        url = "http://User@example.com:Pass@www.python.org:080/doc/?query=yes#frag"
+        p = urlparse.urlsplit(url)
+        self.assertEqual(p.scheme, "http")
+        self.assertEqual(p.netloc, "User at example.com:Pass at www.python.org:080")
+        self.assertEqual(p.path, "/doc/")
+        self.assertEqual(p.query, "query=yes")
+        self.assertEqual(p.fragment, "frag")
+        self.assertEqual(p.username, "User at example.com")
+        self.assertEqual(p.password, "Pass")
+        self.assertEqual(p.hostname, "www.python.org")
+        self.assertEqual(p.port, 80)
+        self.assertEqual(p.geturl(), url)
+
+
     def test_attributes_bad_port(self):
         """Check handling of non-integer ports."""
         p = urlparse.urlsplit("http://www.example.net:foo")
@@ -287,6 +305,10 @@
         self.assertEqual(p.port, None)
         self.assertEqual(p.geturl(), uri)
 
+    def test_noslash(self):
+        # Issue 1637: http://foo.com?query is legal
+        self.assertEqual(urlparse.urlparse("http://example.com?blahblah=/foo"),
+                         ('http', 'example.com', '', '', 'blahblah=/foo', ''))
 
 def test_main():
     test_support.run_unittest(UrlParseTestCase)

Modified: python/branches/py3k-importlib/Lib/test/test_userdict.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_userdict.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_userdict.py	Thu Mar 27 00:48:05 2008
@@ -1,8 +1,7 @@
 # Check every path through every method of UserDict
 
-import unittest
 from test import test_support, mapping_tests
-import UserDict
+import collections
 
 d0 = {}
 d1 = {"one": 1}
@@ -12,36 +11,36 @@
 d5 = {"one": 1, "two": 1}
 
 class UserDictTest(mapping_tests.TestHashMappingProtocol):
-    type2test = UserDict.IterableUserDict
+    type2test = collections.UserDict
 
     def test_all(self):
         # Test constructors
-        u = UserDict.UserDict()
-        u0 = UserDict.UserDict(d0)
-        u1 = UserDict.UserDict(d1)
-        u2 = UserDict.IterableUserDict(d2)
-
-        uu = UserDict.UserDict(u)
-        uu0 = UserDict.UserDict(u0)
-        uu1 = UserDict.UserDict(u1)
-        uu2 = UserDict.UserDict(u2)
+        u = collections.UserDict()
+        u0 = collections.UserDict(d0)
+        u1 = collections.UserDict(d1)
+        u2 = collections.UserDict(d2)
+
+        uu = collections.UserDict(u)
+        uu0 = collections.UserDict(u0)
+        uu1 = collections.UserDict(u1)
+        uu2 = collections.UserDict(u2)
 
         # keyword arg constructor
-        self.assertEqual(UserDict.UserDict(one=1, two=2), d2)
+        self.assertEqual(collections.UserDict(one=1, two=2), d2)
         # item sequence constructor
-        self.assertEqual(UserDict.UserDict([('one',1), ('two',2)]), d2)
-        self.assertEqual(UserDict.UserDict(dict=[('one',1), ('two',2)]), d2)
+        self.assertEqual(collections.UserDict([('one',1), ('two',2)]), d2)
+        self.assertEqual(collections.UserDict(dict=[('one',1), ('two',2)]), d2)
         # both together
-        self.assertEqual(UserDict.UserDict([('one',1), ('two',2)], two=3, three=5), d3)
+        self.assertEqual(collections.UserDict([('one',1), ('two',2)], two=3, three=5), d3)
 
         # alternate constructor
-        self.assertEqual(UserDict.UserDict.fromkeys('one two'.split()), d4)
-        self.assertEqual(UserDict.UserDict().fromkeys('one two'.split()), d4)
-        self.assertEqual(UserDict.UserDict.fromkeys('one two'.split(), 1), d5)
-        self.assertEqual(UserDict.UserDict().fromkeys('one two'.split(), 1), d5)
+        self.assertEqual(collections.UserDict.fromkeys('one two'.split()), d4)
+        self.assertEqual(collections.UserDict().fromkeys('one two'.split()), d4)
+        self.assertEqual(collections.UserDict.fromkeys('one two'.split(), 1), d5)
+        self.assertEqual(collections.UserDict().fromkeys('one two'.split(), 1), d5)
         self.assert_(u1.fromkeys('one two'.split()) is not u1)
-        self.assert_(isinstance(u1.fromkeys('one two'.split()), UserDict.UserDict))
-        self.assert_(isinstance(u2.fromkeys('one two'.split()), UserDict.IterableUserDict))
+        self.assert_(isinstance(u1.fromkeys('one two'.split()), collections.UserDict))
+        self.assert_(isinstance(u2.fromkeys('one two'.split()), collections.UserDict))
 
         # Test __repr__
         self.assertEqual(str(u0), str(d0))
@@ -59,7 +58,7 @@
         self.assertRaises(KeyError, u1.__getitem__, "two")
 
         # Test __setitem__
-        u3 = UserDict.UserDict(u2)
+        u3 = collections.UserDict(u2)
         u3["two"] = 2
         u3["three"] = 3
 
@@ -74,11 +73,11 @@
         # Test copy()
         u2a = u2.copy()
         self.assertEqual(u2a, u2)
-        u2b = UserDict.UserDict(x=42, y=23)
+        u2b = collections.UserDict(x=42, y=23)
         u2c = u2b.copy() # making a copy of a UserDict is special cased
         self.assertEqual(u2b, u2c)
 
-        class MyUserDict(UserDict.UserDict):
+        class MyUserDict(collections.UserDict):
             def display(self): print(self)
 
         m2 = MyUserDict(u2)
@@ -101,15 +100,9 @@
             self.assertEqual(i in u0, i in d0)
 
         # Test update
-        t = UserDict.UserDict()
+        t = collections.UserDict()
         t.update(u2)
         self.assertEqual(t, u2)
-        class Items:
-            def items(self):
-                return (("x", 42), ("y", 23))
-        t = UserDict.UserDict()
-        t.update(Items())
-        self.assertEqual(t, {"x": 42, "y": 23})
 
         # Test get
         for i in u2.keys():
@@ -127,13 +120,13 @@
         self.assertEqual(set(ikeys), set(keys))
 
         # Test setdefault
-        t = UserDict.UserDict()
+        t = collections.UserDict()
         self.assertEqual(t.setdefault("x", 42), 42)
         self.assert_("x" in t)
         self.assertEqual(t.setdefault("x", 23), 42)
 
         # Test pop
-        t = UserDict.UserDict(x=42)
+        t = collections.UserDict(x=42)
         self.assertEqual(t.pop("x"), 42)
         self.assertRaises(KeyError, t.pop, "x")
         self.assertEqual(t.pop("x", 1), 1)
@@ -141,19 +134,19 @@
         self.assertEqual(t.pop("x", 1), 42)
 
         # Test popitem
-        t = UserDict.UserDict(x=42)
+        t = collections.UserDict(x=42)
         self.assertEqual(t.popitem(), ("x", 42))
         self.assertRaises(KeyError, t.popitem)
 
     def test_missing(self):
         # Make sure UserDict doesn't have a __missing__ method
-        self.assertEqual(hasattr(UserDict, "__missing__"), False)
+        self.assertEqual(hasattr(collections.UserDict, "__missing__"), False)
         # Test several cases:
         # (D) subclass defines __missing__ method returning a value
         # (E) subclass defines __missing__ method raising RuntimeError
         # (F) subclass sets __missing__ instance variable (no effect)
         # (G) subclass doesn't define __missing__ at a all
-        class D(UserDict.UserDict):
+        class D(collections.UserDict):
             def __missing__(self, key):
                 return 42
         d = D({1: 2, 3: 4})
@@ -162,7 +155,7 @@
         self.assert_(2 not in d)
         self.assert_(2 not in d.keys())
         self.assertEqual(d[2], 42)
-        class E(UserDict.UserDict):
+        class E(collections.UserDict):
             def __missing__(self, key):
                 raise RuntimeError(key)
         e = E()
@@ -172,11 +165,11 @@
             self.assertEqual(err.args, (42,))
         else:
             self.fail("e[42] didn't raise RuntimeError")
-        class F(UserDict.UserDict):
+        class F(collections.UserDict):
             def __init__(self):
                 # An instance variable __missing__ should have no effect
                 self.__missing__ = lambda key: None
-                UserDict.UserDict.__init__(self)
+                collections.UserDict.__init__(self)
         f = F()
         try:
             f[42]
@@ -184,7 +177,7 @@
             self.assertEqual(err.args, (42,))
         else:
             self.fail("f[42] didn't raise KeyError")
-        class G(UserDict.UserDict):
+        class G(collections.UserDict):
             pass
         g = G()
         try:
@@ -194,150 +187,11 @@
         else:
             self.fail("g[42] didn't raise KeyError")
 
-##########################
-# Test Dict Mixin
 
-class SeqDict(UserDict.DictMixin):
-    """Dictionary lookalike implemented with lists.
-
-    Used to test and demonstrate DictMixin
-    """
-    def __init__(self, other=None, **kwargs):
-        self.keylist = []
-        self.valuelist = []
-        if other is not None:
-            for (key, value) in other:
-                self[key] = value
-        for (key, value) in kwargs.items():
-            self[key] = value
-    def __getitem__(self, key):
-        try:
-            i = self.keylist.index(key)
-        except ValueError:
-            raise KeyError
-        return self.valuelist[i]
-    def __setitem__(self, key, value):
-        try:
-            i = self.keylist.index(key)
-            self.valuelist[i] = value
-        except ValueError:
-            self.keylist.append(key)
-            self.valuelist.append(value)
-    def __delitem__(self, key):
-        try:
-            i = self.keylist.index(key)
-        except ValueError:
-            raise KeyError
-        self.keylist.pop(i)
-        self.valuelist.pop(i)
-    def keys(self):
-        return list(self.keylist)
-    def copy(self):
-        d = self.__class__()
-        for key, value in self.items():
-            d[key] = value
-        return d
-    @classmethod
-    def fromkeys(cls, keys, value=None):
-        d = cls()
-        for key in keys:
-            d[key] = value
-        return d
-
-class UserDictMixinTest(mapping_tests.TestMappingProtocol):
-    type2test = SeqDict
-
-    def test_all(self):
-        ## Setup test and verify working of the test class
-
-        # check init
-        s = SeqDict()
-
-        # exercise setitem
-        s[10] = 'ten'
-        s[20] = 'twenty'
-        s[30] = 'thirty'
-
-        # exercise delitem
-        del s[20]
-        # check getitem and setitem
-        self.assertEqual(s[10], 'ten')
-        # check keys() and delitem
-        self.assertEqual(s.keys(), [10, 30])
-
-        ## Now, test the DictMixin methods one by one
-
-        # __contains__
-        self.assert_(10 in s)
-        self.assert_(20 not in s)
-
-        # __iter__
-        self.assertEqual([k for k in s], [10, 30])
-
-        # __len__
-        self.assertEqual(len(s), 2)
-
-        # iteritems
-        self.assertEqual(list(s.items()), [(10,'ten'), (30, 'thirty')])
-
-        # iterkeys
-        self.assertEqual(list(s.keys()), [10, 30])
-
-        # itervalues
-        self.assertEqual(list(s.values()), ['ten', 'thirty'])
-
-        # values
-        self.assertEqual(s.values(), ['ten', 'thirty'])
-
-        # items
-        self.assertEqual(s.items(), [(10,'ten'), (30, 'thirty')])
-
-        # get
-        self.assertEqual(s.get(10), 'ten')
-        self.assertEqual(s.get(15,'fifteen'), 'fifteen')
-        self.assertEqual(s.get(15), None)
-
-        # setdefault
-        self.assertEqual(s.setdefault(40, 'forty'), 'forty')
-        self.assertEqual(s.setdefault(10, 'null'), 'ten')
-        del s[40]
-
-        # pop
-        self.assertEqual(s.pop(10), 'ten')
-        self.assert_(10 not in s)
-        s[10] = 'ten'
-        self.assertEqual(s.pop("x", 1), 1)
-        s["x"] = 42
-        self.assertEqual(s.pop("x", 1), 42)
-
-        # popitem
-        k, v = s.popitem()
-        self.assert_(k not in s)
-        s[k] = v
-
-        # clear
-        s.clear()
-        self.assertEqual(len(s), 0)
-
-        # empty popitem
-        self.assertRaises(KeyError, s.popitem)
-
-        # update
-        s.update({10: 'ten', 20:'twenty'})
-        self.assertEqual(s[10], 'ten')
-        self.assertEqual(s[20], 'twenty')
-
-        # cmp
-        self.assertEqual(s, {10: 'ten', 20:'twenty'})
-        t = SeqDict()
-        t[20] = 'twenty'
-        t[10] = 'ten'
-        self.assertEqual(s, t)
 
 def test_main():
     test_support.run_unittest(
         UserDictTest,
-        UserDictMixinTest
     )
 
 if __name__ == "__main__":

Modified: python/branches/py3k-importlib/Lib/test/test_userlist.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_userlist.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_userlist.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Check every path through every method of UserList
 
-from UserList import UserList
-import unittest
+from collections import UserList
 from test import test_support, list_tests
 
 class UserListTest(list_tests.CommonTest):

Modified: python/branches/py3k-importlib/Lib/test/test_userstring.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_userstring.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_userstring.py	Thu Mar 27 00:48:05 2008
@@ -2,11 +2,10 @@
 # UserString is a wrapper around the native builtin string type.
 # UserString instances should behave similar to builtin string objects.
 
-import unittest
 import string
 from test import test_support, string_tests
 
-from UserString import UserString, MutableString
+from collections import UserString
 
 class UserStringTest(
     string_tests.CommonTest,
@@ -42,99 +41,9 @@
         # we don't fix the arguments, because UserString can't cope with it
         getattr(object, methodname)(*args)
 
-class MutableStringTest(UserStringTest):
-    type2test = MutableString
-
-    # MutableStrings can be hashed => deactivate test
-    def test_hash(self):
-        pass
-
-    def test_setitem(self):
-        s = self.type2test("foo")
-        self.assertRaises(IndexError, s.__setitem__, -4, "bar")
-        self.assertRaises(IndexError, s.__setitem__, 3, "bar")
-        s[-1] = "bar"
-        self.assertEqual(s, "fobar")
-        s[0] = "bar"
-        self.assertEqual(s, "barobar")
-
-    def test_delitem(self):
-        s = self.type2test("foo")
-        self.assertRaises(IndexError, s.__delitem__, -4)
-        self.assertRaises(IndexError, s.__delitem__, 3)
-        del s[-1]
-        self.assertEqual(s, "fo")
-        del s[0]
-        self.assertEqual(s, "o")
-        del s[0]
-        self.assertEqual(s, "")
-
-    def test_setslice(self):
-        s = self.type2test("foo")
-        s[:] = "bar"
-        self.assertEqual(s, "bar")
-        s[1:2] = "foo"
-        self.assertEqual(s, "bfoor")
-        s[1:-1] = UserString("a")
-        self.assertEqual(s, "bar")
-        s[0:10] = 42
-        self.assertEqual(s, "42")
-
-    def test_delslice(self):
-        s = self.type2test("foobar")
-        del s[3:10]
-        self.assertEqual(s, "foo")
-        del s[-1:10]
-        self.assertEqual(s, "fo")
-
-    def test_extended_set_del_slice(self):
-        indices = (0, None, 1, 3, 19, 100, -1, -2, -31, -100)
-        orig = string.ascii_letters + string.digits
-        for start in indices:
-            for stop in indices:
-                # Use indices[1:] when MutableString can handle real
-                # extended slices
-                for step in (None, 1, -1):
-                    s = self.type2test(orig)
-                    L = list(orig)
-                    # Make sure we have a slice of exactly the right length,
-                    # but with (hopefully) different data.
-                    data = L[start:stop:step]
-                    data.reverse()
-                    L[start:stop:step] = data
-                    s[start:stop:step] = "".join(data)
-                    self.assertEquals(s, "".join(L))
-
-                    del L[start:stop:step]
-                    del s[start:stop:step]
-                    self.assertEquals(s, "".join(L))
-
-    def test_immutable(self):
-        s = self.type2test("foobar")
-        s2 = s.immutable()
-        self.assertEqual(s, s2)
-        self.assert_(isinstance(s2, UserString))
-
-    def test_iadd(self):
-        s = self.type2test("foo")
-        s += "bar"
-        self.assertEqual(s, "foobar")
-        s += UserString("baz")
-        self.assertEqual(s, "foobarbaz")
-        s += 42
-        self.assertEqual(s, "foobarbaz42")
-
-    def test_imul(self):
-        s = self.type2test("foo")
-        s *= 1
-        self.assertEqual(s, "foo")
-        s *= 2
-        self.assertEqual(s, "foofoo")
-        s *= -1
-        self.assertEqual(s, "")
 
 def test_main():
-    test_support.run_unittest(UserStringTest, MutableStringTest)
+    test_support.run_unittest(UserStringTest)
 
 if __name__ == "__main__":
     test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_warnings.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_warnings.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_warnings.py	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,7 @@
 import warnings
+import linecache
 import os
+from io import StringIO
 import sys
 import unittest
 from test import test_support
@@ -36,6 +38,8 @@
                     self.assert_(w.category is category)
 
     def test_filtering(self):
+        # Test filterwarnings().
+        # Implicitly also tests resetwarnings().
         with test_support.catch_warning() as w:
             warnings.filterwarnings("error", "", Warning, "", 0)
             self.assertRaises(UserWarning, warnings.warn, 'convert to error')
@@ -97,6 +101,33 @@
             self.assertEqual(os.path.basename(w.filename), "sys")
 
 
+class WarningsDisplayTests(unittest.TestCase):
+
+    def test_formatwarning(self):
+        message = "msg"
+        category = Warning
+        file_name = os.path.splitext(warning_tests.__file__)[0] + '.py'
+        line_num = 3
+        file_line = linecache.getline(file_name, line_num).strip()
+        expect = "%s:%s: %s: %s\n  %s\n" % (file_name, line_num, category.__name__,
+                                         message, file_line)
+        self.failUnlessEqual(warnings.formatwarning(message, category,
+                                                    file_name, line_num),
+                             expect)
+
+    def test_showwarning(self):
+        file_name = os.path.splitext(warning_tests.__file__)[0] + '.py'
+        line_num = 3
+        expected_file_line = linecache.getline(file_name, line_num).strip()
+        message = 'msg'
+        category = Warning
+        file_object = StringIO()
+        expect = warnings.formatwarning(message, category, file_name, line_num)
+        warnings.showwarning(message, category, file_name, line_num,
+                                file_object)
+        self.failUnlessEqual(file_object.getvalue(), expect)
+
+
 def test_main(verbose=None):
     # Obscure hack so that this test passes after reloads or repeated calls
     # to test_main (regrtest -R).
@@ -106,7 +137,7 @@
         del warning_tests.__warningregistry__
     if hasattr(sys, '__warningregistry__'):
         del sys.__warningregistry__
-    test_support.run_unittest(TestModule)
+    test_support.run_unittest(TestModule, WarningsDisplayTests)
 
 if __name__ == "__main__":
     test_main(verbose=True)

Modified: python/branches/py3k-importlib/Lib/test/test_wave.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_wave.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_wave.py	Thu Mar 27 00:48:05 2008
@@ -1,32 +1,45 @@
-from test.test_support import TestFailed, TESTFN
+from test.test_support import TESTFN, run_unittest
 import os
 import wave
-
-def check(t, msg=None):
-    if not t:
-        raise TestFailed(msg)
+import unittest
 
 nchannels = 2
 sampwidth = 2
 framerate = 8000
 nframes = 100
 
-f = wave.open(TESTFN, 'wb')
-f.setnchannels(nchannels)
-f.setsampwidth(sampwidth)
-f.setframerate(framerate)
-f.setnframes(nframes)
-output = b'\0' * nframes * nchannels * sampwidth
-f.writeframes(output)
-f.close()
-
-f = wave.open(TESTFN, 'rb')
-check(nchannels == f.getnchannels(), "nchannels")
-check(sampwidth == f.getsampwidth(), "sampwidth")
-check(framerate == f.getframerate(), "framerate")
-check(nframes == f.getnframes(), "nframes")
-input = f.readframes(nframes)
-check(input == output, "data")
-f.close()
+class TestWave(unittest.TestCase):
+
+    def setUp(self):
+        self.f = None
+
+    def tearDown(self):
+        if self.f is not None:
+            self.f.close()
+        try:
+            os.remove(TESTFN)
+        except OSError:
+            pass
+
+    def test_it(self):
+        self.f = wave.open(TESTFN, 'wb')
+        self.f.setnchannels(nchannels)
+        self.f.setsampwidth(sampwidth)
+        self.f.setframerate(framerate)
+        self.f.setnframes(nframes)
+        output = b'\0' * nframes * nchannels * sampwidth
+        self.f.writeframes(output)
+        self.f.close()
+
+        self.f = wave.open(TESTFN, 'rb')
+        self.assertEqual(nchannels, self.f.getnchannels())
+        self.assertEqual(sampwidth, self.f.getsampwidth())
+        self.assertEqual(framerate, self.f.getframerate())
+        self.assertEqual(nframes, self.f.getnframes())
+        self.assertEqual(self.f.readframes(nframes), output)
+
+def test_main():
+    run_unittest(TestWave)
 
-os.remove(TESTFN)
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_weakref.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_weakref.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_weakref.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,7 @@
 import gc
 import sys
 import unittest
-import UserList
+import collections
 import weakref
 
 from test import test_support
@@ -28,9 +28,6 @@
 def create_bound_method():
     return C().method
 
-def create_unbound_method():
-    return C.method
-
 
 class TestBase(unittest.TestCase):
 
@@ -47,7 +44,6 @@
         self.check_basic_ref(C)
         self.check_basic_ref(create_function)
         self.check_basic_ref(create_bound_method)
-        self.check_basic_ref(create_unbound_method)
 
         # Just make sure the tp_repr handler doesn't raise an exception.
         # Live reference:
@@ -62,7 +58,6 @@
         self.check_basic_callback(C)
         self.check_basic_callback(create_function)
         self.check_basic_callback(create_bound_method)
-        self.check_basic_callback(create_unbound_method)
 
     def test_multiple_callbacks(self):
         o = C()
@@ -162,7 +157,7 @@
         o = C()
         self.check_proxy(o, weakref.proxy(o))
 
-        L = UserList.UserList()
+        L = collections.UserList()
         p = weakref.proxy(L)
         self.failIf(p, "proxy for empty UserList should be false")
         p.append(12)
@@ -176,11 +171,11 @@
         p[1] = 5
         self.assertEqual(L[1], 5)
         self.assertEqual(p[1], 5)
-        L2 = UserList.UserList(L)
+        L2 = collections.UserList(L)
         p2 = weakref.proxy(L2)
         self.assertEqual(p, p2)
         ## self.assertEqual(repr(L2), repr(p2))
-        L3 = UserList.UserList(range(10))
+        L3 = collections.UserList(range(10))
         p3 = weakref.proxy(L3)
         self.assertEqual(L3[:], p3[:])
         self.assertEqual(L3[5:], p3[5:])

Modified: python/branches/py3k-importlib/Lib/test/test_whichdb.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_whichdb.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_whichdb.py	Thu Mar 27 00:48:05 2008
@@ -8,7 +8,6 @@
 import unittest
 import whichdb
 import anydbm
-import tempfile
 import glob
 from test.test_anydbm import delete_files, dbm_iterator
 

Modified: python/branches/py3k-importlib/Lib/test/test_winreg.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_winreg.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_winreg.py	Thu Mar 27 00:48:05 2008
@@ -73,26 +73,26 @@
 
         key = OpenKey(root_key, test_key_name)
         # Read the sub-keys
-        sub_key = OpenKey(key, subkeystr)
-        # Check I can enumerate over the values.
-        index = 0
-        while 1:
-            try:
-                data = EnumValue(sub_key, index)
-            except EnvironmentError:
-                break
-            self.assertEquals(data in test_data, True,
-                              "Didn't read back the correct test data")
-            index = index + 1
-        self.assertEquals(index, len(test_data),
-                          "Didn't read the correct number of items")
-        # Check I can directly access each item
-        for value_name, value_data, value_type in test_data:
-            read_val, read_typ = QueryValueEx(sub_key, value_name)
-            self.assertEquals(read_val, value_data,
-                              "Could not directly read the value")
-            self.assertEquals(read_typ, value_type,
-                              "Could not directly read the value")
+        with OpenKey(key, subkeystr) as sub_key:
+            # Check I can enumerate over the values.
+            index = 0
+            while 1:
+                try:
+                    data = EnumValue(sub_key, index)
+                except EnvironmentError:
+                    break
+                self.assertEquals(data in test_data, True,
+                                  "Didn't read back the correct test data")
+                index = index + 1
+            self.assertEquals(index, len(test_data),
+                              "Didn't read the correct number of items")
+            # Check I can directly access each item
+            for value_name, value_data, value_type in test_data:
+                read_val, read_typ = QueryValueEx(sub_key, value_name)
+                self.assertEquals(read_val, value_data,
+                                  "Could not directly read the value")
+                self.assertEquals(read_typ, value_type,
+                                  "Could not directly read the value")
         sub_key.Close()
         # Enumerate our main key.
         read_val = EnumKey(key, 0)
@@ -155,6 +155,11 @@
         remote_key = ConnectRegistry(self.remote_name, HKEY_CURRENT_USER)
         self.TestAll(remote_key)
 
+    def testExpandEnvironmentStrings(self):
+        r = ExpandEnvironmentStrings("%windir%\\test")
+        self.assertEqual(type(r), str)
+        self.assertEqual(r, os.environ["windir"] + "\\test")
+
 def test_main():
     test_support.run_unittest(WinregTests)
 

Modified: python/branches/py3k-importlib/Lib/test/test_winsound.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_winsound.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_winsound.py	Thu Mar 27 00:48:05 2008
@@ -2,12 +2,20 @@
 
 import unittest
 from test import test_support
+test_support.requires('audio')
 import winsound, time
 import os
 import subprocess
 
 
 class BeepTest(unittest.TestCase):
+    # As with PlaySoundTest, incorporate the _have_soundcard() check
+    # into our test methods.  If there's no audio device present,
+    # winsound.Beep returns 0 and GetLastError() returns 127, which
+    # is: ERROR_PROC_NOT_FOUND ("The specified procedure could not
+    # be found").  (FWIW, virtual/Hyper-V systems fall under this
+    # scenario as they have no sound devices whatsoever  (not even
+    # a legacy Beep device).)
 
     def test_errors(self):
         self.assertRaises(TypeError, winsound.Beep)
@@ -15,12 +23,27 @@
         self.assertRaises(ValueError, winsound.Beep, 32768, 75)
 
     def test_extremes(self):
-        winsound.Beep(37, 75)
-        winsound.Beep(32767, 75)
+        self._beep(37, 75)
+        self._beep(32767, 75)
 
     def test_increasingfrequency(self):
         for i in range(100, 2000, 100):
-            winsound.Beep(i, 75)
+            self._beep(i, 75)
+
+    def _beep(self, *args):
+        # these tests used to use _have_soundcard(), but it's quite
+        # possible to have a soundcard, and yet have the beep driver
+        # disabled. So basically, we have no way of knowing whether
+        # a beep should be produced or not, so currently if these
+        # tests fail we're ignoring them
+        #
+        # XXX the right fix for this is to define something like
+        # _have_enabled_beep_driver() and use that instead of the
+        # try/except below
+        try:
+            winsound.Beep(*args)
+        except RuntimeError:
+            pass
 
 class MessageBeepTest(unittest.TestCase):
 

Modified: python/branches/py3k-importlib/Lib/test/test_with.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_with.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_with.py	Thu Mar 27 00:48:05 2008
@@ -442,6 +442,7 @@
         self.assertAfterWithGeneratorInvariantsNoError(self.bar)
 
     def testRaisedStopIteration1(self):
+        # From bug 1462485
         @contextmanager
         def cm():
             yield
@@ -453,6 +454,7 @@
         self.assertRaises(StopIteration, shouldThrow)
 
     def testRaisedStopIteration2(self):
+        # From bug 1462485
         class cm(object):
             def __enter__(self):
                 pass
@@ -465,7 +467,21 @@
 
         self.assertRaises(StopIteration, shouldThrow)
 
+    def testRaisedStopIteration3(self):
+        # Another variant where the exception hasn't been instantiated
+        # From bug 1705170
+        @contextmanager
+        def cm():
+            yield
+
+        def shouldThrow():
+            with cm():
+                raise next(iter([]))
+
+        self.assertRaises(StopIteration, shouldThrow)
+
     def testRaisedGeneratorExit1(self):
+        # From bug 1462485
         @contextmanager
         def cm():
             yield
@@ -477,6 +493,7 @@
         self.assertRaises(GeneratorExit, shouldThrow)
 
     def testRaisedGeneratorExit2(self):
+        # From bug 1462485
         class cm (object):
             def __enter__(self):
                 pass

Modified: python/branches/py3k-importlib/Lib/test/test_xml_etree.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_xml_etree.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_xml_etree.py	Thu Mar 27 00:48:05 2008
@@ -2,7 +2,8 @@
 # all included components work as they should.  For a more extensive
 # test suite, see the selftest script in the ElementTree distribution.
 
-import doctest, sys
+import doctest
+import sys
 
 from test import test_support
 
@@ -184,7 +185,7 @@
     >>> print(ET.tostring(element))
     <html><body>text</body></html>
     >>> print(repr(ET.tostring(element, "ascii")))
-    b'<?xml version=\'1.0\' encoding=\'ascii\'?>\n<html><body>text</body></html>'
+    b"<?xml version='1.0' encoding='ascii'?>\n<html><body>text</body></html>"
     >>> _, ids = ET.XMLID("<html><body>text</body></html>")
     >>> len(ids)
     0

Modified: python/branches/py3k-importlib/Lib/test/test_xml_etree_c.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_xml_etree_c.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_xml_etree_c.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,7 @@
 # xml.etree test for cElementTree
 
-import doctest, sys
+import doctest
+import sys
 
 from test import test_support
 
@@ -176,7 +177,7 @@
     >>> print(ET.tostring(element))
     <html><body>text</body></html>
     >>> print(repr(ET.tostring(element, "ascii")))
-    b'<?xml version=\'1.0\' encoding=\'ascii\'?>\n<html><body>text</body></html>'
+    b"<?xml version='1.0' encoding='ascii'?>\n<html><body>text</body></html>"
     >>> _, ids = ET.XMLID("<html><body>text</body></html>")
     >>> len(ids)
     0

Modified: python/branches/py3k-importlib/Lib/test/test_xmlrpc.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_xmlrpc.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_xmlrpc.py	Thu Mar 27 00:48:05 2008
@@ -7,6 +7,9 @@
 import SimpleXMLRPCServer
 import threading
 import mimetools
+import httplib
+import socket
+import os
 from test import test_support
 
 alist = [{'astring': 'foo at bar.baz.spam',
@@ -23,10 +26,6 @@
                         (2005, 2, 10, 11, 41, 23, 0, 1, -1)),
           'datetime3': xmlrpclib.DateTime(
                         datetime.datetime(2005, 2, 10, 11, 41, 23)),
-          'datetime4': xmlrpclib.DateTime(
-                        datetime.date(2005, 2, 10)),
-          'datetime5': xmlrpclib.DateTime(
-                        datetime.time(11, 41, 23)),
           }]
 
 class XMLRPCTestCase(unittest.TestCase):
@@ -50,34 +49,14 @@
         (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
         self.assertEquals(newdt, xmlrpclib.DateTime('20050210T11:41:23'))
 
-    def test_dump_bare_date(self):
-        # This checks that an unwrapped datetime.date object can be handled
-        # by the marshalling code.  This can't be done via test_dump_load()
-        # since the unmarshaller produces a datetime object
-        d = datetime.datetime(2005, 2, 10, 11, 41, 23).date()
-        s = xmlrpclib.dumps((d,))
-        (newd,), m = xmlrpclib.loads(s, use_datetime=1)
-        self.assertEquals(newd.date(), d)
-        self.assertEquals(newd.time(), datetime.time(0, 0, 0))
-        self.assertEquals(m, None)
-
-        (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
-        self.assertEquals(newdt, xmlrpclib.DateTime('20050210T00:00:00'))
-
-    def test_dump_bare_time(self):
-        # This checks that an unwrapped datetime.time object can be handled
-        # by the marshalling code.  This can't be done via test_dump_load()
-        # since the unmarshaller produces a datetime object
-        t = datetime.datetime(2005, 2, 10, 11, 41, 23).time()
-        s = xmlrpclib.dumps((t,))
-        (newt,), m = xmlrpclib.loads(s, use_datetime=1)
-        today = datetime.datetime.now().date().strftime("%Y%m%d")
-        self.assertEquals(newt.time(), t)
-        self.assertEquals(newt.date(), datetime.datetime.now().date())
-        self.assertEquals(m, None)
-
-        (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
-        self.assertEquals(newdt, xmlrpclib.DateTime('%sT11:41:23'%today))
+    def test_cmp_datetime_DateTime(self):
+        now = datetime.datetime.now()
+        dt = xmlrpclib.DateTime(now.timetuple())
+        self.assert_(dt == now)
+        self.assert_(now == dt)
+        then = now + datetime.timedelta(seconds=4)
+        self.assert_(then >= dt)
+        self.assert_(dt < then)
 
     def test_bug_1164912 (self):
         d = xmlrpclib.DateTime()
@@ -117,7 +96,7 @@
         self.assertRaises(TypeError, xmlrpclib.dumps, (d,))
 
     def test_dump_big_int(self):
-        if sys.maxint > 2**31-1:
+        if sys.maxsize > 2**31-1:
             self.assertRaises(OverflowError, xmlrpclib.dumps,
                               (int(2**34),))
 
@@ -166,6 +145,13 @@
         s = xmlrpclib.Marshaller().dumps(f)
         self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, s)
 
+    def test_dotted_attribute(self):
+        # this will raise AttirebuteError because code don't want us to use
+        # private methods
+        self.assertRaises(AttributeError,
+                          SimpleXMLRPCServer.resolve_dotted_attribute, str, '__add')
+
+        self.assert_(SimpleXMLRPCServer.resolve_dotted_attribute(str, 'title'))
 
 class DateTimeTestCase(unittest.TestCase):
     def test_default(self):
@@ -191,21 +177,6 @@
         t = xmlrpclib.DateTime(d)
         self.assertEqual(str(t), '20070102T03:04:05')
 
-    def test_datetime_date(self):
-        d = datetime.date(2007,9,8)
-        t = xmlrpclib.DateTime(d)
-        self.assertEqual(str(t), '20070908T00:00:00')
-
-    def test_datetime_time(self):
-        d = datetime.time(13,17,19)
-        # allow for date rollover by checking today's or tomorrow's dates
-        dd1 = datetime.datetime.now().date()
-        dd2 = dd1 + datetime.timedelta(days=1)
-        vals = (dd1.strftime('%Y%m%dT13:17:19'),
-                dd2.strftime('%Y%m%dT13:17:19'))
-        t = xmlrpclib.DateTime(d)
-        self.assertEqual(str(t) in vals, True)
-
     def test_repr(self):
         d = datetime.datetime(2007,1,2,3,4,5)
         t = xmlrpclib.DateTime(d)
@@ -251,16 +222,25 @@
 
 PORT = None
 
+# The evt is set twice.  First when the server is ready to serve.
+# Second when the server has been shutdown.  The user must clear
+# the event after it has been set the first time to catch the second set.
 def http_server(evt, numrequests):
     class TestInstanceClass:
         def div(self, x, y):
-            '''This is the div function'''
             return x // y
 
+        def _methodHelp(self, name):
+            if name == 'div':
+                return 'This is the div function'
+
+    def my_function():
+        '''This is my function'''
+        return True
+
     try:
         serv = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 0),
                         logRequests=False, bind_and_activate=False)
-        serv.socket.settimeout(3)
         serv.server_bind()
         global PORT
         PORT = serv.socket.getsockname()[1]
@@ -269,7 +249,9 @@
         serv.register_multicall_functions()
         serv.register_function(pow)
         serv.register_function(lambda x,y: x+y, 'add')
+        serv.register_function(my_function)
         serv.register_instance(TestInstanceClass())
+        evt.set()
 
         # handle up to 'numrequests' requests
         while numrequests > 0:
@@ -283,28 +265,25 @@
         PORT = None
         evt.set()
 
-
+# This function prevents errors like:
+#    <ProtocolError for localhost:57527/RPC2: 500 Internal Server Error>
 def is_unavailable_exception(e):
     '''Returns True if the given ProtocolError is the product of a server-side
        exception caused by the 'temporarily unavailable' response sometimes
        given by operations on non-blocking sockets.'''
+
     # sometimes we get a -1 error code and/or empty headers
-    if e.errcode == -1 or e.headers is None:
-        return True
+    try:
+        if e.errcode == -1 or e.headers is None:
+            return True
+        exc_mess = e.headers.get('X-exception')
+    except AttributeError:
+        # Ignore socket.errors here.
+        exc_mess = str(e)
 
-    exc_mess = e.headers.get('X-exception')
     if exc_mess and 'temporarily unavailable' in exc_mess.lower():
         return True
 
-    return False
-
-# NOTE: The tests in SimpleServerTestCase will ignore failures caused by
-# "temporarily unavailable" exceptions raised in SimpleXMLRPCServer.  This
-# condition occurs infrequently on some platforms, frequently on others, and
-# is apparently caused by using SimpleXMLRPCServer with a non-blocking socket.
-# If the server class is updated at some point in the future to handle this
-# situation more gracefully, these tests should be modified appropriately.
-
 class SimpleServerTestCase(unittest.TestCase):
     def setUp(self):
         # enable traceback reporting
@@ -315,17 +294,17 @@
         serv_args = (self.evt, 1)
         threading.Thread(target=http_server, args=serv_args).start()
 
-        # wait for port to be assigned to server
-        n = 1000
-        while n > 0 and PORT is None:
-            time.sleep(0.001)
-            n -= 1
-
-        time.sleep(0.5)
+        # wait for the server to be ready
+        self.evt.wait()
+        self.evt.clear()
 
     def tearDown(self):
         # wait on the server thread to terminate
-        self.evt.wait()
+        self.evt.wait(4.0)
+        if not self.evt.isSet():
+            self.evt.set()
+            stop_serving()
+            raise RuntimeError("timeout reached, test has failed")
 
         # disable traceback reporting
         SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = False
@@ -334,48 +313,75 @@
         try:
             p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
             self.assertEqual(p.pow(6,8), 6**8)
-        except xmlrpclib.ProtocolError as e:
+        except (xmlrpclib.ProtocolError, socket.error) as e:
             # ignore failures due to non-blocking socket 'unavailable' errors
             if not is_unavailable_exception(e):
                 # protocol error; provide additional information in test output
-                self.fail("%s\n%s" % (e, e.headers))
+                self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
+
+    # [ch] The test 404 is causing lots of false alarms.
+    def XXXtest_404(self):
+        # send POST with httplib, it should return 404 header and
+        # 'Not Found' message.
+        conn = httplib.HTTPConnection('localhost', PORT)
+        conn.request('POST', '/this-is-not-valid')
+        response = conn.getresponse()
+        conn.close()
+
+        self.assertEqual(response.status, 404)
+        self.assertEqual(response.reason, 'Not Found')
 
     def test_introspection1(self):
         try:
             p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
             meth = p.system.listMethods()
-            expected_methods = set(['pow', 'div', 'add', 'system.listMethods',
-                'system.methodHelp', 'system.methodSignature', 'system.multicall'])
+            expected_methods = set(['pow', 'div', 'my_function', 'add',
+                                    'system.listMethods', 'system.methodHelp',
+                                    'system.methodSignature', 'system.multicall'])
             self.assertEqual(set(meth), expected_methods)
-        except xmlrpclib.ProtocolError as e:
+        except (xmlrpclib.ProtocolError, socket.error) as e:
             # ignore failures due to non-blocking socket 'unavailable' errors
             if not is_unavailable_exception(e):
                 # protocol error; provide additional information in test output
-                self.fail("%s\n%s" % (e, e.headers))
+                self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
+
 
     def test_introspection2(self):
         try:
+            # test _methodHelp()
             p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
             divhelp = p.system.methodHelp('div')
             self.assertEqual(divhelp, 'This is the div function')
-        except xmlrpclib.ProtocolError as e:
+        except (xmlrpclib.ProtocolError, socket.error) as e:
             # ignore failures due to non-blocking socket 'unavailable' errors
             if not is_unavailable_exception(e):
                 # protocol error; provide additional information in test output
-                self.fail("%s\n%s" % (e, e.headers))
+                self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
 
     def test_introspection3(self):
+        try:
+            # test native doc
+            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+            myfunction = p.system.methodHelp('my_function')
+            self.assertEqual(myfunction, 'This is my function')
+        except (xmlrpclib.ProtocolError, socket.error) as e:
+            # ignore failures due to non-blocking socket 'unavailable' errors
+            if not is_unavailable_exception(e):
+                # protocol error; provide additional information in test output
+                self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
+
+    def test_introspection4(self):
         # the SimpleXMLRPCServer doesn't support signatures, but
         # at least check that we can try making the call
         try:
             p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
             divsig = p.system.methodSignature('div')
             self.assertEqual(divsig, 'signatures not supported')
-        except xmlrpclib.ProtocolError as e:
+        except (xmlrpclib.ProtocolError, socket.error) as e:
             # ignore failures due to non-blocking socket 'unavailable' errors
             if not is_unavailable_exception(e):
                 # protocol error; provide additional information in test output
-                self.fail("%s\n%s" % (e, e.headers))
+                self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
 
     def test_multicall(self):
         try:
@@ -388,12 +394,42 @@
             self.assertEqual(add_result, 2+3)
             self.assertEqual(pow_result, 6**8)
             self.assertEqual(div_result, 127//42)
-        except xmlrpclib.ProtocolError as e:
+        except (xmlrpclib.ProtocolError, socket.error) as e:
+            # ignore failures due to non-blocking socket 'unavailable' errors
+            if not is_unavailable_exception(e):
+                # protocol error; provide additional information in test output
+                self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
+
+    def test_non_existing_multicall(self):
+        try:
+            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+            multicall = xmlrpclib.MultiCall(p)
+            multicall.this_is_not_exists()
+            result = multicall()
+
+            # result.results contains;
+            # [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:'
+            #   'method "this_is_not_exists" is not supported'>}]
+
+            self.assertEqual(result.results[0]['faultCode'], 1)
+            self.assertEqual(result.results[0]['faultString'],
+                '<type \'Exception\'>:method "this_is_not_exists" '
+                'is not supported')
+        except (xmlrpclib.ProtocolError, socket.error) as e:
             # ignore failures due to non-blocking socket 'unavailable' errors
             if not is_unavailable_exception(e):
                 # protocol error; provide additional information in test output
-                self.fail("%s\n%s" % (e, e.headers))
+                self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
 
+    def test_dotted_attribute(self):
+        # Raises an AttributeError because private methods are not allowed.
+        self.assertRaises(AttributeError,
+                          SimpleXMLRPCServer.resolve_dotted_attribute, str, '__add')
+
+        self.assert_(SimpleXMLRPCServer.resolve_dotted_attribute(str, 'title'))
+        # Get the test to run faster by sending a request with test_simple1.
+        # This avoids waiting for the socket timeout.
+        self.test_simple1()
 
 # This is a contrived way to make a failure occur on the server side
 # in order to test the _send_traceback_header flag on the server
@@ -409,16 +445,12 @@
     def setUp(self):
         self.evt = threading.Event()
         # start server thread to handle requests
-        serv_args = (self.evt, 2)
+        serv_args = (self.evt, 1)
         threading.Thread(target=http_server, args=serv_args).start()
 
-        # wait for port to be assigned to server
-        n = 1000
-        while n > 0 and PORT is None:
-            time.sleep(0.001)
-            n -= 1
-
-        time.sleep(0.5)
+        # wait for the server to be ready
+        self.evt.wait()
+        self.evt.clear()
 
     def tearDown(self):
         # wait on the server thread to terminate
@@ -440,11 +472,11 @@
         try:
             p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
             self.assertEqual(p.pow(6,8), 6**8)
-        except xmlrpclib.ProtocolError as e:
+        except (xmlrpclib.ProtocolError, socket.error) as e:
             # ignore failures due to non-blocking socket 'unavailable' errors
             if not is_unavailable_exception(e):
                 # protocol error; provide additional information in test output
-                self.fail("%s\n%s" % (e, e.headers))
+                self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
 
     def test_fail_no_info(self):
         # use the broken message class
@@ -453,9 +485,9 @@
         try:
             p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
             p.pow(6,8)
-        except xmlrpclib.ProtocolError as e:
+        except (xmlrpclib.ProtocolError, socket.error) as e:
             # ignore failures due to non-blocking socket 'unavailable' errors
-            if not is_unavailable_exception(e):
+            if not is_unavailable_exception(e) and hasattr(e, "headers"):
                 # The two server-side error headers shouldn't be sent back in this case
                 self.assertTrue(e.headers.get("X-exception") is None)
                 self.assertTrue(e.headers.get("X-traceback") is None)
@@ -473,9 +505,9 @@
         try:
             p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
             p.pow(6,8)
-        except xmlrpclib.ProtocolError as e:
+        except (xmlrpclib.ProtocolError, socket.error) as e:
             # ignore failures due to non-blocking socket 'unavailable' errors
-            if not is_unavailable_exception(e):
+            if not is_unavailable_exception(e) and hasattr(e, "headers"):
                 # We should get error info in the response
                 expected_err = "invalid literal for int() with base 10: 'I am broken'"
                 self.assertEqual(e.headers.get("x-exception"), expected_err)
@@ -483,6 +515,70 @@
         else:
             self.fail('ProtocolError not raised')
 
+class CGIHandlerTestCase(unittest.TestCase):
+    def setUp(self):
+        self.cgi = SimpleXMLRPCServer.CGIXMLRPCRequestHandler()
+
+    def tearDown(self):
+        self.cgi = None
+
+    def test_cgi_get(self):
+        os.environ['REQUEST_METHOD'] = 'GET'
+        # if the method is GET and no request_text is given, it runs handle_get
+        # get sysout output
+        tmp = sys.stdout
+        sys.stdout = open(test_support.TESTFN, "w")
+        self.cgi.handle_request()
+        sys.stdout.close()
+        sys.stdout = tmp
+
+        # parse Status header
+        handle = open(test_support.TESTFN, "r").read()
+        status = handle.split()[1]
+        message = ' '.join(handle.split()[2:4])
+
+        self.assertEqual(status, '400')
+        self.assertEqual(message, 'Bad Request')
+
+        os.remove(test_support.TESTFN)
+        os.environ['REQUEST_METHOD'] = ''
+
+    def test_cgi_xmlrpc_response(self):
+        data = """<?xml version='1.0'?>
+<methodCall>
+    <methodName>test_method</methodName>
+    <params>
+        <param>
+            <value><string>foo</string></value>
+        </param>
+        <param>
+            <value><string>bar</string></value>
+        </param>
+     </params>
+</methodCall>
+"""
+        open("xmldata.txt", "w").write(data)
+        tmp1 = sys.stdin
+        tmp2 = sys.stdout
+
+        sys.stdin = open("xmldata.txt", "r")
+        sys.stdout = open(test_support.TESTFN, "w")
+
+        self.cgi.handle_request()
+
+        sys.stdin.close()
+        sys.stdout.close()
+        sys.stdin = tmp1
+        sys.stdout = tmp2
+
+        # will respond exception, if so, our goal is achieved ;)
+        handle = open(test_support.TESTFN, "r").read()
+
+        # start with 44th char so as not to get http header, we just need only xml
+        self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, handle[44:])
+
+        os.remove("xmldata.txt")
+        os.remove(test_support.TESTFN)
 
 def test_main():
     xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase,
@@ -495,6 +591,7 @@
     if sys.platform != 'win32':
         xmlrpc_tests.append(SimpleServerTestCase)
         xmlrpc_tests.append(FailingServerTestCase)
+        xmlrpc_tests.append(CGIHandlerTestCase)
 
     test_support.run_unittest(*xmlrpc_tests)
 

Modified: python/branches/py3k-importlib/Lib/test/test_zipfile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_zipfile.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_zipfile.py	Thu Mar 27 00:48:05 2008
@@ -14,6 +14,11 @@
 TESTFN2 = TESTFN + "2"
 FIXEDTEST_SIZE = 1000
 
+SMALL_TEST_DATA = [('_ziptest1', '1q2w3e4r5t'),
+                   ('ziptest2dir/_ziptest2', 'qawsedrftg'),
+                   ('/ziptest2dir/ziptest3dir/_ziptest3', 'azsxdcfvgb'),
+                   ('ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3', '6y7u8i9o0p')]
+
 class TestsWithSourceFile(unittest.TestCase):
     def setUp(self):
         self.line_gen = (bytes("Zipfile test line %d. random float: %f" %
@@ -289,6 +294,58 @@
         self.assertRaises(RuntimeError, zipf.write, TESTFN)
         zipf.close()
 
+    def testExtract(self):
+        zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED)
+        for fpath, fdata in SMALL_TEST_DATA:
+            zipfp.writestr(fpath, fdata)
+        zipfp.close()
+
+        zipfp = zipfile.ZipFile(TESTFN2, "r")
+        for fpath, fdata in SMALL_TEST_DATA:
+            writtenfile = zipfp.extract(fpath)
+
+            # make sure it was written to the right place
+            if os.path.isabs(fpath):
+                correctfile = os.path.join(os.getcwd(), fpath[1:])
+            else:
+                correctfile = os.path.join(os.getcwd(), fpath)
+            correctfile = os.path.normpath(correctfile)
+
+            self.assertEqual(writtenfile, correctfile)
+
+            # make sure correct data is in correct file
+            self.assertEqual(fdata.encode(), open(writtenfile, "rb").read())
+
+            os.remove(writtenfile)
+
+        zipfp.close()
+
+        # remove the test file subdirectories
+        shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
+
+    def testExtractAll(self):
+        zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED)
+        for fpath, fdata in SMALL_TEST_DATA:
+            zipfp.writestr(fpath, fdata)
+        zipfp.close()
+
+        zipfp = zipfile.ZipFile(TESTFN2, "r")
+        zipfp.extractall()
+        for fpath, fdata in SMALL_TEST_DATA:
+            if os.path.isabs(fpath):
+                outfile = os.path.join(os.getcwd(), fpath[1:])
+            else:
+                outfile = os.path.join(os.getcwd(), fpath)
+
+            self.assertEqual(fdata.encode(), open(outfile, "rb").read())
+
+            os.remove(outfile)
+
+        zipfp.close()
+
+        # remove the test file subdirectories
+        shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
+
     def tearDown(self):
         os.remove(TESTFN)
         os.remove(TESTFN2)
@@ -630,31 +687,52 @@
     b'\x1a\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x01\x00 \x00\xb6\x81'
     b'\x00\x00\x00\x00test.txtPK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x006\x00'
     b'\x00\x00L\x00\x00\x00\x00\x00' )
+    data2 = (
+    b'PK\x03\x04\x14\x00\t\x00\x08\x00\xcf}38xu\xaa\xb2\x14\x00\x00\x00\x00\x02'
+    b'\x00\x00\x04\x00\x15\x00zeroUT\t\x00\x03\xd6\x8b\x92G\xda\x8b\x92GUx\x04'
+    b'\x00\xe8\x03\xe8\x03\xc7<M\xb5a\xceX\xa3Y&\x8b{oE\xd7\x9d\x8c\x98\x02\xc0'
+    b'PK\x07\x08xu\xaa\xb2\x14\x00\x00\x00\x00\x02\x00\x00PK\x01\x02\x17\x03'
+    b'\x14\x00\t\x00\x08\x00\xcf}38xu\xaa\xb2\x14\x00\x00\x00\x00\x02\x00\x00'
+    b'\x04\x00\r\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00ze'
+    b'roUT\x05\x00\x03\xd6\x8b\x92GUx\x00\x00PK\x05\x06\x00\x00\x00\x00\x01'
+    b'\x00\x01\x00?\x00\x00\x00[\x00\x00\x00\x00\x00' )
 
     plain = b'zipfile.py encryption test'
+    plain2 = b'\x00'*512
 
     def setUp(self):
         fp = open(TESTFN, "wb")
         fp.write(self.data)
         fp.close()
         self.zip = zipfile.ZipFile(TESTFN, "r")
+        fp = open(TESTFN2, "wb")
+        fp.write(self.data2)
+        fp.close()
+        self.zip2 = zipfile.ZipFile(TESTFN2, "r")
 
     def tearDown(self):
         self.zip.close()
         os.unlink(TESTFN)
+        self.zip2.close()
+        os.unlink(TESTFN2)
 
     def testNoPassword(self):
         # Reading the encrypted file without password
         # must generate a RunTime exception
         self.assertRaises(RuntimeError, self.zip.read, "test.txt")
+        self.assertRaises(RuntimeError, self.zip2.read, "zero")
 
     def testBadPassword(self):
         self.zip.setpassword(b"perl")
         self.assertRaises(RuntimeError, self.zip.read, "test.txt")
+        self.zip2.setpassword(b"perl")
+        self.assertRaises(RuntimeError, self.zip2.read, "zero")
 
     def testGoodPassword(self):
         self.zip.setpassword(b"python")
         self.assertEquals(self.zip.read("test.txt"), self.plain)
+        self.zip2.setpassword(b"12345")
+        self.assertEquals(self.zip2.read("zero"), self.plain2)
 
 
 class TestsWithRandomBinaryFiles(unittest.TestCase):

Modified: python/branches/py3k-importlib/Lib/test/test_zipimport.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_zipimport.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_zipimport.py	Thu Mar 27 00:48:05 2008
@@ -153,7 +153,7 @@
 
     def testBadMagic(self):
         # make pyc magic word invalid, forcing loading from .py
-        badmagic_pyc = bytes(test_pyc)
+        badmagic_pyc = bytearray(test_pyc)
         badmagic_pyc[0] ^= 0x04  # flip an arbitrary bit
         files = {TESTMOD + ".py": (NOW, test_src),
                  TESTMOD + pyc_ext: (NOW, badmagic_pyc)}
@@ -161,7 +161,7 @@
 
     def testBadMagic2(self):
         # make pyc magic word invalid, causing an ImportError
-        badmagic_pyc = bytes(test_pyc)
+        badmagic_pyc = bytearray(test_pyc)
         badmagic_pyc[0] ^= 0x04  # flip an arbitrary bit
         files = {TESTMOD + pyc_ext: (NOW, badmagic_pyc)}
         try:
@@ -172,7 +172,7 @@
             self.fail("expected ImportError; import from bad pyc")
 
     def testBadMTime(self):
-        badtime_pyc = bytes(test_pyc)
+        badtime_pyc = bytearray(test_pyc)
         badtime_pyc[7] ^= 0x02  # flip the second bit -- not the first as that one
                                 # isn't stored in the .py's mtime in the zip archive.
         files = {TESTMOD + ".py": (NOW, test_src),
@@ -220,6 +220,11 @@
             mod = __import__(module_path_to_dotted_name(mod_name))
             self.assertEquals(zi.get_source(TESTPACK), None)
             self.assertEquals(zi.get_source(mod_name), None)
+
+            # test prefix and archivepath members
+            zi2 = zipimport.zipimporter(TEMP_ZIP + os.sep + TESTPACK)
+            self.assertEquals(zi2.archive, TEMP_ZIP)
+            self.assertEquals(zi2.prefix, TESTPACK + os.sep)
         finally:
             z.close()
             os.remove(TEMP_ZIP)

Modified: python/branches/py3k-importlib/Lib/test/test_zlib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_zlib.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_zlib.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,7 @@
 import unittest
 from test import test_support
 import zlib
+import binascii
 import random
 
 
@@ -38,18 +39,37 @@
         self.assertEqual(zlib.crc32(b"penguin"), zlib.crc32(b"penguin", 0))
         self.assertEqual(zlib.adler32(b"penguin"),zlib.adler32(b"penguin",1))
 
+    def test_crc32_adler32_unsigned(self):
+        foo = 'abcdefghijklmnop'
+        # explicitly test signed behavior
+        self.assertEqual(zlib.crc32(foo), 2486878355)
+        self.assertEqual(zlib.crc32('spam'), 1138425661)
+        self.assertEqual(zlib.adler32(foo+foo), 3573550353)
+        self.assertEqual(zlib.adler32('spam'), 72286642)
+
+    def test_same_as_binascii_crc32(self):
+        foo = 'abcdefghijklmnop'
+        crc = 2486878355
+        self.assertEqual(binascii.crc32(foo), crc)
+        self.assertEqual(zlib.crc32(foo), crc)
+        self.assertEqual(binascii.crc32('spam'), zlib.crc32('spam'))
+
 
 
 class ExceptionTestCase(unittest.TestCase):
     # make sure we generate some expected errors
-    def test_bigbits(self):
-        # specifying total bits too large causes an error
-        self.assertRaises(zlib.error,
-                zlib.compress, 'ERROR', zlib.MAX_WBITS + 1)
+    def test_badlevel(self):
+        # specifying compression level out of range causes an error
+        # (but -1 is Z_DEFAULT_COMPRESSION and apparently the zlib
+        # accepts 0 too)
+        self.assertRaises(zlib.error, zlib.compress, 'ERROR', 10)
 
     def test_badcompressobj(self):
         # verify failure on building compress object with bad params
         self.assertRaises(ValueError, zlib.compressobj, 1, zlib.DEFLATED, 0)
+        # specifying total bits too large causes an error
+        self.assertRaises(ValueError,
+                zlib.compressobj, 1, zlib.DEFLATED, zlib.MAX_WBITS + 1)
 
     def test_baddecompressobj(self):
         # verify failure on building decompress object with bad params

Deleted: /python/branches/py3k-importlib/Lib/test/testall.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/testall.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,4 +0,0 @@
-# Backward compatibility -- you should use regrtest instead of this module.
-import sys, regrtest
-sys.argv[1:] = ["-vv"]
-regrtest.main()

Modified: python/branches/py3k-importlib/Lib/test/testcodec.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/testcodec.py	(original)
+++ python/branches/py3k-importlib/Lib/test/testcodec.py	Thu Mar 27 00:48:05 2008
@@ -36,7 +36,7 @@
 decoding_map = codecs.make_identity_dict(range(256))
 decoding_map.update({
         0x78: "abc", # 1-n decoding mapping
-        str8("abc"): 0x0078,# 1-n encoding mapping
+        b"abc": 0x0078,# 1-n encoding mapping
         0x01: None,   # decoding mapping to <undefined>
         0x79: "",    # decoding mapping to <remove character>
 })

Modified: python/branches/py3k-importlib/Lib/test/testtar.tar
==============================================================================
Binary files. No diff available.

Modified: python/branches/py3k-importlib/Lib/test/tokenize_tests.txt
==============================================================================
--- python/branches/py3k-importlib/Lib/test/tokenize_tests.txt	(original)
+++ python/branches/py3k-importlib/Lib/test/tokenize_tests.txt	Thu Mar 27 00:48:05 2008
@@ -110,19 +110,19 @@
 bar \\ baz
 """ + R'''spam
 '''
-x = u'abc' + U'ABC'
-y = u"abc" + U"ABC"
-x = ur'abc' + Ur'ABC' + uR'ABC' + UR'ABC'
-y = ur"abc" + Ur"ABC" + uR"ABC" + UR"ABC"
-x = ur'\\' + UR'\\'
-x = ur'\'' + ''
-y = ur'''
+x = b'abc' + B'ABC'
+y = b"abc" + B"ABC"
+x = br'abc' + Br'ABC' + bR'ABC' + BR'ABC'
+y = br"abc" + Br"ABC" + bR"ABC" + BR"ABC"
+x = br'\\' + BR'\\'
+x = br'\'' + ''
+y = br'''
 foo bar \\
-baz''' + UR'''
+baz''' + BR'''
 foo'''
-y = Ur"""foo
+y = Br"""foo
 bar \\ baz
-""" + uR'''spam
+""" + bR'''spam
 '''
 
 # Indentation

Modified: python/branches/py3k-importlib/Lib/textwrap.py
==============================================================================
--- python/branches/py3k-importlib/Lib/textwrap.py	(original)
+++ python/branches/py3k-importlib/Lib/textwrap.py	Thu Mar 27 00:48:05 2008
@@ -159,7 +159,12 @@
         Handle a chunk of text (most likely a word, not whitespace) that
         is too long to fit in any line.
         """
-        space_left = max(width - cur_len, 1)
+        # Figure out when indent is larger than the specified width, and make
+        # sure at least one character is stripped off on every pass
+        if width < 1:
+            space_left = 1
+        else:
+            space_left = width - cur_len
 
         # If we're allowed to break long words, then do so: put as much
         # of the next chunk onto the current line as will fit.

Modified: python/branches/py3k-importlib/Lib/threading.py
==============================================================================
--- python/branches/py3k-importlib/Lib/threading.py	(original)
+++ python/branches/py3k-importlib/Lib/threading.py	Thu Mar 27 00:48:05 2008
@@ -403,7 +403,7 @@
         self._args = args
         self._kwargs = kwargs
         self._daemonic = self._set_daemon()
-        self._started = False
+        self._started = Event()
         self._stopped = False
         self._block = Condition(Lock())
         self._initialized = True
@@ -418,7 +418,7 @@
     def __repr__(self):
         assert self._initialized, "Thread.__init__() was not called"
         status = "initial"
-        if self._started:
+        if self._started.isSet():
             status = "started"
         if self._stopped:
             status = "stopped"
@@ -429,7 +429,8 @@
     def start(self):
         if not self._initialized:
             raise RuntimeError("thread.__init__() not called")
-        if self._started:
+
+        if self._started.isSet():
             raise RuntimeError("thread already started")
         if __debug__:
             self._note("%s.start(): starting thread", self)
@@ -437,12 +438,16 @@
         _limbo[self] = self
         _active_limbo_lock.release()
         _start_new_thread(self._bootstrap, ())
-        self._started = True
-        _sleep(0.000001)    # 1 usec, to let the thread run (Solaris hack)
+        self._started.wait()
 
     def run(self):
-        if self._target:
-            self._target(*self._args, **self._kwargs)
+        try:
+            if self._target:
+                self._target(*self._args, **self._kwargs)
+        finally:
+            # Avoid a refcycle if the thread is running a function with
+            # an argument that has a member that points to the thread.
+            del self._target, self._args, self._kwargs
 
     def _bootstrap(self):
         # Wrapper around the real bootstrap code that ignores
@@ -450,11 +455,11 @@
         # happen when a daemon thread wakes up at an unfortunate
         # moment, finds the world around it destroyed, and raises some
         # random exception *** while trying to report the exception in
-        # __bootstrap_inner() below ***.  Those random exceptions
+        # _bootstrap_inner() below ***.  Those random exceptions
         # don't help anybody, and they confuse users, so we suppress
         # them.  We suppress them only when it appears that the world
         # indeed has already been destroyed, so that exceptions in
-        # __bootstrap_inner() during normal business hours are properly
+        # _bootstrap_inner() during normal business hours are properly
         # reported.  Also, we only suppress them for daemonic threads;
         # if a non-daemonic encounters this, something else is wrong.
         try:
@@ -466,29 +471,29 @@
 
     def _bootstrap_inner(self):
         try:
-            self._started = True
+            self._started.set()
             _active_limbo_lock.acquire()
             _active[_get_ident()] = self
             del _limbo[self]
             _active_limbo_lock.release()
             if __debug__:
-                self._note("%s.__bootstrap(): thread started", self)
+                self._note("%s._bootstrap(): thread started", self)
 
             if _trace_hook:
-                self._note("%s.__bootstrap(): registering trace hook", self)
+                self._note("%s._bootstrap(): registering trace hook", self)
                 _sys.settrace(_trace_hook)
             if _profile_hook:
-                self._note("%s.__bootstrap(): registering profile hook", self)
+                self._note("%s._bootstrap(): registering profile hook", self)
                 _sys.setprofile(_profile_hook)
 
             try:
                 self.run()
             except SystemExit:
                 if __debug__:
-                    self._note("%s.__bootstrap(): raised SystemExit", self)
+                    self._note("%s._bootstrap(): raised SystemExit", self)
             except:
                 if __debug__:
-                    self._note("%s.__bootstrap(): unhandled exception", self)
+                    self._note("%s._bootstrap(): unhandled exception", self)
                 # If sys.stderr is no more (most likely from interpreter
                 # shutdown) use self._stderr.  Otherwise still use sys (as in
                 # _sys) in case sys.stderr was redefined since the creation of
@@ -521,13 +526,16 @@
                         del exc_type, exc_value, exc_tb
             else:
                 if __debug__:
-                    self._note("%s.__bootstrap(): normal return", self)
+                    self._note("%s._bootstrap(): normal return", self)
         finally:
-            self._stop()
-            try:
-                self._delete()
-            except:
-                pass
+            with _active_limbo_lock:
+                self._stop()
+                try:
+                    # We don't call self.__delete() because it also
+                    # grabs _active_limbo_lock.
+                    del _active[_get_ident()]
+                except:
+                    pass
 
     def _stop(self):
         self._block.acquire()
@@ -572,7 +580,7 @@
     def join(self, timeout=None):
         if not self._initialized:
             raise RuntimeError("Thread.__init__() not called")
-        if not self._started:
+        if not self._started.isSet():
             raise RuntimeError("cannot join thread before it is started")
         if self is currentThread():
             raise RuntimeError("cannot join current thread")
@@ -580,6 +588,7 @@
         if __debug__:
             if not self._stopped:
                 self._note("%s.join(): waiting until thread stops", self)
+
         self._block.acquire()
         try:
             if timeout is None:
@@ -612,7 +621,7 @@
 
     def isAlive(self):
         assert self._initialized, "Thread.__init__() not called"
-        return self._started and not self._stopped
+        return self._started.isSet() and not self._stopped
 
     def isDaemon(self):
         assert self._initialized, "Thread.__init__() not called"
@@ -621,7 +630,7 @@
     def setDaemon(self, daemonic):
         if not self._initialized:
             raise RuntimeError("Thread.__init__() not called")
-        if self._started:
+        if self._started.isSet():
             raise RuntimeError("cannot set daemon status of active thread");
         self._daemonic = daemonic
 
@@ -663,7 +672,7 @@
 
     def __init__(self):
         Thread.__init__(self, name="MainThread")
-        self._started = True
+        self._started.set()
         _active_limbo_lock.acquire()
         _active[_get_ident()] = self
         _active_limbo_lock.release()
@@ -709,7 +718,8 @@
         # instance is immortal, that's bad, so release this resource.
         del self._block
 
-        self._started = True
+
+        self._started.set()
         _active_limbo_lock.acquire()
         _active[_get_ident()] = self
         _active_limbo_lock.release()

Modified: python/branches/py3k-importlib/Lib/timeit.py
==============================================================================
--- python/branches/py3k-importlib/Lib/timeit.py	(original)
+++ python/branches/py3k-importlib/Lib/timeit.py	Thu Mar 27 00:48:05 2008
@@ -121,9 +121,9 @@
         """Constructor.  See class doc string."""
         self.timer = timer
         ns = {}
-        if isinstance(stmt, basestring):
+        if isinstance(stmt, str):
             stmt = reindent(stmt, 8)
-            if isinstance(setup, basestring):
+            if isinstance(setup, str):
                 setup = reindent(setup, 4)
                 src = template % {'stmt': stmt, 'setup': setup}
             elif hasattr(setup, '__call__'):
@@ -137,7 +137,7 @@
             self.inner = ns["inner"]
         elif hasattr(stmt, '__call__'):
             self.src = None
-            if isinstance(setup, basestring):
+            if isinstance(setup, str):
                 _setup = setup
                 def setup():
                     exec(_setup, globals(), ns)

Modified: python/branches/py3k-importlib/Lib/token.py
==============================================================================
--- python/branches/py3k-importlib/Lib/token.py	(original)
+++ python/branches/py3k-importlib/Lib/token.py	Thu Mar 27 00:48:05 2008
@@ -72,6 +72,7 @@
 for _name, _value in list(globals().items()):
     if type(_value) is type(0):
         tok_name[_value] = _name
+del _name, _value
 
 
 def ISTERMINAL(x):

Modified: python/branches/py3k-importlib/Lib/tokenize.py
==============================================================================
--- python/branches/py3k-importlib/Lib/tokenize.py	(original)
+++ python/branches/py3k-importlib/Lib/tokenize.py	Thu Mar 27 00:48:05 2008
@@ -1,8 +1,11 @@
 """Tokenization help for Python programs.
 
-generate_tokens(readline) is a generator that breaks a stream of
-text into Python tokens.  It accepts a readline-like method which is called
-repeatedly to get the next line of input (or "" for EOF).  It generates
+tokenize(readline) is a generator that breaks a stream of
+bytes into Python tokens. It decodes the bytes according to
+PEP-0263 for determining source file encoding.
+
+It accepts a readline-like method which is called
+repeatedly to get the next line of input (or b"" for EOF).  It generates
 5-tuples with these members:
 
     the token type (see token.py)
@@ -13,32 +16,32 @@
 
 It is designed to match the working of the Python tokenizer exactly, except
 that it produces COMMENT tokens for comments and gives type OP for all
-operators
-
-Older entry points
-    tokenize_loop(readline, tokeneater)
-    tokenize(readline, tokeneater=printtoken)
-are the same, except instead of generating tokens, tokeneater is a callback
-function to which the 5 fields described above are passed as 5 arguments,
-each time a new token is found."""
+operators. Aditionally, all token lists start with an ENCODING token
+which tells you which encoding was used to decode the bytes stream."""
 
 __author__ = 'Ka-Ping Yee <ping at lfw.org>'
-__credits__ = \
-    'GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaro, Raymond Hettinger'
+__credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, '
+               'Skip Montanaro, Raymond Hettinger, Trent Nelson, '
+               'Michael Foord')
 
-import string, re
+import re, string, sys
 from token import *
+from codecs import lookup
+from itertools import chain, repeat
+cookie_re = re.compile("coding[:=]\s*([-\w.]+)")
 
 import token
 __all__ = [x for x in dir(token) if x[0] != '_'] + ["COMMENT", "tokenize",
-           "generate_tokens", "NL", "untokenize"]
+           "detect_encoding", "NL", "untokenize", "ENCODING"]
 del token
 
 COMMENT = N_TOKENS
 tok_name[COMMENT] = 'COMMENT'
 NL = N_TOKENS + 1
 tok_name[NL] = 'NL'
-N_TOKENS += 2
+ENCODING = N_TOKENS + 2
+tok_name[ENCODING] = 'ENCODING'
+N_TOKENS += 3
 
 def group(*choices): return '(' + '|'.join(choices) + ')'
 def any(*choices): return group(*choices) + '*'
@@ -49,9 +52,9 @@
 Ignore = Whitespace + any(r'\\\r?\n' + Whitespace) + maybe(Comment)
 Name = r'[a-zA-Z_]\w*'
 
-Hexnumber = r'0[xX][\da-fA-F]*'
-Binnumber = r'0[bB][01]*'
-Octnumber = r'0[oO][0-7]*'
+Hexnumber = r'0[xX][\da-fA-F]+'
+Binnumber = r'0[bB][01]+'
+Octnumber = r'0[oO][0-7]+'
 Decnumber = r'(?:0+|[1-9]\d*)'
 Intnumber = group(Hexnumber, Binnumber, Octnumber, Decnumber)
 Exponent = r'[eE][-+]?\d+'
@@ -69,10 +72,10 @@
 Single3 = r"[^'\\]*(?:(?:\\.|'(?!''))[^'\\]*)*'''"
 # Tail end of """ string.
 Double3 = r'[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*"""'
-Triple = group("[uU]?[rR]?'''", '[uU]?[rR]?"""')
+Triple = group("[bB]?[rR]?'''", '[bB]?[rR]?"""')
 # Single-line ' or " string.
-String = group(r"[uU]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'",
-               r'[uU]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*"')
+String = group(r"[bB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'",
+               r'[bB]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*"')
 
 # Because of leftmost-then-longest match semantics, be sure to put the
 # longest operators first (e.g., if = came before ==, == would get
@@ -90,9 +93,9 @@
 Token = Ignore + PlainToken
 
 # First (or only) line of ' or " string.
-ContStr = group(r"[uU]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*" +
+ContStr = group(r"[bB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*" +
                 group("'", r'\\\r?\n'),
-                r'[uU]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*' +
+                r'[bB]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*' +
                 group('"', r'\\\r?\n'))
 PseudoExtras = group(r'\\\r?\n', Comment, Triple)
 PseudoToken = Whitespace + group(PseudoExtras, Number, Funny, ContStr, Name)
@@ -102,28 +105,28 @@
 endprogs = {"'": re.compile(Single), '"': re.compile(Double),
             "'''": single3prog, '"""': double3prog,
             "r'''": single3prog, 'r"""': double3prog,
-            "u'''": single3prog, 'u"""': double3prog,
-            "ur'''": single3prog, 'ur"""': double3prog,
+            "b'''": single3prog, 'b"""': double3prog,
+            "br'''": single3prog, 'br"""': double3prog,
             "R'''": single3prog, 'R"""': double3prog,
-            "U'''": single3prog, 'U"""': double3prog,
-            "uR'''": single3prog, 'uR"""': double3prog,
-            "Ur'''": single3prog, 'Ur"""': double3prog,
-            "UR'''": single3prog, 'UR"""': double3prog,
-            'r': None, 'R': None, 'u': None, 'U': None}
+            "B'''": single3prog, 'B"""': double3prog,
+            "bR'''": single3prog, 'bR"""': double3prog,
+            "Br'''": single3prog, 'Br"""': double3prog,
+            "BR'''": single3prog, 'BR"""': double3prog,
+            'r': None, 'R': None, 'b': None, 'B': None}
 
 triple_quoted = {}
 for t in ("'''", '"""',
           "r'''", 'r"""', "R'''", 'R"""',
-          "u'''", 'u"""', "U'''", 'U"""',
-          "ur'''", 'ur"""', "Ur'''", 'Ur"""',
-          "uR'''", 'uR"""', "UR'''", 'UR"""'):
+          "b'''", 'b"""', "B'''", 'B"""',
+          "br'''", 'br"""', "Br'''", 'Br"""',
+          "bR'''", 'bR"""', "BR'''", 'BR"""'):
     triple_quoted[t] = t
 single_quoted = {}
 for t in ("'", '"',
           "r'", 'r"', "R'", 'R"',
-          "u'", 'u"', "U'", 'U"',
-          "ur'", 'ur"', "Ur'", 'Ur"',
-          "uR'", 'uR"', "UR'", 'UR"' ):
+          "b'", 'b"', "B'", 'B"',
+          "br'", 'br"', "Br'", 'Br"',
+          "bR'", 'bR"', "BR'", 'BR"' ):
     single_quoted[t] = t
 
 tabsize = 8
@@ -132,33 +135,6 @@
 
 class StopTokenizing(Exception): pass
 
-def printtoken(type, token, startrowcol, endrowcol, line): # for testing
-    (srow, scol), (erow, ecol) = startrowcol, endrowcol
-    print("%d,%d-%d,%d:\t%s\t%s" % \
-        (srow, scol, erow, ecol, tok_name[type], repr(token)))
-
-def tokenize(readline, tokeneater=printtoken):
-    """
-    The tokenize() function accepts two parameters: one representing the
-    input stream, and one providing an output mechanism for tokenize().
-
-    The first parameter, readline, must be a callable object which provides
-    the same interface as the readline() method of built-in file objects.
-    Each call to the function should return one line of input as a string.
-
-    The second parameter, tokeneater, must also be a callable object. It is
-    called once for each token, with five arguments, corresponding to the
-    tuples generated by generate_tokens().
-    """
-    try:
-        tokenize_loop(readline, tokeneater)
-    except StopTokenizing:
-        pass
-
-# backwards compatible interface
-def tokenize_loop(readline, tokeneater):
-    for token_info in generate_tokens(readline):
-        tokeneater(*token_info)
 
 class Untokenizer:
 
@@ -166,6 +142,7 @@
         self.tokens = []
         self.prev_row = 1
         self.prev_col = 0
+        self.encoding = None
 
     def add_whitespace(self, start):
         row, col = start
@@ -180,6 +157,9 @@
                 self.compat(t, iterable)
                 break
             tok_type, token, start, end, line = t
+            if tok_type == ENCODING:
+                self.encoding = token
+                continue
             self.add_whitespace(start)
             self.tokens.append(token)
             self.prev_row, self.prev_col = end
@@ -193,12 +173,16 @@
         indents = []
         toks_append = self.tokens.append
         toknum, tokval = token
+
         if toknum in (NAME, NUMBER):
             tokval += ' '
         if toknum in (NEWLINE, NL):
             startline = True
         for tok in iterable:
             toknum, tokval = tok[:2]
+            if toknum == ENCODING:
+                self.encoding = tokval
+                continue
 
             if toknum in (NAME, NUMBER):
                 tokval += ' '
@@ -216,8 +200,11 @@
                 startline = False
             toks_append(tokval)
 
+
 def untokenize(iterable):
     """Transform tokens back into Python source code.
+    It returns a bytes object, encoded using the ENCODING
+    token, which is the first token sequence output by tokenize.
 
     Each element returned by the iterable must be a token sequence
     with at least two elements, a token number and token value.  If
@@ -227,24 +214,89 @@
         Untokenized source will match input source exactly
 
     Round-trip invariant for limited intput:
-        # Output text will tokenize the back to the input
-        t1 = [tok[:2] for tok in generate_tokens(f.readline)]
+        # Output bytes will tokenize the back to the input
+        t1 = [tok[:2] for tok in tokenize(f.readline)]
         newcode = untokenize(t1)
-        readline = iter(newcode.splitlines(1)).__next__
-        t2 = [tok[:2] for tokin generate_tokens(readline)]
+        readline = BytesIO(newcode).readline
+        t2 = [tok[:2] for tok in tokenize(readline)]
         assert t1 == t2
     """
     ut = Untokenizer()
-    return ut.untokenize(iterable)
+    out = ut.untokenize(iterable)
+    if ut.encoding is not None:
+        out = out.encode(ut.encoding)
+    return out
 
-def generate_tokens(readline):
+
+def detect_encoding(readline):
+    """
+    The detect_encoding() function is used to detect the encoding that should
+    be used to decode a Python source file. It requires one argment, readline,
+    in the same way as the tokenize() generator.
+
+    It will call readline a maximum of twice, and return the encoding used
+    (as a string) and a list of any lines (left as bytes) it has read
+    in.
+
+    It detects the encoding from the presence of a utf-8 bom or an encoding
+    cookie as specified in pep-0263. If both a bom and a cookie are present,
+    but disagree, a SyntaxError will be raised.
+
+    If no encoding is specified, then the default of 'utf-8' will be returned.
     """
-    The generate_tokens() generator requires one argment, readline, which
+    utf8_bom = b'\xef\xbb\xbf'
+    bom_found = False
+    encoding = None
+    def read_or_stop():
+        try:
+            return readline()
+        except StopIteration:
+            return b''
+
+    def find_cookie(line):
+        try:
+            line_string = line.decode('ascii')
+        except UnicodeDecodeError:
+            pass
+        else:
+            matches = cookie_re.findall(line_string)
+            if matches:
+                encoding = matches[0]
+                if bom_found and lookup(encoding).name != 'utf-8':
+                    # This behaviour mimics the Python interpreter
+                    raise SyntaxError('encoding problem: utf-8')
+                return encoding
+
+    first = read_or_stop()
+    if first.startswith(utf8_bom):
+        bom_found = True
+        first = first[3:]
+    if not first:
+        return 'utf-8', []
+
+    encoding = find_cookie(first)
+    if encoding:
+        return encoding, [first]
+
+    second = read_or_stop()
+    if not second:
+        return 'utf-8', [first]
+
+    encoding = find_cookie(second)
+    if encoding:
+        return encoding, [first, second]
+
+    return 'utf-8', [first, second]
+
+
+def tokenize(readline):
+    """
+    The tokenize() generator requires one argment, readline, which
     must be a callable object which provides the same interface as the
     readline() method of built-in file objects. Each call to the function
-    should return one line of input as a string.  Alternately, readline
+    should return one line of input as bytes.  Alternately, readline
     can be a callable function terminating with StopIteration:
-        readline = open(myfile).__next__    # Example of alternate readline
+        readline = open(myfile, 'rb').__next__  # Example of alternate readline
 
     The generator produces 5-tuples with these members: the token type; the
     token string; a 2-tuple (srow, scol) of ints specifying the row and
@@ -252,18 +304,38 @@
     ints specifying the row and column where the token ends in the source;
     and the line on which the token was found. The line passed is the
     logical line; continuation lines are included.
+
+    The first token sequence will always be an ENCODING token
+    which tells you which encoding was used to decode the bytes stream.
     """
+    encoding, consumed = detect_encoding(readline)
+    def readline_generator():
+        while True:
+            try:
+                yield readline()
+            except StopIteration:
+                return
+    chained = chain(consumed, readline_generator())
+    return _tokenize(chained.__next__, encoding)
+
+
+def _tokenize(readline, encoding):
     lnum = parenlev = continued = 0
     namechars, numchars = string.ascii_letters + '_', '0123456789'
     contstr, needcont = '', 0
     contline = None
     indents = [0]
 
+    if encoding is not None:
+        yield (ENCODING, encoding, (0, 0), (0, 0), '')
     while 1:                                   # loop over lines in stream
         try:
             line = readline()
         except StopIteration:
-            line = ''
+            line = b''
+
+        if encoding is not None:
+            line = line.decode(encoding)
         lnum = lnum + 1
         pos, max = 0, len(line)
 
@@ -385,7 +457,8 @@
         yield (DEDENT, '', (lnum, 0), (lnum, 0), '')
     yield (ENDMARKER, '', (lnum, 0), (lnum, 0), '')
 
-if __name__ == '__main__':                     # testing
-    import sys
-    if len(sys.argv) > 1: tokenize(open(sys.argv[1]).readline)
-    else: tokenize(sys.stdin.readline)
+
+# An undocumented, backwards compatible, API for all the places in the standard
+# library that expect to be able to use tokenize with strings
+def generate_tokens(readline):
+    return _tokenize(readline, None)

Modified: python/branches/py3k-importlib/Lib/trace.py
==============================================================================
--- python/branches/py3k-importlib/Lib/trace.py	(original)
+++ python/branches/py3k-importlib/Lib/trace.py	Thu Mar 27 00:48:05 2008
@@ -53,6 +53,7 @@
 import re
 import sys
 import threading
+import time
 import token
 import tokenize
 import types
@@ -94,10 +95,13 @@
                       with '>>>>>> '.
 -s, --summary         Write a brief summary on stdout for each file.
                       (Can only be used with --count or --report.)
+-g, --timing          Prefix each line with the time since the program started.
+                      Only used while tracing.
 
 Filters, may be repeated multiple times:
---ignore-module=<mod> Ignore the given module and its submodules
-                      (if it is a package).
+--ignore-module=<mod> Ignore the given module(s) and its submodules
+                      (if it is a package).  Accepts comma separated
+                      list of module names
 --ignore-dir=<dir>    Ignore files in the given directory (multiple
                       directories can be joined by os.pathsep).
 """ % sys.argv[0])
@@ -282,6 +286,8 @@
             # skip some "files" we don't care about...
             if filename == "<string>":
                 continue
+            if filename.startswith("<doctest "):
+                continue
 
             if filename.endswith((".pyc", ".pyo")):
                 filename = filename[:-1]
@@ -428,7 +434,8 @@
 
 class Trace:
     def __init__(self, count=1, trace=1, countfuncs=0, countcallers=0,
-                 ignoremods=(), ignoredirs=(), infile=None, outfile=None):
+                 ignoremods=(), ignoredirs=(), infile=None, outfile=None,
+                 timing=False):
         """
         @param count true iff it should count number of times each
                      line is executed
@@ -444,6 +451,7 @@
         @param infile file from which to read stored counts to be
                      added into the results
         @param outfile file in which to write the results
+        @param timing true iff timing information be displayed
         """
         self.infile = infile
         self.outfile = outfile
@@ -456,6 +464,9 @@
         self._calledfuncs = {}
         self._callers = {}
         self._caller_cache = {}
+        self.start_time = None
+        if timing:
+            self.start_time = time.time()
         if countcallers:
             self.globaltrace = self.globaltrace_trackcallers
         elif countfuncs:
@@ -606,6 +617,8 @@
             key = filename, lineno
             self.counts[key] = self.counts.get(key, 0) + 1
 
+            if self.start_time:
+                print('%.2f' % (time.time() - self.start_time), end=' ')
             bname = os.path.basename(filename)
             print("%s(%d): %s" % (bname, lineno,
                                   linecache.getline(filename, lineno)), end=' ')
@@ -617,6 +630,8 @@
             filename = frame.f_code.co_filename
             lineno = frame.f_lineno
 
+            if self.start_time:
+                print('%.2f' % (time.time() - self.start_time), end=' ')
             bname = os.path.basename(filename)
             print("%s(%d): %s" % (bname, lineno,
                                   linecache.getline(filename, lineno)), end=' ')
@@ -646,13 +661,13 @@
     if argv is None:
         argv = sys.argv
     try:
-        opts, prog_argv = getopt.getopt(argv[1:], "tcrRf:d:msC:lT",
+        opts, prog_argv = getopt.getopt(argv[1:], "tcrRf:d:msC:lTg",
                                         ["help", "version", "trace", "count",
                                          "report", "no-report", "summary",
                                          "file=", "missing",
                                          "ignore-module=", "ignore-dir=",
                                          "coverdir=", "listfuncs",
-                                         "trackcalls"])
+                                         "trackcalls", "timing"])
 
     except getopt.error as msg:
         sys.stderr.write("%s: %s\n" % (sys.argv[0], msg))
@@ -672,6 +687,7 @@
     summary = 0
     listfuncs = False
     countcallers = False
+    timing = False
 
     for opt, val in opts:
         if opt == "--help":
@@ -690,6 +706,10 @@
             listfuncs = True
             continue
 
+        if opt == "-g" or opt == "--timing":
+            timing = True
+            continue
+
         if opt == "-t" or opt == "--trace":
             trace = 1
             continue
@@ -723,7 +743,8 @@
             continue
 
         if opt == "--ignore-module":
-            ignore_modules.append(val)
+            for mod in val.split(","):
+                ignore_modules.append(mod.strip())
             continue
 
         if opt == "--ignore-dir":
@@ -771,7 +792,7 @@
         t = Trace(count, trace, countfuncs=listfuncs,
                   countcallers=countcallers, ignoremods=ignore_modules,
                   ignoredirs=ignore_dirs, infile=counts_file,
-                  outfile=counts_file)
+                  outfile=counts_file, timing=timing)
         try:
             fp = open(progname)
             try:

Modified: python/branches/py3k-importlib/Lib/traceback.py
==============================================================================
--- python/branches/py3k-importlib/Lib/traceback.py	(original)
+++ python/branches/py3k-importlib/Lib/traceback.py	Thu Mar 27 00:48:05 2008
@@ -168,7 +168,7 @@
 
     stype = etype.__name__
     smod = etype.__module__
-    if smod not in ("__main__", "__builtin__"):
+    if smod not in ("__main__", "builtins"):
         stype = smod + '.' + stype
 
     if not issubclass(etype, SyntaxError):

Modified: python/branches/py3k-importlib/Lib/types.py
==============================================================================
--- python/branches/py3k-importlib/Lib/types.py	(original)
+++ python/branches/py3k-importlib/Lib/types.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,5 @@
-"""Define names for all type symbols known in the standard interpreter.
-
-Types that are part of optional modules (e.g. array) are not listed.
+"""
+Define names for built-in types that aren't directly accessible as a builtin.
 """
 import sys
 
@@ -9,23 +8,6 @@
 # iterator.  Don't check the type!  Use hasattr to check for both
 # "__iter__" and "__next__" attributes instead.
 
-NoneType = type(None)
-TypeType = type
-ObjectType = object
-
-IntType = int
-LongType = int
-FloatType = float
-BooleanType = bool
-try:
-    ComplexType = complex
-except NameError:
-    pass
-
-TupleType = tuple
-ListType = list
-DictType = DictionaryType = dict
-
 def _f(): pass
 FunctionType = type(_f)
 LambdaType = type(lambda: None)         # Same as FunctionType
@@ -37,8 +19,6 @@
 
 class _C:
     def _m(self): pass
-ClassType = type
-UnboundMethodType = type(_C._m)         # Same as MethodType
 MethodType = type(_C()._m)
 
 BuiltinFunctionType = type(len)
@@ -54,12 +34,6 @@
     FrameType = type(tb.tb_frame)
     tb = None; del tb
 
-SliceType = slice
-EllipsisType = type(Ellipsis)
-
-DictProxyType = type(TypeType.__dict__)
-NotImplementedType = type(NotImplemented)
-
 # Extension types defined in a C helper module.  XXX There may be no
 # equivalent in implementations other than CPython, so it seems better to
 # leave them undefined then to set them to e.g. None.

Modified: python/branches/py3k-importlib/Lib/unittest.py
==============================================================================
--- python/branches/py3k-importlib/Lib/unittest.py	(original)
+++ python/branches/py3k-importlib/Lib/unittest.py	Thu Mar 27 00:48:05 2008
@@ -418,7 +418,7 @@
         self._tests.append(test)
 
     def addTests(self, tests):
-        if isinstance(tests, basestring):
+        if isinstance(tests, str):
             raise TypeError("tests must be an iterable of tests, not a string")
         for test in tests:
             self.addTest(test)
@@ -504,6 +504,15 @@
 # Locating and loading tests
 ##############################################################################
 
+def CmpToKey(mycmp):
+    'Convert a cmp= function into a key= function'
+    class K(object):
+        def __init__(self, obj, *args):
+            self.obj = obj
+        def __lt__(self, other):
+            return mycmp(self.obj, other.obj) == -1
+    return K
+
 class TestLoader:
     """This class is responsible for loading tests according to various
     criteria and returning them wrapped in a TestSuite
@@ -559,13 +568,18 @@
             return self.loadTestsFromModule(obj)
         elif isinstance(obj, type) and issubclass(obj, TestCase):
             return self.loadTestsFromTestCase(obj)
-        elif (isinstance(obj, types.UnboundMethodType) and
+        elif (isinstance(obj, types.FunctionType) and
               isinstance(parent, type) and
               issubclass(parent, TestCase)):
-            return TestSuite([parent(obj.__name__)])
+            name = obj.__name__
+            inst = parent(name)
+            # static methods follow a different path
+            if not isinstance(getattr(inst, name), types.FunctionType):
+                return TestSuite([inst])
         elif isinstance(obj, TestSuite):
             return obj
-        elif hasattr(obj, '__call__'):
+
+        if hasattr(obj, '__call__'):
             test = obj()
             if isinstance(test, TestSuite):
                 return test
@@ -593,7 +607,7 @@
                    and hasattr(getattr(testCaseClass, attrname), '__call__')
         testFnNames = list(filter(isTestMethod, dir(testCaseClass)))
         if self.sortTestMethodsUsing:
-            testFnNames.sort(self.sortTestMethodsUsing)
+            testFnNames.sort(key=CmpToKey(self.sortTestMethodsUsing))
         return testFnNames
 
 

Modified: python/branches/py3k-importlib/Lib/urllib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/urllib.py	(original)
+++ python/branches/py3k-importlib/Lib/urllib.py	Thu Mar 27 00:48:05 2008
@@ -359,8 +359,9 @@
 
         # According to RFC 2616, "2xx" code indicates that the client's
         # request was successfully received, understood, and accepted.
-        if not (200 <= response.status < 300):
-            return addinfourl(response.fp, response.msg, "http:" + url)
+        if (200 <= response.status < 300):
+            return addinfourl(response.fp, response.msg, "http:" + url,
+                              response.status)
         else:
             return self.http_error(
                 url, response.fp,
@@ -557,7 +558,7 @@
 
     def http_error_default(self, url, fp, errcode, errmsg, headers):
         """Default error handling -- don't raise an exception."""
-        return addinfourl(fp, headers, "http:" + url)
+        return addinfourl(fp, headers, "http:" + url, errcode)
 
     def http_error_302(self, url, fp, errcode, errmsg, headers, data=None):
         """Error 302 -- relocated (temporarily)."""
@@ -815,9 +816,19 @@
         if not conn:
             # Set transfer mode to ASCII!
             self.ftp.voidcmd('TYPE A')
-            # Try a directory listing
-            if file: cmd = 'LIST ' + file
-            else: cmd = 'LIST'
+            # Try a directory listing. Verify that directory exists.
+            if file:
+                pwd = self.ftp.pwd()
+                try:
+                    try:
+                        self.ftp.cwd(file)
+                    except ftplib.error_perm as reason:
+                        raise IOError('ftp error', reason) from reason
+                finally:
+                    self.ftp.cwd(pwd)
+                cmd = 'LIST ' + file
+            else:
+                cmd = 'LIST'
             conn = self.ftp.ntransfercmd(cmd)
         self.busy = 1
         # Pass back both a suitably decorated object and a retrieval length
@@ -898,14 +909,18 @@
 class addinfourl(addbase):
     """class to add info() and geturl() methods to an open file."""
 
-    def __init__(self, fp, headers, url):
+    def __init__(self, fp, headers, url, code=None):
         addbase.__init__(self, fp)
         self.headers = headers
         self.url = url
+        self.code = code
 
     def info(self):
         return self.headers
 
+    def getcode(self):
+        return self.code
+
     def geturl(self):
         return self.url
 
@@ -925,22 +940,14 @@
 # unquote('abc%20def') -> 'abc def'
 # quote('abc def') -> 'abc%20def')
 
-try:
-    str
-except NameError:
-    def _is_unicode(x):
-        return 0
-else:
-    def _is_unicode(x):
-        return isinstance(x, str)
-
 def toBytes(url):
     """toBytes(u"URL") --> 'URL'."""
     # Most URL schemes require ASCII. If that changes, the conversion
-    # can be relaxed
-    if _is_unicode(url):
+    # can be relaxed.
+    # XXX get rid of toBytes()
+    if isinstance(url, str):
         try:
-            url = url.encode("ASCII")
+            url = url.encode("ASCII").decode()
         except UnicodeError:
             raise UnicodeError("URL " + repr(url) +
                                " contains non-ASCII characters")
@@ -1203,7 +1210,7 @@
             if isinstance(v, str):
                 v = quote_plus(v)
                 l.append(k + '=' + v)
-            elif _is_unicode(v):
+            elif isinstance(v, str):
                 # is there a reasonable way to convert to ASCII?
                 # encode generates a string, but "replace" or "ignore"
                 # lose information and "strict" can raise UnicodeError
@@ -1236,10 +1243,33 @@
     proxies = {}
     for name, value in os.environ.items():
         name = name.lower()
+        if name == 'no_proxy':
+            # handled in proxy_bypass_environment
+            continue
         if value and name[-6:] == '_proxy':
             proxies[name[:-6]] = value
     return proxies
 
+def proxy_bypass_environment(host):
+    """Test if proxies should not be used for a particular host.
+
+    Checks the environment for a variable named no_proxy, which should
+    be a list of DNS suffixes separated by commas, or '*' for all hosts.
+    """
+    no_proxy = os.environ.get('no_proxy', '') or os.environ.get('NO_PROXY', '')
+    # '*' is special case for always bypass
+    if no_proxy == '*':
+        return 1
+    # strip port off host
+    hostonly, port = splitport(host)
+    # check if the host ends with any of the DNS suffixes
+    for name in no_proxy.split(','):
+        if name and (hostonly.endswith(name) or host.endswith(name)):
+            return 1
+    # otherwise, don't bypass
+    return 0
+
+
 if sys.platform == 'darwin':
     def getproxies_internetconfig():
         """Return a dictionary of scheme -> proxy server URL mappings.
@@ -1267,12 +1297,15 @@
                 pass
             else:
                 proxies['http'] = 'http://%s' % value
-        # FTP: XXXX To be done.
-        # Gopher: XXXX To be done.
+        # FTP: XXX To be done.
+        # Gopher: XXX To be done.
         return proxies
 
-    def proxy_bypass(x):
-        return 0
+    def proxy_bypass(host):
+        if getproxies_environment():
+            return proxy_bypass_environment(host)
+        else:
+            return 0
 
     def getproxies():
         return getproxies_environment() or getproxies_internetconfig()
@@ -1332,7 +1365,7 @@
         """
         return getproxies_environment() or getproxies_registry()
 
-    def proxy_bypass(host):
+    def proxy_bypass_registry(host):
         try:
             import _winreg
             import re
@@ -1391,12 +1424,22 @@
                     return 1
         return 0
 
+    def proxy_bypass(host):
+        """Return a dictionary of scheme -> proxy server URL mappings.
+
+        Returns settings gathered from the environment, if specified,
+        or the registry.
+
+        """
+        if getproxies_environment():
+            return proxy_bypass_environment(host)
+        else:
+            return proxy_bypass_registry(host)
+
 else:
     # By default use environment variables
     getproxies = getproxies_environment
-
-    def proxy_bypass(host):
-        return 0
+    proxy_bypass = proxy_bypass_environment
 
 # Test and time quote() and unquote()
 def test1():

Modified: python/branches/py3k-importlib/Lib/urllib2.py
==============================================================================
--- python/branches/py3k-importlib/Lib/urllib2.py	(original)
+++ python/branches/py3k-importlib/Lib/urllib2.py	Thu Mar 27 00:48:05 2008
@@ -359,7 +359,7 @@
 
     def open(self, fullurl, data=None, timeout=None):
         # accept a URL or a Request object
-        if isinstance(fullurl, basestring):
+        if isinstance(fullurl, str):
             req = Request(fullurl, data)
         else:
             req = fullurl
@@ -531,8 +531,11 @@
             # do the same.
             # be conciliant with URIs containing a space
             newurl = newurl.replace(' ', '%20')
+            newheaders = dict((k,v) for k,v in req.headers.items()
+                              if k.lower() not in ("content-length", "content-type")
+                             )
             return Request(newurl,
-                           headers=req.headers,
+                           headers=newheaders,
                            origin_req_host=req.get_origin_req_host(),
                            unverifiable=True)
         else:
@@ -702,7 +705,7 @@
 
     def add_password(self, realm, uri, user, passwd):
         # uri could be a single URI or a sequence
-        if isinstance(uri, basestring):
+        if isinstance(uri, str):
             uri = [uri]
         if not realm in self.passwd:
             self.passwd[realm] = {}
@@ -774,7 +777,10 @@
     # XXX this allows for multiple auth-schemes, but will stupidly pick
     # the last one with a realm specified.
 
-    rx = re.compile('(?:.*,)*[ \t]*([^ \t]+)[ \t]+realm="([^"]*)"', re.I)
+    # allow for double- and single-quoted realm values
+    # (single quotes are a violation of the RFC, but appear in the wild)
+    rx = re.compile('(?:.*,)*[ \t]*([^ \t]+)[ \t]+'
+                    'realm=(["\'])(.*?)\\2', re.I)
 
     # XXX could pre-emptively send auth info already accepted (RFC 2617,
     # end of section 2, and section 1.2 immediately after "credentials"
@@ -794,7 +800,7 @@
         if authreq:
             mo = AbstractBasicAuthHandler.rx.search(authreq)
             if mo:
-                scheme, realm = mo.groups()
+                scheme, quote, realm = mo.groups()
                 if scheme.lower() == 'basic':
                     return self.retry_http_basic_auth(host, req, realm)
 
@@ -802,7 +808,7 @@
         user, pw = self.passwd.find_user_password(realm, host)
         if pw is not None:
             raw = "%s:%s" % (user, pw)
-            auth = 'Basic %s' % str(base64.b64encode(raw)).strip()
+            auth = 'Basic %s' % base64.b64encode(raw).strip().decode()
             if req.headers.get(self.auth_header, None) == auth:
                 return None
             req.add_header(self.auth_header, auth)
@@ -1240,7 +1246,7 @@
         import mimetypes
         host = req.get_host()
         if not host:
-            raise URLError('ftp error', 'no host given')
+            raise URLError('ftp error: no host given')
         host, port = splitport(host)
         if port is None:
             port = ftplib.FTP_PORT
@@ -1286,7 +1292,7 @@
             headers = mimetools.Message(sf)
             return addinfourl(fp, headers, req.get_full_url())
         except ftplib.all_errors as msg:
-            raise URLError('ftp error', msg).with_traceback(sys.exc_info()[2])
+            raise URLError('ftp error: %s' % msg).with_traceback(sys.exc_info()[2])
 
     def connect_ftp(self, user, passwd, host, port, dirs, timeout):
         fw = ftpwrapper(user, passwd, host, port, dirs, timeout)

Modified: python/branches/py3k-importlib/Lib/urlparse.py
==============================================================================
--- python/branches/py3k-importlib/Lib/urlparse.py	(original)
+++ python/branches/py3k-importlib/Lib/urlparse.py	Thu Mar 27 00:48:05 2008
@@ -37,52 +37,17 @@
 
 def clear_cache():
     """Clear the parse cache."""
-    global _parse_cache
-    _parse_cache = {}
+    _parse_cache.clear()
 
 
-class BaseResult(tuple):
-    """Base class for the parsed result objects.
-
-    This provides the attributes shared by the two derived result
-    objects as read-only properties.  The derived classes are
-    responsible for checking the right number of arguments were
-    supplied to the constructor.
-
-    """
-
-    __slots__ = ()
-
-    # Attributes that access the basic components of the URL:
-
-    @property
-    def scheme(self):
-        return self[0]
-
-    @property
-    def netloc(self):
-        return self[1]
-
-    @property
-    def path(self):
-        return self[2]
-
-    @property
-    def query(self):
-        return self[-2]
-
-    @property
-    def fragment(self):
-        return self[-1]
-
-    # Additional attributes that provide access to parsed-out portions
-    # of the netloc:
+class ResultMixin(object):
+    """Shared methods for the parsed result objects."""
 
     @property
     def username(self):
         netloc = self.netloc
         if "@" in netloc:
-            userinfo = netloc.split("@", 1)[0]
+            userinfo = netloc.rsplit("@", 1)[0]
             if ":" in userinfo:
                 userinfo = userinfo.split(":", 1)[0]
             return userinfo
@@ -92,7 +57,7 @@
     def password(self):
         netloc = self.netloc
         if "@" in netloc:
-            userinfo = netloc.split("@", 1)[0]
+            userinfo = netloc.rsplit("@", 1)[0]
             if ":" in userinfo:
                 return userinfo.split(":", 1)[1]
         return None
@@ -101,7 +66,7 @@
     def hostname(self):
         netloc = self.netloc
         if "@" in netloc:
-            netloc = netloc.split("@", 1)[1]
+            netloc = netloc.rsplit("@", 1)[1]
         if ":" in netloc:
             netloc = netloc.split(":", 1)[0]
         return netloc.lower() or None
@@ -110,37 +75,26 @@
     def port(self):
         netloc = self.netloc
         if "@" in netloc:
-            netloc = netloc.split("@", 1)[1]
+            netloc = netloc.rsplit("@", 1)[1]
         if ":" in netloc:
             port = netloc.split(":", 1)[1]
             return int(port, 10)
         return None
 
+from collections import namedtuple
 
-class SplitResult(BaseResult):
+class SplitResult(namedtuple('SplitResult', 'scheme netloc path query fragment'), ResultMixin):
 
     __slots__ = ()
 
-    def __new__(cls, scheme, netloc, path, query, fragment):
-        return BaseResult.__new__(
-            cls, (scheme, netloc, path, query, fragment))
-
     def geturl(self):
         return urlunsplit(self)
 
 
-class ParseResult(BaseResult):
+class ParseResult(namedtuple('ParseResult', 'scheme netloc path params query fragment'), ResultMixin):
 
     __slots__ = ()
 
-    def __new__(cls, scheme, netloc, path, params, query, fragment):
-        return BaseResult.__new__(
-            cls, (scheme, netloc, path, params, query, fragment))
-
-    @property
-    def params(self):
-        return self[3]
-
     def geturl(self):
         return urlunparse(self)
 
@@ -169,13 +123,12 @@
     return url[:i], url[i+1:]
 
 def _splitnetloc(url, start=0):
-    for c in '/?#': # the order is important!
-        delim = url.find(c, start)
-        if delim >= 0:
-            break
-    else:
-        delim = len(url)
-    return url[start:delim], url[delim:]
+    delim = len(url)   # position of end of domain part of url, default is end
+    for c in '/?#':    # look for delimiters; the order is NOT important
+        wdelim = url.find(c, start)        # find first of this delim
+        if wdelim >= 0:                    # if found
+            delim = min(delim, wdelim)     # use earliest delim position
+    return url[start:delim], url[delim:]   # return (domain, rest)
 
 def urlsplit(url, scheme='', allow_fragments=True):
     """Parse a URL into 5 components:
@@ -184,7 +137,7 @@
     Note that we don't break the components up in smaller bits
     (e.g. netloc is a single string) and we don't expand % escapes."""
     allow_fragments = bool(allow_fragments)
-    key = url, scheme, allow_fragments
+    key = url, scheme, allow_fragments, type(url), type(scheme)
     cached = _parse_cache.get(key, None)
     if cached:
         return cached
@@ -352,9 +305,7 @@
     else:
         from io import StringIO
         fp = StringIO(test_input)
-    while 1:
-        line = fp.readline()
-        if not line: break
+    for line in fp:
         words = line.split()
         if not words:
             continue

Modified: python/branches/py3k-importlib/Lib/uu.py
==============================================================================
--- python/branches/py3k-importlib/Lib/uu.py	(original)
+++ python/branches/py3k-importlib/Lib/uu.py	Thu Mar 27 00:48:05 2008
@@ -46,7 +46,7 @@
     #
     if in_file == '-':
         in_file = sys.stdin.buffer
-    elif isinstance(in_file, basestring):
+    elif isinstance(in_file, str):
         if name is None:
             name = os.path.basename(in_file)
         if mode is None:
@@ -60,7 +60,7 @@
     #
     if out_file == '-':
         out_file = sys.stdout.buffer
-    elif isinstance(out_file, basestring):
+    elif isinstance(out_file, str):
         out_file = open(out_file, 'wb')
     #
     # Set defaults for name and mode
@@ -87,7 +87,7 @@
     #
     if in_file == '-':
         in_file = sys.stdin.buffer
-    elif isinstance(in_file, basestring):
+    elif isinstance(in_file, str):
         in_file = open(in_file, 'rb')
     #
     # Read until a begin is encountered or we've exhausted the file
@@ -118,7 +118,7 @@
     opened = False
     if out_file == '-':
         out_file = sys.stdout.buffer
-    elif isinstance(out_file, basestring):
+    elif isinstance(out_file, str):
         fp = open(out_file, 'wb')
         try:
             os.path.chmod(out_file, mode)
@@ -169,7 +169,7 @@
 
     if options.decode:
         if options.text:
-            if isinstance(output, basestring):
+            if isinstance(output, str):
                 output = open(output, 'wb')
             else:
                 print(sys.argv[0], ': cannot do -t to stdout')
@@ -177,7 +177,7 @@
         decode(input, output)
     else:
         if options.text:
-            if isinstance(input, basestring):
+            if isinstance(input, str):
                 input = open(input, 'rb')
             else:
                 print(sys.argv[0], ': cannot do -t from stdin')

Modified: python/branches/py3k-importlib/Lib/uuid.py
==============================================================================
--- python/branches/py3k-importlib/Lib/uuid.py	(original)
+++ python/branches/py3k-importlib/Lib/uuid.py	Thu Mar 27 00:48:05 2008
@@ -234,7 +234,7 @@
 
     @property
     def bytes(self):
-        bytes = b''
+        bytes = bytearray()
         for shift in range(0, 128, 8):
             bytes.insert(0, (self.int >> shift) & 0xff)
         return bytes
@@ -548,7 +548,7 @@
         return UUID(bytes=os.urandom(16), version=4)
     except:
         import random
-        bytes = [chr(random.randrange(256)) for i in range(16)]
+        bytes = bytes_(random.randrange(256) for i in range(16))
         return UUID(bytes=bytes, version=4)
 
 def uuid5(namespace, name):

Modified: python/branches/py3k-importlib/Lib/warnings.py
==============================================================================
--- python/branches/py3k-importlib/Lib/warnings.py	(original)
+++ python/branches/py3k-importlib/Lib/warnings.py	Thu Mar 27 00:48:05 2008
@@ -150,10 +150,10 @@
     import re
     assert action in ("error", "ignore", "always", "default", "module",
                       "once"), "invalid action: %r" % (action,)
-    assert isinstance(message, basestring), "message must be a string"
+    assert isinstance(message, str), "message must be a string"
     assert isinstance(category, type), "category must be a class"
     assert issubclass(category, Warning), "category must be a Warning subclass"
-    assert isinstance(module, basestring), "module must be a string"
+    assert isinstance(module, str), "module must be a string"
     assert isinstance(lineno, int) and lineno >= 0, \
            "lineno must be an int >= 0"
     item = (action, re.compile(message, re.I), category,

Modified: python/branches/py3k-importlib/Lib/wave.py
==============================================================================
--- python/branches/py3k-importlib/Lib/wave.py	(original)
+++ python/branches/py3k-importlib/Lib/wave.py	Thu Mar 27 00:48:05 2008
@@ -71,7 +71,7 @@
 is destroyed.
 """
 
-import __builtin__
+import builtins
 
 __all__ = ["open", "openfp", "Error"]
 
@@ -155,8 +155,8 @@
 
     def __init__(self, f):
         self._i_opened_the_file = None
-        if isinstance(f, basestring):
-            f = __builtin__.open(f, 'rb')
+        if isinstance(f, str):
+            f = builtins.open(f, 'rb')
             self._i_opened_the_file = f
         # else, assume it is an open file object already
         try:
@@ -299,8 +299,8 @@
 
     def __init__(self, f):
         self._i_opened_the_file = None
-        if isinstance(f, basestring):
-            f = __builtin__.open(f, 'wb')
+        if isinstance(f, str):
+            f = builtins.open(f, 'wb')
             self._i_opened_the_file = f
         try:
             self.initfp(f)

Modified: python/branches/py3k-importlib/Lib/weakref.py
==============================================================================
--- python/branches/py3k-importlib/Lib/weakref.py	(original)
+++ python/branches/py3k-importlib/Lib/weakref.py	Thu Mar 27 00:48:05 2008
@@ -9,7 +9,7 @@
 # they are called this instead of "ref" to avoid name collisions with
 # the module-global ref() function imported from _weakref.
 
-import UserDict
+import collections
 
 from _weakref import (
      getweakrefcount,
@@ -20,15 +20,17 @@
      ProxyType,
      ReferenceType)
 
+from _weakrefset import WeakSet
 
 ProxyTypes = (ProxyType, CallableProxyType)
 
 __all__ = ["ref", "proxy", "getweakrefcount", "getweakrefs",
            "WeakKeyDictionary", "ReferenceType", "ProxyType",
-           "CallableProxyType", "ProxyTypes", "WeakValueDictionary"]
+           "CallableProxyType", "ProxyTypes", "WeakValueDictionary",
+           "WeakSet"]
 
 
-class WeakValueDictionary(UserDict.UserDict):
+class WeakValueDictionary(collections.MutableMapping):
     """Mapping class that references values weakly.
 
     Entries in the dictionary will be discarded when no strong
@@ -46,7 +48,8 @@
             if self is not None:
                 del self.data[wr.key]
         self._remove = remove
-        UserDict.UserDict.__init__(self, *args, **kw)
+        self.data = d = {}
+        d.update(*args, **kw)
 
     def __getitem__(self, key):
         o = self.data[key]()
@@ -55,6 +58,12 @@
         else:
             return o
 
+    def __delitem__(self, key):
+        del self.data[key]
+
+    def __len__(self):
+        return sum(wr() is not None for wr in self.data.values())
+
     def __contains__(self, key):
         try:
             o = self.data[key]()
@@ -207,7 +216,7 @@
         super().__init__(ob, callback)
 
 
-class WeakKeyDictionary(UserDict.UserDict):
+class WeakKeyDictionary(collections.MutableMapping):
     """ Mapping class that references keys weakly.
 
     Entries in the dictionary will be discarded when there is no
@@ -233,6 +242,9 @@
     def __getitem__(self, key):
         return self.data[ref(key)]
 
+    def __len__(self):
+        return len(self.data)
+
     def __repr__(self):
         return "<WeakKeyDictionary at %s>" % id(self)
 

Modified: python/branches/py3k-importlib/Lib/webbrowser.py
==============================================================================
--- python/branches/py3k-importlib/Lib/webbrowser.py	(original)
+++ python/branches/py3k-importlib/Lib/webbrowser.py	Thu Mar 27 00:48:05 2008
@@ -159,7 +159,7 @@
        and without remote functionality."""
 
     def __init__(self, name):
-        if isinstance(name, basestring):
+        if isinstance(name, str):
             self.name = name
             self.args = ["%s"]
         else:

Modified: python/branches/py3k-importlib/Lib/xml/dom/domreg.py
==============================================================================
--- python/branches/py3k-importlib/Lib/xml/dom/domreg.py	(original)
+++ python/branches/py3k-importlib/Lib/xml/dom/domreg.py	Thu Mar 27 00:48:05 2008
@@ -62,7 +62,7 @@
 
     # User did not specify a name, try implementations in arbitrary
     # order, returning the one that has the required features
-    if isinstance(features, StringTypes):
+    if isinstance(features, str):
         features = _parse_feature_string(features)
     for creator in registered.values():
         dom = creator()

Modified: python/branches/py3k-importlib/Lib/xml/dom/expatbuilder.py
==============================================================================
--- python/branches/py3k-importlib/Lib/xml/dom/expatbuilder.py	(original)
+++ python/branches/py3k-importlib/Lib/xml/dom/expatbuilder.py	Thu Mar 27 00:48:05 2008
@@ -918,7 +918,7 @@
     else:
         builder = ExpatBuilder()
 
-    if isinstance(file, StringTypes):
+    if isinstance(file, str):
         fp = open(file, 'rb')
         try:
             result = builder.parseFile(fp)
@@ -952,7 +952,7 @@
     else:
         builder = FragmentBuilder(context)
 
-    if isinstance(file, StringTypes):
+    if isinstance(file, str):
         fp = open(file, 'rb')
         try:
             result = builder.parseFile(fp)

Modified: python/branches/py3k-importlib/Lib/xml/dom/minicompat.py
==============================================================================
--- python/branches/py3k-importlib/Lib/xml/dom/minicompat.py	(original)
+++ python/branches/py3k-importlib/Lib/xml/dom/minicompat.py	Thu Mar 27 00:48:05 2008
@@ -95,7 +95,7 @@
 
 
 def defproperty(klass, name, doc):
-    get = getattr(klass, ("_get_" + name)).im_func
+    get = getattr(klass, ("_get_" + name))
     def set(self, value, name=name):
         raise xml.dom.NoModificationAllowedErr(
             "attempt to modify read-only attribute " + repr(name))

Modified: python/branches/py3k-importlib/Lib/xml/dom/minidom.py
==============================================================================
--- python/branches/py3k-importlib/Lib/xml/dom/minidom.py	(original)
+++ python/branches/py3k-importlib/Lib/xml/dom/minidom.py	Thu Mar 27 00:48:05 2008
@@ -204,6 +204,8 @@
                 L.append(child)
                 if child.nodeType == Node.ELEMENT_NODE:
                     child.normalize()
+        if L:
+            L[-1].nextSibling = None
         self.childNodes[:] = L
 
     def cloneNode(self, deep):
@@ -498,7 +500,7 @@
         return L
 
     def __contains__(self, key):
-        if isinstance(key, StringTypes):
+        if isinstance(key, str):
             return key in self._attrs
         else:
             return key in self._attrsNS
@@ -531,7 +533,7 @@
 
     # same as set
     def __setitem__(self, attname, value):
-        if isinstance(value, StringTypes):
+        if isinstance(value, str):
             try:
                 node = self._attrs[attname]
             except KeyError:
@@ -960,7 +962,7 @@
             dotdotdot = "..."
         else:
             dotdotdot = ""
-        return "<DOM %s node \"%s%s\">" % (
+        return '<DOM %s node "%r%s">' % (
             self.__class__.__name__, data[0:10], dotdotdot)
 
     def substringData(self, offset, count):
@@ -1606,7 +1608,7 @@
         return e
 
     def createTextNode(self, data):
-        if not isinstance(data, StringTypes):
+        if not isinstance(data, str):
             raise TypeError("node contents must be a string")
         t = Text()
         t.data = data
@@ -1614,7 +1616,7 @@
         return t
 
     def createCDATASection(self, data):
-        if not isinstance(data, StringTypes):
+        if not isinstance(data, str):
             raise TypeError("node contents must be a string")
         c = CDATASection()
         c.data = data
@@ -1927,7 +1929,7 @@
 
 def getDOMImplementation(features=None):
     if features:
-        if isinstance(features, StringTypes):
+        if isinstance(features, str):
             features = domreg._parse_feature_string(features)
         for f, v in features:
             if not Document.implementation.hasFeature(f, v):

Modified: python/branches/py3k-importlib/Lib/xml/dom/pulldom.py
==============================================================================
--- python/branches/py3k-importlib/Lib/xml/dom/pulldom.py	(original)
+++ python/branches/py3k-importlib/Lib/xml/dom/pulldom.py	Thu Mar 27 00:48:05 2008
@@ -325,7 +325,7 @@
 def parse(stream_or_string, parser=None, bufsize=None):
     if bufsize is None:
         bufsize = default_bufsize
-    if isinstance(stream_or_string, basestring):
+    if isinstance(stream_or_string, str):
         stream = open(stream_or_string)
     else:
         stream = stream_or_string

Modified: python/branches/py3k-importlib/Lib/xml/sax/saxutils.py
==============================================================================
--- python/branches/py3k-importlib/Lib/xml/sax/saxutils.py	(original)
+++ python/branches/py3k-importlib/Lib/xml/sax/saxutils.py	Thu Mar 27 00:48:05 2008
@@ -272,7 +272,7 @@
     """This function takes an InputSource and an optional base URL and
     returns a fully resolved InputSource object ready for reading."""
 
-    if isinstance(source, basestring):
+    if isinstance(source, str):
         source = xmlreader.InputSource(source)
     elif hasattr(source, "read"):
         f = source

Modified: python/branches/py3k-importlib/Lib/xmlrpclib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/xmlrpclib.py	(original)
+++ python/branches/py3k-importlib/Lib/xmlrpclib.py	Thu Mar 27 00:48:05 2008
@@ -294,17 +294,10 @@
     """
 
     def __init__(self, value=0):
-        if not isinstance(value, basestring):
+        if not isinstance(value, str):
             if datetime and isinstance(value, datetime.datetime):
                 self.value = value.strftime("%Y%m%dT%H:%M:%S")
                 return
-            if datetime and isinstance(value, datetime.date):
-                self.value = value.strftime("%Y%m%dT%H:%M:%S")
-                return
-            if datetime and isinstance(value, datetime.time):
-                today = datetime.datetime.now().strftime("%Y%m%d")
-                self.value = value.strftime(today+"T%H:%M:%S")
-                return
             if not isinstance(value, (tuple, time.struct_time)):
                 if value == 0:
                     value = time.time()
@@ -312,15 +305,57 @@
             value = time.strftime("%Y%m%dT%H:%M:%S", value)
         self.value = value
 
-    def __eq__(self, other):
+    def make_comparable(self, other):
         if isinstance(other, DateTime):
-            other = other.value
-        return self.value == other
+            s = self.value
+            o = other.value
+        elif datetime and isinstance(other, datetime.datetime):
+            s = self.value
+            o = other.strftime("%Y%m%dT%H:%M:%S")
+        elif isinstance(other, (str, unicode)):
+            s = self.value
+            o = other
+        elif hasattr(other, "timetuple"):
+            s = self.timetuple()
+            o = other.timetuple()
+        else:
+            otype = (hasattr(other, "__class__")
+                     and other.__class__.__name__
+                     or type(other))
+            raise TypeError("Can't compare %s and %s" %
+                            (self.__class__.__name__, otype))
+        return s, o
+
+    def __lt__(self, other):
+        s, o = self.make_comparable(other)
+        return s < o
+
+    def __le__(self, other):
+        s, o = self.make_comparable(other)
+        return s <= o
+
+    def __gt__(self, other):
+        s, o = self.make_comparable(other)
+        return s > o
+
+    def __ge__(self, other):
+        s, o = self.make_comparable(other)
+        return s >= o
+
+    def __eq__(self, other):
+        s, o = self.make_comparable(other)
+        return s == o
 
     def __ne__(self, other):
-        if isinstance(other, DateTime):
-            other = other.value
-        return self.value != other
+        s, o = self.make_comparable(other)
+        return s != o
+
+    def timetuple(self):
+        return time.strptime(self.value, "%Y%m%dT%H:%M:%S")
+
+    def __cmp__(self, other):
+        s, o = self.make_comparable(other)
+        return cmp(s, o)
 
     ##
     # Get date/time value.
@@ -622,7 +657,7 @@
         write("<value><string>")
         write(escape(value))
         write("</string></value>\n")
-    dispatch[str8] = dump_string
+    dispatch[bytes] = dump_string
 
     def dump_unicode(self, value, write, escape=escape):
         write("<value><string>")
@@ -653,7 +688,7 @@
         write("<value><struct>\n")
         for k, v in value.items():
             write("<member>\n")
-            if not isinstance(k, basestring):
+            if not isinstance(k, str):
                 raise TypeError("dictionary key must be string")
             write("<name>%s</name>\n" % escape(k))
             dump(v, write)
@@ -669,19 +704,6 @@
             write("</dateTime.iso8601></value>\n")
         dispatch[datetime.datetime] = dump_datetime
 
-        def dump_date(self, value, write):
-            write("<value><dateTime.iso8601>")
-            write(value.strftime("%Y%m%dT00:00:00"))
-            write("</dateTime.iso8601></value>\n")
-        dispatch[datetime.date] = dump_date
-
-        def dump_time(self, value, write):
-            write("<value><dateTime.iso8601>")
-            write(datetime.datetime.now().date().strftime("%Y%m%dT"))
-            write(value.strftime("%H:%M:%S"))
-            write("</dateTime.iso8601></value>\n")
-        dispatch[datetime.time] = dump_time
-
     def dump_instance(self, value, write):
         # check for special wrappers
         if value.__class__ in WRAPPERS:
@@ -1031,7 +1053,7 @@
     # standard XML-RPC wrappings
     if methodname:
         # a method call
-        if not isinstance(methodname, basestring):
+        if not isinstance(methodname, str):
             methodname = methodname.encode(encoding)
         data = (
             xmlheader,

Modified: python/branches/py3k-importlib/Lib/zipfile.py
==============================================================================
--- python/branches/py3k-importlib/Lib/zipfile.py	(original)
+++ python/branches/py3k-importlib/Lib/zipfile.py	Thu Mar 27 00:48:05 2008
@@ -3,13 +3,15 @@
 
 XXX references to utf-8 need further investigation.
 """
-import struct, os, time, sys
+import struct, os, time, sys, shutil
 import binascii, io
 
 try:
     import zlib # We may need its compression method
+    crc32 = zlib.crc32
 except ImportError:
     zlib = None
+    crc32 = binascii.crc32
 
 __all__ = ["BadZipfile", "error", "ZIP_STORED", "ZIP_DEFLATED", "is_zipfile",
            "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile" ]
@@ -34,15 +36,15 @@
 # Other ZIP compression methods not supported
 
 # Here are some struct module formats for reading headers
-structEndArchive = "<4s4H2lH"     # 9 items, end of archive, 22 bytes
+structEndArchive = "<4s4H2LH"     # 9 items, end of archive, 22 bytes
 stringEndArchive = b"PK\005\006"   # magic number for end of archive record
-structCentralDir = "<4s4B4HlLL5HLl"# 19 items, central directory, 46 bytes
+structCentralDir = "<4s4B4HLLL5HLL"# 19 items, central directory, 46 bytes
 stringCentralDir = b"PK\001\002"   # magic number for central directory
-structFileHeader = "<4s2B4HlLL2H"  # 12 items, file header record, 30 bytes
+structFileHeader = "<4s2B4HLLL2H"  # 12 items, file header record, 30 bytes
 stringFileHeader = b"PK\003\004"   # magic number for file header
-structEndArchive64Locator = "<4slql" # 4 items, locate Zip64 header, 20 bytes
+structEndArchive64Locator = "<4sLQL" # 4 items, locate Zip64 header, 20 bytes
 stringEndArchive64Locator = b"PK\x06\x07" # magic token for locator header
-structEndArchive64 = "<4sqhhllqqqq" # 10 items, end of archive (Zip64), 56 bytes
+structEndArchive64 = "<4sQHHLLQQQQ" # 10 items, end of archive (Zip64), 56 bytes
 stringEndArchive64 = b"PK\x06\x06" # magic token for Zip64 header
 
 
@@ -140,7 +142,7 @@
         endrec = list(endrec)
         endrec.append("")               # Append the archive comment
         endrec.append(filesize - 22)    # Append the record start offset
-        if endrec[-4] == -1 or endrec[-4] == 0xffffffff:
+        if endrec[-4] == 0xffffffff:
             return _EndRecData64(fpin, -22, endrec)
         return endrec
     # Search the last END_BLOCK bytes of the file for the record signature.
@@ -160,7 +162,7 @@
             # Append the archive comment and start offset
             endrec.append(comment)
             endrec.append(filesize - END_BLOCK + start)
-            if endrec[-4] == -1 or endrec[-4] == 0xffffffff:
+            if endrec[-4] == 0xffffffff:
                 return _EndRecData64(fpin, - END_BLOCK + start, endrec)
             return endrec
     return      # Error, return None
@@ -188,6 +190,7 @@
             'CRC',
             'compress_size',
             'file_size',
+            '_raw_time',
         )
 
     def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)):
@@ -246,7 +249,7 @@
         if file_size > ZIP64_LIMIT or compress_size > ZIP64_LIMIT:
             # File is larger than what fits into a 4 byte integer,
             # fall back to the ZIP64 extension
-            fmt = '<hhqq'
+            fmt = '<HHQQ'
             extra = extra + struct.pack(fmt,
                     1, struct.calcsize(fmt)-4, file_size, compress_size)
             file_size = 0xffffffff # -1
@@ -266,14 +269,14 @@
         extra = self.extra
         unpack = struct.unpack
         while extra:
-            tp, ln = unpack('<hh', extra[:4])
+            tp, ln = unpack('<HH', extra[:4])
             if tp == 1:
                 if ln >= 24:
-                    counts = unpack('<qqq', extra[4:28])
+                    counts = unpack('<QQQ', extra[4:28])
                 elif ln == 16:
-                    counts = unpack('<qq', extra[4:20])
+                    counts = unpack('<QQ', extra[4:20])
                 elif ln == 8:
-                    counts = unpack('<q', extra[4:12])
+                    counts = unpack('<Q', extra[4:12])
                 elif ln == 0:
                     counts = ()
                 else:
@@ -282,7 +285,8 @@
                 idx = 0
 
                 # ZIP64 extension (large files and/or large archives)
-                if self.file_size == -1 or self.file_size == 0xFFFFFFFF:
+                # XXX Is this correct? won't this exclude 2**32-1 byte files?
+                if self.file_size in (0xffffffffffffffff, 0xffffffff):
                     self.file_size = counts[idx]
                     idx += 1
 
@@ -303,7 +307,7 @@
 
     ZIP supports a password-based form of encryption. Even though known
     plaintext attacks have been found against it, it is still useful
-    for low-level securicy.
+    to be able to get data out of such a file.
 
     Usage:
         zd = _ZipDecrypter(mypwd)
@@ -428,7 +432,7 @@
            read a whole line.
         """
         if size < 0:
-            size = sys.maxint
+            size = sys.maxsize
         elif size == 0:
             return b''
 
@@ -596,7 +600,7 @@
         self.pwd = None
 
         # Check if we were passed a file-like object
-        if isinstance(file, basestring):
+        if isinstance(file, str):
             # No, it's a filename
             self._filePassed = 0
             self.filename = file
@@ -678,7 +682,7 @@
                 print(centdir)
             filename = fp.read(centdir[_CD_FILENAME_LENGTH])
             # Create ZipInfo instance to store file information
-            x = ZipInfo(str(filename))
+            x = ZipInfo(filename.decode("utf-8"))
             x.extra = fp.read(centdir[_CD_EXTRA_FIELD_LENGTH])
             x.comment = fp.read(centdir[_CD_COMMENT_LENGTH])
             total = (total + centdir[_CD_FILENAME_LENGTH]
@@ -690,6 +694,7 @@
                 x.CRC, x.compress_size, x.file_size) = centdir[1:12]
             x.volume, x.internal_attr, x.external_attr = centdir[15:18]
             # Convert date/time code to (year, month, day, hour, min, sec)
+            x._raw_time = t
             x.date_time = ( (d>>9)+1980, (d>>5)&0xF, d&0x1F,
                                      t>>11, (t>>5)&0x3F, (t&0x1F) * 2 )
 
@@ -718,7 +723,7 @@
         print("%-46s %19s %12s" % ("File Name", "Modified    ", "Size"),
               file=file)
         for zinfo in self.filelist:
-            date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time
+            date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time[:6]
             print("%-46s %s %12d" % (zinfo.filename, date, zinfo.file_size),
                   file=file)
 
@@ -800,11 +805,18 @@
             # The first 12 bytes in the cypher stream is an encryption header
             #  used to strengthen the algorithm. The first 11 bytes are
             #  completely random, while the 12th contains the MSB of the CRC,
+            #  or the MSB of the file time depending on the header type
             #  and is used to check the correctness of the password.
             bytes = zef_file.read(12)
             h = list(map(zd, bytes[0:12]))
-            if h[11] != ((zinfo.CRC>>24) & 255):
-                raise RuntimeError("Bad password for file %s" % name)
+            if zinfo.flag_bits & 0x8:
+                # compare against the file type from extended local headers
+                check_byte = (zinfo._raw_time >> 8) & 0xff
+            else:
+                # compare against the CRC otherwise
+                check_byte = (zinfo.CRC >> 24) & 0xff
+            if h[11] != check_byte:
+                raise RuntimeError("Bad password for file", name)
 
         # build and return a ZipExtFile
         if zd is None:
@@ -817,6 +829,62 @@
             zef.set_univ_newlines(True)
         return zef
 
+    def extract(self, member, path=None, pwd=None):
+        """Extract a member from the archive to the current working directory,
+           using its full name. Its file information is extracted as accurately
+           as possible. `member' may be a filename or a ZipInfo object. You can
+           specify a different directory using `path'.
+        """
+        if not isinstance(member, ZipInfo):
+            member = self.getinfo(member)
+
+        if path is None:
+            path = os.getcwd()
+
+        return self._extract_member(member, path, pwd)
+
+    def extractall(self, path=None, members=None, pwd=None):
+        """Extract all members from the archive to the current working
+           directory. `path' specifies a different directory to extract to.
+           `members' is optional and must be a subset of the list returned
+           by namelist().
+        """
+        if members is None:
+            members = self.namelist()
+
+        for zipinfo in members:
+            self.extract(zipinfo, path, pwd)
+
+    def _extract_member(self, member, targetpath, pwd):
+        """Extract the ZipInfo object 'member' to a physical
+           file on the path targetpath.
+        """
+        # build the destination pathname, replacing
+        # forward slashes to platform specific separators.
+        if targetpath[-1:] == "/":
+            targetpath = targetpath[:-1]
+
+        # don't include leading "/" from file name if present
+        if os.path.isabs(member.filename):
+            targetpath = os.path.join(targetpath, member.filename[1:])
+        else:
+            targetpath = os.path.join(targetpath, member.filename)
+
+        targetpath = os.path.normpath(targetpath)
+
+        # Create all upper directories if necessary.
+        upperdirs = os.path.dirname(targetpath)
+        if upperdirs and not os.path.exists(upperdirs):
+            os.makedirs(upperdirs)
+
+        source = self.open(member.filename, pwd=pwd)
+        target = open(targetpath, "wb")
+        shutil.copyfileobj(source, target)
+        source.close()
+        target.close()
+
+        return targetpath
+
     def _writecheck(self, zinfo):
         """Check for errors before writing a file to the archive."""
         if zinfo.filename in self.NameToInfo:
@@ -885,7 +953,7 @@
             if not buf:
                 break
             file_size = file_size + len(buf)
-            CRC = binascii.crc32(buf, CRC)
+            CRC = crc32(buf, CRC) & 0xffffffff
             if cmpr:
                 buf = cmpr.compress(buf)
                 compress_size = compress_size + len(buf)
@@ -903,7 +971,7 @@
         # Seek backwards and write CRC and file sizes
         position = self.fp.tell()       # Preserve current position in file
         self.fp.seek(zinfo.header_offset + 14, 0)
-        self.fp.write(struct.pack("<lLL", zinfo.CRC, zinfo.compress_size,
+        self.fp.write(struct.pack("<LLL", zinfo.CRC, zinfo.compress_size,
               zinfo.file_size))
         self.fp.seek(position, 0)
         self.filelist.append(zinfo)
@@ -919,7 +987,7 @@
             data = data.encode("utf-8")
         if not isinstance(zinfo_or_arcname, ZipInfo):
             zinfo = ZipInfo(filename=zinfo_or_arcname,
-                            date_time=time.localtime(time.time()))
+                            date_time=time.localtime(time.time())[:6])
             zinfo.compress_type = self.compression
         else:
             zinfo = zinfo_or_arcname
@@ -932,7 +1000,7 @@
         zinfo.header_offset = self.fp.tell()    # Start of header data
         self._writecheck(zinfo)
         self._didModify = True
-        zinfo.CRC = binascii.crc32(data)       # CRC-32 checksum
+        zinfo.CRC = crc32(data) & 0xffffffff       # CRC-32 checksum
         if zinfo.compress_type == ZIP_DEFLATED:
             co = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
                  zlib.DEFLATED, -15)
@@ -982,7 +1050,7 @@
 
                 if zinfo.header_offset > ZIP64_LIMIT:
                     extra.append(zinfo.header_offset)
-                    header_offset = -1  # struct "l" format:  32 one bits
+                    header_offset = 0xffffffff  # -1 32 bit
                 else:
                     header_offset = zinfo.header_offset
 
@@ -990,7 +1058,7 @@
                 if extra:
                     # Append a ZIP64 field to the extra's
                     extra_data = struct.pack(
-                            '<hh' + 'q'*len(extra),
+                            '<HH' + 'Q'*len(extra),
                             1, 8*len(extra), *extra) + extra_data
 
                     extract_version = max(45, zinfo.extract_version)
@@ -1000,13 +1068,13 @@
                     create_version = zinfo.create_version
 
                 centdir = struct.pack(structCentralDir,
-                  stringCentralDir, create_version,
-                  zinfo.create_system, extract_version, zinfo.reserved,
-                  zinfo.flag_bits, zinfo.compress_type, dostime, dosdate,
-                  zinfo.CRC, compress_size, file_size,
-                  len(zinfo.filename), len(extra_data), len(zinfo.comment),
-                  0, zinfo.internal_attr, zinfo.external_attr,
-                  header_offset)
+                 stringCentralDir, create_version,
+                 zinfo.create_system, extract_version, zinfo.reserved,
+                 zinfo.flag_bits, zinfo.compress_type, dostime, dosdate,
+                 zinfo.CRC, compress_size, file_size,
+                 len(zinfo.filename), len(extra_data), len(zinfo.comment),
+                 0, zinfo.internal_attr, zinfo.external_attr,
+                 header_offset)
                 self.fp.write(centdir)
                 self.fp.write(zinfo.filename.encode("utf-8"))
                 self.fp.write(extra_data)
@@ -1026,10 +1094,8 @@
                         stringEndArchive64Locator, 0, pos2, 1)
                 self.fp.write(zip64locrec)
 
-                # XXX Why is `pos3` computed next?  It's never referenced.
-                pos3 = self.fp.tell()
                 endrec = struct.pack(structEndArchive, stringEndArchive,
-                            0, 0, count, count, pos2 - pos1, -1, 0)
+                            0, 0, count, count, pos2 - pos1, 0xffffffff, 0)
                 self.fp.write(endrec)
 
             else:

Modified: python/branches/py3k-importlib/Mac/Demo/PICTbrowse/ICONbrowse.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Demo/PICTbrowse/ICONbrowse.py	(original)
+++ python/branches/py3k-importlib/Mac/Demo/PICTbrowse/ICONbrowse.py	Thu Mar 27 00:48:05 2008
@@ -7,8 +7,6 @@
 from Carbon import Win
 from Carbon import Controls
 from Carbon import List
-import sys
-import struct
 from Carbon import Icn
 import macresource
 

Modified: python/branches/py3k-importlib/Mac/Demo/PICTbrowse/PICTbrowse.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Demo/PICTbrowse/PICTbrowse.py	(original)
+++ python/branches/py3k-importlib/Mac/Demo/PICTbrowse/PICTbrowse.py	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,6 @@
 from Carbon import Win
 from Carbon import Controls
 from Carbon import List
-import sys
 import struct
 import macresource
 

Modified: python/branches/py3k-importlib/Mac/Demo/PICTbrowse/PICTbrowse2.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Demo/PICTbrowse/PICTbrowse2.py	(original)
+++ python/branches/py3k-importlib/Mac/Demo/PICTbrowse/PICTbrowse2.py	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,6 @@
 from Carbon import Win
 from Carbon import Controls
 from Carbon import List
-import sys
 import struct
 import macresource
 

Modified: python/branches/py3k-importlib/Mac/Demo/PICTbrowse/cicnbrowse.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Demo/PICTbrowse/cicnbrowse.py	(original)
+++ python/branches/py3k-importlib/Mac/Demo/PICTbrowse/cicnbrowse.py	Thu Mar 27 00:48:05 2008
@@ -7,8 +7,6 @@
 from Carbon import Win
 from Carbon import Controls
 from Carbon import List
-import sys
-import struct
 from Carbon import Icn
 import macresource
 

Modified: python/branches/py3k-importlib/Mac/Demo/PICTbrowse/oldPICTbrowse.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Demo/PICTbrowse/oldPICTbrowse.py	(original)
+++ python/branches/py3k-importlib/Mac/Demo/PICTbrowse/oldPICTbrowse.py	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,6 @@
 from Carbon import Qd
 from Carbon import Win
 from Carbon import List
-import sys
 import struct
 import macresource
 

Modified: python/branches/py3k-importlib/Mac/Demo/example1/dnslookup-1.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Demo/example1/dnslookup-1.py	(original)
+++ python/branches/py3k-importlib/Mac/Demo/example1/dnslookup-1.py	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,6 @@
 import EasyDialogs
 from Carbon import Res
 from Carbon import Dlg
-import sys
 import socket
 import string
 import macresource

Modified: python/branches/py3k-importlib/Mac/Demo/example2/dnslookup-2.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Demo/example2/dnslookup-2.py	(original)
+++ python/branches/py3k-importlib/Mac/Demo/example2/dnslookup-2.py	Thu Mar 27 00:48:05 2008
@@ -2,7 +2,6 @@
 import EasyDialogs
 from Carbon import Res
 from Carbon import Dlg
-import sys
 import socket
 import string
 import macresource

Modified: python/branches/py3k-importlib/Mac/Demo/imgbrowse/imgbrowse.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Demo/imgbrowse/imgbrowse.py	(original)
+++ python/branches/py3k-importlib/Mac/Demo/imgbrowse/imgbrowse.py	Thu Mar 27 00:48:05 2008
@@ -7,11 +7,9 @@
 from Carbon import QuickDraw
 from Carbon import Win
 #ifrom Carbon mport List
-import sys
 import struct
 import img
 import imgformat
-import struct
 import mac_image
 
 

Modified: python/branches/py3k-importlib/Mac/Demo/imgbrowse/mac_image.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Demo/imgbrowse/mac_image.py	(original)
+++ python/branches/py3k-importlib/Mac/Demo/imgbrowse/mac_image.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 """mac_image - Helper routines (hacks) for images"""
 import imgformat
 from Carbon import Qd
-import time
 import struct
 import MacOS
 

Modified: python/branches/py3k-importlib/Mac/Modules/MacOS.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/MacOS.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/MacOS.c	Thu Mar 27 00:48:05 2008
@@ -195,7 +195,7 @@
 		PyMac_Error(err);
 		return NULL;
 	}
-	return PyInt_FromLong(where);
+	return PyLong_FromLong(where);
 }
 
 static char rf_close__doc__[] = 
@@ -356,7 +356,7 @@
 		PyObject *m, *rv;
 		errors_loaded = 1;
 		
-		m = PyImport_ImportModule("macresource");
+		m = PyImport_ImportModuleNoBlock("macresource");
 		if (!m) {
 			if (Py_VerboseFlag)
 				PyErr_Print();
@@ -609,7 +609,7 @@
 	MacOS_Error = PyMac_GetOSErrException();
 	if (MacOS_Error == NULL || PyDict_SetItemString(d, "Error", MacOS_Error) != 0)
 		return;
-	Py_Type(&Rftype) = &PyType_Type;
+	Py_TYPE(&Rftype) = &PyType_Type;
 	Py_INCREF(&Rftype);
 	if (PyDict_SetItemString(d, "ResourceForkType", (PyObject *)&Rftype) != 0)
 		return;

Modified: python/branches/py3k-importlib/Mac/Modules/ae/_AEmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/ae/_AEmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/ae/_AEmodule.c	Thu Mar 27 00:48:05 2008
@@ -47,7 +47,7 @@
 
 PyTypeObject AEDesc_Type;
 
-#define AEDesc_Check(x) (Py_Type(x) == &AEDesc_Type || PyObject_TypeCheck((x), &AEDesc_Type))
+#define AEDesc_Check(x) (Py_TYPE(x) == &AEDesc_Type || PyObject_TypeCheck((x), &AEDesc_Type))
 
 typedef struct AEDescObject {
 	PyObject_HEAD
@@ -79,7 +79,7 @@
 static void AEDesc_dealloc(AEDescObject *self)
 {
 	if (self->ob_owned) AEDisposeDesc(&self->ob_itself);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *AEDesc_AECoerceDesc(AEDescObject *_self, PyObject *_args)
@@ -835,9 +835,9 @@
 	OSErr err;
 
 	size = AEGetDescDataSize(&self->ob_itself);
-	if ( (res = PyBytes_FromStringAndSize(NULL, size)) == NULL )
+	if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
 		return NULL;
-	if ( (ptr = PyBytes_AsString(res)) == NULL )
+	if ( (ptr = PyString_AS_STRING(res)) == NULL )
 		return NULL;
 	if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
 		return PyMac_Error(err);
@@ -1440,7 +1440,7 @@
 	if (AE_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", AE_Error) != 0)
 		return;
-	Py_Type(&AEDesc_Type) = &PyType_Type;
+	Py_TYPE(&AEDesc_Type) = &PyType_Type;
 	if (PyType_Ready(&AEDesc_Type) < 0) return;
 	Py_INCREF(&AEDesc_Type);
 	PyModule_AddObject(m, "AEDesc", (PyObject *)&AEDesc_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/ae/aescan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/ae/aescan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/ae/aescan.py	Thu Mar 27 00:48:05 2008
@@ -3,8 +3,6 @@
 # (Should learn how to tell the compiler to compile it as well.)
 
 import sys
-import os
-import string
 import MacOS
 
 from bgenlocations import TOOLBOXDIR, BGENDIR

Modified: python/branches/py3k-importlib/Mac/Modules/ah/ahscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/ah/ahscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/ah/ahscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner_OSX

Modified: python/branches/py3k-importlib/Mac/Modules/app/_Appmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/app/_Appmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/app/_Appmodule.c	Thu Mar 27 00:48:05 2008
@@ -30,7 +30,7 @@
 
 PyTypeObject ThemeDrawingState_Type;
 
-#define ThemeDrawingStateObj_Check(x) (Py_Type(x) == &ThemeDrawingState_Type || PyObject_TypeCheck((x), &ThemeDrawingState_Type))
+#define ThemeDrawingStateObj_Check(x) (Py_TYPE(x) == &ThemeDrawingState_Type || PyObject_TypeCheck((x), &ThemeDrawingState_Type))
 
 typedef struct ThemeDrawingStateObject {
 	PyObject_HEAD
@@ -60,7 +60,7 @@
 static void ThemeDrawingStateObj_dealloc(ThemeDrawingStateObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *ThemeDrawingStateObj_SetThemeDrawingState(ThemeDrawingStateObject *_self, PyObject *_args)
@@ -1807,7 +1807,7 @@
 	if (App_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", App_Error) != 0)
 		return;
-	Py_Type(&ThemeDrawingState_Type) = &PyType_Type;
+	Py_TYPE(&ThemeDrawingState_Type) = &PyType_Type;
 	if (PyType_Ready(&ThemeDrawingState_Type) < 0) return;
 	Py_INCREF(&ThemeDrawingState_Type);
 	PyModule_AddObject(m, "ThemeDrawingState", (PyObject *)&ThemeDrawingState_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/app/appscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/app/appscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/app/appscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner

Modified: python/branches/py3k-importlib/Mac/Modules/carbonevt/CarbonEvtscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/carbonevt/CarbonEvtscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/carbonevt/CarbonEvtscan.py	Thu Mar 27 00:48:05 2008
@@ -1,8 +1,6 @@
 # IBCarbonscan.py
 
 import sys
-import os
-import string
 import MacOS
 import sys
 

Modified: python/branches/py3k-importlib/Mac/Modules/carbonevt/_CarbonEvtmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/carbonevt/_CarbonEvtmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/carbonevt/_CarbonEvtmodule.c	Thu Mar 27 00:48:05 2008
@@ -102,8 +102,8 @@
         } else {
                 if (retValue == Py_None)
                         status = noErr;
-                else if (PyInt_Check(retValue)) {
-                        status = PyInt_AsLong(retValue);
+                else if (PyLong_Check(retValue)) {
+                        status = PyLong_AsLong(retValue);
                 } else
                         status = noErr; /* wrong object type, complain? */
                 Py_DECREF(retValue);
@@ -151,7 +151,7 @@
 static void EventRef_dealloc(EventRefObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *EventRef_RetainEvent(EventRefObject *_self, PyObject *_args)
@@ -495,7 +495,7 @@
 static void EventQueueRef_dealloc(EventQueueRefObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *EventQueueRef_PostEventToQueue(EventQueueRefObject *_self, PyObject *_args)
@@ -715,7 +715,7 @@
 static void EventLoopRef_dealloc(EventLoopRefObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *EventLoopRef_QuitEventLoop(EventLoopRefObject *_self, PyObject *_args)
@@ -844,7 +844,7 @@
 static void EventLoopTimerRef_dealloc(EventLoopTimerRefObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *EventLoopTimerRef_RemoveEventLoopTimer(EventLoopTimerRefObject *_self, PyObject *_args)
@@ -996,7 +996,7 @@
 		RemoveEventHandler(self->ob_itself);
 		Py_DECREF(self->ob_callback);
 	}
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *EventHandlerRef_AddEventTypesToHandler(EventHandlerRefObject *_self, PyObject *_args)
@@ -1183,7 +1183,7 @@
 static void EventHandlerCallRef_dealloc(EventHandlerCallRefObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *EventHandlerCallRef_CallNextEventHandler(EventHandlerCallRefObject *_self, PyObject *_args)
@@ -1315,7 +1315,7 @@
 static void EventTargetRef_dealloc(EventTargetRefObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *EventTargetRef_InstallStandardEventHandler(EventTargetRefObject *_self, PyObject *_args)
@@ -1469,7 +1469,7 @@
 static void EventHotKeyRef_dealloc(EventHotKeyRefObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *EventHotKeyRef_UnregisterEventHotKey(EventHotKeyRefObject *_self, PyObject *_args)
@@ -2152,56 +2152,56 @@
 	if (CarbonEvents_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", CarbonEvents_Error) != 0)
 		return;
-	Py_Type(&EventRef_Type) = &PyType_Type;
+	Py_TYPE(&EventRef_Type) = &PyType_Type;
 	if (PyType_Ready(&EventRef_Type) < 0) return;
 	Py_INCREF(&EventRef_Type);
 	PyModule_AddObject(m, "EventRef", (PyObject *)&EventRef_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&EventRef_Type);
 	PyModule_AddObject(m, "EventRefType", (PyObject *)&EventRef_Type);
-	Py_Type(&EventQueueRef_Type) = &PyType_Type;
+	Py_TYPE(&EventQueueRef_Type) = &PyType_Type;
 	if (PyType_Ready(&EventQueueRef_Type) < 0) return;
 	Py_INCREF(&EventQueueRef_Type);
 	PyModule_AddObject(m, "EventQueueRef", (PyObject *)&EventQueueRef_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&EventQueueRef_Type);
 	PyModule_AddObject(m, "EventQueueRefType", (PyObject *)&EventQueueRef_Type);
-	Py_Type(&EventLoopRef_Type) = &PyType_Type;
+	Py_TYPE(&EventLoopRef_Type) = &PyType_Type;
 	if (PyType_Ready(&EventLoopRef_Type) < 0) return;
 	Py_INCREF(&EventLoopRef_Type);
 	PyModule_AddObject(m, "EventLoopRef", (PyObject *)&EventLoopRef_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&EventLoopRef_Type);
 	PyModule_AddObject(m, "EventLoopRefType", (PyObject *)&EventLoopRef_Type);
-	Py_Type(&EventLoopTimerRef_Type) = &PyType_Type;
+	Py_TYPE(&EventLoopTimerRef_Type) = &PyType_Type;
 	if (PyType_Ready(&EventLoopTimerRef_Type) < 0) return;
 	Py_INCREF(&EventLoopTimerRef_Type);
 	PyModule_AddObject(m, "EventLoopTimerRef", (PyObject *)&EventLoopTimerRef_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&EventLoopTimerRef_Type);
 	PyModule_AddObject(m, "EventLoopTimerRefType", (PyObject *)&EventLoopTimerRef_Type);
-	Py_Type(&EventHandlerRef_Type) = &PyType_Type;
+	Py_TYPE(&EventHandlerRef_Type) = &PyType_Type;
 	if (PyType_Ready(&EventHandlerRef_Type) < 0) return;
 	Py_INCREF(&EventHandlerRef_Type);
 	PyModule_AddObject(m, "EventHandlerRef", (PyObject *)&EventHandlerRef_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&EventHandlerRef_Type);
 	PyModule_AddObject(m, "EventHandlerRefType", (PyObject *)&EventHandlerRef_Type);
-	Py_Type(&EventHandlerCallRef_Type) = &PyType_Type;
+	Py_TYPE(&EventHandlerCallRef_Type) = &PyType_Type;
 	if (PyType_Ready(&EventHandlerCallRef_Type) < 0) return;
 	Py_INCREF(&EventHandlerCallRef_Type);
 	PyModule_AddObject(m, "EventHandlerCallRef", (PyObject *)&EventHandlerCallRef_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&EventHandlerCallRef_Type);
 	PyModule_AddObject(m, "EventHandlerCallRefType", (PyObject *)&EventHandlerCallRef_Type);
-	Py_Type(&EventTargetRef_Type) = &PyType_Type;
+	Py_TYPE(&EventTargetRef_Type) = &PyType_Type;
 	if (PyType_Ready(&EventTargetRef_Type) < 0) return;
 	Py_INCREF(&EventTargetRef_Type);
 	PyModule_AddObject(m, "EventTargetRef", (PyObject *)&EventTargetRef_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&EventTargetRef_Type);
 	PyModule_AddObject(m, "EventTargetRefType", (PyObject *)&EventTargetRef_Type);
-	Py_Type(&EventHotKeyRef_Type) = &PyType_Type;
+	Py_TYPE(&EventHotKeyRef_Type) = &PyType_Type;
 	if (PyType_Ready(&EventHotKeyRef_Type) < 0) return;
 	Py_INCREF(&EventHotKeyRef_Type);
 	PyModule_AddObject(m, "EventHotKeyRef", (PyObject *)&EventHotKeyRef_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/cf/_CFmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/cf/_CFmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/cf/_CFmodule.c	Thu Mar 27 00:48:05 2008
@@ -116,7 +116,7 @@
 
 PyTypeObject CFTypeRef_Type;
 
-#define CFTypeRefObj_Check(x) (Py_Type(x) == &CFTypeRef_Type || PyObject_TypeCheck((x), &CFTypeRef_Type))
+#define CFTypeRefObj_Check(x) (Py_TYPE(x) == &CFTypeRef_Type || PyObject_TypeCheck((x), &CFTypeRef_Type))
 
 typedef struct CFTypeRefObject {
 	PyObject_HEAD
@@ -161,7 +161,7 @@
 		self->ob_freeit((CFTypeRef)self->ob_itself);
 		self->ob_itself = NULL;
 	}
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *CFTypeRefObj_CFGetTypeID(CFTypeRefObject *_self, PyObject *_args)
@@ -477,7 +477,7 @@
 
 PyTypeObject CFArrayRef_Type;
 
-#define CFArrayRefObj_Check(x) (Py_Type(x) == &CFArrayRef_Type || PyObject_TypeCheck((x), &CFArrayRef_Type))
+#define CFArrayRefObj_Check(x) (Py_TYPE(x) == &CFArrayRef_Type || PyObject_TypeCheck((x), &CFArrayRef_Type))
 
 typedef struct CFArrayRefObject {
 	PyObject_HEAD
@@ -687,7 +687,7 @@
 
 PyTypeObject CFMutableArrayRef_Type;
 
-#define CFMutableArrayRefObj_Check(x) (Py_Type(x) == &CFMutableArrayRef_Type || PyObject_TypeCheck((x), &CFMutableArrayRef_Type))
+#define CFMutableArrayRefObj_Check(x) (Py_TYPE(x) == &CFMutableArrayRef_Type || PyObject_TypeCheck((x), &CFMutableArrayRef_Type))
 
 typedef struct CFMutableArrayRefObject {
 	PyObject_HEAD
@@ -926,7 +926,7 @@
 
 PyTypeObject CFDictionaryRef_Type;
 
-#define CFDictionaryRefObj_Check(x) (Py_Type(x) == &CFDictionaryRef_Type || PyObject_TypeCheck((x), &CFDictionaryRef_Type))
+#define CFDictionaryRefObj_Check(x) (Py_TYPE(x) == &CFDictionaryRef_Type || PyObject_TypeCheck((x), &CFDictionaryRef_Type))
 
 typedef struct CFDictionaryRefObject {
 	PyObject_HEAD
@@ -1118,7 +1118,7 @@
 
 PyTypeObject CFMutableDictionaryRef_Type;
 
-#define CFMutableDictionaryRefObj_Check(x) (Py_Type(x) == &CFMutableDictionaryRef_Type || PyObject_TypeCheck((x), &CFMutableDictionaryRef_Type))
+#define CFMutableDictionaryRefObj_Check(x) (Py_TYPE(x) == &CFMutableDictionaryRef_Type || PyObject_TypeCheck((x), &CFMutableDictionaryRef_Type))
 
 typedef struct CFMutableDictionaryRefObject {
 	PyObject_HEAD
@@ -1294,7 +1294,7 @@
 
 PyTypeObject CFDataRef_Type;
 
-#define CFDataRefObj_Check(x) (Py_Type(x) == &CFDataRef_Type || PyObject_TypeCheck((x), &CFDataRef_Type))
+#define CFDataRefObj_Check(x) (Py_TYPE(x) == &CFDataRef_Type || PyObject_TypeCheck((x), &CFDataRef_Type))
 
 typedef struct CFDataRefObject {
 	PyObject_HEAD
@@ -1524,7 +1524,7 @@
 
 PyTypeObject CFMutableDataRef_Type;
 
-#define CFMutableDataRefObj_Check(x) (Py_Type(x) == &CFMutableDataRef_Type || PyObject_TypeCheck((x), &CFMutableDataRef_Type))
+#define CFMutableDataRefObj_Check(x) (Py_TYPE(x) == &CFMutableDataRef_Type || PyObject_TypeCheck((x), &CFMutableDataRef_Type))
 
 typedef struct CFMutableDataRefObject {
 	PyObject_HEAD
@@ -1788,7 +1788,7 @@
 
 PyTypeObject CFStringRef_Type;
 
-#define CFStringRefObj_Check(x) (Py_Type(x) == &CFStringRef_Type || PyObject_TypeCheck((x), &CFStringRef_Type))
+#define CFStringRefObj_Check(x) (Py_TYPE(x) == &CFStringRef_Type || PyObject_TypeCheck((x), &CFStringRef_Type))
 
 typedef struct CFStringRefObject {
 	PyObject_HEAD
@@ -2530,7 +2530,7 @@
 
 PyTypeObject CFMutableStringRef_Type;
 
-#define CFMutableStringRefObj_Check(x) (Py_Type(x) == &CFMutableStringRef_Type || PyObject_TypeCheck((x), &CFMutableStringRef_Type))
+#define CFMutableStringRefObj_Check(x) (Py_TYPE(x) == &CFMutableStringRef_Type || PyObject_TypeCheck((x), &CFMutableStringRef_Type))
 
 typedef struct CFMutableStringRefObject {
 	PyObject_HEAD
@@ -2917,7 +2917,7 @@
 
 PyTypeObject CFURLRef_Type;
 
-#define CFURLRefObj_Check(x) (Py_Type(x) == &CFURLRef_Type || PyObject_TypeCheck((x), &CFURLRef_Type))
+#define CFURLRefObj_Check(x) (Py_TYPE(x) == &CFURLRef_Type || PyObject_TypeCheck((x), &CFURLRef_Type))
 
 typedef struct CFURLRefObject {
 	PyObject_HEAD
@@ -4890,14 +4890,14 @@
 	if (CF_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", CF_Error) != 0)
 		return;
-	Py_Type(&CFTypeRef_Type) = &PyType_Type;
+	Py_TYPE(&CFTypeRef_Type) = &PyType_Type;
 	if (PyType_Ready(&CFTypeRef_Type) < 0) return;
 	Py_INCREF(&CFTypeRef_Type);
 	PyModule_AddObject(m, "CFTypeRef", (PyObject *)&CFTypeRef_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&CFTypeRef_Type);
 	PyModule_AddObject(m, "CFTypeRefType", (PyObject *)&CFTypeRef_Type);
-	Py_Type(&CFArrayRef_Type) = &PyType_Type;
+	Py_TYPE(&CFArrayRef_Type) = &PyType_Type;
 	CFArrayRef_Type.tp_base = &CFTypeRef_Type;
 	if (PyType_Ready(&CFArrayRef_Type) < 0) return;
 	Py_INCREF(&CFArrayRef_Type);
@@ -4905,7 +4905,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&CFArrayRef_Type);
 	PyModule_AddObject(m, "CFArrayRefType", (PyObject *)&CFArrayRef_Type);
-	Py_Type(&CFMutableArrayRef_Type) = &PyType_Type;
+	Py_TYPE(&CFMutableArrayRef_Type) = &PyType_Type;
 	CFMutableArrayRef_Type.tp_base = &CFArrayRef_Type;
 	if (PyType_Ready(&CFMutableArrayRef_Type) < 0) return;
 	Py_INCREF(&CFMutableArrayRef_Type);
@@ -4913,7 +4913,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&CFMutableArrayRef_Type);
 	PyModule_AddObject(m, "CFMutableArrayRefType", (PyObject *)&CFMutableArrayRef_Type);
-	Py_Type(&CFDictionaryRef_Type) = &PyType_Type;
+	Py_TYPE(&CFDictionaryRef_Type) = &PyType_Type;
 	CFDictionaryRef_Type.tp_base = &CFTypeRef_Type;
 	if (PyType_Ready(&CFDictionaryRef_Type) < 0) return;
 	Py_INCREF(&CFDictionaryRef_Type);
@@ -4921,7 +4921,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&CFDictionaryRef_Type);
 	PyModule_AddObject(m, "CFDictionaryRefType", (PyObject *)&CFDictionaryRef_Type);
-	Py_Type(&CFMutableDictionaryRef_Type) = &PyType_Type;
+	Py_TYPE(&CFMutableDictionaryRef_Type) = &PyType_Type;
 	CFMutableDictionaryRef_Type.tp_base = &CFDictionaryRef_Type;
 	if (PyType_Ready(&CFMutableDictionaryRef_Type) < 0) return;
 	Py_INCREF(&CFMutableDictionaryRef_Type);
@@ -4929,7 +4929,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&CFMutableDictionaryRef_Type);
 	PyModule_AddObject(m, "CFMutableDictionaryRefType", (PyObject *)&CFMutableDictionaryRef_Type);
-	Py_Type(&CFDataRef_Type) = &PyType_Type;
+	Py_TYPE(&CFDataRef_Type) = &PyType_Type;
 	CFDataRef_Type.tp_base = &CFTypeRef_Type;
 	if (PyType_Ready(&CFDataRef_Type) < 0) return;
 	Py_INCREF(&CFDataRef_Type);
@@ -4937,7 +4937,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&CFDataRef_Type);
 	PyModule_AddObject(m, "CFDataRefType", (PyObject *)&CFDataRef_Type);
-	Py_Type(&CFMutableDataRef_Type) = &PyType_Type;
+	Py_TYPE(&CFMutableDataRef_Type) = &PyType_Type;
 	CFMutableDataRef_Type.tp_base = &CFDataRef_Type;
 	if (PyType_Ready(&CFMutableDataRef_Type) < 0) return;
 	Py_INCREF(&CFMutableDataRef_Type);
@@ -4945,7 +4945,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&CFMutableDataRef_Type);
 	PyModule_AddObject(m, "CFMutableDataRefType", (PyObject *)&CFMutableDataRef_Type);
-	Py_Type(&CFStringRef_Type) = &PyType_Type;
+	Py_TYPE(&CFStringRef_Type) = &PyType_Type;
 	CFStringRef_Type.tp_base = &CFTypeRef_Type;
 	if (PyType_Ready(&CFStringRef_Type) < 0) return;
 	Py_INCREF(&CFStringRef_Type);
@@ -4953,7 +4953,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&CFStringRef_Type);
 	PyModule_AddObject(m, "CFStringRefType", (PyObject *)&CFStringRef_Type);
-	Py_Type(&CFMutableStringRef_Type) = &PyType_Type;
+	Py_TYPE(&CFMutableStringRef_Type) = &PyType_Type;
 	CFMutableStringRef_Type.tp_base = &CFStringRef_Type;
 	if (PyType_Ready(&CFMutableStringRef_Type) < 0) return;
 	Py_INCREF(&CFMutableStringRef_Type);
@@ -4961,7 +4961,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&CFMutableStringRef_Type);
 	PyModule_AddObject(m, "CFMutableStringRefType", (PyObject *)&CFMutableStringRef_Type);
-	Py_Type(&CFURLRef_Type) = &PyType_Type;
+	Py_TYPE(&CFURLRef_Type) = &PyType_Type;
 	CFURLRef_Type.tp_base = &CFTypeRef_Type;
 	if (PyType_Ready(&CFURLRef_Type) < 0) return;
 	Py_INCREF(&CFURLRef_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/cf/cfscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/cf/cfscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/cf/cfscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner_OSX

Modified: python/branches/py3k-importlib/Mac/Modules/cf/pycfbridge.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/cf/pycfbridge.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/cf/pycfbridge.c	Thu Mar 27 00:48:05 2008
@@ -114,7 +114,7 @@
 			long l;
 			if (!CFNumberGetValue(src, kCFNumberLongType, &l))
 				/* XXXX Out of range! */;
-			return PyInt_FromLong(l);
+			return PyLong_FromLong(l);
 		}
 	}
 	/* XXXX Should return as CFTypeRef, really... */
@@ -258,8 +258,8 @@
 			*dst = kCFBooleanFalse;
 		return 1;
 	}
-	if (PyInt_Check(src)) {
-		long v = PyInt_AsLong(src);
+	if (PyLong_Check(src)) {
+		long v = PyLong_AsLong(src);
 		*dst = CFNumberCreate(NULL, kCFNumberLongType, &v);
 		return 1;
 	}

Modified: python/branches/py3k-importlib/Mac/Modules/cg/_CGmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/cg/_CGmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/cg/_CGmodule.c	Thu Mar 27 00:48:05 2008
@@ -95,7 +95,7 @@
 
 PyTypeObject CGContextRef_Type;
 
-#define CGContextRefObj_Check(x) (Py_Type(x) == &CGContextRef_Type || PyObject_TypeCheck((x), &CGContextRef_Type))
+#define CGContextRefObj_Check(x) (Py_TYPE(x) == &CGContextRef_Type || PyObject_TypeCheck((x), &CGContextRef_Type))
 
 typedef struct CGContextRefObject {
 	PyObject_HEAD
@@ -125,7 +125,7 @@
 static void CGContextRefObj_dealloc(CGContextRefObject *self)
 {
 	CGContextRelease(self->ob_itself);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *CGContextRefObj_CGContextSaveGState(CGContextRefObject *_self, PyObject *_args)
@@ -1294,7 +1294,7 @@
 	if (CG_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", CG_Error) != 0)
 		return;
-	Py_Type(&CGContextRef_Type) = &PyType_Type;
+	Py_TYPE(&CGContextRef_Type) = &PyType_Type;
 	if (PyType_Ready(&CGContextRef_Type) < 0) return;
 	Py_INCREF(&CGContextRef_Type);
 	PyModule_AddObject(m, "CGContextRef", (PyObject *)&CGContextRef_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/cg/cgscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/cg/cgscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/cg/cgscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner_OSX

Modified: python/branches/py3k-importlib/Mac/Modules/cm/_Cmmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/cm/_Cmmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/cm/_Cmmodule.c	Thu Mar 27 00:48:05 2008
@@ -60,7 +60,7 @@
 
 PyTypeObject ComponentInstance_Type;
 
-#define CmpInstObj_Check(x) (Py_Type(x) == &ComponentInstance_Type || PyObject_TypeCheck((x), &ComponentInstance_Type))
+#define CmpInstObj_Check(x) (Py_TYPE(x) == &ComponentInstance_Type || PyObject_TypeCheck((x), &ComponentInstance_Type))
 
 typedef struct ComponentInstanceObject {
 	PyObject_HEAD
@@ -94,7 +94,7 @@
 static void CmpInstObj_dealloc(ComponentInstanceObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *CmpInstObj_CloseComponent(ComponentInstanceObject *_self, PyObject *_args)
@@ -326,7 +326,7 @@
 
 PyTypeObject Component_Type;
 
-#define CmpObj_Check(x) (Py_Type(x) == &Component_Type || PyObject_TypeCheck((x), &Component_Type))
+#define CmpObj_Check(x) (Py_TYPE(x) == &Component_Type || PyObject_TypeCheck((x), &Component_Type))
 
 typedef struct ComponentObject {
 	PyObject_HEAD
@@ -365,7 +365,7 @@
 static void CmpObj_dealloc(ComponentObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *CmpObj_UnregisterComponent(ComponentObject *_self, PyObject *_args)
@@ -925,14 +925,14 @@
 	if (Cm_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Cm_Error) != 0)
 		return;
-	Py_Type(&ComponentInstance_Type) = &PyType_Type;
+	Py_TYPE(&ComponentInstance_Type) = &PyType_Type;
 	if (PyType_Ready(&ComponentInstance_Type) < 0) return;
 	Py_INCREF(&ComponentInstance_Type);
 	PyModule_AddObject(m, "ComponentInstance", (PyObject *)&ComponentInstance_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&ComponentInstance_Type);
 	PyModule_AddObject(m, "ComponentInstanceType", (PyObject *)&ComponentInstance_Type);
-	Py_Type(&Component_Type) = &PyType_Type;
+	Py_TYPE(&Component_Type) = &PyType_Type;
 	if (PyType_Ready(&Component_Type) < 0) return;
 	Py_INCREF(&Component_Type);
 	PyModule_AddObject(m, "Component", (PyObject *)&Component_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/cm/cmscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/cm/cmscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/cm/cmscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner

Modified: python/branches/py3k-importlib/Mac/Modules/ctl/_Ctlmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/ctl/_Ctlmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/ctl/_Ctlmodule.c	Thu Mar 27 00:48:05 2008
@@ -135,7 +135,7 @@
 
 PyTypeObject Control_Type;
 
-#define CtlObj_Check(x) (Py_Type(x) == &Control_Type || PyObject_TypeCheck((x), &Control_Type))
+#define CtlObj_Check(x) (Py_TYPE(x) == &Control_Type || PyObject_TypeCheck((x), &Control_Type))
 
 typedef struct ControlObject {
 	PyObject_HEAD
@@ -170,7 +170,7 @@
 {
 	Py_XDECREF(self->ob_callbackdict);
 	if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *CtlObj_HiliteControl(ControlObject *_self, PyObject *_args)
@@ -3250,7 +3250,7 @@
 	                      PyMac_GetPoint, &startPoint, &callback))
 	        return NULL;
 	if (callback && callback != Py_None) {
-	        if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
+	        if (PyLong_Check(callback) && PyLong_AS_LONG(callback) == -1)
 	                upp = (ControlActionUPP)-1;
 	        else {
 	                settrackfunc(callback);
@@ -3283,7 +3283,7 @@
 	                      &callback))
 	        return NULL;
 	if (callback && callback != Py_None) {
-	        if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
+	        if (PyLong_Check(callback) && PyLong_AS_LONG(callback) == -1)
 	                upp = (ControlActionUPP)-1;
 	        else {
 	                settrackfunc(callback);
@@ -5790,7 +5790,7 @@
 	if (Ctl_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
 		return;
-	Py_Type(&Control_Type) = &PyType_Type;
+	Py_TYPE(&Control_Type) = &PyType_Type;
 	if (PyType_Ready(&Control_Type) < 0) return;
 	Py_INCREF(&Control_Type);
 	PyModule_AddObject(m, "Control", (PyObject *)&Control_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/ctl/ctlscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/ctl/ctlscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/ctl/ctlscan.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,5 @@
 # Scan <Controls.h>, generating ctlgen.py.
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 

Modified: python/branches/py3k-importlib/Mac/Modules/dlg/_Dlgmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/dlg/_Dlgmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/dlg/_Dlgmodule.c	Thu Mar 27 00:48:05 2008
@@ -55,8 +55,8 @@
         }
         else {
                 Dlg_FilterProc_callback = callback;
-                if (PyInt_Check(res)) {
-                        *itemHit = PyInt_AsLong(res);
+                if (PyLong_Check(res)) {
+                        *itemHit = PyLong_AsLong(res);
                         rv = 1;
                 }
                 else
@@ -129,7 +129,7 @@
 
 PyTypeObject Dialog_Type;
 
-#define DlgObj_Check(x) (Py_Type(x) == &Dialog_Type || PyObject_TypeCheck((x), &Dialog_Type))
+#define DlgObj_Check(x) (Py_TYPE(x) == &Dialog_Type || PyObject_TypeCheck((x), &Dialog_Type))
 
 typedef struct DialogObject {
 	PyObject_HEAD
@@ -150,7 +150,7 @@
 int DlgObj_Convert(PyObject *v, DialogPtr *p_itself)
 {
 	if (v == Py_None) { *p_itself = NULL; return 1; }
-	if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
+	if (PyLong_Check(v)) { *p_itself = (DialogPtr)PyLong_AsLong(v);
 	                      return 1; }
 	if (!DlgObj_Check(v))
 	{
@@ -164,7 +164,7 @@
 static void DlgObj_dealloc(DialogObject *self)
 {
 	DisposeDialog(self->ob_itself);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *DlgObj_DrawDialog(DialogObject *_self, PyObject *_args)
@@ -1582,7 +1582,7 @@
 	if (Dlg_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
 		return;
-	Py_Type(&Dialog_Type) = &PyType_Type;
+	Py_TYPE(&Dialog_Type) = &PyType_Type;
 	if (PyType_Ready(&Dialog_Type) < 0) return;
 	Py_INCREF(&Dialog_Type);
 	PyModule_AddObject(m, "Dialog", (PyObject *)&Dialog_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/dlg/dlgscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/dlg/dlgscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/dlg/dlgscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 

Modified: python/branches/py3k-importlib/Mac/Modules/drag/_Dragmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/drag/_Dragmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/drag/_Dragmodule.c	Thu Mar 27 00:48:05 2008
@@ -40,7 +40,7 @@
 
 PyTypeObject DragObj_Type;
 
-#define DragObj_Check(x) (Py_Type(x) == &DragObj_Type || PyObject_TypeCheck((x), &DragObj_Type))
+#define DragObj_Check(x) (Py_TYPE(x) == &DragObj_Type || PyObject_TypeCheck((x), &DragObj_Type))
 
 typedef struct DragObjObject {
 	PyObject_HEAD
@@ -76,7 +76,7 @@
 static void DragObj_dealloc(DragObjObject *self)
 {
 	Py_XDECREF(self->sendproc);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *DragObj_DisposeDrag(DragObjObject *_self, PyObject *_args)
@@ -1125,7 +1125,7 @@
 	if (Drag_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Drag_Error) != 0)
 		return;
-	Py_Type(&DragObj_Type) = &PyType_Type;
+	Py_TYPE(&DragObj_Type) = &PyType_Type;
 	if (PyType_Ready(&DragObj_Type) < 0) return;
 	Py_INCREF(&DragObj_Type);
 	PyModule_AddObject(m, "DragObj", (PyObject *)&DragObj_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/drag/dragscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/drag/dragscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/drag/dragscan.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,5 @@
 # Scan <Drag.h>, generating draggen.py.
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR, INCLUDEDIR
 sys.path.append(BGENDIR)
 

Modified: python/branches/py3k-importlib/Mac/Modules/evt/evtscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/evt/evtscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/evt/evtscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner

Modified: python/branches/py3k-importlib/Mac/Modules/file/_Filemodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/file/_Filemodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/file/_Filemodule.c	Thu Mar 27 00:48:05 2008
@@ -143,7 +143,7 @@
 
 static PyTypeObject FSCatalogInfo_Type;
 
-#define FSCatalogInfo_Check(x) (Py_Type(x) == &FSCatalogInfo_Type || PyObject_TypeCheck((x), &FSCatalogInfo_Type))
+#define FSCatalogInfo_Check(x) (Py_TYPE(x) == &FSCatalogInfo_Type || PyObject_TypeCheck((x), &FSCatalogInfo_Type))
 
 typedef struct FSCatalogInfoObject {
 	PyObject_HEAD
@@ -174,7 +174,7 @@
 static void FSCatalogInfo_dealloc(FSCatalogInfoObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyMethodDef FSCatalogInfo_methods[] = {
@@ -502,7 +502,7 @@
 
 static PyTypeObject FInfo_Type;
 
-#define FInfo_Check(x) (Py_Type(x) == &FInfo_Type || PyObject_TypeCheck((x), &FInfo_Type))
+#define FInfo_Check(x) (Py_TYPE(x) == &FInfo_Type || PyObject_TypeCheck((x), &FInfo_Type))
 
 typedef struct FInfoObject {
 	PyObject_HEAD
@@ -533,7 +533,7 @@
 static void FInfo_dealloc(FInfoObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyMethodDef FInfo_methods[] = {
@@ -687,7 +687,7 @@
 
 static PyTypeObject Alias_Type;
 
-#define Alias_Check(x) (Py_Type(x) == &Alias_Type || PyObject_TypeCheck((x), &Alias_Type))
+#define Alias_Check(x) (Py_TYPE(x) == &Alias_Type || PyObject_TypeCheck((x), &Alias_Type))
 
 typedef struct AliasObject {
 	PyObject_HEAD
@@ -724,7 +724,7 @@
 		self->ob_freeit(self->ob_itself);
 	}
 	self->ob_itself = NULL;
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *Alias_ResolveAlias(AliasObject *_self, PyObject *_args)
@@ -1053,7 +1053,7 @@
 static void FSSpec_dealloc(FSSpecObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *FSSpec_FSpOpenDF(FSSpecObject *_self, PyObject *_args)
@@ -1312,7 +1312,7 @@
 	        PyMac_Error(err);
 	        return NULL;
 	}
-	_res = PyString_FromString(strbuf);
+	_res = PyUnicode_FromString(strbuf);
 	return _res;
 
 }
@@ -1386,7 +1386,7 @@
 {
 	char buf[512];
 	PyOS_snprintf(buf, sizeof(buf), "%s((%d, %ld, '%.*s'))",
-	        Py_Type(self)->tp_name,
+	        Py_TYPE(self)->tp_name,
 	        self->ob_itself.vRefNum,
 	        self->ob_itself.parID,
 	        self->ob_itself.name[0], self->ob_itself.name+1);
@@ -1511,7 +1511,7 @@
 static void FSRef_dealloc(FSRefObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *FSRef_FSMakeFSRefUnicode(FSRefObject *_self, PyObject *_args)
@@ -3246,35 +3246,35 @@
 	if (File_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", File_Error) != 0)
 		return;
-	Py_Type(&FSCatalogInfo_Type) = &PyType_Type;
+	Py_TYPE(&FSCatalogInfo_Type) = &PyType_Type;
 	if (PyType_Ready(&FSCatalogInfo_Type) < 0) return;
 	Py_INCREF(&FSCatalogInfo_Type);
 	PyModule_AddObject(m, "FSCatalogInfo", (PyObject *)&FSCatalogInfo_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&FSCatalogInfo_Type);
 	PyModule_AddObject(m, "FSCatalogInfoType", (PyObject *)&FSCatalogInfo_Type);
-	Py_Type(&FInfo_Type) = &PyType_Type;
+	Py_TYPE(&FInfo_Type) = &PyType_Type;
 	if (PyType_Ready(&FInfo_Type) < 0) return;
 	Py_INCREF(&FInfo_Type);
 	PyModule_AddObject(m, "FInfo", (PyObject *)&FInfo_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&FInfo_Type);
 	PyModule_AddObject(m, "FInfoType", (PyObject *)&FInfo_Type);
-	Py_Type(&Alias_Type) = &PyType_Type;
+	Py_TYPE(&Alias_Type) = &PyType_Type;
 	if (PyType_Ready(&Alias_Type) < 0) return;
 	Py_INCREF(&Alias_Type);
 	PyModule_AddObject(m, "Alias", (PyObject *)&Alias_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&Alias_Type);
 	PyModule_AddObject(m, "AliasType", (PyObject *)&Alias_Type);
-	Py_Type(&FSSpec_Type) = &PyType_Type;
+	Py_TYPE(&FSSpec_Type) = &PyType_Type;
 	if (PyType_Ready(&FSSpec_Type) < 0) return;
 	Py_INCREF(&FSSpec_Type);
 	PyModule_AddObject(m, "FSSpec", (PyObject *)&FSSpec_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&FSSpec_Type);
 	PyModule_AddObject(m, "FSSpecType", (PyObject *)&FSSpec_Type);
-	Py_Type(&FSRef_Type) = &PyType_Type;
+	Py_TYPE(&FSRef_Type) = &PyType_Type;
 	if (PyType_Ready(&FSRef_Type) < 0) return;
 	Py_INCREF(&FSRef_Type);
 	PyModule_AddObject(m, "FSRef", (PyObject *)&FSRef_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/file/filescan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/file/filescan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/file/filescan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner_OSX

Modified: python/branches/py3k-importlib/Mac/Modules/fm/fmscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/fm/fmscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/fm/fmscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner

Modified: python/branches/py3k-importlib/Mac/Modules/folder/folderscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/folder/folderscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/folder/folderscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner_OSX

Modified: python/branches/py3k-importlib/Mac/Modules/gestaltmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/gestaltmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/gestaltmodule.c	Thu Mar 27 00:48:05 2008
@@ -40,7 +40,7 @@
 	iErr = Gestalt ( selector, &response );
 	if (iErr != 0) 
 		return PyMac_Error(iErr);
-	return PyInt_FromLong(response);
+	return PyLong_FromLong(response);
 }
 
 static struct PyMethodDef gestalt_methods[] = {

Modified: python/branches/py3k-importlib/Mac/Modules/help/helpscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/help/helpscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/help/helpscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner

Modified: python/branches/py3k-importlib/Mac/Modules/ibcarbon/IBCarbonscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/ibcarbon/IBCarbonscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/ibcarbon/IBCarbonscan.py	Thu Mar 27 00:48:05 2008
@@ -1,8 +1,6 @@
 # IBCarbonscan.py
 
 import sys
-import os
-import string
 
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)

Modified: python/branches/py3k-importlib/Mac/Modules/ibcarbon/_IBCarbon.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/ibcarbon/_IBCarbon.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/ibcarbon/_IBCarbon.c	Thu Mar 27 00:48:05 2008
@@ -19,7 +19,7 @@
 
 PyTypeObject IBNibRef_Type;
 
-#define IBNibRefObj_Check(x) (Py_Type(x) == &IBNibRef_Type || PyObject_TypeCheck((x), &IBNibRef_Type))
+#define IBNibRefObj_Check(x) (Py_TYPE(x) == &IBNibRef_Type || PyObject_TypeCheck((x), &IBNibRef_Type))
 
 typedef struct IBNibRefObject {
 	PyObject_HEAD
@@ -49,7 +49,7 @@
 static void IBNibRefObj_dealloc(IBNibRefObject *self)
 {
 	DisposeNibReference(self->ob_itself);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *IBNibRefObj_CreateWindowFromNib(IBNibRefObject *_self, PyObject *_args)
@@ -248,7 +248,7 @@
 	if (IBCarbon_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", IBCarbon_Error) != 0)
 		return;
-	Py_Type(&IBNibRef_Type) = &PyType_Type;
+	Py_TYPE(&IBNibRef_Type) = &PyType_Type;
 	if (PyType_Ready(&IBNibRef_Type) < 0) return;
 	Py_INCREF(&IBNibRef_Type);
 	PyModule_AddObject(m, "IBNibRef", (PyObject *)&IBNibRef_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/icn/icnscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/icn/icnscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/icn/icnscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner

Modified: python/branches/py3k-importlib/Mac/Modules/launch/launchscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/launch/launchscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/launch/launchscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner

Modified: python/branches/py3k-importlib/Mac/Modules/list/_Listmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/list/_Listmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/list/_Listmodule.c	Thu Mar 27 00:48:05 2008
@@ -37,7 +37,7 @@
 
 PyTypeObject List_Type;
 
-#define ListObj_Check(x) (Py_Type(x) == &List_Type || PyObject_TypeCheck((x), &List_Type))
+#define ListObj_Check(x) (Py_TYPE(x) == &List_Type || PyObject_TypeCheck((x), &List_Type))
 
 typedef struct ListObject {
 	PyObject_HEAD
@@ -79,7 +79,7 @@
 	self->ob_ldef_func = NULL;
 	SetListRefCon(self->ob_itself, (long)0);
 	if (self->ob_must_be_disposed && self->ob_itself) LDispose(self->ob_itself);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *ListObj_LAddColumn(ListObject *_self, PyObject *_args)
@@ -1116,7 +1116,7 @@
 	if (List_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", List_Error) != 0)
 		return;
-	Py_Type(&List_Type) = &PyType_Type;
+	Py_TYPE(&List_Type) = &PyType_Type;
 	if (PyType_Ready(&List_Type) < 0) return;
 	Py_INCREF(&List_Type);
 	PyModule_AddObject(m, "List", (PyObject *)&List_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/list/listscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/list/listscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/list/listscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner

Modified: python/branches/py3k-importlib/Mac/Modules/menu/_Menumodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/menu/_Menumodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/menu/_Menumodule.c	Thu Mar 27 00:48:05 2008
@@ -57,7 +57,7 @@
 
 PyTypeObject Menu_Type;
 
-#define MenuObj_Check(x) (Py_Type(x) == &Menu_Type || PyObject_TypeCheck((x), &Menu_Type))
+#define MenuObj_Check(x) (Py_TYPE(x) == &Menu_Type || PyObject_TypeCheck((x), &Menu_Type))
 
 typedef struct MenuObject {
 	PyObject_HEAD
@@ -87,7 +87,7 @@
 static void MenuObj_dealloc(MenuObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *MenuObj_DisposeMenu(MenuObject *_self, PyObject *_args)
@@ -3455,7 +3455,7 @@
 	if (Menu_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Menu_Error) != 0)
 		return;
-	Py_Type(&Menu_Type) = &PyType_Type;
+	Py_TYPE(&Menu_Type) = &PyType_Type;
 	if (PyType_Ready(&Menu_Type) < 0) return;
 	Py_INCREF(&Menu_Type);
 	PyModule_AddObject(m, "Menu", (PyObject *)&Menu_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/menu/menuscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/menu/menuscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/menu/menuscan.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,5 @@
 # Scan <Menus.h>, generating menugen.py.
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 

Modified: python/branches/py3k-importlib/Mac/Modules/mlte/_Mltemodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/mlte/_Mltemodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/mlte/_Mltemodule.c	Thu Mar 27 00:48:05 2008
@@ -69,7 +69,7 @@
 
 PyTypeObject TXNObject_Type;
 
-#define TXNObj_Check(x) (Py_Type(x) == &TXNObject_Type || PyObject_TypeCheck((x), &TXNObject_Type))
+#define TXNObj_Check(x) (Py_TYPE(x) == &TXNObject_Type || PyObject_TypeCheck((x), &TXNObject_Type))
 
 typedef struct TXNObjectObject {
 	PyObject_HEAD
@@ -100,7 +100,7 @@
 static void TXNObj_dealloc(TXNObjectObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *TXNObj_TXNDeleteObject(TXNObjectObject *_self, PyObject *_args)
@@ -1304,7 +1304,7 @@
 
 PyTypeObject TXNFontMenuObject_Type;
 
-#define TXNFontMenuObj_Check(x) (Py_Type(x) == &TXNFontMenuObject_Type || PyObject_TypeCheck((x), &TXNFontMenuObject_Type))
+#define TXNFontMenuObj_Check(x) (Py_TYPE(x) == &TXNFontMenuObject_Type || PyObject_TypeCheck((x), &TXNFontMenuObject_Type))
 
 typedef struct TXNFontMenuObjectObject {
 	PyObject_HEAD
@@ -1335,7 +1335,7 @@
 static void TXNFontMenuObj_dealloc(TXNFontMenuObjectObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *TXNFontMenuObj_TXNGetFontMenuHandle(TXNFontMenuObjectObject *_self, PyObject *_args)
@@ -1659,14 +1659,14 @@
 	if (Mlte_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Mlte_Error) != 0)
 		return;
-	Py_Type(&TXNObject_Type) = &PyType_Type;
+	Py_TYPE(&TXNObject_Type) = &PyType_Type;
 	if (PyType_Ready(&TXNObject_Type) < 0) return;
 	Py_INCREF(&TXNObject_Type);
 	PyModule_AddObject(m, "TXNObject", (PyObject *)&TXNObject_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&TXNObject_Type);
 	PyModule_AddObject(m, "TXNObjectType", (PyObject *)&TXNObject_Type);
-	Py_Type(&TXNFontMenuObject_Type) = &PyType_Type;
+	Py_TYPE(&TXNFontMenuObject_Type) = &PyType_Type;
 	if (PyType_Ready(&TXNFontMenuObject_Type) < 0) return;
 	Py_INCREF(&TXNFontMenuObject_Type);
 	PyModule_AddObject(m, "TXNFontMenuObject", (PyObject *)&TXNFontMenuObject_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/mlte/mltescan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/mlte/mltescan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/mlte/mltescan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner_OSX

Modified: python/branches/py3k-importlib/Mac/Modules/osa/_OSAmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/osa/_OSAmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/osa/_OSAmodule.c	Thu Mar 27 00:48:05 2008
@@ -34,7 +34,7 @@
 
 PyTypeObject OSAComponentInstance_Type;
 
-#define OSAObj_Check(x) (Py_Type(x) == &OSAComponentInstance_Type || PyObject_TypeCheck((x), &OSAComponentInstance_Type))
+#define OSAObj_Check(x) (Py_TYPE(x) == &OSAComponentInstance_Type || PyObject_TypeCheck((x), &OSAComponentInstance_Type))
 
 typedef struct OSAComponentInstanceObject {
 	PyObject_HEAD
@@ -73,7 +73,7 @@
 static void OSAObj_dealloc(OSAComponentInstanceObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *OSAObj_OSALoad(OSAComponentInstanceObject *_self, PyObject *_args)
@@ -726,314 +726,6 @@
 	return _res;
 }
 
-static PyObject *OSAObj_OSADebuggerCreateSession(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSAID inScript;
-	OSAID inContext;
-	OSADebugSessionRef outSession;
-#ifndef OSADebuggerCreateSession
-	PyMac_PRECHECK(OSADebuggerCreateSession);
-#endif
-	if (!PyArg_ParseTuple(_args, "ll",
-	                      &inScript,
-	                      &inContext))
-		return NULL;
-	_err = OSADebuggerCreateSession(_self->ob_itself,
-	                                inScript,
-	                                inContext,
-	                                &outSession);
-	if (_err != noErr) return PyMac_Error(_err);
-	_res = Py_BuildValue("l",
-	                     outSession);
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerGetSessionState(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugSessionRef inSession;
-	AERecord outState;
-#ifndef OSADebuggerGetSessionState
-	PyMac_PRECHECK(OSADebuggerGetSessionState);
-#endif
-	if (!PyArg_ParseTuple(_args, "l",
-	                      &inSession))
-		return NULL;
-	_err = OSADebuggerGetSessionState(_self->ob_itself,
-	                                  inSession,
-	                                  &outState);
-	if (_err != noErr) return PyMac_Error(_err);
-	_res = Py_BuildValue("O&",
-	                     AEDesc_New, &outState);
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerSessionStep(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugSessionRef inSession;
-	OSADebugStepKind inKind;
-#ifndef OSADebuggerSessionStep
-	PyMac_PRECHECK(OSADebuggerSessionStep);
-#endif
-	if (!PyArg_ParseTuple(_args, "ll",
-	                      &inSession,
-	                      &inKind))
-		return NULL;
-	_err = OSADebuggerSessionStep(_self->ob_itself,
-	                              inSession,
-	                              inKind);
-	if (_err != noErr) return PyMac_Error(_err);
-	Py_INCREF(Py_None);
-	_res = Py_None;
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerDisposeSession(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugSessionRef inSession;
-#ifndef OSADebuggerDisposeSession
-	PyMac_PRECHECK(OSADebuggerDisposeSession);
-#endif
-	if (!PyArg_ParseTuple(_args, "l",
-	                      &inSession))
-		return NULL;
-	_err = OSADebuggerDisposeSession(_self->ob_itself,
-	                                 inSession);
-	if (_err != noErr) return PyMac_Error(_err);
-	Py_INCREF(Py_None);
-	_res = Py_None;
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerGetStatementRanges(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugSessionRef inSession;
-	AEDescList outStatementRangeArray;
-#ifndef OSADebuggerGetStatementRanges
-	PyMac_PRECHECK(OSADebuggerGetStatementRanges);
-#endif
-	if (!PyArg_ParseTuple(_args, "l",
-	                      &inSession))
-		return NULL;
-	_err = OSADebuggerGetStatementRanges(_self->ob_itself,
-	                                     inSession,
-	                                     &outStatementRangeArray);
-	if (_err != noErr) return PyMac_Error(_err);
-	_res = Py_BuildValue("O&",
-	                     AEDesc_New, &outStatementRangeArray);
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerGetBreakpoint(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugSessionRef inSession;
-	UInt32 inSrcOffset;
-	OSAID outBreakpoint;
-#ifndef OSADebuggerGetBreakpoint
-	PyMac_PRECHECK(OSADebuggerGetBreakpoint);
-#endif
-	if (!PyArg_ParseTuple(_args, "ll",
-	                      &inSession,
-	                      &inSrcOffset))
-		return NULL;
-	_err = OSADebuggerGetBreakpoint(_self->ob_itself,
-	                                inSession,
-	                                inSrcOffset,
-	                                &outBreakpoint);
-	if (_err != noErr) return PyMac_Error(_err);
-	_res = Py_BuildValue("l",
-	                     outBreakpoint);
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerSetBreakpoint(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugSessionRef inSession;
-	UInt32 inSrcOffset;
-	OSAID inBreakpoint;
-#ifndef OSADebuggerSetBreakpoint
-	PyMac_PRECHECK(OSADebuggerSetBreakpoint);
-#endif
-	if (!PyArg_ParseTuple(_args, "lll",
-	                      &inSession,
-	                      &inSrcOffset,
-	                      &inBreakpoint))
-		return NULL;
-	_err = OSADebuggerSetBreakpoint(_self->ob_itself,
-	                                inSession,
-	                                inSrcOffset,
-	                                inBreakpoint);
-	if (_err != noErr) return PyMac_Error(_err);
-	Py_INCREF(Py_None);
-	_res = Py_None;
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerGetDefaultBreakpoint(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugSessionRef inSession;
-	OSAID outBreakpoint;
-#ifndef OSADebuggerGetDefaultBreakpoint
-	PyMac_PRECHECK(OSADebuggerGetDefaultBreakpoint);
-#endif
-	if (!PyArg_ParseTuple(_args, "l",
-	                      &inSession))
-		return NULL;
-	_err = OSADebuggerGetDefaultBreakpoint(_self->ob_itself,
-	                                       inSession,
-	                                       &outBreakpoint);
-	if (_err != noErr) return PyMac_Error(_err);
-	_res = Py_BuildValue("l",
-	                     outBreakpoint);
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerGetCurrentCallFrame(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugSessionRef inSession;
-	OSADebugCallFrameRef outCallFrame;
-#ifndef OSADebuggerGetCurrentCallFrame
-	PyMac_PRECHECK(OSADebuggerGetCurrentCallFrame);
-#endif
-	if (!PyArg_ParseTuple(_args, "l",
-	                      &inSession))
-		return NULL;
-	_err = OSADebuggerGetCurrentCallFrame(_self->ob_itself,
-	                                      inSession,
-	                                      &outCallFrame);
-	if (_err != noErr) return PyMac_Error(_err);
-	_res = Py_BuildValue("l",
-	                     outCallFrame);
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerGetCallFrameState(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugCallFrameRef inCallFrame;
-	AERecord outState;
-#ifndef OSADebuggerGetCallFrameState
-	PyMac_PRECHECK(OSADebuggerGetCallFrameState);
-#endif
-	if (!PyArg_ParseTuple(_args, "l",
-	                      &inCallFrame))
-		return NULL;
-	_err = OSADebuggerGetCallFrameState(_self->ob_itself,
-	                                    inCallFrame,
-	                                    &outState);
-	if (_err != noErr) return PyMac_Error(_err);
-	_res = Py_BuildValue("O&",
-	                     AEDesc_New, &outState);
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerGetVariable(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugCallFrameRef inCallFrame;
-	AEDesc inVariableName;
-	OSAID outVariable;
-#ifndef OSADebuggerGetVariable
-	PyMac_PRECHECK(OSADebuggerGetVariable);
-#endif
-	if (!PyArg_ParseTuple(_args, "lO&",
-	                      &inCallFrame,
-	                      AEDesc_Convert, &inVariableName))
-		return NULL;
-	_err = OSADebuggerGetVariable(_self->ob_itself,
-	                              inCallFrame,
-	                              &inVariableName,
-	                              &outVariable);
-	if (_err != noErr) return PyMac_Error(_err);
-	_res = Py_BuildValue("l",
-	                     outVariable);
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerSetVariable(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugCallFrameRef inCallFrame;
-	AEDesc inVariableName;
-	OSAID inVariable;
-#ifndef OSADebuggerSetVariable
-	PyMac_PRECHECK(OSADebuggerSetVariable);
-#endif
-	if (!PyArg_ParseTuple(_args, "lO&l",
-	                      &inCallFrame,
-	                      AEDesc_Convert, &inVariableName,
-	                      &inVariable))
-		return NULL;
-	_err = OSADebuggerSetVariable(_self->ob_itself,
-	                              inCallFrame,
-	                              &inVariableName,
-	                              inVariable);
-	if (_err != noErr) return PyMac_Error(_err);
-	Py_INCREF(Py_None);
-	_res = Py_None;
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerGetPreviousCallFrame(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugCallFrameRef inCurrentFrame;
-	OSADebugCallFrameRef outPrevFrame;
-#ifndef OSADebuggerGetPreviousCallFrame
-	PyMac_PRECHECK(OSADebuggerGetPreviousCallFrame);
-#endif
-	if (!PyArg_ParseTuple(_args, "l",
-	                      &inCurrentFrame))
-		return NULL;
-	_err = OSADebuggerGetPreviousCallFrame(_self->ob_itself,
-	                                       inCurrentFrame,
-	                                       &outPrevFrame);
-	if (_err != noErr) return PyMac_Error(_err);
-	_res = Py_BuildValue("l",
-	                     outPrevFrame);
-	return _res;
-}
-
-static PyObject *OSAObj_OSADebuggerDisposeCallFrame(OSAComponentInstanceObject *_self, PyObject *_args)
-{
-	PyObject *_res = NULL;
-	OSAError _err;
-	OSADebugCallFrameRef inCallFrame;
-#ifndef OSADebuggerDisposeCallFrame
-	PyMac_PRECHECK(OSADebuggerDisposeCallFrame);
-#endif
-	if (!PyArg_ParseTuple(_args, "l",
-	                      &inCallFrame))
-		return NULL;
-	_err = OSADebuggerDisposeCallFrame(_self->ob_itself,
-	                                   inCallFrame);
-	if (_err != noErr) return PyMac_Error(_err);
-	Py_INCREF(Py_None);
-	_res = Py_None;
-	return _res;
-}
-
 static PyMethodDef OSAObj_methods[] = {
 	{"OSALoad", (PyCFunction)OSAObj_OSALoad, 1,
 	 PyDoc_STR("(AEDesc scriptData, long modeFlags) -> (OSAID resultingScriptID)")},
@@ -1091,34 +783,6 @@
 	 PyDoc_STR("(AppleEvent theAppleEvent, OSAID contextID, long modeFlags) -> (AppleEvent reply)")},
 	{"OSAMakeContext", (PyCFunction)OSAObj_OSAMakeContext, 1,
 	 PyDoc_STR("(AEDesc contextName, OSAID parentContext) -> (OSAID resultingContextID)")},
-	{"OSADebuggerCreateSession", (PyCFunction)OSAObj_OSADebuggerCreateSession, 1,
-	 PyDoc_STR("(OSAID inScript, OSAID inContext) -> (OSADebugSessionRef outSession)")},
-	{"OSADebuggerGetSessionState", (PyCFunction)OSAObj_OSADebuggerGetSessionState, 1,
-	 PyDoc_STR("(OSADebugSessionRef inSession) -> (AERecord outState)")},
-	{"OSADebuggerSessionStep", (PyCFunction)OSAObj_OSADebuggerSessionStep, 1,
-	 PyDoc_STR("(OSADebugSessionRef inSession, OSADebugStepKind inKind) -> None")},
-	{"OSADebuggerDisposeSession", (PyCFunction)OSAObj_OSADebuggerDisposeSession, 1,
-	 PyDoc_STR("(OSADebugSessionRef inSession) -> None")},
-	{"OSADebuggerGetStatementRanges", (PyCFunction)OSAObj_OSADebuggerGetStatementRanges, 1,
-	 PyDoc_STR("(OSADebugSessionRef inSession) -> (AEDescList outStatementRangeArray)")},
-	{"OSADebuggerGetBreakpoint", (PyCFunction)OSAObj_OSADebuggerGetBreakpoint, 1,
-	 PyDoc_STR("(OSADebugSessionRef inSession, UInt32 inSrcOffset) -> (OSAID outBreakpoint)")},
-	{"OSADebuggerSetBreakpoint", (PyCFunction)OSAObj_OSADebuggerSetBreakpoint, 1,
-	 PyDoc_STR("(OSADebugSessionRef inSession, UInt32 inSrcOffset, OSAID inBreakpoint) -> None")},
-	{"OSADebuggerGetDefaultBreakpoint", (PyCFunction)OSAObj_OSADebuggerGetDefaultBreakpoint, 1,
-	 PyDoc_STR("(OSADebugSessionRef inSession) -> (OSAID outBreakpoint)")},
-	{"OSADebuggerGetCurrentCallFrame", (PyCFunction)OSAObj_OSADebuggerGetCurrentCallFrame, 1,
-	 PyDoc_STR("(OSADebugSessionRef inSession) -> (OSADebugCallFrameRef outCallFrame)")},
-	{"OSADebuggerGetCallFrameState", (PyCFunction)OSAObj_OSADebuggerGetCallFrameState, 1,
-	 PyDoc_STR("(OSADebugCallFrameRef inCallFrame) -> (AERecord outState)")},
-	{"OSADebuggerGetVariable", (PyCFunction)OSAObj_OSADebuggerGetVariable, 1,
-	 PyDoc_STR("(OSADebugCallFrameRef inCallFrame, AEDesc inVariableName) -> (OSAID outVariable)")},
-	{"OSADebuggerSetVariable", (PyCFunction)OSAObj_OSADebuggerSetVariable, 1,
-	 PyDoc_STR("(OSADebugCallFrameRef inCallFrame, AEDesc inVariableName, OSAID inVariable) -> None")},
-	{"OSADebuggerGetPreviousCallFrame", (PyCFunction)OSAObj_OSADebuggerGetPreviousCallFrame, 1,
-	 PyDoc_STR("(OSADebugCallFrameRef inCurrentFrame) -> (OSADebugCallFrameRef outPrevFrame)")},
-	{"OSADebuggerDisposeCallFrame", (PyCFunction)OSAObj_OSADebuggerDisposeCallFrame, 1,
-	 PyDoc_STR("(OSADebugCallFrameRef inCallFrame) -> None")},
 	{NULL, NULL, 0}
 };
 
@@ -1221,7 +885,7 @@
 	if (OSA_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", OSA_Error) != 0)
 		return;
-	Py_Type(&OSAComponentInstance_Type) = &PyType_Type;
+	Py_TYPE(&OSAComponentInstance_Type) = &PyType_Type;
 	if (PyType_Ready(&OSAComponentInstance_Type) < 0) return;
 	Py_INCREF(&OSAComponentInstance_Type);
 	PyModule_AddObject(m, "OSAComponentInstance", (PyObject *)&OSAComponentInstance_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/osa/osascan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/osa/osascan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/osa/osascan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner

Modified: python/branches/py3k-importlib/Mac/Modules/qd/_Qdmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/qd/_Qdmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/qd/_Qdmodule.c	Thu Mar 27 00:48:05 2008
@@ -73,7 +73,7 @@
 
 PyTypeObject GrafPort_Type;
 
-#define GrafObj_Check(x) (Py_Type(x) == &GrafPort_Type || PyObject_TypeCheck((x), &GrafPort_Type))
+#define GrafObj_Check(x) (Py_TYPE(x) == &GrafPort_Type || PyObject_TypeCheck((x), &GrafPort_Type))
 
 typedef struct GrafPortObject {
 	PyObject_HEAD
@@ -125,7 +125,7 @@
 static void GrafObj_dealloc(GrafPortObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *GrafObj_MacSetPort(GrafPortObject *_self, PyObject *_args)
@@ -1407,7 +1407,7 @@
 
 PyTypeObject BitMap_Type;
 
-#define BMObj_Check(x) (Py_Type(x) == &BitMap_Type || PyObject_TypeCheck((x), &BitMap_Type))
+#define BMObj_Check(x) (Py_TYPE(x) == &BitMap_Type || PyObject_TypeCheck((x), &BitMap_Type))
 
 typedef struct BitMapObject {
 	PyObject_HEAD
@@ -1443,7 +1443,7 @@
 {
 	Py_XDECREF(self->referred_object);
 	if (self->referred_bitmap) free(self->referred_bitmap);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *BMObj_getdata(BitMapObject *_self, PyObject *_args)
@@ -1488,14 +1488,14 @@
 
 static PyObject *BMObj_get_baseAddr(BitMapObject *self, void *closure)
 {
-	return PyInt_FromLong((long)self->ob_itself->baseAddr);
+	return PyLong_FromLong((long)self->ob_itself->baseAddr);
 }
 
 #define BMObj_set_baseAddr NULL
 
 static PyObject *BMObj_get_rowBytes(BitMapObject *self, void *closure)
 {
-	return PyInt_FromLong((long)self->ob_itself->rowBytes);
+	return PyLong_FromLong((long)self->ob_itself->rowBytes);
 }
 
 #define BMObj_set_rowBytes NULL
@@ -7122,14 +7122,14 @@
 	if (Qd_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Qd_Error) != 0)
 		return;
-	Py_Type(&GrafPort_Type) = &PyType_Type;
+	Py_TYPE(&GrafPort_Type) = &PyType_Type;
 	if (PyType_Ready(&GrafPort_Type) < 0) return;
 	Py_INCREF(&GrafPort_Type);
 	PyModule_AddObject(m, "GrafPort", (PyObject *)&GrafPort_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&GrafPort_Type);
 	PyModule_AddObject(m, "GrafPortType", (PyObject *)&GrafPort_Type);
-	Py_Type(&BitMap_Type) = &PyType_Type;
+	Py_TYPE(&BitMap_Type) = &PyType_Type;
 	if (PyType_Ready(&BitMap_Type) < 0) return;
 	Py_INCREF(&BitMap_Type);
 	PyModule_AddObject(m, "BitMap", (PyObject *)&BitMap_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/qd/qdscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/qd/qdscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/qd/qdscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 

Modified: python/branches/py3k-importlib/Mac/Modules/qdoffs/_Qdoffsmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/qdoffs/_Qdoffsmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/qdoffs/_Qdoffsmodule.c	Thu Mar 27 00:48:05 2008
@@ -34,7 +34,7 @@
 
 PyTypeObject GWorld_Type;
 
-#define GWorldObj_Check(x) (Py_Type(x) == &GWorld_Type || PyObject_TypeCheck((x), &GWorld_Type))
+#define GWorldObj_Check(x) (Py_TYPE(x) == &GWorld_Type || PyObject_TypeCheck((x), &GWorld_Type))
 
 typedef struct GWorldObject {
 	PyObject_HEAD
@@ -65,7 +65,7 @@
 static void GWorldObj_dealloc(GWorldObject *self)
 {
 	DisposeGWorld(self->ob_itself);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *GWorldObj_GetGWorldDevice(GWorldObject *_self, PyObject *_args)
@@ -700,7 +700,7 @@
 	if (Qdoffs_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Qdoffs_Error) != 0)
 		return;
-	Py_Type(&GWorld_Type) = &PyType_Type;
+	Py_TYPE(&GWorld_Type) = &PyType_Type;
 	if (PyType_Ready(&GWorld_Type) < 0) return;
 	Py_INCREF(&GWorld_Type);
 	PyModule_AddObject(m, "GWorld", (PyObject *)&GWorld_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/qdoffs/qdoffsscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/qdoffs/qdoffsscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/qdoffs/qdoffsscan.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,5 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 

Modified: python/branches/py3k-importlib/Mac/Modules/qt/_Qtmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/qt/_Qtmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/qt/_Qtmodule.c	Thu Mar 27 00:48:05 2008
@@ -97,7 +97,7 @@
 
 PyTypeObject IdleManager_Type;
 
-#define IdleManagerObj_Check(x) (Py_Type(x) == &IdleManager_Type || PyObject_TypeCheck((x), &IdleManager_Type))
+#define IdleManagerObj_Check(x) (Py_TYPE(x) == &IdleManager_Type || PyObject_TypeCheck((x), &IdleManager_Type))
 
 typedef struct IdleManagerObject {
 	PyObject_HEAD
@@ -136,7 +136,7 @@
 static void IdleManagerObj_dealloc(IdleManagerObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyMethodDef IdleManagerObj_methods[] = {
@@ -220,7 +220,7 @@
 
 PyTypeObject MovieController_Type;
 
-#define MovieCtlObj_Check(x) (Py_Type(x) == &MovieController_Type || PyObject_TypeCheck((x), &MovieController_Type))
+#define MovieCtlObj_Check(x) (Py_TYPE(x) == &MovieController_Type || PyObject_TypeCheck((x), &MovieController_Type))
 
 typedef struct MovieControllerObject {
 	PyObject_HEAD
@@ -259,7 +259,7 @@
 static void MovieCtlObj_dealloc(MovieControllerObject *self)
 {
 	if (self->ob_itself) DisposeMovieController(self->ob_itself);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *MovieCtlObj_MCSetMovie(MovieControllerObject *_self, PyObject *_args)
@@ -1339,7 +1339,7 @@
 
 PyTypeObject TimeBase_Type;
 
-#define TimeBaseObj_Check(x) (Py_Type(x) == &TimeBase_Type || PyObject_TypeCheck((x), &TimeBase_Type))
+#define TimeBaseObj_Check(x) (Py_TYPE(x) == &TimeBase_Type || PyObject_TypeCheck((x), &TimeBase_Type))
 
 typedef struct TimeBaseObject {
 	PyObject_HEAD
@@ -1378,7 +1378,7 @@
 static void TimeBaseObj_dealloc(TimeBaseObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *TimeBaseObj_DisposeTimeBase(TimeBaseObject *_self, PyObject *_args)
@@ -1832,7 +1832,7 @@
 
 PyTypeObject UserData_Type;
 
-#define UserDataObj_Check(x) (Py_Type(x) == &UserData_Type || PyObject_TypeCheck((x), &UserData_Type))
+#define UserDataObj_Check(x) (Py_TYPE(x) == &UserData_Type || PyObject_TypeCheck((x), &UserData_Type))
 
 typedef struct UserDataObject {
 	PyObject_HEAD
@@ -1871,7 +1871,7 @@
 static void UserDataObj_dealloc(UserDataObject *self)
 {
 	if (self->ob_itself) DisposeUserData(self->ob_itself);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *UserDataObj_GetUserData(UserDataObject *_self, PyObject *_args)
@@ -2202,7 +2202,7 @@
 
 PyTypeObject Media_Type;
 
-#define MediaObj_Check(x) (Py_Type(x) == &Media_Type || PyObject_TypeCheck((x), &Media_Type))
+#define MediaObj_Check(x) (Py_TYPE(x) == &Media_Type || PyObject_TypeCheck((x), &Media_Type))
 
 typedef struct MediaObject {
 	PyObject_HEAD
@@ -2241,7 +2241,7 @@
 static void MediaObj_dealloc(MediaObject *self)
 {
 	if (self->ob_itself) DisposeTrackMedia(self->ob_itself);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *MediaObj_LoadMediaIntoRam(MediaObject *_self, PyObject *_args)
@@ -3443,7 +3443,7 @@
 
 PyTypeObject Track_Type;
 
-#define TrackObj_Check(x) (Py_Type(x) == &Track_Type || PyObject_TypeCheck((x), &Track_Type))
+#define TrackObj_Check(x) (Py_TYPE(x) == &Track_Type || PyObject_TypeCheck((x), &Track_Type))
 
 typedef struct TrackObject {
 	PyObject_HEAD
@@ -3482,7 +3482,7 @@
 static void TrackObj_dealloc(TrackObject *self)
 {
 	if (self->ob_itself) DisposeMovieTrack(self->ob_itself);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *TrackObj_LoadTrackIntoRam(TrackObject *_self, PyObject *_args)
@@ -4790,7 +4790,7 @@
 
 PyTypeObject Movie_Type;
 
-#define MovieObj_Check(x) (Py_Type(x) == &Movie_Type || PyObject_TypeCheck((x), &Movie_Type))
+#define MovieObj_Check(x) (Py_TYPE(x) == &Movie_Type || PyObject_TypeCheck((x), &Movie_Type))
 
 typedef struct MovieObject {
 	PyObject_HEAD
@@ -4829,7 +4829,7 @@
 static void MovieObj_dealloc(MovieObject *self)
 {
 	if (self->ob_itself) DisposeMovie(self->ob_itself);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *MovieObj_MoviesTask(MovieObject *_self, PyObject *_args)
@@ -7342,7 +7342,7 @@
 
 PyTypeObject SGOutput_Type;
 
-#define SGOutputObj_Check(x) (Py_Type(x) == &SGOutput_Type || PyObject_TypeCheck((x), &SGOutput_Type))
+#define SGOutputObj_Check(x) (Py_TYPE(x) == &SGOutput_Type || PyObject_TypeCheck((x), &SGOutput_Type))
 
 typedef struct SGOutputObject {
 	PyObject_HEAD
@@ -7381,7 +7381,7 @@
 static void SGOutputObj_dealloc(SGOutputObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyMethodDef SGOutputObj_methods[] = {
@@ -28013,56 +28013,56 @@
 	if (Qt_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Qt_Error) != 0)
 		return;
-	Py_Type(&IdleManager_Type) = &PyType_Type;
+	Py_TYPE(&IdleManager_Type) = &PyType_Type;
 	if (PyType_Ready(&IdleManager_Type) < 0) return;
 	Py_INCREF(&IdleManager_Type);
 	PyModule_AddObject(m, "IdleManager", (PyObject *)&IdleManager_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&IdleManager_Type);
 	PyModule_AddObject(m, "IdleManagerType", (PyObject *)&IdleManager_Type);
-	Py_Type(&MovieController_Type) = &PyType_Type;
+	Py_TYPE(&MovieController_Type) = &PyType_Type;
 	if (PyType_Ready(&MovieController_Type) < 0) return;
 	Py_INCREF(&MovieController_Type);
 	PyModule_AddObject(m, "MovieController", (PyObject *)&MovieController_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&MovieController_Type);
 	PyModule_AddObject(m, "MovieControllerType", (PyObject *)&MovieController_Type);
-	Py_Type(&TimeBase_Type) = &PyType_Type;
+	Py_TYPE(&TimeBase_Type) = &PyType_Type;
 	if (PyType_Ready(&TimeBase_Type) < 0) return;
 	Py_INCREF(&TimeBase_Type);
 	PyModule_AddObject(m, "TimeBase", (PyObject *)&TimeBase_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&TimeBase_Type);
 	PyModule_AddObject(m, "TimeBaseType", (PyObject *)&TimeBase_Type);
-	Py_Type(&UserData_Type) = &PyType_Type;
+	Py_TYPE(&UserData_Type) = &PyType_Type;
 	if (PyType_Ready(&UserData_Type) < 0) return;
 	Py_INCREF(&UserData_Type);
 	PyModule_AddObject(m, "UserData", (PyObject *)&UserData_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&UserData_Type);
 	PyModule_AddObject(m, "UserDataType", (PyObject *)&UserData_Type);
-	Py_Type(&Media_Type) = &PyType_Type;
+	Py_TYPE(&Media_Type) = &PyType_Type;
 	if (PyType_Ready(&Media_Type) < 0) return;
 	Py_INCREF(&Media_Type);
 	PyModule_AddObject(m, "Media", (PyObject *)&Media_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&Media_Type);
 	PyModule_AddObject(m, "MediaType", (PyObject *)&Media_Type);
-	Py_Type(&Track_Type) = &PyType_Type;
+	Py_TYPE(&Track_Type) = &PyType_Type;
 	if (PyType_Ready(&Track_Type) < 0) return;
 	Py_INCREF(&Track_Type);
 	PyModule_AddObject(m, "Track", (PyObject *)&Track_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&Track_Type);
 	PyModule_AddObject(m, "TrackType", (PyObject *)&Track_Type);
-	Py_Type(&Movie_Type) = &PyType_Type;
+	Py_TYPE(&Movie_Type) = &PyType_Type;
 	if (PyType_Ready(&Movie_Type) < 0) return;
 	Py_INCREF(&Movie_Type);
 	PyModule_AddObject(m, "Movie", (PyObject *)&Movie_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&Movie_Type);
 	PyModule_AddObject(m, "MovieType", (PyObject *)&Movie_Type);
-	Py_Type(&SGOutput_Type) = &PyType_Type;
+	Py_TYPE(&SGOutput_Type) = &PyType_Type;
 	if (PyType_Ready(&SGOutput_Type) < 0) return;
 	Py_INCREF(&SGOutput_Type);
 	PyModule_AddObject(m, "SGOutput", (PyObject *)&SGOutput_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/qt/qtscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/qt/qtscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/qt/qtscan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner

Modified: python/branches/py3k-importlib/Mac/Modules/res/_Resmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/res/_Resmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/res/_Resmodule.c	Thu Mar 27 00:48:05 2008
@@ -41,7 +41,7 @@
 
 PyTypeObject Resource_Type;
 
-#define ResObj_Check(x) (Py_Type(x) == &Resource_Type || PyObject_TypeCheck((x), &Resource_Type))
+#define ResObj_Check(x) (Py_TYPE(x) == &Resource_Type || PyObject_TypeCheck((x), &Resource_Type))
 
 typedef struct ResourceObject {
 	PyObject_HEAD
@@ -89,7 +89,7 @@
 		self->ob_freeit(self->ob_itself);
 	}
 	self->ob_itself = NULL;
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *ResObj_HomeResFile(ResourceObject *_self, PyObject *_args)
@@ -556,7 +556,7 @@
 
 static PyObject *ResObj_get_size(ResourceObject *self, void *closure)
 {
-	return PyInt_FromLong(GetHandleSize(self->ob_itself));
+	return PyLong_FromLong(GetHandleSize(self->ob_itself));
 }
 
 #define ResObj_set_size NULL
@@ -1730,7 +1730,7 @@
 	if (Res_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Res_Error) != 0)
 		return;
-	Py_Type(&Resource_Type) = &PyType_Type;
+	Py_TYPE(&Resource_Type) = &PyType_Type;
 	if (PyType_Ready(&Resource_Type) < 0) return;
 	Py_INCREF(&Resource_Type);
 	PyModule_AddObject(m, "Resource", (PyObject *)&Resource_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/res/resscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/res/resscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/res/resscan.py	Thu Mar 27 00:48:05 2008
@@ -3,8 +3,6 @@
 # (Should learn how to tell the compiler to compile it as well.)
 
 import sys
-import os
-import string
 import MacOS
 
 from bgenlocations import TOOLBOXDIR, BGENDIR

Modified: python/branches/py3k-importlib/Mac/Modules/scrap/_Scrapmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/scrap/_Scrapmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/scrap/_Scrapmodule.c	Thu Mar 27 00:48:05 2008
@@ -23,7 +23,7 @@
 
 PyTypeObject Scrap_Type;
 
-#define ScrapObj_Check(x) (Py_Type(x) == &Scrap_Type || PyObject_TypeCheck((x), &Scrap_Type))
+#define ScrapObj_Check(x) (Py_TYPE(x) == &Scrap_Type || PyObject_TypeCheck((x), &Scrap_Type))
 
 typedef struct ScrapObject {
 	PyObject_HEAD
@@ -52,7 +52,7 @@
 static void ScrapObj_dealloc(ScrapObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *ScrapObj_GetScrapFlavorFlags(ScrapObject *_self, PyObject *_args)
@@ -346,7 +346,7 @@
 	if (Scrap_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Scrap_Error) != 0)
 		return;
-	Py_Type(&Scrap_Type) = &PyType_Type;
+	Py_TYPE(&Scrap_Type) = &PyType_Type;
 	Py_INCREF(&Scrap_Type);
 	if (PyDict_SetItemString(d, "ScrapType", (PyObject *)&Scrap_Type) != 0)
 		Py_FatalError("can't initialize ScrapType");

Modified: python/branches/py3k-importlib/Mac/Modules/scrap/scrapscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/scrap/scrapscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/scrap/scrapscan.py	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,6 @@
 # generates a boilerplate to be edited by hand.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner

Modified: python/branches/py3k-importlib/Mac/Modules/snd/_Sndihooks.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/snd/_Sndihooks.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/snd/_Sndihooks.c	Thu Mar 27 00:48:05 2008
@@ -409,7 +409,7 @@
 	if( (rsizes = PyTuple_New(arg.numsizes)) == NULL)
 		return NULL;
 	for( i=0; i<arg.numsizes; i++ )
-		PyTuple_SetItem(rsizes, i, PyInt_FromLong((long)fsizes[i]));
+		PyTuple_SetItem(rsizes, i, PyLong_FromLong((long)fsizes[i]));
 	return rsizes;
 }
 

Modified: python/branches/py3k-importlib/Mac/Modules/snd/_Sndmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/snd/_Sndmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/snd/_Sndmodule.c	Thu Mar 27 00:48:05 2008
@@ -42,7 +42,7 @@
 
 static PyTypeObject SndChannel_Type;
 
-#define SndCh_Check(x) (Py_Type(x) == &SndChannel_Type || PyObject_TypeCheck((x), &SndChannel_Type))
+#define SndCh_Check(x) (Py_TYPE(x) == &SndChannel_Type || PyObject_TypeCheck((x), &SndChannel_Type))
 
 typedef struct SndChannelObject {
 	PyObject_HEAD
@@ -256,7 +256,7 @@
 
 static PyTypeObject SPB_Type;
 
-#define SPBObj_Check(x) (Py_Type(x) == &SPB_Type || PyObject_TypeCheck((x), &SPB_Type))
+#define SPBObj_Check(x) (Py_TYPE(x) == &SPB_Type || PyObject_TypeCheck((x), &SPB_Type))
 
 typedef struct SPBObject {
 	PyObject_HEAD
@@ -1129,14 +1129,14 @@
 	if (Snd_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Snd_Error) != 0)
 		return;
-	Py_Type(&SndChannel_Type) = &PyType_Type;
+	Py_TYPE(&SndChannel_Type) = &PyType_Type;
 	if (PyType_Ready(&SndChannel_Type) < 0) return;
 	Py_INCREF(&SndChannel_Type);
 	PyModule_AddObject(m, "SndChannel", (PyObject *)&SndChannel_Type);
 	/* Backward-compatible name */
 	Py_INCREF(&SndChannel_Type);
 	PyModule_AddObject(m, "SndChannelType", (PyObject *)&SndChannel_Type);
-	Py_Type(&SPB_Type) = &PyType_Type;
+	Py_TYPE(&SPB_Type) = &PyType_Type;
 	if (PyType_Ready(&SPB_Type) < 0) return;
 	Py_INCREF(&SPB_Type);
 	PyModule_AddObject(m, "SPB", (PyObject *)&SPB_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/snd/sndscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/snd/sndscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/snd/sndscan.py	Thu Mar 27 00:48:05 2008
@@ -3,7 +3,6 @@
 # (Should learn how to tell the compiler to compile it as well.)
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 

Modified: python/branches/py3k-importlib/Mac/Modules/te/_TEmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/te/_TEmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/te/_TEmodule.c	Thu Mar 27 00:48:05 2008
@@ -58,7 +58,7 @@
 
 PyTypeObject TE_Type;
 
-#define TEObj_Check(x) (Py_Type(x) == &TE_Type || PyObject_TypeCheck((x), &TE_Type))
+#define TEObj_Check(x) (Py_TYPE(x) == &TE_Type || PyObject_TypeCheck((x), &TE_Type))
 
 typedef struct TEObject {
 	PyObject_HEAD
@@ -92,7 +92,7 @@
 static void TEObj_dealloc(TEObject *self)
 {
 	TEDispose(self->ob_itself);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *TEObj_TESetText(TEObject *_self, PyObject *_args)
@@ -1317,7 +1317,7 @@
 	if (TE_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", TE_Error) != 0)
 		return;
-	Py_Type(&TE_Type) = &PyType_Type;
+	Py_TYPE(&TE_Type) = &PyType_Type;
 	if (PyType_Ready(&TE_Type) < 0) return;
 	Py_INCREF(&TE_Type);
 	PyModule_AddObject(m, "TE", (PyObject *)&TE_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/te/tescan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/te/tescan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/te/tescan.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,6 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 from scantools import Scanner

Modified: python/branches/py3k-importlib/Mac/Modules/win/_Winmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/win/_Winmodule.c	(original)
+++ python/branches/py3k-importlib/Mac/Modules/win/_Winmodule.c	Thu Mar 27 00:48:05 2008
@@ -45,7 +45,7 @@
 
 PyTypeObject Window_Type;
 
-#define WinObj_Check(x) (Py_Type(x) == &Window_Type || PyObject_TypeCheck((x), &Window_Type))
+#define WinObj_Check(x) (Py_TYPE(x) == &Window_Type || PyObject_TypeCheck((x), &Window_Type))
 
 typedef struct WindowObject {
 	PyObject_HEAD
@@ -74,7 +74,7 @@
 {
 
 	if (v == Py_None) { *p_itself = NULL; return 1; }
-	if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
+	if (PyLong_Check(v)) { *p_itself = (WindowPtr)PyLong_AsLong(v); return 1; }
 
 	{
 		DialogRef dlg;
@@ -102,7 +102,7 @@
 	}
 	self->ob_itself = NULL;
 	self->ob_freeit = NULL;
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *WinObj_GetWindowOwnerCount(WindowObject *_self, PyObject *_args)
@@ -3244,7 +3244,7 @@
 	if (Win_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Win_Error) != 0)
 		return;
-	Py_Type(&Window_Type) = &PyType_Type;
+	Py_TYPE(&Window_Type) = &PyType_Type;
 	if (PyType_Ready(&Window_Type) < 0) return;
 	Py_INCREF(&Window_Type);
 	PyModule_AddObject(m, "Window", (PyObject *)&Window_Type);

Modified: python/branches/py3k-importlib/Mac/Modules/win/winscan.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/win/winscan.py	(original)
+++ python/branches/py3k-importlib/Mac/Modules/win/winscan.py	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,5 @@
 # Scan an Apple header file, generating a Python file of generator calls.
 import sys
-import os
 from bgenlocations import TOOLBOXDIR, BGENDIR
 sys.path.append(BGENDIR)
 

Modified: python/branches/py3k-importlib/Makefile.pre.in
==============================================================================
--- python/branches/py3k-importlib/Makefile.pre.in	(original)
+++ python/branches/py3k-importlib/Makefile.pre.in	Thu Mar 27 00:48:05 2008
@@ -169,7 +169,8 @@
 DLINCLDIR=	@DLINCLDIR@
 DYNLOADFILE=	@DYNLOADFILE@
 MACHDEP_OBJS=	@MACHDEP_OBJS@
-UNICODE_OBJS=   @UNICODE_OBJS@
+LIBOBJDIR=	Python/
+LIBOBJS=	@LIBOBJS@
 
 PYTHON=		python$(EXE)
 BUILDPYTHON=	python$(BUILDEXE)
@@ -222,6 +223,10 @@
 		Parser/printgrammar.o \
 		Parser/pgenmain.o
 
+PARSER_HEADERS= \
+		Parser/parser.h \
+		Parser/tokenizer.h
+
 PGENOBJS=	$(PGENMAIN) $(POBJS) $(PGOBJS)
 
 ##########################################################################
@@ -273,9 +278,11 @@
 		Python/sysmodule.o \
 		Python/traceback.o \
 		Python/getopt.o \
+		Python/pystrcmp.o \
 		Python/pystrtod.o \
 		Python/formatter_unicode.o \
 		Python/$(DYNLOADFILE) \
+		$(LIBOBJS) \
 		$(MACHDEP_OBJS) \
 		$(THREADOBJ)
 
@@ -285,6 +292,7 @@
 OBJECT_OBJS=	\
 		Objects/abstract.o \
 		Objects/boolobject.o \
+		Objects/bytes_methods.o \
 		Objects/bytesobject.o \
 		Objects/cellobject.o \
 		Objects/classobject.o \
@@ -315,8 +323,9 @@
 		Objects/structseq.o \
 		Objects/tupleobject.o \
 		Objects/typeobject.o \
-		Objects/weakrefobject.o \
-		$(UNICODE_OBJS)
+		Objects/unicodeobject.o \
+		Objects/unicodectype.o \
+		Objects/weakrefobject.o
 
 
 ##########################################################################
@@ -335,7 +344,8 @@
 # Rules
 
 # Default target
-all:		$(BUILDPYTHON) oldsharedmods sharedmods
+all:		build_all
+build_all:	$(BUILDPYTHON) oldsharedmods sharedmods
 
 # Build the interpreter
 $(BUILDPYTHON):	Modules/python.o $(LIBRARY) $(LDLIBRARY)
@@ -350,7 +360,7 @@
 # Build the shared modules
 sharedmods: $(BUILDPYTHON)
 	@case $$MAKEFLAGS in \
-	*-s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
+	*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
 	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
 	esac
 
@@ -475,7 +485,7 @@
 
 
 $(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
-		-@ mkdir Include
+		-@$(INSTALL) -d Include
 		-$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
 
 $(PGEN):	$(PGENOBJS)
@@ -507,29 +517,44 @@
 Objects/unicodectype.o:	$(srcdir)/Objects/unicodectype.c \
 				$(srcdir)/Objects/unicodetype_db.h
 
+BYTESTR_DEPS = \
+		$(srcdir/Include/bytes_methods.h \
+		$(srcdir)/Objects/stringlib/count.h \
+		$(srcdir)/Objects/stringlib/ctype.h \
+		$(srcdir)/Objects/stringlib/eq.h \
+		$(srcdir)/Objects/stringlib/fastsearch.h \
+		$(srcdir)/Objects/stringlib/find.h \
+		$(srcdir)/Objects/stringlib/partition.h \
+		$(srcdir)/Objects/stringlib/stringdefs.h \
+		$(srcdir)/Objects/stringlib/string_format.h \
+		$(srcdir)/Objects/stringlib/transmogrify.h \
+		$(srcdir)/Objects/stringlib/unicodedefs.h \
+
+Objects/stringobject.o: $(srcdir)/Objects/stringobject.c $(BYTESTR_DEPS)
+
+Objects/bytesobject.o: $(srcdir)/Objects/bytesobject.c $(BYTESTR_DEPS) 
+
 Objects/unicodeobject.o: $(srcdir)/Objects/unicodeobject.c \
-				$(srcdir)/Objects/stringlib/string_format.h \
-	                        $(srcdir)/Objects/stringlib/unicodedefs.h \
-	                        $(srcdir)/Objects/stringlib/fastsearch.h \
-	                        $(srcdir)/Objects/stringlib/count.h \
-	                        $(srcdir)/Objects/stringlib/find.h \
-	                        $(srcdir)/Objects/stringlib/partition.h
+                                             $(BYTESTR_DEPS)
 
 Python/formatter_unicode.o: $(srcdir)/Python/formatter_unicode.c \
-	                        $(srcdir)/Objects/stringlib/formatter.h
-
+                                             $(BYTESTR_DEPS)
 
 
 ############################################################################
 # Header files
 
 PYTHON_HEADERS= \
-		Include/Python.h \
 		Include/Python-ast.h \
-		Include/asdl.h \
+		Include/Python.h \
 		Include/abstract.h \
+		Include/asdl.h \
+		Include/ast.h \
+		Include/bitset.h \
 		Include/boolobject.h \
+		Include/bytes_methods.h \
 		Include/bytesobject.h \
+		Include/cellobject.h \
 		Include/ceval.h \
 		Include/classobject.h \
 		Include/cobject.h \
@@ -540,46 +565,62 @@
 		Include/descrobject.h \
 		Include/dictobject.h \
 		Include/enumobject.h \
-		Include/genobject.h \
+		Include/errcode.h \
+		Include/eval.h \
 		Include/fileobject.h \
 		Include/floatobject.h \
 		Include/formatter_unicode.h \
+		Include/frameobject.h \
 		Include/funcobject.h \
+		Include/genobject.h \
 		Include/import.h \
-		Include/intobject.h \
 		Include/intrcheck.h \
 		Include/iterobject.h \
 		Include/listobject.h \
+		Include/longintrepr.h \
 		Include/longobject.h \
+		Include/marshal.h \
 		Include/memoryobject.h \
+		Include/metagrammar.h \
 		Include/methodobject.h \
 		Include/modsupport.h \
 		Include/moduleobject.h \
+		Include/node.h \
 		Include/object.h \
 		Include/objimpl.h \
+		Include/opcode.h \
+		Include/osdefs.h \
 		Include/parsetok.h \
 		Include/patchlevel.h \
+		Include/pgen.h \
+		Include/pgenheaders.h \
 		Include/pyarena.h \
 		Include/pydebug.h \
 		Include/pyerrors.h \
 		Include/pyfpe.h \
+		Include/pygetopt.h \
 		Include/pymem.h \
 		Include/pyport.h \
 		Include/pystate.h \
+		Include/pystrcmp.h \
+		Include/pystrtod.h \
 		Include/pythonrun.h \
+		Include/pythread.h \
 		Include/rangeobject.h \
-                Include/setobject.h \
+		Include/setobject.h \
 		Include/sliceobject.h \
 		Include/stringobject.h \
-		Include/structseq.h \
 		Include/structmember.h \
+		Include/structseq.h \
 		Include/symtable.h \
 		Include/sysmodule.h \
 		Include/traceback.h \
 		Include/tupleobject.h \
+		Include/ucnhash.h \
 		Include/unicodeobject.h \
 		Include/weakrefobject.h \
-		pyconfig.h
+		pyconfig.h \
+		$(PARSER_HEADERS)
 
 $(LIBRARY_OBJS) $(MODOBJS) Modules/python.o: $(PYTHON_HEADERS)
 
@@ -596,7 +637,7 @@
 
 TESTOPTS=	-l $(EXTRATESTOPTS)
 TESTPROG=	$(srcdir)/Lib/test/regrtest.py
-TESTPYTHON=	$(RUNSHARED) ./$(BUILDPYTHON) -E -tt
+TESTPYTHON=	$(RUNSHARED) ./$(BUILDPYTHON) -E -tt -bb
 test:		all platform
 		-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
 		-$(TESTPYTHON) $(TESTPROG) $(TESTOPTS)
@@ -604,6 +645,8 @@
 
 testall:	all platform
 		-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
+		$(TESTPYTHON) $(srcdir)/Lib/compileall.py
+		-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
 		-$(TESTPYTHON) $(TESTPROG) $(TESTOPTS) -uall
 		$(TESTPYTHON) $(TESTPROG) $(TESTOPTS) -uall
 
@@ -741,11 +784,12 @@
 		email email/mime email/test email/test/data \
 		sqlite3 sqlite3/test \
 		logging bsddb bsddb/test csv wsgiref \
+		lib2to3 lib2to3/fixes lib2to3/pgen2 \
 		ctypes ctypes/test ctypes/macholib idlelib idlelib/Icons \
 		distutils distutils/command distutils/tests $(XMLLIBSUBDIRS) \
 		setuptools setuptools/command setuptools/tests setuptools.egg-info \
 		curses $(MACHDEPS)
-libinstall:	$(BUILDPYTHON) $(srcdir)/Lib/$(PLATDIR)
+libinstall:	build_all $(srcdir)/Lib/$(PLATDIR)
 	@for i in $(SCRIPTDIR) $(LIBDEST); \
 	do \
 		if test ! -d $(DESTDIR)$$i; then \
@@ -817,6 +861,8 @@
 		./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
 		-d $(LIBDEST)/site-packages -f \
 		-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
+	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+		./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram"
 
 # Create the PLATDIR source directory, if one wasn't distributed..
 $(srcdir)/Lib/$(PLATDIR):
@@ -999,7 +1045,7 @@
 
 # Run reindent on the library
 reindent:
-	./python$(EXEEXT) $(srcdir)/Tools/scripts/reindent.py -r $(srcdir)/Lib
+	./$(BUILDPYTHON) $(srcdir)/Tools/scripts/reindent.py -r $(srcdir)/Lib
 
 # Rerun configure with the same options as it was run last time,
 # provided the config.status script exists
@@ -1108,12 +1154,16 @@
 		-o -name MANIFEST \
 		-o -print
 
+# Perform some verification checks on any modified files.
+check:
+	./$(BUILDPYTHON) $(srcdir)/Tools/scripts/patchcheck.py
+
 # Dependencies
 
 Python/thread.o: @THREADHEADERS@
 
 # Declare targets that aren't real files
-.PHONY: all sharedmods oldsharedmods test quicktest memtest
+.PHONY: all build_all sharedmods oldsharedmods test quicktest memtest
 .PHONY: install altinstall oldsharedinstall bininstall altbininstall
 .PHONY: maninstall libinstall inclinstall libainstall sharedinstall
 .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure

Modified: python/branches/py3k-importlib/Misc/ACKS
==============================================================================
--- python/branches/py3k-importlib/Misc/ACKS	(original)
+++ python/branches/py3k-importlib/Misc/ACKS	Thu Mar 27 00:48:05 2008
@@ -33,6 +33,7 @@
 Stig Bakken
 Greg Ball
 Luigi Ballabio
+Jeff Balogh
 Michael J. Barber
 Chris Barker
 Quentin Barnes
@@ -109,8 +110,6 @@
 Brett Cannon
 Mike Carlton
 Terry Carroll
-Brian Leair
-Luke Kenneth Casson Leighton
 Donn Cave
 Per Cederqvist
 Octavian Cerna
@@ -168,6 +167,7 @@
 Daniel Dittmar
 Walter Dörwald
 Jaromir Dolecek
+Ismail Donmez
 Dima Dorfman
 Cesar Douady
 Dean Draayer
@@ -180,6 +180,7 @@
 Andy Dustman
 Gary Duzan
 Eugene Dvurechenski
+Josip Dzolonga 
 Maxim Dzumanenko
 Hans Eckardt
 Grant Edwards
@@ -214,6 +215,7 @@
 Frederik Fix
 Matt Fleming
 Hernán Martínez Foffani
+Amaury Forgeot d'Arc
 Doug Fort
 John Fouhy
 Martin Franklin
@@ -224,6 +226,8 @@
 Gyro Funch
 Peter Funk
 Geoff Furnish
+Ulisses Furquim
+Achim Gaedke
 Lele Gaifax
 Santiago Gala
 Yitzchak Gale
@@ -275,6 +279,7 @@
 Jochen Hayek
 Christian Heimes
 Thomas Heller
+Malte Helmert
 Lance Finn Helsten
 Jonathan Hendry
 James Henstridge
@@ -386,6 +391,7 @@
 Ben Laurie
 Simon Law
 Chris Lawrence
+Brian Leair
 Christopher Lee
 Inyeol Lee
 John J. Lee
@@ -393,10 +399,13 @@
 Luc Lefebvre
 Kip Lehman
 Joerg Lehmann
+Luke Kenneth Casson Leighton
 Marc-Andre Lemburg
+John Lenton
 Mark Levinson
 William Lewis
 Robert van Liere
+Shawn Ligocki
 Martin Ligr
 Christopher Lindblad
 Eric Lindvall
@@ -423,6 +432,7 @@
 Grzegorz Makarewicz
 Ken Manheimer
 Vladimir Marangozov
+David Marek
 Doug Marien
 Alex Martelli
 Anthony Martin
@@ -459,6 +469,7 @@
 Sape Mullender
 Sjoerd Mullender
 Michael Muller
+John Nagle
 Takahiro Nakayama
 Travers Naran
 Fredrik Nehr
@@ -505,6 +516,7 @@
 Mark Perrego
 Trevor Perrin
 Tim Peters
+Benjamin Peterson
 Chris Petrilli
 Bjorn Pettersen
 Geoff Philbrick
@@ -518,6 +530,8 @@
 François Pinard
 Zach Pincus
 Michael Piotrowski
+Antoine Pitrou
+Michael Pomraning
 Iustin Pop
 John Popplewell
 Amrit Prem
@@ -550,6 +564,7 @@
 Andy Robinson
 Jim Robinson
 Kevin Rodgers
+Giampaolo Rodola
 Mike Romberg
 Case Roole
 Timothy Roscoe
@@ -578,12 +593,14 @@
 David Scherer
 Gregor Schmid
 Ralf Schmitt
+Michael Schneider
 Peter Schneider-Kamp
 Arvin Schnell
 Chad J. Schroeder
 Sam Schulenburg
 Stefan Schwarzer
 Dietmar Schwertberger
+Federico Schwindt
 Barry Scott
 Steven Scott
 Nick Seidenman
@@ -608,6 +625,7 @@
 J. Sipprell
 Kragen Sitaker
 Christopher Smith
+Eric V. Smith
 Gregory P. Smith
 Rafal Smotrzyk
 Dirk Soede
@@ -661,6 +679,7 @@
 Christopher Tur Lesniewski-Laas
 Stephen Turner
 Bill Tutt
+Eren Türkay
 Doobee R. Tzeck
 Lionel Ulmer
 Roger Upole
@@ -691,10 +710,13 @@
 Aaron Watters
 Henrik Weber
 Corran Webster
+Stefan Wehr
 Zack Weinberg
 Edward Welbourne
 Cliff Wells
 Rickard Westman
+Jeff Wheeler
+Christopher White
 Mats Wichmann
 Truida Wiedijk
 Felix Wiemann
@@ -714,6 +736,7 @@
 Stefan Witzel
 Klaus-Juergen Wolf
 Dan Wolfe
+David Wolever
 Richard Wolff
 Gordon Worley
 Thomas Wouters
@@ -731,3 +754,5 @@
 Mike Zarnstorff
 Siebren van der Zee
 Uwe Zessin
+Trent Nelson
+Michael Foord

Modified: python/branches/py3k-importlib/Misc/HISTORY
==============================================================================
--- python/branches/py3k-importlib/Misc/HISTORY	(original)
+++ python/branches/py3k-importlib/Misc/HISTORY	Thu Mar 27 00:48:05 2008
@@ -3,11 +3,2150 @@
 
 This file contains the release messages for previous Python releases.
 As you read on you go back to the dark ages of Python's history.
+(Note: news about 2.5c2 and later 2.5 releases is in the Misc/NEWS
+file of the release25-maint branch.)
 
 
 ======================================================================
 
 
+What's New in Python 2.5 release candidate 1?
+=============================================
+
+*Release date: 17-AUG-2006*
+
+Core and builtins
+-----------------
+
+- Unicode objects will no longer raise an exception when being
+  compared equal or unequal to a string and a UnicodeDecodeError
+  exception occurs, e.g. as result of a decoding failure.
+
+  Instead, the equal (==) and unequal (!=) comparison operators will
+  now issue a UnicodeWarning and interpret the two objects as
+  unequal. The UnicodeWarning can be filtered as desired using
+  the warning framework, e.g. silenced completely, turned into an
+  exception, logged, etc.
+
+  Note that compare operators other than equal and unequal will still
+  raise UnicodeDecodeError exceptions as they've always done.
+
+- Fix segfault when doing string formatting on subclasses of long.
+
+- Fix bug related to __len__ functions using values > 2**32 on 64-bit machines
+  with new-style classes.
+
+- Fix bug related to __len__ functions returning negative values with
+  classic classes.
+
+- Patch #1538606, Fix __index__() clipping.  There were some problems
+  discovered with the API and how integers that didn't fit into Py_ssize_t
+  were handled.  This patch attempts to provide enough alternatives
+  to effectively use __index__.
+
+- Bug #1536021: __hash__ may now return long int; the final hash
+  value is obtained by invoking hash on the long int.
+
+- Bug #1536786: buffer comparison could emit a RuntimeWarning.
+
+- Bug #1535165: fixed a segfault in input() and raw_input() when
+  sys.stdin is closed.
+
+- On Windows, the PyErr_Warn function is now exported from
+  the Python dll again.
+
+- Bug #1191458: tracing over for loops now produces a line event
+  on each iteration.  Fixing this problem required changing the .pyc
+  magic number.  This means that .pyc files generated before 2.5c1
+  will be regenerated.
+
+- Bug #1333982: string/number constants were inappropriately stored
+  in the byte code and co_consts even if they were not used, ie
+  immediately popped off the stack.
+
+- Fixed a reference-counting problem in property().
+
+
+Library
+-------
+
+- Fix a bug in the ``compiler`` package that caused invalid code to be
+  generated for generator expressions.
+
+- The distutils version has been changed to 2.5.0. The change to
+  keep it programmatically in sync with the Python version running
+  the code (introduced in 2.5b3) has been reverted. It will continue
+  to be maintained manually as static string literal.
+
+- If the Python part of a ctypes callback function returns None,
+  and this cannot be converted to the required C type, an exception is
+  printed with PyErr_WriteUnraisable.  Before this change, the C
+  callback returned arbitrary values to the calling code.
+
+- The __repr__ method of a NULL ctypes.py_object() no longer raises
+  an exception.
+
+- uuid.UUID now has a bytes_le attribute. This returns the UUID in
+  little-endian byte order for Windows. In addition, uuid.py gained some
+  workarounds for clocks with low resolution, to stop the code yielding
+  duplicate UUIDs.
+
+- Patch #1540892: site.py Quitter() class attempts to close sys.stdin
+  before raising SystemExit, allowing IDLE to honor quit() and exit().
+
+- Bug #1224621: make tabnanny recognize IndentationErrors raised by tokenize.
+
+- Patch #1536071: trace.py should now find the full module name of a
+  file correctly even on Windows.
+
+- logging's atexit hook now runs even if the rest of the module has
+  already been cleaned up.
+
+- Bug #1112549, fix DoS attack on cgi.FieldStorage.
+
+- Bug #1531405, format_exception no longer raises an exception if
+  str(exception) raised an exception.
+
+- Fix a bug in the ``compiler`` package that caused invalid code to be
+  generated for nested functions.
+
+
+Extension Modules
+-----------------
+
+- Patch #1511317: don't crash on invalid hostname (alias) info.
+
+- Patch #1535500: fix segfault in BZ2File.writelines and make sure it
+  raises the correct exceptions.
+
+- Patch # 1536908: enable building ctypes on OpenBSD/AMD64.  The
+  '-no-stack-protector' compiler flag for OpenBSD has been removed.
+
+- Patch #1532975 was applied, which fixes Bug #1533481: ctypes now
+  uses the _as_parameter_ attribute when objects are passed to foreign
+  function calls.  The ctypes version number was changed to 1.0.1.
+
+- Bug #1530559, struct.pack raises TypeError where it used to convert.
+  Passing float arguments to struct.pack when integers are expected
+  now triggers a DeprecationWarning.
+
+
+Tests
+-----
+
+- test_socketserver should now work on cygwin and not fail sporadically
+  on other platforms.
+
+- test_mailbox should now work on cygwin versions 2006-08-10 and later.
+
+- Bug #1535182: really test the xreadlines() method of bz2 objects.
+
+- test_threading now skips testing alternate thread stack sizes on
+  platforms that don't support changing thread stack size.
+
+
+Documentation
+-------------
+
+- Patch #1534922: unittest docs were corrected and enhanced.
+
+
+Build
+-----
+
+- Bug #1535502, build _hashlib on Windows, and use masm assembler
+  code in OpenSSL.
+
+- Bug #1534738, win32 debug version of _msi should be _msi_d.pyd.
+
+- Bug #1530448, ctypes build failure on Solaris 10 was fixed.
+
+
+C API
+-----
+
+- New API for Unicode rich comparisons: PyUnicode_RichCompare()
+
+- Bug #1069160.  Internal correctness changes were made to
+  ``PyThreadState_SetAsyncExc()``.  A test case was added, and
+  the documentation was changed to state that the return value
+  is always 1 (normal) or 0 (if the specified thread wasn't found).
+
+
+What's New in Python 2.5 beta 3?
+================================
+
+*Release date: 03-AUG-2006*
+
+Core and builtins
+-----------------
+
+- _PyWeakref_GetWeakrefCount() now returns a Py_ssize_t; it previously
+  returned a long (see PEP 353).
+
+- Bug #1515471: string.replace() accepts character buffers again.
+
+- Add PyErr_WarnEx() so C code can pass the stacklevel to warnings.warn().
+  This provides the proper warning for struct.pack().
+  PyErr_Warn() is now deprecated in favor of PyErr_WarnEx().
+
+- Patch #1531113: Fix augmented assignment with yield expressions.
+  Also fix a SystemError when trying to assign to yield expressions.
+
+- Bug #1529871: The speed enhancement patch #921466 broke Python's compliance
+  with PEP 302.  This was fixed by adding an ``imp.NullImporter`` type that is
+  used in ``sys.path_importer_cache`` to cache non-directory paths and avoid
+  excessive filesystem operations during imports.
+
+- Bug #1521947: When checking for overflow, ``PyOS_strtol()`` used some
+  operations on signed longs that are formally undefined by C.
+  Unfortunately, at least one compiler now cares about that, so complicated
+  the code to make that compiler happy again.
+
+- Bug #1524310: Properly report errors from FindNextFile in os.listdir.
+
+- Patch #1232023: Stop including current directory in search
+  path on Windows.
+
+- Fix some potential crashes found with failmalloc.
+
+- Fix warnings reported by Klocwork's static analysis tool.
+
+- Bug #1512814, Fix incorrect lineno's when code within a function
+  had more than 255 blank lines.
+
+- Patch #1521179: Python now accepts the standard options ``--help`` and
+  ``--version`` as well as ``/?`` on Windows.
+
+- Bug #1520864: unpacking singleton tuples in a 'for' loop (for x, in) works
+  again.  Fixing this problem required changing the .pyc magic number.
+  This means that .pyc files generated before 2.5b3 will be regenerated.
+
+- Bug #1524317:  Compiling Python ``--without-threads`` failed.
+  The Python core compiles again, and, in a build without threads, the
+  new ``sys._current_frames()`` returns a dictionary with one entry,
+  mapping the faux "thread id" 0 to the current frame.
+
+- Bug #1525447: build on MacOS X on a case-sensitive filesystem.
+
+
+Library
+-------
+
+- Fix #1693149.  Now you can pass several modules separated by
+  comma to trace.py in the same --ignore-module option.
+
+- Correction of patch #1455898: In the mbcs decoder, set final=False
+  for stream decoder, but final=True for the decode function.
+
+- os.urandom no longer masks unrelated exceptions like SystemExit or
+  KeyboardInterrupt.
+
+- Bug #1525866: Don't copy directory stat times in
+  shutil.copytree on Windows
+
+- Bug #1002398: The documentation for os.path.sameopenfile now correctly
+  refers to file descriptors, not file objects.
+
+- The renaming of the xml package to xmlcore, and the import hackery done
+  to make it appear at both names, has been removed.  Bug #1511497,
+  #1513611, and probably others.
+
+- Bug #1441397: The compiler module now recognizes module and function
+  docstrings correctly as it did in Python 2.4.
+
+- Bug #1529297:  The rewrite of doctest for Python 2.4 unintentionally
+  lost that tests are sorted by name before being run.  This rarely
+  matters for well-written tests, but can create baffling symptoms if
+  side effects from one test to the next affect outcomes.  ``DocTestFinder``
+  has been changed to sort the list of tests it returns.
+
+- The distutils version has been changed to 2.5.0, and is now kept
+  in sync with sys.version_info[:3].
+
+- Bug #978833: Really close underlying socket in _socketobject.close.
+
+- Bug #1459963: urllib and urllib2 now normalize HTTP header names with
+  title().
+
+- Patch #1525766: In pkgutil.walk_packages, correctly pass the onerror callback
+  to recursive calls and call it with the failing package name.
+
+- Bug #1525817: Don't truncate short lines in IDLE's tool tips.
+
+- Patch #1515343: Fix printing of deprecated string exceptions with a
+  value in the traceback module.
+
+- Resync optparse with Optik 1.5.3: minor tweaks for/to tests.
+
+- Patch #1524429: Use repr() instead of backticks in Tkinter again.
+
+- Bug #1520914: Change time.strftime() to accept a zero for any position in its
+  argument tuple.  For arguments where zero is illegal, the value is forced to
+  the minimum value that is correct.  This is to support an undocumented but
+  common way people used  to fill in inconsequential information in the time
+  tuple pre-2.4.
+
+- Patch #1220874: Update the binhex module for Mach-O.
+
+- The email package has improved RFC 2231 support, specifically for
+  recognizing the difference between encoded (name*0*=<blah>) and non-encoded
+  (name*0=<blah>) parameter continuations.  This may change the types of
+  values returned from email.message.Message.get_param() and friends.
+  Specifically in some cases where non-encoded continuations were used,
+  get_param() used to return a 3-tuple of (None, None, string) whereas now it
+  will just return the string (since non-encoded continuations don't have
+  charset and language parts).
+
+  Also, whereas % values were decoded in all parameter continuations, they are
+  now only decoded in encoded parameter parts.
+
+- Bug #1517990: IDLE keybindings on MacOS X now work correctly
+
+- Bug #1517996: IDLE now longer shows the default Tk menu when a
+  path browser, class browser or debugger is the frontmost window on MacOS X
+
+- Patch #1520294: Support for getset and member descriptors in types.py,
+  inspect.py, and pydoc.py.  Specifically, this allows for querying the type
+  of an object against these built-in types and more importantly, for getting
+  their docstrings printed in the interactive interpreter's help() function.
+
+
+Extension Modules
+-----------------
+
+- Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
+  a socket operation on a socket with a timeout, the exception will be
+  caught correctly.  Previously, the exception was not caught.
+
+- Patch #1529514: The _ctypes extension is now compiled on more
+  openbsd target platforms.
+
+- The ``__reduce__()`` method of the new ``collections.defaultdict`` had
+  a memory leak, affecting pickles and deep copies.
+
+- Bug #1471938: Fix curses module build problem on Solaris 8; patch by
+  Paul Eggert.
+
+- Patch #1448199: Release interpreter lock in _winreg.ConnectRegistry.
+
+- Patch #1521817: Index range checking on ctypes arrays containing
+  exactly one element enabled again.  This allows iterating over these
+  arrays, without the need to check the array size before.
+
+- Bug #1521375: When the code in ctypes.util.find_library was
+  run with root privileges, it could overwrite or delete
+  /dev/null in certain cases; this is now fixed.
+
+- Bug #1467450: On Mac OS X 10.3, RTLD_GLOBAL is now used as the
+  default mode for loading shared libraries in ctypes.
+
+- Because of a misspelled preprocessor symbol, ctypes was always
+  compiled without thread support; this is now fixed.
+
+- pybsddb Bug #1527939: bsddb module DBEnv dbremove and dbrename
+  methods now allow their database parameter to be None as the
+  sleepycat API allows.
+
+- Bug #1526460: Fix socketmodule compile on NetBSD as it has a different
+  bluetooth API compared with Linux and FreeBSD.
+
+Tests
+-----
+
+- Bug #1501330: Change test_ossaudiodev to be much more tolerant in terms of
+  how long the test file should take to play.  Now accepts taking 2.93 secs
+  (exact time) +/- 10% instead of the hard-coded 3.1 sec.
+
+- Patch #1529686: The standard tests ``test_defaultdict``, ``test_iterlen``,
+  ``test_uuid`` and ``test_email_codecs`` didn't actually run any tests when
+  run via ``regrtest.py``. Now they do.
+
+Build
+-----
+
+- Bug #1439538: Drop usage of test -e in configure as it is not portable.
+
+Mac
+---
+
+- PythonLauncher now works correctly when the path to the script contains
+  characters that are treated specially by the shell (such as quotes).
+
+- Bug #1527397: PythonLauncher now launches scripts with the working directory
+  set to the directory that contains the script instead of the user home
+  directory. That latter was an implementation accident and not what users
+  expect.
+
+
+What's New in Python 2.5 beta 2?
+================================
+
+*Release date: 11-JUL-2006*
+
+Core and builtins
+-----------------
+
+- Bug #1441486: The literal representation of -(sys.maxint - 1)
+  again evaluates to a int object, not a long.
+
+- Bug #1501934: The scope of global variables that are locally assigned
+  using augmented assignment is now correctly determined.
+
+- Bug #927248: Recursive method-wrapper objects can now safely
+  be released.
+
+- Bug #1417699: Reject locale-specific decimal point in float()
+  and atof().
+
+- Bug #1511381: codec_getstreamcodec() in codec.c is corrected to
+  omit a default "error" argument for NULL pointer.  This allows
+  the parser to take a codec from cjkcodecs again.
+
+- Bug #1519018: 'as' is now validated properly in import statements.
+
+- On 64 bit systems, int literals that use less than 64 bits are
+  now ints rather than longs.
+
+- Bug #1512814, Fix incorrect lineno's when code at module scope
+  started after line 256.
+
+- New function ``sys._current_frames()`` returns a dict mapping thread
+  id to topmost thread stack frame.  This is for expert use, and is
+  especially useful for debugging application deadlocks.  The functionality
+  was previously available in Fazal Majid's ``threadframe`` extension
+  module, but it wasn't possible to do this in a wholly threadsafe way from
+  an extension.
+
+Library
+-------
+
+- Bug #1257728: Mention Cygwin in distutils error message about a missing
+  VS 2003.
+
+- Patch #1519566: Update turtle demo, make begin_fill idempotent.
+
+- Bug #1508010: msvccompiler now requires the DISTUTILS_USE_SDK
+  environment variable to be set in order to the SDK environment
+  for finding the compiler, include files, etc.
+
+- Bug #1515998: Properly generate logical ids for files in bdist_msi.
+
+- warnings.py now ignores ImportWarning by default
+
+- string.Template() now correctly handles tuple-values. Previously,
+  multi-value tuples would raise an exception and single-value tuples would
+  be treated as the value they contain, instead.
+
+- Bug #822974: Honor timeout in telnetlib.{expect,read_until}
+  even if some data are received.
+
+- Bug #1267547: Put proper recursive setup.py call into the
+  spec file generated by bdist_rpm.
+
+- Bug #1514693: Update turtle's heading when switching between
+  degrees and radians.
+
+- Reimplement turtle.circle using a polyline, to allow correct
+  filling of arcs.
+
+- Bug #1514703: Only setup canvas window in turtle when the canvas
+  is created.
+
+- Bug #1513223: .close() of a _socketobj now releases the underlying
+  socket again, which then gets closed as it becomes unreferenced.
+
+- Bug #1504333: Make sgmllib support angle brackets in quoted
+  attribute values.
+
+- Bug #853506: Fix IPv6 address parsing in unquoted attributes in
+  sgmllib ('[' and ']' were not accepted).
+
+- Fix a bug in the turtle module's end_fill function.
+
+- Bug #1510580: The 'warnings' module improperly required that a Warning
+  category be either a types.ClassType and a subclass of Warning.  The proper
+  check is just that it is a subclass with Warning as the documentation states.
+
+- The compiler module now correctly compiles the new try-except-finally
+  statement (bug #1509132).
+
+- The wsgiref package is now installed properly on Unix.
+
+- A bug was fixed in logging.config.fileConfig() which caused a crash on
+  shutdown when fileConfig() was called multiple times.
+
+- The sqlite3 module did cut off data from the SQLite database at the first
+  null character before sending it to a custom converter. This has been fixed
+  now.
+
+Extension Modules
+-----------------
+
+- #1494314: Fix a regression with high-numbered sockets in 2.4.3. This
+  means that select() on sockets > FD_SETSIZE (typically 1024) work again.
+  The patch makes sockets use poll() internally where available.
+
+- Assigning None to pointer type fields in ctypes structures possible
+  overwrote the wrong fields, this is fixed now.
+
+- Fixed a segfault in _ctypes when ctypes.wintypes were imported
+  on non-Windows platforms.
+
+- Bug #1518190: The ctypes.c_void_p constructor now accepts any
+  integer or long, without range checking.
+
+- Patch #1517790: It is now possible to use custom objects in the ctypes
+  foreign function argtypes sequence as long as they provide a from_param
+  method, no longer is it required that the object is a ctypes type.
+
+- The '_ctypes' extension module now works when Python is configured
+  with the --without-threads option.
+
+- Bug #1513646: os.access on Windows now correctly determines write
+  access, again.
+
+- Bug #1512695: cPickle.loads could crash if it was interrupted with
+  a KeyboardInterrupt.
+
+- Bug #1296433: parsing XML with a non-default encoding and
+  a CharacterDataHandler could crash the interpreter in pyexpat.
+
+- Patch #1516912: improve Modules support for OpenVMS.
+
+Build
+-----
+
+- Automate Windows build process for the Win64 SSL module.
+
+- 'configure' now detects the zlib library the same way as distutils.
+  Previously, the slight difference could cause compilation errors of the
+  'zlib' module on systems with more than one version of zlib.
+
+- The MSI compileall step was fixed to also support a TARGETDIR
+  with spaces in it.
+
+- Bug #1517388: sqlite3.dll is now installed on Windows independent
+  of Tcl/Tk.
+
+- Bug #1513032: 'make install' failed on FreeBSD 5.3 due to lib-old
+  trying to be installed even though it's empty.
+
+Tests
+-----
+
+- Call os.waitpid() at the end of tests that spawn child processes in order
+  to minimize resources (zombies).
+
+Documentation
+-------------
+
+- Cover ImportWarning, PendingDeprecationWarning and simplefilter() in the
+  documentation for the warnings module.
+
+- Patch #1509163: MS Toolkit Compiler no longer available.
+
+- Patch #1504046: Add documentation for xml.etree.
+
+
+What's New in Python 2.5 beta 1?
+================================
+
+*Release date: 20-JUN-2006*
+
+Core and builtins
+-----------------
+
+- Patch #1507676: Error messages returned by invalid abstract object operations
+  (such as iterating over an integer) have been improved and now include the
+  type of the offending object to help with debugging.
+
+- Bug #992017: A classic class that defined a __coerce__() method that returned
+  its arguments swapped would infinitely recurse and segfault the interpreter.
+
+- Fix the socket tests so they can be run concurrently.
+
+- Removed 5 integers from C frame objects (PyFrameObject).
+  f_nlocals, f_ncells, f_nfreevars, f_stack_size, f_restricted.
+
+- Bug #532646: object.__call__() will continue looking for the __call__
+  attribute on objects until one without one is found.  This leads to recursion
+  when you take a class and set its __call__ attribute to an instance of the
+  class.  Originally fixed for classic classes, but this fix is for new-style.
+  Removes the infinite_rec_3 crasher.
+
+- The string and unicode methods startswith() and endswith() now accept
+  a tuple of prefixes/suffixes to look for. Implements RFE #1491485.
+
+- Buffer objects, at the C level, never used the char buffer
+  implementation even when the char buffer for the wrapped object was
+  explicitly requested (originally returned the read or write buffer).
+  Now a TypeError is raised if the char buffer is not present but is
+  requested.
+
+- Patch #1346214: Statements like "if 0: suite" are now again optimized
+  away like they were in Python 2.4.
+
+- Builtin exceptions are now full-blown new-style classes instead of
+  instances pretending to be classes, which speeds up exception handling
+  by about 80% in comparison to 2.5a2.
+
+- Patch #1494554: Update unicodedata.numeric and unicode.isnumeric to
+  Unicode 4.1.
+
+- Patch #921466: sys.path_importer_cache is now used to cache valid and
+  invalid file paths for the built-in import machinery which leads to
+  fewer open calls on startup.
+
+- Patch #1442927: ``long(str, base)`` is now up to 6x faster for non-power-
+  of-2 bases.  The largest speedup is for inputs with about 1000 decimal
+  digits.  Conversion from non-power-of-2 bases remains quadratic-time in
+  the number of input digits (it was and remains linear-time for bases
+  2, 4, 8, 16 and 32).
+
+- Bug #1334662: ``int(string, base)`` could deliver a wrong answer
+  when ``base`` was not 2, 4, 8, 10, 16 or 32, and ``string`` represented
+  an integer close to ``sys.maxint``.  This was repaired by patch
+  #1335972, which also gives a nice speedup.
+
+- Patch #1337051: reduced size of frame objects.
+
+- PyErr_NewException now accepts a tuple of base classes as its
+  "base" parameter.
+
+- Patch #876206: function call speedup by retaining allocated frame
+  objects.
+
+- Bug #1462152: file() now checks more thoroughly for invalid mode
+  strings and removes a possible "U" before passing the mode to the
+  C library function.
+
+- Patch #1488312, Fix memory alignment problem on SPARC in unicode
+
+- Bug #1487966: Fix SystemError with conditional expression in assignment
+
+- WindowsError now has two error code attributes: errno, which carries
+  the error values from errno.h, and winerror, which carries the error
+  values from winerror.h. Previous versions put the winerror.h values
+  (from GetLastError()) into the errno attribute.
+
+- Patch #1475845: Raise IndentationError for unexpected indent.
+
+- Patch #1479181: split open() and file() from being aliases for each other.
+
+- Patch #1497053 & bug #1275608: Exceptions occurring in ``__eq__()``
+  methods were always silently ignored by dictionaries when comparing keys.
+  They are now passed through (except when using the C API function
+  ``PyDict_GetItem()``, whose semantics did not change).
+
+- Bug #1456209: In some obscure cases it was possible for a class with a
+  custom ``__eq__()`` method to confuse dict internals when class instances
+  were used as a dict's keys and the ``__eq__()`` method mutated the dict.
+  No, you don't have any code that did this ;-)
+
+Extension Modules
+-----------------
+
+- Bug #1295808: expat symbols should be namespaced in pyexpat
+
+- Patch #1462338: Upgrade pyexpat to expat 2.0.0
+
+- Change binascii.hexlify to accept a read-only buffer instead of only a char
+  buffer and actually follow its documentation.
+
+- Fixed a potentially invalid memory access of CJKCodecs' shift-jis decoder.
+
+- Patch #1478788 (modified version): The functional extension module has
+  been renamed to _functools and a functools Python wrapper module added.
+  This provides a home for additional function related utilities that are
+  not specifically about functional programming. See PEP 309.
+
+- Patch #1493701: performance enhancements for struct module.
+
+- Patch #1490224: time.altzone is now set correctly on Cygwin.
+
+- Patch #1435422: zlib's compress and decompress objects now have a
+  copy() method.
+
+- Patch #1454481: thread stack size is now tunable at runtime for thread
+  enabled builds on Windows and systems with Posix threads support.
+
+- On Win32, os.listdir now supports arbitrarily-long Unicode path names
+  (up to the system limit of 32K characters).
+
+- Use Win32 API to implement os.{access,chdir,chmod,mkdir,remove,rename,rmdir,utime}.
+  As a result, these functions now raise WindowsError instead of OSError.
+
+- ``time.clock()`` on Win64 should use the high-performance Windows
+  ``QueryPerformanceCounter()`` now (as was already the case on 32-bit
+  Windows platforms).
+
+- Calling Tk_Init twice is refused if the first call failed as that
+  may deadlock.
+
+- bsddb: added the DB_ARCH_REMOVE flag and fixed db.DBEnv.log_archive() to
+  accept it without potentially using an uninitialized pointer.
+
+- bsddb: added support for the DBEnv.log_stat() and DBEnv.lsn_reset() methods
+  assuming BerkeleyDB >= 4.0 and 4.4 respectively.  [pybsddb project SF
+  patch numbers 1494885 and 1494902]
+
+- bsddb: added an interface for the BerkeleyDB >= 4.3 DBSequence class.
+  [pybsddb project SF patch number 1466734]
+
+- bsddb: fix DBCursor.pget() bug with keyword argument names when no data
+  parameter is supplied.  [SF pybsddb bug #1477863]
+
+- bsddb: the __len__ method of a DB object has been fixed to return correct
+  results.  It could previously incorrectly return 0 in some cases.
+  Fixes SF bug 1493322 (pybsddb bug 1184012).
+
+- bsddb: the bsddb.dbtables Modify method now raises the proper error and
+  aborts the db transaction safely when a modifier callback fails.
+  Fixes SF python patch/bug #1408584.
+
+- bsddb: multithreaded DB access using the simple bsddb module interface
+  now works reliably.  It has been updated to use automatic BerkeleyDB
+  deadlock detection and the bsddb.dbutils.DeadlockWrap wrapper to retry
+  database calls that would previously deadlock. [SF python bug #775414]
+
+- Patch #1446489: add support for the ZIP64 extensions to zipfile.
+
+- Patch #1506645: add Python wrappers for the curses functions
+  is_term_resized, resize_term and resizeterm.
+
+Library
+-------
+
+- Patch #815924: Restore ability to pass type= and icon= in tkMessageBox
+  functions.
+
+- Patch #812986: Update turtle output even if not tracing.
+
+- Patch #1494750: Destroy master after deleting children in
+  Tkinter.BaseWidget.
+
+- Patch #1096231: Add ``default`` argument to Tkinter.Wm.wm_iconbitmap.
+
+- Patch #763580: Add name and value arguments to Tkinter variable
+  classes.
+
+- Bug #1117556: SimpleHTTPServer now tries to find and use the system's
+  mime.types file for determining MIME types.
+
+- Bug #1339007: Shelf objects now don't raise an exception in their
+  __del__ method when initialization failed.
+
+- Patch #1455898: The MBCS codec now supports the incremental mode for
+  double-byte encodings.
+
+- ``difflib``'s ``SequenceMatcher.get_matching_blocks()`` was changed to
+  guarantee that adjacent triples in the return list always describe
+  non-adjacent blocks.  Previously, a pair of matching blocks could end
+  up being described by multiple adjacent triples that formed a partition
+  of the matching pair.
+
+- Bug #1498146: fix optparse to handle Unicode strings in option help,
+  description, and epilog.
+
+- Bug #1366250: minor optparse documentation error.
+
+- Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately;
+  clarify docs.
+
+- The wsgiref package has been added to the standard library.
+
+- The functions update_wrapper() and wraps() have been added to the functools
+  module. These make it easier to copy relevant metadata from the original
+  function when writing wrapper functions.
+
+- The optional ``isprivate`` argument to ``doctest.testmod()``, and the
+  ``doctest.is_private()`` function, both deprecated in 2.4, were removed.
+
+- Patch #1359618: Speed up charmap encoder by using a trie structure
+  for lookup.
+
+- The functions in the ``pprint`` module now sort dictionaries by key
+  before computing the display.  Before 2.5, ``pprint`` sorted a dictionary
+  if and only if its display required more than one line, although that
+  wasn't documented.  The new behavior increases predictability; e.g.,
+  using ``pprint.pprint(a_dict)`` in a doctest is now reliable.
+
+- Patch #1497027: try HTTP digest auth before basic auth in urllib2
+  (thanks for J. J. Lee).
+
+- Patch #1496206: improve urllib2 handling of passwords with respect to
+  default HTTP and HTTPS ports.
+
+- Patch #1080727: add "encoding" parameter to doctest.DocFileSuite.
+
+- Patch #1281707: speed up gzip.readline.
+
+- Patch #1180296: Two new functions were added to the locale module:
+  format_string() to get the effect of  "format % items" but locale-aware,
+  and currency() to format a monetary number with currency sign.
+
+- Patch #1486962: Several bugs in the turtle Tk demo module were fixed
+  and several features added, such as speed and geometry control.
+
+- Patch #1488881: add support for external file objects in bz2 compressed
+  tarfiles.
+
+- Patch #721464: pdb.Pdb instances can now be given explicit stdin and
+  stdout arguments, making it possible to redirect input and output
+  for remote debugging.
+
+- Patch #1484695: Update the tarfile module to version 0.8. This fixes
+  a couple of issues, notably handling of long file names using the
+  GNU LONGNAME extension.
+
+- Patch #1478292. ``doctest.register_optionflag(name)`` shouldn't create a
+  new flag when ``name`` is already the name of an option flag.
+
+- Bug #1385040: don't allow "def foo(a=1, b): pass" in the compiler
+  package.
+
+- Patch #1472854: make the rlcompleter.Completer class usable on non-
+  UNIX platforms.
+
+- Patch #1470846: fix urllib2 ProxyBasicAuthHandler.
+
+- Bug #1472827: correctly escape newlines and tabs in attribute values in
+  the saxutils.XMLGenerator class.
+
+
+Build
+-----
+
+- Bug #1502728: Correctly link against librt library on HP-UX.
+
+- OpenBSD 3.9 is supported now.
+
+- Patch #1492356: Port to Windows CE.
+
+- Bug/Patch #1481770: Use .so extension for shared libraries on HP-UX for ia64.
+
+- Patch #1471883: Add --enable-universalsdk.
+
+C API
+-----
+
+Tests
+-----
+
+Tools
+-----
+
+Documentation
+-------------
+
+
+
+What's New in Python 2.5 alpha 2?
+=================================
+
+*Release date: 27-APR-2006*
+
+Core and builtins
+-----------------
+
+- Bug #1465834: 'bdist_wininst preinstall script support' was fixed
+  by converting these apis from macros into exported functions again:
+
+    PyParser_SimpleParseFile PyParser_SimpleParseString PyRun_AnyFile
+    PyRun_AnyFileEx PyRun_AnyFileFlags PyRun_File PyRun_FileEx
+    PyRun_FileFlags PyRun_InteractiveLoop PyRun_InteractiveOne
+    PyRun_SimpleFile PyRun_SimpleFileEx PyRun_SimpleString
+    PyRun_String Py_CompileString
+
+- Under COUNT_ALLOCS, types are not necessarily immortal anymore.
+
+- All uses of PyStructSequence_InitType have been changed to initialize
+  the type objects only once, even if the interpreter is initialized
+  multiple times.
+
+- Bug #1454485, array.array('u') could crash the interpreter.  This was
+  due to PyArgs_ParseTuple(args, 'u#', ...) trying to convert buffers (strings)
+  to unicode when it didn't make sense.  'u#' now requires a unicode string.
+
+- Py_UNICODE is unsigned.  It was always documented as unsigned, but
+  due to a bug had a signed value in previous versions.
+
+- Patch #837242: ``id()`` of any Python object always gives a positive
+  number now, which might be a long integer. ``PyLong_FromVoidPtr`` and
+  ``PyLong_AsVoidPtr`` have been changed accordingly.  Note that it has
+  never been correct to implement a ``__hash()__`` method that returns the
+  ``id()`` of an object:
+
+      def __hash__(self):
+          return id(self)  # WRONG
+
+  because a hash result must be a (short) Python int but it was always
+  possible for ``id()`` to return a Python long.  However, because ``id()``
+  could return negative values before, on a 32-bit box an ``id()`` result
+  was always usable as a hash value before this patch.  That's no longer
+  necessarily so.
+
+- Python on OS X 10.3 and above now uses dlopen() (via dynload_shlib.c)
+  to load extension modules and now provides the dl module. As a result,
+  sys.setdlopenflags() now works correctly on these systems. (SF patch
+  #1454844)
+
+- Patch #1463867: enhanced garbage collection to allow cleanup of cycles
+  involving generators that have paused outside of any ``try`` or ``with``
+  blocks.  (In 2.5a1, a paused generator that was part of a reference
+  cycle could not be garbage collected, regardless of whether it was
+  paused in a ``try`` or ``with`` block.)
+
+Extension Modules
+-----------------
+
+- Patch #1191065: Fix preprocessor problems on systems where recvfrom
+  is a macro.
+
+- Bug #1467952: os.listdir() now correctly raises an error if readdir()
+  fails with an error condition.
+
+- Fixed bsddb.db.DBError derived exceptions so they can be unpickled.
+
+- Bug #1117761: bsddb.*open() no longer raises an exception when using
+  the cachesize parameter.
+
+- Bug #1149413: bsddb.*open() no longer raises an exception when using
+  a temporary db (file=None) with the 'n' flag to truncate on open.
+
+- Bug #1332852: bsddb module minimum BerkeleyDB version raised to 3.3
+  as older versions cause excessive test failures.
+
+- Patch #1062014: AF_UNIX sockets under Linux have a special
+  abstract namespace that is now fully supported.
+
+Library
+-------
+
+- Bug #1223937: subprocess.CalledProcessError reports the exit status
+  of the process using the returncode attribute, instead of
+  abusing errno.
+
+- Patch #1475231: ``doctest`` has a new ``SKIP`` option, which causes
+  a doctest to be skipped (the code is not run, and the expected output
+  or exception is ignored).
+
+- Fixed contextlib.nested to cope with exceptions being raised and
+  caught inside exit handlers.
+
+- Updated optparse module to Optik 1.5.1 (allow numeric constants in
+  hex, octal, or binary; add ``append_const`` action; keep going if
+  gettext cannot be imported; added ``OptionParser.destroy()`` method;
+  added ``epilog`` for better help generation).
+
+- Bug #1473760: ``tempfile.TemporaryFile()`` could hang on Windows, when
+  called from a thread spawned as a side effect of importing a module.
+
+- The pydoc module now supports documenting packages contained in
+  .zip or .egg files.
+
+- The pkgutil module now has several new utility functions, such
+  as ``walk_packages()`` to support working with packages that are either
+  in the filesystem or zip files.
+
+- The mailbox module can now modify and delete messages from
+  mailboxes, in addition to simply reading them.  Thanks to Gregory
+  K. Johnson for writing the code, and to the 2005 Google Summer of
+  Code for funding his work.
+
+- The ``__del__`` method of class ``local`` in module ``_threading_local``
+  returned before accomplishing any of its intended cleanup.
+
+- Patch #790710: Add breakpoint command lists in pdb.
+
+- Patch #1063914: Add Tkinter.Misc.clipboard_get().
+
+- Patch #1191700: Adjust column alignment in bdb breakpoint lists.
+
+- SimpleXMLRPCServer relied on the fcntl module, which is unavailable on
+  Windows. Bug #1469163.
+
+- The warnings, linecache, inspect, traceback, site, and doctest modules
+  were updated to work correctly with modules imported from zipfiles or
+  via other PEP 302 __loader__ objects.
+
+- Patch #1467770: Reduce usage of subprocess._active to processes which
+  the application hasn't waited on.
+
+- Patch #1462222: Fix Tix.Grid.
+
+- Fix exception when doing glob.glob('anything*/')
+
+- The pstats.Stats class accepts an optional stream keyword argument to
+  direct output to an alternate file-like object.
+
+Build
+-----
+
+- The Makefile now has a reindent target, which runs reindent.py on
+  the library.
+
+- Patch #1470875: Building Python with MS Free Compiler
+
+- Patch #1161914: Add a python-config script.
+
+- Patch #1324762:Remove ccpython.cc; replace --with-cxx with
+  --with-cxx-main. Link with C++ compiler only if --with-cxx-main was
+  specified. (Can be overridden by explicitly setting LINKCC.) Decouple
+  CXX from --with-cxx-main, see description in README.
+
+- Patch #1429775: Link extension modules with the shared libpython.
+
+- Fixed a libffi build problem on MIPS systems.
+
+- ``PyString_FromFormat``, ``PyErr_Format``, and ``PyString_FromFormatV``
+  now accept formats "%u" for unsigned ints, "%lu" for unsigned longs,
+  and "%zu" for unsigned integers of type ``size_t``.
+
+Tests
+-----
+
+- test_contextlib now checks contextlib.nested can cope with exceptions
+  being raised and caught inside exit handlers.
+
+- test_cmd_line now checks operation of the -m and -c command switches
+
+- The test_contextlib test in 2.5a1 wasn't actually run unless you ran
+  it separately and by hand.  It also wasn't cleaning up its changes to
+  the current Decimal context.
+
+- regrtest.py now has a -M option to run tests that test the new limits of
+  containers, on 64-bit architectures. Running these tests is only sensible
+  on 64-bit machines with more than two gigabytes of memory. The argument
+  passed is the maximum amount of memory for the tests to use.
+
+Tools
+-----
+
+- Added the Python benchmark suite pybench to the Tools/ directory;
+  contributed by Marc-Andre Lemburg.
+
+Documentation
+-------------
+
+- Patch #1473132: Improve docs for ``tp_clear`` and ``tp_traverse``.
+
+- PEP 343: Added Context Types section to the library reference
+  and attempted to bring other PEP 343 related documentation into
+  line with the implementation and/or python-dev discussions.
+
+- Bug #1337990: clarified that ``doctest`` does not support examples
+  requiring both expected output and an exception.
+
+
+What's New in Python 2.5 alpha 1?
+=================================
+
+*Release date: 05-APR-2006*
+
+Core and builtins
+-----------------
+
+- PEP 338: -m command line switch now delegates to runpy.run_module
+  allowing it to support modules in packages and zipfiles
+
+- On Windows, .DLL is not an accepted file name extension for
+  extension modules anymore; extensions are only found if they
+  end in .PYD.
+
+- Bug #1421664: sys.stderr.encoding is now set to the same value as
+  sys.stdout.encoding.
+
+- __import__ accepts keyword arguments.
+
+- Patch #1460496: round() now accepts keyword arguments.
+
+- Fixed bug #1459029 - unicode reprs were double-escaped.
+
+- Patch #1396919: The system scope threads are reenabled on FreeBSD
+  5.4 and later versions.
+
+- Bug #1115379: Compiling a Unicode string with an encoding declaration
+  now gives a SyntaxError.
+
+- Previously, Python code had no easy way to access the contents of a
+  cell object. Now, a ``cell_contents`` attribute has been added
+  (closes patch #1170323).
+
+- Patch #1123430: Python's small-object allocator now returns an arena to
+  the system ``free()`` when all memory within an arena becomes unused
+  again.  Prior to Python 2.5, arenas (256KB chunks of memory) were never
+  freed.  Some applications will see a drop in virtual memory size now,
+  especially long-running applications that, from time to time, temporarily
+  use a large number of small objects.  Note that when Python returns an
+  arena to the platform C's ``free()``, there's no guarantee that the
+  platform C library will in turn return that memory to the operating system.
+  The effect of the patch is to stop making that impossible, and in tests it
+  appears to be effective at least on Microsoft C and gcc-based systems.
+  Thanks to Evan Jones for hard work and patience.
+
+- Patch #1434038: property() now uses the getter's docstring if there is
+  no "doc" argument given. This makes it possible to legitimately use
+  property() as a decorator to produce a read-only property.
+
+- PEP 357, patch 1436368: add an __index__ method to int/long and a matching
+  nb_index slot to the PyNumberMethods struct.  The slot is consulted instead
+  of requiring an int or long in slicing and a few other contexts, enabling
+  other objects (e.g. Numeric Python's integers) to be used as slice indices.
+
+- Fixed various bugs reported by Coverity's Prevent tool.
+
+- PEP 352, patch #1104669: Make exceptions new-style objects.  Introduced the
+  new exception base class, BaseException, which has a new message attribute.
+  KeyboardInterrupt and SystemExit to directly inherit from BaseException now.
+  Raising a string exception now raises a DeprecationWarning.
+
+- Patch #1438387, PEP 328: relative and absolute imports. Imports can now be
+  explicitly relative, using 'from .module import name' to mean 'from the same
+  package as this module is in. Imports without dots still default to the
+  old relative-then-absolute, unless 'from __future__ import
+  absolute_import' is used.
+
+- Properly check if 'warnings' raises an exception (usually when a filter set
+  to "error" is triggered) when raising a warning for raising string
+  exceptions.
+
+- CO_GENERATOR_ALLOWED is no longer defined. This behavior is the default.
+  The name was removed from Include/code.h.
+
+- PEP 308: conditional expressions were added: (x if cond else y).
+
+- Patch 1433928:
+  - The copy module now "copies" function objects (as atomic objects).
+  - dict.__getitem__ now looks for a __missing__ hook before raising
+    KeyError.
+
+- PEP 343: with statement implemented. Needs ``from __future__ import
+  with_statement``. Use of 'with' as a variable will generate a warning.
+  Use of 'as' as a variable will also generate a warning (unless it's
+  part of an import statement).
+  The following objects have __context__ methods:
+  - The built-in file type.
+  - The thread.LockType type.
+  - The following types defined by the threading module:
+    Lock, RLock, Condition, Semaphore, BoundedSemaphore.
+  - The decimal.Context class.
+
+- Fix the encodings package codec search function to only search
+  inside its own package. Fixes problem reported in patch #1433198.
+
+  Note: Codec packages should implement and register their own
+  codec search function. PEP 100 has the details.
+
+- PEP 353: Using ``Py_ssize_t`` as the index type.
+
+- ``PYMALLOC_DEBUG`` builds now add ``4*sizeof(size_t)`` bytes of debugging
+  info to each allocated block, since the ``Py_ssize_t`` changes (PEP 353)
+  now allow Python to make use of memory blocks exceeding 2**32 bytes for
+  some purposes on 64-bit boxes.  A ``PYMALLOC_DEBUG`` build was limited
+  to 4-byte allocations before.
+
+- Patch #1400181, fix unicode string formatting to not use the locale.
+  This is how string objects work.  u'%f' could use , instead of .
+  for the decimal point.  Now both strings and unicode always use periods.
+
+- Bug #1244610, #1392915, fix build problem on OpenBSD 3.7 and 3.8.
+  configure would break checking curses.h.
+
+- Bug #959576: The pwd module is now builtin. This allows Python to be
+  built on UNIX platforms without $HOME set.
+
+- Bug #1072182, fix some potential problems if characters are signed.
+
+- Bug #889500, fix line number on SyntaxWarning for global declarations.
+
+- Bug #1378022, UTF-8 files with a leading BOM crashed the interpreter.
+
+- Support for converting hex strings to floats no longer works.
+  This was not portable.  float('0x3') now raises a ValueError.
+
+- Patch #1382163: Expose Subversion revision number to Python.  New C API
+  function Py_GetBuildNumber().  New attribute sys.subversion.  Build number
+  is now displayed in interactive prompt banner.
+
+- Implementation of PEP 341 - Unification of try/except and try/finally.
+  "except" clauses can now be written together with a "finally" clause in
+  one try statement instead of two nested ones.  Patch #1355913.
+
+- Bug #1379994: Builtin unicode_escape and raw_unicode_escape codec
+  now encodes backslash correctly.
+
+- Patch #1350409: Work around signal handling bug in Visual Studio 2005.
+
+- Bug #1281408: Py_BuildValue now works correctly even with unsigned longs
+  and long longs.
+
+- SF Bug #1350188, "setdlopenflags" leads to crash upon "import"
+  It was possible for dlerror() to return a NULL pointer, so
+  it will now use a default error message in this case.
+
+- Replaced most Unicode charmap codecs with new ones using the
+  new Unicode translate string feature in the builtin charmap
+  codec; the codecs were created from the mapping tables available
+  at ftp.unicode.org and contain a few updates (e.g. the Mac OS
+  encodings now include a mapping for the Apple logo)
+
+- Added a few more codecs for Mac OS encodings
+
+- Sped up some Unicode operations.
+
+- A new AST parser implementation was completed. The abstract
+  syntax tree is available for read-only (non-compile) access
+  to Python code; an _ast module was added.
+
+- SF bug #1167751: fix incorrect code being produced for generator expressions.
+  The following code now raises a SyntaxError:  foo(a = i for i in range(10))
+
+- SF Bug #976608: fix SystemError when mtime of an imported file is -1.
+
+- SF Bug #887946: fix segfault when redirecting stdin from a directory.
+  Provide a warning when a directory is passed on the command line.
+
+- Fix segfault with invalid coding.
+
+- SF bug #772896: unknown encoding results in MemoryError.
+
+- All iterators now have a Boolean value of True.  Formerly, some iterators
+  supported a __len__() method which evaluated to False when the iterator
+  was empty.
+
+- On 64-bit platforms, when __len__() returns a value that cannot be
+  represented as a C int, raise OverflowError.
+
+- test__locale is skipped on OS X < 10.4 (only partial locale support is
+  present).
+
+- SF bug #893549: parsing keyword arguments was broken with a few format
+  codes.
+
+- Changes donated by Elemental Security to make it work on AIX 5.3
+  with IBM's 64-bit compiler (SF patch #1284289).  This also closes SF
+  bug #105470: test_pwd fails on 64bit system (Opteron).
+
+- Changes donated by Elemental Security to make it work on HP-UX 11 on
+  Itanium2 with HP's 64-bit compiler (SF patch #1225212).
+
+- Disallow keyword arguments for type constructors that don't use them
+  (fixes bug #1119418).
+
+- Forward UnicodeDecodeError into SyntaxError for source encoding errors.
+
+- SF bug #900092: When tracing (e.g. for hotshot), restore 'return' events for
+  exceptions that cause a function to exit.
+
+- The implementation of set() and frozenset() was revised to use its
+  own internal data structure.  Memory consumption is reduced by 1/3
+  and there are modest speed-ups as well.  The API is unchanged.
+
+- SF bug #1238681:  freed pointer is used in longobject.c:long_pow().
+
+- SF bug #1229429: PyObject_CallMethod failed to decrement some
+  reference counts in some error exit cases.
+
+- SF bug #1185883:  Python's small-object memory allocator took over
+  a block managed by the platform C library whenever a realloc specified
+  a small new size.  However, there's no portable way to know then how
+  much of the address space following the pointer is valid, so there's no
+  portable way to copy data from the C-managed block into Python's
+  small-object space without risking a memory fault.  Python's small-object
+  realloc now leaves such blocks under the control of the platform C
+  realloc.
+
+- SF bug #1232517: An overflow error was not detected properly when
+  attempting to convert a large float to an int in os.utime().
+
+- SF bug #1224347: hex longs now print with lowercase letters just
+  like their int counterparts.
+
+- SF bug #1163563: the original fix for bug #1010677 ("thread Module
+  Breaks PyGILState_Ensure()") broke badly in the case of multiple
+  interpreter states; back out that fix and do a better job (see
+  http://mail.python.org/pipermail/python-dev/2005-June/054258.html
+  for a longer write-up of the problem).
+
+- SF patch #1180995: marshal now uses a binary format by default when
+  serializing floats.
+
+- SF patch #1181301: on platforms that appear to use IEEE 754 floats,
+  the routines that promise to produce IEEE 754 binary representations
+  of floats now simply copy bytes around.
+
+- bug #967182: disallow opening files with 'wU' or 'aU' as specified by PEP
+  278.
+
+- patch #1109424: int, long, float, complex, and unicode now check for the
+  proper magic slot for type conversions when subclassed.  Previously the
+  magic slot was ignored during conversion.  Semantics now match the way
+  subclasses of str always behaved.  int/long/float, conversion of an instance
+  to the base class has been moved to the proper nb_* magic slot and out of
+  PyNumber_*().
+  Thanks Walter D�rwald.
+
+- Descriptors defined in C with a PyGetSetDef structure, where the setter is
+  NULL, now raise an AttributeError when attempting to set or delete the
+  attribute.  Previously a TypeError was raised, but this was inconsistent
+  with the equivalent pure-Python implementation.
+
+- It is now safe to call PyGILState_Release() before
+  PyEval_InitThreads() (note that if there is reason to believe there
+  are multiple threads around you still must call PyEval_InitThreads()
+  before using the Python API; this fix is for extension modules that
+  have no way of knowing if Python is multi-threaded yet).
+
+- Typing Ctrl-C whilst raw_input() was waiting in a build with threads
+  disabled caused a crash.
+
+- Bug #1165306: instancemethod_new allowed the creation of a method
+  with im_class == im_self == NULL, which caused a crash when called.
+
+- Move exception finalisation later in the shutdown process - this
+  fixes the crash seen in bug #1165761
+
+- Added two new builtins, any() and all().
+
+- Defining a class with empty parentheses is now allowed
+  (e.g., ``class C(): pass`` is no longer a syntax error).
+  Patch #1176012 added support to the 'parser' module and 'compiler' package
+  (thanks to logistix for that added support).
+
+- Patch #1115086: Support PY_LONGLONG in structmember.
+
+- Bug #1155938: new style classes did not check that __init__() was
+  returning None.
+
+- Patch #802188: Report characters after line continuation character
+  ('\') with a specific error message.
+
+- Bug #723201: Raise a TypeError for passing bad objects to 'L' format.
+
+- Bug #1124295: the __name__ attribute of file objects was
+  inadvertently made inaccessible in restricted mode.
+
+- Bug #1074011: closing sys.std{out,err} now causes a flush() and
+  an ferror() call.
+
+- min() and max() now support key= arguments with the same meaning as in
+  list.sort().
+
+- The peephole optimizer now performs simple constant folding in expressions:
+      (2+3) --> (5).
+
+- set and frozenset objects can now be marshalled.  SF #1098985.
+
+- Bug #1077106: Poor argument checking could cause memory corruption
+  in calls to os.read().
+
+- The parser did not complain about future statements in illegal
+  positions.  It once again reports a syntax error if a future
+  statement occurs after anything other than a doc string.
+
+- Change the %s format specifier for str objects so that it returns a
+  unicode instance if the argument is not an instance of basestring and
+  calling __str__ on the argument returns a unicode instance.
+
+- Patch #1413181:  changed ``PyThreadState_Delete()`` to forget about the
+  current thread state when the auto-GIL-state machinery knows about
+  it (since the thread state is being deleted, continuing to remember it
+  can't help, but can hurt if another thread happens to get created with
+  the same thread id).
+
+Extension Modules
+-----------------
+
+- Patch #1380952: fix SSL objects timing out on consecutive read()s
+
+- Patch #1309579: wait3 and wait4 were added to the posix module.
+
+- Patch #1231053: The audioop module now supports encoding/decoding of alaw.
+  In addition, the existing ulaw code was updated.
+
+- RFE #567972: Socket objects' family, type and proto properties are
+  now exposed via new attributes.
+
+- Everything under lib-old was removed.  This includes the following modules:
+    Para, addpack, cmp, cmpcache, codehack, dircmp, dump, find, fmt, grep,
+    lockfile, newdir, ni, packmail, poly, rand, statcache, tb, tzparse,
+    util, whatsound, whrandom, zmod
+
+- The following modules were removed:  regsub, reconvert, regex, regex_syntax.
+
+- re and sre were swapped, so help(re) provides full help.  importing sre
+  is deprecated.  The undocumented re.engine variable no longer exists.
+
+- Bug #1448490: Fixed a bug that ISO-2022 codecs could not handle
+  SS2 (single-shift 2) escape sequences correctly.
+
+- The unicodedata module was updated to the 4.1 version of the Unicode
+  database. The 3.2 version is still available as unicodedata.db_3_2_0
+  for applications that require this specific version (such as IDNA).
+
+- The timing module is no longer built by default.  It was deprecated
+  in PEP 4 in Python 2.0 or earlier.
+
+- Patch 1433928: Added a new type, defaultdict, to the collections module.
+  This uses the new __missing__ hook behavior added to dict (see above).
+
+- Bug #854823: socketmodule now builds on Sun platforms even when
+  INET_ADDRSTRLEN is not defined.
+
+- Patch #1393157: os.startfile() now has an optional argument to specify
+  a "command verb" to invoke on the file.
+
+- Bug #876637, prevent stack corruption when socket descriptor
+  is larger than FD_SETSIZE.
+
+- Patch #1407135, bug #1424041: harmonize mmap behavior of anonymous memory.
+  mmap.mmap(-1, size) now returns anonymous memory in both Unix and Windows.
+  mmap.mmap(0, size) should not be used on Windows for anonymous memory.
+
+- Patch #1422385: The nis module now supports access to domains other
+  than the system default domain.
+
+- Use Win32 API to implement os.stat/fstat. As a result, subsecond timestamps
+  are reported, the limit on path name lengths is removed, and stat reports
+  WindowsError now (instead of OSError).
+
+- Add bsddb.db.DBEnv.set_tx_timestamp allowing time based database recovery.
+
+- Bug #1413192, fix seg fault in bsddb if a transaction was deleted
+  before the env.
+
+- Patch #1103116: Basic AF_NETLINK support.
+
+- Bug #1402308, (possible) segfault when using mmap.mmap(-1, ...)
+
+- Bug #1400822, _curses over{lay,write} doesn't work when passing 6 ints.
+  Also fix ungetmouse() which did not accept arguments properly.
+  The code now conforms to the documented signature.
+
+- Bug #1400115, Fix segfault when calling curses.panel.userptr()
+  without prior setting of the userptr.
+
+- Fix 64-bit problems in bsddb.
+
+- Patch #1365916: fix some unsafe 64-bit mmap methods.
+
+- Bug #1290333: Added a workaround for cjkcodecs' _codecs_cn build
+  problem on AIX.
+
+- Bug #869197: os.setgroups rejects long integer arguments
+
+- Bug #1346533, select.poll() doesn't raise an error if timeout > sys.maxint
+
+- Bug #1344508, Fix UNIX mmap leaking file descriptors
+
+- Patch #1338314, Bug #1336623: fix tarfile so it can extract
+  REGTYPE directories from tarfiles written by old programs.
+
+- Patch #1407992, fixes broken bsddb module db associate when using
+  BerkeleyDB 3.3, 4.0 or 4.1.
+
+- Get bsddb module to build with BerkeleyDB version 4.4
+
+- Get bsddb module to build with BerkeleyDB version 3.2
+
+- Patch #1309009, Fix segfault in pyexpat when the XML document is in latin_1,
+  but Python incorrectly assumes it is in UTF-8 format
+
+- Fix parse errors in the readline module when compiling without threads.
+
+- Patch #1288833: Removed thread lock from socket.getaddrinfo on
+  FreeBSD 5.3 and later versions which got thread-safe getaddrinfo(3).
+
+- Patches #1298449 and #1298499: Add some missing checks for error
+  returns in cStringIO.c.
+
+- Patch #1297028: fix segfault if call type on MultibyteCodec,
+  MultibyteStreamReader, or MultibyteStreamWriter
+
+- Fix memory leak in posix.access().
+
+- Patch #1213831: Fix typo in unicodedata._getcode.
+
+- Bug #1007046: os.startfile() did not accept unicode strings encoded in
+  the file system encoding.
+
+- Patch #756021: Special-case socket.inet_aton('255.255.255.255') for
+  platforms that don't have inet_aton().
+
+- Bug #1215928: Fix bz2.BZ2File.seek() for 64-bit file offsets.
+
+- Bug #1191043: Fix bz2.BZ2File.(x)readlines for files containing one
+  line without newlines.
+
+- Bug #728515: mmap.resize() now resizes the file on Unix as it did
+  on Windows.
+
+- Patch #1180695: Add nanosecond stat resolution, and st_gen,
+  st_birthtime for FreeBSD.
+
+- Patch #1231069: The fcntl.ioctl function now uses the 'I' code for
+  the request code argument, which results in more C-like behaviour
+  for large or negative values.
+
+- Bug #1234979: For the argument of thread.Lock.acquire, the Windows
+  implementation treated all integer values except 1 as false.
+
+- Bug #1194181: bz2.BZ2File didn't handle mode 'U' correctly.
+
+- Patch #1212117: os.stat().st_flags is now accessible as a attribute
+  if available on the platform.
+
+- Patch #1103951: Expose O_SHLOCK and O_EXLOCK in the posix module if
+  available on the platform.
+
+- Bug #1166660: The readline module could segfault if hook functions
+  were set in a different thread than that which called readline.
+
+- collections.deque objects now support a remove() method.
+
+- operator.itemgetter() and operator.attrgetter() now support retrieving
+  multiple fields.  This provides direct support for sorting on multiple
+  keys (primary, secondary, etc).
+
+- os.access now supports Unicode path names on non-Win32 systems.
+
+- Patches #925152, #1118602: Avoid reading after the end of the buffer
+  in pyexpat.GetInputContext.
+
+- Patches #749830, #1144555: allow UNIX mmap size to default to current
+  file size.
+
+- Added functional.partial().  See PEP309.
+
+- Patch #1093585: raise a ValueError for negative history items in readline.
+  {remove_history,replace_history}
+
+- The spwd module has been added, allowing access to the shadow password
+  database.
+
+- stat_float_times is now True.
+
+- array.array objects are now picklable.
+
+- the cPickle module no longer accepts the deprecated None option in the
+  args tuple returned by __reduce__().
+
+- itertools.islice() now accepts None for the start and step arguments.
+  This allows islice() to work more readily with slices:
+      islice(s.start, s.stop, s.step)
+
+- datetime.datetime() now has a strptime class method which can be used to
+  create datetime object using a string and format.
+
+- Patch #1117961: Replace the MD5 implementation from RSA Data Security Inc
+  with the implementation from http://sourceforge.net/projects/libmd5-rfc/.
+
+Library
+-------
+
+- Patch #1388073: Numerous __-prefixed attributes of unittest.TestCase have
+  been renamed to have only a single underscore prefix.  This was done to
+  make subclassing easier.
+
+- PEP 338: new module runpy defines a run_module function to support
+  executing modules which provide access to source code or a code object
+  via the PEP 302 import mechanisms.
+
+- The email module's parsedate_tz function now sets the daylight savings
+  flag to -1 (unknown) since it can't tell from the date whether it should
+  be set.
+
+- Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
+  now sport attributes that provide access to the parts of the result.
+
+- Patch #1462498: sgmllib now handles entity and character references
+  in attribute values.
+
+- Added the sqlite3 package. This is based on pysqlite2.1.3, and provides
+  a DB-API interface in the standard library. You'll need sqlite 3.0.8 or
+  later to build this - if you have an earlier version, the C extension
+  module will not be built.
+
+- Bug #1460340: ``random.sample(dict)`` failed in various ways.  Dicts
+  aren't officially supported here, and trying to use them will probably
+  raise an exception some day.  But dicts have been allowed, and "mostly
+  worked", so support for them won't go away without warning.
+
+- Bug #1445068: getpass.getpass() can now be given an explicit stream
+  argument to specify where to write the prompt.
+
+- Patch #1462313, bug #1443328: the pickle modules now can handle classes
+  that have __private names in their __slots__.
+
+- Bug #1250170: mimetools now handles socket.gethostname() failures gracefully.
+
+- patch #1457316: "setup.py upload" now supports --identity to select the
+  key to be used for signing the uploaded code.
+
+- Queue.Queue objects now support .task_done() and .join() methods
+  to make it easier to monitor when daemon threads have completed
+  processing all enqueued tasks.  Patch #1455676.
+
+- popen2.Popen objects now preserve the command in a .cmd attribute.
+
+- Added the ctypes ffi package.
+
+- email 4.0 package now integrated.  This is largely the same as the email 3.0
+  package that was included in Python 2.3, except that PEP 8 module names are
+  now used (e.g. mail.message instead of email.Message).  The MIME classes
+  have been moved to a subpackage (e.g. email.mime.text instead of
+  email.MIMEText).  The old names are still supported for now.  Several
+  deprecated Message methods have been removed and lots of bugs have been
+  fixed.  More details can be found in the email package documentation.
+
+- Patches #1436130/#1443155: codecs.lookup() now returns a CodecInfo object
+  (a subclass of tuple) that provides incremental decoders and encoders
+  (a way to use stateful codecs without the stream API). Python functions
+  codecs.getincrementaldecoder() and codecs.getincrementalencoder() as well
+  as C functions PyCodec_IncrementalEncoder() and PyCodec_IncrementalDecoder()
+  have been added.
+
+- Patch #1359365: Calling next() on a closed StringIO.String object raises
+  a ValueError instead of a StopIteration now (like file and cString.String do).
+  cStringIO.StringIO.isatty() will raise a ValueError now if close() has been
+  called before (like file and StringIO.StringIO do).
+
+- A regrtest option -w was added to re-run failed tests in verbose mode.
+
+- Patch #1446372: quit and exit can now be called from the interactive
+  interpreter to exit.
+
+- The function get_count() has been added to the gc module, and gc.collect()
+  grew an optional 'generation' argument.
+
+- A library msilib to generate Windows Installer files, and a distutils
+  command bdist_msi have been added.
+
+- PEP 343: new module contextlib.py defines decorator @contextmanager
+  and helpful context managers nested() and closing().
+
+- The compiler package now supports future imports after the module docstring.
+
+- Bug #1413790: zipfile now sanitizes absolute archive names that are
+  not allowed by the specs.
+
+- Patch #1215184: FileInput now can be given an opening hook which can
+  be used to control how files are opened.
+
+- Patch #1212287: fileinput.input() now has a mode parameter for
+  specifying the file mode input files should be opened with.
+
+- Patch #1215184: fileinput now has a fileno() function for getting the
+  current file number.
+
+- Patch #1349274: gettext.install() now optionally installs additional
+  translation functions other than _() in the builtin namespace.
+
+- Patch #1337756: fileinput now accepts Unicode filenames.
+
+- Patch #1373643: The chunk module can now read chunks larger than
+  two gigabytes.
+
+- Patch #1417555: SimpleHTTPServer now returns Last-Modified headers.
+
+- Bug #1430298: It is now possible to send a mail with an empty
+  return address using smtplib.
+
+- Bug #1432260: The names of lambda functions are now properly displayed
+  in pydoc.
+
+- Patch #1412872: zipfile now sets the creator system to 3 (Unix)
+  unless the system is Win32.
+
+- Patch #1349118: urllib now supports user:pass@ style proxy
+  specifications, raises IOErrors when proxies for unsupported protocols
+  are defined, and uses the https proxy on https redirections.
+
+- Bug #902075: urllib2 now supports 'host:port' style proxy specifications.
+
+- Bug #1407902: Add support for sftp:// URIs to urlparse.
+
+- Bug #1371247: Update Windows locale identifiers in locale.py.
+
+- Bug #1394565: SimpleHTTPServer now doesn't choke on query parameters
+  any more.
+
+- Bug #1403410: The warnings module now doesn't get confused
+  when it can't find out the module name it generates a warning for.
+
+- Patch #1177307: Added a new codec utf_8_sig for UTF-8 with a BOM signature.
+
+- Patch #1157027: cookielib mishandles RFC 2109 cookies in Netscape mode
+
+- Patch #1117398: cookielib.LWPCookieJar and .MozillaCookieJar now raise
+  LoadError as documented, instead of IOError.  For compatibility,
+  LoadError subclasses IOError.
+
+- Added the hashlib module.  It provides secure hash functions for MD5 and
+  SHA1, 224, 256, 384, and 512.  Note that recent developments make the
+  historic MD5 and SHA1 unsuitable for cryptographic-strength applications.
+  In <http://mail.python.org/pipermail/python-dev/2005-December/058850.html>
+  Ronald L. Rivest offered this advice for Python:
+
+      "The consensus of researchers in this area (at least as
+      expressed at the NIST Hash Function Workshop 10/31/05),
+      is that SHA-256 is a good choice for the time being, but
+      that research should continue, and other alternatives may
+      arise from this research.  The larger SHA's also seem OK."
+
+- Added a subset of Fredrik Lundh's ElementTree package.  Available
+  modules are xml.etree.ElementTree, xml.etree.ElementPath, and
+  xml.etree.ElementInclude, from ElementTree 1.2.6.
+
+- Patch #1162825: Support non-ASCII characters in IDLE window titles.
+
+- Bug #1365984: urllib now opens "data:" URLs again.
+
+- Patch #1314396: prevent deadlock for threading.Thread.join() when an exception
+  is raised within the method itself on a previous call (e.g., passing in an
+  illegal argument)
+
+- Bug #1340337: change time.strptime() to always return ValueError when there
+  is an error in the format string.
+
+- Patch #754022: Greatly enhanced webbrowser.py (by Oleg Broytmann).
+
+- Bug #729103: pydoc.py: Fix docother() method to accept additional
+  "parent" argument.
+
+- Patch #1300515: xdrlib.py: Fix pack_fstring() to really use null bytes
+  for padding.
+
+- Bug #1296004: httplib.py: Limit maximal amount of data read from the
+  socket to avoid a MemoryError on Windows.
+
+- Patch #1166948: locale.py: Prefer LC_ALL, LC_CTYPE and LANG over LANGUAGE
+  to get the correct encoding.
+
+- Patch #1166938: locale.py: Parse LANGUAGE as a colon separated list of
+  languages.
+
+- Patch #1268314: Cache lines in StreamReader.readlines for performance.
+
+- Bug #1290505: Fix clearing the regex cache for time.strptime().
+
+- Bug #1167128: Fix size of a symlink in a tarfile to be 0.
+
+- Patch #810023: Fix off-by-one bug in urllib.urlretrieve reporthook
+  functionality.
+
+- Bug #1163178: Make IDNA return an empty string when the input is empty.
+
+- Patch #848017: Make Cookie more RFC-compliant. Use CRLF as default output
+  separator and do not output trailing semicolon.
+
+- Patch #1062060: urllib.urlretrieve() now raises a new exception, named
+  ContentTooShortException, when the actually downloaded size does not
+  match the Content-Length header.
+
+- Bug #1121494: distutils.dir_utils.mkpath now accepts Unicode strings.
+
+- Bug #1178484: Return complete lines from codec stream readers
+  even if there is an exception in later lines, resulting in
+  correct line numbers for decoding errors in source code.
+
+- Bug #1192315: Disallow negative arguments to clear() in pdb.
+
+- Patch #827386: Support absolute source paths in msvccompiler.py.
+
+- Patch #1105730: Apply the new implementation of commonprefix in posixpath
+  to ntpath, macpath, os2emxpath and riscospath.
+
+- Fix a problem in Tkinter introduced by SF patch #869468: delete bogus
+  __hasattr__ and __delattr__ methods on class Tk that were breaking
+  Tkdnd.
+
+- Bug #1015140: disambiguated the term "article id" in nntplib docs and
+  docstrings to either "article number" or "message id".
+
+- Bug #1238170: threading.Thread.__init__ no longer has "kwargs={}" as a
+  parameter, but uses the usual "kwargs=None".
+
+- textwrap now processes text chunks at O(n) speed instead of O(n**2).
+  Patch #1209527 (Contributed by Connelly).
+
+- urllib2 has now an attribute 'httpresponses' mapping from HTTP status code
+  to W3C name (404 -> 'Not Found'). RFE #1216944.
+
+- Bug #1177468: Don't cache the /dev/urandom file descriptor for os.urandom,
+  as this can cause problems with apps closing all file descriptors.
+
+- Bug #839151: Fix an attempt to access sys.argv in the warnings module;
+  it can be missing in embedded interpreters
+
+- Bug #1155638: Fix a bug which affected HTTP 0.9 responses in httplib.
+
+- Bug #1100201: Cross-site scripting was possible on BaseHTTPServer via
+  error messages.
+
+- Bug #1108948: Cookie.py produced invalid JavaScript code.
+
+- The tokenize module now detects and reports indentation errors.
+  Bug #1224621.
+
+- The tokenize module has a new untokenize() function to support a full
+  roundtrip from lexed tokens back to Python source code.  In addition,
+  the generate_tokens() function now accepts a callable argument that
+  terminates by raising StopIteration.
+
+- Bug #1196315: fix weakref.WeakValueDictionary constructor.
+
+- Bug #1213894: os.path.realpath didn't resolve symlinks that were the first
+  component of the path.
+
+- Patch #1120353: The xmlrpclib module provides better, more transparent,
+  support for datetime.{datetime,date,time} objects.  With use_datetime set
+  to True, applications shouldn't have to fiddle with the DateTime wrapper
+  class at all.
+
+- distutils.commands.upload was added to support uploading distribution
+  files to PyPI.
+
+- distutils.commands.register now encodes the data as UTF-8 before posting
+  them to PyPI.
+
+- decimal operator and comparison methods now return NotImplemented
+  instead of raising a TypeError when interacting with other types.  This
+  allows other classes to implement __radd__ style methods and have them
+  work as expected.
+
+- Bug #1163325:  Decimal infinities failed to hash.  Attempting to
+  hash a NaN raised an InvalidOperation instead of a TypeError.
+
+- Patch #918101: Add tarfile open mode r|* for auto-detection of the
+  stream compression; add, for symmetry reasons, r:* as a synonym of r.
+
+- Patch #1043890: Add extractall method to tarfile.
+
+- Patch #1075887: Don't require MSVC in distutils if there is nothing
+  to build.
+
+- Patch #1103407: Properly deal with tarfile iterators when untarring
+  symbolic links on Windows.
+
+- Patch #645894: Use getrusage for computing the time consumption in
+  profile.py if available.
+
+- Patch #1046831: Use get_python_version where appropriate in sysconfig.py.
+
+- Patch #1117454: Remove code to special-case cookies without values
+  in LWPCookieJar.
+
+- Patch #1117339: Add cookielib special name tests.
+
+- Patch #1112812: Make bsddb/__init__.py more friendly for modulefinder.
+
+- Patch #1110248: SYNC_FLUSH the zlib buffer for GZipFile.flush.
+
+- Patch #1107973: Allow to iterate over the lines of a tarfile.ExFileObject.
+
+- Patch #1104111: Alter setup.py --help and --help-commands.
+
+- Patch #1121234: Properly cleanup _exit and tkerror commands.
+
+- Patch #1049151: xdrlib now unpacks booleans as True or False.
+
+- Fixed bug in a NameError bug in cookielib.  Patch #1116583.
+
+- Applied a security fix to SimpleXMLRPCserver (PSF-2005-001).  This
+  disables recursive traversal through instance attributes, which can
+  be exploited in various ways.
+
+- Bug #1222790: in SimpleXMLRPCServer, set the reuse-address and close-on-exec
+  flags on the HTTP listening socket.
+
+- Bug #792570: SimpleXMLRPCServer had problems if the request grew too large.
+  Fixed by reading the HTTP body in chunks instead of one big socket.read().
+
+- Patches #893642, #1039083: add allow_none, encoding arguments to
+  constructors of SimpleXMLRPCServer and CGIXMLRPCRequestHandler.
+
+- Bug #1110478: Revert os.environ.update to do putenv again.
+
+- Bug #1103844: fix distutils.install.dump_dirs() with negated options.
+
+- os.{SEEK_SET, SEEK_CUR, SEEK_END} have been added for convenience.
+
+- Enhancements to the csv module:
+
+  + Dialects are now validated by the underlying C code, better
+    reflecting its capabilities, and improving its compliance with
+    PEP 305.
+  + Dialect parameter parsing has been re-implemented to improve error
+    reporting.
+  + quotechar=None and quoting=QUOTE_NONE now work the way PEP 305
+    dictates.
+  + the parser now removes the escapechar prefix from escaped characters.
+  + when quoting=QUOTE_NONNUMERIC, the writer now tests for numeric
+    types, rather than any object that can be represented as a numeric.
+  + when quoting=QUOTE_NONNUMERIC, the reader now casts unquoted fields
+    to floats.
+  + reader now allows \r characters to be quoted (previously it only allowed
+    \n to be quoted).
+  + writer doublequote handling improved.
+  + Dialect classes passed to the module are no longer instantiated by
+    the module before being parsed (the former validation scheme required
+    this, but the mechanism was unreliable).
+  + The dialect registry now contains instances of the internal
+    C-coded dialect type, rather than references to python objects.
+  + the internal c-coded dialect type is now immutable.
+  + register_dialect now accepts the same keyword dialect specifications
+    as the reader and writer, allowing the user to register dialects
+    without first creating a dialect class.
+  + a configurable limit to the size of parsed fields has been added -
+    previously, an unmatched quote character could result in the entire
+    file being read into the field buffer before an error was reported.
+  + A new module method csv.field_size_limit() has been added that sets
+    the parser field size limit (returning the former limit). The initial
+    limit is 128kB.
+  + A line_num attribute has been added to the reader object, which tracks
+    the number of lines read from the source iterator. This is not
+    the same as the number of records returned, as records can span
+    multiple lines.
+  + reader and writer objects were not being registered with the cyclic-GC.
+    This has been fixed.
+
+- _DummyThread objects in the threading module now delete self.__block that is
+  inherited from _Thread since it uses up a lock allocated by 'thread'.  The
+  lock primitives tend to be limited in number and thus should not be wasted on
+  a _DummyThread object.  Fixes bug #1089632.
+
+- The imghdr module now detects Exif files.
+
+- StringIO.truncate() now correctly adjusts the size attribute.
+  (Bug #951915).
+
+- locale.py now uses an updated locale alias table (built using
+  Tools/i18n/makelocalealias.py, a tool to parse the X11 locale
+  alias file); the encoding lookup was enhanced to use Python's
+  encoding alias table.
+
+- moved deprecated modules to Lib/lib-old:  whrandom, tzparse, statcache.
+
+- the pickle module no longer accepts the deprecated None option in the
+  args tuple returned by __reduce__().
+
+- optparse now optionally imports gettext.  This allows its use in setup.py.
+
+- the pickle module no longer uses the deprecated bin parameter.
+
+- the shelve module no longer uses the deprecated binary parameter.
+
+- the pstats module no longer uses the deprecated ignore() method.
+
+- the filecmp module no longer uses the deprecated use_statcache argument.
+
+- unittest.TestCase.run() and unittest.TestSuite.run() can now be successfully
+  extended or overridden by subclasses.  Formerly, the subclassed method would
+  be ignored by the rest of the module.  (Bug #1078905).
+
+- heapq.nsmallest() and heapq.nlargest() now support key= arguments with
+  the same meaning as in list.sort().
+
+- Bug #1076985: ``codecs.StreamReader.readline()`` now calls ``read()`` only
+  once when a size argument is given. This prevents a buffer overflow in the
+  tokenizer with very long source lines.
+
+- Bug #1083110: ``zlib.decompress.flush()`` would segfault if called
+  immediately after creating the object, without any intervening
+  ``.decompress()`` calls.
+
+- The reconvert.quote function can now emit triple-quoted strings.  The
+  reconvert module now has some simple documentation.
+
+- ``UserString.MutableString`` now supports negative indices in
+  ``__setitem__`` and ``__delitem__``
+
+- Bug #1149508: ``textwrap`` now handles hyphenated numbers (eg. "2004-03-05")
+  correctly.
+
+- Partial fixes for SF bugs #1163244 and #1175396: If a chunk read by
+  ``codecs.StreamReader.readline()`` has a trailing "\r", read one more
+  character even if the user has passed a size parameter to get a proper
+  line ending. Remove the special handling of a "\r\n" that has been split
+  between two lines.
+
+- Bug #1251300: On UCS-4 builds the "unicode-internal" codec will now complain
+  about illegal code points. The codec now supports PEP 293 style error
+  handlers.
+
+- Bug #1235646: ``codecs.StreamRecoder.next()`` now reencodes the data it reads
+  from the input stream, so that the output is a byte string in the correct
+  encoding instead of a unicode string.
+
+- Bug #1202493: Fixing SRE parser to handle '{}' as perl does, rather than
+  considering it exactly like a '*'.
+
+- Bug #1245379: Add "unicode-1-1-utf-7" as an alias for "utf-7" to
+  ``encodings.aliases``.
+
+- ` uu.encode()`` and ``uu.decode()`` now support unicode filenames.
+
+- Patch #1413711: Certain patterns of differences were making difflib
+  touch the recursion limit.
+
+- Bug #947906: An object oriented interface has been added to the calendar
+  module. It's possible to generate HTML calendar now and the module can be
+  called as a script (e.g. via ``python -mcalendar``). Localized month and
+  weekday names can be ouput (even if an exotic encoding is used) using
+  special classes that use unicode.
+
+Build
+-----
+
+- Fix test_float, test_long, and test_struct failures on Tru64 with gcc
+  by using -mieee gcc option.
+
+- Patch #1432345: Make python compile on DragonFly.
+
+- Build support for Win64-AMD64 was added.
+
+- Patch #1428494: Prefer linking against ncursesw over ncurses library.
+
+- Patch #881820: look for openpty and forkpty also in libbsd.
+
+- The sources of zlib are now part of the Python distribution (zlib 1.2.3).
+  The zlib module is now builtin on Windows.
+
+- Use -xcode=pic32 for CCSHARED on Solaris with SunPro.
+
+- Bug #1189330: configure did not correctly determine the necessary
+  value of LINKCC if python was built with GCC 4.0.
+
+- Upgrade Windows build to zlib 1.2.3 which eliminates a potential security
+  vulnerability in zlib 1.2.1 and 1.2.2.
+
+- EXTRA_CFLAGS has been introduced as an environment variable to hold compiler
+  flags that change binary compatibility.  Changes were also made to
+  distutils.sysconfig to also use the environment variable when used during
+  compilation of the interpreter and of C extensions through distutils.
+
+- SF patch 1171735: Darwin 8's headers are anal about POSIX compliance,
+  and linking has changed (prebinding is now deprecated, and libcc_dynamic
+  no longer exists). This configure patch makes things right.
+
+- Bug #1158607: Build with --disable-unicode again.
+
+- spwdmodule.c is built only if either HAVE_GETSPNAM or HAVE_HAVE_GETSPENT is
+  defined.  Discovered as a result of not being able to build on OS X.
+
+- setup.py now uses the directories specified in LDFLAGS using the -L option
+  and in CPPFLAGS using the -I option for adding library and include
+  directories, respectively, for compiling extension modules against.  This has
+  led to the core being compiled using the values in CPPFLAGS.  It also removes
+  the need for the special-casing of both DarwinPorts and Fink for darwin since
+  the proper directories can be specified in LDFLAGS (``-L/sw/lib`` for Fink,
+  ``-L/opt/local/lib`` for DarwinPorts) and CPPFLAGS (``-I/sw/include`` for
+  Fink, ``-I/opt/local/include`` for DarwinPorts).
+
+- Test in configure.in that checks for tzset no longer dependent on tm->tm_zone
+  to exist in the struct (not required by either ISO C nor the UNIX 2 spec).
+  Tests for sanity in tzname when HAVE_TZNAME defined were also defined.
+  Closes bug #1096244.  Thanks Gregory Bond.
+
+C API
+-----
+
+- ``PyMem_{Del, DEL}`` and ``PyMem_{Free, FREE}`` no longer map to
+  ``PyObject_{Free, FREE}``.  They map to the system ``free()`` now.  If memory
+  is obtained via the ``PyObject_`` family, it must be released via the
+  ``PyObject_`` family, and likewise for the ``PyMem_`` family.  This has
+  always been officially true, but when Python's small-object allocator was
+  introduced, an attempt was made to cater to a few extension modules
+  discovered at the time that obtained memory via ``PyObject_New`` but
+  released it via ``PyMem_DEL``.  It's years later, and if such code still
+  exists it will fail now (probably with segfaults, but calling wrong
+  low-level memory management functions can yield many symptoms).
+
+- Added a C API for set and frozenset objects.
+
+- Removed PyRange_New().
+
+- Patch #1313939: PyUnicode_DecodeCharmap() accepts a unicode string as the
+  mapping argument now. This string is used as a mapping table. Byte values
+  greater than the length of the string and 0xFFFE are treated as undefined
+  mappings.
+
+
+Tests
+-----
+
+- In test_os, st_?time is now truncated before comparing it with ST_?TIME.
+
+- Patch #1276356: New resource "urlfetch" is implemented.  This enables
+  even impatient people to run tests that require remote files.
+
+
+Documentation
+-------------
+
+- Bug #1402224: Add warning to dl docs about crashes.
+
+- Bug #1396471: Document that Windows' ftell() can return invalid
+  values for text files with UNIX-style line endings.
+
+- Bug #1274828: Document os.path.splitunc().
+
+- Bug #1190204: Clarify which directories are searched by site.py.
+
+- Bug #1193849: Clarify os.path.expanduser() documentation.
+
+- Bug #1243192: re.UNICODE and re.LOCALE affect \d, \D, \s and \S.
+
+- Bug #755617: Document the effects of os.chown() on Windows.
+
+- Patch #1180012: The documentation for modulefinder is now in the library reference.
+
+- Patch #1213031: Document that os.chown() accepts argument values of -1.
+
+- Bug #1190563: Document os.waitpid() return value with WNOHANG flag.
+
+- Bug #1175022: Correct the example code for property().
+
+- Document the IterableUserDict class in the UserDict module.
+  Closes bug #1166582.
+
+- Remove all latent references for "Macintosh" that referred to semantics for
+  Mac OS 9 and change to reflect the state for OS X.
+  Closes patch #1095802.  Thanks Jack Jansen.
+
+Mac
+---
+
+
+New platforms
+-------------
+
+- FreeBSD 7 support is added.
+
+
+Tools/Demos
+-----------
+
+- Created Misc/Vim/vim_syntax.py to auto-generate a python.vim file in that
+  directory for syntax highlighting in Vim.  Vim directory was added and placed
+  vimrc to it (was previous up a level).
+
+- Added two new files to Tools/scripts: pysource.py, which recursively
+  finds Python source files, and findnocoding.py, which finds Python
+  source files that need an encoding declaration.
+  Patch #784089, credits to Oleg Broytmann.
+
+- Bug #1072853: pindent.py used an uninitialized variable.
+
+- Patch #1177597: Correct Complex.__init__.
+
+- Fixed a display glitch in Pynche, which could cause the right arrow to
+  wiggle over by a pixel.
+
+
 What's New in Python 2.4 final?
 ===============================
 

Modified: python/branches/py3k-importlib/Misc/NEWS
==============================================================================
--- python/branches/py3k-importlib/Misc/NEWS	(original)
+++ python/branches/py3k-importlib/Misc/NEWS	Thu Mar 27 00:48:05 2008
@@ -4,9 +4,259 @@
 
 (editors: check NEWS.help for information about editing NEWS using ReST.)
 
+What's New in Python 3.0a4?
+===========================
+
+*Release date: XX-XXX-2008*
+
+Core and Builtins
+-----------------
+
+- Bug #2301: Don't try decoding the source code into the original
+  encoding for syntax errors.
+
+Extension Modules
+-----------------
+
+- Use wchar_t functions in _locale module.
+
+Library
+-------
+
+- The class distutils.commands.build_py.build_py_2to3 can be used
+  as a build_py replacement to automatically run 2to3 on modules
+  that are going to be installed.
+
+- A new pickle protocol (protocol 3) is added with explicit support
+  for bytes.  This is the default protocol.  It intentionally cannot
+  be unpickled by Python 2.x.
+
+- When a pickle written by Python 2.x contains an (8-bit) str
+  instance, this is now decoded to a (Unicode) str instance.  The
+  encoding used to do this defaults to ASCII, but can be overridden
+  via two new keyword arguments to the Unpickler class.  Previously
+  this would create bytes instances, which is usually wrong: str
+  instances are often used to pickle attribute names etc., and text is
+  more common than binary data anyway.
+
+- Default to ASCII as the locale.getpreferredencoding, if the POSIX
+  system doesn't support CODESET and LANG isn't set or doesn't
+  allow deduction of an encoding.
+
+- Issue #1202: zlib.crc32 and zlib.adler32 now return an unsigned value.
+
+- Issue #719888: Updated tokenize to use a bytes API. generate_tokens has been
+  renamed tokenize and now works with bytes rather than strings. A new
+  detect_encoding function has been added for determining source file encoding
+  according to PEP-0263. Token sequences returned by tokenize always start
+  with an ENCODING token which specifies the encoding used to decode the file.
+  This token is used to encode the output of untokenize back to bytes.
+
+What's New in Python 3.0a3?
+===========================
+
+*Release date: 29-Feb-2008*
+
+Core and Builtins
+-----------------
+
+- Issue #2282: io.TextIOWrapper was not overriding seekable() from io.IOBase.
+
+- Issue #2115: Important speedup in setting __slot__ attributes.  Also 
+  prevent a possible crash: an Abstract Base Class would try to access a slot 
+  on a registered virtual subclass.
+
+- Fixed repr() and str() of complex numbers with infinity or nan as real or
+  imaginary part.
+
+- Clear all free list during a gc.collect() of the highest generation in order
+  to allow pymalloc to free more arenas. Python may give back memory to the
+  OS earlier.
+
+- Issue #2045: Fix an infinite recursion triggered when printing a subclass of
+  collections.defaultdict, if its default_factory is set to a bound method.
+
+- Fixed a minor memory leak in dictobject.c. The content of the free
+  list was not freed on interpreter shutdown.
+
+- Limit free list of method and builtin function objects to 256 entries
+  each.
+
+- Patch #1953: Added ``sys._compact_freelists()`` and the C API functions
+  ``PyInt_CompactFreeList`` and ``PyFloat_CompactFreeList``
+  to compact the internal free lists of pre-allocted ints and floats.
+
+- Bug #1983: Fixed return type of fork(), fork1() and forkpty() calls.
+  Python expected the return type int but the fork familie returns pi_t.
+
+- Issue #1678380: Fix a bug that identifies 0j and -0j when they appear
+  in the same code unit.
+
+- Issue #2025 :  Add tuple.count() and tuple.index() methods to comply with
+  the collections.Sequence API.
+
+- Fixed multiple reinitialization of the Python interpreter. The small int
+  list in longobject.c has caused a seg fault during the third finalization.
+
+- Issue #1973: bytes.fromhex('') raises SystemError
+
+- Issue #1771: remove cmp parameter from sorted() and list.sort()
+
+- Issue #1969: split and rsplit in bytearray are inconsistent
+
+- map() and no longer accepts None for the first argument.
+  Use zip() instead.
+
+- Issue #1769: Now int("- 1") is not allowed any more.
+
+- Object/longobject.c: long(float('nan')) raises an OverflowError instead
+  of returning 0.
+
+- Issue #1762972: __file__ points to the source file instead of the pyc/pyo
+  file if the py file exists.
+
+- Issue #1393: object_richcompare() returns NotImplemented instead of
+  False if the objects aren't equal, to give the other side a chance.
+
+- Issue #1692: Interpreter was not displaying location of SyntaxError.
+
+- Improve some exception messages when Windows fails to load an extension
+  module. Now we get for example '%1 is not a valid Win32 application' instead
+  of 'error code 193'.  Also use Unicode strings to deal with non-English
+  locales.
+
+- Issue #1587: Added instancemethod wrapper for PyCFunctions. The Python C API
+  has gained a new type *PyInstanceMethod_Type* and the functions
+  *PyInstanceMethod_Check(o)*, *PyInstanceMethod_New(func)* and
+  *PyInstanceMethod_Function(im)*.
+
+- Constants gc.DEBUG_OBJECT and gc.DEBUG_INSTANCE have been removed from the
+  gc module; gc.DEBUG_COLLECTABLE or gc.DEBUG_UNCOLLECTABLE are now enough to
+  print the corresponding list of objects considered by the garbage collector.
+
+- Issue #1573: Improper use of the keyword-only syntax makes the parser crash.
+
+- Issue #1564: The set implementation should special-case PyUnicode instead
+  of PyString.
+
+- Patch #1031213: Decode source line in SyntaxErrors back to its
+  original source encoding.
+
+- inspect.getsource() includes the decorators again.
+
+- Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a
+  mountpoint.
+
+- Fix utf-8-sig incremental decoder, which didn't recognise a BOM when the
+  first chunk fed to the decoder started with a BOM, but was longer than 3
+  bytes.
+
+
+Extension Modules
+-----------------
+
+- Code for itertools ifilter(), imap(), and izip() moved to bultins and
+  renamed to filter(), map(), and zip().  Also, renamed izip_longest()
+  to zip_longest() and ifilterfalse() to filterfalse().
+
+- Issue #1762972: Readded the reload() function as imp.reload()
+
+- Bug #2111: mmap segfaults when trying to write a block opened with PROT_READ
+
+- #2063: correct order of utime and stime in os.times() result on Windows.
+
+
+Library
+-------
+
+- Weakref dictionaries now inherit from MutableMapping.
+  XXX their API still needs to be modernized (i.e. eliminate the iter methods).
+
+- Created new UserDict class in collections module.  This one inherits from and
+  complies with the MutableMapping ABC.  Also, moved UserString and UserList
+  to the collections module.  The MutableUserString class was removed.
+
+- Removed UserDict.DictMixin.  Replaced all its uses with
+  collections.MutableMapping.
+
+- Issue #1703: getpass() should flush after writing prompt.
+
+- Issue #1585: IDLE uses non-existent xrange() function.
+
+- Issue #1578: Problems in win_getpass.
+
+Build
+-----
+
+- Renamed --enable-unicode configure flag to --with-wide-unicode, since
+  Unicode strings can't be disabled anymore.
+
+
+C API
+-----
+
+- Issue #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE,
+  Py_TYPE and Py_REFCNT.
+
+- New API PyImport_ImportModuleNoBlock(), works like PyImport_ImportModule()
+  but won't block on the import lock (returning an error instead).
+
+
 What's New in Python 3.0a2?
+===========================
+
+*Release date: 07-Dec-2007*
+
+(Note: this list is incomplete.)
+
+Core and Builtins
+-----------------
+
+- str8 now has the same construction signature as bytes.
+
+- Comparisons between str and str8 now return False/True for ==/!=.  sqlite3
+  returns str8 when recreating on object from it's __conform__ value.  The
+  struct module returns str8 for all string-related formats.  This was true
+  before this change, but becomes more apparent thanks to string comparisons
+  always being False.
+
+- Replaced `PyFile_FromFile()` with `PyFile_FromFd(fd, name. mode, buffer, 
+  encoding, newline)`
+
+- Fixed `imp.find_module()` to obey the -*- coding: -*- header.
+
+- Changed `__file__` and `co_filename` to unicode. The path names are decoded
+  with `Py_FileSystemDefaultEncoding` and a new API method 
+  `PyUnicode_DecodeFSDefault(char*)` was added.
+
+- io.open() and _fileio.FileIO have grown a new argument closefd. A false
+  value disables the closing of the file descriptor.
+
+- Added a new option -b to issues warnings (-bb for errors) about certain
+  operations between bytes/buffer and str like str(b'') and comparsion.
+
+- The standards streams sys.stdin, stdout and stderr may be None when the
+  when the C runtime library returns an invalid file descriptor for the
+  streams (fileno(stdin) < 0). For now this happens only for Windows GUI
+  apps and scripts started with `pythonw.exe`.
+
+- Added PCbuild9 directory for VS 2008.
+
+- Renamed structmember.h WRITE_RESTRICTED to PY_WRITE_RESTRICTED to work
+  around a name clash with VS 2008 on Windows.
+
+- Unbound methods are gone for good. ClassObject.method returns an ordinary
+  function object, instance.method still returns a bound method object.
+  The API of bound methods is cleaned up, too. The im_class attribute is
+  removed and im_func + im_self are renamed to __func__ and __self__. The
+  factory PyMethod_New takes only func and instance as argument.
+
+- intobject.h is no longer included by Python.h. The remains were moved
+  to longobject.h. It still exists to define several aliases from PyInt_
+  to PyLong_ functions.
+
+- Removed sys.maxint, use sys.maxsize instead.
 
-*Unreleased*
 
 Extension Modules
 -----------------
@@ -21,13 +271,20 @@
   argument was being ignored if __loader__ is defined and forcing the source to
   be UTF-8.
 
+- The methods `os.tmpnam()`, `os.tempnam()` and `os.tmpfile()` have been
+  removed in favor of the tempfile module.
+
+- Removed the 'new' module.
+
+- Removed all types from the 'types' module that are easily accessable through
+  builtins.
+
 
 What's New in Python 3.0a1?
 ==========================
 
 *Release date: 31-Aug-2007*
 
-
 Core and Builtins
 -----------------
 
@@ -252,6 +509,9 @@
 Tests
 -----
 
+- Removed test.testall as test.regrtest replaces it.
+
+
 Documentation
 -------------
 

Modified: python/branches/py3k-importlib/Misc/Vim/python.vim
==============================================================================
--- python/branches/py3k-importlib/Misc/Vim/python.vim	(original)
+++ python/branches/py3k-importlib/Misc/Vim/python.vim	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,4 @@
-" Auto-generated Vim syntax file for Python
+" Auto-generated Vim syntax file for Python (trunk: r60376M).
 "
 " To use: copy or symlink to ~/.vim/syntax/python.vim
 
@@ -63,7 +63,7 @@
 
 if exists("python_highlight_builtins")
   syn keyword pythonBuiltin    Ellipsis False None NotImplemented True __debug__
-  syn keyword pythonBuiltin    __import__ abs all any basestring bool
+  syn keyword pythonBuiltin    __import__ abs all any bool
   syn keyword pythonBuiltin    buffer callable chr classmethod cmp
   syn keyword pythonBuiltin    complex copyright credits delattr dict
   syn keyword pythonBuiltin    dir divmod enumerate eval exec exit
@@ -73,7 +73,8 @@
   syn keyword pythonBuiltin    max min object oct open ord pow property quit
   syn keyword pythonBuiltin    range reload repr reversed round
   syn keyword pythonBuiltin    set setattr slice sorted staticmethod str sum
-  syn keyword pythonBuiltin    super tuple type unichr unicode vars zip
+  syn keyword pythonBuiltin    super trunc tuple type unicode vars 
+  syn keyword pythonBuiltin    zip
 
 endif
 

Modified: python/branches/py3k-importlib/Misc/Vim/syntax_test.py
==============================================================================
--- python/branches/py3k-importlib/Misc/Vim/syntax_test.py	(original)
+++ python/branches/py3k-importlib/Misc/Vim/syntax_test.py	Thu Mar 27 00:48:05 2008
@@ -4,9 +4,8 @@
 Not necessarily sensical or comprehensive (assume that if one exception is
 highlighted that all are, for instance).
 
-Highlighting extraneous whitespace at the end of the line is not represented
-here as all trailing whitespace is automatically removed from .py files in the
-repository.
+Extraneous trailing whitespace can't be tested because of svn pre-commit hook
+checks for such things.
 
 """
 # Comment

Modified: python/branches/py3k-importlib/Misc/Vim/vim_syntax.py
==============================================================================
--- python/branches/py3k-importlib/Misc/Vim/vim_syntax.py	(original)
+++ python/branches/py3k-importlib/Misc/Vim/vim_syntax.py	Thu Mar 27 00:48:05 2008
@@ -4,10 +4,11 @@
 
 import keyword
 import exceptions
-import __builtin__
+import builtins
 from string import Template
+from sys import subversion
 
-comment_header = '''" Auto-generated Vim syntax file for Python.
+comment_header = '''" Auto-generated Vim syntax file for Python (%s: r%s).
 "
 " To use: copy or symlink to ~/.vim/syntax/python.vim'''
 
@@ -39,7 +40,7 @@
 # nothing that comes with modules (e.g., __name__), so just exclude anything in
 # the 'exceptions' module since we want to ignore exceptions *and* what any
 # module would have
-builtin_names = sorted(builtin for builtin in dir(__builtin__)
+builtin_names = sorted(builtin for builtin in dir(builtins)
                             if builtin not in dir(exceptions))
 
 escapes = (r'+\\[abfnrtv\'"\\]+', r'"\\\o\{1,3}"', r'"\\x\x\{2}"',
@@ -162,7 +163,7 @@
 def main(file_path):
     with open(file_path, 'w') as FILE:
         # Comment for file
-        print>>FILE, comment_header
+        print>>FILE, comment_header % subversion[1:]
         print>>FILE, ''
         # Statements at start of file
         print>>FILE, statement_header

Modified: python/branches/py3k-importlib/Misc/Vim/vimrc
==============================================================================
--- python/branches/py3k-importlib/Misc/Vim/vimrc	(original)
+++ python/branches/py3k-importlib/Misc/Vim/vimrc	Thu Mar 27 00:48:05 2008
@@ -41,10 +41,12 @@
 " Use the below highlight group when displaying bad whitespace is desired
 highlight BadWhitespace ctermbg=red guibg=red
 
-" Display tabs at the beginning of a line in Python mode as bad
+" Display tabs at the beginning of a line in Python mode as bad.
 " Should be done for C code, but not until all code has been moved to 4-space
 "   indents.
 au BufRead,BufNewFile *.py,*.pyw match BadWhitespace /^\t\+/
+" Make trailing whitespace be flagged as bad.
+au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
 
 " Wrap text after a certain number of characters
 " Python: 79 
@@ -86,12 +88,3 @@
 " Keep indentation level from previous line: ``set autoindent``
 
 " Folding based on indentation: ``set foldmethod=indent``
-
-" Make trailing whitespace explicit (left off since this will automatically
-" insert the highlight or characters *as you type*, which can get annoying):
-"``match BadWhitespace /\s\+$/``
-"
-" or, for a non-colored, character-based solution:
-"
-"``set list listchars=trail:-``
-

Modified: python/branches/py3k-importlib/Misc/build.sh
==============================================================================
--- python/branches/py3k-importlib/Misc/build.sh	(original)
+++ python/branches/py3k-importlib/Misc/build.sh	Thu Mar 27 00:48:05 2008
@@ -67,7 +67,7 @@
 # Note: test_XXX (none currently) really leak, but are disabled
 # so we don't send spam.  Any test which really leaks should only 
 # be listed here if there are also test cases under Lib/test/leakers.
-LEAKY_TESTS="test_(cmd_line|popen2|socket|threading_local|urllib2_localnet)"
+LEAKY_TESTS="test_(asynchat|cmd_line|popen2|socket|smtplib|sys|threadsignals|urllib2_localnet)"
 
 # These tests always fail, so skip them so we don't get false positives.
 _ALWAYS_SKIP=""
@@ -92,6 +92,24 @@
     echo "<li><a href=\"$2\">$1</a> <font size=\"-1\">($time seconds)</font></li>" >> $RESULT_FILE
 }
 
+place_summary_first() {
+    testf=$1
+    sed -n '/^[0-9][0-9]* tests OK\./,$p' < $testf \
+        | egrep -v '\[[0-9]+ refs\]' > $testf.tmp
+    echo "" >> $testf.tmp
+    cat $testf >> $testf.tmp
+    mv $testf.tmp $testf
+}
+
+count_failures () {
+    testf=$1
+    n=`grep -ic " failed:" $testf`
+    if [ $n -eq 1 ] ; then
+        n=`grep " failed:" $testf | sed -e 's/ .*//'`
+    fi
+    echo $n
+}
+
 mail_on_failure() {
     if [ "$NUM_FAILURES" != "0" ]; then
         dest=$FAILURE_MAILTO
@@ -99,7 +117,17 @@
         if [ "$FAILURE_CC" != "" ]; then
             dest="$dest -c $FAILURE_CC"
         fi
-        mutt -s "$FAILURE_SUBJECT $1 ($NUM_FAILURES)" $dest < $2
+        if [ "x$3" != "x" ] ; then
+            (echo "More important issues:"
+             echo "----------------------"
+             egrep -v "$3" < $2
+             echo ""
+             echo "Less important issues:"
+             echo "----------------------"
+             egrep "$3" < $2)
+        else
+            cat $2
+        fi | mutt -s "$FAILURE_SUBJECT $1 ($NUM_FAILURES)" $dest
     fi
 }
 
@@ -176,15 +204,17 @@
             ## make and run basic tests
             F=make-test.out
             start=`current_time`
-            $PYTHON $REGRTEST_ARGS $ALWAYS_SKIP >& build/$F
-            NUM_FAILURES=`grep -ic " failed:" build/$F`
+            $PYTHON $REGRTEST_ARGS -u urlfetch >& build/$F
+            NUM_FAILURES=`count_failures build/$F`
+            place_summary_first build/$F
             update_status "Testing basics ($NUM_FAILURES failures)" "$F" $start
             mail_on_failure "basics" build/$F
 
             F=make-test-opt.out
             start=`current_time`
-            $PYTHON -O $REGRTEST_ARGS $ALWAYS_SKIP >& build/$F
-            NUM_FAILURES=`grep -ic " failed:" build/$F`
+            $PYTHON -O $REGRTEST_ARGS -u urlfetch >& build/$F
+            NUM_FAILURES=`count_failures build/$F`
+            place_summary_first build/$F
             update_status "Testing opt ($NUM_FAILURES failures)" "$F" $start
             mail_on_failure "opt" build/$F
 
@@ -193,10 +223,12 @@
             start=`current_time`
             ## ensure that the reflog exists so the grep doesn't fail
             touch $REFLOG
-            $PYTHON $REGRTEST_ARGS -R 4:3:$REFLOG -u network $LEAKY_SKIPS >& build/$F
-            NUM_FAILURES=`egrep -vc "($LEAKY_TESTS|sum=0)" $REFLOG`
+            $PYTHON $REGRTEST_ARGS -R 4:3:$REFLOG -u network,urlfetch $LEAKY_SKIPS >& build/$F
+            LEAK_PAT="($LEAKY_TESTS|sum=0)"
+            NUM_FAILURES=`egrep -vc "$LEAK_PAT" $REFLOG`
+            place_summary_first build/$F
             update_status "Testing refleaks ($NUM_FAILURES failures)" "$F" $start
-            mail_on_failure "refleak" $REFLOG
+            mail_on_failure "refleak" $REFLOG "$LEAK_PAT"
 
             ## now try to run all the tests
             F=make-testall.out
@@ -204,7 +236,8 @@
             ## skip curses when running from cron since there's no terminal
             ## skip sound since it's not setup on the PSF box (/dev/dsp)
             $PYTHON $REGRTEST_ARGS -uall -x test_curses test_linuxaudiodev test_ossaudiodev $_ALWAYS_SKIP >& build/$F
-            NUM_FAILURES=`grep -ic " failed:" build/$F`
+            NUM_FAILURES=`count_failures build/$F`
+            place_summary_first build/$F
             update_status "Testing all except curses and sound ($NUM_FAILURES failures)" "$F" $start
             mail_on_failure "all" build/$F
         fi

Modified: python/branches/py3k-importlib/Misc/cheatsheet
==============================================================================
--- python/branches/py3k-importlib/Misc/cheatsheet	(original)
+++ python/branches/py3k-importlib/Misc/cheatsheet	Thu Mar 27 00:48:05 2008
@@ -561,8 +561,8 @@
 i          Signed integer decimal.
 o          Unsigned octal.
 u          Unsigned decimal.
-x          Unsigned hexidecimal (lowercase).
-X          Unsigned hexidecimal (uppercase).
+x          Unsigned hexadecimal (lowercase).
+X          Unsigned hexadecimal (uppercase).
 e          Floating point exponential format (lowercase).
 E          Floating point exponential format (uppercase).
 f          Floating point decimal format.

Modified: python/branches/py3k-importlib/Misc/developers.txt
==============================================================================
--- python/branches/py3k-importlib/Misc/developers.txt	(original)
+++ python/branches/py3k-importlib/Misc/developers.txt	Thu Mar 27 00:48:05 2008
@@ -17,6 +17,29 @@
 Permissions History
 -------------------
 
+- Jerry Seutter was given SVN access on 20 March 2008 by BAC, for
+  general contributions to Python.
+
+- Jeff Rush was given SVN access on 18 March 2008 by AMK, for Distutils work.
+
+- David Wolever was given SVN access on 17 March 2008 by MvL,
+  for 2to3 work.
+
+- Trent Nelson was given SVN access on 17 March 2008 by MvL,
+  for general contributions to Python.
+
+- Mark Dickinson was given SVN access on 6 January 2008 by Facundo
+  Batista for his work on mathemathics and number related issues.
+
+- Amaury Forgeot d'Arc was given SVN access on 9 November 2007 by MvL,
+  for general contributions to Python.
+
+- Christian Heimes was given SVN access on 31 October 2007 by MvL,
+  for general contributions to Python.
+
+- Chris Monson was given SVN access on 20 October 2007 by NCN,
+  for his work on editing PEPs.
+
 - Bill Janssen was given SVN access on 28 August 2007 by NCN,
   for his work on the SSL module and other things related to (SSL) sockets.
 

Modified: python/branches/py3k-importlib/Misc/python-mode.el
==============================================================================
--- python/branches/py3k-importlib/Misc/python-mode.el	(original)
+++ python/branches/py3k-importlib/Misc/python-mode.el	Thu Mar 27 00:48:05 2008
@@ -2,7 +2,8 @@
 
 ;; Copyright (C) 1992,1993,1994  Tim Peters
 
-;; Author: 1995-2002 Barry A. Warsaw
+;; Author: 2003-2007 http://sf.net/projects/python-mode
+;;         1995-2002 Barry A. Warsaw
 ;;         1992-1994 Tim Peters
 ;; Maintainer: python-mode at python.org
 ;; Created:    Feb 1992
@@ -19,19 +20,38 @@
 
 ;;; Commentary:
 
-;; This is a major mode for editing Python programs.  It was developed
-;; by Tim Peters after an original idea by Michael A. Guravage.  Tim
-;; subsequently left the net; in 1995, Barry Warsaw inherited the mode
-;; and is the current maintainer.  Tim's now back but disavows all
-;; responsibility for the mode.  Smart Tim :-)
+;; This is a major mode for editing Python programs.  It was developed by Tim
+;; Peters after an original idea by Michael A. Guravage.  Tim subsequently
+;; left the net and in 1995, Barry Warsaw inherited the mode.  Tim's now back
+;; but disavows all responsibility for the mode.  In fact, we suspect he
+;; doesn't even use Emacs any more.  In 2003, python-mode.el was moved to its
+;; own SourceForge project apart from the Python project, and now is
+;; maintained by the volunteers at the python-mode at python.org mailing list.
 
-;; pdbtrack support contributed by Ken Manheimer, April 2001.
+;; pdbtrack support contributed by Ken Manheimer, April 2001.  Skip Montanaro
+;; has also contributed significantly to python-mode's development.
 
 ;; Please use the SourceForge Python project to submit bugs or
 ;; patches:
 ;;
 ;;     http://sourceforge.net/projects/python
 
+;; INSTALLATION:
+
+;; To install, just drop this file into a directory on your load-path and
+;; byte-compile it.  To set up Emacs to automatically edit files ending in
+;; ".py" using python-mode add the following to your ~/.emacs file (GNU
+;; Emacs) or ~/.xemacs/init.el file (XEmacs):
+;;    (setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist))
+;;    (setq interpreter-mode-alist (cons '("python" . python-mode)
+;;                                       interpreter-mode-alist))
+;;    (autoload 'python-mode "python-mode" "Python editing mode." t)
+;;
+;; In XEmacs syntax highlighting should be enabled automatically.  In GNU
+;; Emacs you may have to add these lines to your ~/.emacs file:
+;;    (global-font-lock-mode t)
+;;    (setq font-lock-maximum-decoration t)
+
 ;; FOR MORE INFORMATION:
 
 ;; There is some information on python-mode.el at
@@ -60,6 +80,7 @@
 (require 'custom)
 (require 'cl)
 (require 'compile)
+(require 'ansi-color)
 
 
 ;; user definable variables
@@ -70,34 +91,41 @@
   :group 'languages
   :prefix "py-")
 
+(defcustom py-tab-always-indent t
+  "*Non-nil means TAB in Python mode should always reindent the current line,
+regardless of where in the line point is when the TAB command is used."
+  :type 'boolean
+  :group 'python)
+
 (defcustom py-python-command "python"
   "*Shell command used to start Python interpreter."
   :type 'string
   :group 'python)
 
-(defcustom py-jpython-command "jpython"
-  "*Shell command used to start the JPython interpreter."
+(make-obsolete-variable 'py-jpython-command 'py-jython-command)
+(defcustom py-jython-command "jython"
+  "*Shell command used to start the Jython interpreter."
   :type 'string
   :group 'python
-  :tag "JPython Command")
+  :tag "Jython Command")
 
 (defcustom py-default-interpreter 'cpython
   "*Which Python interpreter is used by default.
-The value for this variable can be either `cpython' or `jpython'.
+The value for this variable can be either `cpython' or `jython'.
 
 When the value is `cpython', the variables `py-python-command' and
 `py-python-command-args' are consulted to determine the interpreter
 and arguments to use.
 
-When the value is `jpython', the variables `py-jpython-command' and
-`py-jpython-command-args' are consulted to determine the interpreter
+When the value is `jython', the variables `py-jython-command' and
+`py-jython-command-args' are consulted to determine the interpreter
 and arguments to use.
 
 Note that this variable is consulted only the first time that a Python
 mode buffer is visited during an Emacs session.  After that, use
 \\[py-toggle-shells] to change the interpreter shell."
   :type '(choice (const :tag "Python (a.k.a. CPython)" cpython)
-		 (const :tag "JPython" jpython))
+		 (const :tag "Jython" jython))
   :group 'python)
 
 (defcustom py-python-command-args '("-i")
@@ -105,11 +133,12 @@
   :type '(repeat string)
   :group 'python)
 
-(defcustom py-jpython-command-args '("-i")
-  "*List of string arguments to be used when starting a JPython shell."
+(make-obsolete-variable 'py-jpython-command-args 'py-jython-command-args)
+(defcustom py-jython-command-args '("-i")
+  "*List of string arguments to be used when starting a Jython shell."
   :type '(repeat string)
   :group 'python
-  :tag "JPython Command Args")
+  :tag "Jython Command Args")
 
 (defcustom py-indent-offset 4
   "*Amount of offset per level of indentation.
@@ -248,7 +277,7 @@
   :type 'function
   :group 'python)
 
-(defcustom py-imenu-show-method-args-p nil 
+(defcustom py-imenu-show-method-args-p nil
   "*Controls echoing of arguments of functions & methods in the Imenu buffer.
 When non-nil, arguments are printed."
   :type 'boolean
@@ -275,19 +304,20 @@
   20000
   "Maximum number of characters to search for a Java-ish import statement.
 When `python-mode' tries to calculate the shell to use (either a
-CPython or a JPython shell), it looks at the so-called `shebang' line
+CPython or a Jython shell), it looks at the so-called `shebang' line
 -- i.e. #! line.  If that's not available, it looks at some of the
 file heading imports to see if they look Java-like."
   :type 'integer
   :group 'python
   )
 
-(defcustom py-jpython-packages
+(make-obsolete-variable 'py-jpython-packages 'py-jython-packages)
+(defcustom py-jython-packages
   '("java" "javax" "org" "com")
-  "Imported packages that imply `jpython-mode'."
+  "Imported packages that imply `jython-mode'."
   :type '(repeat string)
   :group 'python)
-  
+
 ;; Not customizable
 (defvar py-master-file nil
   "If non-nil, execute the named file instead of the buffer's file.
@@ -317,16 +347,39 @@
   :tag "Pychecker Command Args")
 
 (defvar py-shell-alist
-  '(("jpython" . 'jpython)
-    ("jython" . 'jpython)
+  '(("jython" . 'jython)
     ("python" . 'cpython))
   "*Alist of interpreters and python shells. Used by `py-choose-shell'
 to select the appropriate python interpreter mode for a file.")
 
+(defcustom py-shell-input-prompt-1-regexp "^>>> "
+  "*A regular expression to match the input prompt of the shell."
+  :type 'string
+  :group 'python)
+
+(defcustom py-shell-input-prompt-2-regexp "^[.][.][.] "
+  "*A regular expression to match the input prompt of the shell after the
+  first line of input."
+  :type 'string
+  :group 'python)
+
+(defcustom py-shell-switch-buffers-on-execute t
+  "*Controls switching to the Python buffer where commands are
+  executed.  When non-nil the buffer switches to the Python buffer, if
+  not no switching occurs."
+  :type 'boolean
+  :group 'python)
+
 
 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 ;; NO USER DEFINABLE VARIABLES BEYOND THIS POINT
 
+(defvar py-line-number-offset 0
+  "When an exception occurs as a result of py-execute-region, a
+subsequent py-up-exception needs the line number where the region
+started, in order to jump to the correct file line.  This variable is
+set in py-execute-region and used in py-jump-to-exception.")
+
 (defconst py-emacs-features
   (let (features)
    features)
@@ -339,9 +392,31 @@
   "Face for pseudo keywords in Python mode, like self, True, False, Ellipsis.")
 (make-face 'py-pseudo-keyword-face)
 
+;; PEP 318 decorators
+(defvar py-decorators-face 'py-decorators-face
+  "Face method decorators.")
+(make-face 'py-decorators-face)
+
+;; Face for builtins
+(defvar py-builtins-face 'py-builtins-face
+  "Face for builtins like TypeError, object, open, and exec.")
+(make-face 'py-builtins-face)
+
+;; XXX, TODO, and FIXME comments and such
+(defvar py-XXX-tag-face 'py-XXX-tag-face
+  "Face for XXX, TODO, and FIXME tags")
+(make-face 'py-XXX-tag-face)
+
 (defun py-font-lock-mode-hook ()
   (or (face-differs-from-default-p 'py-pseudo-keyword-face)
-      (copy-face 'font-lock-keyword-face 'py-pseudo-keyword-face)))
+      (copy-face 'font-lock-keyword-face 'py-pseudo-keyword-face))
+  (or (face-differs-from-default-p 'py-builtins-face)
+      (copy-face 'font-lock-keyword-face 'py-builtins-face))
+  (or (face-differs-from-default-p 'py-decorators-face)
+      (copy-face 'py-pseudo-keyword-face 'py-decorators-face))
+  (or (face-differs-from-default-p 'py-XXX-tag-face)
+      (copy-face 'font-lock-comment-face 'py-XXX-tag-face))
+  )
 (add-hook 'font-lock-mode-hook 'py-font-lock-mode-hook)
 
 (defvar python-font-lock-keywords
@@ -352,7 +427,7 @@
 			  "from"     "global"   "if"      "import"
 			  "in"       "is"       "lambda"  "not"
 			  "or"       "pass"     "print"   "raise"
-			  "return"   "while"    "yield"
+			  "return"   "while"    "with"    "yield"
 			  )
 			"\\|"))
 	(kw2 (mapconcat 'identity
@@ -391,26 +466,52 @@
 			  "super" "tuple" "type" "unichr" "unicode" "vars"
 			  "zip")
 			"\\|"))
+	(kw4 (mapconcat 'identity
+			;; Exceptions and warnings
+			'("ArithmeticError" "AssertionError"
+			  "AttributeError" "DeprecationWarning" "EOFError"
+			  "EnvironmentError" "Exception"
+			  "FloatingPointError" "FutureWarning" "IOError"
+			  "ImportError" "IndentationError" "IndexError"
+			  "KeyError" "KeyboardInterrupt" "LookupError"
+			  "MemoryError" "NameError" "NotImplemented"
+			  "NotImplementedError" "OSError" "OverflowError"
+			  "OverflowWarning" "PendingDeprecationWarning"
+			  "ReferenceError" "RuntimeError" "RuntimeWarning"
+			  "StandardError" "StopIteration" "SyntaxError"
+			  "SyntaxWarning" "SystemError" "SystemExit"
+			  "TabError" "TypeError" "UnboundLocalError"
+			  "UnicodeDecodeError" "UnicodeEncodeError"
+			  "UnicodeError" "UnicodeTranslateError"
+			  "UserWarning" "ValueError" "Warning"
+			  "ZeroDivisionError")
+			"\\|"))
 	)
     (list
+     '("^[ \t]*\\(@.+\\)" 1 'py-decorators-face)
      ;; keywords
-     (cons (concat "\\b\\(" kw1 "\\)\\b[ \n\t(]") 1)
+     (cons (concat "\\<\\(" kw1 "\\)\\>[ \n\t(]") 1)
      ;; builtins when they don't appear as object attributes
-     (cons (concat "\\(\\b\\|[.]\\)\\(" kw3 "\\)\\b[ \n\t(]") 2)
+     (list (concat "\\([^. \t]\\|^\\)[ \t]*\\<\\(" kw3 "\\)\\>[ \n\t(]") 2
+	   'py-builtins-face)
      ;; block introducing keywords with immediately following colons.
      ;; Yes "except" is in both lists.
-     (cons (concat "\\b\\(" kw2 "\\)[ \n\t(]") 1)
-     ;; `as' but only in "import foo as bar"
-     '("[ \t]*\\(\\bfrom\\b.*\\)?\\bimport\\b.*\\b\\(as\\)\\b" . 2)
+     (cons (concat "\\<\\(" kw2 "\\)[ \n\t(]") 1)
+     ;; Exceptions
+     (list (concat "\\<\\(" kw4 "\\)[ \n\t:,(]") 1 'py-builtins-face)
+     ;; `as' but only in "import foo as bar" or "with foo as bar"
+     '("[ \t]*\\(\\<from\\>.*\\)?\\<import\\>.*\\<\\(as\\)\\>" . 2)
+     '("[ \t]*\\<with\\>.*\\<\\(as\\)\\>" . 1)
      ;; classes
-     '("\\bclass[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"
-       1 font-lock-type-face)
+     '("\\<class[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)" 1 font-lock-type-face)
      ;; functions
-     '("\\bdef[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"
+     '("\\<def[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"
        1 font-lock-function-name-face)
      ;; pseudo-keywords
-     '("\\b\\(self\\|None\\|True\\|False\\|Ellipsis\\)\\b"
+     '("\\<\\(self\\|None\\|True\\|False\\|Ellipsis\\)\\>"
        1 py-pseudo-keyword-face)
+     ;; XXX, TODO, and FIXME tags
+     '("XXX\\|TODO\\|FIXME" 0 py-XXX-tag-face t)
      ))
   "Additional expressions to highlight in Python mode.")
 (put 'python-mode 'font-lock-defaults '(python-font-lock-keywords))
@@ -421,13 +522,7 @@
 Currently-active file is at the head of the list.")
 
 (defvar py-pdbtrack-is-tracking-p nil)
-(defvar py-pdbtrack-last-grubbed-buffer nil
-  "Record of the last buffer used when the source path was invalid.
 
-This buffer is consulted before the buffer-list history for satisfying
-`py-pdbtrack-grub-for-buffer', since it's the most often the likely
-prospect as debugging continues.")
-(make-variable-buffer-local 'py-pdbtrack-last-grubbed-buffer)
 (defvar py-pychecker-history nil)
 
 
@@ -461,7 +556,7 @@
    "\\(" "[^#'\"\n\\]" "\\|" py-stringlit-re "\\)*"
    "\\\\$")
   "Regular expression matching Python backslash continuation lines.")
-  
+
 (defconst py-blank-or-comment-re "[ \t]*\\($\\|#\\)"
   "Regular expression matching a blank or comment line.")
 
@@ -474,7 +569,7 @@
 			   "\\|")
 	  "\\)")
   "Regular expression matching statements to be dedented one level.")
-  
+
 (defconst py-block-closing-keywords-re
   "\\(return\\|raise\\|break\\|continue\\|pass\\)"
   "Regular expression matching keywords which typically close a block.")
@@ -495,30 +590,17 @@
 	  "\\)")
   "Regular expression matching lines not to dedent after.")
 
-(defconst py-defun-start-re
-  "^\\([ \t]*\\)def[ \t]+\\([a-zA-Z_0-9]+\\)\\|\\(^[a-zA-Z_0-9]+\\)[ \t]*="
-  ;; If you change this, you probably have to change py-current-defun
-  ;; as well.  This is only used by py-current-defun to find the name
-  ;; for add-log.el.
-  "Regular expression matching a function, method, or variable assignment.")
-
-(defconst py-class-start-re "^class[ \t]*\\([a-zA-Z_0-9]+\\)"
-  ;; If you change this, you probably have to change py-current-defun
-  ;; as well.  This is only used by py-current-defun to find the name
-  ;; for add-log.el.
-  "Regular expression for finding a class name.")
-
-(defconst py-traceback-line-re
+(defvar py-traceback-line-re
   "[ \t]+File \"\\([^\"]+\\)\", line \\([0-9]+\\)"
   "Regular expression that describes tracebacks.")
 
-;; pdbtrack contants
+;; pdbtrack constants
 (defconst py-pdbtrack-stack-entry-regexp
 ;  "^> \\([^(]+\\)(\\([0-9]+\\))\\([?a-zA-Z0-9_]+\\)()"
   "^> \\(.*\\)(\\([0-9]+\\))\\([?a-zA-Z0-9_]+\\)()"
   "Regular expression pdbtrack uses to find a stack trace entry.")
 
-(defconst py-pdbtrack-input-prompt "\n[(<]*pdb[>)]+ "
+(defconst py-pdbtrack-input-prompt "\n[(<]*[Pp]db[>)]+ "
   "Regular expression pdbtrack uses to recognize a pdb prompt.")
 
 (defconst py-pdbtrack-track-range 10000
@@ -536,8 +618,9 @@
 (defvar python-mode-hook nil
   "*Hook called by `python-mode'.")
 
-(defvar jpython-mode-hook nil
-  "*Hook called by `jpython-mode'. `jpython-mode' also calls
+(make-obsolete-variable 'jpython-mode-hook 'jython-mode-hook)
+(defvar jython-mode-hook nil
+  "*Hook called by `jython-mode'. `jython-mode' also calls
 `python-mode-hook'.")
 
 (defvar py-shell-hook nil
@@ -560,8 +643,6 @@
   (define-key py-mode-map "\C-c\C-r"  'py-shift-region-right)
   (define-key py-mode-map "\C-c<"     'py-shift-region-left)
   (define-key py-mode-map "\C-c>"     'py-shift-region-right)
-  ;; paragraph and string filling
-  (define-key py-mode-map "\eq"       'py-fill-paragraph)
   ;; subprocess commands
   (define-key py-mode-map "\C-c\C-c"  'py-execute-buffer)
   (define-key py-mode-map "\C-c\C-m"  'py-execute-import-or-reload)
@@ -624,7 +705,7 @@
   ;; expect RET to do a `py-newline-and-indent' and any Emacsers who
   ;; dislike this are probably knowledgeable enough to do a rebind.
   ;; However, we do *not* change C-j since many Emacsers have already
-  ;; swapped RET and C-j and they don't want C-j bound to `newline' to 
+  ;; swapped RET and C-j and they don't want C-j bound to `newline' to
   ;; change.
   (define-key py-mode-map "\C-m" 'py-newline-and-indent)
   )
@@ -740,8 +821,8 @@
     (cond
      ((eq position 'bol) (beginning-of-line))
      ((eq position 'eol) (end-of-line))
-     ((eq position 'bod) (py-beginning-of-def-or-class))
-     ((eq position 'eod) (py-end-of-def-or-class))
+     ((eq position 'bod) (py-beginning-of-def-or-class 'either))
+     ((eq position 'eod) (py-end-of-def-or-class 'either))
      ;; Kind of funny, I know, but useful for py-up-exception.
      ((eq position 'bob) (beginning-of-buffer))
      ((eq position 'eob) (end-of-buffer))
@@ -849,7 +930,7 @@
 
 (defvar py-imenu-method-regexp
   (concat                               ; <<methods and functions>>
-   "\\("                                ; 
+   "\\("                                ;
    "^[ \t]*"                            ; new line and maybe whitespace
    "\\(def[ \t]+"                       ; function definitions start with def
    "\\([a-zA-Z0-9_]+\\)"                ;   name is here
@@ -885,7 +966,7 @@
 ;; it.
 (defvar py-imenu-generic-expression
   (cons
-   (concat 
+   (concat
     py-imenu-class-regexp
     "\\|"				; or...
     py-imenu-method-regexp
@@ -954,7 +1035,7 @@
 	looking-p
 	def-name prev-name
 	cur-indent def-pos
-	(class-paren (first  py-imenu-generic-parens)) 
+	(class-paren (first  py-imenu-generic-parens))
 	(def-paren   (second py-imenu-generic-parens)))
     (setq looking-p
 	  (re-search-forward py-imenu-generic-regexp (point-max) t))
@@ -1009,7 +1090,7 @@
 			  (cons save-elmt sub-method-alist))
 		    index-alist))))
        ;; found less indented expression, we're done.
-       (t 
+       (t
 	(setq looking-p nil)
 	(re-search-backward py-imenu-generic-regexp (point-min) t)))
       ;; end-cond
@@ -1023,7 +1104,7 @@
 
 
 (defun py-choose-shell-by-shebang ()
-  "Choose CPython or JPython mode by looking at #! on the first line.
+  "Choose CPython or Jython mode by looking at #! on the first line.
 Returns the appropriate mode function.
 Used by `py-choose-shell', and similar to but distinct from
 `set-auto-mode', though it uses `auto-mode-interpreter-regexp' (if available)."
@@ -1047,10 +1128,10 @@
 
 
 (defun py-choose-shell-by-import ()
-  "Choose CPython or JPython mode based imports.
-If a file imports any packages in `py-jpython-packages', within
+  "Choose CPython or Jython mode based imports.
+If a file imports any packages in `py-jython-packages', within
 `py-import-check-point-max' characters from the start of the file,
-return `jpython', otherwise return nil."
+return `jython', otherwise return nil."
   (let (mode)
     (save-excursion
       (goto-char (point-min))
@@ -1058,14 +1139,14 @@
 		  (search-forward-regexp
 		   "^\\(\\(from\\)\\|\\(import\\)\\) \\([^ \t\n.]+\\)"
 		   py-import-check-point-max t))
-	(setq mode (and (member (match-string 4) py-jpython-packages)
-			'jpython
+	(setq mode (and (member (match-string 4) py-jython-packages)
+			'jython
 			))))
     mode))
 
 
 (defun py-choose-shell ()
-  "Choose CPython or JPython mode. Returns the appropriate mode function.
+  "Choose CPython or Jython mode. Returns the appropriate mode function.
 This does the following:
  - look for an interpreter with `py-choose-shell-by-shebang'
  - examine imports using `py-choose-shell-by-import'
@@ -1114,6 +1195,7 @@
   (make-local-variable 'indent-region-function)
   (make-local-variable 'indent-line-function)
   (make-local-variable 'add-log-current-defun-function)
+  (make-local-variable 'fill-paragraph-function)
   ;;
   (set-syntax-table py-mode-syntax-table)
   (setq major-mode              'python-mode
@@ -1132,6 +1214,8 @@
 	indent-line-function    'py-indent-line
 	;; tell add-log.el how to find the current function/method/variable
 	add-log-current-defun-function 'py-current-defun
+
+	fill-paragraph-function 'py-fill-paragraph
 	)
   (use-local-map py-mode-map)
   ;; add the menu
@@ -1171,17 +1255,18 @@
     (py-toggle-shells (py-choose-shell))))
 
 
-(defun jpython-mode ()
-  "Major mode for editing JPython/Jython files.
+(make-obsolete 'jpython-mode 'jython-mode)
+(defun jython-mode ()
+  "Major mode for editing Jython/Jython files.
 This is a simple wrapper around `python-mode'.
-It runs `jpython-mode-hook' then calls `python-mode.'
+It runs `jython-mode-hook' then calls `python-mode.'
 It is added to `interpreter-mode-alist' and `py-choose-shell'.
 "
   (interactive)
   (python-mode)
-  (py-toggle-shells 'jpython)
-  (when jpython-mode-hook
-      (run-hooks 'jpython-mode-hook)))
+  (py-toggle-shells 'jython)
+  (when jython-mode-hook
+      (run-hooks 'jython-mode-hook)))
 
 
 ;; It's handy to add recognition of Python files to the
@@ -1189,16 +1274,16 @@
 ;; can specify different `derived-modes' based on the #! line, but
 ;; with the latter, we can't.  So we just won't add them if they're
 ;; already added.
-(let ((modes '(("jpython" . jpython-mode)
-	       ("jython" . jpython-mode)
+;;;###autoload
+(let ((modes '(("jython" . jython-mode)
 	       ("python" . python-mode))))
   (while modes
     (when (not (assoc (car modes) interpreter-mode-alist))
       (push (car modes) interpreter-mode-alist))
     (setq modes (cdr modes))))
-
+;;;###autoload
 (when (not (or (rassq 'python-mode auto-mode-alist)
-	       (rassq 'jpython-mode auto-mode-alist)))
+	       (rassq 'jython-mode auto-mode-alist)))
   (push '("\\.py$" . python-mode) auto-mode-alist))
 
 
@@ -1283,12 +1368,13 @@
 (defun py-comint-output-filter-function (string)
   "Watch output for Python prompt and exec next file waiting in queue.
 This function is appropriate for `comint-output-filter-functions'."
-  ;; TBD: this should probably use split-string
-  (when (and (or (string-equal string ">>> ")
-		 (and (>= (length string) 5)
-		      (string-equal (substring string -5) "\n>>> ")))
-	     py-file-queue)
-    (pop-to-buffer (current-buffer))
+  ;;remove ansi terminal escape sequences from string, not sure why they are
+  ;;still around...
+  (setq string (ansi-color-filter-apply string))
+  (when (and (string-match py-shell-input-prompt-1-regexp string)
+                   py-file-queue)
+    (if py-shell-switch-buffers-on-execute
+      (pop-to-buffer (current-buffer)))
     (py-safe (delete-file (car py-file-queue)))
     (setq py-file-queue (cdr py-file-queue))
     (if py-file-queue
@@ -1344,7 +1430,7 @@
                                            (- procmark
                                               py-pdbtrack-track-range))
                                       procmark))
-             target target_fname target_lineno)
+             target target_fname target_lineno target_buffer)
 
         (if (not (string-match (concat py-pdbtrack-input-prompt "$") block))
             (py-pdbtrack-overlay-arrow nil)
@@ -1372,8 +1458,7 @@
 We look first to visit the file indicated in the trace.
 
 Failing that, we look for the most recently visited python-mode buffer
-with the same name or having 
-having the named function.
+with the same name or having the named function.
 
 If we're unable find the source code we return a string describing the
 problem as best as we can determine."
@@ -1417,11 +1502,10 @@
 (defun py-pdbtrack-grub-for-buffer (funcname lineno)
   "Find most recent buffer itself named or having function funcname.
 
-We first check the last buffer this function found, if any, then walk
-throught the buffer-list history for python-mode buffers that are
+We walk the buffer-list history for python-mode buffers that are
 named for funcname or define a function funcname."
   (let ((buffers (buffer-list))
-        curbuf
+        buf
         got)
     (while (and buffers (not got))
       (setq buf (car buffers)
@@ -1436,7 +1520,7 @@
                                    (buffer-substring (point-min)
                                                      (point-max))))))
           (setq got buf)))
-    (setq py-pdbtrack-last-grubbed-buffer got)))
+    got))
 
 (defun py-postprocess-output-buffer (buf)
   "Highlight exceptions found in BUF.
@@ -1466,7 +1550,7 @@
 (defconst py-output-buffer "*Python Output*")
 (make-variable-buffer-local 'py-output-buffer)
 
-;; for toggling between CPython and JPython
+;; for toggling between CPython and Jython
 (defvar py-which-shell nil)
 (defvar py-which-args  py-python-command-args)
 (defvar py-which-bufname "Python")
@@ -1475,14 +1559,14 @@
 (make-variable-buffer-local 'py-which-bufname)
 
 (defun py-toggle-shells (arg)
-  "Toggles between the CPython and JPython shells.
+  "Toggles between the CPython and Jython shells.
 
 With positive argument ARG (interactively \\[universal-argument]),
-uses the CPython shell, with negative ARG uses the JPython shell, and
+uses the CPython shell, with negative ARG uses the Jython shell, and
 with a zero argument, toggles the shell.
 
 Programmatically, ARG can also be one of the symbols `cpython' or
-`jpython', equivalent to positive arg and negative arg respectively."
+`jython', equivalent to positive arg and negative arg respectively."
   (interactive "P")
   ;; default is to toggle
   (if (null arg)
@@ -1495,7 +1579,7 @@
 	(setq arg -1)
       (setq arg 1)))
    ((equal arg 'cpython) (setq arg 1))
-   ((equal arg 'jpython) (setq arg -1)))
+   ((equal arg 'jython) (setq arg -1)))
   (let (msg)
     (cond
      ((< 0 arg)
@@ -1503,14 +1587,16 @@
       (setq py-which-shell py-python-command
 	    py-which-args py-python-command-args
 	    py-which-bufname "Python"
-	    msg "CPython"
-	    mode-name "Python"))
+	    msg "CPython")
+      (if (string-equal py-which-bufname "Jython")
+	  (setq mode-name "Python")))
      ((> 0 arg)
-      (setq py-which-shell py-jpython-command
-	    py-which-args py-jpython-command-args
-	    py-which-bufname "JPython"
-	    msg "JPython"
-	    mode-name "JPython"))
+      (setq py-which-shell py-jython-command
+	    py-which-args py-jython-command-args
+	    py-which-bufname "Jython"
+	    msg "Jython")
+      (if (string-equal py-which-bufname "Python")
+	  (setq mode-name "Jython")))
      )
     (message "Using the %s shell" msg)
     (setq py-output-buffer (format "*%s Output*" py-which-bufname))))
@@ -1532,9 +1618,9 @@
 programmatically, or when running in Emacs 19.34 or older.
 
 Note: You can toggle between using the CPython interpreter and the
-JPython interpreter by hitting \\[py-toggle-shells].  This toggles
+Jython interpreter by hitting \\[py-toggle-shells].  This toggles
 buffer local variables which control whether all your subshell
-interactions happen to the `*JPython*' or `*Python*' buffers (the
+interactions happen to the `*Jython*' or `*Python*' buffers (the
 latter is the name used for the CPython buffer).
 
 Warning: Don't use an interactive Python if you change sys.ps1 or
@@ -1568,10 +1654,14 @@
 			       (concat
 				(mapconcat 'identity py-which-args " ") " ")
 			       ))))
-    (switch-to-buffer-other-window
-     (apply 'make-comint py-which-bufname py-which-shell nil args))
+    (if (not (equal (buffer-name) "*Python*"))
+        (switch-to-buffer-other-window
+         (apply 'make-comint py-which-bufname py-which-shell nil args))
+      (apply 'make-comint py-which-bufname py-which-shell nil args))
     (make-local-variable 'comint-prompt-regexp)
-    (setq comint-prompt-regexp "^>>> \\|^[.][.][.] \\|^(pdb) ")
+    (setq comint-prompt-regexp (concat py-shell-input-prompt-1-regexp "\\|"
+                                       py-shell-input-prompt-2-regexp "\\|"
+                                       "^([Pp]db) "))
     (add-hook 'comint-output-filter-functions
 	      'py-comint-output-filter-function)
     ;; pdbtrack
@@ -1642,11 +1732,13 @@
       (setq start (point))
       (or (< start end)
 	  (error "Region is empty"))
+      (setq py-line-number-offset (count-lines 1 start))
       (let ((needs-if (/= (py-point 'bol) (py-point 'boi))))
 	(set-buffer buf)
 	(python-mode)
 	(when needs-if
-	  (insert "if 1:\n"))
+	  (insert "if 1:\n")
+	  (setq py-line-number-offset (- py-line-number-offset 1)))
 	(insert-buffer-substring cur start end)
 	;; Set the shell either to the #! line command, or to the
 	;; py-which-shell buffer local variable.
@@ -1683,8 +1775,9 @@
       (setq py-exception-buffer (cons file (current-buffer))))
      (t
       ;; TBD: a horrible hack, but why create new Custom variables?
-      (let ((cmd (concat shell (if (string-equal py-which-bufname "JPython")
-				   " -" ""))))
+      (let ((cmd (concat py-which-shell (if (string-equal py-which-bufname
+							  "Jython")
+					    " -" ""))))
 	;; otherwise either run it synchronously in a subprocess
 	(save-excursion
 	  (set-buffer buf)
@@ -1718,12 +1811,14 @@
 See the `\\[py-execute-region]' docs for an account of some
 subtleties, including the use of the optional ASYNC argument."
   (interactive "P")
-  (if py-master-file
-      (let* ((filename (expand-file-name py-master-file))
-	     (buffer (or (get-file-buffer filename)
-			 (find-file-noselect filename))))
-	(set-buffer buffer)))
-  (py-execute-region (point-min) (point-max) async))
+  (let ((old-buffer (current-buffer)))
+    (if py-master-file
+        (let* ((filename (expand-file-name py-master-file))
+               (buffer (or (get-file-buffer filename)
+                           (find-file-noselect filename))))
+          (set-buffer buffer)))
+    (py-execute-region (point-min) (point-max) async)
+       (pop-to-buffer old-buffer)))
 
 (defun py-execute-import-or-reload (&optional async)
   "Import the current buffer's file in a Python interpreter.
@@ -1819,6 +1914,9 @@
 		      (t (find-file (read-file-name "Exception file: "
 						    nil
 						    file t))))))
+    ;; Fiddle about with line number
+    (setq line (+ py-line-number-offset line))
+
     (pop-to-buffer buffer)
     ;; Force Python mode
     (if (not (eq major-mode 'python-mode))
@@ -1999,16 +2097,29 @@
   (interactive "P")
   (let* ((ci (current-indentation))
 	 (move-to-indentation-p (<= (current-column) ci))
-	 (need (py-compute-indentation (not arg))))
-    ;; see if we need to dedent
-    (if (py-outdent-p)
-	(setq need (- need py-indent-offset)))
-    (if (/= ci need)
-	(save-excursion
-	  (beginning-of-line)
-	  (delete-horizontal-space)
-	  (indent-to need)))
-    (if move-to-indentation-p (back-to-indentation))))
+	 (need (py-compute-indentation (not arg)))
+         (cc (current-column)))
+    ;; dedent out a level if previous command was the same unless we're in
+    ;; column 1
+    (if (and (equal last-command this-command)
+             (/= cc 0))
+        (progn
+          (beginning-of-line)
+          (delete-horizontal-space)
+          (indent-to (* (/ (- cc 1) py-indent-offset) py-indent-offset)))
+      (progn
+	;; see if we need to dedent
+	(if (py-outdent-p)
+	    (setq need (- need py-indent-offset)))
+	(if (or py-tab-always-indent
+		move-to-indentation-p)
+	    (progn (if (/= ci need)
+		       (save-excursion
+		       (beginning-of-line)
+		       (delete-horizontal-space)
+		       (indent-to need)))
+		   (if move-to-indentation-p (back-to-indentation)))
+	    (insert-tab))))))
 
 (defun py-newline-and-indent ()
   "Strives to act like the Emacs `newline-and-indent'.
@@ -2052,39 +2163,23 @@
        ((py-continuation-line-p)
 	(let ((startpos (point))
 	      (open-bracket-pos (py-nesting-level))
-	      endpos searching found state)
+	      endpos searching found state cind cline)
 	  (if open-bracket-pos
 	      (progn
-		;; align with first item in list; else a normal
-		;; indent beyond the line with the open bracket
-		(goto-char (1+ open-bracket-pos)) ; just beyond bracket
-		;; is the first list item on the same line?
-		(skip-chars-forward " \t")
-		(if (null (memq (following-char) '(?\n ?# ?\\)))
-					; yes, so line up with it
-		    (current-column)
-		  ;; first list item on another line, or doesn't exist yet
-		  (forward-line 1)
-		  (while (and (< (point) startpos)
-			      (looking-at "[ \t]*[#\n\\\\]")) ; skip noise
-		    (forward-line 1))
-		  (if (and (< (point) startpos)
-			   (/= startpos
-			       (save-excursion
-				 (goto-char (1+ open-bracket-pos))
-				 (forward-comment (point-max))
-				 (point))))
-		      ;; again mimic the first list item
-		      (current-indentation)
-		    ;; else they're about to enter the first item
-		    (goto-char open-bracket-pos)
-		    (setq placeholder (point))
-		    (py-goto-initial-line)
-		    (py-goto-beginning-of-tqs
-		     (save-excursion (nth 3 (parse-partial-sexp
-					     placeholder (point)))))
-		    (+ (current-indentation) py-indent-offset))))
-
+		(setq endpos (py-point 'bol))
+		(py-goto-initial-line)
+		(setq cind (current-indentation))
+		(setq cline cind)
+		(dolist (bp 
+			 (nth 9 (save-excursion
+				  (parse-partial-sexp (point) endpos)))
+			 cind)
+		  (if (search-forward "\n" bp t) (setq cline cind))
+		  (goto-char (1+ bp))
+		  (skip-chars-forward " \t")
+		  (setq cind (if (memq (following-char) '(?\n ?# ?\\))
+				 (+ cline py-indent-offset)
+			       (current-column)))))
 	    ;; else on backslash continuation line
 	    (forward-line -1)
 	    (if (py-continuation-line-p) ; on at least 3rd line in block
@@ -2832,7 +2927,7 @@
 ;; ripped from cc-mode
 (defun py-forward-into-nomenclature (&optional arg)
   "Move forward to end of a nomenclature section or word.
-With \\[universal-argument] (programmatically, optional argument ARG), 
+With \\[universal-argument] (programmatically, optional argument ARG),
 do it that many times.
 
 A `nomenclature' is a fancy way of saying AWordWithMixedCaseNotUnderscores."
@@ -2886,6 +2981,11 @@
 
 
 ;; Pychecker
+
+;; hack for FSF Emacs
+(unless (fboundp 'read-shell-command)
+  (defalias 'read-shell-command 'read-string))
+
 (defun py-pychecker-run (command)
   "*Run pychecker (default on the file currently visited)."
   (interactive
@@ -3410,7 +3510,7 @@
 
 (defun py-statement-opens-block-p ()
   "Return t iff the current statement opens a block.
-I.e., iff it ends with a colon that is not in a comment.  Point should 
+I.e., iff it ends with a colon that is not in a comment.  Point should
 be at the start of a statement."
   (save-excursion
     (let ((start (point))
@@ -3494,8 +3594,8 @@
 KEY is a regular expression describing a Python keyword.  Skip blank
 lines and non-indenting comments.  If the statement found starts with
 KEY, then stop, otherwise go back to first enclosing block starting
-with KEY.  If successful, leave point at the start of the KEY line and 
-return t.  Otherwise, leav point at an undefined place and return nil."
+with KEY.  If successful, leave point at the start of the KEY line and
+return t.  Otherwise, leave point at an undefined place and return nil."
   ;; skip blanks and non-indenting #
   (py-goto-initial-line)
   (while (and
@@ -3503,7 +3603,7 @@
 	  (zerop (forward-line -1)))	; go back
     nil)
   (py-goto-initial-line)
-  (let* ((re (concat "[ \t]*" key "\\b"))
+  (let* ((re (concat "[ \t]*" key "\\>"))
 	 (case-fold-search nil)		; let* so looking-at sees this
 	 (found (looking-at re))
 	 (dead nil))
@@ -3529,7 +3629,7 @@
 `Keyword' is defined (essentially) as the regular expression
 ([a-z]+).  Returns nil if none was found."
   (let ((case-fold-search nil))
-    (if (looking-at "[ \t]*\\([a-z]+\\)\\b")
+    (if (looking-at "[ \t]*\\([a-z]+\\)\\>")
 	(intern (buffer-substring (match-beginning 1) (match-end 1)))
       nil)))
 
@@ -3537,14 +3637,49 @@
   "Python value for `add-log-current-defun-function'.
 This tells add-log.el how to find the current function/method/variable."
   (save-excursion
-    (if (re-search-backward py-defun-start-re nil t)
-	(or (match-string 3)
-	    (let ((method (match-string 2)))
-	      (if (and (not (zerop (length (match-string 1))))
-		       (re-search-backward py-class-start-re nil t))
-		  (concat (match-string 1) "." method)
-		method)))
-      nil)))
+
+    ;; Move back to start of the current statement.
+
+    (py-goto-initial-line)
+    (back-to-indentation)
+    (while (and (or (looking-at py-blank-or-comment-re)
+		    (py-in-literal))
+		(not (bobp)))
+      (backward-to-indentation 1))
+    (py-goto-initial-line)
+
+    (let ((scopes "")
+	  (sep "")
+	  dead assignment)
+
+      ;; Check for an assignment.  If this assignment exists inside a
+      ;; def, it will be overwritten inside the while loop.  If it
+      ;; exists at top lever or inside a class, it will be preserved.
+
+      (when (looking-at "[ \t]*\\([a-zA-Z0-9_]+\\)[ \t]*=")
+	(setq scopes (buffer-substring (match-beginning 1) (match-end 1)))
+	(setq assignment t)
+	(setq sep "."))
+
+      ;; Prepend the name of each outer socpe (def or class).
+
+      (while (not dead)
+	(if (and (py-go-up-tree-to-keyword "\\(class\\|def\\)")
+		 (looking-at
+		  "[ \t]*\\(class\\|def\\)[ \t]*\\([a-zA-Z0-9_]+\\)[ \t]*"))
+	    (let ((name (buffer-substring (match-beginning 2) (match-end 2))))
+	      (if (and assignment (looking-at "[ \t]*def"))
+		  (setq scopes name)
+		(setq scopes (concat name sep scopes))
+		(setq sep "."))))
+	(setq assignment nil)
+	(condition-case nil		; Terminate nicely at top level.
+	    (py-goto-block-up 'no-mark)
+	  (error (setq dead t))))
+      (if (string= scopes "")
+	  nil
+	scopes))))
+
 
 
 (defconst py-help-address "python-mode at python.org"
@@ -3586,7 +3721,7 @@
      "Dear Barry,")			;salutation
     (if enhancement-p nil
       (set-mark (point))
-      (insert 
+      (insert
 "Please replace this text with a sufficiently large code sample\n\
 and an exact recipe so that I can reproduce your problem.  Failure\n\
 to do so may mean a greater delay in fixing your bug.\n\n")
@@ -3606,7 +3741,7 @@
 (add-hook 'comint-output-filter-functions 'py-pdbtrack-track-stack-file)
 
 ;; Add a designator to the minor mode strings
-(or (assq 'py-pdbtrack-minor-mode-string minor-mode-alist)
+(or (assq 'py-pdbtrack-is-tracking-p minor-mode-alist)
     (push '(py-pdbtrack-is-tracking-p py-pdbtrack-minor-mode-string)
 	  minor-mode-alist))
 
@@ -3745,20 +3880,35 @@
 If point is inside a string, narrow to that string and fill.
 "
   (interactive "P")
-  (let* ((bod (py-point 'bod))
-	 (pps (parse-partial-sexp bod (point))))
-    (cond
-     ;; are we inside a comment or on a line with only whitespace before
-     ;; the comment start?
-     ((or (nth 4 pps)
-	  (save-excursion (beginning-of-line) (looking-at "[ \t]*#")))
-      (py-fill-comment justify))
-     ;; are we inside a string?
-     ((nth 3 pps)
-      (py-fill-string (nth 8 pps)))
-     ;; otherwise use the default
-     (t
-      (fill-paragraph justify)))))
+  ;; fill-paragraph will narrow incorrectly
+  (save-restriction
+    (widen)
+    (let* ((bod (py-point 'bod))
+	   (pps (parse-partial-sexp bod (point))))
+      (cond
+       ;; are we inside a comment or on a line with only whitespace before
+       ;; the comment start?
+       ((or (nth 4 pps)
+	    (save-excursion (beginning-of-line) (looking-at "[ \t]*#")))
+	(py-fill-comment justify))
+       ;; are we inside a string?
+       ((nth 3 pps)
+	(py-fill-string (nth 8 pps)))
+       ;; are we at the opening quote of a string, or in the indentation?
+       ((save-excursion
+	  (forward-word 1)
+	  (eq (py-in-literal) 'string))
+	(save-excursion
+	  (py-fill-string (py-point 'boi))))
+       ;; are we at or after the closing quote of a string?
+       ((save-excursion
+	  (backward-word 1)
+	  (eq (py-in-literal) 'string))
+	(save-excursion
+	  (py-fill-string (py-point 'boi))))
+       ;; otherwise use the default
+       (t
+	(fill-paragraph justify))))))
 
 
 

Modified: python/branches/py3k-importlib/Modules/Setup.dist
==============================================================================
--- python/branches/py3k-importlib/Modules/Setup.dist	(original)
+++ python/branches/py3k-importlib/Modules/Setup.dist	Thu Mar 27 00:48:05 2008
@@ -116,6 +116,7 @@
 _sre _sre.c			# Fredrik Lundh's new regular expressions
 _codecs _codecsmodule.c		# access to the builtin codecs and codec registry
 _fileio _fileio.c		# Standard I/O baseline
+_weakref _weakref.c		# weak references
 
 # The zipimport module is always imported at startup. Having it as a
 # builtin module avoids some bootstrapping problems and reduces overhead.

Modified: python/branches/py3k-importlib/Modules/_bisectmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_bisectmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/_bisectmodule.c	Thu Mar 27 00:48:05 2008
@@ -48,7 +48,7 @@
 	index = internal_bisect_right(list, item, lo, hi);
 	if (index < 0)
 		return NULL;
-	return PyInt_FromLong(index);
+	return PyLong_FromLong(index);
 }
 
 PyDoc_STRVAR(bisect_right_doc,
@@ -145,7 +145,7 @@
 	index = internal_bisect_left(list, item, lo, hi);
 	if (index < 0)
 		return NULL;
-	return PyInt_FromLong(index);
+	return PyLong_FromLong(index);
 }
 
 PyDoc_STRVAR(bisect_left_doc,

Modified: python/branches/py3k-importlib/Modules/_bsddb.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_bsddb.c	(original)
+++ python/branches/py3k-importlib/Modules/_bsddb.c	Thu Mar 27 00:48:05 2008
@@ -87,20 +87,15 @@
 
 #include <stddef.h>   /* for offsetof() */
 #include <Python.h>
-#include <db.h>
 
-/* --------------------------------------------------------------------- */
-/* Various macro definitions */
-
-/* 40 = 4.0, 33 = 3.3; this will break if the second number is > 9 */
-#define DBVER (DB_VERSION_MAJOR * 10 + DB_VERSION_MINOR)
-#if DB_VERSION_MINOR > 9
-#error "eek! DBVER can't handle minor versions > 9"
-#endif
+#define COMPILING_BSDDB_C
+#include "bsddb.h"
+#undef COMPILING_BSDDB_C
 
-#define PY_BSDDB_VERSION "4.5.0"
 static char *svn_id = "$Id$";
 
+/* --------------------------------------------------------------------- */
+/* Various macro definitions */
 
 #if (PY_VERSION_HEX < 0x02050000)
 typedef int Py_ssize_t;
@@ -196,117 +191,25 @@
 /* --------------------------------------------------------------------- */
 /* Structure definitions */
 
-#if PYTHON_API_VERSION >= 1010       /* python >= 2.1 support weak references */
-#define HAVE_WEAKREF
-#else
-#undef HAVE_WEAKREF
-#endif
-
-/* if Python >= 2.1 better support warnings */
-#if PYTHON_API_VERSION >= 1010
-#define HAVE_WARNINGS
-#else
-#undef HAVE_WARNINGS
+#if PYTHON_API_VERSION < 1010
+#error "Python 2.1 or later required"
 #endif
 
-#if PYTHON_API_VERSION <= 1007
-    /* 1.5 compatibility */
-#define PyObject_New PyObject_NEW
-#define PyObject_Del PyMem_DEL
-#endif
-
-struct behaviourFlags {
-    /* What is the default behaviour when DB->get or DBCursor->get returns a
-       DB_NOTFOUND || DB_KEYEMPTY error?  Return None or raise an exception? */
-    unsigned int getReturnsNone : 1;
-    /* What is the default behaviour for DBCursor.set* methods when DBCursor->get
-     * returns a DB_NOTFOUND || DB_KEYEMPTY  error?  Return None or raise? */
-    unsigned int cursorSetReturnsNone : 1;
-};
 
+/* Defaults for moduleFlags in DBEnvObject and DBObject. */
 #define DEFAULT_GET_RETURNS_NONE                1
 #define DEFAULT_CURSOR_SET_RETURNS_NONE         1   /* 0 in pybsddb < 4.2, python < 2.4 */
 
-typedef struct {
-    PyObject_HEAD
-    DB_ENV*     db_env;
-    u_int32_t   flags;             /* saved flags from open() */
-    int         closed;
-    struct behaviourFlags moduleFlags;
-#ifdef HAVE_WEAKREF
-    PyObject        *in_weakreflist; /* List of weak references */
-#endif
-} DBEnvObject;
-
-
-typedef struct {
-    PyObject_HEAD
-    DB*             db;
-    DBEnvObject*    myenvobj;  /* PyObject containing the DB_ENV */
-    u_int32_t       flags;     /* saved flags from open() */
-    u_int32_t       setflags;  /* saved flags from set_flags() */
-    int             haveStat;
-    struct behaviourFlags moduleFlags;
-#if (DBVER >= 33)
-    PyObject*       associateCallback;
-    PyObject*       btCompareCallback;
-    int             primaryDBType;
-#endif
-#ifdef HAVE_WEAKREF
-    PyObject        *in_weakreflist; /* List of weak references */
-#endif
-} DBObject;
-
-
-typedef struct {
-    PyObject_HEAD
-    DBC*            dbc;
-    DBObject*       mydb;
-#ifdef HAVE_WEAKREF
-    PyObject        *in_weakreflist; /* List of weak references */
-#endif
-} DBCursorObject;
-
-
-typedef struct {
-    PyObject_HEAD
-    DB_TXN*         txn;
-    PyObject        *env;
-#ifdef HAVE_WEAKREF
-    PyObject        *in_weakreflist; /* List of weak references */
-#endif
-} DBTxnObject;
-
-
-typedef struct {
-    PyObject_HEAD
-    DB_LOCK         lock;
-#ifdef HAVE_WEAKREF
-    PyObject        *in_weakreflist; /* List of weak references */
-#endif
-} DBLockObject;
-
-#if (DBVER >= 43)
-typedef struct {
-    PyObject_HEAD
-    DB_SEQUENCE*     sequence;
-    DBObject*        mydb;
-#ifdef HAVE_WEAKREF
-    PyObject        *in_weakreflist; /* List of weak references */
-#endif
-} DBSequenceObject;
-static PyTypeObject DBSequence_Type;
-#endif
 
 static PyTypeObject DB_Type, DBCursor_Type, DBEnv_Type, DBTxn_Type, DBLock_Type;
 
-#define DBObject_Check(v)           (Py_Type(v) == &DB_Type)
-#define DBCursorObject_Check(v)     (Py_Type(v) == &DBCursor_Type)
-#define DBEnvObject_Check(v)        (Py_Type(v) == &DBEnv_Type)
-#define DBTxnObject_Check(v)        (Py_Type(v) == &DBTxn_Type)
-#define DBLockObject_Check(v)       (Py_Type(v) == &DBLock_Type)
+#define DBObject_Check(v)           (Py_TYPE(v) == &DB_Type)
+#define DBCursorObject_Check(v)     (Py_TYPE(v) == &DBCursor_Type)
+#define DBEnvObject_Check(v)        (Py_TYPE(v) == &DBEnv_Type)
+#define DBTxnObject_Check(v)        (Py_TYPE(v) == &DBTxn_Type)
+#define DBLockObject_Check(v)       (Py_TYPE(v) == &DBLock_Type)
 #if (DBVER >= 43)
-#define DBSequenceObject_Check(v)   (Py_Type(v) == &DBSequence_Type)
+#define DBSequenceObject_Check(v)   (Py_TYPE(v) == &DBSequence_Type)
 #endif
 
 
@@ -409,10 +312,9 @@
                         "Py_buffer malloc failed");
         return NULL;
     }
-    /* XXX(gps): PyBUF_LOCKDATA is desired to prevent other theads from
-       trashing the data buffer while we release the GIL during the db
-       operation.  see http://bugs.python.org/issue1035 */
-    if (PyObject_GetBuffer(obj, view, PyBUF_SIMPLE) == -1) {
+    /* We use PyBUF_LOCK to prevent other threads from trashing the data
+       buffer while we release the GIL.  http://bugs.python.org/issue1035 */
+    if (PyObject_GetBuffer(obj, view, PyBUF_LOCK) == -1) {
         PyMem_Free(view);
         return NULL;
     }
@@ -491,7 +393,7 @@
         /* no need to do anything, the structure has already been zeroed */
     }
 
-    else if (PyInt_Check(keyobj)) {
+    else if (PyLong_Check(keyobj)) {
         /* verify access method type */
         type = _DB_get_type(self);
         if (type == -1)
@@ -510,7 +412,7 @@
 
         /* Make a key out of the requested recno, use allocated space so DB
          * will be able to realloc room for the real key if needed. */
-        recno = PyInt_AS_LONG(keyobj);
+        recno = PyLong_AS_LONG(keyobj);
         key->data = malloc(sizeof(db_recno_t));
         if (key->data == NULL) {
             PyErr_SetString(PyExc_MemoryError, "Key memory allocation failed");
@@ -536,15 +438,29 @@
         if ( !(view = _malloc_view(keyobj)) )
             return 0;
 
-        key->data = view->buf;
+        /*
+         * NOTE(gps): I don't like doing a data copy here, it seems
+         * wasteful.  But without a clean way to tell FREE_DBT if it
+         * should free key->data or not we have to.  Other places in
+         * the code check for DB_THREAD and forceably set DBT_MALLOC
+         * when we otherwise would leave flags 0 to indicate that.
+         */
         key->size = Py_SAFE_DOWNCAST(view->len, Py_ssize_t, u_int32_t);
+        key->data = malloc(key->size);
+        if (key->data == NULL) {
+            PyErr_SetString(PyExc_MemoryError, "Key memory allocation failed");
+            key->size = 0;
+            return 0;
+        }
+        memcpy(key->data, view->buf, key->size);
+        key->flags = DB_DBT_REALLOC;
         *returned_view_p = view;
     }
 
     else {
         PyErr_Format(PyExc_TypeError,
                      "buffer or int object expected for key, %s found",
-                     Py_Type(keyobj)->tp_name);
+                     Py_TYPE(keyobj)->tp_name);
         return 0;
     }
 
@@ -628,12 +544,7 @@
                 strncat(errTxt, _db_errmsg, bytes_left);
             }
             _db_errmsg[0] = 0;
-#ifdef HAVE_WARNINGS
             exceptionRaised = PyErr_WarnEx(PyExc_RuntimeWarning, errTxt, 1);
-#else
-            fprintf(stderr, errTxt);
-            fprintf(stderr, "\n");
-#endif
 
 #else  /* do an exception instead */
         errObj = DBIncompleteError;
@@ -699,7 +610,7 @@
 static void makeTypeError(char* expected, PyObject* found)
 {
     PyErr_Format(PyExc_TypeError, "Expected %s argument, %s found.",
-                 expected, Py_Type(found)->tp_name);
+                 expected, Py_TYPE(found)->tp_name);
 }
 
 
@@ -826,7 +737,7 @@
 /* add an integer to a dictionary using the given name as a key */
 static void _addIntToDict(PyObject* dict, char *name, int value)
 {
-    PyObject* v = PyInt_FromLong((long) value);
+    PyObject* v = PyLong_FromLong((long) value);
     if (!v || PyDict_SetItemString(dict, name, v))
         PyErr_Clear();
 
@@ -843,7 +754,7 @@
 		v = PyLong_FromLongLong((PY_LONG_LONG) value);
 	else
 #endif
-		v = PyInt_FromLong((long) value);
+		v = PyLong_FromLong((long) value);
     if (!v || PyDict_SetItemString(dict, name, v))
         PyErr_Clear();
 
@@ -887,9 +798,7 @@
     self->btCompareCallback = NULL;
     self->primaryDBType = 0;
 #endif
-#ifdef HAVE_WEAKREF
     self->in_weakreflist = NULL;
-#endif
 
     /* keep a reference to our python DBEnv object */
     if (arg) {
@@ -940,21 +849,17 @@
             MYDB_BEGIN_ALLOW_THREADS;
             self->db->close(self->db, 0);
             MYDB_END_ALLOW_THREADS;
-#ifdef HAVE_WARNINGS
         } else {
             PyErr_WarnEx(PyExc_RuntimeWarning,
 			 "DB could not be closed in destructor:"
 			 " DBEnv already closed",
 			 1);
-#endif
         }
         self->db = NULL;
     }
-#ifdef HAVE_WEAKREF
     if (self->in_weakreflist != NULL) {
         PyObject_ClearWeakRefs((PyObject *) self);
     }
-#endif
     if (self->myenvobj) {
         Py_DECREF(self->myenvobj);
         self->myenvobj = NULL;
@@ -982,9 +887,7 @@
 
     self->dbc = dbc;
     self->mydb = db;
-#ifdef HAVE_WEAKREF
     self->in_weakreflist = NULL;
-#endif
     Py_INCREF(self->mydb);
     return self;
 }
@@ -995,14 +898,11 @@
 {
     int err;
 
-#ifdef HAVE_WEAKREF
     if (self->in_weakreflist != NULL) {
         PyObject_ClearWeakRefs((PyObject *) self);
     }
-#endif
 
     if (self->dbc != NULL) {
-        MYDB_BEGIN_ALLOW_THREADS;
 	/* If the underlying database has been closed, we don't
 	   need to do anything. If the environment has been closed
 	   we need to leak, as BerkeleyDB will crash trying to access
@@ -1011,9 +911,14 @@
 	   a database open. */
 	if (self->mydb->db && self->mydb->myenvobj &&
 	    !self->mydb->myenvobj->closed)
+        /* test for: open db + no environment or non-closed environment */
+	if (self->mydb->db && (!self->mydb->myenvobj || (self->mydb->myenvobj &&
+	    !self->mydb->myenvobj->closed))) {
+            MYDB_BEGIN_ALLOW_THREADS;
             err = self->dbc->c_close(self->dbc);
+            MYDB_END_ALLOW_THREADS;
+        }
         self->dbc = NULL;
-        MYDB_END_ALLOW_THREADS;
     }
     Py_XDECREF( self->mydb );
     PyObject_Del(self);
@@ -1032,9 +937,7 @@
     self->flags = flags;
     self->moduleFlags.getReturnsNone = DEFAULT_GET_RETURNS_NONE;
     self->moduleFlags.cursorSetReturnsNone = DEFAULT_CURSOR_SET_RETURNS_NONE;
-#ifdef HAVE_WEAKREF
     self->in_weakreflist = NULL;
-#endif
 
     MYDB_BEGIN_ALLOW_THREADS;
     err = db_env_create(&self->db_env, flags);
@@ -1053,11 +956,9 @@
 static void
 DBEnv_dealloc(DBEnvObject* self)
 {
-#ifdef HAVE_WEAKREF
     if (self->in_weakreflist != NULL) {
         PyObject_ClearWeakRefs((PyObject *) self);
     }
-#endif
 
     if (self->db_env && !self->closed) {
         MYDB_BEGIN_ALLOW_THREADS;
@@ -1077,9 +978,7 @@
         return NULL;
     Py_INCREF(myenv);
     self->env = (PyObject*)myenv;
-#ifdef HAVE_WEAKREF
     self->in_weakreflist = NULL;
-#endif
 
     MYDB_BEGIN_ALLOW_THREADS;
 #if (DBVER >= 40)
@@ -1100,13 +999,10 @@
 static void
 DBTxn_dealloc(DBTxnObject* self)
 {
-#ifdef HAVE_WEAKREF
     if (self->in_weakreflist != NULL) {
         PyObject_ClearWeakRefs((PyObject *) self);
     }
-#endif
 
-#ifdef HAVE_WARNINGS
     if (self->txn) {
         /* it hasn't been finalized, abort it! */
         MYDB_BEGIN_ALLOW_THREADS;
@@ -1121,7 +1017,6 @@
 		     " No prior commit() or abort().",
 		     1);
     }
-#endif
 
     Py_DECREF(self->env);
     PyObject_Del(self);
@@ -1136,9 +1031,7 @@
     DBLockObject* self = PyObject_New(DBLockObject, &DBLock_Type);
     if (self == NULL)
         return NULL;
-#ifdef HAVE_WEAKREF
     self->in_weakreflist = NULL;
-#endif
 
     MYDB_BEGIN_ALLOW_THREADS;
 #if (DBVER >= 40)
@@ -1160,11 +1053,9 @@
 static void
 DBLock_dealloc(DBLockObject* self)
 {
-#ifdef HAVE_WEAKREF
     if (self->in_weakreflist != NULL) {
         PyObject_ClearWeakRefs((PyObject *) self);
     }
-#endif
     /* TODO: is this lock held? should we release it? */
 
     PyObject_Del(self);
@@ -1181,9 +1072,7 @@
         return NULL;
     Py_INCREF(mydb);
     self->mydb = mydb;
-#ifdef HAVE_WEAKREF
     self->in_weakreflist = NULL;
-#endif
 
 
     MYDB_BEGIN_ALLOW_THREADS;
@@ -1202,11 +1091,9 @@
 static void
 DBSequence_dealloc(DBSequenceObject* self)
 {
-#ifdef HAVE_WEAKREF
     if (self->in_weakreflist != NULL) {
         PyObject_ClearWeakRefs((PyObject *) self);
     }
-#endif
 
     Py_DECREF(self->mydb);
     PyObject_Del(self);
@@ -1248,7 +1135,7 @@
     }
 
     free_buf_view(dataobj, data_buf_view);
-    return PyInt_FromLong(recno);
+    return PyLong_FromLong(recno);
 }
 
 
@@ -1284,16 +1171,19 @@
         else if (result == Py_None) {
             retval = DB_DONOTINDEX;
         }
-        else if (PyInt_Check(result)) {
-            retval = PyInt_AsLong(result);
+        else if (PyLong_Check(result)) {
+            retval = PyLong_AsLong(result);
         }
-        else if (PyBytes_Check(result)) {
+        else if (PyBytes_Check(result) || PyString_Check(result)) {
             char* data;
             Py_ssize_t size;
 
             CLEAR_DBT(*secKey);
-            size = PyBytes_Size(result);
-            data = PyBytes_AsString(result);
+            size = Py_SIZE(result);
+            if (PyBytes_Check(result))
+                data = PyBytes_AS_STRING(result);
+            else
+                data = PyString_AS_STRING(result);
             secKey->flags = DB_DBT_APPMALLOC;   /* DB will free */
             secKey->data = malloc(size);        /* TODO, check this */
 	    if (secKey->data) {
@@ -1432,7 +1322,6 @@
 }
 
 
-#if (DBVER >= 32)
 static PyObject*
 _DB_consume(DBObject* self, PyObject* args, PyObject* kwargs, int consume_flag)
 {
@@ -1500,8 +1389,6 @@
 {
     return _DB_consume(self, args, kwargs, DB_CONSUME_WAIT);
 }
-#endif
-
 
 
 static PyObject*
@@ -1573,7 +1460,7 @@
     err = self->db->fd(self->db, &the_fd);
     MYDB_END_ALLOW_THREADS;
     RETURN_IF_ERR();
-    return PyInt_FromLong(the_fd);
+    return PyLong_FromLong(the_fd);
 }
 
 
@@ -1636,7 +1523,7 @@
             retval = Py_BuildValue("y#y#", key.data, key.size, data.data,
                                    data.size);
         else /* return just the data */
-            retval = PyBytes_FromStringAndSize((char*)data.data, data.size);
+            retval = PyString_FromStringAndSize((char*)data.data, data.size);
         free_dbt(&data);
     }
     FREE_DBT_VIEW(key, keyobj, key_buf_view);
@@ -1706,22 +1593,22 @@
     else if (!err) {
         PyObject *pkeyObj;
         PyObject *dataObj;
-        dataObj = PyBytes_FromStringAndSize(data.data, data.size);
+        dataObj = PyString_FromStringAndSize(data.data, data.size);
 
         if (self->primaryDBType == DB_RECNO ||
             self->primaryDBType == DB_QUEUE)
-            pkeyObj = PyInt_FromLong(*(int *)pkey.data);
+            pkeyObj = PyLong_FromLong(*(int *)pkey.data);
         else
-            pkeyObj = PyBytes_FromStringAndSize(pkey.data, pkey.size);
+            pkeyObj = PyString_FromStringAndSize(pkey.data, pkey.size);
 
         if (flags & DB_SET_RECNO) /* return key , pkey and data */
         {
             PyObject *keyObj;
             int type = _DB_get_type(self);
             if (type == DB_RECNO || type == DB_QUEUE)
-                keyObj = PyInt_FromLong(*(int *)key.data);
+                keyObj = PyLong_FromLong(*(int *)key.data);
             else
-                keyObj = PyBytes_FromStringAndSize(key.data, key.size);
+                keyObj = PyString_FromStringAndSize(key.data, key.size);
 #if (PY_VERSION_HEX >= 0x02040000)
             retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj);
 #else
@@ -1783,7 +1670,7 @@
     err = self->db->get(self->db, txn, &key, &data, flags);
     MYDB_END_ALLOW_THREADS;
     if (err == DB_BUFFER_SMALL) {
-        retval = PyInt_FromLong((long)data.size);
+        retval = PyLong_FromLong((long)data.size);
         err = 0;
     }
 
@@ -1848,7 +1735,8 @@
     else if (!err) {
         /* XXX(nnorwitz): can we do: retval = dataobj; Py_INCREF(retval); */
         /* XXX(gps) I think not: buffer API input vs. bytes object output. */
-        retval = PyBytes_FromStringAndSize((char*)data.data, data.size);
+        /* XXX(guido) But what if the input is PyString? */
+        retval = PyString_FromStringAndSize((char*)data.data, data.size);
 
         /* Even though the flags require DB_DBT_MALLOC, data is not always
            allocated.  4.4: allocated, 4.5: *not* allocated. :-( */
@@ -1884,7 +1772,7 @@
     retval = self->db->get_byteswapped(self->db);
     MYDB_END_ALLOW_THREADS;
 #endif
-    return PyInt_FromLong(retval);
+    return PyLong_FromLong(retval);
 }
 
 
@@ -1900,7 +1788,7 @@
     type = _DB_get_type(self);
     if (type == -1)
         return NULL;
-    return PyInt_FromLong(type);
+    return PyLong_FromLong(type);
 }
 
 
@@ -2059,21 +1947,6 @@
         return NULL;
     }
 
-#if 0 && (DBVER >= 41)
-    if ((!txn) && (txnobj != Py_None) && self->myenvobj
-        && (self->myenvobj->flags & DB_INIT_TXN))
-    {
-	/* If no 'txn' parameter was supplied (no DbTxn object and None was not
-	 * explicitly passed) but we are in a transaction ready environment:
-	 *   add DB_AUTO_COMMIT to allow for older pybsddb apps using transactions
-	 *   to work on BerkeleyDB 4.1 without needing to modify their
-	 *   DBEnv or DB open calls. 
-	 * TODO make this behaviour of the library configurable.
-	 */
-	flags |= DB_AUTO_COMMIT;
-    }
-#endif
-
     MYDB_BEGIN_ALLOW_THREADS;
 #if (DBVER >= 41)
     err = self->db->open(self->db, txn, filename, dbname, type, flags, mode);
@@ -2087,6 +1960,10 @@
         return NULL;
     }
 
+#if (DBVER >= 42)
+    self->db->get_flags(self->db, &self->setflags);
+#endif
+
     self->flags = flags;
     RETURN_NONE();
 }
@@ -2130,7 +2007,7 @@
     }
 
     if (flags & DB_APPEND)
-        retval = PyInt_FromLong(*((db_recno_t*)key.data));
+        retval = PyLong_FromLong(*((db_recno_t*)key.data));
     else {
         retval = Py_None;
         Py_INCREF(retval);
@@ -2256,8 +2133,8 @@
 	    /* we're in a callback within the DB code, we can't raise */
 	    PyErr_Print();
 	    res = _default_cmp(leftKey, rightKey);
-	} else if (PyInt_Check(result)) {
-	    res = PyInt_AsLong(result);
+	} else if (PyLong_Check(result)) {
+	    res = PyLong_AsLong(result);
 	} else {
 	    PyErr_SetString(PyExc_TypeError,
 			    "DB_bt_compare callback MUST return an int.");
@@ -2301,11 +2178,11 @@
     Py_DECREF(tuple);
     if (result == NULL)
         return NULL;
-    if (!PyInt_Check(result)) {
+    if (!PyLong_Check(result)) {
 	PyErr_SetString(PyExc_TypeError,
 		        "callback MUST return an int");
 	return NULL;
-    } else if (PyInt_AsLong(result) != 0) {
+    } else if (PyLong_AsLong(result) != 0) {
 	PyErr_SetString(PyExc_TypeError,
 		        "callback failed to return 0 on two empty strings");
 	return NULL;
@@ -2526,7 +2403,6 @@
 }
 
 
-#if (DBVER >= 32)
 static PyObject*
 DB_set_q_extentsize(DBObject* self, PyObject* args)
 {
@@ -2543,7 +2419,6 @@
     RETURN_IF_ERR();
     RETURN_NONE();
 }
-#endif
 
 static PyObject*
 DB_stat(DBObject* self, PyObject* args, PyObject* kwargs)
@@ -2709,7 +2584,7 @@
     err = self->db->truncate(self->db, txn, &count, flags);
     MYDB_END_ALLOW_THREADS;
     RETURN_IF_ERR();
-    return PyInt_FromLong(count);
+    return PyLong_FromLong(count);
 }
 #endif
 
@@ -2790,7 +2665,7 @@
         ++oldValue;
     self->moduleFlags.getReturnsNone = (flags >= 1);
     self->moduleFlags.cursorSetReturnsNone = (flags >= 2);
-    return PyInt_FromLong(oldValue);
+    return PyLong_FromLong(oldValue);
 }
 
 #if (DBVER >= 41)
@@ -2905,7 +2780,7 @@
         retval = NULL;
     }
     else {
-        retval = PyBytes_FromStringAndSize((char*)data.data, data.size);
+        retval = PyString_FromStringAndSize((char*)data.data, data.size);
         free_dbt(&data);
     }
 
@@ -2994,9 +2869,9 @@
     FREE_DBT_VIEW(key, keyobj, key_buf_view);
 
     if (err == DB_BUFFER_SMALL || err == 0) {
-        return PyInt_FromLong(1);
+        return PyLong_FromLong(1);
     } else if (err == DB_NOTFOUND || err == DB_KEYEMPTY) {
-        return PyInt_FromLong(0);
+        return PyLong_FromLong(0);
     }
 
     makeDBError(err);
@@ -3060,17 +2935,17 @@
             case DB_BTREE:
             case DB_HASH:
             default:
-                item = PyBytes_FromStringAndSize((char*)key.data, key.size);
+                item = PyString_FromStringAndSize((char*)key.data, key.size);
                 break;
             case DB_RECNO:
             case DB_QUEUE:
-                item = PyInt_FromLong(*((db_recno_t*)key.data));
+                item = PyLong_FromLong(*((db_recno_t*)key.data));
                 break;
             }
             break;
 
         case _VALUES_LIST:
-            item = PyBytes_FromStringAndSize((char*)data.data, data.size);
+            item = PyString_FromStringAndSize((char*)data.data, data.size);
             break;
 
         case _ITEMS_LIST:
@@ -3199,7 +3074,7 @@
     MYDB_END_ALLOW_THREADS;
     RETURN_IF_ERR();
 
-    return PyInt_FromLong(count);
+    return PyLong_FromLong(count);
 }
 
 
@@ -3418,22 +3293,22 @@
     else {
         PyObject *pkeyObj;
         PyObject *dataObj;
-        dataObj = PyBytes_FromStringAndSize(data.data, data.size);
+        dataObj = PyString_FromStringAndSize(data.data, data.size);
 
         if (self->mydb->primaryDBType == DB_RECNO ||
             self->mydb->primaryDBType == DB_QUEUE)
-            pkeyObj = PyInt_FromLong(*(int *)pkey.data);
+            pkeyObj = PyLong_FromLong(*(int *)pkey.data);
         else
-            pkeyObj = PyBytes_FromStringAndSize(pkey.data, pkey.size);
+            pkeyObj = PyString_FromStringAndSize(pkey.data, pkey.size);
 
         if (key.data && key.size) /* return key, pkey and data */
         {
             PyObject *keyObj;
             int type = _DB_get_type(self->mydb);
             if (type == DB_RECNO || type == DB_QUEUE)
-                keyObj = PyInt_FromLong(*(int *)key.data);
+                keyObj = PyLong_FromLong(*(int *)key.data);
             else
-                keyObj = PyBytes_FromStringAndSize(key.data, key.size);
+                keyObj = PyString_FromStringAndSize(key.data, key.size);
             retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj);
             Py_DECREF(keyObj);
         }
@@ -3487,7 +3362,7 @@
     recno = *((db_recno_t*)data.data);
     free_dbt(&key);
     free_dbt(&data);
-    return PyInt_FromLong(recno);
+    return PyLong_FromLong(recno);
 }
 
 
@@ -3789,7 +3664,7 @@
     MYDB_END_ALLOW_THREADS;
     if (err == DB_BUFFER_SMALL || !err) {
         /* DB_BUFFER_SMALL means positive size, !err means zero length value */
-        retval = PyInt_FromLong((long)data.size);
+        retval = PyLong_FromLong((long)data.size);
         err = 0;
     }
 
@@ -4144,7 +4019,6 @@
 }
 
 
-#if (DBVER >= 32)
 static PyObject*
 DBEnv_set_flags(DBEnvObject* self, PyObject* args)
 {
@@ -4161,7 +4035,6 @@
     RETURN_IF_ERR();
     RETURN_NONE();
 }
-#endif
 
 
 static PyObject*
@@ -4288,7 +4161,6 @@
 #endif
 
 
-#if (DBVER >= 32)
 
 static PyObject*
 DBEnv_set_lk_max_locks(DBEnvObject* self, PyObject* args)
@@ -4340,8 +4212,6 @@
     RETURN_NONE();
 }
 
-#endif
-
 
 static PyObject*
 DBEnv_set_mp_mmapsize(DBEnvObject* self, PyObject* args)
@@ -4469,7 +4339,7 @@
 #endif
     MYDB_END_ALLOW_THREADS;
     RETURN_IF_ERR();
-    return PyInt_FromLong(aborted);
+    return PyLong_FromLong(aborted);
 }
 
 
@@ -4513,9 +4383,27 @@
     MYDB_END_ALLOW_THREADS;
     RETURN_IF_ERR();
 
-    return PyInt_FromLong((long)theID);
+    return PyLong_FromLong((long)theID);
 }
 
+#if (DBVER >= 40)
+static PyObject*
+DBEnv_lock_id_free(DBEnvObject* self, PyObject* args)
+{
+    int err;
+    u_int32_t theID;
+
+    if (!PyArg_ParseTuple(args, "I:lock_id_free", &theID))
+        return NULL;
+
+    CHECK_ENV_NOT_CLOSED(self);
+    MYDB_BEGIN_ALLOW_THREADS;
+    err = self->db_env->lock_id_free(self->db_env, theID);
+    MYDB_END_ALLOW_THREADS;
+    RETURN_IF_ERR();
+    RETURN_NONE();
+}
+#endif
 
 static PyObject*
 DBEnv_lock_put(DBEnvObject* self, PyObject* args)
@@ -4664,19 +4552,15 @@
     MAKE_ENTRY(lastid);
 #endif
     MAKE_ENTRY(nmodes);
-#if (DBVER >= 32)
     MAKE_ENTRY(maxlocks);
     MAKE_ENTRY(maxlockers);
     MAKE_ENTRY(maxobjects);
     MAKE_ENTRY(nlocks);
     MAKE_ENTRY(maxnlocks);
-#endif
     MAKE_ENTRY(nlockers);
     MAKE_ENTRY(maxnlockers);
-#if (DBVER >= 32)
     MAKE_ENTRY(nobjects);
     MAKE_ENTRY(maxnobjects);
-#endif
     MAKE_ENTRY(nrequests);
     MAKE_ENTRY(nreleases);
 #if (DBVER < 44)
@@ -4814,7 +4698,7 @@
         ++oldValue;
     self->moduleFlags.getReturnsNone = (flags >= 1);
     self->moduleFlags.cursorSetReturnsNone = (flags >= 2);
-    return PyInt_FromLong(oldValue);
+    return PyLong_FromLong(oldValue);
 }
 
 
@@ -4958,7 +4842,7 @@
     id = txn_id(self->txn);
 #endif
     MYDB_END_ALLOW_THREADS;
-    return PyInt_FromLong(id);
+    return PyLong_FromLong(id);
 }
 
 #if (DBVER >= 43)
@@ -5024,7 +4908,7 @@
 {
     int err;
     DBT key;
-    PyObject *retval;
+    PyObject *retval = NULL;
     key.flags = DB_DBT_MALLOC;
     CHECK_SEQUENCE_NOT_CLOSED(self)
     MYDB_BEGIN_ALLOW_THREADS
@@ -5032,7 +4916,7 @@
     MYDB_END_ALLOW_THREADS
 
     if (!err)
-        retval = PyBytes_FromStringAndSize(key.data, key.size);
+        retval = PyString_FromStringAndSize(key.data, key.size);
 
     free_dbt(&key);
     RETURN_IF_ERR();
@@ -5141,7 +5025,7 @@
     MYDB_END_ALLOW_THREADS
 
     RETURN_IF_ERR();
-    return PyInt_FromLong(size);
+    return PyLong_FromLong(size);
 }
 
 static PyObject*
@@ -5175,7 +5059,7 @@
     MYDB_END_ALLOW_THREADS
 
     RETURN_IF_ERR();
-    return PyInt_FromLong((int)flags);
+    return PyLong_FromLong((int)flags);
 }
 
 static PyObject*
@@ -5265,10 +5149,8 @@
     {"associate",       (PyCFunction)DB_associate,      METH_VARARGS|METH_KEYWORDS},
 #endif
     {"close",           (PyCFunction)DB_close,          METH_VARARGS},
-#if (DBVER >= 32)
     {"consume",         (PyCFunction)DB_consume,        METH_VARARGS|METH_KEYWORDS},
     {"consume_wait",    (PyCFunction)DB_consume_wait,   METH_VARARGS|METH_KEYWORDS},
-#endif
     {"cursor",          (PyCFunction)DB_cursor,         METH_VARARGS|METH_KEYWORDS},
     {"delete",          (PyCFunction)DB_delete,         METH_VARARGS|METH_KEYWORDS},
     {"fd",              (PyCFunction)DB_fd,             METH_VARARGS},
@@ -5306,9 +5188,7 @@
     {"set_re_len",      (PyCFunction)DB_set_re_len,     METH_VARARGS},
     {"set_re_pad",      (PyCFunction)DB_set_re_pad,     METH_VARARGS},
     {"set_re_source",   (PyCFunction)DB_set_re_source,  METH_VARARGS},
-#if (DBVER >= 32)
     {"set_q_extentsize",(PyCFunction)DB_set_q_extentsize,METH_VARARGS},
-#endif
     {"stat",            (PyCFunction)DB_stat,           METH_VARARGS|METH_KEYWORDS},
     {"sync",            (PyCFunction)DB_sync,           METH_VARARGS},
 #if (DBVER >= 33)
@@ -5376,9 +5256,7 @@
     {"set_shm_key",     (PyCFunction)DBEnv_set_shm_key,      METH_VARARGS},
     {"set_cachesize",   (PyCFunction)DBEnv_set_cachesize,    METH_VARARGS},
     {"set_data_dir",    (PyCFunction)DBEnv_set_data_dir,     METH_VARARGS},
-#if (DBVER >= 32)
     {"set_flags",       (PyCFunction)DBEnv_set_flags,        METH_VARARGS},
-#endif
     {"set_lg_bsize",    (PyCFunction)DBEnv_set_lg_bsize,     METH_VARARGS},
     {"set_lg_dir",      (PyCFunction)DBEnv_set_lg_dir,       METH_VARARGS},
     {"set_lg_max",      (PyCFunction)DBEnv_set_lg_max,       METH_VARARGS},
@@ -5389,11 +5267,9 @@
 #if (DBVER < 45)
     {"set_lk_max",      (PyCFunction)DBEnv_set_lk_max,       METH_VARARGS},
 #endif
-#if (DBVER >= 32)
     {"set_lk_max_locks", (PyCFunction)DBEnv_set_lk_max_locks, METH_VARARGS},
     {"set_lk_max_lockers", (PyCFunction)DBEnv_set_lk_max_lockers, METH_VARARGS},
     {"set_lk_max_objects", (PyCFunction)DBEnv_set_lk_max_objects, METH_VARARGS},
-#endif
     {"set_mp_mmapsize", (PyCFunction)DBEnv_set_mp_mmapsize,  METH_VARARGS},
     {"set_tmp_dir",     (PyCFunction)DBEnv_set_tmp_dir,      METH_VARARGS},
     {"txn_begin",       (PyCFunction)DBEnv_txn_begin,        METH_VARARGS|METH_KEYWORDS},
@@ -5404,6 +5280,9 @@
     {"lock_detect",     (PyCFunction)DBEnv_lock_detect,      METH_VARARGS},
     {"lock_get",        (PyCFunction)DBEnv_lock_get,         METH_VARARGS},
     {"lock_id",         (PyCFunction)DBEnv_lock_id,          METH_VARARGS},
+#if (DBVER >= 40)
+    {"lock_id_free",    (PyCFunction)DBEnv_lock_id_free,     METH_VARARGS},
+#endif
     {"lock_put",        (PyCFunction)DBEnv_lock_put,         METH_VARARGS},
     {"lock_stat",       (PyCFunction)DBEnv_lock_stat,        METH_VARARGS},
     {"log_archive",     (PyCFunction)DBEnv_log_archive,      METH_VARARGS},
@@ -5512,7 +5391,6 @@
     0,          /*tp_as_sequence*/
     &DB_mapping,/*tp_as_mapping*/
     0,          /*tp_hash*/
-#ifdef HAVE_WEAKREF
     0,			/* tp_call */
     0,			/* tp_str */
     0,  		/* tp_getattro */
@@ -5524,7 +5402,6 @@
     0,			/* tp_clear */
     0,			/* tp_richcompare */
     offsetof(DBObject, in_weakreflist),   /* tp_weaklistoffset */
-#endif
 };
 
 
@@ -5544,7 +5421,6 @@
     0,                  /*tp_as_sequence*/
     0,                  /*tp_as_mapping*/
     0,                  /*tp_hash*/
-#ifdef HAVE_WEAKREF
     0,			/* tp_call */
     0,			/* tp_str */
     0,  		/* tp_getattro */
@@ -5556,7 +5432,6 @@
     0,			/* tp_clear */
     0,			/* tp_richcompare */
     offsetof(DBCursorObject, in_weakreflist),   /* tp_weaklistoffset */
-#endif
 };
 
 
@@ -5576,7 +5451,6 @@
     0,          /*tp_as_sequence*/
     0,          /*tp_as_mapping*/
     0,          /*tp_hash*/
-#ifdef HAVE_WEAKREF
     0,			/* tp_call */
     0,			/* tp_str */
     0,  		/* tp_getattro */
@@ -5588,7 +5462,6 @@
     0,			/* tp_clear */
     0,			/* tp_richcompare */
     offsetof(DBEnvObject, in_weakreflist),   /* tp_weaklistoffset */
-#endif
 };
 
 static PyTypeObject DBTxn_Type = {
@@ -5607,7 +5480,6 @@
     0,          /*tp_as_sequence*/
     0,          /*tp_as_mapping*/
     0,          /*tp_hash*/
-#ifdef HAVE_WEAKREF
     0,			/* tp_call */
     0,			/* tp_str */
     0,  		/* tp_getattro */
@@ -5619,7 +5491,6 @@
     0,			/* tp_clear */
     0,			/* tp_richcompare */
     offsetof(DBTxnObject, in_weakreflist),   /* tp_weaklistoffset */
-#endif
 };
 
 
@@ -5639,7 +5510,6 @@
     0,          /*tp_as_sequence*/
     0,          /*tp_as_mapping*/
     0,          /*tp_hash*/
-#ifdef HAVE_WEAKREF
     0,			/* tp_call */
     0,			/* tp_str */
     0,  		/* tp_getattro */
@@ -5651,7 +5521,6 @@
     0,			/* tp_clear */
     0,			/* tp_richcompare */
     offsetof(DBLockObject, in_weakreflist),   /* tp_weaklistoffset */
-#endif
 };
 
 #if (DBVER >= 43)
@@ -5671,7 +5540,6 @@
     0,          /*tp_as_sequence*/
     0,          /*tp_as_mapping*/
     0,          /*tp_hash*/
-#ifdef HAVE_WEAKREF
     0,			/* tp_call */
     0,			/* tp_str */
     0,  		/* tp_getattro */
@@ -5683,7 +5551,6 @@
     0,			/* tp_clear */
     0,			/* tp_richcompare */
     offsetof(DBSequenceObject, in_weakreflist),   /* tp_weaklistoffset */
-#endif
 };
 #endif
 
@@ -5765,6 +5632,9 @@
     {NULL,      NULL}       /* sentinel */
 };
 
+/* API structure */
+static BSDDB_api bsddb_api;
+
 
 /* --------------------------------------------------------------------- */
 /* Module initialization */
@@ -5785,16 +5655,17 @@
     PyObject* pybsddb_version_s = PyUnicode_FromString(PY_BSDDB_VERSION);
     PyObject* db_version_s = PyUnicode_FromString(DB_VERSION_STRING);
     PyObject* svnid_s = PyUnicode_FromString(svn_id);
+    PyObject* py_api;
 
     /* Initialize the type of the new type objects here; doing it here
        is required for portability to Windows without requiring C++. */
-    Py_Type(&DB_Type) = &PyType_Type;
-    Py_Type(&DBCursor_Type) = &PyType_Type;
-    Py_Type(&DBEnv_Type) = &PyType_Type;
-    Py_Type(&DBTxn_Type) = &PyType_Type;
-    Py_Type(&DBLock_Type) = &PyType_Type;
+    Py_TYPE(&DB_Type) = &PyType_Type;
+    Py_TYPE(&DBCursor_Type) = &PyType_Type;
+    Py_TYPE(&DBEnv_Type) = &PyType_Type;
+    Py_TYPE(&DBTxn_Type) = &PyType_Type;
+    Py_TYPE(&DBLock_Type) = &PyType_Type;
 #if (DBVER >= 43)    
-    Py_Type(&DBSequence_Type) = &PyType_Type;
+    Py_TYPE(&DBSequence_Type) = &PyType_Type;
 #endif    
 
 
@@ -5846,9 +5717,7 @@
     ADD_INT(d, DB_INIT_LOG);
     ADD_INT(d, DB_INIT_MPOOL);
     ADD_INT(d, DB_INIT_TXN);
-#if (DBVER >= 32)
     ADD_INT(d, DB_JOINENV);
-#endif
 
     ADD_INT(d, DB_RECOVER);
     ADD_INT(d, DB_RECOVER_FATAL);
@@ -5869,11 +5738,9 @@
     ADD_INT(d, DB_RDWRMASTER);
     ADD_INT(d, DB_RDONLY);
     ADD_INT(d, DB_TRUNCATE);
-#if (DBVER >= 32)
     ADD_INT(d, DB_EXTENT);
     ADD_INT(d, DB_CDB_ALLDB);
     ADD_INT(d, DB_VERIFY);
-#endif
     ADD_INT(d, DB_UPGRADE);
 
     ADD_INT(d, DB_AGGRESSIVE);
@@ -5917,9 +5784,7 @@
     ADD_INT(d, DB_LOCK_READ);
     ADD_INT(d, DB_LOCK_WRITE);
     ADD_INT(d, DB_LOCK_NOWAIT);
-#if (DBVER >= 32)
     ADD_INT(d, DB_LOCK_WAIT);
-#endif
     ADD_INT(d, DB_LOCK_IWRITE);
     ADD_INT(d, DB_LOCK_IREAD);
     ADD_INT(d, DB_LOCK_IWR);
@@ -5934,9 +5799,7 @@
 
     ADD_INT(d, DB_LOCK_RECORD);
     ADD_INT(d, DB_LOCK_UPGRADE);
-#if (DBVER >= 32)
     ADD_INT(d, DB_LOCK_SWITCH);
-#endif
 #if (DBVER >= 33)
     ADD_INT(d, DB_LOCK_UPGRADE_WRITE);
 #endif
@@ -5997,9 +5860,7 @@
     ADD_INT(d, DB_COMMIT);
 #endif
     ADD_INT(d, DB_CONSUME);
-#if (DBVER >= 32)
     ADD_INT(d, DB_CONSUME_WAIT);
-#endif
     ADD_INT(d, DB_CURRENT);
 #if (DBVER >= 33)
     ADD_INT(d, DB_FAST_STAT);
@@ -6076,6 +5937,10 @@
     ADD_INT(d, DB_NOPANIC);
 #endif
 
+#ifdef DB_REGISTER
+    ADD_INT(d, DB_REGISTER);
+#endif
+
 #if (DBVER >= 42)
     ADD_INT(d, DB_TIME_NOTGRANTED);
     ADD_INT(d, DB_TXN_NOT_DURABLE);
@@ -6140,7 +6005,7 @@
      * using one base class. */
     PyDict_SetItemString(d, "KeyError", PyExc_KeyError);
     { 
-	    PyObject *builtin_mod = PyImport_ImportModule("__builtin__");
+	    PyObject *builtin_mod = PyImport_ImportModule("builtins");
 	    PyDict_SetItemString(d, "__builtins__", builtin_mod);
     }
     PyRun_String("class DBNotFoundError(DBError, KeyError): pass\n"
@@ -6182,6 +6047,21 @@
 
 #undef MAKE_EX
 
+    /* Initiliase the C API structure and add it to the module */
+    bsddb_api.db_type         = &DB_Type;
+    bsddb_api.dbcursor_type   = &DBCursor_Type;
+    bsddb_api.dbenv_type      = &DBEnv_Type;
+    bsddb_api.dbtxn_type      = &DBTxn_Type;
+    bsddb_api.dblock_type     = &DBLock_Type;
+#if (DBVER >= 43)
+    bsddb_api.dbsequence_type = &DBSequence_Type;
+#endif
+    bsddb_api.makeDBError     = makeDBError;
+
+    py_api = PyCObject_FromVoidPtr((void*)&bsddb_api, NULL);
+    PyDict_SetItemString(d, "api", py_api);
+    Py_DECREF(py_api);
+
     /* Check for errors */
     if (PyErr_Occurred()) {
         PyErr_Print();

Modified: python/branches/py3k-importlib/Modules/_codecsmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_codecsmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/_codecsmodule.c	Thu Mar 27 00:48:05 2008
@@ -180,7 +180,7 @@
 			"string is too large to encode");
 			return NULL;
 	}
-	v = PyBytes_FromStringAndSize(NULL, newsize);
+	v = PyString_FromStringAndSize(NULL, newsize);
 
 	if (v == NULL) {
 		return NULL;
@@ -188,11 +188,11 @@
 	else {
 		register Py_ssize_t i;
 		register char c;
-		register char *p = PyBytes_AS_STRING(v);
+		register char *p = PyString_AS_STRING(v);
 
 		for (i = 0; i < size; i++) {
 			/* There's at least enough room for a hex escape */
-			assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4);
+			assert(newsize - (p - PyString_AS_STRING(v)) >= 4);
 			c = PyString_AS_STRING(str)[i];
 			if (c == '\'' || c == '\\')
 				*p++ = '\\', *p++ = c;
@@ -212,13 +212,12 @@
 				*p++ = c;
 		}
 		*p = '\0';
-		if (PyBytes_Resize(v, (p - PyBytes_AS_STRING(v)))) {
-			Py_DECREF(v);
+		if (_PyString_Resize(&v, (p - PyString_AS_STRING(v)))) {
 			return NULL;
 		}
 	}
 	
-	return codec_tuple(v, PyBytes_Size(v));
+	return codec_tuple(v, PyString_Size(v));
 }
 
 /* --- Decoder ------------------------------------------------------------ */
@@ -251,18 +250,25 @@
 
 static PyObject *
 utf_7_decode(PyObject *self,
-	    PyObject *args)
+             PyObject *args)
 {
     const char *data;
     Py_ssize_t size;
     const char *errors = NULL;
+    int final = 0;
+    Py_ssize_t consumed;
+    PyObject *decoded = NULL;
 
-    if (!PyArg_ParseTuple(args, "t#|z:utf_7_decode",
-			  &data, &size, &errors))
-	return NULL;
+    if (!PyArg_ParseTuple(args, "t#|zi:utf_7_decode",
+                          &data, &size, &errors, &final))
+        return NULL;
+    consumed = size;
 
-    return codec_tuple(PyUnicode_DecodeUTF7(data, size, errors),
-		       size);
+    decoded = PyUnicode_DecodeUTF7Stateful(data, size, errors,
+                                           final ? NULL : &consumed);
+    if (decoded == NULL)
+        return NULL;
+    return codec_tuple(decoded, consumed);
 }
 
 static PyObject *
@@ -654,7 +660,7 @@
 			  &data, &size, &errors))
 	return NULL;
 
-    return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
+    return codec_tuple(PyString_FromStringAndSize(data, size), size);
 }
 
 static PyObject *
@@ -669,7 +675,7 @@
 			  &data, &size, &errors))
 	return NULL;
 
-    return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
+    return codec_tuple(PyString_FromStringAndSize(data, size), size);
 }
 
 static PyObject *
@@ -688,12 +694,12 @@
     if (PyUnicode_Check(obj)) {
 	data = PyUnicode_AS_DATA(obj);
 	size = PyUnicode_GET_DATA_SIZE(obj);
-	return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
+	return codec_tuple(PyString_FromStringAndSize(data, size), size);
     }
     else {
 	if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
 	    return NULL;
-	return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
+	return codec_tuple(PyString_FromStringAndSize(data, size), size);
     }
 }
 

Modified: python/branches/py3k-importlib/Modules/_collectionsmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_collectionsmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/_collectionsmodule.c	Thu Mar 27 00:48:05 2008
@@ -51,6 +51,10 @@
 	PyObject *data[BLOCKLEN];
 } block;
 
+#define MAXFREEBLOCKS 10
+static int numfreeblocks = 0;
+static block *freeblocks[MAXFREEBLOCKS];
+
 static block *
 newblock(block *leftlink, block *rightlink, int len) {
 	block *b;
@@ -66,16 +70,32 @@
 				"cannot add more blocks to the deque");
 		return NULL;
 	}
-	b = PyMem_Malloc(sizeof(block));
-	if (b == NULL) {
-		PyErr_NoMemory();
-		return NULL;
+	if (numfreeblocks) {
+		numfreeblocks -= 1;
+		b = freeblocks[numfreeblocks];
+	} else {
+		b = PyMem_Malloc(sizeof(block));
+		if (b == NULL) {
+			PyErr_NoMemory();
+			return NULL;
+		}
 	}
 	b->leftlink = leftlink;
 	b->rightlink = rightlink;
 	return b;
 }
 
+void
+freeblock(block *b)
+{
+	if (numfreeblocks < MAXFREEBLOCKS) {
+		freeblocks[numfreeblocks] = b;
+		numfreeblocks++;
+	} else {
+		PyMem_Free(b);
+	}
+}
+
 typedef struct {
 	PyObject_HEAD
 	block *leftblock;
@@ -83,10 +103,27 @@
 	int leftindex;	/* in range(BLOCKLEN) */
 	int rightindex;	/* in range(BLOCKLEN) */
 	int len;
+	int maxlen;
 	long state;	/* incremented whenever the indices move */
 	PyObject *weakreflist; /* List of weak references */
 } dequeobject;
 
+/* The deque's size limit is d.maxlen.  The limit can be zero or positive.
+ * If there is no limit, then d.maxlen == -1.
+ * 
+ * After an item is added to a deque, we check to see if the size has grown past
+ * the limit. If it has, we get the size back down to the limit by popping an
+ * item off of the opposite end.  The methods that can trigger this are append(),
+ * appendleft(), extend(), and extendleft().
+ */
+
+#define TRIM(d, popfunction)                               	\
+    if (d->maxlen != -1 && d->len > d->maxlen) {              	\
+            PyObject *rv = popfunction(d, NULL);                \
+            assert(rv != NULL  &&  d->len <= d->maxlen);        \
+            Py_DECREF(rv);                                      \
+    }
+
 static PyTypeObject deque_type;
 
 static PyObject *
@@ -95,9 +132,6 @@
 	dequeobject *deque;
 	block *b;
 
-	if (type == &deque_type && !_PyArg_NoKeywords("deque()", kwds))
-		return NULL;
-
 	/* create dequeobject structure */
 	deque = (dequeobject *)type->tp_alloc(type, 0);
 	if (deque == NULL)
@@ -117,55 +151,12 @@
 	deque->len = 0;
 	deque->state = 0;
 	deque->weakreflist = NULL;
+	deque->maxlen = -1;
 
 	return (PyObject *)deque;
 }
 
 static PyObject *
-deque_append(dequeobject *deque, PyObject *item)
-{
-	deque->state++;
-	if (deque->rightindex == BLOCKLEN-1) {
-		block *b = newblock(deque->rightblock, NULL, deque->len);
-		if (b == NULL)
-			return NULL;
-		assert(deque->rightblock->rightlink == NULL);
-		deque->rightblock->rightlink = b;
-		deque->rightblock = b;
-		deque->rightindex = -1;
-	}
-	Py_INCREF(item);
-	deque->len++;
-	deque->rightindex++;
-	deque->rightblock->data[deque->rightindex] = item;
-	Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(append_doc, "Add an element to the right side of the deque.");
-
-static PyObject *
-deque_appendleft(dequeobject *deque, PyObject *item)
-{
-	deque->state++;
-	if (deque->leftindex == 0) {
-		block *b = newblock(NULL, deque->leftblock, deque->len);
-		if (b == NULL)
-			return NULL;
-		assert(deque->leftblock->leftlink == NULL);
-		deque->leftblock->leftlink = b;
-		deque->leftblock = b;
-		deque->leftindex = BLOCKLEN;
-	}
-	Py_INCREF(item);
-	deque->len++;
-	deque->leftindex--;
-	deque->leftblock->data[deque->leftindex] = item;
-	Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(appendleft_doc, "Add an element to the left side of the deque.");
-
-static PyObject *
 deque_pop(dequeobject *deque, PyObject *unused)
 {
 	PyObject *item;
@@ -190,7 +181,7 @@
 		} else {
 			prevblock = deque->rightblock->leftlink;
 			assert(deque->leftblock != deque->rightblock);
-			PyMem_Free(deque->rightblock);
+			freeblock(deque->rightblock);
 			prevblock->rightlink = NULL;
 			deque->rightblock = prevblock;
 			deque->rightindex = BLOCKLEN - 1;
@@ -227,7 +218,7 @@
 		} else {
 			assert(deque->leftblock != deque->rightblock);
 			prevblock = deque->leftblock->rightlink;
-			PyMem_Free(deque->leftblock);
+			freeblock(deque->leftblock);
 			assert(prevblock != NULL);
 			prevblock->leftlink = NULL;
 			deque->leftblock = prevblock;
@@ -240,6 +231,52 @@
 PyDoc_STRVAR(popleft_doc, "Remove and return the leftmost element.");
 
 static PyObject *
+deque_append(dequeobject *deque, PyObject *item)
+{
+	deque->state++;
+	if (deque->rightindex == BLOCKLEN-1) {
+		block *b = newblock(deque->rightblock, NULL, deque->len);
+		if (b == NULL)
+			return NULL;
+		assert(deque->rightblock->rightlink == NULL);
+		deque->rightblock->rightlink = b;
+		deque->rightblock = b;
+		deque->rightindex = -1;
+	}
+	Py_INCREF(item);
+	deque->len++;
+	deque->rightindex++;
+	deque->rightblock->data[deque->rightindex] = item;
+	TRIM(deque, deque_popleft);
+	Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(append_doc, "Add an element to the right side of the deque.");
+
+static PyObject *
+deque_appendleft(dequeobject *deque, PyObject *item)
+{
+	deque->state++;
+	if (deque->leftindex == 0) {
+		block *b = newblock(NULL, deque->leftblock, deque->len);
+		if (b == NULL)
+			return NULL;
+		assert(deque->leftblock->leftlink == NULL);
+		deque->leftblock->leftlink = b;
+		deque->leftblock = b;
+		deque->leftindex = BLOCKLEN;
+	}
+	Py_INCREF(item);
+	deque->len++;
+	deque->leftindex--;
+	deque->leftblock->data[deque->leftindex] = item;
+	TRIM(deque, deque_pop);
+	Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(appendleft_doc, "Add an element to the left side of the deque.");
+
+static PyObject *
 deque_extend(dequeobject *deque, PyObject *iterable)
 {
 	PyObject *it, *item;
@@ -266,6 +303,7 @@
 		deque->len++;
 		deque->rightindex++;
 		deque->rightblock->data[deque->rightindex] = item;
+		TRIM(deque, deque_popleft);               
 	}
 	Py_DECREF(it);
 	if (PyErr_Occurred())
@@ -303,6 +341,7 @@
 		deque->len++;
 		deque->leftindex--;
 		deque->leftblock->data[deque->leftindex] = item;
+		TRIM(deque, deque_pop);               
 	}
 	Py_DECREF(it);
 	if (PyErr_Occurred())
@@ -540,11 +579,11 @@
 	if (deque->leftblock != NULL) {
 		deque_clear(deque);
 		assert(deque->leftblock != NULL);
-		PyMem_Free(deque->leftblock);
+		freeblock(deque->leftblock);
 	}
 	deque->leftblock = NULL;
 	deque->rightblock = NULL;
-	Py_Type(deque)->tp_free(deque);
+	Py_TYPE(deque)->tp_free(deque);
 }
 
 static int
@@ -579,8 +618,11 @@
 static PyObject *
 deque_copy(PyObject *deque)
 {
-	return PyObject_CallFunctionObjArgs((PyObject *)(Py_Type(deque)),
-		deque, NULL);
+	if (((dequeobject *)deque)->maxlen == -1)
+		return PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "O", deque, NULL);
+	else
+		return PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "Oi",
+			deque, ((dequeobject *)deque)->maxlen, NULL);
 }
 
 PyDoc_STRVAR(copy_doc, "Return a shallow copy of a deque.");
@@ -588,21 +630,29 @@
 static PyObject *
 deque_reduce(dequeobject *deque)
 {
-	PyObject *dict, *result, *it;
+	PyObject *dict, *result, *aslist;
 
 	dict = PyObject_GetAttrString((PyObject *)deque, "__dict__");
-	if (dict == NULL) {
+	if (dict == NULL)
 		PyErr_Clear();
-		dict = Py_None;
-		Py_INCREF(dict);
-	}
-	it = PyObject_GetIter((PyObject *)deque);
-	if (it == NULL) {
-		Py_DECREF(dict);
+	aslist = PySequence_List((PyObject *)deque);
+	if (aslist == NULL) {
+		Py_XDECREF(dict);
 		return NULL;
 	}
-	result = Py_BuildValue("O()ON", Py_Type(deque), dict, it);
-	Py_DECREF(dict);
+	if (dict == NULL) {
+		if (deque->maxlen == -1)
+			result = Py_BuildValue("O(O)", Py_TYPE(deque), aslist);
+		else
+			result = Py_BuildValue("O(Oi)", Py_TYPE(deque), aslist, deque->maxlen);
+	} else {
+		if (deque->maxlen == -1)
+			result = Py_BuildValue("O(OO)O", Py_TYPE(deque), aslist, Py_None, dict);
+		else
+			result = Py_BuildValue("O(Oi)O", Py_TYPE(deque), aslist, deque->maxlen, dict);
+	}
+	Py_XDECREF(dict);
+	Py_DECREF(aslist);
 	return result;
 }
 
@@ -626,8 +676,11 @@
 		Py_ReprLeave(deque);
 		return NULL;
 	}
-
-	result = PyUnicode_FromFormat("deque(%R)", aslist);
+	if (((dequeobject *)deque)->maxlen != -1)
+		result = PyUnicode_FromFormat("deque(%R, maxlen=%i)", aslist,
+                                              ((dequeobject *)deque)->maxlen);
+	else
+		result = PyUnicode_FromFormat("deque(%R)", aslist);
 	Py_DECREF(aslist);
 	Py_ReprLeave(deque);
 	return result;
@@ -712,13 +765,26 @@
 }
 
 static int
-deque_init(dequeobject *deque, PyObject *args, PyObject *kwds)
+deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs)
 {
 	PyObject *iterable = NULL;
+	PyObject *maxlenobj = NULL;
+	int maxlen = -1;
+	char *kwlist[] = {"iterable", "maxlen", 0};
 
-	if (!PyArg_UnpackTuple(args, "deque", 0, 1, &iterable))
+	if (!PyArg_ParseTupleAndKeywords(args, kwdargs, "|OO:deque", kwlist, &iterable, &maxlenobj))
 		return -1;
-
+	if (maxlenobj != NULL && maxlenobj != Py_None) {
+		maxlen = PyLong_AsLong(maxlenobj);
+		if (maxlen == -1 && PyErr_Occurred())
+			return -1;
+		if (maxlen < 0) {
+			PyErr_SetString(PyExc_ValueError, "maxlen must be non-negative");
+			return -1;
+		}
+	}
+	deque->maxlen = maxlen;
+	deque_clear(deque);
 	if (iterable != NULL) {
 		PyObject *rv = deque_extend(deque, iterable);
 		if (rv == NULL)
@@ -773,7 +839,7 @@
 };
 
 PyDoc_STRVAR(deque_doc,
-"deque(iterable) --> deque object\n\
+"deque(iterable[, maxlen]) --> deque object\n\
 \n\
 Build an ordered collection accessible from endpoints only.");
 
@@ -855,7 +921,7 @@
 dequeiter_dealloc(dequeiterobject *dio)
 {
 	Py_XDECREF(dio->deque);
-	Py_Type(dio)->tp_free(dio);
+	Py_TYPE(dio)->tp_free(dio);
 }
 
 static PyObject *
@@ -889,7 +955,7 @@
 static PyObject *
 dequeiter_len(dequeiterobject *it)
 {
-	return PyInt_FromLong(it->counter);
+	return PyLong_FromLong(it->counter);
 }
 
 PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
@@ -1063,7 +1129,7 @@
 	   whose class constructor has the same signature.  Subclasses that
 	   define a different constructor signature must override copy().
 	*/
-	return PyObject_CallFunctionObjArgs((PyObject *)Py_Type(dd),
+	return PyObject_CallFunctionObjArgs((PyObject*)Py_TYPE(dd),
 					    dd->default_factory, dd, NULL);
 }
 
@@ -1106,7 +1172,7 @@
 		Py_DECREF(args);
 		return NULL;
 	}
-	result = PyTuple_Pack(5, Py_Type(dd), args,
+	result = PyTuple_Pack(5, Py_TYPE(dd), args,
 			      Py_None, Py_None, items);
 	Py_DECREF(items);
 	Py_DECREF(args);
@@ -1117,7 +1183,7 @@
 	{"__missing__", (PyCFunction)defdict_missing, METH_O,
 	 defdict_missing_doc},
 	{"copy", (PyCFunction)defdict_copy, METH_NOARGS,
-	 defdict_copy_doc},
+         defdict_copy_doc},
 	{"__copy__", (PyCFunction)defdict_copy, METH_NOARGS,
 	 defdict_copy_doc},
 	{"__reduce__", (PyCFunction)defdict_reduce, METH_NOARGS,
@@ -1143,16 +1209,32 @@
 defdict_repr(defdictobject *dd)
 {
 	PyObject *baserepr;
-	PyObject *def;
+	PyObject *defrepr;
 	PyObject *result;
 	baserepr = PyDict_Type.tp_repr((PyObject *)dd);
 	if (baserepr == NULL)
 		return NULL;
 	if (dd->default_factory == NULL)
-		def = Py_None;
+		defrepr = PyUnicode_FromString("None");
 	else
-		def = dd->default_factory;
-	result = PyUnicode_FromFormat("defaultdict(%R, %U)", def, baserepr);
+	{
+		int status = Py_ReprEnter(dd->default_factory);
+		if (status != 0) {
+			if (status < 0)
+				return NULL;
+			defrepr = PyUnicode_FromString("...");
+		}
+		else
+			defrepr = PyObject_Repr(dd->default_factory);
+		Py_ReprLeave(dd->default_factory);
+	}
+	if (defrepr == NULL) {
+		Py_DECREF(baserepr);
+		return NULL;
+	}
+	result = PyUnicode_FromFormat("defaultdict(%U, %U)",
+				      defrepr, baserepr);
+	Py_DECREF(defrepr);
 	Py_DECREF(baserepr);
 	return result;
 }

Modified: python/branches/py3k-importlib/Modules/_csv.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_csv.c	(original)
+++ python/branches/py3k-importlib/Modules/_csv.c	Thu Mar 27 00:48:05 2008
@@ -17,52 +17,8 @@
 #include "Python.h"
 #include "structmember.h"
 
-
-/* begin 2.2 compatibility macros */
-#ifndef PyDoc_STRVAR
-/* Define macros for inline documentation. */
-#define PyDoc_VAR(name) static char name[]
-#define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
-#ifdef WITH_DOC_STRINGS
-#define PyDoc_STR(str) str
-#else
-#define PyDoc_STR(str) ""
-#endif
-#endif /* ifndef PyDoc_STRVAR */
-
-#ifndef PyMODINIT_FUNC
-#	if defined(__cplusplus)
-#		define PyMODINIT_FUNC extern "C" void
-#	else /* __cplusplus */
-#		define PyMODINIT_FUNC void
-#	endif /* __cplusplus */
-#endif
-
-#ifndef Py_CLEAR
-#define Py_CLEAR(op)						\
-	do {							\
-		if (op) {					\
-			PyObject *tmp = (PyObject *)(op);	\
-			(op) = NULL;				\
-			Py_DECREF(tmp);				\
-		}						\
-	} while (0)
-#endif
-#ifndef Py_VISIT
-#define Py_VISIT(op)							\
-        do { 								\
-                if (op) {						\
-                        int vret = visit((PyObject *)(op), arg);	\
-                        if (vret)					\
-                                return vret;				\
-                }							\
-        } while (0)
-#endif
-
-/* end 2.2 compatibility macros */
-
 #define IS_BASESTRING(o) \
-	PyObject_TypeCheck(o, &PyBaseString_Type)
+	PyUnicode_Check(o)
 
 static PyObject *error_obj;	/* CSV exception */
 static PyObject *dialects;      /* Dialect registry */
@@ -125,7 +81,7 @@
 
 static PyTypeObject Reader_Type;
 
-#define ReaderObject_Check(v)   (Py_Type(v) == &Reader_Type)
+#define ReaderObject_Check(v)   (Py_TYPE(v) == &Reader_Type)
 
 typedef struct {
         PyObject_HEAD
@@ -206,7 +162,7 @@
 static PyObject *
 Dialect_get_quoting(DialectObj *self)
 {
-        return PyInt_FromLong(self->quoting);
+        return PyLong_FromLong(self->quoting);
 }
 
 static int
@@ -225,12 +181,23 @@
 	if (src == NULL)
 		*target = dflt;
 	else {
-		if (!PyInt_CheckExact(src)) {
+		long value;
+		if (!PyLong_CheckExact(src)) {
 			PyErr_Format(PyExc_TypeError, 
 				     "\"%s\" must be an integer", name);
 			return -1;
 		}
-		*target = PyInt_AsLong(src);
+		value = PyLong_AsLong(src);
+		if (value == -1 && PyErr_Occurred())
+			return -1;
+#if SIZEOF_LONG > SIZEOF_INT
+		if (value > INT_MAX || value < INT_MIN) {
+			PyErr_Format(PyExc_ValueError,
+				     "integer out of range for \"%s\"", name);
+			return -1;
+		}
+#endif
+		*target = (int)value;
 	}
 	return 0;
 }
@@ -270,7 +237,7 @@
 			*target = NULL;
 		else if (!IS_BASESTRING(src)) {
 			PyErr_Format(PyExc_TypeError, 
-				     "\"%s\" must be an string", name);
+				     "\"%s\" must be a string", name);
 			return -1;
 		}
 		else {
@@ -317,7 +284,7 @@
 Dialect_dealloc(DialectObj *self)
 {
         Py_XDECREF(self->lineterminator);
-        Py_Type(self)->tp_free((PyObject *)self);
+        Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static char *dialect_kws[] = {
@@ -793,6 +760,16 @@
 					     "newline inside string");
                         return NULL;
                 }
+		if (!PyUnicode_Check(lineobj)) {
+			PyErr_Format(error_obj,
+				     "iterator should return strings, "
+				     "not %.200s "
+				     "(did you open the file in text mode?)",
+				     lineobj->ob_type->tp_name
+				);
+			Py_DECREF(lineobj);
+			return NULL;
+		}
                 ++self->line_num;
                 line = PyUnicode_AsUnicode(lineobj);
                 linelen = PyUnicode_GetSize(lineobj);
@@ -1185,7 +1162,7 @@
 		else {
 			PyObject *str;
 
-			str = PyObject_Unicode(field);
+			str = PyObject_Str(field);
  			Py_DECREF(field);
 			if (str == NULL)
 				return NULL;
@@ -1419,14 +1396,18 @@
 	if (!PyArg_UnpackTuple(args, "field_size_limit", 0, 1, &new_limit))
 		return NULL;
 	if (new_limit != NULL) {
-		if (!PyInt_CheckExact(new_limit)) {
+		if (!PyLong_CheckExact(new_limit)) {
 			PyErr_Format(PyExc_TypeError, 
 				     "limit must be an integer");
 			return NULL;
 		}
-		field_limit = PyInt_AsLong(new_limit);
+		field_limit = PyLong_AsLong(new_limit);
+		if (field_limit == -1 && PyErr_Occurred()) {
+			field_limit = old_limit;
+			return NULL;
+		}
 	}
-	return PyInt_FromLong(old_limit);
+	return PyLong_FromLong(old_limit);
 }
 
 /*

Modified: python/branches/py3k-importlib/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/_ctypes.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/_ctypes.c	Thu Mar 27 00:48:05 2008
@@ -123,10 +123,136 @@
 PyObject *PyExc_ArgError;
 static PyTypeObject Simple_Type;
 
+/* a callable object used for unpickling */
+static PyObject *_unpickle;
+
 char *conversion_mode_encoding = NULL;
 char *conversion_mode_errors = NULL;
 
 
+/****************************************************************/
+
+typedef struct {
+	PyObject_HEAD
+	PyObject *key;
+	PyObject *dict;
+} DictRemoverObject;
+
+static void
+_DictRemover_dealloc(PyObject *_self)
+{
+	DictRemoverObject *self = (DictRemoverObject *)_self;
+	Py_XDECREF(self->key);
+	Py_XDECREF(self->dict);
+	Py_TYPE(self)->tp_free(_self);
+}
+
+static PyObject *
+_DictRemover_call(PyObject *_self, PyObject *args, PyObject *kw)
+{
+	DictRemoverObject *self = (DictRemoverObject *)_self;
+	if (self->key && self->dict) {
+		if (-1 == PyDict_DelItem(self->dict, self->key))
+			/* XXX Error context */
+			PyErr_WriteUnraisable(Py_None);
+		Py_DECREF(self->key);
+		self->key = NULL;
+		Py_DECREF(self->dict);
+		self->dict = NULL;
+	}
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+static PyTypeObject DictRemover_Type = {
+	PyVarObject_HEAD_INIT(NULL, 0)
+	"_ctypes.DictRemover",			/* tp_name */
+	sizeof(DictRemoverObject),		/* tp_basicsize */
+	0,					/* tp_itemsize */
+	_DictRemover_dealloc,			/* tp_dealloc */
+	0,					/* tp_print */
+	0,					/* tp_getattr */
+	0,					/* tp_setattr */
+	0,					/* tp_compare */
+	0,			       		/* tp_repr */
+	0,					/* tp_as_number */
+	0,					/* tp_as_sequence */
+	0,					/* tp_as_mapping */
+	0,					/* tp_hash */
+	_DictRemover_call,			/* tp_call */
+	0,					/* tp_str */
+	0,					/* tp_getattro */
+	0,					/* tp_setattro */
+	0,					/* tp_as_buffer */
+/* XXX should participate in GC? */
+	Py_TPFLAGS_DEFAULT,			/* tp_flags */
+	"deletes a key from a dictionary",	/* tp_doc */
+	0,					/* tp_traverse */
+	0,					/* tp_clear */
+	0,					/* tp_richcompare */
+	0,					/* tp_weaklistoffset */
+	0,					/* tp_iter */
+	0,					/* tp_iternext */
+	0,					/* 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 */
+	0,					/* tp_new */
+	0,					/* tp_free */
+};
+
+int
+PyDict_SetItemProxy(PyObject *dict, PyObject *key, PyObject *item)
+{
+	PyObject *obj;
+	DictRemoverObject *remover;
+	PyObject *proxy;
+	int result;
+
+	obj = PyObject_CallObject((PyObject *)&DictRemover_Type, NULL);
+	if (obj == NULL)
+		return -1;
+
+	remover = (DictRemoverObject *)obj;
+	assert(remover->key == NULL);
+	assert(remover->dict == NULL);
+	Py_INCREF(key);
+	remover->key = key;
+	Py_INCREF(dict);
+	remover->dict = dict;
+
+	proxy = PyWeakref_NewProxy(item, obj);
+	Py_DECREF(obj);
+	if (proxy == NULL)
+		return -1;
+
+	result = PyDict_SetItem(dict, key, proxy);
+	Py_DECREF(proxy);
+	return result;
+}
+
+PyObject *
+PyDict_GetItemProxy(PyObject *dict, PyObject *key)
+{
+	PyObject *result;
+	PyObject *item = PyDict_GetItem(dict, key);
+
+	if (item == NULL)
+		return NULL;
+	if (!PyWeakref_CheckProxy(item))
+		return item;
+	result = PyWeakref_GET_OBJECT(item);
+	if (result == Py_None)
+		return NULL;
+	return result;
+}
+
 /******************************************************************/
 /*
   StructType_Type - a meta type/class.  Creating a new class using this one as
@@ -236,7 +362,7 @@
 CDataType_from_address(PyObject *type, PyObject *value)
 {
 	void *buf;
-	if (!PyInt_Check(value) && !PyLong_Check(value)) {
+	if (!PyLong_Check(value)) {
 		PyErr_SetString(PyExc_TypeError,
 				"integer expected");
 		return NULL;
@@ -265,7 +391,7 @@
 	obj = PyObject_GetAttrString(dll, "_handle");
 	if (!obj)
 		return NULL;
-	if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
+	if (!PyLong_Check(obj)) {
 		PyErr_SetString(PyExc_TypeError,
 				"the _handle attribute of the second argument must be an integer");
 		Py_DECREF(obj);
@@ -328,7 +454,7 @@
 			Py_INCREF(value);
 			return value;
 		}
-		ob_name = (ob) ? Py_Type(ob)->tp_name : "???";
+		ob_name = (ob) ? Py_TYPE(ob)->tp_name : "???";
 		PyErr_Format(PyExc_TypeError,
 			     "expected %s instance instead of pointer to %s",
 			     ((PyTypeObject *)type)->tp_name, ob_name);
@@ -344,7 +470,7 @@
 	PyErr_Format(PyExc_TypeError,
 		     "expected %s instance instead of %s",
 		     ((PyTypeObject *)type)->tp_name,
-		     Py_Type(value)->tp_name);
+		     Py_TYPE(value)->tp_name);
 	return NULL;
 }
 
@@ -401,7 +527,7 @@
 StructType_setattro(PyObject *self, PyObject *key, PyObject *value)
 {
 	/* XXX Should we disallow deleting _fields_? */
-	if (-1 == PyObject_GenericSetAttr(self, key, value))
+	if (-1 == PyType_Type.tp_setattro(self, key, value))
 		return -1;
 	
 	if (value && PyUnicode_Check(key) &&
@@ -587,6 +713,7 @@
 	stgdict->length = 1;
 	stgdict->ffi_type_pointer = ffi_type_pointer;
 	stgdict->paramfunc = PointerType_paramfunc;
+	stgdict->flags |= TYPEFLAG_ISPOINTER;
 
 	proto = PyDict_GetItemString(typedict, "_type_"); /* Borrowed ref */
 	if (proto && -1 == PointerType_SetProto(stgdict, proto)) {
@@ -641,7 +768,7 @@
 	StgDictObject *typedict;
 
 	if (value == Py_None)
-		return PyInt_FromLong(0); /* NULL pointer */
+		return PyLong_FromLong(0); /* NULL pointer */
 
 	typedict = PyType_stgdict(type);
 	assert(typedict); /* Cannot be NULL for pointer types */
@@ -783,20 +910,26 @@
 	char *ptr;
 	Py_ssize_t size;
 
+	if (value == NULL) {
+		PyErr_SetString(PyExc_TypeError,
+				"can't delete attribute");
+		return -1;
+	}
+
 	if (PyUnicode_Check(value)) {
 		value = PyUnicode_AsEncodedString(value,
 						  conversion_mode_encoding,
 						  conversion_mode_errors);
 		if (!value)
 			return -1;
-	} else if (!PyBytes_Check(value)) {
+	} else if (!PyString_Check(value)) {
 		PyErr_Format(PyExc_TypeError,
 			     "str/bytes expected instead of %s instance",
-			     Py_Type(value)->tp_name);
+			     Py_TYPE(value)->tp_name);
 		return -1;
 	} else
 		Py_INCREF(value);
-	size = PyBytes_GET_SIZE(value);
+	size = PyString_GET_SIZE(value);
 	if (size > self->b_size) {
 		PyErr_SetString(PyExc_ValueError,
 				"string too long");
@@ -804,7 +937,7 @@
 		return -1;
 	}
 
-	ptr = PyBytes_AS_STRING(value);
+	ptr = PyString_AS_STRING(value);
 	memcpy(self->b_ptr, ptr, size);
 	if (size < self->b_size)
 		self->b_ptr[size] = '\0';
@@ -838,7 +971,12 @@
 {
 	Py_ssize_t result = 0;
 
-	if (PyBytes_Check(value)) {
+	if (value == NULL) {
+		PyErr_SetString(PyExc_TypeError,
+				"can't delete attribute");
+		return -1;
+	}
+	if (PyString_Check(value)) {
 		value = PyUnicode_FromEncodedObject(value,
 						    conversion_mode_encoding,
 						    conversion_mode_errors);
@@ -847,7 +985,7 @@
 	} else if (!PyUnicode_Check(value)) {
 		PyErr_Format(PyExc_TypeError,
 				"unicode string expected instead of %s instance",
-				Py_Type(value)->tp_name);
+				Py_TYPE(value)->tp_name);
 		return -1;
 	} else
 		Py_INCREF(value);
@@ -954,8 +1092,8 @@
 	StgDictObject *itemdict;
 	PyObject *proto;
 	PyObject *typedict;
-	int length;
-
+	long length;
+	int overflow;
 	Py_ssize_t itemsize, itemalign;
 
 	typedict = PyTuple_GetItem(args, 2);
@@ -963,13 +1101,18 @@
 		return NULL;
 
 	proto = PyDict_GetItemString(typedict, "_length_"); /* Borrowed ref */
-	if (!proto || !PyInt_CheckExact(proto)) {
+	if (!proto || !PyLong_Check(proto)) {
 		PyErr_SetString(PyExc_AttributeError,
 				"class must define a '_length_' attribute, "
 				"which must be a positive integer");
 		return NULL;
 	}
-	length = PyInt_AS_LONG(proto);
+	length = PyLong_AsLongAndOverflow(proto, &overflow);
+	if (overflow) {
+		PyErr_SetString(PyExc_OverflowError,
+				"The '_length_' attribute is too large");
+		return NULL;
+	}
 
 	proto = PyDict_GetItemString(typedict, "_type_"); /* Borrowed ref */
 	if (!proto) {
@@ -1000,6 +1143,9 @@
 
 	itemalign = itemdict->align;
 
+	if (itemdict->flags & (TYPEFLAG_ISPOINTER | TYPEFLAG_HASPOINTER))
+		stgdict->flags |= TYPEFLAG_HASPOINTER;
+
 	stgdict->size = itemsize * length;
 	stgdict->align = itemalign;
 	stgdict->length = length;
@@ -1096,7 +1242,7 @@
 
 */
 
-static char *SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOvtD";
+static char *SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOv?g";
 
 static PyObject *
 c_wchar_p_from_param(PyObject *type, PyObject *value)
@@ -1106,7 +1252,7 @@
 		Py_INCREF(Py_None);
 		return Py_None;
 	}
-	if (PyUnicode_Check(value) || PyBytes_Check(value)) {
+	if (PyUnicode_Check(value) || PyString_Check(value)) {
 		PyCArgObject *parg;
 		struct fielddesc *fd = getentry("Z");
 
@@ -1167,7 +1313,7 @@
 		Py_INCREF(Py_None);
 		return Py_None;
 	}
-	if (PyBytes_Check(value) || PyUnicode_Check(value)) {
+	if (PyString_Check(value) || PyUnicode_Check(value)) {
 		PyCArgObject *parg;
 		struct fielddesc *fd = getentry("z");
 
@@ -1233,7 +1379,7 @@
 	}
 	/* Should probably allow buffer interface as well */
 /* int, long */
-	if (PyInt_Check(value) || PyLong_Check(value)) {
+	if (PyLong_Check(value)) {
 		PyCArgObject *parg;
 		struct fielddesc *fd = getentry("P");
 
@@ -1391,9 +1537,9 @@
 
 	if (suffix == NULL)
 #ifdef WORDS_BIGENDIAN
-		suffix = PyUnicode_FromString("_le");
+		suffix = PyUnicode_InternFromString("_le");
 #else
-		suffix = PyUnicode_FromString("_be");
+		suffix = PyUnicode_InternFromString("_be");
 #endif
 
 	newname = PyUnicode_Concat(name, suffix);
@@ -1452,7 +1598,7 @@
 	
 	dict = PyObject_stgdict((PyObject *)self);
 	assert(dict); /* Cannot be NULL for CDataObject instances */
-	fmt = PyString_AsString(dict->proto);
+	fmt = PyUnicode_AsString(dict->proto);
 	assert(fmt);
 
 	fd = getentry(fmt);
@@ -1477,7 +1623,7 @@
 	StgDictObject *stgdict;
 	PyObject *proto;
 	const char *proto_str;
-	int proto_len;
+	Py_ssize_t proto_len;
 	PyMethodDef *ml;
 	struct fielddesc *fmt;
 
@@ -1567,12 +1713,21 @@
 		switch (*proto_str) {
 		case 'z': /* c_char_p */
 			ml = &c_char_p_method;
+			stgdict->flags |= TYPEFLAG_ISPOINTER;
 			break;
 		case 'Z': /* c_wchar_p */
 			ml = &c_wchar_p_method;
+			stgdict->flags |= TYPEFLAG_ISPOINTER;
 			break;
 		case 'P': /* c_void_p */
 			ml = &c_void_p_method;
+			stgdict->flags |= TYPEFLAG_ISPOINTER;
+			break;
+		case 'u':
+		case 'X':
+		case 'O':
+			ml = NULL;
+			stgdict->flags |= TYPEFLAG_ISPOINTER;
 			break;
 		default:
 			ml = NULL;
@@ -1644,7 +1799,7 @@
 	assert(dict);
 
 	/* I think we can rely on this being a one-character string */
-	fmt = PyString_AsString(dict->proto);
+	fmt = PyUnicode_AsString(dict->proto);
 	assert(fmt);
 	
 	fd = getentry(fmt);
@@ -1784,12 +1939,12 @@
 	stgdict->ffi_type_pointer = ffi_type_pointer;
 
 	ob = PyDict_GetItemString((PyObject *)stgdict, "_flags_");
-	if (!ob || !PyInt_Check(ob)) {
+	if (!ob || !PyLong_Check(ob)) {
 		PyErr_SetString(PyExc_TypeError,
 		    "class must define _flags_ which must be an integer");
 		return -1;
 	}
-	stgdict->flags = PyInt_AS_LONG(ob);
+	stgdict->flags = PyLong_AS_LONG(ob) | TYPEFLAG_ISPOINTER;
 
 	/* _argtypes_ is optional... */
 	ob = PyDict_GetItemString((PyObject *)stgdict, "_argtypes_");
@@ -1864,6 +2019,7 @@
 		return NULL;
 
 	stgdict->paramfunc = CFuncPtrType_paramfunc;
+	stgdict->flags |= TYPEFLAG_ISPOINTER;
 
 	/* create the new instance (which is a class,
 	   since we are a metatype!) */
@@ -2059,7 +2215,7 @@
 CData_dealloc(PyObject *self)
 {
 	CData_clear((CDataObject *)self);
-	Py_Type(self)->tp_free(self);
+	Py_TYPE(self)->tp_free(self);
 }
 
 static PyMemberDef CData_members[] = {
@@ -2096,6 +2252,45 @@
 	return -1;
 }
 
+static PyObject *
+CData_reduce(PyObject *_self, PyObject *args)
+{
+	CDataObject *self = (CDataObject *)_self;
+
+	if (PyObject_stgdict(_self)->flags & (TYPEFLAG_ISPOINTER|TYPEFLAG_HASPOINTER)) {
+		PyErr_SetString(PyExc_ValueError,
+				"ctypes objects containing pointers cannot be pickled");
+		return NULL;
+	}
+	return Py_BuildValue("O(O(NN))",
+			     _unpickle,
+			     Py_TYPE(_self),
+			     PyObject_GetAttrString(_self, "__dict__"),
+			     PyString_FromStringAndSize(self->b_ptr, self->b_size));
+}
+
+static PyObject *
+CData_setstate(PyObject *_self, PyObject *args)
+{
+	void *data;
+	int len;
+	int res;
+	PyObject *dict, *mydict;
+	CDataObject *self = (CDataObject *)_self;
+	if (!PyArg_ParseTuple(args, "Os#", &dict, &data, &len))
+		return NULL;
+	if (len > self->b_size)
+		len = self->b_size;
+	memmove(self->b_ptr, data, len);
+	mydict = PyObject_GetAttrString(_self, "__dict__");
+	res = PyDict_Update(mydict, dict);
+	Py_DECREF(mydict);
+	if (res == -1)
+		return NULL;
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
 /*
  * default __ctypes_from_outparam__ method returns self.
  */
@@ -2108,6 +2303,8 @@
 
 static PyMethodDef CData_methods[] = {
 	{ "__ctypes_from_outparam__", CData_from_outparam, METH_NOARGS, },
+	{ "__reduce__", CData_reduce, METH_NOARGS, },
+	{ "__setstate__", CData_setstate, METH_VARARGS, },
 	{ NULL, NULL },
 };
 
@@ -2318,7 +2515,7 @@
 			PyErr_Format(PyExc_TypeError,
 				     "expected %s instance, got %s",
 				     ((PyTypeObject *)type)->tp_name,
-				     Py_Type(value)->tp_name);
+				     Py_TYPE(value)->tp_name);
 			return NULL;
 		}
 	}
@@ -2349,7 +2546,7 @@
 		if (p1->proto != p2->proto) {
 			PyErr_Format(PyExc_TypeError,
 				     "incompatible types, %s instance instead of %s instance",
-				     Py_Type(value)->tp_name,
+				     Py_TYPE(value)->tp_name,
 				     ((PyTypeObject *)type)->tp_name);
 			return NULL;
 		}
@@ -2364,11 +2561,11 @@
 		  only it's object list.  So we create a tuple, containing
 		  b_objects list PLUS the array itself, and return that!
 		*/
-		return Py_BuildValue("(OO)", keep, value);
+		return PyTuple_Pack(2, keep, value);
 	}
 	PyErr_Format(PyExc_TypeError,
 		     "incompatible types, %s instance instead of %s instance",
-		     Py_Type(value)->tp_name,
+		     Py_TYPE(value)->tp_name,
 		     ((PyTypeObject *)type)->tp_name);
 	return NULL;
 }
@@ -2629,7 +2826,7 @@
 		     Py_SAFE_DOWNCAST(index, Py_ssize_t, int),
 		     PyType_Check(arg) ?
 		     ((PyTypeObject *)arg)->tp_name :
-		     Py_Type(arg)->tp_name);
+		     Py_TYPE(arg)->tp_name);
 	return 0;
 }
 
@@ -2667,7 +2864,7 @@
 		char *name;
 		PyObject *defval;
 		PyObject *typ;
-		if (!PyArg_ParseTuple(item, "i|zO", &flag, &name, &defval)) {
+		if (!PyArg_ParseTuple(item, "i|ZO", &flag, &name, &defval)) {
 			PyErr_SetString(PyExc_TypeError,
 			       "paramflags must be a sequence of (int [,string [,value]]) tuples");
 			return 0;
@@ -2697,16 +2894,20 @@
 _get_name(PyObject *obj, char **pname)
 {
 #ifdef MS_WIN32
-	if (PyInt_Check(obj) || PyLong_Check(obj)) {
+	if (PyLong_Check(obj)) {
 		/* We have to use MAKEINTRESOURCEA for Windows CE.
 		   Works on Windows as well, of course.
 		*/
-		*pname = MAKEINTRESOURCEA(PyInt_AsUnsignedLongMask(obj) & 0xFFFF);
+		*pname = MAKEINTRESOURCEA(PyLong_AsUnsignedLongMask(obj) & 0xFFFF);
 		return 1;
 	}
 #endif
-	if (PyString_Check(obj) || PyUnicode_Check(obj)) {
-		*pname = PyString_AsString(obj);
+	if (PyString_Check(obj)) {
+		*pname = PyString_AS_STRING(obj);
+		return *pname ? 1 : 0;
+	}
+	if (PyUnicode_Check(obj)) {
+		*pname = PyUnicode_AsString(obj);
 		return *pname ? 1 : 0;
 	}
 	PyErr_SetString(PyExc_TypeError,
@@ -2734,7 +2935,7 @@
 	obj = PyObject_GetAttrString(dll, "_handle");
 	if (!obj)
 		return NULL;
-	if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
+	if (!PyLong_Check(obj)) {
 		PyErr_SetString(PyExc_TypeError,
 				"the _handle attribute of the second argument must be an integer");
 		Py_DECREF(obj);
@@ -2854,16 +3055,15 @@
 		return CFuncPtr_FromDll(type, args, kwds);
 
 #ifdef MS_WIN32
-	if (2 <= PyTuple_GET_SIZE(args) && PyInt_Check(PyTuple_GET_ITEM(args, 0)))
+	if (2 <= PyTuple_GET_SIZE(args) && PyLong_Check(PyTuple_GET_ITEM(args, 0)))
 		return CFuncPtr_FromVtblIndex(type, args, kwds);
 #endif
 
 	if (1 == PyTuple_GET_SIZE(args)
-	    && (PyInt_Check(PyTuple_GET_ITEM(args, 0))
-		|| PyLong_Check(PyTuple_GET_ITEM(args, 0)))) {
+	    && (PyLong_Check(PyTuple_GET_ITEM(args, 0)))) {
 		CDataObject *ob;
 		void *ptr = PyLong_AsVoidPtr(PyTuple_GET_ITEM(args, 0));
-		if (ptr == NULL)
+		if (ptr == NULL && PyErr_Occurred())
 			return NULL;
 		ob = (CDataObject *)GenericCData_new(type, args, kwds);
 		if (ob == NULL)
@@ -2967,7 +3167,7 @@
 }
 
 static PyObject *
-_get_arg(int *pindex, char *name, PyObject *defval, PyObject *inargs, PyObject *kwds)
+_get_arg(int *pindex, PyObject *name, PyObject *defval, PyObject *inargs, PyObject *kwds)
 {
 	PyObject *v;
 
@@ -2977,7 +3177,7 @@
 		Py_INCREF(v);
 		return v;
 	}
-	if (kwds && (v = PyDict_GetItemString(kwds, name))) {
+	if (kwds && (v = PyDict_GetItem(kwds, name))) {
 		++*pindex;
 		Py_INCREF(v);
 		return v;
@@ -2989,7 +3189,7 @@
 	/* we can't currently emit a better error message */
 	if (name)
 		PyErr_Format(PyExc_TypeError,
-			     "required argument '%s' missing", name);
+			     "required argument '%S' missing", name);
 	else
 		PyErr_Format(PyExc_TypeError,
 			     "not enough arguments");
@@ -3058,15 +3258,15 @@
 		PyObject *item = PyTuple_GET_ITEM(paramflags, i);
 		PyObject *ob;
 		int flag;
-		char *name = NULL;
+		PyObject *name = NULL;
 		PyObject *defval = NULL;
 
 		/* This way seems to be ~2 us faster than the PyArg_ParseTuple
 		   calls below. */
-		/* We HAVE already checked that the tuple can be parsed with "i|zO", so... */
+		/* We HAVE already checked that the tuple can be parsed with "i|ZO", so... */
 		Py_ssize_t tsize = PyTuple_GET_SIZE(item);
-		flag = PyInt_AS_LONG(PyTuple_GET_ITEM(item, 0));
-		name = tsize > 1 ? PyString_AS_STRING(PyTuple_GET_ITEM(item, 1)) : NULL;
+		flag = PyLong_AS_LONG(PyTuple_GET_ITEM(item, 0));
+		name = tsize > 1 ? PyTuple_GET_ITEM(item, 1) : NULL;
 		defval = tsize > 2 ? PyTuple_GET_ITEM(item, 2) : NULL;
 
 		switch (flag & (PARAMFLAG_FIN | PARAMFLAG_FOUT | PARAMFLAG_FLCID)) {
@@ -3074,7 +3274,7 @@
 			/* ['in', 'lcid'] parameter.  Always taken from defval,
 			 if given, else the integer 0. */
 			if (defval == NULL) {
-				defval = PyInt_FromLong(0);
+				defval = PyLong_FromLong(0);
 				if (defval == NULL)
 					goto error;
 			} else
@@ -3411,7 +3611,7 @@
 CFuncPtr_dealloc(CFuncPtrObject *self)
 {
 	CFuncPtr_clear(self);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *
@@ -3421,11 +3621,11 @@
 	if (self->index)
 		return PyUnicode_FromFormat("<COM method offset %d: %s at %p>",
 					   self->index - 0x1000,
-					   Py_Type(self)->tp_name,
+					   Py_TYPE(self)->tp_name,
 					   self);
 #endif
 	return PyUnicode_FromFormat("<%s object at %p>",
-				   Py_Type(self)->tp_name,
+				   Py_TYPE(self)->tp_name,
 				   self);
 }
 
@@ -3511,7 +3711,7 @@
 
 		if (PyTuple_GET_SIZE(args) > PySequence_Length(fields)) {
 			Py_DECREF(fields);
-			PyErr_SetString(PyExc_ValueError,
+			PyErr_SetString(PyExc_TypeError,
 					"too many initializers");
 			return -1;
 		}
@@ -3532,6 +3732,21 @@
 				return IBUG("_fields_[i][0] failed");
 			}
 
+			if (kwds && PyDict_GetItem(kwds, name)) {
+				char *field = PyString_AsString(name);
+				if (field == NULL) {
+					PyErr_Clear();
+					field = "???";
+				}
+				PyErr_Format(PyExc_TypeError,
+					     "duplicate values for field %s",
+					     field);
+				Py_DECREF(pair);
+				Py_DECREF(name);
+				Py_DECREF(fields);
+				return -1;
+			}
+
 			val = PyTuple_GET_ITEM(args, i);
 			if (-1 == PyObject_SetAttr(self, name, val)) {
 				Py_DECREF(pair);
@@ -3731,10 +3946,10 @@
 			char *dest;
 
 			if (slicelen <= 0)
-				return PyString_FromString("");
+				return PyString_FromStringAndSize("", 0);
 			if (step == 1) {
 				return PyString_FromStringAndSize(ptr + start,
-								  slicelen);
+								 slicelen);
 			}
 			dest = (char *)PyMem_Malloc(slicelen);
 
@@ -3957,16 +4172,21 @@
 	PyObject *key;
 	PyObject *result;
 	char name[256];
+	PyObject *len;
 
 	if (cache == NULL) {
 		cache = PyDict_New();
 		if (cache == NULL)
 			return NULL;
 	}
-	key = Py_BuildValue("(On)", itemtype, length);
+	len = PyLong_FromSsize_t(length);
+	if (len == NULL)
+		return NULL;
+	key = PyTuple_Pack(2, itemtype, len);
+	Py_DECREF(len);
 	if (!key)
 		return NULL;
-	result = PyDict_GetItem(cache, key);
+	result = PyDict_GetItemProxy(cache, key);
 	if (result) {
 		Py_INCREF(result);
 		Py_DECREF(key);
@@ -3995,9 +4215,15 @@
 				       "_type_",
 				       itemtype
 		);
-	if (!result)
+	if (result == NULL) {
+		Py_DECREF(key);
+		return NULL;
+	}
+	if (-1 == PyDict_SetItemProxy(cache, key, result)) {
+		Py_DECREF(key);
+		Py_DECREF(result);
 		return NULL;
-	PyDict_SetItem(cache, key, result);
+	}
 	Py_DECREF(key);
 	return result;
 }
@@ -4014,6 +4240,11 @@
 	PyObject *result;
 	StgDictObject *dict = PyObject_stgdict((PyObject *)self);
 
+	if (value == NULL) {
+		PyErr_SetString(PyExc_TypeError,
+				"can't delete attribute");
+		return -1;
+	}
 	assert(dict); /* Cannot be NULL for CDataObject instances */
 	assert(dict->setfunc);
 	result = dict->setfunc(self->b_ptr, value, dict->size);
@@ -4054,7 +4285,7 @@
 static PyObject *
 Simple_from_outparm(PyObject *self, PyObject *args)
 {
-	if (IsSimpleSubType((PyObject *)Py_Type(self))) {
+	if (IsSimpleSubType((PyObject *)Py_TYPE(self))) {
 		Py_INCREF(self);
 		return self;
 	}
@@ -4092,13 +4323,13 @@
 	PyObject *val, *name, *args, *result;
 	static PyObject *format;
 
-	if (Py_Type(self)->tp_base != &Simple_Type) {
+	if (Py_TYPE(self)->tp_base != &Simple_Type) {
 		return PyUnicode_FromFormat("<%s object at %p>",
-					   Py_Type(self)->tp_name, self);
+					   Py_TYPE(self)->tp_name, self);
 	}
 
 	if (format == NULL) {
-		format = PyUnicode_FromString("%s(%r)");
+		format = PyUnicode_InternFromString("%s(%r)");
 		if (format == NULL)
 			return NULL;
 	}
@@ -4107,7 +4338,7 @@
 	if (val == NULL)
 		return NULL;
 
-	name = PyUnicode_FromString(Py_Type(self)->tp_name);
+	name = PyUnicode_FromString(Py_TYPE(self)->tp_name);
 	if (name == NULL) {
 		Py_DECREF(val);
 		return NULL;
@@ -4278,7 +4509,7 @@
 		PyErr_Format(PyExc_TypeError,
 			     "expected %s instead of %s",
 			     ((PyTypeObject *)(stgdict->proto))->tp_name,
-			     Py_Type(value)->tp_name);
+			     Py_TYPE(value)->tp_name);
 		return -1;
 	}
 
@@ -4408,10 +4639,10 @@
 			char *dest;
 			
 			if (len <= 0)
-                        	return PyString_FromString("");
+                        	return PyString_FromStringAndSize("", 0);
 			if (step == 1) {
 				return PyString_FromStringAndSize(ptr + start,
-								  len);
+								 len);
 			}
 			dest = (char *)PyMem_Malloc(len);
 			if (dest == NULL)
@@ -4556,96 +4787,95 @@
 
 static char comerror_doc[] = "Raised when a COM method call failed.";
 
-static PyObject *
-comerror_str(PyObject *ignored, PyObject *self)
-{
-	PyObject *args = PyObject_GetAttrString(self, "args");
-	PyObject *result;
-	if (args == NULL)
-		return NULL;
-	result = PyObject_Str(args);
-	Py_DECREF(args);
-	return result;
-}
-
-static PyObject *
-comerror_init(PyObject *self, PyObject *args)
+int
+comerror_init(PyObject *self, PyObject *args, PyObject *kwds)
 {
     PyObject *hresult, *text, *details;
+    PyBaseExceptionObject *bself;
     PyObject *a;
     int status;
 
-    if (!PyArg_ParseTuple(args, "OOOO:COMError", &self, &hresult, &text, &details))
-	    return NULL;
+    if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds))
+        return -1;
+
+    if (!PyArg_ParseTuple(args, "OOO:COMError", &hresult, &text, &details))
+	    return -1;
 
     a = PySequence_GetSlice(args, 1, PySequence_Size(args));
     if (!a)
-        return NULL;
+        return -1;
     status = PyObject_SetAttrString(self, "args", a);
     Py_DECREF(a);
     if (status < 0)
-        return NULL;
+        return -1;
 
     if (PyObject_SetAttrString(self, "hresult", hresult) < 0)
-	    return NULL;
+	    return -1;
 
     if (PyObject_SetAttrString(self, "text", text) < 0)
-	    return NULL;
+	    return -1;
 
     if (PyObject_SetAttrString(self, "details", details) < 0)
-	    return NULL;
-
-    Py_INCREF(Py_None);
-    return Py_None;
-}
+	    return -1;
 
-static PyMethodDef comerror_methods[] = {
-	{ "__str__", comerror_str, METH_O },
-	{ "__init__", comerror_init, METH_VARARGS },
-	{ NULL, NULL },
+    bself = (PyBaseExceptionObject *)self;
+    Py_DECREF(bself->args);
+    bself->args = args;
+    Py_INCREF(bself->args);
+
+    return 0;
+}
+
+static PyTypeObject PyComError_Type = {
+    PyVarObject_HEAD_INIT(NULL, 0)
+    "_ctypes.COMError",         /* tp_name */
+    sizeof(PyBaseExceptionObject), /* tp_basicsize */
+    0,                          /* tp_itemsize */
+    0,                          /* tp_dealloc */
+    0,                          /* tp_print */
+    0,                          /* tp_getattr */
+    0,                          /* tp_setattr */
+    0,                          /* tp_compare */
+    0,                          /* tp_repr */
+    0,                          /* tp_as_number */
+    0,                          /* tp_as_sequence */
+    0,                          /* tp_as_mapping */
+    0,                          /* tp_hash */
+    0,                          /* tp_call */
+    0,                          /* tp_str */
+    0,                          /* tp_getattro */
+    0,                          /* tp_setattro */
+    0,                          /* tp_as_buffer */
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
+        | Py_TPFLAGS_HAVE_GC,   /* tp_flags */
+    PyDoc_STR(comerror_doc),    /* tp_doc */
+    0,                          /* tp_traverse */
+    0,                          /* tp_clear */
+    0,                          /* tp_richcompare */
+    0,                          /* tp_weaklistoffset */
+    0,                          /* tp_iter */
+    0,                          /* tp_iternext */
+    0,                          /* 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 */
+    (initproc)comerror_init,    /* tp_init */
+    0,                          /* tp_alloc */
+    0,                          /* tp_new */
 };
 
-PyObject *COMError;
 
 static int
 create_comerror(void)
 {
-	PyObject *dict = PyDict_New();
-	PyMethodDef *methods = comerror_methods;
-	PyObject *s;
-	int status;
-
-	while (methods->ml_name) {
-		/* get a wrapper for the built-in function */
-		PyObject *func = PyCFunction_New(methods, NULL);
-		PyObject *meth;
-		if (func == NULL)
-			return -1;
-		meth = PyMethod_New(func, NULL, ComError);
-		Py_DECREF(func);
-		if (meth == NULL)
-			return -1;
-		PyDict_SetItemString(dict, methods->ml_name, meth);
-		Py_DECREF(meth);
-		++methods;
-	}
-
-	s = PyString_FromString(comerror_doc);
-	if (s == NULL)
-		return -1;
-	status = PyDict_SetItemString(dict, "__doc__", s);
-	Py_DECREF(s);
-	if (status == -1) {
-		Py_DECREF(dict);
-		return -1;
-	}
-
-	ComError = PyErr_NewException("_ctypes.COMError",
-				      NULL,
-				      dict);
-	if (ComError == NULL)
+	PyComError_Type.tp_base = (PyTypeObject*)PyExc_Exception;
+	if (PyType_Ready(&PyComError_Type) < 0)
 		return -1;
-
+	ComError = (PyObject*)&PyComError_Type;
 	return 0;
 }
 
@@ -4655,7 +4885,7 @@
 string_at(const char *ptr, int size)
 {
 	if (size == -1)
-		return PyString_FromString(ptr);
+		return PyString_FromStringAndSize(ptr, strlen(ptr));
 	return PyString_FromStringAndSize(ptr, size);
 }
 
@@ -4680,7 +4910,7 @@
 		     "cast() argument 2 must be a pointer type, not %s",
 		     PyType_Check(arg)
 		     ? ((PyTypeObject *)arg)->tp_name
-		     : Py_Type(arg)->tp_name);
+		     : Py_TYPE(arg)->tp_name);
 	return 0;
 }
 
@@ -4762,6 +4992,10 @@
 	if (!m)
 		return;
 
+	_unpickle = PyObject_GetAttrString(m, "_unpickle");
+	if (_unpickle == NULL)
+		return;
+
 	if (PyType_Ready(&PyCArg_Type) < 0)
 		return;
 
@@ -4807,37 +5041,37 @@
 	if (PyType_Ready(&CData_Type) < 0)
 		return;
 
-	Py_Type(&Struct_Type) = &StructType_Type;
+	Py_TYPE(&Struct_Type) = &StructType_Type;
 	Struct_Type.tp_base = &CData_Type;
 	if (PyType_Ready(&Struct_Type) < 0)
 		return;
 	PyModule_AddObject(m, "Structure", (PyObject *)&Struct_Type);
 
-	Py_Type(&Union_Type) = &UnionType_Type;
+	Py_TYPE(&Union_Type) = &UnionType_Type;
 	Union_Type.tp_base = &CData_Type;
 	if (PyType_Ready(&Union_Type) < 0)
 		return;
 	PyModule_AddObject(m, "Union", (PyObject *)&Union_Type);
 
-	Py_Type(&Pointer_Type) = &PointerType_Type;
+	Py_TYPE(&Pointer_Type) = &PointerType_Type;
 	Pointer_Type.tp_base = &CData_Type;
 	if (PyType_Ready(&Pointer_Type) < 0)
 		return;
 	PyModule_AddObject(m, "_Pointer", (PyObject *)&Pointer_Type);
 
-	Py_Type(&Array_Type) = &ArrayType_Type;
+	Py_TYPE(&Array_Type) = &ArrayType_Type;
 	Array_Type.tp_base = &CData_Type;
 	if (PyType_Ready(&Array_Type) < 0)
 		return;
 	PyModule_AddObject(m, "Array", (PyObject *)&Array_Type);
 
-	Py_Type(&Simple_Type) = &SimpleType_Type;
+	Py_TYPE(&Simple_Type) = &SimpleType_Type;
 	Simple_Type.tp_base = &CData_Type;
 	if (PyType_Ready(&Simple_Type) < 0)
 		return;
 	PyModule_AddObject(m, "_SimpleCData", (PyObject *)&Simple_Type);
 
-	Py_Type(&CFuncPtr_Type) = &CFuncPtrType_Type;
+	Py_TYPE(&CFuncPtr_Type) = &CFuncPtrType_Type;
 	CFuncPtr_Type.tp_base = &CData_Type;
 	if (PyType_Ready(&CFuncPtr_Type) < 0)
 		return;
@@ -4857,16 +5091,20 @@
 	 * Other stuff
 	 */
 
+	DictRemover_Type.tp_new = PyType_GenericNew;
+	if (PyType_Ready(&DictRemover_Type) < 0)
+		return;
+
 #ifdef MS_WIN32
 	if (create_comerror() < 0)
 		return;
 	PyModule_AddObject(m, "COMError", ComError);
 
-	PyModule_AddObject(m, "FUNCFLAG_HRESULT", PyInt_FromLong(FUNCFLAG_HRESULT));
-	PyModule_AddObject(m, "FUNCFLAG_STDCALL", PyInt_FromLong(FUNCFLAG_STDCALL));
+	PyModule_AddObject(m, "FUNCFLAG_HRESULT", PyLong_FromLong(FUNCFLAG_HRESULT));
+	PyModule_AddObject(m, "FUNCFLAG_STDCALL", PyLong_FromLong(FUNCFLAG_STDCALL));
 #endif
-	PyModule_AddObject(m, "FUNCFLAG_CDECL", PyInt_FromLong(FUNCFLAG_CDECL));
-	PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyInt_FromLong(FUNCFLAG_PYTHONAPI));
+	PyModule_AddObject(m, "FUNCFLAG_CDECL", PyLong_FromLong(FUNCFLAG_CDECL));
+	PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyLong_FromLong(FUNCFLAG_PYTHONAPI));
 	PyModule_AddStringConstant(m, "__version__", "1.1.0");
 
 	PyModule_AddObject(m, "_memmove_addr", PyLong_FromVoidPtr(memmove));
@@ -4889,8 +5127,8 @@
 #define RTLD_GLOBAL RTLD_LOCAL
 #endif
 
-	PyModule_AddObject(m, "RTLD_LOCAL", PyInt_FromLong(RTLD_LOCAL));
-	PyModule_AddObject(m, "RTLD_GLOBAL", PyInt_FromLong(RTLD_GLOBAL));
+	PyModule_AddObject(m, "RTLD_LOCAL", PyLong_FromLong(RTLD_LOCAL));
+	PyModule_AddObject(m, "RTLD_GLOBAL", PyLong_FromLong(RTLD_GLOBAL));
 	
 	PyExc_ArgError = PyErr_NewException("ctypes.ArgumentError", NULL, NULL);
 	if (PyExc_ArgError) {

Modified: python/branches/py3k-importlib/Modules/_ctypes/_ctypes_test.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/_ctypes_test.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/_ctypes_test.c	Thu Mar 27 00:48:05 2008
@@ -12,6 +12,15 @@
 
 /* some functions handy for testing */
 
+EXPORT(void)testfunc_array(int values[4])
+{
+	printf("testfunc_array %d %d %d %d\n",
+	       values[0],
+	       values[1],
+	       values[2],
+	       values[3]);
+}
+
 EXPORT(long double)testfunc_Ddd(double a, double b)
 {
 	long double result = (long double)(a * b);
@@ -398,7 +407,7 @@
 	return 0;
 }
 
-PyMethodDef module_methods[] = {
+static PyMethodDef module_methods[] = {
 /*	{"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS},
 	{"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS},
 */

Modified: python/branches/py3k-importlib/Modules/_ctypes/callbacks.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/callbacks.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/callbacks.c	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,7 @@
 	va_start(marker, msg);
 	vsnprintf(buf, sizeof(buf), msg, marker);
 	va_end(marker);
-	if (f)
+	if (f != NULL && f != Py_None)
 		PyFile_WriteString(buf, f);
 	PyErr_Print();
 }
@@ -197,7 +197,7 @@
 	}
 
 #define CHECK(what, x) \
-if (x == NULL) _AddTraceback(what, __FILE__, __LINE__ - 1), PyErr_Print()
+if (x == NULL) _AddTraceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print()
 
 	result = PyObject_CallObject(callable, arglist);
 	CHECK("'calling callback function'", result);
@@ -365,9 +365,9 @@
 	static PyObject *context;
 
 	if (context == NULL)
-		context = PyString_FromString("_ctypes.DllGetClassObject");
+		context = PyUnicode_InternFromString("_ctypes.DllGetClassObject");
 
-	mod = PyImport_ImportModule("ctypes");
+	mod = PyImport_ImportModuleNoBlock("ctypes");
 	if (!mod) {
 		PyErr_WriteUnraisable(context ? context : Py_None);
 		/* There has been a warning before about this already */
@@ -408,7 +408,7 @@
 		return E_FAIL;
 	}
 
-	retval = PyInt_AsLong(result);
+	retval = PyLong_AsLong(result);
 	if (PyErr_Occurred()) {
 		PyErr_WriteUnraisable(context ? context : Py_None);
 		retval = E_FAIL;
@@ -444,9 +444,9 @@
 	static PyObject *context;
 
 	if (context == NULL)
-		context = PyString_FromString("_ctypes.DllCanUnloadNow");
+		context = PyUnicode_InternFromString("_ctypes.DllCanUnloadNow");
 
-	mod = PyImport_ImportModule("ctypes");
+	mod = PyImport_ImportModuleNoBlock("ctypes");
 	if (!mod) {
 /*		OutputDebugString("Could not import ctypes"); */
 		/* We assume that this error can only occur when shutting
@@ -469,7 +469,7 @@
 		return E_FAIL;
 	}
 
-	retval = PyInt_AsLong(result);
+	retval = PyLong_AsLong(result);
 	if (PyErr_Occurred()) {
 		PyErr_WriteUnraisable(context ? context : Py_None);
 		retval = E_FAIL;

Modified: python/branches/py3k-importlib/Modules/_ctypes/callproc.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/callproc.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/callproc.c	Thu Mar 27 00:48:05 2008
@@ -269,7 +269,7 @@
 		return NULL;
 	if (FAILED(hr))
 		return PyErr_SetFromWindowsErr(hr);
-	return PyInt_FromLong(hr);
+	return PyLong_FromLong(hr);
 }
 
 #endif
@@ -507,9 +507,9 @@
 		return 0;
 	}
 
-	if (PyBytes_Check(obj)) {
+	if (PyString_Check(obj)) {
 		pa->ffi_type = &ffi_type_pointer;
-		pa->value.p = PyBytes_AsString(obj);
+		pa->value.p = PyString_AsString(obj);
 		Py_INCREF(obj);
 		pa->keep = obj;
 		return 0;
@@ -727,7 +727,7 @@
 	PyObject *retval, *v;
 
 	if (restype == NULL)
-		return PyInt_FromLong(*(int *)result);
+		return PyLong_FromLong(*(int *)result);
 
 	if (restype == Py_None) {
 		Py_INCREF(Py_None);
@@ -755,7 +755,7 @@
 
 	v = PyObject_CallFunctionObjArgs(checker, retval, NULL);
 	if (v == NULL)
-		_AddTraceback("GetResult", __FILE__, __LINE__-2);
+		_AddTraceback("GetResult", "_ctypes/callproc.c", __LINE__-2);
 	Py_DECREF(retval);
 	return v;
 }
@@ -770,7 +770,7 @@
 	PyObject *tp, *v, *tb, *s, *cls_str, *msg_str;
 
 	va_start(vargs, fmt);
-	s = PyString_FromFormatV(fmt, vargs);
+	s = PyUnicode_FromFormatV(fmt, vargs);
 	va_end(vargs);
 	if (!s)
 		return;
@@ -779,18 +779,18 @@
 	PyErr_NormalizeException(&tp, &v, &tb);
 	cls_str = PyObject_Str(tp);
 	if (cls_str) {
-		PyString_ConcatAndDel(&s, cls_str);
-		PyString_ConcatAndDel(&s, PyString_FromString(": "));
+		PyUnicode_AppendAndDel(&s, cls_str);
+		PyUnicode_AppendAndDel(&s, PyUnicode_FromString(": "));
 		if (s == NULL)
 			goto error;
 	} else
 		PyErr_Clear();
 	msg_str = PyObject_Str(v);
 	if (msg_str)
-		PyString_ConcatAndDel(&s, msg_str);
+		PyUnicode_AppendAndDel(&s, msg_str);
 	else {
 		PyErr_Clear();
-		PyString_ConcatAndDel(&s, PyString_FromString("???"));
+		PyUnicode_AppendAndDel(&s, PyUnicode_FromString("???"));
 		if (s == NULL)
 			goto error;
 	}
@@ -1020,12 +1020,12 @@
 		if (*(int *)resbuf & 0x80000000)
 			retval = GetComError(*(HRESULT *)resbuf, iid, pIunk);
 		else
-			retval = PyInt_FromLong(*(int *)resbuf);
+			retval = PyLong_FromLong(*(int *)resbuf);
 	} else if (flags & FUNCFLAG_HRESULT) {
 		if (*(int *)resbuf & 0x80000000)
 			retval = PyErr_SetFromWindowsErr(*(int *)resbuf);
 		else
-			retval = PyInt_FromLong(*(int *)resbuf);
+			retval = PyLong_FromLong(*(int *)resbuf);
 	} else
 #endif
 		retval = GetResult(restype, resbuf, checker);
@@ -1087,34 +1087,18 @@
 module.\n";
 static PyObject *load_library(PyObject *self, PyObject *args)
 {
-	TCHAR *name;
+	WCHAR *name;
 	PyObject *nameobj;
 	PyObject *ignored;
 	HMODULE hMod;
 	if (!PyArg_ParseTuple(args, "O|O:LoadLibrary", &nameobj, &ignored))
 		return NULL;
-#ifdef _UNICODE
-	name = alloca((PyString_Size(nameobj) + 1) * sizeof(WCHAR));
-	if (!name) {
-		PyErr_NoMemory();
-		return NULL;
-	}
 
-	{
-		int r;
-		char *aname = PyString_AsString(nameobj);
-		if(!aname)
-			return NULL;
-		r = MultiByteToWideChar(CP_ACP, 0, aname, -1, name, PyString_Size(nameobj) + 1);
-		name[r] = 0;
-	}
-#else
-	name = PyString_AsString(nameobj);
-	if(!name)
+	name = PyUnicode_AsUnicode(nameobj);
+	if (!name)
 		return NULL;
-#endif
 
-	hMod = LoadLibrary(name);
+	hMod = LoadLibraryW(name);
 	if (!hMod)
 		return PyErr_SetFromWindowsErr(GetLastError());
 #ifdef _WIN64
@@ -1169,7 +1153,7 @@
 	if (!CDataObject_Check(pcom) || (pcom->b_size != sizeof(void *))) {
 		PyErr_Format(PyExc_TypeError,
 			     "COM Pointer expected instead of %s instance",
-			     Py_Type(pcom)->tp_name);
+			     Py_TYPE(pcom)->tp_name);
 		return NULL;
 	}
 
@@ -1214,12 +1198,12 @@
 	pdst = (IUnknown **)b.value.p;
 
 	if (pdst == NULL)
-		r = PyInt_FromLong(E_POINTER);
+		r = PyLong_FromLong(E_POINTER);
 	else {
 		if (src)
 			src->lpVtbl->AddRef(src);
 		*pdst = src;
-		r = PyInt_FromLong(S_OK);
+		r = PyLong_FromLong(S_OK);
 	}
   done:
 	Py_XDECREF(a.keep);
@@ -1361,10 +1345,10 @@
 
 	dict = PyType_stgdict(obj);
 	if (dict)
-		return PyInt_FromSsize_t(dict->size);
+		return PyLong_FromSsize_t(dict->size);
 
 	if (CDataObject_Check(obj))
-		return PyInt_FromSsize_t(((CDataObject *)obj)->b_size);
+		return PyLong_FromSsize_t(((CDataObject *)obj)->b_size);
 	PyErr_SetString(PyExc_TypeError,
 			"this type has no size");
 	return NULL;
@@ -1382,11 +1366,11 @@
 
 	dict = PyType_stgdict(obj);
 	if (dict)
-		return PyInt_FromSsize_t(dict->align);
+		return PyLong_FromSsize_t(dict->align);
 
 	dict = PyObject_stgdict(obj);
 	if (dict)
-		return PyInt_FromSsize_t(dict->align);
+		return PyLong_FromSsize_t(dict->align);
 
 	PyErr_SetString(PyExc_TypeError,
 			"no alignment info");
@@ -1409,7 +1393,7 @@
 	if (!CDataObject_Check(obj)) {
 		PyErr_Format(PyExc_TypeError,
 			     "byref() argument must be a ctypes instance, not '%s'",
-			     Py_Type(obj)->tp_name);
+			     Py_TYPE(obj)->tp_name);
 		return NULL;
 	}
 
@@ -1559,7 +1543,30 @@
 	return Py_None;
 }
 
+static PyObject *
+unpickle(PyObject *self, PyObject *args)
+{
+	PyObject *typ;
+	PyObject *state;
+	PyObject *result;
+	PyObject *tmp;
+
+	if (!PyArg_ParseTuple(args, "OO", &typ, &state))
+		return NULL;
+	result = PyObject_CallMethod(typ, "__new__", "O", typ);
+	if (result == NULL)
+		return NULL;
+	tmp = PyObject_CallMethod(result, "__setstate__", "O", state);
+	if (tmp == NULL) {
+		Py_DECREF(result);
+		return NULL;
+	}
+	Py_DECREF(tmp);
+	return result;
+}
+
 PyMethodDef module_methods[] = {
+	{"_unpickle", unpickle, METH_VARARGS },
 	{"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},

Modified: python/branches/py3k-importlib/Modules/_ctypes/cfield.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/cfield.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/cfield.c	Thu Mar 27 00:48:05 2008
@@ -195,6 +195,11 @@
 	assert(CDataObject_Check(inst));
 	dst = (CDataObject *)inst;
 	ptr = dst->b_ptr + self->offset;
+	if (value == NULL) {
+		PyErr_SetString(PyExc_TypeError,
+				"can't delete attribute");
+		return -1;
+	}
 	return CData_set(inst, self->proto, self->setfunc, value,
 			 self->index, self->size, ptr);
 }
@@ -216,13 +221,13 @@
 static PyObject *
 CField_get_offset(PyObject *self, void *data)
 {
-	return PyInt_FromSsize_t(((CFieldObject *)self)->offset);
+	return PyLong_FromSsize_t(((CFieldObject *)self)->offset);
 }
 
 static PyObject *
 CField_get_size(PyObject *self, void *data)
 {
-	return PyInt_FromSsize_t(((CFieldObject *)self)->size);
+	return PyLong_FromSsize_t(((CFieldObject *)self)->size);
 }
 
 static PyGetSetDef CField_getset[] = {
@@ -329,13 +334,13 @@
 get_long(PyObject *v, long *p)
 {
 	long x;
-	if (!PyInt_Check(v) && !PyLong_Check(v)) {
-		PyErr_Format(PyExc_TypeError,
-			     "int expected instead of %s instance",
-			     v->ob_type->tp_name);
+
+	if (PyFloat_Check(v)) {
+		PyErr_SetString(PyExc_TypeError,
+				"int expected instead of float");
 		return -1;
 	}
-	x = PyInt_AsUnsignedLongMask(v);
+	x = PyLong_AsUnsignedLongMask(v);
 	if (x == -1 && PyErr_Occurred())
 		return -1;
 	*p = x;
@@ -348,13 +353,13 @@
 get_ulong(PyObject *v, unsigned long *p)
 {
 	unsigned long x;
-	if (!PyInt_Check(v) && !PyLong_Check(v)) {
-		PyErr_Format(PyExc_TypeError,
-			     "int expected instead of %s instance",
-			     v->ob_type->tp_name);
+
+	if (PyFloat_Check(v)) {
+		PyErr_SetString(PyExc_TypeError,
+				"int expected instead of float");
 		return -1;
 	}
-	x = PyInt_AsUnsignedLongMask(v);
+	x = PyLong_AsUnsignedLongMask(v);
 	if (x == -1 && PyErr_Occurred())
 		return -1;
 	*p = x;
@@ -369,13 +374,12 @@
 get_longlong(PyObject *v, PY_LONG_LONG *p)
 {
 	PY_LONG_LONG x;
-	if (!PyInt_Check(v) && !PyLong_Check(v)) {
-		PyErr_Format(PyExc_TypeError,
-			     "int expected instead of %s instance",
-			     v->ob_type->tp_name);
-		return -1;
+	if (PyFloat_Check(v)) {
+		PyErr_SetString(PyExc_TypeError,
+				"int expected instead of float");
+ 		return -1;
 	}
-	x = PyInt_AsUnsignedLongLongMask(v);
+	x = PyLong_AsUnsignedLongLongMask(v);
 	if (x == -1 && PyErr_Occurred())
 		return -1;
 	*p = x;
@@ -388,13 +392,12 @@
 get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p)
 {
 	unsigned PY_LONG_LONG x;
-	if (!PyInt_Check(v) && !PyLong_Check(v)) {
-		PyErr_Format(PyExc_TypeError,
-			     "int expected instead of %s instance",
-			     v->ob_type->tp_name);
-		return -1;
-	}
-	x = PyInt_AsUnsignedLongLongMask(v);
+	if (PyFloat_Check(v)) {
+		PyErr_SetString(PyExc_TypeError,
+				"int expected instead of float");
+ 		return -1;
+ 	}
+	x = PyLong_AsUnsignedLongLongMask(v);
 	if (x == -1 && PyErr_Occurred())
 		return -1;
 	*p = x;
@@ -513,7 +516,7 @@
 {
 	signed char val = *(signed char *)ptr;
 	GET_BITFIELD(val, size);
-	return PyInt_FromLong(val);
+	return PyLong_FromLong(val);
 }
 
 static PyObject *
@@ -533,7 +536,7 @@
 {
 	unsigned char val = *(unsigned char *)ptr;
 	GET_BITFIELD(val, size);
-	return PyInt_FromLong(val);
+	return PyLong_FromLong(val);
 }
 
 static PyObject *
@@ -571,7 +574,7 @@
 	short val;
 	memcpy(&val, ptr, sizeof(val));
 	GET_BITFIELD(val, size);
-	return PyInt_FromLong((long)val);
+	return PyLong_FromLong((long)val);
 }
 
 static PyObject *
@@ -581,7 +584,7 @@
 	memcpy(&val, ptr, sizeof(val));
 	val = SWAP_2(val);
 	GET_BITFIELD(val, size);
-	return PyInt_FromLong(val);
+	return PyLong_FromLong(val);
 }
 
 static PyObject *
@@ -619,7 +622,7 @@
 	unsigned short val;
 	memcpy(&val, ptr, sizeof(val));
 	GET_BITFIELD(val, size);
-	return PyInt_FromLong(val);
+	return PyLong_FromLong(val);
 }
 
 static PyObject *
@@ -629,7 +632,7 @@
 	memcpy(&val, ptr, sizeof(val));
 	val = SWAP_2(val);
 	GET_BITFIELD(val, size);
-	return PyInt_FromLong(val);
+	return PyLong_FromLong(val);
 }
 
 static PyObject *
@@ -667,7 +670,7 @@
 	int val;
 	memcpy(&val, ptr, sizeof(val));
 	GET_BITFIELD(val, size);
-	return PyInt_FromLong(val);
+	return PyLong_FromLong(val);
 }
 
 static PyObject *
@@ -677,7 +680,7 @@
 	memcpy(&val, ptr, sizeof(val));
 	val = SWAP_INT(val);
 	GET_BITFIELD(val, size);
-	return PyInt_FromLong(val);
+	return PyLong_FromLong(val);
 }
 
 #ifdef MS_WIN32
@@ -713,7 +716,7 @@
 #endif
 
 static PyObject *
-t_set(void *ptr, PyObject *value, Py_ssize_t size)
+bool_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
 	switch (PyObject_IsTrue(value)) {
 	case -1:
@@ -728,7 +731,7 @@
 }
 
 static PyObject *
-t_get(void *ptr, Py_ssize_t size)
+bool_get(void *ptr, Py_ssize_t size)
 {
 	return PyBool_FromLong((long)*(BOOL_TYPE *)ptr);
 }
@@ -815,7 +818,7 @@
 	long val;
 	memcpy(&val, ptr, sizeof(val));
 	GET_BITFIELD(val, size);
-	return PyInt_FromLong(val);
+	return PyLong_FromLong(val);
 }
 
 static PyObject *
@@ -825,7 +828,7 @@
 	memcpy(&val, ptr, sizeof(val));
 	val = SWAP_LONG(val);
 	GET_BITFIELD(val, size);
-	return PyInt_FromLong(val);
+	return PyLong_FromLong(val);
 }
 
 static PyObject *
@@ -978,7 +981,7 @@
 
 
 static PyObject *
-D_set(void *ptr, PyObject *value, Py_ssize_t size)
+g_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
 	long double x;
 
@@ -994,7 +997,7 @@
 }
 
 static PyObject *
-D_get(void *ptr, Py_ssize_t size)
+g_get(void *ptr, Py_ssize_t size)
 {
 	long double val;
 	memcpy(&val, ptr, sizeof(long double));
@@ -1157,16 +1160,28 @@
 						  conversion_mode_errors);
 		if (value == NULL)
 			return NULL;
-		if (PyBytes_GET_SIZE(value) != 1) {
+		if (PyString_GET_SIZE(value) != 1) {
 			Py_DECREF(value);
 			goto error;
 		}
-		*(char *)ptr = PyBytes_AsString(value)[0];
+		*(char *)ptr = PyString_AS_STRING(value)[0];
 		Py_DECREF(value);
 		_RET(value);
 	}
+	if (PyString_Check(value) && PyString_GET_SIZE(value) == 1) {
+		*(char *)ptr = PyString_AS_STRING(value)[0];
+		_RET(value);
+	}
 	if (PyBytes_Check(value) && PyBytes_GET_SIZE(value) == 1) {
-		*(char *)ptr = PyBytes_AsString(value)[0];
+		*(char *)ptr = PyBytes_AS_STRING(value)[0];
+		_RET(value);
+	}
+	if (PyLong_Check(value))
+	{
+		long longval = PyLong_AS_LONG(value);
+		if (longval < 0 || longval >= 256)
+			goto error;
+		*(char *)ptr = (char)longval;
 		_RET(value);
 	}
   error:
@@ -1179,7 +1194,7 @@
 static PyObject *
 c_get(void *ptr, Py_ssize_t size)
 {
-	return PyBytes_FromStringAndSize((char *)ptr, 1);
+	return PyString_FromStringAndSize((char *)ptr, 1);
 }
 
 #ifdef CTYPES_UNICODE
@@ -1188,7 +1203,7 @@
 u_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
 	Py_ssize_t len;
-	if (PyBytes_Check(value)) {
+	if (PyString_Check(value)) {
 		value = PyUnicode_FromEncodedObject(value,
 						    conversion_mode_encoding,
 						    conversion_mode_errors);
@@ -1263,7 +1278,7 @@
 	/* It's easier to calculate in characters than in bytes */
 	length /= sizeof(wchar_t);
 
-	if (PyBytes_Check(value)) {
+	if (PyString_Check(value)) {
 		value = PyUnicode_FromEncodedObject(value,
 						    conversion_mode_encoding,
 						    conversion_mode_errors);
@@ -1319,8 +1334,8 @@
 						  conversion_mode_errors);
 		if (value == NULL)
 			return NULL;
-		assert(PyBytes_Check(value));
-	} else if(PyBytes_Check(value)) {
+		assert(PyString_Check(value));
+	} else if(PyString_Check(value)) {
 		Py_INCREF(value);
 	} else {
 		PyErr_Format(PyExc_TypeError,
@@ -1329,10 +1344,10 @@
 		return NULL;
 	}
 
-	data = PyBytes_AsString(value);
+	data = PyString_AS_STRING(value);
 	if (!data)
 		return NULL;
-	size = strlen(data);
+	size = strlen(data); /* XXX Why not Py_SIZE(value)? */
 	if (size < length) {
 		/* This will copy the leading NUL character
 		 * if there is space for it.
@@ -1360,8 +1375,8 @@
 		Py_INCREF(value);
 		return value;
 	}
-	if (PyBytes_Check(value)) {
-		*(char **)ptr = PyBytes_AsString(value);
+	if (PyString_Check(value)) {
+		*(char **)ptr = PyString_AsString(value);
 		Py_INCREF(value);
 		return value;
 	} else if (PyUnicode_Check(value)) {
@@ -1370,14 +1385,13 @@
 							  conversion_mode_errors);
 		if (str == NULL)
 			return NULL;
-		assert(PyBytes_Check(str));
-		*(char **)ptr = PyBytes_AS_STRING(str);
+		*(char **)ptr = PyString_AS_STRING(str);
 		return str;
-	} else if (PyInt_Check(value) || PyLong_Check(value)) {
+	} else if (PyLong_Check(value)) {
 #if SIZEOF_VOID_P == SIZEOF_LONG_LONG
-		*(char **)ptr = (char *)PyInt_AsUnsignedLongLongMask(value);
+		*(char **)ptr = (char *)PyLong_AsUnsignedLongLongMask(value);
 #else
-		*(char **)ptr = (char *)PyInt_AsUnsignedLongMask(value);
+		*(char **)ptr = (char *)PyLong_AsUnsignedLongMask(value);
 #endif
 		_RET(value);
 	}
@@ -1416,16 +1430,16 @@
 		Py_INCREF(value);
 		return value;
 	}
-	if (PyInt_Check(value) || PyLong_Check(value)) {
+	if (PyLong_Check(value) || PyLong_Check(value)) {
 #if SIZEOF_VOID_P == SIZEOF_LONG_LONG
-		*(wchar_t **)ptr = (wchar_t *)PyInt_AsUnsignedLongLongMask(value);
+		*(wchar_t **)ptr = (wchar_t *)PyLong_AsUnsignedLongLongMask(value);
 #else
-		*(wchar_t **)ptr = (wchar_t *)PyInt_AsUnsignedLongMask(value);
+		*(wchar_t **)ptr = (wchar_t *)PyLong_AsUnsignedLongMask(value);
 #endif
 		Py_INCREF(Py_None);
 		return Py_None;
 	}
-	if (PyBytes_Check(value)) {
+	if (PyString_Check(value)) {
 		value = PyUnicode_FromEncodedObject(value,
 						    conversion_mode_encoding,
 						    conversion_mode_errors);
@@ -1508,7 +1522,7 @@
 	/* convert value into a PyUnicodeObject or NULL */
 	if (Py_None == value) {
 		value = NULL;
-	} else if (PyBytes_Check(value)) {
+	} else if (PyString_Check(value)) {
 		value = PyUnicode_FromEncodedObject(value,
 						    conversion_mode_encoding,
 						    conversion_mode_errors);
@@ -1574,21 +1588,21 @@
 		_RET(value);
 	}
 
-	if (!PyInt_Check(value) && !PyLong_Check(value)) {
+	if (!PyLong_Check(value) && !PyLong_Check(value)) {
 		PyErr_SetString(PyExc_TypeError,
 				"cannot be converted to pointer");
 		return NULL;
 	}
 
 #if SIZEOF_VOID_P <= SIZEOF_LONG
-	v = (void *)PyInt_AsUnsignedLongMask(value);
+	v = (void *)PyLong_AsUnsignedLongMask(value);
 #else
 #ifndef HAVE_LONG_LONG
 #   error "PyLong_AsVoidPtr: sizeof(void*) > sizeof(long), but no long long"
 #elif SIZEOF_LONG_LONG < SIZEOF_VOID_P
 #   error "PyLong_AsVoidPtr: sizeof(PY_LONG_LONG) < sizeof(void*)"
 #endif
-	v = (void *)PyInt_AsUnsignedLongLongMask(value);
+	v = (void *)PyLong_AsUnsignedLongLongMask(value);
 #endif
 
 	if (PyErr_Occurred())
@@ -1614,7 +1628,7 @@
 	{ 'B', B_set, B_get, &ffi_type_uchar},
 	{ 'c', c_set, c_get, &ffi_type_schar},
 	{ 'd', d_set, d_get, &ffi_type_double, d_set_sw, d_get_sw},
-	{ 'D', D_set, D_get, &ffi_type_longdouble},
+	{ 'g', g_set, g_get, &ffi_type_longdouble},
 	{ 'f', f_set, f_get, &ffi_type_float, f_set_sw, f_get_sw},
 	{ 'h', h_set, h_get, &ffi_type_sshort, h_set_sw, h_get_sw},
 	{ 'H', H_set, H_get, &ffi_type_ushort, H_set_sw, H_get_sw},
@@ -1623,17 +1637,21 @@
 /* XXX Hm, sizeof(int) == sizeof(long) doesn't hold on every platform */
 /* As soon as we can get rid of the type codes, this is no longer a problem */
 #if SIZEOF_LONG == 4
-	{ 'l', l_set, l_get, &ffi_type_sint, l_set_sw, l_get_sw},
-	{ 'L', L_set, L_get, &ffi_type_uint, L_set_sw, L_get_sw},
+	{ 'l', l_set, l_get, &ffi_type_sint32, l_set_sw, l_get_sw},
+	{ 'L', L_set, L_get, &ffi_type_uint32, L_set_sw, L_get_sw},
 #elif SIZEOF_LONG == 8
-	{ 'l', l_set, l_get, &ffi_type_slong, l_set_sw, l_get_sw},
-	{ 'L', L_set, L_get, &ffi_type_ulong, L_set_sw, L_get_sw},
+	{ 'l', l_set, l_get, &ffi_type_sint64, l_set_sw, l_get_sw},
+	{ 'L', L_set, L_get, &ffi_type_uint64, L_set_sw, L_get_sw},
 #else
 # error
 #endif
 #ifdef HAVE_LONG_LONG
-	{ 'q', q_set, q_get, &ffi_type_slong, q_set_sw, q_get_sw},
-	{ 'Q', Q_set, Q_get, &ffi_type_ulong, Q_set_sw, Q_get_sw},
+#if SIZEOF_LONG_LONG == 8
+	{ 'q', q_set, q_get, &ffi_type_sint64, q_set_sw, q_get_sw},
+	{ 'Q', Q_set, Q_get, &ffi_type_uint64, Q_set_sw, Q_get_sw},
+#else
+# error
+#endif
 #endif
 	{ 'P', P_set, P_get, &ffi_type_pointer},
 	{ 'z', z_set, z_get, &ffi_type_pointer},
@@ -1647,15 +1665,15 @@
 	{ 'v', vBOOL_set, vBOOL_get, &ffi_type_sshort},
 #endif
 #if SIZEOF__BOOL == 1
-	{ 't', t_set, t_get, &ffi_type_uchar}, /* Also fallback for no native _Bool support */
+	{ '?', bool_set, bool_get, &ffi_type_uchar}, /* Also fallback for no native _Bool support */
 #elif SIZEOF__BOOL == SIZEOF_SHORT
-	{ 't', t_set, t_get, &ffi_type_ushort},
+	{ '?', bool_set, bool_get, &ffi_type_ushort},
 #elif SIZEOF__BOOL == SIZEOF_INT
-	{ 't', t_set, t_get, &ffi_type_uint, I_set_sw, I_get_sw},
+	{ '?', bool_set, bool_get, &ffi_type_uint, I_set_sw, I_get_sw},
 #elif SIZEOF__BOOL == SIZEOF_LONG
-	{ 't', t_set, t_get, &ffi_type_ulong, L_set_sw, L_get_sw},
+	{ '?', bool_set, bool_get, &ffi_type_ulong, L_set_sw, L_get_sw},
 #elif SIZEOF__BOOL == SIZEOF_LONG_LONG
-	{ 't', t_set, t_get, &ffi_type_ulong, Q_set_sw, Q_get_sw},
+	{ '?', bool_set, bool_get, &ffi_type_ulong, Q_set_sw, Q_get_sw},
 #endif /* SIZEOF__BOOL */
 	{ 'O', O_set, O_get, &ffi_type_pointer},
 	{ 0, NULL, NULL, NULL},
@@ -1756,11 +1774,13 @@
 
 ffi_type ffi_type_float = { sizeof(float), FLOAT_ALIGN, FFI_TYPE_FLOAT };
 ffi_type ffi_type_double = { sizeof(double), DOUBLE_ALIGN, FFI_TYPE_DOUBLE };
+
+#ifdef ffi_type_longdouble
+#undef ffi_type_longdouble
+#endif
 ffi_type ffi_type_longdouble = { sizeof(long double), LONGDOUBLE_ALIGN,
 				 FFI_TYPE_LONGDOUBLE };
 
-/* ffi_type ffi_type_longdouble */
-
 ffi_type ffi_type_pointer = { sizeof(void *), VOID_P_ALIGN, FFI_TYPE_POINTER };
 
 /*---------------- EOF ----------------*/

Modified: python/branches/py3k-importlib/Modules/_ctypes/ctypes.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/ctypes.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/ctypes.h	Thu Mar 27 00:48:05 2008
@@ -269,6 +269,9 @@
 #define FUNCFLAG_HRESULT 0x2
 #define FUNCFLAG_PYTHONAPI 0x4
 
+#define TYPEFLAG_ISPOINTER 0x100
+#define TYPEFLAG_HASPOINTER 0x200
+
 #define DICTFLAG_FINAL 0x1000
 
 struct tagPyCArgObject {

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/LICENSE
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/LICENSE	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/LICENSE	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,5 @@
-libffi - Copyright (c) 1996-2003  Red Hat, Inc.
+libffi - Copyright (c) 1996-2008  Red Hat, Inc and others.  
+See source files for details.
 
 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the
@@ -11,10 +12,10 @@
 The above copyright notice and this permission notice shall be included
 in all copies or substantial portions of the Software.
 
-THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/README
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/README	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/README	Thu Mar 27 00:48:05 2008
@@ -1,78 +1,67 @@
-This directory contains the libffi package, which is not part of GCC but
-shipped with GCC as convenience.
-
 Status
 ======
 
-libffi-2.00 has not been released yet! This is a development snapshot!
-
-libffi-1.20 was released on October 5, 1998. Check the libffi web
-page for updates: <URL:http://sources.redhat.com/libffi/>.
+libffi-3.0.4 was released on February 24, 2008. Check the libffi web
+page for updates: <URL:http://sourceware.org/libffi/>.
 
 
 What is libffi?
 ===============
 
 Compilers for high level languages generate code that follow certain
-conventions. These conventions are necessary, in part, for separate
-compilation to work. One such convention is the "calling
-convention". The "calling convention" is essentially a set of
-assumptions made by the compiler about where function arguments will
-be found on entry to a function. A "calling convention" also specifies
-where the return value for a function is found.
+conventions.  These conventions are necessary, in part, for separate
+compilation to work.  One such convention is the "calling convention".
+The "calling convention" is a set of assumptions made by the compiler
+about where function arguments will be found on entry to a function.
+A "calling convention" also specifies where the return value for a
+function is found.
 
 Some programs may not know at the time of compilation what arguments
-are to be passed to a function. For instance, an interpreter may be
+are to be passed to a function.  For instance, an interpreter may be
 told at run-time about the number and types of arguments used to call
-a given function. Libffi can be used in such programs to provide a
+a given function.  Libffi can be used in such programs to provide a
 bridge from the interpreter program to compiled code.
 
 The libffi library provides a portable, high level programming
-interface to various calling conventions. This allows a programmer to
+interface to various calling conventions.  This allows a programmer to
 call any function specified by a call interface description at run
-time.  
+time.
 
-Ffi stands for Foreign Function Interface. A foreign function
+FFI stands for Foreign Function Interface.  A foreign function
 interface is the popular name for the interface that allows code
-written in one language to call code written in another language. The
+written in one language to call code written in another language.  The
 libffi library really only provides the lowest, machine dependent
 layer of a fully featured foreign function interface. A layer must
 exist above libffi that handles type conversions for values passed
 between the two languages.
 
 
-Supported Platforms and Prerequisites
-=====================================
-
-Libffi has been ported to:
-
-	SunOS 4.1.3 & Solaris 2.x (SPARC-V8, SPARC-V9)
-
-	Irix 5.3 & 6.2 (System V/o32 & n32)
-
-	Intel x86 - Linux (System V ABI)
-
-	Alpha - Linux and OSF/1
-
-	m68k - Linux (System V ABI)
-
-	PowerPC - Linux (System V ABI, Darwin, AIX)
+Supported Platforms
+===================
 
-	ARM - Linux (System V ABI)
-
-Libffi has been tested with the egcs 1.0.2 gcc compiler. Chances are
-that other versions will work.  Libffi has also been built and tested
-with the SGI compiler tools.
-
-On PowerPC, the tests failed (see the note below).
-
-You must use GNU make to build libffi. SGI's make will not work.
-Sun's probably won't either.
-	
-If you port libffi to another platform, please let me know! I assume
-that some will be easy (x86 NetBSD), and others will be more difficult
-(HP).
+Libffi has been ported to many different platforms, although this
+release was only tested on:
 
+     arm oabi linux
+     arm eabi linux
+     hppa linux
+     mips o32 linux (little endian)
+     powerpc darwin
+     powerpc64 linux
+     sparc solaris
+     sparc64 solaris
+     x86 cygwin
+     x86 darwin
+     x86 freebsd
+     x86 linux
+     x86 openbsd
+     x86-64 darwin
+     x86-64 linux
+     x86-64 OS X
+     x86-64 freebsd
+     
+Please send additional platform test results to
+libffi-discuss at sourceware.org.
 
 Installing libffi
 =================
@@ -101,216 +90,17 @@
 Configure has many other options. Use "configure --help" to see them all.
 
 Once configure has finished, type "make". Note that you must be using
-GNU make. SGI's make will not work.  Sun's probably won't either.
-You can ftp GNU make from prep.ai.mit.edu:/pub/gnu.
+GNU make.  You can ftp GNU make from prep.ai.mit.edu:/pub/gnu.
 
-To ensure that libffi is working as advertised, type "make test".
+To ensure that libffi is working as advertised, type "make check".
+This will require that you have DejaGNU installed.
 
 To install the library and header files, type "make install".
 
 
-Using libffi
-============
-
-	The Basics
-	----------
-
-Libffi assumes that you have a pointer to the function you wish to
-call and that you know the number and types of arguments to pass it,
-as well as the return type of the function.
-
-The first thing you must do is create an ffi_cif object that matches
-the signature of the function you wish to call. The cif in ffi_cif
-stands for Call InterFace. To prepare a call interface object, use the
-following function:
-
-ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi,
-			unsigned int nargs, 
-			ffi_type *rtype, ffi_type **atypes);
-
-	CIF is a pointer to the call interface object you wish
-		to initialize.
-
-	ABI is an enum that specifies the calling convention 
-		to use for the call. FFI_DEFAULT_ABI defaults
-		to the system's native calling convention. Other
-		ABI's may be used with care. They are system
-		specific.
-
-	NARGS is the number of arguments this function accepts.	
-		libffi does not yet support vararg functions.
-
-	RTYPE is a pointer to an ffi_type structure that represents
-		the return type of the function. Ffi_type objects
-		describe the types of values. libffi provides
-		ffi_type objects for many of the native C types:
-		signed int, unsigned int, signed char, unsigned char,
-		etc. There is also a pointer ffi_type object and
-		a void ffi_type. Use &ffi_type_void for functions that 
-		don't return values.
-
-	ATYPES is a vector of ffi_type pointers. ARGS must be NARGS long.
-		If NARGS is 0, this is ignored.
-
-
-ffi_prep_cif will return a status code that you are responsible 
-for checking. It will be one of the following:
-
-	FFI_OK - All is good.
-
-	FFI_BAD_TYPEDEF - One of the ffi_type objects that ffi_prep_cif
-		came across is bad.
-
-
-Before making the call, the VALUES vector should be initialized 
-with pointers to the appropriate argument values.
-
-To call the the function using the initialized ffi_cif, use the
-ffi_call function:
-
-void ffi_call(ffi_cif *cif, void *fn, void *rvalue, void **avalues);
-
-	CIF is a pointer to the ffi_cif initialized specifically
-		for this function.
-
-	FN is a pointer to the function you want to call.
-
-	RVALUE is a pointer to a chunk of memory that is to hold the
-		result of the function call. Currently, it must be
-		at least one word in size (except for the n32 version
-		under Irix 6.x, which must be a pointer to an 8 byte 
-		aligned value (a long long). It must also be at least 
-		word aligned (depending on the return type, and the
-		system's alignment requirements). If RTYPE is 
-		&ffi_type_void, this is ignored. If RVALUE is NULL, 
-		the return value is discarded.
-
-	AVALUES is a vector of void* that point to the memory locations
-		holding the argument values for a call.
-		If NARGS is 0, this is ignored.
-
-
-If you are expecting a return value from FN it will have been stored
-at RVALUE.
-
-
-
-	An Example
-	----------
-
-Here is a trivial example that calls puts() a few times.
-
-    #include <stdio.h>
-    #include <ffi.h>
-    
-    int main()
-    {
-      ffi_cif cif;
-      ffi_type *args[1];
-      void *values[1];
-      char *s;
-      int rc;
-      
-      /* Initialize the argument info vectors */    
-      args[0] = &ffi_type_uint;
-      values[0] = &s;
-      
-      /* Initialize the cif */
-      if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 
-    		       &ffi_type_uint, args) == FFI_OK)
-        {
-          s = "Hello World!";
-          ffi_call(&cif, puts, &rc, values);
-          /* rc now holds the result of the call to puts */
-          
-          /* values holds a pointer to the function's arg, so to 
-	     call puts() again all we need to do is change the 
-             value of s */
-          s = "This is cool!";
-          ffi_call(&cif, puts, &rc, values);
-        }
-      
-      return 0;
-    }
-
-
-
-	Aggregate Types
-	---------------
-
-Although libffi has no special support for unions or bit-fields, it is
-perfectly happy passing structures back and forth. You must first
-describe the structure to libffi by creating a new ffi_type object
-for it. Here is the definition of ffi_type:
-
-    typedef struct _ffi_type
-    {
-      unsigned size;
-      short alignment;
-      short type;
-      struct _ffi_type **elements;
-    } ffi_type;
-    
-All structures must have type set to FFI_TYPE_STRUCT.  You may set
-size and alignment to 0. These will be calculated and reset to the
-appropriate values by ffi_prep_cif().
-
-elements is a NULL terminated array of pointers to ffi_type objects
-that describe the type of the structure elements. These may, in turn,
-be structure elements.
-
-The following example initializes a ffi_type object representing the
-tm struct from Linux's time.h:
-
-				    struct tm {
-					int tm_sec;
-					int tm_min;
-					int tm_hour;
-					int tm_mday;
-					int tm_mon;
-					int tm_year;
-					int tm_wday;
-					int tm_yday;
-					int tm_isdst;
-					/* Those are for future use. */
-					long int __tm_gmtoff__;
-					__const char *__tm_zone__;
-				    };
-
-    {
-      ffi_type tm_type;
-      ffi_type *tm_type_elements[12];
-      int i;
-
-      tm_type.size = tm_type.alignment = 0;
-      tm_type.elements = &tm_type_elements;
-    
-      for (i = 0; i < 9; i++)
-          tm_type_elements[i] = &ffi_type_sint;
-
-      tm_type_elements[9] = &ffi_type_slong;
-      tm_type_elements[10] = &ffi_type_pointer;
-      tm_type_elements[11] = NULL;
-
-      /* tm_type can now be used to represent tm argument types and
-	 return types for ffi_prep_cif() */
-    }
-
-
-
 Platform Specific Notes
 =======================
 
-	Intel x86
-	---------
-
-There are no known problems with the x86 port.
-
-	Sun SPARC - SunOS 4.1.3 & Solaris 2.x
-	-------------------------------------
-
-You must use GNU Make to build libffi on Sun platforms.
-
 	MIPS - Irix 5.3 & 6.x
 	---------------------
 
@@ -339,13 +129,6 @@
 
 You must use GNU Make to build libffi on SGI platforms.
 
-	ARM - System V ABI
-	------------------
-
-The ARM port was performed on a NetWinder running ARM Linux ELF
-(2.0.31) and gcc 2.8.1.
-
-
 
 	PowerPC System V ABI
 	--------------------
@@ -372,17 +155,30 @@
 arguments' test).
 
 
-What's With The Crazy Comments?
-===============================
+History
+=======
 
-You might notice a number of cryptic comments in the code, delimited
-by /*@ and @*/. These are annotations read by the program LCLint, a
-tool for statically checking C programs. You can read all about it at
-<http://larch-www.lcs.mit.edu:8001/larch/lclint/index.html>.
+3.0.4 Feb-24-08
+        Fix x86 OpenBSD configury.
 
+3.0.3 Feb-22-08
+        Enable x86 OpenBSD thanks to Thomas Heller, and
+	x86-64 FreeBSD thanks to Björn König and Andreas Tobler.
+	Clean up test instruction in README.
+
+3.0.2 Feb-21-08
+        Improved x86 FreeBSD support.
+	Thanks to Björn König.
+
+3.0.1 Feb-15-08
+        Fix instruction cache flushing bug on MIPS.
+	Thanks to David Daney.
+
+3.0.0 Feb-15-08
+        Many changes, mostly thanks to the GCC project.
+	Cygnus Solutions is now Red Hat.
 
-History
-=======
+  [10 years go by...]
 
 1.20 Oct-5-98
 	Raffaele Sena produces ARM port.
@@ -467,34 +263,56 @@
 Authors & Credits
 =================
 
-libffi was written by Anthony Green <green at cygnus.com>.
+libffi was originally written by Anthony Green <green at redhat.com>.
+
+The developers of the GNU Compiler Collection project have made
+innumerable valuable contributions.  See the ChangeLog file for
+details.
 
-Portions of libffi were derived from Gianni Mariani's free gencall
-library for Silicon Graphics machines.
+Some of the ideas behind libffi were inspired by Gianni Mariani's free
+gencall library for Silicon Graphics machines.
 
 The closure mechanism was designed and implemented by Kresten Krab
 Thorup.
 
-The Sparc port was derived from code contributed by the fine folks at
-Visible Decisions Inc <http://www.vdi.com>. Further enhancements were
-made by Gordon Irlam at Cygnus Solutions <http://www.cygnus.com>.
-
-The Alpha port was written by Richard Henderson at Cygnus Solutions.
-
-Andreas Schwab ported libffi to m68k Linux and provided a number of
-bug fixes.
+Major processor architecture ports were contributed by the following
+developers:
 
-Geoffrey Keating ported libffi to the PowerPC.
-
-Raffaele Sena ported libffi to the ARM.
+alpha		Richard Henderson
+arm		Raffaele Sena
+cris		Simon Posnjak, Hans-Peter Nilsson
+frv		Anthony Green
+ia64		Hans Boehm
+m32r		Kazuhiro Inaoka
+m68k		Andreas Schwab
+mips		Anthony Green, Casey Marshall
+mips64		David Daney
+pa		Randolph Chung, Dave Anglin, Andreas Tobler
+powerpc		Geoffrey Keating, Andreas Tobler, 
+			 David Edelsohn, John Hornkvist
+powerpc64	Jakub Jelinek
+s390		Gerhard Tonn, Ulrich Weigand
+sh		Kaz Kojima
+sh64		Kaz Kojima
+sparc		Anthony Green, Gordon Irlam
+x86		Anthony Green, Jon Beniston
+x86-64		Bo Thorsen
 
 Jesper Skov and Andrew Haley both did more than their fair share of
 stepping through the code and tracking down bugs.
 
-Thanks also to Tom Tromey for bug fixes and configuration help.
+Thanks also to Tom Tromey for bug fixes, documentation and
+configuration help.
 
 Thanks to Jim Blandy, who provided some useful feedback on the libffi
 interface.
 
+Andreas Tobler has done a tremendous amount of work on the testsuite.
+
+Alex Oliva solved the executable page problem for SElinux.
+
+The list above is almost certainly incomplete and inaccurate.  I'm
+happy to make corrections or additions upon request.
+
 If you have a problem, or have found a bug, please send a note to
-green at cygnus.com.
+green at redhat.com.

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/aclocal.m4
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/aclocal.m4	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/aclocal.m4	Thu Mar 27 00:48:05 2008
@@ -1,92 +1,7516 @@
-# mmap(2) blacklisting.  Some platforms provide the mmap library routine
-# but don't support all of the features we need from it.
-AC_DEFUN([AC_FUNC_MMAP_BLACKLIST],
+# generated automatically by aclocal 1.10 -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+# 2005, 2006  Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+m4_if(m4_PACKAGE_VERSION, [2.61],,
+[m4_fatal([this file was generated for autoconf 2.61.
+You have another version of autoconf.  If you want to use that,
+you should regenerate the build system entirely.], [63])])
+
+# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
+
+# serial 51 AC_PROG_LIBTOOL
+
+
+# AC_PROVIDE_IFELSE(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
+# -----------------------------------------------------------
+# If this macro is not defined by Autoconf, define it here.
+m4_ifdef([AC_PROVIDE_IFELSE],
+         [],
+         [m4_define([AC_PROVIDE_IFELSE],
+	         [m4_ifdef([AC_PROVIDE_$1],
+		           [$2], [$3])])])
+
+
+# AC_PROG_LIBTOOL
+# ---------------
+AC_DEFUN([AC_PROG_LIBTOOL],
+[AC_REQUIRE([_AC_PROG_LIBTOOL])dnl
+dnl If AC_PROG_CXX has already been expanded, run AC_LIBTOOL_CXX
+dnl immediately, otherwise, hook it in at the end of AC_PROG_CXX.
+  AC_PROVIDE_IFELSE([AC_PROG_CXX],
+    [AC_LIBTOOL_CXX],
+    [define([AC_PROG_CXX], defn([AC_PROG_CXX])[AC_LIBTOOL_CXX
+  ])])
+dnl And a similar setup for Fortran 77 support
+  AC_PROVIDE_IFELSE([AC_PROG_F77],
+    [AC_LIBTOOL_F77],
+    [define([AC_PROG_F77], defn([AC_PROG_F77])[AC_LIBTOOL_F77
+])])
+
+dnl Quote A][M_PROG_GCJ so that aclocal doesn't bring it in needlessly.
+dnl If either AC_PROG_GCJ or A][M_PROG_GCJ have already been expanded, run
+dnl AC_LIBTOOL_GCJ immediately, otherwise, hook it in at the end of both.
+  AC_PROVIDE_IFELSE([AC_PROG_GCJ],
+    [AC_LIBTOOL_GCJ],
+    [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],
+      [AC_LIBTOOL_GCJ],
+      [AC_PROVIDE_IFELSE([LT_AC_PROG_GCJ],
+	[AC_LIBTOOL_GCJ],
+      [ifdef([AC_PROG_GCJ],
+	     [define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[AC_LIBTOOL_GCJ])])
+       ifdef([A][M_PROG_GCJ],
+	     [define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[AC_LIBTOOL_GCJ])])
+       ifdef([LT_AC_PROG_GCJ],
+	     [define([LT_AC_PROG_GCJ],
+		defn([LT_AC_PROG_GCJ])[AC_LIBTOOL_GCJ])])])])
+])])# AC_PROG_LIBTOOL
+
+
+# _AC_PROG_LIBTOOL
+# ----------------
+AC_DEFUN([_AC_PROG_LIBTOOL],
+[AC_REQUIRE([AC_LIBTOOL_SETUP])dnl
+AC_BEFORE([$0],[AC_LIBTOOL_CXX])dnl
+AC_BEFORE([$0],[AC_LIBTOOL_F77])dnl
+AC_BEFORE([$0],[AC_LIBTOOL_GCJ])dnl
+
+# This can be used to rebuild libtool when needed
+LIBTOOL_DEPS="$ac_aux_dir/ltmain.sh"
+
+# Always use our own libtool.
+LIBTOOL='$(SHELL) $(top_builddir)/libtool'
+AC_SUBST(LIBTOOL)dnl
+
+# Prevent multiple expansion
+define([AC_PROG_LIBTOOL], [])
+])# _AC_PROG_LIBTOOL
+
+
+# AC_LIBTOOL_SETUP
+# ----------------
+AC_DEFUN([AC_LIBTOOL_SETUP],
+[AC_PREREQ(2.50)dnl
+AC_REQUIRE([AC_ENABLE_SHARED])dnl
+AC_REQUIRE([AC_ENABLE_STATIC])dnl
+AC_REQUIRE([AC_ENABLE_FAST_INSTALL])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_PROG_LD])dnl
+AC_REQUIRE([AC_PROG_LD_RELOAD_FLAG])dnl
+AC_REQUIRE([AC_PROG_NM])dnl
+
+AC_REQUIRE([AC_PROG_LN_S])dnl
+AC_REQUIRE([AC_DEPLIBS_CHECK_METHOD])dnl
+# Autoconf 2.13's AC_OBJEXT and AC_EXEEXT macros only works for C compilers!
+AC_REQUIRE([AC_OBJEXT])dnl
+AC_REQUIRE([AC_EXEEXT])dnl
+dnl
+
+AC_LIBTOOL_SYS_MAX_CMD_LEN
+AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE
+AC_LIBTOOL_OBJDIR
+
+AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl
+_LT_AC_PROG_ECHO_BACKSLASH
+
+case $host_os in
+aix3*)
+  # AIX sometimes has problems with the GCC collect2 program.  For some
+  # reason, if we set the COLLECT_NAMES environment variable, the problems
+  # vanish in a puff of smoke.
+  if test "X${COLLECT_NAMES+set}" != Xset; then
+    COLLECT_NAMES=
+    export COLLECT_NAMES
+  fi
+  ;;
+esac
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+Xsed='sed -e 1s/^X//'
+[sed_quote_subst='s/\([\\"\\`$\\\\]\)/\\\1/g']
+
+# Same as above, but do not quote variable references.
+[double_quote_subst='s/\([\\"\\`\\\\]\)/\\\1/g']
+
+# Sed substitution to delay expansion of an escaped shell variable in a
+# double_quote_subst'ed string.
+delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
+
+# Sed substitution to avoid accidental globbing in evaled expressions
+no_glob_subst='s/\*/\\\*/g'
+
+# Constants:
+rm="rm -f"
+
+# Global variables:
+default_ofile=libtool
+can_build_shared=yes
+
+# All known linkers require a `.a' archive for static linking (except MSVC,
+# which needs '.lib').
+libext=a
+ltmain="$ac_aux_dir/ltmain.sh"
+ofile="$default_ofile"
+with_gnu_ld="$lt_cv_prog_gnu_ld"
+
+AC_CHECK_TOOL(AR, ar, false)
+AC_CHECK_TOOL(RANLIB, ranlib, :)
+AC_CHECK_TOOL(STRIP, strip, :)
+
+old_CC="$CC"
+old_CFLAGS="$CFLAGS"
+
+# Set sane defaults for various variables
+test -z "$AR" && AR=ar
+test -z "$AR_FLAGS" && AR_FLAGS=cru
+test -z "$AS" && AS=as
+test -z "$CC" && CC=cc
+test -z "$LTCC" && LTCC=$CC
+test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
+test -z "$DLLTOOL" && DLLTOOL=dlltool
+test -z "$LD" && LD=ld
+test -z "$LN_S" && LN_S="ln -s"
+test -z "$MAGIC_CMD" && MAGIC_CMD=file
+test -z "$NM" && NM=nm
+test -z "$SED" && SED=sed
+test -z "$OBJDUMP" && OBJDUMP=objdump
+test -z "$RANLIB" && RANLIB=:
+test -z "$STRIP" && STRIP=:
+test -z "$ac_objext" && ac_objext=o
+
+# Determine commands to create old-style static archives.
+old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
+old_postinstall_cmds='chmod 644 $oldlib'
+old_postuninstall_cmds=
+
+if test -n "$RANLIB"; then
+  case $host_os in
+  openbsd*)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib"
+    ;;
+  *)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib"
+    ;;
+  esac
+  old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
+fi
+
+_LT_CC_BASENAME([$compiler])
+
+# Only perform the check for file, if the check method requires it
+case $deplibs_check_method in
+file_magic*)
+  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
+    AC_PATH_MAGIC
+  fi
+  ;;
+esac
+
+AC_PROVIDE_IFELSE([AC_LIBTOOL_DLOPEN], enable_dlopen=yes, enable_dlopen=no)
+AC_PROVIDE_IFELSE([AC_LIBTOOL_WIN32_DLL],
+enable_win32_dll=yes, enable_win32_dll=no)
+
+AC_ARG_ENABLE([libtool-lock],
+    [AC_HELP_STRING([--disable-libtool-lock],
+	[avoid locking (might break parallel builds)])])
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+
+AC_ARG_WITH([pic],
+    [AC_HELP_STRING([--with-pic],
+	[try to use only PIC/non-PIC objects @<:@default=use both@:>@])],
+    [pic_mode="$withval"],
+    [pic_mode=default])
+test -z "$pic_mode" && pic_mode=default
+
+# Use C for the default configuration in the libtool script
+tagname=
+AC_LIBTOOL_LANG_C_CONFIG
+_LT_AC_TAGCONFIG
+])# AC_LIBTOOL_SETUP
+
+
+# _LT_AC_SYS_COMPILER
+# -------------------
+AC_DEFUN([_LT_AC_SYS_COMPILER],
+[AC_REQUIRE([AC_PROG_CC])dnl
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+])# _LT_AC_SYS_COMPILER
+
+
+# _LT_CC_BASENAME(CC)
+# -------------------
+# Calculate cc_basename.  Skip known compiler wrappers and cross-prefix.
+AC_DEFUN([_LT_CC_BASENAME],
+[for cc_temp in $1""; do
+  case $cc_temp in
+    compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;;
+    distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+])
+
+
+# _LT_COMPILER_BOILERPLATE
+# ------------------------
+# Check for compiler boilerplate output or warnings with
+# the simple compiler test code.
+AC_DEFUN([_LT_COMPILER_BOILERPLATE],
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$rm conftest*
+])# _LT_COMPILER_BOILERPLATE
+
+
+# _LT_LINKER_BOILERPLATE
+# ----------------------
+# Check for linker boilerplate output or warnings with
+# the simple link test code.
+AC_DEFUN([_LT_LINKER_BOILERPLATE],
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$rm conftest*
+])# _LT_LINKER_BOILERPLATE
+
+
+# _LT_AC_SYS_LIBPATH_AIX
+# ----------------------
+# Links a minimal program and checks the executable
+# for the system default hardcoded library path. In most cases,
+# this is /usr/lib:/lib, but when the MPI compilers are used
+# the location of the communication and MPI libs are included too.
+# If we don't find anything, use the default library path according
+# to the aix ld manual.
+AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX],
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
+AC_LINK_IFELSE(AC_LANG_PROGRAM,[
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi],[])
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+])# _LT_AC_SYS_LIBPATH_AIX
+
+
+# _LT_AC_SHELL_INIT(ARG)
+# ----------------------
+AC_DEFUN([_LT_AC_SHELL_INIT],
+[ifdef([AC_DIVERSION_NOTICE],
+	     [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)],
+	 [AC_DIVERT_PUSH(NOTICE)])
+$1
+AC_DIVERT_POP
+])# _LT_AC_SHELL_INIT
+
+
+# _LT_AC_PROG_ECHO_BACKSLASH
+# --------------------------
+# Add some code to the start of the generated configure script which
+# will find an echo command which doesn't interpret backslashes.
+AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH],
+[_LT_AC_SHELL_INIT([
+# Check that we are running under the correct shell.
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+case X$ECHO in
+X*--fallback-echo)
+  # Remove one level of quotation (which was required for Make).
+  ECHO=`echo "$ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','`
+  ;;
+esac
+
+echo=${ECHO-echo}
+if test "X[$]1" = X--no-reexec; then
+  # Discard the --no-reexec flag, and continue.
+  shift
+elif test "X[$]1" = X--fallback-echo; then
+  # Avoid inline document here, it may be left over
+  :
+elif test "X`($echo '\t') 2>/dev/null`" = 'X\t' ; then
+  # Yippee, $echo works!
+  :
+else
+  # Restart under the correct shell.
+  exec $SHELL "[$]0" --no-reexec ${1+"[$]@"}
+fi
+
+if test "X[$]1" = X--fallback-echo; then
+  # used as fallback echo
+  shift
+  cat <<EOF
+[$]*
+EOF
+  exit 0
+fi
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+if test -z "$ECHO"; then
+if test "X${echo_test_string+set}" != Xset; then
+# find a string as large as possible, as long as the shell can cope with it
+  for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do
+    # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
+    if (echo_test_string=`eval $cmd`) 2>/dev/null &&
+       echo_test_string=`eval $cmd` &&
+       (test "X$echo_test_string" = "X$echo_test_string") 2>/dev/null
+    then
+      break
+    fi
+  done
+fi
+
+if test "X`($echo '\t') 2>/dev/null`" = 'X\t' &&
+   echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` &&
+   test "X$echo_testing_string" = "X$echo_test_string"; then
+  :
+else
+  # The Solaris, AIX, and Digital Unix default echo programs unquote
+  # backslashes.  This makes it impossible to quote backslashes using
+  #   echo "$something" | sed 's/\\/\\\\/g'
+  #
+  # So, first we look for a working echo in the user's PATH.
+
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for dir in $PATH /usr/ucb; do
+    IFS="$lt_save_ifs"
+    if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
+       test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
+       echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
+       test "X$echo_testing_string" = "X$echo_test_string"; then
+      echo="$dir/echo"
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+
+  if test "X$echo" = Xecho; then
+    # We didn't find a better echo, so look for alternatives.
+    if test "X`(print -r '\t') 2>/dev/null`" = 'X\t' &&
+       echo_testing_string=`(print -r "$echo_test_string") 2>/dev/null` &&
+       test "X$echo_testing_string" = "X$echo_test_string"; then
+      # This shell has a builtin print -r that does the trick.
+      echo='print -r'
+    elif (test -f /bin/ksh || test -f /bin/ksh$ac_exeext) &&
+	 test "X$CONFIG_SHELL" != X/bin/ksh; then
+      # If we have ksh, try running configure again with it.
+      ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
+      export ORIGINAL_CONFIG_SHELL
+      CONFIG_SHELL=/bin/ksh
+      export CONFIG_SHELL
+      exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"}
+    else
+      # Try using printf.
+      echo='printf %s\n'
+      if test "X`($echo '\t') 2>/dev/null`" = 'X\t' &&
+	 echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` &&
+	 test "X$echo_testing_string" = "X$echo_test_string"; then
+	# Cool, printf works
+	:
+      elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
+	   test "X$echo_testing_string" = 'X\t' &&
+	   echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+	   test "X$echo_testing_string" = "X$echo_test_string"; then
+	CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
+	export CONFIG_SHELL
+	SHELL="$CONFIG_SHELL"
+	export SHELL
+	echo="$CONFIG_SHELL [$]0 --fallback-echo"
+      elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
+	   test "X$echo_testing_string" = 'X\t' &&
+	   echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+	   test "X$echo_testing_string" = "X$echo_test_string"; then
+	echo="$CONFIG_SHELL [$]0 --fallback-echo"
+      else
+	# maybe with a smaller string...
+	prev=:
+
+	for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do
+	  if (test "X$echo_test_string" = "X`eval $cmd`") 2>/dev/null
+	  then
+	    break
+	  fi
+	  prev="$cmd"
+	done
+
+	if test "$prev" != 'sed 50q "[$]0"'; then
+	  echo_test_string=`eval $prev`
+	  export echo_test_string
+	  exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"}
+	else
+	  # Oops.  We lost completely, so just stick with echo.
+	  echo=echo
+	fi
+      fi
+    fi
+  fi
+fi
+fi
+
+# Copy echo and quote the copy suitably for passing to libtool from
+# the Makefile, instead of quoting the original, which is used later.
+ECHO=$echo
+if test "X$ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then
+   ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo"
+fi
+
+AC_SUBST(ECHO)
+])])# _LT_AC_PROG_ECHO_BACKSLASH
+
+
+# _LT_AC_LOCK
+# -----------
+AC_DEFUN([_LT_AC_LOCK],
+[AC_ARG_ENABLE([libtool-lock],
+    [AC_HELP_STRING([--disable-libtool-lock],
+	[avoid locking (might break parallel builds)])])
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+
+# Some flags need to be propagated to the compiler or linker for good
+# libtool support.
+case $host in
+ia64-*-hpux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.$ac_objext` in
+    *ELF-32*)
+      HPUX_IA64_MODE="32"
+      ;;
+    *ELF-64*)
+      HPUX_IA64_MODE="64"
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+*-*-irix6*)
+  # Find out which ABI we are using.
+  echo '[#]line __oline__ "configure"' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+   if test "$lt_cv_prog_gnu_ld" = yes; then
+    case `/usr/bin/file conftest.$ac_objext` in
+    *32-bit*)
+      LD="${LD-ld} -melf32bsmip"
+      ;;
+    *N32*)
+      LD="${LD-ld} -melf32bmipn32"
+      ;;
+    *64-bit*)
+      LD="${LD-ld} -melf64bmip"
+      ;;
+    esac
+   else
+    case `/usr/bin/file conftest.$ac_objext` in
+    *32-bit*)
+      LD="${LD-ld} -32"
+      ;;
+    *N32*)
+      LD="${LD-ld} -n32"
+      ;;
+    *64-bit*)
+      LD="${LD-ld} -64"
+      ;;
+    esac
+   fi
+  fi
+  rm -rf conftest*
+  ;;
+
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+s390*-*linux*|sparc*-*linux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.o` in
+    *32-bit*)
+      case $host in
+        x86_64-*kfreebsd*-gnu)
+          LD="${LD-ld} -m elf_i386_fbsd"
+          ;;
+        x86_64-*linux*)
+          LD="${LD-ld} -m elf_i386"
+          ;;
+        ppc64-*linux*|powerpc64-*linux*)
+          LD="${LD-ld} -m elf32ppclinux"
+          ;;
+        s390x-*linux*)
+          LD="${LD-ld} -m elf_s390"
+          ;;
+        sparc64-*linux*)
+          LD="${LD-ld} -m elf32_sparc"
+          ;;
+      esac
+      ;;
+    *64-bit*)
+      libsuff=64
+      case $host in
+        x86_64-*kfreebsd*-gnu)
+          LD="${LD-ld} -m elf_x86_64_fbsd"
+          ;;
+        x86_64-*linux*)
+          LD="${LD-ld} -m elf_x86_64"
+          ;;
+        ppc*-*linux*|powerpc*-*linux*)
+          LD="${LD-ld} -m elf64ppc"
+          ;;
+        s390*-*linux*)
+          LD="${LD-ld} -m elf64_s390"
+          ;;
+        sparc*-*linux*)
+          LD="${LD-ld} -m elf64_sparc"
+          ;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+
+*-*-sco3.2v5*)
+  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -belf"
+  AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf,
+    [AC_LANG_PUSH(C)
+     AC_TRY_LINK([],[],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no])
+     AC_LANG_POP])
+  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
+    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
+    CFLAGS="$SAVE_CFLAGS"
+  fi
+  ;;
+sparc*-*solaris*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.o` in
+    *64-bit*)
+      case $lt_cv_prog_gnu_ld in
+      yes*) LD="${LD-ld} -m elf64_sparc" ;;
+      *)    LD="${LD-ld} -64" ;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+
+AC_PROVIDE_IFELSE([AC_LIBTOOL_WIN32_DLL],
+[*-*-cygwin* | *-*-mingw* | *-*-pw32*)
+  AC_CHECK_TOOL(DLLTOOL, dlltool, false)
+  AC_CHECK_TOOL(AS, as, false)
+  AC_CHECK_TOOL(OBJDUMP, objdump, false)
+  ;;
+  ])
+esac
+
+need_locks="$enable_libtool_lock"
+
+])# _LT_AC_LOCK
+
+
+# AC_LIBTOOL_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
+#		[OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE])
+# ----------------------------------------------------------------
+# Check whether the given compiler option works
+AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION],
+[AC_REQUIRE([LT_AC_PROG_SED])
+AC_CACHE_CHECK([$1], [$2],
+  [$2=no
+  ifelse([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4])
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$3"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&AS_MESSAGE_LOG_FD
+   echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       $2=yes
+     fi
+   fi
+   $rm conftest*
+])
+
+if test x"[$]$2" = xyes; then
+    ifelse([$5], , :, [$5])
+else
+    ifelse([$6], , :, [$6])
+fi
+])# AC_LIBTOOL_COMPILER_OPTION
+
+
+# AC_LIBTOOL_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
+#                          [ACTION-SUCCESS], [ACTION-FAILURE])
+# ------------------------------------------------------------
+# Check whether the given compiler option works
+AC_DEFUN([AC_LIBTOOL_LINKER_OPTION],
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
+AC_CACHE_CHECK([$1], [$2],
+  [$2=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $3"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&AS_MESSAGE_LOG_FD
+       $echo "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         $2=yes
+       fi
+     else
+       $2=yes
+     fi
+   fi
+   $rm conftest*
+   LDFLAGS="$save_LDFLAGS"
+])
+
+if test x"[$]$2" = xyes; then
+    ifelse([$4], , :, [$4])
+else
+    ifelse([$5], , :, [$5])
+fi
+])# AC_LIBTOOL_LINKER_OPTION
+
+
+# AC_LIBTOOL_SYS_MAX_CMD_LEN
+# --------------------------
+AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN],
+[# find the maximum length of command line arguments
+AC_MSG_CHECKING([the maximum length of command line arguments])
+AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl
+  i=0
+  teststring="ABCD"
+
+  case $build_os in
+  msdosdjgpp*)
+    # On DJGPP, this test can blow up pretty badly due to problems in libc
+    # (any single argument exceeding 2000 bytes causes a buffer overrun
+    # during glob expansion).  Even if it were fixed, the result of this
+    # check would be larger than it should be.
+    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
+    ;;
+
+  gnu*)
+    # Under GNU Hurd, this test is not required because there is
+    # no limit to the length of command line arguments.
+    # Libtool will interpret -1 as no limit whatsoever
+    lt_cv_sys_max_cmd_len=-1;
+    ;;
+
+  cygwin* | mingw*)
+    # On Win9x/ME, this test blows up -- it succeeds, but takes
+    # about 5 minutes as the teststring grows exponentially.
+    # Worse, since 9x/ME are not pre-emptively multitasking,
+    # you end up with a "frozen" computer, even though with patience
+    # the test eventually succeeds (with a max line length of 256k).
+    # Instead, let's just punt: use the minimum linelength reported by
+    # all of the supported platforms: 8192 (on NT/2K/XP).
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  amigaos*)
+    # On AmigaOS with pdksh, this test takes hours, literally.
+    # So we just punt and use a minimum line length of 8192.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
+    # This has been around since 386BSD, at least.  Likely further.
+    if test -x /sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
+    elif test -x /usr/sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
+    else
+      lt_cv_sys_max_cmd_len=65536	# usable default for all BSDs
+    fi
+    # And add a safety zone
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    ;;
+
+  interix*)
+    # We know the value 262144 and hardcode it with a safety zone (like BSD)
+    lt_cv_sys_max_cmd_len=196608
+    ;;
+
+  osf*)
+    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
+    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
+    # nice to cause kernel panics so lets avoid the loop below.
+    # First set a reasonable default.
+    lt_cv_sys_max_cmd_len=16384
+    #
+    if test -x /sbin/sysconfig; then
+      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
+        *1*) lt_cv_sys_max_cmd_len=-1 ;;
+      esac
+    fi
+    ;;
+  sco3.2v5*)
+    lt_cv_sys_max_cmd_len=102400
+    ;;
+  sysv5* | sco5v6* | sysv4.2uw2*)
+    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
+    if test -n "$kargmax"; then
+      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ 	]]//'`
+    else
+      lt_cv_sys_max_cmd_len=32768
+    fi
+    ;;
+  *)
+    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
+    if test -n "$lt_cv_sys_max_cmd_len"; then
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    else
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
+      while (test "X"`$SHELL [$]0 --fallback-echo "X$teststring" 2>/dev/null` \
+	       = "XX$teststring") >/dev/null 2>&1 &&
+	      new_result=`expr "X$teststring" : ".*" 2>&1` &&
+	      lt_cv_sys_max_cmd_len=$new_result &&
+	      test $i != 17 # 1/2 MB should be enough
+      do
+        i=`expr $i + 1`
+        teststring=$teststring$teststring
+      done
+      teststring=
+      # Add a significant safety factor because C++ compilers can tack on massive
+      # amounts of additional arguments before passing them to the linker.
+      # It appears as though 1/2 is a usable value.
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    fi
+    ;;
+  esac
+])
+if test -n $lt_cv_sys_max_cmd_len ; then
+  AC_MSG_RESULT($lt_cv_sys_max_cmd_len)
+else
+  AC_MSG_RESULT(none)
+fi
+])# AC_LIBTOOL_SYS_MAX_CMD_LEN
+
+
+# _LT_AC_CHECK_DLFCN
+# ------------------
+AC_DEFUN([_LT_AC_CHECK_DLFCN],
+[AC_CHECK_HEADERS(dlfcn.h)dnl
+])# _LT_AC_CHECK_DLFCN
+
+
+# _LT_AC_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE,
+#                           ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING)
+# ---------------------------------------------------------------------
+AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF],
+[AC_REQUIRE([_LT_AC_CHECK_DLFCN])dnl
+if test "$cross_compiling" = yes; then :
+  [$4]
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<EOF
+[#line __oline__ "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL		RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL		DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL		0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW		RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW		DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW	RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW	DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW	0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+#ifdef __cplusplus
+extern "C" void exit (int);
+#endif
+
+void fnord() { int i=42;}
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+    exit (status);
+}]
+EOF
+  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) $1 ;;
+      x$lt_dlneed_uscore) $2 ;;
+      x$lt_dlunknown|x*) $3 ;;
+    esac
+  else :
+    # compilation failed
+    $3
+  fi
+fi
+rm -fr conftest*
+])# _LT_AC_TRY_DLOPEN_SELF
+
+
+# AC_LIBTOOL_DLOPEN_SELF
+# ----------------------
+AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF],
+[AC_REQUIRE([_LT_AC_CHECK_DLFCN])dnl
+if test "x$enable_dlopen" != xyes; then
+  enable_dlopen=unknown
+  enable_dlopen_self=unknown
+  enable_dlopen_self_static=unknown
+else
+  lt_cv_dlopen=no
+  lt_cv_dlopen_libs=
+
+  case $host_os in
+  beos*)
+    lt_cv_dlopen="load_add_on"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ;;
+
+  mingw* | pw32*)
+    lt_cv_dlopen="LoadLibrary"
+    lt_cv_dlopen_libs=
+   ;;
+
+  cygwin*)
+    lt_cv_dlopen="dlopen"
+    lt_cv_dlopen_libs=
+   ;;
+
+  darwin*)
+  # if libdl is installed we need to link against it
+    AC_CHECK_LIB([dl], [dlopen],
+		[lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[
+    lt_cv_dlopen="dyld"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ])
+   ;;
+
+  *)
+    AC_CHECK_FUNC([shl_load],
+	  [lt_cv_dlopen="shl_load"],
+      [AC_CHECK_LIB([dld], [shl_load],
+	    [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-dld"],
+	[AC_CHECK_FUNC([dlopen],
+	      [lt_cv_dlopen="dlopen"],
+	  [AC_CHECK_LIB([dl], [dlopen],
+		[lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],
+	    [AC_CHECK_LIB([svld], [dlopen],
+		  [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"],
+	      [AC_CHECK_LIB([dld], [dld_link],
+		    [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-dld"])
+	      ])
+	    ])
+	  ])
+	])
+      ])
+    ;;
+  esac
+
+  if test "x$lt_cv_dlopen" != xno; then
+    enable_dlopen=yes
+  else
+    enable_dlopen=no
+  fi
+
+  case $lt_cv_dlopen in
+  dlopen)
+    save_CPPFLAGS="$CPPFLAGS"
+    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
+
+    save_LDFLAGS="$LDFLAGS"
+    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
+
+    save_LIBS="$LIBS"
+    LIBS="$lt_cv_dlopen_libs $LIBS"
+
+    AC_CACHE_CHECK([whether a program can dlopen itself],
+	  lt_cv_dlopen_self, [dnl
+	  _LT_AC_TRY_DLOPEN_SELF(
+	    lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes,
+	    lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross)
+    ])
+
+    if test "x$lt_cv_dlopen_self" = xyes; then
+      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
+      AC_CACHE_CHECK([whether a statically linked program can dlopen itself],
+    	  lt_cv_dlopen_self_static, [dnl
+	  _LT_AC_TRY_DLOPEN_SELF(
+	    lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes,
+	    lt_cv_dlopen_self_static=no,  lt_cv_dlopen_self_static=cross)
+      ])
+    fi
+
+    CPPFLAGS="$save_CPPFLAGS"
+    LDFLAGS="$save_LDFLAGS"
+    LIBS="$save_LIBS"
+    ;;
+  esac
+
+  case $lt_cv_dlopen_self in
+  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
+  *) enable_dlopen_self=unknown ;;
+  esac
+
+  case $lt_cv_dlopen_self_static in
+  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
+  *) enable_dlopen_self_static=unknown ;;
+  esac
+fi
+])# AC_LIBTOOL_DLOPEN_SELF
+
+
+# AC_LIBTOOL_PROG_CC_C_O([TAGNAME])
+# ---------------------------------
+# Check to see if options -c and -o are simultaneously supported by compiler
+AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O],
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
+AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl
+AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext],
+  [_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)],
+  [_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no
+   $rm -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&AS_MESSAGE_LOG_FD
+   echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       _LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
+     fi
+   fi
+   chmod u+w . 2>&AS_MESSAGE_LOG_FD
+   $rm conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files
+   $rm out/* && rmdir out
+   cd ..
+   rmdir conftest
+   $rm conftest*
+])
+])# AC_LIBTOOL_PROG_CC_C_O
+
+
+# AC_LIBTOOL_SYS_HARD_LINK_LOCKS([TAGNAME])
+# -----------------------------------------
+# Check to see if we can do hard links to lock some files if needed
+AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS],
+[AC_REQUIRE([_LT_AC_LOCK])dnl
+
+hard_links="nottested"
+if test "$_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  AC_MSG_CHECKING([if we can lock with hard links])
+  hard_links=yes
+  $rm conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  AC_MSG_RESULT([$hard_links])
+  if test "$hard_links" = no; then
+    AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe])
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+])# AC_LIBTOOL_SYS_HARD_LINK_LOCKS
+
+
+# AC_LIBTOOL_OBJDIR
+# -----------------
+AC_DEFUN([AC_LIBTOOL_OBJDIR],
+[AC_CACHE_CHECK([for objdir], [lt_cv_objdir],
+[rm -f .libs 2>/dev/null
+mkdir .libs 2>/dev/null
+if test -d .libs; then
+  lt_cv_objdir=.libs
+else
+  # MS-DOS does not allow filenames that begin with a dot.
+  lt_cv_objdir=_libs
+fi
+rmdir .libs 2>/dev/null])
+objdir=$lt_cv_objdir
+])# AC_LIBTOOL_OBJDIR
+
+
+# AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH([TAGNAME])
+# ----------------------------------------------
+# Check hardcoding attributes.
+AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH],
+[AC_MSG_CHECKING([how to hardcode library paths into programs])
+_LT_AC_TAGVAR(hardcode_action, $1)=
+if test -n "$_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)" || \
+   test -n "$_LT_AC_TAGVAR(runpath_var, $1)" || \
+   test "X$_LT_AC_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then
+
+  # We can hardcode non-existant directories.
+  if test "$_LT_AC_TAGVAR(hardcode_direct, $1)" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)" != no &&
+     test "$_LT_AC_TAGVAR(hardcode_minus_L, $1)" != no; then
+    # Linking always hardcodes the temporary library directory.
+    _LT_AC_TAGVAR(hardcode_action, $1)=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    _LT_AC_TAGVAR(hardcode_action, $1)=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  _LT_AC_TAGVAR(hardcode_action, $1)=unsupported
+fi
+AC_MSG_RESULT([$_LT_AC_TAGVAR(hardcode_action, $1)])
+
+if test "$_LT_AC_TAGVAR(hardcode_action, $1)" = relink; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+])# AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH
+
+
+# AC_LIBTOOL_SYS_LIB_STRIP
+# ------------------------
+AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP],
+[striplib=
+old_striplib=
+AC_MSG_CHECKING([whether stripping libraries is possible])
+if test -n "$STRIP" && $STRIP -V 2>&1 | grep "GNU strip" >/dev/null; then
+  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
+  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
+  AC_MSG_RESULT([yes])
+else
+# FIXME - insert some real tests, host_os isn't really good enough
+  case $host_os in
+   darwin*)
+       if test -n "$STRIP" ; then
+         striplib="$STRIP -x"
+         old_striplib="$STRIP -S"
+         AC_MSG_RESULT([yes])
+       else
+  AC_MSG_RESULT([no])
+fi
+       ;;
+   *)
+  AC_MSG_RESULT([no])
+    ;;
+  esac
+fi
+])# AC_LIBTOOL_SYS_LIB_STRIP
+
+
+# AC_LIBTOOL_SYS_DYNAMIC_LINKER
+# -----------------------------
+# PORTME Fill in your ld.so characteristics
+AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER],
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
+AC_MSG_CHECKING([dynamic linker characteristics])
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+m4_if($1,[],[
+if test "$GCC" = yes; then
+  case $host_os in
+    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
+    *) lt_awk_arg="/^libraries:/" ;;
+  esac
+  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+  if echo "$lt_search_path_spec" | grep ';' >/dev/null ; then
+    # if the path contains ";" then we assume it to be the separator
+    # otherwise default to the standard path separator (i.e. ":") - it is
+    # assumed that no part of a normal pathname contains ";" but that should
+    # okay in the real world where ";" in dirpaths is itself problematic.
+    lt_search_path_spec=`echo "$lt_search_path_spec" | $SED -e 's/;/ /g'`
+  else
+    lt_search_path_spec=`echo "$lt_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+  fi
+  # Ok, now we have the path, separated by spaces, we can step through it
+  # and add multilib dir if necessary.
+  lt_tmp_lt_search_path_spec=
+  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
+  for lt_sys_path in $lt_search_path_spec; do
+    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
+      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
+    else
+      test -d "$lt_sys_path" && \
+	lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
+    fi
+  done
+  lt_search_path_spec=`echo $lt_tmp_lt_search_path_spec | awk '
+BEGIN {RS=" "; FS="/|\n";} {
+  lt_foo="";
+  lt_count=0;
+  for (lt_i = NF; lt_i > 0; lt_i--) {
+    if ($lt_i != "" && $lt_i != ".") {
+      if ($lt_i == "..") {
+        lt_count++;
+      } else {
+        if (lt_count == 0) {
+          lt_foo="/" $lt_i lt_foo;
+        } else {
+          lt_count--;
+        }
+      }
+    }
+  }
+  if (lt_foo != "") { lt_freq[[lt_foo]]++; }
+  if (lt_freq[[lt_foo]] == 1) { print lt_foo; }
+}'`
+  sys_lib_search_path_spec=`echo $lt_search_path_spec`
+else
+  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
+fi])
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix4* | aix5*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[[01]] | aix4.[[01]].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+	   echo ' yes '
+	   echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then
+	:
+      else
+	can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  library_names_spec='$libname.ixlibrary $libname.a'
+  # Create ${libname}_ixlibrary.a entries in /sys/libs.
+  finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[[45]]*)
+  version_type=linux
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$host_os in
+  yes,cygwin* | yes,mingw* | yes,pw32*)
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $rm \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
+      ;;
+    mingw*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+      if echo "$sys_lib_search_path_spec" | [grep ';[c-zC-Z]:/' >/dev/null]; then
+        # It is most probably a Windows format PATH printed by
+        # mingw gcc, but we are running on Cygwin. Gcc prints its search
+        # path with ; separators, and with drive letters. We can handle the
+        # drive letters (cygwin fileutils understands them), so leave them,
+        # especially as we might pass files found there to a mingw objdump,
+        # which wouldn't understand a cygwinified path. Ahh.
+        sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    ;;
+
+  *)
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    ;;
+  esac
+  dynamic_linker='Win32 ld.exe'
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+  m4_if([$1], [],[
+  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"]) 
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd1*)
+  dynamic_linker=no
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[[123]]*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[[01]]* | freebsdelf3.[[01]]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \
+  freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+gnu*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+   hppa*64*)
+     shrext_cmds='.sl'
+     hardcode_into_libs=yes
+     dynamic_linker="$host_os dld.sl"
+     shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+     shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+     library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+     soname_spec='${libname}${release}${shared_ext}$major'
+     sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+     sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+     ;;
+   *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555.
+  postinstall_cmds='chmod 555 $lib'
+  ;;
+
+interix[[3-9]]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+	if test "$lt_cv_prog_gnu_ld" = yes; then
+		version_type=linux
+	else
+		version_type=irix
+	fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ 	]*hwcap[ 	]/d;s/[:,	]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+nto-qnx*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*) need_version=yes ;;
+    *)                         need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[[89]] | openbsd2.[[89]].*)
+	shlibpath_overrides_runpath=no
+	;;
+      *)
+	shlibpath_overrides_runpath=yes
+	;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      export_dynamic_flag_spec='${wl}-Blargedynsym'
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+    shlibpath_overrides_runpath=no
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    shlibpath_overrides_runpath=yes
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+	;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+uts4*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+AC_MSG_RESULT([$dynamic_linker])
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+])# AC_LIBTOOL_SYS_DYNAMIC_LINKER
+
+
+# _LT_AC_TAGCONFIG
+# ----------------
+AC_DEFUN([_LT_AC_TAGCONFIG],
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
+AC_ARG_WITH([tags],
+    [AC_HELP_STRING([--with-tags@<:@=TAGS@:>@],
+        [include additional configurations @<:@automatic@:>@])],
+    [tagnames="$withval"])
+
+if test -f "$ltmain" && test -n "$tagnames"; then
+  if test ! -f "${ofile}"; then
+    AC_MSG_WARN([output file `$ofile' does not exist])
+  fi
+
+  if test -z "$LTCC"; then
+    eval "`$SHELL ${ofile} --config | grep '^LTCC='`"
+    if test -z "$LTCC"; then
+      AC_MSG_WARN([output file `$ofile' does not look like a libtool script])
+    else
+      AC_MSG_WARN([using `LTCC=$LTCC', extracted from `$ofile'])
+    fi
+  fi
+  if test -z "$LTCFLAGS"; then
+    eval "`$SHELL ${ofile} --config | grep '^LTCFLAGS='`"
+  fi
+
+  # Extract list of available tagged configurations in $ofile.
+  # Note that this assumes the entire list is on one line.
+  available_tags=`grep "^available_tags=" "${ofile}" | $SED -e 's/available_tags=\(.*$\)/\1/' -e 's/\"//g'`
+
+  lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+  for tagname in $tagnames; do
+    IFS="$lt_save_ifs"
+    # Check whether tagname contains only valid characters
+    case `$echo "X$tagname" | $Xsed -e 's:[[-_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,/]]::g'` in
+    "") ;;
+    *)  AC_MSG_ERROR([invalid tag name: $tagname])
+	;;
+    esac
+
+    if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "${ofile}" > /dev/null
+    then
+      AC_MSG_ERROR([tag name \"$tagname\" already exists])
+    fi
+
+    # Update the list of available tags.
+    if test -n "$tagname"; then
+      echo appending configuration tag \"$tagname\" to $ofile
+
+      case $tagname in
+      CXX)
+	if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
+	    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
+	    (test "X$CXX" != "Xg++"))) ; then
+	  AC_LIBTOOL_LANG_CXX_CONFIG
+	else
+	  tagname=""
+	fi
+	;;
+
+      F77)
+	if test -n "$F77" && test "X$F77" != "Xno"; then
+	  AC_LIBTOOL_LANG_F77_CONFIG
+	else
+	  tagname=""
+	fi
+	;;
+
+      GCJ)
+	if test -n "$GCJ" && test "X$GCJ" != "Xno"; then
+	  AC_LIBTOOL_LANG_GCJ_CONFIG
+	else
+	  tagname=""
+	fi
+	;;
+
+      RC)
+	AC_LIBTOOL_LANG_RC_CONFIG
+	;;
+
+      *)
+	AC_MSG_ERROR([Unsupported tag name: $tagname])
+	;;
+      esac
+
+      # Append the new tag name to the list of available tags.
+      if test -n "$tagname" ; then
+      available_tags="$available_tags $tagname"
+    fi
+    fi
+  done
+  IFS="$lt_save_ifs"
+
+  # Now substitute the updated list of available tags.
+  if eval "sed -e 's/^available_tags=.*\$/available_tags=\"$available_tags\"/' \"$ofile\" > \"${ofile}T\""; then
+    mv "${ofile}T" "$ofile"
+    chmod +x "$ofile"
+  else
+    rm -f "${ofile}T"
+    AC_MSG_ERROR([unable to update list of available tagged configurations.])
+  fi
+fi
+])# _LT_AC_TAGCONFIG
+
+
+# AC_LIBTOOL_DLOPEN
+# -----------------
+# enable checks for dlopen support
+AC_DEFUN([AC_LIBTOOL_DLOPEN],
+ [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])
+])# AC_LIBTOOL_DLOPEN
+
+
+# AC_LIBTOOL_WIN32_DLL
+# --------------------
+# declare package support for building win32 DLLs
+AC_DEFUN([AC_LIBTOOL_WIN32_DLL],
+[AC_BEFORE([$0], [AC_LIBTOOL_SETUP])
+])# AC_LIBTOOL_WIN32_DLL
+
+
+# AC_ENABLE_SHARED([DEFAULT])
+# ---------------------------
+# implement the --enable-shared flag
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+AC_DEFUN([AC_ENABLE_SHARED],
+[define([AC_ENABLE_SHARED_DEFAULT], ifelse($1, no, no, yes))dnl
+AC_ARG_ENABLE([shared],
+    [AC_HELP_STRING([--enable-shared@<:@=PKGS@:>@],
+	[build shared libraries @<:@default=]AC_ENABLE_SHARED_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_shared=yes ;;
+    no) enable_shared=no ;;
+    *)
+      enable_shared=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_shared=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_shared=]AC_ENABLE_SHARED_DEFAULT)
+])# AC_ENABLE_SHARED
+
+
+# AC_DISABLE_SHARED
+# -----------------
+# set the default shared flag to --disable-shared
+AC_DEFUN([AC_DISABLE_SHARED],
+[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
+AC_ENABLE_SHARED(no)
+])# AC_DISABLE_SHARED
+
+
+# AC_ENABLE_STATIC([DEFAULT])
+# ---------------------------
+# implement the --enable-static flag
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+AC_DEFUN([AC_ENABLE_STATIC],
+[define([AC_ENABLE_STATIC_DEFAULT], ifelse($1, no, no, yes))dnl
+AC_ARG_ENABLE([static],
+    [AC_HELP_STRING([--enable-static@<:@=PKGS@:>@],
+	[build static libraries @<:@default=]AC_ENABLE_STATIC_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_static=yes ;;
+    no) enable_static=no ;;
+    *)
+     enable_static=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_static=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_static=]AC_ENABLE_STATIC_DEFAULT)
+])# AC_ENABLE_STATIC
+
+
+# AC_DISABLE_STATIC
+# -----------------
+# set the default static flag to --disable-static
+AC_DEFUN([AC_DISABLE_STATIC],
+[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
+AC_ENABLE_STATIC(no)
+])# AC_DISABLE_STATIC
+
+
+# AC_ENABLE_FAST_INSTALL([DEFAULT])
+# ---------------------------------
+# implement the --enable-fast-install flag
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+AC_DEFUN([AC_ENABLE_FAST_INSTALL],
+[define([AC_ENABLE_FAST_INSTALL_DEFAULT], ifelse($1, no, no, yes))dnl
+AC_ARG_ENABLE([fast-install],
+    [AC_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@],
+    [optimize for fast installation @<:@default=]AC_ENABLE_FAST_INSTALL_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_fast_install=yes ;;
+    no) enable_fast_install=no ;;
+    *)
+      enable_fast_install=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_fast_install=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_fast_install=]AC_ENABLE_FAST_INSTALL_DEFAULT)
+])# AC_ENABLE_FAST_INSTALL
+
+
+# AC_DISABLE_FAST_INSTALL
+# -----------------------
+# set the default to --disable-fast-install
+AC_DEFUN([AC_DISABLE_FAST_INSTALL],
+[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
+AC_ENABLE_FAST_INSTALL(no)
+])# AC_DISABLE_FAST_INSTALL
+
+
+# AC_LIBTOOL_PICMODE([MODE])
+# --------------------------
+# implement the --with-pic flag
+# MODE is either `yes' or `no'.  If omitted, it defaults to `both'.
+AC_DEFUN([AC_LIBTOOL_PICMODE],
+[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
+pic_mode=ifelse($#,1,$1,default)
+])# AC_LIBTOOL_PICMODE
+
+
+# AC_PROG_EGREP
+# -------------
+# This is predefined starting with Autoconf 2.54, so this conditional
+# definition can be removed once we require Autoconf 2.54 or later.
+m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP],
+[AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
+   [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
+    then ac_cv_prog_egrep='grep -E'
+    else ac_cv_prog_egrep='egrep'
+    fi])
+ EGREP=$ac_cv_prog_egrep
+ AC_SUBST([EGREP])
+])])
+
+
+# AC_PATH_TOOL_PREFIX
+# -------------------
+# find a file program which can recognize shared library
+AC_DEFUN([AC_PATH_TOOL_PREFIX],
+[AC_REQUIRE([AC_PROG_EGREP])dnl
+AC_MSG_CHECKING([for $1])
+AC_CACHE_VAL(lt_cv_path_MAGIC_CMD,
+[case $MAGIC_CMD in
+[[\\/*] |  ?:[\\/]*])
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+dnl $ac_dummy forces splitting on constant user-supplied paths.
+dnl POSIX.2 word splitting is done only on the output of word expansions,
+dnl not every word.  This closes a longstanding sh security hole.
+  ac_dummy="ifelse([$2], , $PATH, [$2])"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/$1; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/$1"
+      if test -n "$file_magic_test_file"; then
+	case $deplibs_check_method in
+	"file_magic "*)
+	  file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+	  MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+	  if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+	    $EGREP "$file_magic_regex" > /dev/null; then
+	    :
+	  else
+	    cat <<EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool at gnu.org
+
+EOF
+	  fi ;;
+	esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac])
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  AC_MSG_RESULT($MAGIC_CMD)
+else
+  AC_MSG_RESULT(no)
+fi
+])# AC_PATH_TOOL_PREFIX
+
+
+# AC_PATH_MAGIC
+# -------------
+# find a file program which can recognize a shared library
+AC_DEFUN([AC_PATH_MAGIC],
+[AC_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH)
+if test -z "$lt_cv_path_MAGIC_CMD"; then
+  if test -n "$ac_tool_prefix"; then
+    AC_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH)
+  else
+    MAGIC_CMD=:
+  fi
+fi
+])# AC_PATH_MAGIC
+
+
+# AC_PROG_LD
+# ----------
+# find the pathname to the GNU or non-GNU linker
+AC_DEFUN([AC_PROG_LD],
+[AC_ARG_WITH([gnu-ld],
+    [AC_HELP_STRING([--with-gnu-ld],
+	[assume the C compiler uses GNU ld @<:@default=no@:>@])],
+    [test "$withval" = no || with_gnu_ld=yes],
+    [with_gnu_ld=no])
+AC_REQUIRE([LT_AC_PROG_SED])dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  AC_MSG_CHECKING([for ld used by $CC])
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [[\\/]]* | ?:[[\\/]]*)
+      re_direlt='/[[^/]][[^/]]*/\.\./'
+      # Canonicalize the pathname of ld
+      ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
+      while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
+	ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  AC_MSG_CHECKING([for GNU ld])
+else
+  AC_MSG_CHECKING([for non-GNU ld])
+fi
+AC_CACHE_VAL(lt_cv_path_LD,
+[if test -z "$LD"; then
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for ac_dir in $PATH; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      lt_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some variants of GNU ld only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
+      *GNU* | *'with BFD'*)
+	test "$with_gnu_ld" != no && break
+	;;
+      *)
+	test "$with_gnu_ld" != yes && break
+	;;
+      esac
+    fi
+  done
+  IFS="$lt_save_ifs"
+else
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+fi])
+LD="$lt_cv_path_LD"
+if test -n "$LD"; then
+  AC_MSG_RESULT($LD)
+else
+  AC_MSG_RESULT(no)
+fi
+test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
+AC_PROG_LD_GNU
+])# AC_PROG_LD
+
+
+# AC_PROG_LD_GNU
+# --------------
+AC_DEFUN([AC_PROG_LD_GNU],
+[AC_REQUIRE([AC_PROG_EGREP])dnl
+AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
+[# I'd rather use --version here, but apparently some GNU lds only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  lt_cv_prog_gnu_ld=yes
+  ;;
+*)
+  lt_cv_prog_gnu_ld=no
+  ;;
+esac])
+with_gnu_ld=$lt_cv_prog_gnu_ld
+])# AC_PROG_LD_GNU
+
+
+# AC_PROG_LD_RELOAD_FLAG
+# ----------------------
+# find reload flag for linker
+#   -- PORTME Some linkers may need a different reload flag.
+AC_DEFUN([AC_PROG_LD_RELOAD_FLAG],
+[AC_CACHE_CHECK([for $LD option to reload object files],
+  lt_cv_ld_reload_flag,
+  [lt_cv_ld_reload_flag='-r'])
+reload_flag=$lt_cv_ld_reload_flag
+case $reload_flag in
+"" | " "*) ;;
+*) reload_flag=" $reload_flag" ;;
+esac
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
+case $host_os in
+  darwin*)
+    if test "$GCC" = yes; then
+      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
+    else
+      reload_cmds='$LD$reload_flag -o $output$reload_objs'
+    fi
+    ;;
+esac
+])# AC_PROG_LD_RELOAD_FLAG
+
+
+# AC_DEPLIBS_CHECK_METHOD
+# -----------------------
+# how to check for library dependencies
+#  -- PORTME fill in with the dynamic library characteristics
+AC_DEFUN([AC_DEPLIBS_CHECK_METHOD],
+[AC_CACHE_CHECK([how to recognize dependent libraries],
+lt_cv_deplibs_check_method,
+[lt_cv_file_magic_cmd='$MAGIC_CMD'
+lt_cv_file_magic_test_file=
+lt_cv_deplibs_check_method='unknown'
+# Need to set the preceding variable on all platforms that support
+# interlibrary dependencies.
+# 'none' -- dependencies not supported.
+# `unknown' -- same as none, but documents that we really don't know.
+# 'pass_all' -- all dependencies passed with no checks.
+# 'test_compile' -- check by making test program.
+# 'file_magic [[regex]]' -- check by looking for files in library path
+# which responds to the $file_magic_cmd with a given extended regex.
+# If you have `file' or equivalent on your system and you're not sure
+# whether `pass_all' will *always* work, you probably want this one.
+
+case $host_os in
+aix4* | aix5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+beos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+bsdi[[45]]*)
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)'
+  lt_cv_file_magic_cmd='/usr/bin/file -L'
+  lt_cv_file_magic_test_file=/shlib/libc.so
+  ;;
+
+cygwin*)
+  # func_win32_libid is a shell function defined in ltmain.sh
+  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+  lt_cv_file_magic_cmd='func_win32_libid'
+  ;;
+
+mingw* | pw32*)
+  # Base MSYS/MinGW do not provide the 'file' command needed by
+  # func_win32_libid shell function, so use a weaker test based on 'objdump',
+  # unless we find 'file', for example because we are cross-compiling.
+  if ( file / ) >/dev/null 2>&1; then
+    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+    lt_cv_file_magic_cmd='func_win32_libid'
+  else
+    lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?'
+    lt_cv_file_magic_cmd='$OBJDUMP -f'
+  fi
+  ;;
+
+darwin* | rhapsody*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+freebsd* | dragonfly*)
+  if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
+    case $host_cpu in
+    i*86 )
+      # Not sure whether the presence of OpenBSD here was a mistake.
+      # Let's accept both of them until this is cleared up.
+      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library'
+      lt_cv_file_magic_cmd=/usr/bin/file
+      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
+      ;;
+    esac
+  else
+    lt_cv_deplibs_check_method=pass_all
+  fi
+  ;;
+
+gnu*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+hpux10.20* | hpux11*)
+  lt_cv_file_magic_cmd=/usr/bin/file
+  case $host_cpu in
+  ia64*)
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64'
+    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
+    ;;
+  hppa*64*)
+    [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]']
+    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
+    ;;
+  *)
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library'
+    lt_cv_file_magic_test_file=/usr/lib/libc.sl
+    ;;
+  esac
+  ;;
+
+interix[[3-9]]*)
+  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
+  lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$'
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $LD in
+  *-32|*"-32 ") libmagic=32-bit;;
+  *-n32|*"-n32 ") libmagic=N32;;
+  *-64|*"-64 ") libmagic=64-bit;;
+  *) libmagic=never-match;;
+  esac
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+netbsd*)
+  if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$'
+  fi
+  ;;
+
+newos6*)
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)'
+  lt_cv_file_magic_cmd=/usr/bin/file
+  lt_cv_file_magic_test_file=/usr/lib/libnls.so
+  ;;
+
+nto-qnx*)
+  lt_cv_deplibs_check_method=unknown
+  ;;
+
+openbsd*)
+  if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
+  fi
+  ;;
+
+osf3* | osf4* | osf5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+rdos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+solaris*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv4 | sysv4.3*)
+  case $host_vendor in
+  motorola)
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]'
+    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
+    ;;
+  ncr)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  sequent)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )'
+    ;;
+  sni)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib"
+    lt_cv_file_magic_test_file=/lib/libc.so
+    ;;
+  siemens)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  pc)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  esac
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+esac
+])
+file_magic_cmd=$lt_cv_file_magic_cmd
+deplibs_check_method=$lt_cv_deplibs_check_method
+test -z "$deplibs_check_method" && deplibs_check_method=unknown
+])# AC_DEPLIBS_CHECK_METHOD
+
+
+# AC_PROG_NM
+# ----------
+# find the pathname to a BSD-compatible name lister
+AC_DEFUN([AC_PROG_NM],
+[AC_CACHE_CHECK([for BSD-compatible nm], lt_cv_path_NM,
+[if test -n "$NM"; then
+  # Let the user override the test.
+  lt_cv_path_NM="$NM"
+else
+  lt_nm_to_check="${ac_tool_prefix}nm"
+  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
+    lt_nm_to_check="$lt_nm_to_check nm"
+  fi
+  for lt_tmp_nm in $lt_nm_to_check; do
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
+      IFS="$lt_save_ifs"
+      test -z "$ac_dir" && ac_dir=.
+      tmp_nm="$ac_dir/$lt_tmp_nm"
+      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
+	# Check to see if the nm accepts a BSD-compat flag.
+	# Adding the `sed 1q' prevents false positives on HP-UX, which says:
+	#   nm: unknown option "B" ignored
+	# Tru64's nm complains that /dev/null is an invalid object file
+	case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
+	*/dev/null* | *'Invalid file or object type'*)
+	  lt_cv_path_NM="$tmp_nm -B"
+	  break
+	  ;;
+	*)
+	  case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
+	  */dev/null*)
+	    lt_cv_path_NM="$tmp_nm -p"
+	    break
+	    ;;
+	  *)
+	    lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
+	    continue # so that we can try to find one that supports BSD flags
+	    ;;
+	  esac
+	  ;;
+	esac
+      fi
+    done
+    IFS="$lt_save_ifs"
+  done
+  test -z "$lt_cv_path_NM" && lt_cv_path_NM=nm
+fi])
+NM="$lt_cv_path_NM"
+])# AC_PROG_NM
+
+
+# AC_CHECK_LIBM
+# -------------
+# check for math library
+AC_DEFUN([AC_CHECK_LIBM],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+LIBM=
+case $host in
+*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*)
+  # These system don't have libm, or don't need it
+  ;;
+*-ncr-sysv4.3*)
+  AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
+  AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm")
+  ;;
+*)
+  AC_CHECK_LIB(m, cos, LIBM="-lm")
+  ;;
+esac
+])# AC_CHECK_LIBM
+
+
+# AC_LIBLTDL_CONVENIENCE([DIRECTORY])
+# -----------------------------------
+# sets LIBLTDL to the link flags for the libltdl convenience library and
+# LTDLINCL to the include flags for the libltdl header and adds
+# --enable-ltdl-convenience to the configure arguments.  Note that
+# AC_CONFIG_SUBDIRS is not called here.  If DIRECTORY is not provided,
+# it is assumed to be `libltdl'.  LIBLTDL will be prefixed with
+# '${top_builddir}/' and LTDLINCL will be prefixed with '${top_srcdir}/'
+# (note the single quotes!).  If your package is not flat and you're not
+# using automake, define top_builddir and top_srcdir appropriately in
+# the Makefiles.
+AC_DEFUN([AC_LIBLTDL_CONVENIENCE],
+[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
+  case $enable_ltdl_convenience in
+  no) AC_MSG_ERROR([this package needs a convenience libltdl]) ;;
+  "") enable_ltdl_convenience=yes
+      ac_configure_args="$ac_configure_args --enable-ltdl-convenience" ;;
+  esac
+  LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdlc.la
+  LTDLINCL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
+  # For backwards non-gettext consistent compatibility...
+  INCLTDL="$LTDLINCL"
+])# AC_LIBLTDL_CONVENIENCE
+
+
+# AC_LIBLTDL_INSTALLABLE([DIRECTORY])
+# -----------------------------------
+# sets LIBLTDL to the link flags for the libltdl installable library and
+# LTDLINCL to the include flags for the libltdl header and adds
+# --enable-ltdl-install to the configure arguments.  Note that
+# AC_CONFIG_SUBDIRS is not called here.  If DIRECTORY is not provided,
+# and an installed libltdl is not found, it is assumed to be `libltdl'.
+# LIBLTDL will be prefixed with '${top_builddir}/'# and LTDLINCL with
+# '${top_srcdir}/' (note the single quotes!).  If your package is not
+# flat and you're not using automake, define top_builddir and top_srcdir
+# appropriately in the Makefiles.
+# In the future, this macro may have to be called after AC_PROG_LIBTOOL.
+AC_DEFUN([AC_LIBLTDL_INSTALLABLE],
+[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
+  AC_CHECK_LIB(ltdl, lt_dlinit,
+  [test x"$enable_ltdl_install" != xyes && enable_ltdl_install=no],
+  [if test x"$enable_ltdl_install" = xno; then
+     AC_MSG_WARN([libltdl not installed, but installation disabled])
+   else
+     enable_ltdl_install=yes
+   fi
+  ])
+  if test x"$enable_ltdl_install" = x"yes"; then
+    ac_configure_args="$ac_configure_args --enable-ltdl-install"
+    LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdl.la
+    LTDLINCL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
+  else
+    ac_configure_args="$ac_configure_args --enable-ltdl-install=no"
+    LIBLTDL="-lltdl"
+    LTDLINCL=
+  fi
+  # For backwards non-gettext consistent compatibility...
+  INCLTDL="$LTDLINCL"
+])# AC_LIBLTDL_INSTALLABLE
+
+
+# AC_LIBTOOL_CXX
+# --------------
+# enable support for C++ libraries
+AC_DEFUN([AC_LIBTOOL_CXX],
+[AC_REQUIRE([_LT_AC_LANG_CXX])
+])# AC_LIBTOOL_CXX
+
+
+# _LT_AC_LANG_CXX
+# ---------------
+AC_DEFUN([_LT_AC_LANG_CXX],
+[AC_REQUIRE([AC_PROG_CXX])
+AC_REQUIRE([_LT_AC_PROG_CXXCPP])
+_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}CXX])
+])# _LT_AC_LANG_CXX
+
+# _LT_AC_PROG_CXXCPP
+# ------------------
+AC_DEFUN([_LT_AC_PROG_CXXCPP],
+[
+AC_REQUIRE([AC_PROG_CXX])
+if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
+    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
+    (test "X$CXX" != "Xg++"))) ; then
+  AC_PROG_CXXCPP
+fi
+])# _LT_AC_PROG_CXXCPP
+
+# AC_LIBTOOL_F77
+# --------------
+# enable support for Fortran 77 libraries
+AC_DEFUN([AC_LIBTOOL_F77],
+[AC_REQUIRE([_LT_AC_LANG_F77])
+])# AC_LIBTOOL_F77
+
+
+# _LT_AC_LANG_F77
+# ---------------
+AC_DEFUN([_LT_AC_LANG_F77],
+[AC_REQUIRE([AC_PROG_F77])
+_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}F77])
+])# _LT_AC_LANG_F77
+
+
+# AC_LIBTOOL_GCJ
+# --------------
+# enable support for GCJ libraries
+AC_DEFUN([AC_LIBTOOL_GCJ],
+[AC_REQUIRE([_LT_AC_LANG_GCJ])
+])# AC_LIBTOOL_GCJ
+
+
+# _LT_AC_LANG_GCJ
+# ---------------
+AC_DEFUN([_LT_AC_LANG_GCJ],
+[AC_PROVIDE_IFELSE([AC_PROG_GCJ],[],
+  [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],[],
+    [AC_PROVIDE_IFELSE([LT_AC_PROG_GCJ],[],
+      [ifdef([AC_PROG_GCJ],[AC_REQUIRE([AC_PROG_GCJ])],
+	 [ifdef([A][M_PROG_GCJ],[AC_REQUIRE([A][M_PROG_GCJ])],
+	   [AC_REQUIRE([A][C_PROG_GCJ_OR_A][M_PROG_GCJ])])])])])])
+_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}GCJ])
+])# _LT_AC_LANG_GCJ
+
+
+# AC_LIBTOOL_RC
+# -------------
+# enable support for Windows resource files
+AC_DEFUN([AC_LIBTOOL_RC],
+[AC_REQUIRE([LT_AC_PROG_RC])
+_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}RC])
+])# AC_LIBTOOL_RC
+
+
+# AC_LIBTOOL_LANG_C_CONFIG
+# ------------------------
+# Ensure that the configuration vars for the C compiler are
+# suitably defined.  Those variables are subsequently used by
+# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
+AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG], [_LT_AC_LANG_C_CONFIG])
+AC_DEFUN([_LT_AC_LANG_C_CONFIG],
+[lt_save_CC="$CC"
+AC_LANG_PUSH(C)
+
+# Source file extension for C test sources.
+ac_ext=c
+
+# Object file extension for compiled C test sources.
+objext=o
+_LT_AC_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(){return(0);}'
+
+_LT_AC_SYS_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+AC_LIBTOOL_PROG_COMPILER_NO_RTTI($1)
+AC_LIBTOOL_PROG_COMPILER_PIC($1)
+AC_LIBTOOL_PROG_CC_C_O($1)
+AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1)
+AC_LIBTOOL_PROG_LD_SHLIBS($1)
+AC_LIBTOOL_SYS_DYNAMIC_LINKER($1)
+AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1)
+AC_LIBTOOL_SYS_LIB_STRIP
+AC_LIBTOOL_DLOPEN_SELF
+
+# Report which library types will actually be built
+AC_MSG_CHECKING([if libtool supports shared libraries])
+AC_MSG_RESULT([$can_build_shared])
+
+AC_MSG_CHECKING([whether to build shared libraries])
+test "$can_build_shared" = "no" && enable_shared=no
+
+# On AIX, shared libraries and static libraries use the same namespace, and
+# are all built from PIC.
+case $host_os in
+aix3*)
+  test "$enable_shared" = yes && enable_static=no
+  if test -n "$RANLIB"; then
+    archive_cmds="$archive_cmds~\$RANLIB \$lib"
+    postinstall_cmds='$RANLIB $lib'
+  fi
+  ;;
+
+aix4* | aix5*)
+  if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+    test "$enable_shared" = yes && enable_static=no
+  fi
+    ;;
+esac
+AC_MSG_RESULT([$enable_shared])
+
+AC_MSG_CHECKING([whether to build static libraries])
+# Make sure either enable_shared or enable_static is yes.
+test "$enable_shared" = yes || enable_static=yes
+AC_MSG_RESULT([$enable_static])
+
+AC_LIBTOOL_CONFIG($1)
+
+AC_LANG_POP
+CC="$lt_save_CC"
+])# AC_LIBTOOL_LANG_C_CONFIG
+
+
+# AC_LIBTOOL_LANG_CXX_CONFIG
+# --------------------------
+# Ensure that the configuration vars for the C compiler are
+# suitably defined.  Those variables are subsequently used by
+# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
+AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG], [_LT_AC_LANG_CXX_CONFIG(CXX)])
+AC_DEFUN([_LT_AC_LANG_CXX_CONFIG],
+[AC_LANG_PUSH(C++)
+AC_REQUIRE([AC_PROG_CXX])
+AC_REQUIRE([_LT_AC_PROG_CXXCPP])
+
+_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_AC_TAGVAR(allow_undefined_flag, $1)=
+_LT_AC_TAGVAR(always_export_symbols, $1)=no
+_LT_AC_TAGVAR(archive_expsym_cmds, $1)=
+_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_AC_TAGVAR(hardcode_direct, $1)=no
+_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_AC_TAGVAR(hardcode_minus_L, $1)=no
+_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+_LT_AC_TAGVAR(hardcode_automatic, $1)=no
+_LT_AC_TAGVAR(module_cmds, $1)=
+_LT_AC_TAGVAR(module_expsym_cmds, $1)=
+_LT_AC_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_AC_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_AC_TAGVAR(no_undefined_flag, $1)=
+_LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Dependencies to place before and after the object being linked:
+_LT_AC_TAGVAR(predep_objects, $1)=
+_LT_AC_TAGVAR(postdep_objects, $1)=
+_LT_AC_TAGVAR(predeps, $1)=
+_LT_AC_TAGVAR(postdeps, $1)=
+_LT_AC_TAGVAR(compiler_lib_search_path, $1)=
+
+# Source file extension for C++ test sources.
+ac_ext=cpp
+
+# Object file extension for compiled C++ test sources.
+objext=o
+_LT_AC_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }'
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_AC_SYS_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC=$CC
+lt_save_LD=$LD
+lt_save_GCC=$GCC
+GCC=$GXX
+lt_save_with_gnu_ld=$with_gnu_ld
+lt_save_path_LD=$lt_cv_path_LD
+if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then
+  lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx
+else
+  $as_unset lt_cv_prog_gnu_ld
+fi
+if test -n "${lt_cv_path_LDCXX+set}"; then
+  lt_cv_path_LD=$lt_cv_path_LDCXX
+else
+  $as_unset lt_cv_path_LD
+fi
+test -z "${LDCXX+set}" || LD=$LDCXX
+CC=${CXX-"c++"}
+compiler=$CC
+_LT_AC_TAGVAR(compiler, $1)=$CC
+_LT_CC_BASENAME([$compiler])
+
+# We don't want -fno-exception wen compiling C++ code, so set the
+# no_builtin_flag separately
+if test "$GXX" = yes; then
+  _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
+else
+  _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
+fi
+
+if test "$GXX" = yes; then
+  # Set up default GNU C++ configuration
+
+  AC_PROG_LD
+
+  # Check if GNU C++ uses GNU ld as the underlying linker, since the
+  # archiving commands below assume that GNU ld is being used.
+  if test "$with_gnu_ld" = yes; then
+    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+    _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
+    _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to
+    #     investigate it a little bit more. (MM)
+    wlarc='${wl}'
+
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if eval "`$CC -print-prog-name=ld` --help 2>&1" | \
+	grep 'no-whole-archive' > /dev/null; then
+      _LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+    else
+      _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+  else
+    with_gnu_ld=no
+    wlarc=
+
+    # A generic and very simple default shared library creation
+    # command for GNU C++ for the case where it uses the native
+    # linker, instead of GNU ld.  If possible, this setting should
+    # overridden to take advantage of the native linker features on
+    # the platform it is being used on.
+    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+  fi
+
+  # Commands to make compiler produce verbose output that lists
+  # what "hidden" libraries, object files and flags are used when
+  # linking a shared library.
+  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"'
+
+else
+  GXX=no
+  with_gnu_ld=no
+  wlarc=
+fi
+
+# PORTME: fill in a description of your system's C++ link characteristics
+AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
+_LT_AC_TAGVAR(ld_shlibs, $1)=yes
+case $host_os in
+  aix3*)
+    # FIXME: insert proper C++ library support
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
+    ;;
+  aix4* | aix5*)
+    if test "$host_cpu" = ia64; then
+      # On IA64, the linker does run time linking by default, so we don't
+      # have to do anything special.
+      aix_use_runtimelinking=no
+      exp_sym_flag='-Bexport'
+      no_entry_flag=""
+    else
+      aix_use_runtimelinking=no
+
+      # Test if we are trying to use run time linking or normal
+      # AIX style linking. If -brtl is somewhere in LDFLAGS, we
+      # need to do runtime linking.
+      case $host_os in aix4.[[23]]|aix4.[[23]].*|aix5*)
+	for ld_flag in $LDFLAGS; do
+	  case $ld_flag in
+	  *-brtl*)
+	    aix_use_runtimelinking=yes
+	    break
+	    ;;
+	  esac
+	done
+	;;
+      esac
+
+      exp_sym_flag='-bexport'
+      no_entry_flag='-bnoentry'
+    fi
+
+    # When large executables or shared objects are built, AIX ld can
+    # have problems creating the table of contents.  If linking a library
+    # or program results in "error TOC overflow" add -mminimal-toc to
+    # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+    # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+    _LT_AC_TAGVAR(archive_cmds, $1)=''
+    _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+    _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':'
+    _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
+
+    if test "$GXX" = yes; then
+      case $host_os in aix4.[[012]]|aix4.[[012]].*)
+      # We only want to do this on AIX 4.2 and lower, the check
+      # below for broken collect2 doesn't work under 4.3+
+	collect2name=`${CC} -print-prog-name=collect2`
+	if test -f "$collect2name" && \
+	   strings "$collect2name" | grep resolve_lib_name >/dev/null
+	then
+	  # We have reworked collect2
+	  :
+	else
+	  # We have old collect2
+	  _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported
+	  # It fails to find uninstalled libraries when the uninstalled
+	  # path is not listed in the libpath.  Setting hardcode_minus_L
+	  # to unsupported forces relinking
+	  _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+	  _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
+	fi
+	;;
+      esac
+      shared_flag='-shared'
+      if test "$aix_use_runtimelinking" = yes; then
+	shared_flag="$shared_flag "'${wl}-G'
+      fi
+    else
+      # not using gcc
+      if test "$host_cpu" = ia64; then
+	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+	# chokes on -Wl,-G. The following line is correct:
+	shared_flag='-G'
+      else
+	if test "$aix_use_runtimelinking" = yes; then
+	  shared_flag='${wl}-G'
+	else
+	  shared_flag='${wl}-bM:SRE'
+	fi
+      fi
+    fi
+
+    # It seems that -bexpall does not export symbols beginning with
+    # underscore (_), so it is better to generate a list of symbols to export.
+    _LT_AC_TAGVAR(always_export_symbols, $1)=yes
+    if test "$aix_use_runtimelinking" = yes; then
+      # Warning - without using the other runtime loading flags (-brtl),
+      # -berok will link without error, but may produce a broken library.
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)='-berok'
+      # Determine the default libpath from the value encoded in an empty executable.
+      _LT_AC_SYS_LIBPATH_AIX
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+
+      _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+     else
+      if test "$host_cpu" = ia64; then
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+      else
+	# Determine the default libpath from the value encoded in an empty executable.
+	_LT_AC_SYS_LIBPATH_AIX
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+	# Warning - without using the other run time loading flags,
+	# -berok will link without error, but may produce a broken library.
+	_LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
+	# Exported symbols can be pulled into shared objects from archives
+	_LT_AC_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
+	_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes
+	# This is similar to how AIX traditionally builds its shared libraries.
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+      fi
+    fi
+    ;;
+
+  beos*)
+    if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
+      # Joseph Beckenbach <jrb3 at best.com> says some releases of gcc
+      # support --undefined.  This deserves some investigation.  FIXME
+      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+    else
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
+    fi
+    ;;
+
+  chorus*)
+    case $cc_basename in
+      *)
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+    esac
+    ;;
+
+  cygwin* | mingw* | pw32*)
+    # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
+    # as there is no search path for DLLs.
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+    _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
+    _LT_AC_TAGVAR(always_export_symbols, $1)=no
+    _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+
+    if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
+      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      # If the export-symbols file already is a .def file (1st line
+      # is EXPORTS), use it as is; otherwise, prepend...
+      _LT_AC_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	cp $export_symbols $output_objdir/$soname.def;
+      else
+	echo EXPORTS > $output_objdir/$soname.def;
+	cat $export_symbols >> $output_objdir/$soname.def;
+      fi~
+      $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+    else
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
+    fi
+  ;;
+      darwin* | rhapsody*)
+        case $host_os in
+        rhapsody* | darwin1.[[012]])
+         _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}suppress'
+         ;;
+       *) # Darwin 1.3 on
+         if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then
+           _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+         else
+           case ${MACOSX_DEPLOYMENT_TARGET} in
+             10.[[012]])
+               _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+               ;;
+             10.*)
+               _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}dynamic_lookup'
+               ;;
+           esac
+         fi
+         ;;
+        esac
+      _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_AC_TAGVAR(hardcode_direct, $1)=no
+      _LT_AC_TAGVAR(hardcode_automatic, $1)=yes
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+      _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=''
+      _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
+
+    if test "$GXX" = yes ; then
+      lt_int_apple_cc_single_mod=no
+      output_verbose_link_cmd='echo'
+      if $CC -dumpspecs 2>&1 | $EGREP 'single_module' >/dev/null ; then
+       lt_int_apple_cc_single_mod=yes
+      fi
+      if test "X$lt_int_apple_cc_single_mod" = Xyes ; then
+       _LT_AC_TAGVAR(archive_cmds, $1)='$CC -dynamiclib -single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring'
+      else
+          _LT_AC_TAGVAR(archive_cmds, $1)='$CC -r -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring'
+        fi
+        _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
+        # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
+          if test "X$lt_int_apple_cc_single_mod" = Xyes ; then
+            _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib -single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          else
+            _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -r -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          fi
+            _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+      else
+      case $cc_basename in
+        xlc*)
+         output_verbose_link_cmd='echo'
+          _LT_AC_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $xlcverstring'
+          _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
+          # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
+          _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $xlcverstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          ;;
+       *)
+         _LT_AC_TAGVAR(ld_shlibs, $1)=no
+          ;;
+      esac
+      fi
+        ;;
+
+  dgux*)
+    case $cc_basename in
+      ec++*)
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+      ghcx*)
+	# Green Hills C++ Compiler
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+      *)
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+    esac
+    ;;
+  freebsd[[12]]*)
+    # C++ shared libraries reported to be fairly broken before switch to ELF
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
+    ;;
+  freebsd-elf*)
+    _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
+    ;;
+  freebsd* | dragonfly*)
+    # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF
+    # conventions
+    _LT_AC_TAGVAR(ld_shlibs, $1)=yes
+    ;;
+  gnu*)
+    ;;
+  hpux9*)
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+    _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+    _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+    _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+    _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
+				# but as the default
+				# location of the library.
+
+    case $cc_basename in
+    CC*)
+      # FIXME: insert proper C++ library support
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
+      ;;
+    aCC*)
+      _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      # Commands to make compiler produce verbose output that lists
+      # what "hidden" libraries, object files and flags are used when
+      # linking a shared library.
+      #
+      # There doesn't appear to be a way to prevent this compiler from
+      # explicitly linking system object files so we need to strip them
+      # from the output so that they don't get included in the library
+      # dependencies.
+      output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "[[-]]L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
+      ;;
+    *)
+      if test "$GXX" = yes; then
+        _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+        # FIXME: insert proper C++ library support
+        _LT_AC_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+    esac
+    ;;
+  hpux10*|hpux11*)
+    if test $with_gnu_ld = no; then
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+
+      case $host_cpu in
+      hppa*64*|ia64*) ;;
+      *)
+	_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+        ;;
+      esac
+    fi
+    case $host_cpu in
+    hppa*64*|ia64*)
+      _LT_AC_TAGVAR(hardcode_direct, $1)=no
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+    *)
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
+					      # but as the default
+					      # location of the library.
+      ;;
+    esac
+
+    case $cc_basename in
+      CC*)
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+      aCC*)
+	case $host_cpu in
+	hppa*64*)
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	  ;;
+	ia64*)
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	  ;;
+	*)
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	  ;;
+	esac
+	# Commands to make compiler produce verbose output that lists
+	# what "hidden" libraries, object files and flags are used when
+	# linking a shared library.
+	#
+	# There doesn't appear to be a way to prevent this compiler from
+	# explicitly linking system object files so we need to strip them
+	# from the output so that they don't get included in the library
+	# dependencies.
+	output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
+	;;
+      *)
+	if test "$GXX" = yes; then
+	  if test $with_gnu_ld = no; then
+	    case $host_cpu in
+	    hppa*64*)
+	      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	      ;;
+	    ia64*)
+	      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	      ;;
+	    *)
+	      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	      ;;
+	    esac
+	  fi
+	else
+	  # FIXME: insert proper C++ library support
+	  _LT_AC_TAGVAR(ld_shlibs, $1)=no
+	fi
+	;;
+    esac
+    ;;
+  interix[[3-9]]*)
+    _LT_AC_TAGVAR(hardcode_direct, $1)=no
+    _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+    _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+    # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+    # Instead, shared libraries are loaded at an image base (0x10000000 by
+    # default) and relocated if they conflict, which is a slow very memory
+    # consuming and fragmenting process.  To avoid this, we pick a random,
+    # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+    # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+    _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+    ;;
+  irix5* | irix6*)
+    case $cc_basename in
+      CC*)
+	# SGI C++
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+
+	# Archives containing C++ object files must be created using
+	# "CC -ar", where "CC" is the IRIX C++ compiler.  This is
+	# necessary to make sure instantiated templates are included
+	# in the archive.
+	_LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs'
+	;;
+      *)
+	if test "$GXX" = yes; then
+	  if test "$with_gnu_ld" = no; then
+	    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	  else
+	    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` -o $lib'
+	  fi
+	fi
+	_LT_AC_TAGVAR(link_all_deplibs, $1)=yes
+	;;
+    esac
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+    _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+    ;;
+  linux* | k*bsd*-gnu)
+    case $cc_basename in
+      KCC*)
+	# Kuck and Associates, Inc. (KAI) C++ Compiler
+
+	# KCC will only create a shared library if the output file
+	# ends with ".so" (or ".sl" for HP-UX), so rename the library
+	# to its proper name (with version) after linking.
+	_LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib'
+	# Commands to make compiler produce verbose output that lists
+	# what "hidden" libraries, object files and flags are used when
+	# linking a shared library.
+	#
+	# There doesn't appear to be a way to prevent this compiler from
+	# explicitly linking system object files so we need to strip them
+	# from the output so that they don't get included in the library
+	# dependencies.
+	output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | grep "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
+
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath,$libdir'
+	_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+
+	# Archives containing C++ object files must be created using
+	# "CC -Bstatic", where "CC" is the KAI C++ compiler.
+	_LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs'
+	;;
+      icpc*)
+	# Intel C++
+	with_gnu_ld=yes
+	# version 8.0 and above of icpc choke on multiply defined symbols
+	# if we add $predep_objects and $postdep_objects, however 7.1 and
+	# earlier do not add the objects themselves.
+	case `$CC -V 2>&1` in
+	*"Version 7."*)
+  	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+  	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+	  ;;
+	*)  # Version 8.0 or newer
+	  tmp_idyn=
+	  case $host_cpu in
+	    ia64*) tmp_idyn=' -i_dynamic';;
+	  esac
+  	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+	  ;;
+	esac
+	_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+	_LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+	;;
+      pgCC*)
+        # Portland Group C++ compiler
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+  	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
+	_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+	_LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+        ;;
+      cxx*)
+	# Compaq C++
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname  -o $lib ${wl}-retain-symbols-file $wl$export_symbols'
+
+	runpath_var=LD_RUN_PATH
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	# Commands to make compiler produce verbose output that lists
+	# what "hidden" libraries, object files and flags are used when
+	# linking a shared library.
+	#
+	# There doesn't appear to be a way to prevent this compiler from
+	# explicitly linking system object files so we need to strip them
+	# from the output so that they don't get included in the library
+	# dependencies.
+	output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
+	;;
+      *)
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)
+	  # Sun C++ 5.9
+	  _LT_AC_TAGVAR(no_undefined_flag, $1)=' -zdefs'
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols'
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+
+	  # Not sure whether something based on
+	  # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1
+	  # would be better.
+	  output_verbose_link_cmd='echo'
+
+	  # Archives containing C++ object files must be created using
+	  # "CC -xar", where "CC" is the Sun C++ compiler.  This is
+	  # necessary to make sure instantiated templates are included
+	  # in the archive.
+	  _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
+	  ;;
+	esac
+	;;
+    esac
+    ;;
+  lynxos*)
+    # FIXME: insert proper C++ library support
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
+    ;;
+  m88k*)
+    # FIXME: insert proper C++ library support
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
+    ;;
+  mvs*)
+    case $cc_basename in
+      cxx*)
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+      *)
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+    esac
+    ;;
+  netbsd*)
+    if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable  -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags'
+      wlarc=
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+    fi
+    # Workaround some broken pre-1.5 toolchains
+    output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"'
+    ;;
+  openbsd2*)
+    # C++ shared libraries are fairly broken
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
+    ;;
+  openbsd*)
+    if test -f /usr/libexec/ld.so; then
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+      if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib'
+	_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	_LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+      fi
+      output_verbose_link_cmd='echo'
+    else
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
+    fi
+    ;;
+  osf3*)
+    case $cc_basename in
+      KCC*)
+	# Kuck and Associates, Inc. (KAI) C++ Compiler
+
+	# KCC will only create a shared library if the output file
+	# ends with ".so" (or ".sl" for HP-UX), so rename the library
+	# to its proper name (with version) after linking.
+	_LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	# Archives containing C++ object files must be created using
+	# "CC -Bstatic", where "CC" is the KAI C++ compiler.
+	_LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs'
+
+	;;
+      RCC*)
+	# Rational C++ 2.4.1
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+      cxx*)
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && echo ${wl}-set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	# Commands to make compiler produce verbose output that lists
+	# what "hidden" libraries, object files and flags are used when
+	# linking a shared library.
+	#
+	# There doesn't appear to be a way to prevent this compiler from
+	# explicitly linking system object files so we need to strip them
+	# from the output so that they don't get included in the library
+	# dependencies.
+	output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
+	;;
+      *)
+	if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+	  _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	  _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	  # Commands to make compiler produce verbose output that lists
+	  # what "hidden" libraries, object files and flags are used when
+	  # linking a shared library.
+	  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"'
+
+	else
+	  # FIXME: insert proper C++ library support
+	  _LT_AC_TAGVAR(ld_shlibs, $1)=no
+	fi
+	;;
+    esac
+    ;;
+  osf4* | osf5*)
+    case $cc_basename in
+      KCC*)
+	# Kuck and Associates, Inc. (KAI) C++ Compiler
+
+	# KCC will only create a shared library if the output file
+	# ends with ".so" (or ".sl" for HP-UX), so rename the library
+	# to its proper name (with version) after linking.
+	_LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	# Archives containing C++ object files must be created using
+	# the KAI C++ compiler.
+	_LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs'
+	;;
+      RCC*)
+	# Rational C++ 2.4.1
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+      cxx*)
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~
+	  echo "-hidden">> $lib.exp~
+	  $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname -Wl,-input -Wl,$lib.exp  `test -n "$verstring" && echo -set_version	$verstring` -update_registry ${output_objdir}/so_locations -o $lib~
+	  $rm $lib.exp'
+
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	# Commands to make compiler produce verbose output that lists
+	# what "hidden" libraries, object files and flags are used when
+	# linking a shared library.
+	#
+	# There doesn't appear to be a way to prevent this compiler from
+	# explicitly linking system object files so we need to strip them
+	# from the output so that they don't get included in the library
+	# dependencies.
+	output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
+	;;
+      *)
+	if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+	  _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	 _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	  _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	  # Commands to make compiler produce verbose output that lists
+	  # what "hidden" libraries, object files and flags are used when
+	  # linking a shared library.
+	  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"'
+
+	else
+	  # FIXME: insert proper C++ library support
+	  _LT_AC_TAGVAR(ld_shlibs, $1)=no
+	fi
+	;;
+    esac
+    ;;
+  psos*)
+    # FIXME: insert proper C++ library support
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
+    ;;
+  sunos4*)
+    case $cc_basename in
+      CC*)
+	# Sun C++ 4.x
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+      lcc*)
+	# Lucid
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+      *)
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+    esac
+    ;;
+  solaris*)
+    case $cc_basename in
+      CC*)
+	# Sun C++ 4.2, 5.x and Centerline C++
+        _LT_AC_TAGVAR(archive_cmds_need_lc,$1)=yes
+	_LT_AC_TAGVAR(no_undefined_flag, $1)=' -zdefs'
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag}  -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+	$CC -G${allow_undefined_flag}  ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
+
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+	case $host_os in
+	  solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+	  *)
+	    # The compiler driver will combine and reorder linker options,
+	    # but understands `-z linker_flag'.
+	    # Supported since Solaris 2.6 (maybe 2.5.1?)
+	    _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
+	    ;;
+	esac
+	_LT_AC_TAGVAR(link_all_deplibs, $1)=yes
+
+	output_verbose_link_cmd='echo'
+
+	# Archives containing C++ object files must be created using
+	# "CC -xar", where "CC" is the Sun C++ compiler.  This is
+	# necessary to make sure instantiated templates are included
+	# in the archive.
+	_LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
+	;;
+      gcx*)
+	# Green Hills C++ Compiler
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+
+	# The C++ compiler must be used to create the archive.
+	_LT_AC_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs'
+	;;
+      *)
+	# GNU C++ compiler with Solaris linker
+	if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+	  _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs'
+	  if $CC --version | grep -v '^2\.7' > /dev/null; then
+	    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+	    _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+		$CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
+
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    output_verbose_link_cmd="$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\""
+	  else
+	    # g++ 2.7 appears to require `-G' NOT `-shared' on this
+	    # platform.
+	    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+	    _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+		$CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
+
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    output_verbose_link_cmd="$CC -G $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\""
+	  fi
+
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir'
+	  case $host_os in
+	  solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+	  *)
+	    _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+	    ;;
+	  esac
+	fi
+	;;
+    esac
+    ;;
+  sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
+    _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+    _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
+    _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+    runpath_var='LD_RUN_PATH'
+
+    case $cc_basename in
+      CC*)
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	;;
+      *)
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	;;
+    esac
+    ;;
+  sysv5* | sco3.2v5* | sco5v6*)
+    # Note: We can NOT use -z defs as we might desire, because we do not
+    # link with -lc, and that would cause any symbols used from libc to
+    # always be unresolved, which means just about no library would
+    # ever link correctly.  If we're not using GNU ld we use -z text
+    # though, which does catch some bad symbols but isn't as heavy-handed
+    # as -z defs.
+    # For security reasons, it is highly recommended that you always
+    # use absolute paths for naming shared libraries, and exclude the
+    # DT_RUNPATH tag from executables and libraries.  But doing so
+    # requires that you compile everything twice, which is a pain.
+    # So that behaviour is only enabled if SCOABSPATH is set to a
+    # non-empty value in the environment.  Most likely only useful for
+    # creating official distributions of packages.
+    # This is a hack until libtool officially supports absolute path
+    # names for shared libraries.
+    _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+    _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
+    _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
+    _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`'
+    _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':'
+    _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
+    _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
+    runpath_var='LD_RUN_PATH'
+
+    case $cc_basename in
+      CC*)
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	;;
+      *)
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	;;
+    esac
+    ;;
+  tandem*)
+    case $cc_basename in
+      NCC*)
+	# NonStop-UX NCC 3.20
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+      *)
+	# FIXME: insert proper C++ library support
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	;;
+    esac
+    ;;
+  vxworks*)
+    # FIXME: insert proper C++ library support
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
+    ;;
+  *)
+    # FIXME: insert proper C++ library support
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
+    ;;
+esac
+AC_MSG_RESULT([$_LT_AC_TAGVAR(ld_shlibs, $1)])
+test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+_LT_AC_TAGVAR(GCC, $1)="$GXX"
+_LT_AC_TAGVAR(LD, $1)="$LD"
+
+AC_LIBTOOL_POSTDEP_PREDEP($1)
+AC_LIBTOOL_PROG_COMPILER_PIC($1)
+AC_LIBTOOL_PROG_CC_C_O($1)
+AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1)
+AC_LIBTOOL_PROG_LD_SHLIBS($1)
+AC_LIBTOOL_SYS_DYNAMIC_LINKER($1)
+AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1)
+
+AC_LIBTOOL_CONFIG($1)
+
+AC_LANG_POP
+CC=$lt_save_CC
+LDCXX=$LD
+LD=$lt_save_LD
+GCC=$lt_save_GCC
+with_gnu_ldcxx=$with_gnu_ld
+with_gnu_ld=$lt_save_with_gnu_ld
+lt_cv_path_LDCXX=$lt_cv_path_LD
+lt_cv_path_LD=$lt_save_path_LD
+lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld
+lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld
+])# AC_LIBTOOL_LANG_CXX_CONFIG
+
+# AC_LIBTOOL_POSTDEP_PREDEP([TAGNAME])
+# ------------------------------------
+# Figure out "hidden" library dependencies from verbose
+# compiler output when linking a shared library.
+# Parse the compiler output and extract the necessary
+# objects, libraries and library flags.
+AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP],[
+dnl we can't use the lt_simple_compile_test_code here,
+dnl because it contains code intended for an executable,
+dnl not a library.  It's possible we should let each
+dnl tag define a new lt_????_link_test_code variable,
+dnl but it's only used here...
+ifelse([$1],[],[cat > conftest.$ac_ext <<EOF
+int a;
+void foo (void) { a = 0; }
+EOF
+],[$1],[CXX],[cat > conftest.$ac_ext <<EOF
+class Foo
+{
+public:
+  Foo (void) { a = 0; }
+private:
+  int a;
+};
+EOF
+],[$1],[F77],[cat > conftest.$ac_ext <<EOF
+      subroutine foo
+      implicit none
+      integer*4 a
+      a=0
+      return
+      end
+EOF
+],[$1],[GCJ],[cat > conftest.$ac_ext <<EOF
+public class foo {
+  private int a;
+  public void bar (void) {
+    a = 0;
+  }
+};
+EOF
+])
+dnl Parse the compiler output and extract the necessary
+dnl objects, libraries and library flags.
+if AC_TRY_EVAL(ac_compile); then
+  # Parse the compiler output and extract the necessary
+  # objects, libraries and library flags.
+
+  # Sentinel used to keep track of whether or not we are before
+  # the conftest object file.
+  pre_test_object_deps_done=no
+
+  # The `*' in the case matches for architectures that use `case' in
+  # $output_verbose_cmd can trigger glob expansion during the loop
+  # eval without this substitution.
+  output_verbose_link_cmd=`$echo "X$output_verbose_link_cmd" | $Xsed -e "$no_glob_subst"`
+
+  for p in `eval $output_verbose_link_cmd`; do
+    case $p in
+
+    -L* | -R* | -l*)
+       # Some compilers place space between "-{L,R}" and the path.
+       # Remove the space.
+       if test $p = "-L" \
+	  || test $p = "-R"; then
+	 prev=$p
+	 continue
+       else
+	 prev=
+       fi
+
+       if test "$pre_test_object_deps_done" = no; then
+	 case $p in
+	 -L* | -R*)
+	   # Internal compiler library paths should come after those
+	   # provided the user.  The postdeps already come after the
+	   # user supplied libs so there is no need to process them.
+	   if test -z "$_LT_AC_TAGVAR(compiler_lib_search_path, $1)"; then
+	     _LT_AC_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}"
+	   else
+	     _LT_AC_TAGVAR(compiler_lib_search_path, $1)="${_LT_AC_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}"
+	   fi
+	   ;;
+	 # The "-l" case would never come before the object being
+	 # linked, so don't bother handling this case.
+	 esac
+       else
+	 if test -z "$_LT_AC_TAGVAR(postdeps, $1)"; then
+	   _LT_AC_TAGVAR(postdeps, $1)="${prev}${p}"
+	 else
+	   _LT_AC_TAGVAR(postdeps, $1)="${_LT_AC_TAGVAR(postdeps, $1)} ${prev}${p}"
+	 fi
+       fi
+       ;;
+
+    *.$objext)
+       # This assumes that the test object file only shows up
+       # once in the compiler output.
+       if test "$p" = "conftest.$objext"; then
+	 pre_test_object_deps_done=yes
+	 continue
+       fi
+
+       if test "$pre_test_object_deps_done" = no; then
+	 if test -z "$_LT_AC_TAGVAR(predep_objects, $1)"; then
+	   _LT_AC_TAGVAR(predep_objects, $1)="$p"
+	 else
+	   _LT_AC_TAGVAR(predep_objects, $1)="$_LT_AC_TAGVAR(predep_objects, $1) $p"
+	 fi
+       else
+	 if test -z "$_LT_AC_TAGVAR(postdep_objects, $1)"; then
+	   _LT_AC_TAGVAR(postdep_objects, $1)="$p"
+	 else
+	   _LT_AC_TAGVAR(postdep_objects, $1)="$_LT_AC_TAGVAR(postdep_objects, $1) $p"
+	 fi
+       fi
+       ;;
+
+    *) ;; # Ignore the rest.
+
+    esac
+  done
+
+  # Clean up.
+  rm -f a.out a.exe
+else
+  echo "libtool.m4: error: problem compiling $1 test program"
+fi
+
+$rm -f confest.$objext
+
+# PORTME: override above test on systems where it is broken
+ifelse([$1],[CXX],
+[case $host_os in
+interix[[3-9]]*)
+  # Interix 3.5 installs completely hosed .la files for C++, so rather than
+  # hack all around it, let's just trust "g++" to DTRT.
+  _LT_AC_TAGVAR(predep_objects,$1)=
+  _LT_AC_TAGVAR(postdep_objects,$1)=
+  _LT_AC_TAGVAR(postdeps,$1)=
+  ;;
+
+linux*)
+  case `$CC -V 2>&1 | sed 5q` in
+  *Sun\ C*)
+    # Sun C++ 5.9
+    #
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+    if test "$solaris_use_stlport4" != yes; then
+      _LT_AC_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+
+solaris*)
+  case $cc_basename in
+  CC*)
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+
+    # Adding this requires a known-good setup of shared libraries for
+    # Sun compiler versions before 5.6, else PIC objects from an old
+    # archive will be linked into the output, leading to subtle bugs.
+    if test "$solaris_use_stlport4" != yes; then
+      _LT_AC_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+esac
+])
+
+case " $_LT_AC_TAGVAR(postdeps, $1) " in
+*" -lc "*) _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no ;;
+esac
+])# AC_LIBTOOL_POSTDEP_PREDEP
+
+# AC_LIBTOOL_LANG_F77_CONFIG
+# --------------------------
+# Ensure that the configuration vars for the C compiler are
+# suitably defined.  Those variables are subsequently used by
+# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
+AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG], [_LT_AC_LANG_F77_CONFIG(F77)])
+AC_DEFUN([_LT_AC_LANG_F77_CONFIG],
+[AC_REQUIRE([AC_PROG_F77])
+AC_LANG_PUSH(Fortran 77)
+
+_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_AC_TAGVAR(allow_undefined_flag, $1)=
+_LT_AC_TAGVAR(always_export_symbols, $1)=no
+_LT_AC_TAGVAR(archive_expsym_cmds, $1)=
+_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_AC_TAGVAR(hardcode_direct, $1)=no
+_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_AC_TAGVAR(hardcode_minus_L, $1)=no
+_LT_AC_TAGVAR(hardcode_automatic, $1)=no
+_LT_AC_TAGVAR(module_cmds, $1)=
+_LT_AC_TAGVAR(module_expsym_cmds, $1)=
+_LT_AC_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_AC_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_AC_TAGVAR(no_undefined_flag, $1)=
+_LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for f77 test sources.
+ac_ext=f
+
+# Object file extension for compiled f77 test sources.
+objext=o
+_LT_AC_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="\
+      subroutine t
+      return
+      end
+"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code="\
+      program t
+      end
+"
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_AC_SYS_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+CC=${F77-"f77"}
+compiler=$CC
+_LT_AC_TAGVAR(compiler, $1)=$CC
+_LT_CC_BASENAME([$compiler])
+
+AC_MSG_CHECKING([if libtool supports shared libraries])
+AC_MSG_RESULT([$can_build_shared])
+
+AC_MSG_CHECKING([whether to build shared libraries])
+test "$can_build_shared" = "no" && enable_shared=no
+
+# On AIX, shared libraries and static libraries use the same namespace, and
+# are all built from PIC.
+case $host_os in
+aix3*)
+  test "$enable_shared" = yes && enable_static=no
+  if test -n "$RANLIB"; then
+    archive_cmds="$archive_cmds~\$RANLIB \$lib"
+    postinstall_cmds='$RANLIB $lib'
+  fi
+  ;;
+aix4* | aix5*)
+  if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+    test "$enable_shared" = yes && enable_static=no
+  fi
+  ;;
+esac
+AC_MSG_RESULT([$enable_shared])
+
+AC_MSG_CHECKING([whether to build static libraries])
+# Make sure either enable_shared or enable_static is yes.
+test "$enable_shared" = yes || enable_static=yes
+AC_MSG_RESULT([$enable_static])
+
+_LT_AC_TAGVAR(GCC, $1)="$G77"
+_LT_AC_TAGVAR(LD, $1)="$LD"
+
+AC_LIBTOOL_PROG_COMPILER_PIC($1)
+AC_LIBTOOL_PROG_CC_C_O($1)
+AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1)
+AC_LIBTOOL_PROG_LD_SHLIBS($1)
+AC_LIBTOOL_SYS_DYNAMIC_LINKER($1)
+AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1)
+
+AC_LIBTOOL_CONFIG($1)
+
+AC_LANG_POP
+CC="$lt_save_CC"
+])# AC_LIBTOOL_LANG_F77_CONFIG
+
+
+# AC_LIBTOOL_LANG_GCJ_CONFIG
+# --------------------------
+# Ensure that the configuration vars for the C compiler are
+# suitably defined.  Those variables are subsequently used by
+# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
+AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG], [_LT_AC_LANG_GCJ_CONFIG(GCJ)])
+AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG],
+[AC_LANG_SAVE
+
+# Source file extension for Java test sources.
+ac_ext=java
+
+# Object file extension for compiled Java test sources.
+objext=o
+_LT_AC_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="class foo {}"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }'
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_AC_SYS_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+CC=${GCJ-"gcj"}
+compiler=$CC
+_LT_AC_TAGVAR(compiler, $1)=$CC
+_LT_CC_BASENAME([$compiler])
+
+# GCJ did not exist at the time GCC didn't implicitly link libc in.
+_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
+
+_LT_AC_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+
+AC_LIBTOOL_PROG_COMPILER_NO_RTTI($1)
+AC_LIBTOOL_PROG_COMPILER_PIC($1)
+AC_LIBTOOL_PROG_CC_C_O($1)
+AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1)
+AC_LIBTOOL_PROG_LD_SHLIBS($1)
+AC_LIBTOOL_SYS_DYNAMIC_LINKER($1)
+AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1)
+
+AC_LIBTOOL_CONFIG($1)
+
+AC_LANG_RESTORE
+CC="$lt_save_CC"
+])# AC_LIBTOOL_LANG_GCJ_CONFIG
+
+
+# AC_LIBTOOL_LANG_RC_CONFIG
+# -------------------------
+# Ensure that the configuration vars for the Windows resource compiler are
+# suitably defined.  Those variables are subsequently used by
+# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
+AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG], [_LT_AC_LANG_RC_CONFIG(RC)])
+AC_DEFUN([_LT_AC_LANG_RC_CONFIG],
+[AC_LANG_SAVE
+
+# Source file extension for RC test sources.
+ac_ext=rc
+
+# Object file extension for compiled RC test sources.
+objext=o
+_LT_AC_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }'
+
+# Code to be used in simple link tests
+lt_simple_link_test_code="$lt_simple_compile_test_code"
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_AC_SYS_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+CC=${RC-"windres"}
+compiler=$CC
+_LT_AC_TAGVAR(compiler, $1)=$CC
+_LT_CC_BASENAME([$compiler])
+_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
+
+AC_LIBTOOL_CONFIG($1)
+
+AC_LANG_RESTORE
+CC="$lt_save_CC"
+])# AC_LIBTOOL_LANG_RC_CONFIG
+
+
+# AC_LIBTOOL_CONFIG([TAGNAME])
+# ----------------------------
+# If TAGNAME is not passed, then create an initial libtool script
+# with a default configuration from the untagged config vars.  Otherwise
+# add code to config.status for appending the configuration named by
+# TAGNAME from the matching tagged config vars.
+AC_DEFUN([AC_LIBTOOL_CONFIG],
+[# The else clause should only fire when bootstrapping the
+# libtool distribution, otherwise you forgot to ship ltmain.sh
+# with your package, and you will get complaints that there are
+# no rules to generate ltmain.sh.
+if test -f "$ltmain"; then
+  # See if we are running on zsh, and set the options which allow our commands through
+  # without removal of \ escapes.
+  if test -n "${ZSH_VERSION+set}" ; then
+    setopt NO_GLOB_SUBST
+  fi
+  # Now quote all the things that may contain metacharacters while being
+  # careful not to overquote the AC_SUBSTed values.  We take copies of the
+  # variables and quote the copies for generation of the libtool script.
+  for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC LTCFLAGS NM \
+    SED SHELL STRIP \
+    libname_spec library_names_spec soname_spec extract_expsyms_cmds \
+    old_striplib striplib file_magic_cmd finish_cmds finish_eval \
+    deplibs_check_method reload_flag reload_cmds need_locks \
+    lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \
+    lt_cv_sys_global_symbol_to_c_name_address \
+    sys_lib_search_path_spec sys_lib_dlsearch_path_spec \
+    old_postinstall_cmds old_postuninstall_cmds \
+    _LT_AC_TAGVAR(compiler, $1) \
+    _LT_AC_TAGVAR(CC, $1) \
+    _LT_AC_TAGVAR(LD, $1) \
+    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1) \
+    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1) \
+    _LT_AC_TAGVAR(lt_prog_compiler_static, $1) \
+    _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) \
+    _LT_AC_TAGVAR(export_dynamic_flag_spec, $1) \
+    _LT_AC_TAGVAR(thread_safe_flag_spec, $1) \
+    _LT_AC_TAGVAR(whole_archive_flag_spec, $1) \
+    _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1) \
+    _LT_AC_TAGVAR(old_archive_cmds, $1) \
+    _LT_AC_TAGVAR(old_archive_from_new_cmds, $1) \
+    _LT_AC_TAGVAR(predep_objects, $1) \
+    _LT_AC_TAGVAR(postdep_objects, $1) \
+    _LT_AC_TAGVAR(predeps, $1) \
+    _LT_AC_TAGVAR(postdeps, $1) \
+    _LT_AC_TAGVAR(compiler_lib_search_path, $1) \
+    _LT_AC_TAGVAR(archive_cmds, $1) \
+    _LT_AC_TAGVAR(archive_expsym_cmds, $1) \
+    _LT_AC_TAGVAR(postinstall_cmds, $1) \
+    _LT_AC_TAGVAR(postuninstall_cmds, $1) \
+    _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1) \
+    _LT_AC_TAGVAR(allow_undefined_flag, $1) \
+    _LT_AC_TAGVAR(no_undefined_flag, $1) \
+    _LT_AC_TAGVAR(export_symbols_cmds, $1) \
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) \
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1) \
+    _LT_AC_TAGVAR(hardcode_libdir_separator, $1) \
+    _LT_AC_TAGVAR(hardcode_automatic, $1) \
+    _LT_AC_TAGVAR(module_cmds, $1) \
+    _LT_AC_TAGVAR(module_expsym_cmds, $1) \
+    _LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1) \
+    _LT_AC_TAGVAR(fix_srcfile_path, $1) \
+    _LT_AC_TAGVAR(exclude_expsyms, $1) \
+    _LT_AC_TAGVAR(include_expsyms, $1); do
+
+    case $var in
+    _LT_AC_TAGVAR(old_archive_cmds, $1) | \
+    _LT_AC_TAGVAR(old_archive_from_new_cmds, $1) | \
+    _LT_AC_TAGVAR(archive_cmds, $1) | \
+    _LT_AC_TAGVAR(archive_expsym_cmds, $1) | \
+    _LT_AC_TAGVAR(module_cmds, $1) | \
+    _LT_AC_TAGVAR(module_expsym_cmds, $1) | \
+    _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1) | \
+    _LT_AC_TAGVAR(export_symbols_cmds, $1) | \
+    extract_expsyms_cmds | reload_cmds | finish_cmds | \
+    postinstall_cmds | postuninstall_cmds | \
+    old_postinstall_cmds | old_postuninstall_cmds | \
+    sys_lib_search_path_spec | sys_lib_dlsearch_path_spec)
+      # Double-quote double-evaled strings.
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\""
+      ;;
+    *)
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\""
+      ;;
+    esac
+  done
+
+  case $lt_echo in
+  *'\[$]0 --fallback-echo"')
+    lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\[$]0 --fallback-echo"[$]/[$]0 --fallback-echo"/'`
+    ;;
+  esac
+
+ifelse([$1], [],
+  [cfgfile="${ofile}T"
+  trap "$rm \"$cfgfile\"; exit 1" 1 2 15
+  $rm -f "$cfgfile"
+  AC_MSG_NOTICE([creating $ofile])],
+  [cfgfile="$ofile"])
+
+  cat <<__EOF__ >> "$cfgfile"
+ifelse([$1], [],
+[#! $SHELL
+
+# `$echo "$cfgfile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
+# Generated automatically by $PROGRAM (GNU $PACKAGE $VERSION$TIMESTAMP)
+# NOTE: Changes made to this file will be lost: look at ltmain.sh.
+#
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+# Free Software Foundation, Inc.
+#
+# This file is part of GNU Libtool:
+# Originally by Gordon Matzigkeit <gord at gnu.ai.mit.edu>, 1996
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# A sed program that does not truncate output.
+SED=$lt_SED
+
+# Sed that helps us avoid accidentally triggering echo(1) options like -n.
+Xsed="$SED -e 1s/^X//"
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+# The names of the tagged configurations supported by this script.
+available_tags=
+
+# ### BEGIN LIBTOOL CONFIG],
+[# ### BEGIN LIBTOOL TAG CONFIG: $tagname])
+
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+
+# Shell to use when invoking shell scripts.
+SHELL=$lt_SHELL
+
+# Whether or not to build shared libraries.
+build_libtool_libs=$enable_shared
+
+# Whether or not to build static libraries.
+build_old_libs=$enable_static
+
+# Whether or not to add -lc for building shared libraries.
+build_libtool_need_lc=$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)
+
+# Whether or not to disallow shared libs when runtime libs are static
+allow_libtool_libs_with_static_runtimes=$_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)
+
+# Whether or not to optimize for fast installation.
+fast_install=$enable_fast_install
+
+# The host system.
+host_alias=$host_alias
+host=$host
+host_os=$host_os
+
+# The build system.
+build_alias=$build_alias
+build=$build
+build_os=$build_os
+
+# An echo program that does not interpret backslashes.
+echo=$lt_echo
+
+# The archiver.
+AR=$lt_AR
+AR_FLAGS=$lt_AR_FLAGS
+
+# A C compiler.
+LTCC=$lt_LTCC
+
+# LTCC compiler flags.
+LTCFLAGS=$lt_LTCFLAGS
+
+# A language-specific compiler.
+CC=$lt_[]_LT_AC_TAGVAR(compiler, $1)
+
+# Is the compiler the GNU C compiler?
+with_gcc=$_LT_AC_TAGVAR(GCC, $1)
+
+# An ERE matcher.
+EGREP=$lt_EGREP
+
+# The linker used to build libraries.
+LD=$lt_[]_LT_AC_TAGVAR(LD, $1)
+
+# Whether we need hard or soft links.
+LN_S=$lt_LN_S
+
+# A BSD-compatible nm program.
+NM=$lt_NM
+
+# A symbol stripping program
+STRIP=$lt_STRIP
+
+# Used to examine libraries when file_magic_cmd begins "file"
+MAGIC_CMD=$MAGIC_CMD
+
+# Used on cygwin: DLL creation program.
+DLLTOOL="$DLLTOOL"
+
+# Used on cygwin: object dumper.
+OBJDUMP="$OBJDUMP"
+
+# Used on cygwin: assembler.
+AS="$AS"
+
+# The name of the directory that contains temporary libtool files.
+objdir=$objdir
+
+# How to create reloadable object files.
+reload_flag=$lt_reload_flag
+reload_cmds=$lt_reload_cmds
+
+# How to pass a linker flag through the compiler.
+wl=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)
+
+# Object file suffix (normally "o").
+objext="$ac_objext"
+
+# Old archive suffix (normally "a").
+libext="$libext"
+
+# Shared library suffix (normally ".so").
+shrext_cmds='$shrext_cmds'
+
+# Executable file suffix (normally "").
+exeext="$exeext"
+
+# Additional compiler flags for building library objects.
+pic_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)
+pic_mode=$pic_mode
+
+# What is the maximum length of a command?
+max_cmd_len=$lt_cv_sys_max_cmd_len
+
+# Does compiler simultaneously support -c and -o options?
+compiler_c_o=$lt_[]_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)
+
+# Must we lock files when doing compilation?
+need_locks=$lt_need_locks
+
+# Do we need the lib prefix for modules?
+need_lib_prefix=$need_lib_prefix
+
+# Do we need a version for libraries?
+need_version=$need_version
+
+# Whether dlopen is supported.
+dlopen_support=$enable_dlopen
+
+# Whether dlopen of programs is supported.
+dlopen_self=$enable_dlopen_self
+
+# Whether dlopen of statically linked programs is supported.
+dlopen_self_static=$enable_dlopen_self_static
+
+# Compiler flag to prevent dynamic linking.
+link_static_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_static, $1)
+
+# Compiler flag to turn off builtin functions.
+no_builtin_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)
+
+# Compiler flag to allow reflexive dlopens.
+export_dynamic_flag_spec=$lt_[]_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)
+
+# Compiler flag to generate shared objects directly from archives.
+whole_archive_flag_spec=$lt_[]_LT_AC_TAGVAR(whole_archive_flag_spec, $1)
+
+# Compiler flag to generate thread-safe objects.
+thread_safe_flag_spec=$lt_[]_LT_AC_TAGVAR(thread_safe_flag_spec, $1)
+
+# Library versioning type.
+version_type=$version_type
+
+# Format of library name prefix.
+libname_spec=$lt_libname_spec
+
+# List of archive names.  First name is the real one, the rest are links.
+# The last name is the one that the linker finds with -lNAME.
+library_names_spec=$lt_library_names_spec
+
+# The coded name of the library, if different from the real name.
+soname_spec=$lt_soname_spec
+
+# Commands used to build and install an old-style archive.
+RANLIB=$lt_RANLIB
+old_archive_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_cmds, $1)
+old_postinstall_cmds=$lt_old_postinstall_cmds
+old_postuninstall_cmds=$lt_old_postuninstall_cmds
+
+# Create an old-style archive from a shared archive.
+old_archive_from_new_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_from_new_cmds, $1)
+
+# Create a temporary old-style archive to link instead of a shared archive.
+old_archive_from_expsyms_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1)
+
+# Commands used to build and install a shared archive.
+archive_cmds=$lt_[]_LT_AC_TAGVAR(archive_cmds, $1)
+archive_expsym_cmds=$lt_[]_LT_AC_TAGVAR(archive_expsym_cmds, $1)
+postinstall_cmds=$lt_postinstall_cmds
+postuninstall_cmds=$lt_postuninstall_cmds
+
+# Commands used to build a loadable module (assumed same as above if empty)
+module_cmds=$lt_[]_LT_AC_TAGVAR(module_cmds, $1)
+module_expsym_cmds=$lt_[]_LT_AC_TAGVAR(module_expsym_cmds, $1)
+
+# Commands to strip libraries.
+old_striplib=$lt_old_striplib
+striplib=$lt_striplib
+
+# Dependencies to place before the objects being linked to create a
+# shared library.
+predep_objects=$lt_[]_LT_AC_TAGVAR(predep_objects, $1)
+
+# Dependencies to place after the objects being linked to create a
+# shared library.
+postdep_objects=$lt_[]_LT_AC_TAGVAR(postdep_objects, $1)
+
+# Dependencies to place before the objects being linked to create a
+# shared library.
+predeps=$lt_[]_LT_AC_TAGVAR(predeps, $1)
+
+# Dependencies to place after the objects being linked to create a
+# shared library.
+postdeps=$lt_[]_LT_AC_TAGVAR(postdeps, $1)
+
+# The library search path used internally by the compiler when linking
+# a shared library.
+compiler_lib_search_path=$lt_[]_LT_AC_TAGVAR(compiler_lib_search_path, $1)
+
+# Method to check whether dependent libraries are shared objects.
+deplibs_check_method=$lt_deplibs_check_method
+
+# Command to use when deplibs_check_method == file_magic.
+file_magic_cmd=$lt_file_magic_cmd
+
+# Flag that allows shared libraries with undefined symbols to be built.
+allow_undefined_flag=$lt_[]_LT_AC_TAGVAR(allow_undefined_flag, $1)
+
+# Flag that forces no undefined symbols.
+no_undefined_flag=$lt_[]_LT_AC_TAGVAR(no_undefined_flag, $1)
+
+# Commands used to finish a libtool library installation in a directory.
+finish_cmds=$lt_finish_cmds
+
+# Same as above, but a single script fragment to be evaled but not shown.
+finish_eval=$lt_finish_eval
+
+# Take the output of nm and produce a listing of raw symbols and C names.
+global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe
+
+# Transform the output of nm in a proper C declaration
+global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl
+
+# Transform the output of nm in a C name address pair
+global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address
+
+# This is the shared library runtime path variable.
+runpath_var=$runpath_var
+
+# This is the shared library path variable.
+shlibpath_var=$shlibpath_var
+
+# Is shlibpath searched before the hard-coded library search path?
+shlibpath_overrides_runpath=$shlibpath_overrides_runpath
+
+# How to hardcode a shared library path into an executable.
+hardcode_action=$_LT_AC_TAGVAR(hardcode_action, $1)
+
+# Whether we should hardcode library paths into libraries.
+hardcode_into_libs=$hardcode_into_libs
+
+# Flag to hardcode \$libdir into a binary during linking.
+# This must work even if \$libdir does not exist.
+hardcode_libdir_flag_spec=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)
+
+# If ld is used when linking, flag to hardcode \$libdir into
+# a binary during linking. This must work even if \$libdir does
+# not exist.
+hardcode_libdir_flag_spec_ld=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)
+
+# Whether we need a single -rpath flag with a separated argument.
+hardcode_libdir_separator=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_separator, $1)
+
+# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the
+# resulting binary.
+hardcode_direct=$_LT_AC_TAGVAR(hardcode_direct, $1)
+
+# Set to yes if using the -LDIR flag during linking hardcodes DIR into the
+# resulting binary.
+hardcode_minus_L=$_LT_AC_TAGVAR(hardcode_minus_L, $1)
+
+# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into
+# the resulting binary.
+hardcode_shlibpath_var=$_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)
+
+# Set to yes if building a shared library automatically hardcodes DIR into the library
+# and all subsequent libraries and executables linked against it.
+hardcode_automatic=$_LT_AC_TAGVAR(hardcode_automatic, $1)
+
+# Variables whose values should be saved in libtool wrapper scripts and
+# restored at relink time.
+variables_saved_for_relink="$variables_saved_for_relink"
+
+# Whether libtool must link a program against all its dependency libraries.
+link_all_deplibs=$_LT_AC_TAGVAR(link_all_deplibs, $1)
+
+# Compile-time system search path for libraries
+sys_lib_search_path_spec=$lt_sys_lib_search_path_spec
+
+# Run-time system search path for libraries
+sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec
+
+# Fix the shell variable \$srcfile for the compiler.
+fix_srcfile_path=$lt_fix_srcfile_path
+
+# Set to yes if exported symbols are required.
+always_export_symbols=$_LT_AC_TAGVAR(always_export_symbols, $1)
+
+# The commands to list exported symbols.
+export_symbols_cmds=$lt_[]_LT_AC_TAGVAR(export_symbols_cmds, $1)
+
+# The commands to extract the exported symbol list from a shared archive.
+extract_expsyms_cmds=$lt_extract_expsyms_cmds
+
+# Symbols that should not be listed in the preloaded symbols.
+exclude_expsyms=$lt_[]_LT_AC_TAGVAR(exclude_expsyms, $1)
+
+# Symbols that must always be exported.
+include_expsyms=$lt_[]_LT_AC_TAGVAR(include_expsyms, $1)
+
+ifelse([$1],[],
+[# ### END LIBTOOL CONFIG],
+[# ### END LIBTOOL TAG CONFIG: $tagname])
+
+__EOF__
+
+ifelse([$1],[], [
+  case $host_os in
+  aix3*)
+    cat <<\EOF >> "$cfgfile"
+
+# AIX sometimes has problems with the GCC collect2 program.  For some
+# reason, if we set the COLLECT_NAMES environment variable, the problems
+# vanish in a puff of smoke.
+if test "X${COLLECT_NAMES+set}" != Xset; then
+  COLLECT_NAMES=
+  export COLLECT_NAMES
+fi
+EOF
+    ;;
+  esac
+
+  # We use sed instead of cat because bash on DJGPP gets confused if
+  # if finds mixed CR/LF and LF-only lines.  Since sed operates in
+  # text mode, it properly converts lines to CR/LF.  This bash problem
+  # is reportedly fixed, but why not run on old versions too?
+  sed '$q' "$ltmain" >> "$cfgfile" || (rm -f "$cfgfile"; exit 1)
+
+  mv -f "$cfgfile" "$ofile" || \
+    (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
+  chmod +x "$ofile"
+])
+else
+  # If there is no Makefile yet, we rely on a make rule to execute
+  # `config.status --recheck' to rerun these tests and create the
+  # libtool script then.
+  ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'`
+  if test -f "$ltmain_in"; then
+    test -f Makefile && make "$ltmain"
+  fi
+fi
+])# AC_LIBTOOL_CONFIG
+
+
+# AC_LIBTOOL_PROG_COMPILER_NO_RTTI([TAGNAME])
+# -------------------------------------------
+AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI],
+[AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl
+
+_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
+
+if test "$GCC" = yes; then
+  _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
+
+  AC_LIBTOOL_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions],
+    lt_cv_prog_compiler_rtti_exceptions,
+    [-fno-rtti -fno-exceptions], [],
+    [_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"])
+fi
+])# AC_LIBTOOL_PROG_COMPILER_NO_RTTI
+
+
+# AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE
+# ---------------------------------
+AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE],
+[AC_REQUIRE([AC_CANONICAL_HOST])
+AC_REQUIRE([LT_AC_PROG_SED])
+AC_REQUIRE([AC_PROG_NM])
+AC_REQUIRE([AC_OBJEXT])
+# Check for command to grab the raw symbol name followed by C symbol from nm.
+AC_MSG_CHECKING([command to parse $NM output from $compiler object])
+AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe],
 [
-AC_CHECK_HEADER([sys/mman.h],
-		[libffi_header_sys_mman_h=yes], [libffi_header_sys_mman_h=no])
-AC_CHECK_FUNC([mmap], [libffi_func_mmap=yes], [libffi_func_mmap=no])
-if test "$libffi_header_sys_mman_h" != yes \
- || test "$libffi_func_mmap" != yes; then
-   ac_cv_func_mmap_file=no
-   ac_cv_func_mmap_dev_zero=no
-   ac_cv_func_mmap_anon=no
-else
-   AC_CACHE_CHECK([whether read-only mmap of a plain file works],
-  ac_cv_func_mmap_file,
-  [# Add a system to this blacklist if
-   # mmap(0, stat_size, PROT_READ, MAP_PRIVATE, fd, 0) doesn't return a
-   # memory area containing the same data that you'd get if you applied
-   # read() to the same fd.  The only system known to have a problem here
-   # is VMS, where text files have record structure.
-   case "$host_os" in
-     vms* | ultrix*)
-	ac_cv_func_mmap_file=no ;;
-     *)
-	ac_cv_func_mmap_file=yes;;
-   esac])
-   AC_CACHE_CHECK([whether mmap from /dev/zero works],
-  ac_cv_func_mmap_dev_zero,
-  [# Add a system to this blacklist if it has mmap() but /dev/zero
-   # does not exist, or if mmapping /dev/zero does not give anonymous
-   # zeroed pages with both the following properties:
-   # 1. If you map N consecutive pages in with one call, and then
-   #    unmap any subset of those pages, the pages that were not
-   #    explicitly unmapped remain accessible.
-   # 2. If you map two adjacent blocks of memory and then unmap them
-   #    both at once, they must both go away.
-   # Systems known to be in this category are Windows (all variants),
-   # VMS, and Darwin.
-   case "$host_os" in
-     vms* | cygwin* | pe | mingw* | darwin* | ultrix* | hpux10* | hpux11.00)
-	ac_cv_func_mmap_dev_zero=no ;;
-     *)
-	ac_cv_func_mmap_dev_zero=yes;;
-   esac])
-
-   # Unlike /dev/zero, the MAP_ANON(YMOUS) defines can be probed for.
-   AC_CACHE_CHECK([for MAP_ANON(YMOUS)], ac_cv_decl_map_anon,
-    [AC_TRY_COMPILE(
-[#include <sys/types.h>
-#include <sys/mman.h>
-#include <unistd.h>
+# These are sane defaults that work on at least a few old systems.
+# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
+
+# Character class describing NM global symbol codes.
+symcode='[[BCDEGRST]]'
+
+# Regexp to match symbols that can be accessed directly from C.
+sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)'
+
+# Transform an extracted symbol line into a proper C declaration
+lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^. .* \(.*\)$/extern int \1;/p'"
+
+# Transform an extracted symbol line into symbol name and symbol address
+lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode \([[^ ]]*\) \([[^ ]]*\)$/  {\"\2\", (lt_ptr) \&\2},/p'"
+
+# Define system-specific variables.
+case $host_os in
+aix*)
+  symcode='[[BCDT]]'
+  ;;
+cygwin* | mingw* | pw32*)
+  symcode='[[ABCDGISTW]]'
+  ;;
+hpux*) # Its linker distinguishes data from code symbols
+  if test "$host_cpu" = ia64; then
+    symcode='[[ABCDEGRST]]'
+  fi
+  lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+  lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"\2\", (lt_ptr) \&\2},/p'"
+  ;;
+linux* | k*bsd*-gnu)
+  if test "$host_cpu" = ia64; then
+    symcode='[[ABCDGIRSTW]]'
+    lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+    lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"\2\", (lt_ptr) \&\2},/p'"
+  fi
+  ;;
+irix* | nonstopux*)
+  symcode='[[BCDEGRST]]'
+  ;;
+osf*)
+  symcode='[[BCDEGQRST]]'
+  ;;
+solaris*)
+  symcode='[[BDRT]]'
+  ;;
+sco3.2v5*)
+  symcode='[[DT]]'
+  ;;
+sysv4.2uw2*)
+  symcode='[[DT]]'
+  ;;
+sysv5* | sco5v6* | unixware* | OpenUNIX*)
+  symcode='[[ABDT]]'
+  ;;
+sysv4)
+  symcode='[[DFNSTU]]'
+  ;;
+esac
+
+# Handle CRLF in mingw tool chain
+opt_cr=
+case $build_os in
+mingw*)
+  opt_cr=`echo 'x\{0,1\}' | tr x '\015'` # option cr in regexp
+  ;;
+esac
+
+# If we're using GNU nm, then use its standard symbol codes.
+case `$NM -V 2>&1` in
+*GNU* | *'with BFD'*)
+  symcode='[[ABCDGIRSTW]]' ;;
+esac
+
+# Try without a prefix undercore, then with it.
+for ac_symprfx in "" "_"; do
+
+  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
+  symxfrm="\\1 $ac_symprfx\\2 \\2"
+
+  # Write the raw and C identifiers.
+  lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ 	]]\($symcode$symcode*\)[[ 	]][[ 	]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
+
+  # Check to see that the pipe works correctly.
+  pipe_works=no
+
+  rm -f conftest*
+  cat > conftest.$ac_ext <<EOF
+#ifdef __cplusplus
+extern "C" {
+#endif
+char nm_test_var;
+void nm_test_func(){}
+#ifdef __cplusplus
+}
+#endif
+int main(){nm_test_var='a';nm_test_func();return(0);}
+EOF
+
+  if AC_TRY_EVAL(ac_compile); then
+    # Now try to grab the symbols.
+    nlist=conftest.nm
+    if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) && test -s "$nlist"; then
+      # Try sorting and uniquifying the output.
+      if sort "$nlist" | uniq > "$nlist"T; then
+	mv -f "$nlist"T "$nlist"
+      else
+	rm -f "$nlist"T
+      fi
+
+      # Make sure that we snagged all the symbols we need.
+      if grep ' nm_test_var$' "$nlist" >/dev/null; then
+	if grep ' nm_test_func$' "$nlist" >/dev/null; then
+	  cat <<EOF > conftest.$ac_ext
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+EOF
+	  # Now generate the symbol file.
+	  eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | grep -v main >> conftest.$ac_ext'
+
+	  cat <<EOF >> conftest.$ac_ext
+#if defined (__STDC__) && __STDC__
+# define lt_ptr_t void *
+#else
+# define lt_ptr_t char *
+# define const
+#endif
+
+/* The mapping between symbol names and symbols. */
+const struct {
+  const char *name;
+  lt_ptr_t address;
+}
+lt_preloaded_symbols[[]] =
+{
+EOF
+	  $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (lt_ptr_t) \&\2},/" < "$nlist" | grep -v main >> conftest.$ac_ext
+	  cat <<\EOF >> conftest.$ac_ext
+  {0, (lt_ptr_t) 0}
+};
+
+#ifdef __cplusplus
+}
+#endif
+EOF
+	  # Now try linking the two files.
+	  mv conftest.$ac_objext conftstm.$ac_objext
+	  lt_save_LIBS="$LIBS"
+	  lt_save_CFLAGS="$CFLAGS"
+	  LIBS="conftstm.$ac_objext"
+	  CFLAGS="$CFLAGS$_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)"
+	  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then
+	    pipe_works=yes
+	  fi
+	  LIBS="$lt_save_LIBS"
+	  CFLAGS="$lt_save_CFLAGS"
+	else
+	  echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD
+	fi
+      else
+	echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD
+      fi
+    else
+      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD
+    fi
+  else
+    echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD
+    cat conftest.$ac_ext >&5
+  fi
+  rm -f conftest* conftst*
+
+  # Do not use the global_symbol_pipe unless it works.
+  if test "$pipe_works" = yes; then
+    break
+  else
+    lt_cv_sys_global_symbol_pipe=
+  fi
+done
+])
+if test -z "$lt_cv_sys_global_symbol_pipe"; then
+  lt_cv_sys_global_symbol_to_cdecl=
+fi
+if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
+  AC_MSG_RESULT(failed)
+else
+  AC_MSG_RESULT(ok)
+fi
+]) # AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE
 
-#ifndef MAP_ANONYMOUS
-#define MAP_ANONYMOUS MAP_ANON
-#endif
+
+# AC_LIBTOOL_PROG_COMPILER_PIC([TAGNAME])
+# ---------------------------------------
+AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC],
+[_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)=
+_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
+_LT_AC_TAGVAR(lt_prog_compiler_static, $1)=
+
+AC_MSG_CHECKING([for $compiler option to produce PIC])
+ ifelse([$1],[CXX],[
+  # C++ specific cases for pic, static, wl, etc.
+  if test "$GXX" = yes; then
+    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
+
+    case $host_os in
+    aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+    amigaos*)
+      # FIXME: we need at least 68020 code to build shared libraries, but
+      # adding the `-m68020' flag to GCC prevents building anything better,
+      # like `-m68040'.
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
+      ;;
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+    mingw* | cygwin* | os2* | pw32*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'
+      ;;
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
+      ;;
+    *djgpp*)
+      # DJGPP does not support shared libraries at all
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
+      ;;
+    interix[[3-9]]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
+      fi
+      ;;
+    hpux*)
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	;;
+      *)
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	;;
+      esac
+      ;;
+    *)
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+      ;;
+    esac
+  else
+    case $host_os in
+      aix4* | aix5*)
+	# All AIX code is PIC.
+	if test "$host_cpu" = ia64; then
+	  # AIX 5 now supports IA64 processor
+	  _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	else
+	  _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+	fi
+	;;
+      chorus*)
+	case $cc_basename in
+	cxch68*)
+	  # Green Hills C++ Compiler
+	  # _LT_AC_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a"
+	  ;;
+	esac
+	;;
+       darwin*)
+         # PIC is the default on this platform
+         # Common symbols not allowed in MH_DYLIB files
+         case $cc_basename in
+           xlc*)
+           _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-qnocommon'
+           _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           ;;
+         esac
+       ;;
+      dgux*)
+	case $cc_basename in
+	  ec++*)
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    ;;
+	  ghcx*)
+	    # Green Hills C++ Compiler
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      freebsd* | dragonfly*)
+	# FreeBSD uses GNU C++
+	;;
+      hpux9* | hpux10* | hpux11*)
+	case $cc_basename in
+	  CC*)
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+	    if test "$host_cpu" != ia64; then
+	      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+	    fi
+	    ;;
+	  aCC*)
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+	    case $host_cpu in
+	    hppa*64*|ia64*)
+	      # +Z the default
+	      ;;
+	    *)
+	      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+	      ;;
+	    esac
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      interix*)
+	# This is c89, which is MS Visual C++ (no shared libs)
+	# Anyone wants to do a port?
+	;;
+      irix5* | irix6* | nonstopux*)
+	case $cc_basename in
+	  CC*)
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+	    # CC pic flag -KPIC is the default.
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      linux* | k*bsd*-gnu)
+	case $cc_basename in
+	  KCC*)
+	    # KAI C++ Compiler
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	    ;;
+	  icpc* | ecpc*)
+	    # Intel C++
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
+	    ;;
+	  pgCC*)
+	    # Portland Group C++ compiler.
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    ;;
+	  cxx*)
+	    # Compaq C++
+	    # Make sure the PIC flag is empty.  It appears that all Alpha
+	    # Linux and Compaq Tru64 Unix objects are PIC.
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+	    ;;
+	  *)
+	    case `$CC -V 2>&1 | sed 5q` in
+	    *Sun\ C*)
+	      # Sun C++ 5.9
+	      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+	      ;;
+	    esac
+	    ;;
+	esac
+	;;
+      lynxos*)
+	;;
+      m88k*)
+	;;
+      mvs*)
+	case $cc_basename in
+	  cxx*)
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      netbsd*)
+	;;
+      osf3* | osf4* | osf5*)
+	case $cc_basename in
+	  KCC*)
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
+	    ;;
+	  RCC*)
+	    # Rational C++ 2.4.1
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    ;;
+	  cxx*)
+	    # Digital/Compaq C++
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    # Make sure the PIC flag is empty.  It appears that all Alpha
+	    # Linux and Compaq Tru64 Unix objects are PIC.
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      psos*)
+	;;
+      solaris*)
+	case $cc_basename in
+	  CC*)
+	    # Sun C++ 4.2, 5.x and Centerline C++
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+	    ;;
+	  gcx*)
+	    # Green Hills C++ Compiler
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      sunos4*)
+	case $cc_basename in
+	  CC*)
+	    # Sun C++ 4.x
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    ;;
+	  lcc*)
+	    # Lucid
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      tandem*)
+	case $cc_basename in
+	  NCC*)
+	    # NonStop-UX NCC 3.20
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+	case $cc_basename in
+	  CC*)
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    ;;
+	esac
+	;;
+      vxworks*)
+	;;
+      *)
+	_LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+	;;
+    esac
+  fi
 ],
-[int n = MAP_ANONYMOUS;],
-    ac_cv_decl_map_anon=yes,
-    ac_cv_decl_map_anon=no)])
+[
+  if test "$GCC" = yes; then
+    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
 
-   if test $ac_cv_decl_map_anon = no; then
-     ac_cv_func_mmap_anon=no
-   else
-     AC_CACHE_CHECK([whether mmap with MAP_ANON(YMOUS) works],
-     ac_cv_func_mmap_anon,
-  [# Add a system to this blacklist if it has mmap() and MAP_ANON or
-   # MAP_ANONYMOUS, but using mmap(..., MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
-   # doesn't give anonymous zeroed pages with the same properties listed
-   # above for use of /dev/zero.
-   # Systems known to be in this category are Windows, VMS, and SCO Unix.
-   case "$host_os" in
-     vms* | cygwin* | pe | mingw* | sco* | udk* )
-	ac_cv_func_mmap_anon=no ;;
-     *)
-	ac_cv_func_mmap_anon=yes;;
-   esac])
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      # FIXME: we need at least 68020 code to build shared libraries, but
+      # adding the `-m68020' flag to GCC prevents building anything better,
+      # like `-m68040'.
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
+      ;;
+
+    interix[[3-9]]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      enable_shared=no
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
+      fi
+      ;;
+
+    hpux*)
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	;;
+      esac
+      ;;
+
+    *)
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      else
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+      darwin*)
+        # PIC is the default on this platform
+        # Common symbols not allowed in MH_DYLIB files
+       case $cc_basename in
+         xlc*)
+         _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-qnocommon'
+         _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+         ;;
+       esac
+       ;;
+
+    mingw* | cygwin* | pw32* | os2*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+	;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # PIC (with -KPIC) is the default.
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    newsos6)
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    linux* | k*bsd*-gnu)
+      case $cc_basename in
+      icc* | ecc*)
+	_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
+        ;;
+      pgcc* | pgf77* | pgf90* | pgf95*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+	# which looks to be a dead project)
+	_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+        ;;
+      ccc*)
+        _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+        # All Alpha code is PIC.
+        _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+        ;;
+      *)
+        case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)
+	  # Sun C 5.9
+	  _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	  _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	  _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	  ;;
+	*Sun\ F*)
+	  # Sun Fortran 8.3 passes all unrecognized flags to the linker
+	  _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	  _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	  _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)=''
+	  ;;
+	esac
+	;;
+      esac
+      ;;
+
+    osf3* | osf4* | osf5*)
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # All OSF/1 code is PIC.
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    rdos*)
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    solaris*)
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95*)
+	_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';;
+      *)
+	_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic'
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    unicos*)
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      ;;
+
+    uts4*)
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    *)
+      _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      ;;
+    esac
+  fi
+])
+AC_MSG_RESULT([$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)])
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)"; then
+  AC_LIBTOOL_COMPILER_OPTION([if $compiler PIC flag $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) works],
+    _LT_AC_TAGVAR(lt_prog_compiler_pic_works, $1),
+    [$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)ifelse([$1],[],[ -DPIC],[ifelse([$1],[CXX],[ -DPIC],[])])], [],
+    [case $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) in
+     "" | " "*) ;;
+     *) _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)" ;;
+     esac],
+    [_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
+     _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no])
+fi
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
+    ;;
+  *)
+    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)ifelse([$1],[],[ -DPIC],[ifelse([$1],[CXX],[ -DPIC],[])])"
+    ;;
+esac
+
+#
+# Check to make sure the static flag actually works.
+#
+wl=$_LT_AC_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_AC_TAGVAR(lt_prog_compiler_static, $1)\"
+AC_LIBTOOL_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works],
+  _LT_AC_TAGVAR(lt_prog_compiler_static_works, $1),
+  $lt_tmp_static_flag,
+  [],
+  [_LT_AC_TAGVAR(lt_prog_compiler_static, $1)=])
+])
+
+
+# AC_LIBTOOL_PROG_LD_SHLIBS([TAGNAME])
+# ------------------------------------
+# See if the linker supports building shared libraries.
+AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS],
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
+AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
+ifelse([$1],[CXX],[
+  _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  case $host_os in
+  aix4* | aix5*)
+    # If we're using GNU nm, then we don't want the "-C" option.
+    # -C means demangle to AIX nm, but means don't demangle with GNU nm
+    if $NM -V 2>&1 | grep 'GNU' > /dev/null; then
+      _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols'
+    else
+      _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols'
+    fi
+    ;;
+  pw32*)
+    _LT_AC_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds"
+  ;;
+  cygwin* | mingw*)
+    _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols'
+  ;;
+  *)
+    _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  ;;
+  esac
+],[
+  runpath_var=
+  _LT_AC_TAGVAR(allow_undefined_flag, $1)=
+  _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+  _LT_AC_TAGVAR(archive_cmds, $1)=
+  _LT_AC_TAGVAR(archive_expsym_cmds, $1)=
+  _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)=
+  _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1)=
+  _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
+  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
+  _LT_AC_TAGVAR(thread_safe_flag_spec, $1)=
+  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
+  _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+  _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
+  _LT_AC_TAGVAR(hardcode_direct, $1)=no
+  _LT_AC_TAGVAR(hardcode_minus_L, $1)=no
+  _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+  _LT_AC_TAGVAR(link_all_deplibs, $1)=unknown
+  _LT_AC_TAGVAR(hardcode_automatic, $1)=no
+  _LT_AC_TAGVAR(module_cmds, $1)=
+  _LT_AC_TAGVAR(module_expsym_cmds, $1)=
+  _LT_AC_TAGVAR(always_export_symbols, $1)=no
+  _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  _LT_AC_TAGVAR(include_expsyms, $1)=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  _LT_AC_TAGVAR(exclude_expsyms, $1)="_GLOBAL_OFFSET_TABLE_"
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  extract_expsyms_cmds=
+  # Just being paranoid about ensuring that cc_basename is set.
+  _LT_CC_BASENAME([$compiler])
+  case $host_os in
+  cygwin* | mingw* | pw32*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  esac
+
+  _LT_AC_TAGVAR(ld_shlibs, $1)=yes
+  if test "$with_gnu_ld" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
+    _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | grep 'no-whole-archive' > /dev/null; then
+	_LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+      else
+  	_LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>/dev/null` in
+      *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix3* | aix4* | aix5*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	cat <<EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.9.1, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to modify your PATH
+*** so that a non-GNU linker is found, and then restart.
+
+EOF
+      fi
+      ;;
+
+    amigaos*)
+      _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
+
+      # Samuel A. Falvo II <kc5tja at dolphin.openprojects.net> reports
+      # that the semantics of dynamic libraries on AmigaOS, at least up
+      # to version 4, is to share data among multiple programs linked
+      # with the same dynamic library.  Since this doesn't match the
+      # behavior of shared libraries on other platforms, we can't use
+      # them.
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
+	# Joseph Beckenbach <jrb3 at best.com> says some releases of gcc
+	# support --undefined.  This deserves some investigation.  FIXME
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32*)
+      # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
+      # as there is no search path for DLLs.
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_AC_TAGVAR(always_export_symbols, $1)=no
+      _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+      _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/'\'' -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols'
+
+      if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
+        _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+	# If the export-symbols file already is a .def file (1st line
+	# is EXPORTS), use it as is; otherwise, prepend...
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	  cp $export_symbols $output_objdir/$soname.def;
+	else
+	  echo EXPORTS > $output_objdir/$soname.def;
+	  cat $export_symbols >> $output_objdir/$soname.def;
+	fi~
+	$CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    interix[[3-9]]*)
+      _LT_AC_TAGVAR(hardcode_direct, $1)=no
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+      _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | k*bsd*-gnu)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	tmp_addflag=
+	case $cc_basename,$host_cpu in
+	pgcc*)				# Portland Group C compiler
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag'
+	  ;;
+	pgf77* | pgf90* | pgf95*)	# Portland Group f77 and f90 compilers
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag -Mnomain' ;;
+	ecc*,ia64* | icc*,ia64*)		# Intel C compiler on ia64
+	  tmp_addflag=' -i_dynamic' ;;
+	efc*,ia64* | ifort*,ia64*)	# Intel Fortran compiler on ia64
+	  tmp_addflag=' -i_dynamic -nofor_main' ;;
+	ifc* | ifort*)			# Intel Fortran compiler
+	  tmp_addflag=' -nofor_main' ;;
+	esac
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)			# Sun C 5.9
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_sharedflag='-G' ;;
+	*Sun\ F*)			# Sun Fortran 8.3
+	  tmp_sharedflag='-G' ;;
+	*)
+	  tmp_sharedflag='-shared' ;;
+	esac
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+	if test $supports_anon_versioning = yes; then
+	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $output_objdir/$libname.ver~
+  cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+  $echo "local: *; };" >> $output_objdir/$libname.ver~
+	  $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+	fi
+      else
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+	wlarc=
+      else
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	cat <<EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+EOF
+      elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*)
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+	;;
+	*)
+	  if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`'
+	    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib'
+	    _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname,-retain-symbols-file,$export_symbols -o $lib'
+	  else
+	    _LT_AC_TAGVAR(ld_shlibs, $1)=no
+	  fi
+	;;
+      esac
+      ;;
+
+    sunos4*)
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+    esac
+
+    if test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no; then
+      runpath_var=
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
+      _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
+      _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_AC_TAGVAR(always_export_symbols, $1)=yes
+      _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+	# Neither direct hardcoding nor static linking is supported with a
+	# broken collect2.
+	_LT_AC_TAGVAR(hardcode_direct, $1)=unsupported
+      fi
+      ;;
+
+    aix4* | aix5*)
+      if test "$host_cpu" = ia64; then
+	# On IA64, the linker does run time linking by default, so we don't
+	# have to do anything special.
+	aix_use_runtimelinking=no
+	exp_sym_flag='-Bexport'
+	no_entry_flag=""
+      else
+	# If we're using GNU nm, then we don't want the "-C" option.
+	# -C means demangle to AIX nm, but means don't demangle with GNU nm
+	if $NM -V 2>&1 | grep 'GNU' > /dev/null; then
+	  _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols'
+	else
+	  _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols'
+	fi
+	aix_use_runtimelinking=no
+
+	# Test if we are trying to use run time linking or normal
+	# AIX style linking. If -brtl is somewhere in LDFLAGS, we
+	# need to do runtime linking.
+	case $host_os in aix4.[[23]]|aix4.[[23]].*|aix5*)
+	  for ld_flag in $LDFLAGS; do
+  	  if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+  	    aix_use_runtimelinking=yes
+  	    break
+  	  fi
+	  done
+	  ;;
+	esac
+
+	exp_sym_flag='-bexport'
+	no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      _LT_AC_TAGVAR(archive_cmds, $1)=''
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':'
+      _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
+
+      if test "$GCC" = yes; then
+	case $host_os in aix4.[[012]]|aix4.[[012]].*)
+	# We only want to do this on AIX 4.2 and lower, the check
+	# below for broken collect2 doesn't work under 4.3+
+	  collect2name=`${CC} -print-prog-name=collect2`
+	  if test -f "$collect2name" && \
+  	   strings "$collect2name" | grep resolve_lib_name >/dev/null
+	  then
+  	  # We have reworked collect2
+  	  :
+	  else
+  	  # We have old collect2
+  	  _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported
+  	  # It fails to find uninstalled libraries when the uninstalled
+  	  # path is not listed in the libpath.  Setting hardcode_minus_L
+  	  # to unsupported forces relinking
+  	  _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
+  	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+  	  _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
+	  fi
+	  ;;
+	esac
+	shared_flag='-shared'
+	if test "$aix_use_runtimelinking" = yes; then
+	  shared_flag="$shared_flag "'${wl}-G'
+	fi
+      else
+	# not using gcc
+	if test "$host_cpu" = ia64; then
+  	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+  	# chokes on -Wl,-G. The following line is correct:
+	  shared_flag='-G'
+	else
+	  if test "$aix_use_runtimelinking" = yes; then
+	    shared_flag='${wl}-G'
+	  else
+	    shared_flag='${wl}-bM:SRE'
+	  fi
+	fi
+      fi
+
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      _LT_AC_TAGVAR(always_export_symbols, $1)=yes
+      if test "$aix_use_runtimelinking" = yes; then
+	# Warning - without using the other runtime loading flags (-brtl),
+	# -berok will link without error, but may produce a broken library.
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)='-berok'
+       # Determine the default libpath from the value encoded in an empty executable.
+       _LT_AC_SYS_LIBPATH_AIX
+       _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+       else
+	if test "$host_cpu" = ia64; then
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
+	  _LT_AC_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
+	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+	else
+	 # Determine the default libpath from the value encoded in an empty executable.
+	 _LT_AC_SYS_LIBPATH_AIX
+	 _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+	  # Warning - without using the other run time loading flags,
+	  # -berok will link without error, but may produce a broken library.
+	  _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
+	  _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
+	  # Exported symbols can be pulled into shared objects from archives
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
+	  _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes
+	  # This is similar to how AIX traditionally builds its shared libraries.
+	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+	fi
+      fi
+      ;;
+
+    amigaos*)
+      _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
+      # see comment about different semantics on the GNU ld section
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
+      ;;
+
+    bsdi[[45]]*)
+      _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
+      # Tell ltmain to make .lib files, not .a files.
+      libext=lib
+      # Tell ltmain to make .dll files, not .so files.
+      shrext_cmds=".dll"
+      # FIXME: Setting linknames here is a bad hack.
+      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | $SED -e '\''s/ -lc$//'\''` -link -dll~linknames='
+      # The linker will automatically build a .lib file if we build a DLL.
+      _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)='true'
+      # FIXME: Should let the user specify the lib program.
+      _LT_AC_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs'
+      _LT_AC_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`'
+      _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+      ;;
+
+    darwin* | rhapsody*)
+      case $host_os in
+        rhapsody* | darwin1.[[012]])
+         _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}suppress'
+         ;;
+       *) # Darwin 1.3 on
+         if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then
+           _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+         else
+           case ${MACOSX_DEPLOYMENT_TARGET} in
+             10.[[012]])
+               _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+               ;;
+             10.*)
+               _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}dynamic_lookup'
+               ;;
+           esac
+         fi
+         ;;
+      esac
+      _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_AC_TAGVAR(hardcode_direct, $1)=no
+      _LT_AC_TAGVAR(hardcode_automatic, $1)=yes
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+      _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=''
+      _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
+    if test "$GCC" = yes ; then
+    	output_verbose_link_cmd='echo'
+        _LT_AC_TAGVAR(archive_cmds, $1)='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring'
+      _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
+      # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
+      _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+      _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    else
+      case $cc_basename in
+        xlc*)
+         output_verbose_link_cmd='echo'
+         _LT_AC_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $xlcverstring'
+         _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
+          # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
+         _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $xlcverstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          ;;
+       *)
+         _LT_AC_TAGVAR(ld_shlibs, $1)=no
+          ;;
+      esac
+    fi
+      ;;
+
+    dgux*)
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    freebsd1*)
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2*)
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+	_LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+	_LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	_LT_AC_TAGVAR(hardcode_direct, $1)=yes
+	_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+
+	# hardcode_minus_L: Not really in the search PATH,
+	# but as the default location of the library.
+	_LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	case $host_cpu in
+	hppa*64*)
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      else
+	case $host_cpu in
+	hppa*64*)
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      fi
+      if test "$with_gnu_ld" = no; then
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	case $host_cpu in
+	hppa*64*|ia64*)
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir'
+	  _LT_AC_TAGVAR(hardcode_direct, $1)=no
+	  _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+	  ;;
+	*)
+	  _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+	  _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+
+	  # hardcode_minus_L: Not really in the search PATH,
+	  # but as the default location of the library.
+	  _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
+	  ;;
+	esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir'
+      fi
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    newsos6)
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+	_LT_AC_TAGVAR(hardcode_direct, $1)=yes
+	_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+	if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	  _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	else
+	  case $host_os in
+	   openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*)
+	     _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+	     _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	     ;;
+	   *)
+	     _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	     _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	     ;;
+	  esac
+        fi
+      else
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    os2*)
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_AC_TAGVAR(archive_cmds, $1)='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+      ;;
+
+    osf4* | osf5*)	# as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      else
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~
+	$LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~$rm $lib.exp'
+
+	# Both c and cxx compiler support -rpath directly
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+      fi
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
+      ;;
+
+    solaris*)
+      _LT_AC_TAGVAR(no_undefined_flag, $1)=' -z text'
+      if test "$GCC" = yes; then
+	wlarc='${wl}'
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+	  $CC -shared ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$rm $lib.exp'
+      else
+	wlarc=''
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+  	$LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp'
+      fi
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      case $host_os in
+      solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+      *)
+	# The compiler driver will combine and reorder linker options,
+	# but understands `-z linker_flag'.  GCC discards it without `$wl',
+	# but is careful enough not to reorder.
+ 	# Supported since Solaris 2.6 (maybe 2.5.1?)
+	if test "$GCC" = yes; then
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+	else
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
+	fi
+	;;
+      esac
+      _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+	# Use $CC to link under sequent, because it throws in some extra .o
+	# files that make .init and .fini sections work.
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+	sni)
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_AC_TAGVAR(hardcode_direct, $1)=yes # is this really true???
+	;;
+	siemens)
+	  ## LD is ld it makes a PLAMLIB
+	  ## CC just makes a GrossModule.
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_AC_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs'
+	  _LT_AC_TAGVAR(hardcode_direct, $1)=no
+        ;;
+	motorola)
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_AC_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie
+	;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    sysv4.3*)
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+	runpath_var=LD_RUN_PATH
+	hardcode_runpath_var=yes
+	_LT_AC_TAGVAR(ld_shlibs, $1)=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
+      _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
+      _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`'
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':'
+      _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
+      _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *)
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
+      ;;
+    esac
+  fi
+])
+AC_MSG_RESULT([$_LT_AC_TAGVAR(ld_shlibs, $1)])
+test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)" in
+x|xyes)
+  # Assume -lc should be added
+  _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $_LT_AC_TAGVAR(archive_cmds, $1) in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      AC_MSG_CHECKING([whether -lc should be explicitly linked in])
+      $rm conftest*
+      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+      if AC_TRY_EVAL(ac_compile) 2>conftest.err; then
+        soname=conftest
+        lib=conftest
+        libobjs=conftest.$ac_objext
+        deplibs=
+        wl=$_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)
+	pic_flag=$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)
+        compiler_flags=-v
+        linker_flags=-v
+        verstring=
+        output_objdir=.
+        libname=conftest
+        lt_save_allow_undefined_flag=$_LT_AC_TAGVAR(allow_undefined_flag, $1)
+        _LT_AC_TAGVAR(allow_undefined_flag, $1)=
+        if AC_TRY_EVAL(_LT_AC_TAGVAR(archive_cmds, $1) 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1)
+        then
+	  _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
+        else
+	  _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes
+        fi
+        _LT_AC_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag
+      else
+        cat conftest.err 1>&5
+      fi
+      $rm conftest*
+      AC_MSG_RESULT([$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)])
+      ;;
+    esac
+  fi
+  ;;
+esac
+])# AC_LIBTOOL_PROG_LD_SHLIBS
+
+
+# _LT_AC_FILE_LTDLL_C
+# -------------------
+# Be careful that the start marker always follows a newline.
+AC_DEFUN([_LT_AC_FILE_LTDLL_C], [
+# /* ltdll.c starts here */
+# #define WIN32_LEAN_AND_MEAN
+# #include <windows.h>
+# #undef WIN32_LEAN_AND_MEAN
+# #include <stdio.h>
+#
+# #ifndef __CYGWIN__
+# #  ifdef __CYGWIN32__
+# #    define __CYGWIN__ __CYGWIN32__
+# #  endif
+# #endif
+#
+# #ifdef __cplusplus
+# extern "C" {
+# #endif
+# BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved);
+# #ifdef __cplusplus
+# }
+# #endif
+#
+# #ifdef __CYGWIN__
+# #include <cygwin/cygwin_dll.h>
+# DECLARE_CYGWIN_DLL( DllMain );
+# #endif
+# HINSTANCE __hDllInstance_base;
+#
+# BOOL APIENTRY
+# DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)
+# {
+#   __hDllInstance_base = hInst;
+#   return TRUE;
+# }
+# /* ltdll.c ends here */
+])# _LT_AC_FILE_LTDLL_C
+
+
+# _LT_AC_TAGVAR(VARNAME, [TAGNAME])
+# ---------------------------------
+AC_DEFUN([_LT_AC_TAGVAR], [ifelse([$2], [], [$1], [$1_$2])])
+
+
+# old names
+AC_DEFUN([AM_PROG_LIBTOOL],   [AC_PROG_LIBTOOL])
+AC_DEFUN([AM_ENABLE_SHARED],  [AC_ENABLE_SHARED($@)])
+AC_DEFUN([AM_ENABLE_STATIC],  [AC_ENABLE_STATIC($@)])
+AC_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)])
+AC_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)])
+AC_DEFUN([AM_PROG_LD],        [AC_PROG_LD])
+AC_DEFUN([AM_PROG_NM],        [AC_PROG_NM])
+
+# This is just to silence aclocal about the macro not being used
+ifelse([AC_DISABLE_FAST_INSTALL])
+
+AC_DEFUN([LT_AC_PROG_GCJ],
+[AC_CHECK_TOOL(GCJ, gcj, no)
+  test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2"
+  AC_SUBST(GCJFLAGS)
+])
+
+AC_DEFUN([LT_AC_PROG_RC],
+[AC_CHECK_TOOL(RC, windres, no)
+])
+
+
+# Cheap backport of AS_EXECUTABLE_P and required macros
+# from Autoconf 2.59; we should not use $as_executable_p directly.
+
+# _AS_TEST_PREPARE
+# ----------------
+m4_ifndef([_AS_TEST_PREPARE],
+[m4_defun([_AS_TEST_PREPARE],
+[if test -x / >/dev/null 2>&1; then
+  as_executable_p='test -x'
+else
+  as_executable_p='test -f'
+fi
+])])# _AS_TEST_PREPARE
+
+# AS_EXECUTABLE_P
+# ---------------
+# Check whether a file is executable.
+m4_ifndef([AS_EXECUTABLE_P],
+[m4_defun([AS_EXECUTABLE_P],
+[AS_REQUIRE([_AS_TEST_PREPARE])dnl
+$as_executable_p $1[]dnl
+])])# AS_EXECUTABLE_P
+
+# NOTE: This macro has been submitted for inclusion into   #
+#  GNU Autoconf as AC_PROG_SED.  When it is available in   #
+#  a released version of Autoconf we should remove this    #
+#  macro and use it instead.                               #
+# LT_AC_PROG_SED
+# --------------
+# Check for a fully-functional sed program, that truncates
+# as few characters as possible.  Prefer GNU sed if found.
+AC_DEFUN([LT_AC_PROG_SED],
+[AC_MSG_CHECKING([for a sed that does not truncate output])
+AC_CACHE_VAL(lt_cv_path_SED,
+[# Loop through the user's path and test for sed and gsed.
+# Then use that list of sed's as ones to test for truncation.
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for lt_ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      if AS_EXECUTABLE_P(["$as_dir/$lt_ac_prog$ac_exec_ext"]); then
+        lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext"
+      fi
+    done
+  done
+done
+IFS=$as_save_IFS
+lt_ac_max=0
+lt_ac_count=0
+# Add /usr/xpg4/bin/sed as it is typically found on Solaris
+# along with /bin/sed that truncates output.
+for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do
+  test ! -f $lt_ac_sed && continue
+  cat /dev/null > conftest.in
+  lt_ac_count=0
+  echo $ECHO_N "0123456789$ECHO_C" >conftest.in
+  # Check for GNU sed and select it if it is found.
+  if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then
+    lt_cv_path_SED=$lt_ac_sed
+    break
+  fi
+  while true; do
+    cat conftest.in conftest.in >conftest.tmp
+    mv conftest.tmp conftest.in
+    cp conftest.in conftest.nl
+    echo >>conftest.nl
+    $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break
+    cmp -s conftest.out conftest.nl || break
+    # 10000 chars as input seems more than enough
+    test $lt_ac_count -gt 10 && break
+    lt_ac_count=`expr $lt_ac_count + 1`
+    if test $lt_ac_count -gt $lt_ac_max; then
+      lt_ac_max=$lt_ac_count
+      lt_cv_path_SED=$lt_ac_sed
+    fi
+  done
+done
+])
+SED=$lt_cv_path_SED
+AC_SUBST([SED])
+AC_MSG_RESULT([$SED])
+])
+
+# Copyright (C) 2002, 2003, 2005, 2006  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_AUTOMAKE_VERSION(VERSION)
+# ----------------------------
+# Automake X.Y traces this macro to ensure aclocal.m4 has been
+# generated from the m4 files accompanying Automake X.Y.
+# (This private macro should not be called outside this file.)
+AC_DEFUN([AM_AUTOMAKE_VERSION],
+[am__api_version='1.10'
+dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
+dnl require some minimum version.  Point them to the right macro.
+m4_if([$1], [1.10], [],
+      [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
+])
+
+# _AM_AUTOCONF_VERSION(VERSION)
+# -----------------------------
+# aclocal traces this macro to find the Autoconf version.
+# This is a private macro too.  Using m4_define simplifies
+# the logic in aclocal, which can simply ignore this definition.
+m4_define([_AM_AUTOCONF_VERSION], [])
+
+# AM_SET_CURRENT_AUTOMAKE_VERSION
+# -------------------------------
+# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
+# This function is AC_REQUIREd by AC_INIT_AUTOMAKE.
+AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
+[AM_AUTOMAKE_VERSION([1.10])dnl
+_AM_AUTOCONF_VERSION(m4_PACKAGE_VERSION)])
+
+# Figure out how to run the assembler.                      -*- Autoconf -*-
+
+# Copyright (C) 2001, 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 5
+
+# AM_PROG_AS
+# ----------
+AC_DEFUN([AM_PROG_AS],
+[# By default we simply use the C compiler to build assembly code.
+AC_REQUIRE([AC_PROG_CC])
+test "${CCAS+set}" = set || CCAS=$CC
+test "${CCASFLAGS+set}" = set || CCASFLAGS=$CFLAGS
+AC_ARG_VAR([CCAS],      [assembler compiler command (defaults to CC)])
+AC_ARG_VAR([CCASFLAGS], [assembler compiler flags (defaults to CFLAGS)])
+_AM_IF_OPTION([no-dependencies],, [_AM_DEPENDENCIES([CCAS])])dnl
+])
+
+# AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
+
+# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
+# $ac_aux_dir to `$srcdir/foo'.  In other projects, it is set to
+# `$srcdir', `$srcdir/..', or `$srcdir/../..'.
+#
+# Of course, Automake must honor this variable whenever it calls a
+# tool from the auxiliary directory.  The problem is that $srcdir (and
+# therefore $ac_aux_dir as well) can be either absolute or relative,
+# depending on how configure is run.  This is pretty annoying, since
+# it makes $ac_aux_dir quite unusable in subdirectories: in the top
+# source directory, any form will work fine, but in subdirectories a
+# relative path needs to be adjusted first.
+#
+# $ac_aux_dir/missing
+#    fails when called from a subdirectory if $ac_aux_dir is relative
+# $top_srcdir/$ac_aux_dir/missing
+#    fails if $ac_aux_dir is absolute,
+#    fails when called from a subdirectory in a VPATH build with
+#          a relative $ac_aux_dir
+#
+# The reason of the latter failure is that $top_srcdir and $ac_aux_dir
+# are both prefixed by $srcdir.  In an in-source build this is usually
+# harmless because $srcdir is `.', but things will broke when you
+# start a VPATH build or use an absolute $srcdir.
+#
+# So we could use something similar to $top_srcdir/$ac_aux_dir/missing,
+# iff we strip the leading $srcdir from $ac_aux_dir.  That would be:
+#   am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"`
+# and then we would define $MISSING as
+#   MISSING="\${SHELL} $am_aux_dir/missing"
+# This will work as long as MISSING is not called from configure, because
+# unfortunately $(top_srcdir) has no meaning in configure.
+# However there are other variables, like CC, which are often used in
+# configure, and could therefore not use this "fixed" $ac_aux_dir.
+#
+# Another solution, used here, is to always expand $ac_aux_dir to an
+# absolute PATH.  The drawback is that using absolute paths prevent a
+# configured tree to be moved without reconfiguration.
+
+AC_DEFUN([AM_AUX_DIR_EXPAND],
+[dnl Rely on autoconf to set up CDPATH properly.
+AC_PREREQ([2.50])dnl
+# expand $ac_aux_dir to an absolute path
+am_aux_dir=`cd $ac_aux_dir && pwd`
+])
+
+# AM_CONDITIONAL                                            -*- Autoconf -*-
+
+# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 8
+
+# AM_CONDITIONAL(NAME, SHELL-CONDITION)
+# -------------------------------------
+# Define a conditional.
+AC_DEFUN([AM_CONDITIONAL],
+[AC_PREREQ(2.52)dnl
+ ifelse([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
+	[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
+AC_SUBST([$1_TRUE])dnl
+AC_SUBST([$1_FALSE])dnl
+_AM_SUBST_NOTMAKE([$1_TRUE])dnl
+_AM_SUBST_NOTMAKE([$1_FALSE])dnl
+if $2; then
+  $1_TRUE=
+  $1_FALSE='#'
+else
+  $1_TRUE='#'
+  $1_FALSE=
+fi
+AC_CONFIG_COMMANDS_PRE(
+[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
+  AC_MSG_ERROR([[conditional "$1" was never defined.
+Usually this means the macro was only invoked conditionally.]])
+fi])])
+
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 9
+
+# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
+# written in clear, in which case automake, when reading aclocal.m4,
+# will think it sees a *use*, and therefore will trigger all it's
+# C support machinery.  Also note that it means that autoscan, seeing
+# CC etc. in the Makefile, will ask for an AC_PROG_CC use...
+
+
+# _AM_DEPENDENCIES(NAME)
+# ----------------------
+# See how the compiler implements dependency checking.
+# NAME is "CC", "CXX", "GCJ", or "OBJC".
+# We try a few techniques and use that to set a single cache variable.
+#
+# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
+# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular
+# dependency, and given that the user is not expected to run this macro,
+# just rely on AC_PROG_CC.
+AC_DEFUN([_AM_DEPENDENCIES],
+[AC_REQUIRE([AM_SET_DEPDIR])dnl
+AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
+AC_REQUIRE([AM_MAKE_INCLUDE])dnl
+AC_REQUIRE([AM_DEP_TRACK])dnl
+
+ifelse([$1], CC,   [depcc="$CC"   am_compiler_list=],
+       [$1], CXX,  [depcc="$CXX"  am_compiler_list=],
+       [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
+       [$1], UPC,  [depcc="$UPC"  am_compiler_list=],
+       [$1], GCJ,  [depcc="$GCJ"  am_compiler_list='gcc3 gcc'],
+                   [depcc="$$1"   am_compiler_list=])
+
+AC_CACHE_CHECK([dependency style of $depcc],
+               [am_cv_$1_dependencies_compiler_type],
+[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_$1_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
+  fi
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    case $depmode in
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    none) break ;;
+    esac
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.
+    if depmode=$depmode \
+       source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_$1_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_$1_dependencies_compiler_type=none
+fi
+])
+AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])
+AM_CONDITIONAL([am__fastdep$1], [
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_$1_dependencies_compiler_type" = gcc3])
+])
+
+
+# AM_SET_DEPDIR
+# -------------
+# Choose a directory name for dependency files.
+# This macro is AC_REQUIREd in _AM_DEPENDENCIES
+AC_DEFUN([AM_SET_DEPDIR],
+[AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
+])
+
+
+# AM_DEP_TRACK
+# ------------
+AC_DEFUN([AM_DEP_TRACK],
+[AC_ARG_ENABLE(dependency-tracking,
+[  --disable-dependency-tracking  speeds up one-time build
+  --enable-dependency-tracking   do not reject slow dependency extractors])
+if test "x$enable_dependency_tracking" != xno; then
+  am_depcomp="$ac_aux_dir/depcomp"
+  AMDEPBACKSLASH='\'
+fi
+AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
+AC_SUBST([AMDEPBACKSLASH])dnl
+_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
+])
+
+# Generate code to set up dependency tracking.              -*- Autoconf -*-
+
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+#serial 3
+
+# _AM_OUTPUT_DEPENDENCY_COMMANDS
+# ------------------------------
+AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
+[for mf in $CONFIG_FILES; do
+  # Strip MF so we end up with the name of the file.
+  mf=`echo "$mf" | sed -e 's/:.*$//'`
+  # Check whether this is an Automake generated Makefile or not.
+  # We used to match only the files named `Makefile.in', but
+  # some people rename them; so instead we look at the file content.
+  # Grep'ing the first line is not enough: some people post-process
+  # each Makefile.in and add a new line on top of each file to say so.
+  # Grep'ing the whole file is not good either: AIX grep has a line
+  # limit of 2048, but all sed's we know have understand at least 4000.
+  if sed 10q "$mf" | grep '^#.*generated by automake' > /dev/null 2>&1; then
+    dirpart=`AS_DIRNAME("$mf")`
+  else
+    continue
+  fi
+  # Extract the definition of DEPDIR, am__include, and am__quote
+  # from the Makefile without running `make'.
+  DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
+  test -z "$DEPDIR" && continue
+  am__include=`sed -n 's/^am__include = //p' < "$mf"`
+  test -z "am__include" && continue
+  am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+  # When using ansi2knr, U may be empty or an underscore; expand it
+  U=`sed -n 's/^U = //p' < "$mf"`
+  # Find all dependency output files, they are included files with
+  # $(DEPDIR) in their names.  We invoke sed twice because it is the
+  # simplest approach to changing $(DEPDIR) to its actual value in the
+  # expansion.
+  for file in `sed -n "
+    s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
+       sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
+    # Make sure the directory exists.
+    test -f "$dirpart/$file" && continue
+    fdir=`AS_DIRNAME(["$file"])`
+    AS_MKDIR_P([$dirpart/$fdir])
+    # echo "creating $dirpart/$file"
+    echo '# dummy' > "$dirpart/$file"
+  done
+done
+])# _AM_OUTPUT_DEPENDENCY_COMMANDS
+
+
+# AM_OUTPUT_DEPENDENCY_COMMANDS
+# -----------------------------
+# This macro should only be invoked once -- use via AC_REQUIRE.
+#
+# This code is only required when automatic dependency tracking
+# is enabled.  FIXME.  This creates each `.P' file that we will
+# need in order to bootstrap the dependency handling code.
+AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
+[AC_CONFIG_COMMANDS([depfiles],
+     [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
+     [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
+])
+
+# Do all the work for Automake.                             -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+# 2005, 2006 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 12
+
+# This macro actually does too much.  Some checks are only needed if
+# your package does certain things.  But this isn't really a big deal.
+
+# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
+# AM_INIT_AUTOMAKE([OPTIONS])
+# -----------------------------------------------
+# The call with PACKAGE and VERSION arguments is the old style
+# call (pre autoconf-2.50), which is being phased out.  PACKAGE
+# and VERSION should now be passed to AC_INIT and removed from
+# the call to AM_INIT_AUTOMAKE.
+# We support both call styles for the transition.  After
+# the next Automake release, Autoconf can make the AC_INIT
+# arguments mandatory, and then we can depend on a new Autoconf
+# release and drop the old call support.
+AC_DEFUN([AM_INIT_AUTOMAKE],
+[AC_PREREQ([2.60])dnl
+dnl Autoconf wants to disallow AM_ names.  We explicitly allow
+dnl the ones we care about.
+m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
+AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
+AC_REQUIRE([AC_PROG_INSTALL])dnl
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
+  fi
+fi
+
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+AC_SUBST([CYGPATH_W])
+
+# Define the identity of the package.
+dnl Distinguish between old-style and new-style calls.
+m4_ifval([$2],
+[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
+ AC_SUBST([PACKAGE], [$1])dnl
+ AC_SUBST([VERSION], [$2])],
+[_AM_SET_OPTIONS([$1])dnl
+dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
+m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,,
+  [m4_fatal([AC_INIT should be called with package and version arguments])])dnl
+ AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
+ AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
+
+_AM_IF_OPTION([no-define],,
+[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
+ AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl
+
+# Some tools Automake needs.
+AC_REQUIRE([AM_SANITY_CHECK])dnl
+AC_REQUIRE([AC_ARG_PROGRAM])dnl
+AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version})
+AM_MISSING_PROG(AUTOCONF, autoconf)
+AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})
+AM_MISSING_PROG(AUTOHEADER, autoheader)
+AM_MISSING_PROG(MAKEINFO, makeinfo)
+AM_PROG_INSTALL_SH
+AM_PROG_INSTALL_STRIP
+AC_REQUIRE([AM_PROG_MKDIR_P])dnl
+# We need awk for the "check" target.  The system "awk" is bad on
+# some platforms.
+AC_REQUIRE([AC_PROG_AWK])dnl
+AC_REQUIRE([AC_PROG_MAKE_SET])dnl
+AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
+              [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
+	      		     [_AM_PROG_TAR([v7])])])
+_AM_IF_OPTION([no-dependencies],,
+[AC_PROVIDE_IFELSE([AC_PROG_CC],
+                  [_AM_DEPENDENCIES(CC)],
+                  [define([AC_PROG_CC],
+                          defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_CXX],
+                  [_AM_DEPENDENCIES(CXX)],
+                  [define([AC_PROG_CXX],
+                          defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_OBJC],
+                  [_AM_DEPENDENCIES(OBJC)],
+                  [define([AC_PROG_OBJC],
+                          defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl
+])
+])
+
+
+# When config.status generates a header, we must update the stamp-h file.
+# This file resides in the same directory as the config header
+# that is generated.  The stamp files are numbered to have different names.
+
+# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the
+# loop where config.status creates the headers, so we can generate
+# our stamp files there.
+AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],
+[# Compute $1's index in $config_headers.
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+  case $_am_header in
+    $1 | $1:* )
+      break ;;
+    * )
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+  esac
+done
+echo "timestamp for $1" >`AS_DIRNAME([$1])`/stamp-h[]$_am_stamp_count])
+
+# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_INSTALL_SH
+# ------------------
+# Define $install_sh.
+AC_DEFUN([AM_PROG_INSTALL_SH],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+install_sh=${install_sh-"\$(SHELL) $am_aux_dir/install-sh"}
+AC_SUBST(install_sh)])
+
+# Copyright (C) 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 2
+
+# Check whether the underlying file-system supports filenames
+# with a leading dot.  For instance MS-DOS doesn't.
+AC_DEFUN([AM_SET_LEADING_DOT],
+[rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+AC_SUBST([am__leading_dot])])
+
+# Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
+# From Jim Meyering
+
+# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 4
+
+AC_DEFUN([AM_MAINTAINER_MODE],
+[AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
+  dnl maintainer-mode is disabled by default
+  AC_ARG_ENABLE(maintainer-mode,
+[  --enable-maintainer-mode  enable make rules and dependencies not useful
+			  (and sometimes confusing) to the casual installer],
+      USE_MAINTAINER_MODE=$enableval,
+      USE_MAINTAINER_MODE=no)
+  AC_MSG_RESULT([$USE_MAINTAINER_MODE])
+  AM_CONDITIONAL(MAINTAINER_MODE, [test $USE_MAINTAINER_MODE = yes])
+  MAINT=$MAINTAINER_MODE_TRUE
+  AC_SUBST(MAINT)dnl
+]
+)
+
+AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE])
+
+# Check to see how 'make' treats includes.	            -*- Autoconf -*-
+
+# Copyright (C) 2001, 2002, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 3
+
+# AM_MAKE_INCLUDE()
+# -----------------
+# Check to see how make treats includes.
+AC_DEFUN([AM_MAKE_INCLUDE],
+[am_make=${MAKE-make}
+cat > confinc << 'END'
+am__doit:
+	@echo done
+.PHONY: am__doit
+END
+# If we don't find an include directive, just comment out the code.
+AC_MSG_CHECKING([for style of include used by $am_make])
+am__include="#"
+am__quote=
+_am_result=none
+# First try GNU make style include.
+echo "include confinc" > confmf
+# We grep out `Entering directory' and `Leaving directory'
+# messages which can occur if `w' ends up in MAKEFLAGS.
+# In particular we don't look at `^make:' because GNU make might
+# be invoked under some other name (usually "gmake"), in which
+# case it prints its new name instead of `make'.
+if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then
+   am__include=include
+   am__quote=
+   _am_result=GNU
+fi
+# Now try BSD make style include.
+if test "$am__include" = "#"; then
+   echo '.include "confinc"' > confmf
+   if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then
+      am__include=.include
+      am__quote="\""
+      _am_result=BSD
    fi
 fi
+AC_SUBST([am__include])
+AC_SUBST([am__quote])
+AC_MSG_RESULT([$_am_result])
+rm -f confinc confmf
+])
+
+# Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 5
+
+# AM_PROG_CC_C_O
+# --------------
+# Like AC_PROG_CC_C_O, but changed for automake.
+AC_DEFUN([AM_PROG_CC_C_O],
+[AC_REQUIRE([AC_PROG_CC_C_O])dnl
+AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([compile])dnl
+# FIXME: we rely on the cache variable name because
+# there is no other way.
+set dummy $CC
+ac_cc=`echo $[2] | sed ['s/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/']`
+if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" != yes"; then
+   # Losing compiler, so override with the script.
+   # FIXME: It is wrong to rewrite CC.
+   # But if we don't then we get into trouble of one sort or another.
+   # A longer-term fix would be to have automake use am__CC in this case,
+   # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
+   CC="$am_aux_dir/compile $CC"
+fi
+dnl Make sure AC_PROG_CC is never called again, or it will override our
+dnl setting of CC.
+m4_define([AC_PROG_CC],
+          [m4_fatal([AC_PROG_CC cannot be called after AM_PROG_CC_C_O])])
+])
+
+# Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
+
+# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 5
 
-if test $ac_cv_func_mmap_file = yes; then
-  AC_DEFINE(HAVE_MMAP_FILE, 1,
-	    [Define if read-only mmap of a plain file works.])
-fi
-if test $ac_cv_func_mmap_dev_zero = yes; then
-  AC_DEFINE(HAVE_MMAP_DEV_ZERO, 1,
-	    [Define if mmap of /dev/zero works.])
-fi
-if test $ac_cv_func_mmap_anon = yes; then
-  AC_DEFINE(HAVE_MMAP_ANON, 1,
-	    [Define if mmap with MAP_ANON(YMOUS) works.])
+# AM_MISSING_PROG(NAME, PROGRAM)
+# ------------------------------
+AC_DEFUN([AM_MISSING_PROG],
+[AC_REQUIRE([AM_MISSING_HAS_RUN])
+$1=${$1-"${am_missing_run}$2"}
+AC_SUBST($1)])
+
+
+# AM_MISSING_HAS_RUN
+# ------------------
+# Define MISSING if not defined so far and test if it supports --run.
+# If it does, set am_missing_run to use it, otherwise, to nothing.
+AC_DEFUN([AM_MISSING_HAS_RUN],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([missing])dnl
+test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing"
+# Use eval to expand $SHELL
+if eval "$MISSING --run true"; then
+  am_missing_run="$MISSING --run "
+else
+  am_missing_run=
+  AC_MSG_WARN([`missing' script is too old or missing])
 fi
 ])
+
+# Copyright (C) 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_MKDIR_P
+# ---------------
+# Check for `mkdir -p'.
+AC_DEFUN([AM_PROG_MKDIR_P],
+[AC_PREREQ([2.60])dnl
+AC_REQUIRE([AC_PROG_MKDIR_P])dnl
+dnl Automake 1.8 to 1.9.6 used to define mkdir_p.  We now use MKDIR_P,
+dnl while keeping a definition of mkdir_p for backward compatibility.
+dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile.
+dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of
+dnl Makefile.ins that do not define MKDIR_P, so we do our own
+dnl adjustment using top_builddir (which is defined more often than
+dnl MKDIR_P).
+AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl
+case $mkdir_p in
+  [[\\/$]]* | ?:[[\\/]]*) ;;
+  */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
+esac
+])
+
+# Helper functions for option handling.                     -*- Autoconf -*-
+
+# Copyright (C) 2001, 2002, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 3
+
+# _AM_MANGLE_OPTION(NAME)
+# -----------------------
+AC_DEFUN([_AM_MANGLE_OPTION],
+[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
+
+# _AM_SET_OPTION(NAME)
+# ------------------------------
+# Set option NAME.  Presently that only means defining a flag for this option.
+AC_DEFUN([_AM_SET_OPTION],
+[m4_define(_AM_MANGLE_OPTION([$1]), 1)])
+
+# _AM_SET_OPTIONS(OPTIONS)
+# ----------------------------------
+# OPTIONS is a space-separated list of Automake options.
+AC_DEFUN([_AM_SET_OPTIONS],
+[AC_FOREACH([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
+
+# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
+# -------------------------------------------
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
+AC_DEFUN([_AM_IF_OPTION],
+[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
+
+# Check to make sure that the build environment is sane.    -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 4
+
+# AM_SANITY_CHECK
+# ---------------
+AC_DEFUN([AM_SANITY_CHECK],
+[AC_MSG_CHECKING([whether build environment is sane])
+# Just in case
+sleep 1
+echo timestamp > conftest.file
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null`
+   if test "$[*]" = "X"; then
+      # -L didn't work.
+      set X `ls -t $srcdir/configure conftest.file`
+   fi
+   rm -f conftest.file
+   if test "$[*]" != "X $srcdir/configure conftest.file" \
+      && test "$[*]" != "X conftest.file $srcdir/configure"; then
+
+      # If neither matched, then we have a broken ls.  This can happen
+      # if, for instance, CONFIG_SHELL is bash and it inherits a
+      # broken ls alias from the environment.  This has actually
+      # happened.  Such a system could not be considered "sane".
+      AC_MSG_ERROR([ls -t appears to fail.  Make sure there is not a broken
+alias in your environment])
+   fi
+
+   test "$[2]" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   AC_MSG_ERROR([newly created file is older than distributed files!
+Check your system clock])
+fi
+AC_MSG_RESULT(yes)])
+
+# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_INSTALL_STRIP
+# ---------------------
+# One issue with vendor `install' (even GNU) is that you can't
+# specify the program used to strip binaries.  This is especially
+# annoying in cross-compiling environments, where the build's strip
+# is unlikely to handle the host's binaries.
+# Fortunately install-sh will honor a STRIPPROG variable, so we
+# always use install-sh in `make install-strip', and initialize
+# STRIPPROG with the value of the STRIP variable (set by the user).
+AC_DEFUN([AM_PROG_INSTALL_STRIP],
+[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+# Installed binaries are usually stripped using `strip' when the user
+# run `make install-strip'.  However `strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the `STRIP' environment variable to overrule this program.
+dnl Don't test for $cross_compiling = yes, because it might be `maybe'.
+if test "$cross_compiling" != no; then
+  AC_CHECK_TOOL([STRIP], [strip], :)
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+AC_SUBST([INSTALL_STRIP_PROGRAM])])
+
+# Copyright (C) 2006  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# _AM_SUBST_NOTMAKE(VARIABLE)
+# ---------------------------
+# Prevent Automake from outputing VARIABLE = @VARIABLE@ in Makefile.in.
+# This macro is traced by Automake.
+AC_DEFUN([_AM_SUBST_NOTMAKE])
+
+# Check how to create a tarball.                            -*- Autoconf -*-
+
+# Copyright (C) 2004, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 2
+
+# _AM_PROG_TAR(FORMAT)
+# --------------------
+# Check how to create a tarball in format FORMAT.
+# FORMAT should be one of `v7', `ustar', or `pax'.
+#
+# Substitute a variable $(am__tar) that is a command
+# writing to stdout a FORMAT-tarball containing the directory
+# $tardir.
+#     tardir=directory && $(am__tar) > result.tar
+#
+# Substitute a variable $(am__untar) that extract such
+# a tarball read from stdin.
+#     $(am__untar) < result.tar
+AC_DEFUN([_AM_PROG_TAR],
+[# Always define AMTAR for backward compatibility.
+AM_MISSING_PROG([AMTAR], [tar])
+m4_if([$1], [v7],
+     [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'],
+     [m4_case([$1], [ustar],, [pax],,
+              [m4_fatal([Unknown tar format])])
+AC_MSG_CHECKING([how to create a $1 tar archive])
+# Loop over all known methods to create a tar archive until one works.
+_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
+_am_tools=${am_cv_prog_tar_$1-$_am_tools}
+# Do not fold the above two line into one, because Tru64 sh and
+# Solaris sh will not grok spaces in the rhs of `-'.
+for _am_tool in $_am_tools
+do
+  case $_am_tool in
+  gnutar)
+    for _am_tar in tar gnutar gtar;
+    do
+      AM_RUN_LOG([$_am_tar --version]) && break
+    done
+    am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"'
+    am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"'
+    am__untar="$_am_tar -xf -"
+    ;;
+  plaintar)
+    # Must skip GNU tar: if it does not support --format= it doesn't create
+    # ustar tarball either.
+    (tar --version) >/dev/null 2>&1 && continue
+    am__tar='tar chf - "$$tardir"'
+    am__tar_='tar chf - "$tardir"'
+    am__untar='tar xf -'
+    ;;
+  pax)
+    am__tar='pax -L -x $1 -w "$$tardir"'
+    am__tar_='pax -L -x $1 -w "$tardir"'
+    am__untar='pax -r'
+    ;;
+  cpio)
+    am__tar='find "$$tardir" -print | cpio -o -H $1 -L'
+    am__tar_='find "$tardir" -print | cpio -o -H $1 -L'
+    am__untar='cpio -i -H $1 -d'
+    ;;
+  none)
+    am__tar=false
+    am__tar_=false
+    am__untar=false
+    ;;
+  esac
+
+  # If the value was cached, stop now.  We just wanted to have am__tar
+  # and am__untar set.
+  test -n "${am_cv_prog_tar_$1}" && break
+
+  # tar/untar a dummy directory, and stop if the command works
+  rm -rf conftest.dir
+  mkdir conftest.dir
+  echo GrepMe > conftest.dir/file
+  AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar])
+  rm -rf conftest.dir
+  if test -s conftest.tar; then
+    AM_RUN_LOG([$am__untar <conftest.tar])
+    grep GrepMe conftest.dir/file >/dev/null 2>&1 && break
+  fi
+done
+rm -rf conftest.dir
+
+AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])
+AC_MSG_RESULT([$am_cv_prog_tar_$1])])
+AC_SUBST([am__tar])
+AC_SUBST([am__untar])
+]) # _AM_PROG_TAR
+
+m4_include([acinclude.m4])

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/config.guess
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/config.guess	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/config.guess	Thu Mar 27 00:48:05 2008
@@ -1,9 +1,10 @@
 #! /bin/sh
 # Attempt to guess a canonical system name.
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
+#   Inc.
 
-timestamp='2004-11-12'
+timestamp='2007-05-17'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -17,13 +18,15 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+# 02110-1301, USA.
 #
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # configuration script generated by Autoconf, you may include it under
 # the same distribution terms that you use for the rest of that program.
 
+
 # Originally written by Per Bothner <per at bothner.com>.
 # Please send patches to <config-patches at gnu.org>.  Submit a context
 # diff and a properly formatted ChangeLog entry.
@@ -53,7 +56,7 @@
 GNU config.guess ($timestamp)
 
 Originally written by Per Bothner.
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
@@ -66,11 +69,11 @@
 while test $# -gt 0 ; do
   case $1 in
     --time-stamp | --time* | -t )
-       echo "$timestamp" ; exit 0 ;;
+       echo "$timestamp" ; exit ;;
     --version | -v )
-       echo "$version" ; exit 0 ;;
+       echo "$version" ; exit ;;
     --help | --h* | -h )
-       echo "$usage"; exit 0 ;;
+       echo "$usage"; exit ;;
     -- )     # Stop option processing
        shift; break ;;
     - )	# Use stdin as input.
@@ -104,7 +107,7 @@
 trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
 trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
 : ${TMPDIR=/tmp} ;
- { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
  { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
  { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
  { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
@@ -123,7 +126,7 @@
 	;;
  ,,*)   CC_FOR_BUILD=$CC ;;
  ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
-esac ;'
+esac ; set_cc_for_build= ;'
 
 # This is needed to find uname on a Pyramid OSx when run in the BSD universe.
 # (ghazi at noc.rutgers.edu 1994-08-24)
@@ -158,6 +161,7 @@
 	    arm*) machine=arm-unknown ;;
 	    sh3el) machine=shl-unknown ;;
 	    sh3eb) machine=sh-unknown ;;
+	    sh5el) machine=sh5le-unknown ;;
 	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
 	esac
 	# The Operating System including object format, if it has switched
@@ -196,55 +200,23 @@
 	# contains redundant information, the shorter form:
 	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
 	echo "${machine}-${os}${release}"
-	exit 0 ;;
-    amd64:OpenBSD:*:*)
-	echo x86_64-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    amiga:OpenBSD:*:*)
-	echo m68k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    cats:OpenBSD:*:*)
-	echo arm-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    hp300:OpenBSD:*:*)
-	echo m68k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    luna88k:OpenBSD:*:*)
-    	echo m88k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    mac68k:OpenBSD:*:*)
-	echo m68k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    macppc:OpenBSD:*:*)
-	echo powerpc-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    mvme68k:OpenBSD:*:*)
-	echo m68k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    mvme88k:OpenBSD:*:*)
-	echo m88k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    mvmeppc:OpenBSD:*:*)
-	echo powerpc-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    sgi:OpenBSD:*:*)
-	echo mips64-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    sun3:OpenBSD:*:*)
-	echo m68k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:OpenBSD:*:*)
-	echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
+	UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
+	echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
+	exit ;;
     *:ekkoBSD:*:*)
 	echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
+    *:SolidBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
+	exit ;;
     macppc:MirBSD:*:*)
-	echo powerppc-unknown-mirbsd${UNAME_RELEASE}
-	exit 0 ;;
+	echo powerpc-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
     *:MirBSD:*:*)
 	echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     alpha:OSF1:*:*)
 	case $UNAME_RELEASE in
 	*4.0)
@@ -297,40 +269,43 @@
 	# A Xn.n version is an unreleased experimental baselevel.
 	# 1.2 uses "1.2" for uname -r.
 	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-	exit 0 ;;
+	exit ;;
     Alpha\ *:Windows_NT*:*)
 	# How do we know it's Interix rather than the generic POSIX subsystem?
 	# Should we change UNAME_MACHINE based on the output of uname instead
 	# of the specific Alpha model?
 	echo alpha-pc-interix
-	exit 0 ;;
+	exit ;;
     21064:Windows_NT:50:3)
 	echo alpha-dec-winnt3.5
-	exit 0 ;;
+	exit ;;
     Amiga*:UNIX_System_V:4.0:*)
 	echo m68k-unknown-sysv4
-	exit 0;;
+	exit ;;
     *:[Aa]miga[Oo][Ss]:*:*)
 	echo ${UNAME_MACHINE}-unknown-amigaos
-	exit 0 ;;
+	exit ;;
     *:[Mm]orph[Oo][Ss]:*:*)
 	echo ${UNAME_MACHINE}-unknown-morphos
-	exit 0 ;;
+	exit ;;
     *:OS/390:*:*)
 	echo i370-ibm-openedition
-	exit 0 ;;
+	exit ;;
     *:z/VM:*:*)
 	echo s390-ibm-zvmoe
-	exit 0 ;;
+	exit ;;
     *:OS400:*:*)
         echo powerpc-ibm-os400
-	exit 0 ;;
+	exit ;;
     arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
 	echo arm-acorn-riscix${UNAME_RELEASE}
-	exit 0;;
+	exit ;;
+    arm:riscos:*:*|arm:RISCOS:*:*)
+	echo arm-unknown-riscos
+	exit ;;
     SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
 	echo hppa1.1-hitachi-hiuxmpp
-	exit 0;;
+	exit ;;
     Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
 	# akee at wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
 	if test "`(/bin/universe) 2>/dev/null`" = att ; then
@@ -338,32 +313,32 @@
 	else
 		echo pyramid-pyramid-bsd
 	fi
-	exit 0 ;;
+	exit ;;
     NILE*:*:*:dcosx)
 	echo pyramid-pyramid-svr4
-	exit 0 ;;
+	exit ;;
     DRS?6000:unix:4.0:6*)
 	echo sparc-icl-nx6
-	exit 0 ;;
+	exit ;;
     DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
 	case `/usr/bin/uname -p` in
-	    sparc) echo sparc-icl-nx7 && exit 0 ;;
+	    sparc) echo sparc-icl-nx7; exit ;;
 	esac ;;
     sun4H:SunOS:5.*:*)
 	echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit 0 ;;
+	exit ;;
     sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
 	echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit 0 ;;
-    i86pc:SunOS:5.*:*)
+	exit ;;
+    i86pc:SunOS:5.*:* | ix86xen:SunOS:5.*:*)
 	echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit 0 ;;
+	exit ;;
     sun4*:SunOS:6*:*)
 	# According to config.sub, this is the proper way to canonicalize
 	# SunOS6.  Hard to guess exactly what SunOS6 will be like, but
 	# it's likely to be more like Solaris than SunOS4.
 	echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit 0 ;;
+	exit ;;
     sun4*:SunOS:*:*)
 	case "`/usr/bin/arch -k`" in
 	    Series*|S4*)
@@ -372,10 +347,10 @@
 	esac
 	# Japanese Language versions have a version number like `4.1.3-JL'.
 	echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
-	exit 0 ;;
+	exit ;;
     sun3*:SunOS:*:*)
 	echo m68k-sun-sunos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     sun*:*:4.2BSD:*)
 	UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
 	test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
@@ -387,10 +362,10 @@
 		echo sparc-sun-sunos${UNAME_RELEASE}
 		;;
 	esac
-	exit 0 ;;
+	exit ;;
     aushp:SunOS:*:*)
 	echo sparc-auspex-sunos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     # The situation for MiNT is a little confusing.  The machine name
     # can be virtually everything (everything which is not
     # "atarist" or "atariste" at least should have a processor
@@ -401,40 +376,40 @@
     # be no problem.
     atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
         echo m68k-atari-mint${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
 	echo m68k-atari-mint${UNAME_RELEASE}
-        exit 0 ;;
+        exit ;;
     *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
         echo m68k-atari-mint${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
         echo m68k-milan-mint${UNAME_RELEASE}
-        exit 0 ;;
+        exit ;;
     hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
         echo m68k-hades-mint${UNAME_RELEASE}
-        exit 0 ;;
+        exit ;;
     *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
         echo m68k-unknown-mint${UNAME_RELEASE}
-        exit 0 ;;
+        exit ;;
     m68k:machten:*:*)
 	echo m68k-apple-machten${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     powerpc:machten:*:*)
 	echo powerpc-apple-machten${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     RISC*:Mach:*:*)
 	echo mips-dec-mach_bsd4.3
-	exit 0 ;;
+	exit ;;
     RISC*:ULTRIX:*:*)
 	echo mips-dec-ultrix${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     VAX*:ULTRIX*:*:*)
 	echo vax-dec-ultrix${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     2020:CLIX:*:* | 2430:CLIX:*:*)
 	echo clipper-intergraph-clix${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     mips:*:*:UMIPS | mips:*:*:RISCos)
 	eval $set_cc_for_build
 	sed 's/^	//' << EOF >$dummy.c
@@ -458,32 +433,33 @@
 	  exit (-1);
 	}
 EOF
-	$CC_FOR_BUILD -o $dummy $dummy.c \
-	  && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
-	  && exit 0
+	$CC_FOR_BUILD -o $dummy $dummy.c &&
+	  dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
+	  SYSTEM_NAME=`$dummy $dummyarg` &&
+	    { echo "$SYSTEM_NAME"; exit; }
 	echo mips-mips-riscos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     Motorola:PowerMAX_OS:*:*)
 	echo powerpc-motorola-powermax
-	exit 0 ;;
+	exit ;;
     Motorola:*:4.3:PL8-*)
 	echo powerpc-harris-powermax
-	exit 0 ;;
+	exit ;;
     Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
 	echo powerpc-harris-powermax
-	exit 0 ;;
+	exit ;;
     Night_Hawk:Power_UNIX:*:*)
 	echo powerpc-harris-powerunix
-	exit 0 ;;
+	exit ;;
     m88k:CX/UX:7*:*)
 	echo m88k-harris-cxux7
-	exit 0 ;;
+	exit ;;
     m88k:*:4*:R4*)
 	echo m88k-motorola-sysv4
-	exit 0 ;;
+	exit ;;
     m88k:*:3*:R3*)
 	echo m88k-motorola-sysv3
-	exit 0 ;;
+	exit ;;
     AViiON:dgux:*:*)
         # DG/UX returns AViiON for all architectures
         UNAME_PROCESSOR=`/usr/bin/uname -p`
@@ -499,29 +475,29 @@
 	else
 	    echo i586-dg-dgux${UNAME_RELEASE}
 	fi
- 	exit 0 ;;
+ 	exit ;;
     M88*:DolphinOS:*:*)	# DolphinOS (SVR3)
 	echo m88k-dolphin-sysv3
-	exit 0 ;;
+	exit ;;
     M88*:*:R3*:*)
 	# Delta 88k system running SVR3
 	echo m88k-motorola-sysv3
-	exit 0 ;;
+	exit ;;
     XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
 	echo m88k-tektronix-sysv3
-	exit 0 ;;
+	exit ;;
     Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
 	echo m68k-tektronix-bsd
-	exit 0 ;;
+	exit ;;
     *:IRIX*:*:*)
 	echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
-	exit 0 ;;
+	exit ;;
     ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
-	echo romp-ibm-aix      # uname -m gives an 8 hex-code CPU id
-	exit 0 ;;              # Note that: echo "'`uname -s`'" gives 'AIX '
+	echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
+	exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
     i*86:AIX:*:*)
 	echo i386-ibm-aix
-	exit 0 ;;
+	exit ;;
     ia64:AIX:*:*)
 	if [ -x /usr/bin/oslevel ] ; then
 		IBM_REV=`/usr/bin/oslevel`
@@ -529,7 +505,7 @@
 		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
 	fi
 	echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
-	exit 0 ;;
+	exit ;;
     *:AIX:2:3)
 	if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
 		eval $set_cc_for_build
@@ -544,14 +520,18 @@
 			exit(0);
 			}
 EOF
-		$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
-		echo rs6000-ibm-aix3.2.5
+		if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
+		then
+			echo "$SYSTEM_NAME"
+		else
+			echo rs6000-ibm-aix3.2.5
+		fi
 	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
 		echo rs6000-ibm-aix3.2.4
 	else
 		echo rs6000-ibm-aix3.2
 	fi
-	exit 0 ;;
+	exit ;;
     *:AIX:*:[45])
 	IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
 	if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
@@ -565,28 +545,28 @@
 		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
 	fi
 	echo ${IBM_ARCH}-ibm-aix${IBM_REV}
-	exit 0 ;;
+	exit ;;
     *:AIX:*:*)
 	echo rs6000-ibm-aix
-	exit 0 ;;
+	exit ;;
     ibmrt:4.4BSD:*|romp-ibm:BSD:*)
 	echo romp-ibm-bsd4.4
-	exit 0 ;;
+	exit ;;
     ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
 	echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
-	exit 0 ;;                           # report: romp-ibm BSD 4.3
+	exit ;;                             # report: romp-ibm BSD 4.3
     *:BOSX:*:*)
 	echo rs6000-bull-bosx
-	exit 0 ;;
+	exit ;;
     DPX/2?00:B.O.S.:*:*)
 	echo m68k-bull-sysv3
-	exit 0 ;;
+	exit ;;
     9000/[34]??:4.3bsd:1.*:*)
 	echo m68k-hp-bsd
-	exit 0 ;;
+	exit ;;
     hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
 	echo m68k-hp-bsd4.4
-	exit 0 ;;
+	exit ;;
     9000/[34678]??:HP-UX:*:*)
 	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
 	case "${UNAME_MACHINE}" in
@@ -648,9 +628,19 @@
 	esac
 	if [ ${HP_ARCH} = "hppa2.0w" ]
 	then
-	    # avoid double evaluation of $set_cc_for_build
-	    test -n "$CC_FOR_BUILD" || eval $set_cc_for_build
-	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null
+	    eval $set_cc_for_build
+
+	    # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
+	    # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
+	    # generating 64-bit code.  GNU and HP use different nomenclature:
+	    #
+	    # $ CC_FOR_BUILD=cc ./config.guess
+	    # => hppa2.0w-hp-hpux11.23
+	    # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
+	    # => hppa64-hp-hpux11.23
+
+	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
+		grep __LP64__ >/dev/null
 	    then
 		HP_ARCH="hppa2.0w"
 	    else
@@ -658,11 +648,11 @@
 	    fi
 	fi
 	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
-	exit 0 ;;
+	exit ;;
     ia64:HP-UX:*:*)
 	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
 	echo ia64-hp-hpux${HPUX_REV}
-	exit 0 ;;
+	exit ;;
     3050*:HI-UX:*:*)
 	eval $set_cc_for_build
 	sed 's/^	//' << EOF >$dummy.c
@@ -690,158 +680,182 @@
 	  exit (0);
 	}
 EOF
-	$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
+	$CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
+		{ echo "$SYSTEM_NAME"; exit; }
 	echo unknown-hitachi-hiuxwe2
-	exit 0 ;;
+	exit ;;
     9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
 	echo hppa1.1-hp-bsd
-	exit 0 ;;
+	exit ;;
     9000/8??:4.3bsd:*:*)
 	echo hppa1.0-hp-bsd
-	exit 0 ;;
+	exit ;;
     *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
 	echo hppa1.0-hp-mpeix
-	exit 0 ;;
+	exit ;;
     hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
 	echo hppa1.1-hp-osf
-	exit 0 ;;
+	exit ;;
     hp8??:OSF1:*:*)
 	echo hppa1.0-hp-osf
-	exit 0 ;;
+	exit ;;
     i*86:OSF1:*:*)
 	if [ -x /usr/sbin/sysversion ] ; then
 	    echo ${UNAME_MACHINE}-unknown-osf1mk
 	else
 	    echo ${UNAME_MACHINE}-unknown-osf1
 	fi
-	exit 0 ;;
+	exit ;;
     parisc*:Lites*:*:*)
 	echo hppa1.1-hp-lites
-	exit 0 ;;
+	exit ;;
     C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
 	echo c1-convex-bsd
-        exit 0 ;;
+        exit ;;
     C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
 	if getsysinfo -f scalar_acc
 	then echo c32-convex-bsd
 	else echo c2-convex-bsd
 	fi
-        exit 0 ;;
+        exit ;;
     C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
 	echo c34-convex-bsd
-        exit 0 ;;
+        exit ;;
     C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
 	echo c38-convex-bsd
-        exit 0 ;;
+        exit ;;
     C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
 	echo c4-convex-bsd
-        exit 0 ;;
+        exit ;;
     CRAY*Y-MP:*:*:*)
 	echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
+	exit ;;
     CRAY*[A-Z]90:*:*:*)
 	echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
 	| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
 	      -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
 	      -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
+	exit ;;
     CRAY*TS:*:*:*)
 	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
+	exit ;;
     CRAY*T3E:*:*:*)
 	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
+	exit ;;
     CRAY*SV1:*:*:*)
 	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
+	exit ;;
     *:UNICOS/mp:*:*)
 	echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
+	exit ;;
     F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
 	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
         FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
         FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
         echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
-        exit 0 ;;
+        exit ;;
     5000:UNIX_System_V:4.*:*)
         FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
         FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
         echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
-	exit 0 ;;
+	exit ;;
     i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
 	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     sparc*:BSD/OS:*:*)
 	echo sparc-unknown-bsdi${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:BSD/OS:*:*)
 	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:FreeBSD:*:*)
-	echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
-	exit 0 ;;
+	case ${UNAME_MACHINE} in
+	    pc98)
+		echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	    amd64)
+		echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	    *)
+		echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	esac
+	exit ;;
     i*:CYGWIN*:*)
 	echo ${UNAME_MACHINE}-pc-cygwin
-	exit 0 ;;
-    i*:MINGW*:*)
+	exit ;;
+    *:MINGW*:*)
 	echo ${UNAME_MACHINE}-pc-mingw32
-	exit 0 ;;
+	exit ;;
+    i*:windows32*:*)
+    	# uname -m includes "-pc" on this system.
+    	echo ${UNAME_MACHINE}-mingw32
+	exit ;;
     i*:PW*:*)
 	echo ${UNAME_MACHINE}-pc-pw32
-	exit 0 ;;
-    x86:Interix*:[34]*)
-	echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//'
-	exit 0 ;;
+	exit ;;
+    *:Interix*:[3456]*)
+    	case ${UNAME_MACHINE} in
+	    x86) 
+		echo i586-pc-interix${UNAME_RELEASE}
+		exit ;;
+	    EM64T | authenticamd)
+		echo x86_64-unknown-interix${UNAME_RELEASE}
+		exit ;;
+	esac ;;
     [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
 	echo i${UNAME_MACHINE}-pc-mks
-	exit 0 ;;
+	exit ;;
     i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
 	# How do we know it's Interix rather than the generic POSIX subsystem?
 	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
 	# UNAME_MACHINE based on the output of uname instead of i386?
 	echo i586-pc-interix
-	exit 0 ;;
+	exit ;;
     i*:UWIN*:*)
 	echo ${UNAME_MACHINE}-pc-uwin
-	exit 0 ;;
+	exit ;;
+    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
+	echo x86_64-unknown-cygwin
+	exit ;;
     p*:CYGWIN*:*)
 	echo powerpcle-unknown-cygwin
-	exit 0 ;;
+	exit ;;
     prep*:SunOS:5.*:*)
 	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit 0 ;;
+	exit ;;
     *:GNU:*:*)
 	# the GNU system
 	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
-	exit 0 ;;
+	exit ;;
     *:GNU/*:*:*)
 	# other systems with GNU libc and userland
 	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
-	exit 0 ;;
+	exit ;;
     i*86:Minix:*:*)
 	echo ${UNAME_MACHINE}-pc-minix
-	exit 0 ;;
+	exit ;;
     arm*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
+    avr32*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
     cris:Linux:*:*)
 	echo cris-axis-linux-gnu
-	exit 0 ;;
+	exit ;;
     crisv32:Linux:*:*)
 	echo crisv32-axis-linux-gnu
-	exit 0 ;;
+	exit ;;
     frv:Linux:*:*)
     	echo frv-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     ia64:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     m32r*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     m68*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     mips:Linux:*:*)
 	eval $set_cc_for_build
 	sed 's/^	//' << EOF >$dummy.c
@@ -858,8 +872,12 @@
 	#endif
 	#endif
 EOF
-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
-	test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
+	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+	    /^CPU/{
+		s: ::g
+		p
+	    }'`"
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
 	;;
     mips64:Linux:*:*)
 	eval $set_cc_for_build
@@ -877,15 +895,22 @@
 	#endif
 	#endif
 EOF
-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
-	test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
+	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+	    /^CPU/{
+		s: ::g
+		p
+	    }'`"
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
 	;;
+    or32:Linux:*:*)
+	echo or32-unknown-linux-gnu
+	exit ;;
     ppc:Linux:*:*)
 	echo powerpc-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     ppc64:Linux:*:*)
 	echo powerpc64-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     alpha:Linux:*:*)
 	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
 	  EV5)   UNAME_MACHINE=alphaev5 ;;
@@ -899,7 +924,7 @@
 	objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
 	if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
 	echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
-	exit 0 ;;
+	exit ;;
     parisc:Linux:*:* | hppa:Linux:*:*)
 	# Look for CPU level
 	case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
@@ -907,25 +932,31 @@
 	  PA8*) echo hppa2.0-unknown-linux-gnu ;;
 	  *)    echo hppa-unknown-linux-gnu ;;
 	esac
-	exit 0 ;;
+	exit ;;
     parisc64:Linux:*:* | hppa64:Linux:*:*)
 	echo hppa64-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     s390:Linux:*:* | s390x:Linux:*:*)
 	echo ${UNAME_MACHINE}-ibm-linux
-	exit 0 ;;
+	exit ;;
     sh64*:Linux:*:*)
     	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     sh*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     sparc:Linux:*:* | sparc64:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
+    vax:Linux:*:*)
+	echo ${UNAME_MACHINE}-dec-linux-gnu
+	exit ;;
     x86_64:Linux:*:*)
 	echo x86_64-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
+    xtensa:Linux:*:*)
+    	echo xtensa-unknown-linux-gnu
+	exit ;;
     i*86:Linux:*:*)
 	# The BFD linker knows what the default object file format is, so
 	# first see if it will tell us. cd to the root directory to prevent
@@ -943,15 +974,15 @@
 		;;
 	  a.out-i386-linux)
 		echo "${UNAME_MACHINE}-pc-linux-gnuaout"
-		exit 0 ;;
+		exit ;;
 	  coff-i386)
 		echo "${UNAME_MACHINE}-pc-linux-gnucoff"
-		exit 0 ;;
+		exit ;;
 	  "")
 		# Either a pre-BFD a.out linker (linux-gnuoldld) or
 		# one that does not give us useful --help.
 		echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
-		exit 0 ;;
+		exit ;;
 	esac
 	# Determine whether the default compiler is a.out or elf
 	eval $set_cc_for_build
@@ -968,7 +999,7 @@
 	LIBC=gnulibc1
 	# endif
 	#else
-	#ifdef __INTEL_COMPILER
+	#if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
 	LIBC=gnu
 	#else
 	LIBC=gnuaout
@@ -978,16 +1009,23 @@
 	LIBC=dietlibc
 	#endif
 EOF
-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
-	test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0
-	test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0
+	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+	    /^LIBC/{
+		s: ::g
+		p
+	    }'`"
+	test x"${LIBC}" != x && {
+		echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
+		exit
+	}
+	test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; }
 	;;
     i*86:DYNIX/ptx:4*:*)
 	# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
 	# earlier versions are messed up and put the nodename in both
 	# sysname and nodename.
 	echo i386-sequent-sysv4
-	exit 0 ;;
+	exit ;;
     i*86:UNIX_SV:4.2MP:2.*)
         # Unixware is an offshoot of SVR4, but it has its own version
         # number series starting with 2...
@@ -995,27 +1033,27 @@
 	# I just have to hope.  -- rms.
         # Use sysv4.2uw... so that sysv4* matches it.
 	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
-	exit 0 ;;
+	exit ;;
     i*86:OS/2:*:*)
 	# If we were able to find `uname', then EMX Unix compatibility
 	# is probably installed.
 	echo ${UNAME_MACHINE}-pc-os2-emx
-	exit 0 ;;
+	exit ;;
     i*86:XTS-300:*:STOP)
 	echo ${UNAME_MACHINE}-unknown-stop
-	exit 0 ;;
+	exit ;;
     i*86:atheos:*:*)
 	echo ${UNAME_MACHINE}-unknown-atheos
-	exit 0 ;;
-	i*86:syllable:*:*)
+	exit ;;
+    i*86:syllable:*:*)
 	echo ${UNAME_MACHINE}-pc-syllable
-	exit 0 ;;
+	exit ;;
     i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
 	echo i386-unknown-lynxos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     i*86:*DOS:*:*)
 	echo ${UNAME_MACHINE}-pc-msdosdjgpp
-	exit 0 ;;
+	exit ;;
     i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
 	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
 	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
@@ -1023,15 +1061,16 @@
 	else
 		echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
 	fi
-	exit 0 ;;
-    i*86:*:5:[78]*)
+	exit ;;
+    i*86:*:5:[678]*)
+    	# UnixWare 7.x, OpenUNIX and OpenServer 6.
 	case `/bin/uname -X | grep "^Machine"` in
 	    *486*)	     UNAME_MACHINE=i486 ;;
 	    *Pentium)	     UNAME_MACHINE=i586 ;;
 	    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
 	esac
 	echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
-	exit 0 ;;
+	exit ;;
     i*86:*:3.2:*)
 	if test -f /usr/options/cb.name; then
 		UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
@@ -1049,73 +1088,73 @@
 	else
 		echo ${UNAME_MACHINE}-pc-sysv32
 	fi
-	exit 0 ;;
+	exit ;;
     pc:*:*:*)
 	# Left here for compatibility:
         # uname -m prints for DJGPP always 'pc', but it prints nothing about
         # the processor, so we play safe by assuming i386.
 	echo i386-pc-msdosdjgpp
-        exit 0 ;;
+        exit ;;
     Intel:Mach:3*:*)
 	echo i386-pc-mach3
-	exit 0 ;;
+	exit ;;
     paragon:*:*:*)
 	echo i860-intel-osf1
-	exit 0 ;;
+	exit ;;
     i860:*:4.*:*) # i860-SVR4
 	if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
 	  echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
 	else # Add other i860-SVR4 vendors below as they are discovered.
 	  echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
 	fi
-	exit 0 ;;
+	exit ;;
     mini*:CTIX:SYS*5:*)
 	# "miniframe"
 	echo m68010-convergent-sysv
-	exit 0 ;;
+	exit ;;
     mc68k:UNIX:SYSTEM5:3.51m)
 	echo m68k-convergent-sysv
-	exit 0 ;;
+	exit ;;
     M680?0:D-NIX:5.3:*)
 	echo m68k-diab-dnix
-	exit 0 ;;
+	exit ;;
     M68*:*:R3V[5678]*:*)
-	test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
+	test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
     3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
 	OS_REL=''
 	test -r /etc/.relid \
 	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
 	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
-	  && echo i486-ncr-sysv4.3${OS_REL} && exit 0
+	  && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
 	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
-	  && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;;
+	  && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
     3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
         /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
-          && echo i486-ncr-sysv4 && exit 0 ;;
+          && { echo i486-ncr-sysv4; exit; } ;;
     m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
 	echo m68k-unknown-lynxos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     mc68030:UNIX_System_V:4.*:*)
 	echo m68k-atari-sysv4
-	exit 0 ;;
+	exit ;;
     TSUNAMI:LynxOS:2.*:*)
 	echo sparc-unknown-lynxos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     rs6000:LynxOS:2.*:*)
 	echo rs6000-unknown-lynxos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
 	echo powerpc-unknown-lynxos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     SM[BE]S:UNIX_SV:*:*)
 	echo mips-dde-sysv${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     RM*:ReliantUNIX-*:*:*)
 	echo mips-sni-sysv4
-	exit 0 ;;
+	exit ;;
     RM*:SINIX-*:*:*)
 	echo mips-sni-sysv4
-	exit 0 ;;
+	exit ;;
     *:SINIX-*:*:*)
 	if uname -p 2>/dev/null >/dev/null ; then
 		UNAME_MACHINE=`(uname -p) 2>/dev/null`
@@ -1123,69 +1162,81 @@
 	else
 		echo ns32k-sni-sysv
 	fi
-	exit 0 ;;
+	exit ;;
     PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
                       # says <Richard.M.Bartel at ccMail.Census.GOV>
         echo i586-unisys-sysv4
-        exit 0 ;;
+        exit ;;
     *:UNIX_System_V:4*:FTX*)
 	# From Gerald Hewes <hewes at openmarket.com>.
 	# How about differentiating between stratus architectures? -djm
 	echo hppa1.1-stratus-sysv4
-	exit 0 ;;
+	exit ;;
     *:*:*:FTX*)
 	# From seanf at swdc.stratus.com.
 	echo i860-stratus-sysv4
-	exit 0 ;;
+	exit ;;
+    i*86:VOS:*:*)
+	# From Paul.Green at stratus.com.
+	echo ${UNAME_MACHINE}-stratus-vos
+	exit ;;
     *:VOS:*:*)
 	# From Paul.Green at stratus.com.
 	echo hppa1.1-stratus-vos
-	exit 0 ;;
+	exit ;;
     mc68*:A/UX:*:*)
 	echo m68k-apple-aux${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     news*:NEWS-OS:6*:*)
 	echo mips-sony-newsos6
-	exit 0 ;;
+	exit ;;
     R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
 	if [ -d /usr/nec ]; then
 	        echo mips-nec-sysv${UNAME_RELEASE}
 	else
 	        echo mips-unknown-sysv${UNAME_RELEASE}
 	fi
-        exit 0 ;;
+        exit ;;
     BeBox:BeOS:*:*)	# BeOS running on hardware made by Be, PPC only.
 	echo powerpc-be-beos
-	exit 0 ;;
+	exit ;;
     BeMac:BeOS:*:*)	# BeOS running on Mac or Mac clone, PPC only.
 	echo powerpc-apple-beos
-	exit 0 ;;
+	exit ;;
     BePC:BeOS:*:*)	# BeOS running on Intel PC compatible.
 	echo i586-pc-beos
-	exit 0 ;;
+	exit ;;
     SX-4:SUPER-UX:*:*)
 	echo sx4-nec-superux${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     SX-5:SUPER-UX:*:*)
 	echo sx5-nec-superux${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     SX-6:SUPER-UX:*:*)
 	echo sx6-nec-superux${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
+    SX-7:SUPER-UX:*:*)
+	echo sx7-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-8:SUPER-UX:*:*)
+	echo sx8-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-8R:SUPER-UX:*:*)
+	echo sx8r-nec-superux${UNAME_RELEASE}
+	exit ;;
     Power*:Rhapsody:*:*)
 	echo powerpc-apple-rhapsody${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:Rhapsody:*:*)
 	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:Darwin:*:*)
 	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
 	case $UNAME_PROCESSOR in
-	    *86) UNAME_PROCESSOR=i686 ;;
 	    unknown) UNAME_PROCESSOR=powerpc ;;
 	esac
 	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:procnto*:*:* | *:QNX:[0123456789]*:*)
 	UNAME_PROCESSOR=`uname -p`
 	if test "$UNAME_PROCESSOR" = "x86"; then
@@ -1193,22 +1244,25 @@
 		UNAME_MACHINE=pc
 	fi
 	echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:QNX:*:4*)
 	echo i386-pc-qnx
-	exit 0 ;;
+	exit ;;
+    NSE-?:NONSTOP_KERNEL:*:*)
+	echo nse-tandem-nsk${UNAME_RELEASE}
+	exit ;;
     NSR-?:NONSTOP_KERNEL:*:*)
 	echo nsr-tandem-nsk${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:NonStop-UX:*:*)
 	echo mips-compaq-nonstopux
-	exit 0 ;;
+	exit ;;
     BS2000:POSIX*:*:*)
 	echo bs2000-siemens-sysv
-	exit 0 ;;
+	exit ;;
     DS/*:UNIX_System_V:*:*)
 	echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:Plan9:*:*)
 	# "uname -m" is not consistent, so use $cputype instead. 386
 	# is converted to i386 for consistency with other x86
@@ -1219,41 +1273,47 @@
 	    UNAME_MACHINE="$cputype"
 	fi
 	echo ${UNAME_MACHINE}-unknown-plan9
-	exit 0 ;;
+	exit ;;
     *:TOPS-10:*:*)
 	echo pdp10-unknown-tops10
-	exit 0 ;;
+	exit ;;
     *:TENEX:*:*)
 	echo pdp10-unknown-tenex
-	exit 0 ;;
+	exit ;;
     KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
 	echo pdp10-dec-tops20
-	exit 0 ;;
+	exit ;;
     XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
 	echo pdp10-xkl-tops20
-	exit 0 ;;
+	exit ;;
     *:TOPS-20:*:*)
 	echo pdp10-unknown-tops20
-	exit 0 ;;
+	exit ;;
     *:ITS:*:*)
 	echo pdp10-unknown-its
-	exit 0 ;;
+	exit ;;
     SEI:*:*:SEIUX)
         echo mips-sei-seiux${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:DragonFly:*:*)
 	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
-	exit 0 ;;
+	exit ;;
     *:*VMS:*:*)
     	UNAME_MACHINE=`(uname -p) 2>/dev/null`
 	case "${UNAME_MACHINE}" in
-	    A*) echo alpha-dec-vms && exit 0 ;;
-	    I*) echo ia64-dec-vms && exit 0 ;;
-	    V*) echo vax-dec-vms && exit 0 ;;
+	    A*) echo alpha-dec-vms ; exit ;;
+	    I*) echo ia64-dec-vms ; exit ;;
+	    V*) echo vax-dec-vms ; exit ;;
 	esac ;;
     *:XENIX:*:SysV)
 	echo i386-pc-xenix
-	exit 0 ;;
+	exit ;;
+    i*86:skyos:*:*)
+	echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
+	exit ;;
+    i*86:rdos:*:*)
+	echo ${UNAME_MACHINE}-pc-rdos
+	exit ;;
 esac
 
 #echo '(No uname command or uname output not recognized.)' 1>&2
@@ -1285,7 +1345,7 @@
 #endif
 
 #if defined (__arm) && defined (__acorn) && defined (__unix)
-  printf ("arm-acorn-riscix"); exit (0);
+  printf ("arm-acorn-riscix\n"); exit (0);
 #endif
 
 #if defined (hp300) && !defined (hpux)
@@ -1374,11 +1434,12 @@
 }
 EOF
 
-$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0
+$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
+	{ echo "$SYSTEM_NAME"; exit; }
 
 # Apollos put the system type in the environment.
 
-test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
+test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
 
 # Convex versions that predate uname can use getsysinfo(1)
 
@@ -1387,22 +1448,22 @@
     case `getsysinfo -f cpu_type` in
     c1*)
 	echo c1-convex-bsd
-	exit 0 ;;
+	exit ;;
     c2*)
 	if getsysinfo -f scalar_acc
 	then echo c32-convex-bsd
 	else echo c2-convex-bsd
 	fi
-	exit 0 ;;
+	exit ;;
     c34*)
 	echo c34-convex-bsd
-	exit 0 ;;
+	exit ;;
     c38*)
 	echo c38-convex-bsd
-	exit 0 ;;
+	exit ;;
     c4*)
 	echo c4-convex-bsd
-	exit 0 ;;
+	exit ;;
     esac
 fi
 
@@ -1413,7 +1474,9 @@
 the operating system you are using. It is advised that you
 download the most up to date version of the config scripts from
 
-    ftp://ftp.gnu.org/pub/gnu/config/
+  http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess
+and
+  http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub
 
 If the version you run ($0) is already up to date, please
 send the following data and any information you think might be

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/config.sub
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/config.sub	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/config.sub	Thu Mar 27 00:48:05 2008
@@ -1,9 +1,10 @@
 #! /bin/sh
 # Configuration validation subroutine script.
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
+#   Inc.
 
-timestamp='2005-04-22'
+timestamp='2007-04-29'
 
 # This file is (in principle) common to ALL GNU software.
 # The presence of a machine in this file suggests that SOME GNU software
@@ -21,14 +22,15 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 02111-1307, USA.
-
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # configuration script generated by Autoconf, you may include it under
 # the same distribution terms that you use for the rest of that program.
 
+
 # Please send patches to <config-patches at gnu.org>.  Submit a context
 # diff and a properly formatted ChangeLog entry.
 #
@@ -83,11 +85,11 @@
 while test $# -gt 0 ; do
   case $1 in
     --time-stamp | --time* | -t )
-       echo "$timestamp" ; exit 0 ;;
+       echo "$timestamp" ; exit ;;
     --version | -v )
-       echo "$version" ; exit 0 ;;
+       echo "$version" ; exit ;;
     --help | --h* | -h )
-       echo "$usage"; exit 0 ;;
+       echo "$usage"; exit ;;
     -- )     # Stop option processing
        shift; break ;;
     - )	# Use stdin as input.
@@ -99,7 +101,7 @@
     *local*)
        # First pass through any local machine types.
        echo $1
-       exit 0;;
+       exit ;;
 
     * )
        break ;;
@@ -118,8 +120,9 @@
 # Here we must recognize all the valid KERNEL-OS combinations.
 maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
 case $maybe_os in
-  nto-qnx* | linux-gnu* | linux-dietlibc | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | \
-  kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
+  nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
+  uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
+  storm-chaos* | os2-emx* | rtmk-nova*)
     os=-$maybe_os
     basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
     ;;
@@ -170,6 +173,10 @@
 	-hiux*)
 		os=-hiuxwe2
 		;;
+	-sco6)
+		os=-sco5v6
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
 	-sco5)
 		os=-sco3.2v5
 		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
@@ -186,6 +193,10 @@
 		# Don't forget version if it is 3.2v4 or newer.
 		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
 		;;
+	-sco5v6*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
 	-sco*)
 		os=-sco3.2v2
 		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
@@ -230,15 +241,16 @@
 	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
 	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
 	| am33_2.0 \
-	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \
+	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
 	| bfin \
 	| c4x | clipper \
 	| d10v | d30v | dlx | dsp16xx \
-	| fr30 | frv \
+	| fido | fr30 | frv \
 	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
 	| i370 | i860 | i960 | ia64 \
 	| ip2k | iq2000 \
-	| m32r | m32rle | m68000 | m68k | m88k | maxq | mcore \
+	| m32c | m32r | m32rle | m68000 | m68k | m88k \
+	| maxq | mb | microblaze | mcore | mep \
 	| mips | mipsbe | mipseb | mipsel | mipsle \
 	| mips16 \
 	| mips64 | mips64el \
@@ -247,6 +259,7 @@
 	| mips64vr4100 | mips64vr4100el \
 	| mips64vr4300 | mips64vr4300el \
 	| mips64vr5000 | mips64vr5000el \
+	| mips64vr5900 | mips64vr5900el \
 	| mipsisa32 | mipsisa32el \
 	| mipsisa32r2 | mipsisa32r2el \
 	| mipsisa64 | mipsisa64el \
@@ -255,21 +268,24 @@
 	| mipsisa64sr71k | mipsisa64sr71kel \
 	| mipstx39 | mipstx39el \
 	| mn10200 | mn10300 \
+	| mt \
 	| msp430 \
+	| nios | nios2 \
 	| ns16k | ns32k \
-	| openrisc | or32 \
+	| or32 \
 	| pdp10 | pdp11 | pj | pjl \
 	| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
 	| pyramid \
-	| sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \
+	| score \
+	| sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
 	| sh64 | sh64le \
-	| sparc | sparc64 | sparc64b | sparc86x | sparclet | sparclite \
-	| sparcv8 | sparcv9 | sparcv9b \
-	| strongarm \
+	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
+	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
+	| spu | strongarm \
 	| tahoe | thumb | tic4x | tic80 | tron \
 	| v850 | v850e \
 	| we32k \
-	| x86 | xscale | xscalee[bl] | xstormy16 | xtensa \
+	| x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
 	| z8k)
 		basic_machine=$basic_machine-unknown
 		;;
@@ -280,6 +296,9 @@
 		;;
 	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
 		;;
+	ms1)
+		basic_machine=mt-unknown
+		;;
 
 	# We use `pc' rather than `unknown'
 	# because (1) that's what they normally are, and
@@ -299,18 +318,18 @@
 	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
 	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
 	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
-	| avr-* \
+	| avr-* | avr32-* \
 	| bfin-* | bs2000-* \
 	| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
 	| clipper-* | craynv-* | cydra-* \
 	| d10v-* | d30v-* | dlx-* \
 	| elxsi-* \
-	| f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \
+	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
 	| h8300-* | h8500-* \
 	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
 	| i*86-* | i860-* | i960-* | ia64-* \
 	| ip2k-* | iq2000-* \
-	| m32r-* | m32rle-* \
+	| m32c-* | m32r-* | m32rle-* \
 	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
 	| m88110-* | m88k-* | maxq-* | mcore-* \
 	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
@@ -321,6 +340,7 @@
 	| mips64vr4100-* | mips64vr4100el-* \
 	| mips64vr4300-* | mips64vr4300el-* \
 	| mips64vr5000-* | mips64vr5000el-* \
+	| mips64vr5900-* | mips64vr5900el-* \
 	| mipsisa32-* | mipsisa32el-* \
 	| mipsisa32r2-* | mipsisa32r2el-* \
 	| mipsisa64-* | mipsisa64el-* \
@@ -329,24 +349,26 @@
 	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
 	| mipstx39-* | mipstx39el-* \
 	| mmix-* \
+	| mt-* \
 	| msp430-* \
+	| nios-* | nios2-* \
 	| none-* | np1-* | ns16k-* | ns32k-* \
 	| orion-* \
 	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
 	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
 	| pyramid-* \
 	| romp-* | rs6000-* \
-	| sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \
+	| sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
 	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
-	| sparc-* | sparc64-* | sparc64b-* | sparc86x-* | sparclet-* \
+	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
 	| sparclite-* \
-	| sparcv8-* | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \
+	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
 	| tahoe-* | thumb-* \
 	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
 	| tron-* \
 	| v850-* | v850e-* | vax-* \
 	| we32k-* \
-	| x86-* | x86_64-* | xps100-* | xscale-* | xscalee[bl]-* \
+	| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
 	| xstormy16-* | xtensa-* \
 	| ymp-* \
 	| z8k-*)
@@ -661,6 +683,10 @@
 		basic_machine=i386-pc
 		os=-mingw32
 		;;
+	mingw32ce)
+		basic_machine=arm-unknown
+		os=-mingw32ce
+		;;
 	miniframe)
 		basic_machine=m68000-convergent
 		;;
@@ -686,6 +712,9 @@
 		basic_machine=i386-pc
 		os=-msdos
 		;;
+	ms1-*)
+		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
+		;;
 	mvs)
 		basic_machine=i370-ibm
 		os=-mvs
@@ -761,9 +790,8 @@
 		basic_machine=hppa1.1-oki
 		os=-proelf
 		;;
-	or32 | or32-*)
+	openrisc | openrisc-*)
 		basic_machine=or32-unknown
-		os=-coff
 		;;
 	os400)
 		basic_machine=powerpc-ibm
@@ -794,6 +822,12 @@
 	pc532 | pc532-*)
 		basic_machine=ns32k-pc532
 		;;
+	pc98)
+		basic_machine=i386-pc
+		;;
+	pc98-*)
+		basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
 	pentium | p5 | k5 | k6 | nexgen | viac3)
 		basic_machine=i586-pc
 		;;
@@ -850,6 +884,10 @@
 		basic_machine=i586-unknown
 		os=-pw32
 		;;
+	rdos)
+		basic_machine=i386-pc
+		os=-rdos
+		;;
 	rom68k)
 		basic_machine=m68k-rom68k
 		os=-coff
@@ -876,6 +914,10 @@
 	sb1el)
 		basic_machine=mipsisa64sb1el-unknown
 		;;
+	sde)
+		basic_machine=mipsisa32-sde
+		os=-elf
+		;;
 	sei)
 		basic_machine=mips-sei
 		os=-seiux
@@ -887,6 +929,9 @@
 		basic_machine=sh-hitachi
 		os=-hms
 		;;
+	sh5el)
+		basic_machine=sh5le-unknown
+		;;
 	sh64)
 		basic_machine=sh64-unknown
 		;;
@@ -1089,13 +1134,10 @@
 	we32k)
 		basic_machine=we32k-att
 		;;
-	sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele)
+	sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele)
 		basic_machine=sh-unknown
 		;;
-	sh64)
-		basic_machine=sh64-unknown
-		;;
-	sparc | sparcv8 | sparcv9 | sparcv9b)
+	sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
 		basic_machine=sparc-sun
 		;;
 	cydra)
@@ -1168,20 +1210,23 @@
 	      | -aos* \
 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
-	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* | -openbsd* \
+	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
+	      | -openbsd* | -solidbsd* \
 	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
 	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
 	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
 	      | -chorusos* | -chorusrdb* \
 	      | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
-	      | -mingw32* | -linux-gnu* | -linux-uclibc* | -uxpv* | -beos* | -mpeix* | -udk* \
+	      | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
+	      | -uxpv* | -beos* | -mpeix* | -udk* \
 	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
 	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
 	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
 	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
 	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
-	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly*)
+	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
+	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops*)
 	# Remember, each alternative MUST END IN *, to match a version number.
 		;;
 	-qnx*)
@@ -1199,7 +1244,7 @@
 		os=`echo $os | sed -e 's|nto|nto-qnx|'`
 		;;
 	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
-	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* \
+	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
 	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
 		;;
 	-mac*)
@@ -1333,6 +1378,12 @@
 # system, and we'll never get to this point.
 
 case $basic_machine in
+        score-*)
+		os=-elf
+		;;
+        spu-*)
+		os=-elf
+		;;
 	*-acorn)
 		os=-riscix1.2
 		;;
@@ -1342,9 +1393,9 @@
 	arm*-semi)
 		os=-aout
 		;;
-    c4x-* | tic4x-*)
-        os=-coff
-        ;;
+        c4x-* | tic4x-*)
+        	os=-coff
+		;;
 	# This must come before the *-dec entry.
 	pdp10-*)
 		os=-tops20
@@ -1370,6 +1421,9 @@
 	m68*-cisco)
 		os=-aout
 		;;
+        mep-*)
+		os=-elf
+		;;
 	mips*-cisco)
 		os=-elf
 		;;
@@ -1388,6 +1442,9 @@
 	*-be)
 		os=-beos
 		;;
+	*-haiku)
+		os=-haiku
+		;;
 	*-ibm)
 		os=-aix
 		;;
@@ -1559,7 +1616,7 @@
 esac
 
 echo $basic_machine$os
-exit 0
+exit
 
 # Local variables:
 # eval: (add-hook 'write-file-hooks 'time-stamp)

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/configure
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/configure	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/configure	Thu Mar 27 00:48:05 2008
@@ -1,27 +1,56 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.59 for libffi 2.1.
+# Generated by GNU Autoconf 2.61 for libffi 3.0.4.
 #
 # Report bugs to <http://gcc.gnu.org/bugs.html>.
 #
-# Copyright (C) 2003 Free Software Foundation, Inc.
+# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
+# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 # This configure script is free software; the Free Software Foundation
 # gives unlimited permission to copy, distribute and modify it.
 ## --------------------- ##
 ## M4sh Initialization.  ##
 ## --------------------- ##
 
-# Be Bourne compatible
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
   emulate sh
   NULLCMD=:
   # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
   # is contrary to our usage.  Disable this feature.
   alias -g '${1+"$@"}'='"$@"'
-elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
-  set -o posix
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in
+  *posix*) set -o posix ;;
+esac
+
+fi
+
+
+
+
+# PATH needs CR
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
 fi
-DUALCASE=1; export DUALCASE # for MKS sh
 
 # Support unset when possible.
 if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
@@ -31,8 +60,43 @@
 fi
 
 
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+as_nl='
+'
+IFS=" ""	$as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+case $0 in
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  { (exit 1); exit 1; }
+fi
+
 # Work around bugs in pre-3.0 UWIN ksh.
-$as_unset ENV MAIL MAILPATH
+for as_var in ENV MAIL MAILPATH
+do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+done
 PS1='$ '
 PS2='> '
 PS4='+ '
@@ -46,18 +110,19 @@
   if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
     eval $as_var=C; export $as_var
   else
-    $as_unset $as_var
+    ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
   fi
 done
 
 # Required to use basename.
-if expr a : '\(a\)' >/dev/null 2>&1; then
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
   as_expr=expr
 else
   as_expr=false
 fi
 
-if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
   as_basename=basename
 else
   as_basename=false
@@ -65,157 +130,388 @@
 
 
 # Name of the executable.
-as_me=`$as_basename "$0" ||
+as_me=`$as_basename -- "$0" ||
 $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
 	 X"$0" : 'X\(//\)$' \| \
-	 X"$0" : 'X\(/\)$' \| \
-	 .     : '\(.\)' 2>/dev/null ||
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
 echo X/"$0" |
-    sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
-  	  /^X\/\(\/\/\)$/{ s//\1/; q; }
-  	  /^X\/\(\/\).*/{ s//\1/; q; }
-  	  s/.*/./; q'`
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
 
+# CDPATH.
+$as_unset CDPATH
 
-# PATH needs CR, and LINENO needs CR and PATH.
-# Avoid depending upon Character Ranges.
-as_cr_letters='abcdefghijklmnopqrstuvwxyz'
-as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-as_cr_Letters=$as_cr_letters$as_cr_LETTERS
-as_cr_digits='0123456789'
-as_cr_alnum=$as_cr_Letters$as_cr_digits
 
-# The user is always right.
-if test "${PATH_SEPARATOR+set}" != set; then
-  echo "#! /bin/sh" >conf$$.sh
-  echo  "exit 0"   >>conf$$.sh
-  chmod +x conf$$.sh
-  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
-    PATH_SEPARATOR=';'
-  else
-    PATH_SEPARATOR=:
-  fi
-  rm -f conf$$.sh
+if test "x$CONFIG_SHELL" = x; then
+  if (eval ":") 2>/dev/null; then
+  as_have_required=yes
+else
+  as_have_required=no
 fi
 
+  if test $as_have_required = yes && 	 (eval ":
+(as_func_return () {
+  (exit \$1)
+}
+as_func_success () {
+  as_func_return 0
+}
+as_func_failure () {
+  as_func_return 1
+}
+as_func_ret_success () {
+  return 0
+}
+as_func_ret_failure () {
+  return 1
+}
 
-  as_lineno_1=$LINENO
-  as_lineno_2=$LINENO
-  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
-  test "x$as_lineno_1" != "x$as_lineno_2" &&
-  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
-  # Find who we are.  Look in the path if we contain no path at all
-  # relative or not.
-  case $0 in
-    *[\\/]* ) as_myself=$0 ;;
-    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
-done
+exitcode=0
+if as_func_success; then
+  :
+else
+  exitcode=1
+  echo as_func_success failed.
+fi
 
-       ;;
-  esac
-  # We did not find ourselves, most probably we were run as `sh COMMAND'
-  # in which case we are not to be found in the path.
-  if test "x$as_myself" = x; then
-    as_myself=$0
-  fi
-  if test ! -f "$as_myself"; then
-    { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2
-   { (exit 1); exit 1; }; }
-  fi
-  case $CONFIG_SHELL in
-  '')
+if as_func_failure; then
+  exitcode=1
+  echo as_func_failure succeeded.
+fi
+
+if as_func_ret_success; then
+  :
+else
+  exitcode=1
+  echo as_func_ret_success failed.
+fi
+
+if as_func_ret_failure; then
+  exitcode=1
+  echo as_func_ret_failure succeeded.
+fi
+
+if ( set x; as_func_ret_success y && test x = \"\$1\" ); then
+  :
+else
+  exitcode=1
+  echo positional parameters were not saved.
+fi
+
+test \$exitcode = 0) || { (exit 1); exit 1; }
+
+(
+  as_lineno_1=\$LINENO
+  as_lineno_2=\$LINENO
+  test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" &&
+  test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; }
+") 2> /dev/null; then
+  :
+else
+  as_candidate_shells=
     as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  for as_base in sh bash ksh sh5; do
-	 case $as_dir in
+  case $as_dir in
 	 /*)
-	   if ("$as_dir/$as_base" -c '
+	   for as_base in sh bash ksh sh5; do
+	     as_candidate_shells="$as_candidate_shells $as_dir/$as_base"
+	   done;;
+       esac
+done
+IFS=$as_save_IFS
+
+
+      for as_shell in $as_candidate_shells $SHELL; do
+	 # Try only shells that exist, to save several forks.
+	 if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+		{ ("$as_shell") 2> /dev/null <<\_ASEOF
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in
+  *posix*) set -o posix ;;
+esac
+
+fi
+
+
+:
+_ASEOF
+}; then
+  CONFIG_SHELL=$as_shell
+	       as_have_required=yes
+	       if { "$as_shell" 2> /dev/null <<\_ASEOF
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in
+  *posix*) set -o posix ;;
+esac
+
+fi
+
+
+:
+(as_func_return () {
+  (exit $1)
+}
+as_func_success () {
+  as_func_return 0
+}
+as_func_failure () {
+  as_func_return 1
+}
+as_func_ret_success () {
+  return 0
+}
+as_func_ret_failure () {
+  return 1
+}
+
+exitcode=0
+if as_func_success; then
+  :
+else
+  exitcode=1
+  echo as_func_success failed.
+fi
+
+if as_func_failure; then
+  exitcode=1
+  echo as_func_failure succeeded.
+fi
+
+if as_func_ret_success; then
+  :
+else
+  exitcode=1
+  echo as_func_ret_success failed.
+fi
+
+if as_func_ret_failure; then
+  exitcode=1
+  echo as_func_ret_failure succeeded.
+fi
+
+if ( set x; as_func_ret_success y && test x = "$1" ); then
+  :
+else
+  exitcode=1
+  echo positional parameters were not saved.
+fi
+
+test $exitcode = 0) || { (exit 1); exit 1; }
+
+(
   as_lineno_1=$LINENO
   as_lineno_2=$LINENO
-  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
   test "x$as_lineno_1" != "x$as_lineno_2" &&
-  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
-	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
-	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
-	     CONFIG_SHELL=$as_dir/$as_base
-	     export CONFIG_SHELL
-	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
-	   fi;;
-	 esac
-       done
-done
-;;
-  esac
+  test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2") || { (exit 1); exit 1; }
+
+_ASEOF
+}; then
+  break
+fi
+
+fi
+
+      done
+
+      if test "x$CONFIG_SHELL" != x; then
+  for as_var in BASH_ENV ENV
+        do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+        done
+        export CONFIG_SHELL
+        exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
+fi
+
+
+    if test $as_have_required = no; then
+  echo This script requires a shell more modern than all the
+      echo shells that I found on your system.  Please install a
+      echo modern shell, or manually run the script under such a
+      echo shell if you do have one.
+      { (exit 1); exit 1; }
+fi
+
+
+fi
+
+fi
+
+
+
+(eval "as_func_return () {
+  (exit \$1)
+}
+as_func_success () {
+  as_func_return 0
+}
+as_func_failure () {
+  as_func_return 1
+}
+as_func_ret_success () {
+  return 0
+}
+as_func_ret_failure () {
+  return 1
+}
+
+exitcode=0
+if as_func_success; then
+  :
+else
+  exitcode=1
+  echo as_func_success failed.
+fi
+
+if as_func_failure; then
+  exitcode=1
+  echo as_func_failure succeeded.
+fi
+
+if as_func_ret_success; then
+  :
+else
+  exitcode=1
+  echo as_func_ret_success failed.
+fi
+
+if as_func_ret_failure; then
+  exitcode=1
+  echo as_func_ret_failure succeeded.
+fi
+
+if ( set x; as_func_ret_success y && test x = \"\$1\" ); then
+  :
+else
+  exitcode=1
+  echo positional parameters were not saved.
+fi
+
+test \$exitcode = 0") || {
+  echo No shell found that supports shell functions.
+  echo Please tell autoconf at gnu.org about your system,
+  echo including any error possibly output before this
+  echo message
+}
+
+
+
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || {
 
   # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
   # uniformly replaced by the line number.  The first 'sed' inserts a
-  # line-number line before each line; the second 'sed' does the real
-  # work.  The second script uses 'N' to pair each line-number line
-  # with the numbered line, and appends trailing '-' during
-  # substitution so that $LINENO is not a special case at line end.
+  # line-number line after each line using $LINENO; the second 'sed'
+  # does the real work.  The second script uses 'N' to pair each
+  # line-number line with the line containing $LINENO, and appends
+  # trailing '-' during substitution so that $LINENO is not a special
+  # case at line end.
   # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
-  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
-  sed '=' <$as_myself |
+  # scripts with optimization help from Paolo Bonzini.  Blame Lee
+  # E. McMahon (1931-1989) for sed's syntax.  :-)
+  sed -n '
+    p
+    /[$]LINENO/=
+  ' <$as_myself |
     sed '
+      s/[$]LINENO.*/&-/
+      t lineno
+      b
+      :lineno
       N
-      s,$,-,
-      : loop
-      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
+      :loop
+      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
       t loop
-      s,-$,,
-      s,^['$as_cr_digits']*\n,,
+      s/-\n.*//
     ' >$as_me.lineno &&
-  chmod +x $as_me.lineno ||
+  chmod +x "$as_me.lineno" ||
     { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
    { (exit 1); exit 1; }; }
 
   # Don't try to exec as it changes $[0], causing all sort of problems
   # (the dirname of $[0] is not the place where we might find the
-  # original and so on.  Autoconf is especially sensible to this).
-  . ./$as_me.lineno
+  # original and so on.  Autoconf is especially sensitive to this).
+  . "./$as_me.lineno"
   # Exit status is that of the last command.
   exit
 }
 
 
-case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
-  *c*,-n*) ECHO_N= ECHO_C='
-' ECHO_T='	' ;;
-  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
-  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in
+-n*)
+  case `echo 'x\c'` in
+  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
+  *)   ECHO_C='\c';;
+  esac;;
+*)
+  ECHO_N='-n';;
 esac
 
-if expr a : '\(a\)' >/dev/null 2>&1; then
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
   as_expr=expr
 else
   as_expr=false
 fi
 
 rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir
+fi
 echo >conf$$.file
 if ln -s conf$$.file conf$$ 2>/dev/null; then
-  # We could just check for DJGPP; but this test a) works b) is more generic
-  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
-  if test -f conf$$.exe; then
-    # Don't use ln at all; we don't have any links
+  as_ln_s='ln -s'
+  # ... but there are two gotchas:
+  # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+  # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+  # In both cases, we have to default to `cp -p'.
+  ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
     as_ln_s='cp -p'
-  else
-    as_ln_s='ln -s'
-  fi
 elif ln conf$$.file conf$$ 2>/dev/null; then
   as_ln_s=ln
 else
   as_ln_s='cp -p'
 fi
-rm -f conf$$ conf$$.exe conf$$.file
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
 
 if mkdir -p . 2>/dev/null; then
   as_mkdir_p=:
@@ -224,7 +520,28 @@
   as_mkdir_p=false
 fi
 
-as_executable_p="test -f"
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+        test -d "$1/.";
+      else
+	case $1 in
+        -*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
 
 # Sed expression to map a string onto a valid CPP name.
 as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
@@ -233,85 +550,414 @@
 as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
 
 
-# IFS
-# We need space, tab and new line, in precisely that order.
-as_nl='
-'
-IFS=" 	$as_nl"
-
-# CDPATH.
-$as_unset CDPATH
 
 
-# Name of the host.
-# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
-# so uname gets run too.
-ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+# Check that we are running under the correct shell.
+SHELL=${CONFIG_SHELL-/bin/sh}
 
-exec 6>&1
+case X$ECHO in
+X*--fallback-echo)
+  # Remove one level of quotation (which was required for Make).
+  ECHO=`echo "$ECHO" | sed 's,\\\\\$\\$0,'$0','`
+  ;;
+esac
 
-#
-# Initializations.
-#
-ac_default_prefix=/usr/local
-ac_config_libobj_dir=.
-cross_compiling=no
-subdirs=
-MFLAGS=
-MAKEFLAGS=
-SHELL=${CONFIG_SHELL-/bin/sh}
+echo=${ECHO-echo}
+if test "X$1" = X--no-reexec; then
+  # Discard the --no-reexec flag, and continue.
+  shift
+elif test "X$1" = X--fallback-echo; then
+  # Avoid inline document here, it may be left over
+  :
+elif test "X`($echo '\t') 2>/dev/null`" = 'X\t' ; then
+  # Yippee, $echo works!
+  :
+else
+  # Restart under the correct shell.
+  exec $SHELL "$0" --no-reexec ${1+"$@"}
+fi
 
-# Maximum number of lines to put in a shell here document.
-# This variable seems obsolete.  It should probably be removed, and
-# only ac_max_sed_lines should be used.
-: ${ac_max_here_lines=38}
+if test "X$1" = X--fallback-echo; then
+  # used as fallback echo
+  shift
+  cat <<EOF
+$*
+EOF
+  exit 0
+fi
 
-# Identity of this package.
-PACKAGE_NAME='libffi'
-PACKAGE_TARNAME='libffi'
-PACKAGE_VERSION='2.1'
-PACKAGE_STRING='libffi 2.1'
-PACKAGE_BUGREPORT='http://gcc.gnu.org/bugs.html'
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+if test -z "$ECHO"; then
+if test "X${echo_test_string+set}" != Xset; then
+# find a string as large as possible, as long as the shell can cope with it
+  for cmd in 'sed 50q "$0"' 'sed 20q "$0"' 'sed 10q "$0"' 'sed 2q "$0"' 'echo test'; do
+    # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
+    if (echo_test_string=`eval $cmd`) 2>/dev/null &&
+       echo_test_string=`eval $cmd` &&
+       (test "X$echo_test_string" = "X$echo_test_string") 2>/dev/null
+    then
+      break
+    fi
+  done
+fi
+
+if test "X`($echo '\t') 2>/dev/null`" = 'X\t' &&
+   echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` &&
+   test "X$echo_testing_string" = "X$echo_test_string"; then
+  :
+else
+  # The Solaris, AIX, and Digital Unix default echo programs unquote
+  # backslashes.  This makes it impossible to quote backslashes using
+  #   echo "$something" | sed 's/\\/\\\\/g'
+  #
+  # So, first we look for a working echo in the user's PATH.
+
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for dir in $PATH /usr/ucb; do
+    IFS="$lt_save_ifs"
+    if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
+       test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
+       echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
+       test "X$echo_testing_string" = "X$echo_test_string"; then
+      echo="$dir/echo"
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+
+  if test "X$echo" = Xecho; then
+    # We didn't find a better echo, so look for alternatives.
+    if test "X`(print -r '\t') 2>/dev/null`" = 'X\t' &&
+       echo_testing_string=`(print -r "$echo_test_string") 2>/dev/null` &&
+       test "X$echo_testing_string" = "X$echo_test_string"; then
+      # This shell has a builtin print -r that does the trick.
+      echo='print -r'
+    elif (test -f /bin/ksh || test -f /bin/ksh$ac_exeext) &&
+	 test "X$CONFIG_SHELL" != X/bin/ksh; then
+      # If we have ksh, try running configure again with it.
+      ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
+      export ORIGINAL_CONFIG_SHELL
+      CONFIG_SHELL=/bin/ksh
+      export CONFIG_SHELL
+      exec $CONFIG_SHELL "$0" --no-reexec ${1+"$@"}
+    else
+      # Try using printf.
+      echo='printf %s\n'
+      if test "X`($echo '\t') 2>/dev/null`" = 'X\t' &&
+	 echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` &&
+	 test "X$echo_testing_string" = "X$echo_test_string"; then
+	# Cool, printf works
+	:
+      elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` &&
+	   test "X$echo_testing_string" = 'X\t' &&
+	   echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+	   test "X$echo_testing_string" = "X$echo_test_string"; then
+	CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
+	export CONFIG_SHELL
+	SHELL="$CONFIG_SHELL"
+	export SHELL
+	echo="$CONFIG_SHELL $0 --fallback-echo"
+      elif echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` &&
+	   test "X$echo_testing_string" = 'X\t' &&
+	   echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+	   test "X$echo_testing_string" = "X$echo_test_string"; then
+	echo="$CONFIG_SHELL $0 --fallback-echo"
+      else
+	# maybe with a smaller string...
+	prev=:
+
+	for cmd in 'echo test' 'sed 2q "$0"' 'sed 10q "$0"' 'sed 20q "$0"' 'sed 50q "$0"'; do
+	  if (test "X$echo_test_string" = "X`eval $cmd`") 2>/dev/null
+	  then
+	    break
+	  fi
+	  prev="$cmd"
+	done
+
+	if test "$prev" != 'sed 50q "$0"'; then
+	  echo_test_string=`eval $prev`
+	  export echo_test_string
+	  exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "$0" ${1+"$@"}
+	else
+	  # Oops.  We lost completely, so just stick with echo.
+	  echo=echo
+	fi
+      fi
+    fi
+  fi
+fi
+fi
+
+# Copy echo and quote the copy suitably for passing to libtool from
+# the Makefile, instead of quoting the original, which is used later.
+ECHO=$echo
+if test "X$ECHO" = "X$CONFIG_SHELL $0 --fallback-echo"; then
+   ECHO="$CONFIG_SHELL \\\$\$0 --fallback-echo"
+fi
+
+
+
+
+tagnames=${tagnames+${tagnames},}CXX
+
+tagnames=${tagnames+${tagnames},}F77
+
+exec 7<&0 </dev/null 6>&1
+
+# Name of the host.
+# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_clean_files=
+ac_config_libobj_dir=.
+LIBOBJS=
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+# Identity of this package.
+PACKAGE_NAME='libffi'
+PACKAGE_TARNAME='libffi'
+PACKAGE_VERSION='3.0.4'
+PACKAGE_STRING='libffi 3.0.4'
+PACKAGE_BUGREPORT='http://gcc.gnu.org/bugs.html'
 
 # Factoring default headers for most tests.
 ac_includes_default="\
 #include <stdio.h>
-#if HAVE_SYS_TYPES_H
+#ifdef HAVE_SYS_TYPES_H
 # include <sys/types.h>
 #endif
-#if HAVE_SYS_STAT_H
+#ifdef HAVE_SYS_STAT_H
 # include <sys/stat.h>
 #endif
-#if STDC_HEADERS
+#ifdef STDC_HEADERS
 # include <stdlib.h>
 # include <stddef.h>
 #else
-# if HAVE_STDLIB_H
+# ifdef HAVE_STDLIB_H
 #  include <stdlib.h>
 # endif
 #endif
-#if HAVE_STRING_H
-# if !STDC_HEADERS && HAVE_MEMORY_H
+#ifdef HAVE_STRING_H
+# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
 #  include <memory.h>
 # endif
 # include <string.h>
 #endif
-#if HAVE_STRINGS_H
+#ifdef HAVE_STRINGS_H
 # include <strings.h>
 #endif
-#if HAVE_INTTYPES_H
+#ifdef HAVE_INTTYPES_H
 # include <inttypes.h>
-#else
-# if HAVE_STDINT_H
-#  include <stdint.h>
-# endif
 #endif
-#if HAVE_UNISTD_H
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif"
 
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os CC ac_ct_CC EXEEXT OBJEXT CFLAGS CPP CPPFLAGS EGREP ALLOCA HAVE_LONG_DOUBLE TARGET TARGETDIR MKTARGET LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL
+PATH_SEPARATOR
+PACKAGE_NAME
+PACKAGE_TARNAME
+PACKAGE_VERSION
+PACKAGE_STRING
+PACKAGE_BUGREPORT
+exec_prefix
+prefix
+program_transform_name
+bindir
+sbindir
+libexecdir
+datarootdir
+datadir
+sysconfdir
+sharedstatedir
+localstatedir
+includedir
+oldincludedir
+docdir
+infodir
+htmldir
+dvidir
+pdfdir
+psdir
+libdir
+localedir
+mandir
+DEFS
+ECHO_C
+ECHO_N
+ECHO_T
+LIBS
+build_alias
+host_alias
+target_alias
+build
+build_cpu
+build_vendor
+build_os
+host
+host_cpu
+host_vendor
+host_os
+target
+target_cpu
+target_vendor
+target_os
+INSTALL_PROGRAM
+INSTALL_SCRIPT
+INSTALL_DATA
+am__isrc
+CYGPATH_W
+PACKAGE
+VERSION
+ACLOCAL
+AUTOCONF
+AUTOMAKE
+AUTOHEADER
+MAKEINFO
+install_sh
+STRIP
+INSTALL_STRIP_PROGRAM
+mkdir_p
+AWK
+SET_MAKE
+am__leading_dot
+AMTAR
+am__tar
+am__untar
+CC
+CFLAGS
+LDFLAGS
+CPPFLAGS
+ac_ct_CC
+EXEEXT
+OBJEXT
+DEPDIR
+am__include
+am__quote
+AMDEP_TRUE
+AMDEP_FALSE
+AMDEPBACKSLASH
+CCDEPMODE
+am__fastdepCC_TRUE
+am__fastdepCC_FALSE
+CCAS
+CCASFLAGS
+CCASDEPMODE
+am__fastdepCCAS_TRUE
+am__fastdepCCAS_FALSE
+SED
+GREP
+EGREP
+LN_S
+ECHO
+AR
+RANLIB
+CPP
+CXX
+CXXFLAGS
+ac_ct_CXX
+CXXDEPMODE
+am__fastdepCXX_TRUE
+am__fastdepCXX_FALSE
+CXXCPP
+F77
+FFLAGS
+ac_ct_F77
+LIBTOOL
+MAINTAINER_MODE_TRUE
+MAINTAINER_MODE_FALSE
+MAINT
+TESTSUBDIR_TRUE
+TESTSUBDIR_FALSE
+AM_RUNTESTFLAGS
+MIPS_TRUE
+MIPS_FALSE
+SPARC_TRUE
+SPARC_FALSE
+X86_TRUE
+X86_FALSE
+X86_FREEBSD_TRUE
+X86_FREEBSD_FALSE
+X86_WIN32_TRUE
+X86_WIN32_FALSE
+X86_DARWIN_TRUE
+X86_DARWIN_FALSE
+ALPHA_TRUE
+ALPHA_FALSE
+IA64_TRUE
+IA64_FALSE
+M32R_TRUE
+M32R_FALSE
+M68K_TRUE
+M68K_FALSE
+POWERPC_TRUE
+POWERPC_FALSE
+POWERPC_AIX_TRUE
+POWERPC_AIX_FALSE
+POWERPC_DARWIN_TRUE
+POWERPC_DARWIN_FALSE
+POWERPC_FREEBSD_TRUE
+POWERPC_FREEBSD_FALSE
+ARM_TRUE
+ARM_FALSE
+LIBFFI_CRIS_TRUE
+LIBFFI_CRIS_FALSE
+FRV_TRUE
+FRV_FALSE
+S390_TRUE
+S390_FALSE
+X86_64_TRUE
+X86_64_FALSE
+SH_TRUE
+SH_FALSE
+SH64_TRUE
+SH64_FALSE
+PA_LINUX_TRUE
+PA_LINUX_FALSE
+PA_HPUX_TRUE
+PA_HPUX_FALSE
+PA64_HPUX_TRUE
+PA64_HPUX_FALSE
+ALLOCA
+HAVE_LONG_DOUBLE
+TARGET
+TARGETDIR
+toolexecdir
+toolexeclibdir
+LIBOBJS
+LTLIBOBJS'
 ac_subst_files=''
+      ac_precious_vars='build_alias
+host_alias
+target_alias
+CCAS
+CCASFLAGS
+CPP
+CPPFLAGS
+CXX
+CXXFLAGS
+LDFLAGS
+LIBS
+CCC
+CXXCPP
+F77
+FFLAGS'
+
 
 # Initialize some variables set by options.
 ac_init_help=
@@ -338,34 +984,48 @@
 # and all the variables that are supposed to be based on exec_prefix
 # by default will actually change.
 # Use braces instead of parens because sh, perl, etc. also accept them.
+# (The list follows the same order as the GNU Coding Standards.)
 bindir='${exec_prefix}/bin'
 sbindir='${exec_prefix}/sbin'
 libexecdir='${exec_prefix}/libexec'
-datadir='${prefix}/share'
+datarootdir='${prefix}/share'
+datadir='${datarootdir}'
 sysconfdir='${prefix}/etc'
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
-libdir='${exec_prefix}/lib'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
-infodir='${prefix}/info'
-mandir='${prefix}/man'
+docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
+infodir='${datarootdir}/info'
+htmldir='${docdir}'
+dvidir='${docdir}'
+pdfdir='${docdir}'
+psdir='${docdir}'
+libdir='${exec_prefix}/lib'
+localedir='${datarootdir}/locale'
+mandir='${datarootdir}/man'
 
 ac_prev=
+ac_dashdash=
 for ac_option
 do
   # If the previous option needs an argument, assign it.
   if test -n "$ac_prev"; then
-    eval "$ac_prev=\$ac_option"
+    eval $ac_prev=\$ac_option
     ac_prev=
     continue
   fi
 
-  ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
+  case $ac_option in
+  *=*)	ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
+  *)	ac_optarg=yes ;;
+  esac
 
   # Accept the important Cygnus configure options, so we can diagnose typos.
 
-  case $ac_option in
+  case $ac_dashdash$ac_option in
+  --)
+    ac_dashdash=yes ;;
 
   -bindir | --bindir | --bindi | --bind | --bin | --bi)
     ac_prev=bindir ;;
@@ -387,33 +1047,45 @@
   --config-cache | -C)
     cache_file=config.cache ;;
 
-  -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
+  -datadir | --datadir | --datadi | --datad)
     ac_prev=datadir ;;
-  -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
-  | --da=*)
+  -datadir=* | --datadir=* | --datadi=* | --datad=*)
     datadir=$ac_optarg ;;
 
+  -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
+  | --dataroo | --dataro | --datar)
+    ac_prev=datarootdir ;;
+  -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
+  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
+    datarootdir=$ac_optarg ;;
+
   -disable-* | --disable-*)
     ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
     # Reject names that are not valid shell variable names.
-    expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+    expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null &&
       { echo "$as_me: error: invalid feature name: $ac_feature" >&2
    { (exit 1); exit 1; }; }
-    ac_feature=`echo $ac_feature | sed 's/-/_/g'`
-    eval "enable_$ac_feature=no" ;;
+    ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'`
+    eval enable_$ac_feature=no ;;
+
+  -docdir | --docdir | --docdi | --doc | --do)
+    ac_prev=docdir ;;
+  -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
+    docdir=$ac_optarg ;;
+
+  -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
+    ac_prev=dvidir ;;
+  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
+    dvidir=$ac_optarg ;;
 
   -enable-* | --enable-*)
     ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
     # Reject names that are not valid shell variable names.
-    expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+    expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null &&
       { echo "$as_me: error: invalid feature name: $ac_feature" >&2
    { (exit 1); exit 1; }; }
-    ac_feature=`echo $ac_feature | sed 's/-/_/g'`
-    case $ac_option in
-      *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
-      *) ac_optarg=yes ;;
-    esac
-    eval "enable_$ac_feature='$ac_optarg'" ;;
+    ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'`
+    eval enable_$ac_feature=\$ac_optarg ;;
 
   -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
   | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
@@ -440,6 +1112,12 @@
   -host=* | --host=* | --hos=* | --ho=*)
     host_alias=$ac_optarg ;;
 
+  -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
+    ac_prev=htmldir ;;
+  -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
+  | --ht=*)
+    htmldir=$ac_optarg ;;
+
   -includedir | --includedir | --includedi | --included | --include \
   | --includ | --inclu | --incl | --inc)
     ac_prev=includedir ;;
@@ -464,13 +1142,16 @@
   | --libexe=* | --libex=* | --libe=*)
     libexecdir=$ac_optarg ;;
 
+  -localedir | --localedir | --localedi | --localed | --locale)
+    ac_prev=localedir ;;
+  -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
+    localedir=$ac_optarg ;;
+
   -localstatedir | --localstatedir | --localstatedi | --localstated \
-  | --localstate | --localstat | --localsta | --localst \
-  | --locals | --local | --loca | --loc | --lo)
+  | --localstate | --localstat | --localsta | --localst | --locals)
     ac_prev=localstatedir ;;
   -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
-  | --localstate=* | --localstat=* | --localsta=* | --localst=* \
-  | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
     localstatedir=$ac_optarg ;;
 
   -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
@@ -535,6 +1216,16 @@
   | --progr-tra=* | --program-tr=* | --program-t=*)
     program_transform_name=$ac_optarg ;;
 
+  -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
+    ac_prev=pdfdir ;;
+  -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
+    pdfdir=$ac_optarg ;;
+
+  -psdir | --psdir | --psdi | --psd | --ps)
+    ac_prev=psdir ;;
+  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
+    psdir=$ac_optarg ;;
+
   -q | -quiet | --quiet | --quie | --qui | --qu | --q \
   | -silent | --silent | --silen | --sile | --sil)
     silent=yes ;;
@@ -587,24 +1278,20 @@
   -with-* | --with-*)
     ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
     # Reject names that are not valid shell variable names.
-    expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+    expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null &&
       { echo "$as_me: error: invalid package name: $ac_package" >&2
    { (exit 1); exit 1; }; }
-    ac_package=`echo $ac_package| sed 's/-/_/g'`
-    case $ac_option in
-      *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
-      *) ac_optarg=yes ;;
-    esac
-    eval "with_$ac_package='$ac_optarg'" ;;
+    ac_package=`echo $ac_package | sed 's/[-.]/_/g'`
+    eval with_$ac_package=\$ac_optarg ;;
 
   -without-* | --without-*)
     ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'`
     # Reject names that are not valid shell variable names.
-    expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+    expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null &&
       { echo "$as_me: error: invalid package name: $ac_package" >&2
    { (exit 1); exit 1; }; }
-    ac_package=`echo $ac_package | sed 's/-/_/g'`
-    eval "with_$ac_package=no" ;;
+    ac_package=`echo $ac_package | sed 's/[-.]/_/g'`
+    eval with_$ac_package=no ;;
 
   --x)
     # Obsolete; use --with-x.
@@ -635,8 +1322,7 @@
     expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
       { echo "$as_me: error: invalid variable name: $ac_envvar" >&2
    { (exit 1); exit 1; }; }
-    ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`
-    eval "$ac_envvar='$ac_optarg'"
+    eval $ac_envvar=\$ac_optarg
     export $ac_envvar ;;
 
   *)
@@ -656,27 +1342,19 @@
    { (exit 1); exit 1; }; }
 fi
 
-# Be sure to have absolute paths.
-for ac_var in exec_prefix prefix
-do
-  eval ac_val=$`echo $ac_var`
-  case $ac_val in
-    [\\/$]* | ?:[\\/]* | NONE | '' ) ;;
-    *)  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
-   { (exit 1); exit 1; }; };;
-  esac
-done
-
-# Be sure to have absolute paths.
-for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \
-	      localstatedir libdir includedir oldincludedir infodir mandir
+# Be sure to have absolute directory names.
+for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
+		datadir sysconfdir sharedstatedir localstatedir includedir \
+		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
+		libdir localedir mandir
 do
-  eval ac_val=$`echo $ac_var`
+  eval ac_val=\$$ac_var
   case $ac_val in
-    [\\/$]* | ?:[\\/]* ) ;;
-    *)  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
-   { (exit 1); exit 1; }; };;
+    [\\/$]* | ?:[\\/]* )  continue;;
+    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
   esac
+  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+   { (exit 1); exit 1; }; }
 done
 
 # There might be people who depend on the old broken behavior: `$host'
@@ -703,62 +1381,76 @@
 test "$silent" = yes && exec 6>/dev/null
 
 
+ac_pwd=`pwd` && test -n "$ac_pwd" &&
+ac_ls_di=`ls -di .` &&
+ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
+  { echo "$as_me: error: Working directory cannot be determined" >&2
+   { (exit 1); exit 1; }; }
+test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
+  { echo "$as_me: error: pwd does not report name of working directory" >&2
+   { (exit 1); exit 1; }; }
+
+
 # Find the source files, if location was not specified.
 if test -z "$srcdir"; then
   ac_srcdir_defaulted=yes
-  # Try the directory containing this script, then its parent.
-  ac_confdir=`(dirname "$0") 2>/dev/null ||
+  # Try the directory containing this script, then the parent directory.
+  ac_confdir=`$as_dirname -- "$0" ||
 $as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
 	 X"$0" : 'X\(//\)[^/]' \| \
 	 X"$0" : 'X\(//\)$' \| \
-	 X"$0" : 'X\(/\)' \| \
-	 .     : '\(.\)' 2>/dev/null ||
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
 echo X"$0" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
-  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
-  	  /^X\(\/\/\)$/{ s//\1/; q; }
-  	  /^X\(\/\).*/{ s//\1/; q; }
-  	  s/.*/./; q'`
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
   srcdir=$ac_confdir
-  if test ! -r $srcdir/$ac_unique_file; then
+  if test ! -r "$srcdir/$ac_unique_file"; then
     srcdir=..
   fi
 else
   ac_srcdir_defaulted=no
 fi
-if test ! -r $srcdir/$ac_unique_file; then
-  if test "$ac_srcdir_defaulted" = yes; then
-    { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2
-   { (exit 1); exit 1; }; }
-  else
-    { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2
+if test ! -r "$srcdir/$ac_unique_file"; then
+  test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
+  { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2
    { (exit 1); exit 1; }; }
-  fi
 fi
-(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null ||
-  { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2
-   { (exit 1); exit 1; }; }
-srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'`
-ac_env_build_alias_set=${build_alias+set}
-ac_env_build_alias_value=$build_alias
-ac_cv_env_build_alias_set=${build_alias+set}
-ac_cv_env_build_alias_value=$build_alias
-ac_env_host_alias_set=${host_alias+set}
-ac_env_host_alias_value=$host_alias
-ac_cv_env_host_alias_set=${host_alias+set}
-ac_cv_env_host_alias_value=$host_alias
-ac_env_target_alias_set=${target_alias+set}
-ac_env_target_alias_value=$target_alias
-ac_cv_env_target_alias_set=${target_alias+set}
-ac_cv_env_target_alias_value=$target_alias
-ac_env_CPP_set=${CPP+set}
-ac_env_CPP_value=$CPP
-ac_cv_env_CPP_set=${CPP+set}
-ac_cv_env_CPP_value=$CPP
-ac_env_CPPFLAGS_set=${CPPFLAGS+set}
-ac_env_CPPFLAGS_value=$CPPFLAGS
-ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set}
-ac_cv_env_CPPFLAGS_value=$CPPFLAGS
+ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
+ac_abs_confdir=`(
+	cd "$srcdir" && test -r "./$ac_unique_file" || { echo "$as_me: error: $ac_msg" >&2
+   { (exit 1); exit 1; }; }
+	pwd)`
+# When building in place, set srcdir=.
+if test "$ac_abs_confdir" = "$ac_pwd"; then
+  srcdir=.
+fi
+# Remove unnecessary trailing slashes from srcdir.
+# Double slashes in file names in object file debugging info
+# mess up M-x gdb in Emacs.
+case $srcdir in
+*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
+esac
+for ac_var in $ac_precious_vars; do
+  eval ac_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_env_${ac_var}_value=\$${ac_var}
+  eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_cv_env_${ac_var}_value=\$${ac_var}
+done
 
 #
 # Report the --help message.
@@ -767,7 +1459,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures libffi 2.1 to adapt to many kinds of systems.
+\`configure' configures libffi 3.0.4 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -787,9 +1479,6 @@
   -n, --no-create         do not create output files
       --srcdir=DIR        find the sources in DIR [configure dir or \`..']
 
-_ACEOF
-
-  cat <<_ACEOF
 Installation directories:
   --prefix=PREFIX         install architecture-independent files in PREFIX
 			  [$ac_default_prefix]
@@ -807,19 +1496,31 @@
   --bindir=DIR           user executables [EPREFIX/bin]
   --sbindir=DIR          system admin executables [EPREFIX/sbin]
   --libexecdir=DIR       program executables [EPREFIX/libexec]
-  --datadir=DIR          read-only architecture-independent data [PREFIX/share]
   --sysconfdir=DIR       read-only single-machine data [PREFIX/etc]
   --sharedstatedir=DIR   modifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR    modifiable single-machine data [PREFIX/var]
   --libdir=DIR           object code libraries [EPREFIX/lib]
   --includedir=DIR       C header files [PREFIX/include]
   --oldincludedir=DIR    C header files for non-gcc [/usr/include]
-  --infodir=DIR          info documentation [PREFIX/info]
-  --mandir=DIR           man documentation [PREFIX/man]
+  --datarootdir=DIR      read-only arch.-independent data root [PREFIX/share]
+  --datadir=DIR          read-only architecture-independent data [DATAROOTDIR]
+  --infodir=DIR          info documentation [DATAROOTDIR/info]
+  --localedir=DIR        locale-dependent data [DATAROOTDIR/locale]
+  --mandir=DIR           man documentation [DATAROOTDIR/man]
+  --docdir=DIR           documentation root [DATAROOTDIR/doc/libffi]
+  --htmldir=DIR          html documentation [DOCDIR]
+  --dvidir=DIR           dvi documentation [DOCDIR]
+  --pdfdir=DIR           pdf documentation [DOCDIR]
+  --psdir=DIR            ps documentation [DOCDIR]
 _ACEOF
 
   cat <<\_ACEOF
 
+Program names:
+  --program-prefix=PREFIX            prepend PREFIX to installed program names
+  --program-suffix=SUFFIX            append SUFFIX to installed program names
+  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names
+
 System types:
   --build=BUILD     configure for building on BUILD [guessed]
   --host=HOST       cross-compile to build programs to run on HOST [BUILD]
@@ -829,138 +1530,137 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of libffi 2.1:";;
+     short | recursive ) echo "Configuration of libffi 3.0.4:";;
    esac
   cat <<\_ACEOF
 
+Optional Features:
+  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
+  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --disable-dependency-tracking  speeds up one-time build
+  --enable-dependency-tracking   do not reject slow dependency extractors
+  --enable-shared[=PKGS]  build shared libraries [default=yes]
+  --enable-static[=PKGS]  build static libraries [default=yes]
+  --enable-fast-install[=PKGS]
+                          optimize for fast installation [default=yes]
+  --disable-libtool-lock  avoid locking (might break parallel builds)
+  --enable-maintainer-mode  enable make rules and dependencies not useful
+			  (and sometimes confusing) to the casual installer
+  --enable-debug          debugging mode
+  --disable-structs       omit code for struct support
+  --disable-raw-api       make the raw api unavailable
+  --enable-purify-safety  purify-safe mode
+
+Optional Packages:
+  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
+  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+  --with-pic              try to use only PIC/non-PIC objects [default=use
+                          both]
+  --with-tags[=TAGS]      include additional configurations [automatic]
+
 Some influential environment variables:
   CC          C compiler command
   CFLAGS      C compiler flags
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
               nonstandard directory <lib dir>
-  CPPFLAGS    C/C++ preprocessor flags, e.g. -I<include dir> if you have
-              headers in a nonstandard directory <include dir>
+  LIBS        libraries to pass to the linker, e.g. -l<library>
+  CPPFLAGS    C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
+              you have headers in a nonstandard directory <include dir>
+  CCAS        assembler compiler command (defaults to CC)
+  CCASFLAGS   assembler compiler flags (defaults to CFLAGS)
   CPP         C preprocessor
+  CXX         C++ compiler command
+  CXXFLAGS    C++ compiler flags
+  CXXCPP      C++ preprocessor
+  F77         Fortran 77 compiler command
+  FFLAGS      Fortran 77 compiler flags
 
 Use these variables to override the choices made by `configure' or to help
 it to find libraries and programs with nonstandard names/locations.
 
 Report bugs to <http://gcc.gnu.org/bugs.html>.
 _ACEOF
+ac_status=$?
 fi
 
 if test "$ac_init_help" = "recursive"; then
   # If there are subdirs, report their specific --help.
-  ac_popdir=`pwd`
   for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
-    test -d $ac_dir || continue
+    test -d "$ac_dir" || continue
     ac_builddir=.
 
-if test "$ac_dir" != .; then
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
   ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
-  # A "../" for each directory in $ac_dir_suffix.
-  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
-else
-  ac_dir_suffix= ac_top_builddir=
-fi
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
 
 case $srcdir in
-  .)  # No --srcdir option.  We are building in place.
+  .)  # We are building in place.
     ac_srcdir=.
-    if test -z "$ac_top_builddir"; then
-       ac_top_srcdir=.
-    else
-       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
-    fi ;;
-  [\\/]* | ?:[\\/]* )  # Absolute path.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
     ac_srcdir=$srcdir$ac_dir_suffix;
-    ac_top_srcdir=$srcdir ;;
-  *) # Relative path.
-    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
-    ac_top_srcdir=$ac_top_builddir$srcdir ;;
-esac
-
-# Do not use `cd foo && pwd` to compute absolute paths, because
-# the directories may not exist.
-case `pwd` in
-.) ac_abs_builddir="$ac_dir";;
-*)
-  case "$ac_dir" in
-  .) ac_abs_builddir=`pwd`;;
-  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
-  *) ac_abs_builddir=`pwd`/"$ac_dir";;
-  esac;;
-esac
-case $ac_abs_builddir in
-.) ac_abs_top_builddir=${ac_top_builddir}.;;
-*)
-  case ${ac_top_builddir}. in
-  .) ac_abs_top_builddir=$ac_abs_builddir;;
-  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
-  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
-  esac;;
-esac
-case $ac_abs_builddir in
-.) ac_abs_srcdir=$ac_srcdir;;
-*)
-  case $ac_srcdir in
-  .) ac_abs_srcdir=$ac_abs_builddir;;
-  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
-  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
-  esac;;
-esac
-case $ac_abs_builddir in
-.) ac_abs_top_srcdir=$ac_top_srcdir;;
-*)
-  case $ac_top_srcdir in
-  .) ac_abs_top_srcdir=$ac_abs_builddir;;
-  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
-  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
-  esac;;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
 esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
 
-    cd $ac_dir
-    # Check for guested configure; otherwise get Cygnus style configure.
-    if test -f $ac_srcdir/configure.gnu; then
-      echo
-      $SHELL $ac_srcdir/configure.gnu  --help=recursive
-    elif test -f $ac_srcdir/configure; then
-      echo
-      $SHELL $ac_srcdir/configure  --help=recursive
-    elif test -f $ac_srcdir/configure.ac ||
-	   test -f $ac_srcdir/configure.in; then
-      echo
-      $ac_configure --help
+    cd "$ac_dir" || { ac_status=$?; continue; }
+    # Check for guested configure.
+    if test -f "$ac_srcdir/configure.gnu"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure.gnu" --help=recursive
+    elif test -f "$ac_srcdir/configure"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure" --help=recursive
     else
       echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
-    fi
-    cd $ac_popdir
+    fi || ac_status=$?
+    cd "$ac_pwd" || { ac_status=$?; break; }
   done
 fi
 
-test -n "$ac_init_help" && exit 0
+test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-libffi configure 2.1
-generated by GNU Autoconf 2.59
+libffi configure 3.0.4
+generated by GNU Autoconf 2.61
 
-Copyright (C) 2003 Free Software Foundation, Inc.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
+2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 This configure script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it.
 _ACEOF
-  exit 0
+  exit
 fi
-exec 5>config.log
-cat >&5 <<_ACEOF
+cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by libffi $as_me 2.1, which was
-generated by GNU Autoconf 2.59.  Invocation command line was
+It was created by libffi $as_me 3.0.4, which was
+generated by GNU Autoconf 2.61.  Invocation command line was
 
   $ $0 $@
 
 _ACEOF
+exec 5>>config.log
 {
 cat <<_ASUNAME
 ## --------- ##
@@ -979,7 +1679,7 @@
 /bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
 /usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
 /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
-hostinfo               = `(hostinfo) 2>/dev/null               || echo unknown`
+/usr/bin/hostinfo      = `(/usr/bin/hostinfo) 2>/dev/null      || echo unknown`
 /bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
 /usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
 /bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
@@ -993,6 +1693,7 @@
   test -z "$as_dir" && as_dir=.
   echo "PATH: $as_dir"
 done
+IFS=$as_save_IFS
 
 } >&5
 
@@ -1014,7 +1715,6 @@
 ac_configure_args=
 ac_configure_args0=
 ac_configure_args1=
-ac_sep=
 ac_must_keep_next=false
 for ac_pass in 1 2
 do
@@ -1025,7 +1725,7 @@
     -q | -quiet | --quiet | --quie | --qui | --qu | --q \
     | -silent | --silent | --silen | --sile | --sil)
       continue ;;
-    *" "*|*"	"*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
+    *\'*)
       ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
     esac
     case $ac_pass in
@@ -1047,9 +1747,7 @@
 	  -* ) ac_must_keep_next=true ;;
 	esac
       fi
-      ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'"
-      # Get rid of the leading space.
-      ac_sep=" "
+      ac_configure_args="$ac_configure_args '$ac_arg'"
       ;;
     esac
   done
@@ -1060,8 +1758,8 @@
 # When interrupted or exit'd, cleanup temporary files, and complete
 # config.log.  We remove comments because anyway the quotes in there
 # would cause problems or look ugly.
-# WARNING: Be sure not to use single quotes in there, as some shells,
-# such as our DU 5.0 friend, will then `close' the trap.
+# WARNING: Use '\'' to represent an apostrophe within the trap.
+# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
 trap 'exit_status=$?
   # Save into config.log some information that might help in debugging.
   {
@@ -1074,20 +1772,34 @@
 _ASBOX
     echo
     # The following way of writing the cache mishandles newlines in values,
-{
+(
+  for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5
+echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      *) $as_unset $ac_var ;;
+      esac ;;
+    esac
+  done
   (set) 2>&1 |
-    case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in
-    *ac_space=\ *)
+    case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
       sed -n \
-	"s/'"'"'/'"'"'\\\\'"'"''"'"'/g;
-	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p"
-      ;;
+	"s/'\''/'\''\\\\'\'''\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
+      ;; #(
     *)
-      sed -n \
-	"s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
       ;;
-    esac;
-}
+    esac |
+    sort
+)
     echo
 
     cat <<\_ASBOX
@@ -1098,22 +1810,28 @@
     echo
     for ac_var in $ac_subst_vars
     do
-      eval ac_val=$`echo $ac_var`
-      echo "$ac_var='"'"'$ac_val'"'"'"
+      eval ac_val=\$$ac_var
+      case $ac_val in
+      *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+      esac
+      echo "$ac_var='\''$ac_val'\''"
     done | sort
     echo
 
     if test -n "$ac_subst_files"; then
       cat <<\_ASBOX
-## ------------- ##
-## Output files. ##
-## ------------- ##
+## ------------------- ##
+## File substitutions. ##
+## ------------------- ##
 _ASBOX
       echo
       for ac_var in $ac_subst_files
       do
-	eval ac_val=$`echo $ac_var`
-	echo "$ac_var='"'"'$ac_val'"'"'"
+	eval ac_val=\$$ac_var
+	case $ac_val in
+	*\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+	esac
+	echo "$ac_var='\''$ac_val'\''"
       done | sort
       echo
     fi
@@ -1125,26 +1843,24 @@
 ## ----------- ##
 _ASBOX
       echo
-      sed "/^$/d" confdefs.h | sort
+      cat confdefs.h
       echo
     fi
     test "$ac_signal" != 0 &&
       echo "$as_me: caught signal $ac_signal"
     echo "$as_me: exit $exit_status"
   } >&5
-  rm -f core *.core &&
-  rm -rf conftest* confdefs* conf$$* $ac_clean_files &&
+  rm -f core *.core core.conftest.* &&
+    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
     exit $exit_status
-     ' 0
+' 0
 for ac_signal in 1 2 13 15; do
   trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal
 done
 ac_signal=0
 
 # confdefs.h avoids OS command line length limits that DEFS can exceed.
-rm -rf conftest* confdefs.h
-# AIX cpp loses on an empty file, so make sure it contains at least a newline.
-echo >confdefs.h
+rm -f -r conftest* confdefs.h
 
 # Predefined preprocessor variables.
 
@@ -1175,14 +1891,17 @@
 
 # Let the site file select an alternate cache file if it wants to.
 # Prefer explicitly selected file to automatically selected ones.
-if test -z "$CONFIG_SITE"; then
-  if test "x$prefix" != xNONE; then
-    CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
-  else
-    CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
-  fi
+if test -n "$CONFIG_SITE"; then
+  set x "$CONFIG_SITE"
+elif test "x$prefix" != xNONE; then
+  set x "$prefix/share/config.site" "$prefix/etc/config.site"
+else
+  set x "$ac_default_prefix/share/config.site" \
+	"$ac_default_prefix/etc/config.site"
 fi
-for ac_site_file in $CONFIG_SITE; do
+shift
+for ac_site_file
+do
   if test -r "$ac_site_file"; then
     { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5
 echo "$as_me: loading site script $ac_site_file" >&6;}
@@ -1198,8 +1917,8 @@
     { echo "$as_me:$LINENO: loading cache $cache_file" >&5
 echo "$as_me: loading cache $cache_file" >&6;}
     case $cache_file in
-      [\\/]* | ?:[\\/]* ) . $cache_file;;
-      *)                      . ./$cache_file;;
+      [\\/]* | ?:[\\/]* ) . "$cache_file";;
+      *)                      . "./$cache_file";;
     esac
   fi
 else
@@ -1211,12 +1930,11 @@
 # Check that the precious variables saved in the cache have kept the same
 # value.
 ac_cache_corrupted=false
-for ac_var in `(set) 2>&1 |
-	       sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do
+for ac_var in $ac_precious_vars; do
   eval ac_old_set=\$ac_cv_env_${ac_var}_set
   eval ac_new_set=\$ac_env_${ac_var}_set
-  eval ac_old_val="\$ac_cv_env_${ac_var}_value"
-  eval ac_new_val="\$ac_env_${ac_var}_value"
+  eval ac_old_val=\$ac_cv_env_${ac_var}_value
+  eval ac_new_val=\$ac_env_${ac_var}_value
   case $ac_old_set,$ac_new_set in
     set,)
       { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
@@ -1241,8 +1959,7 @@
   # Pass precious variables to config.status.
   if test "$ac_new_set" = set; then
     case $ac_new_val in
-    *" "*|*"	"*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
-      ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *\'*) ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
     *) ac_arg=$ac_var=$ac_new_val ;;
     esac
     case " $ac_configure_args " in
@@ -1259,12 +1976,6 @@
    { (exit 1); exit 1; }; }
 fi
 
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
 
 
 
@@ -1289,110 +2000,165 @@
 
 
 
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
-          ac_config_headers="$ac_config_headers fficonfig.h"
+ac_config_headers="$ac_config_headers fficonfig.h"
 
 
 ac_aux_dir=
-for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
-  if test -f $ac_dir/install-sh; then
+for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
+  if test -f "$ac_dir/install-sh"; then
     ac_aux_dir=$ac_dir
     ac_install_sh="$ac_aux_dir/install-sh -c"
     break
-  elif test -f $ac_dir/install.sh; then
+  elif test -f "$ac_dir/install.sh"; then
     ac_aux_dir=$ac_dir
     ac_install_sh="$ac_aux_dir/install.sh -c"
     break
-  elif test -f $ac_dir/shtool; then
+  elif test -f "$ac_dir/shtool"; then
     ac_aux_dir=$ac_dir
     ac_install_sh="$ac_aux_dir/shtool install -c"
     break
   fi
 done
 if test -z "$ac_aux_dir"; then
-  { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&5
-echo "$as_me: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&2;}
+  { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" >&5
+echo "$as_me: error: cannot find install-sh or install.sh in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" >&2;}
    { (exit 1); exit 1; }; }
 fi
-ac_config_guess="$SHELL $ac_aux_dir/config.guess"
-ac_config_sub="$SHELL $ac_aux_dir/config.sub"
-ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure.
+
+# These three variables are undocumented and unsupported,
+# and are intended to be withdrawn in a future Autoconf release.
+# They can cause serious problems if a builder's source tree is in a directory
+# whose full name contains unusual characters.
+ac_config_guess="$SHELL $ac_aux_dir/config.guess"  # Please don't use this var.
+ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
+ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
+
 
 # Make sure we can run config.sub.
-$ac_config_sub sun4 >/dev/null 2>&1 ||
-  { { echo "$as_me:$LINENO: error: cannot run $ac_config_sub" >&5
-echo "$as_me: error: cannot run $ac_config_sub" >&2;}
+$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
+  { { echo "$as_me:$LINENO: error: cannot run $SHELL $ac_aux_dir/config.sub" >&5
+echo "$as_me: error: cannot run $SHELL $ac_aux_dir/config.sub" >&2;}
    { (exit 1); exit 1; }; }
 
-echo "$as_me:$LINENO: checking build system type" >&5
-echo $ECHO_N "checking build system type... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking build system type" >&5
+echo $ECHO_N "checking build system type... $ECHO_C" >&6; }
 if test "${ac_cv_build+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  ac_cv_build_alias=$build_alias
-test -z "$ac_cv_build_alias" &&
-  ac_cv_build_alias=`$ac_config_guess`
-test -z "$ac_cv_build_alias" &&
+  ac_build_alias=$build_alias
+test "x$ac_build_alias" = x &&
+  ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
+test "x$ac_build_alias" = x &&
   { { echo "$as_me:$LINENO: error: cannot guess build type; you must specify one" >&5
 echo "$as_me: error: cannot guess build type; you must specify one" >&2;}
    { (exit 1); exit 1; }; }
-ac_cv_build=`$ac_config_sub $ac_cv_build_alias` ||
-  { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_build_alias failed" >&5
-echo "$as_me: error: $ac_config_sub $ac_cv_build_alias failed" >&2;}
+ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` ||
+  { { echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $ac_build_alias failed" >&5
+echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $ac_build_alias failed" >&2;}
    { (exit 1); exit 1; }; }
 
 fi
-echo "$as_me:$LINENO: result: $ac_cv_build" >&5
-echo "${ECHO_T}$ac_cv_build" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_build" >&5
+echo "${ECHO_T}$ac_cv_build" >&6; }
+case $ac_cv_build in
+*-*-*) ;;
+*) { { echo "$as_me:$LINENO: error: invalid value of canonical build" >&5
+echo "$as_me: error: invalid value of canonical build" >&2;}
+   { (exit 1); exit 1; }; };;
+esac
 build=$ac_cv_build
-build_cpu=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
-build_vendor=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
-build_os=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_build
+shift
+build_cpu=$1
+build_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+build_os=$*
+IFS=$ac_save_IFS
+case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac
 
 
-echo "$as_me:$LINENO: checking host system type" >&5
-echo $ECHO_N "checking host system type... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking host system type" >&5
+echo $ECHO_N "checking host system type... $ECHO_C" >&6; }
 if test "${ac_cv_host+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  ac_cv_host_alias=$host_alias
-test -z "$ac_cv_host_alias" &&
-  ac_cv_host_alias=$ac_cv_build_alias
-ac_cv_host=`$ac_config_sub $ac_cv_host_alias` ||
-  { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_host_alias failed" >&5
-echo "$as_me: error: $ac_config_sub $ac_cv_host_alias failed" >&2;}
+  if test "x$host_alias" = x; then
+  ac_cv_host=$ac_cv_build
+else
+  ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
+    { { echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $host_alias failed" >&5
+echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $host_alias failed" >&2;}
    { (exit 1); exit 1; }; }
+fi
 
 fi
-echo "$as_me:$LINENO: result: $ac_cv_host" >&5
-echo "${ECHO_T}$ac_cv_host" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_host" >&5
+echo "${ECHO_T}$ac_cv_host" >&6; }
+case $ac_cv_host in
+*-*-*) ;;
+*) { { echo "$as_me:$LINENO: error: invalid value of canonical host" >&5
+echo "$as_me: error: invalid value of canonical host" >&2;}
+   { (exit 1); exit 1; }; };;
+esac
 host=$ac_cv_host
-host_cpu=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
-host_vendor=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
-host_os=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_host
+shift
+host_cpu=$1
+host_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+host_os=$*
+IFS=$ac_save_IFS
+case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
 
 
-echo "$as_me:$LINENO: checking target system type" >&5
-echo $ECHO_N "checking target system type... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking target system type" >&5
+echo $ECHO_N "checking target system type... $ECHO_C" >&6; }
 if test "${ac_cv_target+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  ac_cv_target_alias=$target_alias
-test "x$ac_cv_target_alias" = "x" &&
-  ac_cv_target_alias=$ac_cv_host_alias
-ac_cv_target=`$ac_config_sub $ac_cv_target_alias` ||
-  { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_target_alias failed" >&5
-echo "$as_me: error: $ac_config_sub $ac_cv_target_alias failed" >&2;}
+  if test "x$target_alias" = x; then
+  ac_cv_target=$ac_cv_host
+else
+  ac_cv_target=`$SHELL "$ac_aux_dir/config.sub" $target_alias` ||
+    { { echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $target_alias failed" >&5
+echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $target_alias failed" >&2;}
    { (exit 1); exit 1; }; }
+fi
 
 fi
-echo "$as_me:$LINENO: result: $ac_cv_target" >&5
-echo "${ECHO_T}$ac_cv_target" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_target" >&5
+echo "${ECHO_T}$ac_cv_target" >&6; }
+case $ac_cv_target in
+*-*-*) ;;
+*) { { echo "$as_me:$LINENO: error: invalid value of canonical target" >&5
+echo "$as_me: error: invalid value of canonical target" >&2;}
+   { (exit 1); exit 1; }; };;
+esac
 target=$ac_cv_target
-target_cpu=`echo $ac_cv_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
-target_vendor=`echo $ac_cv_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
-target_os=`echo $ac_cv_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_target
+shift
+target_cpu=$1
+target_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+target_os=$*
+IFS=$ac_save_IFS
+case $target_os in *\ *) target_os=`echo "$target_os" | sed 's/ /-/g'`;; esac
 
 
 # The aliases save the names the user supplied, while $host etc.
@@ -1403,61 +2169,220 @@
   program_prefix=${target_alias}-
 target_alias=${target_alias-$host_alias}
 
+. ${srcdir}/configure.host
 
+am__api_version='1.10'
 
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-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 -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
-set dummy ${ac_tool_prefix}gcc; ac_word=$2
-echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
-if test "${ac_cv_prog_CC+set}" = set; then
+# Find a good install program.  We prefer a C program (faster),
+# so one script is as good as another.  But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+{ echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5
+echo $ECHO_N "checking for a BSD-compatible install... $ECHO_C" >&6; }
+if test -z "$INSTALL"; then
+if test "${ac_cv_path_install+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  if test -n "$CC"; then
-  ac_cv_prog_CC="$CC" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  for ac_exec_ext in '' $ac_executable_extensions; do
-  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_CC="${ac_tool_prefix}gcc"
-    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
+  # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in
+  ./ | .// | /cC/* | \
+  /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+  ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \
+  /usr/ucb/* ) ;;
+  *)
+    # OSF1 and SCO ODT 3.0 have their own names for install.
+    # Don't use installbsd from OSF since it installs stuff as root
+    # by default.
+    for ac_prog in ginstall scoinst install; do
+      for ac_exec_ext in '' $ac_executable_extensions; do
+	if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then
+	  if test $ac_prog = install &&
+	    grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # AIX install.  It has an incompatible calling convention.
+	    :
+	  elif test $ac_prog = install &&
+	    grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # program-specific install script used by HP pwplus--don't use.
+	    :
+	  else
+	    ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+	    break 3
+	  fi
+	fi
+      done
+    done
+    ;;
+esac
 done
+IFS=$as_save_IFS
+
 
 fi
+  if test "${ac_cv_path_install+set}" = set; then
+    INSTALL=$ac_cv_path_install
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for INSTALL within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    INSTALL=$ac_install_sh
+  fi
 fi
-CC=$ac_cv_prog_CC
-if test -n "$CC"; then
-  echo "$as_me:$LINENO: result: $CC" >&5
-echo "${ECHO_T}$CC" >&6
+{ echo "$as_me:$LINENO: result: $INSTALL" >&5
+echo "${ECHO_T}$INSTALL" >&6; }
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+{ echo "$as_me:$LINENO: checking whether build environment is sane" >&5
+echo $ECHO_N "checking whether build environment is sane... $ECHO_C" >&6; }
+# Just in case
+sleep 1
+echo timestamp > conftest.file
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null`
+   if test "$*" = "X"; then
+      # -L didn't work.
+      set X `ls -t $srcdir/configure conftest.file`
+   fi
+   rm -f conftest.file
+   if test "$*" != "X $srcdir/configure conftest.file" \
+      && test "$*" != "X conftest.file $srcdir/configure"; then
+
+      # If neither matched, then we have a broken ls.  This can happen
+      # if, for instance, CONFIG_SHELL is bash and it inherits a
+      # broken ls alias from the environment.  This has actually
+      # happened.  Such a system could not be considered "sane".
+      { { echo "$as_me:$LINENO: error: ls -t appears to fail.  Make sure there is not a broken
+alias in your environment" >&5
+echo "$as_me: error: ls -t appears to fail.  Make sure there is not a broken
+alias in your environment" >&2;}
+   { (exit 1); exit 1; }; }
+   fi
+
+   test "$2" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   { { echo "$as_me:$LINENO: error: newly created file is older than distributed files!
+Check your system clock" >&5
+echo "$as_me: error: newly created file is older than distributed files!
+Check your system clock" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+{ echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+test "$program_prefix" != NONE &&
+  program_transform_name="s&^&$program_prefix&;$program_transform_name"
+# Use a double $ so make ignores it.
+test "$program_suffix" != NONE &&
+  program_transform_name="s&\$&$program_suffix&;$program_transform_name"
+# Double any \ or $.  echo might interpret backslashes.
+# By default was `s,x,x', remove it if useless.
+cat <<\_ACEOF >conftest.sed
+s/[\\$]/&&/g;s/;s,x,x,$//
+_ACEOF
+program_transform_name=`echo $program_transform_name | sed -f conftest.sed`
+rm -f conftest.sed
+
+# expand $ac_aux_dir to an absolute path
+am_aux_dir=`cd $ac_aux_dir && pwd`
+
+test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing"
+# Use eval to expand $SHELL
+if eval "$MISSING --run true"; then
+  am_missing_run="$MISSING --run "
+else
+  am_missing_run=
+  { echo "$as_me:$LINENO: WARNING: \`missing' script is too old or missing" >&5
+echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;}
+fi
+
+{ echo "$as_me:$LINENO: checking for a thread-safe mkdir -p" >&5
+echo $ECHO_N "checking for a thread-safe mkdir -p... $ECHO_C" >&6; }
+if test -z "$MKDIR_P"; then
+  if test "${ac_cv_path_mkdir+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_prog in mkdir gmkdir; do
+	 for ac_exec_ext in '' $ac_executable_extensions; do
+	   { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue
+	   case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #(
+	     'mkdir (GNU coreutils) '* | \
+	     'mkdir (coreutils) '* | \
+	     'mkdir (fileutils) '4.1*)
+	       ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext
+	       break 3;;
+	   esac
+	 done
+       done
+done
+IFS=$as_save_IFS
+
 fi
 
+  if test "${ac_cv_path_mkdir+set}" = set; then
+    MKDIR_P="$ac_cv_path_mkdir -p"
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for MKDIR_P within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    test -d ./--version && rmdir ./--version
+    MKDIR_P="$ac_install_sh -d"
+  fi
 fi
-if test -z "$ac_cv_prog_CC"; then
-  ac_ct_CC=$CC
-  # Extract the first word of "gcc", so it can be a program name with args.
-set dummy gcc; ac_word=$2
-echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
-if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+{ echo "$as_me:$LINENO: result: $MKDIR_P" >&5
+echo "${ECHO_T}$MKDIR_P" >&6; }
+
+mkdir_p="$MKDIR_P"
+case $mkdir_p in
+  [\\/$]* | ?:[\\/]*) ;;
+  */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
+esac
+
+for ac_prog in gawk mawk nawk awk
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_AWK+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  if test -n "$ac_ct_CC"; then
-  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+  if test -n "$AWK"; then
+  ac_cv_prog_AWK="$AWK" # Let the user override the test.
 else
 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH
@@ -1465,41 +2390,138 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
   for ac_exec_ext in '' $ac_executable_extensions; do
-  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_ac_ct_CC="gcc"
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_AWK="$ac_prog"
     echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
 done
+IFS=$as_save_IFS
 
 fi
 fi
-ac_ct_CC=$ac_cv_prog_ac_ct_CC
-if test -n "$ac_ct_CC"; then
-  echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
-echo "${ECHO_T}$ac_ct_CC" >&6
+AWK=$ac_cv_prog_AWK
+if test -n "$AWK"; then
+  { echo "$as_me:$LINENO: result: $AWK" >&5
+echo "${ECHO_T}$AWK" >&6; }
 else
-  echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
 fi
 
-  CC=$ac_ct_CC
+
+  test -n "$AWK" && break
+done
+
+{ echo "$as_me:$LINENO: checking whether ${MAKE-make} sets \$(MAKE)" >&5
+echo $ECHO_N "checking whether ${MAKE-make} sets \$(MAKE)... $ECHO_C" >&6; }
+set x ${MAKE-make}; ac_make=`echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
+if { as_var=ac_cv_prog_make_${ac_make}_set; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  CC="$ac_cv_prog_CC"
+  cat >conftest.make <<\_ACEOF
+SHELL = /bin/sh
+all:
+	@echo '@@@%%%=$(MAKE)=@@@%%%'
+_ACEOF
+# GNU make sometimes prints "make[1]: Entering...", which would confuse us.
+case `${MAKE-make} -f conftest.make 2>/dev/null` in
+  *@@@%%%=?*=@@@%%%*)
+    eval ac_cv_prog_make_${ac_make}_set=yes;;
+  *)
+    eval ac_cv_prog_make_${ac_make}_set=no;;
+esac
+rm -f conftest.make
+fi
+if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then
+  { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+  SET_MAKE=
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+  SET_MAKE="MAKE=${MAKE-make}"
+fi
+
+rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  am__isrc=' -I$(srcdir)'
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    { { echo "$as_me:$LINENO: error: source directory already configured; run \"make distclean\" there first" >&5
+echo "$as_me: error: source directory already configured; run \"make distclean\" there first" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
 fi
 
-if test -z "$CC"; then
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+
+
+# Define the identity of the package.
+ PACKAGE='libffi'
+ VERSION='3.0.4'
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE "$PACKAGE"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define VERSION "$VERSION"
+_ACEOF
+
+# Some tools Automake needs.
+
+ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"}
+
+
+AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"}
+
+
+AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"}
+
+
+AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"}
+
+
+MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"}
+
+install_sh=${install_sh-"\$(SHELL) $am_aux_dir/install-sh"}
+
+# Installed binaries are usually stripped using `strip' when the user
+# run `make install-strip'.  However `strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the `STRIP' environment variable to overrule this program.
+if test "$cross_compiling" != no; then
   if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
-set dummy ${ac_tool_prefix}cc; ac_word=$2
-echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
-if test "${ac_cv_prog_CC+set}" = set; then
+  # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
+set dummy ${ac_tool_prefix}strip; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_STRIP+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  if test -n "$CC"; then
-  ac_cv_prog_CC="$CC" # Let the user override the test.
+  if test -n "$STRIP"; then
+  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
 else
 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH
@@ -1507,37 +2529,39 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
   for ac_exec_ext in '' $ac_executable_extensions; do
-  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_CC="${ac_tool_prefix}cc"
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_STRIP="${ac_tool_prefix}strip"
     echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
 done
+IFS=$as_save_IFS
 
 fi
 fi
-CC=$ac_cv_prog_CC
-if test -n "$CC"; then
-  echo "$as_me:$LINENO: result: $CC" >&5
-echo "${ECHO_T}$CC" >&6
+STRIP=$ac_cv_prog_STRIP
+if test -n "$STRIP"; then
+  { echo "$as_me:$LINENO: result: $STRIP" >&5
+echo "${ECHO_T}$STRIP" >&6; }
 else
-  echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
 fi
 
+
 fi
-if test -z "$ac_cv_prog_CC"; then
-  ac_ct_CC=$CC
-  # Extract the first word of "cc", so it can be a program name with args.
-set dummy cc; ac_word=$2
-echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
-if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+if test -z "$ac_cv_prog_STRIP"; then
+  ac_ct_STRIP=$STRIP
+  # Extract the first word of "strip", so it can be a program name with args.
+set dummy strip; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  if test -n "$ac_ct_CC"; then
-  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+  if test -n "$ac_ct_STRIP"; then
+  ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
 else
 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH
@@ -1545,36 +2569,215 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
   for ac_exec_ext in '' $ac_executable_extensions; do
-  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_ac_ct_CC="cc"
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_STRIP="strip"
     echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
 done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP
+if test -n "$ac_ct_STRIP"; then
+  { echo "$as_me:$LINENO: result: $ac_ct_STRIP" >&5
+echo "${ECHO_T}$ac_ct_STRIP" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+  if test "x$ac_ct_STRIP" = x; then
+    STRIP=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&5
+echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&2;}
+ac_tool_warned=yes ;;
+esac
+    STRIP=$ac_ct_STRIP
+  fi
+else
+  STRIP="$ac_cv_prog_STRIP"
+fi
+
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+
+# We need awk for the "check" target.  The system "awk" is bad on
+# some platforms.
+# Always define AMTAR for backward compatibility.
+
+AMTAR=${AMTAR-"${am_missing_run}tar"}
+
+am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'
+
+
+
+
+
+
+# The same as in boehm-gc and libstdc++. Have to borrow it from there.
+# We must force CC to /not/ be precious variables; otherwise
+# the wrong, non-multilib-adjusted value will be used in multilibs.
+# As a side effect, we have to subst CFLAGS ourselves.
+
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+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 -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="${ac_tool_prefix}gcc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_CC="gcc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
 
 fi
 fi
 ac_ct_CC=$ac_cv_prog_ac_ct_CC
 if test -n "$ac_ct_CC"; then
-  echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
-echo "${ECHO_T}$ac_ct_CC" >&6
+  { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6; }
 else
-  echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
 fi
 
-  CC=$ac_ct_CC
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&5
+echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
 else
   CC="$ac_cv_prog_CC"
 fi
 
+if test -z "$CC"; then
+          if test -n "$ac_tool_prefix"; then
+    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CC="${ac_tool_prefix}cc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+
+  fi
 fi
 if test -z "$CC"; then
   # Extract the first word of "cc", so it can be a program name with args.
 set dummy cc; ac_word=$2
-echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
 if test "${ac_cv_prog_CC+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
@@ -1588,7 +2791,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
   for ac_exec_ext in '' $ac_executable_extensions; do
-  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
        ac_prog_rejected=yes
        continue
@@ -1599,6 +2802,7 @@
   fi
 done
 done
+IFS=$as_save_IFS
 
 if test $ac_prog_rejected = yes; then
   # We found a bogon in the path, so make sure we never use it.
@@ -1616,22 +2820,23 @@
 fi
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  echo "$as_me:$LINENO: result: $CC" >&5
-echo "${ECHO_T}$CC" >&6
+  { echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6; }
 else
-  echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
 fi
 
+
 fi
 if test -z "$CC"; then
   if test -n "$ac_tool_prefix"; then
-  for ac_prog in cl
+  for ac_prog in cl.exe
   do
     # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
-echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
 if test "${ac_cv_prog_CC+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
@@ -1644,36 +2849,38 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
   for ac_exec_ext in '' $ac_executable_extensions; do
-  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
     echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
 done
+IFS=$as_save_IFS
 
 fi
 fi
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  echo "$as_me:$LINENO: result: $CC" >&5
-echo "${ECHO_T}$CC" >&6
+  { echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6; }
 else
-  echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
 fi
 
+
     test -n "$CC" && break
   done
 fi
 if test -z "$CC"; then
   ac_ct_CC=$CC
-  for ac_prog in cl
+  for ac_prog in cl.exe
 do
   # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
-echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
 if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
@@ -1686,29 +2893,45 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
   for ac_exec_ext in '' $ac_executable_extensions; do
-  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_ac_ct_CC="$ac_prog"
     echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
 done
+IFS=$as_save_IFS
 
 fi
 fi
 ac_ct_CC=$ac_cv_prog_ac_ct_CC
 if test -n "$ac_ct_CC"; then
-  echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
-echo "${ECHO_T}$ac_ct_CC" >&6
+  { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6; }
 else
-  echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
 fi
 
+
   test -n "$ac_ct_CC" && break
 done
 
-  CC=$ac_ct_CC
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&5
+echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
 fi
 
 fi
@@ -1721,21 +2944,35 @@
    { (exit 1); exit 1; }; }
 
 # Provide some information about the compiler.
-echo "$as_me:$LINENO:" \
-     "checking for C compiler version" >&5
+echo "$as_me:$LINENO: checking for C compiler version" >&5
 ac_compiler=`set X $ac_compile; echo $2`
-{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version </dev/null >&5\"") >&5
-  (eval $ac_compiler --version </dev/null >&5) 2>&5
+{ (ac_try="$ac_compiler --version >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compiler --version >&5") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }
-{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v </dev/null >&5\"") >&5
-  (eval $ac_compiler -v </dev/null >&5) 2>&5
+{ (ac_try="$ac_compiler -v >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compiler -v >&5") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }
-{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V </dev/null >&5\"") >&5
-  (eval $ac_compiler -V </dev/null >&5) 2>&5
+{ (ac_try="$ac_compiler -V >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compiler -V >&5") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }
@@ -1760,47 +2997,77 @@
 # Try to create an executable without -o first, disregard a.out.
 # It will help us diagnose broken compilers, and finding out an intuition
 # of exeext.
-echo "$as_me:$LINENO: checking for C compiler default output file name" >&5
-echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking for C compiler default output file name" >&5
+echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6; }
 ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
-if { (eval echo "$as_me:$LINENO: \"$ac_link_default\"") >&5
-  (eval $ac_link_default) 2>&5
+#
+# List of possible output files, starting from the most likely.
+# The algorithm is not robust to junk in `.', hence go to wildcards (a.*)
+# only as a last resort.  b.out is created by i960 compilers.
+ac_files='a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out'
+#
+# The IRIX 6 linker writes into existing files which may not be
+# executable, retaining their permissions.  Remove them first so a
+# subsequent execution test works.
+ac_rmfiles=
+for ac_file in $ac_files
+do
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) ;;
+    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
+  esac
+done
+rm -f $ac_rmfiles
+
+if { (ac_try="$ac_link_default"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link_default") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; then
-  # Find the output, starting from the most likely.  This scheme is
-# not robust to junk in `.', hence go to wildcards (a.*) only as a last
-# resort.
-
-# Be careful to initialize this variable, since it used to be cached.
-# Otherwise an old cache value of `no' led to `EXEEXT = no' in a Makefile.
-ac_cv_exeext=
-# b.out is created by i960 compilers.
-for ac_file in a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out
+  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
+# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
+# in a Makefile.  We should not override ac_cv_exeext if it was cached,
+# so that the user can short-circuit this test for compilers unknown to
+# Autoconf.
+for ac_file in $ac_files ''
 do
   test -f "$ac_file" || continue
   case $ac_file in
-    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj )
-	;;
-    conftest.$ac_ext )
-	# This is the source file.
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj )
 	;;
     [ab].out )
 	# We found the default executable, but exeext='' is most
 	# certainly right.
 	break;;
     *.* )
-	ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
-	# FIXME: I believe we export ac_cv_exeext for Libtool,
-	# but it would be cool to find out if it's true.  Does anybody
-	# maintain Libtool? --akim.
-	export ac_cv_exeext
+        if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
+	then :; else
+	   ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	fi
+	# We set ac_cv_exeext here because the later test for it is not
+	# safe: cross compilers may not add the suffix if given an `-o'
+	# argument, so we may need to know it at that point already.
+	# Even if this section looks crufty: it has the advantage of
+	# actually working.
 	break;;
     * )
 	break;;
   esac
 done
+test "$ac_cv_exeext" = no && ac_cv_exeext=
+
 else
+  ac_file=''
+fi
+
+{ echo "$as_me:$LINENO: result: $ac_file" >&5
+echo "${ECHO_T}$ac_file" >&6; }
+if test -z "$ac_file"; then
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
@@ -1812,19 +3079,21 @@
 fi
 
 ac_exeext=$ac_cv_exeext
-echo "$as_me:$LINENO: result: $ac_file" >&5
-echo "${ECHO_T}$ac_file" >&6
 
-# Check the compiler produces executables we can run.  If not, either
+# Check that the compiler produces executables we can run.  If not, either
 # the compiler is broken, or we cross compile.
-echo "$as_me:$LINENO: checking whether the C compiler works" >&5
-echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking whether the C compiler works" >&5
+echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6; }
 # FIXME: These cross compiler hacks should be removed for Autoconf 3.0
 # If not cross compiling, check that we can run a simple program.
 if test "$cross_compiling" != yes; then
   if { ac_try='./$ac_file'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
@@ -1843,22 +3112,27 @@
     fi
   fi
 fi
-echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6
+{ echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
 
 rm -f a.out a.exe conftest$ac_cv_exeext b.out
 ac_clean_files=$ac_clean_files_save
-# Check the compiler produces executables we can run.  If not, either
+# Check that the compiler produces executables we can run.  If not, either
 # the compiler is broken, or we cross compile.
-echo "$as_me:$LINENO: checking whether we are cross compiling" >&5
-echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6
-echo "$as_me:$LINENO: result: $cross_compiling" >&5
-echo "${ECHO_T}$cross_compiling" >&6
-
-echo "$as_me:$LINENO: checking for suffix of executables" >&5
-echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>&5
+{ echo "$as_me:$LINENO: checking whether we are cross compiling" >&5
+echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6; }
+{ echo "$as_me:$LINENO: result: $cross_compiling" >&5
+echo "${ECHO_T}$cross_compiling" >&6; }
+
+{ echo "$as_me:$LINENO: checking for suffix of executables" >&5
+echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6; }
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; then
@@ -1869,9 +3143,8 @@
 for ac_file in conftest.exe conftest conftest.*; do
   test -f "$ac_file" || continue
   case $ac_file in
-    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) ;;
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) ;;
     *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
-	  export ac_cv_exeext
 	  break;;
     * ) break;;
   esac
@@ -1885,14 +3158,14 @@
 fi
 
 rm -f conftest$ac_cv_exeext
-echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5
-echo "${ECHO_T}$ac_cv_exeext" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5
+echo "${ECHO_T}$ac_cv_exeext" >&6; }
 
 rm -f conftest.$ac_ext
 EXEEXT=$ac_cv_exeext
 ac_exeext=$EXEEXT
-echo "$as_me:$LINENO: checking for suffix of object files" >&5
-echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking for suffix of object files" >&5
+echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6; }
 if test "${ac_cv_objext+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
@@ -1912,14 +3185,20 @@
 }
 _ACEOF
 rm -f conftest.o conftest.obj
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>&5
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; then
-  for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do
+  for ac_file in conftest.o conftest.obj conftest.*; do
+  test -f "$ac_file" || continue;
   case $ac_file in
-    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg ) ;;
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf ) ;;
     *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
        break;;
   esac
@@ -1937,12 +3216,12 @@
 
 rm -f conftest.$ac_cv_objext conftest.$ac_ext
 fi
-echo "$as_me:$LINENO: result: $ac_cv_objext" >&5
-echo "${ECHO_T}$ac_cv_objext" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_objext" >&5
+echo "${ECHO_T}$ac_cv_objext" >&6; }
 OBJEXT=$ac_cv_objext
 ac_objext=$OBJEXT
-echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5
-echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5
+echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6; }
 if test "${ac_cv_c_compiler_gnu+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
@@ -1965,50 +3244,49 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_compiler_gnu=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_compiler_gnu=no
+	ac_compiler_gnu=no
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 ac_cv_c_compiler_gnu=$ac_compiler_gnu
 
 fi
-echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5
-echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5
+echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6; }
 GCC=`test $ac_compiler_gnu = yes && echo yes`
 ac_test_CFLAGS=${CFLAGS+set}
 ac_save_CFLAGS=$CFLAGS
-CFLAGS="-g"
-echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5
-echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5
+echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6; }
 if test "${ac_cv_prog_cc_g+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  ac_save_c_werror_flag=$ac_c_werror_flag
+   ac_c_werror_flag=yes
+   ac_cv_prog_cc_g=no
+   CFLAGS="-g"
+   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -2024,38 +3302,118 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_prog_cc_g=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	CFLAGS=""
+      cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_c_werror_flag=$ac_save_c_werror_flag
+	 CFLAGS="-g"
+	 cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_prog_cc_g=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_cv_prog_cc_g=no
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   ac_c_werror_flag=$ac_save_c_werror_flag
 fi
-echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5
-echo "${ECHO_T}$ac_cv_prog_cc_g" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5
+echo "${ECHO_T}$ac_cv_prog_cc_g" >&6; }
 if test "$ac_test_CFLAGS" = set; then
   CFLAGS=$ac_save_CFLAGS
 elif test $ac_cv_prog_cc_g = yes; then
@@ -2071,12 +3429,12 @@
     CFLAGS=
   fi
 fi
-echo "$as_me:$LINENO: checking for $CC option to accept ANSI C" >&5
-echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6
-if test "${ac_cv_prog_cc_stdc+set}" = set; then
+{ echo "$as_me:$LINENO: checking for $CC option to accept ISO C89" >&5
+echo $ECHO_N "checking for $CC option to accept ISO C89... $ECHO_C" >&6; }
+if test "${ac_cv_prog_cc_c89+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  ac_cv_prog_cc_stdc=no
+  ac_cv_prog_cc_c89=no
 ac_save_CC=$CC
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -2110,12 +3468,17 @@
 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
    function prototypes and stuff, but not '\xHH' hex character constants.
    These don't provoke an error unfortunately, instead are silently treated
-   as 'x'.  The following induces an error, until -std1 is added to get
+   as 'x'.  The following induces an error, until -std is added to get
    proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
    array size at least.  It's necessary to write '\x00'==0 to get something
-   that's true only with -std1.  */
+   that's true only with -std.  */
 int osf4_cc_array ['\x00' == 0 ? 1 : -1];
 
+/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
+   inside strings and character constants.  */
+#define FOO(x) 'x'
+int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
+
 int test (int i, double x);
 struct s1 {int (*f) (int a);};
 struct s2 {int (*f) (double a);};
@@ -2130,1105 +3493,1718 @@
   return 0;
 }
 _ACEOF
-# Don't try gcc -ansi; that turns off useful extensions and
-# breaks some systems' header files.
-# AIX			-qlanglvl=ansi
-# Ultrix and OSF/1	-std1
-# HP-UX 10.20 and later	-Ae
-# HP-UX older versions	-Aa -D_HPUX_SOURCE
-# SVR4			-Xc -D__EXTENSIONS__
-for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
+	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
 do
   CC="$ac_save_CC $ac_arg"
   rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_cv_prog_cc_stdc=$ac_arg
-break
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_prog_cc_c89=$ac_arg
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
+
 fi
-rm -f conftest.err conftest.$ac_objext
+
+rm -f core conftest.err conftest.$ac_objext
+  test "x$ac_cv_prog_cc_c89" != "xno" && break
 done
-rm -f conftest.$ac_ext conftest.$ac_objext
+rm -f conftest.$ac_ext
 CC=$ac_save_CC
 
 fi
-
-case "x$ac_cv_prog_cc_stdc" in
-  x|xno)
-    echo "$as_me:$LINENO: result: none needed" >&5
-echo "${ECHO_T}none needed" >&6 ;;
+# AC_CACHE_VAL
+case "x$ac_cv_prog_cc_c89" in
+  x)
+    { echo "$as_me:$LINENO: result: none needed" >&5
+echo "${ECHO_T}none needed" >&6; } ;;
+  xno)
+    { echo "$as_me:$LINENO: result: unsupported" >&5
+echo "${ECHO_T}unsupported" >&6; } ;;
   *)
-    echo "$as_me:$LINENO: result: $ac_cv_prog_cc_stdc" >&5
-echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6
-    CC="$CC $ac_cv_prog_cc_stdc" ;;
+    CC="$CC $ac_cv_prog_cc_c89"
+    { echo "$as_me:$LINENO: result: $ac_cv_prog_cc_c89" >&5
+echo "${ECHO_T}$ac_cv_prog_cc_c89" >&6; } ;;
 esac
 
-# Some people use a C++ compiler to compile C.  Since we use `exit',
-# in C++ we need to declare it.  In case someone uses the same compiler
-# for both compiling C and C++ we need to have the C++ compiler decide
-# the declaration of exit, since it's the most demanding environment.
-cat >conftest.$ac_ext <<_ACEOF
-#ifndef __cplusplus
-  choke me
-#endif
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  for ac_declaration in \
-   '' \
-   'extern "C" void std::exit (int) throw (); using std::exit;' \
-   'extern "C" void std::exit (int); using std::exit;' \
-   'extern "C" void exit (int) throw ();' \
-   'extern "C" void exit (int);' \
-   'void exit (int);'
-do
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+DEPDIR="${am__leading_dot}deps"
+
+ac_config_commands="$ac_config_commands depfiles"
+
+
+am_make=${MAKE-make}
+cat > confinc << 'END'
+am__doit:
+	@echo done
+.PHONY: am__doit
+END
+# If we don't find an include directive, just comment out the code.
+{ echo "$as_me:$LINENO: checking for style of include used by $am_make" >&5
+echo $ECHO_N "checking for style of include used by $am_make... $ECHO_C" >&6; }
+am__include="#"
+am__quote=
+_am_result=none
+# First try GNU make style include.
+echo "include confinc" > confmf
+# We grep out `Entering directory' and `Leaving directory'
+# messages which can occur if `w' ends up in MAKEFLAGS.
+# In particular we don't look at `^make:' because GNU make might
+# be invoked under some other name (usually "gmake"), in which
+# case it prints its new name instead of `make'.
+if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then
+   am__include=include
+   am__quote=
+   _am_result=GNU
+fi
+# Now try BSD make style include.
+if test "$am__include" = "#"; then
+   echo '.include "confinc"' > confmf
+   if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then
+      am__include=.include
+      am__quote="\""
+      _am_result=BSD
+   fi
+fi
+
+
+{ echo "$as_me:$LINENO: result: $_am_result" >&5
+echo "${ECHO_T}$_am_result" >&6; }
+rm -f confinc confmf
+
+# Check whether --enable-dependency-tracking was given.
+if test "${enable_dependency_tracking+set}" = set; then
+  enableval=$enable_dependency_tracking;
+fi
+
+if test "x$enable_dependency_tracking" != xno; then
+  am_depcomp="$ac_aux_dir/depcomp"
+  AMDEPBACKSLASH='\'
+fi
+ if test "x$enable_dependency_tracking" != xno; then
+  AMDEP_TRUE=
+  AMDEP_FALSE='#'
+else
+  AMDEP_TRUE='#'
+  AMDEP_FALSE=
+fi
+
+
+
+depcc="$CC"   am_compiler_list=
+
+{ echo "$as_me:$LINENO: checking dependency style of $depcc" >&5
+echo $ECHO_N "checking dependency style of $depcc... $ECHO_C" >&6; }
+if test "${am_cv_CC_dependencies_compiler_type+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_CC_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp`
+  fi
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    case $depmode in
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    none) break ;;
+    esac
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.
+    if depmode=$depmode \
+       source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_CC_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_CC_dependencies_compiler_type=none
+fi
+
+fi
+{ echo "$as_me:$LINENO: result: $am_cv_CC_dependencies_compiler_type" >&5
+echo "${ECHO_T}$am_cv_CC_dependencies_compiler_type" >&6; }
+CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type
+
+ if
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then
+  am__fastdepCC_TRUE=
+  am__fastdepCC_FALSE='#'
+else
+  am__fastdepCC_TRUE='#'
+  am__fastdepCC_FALSE=
+fi
+
+
+
+
+
+
+# By default we simply use the C compiler to build assembly code.
+
+test "${CCAS+set}" = set || CCAS=$CC
+test "${CCASFLAGS+set}" = set || CCASFLAGS=$CFLAGS
+
+
+
+depcc="$CCAS"   am_compiler_list=
+
+{ echo "$as_me:$LINENO: checking dependency style of $depcc" >&5
+echo $ECHO_N "checking dependency style of $depcc... $ECHO_C" >&6; }
+if test "${am_cv_CCAS_dependencies_compiler_type+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_CCAS_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp`
+  fi
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    case $depmode in
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    none) break ;;
+    esac
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.
+    if depmode=$depmode \
+       source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_CCAS_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_CCAS_dependencies_compiler_type=none
+fi
+
+fi
+{ echo "$as_me:$LINENO: result: $am_cv_CCAS_dependencies_compiler_type" >&5
+echo "${ECHO_T}$am_cv_CCAS_dependencies_compiler_type" >&6; }
+CCASDEPMODE=depmode=$am_cv_CCAS_dependencies_compiler_type
+
+ if
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_CCAS_dependencies_compiler_type" = gcc3; then
+  am__fastdepCCAS_TRUE=
+  am__fastdepCCAS_FALSE='#'
+else
+  am__fastdepCCAS_TRUE='#'
+  am__fastdepCCAS_FALSE=
+fi
+
+
+if test "x$CC" != xcc; then
+  { echo "$as_me:$LINENO: checking whether $CC and cc understand -c and -o together" >&5
+echo $ECHO_N "checking whether $CC and cc understand -c and -o together... $ECHO_C" >&6; }
+else
+  { echo "$as_me:$LINENO: checking whether cc understands -c and -o together" >&5
+echo $ECHO_N "checking whether cc understands -c and -o together... $ECHO_C" >&6; }
+fi
+set dummy $CC; ac_cc=`echo $2 |
+		      sed 's/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/'`
+if { as_var=ac_cv_prog_cc_${ac_cc}_c_o; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-$ac_declaration
-#include <stdlib.h>
+
 int
 main ()
 {
-exit (42);
+
   ;
   return 0;
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+# Make sure it works both with $CC and with simple cc.
+# We do the test twice because some compilers refuse to overwrite an
+# existing .o file with -o, though they will create one.
+ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&5'
+rm -f conftest2.*
+if { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
   ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+   test -f conftest2.$ac_objext && { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+  (exit $ac_status); };
+then
+  eval ac_cv_prog_cc_${ac_cc}_c_o=yes
+  if test "x$CC" != xcc; then
+    # Test first that cc exists at all.
+    if { ac_try='cc -c conftest.$ac_ext >&5'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  :
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-continue
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_declaration
-int
-main ()
-{
-exit (42);
-  ;
-  return 0;
-}
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+      ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&5'
+      rm -f conftest2.*
+      if { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
   ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+	 test -f conftest2.$ac_objext && { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  break
+  (exit $ac_status); };
+      then
+	# cc works too.
+	:
+      else
+	# cc exists but doesn't like -o.
+	eval ac_cv_prog_cc_${ac_cc}_c_o=no
+      fi
+    fi
+  fi
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-done
-rm -f conftest*
-if test -n "$ac_declaration"; then
-  echo '#ifdef __cplusplus' >>confdefs.h
-  echo $ac_declaration      >>confdefs.h
-  echo '#endif'             >>confdefs.h
+  eval ac_cv_prog_cc_${ac_cc}_c_o=no
 fi
+rm -f core conftest*
 
+fi
+if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
+  { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+
+cat >>confdefs.h <<\_ACEOF
+#define NO_MINUS_C_MINUS_O 1
+_ACEOF
 
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+# FIXME: we rely on the cache variable name because
+# there is no other way.
+set dummy $CC
+ac_cc=`echo $2 | sed 's/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/'`
+if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" != yes"; then
+   # Losing compiler, so override with the script.
+   # FIXME: It is wrong to rewrite CC.
+   # But if we don't then we get into trouble of one sort or another.
+   # A longer-term fix would be to have automake use am__CC in this case,
+   # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
+   CC="$am_aux_dir/compile $CC"
+fi
 
 
+# Check whether --enable-shared was given.
+if test "${enable_shared+set}" = set; then
+  enableval=$enable_shared; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_shared=yes ;;
+    no) enable_shared=no ;;
+    *)
+      enable_shared=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_shared=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_shared=yes
+fi
 
 
+# Check whether --enable-static was given.
+if test "${enable_static+set}" = set; then
+  enableval=$enable_static; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_static=yes ;;
+    no) enable_static=no ;;
+    *)
+     enable_static=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_static=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_static=yes
+fi
 
 
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5
-echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6
-# On Suns, sometimes $CPP names a directory.
-if test -n "$CPP" && test -d "$CPP"; then
-  CPP=
+# Check whether --enable-fast-install was given.
+if test "${enable_fast_install+set}" = set; then
+  enableval=$enable_fast_install; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_fast_install=yes ;;
+    no) enable_fast_install=no ;;
+    *)
+      enable_fast_install=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_fast_install=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_fast_install=yes
 fi
-if test -z "$CPP"; then
-  if test "${ac_cv_prog_CPP+set}" = set; then
+
+
+{ echo "$as_me:$LINENO: checking for a sed that does not truncate output" >&5
+echo $ECHO_N "checking for a sed that does not truncate output... $ECHO_C" >&6; }
+if test "${lt_cv_path_SED+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-      # Double quotes because CPP needs to be expanded
-    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
-    do
-      ac_preproc_ok=false
-for ac_c_preproc_warn_flag in '' yes
+  # Loop through the user's path and test for sed and gsed.
+# Then use that list of sed's as ones to test for truncation.
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
 do
-  # Use a header file that comes with gcc, so configuring glibc
-  # with a fresh cross-compiler works.
-  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
-  # <limits.h> exists even on freestanding compilers.
-  # On the NeXT, cc -E runs the code through the compiler's parser,
-  # not just through cpp. "Syntax error" is here to catch this case.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#ifdef __STDC__
-# include <limits.h>
-#else
-# include <assert.h>
-#endif
-		     Syntax error
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
-  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null; then
-  if test -s conftest.err; then
-    ac_cpp_err=$ac_c_preproc_warn_flag
-    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
-  else
-    ac_cpp_err=
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for lt_ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      if { test -f "$as_dir/$lt_ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$lt_ac_prog$ac_exec_ext"; }; then
+        lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext"
+      fi
+    done
+  done
+done
+IFS=$as_save_IFS
+lt_ac_max=0
+lt_ac_count=0
+# Add /usr/xpg4/bin/sed as it is typically found on Solaris
+# along with /bin/sed that truncates output.
+for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do
+  test ! -f $lt_ac_sed && continue
+  cat /dev/null > conftest.in
+  lt_ac_count=0
+  echo $ECHO_N "0123456789$ECHO_C" >conftest.in
+  # Check for GNU sed and select it if it is found.
+  if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then
+    lt_cv_path_SED=$lt_ac_sed
+    break
   fi
-else
-  ac_cpp_err=yes
+  while true; do
+    cat conftest.in conftest.in >conftest.tmp
+    mv conftest.tmp conftest.in
+    cp conftest.in conftest.nl
+    echo >>conftest.nl
+    $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break
+    cmp -s conftest.out conftest.nl || break
+    # 10000 chars as input seems more than enough
+    test $lt_ac_count -gt 10 && break
+    lt_ac_count=`expr $lt_ac_count + 1`
+    if test $lt_ac_count -gt $lt_ac_max; then
+      lt_ac_max=$lt_ac_count
+      lt_cv_path_SED=$lt_ac_sed
+    fi
+  done
+done
+
 fi
-if test -z "$ac_cpp_err"; then
-  :
+
+SED=$lt_cv_path_SED
+
+{ echo "$as_me:$LINENO: result: $SED" >&5
+echo "${ECHO_T}$SED" >&6; }
+
+{ echo "$as_me:$LINENO: checking for grep that handles long lines and -e" >&5
+echo $ECHO_N "checking for grep that handles long lines and -e... $ECHO_C" >&6; }
+if test "${ac_cv_path_GREP+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
+  # Extract the first word of "grep ggrep" to use in msg output
+if test -z "$GREP"; then
+set dummy grep ggrep; ac_prog_name=$2
+if test "${ac_cv_path_GREP+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_path_GREP_found=false
+# Loop through the user's path and test for each of PROGNAME-LIST
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_prog in grep ggrep; do
+  for ac_exec_ext in '' $ac_executable_extensions; do
+    ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
+    { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue
+    # Check for GNU ac_path_GREP and select it if it is found.
+  # Check for GNU $ac_path_GREP
+case `"$ac_path_GREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
+*)
+  ac_count=0
+  echo $ECHO_N "0123456789$ECHO_C" >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    echo 'GREP' >> "conftest.nl"
+    "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    ac_count=`expr $ac_count + 1`
+    if test $ac_count -gt ${ac_path_GREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_GREP="$ac_path_GREP"
+      ac_path_GREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+
+    $ac_path_GREP_found && break 3
+  done
+done
+
+done
+IFS=$as_save_IFS
 
-  # Broken: fails on valid input.
-continue
-fi
-rm -f conftest.err conftest.$ac_ext
 
-  # OK, works on sane cases.  Now check whether non-existent headers
-  # can be detected and how.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <ac_nonexistent.h>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
-  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null; then
-  if test -s conftest.err; then
-    ac_cpp_err=$ac_c_preproc_warn_flag
-    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
-  else
-    ac_cpp_err=
-  fi
-else
-  ac_cpp_err=yes
 fi
-if test -z "$ac_cpp_err"; then
-  # Broken: success on invalid input.
-continue
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
 
-  # Passes both tests.
-ac_preproc_ok=:
-break
+GREP="$ac_cv_path_GREP"
+if test -z "$GREP"; then
+  { { echo "$as_me:$LINENO: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5
+echo "$as_me: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;}
+   { (exit 1); exit 1; }; }
 fi
-rm -f conftest.err conftest.$ac_ext
 
-done
-# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
-rm -f conftest.err conftest.$ac_ext
-if $ac_preproc_ok; then
-  break
+else
+  ac_cv_path_GREP=$GREP
 fi
 
-    done
-    ac_cv_prog_CPP=$CPP
 
 fi
-  CPP=$ac_cv_prog_CPP
+{ echo "$as_me:$LINENO: result: $ac_cv_path_GREP" >&5
+echo "${ECHO_T}$ac_cv_path_GREP" >&6; }
+ GREP="$ac_cv_path_GREP"
+
+
+{ echo "$as_me:$LINENO: checking for egrep" >&5
+echo $ECHO_N "checking for egrep... $ECHO_C" >&6; }
+if test "${ac_cv_path_EGREP+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  ac_cv_prog_CPP=$CPP
-fi
-echo "$as_me:$LINENO: result: $CPP" >&5
-echo "${ECHO_T}$CPP" >&6
-ac_preproc_ok=false
-for ac_c_preproc_warn_flag in '' yes
-do
-  # Use a header file that comes with gcc, so configuring glibc
-  # with a fresh cross-compiler works.
-  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
-  # <limits.h> exists even on freestanding compilers.
-  # On the NeXT, cc -E runs the code through the compiler's parser,
-  # not just through cpp. "Syntax error" is here to catch this case.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#ifdef __STDC__
-# include <limits.h>
-#else
-# include <assert.h>
-#endif
-		     Syntax error
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
-  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null; then
-  if test -s conftest.err; then
-    ac_cpp_err=$ac_c_preproc_warn_flag
-    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
-  else
-    ac_cpp_err=
-  fi
+  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
+   then ac_cv_path_EGREP="$GREP -E"
+   else
+     # Extract the first word of "egrep" to use in msg output
+if test -z "$EGREP"; then
+set dummy egrep; ac_prog_name=$2
+if test "${ac_cv_path_EGREP+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  ac_cpp_err=yes
+  ac_path_EGREP_found=false
+# Loop through the user's path and test for each of PROGNAME-LIST
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_prog in egrep; do
+  for ac_exec_ext in '' $ac_executable_extensions; do
+    ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
+    { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue
+    # Check for GNU ac_path_EGREP and select it if it is found.
+  # Check for GNU $ac_path_EGREP
+case `"$ac_path_EGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
+*)
+  ac_count=0
+  echo $ECHO_N "0123456789$ECHO_C" >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    echo 'EGREP' >> "conftest.nl"
+    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    ac_count=`expr $ac_count + 1`
+    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_EGREP="$ac_path_EGREP"
+      ac_path_EGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+
+    $ac_path_EGREP_found && break 3
+  done
+done
+
+done
+IFS=$as_save_IFS
+
+
 fi
-if test -z "$ac_cpp_err"; then
-  :
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
 
-  # Broken: fails on valid input.
-continue
+EGREP="$ac_cv_path_EGREP"
+if test -z "$EGREP"; then
+  { { echo "$as_me:$LINENO: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5
+echo "$as_me: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;}
+   { (exit 1); exit 1; }; }
 fi
-rm -f conftest.err conftest.$ac_ext
 
-  # OK, works on sane cases.  Now check whether non-existent headers
-  # can be detected and how.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <ac_nonexistent.h>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
-  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null; then
-  if test -s conftest.err; then
-    ac_cpp_err=$ac_c_preproc_warn_flag
-    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
-  else
-    ac_cpp_err=
-  fi
 else
-  ac_cpp_err=yes
+  ac_cv_path_EGREP=$EGREP
 fi
-if test -z "$ac_cpp_err"; then
-  # Broken: success on invalid input.
-continue
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
 
-  # Passes both tests.
-ac_preproc_ok=:
-break
-fi
-rm -f conftest.err conftest.$ac_ext
 
-done
-# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
-rm -f conftest.err conftest.$ac_ext
-if $ac_preproc_ok; then
-  :
-else
-  { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check
-See \`config.log' for more details." >&5
-echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
+   fi
 fi
+{ echo "$as_me:$LINENO: result: $ac_cv_path_EGREP" >&5
+echo "${ECHO_T}$ac_cv_path_EGREP" >&6; }
+ EGREP="$ac_cv_path_EGREP"
+
 
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
+# Check whether --with-gnu-ld was given.
+if test "${with_gnu_ld+set}" = set; then
+  withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes
+else
+  with_gnu_ld=no
+fi
 
-echo "$as_me:$LINENO: checking for egrep" >&5
-echo $ECHO_N "checking for egrep... $ECHO_C" >&6
-if test "${ac_cv_prog_egrep+set}" = set; then
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  { echo "$as_me:$LINENO: checking for ld used by $CC" >&5
+echo $ECHO_N "checking for ld used by $CC... $ECHO_C" >&6; }
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [\\/]* | ?:[\\/]*)
+      re_direlt='/[^/][^/]*/\.\./'
+      # Canonicalize the pathname of ld
+      ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
+      while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
+	ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  { echo "$as_me:$LINENO: checking for GNU ld" >&5
+echo $ECHO_N "checking for GNU ld... $ECHO_C" >&6; }
+else
+  { echo "$as_me:$LINENO: checking for non-GNU ld" >&5
+echo $ECHO_N "checking for non-GNU ld... $ECHO_C" >&6; }
+fi
+if test "${lt_cv_path_LD+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  if echo a | (grep -E '(a|b)') >/dev/null 2>&1
-    then ac_cv_prog_egrep='grep -E'
-    else ac_cv_prog_egrep='egrep'
+  if test -z "$LD"; then
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for ac_dir in $PATH; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      lt_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some variants of GNU ld only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
+      *GNU* | *'with BFD'*)
+	test "$with_gnu_ld" != no && break
+	;;
+      *)
+	test "$with_gnu_ld" != yes && break
+	;;
+      esac
     fi
+  done
+  IFS="$lt_save_ifs"
+else
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+fi
 fi
-echo "$as_me:$LINENO: result: $ac_cv_prog_egrep" >&5
-echo "${ECHO_T}$ac_cv_prog_egrep" >&6
- EGREP=$ac_cv_prog_egrep
-
 
-echo "$as_me:$LINENO: checking for ANSI C header files" >&5
-echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6
-if test "${ac_cv_header_stdc+set}" = set; then
+LD="$lt_cv_path_LD"
+if test -n "$LD"; then
+  { echo "$as_me:$LINENO: result: $LD" >&5
+echo "${ECHO_T}$LD" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+test -z "$LD" && { { echo "$as_me:$LINENO: error: no acceptable ld found in \$PATH" >&5
+echo "$as_me: error: no acceptable ld found in \$PATH" >&2;}
+   { (exit 1); exit 1; }; }
+{ echo "$as_me:$LINENO: checking if the linker ($LD) is GNU ld" >&5
+echo $ECHO_N "checking if the linker ($LD) is GNU ld... $ECHO_C" >&6; }
+if test "${lt_cv_prog_gnu_ld+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <float.h>
+  # I'd rather use --version here, but apparently some GNU lds only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  lt_cv_prog_gnu_ld=yes
+  ;;
+*)
+  lt_cv_prog_gnu_ld=no
+  ;;
+esac
+fi
+{ echo "$as_me:$LINENO: result: $lt_cv_prog_gnu_ld" >&5
+echo "${ECHO_T}$lt_cv_prog_gnu_ld" >&6; }
+with_gnu_ld=$lt_cv_prog_gnu_ld
 
-int
-main ()
-{
 
-  ;
-  return 0;
-}
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_cv_header_stdc=yes
+{ echo "$as_me:$LINENO: checking for $LD option to reload object files" >&5
+echo $ECHO_N "checking for $LD option to reload object files... $ECHO_C" >&6; }
+if test "${lt_cv_ld_reload_flag+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_cv_header_stdc=no
+  lt_cv_ld_reload_flag='-r'
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-
-if test $ac_cv_header_stdc = yes; then
-  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <string.h>
+{ echo "$as_me:$LINENO: result: $lt_cv_ld_reload_flag" >&5
+echo "${ECHO_T}$lt_cv_ld_reload_flag" >&6; }
+reload_flag=$lt_cv_ld_reload_flag
+case $reload_flag in
+"" | " "*) ;;
+*) reload_flag=" $reload_flag" ;;
+esac
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
+case $host_os in
+  darwin*)
+    if test "$GCC" = yes; then
+      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
+    else
+      reload_cmds='$LD$reload_flag -o $output$reload_objs'
+    fi
+    ;;
+esac
 
-_ACEOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  $EGREP "memchr" >/dev/null 2>&1; then
-  :
+{ echo "$as_me:$LINENO: checking for BSD-compatible nm" >&5
+echo $ECHO_N "checking for BSD-compatible nm... $ECHO_C" >&6; }
+if test "${lt_cv_path_NM+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  ac_cv_header_stdc=no
+  if test -n "$NM"; then
+  # Let the user override the test.
+  lt_cv_path_NM="$NM"
+else
+  lt_nm_to_check="${ac_tool_prefix}nm"
+  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
+    lt_nm_to_check="$lt_nm_to_check nm"
+  fi
+  for lt_tmp_nm in $lt_nm_to_check; do
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
+      IFS="$lt_save_ifs"
+      test -z "$ac_dir" && ac_dir=.
+      tmp_nm="$ac_dir/$lt_tmp_nm"
+      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
+	# Check to see if the nm accepts a BSD-compat flag.
+	# Adding the `sed 1q' prevents false positives on HP-UX, which says:
+	#   nm: unknown option "B" ignored
+	# Tru64's nm complains that /dev/null is an invalid object file
+	case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
+	*/dev/null* | *'Invalid file or object type'*)
+	  lt_cv_path_NM="$tmp_nm -B"
+	  break
+	  ;;
+	*)
+	  case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
+	  */dev/null*)
+	    lt_cv_path_NM="$tmp_nm -p"
+	    break
+	    ;;
+	  *)
+	    lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
+	    continue # so that we can try to find one that supports BSD flags
+	    ;;
+	  esac
+	  ;;
+	esac
+      fi
+    done
+    IFS="$lt_save_ifs"
+  done
+  test -z "$lt_cv_path_NM" && lt_cv_path_NM=nm
 fi
-rm -f conftest*
-
 fi
+{ echo "$as_me:$LINENO: result: $lt_cv_path_NM" >&5
+echo "${ECHO_T}$lt_cv_path_NM" >&6; }
+NM="$lt_cv_path_NM"
 
-if test $ac_cv_header_stdc = yes; then
-  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <stdlib.h>
-
-_ACEOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  $EGREP "free" >/dev/null 2>&1; then
-  :
+{ echo "$as_me:$LINENO: checking whether ln -s works" >&5
+echo $ECHO_N "checking whether ln -s works... $ECHO_C" >&6; }
+LN_S=$as_ln_s
+if test "$LN_S" = "ln -s"; then
+  { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
 else
-  ac_cv_header_stdc=no
-fi
-rm -f conftest*
-
+  { echo "$as_me:$LINENO: result: no, using $LN_S" >&5
+echo "${ECHO_T}no, using $LN_S" >&6; }
 fi
 
-if test $ac_cv_header_stdc = yes; then
-  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
-  if test "$cross_compiling" = yes; then
-  :
+{ echo "$as_me:$LINENO: checking how to recognize dependent libraries" >&5
+echo $ECHO_N "checking how to recognize dependent libraries... $ECHO_C" >&6; }
+if test "${lt_cv_deplibs_check_method+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <ctype.h>
-#if ((' ' & 0x0FF) == 0x020)
-# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
-# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
-#else
-# define ISLOWER(c) \
-		   (('a' <= (c) && (c) <= 'i') \
-		     || ('j' <= (c) && (c) <= 'r') \
-		     || ('s' <= (c) && (c) <= 'z'))
-# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
-#endif
+  lt_cv_file_magic_cmd='$MAGIC_CMD'
+lt_cv_file_magic_test_file=
+lt_cv_deplibs_check_method='unknown'
+# Need to set the preceding variable on all platforms that support
+# interlibrary dependencies.
+# 'none' -- dependencies not supported.
+# `unknown' -- same as none, but documents that we really don't know.
+# 'pass_all' -- all dependencies passed with no checks.
+# 'test_compile' -- check by making test program.
+# 'file_magic [[regex]]' -- check by looking for files in library path
+# which responds to the $file_magic_cmd with a given extended regex.
+# If you have `file' or equivalent on your system and you're not sure
+# whether `pass_all' will *always* work, you probably want this one.
+
+case $host_os in
+aix4* | aix5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+beos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+bsdi[45]*)
+  lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)'
+  lt_cv_file_magic_cmd='/usr/bin/file -L'
+  lt_cv_file_magic_test_file=/shlib/libc.so
+  ;;
+
+cygwin*)
+  # func_win32_libid is a shell function defined in ltmain.sh
+  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+  lt_cv_file_magic_cmd='func_win32_libid'
+  ;;
+
+mingw* | pw32*)
+  # Base MSYS/MinGW do not provide the 'file' command needed by
+  # func_win32_libid shell function, so use a weaker test based on 'objdump',
+  # unless we find 'file', for example because we are cross-compiling.
+  if ( file / ) >/dev/null 2>&1; then
+    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+    lt_cv_file_magic_cmd='func_win32_libid'
+  else
+    lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?'
+    lt_cv_file_magic_cmd='$OBJDUMP -f'
+  fi
+  ;;
 
-#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
-int
-main ()
-{
-  int i;
-  for (i = 0; i < 256; i++)
-    if (XOR (islower (i), ISLOWER (i))
-	|| toupper (i) != TOUPPER (i))
-      exit(2);
-  exit (0);
-}
-_ACEOF
-rm -f conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  :
-else
-  echo "$as_me: program exited with status $ac_status" >&5
-echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
+darwin* | rhapsody*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+freebsd* | dragonfly*)
+  if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
+    case $host_cpu in
+    i*86 )
+      # Not sure whether the presence of OpenBSD here was a mistake.
+      # Let's accept both of them until this is cleared up.
+      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library'
+      lt_cv_file_magic_cmd=/usr/bin/file
+      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
+      ;;
+    esac
+  else
+    lt_cv_deplibs_check_method=pass_all
+  fi
+  ;;
 
-( exit $ac_status )
-ac_cv_header_stdc=no
-fi
-rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
-fi
-fi
-fi
-echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5
-echo "${ECHO_T}$ac_cv_header_stdc" >&6
-if test $ac_cv_header_stdc = yes; then
+gnu*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+hpux10.20* | hpux11*)
+  lt_cv_file_magic_cmd=/usr/bin/file
+  case $host_cpu in
+  ia64*)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64'
+    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
+    ;;
+  hppa*64*)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]'
+    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
+    ;;
+  *)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9].[0-9]) shared library'
+    lt_cv_file_magic_test_file=/usr/lib/libc.sl
+    ;;
+  esac
+  ;;
 
-cat >>confdefs.h <<\_ACEOF
-#define STDC_HEADERS 1
-_ACEOF
+interix[3-9]*)
+  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
+  lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$'
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $LD in
+  *-32|*"-32 ") libmagic=32-bit;;
+  *-n32|*"-n32 ") libmagic=N32;;
+  *-64|*"-64 ") libmagic=64-bit;;
+  *) libmagic=never-match;;
+  esac
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+netbsd*)
+  if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$'
+  fi
+  ;;
+
+newos6*)
+  lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)'
+  lt_cv_file_magic_cmd=/usr/bin/file
+  lt_cv_file_magic_test_file=/usr/lib/libnls.so
+  ;;
+
+nto-qnx*)
+  lt_cv_deplibs_check_method=unknown
+  ;;
+
+openbsd*)
+  if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
+  fi
+  ;;
+
+osf3* | osf4* | osf5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+rdos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+solaris*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv4 | sysv4.3*)
+  case $host_vendor in
+  motorola)
+    lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]'
+    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
+    ;;
+  ncr)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  sequent)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )'
+    ;;
+  sni)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib"
+    lt_cv_file_magic_test_file=/lib/libc.so
+    ;;
+  siemens)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  pc)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  esac
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+esac
 
 fi
+{ echo "$as_me:$LINENO: result: $lt_cv_deplibs_check_method" >&5
+echo "${ECHO_T}$lt_cv_deplibs_check_method" >&6; }
+file_magic_cmd=$lt_cv_file_magic_cmd
+deplibs_check_method=$lt_cv_deplibs_check_method
+test -z "$deplibs_check_method" && deplibs_check_method=unknown
 
-# On IRIX 5.3, sys/types and inttypes.h are conflicting.
 
 
 
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
 
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
 
+# Allow CC to be a program name with arguments.
+compiler=$CC
 
 
+# Check whether --enable-libtool-lock was given.
+if test "${enable_libtool_lock+set}" = set; then
+  enableval=$enable_libtool_lock;
+fi
 
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
 
-for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
-		  inttypes.h stdint.h unistd.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
+# Some flags need to be propagated to the compiler or linker for good
+# libtool support.
+case $host in
+ia64-*-hpux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+    case `/usr/bin/file conftest.$ac_objext` in
+    *ELF-32*)
+      HPUX_IA64_MODE="32"
+      ;;
+    *ELF-64*)
+      HPUX_IA64_MODE="64"
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+*-*-irix6*)
+  # Find out which ABI we are using.
+  echo '#line 4693 "configure"' > conftest.$ac_ext
+  if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+   if test "$lt_cv_prog_gnu_ld" = yes; then
+    case `/usr/bin/file conftest.$ac_objext` in
+    *32-bit*)
+      LD="${LD-ld} -melf32bsmip"
+      ;;
+    *N32*)
+      LD="${LD-ld} -melf32bmipn32"
+      ;;
+    *64-bit*)
+      LD="${LD-ld} -melf64bmip"
+      ;;
+    esac
+   else
+    case `/usr/bin/file conftest.$ac_objext` in
+    *32-bit*)
+      LD="${LD-ld} -32"
+      ;;
+    *N32*)
+      LD="${LD-ld} -n32"
+      ;;
+    *64-bit*)
+      LD="${LD-ld} -64"
+      ;;
+    esac
+   fi
+  fi
+  rm -rf conftest*
+  ;;
+
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+s390*-*linux*|sparc*-*linux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+    case `/usr/bin/file conftest.o` in
+    *32-bit*)
+      case $host in
+        x86_64-*kfreebsd*-gnu)
+          LD="${LD-ld} -m elf_i386_fbsd"
+          ;;
+        x86_64-*linux*)
+          LD="${LD-ld} -m elf_i386"
+          ;;
+        ppc64-*linux*|powerpc64-*linux*)
+          LD="${LD-ld} -m elf32ppclinux"
+          ;;
+        s390x-*linux*)
+          LD="${LD-ld} -m elf_s390"
+          ;;
+        sparc64-*linux*)
+          LD="${LD-ld} -m elf32_sparc"
+          ;;
+      esac
+      ;;
+    *64-bit*)
+      libsuff=64
+      case $host in
+        x86_64-*kfreebsd*-gnu)
+          LD="${LD-ld} -m elf_x86_64_fbsd"
+          ;;
+        x86_64-*linux*)
+          LD="${LD-ld} -m elf_x86_64"
+          ;;
+        ppc*-*linux*|powerpc*-*linux*)
+          LD="${LD-ld} -m elf64ppc"
+          ;;
+        s390*-*linux*)
+          LD="${LD-ld} -m elf64_s390"
+          ;;
+        sparc*-*linux*)
+          LD="${LD-ld} -m elf64_sparc"
+          ;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+
+*-*-sco3.2v5*)
+  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -belf"
+  { echo "$as_me:$LINENO: checking whether the C compiler needs -belf" >&5
+echo $ECHO_N "checking whether the C compiler needs -belf... $ECHO_C" >&6; }
+if test "${lt_cv_cc_needs_belf+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+     cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-$ac_includes_default
 
-#include <$ac_header>
+int
+main ()
+{
+
+  ;
+  return 0;
+}
 _ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  eval "$as_ac_Header=yes"
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  lt_cv_cc_needs_belf=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-eval "$as_ac_Header=no"
+	lt_cv_cc_needs_belf=no
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+     ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 fi
+{ echo "$as_me:$LINENO: result: $lt_cv_cc_needs_belf" >&5
+echo "${ECHO_T}$lt_cv_cc_needs_belf" >&6; }
+  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
+    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
+    CFLAGS="$SAVE_CFLAGS"
+  fi
+  ;;
+sparc*-*solaris*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+    case `/usr/bin/file conftest.o` in
+    *64-bit*)
+      case $lt_cv_prog_gnu_ld in
+      yes*) LD="${LD-ld} -m elf64_sparc" ;;
+      *)    LD="${LD-ld} -64" ;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
 
-done
 
+esac
 
+need_locks="$enable_libtool_lock"
 
-for ac_header in sys/mman.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+{ echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5
+echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6; }
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+  CPP=
 fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+if test -z "$CPP"; then
+  if test "${ac_cv_prog_CPP+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
+      # Double quotes because CPP needs to be expanded
+    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
+    do
+      ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-$ac_includes_default
-#include <$ac_header>
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
 _ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_header_compiler=yes
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  :
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_header_compiler=no
+  # Broken: fails on valid input.
+continue
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
 
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#include <$ac_header>
+#include <ac_nonexistent.h>
 _ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
-  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null; then
-  if test -s conftest.err; then
-    ac_cpp_err=$ac_c_preproc_warn_flag
-    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
-  else
-    ac_cpp_err=
-  fi
-else
-  ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
-  ac_header_preproc=yes
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  # Broken: success on invalid input.
+continue
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-  ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
-    (
-      cat <<\_ASBOX
-## ------------------------------------------- ##
-## Report this to http://gcc.gnu.org/bugs.html ##
-## ------------------------------------------- ##
-_ASBOX
-    ) |
-      sed "s/^/$as_me: WARNING:     /" >&2
-    ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
+  # Passes both tests.
+ac_preproc_ok=:
+break
 fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
 
-fi
+rm -f conftest.err conftest.$ac_ext
 
 done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
+  break
+fi
 
+    done
+    ac_cv_prog_CPP=$CPP
 
-for ac_func in mmap
-do
-as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
-echo "$as_me:$LINENO: checking for $ac_func" >&5
-echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
-if eval "test \"\${$as_ac_var+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+  CPP=$ac_cv_prog_CPP
 else
+  ac_cv_prog_CPP=$CPP
+fi
+{ echo "$as_me:$LINENO: result: $CPP" >&5
+echo "${ECHO_T}$CPP" >&6; }
+ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
-   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
-#define $ac_func innocuous_$ac_func
-
-/* System header to define __stub macros and hopefully few prototypes,
-    which can conflict with char $ac_func (); below.
-    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
-    <limits.h> exists even on freestanding compilers.  */
-
 #ifdef __STDC__
 # include <limits.h>
 #else
 # include <assert.h>
 #endif
+		     Syntax error
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
 
-#undef $ac_func
+  # Broken: fails on valid input.
+continue
+fi
 
-/* Override any gcc2 internal prototype to avoid an error.  */
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-/* We use char because int might match the return type of a gcc2
-   builtin and then its argument prototype would still apply.  */
-char $ac_func ();
-/* The GNU C library defines this for functions which it implements
-    to always fail with ENOSYS.  Some functions are actually named
-    something starting with __ and the normal name is an alias.  */
-#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
-choke me
-#else
-char (*f) () = $ac_func;
-#endif
-#ifdef __cplusplus
-}
-#endif
+rm -f conftest.err conftest.$ac_ext
 
-int
-main ()
-{
-return f != $ac_func;
-  ;
-  return 0;
-}
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>conftest.er1
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  eval "$as_ac_var=yes"
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  # Broken: success on invalid input.
+continue
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-eval "$as_ac_var=no"
-fi
-rm -f conftest.err conftest.$ac_objext \
-      conftest$ac_exeext conftest.$ac_ext
+  # Passes both tests.
+ac_preproc_ok=:
+break
 fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
-if test `eval echo '${'$as_ac_var'}'` = yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
-_ACEOF
 
-fi
+rm -f conftest.err conftest.$ac_ext
+
 done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
+  :
+else
+  { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." >&5
+echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
 
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+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 "${ac_cv_header_sys_mman_h+set}" = set; then
-  echo "$as_me:$LINENO: checking for sys/mman.h" >&5
-echo $ECHO_N "checking for sys/mman.h... $ECHO_C" >&6
-if test "${ac_cv_header_sys_mman_h+set}" = set; then
+
+{ echo "$as_me:$LINENO: checking for ANSI C header files" >&5
+echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6; }
+if test "${ac_cv_header_stdc+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: $ac_cv_header_sys_mman_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_mman_h" >&6
 else
-  # Is the header compilable?
-echo "$as_me:$LINENO: checking sys/mman.h usability" >&5
-echo $ECHO_N "checking sys/mman.h usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
+  cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-$ac_includes_default
-#include <sys/mman.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_header_compiler=yes
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_header_stdc=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_header_compiler=no
+	ac_cv_header_stdc=no
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
 
-# Is the header present?
-echo "$as_me:$LINENO: checking sys/mman.h presence" >&5
-echo $ECHO_N "checking sys/mman.h presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#include <sys/mman.h>
+#include <string.h>
+
 _ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
-  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null; then
-  if test -s conftest.err; then
-    ac_cpp_err=$ac_c_preproc_warn_flag
-    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
-  else
-    ac_cpp_err=
-  fi
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then
+  :
 else
-  ac_cpp_err=yes
+  ac_cv_header_stdc=no
 fi
-if test -z "$ac_cpp_err"; then
-  ac_header_preproc=yes
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then
+  :
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
 
-  ac_header_preproc=no
 fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
 
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: sys/mman.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: sys/mman.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/mman.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: sys/mman.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: sys/mman.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: sys/mman.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/mman.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: sys/mman.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/mman.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: sys/mman.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/mman.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: sys/mman.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/mman.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: sys/mman.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/mman.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: sys/mman.h: in the future, the compiler will take precedence" >&2;}
-    (
-      cat <<\_ASBOX
-## ------------------------------------------- ##
-## Report this to http://gcc.gnu.org/bugs.html ##
-## ------------------------------------------- ##
-_ASBOX
-    ) |
-      sed "s/^/$as_me: WARNING:     /" >&2
-    ;;
-esac
-echo "$as_me:$LINENO: checking for sys/mman.h" >&5
-echo $ECHO_N "checking for sys/mman.h... $ECHO_C" >&6
-if test "${ac_cv_header_sys_mman_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_sys_mman_h=$ac_header_preproc
-fi
-echo "$as_me:$LINENO: result: $ac_cv_header_sys_mman_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_mman_h" >&6
-
-fi
-if test $ac_cv_header_sys_mman_h = yes; then
-  libffi_header_sys_mman_h=yes
-else
-  libffi_header_sys_mman_h=no
-fi
-
-
-echo "$as_me:$LINENO: checking for mmap" >&5
-echo $ECHO_N "checking for mmap... $ECHO_C" >&6
-if test "${ac_cv_func_mmap+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then
+  :
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -3236,145 +5212,93 @@
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-/* Define mmap to an innocuous variant, in case <limits.h> declares mmap.
-   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
-#define mmap innocuous_mmap
-
-/* System header to define __stub macros and hopefully few prototypes,
-    which can conflict with char mmap (); below.
-    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
-    <limits.h> exists even on freestanding compilers.  */
-
-#ifdef __STDC__
-# include <limits.h>
-#else
-# include <assert.h>
-#endif
-
-#undef mmap
-
-/* Override any gcc2 internal prototype to avoid an error.  */
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-/* We use char because int might match the return type of a gcc2
-   builtin and then its argument prototype would still apply.  */
-char mmap ();
-/* The GNU C library defines this for functions which it implements
-    to always fail with ENOSYS.  Some functions are actually named
-    something starting with __ and the normal name is an alias.  */
-#if defined (__stub_mmap) || defined (__stub___mmap)
-choke me
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
 #else
-char (*f) () = mmap;
-#endif
-#ifdef __cplusplus
-}
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
 #endif
 
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
 int
 main ()
 {
-return f != mmap;
-  ;
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      return 2;
   return 0;
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  ac_cv_func_mmap=yes
+  :
 else
-  echo "$as_me: failed program was:" >&5
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_cv_func_mmap=no
-fi
-rm -f conftest.err conftest.$ac_objext \
-      conftest$ac_exeext conftest.$ac_ext
+( exit $ac_status )
+ac_cv_header_stdc=no
 fi
-echo "$as_me:$LINENO: result: $ac_cv_func_mmap" >&5
-echo "${ECHO_T}$ac_cv_func_mmap" >&6
-if test $ac_cv_func_mmap = yes; then
-  libffi_func_mmap=yes
-else
-  libffi_func_mmap=no
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
 fi
 
-if test "$libffi_header_sys_mman_h" != yes \
- || test "$libffi_func_mmap" != yes; then
-   ac_cv_func_mmap_file=no
-   ac_cv_func_mmap_dev_zero=no
-   ac_cv_func_mmap_anon=no
-else
-   echo "$as_me:$LINENO: checking whether read-only mmap of a plain file works" >&5
-echo $ECHO_N "checking whether read-only mmap of a plain file works... $ECHO_C" >&6
-if test "${ac_cv_func_mmap_file+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  # Add a system to this blacklist if
-   # mmap(0, stat_size, PROT_READ, MAP_PRIVATE, fd, 0) doesn't return a
-   # memory area containing the same data that you'd get if you applied
-   # read() to the same fd.  The only system known to have a problem here
-   # is VMS, where text files have record structure.
-   case "$host_os" in
-     vms* | ultrix*)
-	ac_cv_func_mmap_file=no ;;
-     *)
-	ac_cv_func_mmap_file=yes;;
-   esac
+
 fi
-echo "$as_me:$LINENO: result: $ac_cv_func_mmap_file" >&5
-echo "${ECHO_T}$ac_cv_func_mmap_file" >&6
-   echo "$as_me:$LINENO: checking whether mmap from /dev/zero works" >&5
-echo $ECHO_N "checking whether mmap from /dev/zero works... $ECHO_C" >&6
-if test "${ac_cv_func_mmap_dev_zero+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  # Add a system to this blacklist if it has mmap() but /dev/zero
-   # does not exist, or if mmapping /dev/zero does not give anonymous
-   # zeroed pages with both the following properties:
-   # 1. If you map N consecutive pages in with one call, and then
-   #    unmap any subset of those pages, the pages that were not
-   #    explicitly unmapped remain accessible.
-   # 2. If you map two adjacent blocks of memory and then unmap them
-   #    both at once, they must both go away.
-   # Systems known to be in this category are Windows (all variants),
-   # VMS, and Darwin.
-   case "$host_os" in
-     vms* | cygwin* | pe | mingw* | darwin* | ultrix* | hpux10* | hpux11.00)
-	ac_cv_func_mmap_dev_zero=no ;;
-     *)
-	ac_cv_func_mmap_dev_zero=yes;;
-   esac
 fi
-echo "$as_me:$LINENO: result: $ac_cv_func_mmap_dev_zero" >&5
-echo "${ECHO_T}$ac_cv_func_mmap_dev_zero" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5
+echo "${ECHO_T}$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
 
-   # Unlike /dev/zero, the MAP_ANON(YMOUS) defines can be probed for.
-   echo "$as_me:$LINENO: checking for MAP_ANON(YMOUS)" >&5
-echo $ECHO_N "checking for MAP_ANON(YMOUS)... $ECHO_C" >&6
-if test "${ac_cv_decl_map_anon+set}" = set; then
+cat >>confdefs.h <<\_ACEOF
+#define STDC_HEADERS 1
+_ACEOF
+
+fi
+
+# On IRIX 5.3, sys/types and inttypes.h are conflicting.
+
+
+
+
+
+
+
+
+
+for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
+		  inttypes.h stdint.h unistd.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
@@ -3383,273 +5307,348 @@
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <unistd.h>
-
-#ifndef MAP_ANONYMOUS
-#define MAP_ANONYMOUS MAP_ANON
-#endif
+$ac_includes_default
 
-int
-main ()
-{
-int n = MAP_ANONYMOUS;
-  ;
-  return 0;
-}
+#include <$ac_header>
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_cv_decl_map_anon=yes
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  eval "$as_ac_Header=yes"
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_cv_decl_map_anon=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+	eval "$as_ac_Header=no"
 fi
-echo "$as_me:$LINENO: result: $ac_cv_decl_map_anon" >&5
-echo "${ECHO_T}$ac_cv_decl_map_anon" >&6
 
-   if test $ac_cv_decl_map_anon = no; then
-     ac_cv_func_mmap_anon=no
-   else
-     echo "$as_me:$LINENO: checking whether mmap with MAP_ANON(YMOUS) works" >&5
-echo $ECHO_N "checking whether mmap with MAP_ANON(YMOUS) works... $ECHO_C" >&6
-if test "${ac_cv_func_mmap_anon+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  # Add a system to this blacklist if it has mmap() and MAP_ANON or
-   # MAP_ANONYMOUS, but using mmap(..., MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
-   # doesn't give anonymous zeroed pages with the same properties listed
-   # above for use of /dev/zero.
-   # Systems known to be in this category are Windows, VMS, and SCO Unix.
-   case "$host_os" in
-     vms* | cygwin* | pe | mingw* | sco* | udk* )
-	ac_cv_func_mmap_anon=no ;;
-     *)
-	ac_cv_func_mmap_anon=yes;;
-   esac
-fi
-echo "$as_me:$LINENO: result: $ac_cv_func_mmap_anon" >&5
-echo "${ECHO_T}$ac_cv_func_mmap_anon" >&6
-   fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-
-if test $ac_cv_func_mmap_file = yes; then
-
-cat >>confdefs.h <<\_ACEOF
-#define HAVE_MMAP_FILE 1
+ac_res=`eval echo '${'$as_ac_Header'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
 
 fi
-if test $ac_cv_func_mmap_dev_zero = yes; then
 
-cat >>confdefs.h <<\_ACEOF
-#define HAVE_MMAP_DEV_ZERO 1
-_ACEOF
+done
 
-fi
-if test $ac_cv_func_mmap_anon = yes; then
 
-cat >>confdefs.h <<\_ACEOF
-#define HAVE_MMAP_ANON 1
-_ACEOF
 
+for ac_header in dlfcn.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  { echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 fi
-
-
-TARGETDIR="unknown"
-case "$host" in
-x86_64-*-openbsd*) TARGET=X86_64; TARGETDIR=x86;;
-mips*-*-openbsd*) TARGET=MIPS; TARGETDIR=mips;;
-sparc-*-openbsd*) TARGET=SPARC; TARGETDIR=sparc;;
-sparc64-*-openbsd*) TARGET=SPARC; TARGETDIR=sparc;;
-alpha*-*-openbsd*) TARGET=ALPHA; TARGETDIR=alpha;;
-m68k-*-openbsd*) TARGET=M68K; TARGETDIR=m68k;;
-powerpc-*-openbsd*) TARGET=POWERPC; TARGETDIR=powerpc;;
-i*86-*-darwin*) TARGET=X86_DARWIN; TARGETDIR=x86;;
-i*86-*-linux*) TARGET=X86; TARGETDIR=x86;;
-i*86-*-gnu*) TARGET=X86; TARGETDIR=x86;;
-i*86-*-solaris2.1[0-9]*) TARGET=X86_64; TARGETDIR=x86;;
-i*86-*-solaris*) TARGET=X86; TARGETDIR=x86;;
-i*86-*-beos*) TARGET=X86; TARGETDIR=x86;;
-i*86-*-freebsd* | i*86-*-kfreebsd*-gnu) TARGET=X86; TARGETDIR=x86;;
-i*86-*-netbsdelf* | i*86-*-knetbsd*-gnu) TARGET=X86; TARGETDIR=x86;;
-i*86-*-openbsd*) TARGET=X86; TARGETDIR=x86;;
-i*86-*-rtems*) TARGET=X86; TARGETDIR=x86;;
-i*86-*-win32*) TARGET=X86_WIN32; TARGETDIR=x86;;
-i*86-*-cygwin*) TARGET=X86_WIN32; TARGETDIR=x86;;
-i*86-*-mingw*) TARGET=X86_WIN32; TARGETDIR=x86;;
-frv-*-*) TARGET=FRV; TARGETDIR=frv;;
-sparc-sun-4*) TARGET=SPARC; TARGETDIR=sparc;;
-sparc*-sun-*) TARGET=SPARC; TARGETDIR=sparc;;
-sparc-*-linux* | sparc-*-netbsdelf* | sparc-*-knetbsd*-gnu) TARGET=SPARC; TARGETDIR=sparc;;
-sparc*-*-rtems*) TARGET=SPARC; TARGETDIR=sparc;;
-sparc64-*-linux* | sparc64-*-freebsd* | sparc64-*-netbsd* | sparc64-*-knetbsd*-gnu) TARGET=SPARC; TARGETDIR=sparc;;
-alpha*-*-linux* | alpha*-*-osf* | alpha*-*-freebsd* | alpha*-*-kfreebsd*-gnu | alpha*-*-netbsd* | alpha*-*-knetbsd*-gnu) TARGET=ALPHA; TARGETDIR=alpha;;
-ia64*-*-*) TARGET=IA64; TARGETDIR=ia64;;
-m32r*-*-linux* ) TARGET=M32R; TARGETDIR=m32r;;
-m68k-*-linux*) TARGET=M68K; TARGETDIR=m68k;;
-mips64*-*);;
-mips-sgi-irix5.* | mips-sgi-irix6.*) TARGET=MIPS_IRIX; TARGETDIR=mips;;
-mips*-*-linux*) TARGET=MIPS_LINUX; TARGETDIR=mips;;
-powerpc*-*-linux* | powerpc-*-sysv*) TARGET=POWERPC; TARGETDIR=powerpc;;
-powerpc-*-beos*) TARGET=POWERPC; TARGETDIR=powerpc;;
-powerpc-*-darwin*) TARGET=POWERPC_DARWIN; TARGETDIR=powerpc;;
-powerpc-*-aix*) TARGET=POWERPC_AIX; TARGETDIR=powerpc;;
-powerpc-*-freebsd*) TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc;;
-powerpc*-*-rtems*) TARGET=POWERPC; TARGETDIR=powerpc;;
-rs6000-*-aix*) TARGET=POWERPC_AIX; TARGETDIR=powerpc;;
-arm*-*-linux-*) TARGET=ARM; TARGETDIR=arm;;
-arm*-*-netbsdelf* | arm*-*-knetbsd*-gnu) TARGET=ARM; TARGETDIR=arm;;
-arm*-*-rtems*) TARGET=ARM; TARGETDIR=arm;;
-cris-*-*) TARGET=LIBFFI_CRIS; TARGETDIR=cris;;
-s390-*-linux-*) TARGET=S390; TARGETDIR=s390;;
-s390x-*-linux-*) TARGET=S390; TARGETDIR=s390;;
-x86_64-*-linux* | x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu) TARGET=X86_64; TARGETDIR=x86;;
-sh-*-linux* | sh[34]*-*-linux*) TARGET=SH; TARGETDIR=sh;;
-sh-*-rtems*) TARGET=SH; TARGETDIR=sh;;
-sh64-*-linux* | sh5*-*-linux*) TARGET=SH64; TARGETDIR=sh64;;
-hppa*-*-linux* | parisc*-*-linux*) TARGET=PA; TARGETDIR=pa;;
-esac
-
-if test $TARGETDIR = unknown; then
-  { { echo "$as_me:$LINENO: error: \"libffi has not been ported to $host.\"" >&5
-echo "$as_me: error: \"libffi has not been ported to $host.\"" >&2;}
-   { (exit 1); exit 1; }; }
-fi
-
-MKTARGET=$TARGET
-
-case x$TARGET in
-  xMIPS*) TARGET=MIPS ;;
-  *) ;;
-esac
-
-echo "$as_me:$LINENO: checking for ANSI C header files" >&5
-echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6
-if test "${ac_cv_header_stdc+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+ac_res=`eval echo '${'$as_ac_Header'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  # Is the header compilable?
+{ echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <float.h>
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
+$ac_includes_default
+#include <$ac_header>
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_cv_header_stdc=yes
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_cv_header_stdc=no
+	ac_header_compiler=no
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
 
-if test $ac_cv_header_stdc = yes; then
-  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
-  cat >conftest.$ac_ext <<_ACEOF
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#include <string.h>
-
+#include <$ac_header>
 _ACEOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  $EGREP "memchr" >/dev/null 2>&1; then
-  :
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
 else
-  ac_cv_header_stdc=no
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
 fi
-rm -f conftest*
 
+rm -f conftest.err conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
+    ( cat <<\_ASBOX
+## ------------------------------------------- ##
+## Report this to http://gcc.gnu.org/bugs.html ##
+## ------------------------------------------- ##
+_ASBOX
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+{ echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  eval "$as_ac_Header=\$ac_header_preproc"
 fi
+ac_res=`eval echo '${'$as_ac_Header'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
 
-if test $ac_cv_header_stdc = yes; then
-  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <stdlib.h>
 
-_ACEOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  $EGREP "free" >/dev/null 2>&1; then
-  :
+fi
+
+done
+
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+if test -z "$CXX"; then
+  if test -n "$CCC"; then
+    CXX=$CCC
+  else
+    if test -n "$ac_tool_prefix"; then
+  for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_CXX+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  ac_cv_header_stdc=no
+  if test -n "$CXX"; then
+  ac_cv_prog_CXX="$CXX" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_CXX="$ac_tool_prefix$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
 fi
-rm -f conftest*
+fi
+CXX=$ac_cv_prog_CXX
+if test -n "$CXX"; then
+  { echo "$as_me:$LINENO: result: $CXX" >&5
+echo "${ECHO_T}$CXX" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+
+    test -n "$CXX" && break
+  done
+fi
+if test -z "$CXX"; then
+  ac_ct_CXX=$CXX
+  for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CXX"; then
+  ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_CXX="$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
 
 fi
+fi
+ac_ct_CXX=$ac_cv_prog_ac_ct_CXX
+if test -n "$ac_ct_CXX"; then
+  { echo "$as_me:$LINENO: result: $ac_ct_CXX" >&5
+echo "${ECHO_T}$ac_ct_CXX" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
 
-if test $ac_cv_header_stdc = yes; then
-  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
-  if test "$cross_compiling" = yes; then
-  :
+
+  test -n "$ac_ct_CXX" && break
+done
+
+  if test "x$ac_ct_CXX" = x; then
+    CXX="g++"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&5
+echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&2;}
+ac_tool_warned=yes ;;
+esac
+    CXX=$ac_ct_CXX
+  fi
+fi
+
+  fi
+fi
+# Provide some information about the compiler.
+echo "$as_me:$LINENO: checking for C++ compiler version" >&5
+ac_compiler=`set X $ac_compile; echo $2`
+{ (ac_try="$ac_compiler --version >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compiler --version >&5") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (ac_try="$ac_compiler -v >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compiler -v >&5") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (ac_try="$ac_compiler -V >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compiler -V >&5") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+
+{ echo "$as_me:$LINENO: checking whether we are using the GNU C++ compiler" >&5
+echo $ECHO_N "checking whether we are using the GNU C++ compiler... $ECHO_C" >&6; }
+if test "${ac_cv_cxx_compiler_gnu+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -3657,233 +5656,15027 @@
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#include <ctype.h>
-#if ((' ' & 0x0FF) == 0x020)
-# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
-# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
-#else
-# define ISLOWER(c) \
-		   (('a' <= (c) && (c) <= 'i') \
-		     || ('j' <= (c) && (c) <= 'r') \
-		     || ('s' <= (c) && (c) <= 'z'))
-# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
-#endif
 
-#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
 int
 main ()
 {
-  int i;
-  for (i = 0; i < 256; i++)
-    if (XOR (islower (i), ISLOWER (i))
-	|| toupper (i) != TOUPPER (i))
-      exit(2);
-  exit (0);
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
 }
 _ACEOF
-rm -f conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  :
+  (exit $ac_status); } && {
+	 test -z "$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_compiler_gnu=yes
 else
-  echo "$as_me: program exited with status $ac_status" >&5
-echo "$as_me: failed program was:" >&5
+  echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-( exit $ac_status )
-ac_cv_header_stdc=no
+	ac_compiler_gnu=no
 fi
-rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
-fi
-fi
-fi
-echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5
-echo "${ECHO_T}$ac_cv_header_stdc" >&6
-if test $ac_cv_header_stdc = yes; then
 
-cat >>confdefs.h <<\_ACEOF
-#define STDC_HEADERS 1
-_ACEOF
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_cxx_compiler_gnu=$ac_compiler_gnu
 
 fi
-
-
-for ac_func in memcpy
-do
-as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
-echo "$as_me:$LINENO: checking for $ac_func" >&5
-echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
-if eval "test \"\${$as_ac_var+set}\" = set"; then
+{ echo "$as_me:$LINENO: result: $ac_cv_cxx_compiler_gnu" >&5
+echo "${ECHO_T}$ac_cv_cxx_compiler_gnu" >&6; }
+GXX=`test $ac_compiler_gnu = yes && echo yes`
+ac_test_CXXFLAGS=${CXXFLAGS+set}
+ac_save_CXXFLAGS=$CXXFLAGS
+{ echo "$as_me:$LINENO: checking whether $CXX accepts -g" >&5
+echo $ECHO_N "checking whether $CXX accepts -g... $ECHO_C" >&6; }
+if test "${ac_cv_prog_cxx_g+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  ac_save_cxx_werror_flag=$ac_cxx_werror_flag
+   ac_cxx_werror_flag=yes
+   ac_cv_prog_cxx_g=no
+   CXXFLAGS="-g"
+   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
-   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
-#define $ac_func innocuous_$ac_func
 
-/* System header to define __stub macros and hopefully few prototypes,
-    which can conflict with char $ac_func (); below.
-    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
-    <limits.h> exists even on freestanding compilers.  */
+int
+main ()
+{
 
-#ifdef __STDC__
-# include <limits.h>
-#else
-# include <assert.h>
-#endif
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_prog_cxx_g=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
 
-#undef $ac_func
+	CXXFLAGS=""
+      cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
 
-/* Override any gcc2 internal prototype to avoid an error.  */
-#ifdef __cplusplus
-extern "C"
+int
+main ()
 {
-#endif
-/* We use char because int might match the return type of a gcc2
-   builtin and then its argument prototype would still apply.  */
-char $ac_func ();
-/* The GNU C library defines this for functions which it implements
-    to always fail with ENOSYS.  Some functions are actually named
-    something starting with __ and the normal name is an alias.  */
-#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
-choke me
-#else
-char (*f) () = $ac_func;
-#endif
-#ifdef __cplusplus
+
+  ;
+  return 0;
 }
-#endif
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+	 CXXFLAGS="-g"
+	 cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
 
 int
 main ()
 {
-return f != $ac_func;
+
   ;
   return 0;
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>conftest.er1
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  eval "$as_ac_var=yes"
+  (exit $ac_status); } && {
+	 test -z "$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_prog_cxx_g=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-eval "$as_ac_var=no"
+
 fi
-rm -f conftest.err conftest.$ac_objext \
-      conftest$ac_exeext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
-if test `eval echo '${'$as_ac_var'}'` = yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
-_ACEOF
 
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-done
 
-# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
-# for constant arguments.  Useless!
-echo "$as_me:$LINENO: checking for working alloca.h" >&5
-echo $ECHO_N "checking for working alloca.h... $ECHO_C" >&6
-if test "${ac_cv_working_alloca_h+set}" = set; then
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_prog_cxx_g" >&5
+echo "${ECHO_T}$ac_cv_prog_cxx_g" >&6; }
+if test "$ac_test_CXXFLAGS" = set; then
+  CXXFLAGS=$ac_save_CXXFLAGS
+elif test $ac_cv_prog_cxx_g = yes; then
+  if test "$GXX" = yes; then
+    CXXFLAGS="-g -O2"
+  else
+    CXXFLAGS="-g"
+  fi
+else
+  if test "$GXX" = yes; then
+    CXXFLAGS="-O2"
+  else
+    CXXFLAGS=
+  fi
+fi
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+depcc="$CXX"  am_compiler_list=
+
+{ echo "$as_me:$LINENO: checking dependency style of $depcc" >&5
+echo $ECHO_N "checking dependency style of $depcc... $ECHO_C" >&6; }
+if test "${am_cv_CXX_dependencies_compiler_type+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_CXX_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp`
+  fi
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    case $depmode in
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    none) break ;;
+    esac
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.
+    if depmode=$depmode \
+       source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_CXX_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_CXX_dependencies_compiler_type=none
+fi
+
+fi
+{ echo "$as_me:$LINENO: result: $am_cv_CXX_dependencies_compiler_type" >&5
+echo "${ECHO_T}$am_cv_CXX_dependencies_compiler_type" >&6; }
+CXXDEPMODE=depmode=$am_cv_CXX_dependencies_compiler_type
+
+ if
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_CXX_dependencies_compiler_type" = gcc3; then
+  am__fastdepCXX_TRUE=
+  am__fastdepCXX_FALSE='#'
+else
+  am__fastdepCXX_TRUE='#'
+  am__fastdepCXX_FALSE=
+fi
+
+
+
+
+if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
+    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
+    (test "X$CXX" != "Xg++"))) ; then
+  ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+{ echo "$as_me:$LINENO: checking how to run the C++ preprocessor" >&5
+echo $ECHO_N "checking how to run the C++ preprocessor... $ECHO_C" >&6; }
+if test -z "$CXXCPP"; then
+  if test "${ac_cv_prog_CXXCPP+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
+      # Double quotes because CXXCPP needs to be expanded
+    for CXXCPP in "$CXX -E" "/lib/cpp"
+    do
+      ac_preproc_ok=false
+for ac_cxx_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#include <alloca.h>
-int
-main ()
-{
-char *p = (char *) alloca (2 * sizeof (int));
-  ;
-  return 0;
-}
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>conftest.er1
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Broken: fails on valid input.
+continue
+fi
+
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
   ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  # Broken: success on invalid input.
+continue
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+
+rm -f conftest.err conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
+  break
+fi
+
+    done
+    ac_cv_prog_CXXCPP=$CXXCPP
+
+fi
+  CXXCPP=$ac_cv_prog_CXXCPP
+else
+  ac_cv_prog_CXXCPP=$CXXCPP
+fi
+{ echo "$as_me:$LINENO: result: $CXXCPP" >&5
+echo "${ECHO_T}$CXXCPP" >&6; }
+ac_preproc_ok=false
+for ac_cxx_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
   ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_cv_working_alloca_h=yes
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  :
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_cv_working_alloca_h=no
+  # Broken: fails on valid input.
+continue
+fi
+
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  # Broken: success on invalid input.
+continue
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+
+rm -f conftest.err conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
+  :
+else
+  { { echo "$as_me:$LINENO: error: C++ preprocessor \"$CXXCPP\" fails sanity check
+See \`config.log' for more details." >&5
+echo "$as_me: error: C++ preprocessor \"$CXXCPP\" fails sanity check
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+fi
+
+
+ac_ext=f
+ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&5'
+ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_f77_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  for ac_prog in g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77 xlf90 f90 pgf90 pghpf epcf90 gfortran g95 xlf95 f95 fort ifort ifc efc pgf95 lf95 ftn
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_F77+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$F77"; then
+  ac_cv_prog_F77="$F77" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_F77="$ac_tool_prefix$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+F77=$ac_cv_prog_F77
+if test -n "$F77"; then
+  { echo "$as_me:$LINENO: result: $F77" >&5
+echo "${ECHO_T}$F77" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+
+    test -n "$F77" && break
+  done
+fi
+if test -z "$F77"; then
+  ac_ct_F77=$F77
+  for ac_prog in g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77 xlf90 f90 pgf90 pghpf epcf90 gfortran g95 xlf95 f95 fort ifort ifc efc pgf95 lf95 ftn
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_ac_ct_F77+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_F77"; then
+  ac_cv_prog_ac_ct_F77="$ac_ct_F77" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_F77="$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_F77=$ac_cv_prog_ac_ct_F77
+if test -n "$ac_ct_F77"; then
+  { echo "$as_me:$LINENO: result: $ac_ct_F77" >&5
+echo "${ECHO_T}$ac_ct_F77" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+
+  test -n "$ac_ct_F77" && break
+done
+
+  if test "x$ac_ct_F77" = x; then
+    F77=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&5
+echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&2;}
+ac_tool_warned=yes ;;
+esac
+    F77=$ac_ct_F77
+  fi
+fi
+
+
+# Provide some information about the compiler.
+echo "$as_me:$LINENO: checking for Fortran 77 compiler version" >&5
+ac_compiler=`set X $ac_compile; echo $2`
+{ (ac_try="$ac_compiler --version >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compiler --version >&5") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (ac_try="$ac_compiler -v >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compiler -v >&5") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (ac_try="$ac_compiler -V >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compiler -V >&5") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+rm -f a.out
+
+# If we don't use `.F' as extension, the preprocessor is not run on the
+# input file.  (Note that this only needs to work for GNU compilers.)
+ac_save_ext=$ac_ext
+ac_ext=F
+{ echo "$as_me:$LINENO: checking whether we are using the GNU Fortran 77 compiler" >&5
+echo $ECHO_N "checking whether we are using the GNU Fortran 77 compiler... $ECHO_C" >&6; }
+if test "${ac_cv_f77_compiler_gnu+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+      program main
+#ifndef __GNUC__
+       choke me
+#endif
+
+      end
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_f77_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_compiler_gnu=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_compiler_gnu=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_f77_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_f77_compiler_gnu" >&5
+echo "${ECHO_T}$ac_cv_f77_compiler_gnu" >&6; }
+ac_ext=$ac_save_ext
+ac_test_FFLAGS=${FFLAGS+set}
+ac_save_FFLAGS=$FFLAGS
+FFLAGS=
+{ echo "$as_me:$LINENO: checking whether $F77 accepts -g" >&5
+echo $ECHO_N "checking whether $F77 accepts -g... $ECHO_C" >&6; }
+if test "${ac_cv_prog_f77_g+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  FFLAGS=-g
+cat >conftest.$ac_ext <<_ACEOF
+      program main
+
+      end
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_f77_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_prog_f77_g=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_prog_f77_g=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_prog_f77_g" >&5
+echo "${ECHO_T}$ac_cv_prog_f77_g" >&6; }
+if test "$ac_test_FFLAGS" = set; then
+  FFLAGS=$ac_save_FFLAGS
+elif test $ac_cv_prog_f77_g = yes; then
+  if test "x$ac_cv_f77_compiler_gnu" = xyes; then
+    FFLAGS="-g -O2"
+  else
+    FFLAGS="-g"
+  fi
+else
+  if test "x$ac_cv_f77_compiler_gnu" = xyes; then
+    FFLAGS="-O2"
+  else
+    FFLAGS=
+  fi
+fi
+
+G77=`test $ac_compiler_gnu = yes && echo yes`
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+# Autoconf 2.13's AC_OBJEXT and AC_EXEEXT macros only works for C compilers!
+
+# find the maximum length of command line arguments
+{ echo "$as_me:$LINENO: checking the maximum length of command line arguments" >&5
+echo $ECHO_N "checking the maximum length of command line arguments... $ECHO_C" >&6; }
+if test "${lt_cv_sys_max_cmd_len+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+    i=0
+  teststring="ABCD"
+
+  case $build_os in
+  msdosdjgpp*)
+    # On DJGPP, this test can blow up pretty badly due to problems in libc
+    # (any single argument exceeding 2000 bytes causes a buffer overrun
+    # during glob expansion).  Even if it were fixed, the result of this
+    # check would be larger than it should be.
+    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
+    ;;
+
+  gnu*)
+    # Under GNU Hurd, this test is not required because there is
+    # no limit to the length of command line arguments.
+    # Libtool will interpret -1 as no limit whatsoever
+    lt_cv_sys_max_cmd_len=-1;
+    ;;
+
+  cygwin* | mingw*)
+    # On Win9x/ME, this test blows up -- it succeeds, but takes
+    # about 5 minutes as the teststring grows exponentially.
+    # Worse, since 9x/ME are not pre-emptively multitasking,
+    # you end up with a "frozen" computer, even though with patience
+    # the test eventually succeeds (with a max line length of 256k).
+    # Instead, let's just punt: use the minimum linelength reported by
+    # all of the supported platforms: 8192 (on NT/2K/XP).
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  amigaos*)
+    # On AmigaOS with pdksh, this test takes hours, literally.
+    # So we just punt and use a minimum line length of 8192.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
+    # This has been around since 386BSD, at least.  Likely further.
+    if test -x /sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
+    elif test -x /usr/sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
+    else
+      lt_cv_sys_max_cmd_len=65536	# usable default for all BSDs
+    fi
+    # And add a safety zone
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    ;;
+
+  interix*)
+    # We know the value 262144 and hardcode it with a safety zone (like BSD)
+    lt_cv_sys_max_cmd_len=196608
+    ;;
+
+  osf*)
+    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
+    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
+    # nice to cause kernel panics so lets avoid the loop below.
+    # First set a reasonable default.
+    lt_cv_sys_max_cmd_len=16384
+    #
+    if test -x /sbin/sysconfig; then
+      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
+        *1*) lt_cv_sys_max_cmd_len=-1 ;;
+      esac
+    fi
+    ;;
+  sco3.2v5*)
+    lt_cv_sys_max_cmd_len=102400
+    ;;
+  sysv5* | sco5v6* | sysv4.2uw2*)
+    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
+    if test -n "$kargmax"; then
+      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[ 	]//'`
+    else
+      lt_cv_sys_max_cmd_len=32768
+    fi
+    ;;
+  *)
+    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
+    if test -n "$lt_cv_sys_max_cmd_len"; then
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    else
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
+      while (test "X"`$SHELL $0 --fallback-echo "X$teststring" 2>/dev/null` \
+	       = "XX$teststring") >/dev/null 2>&1 &&
+	      new_result=`expr "X$teststring" : ".*" 2>&1` &&
+	      lt_cv_sys_max_cmd_len=$new_result &&
+	      test $i != 17 # 1/2 MB should be enough
+      do
+        i=`expr $i + 1`
+        teststring=$teststring$teststring
+      done
+      teststring=
+      # Add a significant safety factor because C++ compilers can tack on massive
+      # amounts of additional arguments before passing them to the linker.
+      # It appears as though 1/2 is a usable value.
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    fi
+    ;;
+  esac
+
+fi
+
+if test -n $lt_cv_sys_max_cmd_len ; then
+  { echo "$as_me:$LINENO: result: $lt_cv_sys_max_cmd_len" >&5
+echo "${ECHO_T}$lt_cv_sys_max_cmd_len" >&6; }
+else
+  { echo "$as_me:$LINENO: result: none" >&5
+echo "${ECHO_T}none" >&6; }
+fi
+
+
+
+
+
+# Check for command to grab the raw symbol name followed by C symbol from nm.
+{ echo "$as_me:$LINENO: checking command to parse $NM output from $compiler object" >&5
+echo $ECHO_N "checking command to parse $NM output from $compiler object... $ECHO_C" >&6; }
+if test "${lt_cv_sys_global_symbol_pipe+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+# These are sane defaults that work on at least a few old systems.
+# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
+
+# Character class describing NM global symbol codes.
+symcode='[BCDEGRST]'
+
+# Regexp to match symbols that can be accessed directly from C.
+sympat='\([_A-Za-z][_A-Za-z0-9]*\)'
+
+# Transform an extracted symbol line into a proper C declaration
+lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^. .* \(.*\)$/extern int \1;/p'"
+
+# Transform an extracted symbol line into symbol name and symbol address
+lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\) $/  {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode \([^ ]*\) \([^ ]*\)$/  {\"\2\", (lt_ptr) \&\2},/p'"
+
+# Define system-specific variables.
+case $host_os in
+aix*)
+  symcode='[BCDT]'
+  ;;
+cygwin* | mingw* | pw32*)
+  symcode='[ABCDGISTW]'
+  ;;
+hpux*) # Its linker distinguishes data from code symbols
+  if test "$host_cpu" = ia64; then
+    symcode='[ABCDEGRST]'
+  fi
+  lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+  lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\) $/  {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/  {\"\2\", (lt_ptr) \&\2},/p'"
+  ;;
+linux* | k*bsd*-gnu)
+  if test "$host_cpu" = ia64; then
+    symcode='[ABCDGIRSTW]'
+    lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+    lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\) $/  {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/  {\"\2\", (lt_ptr) \&\2},/p'"
+  fi
+  ;;
+irix* | nonstopux*)
+  symcode='[BCDEGRST]'
+  ;;
+osf*)
+  symcode='[BCDEGQRST]'
+  ;;
+solaris*)
+  symcode='[BDRT]'
+  ;;
+sco3.2v5*)
+  symcode='[DT]'
+  ;;
+sysv4.2uw2*)
+  symcode='[DT]'
+  ;;
+sysv5* | sco5v6* | unixware* | OpenUNIX*)
+  symcode='[ABDT]'
+  ;;
+sysv4)
+  symcode='[DFNSTU]'
+  ;;
+esac
+
+# Handle CRLF in mingw tool chain
+opt_cr=
+case $build_os in
+mingw*)
+  opt_cr=`echo 'x\{0,1\}' | tr x '\015'` # option cr in regexp
+  ;;
+esac
+
+# If we're using GNU nm, then use its standard symbol codes.
+case `$NM -V 2>&1` in
+*GNU* | *'with BFD'*)
+  symcode='[ABCDGIRSTW]' ;;
+esac
+
+# Try without a prefix undercore, then with it.
+for ac_symprfx in "" "_"; do
+
+  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
+  symxfrm="\\1 $ac_symprfx\\2 \\2"
+
+  # Write the raw and C identifiers.
+  lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[ 	]\($symcode$symcode*\)[ 	][ 	]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
+
+  # Check to see that the pipe works correctly.
+  pipe_works=no
+
+  rm -f conftest*
+  cat > conftest.$ac_ext <<EOF
+#ifdef __cplusplus
+extern "C" {
+#endif
+char nm_test_var;
+void nm_test_func(){}
+#ifdef __cplusplus
+}
+#endif
+int main(){nm_test_var='a';nm_test_func();return(0);}
+EOF
+
+  if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+    # Now try to grab the symbols.
+    nlist=conftest.nm
+    if { (eval echo "$as_me:$LINENO: \"$NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist\"") >&5
+  (eval $NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && test -s "$nlist"; then
+      # Try sorting and uniquifying the output.
+      if sort "$nlist" | uniq > "$nlist"T; then
+	mv -f "$nlist"T "$nlist"
+      else
+	rm -f "$nlist"T
+      fi
+
+      # Make sure that we snagged all the symbols we need.
+      if grep ' nm_test_var$' "$nlist" >/dev/null; then
+	if grep ' nm_test_func$' "$nlist" >/dev/null; then
+	  cat <<EOF > conftest.$ac_ext
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+EOF
+	  # Now generate the symbol file.
+	  eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | grep -v main >> conftest.$ac_ext'
+
+	  cat <<EOF >> conftest.$ac_ext
+#if defined (__STDC__) && __STDC__
+# define lt_ptr_t void *
+#else
+# define lt_ptr_t char *
+# define const
+#endif
+
+/* The mapping between symbol names and symbols. */
+const struct {
+  const char *name;
+  lt_ptr_t address;
+}
+lt_preloaded_symbols[] =
+{
+EOF
+	  $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (lt_ptr_t) \&\2},/" < "$nlist" | grep -v main >> conftest.$ac_ext
+	  cat <<\EOF >> conftest.$ac_ext
+  {0, (lt_ptr_t) 0}
+};
+
+#ifdef __cplusplus
+}
+#endif
+EOF
+	  # Now try linking the two files.
+	  mv conftest.$ac_objext conftstm.$ac_objext
+	  lt_save_LIBS="$LIBS"
+	  lt_save_CFLAGS="$CFLAGS"
+	  LIBS="conftstm.$ac_objext"
+	  CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag"
+	  if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && test -s conftest${ac_exeext}; then
+	    pipe_works=yes
+	  fi
+	  LIBS="$lt_save_LIBS"
+	  CFLAGS="$lt_save_CFLAGS"
+	else
+	  echo "cannot find nm_test_func in $nlist" >&5
+	fi
+      else
+	echo "cannot find nm_test_var in $nlist" >&5
+      fi
+    else
+      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5
+    fi
+  else
+    echo "$progname: failed program was:" >&5
+    cat conftest.$ac_ext >&5
+  fi
+  rm -f conftest* conftst*
+
+  # Do not use the global_symbol_pipe unless it works.
+  if test "$pipe_works" = yes; then
+    break
+  else
+    lt_cv_sys_global_symbol_pipe=
+  fi
+done
+
+fi
+
+if test -z "$lt_cv_sys_global_symbol_pipe"; then
+  lt_cv_sys_global_symbol_to_cdecl=
+fi
+if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
+  { echo "$as_me:$LINENO: result: failed" >&5
+echo "${ECHO_T}failed" >&6; }
+else
+  { echo "$as_me:$LINENO: result: ok" >&5
+echo "${ECHO_T}ok" >&6; }
+fi
+
+{ echo "$as_me:$LINENO: checking for objdir" >&5
+echo $ECHO_N "checking for objdir... $ECHO_C" >&6; }
+if test "${lt_cv_objdir+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  rm -f .libs 2>/dev/null
+mkdir .libs 2>/dev/null
+if test -d .libs; then
+  lt_cv_objdir=.libs
+else
+  # MS-DOS does not allow filenames that begin with a dot.
+  lt_cv_objdir=_libs
+fi
+rmdir .libs 2>/dev/null
+fi
+{ echo "$as_me:$LINENO: result: $lt_cv_objdir" >&5
+echo "${ECHO_T}$lt_cv_objdir" >&6; }
+objdir=$lt_cv_objdir
+
+
+
+
+
+case $host_os in
+aix3*)
+  # AIX sometimes has problems with the GCC collect2 program.  For some
+  # reason, if we set the COLLECT_NAMES environment variable, the problems
+  # vanish in a puff of smoke.
+  if test "X${COLLECT_NAMES+set}" != Xset; then
+    COLLECT_NAMES=
+    export COLLECT_NAMES
+  fi
+  ;;
+esac
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+Xsed='sed -e 1s/^X//'
+sed_quote_subst='s/\([\\"\\`$\\\\]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\([\\"\\`\\\\]\)/\\\1/g'
+
+# Sed substitution to delay expansion of an escaped shell variable in a
+# double_quote_subst'ed string.
+delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
+
+# Sed substitution to avoid accidental globbing in evaled expressions
+no_glob_subst='s/\*/\\\*/g'
+
+# Constants:
+rm="rm -f"
+
+# Global variables:
+default_ofile=libtool
+can_build_shared=yes
+
+# All known linkers require a `.a' archive for static linking (except MSVC,
+# which needs '.lib').
+libext=a
+ltmain="$ac_aux_dir/ltmain.sh"
+ofile="$default_ofile"
+with_gnu_ld="$lt_cv_prog_gnu_ld"
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ar; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_AR+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$AR"; then
+  ac_cv_prog_AR="$AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_AR="${ac_tool_prefix}ar"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+AR=$ac_cv_prog_AR
+if test -n "$AR"; then
+  { echo "$as_me:$LINENO: result: $AR" >&5
+echo "${ECHO_T}$AR" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_AR"; then
+  ac_ct_AR=$AR
+  # Extract the first word of "ar", so it can be a program name with args.
+set dummy ar; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_ac_ct_AR+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_AR"; then
+  ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_AR="ar"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_AR=$ac_cv_prog_ac_ct_AR
+if test -n "$ac_ct_AR"; then
+  { echo "$as_me:$LINENO: result: $ac_ct_AR" >&5
+echo "${ECHO_T}$ac_ct_AR" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+  if test "x$ac_ct_AR" = x; then
+    AR="false"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&5
+echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&2;}
+ac_tool_warned=yes ;;
+esac
+    AR=$ac_ct_AR
+  fi
+else
+  AR="$ac_cv_prog_AR"
+fi
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_RANLIB+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  { echo "$as_me:$LINENO: result: $RANLIB" >&5
+echo "${ECHO_T}$RANLIB" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_RANLIB="ranlib"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  { echo "$as_me:$LINENO: result: $ac_ct_RANLIB" >&5
+echo "${ECHO_T}$ac_ct_RANLIB" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+  if test "x$ac_ct_RANLIB" = x; then
+    RANLIB=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&5
+echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&2;}
+ac_tool_warned=yes ;;
+esac
+    RANLIB=$ac_ct_RANLIB
+  fi
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
+set dummy ${ac_tool_prefix}strip; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_STRIP+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$STRIP"; then
+  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_STRIP="${ac_tool_prefix}strip"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+STRIP=$ac_cv_prog_STRIP
+if test -n "$STRIP"; then
+  { echo "$as_me:$LINENO: result: $STRIP" >&5
+echo "${ECHO_T}$STRIP" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_STRIP"; then
+  ac_ct_STRIP=$STRIP
+  # Extract the first word of "strip", so it can be a program name with args.
+set dummy strip; ac_word=$2
+{ echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
+if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_STRIP"; then
+  ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_prog_ac_ct_STRIP="strip"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP
+if test -n "$ac_ct_STRIP"; then
+  { echo "$as_me:$LINENO: result: $ac_ct_STRIP" >&5
+echo "${ECHO_T}$ac_ct_STRIP" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+  if test "x$ac_ct_STRIP" = x; then
+    STRIP=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&5
+echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools
+whose name does not start with the host triplet.  If you think this
+configuration is useful to you, please write to autoconf at gnu.org." >&2;}
+ac_tool_warned=yes ;;
+esac
+    STRIP=$ac_ct_STRIP
+  fi
+else
+  STRIP="$ac_cv_prog_STRIP"
+fi
+
+
+old_CC="$CC"
+old_CFLAGS="$CFLAGS"
+
+# Set sane defaults for various variables
+test -z "$AR" && AR=ar
+test -z "$AR_FLAGS" && AR_FLAGS=cru
+test -z "$AS" && AS=as
+test -z "$CC" && CC=cc
+test -z "$LTCC" && LTCC=$CC
+test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
+test -z "$DLLTOOL" && DLLTOOL=dlltool
+test -z "$LD" && LD=ld
+test -z "$LN_S" && LN_S="ln -s"
+test -z "$MAGIC_CMD" && MAGIC_CMD=file
+test -z "$NM" && NM=nm
+test -z "$SED" && SED=sed
+test -z "$OBJDUMP" && OBJDUMP=objdump
+test -z "$RANLIB" && RANLIB=:
+test -z "$STRIP" && STRIP=:
+test -z "$ac_objext" && ac_objext=o
+
+# Determine commands to create old-style static archives.
+old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
+old_postinstall_cmds='chmod 644 $oldlib'
+old_postuninstall_cmds=
+
+if test -n "$RANLIB"; then
+  case $host_os in
+  openbsd*)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib"
+    ;;
+  *)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib"
+    ;;
+  esac
+  old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
+fi
+
+for cc_temp in $compiler""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+
+
+# Only perform the check for file, if the check method requires it
+case $deplibs_check_method in
+file_magic*)
+  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
+    { echo "$as_me:$LINENO: checking for ${ac_tool_prefix}file" >&5
+echo $ECHO_N "checking for ${ac_tool_prefix}file... $ECHO_C" >&6; }
+if test "${lt_cv_path_MAGIC_CMD+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  case $MAGIC_CMD in
+[\\/*] |  ?:[\\/]*)
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  ac_dummy="/usr/bin$PATH_SEPARATOR$PATH"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/${ac_tool_prefix}file; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/${ac_tool_prefix}file"
+      if test -n "$file_magic_test_file"; then
+	case $deplibs_check_method in
+	"file_magic "*)
+	  file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+	  MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+	  if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+	    $EGREP "$file_magic_regex" > /dev/null; then
+	    :
+	  else
+	    cat <<EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool at gnu.org
+
+EOF
+	  fi ;;
+	esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac
+fi
+
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  { echo "$as_me:$LINENO: result: $MAGIC_CMD" >&5
+echo "${ECHO_T}$MAGIC_CMD" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+if test -z "$lt_cv_path_MAGIC_CMD"; then
+  if test -n "$ac_tool_prefix"; then
+    { echo "$as_me:$LINENO: checking for file" >&5
+echo $ECHO_N "checking for file... $ECHO_C" >&6; }
+if test "${lt_cv_path_MAGIC_CMD+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  case $MAGIC_CMD in
+[\\/*] |  ?:[\\/]*)
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  ac_dummy="/usr/bin$PATH_SEPARATOR$PATH"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/file; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/file"
+      if test -n "$file_magic_test_file"; then
+	case $deplibs_check_method in
+	"file_magic "*)
+	  file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+	  MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+	  if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+	    $EGREP "$file_magic_regex" > /dev/null; then
+	    :
+	  else
+	    cat <<EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool at gnu.org
+
+EOF
+	  fi ;;
+	esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac
+fi
+
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  { echo "$as_me:$LINENO: result: $MAGIC_CMD" >&5
+echo "${ECHO_T}$MAGIC_CMD" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+
+  else
+    MAGIC_CMD=:
+  fi
+fi
+
+  fi
+  ;;
+esac
+
+enable_dlopen=no
+enable_win32_dll=no
+
+# Check whether --enable-libtool-lock was given.
+if test "${enable_libtool_lock+set}" = set; then
+  enableval=$enable_libtool_lock;
+fi
+
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+
+
+# Check whether --with-pic was given.
+if test "${with_pic+set}" = set; then
+  withval=$with_pic; pic_mode="$withval"
+else
+  pic_mode=default
+fi
+
+test -z "$pic_mode" && pic_mode=default
+
+# Use C for the default configuration in the libtool script
+tagname=
+lt_save_CC="$CC"
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+# Source file extension for C test sources.
+ac_ext=c
+
+# Object file extension for compiled C test sources.
+objext=o
+objext=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(){return(0);}'
+
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+
+# save warnings/boilerplate of simple test code
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$rm conftest*
+
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$rm conftest*
+
+
+
+lt_prog_compiler_no_builtin_flag=
+
+if test "$GCC" = yes; then
+  lt_prog_compiler_no_builtin_flag=' -fno-builtin'
+
+
+{ echo "$as_me:$LINENO: checking if $compiler supports -fno-rtti -fno-exceptions" >&5
+echo $ECHO_N "checking if $compiler supports -fno-rtti -fno-exceptions... $ECHO_C" >&6; }
+if test "${lt_cv_prog_compiler_rtti_exceptions+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_cv_prog_compiler_rtti_exceptions=no
+  ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="-fno-rtti -fno-exceptions"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:7436: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:7440: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_rtti_exceptions=yes
+     fi
+   fi
+   $rm conftest*
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_rtti_exceptions" >&5
+echo "${ECHO_T}$lt_cv_prog_compiler_rtti_exceptions" >&6; }
+
+if test x"$lt_cv_prog_compiler_rtti_exceptions" = xyes; then
+    lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions"
+else
+    :
+fi
+
+fi
+
+lt_prog_compiler_wl=
+lt_prog_compiler_pic=
+lt_prog_compiler_static=
+
+{ echo "$as_me:$LINENO: checking for $compiler option to produce PIC" >&5
+echo $ECHO_N "checking for $compiler option to produce PIC... $ECHO_C" >&6; }
+
+  if test "$GCC" = yes; then
+    lt_prog_compiler_wl='-Wl,'
+    lt_prog_compiler_static='-static'
+
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	lt_prog_compiler_static='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      # FIXME: we need at least 68020 code to build shared libraries, but
+      # adding the `-m68020' flag to GCC prevents building anything better,
+      # like `-m68040'.
+      lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4'
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      lt_prog_compiler_pic='-DDLL_EXPORT'
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      lt_prog_compiler_pic='-fno-common'
+      ;;
+
+    interix[3-9]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      lt_prog_compiler_can_build_shared=no
+      enable_shared=no
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	lt_prog_compiler_pic=-Kconform_pic
+      fi
+      ;;
+
+    hpux*)
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	lt_prog_compiler_pic='-fPIC'
+	;;
+      esac
+      ;;
+
+    *)
+      lt_prog_compiler_pic='-fPIC'
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      lt_prog_compiler_wl='-Wl,'
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	lt_prog_compiler_static='-Bstatic'
+      else
+	lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+      darwin*)
+        # PIC is the default on this platform
+        # Common symbols not allowed in MH_DYLIB files
+       case $cc_basename in
+         xlc*)
+         lt_prog_compiler_pic='-qnocommon'
+         lt_prog_compiler_wl='-Wl,'
+         ;;
+       esac
+       ;;
+
+    mingw* | cygwin* | pw32* | os2*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      lt_prog_compiler_pic='-DDLL_EXPORT'
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      lt_prog_compiler_wl='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	lt_prog_compiler_pic='+Z'
+	;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      lt_prog_compiler_static='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      lt_prog_compiler_wl='-Wl,'
+      # PIC (with -KPIC) is the default.
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    newsos6)
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    linux* | k*bsd*-gnu)
+      case $cc_basename in
+      icc* | ecc*)
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='-KPIC'
+	lt_prog_compiler_static='-static'
+        ;;
+      pgcc* | pgf77* | pgf90* | pgf95*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+	# which looks to be a dead project)
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='-fpic'
+	lt_prog_compiler_static='-Bstatic'
+        ;;
+      ccc*)
+        lt_prog_compiler_wl='-Wl,'
+        # All Alpha code is PIC.
+        lt_prog_compiler_static='-non_shared'
+        ;;
+      *)
+        case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)
+	  # Sun C 5.9
+	  lt_prog_compiler_pic='-KPIC'
+	  lt_prog_compiler_static='-Bstatic'
+	  lt_prog_compiler_wl='-Wl,'
+	  ;;
+	*Sun\ F*)
+	  # Sun Fortran 8.3 passes all unrecognized flags to the linker
+	  lt_prog_compiler_pic='-KPIC'
+	  lt_prog_compiler_static='-Bstatic'
+	  lt_prog_compiler_wl=''
+	  ;;
+	esac
+	;;
+      esac
+      ;;
+
+    osf3* | osf4* | osf5*)
+      lt_prog_compiler_wl='-Wl,'
+      # All OSF/1 code is PIC.
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    rdos*)
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    solaris*)
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95*)
+	lt_prog_compiler_wl='-Qoption ld ';;
+      *)
+	lt_prog_compiler_wl='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      lt_prog_compiler_wl='-Qoption ld '
+      lt_prog_compiler_pic='-PIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+	lt_prog_compiler_pic='-Kconform_pic'
+	lt_prog_compiler_static='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    unicos*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_can_build_shared=no
+      ;;
+
+    uts4*)
+      lt_prog_compiler_pic='-pic'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    *)
+      lt_prog_compiler_can_build_shared=no
+      ;;
+    esac
+  fi
+
+{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic" >&5
+echo "${ECHO_T}$lt_prog_compiler_pic" >&6; }
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$lt_prog_compiler_pic"; then
+
+{ echo "$as_me:$LINENO: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5
+echo $ECHO_N "checking if $compiler PIC flag $lt_prog_compiler_pic works... $ECHO_C" >&6; }
+if test "${lt_prog_compiler_pic_works+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_prog_compiler_pic_works=no
+  ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$lt_prog_compiler_pic -DPIC"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:7726: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:7730: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_prog_compiler_pic_works=yes
+     fi
+   fi
+   $rm conftest*
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_works" >&5
+echo "${ECHO_T}$lt_prog_compiler_pic_works" >&6; }
+
+if test x"$lt_prog_compiler_pic_works" = xyes; then
+    case $lt_prog_compiler_pic in
+     "" | " "*) ;;
+     *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;;
+     esac
+else
+    lt_prog_compiler_pic=
+     lt_prog_compiler_can_build_shared=no
+fi
+
+fi
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    lt_prog_compiler_pic=
+    ;;
+  *)
+    lt_prog_compiler_pic="$lt_prog_compiler_pic -DPIC"
+    ;;
+esac
+
+#
+# Check to make sure the static flag actually works.
+#
+wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\"
+{ echo "$as_me:$LINENO: checking if $compiler static flag $lt_tmp_static_flag works" >&5
+echo $ECHO_N "checking if $compiler static flag $lt_tmp_static_flag works... $ECHO_C" >&6; }
+if test "${lt_prog_compiler_static_works+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_prog_compiler_static_works=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $lt_tmp_static_flag"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&5
+       $echo "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         lt_prog_compiler_static_works=yes
+       fi
+     else
+       lt_prog_compiler_static_works=yes
+     fi
+   fi
+   $rm conftest*
+   LDFLAGS="$save_LDFLAGS"
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_prog_compiler_static_works" >&5
+echo "${ECHO_T}$lt_prog_compiler_static_works" >&6; }
+
+if test x"$lt_prog_compiler_static_works" = xyes; then
+    :
+else
+    lt_prog_compiler_static=
+fi
+
+
+{ echo "$as_me:$LINENO: checking if $compiler supports -c -o file.$ac_objext" >&5
+echo $ECHO_N "checking if $compiler supports -c -o file.$ac_objext... $ECHO_C" >&6; }
+if test "${lt_cv_prog_compiler_c_o+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_cv_prog_compiler_c_o=no
+   $rm -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:7830: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&5
+   echo "$as_me:7834: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_c_o=yes
+     fi
+   fi
+   chmod u+w . 2>&5
+   $rm conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files
+   $rm out/* && rmdir out
+   cd ..
+   rmdir conftest
+   $rm conftest*
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_c_o" >&5
+echo "${ECHO_T}$lt_cv_prog_compiler_c_o" >&6; }
+
+
+hard_links="nottested"
+if test "$lt_cv_prog_compiler_c_o" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  { echo "$as_me:$LINENO: checking if we can lock with hard links" >&5
+echo $ECHO_N "checking if we can lock with hard links... $ECHO_C" >&6; }
+  hard_links=yes
+  $rm conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  { echo "$as_me:$LINENO: result: $hard_links" >&5
+echo "${ECHO_T}$hard_links" >&6; }
+  if test "$hard_links" = no; then
+    { echo "$as_me:$LINENO: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5
+echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;}
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+
+{ echo "$as_me:$LINENO: checking whether the $compiler linker ($LD) supports shared libraries" >&5
+echo $ECHO_N "checking whether the $compiler linker ($LD) supports shared libraries... $ECHO_C" >&6; }
+
+  runpath_var=
+  allow_undefined_flag=
+  enable_shared_with_static_runtimes=no
+  archive_cmds=
+  archive_expsym_cmds=
+  old_archive_From_new_cmds=
+  old_archive_from_expsyms_cmds=
+  export_dynamic_flag_spec=
+  whole_archive_flag_spec=
+  thread_safe_flag_spec=
+  hardcode_libdir_flag_spec=
+  hardcode_libdir_flag_spec_ld=
+  hardcode_libdir_separator=
+  hardcode_direct=no
+  hardcode_minus_L=no
+  hardcode_shlibpath_var=unsupported
+  link_all_deplibs=unknown
+  hardcode_automatic=no
+  module_cmds=
+  module_expsym_cmds=
+  always_export_symbols=no
+  export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  include_expsyms=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  exclude_expsyms="_GLOBAL_OFFSET_TABLE_"
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  extract_expsyms_cmds=
+  # Just being paranoid about ensuring that cc_basename is set.
+  for cc_temp in $compiler""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+
+  case $host_os in
+  cygwin* | mingw* | pw32*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  esac
+
+  ld_shlibs=yes
+  if test "$with_gnu_ld" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    hardcode_libdir_flag_spec='${wl}--rpath ${wl}$libdir'
+    export_dynamic_flag_spec='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | grep 'no-whole-archive' > /dev/null; then
+	whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+      else
+  	whole_archive_flag_spec=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>/dev/null` in
+      *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix3* | aix4* | aix5*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+	ld_shlibs=no
+	cat <<EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.9.1, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to modify your PATH
+*** so that a non-GNU linker is found, and then restart.
+
+EOF
+      fi
+      ;;
+
+    amigaos*)
+      archive_cmds='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_minus_L=yes
+
+      # Samuel A. Falvo II <kc5tja at dolphin.openprojects.net> reports
+      # that the semantics of dynamic libraries on AmigaOS, at least up
+      # to version 4, is to share data among multiple programs linked
+      # with the same dynamic library.  Since this doesn't match the
+      # behavior of shared libraries on other platforms, we can't use
+      # them.
+      ld_shlibs=no
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	allow_undefined_flag=unsupported
+	# Joseph Beckenbach <jrb3 at best.com> says some releases of gcc
+	# support --undefined.  This deserves some investigation.  FIXME
+	archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32*)
+      # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless,
+      # as there is no search path for DLLs.
+      hardcode_libdir_flag_spec='-L$libdir'
+      allow_undefined_flag=unsupported
+      always_export_symbols=no
+      enable_shared_with_static_runtimes=yes
+      export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/'\'' -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols'
+
+      if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
+        archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+	# If the export-symbols file already is a .def file (1st line
+	# is EXPORTS), use it as is; otherwise, prepend...
+	archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	  cp $export_symbols $output_objdir/$soname.def;
+	else
+	  echo EXPORTS > $output_objdir/$soname.def;
+	  cat $export_symbols >> $output_objdir/$soname.def;
+	fi~
+	$CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    interix[3-9]*)
+      hardcode_direct=no
+      hardcode_shlibpath_var=no
+      hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+      export_dynamic_flag_spec='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      archive_expsym_cmds='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | k*bsd*-gnu)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	tmp_addflag=
+	case $cc_basename,$host_cpu in
+	pgcc*)				# Portland Group C compiler
+	  whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag'
+	  ;;
+	pgf77* | pgf90* | pgf95*)	# Portland Group f77 and f90 compilers
+	  whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag -Mnomain' ;;
+	ecc*,ia64* | icc*,ia64*)		# Intel C compiler on ia64
+	  tmp_addflag=' -i_dynamic' ;;
+	efc*,ia64* | ifort*,ia64*)	# Intel Fortran compiler on ia64
+	  tmp_addflag=' -i_dynamic -nofor_main' ;;
+	ifc* | ifort*)			# Intel Fortran compiler
+	  tmp_addflag=' -nofor_main' ;;
+	esac
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)			# Sun C 5.9
+	  whole_archive_flag_spec='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_sharedflag='-G' ;;
+	*Sun\ F*)			# Sun Fortran 8.3
+	  tmp_sharedflag='-G' ;;
+	*)
+	  tmp_sharedflag='-shared' ;;
+	esac
+	archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+	if test $supports_anon_versioning = yes; then
+	  archive_expsym_cmds='$echo "{ global:" > $output_objdir/$libname.ver~
+  cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+  $echo "local: *; };" >> $output_objdir/$libname.ver~
+	  $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+	fi
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+	archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+	wlarc=
+      else
+	archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then
+	ld_shlibs=no
+	cat <<EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+EOF
+      elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*)
+	ld_shlibs=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+	;;
+	*)
+	  if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	    hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`'
+	    archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib'
+	    archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname,-retain-symbols-file,$export_symbols -o $lib'
+	  else
+	    ld_shlibs=no
+	  fi
+	;;
+      esac
+      ;;
+
+    sunos4*)
+      archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	ld_shlibs=no
+      fi
+      ;;
+    esac
+
+    if test "$ld_shlibs" = no; then
+      runpath_var=
+      hardcode_libdir_flag_spec=
+      export_dynamic_flag_spec=
+      whole_archive_flag_spec=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      allow_undefined_flag=unsupported
+      always_export_symbols=yes
+      archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      hardcode_minus_L=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+	# Neither direct hardcoding nor static linking is supported with a
+	# broken collect2.
+	hardcode_direct=unsupported
+      fi
+      ;;
+
+    aix4* | aix5*)
+      if test "$host_cpu" = ia64; then
+	# On IA64, the linker does run time linking by default, so we don't
+	# have to do anything special.
+	aix_use_runtimelinking=no
+	exp_sym_flag='-Bexport'
+	no_entry_flag=""
+      else
+	# If we're using GNU nm, then we don't want the "-C" option.
+	# -C means demangle to AIX nm, but means don't demangle with GNU nm
+	if $NM -V 2>&1 | grep 'GNU' > /dev/null; then
+	  export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols'
+	else
+	  export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols'
+	fi
+	aix_use_runtimelinking=no
+
+	# Test if we are trying to use run time linking or normal
+	# AIX style linking. If -brtl is somewhere in LDFLAGS, we
+	# need to do runtime linking.
+	case $host_os in aix4.[23]|aix4.[23].*|aix5*)
+	  for ld_flag in $LDFLAGS; do
+  	  if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+  	    aix_use_runtimelinking=yes
+  	    break
+  	  fi
+	  done
+	  ;;
+	esac
+
+	exp_sym_flag='-bexport'
+	no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      archive_cmds=''
+      hardcode_direct=yes
+      hardcode_libdir_separator=':'
+      link_all_deplibs=yes
+
+      if test "$GCC" = yes; then
+	case $host_os in aix4.[012]|aix4.[012].*)
+	# We only want to do this on AIX 4.2 and lower, the check
+	# below for broken collect2 doesn't work under 4.3+
+	  collect2name=`${CC} -print-prog-name=collect2`
+	  if test -f "$collect2name" && \
+  	   strings "$collect2name" | grep resolve_lib_name >/dev/null
+	  then
+  	  # We have reworked collect2
+  	  :
+	  else
+  	  # We have old collect2
+  	  hardcode_direct=unsupported
+  	  # It fails to find uninstalled libraries when the uninstalled
+  	  # path is not listed in the libpath.  Setting hardcode_minus_L
+  	  # to unsupported forces relinking
+  	  hardcode_minus_L=yes
+  	  hardcode_libdir_flag_spec='-L$libdir'
+  	  hardcode_libdir_separator=
+	  fi
+	  ;;
+	esac
+	shared_flag='-shared'
+	if test "$aix_use_runtimelinking" = yes; then
+	  shared_flag="$shared_flag "'${wl}-G'
+	fi
+      else
+	# not using gcc
+	if test "$host_cpu" = ia64; then
+  	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+  	# chokes on -Wl,-G. The following line is correct:
+	  shared_flag='-G'
+	else
+	  if test "$aix_use_runtimelinking" = yes; then
+	    shared_flag='${wl}-G'
+	  else
+	    shared_flag='${wl}-bM:SRE'
+	  fi
+	fi
+      fi
+
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      always_export_symbols=yes
+      if test "$aix_use_runtimelinking" = yes; then
+	# Warning - without using the other runtime loading flags (-brtl),
+	# -berok will link without error, but may produce a broken library.
+	allow_undefined_flag='-berok'
+       # Determine the default libpath from the value encoded in an empty executable.
+       cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+
+       hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
+	archive_expsym_cmds="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+       else
+	if test "$host_cpu" = ia64; then
+	  hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib'
+	  allow_undefined_flag="-z nodefs"
+	  archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+	else
+	 # Determine the default libpath from the value encoded in an empty executable.
+	 cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+
+	 hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
+	  # Warning - without using the other run time loading flags,
+	  # -berok will link without error, but may produce a broken library.
+	  no_undefined_flag=' ${wl}-bernotok'
+	  allow_undefined_flag=' ${wl}-berok'
+	  # Exported symbols can be pulled into shared objects from archives
+	  whole_archive_flag_spec='$convenience'
+	  archive_cmds_need_lc=yes
+	  # This is similar to how AIX traditionally builds its shared libraries.
+	  archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+	fi
+      fi
+      ;;
+
+    amigaos*)
+      archive_cmds='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_minus_L=yes
+      # see comment about different semantics on the GNU ld section
+      ld_shlibs=no
+      ;;
+
+    bsdi[45]*)
+      export_dynamic_flag_spec=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      hardcode_libdir_flag_spec=' '
+      allow_undefined_flag=unsupported
+      # Tell ltmain to make .lib files, not .a files.
+      libext=lib
+      # Tell ltmain to make .dll files, not .so files.
+      shrext_cmds=".dll"
+      # FIXME: Setting linknames here is a bad hack.
+      archive_cmds='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | $SED -e '\''s/ -lc$//'\''` -link -dll~linknames='
+      # The linker will automatically build a .lib file if we build a DLL.
+      old_archive_From_new_cmds='true'
+      # FIXME: Should let the user specify the lib program.
+      old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs'
+      fix_srcfile_path='`cygpath -w "$srcfile"`'
+      enable_shared_with_static_runtimes=yes
+      ;;
+
+    darwin* | rhapsody*)
+      case $host_os in
+        rhapsody* | darwin1.[012])
+         allow_undefined_flag='${wl}-undefined ${wl}suppress'
+         ;;
+       *) # Darwin 1.3 on
+         if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then
+           allow_undefined_flag='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+         else
+           case ${MACOSX_DEPLOYMENT_TARGET} in
+             10.[012])
+               allow_undefined_flag='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+               ;;
+             10.*)
+               allow_undefined_flag='${wl}-undefined ${wl}dynamic_lookup'
+               ;;
+           esac
+         fi
+         ;;
+      esac
+      archive_cmds_need_lc=no
+      hardcode_direct=no
+      hardcode_automatic=yes
+      hardcode_shlibpath_var=unsupported
+      whole_archive_flag_spec=''
+      link_all_deplibs=yes
+    if test "$GCC" = yes ; then
+    	output_verbose_link_cmd='echo'
+        archive_cmds='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring'
+      module_cmds='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
+      # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
+      archive_expsym_cmds='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+      module_expsym_cmds='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    else
+      case $cc_basename in
+        xlc*)
+         output_verbose_link_cmd='echo'
+         archive_cmds='$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $xlcverstring'
+         module_cmds='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
+          # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
+         archive_expsym_cmds='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $xlcverstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          module_expsym_cmds='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          ;;
+       *)
+         ld_shlibs=no
+          ;;
+      esac
+    fi
+      ;;
+
+    dgux*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_shlibpath_var=no
+      ;;
+
+    freebsd1*)
+      ld_shlibs=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2*)
+      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct=yes
+      hardcode_minus_L=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      archive_cmds='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+	archive_cmds='$rm $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+	archive_cmds='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+      hardcode_libdir_separator=:
+      hardcode_direct=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      hardcode_minus_L=yes
+      export_dynamic_flag_spec='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+	hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+	hardcode_libdir_separator=:
+
+	hardcode_direct=yes
+	export_dynamic_flag_spec='${wl}-E'
+
+	# hardcode_minus_L: Not really in the search PATH,
+	# but as the default location of the library.
+	hardcode_minus_L=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	case $host_cpu in
+	hppa*64*)
+	  archive_cmds='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  archive_cmds='$CC -shared ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      else
+	case $host_cpu in
+	hppa*64*)
+	  archive_cmds='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      fi
+      if test "$with_gnu_ld" = no; then
+	hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+	hardcode_libdir_separator=:
+
+	case $host_cpu in
+	hppa*64*|ia64*)
+	  hardcode_libdir_flag_spec_ld='+b $libdir'
+	  hardcode_direct=no
+	  hardcode_shlibpath_var=no
+	  ;;
+	*)
+	  hardcode_direct=yes
+	  export_dynamic_flag_spec='${wl}-E'
+
+	  # hardcode_minus_L: Not really in the search PATH,
+	  # but as the default location of the library.
+	  hardcode_minus_L=yes
+	  ;;
+	esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+	archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+	hardcode_libdir_flag_spec_ld='-rpath $libdir'
+      fi
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      link_all_deplibs=yes
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+	archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+	archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    newsos6)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct=yes
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      hardcode_shlibpath_var=no
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+	hardcode_direct=yes
+	hardcode_shlibpath_var=no
+	if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	  archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	  archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+	  hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+	  export_dynamic_flag_spec='${wl}-E'
+	else
+	  case $host_os in
+	   openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
+	     archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+	     hardcode_libdir_flag_spec='-R$libdir'
+	     ;;
+	   *)
+	     archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	     hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+	     ;;
+	  esac
+        fi
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    os2*)
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_minus_L=yes
+      allow_undefined_flag=unsupported
+      archive_cmds='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      old_archive_From_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+	allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
+	archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	allow_undefined_flag=' -expect_unresolved \*'
+	archive_cmds='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      ;;
+
+    osf4* | osf5*)	# as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+	allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
+	archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      else
+	allow_undefined_flag=' -expect_unresolved \*'
+	archive_cmds='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+	archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~
+	$LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~$rm $lib.exp'
+
+	# Both c and cxx compiler support -rpath directly
+	hardcode_libdir_flag_spec='-rpath $libdir'
+      fi
+      hardcode_libdir_separator=:
+      ;;
+
+    solaris*)
+      no_undefined_flag=' -z text'
+      if test "$GCC" = yes; then
+	wlarc='${wl}'
+	archive_cmds='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+	  $CC -shared ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$rm $lib.exp'
+      else
+	wlarc=''
+	archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	archive_expsym_cmds='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+  	$LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp'
+      fi
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_shlibpath_var=no
+      case $host_os in
+      solaris2.[0-5] | solaris2.[0-5].*) ;;
+      *)
+	# The compiler driver will combine and reorder linker options,
+	# but understands `-z linker_flag'.  GCC discards it without `$wl',
+	# but is careful enough not to reorder.
+ 	# Supported since Solaris 2.6 (maybe 2.5.1?)
+	if test "$GCC" = yes; then
+	  whole_archive_flag_spec='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+	else
+	  whole_archive_flag_spec='-z allextract$convenience -z defaultextract'
+	fi
+	;;
+      esac
+      link_all_deplibs=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+	# Use $CC to link under sequent, because it throws in some extra .o
+	# files that make .init and .fini sections work.
+	archive_cmds='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_direct=yes
+      hardcode_minus_L=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+	sni)
+	  archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  hardcode_direct=yes # is this really true???
+	;;
+	siemens)
+	  ## LD is ld it makes a PLAMLIB
+	  ## CC just makes a GrossModule.
+	  archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+	  reload_cmds='$CC -r -o $output$reload_objs'
+	  hardcode_direct=no
+        ;;
+	motorola)
+	  archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  hardcode_direct=no #Motorola manual says yes, but my tests say they lie
+	;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      hardcode_shlibpath_var=no
+      ;;
+
+    sysv4.3*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_shlibpath_var=no
+      export_dynamic_flag_spec='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	hardcode_shlibpath_var=no
+	runpath_var=LD_RUN_PATH
+	hardcode_runpath_var=yes
+	ld_shlibs=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*)
+      no_undefined_flag='${wl}-z,text'
+      archive_cmds_need_lc=no
+      hardcode_shlibpath_var=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      no_undefined_flag='${wl}-z,text'
+      allow_undefined_flag='${wl}-z,nodefs'
+      archive_cmds_need_lc=no
+      hardcode_shlibpath_var=no
+      hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`'
+      hardcode_libdir_separator=':'
+      link_all_deplibs=yes
+      export_dynamic_flag_spec='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	archive_cmds='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_shlibpath_var=no
+      ;;
+
+    *)
+      ld_shlibs=no
+      ;;
+    esac
+  fi
+
+{ echo "$as_me:$LINENO: result: $ld_shlibs" >&5
+echo "${ECHO_T}$ld_shlibs" >&6; }
+test "$ld_shlibs" = no && can_build_shared=no
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$archive_cmds_need_lc" in
+x|xyes)
+  # Assume -lc should be added
+  archive_cmds_need_lc=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $archive_cmds in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      { echo "$as_me:$LINENO: checking whether -lc should be explicitly linked in" >&5
+echo $ECHO_N "checking whether -lc should be explicitly linked in... $ECHO_C" >&6; }
+      $rm conftest*
+      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+      if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } 2>conftest.err; then
+        soname=conftest
+        lib=conftest
+        libobjs=conftest.$ac_objext
+        deplibs=
+        wl=$lt_prog_compiler_wl
+	pic_flag=$lt_prog_compiler_pic
+        compiler_flags=-v
+        linker_flags=-v
+        verstring=
+        output_objdir=.
+        libname=conftest
+        lt_save_allow_undefined_flag=$allow_undefined_flag
+        allow_undefined_flag=
+        if { (eval echo "$as_me:$LINENO: \"$archive_cmds 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1\"") >&5
+  (eval $archive_cmds 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+        then
+	  archive_cmds_need_lc=no
+        else
+	  archive_cmds_need_lc=yes
+        fi
+        allow_undefined_flag=$lt_save_allow_undefined_flag
+      else
+        cat conftest.err 1>&5
+      fi
+      $rm conftest*
+      { echo "$as_me:$LINENO: result: $archive_cmds_need_lc" >&5
+echo "${ECHO_T}$archive_cmds_need_lc" >&6; }
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+{ echo "$as_me:$LINENO: checking dynamic linker characteristics" >&5
+echo $ECHO_N "checking dynamic linker characteristics... $ECHO_C" >&6; }
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+
+if test "$GCC" = yes; then
+  case $host_os in
+    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
+    *) lt_awk_arg="/^libraries:/" ;;
+  esac
+  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+  if echo "$lt_search_path_spec" | grep ';' >/dev/null ; then
+    # if the path contains ";" then we assume it to be the separator
+    # otherwise default to the standard path separator (i.e. ":") - it is
+    # assumed that no part of a normal pathname contains ";" but that should
+    # okay in the real world where ";" in dirpaths is itself problematic.
+    lt_search_path_spec=`echo "$lt_search_path_spec" | $SED -e 's/;/ /g'`
+  else
+    lt_search_path_spec=`echo "$lt_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+  fi
+  # Ok, now we have the path, separated by spaces, we can step through it
+  # and add multilib dir if necessary.
+  lt_tmp_lt_search_path_spec=
+  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
+  for lt_sys_path in $lt_search_path_spec; do
+    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
+      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
+    else
+      test -d "$lt_sys_path" && \
+	lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
+    fi
+  done
+  lt_search_path_spec=`echo $lt_tmp_lt_search_path_spec | awk '
+BEGIN {RS=" "; FS="/|\n";} {
+  lt_foo="";
+  lt_count=0;
+  for (lt_i = NF; lt_i > 0; lt_i--) {
+    if ($lt_i != "" && $lt_i != ".") {
+      if ($lt_i == "..") {
+        lt_count++;
+      } else {
+        if (lt_count == 0) {
+          lt_foo="/" $lt_i lt_foo;
+        } else {
+          lt_count--;
+        }
+      }
+    }
+  }
+  if (lt_foo != "") { lt_freq[lt_foo]++; }
+  if (lt_freq[lt_foo] == 1) { print lt_foo; }
+}'`
+  sys_lib_search_path_spec=`echo $lt_search_path_spec`
+else
+  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
+fi
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix4* | aix5*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[01] | aix4.[01].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+	   echo ' yes '
+	   echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then
+	:
+      else
+	can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  library_names_spec='$libname.ixlibrary $libname.a'
+  # Create ${libname}_ixlibrary.a entries in /sys/libs.
+  finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[45]*)
+  version_type=linux
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$host_os in
+  yes,cygwin* | yes,mingw* | yes,pw32*)
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $rm \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
+      ;;
+    mingw*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+      if echo "$sys_lib_search_path_spec" | grep ';[c-zC-Z]:/' >/dev/null; then
+        # It is most probably a Windows format PATH printed by
+        # mingw gcc, but we are running on Cygwin. Gcc prints its search
+        # path with ; separators, and with drive letters. We can handle the
+        # drive letters (cygwin fileutils understands them), so leave them,
+        # especially as we might pass files found there to a mingw objdump,
+        # which wouldn't understand a cygwinified path. Ahh.
+        sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    ;;
+
+  *)
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    ;;
+  esac
+  dynamic_linker='Win32 ld.exe'
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+
+  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd1*)
+  dynamic_linker=no
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[123]*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[01]* | freebsdelf3.[01]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[2-9]* | freebsdelf3.[2-9]* | \
+  freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+gnu*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+   hppa*64*)
+     shrext_cmds='.sl'
+     hardcode_into_libs=yes
+     dynamic_linker="$host_os dld.sl"
+     shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+     shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+     library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+     soname_spec='${libname}${release}${shared_ext}$major'
+     sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+     sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+     ;;
+   *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555.
+  postinstall_cmds='chmod 555 $lib'
+  ;;
+
+interix[3-9]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+	if test "$lt_cv_prog_gnu_ld" = yes; then
+		version_type=linux
+	else
+		version_type=irix
+	fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ 	]*hwcap[ 	]/d;s/[:,	]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+nto-qnx*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*) need_version=yes ;;
+    *)                         need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[89] | openbsd2.[89].*)
+	shlibpath_overrides_runpath=no
+	;;
+      *)
+	shlibpath_overrides_runpath=yes
+	;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      export_dynamic_flag_spec='${wl}-Blargedynsym'
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+    shlibpath_overrides_runpath=no
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    shlibpath_overrides_runpath=yes
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+	;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+uts4*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+{ echo "$as_me:$LINENO: result: $dynamic_linker" >&5
+echo "${ECHO_T}$dynamic_linker" >&6; }
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+{ echo "$as_me:$LINENO: checking how to hardcode library paths into programs" >&5
+echo $ECHO_N "checking how to hardcode library paths into programs... $ECHO_C" >&6; }
+hardcode_action=
+if test -n "$hardcode_libdir_flag_spec" || \
+   test -n "$runpath_var" || \
+   test "X$hardcode_automatic" = "Xyes" ; then
+
+  # We can hardcode non-existant directories.
+  if test "$hardcode_direct" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, )" != no &&
+     test "$hardcode_minus_L" != no; then
+    # Linking always hardcodes the temporary library directory.
+    hardcode_action=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    hardcode_action=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  hardcode_action=unsupported
+fi
+{ echo "$as_me:$LINENO: result: $hardcode_action" >&5
+echo "${ECHO_T}$hardcode_action" >&6; }
+
+if test "$hardcode_action" = relink; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+
+striplib=
+old_striplib=
+{ echo "$as_me:$LINENO: checking whether stripping libraries is possible" >&5
+echo $ECHO_N "checking whether stripping libraries is possible... $ECHO_C" >&6; }
+if test -n "$STRIP" && $STRIP -V 2>&1 | grep "GNU strip" >/dev/null; then
+  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
+  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
+  { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+# FIXME - insert some real tests, host_os isn't really good enough
+  case $host_os in
+   darwin*)
+       if test -n "$STRIP" ; then
+         striplib="$STRIP -x"
+         old_striplib="$STRIP -S"
+         { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+       else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+       ;;
+   *)
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+    ;;
+  esac
+fi
+
+if test "x$enable_dlopen" != xyes; then
+  enable_dlopen=unknown
+  enable_dlopen_self=unknown
+  enable_dlopen_self_static=unknown
+else
+  lt_cv_dlopen=no
+  lt_cv_dlopen_libs=
+
+  case $host_os in
+  beos*)
+    lt_cv_dlopen="load_add_on"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ;;
+
+  mingw* | pw32*)
+    lt_cv_dlopen="LoadLibrary"
+    lt_cv_dlopen_libs=
+   ;;
+
+  cygwin*)
+    lt_cv_dlopen="dlopen"
+    lt_cv_dlopen_libs=
+   ;;
+
+  darwin*)
+  # if libdl is installed we need to link against it
+    { echo "$as_me:$LINENO: checking for dlopen in -ldl" >&5
+echo $ECHO_N "checking for dlopen in -ldl... $ECHO_C" >&6; }
+if test "${ac_cv_lib_dl_dlopen+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_lib_dl_dlopen=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_dl_dlopen=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_lib_dl_dlopen" >&5
+echo "${ECHO_T}$ac_cv_lib_dl_dlopen" >&6; }
+if test $ac_cv_lib_dl_dlopen = yes; then
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
+else
+
+    lt_cv_dlopen="dyld"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+
+fi
+
+   ;;
+
+  *)
+    { echo "$as_me:$LINENO: checking for shl_load" >&5
+echo $ECHO_N "checking for shl_load... $ECHO_C" >&6; }
+if test "${ac_cv_func_shl_load+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define shl_load to an innocuous variant, in case <limits.h> declares shl_load.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define shl_load innocuous_shl_load
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char shl_load (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef shl_load
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char shl_load ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_shl_load || defined __stub___shl_load
+choke me
+#endif
+
+int
+main ()
+{
+return shl_load ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_func_shl_load=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_func_shl_load=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_func_shl_load" >&5
+echo "${ECHO_T}$ac_cv_func_shl_load" >&6; }
+if test $ac_cv_func_shl_load = yes; then
+  lt_cv_dlopen="shl_load"
+else
+  { echo "$as_me:$LINENO: checking for shl_load in -ldld" >&5
+echo $ECHO_N "checking for shl_load in -ldld... $ECHO_C" >&6; }
+if test "${ac_cv_lib_dld_shl_load+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldld  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char shl_load ();
+int
+main ()
+{
+return shl_load ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_lib_dld_shl_load=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_dld_shl_load=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_lib_dld_shl_load" >&5
+echo "${ECHO_T}$ac_cv_lib_dld_shl_load" >&6; }
+if test $ac_cv_lib_dld_shl_load = yes; then
+  lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-dld"
+else
+  { echo "$as_me:$LINENO: checking for dlopen" >&5
+echo $ECHO_N "checking for dlopen... $ECHO_C" >&6; }
+if test "${ac_cv_func_dlopen+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define dlopen to an innocuous variant, in case <limits.h> declares dlopen.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define dlopen innocuous_dlopen
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char dlopen (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef dlopen
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_dlopen || defined __stub___dlopen
+choke me
+#endif
+
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_func_dlopen=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_func_dlopen=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_func_dlopen" >&5
+echo "${ECHO_T}$ac_cv_func_dlopen" >&6; }
+if test $ac_cv_func_dlopen = yes; then
+  lt_cv_dlopen="dlopen"
+else
+  { echo "$as_me:$LINENO: checking for dlopen in -ldl" >&5
+echo $ECHO_N "checking for dlopen in -ldl... $ECHO_C" >&6; }
+if test "${ac_cv_lib_dl_dlopen+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_lib_dl_dlopen=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_dl_dlopen=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_lib_dl_dlopen" >&5
+echo "${ECHO_T}$ac_cv_lib_dl_dlopen" >&6; }
+if test $ac_cv_lib_dl_dlopen = yes; then
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
+else
+  { echo "$as_me:$LINENO: checking for dlopen in -lsvld" >&5
+echo $ECHO_N "checking for dlopen in -lsvld... $ECHO_C" >&6; }
+if test "${ac_cv_lib_svld_dlopen+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lsvld  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_lib_svld_dlopen=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_svld_dlopen=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_lib_svld_dlopen" >&5
+echo "${ECHO_T}$ac_cv_lib_svld_dlopen" >&6; }
+if test $ac_cv_lib_svld_dlopen = yes; then
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"
+else
+  { echo "$as_me:$LINENO: checking for dld_link in -ldld" >&5
+echo $ECHO_N "checking for dld_link in -ldld... $ECHO_C" >&6; }
+if test "${ac_cv_lib_dld_dld_link+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldld  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dld_link ();
+int
+main ()
+{
+return dld_link ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_lib_dld_dld_link=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_dld_dld_link=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_lib_dld_dld_link" >&5
+echo "${ECHO_T}$ac_cv_lib_dld_dld_link" >&6; }
+if test $ac_cv_lib_dld_dld_link = yes; then
+  lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-dld"
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+    ;;
+  esac
+
+  if test "x$lt_cv_dlopen" != xno; then
+    enable_dlopen=yes
+  else
+    enable_dlopen=no
+  fi
+
+  case $lt_cv_dlopen in
+  dlopen)
+    save_CPPFLAGS="$CPPFLAGS"
+    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
+
+    save_LDFLAGS="$LDFLAGS"
+    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
+
+    save_LIBS="$LIBS"
+    LIBS="$lt_cv_dlopen_libs $LIBS"
+
+    { echo "$as_me:$LINENO: checking whether a program can dlopen itself" >&5
+echo $ECHO_N "checking whether a program can dlopen itself... $ECHO_C" >&6; }
+if test "${lt_cv_dlopen_self+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  	  if test "$cross_compiling" = yes; then :
+  lt_cv_dlopen_self=cross
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<EOF
+#line 10181 "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL		RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL		DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL		0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW		RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW		DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW	RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW	DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW	0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+#ifdef __cplusplus
+extern "C" void exit (int);
+#endif
+
+void fnord() { int i=42;}
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+    exit (status);
+}
+EOF
+  if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&5 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;;
+      x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;;
+      x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;;
+    esac
+  else :
+    # compilation failed
+    lt_cv_dlopen_self=no
+  fi
+fi
+rm -fr conftest*
+
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_cv_dlopen_self" >&5
+echo "${ECHO_T}$lt_cv_dlopen_self" >&6; }
+
+    if test "x$lt_cv_dlopen_self" = xyes; then
+      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
+      { echo "$as_me:$LINENO: checking whether a statically linked program can dlopen itself" >&5
+echo $ECHO_N "checking whether a statically linked program can dlopen itself... $ECHO_C" >&6; }
+if test "${lt_cv_dlopen_self_static+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  	  if test "$cross_compiling" = yes; then :
+  lt_cv_dlopen_self_static=cross
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<EOF
+#line 10281 "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL		RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL		DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL		0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW		RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW		DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW	RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW	DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW	0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+#ifdef __cplusplus
+extern "C" void exit (int);
+#endif
+
+void fnord() { int i=42;}
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+    exit (status);
+}
+EOF
+  if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&5 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;;
+      x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;;
+      x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;;
+    esac
+  else :
+    # compilation failed
+    lt_cv_dlopen_self_static=no
+  fi
+fi
+rm -fr conftest*
+
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_cv_dlopen_self_static" >&5
+echo "${ECHO_T}$lt_cv_dlopen_self_static" >&6; }
+    fi
+
+    CPPFLAGS="$save_CPPFLAGS"
+    LDFLAGS="$save_LDFLAGS"
+    LIBS="$save_LIBS"
+    ;;
+  esac
+
+  case $lt_cv_dlopen_self in
+  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
+  *) enable_dlopen_self=unknown ;;
+  esac
+
+  case $lt_cv_dlopen_self_static in
+  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
+  *) enable_dlopen_self_static=unknown ;;
+  esac
+fi
+
+
+# Report which library types will actually be built
+{ echo "$as_me:$LINENO: checking if libtool supports shared libraries" >&5
+echo $ECHO_N "checking if libtool supports shared libraries... $ECHO_C" >&6; }
+{ echo "$as_me:$LINENO: result: $can_build_shared" >&5
+echo "${ECHO_T}$can_build_shared" >&6; }
+
+{ echo "$as_me:$LINENO: checking whether to build shared libraries" >&5
+echo $ECHO_N "checking whether to build shared libraries... $ECHO_C" >&6; }
+test "$can_build_shared" = "no" && enable_shared=no
+
+# On AIX, shared libraries and static libraries use the same namespace, and
+# are all built from PIC.
+case $host_os in
+aix3*)
+  test "$enable_shared" = yes && enable_static=no
+  if test -n "$RANLIB"; then
+    archive_cmds="$archive_cmds~\$RANLIB \$lib"
+    postinstall_cmds='$RANLIB $lib'
+  fi
+  ;;
+
+aix4* | aix5*)
+  if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+    test "$enable_shared" = yes && enable_static=no
+  fi
+    ;;
+esac
+{ echo "$as_me:$LINENO: result: $enable_shared" >&5
+echo "${ECHO_T}$enable_shared" >&6; }
+
+{ echo "$as_me:$LINENO: checking whether to build static libraries" >&5
+echo $ECHO_N "checking whether to build static libraries... $ECHO_C" >&6; }
+# Make sure either enable_shared or enable_static is yes.
+test "$enable_shared" = yes || enable_static=yes
+{ echo "$as_me:$LINENO: result: $enable_static" >&5
+echo "${ECHO_T}$enable_static" >&6; }
+
+# The else clause should only fire when bootstrapping the
+# libtool distribution, otherwise you forgot to ship ltmain.sh
+# with your package, and you will get complaints that there are
+# no rules to generate ltmain.sh.
+if test -f "$ltmain"; then
+  # See if we are running on zsh, and set the options which allow our commands through
+  # without removal of \ escapes.
+  if test -n "${ZSH_VERSION+set}" ; then
+    setopt NO_GLOB_SUBST
+  fi
+  # Now quote all the things that may contain metacharacters while being
+  # careful not to overquote the AC_SUBSTed values.  We take copies of the
+  # variables and quote the copies for generation of the libtool script.
+  for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC LTCFLAGS NM \
+    SED SHELL STRIP \
+    libname_spec library_names_spec soname_spec extract_expsyms_cmds \
+    old_striplib striplib file_magic_cmd finish_cmds finish_eval \
+    deplibs_check_method reload_flag reload_cmds need_locks \
+    lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \
+    lt_cv_sys_global_symbol_to_c_name_address \
+    sys_lib_search_path_spec sys_lib_dlsearch_path_spec \
+    old_postinstall_cmds old_postuninstall_cmds \
+    compiler \
+    CC \
+    LD \
+    lt_prog_compiler_wl \
+    lt_prog_compiler_pic \
+    lt_prog_compiler_static \
+    lt_prog_compiler_no_builtin_flag \
+    export_dynamic_flag_spec \
+    thread_safe_flag_spec \
+    whole_archive_flag_spec \
+    enable_shared_with_static_runtimes \
+    old_archive_cmds \
+    old_archive_from_new_cmds \
+    predep_objects \
+    postdep_objects \
+    predeps \
+    postdeps \
+    compiler_lib_search_path \
+    archive_cmds \
+    archive_expsym_cmds \
+    postinstall_cmds \
+    postuninstall_cmds \
+    old_archive_from_expsyms_cmds \
+    allow_undefined_flag \
+    no_undefined_flag \
+    export_symbols_cmds \
+    hardcode_libdir_flag_spec \
+    hardcode_libdir_flag_spec_ld \
+    hardcode_libdir_separator \
+    hardcode_automatic \
+    module_cmds \
+    module_expsym_cmds \
+    lt_cv_prog_compiler_c_o \
+    fix_srcfile_path \
+    exclude_expsyms \
+    include_expsyms; do
+
+    case $var in
+    old_archive_cmds | \
+    old_archive_from_new_cmds | \
+    archive_cmds | \
+    archive_expsym_cmds | \
+    module_cmds | \
+    module_expsym_cmds | \
+    old_archive_from_expsyms_cmds | \
+    export_symbols_cmds | \
+    extract_expsyms_cmds | reload_cmds | finish_cmds | \
+    postinstall_cmds | postuninstall_cmds | \
+    old_postinstall_cmds | old_postuninstall_cmds | \
+    sys_lib_search_path_spec | sys_lib_dlsearch_path_spec)
+      # Double-quote double-evaled strings.
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\""
+      ;;
+    *)
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\""
+      ;;
+    esac
+  done
+
+  case $lt_echo in
+  *'\$0 --fallback-echo"')
+    lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\$0 --fallback-echo"$/$0 --fallback-echo"/'`
+    ;;
+  esac
+
+cfgfile="${ofile}T"
+  trap "$rm \"$cfgfile\"; exit 1" 1 2 15
+  $rm -f "$cfgfile"
+  { echo "$as_me:$LINENO: creating $ofile" >&5
+echo "$as_me: creating $ofile" >&6;}
+
+  cat <<__EOF__ >> "$cfgfile"
+#! $SHELL
+
+# `$echo "$cfgfile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
+# Generated automatically by $PROGRAM (GNU $PACKAGE $VERSION$TIMESTAMP)
+# NOTE: Changes made to this file will be lost: look at ltmain.sh.
+#
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+# Free Software Foundation, Inc.
+#
+# This file is part of GNU Libtool:
+# Originally by Gordon Matzigkeit <gord at gnu.ai.mit.edu>, 1996
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# A sed program that does not truncate output.
+SED=$lt_SED
+
+# Sed that helps us avoid accidentally triggering echo(1) options like -n.
+Xsed="$SED -e 1s/^X//"
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+# The names of the tagged configurations supported by this script.
+available_tags=
+
+# ### BEGIN LIBTOOL CONFIG
+
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+
+# Shell to use when invoking shell scripts.
+SHELL=$lt_SHELL
+
+# Whether or not to build shared libraries.
+build_libtool_libs=$enable_shared
+
+# Whether or not to build static libraries.
+build_old_libs=$enable_static
+
+# Whether or not to add -lc for building shared libraries.
+build_libtool_need_lc=$archive_cmds_need_lc
+
+# Whether or not to disallow shared libs when runtime libs are static
+allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes
+
+# Whether or not to optimize for fast installation.
+fast_install=$enable_fast_install
+
+# The host system.
+host_alias=$host_alias
+host=$host
+host_os=$host_os
+
+# The build system.
+build_alias=$build_alias
+build=$build
+build_os=$build_os
+
+# An echo program that does not interpret backslashes.
+echo=$lt_echo
+
+# The archiver.
+AR=$lt_AR
+AR_FLAGS=$lt_AR_FLAGS
+
+# A C compiler.
+LTCC=$lt_LTCC
+
+# LTCC compiler flags.
+LTCFLAGS=$lt_LTCFLAGS
+
+# A language-specific compiler.
+CC=$lt_compiler
+
+# Is the compiler the GNU C compiler?
+with_gcc=$GCC
+
+# An ERE matcher.
+EGREP=$lt_EGREP
+
+# The linker used to build libraries.
+LD=$lt_LD
+
+# Whether we need hard or soft links.
+LN_S=$lt_LN_S
+
+# A BSD-compatible nm program.
+NM=$lt_NM
+
+# A symbol stripping program
+STRIP=$lt_STRIP
+
+# Used to examine libraries when file_magic_cmd begins "file"
+MAGIC_CMD=$MAGIC_CMD
+
+# Used on cygwin: DLL creation program.
+DLLTOOL="$DLLTOOL"
+
+# Used on cygwin: object dumper.
+OBJDUMP="$OBJDUMP"
+
+# Used on cygwin: assembler.
+AS="$AS"
+
+# The name of the directory that contains temporary libtool files.
+objdir=$objdir
+
+# How to create reloadable object files.
+reload_flag=$lt_reload_flag
+reload_cmds=$lt_reload_cmds
+
+# How to pass a linker flag through the compiler.
+wl=$lt_lt_prog_compiler_wl
+
+# Object file suffix (normally "o").
+objext="$ac_objext"
+
+# Old archive suffix (normally "a").
+libext="$libext"
+
+# Shared library suffix (normally ".so").
+shrext_cmds='$shrext_cmds'
+
+# Executable file suffix (normally "").
+exeext="$exeext"
+
+# Additional compiler flags for building library objects.
+pic_flag=$lt_lt_prog_compiler_pic
+pic_mode=$pic_mode
+
+# What is the maximum length of a command?
+max_cmd_len=$lt_cv_sys_max_cmd_len
+
+# Does compiler simultaneously support -c and -o options?
+compiler_c_o=$lt_lt_cv_prog_compiler_c_o
+
+# Must we lock files when doing compilation?
+need_locks=$lt_need_locks
+
+# Do we need the lib prefix for modules?
+need_lib_prefix=$need_lib_prefix
+
+# Do we need a version for libraries?
+need_version=$need_version
+
+# Whether dlopen is supported.
+dlopen_support=$enable_dlopen
+
+# Whether dlopen of programs is supported.
+dlopen_self=$enable_dlopen_self
+
+# Whether dlopen of statically linked programs is supported.
+dlopen_self_static=$enable_dlopen_self_static
+
+# Compiler flag to prevent dynamic linking.
+link_static_flag=$lt_lt_prog_compiler_static
+
+# Compiler flag to turn off builtin functions.
+no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag
+
+# Compiler flag to allow reflexive dlopens.
+export_dynamic_flag_spec=$lt_export_dynamic_flag_spec
+
+# Compiler flag to generate shared objects directly from archives.
+whole_archive_flag_spec=$lt_whole_archive_flag_spec
+
+# Compiler flag to generate thread-safe objects.
+thread_safe_flag_spec=$lt_thread_safe_flag_spec
+
+# Library versioning type.
+version_type=$version_type
+
+# Format of library name prefix.
+libname_spec=$lt_libname_spec
+
+# List of archive names.  First name is the real one, the rest are links.
+# The last name is the one that the linker finds with -lNAME.
+library_names_spec=$lt_library_names_spec
+
+# The coded name of the library, if different from the real name.
+soname_spec=$lt_soname_spec
+
+# Commands used to build and install an old-style archive.
+RANLIB=$lt_RANLIB
+old_archive_cmds=$lt_old_archive_cmds
+old_postinstall_cmds=$lt_old_postinstall_cmds
+old_postuninstall_cmds=$lt_old_postuninstall_cmds
+
+# Create an old-style archive from a shared archive.
+old_archive_from_new_cmds=$lt_old_archive_from_new_cmds
+
+# Create a temporary old-style archive to link instead of a shared archive.
+old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds
+
+# Commands used to build and install a shared archive.
+archive_cmds=$lt_archive_cmds
+archive_expsym_cmds=$lt_archive_expsym_cmds
+postinstall_cmds=$lt_postinstall_cmds
+postuninstall_cmds=$lt_postuninstall_cmds
+
+# Commands used to build a loadable module (assumed same as above if empty)
+module_cmds=$lt_module_cmds
+module_expsym_cmds=$lt_module_expsym_cmds
+
+# Commands to strip libraries.
+old_striplib=$lt_old_striplib
+striplib=$lt_striplib
+
+# Dependencies to place before the objects being linked to create a
+# shared library.
+predep_objects=$lt_predep_objects
+
+# Dependencies to place after the objects being linked to create a
+# shared library.
+postdep_objects=$lt_postdep_objects
+
+# Dependencies to place before the objects being linked to create a
+# shared library.
+predeps=$lt_predeps
+
+# Dependencies to place after the objects being linked to create a
+# shared library.
+postdeps=$lt_postdeps
+
+# The library search path used internally by the compiler when linking
+# a shared library.
+compiler_lib_search_path=$lt_compiler_lib_search_path
+
+# Method to check whether dependent libraries are shared objects.
+deplibs_check_method=$lt_deplibs_check_method
+
+# Command to use when deplibs_check_method == file_magic.
+file_magic_cmd=$lt_file_magic_cmd
+
+# Flag that allows shared libraries with undefined symbols to be built.
+allow_undefined_flag=$lt_allow_undefined_flag
+
+# Flag that forces no undefined symbols.
+no_undefined_flag=$lt_no_undefined_flag
+
+# Commands used to finish a libtool library installation in a directory.
+finish_cmds=$lt_finish_cmds
+
+# Same as above, but a single script fragment to be evaled but not shown.
+finish_eval=$lt_finish_eval
+
+# Take the output of nm and produce a listing of raw symbols and C names.
+global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe
+
+# Transform the output of nm in a proper C declaration
+global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl
+
+# Transform the output of nm in a C name address pair
+global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address
+
+# This is the shared library runtime path variable.
+runpath_var=$runpath_var
+
+# This is the shared library path variable.
+shlibpath_var=$shlibpath_var
+
+# Is shlibpath searched before the hard-coded library search path?
+shlibpath_overrides_runpath=$shlibpath_overrides_runpath
+
+# How to hardcode a shared library path into an executable.
+hardcode_action=$hardcode_action
+
+# Whether we should hardcode library paths into libraries.
+hardcode_into_libs=$hardcode_into_libs
+
+# Flag to hardcode \$libdir into a binary during linking.
+# This must work even if \$libdir does not exist.
+hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec
+
+# If ld is used when linking, flag to hardcode \$libdir into
+# a binary during linking. This must work even if \$libdir does
+# not exist.
+hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld
+
+# Whether we need a single -rpath flag with a separated argument.
+hardcode_libdir_separator=$lt_hardcode_libdir_separator
+
+# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the
+# resulting binary.
+hardcode_direct=$hardcode_direct
+
+# Set to yes if using the -LDIR flag during linking hardcodes DIR into the
+# resulting binary.
+hardcode_minus_L=$hardcode_minus_L
+
+# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into
+# the resulting binary.
+hardcode_shlibpath_var=$hardcode_shlibpath_var
+
+# Set to yes if building a shared library automatically hardcodes DIR into the library
+# and all subsequent libraries and executables linked against it.
+hardcode_automatic=$hardcode_automatic
+
+# Variables whose values should be saved in libtool wrapper scripts and
+# restored at relink time.
+variables_saved_for_relink="$variables_saved_for_relink"
+
+# Whether libtool must link a program against all its dependency libraries.
+link_all_deplibs=$link_all_deplibs
+
+# Compile-time system search path for libraries
+sys_lib_search_path_spec=$lt_sys_lib_search_path_spec
+
+# Run-time system search path for libraries
+sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec
+
+# Fix the shell variable \$srcfile for the compiler.
+fix_srcfile_path=$lt_fix_srcfile_path
+
+# Set to yes if exported symbols are required.
+always_export_symbols=$always_export_symbols
+
+# The commands to list exported symbols.
+export_symbols_cmds=$lt_export_symbols_cmds
+
+# The commands to extract the exported symbol list from a shared archive.
+extract_expsyms_cmds=$lt_extract_expsyms_cmds
+
+# Symbols that should not be listed in the preloaded symbols.
+exclude_expsyms=$lt_exclude_expsyms
+
+# Symbols that must always be exported.
+include_expsyms=$lt_include_expsyms
+
+# ### END LIBTOOL CONFIG
+
+__EOF__
+
+
+  case $host_os in
+  aix3*)
+    cat <<\EOF >> "$cfgfile"
+
+# AIX sometimes has problems with the GCC collect2 program.  For some
+# reason, if we set the COLLECT_NAMES environment variable, the problems
+# vanish in a puff of smoke.
+if test "X${COLLECT_NAMES+set}" != Xset; then
+  COLLECT_NAMES=
+  export COLLECT_NAMES
+fi
+EOF
+    ;;
+  esac
+
+  # We use sed instead of cat because bash on DJGPP gets confused if
+  # if finds mixed CR/LF and LF-only lines.  Since sed operates in
+  # text mode, it properly converts lines to CR/LF.  This bash problem
+  # is reportedly fixed, but why not run on old versions too?
+  sed '$q' "$ltmain" >> "$cfgfile" || (rm -f "$cfgfile"; exit 1)
+
+  mv -f "$cfgfile" "$ofile" || \
+    (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
+  chmod +x "$ofile"
+
+else
+  # If there is no Makefile yet, we rely on a make rule to execute
+  # `config.status --recheck' to rerun these tests and create the
+  # libtool script then.
+  ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'`
+  if test -f "$ltmain_in"; then
+    test -f Makefile && make "$ltmain"
+  fi
+fi
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+CC="$lt_save_CC"
+
+
+# Check whether --with-tags was given.
+if test "${with_tags+set}" = set; then
+  withval=$with_tags; tagnames="$withval"
+fi
+
+
+if test -f "$ltmain" && test -n "$tagnames"; then
+  if test ! -f "${ofile}"; then
+    { echo "$as_me:$LINENO: WARNING: output file \`$ofile' does not exist" >&5
+echo "$as_me: WARNING: output file \`$ofile' does not exist" >&2;}
+  fi
+
+  if test -z "$LTCC"; then
+    eval "`$SHELL ${ofile} --config | grep '^LTCC='`"
+    if test -z "$LTCC"; then
+      { echo "$as_me:$LINENO: WARNING: output file \`$ofile' does not look like a libtool script" >&5
+echo "$as_me: WARNING: output file \`$ofile' does not look like a libtool script" >&2;}
+    else
+      { echo "$as_me:$LINENO: WARNING: using \`LTCC=$LTCC', extracted from \`$ofile'" >&5
+echo "$as_me: WARNING: using \`LTCC=$LTCC', extracted from \`$ofile'" >&2;}
+    fi
+  fi
+  if test -z "$LTCFLAGS"; then
+    eval "`$SHELL ${ofile} --config | grep '^LTCFLAGS='`"
+  fi
+
+  # Extract list of available tagged configurations in $ofile.
+  # Note that this assumes the entire list is on one line.
+  available_tags=`grep "^available_tags=" "${ofile}" | $SED -e 's/available_tags=\(.*$\)/\1/' -e 's/\"//g'`
+
+  lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+  for tagname in $tagnames; do
+    IFS="$lt_save_ifs"
+    # Check whether tagname contains only valid characters
+    case `$echo "X$tagname" | $Xsed -e 's:[-_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,/]::g'` in
+    "") ;;
+    *)  { { echo "$as_me:$LINENO: error: invalid tag name: $tagname" >&5
+echo "$as_me: error: invalid tag name: $tagname" >&2;}
+   { (exit 1); exit 1; }; }
+	;;
+    esac
+
+    if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "${ofile}" > /dev/null
+    then
+      { { echo "$as_me:$LINENO: error: tag name \"$tagname\" already exists" >&5
+echo "$as_me: error: tag name \"$tagname\" already exists" >&2;}
+   { (exit 1); exit 1; }; }
+    fi
+
+    # Update the list of available tags.
+    if test -n "$tagname"; then
+      echo appending configuration tag \"$tagname\" to $ofile
+
+      case $tagname in
+      CXX)
+	if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
+	    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
+	    (test "X$CXX" != "Xg++"))) ; then
+	  ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+
+
+
+archive_cmds_need_lc_CXX=no
+allow_undefined_flag_CXX=
+always_export_symbols_CXX=no
+archive_expsym_cmds_CXX=
+export_dynamic_flag_spec_CXX=
+hardcode_direct_CXX=no
+hardcode_libdir_flag_spec_CXX=
+hardcode_libdir_flag_spec_ld_CXX=
+hardcode_libdir_separator_CXX=
+hardcode_minus_L_CXX=no
+hardcode_shlibpath_var_CXX=unsupported
+hardcode_automatic_CXX=no
+module_cmds_CXX=
+module_expsym_cmds_CXX=
+link_all_deplibs_CXX=unknown
+old_archive_cmds_CXX=$old_archive_cmds
+no_undefined_flag_CXX=
+whole_archive_flag_spec_CXX=
+enable_shared_with_static_runtimes_CXX=no
+
+# Dependencies to place before and after the object being linked:
+predep_objects_CXX=
+postdep_objects_CXX=
+predeps_CXX=
+postdeps_CXX=
+compiler_lib_search_path_CXX=
+
+# Source file extension for C++ test sources.
+ac_ext=cpp
+
+# Object file extension for compiled C++ test sources.
+objext=o
+objext_CXX=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(int, char *[]) { return(0); }'
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+
+# save warnings/boilerplate of simple test code
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$rm conftest*
+
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$rm conftest*
+
+
+# Allow CC to be a program name with arguments.
+lt_save_CC=$CC
+lt_save_LD=$LD
+lt_save_GCC=$GCC
+GCC=$GXX
+lt_save_with_gnu_ld=$with_gnu_ld
+lt_save_path_LD=$lt_cv_path_LD
+if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then
+  lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx
+else
+  $as_unset lt_cv_prog_gnu_ld
+fi
+if test -n "${lt_cv_path_LDCXX+set}"; then
+  lt_cv_path_LD=$lt_cv_path_LDCXX
+else
+  $as_unset lt_cv_path_LD
+fi
+test -z "${LDCXX+set}" || LD=$LDCXX
+CC=${CXX-"c++"}
+compiler=$CC
+compiler_CXX=$CC
+for cc_temp in $compiler""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+
+
+# We don't want -fno-exception wen compiling C++ code, so set the
+# no_builtin_flag separately
+if test "$GXX" = yes; then
+  lt_prog_compiler_no_builtin_flag_CXX=' -fno-builtin'
+else
+  lt_prog_compiler_no_builtin_flag_CXX=
+fi
+
+if test "$GXX" = yes; then
+  # Set up default GNU C++ configuration
+
+
+# Check whether --with-gnu-ld was given.
+if test "${with_gnu_ld+set}" = set; then
+  withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes
+else
+  with_gnu_ld=no
+fi
+
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  { echo "$as_me:$LINENO: checking for ld used by $CC" >&5
+echo $ECHO_N "checking for ld used by $CC... $ECHO_C" >&6; }
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [\\/]* | ?:[\\/]*)
+      re_direlt='/[^/][^/]*/\.\./'
+      # Canonicalize the pathname of ld
+      ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
+      while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
+	ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  { echo "$as_me:$LINENO: checking for GNU ld" >&5
+echo $ECHO_N "checking for GNU ld... $ECHO_C" >&6; }
+else
+  { echo "$as_me:$LINENO: checking for non-GNU ld" >&5
+echo $ECHO_N "checking for non-GNU ld... $ECHO_C" >&6; }
+fi
+if test "${lt_cv_path_LD+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -z "$LD"; then
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for ac_dir in $PATH; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      lt_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some variants of GNU ld only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
+      *GNU* | *'with BFD'*)
+	test "$with_gnu_ld" != no && break
+	;;
+      *)
+	test "$with_gnu_ld" != yes && break
+	;;
+      esac
+    fi
+  done
+  IFS="$lt_save_ifs"
+else
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+fi
+fi
+
+LD="$lt_cv_path_LD"
+if test -n "$LD"; then
+  { echo "$as_me:$LINENO: result: $LD" >&5
+echo "${ECHO_T}$LD" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
+test -z "$LD" && { { echo "$as_me:$LINENO: error: no acceptable ld found in \$PATH" >&5
+echo "$as_me: error: no acceptable ld found in \$PATH" >&2;}
+   { (exit 1); exit 1; }; }
+{ echo "$as_me:$LINENO: checking if the linker ($LD) is GNU ld" >&5
+echo $ECHO_N "checking if the linker ($LD) is GNU ld... $ECHO_C" >&6; }
+if test "${lt_cv_prog_gnu_ld+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  # I'd rather use --version here, but apparently some GNU lds only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  lt_cv_prog_gnu_ld=yes
+  ;;
+*)
+  lt_cv_prog_gnu_ld=no
+  ;;
+esac
+fi
+{ echo "$as_me:$LINENO: result: $lt_cv_prog_gnu_ld" >&5
+echo "${ECHO_T}$lt_cv_prog_gnu_ld" >&6; }
+with_gnu_ld=$lt_cv_prog_gnu_ld
+
+
+
+  # Check if GNU C++ uses GNU ld as the underlying linker, since the
+  # archiving commands below assume that GNU ld is being used.
+  if test "$with_gnu_ld" = yes; then
+    archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+    archive_expsym_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+
+    hardcode_libdir_flag_spec_CXX='${wl}--rpath ${wl}$libdir'
+    export_dynamic_flag_spec_CXX='${wl}--export-dynamic'
+
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to
+    #     investigate it a little bit more. (MM)
+    wlarc='${wl}'
+
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if eval "`$CC -print-prog-name=ld` --help 2>&1" | \
+	grep 'no-whole-archive' > /dev/null; then
+      whole_archive_flag_spec_CXX="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+    else
+      whole_archive_flag_spec_CXX=
+    fi
+  else
+    with_gnu_ld=no
+    wlarc=
+
+    # A generic and very simple default shared library creation
+    # command for GNU C++ for the case where it uses the native
+    # linker, instead of GNU ld.  If possible, this setting should
+    # overridden to take advantage of the native linker features on
+    # the platform it is being used on.
+    archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+  fi
+
+  # Commands to make compiler produce verbose output that lists
+  # what "hidden" libraries, object files and flags are used when
+  # linking a shared library.
+  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"'
+
+else
+  GXX=no
+  with_gnu_ld=no
+  wlarc=
+fi
+
+# PORTME: fill in a description of your system's C++ link characteristics
+{ echo "$as_me:$LINENO: checking whether the $compiler linker ($LD) supports shared libraries" >&5
+echo $ECHO_N "checking whether the $compiler linker ($LD) supports shared libraries... $ECHO_C" >&6; }
+ld_shlibs_CXX=yes
+case $host_os in
+  aix3*)
+    # FIXME: insert proper C++ library support
+    ld_shlibs_CXX=no
+    ;;
+  aix4* | aix5*)
+    if test "$host_cpu" = ia64; then
+      # On IA64, the linker does run time linking by default, so we don't
+      # have to do anything special.
+      aix_use_runtimelinking=no
+      exp_sym_flag='-Bexport'
+      no_entry_flag=""
+    else
+      aix_use_runtimelinking=no
+
+      # Test if we are trying to use run time linking or normal
+      # AIX style linking. If -brtl is somewhere in LDFLAGS, we
+      # need to do runtime linking.
+      case $host_os in aix4.[23]|aix4.[23].*|aix5*)
+	for ld_flag in $LDFLAGS; do
+	  case $ld_flag in
+	  *-brtl*)
+	    aix_use_runtimelinking=yes
+	    break
+	    ;;
+	  esac
+	done
+	;;
+      esac
+
+      exp_sym_flag='-bexport'
+      no_entry_flag='-bnoentry'
+    fi
+
+    # When large executables or shared objects are built, AIX ld can
+    # have problems creating the table of contents.  If linking a library
+    # or program results in "error TOC overflow" add -mminimal-toc to
+    # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+    # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+    archive_cmds_CXX=''
+    hardcode_direct_CXX=yes
+    hardcode_libdir_separator_CXX=':'
+    link_all_deplibs_CXX=yes
+
+    if test "$GXX" = yes; then
+      case $host_os in aix4.[012]|aix4.[012].*)
+      # We only want to do this on AIX 4.2 and lower, the check
+      # below for broken collect2 doesn't work under 4.3+
+	collect2name=`${CC} -print-prog-name=collect2`
+	if test -f "$collect2name" && \
+	   strings "$collect2name" | grep resolve_lib_name >/dev/null
+	then
+	  # We have reworked collect2
+	  :
+	else
+	  # We have old collect2
+	  hardcode_direct_CXX=unsupported
+	  # It fails to find uninstalled libraries when the uninstalled
+	  # path is not listed in the libpath.  Setting hardcode_minus_L
+	  # to unsupported forces relinking
+	  hardcode_minus_L_CXX=yes
+	  hardcode_libdir_flag_spec_CXX='-L$libdir'
+	  hardcode_libdir_separator_CXX=
+	fi
+	;;
+      esac
+      shared_flag='-shared'
+      if test "$aix_use_runtimelinking" = yes; then
+	shared_flag="$shared_flag "'${wl}-G'
+      fi
+    else
+      # not using gcc
+      if test "$host_cpu" = ia64; then
+	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+	# chokes on -Wl,-G. The following line is correct:
+	shared_flag='-G'
+      else
+	if test "$aix_use_runtimelinking" = yes; then
+	  shared_flag='${wl}-G'
+	else
+	  shared_flag='${wl}-bM:SRE'
+	fi
+      fi
+    fi
+
+    # It seems that -bexpall does not export symbols beginning with
+    # underscore (_), so it is better to generate a list of symbols to export.
+    always_export_symbols_CXX=yes
+    if test "$aix_use_runtimelinking" = yes; then
+      # Warning - without using the other runtime loading flags (-brtl),
+      # -berok will link without error, but may produce a broken library.
+      allow_undefined_flag_CXX='-berok'
+      # Determine the default libpath from the value encoded in an empty executable.
+      cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+
+      hardcode_libdir_flag_spec_CXX='${wl}-blibpath:$libdir:'"$aix_libpath"
+
+      archive_expsym_cmds_CXX="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+     else
+      if test "$host_cpu" = ia64; then
+	hardcode_libdir_flag_spec_CXX='${wl}-R $libdir:/usr/lib:/lib'
+	allow_undefined_flag_CXX="-z nodefs"
+	archive_expsym_cmds_CXX="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+      else
+	# Determine the default libpath from the value encoded in an empty executable.
+	cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+
+	hardcode_libdir_flag_spec_CXX='${wl}-blibpath:$libdir:'"$aix_libpath"
+	# Warning - without using the other run time loading flags,
+	# -berok will link without error, but may produce a broken library.
+	no_undefined_flag_CXX=' ${wl}-bernotok'
+	allow_undefined_flag_CXX=' ${wl}-berok'
+	# Exported symbols can be pulled into shared objects from archives
+	whole_archive_flag_spec_CXX='$convenience'
+	archive_cmds_need_lc_CXX=yes
+	# This is similar to how AIX traditionally builds its shared libraries.
+	archive_expsym_cmds_CXX="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+      fi
+    fi
+    ;;
+
+  beos*)
+    if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+      allow_undefined_flag_CXX=unsupported
+      # Joseph Beckenbach <jrb3 at best.com> says some releases of gcc
+      # support --undefined.  This deserves some investigation.  FIXME
+      archive_cmds_CXX='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+    else
+      ld_shlibs_CXX=no
+    fi
+    ;;
+
+  chorus*)
+    case $cc_basename in
+      *)
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+    esac
+    ;;
+
+  cygwin* | mingw* | pw32*)
+    # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, CXX) is actually meaningless,
+    # as there is no search path for DLLs.
+    hardcode_libdir_flag_spec_CXX='-L$libdir'
+    allow_undefined_flag_CXX=unsupported
+    always_export_symbols_CXX=no
+    enable_shared_with_static_runtimes_CXX=yes
+
+    if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
+      archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      # If the export-symbols file already is a .def file (1st line
+      # is EXPORTS), use it as is; otherwise, prepend...
+      archive_expsym_cmds_CXX='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	cp $export_symbols $output_objdir/$soname.def;
+      else
+	echo EXPORTS > $output_objdir/$soname.def;
+	cat $export_symbols >> $output_objdir/$soname.def;
+      fi~
+      $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+    else
+      ld_shlibs_CXX=no
+    fi
+  ;;
+      darwin* | rhapsody*)
+        case $host_os in
+        rhapsody* | darwin1.[012])
+         allow_undefined_flag_CXX='${wl}-undefined ${wl}suppress'
+         ;;
+       *) # Darwin 1.3 on
+         if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then
+           allow_undefined_flag_CXX='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+         else
+           case ${MACOSX_DEPLOYMENT_TARGET} in
+             10.[012])
+               allow_undefined_flag_CXX='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+               ;;
+             10.*)
+               allow_undefined_flag_CXX='${wl}-undefined ${wl}dynamic_lookup'
+               ;;
+           esac
+         fi
+         ;;
+        esac
+      archive_cmds_need_lc_CXX=no
+      hardcode_direct_CXX=no
+      hardcode_automatic_CXX=yes
+      hardcode_shlibpath_var_CXX=unsupported
+      whole_archive_flag_spec_CXX=''
+      link_all_deplibs_CXX=yes
+
+    if test "$GXX" = yes ; then
+      lt_int_apple_cc_single_mod=no
+      output_verbose_link_cmd='echo'
+      if $CC -dumpspecs 2>&1 | $EGREP 'single_module' >/dev/null ; then
+       lt_int_apple_cc_single_mod=yes
+      fi
+      if test "X$lt_int_apple_cc_single_mod" = Xyes ; then
+       archive_cmds_CXX='$CC -dynamiclib -single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring'
+      else
+          archive_cmds_CXX='$CC -r -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring'
+        fi
+        module_cmds_CXX='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
+        # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
+          if test "X$lt_int_apple_cc_single_mod" = Xyes ; then
+            archive_expsym_cmds_CXX='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib -single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          else
+            archive_expsym_cmds_CXX='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -r -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          fi
+            module_expsym_cmds_CXX='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+      else
+      case $cc_basename in
+        xlc*)
+         output_verbose_link_cmd='echo'
+          archive_cmds_CXX='$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $xlcverstring'
+          module_cmds_CXX='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
+          # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
+          archive_expsym_cmds_CXX='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $xlcverstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          module_expsym_cmds_CXX='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          ;;
+       *)
+         ld_shlibs_CXX=no
+          ;;
+      esac
+      fi
+        ;;
+
+  dgux*)
+    case $cc_basename in
+      ec++*)
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+      ghcx*)
+	# Green Hills C++ Compiler
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+      *)
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+    esac
+    ;;
+  freebsd[12]*)
+    # C++ shared libraries reported to be fairly broken before switch to ELF
+    ld_shlibs_CXX=no
+    ;;
+  freebsd-elf*)
+    archive_cmds_need_lc_CXX=no
+    ;;
+  freebsd* | dragonfly*)
+    # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF
+    # conventions
+    ld_shlibs_CXX=yes
+    ;;
+  gnu*)
+    ;;
+  hpux9*)
+    hardcode_libdir_flag_spec_CXX='${wl}+b ${wl}$libdir'
+    hardcode_libdir_separator_CXX=:
+    export_dynamic_flag_spec_CXX='${wl}-E'
+    hardcode_direct_CXX=yes
+    hardcode_minus_L_CXX=yes # Not in the search PATH,
+				# but as the default
+				# location of the library.
+
+    case $cc_basename in
+    CC*)
+      # FIXME: insert proper C++ library support
+      ld_shlibs_CXX=no
+      ;;
+    aCC*)
+      archive_cmds_CXX='$rm $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      # Commands to make compiler produce verbose output that lists
+      # what "hidden" libraries, object files and flags are used when
+      # linking a shared library.
+      #
+      # There doesn't appear to be a way to prevent this compiler from
+      # explicitly linking system object files so we need to strip them
+      # from the output so that they don't get included in the library
+      # dependencies.
+      output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "[-]L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
+      ;;
+    *)
+      if test "$GXX" = yes; then
+        archive_cmds_CXX='$rm $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+        # FIXME: insert proper C++ library support
+        ld_shlibs_CXX=no
+      fi
+      ;;
+    esac
+    ;;
+  hpux10*|hpux11*)
+    if test $with_gnu_ld = no; then
+      hardcode_libdir_flag_spec_CXX='${wl}+b ${wl}$libdir'
+      hardcode_libdir_separator_CXX=:
+
+      case $host_cpu in
+      hppa*64*|ia64*) ;;
+      *)
+	export_dynamic_flag_spec_CXX='${wl}-E'
+        ;;
+      esac
+    fi
+    case $host_cpu in
+    hppa*64*|ia64*)
+      hardcode_direct_CXX=no
+      hardcode_shlibpath_var_CXX=no
+      ;;
+    *)
+      hardcode_direct_CXX=yes
+      hardcode_minus_L_CXX=yes # Not in the search PATH,
+					      # but as the default
+					      # location of the library.
+      ;;
+    esac
+
+    case $cc_basename in
+      CC*)
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+      aCC*)
+	case $host_cpu in
+	hppa*64*)
+	  archive_cmds_CXX='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	  ;;
+	ia64*)
+	  archive_cmds_CXX='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	  ;;
+	*)
+	  archive_cmds_CXX='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	  ;;
+	esac
+	# Commands to make compiler produce verbose output that lists
+	# what "hidden" libraries, object files and flags are used when
+	# linking a shared library.
+	#
+	# There doesn't appear to be a way to prevent this compiler from
+	# explicitly linking system object files so we need to strip them
+	# from the output so that they don't get included in the library
+	# dependencies.
+	output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
+	;;
+      *)
+	if test "$GXX" = yes; then
+	  if test $with_gnu_ld = no; then
+	    case $host_cpu in
+	    hppa*64*)
+	      archive_cmds_CXX='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	      ;;
+	    ia64*)
+	      archive_cmds_CXX='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	      ;;
+	    *)
+	      archive_cmds_CXX='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	      ;;
+	    esac
+	  fi
+	else
+	  # FIXME: insert proper C++ library support
+	  ld_shlibs_CXX=no
+	fi
+	;;
+    esac
+    ;;
+  interix[3-9]*)
+    hardcode_direct_CXX=no
+    hardcode_shlibpath_var_CXX=no
+    hardcode_libdir_flag_spec_CXX='${wl}-rpath,$libdir'
+    export_dynamic_flag_spec_CXX='${wl}-E'
+    # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+    # Instead, shared libraries are loaded at an image base (0x10000000 by
+    # default) and relocated if they conflict, which is a slow very memory
+    # consuming and fragmenting process.  To avoid this, we pick a random,
+    # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+    # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+    archive_cmds_CXX='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+    archive_expsym_cmds_CXX='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+    ;;
+  irix5* | irix6*)
+    case $cc_basename in
+      CC*)
+	# SGI C++
+	archive_cmds_CXX='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+
+	# Archives containing C++ object files must be created using
+	# "CC -ar", where "CC" is the IRIX C++ compiler.  This is
+	# necessary to make sure instantiated templates are included
+	# in the archive.
+	old_archive_cmds_CXX='$CC -ar -WR,-u -o $oldlib $oldobjs'
+	;;
+      *)
+	if test "$GXX" = yes; then
+	  if test "$with_gnu_ld" = no; then
+	    archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	  else
+	    archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` -o $lib'
+	  fi
+	fi
+	link_all_deplibs_CXX=yes
+	;;
+    esac
+    hardcode_libdir_flag_spec_CXX='${wl}-rpath ${wl}$libdir'
+    hardcode_libdir_separator_CXX=:
+    ;;
+  linux* | k*bsd*-gnu)
+    case $cc_basename in
+      KCC*)
+	# Kuck and Associates, Inc. (KAI) C++ Compiler
+
+	# KCC will only create a shared library if the output file
+	# ends with ".so" (or ".sl" for HP-UX), so rename the library
+	# to its proper name (with version) after linking.
+	archive_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+	archive_expsym_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib'
+	# Commands to make compiler produce verbose output that lists
+	# what "hidden" libraries, object files and flags are used when
+	# linking a shared library.
+	#
+	# There doesn't appear to be a way to prevent this compiler from
+	# explicitly linking system object files so we need to strip them
+	# from the output so that they don't get included in the library
+	# dependencies.
+	output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | grep "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
+
+	hardcode_libdir_flag_spec_CXX='${wl}--rpath,$libdir'
+	export_dynamic_flag_spec_CXX='${wl}--export-dynamic'
+
+	# Archives containing C++ object files must be created using
+	# "CC -Bstatic", where "CC" is the KAI C++ compiler.
+	old_archive_cmds_CXX='$CC -Bstatic -o $oldlib $oldobjs'
+	;;
+      icpc*)
+	# Intel C++
+	with_gnu_ld=yes
+	# version 8.0 and above of icpc choke on multiply defined symbols
+	# if we add $predep_objects and $postdep_objects, however 7.1 and
+	# earlier do not add the objects themselves.
+	case `$CC -V 2>&1` in
+	*"Version 7."*)
+  	  archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+  	  archive_expsym_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+	  ;;
+	*)  # Version 8.0 or newer
+	  tmp_idyn=
+	  case $host_cpu in
+	    ia64*) tmp_idyn=' -i_dynamic';;
+	  esac
+  	  archive_cmds_CXX='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	  archive_expsym_cmds_CXX='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+	  ;;
+	esac
+	archive_cmds_need_lc_CXX=no
+	hardcode_libdir_flag_spec_CXX='${wl}-rpath,$libdir'
+	export_dynamic_flag_spec_CXX='${wl}--export-dynamic'
+	whole_archive_flag_spec_CXX='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+	;;
+      pgCC*)
+        # Portland Group C++ compiler
+	archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+  	archive_expsym_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+
+	hardcode_libdir_flag_spec_CXX='${wl}--rpath ${wl}$libdir'
+	export_dynamic_flag_spec_CXX='${wl}--export-dynamic'
+	whole_archive_flag_spec_CXX='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+        ;;
+      cxx*)
+	# Compaq C++
+	archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname  -o $lib ${wl}-retain-symbols-file $wl$export_symbols'
+
+	runpath_var=LD_RUN_PATH
+	hardcode_libdir_flag_spec_CXX='-rpath $libdir'
+	hardcode_libdir_separator_CXX=:
+
+	# Commands to make compiler produce verbose output that lists
+	# what "hidden" libraries, object files and flags are used when
+	# linking a shared library.
+	#
+	# There doesn't appear to be a way to prevent this compiler from
+	# explicitly linking system object files so we need to strip them
+	# from the output so that they don't get included in the library
+	# dependencies.
+	output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
+	;;
+      *)
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)
+	  # Sun C++ 5.9
+	  no_undefined_flag_CXX=' -zdefs'
+	  archive_cmds_CXX='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	  archive_expsym_cmds_CXX='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols'
+	  hardcode_libdir_flag_spec_CXX='-R$libdir'
+	  whole_archive_flag_spec_CXX='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+
+	  # Not sure whether something based on
+	  # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1
+	  # would be better.
+	  output_verbose_link_cmd='echo'
+
+	  # Archives containing C++ object files must be created using
+	  # "CC -xar", where "CC" is the Sun C++ compiler.  This is
+	  # necessary to make sure instantiated templates are included
+	  # in the archive.
+	  old_archive_cmds_CXX='$CC -xar -o $oldlib $oldobjs'
+	  ;;
+	esac
+	;;
+    esac
+    ;;
+  lynxos*)
+    # FIXME: insert proper C++ library support
+    ld_shlibs_CXX=no
+    ;;
+  m88k*)
+    # FIXME: insert proper C++ library support
+    ld_shlibs_CXX=no
+    ;;
+  mvs*)
+    case $cc_basename in
+      cxx*)
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+      *)
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+    esac
+    ;;
+  netbsd*)
+    if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+      archive_cmds_CXX='$LD -Bshareable  -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags'
+      wlarc=
+      hardcode_libdir_flag_spec_CXX='-R$libdir'
+      hardcode_direct_CXX=yes
+      hardcode_shlibpath_var_CXX=no
+    fi
+    # Workaround some broken pre-1.5 toolchains
+    output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"'
+    ;;
+  openbsd2*)
+    # C++ shared libraries are fairly broken
+    ld_shlibs_CXX=no
+    ;;
+  openbsd*)
+    if test -f /usr/libexec/ld.so; then
+      hardcode_direct_CXX=yes
+      hardcode_shlibpath_var_CXX=no
+      archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+      hardcode_libdir_flag_spec_CXX='${wl}-rpath,$libdir'
+      if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	archive_expsym_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib'
+	export_dynamic_flag_spec_CXX='${wl}-E'
+	whole_archive_flag_spec_CXX="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+      fi
+      output_verbose_link_cmd='echo'
+    else
+      ld_shlibs_CXX=no
+    fi
+    ;;
+  osf3*)
+    case $cc_basename in
+      KCC*)
+	# Kuck and Associates, Inc. (KAI) C++ Compiler
+
+	# KCC will only create a shared library if the output file
+	# ends with ".so" (or ".sl" for HP-UX), so rename the library
+	# to its proper name (with version) after linking.
+	archive_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+
+	hardcode_libdir_flag_spec_CXX='${wl}-rpath,$libdir'
+	hardcode_libdir_separator_CXX=:
+
+	# Archives containing C++ object files must be created using
+	# "CC -Bstatic", where "CC" is the KAI C++ compiler.
+	old_archive_cmds_CXX='$CC -Bstatic -o $oldlib $oldobjs'
+
+	;;
+      RCC*)
+	# Rational C++ 2.4.1
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+      cxx*)
+	allow_undefined_flag_CXX=' ${wl}-expect_unresolved ${wl}\*'
+	archive_cmds_CXX='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && echo ${wl}-set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+
+	hardcode_libdir_flag_spec_CXX='${wl}-rpath ${wl}$libdir'
+	hardcode_libdir_separator_CXX=:
+
+	# Commands to make compiler produce verbose output that lists
+	# what "hidden" libraries, object files and flags are used when
+	# linking a shared library.
+	#
+	# There doesn't appear to be a way to prevent this compiler from
+	# explicitly linking system object files so we need to strip them
+	# from the output so that they don't get included in the library
+	# dependencies.
+	output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
+	;;
+      *)
+	if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+	  allow_undefined_flag_CXX=' ${wl}-expect_unresolved ${wl}\*'
+	  archive_cmds_CXX='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+
+	  hardcode_libdir_flag_spec_CXX='${wl}-rpath ${wl}$libdir'
+	  hardcode_libdir_separator_CXX=:
+
+	  # Commands to make compiler produce verbose output that lists
+	  # what "hidden" libraries, object files and flags are used when
+	  # linking a shared library.
+	  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"'
+
+	else
+	  # FIXME: insert proper C++ library support
+	  ld_shlibs_CXX=no
+	fi
+	;;
+    esac
+    ;;
+  osf4* | osf5*)
+    case $cc_basename in
+      KCC*)
+	# Kuck and Associates, Inc. (KAI) C++ Compiler
+
+	# KCC will only create a shared library if the output file
+	# ends with ".so" (or ".sl" for HP-UX), so rename the library
+	# to its proper name (with version) after linking.
+	archive_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+
+	hardcode_libdir_flag_spec_CXX='${wl}-rpath,$libdir'
+	hardcode_libdir_separator_CXX=:
+
+	# Archives containing C++ object files must be created using
+	# the KAI C++ compiler.
+	old_archive_cmds_CXX='$CC -o $oldlib $oldobjs'
+	;;
+      RCC*)
+	# Rational C++ 2.4.1
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+      cxx*)
+	allow_undefined_flag_CXX=' -expect_unresolved \*'
+	archive_cmds_CXX='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+	archive_expsym_cmds_CXX='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~
+	  echo "-hidden">> $lib.exp~
+	  $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname -Wl,-input -Wl,$lib.exp  `test -n "$verstring" && echo -set_version	$verstring` -update_registry ${output_objdir}/so_locations -o $lib~
+	  $rm $lib.exp'
+
+	hardcode_libdir_flag_spec_CXX='-rpath $libdir'
+	hardcode_libdir_separator_CXX=:
+
+	# Commands to make compiler produce verbose output that lists
+	# what "hidden" libraries, object files and flags are used when
+	# linking a shared library.
+	#
+	# There doesn't appear to be a way to prevent this compiler from
+	# explicitly linking system object files so we need to strip them
+	# from the output so that they don't get included in the library
+	# dependencies.
+	output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
+	;;
+      *)
+	if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+	  allow_undefined_flag_CXX=' ${wl}-expect_unresolved ${wl}\*'
+	 archive_cmds_CXX='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+
+	  hardcode_libdir_flag_spec_CXX='${wl}-rpath ${wl}$libdir'
+	  hardcode_libdir_separator_CXX=:
+
+	  # Commands to make compiler produce verbose output that lists
+	  # what "hidden" libraries, object files and flags are used when
+	  # linking a shared library.
+	  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"'
+
+	else
+	  # FIXME: insert proper C++ library support
+	  ld_shlibs_CXX=no
+	fi
+	;;
+    esac
+    ;;
+  psos*)
+    # FIXME: insert proper C++ library support
+    ld_shlibs_CXX=no
+    ;;
+  sunos4*)
+    case $cc_basename in
+      CC*)
+	# Sun C++ 4.x
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+      lcc*)
+	# Lucid
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+      *)
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+    esac
+    ;;
+  solaris*)
+    case $cc_basename in
+      CC*)
+	# Sun C++ 4.2, 5.x and Centerline C++
+        archive_cmds_need_lc_CXX=yes
+	no_undefined_flag_CXX=' -zdefs'
+	archive_cmds_CXX='$CC -G${allow_undefined_flag}  -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	archive_expsym_cmds_CXX='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+	$CC -G${allow_undefined_flag}  ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
+
+	hardcode_libdir_flag_spec_CXX='-R$libdir'
+	hardcode_shlibpath_var_CXX=no
+	case $host_os in
+	  solaris2.[0-5] | solaris2.[0-5].*) ;;
+	  *)
+	    # The compiler driver will combine and reorder linker options,
+	    # but understands `-z linker_flag'.
+	    # Supported since Solaris 2.6 (maybe 2.5.1?)
+	    whole_archive_flag_spec_CXX='-z allextract$convenience -z defaultextract'
+	    ;;
+	esac
+	link_all_deplibs_CXX=yes
+
+	output_verbose_link_cmd='echo'
+
+	# Archives containing C++ object files must be created using
+	# "CC -xar", where "CC" is the Sun C++ compiler.  This is
+	# necessary to make sure instantiated templates are included
+	# in the archive.
+	old_archive_cmds_CXX='$CC -xar -o $oldlib $oldobjs'
+	;;
+      gcx*)
+	# Green Hills C++ Compiler
+	archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+
+	# The C++ compiler must be used to create the archive.
+	old_archive_cmds_CXX='$CC $LDFLAGS -archive -o $oldlib $oldobjs'
+	;;
+      *)
+	# GNU C++ compiler with Solaris linker
+	if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+	  no_undefined_flag_CXX=' ${wl}-z ${wl}defs'
+	  if $CC --version | grep -v '^2\.7' > /dev/null; then
+	    archive_cmds_CXX='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+	    archive_expsym_cmds_CXX='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+		$CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
+
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    output_verbose_link_cmd="$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\""
+	  else
+	    # g++ 2.7 appears to require `-G' NOT `-shared' on this
+	    # platform.
+	    archive_cmds_CXX='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+	    archive_expsym_cmds_CXX='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+		$CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
+
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    output_verbose_link_cmd="$CC -G $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\""
+	  fi
+
+	  hardcode_libdir_flag_spec_CXX='${wl}-R $wl$libdir'
+	  case $host_os in
+	  solaris2.[0-5] | solaris2.[0-5].*) ;;
+	  *)
+	    whole_archive_flag_spec_CXX='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+	    ;;
+	  esac
+	fi
+	;;
+    esac
+    ;;
+  sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*)
+    no_undefined_flag_CXX='${wl}-z,text'
+    archive_cmds_need_lc_CXX=no
+    hardcode_shlibpath_var_CXX=no
+    runpath_var='LD_RUN_PATH'
+
+    case $cc_basename in
+      CC*)
+	archive_cmds_CXX='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_CXX='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	;;
+      *)
+	archive_cmds_CXX='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_CXX='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	;;
+    esac
+    ;;
+  sysv5* | sco3.2v5* | sco5v6*)
+    # Note: We can NOT use -z defs as we might desire, because we do not
+    # link with -lc, and that would cause any symbols used from libc to
+    # always be unresolved, which means just about no library would
+    # ever link correctly.  If we're not using GNU ld we use -z text
+    # though, which does catch some bad symbols but isn't as heavy-handed
+    # as -z defs.
+    # For security reasons, it is highly recommended that you always
+    # use absolute paths for naming shared libraries, and exclude the
+    # DT_RUNPATH tag from executables and libraries.  But doing so
+    # requires that you compile everything twice, which is a pain.
+    # So that behaviour is only enabled if SCOABSPATH is set to a
+    # non-empty value in the environment.  Most likely only useful for
+    # creating official distributions of packages.
+    # This is a hack until libtool officially supports absolute path
+    # names for shared libraries.
+    no_undefined_flag_CXX='${wl}-z,text'
+    allow_undefined_flag_CXX='${wl}-z,nodefs'
+    archive_cmds_need_lc_CXX=no
+    hardcode_shlibpath_var_CXX=no
+    hardcode_libdir_flag_spec_CXX='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`'
+    hardcode_libdir_separator_CXX=':'
+    link_all_deplibs_CXX=yes
+    export_dynamic_flag_spec_CXX='${wl}-Bexport'
+    runpath_var='LD_RUN_PATH'
+
+    case $cc_basename in
+      CC*)
+	archive_cmds_CXX='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_CXX='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	;;
+      *)
+	archive_cmds_CXX='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_CXX='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	;;
+    esac
+    ;;
+  tandem*)
+    case $cc_basename in
+      NCC*)
+	# NonStop-UX NCC 3.20
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+      *)
+	# FIXME: insert proper C++ library support
+	ld_shlibs_CXX=no
+	;;
+    esac
+    ;;
+  vxworks*)
+    # FIXME: insert proper C++ library support
+    ld_shlibs_CXX=no
+    ;;
+  *)
+    # FIXME: insert proper C++ library support
+    ld_shlibs_CXX=no
+    ;;
+esac
+{ echo "$as_me:$LINENO: result: $ld_shlibs_CXX" >&5
+echo "${ECHO_T}$ld_shlibs_CXX" >&6; }
+test "$ld_shlibs_CXX" = no && can_build_shared=no
+
+GCC_CXX="$GXX"
+LD_CXX="$LD"
+
+
+cat > conftest.$ac_ext <<EOF
+class Foo
+{
+public:
+  Foo (void) { a = 0; }
+private:
+  int a;
+};
+EOF
+
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  # Parse the compiler output and extract the necessary
+  # objects, libraries and library flags.
+
+  # Sentinel used to keep track of whether or not we are before
+  # the conftest object file.
+  pre_test_object_deps_done=no
+
+  # The `*' in the case matches for architectures that use `case' in
+  # $output_verbose_cmd can trigger glob expansion during the loop
+  # eval without this substitution.
+  output_verbose_link_cmd=`$echo "X$output_verbose_link_cmd" | $Xsed -e "$no_glob_subst"`
+
+  for p in `eval $output_verbose_link_cmd`; do
+    case $p in
+
+    -L* | -R* | -l*)
+       # Some compilers place space between "-{L,R}" and the path.
+       # Remove the space.
+       if test $p = "-L" \
+	  || test $p = "-R"; then
+	 prev=$p
+	 continue
+       else
+	 prev=
+       fi
+
+       if test "$pre_test_object_deps_done" = no; then
+	 case $p in
+	 -L* | -R*)
+	   # Internal compiler library paths should come after those
+	   # provided the user.  The postdeps already come after the
+	   # user supplied libs so there is no need to process them.
+	   if test -z "$compiler_lib_search_path_CXX"; then
+	     compiler_lib_search_path_CXX="${prev}${p}"
+	   else
+	     compiler_lib_search_path_CXX="${compiler_lib_search_path_CXX} ${prev}${p}"
+	   fi
+	   ;;
+	 # The "-l" case would never come before the object being
+	 # linked, so don't bother handling this case.
+	 esac
+       else
+	 if test -z "$postdeps_CXX"; then
+	   postdeps_CXX="${prev}${p}"
+	 else
+	   postdeps_CXX="${postdeps_CXX} ${prev}${p}"
+	 fi
+       fi
+       ;;
+
+    *.$objext)
+       # This assumes that the test object file only shows up
+       # once in the compiler output.
+       if test "$p" = "conftest.$objext"; then
+	 pre_test_object_deps_done=yes
+	 continue
+       fi
+
+       if test "$pre_test_object_deps_done" = no; then
+	 if test -z "$predep_objects_CXX"; then
+	   predep_objects_CXX="$p"
+	 else
+	   predep_objects_CXX="$predep_objects_CXX $p"
+	 fi
+       else
+	 if test -z "$postdep_objects_CXX"; then
+	   postdep_objects_CXX="$p"
+	 else
+	   postdep_objects_CXX="$postdep_objects_CXX $p"
+	 fi
+       fi
+       ;;
+
+    *) ;; # Ignore the rest.
+
+    esac
+  done
+
+  # Clean up.
+  rm -f a.out a.exe
+else
+  echo "libtool.m4: error: problem compiling CXX test program"
+fi
+
+$rm -f confest.$objext
+
+# PORTME: override above test on systems where it is broken
+case $host_os in
+interix[3-9]*)
+  # Interix 3.5 installs completely hosed .la files for C++, so rather than
+  # hack all around it, let's just trust "g++" to DTRT.
+  predep_objects_CXX=
+  postdep_objects_CXX=
+  postdeps_CXX=
+  ;;
+
+linux*)
+  case `$CC -V 2>&1 | sed 5q` in
+  *Sun\ C*)
+    # Sun C++ 5.9
+    #
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+    if test "$solaris_use_stlport4" != yes; then
+      postdeps_CXX='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+
+solaris*)
+  case $cc_basename in
+  CC*)
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+
+    # Adding this requires a known-good setup of shared libraries for
+    # Sun compiler versions before 5.6, else PIC objects from an old
+    # archive will be linked into the output, leading to subtle bugs.
+    if test "$solaris_use_stlport4" != yes; then
+      postdeps_CXX='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+esac
+
+
+case " $postdeps_CXX " in
+*" -lc "*) archive_cmds_need_lc_CXX=no ;;
+esac
+
+lt_prog_compiler_wl_CXX=
+lt_prog_compiler_pic_CXX=
+lt_prog_compiler_static_CXX=
+
+{ echo "$as_me:$LINENO: checking for $compiler option to produce PIC" >&5
+echo $ECHO_N "checking for $compiler option to produce PIC... $ECHO_C" >&6; }
+
+  # C++ specific cases for pic, static, wl, etc.
+  if test "$GXX" = yes; then
+    lt_prog_compiler_wl_CXX='-Wl,'
+    lt_prog_compiler_static_CXX='-static'
+
+    case $host_os in
+    aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	lt_prog_compiler_static_CXX='-Bstatic'
+      fi
+      ;;
+    amigaos*)
+      # FIXME: we need at least 68020 code to build shared libraries, but
+      # adding the `-m68020' flag to GCC prevents building anything better,
+      # like `-m68040'.
+      lt_prog_compiler_pic_CXX='-m68020 -resident32 -malways-restore-a4'
+      ;;
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+    mingw* | cygwin* | os2* | pw32*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      lt_prog_compiler_pic_CXX='-DDLL_EXPORT'
+      ;;
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      lt_prog_compiler_pic_CXX='-fno-common'
+      ;;
+    *djgpp*)
+      # DJGPP does not support shared libraries at all
+      lt_prog_compiler_pic_CXX=
+      ;;
+    interix[3-9]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	lt_prog_compiler_pic_CXX=-Kconform_pic
+      fi
+      ;;
+    hpux*)
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	;;
+      *)
+	lt_prog_compiler_pic_CXX='-fPIC'
+	;;
+      esac
+      ;;
+    *)
+      lt_prog_compiler_pic_CXX='-fPIC'
+      ;;
+    esac
+  else
+    case $host_os in
+      aix4* | aix5*)
+	# All AIX code is PIC.
+	if test "$host_cpu" = ia64; then
+	  # AIX 5 now supports IA64 processor
+	  lt_prog_compiler_static_CXX='-Bstatic'
+	else
+	  lt_prog_compiler_static_CXX='-bnso -bI:/lib/syscalls.exp'
+	fi
+	;;
+      chorus*)
+	case $cc_basename in
+	cxch68*)
+	  # Green Hills C++ Compiler
+	  # _LT_AC_TAGVAR(lt_prog_compiler_static, CXX)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a"
+	  ;;
+	esac
+	;;
+       darwin*)
+         # PIC is the default on this platform
+         # Common symbols not allowed in MH_DYLIB files
+         case $cc_basename in
+           xlc*)
+           lt_prog_compiler_pic_CXX='-qnocommon'
+           lt_prog_compiler_wl_CXX='-Wl,'
+           ;;
+         esac
+       ;;
+      dgux*)
+	case $cc_basename in
+	  ec++*)
+	    lt_prog_compiler_pic_CXX='-KPIC'
+	    ;;
+	  ghcx*)
+	    # Green Hills C++ Compiler
+	    lt_prog_compiler_pic_CXX='-pic'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      freebsd* | dragonfly*)
+	# FreeBSD uses GNU C++
+	;;
+      hpux9* | hpux10* | hpux11*)
+	case $cc_basename in
+	  CC*)
+	    lt_prog_compiler_wl_CXX='-Wl,'
+	    lt_prog_compiler_static_CXX='${wl}-a ${wl}archive'
+	    if test "$host_cpu" != ia64; then
+	      lt_prog_compiler_pic_CXX='+Z'
+	    fi
+	    ;;
+	  aCC*)
+	    lt_prog_compiler_wl_CXX='-Wl,'
+	    lt_prog_compiler_static_CXX='${wl}-a ${wl}archive'
+	    case $host_cpu in
+	    hppa*64*|ia64*)
+	      # +Z the default
+	      ;;
+	    *)
+	      lt_prog_compiler_pic_CXX='+Z'
+	      ;;
+	    esac
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      interix*)
+	# This is c89, which is MS Visual C++ (no shared libs)
+	# Anyone wants to do a port?
+	;;
+      irix5* | irix6* | nonstopux*)
+	case $cc_basename in
+	  CC*)
+	    lt_prog_compiler_wl_CXX='-Wl,'
+	    lt_prog_compiler_static_CXX='-non_shared'
+	    # CC pic flag -KPIC is the default.
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      linux* | k*bsd*-gnu)
+	case $cc_basename in
+	  KCC*)
+	    # KAI C++ Compiler
+	    lt_prog_compiler_wl_CXX='--backend -Wl,'
+	    lt_prog_compiler_pic_CXX='-fPIC'
+	    ;;
+	  icpc* | ecpc*)
+	    # Intel C++
+	    lt_prog_compiler_wl_CXX='-Wl,'
+	    lt_prog_compiler_pic_CXX='-KPIC'
+	    lt_prog_compiler_static_CXX='-static'
+	    ;;
+	  pgCC*)
+	    # Portland Group C++ compiler.
+	    lt_prog_compiler_wl_CXX='-Wl,'
+	    lt_prog_compiler_pic_CXX='-fpic'
+	    lt_prog_compiler_static_CXX='-Bstatic'
+	    ;;
+	  cxx*)
+	    # Compaq C++
+	    # Make sure the PIC flag is empty.  It appears that all Alpha
+	    # Linux and Compaq Tru64 Unix objects are PIC.
+	    lt_prog_compiler_pic_CXX=
+	    lt_prog_compiler_static_CXX='-non_shared'
+	    ;;
+	  *)
+	    case `$CC -V 2>&1 | sed 5q` in
+	    *Sun\ C*)
+	      # Sun C++ 5.9
+	      lt_prog_compiler_pic_CXX='-KPIC'
+	      lt_prog_compiler_static_CXX='-Bstatic'
+	      lt_prog_compiler_wl_CXX='-Qoption ld '
+	      ;;
+	    esac
+	    ;;
+	esac
+	;;
+      lynxos*)
+	;;
+      m88k*)
+	;;
+      mvs*)
+	case $cc_basename in
+	  cxx*)
+	    lt_prog_compiler_pic_CXX='-W c,exportall'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      netbsd*)
+	;;
+      osf3* | osf4* | osf5*)
+	case $cc_basename in
+	  KCC*)
+	    lt_prog_compiler_wl_CXX='--backend -Wl,'
+	    ;;
+	  RCC*)
+	    # Rational C++ 2.4.1
+	    lt_prog_compiler_pic_CXX='-pic'
+	    ;;
+	  cxx*)
+	    # Digital/Compaq C++
+	    lt_prog_compiler_wl_CXX='-Wl,'
+	    # Make sure the PIC flag is empty.  It appears that all Alpha
+	    # Linux and Compaq Tru64 Unix objects are PIC.
+	    lt_prog_compiler_pic_CXX=
+	    lt_prog_compiler_static_CXX='-non_shared'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      psos*)
+	;;
+      solaris*)
+	case $cc_basename in
+	  CC*)
+	    # Sun C++ 4.2, 5.x and Centerline C++
+	    lt_prog_compiler_pic_CXX='-KPIC'
+	    lt_prog_compiler_static_CXX='-Bstatic'
+	    lt_prog_compiler_wl_CXX='-Qoption ld '
+	    ;;
+	  gcx*)
+	    # Green Hills C++ Compiler
+	    lt_prog_compiler_pic_CXX='-PIC'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      sunos4*)
+	case $cc_basename in
+	  CC*)
+	    # Sun C++ 4.x
+	    lt_prog_compiler_pic_CXX='-pic'
+	    lt_prog_compiler_static_CXX='-Bstatic'
+	    ;;
+	  lcc*)
+	    # Lucid
+	    lt_prog_compiler_pic_CXX='-pic'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      tandem*)
+	case $cc_basename in
+	  NCC*)
+	    # NonStop-UX NCC 3.20
+	    lt_prog_compiler_pic_CXX='-KPIC'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+	case $cc_basename in
+	  CC*)
+	    lt_prog_compiler_wl_CXX='-Wl,'
+	    lt_prog_compiler_pic_CXX='-KPIC'
+	    lt_prog_compiler_static_CXX='-Bstatic'
+	    ;;
+	esac
+	;;
+      vxworks*)
+	;;
+      *)
+	lt_prog_compiler_can_build_shared_CXX=no
+	;;
+    esac
+  fi
+
+{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_CXX" >&5
+echo "${ECHO_T}$lt_prog_compiler_pic_CXX" >&6; }
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$lt_prog_compiler_pic_CXX"; then
+
+{ echo "$as_me:$LINENO: checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works" >&5
+echo $ECHO_N "checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works... $ECHO_C" >&6; }
+if test "${lt_prog_compiler_pic_works_CXX+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_prog_compiler_pic_works_CXX=no
+  ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$lt_prog_compiler_pic_CXX -DPIC"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:12701: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:12705: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_prog_compiler_pic_works_CXX=yes
+     fi
+   fi
+   $rm conftest*
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_works_CXX" >&5
+echo "${ECHO_T}$lt_prog_compiler_pic_works_CXX" >&6; }
+
+if test x"$lt_prog_compiler_pic_works_CXX" = xyes; then
+    case $lt_prog_compiler_pic_CXX in
+     "" | " "*) ;;
+     *) lt_prog_compiler_pic_CXX=" $lt_prog_compiler_pic_CXX" ;;
+     esac
+else
+    lt_prog_compiler_pic_CXX=
+     lt_prog_compiler_can_build_shared_CXX=no
+fi
+
+fi
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    lt_prog_compiler_pic_CXX=
+    ;;
+  *)
+    lt_prog_compiler_pic_CXX="$lt_prog_compiler_pic_CXX -DPIC"
+    ;;
+esac
+
+#
+# Check to make sure the static flag actually works.
+#
+wl=$lt_prog_compiler_wl_CXX eval lt_tmp_static_flag=\"$lt_prog_compiler_static_CXX\"
+{ echo "$as_me:$LINENO: checking if $compiler static flag $lt_tmp_static_flag works" >&5
+echo $ECHO_N "checking if $compiler static flag $lt_tmp_static_flag works... $ECHO_C" >&6; }
+if test "${lt_prog_compiler_static_works_CXX+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_prog_compiler_static_works_CXX=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $lt_tmp_static_flag"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&5
+       $echo "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         lt_prog_compiler_static_works_CXX=yes
+       fi
+     else
+       lt_prog_compiler_static_works_CXX=yes
+     fi
+   fi
+   $rm conftest*
+   LDFLAGS="$save_LDFLAGS"
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_prog_compiler_static_works_CXX" >&5
+echo "${ECHO_T}$lt_prog_compiler_static_works_CXX" >&6; }
+
+if test x"$lt_prog_compiler_static_works_CXX" = xyes; then
+    :
+else
+    lt_prog_compiler_static_CXX=
+fi
+
+
+{ echo "$as_me:$LINENO: checking if $compiler supports -c -o file.$ac_objext" >&5
+echo $ECHO_N "checking if $compiler supports -c -o file.$ac_objext... $ECHO_C" >&6; }
+if test "${lt_cv_prog_compiler_c_o_CXX+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_cv_prog_compiler_c_o_CXX=no
+   $rm -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:12805: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&5
+   echo "$as_me:12809: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_c_o_CXX=yes
+     fi
+   fi
+   chmod u+w . 2>&5
+   $rm conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files
+   $rm out/* && rmdir out
+   cd ..
+   rmdir conftest
+   $rm conftest*
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_c_o_CXX" >&5
+echo "${ECHO_T}$lt_cv_prog_compiler_c_o_CXX" >&6; }
+
+
+hard_links="nottested"
+if test "$lt_cv_prog_compiler_c_o_CXX" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  { echo "$as_me:$LINENO: checking if we can lock with hard links" >&5
+echo $ECHO_N "checking if we can lock with hard links... $ECHO_C" >&6; }
+  hard_links=yes
+  $rm conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  { echo "$as_me:$LINENO: result: $hard_links" >&5
+echo "${ECHO_T}$hard_links" >&6; }
+  if test "$hard_links" = no; then
+    { echo "$as_me:$LINENO: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5
+echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;}
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+
+{ echo "$as_me:$LINENO: checking whether the $compiler linker ($LD) supports shared libraries" >&5
+echo $ECHO_N "checking whether the $compiler linker ($LD) supports shared libraries... $ECHO_C" >&6; }
+
+  export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  case $host_os in
+  aix4* | aix5*)
+    # If we're using GNU nm, then we don't want the "-C" option.
+    # -C means demangle to AIX nm, but means don't demangle with GNU nm
+    if $NM -V 2>&1 | grep 'GNU' > /dev/null; then
+      export_symbols_cmds_CXX='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols'
+    else
+      export_symbols_cmds_CXX='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols'
+    fi
+    ;;
+  pw32*)
+    export_symbols_cmds_CXX="$ltdll_cmds"
+  ;;
+  cygwin* | mingw*)
+    export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;/^.*[ ]__nm__/s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols'
+  ;;
+  *)
+    export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  ;;
+  esac
+
+{ echo "$as_me:$LINENO: result: $ld_shlibs_CXX" >&5
+echo "${ECHO_T}$ld_shlibs_CXX" >&6; }
+test "$ld_shlibs_CXX" = no && can_build_shared=no
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$archive_cmds_need_lc_CXX" in
+x|xyes)
+  # Assume -lc should be added
+  archive_cmds_need_lc_CXX=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $archive_cmds_CXX in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      { echo "$as_me:$LINENO: checking whether -lc should be explicitly linked in" >&5
+echo $ECHO_N "checking whether -lc should be explicitly linked in... $ECHO_C" >&6; }
+      $rm conftest*
+      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+      if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } 2>conftest.err; then
+        soname=conftest
+        lib=conftest
+        libobjs=conftest.$ac_objext
+        deplibs=
+        wl=$lt_prog_compiler_wl_CXX
+	pic_flag=$lt_prog_compiler_pic_CXX
+        compiler_flags=-v
+        linker_flags=-v
+        verstring=
+        output_objdir=.
+        libname=conftest
+        lt_save_allow_undefined_flag=$allow_undefined_flag_CXX
+        allow_undefined_flag_CXX=
+        if { (eval echo "$as_me:$LINENO: \"$archive_cmds_CXX 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1\"") >&5
+  (eval $archive_cmds_CXX 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+        then
+	  archive_cmds_need_lc_CXX=no
+        else
+	  archive_cmds_need_lc_CXX=yes
+        fi
+        allow_undefined_flag_CXX=$lt_save_allow_undefined_flag
+      else
+        cat conftest.err 1>&5
+      fi
+      $rm conftest*
+      { echo "$as_me:$LINENO: result: $archive_cmds_need_lc_CXX" >&5
+echo "${ECHO_T}$archive_cmds_need_lc_CXX" >&6; }
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+{ echo "$as_me:$LINENO: checking dynamic linker characteristics" >&5
+echo $ECHO_N "checking dynamic linker characteristics... $ECHO_C" >&6; }
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix4* | aix5*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[01] | aix4.[01].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+	   echo ' yes '
+	   echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then
+	:
+      else
+	can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  library_names_spec='$libname.ixlibrary $libname.a'
+  # Create ${libname}_ixlibrary.a entries in /sys/libs.
+  finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[45]*)
+  version_type=linux
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$host_os in
+  yes,cygwin* | yes,mingw* | yes,pw32*)
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $rm \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
+      ;;
+    mingw*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+      if echo "$sys_lib_search_path_spec" | grep ';[c-zC-Z]:/' >/dev/null; then
+        # It is most probably a Windows format PATH printed by
+        # mingw gcc, but we are running on Cygwin. Gcc prints its search
+        # path with ; separators, and with drive letters. We can handle the
+        # drive letters (cygwin fileutils understands them), so leave them,
+        # especially as we might pass files found there to a mingw objdump,
+        # which wouldn't understand a cygwinified path. Ahh.
+        sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    ;;
+
+  *)
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    ;;
+  esac
+  dynamic_linker='Win32 ld.exe'
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd1*)
+  dynamic_linker=no
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[123]*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[01]* | freebsdelf3.[01]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[2-9]* | freebsdelf3.[2-9]* | \
+  freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+gnu*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+   hppa*64*)
+     shrext_cmds='.sl'
+     hardcode_into_libs=yes
+     dynamic_linker="$host_os dld.sl"
+     shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+     shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+     library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+     soname_spec='${libname}${release}${shared_ext}$major'
+     sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+     sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+     ;;
+   *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555.
+  postinstall_cmds='chmod 555 $lib'
+  ;;
+
+interix[3-9]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+	if test "$lt_cv_prog_gnu_ld" = yes; then
+		version_type=linux
+	else
+		version_type=irix
+	fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ 	]*hwcap[ 	]/d;s/[:,	]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+nto-qnx*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*) need_version=yes ;;
+    *)                         need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[89] | openbsd2.[89].*)
+	shlibpath_overrides_runpath=no
+	;;
+      *)
+	shlibpath_overrides_runpath=yes
+	;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      export_dynamic_flag_spec='${wl}-Blargedynsym'
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+    shlibpath_overrides_runpath=no
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    shlibpath_overrides_runpath=yes
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+	;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+uts4*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+{ echo "$as_me:$LINENO: result: $dynamic_linker" >&5
+echo "${ECHO_T}$dynamic_linker" >&6; }
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+{ echo "$as_me:$LINENO: checking how to hardcode library paths into programs" >&5
+echo $ECHO_N "checking how to hardcode library paths into programs... $ECHO_C" >&6; }
+hardcode_action_CXX=
+if test -n "$hardcode_libdir_flag_spec_CXX" || \
+   test -n "$runpath_var_CXX" || \
+   test "X$hardcode_automatic_CXX" = "Xyes" ; then
+
+  # We can hardcode non-existant directories.
+  if test "$hardcode_direct_CXX" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, CXX)" != no &&
+     test "$hardcode_minus_L_CXX" != no; then
+    # Linking always hardcodes the temporary library directory.
+    hardcode_action_CXX=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    hardcode_action_CXX=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  hardcode_action_CXX=unsupported
+fi
+{ echo "$as_me:$LINENO: result: $hardcode_action_CXX" >&5
+echo "${ECHO_T}$hardcode_action_CXX" >&6; }
+
+if test "$hardcode_action_CXX" = relink; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+
+
+# The else clause should only fire when bootstrapping the
+# libtool distribution, otherwise you forgot to ship ltmain.sh
+# with your package, and you will get complaints that there are
+# no rules to generate ltmain.sh.
+if test -f "$ltmain"; then
+  # See if we are running on zsh, and set the options which allow our commands through
+  # without removal of \ escapes.
+  if test -n "${ZSH_VERSION+set}" ; then
+    setopt NO_GLOB_SUBST
+  fi
+  # Now quote all the things that may contain metacharacters while being
+  # careful not to overquote the AC_SUBSTed values.  We take copies of the
+  # variables and quote the copies for generation of the libtool script.
+  for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC LTCFLAGS NM \
+    SED SHELL STRIP \
+    libname_spec library_names_spec soname_spec extract_expsyms_cmds \
+    old_striplib striplib file_magic_cmd finish_cmds finish_eval \
+    deplibs_check_method reload_flag reload_cmds need_locks \
+    lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \
+    lt_cv_sys_global_symbol_to_c_name_address \
+    sys_lib_search_path_spec sys_lib_dlsearch_path_spec \
+    old_postinstall_cmds old_postuninstall_cmds \
+    compiler_CXX \
+    CC_CXX \
+    LD_CXX \
+    lt_prog_compiler_wl_CXX \
+    lt_prog_compiler_pic_CXX \
+    lt_prog_compiler_static_CXX \
+    lt_prog_compiler_no_builtin_flag_CXX \
+    export_dynamic_flag_spec_CXX \
+    thread_safe_flag_spec_CXX \
+    whole_archive_flag_spec_CXX \
+    enable_shared_with_static_runtimes_CXX \
+    old_archive_cmds_CXX \
+    old_archive_from_new_cmds_CXX \
+    predep_objects_CXX \
+    postdep_objects_CXX \
+    predeps_CXX \
+    postdeps_CXX \
+    compiler_lib_search_path_CXX \
+    archive_cmds_CXX \
+    archive_expsym_cmds_CXX \
+    postinstall_cmds_CXX \
+    postuninstall_cmds_CXX \
+    old_archive_from_expsyms_cmds_CXX \
+    allow_undefined_flag_CXX \
+    no_undefined_flag_CXX \
+    export_symbols_cmds_CXX \
+    hardcode_libdir_flag_spec_CXX \
+    hardcode_libdir_flag_spec_ld_CXX \
+    hardcode_libdir_separator_CXX \
+    hardcode_automatic_CXX \
+    module_cmds_CXX \
+    module_expsym_cmds_CXX \
+    lt_cv_prog_compiler_c_o_CXX \
+    fix_srcfile_path_CXX \
+    exclude_expsyms_CXX \
+    include_expsyms_CXX; do
+
+    case $var in
+    old_archive_cmds_CXX | \
+    old_archive_from_new_cmds_CXX | \
+    archive_cmds_CXX | \
+    archive_expsym_cmds_CXX | \
+    module_cmds_CXX | \
+    module_expsym_cmds_CXX | \
+    old_archive_from_expsyms_cmds_CXX | \
+    export_symbols_cmds_CXX | \
+    extract_expsyms_cmds | reload_cmds | finish_cmds | \
+    postinstall_cmds | postuninstall_cmds | \
+    old_postinstall_cmds | old_postuninstall_cmds | \
+    sys_lib_search_path_spec | sys_lib_dlsearch_path_spec)
+      # Double-quote double-evaled strings.
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\""
+      ;;
+    *)
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\""
+      ;;
+    esac
+  done
+
+  case $lt_echo in
+  *'\$0 --fallback-echo"')
+    lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\$0 --fallback-echo"$/$0 --fallback-echo"/'`
+    ;;
+  esac
+
+cfgfile="$ofile"
+
+  cat <<__EOF__ >> "$cfgfile"
+# ### BEGIN LIBTOOL TAG CONFIG: $tagname
+
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+
+# Shell to use when invoking shell scripts.
+SHELL=$lt_SHELL
+
+# Whether or not to build shared libraries.
+build_libtool_libs=$enable_shared
+
+# Whether or not to build static libraries.
+build_old_libs=$enable_static
+
+# Whether or not to add -lc for building shared libraries.
+build_libtool_need_lc=$archive_cmds_need_lc_CXX
+
+# Whether or not to disallow shared libs when runtime libs are static
+allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes_CXX
+
+# Whether or not to optimize for fast installation.
+fast_install=$enable_fast_install
+
+# The host system.
+host_alias=$host_alias
+host=$host
+host_os=$host_os
+
+# The build system.
+build_alias=$build_alias
+build=$build
+build_os=$build_os
+
+# An echo program that does not interpret backslashes.
+echo=$lt_echo
+
+# The archiver.
+AR=$lt_AR
+AR_FLAGS=$lt_AR_FLAGS
+
+# A C compiler.
+LTCC=$lt_LTCC
+
+# LTCC compiler flags.
+LTCFLAGS=$lt_LTCFLAGS
+
+# A language-specific compiler.
+CC=$lt_compiler_CXX
+
+# Is the compiler the GNU C compiler?
+with_gcc=$GCC_CXX
+
+# An ERE matcher.
+EGREP=$lt_EGREP
+
+# The linker used to build libraries.
+LD=$lt_LD_CXX
+
+# Whether we need hard or soft links.
+LN_S=$lt_LN_S
+
+# A BSD-compatible nm program.
+NM=$lt_NM
+
+# A symbol stripping program
+STRIP=$lt_STRIP
+
+# Used to examine libraries when file_magic_cmd begins "file"
+MAGIC_CMD=$MAGIC_CMD
+
+# Used on cygwin: DLL creation program.
+DLLTOOL="$DLLTOOL"
+
+# Used on cygwin: object dumper.
+OBJDUMP="$OBJDUMP"
+
+# Used on cygwin: assembler.
+AS="$AS"
+
+# The name of the directory that contains temporary libtool files.
+objdir=$objdir
+
+# How to create reloadable object files.
+reload_flag=$lt_reload_flag
+reload_cmds=$lt_reload_cmds
+
+# How to pass a linker flag through the compiler.
+wl=$lt_lt_prog_compiler_wl_CXX
+
+# Object file suffix (normally "o").
+objext="$ac_objext"
+
+# Old archive suffix (normally "a").
+libext="$libext"
+
+# Shared library suffix (normally ".so").
+shrext_cmds='$shrext_cmds'
+
+# Executable file suffix (normally "").
+exeext="$exeext"
+
+# Additional compiler flags for building library objects.
+pic_flag=$lt_lt_prog_compiler_pic_CXX
+pic_mode=$pic_mode
+
+# What is the maximum length of a command?
+max_cmd_len=$lt_cv_sys_max_cmd_len
+
+# Does compiler simultaneously support -c and -o options?
+compiler_c_o=$lt_lt_cv_prog_compiler_c_o_CXX
+
+# Must we lock files when doing compilation?
+need_locks=$lt_need_locks
+
+# Do we need the lib prefix for modules?
+need_lib_prefix=$need_lib_prefix
+
+# Do we need a version for libraries?
+need_version=$need_version
+
+# Whether dlopen is supported.
+dlopen_support=$enable_dlopen
+
+# Whether dlopen of programs is supported.
+dlopen_self=$enable_dlopen_self
+
+# Whether dlopen of statically linked programs is supported.
+dlopen_self_static=$enable_dlopen_self_static
+
+# Compiler flag to prevent dynamic linking.
+link_static_flag=$lt_lt_prog_compiler_static_CXX
+
+# Compiler flag to turn off builtin functions.
+no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag_CXX
+
+# Compiler flag to allow reflexive dlopens.
+export_dynamic_flag_spec=$lt_export_dynamic_flag_spec_CXX
+
+# Compiler flag to generate shared objects directly from archives.
+whole_archive_flag_spec=$lt_whole_archive_flag_spec_CXX
+
+# Compiler flag to generate thread-safe objects.
+thread_safe_flag_spec=$lt_thread_safe_flag_spec_CXX
+
+# Library versioning type.
+version_type=$version_type
+
+# Format of library name prefix.
+libname_spec=$lt_libname_spec
+
+# List of archive names.  First name is the real one, the rest are links.
+# The last name is the one that the linker finds with -lNAME.
+library_names_spec=$lt_library_names_spec
+
+# The coded name of the library, if different from the real name.
+soname_spec=$lt_soname_spec
+
+# Commands used to build and install an old-style archive.
+RANLIB=$lt_RANLIB
+old_archive_cmds=$lt_old_archive_cmds_CXX
+old_postinstall_cmds=$lt_old_postinstall_cmds
+old_postuninstall_cmds=$lt_old_postuninstall_cmds
+
+# Create an old-style archive from a shared archive.
+old_archive_from_new_cmds=$lt_old_archive_from_new_cmds_CXX
+
+# Create a temporary old-style archive to link instead of a shared archive.
+old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds_CXX
+
+# Commands used to build and install a shared archive.
+archive_cmds=$lt_archive_cmds_CXX
+archive_expsym_cmds=$lt_archive_expsym_cmds_CXX
+postinstall_cmds=$lt_postinstall_cmds
+postuninstall_cmds=$lt_postuninstall_cmds
+
+# Commands used to build a loadable module (assumed same as above if empty)
+module_cmds=$lt_module_cmds_CXX
+module_expsym_cmds=$lt_module_expsym_cmds_CXX
+
+# Commands to strip libraries.
+old_striplib=$lt_old_striplib
+striplib=$lt_striplib
+
+# Dependencies to place before the objects being linked to create a
+# shared library.
+predep_objects=$lt_predep_objects_CXX
+
+# Dependencies to place after the objects being linked to create a
+# shared library.
+postdep_objects=$lt_postdep_objects_CXX
+
+# Dependencies to place before the objects being linked to create a
+# shared library.
+predeps=$lt_predeps_CXX
+
+# Dependencies to place after the objects being linked to create a
+# shared library.
+postdeps=$lt_postdeps_CXX
+
+# The library search path used internally by the compiler when linking
+# a shared library.
+compiler_lib_search_path=$lt_compiler_lib_search_path_CXX
+
+# Method to check whether dependent libraries are shared objects.
+deplibs_check_method=$lt_deplibs_check_method
+
+# Command to use when deplibs_check_method == file_magic.
+file_magic_cmd=$lt_file_magic_cmd
+
+# Flag that allows shared libraries with undefined symbols to be built.
+allow_undefined_flag=$lt_allow_undefined_flag_CXX
+
+# Flag that forces no undefined symbols.
+no_undefined_flag=$lt_no_undefined_flag_CXX
+
+# Commands used to finish a libtool library installation in a directory.
+finish_cmds=$lt_finish_cmds
+
+# Same as above, but a single script fragment to be evaled but not shown.
+finish_eval=$lt_finish_eval
+
+# Take the output of nm and produce a listing of raw symbols and C names.
+global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe
+
+# Transform the output of nm in a proper C declaration
+global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl
+
+# Transform the output of nm in a C name address pair
+global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address
+
+# This is the shared library runtime path variable.
+runpath_var=$runpath_var
+
+# This is the shared library path variable.
+shlibpath_var=$shlibpath_var
+
+# Is shlibpath searched before the hard-coded library search path?
+shlibpath_overrides_runpath=$shlibpath_overrides_runpath
+
+# How to hardcode a shared library path into an executable.
+hardcode_action=$hardcode_action_CXX
+
+# Whether we should hardcode library paths into libraries.
+hardcode_into_libs=$hardcode_into_libs
+
+# Flag to hardcode \$libdir into a binary during linking.
+# This must work even if \$libdir does not exist.
+hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec_CXX
+
+# If ld is used when linking, flag to hardcode \$libdir into
+# a binary during linking. This must work even if \$libdir does
+# not exist.
+hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld_CXX
+
+# Whether we need a single -rpath flag with a separated argument.
+hardcode_libdir_separator=$lt_hardcode_libdir_separator_CXX
+
+# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the
+# resulting binary.
+hardcode_direct=$hardcode_direct_CXX
+
+# Set to yes if using the -LDIR flag during linking hardcodes DIR into the
+# resulting binary.
+hardcode_minus_L=$hardcode_minus_L_CXX
+
+# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into
+# the resulting binary.
+hardcode_shlibpath_var=$hardcode_shlibpath_var_CXX
+
+# Set to yes if building a shared library automatically hardcodes DIR into the library
+# and all subsequent libraries and executables linked against it.
+hardcode_automatic=$hardcode_automatic_CXX
+
+# Variables whose values should be saved in libtool wrapper scripts and
+# restored at relink time.
+variables_saved_for_relink="$variables_saved_for_relink"
+
+# Whether libtool must link a program against all its dependency libraries.
+link_all_deplibs=$link_all_deplibs_CXX
+
+# Compile-time system search path for libraries
+sys_lib_search_path_spec=$lt_sys_lib_search_path_spec
+
+# Run-time system search path for libraries
+sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec
+
+# Fix the shell variable \$srcfile for the compiler.
+fix_srcfile_path=$lt_fix_srcfile_path
+
+# Set to yes if exported symbols are required.
+always_export_symbols=$always_export_symbols_CXX
+
+# The commands to list exported symbols.
+export_symbols_cmds=$lt_export_symbols_cmds_CXX
+
+# The commands to extract the exported symbol list from a shared archive.
+extract_expsyms_cmds=$lt_extract_expsyms_cmds
+
+# Symbols that should not be listed in the preloaded symbols.
+exclude_expsyms=$lt_exclude_expsyms_CXX
+
+# Symbols that must always be exported.
+include_expsyms=$lt_include_expsyms_CXX
+
+# ### END LIBTOOL TAG CONFIG: $tagname
+
+__EOF__
+
+
+else
+  # If there is no Makefile yet, we rely on a make rule to execute
+  # `config.status --recheck' to rerun these tests and create the
+  # libtool script then.
+  ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'`
+  if test -f "$ltmain_in"; then
+    test -f Makefile && make "$ltmain"
+  fi
+fi
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+CC=$lt_save_CC
+LDCXX=$LD
+LD=$lt_save_LD
+GCC=$lt_save_GCC
+with_gnu_ldcxx=$with_gnu_ld
+with_gnu_ld=$lt_save_with_gnu_ld
+lt_cv_path_LDCXX=$lt_cv_path_LD
+lt_cv_path_LD=$lt_save_path_LD
+lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld
+lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld
+
+	else
+	  tagname=""
+	fi
+	;;
+
+      F77)
+	if test -n "$F77" && test "X$F77" != "Xno"; then
+
+ac_ext=f
+ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&5'
+ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_f77_compiler_gnu
+
+
+archive_cmds_need_lc_F77=no
+allow_undefined_flag_F77=
+always_export_symbols_F77=no
+archive_expsym_cmds_F77=
+export_dynamic_flag_spec_F77=
+hardcode_direct_F77=no
+hardcode_libdir_flag_spec_F77=
+hardcode_libdir_flag_spec_ld_F77=
+hardcode_libdir_separator_F77=
+hardcode_minus_L_F77=no
+hardcode_automatic_F77=no
+module_cmds_F77=
+module_expsym_cmds_F77=
+link_all_deplibs_F77=unknown
+old_archive_cmds_F77=$old_archive_cmds
+no_undefined_flag_F77=
+whole_archive_flag_spec_F77=
+enable_shared_with_static_runtimes_F77=no
+
+# Source file extension for f77 test sources.
+ac_ext=f
+
+# Object file extension for compiled f77 test sources.
+objext=o
+objext_F77=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="\
+      subroutine t
+      return
+      end
+"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code="\
+      program t
+      end
+"
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+
+# save warnings/boilerplate of simple test code
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$rm conftest*
+
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$rm conftest*
+
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+CC=${F77-"f77"}
+compiler=$CC
+compiler_F77=$CC
+for cc_temp in $compiler""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+
+
+{ echo "$as_me:$LINENO: checking if libtool supports shared libraries" >&5
+echo $ECHO_N "checking if libtool supports shared libraries... $ECHO_C" >&6; }
+{ echo "$as_me:$LINENO: result: $can_build_shared" >&5
+echo "${ECHO_T}$can_build_shared" >&6; }
+
+{ echo "$as_me:$LINENO: checking whether to build shared libraries" >&5
+echo $ECHO_N "checking whether to build shared libraries... $ECHO_C" >&6; }
+test "$can_build_shared" = "no" && enable_shared=no
+
+# On AIX, shared libraries and static libraries use the same namespace, and
+# are all built from PIC.
+case $host_os in
+aix3*)
+  test "$enable_shared" = yes && enable_static=no
+  if test -n "$RANLIB"; then
+    archive_cmds="$archive_cmds~\$RANLIB \$lib"
+    postinstall_cmds='$RANLIB $lib'
+  fi
+  ;;
+aix4* | aix5*)
+  if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+    test "$enable_shared" = yes && enable_static=no
+  fi
+  ;;
+esac
+{ echo "$as_me:$LINENO: result: $enable_shared" >&5
+echo "${ECHO_T}$enable_shared" >&6; }
+
+{ echo "$as_me:$LINENO: checking whether to build static libraries" >&5
+echo $ECHO_N "checking whether to build static libraries... $ECHO_C" >&6; }
+# Make sure either enable_shared or enable_static is yes.
+test "$enable_shared" = yes || enable_static=yes
+{ echo "$as_me:$LINENO: result: $enable_static" >&5
+echo "${ECHO_T}$enable_static" >&6; }
+
+GCC_F77="$G77"
+LD_F77="$LD"
+
+lt_prog_compiler_wl_F77=
+lt_prog_compiler_pic_F77=
+lt_prog_compiler_static_F77=
+
+{ echo "$as_me:$LINENO: checking for $compiler option to produce PIC" >&5
+echo $ECHO_N "checking for $compiler option to produce PIC... $ECHO_C" >&6; }
+
+  if test "$GCC" = yes; then
+    lt_prog_compiler_wl_F77='-Wl,'
+    lt_prog_compiler_static_F77='-static'
+
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	lt_prog_compiler_static_F77='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      # FIXME: we need at least 68020 code to build shared libraries, but
+      # adding the `-m68020' flag to GCC prevents building anything better,
+      # like `-m68040'.
+      lt_prog_compiler_pic_F77='-m68020 -resident32 -malways-restore-a4'
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      lt_prog_compiler_pic_F77='-DDLL_EXPORT'
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      lt_prog_compiler_pic_F77='-fno-common'
+      ;;
+
+    interix[3-9]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      lt_prog_compiler_can_build_shared_F77=no
+      enable_shared=no
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	lt_prog_compiler_pic_F77=-Kconform_pic
+      fi
+      ;;
+
+    hpux*)
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	lt_prog_compiler_pic_F77='-fPIC'
+	;;
+      esac
+      ;;
+
+    *)
+      lt_prog_compiler_pic_F77='-fPIC'
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      lt_prog_compiler_wl_F77='-Wl,'
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	lt_prog_compiler_static_F77='-Bstatic'
+      else
+	lt_prog_compiler_static_F77='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+      darwin*)
+        # PIC is the default on this platform
+        # Common symbols not allowed in MH_DYLIB files
+       case $cc_basename in
+         xlc*)
+         lt_prog_compiler_pic_F77='-qnocommon'
+         lt_prog_compiler_wl_F77='-Wl,'
+         ;;
+       esac
+       ;;
+
+    mingw* | cygwin* | pw32* | os2*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      lt_prog_compiler_pic_F77='-DDLL_EXPORT'
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      lt_prog_compiler_wl_F77='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	lt_prog_compiler_pic_F77='+Z'
+	;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      lt_prog_compiler_static_F77='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      lt_prog_compiler_wl_F77='-Wl,'
+      # PIC (with -KPIC) is the default.
+      lt_prog_compiler_static_F77='-non_shared'
+      ;;
+
+    newsos6)
+      lt_prog_compiler_pic_F77='-KPIC'
+      lt_prog_compiler_static_F77='-Bstatic'
+      ;;
+
+    linux* | k*bsd*-gnu)
+      case $cc_basename in
+      icc* | ecc*)
+	lt_prog_compiler_wl_F77='-Wl,'
+	lt_prog_compiler_pic_F77='-KPIC'
+	lt_prog_compiler_static_F77='-static'
+        ;;
+      pgcc* | pgf77* | pgf90* | pgf95*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+	# which looks to be a dead project)
+	lt_prog_compiler_wl_F77='-Wl,'
+	lt_prog_compiler_pic_F77='-fpic'
+	lt_prog_compiler_static_F77='-Bstatic'
+        ;;
+      ccc*)
+        lt_prog_compiler_wl_F77='-Wl,'
+        # All Alpha code is PIC.
+        lt_prog_compiler_static_F77='-non_shared'
+        ;;
+      *)
+        case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)
+	  # Sun C 5.9
+	  lt_prog_compiler_pic_F77='-KPIC'
+	  lt_prog_compiler_static_F77='-Bstatic'
+	  lt_prog_compiler_wl_F77='-Wl,'
+	  ;;
+	*Sun\ F*)
+	  # Sun Fortran 8.3 passes all unrecognized flags to the linker
+	  lt_prog_compiler_pic_F77='-KPIC'
+	  lt_prog_compiler_static_F77='-Bstatic'
+	  lt_prog_compiler_wl_F77=''
+	  ;;
+	esac
+	;;
+      esac
+      ;;
+
+    osf3* | osf4* | osf5*)
+      lt_prog_compiler_wl_F77='-Wl,'
+      # All OSF/1 code is PIC.
+      lt_prog_compiler_static_F77='-non_shared'
+      ;;
+
+    rdos*)
+      lt_prog_compiler_static_F77='-non_shared'
+      ;;
+
+    solaris*)
+      lt_prog_compiler_pic_F77='-KPIC'
+      lt_prog_compiler_static_F77='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95*)
+	lt_prog_compiler_wl_F77='-Qoption ld ';;
+      *)
+	lt_prog_compiler_wl_F77='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      lt_prog_compiler_wl_F77='-Qoption ld '
+      lt_prog_compiler_pic_F77='-PIC'
+      lt_prog_compiler_static_F77='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      lt_prog_compiler_wl_F77='-Wl,'
+      lt_prog_compiler_pic_F77='-KPIC'
+      lt_prog_compiler_static_F77='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+	lt_prog_compiler_pic_F77='-Kconform_pic'
+	lt_prog_compiler_static_F77='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      lt_prog_compiler_wl_F77='-Wl,'
+      lt_prog_compiler_pic_F77='-KPIC'
+      lt_prog_compiler_static_F77='-Bstatic'
+      ;;
+
+    unicos*)
+      lt_prog_compiler_wl_F77='-Wl,'
+      lt_prog_compiler_can_build_shared_F77=no
+      ;;
+
+    uts4*)
+      lt_prog_compiler_pic_F77='-pic'
+      lt_prog_compiler_static_F77='-Bstatic'
+      ;;
+
+    *)
+      lt_prog_compiler_can_build_shared_F77=no
+      ;;
+    esac
+  fi
+
+{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_F77" >&5
+echo "${ECHO_T}$lt_prog_compiler_pic_F77" >&6; }
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$lt_prog_compiler_pic_F77"; then
+
+{ echo "$as_me:$LINENO: checking if $compiler PIC flag $lt_prog_compiler_pic_F77 works" >&5
+echo $ECHO_N "checking if $compiler PIC flag $lt_prog_compiler_pic_F77 works... $ECHO_C" >&6; }
+if test "${lt_prog_compiler_pic_works_F77+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_prog_compiler_pic_works_F77=no
+  ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$lt_prog_compiler_pic_F77"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:14369: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:14373: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_prog_compiler_pic_works_F77=yes
+     fi
+   fi
+   $rm conftest*
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_works_F77" >&5
+echo "${ECHO_T}$lt_prog_compiler_pic_works_F77" >&6; }
+
+if test x"$lt_prog_compiler_pic_works_F77" = xyes; then
+    case $lt_prog_compiler_pic_F77 in
+     "" | " "*) ;;
+     *) lt_prog_compiler_pic_F77=" $lt_prog_compiler_pic_F77" ;;
+     esac
+else
+    lt_prog_compiler_pic_F77=
+     lt_prog_compiler_can_build_shared_F77=no
+fi
+
+fi
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    lt_prog_compiler_pic_F77=
+    ;;
+  *)
+    lt_prog_compiler_pic_F77="$lt_prog_compiler_pic_F77"
+    ;;
+esac
+
+#
+# Check to make sure the static flag actually works.
+#
+wl=$lt_prog_compiler_wl_F77 eval lt_tmp_static_flag=\"$lt_prog_compiler_static_F77\"
+{ echo "$as_me:$LINENO: checking if $compiler static flag $lt_tmp_static_flag works" >&5
+echo $ECHO_N "checking if $compiler static flag $lt_tmp_static_flag works... $ECHO_C" >&6; }
+if test "${lt_prog_compiler_static_works_F77+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_prog_compiler_static_works_F77=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $lt_tmp_static_flag"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&5
+       $echo "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         lt_prog_compiler_static_works_F77=yes
+       fi
+     else
+       lt_prog_compiler_static_works_F77=yes
+     fi
+   fi
+   $rm conftest*
+   LDFLAGS="$save_LDFLAGS"
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_prog_compiler_static_works_F77" >&5
+echo "${ECHO_T}$lt_prog_compiler_static_works_F77" >&6; }
+
+if test x"$lt_prog_compiler_static_works_F77" = xyes; then
+    :
+else
+    lt_prog_compiler_static_F77=
+fi
+
+
+{ echo "$as_me:$LINENO: checking if $compiler supports -c -o file.$ac_objext" >&5
+echo $ECHO_N "checking if $compiler supports -c -o file.$ac_objext... $ECHO_C" >&6; }
+if test "${lt_cv_prog_compiler_c_o_F77+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_cv_prog_compiler_c_o_F77=no
+   $rm -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:14473: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&5
+   echo "$as_me:14477: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_c_o_F77=yes
+     fi
+   fi
+   chmod u+w . 2>&5
+   $rm conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files
+   $rm out/* && rmdir out
+   cd ..
+   rmdir conftest
+   $rm conftest*
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_c_o_F77" >&5
+echo "${ECHO_T}$lt_cv_prog_compiler_c_o_F77" >&6; }
+
+
+hard_links="nottested"
+if test "$lt_cv_prog_compiler_c_o_F77" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  { echo "$as_me:$LINENO: checking if we can lock with hard links" >&5
+echo $ECHO_N "checking if we can lock with hard links... $ECHO_C" >&6; }
+  hard_links=yes
+  $rm conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  { echo "$as_me:$LINENO: result: $hard_links" >&5
+echo "${ECHO_T}$hard_links" >&6; }
+  if test "$hard_links" = no; then
+    { echo "$as_me:$LINENO: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5
+echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;}
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+
+{ echo "$as_me:$LINENO: checking whether the $compiler linker ($LD) supports shared libraries" >&5
+echo $ECHO_N "checking whether the $compiler linker ($LD) supports shared libraries... $ECHO_C" >&6; }
+
+  runpath_var=
+  allow_undefined_flag_F77=
+  enable_shared_with_static_runtimes_F77=no
+  archive_cmds_F77=
+  archive_expsym_cmds_F77=
+  old_archive_From_new_cmds_F77=
+  old_archive_from_expsyms_cmds_F77=
+  export_dynamic_flag_spec_F77=
+  whole_archive_flag_spec_F77=
+  thread_safe_flag_spec_F77=
+  hardcode_libdir_flag_spec_F77=
+  hardcode_libdir_flag_spec_ld_F77=
+  hardcode_libdir_separator_F77=
+  hardcode_direct_F77=no
+  hardcode_minus_L_F77=no
+  hardcode_shlibpath_var_F77=unsupported
+  link_all_deplibs_F77=unknown
+  hardcode_automatic_F77=no
+  module_cmds_F77=
+  module_expsym_cmds_F77=
+  always_export_symbols_F77=no
+  export_symbols_cmds_F77='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  include_expsyms_F77=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  exclude_expsyms_F77="_GLOBAL_OFFSET_TABLE_"
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  extract_expsyms_cmds=
+  # Just being paranoid about ensuring that cc_basename is set.
+  for cc_temp in $compiler""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+
+  case $host_os in
+  cygwin* | mingw* | pw32*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  esac
+
+  ld_shlibs_F77=yes
+  if test "$with_gnu_ld" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    hardcode_libdir_flag_spec_F77='${wl}--rpath ${wl}$libdir'
+    export_dynamic_flag_spec_F77='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | grep 'no-whole-archive' > /dev/null; then
+	whole_archive_flag_spec_F77="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+      else
+  	whole_archive_flag_spec_F77=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>/dev/null` in
+      *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix3* | aix4* | aix5*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+	ld_shlibs_F77=no
+	cat <<EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.9.1, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to modify your PATH
+*** so that a non-GNU linker is found, and then restart.
+
+EOF
+      fi
+      ;;
+
+    amigaos*)
+      archive_cmds_F77='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+      hardcode_libdir_flag_spec_F77='-L$libdir'
+      hardcode_minus_L_F77=yes
+
+      # Samuel A. Falvo II <kc5tja at dolphin.openprojects.net> reports
+      # that the semantics of dynamic libraries on AmigaOS, at least up
+      # to version 4, is to share data among multiple programs linked
+      # with the same dynamic library.  Since this doesn't match the
+      # behavior of shared libraries on other platforms, we can't use
+      # them.
+      ld_shlibs_F77=no
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	allow_undefined_flag_F77=unsupported
+	# Joseph Beckenbach <jrb3 at best.com> says some releases of gcc
+	# support --undefined.  This deserves some investigation.  FIXME
+	archive_cmds_F77='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+	ld_shlibs_F77=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32*)
+      # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, F77) is actually meaningless,
+      # as there is no search path for DLLs.
+      hardcode_libdir_flag_spec_F77='-L$libdir'
+      allow_undefined_flag_F77=unsupported
+      always_export_symbols_F77=no
+      enable_shared_with_static_runtimes_F77=yes
+      export_symbols_cmds_F77='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/'\'' -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols'
+
+      if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
+        archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+	# If the export-symbols file already is a .def file (1st line
+	# is EXPORTS), use it as is; otherwise, prepend...
+	archive_expsym_cmds_F77='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	  cp $export_symbols $output_objdir/$soname.def;
+	else
+	  echo EXPORTS > $output_objdir/$soname.def;
+	  cat $export_symbols >> $output_objdir/$soname.def;
+	fi~
+	$CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+	ld_shlibs_F77=no
+      fi
+      ;;
+
+    interix[3-9]*)
+      hardcode_direct_F77=no
+      hardcode_shlibpath_var_F77=no
+      hardcode_libdir_flag_spec_F77='${wl}-rpath,$libdir'
+      export_dynamic_flag_spec_F77='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      archive_cmds_F77='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      archive_expsym_cmds_F77='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | k*bsd*-gnu)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	tmp_addflag=
+	case $cc_basename,$host_cpu in
+	pgcc*)				# Portland Group C compiler
+	  whole_archive_flag_spec_F77='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag'
+	  ;;
+	pgf77* | pgf90* | pgf95*)	# Portland Group f77 and f90 compilers
+	  whole_archive_flag_spec_F77='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag -Mnomain' ;;
+	ecc*,ia64* | icc*,ia64*)		# Intel C compiler on ia64
+	  tmp_addflag=' -i_dynamic' ;;
+	efc*,ia64* | ifort*,ia64*)	# Intel Fortran compiler on ia64
+	  tmp_addflag=' -i_dynamic -nofor_main' ;;
+	ifc* | ifort*)			# Intel Fortran compiler
+	  tmp_addflag=' -nofor_main' ;;
+	esac
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)			# Sun C 5.9
+	  whole_archive_flag_spec_F77='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_sharedflag='-G' ;;
+	*Sun\ F*)			# Sun Fortran 8.3
+	  tmp_sharedflag='-G' ;;
+	*)
+	  tmp_sharedflag='-shared' ;;
+	esac
+	archive_cmds_F77='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+	if test $supports_anon_versioning = yes; then
+	  archive_expsym_cmds_F77='$echo "{ global:" > $output_objdir/$libname.ver~
+  cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+  $echo "local: *; };" >> $output_objdir/$libname.ver~
+	  $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+	fi
+      else
+	ld_shlibs_F77=no
+      fi
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+	archive_cmds_F77='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+	wlarc=
+      else
+	archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then
+	ld_shlibs_F77=no
+	cat <<EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+EOF
+      elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	ld_shlibs_F77=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*)
+	ld_shlibs_F77=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+	;;
+	*)
+	  if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	    hardcode_libdir_flag_spec_F77='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`'
+	    archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib'
+	    archive_expsym_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname,-retain-symbols-file,$export_symbols -o $lib'
+	  else
+	    ld_shlibs_F77=no
+	  fi
+	;;
+      esac
+      ;;
+
+    sunos4*)
+      archive_cmds_F77='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      hardcode_direct_F77=yes
+      hardcode_shlibpath_var_F77=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	ld_shlibs_F77=no
+      fi
+      ;;
+    esac
+
+    if test "$ld_shlibs_F77" = no; then
+      runpath_var=
+      hardcode_libdir_flag_spec_F77=
+      export_dynamic_flag_spec_F77=
+      whole_archive_flag_spec_F77=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      allow_undefined_flag_F77=unsupported
+      always_export_symbols_F77=yes
+      archive_expsym_cmds_F77='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      hardcode_minus_L_F77=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+	# Neither direct hardcoding nor static linking is supported with a
+	# broken collect2.
+	hardcode_direct_F77=unsupported
+      fi
+      ;;
+
+    aix4* | aix5*)
+      if test "$host_cpu" = ia64; then
+	# On IA64, the linker does run time linking by default, so we don't
+	# have to do anything special.
+	aix_use_runtimelinking=no
+	exp_sym_flag='-Bexport'
+	no_entry_flag=""
+      else
+	# If we're using GNU nm, then we don't want the "-C" option.
+	# -C means demangle to AIX nm, but means don't demangle with GNU nm
+	if $NM -V 2>&1 | grep 'GNU' > /dev/null; then
+	  export_symbols_cmds_F77='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols'
+	else
+	  export_symbols_cmds_F77='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols'
+	fi
+	aix_use_runtimelinking=no
+
+	# Test if we are trying to use run time linking or normal
+	# AIX style linking. If -brtl is somewhere in LDFLAGS, we
+	# need to do runtime linking.
+	case $host_os in aix4.[23]|aix4.[23].*|aix5*)
+	  for ld_flag in $LDFLAGS; do
+  	  if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+  	    aix_use_runtimelinking=yes
+  	    break
+  	  fi
+	  done
+	  ;;
+	esac
+
+	exp_sym_flag='-bexport'
+	no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      archive_cmds_F77=''
+      hardcode_direct_F77=yes
+      hardcode_libdir_separator_F77=':'
+      link_all_deplibs_F77=yes
+
+      if test "$GCC" = yes; then
+	case $host_os in aix4.[012]|aix4.[012].*)
+	# We only want to do this on AIX 4.2 and lower, the check
+	# below for broken collect2 doesn't work under 4.3+
+	  collect2name=`${CC} -print-prog-name=collect2`
+	  if test -f "$collect2name" && \
+  	   strings "$collect2name" | grep resolve_lib_name >/dev/null
+	  then
+  	  # We have reworked collect2
+  	  :
+	  else
+  	  # We have old collect2
+  	  hardcode_direct_F77=unsupported
+  	  # It fails to find uninstalled libraries when the uninstalled
+  	  # path is not listed in the libpath.  Setting hardcode_minus_L
+  	  # to unsupported forces relinking
+  	  hardcode_minus_L_F77=yes
+  	  hardcode_libdir_flag_spec_F77='-L$libdir'
+  	  hardcode_libdir_separator_F77=
+	  fi
+	  ;;
+	esac
+	shared_flag='-shared'
+	if test "$aix_use_runtimelinking" = yes; then
+	  shared_flag="$shared_flag "'${wl}-G'
+	fi
+      else
+	# not using gcc
+	if test "$host_cpu" = ia64; then
+  	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+  	# chokes on -Wl,-G. The following line is correct:
+	  shared_flag='-G'
+	else
+	  if test "$aix_use_runtimelinking" = yes; then
+	    shared_flag='${wl}-G'
+	  else
+	    shared_flag='${wl}-bM:SRE'
+	  fi
+	fi
+      fi
+
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      always_export_symbols_F77=yes
+      if test "$aix_use_runtimelinking" = yes; then
+	# Warning - without using the other runtime loading flags (-brtl),
+	# -berok will link without error, but may produce a broken library.
+	allow_undefined_flag_F77='-berok'
+       # Determine the default libpath from the value encoded in an empty executable.
+       cat >conftest.$ac_ext <<_ACEOF
+      program main
+
+      end
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_f77_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+
+       hardcode_libdir_flag_spec_F77='${wl}-blibpath:$libdir:'"$aix_libpath"
+	archive_expsym_cmds_F77="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+       else
+	if test "$host_cpu" = ia64; then
+	  hardcode_libdir_flag_spec_F77='${wl}-R $libdir:/usr/lib:/lib'
+	  allow_undefined_flag_F77="-z nodefs"
+	  archive_expsym_cmds_F77="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+	else
+	 # Determine the default libpath from the value encoded in an empty executable.
+	 cat >conftest.$ac_ext <<_ACEOF
+      program main
+
+      end
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_f77_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+
+	 hardcode_libdir_flag_spec_F77='${wl}-blibpath:$libdir:'"$aix_libpath"
+	  # Warning - without using the other run time loading flags,
+	  # -berok will link without error, but may produce a broken library.
+	  no_undefined_flag_F77=' ${wl}-bernotok'
+	  allow_undefined_flag_F77=' ${wl}-berok'
+	  # Exported symbols can be pulled into shared objects from archives
+	  whole_archive_flag_spec_F77='$convenience'
+	  archive_cmds_need_lc_F77=yes
+	  # This is similar to how AIX traditionally builds its shared libraries.
+	  archive_expsym_cmds_F77="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+	fi
+      fi
+      ;;
+
+    amigaos*)
+      archive_cmds_F77='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+      hardcode_libdir_flag_spec_F77='-L$libdir'
+      hardcode_minus_L_F77=yes
+      # see comment about different semantics on the GNU ld section
+      ld_shlibs_F77=no
+      ;;
+
+    bsdi[45]*)
+      export_dynamic_flag_spec_F77=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      hardcode_libdir_flag_spec_F77=' '
+      allow_undefined_flag_F77=unsupported
+      # Tell ltmain to make .lib files, not .a files.
+      libext=lib
+      # Tell ltmain to make .dll files, not .so files.
+      shrext_cmds=".dll"
+      # FIXME: Setting linknames here is a bad hack.
+      archive_cmds_F77='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | $SED -e '\''s/ -lc$//'\''` -link -dll~linknames='
+      # The linker will automatically build a .lib file if we build a DLL.
+      old_archive_From_new_cmds_F77='true'
+      # FIXME: Should let the user specify the lib program.
+      old_archive_cmds_F77='lib -OUT:$oldlib$oldobjs$old_deplibs'
+      fix_srcfile_path_F77='`cygpath -w "$srcfile"`'
+      enable_shared_with_static_runtimes_F77=yes
+      ;;
+
+    darwin* | rhapsody*)
+      case $host_os in
+        rhapsody* | darwin1.[012])
+         allow_undefined_flag_F77='${wl}-undefined ${wl}suppress'
+         ;;
+       *) # Darwin 1.3 on
+         if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then
+           allow_undefined_flag_F77='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+         else
+           case ${MACOSX_DEPLOYMENT_TARGET} in
+             10.[012])
+               allow_undefined_flag_F77='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+               ;;
+             10.*)
+               allow_undefined_flag_F77='${wl}-undefined ${wl}dynamic_lookup'
+               ;;
+           esac
+         fi
+         ;;
+      esac
+      archive_cmds_need_lc_F77=no
+      hardcode_direct_F77=no
+      hardcode_automatic_F77=yes
+      hardcode_shlibpath_var_F77=unsupported
+      whole_archive_flag_spec_F77=''
+      link_all_deplibs_F77=yes
+    if test "$GCC" = yes ; then
+    	output_verbose_link_cmd='echo'
+        archive_cmds_F77='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring'
+      module_cmds_F77='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
+      # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
+      archive_expsym_cmds_F77='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+      module_expsym_cmds_F77='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    else
+      case $cc_basename in
+        xlc*)
+         output_verbose_link_cmd='echo'
+         archive_cmds_F77='$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $xlcverstring'
+         module_cmds_F77='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
+          # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
+         archive_expsym_cmds_F77='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $xlcverstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          module_expsym_cmds_F77='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          ;;
+       *)
+         ld_shlibs_F77=no
+          ;;
+      esac
+    fi
+      ;;
+
+    dgux*)
+      archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec_F77='-L$libdir'
+      hardcode_shlibpath_var_F77=no
+      ;;
+
+    freebsd1*)
+      ld_shlibs_F77=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      archive_cmds_F77='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      hardcode_libdir_flag_spec_F77='-R$libdir'
+      hardcode_direct_F77=yes
+      hardcode_shlibpath_var_F77=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2*)
+      archive_cmds_F77='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct_F77=yes
+      hardcode_minus_L_F77=yes
+      hardcode_shlibpath_var_F77=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      archive_cmds_F77='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
+      hardcode_libdir_flag_spec_F77='-R$libdir'
+      hardcode_direct_F77=yes
+      hardcode_shlibpath_var_F77=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+	archive_cmds_F77='$rm $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+	archive_cmds_F77='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      hardcode_libdir_flag_spec_F77='${wl}+b ${wl}$libdir'
+      hardcode_libdir_separator_F77=:
+      hardcode_direct_F77=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      hardcode_minus_L_F77=yes
+      export_dynamic_flag_spec_F77='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	archive_cmds_F77='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds_F77='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+	hardcode_libdir_flag_spec_F77='${wl}+b ${wl}$libdir'
+	hardcode_libdir_separator_F77=:
+
+	hardcode_direct_F77=yes
+	export_dynamic_flag_spec_F77='${wl}-E'
+
+	# hardcode_minus_L: Not really in the search PATH,
+	# but as the default location of the library.
+	hardcode_minus_L_F77=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	case $host_cpu in
+	hppa*64*)
+	  archive_cmds_F77='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  archive_cmds_F77='$CC -shared ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  archive_cmds_F77='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      else
+	case $host_cpu in
+	hppa*64*)
+	  archive_cmds_F77='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  archive_cmds_F77='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  archive_cmds_F77='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      fi
+      if test "$with_gnu_ld" = no; then
+	hardcode_libdir_flag_spec_F77='${wl}+b ${wl}$libdir'
+	hardcode_libdir_separator_F77=:
+
+	case $host_cpu in
+	hppa*64*|ia64*)
+	  hardcode_libdir_flag_spec_ld_F77='+b $libdir'
+	  hardcode_direct_F77=no
+	  hardcode_shlibpath_var_F77=no
+	  ;;
+	*)
+	  hardcode_direct_F77=yes
+	  export_dynamic_flag_spec_F77='${wl}-E'
+
+	  # hardcode_minus_L: Not really in the search PATH,
+	  # but as the default location of the library.
+	  hardcode_minus_L_F77=yes
+	  ;;
+	esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+	archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	archive_cmds_F77='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+	hardcode_libdir_flag_spec_ld_F77='-rpath $libdir'
+      fi
+      hardcode_libdir_flag_spec_F77='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator_F77=:
+      link_all_deplibs_F77=yes
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+	archive_cmds_F77='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+	archive_cmds_F77='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      hardcode_libdir_flag_spec_F77='-R$libdir'
+      hardcode_direct_F77=yes
+      hardcode_shlibpath_var_F77=no
+      ;;
+
+    newsos6)
+      archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct_F77=yes
+      hardcode_libdir_flag_spec_F77='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator_F77=:
+      hardcode_shlibpath_var_F77=no
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+	hardcode_direct_F77=yes
+	hardcode_shlibpath_var_F77=no
+	if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	  archive_cmds_F77='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	  archive_expsym_cmds_F77='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+	  hardcode_libdir_flag_spec_F77='${wl}-rpath,$libdir'
+	  export_dynamic_flag_spec_F77='${wl}-E'
+	else
+	  case $host_os in
+	   openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
+	     archive_cmds_F77='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+	     hardcode_libdir_flag_spec_F77='-R$libdir'
+	     ;;
+	   *)
+	     archive_cmds_F77='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	     hardcode_libdir_flag_spec_F77='${wl}-rpath,$libdir'
+	     ;;
+	  esac
+        fi
+      else
+	ld_shlibs_F77=no
+      fi
+      ;;
+
+    os2*)
+      hardcode_libdir_flag_spec_F77='-L$libdir'
+      hardcode_minus_L_F77=yes
+      allow_undefined_flag_F77=unsupported
+      archive_cmds_F77='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      old_archive_From_new_cmds_F77='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+	allow_undefined_flag_F77=' ${wl}-expect_unresolved ${wl}\*'
+	archive_cmds_F77='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	allow_undefined_flag_F77=' -expect_unresolved \*'
+	archive_cmds_F77='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      hardcode_libdir_flag_spec_F77='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator_F77=:
+      ;;
+
+    osf4* | osf5*)	# as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+	allow_undefined_flag_F77=' ${wl}-expect_unresolved ${wl}\*'
+	archive_cmds_F77='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	hardcode_libdir_flag_spec_F77='${wl}-rpath ${wl}$libdir'
+      else
+	allow_undefined_flag_F77=' -expect_unresolved \*'
+	archive_cmds_F77='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+	archive_expsym_cmds_F77='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~
+	$LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~$rm $lib.exp'
+
+	# Both c and cxx compiler support -rpath directly
+	hardcode_libdir_flag_spec_F77='-rpath $libdir'
+      fi
+      hardcode_libdir_separator_F77=:
+      ;;
+
+    solaris*)
+      no_undefined_flag_F77=' -z text'
+      if test "$GCC" = yes; then
+	wlarc='${wl}'
+	archive_cmds_F77='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_F77='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+	  $CC -shared ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$rm $lib.exp'
+      else
+	wlarc=''
+	archive_cmds_F77='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	archive_expsym_cmds_F77='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+  	$LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp'
+      fi
+      hardcode_libdir_flag_spec_F77='-R$libdir'
+      hardcode_shlibpath_var_F77=no
+      case $host_os in
+      solaris2.[0-5] | solaris2.[0-5].*) ;;
+      *)
+	# The compiler driver will combine and reorder linker options,
+	# but understands `-z linker_flag'.  GCC discards it without `$wl',
+	# but is careful enough not to reorder.
+ 	# Supported since Solaris 2.6 (maybe 2.5.1?)
+	if test "$GCC" = yes; then
+	  whole_archive_flag_spec_F77='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+	else
+	  whole_archive_flag_spec_F77='-z allextract$convenience -z defaultextract'
+	fi
+	;;
+      esac
+      link_all_deplibs_F77=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+	# Use $CC to link under sequent, because it throws in some extra .o
+	# files that make .init and .fini sections work.
+	archive_cmds_F77='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds_F77='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      hardcode_libdir_flag_spec_F77='-L$libdir'
+      hardcode_direct_F77=yes
+      hardcode_minus_L_F77=yes
+      hardcode_shlibpath_var_F77=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+	sni)
+	  archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  hardcode_direct_F77=yes # is this really true???
+	;;
+	siemens)
+	  ## LD is ld it makes a PLAMLIB
+	  ## CC just makes a GrossModule.
+	  archive_cmds_F77='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+	  reload_cmds_F77='$CC -r -o $output$reload_objs'
+	  hardcode_direct_F77=no
+        ;;
+	motorola)
+	  archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  hardcode_direct_F77=no #Motorola manual says yes, but my tests say they lie
+	;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      hardcode_shlibpath_var_F77=no
+      ;;
+
+    sysv4.3*)
+      archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_shlibpath_var_F77=no
+      export_dynamic_flag_spec_F77='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	hardcode_shlibpath_var_F77=no
+	runpath_var=LD_RUN_PATH
+	hardcode_runpath_var=yes
+	ld_shlibs_F77=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*)
+      no_undefined_flag_F77='${wl}-z,text'
+      archive_cmds_need_lc_F77=no
+      hardcode_shlibpath_var_F77=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	archive_cmds_F77='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_F77='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds_F77='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_F77='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      no_undefined_flag_F77='${wl}-z,text'
+      allow_undefined_flag_F77='${wl}-z,nodefs'
+      archive_cmds_need_lc_F77=no
+      hardcode_shlibpath_var_F77=no
+      hardcode_libdir_flag_spec_F77='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`'
+      hardcode_libdir_separator_F77=':'
+      link_all_deplibs_F77=yes
+      export_dynamic_flag_spec_F77='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	archive_cmds_F77='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_F77='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds_F77='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_F77='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      archive_cmds_F77='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec_F77='-L$libdir'
+      hardcode_shlibpath_var_F77=no
+      ;;
+
+    *)
+      ld_shlibs_F77=no
+      ;;
+    esac
+  fi
+
+{ echo "$as_me:$LINENO: result: $ld_shlibs_F77" >&5
+echo "${ECHO_T}$ld_shlibs_F77" >&6; }
+test "$ld_shlibs_F77" = no && can_build_shared=no
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$archive_cmds_need_lc_F77" in
+x|xyes)
+  # Assume -lc should be added
+  archive_cmds_need_lc_F77=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $archive_cmds_F77 in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      { echo "$as_me:$LINENO: checking whether -lc should be explicitly linked in" >&5
+echo $ECHO_N "checking whether -lc should be explicitly linked in... $ECHO_C" >&6; }
+      $rm conftest*
+      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+      if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } 2>conftest.err; then
+        soname=conftest
+        lib=conftest
+        libobjs=conftest.$ac_objext
+        deplibs=
+        wl=$lt_prog_compiler_wl_F77
+	pic_flag=$lt_prog_compiler_pic_F77
+        compiler_flags=-v
+        linker_flags=-v
+        verstring=
+        output_objdir=.
+        libname=conftest
+        lt_save_allow_undefined_flag=$allow_undefined_flag_F77
+        allow_undefined_flag_F77=
+        if { (eval echo "$as_me:$LINENO: \"$archive_cmds_F77 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1\"") >&5
+  (eval $archive_cmds_F77 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+        then
+	  archive_cmds_need_lc_F77=no
+        else
+	  archive_cmds_need_lc_F77=yes
+        fi
+        allow_undefined_flag_F77=$lt_save_allow_undefined_flag
+      else
+        cat conftest.err 1>&5
+      fi
+      $rm conftest*
+      { echo "$as_me:$LINENO: result: $archive_cmds_need_lc_F77" >&5
+echo "${ECHO_T}$archive_cmds_need_lc_F77" >&6; }
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+{ echo "$as_me:$LINENO: checking dynamic linker characteristics" >&5
+echo $ECHO_N "checking dynamic linker characteristics... $ECHO_C" >&6; }
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix4* | aix5*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[01] | aix4.[01].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+	   echo ' yes '
+	   echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then
+	:
+      else
+	can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  library_names_spec='$libname.ixlibrary $libname.a'
+  # Create ${libname}_ixlibrary.a entries in /sys/libs.
+  finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[45]*)
+  version_type=linux
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$host_os in
+  yes,cygwin* | yes,mingw* | yes,pw32*)
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $rm \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
+      ;;
+    mingw*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+      if echo "$sys_lib_search_path_spec" | grep ';[c-zC-Z]:/' >/dev/null; then
+        # It is most probably a Windows format PATH printed by
+        # mingw gcc, but we are running on Cygwin. Gcc prints its search
+        # path with ; separators, and with drive letters. We can handle the
+        # drive letters (cygwin fileutils understands them), so leave them,
+        # especially as we might pass files found there to a mingw objdump,
+        # which wouldn't understand a cygwinified path. Ahh.
+        sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    ;;
+
+  *)
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    ;;
+  esac
+  dynamic_linker='Win32 ld.exe'
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd1*)
+  dynamic_linker=no
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[123]*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[01]* | freebsdelf3.[01]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[2-9]* | freebsdelf3.[2-9]* | \
+  freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+gnu*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+   hppa*64*)
+     shrext_cmds='.sl'
+     hardcode_into_libs=yes
+     dynamic_linker="$host_os dld.sl"
+     shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+     shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+     library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+     soname_spec='${libname}${release}${shared_ext}$major'
+     sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+     sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+     ;;
+   *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555.
+  postinstall_cmds='chmod 555 $lib'
+  ;;
+
+interix[3-9]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+	if test "$lt_cv_prog_gnu_ld" = yes; then
+		version_type=linux
+	else
+		version_type=irix
+	fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ 	]*hwcap[ 	]/d;s/[:,	]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+nto-qnx*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*) need_version=yes ;;
+    *)                         need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[89] | openbsd2.[89].*)
+	shlibpath_overrides_runpath=no
+	;;
+      *)
+	shlibpath_overrides_runpath=yes
+	;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      export_dynamic_flag_spec='${wl}-Blargedynsym'
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+    shlibpath_overrides_runpath=no
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    shlibpath_overrides_runpath=yes
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+	;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+uts4*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+{ echo "$as_me:$LINENO: result: $dynamic_linker" >&5
+echo "${ECHO_T}$dynamic_linker" >&6; }
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+{ echo "$as_me:$LINENO: checking how to hardcode library paths into programs" >&5
+echo $ECHO_N "checking how to hardcode library paths into programs... $ECHO_C" >&6; }
+hardcode_action_F77=
+if test -n "$hardcode_libdir_flag_spec_F77" || \
+   test -n "$runpath_var_F77" || \
+   test "X$hardcode_automatic_F77" = "Xyes" ; then
+
+  # We can hardcode non-existant directories.
+  if test "$hardcode_direct_F77" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, F77)" != no &&
+     test "$hardcode_minus_L_F77" != no; then
+    # Linking always hardcodes the temporary library directory.
+    hardcode_action_F77=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    hardcode_action_F77=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  hardcode_action_F77=unsupported
+fi
+{ echo "$as_me:$LINENO: result: $hardcode_action_F77" >&5
+echo "${ECHO_T}$hardcode_action_F77" >&6; }
+
+if test "$hardcode_action_F77" = relink; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+
+
+# The else clause should only fire when bootstrapping the
+# libtool distribution, otherwise you forgot to ship ltmain.sh
+# with your package, and you will get complaints that there are
+# no rules to generate ltmain.sh.
+if test -f "$ltmain"; then
+  # See if we are running on zsh, and set the options which allow our commands through
+  # without removal of \ escapes.
+  if test -n "${ZSH_VERSION+set}" ; then
+    setopt NO_GLOB_SUBST
+  fi
+  # Now quote all the things that may contain metacharacters while being
+  # careful not to overquote the AC_SUBSTed values.  We take copies of the
+  # variables and quote the copies for generation of the libtool script.
+  for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC LTCFLAGS NM \
+    SED SHELL STRIP \
+    libname_spec library_names_spec soname_spec extract_expsyms_cmds \
+    old_striplib striplib file_magic_cmd finish_cmds finish_eval \
+    deplibs_check_method reload_flag reload_cmds need_locks \
+    lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \
+    lt_cv_sys_global_symbol_to_c_name_address \
+    sys_lib_search_path_spec sys_lib_dlsearch_path_spec \
+    old_postinstall_cmds old_postuninstall_cmds \
+    compiler_F77 \
+    CC_F77 \
+    LD_F77 \
+    lt_prog_compiler_wl_F77 \
+    lt_prog_compiler_pic_F77 \
+    lt_prog_compiler_static_F77 \
+    lt_prog_compiler_no_builtin_flag_F77 \
+    export_dynamic_flag_spec_F77 \
+    thread_safe_flag_spec_F77 \
+    whole_archive_flag_spec_F77 \
+    enable_shared_with_static_runtimes_F77 \
+    old_archive_cmds_F77 \
+    old_archive_from_new_cmds_F77 \
+    predep_objects_F77 \
+    postdep_objects_F77 \
+    predeps_F77 \
+    postdeps_F77 \
+    compiler_lib_search_path_F77 \
+    archive_cmds_F77 \
+    archive_expsym_cmds_F77 \
+    postinstall_cmds_F77 \
+    postuninstall_cmds_F77 \
+    old_archive_from_expsyms_cmds_F77 \
+    allow_undefined_flag_F77 \
+    no_undefined_flag_F77 \
+    export_symbols_cmds_F77 \
+    hardcode_libdir_flag_spec_F77 \
+    hardcode_libdir_flag_spec_ld_F77 \
+    hardcode_libdir_separator_F77 \
+    hardcode_automatic_F77 \
+    module_cmds_F77 \
+    module_expsym_cmds_F77 \
+    lt_cv_prog_compiler_c_o_F77 \
+    fix_srcfile_path_F77 \
+    exclude_expsyms_F77 \
+    include_expsyms_F77; do
+
+    case $var in
+    old_archive_cmds_F77 | \
+    old_archive_from_new_cmds_F77 | \
+    archive_cmds_F77 | \
+    archive_expsym_cmds_F77 | \
+    module_cmds_F77 | \
+    module_expsym_cmds_F77 | \
+    old_archive_from_expsyms_cmds_F77 | \
+    export_symbols_cmds_F77 | \
+    extract_expsyms_cmds | reload_cmds | finish_cmds | \
+    postinstall_cmds | postuninstall_cmds | \
+    old_postinstall_cmds | old_postuninstall_cmds | \
+    sys_lib_search_path_spec | sys_lib_dlsearch_path_spec)
+      # Double-quote double-evaled strings.
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\""
+      ;;
+    *)
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\""
+      ;;
+    esac
+  done
+
+  case $lt_echo in
+  *'\$0 --fallback-echo"')
+    lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\$0 --fallback-echo"$/$0 --fallback-echo"/'`
+    ;;
+  esac
+
+cfgfile="$ofile"
+
+  cat <<__EOF__ >> "$cfgfile"
+# ### BEGIN LIBTOOL TAG CONFIG: $tagname
+
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+
+# Shell to use when invoking shell scripts.
+SHELL=$lt_SHELL
+
+# Whether or not to build shared libraries.
+build_libtool_libs=$enable_shared
+
+# Whether or not to build static libraries.
+build_old_libs=$enable_static
+
+# Whether or not to add -lc for building shared libraries.
+build_libtool_need_lc=$archive_cmds_need_lc_F77
+
+# Whether or not to disallow shared libs when runtime libs are static
+allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes_F77
+
+# Whether or not to optimize for fast installation.
+fast_install=$enable_fast_install
+
+# The host system.
+host_alias=$host_alias
+host=$host
+host_os=$host_os
+
+# The build system.
+build_alias=$build_alias
+build=$build
+build_os=$build_os
+
+# An echo program that does not interpret backslashes.
+echo=$lt_echo
+
+# The archiver.
+AR=$lt_AR
+AR_FLAGS=$lt_AR_FLAGS
+
+# A C compiler.
+LTCC=$lt_LTCC
+
+# LTCC compiler flags.
+LTCFLAGS=$lt_LTCFLAGS
+
+# A language-specific compiler.
+CC=$lt_compiler_F77
+
+# Is the compiler the GNU C compiler?
+with_gcc=$GCC_F77
+
+# An ERE matcher.
+EGREP=$lt_EGREP
+
+# The linker used to build libraries.
+LD=$lt_LD_F77
+
+# Whether we need hard or soft links.
+LN_S=$lt_LN_S
+
+# A BSD-compatible nm program.
+NM=$lt_NM
+
+# A symbol stripping program
+STRIP=$lt_STRIP
+
+# Used to examine libraries when file_magic_cmd begins "file"
+MAGIC_CMD=$MAGIC_CMD
+
+# Used on cygwin: DLL creation program.
+DLLTOOL="$DLLTOOL"
+
+# Used on cygwin: object dumper.
+OBJDUMP="$OBJDUMP"
+
+# Used on cygwin: assembler.
+AS="$AS"
+
+# The name of the directory that contains temporary libtool files.
+objdir=$objdir
+
+# How to create reloadable object files.
+reload_flag=$lt_reload_flag
+reload_cmds=$lt_reload_cmds
+
+# How to pass a linker flag through the compiler.
+wl=$lt_lt_prog_compiler_wl_F77
+
+# Object file suffix (normally "o").
+objext="$ac_objext"
+
+# Old archive suffix (normally "a").
+libext="$libext"
+
+# Shared library suffix (normally ".so").
+shrext_cmds='$shrext_cmds'
+
+# Executable file suffix (normally "").
+exeext="$exeext"
+
+# Additional compiler flags for building library objects.
+pic_flag=$lt_lt_prog_compiler_pic_F77
+pic_mode=$pic_mode
+
+# What is the maximum length of a command?
+max_cmd_len=$lt_cv_sys_max_cmd_len
+
+# Does compiler simultaneously support -c and -o options?
+compiler_c_o=$lt_lt_cv_prog_compiler_c_o_F77
+
+# Must we lock files when doing compilation?
+need_locks=$lt_need_locks
+
+# Do we need the lib prefix for modules?
+need_lib_prefix=$need_lib_prefix
+
+# Do we need a version for libraries?
+need_version=$need_version
+
+# Whether dlopen is supported.
+dlopen_support=$enable_dlopen
+
+# Whether dlopen of programs is supported.
+dlopen_self=$enable_dlopen_self
+
+# Whether dlopen of statically linked programs is supported.
+dlopen_self_static=$enable_dlopen_self_static
+
+# Compiler flag to prevent dynamic linking.
+link_static_flag=$lt_lt_prog_compiler_static_F77
+
+# Compiler flag to turn off builtin functions.
+no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag_F77
+
+# Compiler flag to allow reflexive dlopens.
+export_dynamic_flag_spec=$lt_export_dynamic_flag_spec_F77
+
+# Compiler flag to generate shared objects directly from archives.
+whole_archive_flag_spec=$lt_whole_archive_flag_spec_F77
+
+# Compiler flag to generate thread-safe objects.
+thread_safe_flag_spec=$lt_thread_safe_flag_spec_F77
+
+# Library versioning type.
+version_type=$version_type
+
+# Format of library name prefix.
+libname_spec=$lt_libname_spec
+
+# List of archive names.  First name is the real one, the rest are links.
+# The last name is the one that the linker finds with -lNAME.
+library_names_spec=$lt_library_names_spec
+
+# The coded name of the library, if different from the real name.
+soname_spec=$lt_soname_spec
+
+# Commands used to build and install an old-style archive.
+RANLIB=$lt_RANLIB
+old_archive_cmds=$lt_old_archive_cmds_F77
+old_postinstall_cmds=$lt_old_postinstall_cmds
+old_postuninstall_cmds=$lt_old_postuninstall_cmds
+
+# Create an old-style archive from a shared archive.
+old_archive_from_new_cmds=$lt_old_archive_from_new_cmds_F77
+
+# Create a temporary old-style archive to link instead of a shared archive.
+old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds_F77
+
+# Commands used to build and install a shared archive.
+archive_cmds=$lt_archive_cmds_F77
+archive_expsym_cmds=$lt_archive_expsym_cmds_F77
+postinstall_cmds=$lt_postinstall_cmds
+postuninstall_cmds=$lt_postuninstall_cmds
+
+# Commands used to build a loadable module (assumed same as above if empty)
+module_cmds=$lt_module_cmds_F77
+module_expsym_cmds=$lt_module_expsym_cmds_F77
+
+# Commands to strip libraries.
+old_striplib=$lt_old_striplib
+striplib=$lt_striplib
+
+# Dependencies to place before the objects being linked to create a
+# shared library.
+predep_objects=$lt_predep_objects_F77
+
+# Dependencies to place after the objects being linked to create a
+# shared library.
+postdep_objects=$lt_postdep_objects_F77
+
+# Dependencies to place before the objects being linked to create a
+# shared library.
+predeps=$lt_predeps_F77
+
+# Dependencies to place after the objects being linked to create a
+# shared library.
+postdeps=$lt_postdeps_F77
+
+# The library search path used internally by the compiler when linking
+# a shared library.
+compiler_lib_search_path=$lt_compiler_lib_search_path_F77
+
+# Method to check whether dependent libraries are shared objects.
+deplibs_check_method=$lt_deplibs_check_method
+
+# Command to use when deplibs_check_method == file_magic.
+file_magic_cmd=$lt_file_magic_cmd
+
+# Flag that allows shared libraries with undefined symbols to be built.
+allow_undefined_flag=$lt_allow_undefined_flag_F77
+
+# Flag that forces no undefined symbols.
+no_undefined_flag=$lt_no_undefined_flag_F77
+
+# Commands used to finish a libtool library installation in a directory.
+finish_cmds=$lt_finish_cmds
+
+# Same as above, but a single script fragment to be evaled but not shown.
+finish_eval=$lt_finish_eval
+
+# Take the output of nm and produce a listing of raw symbols and C names.
+global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe
+
+# Transform the output of nm in a proper C declaration
+global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl
+
+# Transform the output of nm in a C name address pair
+global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address
+
+# This is the shared library runtime path variable.
+runpath_var=$runpath_var
+
+# This is the shared library path variable.
+shlibpath_var=$shlibpath_var
+
+# Is shlibpath searched before the hard-coded library search path?
+shlibpath_overrides_runpath=$shlibpath_overrides_runpath
+
+# How to hardcode a shared library path into an executable.
+hardcode_action=$hardcode_action_F77
+
+# Whether we should hardcode library paths into libraries.
+hardcode_into_libs=$hardcode_into_libs
+
+# Flag to hardcode \$libdir into a binary during linking.
+# This must work even if \$libdir does not exist.
+hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec_F77
+
+# If ld is used when linking, flag to hardcode \$libdir into
+# a binary during linking. This must work even if \$libdir does
+# not exist.
+hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld_F77
+
+# Whether we need a single -rpath flag with a separated argument.
+hardcode_libdir_separator=$lt_hardcode_libdir_separator_F77
+
+# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the
+# resulting binary.
+hardcode_direct=$hardcode_direct_F77
+
+# Set to yes if using the -LDIR flag during linking hardcodes DIR into the
+# resulting binary.
+hardcode_minus_L=$hardcode_minus_L_F77
+
+# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into
+# the resulting binary.
+hardcode_shlibpath_var=$hardcode_shlibpath_var_F77
+
+# Set to yes if building a shared library automatically hardcodes DIR into the library
+# and all subsequent libraries and executables linked against it.
+hardcode_automatic=$hardcode_automatic_F77
+
+# Variables whose values should be saved in libtool wrapper scripts and
+# restored at relink time.
+variables_saved_for_relink="$variables_saved_for_relink"
+
+# Whether libtool must link a program against all its dependency libraries.
+link_all_deplibs=$link_all_deplibs_F77
+
+# Compile-time system search path for libraries
+sys_lib_search_path_spec=$lt_sys_lib_search_path_spec
+
+# Run-time system search path for libraries
+sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec
+
+# Fix the shell variable \$srcfile for the compiler.
+fix_srcfile_path=$lt_fix_srcfile_path
+
+# Set to yes if exported symbols are required.
+always_export_symbols=$always_export_symbols_F77
+
+# The commands to list exported symbols.
+export_symbols_cmds=$lt_export_symbols_cmds_F77
+
+# The commands to extract the exported symbol list from a shared archive.
+extract_expsyms_cmds=$lt_extract_expsyms_cmds
+
+# Symbols that should not be listed in the preloaded symbols.
+exclude_expsyms=$lt_exclude_expsyms_F77
+
+# Symbols that must always be exported.
+include_expsyms=$lt_include_expsyms_F77
+
+# ### END LIBTOOL TAG CONFIG: $tagname
+
+__EOF__
+
+
+else
+  # If there is no Makefile yet, we rely on a make rule to execute
+  # `config.status --recheck' to rerun these tests and create the
+  # libtool script then.
+  ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'`
+  if test -f "$ltmain_in"; then
+    test -f Makefile && make "$ltmain"
+  fi
+fi
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+CC="$lt_save_CC"
+
+	else
+	  tagname=""
+	fi
+	;;
+
+      GCJ)
+	if test -n "$GCJ" && test "X$GCJ" != "Xno"; then
+
+
+# Source file extension for Java test sources.
+ac_ext=java
+
+# Object file extension for compiled Java test sources.
+objext=o
+objext_GCJ=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="class foo {}"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='public class conftest { public static void main(String[] argv) {}; }'
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+
+# save warnings/boilerplate of simple test code
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$rm conftest*
+
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$rm conftest*
+
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+CC=${GCJ-"gcj"}
+compiler=$CC
+compiler_GCJ=$CC
+for cc_temp in $compiler""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+
+
+# GCJ did not exist at the time GCC didn't implicitly link libc in.
+archive_cmds_need_lc_GCJ=no
+
+old_archive_cmds_GCJ=$old_archive_cmds
+
+
+lt_prog_compiler_no_builtin_flag_GCJ=
+
+if test "$GCC" = yes; then
+  lt_prog_compiler_no_builtin_flag_GCJ=' -fno-builtin'
+
+
+{ echo "$as_me:$LINENO: checking if $compiler supports -fno-rtti -fno-exceptions" >&5
+echo $ECHO_N "checking if $compiler supports -fno-rtti -fno-exceptions... $ECHO_C" >&6; }
+if test "${lt_cv_prog_compiler_rtti_exceptions+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_cv_prog_compiler_rtti_exceptions=no
+  ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="-fno-rtti -fno-exceptions"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:16662: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:16666: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_rtti_exceptions=yes
+     fi
+   fi
+   $rm conftest*
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_rtti_exceptions" >&5
+echo "${ECHO_T}$lt_cv_prog_compiler_rtti_exceptions" >&6; }
+
+if test x"$lt_cv_prog_compiler_rtti_exceptions" = xyes; then
+    lt_prog_compiler_no_builtin_flag_GCJ="$lt_prog_compiler_no_builtin_flag_GCJ -fno-rtti -fno-exceptions"
+else
+    :
+fi
+
+fi
+
+lt_prog_compiler_wl_GCJ=
+lt_prog_compiler_pic_GCJ=
+lt_prog_compiler_static_GCJ=
+
+{ echo "$as_me:$LINENO: checking for $compiler option to produce PIC" >&5
+echo $ECHO_N "checking for $compiler option to produce PIC... $ECHO_C" >&6; }
+
+  if test "$GCC" = yes; then
+    lt_prog_compiler_wl_GCJ='-Wl,'
+    lt_prog_compiler_static_GCJ='-static'
+
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	lt_prog_compiler_static_GCJ='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      # FIXME: we need at least 68020 code to build shared libraries, but
+      # adding the `-m68020' flag to GCC prevents building anything better,
+      # like `-m68040'.
+      lt_prog_compiler_pic_GCJ='-m68020 -resident32 -malways-restore-a4'
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      lt_prog_compiler_pic_GCJ='-DDLL_EXPORT'
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      lt_prog_compiler_pic_GCJ='-fno-common'
+      ;;
+
+    interix[3-9]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      lt_prog_compiler_can_build_shared_GCJ=no
+      enable_shared=no
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	lt_prog_compiler_pic_GCJ=-Kconform_pic
+      fi
+      ;;
+
+    hpux*)
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	lt_prog_compiler_pic_GCJ='-fPIC'
+	;;
+      esac
+      ;;
+
+    *)
+      lt_prog_compiler_pic_GCJ='-fPIC'
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      lt_prog_compiler_wl_GCJ='-Wl,'
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	lt_prog_compiler_static_GCJ='-Bstatic'
+      else
+	lt_prog_compiler_static_GCJ='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+      darwin*)
+        # PIC is the default on this platform
+        # Common symbols not allowed in MH_DYLIB files
+       case $cc_basename in
+         xlc*)
+         lt_prog_compiler_pic_GCJ='-qnocommon'
+         lt_prog_compiler_wl_GCJ='-Wl,'
+         ;;
+       esac
+       ;;
+
+    mingw* | cygwin* | pw32* | os2*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      lt_prog_compiler_pic_GCJ='-DDLL_EXPORT'
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      lt_prog_compiler_wl_GCJ='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	lt_prog_compiler_pic_GCJ='+Z'
+	;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      lt_prog_compiler_static_GCJ='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      lt_prog_compiler_wl_GCJ='-Wl,'
+      # PIC (with -KPIC) is the default.
+      lt_prog_compiler_static_GCJ='-non_shared'
+      ;;
+
+    newsos6)
+      lt_prog_compiler_pic_GCJ='-KPIC'
+      lt_prog_compiler_static_GCJ='-Bstatic'
+      ;;
+
+    linux* | k*bsd*-gnu)
+      case $cc_basename in
+      icc* | ecc*)
+	lt_prog_compiler_wl_GCJ='-Wl,'
+	lt_prog_compiler_pic_GCJ='-KPIC'
+	lt_prog_compiler_static_GCJ='-static'
+        ;;
+      pgcc* | pgf77* | pgf90* | pgf95*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+	# which looks to be a dead project)
+	lt_prog_compiler_wl_GCJ='-Wl,'
+	lt_prog_compiler_pic_GCJ='-fpic'
+	lt_prog_compiler_static_GCJ='-Bstatic'
+        ;;
+      ccc*)
+        lt_prog_compiler_wl_GCJ='-Wl,'
+        # All Alpha code is PIC.
+        lt_prog_compiler_static_GCJ='-non_shared'
+        ;;
+      *)
+        case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)
+	  # Sun C 5.9
+	  lt_prog_compiler_pic_GCJ='-KPIC'
+	  lt_prog_compiler_static_GCJ='-Bstatic'
+	  lt_prog_compiler_wl_GCJ='-Wl,'
+	  ;;
+	*Sun\ F*)
+	  # Sun Fortran 8.3 passes all unrecognized flags to the linker
+	  lt_prog_compiler_pic_GCJ='-KPIC'
+	  lt_prog_compiler_static_GCJ='-Bstatic'
+	  lt_prog_compiler_wl_GCJ=''
+	  ;;
+	esac
+	;;
+      esac
+      ;;
+
+    osf3* | osf4* | osf5*)
+      lt_prog_compiler_wl_GCJ='-Wl,'
+      # All OSF/1 code is PIC.
+      lt_prog_compiler_static_GCJ='-non_shared'
+      ;;
+
+    rdos*)
+      lt_prog_compiler_static_GCJ='-non_shared'
+      ;;
+
+    solaris*)
+      lt_prog_compiler_pic_GCJ='-KPIC'
+      lt_prog_compiler_static_GCJ='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95*)
+	lt_prog_compiler_wl_GCJ='-Qoption ld ';;
+      *)
+	lt_prog_compiler_wl_GCJ='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      lt_prog_compiler_wl_GCJ='-Qoption ld '
+      lt_prog_compiler_pic_GCJ='-PIC'
+      lt_prog_compiler_static_GCJ='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      lt_prog_compiler_wl_GCJ='-Wl,'
+      lt_prog_compiler_pic_GCJ='-KPIC'
+      lt_prog_compiler_static_GCJ='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+	lt_prog_compiler_pic_GCJ='-Kconform_pic'
+	lt_prog_compiler_static_GCJ='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      lt_prog_compiler_wl_GCJ='-Wl,'
+      lt_prog_compiler_pic_GCJ='-KPIC'
+      lt_prog_compiler_static_GCJ='-Bstatic'
+      ;;
+
+    unicos*)
+      lt_prog_compiler_wl_GCJ='-Wl,'
+      lt_prog_compiler_can_build_shared_GCJ=no
+      ;;
+
+    uts4*)
+      lt_prog_compiler_pic_GCJ='-pic'
+      lt_prog_compiler_static_GCJ='-Bstatic'
+      ;;
+
+    *)
+      lt_prog_compiler_can_build_shared_GCJ=no
+      ;;
+    esac
+  fi
+
+{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_GCJ" >&5
+echo "${ECHO_T}$lt_prog_compiler_pic_GCJ" >&6; }
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$lt_prog_compiler_pic_GCJ"; then
+
+{ echo "$as_me:$LINENO: checking if $compiler PIC flag $lt_prog_compiler_pic_GCJ works" >&5
+echo $ECHO_N "checking if $compiler PIC flag $lt_prog_compiler_pic_GCJ works... $ECHO_C" >&6; }
+if test "${lt_prog_compiler_pic_works_GCJ+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_prog_compiler_pic_works_GCJ=no
+  ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$lt_prog_compiler_pic_GCJ"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:16952: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:16956: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_prog_compiler_pic_works_GCJ=yes
+     fi
+   fi
+   $rm conftest*
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_prog_compiler_pic_works_GCJ" >&5
+echo "${ECHO_T}$lt_prog_compiler_pic_works_GCJ" >&6; }
+
+if test x"$lt_prog_compiler_pic_works_GCJ" = xyes; then
+    case $lt_prog_compiler_pic_GCJ in
+     "" | " "*) ;;
+     *) lt_prog_compiler_pic_GCJ=" $lt_prog_compiler_pic_GCJ" ;;
+     esac
+else
+    lt_prog_compiler_pic_GCJ=
+     lt_prog_compiler_can_build_shared_GCJ=no
+fi
+
+fi
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    lt_prog_compiler_pic_GCJ=
+    ;;
+  *)
+    lt_prog_compiler_pic_GCJ="$lt_prog_compiler_pic_GCJ"
+    ;;
+esac
+
+#
+# Check to make sure the static flag actually works.
+#
+wl=$lt_prog_compiler_wl_GCJ eval lt_tmp_static_flag=\"$lt_prog_compiler_static_GCJ\"
+{ echo "$as_me:$LINENO: checking if $compiler static flag $lt_tmp_static_flag works" >&5
+echo $ECHO_N "checking if $compiler static flag $lt_tmp_static_flag works... $ECHO_C" >&6; }
+if test "${lt_prog_compiler_static_works_GCJ+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_prog_compiler_static_works_GCJ=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $lt_tmp_static_flag"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&5
+       $echo "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         lt_prog_compiler_static_works_GCJ=yes
+       fi
+     else
+       lt_prog_compiler_static_works_GCJ=yes
+     fi
+   fi
+   $rm conftest*
+   LDFLAGS="$save_LDFLAGS"
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_prog_compiler_static_works_GCJ" >&5
+echo "${ECHO_T}$lt_prog_compiler_static_works_GCJ" >&6; }
+
+if test x"$lt_prog_compiler_static_works_GCJ" = xyes; then
+    :
+else
+    lt_prog_compiler_static_GCJ=
+fi
+
+
+{ echo "$as_me:$LINENO: checking if $compiler supports -c -o file.$ac_objext" >&5
+echo $ECHO_N "checking if $compiler supports -c -o file.$ac_objext... $ECHO_C" >&6; }
+if test "${lt_cv_prog_compiler_c_o_GCJ+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  lt_cv_prog_compiler_c_o_GCJ=no
+   $rm -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:17056: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&5
+   echo "$as_me:17060: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_c_o_GCJ=yes
+     fi
+   fi
+   chmod u+w . 2>&5
+   $rm conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files
+   $rm out/* && rmdir out
+   cd ..
+   rmdir conftest
+   $rm conftest*
+
+fi
+{ echo "$as_me:$LINENO: result: $lt_cv_prog_compiler_c_o_GCJ" >&5
+echo "${ECHO_T}$lt_cv_prog_compiler_c_o_GCJ" >&6; }
+
+
+hard_links="nottested"
+if test "$lt_cv_prog_compiler_c_o_GCJ" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  { echo "$as_me:$LINENO: checking if we can lock with hard links" >&5
+echo $ECHO_N "checking if we can lock with hard links... $ECHO_C" >&6; }
+  hard_links=yes
+  $rm conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  { echo "$as_me:$LINENO: result: $hard_links" >&5
+echo "${ECHO_T}$hard_links" >&6; }
+  if test "$hard_links" = no; then
+    { echo "$as_me:$LINENO: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5
+echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;}
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+
+{ echo "$as_me:$LINENO: checking whether the $compiler linker ($LD) supports shared libraries" >&5
+echo $ECHO_N "checking whether the $compiler linker ($LD) supports shared libraries... $ECHO_C" >&6; }
+
+  runpath_var=
+  allow_undefined_flag_GCJ=
+  enable_shared_with_static_runtimes_GCJ=no
+  archive_cmds_GCJ=
+  archive_expsym_cmds_GCJ=
+  old_archive_From_new_cmds_GCJ=
+  old_archive_from_expsyms_cmds_GCJ=
+  export_dynamic_flag_spec_GCJ=
+  whole_archive_flag_spec_GCJ=
+  thread_safe_flag_spec_GCJ=
+  hardcode_libdir_flag_spec_GCJ=
+  hardcode_libdir_flag_spec_ld_GCJ=
+  hardcode_libdir_separator_GCJ=
+  hardcode_direct_GCJ=no
+  hardcode_minus_L_GCJ=no
+  hardcode_shlibpath_var_GCJ=unsupported
+  link_all_deplibs_GCJ=unknown
+  hardcode_automatic_GCJ=no
+  module_cmds_GCJ=
+  module_expsym_cmds_GCJ=
+  always_export_symbols_GCJ=no
+  export_symbols_cmds_GCJ='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  include_expsyms_GCJ=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  exclude_expsyms_GCJ="_GLOBAL_OFFSET_TABLE_"
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  extract_expsyms_cmds=
+  # Just being paranoid about ensuring that cc_basename is set.
+  for cc_temp in $compiler""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+
+  case $host_os in
+  cygwin* | mingw* | pw32*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  esac
+
+  ld_shlibs_GCJ=yes
+  if test "$with_gnu_ld" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    hardcode_libdir_flag_spec_GCJ='${wl}--rpath ${wl}$libdir'
+    export_dynamic_flag_spec_GCJ='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | grep 'no-whole-archive' > /dev/null; then
+	whole_archive_flag_spec_GCJ="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+      else
+  	whole_archive_flag_spec_GCJ=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>/dev/null` in
+      *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix3* | aix4* | aix5*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+	ld_shlibs_GCJ=no
+	cat <<EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.9.1, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to modify your PATH
+*** so that a non-GNU linker is found, and then restart.
+
+EOF
+      fi
+      ;;
+
+    amigaos*)
+      archive_cmds_GCJ='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+      hardcode_libdir_flag_spec_GCJ='-L$libdir'
+      hardcode_minus_L_GCJ=yes
+
+      # Samuel A. Falvo II <kc5tja at dolphin.openprojects.net> reports
+      # that the semantics of dynamic libraries on AmigaOS, at least up
+      # to version 4, is to share data among multiple programs linked
+      # with the same dynamic library.  Since this doesn't match the
+      # behavior of shared libraries on other platforms, we can't use
+      # them.
+      ld_shlibs_GCJ=no
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	allow_undefined_flag_GCJ=unsupported
+	# Joseph Beckenbach <jrb3 at best.com> says some releases of gcc
+	# support --undefined.  This deserves some investigation.  FIXME
+	archive_cmds_GCJ='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+	ld_shlibs_GCJ=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32*)
+      # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, GCJ) is actually meaningless,
+      # as there is no search path for DLLs.
+      hardcode_libdir_flag_spec_GCJ='-L$libdir'
+      allow_undefined_flag_GCJ=unsupported
+      always_export_symbols_GCJ=no
+      enable_shared_with_static_runtimes_GCJ=yes
+      export_symbols_cmds_GCJ='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/'\'' -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols'
+
+      if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
+        archive_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+	# If the export-symbols file already is a .def file (1st line
+	# is EXPORTS), use it as is; otherwise, prepend...
+	archive_expsym_cmds_GCJ='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	  cp $export_symbols $output_objdir/$soname.def;
+	else
+	  echo EXPORTS > $output_objdir/$soname.def;
+	  cat $export_symbols >> $output_objdir/$soname.def;
+	fi~
+	$CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+	ld_shlibs_GCJ=no
+      fi
+      ;;
+
+    interix[3-9]*)
+      hardcode_direct_GCJ=no
+      hardcode_shlibpath_var_GCJ=no
+      hardcode_libdir_flag_spec_GCJ='${wl}-rpath,$libdir'
+      export_dynamic_flag_spec_GCJ='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      archive_cmds_GCJ='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      archive_expsym_cmds_GCJ='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | k*bsd*-gnu)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	tmp_addflag=
+	case $cc_basename,$host_cpu in
+	pgcc*)				# Portland Group C compiler
+	  whole_archive_flag_spec_GCJ='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag'
+	  ;;
+	pgf77* | pgf90* | pgf95*)	# Portland Group f77 and f90 compilers
+	  whole_archive_flag_spec_GCJ='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag -Mnomain' ;;
+	ecc*,ia64* | icc*,ia64*)		# Intel C compiler on ia64
+	  tmp_addflag=' -i_dynamic' ;;
+	efc*,ia64* | ifort*,ia64*)	# Intel Fortran compiler on ia64
+	  tmp_addflag=' -i_dynamic -nofor_main' ;;
+	ifc* | ifort*)			# Intel Fortran compiler
+	  tmp_addflag=' -nofor_main' ;;
+	esac
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)			# Sun C 5.9
+	  whole_archive_flag_spec_GCJ='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_sharedflag='-G' ;;
+	*Sun\ F*)			# Sun Fortran 8.3
+	  tmp_sharedflag='-G' ;;
+	*)
+	  tmp_sharedflag='-shared' ;;
+	esac
+	archive_cmds_GCJ='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+	if test $supports_anon_versioning = yes; then
+	  archive_expsym_cmds_GCJ='$echo "{ global:" > $output_objdir/$libname.ver~
+  cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+  $echo "local: *; };" >> $output_objdir/$libname.ver~
+	  $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+	fi
+      else
+	ld_shlibs_GCJ=no
+      fi
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+	archive_cmds_GCJ='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+	wlarc=
+      else
+	archive_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then
+	ld_shlibs_GCJ=no
+	cat <<EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+EOF
+      elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	archive_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	ld_shlibs_GCJ=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*)
+	ld_shlibs_GCJ=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+	;;
+	*)
+	  if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	    hardcode_libdir_flag_spec_GCJ='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`'
+	    archive_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib'
+	    archive_expsym_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname,-retain-symbols-file,$export_symbols -o $lib'
+	  else
+	    ld_shlibs_GCJ=no
+	  fi
+	;;
+      esac
+      ;;
+
+    sunos4*)
+      archive_cmds_GCJ='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      hardcode_direct_GCJ=yes
+      hardcode_shlibpath_var_GCJ=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
+	archive_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	ld_shlibs_GCJ=no
+      fi
+      ;;
+    esac
+
+    if test "$ld_shlibs_GCJ" = no; then
+      runpath_var=
+      hardcode_libdir_flag_spec_GCJ=
+      export_dynamic_flag_spec_GCJ=
+      whole_archive_flag_spec_GCJ=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      allow_undefined_flag_GCJ=unsupported
+      always_export_symbols_GCJ=yes
+      archive_expsym_cmds_GCJ='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      hardcode_minus_L_GCJ=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+	# Neither direct hardcoding nor static linking is supported with a
+	# broken collect2.
+	hardcode_direct_GCJ=unsupported
+      fi
+      ;;
+
+    aix4* | aix5*)
+      if test "$host_cpu" = ia64; then
+	# On IA64, the linker does run time linking by default, so we don't
+	# have to do anything special.
+	aix_use_runtimelinking=no
+	exp_sym_flag='-Bexport'
+	no_entry_flag=""
+      else
+	# If we're using GNU nm, then we don't want the "-C" option.
+	# -C means demangle to AIX nm, but means don't demangle with GNU nm
+	if $NM -V 2>&1 | grep 'GNU' > /dev/null; then
+	  export_symbols_cmds_GCJ='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols'
+	else
+	  export_symbols_cmds_GCJ='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols'
+	fi
+	aix_use_runtimelinking=no
+
+	# Test if we are trying to use run time linking or normal
+	# AIX style linking. If -brtl is somewhere in LDFLAGS, we
+	# need to do runtime linking.
+	case $host_os in aix4.[23]|aix4.[23].*|aix5*)
+	  for ld_flag in $LDFLAGS; do
+  	  if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+  	    aix_use_runtimelinking=yes
+  	    break
+  	  fi
+	  done
+	  ;;
+	esac
+
+	exp_sym_flag='-bexport'
+	no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      archive_cmds_GCJ=''
+      hardcode_direct_GCJ=yes
+      hardcode_libdir_separator_GCJ=':'
+      link_all_deplibs_GCJ=yes
+
+      if test "$GCC" = yes; then
+	case $host_os in aix4.[012]|aix4.[012].*)
+	# We only want to do this on AIX 4.2 and lower, the check
+	# below for broken collect2 doesn't work under 4.3+
+	  collect2name=`${CC} -print-prog-name=collect2`
+	  if test -f "$collect2name" && \
+  	   strings "$collect2name" | grep resolve_lib_name >/dev/null
+	  then
+  	  # We have reworked collect2
+  	  :
+	  else
+  	  # We have old collect2
+  	  hardcode_direct_GCJ=unsupported
+  	  # It fails to find uninstalled libraries when the uninstalled
+  	  # path is not listed in the libpath.  Setting hardcode_minus_L
+  	  # to unsupported forces relinking
+  	  hardcode_minus_L_GCJ=yes
+  	  hardcode_libdir_flag_spec_GCJ='-L$libdir'
+  	  hardcode_libdir_separator_GCJ=
+	  fi
+	  ;;
+	esac
+	shared_flag='-shared'
+	if test "$aix_use_runtimelinking" = yes; then
+	  shared_flag="$shared_flag "'${wl}-G'
+	fi
+      else
+	# not using gcc
+	if test "$host_cpu" = ia64; then
+  	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+  	# chokes on -Wl,-G. The following line is correct:
+	  shared_flag='-G'
+	else
+	  if test "$aix_use_runtimelinking" = yes; then
+	    shared_flag='${wl}-G'
+	  else
+	    shared_flag='${wl}-bM:SRE'
+	  fi
+	fi
+      fi
+
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      always_export_symbols_GCJ=yes
+      if test "$aix_use_runtimelinking" = yes; then
+	# Warning - without using the other runtime loading flags (-brtl),
+	# -berok will link without error, but may produce a broken library.
+	allow_undefined_flag_GCJ='-berok'
+       # Determine the default libpath from the value encoded in an empty executable.
+       cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+
+       hardcode_libdir_flag_spec_GCJ='${wl}-blibpath:$libdir:'"$aix_libpath"
+	archive_expsym_cmds_GCJ="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+       else
+	if test "$host_cpu" = ia64; then
+	  hardcode_libdir_flag_spec_GCJ='${wl}-R $libdir:/usr/lib:/lib'
+	  allow_undefined_flag_GCJ="-z nodefs"
+	  archive_expsym_cmds_GCJ="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+	else
+	 # Determine the default libpath from the value encoded in an empty executable.
+	 cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+
+	 hardcode_libdir_flag_spec_GCJ='${wl}-blibpath:$libdir:'"$aix_libpath"
+	  # Warning - without using the other run time loading flags,
+	  # -berok will link without error, but may produce a broken library.
+	  no_undefined_flag_GCJ=' ${wl}-bernotok'
+	  allow_undefined_flag_GCJ=' ${wl}-berok'
+	  # Exported symbols can be pulled into shared objects from archives
+	  whole_archive_flag_spec_GCJ='$convenience'
+	  archive_cmds_need_lc_GCJ=yes
+	  # This is similar to how AIX traditionally builds its shared libraries.
+	  archive_expsym_cmds_GCJ="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+	fi
+      fi
+      ;;
+
+    amigaos*)
+      archive_cmds_GCJ='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+      hardcode_libdir_flag_spec_GCJ='-L$libdir'
+      hardcode_minus_L_GCJ=yes
+      # see comment about different semantics on the GNU ld section
+      ld_shlibs_GCJ=no
+      ;;
+
+    bsdi[45]*)
+      export_dynamic_flag_spec_GCJ=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      hardcode_libdir_flag_spec_GCJ=' '
+      allow_undefined_flag_GCJ=unsupported
+      # Tell ltmain to make .lib files, not .a files.
+      libext=lib
+      # Tell ltmain to make .dll files, not .so files.
+      shrext_cmds=".dll"
+      # FIXME: Setting linknames here is a bad hack.
+      archive_cmds_GCJ='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | $SED -e '\''s/ -lc$//'\''` -link -dll~linknames='
+      # The linker will automatically build a .lib file if we build a DLL.
+      old_archive_From_new_cmds_GCJ='true'
+      # FIXME: Should let the user specify the lib program.
+      old_archive_cmds_GCJ='lib -OUT:$oldlib$oldobjs$old_deplibs'
+      fix_srcfile_path_GCJ='`cygpath -w "$srcfile"`'
+      enable_shared_with_static_runtimes_GCJ=yes
+      ;;
+
+    darwin* | rhapsody*)
+      case $host_os in
+        rhapsody* | darwin1.[012])
+         allow_undefined_flag_GCJ='${wl}-undefined ${wl}suppress'
+         ;;
+       *) # Darwin 1.3 on
+         if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then
+           allow_undefined_flag_GCJ='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+         else
+           case ${MACOSX_DEPLOYMENT_TARGET} in
+             10.[012])
+               allow_undefined_flag_GCJ='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
+               ;;
+             10.*)
+               allow_undefined_flag_GCJ='${wl}-undefined ${wl}dynamic_lookup'
+               ;;
+           esac
+         fi
+         ;;
+      esac
+      archive_cmds_need_lc_GCJ=no
+      hardcode_direct_GCJ=no
+      hardcode_automatic_GCJ=yes
+      hardcode_shlibpath_var_GCJ=unsupported
+      whole_archive_flag_spec_GCJ=''
+      link_all_deplibs_GCJ=yes
+    if test "$GCC" = yes ; then
+    	output_verbose_link_cmd='echo'
+        archive_cmds_GCJ='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring'
+      module_cmds_GCJ='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
+      # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
+      archive_expsym_cmds_GCJ='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+      module_expsym_cmds_GCJ='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    else
+      case $cc_basename in
+        xlc*)
+         output_verbose_link_cmd='echo'
+         archive_cmds_GCJ='$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $xlcverstring'
+         module_cmds_GCJ='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
+          # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
+         archive_expsym_cmds_GCJ='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $xlcverstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          module_expsym_cmds_GCJ='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
+          ;;
+       *)
+         ld_shlibs_GCJ=no
+          ;;
+      esac
+    fi
+      ;;
+
+    dgux*)
+      archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec_GCJ='-L$libdir'
+      hardcode_shlibpath_var_GCJ=no
+      ;;
+
+    freebsd1*)
+      ld_shlibs_GCJ=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      archive_cmds_GCJ='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      hardcode_libdir_flag_spec_GCJ='-R$libdir'
+      hardcode_direct_GCJ=yes
+      hardcode_shlibpath_var_GCJ=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2*)
+      archive_cmds_GCJ='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct_GCJ=yes
+      hardcode_minus_L_GCJ=yes
+      hardcode_shlibpath_var_GCJ=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      archive_cmds_GCJ='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
+      hardcode_libdir_flag_spec_GCJ='-R$libdir'
+      hardcode_direct_GCJ=yes
+      hardcode_shlibpath_var_GCJ=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+	archive_cmds_GCJ='$rm $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+	archive_cmds_GCJ='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      hardcode_libdir_flag_spec_GCJ='${wl}+b ${wl}$libdir'
+      hardcode_libdir_separator_GCJ=:
+      hardcode_direct_GCJ=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      hardcode_minus_L_GCJ=yes
+      export_dynamic_flag_spec_GCJ='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	archive_cmds_GCJ='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds_GCJ='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+	hardcode_libdir_flag_spec_GCJ='${wl}+b ${wl}$libdir'
+	hardcode_libdir_separator_GCJ=:
+
+	hardcode_direct_GCJ=yes
+	export_dynamic_flag_spec_GCJ='${wl}-E'
+
+	# hardcode_minus_L: Not really in the search PATH,
+	# but as the default location of the library.
+	hardcode_minus_L_GCJ=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	case $host_cpu in
+	hppa*64*)
+	  archive_cmds_GCJ='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  archive_cmds_GCJ='$CC -shared ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  archive_cmds_GCJ='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      else
+	case $host_cpu in
+	hppa*64*)
+	  archive_cmds_GCJ='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  archive_cmds_GCJ='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  archive_cmds_GCJ='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      fi
+      if test "$with_gnu_ld" = no; then
+	hardcode_libdir_flag_spec_GCJ='${wl}+b ${wl}$libdir'
+	hardcode_libdir_separator_GCJ=:
+
+	case $host_cpu in
+	hppa*64*|ia64*)
+	  hardcode_libdir_flag_spec_ld_GCJ='+b $libdir'
+	  hardcode_direct_GCJ=no
+	  hardcode_shlibpath_var_GCJ=no
+	  ;;
+	*)
+	  hardcode_direct_GCJ=yes
+	  export_dynamic_flag_spec_GCJ='${wl}-E'
+
+	  # hardcode_minus_L: Not really in the search PATH,
+	  # but as the default location of the library.
+	  hardcode_minus_L_GCJ=yes
+	  ;;
+	esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+	archive_cmds_GCJ='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	archive_cmds_GCJ='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+	hardcode_libdir_flag_spec_ld_GCJ='-rpath $libdir'
+      fi
+      hardcode_libdir_flag_spec_GCJ='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator_GCJ=:
+      link_all_deplibs_GCJ=yes
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+	archive_cmds_GCJ='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+	archive_cmds_GCJ='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      hardcode_libdir_flag_spec_GCJ='-R$libdir'
+      hardcode_direct_GCJ=yes
+      hardcode_shlibpath_var_GCJ=no
+      ;;
+
+    newsos6)
+      archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct_GCJ=yes
+      hardcode_libdir_flag_spec_GCJ='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator_GCJ=:
+      hardcode_shlibpath_var_GCJ=no
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+	hardcode_direct_GCJ=yes
+	hardcode_shlibpath_var_GCJ=no
+	if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	  archive_cmds_GCJ='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	  archive_expsym_cmds_GCJ='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+	  hardcode_libdir_flag_spec_GCJ='${wl}-rpath,$libdir'
+	  export_dynamic_flag_spec_GCJ='${wl}-E'
+	else
+	  case $host_os in
+	   openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
+	     archive_cmds_GCJ='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+	     hardcode_libdir_flag_spec_GCJ='-R$libdir'
+	     ;;
+	   *)
+	     archive_cmds_GCJ='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	     hardcode_libdir_flag_spec_GCJ='${wl}-rpath,$libdir'
+	     ;;
+	  esac
+        fi
+      else
+	ld_shlibs_GCJ=no
+      fi
+      ;;
+
+    os2*)
+      hardcode_libdir_flag_spec_GCJ='-L$libdir'
+      hardcode_minus_L_GCJ=yes
+      allow_undefined_flag_GCJ=unsupported
+      archive_cmds_GCJ='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      old_archive_From_new_cmds_GCJ='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+	allow_undefined_flag_GCJ=' ${wl}-expect_unresolved ${wl}\*'
+	archive_cmds_GCJ='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	allow_undefined_flag_GCJ=' -expect_unresolved \*'
+	archive_cmds_GCJ='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      hardcode_libdir_flag_spec_GCJ='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator_GCJ=:
+      ;;
+
+    osf4* | osf5*)	# as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+	allow_undefined_flag_GCJ=' ${wl}-expect_unresolved ${wl}\*'
+	archive_cmds_GCJ='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	hardcode_libdir_flag_spec_GCJ='${wl}-rpath ${wl}$libdir'
+      else
+	allow_undefined_flag_GCJ=' -expect_unresolved \*'
+	archive_cmds_GCJ='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
+	archive_expsym_cmds_GCJ='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~
+	$LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~$rm $lib.exp'
+
+	# Both c and cxx compiler support -rpath directly
+	hardcode_libdir_flag_spec_GCJ='-rpath $libdir'
+      fi
+      hardcode_libdir_separator_GCJ=:
+      ;;
+
+    solaris*)
+      no_undefined_flag_GCJ=' -z text'
+      if test "$GCC" = yes; then
+	wlarc='${wl}'
+	archive_cmds_GCJ='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_GCJ='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+	  $CC -shared ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$rm $lib.exp'
+      else
+	wlarc=''
+	archive_cmds_GCJ='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	archive_expsym_cmds_GCJ='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
+  	$LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp'
+      fi
+      hardcode_libdir_flag_spec_GCJ='-R$libdir'
+      hardcode_shlibpath_var_GCJ=no
+      case $host_os in
+      solaris2.[0-5] | solaris2.[0-5].*) ;;
+      *)
+	# The compiler driver will combine and reorder linker options,
+	# but understands `-z linker_flag'.  GCC discards it without `$wl',
+	# but is careful enough not to reorder.
+ 	# Supported since Solaris 2.6 (maybe 2.5.1?)
+	if test "$GCC" = yes; then
+	  whole_archive_flag_spec_GCJ='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+	else
+	  whole_archive_flag_spec_GCJ='-z allextract$convenience -z defaultextract'
+	fi
+	;;
+      esac
+      link_all_deplibs_GCJ=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+	# Use $CC to link under sequent, because it throws in some extra .o
+	# files that make .init and .fini sections work.
+	archive_cmds_GCJ='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds_GCJ='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      hardcode_libdir_flag_spec_GCJ='-L$libdir'
+      hardcode_direct_GCJ=yes
+      hardcode_minus_L_GCJ=yes
+      hardcode_shlibpath_var_GCJ=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+	sni)
+	  archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  hardcode_direct_GCJ=yes # is this really true???
+	;;
+	siemens)
+	  ## LD is ld it makes a PLAMLIB
+	  ## CC just makes a GrossModule.
+	  archive_cmds_GCJ='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+	  reload_cmds_GCJ='$CC -r -o $output$reload_objs'
+	  hardcode_direct_GCJ=no
+        ;;
+	motorola)
+	  archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  hardcode_direct_GCJ=no #Motorola manual says yes, but my tests say they lie
+	;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      hardcode_shlibpath_var_GCJ=no
+      ;;
+
+    sysv4.3*)
+      archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_shlibpath_var_GCJ=no
+      export_dynamic_flag_spec_GCJ='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	hardcode_shlibpath_var_GCJ=no
+	runpath_var=LD_RUN_PATH
+	hardcode_runpath_var=yes
+	ld_shlibs_GCJ=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*)
+      no_undefined_flag_GCJ='${wl}-z,text'
+      archive_cmds_need_lc_GCJ=no
+      hardcode_shlibpath_var_GCJ=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	archive_cmds_GCJ='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_GCJ='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds_GCJ='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_GCJ='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      no_undefined_flag_GCJ='${wl}-z,text'
+      allow_undefined_flag_GCJ='${wl}-z,nodefs'
+      archive_cmds_need_lc_GCJ=no
+      hardcode_shlibpath_var_GCJ=no
+      hardcode_libdir_flag_spec_GCJ='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`'
+      hardcode_libdir_separator_GCJ=':'
+      link_all_deplibs_GCJ=yes
+      export_dynamic_flag_spec_GCJ='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	archive_cmds_GCJ='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_GCJ='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds_GCJ='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds_GCJ='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      archive_cmds_GCJ='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec_GCJ='-L$libdir'
+      hardcode_shlibpath_var_GCJ=no
+      ;;
+
+    *)
+      ld_shlibs_GCJ=no
+      ;;
+    esac
+  fi
+
+{ echo "$as_me:$LINENO: result: $ld_shlibs_GCJ" >&5
+echo "${ECHO_T}$ld_shlibs_GCJ" >&6; }
+test "$ld_shlibs_GCJ" = no && can_build_shared=no
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$archive_cmds_need_lc_GCJ" in
+x|xyes)
+  # Assume -lc should be added
+  archive_cmds_need_lc_GCJ=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $archive_cmds_GCJ in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      { echo "$as_me:$LINENO: checking whether -lc should be explicitly linked in" >&5
+echo $ECHO_N "checking whether -lc should be explicitly linked in... $ECHO_C" >&6; }
+      $rm conftest*
+      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+      if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } 2>conftest.err; then
+        soname=conftest
+        lib=conftest
+        libobjs=conftest.$ac_objext
+        deplibs=
+        wl=$lt_prog_compiler_wl_GCJ
+	pic_flag=$lt_prog_compiler_pic_GCJ
+        compiler_flags=-v
+        linker_flags=-v
+        verstring=
+        output_objdir=.
+        libname=conftest
+        lt_save_allow_undefined_flag=$allow_undefined_flag_GCJ
+        allow_undefined_flag_GCJ=
+        if { (eval echo "$as_me:$LINENO: \"$archive_cmds_GCJ 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1\"") >&5
+  (eval $archive_cmds_GCJ 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+        then
+	  archive_cmds_need_lc_GCJ=no
+        else
+	  archive_cmds_need_lc_GCJ=yes
+        fi
+        allow_undefined_flag_GCJ=$lt_save_allow_undefined_flag
+      else
+        cat conftest.err 1>&5
+      fi
+      $rm conftest*
+      { echo "$as_me:$LINENO: result: $archive_cmds_need_lc_GCJ" >&5
+echo "${ECHO_T}$archive_cmds_need_lc_GCJ" >&6; }
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+{ echo "$as_me:$LINENO: checking dynamic linker characteristics" >&5
+echo $ECHO_N "checking dynamic linker characteristics... $ECHO_C" >&6; }
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix4* | aix5*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[01] | aix4.[01].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+	   echo ' yes '
+	   echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then
+	:
+      else
+	can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  library_names_spec='$libname.ixlibrary $libname.a'
+  # Create ${libname}_ixlibrary.a entries in /sys/libs.
+  finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[45]*)
+  version_type=linux
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$host_os in
+  yes,cygwin* | yes,mingw* | yes,pw32*)
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $rm \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
+      ;;
+    mingw*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+      if echo "$sys_lib_search_path_spec" | grep ';[c-zC-Z]:/' >/dev/null; then
+        # It is most probably a Windows format PATH printed by
+        # mingw gcc, but we are running on Cygwin. Gcc prints its search
+        # path with ; separators, and with drive letters. We can handle the
+        # drive letters (cygwin fileutils understands them), so leave them,
+        # especially as we might pass files found there to a mingw objdump,
+        # which wouldn't understand a cygwinified path. Ahh.
+        sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    ;;
+
+  *)
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    ;;
+  esac
+  dynamic_linker='Win32 ld.exe'
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd1*)
+  dynamic_linker=no
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[123]*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[01]* | freebsdelf3.[01]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[2-9]* | freebsdelf3.[2-9]* | \
+  freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+gnu*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+   hppa*64*)
+     shrext_cmds='.sl'
+     hardcode_into_libs=yes
+     dynamic_linker="$host_os dld.sl"
+     shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+     shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+     library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+     soname_spec='${libname}${release}${shared_ext}$major'
+     sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+     sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+     ;;
+   *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555.
+  postinstall_cmds='chmod 555 $lib'
+  ;;
+
+interix[3-9]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+	if test "$lt_cv_prog_gnu_ld" = yes; then
+		version_type=linux
+	else
+		version_type=irix
+	fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ 	]*hwcap[ 	]/d;s/[:,	]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+nto-qnx*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*) need_version=yes ;;
+    *)                         need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[89] | openbsd2.[89].*)
+	shlibpath_overrides_runpath=no
+	;;
+      *)
+	shlibpath_overrides_runpath=yes
+	;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      export_dynamic_flag_spec='${wl}-Blargedynsym'
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+    shlibpath_overrides_runpath=no
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    shlibpath_overrides_runpath=yes
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+	;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+uts4*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+{ echo "$as_me:$LINENO: result: $dynamic_linker" >&5
+echo "${ECHO_T}$dynamic_linker" >&6; }
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+{ echo "$as_me:$LINENO: checking how to hardcode library paths into programs" >&5
+echo $ECHO_N "checking how to hardcode library paths into programs... $ECHO_C" >&6; }
+hardcode_action_GCJ=
+if test -n "$hardcode_libdir_flag_spec_GCJ" || \
+   test -n "$runpath_var_GCJ" || \
+   test "X$hardcode_automatic_GCJ" = "Xyes" ; then
+
+  # We can hardcode non-existant directories.
+  if test "$hardcode_direct_GCJ" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, GCJ)" != no &&
+     test "$hardcode_minus_L_GCJ" != no; then
+    # Linking always hardcodes the temporary library directory.
+    hardcode_action_GCJ=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    hardcode_action_GCJ=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  hardcode_action_GCJ=unsupported
+fi
+{ echo "$as_me:$LINENO: result: $hardcode_action_GCJ" >&5
+echo "${ECHO_T}$hardcode_action_GCJ" >&6; }
+
+if test "$hardcode_action_GCJ" = relink; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+
+
+# The else clause should only fire when bootstrapping the
+# libtool distribution, otherwise you forgot to ship ltmain.sh
+# with your package, and you will get complaints that there are
+# no rules to generate ltmain.sh.
+if test -f "$ltmain"; then
+  # See if we are running on zsh, and set the options which allow our commands through
+  # without removal of \ escapes.
+  if test -n "${ZSH_VERSION+set}" ; then
+    setopt NO_GLOB_SUBST
+  fi
+  # Now quote all the things that may contain metacharacters while being
+  # careful not to overquote the AC_SUBSTed values.  We take copies of the
+  # variables and quote the copies for generation of the libtool script.
+  for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC LTCFLAGS NM \
+    SED SHELL STRIP \
+    libname_spec library_names_spec soname_spec extract_expsyms_cmds \
+    old_striplib striplib file_magic_cmd finish_cmds finish_eval \
+    deplibs_check_method reload_flag reload_cmds need_locks \
+    lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \
+    lt_cv_sys_global_symbol_to_c_name_address \
+    sys_lib_search_path_spec sys_lib_dlsearch_path_spec \
+    old_postinstall_cmds old_postuninstall_cmds \
+    compiler_GCJ \
+    CC_GCJ \
+    LD_GCJ \
+    lt_prog_compiler_wl_GCJ \
+    lt_prog_compiler_pic_GCJ \
+    lt_prog_compiler_static_GCJ \
+    lt_prog_compiler_no_builtin_flag_GCJ \
+    export_dynamic_flag_spec_GCJ \
+    thread_safe_flag_spec_GCJ \
+    whole_archive_flag_spec_GCJ \
+    enable_shared_with_static_runtimes_GCJ \
+    old_archive_cmds_GCJ \
+    old_archive_from_new_cmds_GCJ \
+    predep_objects_GCJ \
+    postdep_objects_GCJ \
+    predeps_GCJ \
+    postdeps_GCJ \
+    compiler_lib_search_path_GCJ \
+    archive_cmds_GCJ \
+    archive_expsym_cmds_GCJ \
+    postinstall_cmds_GCJ \
+    postuninstall_cmds_GCJ \
+    old_archive_from_expsyms_cmds_GCJ \
+    allow_undefined_flag_GCJ \
+    no_undefined_flag_GCJ \
+    export_symbols_cmds_GCJ \
+    hardcode_libdir_flag_spec_GCJ \
+    hardcode_libdir_flag_spec_ld_GCJ \
+    hardcode_libdir_separator_GCJ \
+    hardcode_automatic_GCJ \
+    module_cmds_GCJ \
+    module_expsym_cmds_GCJ \
+    lt_cv_prog_compiler_c_o_GCJ \
+    fix_srcfile_path_GCJ \
+    exclude_expsyms_GCJ \
+    include_expsyms_GCJ; do
+
+    case $var in
+    old_archive_cmds_GCJ | \
+    old_archive_from_new_cmds_GCJ | \
+    archive_cmds_GCJ | \
+    archive_expsym_cmds_GCJ | \
+    module_cmds_GCJ | \
+    module_expsym_cmds_GCJ | \
+    old_archive_from_expsyms_cmds_GCJ | \
+    export_symbols_cmds_GCJ | \
+    extract_expsyms_cmds | reload_cmds | finish_cmds | \
+    postinstall_cmds | postuninstall_cmds | \
+    old_postinstall_cmds | old_postuninstall_cmds | \
+    sys_lib_search_path_spec | sys_lib_dlsearch_path_spec)
+      # Double-quote double-evaled strings.
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\""
+      ;;
+    *)
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\""
+      ;;
+    esac
+  done
+
+  case $lt_echo in
+  *'\$0 --fallback-echo"')
+    lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\$0 --fallback-echo"$/$0 --fallback-echo"/'`
+    ;;
+  esac
+
+cfgfile="$ofile"
+
+  cat <<__EOF__ >> "$cfgfile"
+# ### BEGIN LIBTOOL TAG CONFIG: $tagname
+
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+
+# Shell to use when invoking shell scripts.
+SHELL=$lt_SHELL
+
+# Whether or not to build shared libraries.
+build_libtool_libs=$enable_shared
+
+# Whether or not to build static libraries.
+build_old_libs=$enable_static
+
+# Whether or not to add -lc for building shared libraries.
+build_libtool_need_lc=$archive_cmds_need_lc_GCJ
+
+# Whether or not to disallow shared libs when runtime libs are static
+allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes_GCJ
+
+# Whether or not to optimize for fast installation.
+fast_install=$enable_fast_install
+
+# The host system.
+host_alias=$host_alias
+host=$host
+host_os=$host_os
+
+# The build system.
+build_alias=$build_alias
+build=$build
+build_os=$build_os
+
+# An echo program that does not interpret backslashes.
+echo=$lt_echo
+
+# The archiver.
+AR=$lt_AR
+AR_FLAGS=$lt_AR_FLAGS
+
+# A C compiler.
+LTCC=$lt_LTCC
+
+# LTCC compiler flags.
+LTCFLAGS=$lt_LTCFLAGS
+
+# A language-specific compiler.
+CC=$lt_compiler_GCJ
+
+# Is the compiler the GNU C compiler?
+with_gcc=$GCC_GCJ
+
+# An ERE matcher.
+EGREP=$lt_EGREP
+
+# The linker used to build libraries.
+LD=$lt_LD_GCJ
+
+# Whether we need hard or soft links.
+LN_S=$lt_LN_S
+
+# A BSD-compatible nm program.
+NM=$lt_NM
+
+# A symbol stripping program
+STRIP=$lt_STRIP
+
+# Used to examine libraries when file_magic_cmd begins "file"
+MAGIC_CMD=$MAGIC_CMD
+
+# Used on cygwin: DLL creation program.
+DLLTOOL="$DLLTOOL"
+
+# Used on cygwin: object dumper.
+OBJDUMP="$OBJDUMP"
+
+# Used on cygwin: assembler.
+AS="$AS"
+
+# The name of the directory that contains temporary libtool files.
+objdir=$objdir
+
+# How to create reloadable object files.
+reload_flag=$lt_reload_flag
+reload_cmds=$lt_reload_cmds
+
+# How to pass a linker flag through the compiler.
+wl=$lt_lt_prog_compiler_wl_GCJ
+
+# Object file suffix (normally "o").
+objext="$ac_objext"
+
+# Old archive suffix (normally "a").
+libext="$libext"
+
+# Shared library suffix (normally ".so").
+shrext_cmds='$shrext_cmds'
+
+# Executable file suffix (normally "").
+exeext="$exeext"
+
+# Additional compiler flags for building library objects.
+pic_flag=$lt_lt_prog_compiler_pic_GCJ
+pic_mode=$pic_mode
+
+# What is the maximum length of a command?
+max_cmd_len=$lt_cv_sys_max_cmd_len
+
+# Does compiler simultaneously support -c and -o options?
+compiler_c_o=$lt_lt_cv_prog_compiler_c_o_GCJ
+
+# Must we lock files when doing compilation?
+need_locks=$lt_need_locks
+
+# Do we need the lib prefix for modules?
+need_lib_prefix=$need_lib_prefix
+
+# Do we need a version for libraries?
+need_version=$need_version
+
+# Whether dlopen is supported.
+dlopen_support=$enable_dlopen
+
+# Whether dlopen of programs is supported.
+dlopen_self=$enable_dlopen_self
+
+# Whether dlopen of statically linked programs is supported.
+dlopen_self_static=$enable_dlopen_self_static
+
+# Compiler flag to prevent dynamic linking.
+link_static_flag=$lt_lt_prog_compiler_static_GCJ
+
+# Compiler flag to turn off builtin functions.
+no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag_GCJ
+
+# Compiler flag to allow reflexive dlopens.
+export_dynamic_flag_spec=$lt_export_dynamic_flag_spec_GCJ
+
+# Compiler flag to generate shared objects directly from archives.
+whole_archive_flag_spec=$lt_whole_archive_flag_spec_GCJ
+
+# Compiler flag to generate thread-safe objects.
+thread_safe_flag_spec=$lt_thread_safe_flag_spec_GCJ
+
+# Library versioning type.
+version_type=$version_type
+
+# Format of library name prefix.
+libname_spec=$lt_libname_spec
+
+# List of archive names.  First name is the real one, the rest are links.
+# The last name is the one that the linker finds with -lNAME.
+library_names_spec=$lt_library_names_spec
+
+# The coded name of the library, if different from the real name.
+soname_spec=$lt_soname_spec
+
+# Commands used to build and install an old-style archive.
+RANLIB=$lt_RANLIB
+old_archive_cmds=$lt_old_archive_cmds_GCJ
+old_postinstall_cmds=$lt_old_postinstall_cmds
+old_postuninstall_cmds=$lt_old_postuninstall_cmds
+
+# Create an old-style archive from a shared archive.
+old_archive_from_new_cmds=$lt_old_archive_from_new_cmds_GCJ
+
+# Create a temporary old-style archive to link instead of a shared archive.
+old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds_GCJ
+
+# Commands used to build and install a shared archive.
+archive_cmds=$lt_archive_cmds_GCJ
+archive_expsym_cmds=$lt_archive_expsym_cmds_GCJ
+postinstall_cmds=$lt_postinstall_cmds
+postuninstall_cmds=$lt_postuninstall_cmds
+
+# Commands used to build a loadable module (assumed same as above if empty)
+module_cmds=$lt_module_cmds_GCJ
+module_expsym_cmds=$lt_module_expsym_cmds_GCJ
+
+# Commands to strip libraries.
+old_striplib=$lt_old_striplib
+striplib=$lt_striplib
+
+# Dependencies to place before the objects being linked to create a
+# shared library.
+predep_objects=$lt_predep_objects_GCJ
+
+# Dependencies to place after the objects being linked to create a
+# shared library.
+postdep_objects=$lt_postdep_objects_GCJ
+
+# Dependencies to place before the objects being linked to create a
+# shared library.
+predeps=$lt_predeps_GCJ
+
+# Dependencies to place after the objects being linked to create a
+# shared library.
+postdeps=$lt_postdeps_GCJ
+
+# The library search path used internally by the compiler when linking
+# a shared library.
+compiler_lib_search_path=$lt_compiler_lib_search_path_GCJ
+
+# Method to check whether dependent libraries are shared objects.
+deplibs_check_method=$lt_deplibs_check_method
+
+# Command to use when deplibs_check_method == file_magic.
+file_magic_cmd=$lt_file_magic_cmd
+
+# Flag that allows shared libraries with undefined symbols to be built.
+allow_undefined_flag=$lt_allow_undefined_flag_GCJ
+
+# Flag that forces no undefined symbols.
+no_undefined_flag=$lt_no_undefined_flag_GCJ
+
+# Commands used to finish a libtool library installation in a directory.
+finish_cmds=$lt_finish_cmds
+
+# Same as above, but a single script fragment to be evaled but not shown.
+finish_eval=$lt_finish_eval
+
+# Take the output of nm and produce a listing of raw symbols and C names.
+global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe
+
+# Transform the output of nm in a proper C declaration
+global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl
+
+# Transform the output of nm in a C name address pair
+global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address
+
+# This is the shared library runtime path variable.
+runpath_var=$runpath_var
+
+# This is the shared library path variable.
+shlibpath_var=$shlibpath_var
+
+# Is shlibpath searched before the hard-coded library search path?
+shlibpath_overrides_runpath=$shlibpath_overrides_runpath
+
+# How to hardcode a shared library path into an executable.
+hardcode_action=$hardcode_action_GCJ
+
+# Whether we should hardcode library paths into libraries.
+hardcode_into_libs=$hardcode_into_libs
+
+# Flag to hardcode \$libdir into a binary during linking.
+# This must work even if \$libdir does not exist.
+hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec_GCJ
+
+# If ld is used when linking, flag to hardcode \$libdir into
+# a binary during linking. This must work even if \$libdir does
+# not exist.
+hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld_GCJ
+
+# Whether we need a single -rpath flag with a separated argument.
+hardcode_libdir_separator=$lt_hardcode_libdir_separator_GCJ
+
+# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the
+# resulting binary.
+hardcode_direct=$hardcode_direct_GCJ
+
+# Set to yes if using the -LDIR flag during linking hardcodes DIR into the
+# resulting binary.
+hardcode_minus_L=$hardcode_minus_L_GCJ
+
+# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into
+# the resulting binary.
+hardcode_shlibpath_var=$hardcode_shlibpath_var_GCJ
+
+# Set to yes if building a shared library automatically hardcodes DIR into the library
+# and all subsequent libraries and executables linked against it.
+hardcode_automatic=$hardcode_automatic_GCJ
+
+# Variables whose values should be saved in libtool wrapper scripts and
+# restored at relink time.
+variables_saved_for_relink="$variables_saved_for_relink"
+
+# Whether libtool must link a program against all its dependency libraries.
+link_all_deplibs=$link_all_deplibs_GCJ
+
+# Compile-time system search path for libraries
+sys_lib_search_path_spec=$lt_sys_lib_search_path_spec
+
+# Run-time system search path for libraries
+sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec
+
+# Fix the shell variable \$srcfile for the compiler.
+fix_srcfile_path=$lt_fix_srcfile_path
+
+# Set to yes if exported symbols are required.
+always_export_symbols=$always_export_symbols_GCJ
+
+# The commands to list exported symbols.
+export_symbols_cmds=$lt_export_symbols_cmds_GCJ
+
+# The commands to extract the exported symbol list from a shared archive.
+extract_expsyms_cmds=$lt_extract_expsyms_cmds
+
+# Symbols that should not be listed in the preloaded symbols.
+exclude_expsyms=$lt_exclude_expsyms_GCJ
+
+# Symbols that must always be exported.
+include_expsyms=$lt_include_expsyms_GCJ
+
+# ### END LIBTOOL TAG CONFIG: $tagname
+
+__EOF__
+
+
+else
+  # If there is no Makefile yet, we rely on a make rule to execute
+  # `config.status --recheck' to rerun these tests and create the
+  # libtool script then.
+  ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'`
+  if test -f "$ltmain_in"; then
+    test -f Makefile && make "$ltmain"
+  fi
+fi
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+CC="$lt_save_CC"
+
+	else
+	  tagname=""
+	fi
+	;;
+
+      RC)
+
+
+# Source file extension for RC test sources.
+ac_ext=rc
+
+# Object file extension for compiled RC test sources.
+objext=o
+objext_RC=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }'
+
+# Code to be used in simple link tests
+lt_simple_link_test_code="$lt_simple_compile_test_code"
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+
+# save warnings/boilerplate of simple test code
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$rm conftest*
+
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$rm conftest*
+
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+CC=${RC-"windres"}
+compiler=$CC
+compiler_RC=$CC
+for cc_temp in $compiler""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+
+lt_cv_prog_compiler_c_o_RC=yes
+
+# The else clause should only fire when bootstrapping the
+# libtool distribution, otherwise you forgot to ship ltmain.sh
+# with your package, and you will get complaints that there are
+# no rules to generate ltmain.sh.
+if test -f "$ltmain"; then
+  # See if we are running on zsh, and set the options which allow our commands through
+  # without removal of \ escapes.
+  if test -n "${ZSH_VERSION+set}" ; then
+    setopt NO_GLOB_SUBST
+  fi
+  # Now quote all the things that may contain metacharacters while being
+  # careful not to overquote the AC_SUBSTed values.  We take copies of the
+  # variables and quote the copies for generation of the libtool script.
+  for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC LTCFLAGS NM \
+    SED SHELL STRIP \
+    libname_spec library_names_spec soname_spec extract_expsyms_cmds \
+    old_striplib striplib file_magic_cmd finish_cmds finish_eval \
+    deplibs_check_method reload_flag reload_cmds need_locks \
+    lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \
+    lt_cv_sys_global_symbol_to_c_name_address \
+    sys_lib_search_path_spec sys_lib_dlsearch_path_spec \
+    old_postinstall_cmds old_postuninstall_cmds \
+    compiler_RC \
+    CC_RC \
+    LD_RC \
+    lt_prog_compiler_wl_RC \
+    lt_prog_compiler_pic_RC \
+    lt_prog_compiler_static_RC \
+    lt_prog_compiler_no_builtin_flag_RC \
+    export_dynamic_flag_spec_RC \
+    thread_safe_flag_spec_RC \
+    whole_archive_flag_spec_RC \
+    enable_shared_with_static_runtimes_RC \
+    old_archive_cmds_RC \
+    old_archive_from_new_cmds_RC \
+    predep_objects_RC \
+    postdep_objects_RC \
+    predeps_RC \
+    postdeps_RC \
+    compiler_lib_search_path_RC \
+    archive_cmds_RC \
+    archive_expsym_cmds_RC \
+    postinstall_cmds_RC \
+    postuninstall_cmds_RC \
+    old_archive_from_expsyms_cmds_RC \
+    allow_undefined_flag_RC \
+    no_undefined_flag_RC \
+    export_symbols_cmds_RC \
+    hardcode_libdir_flag_spec_RC \
+    hardcode_libdir_flag_spec_ld_RC \
+    hardcode_libdir_separator_RC \
+    hardcode_automatic_RC \
+    module_cmds_RC \
+    module_expsym_cmds_RC \
+    lt_cv_prog_compiler_c_o_RC \
+    fix_srcfile_path_RC \
+    exclude_expsyms_RC \
+    include_expsyms_RC; do
+
+    case $var in
+    old_archive_cmds_RC | \
+    old_archive_from_new_cmds_RC | \
+    archive_cmds_RC | \
+    archive_expsym_cmds_RC | \
+    module_cmds_RC | \
+    module_expsym_cmds_RC | \
+    old_archive_from_expsyms_cmds_RC | \
+    export_symbols_cmds_RC | \
+    extract_expsyms_cmds | reload_cmds | finish_cmds | \
+    postinstall_cmds | postuninstall_cmds | \
+    old_postinstall_cmds | old_postuninstall_cmds | \
+    sys_lib_search_path_spec | sys_lib_dlsearch_path_spec)
+      # Double-quote double-evaled strings.
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\""
+      ;;
+    *)
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\""
+      ;;
+    esac
+  done
+
+  case $lt_echo in
+  *'\$0 --fallback-echo"')
+    lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\$0 --fallback-echo"$/$0 --fallback-echo"/'`
+    ;;
+  esac
+
+cfgfile="$ofile"
+
+  cat <<__EOF__ >> "$cfgfile"
+# ### BEGIN LIBTOOL TAG CONFIG: $tagname
+
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+
+# Shell to use when invoking shell scripts.
+SHELL=$lt_SHELL
+
+# Whether or not to build shared libraries.
+build_libtool_libs=$enable_shared
+
+# Whether or not to build static libraries.
+build_old_libs=$enable_static
+
+# Whether or not to add -lc for building shared libraries.
+build_libtool_need_lc=$archive_cmds_need_lc_RC
+
+# Whether or not to disallow shared libs when runtime libs are static
+allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes_RC
+
+# Whether or not to optimize for fast installation.
+fast_install=$enable_fast_install
+
+# The host system.
+host_alias=$host_alias
+host=$host
+host_os=$host_os
+
+# The build system.
+build_alias=$build_alias
+build=$build
+build_os=$build_os
+
+# An echo program that does not interpret backslashes.
+echo=$lt_echo
+
+# The archiver.
+AR=$lt_AR
+AR_FLAGS=$lt_AR_FLAGS
+
+# A C compiler.
+LTCC=$lt_LTCC
+
+# LTCC compiler flags.
+LTCFLAGS=$lt_LTCFLAGS
+
+# A language-specific compiler.
+CC=$lt_compiler_RC
+
+# Is the compiler the GNU C compiler?
+with_gcc=$GCC_RC
+
+# An ERE matcher.
+EGREP=$lt_EGREP
+
+# The linker used to build libraries.
+LD=$lt_LD_RC
+
+# Whether we need hard or soft links.
+LN_S=$lt_LN_S
+
+# A BSD-compatible nm program.
+NM=$lt_NM
+
+# A symbol stripping program
+STRIP=$lt_STRIP
+
+# Used to examine libraries when file_magic_cmd begins "file"
+MAGIC_CMD=$MAGIC_CMD
+
+# Used on cygwin: DLL creation program.
+DLLTOOL="$DLLTOOL"
+
+# Used on cygwin: object dumper.
+OBJDUMP="$OBJDUMP"
+
+# Used on cygwin: assembler.
+AS="$AS"
+
+# The name of the directory that contains temporary libtool files.
+objdir=$objdir
+
+# How to create reloadable object files.
+reload_flag=$lt_reload_flag
+reload_cmds=$lt_reload_cmds
+
+# How to pass a linker flag through the compiler.
+wl=$lt_lt_prog_compiler_wl_RC
+
+# Object file suffix (normally "o").
+objext="$ac_objext"
+
+# Old archive suffix (normally "a").
+libext="$libext"
+
+# Shared library suffix (normally ".so").
+shrext_cmds='$shrext_cmds'
+
+# Executable file suffix (normally "").
+exeext="$exeext"
+
+# Additional compiler flags for building library objects.
+pic_flag=$lt_lt_prog_compiler_pic_RC
+pic_mode=$pic_mode
+
+# What is the maximum length of a command?
+max_cmd_len=$lt_cv_sys_max_cmd_len
+
+# Does compiler simultaneously support -c and -o options?
+compiler_c_o=$lt_lt_cv_prog_compiler_c_o_RC
+
+# Must we lock files when doing compilation?
+need_locks=$lt_need_locks
+
+# Do we need the lib prefix for modules?
+need_lib_prefix=$need_lib_prefix
+
+# Do we need a version for libraries?
+need_version=$need_version
+
+# Whether dlopen is supported.
+dlopen_support=$enable_dlopen
+
+# Whether dlopen of programs is supported.
+dlopen_self=$enable_dlopen_self
+
+# Whether dlopen of statically linked programs is supported.
+dlopen_self_static=$enable_dlopen_self_static
+
+# Compiler flag to prevent dynamic linking.
+link_static_flag=$lt_lt_prog_compiler_static_RC
+
+# Compiler flag to turn off builtin functions.
+no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag_RC
+
+# Compiler flag to allow reflexive dlopens.
+export_dynamic_flag_spec=$lt_export_dynamic_flag_spec_RC
+
+# Compiler flag to generate shared objects directly from archives.
+whole_archive_flag_spec=$lt_whole_archive_flag_spec_RC
+
+# Compiler flag to generate thread-safe objects.
+thread_safe_flag_spec=$lt_thread_safe_flag_spec_RC
+
+# Library versioning type.
+version_type=$version_type
+
+# Format of library name prefix.
+libname_spec=$lt_libname_spec
+
+# List of archive names.  First name is the real one, the rest are links.
+# The last name is the one that the linker finds with -lNAME.
+library_names_spec=$lt_library_names_spec
+
+# The coded name of the library, if different from the real name.
+soname_spec=$lt_soname_spec
+
+# Commands used to build and install an old-style archive.
+RANLIB=$lt_RANLIB
+old_archive_cmds=$lt_old_archive_cmds_RC
+old_postinstall_cmds=$lt_old_postinstall_cmds
+old_postuninstall_cmds=$lt_old_postuninstall_cmds
+
+# Create an old-style archive from a shared archive.
+old_archive_from_new_cmds=$lt_old_archive_from_new_cmds_RC
+
+# Create a temporary old-style archive to link instead of a shared archive.
+old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds_RC
+
+# Commands used to build and install a shared archive.
+archive_cmds=$lt_archive_cmds_RC
+archive_expsym_cmds=$lt_archive_expsym_cmds_RC
+postinstall_cmds=$lt_postinstall_cmds
+postuninstall_cmds=$lt_postuninstall_cmds
+
+# Commands used to build a loadable module (assumed same as above if empty)
+module_cmds=$lt_module_cmds_RC
+module_expsym_cmds=$lt_module_expsym_cmds_RC
+
+# Commands to strip libraries.
+old_striplib=$lt_old_striplib
+striplib=$lt_striplib
+
+# Dependencies to place before the objects being linked to create a
+# shared library.
+predep_objects=$lt_predep_objects_RC
+
+# Dependencies to place after the objects being linked to create a
+# shared library.
+postdep_objects=$lt_postdep_objects_RC
+
+# Dependencies to place before the objects being linked to create a
+# shared library.
+predeps=$lt_predeps_RC
+
+# Dependencies to place after the objects being linked to create a
+# shared library.
+postdeps=$lt_postdeps_RC
+
+# The library search path used internally by the compiler when linking
+# a shared library.
+compiler_lib_search_path=$lt_compiler_lib_search_path_RC
+
+# Method to check whether dependent libraries are shared objects.
+deplibs_check_method=$lt_deplibs_check_method
+
+# Command to use when deplibs_check_method == file_magic.
+file_magic_cmd=$lt_file_magic_cmd
+
+# Flag that allows shared libraries with undefined symbols to be built.
+allow_undefined_flag=$lt_allow_undefined_flag_RC
+
+# Flag that forces no undefined symbols.
+no_undefined_flag=$lt_no_undefined_flag_RC
+
+# Commands used to finish a libtool library installation in a directory.
+finish_cmds=$lt_finish_cmds
+
+# Same as above, but a single script fragment to be evaled but not shown.
+finish_eval=$lt_finish_eval
+
+# Take the output of nm and produce a listing of raw symbols and C names.
+global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe
+
+# Transform the output of nm in a proper C declaration
+global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl
+
+# Transform the output of nm in a C name address pair
+global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address
+
+# This is the shared library runtime path variable.
+runpath_var=$runpath_var
+
+# This is the shared library path variable.
+shlibpath_var=$shlibpath_var
+
+# Is shlibpath searched before the hard-coded library search path?
+shlibpath_overrides_runpath=$shlibpath_overrides_runpath
+
+# How to hardcode a shared library path into an executable.
+hardcode_action=$hardcode_action_RC
+
+# Whether we should hardcode library paths into libraries.
+hardcode_into_libs=$hardcode_into_libs
+
+# Flag to hardcode \$libdir into a binary during linking.
+# This must work even if \$libdir does not exist.
+hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec_RC
+
+# If ld is used when linking, flag to hardcode \$libdir into
+# a binary during linking. This must work even if \$libdir does
+# not exist.
+hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld_RC
+
+# Whether we need a single -rpath flag with a separated argument.
+hardcode_libdir_separator=$lt_hardcode_libdir_separator_RC
+
+# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the
+# resulting binary.
+hardcode_direct=$hardcode_direct_RC
+
+# Set to yes if using the -LDIR flag during linking hardcodes DIR into the
+# resulting binary.
+hardcode_minus_L=$hardcode_minus_L_RC
+
+# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into
+# the resulting binary.
+hardcode_shlibpath_var=$hardcode_shlibpath_var_RC
+
+# Set to yes if building a shared library automatically hardcodes DIR into the library
+# and all subsequent libraries and executables linked against it.
+hardcode_automatic=$hardcode_automatic_RC
+
+# Variables whose values should be saved in libtool wrapper scripts and
+# restored at relink time.
+variables_saved_for_relink="$variables_saved_for_relink"
+
+# Whether libtool must link a program against all its dependency libraries.
+link_all_deplibs=$link_all_deplibs_RC
+
+# Compile-time system search path for libraries
+sys_lib_search_path_spec=$lt_sys_lib_search_path_spec
+
+# Run-time system search path for libraries
+sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec
+
+# Fix the shell variable \$srcfile for the compiler.
+fix_srcfile_path=$lt_fix_srcfile_path
+
+# Set to yes if exported symbols are required.
+always_export_symbols=$always_export_symbols_RC
+
+# The commands to list exported symbols.
+export_symbols_cmds=$lt_export_symbols_cmds_RC
+
+# The commands to extract the exported symbol list from a shared archive.
+extract_expsyms_cmds=$lt_extract_expsyms_cmds
+
+# Symbols that should not be listed in the preloaded symbols.
+exclude_expsyms=$lt_exclude_expsyms_RC
+
+# Symbols that must always be exported.
+include_expsyms=$lt_include_expsyms_RC
+
+# ### END LIBTOOL TAG CONFIG: $tagname
+
+__EOF__
+
+
+else
+  # If there is no Makefile yet, we rely on a make rule to execute
+  # `config.status --recheck' to rerun these tests and create the
+  # libtool script then.
+  ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'`
+  if test -f "$ltmain_in"; then
+    test -f Makefile && make "$ltmain"
+  fi
+fi
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+CC="$lt_save_CC"
+
+	;;
+
+      *)
+	{ { echo "$as_me:$LINENO: error: Unsupported tag name: $tagname" >&5
+echo "$as_me: error: Unsupported tag name: $tagname" >&2;}
+   { (exit 1); exit 1; }; }
+	;;
+      esac
+
+      # Append the new tag name to the list of available tags.
+      if test -n "$tagname" ; then
+      available_tags="$available_tags $tagname"
+    fi
+    fi
+  done
+  IFS="$lt_save_ifs"
+
+  # Now substitute the updated list of available tags.
+  if eval "sed -e 's/^available_tags=.*\$/available_tags=\"$available_tags\"/' \"$ofile\" > \"${ofile}T\""; then
+    mv "${ofile}T" "$ofile"
+    chmod +x "$ofile"
+  else
+    rm -f "${ofile}T"
+    { { echo "$as_me:$LINENO: error: unable to update list of available tagged configurations." >&5
+echo "$as_me: error: unable to update list of available tagged configurations." >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+fi
+
+
+
+# This can be used to rebuild libtool when needed
+LIBTOOL_DEPS="$ac_aux_dir/ltmain.sh"
+
+# Always use our own libtool.
+LIBTOOL='$(SHELL) $(top_builddir)/libtool'
+
+# Prevent multiple expansion
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{ echo "$as_me:$LINENO: checking whether to enable maintainer-specific portions of Makefiles" >&5
+echo $ECHO_N "checking whether to enable maintainer-specific portions of Makefiles... $ECHO_C" >&6; }
+    # Check whether --enable-maintainer-mode was given.
+if test "${enable_maintainer_mode+set}" = set; then
+  enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval
+else
+  USE_MAINTAINER_MODE=no
+fi
+
+  { echo "$as_me:$LINENO: result: $USE_MAINTAINER_MODE" >&5
+echo "${ECHO_T}$USE_MAINTAINER_MODE" >&6; }
+   if test $USE_MAINTAINER_MODE = yes; then
+  MAINTAINER_MODE_TRUE=
+  MAINTAINER_MODE_FALSE='#'
+else
+  MAINTAINER_MODE_TRUE='#'
+  MAINTAINER_MODE_FALSE=
+fi
+
+  MAINT=$MAINTAINER_MODE_TRUE
+
+
+
+
+for ac_header in sys/mman.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  { echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+ac_res=`eval echo '${'$as_ac_Header'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <$ac_header>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
+    ( cat <<\_ASBOX
+## ------------------------------------------- ##
+## Report this to http://gcc.gnu.org/bugs.html ##
+## ------------------------------------------- ##
+_ASBOX
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+{ echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  eval "$as_ac_Header=\$ac_header_preproc"
+fi
+ac_res=`eval echo '${'$as_ac_Header'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+for ac_func in mmap
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; }
+if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$ac_func || defined __stub___$ac_func
+choke me
+#endif
+
+int
+main ()
+{
+return $ac_func ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	eval "$as_ac_var=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+ac_res=`eval echo '${'$as_ac_var'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+if test "${ac_cv_header_sys_mman_h+set}" = set; then
+  { echo "$as_me:$LINENO: checking for sys/mman.h" >&5
+echo $ECHO_N "checking for sys/mman.h... $ECHO_C" >&6; }
+if test "${ac_cv_header_sys_mman_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_mman_h" >&5
+echo "${ECHO_T}$ac_cv_header_sys_mman_h" >&6; }
+else
+  # Is the header compilable?
+{ echo "$as_me:$LINENO: checking sys/mman.h usability" >&5
+echo $ECHO_N "checking sys/mman.h usability... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <sys/mman.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ echo "$as_me:$LINENO: checking sys/mman.h presence" >&5
+echo $ECHO_N "checking sys/mman.h presence... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/mman.h>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: sys/mman.h: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: sys/mman.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: sys/mman.h: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: sys/mman.h: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: sys/mman.h: present but cannot be compiled" >&5
+echo "$as_me: WARNING: sys/mman.h: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: sys/mman.h:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: sys/mman.h:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: sys/mman.h: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: sys/mman.h: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: sys/mman.h:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: sys/mman.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: sys/mman.h: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: sys/mman.h: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: sys/mman.h: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: sys/mman.h: in the future, the compiler will take precedence" >&2;}
+    ( cat <<\_ASBOX
+## ------------------------------------------- ##
+## Report this to http://gcc.gnu.org/bugs.html ##
+## ------------------------------------------- ##
+_ASBOX
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+{ echo "$as_me:$LINENO: checking for sys/mman.h" >&5
+echo $ECHO_N "checking for sys/mman.h... $ECHO_C" >&6; }
+if test "${ac_cv_header_sys_mman_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_header_sys_mman_h=$ac_header_preproc
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_mman_h" >&5
+echo "${ECHO_T}$ac_cv_header_sys_mman_h" >&6; }
+
+fi
+if test $ac_cv_header_sys_mman_h = yes; then
+  libffi_header_sys_mman_h=yes
+else
+  libffi_header_sys_mman_h=no
+fi
+
+
+{ echo "$as_me:$LINENO: checking for mmap" >&5
+echo $ECHO_N "checking for mmap... $ECHO_C" >&6; }
+if test "${ac_cv_func_mmap+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define mmap to an innocuous variant, in case <limits.h> declares mmap.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define mmap innocuous_mmap
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char mmap (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef mmap
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char mmap ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_mmap || defined __stub___mmap
+choke me
+#endif
+
+int
+main ()
+{
+return mmap ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_func_mmap=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_func_mmap=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_func_mmap" >&5
+echo "${ECHO_T}$ac_cv_func_mmap" >&6; }
+if test $ac_cv_func_mmap = yes; then
+  libffi_func_mmap=yes
+else
+  libffi_func_mmap=no
+fi
+
+if test "$libffi_header_sys_mman_h" != yes \
+ || test "$libffi_func_mmap" != yes; then
+   ac_cv_func_mmap_file=no
+   ac_cv_func_mmap_dev_zero=no
+   ac_cv_func_mmap_anon=no
+else
+   { echo "$as_me:$LINENO: checking whether read-only mmap of a plain file works" >&5
+echo $ECHO_N "checking whether read-only mmap of a plain file works... $ECHO_C" >&6; }
+if test "${ac_cv_func_mmap_file+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  # Add a system to this blacklist if
+   # mmap(0, stat_size, PROT_READ, MAP_PRIVATE, fd, 0) doesn't return a
+   # memory area containing the same data that you'd get if you applied
+   # read() to the same fd.  The only system known to have a problem here
+   # is VMS, where text files have record structure.
+   case "$host_os" in
+     vms* | ultrix*)
+	ac_cv_func_mmap_file=no ;;
+     *)
+	ac_cv_func_mmap_file=yes;;
+   esac
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_func_mmap_file" >&5
+echo "${ECHO_T}$ac_cv_func_mmap_file" >&6; }
+   { echo "$as_me:$LINENO: checking whether mmap from /dev/zero works" >&5
+echo $ECHO_N "checking whether mmap from /dev/zero works... $ECHO_C" >&6; }
+if test "${ac_cv_func_mmap_dev_zero+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  # Add a system to this blacklist if it has mmap() but /dev/zero
+   # does not exist, or if mmapping /dev/zero does not give anonymous
+   # zeroed pages with both the following properties:
+   # 1. If you map N consecutive pages in with one call, and then
+   #    unmap any subset of those pages, the pages that were not
+   #    explicitly unmapped remain accessible.
+   # 2. If you map two adjacent blocks of memory and then unmap them
+   #    both at once, they must both go away.
+   # Systems known to be in this category are Windows (all variants),
+   # VMS, and Darwin.
+   case "$host_os" in
+     vms* | cygwin* | pe | mingw* | darwin* | ultrix* | hpux10* | hpux11.00)
+	ac_cv_func_mmap_dev_zero=no ;;
+     *)
+	ac_cv_func_mmap_dev_zero=yes;;
+   esac
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_func_mmap_dev_zero" >&5
+echo "${ECHO_T}$ac_cv_func_mmap_dev_zero" >&6; }
+
+   # Unlike /dev/zero, the MAP_ANON(YMOUS) defines can be probed for.
+   { echo "$as_me:$LINENO: checking for MAP_ANON(YMOUS)" >&5
+echo $ECHO_N "checking for MAP_ANON(YMOUS)... $ECHO_C" >&6; }
+if test "${ac_cv_decl_map_anon+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+
+int
+main ()
+{
+int n = MAP_ANONYMOUS;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_decl_map_anon=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_decl_map_anon=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_decl_map_anon" >&5
+echo "${ECHO_T}$ac_cv_decl_map_anon" >&6; }
+
+   if test $ac_cv_decl_map_anon = no; then
+     ac_cv_func_mmap_anon=no
+   else
+     { echo "$as_me:$LINENO: checking whether mmap with MAP_ANON(YMOUS) works" >&5
+echo $ECHO_N "checking whether mmap with MAP_ANON(YMOUS) works... $ECHO_C" >&6; }
+if test "${ac_cv_func_mmap_anon+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  # Add a system to this blacklist if it has mmap() and MAP_ANON or
+   # MAP_ANONYMOUS, but using mmap(..., MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
+   # doesn't give anonymous zeroed pages with the same properties listed
+   # above for use of /dev/zero.
+   # Systems known to be in this category are Windows, VMS, and SCO Unix.
+   case "$host_os" in
+     vms* | cygwin* | pe | mingw* | sco* | udk* )
+	ac_cv_func_mmap_anon=no ;;
+     *)
+	ac_cv_func_mmap_anon=yes;;
+   esac
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_func_mmap_anon" >&5
+echo "${ECHO_T}$ac_cv_func_mmap_anon" >&6; }
+   fi
+fi
+
+if test $ac_cv_func_mmap_file = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_MMAP_FILE 1
+_ACEOF
+
+fi
+if test $ac_cv_func_mmap_dev_zero = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_MMAP_DEV_ZERO 1
+_ACEOF
+
+fi
+if test $ac_cv_func_mmap_anon = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_MMAP_ANON 1
+_ACEOF
+
+fi
+
+
+ if test -d $srcdir/testsuite; then
+  TESTSUBDIR_TRUE=
+  TESTSUBDIR_FALSE='#'
+else
+  TESTSUBDIR_TRUE='#'
+  TESTSUBDIR_FALSE=
+fi
+
+
+TARGETDIR="unknown"
+case "$host" in
+  alpha*-*-*)
+	TARGET=ALPHA; TARGETDIR=alpha;
+	# Support 128-bit long double, changable via command-line switch.
+	HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)'
+	;;
+
+  arm*-*-*)
+	TARGET=ARM; TARGETDIR=arm
+	;;
+
+  amd64-*-freebsd*)
+	TARGET=X86_64; TARGETDIR=x86
+  	;;
+
+  cris-*-*)
+	TARGET=LIBFFI_CRIS; TARGETDIR=cris
+	;;
+
+  frv-*-*)
+	TARGET=FRV; TARGETDIR=frv
+	;;
+
+  hppa*-*-linux* | parisc*-*-linux*)
+	TARGET=PA_LINUX; TARGETDIR=pa
+	;;
+  hppa*64-*-hpux*)
+	TARGET=PA64_HPUX; TARGETDIR=pa
+	;;
+  hppa*-*-hpux*)
+	TARGET=PA_HPUX; TARGETDIR=pa
+	;;
+
+  i386-*-freebsd* | i386-*-openbsd*)
+	TARGET=X86_FREEBSD; TARGETDIR=x86
+	;;
+  i?86-win32* | i?86-*-cygwin* | i?86-*-mingw*)
+	TARGET=X86_WIN32; TARGETDIR=x86
+	;;
+  i?86-*-darwin*)
+	TARGET=X86_DARWIN; TARGETDIR=x86
+	;;
+  i?86-*-solaris2.1[0-9]*)
+	TARGET=X86_64; TARGETDIR=x86
+	;;
+  i?86-*-*)
+	TARGET=X86; TARGETDIR=x86
+	;;
+
+  ia64*-*-*)
+	TARGET=IA64; TARGETDIR=ia64
+	;;
+
+  m32r*-*-*)
+	TARGET=M32R; TARGETDIR=m32r
+	;;
+
+  m68k-*-*)
+	TARGET=M68K; TARGETDIR=m68k
+	;;
+
+  mips-sgi-irix5.* | mips-sgi-irix6.*)
+	TARGET=MIPS; TARGETDIR=mips
+	;;
+  mips*-*-linux*)
+	TARGET=MIPS; TARGETDIR=mips
+	;;
+
+  powerpc*-*-linux* | powerpc-*-sysv*)
+	TARGET=POWERPC; TARGETDIR=powerpc
+	;;
+  powerpc-*-beos*)
+	TARGET=POWERPC; TARGETDIR=powerpc
+	;;
+  powerpc-*-darwin*)
+	TARGET=POWERPC_DARWIN; TARGETDIR=powerpc
+	;;
+  powerpc-*-aix* | rs6000-*-aix*)
+	TARGET=POWERPC_AIX; TARGETDIR=powerpc
+	;;
+  powerpc-*-freebsd*)
+	TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
+	;;
+  powerpc*-*-rtems*)
+	TARGET=POWERPC; TARGETDIR=powerpc
+	;;
+
+  s390-*-* | s390x-*-*)
+	TARGET=S390; TARGETDIR=s390
+	;;
+
+  sh-*-* | sh[34]*-*-*)
+	TARGET=SH; TARGETDIR=sh
+	;;
+  sh64-*-* | sh5*-*-*)
+	TARGET=SH64; TARGETDIR=sh64
+	;;
+
+  sparc*-*-*)
+	TARGET=SPARC; TARGETDIR=sparc
+	;;
+
+  x86_64-*-darwin*)
+	TARGET=X86_DARWIN; TARGETDIR=x86
+	;;
+  x86_64-*-cygwin* | x86_64-*-mingw*)
+	;;
+  x86_64-*-*)
+	TARGET=X86_64; TARGETDIR=x86
+	;;
+esac
+
+
+
+if test $TARGETDIR = unknown; then
+  { { echo "$as_me:$LINENO: error: \"libffi has not been ported to $host.\"" >&5
+echo "$as_me: error: \"libffi has not been ported to $host.\"" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+ if test x$TARGET = xMIPS; then
+  MIPS_TRUE=
+  MIPS_FALSE='#'
+else
+  MIPS_TRUE='#'
+  MIPS_FALSE=
+fi
+
+ if test x$TARGET = xSPARC; then
+  SPARC_TRUE=
+  SPARC_FALSE='#'
+else
+  SPARC_TRUE='#'
+  SPARC_FALSE=
+fi
+
+ if test x$TARGET = xX86; then
+  X86_TRUE=
+  X86_FALSE='#'
+else
+  X86_TRUE='#'
+  X86_FALSE=
+fi
+
+ if test x$TARGET = xX86_FREEBSD; then
+  X86_FREEBSD_TRUE=
+  X86_FREEBSD_FALSE='#'
+else
+  X86_FREEBSD_TRUE='#'
+  X86_FREEBSD_FALSE=
+fi
+
+ if test x$TARGET = xX86_WIN32; then
+  X86_WIN32_TRUE=
+  X86_WIN32_FALSE='#'
+else
+  X86_WIN32_TRUE='#'
+  X86_WIN32_FALSE=
+fi
+
+ if test x$TARGET = xX86_DARWIN; then
+  X86_DARWIN_TRUE=
+  X86_DARWIN_FALSE='#'
+else
+  X86_DARWIN_TRUE='#'
+  X86_DARWIN_FALSE=
+fi
+
+ if test x$TARGET = xALPHA; then
+  ALPHA_TRUE=
+  ALPHA_FALSE='#'
+else
+  ALPHA_TRUE='#'
+  ALPHA_FALSE=
+fi
+
+ if test x$TARGET = xIA64; then
+  IA64_TRUE=
+  IA64_FALSE='#'
+else
+  IA64_TRUE='#'
+  IA64_FALSE=
+fi
+
+ if test x$TARGET = xM32R; then
+  M32R_TRUE=
+  M32R_FALSE='#'
+else
+  M32R_TRUE='#'
+  M32R_FALSE=
+fi
+
+ if test x$TARGET = xM68K; then
+  M68K_TRUE=
+  M68K_FALSE='#'
+else
+  M68K_TRUE='#'
+  M68K_FALSE=
+fi
+
+ if test x$TARGET = xPOWERPC; then
+  POWERPC_TRUE=
+  POWERPC_FALSE='#'
+else
+  POWERPC_TRUE='#'
+  POWERPC_FALSE=
+fi
+
+ if test x$TARGET = xPOWERPC_AIX; then
+  POWERPC_AIX_TRUE=
+  POWERPC_AIX_FALSE='#'
+else
+  POWERPC_AIX_TRUE='#'
+  POWERPC_AIX_FALSE=
+fi
+
+ if test x$TARGET = xPOWERPC_DARWIN; then
+  POWERPC_DARWIN_TRUE=
+  POWERPC_DARWIN_FALSE='#'
+else
+  POWERPC_DARWIN_TRUE='#'
+  POWERPC_DARWIN_FALSE=
+fi
+
+ if test x$TARGET = xPOWERPC_FREEBSD; then
+  POWERPC_FREEBSD_TRUE=
+  POWERPC_FREEBSD_FALSE='#'
+else
+  POWERPC_FREEBSD_TRUE='#'
+  POWERPC_FREEBSD_FALSE=
+fi
+
+ if test x$TARGET = xARM; then
+  ARM_TRUE=
+  ARM_FALSE='#'
+else
+  ARM_TRUE='#'
+  ARM_FALSE=
+fi
+
+ if test x$TARGET = xLIBFFI_CRIS; then
+  LIBFFI_CRIS_TRUE=
+  LIBFFI_CRIS_FALSE='#'
+else
+  LIBFFI_CRIS_TRUE='#'
+  LIBFFI_CRIS_FALSE=
+fi
+
+ if test x$TARGET = xFRV; then
+  FRV_TRUE=
+  FRV_FALSE='#'
+else
+  FRV_TRUE='#'
+  FRV_FALSE=
+fi
+
+ if test x$TARGET = xS390; then
+  S390_TRUE=
+  S390_FALSE='#'
+else
+  S390_TRUE='#'
+  S390_FALSE=
+fi
+
+ if test x$TARGET = xX86_64; then
+  X86_64_TRUE=
+  X86_64_FALSE='#'
+else
+  X86_64_TRUE='#'
+  X86_64_FALSE=
+fi
+
+ if test x$TARGET = xSH; then
+  SH_TRUE=
+  SH_FALSE='#'
+else
+  SH_TRUE='#'
+  SH_FALSE=
+fi
+
+ if test x$TARGET = xSH64; then
+  SH64_TRUE=
+  SH64_FALSE='#'
+else
+  SH64_TRUE='#'
+  SH64_FALSE=
 fi
-rm -f conftest.err conftest.$ac_objext \
-      conftest$ac_exeext conftest.$ac_ext
+
+ if test x$TARGET = xPA_LINUX; then
+  PA_LINUX_TRUE=
+  PA_LINUX_FALSE='#'
+else
+  PA_LINUX_TRUE='#'
+  PA_LINUX_FALSE=
 fi
-echo "$as_me:$LINENO: result: $ac_cv_working_alloca_h" >&5
-echo "${ECHO_T}$ac_cv_working_alloca_h" >&6
-if test $ac_cv_working_alloca_h = yes; then
 
-cat >>confdefs.h <<\_ACEOF
-#define HAVE_ALLOCA_H 1
-_ACEOF
+ if test x$TARGET = xPA_HPUX; then
+  PA_HPUX_TRUE=
+  PA_HPUX_FALSE='#'
+else
+  PA_HPUX_TRUE='#'
+  PA_HPUX_FALSE=
+fi
 
+ if test x$TARGET = xPA64_HPUX; then
+  PA64_HPUX_TRUE=
+  PA64_HPUX_FALSE='#'
+else
+  PA64_HPUX_TRUE='#'
+  PA64_HPUX_FALSE=
 fi
 
-echo "$as_me:$LINENO: checking for alloca" >&5
-echo $ECHO_N "checking for alloca... $ECHO_C" >&6
-if test "${ac_cv_func_alloca_works+set}" = set; then
+
+{ echo "$as_me:$LINENO: checking for ANSI C header files" >&5
+echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6; }
+if test "${ac_cv_header_stdc+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
@@ -3892,230 +20685,92 @@
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#ifdef __GNUC__
-# define alloca __builtin_alloca
-#else
-# ifdef _MSC_VER
-#  include <malloc.h>
-#  define alloca _alloca
-# else
-#  if HAVE_ALLOCA_H
-#   include <alloca.h>
-#  else
-#   ifdef _AIX
- #pragma alloca
-#   else
-#    ifndef alloca /* predefined by HP cc +Olibcalls */
-char *alloca ();
-#    endif
-#   endif
-#  endif
-# endif
-#endif
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
 
 int
 main ()
 {
-char *p = (char *) alloca (1);
+
   ;
   return 0;
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>conftest.er1
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_cv_func_alloca_works=yes
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_header_stdc=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_cv_func_alloca_works=no
+	ac_cv_header_stdc=no
 fi
-rm -f conftest.err conftest.$ac_objext \
-      conftest$ac_exeext conftest.$ac_ext
-fi
-echo "$as_me:$LINENO: result: $ac_cv_func_alloca_works" >&5
-echo "${ECHO_T}$ac_cv_func_alloca_works" >&6
-
-if test $ac_cv_func_alloca_works = yes; then
-
-cat >>confdefs.h <<\_ACEOF
-#define HAVE_ALLOCA 1
-_ACEOF
 
-else
-  # The SVR3 libPW and SVR4 libucb both contain incompatible functions
-# that cause trouble.  Some versions do not even contain alloca or
-# contain a buggy version.  If you still want to use their alloca,
-# use ar to extract alloca.o from them instead of compiling alloca.c.
-
-ALLOCA=alloca.$ac_objext
-
-cat >>confdefs.h <<\_ACEOF
-#define C_ALLOCA 1
-_ACEOF
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
-
-echo "$as_me:$LINENO: checking whether \`alloca.c' needs Cray hooks" >&5
-echo $ECHO_N "checking whether \`alloca.c' needs Cray hooks... $ECHO_C" >&6
-if test "${ac_cv_os_cray+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#if defined(CRAY) && ! defined(CRAY2)
-webecray
-#else
-wenotbecray
-#endif
+#include <string.h>
 
 _ACEOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  $EGREP "webecray" >/dev/null 2>&1; then
-  ac_cv_os_cray=yes
+  $EGREP "memchr" >/dev/null 2>&1; then
+  :
 else
-  ac_cv_os_cray=no
+  ac_cv_header_stdc=no
 fi
 rm -f conftest*
 
 fi
-echo "$as_me:$LINENO: result: $ac_cv_os_cray" >&5
-echo "${ECHO_T}$ac_cv_os_cray" >&6
-if test $ac_cv_os_cray = yes; then
-  for ac_func in _getb67 GETB67 getb67; do
-    as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
-echo "$as_me:$LINENO: checking for $ac_func" >&5
-echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
-if eval "test \"\${$as_ac_var+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
-   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
-#define $ac_func innocuous_$ac_func
-
-/* System header to define __stub macros and hopefully few prototypes,
-    which can conflict with char $ac_func (); below.
-    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
-    <limits.h> exists even on freestanding compilers.  */
-
-#ifdef __STDC__
-# include <limits.h>
-#else
-# include <assert.h>
-#endif
-
-#undef $ac_func
-
-/* Override any gcc2 internal prototype to avoid an error.  */
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-/* We use char because int might match the return type of a gcc2
-   builtin and then its argument prototype would still apply.  */
-char $ac_func ();
-/* The GNU C library defines this for functions which it implements
-    to always fail with ENOSYS.  Some functions are actually named
-    something starting with __ and the normal name is an alias.  */
-#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
-choke me
-#else
-char (*f) () = $ac_func;
-#endif
-#ifdef __cplusplus
-}
-#endif
+#include <stdlib.h>
 
-int
-main ()
-{
-return f != $ac_func;
-  ;
-  return 0;
-}
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  eval "$as_ac_var=yes"
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then
+  :
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-eval "$as_ac_var=no"
-fi
-rm -f conftest.err conftest.$ac_objext \
-      conftest$ac_exeext conftest.$ac_ext
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
-if test `eval echo '${'$as_ac_var'}'` = yes; then
-
-cat >>confdefs.h <<_ACEOF
-#define CRAY_STACKSEG_END $ac_func
-_ACEOF
-
-    break
+  ac_cv_header_stdc=no
 fi
+rm -f conftest*
 
-  done
 fi
 
-echo "$as_me:$LINENO: checking stack direction for C alloca" >&5
-echo $ECHO_N "checking stack direction for C alloca... $ECHO_C" >&6
-if test "${ac_cv_c_stack_direction+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
   if test "$cross_compiling" = yes; then
-  ac_cv_c_stack_direction=0
+  :
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -4123,63 +20778,83 @@
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-int
-find_stack_direction ()
-{
-  static char *addr = 0;
-  auto char dummy;
-  if (addr == 0)
-    {
-      addr = &dummy;
-      return find_stack_direction ();
-    }
-  else
-    return (&dummy > addr) ? 1 : -1;
-}
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
 
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
 int
 main ()
 {
-  exit (find_stack_direction () < 0);
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      return 2;
+  return 0;
 }
 _ACEOF
 rm -f conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>&5
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  ac_cv_c_stack_direction=1
+  :
 else
   echo "$as_me: program exited with status $ac_status" >&5
 echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
 ( exit $ac_status )
-ac_cv_c_stack_direction=-1
+ac_cv_header_stdc=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
 fi
-rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+
+
 fi
 fi
-echo "$as_me:$LINENO: result: $ac_cv_c_stack_direction" >&5
-echo "${ECHO_T}$ac_cv_c_stack_direction" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5
+echo "${ECHO_T}$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
 
-cat >>confdefs.h <<_ACEOF
-#define STACK_DIRECTION $ac_cv_c_stack_direction
+cat >>confdefs.h <<\_ACEOF
+#define STDC_HEADERS 1
 _ACEOF
 
-
 fi
 
 
-echo "$as_me:$LINENO: checking for double" >&5
-echo $ECHO_N "checking for double... $ECHO_C" >&6
-if test "${ac_cv_type_double+set}" = set; then
+for ac_func in memcpy
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; }
+if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
@@ -4188,331 +20863,372 @@
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-$ac_includes_default
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$ac_func || defined __stub___$ac_func
+choke me
+#endif
+
 int
 main ()
 {
-if ((double *) 0)
-  return 0;
-if (sizeof (double))
-  return 0;
+return $ac_func ();
   ;
   return 0;
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_cv_type_double=yes
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  eval "$as_ac_var=yes"
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_cv_type_double=no
+	eval "$as_ac_var=no"
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
 fi
-echo "$as_me:$LINENO: result: $ac_cv_type_double" >&5
-echo "${ECHO_T}$ac_cv_type_double" >&6
+ac_res=`eval echo '${'$as_ac_var'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
 
-echo "$as_me:$LINENO: checking size of double" >&5
-echo $ECHO_N "checking size of double... $ECHO_C" >&6
-if test "${ac_cv_sizeof_double+set}" = set; then
+fi
+done
+
+# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
+# for constant arguments.  Useless!
+{ echo "$as_me:$LINENO: checking for working alloca.h" >&5
+echo $ECHO_N "checking for working alloca.h... $ECHO_C" >&6; }
+if test "${ac_cv_working_alloca_h+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  if test "$ac_cv_type_double" = yes; then
-  # The cast to unsigned long works around a bug in the HP C Compiler
-  # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
-  # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
-  # This bug is HP SR number 8606223364.
-  if test "$cross_compiling" = yes; then
-  # Depending upon the size, compute the lo and hi bounds.
-cat >conftest.$ac_ext <<_ACEOF
+  cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-$ac_includes_default
+#include <alloca.h>
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (double))) >= 0)];
-test_array [0] = 0
-
+char *p = (char *) alloca (2 * sizeof (int));
+			  if (p) return 0;
   ;
   return 0;
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_lo=0 ac_mid=0
-  while :; do
-    cat >conftest.$ac_ext <<_ACEOF
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_working_alloca_h=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_working_alloca_h=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_working_alloca_h" >&5
+echo "${ECHO_T}$ac_cv_working_alloca_h" >&6; }
+if test $ac_cv_working_alloca_h = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_ALLOCA_H 1
+_ACEOF
+
+fi
+
+{ echo "$as_me:$LINENO: checking for alloca" >&5
+echo $ECHO_N "checking for alloca... $ECHO_C" >&6; }
+if test "${ac_cv_func_alloca_works+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-$ac_includes_default
+#ifdef __GNUC__
+# define alloca __builtin_alloca
+#else
+# ifdef _MSC_VER
+#  include <malloc.h>
+#  define alloca _alloca
+# else
+#  ifdef HAVE_ALLOCA_H
+#   include <alloca.h>
+#  else
+#   ifdef _AIX
+ #pragma alloca
+#   else
+#    ifndef alloca /* predefined by HP cc +Olibcalls */
+char *alloca ();
+#    endif
+#   endif
+#  endif
+# endif
+#endif
+
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (double))) <= $ac_mid)];
-test_array [0] = 0
-
+char *p = (char *) alloca (1);
+				    if (p) return 0;
   ;
   return 0;
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_hi=$ac_mid; break
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_func_alloca_works=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_lo=`expr $ac_mid + 1`
-		    if test $ac_lo -le $ac_mid; then
-		      ac_lo= ac_hi=
-		      break
-		    fi
-		    ac_mid=`expr 2 '*' $ac_mid + 1`
+	ac_cv_func_alloca_works=no
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-  done
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
 
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_func_alloca_works" >&5
+echo "${ECHO_T}$ac_cv_func_alloca_works" >&6; }
+
+if test $ac_cv_func_alloca_works = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_ALLOCA 1
 _ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-int
-main ()
-{
-static int test_array [1 - 2 * !(((long) (sizeof (double))) < 0)];
-test_array [0] = 0
 
-  ;
-  return 0;
-}
+else
+  # The SVR3 libPW and SVR4 libucb both contain incompatible functions
+# that cause trouble.  Some versions do not even contain alloca or
+# contain a buggy version.  If you still want to use their alloca,
+# use ar to extract alloca.o from them instead of compiling alloca.c.
+
+ALLOCA=\${LIBOBJDIR}alloca.$ac_objext
+
+cat >>confdefs.h <<\_ACEOF
+#define C_ALLOCA 1
 _ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_hi=-1 ac_mid=-1
-  while :; do
-    cat >conftest.$ac_ext <<_ACEOF
+
+
+{ echo "$as_me:$LINENO: checking whether \`alloca.c' needs Cray hooks" >&5
+echo $ECHO_N "checking whether \`alloca.c' needs Cray hooks... $ECHO_C" >&6; }
+if test "${ac_cv_os_cray+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-$ac_includes_default
-int
-main ()
-{
-static int test_array [1 - 2 * !(((long) (sizeof (double))) >= $ac_mid)];
-test_array [0] = 0
+#if defined CRAY && ! defined CRAY2
+webecray
+#else
+wenotbecray
+#endif
 
-  ;
-  return 0;
-}
 _ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_lo=$ac_mid; break
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "webecray" >/dev/null 2>&1; then
+  ac_cv_os_cray=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_hi=`expr '(' $ac_mid ')' - 1`
-		       if test $ac_mid -le $ac_hi; then
-			 ac_lo= ac_hi=
-			 break
-		       fi
-		       ac_mid=`expr 2 '*' $ac_mid`
+  ac_cv_os_cray=no
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-  done
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
+rm -f conftest*
 
-ac_lo= ac_hi=
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-# Binary search between lo and hi bounds.
-while test "x$ac_lo" != "x$ac_hi"; do
-  ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
+{ echo "$as_me:$LINENO: result: $ac_cv_os_cray" >&5
+echo "${ECHO_T}$ac_cv_os_cray" >&6; }
+if test $ac_cv_os_cray = yes; then
+  for ac_func in _getb67 GETB67 getb67; do
+    as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; }
+if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-$ac_includes_default
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$ac_func || defined __stub___$ac_func
+choke me
+#endif
+
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (double))) <= $ac_mid)];
-test_array [0] = 0
-
+return $ac_func ();
   ;
   return 0;
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_hi=$ac_mid
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  eval "$as_ac_var=yes"
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_lo=`expr '(' $ac_mid ')' + 1`
+	eval "$as_ac_var=no"
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-done
-case $ac_lo in
-?*) ac_cv_sizeof_double=$ac_lo;;
-'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (double), 77
-See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute sizeof (double), 77
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; } ;;
-esac
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+ac_res=`eval echo '${'$as_ac_var'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define CRAY_STACKSEG_END $ac_func
+_ACEOF
+
+    break
+fi
+
+  done
+fi
+
+{ echo "$as_me:$LINENO: checking stack direction for C alloca" >&5
+echo $ECHO_N "checking stack direction for C alloca... $ECHO_C" >&6; }
+if test "${ac_cv_c_stack_direction+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   if test "$cross_compiling" = yes; then
-  { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&5
-echo "$as_me: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
+  ac_cv_c_stack_direction=0
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -4521,79 +21237,74 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-long longval () { return (long) (sizeof (double)); }
-unsigned long ulongval () { return (long) (sizeof (double)); }
-#include <stdio.h>
-#include <stdlib.h>
 int
-main ()
+find_stack_direction ()
 {
-
-  FILE *f = fopen ("conftest.val", "w");
-  if (! f)
-    exit (1);
-  if (((long) (sizeof (double))) < 0)
+  static char *addr = 0;
+  auto char dummy;
+  if (addr == 0)
     {
-      long i = longval ();
-      if (i != ((long) (sizeof (double))))
-	exit (1);
-      fprintf (f, "%ld\n", i);
+      addr = &dummy;
+      return find_stack_direction ();
     }
   else
-    {
-      unsigned long i = ulongval ();
-      if (i != ((long) (sizeof (double))))
-	exit (1);
-      fprintf (f, "%lu\n", i);
-    }
-  exit (ferror (f) || fclose (f) != 0);
+    return (&dummy > addr) ? 1 : -1;
+}
 
-  ;
-  return 0;
+int
+main ()
+{
+  return find_stack_direction () < 0;
 }
 _ACEOF
 rm -f conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>&5
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  ac_cv_sizeof_double=`cat conftest.val`
+  ac_cv_c_stack_direction=1
 else
   echo "$as_me: program exited with status $ac_status" >&5
 echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
 ( exit $ac_status )
-{ { echo "$as_me:$LINENO: error: cannot compute sizeof (double), 77
-See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute sizeof (double), 77
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
-fi
-rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
-fi
+ac_cv_c_stack_direction=-1
 fi
-rm -f conftest.val
-else
-  ac_cv_sizeof_double=0
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
 fi
+
+
 fi
-echo "$as_me:$LINENO: result: $ac_cv_sizeof_double" >&5
-echo "${ECHO_T}$ac_cv_sizeof_double" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_c_stack_direction" >&5
+echo "${ECHO_T}$ac_cv_c_stack_direction" >&6; }
+
 cat >>confdefs.h <<_ACEOF
-#define SIZEOF_DOUBLE $ac_cv_sizeof_double
+#define STACK_DIRECTION $ac_cv_c_stack_direction
 _ACEOF
 
 
-echo "$as_me:$LINENO: checking for long double" >&5
-echo $ECHO_N "checking for long double... $ECHO_C" >&6
-if test "${ac_cv_type_long_double+set}" = set; then
+fi
+
+
+{ echo "$as_me:$LINENO: checking for double" >&5
+echo $ECHO_N "checking for double... $ECHO_C" >&6; }
+if test "${ac_cv_type_double+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
@@ -4603,61 +21314,57 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
+typedef double ac__type_new_;
 int
 main ()
 {
-if ((long double *) 0)
+if ((ac__type_new_ *) 0)
   return 0;
-if (sizeof (long double))
+if (sizeof (ac__type_new_))
   return 0;
   ;
   return 0;
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_cv_type_long_double=yes
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_type_double=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_cv_type_long_double=no
+	ac_cv_type_double=no
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-echo "$as_me:$LINENO: result: $ac_cv_type_long_double" >&5
-echo "${ECHO_T}$ac_cv_type_long_double" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_type_double" >&5
+echo "${ECHO_T}$ac_cv_type_double" >&6; }
 
-echo "$as_me:$LINENO: checking size of long double" >&5
-echo $ECHO_N "checking size of long double... $ECHO_C" >&6
-if test "${ac_cv_sizeof_long_double+set}" = set; then
+# The cast to long int works around a bug in the HP C Compiler
+# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
+# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
+# This bug is HP SR number 8606223364.
+{ echo "$as_me:$LINENO: checking size of double" >&5
+echo $ECHO_N "checking size of double... $ECHO_C" >&6; }
+if test "${ac_cv_sizeof_double+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  if test "$ac_cv_type_long_double" = yes; then
-  # The cast to unsigned long works around a bug in the HP C Compiler
-  # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
-  # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
-  # This bug is HP SR number 8606223364.
   if test "$cross_compiling" = yes; then
   # Depending upon the size, compute the lo and hi bounds.
 cat >conftest.$ac_ext <<_ACEOF
@@ -4667,10 +21374,11 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
+   typedef double ac__type_sizeof_;
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (long double))) >= 0)];
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= 0)];
 test_array [0] = 0
 
   ;
@@ -4678,27 +21386,22 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_lo=0 ac_mid=0
   while :; do
     cat >conftest.$ac_ext <<_ACEOF
@@ -4708,10 +21411,11 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
+   typedef double ac__type_sizeof_;
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (long double))) <= $ac_mid)];
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)];
 test_array [0] = 0
 
   ;
@@ -4719,56 +21423,53 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_hi=$ac_mid; break
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_lo=`expr $ac_mid + 1`
-		    if test $ac_lo -le $ac_mid; then
-		      ac_lo= ac_hi=
-		      break
-		    fi
-		    ac_mid=`expr 2 '*' $ac_mid + 1`
+	ac_lo=`expr $ac_mid + 1`
+			if test $ac_lo -le $ac_mid; then
+			  ac_lo= ac_hi=
+			  break
+			fi
+			ac_mid=`expr 2 '*' $ac_mid + 1`
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   done
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-cat >conftest.$ac_ext <<_ACEOF
+	cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
+   typedef double ac__type_sizeof_;
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (long double))) < 0)];
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) < 0)];
 test_array [0] = 0
 
   ;
@@ -4776,27 +21477,22 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_hi=-1 ac_mid=-1
   while :; do
     cat >conftest.$ac_ext <<_ACEOF
@@ -4806,10 +21502,11 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
+   typedef double ac__type_sizeof_;
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (long double))) >= $ac_mid)];
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= $ac_mid)];
 test_array [0] = 0
 
   ;
@@ -4817,50 +21514,48 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_lo=$ac_mid; break
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_hi=`expr '(' $ac_mid ')' - 1`
-		       if test $ac_mid -le $ac_hi; then
-			 ac_lo= ac_hi=
-			 break
-		       fi
-		       ac_mid=`expr 2 '*' $ac_mid`
+	ac_hi=`expr '(' $ac_mid ')' - 1`
+			if test $ac_mid -le $ac_hi; then
+			  ac_lo= ac_hi=
+			  break
+			fi
+			ac_mid=`expr 2 '*' $ac_mid`
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   done
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_lo= ac_hi=
+	ac_lo= ac_hi=
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 # Binary search between lo and hi bounds.
 while test "x$ac_lo" != "x$ac_hi"; do
   ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
@@ -4871,10 +21566,11 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
+   typedef double ac__type_sizeof_;
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (long double))) <= $ac_mid)];
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)];
 test_array [0] = 0
 
   ;
@@ -4882,52 +21578,45 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_hi=$ac_mid
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_lo=`expr '(' $ac_mid ')' + 1`
+	ac_lo=`expr '(' $ac_mid ')' + 1`
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 done
 case $ac_lo in
-?*) ac_cv_sizeof_long_double=$ac_lo;;
-'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (long double), 77
+?*) ac_cv_sizeof_double=$ac_lo;;
+'') if test "$ac_cv_type_double" = yes; then
+     { { echo "$as_me:$LINENO: error: cannot compute sizeof (double)
 See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute sizeof (long double), 77
+echo "$as_me: error: cannot compute sizeof (double)
 See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; } ;;
+   { (exit 77); exit 77; }; }
+   else
+     ac_cv_sizeof_double=0
+   fi ;;
 esac
 else
-  if test "$cross_compiling" = yes; then
-  { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&5
-echo "$as_me: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
-else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -4935,8 +21624,9 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-long longval () { return (long) (sizeof (long double)); }
-unsigned long ulongval () { return (long) (sizeof (long double)); }
+   typedef double ac__type_sizeof_;
+static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); }
+static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); }
 #include <stdio.h>
 #include <stdlib.h>
 int
@@ -4945,141 +21635,81 @@
 
   FILE *f = fopen ("conftest.val", "w");
   if (! f)
-    exit (1);
-  if (((long) (sizeof (long double))) < 0)
+    return 1;
+  if (((long int) (sizeof (ac__type_sizeof_))) < 0)
     {
-      long i = longval ();
-      if (i != ((long) (sizeof (long double))))
-	exit (1);
+      long int i = longval ();
+      if (i != ((long int) (sizeof (ac__type_sizeof_))))
+	return 1;
       fprintf (f, "%ld\n", i);
     }
   else
     {
-      unsigned long i = ulongval ();
-      if (i != ((long) (sizeof (long double))))
-	exit (1);
+      unsigned long int i = ulongval ();
+      if (i != ((long int) (sizeof (ac__type_sizeof_))))
+	return 1;
       fprintf (f, "%lu\n", i);
     }
-  exit (ferror (f) || fclose (f) != 0);
+  return ferror (f) || fclose (f) != 0;
 
   ;
   return 0;
 }
 _ACEOF
 rm -f conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>&5
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  ac_cv_sizeof_long_double=`cat conftest.val`
+  ac_cv_sizeof_double=`cat conftest.val`
 else
   echo "$as_me: program exited with status $ac_status" >&5
 echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
 ( exit $ac_status )
-{ { echo "$as_me:$LINENO: error: cannot compute sizeof (long double), 77
+if test "$ac_cv_type_double" = yes; then
+     { { echo "$as_me:$LINENO: error: cannot compute sizeof (double)
 See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute sizeof (long double), 77
+echo "$as_me: error: cannot compute sizeof (double)
 See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
-fi
-rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+   { (exit 77); exit 77; }; }
+   else
+     ac_cv_sizeof_double=0
+   fi
 fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
 fi
 rm -f conftest.val
-else
-  ac_cv_sizeof_long_double=0
-fi
-fi
-echo "$as_me:$LINENO: result: $ac_cv_sizeof_long_double" >&5
-echo "${ECHO_T}$ac_cv_sizeof_long_double" >&6
-cat >>confdefs.h <<_ACEOF
-#define SIZEOF_LONG_DOUBLE $ac_cv_sizeof_long_double
-_ACEOF
-
-
-
-# Also AC_SUBST this variable for ffi.h.
-HAVE_LONG_DOUBLE=0
-if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
-  if test $ac_cv_sizeof_long_double != 0; then
-    HAVE_LONG_DOUBLE=1
-
-cat >>confdefs.h <<\_ACEOF
-#define HAVE_LONG_DOUBLE 1
-_ACEOF
-
-  fi
 fi
+{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_double" >&5
+echo "${ECHO_T}$ac_cv_sizeof_double" >&6; }
 
 
-echo "$as_me:$LINENO: checking for _Bool support" >&5
-echo $ECHO_N "checking for _Bool support... $ECHO_C" >&6
-have_c99_bool=no
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-
-int
-main ()
-{
-_Bool x; x = (_Bool)0;
-  ;
-  return 0;
-}
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-
 
-cat >>confdefs.h <<\_ACEOF
-#define HAVE_C99_BOOL 1
+cat >>confdefs.h <<_ACEOF
+#define SIZEOF_DOUBLE $ac_cv_sizeof_double
 _ACEOF
 
-  have_c99_bool=yes
-
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
 
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $have_c99_bool" >&5
-echo "${ECHO_T}$have_c99_bool" >&6
-if test "$have_c99_bool" = yes ; then
-echo "$as_me:$LINENO: checking for _Bool" >&5
-echo $ECHO_N "checking for _Bool... $ECHO_C" >&6
-if test "${ac_cv_type__Bool+set}" = set; then
+{ echo "$as_me:$LINENO: checking for long double" >&5
+echo $ECHO_N "checking for long double... $ECHO_C" >&6; }
+if test "${ac_cv_type_long_double+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
@@ -5089,61 +21719,57 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
+typedef long double ac__type_new_;
 int
 main ()
 {
-if ((_Bool *) 0)
+if ((ac__type_new_ *) 0)
   return 0;
-if (sizeof (_Bool))
+if (sizeof (ac__type_new_))
   return 0;
   ;
   return 0;
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_cv_type__Bool=yes
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_type_long_double=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_cv_type__Bool=no
+	ac_cv_type_long_double=no
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-echo "$as_me:$LINENO: result: $ac_cv_type__Bool" >&5
-echo "${ECHO_T}$ac_cv_type__Bool" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_type_long_double" >&5
+echo "${ECHO_T}$ac_cv_type_long_double" >&6; }
 
-echo "$as_me:$LINENO: checking size of _Bool" >&5
-echo $ECHO_N "checking size of _Bool... $ECHO_C" >&6
-if test "${ac_cv_sizeof__Bool+set}" = set; then
+# The cast to long int works around a bug in the HP C Compiler
+# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
+# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
+# This bug is HP SR number 8606223364.
+{ echo "$as_me:$LINENO: checking size of long double" >&5
+echo $ECHO_N "checking size of long double... $ECHO_C" >&6; }
+if test "${ac_cv_sizeof_long_double+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-  if test "$ac_cv_type__Bool" = yes; then
-  # The cast to unsigned long works around a bug in the HP C Compiler
-  # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
-  # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
-  # This bug is HP SR number 8606223364.
   if test "$cross_compiling" = yes; then
   # Depending upon the size, compute the lo and hi bounds.
 cat >conftest.$ac_ext <<_ACEOF
@@ -5153,10 +21779,11 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
+   typedef long double ac__type_sizeof_;
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (_Bool))) >= 0)];
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= 0)];
 test_array [0] = 0
 
   ;
@@ -5164,27 +21791,22 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_lo=0 ac_mid=0
   while :; do
     cat >conftest.$ac_ext <<_ACEOF
@@ -5194,10 +21816,11 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
+   typedef long double ac__type_sizeof_;
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (_Bool))) <= $ac_mid)];
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)];
 test_array [0] = 0
 
   ;
@@ -5205,56 +21828,53 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_hi=$ac_mid; break
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_lo=`expr $ac_mid + 1`
-		    if test $ac_lo -le $ac_mid; then
-		      ac_lo= ac_hi=
-		      break
-		    fi
-		    ac_mid=`expr 2 '*' $ac_mid + 1`
+	ac_lo=`expr $ac_mid + 1`
+			if test $ac_lo -le $ac_mid; then
+			  ac_lo= ac_hi=
+			  break
+			fi
+			ac_mid=`expr 2 '*' $ac_mid + 1`
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   done
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-cat >conftest.$ac_ext <<_ACEOF
+	cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
+   typedef long double ac__type_sizeof_;
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (_Bool))) < 0)];
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) < 0)];
 test_array [0] = 0
 
   ;
@@ -5262,27 +21882,22 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_hi=-1 ac_mid=-1
   while :; do
     cat >conftest.$ac_ext <<_ACEOF
@@ -5292,10 +21907,11 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
+   typedef long double ac__type_sizeof_;
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (_Bool))) >= $ac_mid)];
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= $ac_mid)];
 test_array [0] = 0
 
   ;
@@ -5303,50 +21919,48 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_lo=$ac_mid; break
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_hi=`expr '(' $ac_mid ')' - 1`
-		       if test $ac_mid -le $ac_hi; then
-			 ac_lo= ac_hi=
-			 break
-		       fi
-		       ac_mid=`expr 2 '*' $ac_mid`
+	ac_hi=`expr '(' $ac_mid ')' - 1`
+			if test $ac_mid -le $ac_hi; then
+			  ac_lo= ac_hi=
+			  break
+			fi
+			ac_mid=`expr 2 '*' $ac_mid`
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   done
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_lo= ac_hi=
+	ac_lo= ac_hi=
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 # Binary search between lo and hi bounds.
 while test "x$ac_lo" != "x$ac_hi"; do
   ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
@@ -5357,10 +21971,11 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
+   typedef long double ac__type_sizeof_;
 int
 main ()
 {
-static int test_array [1 - 2 * !(((long) (sizeof (_Bool))) <= $ac_mid)];
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)];
 test_array [0] = 0
 
   ;
@@ -5368,52 +21983,45 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_hi=$ac_mid
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_lo=`expr '(' $ac_mid ')' + 1`
+	ac_lo=`expr '(' $ac_mid ')' + 1`
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 done
 case $ac_lo in
-?*) ac_cv_sizeof__Bool=$ac_lo;;
-'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (_Bool), 77
+?*) ac_cv_sizeof_long_double=$ac_lo;;
+'') if test "$ac_cv_type_long_double" = yes; then
+     { { echo "$as_me:$LINENO: error: cannot compute sizeof (long double)
 See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute sizeof (_Bool), 77
+echo "$as_me: error: cannot compute sizeof (long double)
 See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; } ;;
+   { (exit 77); exit 77; }; }
+   else
+     ac_cv_sizeof_long_double=0
+   fi ;;
 esac
 else
-  if test "$cross_compiling" = yes; then
-  { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&5
-echo "$as_me: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
-else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -5421,8 +22029,9 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-long longval () { return (long) (sizeof (_Bool)); }
-unsigned long ulongval () { return (long) (sizeof (_Bool)); }
+   typedef long double ac__type_sizeof_;
+static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); }
+static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); }
 #include <stdio.h>
 #include <stdlib.h>
 int
@@ -5431,70 +22040,97 @@
 
   FILE *f = fopen ("conftest.val", "w");
   if (! f)
-    exit (1);
-  if (((long) (sizeof (_Bool))) < 0)
+    return 1;
+  if (((long int) (sizeof (ac__type_sizeof_))) < 0)
     {
-      long i = longval ();
-      if (i != ((long) (sizeof (_Bool))))
-	exit (1);
+      long int i = longval ();
+      if (i != ((long int) (sizeof (ac__type_sizeof_))))
+	return 1;
       fprintf (f, "%ld\n", i);
     }
   else
     {
-      unsigned long i = ulongval ();
-      if (i != ((long) (sizeof (_Bool))))
-	exit (1);
+      unsigned long int i = ulongval ();
+      if (i != ((long int) (sizeof (ac__type_sizeof_))))
+	return 1;
       fprintf (f, "%lu\n", i);
     }
-  exit (ferror (f) || fclose (f) != 0);
+  return ferror (f) || fclose (f) != 0;
 
   ;
   return 0;
 }
 _ACEOF
 rm -f conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>&5
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  ac_cv_sizeof__Bool=`cat conftest.val`
+  ac_cv_sizeof_long_double=`cat conftest.val`
 else
   echo "$as_me: program exited with status $ac_status" >&5
 echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
 ( exit $ac_status )
-{ { echo "$as_me:$LINENO: error: cannot compute sizeof (_Bool), 77
+if test "$ac_cv_type_long_double" = yes; then
+     { { echo "$as_me:$LINENO: error: cannot compute sizeof (long double)
 See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute sizeof (_Bool), 77
+echo "$as_me: error: cannot compute sizeof (long double)
 See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
-fi
-rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+   { (exit 77); exit 77; }; }
+   else
+     ac_cv_sizeof_long_double=0
+   fi
 fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
 fi
 rm -f conftest.val
-else
-  ac_cv_sizeof__Bool=0
 fi
-fi
-echo "$as_me:$LINENO: result: $ac_cv_sizeof__Bool" >&5
-echo "${ECHO_T}$ac_cv_sizeof__Bool" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_long_double" >&5
+echo "${ECHO_T}$ac_cv_sizeof_long_double" >&6; }
+
+
+
 cat >>confdefs.h <<_ACEOF
-#define SIZEOF__BOOL $ac_cv_sizeof__Bool
+#define SIZEOF_LONG_DOUBLE $ac_cv_sizeof_long_double
 _ACEOF
 
 
+
+# Also AC_SUBST this variable for ffi.h.
+if test -z "$HAVE_LONG_DOUBLE"; then
+  HAVE_LONG_DOUBLE=0
+  if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
+    if test $ac_cv_sizeof_long_double != 0; then
+      HAVE_LONG_DOUBLE=1
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_LONG_DOUBLE 1
+_ACEOF
+
+    fi
+  fi
 fi
 
-echo "$as_me:$LINENO: checking whether byte ordering is bigendian" >&5
-echo $ECHO_N "checking whether byte ordering is bigendian... $ECHO_C" >&6
+
+{ echo "$as_me:$LINENO: checking whether byte ordering is bigendian" >&5
+echo $ECHO_N "checking whether byte ordering is bigendian... $ECHO_C" >&6; }
 if test "${ac_cv_c_bigendian+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
@@ -5511,7 +22147,8 @@
 int
 main ()
 {
-#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
+#if  ! (defined BYTE_ORDER && defined BIG_ENDIAN && defined LITTLE_ENDIAN \
+	&& BYTE_ORDER && BIG_ENDIAN && LITTLE_ENDIAN)
  bogus endian macros
 #endif
 
@@ -5520,27 +22157,22 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   # It does; now see whether it defined to BIG_ENDIAN or not.
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -5563,40 +22195,36 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_c_bigendian=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-ac_cv_c_bigendian=no
+	ac_cv_c_bigendian=no
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-# It does not; compile a test program.
+	# It does not; compile a test program.
 if test "$cross_compiling" = yes; then
   # try to guess the endianness by grepping values into an object file
   ac_cv_c_bigendian=unknown
@@ -5606,11 +22234,11 @@
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
-short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
+short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
+short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
 void _ascii () { char *s = (char *) ascii_mm; s = (char *) ascii_ii; }
-short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
-short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
+short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
+short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
 void _ebcdic () { char *s = (char *) ebcdic_mm; s = (char *) ebcdic_ii; }
 int
 main ()
@@ -5621,27 +22249,22 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   if grep BIGenDianSyS conftest.$ac_objext >/dev/null ; then
   ac_cv_c_bigendian=yes
 fi
@@ -5657,8 +22280,10 @@
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
+
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -5666,27 +22291,41 @@
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
+$ac_includes_default
 int
 main ()
 {
+
   /* Are we little or big endian?  From Harbison&Steele.  */
   union
   {
-    long l;
-    char c[sizeof (long)];
+    long int l;
+    char c[sizeof (long int)];
   } u;
   u.l = 1;
-  exit (u.c[sizeof (long) - 1] == 1);
+  return u.c[sizeof (long int) - 1] == 1;
+
+  ;
+  return 0;
 }
 _ACEOF
 rm -f conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>&5
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
@@ -5699,13 +22338,16 @@
 ( exit $ac_status )
 ac_cv_c_bigendian=yes
 fi
-rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
 fi
+
+
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-echo "$as_me:$LINENO: result: $ac_cv_c_bigendian" >&5
-echo "${ECHO_T}$ac_cv_c_bigendian" >&6
+{ echo "$as_me:$LINENO: result: $ac_cv_c_bigendian" >&5
+echo "${ECHO_T}$ac_cv_c_bigendian" >&6; }
 case $ac_cv_c_bigendian in
   yes)
 
@@ -5724,12 +22366,69 @@
 esac
 
 
+{ echo "$as_me:$LINENO: checking assembler .cfi pseudo-op support" >&5
+echo $ECHO_N "checking assembler .cfi pseudo-op support... $ECHO_C" >&6; }
+if test "${libffi_cv_as_cfi_pseudo_op+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+    libffi_cv_as_cfi_pseudo_op=unknown
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+asm (".cfi_startproc\n\t.cfi_endproc");
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  libffi_cv_as_cfi_pseudo_op=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	libffi_cv_as_cfi_pseudo_op=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ echo "$as_me:$LINENO: result: $libffi_cv_as_cfi_pseudo_op" >&5
+echo "${ECHO_T}$libffi_cv_as_cfi_pseudo_op" >&6; }
+if test "x$libffi_cv_as_cfi_pseudo_op" = xyes; then
 
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_AS_CFI_PSEUDO_OP 1
+_ACEOF
 
+fi
 
 if test x$TARGET = xSPARC; then
-    echo "$as_me:$LINENO: checking assembler and linker support unaligned pc related relocs" >&5
-echo $ECHO_N "checking assembler and linker support unaligned pc related relocs... $ECHO_C" >&6
+    { echo "$as_me:$LINENO: checking assembler and linker support unaligned pc related relocs" >&5
+echo $ECHO_N "checking assembler and linker support unaligned pc related relocs... $ECHO_C" >&6; }
 if test "${libffi_cv_as_sparc_ua_pcrel+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
@@ -5754,41 +22453,38 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>conftest.er1
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest$ac_exeext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
   libffi_cv_as_sparc_ua_pcrel=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-libffi_cv_as_sparc_ua_pcrel=no
+	libffi_cv_as_sparc_ua_pcrel=no
 fi
-rm -f conftest.err conftest.$ac_objext \
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
       conftest$ac_exeext conftest.$ac_ext
 	CFLAGS="$save_CFLAGS"
 	LDFLAGS="$save_LDFLAGS"
 fi
-echo "$as_me:$LINENO: result: $libffi_cv_as_sparc_ua_pcrel" >&5
-echo "${ECHO_T}$libffi_cv_as_sparc_ua_pcrel" >&6
+{ echo "$as_me:$LINENO: result: $libffi_cv_as_sparc_ua_pcrel" >&5
+echo "${ECHO_T}$libffi_cv_as_sparc_ua_pcrel" >&6; }
     if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
 
 cat >>confdefs.h <<\_ACEOF
@@ -5797,8 +22493,8 @@
 
     fi
 
-    echo "$as_me:$LINENO: checking assembler .register pseudo-op support" >&5
-echo $ECHO_N "checking assembler .register pseudo-op support... $ECHO_C" >&6
+    { echo "$as_me:$LINENO: checking assembler .register pseudo-op support" >&5
+echo $ECHO_N "checking assembler .register pseudo-op support... $ECHO_C" >&6; }
 if test "${libffi_cv_as_register_pseudo_op+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
@@ -5821,39 +22517,35 @@
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   libffi_cv_as_register_pseudo_op=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-libffi_cv_as_register_pseudo_op=no
+	libffi_cv_as_register_pseudo_op=no
 fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 fi
-echo "$as_me:$LINENO: result: $libffi_cv_as_register_pseudo_op" >&5
-echo "${ECHO_T}$libffi_cv_as_register_pseudo_op" >&6
+{ echo "$as_me:$LINENO: result: $libffi_cv_as_register_pseudo_op" >&5
+echo "${ECHO_T}$libffi_cv_as_register_pseudo_op" >&6; }
     if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
 
 cat >>confdefs.h <<\_ACEOF
@@ -5863,8 +22555,8 @@
     fi
 fi
 
-echo "$as_me:$LINENO: checking whether .eh_frame section should be read-only" >&5
-echo $ECHO_N "checking whether .eh_frame section should be read-only... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking whether .eh_frame section should be read-only" >&5
+echo $ECHO_N "checking whether .eh_frame section should be read-only... $ECHO_C" >&6; }
 if test "${libffi_cv_ro_eh_frame+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
@@ -5882,8 +22574,8 @@
 	rm -f conftest.*
 
 fi
-echo "$as_me:$LINENO: result: $libffi_cv_ro_eh_frame" >&5
-echo "${ECHO_T}$libffi_cv_ro_eh_frame" >&6
+{ echo "$as_me:$LINENO: result: $libffi_cv_ro_eh_frame" >&5
+echo "${ECHO_T}$libffi_cv_ro_eh_frame" >&6; }
 if test "x$libffi_cv_ro_eh_frame" = xyes; then
 
 cat >>confdefs.h <<\_ACEOF
@@ -5903,8 +22595,8 @@
 
 fi
 
-echo "$as_me:$LINENO: checking for __attribute__((visibility(\"hidden\")))" >&5
-echo $ECHO_N "checking for __attribute__((visibility(\"hidden\")))... $ECHO_C" >&6
+{ echo "$as_me:$LINENO: checking for __attribute__((visibility(\"hidden\")))" >&5
+echo $ECHO_N "checking for __attribute__((visibility(\"hidden\")))... $ECHO_C" >&6; }
 if test "${libffi_cv_hidden_visibility_attribute+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
@@ -5923,51 +22615,110 @@
 	fi
 	rm -f conftest.*
 
-fi
-echo "$as_me:$LINENO: result: $libffi_cv_hidden_visibility_attribute" >&5
-echo "${ECHO_T}$libffi_cv_hidden_visibility_attribute" >&6
-if test $libffi_cv_hidden_visibility_attribute = yes; then
+fi
+{ echo "$as_me:$LINENO: result: $libffi_cv_hidden_visibility_attribute" >&5
+echo "${ECHO_T}$libffi_cv_hidden_visibility_attribute" >&6; }
+if test $libffi_cv_hidden_visibility_attribute = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_HIDDEN_VISIBILITY_ATTRIBUTE 1
+_ACEOF
+
+fi
+
+
+
+
+
+
+
+
+
+# Check whether --enable-debug was given.
+if test "${enable_debug+set}" = set; then
+  enableval=$enable_debug; if test "$enable_debug" = "yes"; then
 
 cat >>confdefs.h <<\_ACEOF
-#define HAVE_HIDDEN_VISIBILITY_ATTRIBUTE 1
+#define FFI_DEBUG 1
 _ACEOF
 
+  fi
 fi
 
 
+# Check whether --enable-structs was given.
+if test "${enable_structs+set}" = set; then
+  enableval=$enable_structs; if test "$enable_structs" = "no"; then
 
+cat >>confdefs.h <<\_ACEOF
+#define FFI_NO_STRUCTS 1
+_ACEOF
 
+  fi
+fi
 
 
+# Check whether --enable-raw-api was given.
+if test "${enable_raw_api+set}" = set; then
+  enableval=$enable_raw_api; if test "$enable_raw_api" = "no"; then
 
+cat >>confdefs.h <<\_ACEOF
+#define FFI_NO_RAW_API 1
+_ACEOF
 
+  fi
+fi
 
 
+# Check whether --enable-purify-safety was given.
+if test "${enable_purify_safety+set}" = set; then
+  enableval=$enable_purify_safety; if test "$enable_purify_safety" = "yes"; then
 
 cat >>confdefs.h <<\_ACEOF
-#define FFI_NO_RAW_API 1
+#define USING_PURIFY 1
 _ACEOF
 
+  fi
+fi
+
 
-          ac_config_commands="$ac_config_commands include"
+if test -n "$with_cross_host" &&
+   test x"$with_cross_host" != x"no"; then
+  toolexecdir='$(exec_prefix)/$(target_alias)'
+  toolexeclibdir='$(toolexecdir)/lib'
+else
+  toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+  toolexeclibdir='$(libdir)'
+fi
+multi_os_directory=`$CC -print-multi-os-directory`
+case $multi_os_directory in
+  .) ;; # Avoid trailing /.
+  *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
+esac
 
-          ac_config_commands="$ac_config_commands src"
 
 
-TARGETINCDIR=$TARGETDIR
-case $host in
-*-*-darwin*)
-   TARGETINCDIR="darwin"
-   ;;
-esac
+if test "${multilib}" = "yes"; then
+  multilib_arg="--enable-multilib"
+else
+  multilib_arg=
+fi
+
+ac_config_commands="$ac_config_commands include"
 
+ac_config_commands="$ac_config_commands src"
 
-          ac_config_links="$ac_config_links include/ffitarget.h:src/$TARGETINCDIR/ffitarget.h"
 
-          ac_config_links="$ac_config_links include/ffi_common.h:include/ffi_common.h"
+ac_config_links="$ac_config_links include/ffitarget.h:src/$TARGETDIR/ffitarget.h"
 
 
-                    ac_config_files="$ac_config_files include/ffi.h fficonfig.py"
+ac_config_files="$ac_config_files include/ffi.h"
+
+
+ac_config_links="$ac_config_links include/ffi_common.h:include/ffi_common.h"
+
+
+ac_config_files="$ac_config_files fficonfig.py"
 
 
 cat >confcache <<\_ACEOF
@@ -5988,39 +22739,58 @@
 
 # The following way of writing the cache mishandles newlines in values,
 # but we know of no workaround that is simple, portable, and efficient.
-# So, don't put newlines in cache variables' values.
+# So, we kill variables containing newlines.
 # Ultrix sh set writes to stderr and can't be redirected directly,
 # and sets the high bit in the cache file unless we assign to the vars.
-{
+(
+  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5
+echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      *) $as_unset $ac_var ;;
+      esac ;;
+    esac
+  done
+
   (set) 2>&1 |
-    case `(ac_space=' '; set | grep ac_space) 2>&1` in
-    *ac_space=\ *)
+    case $as_nl`(ac_space=' '; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
       # `set' does not quote correctly, so add quotes (double-quote
       # substitution turns \\\\ into \\, and sed turns \\ into \).
       sed -n \
 	"s/'/'\\\\''/g;
 	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
-      ;;
+      ;; #(
     *)
       # `set' quotes correctly as required by POSIX, so do not add quotes.
-      sed -n \
-	"s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
       ;;
-    esac;
-} |
+    esac |
+    sort
+) |
   sed '
+     /^ac_cv_env_/b end
      t clear
-     : clear
+     :clear
      s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
      t end
-     /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
-     : end' >>confcache
-if diff $cache_file confcache >/dev/null 2>&1; then :; else
-  if test -w $cache_file; then
-    test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file"
+     s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+     :end' >>confcache
+if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
+  if test -w "$cache_file"; then
+    test "x$cache_file" != "x/dev/null" &&
+      { echo "$as_me:$LINENO: updating cache $cache_file" >&5
+echo "$as_me: updating cache $cache_file" >&6;}
     cat confcache >$cache_file
   else
-    echo "not updating unwritable cache $cache_file"
+    { echo "$as_me:$LINENO: not updating unwritable cache $cache_file" >&5
+echo "$as_me: not updating unwritable cache $cache_file" >&6;}
   fi
 fi
 rm -f confcache
@@ -6029,38 +22799,234 @@
 # Let make expand exec_prefix.
 test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
 
-# VPATH may cause trouble with some makes, so we remove $(srcdir),
-# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
-# trailing colons and then remove the whole line if VPATH becomes empty
-# (actually we leave an empty line to preserve line numbers).
-if test "x$srcdir" = x.; then
-  ac_vpsub='/^[	 ]*VPATH[	 ]*=/{
-s/:*\$(srcdir):*/:/;
-s/:*\${srcdir}:*/:/;
-s/:*@srcdir@:*/:/;
-s/^\([^=]*=[	 ]*\):*/\1/;
-s/:*$//;
-s/^[^=]*=[	 ]*$//;
-}'
-fi
-
 DEFS=-DHAVE_CONFIG_H
 
 ac_libobjs=
 ac_ltlibobjs=
 for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
   # 1. Remove the extension, and $U if already installed.
-  ac_i=`echo "$ac_i" |
-	 sed 's/\$U\././;s/\.o$//;s/\.obj$//'`
-  # 2. Add them.
-  ac_libobjs="$ac_libobjs $ac_i\$U.$ac_objext"
-  ac_ltlibobjs="$ac_ltlibobjs $ac_i"'$U.lo'
+  ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
+  ac_i=`echo "$ac_i" | sed "$ac_script"`
+  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
+  #    will be set to the directory where LIBOBJS objects are built.
+  ac_libobjs="$ac_libobjs \${LIBOBJDIR}$ac_i\$U.$ac_objext"
+  ac_ltlibobjs="$ac_ltlibobjs \${LIBOBJDIR}$ac_i"'$U.lo'
 done
 LIBOBJS=$ac_libobjs
 
 LTLIBOBJS=$ac_ltlibobjs
 
 
+if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"AMDEP\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"AMDEP\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"am__fastdepCC\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"am__fastdepCC\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${am__fastdepCCAS_TRUE}" && test -z "${am__fastdepCCAS_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"am__fastdepCCAS\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"am__fastdepCCAS\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"am__fastdepCXX\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"am__fastdepCXX\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"MAINTAINER_MODE\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"MAINTAINER_MODE\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${TESTSUBDIR_TRUE}" && test -z "${TESTSUBDIR_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"TESTSUBDIR\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"TESTSUBDIR\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${MIPS_TRUE}" && test -z "${MIPS_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"MIPS\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"MIPS\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${SPARC_TRUE}" && test -z "${SPARC_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"SPARC\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"SPARC\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${X86_TRUE}" && test -z "${X86_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"X86\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"X86\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${X86_FREEBSD_TRUE}" && test -z "${X86_FREEBSD_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"X86_FREEBSD\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"X86_FREEBSD\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${X86_WIN32_TRUE}" && test -z "${X86_WIN32_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"X86_WIN32\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"X86_WIN32\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${X86_DARWIN_TRUE}" && test -z "${X86_DARWIN_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"X86_DARWIN\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"X86_DARWIN\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${ALPHA_TRUE}" && test -z "${ALPHA_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"ALPHA\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"ALPHA\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${IA64_TRUE}" && test -z "${IA64_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"IA64\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"IA64\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${M32R_TRUE}" && test -z "${M32R_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"M32R\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"M32R\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${M68K_TRUE}" && test -z "${M68K_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"M68K\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"M68K\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${POWERPC_TRUE}" && test -z "${POWERPC_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"POWERPC\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"POWERPC\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${POWERPC_AIX_TRUE}" && test -z "${POWERPC_AIX_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"POWERPC_AIX\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"POWERPC_AIX\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${POWERPC_DARWIN_TRUE}" && test -z "${POWERPC_DARWIN_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"POWERPC_DARWIN\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"POWERPC_DARWIN\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${POWERPC_FREEBSD_TRUE}" && test -z "${POWERPC_FREEBSD_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"POWERPC_FREEBSD\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"POWERPC_FREEBSD\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${ARM_TRUE}" && test -z "${ARM_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"ARM\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"ARM\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${LIBFFI_CRIS_TRUE}" && test -z "${LIBFFI_CRIS_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"LIBFFI_CRIS\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"LIBFFI_CRIS\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${FRV_TRUE}" && test -z "${FRV_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"FRV\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"FRV\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${S390_TRUE}" && test -z "${S390_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"S390\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"S390\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${X86_64_TRUE}" && test -z "${X86_64_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"X86_64\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"X86_64\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${SH_TRUE}" && test -z "${SH_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"SH\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"SH\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${SH64_TRUE}" && test -z "${SH64_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"SH64\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"SH64\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${PA_LINUX_TRUE}" && test -z "${PA_LINUX_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"PA_LINUX\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"PA_LINUX\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${PA_HPUX_TRUE}" && test -z "${PA_HPUX_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"PA_HPUX\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"PA_HPUX\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${PA64_HPUX_TRUE}" && test -z "${PA64_HPUX_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"PA64_HPUX\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"PA64_HPUX\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
 
 : ${CONFIG_STATUS=./config.status}
 ac_clean_files_save=$ac_clean_files
@@ -6085,17 +23051,45 @@
 ## M4sh Initialization.  ##
 ## --------------------- ##
 
-# Be Bourne compatible
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
   emulate sh
   NULLCMD=:
   # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
   # is contrary to our usage.  Disable this feature.
   alias -g '${1+"$@"}'='"$@"'
-elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
-  set -o posix
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in
+  *posix*) set -o posix ;;
+esac
+
+fi
+
+
+
+
+# PATH needs CR
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
 fi
-DUALCASE=1; export DUALCASE # for MKS sh
 
 # Support unset when possible.
 if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
@@ -6105,8 +23099,43 @@
 fi
 
 
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+as_nl='
+'
+IFS=" ""	$as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+case $0 in
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  { (exit 1); exit 1; }
+fi
+
 # Work around bugs in pre-3.0 UWIN ksh.
-$as_unset ENV MAIL MAILPATH
+for as_var in ENV MAIL MAILPATH
+do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+done
 PS1='$ '
 PS2='> '
 PS4='+ '
@@ -6120,18 +23149,19 @@
   if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
     eval $as_var=C; export $as_var
   else
-    $as_unset $as_var
+    ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
   fi
 done
 
 # Required to use basename.
-if expr a : '\(a\)' >/dev/null 2>&1; then
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
   as_expr=expr
 else
   as_expr=false
 fi
 
-if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
   as_basename=basename
 else
   as_basename=false
@@ -6139,159 +23169,120 @@
 
 
 # Name of the executable.
-as_me=`$as_basename "$0" ||
+as_me=`$as_basename -- "$0" ||
 $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
 	 X"$0" : 'X\(//\)$' \| \
-	 X"$0" : 'X\(/\)$' \| \
-	 .     : '\(.\)' 2>/dev/null ||
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
 echo X/"$0" |
-    sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
-  	  /^X\/\(\/\/\)$/{ s//\1/; q; }
-  	  /^X\/\(\/\).*/{ s//\1/; q; }
-  	  s/.*/./; q'`
-
-
-# PATH needs CR, and LINENO needs CR and PATH.
-# Avoid depending upon Character Ranges.
-as_cr_letters='abcdefghijklmnopqrstuvwxyz'
-as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-as_cr_Letters=$as_cr_letters$as_cr_LETTERS
-as_cr_digits='0123456789'
-as_cr_alnum=$as_cr_Letters$as_cr_digits
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
 
-# The user is always right.
-if test "${PATH_SEPARATOR+set}" != set; then
-  echo "#! /bin/sh" >conf$$.sh
-  echo  "exit 0"   >>conf$$.sh
-  chmod +x conf$$.sh
-  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
-    PATH_SEPARATOR=';'
-  else
-    PATH_SEPARATOR=:
-  fi
-  rm -f conf$$.sh
-fi
+# CDPATH.
+$as_unset CDPATH
 
 
-  as_lineno_1=$LINENO
-  as_lineno_2=$LINENO
-  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
-  test "x$as_lineno_1" != "x$as_lineno_2" &&
-  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
-  # Find who we are.  Look in the path if we contain no path at all
-  # relative or not.
-  case $0 in
-    *[\\/]* ) as_myself=$0 ;;
-    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
-done
 
-       ;;
-  esac
-  # We did not find ourselves, most probably we were run as `sh COMMAND'
-  # in which case we are not to be found in the path.
-  if test "x$as_myself" = x; then
-    as_myself=$0
-  fi
-  if test ! -f "$as_myself"; then
-    { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5
-echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2;}
-   { (exit 1); exit 1; }; }
-  fi
-  case $CONFIG_SHELL in
-  '')
-    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-  for as_base in sh bash ksh sh5; do
-	 case $as_dir in
-	 /*)
-	   if ("$as_dir/$as_base" -c '
   as_lineno_1=$LINENO
   as_lineno_2=$LINENO
-  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
   test "x$as_lineno_1" != "x$as_lineno_2" &&
-  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
-	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
-	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
-	     CONFIG_SHELL=$as_dir/$as_base
-	     export CONFIG_SHELL
-	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
-	   fi;;
-	 esac
-       done
-done
-;;
-  esac
+  test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || {
 
   # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
   # uniformly replaced by the line number.  The first 'sed' inserts a
-  # line-number line before each line; the second 'sed' does the real
-  # work.  The second script uses 'N' to pair each line-number line
-  # with the numbered line, and appends trailing '-' during
-  # substitution so that $LINENO is not a special case at line end.
+  # line-number line after each line using $LINENO; the second 'sed'
+  # does the real work.  The second script uses 'N' to pair each
+  # line-number line with the line containing $LINENO, and appends
+  # trailing '-' during substitution so that $LINENO is not a special
+  # case at line end.
   # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
-  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
-  sed '=' <$as_myself |
+  # scripts with optimization help from Paolo Bonzini.  Blame Lee
+  # E. McMahon (1931-1989) for sed's syntax.  :-)
+  sed -n '
+    p
+    /[$]LINENO/=
+  ' <$as_myself |
     sed '
+      s/[$]LINENO.*/&-/
+      t lineno
+      b
+      :lineno
       N
-      s,$,-,
-      : loop
-      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
+      :loop
+      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
       t loop
-      s,-$,,
-      s,^['$as_cr_digits']*\n,,
+      s/-\n.*//
     ' >$as_me.lineno &&
-  chmod +x $as_me.lineno ||
-    { { echo "$as_me:$LINENO: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&5
-echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2;}
+  chmod +x "$as_me.lineno" ||
+    { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
    { (exit 1); exit 1; }; }
 
   # Don't try to exec as it changes $[0], causing all sort of problems
   # (the dirname of $[0] is not the place where we might find the
-  # original and so on.  Autoconf is especially sensible to this).
-  . ./$as_me.lineno
+  # original and so on.  Autoconf is especially sensitive to this).
+  . "./$as_me.lineno"
   # Exit status is that of the last command.
   exit
 }
 
 
-case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
-  *c*,-n*) ECHO_N= ECHO_C='
-' ECHO_T='	' ;;
-  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
-  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in
+-n*)
+  case `echo 'x\c'` in
+  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
+  *)   ECHO_C='\c';;
+  esac;;
+*)
+  ECHO_N='-n';;
 esac
 
-if expr a : '\(a\)' >/dev/null 2>&1; then
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
   as_expr=expr
 else
   as_expr=false
 fi
 
 rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir
+fi
 echo >conf$$.file
 if ln -s conf$$.file conf$$ 2>/dev/null; then
-  # We could just check for DJGPP; but this test a) works b) is more generic
-  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
-  if test -f conf$$.exe; then
-    # Don't use ln at all; we don't have any links
+  as_ln_s='ln -s'
+  # ... but there are two gotchas:
+  # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+  # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+  # In both cases, we have to default to `cp -p'.
+  ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
     as_ln_s='cp -p'
-  else
-    as_ln_s='ln -s'
-  fi
 elif ln conf$$.file conf$$ 2>/dev/null; then
   as_ln_s=ln
 else
   as_ln_s='cp -p'
 fi
-rm -f conf$$ conf$$.exe conf$$.file
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
 
 if mkdir -p . 2>/dev/null; then
   as_mkdir_p=:
@@ -6300,7 +23291,28 @@
   as_mkdir_p=false
 fi
 
-as_executable_p="test -f"
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+        test -d "$1/.";
+      else
+	case $1 in
+        -*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
 
 # Sed expression to map a string onto a valid CPP name.
 as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
@@ -6309,31 +23321,14 @@
 as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
 
 
-# IFS
-# We need space, tab and new line, in precisely that order.
-as_nl='
-'
-IFS=" 	$as_nl"
-
-# CDPATH.
-$as_unset CDPATH
-
 exec 6>&1
 
-# Open the log real soon, to keep \$[0] and so on meaningful, and to
+# Save the log message, to keep $[0] and so on meaningful, and to
 # report actual input values of CONFIG_FILES etc. instead of their
-# values after options handling.  Logging --version etc. is OK.
-exec 5>>config.log
-{
-  echo
-  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
-## Running $as_me. ##
-_ASBOX
-} >&5
-cat >&5 <<_CSEOF
-
-This file was extended by libffi $as_me 2.1, which was
-generated by GNU Autoconf 2.59.  Invocation command line was
+# values after options handling.
+ac_log="
+This file was extended by libffi $as_me 3.0.4, which was
+generated by GNU Autoconf 2.61.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
@@ -6341,30 +23336,21 @@
   CONFIG_COMMANDS = $CONFIG_COMMANDS
   $ $0 $@
 
-_CSEOF
-echo "on `(hostname || uname -n) 2>/dev/null | sed 1q`" >&5
-echo >&5
+on `(hostname || uname -n) 2>/dev/null | sed 1q`
+"
+
 _ACEOF
 
+cat >>$CONFIG_STATUS <<_ACEOF
 # Files that config.status was made for.
-if test -n "$ac_config_files"; then
-  echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS
-fi
-
-if test -n "$ac_config_headers"; then
-  echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS
-fi
-
-if test -n "$ac_config_links"; then
-  echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS
-fi
+config_files="$ac_config_files"
+config_headers="$ac_config_headers"
+config_links="$ac_config_links"
+config_commands="$ac_config_commands"
 
-if test -n "$ac_config_commands"; then
-  echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS
-fi
+_ACEOF
 
 cat >>$CONFIG_STATUS <<\_ACEOF
-
 ac_cs_usage="\
 \`$as_me' instantiates files from templates according to the
 current configuration.
@@ -6372,7 +23358,7 @@
 Usage: $0 [OPTIONS] [FILE]...
 
   -h, --help       print this help, then exit
-  -V, --version    print version number, then exit
+  -V, --version    print version number and configuration settings, then exit
   -q, --quiet      do not print progress messages
   -d, --debug      don't remove temporary files
       --recheck    update $as_me by reconfiguring in the same conditions
@@ -6394,18 +23380,22 @@
 $config_commands
 
 Report bugs to <bug-autoconf at gnu.org>."
-_ACEOF
 
+_ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF
 ac_cs_version="\\
-libffi config.status 2.1
-configured by $0, generated by GNU Autoconf 2.59,
-  with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
+libffi config.status 3.0.4
+configured by $0, generated by GNU Autoconf 2.61,
+  with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 
-Copyright (C) 2003 Free Software Foundation, Inc.
+Copyright (C) 2006 Free Software Foundation, Inc.
 This config.status script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it."
-srcdir=$srcdir
+
+ac_pwd='$ac_pwd'
+srcdir='$srcdir'
+INSTALL='$INSTALL'
+MKDIR_P='$MKDIR_P'
 _ACEOF
 
 cat >>$CONFIG_STATUS <<\_ACEOF
@@ -6416,39 +23406,24 @@
 do
   case $1 in
   --*=*)
-    ac_option=`expr "x$1" : 'x\([^=]*\)='`
-    ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
     ac_shift=:
     ;;
-  -*)
+  *)
     ac_option=$1
     ac_optarg=$2
     ac_shift=shift
     ;;
-  *) # This is not an option, so the user has probably given explicit
-     # arguments.
-     ac_option=$1
-     ac_need_defaults=false;;
   esac
 
   case $ac_option in
   # Handling of the options.
-_ACEOF
-cat >>$CONFIG_STATUS <<\_ACEOF
   -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
     ac_cs_recheck=: ;;
-  --version | --vers* | -V )
-    echo "$ac_cs_version"; exit 0 ;;
-  --he | --h)
-    # Conflict between --help and --header
-    { { echo "$as_me:$LINENO: error: ambiguous option: $1
-Try \`$0 --help' for more information." >&5
-echo "$as_me: error: ambiguous option: $1
-Try \`$0 --help' for more information." >&2;}
-   { (exit 1); exit 1; }; };;
-  --help | --hel | -h )
-    echo "$ac_cs_usage"; exit 0 ;;
-  --debug | --d* | -d )
+  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
+    echo "$ac_cs_version"; exit ;;
+  --debug | --debu | --deb | --de | --d | -d )
     debug=: ;;
   --file | --fil | --fi | --f )
     $ac_shift
@@ -6458,18 +23433,24 @@
     $ac_shift
     CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg"
     ac_need_defaults=false;;
+  --he | --h)
+    # Conflict between --help and --header
+    { echo "$as_me: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; };;
+  --help | --hel | -h )
+    echo "$ac_cs_usage"; exit ;;
   -q | -quiet | --quiet | --quie | --qui | --qu | --q \
   | -silent | --silent | --silen | --sile | --sil | --si | --s)
     ac_cs_silent=: ;;
 
   # This is an error.
-  -*) { { echo "$as_me:$LINENO: error: unrecognized option: $1
-Try \`$0 --help' for more information." >&5
-echo "$as_me: error: unrecognized option: $1
-Try \`$0 --help' for more information." >&2;}
+  -*) { echo "$as_me: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&2
    { (exit 1); exit 1; }; } ;;
 
-  *) ac_config_targets="$ac_config_targets $1" ;;
+  *) ac_config_targets="$ac_config_targets $1"
+     ac_need_defaults=false ;;
 
   esac
   shift
@@ -6485,41 +23466,55 @@
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF
 if \$ac_cs_recheck; then
-  echo "running $SHELL $0 " $ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6
-  exec $SHELL $0 $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  echo "running CONFIG_SHELL=$SHELL $SHELL $0 "$ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6
+  CONFIG_SHELL=$SHELL
+  export CONFIG_SHELL
+  exec $SHELL "$0"$ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
 fi
 
 _ACEOF
-
+cat >>$CONFIG_STATUS <<\_ACEOF
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+  echo "$ac_log"
+} >&5
+
+_ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF
 #
-# INIT-COMMANDS section.
+# INIT-COMMANDS
 #
-
+AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"
 TARGETDIR="$TARGETDIR"
 
 _ACEOF
 
-
-
 cat >>$CONFIG_STATUS <<\_ACEOF
+
+# Handling of arguments.
 for ac_config_target in $ac_config_targets
 do
-  case "$ac_config_target" in
-  # Handling of arguments.
-  "include/ffi.h" ) CONFIG_FILES="$CONFIG_FILES include/ffi.h" ;;
-  "fficonfig.py" ) CONFIG_FILES="$CONFIG_FILES fficonfig.py" ;;
-  "include/ffitarget.h" ) CONFIG_LINKS="$CONFIG_LINKS include/ffitarget.h:src/$TARGETINCDIR/ffitarget.h" ;;
-  "include/ffi_common.h" ) CONFIG_LINKS="$CONFIG_LINKS include/ffi_common.h:include/ffi_common.h" ;;
-  "include" ) CONFIG_COMMANDS="$CONFIG_COMMANDS include" ;;
-  "src" ) CONFIG_COMMANDS="$CONFIG_COMMANDS src" ;;
-  "fficonfig.h" ) CONFIG_HEADERS="$CONFIG_HEADERS fficonfig.h" ;;
+  case $ac_config_target in
+    "fficonfig.h") CONFIG_HEADERS="$CONFIG_HEADERS fficonfig.h" ;;
+    "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
+    "include") CONFIG_COMMANDS="$CONFIG_COMMANDS include" ;;
+    "src") CONFIG_COMMANDS="$CONFIG_COMMANDS src" ;;
+    "include/ffitarget.h") CONFIG_LINKS="$CONFIG_LINKS include/ffitarget.h:src/$TARGETDIR/ffitarget.h" ;;
+    "include/ffi.h") CONFIG_FILES="$CONFIG_FILES include/ffi.h" ;;
+    "include/ffi_common.h") CONFIG_LINKS="$CONFIG_LINKS include/ffi_common.h:include/ffi_common.h" ;;
+    "fficonfig.py") CONFIG_FILES="$CONFIG_FILES fficonfig.py" ;;
+
   *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
 echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
    { (exit 1); exit 1; }; };;
   esac
 done
 
+
 # If the user did not use the arguments to specify the items to instantiate,
 # then the envvar interface is used.  Set only those that are not.
 # We use the long form for the default assignment because of an extremely
@@ -6532,819 +23527,866 @@
 fi
 
 # Have a temporary directory for convenience.  Make it in the build tree
-# simply because there is no reason to put it here, and in addition,
+# simply because there is no reason against having it here, and in addition,
 # creating and moving files from /tmp can sometimes cause problems.
-# Create a temporary directory, and hook for its removal unless debugging.
+# Hook for its removal unless debugging.
+# Note that there is a small window in which the directory will not be cleaned:
+# after its creation but before its name has been assigned to `$tmp'.
 $debug ||
 {
-  trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0
+  tmp=
+  trap 'exit_status=$?
+  { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status
+' 0
   trap '{ (exit 1); exit 1; }' 1 2 13 15
 }
-
 # Create a (secure) tmp directory for tmp files.
 
 {
-  tmp=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
+  tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
   test -n "$tmp" && test -d "$tmp"
 }  ||
 {
-  tmp=./confstat$$-$RANDOM
-  (umask 077 && mkdir $tmp)
+  tmp=./conf$$-$RANDOM
+  (umask 077 && mkdir "$tmp")
 } ||
 {
    echo "$me: cannot create a temporary directory in ." >&2
    { (exit 1); exit 1; }
 }
 
-_ACEOF
-
-cat >>$CONFIG_STATUS <<_ACEOF
-
 #
-# CONFIG_FILES section.
+# Set up the sed scripts for CONFIG_FILES section.
 #
 
 # No need to generate the scripts if there are no CONFIG_FILES.
 # This happens for instance when ./config.status config.h
-if test -n "\$CONFIG_FILES"; then
-  # Protect against being on the right side of a sed subst in config.status.
-  sed 's/,@/@@/; s/@,/@@/; s/,;t t\$/@;t t/; /@;t t\$/s/[\\\\&,]/\\\\&/g;
-   s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF
-s, at SHELL@,$SHELL,;t t
-s, at PATH_SEPARATOR@,$PATH_SEPARATOR,;t t
-s, at PACKAGE_NAME@,$PACKAGE_NAME,;t t
-s, at PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t
-s, at PACKAGE_VERSION@,$PACKAGE_VERSION,;t t
-s, at PACKAGE_STRING@,$PACKAGE_STRING,;t t
-s, at PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t
-s, at exec_prefix@,$exec_prefix,;t t
-s, at prefix@,$prefix,;t t
-s, at program_transform_name@,$program_transform_name,;t t
-s, at bindir@,$bindir,;t t
-s, at sbindir@,$sbindir,;t t
-s, at libexecdir@,$libexecdir,;t t
-s, at datadir@,$datadir,;t t
-s, at sysconfdir@,$sysconfdir,;t t
-s, at sharedstatedir@,$sharedstatedir,;t t
-s, at localstatedir@,$localstatedir,;t t
-s, at libdir@,$libdir,;t t
-s, at includedir@,$includedir,;t t
-s, at oldincludedir@,$oldincludedir,;t t
-s, at infodir@,$infodir,;t t
-s, at mandir@,$mandir,;t t
-s, at build_alias@,$build_alias,;t t
-s, at host_alias@,$host_alias,;t t
-s, at target_alias@,$target_alias,;t t
-s, at DEFS@,$DEFS,;t t
-s, at ECHO_C@,$ECHO_C,;t t
-s, at ECHO_N@,$ECHO_N,;t t
-s, at ECHO_T@,$ECHO_T,;t t
-s, at LIBS@,$LIBS,;t t
-s, at build@,$build,;t t
-s, at build_cpu@,$build_cpu,;t t
-s, at build_vendor@,$build_vendor,;t t
-s, at build_os@,$build_os,;t t
-s, at host@,$host,;t t
-s, at host_cpu@,$host_cpu,;t t
-s, at host_vendor@,$host_vendor,;t t
-s, at host_os@,$host_os,;t t
-s, at target@,$target,;t t
-s, at target_cpu@,$target_cpu,;t t
-s, at target_vendor@,$target_vendor,;t t
-s, at target_os@,$target_os,;t t
-s, at CC@,$CC,;t t
-s, at ac_ct_CC@,$ac_ct_CC,;t t
-s, at EXEEXT@,$EXEEXT,;t t
-s, at OBJEXT@,$OBJEXT,;t t
-s, at CFLAGS@,$CFLAGS,;t t
-s, at CPP@,$CPP,;t t
-s, at CPPFLAGS@,$CPPFLAGS,;t t
-s, at EGREP@,$EGREP,;t t
-s, at ALLOCA@,$ALLOCA,;t t
-s, at HAVE_LONG_DOUBLE@,$HAVE_LONG_DOUBLE,;t t
-s, at TARGET@,$TARGET,;t t
-s, at TARGETDIR@,$TARGETDIR,;t t
-s, at MKTARGET@,$MKTARGET,;t t
-s, at LIBOBJS@,$LIBOBJS,;t t
-s, at LTLIBOBJS@,$LTLIBOBJS,;t t
-CEOF
-
-_ACEOF
-
-  cat >>$CONFIG_STATUS <<\_ACEOF
-  # Split the substitutions into bite-sized pieces for seds with
-  # small command number limits, like on Digital OSF/1 and HP-UX.
-  ac_max_sed_lines=48
-  ac_sed_frag=1 # Number of current file.
-  ac_beg=1 # First line for current file.
-  ac_end=$ac_max_sed_lines # Line after last line for current file.
-  ac_more_lines=:
-  ac_sed_cmds=
-  while $ac_more_lines; do
-    if test $ac_beg -gt 1; then
-      sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
-    else
-      sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
-    fi
-    if test ! -s $tmp/subs.frag; then
-      ac_more_lines=false
-    else
-      # The purpose of the label and of the branching condition is to
-      # speed up the sed processing (if there are no `@' at all, there
-      # is no need to browse any of the substitutions).
-      # These are the two extra sed commands mentioned above.
-      (echo ':t
-  /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed
-      if test -z "$ac_sed_cmds"; then
-	ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed"
-      else
-	ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed"
-      fi
-      ac_sed_frag=`expr $ac_sed_frag + 1`
-      ac_beg=$ac_end
-      ac_end=`expr $ac_end + $ac_max_sed_lines`
-    fi
-  done
-  if test -z "$ac_sed_cmds"; then
-    ac_sed_cmds=cat
+if test -n "$CONFIG_FILES"; then
+
+_ACEOF
+
+
+
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+  cat >conf$$subs.sed <<_ACEOF
+SHELL!$SHELL$ac_delim
+PATH_SEPARATOR!$PATH_SEPARATOR$ac_delim
+PACKAGE_NAME!$PACKAGE_NAME$ac_delim
+PACKAGE_TARNAME!$PACKAGE_TARNAME$ac_delim
+PACKAGE_VERSION!$PACKAGE_VERSION$ac_delim
+PACKAGE_STRING!$PACKAGE_STRING$ac_delim
+PACKAGE_BUGREPORT!$PACKAGE_BUGREPORT$ac_delim
+exec_prefix!$exec_prefix$ac_delim
+prefix!$prefix$ac_delim
+program_transform_name!$program_transform_name$ac_delim
+bindir!$bindir$ac_delim
+sbindir!$sbindir$ac_delim
+libexecdir!$libexecdir$ac_delim
+datarootdir!$datarootdir$ac_delim
+datadir!$datadir$ac_delim
+sysconfdir!$sysconfdir$ac_delim
+sharedstatedir!$sharedstatedir$ac_delim
+localstatedir!$localstatedir$ac_delim
+includedir!$includedir$ac_delim
+oldincludedir!$oldincludedir$ac_delim
+docdir!$docdir$ac_delim
+infodir!$infodir$ac_delim
+htmldir!$htmldir$ac_delim
+dvidir!$dvidir$ac_delim
+pdfdir!$pdfdir$ac_delim
+psdir!$psdir$ac_delim
+libdir!$libdir$ac_delim
+localedir!$localedir$ac_delim
+mandir!$mandir$ac_delim
+DEFS!$DEFS$ac_delim
+ECHO_C!$ECHO_C$ac_delim
+ECHO_N!$ECHO_N$ac_delim
+ECHO_T!$ECHO_T$ac_delim
+LIBS!$LIBS$ac_delim
+build_alias!$build_alias$ac_delim
+host_alias!$host_alias$ac_delim
+target_alias!$target_alias$ac_delim
+build!$build$ac_delim
+build_cpu!$build_cpu$ac_delim
+build_vendor!$build_vendor$ac_delim
+build_os!$build_os$ac_delim
+host!$host$ac_delim
+host_cpu!$host_cpu$ac_delim
+host_vendor!$host_vendor$ac_delim
+host_os!$host_os$ac_delim
+target!$target$ac_delim
+target_cpu!$target_cpu$ac_delim
+target_vendor!$target_vendor$ac_delim
+target_os!$target_os$ac_delim
+INSTALL_PROGRAM!$INSTALL_PROGRAM$ac_delim
+INSTALL_SCRIPT!$INSTALL_SCRIPT$ac_delim
+INSTALL_DATA!$INSTALL_DATA$ac_delim
+am__isrc!$am__isrc$ac_delim
+CYGPATH_W!$CYGPATH_W$ac_delim
+PACKAGE!$PACKAGE$ac_delim
+VERSION!$VERSION$ac_delim
+ACLOCAL!$ACLOCAL$ac_delim
+AUTOCONF!$AUTOCONF$ac_delim
+AUTOMAKE!$AUTOMAKE$ac_delim
+AUTOHEADER!$AUTOHEADER$ac_delim
+MAKEINFO!$MAKEINFO$ac_delim
+install_sh!$install_sh$ac_delim
+STRIP!$STRIP$ac_delim
+INSTALL_STRIP_PROGRAM!$INSTALL_STRIP_PROGRAM$ac_delim
+mkdir_p!$mkdir_p$ac_delim
+AWK!$AWK$ac_delim
+SET_MAKE!$SET_MAKE$ac_delim
+am__leading_dot!$am__leading_dot$ac_delim
+AMTAR!$AMTAR$ac_delim
+am__tar!$am__tar$ac_delim
+am__untar!$am__untar$ac_delim
+CC!$CC$ac_delim
+CFLAGS!$CFLAGS$ac_delim
+LDFLAGS!$LDFLAGS$ac_delim
+CPPFLAGS!$CPPFLAGS$ac_delim
+ac_ct_CC!$ac_ct_CC$ac_delim
+EXEEXT!$EXEEXT$ac_delim
+OBJEXT!$OBJEXT$ac_delim
+DEPDIR!$DEPDIR$ac_delim
+am__include!$am__include$ac_delim
+am__quote!$am__quote$ac_delim
+AMDEP_TRUE!$AMDEP_TRUE$ac_delim
+AMDEP_FALSE!$AMDEP_FALSE$ac_delim
+AMDEPBACKSLASH!$AMDEPBACKSLASH$ac_delim
+CCDEPMODE!$CCDEPMODE$ac_delim
+am__fastdepCC_TRUE!$am__fastdepCC_TRUE$ac_delim
+am__fastdepCC_FALSE!$am__fastdepCC_FALSE$ac_delim
+CCAS!$CCAS$ac_delim
+CCASFLAGS!$CCASFLAGS$ac_delim
+CCASDEPMODE!$CCASDEPMODE$ac_delim
+am__fastdepCCAS_TRUE!$am__fastdepCCAS_TRUE$ac_delim
+am__fastdepCCAS_FALSE!$am__fastdepCCAS_FALSE$ac_delim
+SED!$SED$ac_delim
+GREP!$GREP$ac_delim
+EGREP!$EGREP$ac_delim
+LN_S!$LN_S$ac_delim
+ECHO!$ECHO$ac_delim
+_ACEOF
+
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
+    break
+  elif $ac_last_try; then
+    { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
+echo "$as_me: error: could not make $CONFIG_STATUS" >&2;}
+   { (exit 1); exit 1; }; }
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
   fi
-fi # test -n "$CONFIG_FILES"
+done
+
+ac_eof=`sed -n '/^CEOF[0-9]*$/s/CEOF/0/p' conf$$subs.sed`
+if test -n "$ac_eof"; then
+  ac_eof=`echo "$ac_eof" | sort -nru | sed 1q`
+  ac_eof=`expr $ac_eof + 1`
+fi
+
+cat >>$CONFIG_STATUS <<_ACEOF
+cat >"\$tmp/subs-1.sed" <<\CEOF$ac_eof
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+_ACEOF
+sed '
+s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g
+s/^/s,@/; s/!/@,|#_!!_#|/
+:n
+t n
+s/'"$ac_delim"'$/,g/; t
+s/$/\\/; p
+N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n
+' >>$CONFIG_STATUS <conf$$subs.sed
+rm -f conf$$subs.sed
+cat >>$CONFIG_STATUS <<_ACEOF
+CEOF$ac_eof
+_ACEOF
+
+
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+  cat >conf$$subs.sed <<_ACEOF
+AR!$AR$ac_delim
+RANLIB!$RANLIB$ac_delim
+CPP!$CPP$ac_delim
+CXX!$CXX$ac_delim
+CXXFLAGS!$CXXFLAGS$ac_delim
+ac_ct_CXX!$ac_ct_CXX$ac_delim
+CXXDEPMODE!$CXXDEPMODE$ac_delim
+am__fastdepCXX_TRUE!$am__fastdepCXX_TRUE$ac_delim
+am__fastdepCXX_FALSE!$am__fastdepCXX_FALSE$ac_delim
+CXXCPP!$CXXCPP$ac_delim
+F77!$F77$ac_delim
+FFLAGS!$FFLAGS$ac_delim
+ac_ct_F77!$ac_ct_F77$ac_delim
+LIBTOOL!$LIBTOOL$ac_delim
+MAINTAINER_MODE_TRUE!$MAINTAINER_MODE_TRUE$ac_delim
+MAINTAINER_MODE_FALSE!$MAINTAINER_MODE_FALSE$ac_delim
+MAINT!$MAINT$ac_delim
+TESTSUBDIR_TRUE!$TESTSUBDIR_TRUE$ac_delim
+TESTSUBDIR_FALSE!$TESTSUBDIR_FALSE$ac_delim
+AM_RUNTESTFLAGS!$AM_RUNTESTFLAGS$ac_delim
+MIPS_TRUE!$MIPS_TRUE$ac_delim
+MIPS_FALSE!$MIPS_FALSE$ac_delim
+SPARC_TRUE!$SPARC_TRUE$ac_delim
+SPARC_FALSE!$SPARC_FALSE$ac_delim
+X86_TRUE!$X86_TRUE$ac_delim
+X86_FALSE!$X86_FALSE$ac_delim
+X86_FREEBSD_TRUE!$X86_FREEBSD_TRUE$ac_delim
+X86_FREEBSD_FALSE!$X86_FREEBSD_FALSE$ac_delim
+X86_WIN32_TRUE!$X86_WIN32_TRUE$ac_delim
+X86_WIN32_FALSE!$X86_WIN32_FALSE$ac_delim
+X86_DARWIN_TRUE!$X86_DARWIN_TRUE$ac_delim
+X86_DARWIN_FALSE!$X86_DARWIN_FALSE$ac_delim
+ALPHA_TRUE!$ALPHA_TRUE$ac_delim
+ALPHA_FALSE!$ALPHA_FALSE$ac_delim
+IA64_TRUE!$IA64_TRUE$ac_delim
+IA64_FALSE!$IA64_FALSE$ac_delim
+M32R_TRUE!$M32R_TRUE$ac_delim
+M32R_FALSE!$M32R_FALSE$ac_delim
+M68K_TRUE!$M68K_TRUE$ac_delim
+M68K_FALSE!$M68K_FALSE$ac_delim
+POWERPC_TRUE!$POWERPC_TRUE$ac_delim
+POWERPC_FALSE!$POWERPC_FALSE$ac_delim
+POWERPC_AIX_TRUE!$POWERPC_AIX_TRUE$ac_delim
+POWERPC_AIX_FALSE!$POWERPC_AIX_FALSE$ac_delim
+POWERPC_DARWIN_TRUE!$POWERPC_DARWIN_TRUE$ac_delim
+POWERPC_DARWIN_FALSE!$POWERPC_DARWIN_FALSE$ac_delim
+POWERPC_FREEBSD_TRUE!$POWERPC_FREEBSD_TRUE$ac_delim
+POWERPC_FREEBSD_FALSE!$POWERPC_FREEBSD_FALSE$ac_delim
+ARM_TRUE!$ARM_TRUE$ac_delim
+ARM_FALSE!$ARM_FALSE$ac_delim
+LIBFFI_CRIS_TRUE!$LIBFFI_CRIS_TRUE$ac_delim
+LIBFFI_CRIS_FALSE!$LIBFFI_CRIS_FALSE$ac_delim
+FRV_TRUE!$FRV_TRUE$ac_delim
+FRV_FALSE!$FRV_FALSE$ac_delim
+S390_TRUE!$S390_TRUE$ac_delim
+S390_FALSE!$S390_FALSE$ac_delim
+X86_64_TRUE!$X86_64_TRUE$ac_delim
+X86_64_FALSE!$X86_64_FALSE$ac_delim
+SH_TRUE!$SH_TRUE$ac_delim
+SH_FALSE!$SH_FALSE$ac_delim
+SH64_TRUE!$SH64_TRUE$ac_delim
+SH64_FALSE!$SH64_FALSE$ac_delim
+PA_LINUX_TRUE!$PA_LINUX_TRUE$ac_delim
+PA_LINUX_FALSE!$PA_LINUX_FALSE$ac_delim
+PA_HPUX_TRUE!$PA_HPUX_TRUE$ac_delim
+PA_HPUX_FALSE!$PA_HPUX_FALSE$ac_delim
+PA64_HPUX_TRUE!$PA64_HPUX_TRUE$ac_delim
+PA64_HPUX_FALSE!$PA64_HPUX_FALSE$ac_delim
+ALLOCA!$ALLOCA$ac_delim
+HAVE_LONG_DOUBLE!$HAVE_LONG_DOUBLE$ac_delim
+TARGET!$TARGET$ac_delim
+TARGETDIR!$TARGETDIR$ac_delim
+toolexecdir!$toolexecdir$ac_delim
+toolexeclibdir!$toolexeclibdir$ac_delim
+LIBOBJS!$LIBOBJS$ac_delim
+LTLIBOBJS!$LTLIBOBJS$ac_delim
+_ACEOF
+
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 76; then
+    break
+  elif $ac_last_try; then
+    { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
+echo "$as_me: error: could not make $CONFIG_STATUS" >&2;}
+   { (exit 1); exit 1; }; }
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+
+ac_eof=`sed -n '/^CEOF[0-9]*$/s/CEOF/0/p' conf$$subs.sed`
+if test -n "$ac_eof"; then
+  ac_eof=`echo "$ac_eof" | sort -nru | sed 1q`
+  ac_eof=`expr $ac_eof + 1`
+fi
 
+cat >>$CONFIG_STATUS <<_ACEOF
+cat >"\$tmp/subs-2.sed" <<\CEOF$ac_eof
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b end
+_ACEOF
+sed '
+s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g
+s/^/s,@/; s/!/@,|#_!!_#|/
+:n
+t n
+s/'"$ac_delim"'$/,g/; t
+s/$/\\/; p
+N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n
+' >>$CONFIG_STATUS <conf$$subs.sed
+rm -f conf$$subs.sed
+cat >>$CONFIG_STATUS <<_ACEOF
+:end
+s/|#_!!_#|//g
+CEOF$ac_eof
 _ACEOF
+
+
+# VPATH may cause trouble with some makes, so we remove $(srcdir),
+# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=/{
+s/:*\$(srcdir):*/:/
+s/:*\${srcdir}:*/:/
+s/:*@srcdir@:*/:/
+s/^\([^=]*=[	 ]*\):*/\1/
+s/:*$//
+s/^[^=]*=[	 ]*$//
+}'
+fi
+
 cat >>$CONFIG_STATUS <<\_ACEOF
-for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue
-  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
-  case $ac_file in
-  - | *:- | *:-:* ) # input from stdin
-	cat >$tmp/stdin
-	ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
-	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
-  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
-	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
-  * )   ac_file_in=$ac_file.in ;;
+fi # test -n "$CONFIG_FILES"
+
+
+for ac_tag in  :F $CONFIG_FILES  :H $CONFIG_HEADERS  :L $CONFIG_LINKS  :C $CONFIG_COMMANDS
+do
+  case $ac_tag in
+  :[FHLC]) ac_mode=$ac_tag; continue;;
+  esac
+  case $ac_mode$ac_tag in
+  :[FHL]*:*);;
+  :L* | :C*:*) { { echo "$as_me:$LINENO: error: Invalid tag $ac_tag." >&5
+echo "$as_me: error: Invalid tag $ac_tag." >&2;}
+   { (exit 1); exit 1; }; };;
+  :[FH]-) ac_tag=-:-;;
+  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
+  esac
+  ac_save_IFS=$IFS
+  IFS=:
+  set x $ac_tag
+  IFS=$ac_save_IFS
+  shift
+  ac_file=$1
+  shift
+
+  case $ac_mode in
+  :L) ac_source=$1;;
+  :[FH])
+    ac_file_inputs=
+    for ac_f
+    do
+      case $ac_f in
+      -) ac_f="$tmp/stdin";;
+      *) # Look for the file first in the build tree, then in the source tree
+	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
+	 # because $ac_f cannot contain `:'.
+	 test -f "$ac_f" ||
+	   case $ac_f in
+	   [\\/$]*) false;;
+	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
+	   esac ||
+	   { { echo "$as_me:$LINENO: error: cannot find input file: $ac_f" >&5
+echo "$as_me: error: cannot find input file: $ac_f" >&2;}
+   { (exit 1); exit 1; }; };;
+      esac
+      ac_file_inputs="$ac_file_inputs $ac_f"
+    done
+
+    # Let's still pretend it is `configure' which instantiates (i.e., don't
+    # use $as_me), people would be surprised to read:
+    #    /* config.h.  Generated by config.status.  */
+    configure_input="Generated from "`IFS=:
+	  echo $* | sed 's|^[^:]*/||;s|:[^:]*/|, |g'`" by configure."
+    if test x"$ac_file" != x-; then
+      configure_input="$ac_file.  $configure_input"
+      { echo "$as_me:$LINENO: creating $ac_file" >&5
+echo "$as_me: creating $ac_file" >&6;}
+    fi
+
+    case $ac_tag in
+    *:-:* | *:-) cat >"$tmp/stdin";;
+    esac
+    ;;
   esac
 
-  # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories.
-  ac_dir=`(dirname "$ac_file") 2>/dev/null ||
+  ac_dir=`$as_dirname -- "$ac_file" ||
 $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
 	 X"$ac_file" : 'X\(//\)[^/]' \| \
 	 X"$ac_file" : 'X\(//\)$' \| \
-	 X"$ac_file" : 'X\(/\)' \| \
-	 .     : '\(.\)' 2>/dev/null ||
+	 X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
 echo X"$ac_file" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
-  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
-  	  /^X\(\/\/\)$/{ s//\1/; q; }
-  	  /^X\(\/\).*/{ s//\1/; q; }
-  	  s/.*/./; q'`
-  { if $as_mkdir_p; then
-    mkdir -p "$ac_dir"
-  else
-    as_dir="$ac_dir"
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+  { as_dir="$ac_dir"
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || {
     as_dirs=
-    while test ! -d "$as_dir"; do
-      as_dirs="$as_dir $as_dirs"
-      as_dir=`(dirname "$as_dir") 2>/dev/null ||
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
 $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
 	 X"$as_dir" : 'X\(//\)[^/]' \| \
 	 X"$as_dir" : 'X\(//\)$' \| \
-	 X"$as_dir" : 'X\(/\)' \| \
-	 .     : '\(.\)' 2>/dev/null ||
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
 echo X"$as_dir" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
-  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
-  	  /^X\(\/\/\)$/{ s//\1/; q; }
-  	  /^X\(\/\).*/{ s//\1/; q; }
-  	  s/.*/./; q'`
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
     done
-    test ! -n "$as_dirs" || mkdir $as_dirs
-  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
-echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || { { echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5
+echo "$as_me: error: cannot create directory $as_dir" >&2;}
    { (exit 1); exit 1; }; }; }
-
   ac_builddir=.
 
-if test "$ac_dir" != .; then
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
   ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
-  # A "../" for each directory in $ac_dir_suffix.
-  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
-else
-  ac_dir_suffix= ac_top_builddir=
-fi
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
 
 case $srcdir in
-  .)  # No --srcdir option.  We are building in place.
+  .)  # We are building in place.
     ac_srcdir=.
-    if test -z "$ac_top_builddir"; then
-       ac_top_srcdir=.
-    else
-       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
-    fi ;;
-  [\\/]* | ?:[\\/]* )  # Absolute path.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
     ac_srcdir=$srcdir$ac_dir_suffix;
-    ac_top_srcdir=$srcdir ;;
-  *) # Relative path.
-    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
-    ac_top_srcdir=$ac_top_builddir$srcdir ;;
-esac
-
-# Do not use `cd foo && pwd` to compute absolute paths, because
-# the directories may not exist.
-case `pwd` in
-.) ac_abs_builddir="$ac_dir";;
-*)
-  case "$ac_dir" in
-  .) ac_abs_builddir=`pwd`;;
-  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
-  *) ac_abs_builddir=`pwd`/"$ac_dir";;
-  esac;;
-esac
-case $ac_abs_builddir in
-.) ac_abs_top_builddir=${ac_top_builddir}.;;
-*)
-  case ${ac_top_builddir}. in
-  .) ac_abs_top_builddir=$ac_abs_builddir;;
-  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
-  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
-  esac;;
-esac
-case $ac_abs_builddir in
-.) ac_abs_srcdir=$ac_srcdir;;
-*)
-  case $ac_srcdir in
-  .) ac_abs_srcdir=$ac_abs_builddir;;
-  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
-  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
-  esac;;
-esac
-case $ac_abs_builddir in
-.) ac_abs_top_srcdir=$ac_top_srcdir;;
-*)
-  case $ac_top_srcdir in
-  .) ac_abs_top_srcdir=$ac_abs_builddir;;
-  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
-  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
-  esac;;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
 esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
 
 
+  case $ac_mode in
+  :F)
+  #
+  # CONFIG_FILE
+  #
+
+  case $INSTALL in
+  [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
+  *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;;
+  esac
+  ac_MKDIR_P=$MKDIR_P
+  case $MKDIR_P in
+  [\\/$]* | ?:[\\/]* ) ;;
+  */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;;
+  esac
+_ACEOF
 
-  if test x"$ac_file" != x-; then
-    { echo "$as_me:$LINENO: creating $ac_file" >&5
-echo "$as_me: creating $ac_file" >&6;}
-    rm -f "$ac_file"
-  fi
-  # Let's still pretend it is `configure' which instantiates (i.e., don't
-  # use $as_me), people would be surprised to read:
-  #    /* config.h.  Generated by config.status.  */
-  if test x"$ac_file" = x-; then
-    configure_input=
-  else
-    configure_input="$ac_file.  "
-  fi
-  configure_input=$configure_input"Generated from `echo $ac_file_in |
-				     sed 's,.*/,,'` by configure."
-
-  # First look for the input files in the build tree, otherwise in the
-  # src tree.
-  ac_file_inputs=`IFS=:
-    for f in $ac_file_in; do
-      case $f in
-      -) echo $tmp/stdin ;;
-      [\\/$]*)
-	 # Absolute (can't be DOS-style, as IFS=:)
-	 test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
-echo "$as_me: error: cannot find input file: $f" >&2;}
-   { (exit 1); exit 1; }; }
-	 echo "$f";;
-      *) # Relative
-	 if test -f "$f"; then
-	   # Build tree
-	   echo "$f"
-	 elif test -f "$srcdir/$f"; then
-	   # Source tree
-	   echo "$srcdir/$f"
-	 else
-	   # /dev/null tree
-	   { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
-echo "$as_me: error: cannot find input file: $f" >&2;}
-   { (exit 1); exit 1; }; }
-	 fi;;
-      esac
-    done` || { (exit 1); exit 1; }
+cat >>$CONFIG_STATUS <<\_ACEOF
+# If the template does not know about datarootdir, expand it.
+# FIXME: This hack should be removed a few years after 2.60.
+ac_datarootdir_hack=; ac_datarootdir_seen=
+
+case `sed -n '/datarootdir/ {
+  p
+  q
+}
+/@datadir@/p
+/@docdir@/p
+/@infodir@/p
+/@localedir@/p
+/@mandir@/p
+' $ac_file_inputs` in
+*datarootdir*) ac_datarootdir_seen=yes;;
+*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
+  { echo "$as_me:$LINENO: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
+echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF
+  ac_datarootdir_hack='
+  s&@datadir@&$datadir&g
+  s&@docdir@&$docdir&g
+  s&@infodir@&$infodir&g
+  s&@localedir@&$localedir&g
+  s&@mandir@&$mandir&g
+    s&\\\${datarootdir}&$datarootdir&g' ;;
+esac
+_ACEOF
+
+# Neutralize VPATH when `$srcdir' = `.'.
+# Shell code in configure.ac might set extrasub.
+# FIXME: do we really want to maintain this feature?
+cat >>$CONFIG_STATUS <<_ACEOF
   sed "$ac_vpsub
 $extrasub
 _ACEOF
 cat >>$CONFIG_STATUS <<\_ACEOF
 :t
 /@[a-zA-Z_][a-zA-Z_0-9]*@/!b
-s, at configure_input@,$configure_input,;t t
-s, at srcdir@,$ac_srcdir,;t t
-s, at abs_srcdir@,$ac_abs_srcdir,;t t
-s, at top_srcdir@,$ac_top_srcdir,;t t
-s, at abs_top_srcdir@,$ac_abs_top_srcdir,;t t
-s, at builddir@,$ac_builddir,;t t
-s, at abs_builddir@,$ac_abs_builddir,;t t
-s, at top_builddir@,$ac_top_builddir,;t t
-s, at abs_top_builddir@,$ac_abs_top_builddir,;t t
-" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out
-  rm -f $tmp/stdin
-  if test x"$ac_file" != x-; then
-    mv $tmp/out $ac_file
-  else
-    cat $tmp/out
-    rm -f $tmp/out
-  fi
-
-done
-_ACEOF
-cat >>$CONFIG_STATUS <<\_ACEOF
-
-#
-# CONFIG_HEADER section.
-#
-
-# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where
-# NAME is the cpp macro being defined and VALUE is the value it is being given.
-#
-# ac_d sets the value in "#define NAME VALUE" lines.
-ac_dA='s,^\([	 ]*\)#\([	 ]*define[	 ][	 ]*\)'
-ac_dB='[	 ].*$,\1#\2'
-ac_dC=' '
-ac_dD=',;t'
-# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
-ac_uA='s,^\([	 ]*\)#\([	 ]*\)undef\([	 ][	 ]*\)'
-ac_uB='$,\1#\2define\3'
-ac_uC=' '
-ac_uD=',;t'
+s&@configure_input@&$configure_input&;t t
+s&@top_builddir@&$ac_top_builddir_sub&;t t
+s&@srcdir@&$ac_srcdir&;t t
+s&@abs_srcdir@&$ac_abs_srcdir&;t t
+s&@top_srcdir@&$ac_top_srcdir&;t t
+s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
+s&@builddir@&$ac_builddir&;t t
+s&@abs_builddir@&$ac_abs_builddir&;t t
+s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
+s&@INSTALL@&$ac_INSTALL&;t t
+s&@MKDIR_P@&$ac_MKDIR_P&;t t
+$ac_datarootdir_hack
+" $ac_file_inputs | sed -f "$tmp/subs-1.sed" | sed -f "$tmp/subs-2.sed" >$tmp/out
+
+test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
+  { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } &&
+  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } &&
+  { echo "$as_me:$LINENO: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined." >&5
+echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined." >&2;}
 
-for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue
-  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+  rm -f "$tmp/stdin"
   case $ac_file in
-  - | *:- | *:-:* ) # input from stdin
-	cat >$tmp/stdin
-	ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
-	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
-  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
-	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
-  * )   ac_file_in=$ac_file.in ;;
+  -) cat "$tmp/out"; rm -f "$tmp/out";;
+  *) rm -f "$ac_file"; mv "$tmp/out" $ac_file;;
   esac
+ ;;
+  :H)
+  #
+  # CONFIG_HEADER
+  #
+_ACEOF
+
+# Transform confdefs.h into a sed script `conftest.defines', that
+# substitutes the proper values into config.h.in to produce config.h.
+rm -f conftest.defines conftest.tail
+# First, append a space to every undef/define line, to ease matching.
+echo 's/$/ /' >conftest.defines
+# Then, protect against being on the right side of a sed subst, or in
+# an unquoted here document, in config.status.  If some macros were
+# called several times there might be several #defines for the same
+# symbol, which is useless.  But do not sort them, since the last
+# AC_DEFINE must be honored.
+ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]*
+# These sed commands are passed to sed as "A NAME B PARAMS C VALUE D", where
+# NAME is the cpp macro being defined, VALUE is the value it is being given.
+# PARAMS is the parameter list in the macro definition--in most cases, it's
+# just an empty string.
+ac_dA='s,^\\([	 #]*\\)[^	 ]*\\([	 ]*'
+ac_dB='\\)[	 (].*,\\1define\\2'
+ac_dC=' '
+ac_dD=' ,'
 
-  test x"$ac_file" != x- && { echo "$as_me:$LINENO: creating $ac_file" >&5
-echo "$as_me: creating $ac_file" >&6;}
-
-  # First look for the input files in the build tree, otherwise in the
-  # src tree.
-  ac_file_inputs=`IFS=:
-    for f in $ac_file_in; do
-      case $f in
-      -) echo $tmp/stdin ;;
-      [\\/$]*)
-	 # Absolute (can't be DOS-style, as IFS=:)
-	 test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
-echo "$as_me: error: cannot find input file: $f" >&2;}
-   { (exit 1); exit 1; }; }
-	 # Do quote $f, to prevent DOS paths from being IFS'd.
-	 echo "$f";;
-      *) # Relative
-	 if test -f "$f"; then
-	   # Build tree
-	   echo "$f"
-	 elif test -f "$srcdir/$f"; then
-	   # Source tree
-	   echo "$srcdir/$f"
-	 else
-	   # /dev/null tree
-	   { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
-echo "$as_me: error: cannot find input file: $f" >&2;}
-   { (exit 1); exit 1; }; }
-	 fi;;
-      esac
-    done` || { (exit 1); exit 1; }
-  # Remove the trailing spaces.
-  sed 's/[	 ]*$//' $ac_file_inputs >$tmp/in
-
-_ACEOF
-
-# Transform confdefs.h into two sed scripts, `conftest.defines' and
-# `conftest.undefs', that substitutes the proper values into
-# config.h.in to produce config.h.  The first handles `#define'
-# templates, and the second `#undef' templates.
-# And first: Protect against being on the right side of a sed subst in
-# config.status.  Protect against being in an unquoted here document
-# in config.status.
-rm -f conftest.defines conftest.undefs
-# Using a here document instead of a string reduces the quoting nightmare.
-# Putting comments in sed scripts is not portable.
-#
-# `end' is used to avoid that the second main sed command (meant for
-# 0-ary CPP macros) applies to n-ary macro definitions.
-# See the Autoconf documentation for `clear'.
-cat >confdef2sed.sed <<\_ACEOF
-s/[\\&,]/\\&/g
-s,[\\$`],\\&,g
-t clear
-: clear
-s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 (][^	 (]*\)\(([^)]*)\)[	 ]*\(.*\)$,${ac_dA}\1${ac_dB}\1\2${ac_dC}\3${ac_dD},gp
-t end
-s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 ][^	 ]*\)[	 ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp
-: end
-_ACEOF
-# If some macros were called several times there might be several times
-# the same #defines, which is useless.  Nevertheless, we may not want to
-# sort them, since we want the *last* AC-DEFINE to be honored.
-uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines
-sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs
-rm -f confdef2sed.sed
+uniq confdefs.h |
+  sed -n '
+	t rset
+	:rset
+	s/^[	 ]*#[	 ]*define[	 ][	 ]*//
+	t ok
+	d
+	:ok
+	s/[\\&,]/\\&/g
+	s/^\('"$ac_word_re"'\)\(([^()]*)\)[	 ]*\(.*\)/ '"$ac_dA"'\1'"$ac_dB"'\2'"${ac_dC}"'\3'"$ac_dD"'/p
+	s/^\('"$ac_word_re"'\)[	 ]*\(.*\)/'"$ac_dA"'\1'"$ac_dB$ac_dC"'\2'"$ac_dD"'/p
+  ' >>conftest.defines
 
-# This sed command replaces #undef with comments.  This is necessary, for
+# Remove the space that was appended to ease matching.
+# Then replace #undef with comments.  This is necessary, for
 # example, in the case of _POSIX_SOURCE, which is predefined and required
 # on some systems where configure will not decide to define it.
-cat >>conftest.undefs <<\_ACEOF
-s,^[	 ]*#[	 ]*undef[	 ][	 ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */,
-_ACEOF
+# (The regexp can be short, since the line contains either #define or #undef.)
+echo 's/ $//
+s,^[	 #]*u.*,/* & */,' >>conftest.defines
+
+# Break up conftest.defines:
+ac_max_sed_lines=50
+
+# First sed command is:	 sed -f defines.sed $ac_file_inputs >"$tmp/out1"
+# Second one is:	 sed -f defines.sed "$tmp/out1" >"$tmp/out2"
+# Third one will be:	 sed -f defines.sed "$tmp/out2" >"$tmp/out1"
+# et cetera.
+ac_in='$ac_file_inputs'
+ac_out='"$tmp/out1"'
+ac_nxt='"$tmp/out2"'
 
-# Break up conftest.defines because some shells have a limit on the size
-# of here documents, and old seds have small limits too (100 cmds).
-echo '  # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS
-echo '  if grep "^[	 ]*#[	 ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS
-echo '  # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS
-echo '  :' >>$CONFIG_STATUS
-rm -f conftest.tail
-while grep . conftest.defines >/dev/null
-do
-  # Write a limited-size here document to $tmp/defines.sed.
-  echo '  cat >$tmp/defines.sed <<CEOF' >>$CONFIG_STATUS
-  # Speed up: don't consider the non `#define' lines.
-  echo '/^[	 ]*#[	 ]*define/!b' >>$CONFIG_STATUS
-  # Work around the forget-to-reset-the-flag bug.
-  echo 't clr' >>$CONFIG_STATUS
-  echo ': clr' >>$CONFIG_STATUS
-  sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS
+while :
+do
+  # Write a here document:
+    cat >>$CONFIG_STATUS <<_ACEOF
+    # First, check the format of the line:
+    cat >"\$tmp/defines.sed" <<\\CEOF
+/^[	 ]*#[	 ]*undef[	 ][	 ]*$ac_word_re[	 ]*\$/b def
+/^[	 ]*#[	 ]*define[	 ][	 ]*$ac_word_re[(	 ]/b def
+b
+:def
+_ACEOF
+  sed ${ac_max_sed_lines}q conftest.defines >>$CONFIG_STATUS
   echo 'CEOF
-  sed -f $tmp/defines.sed $tmp/in >$tmp/out
-  rm -f $tmp/in
-  mv $tmp/out $tmp/in
-' >>$CONFIG_STATUS
-  sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail
+    sed -f "$tmp/defines.sed"' "$ac_in >$ac_out" >>$CONFIG_STATUS
+  ac_in=$ac_out; ac_out=$ac_nxt; ac_nxt=$ac_in
+  sed 1,${ac_max_sed_lines}d conftest.defines >conftest.tail
+  grep . conftest.tail >/dev/null || break
   rm -f conftest.defines
   mv conftest.tail conftest.defines
 done
-rm -f conftest.defines
-echo '  fi # grep' >>$CONFIG_STATUS
-echo >>$CONFIG_STATUS
-
-# Break up conftest.undefs because some shells have a limit on the size
-# of here documents, and old seds have small limits too (100 cmds).
-echo '  # Handle all the #undef templates' >>$CONFIG_STATUS
-rm -f conftest.tail
-while grep . conftest.undefs >/dev/null
-do
-  # Write a limited-size here document to $tmp/undefs.sed.
-  echo '  cat >$tmp/undefs.sed <<CEOF' >>$CONFIG_STATUS
-  # Speed up: don't consider the non `#undef'
-  echo '/^[	 ]*#[	 ]*undef/!b' >>$CONFIG_STATUS
-  # Work around the forget-to-reset-the-flag bug.
-  echo 't clr' >>$CONFIG_STATUS
-  echo ': clr' >>$CONFIG_STATUS
-  sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS
-  echo 'CEOF
-  sed -f $tmp/undefs.sed $tmp/in >$tmp/out
-  rm -f $tmp/in
-  mv $tmp/out $tmp/in
-' >>$CONFIG_STATUS
-  sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail
-  rm -f conftest.undefs
-  mv conftest.tail conftest.undefs
-done
-rm -f conftest.undefs
+rm -f conftest.defines conftest.tail
 
+echo "ac_result=$ac_in" >>$CONFIG_STATUS
 cat >>$CONFIG_STATUS <<\_ACEOF
-  # Let's still pretend it is `configure' which instantiates (i.e., don't
-  # use $as_me), people would be surprised to read:
-  #    /* config.h.  Generated by config.status.  */
-  if test x"$ac_file" = x-; then
-    echo "/* Generated by configure.  */" >$tmp/config.h
-  else
-    echo "/* $ac_file.  Generated by configure.  */" >$tmp/config.h
-  fi
-  cat $tmp/in >>$tmp/config.h
-  rm -f $tmp/in
   if test x"$ac_file" != x-; then
-    if diff $ac_file $tmp/config.h >/dev/null 2>&1; then
+    echo "/* $configure_input  */" >"$tmp/config.h"
+    cat "$ac_result" >>"$tmp/config.h"
+    if diff $ac_file "$tmp/config.h" >/dev/null 2>&1; then
       { echo "$as_me:$LINENO: $ac_file is unchanged" >&5
 echo "$as_me: $ac_file is unchanged" >&6;}
     else
-      ac_dir=`(dirname "$ac_file") 2>/dev/null ||
-$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-	 X"$ac_file" : 'X\(//\)[^/]' \| \
-	 X"$ac_file" : 'X\(//\)$' \| \
-	 X"$ac_file" : 'X\(/\)' \| \
-	 .     : '\(.\)' 2>/dev/null ||
-echo X"$ac_file" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
-  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
-  	  /^X\(\/\/\)$/{ s//\1/; q; }
-  	  /^X\(\/\).*/{ s//\1/; q; }
-  	  s/.*/./; q'`
-      { if $as_mkdir_p; then
-    mkdir -p "$ac_dir"
-  else
-    as_dir="$ac_dir"
-    as_dirs=
-    while test ! -d "$as_dir"; do
-      as_dirs="$as_dir $as_dirs"
-      as_dir=`(dirname "$as_dir") 2>/dev/null ||
-$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-	 X"$as_dir" : 'X\(//\)[^/]' \| \
-	 X"$as_dir" : 'X\(//\)$' \| \
-	 X"$as_dir" : 'X\(/\)' \| \
-	 .     : '\(.\)' 2>/dev/null ||
-echo X"$as_dir" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
-  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
-  	  /^X\(\/\/\)$/{ s//\1/; q; }
-  	  /^X\(\/\).*/{ s//\1/; q; }
-  	  s/.*/./; q'`
-    done
-    test ! -n "$as_dirs" || mkdir $as_dirs
-  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
-echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
-   { (exit 1); exit 1; }; }; }
-
       rm -f $ac_file
-      mv $tmp/config.h $ac_file
+      mv "$tmp/config.h" $ac_file
     fi
   else
-    cat $tmp/config.h
-    rm -f $tmp/config.h
+    echo "/* $configure_input  */"
+    cat "$ac_result"
   fi
+  rm -f "$tmp/out12"
+# Compute $ac_file's index in $config_headers.
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+  case $_am_header in
+    $ac_file | $ac_file:* )
+      break ;;
+    * )
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+  esac
 done
-_ACEOF
-cat >>$CONFIG_STATUS <<\_ACEOF
-
-#
-# CONFIG_LINKS section.
-#
-
-for ac_file in : $CONFIG_LINKS; do test "x$ac_file" = x: && continue
-  ac_dest=`echo "$ac_file" | sed 's,:.*,,'`
-  ac_source=`echo "$ac_file" | sed 's,[^:]*:,,'`
+echo "timestamp for $ac_file" >`$as_dirname -- $ac_file ||
+$as_expr X$ac_file : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X$ac_file : 'X\(//\)[^/]' \| \
+	 X$ac_file : 'X\(//\)$' \| \
+	 X$ac_file : 'X\(/\)' \| . 2>/dev/null ||
+echo X$ac_file |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`/stamp-h$_am_stamp_count
+ ;;
+  :L)
+  #
+  # CONFIG_LINK
+  #
 
-  { echo "$as_me:$LINENO: linking $srcdir/$ac_source to $ac_dest" >&5
-echo "$as_me: linking $srcdir/$ac_source to $ac_dest" >&6;}
+  { echo "$as_me:$LINENO: linking $srcdir/$ac_source to $ac_file" >&5
+echo "$as_me: linking $srcdir/$ac_source to $ac_file" >&6;}
 
-  if test ! -r $srcdir/$ac_source; then
+  if test ! -r "$srcdir/$ac_source"; then
     { { echo "$as_me:$LINENO: error: $srcdir/$ac_source: file not found" >&5
 echo "$as_me: error: $srcdir/$ac_source: file not found" >&2;}
    { (exit 1); exit 1; }; }
   fi
-  rm -f $ac_dest
-
-  # Make relative symlinks.
-  ac_dest_dir=`(dirname "$ac_dest") 2>/dev/null ||
-$as_expr X"$ac_dest" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-	 X"$ac_dest" : 'X\(//\)[^/]' \| \
-	 X"$ac_dest" : 'X\(//\)$' \| \
-	 X"$ac_dest" : 'X\(/\)' \| \
-	 .     : '\(.\)' 2>/dev/null ||
-echo X"$ac_dest" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
-  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
-  	  /^X\(\/\/\)$/{ s//\1/; q; }
-  	  /^X\(\/\).*/{ s//\1/; q; }
-  	  s/.*/./; q'`
-  { if $as_mkdir_p; then
-    mkdir -p "$ac_dest_dir"
-  else
-    as_dir="$ac_dest_dir"
-    as_dirs=
-    while test ! -d "$as_dir"; do
-      as_dirs="$as_dir $as_dirs"
-      as_dir=`(dirname "$as_dir") 2>/dev/null ||
-$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-	 X"$as_dir" : 'X\(//\)[^/]' \| \
-	 X"$as_dir" : 'X\(//\)$' \| \
-	 X"$as_dir" : 'X\(/\)' \| \
-	 .     : '\(.\)' 2>/dev/null ||
-echo X"$as_dir" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
-  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
-  	  /^X\(\/\/\)$/{ s//\1/; q; }
-  	  /^X\(\/\).*/{ s//\1/; q; }
-  	  s/.*/./; q'`
-    done
-    test ! -n "$as_dirs" || mkdir $as_dirs
-  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dest_dir\"" >&5
-echo "$as_me: error: cannot create directory \"$ac_dest_dir\"" >&2;}
-   { (exit 1); exit 1; }; }; }
-
-  ac_builddir=.
-
-if test "$ac_dest_dir" != .; then
-  ac_dir_suffix=/`echo "$ac_dest_dir" | sed 's,^\.[\\/],,'`
-  # A "../" for each directory in $ac_dir_suffix.
-  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
-else
-  ac_dir_suffix= ac_top_builddir=
-fi
-
-case $srcdir in
-  .)  # No --srcdir option.  We are building in place.
-    ac_srcdir=.
-    if test -z "$ac_top_builddir"; then
-       ac_top_srcdir=.
-    else
-       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
-    fi ;;
-  [\\/]* | ?:[\\/]* )  # Absolute path.
-    ac_srcdir=$srcdir$ac_dir_suffix;
-    ac_top_srcdir=$srcdir ;;
-  *) # Relative path.
-    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
-    ac_top_srcdir=$ac_top_builddir$srcdir ;;
-esac
-
-# Do not use `cd foo && pwd` to compute absolute paths, because
-# the directories may not exist.
-case `pwd` in
-.) ac_abs_builddir="$ac_dest_dir";;
-*)
-  case "$ac_dest_dir" in
-  .) ac_abs_builddir=`pwd`;;
-  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dest_dir";;
-  *) ac_abs_builddir=`pwd`/"$ac_dest_dir";;
-  esac;;
-esac
-case $ac_abs_builddir in
-.) ac_abs_top_builddir=${ac_top_builddir}.;;
-*)
-  case ${ac_top_builddir}. in
-  .) ac_abs_top_builddir=$ac_abs_builddir;;
-  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
-  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
-  esac;;
-esac
-case $ac_abs_builddir in
-.) ac_abs_srcdir=$ac_srcdir;;
-*)
-  case $ac_srcdir in
-  .) ac_abs_srcdir=$ac_abs_builddir;;
-  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
-  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
-  esac;;
-esac
-case $ac_abs_builddir in
-.) ac_abs_top_srcdir=$ac_top_srcdir;;
-*)
-  case $ac_top_srcdir in
-  .) ac_abs_top_srcdir=$ac_abs_builddir;;
-  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
-  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
-  esac;;
-esac
-
+  rm -f "$ac_file"
 
+  # Try a relative symlink, then a hard link, then a copy.
   case $srcdir in
   [\\/$]* | ?:[\\/]* ) ac_rel_source=$srcdir/$ac_source ;;
-      *) ac_rel_source=$ac_top_builddir$srcdir/$ac_source ;;
+      *) ac_rel_source=$ac_top_build_prefix$srcdir/$ac_source ;;
   esac
-
-  # Try a symlink, then a hard link, then a copy.
-  ln -s $ac_rel_source $ac_dest 2>/dev/null ||
-    ln $srcdir/$ac_source $ac_dest 2>/dev/null ||
-    cp -p $srcdir/$ac_source $ac_dest ||
-    { { echo "$as_me:$LINENO: error: cannot link or copy $srcdir/$ac_source to $ac_dest" >&5
-echo "$as_me: error: cannot link or copy $srcdir/$ac_source to $ac_dest" >&2;}
+  ln -s "$ac_rel_source" "$ac_file" 2>/dev/null ||
+    ln "$srcdir/$ac_source" "$ac_file" 2>/dev/null ||
+    cp -p "$srcdir/$ac_source" "$ac_file" ||
+    { { echo "$as_me:$LINENO: error: cannot link or copy $srcdir/$ac_source to $ac_file" >&5
+echo "$as_me: error: cannot link or copy $srcdir/$ac_source to $ac_file" >&2;}
    { (exit 1); exit 1; }; }
-done
-_ACEOF
-cat >>$CONFIG_STATUS <<\_ACEOF
+ ;;
+  :C)  { echo "$as_me:$LINENO: executing $ac_file commands" >&5
+echo "$as_me: executing $ac_file commands" >&6;}
+ ;;
+  esac
 
-#
-# CONFIG_COMMANDS section.
-#
-for ac_file in : $CONFIG_COMMANDS; do test "x$ac_file" = x: && continue
-  ac_dest=`echo "$ac_file" | sed 's,:.*,,'`
-  ac_source=`echo "$ac_file" | sed 's,[^:]*:,,'`
-  ac_dir=`(dirname "$ac_dest") 2>/dev/null ||
-$as_expr X"$ac_dest" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-	 X"$ac_dest" : 'X\(//\)[^/]' \| \
-	 X"$ac_dest" : 'X\(//\)$' \| \
-	 X"$ac_dest" : 'X\(/\)' \| \
-	 .     : '\(.\)' 2>/dev/null ||
-echo X"$ac_dest" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
-  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
-  	  /^X\(\/\/\)$/{ s//\1/; q; }
-  	  /^X\(\/\).*/{ s//\1/; q; }
-  	  s/.*/./; q'`
-  { if $as_mkdir_p; then
-    mkdir -p "$ac_dir"
+
+  case $ac_file$ac_mode in
+    "depfiles":C) test x"$AMDEP_TRUE" != x"" || for mf in $CONFIG_FILES; do
+  # Strip MF so we end up with the name of the file.
+  mf=`echo "$mf" | sed -e 's/:.*$//'`
+  # Check whether this is an Automake generated Makefile or not.
+  # We used to match only the files named `Makefile.in', but
+  # some people rename them; so instead we look at the file content.
+  # Grep'ing the first line is not enough: some people post-process
+  # each Makefile.in and add a new line on top of each file to say so.
+  # Grep'ing the whole file is not good either: AIX grep has a line
+  # limit of 2048, but all sed's we know have understand at least 4000.
+  if sed 10q "$mf" | grep '^#.*generated by automake' > /dev/null 2>&1; then
+    dirpart=`$as_dirname -- "$mf" ||
+$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$mf" : 'X\(//\)[^/]' \| \
+	 X"$mf" : 'X\(//\)$' \| \
+	 X"$mf" : 'X\(/\)' \| . 2>/dev/null ||
+echo X"$mf" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
   else
-    as_dir="$ac_dir"
+    continue
+  fi
+  # Extract the definition of DEPDIR, am__include, and am__quote
+  # from the Makefile without running `make'.
+  DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
+  test -z "$DEPDIR" && continue
+  am__include=`sed -n 's/^am__include = //p' < "$mf"`
+  test -z "am__include" && continue
+  am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+  # When using ansi2knr, U may be empty or an underscore; expand it
+  U=`sed -n 's/^U = //p' < "$mf"`
+  # Find all dependency output files, they are included files with
+  # $(DEPDIR) in their names.  We invoke sed twice because it is the
+  # simplest approach to changing $(DEPDIR) to its actual value in the
+  # expansion.
+  for file in `sed -n "
+    s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
+       sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
+    # Make sure the directory exists.
+    test -f "$dirpart/$file" && continue
+    fdir=`$as_dirname -- "$file" ||
+$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$file" : 'X\(//\)[^/]' \| \
+	 X"$file" : 'X\(//\)$' \| \
+	 X"$file" : 'X\(/\)' \| . 2>/dev/null ||
+echo X"$file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+    { as_dir=$dirpart/$fdir
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || {
     as_dirs=
-    while test ! -d "$as_dir"; do
-      as_dirs="$as_dir $as_dirs"
-      as_dir=`(dirname "$as_dir") 2>/dev/null ||
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
 $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
 	 X"$as_dir" : 'X\(//\)[^/]' \| \
 	 X"$as_dir" : 'X\(//\)$' \| \
-	 X"$as_dir" : 'X\(/\)' \| \
-	 .     : '\(.\)' 2>/dev/null ||
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
 echo X"$as_dir" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
-  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
-  	  /^X\(\/\/\)$/{ s//\1/; q; }
-  	  /^X\(\/\).*/{ s//\1/; q; }
-  	  s/.*/./; q'`
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
     done
-    test ! -n "$as_dirs" || mkdir $as_dirs
-  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
-echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || { { echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5
+echo "$as_me: error: cannot create directory $as_dir" >&2;}
    { (exit 1); exit 1; }; }; }
-
-  ac_builddir=.
-
-if test "$ac_dir" != .; then
-  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
-  # A "../" for each directory in $ac_dir_suffix.
-  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
-else
-  ac_dir_suffix= ac_top_builddir=
-fi
-
-case $srcdir in
-  .)  # No --srcdir option.  We are building in place.
-    ac_srcdir=.
-    if test -z "$ac_top_builddir"; then
-       ac_top_srcdir=.
-    else
-       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
-    fi ;;
-  [\\/]* | ?:[\\/]* )  # Absolute path.
-    ac_srcdir=$srcdir$ac_dir_suffix;
-    ac_top_srcdir=$srcdir ;;
-  *) # Relative path.
-    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
-    ac_top_srcdir=$ac_top_builddir$srcdir ;;
-esac
-
-# Do not use `cd foo && pwd` to compute absolute paths, because
-# the directories may not exist.
-case `pwd` in
-.) ac_abs_builddir="$ac_dir";;
-*)
-  case "$ac_dir" in
-  .) ac_abs_builddir=`pwd`;;
-  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
-  *) ac_abs_builddir=`pwd`/"$ac_dir";;
-  esac;;
-esac
-case $ac_abs_builddir in
-.) ac_abs_top_builddir=${ac_top_builddir}.;;
-*)
-  case ${ac_top_builddir}. in
-  .) ac_abs_top_builddir=$ac_abs_builddir;;
-  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
-  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
-  esac;;
-esac
-case $ac_abs_builddir in
-.) ac_abs_srcdir=$ac_srcdir;;
-*)
-  case $ac_srcdir in
-  .) ac_abs_srcdir=$ac_abs_builddir;;
-  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
-  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
-  esac;;
-esac
-case $ac_abs_builddir in
-.) ac_abs_top_srcdir=$ac_top_srcdir;;
-*)
-  case $ac_top_srcdir in
-  .) ac_abs_top_srcdir=$ac_abs_builddir;;
-  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
-  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
-  esac;;
-esac
-
-
-  { echo "$as_me:$LINENO: executing $ac_dest commands" >&5
-echo "$as_me: executing $ac_dest commands" >&6;}
-  case $ac_dest in
-    include ) test -d include || mkdir include ;;
-    src )
+    # echo "creating $dirpart/$file"
+    echo '# dummy' > "$dirpart/$file"
+  done
+done
+ ;;
+    "include":C) test -d include || mkdir include ;;
+    "src":C)
 test -d src || mkdir src
 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
  ;;
+
   esac
-done
-_ACEOF
+done # for ac_tag
 
-cat >>$CONFIG_STATUS <<\_ACEOF
 
 { (exit 0); exit 0; }
 _ACEOF

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/configure.ac
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/configure.ac	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/configure.ac	Thu Mar 27 00:48:05 2008
@@ -2,12 +2,21 @@
 
 AC_PREREQ(2.59)
 
-AC_INIT([libffi], [2.1], [http://gcc.gnu.org/bugs.html])
+AC_INIT([libffi], [3.0.4], [http://gcc.gnu.org/bugs.html])
 AC_CONFIG_HEADERS([fficonfig.h])
 
 AC_CANONICAL_SYSTEM
 target_alias=${target_alias-$host_alias}
 
+. ${srcdir}/configure.host
+
+AM_INIT_AUTOMAKE
+
+# The same as in boehm-gc and libstdc++. Have to borrow it from there.
+# We must force CC to /not/ be precious variables; otherwise
+# the wrong, non-multilib-adjusted value will be used in multilibs.
+# As a side effect, we have to subst CFLAGS ourselves.
+
 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
 m4_define([_AC_ARG_VAR_PRECIOUS],[])
 AC_PROG_CC
@@ -15,79 +24,162 @@
 
 AC_SUBST(CFLAGS)
 
+AM_PROG_AS
+AM_PROG_CC_C_O
+AC_PROG_LIBTOOL
+
+AM_MAINTAINER_MODE
+
 AC_CHECK_HEADERS(sys/mman.h)
 AC_CHECK_FUNCS(mmap)
 AC_FUNC_MMAP_BLACKLIST
 
+dnl The -no-testsuite modules omit the test subdir.
+AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
+
 TARGETDIR="unknown"
 case "$host" in
-x86_64-*-openbsd*) TARGET=X86_64; TARGETDIR=x86;;
-mips*-*-openbsd*) TARGET=MIPS; TARGETDIR=mips;;
-sparc-*-openbsd*) TARGET=SPARC; TARGETDIR=sparc;;
-sparc64-*-openbsd*) TARGET=SPARC; TARGETDIR=sparc;;
-alpha*-*-openbsd*) TARGET=ALPHA; TARGETDIR=alpha;;
-m68k-*-openbsd*) TARGET=M68K; TARGETDIR=m68k;;
-powerpc-*-openbsd*) TARGET=POWERPC; TARGETDIR=powerpc;;
-i*86-*-darwin*) TARGET=X86_DARWIN; TARGETDIR=x86;;
-i*86-*-linux*) TARGET=X86; TARGETDIR=x86;;
-i*86-*-gnu*) TARGET=X86; TARGETDIR=x86;;
-i*86-*-solaris2.1[[0-9]]*) TARGET=X86_64; TARGETDIR=x86;;
-i*86-*-solaris*) TARGET=X86; TARGETDIR=x86;;
-i*86-*-beos*) TARGET=X86; TARGETDIR=x86;;
-i*86-*-freebsd* | i*86-*-kfreebsd*-gnu) TARGET=X86; TARGETDIR=x86;;
-i*86-*-netbsdelf* | i*86-*-knetbsd*-gnu) TARGET=X86; TARGETDIR=x86;;
-i*86-*-openbsd*) TARGET=X86; TARGETDIR=x86;;
-i*86-*-rtems*) TARGET=X86; TARGETDIR=x86;;
-i*86-*-win32*) TARGET=X86_WIN32; TARGETDIR=x86;;
-i*86-*-cygwin*) TARGET=X86_WIN32; TARGETDIR=x86;;
-i*86-*-mingw*) TARGET=X86_WIN32; TARGETDIR=x86;;
-frv-*-*) TARGET=FRV; TARGETDIR=frv;;
-sparc-sun-4*) TARGET=SPARC; TARGETDIR=sparc;;
-sparc*-sun-*) TARGET=SPARC; TARGETDIR=sparc;;
-sparc-*-linux* | sparc-*-netbsdelf* | sparc-*-knetbsd*-gnu) TARGET=SPARC; TARGETDIR=sparc;;
-sparc*-*-rtems*) TARGET=SPARC; TARGETDIR=sparc;;
-sparc64-*-linux* | sparc64-*-freebsd* | sparc64-*-netbsd* | sparc64-*-knetbsd*-gnu) TARGET=SPARC; TARGETDIR=sparc;;
-alpha*-*-linux* | alpha*-*-osf* | alpha*-*-freebsd* | alpha*-*-kfreebsd*-gnu | alpha*-*-netbsd* | alpha*-*-knetbsd*-gnu) TARGET=ALPHA; TARGETDIR=alpha;;
-ia64*-*-*) TARGET=IA64; TARGETDIR=ia64;;
-m32r*-*-linux* ) TARGET=M32R; TARGETDIR=m32r;;
-m68k-*-linux*) TARGET=M68K; TARGETDIR=m68k;;
-mips64*-*);;
-mips-sgi-irix5.* | mips-sgi-irix6.*) TARGET=MIPS_IRIX; TARGETDIR=mips;;
-mips*-*-linux*) TARGET=MIPS_LINUX; TARGETDIR=mips;;
-powerpc*-*-linux* | powerpc-*-sysv*) TARGET=POWERPC; TARGETDIR=powerpc;;
-powerpc-*-beos*) TARGET=POWERPC; TARGETDIR=powerpc;;
-powerpc-*-darwin*) TARGET=POWERPC_DARWIN; TARGETDIR=powerpc;;
-powerpc-*-aix*) TARGET=POWERPC_AIX; TARGETDIR=powerpc;;
-powerpc-*-freebsd*) TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc;;
-powerpc*-*-rtems*) TARGET=POWERPC; TARGETDIR=powerpc;;
-rs6000-*-aix*) TARGET=POWERPC_AIX; TARGETDIR=powerpc;;
-arm*-*-linux-*) TARGET=ARM; TARGETDIR=arm;;
-arm*-*-netbsdelf* | arm*-*-knetbsd*-gnu) TARGET=ARM; TARGETDIR=arm;;
-arm*-*-rtems*) TARGET=ARM; TARGETDIR=arm;;
-cris-*-*) TARGET=LIBFFI_CRIS; TARGETDIR=cris;;
-s390-*-linux-*) TARGET=S390; TARGETDIR=s390;;
-s390x-*-linux-*) TARGET=S390; TARGETDIR=s390;;
-x86_64-*-linux* | x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu) TARGET=X86_64; TARGETDIR=x86;;
-sh-*-linux* | sh[[34]]*-*-linux*) TARGET=SH; TARGETDIR=sh;;
-sh-*-rtems*) TARGET=SH; TARGETDIR=sh;;
-sh64-*-linux* | sh5*-*-linux*) TARGET=SH64; TARGETDIR=sh64;;
-hppa*-*-linux* | parisc*-*-linux*) TARGET=PA; TARGETDIR=pa;;
+  alpha*-*-*)
+	TARGET=ALPHA; TARGETDIR=alpha;
+	# Support 128-bit long double, changable via command-line switch.
+	HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)'
+	;;
+
+  arm*-*-*)
+	TARGET=ARM; TARGETDIR=arm
+	;;
+
+  amd64-*-freebsd*)
+	TARGET=X86_64; TARGETDIR=x86
+  	;;
+
+  cris-*-*)
+	TARGET=LIBFFI_CRIS; TARGETDIR=cris
+	;;
+
+  frv-*-*)
+	TARGET=FRV; TARGETDIR=frv
+	;;
+
+  hppa*-*-linux* | parisc*-*-linux*)
+	TARGET=PA_LINUX; TARGETDIR=pa
+	;;
+  hppa*64-*-hpux*)
+	TARGET=PA64_HPUX; TARGETDIR=pa
+	;;
+  hppa*-*-hpux*)
+	TARGET=PA_HPUX; TARGETDIR=pa
+	;;
+
+  i386-*-freebsd* | i386-*-openbsd*)
+	TARGET=X86_FREEBSD; TARGETDIR=x86
+	;;
+  i?86-win32* | i?86-*-cygwin* | i?86-*-mingw*)
+	TARGET=X86_WIN32; TARGETDIR=x86
+	;;
+  i?86-*-darwin*)
+	TARGET=X86_DARWIN; TARGETDIR=x86
+	;;
+  i?86-*-solaris2.1[[0-9]]*)
+	TARGET=X86_64; TARGETDIR=x86
+	;;
+  i?86-*-*)
+	TARGET=X86; TARGETDIR=x86
+	;;
+
+  ia64*-*-*)
+	TARGET=IA64; TARGETDIR=ia64
+	;;
+
+  m32r*-*-*)
+	TARGET=M32R; TARGETDIR=m32r
+	;;
+
+  m68k-*-*)
+	TARGET=M68K; TARGETDIR=m68k
+	;;
+
+  mips-sgi-irix5.* | mips-sgi-irix6.*)
+	TARGET=MIPS; TARGETDIR=mips
+	;;
+  mips*-*-linux*)
+	TARGET=MIPS; TARGETDIR=mips
+	;;
+
+  powerpc*-*-linux* | powerpc-*-sysv*)
+	TARGET=POWERPC; TARGETDIR=powerpc
+	;;
+  powerpc-*-beos*)
+	TARGET=POWERPC; TARGETDIR=powerpc
+	;;
+  powerpc-*-darwin*)
+	TARGET=POWERPC_DARWIN; TARGETDIR=powerpc
+	;;
+  powerpc-*-aix* | rs6000-*-aix*)
+	TARGET=POWERPC_AIX; TARGETDIR=powerpc
+	;;
+  powerpc-*-freebsd*)
+	TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
+	;;
+  powerpc*-*-rtems*)
+	TARGET=POWERPC; TARGETDIR=powerpc
+	;;
+
+  s390-*-* | s390x-*-*)
+	TARGET=S390; TARGETDIR=s390
+	;;
+
+  sh-*-* | sh[[34]]*-*-*)
+	TARGET=SH; TARGETDIR=sh
+	;;
+  sh64-*-* | sh5*-*-*)
+	TARGET=SH64; TARGETDIR=sh64
+	;;
+
+  sparc*-*-*)
+	TARGET=SPARC; TARGETDIR=sparc
+	;;
+
+  x86_64-*-darwin*)
+	TARGET=X86_DARWIN; TARGETDIR=x86
+	;;
+  x86_64-*-cygwin* | x86_64-*-mingw*)
+	;;
+  x86_64-*-*)
+	TARGET=X86_64; TARGETDIR=x86
+	;;
 esac
 
+AC_SUBST(AM_RUNTESTFLAGS)
+
 if test $TARGETDIR = unknown; then
   AC_MSG_ERROR(["libffi has not been ported to $host."])
 fi
 
-dnl  libffi changes TARGET for MIPS to define a such macro in the header
-dnl  while MIPS_IRIX or MIPS_LINUX is separatedly used to decide which
-dnl  files will be compiled.  So, we need to keep the original decision
-dnl  of TARGET to use in fficonfig.py.in.
-MKTARGET=$TARGET
-
-case x$TARGET in
-  xMIPS*) TARGET=MIPS ;;
-  *) ;;
-esac
+AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
+AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
+AM_CONDITIONAL(X86, test x$TARGET = xX86)
+AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD)
+AM_CONDITIONAL(X86_WIN32, test x$TARGET = xX86_WIN32)
+AM_CONDITIONAL(X86_DARWIN, test x$TARGET = xX86_DARWIN)
+AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
+AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
+AM_CONDITIONAL(M32R, test x$TARGET = xM32R)
+AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
+AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
+AM_CONDITIONAL(POWERPC_AIX, test x$TARGET = xPOWERPC_AIX)
+AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN)
+AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD)
+AM_CONDITIONAL(ARM, test x$TARGET = xARM)
+AM_CONDITIONAL(LIBFFI_CRIS, test x$TARGET = xLIBFFI_CRIS)
+AM_CONDITIONAL(FRV, test x$TARGET = xFRV)
+AM_CONDITIONAL(S390, test x$TARGET = xS390)
+AM_CONDITIONAL(X86_64, test x$TARGET = xX86_64)
+AM_CONDITIONAL(SH, test x$TARGET = xSH)
+AM_CONDITIONAL(SH64, test x$TARGET = xSH64)
+AM_CONDITIONAL(PA_LINUX, test x$TARGET = xPA_LINUX)
+AM_CONDITIONAL(PA_HPUX, test x$TARGET = xPA_HPUX)
+AM_CONDITIONAL(PA64_HPUX, test x$TARGET = xPA64_HPUX)
 
 AC_HEADER_STDC
 AC_CHECK_FUNCS(memcpy)
@@ -97,45 +189,30 @@
 AC_CHECK_SIZEOF(long double)
 
 # Also AC_SUBST this variable for ffi.h.
-HAVE_LONG_DOUBLE=0
-if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
-  if test $ac_cv_sizeof_long_double != 0; then
-    HAVE_LONG_DOUBLE=1
-    AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
+if test -z "$HAVE_LONG_DOUBLE"; then
+  HAVE_LONG_DOUBLE=0
+  if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
+    if test $ac_cv_sizeof_long_double != 0; then
+      HAVE_LONG_DOUBLE=1
+      AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
+    fi
   fi
 fi
 AC_SUBST(HAVE_LONG_DOUBLE)
 
-AC_MSG_CHECKING(for _Bool support)
-have_c99_bool=no
-AC_TRY_COMPILE([], [_Bool x; x = (_Bool)0;], [
-  AC_DEFINE(HAVE_C99_BOOL, 1, [Define this if you have the type _Bool.]) 
-  have_c99_bool=yes
-])
-AC_MSG_RESULT($have_c99_bool)
-if test "$have_c99_bool" = yes ; then
-AC_CHECK_SIZEOF(_Bool, 1)
-fi
-
 AC_C_BIGENDIAN
-AH_VERBATIM([WORDS_BIGENDIAN],
-[
-/* Define to 1 if your processor stores words with the most significant byte
-   first (like Motorola and SPARC, unlike Intel and VAX). 
-
-   The block below does compile-time checking for endianness on platforms
-   that use GCC and therefore allows compiling fat binaries on OSX by using
-   '-arch ppc -arch i386' as the compile flags. The phrasing was choosen
-   such that the configure-result is used on systems that don't use GCC.
-*/
-#ifdef __BIG_ENDIAN__
-#define WORDS_BIGENDIAN 1
-#else
-#ifndef __LITTLE_ENDIAN__
-#undef WORDS_BIGENDIAN
-#endif
-#endif])
 
+AC_CACHE_CHECK([assembler .cfi pseudo-op support],
+    libffi_cv_as_cfi_pseudo_op, [
+    libffi_cv_as_cfi_pseudo_op=unknown
+    AC_TRY_COMPILE([asm (".cfi_startproc\n\t.cfi_endproc");],,
+		   [libffi_cv_as_cfi_pseudo_op=yes],
+		   [libffi_cv_as_cfi_pseudo_op=no])
+])
+if test "x$libffi_cv_as_cfi_pseudo_op" = xyes; then
+    AC_DEFINE(HAVE_AS_CFI_PSEUDO_OP, 1,
+	      [Define if your assembler supports .cfi_* directives.])
+fi
 
 if test x$TARGET = xSPARC; then
     AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
@@ -226,11 +303,54 @@
 
 AC_SUBST(TARGET)
 AC_SUBST(TARGETDIR)
-AC_SUBST(MKTARGET)
 
 AC_SUBST(SHELL)
 
-AC_DEFINE(FFI_NO_RAW_API, 1, [Define this is you do not want support for the raw API.])
+AC_ARG_ENABLE(debug,
+[  --enable-debug          debugging mode],
+  if test "$enable_debug" = "yes"; then
+    AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
+  fi)
+
+AC_ARG_ENABLE(structs,
+[  --disable-structs       omit code for struct support],
+  if test "$enable_structs" = "no"; then
+    AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this is you do not want support for aggregate types.])
+  fi)
+
+AC_ARG_ENABLE(raw-api,
+[  --disable-raw-api       make the raw api unavailable],
+  if test "$enable_raw_api" = "no"; then
+    AC_DEFINE(FFI_NO_RAW_API, 1, [Define this is you do not want support for the raw API.])
+  fi)
+
+AC_ARG_ENABLE(purify-safety,
+[  --enable-purify-safety  purify-safe mode],
+  if test "$enable_purify_safety" = "yes"; then
+    AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
+  fi)
+
+if test -n "$with_cross_host" &&
+   test x"$with_cross_host" != x"no"; then
+  toolexecdir='$(exec_prefix)/$(target_alias)'
+  toolexeclibdir='$(toolexecdir)/lib'
+else
+  toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+  toolexeclibdir='$(libdir)'
+fi
+multi_os_directory=`$CC -print-multi-os-directory`
+case $multi_os_directory in
+  .) ;; # Avoid trailing /.
+  *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
+esac
+AC_SUBST(toolexecdir)
+AC_SUBST(toolexeclibdir)
+
+if test "${multilib}" = "yes"; then
+  multilib_arg="--enable-multilib"
+else
+  multilib_arg=
+fi
 
 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
 AC_CONFIG_COMMANDS(src, [
@@ -238,17 +358,12 @@
 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
 ], [TARGETDIR="$TARGETDIR"])
 
-TARGETINCDIR=$TARGETDIR
-case $host in
-*-*-darwin*)
-   TARGETINCDIR="darwin"
-   ;;
-esac
+AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
 
+AC_CONFIG_FILES(include/ffi.h)
 
-AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETINCDIR/ffitarget.h)
 AC_CONFIG_LINKS(include/ffi_common.h:include/ffi_common.h)
 
-AC_CONFIG_FILES(include/ffi.h fficonfig.py)
+AC_CONFIG_FILES(fficonfig.py)
 
 AC_OUTPUT

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/fficonfig.h.in
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/fficonfig.h.in	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/fficonfig.h.in	Thu Mar 27 00:48:05 2008
@@ -11,9 +11,15 @@
 /* Define to the flags needed for the .section .eh_frame directive. */
 #undef EH_FRAME_FLAGS
 
+/* Define this if you want extra debugging. */
+#undef FFI_DEBUG
+
 /* Define this is you do not want support for the raw API. */
 #undef FFI_NO_RAW_API
 
+/* Define this is you do not want support for aggregate types. */
+#undef FFI_NO_STRUCTS
+
 /* Define to 1 if you have `alloca', as a function or macro. */
 #undef HAVE_ALLOCA
 
@@ -21,6 +27,9 @@
    */
 #undef HAVE_ALLOCA_H
 
+/* Define if your assembler supports .cfi_* directives. */
+#undef HAVE_AS_CFI_PSEUDO_OP
+
 /* Define if your assembler supports .register. */
 #undef HAVE_AS_REGISTER_PSEUDO_OP
 
@@ -28,8 +37,8 @@
    */
 #undef HAVE_AS_SPARC_UA_PCREL
 
-/* Define this if you have the type _Bool. */
-#undef HAVE_C99_BOOL
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
 
 /* Define if __attribute__((visibility("hidden"))) is supported. */
 #undef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
@@ -85,6 +94,12 @@
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
+/* Define to 1 if your C compiler doesn't accept -c and -o together. */
+#undef NO_MINUS_C_MINUS_O
+
+/* Name of package */
+#undef PACKAGE
+
 /* Define to the address where bug reports for this package should be sent. */
 #undef PACKAGE_BUGREPORT
 
@@ -100,18 +115,15 @@
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
-/* The size of a `double', as computed by sizeof. */
+/* The size of `double', as computed by sizeof. */
 #undef SIZEOF_DOUBLE
 
-/* The size of a `long double', as computed by sizeof. */
+/* The size of `long double', as computed by sizeof. */
 #undef SIZEOF_LONG_DOUBLE
 
-/* The size of a `_Bool', as computed by sizeof. */
-#undef SIZEOF__BOOL
-
 /* If using the C implementation of alloca, define if you know the
    direction of stack growth for your system; otherwise it will be
-   automatically deduced at run-time.
+   automatically deduced at runtime.
 	STACK_DIRECTION > 0 => grows toward higher addresses
 	STACK_DIRECTION < 0 => grows toward lower addresses
 	STACK_DIRECTION = 0 => direction of growth unknown */
@@ -120,22 +132,16 @@
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
+/* Define this if you are using Purify and want to suppress spurious messages.
+   */
+#undef USING_PURIFY
 
-/* Define to 1 if your processor stores words with the most significant byte
-   first (like Motorola and SPARC, unlike Intel and VAX). 
+/* Version number of package */
+#undef VERSION
 
-   The block below does compile-time checking for endianness on platforms
-   that use GCC and therefore allows compiling fat binaries on OSX by using
-   '-arch ppc -arch i386' as the compile flags. The phrasing was choosen
-   such that the configure-result is used on systems that don't use GCC.
-*/
-#ifdef __BIG_ENDIAN__
-#define WORDS_BIGENDIAN 1
-#else
-#ifndef __LITTLE_ENDIAN__
+/* Define to 1 if your processor stores words with the most significant byte
+   first (like Motorola and SPARC, unlike Intel and VAX). */
 #undef WORDS_BIGENDIAN
-#endif
-#endif
 
 
 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/fficonfig.py.in
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/fficonfig.py.in	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/fficonfig.py.in	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,7 @@
     'MIPS_IRIX': ['src/mips/ffi.c', 'src/mips/o32.S', 'src/mips/n32.S'],
     'MIPS_LINUX': ['src/mips/ffi.c', 'src/mips/o32.S'],
     'X86': ['src/x86/ffi.c', 'src/x86/sysv.S'],
-    'X86_DARWIN': ['src/x86/ffi_darwin.c', 'src/x86/darwin.S'],
+    'X86_FREEBSD': ['src/x86/ffi.c', 'src/x86/sysv.S'],
     'X86_WIN32': ['src/x86/ffi.c', 'src/x86/win32.S'],
     'SPARC': ['src/sparc/ffi.c', 'src/sparc/v8.S', 'src/sparc/v9.S'],
     'ALPHA': ['src/alpha/ffi.c', 'src/alpha/osf.S'],
@@ -14,8 +14,7 @@
     'M32R': ['src/m32r/sysv.S', 'src/m32r/ffi.c'],
     'M68K': ['src/m68k/ffi.c', 'src/m68k/sysv.S'],
     'POWERPC': ['src/powerpc/ffi.c', 'src/powerpc/sysv.S', 'src/powerpc/ppc_closure.S', 'src/powerpc/linux64.S', 'src/powerpc/linux64_closure.S'],
-    'POWERPC_AIX': ['src/powerpc/ffi_darwin.c', 'src/powerpc/aix.S', 'src/powerpc/aix_closure.S'],
-    'POWERPC_DARWIN': ['src/powerpc/ffi_darwin.c', 'src/powerpc/darwin.S', 'src/powerpc/darwin_closure.S'],
+    'POWERPC_AIX': ['src/powerpc/ffi.c', 'src/powerpc/aix.S', 'src/powerpc/aix_closure.S'],
     'POWERPC_FREEBSD': ['src/powerpc/ffi.c', 'src/powerpc/sysv.S', 'src/powerpc/ppc_closure.S'],
     'ARM': ['src/arm/sysv.S', 'src/arm/ffi.c'],
     'LIBFFI_CRIS': ['src/cris/sysv.S', 'src/cris/ffi.c'],
@@ -25,21 +24,11 @@
     'SH': ['src/sh/sysv.S', 'src/sh/ffi.c'],
     'SH64': ['src/sh64/sysv.S', 'src/sh64/ffi.c'],
     'PA': ['src/pa/linux.S', 'src/pa/ffi.c'],
+    'PA_LINUX': ['src/pa/linux.S', 'src/pa/ffi.c'],
 }
 
-# Build all darwin related files on all supported darwin architectures, this
-# makes it easier to build universal binaries.
-if 1:
-    all_darwin = ('X86_DARWIN', 'POWERPC_DARWIN')
-    all_darwin_files = []
-    for pn in all_darwin:
-        all_darwin_files.extend(ffi_platforms[pn])
-    for pn in all_darwin:
-        ffi_platforms[pn] = all_darwin_files
-    del all_darwin, all_darwin_files, pn
-
 ffi_srcdir = '@srcdir@'
-ffi_sources += ffi_platforms['@MKTARGET@']
+ffi_sources += ffi_platforms['@TARGET@']
 ffi_sources = [os.path.join('@srcdir@', f) for f in ffi_sources]
 
 ffi_cflags = '@CFLAGS@'

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/include/ffi.h.in
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/include/ffi.h.in	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/include/ffi.h.in	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------*-C-*-
-   libffi @VERSION@ - Copyright (c) 1996-2003  Red Hat, Inc.
+   libffi @VERSION@ - Copyright (c) 1996-2003, 2007, 2008  Red Hat, Inc.
 
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
@@ -12,13 +12,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 
@@ -82,6 +83,18 @@
 # endif
 #endif
 
+/* The closure code assumes that this works on pointers, i.e. a size_t	*/
+/* can hold a pointer.							*/
+
+typedef struct _ffi_type
+{
+  size_t size;
+  unsigned short alignment;
+  unsigned short type;
+  struct _ffi_type **elements;
+} ffi_type;
+
+#ifndef LIBFFI_HIDE_BASIC_TYPES
 #if SCHAR_MAX == 127
 # define ffi_type_uchar                ffi_type_uint8
 # define ffi_type_schar                ffi_type_sint8
@@ -112,26 +125,23 @@
  #error "int size not supported"
 #endif
 
-#define ffi_type_ulong         ffi_type_uint64
-#define ffi_type_slong         ffi_type_sint64
 #if LONG_MAX == 2147483647
 # if FFI_LONG_LONG_MAX != 9223372036854775807
-  #error "no 64-bit data type supported"
+ #error "no 64-bit data type supported"
 # endif
 #elif LONG_MAX != 9223372036854775807
  #error "long size not supported"
 #endif
 
-/* The closure code assumes that this works on pointers, i.e. a size_t	*/
-/* can hold a pointer.							*/
-
-typedef struct _ffi_type
-{
-  size_t size;
-  unsigned short alignment;
-  unsigned short type;
-  /*@null@*/ struct _ffi_type **elements;
-} ffi_type;
+#if LONG_MAX == 2147483647
+# define ffi_type_ulong        ffi_type_uint32
+# define ffi_type_slong        ffi_type_sint32
+#elif LONG_MAX == 9223372036854775807
+# define ffi_type_ulong        ffi_type_uint64
+# define ffi_type_slong        ffi_type_sint64
+#else
+ #error "long size not supported"
+#endif
 
 /* These are defined in types.c */
 extern ffi_type ffi_type_void;
@@ -145,14 +155,19 @@
 extern ffi_type ffi_type_sint64;
 extern ffi_type ffi_type_float;
 extern ffi_type ffi_type_double;
-extern ffi_type ffi_type_longdouble;
 extern ffi_type ffi_type_pointer;
 
+#if @HAVE_LONG_DOUBLE@
+extern ffi_type ffi_type_longdouble;
+#else
+#define ffi_type_longdouble ffi_type_double
+#endif
+#endif /* LIBFFI_HIDE_BASIC_TYPES */
 
 typedef enum {
   FFI_OK = 0,
   FFI_BAD_TYPEDEF,
-  FFI_BAD_ABI 
+  FFI_BAD_ABI
 } ffi_status;
 
 typedef unsigned FFI_TYPE;
@@ -160,8 +175,8 @@
 typedef struct {
   ffi_abi abi;
   unsigned nargs;
-  /*@dependent@*/ ffi_type **arg_types;
-  /*@dependent@*/ ffi_type *rtype;
+  ffi_type **arg_types;
+  ffi_type *rtype;
   unsigned bytes;
   unsigned flags;
 #ifdef FFI_EXTRA_CIF_FIELDS
@@ -179,6 +194,10 @@
 # endif
 #endif
 
+#ifndef FFI_SIZEOF_JAVA_RAW
+#  define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG
+#endif
+
 typedef union {
   ffi_sarg  sint;
   ffi_arg   uint;
@@ -187,10 +206,25 @@
   void*     ptr;
 } ffi_raw;
 
-void ffi_raw_call (/*@dependent@*/ ffi_cif *cif, 
-		   void (*fn)(void), 
-		   /*@out@*/ void *rvalue, 
-		   /*@dependent@*/ ffi_raw *avalue);
+#if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8
+/* This is a special case for mips64/n32 ABI (and perhaps others) where
+   sizeof(void *) is 4 and FFI_SIZEOF_ARG is 8.  */
+typedef union {
+  signed int	sint;
+  unsigned int	uint;
+  float		flt;
+  char		data[FFI_SIZEOF_JAVA_RAW];
+  void*		ptr;
+} ffi_java_raw;
+#else
+typedef ffi_raw ffi_java_raw;
+#endif
+
+
+void ffi_raw_call (ffi_cif *cif,
+		   void (*fn)(void),
+		   void *rvalue,
+		   ffi_raw *avalue);
 
 void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
 void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
@@ -200,13 +234,13 @@
 /* packing, even on 64-bit machines.  I.e. on 64-bit machines		*/
 /* longs and doubles are followed by an empty 64-bit word.		*/
 
-void ffi_java_raw_call (/*@dependent@*/ ffi_cif *cif, 
-		        void (*fn)(void), 
-		        /*@out@*/ void *rvalue, 
-		        /*@dependent@*/ ffi_raw *avalue);
+void ffi_java_raw_call (ffi_cif *cif,
+			void (*fn)(void),
+			void *rvalue,
+			ffi_java_raw *avalue);
 
-void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
-void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
+void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw);
+void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args);
 size_t ffi_java_raw_size (ffi_cif *cif);
 
 /* ---- Definitions for closures ----------------------------------------- */
@@ -220,12 +254,22 @@
   void      *user_data;
 } ffi_closure __attribute__((aligned (8)));
 
+void *ffi_closure_alloc (size_t size, void **code);
+void ffi_closure_free (void *);
+
 ffi_status
 ffi_prep_closure (ffi_closure*,
 		  ffi_cif *,
 		  void (*fun)(ffi_cif*,void*,void**,void*),
 		  void *user_data);
 
+ffi_status
+ffi_prep_closure_loc (ffi_closure*,
+		      ffi_cif *,
+		      void (*fun)(ffi_cif*,void*,void**,void*),
+		      void *user_data,
+		      void*codeloc);
+
 typedef struct {
   char tramp[FFI_TRAMPOLINE_SIZE];
 
@@ -247,6 +291,27 @@
 
 } ffi_raw_closure;
 
+typedef struct {
+  char tramp[FFI_TRAMPOLINE_SIZE];
+
+  ffi_cif   *cif;
+
+#if !FFI_NATIVE_RAW_API
+
+  /* if this is enabled, then a raw closure has the same layout 
+     as a regular closure.  We use this to install an intermediate 
+     handler to do the transaltion, void** -> ffi_raw*. */
+
+  void     (*translate_args)(ffi_cif*,void*,void**,void*);
+  void      *this_closure;
+
+#endif
+
+  void     (*fun)(ffi_cif*,void*,ffi_java_raw*,void*);
+  void      *user_data;
+
+} ffi_java_raw_closure;
+
 ffi_status
 ffi_prep_raw_closure (ffi_raw_closure*,
 		      ffi_cif *cif,
@@ -254,28 +319,42 @@
 		      void *user_data);
 
 ffi_status
-ffi_prep_java_raw_closure (ffi_raw_closure*,
+ffi_prep_raw_closure_loc (ffi_raw_closure*,
+			  ffi_cif *cif,
+			  void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
+			  void *user_data,
+			  void *codeloc);
+
+ffi_status
+ffi_prep_java_raw_closure (ffi_java_raw_closure*,
 		           ffi_cif *cif,
-		           void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
+		           void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
 		           void *user_data);
 
+ffi_status
+ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*,
+			       ffi_cif *cif,
+			       void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
+			       void *user_data,
+			       void *codeloc);
+
 #endif /* FFI_CLOSURES */
 
 /* ---- Public interface definition -------------------------------------- */
 
-ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif, 
+ffi_status ffi_prep_cif(ffi_cif *cif,
 			ffi_abi abi,
-			unsigned int nargs, 
-			/*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type *rtype, 
-			/*@dependent@*/ ffi_type **atypes);
-
-void ffi_call(/*@dependent@*/ ffi_cif *cif, 
-	      void (*fn)(void), 
-	      /*@out@*/ void *rvalue, 
-	      /*@dependent@*/ void **avalue);
+			unsigned int nargs,
+			ffi_type *rtype,
+			ffi_type **atypes);
+
+void ffi_call(ffi_cif *cif,
+	      void (*fn)(void),
+	      void *rvalue,
+	      void **avalue);
 
 /* Useful for eliminating compiler warnings */
-#define FFI_FN(f) ((void (*)())f)
+#define FFI_FN(f) ((void (*)(void))f)
 
 /* ---- Definitions shared with assembly code ---------------------------- */
 
@@ -310,4 +389,3 @@
 #endif
 
 #endif
-

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/include/ffi_common.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/include/ffi_common.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/include/ffi_common.h	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------------
    ffi_common.h - Copyright (c) 1996  Red Hat, Inc.
+   Copyright (C) 2007 Free Software Foundation, Inc
 
    Common internal definitions and macros. Only necessary for building
    libffi.
@@ -18,7 +19,9 @@
    this is positioned. */
 #ifdef __GNUC__
 # define alloca __builtin_alloca
+# define MAYBE_UNUSED __attribute__((__unused__))
 #else
+# define MAYBE_UNUSED
 # if HAVE_ALLOCA_H
 #  include <alloca.h>
 # else
@@ -41,20 +44,20 @@
 # endif
 #endif
 
-#if defined(FFI_DEBUG) 
+#if defined(FFI_DEBUG)
 #include <stdio.h>
 #endif
 
 #ifdef FFI_DEBUG
-/*@exits@*/ void ffi_assert(/*@temp@*/ char *expr, /*@temp@*/ char *file, int line);
+void ffi_assert(char *expr, char *file, int line);
 void ffi_stop_here(void);
-void ffi_type_test(/*@temp@*/ /*@out@*/ ffi_type *a, /*@temp@*/ char *file, int line);
+void ffi_type_test(ffi_type *a, char *file, int line);
 
 #define FFI_ASSERT(x) ((x) ? (void)0 : ffi_assert(#x, __FILE__,__LINE__))
 #define FFI_ASSERT_AT(x, f, l) ((x) ? 0 : ffi_assert(#x, (f), (l)))
 #define FFI_ASSERT_VALID_TYPE(x) ffi_type_test (x, __FILE__, __LINE__)
 #else
-#define FFI_ASSERT(x) 
+#define FFI_ASSERT(x)
 #define FFI_ASSERT_AT(x, f, l)
 #define FFI_ASSERT_VALID_TYPE(x)
 #endif
@@ -68,9 +71,9 @@
 /* Extended cif, used in callback from assembly routine */
 typedef struct
 {
-  /*@dependent@*/ ffi_cif *cif;
-  /*@dependent@*/ void *rvalue;
-  /*@dependent@*/ void **avalue;
+  ffi_cif *cif;
+  void *rvalue;
+  void **avalue;
 } extended_cif;
 
 /* Terse sized type definitions.  */

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/install-sh
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/install-sh	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/install-sh	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,8 @@
 #!/bin/sh
-#
 # install - install a program, script, or datafile
-#
+
+scriptversion=2004-12-17.09
+
 # This originates from X11R5 (mit/util/scripts/install.sh), which was
 # later released in X11R6 (xc/config/util/install.sh) with the
 # following copyright and license.
@@ -41,13 +42,11 @@
 # from scratch.  It can only install one file at a time, a restriction
 # shared with many OS's install programs.
 
-
 # set DOITPROG to echo to test this script
 
 # Don't use :- since 4.3BSD and earlier shells don't like it.
 doit="${DOITPROG-}"
 
-
 # put in absolute paths if you don't have them in your path; or use env. vars.
 
 mvprog="${MVPROG-mv}"
@@ -59,236 +58,266 @@
 rmprog="${RMPROG-rm}"
 mkdirprog="${MKDIRPROG-mkdir}"
 
-transformbasename=""
-transform_arg=""
-instcmd="$mvprog"
 chmodcmd="$chmodprog 0755"
-chowncmd=""
-chgrpcmd=""
-stripcmd=""
+chowncmd=
+chgrpcmd=
+stripcmd=
 rmcmd="$rmprog -f"
 mvcmd="$mvprog"
-src=""
-dst=""
-dir_arg=""
-
-while [ x"$1" != x ]; do
-    case $1 in
-	-c) instcmd=$cpprog
-	    shift
-	    continue;;
-
-	-d) dir_arg=true
-	    shift
-	    continue;;
-
-	-m) chmodcmd="$chmodprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-o) chowncmd="$chownprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-g) chgrpcmd="$chgrpprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-s) stripcmd=$stripprog
-	    shift
-	    continue;;
-
-	-t=*) transformarg=`echo $1 | sed 's/-t=//'`
-	    shift
-	    continue;;
-
-	-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
-	    shift
-	    continue;;
-
-	*)  if [ x"$src" = x ]
-	    then
-		src=$1
-	    else
-		# this colon is to work around a 386BSD /bin/sh bug
-		:
-		dst=$1
-	    fi
-	    shift
-	    continue;;
-    esac
-done
-
-if [ x"$src" = x ]
-then
-	echo "$0: no input file specified" >&2
-	exit 1
-else
-	:
-fi
+src=
+dst=
+dir_arg=
+dstarg=
+no_target_directory=
+
+usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
+   or: $0 [OPTION]... SRCFILES... DIRECTORY
+   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
+   or: $0 [OPTION]... -d DIRECTORIES...
+
+In the 1st form, copy SRCFILE to DSTFILE.
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
+In the 4th, create DIRECTORIES.
+
+Options:
+-c         (ignored)
+-d         create directories instead of installing files.
+-g GROUP   $chgrpprog installed files to GROUP.
+-m MODE    $chmodprog installed files to MODE.
+-o USER    $chownprog installed files to USER.
+-s         $stripprog installed files.
+-t DIRECTORY  install into DIRECTORY.
+-T         report an error if DSTFILE is a directory.
+--help     display this help and exit.
+--version  display version info and exit.
+
+Environment variables override the default commands:
+  CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
+"
+
+while test -n "$1"; do
+  case $1 in
+    -c) shift
+        continue;;
+
+    -d) dir_arg=true
+        shift
+        continue;;
+
+    -g) chgrpcmd="$chgrpprog $2"
+        shift
+        shift
+        continue;;
+
+    --help) echo "$usage"; exit 0;;
+
+    -m) chmodcmd="$chmodprog $2"
+        shift
+        shift
+        continue;;
+
+    -o) chowncmd="$chownprog $2"
+        shift
+        shift
+        continue;;
+
+    -s) stripcmd=$stripprog
+        shift
+        continue;;
 
-if [ x"$dir_arg" != x ]; then
-	dst=$src
-	src=""
-
-	if [ -d "$dst" ]; then
-		instcmd=:
-		chmodcmd=""
-	else
-		instcmd=$mkdirprog
-	fi
-else
-
-# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
-# might cause directories to be created, which would be especially bad
-# if $src (and thus $dsttmp) contains '*'.
-
-	if [ -f "$src" ] || [ -d "$src" ]
-	then
-		:
-	else
-		echo "$0: $src does not exist" >&2
-		exit 1
-	fi
-
-	if [ x"$dst" = x ]
-	then
-		echo "$0: no destination specified" >&2
-		exit 1
-	else
-		:
-	fi
-
-# If destination is a directory, append the input filename; if your system
-# does not like double slashes in filenames, you may need to add some logic
-
-	if [ -d "$dst" ]
-	then
-		dst=$dst/`basename "$src"`
-	else
-		:
-	fi
-fi
-
-## this sed command emulates the dirname command
-dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
-
-# Make sure that the destination directory exists.
-#  this part is taken from Noah Friedman's mkinstalldirs script
-
-# Skip lots of stat calls in the usual case.
-if [ ! -d "$dstdir" ]; then
-defaultIFS='
-	'
-IFS="${IFS-$defaultIFS}"
-
-oIFS=$IFS
-# Some sh's can't handle IFS=/ for some reason.
-IFS='%'
-set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
-IFS=$oIFS
-
-pathcomp=''
+    -t) dstarg=$2
+	shift
+	shift
+	continue;;
 
-while [ $# -ne 0 ] ; do
-	pathcomp=$pathcomp$1
+    -T) no_target_directory=true
 	shift
+	continue;;
 
-	if [ ! -d "$pathcomp" ] ;
-        then
-		$mkdirprog "$pathcomp"
-	else
-		:
-	fi
+    --version) echo "$0 $scriptversion"; exit 0;;
 
-	pathcomp=$pathcomp/
+    *)  # When -d is used, all remaining arguments are directories to create.
+	# When -t is used, the destination is already specified.
+	test -n "$dir_arg$dstarg" && break
+        # Otherwise, the last argument is the destination.  Remove it from $@.
+	for arg
+	do
+          if test -n "$dstarg"; then
+	    # $@ is not empty: it contains at least $arg.
+	    set fnord "$@" "$dstarg"
+	    shift # fnord
+	  fi
+	  shift # arg
+	  dstarg=$arg
+	done
+	break;;
+  esac
 done
-fi
-
-if [ x"$dir_arg" != x ]
-then
-	$doit $instcmd "$dst" &&
-
-	if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
-	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
-	if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
-	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
-else
-
-# If we're going to rename the final executable, determine the name now.
 
-	if [ x"$transformarg" = x ]
-	then
-		dstfile=`basename "$dst"`
-	else
-		dstfile=`basename "$dst" $transformbasename |
-			sed $transformarg`$transformbasename
-	fi
-
-# don't allow the sed command to completely eliminate the filename
-
-	if [ x"$dstfile" = x ]
-	then
-		dstfile=`basename "$dst"`
-	else
-		:
-	fi
-
-# Make a couple of temp file names in the proper directory.
-
-	dsttmp=$dstdir/#inst.$$#
-	rmtmp=$dstdir/#rm.$$#
-
-# Trap to clean up temp files at exit.
-
-	trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
-	trap '(exit $?); exit' 1 2 13 15
-
-# Move or copy the file name to the temp name
-
-	$doit $instcmd "$src" "$dsttmp" &&
-
-# and set any options; do chmod last to preserve setuid bits
-
-# If any of these fail, we abort the whole thing.  If we want to
-# ignore errors from any of these, just make sure not to ignore
-# errors from the above "$doit $instcmd $src $dsttmp" command.
-
-	if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
-	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
-	if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
-	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
-
-# Now remove or move aside any old file at destination location.  We try this
-# two ways since rm can't unlink itself on some systems and the destination
-# file might be busy for other reasons.  In this case, the final cleanup
-# might fail but the new file should still install successfully.
-
-{
-	if [ -f "$dstdir/$dstfile" ]
-	then
-		$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
-		$doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
-		{
-		  echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
-		  (exit 1); exit
-		}
-	else
-		:
-	fi
-} &&
-
-# Now rename the file to the real destination.
+if test -z "$1"; then
+  if test -z "$dir_arg"; then
+    echo "$0: no input file specified." >&2
+    exit 1
+  fi
+  # It's OK to call `install-sh -d' without argument.
+  # This can happen when creating conditional directories.
+  exit 0
+fi
 
-	$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
+for src
+do
+  # Protect names starting with `-'.
+  case $src in
+    -*) src=./$src ;;
+  esac
+
+  if test -n "$dir_arg"; then
+    dst=$src
+    src=
+
+    if test -d "$dst"; then
+      mkdircmd=:
+      chmodcmd=
+    else
+      mkdircmd=$mkdirprog
+    fi
+  else
+    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
+    # might cause directories to be created, which would be especially bad
+    # if $src (and thus $dsttmp) contains '*'.
+    if test ! -f "$src" && test ! -d "$src"; then
+      echo "$0: $src does not exist." >&2
+      exit 1
+    fi
+
+    if test -z "$dstarg"; then
+      echo "$0: no destination specified." >&2
+      exit 1
+    fi
+
+    dst=$dstarg
+    # Protect names starting with `-'.
+    case $dst in
+      -*) dst=./$dst ;;
+    esac
 
-fi &&
+    # If destination is a directory, append the input filename; won't work
+    # if double slashes aren't ignored.
+    if test -d "$dst"; then
+      if test -n "$no_target_directory"; then
+	echo "$0: $dstarg: Is a directory" >&2
+	exit 1
+      fi
+      dst=$dst/`basename "$src"`
+    fi
+  fi
+
+  # This sed command emulates the dirname command.
+  dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
+
+  # Make sure that the destination directory exists.
+
+  # Skip lots of stat calls in the usual case.
+  if test ! -d "$dstdir"; then
+    defaultIFS='
+	 '
+    IFS="${IFS-$defaultIFS}"
+
+    oIFS=$IFS
+    # Some sh's can't handle IFS=/ for some reason.
+    IFS='%'
+    set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
+    shift
+    IFS=$oIFS
+
+    pathcomp=
+
+    while test $# -ne 0 ; do
+      pathcomp=$pathcomp$1
+      shift
+      if test ! -d "$pathcomp"; then
+        $mkdirprog "$pathcomp"
+	# mkdir can fail with a `File exist' error in case several
+	# install-sh are creating the directory concurrently.  This
+	# is OK.
+	test -d "$pathcomp" || exit
+      fi
+      pathcomp=$pathcomp/
+    done
+  fi
+
+  if test -n "$dir_arg"; then
+    $doit $mkdircmd "$dst" \
+      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
+      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
+      && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
+      && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
+
+  else
+    dstfile=`basename "$dst"`
+
+    # Make a couple of temp file names in the proper directory.
+    dsttmp=$dstdir/_inst.$$_
+    rmtmp=$dstdir/_rm.$$_
+
+    # Trap to clean up those temp files at exit.
+    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
+    trap '(exit $?); exit' 1 2 13 15
+
+    # Copy the file name to the temp name.
+    $doit $cpprog "$src" "$dsttmp" &&
+
+    # and set any options; do chmod last to preserve setuid bits.
+    #
+    # If any of these fail, we abort the whole thing.  If we want to
+    # ignore errors from any of these, just make sure not to ignore
+    # errors from the above "$doit $cpprog $src $dsttmp" command.
+    #
+    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
+      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
+      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
+      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
+
+    # Now rename the file to the real destination.
+    { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
+      || {
+	   # The rename failed, perhaps because mv can't rename something else
+	   # to itself, or perhaps because mv is so ancient that it does not
+	   # support -f.
+
+	   # Now remove or move aside any old file at destination location.
+	   # We try this two ways since rm can't unlink itself on some
+	   # systems and the destination file might be busy for other
+	   # reasons.  In this case, the final cleanup might fail but the new
+	   # file should still install successfully.
+	   {
+	     if test -f "$dstdir/$dstfile"; then
+	       $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
+	       || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
+	       || {
+		 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
+		 (exit 1); exit 1
+	       }
+	     else
+	       :
+	     fi
+	   } &&
+
+	   # Now rename the file to the real destination.
+	   $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
+	 }
+    }
+  fi || { (exit 1); exit 1; }
+done
 
 # The final little trick to "correctly" pass the exit status to the exit trap.
-
 {
-	(exit 0); exit
+  (exit 0); exit 0
 }
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
+# End:

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/alpha/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/alpha/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/alpha/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1998, 2001 Red Hat, Inc.
+   ffi.c - Copyright (c) 1998, 2001, 2007, 2008  Red Hat, Inc.
    
    Alpha Foreign Function Interface 
 
@@ -14,22 +14,34 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #include <ffi.h>
 #include <ffi_common.h>
-
 #include <stdlib.h>
 
-extern void ffi_call_osf(void *, unsigned long, unsigned, void *, void (*)());
-extern void ffi_closure_osf(void);
+/* Force FFI_TYPE_LONGDOUBLE to be different than FFI_TYPE_DOUBLE;
+   all further uses in this file will refer to the 128-bit type.  */
+#if defined(__LONG_DOUBLE_128__)
+# if FFI_TYPE_LONGDOUBLE != 4
+#  error FFI_TYPE_LONGDOUBLE out of date
+# endif
+#else
+# undef FFI_TYPE_LONGDOUBLE
+# define FFI_TYPE_LONGDOUBLE 4
+#endif
+
+extern void ffi_call_osf(void *, unsigned long, unsigned, void *, void (*)(void))
+  FFI_HIDDEN;
+extern void ffi_closure_osf(void) FFI_HIDDEN;
 
 
 ffi_status
@@ -49,6 +61,11 @@
       cif->flags = cif->rtype->type;
       break;
 
+    case FFI_TYPE_LONGDOUBLE:
+      /* 128-bit long double is returned in memory, like a struct.  */
+      cif->flags = FFI_TYPE_STRUCT;
+      break;
+
     default:
       cif->flags = FFI_TYPE_INT;
       break;
@@ -57,15 +74,14 @@
   return FFI_OK;
 }
 
+
 void
-ffi_call(ffi_cif *cif, void (*fn)(), void *rvalue, void **avalue)
+ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   unsigned long *stack, *argp;
   long i, avn;
   ffi_type **arg_types;
   
-  FFI_ASSERT (cif->abi == FFI_OSF);
-
   /* If the return value is a struct and we don't have a return
      value address then we need to make one.  */
   if (rvalue == NULL && cif->flags == FFI_TYPE_STRUCT)
@@ -84,6 +100,8 @@
 
   while (i < avn)
     {
+      size_t size = (*arg_types)->size;
+
       switch ((*arg_types)->type)
 	{
 	case FFI_TYPE_SINT8:
@@ -129,6 +147,12 @@
 	  *(double *) argp = *(double *)(* avalue);
 	  break;
 
+	case FFI_TYPE_LONGDOUBLE:
+	  /* 128-bit long double is passed by reference.  */
+	  *(long double **) argp = (long double *)(* avalue);
+	  size = sizeof (long double *);
+	  break;
+
 	case FFI_TYPE_STRUCT:
 	  memcpy(argp, *avalue, (*arg_types)->size);
 	  break;
@@ -137,7 +161,7 @@
 	  FFI_ASSERT(0);
 	}
 
-      argp += ALIGN((*arg_types)->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
+      argp += ALIGN(size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
       i++, arg_types++, avalue++;
     }
 
@@ -146,15 +170,14 @@
 
 
 ffi_status
-ffi_prep_closure (ffi_closure* closure,
-		  ffi_cif* cif,
-		  void (*fun)(ffi_cif*, void*, void**, void*),
-		  void *user_data)
+ffi_prep_closure_loc (ffi_closure* closure,
+		      ffi_cif* cif,
+		      void (*fun)(ffi_cif*, void*, void**, void*),
+		      void *user_data,
+		      void *codeloc)
 {
   unsigned int *tramp;
 
-  FFI_ASSERT (cif->abi == FFI_OSF);
-
   tramp = (unsigned int *) &closure->tramp[0];
   tramp[0] = 0x47fb0401;	/* mov $27,$1		*/
   tramp[1] = 0xa77b0010;	/* ldq $27,16($27)	*/
@@ -177,7 +200,8 @@
   return FFI_OK;
 }
 
-int
+
+long FFI_HIDDEN
 ffi_closure_osf_inner(ffi_closure *closure, void *rvalue, unsigned long *argp)
 {
   ffi_cif *cif;
@@ -205,6 +229,8 @@
   /* Grab the addresses of the arguments from the stack frame.  */
   while (i < avn)
     {
+      size_t size = arg_types[i]->size;
+
       switch (arg_types[i]->type)
 	{
 	case FFI_TYPE_SINT8:
@@ -236,16 +262,22 @@
 	  avalue[i] = &argp[argn - (argn < 6 ? 6 : 0)];
 	  break;
 
+	case FFI_TYPE_LONGDOUBLE:
+	  /* 128-bit long double is passed by reference.  */
+	  avalue[i] = (long double *) argp[argn];
+	  size = sizeof (long double *);
+	  break;
+
 	default:
-	  FFI_ASSERT(0);
+	  abort ();
 	}
 
-      argn += ALIGN(arg_types[i]->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
+      argn += ALIGN(size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
       i++;
     }
 
   /* Invoke the closure.  */
-  (closure->fun) (cif, rvalue, avalue, closure->user_data);
+  closure->fun (cif, rvalue, avalue, closure->user_data);
 
   /* Tell ffi_closure_osf how to perform return type promotions.  */
   return cif->rtype->type;

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/alpha/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/alpha/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/alpha/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -13,13 +13,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 
@@ -33,8 +34,8 @@
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
   FFI_OSF,
-  FFI_DEFAULT_ABI = FFI_OSF,
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_OSF
 } ffi_abi;
 #endif
 
@@ -45,4 +46,3 @@
 #define FFI_NATIVE_RAW_API 0
 
 #endif
-

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/alpha/osf.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/alpha/osf.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/alpha/osf.S	Thu Mar 27 00:48:05 2008
@@ -1,10 +1,8 @@
 /* -----------------------------------------------------------------------
-   osf.S - Copyright (c) 1998, 2001 Red Hat
+   osf.S - Copyright (c) 1998, 2001, 2007, 2008 Red Hat
    
    Alpha/OSF Foreign Function Interface 
 
-   $Id: osf.S,v 1.2 2006/03/03 20:24:26 theller Exp $
-
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    ``Software''), to deal in the Software without restriction, including
@@ -16,13 +14,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #define LIBFFI_ASM	
@@ -33,7 +32,7 @@
 	.text
 
 /* ffi_call_osf (void *args, unsigned long bytes, unsigned flags,
-		 void *raddr, void (*fnaddr)());
+		 void *raddr, void (*fnaddr)(void));
 
    Bit o trickiness here -- ARGS+BYTES is the base of the stack frame
    for this function.  This has been allocated by ffi_call.  We also
@@ -42,6 +41,8 @@
 	.align	3
 	.globl	ffi_call_osf
 	.ent	ffi_call_osf
+	FFI_HIDDEN(ffi_call_osf)
+
 ffi_call_osf:
 	.frame	$15, 32, $26, 0
 	.mask   0x4008000, -32
@@ -129,6 +130,8 @@
 	.align	3
 	.globl	ffi_closure_osf
 	.ent	ffi_closure_osf
+	FFI_HIDDEN(ffi_closure_osf)
+
 ffi_closure_osf:
 	.frame	$30, 16*8, $26, 0
 	.mask	0x4000000, -16*8
@@ -265,7 +268,7 @@
 	.gprel32 $load_32	# FFI_TYPE_INT
 	.gprel32 $load_float	# FFI_TYPE_FLOAT
 	.gprel32 $load_double	# FFI_TYPE_DOUBLE
-	.gprel32 $load_double	# FFI_TYPE_LONGDOUBLE
+	.gprel32 $load_none	# FFI_TYPE_LONGDOUBLE
 	.gprel32 $load_u8	# FFI_TYPE_UINT8
 	.gprel32 $load_s8	# FFI_TYPE_SINT8
 	.gprel32 $load_u16	# FFI_TYPE_UINT16
@@ -356,4 +359,8 @@
 	.byte	16		# uleb128 offset 16*-8
 	.align 3
 $LEFDE3:
+
+#ifdef __linux__
+	.section	.note.GNU-stack,"", at progbits
+#endif
 #endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/arm/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/arm/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/arm/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1998  Red Hat, Inc.
+   ffi.c - Copyright (c) 1998, 2008  Red Hat, Inc.
    
    ARM Foreign Function Interface 
 
@@ -14,13 +14,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #include <ffi.h>
@@ -31,9 +32,7 @@
 /* ffi_prep_args is called by the assembly routine once stack space
    has been allocated for the function's arguments */
 
-/*@-exportheader@*/
 void ffi_prep_args(char *stack, extended_cif *ecif)
-/*@=exportheader@*/
 {
   register unsigned int i;
   register void **p_argv;
@@ -42,7 +41,7 @@
 
   argp = stack;
 
-  if ( ecif->cif->rtype->type == FFI_TYPE_STRUCT ) {
+  if ( ecif->cif->flags == FFI_TYPE_STRUCT ) {
     *(void **) argp = ecif->rvalue;
     argp += 4;
   }
@@ -60,6 +59,9 @@
 	argp = (char *) ALIGN(argp, (*p_arg)->alignment);
       }
 
+      if ((*p_arg)->type == FFI_TYPE_STRUCT)
+	argp = (char *) ALIGN(argp, 4);
+
 	  z = (*p_arg)->size;
 	  if (z < sizeof(int))
 	    {
@@ -83,7 +85,7 @@
 		  break;
 		  
 		case FFI_TYPE_STRUCT:
-		  *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
+		  memcpy(argp, *p_argv, (*p_arg)->size);
 		  break;
 
 		default:
@@ -117,7 +119,6 @@
   switch (cif->rtype->type)
     {
     case FFI_TYPE_VOID:
-    case FFI_TYPE_STRUCT:
     case FFI_TYPE_FLOAT:
     case FFI_TYPE_DOUBLE:
       cif->flags = (unsigned) cif->rtype->type;
@@ -128,6 +129,17 @@
       cif->flags = (unsigned) FFI_TYPE_SINT64;
       break;
 
+    case FFI_TYPE_STRUCT:
+      if (cif->rtype->size <= 4)
+	/* A Composite Type not larger than 4 bytes is returned in r0.  */
+	cif->flags = (unsigned)FFI_TYPE_INT;
+      else
+	/* A Composite Type larger than 4 bytes, or whose size cannot
+	   be determined statically ... is stored in memory at an
+	   address passed [in r0].  */
+	cif->flags = (unsigned)FFI_TYPE_STRUCT;
+      break;
+
     default:
       cif->flags = FFI_TYPE_INT;
       break;
@@ -136,50 +148,162 @@
   return FFI_OK;
 }
 
-/*@-declundef@*/
-/*@-exportheader@*/
-extern void ffi_call_SYSV(void (*)(char *, extended_cif *), 
-			  /*@out@*/ extended_cif *, 
-			  unsigned, unsigned, 
-			  /*@out@*/ unsigned *, 
-			  void (*fn)());
-/*@=declundef@*/
-/*@=exportheader@*/
+extern void ffi_call_SYSV(void (*)(char *, extended_cif *), extended_cif *,
+			  unsigned, unsigned, unsigned *, void (*fn)(void));
 
-void ffi_call(/*@dependent@*/ ffi_cif *cif, 
-	      void (*fn)(), 
-	      /*@out@*/ void *rvalue, 
-	      /*@dependent@*/ void **avalue)
+void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   extended_cif ecif;
 
+  int small_struct = (cif->flags == FFI_TYPE_INT 
+		      && cif->rtype->type == FFI_TYPE_STRUCT);
+
   ecif.cif = cif;
   ecif.avalue = avalue;
+
+  unsigned int temp;
   
   /* If the return value is a struct and we don't have a return	*/
   /* value address then we need to make one		        */
 
   if ((rvalue == NULL) && 
-      (cif->rtype->type == FFI_TYPE_STRUCT))
+      (cif->flags == FFI_TYPE_STRUCT))
     {
-      /*@-sysunrecog@*/
       ecif.rvalue = alloca(cif->rtype->size);
-      /*@=sysunrecog@*/
     }
+  else if (small_struct)
+    ecif.rvalue = &temp;
   else
     ecif.rvalue = rvalue;
-    
-  
+
   switch (cif->abi) 
     {
     case FFI_SYSV:
-      /*@-usedef@*/
-      ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, 
-		    cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
+      ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, cif->flags, ecif.rvalue,
+		    fn);
+
       break;
     default:
       FFI_ASSERT(0);
       break;
     }
+  if (small_struct)
+    memcpy (rvalue, &temp, cif->rtype->size);
+}
+
+/** private members **/
+
+static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
+					 void** args, ffi_cif* cif);
+
+void ffi_closure_SYSV (ffi_closure *);
+
+/* This function is jumped to by the trampoline */
+
+unsigned int
+ffi_closure_SYSV_inner (closure, respp, args)
+     ffi_closure *closure;
+     void **respp;
+     void *args;
+{
+  // our various things...
+  ffi_cif       *cif;
+  void         **arg_area;
+
+  cif         = closure->cif;
+  arg_area    = (void**) alloca (cif->nargs * sizeof (void*));  
+
+  /* this call will initialize ARG_AREA, such that each
+   * element in that array points to the corresponding 
+   * value on the stack; and if the function returns
+   * a structure, it will re-set RESP to point to the
+   * structure return address.  */
+
+  ffi_prep_incoming_args_SYSV(args, respp, arg_area, cif);
+
+  (closure->fun) (cif, *respp, arg_area, closure->user_data);
+
+  return cif->flags;
+}
+
+/*@-exportheader@*/
+static void 
+ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
+			    void **avalue, ffi_cif *cif)
+/*@=exportheader@*/
+{
+  register unsigned int i;
+  register void **p_argv;
+  register char *argp;
+  register ffi_type **p_arg;
+
+  argp = stack;
+
+  if ( cif->flags == FFI_TYPE_STRUCT ) {
+    *rvalue = *(void **) argp;
+    argp += 4;
+  }
+
+  p_argv = avalue;
+
+  for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
+    {
+      size_t z;
+
+      size_t alignment = (*p_arg)->alignment;
+      if (alignment < 4)
+	alignment = 4;
+      /* Align if necessary */
+      if ((alignment - 1) & (unsigned) argp) {
+	argp = (char *) ALIGN(argp, alignment);
+      }
+
+      z = (*p_arg)->size;
+
+      /* because we're little endian, this is what it turns into.   */
+
+      *p_argv = (void*) argp;
+
+      p_argv++;
+      argp += z;
+    }
+  
+  return;
+}
+
+/* How to make a trampoline.  */
+
+#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX)				\
+({ unsigned char *__tramp = (unsigned char*)(TRAMP);			\
+   unsigned int  __fun = (unsigned int)(FUN);				\
+   unsigned int  __ctx = (unsigned int)(CTX);				\
+   *(unsigned int*) &__tramp[0] = 0xe92d000f; /* stmfd sp!, {r0-r3} */	\
+   *(unsigned int*) &__tramp[4] = 0xe59f0000; /* ldr r0, [pc] */	\
+   *(unsigned int*) &__tramp[8] = 0xe59ff000; /* ldr pc, [pc] */	\
+   *(unsigned int*) &__tramp[12] = __ctx;				\
+   *(unsigned int*) &__tramp[16] = __fun;				\
+   __clear_cache((&__tramp[0]), (&__tramp[19]));			\
+ })
+
+
+/* the cif must already be prep'ed */
+
+ffi_status
+ffi_prep_closure_loc (ffi_closure* closure,
+		      ffi_cif* cif,
+		      void (*fun)(ffi_cif*,void*,void**,void*),
+		      void *user_data,
+		      void *codeloc)
+{
+  FFI_ASSERT (cif->abi == FFI_SYSV);
+
+  FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
+		       &ffi_closure_SYSV,  \
+		       codeloc);
+    
+  closure->cif  = cif;
+  closure->user_data = user_data;
+  closure->fun  = fun;
+
+  return FFI_OK;
 }

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/arm/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/arm/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/arm/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -13,13 +13,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 
@@ -40,7 +41,8 @@
 
 /* ---- Definitions for closures ----------------------------------------- */
 
-#define FFI_CLOSURES 0
+#define FFI_CLOSURES 1
+#define FFI_TRAMPOLINE_SIZE 20
 #define FFI_NATIVE_RAW_API 0
 
 #endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/arm/sysv.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/arm/sysv.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/arm/sysv.S	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   sysv.S - Copyright (c) 1998 Red Hat, Inc.
+   sysv.S - Copyright (c) 1998, 2008 Red Hat, Inc.
    
    ARM Foreign Function Interface 
 
@@ -14,13 +14,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #define LIBFFI_ASM	
@@ -82,6 +83,14 @@
 # define call_reg(x)	mov	lr, pc ; mov	pc, x
 #endif
 
+/* Conditionally compile unwinder directives.  */
+#ifdef __ARM_EABI__
+#define UNWIND
+#else
+#define UNWIND @
+#endif	
+
+	
 #if defined(__thumb__) && !defined(__THUMB_INTERWORK__)
 .macro	ARM_FUNC_START name
 	.text
@@ -92,6 +101,7 @@
 	bx	pc
 	nop
 	.arm
+	UNWIND .fnstart
 /* A hook to tell gdb that we've switched to ARM mode.  Also used to call
    directly from other local arm routines.  */
 _L__\name:		
@@ -102,6 +112,7 @@
 	.align 0
 	.arm
 	ENTRY(\name)
+	UNWIND .fnstart
 .endm
 #endif
 
@@ -134,8 +145,11 @@
 ARM_FUNC_START ffi_call_SYSV
 	@ Save registers
         stmfd	sp!, {r0-r3, fp, lr}
+	UNWIND .save	{r0-r3, fp, lr}
 	mov	fp, sp
 
+	UNWIND .setfp	fp, sp
+
 	@ Make room for all of the new args.
 	sub	sp, fp, r2
 
@@ -205,5 +219,81 @@
 	RETLDM	"r0-r3,fp"
 
 .ffi_call_SYSV_end:
+	UNWIND .fnend
         .size    CNAME(ffi_call_SYSV),.ffi_call_SYSV_end-CNAME(ffi_call_SYSV)
 
+/*
+	unsigned int FFI_HIDDEN
+	ffi_closure_SYSV_inner (closure, respp, args)
+	     ffi_closure *closure;
+	     void **respp;
+  	     void *args;
+*/
+
+ARM_FUNC_START ffi_closure_SYSV
+	UNWIND .pad #16
+	add	ip, sp, #16
+	stmfd	sp!, {ip, lr}
+	UNWIND .save	{r0, lr}
+	add	r2, sp, #8
+	.pad #16
+	sub	sp, sp, #16
+	str	sp, [sp, #8]
+	add	r1, sp, #8
+	bl	ffi_closure_SYSV_inner
+	cmp	r0, #FFI_TYPE_INT
+	beq	.Lretint
+
+	cmp	r0, #FFI_TYPE_FLOAT
+#ifdef __SOFTFP__
+	beq	.Lretint
+#else
+	beq	.Lretfloat
+#endif
+
+	cmp	r0, #FFI_TYPE_DOUBLE
+#ifdef __SOFTFP__
+	beq	.Lretlonglong
+#else
+	beq	.Lretdouble
+#endif
+
+	cmp	r0, #FFI_TYPE_LONGDOUBLE
+#ifdef __SOFTFP__
+	beq	.Lretlonglong
+#else
+	beq	.Lretlongdouble
+#endif
+
+	cmp	r0, #FFI_TYPE_SINT64
+	beq	.Lretlonglong
+.Lclosure_epilogue:
+	add	sp, sp, #16
+	ldmfd	sp, {sp, pc}
+.Lretint:
+	ldr	r0, [sp]
+	b	.Lclosure_epilogue
+.Lretlonglong:
+	ldr	r0, [sp]
+	ldr	r1, [sp, #4]
+	b	.Lclosure_epilogue
+
+#ifndef __SOFTFP__
+.Lretfloat:
+	ldfs	f0, [sp]
+	b	.Lclosure_epilogue
+.Lretdouble:
+	ldfd	f0, [sp]
+	b	.Lclosure_epilogue
+.Lretlongdouble:
+	ldfd	f0, [sp]
+	b	.Lclosure_epilogue
+#endif
+
+.ffi_closure_SYSV_end:
+	UNWIND .fnend
+        .size    CNAME(ffi_closure_SYSV),.ffi_closure_SYSV_end-CNAME(ffi_closure_SYSV)
+
+#if defined __ELF__ && defined __linux__
+	.section	.note.GNU-stack,"",%progbits
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/cris/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/cris/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/cris/ffi.c	Thu Mar 27 00:48:05 2008
@@ -2,6 +2,7 @@
    ffi.c - Copyright (c) 1998 Cygnus Solutions
            Copyright (c) 2004 Simon Posnjak
 	   Copyright (c) 2005 Axis Communications AB
+	   Copyright (C) 2007 Free Software Foundation, Inc.
 
    CRIS Foreign Function Interface
 
@@ -360,10 +361,11 @@
 /* API function: Prepare the trampoline.  */
 
 ffi_status
-ffi_prep_closure (ffi_closure* closure,
-		  ffi_cif* cif,
-		  void (*fun)(ffi_cif *, void *, void **, void*),
-		  void *user_data)
+ffi_prep_closure_loc (ffi_closure* closure,
+		      ffi_cif* cif,
+		      void (*fun)(ffi_cif *, void *, void **, void*),
+		      void *user_data,
+		      void *codeloc)
 {
   void *innerfn = ffi_prep_closure_inner;
   FFI_ASSERT (cif->abi == FFI_SYSV);
@@ -375,7 +377,7 @@
   memcpy (closure->tramp + ffi_cris_trampoline_fn_offset,
 	  &innerfn, sizeof (void *));
   memcpy (closure->tramp + ffi_cris_trampoline_closure_offset,
-	  &closure, sizeof (void *));
+	  &codeloc, sizeof (void *));
 
   return FFI_OK;
 }

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/cris/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/cris/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/cris/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -13,13 +13,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/frv/eabi.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/frv/eabi.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/frv/eabi.S	Thu Mar 27 00:48:05 2008
@@ -3,8 +3,6 @@
    
    FR-V Assembly glue.
 
-   $Id: eabi.S,v 1.2 2006/03/03 20:24:46 theller Exp $
-
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    ``Software''), to deal in the Software without restriction, including

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/frv/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/frv/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/frv/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,7 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 2004  Anthony Green
+   ffi.c - Copyright (C) 2004  Anthony Green
+           Copyright (C) 2007  Free Software Foundation, Inc.
+	   Copyright (C) 2008  Red Hat, Inc.
    
    FR-V Foreign Function Interface 
 
@@ -14,13 +16,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #include <ffi.h>
@@ -124,10 +127,10 @@
 			  extended_cif *, 
 			  unsigned, unsigned, 
 			  unsigned *, 
-			  void (*fn)());
+			  void (*fn)(void));
 
 void ffi_call(ffi_cif *cif, 
-	      void (*fn)(), 
+	      void (*fn)(void), 
 	      void *rvalue, 
 	      void **avalue)
 {
@@ -243,14 +246,15 @@
 }
 
 ffi_status
-ffi_prep_closure (ffi_closure* closure,
-		  ffi_cif* cif,
-		  void (*fun)(ffi_cif*, void*, void**, void*),
-		  void *user_data)
+ffi_prep_closure_loc (ffi_closure* closure,
+		      ffi_cif* cif,
+		      void (*fun)(ffi_cif*, void*, void**, void*),
+		      void *user_data,
+		      void *codeloc)
 {
   unsigned int *tramp = (unsigned int *) &closure->tramp[0];
   unsigned long fn = (long) ffi_closure_eabi;
-  unsigned long cls = (long) closure;
+  unsigned long cls = (long) codeloc;
 #ifdef __FRV_FDPIC__
   register void *got __asm__("gr15");
 #endif
@@ -259,7 +263,7 @@
   fn = (unsigned long) ffi_closure_eabi;
 
 #ifdef __FRV_FDPIC__
-  tramp[0] = &tramp[2];
+  tramp[0] = &((unsigned int *)codeloc)[2];
   tramp[1] = got;
   tramp[2] = 0x8cfc0000 + (fn  & 0xffff); /* setlos lo(fn), gr6    */
   tramp[3] = 0x8efc0000 + (cls & 0xffff); /* setlos lo(cls), gr7   */
@@ -281,7 +285,8 @@
 
   /* Cache flushing.  */
   for (i = 0; i < FFI_TRAMPOLINE_SIZE; i++)
-    __asm__ volatile ("dcf @(%0,%1)\n\tici @(%0,%1)" :: "r" (tramp), "r" (i));
+    __asm__ volatile ("dcf @(%0,%1)\n\tici @(%2,%1)" :: "r" (tramp), "r" (i),
+		      "r" (codeloc));
 
   return FFI_OK;
 }

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/frv/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/frv/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/frv/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -13,13 +13,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1998 Red Hat, Inc.
+   ffi.c - Copyright (c) 1998, 2007, 2008 Red Hat, Inc.
 	   Copyright (c) 2000 Hewlett Packard Company
    
    IA64 Foreign Function Interface 
@@ -15,13 +15,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #include <ffi.h>
@@ -69,24 +70,19 @@
 #endif
 }
 
-/* Store VALUE to ADDR in the current cpu implementation's fp spill format.  */
+/* Store VALUE to ADDR in the current cpu implementation's fp spill format.
+   This is a macro instead of a function, so that it works for all 3 floating
+   point types without type conversions.  Type conversion to long double breaks
+   the denorm support.  */
 
-static inline void
-stf_spill(fpreg *addr, __float80 value)
-{
+#define stf_spill(addr, value)	\
   asm ("stf.spill %0 = %1%P0" : "=m" (*addr) : "f"(value));
-}
 
 /* Load a value from ADDR, which is in the current cpu implementation's
-   fp spill format.  */
+   fp spill format.  As above, this must also be a macro.  */
 
-static inline __float80
-ldf_fill(fpreg *addr)
-{
-  __float80 ret;
-  asm ("ldf.fill %0 = %1%P1" : "=f"(ret) : "m"(*addr));
-  return ret;
-}
+#define ldf_fill(result, addr)	\
+  asm ("ldf.fill %0 = %1%P1" : "=f"(result) : "m"(*addr));
 
 /* Return the size of the C type associated with with TYPE.  Which will
    be one of the FFI_IA64_TYPE_HFA_* values.  */
@@ -110,17 +106,20 @@
 /* Load from ADDR a value indicated by TYPE.  Which will be one of
    the FFI_IA64_TYPE_HFA_* values.  */
 
-static __float80
-hfa_type_load (int type, void *addr)
+static void
+hfa_type_load (fpreg *fpaddr, int type, void *addr)
 {
   switch (type)
     {
     case FFI_IA64_TYPE_HFA_FLOAT:
-      return *(float *) addr;
+      stf_spill (fpaddr, *(float *) addr);
+      return;
     case FFI_IA64_TYPE_HFA_DOUBLE:
-      return *(double *) addr;
+      stf_spill (fpaddr, *(double *) addr);
+      return;
     case FFI_IA64_TYPE_HFA_LDOUBLE:
-      return *(__float80 *) addr;
+      stf_spill (fpaddr, *(__float80 *) addr);
+      return;
     default:
       abort ();
     }
@@ -130,19 +129,31 @@
    the FFI_IA64_TYPE_HFA_* values.  */
 
 static void
-hfa_type_store (int type, void *addr, __float80 value)
+hfa_type_store (int type, void *addr, fpreg *fpaddr)
 {
   switch (type)
     {
     case FFI_IA64_TYPE_HFA_FLOAT:
-      *(float *) addr = value;
-      break;
+      {
+	float result;
+	ldf_fill (result, fpaddr);
+	*(float *) addr = result;
+	break;
+      }
     case FFI_IA64_TYPE_HFA_DOUBLE:
-      *(double *) addr = value;
-      break;
+      {
+	double result;
+	ldf_fill (result, fpaddr);
+	*(double *) addr = result;
+	break;
+      }
     case FFI_IA64_TYPE_HFA_LDOUBLE:
-      *(__float80 *) addr = value;
-      break;
+      {
+	__float80 result;
+	ldf_fill (result, fpaddr);
+	*(__float80 *) addr = result;
+	break;
+      }
     default:
       abort ();
     }
@@ -259,10 +270,10 @@
   return FFI_OK;
 }
 
-extern int ffi_call_unix (struct ia64_args *, PTR64, void (*)(), UINT64);
+extern int ffi_call_unix (struct ia64_args *, PTR64, void (*)(void), UINT64);
 
 void
-ffi_call(ffi_cif *cif, void (*fn)(), void *rvalue, void **avalue)
+ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   struct ia64_args *stack;
   long i, avn, gpcount, fpcount;
@@ -351,8 +362,8 @@
 		       && offset < size
 		       && gp_offset < 8 * 8)
 		  {
-		    stf_spill (&stack->fp_regs[fpcount],
-			       hfa_type_load (hfa_type, avalue[i] + offset));
+		    hfa_type_load (&stack->fp_regs[fpcount], hfa_type,
+				   avalue[i] + offset);
 		    offset += hfa_size;
 		    gp_offset += hfa_size;
 		    fpcount += 1;
@@ -390,10 +401,11 @@
 extern void ffi_closure_unix ();
 
 ffi_status
-ffi_prep_closure (ffi_closure* closure,
-		  ffi_cif* cif,
-		  void (*fun)(ffi_cif*,void*,void**,void*),
-		  void *user_data)
+ffi_prep_closure_loc (ffi_closure* closure,
+		      ffi_cif* cif,
+		      void (*fun)(ffi_cif*,void*,void**,void*),
+		      void *user_data,
+		      void *codeloc)
 {
   /* The layout of a function descriptor.  A C function pointer really 
      points to one of these.  */
@@ -420,7 +432,7 @@
 
   tramp->code_pointer = fd->code_pointer;
   tramp->real_gp = fd->gp;
-  tramp->fake_gp = (UINT64)(PTR64)closure;
+  tramp->fake_gp = (UINT64)(PTR64)codeloc;
   closure->cif = cif;
   closure->user_data = user_data;
   closure->fun = fun;
@@ -475,9 +487,11 @@
 	case FFI_TYPE_FLOAT:
 	  if (gpcount < 8 && fpcount < 8)
 	    {
-	      void *addr = &stack->fp_regs[fpcount++];
+	      fpreg *addr = &stack->fp_regs[fpcount++];
+	      float result;
 	      avalue[i] = addr;
-	      *(float *)addr = ldf_fill (addr);
+	      ldf_fill (result, addr);
+	      *(float *)addr = result;
 	    }
 	  else
 	    avalue[i] = endian_adjust(&stack->gp_regs[gpcount], 4);
@@ -487,9 +501,11 @@
 	case FFI_TYPE_DOUBLE:
 	  if (gpcount < 8 && fpcount < 8)
 	    {
-	      void *addr = &stack->fp_regs[fpcount++];
+	      fpreg *addr = &stack->fp_regs[fpcount++];
+	      double result;
 	      avalue[i] = addr;
-	      *(double *)addr = ldf_fill (addr);
+	      ldf_fill (result, addr);
+	      *(double *)addr = result;
 	    }
 	  else
 	    avalue[i] = &stack->gp_regs[gpcount];
@@ -501,9 +517,11 @@
 	    gpcount++;
 	  if (LDBL_MANT_DIG == 64 && gpcount < 8 && fpcount < 8)
 	    {
-	      void *addr = &stack->fp_regs[fpcount++];
+	      fpreg *addr = &stack->fp_regs[fpcount++];
+	      __float80 result;
 	      avalue[i] = addr;
-	      *(__float80 *)addr = ldf_fill (addr);
+	      ldf_fill (result, addr);
+	      *(__float80 *)addr = result;
 	    }
 	  else
 	    avalue[i] = &stack->gp_regs[gpcount];
@@ -533,8 +551,8 @@
 		       && offset < size
 		       && gp_offset < 8 * 8)
 		  {
-		    hfa_type_store (hfa_type, addr + offset, 
-				    ldf_fill (&stack->fp_regs[fpcount]));
+		    hfa_type_store (hfa_type, addr + offset,
+				    &stack->fp_regs[fpcount]);
 		    offset += hfa_size;
 		    gp_offset += hfa_size;
 		    fpcount += 1;

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -13,13 +13,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/ia64_flags.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/ia64_flags.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/ia64_flags.h	Thu Mar 27 00:48:05 2008
@@ -16,13 +16,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 /* "Type" codes used between assembly and C.  When used as a part of

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/unix.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/unix.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/ia64/unix.S	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   unix.S - Copyright (c) 1998 Red Hat, Inc.
+   unix.S - Copyright (c) 1998, 2008 Red Hat, Inc.
             Copyright (c) 2000 Hewlett Packard Company
    
    IA64/unix Foreign Function Interface 
@@ -19,13 +19,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #define LIBFFI_ASM	
@@ -37,7 +38,7 @@
 .text
 
 /* int ffi_call_unix (struct ia64_args *stack, PTR64 rvalue,
-		      void (*fn)(), int flags);
+		      void (*fn)(void), int flags);
  */
 
         .align 16
@@ -553,3 +554,7 @@
 	data8	@pcrel(.Lld_hfa_float)		// FFI_IA64_TYPE_HFA_FLOAT
 	data8	@pcrel(.Lld_hfa_double)		// FFI_IA64_TYPE_HFA_DOUBLE
 	data8	@pcrel(.Lld_hfa_ldouble)	// FFI_IA64_TYPE_HFA_LDOUBLE
+
+#if defined __ELF__ && defined __linux__
+	.section	.note.GNU-stack,"", at progbits
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m32r/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m32r/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m32r/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------------
    ffi.c - Copyright (c) 2004  Renesas Technology
+           Copyright (c) 2008  Red Hat, Inc.
    
    M32R Foreign Function Interface 
 
@@ -31,9 +32,7 @@
 /* ffi_prep_args is called by the assembly routine once stack
    space has been allocated for the function's arguments.  */
 
-/*@-exportheader@*/
 void ffi_prep_args(char *stack, extended_cif *ecif)
-/*@=exportheader@*/
 {
   unsigned int i;
   int tmp;
@@ -173,20 +172,10 @@
   return FFI_OK;
 }
 
-/*@-declundef@*/
-/*@-exportheader@*/
-extern void ffi_call_SYSV(void (*)(char *, extended_cif *), 
-			  /*@out@*/ extended_cif *, 
-			  unsigned, unsigned, 
-			  /*@out@*/ unsigned *, 
-			  void (*fn)());
-/*@=declundef@*/
-/*@=exportheader@*/
-
-void ffi_call(/*@dependent@*/ ffi_cif *cif, 
-	      void (*fn)(), 
-	      /*@out@*/ void *rvalue, 
-	      /*@dependent@*/ void **avalue)
+extern void ffi_call_SYSV(void (*)(char *, extended_cif *), extended_cif *,
+			  unsigned, unsigned, unsigned *, void (*fn)(void));
+
+void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   extended_cif ecif;
 
@@ -198,9 +187,7 @@
   if ((rvalue == NULL) && 
       (cif->rtype->type == FFI_TYPE_STRUCT))
     {
-      /*@-sysunrecog@*/
       ecif.rvalue = alloca (cif->rtype->size);
-      /*@=sysunrecog@*/
     }
   else
     ecif.rvalue = rvalue;    
@@ -208,7 +195,6 @@
   switch (cif->abi) 
     {
     case FFI_SYSV:
-      /*@-usedef@*/
       ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, 
 		    cif->flags, ecif.rvalue, fn);
       if (cif->rtype->type == FFI_TYPE_STRUCT)
@@ -237,7 +223,6 @@
 		}
 	    }
 	}
-      /*@=usedef@*/
       break;
 
     default:

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m68k/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m68k/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m68k/ffi.c	Thu Mar 27 00:48:05 2008
@@ -8,11 +8,23 @@
 #include <ffi_common.h>
 
 #include <stdlib.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <asm/cachectl.h>
+
+void ffi_call_SYSV (extended_cif *,
+		    unsigned, unsigned,
+		    void *, void (*fn) ());
+void *ffi_prep_args (void *stack, extended_cif *ecif);
+void ffi_closure_SYSV (ffi_closure *);
+void ffi_closure_struct_SYSV (ffi_closure *);
+unsigned int ffi_closure_SYSV_inner (ffi_closure *closure,
+				     void *resp, void *args);
 
 /* ffi_prep_args is called by the assembly routine once stack space has
    been allocated for the function's arguments.  */
 
-static void *
+void *
 ffi_prep_args (void *stack, extended_cif *ecif)
 {
   unsigned int i;
@@ -24,7 +36,7 @@
   argp = stack;
 
   if (ecif->cif->rtype->type == FFI_TYPE_STRUCT
-      && ecif->cif->rtype->size > 8)
+      && !ecif->cif->flags)
     struct_value_ptr = ecif->rvalue;
   else
     struct_value_ptr = NULL;
@@ -37,44 +49,47 @@
     {
       size_t z;
 
-      /* Align if necessary.  */
-      if (((*p_arg)->alignment - 1) & (unsigned) argp)
-	argp = (char *) ALIGN (argp, (*p_arg)->alignment);
-
-	  z = (*p_arg)->size;
-	  if (z < sizeof (int))
+      z = (*p_arg)->size;
+      if (z < sizeof (int))
+	{
+	  switch ((*p_arg)->type)
 	    {
-	      switch ((*p_arg)->type)
-		{
-		case FFI_TYPE_SINT8:
-		  *(signed int *) argp = (signed int) *(SINT8 *) *p_argv;
-		  break;
-
-		case FFI_TYPE_UINT8:
-		  *(unsigned int *) argp = (unsigned int) *(UINT8 *) *p_argv;
-		  break;
-
-		case FFI_TYPE_SINT16:
-		  *(signed int *) argp = (signed int) *(SINT16 *) *p_argv;
-		  break;
-
-		case FFI_TYPE_UINT16:
-		  *(unsigned int *) argp = (unsigned int) *(UINT16 *) *p_argv;
-		  break;
-
-		case FFI_TYPE_STRUCT:
-		  memcpy (argp + sizeof (int) - z, *p_argv, z);
-		  break;
-
-		default:
-		  FFI_ASSERT (0);
-		}
-	      z = sizeof (int);
+	    case FFI_TYPE_SINT8:
+	      *(signed int *) argp = (signed int) *(SINT8 *) *p_argv;
+	      break;
+
+	    case FFI_TYPE_UINT8:
+	      *(unsigned int *) argp = (unsigned int) *(UINT8 *) *p_argv;
+	      break;
+
+	    case FFI_TYPE_SINT16:
+	      *(signed int *) argp = (signed int) *(SINT16 *) *p_argv;
+	      break;
+
+	    case FFI_TYPE_UINT16:
+	      *(unsigned int *) argp = (unsigned int) *(UINT16 *) *p_argv;
+	      break;
+
+	    case FFI_TYPE_STRUCT:
+	      memcpy (argp + sizeof (int) - z, *p_argv, z);
+	      break;
+
+	    default:
+	      FFI_ASSERT (0);
 	    }
-	  else
-	    memcpy (argp, *p_argv, z);
-	  p_argv++;
-	  argp += z;
+	  z = sizeof (int);
+	}
+      else
+	{
+	  memcpy (argp, *p_argv, z);
+
+	  /* Align if necessary.  */
+	  if ((sizeof(int) - 1) & z)
+	    z = ALIGN(z, sizeof(int));
+	}
+
+      p_argv++;
+      argp += z;
     }
 
   return struct_value_ptr;
@@ -86,7 +101,8 @@
 #define CIF_FLAGS_DOUBLE	8
 #define CIF_FLAGS_LDOUBLE	16
 #define CIF_FLAGS_POINTER	32
-#define CIF_FLAGS_STRUCT	64
+#define CIF_FLAGS_STRUCT1	64
+#define CIF_FLAGS_STRUCT2	128
 
 /* Perform machine dependent cif processing */
 ffi_status
@@ -100,12 +116,24 @@
       break;
 
     case FFI_TYPE_STRUCT:
-      if (cif->rtype->size > 4 && cif->rtype->size <= 8)
-	cif->flags = CIF_FLAGS_DINT;
-      else if (cif->rtype->size <= 4)
-	cif->flags = CIF_FLAGS_STRUCT;
-      else
-	cif->flags = 0;
+      switch (cif->rtype->size)
+	{
+	case 1:
+	  cif->flags = CIF_FLAGS_STRUCT1;
+	  break;
+	case 2:
+	  cif->flags = CIF_FLAGS_STRUCT2;
+	  break;
+	case 4:
+	  cif->flags = CIF_FLAGS_INT;
+	  break;
+	case 8:
+	  cif->flags = CIF_FLAGS_DINT;
+	  break;
+	default:
+	  cif->flags = 0;
+	  break;
+	}
       break;
 
     case FFI_TYPE_FLOAT:
@@ -137,11 +165,6 @@
   return FFI_OK;
 }
 
-extern void ffi_call_SYSV (void *(*) (void *, extended_cif *), 
-			   extended_cif *, 
-			   unsigned, unsigned, unsigned,
-			   void *, void (*fn) ());
-
 void
 ffi_call (ffi_cif *cif, void (*fn) (), void *rvalue, void **avalue)
 {
@@ -149,7 +172,7 @@
 
   ecif.cif = cif;
   ecif.avalue = avalue;
-  
+
   /* If the return value is a struct and we don't have a return value
      address then we need to make one.  */
 
@@ -159,13 +182,11 @@
     ecif.rvalue = alloca (cif->rtype->size);
   else
     ecif.rvalue = rvalue;
-    
-  
-  switch (cif->abi) 
+
+  switch (cif->abi)
     {
     case FFI_SYSV:
-      ffi_call_SYSV (ffi_prep_args, &ecif, cif->bytes, 
-		     cif->flags, cif->rtype->size * 8,
+      ffi_call_SYSV (&ecif, cif->bytes, cif->flags,
 		     ecif.rvalue, fn);
       break;
 
@@ -174,3 +195,84 @@
       break;
     }
 }
+
+static void
+ffi_prep_incoming_args_SYSV (char *stack, void **avalue, ffi_cif *cif)
+{
+  unsigned int i;
+  void **p_argv;
+  char *argp;
+  ffi_type **p_arg;
+
+  argp = stack;
+  p_argv = avalue;
+
+  for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
+    {
+      size_t z;
+
+      z = (*p_arg)->size;
+      if (z <= 4)
+	{
+	  *p_argv = (void *) (argp + 4 - z);
+
+	  z = 4;
+	}
+      else
+	{
+	  *p_argv = (void *) argp;
+
+	  /* Align if necessary */
+	  if ((sizeof(int) - 1) & z)
+	    z = ALIGN(z, sizeof(int));
+	}
+
+      p_argv++;
+      argp += z;
+    }
+}
+
+unsigned int
+ffi_closure_SYSV_inner (ffi_closure *closure, void *resp, void *args)
+{
+  ffi_cif *cif;
+  void **arg_area;
+
+  cif = closure->cif;
+  arg_area = (void**) alloca (cif->nargs * sizeof (void *));
+
+  ffi_prep_incoming_args_SYSV(args, arg_area, cif);
+
+  (closure->fun) (cif, resp, arg_area, closure->user_data);
+
+  return cif->flags;
+}
+
+ffi_status
+ffi_prep_closure_loc (ffi_closure* closure,
+		      ffi_cif* cif,
+		      void (*fun)(ffi_cif*,void*,void**,void*),
+		      void *user_data,
+		      void *codeloc)
+{
+  FFI_ASSERT (cif->abi == FFI_SYSV);
+
+  *(unsigned short *)closure->tramp = 0x207c;
+  *(void **)(closure->tramp + 2) = codeloc;
+  *(unsigned short *)(closure->tramp + 6) = 0x4ef9;
+  if (cif->rtype->type == FFI_TYPE_STRUCT
+      && !cif->flags)
+    *(void **)(closure->tramp + 8) = ffi_closure_struct_SYSV;
+  else
+    *(void **)(closure->tramp + 8) = ffi_closure_SYSV;
+
+  syscall(SYS_cacheflush, codeloc, FLUSH_SCOPE_LINE,
+	  FLUSH_CACHE_BOTH, FFI_TRAMPOLINE_SIZE);
+
+  closure->cif  = cif;
+  closure->user_data = user_data;
+  closure->fun  = fun;
+
+  return FFI_OK;
+}
+

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m68k/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m68k/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m68k/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -13,13 +13,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 
@@ -40,7 +41,8 @@
 
 /* ---- Definitions for closures ----------------------------------------- */
 
-#define FFI_CLOSURES 0
+#define FFI_CLOSURES 1
+#define FFI_TRAMPOLINE_SIZE 16
 #define FFI_NATIVE_RAW_API 0
 
 #endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m68k/sysv.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m68k/sysv.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/m68k/sysv.S	Thu Mar 27 00:48:05 2008
@@ -1,47 +1,88 @@
 /* -----------------------------------------------------------------------
-   sysv.S
+   sysv.S - Copyright (c) 1998 Andreas Schwab
+	    Copyright (c) 2008 Red Hat, Inc. 
    
    m68k Foreign Function Interface 
+
+   Permission is hereby granted, free of charge, to any person obtaining
+   a copy of this software and associated documentation files (the
+   ``Software''), to deal in the Software without restriction, including
+   without limitation the rights to use, copy, modify, merge, publish,
+   distribute, sublicense, and/or sell copies of the Software, and to
+   permit persons to whom the Software is furnished to do so, subject to
+   the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #define LIBFFI_ASM	
 #include <fficonfig.h>
 #include <ffi.h>
 
+#ifdef HAVE_AS_CFI_PSEUDO_OP
+#define CFI_STARTPROC()		.cfi_startproc
+#define CFI_OFFSET(reg,off)	.cfi_offset	reg,off
+#define CFI_DEF_CFA(reg,off)	.cfi_def_cfa	reg,off
+#define CFI_ENDPROC()		.cfi_endproc
+#else
+#define CFI_STARTPROC()
+#define CFI_OFFSET(reg,off)
+#define CFI_DEF_CFA(reg,off)
+#define CFI_ENDPROC()
+#endif
+
 	.text
 
 	.globl	ffi_call_SYSV
 	.type	ffi_call_SYSV, at function
+	.align	4
 
 ffi_call_SYSV:
+	CFI_STARTPROC()
 	link	%fp,#0
+	CFI_OFFSET(14,-8)
+	CFI_DEF_CFA(14,8)
 	move.l	%d2,-(%sp)
+	CFI_OFFSET(2,-12)
 
 	| Make room for all of the new args.
-	sub.l	16(%fp),%sp
+	sub.l	12(%fp),%sp
 
 	| Call ffi_prep_args
-	move.l	12(%fp),-(%sp)
+	move.l	8(%fp),-(%sp)
 	pea	4(%sp)
-	move.l	8(%fp),%a0
-	jsr	(%a0)
+#if !defined __PIC__
+	jsr	ffi_prep_args
+#else
+	bsr.l	ffi_prep_args at PLTPC
+#endif
 	addq.l	#8,%sp	
 
 	| Pass pointer to struct value, if any
 	move.l	%a0,%a1
 
 	| Call the function
-	move.l	32(%fp),%a0
+	move.l	24(%fp),%a0
 	jsr	(%a0)
 
 	| Remove the space we pushed for the args
-	add.l	16(%fp),%sp
+	add.l	12(%fp),%sp
 
 	| Load the pointer to storage for the return value
-	move.l	28(%fp),%a1
+	move.l	20(%fp),%a1
 
 	| Load the return type code 
-	move.l	20(%fp),%d2
+	move.l	16(%fp),%d2
 
 	| If the return value pointer is NULL, assume no return value.
 	tst.l	%a1
@@ -79,19 +120,115 @@
 
 retpointer:
 	btst	#5,%d2
-	jbeq	retstruct
+	jbeq	retstruct1
 	move.l	%a0,(%a1)
 	jbra	epilogue
 
-retstruct:
+retstruct1:
 	btst	#6,%d2
+	jbeq	retstruct2
+	move.b	%d0,(%a1)
+	jbra	epilogue
+
+retstruct2:
+	btst	#7,%d2
 	jbeq	noretval
-	move.l	24(%fp),%d2
-	bfins	%d0,(%a1){#0,%d2}
+	move.w	%d0,(%a1)
 
 noretval:
 epilogue:
 	move.l	(%sp)+,%d2
-	unlk	%a6
+	unlk	%fp
 	rts
+	CFI_ENDPROC()
 	.size	ffi_call_SYSV,.-ffi_call_SYSV
+
+	.globl	ffi_closure_SYSV
+	.type	ffi_closure_SYSV, @function
+	.align	4
+
+ffi_closure_SYSV:
+	CFI_STARTPROC()
+	link	%fp,#-12
+	CFI_OFFSET(14,-8)
+	CFI_DEF_CFA(14,8)
+	move.l	%sp,-12(%fp)
+	pea	8(%fp)
+	pea	-12(%fp)
+	move.l	%a0,-(%sp)
+#if !defined __PIC__
+	jsr	ffi_closure_SYSV_inner
+#else
+	bsr.l	ffi_closure_SYSV_inner at PLTPC
+#endif
+
+	lsr.l	#1,%d0
+	jne	1f
+	jcc	.Lcls_epilogue
+	move.l	-12(%fp),%d0
+.Lcls_epilogue:
+	unlk	%fp
+	rts
+1:
+	lea	-12(%fp),%a0
+	lsr.l	#2,%d0
+	jne	1f
+	jcs	.Lcls_ret_float
+	move.l	(%a0)+,%d0
+	move.l	(%a0),%d1
+	jra	.Lcls_epilogue
+.Lcls_ret_float:
+	fmove.s	(%a0),%fp0
+	jra	.Lcls_epilogue
+1:
+	lsr.l	#2,%d0
+	jne	1f
+	jcs	.Lcls_ret_ldouble
+	fmove.d	(%a0),%fp0
+	jra	.Lcls_epilogue
+.Lcls_ret_ldouble:
+	fmove.x	(%a0),%fp0
+	jra	.Lcls_epilogue
+1:
+	lsr.l	#2,%d0
+	jne	.Lcls_ret_struct2
+	jcs	.Lcls_ret_struct1
+	move.l	(%a0),%a0
+	move.l	%a0,%d0
+	jra	.Lcls_epilogue
+.Lcls_ret_struct1:
+	move.b	(%a0),%d0
+	jra	.Lcls_epilogue
+.Lcls_ret_struct2:
+	move.w	(%a0),%d0
+	jra	.Lcls_epilogue
+	CFI_ENDPROC()
+
+	.size	ffi_closure_SYSV,.-ffi_closure_SYSV
+
+	.globl	ffi_closure_struct_SYSV
+	.type	ffi_closure_struct_SYSV, @function
+	.align	4
+
+ffi_closure_struct_SYSV:
+	CFI_STARTPROC()
+	link	%fp,#0
+	CFI_OFFSET(14,-8)
+	CFI_DEF_CFA(14,8)
+	move.l	%sp,-12(%fp)
+	pea	8(%fp)
+	move.l	%a1,-(%sp)
+	move.l	%a0,-(%sp)
+#if !defined __PIC__
+	jsr	ffi_closure_SYSV_inner
+#else
+	bsr.l	ffi_closure_SYSV_inner at PLTPC
+#endif
+	unlk	%fp
+	rts
+	CFI_ENDPROC()
+	.size	ffi_closure_struct_SYSV,.-ffi_closure_struct_SYSV
+
+#if defined __ELF__ && defined __linux__
+	.section	.note.GNU-stack,"", at progbits
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1996 Red Hat, Inc.
+   ffi.c - Copyright (c) 1996, 2007, 2008  Red Hat, Inc.
+           Copyright (c) 2008       David Daney
    
    MIPS Foreign Function Interface 
 
@@ -14,28 +15,44 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #include <ffi.h>
 #include <ffi_common.h>
 
 #include <stdlib.h>
+
+#ifdef __GNUC__
+#  if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))
+#    define USE__BUILTIN___CLEAR_CACHE 1
+#  endif
+#endif
+
+#ifndef USE__BUILTIN___CLEAR_CACHE
 #include <sys/cachectl.h>
+#endif
 
-#if _MIPS_SIM == _ABIN32
+#ifdef FFI_DEBUG
+# define FFI_MIPS_STOP_HERE() ffi_stop_here()
+#else
+# define FFI_MIPS_STOP_HERE() do {} while(0)
+#endif
+
+#ifdef FFI_MIPS_N32
 #define FIX_ARGP \
 FFI_ASSERT(argp <= &stack[bytes]); \
 if (argp == &stack[bytes]) \
 { \
   argp = stack; \
-  ffi_stop_here(); \
+  FFI_MIPS_STOP_HERE(); \
 }
 #else
 #define FIX_ARGP 
@@ -55,7 +72,7 @@
   char *argp;
   ffi_type **p_arg;
 
-#if _MIPS_SIM == _ABIN32
+#ifdef FFI_MIPS_N32
   /* If more than 8 double words are used, the remainder go
      on the stack. We reorder stuff on the stack here to 
      support this easily. */
@@ -69,7 +86,7 @@
 
   memset(stack, 0, bytes);
 
-#if _MIPS_SIM == _ABIN32
+#ifdef FFI_MIPS_N32
   if ( ecif->cif->rstruct_flag != 0 )
 #else
   if ( ecif->cif->rtype->type == FFI_TYPE_STRUCT )
@@ -92,7 +109,7 @@
       if (a < sizeof(ffi_arg))
         a = sizeof(ffi_arg);
       
-      if ((a - 1) & (unsigned int) argp)
+      if ((a - 1) & (unsigned long) argp)
 	{
 	  argp = (char *) ALIGN(argp, a);
 	  FIX_ARGP;
@@ -101,9 +118,15 @@
       z = (*p_arg)->size;
       if (z <= sizeof(ffi_arg))
 	{
+          int type = (*p_arg)->type;
 	  z = sizeof(ffi_arg);
 
-	  switch ((*p_arg)->type)
+          /* The size of a pointer depends on the ABI */
+          if (type == FFI_TYPE_POINTER)
+            type =
+              (ecif->cif->abi == FFI_N64) ? FFI_TYPE_SINT64 : FFI_TYPE_SINT32;
+
+	  switch (type)
 	    {
 	      case FFI_TYPE_SINT8:
 		*(ffi_arg *)argp = *(SINT8 *)(* p_argv);
@@ -126,7 +149,6 @@
 		break;
 		  
 	      case FFI_TYPE_UINT32:
-	      case FFI_TYPE_POINTER:
 		*(ffi_arg *)argp = *(UINT32 *)(* p_argv);
 		break;
 
@@ -135,8 +157,7 @@
 		*(float *) argp = *(float *)(* p_argv);
 		break;
 
-	      /* Handle small structures.  */
-	      case FFI_TYPE_STRUCT:
+	      /* Handle structures.  */
 	      default:
 		memcpy(argp, *p_argv, (*p_arg)->size);
 		break;
@@ -144,12 +165,12 @@
 	}
       else
 	{
-#if _MIPS_SIM == _ABIO32
+#ifdef FFI_MIPS_O32
 	  memcpy(argp, *p_argv, z);
 #else
 	  {
-	    unsigned end = (unsigned) argp+z;
-	    unsigned cap = (unsigned) stack+bytes;
+	    unsigned long end = (unsigned long) argp + z;
+	    unsigned long cap = (unsigned long) stack + bytes;
 
 	    /* Check if the data will fit within the register space.
 	       Handle it if it doesn't.  */
@@ -158,12 +179,13 @@
 	      memcpy(argp, *p_argv, z);
 	    else
 	      {
-		unsigned portion = end - cap;
+		unsigned long portion = cap - (unsigned long)argp;
 
 		memcpy(argp, *p_argv, portion);
 		argp = stack;
-		memcpy(argp,
-		       (void*)((unsigned)(*p_argv)+portion), z - portion);
+                z -= portion;
+		memcpy(argp, (void*)((unsigned long)(*p_argv) + portion),
+                       z);
 	      }
 	  }
 #endif
@@ -174,7 +196,7 @@
     }
 }
 
-#if _MIPS_SIM == _ABIN32
+#ifdef FFI_MIPS_N32
 
 /* The n32 spec says that if "a chunk consists solely of a double 
    float field (but not a double, which is part of a union), it
@@ -182,35 +204,41 @@
    passed in an integer register". This code traverses structure
    definitions and generates the appropriate flags. */
 
-unsigned calc_n32_struct_flags(ffi_type *arg, unsigned *shift)
+static unsigned
+calc_n32_struct_flags(ffi_type *arg, unsigned *loc, unsigned *arg_reg)
 {
   unsigned flags = 0;
   unsigned index = 0;
 
   ffi_type *e;
 
-  while (e = arg->elements[index])
+  while ((e = arg->elements[index]))
     {
+      /* Align this object.  */
+      *loc = ALIGN(*loc, e->alignment);
       if (e->type == FFI_TYPE_DOUBLE)
 	{
-	  flags += (FFI_TYPE_DOUBLE << *shift);
-	  *shift += FFI_FLAG_BITS;
+          /* Already aligned to FFI_SIZEOF_ARG.  */
+          *arg_reg = *loc / FFI_SIZEOF_ARG;
+          if (*arg_reg > 7)
+            break;
+	  flags += (FFI_TYPE_DOUBLE << (*arg_reg * FFI_FLAG_BITS));
+          *loc += e->size;
 	}
-      else if (e->type == FFI_TYPE_STRUCT)
-	  flags += calc_n32_struct_flags(e, shift);
       else
-	*shift += FFI_FLAG_BITS;
-
+        *loc += e->size;
       index++;
     }
+  /* Next Argument register at alignment of FFI_SIZEOF_ARG.  */
+  *arg_reg = ALIGN(*loc, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
 
   return flags;
 }
 
-unsigned calc_n32_return_struct_flags(ffi_type *arg)
+static unsigned
+calc_n32_return_struct_flags(ffi_type *arg)
 {
   unsigned flags = 0;
-  unsigned index = 0;
   unsigned small = FFI_TYPE_SMALLSTRUCT;
   ffi_type *e;
 
@@ -229,16 +257,16 @@
 
   e = arg->elements[0];
   if (e->type == FFI_TYPE_DOUBLE)
-    flags = FFI_TYPE_DOUBLE << FFI_FLAG_BITS;
+    flags = FFI_TYPE_DOUBLE;
   else if (e->type == FFI_TYPE_FLOAT)
-    flags = FFI_TYPE_FLOAT << FFI_FLAG_BITS;
+    flags = FFI_TYPE_FLOAT;
 
   if (flags && (e = arg->elements[1]))
     {
       if (e->type == FFI_TYPE_DOUBLE)
-	flags += FFI_TYPE_DOUBLE;
+	flags += FFI_TYPE_DOUBLE << FFI_FLAG_BITS;
       else if (e->type == FFI_TYPE_FLOAT)
-	flags += FFI_TYPE_FLOAT;
+	flags += FFI_TYPE_FLOAT << FFI_FLAG_BITS;
       else 
 	return small;
 
@@ -263,7 +291,7 @@
 {
   cif->flags = 0;
 
-#if _MIPS_SIM == _ABIO32
+#ifdef FFI_MIPS_O32
   /* Set the flags necessary for O32 processing.  FFI_O32_SOFT_FLOAT
    * does not have special handling for floating point args.
    */
@@ -351,10 +379,11 @@
     }
 #endif
 
-#if _MIPS_SIM == _ABIN32
+#ifdef FFI_MIPS_N32
   /* Set the flags necessary for N32 processing */
   {
-    unsigned shift = 0;
+    unsigned arg_reg = 0;
+    unsigned loc = 0;
     unsigned count = (cif->nargs < 8) ? cif->nargs : 8;
     unsigned index = 0;
 
@@ -369,7 +398,7 @@
 	    /* This means that the structure is being passed as
 	       a hidden argument */
 
-	    shift = FFI_FLAG_BITS;
+	    arg_reg = 1;
 	    count = (cif->nargs < 7) ? cif->nargs : 7;
 
 	    cif->rstruct_flag = !0;
@@ -380,23 +409,37 @@
     else
       cif->rstruct_flag = 0;
 
-    while (count-- > 0)
+    while (count-- > 0 && arg_reg < 8)
       {
 	switch ((cif->arg_types)[index]->type)
 	  {
 	  case FFI_TYPE_FLOAT:
 	  case FFI_TYPE_DOUBLE:
-	    cif->flags += ((cif->arg_types)[index]->type << shift);
-	    shift += FFI_FLAG_BITS;
+	    cif->flags +=
+              ((cif->arg_types)[index]->type << (arg_reg * FFI_FLAG_BITS));
+	    arg_reg++;
 	    break;
+          case FFI_TYPE_LONGDOUBLE:
+            /* Align it.  */
+            arg_reg = ALIGN(arg_reg, 2);
+            /* Treat it as two adjacent doubles.  */
+	    cif->flags +=
+              (FFI_TYPE_DOUBLE << (arg_reg * FFI_FLAG_BITS));
+            arg_reg++;
+	    cif->flags +=
+              (FFI_TYPE_DOUBLE << (arg_reg * FFI_FLAG_BITS));
+            arg_reg++;
+            break;
 
 	  case FFI_TYPE_STRUCT:
+            loc = arg_reg * FFI_SIZEOF_ARG;
 	    cif->flags += calc_n32_struct_flags((cif->arg_types)[index],
-						&shift);
+						&loc, &arg_reg);
 	    break;
 
 	  default:
-	    shift += FFI_FLAG_BITS;
+	    arg_reg++;
+            break;
 	  }
 
 	index++;
@@ -431,7 +474,13 @@
       case FFI_TYPE_DOUBLE:
 	cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 8);
 	break;
-	
+      case FFI_TYPE_LONGDOUBLE:
+	/* Long double is returned as if it were a struct containing
+	   two doubles.  */
+	cif->flags += FFI_TYPE_STRUCT << (FFI_FLAG_BITS * 8);
+	cif->flags += (FFI_TYPE_DOUBLE + (FFI_TYPE_DOUBLE << FFI_FLAG_BITS))
+		      << (4 + (FFI_FLAG_BITS * 8));
+	break;
       default:
 	cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
 	break;
@@ -445,14 +494,14 @@
 /* Low level routine for calling O32 functions */
 extern int ffi_call_O32(void (*)(char *, extended_cif *, int, int), 
 			extended_cif *, unsigned, 
-			unsigned, unsigned *, void (*)());
+			unsigned, unsigned *, void (*)(void));
 
 /* Low level routine for calling N32 functions */
 extern int ffi_call_N32(void (*)(char *, extended_cif *, int, int), 
 			extended_cif *, unsigned, 
-			unsigned, unsigned *, void (*)());
+			unsigned, unsigned *, void (*)(void));
 
-void ffi_call(ffi_cif *cif, void (*fn)(), void *rvalue, void **avalue)
+void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   extended_cif ecif;
 
@@ -470,7 +519,7 @@
     
   switch (cif->abi) 
     {
-#if _MIPS_SIM == _ABIO32
+#ifdef FFI_MIPS_O32
     case FFI_O32:
     case FFI_O32_SOFT_FLOAT:
       ffi_call_O32(ffi_prep_args, &ecif, cif->bytes, 
@@ -478,10 +527,25 @@
       break;
 #endif
 
-#if _MIPS_SIM == _ABIN32
+#ifdef FFI_MIPS_N32
     case FFI_N32:
-      ffi_call_N32(ffi_prep_args, &ecif, cif->bytes, 
-		   cif->flags, ecif.rvalue, fn);
+    case FFI_N64:
+      {
+        int copy_rvalue = 0;
+        void *rvalue_copy = ecif.rvalue;
+        if (cif->rtype->type == FFI_TYPE_STRUCT && cif->rtype->size < 16)
+          {
+            /* For structures smaller than 16 bytes we clobber memory
+               in 8 byte increments.  Make a copy so we don't clobber
+               the callers memory outside of the struct bounds.  */
+            rvalue_copy = alloca(16);
+            copy_rvalue = 1;
+          }
+        ffi_call_N32(ffi_prep_args, &ecif, cif->bytes,
+                     cif->flags, rvalue_copy, fn);
+        if (copy_rvalue)
+          memcpy(ecif.rvalue, rvalue_copy, cif->rtype->size);
+      }
       break;
 #endif
 
@@ -491,42 +555,83 @@
     }
 }
 
-#if FFI_CLOSURES  /* N32 not implemented yet, FFI_CLOSURES not defined */
+#if FFI_CLOSURES
 #if defined(FFI_MIPS_O32)
 extern void ffi_closure_O32(void);
+#else
+extern void ffi_closure_N32(void);
 #endif /* FFI_MIPS_O32 */
 
 ffi_status
-ffi_prep_closure (ffi_closure *closure,
-		  ffi_cif *cif,
-		  void (*fun)(ffi_cif*,void*,void**,void*),
-		  void *user_data)
+ffi_prep_closure_loc (ffi_closure *closure,
+		      ffi_cif *cif,
+		      void (*fun)(ffi_cif*,void*,void**,void*),
+		      void *user_data,
+		      void *codeloc)
 {
   unsigned int *tramp = (unsigned int *) &closure->tramp[0];
-  unsigned int fn;
-  unsigned int ctx = (unsigned int) closure;
+  void * fn;
+  char *clear_location = (char *) codeloc;
 
 #if defined(FFI_MIPS_O32)
   FFI_ASSERT(cif->abi == FFI_O32 || cif->abi == FFI_O32_SOFT_FLOAT);
-  fn = (unsigned int) ffi_closure_O32;
+  fn = ffi_closure_O32;
 #else /* FFI_MIPS_N32 */
-  FFI_ASSERT(cif->abi == FFI_N32);
-  FFI_ASSERT(!"not implemented");
+  FFI_ASSERT(cif->abi == FFI_N32 || cif->abi == FFI_N64);
+  fn = ffi_closure_N32;
 #endif /* FFI_MIPS_O32 */
 
-  tramp[0] = 0x3c190000 | (fn >> 16);     /* lui  $25,high(fn) */
-  tramp[1] = 0x37390000 | (fn & 0xffff);  /* ori  $25,low(fn)  */
-  tramp[2] = 0x3c080000 | (ctx >> 16);    /* lui  $8,high(ctx) */
-  tramp[3] = 0x03200008;                  /* jr   $25          */
-  tramp[4] = 0x35080000 | (ctx & 0xffff); /* ori  $8,low(ctx)  */
+#if defined(FFI_MIPS_O32) || (_MIPS_SIM ==_ABIN32)
+  /* lui  $25,high(fn) */
+  tramp[0] = 0x3c190000 | ((unsigned)fn >> 16);
+  /* ori  $25,low(fn)  */
+  tramp[1] = 0x37390000 | ((unsigned)fn & 0xffff);
+  /* lui  $12,high(codeloc) */
+  tramp[2] = 0x3c0c0000 | ((unsigned)codeloc >> 16);
+  /* jr   $25          */
+  tramp[3] = 0x03200008;
+  /* ori  $12,low(codeloc)  */
+  tramp[4] = 0x358c0000 | ((unsigned)codeloc & 0xffff);
+#else
+  /* N64 has a somewhat larger trampoline.  */
+  /* lui  $25,high(fn) */
+  tramp[0] = 0x3c190000 | ((unsigned long)fn >> 48);
+  /* lui  $12,high(codeloc) */
+  tramp[1] = 0x3c0c0000 | ((unsigned long)codeloc >> 48);
+  /* ori  $25,mid-high(fn)  */
+  tramp[2] = 0x37390000 | (((unsigned long)fn >> 32 ) & 0xffff);
+  /* ori  $12,mid-high(codeloc)  */
+  tramp[3] = 0x358c0000 | (((unsigned long)codeloc >> 32) & 0xffff);
+  /* dsll $25,$25,16 */
+  tramp[4] = 0x0019cc38;
+  /* dsll $12,$12,16 */
+  tramp[5] = 0x000c6438;
+  /* ori  $25,mid-low(fn)  */
+  tramp[6] = 0x37390000 | (((unsigned long)fn >> 16 ) & 0xffff);
+  /* ori  $12,mid-low(codeloc)  */
+  tramp[7] = 0x358c0000 | (((unsigned long)codeloc >> 16) & 0xffff);
+  /* dsll $25,$25,16 */
+  tramp[8] = 0x0019cc38;
+  /* dsll $12,$12,16 */
+  tramp[9] = 0x000c6438;
+  /* ori  $25,low(fn)  */
+  tramp[10] = 0x37390000 | ((unsigned long)fn  & 0xffff);
+  /* jr   $25          */
+  tramp[11] = 0x03200008;
+  /* ori  $12,low(codeloc)  */
+  tramp[12] = 0x358c0000 | ((unsigned long)codeloc & 0xffff);
+
+#endif
 
   closure->cif = cif;
   closure->fun = fun;
   closure->user_data = user_data;
 
-  /* XXX this is available on Linux, but anything else? */
-  cacheflush (tramp, FFI_TRAMPOLINE_SIZE, ICACHE);
-
+#ifdef USE__BUILTIN___CLEAR_CACHE
+  __builtin___clear_cache(clear_location, clear_location + FFI_TRAMPOLINE_SIZE);
+#else
+  cacheflush (clear_location, FFI_TRAMPOLINE_SIZE, ICACHE);
+#endif
   return FFI_OK;
 }
 
@@ -567,7 +672,7 @@
 
   if ((cif->flags >> (FFI_FLAG_BITS * 2)) == FFI_TYPE_STRUCT)
     {
-      rvalue = (void *) ar[0];
+      rvalue = (void *)(UINT32)ar[0];
       argn = 1;
     }
 
@@ -645,4 +750,177 @@
     }
 }
 
+#if defined(FFI_MIPS_N32)
+
+static void
+copy_struct_N32(char *target, unsigned offset, ffi_abi abi, ffi_type *type,
+                int argn, unsigned arg_offset, ffi_arg *ar,
+                ffi_arg *fpr)
+{
+  ffi_type **elt_typep = type->elements;
+  while(*elt_typep)
+    {
+      ffi_type *elt_type = *elt_typep;
+      unsigned o;
+      char *tp;
+      char *argp;
+      char *fpp;
+
+      o = ALIGN(offset, elt_type->alignment);
+      arg_offset += o - offset;
+      offset = o;
+      argn += arg_offset / sizeof(ffi_arg);
+      arg_offset = arg_offset % sizeof(ffi_arg);
+
+      argp = (char *)(ar + argn);
+      fpp = (char *)(argn >= 8 ? ar + argn : fpr + argn);
+
+      tp = target + offset;
+
+      if (elt_type->type == FFI_TYPE_DOUBLE)
+        *(double *)tp = *(double *)fpp;
+      else
+        memcpy(tp, argp + arg_offset, elt_type->size);
+
+      offset += elt_type->size;
+      arg_offset += elt_type->size;
+      elt_typep++;
+      argn += arg_offset / sizeof(ffi_arg);
+      arg_offset = arg_offset % sizeof(ffi_arg);
+    }
+}
+
+/*
+ * Decodes the arguments to a function, which will be stored on the
+ * stack. AR is the pointer to the beginning of the integer
+ * arguments. FPR is a pointer to the area where floating point
+ * registers have been saved.
+ *
+ * RVALUE is the location where the function return value will be
+ * stored. CLOSURE is the prepared closure to invoke.
+ *
+ * This function should only be called from assembly, which is in
+ * turn called from a trampoline.
+ *
+ * Returns the function return flags.
+ *
+ */
+int
+ffi_closure_mips_inner_N32 (ffi_closure *closure,
+			    void *rvalue, ffi_arg *ar,
+			    ffi_arg *fpr)
+{
+  ffi_cif *cif;
+  void **avaluep;
+  ffi_arg *avalue;
+  ffi_type **arg_types;
+  int i, avn, argn;
+
+  cif = closure->cif;
+  avalue = alloca (cif->nargs * sizeof (ffi_arg));
+  avaluep = alloca (cif->nargs * sizeof (ffi_arg));
+
+  argn = 0;
+
+  if (cif->rstruct_flag)
+    {
+#if _MIPS_SIM==_ABIN32
+      rvalue = (void *)(UINT32)ar[0];
+#else /* N64 */
+      rvalue = (void *)ar[0];
+#endif
+      argn = 1;
+    }
+
+  i = 0;
+  avn = cif->nargs;
+  arg_types = cif->arg_types;
+
+  while (i < avn)
+    {
+      if (arg_types[i]->type == FFI_TYPE_FLOAT
+          || arg_types[i]->type == FFI_TYPE_DOUBLE)
+        {
+          ffi_arg *argp = argn >= 8 ? ar + argn : fpr + argn;
+#ifdef __MIPSEB__
+          if (arg_types[i]->type == FFI_TYPE_FLOAT && argn < 8)
+            avaluep[i] = ((char *) argp) + sizeof (float);
+          else
+#endif
+            avaluep[i] = (char *) argp;
+        }
+      else
+        {
+          unsigned type = arg_types[i]->type;
+
+          if (arg_types[i]->alignment > sizeof(ffi_arg))
+            argn = ALIGN(argn, arg_types[i]->alignment / sizeof(ffi_arg));
+
+          ffi_arg *argp = ar + argn;
+
+          /* The size of a pointer depends on the ABI */
+          if (type == FFI_TYPE_POINTER)
+            type = (cif->abi == FFI_N64) ? FFI_TYPE_SINT64 : FFI_TYPE_SINT32;
+
+          switch (type)
+            {
+            case FFI_TYPE_SINT8:
+              avaluep[i] = &avalue[i];
+              *(SINT8 *) &avalue[i] = (SINT8) *argp;
+              break;
+
+            case FFI_TYPE_UINT8:
+              avaluep[i] = &avalue[i];
+              *(UINT8 *) &avalue[i] = (UINT8) *argp;
+              break;
+
+            case FFI_TYPE_SINT16:
+              avaluep[i] = &avalue[i];
+              *(SINT16 *) &avalue[i] = (SINT16) *argp;
+              break;
+
+            case FFI_TYPE_UINT16:
+              avaluep[i] = &avalue[i];
+              *(UINT16 *) &avalue[i] = (UINT16) *argp;
+              break;
+
+            case FFI_TYPE_SINT32:
+              avaluep[i] = &avalue[i];
+              *(SINT32 *) &avalue[i] = (SINT32) *argp;
+              break;
+
+            case FFI_TYPE_UINT32:
+              avaluep[i] = &avalue[i];
+              *(UINT32 *) &avalue[i] = (UINT32) *argp;
+              break;
+
+            case FFI_TYPE_STRUCT:
+              if (argn < 8)
+                {
+                  /* Allocate space for the struct as at least part of
+                     it was passed in registers.  */
+                  avaluep[i] = alloca(arg_types[i]->size);
+                  copy_struct_N32(avaluep[i], 0, cif->abi, arg_types[i],
+                                  argn, 0, ar, fpr);
+
+                  break;
+                }
+              /* Else fall through.  */
+            default:
+              avaluep[i] = (char *) argp;
+              break;
+            }
+        }
+      argn += ALIGN(arg_types[i]->size, sizeof(ffi_arg)) / sizeof(ffi_arg);
+      i++;
+    }
+
+  /* Invoke the closure. */
+  (closure->fun) (cif, rvalue, avaluep, closure->user_data);
+
+  return cif->flags >> (FFI_FLAG_BITS * 8);
+}
+
+#endif /* FFI_MIPS_N32 */
+
 #endif /* FFI_CLOSURES */

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -13,19 +13,33 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 
 #ifndef LIBFFI_TARGET_H
 #define LIBFFI_TARGET_H
 
+#ifdef linux
+#include <asm/sgidefs.h>
+#  ifndef _ABIN32
+#    define _ABIN32 _MIPS_SIM_NABI32
+#  endif
+#  ifndef _ABI64
+#    define _ABI64 _MIPS_SIM_ABI64
+#  endif
+#  ifndef _ABIO32
+#    define _ABIO32 _MIPS_SIM_ABI32
+#  endif
+#endif
+
 #if !defined(_MIPS_SIM)
 -- something is very wrong --
 #else
@@ -42,10 +56,13 @@
 
 #ifdef FFI_MIPS_O32
 /* O32 stack frames have 32bit integer args */
-#define FFI_SIZEOF_ARG         4
+#  define FFI_SIZEOF_ARG    4
 #else
 /* N32 and N64 frames have 64bit integer args */
-#define FFI_SIZEOF_ARG         8
+#  define FFI_SIZEOF_ARG    8
+#  if _MIPS_SIM == _ABIN32
+#    define FFI_SIZEOF_JAVA_RAW  4
+#  endif
 #endif
 
 #define FFI_FLAG_BITS 2
@@ -104,19 +121,28 @@
 #define ra $31		
 
 #ifdef FFI_MIPS_O32
-#define REG_L	lw
-#define REG_S	sw
-#define SUBU	subu
-#define ADDU	addu
-#define SRL	srl
-#define LI	li
+# define REG_L	lw
+# define REG_S	sw
+# define SUBU	subu
+# define ADDU	addu
+# define SRL	srl
+# define LI	li
 #else /* !FFI_MIPS_O32 */
-#define REG_L	ld
-#define REG_S	sd
-#define SUBU	dsubu
-#define ADDU	daddu
-#define SRL	dsrl
-#define LI 	dli
+# define REG_L	ld
+# define REG_S	sd
+# define SUBU	dsubu
+# define ADDU	daddu
+# define SRL	dsrl
+# define LI 	dli
+# if (_MIPS_SIM==_ABI64)
+#  define LA dla
+#  define EH_FRAME_ALIGN 3
+#  define FDE_ADDR_BYTES .8byte
+# else
+#  define LA la
+#  define EH_FRAME_ALIGN 2
+#  define FDE_ADDR_BYTES .4byte
+# endif /* _MIPS_SIM==_ABI64 */
 #endif /* !FFI_MIPS_O32 */
 #else /* !LIBFFI_ASM */
 #ifdef FFI_MIPS_O32
@@ -143,7 +169,11 @@
   FFI_DEFAULT_ABI = FFI_O32,
 #endif
 #else
+# if _MIPS_SIM==_ABI64
+  FFI_DEFAULT_ABI = FFI_N64,
+# else
   FFI_DEFAULT_ABI = FFI_N32,
+# endif
 #endif
 
   FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
@@ -158,8 +188,13 @@
 #define FFI_CLOSURES 1
 #define FFI_TRAMPOLINE_SIZE 20
 #else
-/* N32/N64 not implemented yet. */
-#define FFI_CLOSURES 0
+/* N32/N64. */
+# define FFI_CLOSURES 1
+#if _MIPS_SIM==_ABI64
+#define FFI_TRAMPOLINE_SIZE 52
+#else
+#define FFI_TRAMPOLINE_SIZE 20
+#endif
 #endif /* FFI_MIPS_O32 */
 #define FFI_NATIVE_RAW_API 0
 

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/n32.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/n32.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/n32.S	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,8 @@
    THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+	ANY CLAIM, DAMAGES OR
    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    OTHER DEALINGS IN THE SOFTWARE.
@@ -45,13 +46,19 @@
 	.globl	ffi_call_N32
 	.ent	ffi_call_N32
 ffi_call_N32:	
+.LFB3:
+	.frame	$fp, SIZEOF_FRAME, ra
+	.mask	0xc0000000,-FFI_SIZEOF_ARG
+	.fmask	0x00000000,0
 
 	# Prologue
 	SUBU	$sp, SIZEOF_FRAME			# Frame size
+.LCFI0:
 	REG_S	$fp, SIZEOF_FRAME - 2*FFI_SIZEOF_ARG($sp)	# Save frame pointer
 	REG_S	ra, SIZEOF_FRAME - 1*FFI_SIZEOF_ARG($sp)	# Save return address
+.LCFI1:
 	move	$fp, $sp
-
+.LCFI3:
 	move	t9, callback	# callback function pointer
 	REG_S	bytes, 2*FFI_SIZEOF_ARG($fp) # bytes
 	REG_S	flags, 3*FFI_SIZEOF_ARG($fp) # flags
@@ -72,14 +79,12 @@
 	SUBU	$sp, $sp, v0	# move the stack pointer to reflect the
 				# arg space
 
-	ADDU	a0, $sp, 0      # 4 * FFI_SIZEOF_ARG
+	move	a0, $sp         # 4 * FFI_SIZEOF_ARG
 	ADDU	a3, $fp, 3 * FFI_SIZEOF_ARG
 
 	# Call ffi_prep_args
 	jal	t9
 	
-	#	ADDU	$sp, $sp, 4 * FFI_SIZEOF_ARG	# adjust $sp to new args
-
 	# Copy the stack pointer to t9
 	move	t9, $sp
 	
@@ -90,18 +95,16 @@
 	REG_L	t6, 2*FFI_SIZEOF_ARG($fp)
 
 	# Is it bigger than 8 * FFI_SIZEOF_ARG?
-	dadd	t7, $0, 8 * FFI_SIZEOF_ARG
-	dsub	t8, t6, t7
+	daddiu	t8, t6, -(8 * FFI_SIZEOF_ARG)
 	bltz	t8, loadregs
 
-	add	t9, t9, t8
+	ADDU	t9, t9, t8
 	
 loadregs:	
 
-	REG_L	t4, 3*FFI_SIZEOF_ARG($fp)  # load the flags word
-	add	t6, t4, 0			      # and copy it into t6
+	REG_L	t6, 3*FFI_SIZEOF_ARG($fp)  # load the flags word into t6.
 
-	and	t4, ((1<<FFI_FLAG_BITS)-1)
+	and	t4, t6, ((1<<FFI_FLAG_BITS)-1)
 	bnez	t4, arg1_floatp
 	REG_L	a0, 0*FFI_SIZEOF_ARG(t9)
 	b	arg1_next
@@ -113,8 +116,7 @@
 	l.d	$f12, 0*FFI_SIZEOF_ARG(t9)
 arg1_next:	
 	
-	add	t4, t6, 0
-	SRL	t4, 1*FFI_FLAG_BITS
+	SRL	t4, t6, 1*FFI_FLAG_BITS
 	and	t4, ((1<<FFI_FLAG_BITS)-1)
 	bnez	t4, arg2_floatp
 	REG_L	a1, 1*FFI_SIZEOF_ARG(t9)
@@ -127,8 +129,7 @@
 	l.d	$f13, 1*FFI_SIZEOF_ARG(t9)	
 arg2_next:	
 	
-	add	t4, t6, 0
-	SRL	t4, 2*FFI_FLAG_BITS
+	SRL	t4, t6, 2*FFI_FLAG_BITS
 	and	t4, ((1<<FFI_FLAG_BITS)-1)
 	bnez	t4, arg3_floatp
 	REG_L	a2, 2*FFI_SIZEOF_ARG(t9)
@@ -141,8 +142,7 @@
 	l.d	$f14, 2*FFI_SIZEOF_ARG(t9)	
 arg3_next:	
 	
-	add	t4, t6, 0
-	SRL	t4, 3*FFI_FLAG_BITS
+	SRL	t4, t6, 3*FFI_FLAG_BITS
 	and	t4, ((1<<FFI_FLAG_BITS)-1)
 	bnez	t4, arg4_floatp
 	REG_L	a3, 3*FFI_SIZEOF_ARG(t9)
@@ -155,8 +155,7 @@
 	l.d	$f15, 3*FFI_SIZEOF_ARG(t9)	
 arg4_next:	
 	
-	add	t4, t6, 0
-	SRL	t4, 4*FFI_FLAG_BITS
+	SRL	t4, t6, 4*FFI_FLAG_BITS
 	and	t4, ((1<<FFI_FLAG_BITS)-1)
 	bnez	t4, arg5_floatp
 	REG_L	a4, 4*FFI_SIZEOF_ARG(t9)
@@ -169,8 +168,7 @@
 	l.d	$f16, 4*FFI_SIZEOF_ARG(t9)	
 arg5_next:	
 	
-	add	t4, t6, 0
-	SRL	t4, 5*FFI_FLAG_BITS
+	SRL	t4, t6, 5*FFI_FLAG_BITS
 	and	t4, ((1<<FFI_FLAG_BITS)-1)
 	bnez	t4, arg6_floatp
 	REG_L	a5, 5*FFI_SIZEOF_ARG(t9)
@@ -183,8 +181,7 @@
 	l.d	$f17, 5*FFI_SIZEOF_ARG(t9)	
 arg6_next:	
 	
-	add	t4, t6, 0
-	SRL	t4, 6*FFI_FLAG_BITS
+	SRL	t4, t6, 6*FFI_FLAG_BITS
 	and	t4, ((1<<FFI_FLAG_BITS)-1)
 	bnez	t4, arg7_floatp
 	REG_L	a6, 6*FFI_SIZEOF_ARG(t9)
@@ -197,8 +194,7 @@
 	l.d	$f18, 6*FFI_SIZEOF_ARG(t9)	
 arg7_next:	
 	
-	add	t4, t6, 0
-	SRL	t4, 7*FFI_FLAG_BITS
+	SRL	t4, t6, 7*FFI_FLAG_BITS
 	and	t4, ((1<<FFI_FLAG_BITS)-1)
 	bnez	t4, arg8_floatp
 	REG_L	a7, 7*FFI_SIZEOF_ARG(t9)
@@ -315,6 +311,224 @@
 	ADDU	$sp, SIZEOF_FRAME		      # Fix stack pointer
 	j	ra
 
+.LFE3:
 	.end	ffi_call_N32
+
+/* ffi_closure_N32. Expects address of the passed-in ffi_closure in t0
+   ($12). Stores any arguments passed in registers onto the stack,
+   then calls ffi_closure_mips_inner_N32, which then decodes
+   them.
+	
+	Stack layout:
+
+	20 - Start of parameters, original sp
+	19 - Called function a7 save
+	18 - Called function a6 save
+	17 - Called function a5 save
+	16 - Called function a4 save
+	15 - Called function a3 save
+	14 - Called function a2 save
+	13 - Called function a1 save
+	12 - Called function a0 save
+	11 - Called function f19
+	10 - Called function f18
+	 9 - Called function f17
+	 8 - Called function f16
+	 7 - Called function f15
+         6 - Called function f14
+         5 - Called function f13
+         4 - Called function f12
+	 3 - return value high (v1 or $f2)
+	 2 - return value low (v0 or $f0)
+	 1 - ra save
+	 0 - gp save our sp  points here
+	 */
+
+#define SIZEOF_FRAME2	(20 * FFI_SIZEOF_ARG)
+	
+#define A7_OFF2		(19 * FFI_SIZEOF_ARG)
+#define A6_OFF2		(18 * FFI_SIZEOF_ARG)
+#define A5_OFF2		(17 * FFI_SIZEOF_ARG)
+#define A4_OFF2		(16 * FFI_SIZEOF_ARG)
+#define A3_OFF2		(15 * FFI_SIZEOF_ARG)
+#define A2_OFF2		(14 * FFI_SIZEOF_ARG)
+#define A1_OFF2		(13 * FFI_SIZEOF_ARG)
+#define A0_OFF2		(12 * FFI_SIZEOF_ARG)	
+
+#define F19_OFF2	(11 * FFI_SIZEOF_ARG)
+#define F18_OFF2	(10 * FFI_SIZEOF_ARG)
+#define F17_OFF2	(9  * FFI_SIZEOF_ARG)
+#define F16_OFF2	(8  * FFI_SIZEOF_ARG)
+#define F15_OFF2	(7  * FFI_SIZEOF_ARG)
+#define F14_OFF2	(6  * FFI_SIZEOF_ARG)
+#define F13_OFF2	(5  * FFI_SIZEOF_ARG)
+#define F12_OFF2	(4  * FFI_SIZEOF_ARG)
+
+#define V1_OFF2		(3  * FFI_SIZEOF_ARG)
+#define V0_OFF2		(2  * FFI_SIZEOF_ARG)
+
+#define RA_OFF2		(1  * FFI_SIZEOF_ARG)
+#define GP_OFF2		(0  * FFI_SIZEOF_ARG)
+
+	.align	2
+	.globl	ffi_closure_N32
+	.ent	ffi_closure_N32
+ffi_closure_N32:
+.LFB2:
+	.frame	$sp, SIZEOF_FRAME2, ra
+	.mask	0x90000000,-(SIZEOF_FRAME2 - RA_OFF2)
+	.fmask	0x00000000,0
+	SUBU	$sp, SIZEOF_FRAME2
+.LCFI5:
+	.cpsetup t9, GP_OFF2, ffi_closure_N32
+	REG_S	ra, RA_OFF2($sp)	# Save return address
+.LCFI6:
+	# Store all possible argument registers. If there are more than
+	# fit in registers, then they were stored on the stack.
+	REG_S	a0, A0_OFF2($sp)
+	REG_S	a1, A1_OFF2($sp)
+	REG_S	a2, A2_OFF2($sp)
+	REG_S	a3, A3_OFF2($sp)
+	REG_S	a4, A4_OFF2($sp)
+	REG_S	a5, A5_OFF2($sp)
+	REG_S	a6, A6_OFF2($sp)
+	REG_S	a7, A7_OFF2($sp)
+
+	# Store all possible float/double registers.
+	s.d	$f12, F12_OFF2($sp)
+	s.d	$f13, F13_OFF2($sp)
+	s.d	$f14, F14_OFF2($sp)
+	s.d	$f15, F15_OFF2($sp)
+	s.d	$f16, F16_OFF2($sp)
+	s.d	$f17, F17_OFF2($sp)
+	s.d	$f18, F18_OFF2($sp)
+	s.d	$f19, F19_OFF2($sp)
+
+	# Call ffi_closure_mips_inner_N32 to do the real work.
+	LA	t9, ffi_closure_mips_inner_N32
+	move	a0, $12	 # Pointer to the ffi_closure
+	ADDU	a1, $sp, V0_OFF2
+	ADDU	a2, $sp, A0_OFF2
+	ADDU	a3, $sp, F12_OFF2
+	jalr	t9
+
+	# Return flags are in v0
+	bne     v0, FFI_TYPE_INT, cls_retfloat
+	REG_L	v0, V0_OFF2($sp)
+	b	cls_epilogue
+
+cls_retfloat:
+	bne     v0, FFI_TYPE_FLOAT, cls_retdouble
+	l.s	$f0, V0_OFF2($sp)
+	b	cls_epilogue
+
+cls_retdouble:	
+	bne	v0, FFI_TYPE_DOUBLE, cls_retstruct_d
+	l.d	$f0, V0_OFF2($sp)
+	b	cls_epilogue
+
+cls_retstruct_d:	
+	bne	v0, FFI_TYPE_STRUCT_D, cls_retstruct_f
+	l.d	$f0, V0_OFF2($sp)
+	b	cls_epilogue
+	
+cls_retstruct_f:	
+	bne	v0, FFI_TYPE_STRUCT_F, cls_retstruct_d_d
+	l.s	$f0, V0_OFF2($sp)
+	b	cls_epilogue
+	
+cls_retstruct_d_d:	
+	bne	v0, FFI_TYPE_STRUCT_DD, cls_retstruct_f_f
+	l.d	$f0, V0_OFF2($sp)
+	l.d	$f2, V1_OFF2($sp)
+	b	cls_epilogue
+	
+cls_retstruct_f_f:	
+	bne	v0, FFI_TYPE_STRUCT_FF, cls_retstruct_d_f
+	l.s	$f0, V0_OFF2($sp)
+	l.s	$f2, V1_OFF2($sp)
+	b	cls_epilogue
+	
+cls_retstruct_d_f:	
+	bne	v0, FFI_TYPE_STRUCT_DF, cls_retstruct_f_d
+	l.d	$f0, V0_OFF2($sp)
+	l.s	$f2, V1_OFF2($sp)
+	b	cls_epilogue
+	
+cls_retstruct_f_d:	
+	bne	v0, FFI_TYPE_STRUCT_FD, cls_retstruct_small2
+	l.s	$f0, V0_OFF2($sp)
+	l.d	$f2, V1_OFF2($sp)
+	b	cls_epilogue
+	
+cls_retstruct_small2:	
+	REG_L	v0, V0_OFF2($sp)
+	REG_L	v1, V1_OFF2($sp)
+	
+	# Epilogue
+cls_epilogue:	
+	REG_L	ra,  RA_OFF2($sp)	 # Restore return address
+	.cpreturn
+	ADDU	$sp, SIZEOF_FRAME2
+	j	ra
+.LFE2:	
+	.end	ffi_closure_N32
+
+        .section        .eh_frame,"aw", at progbits
+.Lframe1:
+        .4byte  .LECIE1-.LSCIE1		# length
+.LSCIE1:
+        .4byte  0x0			# CIE
+        .byte   0x1			# Version 1
+        .ascii  "\000"			# Augmentation
+        .uleb128 0x1			# Code alignment 1
+        .sleb128 -4			# Data alignment -4
+        .byte   0x1f			# Return Address $31
+        .byte   0xc			# DW_CFA_def_cfa
+        .uleb128 0x1d			# in $sp
+        .uleb128 0x0			# offset 0
+        .align  EH_FRAME_ALIGN
+.LECIE1:
+
+.LSFDE1:
+        .4byte  .LEFDE1-.LASFDE1	# length.
+.LASFDE1:
+        .4byte  .LASFDE1-.Lframe1	# CIE_pointer.
+        FDE_ADDR_BYTES  .LFB3		# initial_location.
+        FDE_ADDR_BYTES  .LFE3-.LFB3	# address_range.
+        .byte   0x4			# DW_CFA_advance_loc4
+        .4byte  .LCFI0-.LFB3		# to .LCFI0
+        .byte   0xe			# DW_CFA_def_cfa_offset
+        .uleb128 SIZEOF_FRAME		# adjust stack.by SIZEOF_FRAME
+        .byte   0x4			# DW_CFA_advance_loc4
+        .4byte  .LCFI1-.LCFI0		# to .LCFI1
+        .byte   0x9e			# DW_CFA_offset of $fp
+        .uleb128 2*FFI_SIZEOF_ARG/4	# 
+        .byte   0x9f			# DW_CFA_offset of ra
+        .uleb128 1*FFI_SIZEOF_ARG/4	# 
+        .byte   0x4			# DW_CFA_advance_loc4
+        .4byte  .LCFI3-.LCFI1		# to .LCFI3
+        .byte   0xd			# DW_CFA_def_cfa_register
+        .uleb128 0x1e			# in $fp
+        .align  EH_FRAME_ALIGN
+.LEFDE1:
+.LSFDE3:
+	.4byte	.LEFDE3-.LASFDE3	# length
+.LASFDE3:
+	.4byte	.LASFDE3-.Lframe1	# CIE_pointer.
+	FDE_ADDR_BYTES	.LFB2		# initial_location.
+	FDE_ADDR_BYTES	.LFE2-.LFB2	# address_range.
+	.byte	0x4			# DW_CFA_advance_loc4
+	.4byte	.LCFI5-.LFB2		# to .LCFI5
+	.byte	0xe			# DW_CFA_def_cfa_offset
+	.uleb128 SIZEOF_FRAME2		# adjust stack.by SIZEOF_FRAME
+	.byte	0x4			# DW_CFA_advance_loc4
+	.4byte	.LCFI6-.LCFI5		# to .LCFI6
+	.byte	0x9c			# DW_CFA_offset of $gp ($28)
+	.uleb128 (SIZEOF_FRAME2 - GP_OFF2)/4
+	.byte	0x9f			# DW_CFA_offset of ra ($31)
+	.uleb128 (SIZEOF_FRAME2 - RA_OFF2)/4
+	.align	EH_FRAME_ALIGN
+.LEFDE3:
 	
 #endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/o32.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/o32.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/mips/o32.S	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,8 @@
    THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+	ANY CLAIM, DAMAGES OR
    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    OTHER DEALINGS IN THE SOFTWARE.
@@ -183,27 +184,30 @@
 
 
 /* ffi_closure_O32. Expects address of the passed-in ffi_closure
-	in t0. Stores any arguments passed in registers onto the
+	in t4 ($12). Stores any arguments passed in registers onto the
 	stack, then calls ffi_closure_mips_inner_O32, which
 	then decodes them.
 	
 	Stack layout:
 
-	14 - Start of parameters, original sp
-	13 - ra save
-	12 - fp save
-	11 - $16 (s0) save
-	10 - cprestore
-	 9 - return value high (v1)
-	 8 - return value low (v0)
-	 7 - f14 (le high, be low)
-	 6 - f14 (le low, be high)
-	 5 - f12 (le high, be low)
-	 4 - f12 (le low, be high)
-	 3 - Called function a3 save
-	 2 - Called function a2 save
-	 1 - Called function a1 save
-	 0 - Called function a0 save our sp, fp point here
+	 3 - a3 save
+	 2 - a2 save
+	 1 - a1 save
+	 0 - a0 save, original sp
+	-1 - ra save
+	-2 - fp save
+	-3 - $16 (s0) save
+	-4 - cprestore
+	-5 - return value high (v1)
+	-6 - return value low (v0)
+	-7 - f14 (le high, be low)
+	-8 - f14 (le low, be high)
+	-9 - f12 (le high, be low)
+       -10 - f12 (le low, be high)
+       -11 - Called function a3 save
+       -12 - Called function a2 save
+       -13 - Called function a1 save
+       -14 - Called function a0 save, our sp and fp point here
 	 */
 	
 #define SIZEOF_FRAME2	(14 * FFI_SIZEOF_ARG)
@@ -251,7 +255,7 @@
 	REG_S	a3, A3_OFF2($fp)
 
 	# Load ABI enum to s0
-	REG_L	$16, 20($8)	# cif pointer follows tramp.
+	REG_L	$16, 20($12)	# cif pointer follows tramp.
 	REG_L	$16, 0($16)	# abi is first member.
 
 	li	$13, 1		# FFI_O32
@@ -263,7 +267,7 @@
 1:	
 	# Call ffi_closure_mips_inner_O32 to do the work.
 	la	t9, ffi_closure_mips_inner_O32
-	move	a0, $8	 # Pointer to the ffi_closure
+	move	a0, $12	 # Pointer to the ffi_closure
 	addu	a1, $fp, V0_OFF2
 	addu	a2, $fp, A0_OFF2
 	addu	a3, $fp, FA_0_0_OFF2

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/pa/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/pa/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/pa/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,9 @@
 /* -----------------------------------------------------------------------
    ffi.c - (c) 2003-2004 Randolph Chung <tausq at debian.org>
+           (c) 2008 Red Hat, Inc.
 
    HPPA Foreign Function Interface
+   HP-UX PA ABI support (c) 2006 Free Software Foundation, Inc.
 
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
@@ -14,13 +16,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #include <ffi.h>
@@ -30,15 +33,19 @@
 #include <stdio.h>
 
 #define ROUND_UP(v, a)  (((size_t)(v) + (a) - 1) & ~((a) - 1))
-#define ROUND_DOWN(v, a)  (((size_t)(v) - (a) + 1) & ~((a) - 1))
+
 #define MIN_STACK_SIZE  64
 #define FIRST_ARG_SLOT  9
 #define DEBUG_LEVEL   0
 
-#define fldw(addr, fpreg) asm volatile ("fldw 0(%0), %%" #fpreg "L" : : "r"(addr) : #fpreg)
-#define fstw(fpreg, addr) asm volatile ("fstw %%" #fpreg "L, 0(%0)" : : "r"(addr))
-#define fldd(addr, fpreg) asm volatile ("fldd 0(%0), %%" #fpreg : : "r"(addr) : #fpreg)
-#define fstd(fpreg, addr) asm volatile ("fstd %%" #fpreg "L, 0(%0)" : : "r"(addr))
+#define fldw(addr, fpreg) \
+  __asm__ volatile ("fldw 0(%0), %%" #fpreg "L" : : "r"(addr) : #fpreg)
+#define fstw(fpreg, addr) \
+  __asm__ volatile ("fstw %%" #fpreg "L, 0(%0)" : : "r"(addr))
+#define fldd(addr, fpreg) \
+  __asm__ volatile ("fldd 0(%0), %%" #fpreg : : "r"(addr) : #fpreg)
+#define fstd(fpreg, addr) \
+  __asm__ volatile ("fstd %%" #fpreg "L, 0(%0)" : : "r"(addr))
 
 #define debug(lvl, x...) do { if (lvl <= DEBUG_LEVEL) { printf(x); } } while (0)
 
@@ -47,16 +54,19 @@
   size_t sz = t->size;
 
   /* Small structure results are passed in registers,
-     larger ones are passed by pointer.  */
+     larger ones are passed by pointer.  Note that
+     small structures of size 2, 4 and 8 differ from
+     the corresponding integer types in that they have
+     different alignment requirements.  */
 
   if (sz <= 1)
     return FFI_TYPE_UINT8;
   else if (sz == 2)
-    return FFI_TYPE_UINT16;
+    return FFI_TYPE_SMALL_STRUCT2;
   else if (sz == 3)
     return FFI_TYPE_SMALL_STRUCT3;
   else if (sz == 4)
-    return FFI_TYPE_UINT32;
+    return FFI_TYPE_SMALL_STRUCT4;
   else if (sz == 5)
     return FFI_TYPE_SMALL_STRUCT5;
   else if (sz == 6)
@@ -64,61 +74,80 @@
   else if (sz == 7)
     return FFI_TYPE_SMALL_STRUCT7;
   else if (sz <= 8)
-    return FFI_TYPE_UINT64;
+    return FFI_TYPE_SMALL_STRUCT8;
   else
     return FFI_TYPE_STRUCT; /* else, we pass it by pointer.  */
 }
 
 /* PA has a downward growing stack, which looks like this:
-  
+
    Offset
-        [ Variable args ]
+	[ Variable args ]
    SP = (4*(n+9))       arg word N
    ...
    SP-52                arg word 4
-        [ Fixed args ]
+	[ Fixed args ]
    SP-48                arg word 3
    SP-44                arg word 2
    SP-40                arg word 1
    SP-36                arg word 0
-        [ Frame marker ]
+	[ Frame marker ]
    ...
    SP-20                RP
    SP-4                 previous SP
-  
-   First 4 non-FP 32-bit args are passed in gr26, gr25, gr24 and gr23
-   First 2 non-FP 64-bit args are passed in register pairs, starting
-     on an even numbered register (i.e. r26/r25 and r24+r23)
-   First 4 FP 32-bit arguments are passed in fr4L, fr5L, fr6L and fr7L
-   First 2 FP 64-bit arguments are passed in fr5 and fr7
-   The rest are passed on the stack starting at SP-52, but 64-bit
-     arguments need to be aligned to an 8-byte boundary
-  
+
+   The first four argument words on the stack are reserved for use by
+   the callee.  Instead, the general and floating registers replace
+   the first four argument slots.  Non FP arguments are passed solely
+   in the general registers.  FP arguments are passed in both general
+   and floating registers when using libffi.
+
+   Non-FP 32-bit args are passed in gr26, gr25, gr24 and gr23.
+   Non-FP 64-bit args are passed in register pairs, starting
+   on an odd numbered register (i.e. r25+r26 and r23+r24).
+   FP 32-bit arguments are passed in fr4L, fr5L, fr6L and fr7L.
+   FP 64-bit arguments are passed in fr5 and fr7.
+
+   The registers are allocated in the same manner as stack slots.
+   This allows the callee to save its arguments on the stack if
+   necessary:
+
+   arg word 3 -> gr23 or fr7L
+   arg word 2 -> gr24 or fr6L or fr7R
+   arg word 1 -> gr25 or fr5L
+   arg word 0 -> gr26 or fr4L or fr5R
+
+   Note that fr4R and fr6R are never used for arguments (i.e.,
+   doubles are not passed in fr4 or fr6).
+
+   The rest of the arguments are passed on the stack starting at SP-52,
+   but 64-bit arguments need to be aligned to an 8-byte boundary
+
    This means we can have holes either in the register allocation,
    or in the stack.  */
 
 /* ffi_prep_args is called by the assembly routine once stack space
    has been allocated for the function's arguments
-  
+
    The following code will put everything into the stack frame
    (which was allocated by the asm routine), and on return
    the asm routine will load the arguments that should be
    passed by register into the appropriate registers
-  
+
    NOTE: We load floating point args in this function... that means we
    assume gcc will not mess with fp regs in here.  */
 
-/*@-exportheader@*/
-void ffi_prep_args_LINUX(UINT32 *stack, extended_cif *ecif, unsigned bytes)
-/*@=exportheader@*/
+void ffi_prep_args_pa32(UINT32 *stack, extended_cif *ecif, unsigned bytes)
 {
   register unsigned int i;
   register ffi_type **p_arg;
   register void **p_argv;
-  unsigned int slot = FIRST_ARG_SLOT - 1;
+  unsigned int slot = FIRST_ARG_SLOT;
   char *dest_cpy;
+  size_t len;
 
-  debug(1, "%s: stack = %p, ecif = %p, bytes = %u\n", __FUNCTION__, stack, ecif, bytes);
+  debug(1, "%s: stack = %p, ecif = %p, bytes = %u\n", __FUNCTION__, stack,
+	ecif, bytes);
 
   p_arg = ecif->cif->arg_types;
   p_argv = ecif->avalue;
@@ -130,116 +159,105 @@
       switch (type)
 	{
 	case FFI_TYPE_SINT8:
-	  slot++;
 	  *(SINT32 *)(stack - slot) = *(SINT8 *)(*p_argv);
 	  break;
 
 	case FFI_TYPE_UINT8:
-	  slot++;
 	  *(UINT32 *)(stack - slot) = *(UINT8 *)(*p_argv);
 	  break;
 
 	case FFI_TYPE_SINT16:
-	  slot++;
 	  *(SINT32 *)(stack - slot) = *(SINT16 *)(*p_argv);
 	  break;
 
 	case FFI_TYPE_UINT16:
-	  slot++;
 	  *(UINT32 *)(stack - slot) = *(UINT16 *)(*p_argv);
 	  break;
 
 	case FFI_TYPE_UINT32:
 	case FFI_TYPE_SINT32:
 	case FFI_TYPE_POINTER:
-	  slot++;
-	  debug(3, "Storing UINT32 %u in slot %u\n", *(UINT32 *)(*p_argv), slot);
+	  debug(3, "Storing UINT32 %u in slot %u\n", *(UINT32 *)(*p_argv),
+		slot);
 	  *(UINT32 *)(stack - slot) = *(UINT32 *)(*p_argv);
 	  break;
 
 	case FFI_TYPE_UINT64:
 	case FFI_TYPE_SINT64:
-	  slot += 2;
-	  if (slot & 1)
-	    slot++;
-
-	  *(UINT32 *)(stack - slot) = (*(UINT64 *)(*p_argv)) >> 32;
-	  *(UINT32 *)(stack - slot + 1) = (*(UINT64 *)(*p_argv)) & 0xffffffffUL;
+	  /* Align slot for 64-bit type.  */
+	  slot += (slot & 1) ? 1 : 2;
+	  *(UINT64 *)(stack - slot) = *(UINT64 *)(*p_argv);
 	  break;
 
 	case FFI_TYPE_FLOAT:
-	  /* First 4 args go in fr4L - fr7L */
-	  slot++;
+	  /* First 4 args go in fr4L - fr7L.  */
+	  debug(3, "Storing UINT32(float) in slot %u\n", slot);
+	  *(UINT32 *)(stack - slot) = *(UINT32 *)(*p_argv);
 	  switch (slot - FIRST_ARG_SLOT)
 	    {
-	    case 0: fldw(*p_argv, fr4); break;
-	    case 1: fldw(*p_argv, fr5); break;
-	    case 2: fldw(*p_argv, fr6); break;
-	    case 3: fldw(*p_argv, fr7); break;
-	    default:
-	      /* Other ones are just passed on the stack.  */
-	      debug(3, "Storing UINT32(float) in slot %u\n", slot);
-	      *(UINT32 *)(stack - slot) = *(UINT32 *)(*p_argv);
-	      break;
+	    /* First 4 args go in fr4L - fr7L.  */
+	    case 0: fldw(stack - slot, fr4); break;
+	    case 1: fldw(stack - slot, fr5); break;
+	    case 2: fldw(stack - slot, fr6); break;
+	    case 3: fldw(stack - slot, fr7); break;
 	    }
-	    break;
+	  break;
 
 	case FFI_TYPE_DOUBLE:
-	  slot += 2;
-	  if (slot & 1)
-	    slot++;
-	  switch (slot - FIRST_ARG_SLOT + 1)
+	  /* Align slot for 64-bit type.  */
+	  slot += (slot & 1) ? 1 : 2;
+	  debug(3, "Storing UINT64(double) at slot %u\n", slot);
+	  *(UINT64 *)(stack - slot) = *(UINT64 *)(*p_argv);
+	  switch (slot - FIRST_ARG_SLOT)
 	    {
-	      /* First 2 args go in fr5, fr7 */
-	      case 2: fldd(*p_argv, fr5); break;
-	      case 4: fldd(*p_argv, fr7); break;
-	      default:
-	        debug(3, "Storing UINT64(double) at slot %u\n", slot);
-	        *(UINT64 *)(stack - slot) = *(UINT64 *)(*p_argv);
-	        break;
+	      /* First 2 args go in fr5, fr7.  */
+	      case 1: fldd(stack - slot, fr5); break;
+	      case 3: fldd(stack - slot, fr7); break;
 	    }
 	  break;
 
+#ifdef PA_HPUX
+	case FFI_TYPE_LONGDOUBLE:
+	  /* Long doubles are passed in the same manner as structures
+	     larger than 8 bytes.  */
+	  *(UINT32 *)(stack - slot) = (UINT32)(*p_argv);
+	  break;
+#endif
+
 	case FFI_TYPE_STRUCT:
 
 	  /* Structs smaller or equal than 4 bytes are passed in one
 	     register. Structs smaller or equal 8 bytes are passed in two
 	     registers. Larger structures are passed by pointer.  */
 
-	  if((*p_arg)->size <= 4) 
+	  len = (*p_arg)->size;
+	  if (len <= 4)
 	    {
-	      slot++;
-	      dest_cpy = (char *)(stack - slot);
-	      dest_cpy += 4 - (*p_arg)->size;
-	      memcpy((char *)dest_cpy, (char *)*p_argv, (*p_arg)->size);
+	      dest_cpy = (char *)(stack - slot) + 4 - len;
+	      memcpy(dest_cpy, (char *)*p_argv, len);
 	    }
-	  else if ((*p_arg)->size <= 8) 
+	  else if (len <= 8)
 	    {
-	      slot += 2;
-	      if (slot & 1)
-	        slot++;
-	      dest_cpy = (char *)(stack - slot);
-	      dest_cpy += 8 - (*p_arg)->size;
-	      memcpy((char *)dest_cpy, (char *)*p_argv, (*p_arg)->size);
-	    } 
-	  else 
-	    {
-	      slot++;
-	      *(UINT32 *)(stack - slot) = (UINT32)(*p_argv);
+	      slot += (slot & 1) ? 1 : 2;
+	      dest_cpy = (char *)(stack - slot) + 8 - len;
+	      memcpy(dest_cpy, (char *)*p_argv, len);
 	    }
+	  else
+	    *(UINT32 *)(stack - slot) = (UINT32)(*p_argv);
 	  break;
 
 	default:
 	  FFI_ASSERT(0);
 	}
 
+      slot++;
       p_arg++;
       p_argv++;
     }
 
   /* Make sure we didn't mess up and scribble on the stack.  */
   {
-    int n;
+    unsigned int n;
 
     debug(5, "Stack setup:\n");
     for (n = 0; n < (bytes + 3) / 4; n++)
@@ -255,7 +273,7 @@
   return;
 }
 
-static void ffi_size_stack_LINUX(ffi_cif *cif)
+static void ffi_size_stack_pa32(ffi_cif *cif)
 {
   ffi_type **ptr;
   int i;
@@ -273,6 +291,9 @@
 	  z += 2 + (z & 1); /* must start on even regs, so we may waste one */
 	  break;
 
+#ifdef PA_HPUX
+	case FFI_TYPE_LONGDOUBLE:
+#endif
 	case FFI_TYPE_STRUCT:
 	  z += 1; /* pass by ptr, callee will copy */
 	  break;
@@ -304,6 +325,13 @@
       cif->flags = (unsigned) cif->rtype->type;
       break;
 
+#ifdef PA_HPUX
+    case FFI_TYPE_LONGDOUBLE:
+      /* Long doubles are treated like a structure.  */
+      cif->flags = FFI_TYPE_STRUCT;
+      break;
+#endif
+
     case FFI_TYPE_STRUCT:
       /* For the return type we have to check the size of the structures.
 	 If the size is smaller or equal 4 bytes, the result is given back
@@ -327,8 +355,8 @@
      own stack sizing.  */
   switch (cif->abi)
     {
-    case FFI_LINUX:
-      ffi_size_stack_LINUX(cif);
+    case FFI_PA32:
+      ffi_size_stack_pa32(cif);
       break;
 
     default:
@@ -339,20 +367,11 @@
   return FFI_OK;
 }
 
-/*@-declundef@*/
-/*@-exportheader@*/
-extern void ffi_call_LINUX(void (*)(UINT32 *, extended_cif *, unsigned),
-			   /*@out@*/ extended_cif *,
-			   unsigned, unsigned,
-			   /*@out@*/ unsigned *,
-			   void (*fn)());
-/*@=declundef@*/
-/*@=exportheader@*/
-
-void ffi_call(/*@dependent@*/ ffi_cif *cif,
-	      void (*fn)(),
-	      /*@out@*/ void *rvalue,
-	      /*@dependent@*/ void **avalue)
+extern void ffi_call_pa32(void (*)(UINT32 *, extended_cif *, unsigned),
+			  extended_cif *, unsigned, unsigned, unsigned *,
+			  void (*fn)(void));
+
+void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   extended_cif ecif;
 
@@ -362,12 +381,15 @@
   /* If the return value is a struct and we don't have a return
      value address then we need to make one.  */
 
-  if ((rvalue == NULL) &&
-      (cif->rtype->type == FFI_TYPE_STRUCT))
+  if (rvalue == NULL
+#ifdef PA_HPUX
+      && (cif->rtype->type == FFI_TYPE_STRUCT
+	  || cif->rtype->type == FFI_TYPE_LONGDOUBLE))
+#else
+      && cif->rtype->type == FFI_TYPE_STRUCT)
+#endif
     {
-      /*@-sysunrecog@*/
       ecif.rvalue = alloca(cif->rtype->size);
-      /*@=sysunrecog@*/
     }
   else
     ecif.rvalue = rvalue;
@@ -375,12 +397,10 @@
 
   switch (cif->abi)
     {
-    case FFI_LINUX:
-      /*@-usedef@*/
-      debug(2, "Calling ffi_call_LINUX: ecif=%p, bytes=%u, flags=%u, rvalue=%p, fn=%p\n", &ecif, cif->bytes, cif->flags, ecif.rvalue, (void *)fn);
-      ffi_call_LINUX(ffi_prep_args_LINUX, &ecif, cif->bytes,
+    case FFI_PA32:
+      debug(3, "Calling ffi_call_pa32: ecif=%p, bytes=%u, flags=%u, rvalue=%p, fn=%p\n", &ecif, cif->bytes, cif->flags, ecif.rvalue, (void *)fn);
+      ffi_call_pa32(ffi_prep_args_pa32, &ecif, cif->bytes,
 		     cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
       break;
 
     default:
@@ -394,7 +414,7 @@
    the stack, and we need to fill them into a cif structure and invoke
    the user function. This really ought to be in asm to make sure
    the compiler doesn't do things we don't expect.  */
-UINT32 ffi_closure_inner_LINUX(ffi_closure *closure, UINT32 *stack)
+ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
 {
   ffi_cif *cif;
   void **avalue;
@@ -402,7 +422,8 @@
   UINT32 ret[2]; /* function can return up to 64-bits in registers */
   ffi_type **p_arg;
   char *tmp;
-  int i, avn, slot = FIRST_ARG_SLOT - 1;
+  int i, avn;
+  unsigned int slot = FIRST_ARG_SLOT;
   register UINT32 r28 asm("r28");
 
   cif = closure->cif;
@@ -430,20 +451,23 @@
 	case FFI_TYPE_SINT32:
 	case FFI_TYPE_UINT32:
 	case FFI_TYPE_POINTER:
-	  slot++;
 	  avalue[i] = (char *)(stack - slot) + sizeof(UINT32) - (*p_arg)->size;
 	  break;
 
 	case FFI_TYPE_SINT64:
 	case FFI_TYPE_UINT64:
-	  slot += 2;
-	  if (slot & 1)
-	    slot++;
+	  slot += (slot & 1) ? 1 : 2;
 	  avalue[i] = (void *)(stack - slot);
 	  break;
 
 	case FFI_TYPE_FLOAT:
-	  slot++;
+#ifdef PA_LINUX
+	  /* The closure call is indirect.  In Linux, floating point
+	     arguments in indirect calls with a prototype are passed
+	     in the floating point registers instead of the general
+	     registers.  So, we need to replace what was previously
+	     stored in the current slot with the value in the
+	     corresponding floating point register.  */
 	  switch (slot - FIRST_ARG_SLOT)
 	    {
 	    case 0: fstw(fr4, (void *)(stack - slot)); break;
@@ -451,18 +475,20 @@
 	    case 2: fstw(fr6, (void *)(stack - slot)); break;
 	    case 3: fstw(fr7, (void *)(stack - slot)); break;
 	    }
+#endif
 	  avalue[i] = (void *)(stack - slot);
 	  break;
 
 	case FFI_TYPE_DOUBLE:
-	  slot += 2;
-	  if (slot & 1)
-	    slot++;
-	  switch (slot - FIRST_ARG_SLOT + 1)
+	  slot += (slot & 1) ? 1 : 2;
+#ifdef PA_LINUX
+	  /* See previous comment for FFI_TYPE_FLOAT.  */
+	  switch (slot - FIRST_ARG_SLOT)
 	    {
-	    case 2: fstd(fr5, (void *)(stack - slot)); break;
-	    case 4: fstd(fr7, (void *)(stack - slot)); break;
+	    case 1: fstd(fr5, (void *)(stack - slot)); break;
+	    case 3: fstd(fr7, (void *)(stack - slot)); break;
 	    }
+#endif
 	  avalue[i] = (void *)(stack - slot);
 	  break;
 
@@ -470,35 +496,36 @@
 	  /* Structs smaller or equal than 4 bytes are passed in one
 	     register. Structs smaller or equal 8 bytes are passed in two
 	     registers. Larger structures are passed by pointer.  */
-	  if((*p_arg)->size <= 4) {
-	    slot++;
-	    avalue[i] = (void *)(stack - slot) + sizeof(UINT32) -
-	      (*p_arg)->size;
-	  } else if ((*p_arg)->size <= 8) {
-	    slot += 2;
-	    if (slot & 1)
-	      slot++;
-	    avalue[i] = (void *)(stack - slot) + sizeof(UINT64) -
-	      (*p_arg)->size;
-	  } else {
-	    slot++;
+	  if((*p_arg)->size <= 4)
+	    {
+	      avalue[i] = (void *)(stack - slot) + sizeof(UINT32) -
+		(*p_arg)->size;
+	    }
+	  else if ((*p_arg)->size <= 8)
+	    {
+	      slot += (slot & 1) ? 1 : 2;
+	      avalue[i] = (void *)(stack - slot) + sizeof(UINT64) -
+		(*p_arg)->size;
+	    }
+	  else
 	    avalue[i] = (void *) *(stack - slot);
-	  }
 	  break;
 
 	default:
 	  FFI_ASSERT(0);
 	}
 
+      slot++;
       p_arg++;
     }
 
   /* Invoke the closure.  */
   (closure->fun) (cif, rvalue, avalue, closure->user_data);
 
-  debug(3, "after calling function, ret[0] = %08x, ret[1] = %08x\n", ret[0], ret[1]);
+  debug(3, "after calling function, ret[0] = %08x, ret[1] = %08x\n", ret[0],
+	ret[1]);
 
-  /* Store the result */
+  /* Store the result using the lower 2 bytes of the flags.  */
   switch (cif->flags)
     {
     case FFI_TYPE_UINT8:
@@ -536,7 +563,9 @@
       /* Don't need a return value, done by caller.  */
       break;
 
+    case FFI_TYPE_SMALL_STRUCT2:
     case FFI_TYPE_SMALL_STRUCT3:
+    case FFI_TYPE_SMALL_STRUCT4:
       tmp = (void*)(stack -  FIRST_ARG_SLOT);
       tmp += 4 - cif->rtype->size;
       memcpy((void*)tmp, &ret[0], cif->rtype->size);
@@ -545,6 +574,7 @@
     case FFI_TYPE_SMALL_STRUCT5:
     case FFI_TYPE_SMALL_STRUCT6:
     case FFI_TYPE_SMALL_STRUCT7:
+    case FFI_TYPE_SMALL_STRUCT8:
       {
 	unsigned int ret2[2];
 	int off;
@@ -582,39 +612,93 @@
    cif specifies the argument and result types for fun.
    The cif must already be prep'ed.  */
 
-void ffi_closure_LINUX(void);
+extern void ffi_closure_pa32(void);
 
 ffi_status
-ffi_prep_closure (ffi_closure* closure,
-		  ffi_cif* cif,
-		  void (*fun)(ffi_cif*,void*,void**,void*),
-		  void *user_data)
+ffi_prep_closure_loc (ffi_closure* closure,
+		      ffi_cif* cif,
+		      void (*fun)(ffi_cif*,void*,void**,void*),
+		      void *user_data,
+		      void *codeloc)
 {
   UINT32 *tramp = (UINT32 *)(closure->tramp);
+#ifdef PA_HPUX
+  UINT32 *tmp;
+#endif
 
-  FFI_ASSERT (cif->abi == FFI_LINUX);
+  FFI_ASSERT (cif->abi == FFI_PA32);
 
   /* Make a small trampoline that will branch to our
      handler function. Use PC-relative addressing.  */
 
-  tramp[0] = 0xeaa00000; /* b,l  .+8, %r21      ; %r21 <- pc+8 */
-  tramp[1] = 0xd6a01c1e; /* depi 0,31,2, %r21   ; mask priv bits */
-  tramp[2] = 0x4aa10028; /* ldw  20(%r21), %r1  ; load plabel */
-  tramp[3] = 0x36b53ff1; /* ldo  -8(%r21), %r21 ; get closure addr */
-  tramp[4] = 0x0c201096; /* ldw  0(%r1), %r22   ; address of handler */
-  tramp[5] = 0xeac0c000; /* bv	 %r0(%r22)      ; branch to handler */
-  tramp[6] = 0x0c281093; /* ldw  4(%r1), %r19   ; GP of handler */
-  tramp[7] = ((UINT32)(ffi_closure_LINUX) & ~2);
+#ifdef PA_LINUX
+  tramp[0] = 0xeaa00000; /* b,l .+8,%r21        ; %r21 <- pc+8 */
+  tramp[1] = 0xd6a01c1e; /* depi 0,31,2,%r21    ; mask priv bits */
+  tramp[2] = 0x4aa10028; /* ldw 20(%r21),%r1    ; load plabel */
+  tramp[3] = 0x36b53ff1; /* ldo -8(%r21),%r21   ; get closure addr */
+  tramp[4] = 0x0c201096; /* ldw 0(%r1),%r22     ; address of handler */
+  tramp[5] = 0xeac0c000; /* bv%r0(%r22)         ; branch to handler */
+  tramp[6] = 0x0c281093; /* ldw 4(%r1),%r19     ; GP of handler */
+  tramp[7] = ((UINT32)(ffi_closure_pa32) & ~2);
 
   /* Flush d/icache -- have to flush up 2 two lines because of
      alignment.  */
-  asm volatile (
-		"fdc 0(%0)\n"
-		"fdc %1(%0)\n"
-		"fic 0(%%sr4, %0)\n"
-		"fic %1(%%sr4, %0)\n"
-		"sync\n"
-		: : "r"((unsigned long)tramp & ~31), "r"(32 /* stride */));
+  __asm__ volatile(
+		   "fdc 0(%0)\n\t"
+		   "fdc %1(%0)\n\t"
+		   "fic 0(%%sr4, %0)\n\t"
+		   "fic %1(%%sr4, %0)\n\t"
+		   "sync\n\t"
+		   "nop\n\t"
+		   "nop\n\t"
+		   "nop\n\t"
+		   "nop\n\t"
+		   "nop\n\t"
+		   "nop\n\t"
+		   "nop\n"
+		   :
+		   : "r"((unsigned long)tramp & ~31),
+		     "r"(32 /* stride */)
+		   : "memory");
+#endif
+
+#ifdef PA_HPUX
+  tramp[0] = 0xeaa00000; /* b,l .+8,%r21        ; %r21 <- pc+8  */
+  tramp[1] = 0xd6a01c1e; /* depi 0,31,2,%r21    ; mask priv bits  */
+  tramp[2] = 0x4aa10038; /* ldw 28(%r21),%r1    ; load plabel  */
+  tramp[3] = 0x36b53ff1; /* ldo -8(%r21),%r21   ; get closure addr  */
+  tramp[4] = 0x0c201096; /* ldw 0(%r1),%r22     ; address of handler  */
+  tramp[5] = 0x02c010b4; /* ldsid (%r22),%r20   ; load space id  */
+  tramp[6] = 0x00141820; /* mtsp %r20,%sr0      ; into %sr0  */
+  tramp[7] = 0xe2c00000; /* be 0(%sr0,%r22)     ; branch to handler  */
+  tramp[8] = 0x0c281093; /* ldw 4(%r1),%r19     ; GP of handler  */
+  tramp[9] = ((UINT32)(ffi_closure_pa32) & ~2);
+
+  /* Flush d/icache -- have to flush three lines because of alignment.  */
+  __asm__ volatile(
+		   "copy %1,%0\n\t"
+		   "fdc,m %2(%0)\n\t"
+		   "fdc,m %2(%0)\n\t"
+		   "fdc,m %2(%0)\n\t"
+		   "ldsid (%1),%0\n\t"
+		   "mtsp %0,%%sr0\n\t"
+		   "copy %1,%0\n\t"
+		   "fic,m %2(%%sr0,%0)\n\t"
+		   "fic,m %2(%%sr0,%0)\n\t"
+		   "fic,m %2(%%sr0,%0)\n\t"
+		   "sync\n\t"
+		   "nop\n\t"
+		   "nop\n\t"
+		   "nop\n\t"
+		   "nop\n\t"
+		   "nop\n\t"
+		   "nop\n\t"
+		   "nop\n"
+		   : "=&r" ((unsigned long)tmp)
+		   : "r" ((unsigned long)tramp & ~31),
+		     "r" (32/* stride */)
+		   : "memory");
+#endif
 
   closure->cif  = cif;
   closure->user_data = user_data;

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/pa/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/pa/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/pa/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -13,13 +13,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 
@@ -35,9 +36,20 @@
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
 
-#ifdef PA
-  FFI_LINUX,
-  FFI_DEFAULT_ABI = FFI_LINUX,
+#ifdef PA_LINUX
+  FFI_PA32,
+  FFI_DEFAULT_ABI = FFI_PA32,
+#endif
+
+#ifdef PA_HPUX
+  FFI_PA32,
+  FFI_DEFAULT_ABI = FFI_PA32,
+#endif
+
+#ifdef PA64_HPUX
+#error "PA64_HPUX FFI is not yet implemented"
+  FFI_PA64,
+  FFI_DEFAULT_ABI = FFI_PA64,
 #endif
 
   FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
@@ -49,11 +61,17 @@
 #define FFI_CLOSURES 1
 #define FFI_NATIVE_RAW_API 0
 
+#ifdef PA_LINUX
 #define FFI_TRAMPOLINE_SIZE 32
-
-#define FFI_TYPE_SMALL_STRUCT3 -1
-#define FFI_TYPE_SMALL_STRUCT5 -2
-#define FFI_TYPE_SMALL_STRUCT6 -3
-#define FFI_TYPE_SMALL_STRUCT7 -4
+#else
+#define FFI_TRAMPOLINE_SIZE 40
 #endif
 
+#define FFI_TYPE_SMALL_STRUCT2 -1
+#define FFI_TYPE_SMALL_STRUCT3 -2
+#define FFI_TYPE_SMALL_STRUCT4 -3
+#define FFI_TYPE_SMALL_STRUCT5 -4
+#define FFI_TYPE_SMALL_STRUCT6 -5
+#define FFI_TYPE_SMALL_STRUCT7 -6
+#define FFI_TYPE_SMALL_STRUCT8 -7
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/pa/linux.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/pa/linux.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/pa/linux.S	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------------
    linux.S - (c) 2003-2004 Randolph Chung <tausq at debian.org>
+	     (c) 2008 Red Hat, Inc.
 
    HPPA Foreign Function Interface
 
@@ -17,7 +18,7 @@
    THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+   IN NO EVENT SHALL RENESAS TECHNOLOGY BE LIABLE FOR ANY CLAIM, DAMAGES OR
    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    OTHER DEALINGS IN THE SOFTWARE.
@@ -31,20 +32,20 @@
 	.level 1.1
 	.align 4
 
-	/* void ffi_call_LINUX(void (*)(char *, extended_cif *),
+	/* void ffi_call_pa32(void (*)(char *, extended_cif *),
 			       extended_cif *ecif,
 			       unsigned bytes,
 			       unsigned flags,
 			       unsigned *rvalue,
-			       void (*fn)());
+			       void (*fn)(void));
 	 */
 
-	.export ffi_call_LINUX,code
-	.import ffi_prep_args_LINUX,code
+	.export ffi_call_pa32,code
+	.import ffi_prep_args_pa32,code
 
-	.type ffi_call_LINUX, @function
+	.type ffi_call_pa32, @function
 .LFB1:
-ffi_call_LINUX:
+ffi_call_pa32:
 	.proc
 	.callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=4
 	.entry
@@ -63,7 +64,7 @@
 	   [ 64-bytes register save area               ] <- %r4
 
 	   [ Stack space for actual call, passed as    ] <- %arg0
-	   [     arg0 to ffi_prep_args_LINUX           ]
+	   [     arg0 to ffi_prep_args_pa32           ]
 
 	   [ Stack for calling prep_args               ] <- %sp
 	 */
@@ -73,14 +74,14 @@
 .LCFI13:
 	copy %sp, %r4
 
-	addl %arg2, %r4, %arg0                  /* arg stack */
-	stw %arg3, -48(%r3)                     /* save flags; we need it later */
+	addl %arg2, %r4, %arg0      /* arg stack */
+	stw %arg3, -48(%r3)         /* save flags; we need it later */
 
 	/* Call prep_args:
 	   %arg0(stack) -- set up above
 	   %arg1(ecif) -- same as incoming param
 	   %arg2(bytes) -- same as incoming param */
-	bl ffi_prep_args_LINUX,%r2
+	bl ffi_prep_args_pa32,%r2
 	ldo 64(%arg0), %sp
 	ldo -64(%sp), %sp
 
@@ -106,90 +107,139 @@
 
 	/* Store the result according to the return type.  */
 
-checksmst3:
-	comib,<>,n FFI_TYPE_SMALL_STRUCT3, %r21, checksmst567
-	/* 3-byte structs are returned in ret0 as ??xxyyzz.  Shift
-	   left 8 bits to write to the result structure.  */
-	zdep %ret0, 23, 24, %r22
-	b done
-	stw %r22, 0(%r20)
-
-checksmst567:
-	/* 5-7 byte values are returned right justified:
+.Lcheckint:
+	comib,<>,n FFI_TYPE_INT, %r21, .Lcheckint8
+	b	.Ldone
+	stw	%ret0, 0(%r20)
+
+.Lcheckint8:
+	comib,<>,n FFI_TYPE_UINT8, %r21, .Lcheckint16
+	b	.Ldone
+	stb	%ret0, 0(%r20)
+
+.Lcheckint16:
+	comib,<>,n FFI_TYPE_UINT16, %r21, .Lcheckdbl
+	b	.Ldone
+	sth	%ret0, 0(%r20)
+
+.Lcheckdbl:
+	comib,<>,n FFI_TYPE_DOUBLE, %r21, .Lcheckfloat
+	b	.Ldone
+	fstd	%fr4,0(%r20)
+
+.Lcheckfloat:
+	comib,<>,n FFI_TYPE_FLOAT, %r21, .Lcheckll
+	b	.Ldone
+	fstw	%fr4L,0(%r20)
+
+.Lcheckll:
+	comib,<>,n FFI_TYPE_UINT64, %r21, .Lchecksmst2
+	stw	%ret0, 0(%r20)
+	b	.Ldone
+	stw	%ret1, 4(%r20)
+
+.Lchecksmst2:
+	comib,<>,n FFI_TYPE_SMALL_STRUCT2, %r21, .Lchecksmst3
+	/* 2-byte structs are returned in ret0 as ????xxyy.  */
+	extru	%ret0, 23, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	b	.Ldone
+	stb	%ret0, 0(%r20)
+
+.Lchecksmst3:
+	comib,<>,n FFI_TYPE_SMALL_STRUCT3, %r21, .Lchecksmst4
+	/* 3-byte structs are returned in ret0 as ??xxyyzz.  */
+	extru	%ret0, 15, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret0, 23, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	b	.Ldone
+	stb	%ret0, 0(%r20)
+
+.Lchecksmst4:
+	comib,<>,n FFI_TYPE_SMALL_STRUCT4, %r21, .Lchecksmst5
+	/* 4-byte structs are returned in ret0 as wwxxyyzz.  */
+	extru	%ret0, 7, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret0, 15, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret0, 23, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	b	.Ldone
+	stb	%ret0, 0(%r20)
+
+.Lchecksmst5:
+	comib,<>,n FFI_TYPE_SMALL_STRUCT5, %r21, .Lchecksmst6
+	/* 5 byte values are returned right justified:
+	      ret0     ret1
+	   5: ??????aa bbccddee */
+	stbs,ma	%ret0, 1(%r20)
+	extru	%ret1, 7, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret1, 15, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret1, 23, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	b	.Ldone
+	stb	%ret1, 0(%r20)
+
+.Lchecksmst6:
+	comib,<>,n FFI_TYPE_SMALL_STRUCT6, %r21, .Lchecksmst7
+	/* 6 byte values are returned right justified:
+	      ret0     ret1
+	   6: ????aabb ccddeeff */
+	extru	%ret0, 23, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	stbs,ma	%ret0, 1(%r20)
+	extru	%ret1, 7, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret1, 15, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret1, 23, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	b	.Ldone
+	stb	%ret1, 0(%r20)
+
+.Lchecksmst7:
+	comib,<>,n FFI_TYPE_SMALL_STRUCT7, %r21, .Lchecksmst8
+	/* 7 byte values are returned right justified:
 	      ret0     ret1
-	   5: ??????aa bbccddee
-	   6: ????aabb ccddeeff
-	   7: ??aabbcc ddeeffgg
-
-	   To store this in the result, write the first 4 bytes into a temp
-	   register using shrpw (t1 = aabbccdd), followed by a rotation of
-	   ret1:
-
-	      ret0     ret1	   ret1
-	   5: ??????aa bbccddee -> eebbccdd (rotate 8)
-	   6: ????aabb ccddeeff -> eeffccdd (rotate 16)
-	   7: ??aabbcc ddeeffgg -> eeffggdd (rotate 24)
-
-	   then we write (t1, ret1) into the result.  */
-
-	addi,<> -FFI_TYPE_SMALL_STRUCT5,%r21,%r0
-	ldi 8, %r22
-	addi,<> -FFI_TYPE_SMALL_STRUCT6,%r21,%r0
-	ldi 16, %r22
-	addi,<> -FFI_TYPE_SMALL_STRUCT7,%r21,%r0
-	ldi 24, %r22
-
-	/* This relies on all the FFI_TYPE_*_STRUCT* defines being <0 */
-	cmpib,<=,n 0, %r21, checkint8
-	mtsar %r22
-
-	shrpw %ret0, %ret1, %sar, %ret0  /* ret0 = aabbccdd */
-	shrpw %ret1, %ret1, %sar, %ret1  /* rotate ret1 */
-	
-	stw %ret0, 0(%r20)
-	b done
-	stw %ret1, 4(%r20)
-
-checkint8:
-	comib,<>,n FFI_TYPE_UINT8, %r21, checkint16
-	b done
-	stb %ret0, 0(%r20)
-
-checkint16:
-	comib,<>,n FFI_TYPE_UINT16, %r21, checkint32
-	b done
-	sth %ret0, 0(%r20)
-
-checkint32:
-	comib,<>,n FFI_TYPE_UINT32, %r21, checkint
-	b done
-	stw %ret0, 0(%r20)
-
-checkint:
-	comib,<>,n FFI_TYPE_INT, %r21, checkll
-	b done
-	stw %ret0, 0(%r20)
-
-checkll:
-	comib,<>,n FFI_TYPE_UINT64, %r21, checkdbl
-	stw %ret0, 0(%r20)
-	b done
-	stw %ret1, 4(%r20)
-
-checkdbl:
-	comib,<>,n FFI_TYPE_DOUBLE, %r21, checkfloat
-	b done
-	fstd %fr4,0(%r20)
-
-checkfloat:
-	comib,<>,n FFI_TYPE_FLOAT, %r21, done
-	fstw %fr4L,0(%r20)
-
-	/* structure returns are either handled by one of the
-	   INT/UINT64 cases above, or, if passed by pointer,
-	   is handled by the callee.  */
+	   7: ??aabbcc ddeeffgg */
+	extru	%ret0, 15, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret0, 23, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	stbs,ma	%ret0, 1(%r20)
+	extru	%ret1, 7, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret1, 15, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret1, 23, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	b	.Ldone
+	stb	%ret1, 0(%r20)
+
+.Lchecksmst8:
+	comib,<>,n FFI_TYPE_SMALL_STRUCT8, %r21, .Ldone
+	/* 8 byte values are returned right justified:
+	      ret0     ret1
+	   8: aabbccdd eeffgghh */
+	extru	%ret0, 7, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret0, 15, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret0, 23, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	stbs,ma	%ret0, 1(%r20)
+	extru	%ret1, 7, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret1, 15, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	extru	%ret1, 23, 8, %r22
+	stbs,ma	%r22, 1(%r20)
+	stb	%ret1, 0(%r20)
 
-done:
+.Ldone:
 	/* all done, return */
 	copy %r4, %sp                           /* pop arg stack */
 	ldw 12(%r3), %r4
@@ -201,14 +251,14 @@
 	.procend
 .LFE1:
 
-	/* void ffi_closure_LINUX(void);
+	/* void ffi_closure_pa32(void);
 	   Called with closure argument in %r21 */
-	.export ffi_closure_LINUX,code
-	.import ffi_closure_inner_LINUX,code
+	.export ffi_closure_pa32,code
+	.import ffi_closure_inner_pa32,code
 
-	.type ffi_closure_LINUX, @function
+	.type ffi_closure_pa32, @function
 .LFB2:
-ffi_closure_LINUX:
+ffi_closure_pa32:
 	.proc
 	.callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
 	.entry
@@ -228,7 +278,7 @@
 	stw %arg3, -48(%r3)
 
 	copy %r21, %arg0
-	bl ffi_closure_inner_LINUX, %r2
+	bl ffi_closure_inner_pa32, %r2
 	copy %r3, %arg1
 
 	ldwm -64(%sp), %r3
@@ -299,7 +349,7 @@
 	.sleb128 -5
 
 	.byte   0x4     ;# DW_CFA_advance_loc4
-	.word   .LCFI12-.LCFI11
+	.word   .LCFI22-.LCFI21
 	.byte   0xd     ;# DW_CFA_def_cfa_register = r3
 	.uleb128 0x3
 

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/darwin.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/darwin.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/darwin.S	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-#ifdef __ppc__
 /* -----------------------------------------------------------------------
    darwin.S - Copyright (c) 2000 John Hornkvist
 	      Copyright (c) 2004 Free Software Foundation, Inc.
@@ -244,4 +243,3 @@
 	.align LOG2_GPR_BYTES
 LLFB0$non_lazy_ptr:
 	.g_long LFB0
-#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,3 @@
-#ifdef __ppc__
 /* -----------------------------------------------------------------------
    darwin_closure.S - Copyright (c) 2002, 2003, 2004, Free Software Foundation,
    Inc. based on ppc_closure.S
@@ -247,7 +246,7 @@
 /* END(ffi_closure_ASM)  */
 
 .data
-.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms
+.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
 EH_frame1:
 	.set	L$set$0,LECIE1-LSCIE1
 	.long	L$set$0	; Length of Common Information Entry
@@ -316,4 +315,3 @@
 	.align LOG2_GPR_BYTES
 LLFB1$non_lazy_ptr:
 	.g_long LFB1
-#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,7 @@
 /* -----------------------------------------------------------------------
    ffi.c - Copyright (c) 1998 Geoffrey Keating
+   Copyright (C) 2007 Free Software Foundation, Inc
+   Copyright (C) 2008 Red Hat, Inc
 
    PowerPC Foreign Function Interface
 
@@ -39,7 +41,8 @@
   FLAG_RETURNS_NOTHING  = 1 << (31-30), /* These go in cr7 */
   FLAG_RETURNS_FP       = 1 << (31-29),
   FLAG_RETURNS_64BITS   = 1 << (31-28),
-  FLAG_RETURNS_128BITS  = 1 << (31-27),
+
+  FLAG_RETURNS_128BITS  = 1 << (31-27), /* cr6  */
 
   FLAG_ARG_NEEDS_COPY   = 1 << (31- 7),
   FLAG_FP_ARGUMENTS     = 1 << (31- 6), /* cr1.eq; specified by ABI */
@@ -48,10 +51,13 @@
 };
 
 /* About the SYSV ABI.  */
-enum {
-  NUM_GPR_ARG_REGISTERS = 8,
-  NUM_FPR_ARG_REGISTERS = 8
-};
+unsigned int NUM_GPR_ARG_REGISTERS = 8;
+#ifndef __NO_FPRS__
+unsigned int NUM_FPR_ARG_REGISTERS = 8;
+#else
+unsigned int NUM_FPR_ARG_REGISTERS = 0;
+#endif
+
 enum { ASM_NEEDS_REGISTERS = 4 };
 
 /* ffi_prep_args_SYSV is called by the assembly routine once stack space
@@ -80,10 +86,8 @@
 
 */
 
-/*@-exportheader@*/
 void
 ffi_prep_args_SYSV (extended_cif *ecif, unsigned *const stack)
-/*@=exportheader@*/
 {
   const unsigned bytes = ecif->cif->bytes;
   const unsigned flags = ecif->cif->flags;
@@ -116,7 +120,7 @@
   /* 'next_arg' grows up as we put parameters in it.  */
   valp next_arg;
 
-  int i;
+  int i, ii MAYBE_UNUSED;
   ffi_type **ptr;
   double double_tmp;
   union {
@@ -134,6 +138,9 @@
   size_t struct_copy_size;
   unsigned gprvalue;
 
+  if (ecif->cif->abi == FFI_LINUX_SOFT_FLOAT)
+    NUM_FPR_ARG_REGISTERS = 0;
+
   stacktop.c = (char *) stack + bytes;
   gpr_base.u = stacktop.u - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS;
   intarg_count = 0;
@@ -165,6 +172,9 @@
       switch ((*ptr)->type)
 	{
 	case FFI_TYPE_FLOAT:
+	  /* With FFI_LINUX_SOFT_FLOAT floats are handled like UINT32.  */
+	  if (ecif->cif->abi == FFI_LINUX_SOFT_FLOAT)
+	    goto soft_float_prep;
 	  double_tmp = **p_argv.f;
 	  if (fparg_count >= NUM_FPR_ARG_REGISTERS)
 	    {
@@ -178,6 +188,9 @@
 	  break;
 
 	case FFI_TYPE_DOUBLE:
+	  /* With FFI_LINUX_SOFT_FLOAT doubles are handled like UINT64.  */
+	  if (ecif->cif->abi == FFI_LINUX_SOFT_FLOAT)
+	    goto soft_double_prep;
 	  double_tmp = **p_argv.d;
 
 	  if (fparg_count >= NUM_FPR_ARG_REGISTERS)
@@ -197,8 +210,77 @@
 	  FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 	  break;
 
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+	case FFI_TYPE_LONGDOUBLE:
+	  if ((ecif->cif->abi != FFI_LINUX)
+		&& (ecif->cif->abi != FFI_LINUX_SOFT_FLOAT))
+	    goto do_struct;
+	  /* The soft float ABI for long doubles works like this,
+	     a long double is passed in four consecutive gprs if available.
+	     A maximum of 2 long doubles can be passed in gprs.
+	     If we do not have 4 gprs left, the long double is passed on the
+	     stack, 4-byte aligned.  */
+	  if (ecif->cif->abi == FFI_LINUX_SOFT_FLOAT)
+	    {
+	      unsigned int int_tmp = (*p_argv.ui)[0];
+	      if (intarg_count >= NUM_GPR_ARG_REGISTERS - 3)
+		{
+		  if (intarg_count < NUM_GPR_ARG_REGISTERS)
+		    intarg_count += NUM_GPR_ARG_REGISTERS - intarg_count;
+		  *next_arg.u = int_tmp;
+		  next_arg.u++;
+		  for (ii = 1; ii < 4; ii++)
+		    {
+		      int_tmp = (*p_argv.ui)[ii];
+		      *next_arg.u = int_tmp;
+		      next_arg.u++;
+		    }
+		}
+	      else
+		{
+		  *gpr_base.u++ = int_tmp;
+		  for (ii = 1; ii < 4; ii++)
+		    {
+		      int_tmp = (*p_argv.ui)[ii];
+		      *gpr_base.u++ = int_tmp;
+		    }
+		}
+	      intarg_count +=4;
+	    }
+	  else
+	    {
+	      double_tmp = (*p_argv.d)[0];
+
+	      if (fparg_count >= NUM_FPR_ARG_REGISTERS - 1)
+		{
+		  if (intarg_count >= NUM_GPR_ARG_REGISTERS
+		      && intarg_count % 2 != 0)
+		    {
+		      intarg_count++;
+		      next_arg.u++;
+		    }
+		  *next_arg.d = double_tmp;
+		  next_arg.u += 2;
+		  double_tmp = (*p_argv.d)[1];
+		  *next_arg.d = double_tmp;
+		  next_arg.u += 2;
+		}
+	      else
+		{
+		  *fpr_base.d++ = double_tmp;
+		  double_tmp = (*p_argv.d)[1];
+		  *fpr_base.d++ = double_tmp;
+		}
+
+	      fparg_count += 2;
+	      FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
+	    }
+	  break;
+#endif
+
 	case FFI_TYPE_UINT64:
 	case FFI_TYPE_SINT64:
+	soft_double_prep:
 	  if (intarg_count == NUM_GPR_ARG_REGISTERS-1)
 	    intarg_count++;
 	  if (intarg_count >= NUM_GPR_ARG_REGISTERS)
@@ -232,7 +314,7 @@
 
 	case FFI_TYPE_STRUCT:
 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
-	case FFI_TYPE_LONGDOUBLE:
+	do_struct:
 #endif
 	  struct_copy_size = ((*ptr)->size + 15) & ~0xF;
 	  copy_space.c -= struct_copy_size;
@@ -261,6 +343,8 @@
 	case FFI_TYPE_UINT32:
 	case FFI_TYPE_SINT32:
 	case FFI_TYPE_POINTER:
+	soft_float_prep:
+
 	  gprvalue = **p_argv.ui;
 
 	putgpr:
@@ -322,10 +406,8 @@
 
 */
 
-/*@-exportheader@*/
 void FFI_HIDDEN
 ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack)
-/*@=exportheader@*/
 {
   const unsigned long bytes = ecif->cif->bytes;
   const unsigned long flags = ecif->cif->flags;
@@ -433,6 +515,7 @@
 	  if (fparg_count < NUM_FPR_ARG_REGISTERS64)
 	    *fpr_base.d++ = double_tmp;
 	  fparg_count++;
+	  FFI_ASSERT (__LDBL_MANT_DIG__ == 106);
 	  FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 	  break;
 #endif
@@ -515,6 +598,9 @@
   unsigned type = cif->rtype->type;
   unsigned size = cif->rtype->size;
 
+  if (cif->abi == FFI_LINUX_SOFT_FLOAT)
+    NUM_FPR_ARG_REGISTERS = 0;
+
   if (cif->abi != FFI_LINUX64)
     {
       /* All the machine-independent calculation of cif->bytes will be wrong.
@@ -536,11 +622,6 @@
 
       /* Space for the mandatory parm save area and general registers.  */
       bytes += 2 * NUM_GPR_ARG_REGISTERS64 * sizeof (long);
-
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
-      if (type == FFI_TYPE_LONGDOUBLE)
-	type = FFI_TYPE_DOUBLE;
-#endif
     }
 
   /* Return value handling.  The rules for SYSV are as follows:
@@ -549,19 +630,33 @@
      - 64-bit integer values and structures between 5 and 8 bytes are returned
      in gpr3 and gpr4;
      - Single/double FP values are returned in fpr1;
-     - Larger structures and long double (if not equivalent to double) values
-     are allocated space and a pointer is passed as the first argument.
+     - Larger structures are allocated space and a pointer is passed as
+     the first argument.
+     - long doubles (if not equivalent to double) are returned in
+     fpr1,fpr2 for Linux and as for large structs for SysV.
      For LINUX64:
      - integer values in gpr3;
      - Structures/Unions by reference;
-     - Single/double FP values in fpr1, long double in fpr1,fpr2.  */
+     - Single/double FP values in fpr1, long double in fpr1,fpr2.
+     - soft-float float/doubles are treated as UINT32/UINT64 respectivley.
+     - soft-float long doubles are returned in gpr3-gpr6.  */
   switch (type)
     {
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+    case FFI_TYPE_LONGDOUBLE:
+      if (cif->abi != FFI_LINUX && cif->abi != FFI_LINUX64
+	&& cif->abi != FFI_LINUX_SOFT_FLOAT)
+	goto byref;
+      flags |= FLAG_RETURNS_128BITS;
+      /* Fall through.  */
+#endif
     case FFI_TYPE_DOUBLE:
       flags |= FLAG_RETURNS_64BITS;
       /* Fall through.  */
     case FFI_TYPE_FLOAT:
-      flags |= FLAG_RETURNS_FP;
+      /* With FFI_LINUX_SOFT_FLOAT no fp registers are used.  */
+      if (cif->abi != FFI_LINUX_SOFT_FLOAT)
+	flags |= FLAG_RETURNS_FP;
       break;
 
     case FFI_TYPE_UINT64:
@@ -598,15 +693,8 @@
 		}
 	    }
 	}
-      /* else fall through.  */
 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
-    case FFI_TYPE_LONGDOUBLE:
-      if (type == FFI_TYPE_LONGDOUBLE && cif->abi == FFI_LINUX64)
-	{
-	  flags |= FLAG_RETURNS_128BITS;
-	  flags |= FLAG_RETURNS_FP;
-	  break;
-	}
+    byref:
 #endif
       intarg_count++;
       flags |= FLAG_RETVAL_REFERENCE;
@@ -631,11 +719,36 @@
 	switch ((*ptr)->type)
 	  {
 	  case FFI_TYPE_FLOAT:
+	    /* With FFI_LINUX_SOFT_FLOAT floats are handled like UINT32.  */
+	    if (cif->abi == FFI_LINUX_SOFT_FLOAT)
+	      goto soft_float_cif;
 	    fparg_count++;
 	    /* floating singles are not 8-aligned on stack */
 	    break;
 
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+	  case FFI_TYPE_LONGDOUBLE:
+	    if (cif->abi != FFI_LINUX && cif->abi != FFI_LINUX_SOFT_FLOAT)
+	      goto do_struct;
+	    if (cif->abi == FFI_LINUX_SOFT_FLOAT)
+	      {
+		if (intarg_count >= NUM_GPR_ARG_REGISTERS - 3
+		  || intarg_count < NUM_GPR_ARG_REGISTERS)
+		  /* A long double in FFI_LINUX_SOFT_FLOAT can use only
+		     a set of four consecutive gprs. If we have not enough,
+		     we have to adjust the intarg_count value.  */
+		  intarg_count += NUM_GPR_ARG_REGISTERS - intarg_count;
+		intarg_count += 4;
+		break;
+	      }
+	    else
+	      fparg_count++;
+	    /* Fall thru */
+#endif
 	  case FFI_TYPE_DOUBLE:
+	    /* With FFI_LINUX_SOFT_FLOAT doubles are handled like UINT64.  */
+	    if (cif->abi == FFI_LINUX_SOFT_FLOAT)
+	      goto soft_double_cif;
 	    fparg_count++;
 	    /* If this FP arg is going on the stack, it must be
 	       8-byte-aligned.  */
@@ -647,6 +760,7 @@
 
 	  case FFI_TYPE_UINT64:
 	  case FFI_TYPE_SINT64:
+	  soft_double_cif:
 	    /* 'long long' arguments are passed as two words, but
 	       either both words must fit in registers or both go
 	       on the stack.  If they go on the stack, they must
@@ -664,7 +778,7 @@
 
 	  case FFI_TYPE_STRUCT:
 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
-	  case FFI_TYPE_LONGDOUBLE:
+	  do_struct:
 #endif
 	    /* We must allocate space for a copy of these to enforce
 	       pass-by-value.  Pad the space up to a multiple of 16
@@ -674,6 +788,7 @@
 	    /* Fall through (allocate space for the pointer).  */
 
 	  default:
+	  soft_float_cif:
 	    /* Everything else is passed as a 4-byte word in a GPR, either
 	       the object itself or a pointer to it.  */
 	    intarg_count++;
@@ -687,8 +802,13 @@
 	  {
 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 	  case FFI_TYPE_LONGDOUBLE:
-	    fparg_count += 2;
-	    intarg_count += 2;
+	    if (cif->abi == FFI_LINUX_SOFT_FLOAT)
+	      intarg_count += 4;
+	    else
+	      {
+		fparg_count += 2;
+		intarg_count += 2;
+	      }
 	    break;
 #endif
 	  case FFI_TYPE_FLOAT:
@@ -751,24 +871,14 @@
   return FFI_OK;
 }
 
-/*@-declundef@*/
-/*@-exportheader@*/
-extern void ffi_call_SYSV(/*@out@*/ extended_cif *,
-			  unsigned, unsigned,
-			  /*@out@*/ unsigned *,
-			  void (*fn)());
-extern void FFI_HIDDEN ffi_call_LINUX64(/*@out@*/ extended_cif *,
-					unsigned long, unsigned long,
-					/*@out@*/ unsigned long *,
-					void (*fn)());
-/*@=declundef@*/
-/*@=exportheader@*/
+extern void ffi_call_SYSV(extended_cif *, unsigned, unsigned, unsigned *,
+			  void (*fn)(void));
+extern void FFI_HIDDEN ffi_call_LINUX64(extended_cif *, unsigned long,
+					unsigned long, unsigned long *,
+					void (*fn)(void));
 
 void
-ffi_call(/*@dependent@*/ ffi_cif *cif,
-	 void (*fn)(),
-	 /*@out@*/ void *rvalue,
-	 /*@dependent@*/ void **avalue)
+ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   extended_cif ecif;
 
@@ -780,9 +890,7 @@
 
   if ((rvalue == NULL) && (cif->rtype->type == FFI_TYPE_STRUCT))
     {
-      /*@-sysunrecog@*/
       ecif.rvalue = alloca(cif->rtype->size);
-      /*@=sysunrecog@*/
     }
   else
     ecif.rvalue = rvalue;
@@ -793,15 +901,13 @@
 #ifndef POWERPC64
     case FFI_SYSV:
     case FFI_GCC_SYSV:
-      /*@-usedef@*/
+    case FFI_LINUX:
+    case FFI_LINUX_SOFT_FLOAT:
       ffi_call_SYSV (&ecif, -cif->bytes, cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
       break;
 #else
     case FFI_LINUX64:
-      /*@-usedef@*/
       ffi_call_LINUX64 (&ecif, -(long) cif->bytes, cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
       break;
 #endif
     default:
@@ -815,27 +921,24 @@
 #define MIN_CACHE_LINE_SIZE 8
 
 static void
-flush_icache (char *addr1, int size)
+flush_icache (char *wraddr, char *xaddr, int size)
 {
   int i;
-  char * addr;
   for (i = 0; i < size; i += MIN_CACHE_LINE_SIZE)
-    {
-      addr = addr1 + i;
-      __asm__ volatile ("icbi 0,%0;" "dcbf 0,%0;"
-			: : "r" (addr) : "memory");
-    }
-  addr = addr1 + size - 1;
-  __asm__ volatile ("icbi 0,%0;" "dcbf 0,%0;" "sync;" "isync;"
-		    : : "r"(addr) : "memory");
+    __asm__ volatile ("icbi 0,%0;" "dcbf 0,%1;"
+		      : : "r" (xaddr + i), "r" (wraddr + i) : "memory");
+  __asm__ volatile ("icbi 0,%0;" "dcbf 0,%1;" "sync;" "isync;"
+		    : : "r"(xaddr + size - 1), "r"(wraddr + size - 1)
+		    : "memory");
 }
 #endif
 
 ffi_status
-ffi_prep_closure (ffi_closure *closure,
-		  ffi_cif *cif,
-		  void (*fun) (ffi_cif *, void *, void **, void *),
-		  void *user_data)
+ffi_prep_closure_loc (ffi_closure *closure,
+		      ffi_cif *cif,
+		      void (*fun) (ffi_cif *, void *, void **, void *),
+		      void *user_data,
+		      void *codeloc)
 {
 #ifdef POWERPC64
   void **tramp = (void **) &closure->tramp[0];
@@ -843,7 +946,7 @@
   FFI_ASSERT (cif->abi == FFI_LINUX64);
   /* Copy function address and TOC from ffi_closure_LINUX64.  */
   memcpy (tramp, (char *) ffi_closure_LINUX64, 16);
-  tramp[2] = (void *) closure;
+  tramp[2] = codeloc;
 #else
   unsigned int *tramp;
 
@@ -859,10 +962,10 @@
   tramp[8] = 0x7c0903a6;  /*   mtctr   r0 */
   tramp[9] = 0x4e800420;  /*   bctr */
   *(void **) &tramp[2] = (void *) ffi_closure_SYSV; /* function */
-  *(void **) &tramp[3] = (void *) closure;          /* context */
+  *(void **) &tramp[3] = codeloc;                   /* context */
 
   /* Flush the icache.  */
-  flush_icache (&closure->tramp[0],FFI_TRAMPOLINE_SIZE);
+  flush_icache ((char *)tramp, (char *)codeloc, FFI_TRAMPOLINE_SIZE);
 #endif
 
   closure->cif = cif;
@@ -920,14 +1023,17 @@
      For FFI_SYSV the result is passed in r3/r4 if the struct size is less
      or equal 8 bytes.  */
 
-  if (cif->rtype->type == FFI_TYPE_STRUCT)
+  if ((cif->rtype->type == FFI_TYPE_STRUCT
+       && !((cif->abi == FFI_SYSV) && (size <= 8)))
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+      || (cif->rtype->type == FFI_TYPE_LONGDOUBLE
+	  && cif->abi != FFI_LINUX && cif->abi != FFI_LINUX_SOFT_FLOAT)
+#endif
+      )
     {
-      if (!((cif->abi == FFI_SYSV) && (size <= 8)))
-	{
-	  rvalue = (void *) *pgr;
-	  ng++;
-	  pgr++;
-	}
+      rvalue = (void *) *pgr;
+      ng++;
+      pgr++;
     }
 
   i = 0;
@@ -974,6 +1080,7 @@
 	case FFI_TYPE_SINT32:
 	case FFI_TYPE_UINT32:
 	case FFI_TYPE_POINTER:
+	soft_float_closure:
 	  /* there are 8 gpr registers used to pass values */
 	  if (ng < 8)
 	    {
@@ -989,6 +1096,9 @@
 	  break;
 
 	case FFI_TYPE_STRUCT:
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+	do_struct:
+#endif
 	  /* Structs are passed by reference. The address will appear in a
 	     gpr if it is one of the first 8 arguments.  */
 	  if (ng < 8)
@@ -1006,6 +1116,7 @@
 
 	case FFI_TYPE_SINT64:
 	case FFI_TYPE_UINT64:
+	soft_double_closure:
 	  /* passing long long ints are complex, they must
 	   * be passed in suitable register pairs such as
 	   * (r3,r4) or (r5,r6) or (r6,r7), or (r7,r8) or (r9,r10)
@@ -1037,6 +1148,9 @@
 	  break;
 
 	case FFI_TYPE_FLOAT:
+	  /* With FFI_LINUX_SOFT_FLOAT floats are handled like UINT32.  */
+	  if (cif->abi == FFI_LINUX_SOFT_FLOAT)
+	    goto soft_float_closure;
 	  /* unfortunately float values are stored as doubles
 	   * in the ffi_closure_SYSV code (since we don't check
 	   * the type in that routine).
@@ -1060,12 +1174,14 @@
 	       * naughty thing to do but...
 	       */
 	      avalue[i] = pst;
-	      nf++;
 	      pst += 1;
 	    }
 	  break;
 
 	case FFI_TYPE_DOUBLE:
+	  /* With FFI_LINUX_SOFT_FLOAT doubles are handled like UINT64.  */
+	  if (cif->abi == FFI_LINUX_SOFT_FLOAT)
+	    goto soft_double_closure;
 	  /* On the outgoing stack all values are aligned to 8 */
 	  /* there are 8 64bit floating point registers */
 
@@ -1080,11 +1196,47 @@
 	      if (((long) pst) & 4)
 		pst++;
 	      avalue[i] = pst;
-	      nf++;
 	      pst += 2;
 	    }
 	  break;
 
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+	case FFI_TYPE_LONGDOUBLE:
+	  if (cif->abi != FFI_LINUX && cif->abi != FFI_LINUX_SOFT_FLOAT)
+	    goto do_struct;
+	  if (cif->abi == FFI_LINUX_SOFT_FLOAT)
+	    { /* Test if for the whole long double, 4 gprs are available.
+		 otherwise the stuff ends up on the stack.  */
+	      if (ng < 5)
+		{
+		  avalue[i] = pgr;
+		  pgr += 4;
+		  ng += 4;
+		}
+	      else
+		{
+		  avalue[i] = pst;
+		  pst += 4;
+		}
+	      break;
+	    }
+	  if (nf < 7)
+	    {
+	      avalue[i] = pfr;
+	      pfr += 2;
+	      nf += 2;
+	    }
+	  else
+	    {
+	      if (((long) pst) & 4)
+		pst++;
+	      avalue[i] = pst;
+	      pst += 4;
+	      nf = 8;
+	    }
+	  break;
+#endif
+
 	default:
 	  FFI_ASSERT (0);
 	}
@@ -1101,8 +1253,36 @@
   if (cif->abi == FFI_SYSV && cif->rtype->type == FFI_TYPE_STRUCT
       && size <= 8)
     return FFI_SYSV_TYPE_SMALL_STRUCT + size;
-  return cif->rtype->type;
-
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+  else if (cif->rtype->type == FFI_TYPE_LONGDOUBLE
+	   && cif->abi != FFI_LINUX && cif->abi != FFI_LINUX_SOFT_FLOAT)
+    return FFI_TYPE_STRUCT;
+#endif
+  /* With FFI_LINUX_SOFT_FLOAT floats and doubles are handled like UINT32
+     respectivley UINT64.  */
+  if (cif->abi == FFI_LINUX_SOFT_FLOAT)
+    {
+      switch (cif->rtype->type)
+	{
+	case FFI_TYPE_FLOAT:
+	  return FFI_TYPE_UINT32;
+	  break;
+	case FFI_TYPE_DOUBLE:
+	  return FFI_TYPE_UINT64;
+	  break;
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+	case FFI_TYPE_LONGDOUBLE:
+	  return FFI_TYPE_UINT128;
+	  break;
+#endif
+	default:
+	  return cif->rtype->type;
+	}
+    }
+  else
+    {
+      return cif->rtype->type;
+    }
 }
 
 int FFI_HIDDEN ffi_closure_helper_LINUX64 (ffi_closure *, void *,

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c	Thu Mar 27 00:48:05 2008
@@ -1,12 +1,12 @@
-#if !(defined(__APPLE__) && !defined(__ppc__))
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1998 Geoffrey Keating
+   ffi_darwin.c
 
-   PowerPC Foreign Function Interface
-
-   Darwin ABI support (c) 2001 John Hornkvist
-   AIX ABI support (c) 2002 Free Software Foundation, Inc.
+   Copyright (C) 1998 Geoffrey Keating
+   Copyright (C) 2001 John Hornkvist
+   Copyright (C) 2002, 2006, 2007 Free Software Foundation, Inc.
 
+   FFI support for Darwin and AIX.
+   
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    ``Software''), to deal in the Software without restriction, including
@@ -80,9 +80,7 @@
 
    */
 
-/*@-exportheader@*/
 void ffi_prep_args(extended_cif *ecif, unsigned *const stack)
-/*@=exportheader@*/
 {
   const unsigned bytes = ecif->cif->bytes;
   const unsigned flags = ecif->cif->flags;
@@ -228,6 +226,48 @@
   //FFI_ASSERT(flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4);
 }
 
+/* Adjust the size of S to be correct for Darwin.
+   On Darwin, the first field of a structure has natural alignment.  */
+
+static void
+darwin_adjust_aggregate_sizes (ffi_type *s)
+{
+  int i;
+
+  if (s->type != FFI_TYPE_STRUCT)
+    return;
+
+  s->size = 0;
+  for (i = 0; s->elements[i] != NULL; i++)
+    {
+      ffi_type *p;
+      int align;
+      
+      p = s->elements[i];
+      darwin_adjust_aggregate_sizes (p);
+      if (i == 0
+	  && (p->type == FFI_TYPE_UINT64
+	      || p->type == FFI_TYPE_SINT64
+	      || p->type == FFI_TYPE_DOUBLE
+	      || p->alignment == 8))
+	align = 8;
+      else if (p->alignment == 16 || p->alignment < 4)
+	align = p->alignment;
+      else
+	align = 4;
+      s->size = ALIGN(s->size, align) + p->size;
+    }
+  
+  s->size = ALIGN(s->size, s->alignment);
+  
+  if (s->elements[0]->type == FFI_TYPE_UINT64
+      || s->elements[0]->type == FFI_TYPE_SINT64
+      || s->elements[0]->type == FFI_TYPE_DOUBLE
+      || s->elements[0]->alignment == 8)
+    s->alignment = s->alignment > 8 ? s->alignment : 8;
+  /* Do not add additional tail padding.  */
+}
+
 /* Perform machine dependent cif processing.  */
 ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
 {
@@ -240,8 +280,16 @@
   unsigned size_al = 0;
 
   /* All the machine-independent calculation of cif->bytes will be wrong.
+     All the calculation of structure sizes will also be wrong.
      Redo the calculation for DARWIN.  */
 
+  if (cif->abi == FFI_DARWIN)
+    {
+      darwin_adjust_aggregate_sizes (cif->rtype);
+      for (i = 0; i < cif->nargs; i++)
+	darwin_adjust_aggregate_sizes (cif->arg_types[i]);
+    }
+
   /* Space for the frame pointer, callee's LR, CR, etc, and for
      the asm's temp regs.  */
 
@@ -376,25 +424,12 @@
   return FFI_OK;
 }
 
-/*@-declundef@*/
-/*@-exportheader@*/
-extern void ffi_call_AIX(/*@out@*/ extended_cif *,
-			 unsigned, unsigned,
-			 /*@out@*/ unsigned *,
-			 void (*fn)(void),
-			 void (*fn2)(extended_cif *, unsigned *const));
-extern void ffi_call_DARWIN(/*@out@*/ extended_cif *,
-			    unsigned, unsigned,
-			    /*@out@*/ unsigned *,
-			    void (*fn)(void),
-			    void (*fn2)(extended_cif *, unsigned *const));
-/*@=declundef@*/
-/*@=exportheader@*/
-
-void ffi_call(/*@dependent@*/ ffi_cif *cif,
-	      void (*fn)(void),
-	      /*@out@*/ void *rvalue,
-	      /*@dependent@*/ void **avalue)
+extern void ffi_call_AIX(extended_cif *, unsigned, unsigned, unsigned *,
+			 void (*fn)(void), void (*fn2)(void));
+extern void ffi_call_DARWIN(extended_cif *, unsigned, unsigned, unsigned *,
+			    void (*fn)(void), void (*fn2)(void));
+
+void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   extended_cif ecif;
 
@@ -407,9 +442,7 @@
   if ((rvalue == NULL) &&
       (cif->rtype->type == FFI_TYPE_STRUCT))
     {
-      /*@-sysunrecog@*/
       ecif.rvalue = alloca(cif->rtype->size);
-      /*@=sysunrecog@*/
     }
   else
     ecif.rvalue = rvalue;
@@ -417,16 +450,12 @@
   switch (cif->abi)
     {
     case FFI_AIX:
-      /*@-usedef@*/
-      ffi_call_AIX(&ecif, -cif->bytes,
-		   cif->flags, ecif.rvalue, fn, ffi_prep_args);
-      /*@=usedef@*/
+      ffi_call_AIX(&ecif, -cif->bytes, cif->flags, ecif.rvalue, fn,
+		   ffi_prep_args);
       break;
     case FFI_DARWIN:
-      /*@-usedef@*/
-      ffi_call_DARWIN(&ecif, -cif->bytes,
-		      cif->flags, ecif.rvalue, fn, ffi_prep_args);
-      /*@=usedef@*/
+      ffi_call_DARWIN(&ecif, -cif->bytes, cif->flags, ecif.rvalue, fn,
+		      ffi_prep_args);
       break;
     default:
       FFI_ASSERT(0);
@@ -499,10 +528,11 @@
 
 */
 ffi_status
-ffi_prep_closure (ffi_closure* closure,
-		  ffi_cif* cif,
-		  void (*fun)(ffi_cif*, void*, void**, void*),
-		  void *user_data)
+ffi_prep_closure_loc (ffi_closure* closure,
+		      ffi_cif* cif,
+		      void (*fun)(ffi_cif*, void*, void**, void*),
+		      void *user_data,
+		      void *codeloc)
 {
   unsigned int *tramp;
   struct ffi_aix_trampoline_struct *tramp_aix;
@@ -524,14 +554,14 @@
       tramp[8] = 0x816b0004;  /*   lwz     r11,4(r11) static chain  */
       tramp[9] = 0x4e800420;  /*   bctr  */
       tramp[2] = (unsigned long) ffi_closure_ASM; /* function  */
-      tramp[3] = (unsigned long) closure; /* context  */
+      tramp[3] = (unsigned long) codeloc; /* context  */
 
       closure->cif = cif;
       closure->fun = fun;
       closure->user_data = user_data;
 
       /* Flush the icache. Only necessary on Darwin.  */
-      flush_range(&closure->tramp[0],FFI_TRAMPOLINE_SIZE);
+      flush_range(codeloc, FFI_TRAMPOLINE_SIZE);
 
       break;
 
@@ -544,7 +574,7 @@
 
       tramp_aix->code_pointer = fd->code_pointer;
       tramp_aix->toc = fd->toc;
-      tramp_aix->static_chain = closure;
+      tramp_aix->static_chain = codeloc;
       closure->cif = cif;
       closure->fun = fun;
       closure->user_data = user_data;
@@ -768,4 +798,3 @@
   /* Tell ffi_closure_ASM to perform return type promotions.  */
   return cif->rtype->type;
 }
-#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------*-C-*-
    ffitarget.h - Copyright (c) 1996-2003  Red Hat, Inc.
+   Copyright (C) 2007 Free Software Foundation, Inc
    Target configuration macros for PowerPC.
 
    Permission is hereby granted, free of charge, to any person obtaining
@@ -13,13 +14,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 
@@ -43,10 +45,20 @@
   FFI_SYSV,
   FFI_GCC_SYSV,
   FFI_LINUX64,
+  FFI_LINUX,
+  FFI_LINUX_SOFT_FLOAT,
 # ifdef POWERPC64
   FFI_DEFAULT_ABI = FFI_LINUX64,
 # else
+#  if (!defined(__NO_FPRS__) && (__LDBL_MANT_DIG__ == 106))
+  FFI_DEFAULT_ABI = FFI_LINUX,
+#  else
+#   ifdef __NO_FPRS__
+  FFI_DEFAULT_ABI = FFI_LINUX_SOFT_FLOAT,
+#   else
   FFI_DEFAULT_ABI = FFI_GCC_SYSV,
+#   endif
+#  endif
 # endif
 #endif
 
@@ -69,7 +81,7 @@
   FFI_DEFAULT_ABI = FFI_SYSV,
 #endif
 
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI
 } ffi_abi;
 #endif
 
@@ -78,8 +90,14 @@
 #define FFI_CLOSURES 1
 #define FFI_NATIVE_RAW_API 0
 
+/* For additional types like the below, take care about the order in
+   ppc_closures.S. They must follow after the FFI_TYPE_LAST.  */
+
+/* Needed for soft-float long-double-128 support.  */
+#define FFI_TYPE_UINT128 (FFI_TYPE_LAST + 1)
+
 /* Needed for FFI_SYSV small structure returns.  */
-#define FFI_SYSV_TYPE_SMALL_STRUCT  (FFI_TYPE_LAST)
+#define FFI_SYSV_TYPE_SMALL_STRUCT (FFI_TYPE_LAST + 2)
 
 #if defined(POWERPC64) || defined(POWERPC_AIX)
 #define FFI_TRAMPOLINE_SIZE 24

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/linux64.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/linux64.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/linux64.S	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------------
    sysv.h - Copyright (c) 2003 Jakub Jelinek <jakub at redhat.com>
+	    Copyright (c) 2008 Red Hat, Inc.
 
    PowerPC64 Assembly glue.
 
@@ -14,13 +15,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #define LIBFFI_ASM
@@ -47,8 +49,8 @@
 	std	%r0, 16(%r1)
 
 	mr	%r28, %r1	/* our AP.  */
-	stdux	%r1, %r1, %r4
 .LCFI0:
+	stdux	%r1, %r1, %r4
 	mr	%r31, %r5	/* flags, */
 	mr	%r30, %r6	/* rvalue, */
 	mr	%r29, %r7	/* function address.  */
@@ -100,6 +102,10 @@
 	/* Make the call.  */
 	bctrl
 
+	/* This must follow the call immediately, the unwinder
+	   uses this to find out if r2 has been saved or not.  */
+	ld	%r2, 40(%r1)
+
 	/* Now, deal with the return value.  */
 	mtcrf	0x01, %r31
 	bt-	30, .Ldone_return_value
@@ -109,7 +115,6 @@
 
 .Ldone_return_value:
 	/* Restore the registers we used and return.  */
-	ld	%r2, 40(%r1)
 	mr	%r1, %r28
 	ld	%r0, 16(%r28)
 	ld	%r28, -32(%r1)
@@ -120,12 +125,10 @@
 	blr
 
 .Lfp_return_value:
-	bt	27, .Lfd_return_value
 	bf	28, .Lfloat_return_value
 	stfd	%f1, 0(%r30)
-	b	.Ldone_return_value
-.Lfd_return_value:
-	stfd	%f1, 0(%r30)
+	mtcrf	0x02, %r31 /* cr6  */
+	bf	27, .Ldone_return_value
 	stfd	%f2, 8(%r30)
 	b	.Ldone_return_value
 .Lfloat_return_value:
@@ -178,3 +181,7 @@
 	.align 3
 .LEFDE1:
 #endif
+
+#if defined __ELF__ && defined __linux__
+	.section	.note.GNU-stack,"", at progbits
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/linux64_closure.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/linux64_closure.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/linux64_closure.S	Thu Mar 27 00:48:05 2008
@@ -1,3 +1,29 @@
+/* -----------------------------------------------------------------------
+   sysv.h - Copyright (c) 2003 Jakub Jelinek <jakub at redhat.com>
+	    Copyright (c) 2008 Red Hat, Inc.
+
+   PowerPC64 Assembly glue.
+
+   Permission is hereby granted, free of charge, to any person obtaining
+   a copy of this software and associated documentation files (the
+   ``Software''), to deal in the Software without restriction, including
+   without limitation the rights to use, copy, modify, merge, publish,
+   distribute, sublicense, and/or sell copies of the Software, and to
+   permit persons to whom the Software is furnished to do so, subject to
+   the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+   ----------------------------------------------------------------------- */
 #define LIBFFI_ASM
 #include <fficonfig.h>
 #include <ffi.h>
@@ -204,3 +230,7 @@
 	.align 3
 .LEFDE1:
 #endif
+
+#if defined __ELF__ && defined __linux__
+	.section	.note.GNU-stack,"", at progbits
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ppc_closure.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ppc_closure.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/ppc_closure.S	Thu Mar 27 00:48:05 2008
@@ -1,3 +1,29 @@
+/* -----------------------------------------------------------------------
+   sysv.h - Copyright (c) 2003 Jakub Jelinek <jakub at redhat.com>
+	    Copyright (c) 2008 Red Hat, Inc.
+
+   PowerPC Assembly glue.
+
+   Permission is hereby granted, free of charge, to any person obtaining
+   a copy of this software and associated documentation files (the
+   ``Software''), to deal in the Software without restriction, including
+   without limitation the rights to use, copy, modify, merge, publish,
+   distribute, sublicense, and/or sell copies of the Software, and to
+   permit persons to whom the Software is furnished to do so, subject to
+   the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+   ----------------------------------------------------------------------- */
 #define LIBFFI_ASM
 #include <fficonfig.h>
 #include <ffi.h>
@@ -28,6 +54,7 @@
 	stw   %r9, 40(%r1)
 	stw   %r10,44(%r1)
 
+#ifndef __NO_FPRS__
 	# next save fpr 1 to fpr 8 (aligned to 8)
 	stfd  %f1, 48(%r1)
 	stfd  %f2, 56(%r1)
@@ -37,6 +64,7 @@
 	stfd  %f6, 88(%r1)
 	stfd  %f7, 96(%r1)
 	stfd  %f8, 104(%r1)
+#endif
 
 	# set up registers for the routine that actually does the work
 	# get the context pointer from the trampoline
@@ -58,218 +86,190 @@
 
 	# make the call
 	bl ffi_closure_helper_SYSV at local
-
+.Lret:
 	# now r3 contains the return type
 	# so use it to look up in a table
 	# so we know how to deal with each type
 
 	# look up the proper starting point in table
 	# by using return type as offset
-	addi %r6,%r1,112   # get pointer to results area
-	bl .Lget_ret_type0_addr # get pointer to .Lret_type0 into LR
-	mflr %r4           # move to r4
-	slwi %r3,%r3,4     # now multiply return type by 16
-	add %r3,%r3,%r4    # add contents of table to table address
+
+	mflr %r4		# move address of .Lret to r4
+	slwi %r3,%r3,4		# now multiply return type by 16
+	addi %r4, %r4, .Lret_type0 - .Lret
+	lwz %r0,148(%r1)
+	add %r3,%r3,%r4		# add contents of table to table address
 	mtctr %r3
-	bctr               # jump to it
+	bctr			# jump to it
 .LFE1:
 
 # Each of the ret_typeX code fragments has to be exactly 16 bytes long
 # (4 instructions). For cache effectiveness we align to a 16 byte boundary
 # first.
 	.align 4
-
-	nop
-	nop
-	nop
-.Lget_ret_type0_addr:
-	blrl
-
 # case FFI_TYPE_VOID
 .Lret_type0:
-	b .Lfinish
-	nop
-	nop
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 	nop
 
 # case FFI_TYPE_INT
-.Lret_type1:
-	lwz %r3,0(%r6)
-	b .Lfinish
-	nop
-	nop
+	lwz %r3,112+0(%r1)
+	mtlr %r0
+.Lfinish:
+	addi %r1,%r1,144
+	blr
 
 # case FFI_TYPE_FLOAT
-.Lret_type2:
-	lfs %f1,0(%r6)
-	b .Lfinish
-	nop
-	nop
+	lfs %f1,112+0(%r1)
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 
 # case FFI_TYPE_DOUBLE
-.Lret_type3:
-	lfd %f1,0(%r6)
-	b .Lfinish
-	nop
-	nop
+	lfd %f1,112+0(%r1)
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 
 # case FFI_TYPE_LONGDOUBLE
-.Lret_type4:
-	lfd %f1,0(%r6)
+	lfd %f1,112+0(%r1)
+	lfd %f2,112+8(%r1)
+	mtlr %r0
 	b .Lfinish
-	nop
-	nop
 
 # case FFI_TYPE_UINT8
-.Lret_type5:
-	lbz %r3,3(%r6)
-	b .Lfinish
-	nop
-	nop
+	lbz %r3,112+3(%r1)
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 
 # case FFI_TYPE_SINT8
-.Lret_type6:
-	lbz %r3,3(%r6)
+	lbz %r3,112+3(%r1)
 	extsb %r3,%r3
+	mtlr %r0
 	b .Lfinish
-	nop
 
 # case FFI_TYPE_UINT16
-.Lret_type7:
-	lhz %r3,2(%r6)
-	b .Lfinish
-	nop
-	nop
+	lhz %r3,112+2(%r1)
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 
 # case FFI_TYPE_SINT16
-.Lret_type8:
-	lha %r3,2(%r6)
-	b .Lfinish
-	nop
-	nop
+	lha %r3,112+2(%r1)
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 
 # case FFI_TYPE_UINT32
-.Lret_type9:
-	lwz %r3,0(%r6)
-	b .Lfinish
-	nop
-	nop
+	lwz %r3,112+0(%r1)
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 
 # case FFI_TYPE_SINT32
-.Lret_type10:
-	lwz %r3,0(%r6)
-	b .Lfinish
-	nop
-	nop
+	lwz %r3,112+0(%r1)
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 
 # case FFI_TYPE_UINT64
-.Lret_type11:
-	lwz %r3,0(%r6)
-	lwz %r4,4(%r6)
+	lwz %r3,112+0(%r1)
+	lwz %r4,112+4(%r1)
+	mtlr %r0
 	b .Lfinish
-	nop
 
 # case FFI_TYPE_SINT64
-.Lret_type12:
-	lwz %r3,0(%r6)
-	lwz %r4,4(%r6)
+	lwz %r3,112+0(%r1)
+	lwz %r4,112+4(%r1)
+	mtlr %r0
 	b .Lfinish
-	nop
 
 # case FFI_TYPE_STRUCT
-.Lret_type13:
-	b .Lfinish
-	nop
-	nop
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 	nop
 
 # case FFI_TYPE_POINTER
-.Lret_type14:
-	lwz %r3,0(%r6)
-	b .Lfinish
-	nop
-	nop
+	lwz %r3,112+0(%r1)
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
+
+# case FFI_TYPE_UINT128
+	lwz %r3,112+0(%r1)
+	lwz %r4,112+4(%r1)
+	lwz %r5,112+8(%r1)
+	bl .Luint128
 
 # The return types below are only used when the ABI type is FFI_SYSV.
 # case FFI_SYSV_TYPE_SMALL_STRUCT + 1. One byte struct.
-.Lret_type15:
-# fall through.
-	lbz %r3,0(%r6)
-	b .Lfinish
-	nop
-	nop
+	lbz %r3,112+0(%r1)
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 
 # case FFI_SYSV_TYPE_SMALL_STRUCT + 2. Two byte struct.
-.Lret_type16:
-# fall through.
-	lhz %r3,0(%r6)
-	b .Lfinish
-	nop
-	nop
+	lhz %r3,112+0(%r1)
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 
 # case FFI_SYSV_TYPE_SMALL_STRUCT + 3. Three byte struct.
-.Lret_type17:
-# fall through.
-	lwz %r3,0(%r6)
+	lwz %r3,112+0(%r1)
 	srwi %r3,%r3,8
+	mtlr %r0
 	b .Lfinish
-	nop
 
 # case FFI_SYSV_TYPE_SMALL_STRUCT + 4. Four byte struct.
-.Lret_type18:
-# this one handles the structs from above too.
-	lwz %r3,0(%r6)
-	b .Lfinish
-	nop
-	nop
+	lwz %r3,112+0(%r1)
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 
 # case FFI_SYSV_TYPE_SMALL_STRUCT + 5. Five byte struct.
-.Lret_type19:
-# fall through.
-	lwz %r3,0(%r6)
-	lwz %r4,4(%r6)
+	lwz %r3,112+0(%r1)
+	lwz %r4,112+4(%r1)
 	li %r5,24
 	b .Lstruct567
 
 # case FFI_SYSV_TYPE_SMALL_STRUCT + 6. Six byte struct.
-.Lret_type20:
-# fall through.
-	lwz %r3,0(%r6)
-	lwz %r4,4(%r6)
+	lwz %r3,112+0(%r1)
+	lwz %r4,112+4(%r1)
 	li %r5,16
 	b .Lstruct567
 
 # case FFI_SYSV_TYPE_SMALL_STRUCT + 7. Seven byte struct.
-.Lret_type21:
-# fall through.
-	lwz %r3,0(%r6)
-	lwz %r4,4(%r6)
+	lwz %r3,112+0(%r1)
+	lwz %r4,112+4(%r1)
 	li %r5,8
 	b .Lstruct567
 
 # case FFI_SYSV_TYPE_SMALL_STRUCT + 8. Eight byte struct.
-.Lret_type22:
-# this one handles the above unhandled structs.
-	lwz %r3,0(%r6)
-	lwz %r4,4(%r6)
+	lwz %r3,112+0(%r1)
+	lwz %r4,112+4(%r1)
+	mtlr %r0
 	b .Lfinish
-	nop
 
-# case done
-.Lfinish:
+.Lstruct567:
+	subfic %r6,%r5,32
+	srw %r4,%r4,%r5
+	slw %r6,%r3,%r6
+	srw %r3,%r3,%r5
+	or %r4,%r6,%r4
+	mtlr %r0
+	addi %r1,%r1,144
+	blr
 
-	lwz %r0,148(%r1)
+.Luint128:
+	lwz %r6,112+12(%r1)
 	mtlr %r0
 	addi %r1,%r1,144
 	blr
 
-.Lstruct567:
-	subfic %r0,%r5,32
-	srw %r4,%r4,%r5
-	slw %r0,%r3,%r0
-	srw %r3,%r3,%r5
-	or %r4,%r0,%r4
-	b .Lfinish
 END(ffi_closure_SYSV)
 
 	.section	".eh_frame",EH_FRAME_FLAGS, at progbits
@@ -321,3 +321,7 @@
 .LEFDE1:
 
 #endif
+
+#if defined __ELF__ && defined __linux__
+	.section	.note.GNU-stack,"", at progbits
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/sysv.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/sysv.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/powerpc/sysv.S	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------------
-   sysv.h - Copyright (c) 1998 Geoffrey Keating
+   sysv.S - Copyright (c) 1998 Geoffrey Keating
+   Copyright (C) 2007 Free Software Foundation, Inc
 
    PowerPC Assembly glue.
 
@@ -14,13 +15,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #define LIBFFI_ASM
@@ -98,13 +100,17 @@
 	bctrl
 
 	/* Now, deal with the return value.  */
-	mtcrf	0x01,%r31
+	mtcrf	0x01,%r31 /* cr7  */
 	bt-	31,L(small_struct_return_value)
 	bt-	30,L(done_return_value)
 	bt-	29,L(fp_return_value)
 	stw	%r3,0(%r30)
 	bf+	28,L(done_return_value)
 	stw	%r4,4(%r30)
+	mtcrf	0x02,%r31 /* cr6  */
+	bf	27,L(done_return_value)
+	stw     %r5,8(%r30)
+	stw	%r6,12(%r30)
 	/* Fall through...  */
 
 L(done_return_value):
@@ -121,6 +127,9 @@
 L(fp_return_value):
 	bf	28,L(float_return_value)
 	stfd	%f1,0(%r30)
+	mtcrf   0x02,%r31 /* cr6  */
+	bf	27,L(done_return_value)
+	stfd	%f2,8(%r30)
 	b	L(done_return_value)
 L(float_return_value):
 	stfs	%f1,0(%r30)
@@ -215,3 +224,7 @@
       .align 2
 .LEFDE1:
 #endif
+
+#if defined __ELF__ && defined __linux__
+	.section	.note.GNU-stack,"", at progbits
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/prep_cif.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/prep_cif.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/prep_cif.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   prep_cif.c - Copyright (c) 1996, 1998  Red Hat, Inc.
+   prep_cif.c - Copyright (c) 1996, 1998, 2007  Red Hat, Inc.
 
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
@@ -12,20 +12,20 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #include <ffi.h>
 #include <ffi_common.h>
 #include <stdlib.h>
 
-
 /* Round up to FFI_SIZEOF_ARG. */
 
 #define STACK_ARG_SIZE(x) ALIGN(x, FFI_SIZEOF_ARG)
@@ -33,14 +33,12 @@
 /* Perform machine independent initialization of aggregate type
    specifications. */
 
-static ffi_status initialize_aggregate(/*@out@*/ ffi_type *arg)
+static ffi_status initialize_aggregate(ffi_type *arg)
 {
-  ffi_type **ptr; 
+  ffi_type **ptr;
 
   FFI_ASSERT(arg != NULL);
 
-  /*@-usedef@*/
-
   FFI_ASSERT(arg->elements != NULL);
   FFI_ASSERT(arg->size == 0);
   FFI_ASSERT(arg->alignment == 0);
@@ -51,33 +49,15 @@
     {
       if (((*ptr)->size == 0) && (initialize_aggregate((*ptr)) != FFI_OK))
 	return FFI_BAD_TYPEDEF;
-      
+
       /* Perform a sanity check on the argument type */
       FFI_ASSERT_VALID_TYPE(*ptr);
 
-#ifdef POWERPC_DARWIN
-      {
-	      int curalign;
-
-	      curalign = (*ptr)->alignment;
-	      if (ptr != &(arg->elements[0])) {
-		      if (curalign > 4 && curalign != 16) {
-			      curalign = 4;
-		      }
-	      }
-      arg->size = ALIGN(arg->size, curalign);
-      arg->size += (*ptr)->size;
-
-      arg->alignment = (arg->alignment > curalign) ? 
-	      arg->alignment : curalign;
-      }
-#else
       arg->size = ALIGN(arg->size, (*ptr)->alignment);
       arg->size += (*ptr)->size;
 
-      arg->alignment = (arg->alignment > (*ptr)->alignment) ? 
+      arg->alignment = (arg->alignment > (*ptr)->alignment) ?
 	arg->alignment : (*ptr)->alignment;
-#endif
 
       ptr++;
     }
@@ -95,8 +75,6 @@
     return FFI_BAD_TYPEDEF;
   else
     return FFI_OK;
-
-  /*@=usedef@*/
 }
 
 #ifndef __CRIS__
@@ -107,23 +85,8 @@
 /* Perform machine independent ffi_cif preparation, then call
    machine dependent routine. */
 
-#ifdef X86_DARWIN
-static inline int struct_on_stack(int size)
-{
-	if (size > 8) return 1;
-	/* This is not what the ABI says, but is what is really implemented */
-	switch (size) {
-	case 1: case 2: case 4: case 8: return 0;
-	}
-	return 1;
-}
-#endif
-
-
-ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif, 
-			ffi_abi abi, unsigned int nargs, 
-			/*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type *rtype, 
-			/*@dependent@*/ ffi_type **atypes)
+ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs,
+			ffi_type *rtype, ffi_type **atypes)
 {
   unsigned bytes = 0;
   unsigned int i;
@@ -140,10 +103,8 @@
   cif->flags = 0;
 
   /* Initialize the return type if necessary */
-  /*@-usedef@*/
   if ((cif->rtype->size == 0) && (initialize_aggregate(cif->rtype) != FFI_OK))
     return FFI_BAD_TYPEDEF;
-  /*@=usedef@*/
 
   /* Perform a sanity check on the return type */
   FFI_ASSERT_VALID_TYPE(cif->rtype);
@@ -156,10 +117,9 @@
       && (cif->abi != FFI_V9 || cif->rtype->size > 32)
 #endif
 #ifdef X86_DARWIN
-
-      && (struct_on_stack(cif->rtype->size))
+      && (cif->rtype->size > 8)
 #endif
-      )
+     )
     bytes = STACK_ARG_SIZE(sizeof(void*));
 #endif
 
@@ -170,20 +130,11 @@
       if (((*ptr)->size == 0) && (initialize_aggregate((*ptr)) != FFI_OK))
 	return FFI_BAD_TYPEDEF;
 
-      /* Perform a sanity check on the argument type, do this 
+      /* Perform a sanity check on the argument type, do this
 	 check after the initialization.  */
       FFI_ASSERT_VALID_TYPE(*ptr);
 
-#if defined(X86_DARWIN)
-      {
-	      int align = (*ptr)->alignment;
-	      if (align > 4) align = 4;
-	      if ((align - 1) & bytes)
-		 bytes = ALIGN(bytes, align);
-	      bytes += STACK_ARG_SIZE((*ptr)->size);
-      }
-
-#elif !defined __x86_64__ && !defined S390 && !defined PA
+#if !defined __x86_64__ && !defined S390 && !defined PA
 #ifdef SPARC
       if (((*ptr)->type == FFI_TYPE_STRUCT
 	   && ((*ptr)->size > 16 || cif->abi != FFI_V9))
@@ -196,7 +147,7 @@
 	  /* Add any padding if necessary */
 	  if (((*ptr)->alignment - 1) & bytes)
 	    bytes = ALIGN(bytes, (*ptr)->alignment);
-	  
+
 	  bytes += STACK_ARG_SIZE((*ptr)->size);
 	}
 #endif
@@ -208,3 +159,16 @@
   return ffi_prep_cif_machdep(cif);
 }
 #endif /* not __CRIS__ */
+
+#if FFI_CLOSURES
+
+ffi_status
+ffi_prep_closure (ffi_closure* closure,
+		  ffi_cif* cif,
+		  void (*fun)(ffi_cif*,void*,void**,void*),
+		  void *user_data)
+{
+  return ffi_prep_closure_loc (closure, cif, fun, user_data, closure);
+}
+
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/s390/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/s390/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/s390/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 2000 Software AG
+   ffi.c - Copyright (c) 2000, 2007 Software AG
+           Copyright (c) 2008 Red Hat, Inc
  
    S390 Foreign Function Interface
  
@@ -88,7 +89,7 @@
 			  void (*)(unsigned char *, extended_cif *),
 			  unsigned,
 			  void *,
-			  void (*fn)());
+			  void (*fn)(void));
 
 extern void ffi_closure_SYSV(void);
  
@@ -207,6 +208,12 @@
       void *arg = *p_argv;
       int type = (*ptr)->type;
 
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+      /* 16-byte long double is passed like a struct.  */
+      if (type == FFI_TYPE_LONGDOUBLE)
+	type = FFI_TYPE_STRUCT;
+#endif
+
       /* Check how a structure type is passed.  */
       if (type == FFI_TYPE_STRUCT)
 	{
@@ -364,6 +371,12 @@
 	cif->flags = FFI390_RET_DOUBLE;
 	break;
 
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+      case FFI_TYPE_LONGDOUBLE:
+	cif->flags = FFI390_RET_STRUCT;
+	n_gpr++;
+	break;
+#endif
       /* Integer values are returned in gpr 2 (and gpr 3
 	 for 64-bit values on 31-bit machines).  */
       case FFI_TYPE_UINT64:
@@ -400,6 +413,12 @@
     {
       int type = (*ptr)->type;
 
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+      /* 16-byte long double is passed like a struct.  */
+      if (type == FFI_TYPE_LONGDOUBLE)
+	type = FFI_TYPE_STRUCT;
+#endif
+
       /* Check how a structure type is passed.  */
       if (type == FFI_TYPE_STRUCT)
 	{
@@ -480,7 +499,7 @@
  
 void
 ffi_call(ffi_cif *cif,
-	 void (*fn)(),
+	 void (*fn)(void),
 	 void *rvalue,
 	 void **avalue)
 {
@@ -562,6 +581,12 @@
       int deref_struct_pointer = 0;
       int type = (*ptr)->type;
 
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+      /* 16-byte long double is passed like a struct.  */
+      if (type == FFI_TYPE_LONGDOUBLE)
+	type = FFI_TYPE_STRUCT;
+#endif
+
       /* Check how a structure type is passed.  */
       if (type == FFI_TYPE_STRUCT)
 	{
@@ -662,6 +687,9 @@
       /* Void is easy, and so is struct.  */
       case FFI_TYPE_VOID:
       case FFI_TYPE_STRUCT:
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+      case FFI_TYPE_LONGDOUBLE:
+#endif
 	break;
 
       /* Floating point values are returned in fpr 0.  */
@@ -709,17 +737,18 @@
 
 /*====================================================================*/
 /*                                                                    */
-/* Name     - ffi_prep_closure.                                       */
+/* Name     - ffi_prep_closure_loc.                                   */
 /*                                                                    */
 /* Function - Prepare a FFI closure.                                  */
 /*                                                                    */
 /*====================================================================*/
  
 ffi_status
-ffi_prep_closure (ffi_closure *closure,
-                  ffi_cif *cif,
-                  void (*fun) (ffi_cif *, void *, void **, void *),
-                  void *user_data)
+ffi_prep_closure_loc (ffi_closure *closure,
+		      ffi_cif *cif,
+		      void (*fun) (ffi_cif *, void *, void **, void *),
+		      void *user_data,
+		      void *codeloc)
 {
   FFI_ASSERT (cif->abi == FFI_SYSV);
 
@@ -728,7 +757,7 @@
   *(short *)&closure->tramp [2] = 0x9801;   /* lm %r0,%r1,6(%r1) */
   *(short *)&closure->tramp [4] = 0x1006;
   *(short *)&closure->tramp [6] = 0x07f1;   /* br %r1 */
-  *(long  *)&closure->tramp [8] = (long)closure;
+  *(long  *)&closure->tramp [8] = (long)codeloc;
   *(long  *)&closure->tramp[12] = (long)&ffi_closure_SYSV;
 #else
   *(short *)&closure->tramp [0] = 0x0d10;   /* basr %r1,0 */
@@ -736,7 +765,7 @@
   *(short *)&closure->tramp [4] = 0x100e;
   *(short *)&closure->tramp [6] = 0x0004;
   *(short *)&closure->tramp [8] = 0x07f1;   /* br %r1 */
-  *(long  *)&closure->tramp[16] = (long)closure;
+  *(long  *)&closure->tramp[16] = (long)codeloc;
   *(long  *)&closure->tramp[24] = (long)&ffi_closure_SYSV;
 #endif 
  

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/s390/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/s390/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/s390/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -13,13 +13,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/s390/sysv.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/s390/sysv.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/s390/sysv.S	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,7 @@
 /* -----------------------------------------------------------------------
    sysv.S - Copyright (c) 2000 Software AG
- 
+            Copyright (c) 2008 Red Hat, Inc.
+	
    S390 Foreign Function Interface
  
    Permission is hereby granted, free of charge, to any person obtaining
@@ -14,13 +15,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
  
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #define LIBFFI_ASM
@@ -427,3 +429,6 @@
 
 #endif
 
+#if defined __ELF__ && defined __linux__
+	.section	.note.GNU-stack,"", at progbits
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 2002, 2003, 2004, 2005 Kaz Kojima
+   ffi.c - Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007 Kaz Kojima
+           Copyright (c) 2008 Red Hat, Inc.
    
    SuperH Foreign Function Interface 
 
@@ -14,13 +15,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #include <ffi.h>
@@ -106,9 +108,7 @@
 /* ffi_prep_args is called by the assembly routine once stack space
    has been allocated for the function's arguments */
 
-/*@-exportheader@*/
 void ffi_prep_args(char *stack, extended_cif *ecif)
-/*@=exportheader@*/
 {
   register unsigned int i;
   register int tmp;
@@ -406,20 +406,10 @@
   return FFI_OK;
 }
 
-/*@-declundef@*/
-/*@-exportheader@*/
-extern void ffi_call_SYSV(void (*)(char *, extended_cif *), 
-			  /*@out@*/ extended_cif *, 
-			  unsigned, unsigned, 
-			  /*@out@*/ unsigned *, 
-			  void (*fn)());
-/*@=declundef@*/
-/*@=exportheader@*/
-
-void ffi_call(/*@dependent@*/ ffi_cif *cif, 
-	      void (*fn)(), 
-	      /*@out@*/ void *rvalue, 
-	      /*@dependent@*/ void **avalue)
+extern void ffi_call_SYSV(void (*)(char *, extended_cif *), extended_cif *,
+			  unsigned, unsigned, unsigned *, void (*fn)(void));
+
+void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   extended_cif ecif;
   UINT64 trvalue;
@@ -436,9 +426,7 @@
   else if ((rvalue == NULL) && 
       (cif->rtype->type == FFI_TYPE_STRUCT))
     {
-      /*@-sysunrecog@*/
       ecif.rvalue = alloca(cif->rtype->size);
-      /*@=sysunrecog@*/
     }
   else
     ecif.rvalue = rvalue;
@@ -446,10 +434,8 @@
   switch (cif->abi) 
     {
     case FFI_SYSV:
-      /*@-usedef@*/
-      ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, 
-		    cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
+      ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, cif->flags, ecif.rvalue,
+		    fn);
       break;
     default:
       FFI_ASSERT(0);
@@ -468,10 +454,11 @@
 #endif
 
 ffi_status
-ffi_prep_closure (ffi_closure* closure,
-		  ffi_cif* cif,
-		  void (*fun)(ffi_cif*, void*, void**, void*),
-		  void *user_data)
+ffi_prep_closure_loc (ffi_closure* closure,
+		      ffi_cif* cif,
+		      void (*fun)(ffi_cif*, void*, void**, void*),
+		      void *user_data,
+		      void *codeloc)
 {
   unsigned int *tramp;
   unsigned short insn;
@@ -491,7 +478,7 @@
   tramp[0] = 0xd102d301;
   tramp[1] = 0x412b0000 | insn;
 #endif
-  *(void **) &tramp[2] = (void *)closure;          /* ctx */
+  *(void **) &tramp[2] = (void *)codeloc;          /* ctx */
   *(void **) &tramp[3] = (void *)ffi_closure_SYSV; /* funaddr */
 
   closure->cif = cif;
@@ -500,7 +487,7 @@
 
 #if defined(__SH4__)
   /* Flush the icache.  */
-  __ic_invalidate(&closure->tramp[0]);
+  __ic_invalidate(codeloc);
 #endif
 
   return FFI_OK;
@@ -535,7 +522,6 @@
   int freg = 0;
 #endif
   ffi_cif *cif; 
-  double temp; 
 
   cif = closure->cif;
   avalue = alloca(cif->nargs * sizeof(void *));
@@ -544,7 +530,7 @@
      returns the data directly to the caller.  */
   if (cif->rtype->type == FFI_TYPE_STRUCT && STRUCT_VALUE_ADDRESS_WITH_ARG)
     {
-      rvalue = *pgr++;
+      rvalue = (void *) *pgr++;
       ireg = 1;
     }
   else
@@ -611,6 +597,8 @@
 	{
 	  if (freg + 1 >= NFREGARG)
 	    continue;
+	  if (freg & 1)
+	    pfr++;
 	  freg = (freg + 1) & ~1;
 	  freg += 2;
 	  avalue[i] = pfr;

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -13,13 +13,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh/sysv.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh/sysv.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh/sysv.S	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   sysv.S - Copyright (c) 2002, 2003, 2004 Kaz Kojima
+   sysv.S - Copyright (c) 2002, 2003, 2004, 2006 Kaz Kojima
    
    SuperH Foreign Function Interface 
 
@@ -17,7 +17,8 @@
    THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+	ANY CLAIM, DAMAGES OR
    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    OTHER DEALINGS IN THE SOFTWARE.
@@ -829,13 +830,13 @@
 	.byte	0x6	/* uleb128 0x6 */
 	.byte	0x8e	/* DW_CFA_offset, column 0xe */
 	.byte	0x5	/* uleb128 0x5 */
-	.byte	0x8b	/* DW_CFA_offset, column 0xb */
+	.byte	0x84	/* DW_CFA_offset, column 0x4 */
 	.byte	0x4	/* uleb128 0x4 */
-	.byte	0x8a	/* DW_CFA_offset, column 0xa */
+	.byte	0x85	/* DW_CFA_offset, column 0x5 */
 	.byte	0x3	/* uleb128 0x3 */
-	.byte	0x89	/* DW_CFA_offset, column 0x9 */
+	.byte	0x86	/* DW_CFA_offset, column 0x6 */
 	.byte	0x2	/* uleb128 0x2 */
-	.byte	0x88	/* DW_CFA_offset, column 0x8 */
+	.byte	0x87	/* DW_CFA_offset, column 0x7 */
 	.byte	0x1	/* uleb128 0x1 */
 	.byte	0x4	/* DW_CFA_advance_loc4 */
 	.4byte	.LCFIE-.LCFID

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh64/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh64/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh64/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------------
    ffi.c - Copyright (c) 2003, 2004 Kaz Kojima
+           Copyright (c) 2008 Anthony Green
    
    SuperH SHmedia Foreign Function Interface 
 
@@ -14,13 +15,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #include <ffi.h>
@@ -238,12 +240,12 @@
 			  /*@out@*/ extended_cif *, 
 			  unsigned, unsigned, long long,
 			  /*@out@*/ unsigned *, 
-			  void (*fn)());
+			  void (*fn)(void));
 /*@=declundef@*/
 /*@=exportheader@*/
 
 void ffi_call(/*@dependent@*/ ffi_cif *cif, 
-	      void (*fn)(), 
+	      void (*fn)(void), 
 	      /*@out@*/ void *rvalue, 
 	      /*@dependent@*/ void **avalue)
 {

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh64/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh64/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh64/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -13,13 +13,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh64/sysv.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh64/sysv.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sh64/sysv.S	Thu Mar 27 00:48:05 2008
@@ -17,7 +17,8 @@
    THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+	ANY CLAIM, DAMAGES OR
    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    OTHER DEALINGS IN THE SOFTWARE.

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1996, 2003, 2004 Red Hat, Inc.
+   ffi.c - Copyright (c) 1996, 2003, 2004, 2007, 2008 Red Hat, Inc.
    
    SPARC Foreign Function Interface 
 
@@ -14,13 +14,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #include <ffi.h>
@@ -358,13 +359,13 @@
 
 #ifdef SPARC64
 extern int ffi_call_v9(void *, extended_cif *, unsigned, 
-		       unsigned, unsigned *, void (*fn)());
+		       unsigned, unsigned *, void (*fn)(void));
 #else
 extern int ffi_call_v8(void *, extended_cif *, unsigned, 
-		       unsigned, unsigned *, void (*fn)());
+		       unsigned, unsigned *, void (*fn)(void));
 #endif
 
-void ffi_call(ffi_cif *cif, void (*fn)(), void *rvalue, void **avalue)
+void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   extended_cif ecif;
   void *rval = rvalue;
@@ -425,10 +426,11 @@
 #endif
 
 ffi_status
-ffi_prep_closure (ffi_closure* closure,
-		  ffi_cif* cif,
-		  void (*fun)(ffi_cif*, void*, void**, void*),
-		  void *user_data)
+ffi_prep_closure_loc (ffi_closure* closure,
+		      ffi_cif* cif,
+		      void (*fun)(ffi_cif*, void*, void**, void*),
+		      void *user_data,
+		      void *codeloc)
 {
   unsigned int *tramp = (unsigned int *) &closure->tramp[0];
   unsigned long fn;
@@ -443,7 +445,7 @@
   tramp[3] = 0x01000000;	/* nop			*/
   *((unsigned long *) &tramp[4]) = fn;
 #else
-  unsigned long ctx = (unsigned long) closure;
+  unsigned long ctx = (unsigned long) codeloc;
   FFI_ASSERT (cif->abi == FFI_V8);
   fn = (unsigned long) ffi_closure_v8;
   tramp[0] = 0x03000000 | fn >> 10;	/* sethi %hi(fn), %g1	*/

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -13,13 +13,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/v8.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/v8.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/v8.S	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   v8.S - Copyright (c) 1996, 1997, 2003, 2004 Red Hat, Inc.
+   v8.S - Copyright (c) 1996, 1997, 2003, 2004, 2008 Red Hat, Inc.
    
    SPARC Foreign Function Interface 
 
@@ -14,13 +14,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #define LIBFFI_ASM	
@@ -265,3 +266,7 @@
 	.byte	0x1f	! uleb128 0x1f
 	.align	WS
 .LLEFDE2:
+
+#if defined __ELF__ && defined __linux__
+	.section	.note.GNU-stack,"", at progbits
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/v9.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/v9.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/sparc/v9.S	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   v9.S - Copyright (c) 2000, 2003, 2004 Red Hat, Inc.
+   v9.S - Copyright (c) 2000, 2003, 2004, 2008 Red Hat, Inc.
    
    SPARC 64-bit Foreign Function Interface 
 
@@ -14,13 +14,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #define LIBFFI_ASM	
@@ -300,3 +301,7 @@
 	.align 8
 .LLEFDE2:
 #endif
+
+#ifdef __linux__
+	.section	.note.GNU-stack,"", at progbits
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/darwin.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/darwin.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/darwin.S	Thu Mar 27 00:48:05 2008
@@ -1,8 +1,8 @@
-#ifdef __i386__
 /* -----------------------------------------------------------------------
-   darwin.S - Copyright (c) 1996, 1998, 2001, 2002, 2003  Red Hat, Inc.
-   
-   X86 Foreign Function Interface 
+   darwin.S - Copyright (c) 1996, 1998, 2001, 2002, 2003, 2005  Red Hat, Inc.
+	Copyright (C) 2008  Free Software Foundation, Inc.
+
+   X86 Foreign Function Interface
 
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
@@ -18,16 +18,12 @@
    THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+	ANY CLAIM, DAMAGES OR
    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    OTHER DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
-  
-/*
- * This file is based on sysv.S and then hacked up by Ronald who hasn't done
- * assembly programming in 8 years.
- */
 
 #ifndef __x86_64__
 
@@ -35,18 +31,11 @@
 #include <fficonfig.h>
 #include <ffi.h>
 
-#ifdef PyObjC_STRICT_DEBUGGING
-  /* XXX: Debugging of stack alignment, to be removed */
-#define ASSERT_STACK_ALIGNED movdqa -16(%esp), %xmm0
-#else
-#define ASSERT_STACK_ALIGNED 
-#endif
-
 .text
 
 .globl _ffi_prep_args
 
-.align 4
+	.align 4
 .globl _ffi_call_SYSV
 
 _ffi_call_SYSV:
@@ -54,15 +43,12 @@
         pushl %ebp
 .LCFI0:
         movl  %esp,%ebp
-	subl  $8,%esp
-	ASSERT_STACK_ALIGNED
 .LCFI1:
+        subl $8,%esp
 	/* Make room for all of the new args.  */
 	movl  16(%ebp),%ecx
 	subl  %ecx,%esp
 
-	ASSERT_STACK_ALIGNED
-
 	movl  %esp,%eax
 
 	/* Place all of the ffi_prep_args in position  */
@@ -71,27 +57,20 @@
 	pushl %eax
 	call  *8(%ebp)
 
-	ASSERT_STACK_ALIGNED
-
 	/* Return stack to previous state and call the function  */
-	addl  $16,%esp
-
-	ASSERT_STACK_ALIGNED
+	addl  $16,%esp	
 
 	call  *28(%ebp)
-	
-	/* XXX: return returns return with 'ret $4', that upsets the stack! */
-	movl  16(%ebp),%ecx
-	addl  %ecx,%esp
-
 
 	/* Load %ecx with the return type code  */
 	movl  20(%ebp),%ecx	
 
+	/* Protect %esi.  We're going to pop it in the epilogue.  */
+	pushl %esi
 
 	/* If the return value pointer is NULL, assume no return value.  */
 	cmpl  $0,24(%ebp)
-	jne   retint
+	jne  0f
 
 	/* Even if there is no space for the return value, we are 
 	   obliged to handle floating-point values.  */
@@ -99,145 +78,366 @@
 	jne   noretval
 	fstp  %st(0)
 
-        jmp   epilogue
-
-retint:
-	cmpl  $FFI_TYPE_INT,%ecx
-	jne   retfloat
-	/* Load %ecx with the pointer to storage for the return value  */
-	movl  24(%ebp),%ecx	
-	movl  %eax,0(%ecx)
 	jmp   epilogue
+0:
+	.align 4
+	call 1f
+.Lstore_table:
+	.long   noretval-.Lstore_table		/* FFI_TYPE_VOID */
+	.long   retint-.Lstore_table		/* FFI_TYPE_INT */
+	.long   retfloat-.Lstore_table		/* FFI_TYPE_FLOAT */
+	.long   retdouble-.Lstore_table		/* FFI_TYPE_DOUBLE */
+	.long   retlongdouble-.Lstore_table     /* FFI_TYPE_LONGDOUBLE */
+	.long   retuint8-.Lstore_table		/* FFI_TYPE_UINT8 */
+	.long   retsint8-.Lstore_table		/* FFI_TYPE_SINT8 */
+	.long   retuint16-.Lstore_table		/* FFI_TYPE_UINT16 */
+	.long   retsint16-.Lstore_table		/* FFI_TYPE_SINT16 */
+	.long   retint-.Lstore_table		/* FFI_TYPE_UINT32 */
+	.long   retint-.Lstore_table		/* FFI_TYPE_SINT32 */
+	.long   retint64-.Lstore_table		/* FFI_TYPE_UINT64 */
+	.long   retint64-.Lstore_table		/* FFI_TYPE_SINT64 */
+	.long   retstruct-.Lstore_table		/* FFI_TYPE_STRUCT */
+	.long   retint-.Lstore_table		/* FFI_TYPE_POINTER */
+	.long   retstruct1b-.Lstore_table	/* FFI_TYPE_SMALL_STRUCT_1B */
+	.long   retstruct2b-.Lstore_table	/* FFI_TYPE_SMALL_STRUCT_2B */
+1:
+	pop  %esi
+	add  (%esi, %ecx, 4), %esi
+	jmp  *%esi
+
+	/* Sign/zero extend as appropriate.  */
+retsint8:
+	movsbl  %al, %eax
+	jmp  retint
+
+retsint16:
+	movswl  %ax, %eax
+	jmp  retint
+
+retuint8:
+	movzbl  %al, %eax
+	jmp  retint
+
+retuint16:
+	movzwl  %ax, %eax
+	jmp  retint
 
 retfloat:
-	cmpl  $FFI_TYPE_FLOAT,%ecx
-	jne   retdouble
 	/* Load %ecx with the pointer to storage for the return value  */
-	movl  24(%ebp),%ecx	
+	movl  24(%ebp),%ecx
 	fstps (%ecx)
 	jmp   epilogue
 
 retdouble:
-	cmpl  $FFI_TYPE_DOUBLE,%ecx
-	jne   retlongdouble
 	/* Load %ecx with the pointer to storage for the return value  */
-	movl  24(%ebp),%ecx	
+	movl  24(%ebp),%ecx
 	fstpl (%ecx)
 	jmp   epilogue
 
 retlongdouble:
-	cmpl  $FFI_TYPE_LONGDOUBLE,%ecx
-	jne   retint64
 	/* Load %ecx with the pointer to storage for the return value  */
-	movl  24(%ebp),%ecx	
+	movl  24(%ebp),%ecx
 	fstpt (%ecx)
 	jmp   epilogue
-	
-retint64:	
-	cmpl  $FFI_TYPE_SINT64,%ecx
-        jne   retstruct1b
+
+retint64:
 	/* Load %ecx with the pointer to storage for the return value  */
-	movl  24(%ebp),%ecx	
+	movl  24(%ebp),%ecx
 	movl  %eax,0(%ecx)
 	movl  %edx,4(%ecx)
 	jmp   epilogue
 
 retstruct1b:
-   cmpl $FFI_TYPE_SINT8,%ecx
-   jne  retstruct2b
-   movl 24(%ebp),%ecx
-   movb  %al,0(%ecx)
-   jmp  epilogue
+	/* Load %ecx with the pointer to storage for the return value  */
+	movl  24(%ebp),%ecx
+	movb  %al,0(%ecx)
+	jmp   epilogue
 
 retstruct2b:
-   cmpl $FFI_TYPE_SINT16,%ecx
-   jne  retstruct
-   movl 24(%ebp),%ecx
-   movw %ax,0(%ecx)
-   jmp  epilogue
-	
-retstruct:
-   cmpl $FFI_TYPE_STRUCT,%ecx
-   jne  noretval
-	/* Nothing to do!  */
-
-	subl $4,%esp
+	/* Load %ecx with the pointer to storage for the return value  */
+	movl  24(%ebp),%ecx
+	movw  %ax,0(%ecx)
+	jmp   epilogue
 
-	ASSERT_STACK_ALIGNED
+retint:
+	/* Load %ecx with the pointer to storage for the return value  */
+	movl  24(%ebp),%ecx
+	movl  %eax,0(%ecx)
 
-	addl $8,%esp
-	movl %ebp, %esp
-	popl %ebp
-	ret
+retstruct:
+	/* Nothing to do!  */
 
 noretval:
 epilogue:
-	ASSERT_STACK_ALIGNED
-	addl $8, %esp
-
+	popl %esi
+	movl %ebp,%esp
+	popl %ebp
+	ret
 
-        movl %ebp,%esp
-        popl %ebp
-        ret
 .LFE1:
 .ffi_call_SYSV_end:
-#if 0
-        .size    ffi_call_SYSV,.ffi_call_SYSV_end-ffi_call_SYSV
-#endif
 
-#if 0
-	.section	.eh_frame,EH_FRAME_FLAGS, at progbits
-.Lframe1:
-	.long	.LECIE1-.LSCIE1	/* Length of Common Information Entry */
-.LSCIE1:
-	.long	0x0	/* CIE Identifier Tag */
-	.byte	0x1	/* CIE Version */
-#ifdef __PIC__
-	.ascii "zR\0"	/* CIE Augmentation */
-#else
-	.ascii "\0"	/* CIE Augmentation */
-#endif
-	.byte	0x1	/* .uleb128 0x1; CIE Code Alignment Factor */
-	.byte	0x7c	/* .sleb128 -4; CIE Data Alignment Factor */
-	.byte	0x8	/* CIE RA Column */
-#ifdef __PIC__
-	.byte	0x1	/* .uleb128 0x1; Augmentation size */
-	.byte	0x1b	/* FDE Encoding (pcrel sdata4) */
-#endif
-	.byte	0xc	/* DW_CFA_def_cfa */
-	.byte	0x4	/* .uleb128 0x4 */
-	.byte	0x4	/* .uleb128 0x4 */
-	.byte	0x88	/* DW_CFA_offset, column 0x8 */
-	.byte	0x1	/* .uleb128 0x1 */
-	.align 4
-.LECIE1:
-.LSFDE1:
-	.long	.LEFDE1-.LASFDE1	/* FDE Length */
-.LASFDE1:
-	.long	.LASFDE1-.Lframe1	/* FDE CIE offset */
-#ifdef __PIC__
-	.long	.LFB1-.	/* FDE initial location */
-#else
-	.long	.LFB1	/* FDE initial location */
-#endif
-	.long	.LFE1-.LFB1	/* FDE address range */
-#ifdef __PIC__
-	.byte	0x0	/* .uleb128 0x0; Augmentation size */
+	.align	4
+FFI_HIDDEN (ffi_closure_SYSV)
+.globl _ffi_closure_SYSV
+
+_ffi_closure_SYSV:
+.LFB2:
+	pushl	%ebp
+.LCFI2:
+	movl	%esp, %ebp
+.LCFI3:
+	subl	$40, %esp
+	leal	-24(%ebp), %edx
+	movl	%edx, -12(%ebp)	/* resp */
+	leal	8(%ebp), %edx
+	movl	%edx, 4(%esp)	/* args = __builtin_dwarf_cfa () */
+	leal	-12(%ebp), %edx
+	movl	%edx, (%esp)	/* &resp */
+	movl	%ebx, 8(%esp)
+.LCFI7:
+	call	L_ffi_closure_SYSV_inner$stub
+	movl	8(%esp), %ebx
+	movl	-12(%ebp), %ecx
+	cmpl	$FFI_TYPE_INT, %eax
+	je	.Lcls_retint
+
+	/* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16,
+	   FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32.  */
+	cmpl	$FFI_TYPE_UINT64, %eax
+	jge	0f
+	cmpl	$FFI_TYPE_UINT8, %eax
+	jge	.Lcls_retint
+
+0:	cmpl	$FFI_TYPE_FLOAT, %eax
+	je	.Lcls_retfloat
+	cmpl	$FFI_TYPE_DOUBLE, %eax
+	je	.Lcls_retdouble
+	cmpl	$FFI_TYPE_LONGDOUBLE, %eax
+	je	.Lcls_retldouble
+	cmpl	$FFI_TYPE_SINT64, %eax
+	je	.Lcls_retllong
+	cmpl	$FFI_TYPE_SMALL_STRUCT_1B, %eax
+	je	.Lcls_retstruct1b
+	cmpl	$FFI_TYPE_SMALL_STRUCT_2B, %eax
+	je	.Lcls_retstruct2b
+	cmpl	$FFI_TYPE_STRUCT, %eax
+	je	.Lcls_retstruct
+.Lcls_epilogue:
+	movl	%ebp, %esp
+	popl	%ebp
+	ret
+.Lcls_retint:
+	movl	(%ecx), %eax
+	jmp	.Lcls_epilogue
+.Lcls_retfloat:
+	flds	(%ecx)
+	jmp	.Lcls_epilogue
+.Lcls_retdouble:
+	fldl	(%ecx)
+	jmp	.Lcls_epilogue
+.Lcls_retldouble:
+	fldt	(%ecx)
+	jmp	.Lcls_epilogue
+.Lcls_retllong:
+	movl	(%ecx), %eax
+	movl	4(%ecx), %edx
+	jmp	.Lcls_epilogue
+.Lcls_retstruct1b:
+	movsbl	(%ecx), %eax
+	jmp	.Lcls_epilogue
+.Lcls_retstruct2b:
+	movswl	(%ecx), %eax
+	jmp	.Lcls_epilogue
+.Lcls_retstruct:
+	lea -8(%ebp),%esp
+	movl	%ebp, %esp
+	popl	%ebp
+	ret $4
+.LFE2:
+
+#if !FFI_NO_RAW_API
+
+#define RAW_CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) & ~3)
+#define RAW_CLOSURE_FUN_OFFSET (RAW_CLOSURE_CIF_OFFSET + 4)
+#define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4)
+#define CIF_FLAGS_OFFSET 20
+
+	.align	4
+FFI_HIDDEN (ffi_closure_raw_SYSV)
+.globl _ffi_closure_raw_SYSV
+
+_ffi_closure_raw_SYSV:
+.LFB3:
+	pushl	%ebp
+.LCFI4:
+	movl	%esp, %ebp
+.LCFI5:
+	pushl	%esi
+.LCFI6:
+	subl	$36, %esp
+	movl	RAW_CLOSURE_CIF_OFFSET(%eax), %esi	 /* closure->cif */
+	movl	RAW_CLOSURE_USER_DATA_OFFSET(%eax), %edx /* closure->user_data */
+	movl	%edx, 12(%esp)	/* user_data */
+	leal	8(%ebp), %edx	/* __builtin_dwarf_cfa () */
+	movl	%edx, 8(%esp)	/* raw_args */
+	leal	-24(%ebp), %edx
+	movl	%edx, 4(%esp)	/* &res */
+	movl	%esi, (%esp)	/* cif */
+	call	*RAW_CLOSURE_FUN_OFFSET(%eax)		 /* closure->fun */
+	movl	CIF_FLAGS_OFFSET(%esi), %eax		 /* rtype */
+	cmpl	$FFI_TYPE_INT, %eax
+	je	.Lrcls_retint
+
+	/* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16,
+	   FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32.  */
+	cmpl	$FFI_TYPE_UINT64, %eax
+	jge	0f
+	cmpl	$FFI_TYPE_UINT8, %eax
+	jge	.Lrcls_retint
+0:
+	cmpl	$FFI_TYPE_FLOAT, %eax
+	je	.Lrcls_retfloat
+	cmpl	$FFI_TYPE_DOUBLE, %eax
+	je	.Lrcls_retdouble
+	cmpl	$FFI_TYPE_LONGDOUBLE, %eax
+	je	.Lrcls_retldouble
+	cmpl	$FFI_TYPE_SINT64, %eax
+	je	.Lrcls_retllong
+.Lrcls_epilogue:
+	addl	$36, %esp
+	popl	%esi
+	popl	%ebp
+	ret
+.Lrcls_retint:
+	movl	-24(%ebp), %eax
+	jmp	.Lrcls_epilogue
+.Lrcls_retfloat:
+	flds	-24(%ebp)
+	jmp	.Lrcls_epilogue
+.Lrcls_retdouble:
+	fldl	-24(%ebp)
+	jmp	.Lrcls_epilogue
+.Lrcls_retldouble:
+	fldt	-24(%ebp)
+	jmp	.Lrcls_epilogue
+.Lrcls_retllong:
+	movl	-24(%ebp), %eax
+	movl	-20(%ebp), %edx
+	jmp	.Lrcls_epilogue
+.LFE3:
 #endif
-	.byte	0x4	/* DW_CFA_advance_loc4 */
-	.long	.LCFI0-.LFB1
-	.byte	0xe	/* DW_CFA_def_cfa_offset */
-	.byte	0x8	/* .uleb128 0x8 */
-	.byte	0x85	/* DW_CFA_offset, column 0x5 */
-	.byte	0x2	/* .uleb128 0x2 */
-	.byte	0x4	/* DW_CFA_advance_loc4 */
-	.long	.LCFI1-.LCFI0
-	.byte	0xd	/* DW_CFA_def_cfa_register */
-	.byte	0x5	/* .uleb128 0x5 */
-	.align 4
-.LEFDE1:
+
+.section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5
+L_ffi_closure_SYSV_inner$stub:
+	.indirect_symbol _ffi_closure_SYSV_inner
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+
+.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
+EH_frame1:
+	.set	L$set$0,LECIE1-LSCIE1
+	.long	L$set$0
+LSCIE1:
+	.long	0x0
+	.byte	0x1
+	.ascii "zR\0"
+	.byte	0x1
+	.byte	0x7c
+	.byte	0x8
+	.byte	0x1
+	.byte	0x10
+	.byte	0xc
+	.byte	0x5
+	.byte	0x4
+	.byte	0x88
+	.byte	0x1
+	.align 2
+LECIE1:
+.globl _ffi_call_SYSV.eh
+_ffi_call_SYSV.eh:
+LSFDE1:
+	.set	L$set$1,LEFDE1-LASFDE1
+	.long	L$set$1
+LASFDE1:
+	.long	LASFDE1-EH_frame1
+	.long	.LFB1-.
+	.set L$set$2,.LFE1-.LFB1
+	.long L$set$2
+	.byte	0x0
+	.byte	0x4
+	.set L$set$3,.LCFI0-.LFB1
+	.long L$set$3
+	.byte	0xe
+	.byte	0x8
+	.byte	0x84
+	.byte	0x2
+	.byte	0x4
+	.set L$set$4,.LCFI1-.LCFI0
+	.long L$set$4
+	.byte	0xd
+	.byte	0x4
+	.align 2
+LEFDE1:
+.globl _ffi_closure_SYSV.eh
+_ffi_closure_SYSV.eh:
+LSFDE2:
+	.set	L$set$5,LEFDE2-LASFDE2
+	.long	L$set$5
+LASFDE2:
+	.long	LASFDE2-EH_frame1
+	.long	.LFB2-.
+	.set L$set$6,.LFE2-.LFB2
+	.long L$set$6
+	.byte	0x0
+	.byte	0x4
+	.set L$set$7,.LCFI2-.LFB2
+	.long L$set$7
+	.byte	0xe
+	.byte	0x8
+	.byte	0x84
+	.byte	0x2
+	.byte	0x4
+	.set L$set$8,.LCFI3-.LCFI2
+	.long L$set$8
+	.byte	0xd
+	.byte	0x4
+	.align 2
+LEFDE2:
+
+#if !FFI_NO_RAW_API
+
+.globl _ffi_closure_raw_SYSV.eh
+_ffi_closure_raw_SYSV.eh:
+LSFDE3:
+	.set	L$set$10,LEFDE3-LASFDE3
+	.long	L$set$10
+LASFDE3:
+	.long	LASFDE3-EH_frame1
+	.long	.LFB3-.
+	.set L$set$11,.LFE3-.LFB3
+	.long L$set$11
+	.byte	0x0
+	.byte	0x4
+	.set L$set$12,.LCFI4-.LFB3
+	.long L$set$12
+	.byte	0xe
+	.byte	0x8
+	.byte	0x84
+	.byte	0x2
+	.byte	0x4
+	.set L$set$13,.LCFI5-.LCFI4
+	.long L$set$13
+	.byte	0xd
+	.byte	0x4
+	.byte	0x4
+	.set L$set$14,.LCFI6-.LCFI5
+	.long L$set$14
+	.byte	0x85
+	.byte	0x3
+	.align 2
+LEFDE3:
+
 #endif
 
 #endif /* ifndef __x86_64__ */
-
-#endif /* defined __i386__ */

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffi.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffi.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffi.c	Thu Mar 27 00:48:05 2008
@@ -1,10 +1,11 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1996, 1998, 1999, 2001  Red Hat, Inc.
+   ffi.c - Copyright (c) 1996, 1998, 1999, 2001, 2007, 2008  Red Hat, Inc.
            Copyright (c) 2002  Ranjit Mathew
            Copyright (c) 2002  Bo Thorsen
            Copyright (c) 2002  Roger Sayle
-   
-   x86 Foreign Function Interface 
+	   Copyright (C) 2008  Free Software Foundation, Inc.
+
+   x86 Foreign Function Interface
 
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
@@ -17,13 +18,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #ifndef __x86_64__
@@ -36,9 +38,7 @@
 /* ffi_prep_args is called by the assembly routine once stack space
    has been allocated for the function's arguments */
 
-/*@-exportheader@*/
 void ffi_prep_args(char *stack, extended_cif *ecif)
-/*@=exportheader@*/
 {
   register unsigned int i;
   register void **p_argv;
@@ -121,9 +121,16 @@
   switch (cif->rtype->type)
     {
     case FFI_TYPE_VOID:
-#if !defined(X86_WIN32) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
+#ifdef X86
     case FFI_TYPE_STRUCT:
 #endif
+#if defined(X86) || defined(X86_DARWIN)
+    case FFI_TYPE_UINT8:
+    case FFI_TYPE_UINT16:
+    case FFI_TYPE_SINT8:
+    case FFI_TYPE_SINT16:
+#endif
+
     case FFI_TYPE_SINT64:
     case FFI_TYPE_FLOAT:
     case FFI_TYPE_DOUBLE:
@@ -135,15 +142,15 @@
       cif->flags = FFI_TYPE_SINT64;
       break;
 
-#if defined(X86_WIN32) || defined(__OpenBSD__) || defined(__FreeBSD__)
+#ifndef X86
     case FFI_TYPE_STRUCT:
       if (cif->rtype->size == 1)
         {
-          cif->flags = FFI_TYPE_SINT8; /* same as char size */
+          cif->flags = FFI_TYPE_SMALL_STRUCT_1B; /* same as char size */
         }
       else if (cif->rtype->size == 2)
         {
-          cif->flags = FFI_TYPE_SINT16; /* same as short size */
+          cif->flags = FFI_TYPE_SMALL_STRUCT_2B; /* same as short size */
         }
       else if (cif->rtype->size == 4)
         {
@@ -165,35 +172,23 @@
       break;
     }
 
+#ifdef X86_DARWIN
+  cif->bytes = (cif->bytes + 15) & ~0xF;
+#endif
+
   return FFI_OK;
 }
 
-/*@-declundef@*/
-/*@-exportheader@*/
-extern void ffi_call_SYSV(void (*)(char *, extended_cif *), 
-			  /*@out@*/ extended_cif *, 
-			  unsigned, unsigned, 
-			  /*@out@*/ unsigned *, 
-			  void (*fn)(void));
-/*@=declundef@*/
-/*@=exportheader@*/
+extern void ffi_call_SYSV(void (*)(char *, extended_cif *), extended_cif *,
+			  unsigned, unsigned, unsigned *, void (*fn)(void));
 
 #ifdef X86_WIN32
-/*@-declundef@*/
-/*@-exportheader@*/
-extern void ffi_call_STDCALL(void (*)(char *, extended_cif *),
-			  /*@out@*/ extended_cif *,
-			  unsigned, unsigned,
-			  /*@out@*/ unsigned *,
-			  void (*fn)(void));
-/*@=declundef@*/
-/*@=exportheader@*/
+extern void ffi_call_STDCALL(void (*)(char *, extended_cif *), extended_cif *,
+			  unsigned, unsigned, unsigned *, void (*fn)(void));
+
 #endif /* X86_WIN32 */
 
-void ffi_call(/*@dependent@*/ ffi_cif *cif, 
-	      void (*fn)(void), 
-	      /*@out@*/ void *rvalue, 
-	      /*@dependent@*/ void **avalue)
+void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   extended_cif ecif;
 
@@ -206,9 +201,7 @@
   if ((rvalue == NULL) && 
       (cif->flags == FFI_TYPE_STRUCT))
     {
-      /*@-sysunrecog@*/
       ecif.rvalue = alloca(cif->rtype->size);
-      /*@=sysunrecog@*/
     }
   else
     ecif.rvalue = rvalue;
@@ -217,17 +210,13 @@
   switch (cif->abi) 
     {
     case FFI_SYSV:
-      /*@-usedef@*/
-      ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, 
-		    cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
+      ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, cif->flags, ecif.rvalue,
+		    fn);
       break;
 #ifdef X86_WIN32
     case FFI_STDCALL:
-      /*@-usedef@*/
-      ffi_call_STDCALL(ffi_prep_args, &ecif, cif->bytes,
-		    cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
+      ffi_call_STDCALL(ffi_prep_args, &ecif, cif->bytes, cif->flags,
+		       ecif.rvalue, fn);
       break;
 #endif /* X86_WIN32 */
     default:
@@ -247,6 +236,10 @@
      __attribute__ ((regparm(1)));
 void FFI_HIDDEN ffi_closure_raw_SYSV (ffi_raw_closure *)
      __attribute__ ((regparm(1)));
+#ifdef X86_WIN32
+void FFI_HIDDEN ffi_closure_STDCALL (ffi_closure *)
+     __attribute__ ((regparm(1)));
+#endif
 
 /* This function is jumped to by the trampoline */
 
@@ -256,7 +249,7 @@
      void **respp;
      void *args;
 {
-  // our various things...
+  /* our various things...  */
   ffi_cif       *cif;
   void         **arg_area;
 
@@ -276,11 +269,9 @@
   return cif->flags;
 }
 
-/*@-exportheader@*/
-static void 
-ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
-			    void **avalue, ffi_cif *cif)
-/*@=exportheader@*/
+static void
+ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, void **avalue,
+			    ffi_cif *cif)
 {
   register unsigned int i;
   register void **p_argv;
@@ -324,27 +315,54 @@
 ({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
    unsigned int  __fun = (unsigned int)(FUN); \
    unsigned int  __ctx = (unsigned int)(CTX); \
-   unsigned int  __dis = __fun - ((unsigned int) __tramp + FFI_TRAMPOLINE_SIZE); \
+   unsigned int  __dis = __fun - (__ctx + 10);	\
    *(unsigned char*) &__tramp[0] = 0xb8; \
    *(unsigned int*)  &__tramp[1] = __ctx; /* movl __ctx, %eax */ \
    *(unsigned char *)  &__tramp[5] = 0xe9; \
    *(unsigned int*)  &__tramp[6] = __dis; /* jmp __fun  */ \
  })
 
+#define FFI_INIT_TRAMPOLINE_STDCALL(TRAMP,FUN,CTX,SIZE)  \
+({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
+   unsigned int  __fun = (unsigned int)(FUN); \
+   unsigned int  __ctx = (unsigned int)(CTX); \
+   unsigned int  __dis = __fun - (__ctx + 10); \
+   unsigned short __size = (unsigned short)(SIZE); \
+   *(unsigned char*) &__tramp[0] = 0xb8; \
+   *(unsigned int*)  &__tramp[1] = __ctx; /* movl __ctx, %eax */ \
+   *(unsigned char *)  &__tramp[5] = 0xe8; \
+   *(unsigned int*)  &__tramp[6] = __dis; /* call __fun  */ \
+   *(unsigned char *)  &__tramp[10] = 0xc2; \
+   *(unsigned short*)  &__tramp[11] = __size; /* ret __size  */ \
+ })
 
 /* the cif must already be prep'ed */
 
 ffi_status
-ffi_prep_closure (ffi_closure* closure,
-		  ffi_cif* cif,
-		  void (*fun)(ffi_cif*,void*,void**,void*),
-		  void *user_data)
+ffi_prep_closure_loc (ffi_closure* closure,
+		      ffi_cif* cif,
+		      void (*fun)(ffi_cif*,void*,void**,void*),
+		      void *user_data,
+		      void *codeloc)
 {
-  FFI_ASSERT (cif->abi == FFI_SYSV);
-
-  FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
-		       &ffi_closure_SYSV,  \
-		       (void*)closure);
+  if (cif->abi == FFI_SYSV)
+    {
+      FFI_INIT_TRAMPOLINE (&closure->tramp[0],
+                           &ffi_closure_SYSV,
+                           (void*)closure);
+    }
+#ifdef X86_WIN32
+  else if (cif->abi == FFI_STDCALL)
+    {
+      FFI_INIT_TRAMPOLINE_STDCALL (&closure->tramp[0],
+                                   &ffi_closure_STDCALL,
+                                   (void*)closure, cif->bytes);
+    }
+#endif
+  else
+    {
+      return FFI_BAD_ABI;
+    }
     
   closure->cif  = cif;
   closure->user_data = user_data;
@@ -358,14 +376,17 @@
 #if !FFI_NO_RAW_API
 
 ffi_status
-ffi_prep_raw_closure (ffi_raw_closure* closure,
-		      ffi_cif* cif,
-		      void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
-		      void *user_data)
+ffi_prep_raw_closure_loc (ffi_raw_closure* closure,
+			  ffi_cif* cif,
+			  void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
+			  void *user_data,
+			  void *codeloc)
 {
   int i;
 
-  FFI_ASSERT (cif->abi == FFI_SYSV);
+  if (cif->abi != FFI_SYSV) {
+    return FFI_BAD_ABI;
+  }
 
   // we currently don't support certain kinds of arguments for raw
   // closures.  This should be implemented by a separate assembly language
@@ -380,7 +401,7 @@
   
 
   FFI_INIT_TRAMPOLINE (&closure->tramp[0], &ffi_closure_raw_SYSV,
-		       (void*)closure);
+		       codeloc);
     
   closure->cif  = cif;
   closure->user_data = user_data;
@@ -400,27 +421,18 @@
  * libffi-1.20, this is not the case.)
  */
 
-extern void 
-ffi_call_SYSV(void (*)(char *, extended_cif *), 
-	      /*@out@*/ extended_cif *, 
-	      unsigned, unsigned, 
-	      /*@out@*/ unsigned *, 
-	      void (*fn)(void));
+extern void
+ffi_call_SYSV(void (*)(char *, extended_cif *), extended_cif *, unsigned, 
+	      unsigned, unsigned *, void (*fn)(void));
 
 #ifdef X86_WIN32
 extern void
-ffi_call_STDCALL(void (*)(char *, extended_cif *),
-	      /*@out@*/ extended_cif *,
-	      unsigned, unsigned,
-	      /*@out@*/ unsigned *,
-	      void (*fn)(void));
+ffi_call_STDCALL(void (*)(char *, extended_cif *), extended_cif *, unsigned,
+		 unsigned, unsigned *, void (*fn)(void));
 #endif /* X86_WIN32 */
 
 void
-ffi_raw_call(/*@dependent@*/ ffi_cif *cif, 
-	     void (*fn)(void), 
-	     /*@out@*/ void *rvalue, 
-	     /*@dependent@*/ ffi_raw *fake_avalue)
+ffi_raw_call(ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *fake_avalue)
 {
   extended_cif ecif;
   void **avalue = (void **)fake_avalue;
@@ -434,9 +446,7 @@
   if ((rvalue == NULL) && 
       (cif->rtype->type == FFI_TYPE_STRUCT))
     {
-      /*@-sysunrecog@*/
       ecif.rvalue = alloca(cif->rtype->size);
-      /*@=sysunrecog@*/
     }
   else
     ecif.rvalue = rvalue;
@@ -445,17 +455,13 @@
   switch (cif->abi) 
     {
     case FFI_SYSV:
-      /*@-usedef@*/
-      ffi_call_SYSV(ffi_prep_args_raw, &ecif, cif->bytes, 
-		    cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
+      ffi_call_SYSV(ffi_prep_args_raw, &ecif, cif->bytes, cif->flags,
+		    ecif.rvalue, fn);
       break;
 #ifdef X86_WIN32
     case FFI_STDCALL:
-      /*@-usedef@*/
-      ffi_call_STDCALL(ffi_prep_args_raw, &ecif, cif->bytes,
-		    cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
+      ffi_call_STDCALL(ffi_prep_args_raw, &ecif, cif->bytes, cif->flags,
+		       ecif.rvalue, fn);
       break;
 #endif /* X86_WIN32 */
     default:

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffi64.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffi64.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffi64.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 2002  Bo Thorsen <bo at suse.de>
+   ffi.c - Copyright (c) 2002, 2007  Bo Thorsen <bo at suse.de>
+           Copyright (c) 2008  Red Hat, Inc.
    
    x86-64 Foreign Function Interface 
 
@@ -14,13 +15,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #include <ffi.h>
@@ -433,10 +435,11 @@
 extern void ffi_closure_unix64(void);
 
 ffi_status
-ffi_prep_closure (ffi_closure* closure,
-		  ffi_cif* cif,
-		  void (*fun)(ffi_cif*, void*, void**, void*),
-		  void *user_data)
+ffi_prep_closure_loc (ffi_closure* closure,
+		      ffi_cif* cif,
+		      void (*fun)(ffi_cif*, void*, void**, void*),
+		      void *user_data,
+		      void *codeloc)
 {
   volatile unsigned short *tramp;
 
@@ -445,7 +448,7 @@
   tramp[0] = 0xbb49;		/* mov <code>, %r11	*/
   *(void * volatile *) &tramp[1] = ffi_closure_unix64;
   tramp[5] = 0xba49;		/* mov <data>, %r10	*/
-  *(void * volatile *) &tramp[6] = closure;
+  *(void * volatile *) &tramp[6] = codeloc;
 
   /* Set the carry bit iff the function uses any sse registers.
      This is clc or stc, together with the first byte of the jmp.  */

Deleted: /python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffi_darwin.c
==============================================================================
--- /python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffi_darwin.c	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,594 +0,0 @@
-# ifdef __i386__
-/* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1996, 1998, 1999, 2001  Red Hat, Inc.
-           Copyright (c) 2002  Ranjit Mathew
-           Copyright (c) 2002  Bo Thorsen
-           Copyright (c) 2002  Roger Sayle
-   
-   x86 Foreign Function Interface 
-
-   Permission is hereby granted, free of charge, to any person obtaining
-   a copy of this software and associated documentation files (the
-   ``Software''), to deal in the Software without restriction, including
-   without limitation the rights to use, copy, modify, merge, publish,
-   distribute, sublicense, and/or sell copies of the Software, and to
-   permit persons to whom the Software is furnished to do so, subject to
-   the following conditions:
-
-   The above copyright notice and this permission notice shall be included
-   in all copies or substantial portions of the Software.
-
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
-   ----------------------------------------------------------------------- */
-
-#ifndef __x86_64__
-
-#include <ffi.h>
-#include <ffi_common.h>
-
-#include <stdlib.h>
-
-/* ffi_prep_args is called by the assembly routine once stack space
-   has been allocated for the function's arguments */
-
-/*@-exportheader@*/
-void ffi_prep_args(char *stack, extended_cif *ecif);
-
-static inline int retval_on_stack(ffi_type* tp)
-{
-	if (tp->type == FFI_TYPE_STRUCT) {
-		int sz = tp->size;
-		if (sz > 8) {
-			return 1;
-		}
-		switch (sz) {
-		case 1: case 2: case 4: case 8: return 0;
-		default: return 1;
-		}
-	}
-	return 0;
-}
-
-
-void ffi_prep_args(char *stack, extended_cif *ecif)
-/*@=exportheader@*/
-{
-  register unsigned int i;
-  register void **p_argv;
-  register char *argp;
-  register ffi_type **p_arg;
-
-  argp = stack;
-
-  if (retval_on_stack(ecif->cif->rtype)) {
-      *(void **) argp = ecif->rvalue;
-      argp += 4;
-  }
-
-
-  p_argv = ecif->avalue;
-
-  for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
-       i != 0;
-       i--, p_arg++)
-    {
-      size_t z;
-
-      /* Align if necessary */
-      if ((sizeof(int) - 1) & (unsigned) argp)
-	      argp = (char *) ALIGN(argp, sizeof(int));
-
-      z = (*p_arg)->size;
-      if (z < sizeof(int))
-	{
-	  z = sizeof(int);
-	  switch ((*p_arg)->type)
-	    {
-	    case FFI_TYPE_SINT8:
-	      *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv);
-	      break;
-
-	    case FFI_TYPE_UINT8:
-	      *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv);
-	      break;
-
-	    case FFI_TYPE_SINT16:
-	      *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv);
-	      break;
-
-	    case FFI_TYPE_UINT16:
-	      *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv);
-	      break;
-
-	    case FFI_TYPE_SINT32:
-	      *(signed int *) argp = (signed int)*(SINT32 *)(* p_argv);
-	      break;
-
-	    case FFI_TYPE_UINT32:
-	      *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
-	      break;
-
-	    case FFI_TYPE_STRUCT:
-	      *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
-	      break;
-
-	    default:
-	      FFI_ASSERT(0);
-	    }
-	}
-      else
-	{
-	  memcpy(argp, *p_argv, z);
-	}
-      p_argv++;
-      argp += z;
-    }
-  
-  return;
-}
-
-/* Perform machine dependent cif processing */
-ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
-{
-  /* Set the return type flag */
-  switch (cif->rtype->type)
-    {
-    case FFI_TYPE_VOID:
-#if !defined(X86_WIN32)  && !defined(X86_DARWIN)
-    case FFI_TYPE_STRUCT:
-#endif
-    case FFI_TYPE_SINT64:
-    case FFI_TYPE_FLOAT:
-    case FFI_TYPE_DOUBLE:
-    case FFI_TYPE_LONGDOUBLE:
-      cif->flags = (unsigned) cif->rtype->type;
-      break;
-
-    case FFI_TYPE_UINT64:
-      cif->flags = FFI_TYPE_SINT64;
-      break;
-
-#if defined(X86_WIN32) || defined(X86_DARWIN)
-
-    case FFI_TYPE_STRUCT:
-      if (cif->rtype->size == 1)
-        {
-          cif->flags = FFI_TYPE_SINT8; /* same as char size */
-        }
-      else if (cif->rtype->size == 2)
-        {
-          cif->flags = FFI_TYPE_SINT16; /* same as short size */
-        }
-      else if (cif->rtype->size == 4)
-        {
-          cif->flags = FFI_TYPE_INT; /* same as int type */
-        }
-      else if (cif->rtype->size == 8)
-        {
-          cif->flags = FFI_TYPE_SINT64; /* same as int64 type */
-        }
-      else
-        {
-          cif->flags = FFI_TYPE_STRUCT;
-        }
-      break;
-#endif
-
-    default:
-      cif->flags = FFI_TYPE_INT;
-      break;
-    }
-
-  /* Darwin: The stack needs to be aligned to a multiple of 16 bytes */
-#if 1
-  cif->bytes = (cif->bytes + 15) & ~0xF;
-#endif
-
-
-  return FFI_OK;
-}
-
-/*@-declundef@*/
-/*@-exportheader@*/
-extern void ffi_call_SYSV(void (*)(char *, extended_cif *), 
-			  /*@out@*/ extended_cif *, 
-			  unsigned, unsigned, 
-			  /*@out@*/ unsigned *, 
-			  void (*fn)(void));
-/*@=declundef@*/
-/*@=exportheader@*/
-
-#ifdef X86_WIN32
-/*@-declundef@*/
-/*@-exportheader@*/
-extern void ffi_call_STDCALL(void (*)(char *, extended_cif *),
-			  /*@out@*/ extended_cif *,
-			  unsigned, unsigned,
-			  /*@out@*/ unsigned *,
-			  void (*fn)(void));
-/*@=declundef@*/
-/*@=exportheader@*/
-#endif /* X86_WIN32 */
-
-void ffi_call(/*@dependent@*/ ffi_cif *cif, 
-	      void (*fn)(), 
-	      /*@out@*/ void *rvalue, 
-	      /*@dependent@*/ void **avalue)
-{
-  extended_cif ecif;
-
-  ecif.cif = cif;
-  ecif.avalue = avalue;
-  
-  /* If the return value is a struct and we don't have a return	*/
-  /* value address then we need to make one		        */
-
-  if ((rvalue == NULL) && retval_on_stack(cif->rtype))
-    {
-      /*@-sysunrecog@*/
-      ecif.rvalue = alloca(cif->rtype->size);
-      /*@=sysunrecog@*/
-    }
-  else
-    ecif.rvalue = rvalue;
-
-  switch (cif->abi) 
-    {
-    case FFI_SYSV:
-      /*@-usedef@*/
-      /* To avoid changing the assembly code make sure the size of the argument 
-       * block is a multiple of 16. Then add 8 to compensate for local variables
-       * in ffi_call_SYSV.
-       */
-      ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, 
-		    cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
-      break;
-#ifdef X86_WIN32
-    case FFI_STDCALL:
-      /*@-usedef@*/
-      ffi_call_STDCALL(ffi_prep_args, &ecif, cif->bytes,
-		    cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
-      break;
-#endif /* X86_WIN32 */
-    default:
-      FFI_ASSERT(0);
-      break;
-    }
-}
-
-
-/** private members **/
-
-static void ffi_closure_SYSV (ffi_closure *)
-     __attribute__ ((regparm(1)));
-#if !FFI_NO_RAW_API
-static void ffi_closure_raw_SYSV (ffi_raw_closure *)
-     __attribute__ ((regparm(1)));
-#endif
-
-/*@-exportheader@*/
-static inline void 
-ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
-			    void **avalue, ffi_cif *cif)
-/*@=exportheader@*/
-{
-  register unsigned int i;
-  register void **p_argv;
-  register char *argp;
-  register ffi_type **p_arg;
-
-  argp = stack;
-
-  if (retval_on_stack(cif->rtype)) {
-    *rvalue = *(void **) argp;
-    argp += 4;
-  }
-
-  p_argv = avalue;
-
-  for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
-    {
-      size_t z;
-
-      /* Align if necessary */
-      if ((sizeof(int) - 1) & (unsigned) argp) {
-	argp = (char *) ALIGN(argp, sizeof(int));
-      }
-
-      z = (*p_arg)->size;
-
-      /* because we're little endian, this is what it turns into.   */
-
-      *p_argv = (void*) argp;
-
-      p_argv++;
-      argp += z;
-    }
-  
-  return;
-}
-
-/* This function is jumped to by the trampoline */
-
-static void
-ffi_closure_SYSV (closure)
-     ffi_closure *closure;
-{
-  // this is our return value storage
-  long double  res;
-
-  // our various things...
-  ffi_cif       *cif;
-  void         **arg_area;
-  void          *resp = (void*)&res;
-  void *args = __builtin_dwarf_cfa ();
-
-
-  cif         = closure->cif;
-  arg_area    = (void**) alloca (cif->nargs * sizeof (void*));  
-
-  /* this call will initialize ARG_AREA, such that each
-   * element in that array points to the corresponding 
-   * value on the stack; and if the function returns
-   * a structure, it will re-set RESP to point to the
-   * structure return address.  */
-
-  ffi_prep_incoming_args_SYSV(args, (void**)&resp, arg_area, cif);
-  
-  (closure->fun) (cif, resp, arg_area, closure->user_data);
-
-  /* now, do a generic return based on the value of rtype */
-  if (cif->flags == FFI_TYPE_INT)
-    {
-      asm ("movl (%0),%%eax" : : "r" (resp) : "eax");
-    }
-  else if (cif->flags == FFI_TYPE_FLOAT)
-    {
-      asm ("flds (%0)" : : "r" (resp) : "st" );
-    }
-  else if (cif->flags == FFI_TYPE_DOUBLE)
-    {
-      asm ("fldl (%0)" : : "r" (resp) : "st", "st(1)" );
-    }
-  else if (cif->flags == FFI_TYPE_LONGDOUBLE)
-    {
-      asm ("fldt (%0)" : : "r" (resp) : "st", "st(1)" );
-    }
-  else if (cif->flags == FFI_TYPE_SINT64)
-    {
-      asm ("movl 0(%0),%%eax;"
-	   "movl 4(%0),%%edx" 
-	   : : "r"(resp)
-	   : "eax", "edx");
-    }
-#if defined(X86_WIN32) || defined(X86_DARWIN)
-  else if (cif->flags == FFI_TYPE_SINT8) /* 1-byte struct  */
-    {
-      asm ("movsbl (%0),%%eax" : : "r" (resp) : "eax");
-    }
-  else if (cif->flags == FFI_TYPE_SINT16) /* 2-bytes struct */
-    {
-      asm ("movswl (%0),%%eax" : : "r" (resp) : "eax");
-    }
-#endif
-
-  else if (cif->flags == FFI_TYPE_STRUCT)
-    {
-      asm ("lea -8(%ebp),%esp;"
-	   "pop %esi;"
-	   "pop %edi;"
-	   "pop %ebp;"
-	   "ret $4"); 
-    }
-}
-
-
-/* How to make a trampoline.  Derived from gcc/config/i386/i386.c. */
-
-#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX) \
-({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
-   unsigned int  __fun = (unsigned int)(FUN); \
-   unsigned int  __ctx = (unsigned int)(CTX); \
-   unsigned int  __dis = __fun - ((unsigned int) __tramp + FFI_TRAMPOLINE_SIZE); \
-   *(unsigned char*) &__tramp[0] = 0xb8; \
-   *(unsigned int*)  &__tramp[1] = __ctx; /* movl __ctx, %eax */ \
-   *(unsigned char *)  &__tramp[5] = 0xe9; \
-   *(unsigned int*)  &__tramp[6] = __dis; /* jmp __fun  */ \
- })
-
-
-/* the cif must already be prep'ed */
-
-ffi_status
-ffi_prep_closure (ffi_closure* closure,
-		  ffi_cif* cif,
-		  void (*fun)(ffi_cif*,void*,void**,void*),
-		  void *user_data)
-{
-  FFI_ASSERT (cif->abi == FFI_SYSV);
-
-  FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
-		       &ffi_closure_SYSV,  \
-		       (void*)closure);
-    
-  closure->cif  = cif;
-  closure->user_data = user_data;
-  closure->fun  = fun;
-
-  return FFI_OK;
-}
-
-/* ------- Native raw API support -------------------------------- */
-
-#if !FFI_NO_RAW_API
-
-static void
-ffi_closure_raw_SYSV (closure)
-     ffi_raw_closure *closure;
-{
-  // this is our return value storage
-  long double    res;
-
-  // our various things...
-  ffi_raw         *raw_args;
-  ffi_cif         *cif;
-  unsigned short   rtype;
-  void            *resp = (void*)&res;
-
-  /* get the cif */
-  cif = closure->cif;
-
-  /* the SYSV/X86 abi matches the RAW API exactly, well.. almost */
-  raw_args = (ffi_raw*) __builtin_dwarf_cfa ();
-
-  (closure->fun) (cif, resp, raw_args, closure->user_data);
-
-  rtype = cif->flags;
-
-  /* now, do a generic return based on the value of rtype */
-  if (rtype == FFI_TYPE_INT)
-    {
-      asm ("movl (%0),%%eax" : : "r" (resp) : "eax");
-    }
-  else if (rtype == FFI_TYPE_FLOAT)
-    {
-      asm ("flds (%0)" : : "r" (resp) : "st" );
-    }
-  else if (rtype == FFI_TYPE_DOUBLE)
-    {
-      asm ("fldl (%0)" : : "r" (resp) : "st", "st(1)" );
-    }
-  else if (rtype == FFI_TYPE_LONGDOUBLE)
-    {
-      asm ("fldt (%0)" : : "r" (resp) : "st", "st(1)" );
-    }
-  else if (rtype == FFI_TYPE_SINT64)
-    {
-      asm ("movl 0(%0),%%eax; movl 4(%0),%%edx" 
-	   : : "r"(resp)
-	   : "eax", "edx");
-    }
-}
-
- 
-
-
-ffi_status
-ffi_prep_raw_closure (ffi_raw_closure* closure,
-		      ffi_cif* cif,
-		      void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
-		      void *user_data)
-{
-  int i;
-
-  FFI_ASSERT (cif->abi == FFI_SYSV);
-
-  // we currently don't support certain kinds of arguments for raw
-  // closures.  This should be implemented by a separate assembly language
-  // routine, since it would require argument processing, something we
-  // don't do now for performance.
-
-  for (i = cif->nargs-1; i >= 0; i--)
-    {
-      FFI_ASSERT (cif->arg_types[i]->type != FFI_TYPE_STRUCT);
-      FFI_ASSERT (cif->arg_types[i]->type != FFI_TYPE_LONGDOUBLE);
-    }
-  
-
-  FFI_INIT_TRAMPOLINE (&closure->tramp[0], &ffi_closure_raw_SYSV,
-		       (void*)closure);
-    
-  closure->cif  = cif;
-  closure->user_data = user_data;
-  closure->fun  = fun;
-
-  return FFI_OK;
-}
-
-static void 
-ffi_prep_args_raw(char *stack, extended_cif *ecif)
-{
-  memcpy (stack, ecif->avalue, ecif->cif->bytes);
-}
-
-/* we borrow this routine from libffi (it must be changed, though, to
- * actually call the function passed in the first argument.  as of
- * libffi-1.20, this is not the case.)
- */
-
-extern void 
-ffi_call_SYSV(void (*)(char *, extended_cif *), 
-	      /*@out@*/ extended_cif *, 
-	      unsigned, unsigned, 
-	      /*@out@*/ unsigned *, 
-	      void (*fn)());
-
-#ifdef X86_WIN32
-extern void
-ffi_call_STDCALL(void (*)(char *, extended_cif *),
-	      /*@out@*/ extended_cif *,
-	      unsigned, unsigned,
-	      /*@out@*/ unsigned *,
-	      void (*fn)());
-#endif /* X86_WIN32 */
-
-void
-ffi_raw_call(/*@dependent@*/ ffi_cif *cif, 
-	     void (*fn)(), 
-	     /*@out@*/ void *rvalue, 
-	     /*@dependent@*/ ffi_raw *fake_avalue)
-{
-  extended_cif ecif;
-  void **avalue = (void **)fake_avalue;
-
-  ecif.cif = cif;
-  ecif.avalue = avalue;
-  
-  /* If the return value is a struct and we don't have a return	*/
-  /* value address then we need to make one		        */
-
-  if ((rvalue == NULL) && retval_on_stack(cif->rtype)) 
-    {
-      /*@-sysunrecog@*/
-      ecif.rvalue = alloca(cif->rtype->size);
-      /*@=sysunrecog@*/
-    }
-  else
-    ecif.rvalue = rvalue;
-    
-  
-  switch (cif->abi) 
-    {
-    case FFI_SYSV:
-      /*@-usedef@*/
-      ffi_call_SYSV(ffi_prep_args_raw, &ecif, cif->bytes, 
-		    cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
-      break;
-#ifdef X86_WIN32
-    case FFI_STDCALL:
-      /*@-usedef@*/
-      ffi_call_STDCALL(ffi_prep_args_raw, &ecif, cif->bytes,
-		    cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
-      break;
-#endif /* X86_WIN32 */
-    default:
-      FFI_ASSERT(0);
-      break;
-    }
-}
-
-#endif
-
-#endif /* __x86_64__  */
-
-#endif /* __i386__ */

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffitarget.h
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffitarget.h	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/ffitarget.h	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,7 @@
 /* -----------------------------------------------------------------*-C-*-
    ffitarget.h - Copyright (c) 1996-2003  Red Hat, Inc.
+   Copyright (C) 2008  Free Software Foundation, Inc.
+
    Target configuration macros for x86 and x86-64.
 
    Permission is hereby granted, free of charge, to any person obtaining
@@ -13,13 +15,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
 
    ----------------------------------------------------------------------- */
 
@@ -51,7 +54,7 @@
 #endif
 
   /* ---- Intel x86 and AMD x86-64 - */
-#if !defined(X86_WIN32) && (defined(__i386__) || defined(__x86_64__)) 
+#if !defined(X86_WIN32) && (defined(__i386__) || defined(__x86_64__))
   FFI_SYSV,
   FFI_UNIX64,   /* Unix variants all use the same ABI for x86-64  */
 #ifdef __i386__
@@ -68,12 +71,18 @@
 /* ---- Definitions for closures ----------------------------------------- */
 
 #define FFI_CLOSURES 1
+#define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
+#define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
 
-#ifdef X86_64
+#if defined (X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
 #define FFI_TRAMPOLINE_SIZE 24
 #define FFI_NATIVE_RAW_API 0
 #else
+#ifdef X86_WIN32
+#define FFI_TRAMPOLINE_SIZE 13
+#else
 #define FFI_TRAMPOLINE_SIZE 10
+#endif
 #define FFI_NATIVE_RAW_API 1	/* x86 has native raw api support */
 #endif
 

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/sysv.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/sysv.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/sysv.S	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   sysv.S - Copyright (c) 1996, 1998, 2001, 2002, 2003, 2005  Red Hat, Inc.
+   sysv.S - Copyright (c) 1996, 1998, 2001-2003, 2005, 2008  Red Hat, Inc.
    
    X86 Foreign Function Interface 
 
@@ -14,13 +14,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #ifndef __x86_64__
@@ -59,16 +60,15 @@
 
 	call  *28(%ebp)
 
-	/* Remove the space we pushed for the args  */
-	movl  16(%ebp),%ecx
-	addl  %ecx,%esp
-
 	/* Load %ecx with the return type code  */
 	movl  20(%ebp),%ecx	
 
+	/* Protect %esi.  We're going to pop it in the epilogue.  */
+	pushl %esi
+
 	/* If the return value pointer is NULL, assume no return value.  */
 	cmpl  $0,24(%ebp)
-	jne   retint
+	jne  0f
 
 	/* Even if there is no space for the return value, we are 
 	   obliged to handle floating-point values.  */
@@ -78,51 +78,84 @@
 
         jmp   epilogue
 
-retint:
-	cmpl  $FFI_TYPE_INT,%ecx
-	jne   retfloat
-	/* Load %ecx with the pointer to storage for the return value  */
-	movl  24(%ebp),%ecx	
-	movl  %eax,0(%ecx)
-	jmp   epilogue
+0:
+	call  1f
+
+.Lstore_table:
+	.long	noretval-.Lstore_table	/* FFI_TYPE_VOID */
+	.long	retint-.Lstore_table	/* FFI_TYPE_INT */
+	.long	retfloat-.Lstore_table	/* FFI_TYPE_FLOAT */
+	.long	retdouble-.Lstore_table	/* FFI_TYPE_DOUBLE */
+	.long	retlongdouble-.Lstore_table	/* FFI_TYPE_LONGDOUBLE */
+	.long	retuint8-.Lstore_table	/* FFI_TYPE_UINT8 */
+	.long	retsint8-.Lstore_table	/* FFI_TYPE_SINT8 */
+	.long	retuint16-.Lstore_table	/* FFI_TYPE_UINT16 */
+	.long	retsint16-.Lstore_table	/* FFI_TYPE_SINT16 */
+	.long	retint-.Lstore_table	/* FFI_TYPE_UINT32 */
+	.long	retint-.Lstore_table	/* FFI_TYPE_SINT32 */
+	.long	retint64-.Lstore_table	/* FFI_TYPE_UINT64 */
+	.long	retint64-.Lstore_table	/* FFI_TYPE_SINT64 */
+	.long	retstruct-.Lstore_table	/* FFI_TYPE_STRUCT */
+	.long	retint-.Lstore_table	/* FFI_TYPE_POINTER */
+
+1:
+	pop  %esi
+	add  (%esi, %ecx, 4), %esi
+	jmp  *%esi
+
+	/* Sign/zero extend as appropriate.  */
+retsint8:
+	movsbl  %al, %eax
+	jmp  retint
+
+retsint16:
+	movswl  %ax, %eax
+	jmp  retint
+
+retuint8:
+	movzbl  %al, %eax
+	jmp  retint
+
+retuint16:
+	movzwl  %ax, %eax
+	jmp  retint
 
 retfloat:
-	cmpl  $FFI_TYPE_FLOAT,%ecx
-	jne   retdouble
 	/* Load %ecx with the pointer to storage for the return value  */
 	movl  24(%ebp),%ecx	
 	fstps (%ecx)
 	jmp   epilogue
 
 retdouble:
-	cmpl  $FFI_TYPE_DOUBLE,%ecx
-	jne   retlongdouble
 	/* Load %ecx with the pointer to storage for the return value  */
 	movl  24(%ebp),%ecx	
 	fstpl (%ecx)
 	jmp   epilogue
 
 retlongdouble:
-	cmpl  $FFI_TYPE_LONGDOUBLE,%ecx
-	jne   retint64
 	/* Load %ecx with the pointer to storage for the return value  */
 	movl  24(%ebp),%ecx	
 	fstpt (%ecx)
 	jmp   epilogue
 	
 retint64:	
-	cmpl  $FFI_TYPE_SINT64,%ecx
-        jne   retstruct
 	/* Load %ecx with the pointer to storage for the return value  */
 	movl  24(%ebp),%ecx	
 	movl  %eax,0(%ecx)
 	movl  %edx,4(%ecx)
+	jmp   epilogue
 	
+retint:
+	/* Load %ecx with the pointer to storage for the return value  */
+	movl  24(%ebp),%ecx	
+	movl  %eax,0(%ecx)
+
 retstruct:
 	/* Nothing to do!  */
 
 noretval:
 epilogue:
+        popl %esi
         movl %ebp,%esp
         popl %ebp
         ret
@@ -162,7 +195,15 @@
 	movl	-12(%ebp), %ecx
 	cmpl	$FFI_TYPE_INT, %eax
 	je	.Lcls_retint
-	cmpl	$FFI_TYPE_FLOAT, %eax
+
+	/* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16,
+	   FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32.  */
+	cmpl	$FFI_TYPE_UINT64, %eax
+	jge	0f
+	cmpl	$FFI_TYPE_UINT8, %eax
+	jge	.Lcls_retint
+	
+0:	cmpl	$FFI_TYPE_FLOAT, %eax
 	je	.Lcls_retfloat
 	cmpl	$FFI_TYPE_DOUBLE, %eax
 	je	.Lcls_retdouble
@@ -170,6 +211,8 @@
 	je	.Lcls_retldouble
 	cmpl	$FFI_TYPE_SINT64, %eax
 	je	.Lcls_retllong
+	cmpl	$FFI_TYPE_STRUCT, %eax
+	je	.Lcls_retstruct
 .Lcls_epilogue:
 	movl	%ebp, %esp
 	popl	%ebp
@@ -190,6 +233,10 @@
 	movl	(%ecx), %eax
 	movl	4(%ecx), %edx
 	jmp	.Lcls_epilogue
+.Lcls_retstruct:
+	movl	%ebp, %esp
+	popl	%ebp
+	ret	$4
 .LFE2:
 	.size	ffi_closure_SYSV, .-ffi_closure_SYSV
 
@@ -226,6 +273,14 @@
 	movl	CIF_FLAGS_OFFSET(%esi), %eax		 /* rtype */
 	cmpl	$FFI_TYPE_INT, %eax
 	je	.Lrcls_retint
+
+	/* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16,
+	   FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32.  */
+	cmpl	$FFI_TYPE_UINT64, %eax
+	jge	0f
+	cmpl	$FFI_TYPE_UINT8, %eax
+	jge	.Lrcls_retint
+0:
 	cmpl	$FFI_TYPE_FLOAT, %eax
 	je	.Lrcls_retfloat
 	cmpl	$FFI_TYPE_DOUBLE, %eax
@@ -377,6 +432,6 @@
 
 #endif /* ifndef __x86_64__ */
 
-#ifdef __ELF__
-.section .note.GNU-stack,"",%progbits
+#if defined __ELF__ && defined __linux__
+	.section	.note.GNU-stack,"", at progbits
 #endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/unix64.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/unix64.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/unix64.S	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,6 @@
 /* -----------------------------------------------------------------------
    unix64.S - Copyright (c) 2002  Bo Thorsen <bo at suse.de>
+	      Copyright (c) 2008  Red Hat, Inc
 
    x86-64 Foreign Function Interface 
 
@@ -14,13 +15,14 @@
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.
 
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
 #ifdef __x86_64__
@@ -31,7 +33,7 @@
 .text
 
 /* ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags,
-	            void *raddr, void (*fnaddr)());
+	            void *raddr, void (*fnaddr)(void));
 
    Bit o trickiness here -- ARGS+BYTES is the base of the stack frame
    for this function.  This has been allocated by ffi_call.  We also
@@ -410,3 +412,7 @@
 .LEFDE3:
 
 #endif /* __x86_64__ */
+
+#if defined __ELF__ && defined __linux__
+	.section	.note.GNU-stack,"", at progbits
+#endif

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/win32.S
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/win32.S	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi/src/x86/win32.S	Thu Mar 27 00:48:05 2008
@@ -20,7 +20,8 @@
    THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+	ANY CLAIM, DAMAGES OR
    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    OTHER DEALINGS IN THE SOFTWARE.
@@ -258,6 +259,22 @@
 
 .ffi_call_STDCALL_end:
 
+	.globl _ffi_closure_STDCALL
+_ffi_closure_STDCALL:
+	pushl	%ebp
+	movl	%esp, %ebp
+	subl	$40, %esp
+	leal	-24(%ebp), %edx
+	movl	%edx, -12(%ebp)	/* resp */
+	leal	12(%ebp), %edx  /* account for stub return address on stack */
+	movl	%edx, 4(%esp)	/* args */
+	leal	-12(%ebp), %edx
+	movl	%edx, (%esp)	/* &resp */
+	call	_ffi_closure_SYSV_inner
+	movl	-12(%ebp), %ecx
+	jmp     .Lcls_return_result
+.ffi_closure_STDCALL_end:
+
 	.globl _ffi_closure_SYSV
 _ffi_closure_SYSV:
 	pushl	%ebp
@@ -271,6 +288,7 @@
 	movl	%edx, (%esp)	/* &resp */
 	call	_ffi_closure_SYSV_inner
 	movl	-12(%ebp), %ecx
+.Lcls_return_result:
 	cmpl	$FFI_TYPE_INT, %eax
 	je	.Lcls_retint
 	cmpl	$FFI_TYPE_FLOAT, %eax

Modified: python/branches/py3k-importlib/Modules/_ctypes/libffi_msvc/prep_cif.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/libffi_msvc/prep_cif.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/libffi_msvc/prep_cif.c	Thu Mar 27 00:48:05 2008
@@ -163,7 +163,7 @@
 	    bytes = ALIGN(bytes, (*ptr)->alignment);
 	  
 #endif
-	  bytes += STACK_ARG_SIZE((*ptr)->size);
+	  bytes += (unsigned)STACK_ARG_SIZE((*ptr)->size);
 	}
 #endif
     }

Modified: python/branches/py3k-importlib/Modules/_ctypes/stgdict.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/stgdict.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/stgdict.c	Thu Mar 27 00:48:05 2008
@@ -183,7 +183,7 @@
 			Py_DECREF(fieldlist);
 			return -1;
 		}
-		if (Py_Type(fdescr) != &CField_Type) {
+		if (Py_TYPE(fdescr) != &CField_Type) {
 			PyErr_SetString(PyExc_TypeError, "unexpected type");
 			Py_DECREF(fdescr);
 			Py_DECREF(fieldlist);
@@ -206,7 +206,7 @@
 			Py_DECREF(fieldlist);
 			return -1;
 		}
-		assert(Py_Type(new_descr) == &CField_Type);
+		assert(Py_TYPE(new_descr) == &CField_Type);
  		new_descr->size = fdescr->size;
  		new_descr->offset = fdescr->offset + offset;
  		new_descr->index = fdescr->index + index;
@@ -254,7 +254,7 @@
 			Py_DECREF(anon_names);
 			return -1;
 		}
-		assert(Py_Type(descr) == &CField_Type);
+		assert(Py_TYPE(descr) == &CField_Type);
 		descr->anonymous = 1;
 
 		/* descr is in the field descriptor. */
@@ -311,7 +311,7 @@
 
 	isPacked = PyObject_GetAttrString(type, "_pack_");
 	if (isPacked) {
-		pack = PyInt_AsLong(isPacked);
+		pack = PyLong_AsLong(isPacked);
 		if (pack < 0 || PyErr_Occurred()) {
 			Py_XDECREF(isPacked);
 			PyErr_SetString(PyExc_ValueError,
@@ -402,6 +402,8 @@
 			return -1;
 		}
 		stgdict->ffi_type_pointer.elements[ffi_ofs + i] = &dict->ffi_type_pointer;
+		if (dict->flags & (TYPEFLAG_ISPOINTER | TYPEFLAG_HASPOINTER))
+			stgdict->flags |= TYPEFLAG_HASPOINTER;
 		dict->flags |= DICTFLAG_FINAL; /* mark field type final */
 		if (PyTuple_Size(pair) == 3) { /* bits specified */
 			switch(dict->ffi_type_pointer.type) {
@@ -458,7 +460,7 @@
 			Py_DECREF(pair);
 			return -1;
 		}
-		if (-1 == PyDict_SetItem(realdict, name, prop)) {
+		if (-1 == PyObject_SetAttr(type, name, prop)) {
 			Py_DECREF(prop);
 			Py_DECREF(pair);
 			return -1;

Modified: python/branches/py3k-importlib/Modules/_curses_panel.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_curses_panel.c	(original)
+++ python/branches/py3k-importlib/Modules/_curses_panel.c	Thu Mar 27 00:48:05 2008
@@ -56,7 +56,7 @@
 
 PyTypeObject PyCursesPanel_Type;
 
-#define PyCursesPanel_Check(v)	 (Py_Type(v) == &PyCursesPanel_Type)
+#define PyCursesPanel_Check(v)	 (Py_TYPE(v) == &PyCursesPanel_Type)
 
 /* Some helper functions. The problem is that there's always a window
    associated with a panel. To ensure that Python's GC doesn't pull
@@ -457,7 +457,7 @@
     PyObject *m, *d, *v;
 
     /* Initialize object type */
-    Py_Type(&PyCursesPanel_Type) = &PyType_Type;
+    Py_TYPE(&PyCursesPanel_Type) = &PyType_Type;
 
     import_curses();
 

Modified: python/branches/py3k-importlib/Modules/_cursesmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_cursesmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/_cursesmodule.c	Thu Mar 27 00:48:05 2008
@@ -196,8 +196,13 @@
 static int 
 PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
 {
-  if (PyInt_CheckExact(obj)) {
-    *ch = (chtype) PyInt_AsLong(obj);
+  if (PyLong_CheckExact(obj)) {
+    int overflow;
+    /* XXX should the truncation by the cast also be reported
+       as an error? */
+    *ch = (chtype) PyLong_AsLongAndOverflow(obj, &overflow);
+    if (overflow)
+      return 0;
   } else if(PyString_Check(obj) 
 	    && (PyString_Size(obj) == 1)) {
     *ch = (chtype) *PyString_AsString(obj);
@@ -317,9 +322,6 @@
 Window_NoArg2TupleReturnFunction(getmaxyx, int, "ii")
 Window_NoArg2TupleReturnFunction(getparyx, int, "ii")
 
-Window_OneArgNoReturnFunction(wattron, attr_t, "l;attr")
-Window_OneArgNoReturnFunction(wattroff, attr_t, "l;attr")
-Window_OneArgNoReturnFunction(wattrset, attr_t, "l;attr")
 Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
 Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
 #if defined(__NetBSD__)
@@ -374,6 +376,7 @@
   PyObject *temp;
   chtype ch = 0;
   attr_t attr = A_NORMAL;
+  long lattr;
   
   switch (PyTuple_Size(args)) {
   case 1:
@@ -381,8 +384,9 @@
 	  return NULL;
     break;
   case 2:
-    if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &attr))
+    if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
       return NULL;
+    attr = lattr;
     break;
   case 3:
     if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
@@ -391,8 +395,9 @@
     break;
   case 4:
     if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", 
-		     &y, &x, &temp, &attr))
+		     &y, &x, &temp, &lattr))
       return NULL;
+    attr = lattr;
     use_xy = TRUE;
     break;
   default:
@@ -420,6 +425,7 @@
   int x, y;
   char *str;
   attr_t attr = A_NORMAL , attr_old = A_NORMAL;
+  long lattr;
   int use_xy = FALSE, use_attr = FALSE;
 
   switch (PyTuple_Size(args)) {
@@ -428,8 +434,9 @@
       return NULL;
     break;
   case 2:
-    if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &attr))
+    if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr))
       return NULL;
+    attr = lattr;
     use_attr = TRUE;
     break;
   case 3:
@@ -438,8 +445,9 @@
     use_xy = TRUE;
     break;
   case 4:
-    if (!PyArg_ParseTuple(args,"iisl;int,int,str,attr", &y, &x, &str, &attr))
+    if (!PyArg_ParseTuple(args,"iisl;int,int,str,attr", &y, &x, &str, &lattr))
       return NULL;
+    attr = lattr;
     use_xy = use_attr = TRUE;
     break;
   default:
@@ -466,6 +474,7 @@
   int rtn, x, y, n;
   char *str;
   attr_t attr = A_NORMAL , attr_old = A_NORMAL;
+  long lattr;
   int use_xy = FALSE, use_attr = FALSE;
 
   switch (PyTuple_Size(args)) {
@@ -474,8 +483,9 @@
       return NULL;
     break;
   case 3:
-    if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &attr))
+    if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr))
       return NULL;
+    attr = lattr;
     use_attr = TRUE;
     break;
   case 4:
@@ -484,8 +494,9 @@
     use_xy = TRUE;
     break;
   case 5:
-    if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &attr))
+    if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr))
       return NULL;
+    attr = lattr;
     use_xy = use_attr = TRUE;
     break;
   default:
@@ -512,6 +523,7 @@
   PyObject *temp;
   chtype bkgd;
   attr_t attr = A_NORMAL;
+  long lattr;
 
   switch (PyTuple_Size(args)) {
     case 1:
@@ -519,8 +531,9 @@
         return NULL;
       break;
     case 2:
-      if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr))
+      if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
         return NULL;
+      attr = lattr;
       break;
     default:
       PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
@@ -536,11 +549,39 @@
 }
 
 static PyObject *
+PyCursesWindow_AttrOff(PyCursesWindowObject *self, PyObject *args)
+{
+  long lattr;
+  if (!PyArg_ParseTuple(args,"l;attr", &lattr))
+    return NULL;
+  return PyCursesCheckERR(wattroff(self->win, (attr_t)lattr), "attroff");
+}
+
+static PyObject *
+PyCursesWindow_AttrOn(PyCursesWindowObject *self, PyObject *args)
+{
+  long lattr;
+  if (!PyArg_ParseTuple(args,"l;attr", &lattr))
+    return NULL;
+  return PyCursesCheckERR(wattron(self->win, (attr_t)lattr), "attron");
+}
+
+static PyObject *
+PyCursesWindow_AttrSet(PyCursesWindowObject *self, PyObject *args)
+{
+  long lattr;
+  if (!PyArg_ParseTuple(args,"l;attr", &lattr))
+    return NULL;
+  return PyCursesCheckERR(wattrset(self->win, (attr_t)lattr), "attrset");
+}
+
+static PyObject *
 PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args)
 {
   PyObject *temp;
   chtype bkgd;
   attr_t attr = A_NORMAL;
+  long lattr;
 
   switch (PyTuple_Size(args)) {
     case 1:
@@ -548,8 +589,9 @@
         return NULL;
       break;
     case 2:
-      if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr))
+      if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
         return NULL;
+      attr = lattr;
       break;
     default:
       PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
@@ -635,25 +677,30 @@
   int num = -1;
   short color;
   attr_t attr = A_NORMAL;
+  long lattr;
   int use_xy = FALSE;
 
   switch (PyTuple_Size(args)) {
   case 1:
-    if (!PyArg_ParseTuple(args,"l;attr", &attr))
+    if (!PyArg_ParseTuple(args,"l;attr", &lattr))
       return NULL;
+    attr = lattr;
     break;
   case 2:
-    if (!PyArg_ParseTuple(args,"il;n,attr", &num, &attr))
+    if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr))
       return NULL;
+    attr = lattr;
     break;
   case 3:
-    if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &attr))
+    if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr))
       return NULL;
+    attr = lattr;
     use_xy = TRUE;
     break;
   case 4:
-    if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &attr))
+    if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr))
       return NULL;
+    attr = lattr;
     use_xy = TRUE;
     break;
   default:
@@ -737,6 +784,7 @@
   PyObject *temp;
   chtype ch;
   attr_t attr = A_NORMAL;
+  long lattr;
 
   switch (PyTuple_Size(args)) {
   case 1:
@@ -744,8 +792,9 @@
       return NULL;
     break;
   case 2:
-    if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr))
+    if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
       return NULL;
+    attr = lattr;
     break;
   default:
     PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
@@ -777,14 +826,14 @@
 	if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
 		return NULL;
 
-	return PyInt_FromLong( wenclose(self->win,y,x) );
+	return PyLong_FromLong( wenclose(self->win,y,x) );
 }
 #endif
 
 static PyObject *
 PyCursesWindow_GetBkgd(PyCursesWindowObject *self)
 {
-  return PyInt_FromLong((long) getbkgd(self->win));
+  return PyLong_FromLong((long) getbkgd(self->win));
 }
 
 static PyObject *
@@ -810,7 +859,7 @@
     PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
     return NULL;
   }
-  return PyInt_FromLong((long)rtn);
+  return PyLong_FromLong((long)rtn);
 }
 
 static PyObject *
@@ -911,6 +960,7 @@
   chtype ch;
   int n, x, y, code = OK;
   attr_t attr = A_NORMAL;
+  long lattr;
 
   switch (PyTuple_Size(args)) {
   case 2:
@@ -918,8 +968,9 @@
       return NULL;
     break;
   case 3:
-    if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &attr))
+    if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
       return NULL;
+    attr = lattr;
     break;
   case 4:
     if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
@@ -928,8 +979,9 @@
     break;
   case 5:
     if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", 
-		     &y, &x, &temp, &n, &attr))
+		     &y, &x, &temp, &n, &lattr))
       return NULL;
+    attr = lattr;
     code = wmove(self->win, y, x);
     break;
   default:
@@ -955,6 +1007,7 @@
   PyObject *temp;
   chtype ch = 0;
   attr_t attr = A_NORMAL;
+  long lattr;
   
   switch (PyTuple_Size(args)) {
   case 1:
@@ -962,8 +1015,9 @@
       return NULL;
     break;
   case 2:
-    if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &attr))
+    if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
       return NULL;
+    attr = lattr;
     break;
   case 3:
     if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
@@ -971,8 +1025,9 @@
     use_xy = TRUE;
     break;
   case 4:
-    if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &attr))
+    if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &lattr))
       return NULL;
+    attr = lattr;
     use_xy = TRUE;
     break;
   default:
@@ -1012,7 +1067,7 @@
     PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
     return NULL;
   }
-  return PyInt_FromLong((long) rtn);
+  return PyLong_FromLong((long) rtn);
 }
 
 static PyObject *
@@ -1057,6 +1112,7 @@
   int x, y;
   char *str;
   attr_t attr = A_NORMAL , attr_old = A_NORMAL;
+  long lattr;
   int use_xy = FALSE, use_attr = FALSE;
 
   switch (PyTuple_Size(args)) {
@@ -1065,8 +1121,9 @@
       return NULL;
     break;
   case 2:
-    if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &attr))
+    if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr))
       return NULL;
+    attr = lattr;
     use_attr = TRUE;
     break;
   case 3:
@@ -1075,8 +1132,9 @@
     use_xy = TRUE;
     break;
   case 4:
-    if (!PyArg_ParseTuple(args,"iisl;y,x,str,attr", &y, &x, &str, &attr))
+    if (!PyArg_ParseTuple(args,"iisl;y,x,str,attr", &y, &x, &str, &lattr))
       return NULL;
+    attr = lattr;
     use_xy = use_attr = TRUE;
     break;
   default:
@@ -1103,6 +1161,7 @@
   int rtn, x, y, n;
   char *str;
   attr_t attr = A_NORMAL , attr_old = A_NORMAL;
+  long lattr;
   int use_xy = FALSE, use_attr = FALSE;
 
   switch (PyTuple_Size(args)) {
@@ -1111,8 +1170,9 @@
       return NULL;
     break;
   case 3:
-    if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &attr))
+    if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr))
       return NULL;
+    attr = lattr;
     use_attr = TRUE;
     break;
   case 4:
@@ -1121,8 +1181,9 @@
     use_xy = TRUE;
     break;
   case 5:
-    if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &attr))
+    if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr))
       return NULL;
+    attr = lattr;
     use_xy = use_attr = TRUE;
     break;
   default:
@@ -1465,6 +1526,7 @@
   chtype ch;
   int n, x, y, code = OK;
   attr_t attr = A_NORMAL;
+  long lattr;
 
   switch (PyTuple_Size(args)) {
   case 2:
@@ -1472,8 +1534,9 @@
       return NULL;
     break;
   case 3:
-    if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &attr))
+    if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
       return NULL;
+    attr = lattr;
     break;
   case 4:
     if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
@@ -1482,8 +1545,9 @@
     break;
   case 5:
     if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", 
-		     &y, &x, &temp, &n, &attr))
+		     &y, &x, &temp, &n, &lattr))
       return NULL;
+    attr = lattr;
     code = wmove(self->win, y, x);
     break;
   default:
@@ -1506,9 +1570,9 @@
 	{"addch",           (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS},
 	{"addnstr",         (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS},
 	{"addstr",          (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS},
-	{"attroff",         (PyCFunction)PyCursesWindow_wattroff, METH_VARARGS},
-	{"attron",          (PyCFunction)PyCursesWindow_wattron, METH_VARARGS},
-	{"attrset",         (PyCFunction)PyCursesWindow_wattrset, METH_VARARGS},
+	{"attroff",         (PyCFunction)PyCursesWindow_AttrOff, METH_VARARGS},
+	{"attron",          (PyCFunction)PyCursesWindow_AttrOn, METH_VARARGS},
+	{"attrset",         (PyCFunction)PyCursesWindow_AttrSet, METH_VARARGS},
 	{"bkgd",            (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS},
 	{"chgat",           (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS},
 	{"bkgdset",         (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS},
@@ -1647,11 +1711,20 @@
 NoArgTrueFalseFunction(has_ic)
 NoArgTrueFalseFunction(has_il)
 NoArgTrueFalseFunction(isendwin)
-NoArgNoReturnVoidFunction(filter)
 NoArgNoReturnVoidFunction(flushinp)
 NoArgNoReturnVoidFunction(noqiflush)
 
 static PyObject *
+PyCurses_filter(PyObject *self)
+{
+  /* not checking for PyCursesInitialised here since filter() must
+     be called before initscr() */
+  filter();
+  Py_INCREF(Py_None);
+  return Py_None;
+}
+
+static PyObject *
 PyCurses_Color_Content(PyObject *self, PyObject *args)
 {
   short color,r,g,b;
@@ -1679,7 +1752,7 @@
   PyCursesInitialisedColor
 
   if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL;
-  return PyInt_FromLong((long) (n << 8));
+  return PyLong_FromLong((long) (n << 8));
 }
 
 static PyObject *
@@ -1694,7 +1767,7 @@
   erg = curs_set(vis);
   if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
 
-  return PyInt_FromLong((long) erg);
+  return PyLong_FromLong((long) erg);
 }
 
 static PyObject *
@@ -1796,7 +1869,7 @@
     remove(fn);
     return NULL;
   }
-  if (!PyBytes_Check(data)) {
+  if (!PyString_Check(data)) {
     PyErr_Format(PyExc_TypeError,
                  "f.read() returned %.100s instead of bytes",
                  data->ob_type->tp_name);
@@ -1805,7 +1878,7 @@
     remove(fn);
     return NULL;
   }
-  fwrite(PyBytes_AS_STRING(data), 1, PyBytes_GET_SIZE(data), fp);
+  fwrite(PyString_AS_STRING(data), 1, PyString_GET_SIZE(data), fp);
   Py_DECREF(data);
   fseek(fp, 0, 0);
   win = getwin(fp);
@@ -1912,7 +1985,7 @@
    where they're not defined until you've called initscr() */
 #define SetDictInt(string,ch) \
     do {							\
-	PyObject *o = PyInt_FromLong((long) (ch));		\
+	PyObject *o = PyLong_FromLong((long) (ch));		\
 	if (o && PyDict_SetItemString(ModDict, string, o) == 0)	{ \
 	    Py_DECREF(o);					\
 	}							\
@@ -2010,7 +2083,7 @@
 
 		sys_stdout = PySys_GetObject("stdout");
 
-		if (sys_stdout == NULL) {
+		if (sys_stdout == NULL || sys_stdout == Py_None) {
 			PyErr_SetString(
 				PyCursesError,
 				"lost sys.stdout");
@@ -2269,7 +2342,7 @@
     return NULL;
   }
 
-  return PyInt_FromLong((long) ((n & A_COLOR) >> 8));
+  return PyLong_FromLong((long) ((n & A_COLOR) >> 8));
 }
 
 static PyObject *
@@ -2311,12 +2384,12 @@
 update_lines_cols(void)
 {
   PyObject *o;
-  PyObject *m = PyImport_ImportModule("curses");
+  PyObject *m = PyImport_ImportModuleNoBlock("curses");
 
   if (!m)
     return 0;
 
-  o = PyInt_FromLong(LINES);
+  o = PyLong_FromLong(LINES);
   if (!o) {
     Py_DECREF(m);
     return 0;
@@ -2332,7 +2405,7 @@
     return 0;
   }
   Py_DECREF(o);
-  o = PyInt_FromLong(COLS);
+  o = PyLong_FromLong(COLS);
   if (!o) {
     Py_DECREF(m);
     return 0;
@@ -2429,10 +2502,10 @@
   code = start_color();
   if (code != ERR) {
     initialisedcolors = TRUE;
-    c = PyInt_FromLong((long) COLORS);
+    c = PyLong_FromLong((long) COLORS);
     PyDict_SetItemString(ModDict, "COLORS", c);
     Py_DECREF(c);
-    cp = PyInt_FromLong((long) COLOR_PAIRS);
+    cp = PyLong_FromLong((long) COLOR_PAIRS);
     PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
     Py_DECREF(cp);
     Py_INCREF(Py_None);
@@ -2453,7 +2526,7 @@
 	if (!PyArg_ParseTuple(args, "z", &capname))
 		return NULL;
 
-	return PyInt_FromLong( (long) tigetflag( capname ) );
+	return PyLong_FromLong( (long) tigetflag( capname ) );
 }
 
 static PyObject *
@@ -2466,7 +2539,7 @@
 	if (!PyArg_ParseTuple(args, "z", &capname))
 		return NULL;
 
-	return PyInt_FromLong( (long) tigetnum( capname ) );
+	return PyLong_FromLong( (long) tigetnum( capname ) );
 }
 
 static PyObject *
@@ -2704,7 +2777,7 @@
 	static void *PyCurses_API[PyCurses_API_pointers];
 
 	/* Initialize object type */
-	Py_Type(&PyCursesWindow_Type) = &PyType_Type;
+	Py_TYPE(&PyCursesWindow_Type) = &PyType_Type;
 
 	/* Initialize the C API pointer array */
 	PyCurses_API[0] = (void *)&PyCursesWindow_Type;

Modified: python/branches/py3k-importlib/Modules/_elementtree.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_elementtree.c	(original)
+++ python/branches/py3k-importlib/Modules/_elementtree.c	Thu Mar 27 00:48:05 2008
@@ -248,7 +248,7 @@
 
 static PyTypeObject Element_Type;
 
-#define Element_CheckExact(op) (Py_Type(op) == &Element_Type)
+#define Element_CheckExact(op) (Py_TYPE(op) == &Element_Type)
 
 /* -------------------------------------------------------------------- */
 /* element constructor and destructor */
@@ -348,7 +348,17 @@
     if (size > self->extra->allocated) {
         /* use Python 2.4's list growth strategy */
         size = (size >> 3) + (size < 9 ? 3 : 6) + size;
+        /* Coverity CID #182 size_error: Allocating 1 bytes to pointer "children"
+         * which needs at least 4 bytes. 
+         * Although it's a false alarm always assume at least one child to 
+         * be safe.
+         */
+        size = size ? size : 1;
         if (self->extra->children != self->extra->_children) {
+            /* Coverity CID #182 size_error: Allocating 1 bytes to pointer
+             * "children", which needs at least 4 bytes. Although it's a 
+             * false alarm always assume at least one child to be safe.
+             */
             children = PyObject_Realloc(self->extra->children,
                                         size * sizeof(PyObject*));
             if (!children)
@@ -677,7 +687,7 @@
     }
 
     /* add object to memo dictionary (so deepcopy won't visit it again) */
-    id = PyInt_FromLong((Py_uintptr_t) self);
+    id = PyLong_FromLong((Py_uintptr_t) self);
 
     i = PyDict_SetItem(memo, id, (PyObject*) element);
 
@@ -1174,7 +1184,7 @@
         /* FIXME: support arbitrary sequences? */
         PyErr_Format(
             PyExc_TypeError,
-            "expected list, not \"%.200s\"", Py_Type(item)->tp_name
+            "expected list, not \"%.200s\"", Py_TYPE(item)->tp_name
             );
         return -1;
     }
@@ -1407,7 +1417,7 @@
 
 static PyTypeObject TreeBuilder_Type;
 
-#define TreeBuilder_CheckExact(op) (Py_Type(op) == &TreeBuilder_Type)
+#define TreeBuilder_CheckExact(op) (Py_TYPE(op) == &TreeBuilder_Type)
 
 /* -------------------------------------------------------------------- */
 /* constructor and destructor */
@@ -1574,7 +1584,7 @@
         Py_INCREF(data); self->data = data;
     } else {
         /* more than one item; use a list to collect items */
-        if (PyString_CheckExact(self->data) && Py_Refcnt(self->data) == 1 &&
+        if (PyString_CheckExact(self->data) && Py_REFCNT(self->data) == 1 &&
             PyString_CheckExact(data) && PyString_GET_SIZE(data) == 1) {
             /* expat often generates single character data sections; handle
                the most common case by resizing the existing string... */
@@ -2550,9 +2560,9 @@
 #endif
 
     /* Patch object type */
-    Py_Type(&Element_Type) = Py_Type(&TreeBuilder_Type) = &PyType_Type;
+    Py_TYPE(&Element_Type) = Py_TYPE(&TreeBuilder_Type) = &PyType_Type;
 #if defined(USE_EXPAT)
-    Py_Type(&XMLParser_Type) = &PyType_Type;
+    Py_TYPE(&XMLParser_Type) = &PyType_Type;
 #endif
 
     m = Py_InitModule("_elementtree", _functions);

Modified: python/branches/py3k-importlib/Modules/_fileio.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_fileio.c	(original)
+++ python/branches/py3k-importlib/Modules/_fileio.c	Thu Mar 27 00:48:05 2008
@@ -33,6 +33,7 @@
 	unsigned readable : 1;
 	unsigned writable : 1;
 	int seekable : 2; /* -1 means unknown */
+	int closefd : 1;
 	PyObject *weakreflist;
 } PyFileIOObject;
 
@@ -59,6 +60,13 @@
 static PyObject *
 fileio_close(PyFileIOObject *self)
 {
+	if (!self->closefd) {
+		if (PyErr_WarnEx(PyExc_RuntimeWarning,
+				 "Trying to close unclosable fd!", 3) < 0) {
+			return NULL;
+		}
+		Py_RETURN_NONE;
+	}
 	errno = internal_close(self);
 	if (errno < 0) {
 		PyErr_SetFromErrno(PyExc_IOError);
@@ -96,11 +104,7 @@
 	if (self->fd < 0)
 		return 0;
 	if (fstat(self->fd, &buf) == 0 && S_ISDIR(buf.st_mode)) {
-#ifdef HAVE_STRERROR
 		char *msg = strerror(EISDIR);
-#else
-		char *msg = "Is a directory";
-#endif
 		PyObject *exc;
 		internal_close(self);
 
@@ -119,7 +123,7 @@
 fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
 {
 	PyFileIOObject *self = (PyFileIOObject *) oself;
-	static char *kwlist[] = {"file", "mode", NULL};
+	static char *kwlist[] = {"file", "mode", "closefd", NULL};
 	char *name = NULL;
 	char *mode = "r";
 	char *s;
@@ -130,6 +134,7 @@
 	int rwa = 0, plus = 0, append = 0;
 	int flags = 0;
 	int fd = -1;
+	int closefd = 1;
 
 	assert(PyFileIO_Check(oself));
 	if (self->fd >= 0) {
@@ -138,8 +143,8 @@
 			return -1;
 	}
 
-	if (PyArg_ParseTupleAndKeywords(args, kwds, "i|s:fileio",
-					kwlist, &fd, &mode)) {
+	if (PyArg_ParseTupleAndKeywords(args, kwds, "i|si:fileio",
+					kwlist, &fd, &mode, &closefd)) {
 		if (fd < 0) {
 			PyErr_SetString(PyExc_ValueError,
 					"Negative filedescriptor");
@@ -153,8 +158,9 @@
 	    if (GetVersion() < 0x80000000) {
 		/* On NT, so wide API available */
 		PyObject *po;
-		if (PyArg_ParseTupleAndKeywords(args, kwds, "U|s:fileio",
-						kwlist, &po, &mode)) {
+		if (PyArg_ParseTupleAndKeywords(args, kwds, "U|si:fileio",
+						kwlist, &po, &mode, &closefd)
+						) {
 			widename = PyUnicode_AS_UNICODE(po);
 		} else {
 			/* Drop the argument parsing error as narrow
@@ -162,13 +168,13 @@
 			PyErr_Clear();
 		}
 	    }
-	    if (widename == NULL) 
+	    if (widename == NULL)
 #endif
 	    {
-		if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|s:fileio",
+		if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|si:fileio",
 						 kwlist,
 						 Py_FileSystemDefaultEncoding,
-						 &name, &mode))
+						 &name, &mode, &closefd))
 			goto error;
 	    }
 	}
@@ -237,8 +243,16 @@
 
 	if (fd >= 0) {
 		self->fd = fd;
+		self->closefd = closefd;
 	}
 	else {
+		self->closefd = 1;
+		if (!closefd) {
+			PyErr_SetString(PyExc_ValueError,
+                            "Cannot use closefd=True with file name");
+			goto error;
+		}
+
 		Py_BEGIN_ALLOW_THREADS
 		errno = 0;
 #ifdef MS_WINDOWS
@@ -249,7 +263,11 @@
 			self->fd = open(name, flags, 0666);
 		Py_END_ALLOW_THREADS
 		if (self->fd < 0 || dircheck(self) < 0) {
+#ifdef MS_WINDOWS
+			PyErr_SetFromErrnoWithUnicodeFilename(PyExc_IOError, widename);
+#else
 			PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
+#endif
 			goto error;
 		}
 	}
@@ -270,19 +288,15 @@
 	if (self->weakreflist != NULL)
 		PyObject_ClearWeakRefs((PyObject *) self);
 
-	if (self->fd >= 0) {
+	if (self->fd >= 0 && self->closefd) {
 		errno = internal_close(self);
 		if (errno < 0) {
-#ifdef HAVE_STRERROR
 			PySys_WriteStderr("close failed: [Errno %d] %s\n",
                                           errno, strerror(errno));
-#else
-			PySys_WriteStderr("close failed: [Errno %d]\n", errno);
-#endif
 		}
 	}
 
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *
@@ -304,7 +318,7 @@
 {
 	if (self->fd < 0)
 		return err_closed();
-	return PyInt_FromLong((long) self->fd);
+	return PyLong_FromLong((long) self->fd);
 }
 
 static PyObject *
@@ -366,7 +380,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromSsize_t(n);
+	return PyLong_FromSsize_t(n);
 }
 
 #define DEFAULT_BUFFER_SIZE (8*1024)
@@ -378,14 +392,14 @@
 	Py_ssize_t total = 0;
 	int n;
 
-	result = PyBytes_FromStringAndSize(NULL, DEFAULT_BUFFER_SIZE);
+	result = PyString_FromStringAndSize(NULL, DEFAULT_BUFFER_SIZE);
 	if (result == NULL)
 		return NULL;
 
 	while (1) {
 		Py_ssize_t newsize = total + DEFAULT_BUFFER_SIZE;
-		if (PyBytes_GET_SIZE(result) < newsize) {
-			if (PyBytes_Resize(result, newsize) < 0) {
+		if (PyString_GET_SIZE(result) < newsize) {
+			if (_PyString_Resize(&result, newsize) < 0) {
 				if (total == 0) {
 					Py_DECREF(result);
 					return NULL;
@@ -397,7 +411,7 @@
 		Py_BEGIN_ALLOW_THREADS
 		errno = 0;
 		n = read(self->fd,
-			 PyBytes_AS_STRING(result) + total,
+			 PyString_AS_STRING(result) + total,
 			 newsize - total);
 		Py_END_ALLOW_THREADS
 		if (n == 0)
@@ -416,8 +430,8 @@
 		total += n;
 	}
 
-	if (PyBytes_GET_SIZE(result) > total) {
-		if (PyBytes_Resize(result, total) < 0) {
+	if (PyString_GET_SIZE(result) > total) {
+		if (_PyString_Resize(&result, total) < 0) {
 			/* This should never happen, but just in case */
 			Py_DECREF(result);
 			return NULL;
@@ -446,10 +460,10 @@
 		return fileio_readall(self);
 	}
 
-	bytes = PyBytes_FromStringAndSize(NULL, size);
+	bytes = PyString_FromStringAndSize(NULL, size);
 	if (bytes == NULL)
 		return NULL;
-	ptr = PyBytes_AsString(bytes);
+	ptr = PyString_AS_STRING(bytes);
 
 	Py_BEGIN_ALLOW_THREADS
 	errno = 0;
@@ -464,7 +478,7 @@
 	}
 
 	if (n != size) {
-		if (PyBytes_Resize(bytes, n) < 0) {
+		if (_PyString_Resize(&bytes, n) < 0) {
 			Py_DECREF(bytes);
 			return NULL;
 		}
@@ -499,7 +513,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromSsize_t(n);
+	return PyLong_FromSsize_t(n);
 }
 
 /* XXX Windows support below is likely incomplete */
@@ -534,11 +548,15 @@
 	if (posobj == NULL)
 		pos = 0;
 	else {
+		if(PyFloat_Check(posobj)) {
+			PyErr_SetString(PyExc_TypeError, "an integer is required");
+			return NULL;
+		}
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-		pos = PyInt_AsLong(posobj);
+		pos = PyLong_AsLong(posobj);
 #else
 		pos = PyLong_Check(posobj) ?
-			PyLong_AsLongLong(posobj) : PyInt_AsLong(posobj);
+			PyLong_AsLongLong(posobj) : PyLong_AsLong(posobj);
 #endif
 		if (PyErr_Occurred())
 			return NULL;
@@ -555,7 +573,7 @@
 		return PyErr_SetFromErrno(PyExc_IOError);
 
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-	return PyInt_FromLong(res);
+	return PyLong_FromLong(res);
 #else
 	return PyLong_FromLongLong(res);
 #endif
@@ -613,10 +631,10 @@
         }
 
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-	pos = PyInt_AsLong(posobj);
+	pos = PyLong_AsLong(posobj);
 #else
 	pos = PyLong_Check(posobj) ?
-		PyLong_AsLongLong(posobj) : PyInt_AsLong(posobj);
+		PyLong_AsLongLong(posobj) : PyLong_AsLong(posobj);
 #endif
 	if (PyErr_Occurred()) {
 		Py_DECREF(posobj);
@@ -628,14 +646,21 @@
 	   so don't even try using it. */
 	{
 		HANDLE hFile;
-		PyObject *pos2;
+		PyObject *pos2, *oldposobj;
+
+		/* store the current position */
+		oldposobj = portable_lseek(self->fd, NULL, 1);
+		if (oldposobj == NULL) {
+			Py_DECREF(posobj);
+			return NULL;
+		}
 
 		/* Have to move current pos to desired endpoint on Windows. */
 		errno = 0;
 		pos2 = portable_lseek(fd, posobj, SEEK_SET);
-		if (pos2 == NULL)
-		{
+		if (pos2 == NULL) {
 			Py_DECREF(posobj);
+			Py_DECREF(oldposobj);
 			return NULL;
 		}
 		Py_DECREF(pos2);
@@ -651,6 +676,18 @@
 				errno = EACCES;
 		}
 		Py_END_ALLOW_THREADS
+
+		if (ret == 0) {
+			/* Move to the previous position in the file */
+			pos2 = portable_lseek(fd, oldposobj, SEEK_SET);
+			if (pos2 == NULL) {
+				Py_DECREF(posobj);
+				Py_DECREF(oldposobj);
+				return NULL;
+			}
+		}
+		Py_DECREF(pos2);
+		Py_DECREF(oldposobj);
 	}
 #else
 	Py_BEGIN_ALLOW_THREADS
@@ -822,7 +859,7 @@
 
 PyTypeObject PyFileIO_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"FileIO",
+	"_FileIO",
 	sizeof(PyFileIOObject),
 	0,
 	(destructor)fileio_dealloc,		/* tp_dealloc */

Modified: python/branches/py3k-importlib/Modules/_functoolsmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_functoolsmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/_functoolsmodule.c	Thu Mar 27 00:48:05 2008
@@ -81,7 +81,7 @@
 	Py_XDECREF(pto->args);
 	Py_XDECREF(pto->kw);
 	Py_XDECREF(pto->dict);
-	Py_Type(pto)->tp_free(pto);
+	Py_TYPE(pto)->tp_free(pto);
 }
 
 static PyObject *

Modified: python/branches/py3k-importlib/Modules/_hashopenssl.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_hashopenssl.c	(original)
+++ python/branches/py3k-importlib/Modules/_hashopenssl.c	Thu Mar 27 00:48:05 2008
@@ -108,7 +108,7 @@
     digest_size = EVP_MD_CTX_size(&temp_ctx);
     EVP_DigestFinal(&temp_ctx, digest, NULL);
 
-    retval = PyBytes_FromStringAndSize((const char *)digest, digest_size);
+    retval = PyString_FromStringAndSize((const char *)digest, digest_size);
     EVP_MD_CTX_cleanup(&temp_ctx);
     return retval;
 }
@@ -203,13 +203,13 @@
 static PyObject *
 EVP_get_block_size(EVPobject *self, void *closure)
 {
-    return PyInt_FromLong(EVP_MD_CTX_block_size(&((EVPobject *)self)->ctx));
+    return PyLong_FromLong(EVP_MD_CTX_block_size(&((EVPobject *)self)->ctx));
 }
 
 static PyObject *
 EVP_get_digest_size(EVPobject *self, void *closure)
 {
-    return PyInt_FromLong(EVP_MD_CTX_size(&((EVPobject *)self)->ctx));
+    return PyLong_FromLong(EVP_MD_CTX_size(&((EVPobject *)self)->ctx));
 }
 
 static PyMemberDef EVP_members[] = {
@@ -510,7 +510,7 @@
      * but having some be unsupported.  Only init appropriate
      * constants. */
 
-    Py_Type(&EVPtype) = &PyType_Type;
+    Py_TYPE(&EVPtype) = &PyType_Type;
     if (PyType_Ready(&EVPtype) < 0)
         return;
 

Modified: python/branches/py3k-importlib/Modules/_heapqmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_heapqmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/_heapqmodule.c	Thu Mar 27 00:48:05 2008
@@ -196,6 +196,48 @@
             item = heapreplace(heap, item)\n");
 
 static PyObject *
+heappushpop(PyObject *self, PyObject *args)
+{
+	PyObject *heap, *item, *returnitem;
+	int cmp;
+
+	if (!PyArg_UnpackTuple(args, "heappushpop", 2, 2, &heap, &item))
+		return NULL;
+
+	if (!PyList_Check(heap)) {
+		PyErr_SetString(PyExc_TypeError, "heap argument must be a list");
+		return NULL;
+	}
+
+	if (PyList_GET_SIZE(heap) < 1) {
+		Py_INCREF(item);
+		return item;
+	}
+
+	cmp = PyObject_RichCompareBool(item, PyList_GET_ITEM(heap, 0), Py_LE);
+	if (cmp == -1)
+		return NULL;
+	if (cmp == 1) {
+		Py_INCREF(item);
+		return item;
+	}
+
+	returnitem = PyList_GET_ITEM(heap, 0);
+	Py_INCREF(item);
+	PyList_SET_ITEM(heap, 0, item);
+	if (_siftup((PyListObject *)heap, 0) == -1) {
+		Py_DECREF(returnitem);
+		return NULL;
+	}
+	return returnitem;
+}
+
+PyDoc_STRVAR(heappushpop_doc,
+"Push item on the heap, then pop and return the smallest item\n\
+from the heap. The combined action runs more efficiently than\n\
+heappush() followed by a separate call to heappop().");
+
+static PyObject *
 heapify(PyObject *self, PyObject *heap)
 {
 	Py_ssize_t i, n;
@@ -468,6 +510,8 @@
 static PyMethodDef heapq_methods[] = {
 	{"heappush",	(PyCFunction)heappush,		
 		METH_VARARGS,	heappush_doc},
+	{"heappushpop",	(PyCFunction)heappushpop,		
+		METH_VARARGS,	heappushpop_doc},
 	{"heappop",	(PyCFunction)heappop,
 		METH_O,		heappop_doc},
 	{"heapreplace",	(PyCFunction)heapreplace,

Modified: python/branches/py3k-importlib/Modules/_localemodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_localemodule.c	(original)
+++ python/branches/py3k-importlib/Modules/_localemodule.c	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright (C) 1997, 2002, 2003, 2007 Martin von Loewis
+Copyright (C) 1997, 2002, 2003, 2007, 2008 Martin von Loewis
 
 Permission to use, copy, modify, and distribute this software and its
 documentation for any purpose and without fee is hereby granted,
@@ -45,6 +45,35 @@
 
 static PyObject *Error;
 
+/* Convert a char* to a Unicode object according to the current locale */
+static PyObject*
+str2uni(const char* s)
+{
+    size_t needed = mbstowcs(NULL, s, 0);
+    size_t res1;
+    wchar_t smallbuf[30];
+    wchar_t *dest;
+    PyObject *res2;
+    if (needed == (size_t)-1) {
+        PyErr_SetString(PyExc_ValueError, "Cannot convert byte to string");
+        return NULL;
+    }
+    if (needed*sizeof(wchar_t) < sizeof(smallbuf))
+        dest = smallbuf;
+    else {
+        dest = PyMem_Malloc((needed+1)*sizeof(wchar_t));
+        if (!dest)
+            return PyErr_NoMemory();
+    }
+    /* This shouldn't fail now */
+    res1 = mbstowcs(dest, s, needed+1);
+    assert(res1 == needed);
+    res2 = PyUnicode_FromWideChar(dest, res1);
+    if (dest != smallbuf)
+        PyMem_Free(dest);
+    return res2;
+}        
+
 /* support functions for formatting floating point numbers */
 
 PyDoc_STRVAR(setlocale__doc__,
@@ -71,7 +100,7 @@
     i = -1;
     do {
         i++;
-        val = PyInt_FromLong(s[i]);
+        val = PyLong_FromLong(s[i]);
         if (!val)
             break;
         if (PyList_SetItem(result, i, val)) {
@@ -107,7 +136,7 @@
             PyErr_SetString(Error, "unsupported locale setting");
             return NULL;
         }
-        result_object = PyUnicode_FromString(result);
+        result_object = str2uni(result);
         if (!result_object)
             return NULL;
     } else {
@@ -117,7 +146,7 @@
             PyErr_SetString(Error, "locale query failed");
             return NULL;
         }
-        result_object = PyUnicode_FromString(result);
+        result_object = str2uni(result);
     }
     return result_object;
 }
@@ -143,13 +172,13 @@
        involved herein */
 
 #define RESULT_STRING(s)\
-    x = PyUnicode_FromString(l->s);\
+    x = str2uni(l->s);   \
     if (!x) goto failed;\
     PyDict_SetItemString(result, #s, x);\
     Py_XDECREF(x)
 
 #define RESULT_INT(i)\
-    x = PyInt_FromLong(l->i);\
+    x = PyLong_FromLong(l->i);\
     if (!x) goto failed;\
     PyDict_SetItemString(result, #i, x);\
     Py_XDECREF(x)
@@ -191,29 +220,19 @@
     return NULL;
 }
 
+#if defined(HAVE_WCSCOLL)
 PyDoc_STRVAR(strcoll__doc__,
 "string,string -> int. Compares two strings according to the locale.");
 
 static PyObject*
 PyLocale_strcoll(PyObject* self, PyObject* args)
 {
-#if !defined(HAVE_WCSCOLL)
-    char *s1,*s2;
-    
-    if (!PyArg_ParseTuple(args, "ss:strcoll", &s1, &s2))
-        return NULL;
-    return PyInt_FromLong(strcoll(s1, s2));
-#else
     PyObject *os1, *os2, *result = NULL;
     wchar_t *ws1 = NULL, *ws2 = NULL;
-    int len1, len2;
+    Py_ssize_t len1, len2;
     
-    if (!PyArg_UnpackTuple(args, "strcoll", 2, 2, &os1, &os2))
+    if (!PyArg_ParseTuple(args, "UU:strcoll", &os1, &os2))
         return NULL;
-    /* Both arguments must be unicode, or it's an error.  */
-    if (!PyUnicode_Check(os1) || !PyUnicode_Check(os2)) {
-        PyErr_SetString(PyExc_ValueError, "strcoll arguments must be strings");
-    }
     /* Convert the unicode strings to wchar[]. */
     len1 = PyUnicode_GET_SIZE(os1) + 1;
     ws1 = PyMem_MALLOC(len1 * sizeof(wchar_t));
@@ -234,46 +253,68 @@
         goto done;
     ws2[len2 - 1] = 0;
     /* Collate the strings. */
-    result = PyInt_FromLong(wcscoll(ws1, ws2));
+    result = PyLong_FromLong(wcscoll(ws1, ws2));
   done:
     /* Deallocate everything. */
     if (ws1) PyMem_FREE(ws1);
     if (ws2) PyMem_FREE(ws2);
     return result;
-#endif
 }
+#endif
 
-
+#ifdef HAVE_WCSXFRM
 PyDoc_STRVAR(strxfrm__doc__,
 "string -> string. Returns a string that behaves for cmp locale-aware.");
 
 static PyObject*
 PyLocale_strxfrm(PyObject* self, PyObject* args)
 {
-    char *s, *buf;
+    Py_UNICODE *s0;
+    Py_ssize_t n0;
+    wchar_t *s, *buf = NULL;
     size_t n1, n2;
-    PyObject *result;
+    PyObject *result = NULL;
+    Py_ssize_t i;
 
-    if (!PyArg_ParseTuple(args, "s:strxfrm", &s))
+    if (!PyArg_ParseTuple(args, "u#:strxfrm", &s0, &n0))
         return NULL;
 
-    /* assume no change in size, first */
-    n1 = strlen(s) + 1;
-    buf = PyMem_Malloc(n1);
-    if (!buf)
+#ifdef HAVE_USABLE_WCHAR_T
+    s = s0;
+#else
+    s = PyMem_Malloc((n0+1)*sizeof(wchar_t));
+    if (!s)
         return PyErr_NoMemory();
-    n2 = strxfrm(buf, s, n1) + 1;
-    if (n2 > n1) {
+    for (i=0; i<=n0; i++)
+        s[i] = s0[i];
+#endif
+
+    /* assume no change in size, first */
+    n1 = wcslen(s) + 1;
+    buf = PyMem_Malloc(n1*sizeof(wchar_t));
+    if (!buf) {
+        PyErr_NoMemory();
+        goto exit;
+    }
+    n2 = wcsxfrm(buf, s, n1);
+    if (n2 >= n1) {
         /* more space needed */
-        buf = PyMem_Realloc(buf, n2);
-        if (!buf)
-            return PyErr_NoMemory();
-        strxfrm(buf, s, n2);
+        buf = PyMem_Realloc(buf, (n2+1)*sizeof(wchar_t));
+        if (!buf) {
+            PyErr_NoMemory();
+            goto exit;
+        }
+        n2 = wcsxfrm(buf, s, n2);
     }
-    result = PyUnicode_FromString(buf);
-    PyMem_Free(buf);
+    result = PyUnicode_FromWideChar(buf, n2);
+ exit:
+    if (buf) PyMem_Free(buf);
+#ifdef HAVE_USABLE_WCHAR_T
+    PyMem_Free(s);
+#endif
     return result;
 }
+#endif
 
 #if defined(MS_WINDOWS)
 static PyObject*
@@ -471,8 +512,8 @@
             /* Check NULL as a workaround for GNU libc's returning NULL
                instead of an empty string for nl_langinfo(ERA).  */
             const char *result = nl_langinfo(item);
-            /* XXX may have to convert this to wcs first. */
-            return PyUnicode_FromString(result != NULL ? result : "");
+            result = result != NULL ? result : "";
+            return str2uni(result);
         }
     PyErr_SetString(PyExc_ValueError, "unsupported langinfo constant");
     return NULL;
@@ -491,7 +532,7 @@
 	char *in;
 	if (!PyArg_ParseTuple(args, "z", &in))
 		return 0;
-	return PyUnicode_FromString(gettext(in));
+	return str2uni(gettext(in));
 }
 
 PyDoc_STRVAR(dgettext__doc__,
@@ -504,7 +545,7 @@
 	char *domain, *in;
 	if (!PyArg_ParseTuple(args, "zz", &domain, &in))
 		return 0;
-	return PyUnicode_FromString(dgettext(domain, in));
+	return str2uni(dgettext(domain, in));
 }
 
 PyDoc_STRVAR(dcgettext__doc__,
@@ -518,7 +559,7 @@
 	int category;
 	if (!PyArg_ParseTuple(args, "zzi", &domain, &msgid, &category))
 		return 0;
-	return PyUnicode_FromString(dcgettext(domain,msgid,category));
+	return str2uni(dcgettext(domain,msgid,category));
 }
 
 PyDoc_STRVAR(textdomain__doc__,
@@ -536,7 +577,7 @@
 		PyErr_SetFromErrno(PyExc_OSError);
 		return NULL;
 	}
-	return PyUnicode_FromString(domain);
+	return str2uni(domain);
 }
 
 PyDoc_STRVAR(bindtextdomain__doc__,
@@ -554,7 +595,7 @@
 		PyErr_SetFromErrno(PyExc_OSError);
 		return NULL;
 	}
-	return PyUnicode_FromString(dirname);
+	return str2uni(dirname);
 }
 
 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
@@ -570,7 +611,7 @@
 		return NULL;
 	codeset = bind_textdomain_codeset(domain, codeset);
 	if (codeset)
-		return PyUnicode_FromString(codeset);
+		return str2uni(codeset);
 	Py_RETURN_NONE;
 }
 #endif
@@ -582,10 +623,14 @@
    METH_VARARGS, setlocale__doc__},
   {"localeconv", (PyCFunction) PyLocale_localeconv, 
    METH_NOARGS, localeconv__doc__},
+#ifdef HAVE_WCSCOLL
   {"strcoll", (PyCFunction) PyLocale_strcoll, 
    METH_VARARGS, strcoll__doc__},
+#endif
+#ifdef HAVE_WCSXFRM
   {"strxfrm", (PyCFunction) PyLocale_strxfrm, 
    METH_VARARGS, strxfrm__doc__},
+#endif
 #if defined(MS_WINDOWS) || defined(__APPLE__)
   {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS},
 #endif
@@ -626,37 +671,37 @@
 
     d = PyModule_GetDict(m);
 
-    x = PyInt_FromLong(LC_CTYPE);
+    x = PyLong_FromLong(LC_CTYPE);
     PyDict_SetItemString(d, "LC_CTYPE", x);
     Py_XDECREF(x);
 
-    x = PyInt_FromLong(LC_TIME);
+    x = PyLong_FromLong(LC_TIME);
     PyDict_SetItemString(d, "LC_TIME", x);
     Py_XDECREF(x);
 
-    x = PyInt_FromLong(LC_COLLATE);
+    x = PyLong_FromLong(LC_COLLATE);
     PyDict_SetItemString(d, "LC_COLLATE", x);
     Py_XDECREF(x);
 
-    x = PyInt_FromLong(LC_MONETARY);
+    x = PyLong_FromLong(LC_MONETARY);
     PyDict_SetItemString(d, "LC_MONETARY", x);
     Py_XDECREF(x);
 
 #ifdef LC_MESSAGES
-    x = PyInt_FromLong(LC_MESSAGES);
+    x = PyLong_FromLong(LC_MESSAGES);
     PyDict_SetItemString(d, "LC_MESSAGES", x);
     Py_XDECREF(x);
 #endif /* LC_MESSAGES */
 
-    x = PyInt_FromLong(LC_NUMERIC);
+    x = PyLong_FromLong(LC_NUMERIC);
     PyDict_SetItemString(d, "LC_NUMERIC", x);
     Py_XDECREF(x);
 
-    x = PyInt_FromLong(LC_ALL);
+    x = PyLong_FromLong(LC_ALL);
     PyDict_SetItemString(d, "LC_ALL", x);
     Py_XDECREF(x);
 
-    x = PyInt_FromLong(CHAR_MAX);
+    x = PyLong_FromLong(CHAR_MAX);
     PyDict_SetItemString(d, "CHAR_MAX", x);
     Py_XDECREF(x);
 

Modified: python/branches/py3k-importlib/Modules/_lsprof.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_lsprof.c	(original)
+++ python/branches/py3k-importlib/Modules/_lsprof.c	Thu Mar 27 00:48:05 2008
@@ -120,7 +120,7 @@
 static PyTypeObject PyProfiler_Type;
 
 #define PyProfiler_Check(op) PyObject_TypeCheck(op, &PyProfiler_Type)
-#define PyProfiler_CheckExact(op) (Py_Type(op) == &PyProfiler_Type)
+#define PyProfiler_CheckExact(op) (Py_TYPE(op) == &PyProfiler_Type)
 
 /*** External Timers ***/
 
@@ -179,23 +179,20 @@
 		/* built-in function: look up the module name */
 		PyObject *mod = fn->m_module;
 		const char *modname;
-		if (mod && PyString_Check(mod)) {
-			modname = PyString_AS_STRING(mod);
-		}
-		else if (mod && PyUnicode_Check(mod)) {
+		if (mod && PyUnicode_Check(mod)) {
 			modname = PyUnicode_AsString(mod);
 		}
 		else if (mod && PyModule_Check(mod)) {
 			modname = PyModule_GetName(mod);
 			if (modname == NULL) {
 				PyErr_Clear();
-				modname = "__builtin__";
+				modname = "builtins";
 			}
 		}
 		else {
-			modname = "__builtin__";
+			modname = "builtins";
 		}
-		if (strcmp(modname, "__builtin__") != 0)
+		if (strcmp(modname, "builtins") != 0)
 			return PyUnicode_FromFormat("<%s.%s>",
 						    modname,
 						    fn->m_ml->ml_name);
@@ -210,7 +207,7 @@
 		PyObject *self = fn->m_self;
 		PyObject *name = PyUnicode_FromString(fn->m_ml->ml_name);
 		if (name != NULL) {
-			PyObject *mo = _PyType_Lookup(Py_Type(self), name);
+			PyObject *mo = _PyType_Lookup(Py_TYPE(self), name);
 			Py_XINCREF(mo);
 			Py_DECREF(name);
 			if (mo != NULL) {
@@ -759,7 +756,7 @@
 	flush_unmatched(op);
 	clearEntries(op);
 	Py_XDECREF(op->externalTimer);
-	Py_Type(op)->tp_free(op);
+	Py_TYPE(op)->tp_free(op);
 }
 
 static int

Modified: python/branches/py3k-importlib/Modules/_randommodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_randommodule.c	(original)
+++ python/branches/py3k-importlib/Modules/_randommodule.c	Thu Mar 27 00:48:05 2008
@@ -84,7 +84,7 @@
 
 static PyTypeObject Random_Type;
 
-#define RandomObject_Check(v)	   (Py_Type(v) == &Random_Type)
+#define RandomObject_Check(v)	   (Py_TYPE(v) == &Random_Type)
 
 
 /* Random methods */
@@ -259,7 +259,7 @@
 	masklower = PyLong_FromUnsignedLong(0xffffffffU);
 	if (masklower == NULL)
 		goto Done;
-	thirtytwo = PyInt_FromLong(32L);
+	thirtytwo = PyLong_FromLong(32L);
 	if (thirtytwo == NULL)
 		goto Done;
 	while ((err=PyObject_IsTrue(n))) {
@@ -319,12 +319,12 @@
 	if (state == NULL)
 		return NULL;
 	for (i=0; i<N ; i++) {
-		element = PyInt_FromLong((long)(self->state[i]));
+		element = PyLong_FromUnsignedLong(self->state[i]);
 		if (element == NULL)
 			goto Fail;
 		PyTuple_SET_ITEM(state, i, element);
 	}
-	element = PyInt_FromLong((long)(self->index));
+	element = PyLong_FromLong((long)(self->index));
 	if (element == NULL)
 		goto Fail;
 	PyTuple_SET_ITEM(state, i, element);
@@ -339,7 +339,8 @@
 random_setstate(RandomObject *self, PyObject *state)
 {
 	int i;
-	long element;
+	unsigned long element;
+	long index;
 
 	if (!PyTuple_Check(state)) {
 		PyErr_SetString(PyExc_TypeError,
@@ -353,87 +354,21 @@
 	}
 
 	for (i=0; i<N ; i++) {
-		element = PyInt_AsLong(PyTuple_GET_ITEM(state, i));
+		element = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(state, i));
 		if (element == -1 && PyErr_Occurred())
 			return NULL;
-		self->state[i] = (unsigned long)element;
+		self->state[i] = element & 0xffffffffUL; /* Make sure we get sane state */
 	}
 
-	element = PyInt_AsLong(PyTuple_GET_ITEM(state, i));
-	if (element == -1 && PyErr_Occurred())
+	index = PyLong_AsLong(PyTuple_GET_ITEM(state, i));
+	if (index == -1 && PyErr_Occurred())
 		return NULL;
-	self->index = (int)element;
+	self->index = (int)index;
 
 	Py_INCREF(Py_None);
 	return Py_None;
 }
 
-/*
-Jumpahead should be a fast way advance the generator n-steps ahead, but
-lacking a formula for that, the next best is to use n and the existing
-state to create a new state far away from the original.
-
-The generator uses constant spaced additive feedback, so shuffling the
-state elements ought to produce a state which would not be encountered
-(in the near term) by calls to random().  Shuffling is normally
-implemented by swapping the ith element with another element ranging
-from 0 to i inclusive.  That allows the element to have the possibility
-of not being moved.  Since the goal is to produce a new, different
-state, the swap element is ranged from 0 to i-1 inclusive.  This assures
-that each element gets moved at least once.
-
-To make sure that consecutive calls to jumpahead(n) produce different
-states (even in the rare case of involutory shuffles), i+1 is added to
-each element at position i.  Successive calls are then guaranteed to
-have changing (growing) values as well as shuffled positions.
-
-Finally, the self->index value is set to N so that the generator itself
-kicks in on the next call to random().	This assures that all results
-have been through the generator and do not just reflect alterations to
-the underlying state.
-*/
-
-static PyObject *
-random_jumpahead(RandomObject *self, PyObject *n)
-{
-	long i, j;
-	PyObject *iobj;
-	PyObject *remobj;
-	unsigned long *mt, tmp;
-
-	if (!PyLong_Check(n)) {
-		PyErr_Format(PyExc_TypeError, "jumpahead requires an "
-			     "integer, not '%s'",
-			     Py_Type(n)->tp_name);
-		return NULL;
-	}
-
-	mt = self->state;
-	for (i = N-1; i > 1; i--) {
-		iobj = PyInt_FromLong(i);
-		if (iobj == NULL)
-			return NULL;
-		remobj = PyNumber_Remainder(n, iobj);
-		Py_DECREF(iobj);
-		if (remobj == NULL)
-			return NULL;
-		j = PyInt_AsLong(remobj);
-		Py_DECREF(remobj);
-		if (j == -1L && PyErr_Occurred())
-			return NULL;
-		tmp = mt[i];
-		mt[i] = mt[j];
-		mt[j] = tmp;
-	}
-
-	for (i = 0; i < N; i++)
-		mt[i] += i+1;
-
-	self->index = N;
-	Py_INCREF(Py_None);
-	return Py_None;
-}
-
 static PyObject *
 random_getrandbits(RandomObject *self, PyObject *args)
 {
@@ -505,9 +440,6 @@
 		PyDoc_STR("getstate() -> tuple containing the current state.")},
 	{"setstate",	  (PyCFunction)random_setstate,  METH_O,
 		PyDoc_STR("setstate(state) -> None.  Restores generator state.")},
-	{"jumpahead",	(PyCFunction)random_jumpahead,	METH_O,
-		PyDoc_STR("jumpahead(int) -> None.  Create new state from "
-			  "existing state and integer.")},
 	{"getrandbits",	(PyCFunction)random_getrandbits,  METH_VARARGS,
 		PyDoc_STR("getrandbits(k) -> x.  Generates a long int with "
 			  "k random bits.")},

Modified: python/branches/py3k-importlib/Modules/_sqlite/cache.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sqlite/cache.c	(original)
+++ python/branches/py3k-importlib/Modules/_sqlite/cache.c	Thu Mar 27 00:48:05 2008
@@ -51,7 +51,7 @@
     Py_DECREF(self->key);
     Py_DECREF(self->data);
 
-    Py_Type(self)->tp_free((PyObject*)self);
+    Py_TYPE(self)->tp_free((PyObject*)self);
 }
 
 int pysqlite_cache_init(pysqlite_Cache* self, PyObject* args, PyObject* kwargs)
@@ -109,7 +109,7 @@
     }
     Py_DECREF(self->mapping);
 
-    Py_Type(self)->tp_free((PyObject*)self);
+    Py_TYPE(self)->tp_free((PyObject*)self);
 }
 
 PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* args)
@@ -241,12 +241,12 @@
         if (!fmt_args) {
             return NULL;
         }
-        template = PyString_FromString("%s <- %s ->%s\n");
+        template = PyUnicode_FromString("%s <- %s ->%s\n");
         if (!template) {
             Py_DECREF(fmt_args);
             return NULL;
         }
-        display_str = PyString_Format(template, fmt_args);
+        display_str = PyUnicode_Format(template, fmt_args);
         Py_DECREF(template);
         Py_DECREF(fmt_args);
         if (!display_str) {

Modified: python/branches/py3k-importlib/Modules/_sqlite/connection.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sqlite/connection.c	(original)
+++ python/branches/py3k-importlib/Modules/_sqlite/connection.c	Thu Mar 27 00:48:05 2008
@@ -87,7 +87,7 @@
     }
 
     if (!isolation_level) {
-        isolation_level = PyString_FromString("");
+        isolation_level = PyUnicode_FromString("");
         if (!isolation_level) {
             return -1;
         }
@@ -205,7 +205,7 @@
     Py_XDECREF(self->collations);
     Py_XDECREF(self->statements);
 
-    Py_Type(self)->tp_free((PyObject*)self);
+    Py_TYPE(self)->tp_free((PyObject*)self);
 }
 
 PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
@@ -420,13 +420,11 @@
         sqlite3_result_null(context);
     } else if (py_val == Py_None) {
         sqlite3_result_null(context);
-    } else if (PyInt_Check(py_val)) {
-        longval = PyInt_AsLong(py_val);
+    } else if (PyLong_Check(py_val)) {
+        longval = PyLong_AsLong(py_val);
         sqlite3_result_int64(context, (PY_LONG_LONG)longval);
     } else if (PyFloat_Check(py_val)) {
         sqlite3_result_double(context, PyFloat_AsDouble(py_val));
-    } else if (PyString_Check(py_val)) {
-        sqlite3_result_text(context, PyString_AsString(py_val), -1, SQLITE_TRANSIENT);
     } else if (PyUnicode_Check(py_val)) {
         sqlite3_result_text(context, PyUnicode_AsString(py_val), -1, SQLITE_TRANSIENT);
     } else if (PyObject_CheckBuffer(py_val)) {
@@ -460,14 +458,14 @@
         switch (sqlite3_value_type(argv[i])) {
             case SQLITE_INTEGER:
                 val_int = sqlite3_value_int64(cur_value);
-                cur_py_value = PyInt_FromLong((long)val_int);
+                cur_py_value = PyLong_FromLong((long)val_int);
                 break;
             case SQLITE_FLOAT:
                 cur_py_value = PyFloat_FromDouble(sqlite3_value_double(cur_value));
                 break;
             case SQLITE_TEXT:
                 val_str = (const char*)sqlite3_value_text(cur_value);
-                cur_py_value = PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL);
+                cur_py_value = PyUnicode_FromString(val_str);
                 /* TODO: have a way to show errors here */
                 if (!cur_py_value) {
                     PyErr_Clear();
@@ -477,7 +475,7 @@
                 break;
             case SQLITE_BLOB:
                 buflen = sqlite3_value_bytes(cur_value);
-                cur_py_value = PyBytes_FromStringAndSize(
+                cur_py_value = PyString_FromStringAndSize(
                     sqlite3_value_blob(cur_value), buflen);
                 break;
             case SQLITE_NULL:
@@ -736,8 +734,8 @@
 
         rc = SQLITE_DENY;
     } else {
-        if (PyInt_Check(ret)) {
-            rc = (int)PyInt_AsLong(ret);
+        if (PyLong_Check(ret)) {
+            rc = (int)PyLong_AsLong(ret);
         } else {
             rc = SQLITE_DENY;
         }
@@ -808,6 +806,7 @@
 {
     PyObject* res;
     PyObject* begin_statement;
+    static PyObject* begin_word;
 
     Py_XDECREF(self->isolation_level);
 
@@ -828,24 +827,28 @@
 
         self->inTransaction = 0;
     } else {
+        const char *statement;
+        Py_ssize_t size;
+
         Py_INCREF(isolation_level);
         self->isolation_level = isolation_level;
 
-        begin_statement = PyString_FromString("BEGIN ");
-        if (!begin_statement) {
-            return -1;
+        if (!begin_word) {
+            begin_word = PyUnicode_FromString("BEGIN ");
+            if (!begin_word) return -1;
         }
-        PyString_Concat(&begin_statement, isolation_level);
+        begin_statement = PyUnicode_Concat(begin_word, isolation_level);
         if (!begin_statement) {
             return -1;
         }
 
-        self->begin_statement = PyMem_Malloc(PyString_Size(begin_statement) + 2);
+        statement = PyUnicode_AsStringAndSize(begin_statement, &size);
+        self->begin_statement = PyMem_Malloc(size + 2);
         if (!self->begin_statement) {
             return -1;
         }
 
-        strcpy(self->begin_statement, PyString_AsString(begin_statement));
+        strcpy(self->begin_statement, statement);
         Py_DECREF(begin_statement);
     }
 
@@ -1019,8 +1022,8 @@
         goto finally;
     }
 
-    string1 = PyString_FromStringAndSize((const char*)text1_data, text1_length);
-    string2 = PyString_FromStringAndSize((const char*)text2_data, text2_length);
+    string1 = PyUnicode_FromStringAndSize((const char*)text1_data, text1_length);
+    string2 = PyUnicode_FromStringAndSize((const char*)text2_data, text2_length);
 
     if (!string1 || !string2) {
         goto finally; /* failed to allocate strings */
@@ -1033,7 +1036,7 @@
         goto finally;
     }
 
-    result = PyInt_AsLong(retval);
+    result = PyLong_AsLong(retval);
     if (PyErr_Occurred()) {
         result = 0;
     }
@@ -1089,7 +1092,7 @@
         goto finally;
     }
 
-    chk = PyString_AsString(uppercase_name);
+    chk = PyUnicode_AsString(uppercase_name);
     while (*chk) {
         if ((*chk >= '0' && *chk <= '9')
          || (*chk >= 'A' && *chk <= 'Z')
@@ -1114,7 +1117,7 @@
     }
 
     rc = sqlite3_create_collation(self->db,
-                                  PyString_AsString(uppercase_name),
+                                  PyUnicode_AsString(uppercase_name),
                                   SQLITE_UTF8,
                                   (callable != Py_None) ? callable : NULL,
                                   (callable != Py_None) ? pysqlite_collation_callback : NULL);

Modified: python/branches/py3k-importlib/Modules/_sqlite/cursor.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sqlite/cursor.c	(original)
+++ python/branches/py3k-importlib/Modules/_sqlite/cursor.c	Thu Mar 27 00:48:05 2008
@@ -26,7 +26,7 @@
 #include "util.h"
 #include "sqlitecompat.h"
 
-/* used to decide wether to call PyInt_FromLong or PyLong_FromLongLong */
+/* used to decide wether to call PyLong_FromLong or PyLong_FromLongLong */
 #ifndef INT32_MIN
 #define INT32_MIN (-2147483647 - 1)
 #endif
@@ -101,7 +101,7 @@
 
     self->arraysize = 1;
 
-    self->rowcount = PyInt_FromLong(-1L);
+    self->rowcount = PyLong_FromLong(-1L);
     if (!self->rowcount) {
         return -1;
     }
@@ -134,7 +134,7 @@
     Py_XDECREF(self->row_factory);
     Py_XDECREF(self->next_row);
 
-    Py_Type(self)->tp_free((PyObject*)self);
+    Py_TYPE(self)->tp_free((PyObject*)self);
 }
 
 PyObject* _pysqlite_get_converter(PyObject* key)
@@ -182,7 +182,7 @@
                     if (*pos == '[') {
                         type_start = pos + 1;
                     } else if (*pos == ']' && type_start != (const char*)-1) {
-                        key = PyString_FromStringAndSize(type_start, pos - type_start);
+                        key = PyUnicode_FromStringAndSize(type_start, pos - type_start);
                         if (!key) {
                             /* creating a string failed, but it is too complicated
                              * to propagate the error here, we just assume there is
@@ -203,7 +203,7 @@
             if (decltype) {
                 for (pos = decltype;;pos++) {
                     if (*pos == ' ' || *pos == 0) {
-                        py_decltype = PyString_FromStringAndSize(decltype, pos - decltype);
+                        py_decltype = PyUnicode_FromStringAndSize(decltype, pos - decltype);
                         if (!py_decltype) {
                             return -1;
                         }
@@ -272,11 +272,7 @@
         }
     }
 
-    if (is_ascii) {
-        return PyString_FromString(val_str);
-    } else {
-        return PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL);
-    }
+    return PyUnicode_FromString(val_str);
 }
 
 /*
@@ -299,6 +295,8 @@
     const char* val_str;
     char buf[200];
     const char* colname;
+    PyObject* buf_bytes;
+    PyObject* error_obj;
 
     Py_BEGIN_ALLOW_THREADS
     numcols = sqlite3_data_count(self->statement->st);
@@ -348,7 +346,7 @@
                 if (intval < INT32_MIN || intval > INT32_MAX) {
                     converted = PyLong_FromLongLong(intval);
                 } else {
-                    converted = PyInt_FromLong((long)intval);
+                    converted = PyLong_FromLong((long)intval);
                 }
             } else if (coltype == SQLITE_FLOAT) {
                 converted = PyFloat_FromDouble(sqlite3_column_double(self->statement->st, i));
@@ -367,7 +365,19 @@
                         }
                         PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'",
                                      colname , val_str);
-                        PyErr_SetString(pysqlite_OperationalError, buf);
+                        buf_bytes = PyBytes_FromStringAndSize(buf, strlen(buf)); 
+                        if (!buf_bytes) {
+                            PyErr_SetString(pysqlite_OperationalError, "Could not decode to UTF-8");
+                        } else {
+                            error_obj = PyUnicode_FromEncodedObject(buf_bytes, "ascii", "replace");
+                            if (!error_obj) {
+                                PyErr_SetString(pysqlite_OperationalError, "Could not decode to UTF-8");
+                                Py_DECREF(error_obj);
+                            } else {
+                                PyErr_SetObject(pysqlite_OperationalError, error_obj);
+                            }
+                            Py_DECREF(buf_bytes);
+                        }
                     }
                 } else if (self->connection->text_factory == (PyObject*)&PyString_Type) {
                     converted = PyString_FromString(val_str);
@@ -379,7 +389,7 @@
             } else {
                 /* coltype == SQLITE_BLOB */
                 nbytes = sqlite3_column_bytes(self->statement->st, i);
-                buffer = PyBytes_FromStringAndSize(
+                buffer = PyString_FromStringAndSize(
                     sqlite3_column_blob(self->statement->st, i), nbytes);
                 if (!buffer) {
                     break;
@@ -436,8 +446,8 @@
             return NULL; 
         }
 
-        if (!PyString_Check(operation) && !PyUnicode_Check(operation)) {
-            PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode");
+        if (!PyUnicode_Check(operation)) {
+            PyErr_SetString(PyExc_ValueError, "operation parameter must be str");
             return NULL;
         }
 
@@ -458,8 +468,8 @@
             return NULL; 
         }
 
-        if (!PyString_Check(operation) && !PyUnicode_Check(operation)) {
-            PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode");
+        if (!PyUnicode_Check(operation)) {
+            PyErr_SetString(PyExc_ValueError, "operation parameter must be str");
             return NULL;
         }
 
@@ -503,7 +513,7 @@
     self->description = Py_None;
 
     Py_DECREF(self->rowcount);
-    self->rowcount = PyInt_FromLong(-1L);
+    self->rowcount = PyLong_FromLong(-1L);
     if (!self->rowcount) {
         goto error;
     }
@@ -684,7 +694,7 @@
                 rowcount += (long)sqlite3_changes(self->connection->db);
                 Py_END_ALLOW_THREADS
                 Py_DECREF(self->rowcount);
-                self->rowcount = PyInt_FromLong(rowcount);
+                self->rowcount = PyLong_FromLong(rowcount);
         }
 
         Py_DECREF(self->lastrowid);
@@ -692,7 +702,7 @@
             Py_BEGIN_ALLOW_THREADS
             lastrowid = sqlite3_last_insert_rowid(self->connection->db);
             Py_END_ALLOW_THREADS
-            self->lastrowid = PyInt_FromLong((long)lastrowid);
+            self->lastrowid = PyLong_FromLong((long)lastrowid);
         } else {
             Py_INCREF(Py_None);
             self->lastrowid = Py_None;
@@ -977,11 +987,11 @@
     {"executescript", (PyCFunction)pysqlite_cursor_executescript, METH_VARARGS,
         PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")},
     {"fetchone", (PyCFunction)pysqlite_cursor_fetchone, METH_NOARGS,
-        PyDoc_STR("Fetches several rows from the resultset.")},
+        PyDoc_STR("Fetches one row from the resultset.")},
     {"fetchmany", (PyCFunction)pysqlite_cursor_fetchmany, METH_VARARGS,
-        PyDoc_STR("Fetches all rows from the resultset.")},
+        PyDoc_STR("Fetches several rows from the resultset.")},
     {"fetchall", (PyCFunction)pysqlite_cursor_fetchall, METH_NOARGS,
-        PyDoc_STR("Fetches one row from the resultset.")},
+        PyDoc_STR("Fetches all rows from the resultset.")},
     {"close", (PyCFunction)pysqlite_cursor_close, METH_NOARGS,
         PyDoc_STR("Closes the cursor.")},
     {"setinputsizes", (PyCFunction)pysqlite_noop, METH_VARARGS,

Modified: python/branches/py3k-importlib/Modules/_sqlite/module.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sqlite/module.c	(original)
+++ python/branches/py3k-importlib/Modules/_sqlite/module.c	Thu Mar 27 00:48:05 2008
@@ -146,7 +146,7 @@
     PyObject* callable;
     PyObject* retval = NULL;
 
-    if (!PyArg_ParseTuple(args, "SO", &orig_name, &callable)) {
+    if (!PyArg_ParseTuple(args, "UO", &orig_name, &callable)) {
         return NULL;
     }
 
@@ -351,7 +351,7 @@
 
     /* Set integer constants */
     for (i = 0; _int_constants[i].constant_name != 0; i++) {
-        tmp_obj = PyInt_FromLong(_int_constants[i].constant_value);
+        tmp_obj = PyLong_FromLong(_int_constants[i].constant_value);
         if (!tmp_obj) {
             goto error;
         }
@@ -359,13 +359,13 @@
         Py_DECREF(tmp_obj);
     }
 
-    if (!(tmp_obj = PyString_FromString(PYSQLITE_VERSION))) {
+    if (!(tmp_obj = PyUnicode_FromString(PYSQLITE_VERSION))) {
         goto error;
     }
     PyDict_SetItemString(dict, "version", tmp_obj);
     Py_DECREF(tmp_obj);
 
-    if (!(tmp_obj = PyString_FromString(sqlite3_libversion()))) {
+    if (!(tmp_obj = PyUnicode_FromString(sqlite3_libversion()))) {
         goto error;
     }
     PyDict_SetItemString(dict, "sqlite_version", tmp_obj);

Modified: python/branches/py3k-importlib/Modules/_sqlite/prepare_protocol.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sqlite/prepare_protocol.c	(original)
+++ python/branches/py3k-importlib/Modules/_sqlite/prepare_protocol.c	Thu Mar 27 00:48:05 2008
@@ -30,7 +30,7 @@
 
 void pysqlite_prepare_protocol_dealloc(pysqlite_PrepareProtocol* self)
 {
-    Py_Type(self)->tp_free((PyObject*)self);
+    Py_TYPE(self)->tp_free((PyObject*)self);
 }
 
 PyTypeObject pysqlite_PrepareProtocolType= {
@@ -78,6 +78,6 @@
 extern int pysqlite_prepare_protocol_setup_types(void)
 {
     pysqlite_PrepareProtocolType.tp_new = PyType_GenericNew;
-    Py_Type(&pysqlite_PrepareProtocolType)= &PyType_Type;
+    Py_TYPE(&pysqlite_PrepareProtocolType)= &PyType_Type;
     return PyType_Ready(&pysqlite_PrepareProtocolType);
 }

Modified: python/branches/py3k-importlib/Modules/_sqlite/row.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sqlite/row.c	(original)
+++ python/branches/py3k-importlib/Modules/_sqlite/row.c	Thu Mar 27 00:48:05 2008
@@ -30,7 +30,7 @@
     Py_XDECREF(self->data);
     Py_XDECREF(self->description);
 
-    Py_Type(self)->tp_free((PyObject*)self);
+    Py_TYPE(self)->tp_free((PyObject*)self);
 }
 
 int pysqlite_row_init(pysqlite_Row* self, PyObject* args, PyObject* kwargs)
@@ -76,12 +76,7 @@
 
     PyObject* item;
 
-    if (PyInt_Check(idx)) {
-        _idx = PyInt_AsLong(idx);
-        item = PyTuple_GetItem(self->data, _idx);
-        Py_XINCREF(item);
-        return item;
-    } else if (PyLong_Check(idx)) {
+    if (PyLong_Check(idx)) {
         _idx = PyLong_AsLong(idx);
         item = PyTuple_GetItem(self->data, _idx);
         Py_XINCREF(item);
@@ -92,7 +87,7 @@
         nitems = PyTuple_Size(self->description);
 
         for (i = 0; i < nitems; i++) {
-            compare_key = PyString_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0));
+            compare_key = PyUnicode_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0));
             if (!compare_key) {
                 return NULL;
             }

Modified: python/branches/py3k-importlib/Modules/_sqlite/statement.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sqlite/statement.c	(original)
+++ python/branches/py3k-importlib/Modules/_sqlite/statement.c	Thu Mar 27 00:48:05 2008
@@ -80,37 +80,34 @@
 int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
 {
     int rc = SQLITE_OK;
-    long longval;
 #ifdef HAVE_LONG_LONG
     PY_LONG_LONG longlongval;
+#else
+    long longval;
 #endif
     const char* buffer;
     char* string;
     Py_ssize_t buflen;
-    PyObject* stringval;
 
     if (parameter == Py_None) {
         rc = sqlite3_bind_null(self->st, pos);
-    } else if (PyInt_CheckExact(parameter)) {
-        longval = PyInt_AsLong(parameter);
-        rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longval);
 #ifdef HAVE_LONG_LONG
     } else if (PyLong_Check(parameter)) {
         longlongval = PyLong_AsLongLong(parameter);
         /* in the overflow error case, longlongval is -1, and an exception is set */
         rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longlongval);
+#else
+    } else if (PyLong_Check(parameter)) {
+        longval = PyLong_AsLong(parameter);
+        /* in the overflow error case, longval is -1, and an exception is set */
+        rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longval);
 #endif
     } else if (PyFloat_Check(parameter)) {
         rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
-    } else if PyString_Check(parameter) {
-        string = PyString_AsString(parameter);
-        rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
     } else if PyUnicode_Check(parameter) {
-        stringval = PyUnicode_AsUTF8String(parameter);
-        string = PyBytes_AsString(stringval);
+        string = PyUnicode_AsString(parameter);
 
         rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
-        Py_DECREF(stringval);
     } else if (PyObject_CheckBuffer(parameter)) {
         if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) {
             rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT);
@@ -234,7 +231,11 @@
          */
         #ifdef SQLITE_VERSION_NUMBER
         #if SQLITE_VERSION_NUMBER >= 3002002
-        (void)sqlite3_transfer_bindings(self->st, new_st);
+        /* The check for the number of parameters is necessary to not trigger a
+         * bug in certain SQLite versions (experienced in 3.2.8 and 3.3.4). */
+        if (sqlite3_bind_parameter_count(self->st) > 0) {
+            (void)sqlite3_transfer_bindings(self->st, new_st);
+        }
         #endif
         #else
         statement_bind_parameters(self, params);
@@ -306,7 +307,7 @@
         PyObject_ClearWeakRefs((PyObject*)self);
     }
 
-    Py_Type(self)->tp_free((PyObject*)self);
+    Py_TYPE(self)->tp_free((PyObject*)self);
 }
 
 /*

Modified: python/branches/py3k-importlib/Modules/_sqlite/util.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sqlite/util.c	(original)
+++ python/branches/py3k-importlib/Modules/_sqlite/util.c	Thu Mar 27 00:48:05 2008
@@ -28,9 +28,15 @@
 {
     int rc;
 
-    Py_BEGIN_ALLOW_THREADS
-    rc = sqlite3_step(statement);
-    Py_END_ALLOW_THREADS
+    if (statement == NULL) {
+        /* this is a workaround for SQLite 3.5 and later. it now apparently
+         * returns NULL for "no-operation" statements */
+        rc = SQLITE_OK;
+    } else {
+        Py_BEGIN_ALLOW_THREADS
+        rc = sqlite3_step(statement);
+        Py_END_ALLOW_THREADS
+    }
 
     return rc;
 }

Modified: python/branches/py3k-importlib/Modules/_sre.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sre.c	(original)
+++ python/branches/py3k-importlib/Modules/_sre.c	Thu Mar 27 00:48:05 2008
@@ -95,6 +95,7 @@
 #define SRE_ERROR_STATE -2 /* illegal state */
 #define SRE_ERROR_RECURSION_LIMIT -3 /* runaway recursion */
 #define SRE_ERROR_MEMORY -9 /* out of memory */
+#define SRE_ERROR_INTERRUPTED -10 /* signal handler raised exception */
 
 #if defined(VERBOSE)
 #define TRACE(v) printf v
@@ -805,6 +806,7 @@
     Py_ssize_t alloc_pos, ctx_pos = -1;
     Py_ssize_t i, ret = 0;
     Py_ssize_t jump;
+    unsigned int sigcount=0;
 
     SRE_MATCH_CONTEXT* ctx;
     SRE_MATCH_CONTEXT* nextctx;
@@ -833,6 +835,9 @@
     }
 
     for (;;) {
+        ++sigcount;
+        if ((0 == (sigcount & 0xfff)) && PyErr_CheckSignals())
+            RETURN_ERROR(SRE_ERROR_INTERRUPTED);
 
         switch (*ctx->pattern++) {
 
@@ -1685,7 +1690,7 @@
 
     /* get pointer to string buffer */
     view.len = -1;
-    buffer = Py_Type(string)->tp_as_buffer;
+    buffer = Py_TYPE(string)->tp_as_buffer;
     if (!buffer || !buffer->bf_getbuffer || 
         (*buffer->bf_getbuffer)(string, &view, PyBUF_SIMPLE) < 0) {
             PyErr_SetString(PyExc_TypeError, "expected string or buffer");
@@ -1833,6 +1838,9 @@
     case SRE_ERROR_MEMORY:
         PyErr_NoMemory();
         break;
+    case SRE_ERROR_INTERRUPTED:
+    /* An exception has already been raised, so let it fly */
+        break;
     default:
         /* other error codes indicate compiler/engine bugs */
         PyErr_SetString(
@@ -2669,7 +2677,7 @@
         return NULL;
 
     n = PyList_GET_SIZE(code);
-
+    /* coverity[ampersand_in_size] */
     self = PyObject_NEW_VAR(PatternObject, &Pattern_Type, n);
     if (!self)
         return NULL;
@@ -2756,8 +2764,8 @@
 	/* Default value */
 	return 0;
 
-    if (PyInt_Check(index))
-        return PyInt_AsSsize_t(index);
+    if (PyLong_Check(index))
+        return PyLong_AsSsize_t(index);
 
     i = -1;
 
@@ -2765,7 +2773,7 @@
         index = PyObject_GetItem(self->pattern->groupindex, index);
         if (index) {
             if (PyLong_Check(index))
-                i = PyInt_AsSsize_t(index);
+                i = PyLong_AsSsize_t(index);
             Py_DECREF(index);
         } else
             PyErr_Clear();
@@ -2957,12 +2965,12 @@
     if (!pair)
         return NULL;
 
-    item = PyInt_FromSsize_t(i1);
+    item = PyLong_FromSsize_t(i1);
     if (!item)
         goto error;
     PyTuple_SET_ITEM(pair, 0, item);
 
-    item = PyInt_FromSsize_t(i2);
+    item = PyLong_FromSsize_t(i2);
     if (!item)
         goto error;
     PyTuple_SET_ITEM(pair, 1, item);
@@ -3179,6 +3187,7 @@
     if (status > 0) {
 
         /* create match object (with room for extra group marks) */
+        /* coverity[ampersand_in_size] */
         match = PyObject_NEW_VAR(MatchObject, &Match_Type,
                                  2*(pattern->groups+1));
         if (!match)
@@ -3397,13 +3406,13 @@
     	return;
     d = PyModule_GetDict(m);
 
-    x = PyInt_FromLong(SRE_MAGIC);
+    x = PyLong_FromLong(SRE_MAGIC);
     if (x) {
         PyDict_SetItemString(d, "MAGIC", x);
         Py_DECREF(x);
     }
 
-    x = PyInt_FromLong(sizeof(SRE_CODE));
+    x = PyLong_FromLong(sizeof(SRE_CODE));
     if (x) {
         PyDict_SetItemString(d, "CODESIZE", x);
         Py_DECREF(x);

Modified: python/branches/py3k-importlib/Modules/_ssl.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ssl.c	(original)
+++ python/branches/py3k-importlib/Modules/_ssl.c	Thu Mar 27 00:48:05 2008
@@ -2,14 +2,15 @@
 
    SSL support based on patches by Brian E Gallew and Laszlo Kovacs.
    Re-worked a bit by Bill Janssen to add server-side support and
-   certificate decoding.
+   certificate decoding.  Chris Stawarz contributed some non-blocking
+   patches.
 
    This module is imported by ssl.py. It should *not* be used
    directly.
 
    XXX should partial writes be enabled, SSL_MODE_ENABLE_PARTIAL_WRITE?
 
-   XXX what about SSL_MODE_AUTO_RETRY
+   XXX what about SSL_MODE_AUTO_RETRY?
 */
 
 #include "Python.h"
@@ -17,7 +18,7 @@
 #ifdef WITH_THREAD
 #include "pythread.h"
 #define PySSL_BEGIN_ALLOW_THREADS { \
-			PyThreadState *_save;  \
+			PyThreadState *_save = NULL;  \
 			if (_ssl_locks_count>0) {_save = PyEval_SaveThread();}
 #define PySSL_BLOCK_THREADS	if (_ssl_locks_count>0){PyEval_RestoreThread(_save)};
 #define PySSL_UNBLOCK_THREADS	if (_ssl_locks_count>0){_save = PyEval_SaveThread()};
@@ -45,6 +46,7 @@
 	PY_SSL_ERROR_WANT_CONNECT,
 	/* start of non ssl.h errorcodes */
 	PY_SSL_ERROR_EOF,         /* special case of SSL_ERROR_SYSCALL */
+        PY_SSL_ERROR_NO_SOCKET,   /* socket has been GC'd */
 	PY_SSL_ERROR_INVALID_ERROR_CODE
 };
 
@@ -110,12 +112,10 @@
 
 typedef struct {
 	PyObject_HEAD
-	PySocketSockObject *Socket;	/* Socket on which we're layered */
+	PyObject        *Socket;	/* weakref to socket on which we're layered */
 	SSL_CTX*	ctx;
 	SSL*		ssl;
 	X509*		peer_cert;
-	char		server[X509_NAME_MAXLEN];
-	char		issuer[X509_NAME_MAXLEN];
 
 } PySSLObject;
 
@@ -127,7 +127,7 @@
 static PyObject *PySSL_peercert(PySSLObject *self, PyObject *args);
 static PyObject *PySSL_cipher(PySSLObject *self);
 
-#define PySSLObject_Check(v)	(Py_Type(v) == &PySSL_Type)
+#define PySSLObject_Check(v)	(Py_TYPE(v) == &PySSL_Type)
 
 typedef enum {
 	SOCKET_IS_NONBLOCKING,
@@ -189,13 +189,15 @@
 		{
 			unsigned long e = ERR_get_error();
 			if (e == 0) {
-				if (ret == 0 || !obj->Socket) {
+                                PySocketSockObject *s
+                                  = (PySocketSockObject *) PyWeakref_GetObject(obj->Socket);
+				if (ret == 0 || (((PyObject *)s) == Py_None)) {
 				  p = PY_SSL_ERROR_EOF;
 				  errstr =
                                       "EOF occurred in violation of protocol";
 				} else if (ret == -1) {
 				  /* underlying BIO reported an I/O error */
-                                  return obj->Socket->errorhandler();
+                                  return s->errorhandler();
 				} else { /* possible? */
                                   p = PY_SSL_ERROR_SYSCALL;
                                   errstr = "Some I/O error occurred";
@@ -265,15 +267,11 @@
 	PySSLObject *self;
 	char *errstr = NULL;
 	int ret;
-	int err;
-	int sockstate;
 	int verification_mode;
 
 	self = PyObject_New(PySSLObject, &PySSL_Type); /* Create new object */
 	if (self == NULL)
 		return NULL;
-	memset(self->server, '\0', sizeof(char) * X509_NAME_MAXLEN);
-	memset(self->issuer, '\0', sizeof(char) * X509_NAME_MAXLEN);
 	self->peer_cert = NULL;
 	self->ssl = NULL;
 	self->ctx = NULL;
@@ -388,59 +386,7 @@
 		SSL_set_accept_state(self->ssl);
 	PySSL_END_ALLOW_THREADS
 
-	/* Actually negotiate SSL connection */
-	/* XXX If SSL_connect() returns 0, it's also a failure. */
-	sockstate = 0;
-	do {
-		PySSL_BEGIN_ALLOW_THREADS
-		if (socket_type == PY_SSL_CLIENT)
-			ret = SSL_connect(self->ssl);
-		else
-			ret = SSL_accept(self->ssl);
-		err = SSL_get_error(self->ssl, ret);
-		PySSL_END_ALLOW_THREADS
-		if(PyErr_CheckSignals()) {
-			goto fail;
-		}
-		if (err == SSL_ERROR_WANT_READ) {
-			sockstate = check_socket_and_wait_for_timeout(Sock, 0);
-		} else if (err == SSL_ERROR_WANT_WRITE) {
-			sockstate = check_socket_and_wait_for_timeout(Sock, 1);
-		} else {
-			sockstate = SOCKET_OPERATION_OK;
-		}
-		if (sockstate == SOCKET_HAS_TIMED_OUT) {
-			PyErr_SetString(PySSLErrorObject,
-				ERRSTR("The connect operation timed out"));
-			goto fail;
-		} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
-			PyErr_SetString(PySSLErrorObject,
-				ERRSTR("Underlying socket has been closed."));
-			goto fail;
-		} else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) {
-			PyErr_SetString(PySSLErrorObject,
-			  ERRSTR("Underlying socket too large for select()."));
-			goto fail;
-		} else if (sockstate == SOCKET_IS_NONBLOCKING) {
-			break;
-		}
-	} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
-	if (ret < 1) {
-		PySSL_SetError(self, ret, __FILE__, __LINE__);
-		goto fail;
-	}
-	self->ssl->debug = 1;
-
-	PySSL_BEGIN_ALLOW_THREADS
-	if ((self->peer_cert = SSL_get_peer_certificate(self->ssl))) {
-		X509_NAME_oneline(X509_get_subject_name(self->peer_cert),
-				  self->server, X509_NAME_MAXLEN);
-		X509_NAME_oneline(X509_get_issuer_name(self->peer_cert),
-				  self->issuer, X509_NAME_MAXLEN);
-	}
-	PySSL_END_ALLOW_THREADS
-	self->Socket = Sock;
-	Py_INCREF(self->Socket);
+	self->Socket = PyWeakref_NewRef((PyObject *) Sock, Py_None);
 	return self;
  fail:
 	if (errstr)
@@ -488,16 +434,66 @@
 
 /* SSL object methods */
 
-static PyObject *
-PySSL_server(PySSLObject *self)
+static PyObject *PySSL_SSLdo_handshake(PySSLObject *self)
 {
-	return PyUnicode_FromString(self->server);
-}
+	int ret;
+	int err;
+	int sockstate;
 
-static PyObject *
-PySSL_issuer(PySSLObject *self)
-{
-	return PyUnicode_FromString(self->issuer);
+	/* Actually negotiate SSL connection */
+	/* XXX If SSL_do_handshake() returns 0, it's also a failure. */
+	sockstate = 0;
+	do {
+                PySocketSockObject *sock
+                  = (PySocketSockObject *) PyWeakref_GetObject(self->Socket);
+                if (((PyObject*)sock) == Py_None) {
+                        _setSSLError("Underlying socket connection gone",
+                                     PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__);
+                        return NULL;
+                }
+
+		PySSL_BEGIN_ALLOW_THREADS
+		ret = SSL_do_handshake(self->ssl);
+		err = SSL_get_error(self->ssl, ret);
+		PySSL_END_ALLOW_THREADS
+		if(PyErr_CheckSignals()) {
+			return NULL;
+		}
+		if (err == SSL_ERROR_WANT_READ) {
+			sockstate = check_socket_and_wait_for_timeout(sock, 0);
+		} else if (err == SSL_ERROR_WANT_WRITE) {
+			sockstate = check_socket_and_wait_for_timeout(sock, 1);
+		} else {
+			sockstate = SOCKET_OPERATION_OK;
+		}
+		if (sockstate == SOCKET_HAS_TIMED_OUT) {
+			PyErr_SetString(PySSLErrorObject,
+				ERRSTR("The handshake operation timed out"));
+			return NULL;
+		} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
+			PyErr_SetString(PySSLErrorObject,
+				ERRSTR("Underlying socket has been closed."));
+			return NULL;
+		} else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) {
+			PyErr_SetString(PySSLErrorObject,
+			  ERRSTR("Underlying socket too large for select()."));
+			return NULL;
+		} else if (sockstate == SOCKET_IS_NONBLOCKING) {
+			break;
+		}
+	} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
+	if (ret < 1)
+		return PySSL_SetError(self, ret, __FILE__, __LINE__);
+	self->ssl->debug = 1;
+
+	if (self->peer_cert)
+		X509_free (self->peer_cert);
+        PySSL_BEGIN_ALLOW_THREADS
+	self->peer_cert = SSL_get_peer_certificate(self->ssl);
+	PySSL_END_ALLOW_THREADS
+
+	Py_INCREF(Py_None);
+	return Py_None;
 }
 
 static PyObject *
@@ -515,10 +511,10 @@
 		_setSSLError(NULL, 0, __FILE__, __LINE__);
 		goto fail;
 	}
-	name_obj = PyString_FromStringAndSize(namebuf, buflen);
+	name_obj = PyUnicode_FromStringAndSize(namebuf, buflen);
 	if (name_obj == NULL)
 		goto fail;
-	
+
 	buflen = ASN1_STRING_to_UTF8(&valuebuf, value);
 	if (buflen < 0) {
 		_setSSLError(NULL, 0, __FILE__, __LINE__);
@@ -604,7 +600,7 @@
                 fprintf(stderr, "RDN level %d, attribute %s: %s\n",
                         entry->set,
                         PyString_AS_STRING(PyTuple_GET_ITEM(attr, 0)),
-                        PyString_AS_STRING(PyTuple_GET_ITEM(attr, 1)));                        
+                        PyString_AS_STRING(PyTuple_GET_ITEM(attr, 1)));
                 */
 		if (attr == NULL)
 			goto fail1;
@@ -642,7 +638,7 @@
 
 static PyObject *
 _get_peer_alt_names (X509 *certificate) {
-                  
+
 	/* this code follows the procedure outlined in
 	   OpenSSL's crypto/x509v3/v3_prn.c:X509v3_EXT_print()
 	   function to extract the STACK_OF(GENERAL_NAME),
@@ -655,12 +651,12 @@
 	X509_EXTENSION *ext = NULL;
 	GENERAL_NAMES *names = NULL;
 	GENERAL_NAME *name;
-	X509V3_EXT_METHOD *method;	
+	X509V3_EXT_METHOD *method;
 	BIO *biobuf = NULL;
 	char buf[2048];
 	char *vptr;
 	int len;
-	unsigned char *p;
+	const unsigned char *p;
 
 	if (certificate == NULL)
 		return peer_alt_names;
@@ -677,25 +673,28 @@
                         if (peer_alt_names == NULL)
 				goto fail;
 		}
-		
+
 		/* now decode the altName */
 		ext = X509_get_ext(certificate, i);
 		if(!(method = X509V3_EXT_get(ext))) {
-			PyErr_SetString(PySSLErrorObject,
-					ERRSTR("No method for internalizing subjectAltName!"));
+			PyErr_SetString
+                          (PySSLErrorObject,
+                           ERRSTR("No method for internalizing subjectAltName!"));
 			goto fail;
 		}
 
 		p = ext->value->data;
-		if(method->it)
-			names = (GENERAL_NAMES*) (ASN1_item_d2i(NULL,
-								&p,
-								ext->value->length,
-								ASN1_ITEM_ptr(method->it)));
+		if (method->it)
+			names = (GENERAL_NAMES*)
+                          (ASN1_item_d2i(NULL,
+                                         &p,
+                                         ext->value->length,
+                                         ASN1_ITEM_ptr(method->it)));
 		else
-			names = (GENERAL_NAMES*) (method->d2i(NULL,
-							      &p,
-							      ext->value->length));
+			names = (GENERAL_NAMES*)
+                          (method->d2i(NULL,
+                                       &p,
+                                       ext->value->length));
 
 		for(j = 0; j < sk_GENERAL_NAME_num(names); j++) {
 
@@ -704,14 +703,15 @@
 			name = sk_GENERAL_NAME_value(names, j);
 			if (name->type == GEN_DIRNAME) {
 
-				/* we special-case DirName as a tuple of tuples of attributes */
+				/* we special-case DirName as a tuple of
+                                   tuples of attributes */
 
 				t = PyTuple_New(2);
 				if (t == NULL) {
 					goto fail;
 				}
 
-				v = PyString_FromString("DirName");
+				v = PyUnicode_FromString("DirName");
 				if (v == NULL) {
 					Py_DECREF(t);
 					goto fail;
@@ -724,7 +724,7 @@
 					goto fail;
 				}
 				PyTuple_SET_ITEM(t, 1, v);
-				
+
 			} else {
 
 				/* for everything else, we use the OpenSSL print form */
@@ -742,13 +742,14 @@
 				t = PyTuple_New(2);
 				if (t == NULL)
 					goto fail;
-				v = PyString_FromStringAndSize(buf, (vptr - buf));
+				v = PyUnicode_FromStringAndSize(buf, (vptr - buf));
 				if (v == NULL) {
 					Py_DECREF(t);
 					goto fail;
 				}
 				PyTuple_SET_ITEM(t, 0, v);
-				v = PyString_FromStringAndSize((vptr + 1), (len - (vptr - buf + 1)));
+				v = PyUnicode_FromStringAndSize((vptr + 1),
+                                                                (len - (vptr - buf + 1)));
 				if (v == NULL) {
 					Py_DECREF(t);
 					goto fail;
@@ -773,7 +774,7 @@
 	} else {
 		return peer_alt_names;
 	}
-	
+
 
   fail:
 	if (biobuf != NULL)
@@ -826,18 +827,18 @@
 			goto fail0;
 		}
 		Py_DECREF(issuer);
-	
-		version = PyInt_FromLong(X509_get_version(certificate) + 1);
+
+		version = PyLong_FromLong(X509_get_version(certificate) + 1);
 		if (PyDict_SetItemString(retval, "version", version) < 0) {
 			Py_DECREF(version);
 			goto fail0;
 		}
 		Py_DECREF(version);
 	}
-	
+
 	/* get a memory buffer */
 	biobuf = BIO_new(BIO_s_mem());
-	
+
 	if (verbose) {
 
 		(void) BIO_reset(biobuf);
@@ -849,7 +850,7 @@
 			_setSSLError(NULL, 0, __FILE__, __LINE__);
 			goto fail1;
 		}
-		sn_obj = PyString_FromStringAndSize(buf, len);
+		sn_obj = PyUnicode_FromStringAndSize(buf, len);
 		if (sn_obj == NULL)
 			goto fail1;
 		if (PyDict_SetItemString(retval, "serialNumber", sn_obj) < 0) {
@@ -866,7 +867,7 @@
 			_setSSLError(NULL, 0, __FILE__, __LINE__);
 			goto fail1;
 		}
-		pnotBefore = PyString_FromStringAndSize(buf, len);
+		pnotBefore = PyUnicode_FromStringAndSize(buf, len);
 		if (pnotBefore == NULL)
 			goto fail1;
 		if (PyDict_SetItemString(retval, "notBefore", pnotBefore) < 0) {
@@ -884,7 +885,7 @@
 		_setSSLError(NULL, 0, __FILE__, __LINE__);
 		goto fail1;
 	}
-	pnotAfter = PyString_FromStringAndSize(buf, len);
+	pnotAfter = PyUnicode_FromStringAndSize(buf, len);
 	if (pnotAfter == NULL)
 		goto fail1;
 	if (PyDict_SetItemString(retval, "notAfter", pnotAfter) < 0) {
@@ -906,7 +907,7 @@
 		}
 		Py_DECREF(peer_alt_names);
 	}
-	
+
 	BIO_free(biobuf);
 	return retval;
 
@@ -928,29 +929,33 @@
 	BIO *cert;
 	int verbose = 1;
 
-	if (!PyArg_ParseTuple(args, "s|i:test_decode_certificate", &filename, &verbose))
+	if (!PyArg_ParseTuple(args, "s|i:test_decode_certificate",
+                              &filename, &verbose))
 		return NULL;
 
 	if ((cert=BIO_new(BIO_s_file())) == NULL) {
-		PyErr_SetString(PySSLErrorObject, "Can't malloc memory to read file");
+		PyErr_SetString(PySSLErrorObject,
+                                "Can't malloc memory to read file");
 		goto fail0;
 	}
 
 	if (BIO_read_filename(cert,filename) <= 0) {
-		PyErr_SetString(PySSLErrorObject, "Can't open file");
+		PyErr_SetString(PySSLErrorObject,
+                                "Can't open file");
 		goto fail0;
 	}
 
 	x = PEM_read_bio_X509_AUX(cert,NULL, NULL, NULL);
 	if (x == NULL) {
-		PyErr_SetString(PySSLErrorObject, "Error decoding PEM-encoded file");
+		PyErr_SetString(PySSLErrorObject,
+                                "Error decoding PEM-encoded file");
 		goto fail0;
 	}
 
 	retval = _decode_certificate(x, verbose);
 
   fail0:
-		
+
 	if (cert != NULL) BIO_free(cert);
 	return retval;
 }
@@ -981,7 +986,9 @@
 			PySSL_SetError(self, len, __FILE__, __LINE__);
 			return NULL;
 		}
-		retval = PyString_FromStringAndSize((const char *) bytes_buf, len);
+                /* this is actually an immutable bytes sequence */
+		retval = PyString_FromStringAndSize
+                  ((const char *) bytes_buf, len);
 		OPENSSL_free(bytes_buf);
 		return retval;
 
@@ -1028,7 +1035,7 @@
 	if (cipher_name == NULL) {
 		PyTuple_SET_ITEM(retval, 0, Py_None);
 	} else {
-		v = PyString_FromString(cipher_name);
+		v = PyUnicode_FromString(cipher_name);
 		if (v == NULL)
 			goto fail0;
 		PyTuple_SET_ITEM(retval, 0, v);
@@ -1037,17 +1044,17 @@
 	if (cipher_protocol == NULL) {
 		PyTuple_SET_ITEM(retval, 1, Py_None);
 	} else {
-		v = PyString_FromString(cipher_protocol);
+		v = PyUnicode_FromString(cipher_protocol);
 		if (v == NULL)
 			goto fail0;
 		PyTuple_SET_ITEM(retval, 1, v);
 	}
-	v = PyInt_FromLong(SSL_CIPHER_get_bits(current, NULL));
+	v = PyLong_FromLong(SSL_CIPHER_get_bits(current, NULL));
 	if (v == NULL)
 		goto fail0;
 	PyTuple_SET_ITEM(retval, 2, v);
 	return retval;
-	
+
   fail0:
 	Py_DECREF(retval);
 	return NULL;
@@ -1127,7 +1134,9 @@
 		rc = select(s->sock_fd+1, &fds, NULL, NULL, &tv);
 	PySSL_END_ALLOW_THREADS
 
+#ifdef HAVE_POLL
 normal_return:
+#endif
 	/* Return SOCKET_TIMED_OUT on timeout, SOCKET_OPERATION_OK otherwise
 	   (when we are able to write or when there's something to read) */
 	return rc == 0 ? SOCKET_HAS_TIMED_OUT : SOCKET_OPERATION_OK;
@@ -1140,11 +1149,25 @@
 	int count;
 	int sockstate;
 	int err;
+        int nonblocking;
+        PySocketSockObject *sock
+          = (PySocketSockObject *) PyWeakref_GetObject(self->Socket);
+
+        if (((PyObject*)sock) == Py_None) {
+                _setSSLError("Underlying socket connection gone",
+                             PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__);
+                return NULL;
+        }
 
-	if (!PyArg_ParseTuple(args, "s#:write", &data, &count))
+	if (!PyArg_ParseTuple(args, "y#:write", &data, &count))
 		return NULL;
 
-	sockstate = check_socket_and_wait_for_timeout(self->Socket, 1);
+        /* just in case the blocking state of the socket has been changed */
+	nonblocking = (sock->sock_timeout >= 0.0);
+        BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
+        BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking);
+
+	sockstate = check_socket_and_wait_for_timeout(sock, 1);
 	if (sockstate == SOCKET_HAS_TIMED_OUT) {
 		PyErr_SetString(PySSLErrorObject,
                                 "The write operation timed out");
@@ -1169,10 +1192,10 @@
 		}
 		if (err == SSL_ERROR_WANT_READ) {
 			sockstate =
-                            check_socket_and_wait_for_timeout(self->Socket, 0);
+                            check_socket_and_wait_for_timeout(sock, 0);
 		} else if (err == SSL_ERROR_WANT_WRITE) {
 			sockstate =
-                            check_socket_and_wait_for_timeout(self->Socket, 1);
+                            check_socket_and_wait_for_timeout(sock, 1);
 		} else {
 			sockstate = SOCKET_OPERATION_OK;
 		}
@@ -1189,7 +1212,7 @@
 		}
 	} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
 	if (len > 0)
-		return PyInt_FromLong(len);
+		return PyLong_FromLong(len);
 	else
 		return PySSL_SetError(self, len, __FILE__, __LINE__);
 }
@@ -1200,19 +1223,65 @@
 Writes the string s into the SSL object.  Returns the number\n\
 of bytes written.");
 
-static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
+static PyObject *PySSL_SSLpending(PySSLObject *self)
 {
-	PyObject *buf;
 	int count = 0;
+
+	PySSL_BEGIN_ALLOW_THREADS
+	count = SSL_pending(self->ssl);
+	PySSL_END_ALLOW_THREADS
+	if (count < 0)
+		return PySSL_SetError(self, count, __FILE__, __LINE__);
+	else
+		return PyLong_FromLong(count);
+}
+
+PyDoc_STRVAR(PySSL_SSLpending_doc,
+"pending() -> count\n\
+\n\
+Returns the number of already decrypted bytes available for read,\n\
+pending on the connection.\n");
+
+static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
+{
+	PyObject *buf = NULL;
+	int buf_passed = 0;
+	int count = -1;
 	int len = 1024;
 	int sockstate;
 	int err;
+        int nonblocking;
+        PySocketSockObject *sock
+          = (PySocketSockObject *) PyWeakref_GetObject(self->Socket);
+
+        if (((PyObject*)sock) == Py_None) {
+                _setSSLError("Underlying socket connection gone",
+                             PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__);
+                return NULL;
+        }
 
-	if (!PyArg_ParseTuple(args, "|i:read", &len))
+	if (!PyArg_ParseTuple(args, "|Oi:read", &buf, &count))
 		return NULL;
+        if ((buf == NULL) || (buf == Py_None)) {
+		if (!(buf = PyBytes_FromStringAndSize((char *) 0, len)))
+			return NULL;
+        } else if (PyLong_Check(buf)) {
+		len = PyLong_AS_LONG(buf);
+		if (!(buf = PyBytes_FromStringAndSize((char *) 0, len)))
+			return NULL;
+	} else {
+		if (!PyBytes_Check(buf))
+			return NULL;
+		len = PyBytes_Size(buf);
+		if ((count > 0) && (count <= len))
+			len = count;
+		buf_passed = 1;
+	}
 
-	if (!(buf = PyBytes_FromStringAndSize((char *) 0, len)))
-		return NULL;
+        /* just in case the blocking state of the socket has been changed */
+	nonblocking = (sock->sock_timeout >= 0.0);
+        BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
+        BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking);
 
 	/* first check if there are bytes ready to be read */
 	PySSL_BEGIN_ALLOW_THREADS
@@ -1220,81 +1289,95 @@
 	PySSL_END_ALLOW_THREADS
 
 	if (!count) {
-		sockstate = check_socket_and_wait_for_timeout(self->Socket, 0);
+		sockstate = check_socket_and_wait_for_timeout(sock, 0);
 		if (sockstate == SOCKET_HAS_TIMED_OUT) {
 			PyErr_SetString(PySSLErrorObject,
 					"The read operation timed out");
-			Py_DECREF(buf);
+			if (!buf_passed) {
+				Py_DECREF(buf);
+			}
 			return NULL;
 		} else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) {
 			PyErr_SetString(PySSLErrorObject,
 				"Underlying socket too large for select().");
+			if (!buf_passed) {
+				Py_DECREF(buf);
+			}
 			Py_DECREF(buf);
 			return NULL;
 		} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
-			/* should contain a zero-length string */
-			_PyString_Resize(&buf, 0);
-			return buf;
+			count = 0;
+			goto done;
 		}
 	}
 	do {
 		err = 0;
 		PySSL_BEGIN_ALLOW_THREADS
-		count = SSL_read(self->ssl, PyBytes_AS_STRING(buf), len);
+		count = SSL_read(self->ssl, PyBytes_AsString(buf), len);
 		err = SSL_get_error(self->ssl, count);
 		PySSL_END_ALLOW_THREADS
 		if(PyErr_CheckSignals()) {
-			Py_DECREF(buf);
+			if (!buf_passed) {
+				Py_DECREF(buf);
+			}
 			return NULL;
 		}
 		if (err == SSL_ERROR_WANT_READ) {
 			sockstate =
-			  check_socket_and_wait_for_timeout(self->Socket, 0);
+			  check_socket_and_wait_for_timeout(sock, 0);
 		} else if (err == SSL_ERROR_WANT_WRITE) {
 			sockstate =
-			  check_socket_and_wait_for_timeout(self->Socket, 1);
+			  check_socket_and_wait_for_timeout(sock, 1);
 		} else if ((err == SSL_ERROR_ZERO_RETURN) &&
 			   (SSL_get_shutdown(self->ssl) ==
 			    SSL_RECEIVED_SHUTDOWN))
 		{
-			_PyString_Resize(&buf, 0);
-			return buf;
+			count = 0;
+			goto done;
 		} else {
 			sockstate = SOCKET_OPERATION_OK;
 		}
 		if (sockstate == SOCKET_HAS_TIMED_OUT) {
 			PyErr_SetString(PySSLErrorObject,
 					"The read operation timed out");
-			Py_DECREF(buf);
+			if (!buf_passed) {
+				Py_DECREF(buf);
+			}
 			return NULL;
 		} else if (sockstate == SOCKET_IS_NONBLOCKING) {
 			break;
 		}
 	} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
 	if (count <= 0) {
-		Py_DECREF(buf);
+		if (!buf_passed) {
+			Py_DECREF(buf);
+		}
 		return PySSL_SetError(self, count, __FILE__, __LINE__);
 	}
-	if (count != len)
-		if (PyBytes_Resize(buf, count) < 0) {
-                        Py_DECREF(buf);
-                        return NULL;
-                }
-	return buf;
+  done:
+	if (!buf_passed) {
+		PyObject *res = PyString_FromStringAndSize(
+			PyBytes_AS_STRING(buf), count);
+		Py_DECREF(buf);
+		return res;
+	} else {
+		return PyLong_FromLong(count);
+	}
 }
 
 PyDoc_STRVAR(PySSL_SSLread_doc,
-"read([len]) -> bytes\n\
+"read([len]) -> string\n\
 \n\
 Read up to len bytes from the SSL socket.");
 
 static PyMethodDef PySSLMethods[] = {
+	{"do_handshake", (PyCFunction)PySSL_SSLdo_handshake, METH_NOARGS},
 	{"write", (PyCFunction)PySSL_SSLwrite, METH_VARARGS,
 	 PySSL_SSLwrite_doc},
 	{"read", (PyCFunction)PySSL_SSLread, METH_VARARGS,
 	 PySSL_SSLread_doc},
-	{"server", (PyCFunction)PySSL_server, METH_NOARGS},
-	{"issuer", (PyCFunction)PySSL_issuer, METH_NOARGS},
+	{"pending", (PyCFunction)PySSL_SSLpending, METH_NOARGS,
+	 PySSL_SSLpending_doc},
 	{"peer_certificate", (PyCFunction)PySSL_peercert, METH_VARARGS,
 	 PySSL_peercert_doc},
 	{"cipher", (PyCFunction)PySSL_cipher, METH_NOARGS},
@@ -1350,33 +1433,33 @@
 static PyObject *
 PySSL_RAND_status(PyObject *self)
 {
-    return PyBool_FromLong(RAND_status());
+    return PyLong_FromLong(RAND_status());
 }
 
 PyDoc_STRVAR(PySSL_RAND_status_doc,
 "RAND_status() -> 0 or 1\n\
 \n\
-Returns True if the OpenSSL PRNG has been seeded with enough data and\n\
-False if not.  It is necessary to seed the PRNG with RAND_add()\n\
-on some platforms before using the ssl() function.");
+Returns 1 if the OpenSSL PRNG has been seeded with enough data and 0 if not.\n\
+It is necessary to seed the PRNG with RAND_add() on some platforms before\n\
+using the ssl() function.");
 
 static PyObject *
 PySSL_RAND_egd(PyObject *self, PyObject *arg)
 {
     int bytes;
 
-    if (!PyString_Check(arg))
+    if (!PyUnicode_Check(arg))
 	return PyErr_Format(PyExc_TypeError,
 			    "RAND_egd() expected string, found %s",
-			    Py_Type(arg)->tp_name);
-    bytes = RAND_egd(PyString_AS_STRING(arg));
+			    Py_TYPE(arg)->tp_name);
+    bytes = RAND_egd(PyUnicode_AsString(arg));
     if (bytes == -1) {
 	PyErr_SetString(PySSLErrorObject,
 			"EGD connection failed or EGD did not return "
 			"enough data to seed the PRNG");
 	return NULL;
     }
-    return PyInt_FromLong(bytes);
+    return PyLong_FromLong(bytes);
 }
 
 PyDoc_STRVAR(PySSL_RAND_egd_doc,
@@ -1418,16 +1501,17 @@
 	return PyThread_get_thread_ident();
 }
 
-static void _ssl_thread_locking_function (int mode, int n, const char *file, int line) {
+static void _ssl_thread_locking_function
+        (int mode, int n, const char *file, int line) {
 	/* this function is needed to perform locking on shared data
 	   structures. (Note that OpenSSL uses a number of global data
-	   structures that will be implicitly shared whenever multiple threads
-	   use OpenSSL.) Multi-threaded applications will crash at random if
-	   it is not set.
-
-	   locking_function() must be able to handle up to CRYPTO_num_locks()
-	   different mutex locks. It sets the n-th lock if mode & CRYPTO_LOCK, and
-	   releases it otherwise.
+	   structures that will be implicitly shared whenever multiple
+	   threads use OpenSSL.) Multi-threaded applications will
+	   crash at random if it is not set.
+
+	   locking_function() must be able to handle up to
+	   CRYPTO_num_locks() different mutex locks. It sets the n-th
+	   lock if mode & CRYPTO_LOCK, and releases it otherwise.
 
 	   file and line are the file number of the function setting the
 	   lock. They can be useful for debugging.
@@ -1454,7 +1538,8 @@
 			malloc(sizeof(PyThread_type_lock) * _ssl_locks_count);
 		if (_ssl_locks == NULL)
 			return 0;
-		memset(_ssl_locks, 0, sizeof(PyThread_type_lock) * _ssl_locks_count);
+		memset(_ssl_locks, 0,
+                       sizeof(PyThread_type_lock) * _ssl_locks_count);
 		for (i = 0;  i < _ssl_locks_count;  i++) {
 			_ssl_locks[i] = PyThread_allocate_lock();
 			if (_ssl_locks[i] == NULL) {
@@ -1483,7 +1568,7 @@
 {
 	PyObject *m, *d;
 
-	Py_Type(&PySSL_Type) = &PyType_Type;
+	Py_TYPE(&PySSL_Type) = &PyType_Type;
 
 	m = Py_InitModule3("_ssl", PySSL_methods, module_doc);
 	if (m == NULL)

Modified: python/branches/py3k-importlib/Modules/_struct.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_struct.c	(original)
+++ python/branches/py3k-importlib/Modules/_struct.c	Thu Mar 27 00:48:05 2008
@@ -12,11 +12,6 @@
 
 static PyTypeObject PyStructType;
 
-/* compatibility macros */
-#if (PY_VERSION_HEX < 0x02050000)
-typedef int Py_ssize_t;
-#endif
-
 /* If PY_STRUCT_OVERFLOW_MASKING is defined, the struct module will wrap all input
    numbers for explicit endians such that they fit in the given type, much
    like explicit casting in C. A warning will be raised if the number did
@@ -72,7 +67,7 @@
 
 
 #define PyStruct_Check(op) PyObject_TypeCheck(op, &PyStructType)
-#define PyStruct_CheckExact(op) (Py_Type(op) == &PyStructType)
+#define PyStruct_CheckExact(op) (Py_TYPE(op) == &PyStructType)
 
 
 /* Exception */
@@ -131,7 +126,7 @@
 		Py_INCREF(v);
 		return v;
 	}
-	m = Py_Type(v)->tp_as_number;
+	m = Py_TYPE(v)->tp_as_number;
 	if (m != NULL && m->nb_long != NULL) {
 		v = m->nb_long(v);
 		if (v == NULL)
@@ -151,7 +146,7 @@
 static int
 get_long(PyObject *v, long *p)
 {
-	long x = PyInt_AsLong(v);
+	long x = PyLong_AsLong(v);
 	if (x == -1 && PyErr_Occurred()) {
 #ifdef PY_STRUCT_FLOAT_COERCE
 		if (PyFloat_Check(v)) {
@@ -411,7 +406,7 @@
 		if (msg == NULL)
 			return -1;
 		rval = PyErr_WarnEx(PyExc_DeprecationWarning,
-				    PyString_AS_STRING(msg), 2);
+				    PyUnicode_AsString(msg), 2);
 		Py_DECREF(msg);
 		if (rval == 0)
 			return 0;
@@ -450,13 +445,13 @@
 static PyObject *
 nu_byte(const char *p, const formatdef *f)
 {
-	return PyInt_FromLong((long) *(signed char *)p);
+	return PyLong_FromLong((long) *(signed char *)p);
 }
 
 static PyObject *
 nu_ubyte(const char *p, const formatdef *f)
 {
-	return PyInt_FromLong((long) *(unsigned char *)p);
+	return PyLong_FromLong((long) *(unsigned char *)p);
 }
 
 static PyObject *
@@ -464,7 +459,7 @@
 {
 	short x;
 	memcpy((char *)&x, p, sizeof x);
-	return PyInt_FromLong((long)x);
+	return PyLong_FromLong((long)x);
 }
 
 static PyObject *
@@ -472,7 +467,7 @@
 {
 	unsigned short x;
 	memcpy((char *)&x, p, sizeof x);
-	return PyInt_FromLong((long)x);
+	return PyLong_FromLong((long)x);
 }
 
 static PyObject *
@@ -480,7 +475,7 @@
 {
 	int x;
 	memcpy((char *)&x, p, sizeof x);
-	return PyInt_FromLong((long)x);
+	return PyLong_FromLong((long)x);
 }
 
 static PyObject *
@@ -489,10 +484,10 @@
 	unsigned int x;
 	memcpy((char *)&x, p, sizeof x);
 #if (SIZEOF_LONG > SIZEOF_INT)
-	return PyInt_FromLong((long)x);
+	return PyLong_FromLong((long)x);
 #else
 	if (x <= ((unsigned int)LONG_MAX))
-		return PyInt_FromLong((long)x);
+		return PyLong_FromLong((long)x);
 	return PyLong_FromUnsignedLong((unsigned long)x);
 #endif
 }
@@ -502,7 +497,7 @@
 {
 	long x;
 	memcpy((char *)&x, p, sizeof x);
-	return PyInt_FromLong(x);
+	return PyLong_FromLong(x);
 }
 
 static PyObject *
@@ -511,7 +506,7 @@
 	unsigned long x;
 	memcpy((char *)&x, p, sizeof x);
 	if (x <= LONG_MAX)
-		return PyInt_FromLong((long)x);
+		return PyLong_FromLong((long)x);
 	return PyLong_FromUnsignedLong(x);
 }
 
@@ -526,7 +521,7 @@
 	PY_LONG_LONG x;
 	memcpy((char *)&x, p, sizeof x);
 	if (x >= LONG_MIN && x <= LONG_MAX)
-		return PyInt_FromLong(Py_SAFE_DOWNCAST(x, PY_LONG_LONG, long));
+		return PyLong_FromLong(Py_SAFE_DOWNCAST(x, PY_LONG_LONG, long));
 	return PyLong_FromLongLong(x);
 }
 
@@ -536,7 +531,7 @@
 	unsigned PY_LONG_LONG x;
 	memcpy((char *)&x, p, sizeof x);
 	if (x <= LONG_MAX)
-		return PyInt_FromLong(Py_SAFE_DOWNCAST(x, unsigned PY_LONG_LONG, long));
+		return PyLong_FromLong(Py_SAFE_DOWNCAST(x, unsigned PY_LONG_LONG, long));
 	return PyLong_FromUnsignedLongLong(x);
 }
 
@@ -802,7 +797,7 @@
 	{'q',	sizeof(PY_LONG_LONG), LONG_LONG_ALIGN, nu_longlong, np_longlong},
 	{'Q',	sizeof(PY_LONG_LONG), LONG_LONG_ALIGN, nu_ulonglong,np_ulonglong},
 #endif
-	{'t',	sizeof(BOOL_TYPE),	BOOL_ALIGN,	nu_bool,	np_bool},
+	{'?',	sizeof(BOOL_TYPE),	BOOL_ALIGN,	nu_bool,	np_bool},
 	{'f',	sizeof(float),	FLOAT_ALIGN,	nu_float,	np_float},
 	{'d',	sizeof(double),	DOUBLE_ALIGN,	nu_double,	np_double},
 	{'P',	sizeof(void *),	VOID_P_ALIGN,	nu_void_p,	np_void_p},
@@ -823,7 +818,7 @@
 	/* Extend the sign bit. */
 	if (SIZEOF_LONG > f->size)
 		x |= -(x & (1L << ((8 * f->size) - 1)));
-	return PyInt_FromLong(x);
+	return PyLong_FromLong(x);
 }
 
 static PyObject *
@@ -836,7 +831,7 @@
 		x = (x<<8) | *bytes++;
 	} while (--i > 0);
 	if (x <= LONG_MAX)
-		return PyInt_FromLong((long)x);
+		return PyLong_FromLong((long)x);
 	return PyLong_FromUnsignedLong(x);
 }
 
@@ -854,7 +849,7 @@
 	if (SIZEOF_LONG_LONG > f->size)
 		x |= -(x & ((PY_LONG_LONG)1 << ((8 * f->size) - 1)));
 	if (x >= LONG_MIN && x <= LONG_MAX)
-		return PyInt_FromLong(Py_SAFE_DOWNCAST(x, PY_LONG_LONG, long));
+		return PyLong_FromLong(Py_SAFE_DOWNCAST(x, PY_LONG_LONG, long));
 	return PyLong_FromLongLong(x);
 #else
 	return _PyLong_FromByteArray((const unsigned char *)p,
@@ -875,7 +870,7 @@
 		x = (x<<8) | *bytes++;
 	} while (--i > 0);
 	if (x <= LONG_MAX)
-		return PyInt_FromLong(Py_SAFE_DOWNCAST(x, unsigned PY_LONG_LONG, long));
+		return PyLong_FromLong(Py_SAFE_DOWNCAST(x, unsigned PY_LONG_LONG, long));
 	return PyLong_FromUnsignedLongLong(x);
 #else
 	return _PyLong_FromByteArray((const unsigned char *)p,
@@ -1039,7 +1034,7 @@
 	{'L',	4,		0,		bu_uint,	bp_uint},
 	{'q',	8,		0,		bu_longlong,	bp_longlong},
 	{'Q',	8,		0,		bu_ulonglong,	bp_ulonglong},
-	{'t',	1,		0,		bu_bool,	bp_bool},
+	{'?',	1,		0,		bu_bool,	bp_bool},
 	{'f',	4,		0,		bu_float,	bp_float},
 	{'d',	8,		0,		bu_double,	bp_double},
 	{0}
@@ -1059,7 +1054,7 @@
 	/* Extend the sign bit. */
 	if (SIZEOF_LONG > f->size)
 		x |= -(x & (1L << ((8 * f->size) - 1)));
-	return PyInt_FromLong(x);
+	return PyLong_FromLong(x);
 }
 
 static PyObject *
@@ -1072,7 +1067,7 @@
 		x = (x<<8) | bytes[--i];
 	} while (i > 0);
 	if (x <= LONG_MAX)
-		return PyInt_FromLong((long)x);
+		return PyLong_FromLong((long)x);
 	return PyLong_FromUnsignedLong((long)x);
 }
 
@@ -1090,7 +1085,7 @@
 	if (SIZEOF_LONG_LONG > f->size)
 		x |= -(x & ((PY_LONG_LONG)1 << ((8 * f->size) - 1)));
 	if (x >= LONG_MIN && x <= LONG_MAX)
-		return PyInt_FromLong(Py_SAFE_DOWNCAST(x, PY_LONG_LONG, long));
+		return PyLong_FromLong(Py_SAFE_DOWNCAST(x, PY_LONG_LONG, long));
 	return PyLong_FromLongLong(x);
 #else
 	return _PyLong_FromByteArray((const unsigned char *)p,
@@ -1111,7 +1106,7 @@
 		x = (x<<8) | bytes[--i];
 	} while (i > 0);
 	if (x <= LONG_MAX)
-		return PyInt_FromLong(Py_SAFE_DOWNCAST(x, unsigned PY_LONG_LONG, long));
+		return PyLong_FromLong(Py_SAFE_DOWNCAST(x, unsigned PY_LONG_LONG, long));
 	return PyLong_FromUnsignedLongLong(x);
 #else
 	return _PyLong_FromByteArray((const unsigned char *)p,
@@ -1258,7 +1253,7 @@
 	{'L',	4,		0,		lu_uint,	lp_uint},
 	{'q',	8,		0,		lu_longlong,	lp_longlong},
 	{'Q',	8,		0,		lu_ulonglong,	lp_ulonglong},
-	{'t',	1,		0,		bu_bool,	bp_bool}, /* Std rep not endian dep,
+	{'?',	1,		0,		bu_bool,	bp_bool}, /* Std rep not endian dep,
 		but potentially different from native rep -- reuse bx_bool funcs. */
 	{'f',	4,		0,		lu_float,	lp_float},
 	{'d',	8,		0,		lu_double,	lp_double},
@@ -1469,12 +1464,29 @@
 
 	assert(PyStruct_Check(self));
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, "S:Struct", kwlist,
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:Struct", kwlist,
 					 &o_format))
 		return -1;
 
-	Py_INCREF(o_format);
-	Py_XDECREF(soself->s_format);
+	if (PyUnicode_Check(o_format)) {
+		o_format = PyUnicode_AsASCIIString(o_format);
+		if (o_format == NULL)
+			return -1;
+	}
+	/* XXX support buffer interface, too */
+	else {
+		Py_INCREF(o_format);
+	}
+
+	if (!PyString_Check(o_format)) {
+		Py_DECREF(o_format);
+		PyErr_Format(PyExc_TypeError,
+			     "Struct() argument 1 must be bytes, not %.200s",
+			     Py_TYPE(o_format)->tp_name);
+		return -1;
+	}
+
+	Py_CLEAR(soself->s_format);
 	soself->s_format = o_format;
 
 	ret = prepare_s(soself);
@@ -1490,7 +1502,7 @@
 		PyMem_FREE(s->s_codes);
 	}
 	Py_XDECREF(s->s_format);
-	Py_Type(s)->tp_free((PyObject *)s);
+	Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 static PyObject *
@@ -1535,37 +1547,26 @@
 strings.");
 
 static PyObject *
-s_unpack(PyObject *self, PyObject *inputstr)
+s_unpack(PyObject *self, PyObject *input)
 {
-	char *start;
-	Py_ssize_t len;
-	PyObject *args=NULL, *result;
+	Py_buffer vbuf;
+	PyObject *result;
 	PyStructObject *soself = (PyStructObject *)self;
+
 	assert(PyStruct_Check(self));
 	assert(soself->s_codes != NULL);
-	if (inputstr == NULL)
-		goto fail;
-	if (PyString_Check(inputstr) &&
-		PyString_GET_SIZE(inputstr) == soself->s_size) {
-			return s_unpack_internal(soself, PyString_AS_STRING(inputstr));
-	}
-	args = PyTuple_Pack(1, inputstr);
-	if (args == NULL)
-		return NULL;
-	if (!PyArg_ParseTuple(args, "s#:unpack", &start, &len))
-		goto fail;
-	if (soself->s_size != len)
-		goto fail;
-	result = s_unpack_internal(soself, start);
-	Py_DECREF(args);
+	if (PyObject_GetBuffer(input, &vbuf, PyBUF_SIMPLE) < 0)
+		return NULL;
+	if (vbuf.len != soself->s_size) {
+		PyErr_Format(StructError,
+			     "unpack requires a bytes argument of length %zd",
+			     soself->s_size);
+                PyObject_ReleaseBuffer(input, &vbuf);
+		return NULL;
+	}
+	result = s_unpack_internal(soself, vbuf.buf);
+	PyObject_ReleaseBuffer(input, &vbuf);
 	return result;
-
-fail:
-	Py_XDECREF(args);
-	PyErr_Format(StructError,
-		"unpack requires a string argument of length %zd",
-		soself->s_size);
-	return NULL;
 }
 
 PyDoc_STRVAR(s_unpack_from__doc__,
@@ -1580,37 +1581,34 @@
 s_unpack_from(PyObject *self, PyObject *args, PyObject *kwds)
 {
 	static char *kwlist[] = {"buffer", "offset", 0};
-#if (PY_VERSION_HEX < 0x02050000)
-	static char *fmt = "z#|i:unpack_from";
-#else
-	static char *fmt = "z#|n:unpack_from";
-#endif
-	Py_ssize_t buffer_len = 0, offset = 0;
-	char *buffer = NULL;
+
+	PyObject *input;
+	Py_ssize_t offset = 0;
+	Py_buffer vbuf;
+	PyObject *result;
 	PyStructObject *soself = (PyStructObject *)self;
+
 	assert(PyStruct_Check(self));
 	assert(soself->s_codes != NULL);
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, fmt, kwlist,
-					 &buffer, &buffer_len, &offset))
+	if (!PyArg_ParseTupleAndKeywords(args, kwds,
+					 "O|n:unpack_from", kwlist,
+					 &input, &offset))
 		return NULL;
-
-	if (buffer == NULL) {
-		PyErr_Format(StructError,
-			"unpack_from requires a buffer argument");
+	if (PyObject_GetBuffer(input, &vbuf, PyBUF_SIMPLE) < 0)
 		return NULL;
-	}
-
 	if (offset < 0)
-		offset += buffer_len;
-
-	if (offset < 0 || (buffer_len - offset) < soself->s_size) {
+		offset += vbuf.len;
+	if (offset < 0 || vbuf.len - offset < soself->s_size) {
 		PyErr_Format(StructError,
 			"unpack_from requires a buffer of at least %zd bytes",
 			soself->s_size);
+                PyObject_ReleaseBuffer(input, &vbuf);
 		return NULL;
 	}
-	return s_unpack_internal(soself, buffer + offset);
+	result = s_unpack_internal(soself, (char*)vbuf.buf + offset);
+	PyObject_ReleaseBuffer(input, &vbuf);
+	return result;
 }
 
 
@@ -1781,7 +1779,7 @@
 	assert( buffer_len >= 0 );
 
 	/* Extract the offset from the first argument */
-	offset = PyInt_AsSsize_t(PyTuple_GET_ITEM(args, 1));
+	offset = PyLong_AsSsize_t(PyTuple_GET_ITEM(args, 1));
 
 	/* Support negative offsets. */
 	if (offset < 0)
@@ -1813,7 +1811,7 @@
 static PyObject *
 s_get_size(PyStructObject *self, void *unused)
 {
-    return PyInt_FromSsize_t(self->s_size);
+    return PyLong_FromSsize_t(self->s_size);
 }
 
 /* List of functions */
@@ -1880,22 +1878,235 @@
 	PyObject_Del,		/* tp_free */
 };
 
+
+/* ---- Standalone functions  ---- */
+
+#define MAXCACHE 100
+static PyObject *cache = NULL;
+
+static PyObject *
+cache_struct(PyObject *fmt)
+{
+	PyObject * s_object;
+
+	if (cache == NULL) {
+		cache = PyDict_New();
+		if (cache == NULL)
+			return NULL;
+	}
+
+	s_object = PyDict_GetItem(cache, fmt);
+	if (s_object != NULL) {
+		Py_INCREF(s_object);
+		return s_object;
+	}
+
+	s_object = PyObject_CallFunctionObjArgs((PyObject *)(&PyStructType), fmt, NULL);
+	if (s_object != NULL) {
+		if (PyDict_Size(cache) >= MAXCACHE)
+			PyDict_Clear(cache);
+		/* Attempt to cache the result */
+		if (PyDict_SetItem(cache, fmt, s_object) == -1)
+			PyErr_Clear();
+	}
+	return s_object;
+}
+
+PyDoc_STRVAR(clearcache_doc,
+"Clear the internal cache.");
+
+static PyObject *
+clearcache(PyObject *self)
+{
+	Py_CLEAR(cache);
+	Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(calcsize_doc,
+"Return size of C struct described by format string fmt.");
+
+static PyObject *
+calcsize(PyObject *self, PyObject *fmt)
+{
+	Py_ssize_t n;
+	PyObject *s_object = cache_struct(fmt);
+	if (s_object == NULL)
+		return NULL;
+	n = ((PyStructObject *)s_object)->s_size;
+	Py_DECREF(s_object);
+    	return PyLong_FromSsize_t(n);
+}
+
+PyDoc_STRVAR(pack_doc,
+"Return string containing values v1, v2, ... packed according to fmt.");
+
+static PyObject *
+pack(PyObject *self, PyObject *args)
+{
+	PyObject *s_object, *fmt, *newargs, *result;
+	Py_ssize_t n = PyTuple_GET_SIZE(args);
+
+	if (n == 0) {
+		PyErr_SetString(PyExc_TypeError, "missing format argument");
+		return NULL;
+	}
+	fmt = PyTuple_GET_ITEM(args, 0);
+	newargs = PyTuple_GetSlice(args, 1, n);
+	if (newargs == NULL)
+		return NULL;
+
+	s_object = cache_struct(fmt);
+	if (s_object == NULL) {
+		Py_DECREF(newargs);
+		return NULL;
+	}
+    	result = s_pack(s_object, newargs);
+	Py_DECREF(newargs);
+	Py_DECREF(s_object);
+	return result;
+}
+
+PyDoc_STRVAR(pack_into_doc,
+"Pack the values v1, v2, ... according to fmt.\n\
+Write the packed bytes into the writable buffer buf starting at offset.");
+
+static PyObject *
+pack_into(PyObject *self, PyObject *args)
+{
+	PyObject *s_object, *fmt, *newargs, *result;
+	Py_ssize_t n = PyTuple_GET_SIZE(args);
+
+	if (n == 0) {
+		PyErr_SetString(PyExc_TypeError, "missing format argument");
+		return NULL;
+	}
+	fmt = PyTuple_GET_ITEM(args, 0);
+	newargs = PyTuple_GetSlice(args, 1, n);
+	if (newargs == NULL)
+		return NULL;
+
+	s_object = cache_struct(fmt);
+	if (s_object == NULL) {
+		Py_DECREF(newargs);
+		return NULL;
+	}
+    	result = s_pack_into(s_object, newargs);
+	Py_DECREF(newargs);
+	Py_DECREF(s_object);
+	return result;
+}
+
+PyDoc_STRVAR(unpack_doc,
+"Unpack the string containing packed C structure data, according to fmt.\n\
+Requires len(string) == calcsize(fmt).");
+
+static PyObject *
+unpack(PyObject *self, PyObject *args)
+{
+	PyObject *s_object, *fmt, *inputstr, *result;
+
+	if (!PyArg_UnpackTuple(args, "unpack", 2, 2, &fmt, &inputstr))
+		return NULL;
+
+	s_object = cache_struct(fmt);
+	if (s_object == NULL)
+		return NULL;
+    	result = s_unpack(s_object, inputstr);
+	Py_DECREF(s_object);
+	return result;
+}
+
+PyDoc_STRVAR(unpack_from_doc,
+"Unpack the buffer, containing packed C structure data, according to\n\
+fmt, starting at offset. Requires len(buffer[offset:]) >= calcsize(fmt).");
+
+static PyObject *
+unpack_from(PyObject *self, PyObject *args, PyObject *kwds)
+{
+	PyObject *s_object, *fmt, *newargs, *result;
+	Py_ssize_t n = PyTuple_GET_SIZE(args);
+
+	if (n == 0) {
+		PyErr_SetString(PyExc_TypeError, "missing format argument");
+		return NULL;
+	}
+	fmt = PyTuple_GET_ITEM(args, 0);
+	newargs = PyTuple_GetSlice(args, 1, n);
+	if (newargs == NULL)
+		return NULL;
+
+	s_object = cache_struct(fmt);
+	if (s_object == NULL) {
+		Py_DECREF(newargs);
+		return NULL;
+	}
+    	result = s_unpack_from(s_object, newargs, kwds);
+	Py_DECREF(newargs);
+	Py_DECREF(s_object);
+	return result;
+}
+
+static struct PyMethodDef module_functions[] = {
+	{"_clearcache",	(PyCFunction)clearcache,	METH_NOARGS, 	clearcache_doc},
+	{"calcsize",	calcsize,	METH_O, 	calcsize_doc},
+	{"pack",	pack,		METH_VARARGS, 	pack_doc},
+	{"pack_into",	pack_into,	METH_VARARGS, 	pack_into_doc},
+	{"unpack",	unpack,       	METH_VARARGS, 	unpack_doc},
+	{"unpack_from",	(PyCFunction)unpack_from, 	
+			METH_VARARGS|METH_KEYWORDS, 	unpack_from_doc},
+	{NULL,	 NULL}		/* sentinel */
+};
+
+
 /* Module initialization */
 
+PyDoc_STRVAR(module_doc,
+"Functions to convert between Python values and C structs.\n\
+Python strings are used to hold the data representing the C struct\n\
+and also as format strings to describe the layout of data in the C struct.\n\
+\n\
+The optional first format char indicates byte order, size and alignment:\n\
+ @: native order, size & alignment (default)\n\
+ =: native order, std. size & alignment\n\
+ <: little-endian, std. size & alignment\n\
+ >: big-endian, std. size & alignment\n\
+ !: same as >\n\
+\n\
+The remaining chars indicate types of args and must match exactly;\n\
+these can be preceded by a decimal repeat count:\n\
+  x: pad byte (no data); c:char; b:signed byte; B:unsigned byte;\n\
+  h:short; H:unsigned short; i:int; I:unsigned int;\n\
+  l:long; L:unsigned long; f:float; d:double.\n\
+Special cases (preceding decimal count indicates length):\n\
+  s:string (array of char); p: pascal string (with count byte).\n\
+Special case (only available in native format):\n\
+  P:an integer type that is wide enough to hold a pointer.\n\
+Special case (not in native mode unless 'long long' in platform C):\n\
+  q:long long; Q:unsigned long long\n\
+Whitespace between formats is ignored.\n\
+\n\
+The variable struct.error is an exception raised on errors.\n");
+
 PyMODINIT_FUNC
 init_struct(void)
 {
-	PyObject *m = Py_InitModule("_struct", NULL);
+	PyObject *ver, *m;
+
+	ver = PyString_FromString("0.2");
+	if (ver == NULL)
+		return;
+
+	m = Py_InitModule3("_struct", module_functions, module_doc);
 	if (m == NULL)
 		return;
 
-	Py_Type(&PyStructType) = &PyType_Type;
+	Py_TYPE(&PyStructType) = &PyType_Type;
 	if (PyType_Ready(&PyStructType) < 0)
 		return;
 
 #ifdef PY_STRUCT_OVERFLOW_MASKING
 	if (pyint_zero == NULL) {
-		pyint_zero = PyInt_FromLong(0);
+		pyint_zero = PyLong_FromLong(0);
 		if (pyint_zero == NULL)
 			return;
 	}
@@ -1966,6 +2177,8 @@
 	Py_INCREF((PyObject*)&PyStructType);
 	PyModule_AddObject(m, "Struct", (PyObject*)&PyStructType);
 
+	PyModule_AddObject(m, "__version__", ver);
+
 	PyModule_AddIntConstant(m, "_PY_STRUCT_RANGE_CHECKING", 1);
 #ifdef PY_STRUCT_OVERFLOW_MASKING
 	PyModule_AddIntConstant(m, "_PY_STRUCT_OVERFLOW_MASKING", 1);

Modified: python/branches/py3k-importlib/Modules/_testcapimodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_testcapimodule.c	(original)
+++ python/branches/py3k-importlib/Modules/_testcapimodule.c	Thu Mar 27 00:48:05 2008
@@ -5,6 +5,8 @@
  * standard Python regression test, via Lib/test/test_capi.py.
  */
 
+#define PY_SSIZE_T_CLEAN
+
 #include "Python.h"
 #include <float.h>
 #include "structmember.h"
@@ -83,7 +85,7 @@
 		return (PyObject*)NULL;
 	/* list = range(NLIST) */
 	for (i = 0; i < NLIST; ++i) {
-		PyObject* anint = PyInt_FromLong(i);
+		PyObject* anint = PyLong_FromLong(i);
 		if (anint == (PyObject*)NULL) {
 			Py_DECREF(list);
 			return (PyObject*)NULL;
@@ -99,7 +101,7 @@
 	/* Check that list == range(29, -1, -1) now */
 	for (i = 0; i < NLIST; ++i) {
 		PyObject* anint = PyList_GET_ITEM(list, i);
-		if (PyInt_AS_LONG(anint) != NLIST-1-i) {
+		if (PyLong_AS_LONG(anint) != NLIST-1-i) {
 			PyErr_SetString(TestError,
 			                "test_list_api: reverse screwed up");
 			Py_DECREF(list);
@@ -125,7 +127,7 @@
 		return -1;
 
 	for (i = 0; i < count; i++) {
-		v = PyInt_FromLong(i);
+		v = PyLong_FromLong(i);
 		PyDict_SetItem(dict, v, v);
 		Py_DECREF(v);
 	}
@@ -134,8 +136,8 @@
 		PyObject *o;
 		iterations++;
 
-		i = PyInt_AS_LONG(v) + 1;
-		o = PyInt_FromLong(i);
+		i = PyLong_AS_LONG(v) + 1;
+		o = PyLong_FromLong(i);
 		if (o == NULL)
 			return -1;
 		if (PyDict_SetItem(dict, k, o) < 0) {
@@ -276,7 +278,7 @@
 			"L code returned wrong value for long 42");
 
 	Py_DECREF(num);
-        num = PyInt_FromLong(42);
+        num = PyLong_FromLong(42);
         if (num == NULL)
         	return NULL;
 
@@ -306,6 +308,22 @@
 	return Py_BuildValue("iii", a, b, c);
 }
 
+/* test PyArg_ParseTupleAndKeywords */
+static PyObject *getargs_keywords(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+	static char *keywords[] = {"arg1","arg2","arg3","arg4","arg5", NULL};
+	static char *fmt="(ii)i|(i(ii))(iii)i";
+	int int_args[10]={-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords,
+		&int_args[0], &int_args[1], &int_args[2], &int_args[3], &int_args[4],
+		&int_args[5], &int_args[6], &int_args[7], &int_args[8], &int_args[9]))
+		return NULL;
+	return Py_BuildValue("iiiiiiiiii",
+		int_args[0], int_args[1], int_args[2], int_args[3], int_args[4],
+		int_args[5], int_args[6], int_args[7], int_args[8], int_args[9]);
+}
+
 /* Functions to call PyArg_ParseTuple with integer format codes,
    and return the result.
 */
@@ -377,8 +395,8 @@
 {
 	Py_ssize_t value;
 	if (!PyArg_ParseTuple(args, "n", &value))
-	return NULL;
-	return PyInt_FromSsize_t(value);
+		return NULL;
+	return PyLong_FromSsize_t(value);
 }
 
 #ifdef HAVE_LONG_LONG
@@ -402,7 +420,7 @@
 #endif
 
 /* This function not only tests the 'k' getargs code, but also the
-   PyInt_AsUnsignedLongMask() and PyInt_AsUnsignedLongMask() functions. */
+   PyLong_AsUnsignedLongMask() and PyLong_AsUnsignedLongMask() functions. */
 static PyObject *
 test_k_code(PyObject *self)
 {
@@ -418,10 +436,10 @@
         if (num == NULL)
         	return NULL;
 
-	value = PyInt_AsUnsignedLongMask(num);
+	value = PyLong_AsUnsignedLongMask(num);
 	if (value != ULONG_MAX)
         	return raiseTestError("test_k_code",
-	    "PyInt_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
+	    "PyLong_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
 
         PyTuple_SET_ITEM(tuple, 0, num);
 
@@ -437,10 +455,10 @@
         if (num == NULL)
         	return NULL;
 
-	value = PyInt_AsUnsignedLongMask(num);
+	value = PyLong_AsUnsignedLongMask(num);
 	if (value != (unsigned long)-0x42)
         	return raiseTestError("test_k_code",
-	    "PyInt_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
+	    "PyLong_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
 
         PyTuple_SET_ITEM(tuple, 0, num);
 
@@ -465,7 +483,7 @@
 {
 	PyObject *tuple, *obj;
 	Py_UNICODE *value;
-	int len;
+	Py_ssize_t len;
 
         tuple = PyTuple_New(1);
         if (tuple == NULL)
@@ -503,7 +521,7 @@
 {
 	PyObject *tuple, *obj;
 	Py_UNICODE *value1, *value2;
-	int len1, len2;
+	Py_ssize_t len1, len2;
 
         tuple = PyTuple_New(2);
         if (tuple == NULL)
@@ -613,12 +631,12 @@
 	return Py_None;
 }
 
-/* Example passing NULLs to PyObject_Str(NULL) and PyObject_Unicode(NULL). */
+/* Example passing NULLs to PyObject_Str(NULL). */
 
 static PyObject *
 test_null_strings(PyObject *self)
 {
-	PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Unicode(NULL);
+	PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Str(NULL);
 	PyObject *tuple = PyTuple_Pack(2, o1, o2);
 	Py_XDECREF(o1);
 	Py_XDECREF(o2);
@@ -640,7 +658,7 @@
 	if (exc_args == NULL)
 		return NULL;
 	for (i = 0; i < num_args; ++i) {
-		v = PyInt_FromLong(i);
+		v = PyLong_FromLong(i);
 		if (v == NULL) {
 			Py_DECREF(exc_args);
 			return NULL;
@@ -794,7 +812,7 @@
 	gettimeofday(&start, NULL);
 	for(k=0; k < 20000; k++)
 		for(i=0; i < 1000; i++) {
-			single = PyInt_FromLong(i);
+			single = PyLong_FromLong(i);
 			Py_DECREF(single);
 		}
 	gettimeofday(&stop, NULL);
@@ -805,7 +823,7 @@
 	gettimeofday(&start, NULL);
 	for(k=0; k < 20000; k++)
 		for(i=0; i < 1000; i++) {
-			single = PyInt_FromLong(i+1000000);
+			single = PyLong_FromLong(i+1000000);
 			Py_DECREF(single);
 		}
 	gettimeofday(&stop, NULL);
@@ -817,7 +835,7 @@
 	gettimeofday(&start, NULL);
 	for(k=0; k < 20000; k++) {
 		for(i=0; i < 1000; i++) {
-			multiple[i] = PyInt_FromLong(i+1000000);
+			multiple[i] = PyLong_FromLong(i+1000000);
 		}
 		for(i=0; i < 1000; i++) {
 			Py_DECREF(multiple[i]);
@@ -832,7 +850,7 @@
 	gettimeofday(&start, NULL);
 	for(k=0; k < 20; k++) {
 		for(i=0; i < 1000000; i++) {
-			multiple[i] = PyInt_FromLong(i+1000000);
+			multiple[i] = PyLong_FromLong(i+1000000);
 		}
 		for(i=0; i < 1000000; i++) {
 			Py_DECREF(multiple[i]);
@@ -846,7 +864,7 @@
 	gettimeofday(&start, NULL);
 	for(k=0; k < 10; k++) {
 		for(i=0; i < 1000000; i++) {
-			multiple[i] = PyInt_FromLong(i+1000);
+			multiple[i] = PyLong_FromLong(i+1000);
 		}
 		for(i=0; i < 1000000; i++) {
 			Py_DECREF(multiple[i]);
@@ -856,7 +874,7 @@
 	print_delta(5, &start, &stop);
 
 	/* Test 6: Perform small int addition */
-	op1 = PyInt_FromLong(1);
+	op1 = PyLong_FromLong(1);
 	gettimeofday(&start, NULL);
 	for(i=0; i < 10000000; i++) {
 		result = PyNumber_Add(op1, op1);
@@ -867,7 +885,7 @@
 	print_delta(6, &start, &stop);
 
 	/* Test 7: Perform medium int addition */
-	op1 = PyInt_FromLong(1000);
+	op1 = PyLong_FromLong(1000);
 	gettimeofday(&start, NULL);
 	for(i=0; i < 10000000; i++) {
 		result = PyNumber_Add(op1, op1);
@@ -896,6 +914,8 @@
 	 PyDoc_STR("This is a pretty normal docstring.")},
 
 	{"getargs_tuple",	getargs_tuple,			 METH_VARARGS},
+	{"getargs_keywords", (PyCFunction)getargs_keywords, 
+	  METH_VARARGS|METH_KEYWORDS},
 	{"getargs_b",		getargs_b,			 METH_VARARGS},
 	{"getargs_B",		getargs_B,			 METH_VARARGS},
 	{"getargs_H",		getargs_H,			 METH_VARARGS},
@@ -928,6 +948,7 @@
 #define AddSym(d, n, f, v) {PyObject *o = f(v); PyDict_SetItemString(d, n, o); Py_DECREF(o);}
 
 typedef struct {
+	char bool_member;
 	char byte_member;
 	unsigned char ubyte_member;
 	short short_member;
@@ -950,6 +971,7 @@
 } test_structmembers;
 
 static struct PyMemberDef test_members[] = {
+	{"T_BOOL", T_BOOL, offsetof(test_structmembers, structmembers.bool_member), 0, NULL},
 	{"T_BYTE", T_BYTE, offsetof(test_structmembers, structmembers.byte_member), 0, NULL},
 	{"T_UBYTE", T_UBYTE, offsetof(test_structmembers, structmembers.ubyte_member), 0, NULL},
 	{"T_SHORT", T_SHORT, offsetof(test_structmembers, structmembers.short_member), 0, NULL},
@@ -968,39 +990,53 @@
 };
 
 
-static PyObject *test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs){
-	static char *keywords[]={"T_BYTE", "T_UBYTE", "T_SHORT", "T_USHORT", "T_INT", "T_UINT",
-		"T_LONG", "T_ULONG", "T_FLOAT", "T_DOUBLE",
-		#ifdef HAVE_LONG_LONG	
+static PyObject *
+test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+	static char *keywords[] = {
+		"T_BOOL", "T_BYTE", "T_UBYTE", "T_SHORT", "T_USHORT",
+		"T_INT", "T_UINT", "T_LONG", "T_ULONG",
+		"T_FLOAT", "T_DOUBLE",
+#ifdef HAVE_LONG_LONG	
 		"T_LONGLONG", "T_ULONGLONG",
-		#endif
+#endif
 		NULL};
-	static char *fmt="|bBhHiIlkfd"
-		#ifdef HAVE_LONG_LONG
+	static char *fmt = "|bbBhHiIlkfd"
+#ifdef HAVE_LONG_LONG
 		"LK"
-		#endif
+#endif
 		;
-	test_structmembers *ob=PyObject_New(test_structmembers, type);
-	if (ob==NULL)
+	test_structmembers *ob;
+	ob = PyObject_New(test_structmembers, type);
+	if (ob == NULL)
 		return NULL;
 	memset(&ob->structmembers, 0, sizeof(all_structmembers));
 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords,
-		&ob->structmembers.byte_member, &ob->structmembers.ubyte_member,
-		&ob->structmembers.short_member, &ob->structmembers.ushort_member,
-		&ob->structmembers.int_member, &ob->structmembers.uint_member, 
-		&ob->structmembers.long_member, &ob->structmembers.ulong_member,
-		&ob->structmembers.float_member, &ob->structmembers.double_member
-		#ifdef HAVE_LONG_LONG
-		,&ob->structmembers.longlong_member, &ob->structmembers.ulonglong_member
-		#endif
-		)){
+					 &ob->structmembers.bool_member,
+					 &ob->structmembers.byte_member,
+					 &ob->structmembers.ubyte_member,
+					 &ob->structmembers.short_member,
+					 &ob->structmembers.ushort_member,
+					 &ob->structmembers.int_member,
+					 &ob->structmembers.uint_member, 
+					 &ob->structmembers.long_member,
+					 &ob->structmembers.ulong_member,
+					 &ob->structmembers.float_member,
+					 &ob->structmembers.double_member
+#ifdef HAVE_LONG_LONG
+					 , &ob->structmembers.longlong_member,
+					 &ob->structmembers.ulonglong_member
+#endif
+		)) {
 		Py_DECREF(ob);
 		return NULL;
-		}
+	}
 	return (PyObject *)ob;
 }
 
-static void test_structmembers_free(PyObject *ob){
+static void
+test_structmembers_free(PyObject *ob)
+{
 	PyObject_FREE(ob);
 }
 
@@ -1021,8 +1057,8 @@
 	0,				/* tp_hash */
 	0,				/* tp_call */
 	0,				/* tp_str */
-	PyObject_GenericGetAttr,
-	PyObject_GenericSetAttr,
+	PyObject_GenericGetAttr,	/* tp_getattro */
+	PyObject_GenericSetAttr,	/* tp_setattro */
 	0,				/* tp_as_buffer */
 	0,				/* tp_flags */
 	"Type containing all structmember types",
@@ -1033,7 +1069,7 @@
 	0,				/* tp_iter */
 	0,				/* tp_iternext */
 	0,				/* tp_methods */
-	test_members,	/* tp_members */
+	test_members,			/* tp_members */
 	0,
 	0,
 	0,
@@ -1042,7 +1078,7 @@
 	0,
 	0,
 	0,
-	test_structmembers_new,			/* tp_new */
+	test_structmembers_new,	       	/* tp_new */
 };
 
 
@@ -1055,21 +1091,21 @@
 	if (m == NULL)
 		return;
 
-	Py_Type(&test_structmembersType)=&PyType_Type;
+	Py_TYPE(&test_structmembersType)=&PyType_Type;
 	Py_INCREF(&test_structmembersType);
 	PyModule_AddObject(m, "test_structmembersType", (PyObject *)&test_structmembersType);
 
-	PyModule_AddObject(m, "CHAR_MAX", PyInt_FromLong(CHAR_MAX));
-	PyModule_AddObject(m, "CHAR_MIN", PyInt_FromLong(CHAR_MIN));
-	PyModule_AddObject(m, "UCHAR_MAX", PyInt_FromLong(UCHAR_MAX));
-	PyModule_AddObject(m, "SHRT_MAX", PyInt_FromLong(SHRT_MAX));
-	PyModule_AddObject(m, "SHRT_MIN", PyInt_FromLong(SHRT_MIN));
-	PyModule_AddObject(m, "USHRT_MAX", PyInt_FromLong(USHRT_MAX));
+	PyModule_AddObject(m, "CHAR_MAX", PyLong_FromLong(CHAR_MAX));
+	PyModule_AddObject(m, "CHAR_MIN", PyLong_FromLong(CHAR_MIN));
+	PyModule_AddObject(m, "UCHAR_MAX", PyLong_FromLong(UCHAR_MAX));
+	PyModule_AddObject(m, "SHRT_MAX", PyLong_FromLong(SHRT_MAX));
+	PyModule_AddObject(m, "SHRT_MIN", PyLong_FromLong(SHRT_MIN));
+	PyModule_AddObject(m, "USHRT_MAX", PyLong_FromLong(USHRT_MAX));
 	PyModule_AddObject(m, "INT_MAX",  PyLong_FromLong(INT_MAX));
 	PyModule_AddObject(m, "INT_MIN",  PyLong_FromLong(INT_MIN));
 	PyModule_AddObject(m, "UINT_MAX",  PyLong_FromUnsignedLong(UINT_MAX));
-	PyModule_AddObject(m, "LONG_MAX", PyInt_FromLong(LONG_MAX));
-	PyModule_AddObject(m, "LONG_MIN", PyInt_FromLong(LONG_MIN));
+	PyModule_AddObject(m, "LONG_MAX", PyLong_FromLong(LONG_MAX));
+	PyModule_AddObject(m, "LONG_MIN", PyLong_FromLong(LONG_MIN));
 	PyModule_AddObject(m, "ULONG_MAX", PyLong_FromUnsignedLong(ULONG_MAX));
 	PyModule_AddObject(m, "FLT_MAX", PyFloat_FromDouble(FLT_MAX));
 	PyModule_AddObject(m, "FLT_MIN", PyFloat_FromDouble(FLT_MIN));
@@ -1078,8 +1114,8 @@
 	PyModule_AddObject(m, "LLONG_MAX", PyLong_FromLongLong(PY_LLONG_MAX));
 	PyModule_AddObject(m, "LLONG_MIN", PyLong_FromLongLong(PY_LLONG_MIN));
 	PyModule_AddObject(m, "ULLONG_MAX", PyLong_FromUnsignedLongLong(PY_ULLONG_MAX));
-	PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyInt_FromSsize_t(PY_SSIZE_T_MAX));
-	PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyInt_FromSsize_t(PY_SSIZE_T_MIN));
+	PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyLong_FromSsize_t(PY_SSIZE_T_MAX));
+	PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyLong_FromSsize_t(PY_SSIZE_T_MIN));
 
 	TestError = PyErr_NewException("_testcapi.error", NULL, NULL);
 	Py_INCREF(TestError);

Modified: python/branches/py3k-importlib/Modules/_tkinter.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_tkinter.c	(original)
+++ python/branches/py3k-importlib/Modules/_tkinter.c	Thu Mar 27 00:48:05 2008
@@ -44,7 +44,7 @@
 
 #ifndef PyBool_Check
 #define PyBool_Check(o)       0
-#define PyBool_FromLong       PyInt_FromLong
+#define PyBool_FromLong       PyLong_FromLong
 #endif
 
 /* Starting with Tcl 8.4, many APIs offer const-correctness.  Unfortunately,
@@ -83,8 +83,8 @@
 /* Unicode conversion assumes that Tcl_UniChar is two bytes.
    We cannot test this directly, so we test UTF-8 size instead,
    expecting that TCL_UTF_MAX is changed if Tcl ever supports
-   either UTF-16 or UCS-4.  
-   Redhat 8 sets TCL_UTF_MAX to 6, and uses wchar_t for 
+   either UTF-16 or UCS-4.
+   Redhat 8 sets TCL_UTF_MAX to 6, and uses wchar_t for
    Tcl_Unichar. This is also ok as long as Python uses UCS-4,
    as well.
 */
@@ -262,12 +262,12 @@
 	Tcl_ObjType *StringType;
 } TkappObject;
 
-#define Tkapp_Check(v) (Py_Type(v) == &Tkapp_Type)
+#define Tkapp_Check(v) (Py_TYPE(v) == &Tkapp_Type)
 #define Tkapp_Interp(v) (((TkappObject *) (v))->interp)
 #define Tkapp_Result(v) Tcl_GetStringResult(Tkapp_Interp(v))
 
 #define DEBUG_REFCNT(v) (printf("DEBUG: id=%p, refcnt=%i\n", \
-(void *) v, Py_Refcnt(v)))
+(void *) v, Py_REFCNT(v)))
 
 
 
@@ -749,8 +749,8 @@
 }
 
 /* Like _str, but create Unicode if necessary. */
-PyDoc_STRVAR(PyTclObject_string__doc__, 
-"the string representation of this object, either as str8 or str");
+PyDoc_STRVAR(PyTclObject_string__doc__,
+"the string representation of this object, either as str or bytes");
 
 static PyObject *
 PyTclObject_string(PyTclObject *self, void *ignored)
@@ -810,7 +810,7 @@
 
 static PyGetSetDef PyTclObject_getsetlist[] = {
 	{"typename", (getter)get_typename, NULL, get_typename__doc__},
-	{"string", (getter)PyTclObject_string, NULL, 
+	{"string", (getter)PyTclObject_string, NULL,
 	 PyTclObject_string__doc__},
 	{0},
 };
@@ -863,14 +863,21 @@
 AsObj(PyObject *value)
 {
 	Tcl_Obj *result;
+	long longVal;
+	int overflow;
 
 	if (PyString_Check(value))
 		return Tcl_NewStringObj(PyString_AS_STRING(value),
 					PyString_GET_SIZE(value));
 	else if (PyBool_Check(value))
 		return Tcl_NewBooleanObj(PyObject_IsTrue(value));
-	else if (PyInt_CheckExact(value))
-		return Tcl_NewLongObj(PyInt_AS_LONG(value));
+	else if (PyLong_CheckExact(value) &&
+		 ((longVal = PyLong_AsLongAndOverflow(value, &overflow)),
+		  !overflow)) {
+		/* If there is an overflow in the long conversion,
+		   fall through to default object handling. */
+		return Tcl_NewLongObj(longVal);
+	}
 	else if (PyFloat_Check(value))
 		return Tcl_NewDoubleObj(PyFloat_AS_DOUBLE(value));
 	else if (PyTuple_Check(value)) {
@@ -891,10 +898,12 @@
 		/* This #ifdef assumes that Tcl uses UCS-2.
 		   See TCL_UTF_MAX test above. */
 #if defined(Py_UNICODE_WIDE) && TCL_UTF_MAX == 3
-		Tcl_UniChar *outbuf;
+		Tcl_UniChar *outbuf = NULL;
 		Py_ssize_t i;
-		assert(size < size * sizeof(Tcl_UniChar));
-		outbuf = (Tcl_UniChar*)ckalloc(size * sizeof(Tcl_UniChar));
+		size_t allocsize = ((size_t)size) * sizeof(Tcl_UniChar);
+		if (allocsize >= size)
+			outbuf = (Tcl_UniChar*)ckalloc(allocsize);
+		/* Else overflow occurred, and we take the next exit */
 		if (!outbuf) {
 			PyErr_NoMemory();
 			return NULL;
@@ -921,7 +930,7 @@
 		Tcl_Obj *v = ((PyTclObject*)value)->value;
 		Tcl_IncrRefCount(v);
 		return v;
-	} 
+	}
 	else {
 		PyObject *v = PyObject_Str(value);
 		if (!v)
@@ -939,7 +948,7 @@
 	TkappObject *app = (TkappObject*)tkapp;
 
 	if (value->typePtr == NULL) {
-		return PyUnicode_FromStringAndSize(value->bytes, 
+		return PyUnicode_FromStringAndSize(value->bytes,
 						   value->length);
 	}
 
@@ -952,7 +961,7 @@
 	if (value->typePtr == app->ByteArrayType) {
 		int size;
 		char *data = (char*)Tcl_GetByteArrayFromObj(value, &size);
-		return PyBytes_FromStringAndSize(data, size);
+		return PyString_FromStringAndSize(data, size);
 	}
 
 	if (value->typePtr == app->DoubleType) {
@@ -960,7 +969,7 @@
 	}
 
 	if (value->typePtr == app->IntType) {
-		return PyInt_FromLong(value->internalRep.longValue);
+		return PyLong_FromLong(value->internalRep.longValue);
 	}
 
 	if (value->typePtr == app->ListType) {
@@ -1219,7 +1228,7 @@
 				PyErr_SetObject(Tkinter_TclError, exc_value);
 		}
 	}
-	else 
+	else
 #endif
 	{
 
@@ -1424,7 +1433,7 @@
 	}
 	/* XXX: Should give diagnostics. */
 	return 0;
-}	
+}
 
 void
 var_perform(VarEvent *ev)
@@ -1438,7 +1447,7 @@
 		*(ev->exc_val) = val;
 		Py_DECREF(tb);
 	}
-		
+
 }
 
 static int
@@ -1462,7 +1471,7 @@
 		TkappObject *self = (TkappObject*)selfptr;
 		VarEvent *ev;
 		PyObject *res, *exc_type, *exc_val;
-		
+
 		/* The current thread is not the interpreter thread.  Marshal
 		   the call to the interpreter thread, then wait for
 		   completion. */
@@ -1502,14 +1511,14 @@
 	PyObject *res = NULL;
 	Tcl_Obj *newval, *ok;
 
-	if (PyArg_ParseTuple(args, "O&O:setvar", 
+	if (PyArg_ParseTuple(args, "O&O:setvar",
 			     varname_converter, &name1, &newValue)) {
 		/* XXX Acquire tcl lock??? */
 		newval = AsObj(newValue);
 		if (newval == NULL)
 			return NULL;
 		ENTER_TCL
-		ok = Tcl_SetVar2Ex(Tkapp_Interp(self), name1, NULL, 
+		ok = Tcl_SetVar2Ex(Tkapp_Interp(self), name1, NULL,
 				   newval, flags);
 		ENTER_OVERLAP
 		if (!ok)
@@ -1565,7 +1574,7 @@
 	PyObject *res = NULL;
 	Tcl_Obj *tres;
 
-	if (!PyArg_ParseTuple(args, "O&|s:getvar", 
+	if (!PyArg_ParseTuple(args, "O&|s:getvar",
 			      varname_converter, &name1, &name2))
 		return NULL;
 
@@ -1647,7 +1656,7 @@
 
 	if (PyTuple_Size(args) == 1) {
 		PyObject* o = PyTuple_GetItem(args, 0);
-		if (PyInt_Check(o)) {
+		if (PyLong_Check(o)) {
 			Py_INCREF(o);
 			return o;
 		}
@@ -1687,7 +1696,7 @@
 
 	if (PyTuple_Size(args) == 1) {
 		PyObject *o = PyTuple_GetItem(args, 0);
-		if (PyInt_Check(o)) {
+		if (PyLong_Check(o)) {
 			Py_INCREF(o);
 			return o;
 		}
@@ -1708,7 +1717,7 @@
 
 	if (!PyArg_ParseTuple(args, "s:exprstring", &s))
 		return NULL;
-	
+
 	CHECK_TCL_APPARTMENT;
 
 	ENTER_TCL
@@ -1813,7 +1822,7 @@
 	if (!PyArg_ParseTuple(args, "et:splitlist", "utf-8", &list))
 		return NULL;
 
-	if (Tcl_SplitList(Tkapp_Interp(self), list, 
+	if (Tcl_SplitList(Tkapp_Interp(self), list,
 			  &argc, &argv) == TCL_ERROR)  {
 		PyMem_Free(list);
 		return Tkinter_Error(self);
@@ -1899,7 +1908,7 @@
 	PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData;
 	PyObject *self, *func, *arg, *res, *s;
 	int i, rv;
-	Tcl_Obj *tres;
+	Tcl_Obj *obj_res;
 
 	ENTER_PYTHON
 
@@ -1932,13 +1941,13 @@
 	if (res == NULL)
 		return PythonCmd_Error(interp);
 
-	tres = AsObj(res);
-	if (tres == NULL) {
+	obj_res = AsObj(res);
+	if (obj_res == NULL) {
 		Py_DECREF(res);
 		return PythonCmd_Error(interp);
 	}
 	else {
-		Tcl_SetObjResult(Tkapp_Interp(self), tres);
+		Tcl_SetObjResult(Tkapp_Interp(self), obj_res);
 		rv = TCL_OK;
 	}
 
@@ -2020,7 +2029,7 @@
 	Py_INCREF(func);
 	data->self = selfptr;
 	data->func = func;
-	
+
 	if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
 		CommandEvent *ev = (CommandEvent*)ckalloc(sizeof(CommandEvent));
 		ev->ev.proc = (Tcl_EventProc*)Tkapp_CommandProc;
@@ -2069,7 +2078,7 @@
 		ev->name = cmdName;
 		ev->status = &err;
 		ev->done = NULL;
-		Tkapp_ThreadSend(self, (Tcl_Event*)ev, &ev->done, 
+		Tkapp_ThreadSend(self, (Tcl_Event*)ev, &ev->done,
 				 &command_mutex);
 	}
 	else {
@@ -2282,7 +2291,7 @@
 Tktt_New(PyObject *func)
 {
 	TkttObject *v;
-  
+
 	v = PyObject_New(TkttObject, &Tktt_Type);
 	if (v == NULL)
 		return NULL;
@@ -2527,7 +2536,7 @@
 	if (!PyArg_ParseTuple(args, ":interpaddr"))
 		return NULL;
 
-	return PyInt_FromLong((long)Tkapp_Interp(self));
+	return PyLong_FromLong((long)Tkapp_Interp(self));
 }
 
 static PyObject	*
@@ -2545,11 +2554,11 @@
 	   To avoid the deadlock, we just refuse the second call through
 	   a static variable. */
 	if (has_failed) {
-		PyErr_SetString(Tkinter_TclError, 
+		PyErr_SetString(Tkinter_TclError,
 				"Calling Tk_Init again after a previous call failed might deadlock");
 		return NULL;
 	}
-	   
+
 	/* We want to guard against calling Tk_Init() multiple times */
 	CHECK_TCL_APPARTMENT;
 	ENTER_TCL
@@ -2783,11 +2792,11 @@
 	context.maxsize = PySequence_Size(item);
 	if (context.maxsize <= 0)
 		return PyTuple_New(0);
-	
+
 	context.tuple = PyTuple_New(context.maxsize);
 	if (!context.tuple)
 		return NULL;
-	
+
 	context.size = 0;
 
 	if (!_flatten1(&context, item,0))
@@ -2817,14 +2826,14 @@
 	else
 		baseName = Py_GetProgramName();
 	className = "Tk";
-  
+
 	if (!PyArg_ParseTuple(args, "|zssiiiiz:create",
 			      &screenName, &baseName, &className,
 			      &interactive, &wantobjects, &wantTk,
 			      &sync, &use))
 		return NULL;
 
-	return (PyObject *) Tkapp_New(screenName, baseName, className, 
+	return (PyObject *) Tkapp_New(screenName, baseName, className,
 				      interactive, wantobjects,	wantTk,
 				      sync, use);
 }
@@ -2856,7 +2865,7 @@
 static PyObject *
 Tkinter_getbusywaitinterval(PyObject *self, PyObject *args)
 {
-        return PyInt_FromLong(Tkinter_busywaitinterval);
+        return PyLong_FromLong(Tkinter_busywaitinterval);
 }
 
 static char getbusywaitinterval_doc[] =
@@ -2987,7 +2996,7 @@
 static void
 ins_long(PyObject *d, char *name, long val)
 {
-	PyObject *v = PyInt_FromLong(val);
+	PyObject *v = PyLong_FromLong(val);
 	if (v) {
 		PyDict_SetItemString(d, name, v);
 		Py_DECREF(v);
@@ -3009,7 +3018,7 @@
 {
 	PyObject *m, *d;
 
-	Py_Type(&Tkapp_Type) = &PyType_Type;
+	Py_TYPE(&Tkapp_Type) = &PyType_Type;
 
 #ifdef WITH_THREAD
 	tcl_lock = PyThread_allocate_lock();
@@ -3037,10 +3046,10 @@
 
 	PyDict_SetItemString(d, "TkappType", (PyObject *)&Tkapp_Type);
 
-	Py_Type(&Tktt_Type) = &PyType_Type;
+	Py_TYPE(&Tktt_Type) = &PyType_Type;
 	PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type);
 
-	Py_Type(&PyTclObject_Type) = &PyType_Type;
+	Py_TYPE(&PyTclObject_Type) = &PyType_Type;
 	PyDict_SetItemString(d, "Tcl_Obj", (PyObject *)&PyTclObject_Type);
 
 #ifdef TK_AQUA

Modified: python/branches/py3k-importlib/Modules/_weakref.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_weakref.c	(original)
+++ python/branches/py3k-importlib/Modules/_weakref.c	Thu Mar 27 00:48:05 2008
@@ -14,13 +14,13 @@
 {
     PyObject *result = NULL;
 
-    if (PyType_SUPPORTS_WEAKREFS(Py_Type(object))) {
+    if (PyType_SUPPORTS_WEAKREFS(Py_TYPE(object))) {
         PyWeakReference **list = GET_WEAKREFS_LISTPTR(object);
 
-        result = PyInt_FromSsize_t(_PyWeakref_GetWeakrefCount(*list));
+        result = PyLong_FromSsize_t(_PyWeakref_GetWeakrefCount(*list));
     }
     else
-        result = PyInt_FromLong(0);
+        result = PyLong_FromLong(0);
 
     return result;
 }
@@ -35,7 +35,7 @@
 {
     PyObject *result = NULL;
 
-    if (PyType_SUPPORTS_WEAKREFS(Py_Type(object))) {
+    if (PyType_SUPPORTS_WEAKREFS(Py_TYPE(object))) {
         PyWeakReference **list = GET_WEAKREFS_LISTPTR(object);
         Py_ssize_t count = _PyWeakref_GetWeakrefCount(*list);
 

Modified: python/branches/py3k-importlib/Modules/arraymodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/arraymodule.c	(original)
+++ python/branches/py3k-importlib/Modules/arraymodule.c	Thu Mar 27 00:48:05 2008
@@ -41,7 +41,7 @@
 static PyTypeObject Arraytype;
 
 #define array_Check(op) PyObject_TypeCheck(op, &Arraytype)
-#define array_CheckExact(op) (Py_Type(op) == &Arraytype)
+#define array_CheckExact(op) (Py_TYPE(op) == &Arraytype)
 
 static int
 array_resize(arrayobject *self, Py_ssize_t newsize)
@@ -55,9 +55,9 @@
 	*/
 
 	if (self->allocated >= newsize &&
-	    Py_Size(self) < newsize + 16 &&
+	    Py_SIZE(self) < newsize + 16 &&
 	    self->ob_item != NULL) {
-		Py_Size(self) = newsize;
+		Py_SIZE(self) = newsize;
 		return 0;
 	}
 
@@ -79,7 +79,7 @@
 	 * memory critical.
 	 */
 
-	_new_size = (newsize >> 4) + (Py_Size(self) < 8 ? 3 : 7) + newsize;
+	_new_size = (newsize >> 4) + (Py_SIZE(self) < 8 ? 3 : 7) + newsize;
 	items = self->ob_item;
 	/* XXX The following multiplication and division does not optimize away 
 	   like it does for lists since the size is not known at compile time */
@@ -92,7 +92,7 @@
 		return -1;
 	}
 	self->ob_item = items;
-	Py_Size(self) = newsize;
+	Py_SIZE(self) = newsize;
 	self->allocated = _new_size;
 	return 0;
 }
@@ -115,7 +115,7 @@
 	long x = ((char *)ap->ob_item)[i];
 	if (x >= 128)
 		x -= 256;
-	return PyInt_FromLong(x);
+	return PyLong_FromLong(x);
 }
 
 static int
@@ -146,7 +146,7 @@
 BB_getitem(arrayobject *ap, Py_ssize_t i)
 {
 	long x = ((unsigned char *)ap->ob_item)[i];
-	return PyInt_FromLong(x);
+	return PyLong_FromLong(x);
 }
 
 static int
@@ -189,7 +189,7 @@
 static PyObject *
 h_getitem(arrayobject *ap, Py_ssize_t i)
 {
-	return PyInt_FromLong((long) ((short *)ap->ob_item)[i]);
+	return PyLong_FromLong((long) ((short *)ap->ob_item)[i]);
 }
 
 
@@ -208,7 +208,7 @@
 static PyObject *
 HH_getitem(arrayobject *ap, Py_ssize_t i)
 {
-	return PyInt_FromLong((long) ((unsigned short *)ap->ob_item)[i]);
+	return PyLong_FromLong((long) ((unsigned short *)ap->ob_item)[i]);
 }
 
 static int
@@ -237,7 +237,7 @@
 static PyObject *
 i_getitem(arrayobject *ap, Py_ssize_t i)
 {
-	return PyInt_FromLong((long) ((int *)ap->ob_item)[i]);
+	return PyLong_FromLong((long) ((int *)ap->ob_item)[i]);
 }
 
 static int
@@ -294,7 +294,7 @@
 static PyObject *
 l_getitem(arrayobject *ap, Py_ssize_t i)
 {
-	return PyInt_FromLong(((long *)ap->ob_item)[i]);
+	return PyLong_FromLong(((long *)ap->ob_item)[i]);
 }
 
 static int
@@ -421,7 +421,7 @@
 	if (op == NULL) {
 		return NULL;
 	}
-	Py_Size(op) = size;
+	Py_SIZE(op) = size;
 	if (size <= 0) {
 		op->ob_item = NULL;
 	}
@@ -445,7 +445,7 @@
 	register arrayobject *ap;
 	assert(array_Check(op));
 	ap = (arrayobject *)op;
-	assert(i>=0 && i<Py_Size(ap));
+	assert(i>=0 && i<Py_SIZE(ap));
 	return (*ap->ob_descr->getitem)(ap, i);
 }
 
@@ -453,7 +453,7 @@
 ins1(arrayobject *self, Py_ssize_t where, PyObject *v)
 {
 	char *items;
-	Py_ssize_t n = Py_Size(self);
+	Py_ssize_t n = Py_SIZE(self);
 	if (v == NULL) {
 		PyErr_BadInternalCall();
 		return -1;
@@ -488,7 +488,7 @@
 		PyObject_ClearWeakRefs((PyObject *) op);
 	if (op->ob_item != NULL)
 		PyMem_DEL(op->ob_item);
-	Py_Type(op)->tp_free((PyObject *)op);
+	Py_TYPE(op)->tp_free((PyObject *)op);
 }
 
 static PyObject *
@@ -508,7 +508,7 @@
 	va = (arrayobject *)v;
 	wa = (arrayobject *)w;
 
-	if (Py_Size(va) != Py_Size(wa) && (op == Py_EQ || op == Py_NE)) {
+	if (Py_SIZE(va) != Py_SIZE(wa) && (op == Py_EQ || op == Py_NE)) {
 		/* Shortcut: if the lengths differ, the arrays differ */
 		if (op == Py_EQ)
 			res = Py_False;
@@ -520,7 +520,7 @@
 
 	/* Search for the first index where items are different */
 	k = 1;
-	for (i = 0; i < Py_Size(va) && i < Py_Size(wa); i++) {
+	for (i = 0; i < Py_SIZE(va) && i < Py_SIZE(wa); i++) {
 		vi = getarrayitem(v, i);
 		wi = getarrayitem(w, i);
 		if (vi == NULL || wi == NULL) {
@@ -539,8 +539,8 @@
 
 	if (k) {
 		/* No more items to compare -- compare sizes */
-		Py_ssize_t vs = Py_Size(va);
-		Py_ssize_t ws = Py_Size(wa);
+		Py_ssize_t vs = Py_SIZE(va);
+		Py_ssize_t ws = Py_SIZE(wa);
 		int cmp;
 		switch (op) {
 		case Py_LT: cmp = vs <  ws; break;
@@ -580,13 +580,13 @@
 static Py_ssize_t
 array_length(arrayobject *a)
 {
-	return Py_Size(a);
+	return Py_SIZE(a);
 }
 
 static PyObject *
 array_item(arrayobject *a, Py_ssize_t i)
 {
-	if (i < 0 || i >= Py_Size(a)) {
+	if (i < 0 || i >= Py_SIZE(a)) {
 		PyErr_SetString(PyExc_IndexError, "array index out of range");
 		return NULL;
 	}
@@ -599,14 +599,14 @@
 	arrayobject *np;
 	if (ilow < 0)
 		ilow = 0;
-	else if (ilow > Py_Size(a))
-		ilow = Py_Size(a);
+	else if (ilow > Py_SIZE(a))
+		ilow = Py_SIZE(a);
 	if (ihigh < 0)
 		ihigh = 0;
 	if (ihigh < ilow)
 		ihigh = ilow;
-	else if (ihigh > Py_Size(a))
-		ihigh = Py_Size(a);
+	else if (ihigh > Py_SIZE(a))
+		ihigh = Py_SIZE(a);
 	np = (arrayobject *) newarrayobject(&Arraytype, ihigh - ilow, a->ob_descr);
 	if (np == NULL)
 		return NULL;
@@ -618,7 +618,7 @@
 static PyObject *
 array_copy(arrayobject *a, PyObject *unused)
 {
-	return array_slice(a, 0, Py_Size(a));
+	return array_slice(a, 0, Py_SIZE(a));
 }
 
 PyDoc_STRVAR(copy_doc,
@@ -634,7 +634,7 @@
 	if (!array_Check(bb)) {
 		PyErr_Format(PyExc_TypeError,
 		     "can only append array (not \"%.200s\") to array",
-			     Py_Type(bb)->tp_name);
+			     Py_TYPE(bb)->tp_name);
 		return NULL;
 	}
 #define b ((arrayobject *)bb)
@@ -642,14 +642,14 @@
 		PyErr_BadArgument();
 		return NULL;
 	}
-	size = Py_Size(a) + Py_Size(b);
+	size = Py_SIZE(a) + Py_SIZE(b);
 	np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr);
 	if (np == NULL) {
 		return NULL;
 	}
-	memcpy(np->ob_item, a->ob_item, Py_Size(a)*a->ob_descr->itemsize);
-	memcpy(np->ob_item + Py_Size(a)*a->ob_descr->itemsize,
-	       b->ob_item, Py_Size(b)*b->ob_descr->itemsize);
+	memcpy(np->ob_item, a->ob_item, Py_SIZE(a)*a->ob_descr->itemsize);
+	memcpy(np->ob_item + Py_SIZE(a)*a->ob_descr->itemsize,
+	       b->ob_item, Py_SIZE(b)*b->ob_descr->itemsize);
 	return (PyObject *)np;
 #undef b
 }
@@ -664,12 +664,12 @@
 	Py_ssize_t nbytes;
 	if (n < 0)
 		n = 0;
-	size = Py_Size(a) * n;
+	size = Py_SIZE(a) * n;
 	np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr);
 	if (np == NULL)
 		return NULL;
 	p = np->ob_item;
-	nbytes = Py_Size(a) * a->ob_descr->itemsize;
+	nbytes = Py_SIZE(a) * a->ob_descr->itemsize;
 	for (i = 0; i < n; i++) {
 		memcpy(p, a->ob_item, nbytes);
 		p += nbytes;
@@ -687,7 +687,7 @@
 	if (v == NULL)
 		n = 0;
 	else if (array_Check(v)) {
-		n = Py_Size(b);
+		n = Py_SIZE(b);
 		if (a == b) {
 			/* Special case "a[i:j] = a" -- copy b first */
 			int ret;
@@ -706,44 +706,44 @@
 	else {
 		PyErr_Format(PyExc_TypeError,
 	     "can only assign array (not \"%.200s\") to array slice",
-			     Py_Type(v)->tp_name);
+			     Py_TYPE(v)->tp_name);
 		return -1;
 	}
 	if (ilow < 0)
 		ilow = 0;
-	else if (ilow > Py_Size(a))
-		ilow = Py_Size(a);
+	else if (ilow > Py_SIZE(a))
+		ilow = Py_SIZE(a);
 	if (ihigh < 0)
 		ihigh = 0;
 	if (ihigh < ilow)
 		ihigh = ilow;
-	else if (ihigh > Py_Size(a))
-		ihigh = Py_Size(a);
+	else if (ihigh > Py_SIZE(a))
+		ihigh = Py_SIZE(a);
 	item = a->ob_item;
 	d = n - (ihigh-ilow);
 	if (d < 0) { /* Delete -d items */
 		memmove(item + (ihigh+d)*a->ob_descr->itemsize,
 			item + ihigh*a->ob_descr->itemsize,
-			(Py_Size(a)-ihigh)*a->ob_descr->itemsize);
-		Py_Size(a) += d;
-		PyMem_RESIZE(item, char, Py_Size(a)*a->ob_descr->itemsize);
+			(Py_SIZE(a)-ihigh)*a->ob_descr->itemsize);
+		Py_SIZE(a) += d;
+		PyMem_RESIZE(item, char, Py_SIZE(a)*a->ob_descr->itemsize);
 						/* Can't fail */
 		a->ob_item = item;
-		a->allocated = Py_Size(a);
+		a->allocated = Py_SIZE(a);
 	}
 	else if (d > 0) { /* Insert d items */
 		PyMem_RESIZE(item, char,
-			     (Py_Size(a) + d)*a->ob_descr->itemsize);
+			     (Py_SIZE(a) + d)*a->ob_descr->itemsize);
 		if (item == NULL) {
 			PyErr_NoMemory();
 			return -1;
 		}
 		memmove(item + (ihigh+d)*a->ob_descr->itemsize,
 			item + ihigh*a->ob_descr->itemsize,
-			(Py_Size(a)-ihigh)*a->ob_descr->itemsize);
+			(Py_SIZE(a)-ihigh)*a->ob_descr->itemsize);
 		a->ob_item = item;
-		Py_Size(a) += d;
-		a->allocated = Py_Size(a);
+		Py_SIZE(a) += d;
+		a->allocated = Py_SIZE(a);
 	}
 	if (n > 0)
 		memcpy(item + ilow*a->ob_descr->itemsize, b->ob_item,
@@ -755,7 +755,7 @@
 static int
 array_ass_item(arrayobject *a, Py_ssize_t i, PyObject *v)
 {
-	if (i < 0 || i >= Py_Size(a)) {
+	if (i < 0 || i >= Py_SIZE(a)) {
 		PyErr_SetString(PyExc_IndexError,
 			         "array assignment index out of range");
 		return -1;
@@ -782,7 +782,7 @@
 		return -1;
 
 	while ((v = PyIter_Next(it)) != NULL) {
-		if (ins1(self, (int) Py_Size(self), v) != 0) {
+		if (ins1(self, (int) Py_SIZE(self), v) != 0) {
 			Py_DECREF(v);
 			Py_DECREF(it);
 			return -1;
@@ -808,16 +808,16 @@
 			     "can only extend with array of same kind");
 		return -1;
 	}
-	size = Py_Size(self) + Py_Size(b);
+	size = Py_SIZE(self) + Py_SIZE(b);
         PyMem_RESIZE(self->ob_item, char, size*self->ob_descr->itemsize);
         if (self->ob_item == NULL) {
                 PyObject_Del(self);
                 PyErr_NoMemory();
 		return -1;
         }
-	memcpy(self->ob_item + Py_Size(self)*self->ob_descr->itemsize,
-               b->ob_item, Py_Size(b)*b->ob_descr->itemsize);
-	Py_Size(self) = size;
+	memcpy(self->ob_item + Py_SIZE(self)*self->ob_descr->itemsize,
+               b->ob_item, Py_SIZE(b)*b->ob_descr->itemsize);
+	Py_SIZE(self) = size;
 	self->allocated = size;
 
 	return 0;
@@ -830,7 +830,7 @@
 	if (!array_Check(bb)) {
 		PyErr_Format(PyExc_TypeError,
 			"can only extend array with array (not \"%.200s\")",
-			Py_Type(bb)->tp_name);
+			Py_TYPE(bb)->tp_name);
 		return NULL;
 	}
 	if (array_do_extend(self, bb) == -1)
@@ -845,15 +845,15 @@
 	char *items, *p;
 	Py_ssize_t size, i;
 
-	if (Py_Size(self) > 0) {
+	if (Py_SIZE(self) > 0) {
 		if (n < 0)
 			n = 0;
 		items = self->ob_item;
-		size = Py_Size(self) * self->ob_descr->itemsize;
+		size = Py_SIZE(self) * self->ob_descr->itemsize;
 		if (n == 0) {
 			PyMem_FREE(items);
 			self->ob_item = NULL;
-			Py_Size(self) = 0;
+			Py_SIZE(self) = 0;
 			self->allocated = 0;
 		}
 		else {
@@ -866,8 +866,8 @@
 				memcpy(p, items, size);
 			}
 			self->ob_item = items;
-			Py_Size(self) *= n;
-			self->allocated = Py_Size(self);
+			Py_SIZE(self) *= n;
+			self->allocated = Py_SIZE(self);
 		}
 	}
 	Py_INCREF(self);
@@ -890,7 +890,7 @@
 	Py_ssize_t count = 0;
 	Py_ssize_t i;
 
-	for (i = 0; i < Py_Size(self); i++) {
+	for (i = 0; i < Py_SIZE(self); i++) {
 		PyObject *selfi = getarrayitem((PyObject *)self, i);
 		int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
 		Py_DECREF(selfi);
@@ -899,7 +899,7 @@
 		else if (cmp < 0)
 			return NULL;
 	}
-	return PyInt_FromSsize_t(count);
+	return PyLong_FromSsize_t(count);
 }
 
 PyDoc_STRVAR(count_doc,
@@ -912,12 +912,12 @@
 {
 	Py_ssize_t i;
 
-	for (i = 0; i < Py_Size(self); i++) {
+	for (i = 0; i < Py_SIZE(self); i++) {
 		PyObject *selfi = getarrayitem((PyObject *)self, i);
 		int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
 		Py_DECREF(selfi);
 		if (cmp > 0) {
-			return PyInt_FromLong((long)i);
+			return PyLong_FromLong((long)i);
 		}
 		else if (cmp < 0)
 			return NULL;
@@ -937,7 +937,7 @@
 	Py_ssize_t i;
 	int cmp;
 
-	for (i = 0, cmp = 0 ; cmp == 0 && i < Py_Size(self); i++) {
+	for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(self); i++) {
 		PyObject *selfi = getarrayitem((PyObject *)self, i);
 		cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
 		Py_DECREF(selfi);
@@ -950,7 +950,7 @@
 {
 	int i;
 
-	for (i = 0; i < Py_Size(self); i++) {
+	for (i = 0; i < Py_SIZE(self); i++) {
 		PyObject *selfi = getarrayitem((PyObject *)self,i);
 		int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
 		Py_DECREF(selfi);
@@ -980,14 +980,14 @@
 	PyObject *v;
 	if (!PyArg_ParseTuple(args, "|n:pop", &i))
 		return NULL;
-	if (Py_Size(self) == 0) {
+	if (Py_SIZE(self) == 0) {
 		/* Special-case most common failure cause */
 		PyErr_SetString(PyExc_IndexError, "pop from empty array");
 		return NULL;
 	}
 	if (i < 0)
-		i += Py_Size(self);
-	if (i < 0 || i >= Py_Size(self)) {
+		i += Py_SIZE(self);
+	if (i < 0 || i >= Py_SIZE(self)) {
 		PyErr_SetString(PyExc_IndexError, "pop index out of range");
 		return NULL;
 	}
@@ -1043,7 +1043,7 @@
 		return NULL;
 
 	PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self->ob_item));
-	PyTuple_SET_ITEM(retval, 1, PyInt_FromLong((long)(Py_Size(self))));
+	PyTuple_SET_ITEM(retval, 1, PyLong_FromLong((long)(Py_SIZE(self))));
 
 	return retval;
 }
@@ -1060,7 +1060,7 @@
 static PyObject *
 array_append(arrayobject *self, PyObject *v)
 {
-	return ins(self, (int) Py_Size(self), v);
+	return ins(self, (int) Py_SIZE(self), v);
 }
 
 PyDoc_STRVAR(append_doc,
@@ -1079,14 +1079,14 @@
 	case 1:
 		break;
 	case 2:
-		for (p = self->ob_item, i = Py_Size(self); --i >= 0; p += 2) {
+		for (p = self->ob_item, i = Py_SIZE(self); --i >= 0; p += 2) {
 			char p0 = p[0];
 			p[0] = p[1];
 			p[1] = p0;
 		}
 		break;
 	case 4:
-		for (p = self->ob_item, i = Py_Size(self); --i >= 0; p += 4) {
+		for (p = self->ob_item, i = Py_SIZE(self); --i >= 0; p += 4) {
 			char p0 = p[0];
 			char p1 = p[1];
 			p[0] = p[3];
@@ -1096,7 +1096,7 @@
 		}
 		break;
 	case 8:
-		for (p = self->ob_item, i = Py_Size(self); --i >= 0; p += 8) {
+		for (p = self->ob_item, i = Py_SIZE(self); --i >= 0; p += 8) {
 			char p0 = p[0];
 			char p1 = p[1];
 			char p2 = p[2];
@@ -1137,16 +1137,16 @@
 		dict = Py_None;
 		Py_INCREF(dict);
 	}
-	if (Py_Size(array) > 0) {
+	if (Py_SIZE(array) > 0) {
 		result = Py_BuildValue("O(cy#)O", 
-			Py_Type(array), 
+			Py_TYPE(array), 
 			array->ob_descr->typecode,
 			array->ob_item,
-			Py_Size(array) * array->ob_descr->itemsize,
+			Py_SIZE(array) * array->ob_descr->itemsize,
 			dict);
 	} else {
 		result = Py_BuildValue("O(c)O", 
-			Py_Type(array), 
+			Py_TYPE(array), 
 			array->ob_descr->typecode,
 			dict);
 	}
@@ -1165,9 +1165,9 @@
 	char tmp[256];	/* 8 is probably enough -- but why skimp */
 	assert((size_t)itemsize <= sizeof(tmp));
 
-	if (Py_Size(self) > 1) {
+	if (Py_SIZE(self) > 1) {
 		for (p = self->ob_item,
-		     q = self->ob_item + (Py_Size(self) - 1)*itemsize;
+		     q = self->ob_item + (Py_SIZE(self) - 1)*itemsize;
 		     p < q;
 		     p += itemsize, q -= itemsize) {
 			/* memory areas guaranteed disjoint, so memcpy
@@ -1212,14 +1212,14 @@
 	if (b == NULL)
 		return NULL;
 
-	if (!PyBytes_Check(b)) {
+	if (!PyString_Check(b)) {
 		PyErr_SetString(PyExc_TypeError,
 				"read() didn't return bytes");
 		Py_DECREF(b);
 		return NULL;
 	}
 
-	if (PyBytes_GET_SIZE(b) != nbytes) {
+	if (PyString_GET_SIZE(b) != nbytes) {
 		PyErr_SetString(PyExc_EOFError,
 				"read() didn't return enough bytes");
 		Py_DECREF(b);
@@ -1241,20 +1241,20 @@
 "fromfile(f, n)\n\
 \n\
 Read n objects from the file object f and append them to the end of the\n\
-array.  Also called as read.");
+array.");
 
 
 static PyObject *
 array_tofile(arrayobject *self, PyObject *f)
 {
-	Py_ssize_t nbytes = Py_Size(self) * self->ob_descr->itemsize;
+	Py_ssize_t nbytes = Py_SIZE(self) * self->ob_descr->itemsize;
 	/* Write 64K blocks at a time */
 	/* XXX Make the block size settable */
 	int BLOCKSIZE = 64*1024;
 	Py_ssize_t nblocks = (nbytes + BLOCKSIZE - 1) / BLOCKSIZE;
 	Py_ssize_t i;
 
-        if (Py_Size(self) == 0)
+        if (Py_SIZE(self) == 0)
 		goto done;
 
 	for (i = 0; i < nblocks; i++) {
@@ -1263,7 +1263,7 @@
 		PyObject *bytes, *res;
 		if (i*BLOCKSIZE + size > nbytes)
 			size = nbytes - i*BLOCKSIZE;
-		bytes = PyBytes_FromStringAndSize(ptr, size);
+		bytes = PyString_FromStringAndSize(ptr, size);
 		if (bytes == NULL)
 			return NULL;
 		res = PyObject_CallMethod(f, "write", "O", bytes);
@@ -1281,8 +1281,7 @@
 PyDoc_STRVAR(tofile_doc,
 "tofile(f)\n\
 \n\
-Write all items (as machine values) to the file object f.  Also called as\n\
-write.");
+Write all items (as machine values) to the file object f.");
 
 
 static PyObject *
@@ -1299,23 +1298,23 @@
 	if (n > 0) {
 		char *item = self->ob_item;
 		Py_ssize_t i;
-		PyMem_RESIZE(item, char, (Py_Size(self) + n) * itemsize);
+		PyMem_RESIZE(item, char, (Py_SIZE(self) + n) * itemsize);
 		if (item == NULL) {
 			PyErr_NoMemory();
 			return NULL;
 		}
 		self->ob_item = item;
-		Py_Size(self) += n;
-		self->allocated = Py_Size(self);
+		Py_SIZE(self) += n;
+		self->allocated = Py_SIZE(self);
 		for (i = 0; i < n; i++) {
 			PyObject *v = PyList_GetItem(list, i);
 			if ((*self->ob_descr->setitem)(self,
-					Py_Size(self) - n + i, v) != 0) {
-				Py_Size(self) -= n;
+					Py_SIZE(self) - n + i, v) != 0) {
+				Py_SIZE(self) -= n;
 				PyMem_RESIZE(item, char,
-					          Py_Size(self) * itemsize);
+					          Py_SIZE(self) * itemsize);
 				self->ob_item = item;
-				self->allocated = Py_Size(self);
+				self->allocated = Py_SIZE(self);
 				return NULL;
 			}
 		}
@@ -1332,12 +1331,12 @@
 static PyObject *
 array_tolist(arrayobject *self, PyObject *unused)
 {
-	PyObject *list = PyList_New(Py_Size(self));
+	PyObject *list = PyList_New(Py_SIZE(self));
 	Py_ssize_t i;
 
 	if (list == NULL)
 		return NULL;
-	for (i = 0; i < Py_Size(self); i++) {
+	for (i = 0; i < Py_SIZE(self); i++) {
 		PyObject *v = getarrayitem((PyObject *)self, i);
 		if (v == NULL) {
 			Py_DECREF(list);
@@ -1370,15 +1369,15 @@
 	n = n / itemsize;
 	if (n > 0) {
 		char *item = self->ob_item;
-		PyMem_RESIZE(item, char, (Py_Size(self) + n) * itemsize);
+		PyMem_RESIZE(item, char, (Py_SIZE(self) + n) * itemsize);
 		if (item == NULL) {
 			PyErr_NoMemory();
 			return NULL;
 		}
 		self->ob_item = item;
-		Py_Size(self) += n;
-		self->allocated = Py_Size(self);
-		memcpy(item + (Py_Size(self) - n) * itemsize,
+		Py_SIZE(self) += n;
+		self->allocated = Py_SIZE(self);
+		memcpy(item + (Py_SIZE(self) - n) * itemsize,
 		       str, itemsize*n);
 	}
 	Py_INCREF(Py_None);
@@ -1395,8 +1394,8 @@
 static PyObject *
 array_tostring(arrayobject *self, PyObject *unused)
 {
-	return PyBytes_FromStringAndSize(self->ob_item,
-                                         Py_Size(self) * self->ob_descr->itemsize);
+	return PyString_FromStringAndSize(self->ob_item,
+                                         Py_SIZE(self) * self->ob_descr->itemsize);
 }
 
 PyDoc_STRVAR(tostring_doc,
@@ -1425,15 +1424,15 @@
 	}
 	if (n > 0) {
 		Py_UNICODE *item = (Py_UNICODE *) self->ob_item;
-		PyMem_RESIZE(item, Py_UNICODE, Py_Size(self) + n);
+		PyMem_RESIZE(item, Py_UNICODE, Py_SIZE(self) + n);
 		if (item == NULL) {
 			PyErr_NoMemory();
 			return NULL;
 		}
 		self->ob_item = (char *) item;
-		Py_Size(self) += n;
-		self->allocated = Py_Size(self);
-		memcpy(item + Py_Size(self) - n,
+		Py_SIZE(self) += n;
+		self->allocated = Py_SIZE(self);
+		memcpy(item + Py_SIZE(self) - n,
 		       ustr, n * sizeof(Py_UNICODE));
 	}
 
@@ -1460,7 +1459,7 @@
 		     "tounicode() may only be called on unicode type arrays");
 		return NULL;
 	}
-	return PyUnicode_FromUnicode((Py_UNICODE *) self->ob_item, Py_Size(self));
+	return PyUnicode_FromUnicode((Py_UNICODE *) self->ob_item, Py_SIZE(self));
 }
 
 PyDoc_STRVAR(tounicode_doc,
@@ -1483,7 +1482,7 @@
 static PyObject *
 array_get_itemsize(arrayobject *a, void *closure)
 {
-	return PyInt_FromLong((long)a->ob_descr->itemsize);
+	return PyLong_FromLong((long)a->ob_descr->itemsize);
 }
 
 static PyGetSetDef array_getsets [] = {
@@ -1523,8 +1522,6 @@
 	 insert_doc},
 	{"pop",		(PyCFunction)array_pop,		METH_VARARGS,
 	 pop_doc},
-	{"read",	(PyCFunction)array_fromfile,	METH_VARARGS,
-	 fromfile_doc},
 	{"__reduce__",	(PyCFunction)array_reduce,	METH_NOARGS,
 	 array_doc},
 	{"remove",	(PyCFunction)array_remove,	METH_O,
@@ -1541,8 +1538,6 @@
 	 tostring_doc},
 	{"tounicode",   (PyCFunction)array_tounicode,	METH_NOARGS,
 	 tounicode_doc},
-	{"write",	(PyCFunction)array_tofile,	METH_O,
-	 tofile_doc},
 	{NULL,		NULL}		/* sentinel */
 };
 
@@ -1553,7 +1548,7 @@
 	PyObject *s, *v = NULL;
 	Py_ssize_t len;
 
-	len = Py_Size(a);
+	len = Py_SIZE(a);
 	typecode = a->ob_descr->typecode;
 	if (len == 0) {
 		return PyUnicode_FromFormat("array('%c')", typecode);
@@ -1577,7 +1572,7 @@
 			return NULL;
 		}
 		if (i < 0)
-			i += Py_Size(self);
+			i += Py_SIZE(self);
 		return array_item(self, i);
 	}
 	else if (PySlice_Check(item)) {
@@ -1586,7 +1581,7 @@
 		arrayobject* ar;
 		int itemsize = self->ob_descr->itemsize;
 
-		if (PySlice_GetIndicesEx((PySliceObject*)item, Py_Size(self),
+		if (PySlice_GetIndicesEx((PySliceObject*)item, Py_SIZE(self),
 				 &start, &stop, &step, &slicelength) < 0) {
 			return NULL;
 		}
@@ -1640,8 +1635,8 @@
 		if (i == -1 && PyErr_Occurred())
 			return -1;
 		if (i < 0)
-			i += Py_Size(self);
-		if (i < 0 || i >= Py_Size(self)) {
+			i += Py_SIZE(self);
+		if (i < 0 || i >= Py_SIZE(self)) {
 			PyErr_SetString(PyExc_IndexError,
 				"array assignment index out of range");
 			return -1;
@@ -1658,7 +1653,7 @@
 	}
 	else if (PySlice_Check(item)) {
 		if (PySlice_GetIndicesEx((PySliceObject *)item,
-					 Py_Size(self), &start, &stop,
+					 Py_SIZE(self), &start, &stop,
 					 &step, &slicelength) < 0) {
 			return -1;
 		}
@@ -1674,7 +1669,7 @@
 	}
 	else if (array_Check(value)) {
 		other = (arrayobject *)value;
-		needed = Py_Size(other);
+		needed = Py_SIZE(other);
 		if (self == other) {
 			/* Special case "self[i:j] = self" -- copy self first */
 			int ret;
@@ -1693,7 +1688,7 @@
 	else {
 		PyErr_Format(PyExc_TypeError,
 	     "can only assign array (not \"%.200s\") to array slice",
-			     Py_Type(value)->tp_name);
+			     Py_TYPE(value)->tp_name);
 		return -1;
 	}
 	itemsize = self->ob_descr->itemsize;
@@ -1705,18 +1700,18 @@
 		if (slicelength > needed) {
 			memmove(self->ob_item + (start + needed) * itemsize,
 				self->ob_item + stop * itemsize,
-				(Py_Size(self) - stop) * itemsize);
-			if (array_resize(self, Py_Size(self) +
+				(Py_SIZE(self) - stop) * itemsize);
+			if (array_resize(self, Py_SIZE(self) +
 					 needed - slicelength) < 0)
 				return -1;
 		}
 		else if (slicelength < needed) {
-			if (array_resize(self, Py_Size(self) +
+			if (array_resize(self, Py_SIZE(self) +
 					 needed - slicelength) < 0)
 				return -1;
 			memmove(self->ob_item + (start + needed) * itemsize,
 				self->ob_item + stop * itemsize,
-				(Py_Size(self) - start - needed) * itemsize);
+				(Py_SIZE(self) - start - needed) * itemsize);
 		}
 		if (needed > 0)
 			memcpy(self->ob_item + start * itemsize,
@@ -1736,19 +1731,19 @@
 		     cur += step, i++) {
 			Py_ssize_t lim = step - 1;
 
-			if (cur + step >= Py_Size(self))
-				lim = Py_Size(self) - cur - 1;
+			if (cur + step >= Py_SIZE(self))
+				lim = Py_SIZE(self) - cur - 1;
 			memmove(self->ob_item + (cur - i) * itemsize,
 				self->ob_item + (cur + 1) * itemsize,
 				lim * itemsize);
 		}
 		cur = start + slicelength * step;
-		if (cur < Py_Size(self)) {
+		if (cur < Py_SIZE(self)) {
 			memmove(self->ob_item + (cur-slicelength) * itemsize,
 				self->ob_item + cur * itemsize,
-				(Py_Size(self) - cur) * itemsize);
+				(Py_SIZE(self) - cur) * itemsize);
 		}
-		if (array_resize(self, Py_Size(self) - slicelength) < 0)
+		if (array_resize(self, Py_SIZE(self) - slicelength) < 0)
 			return -1;
 		return 0;
 	}
@@ -1794,14 +1789,14 @@
         view->buf = (void *)self->ob_item;
         if (view->buf == NULL)
                 view->buf = (void *)emptybuf;
-        view->len = (Py_Size(self)) * self->ob_descr->itemsize;
+        view->len = (Py_SIZE(self)) * self->ob_descr->itemsize;
         view->readonly = 0;
         view->ndim = 1;
         view->itemsize = self->ob_descr->itemsize;
         view->suboffsets = NULL;
         view->shape = NULL;
         if ((flags & PyBUF_ND)==PyBUF_ND) {
-                view->shape = &((Py_Size(self)));
+                view->shape = &((Py_SIZE(self)));
         }
         view->strides = NULL;
         if ((flags & PyBUF_STRIDES)==PyBUF_STRIDES)
@@ -1861,6 +1856,7 @@
 
 	if (!(initial == NULL || PyList_Check(initial)
 	      || PyBytes_Check(initial)
+	      || PyString_Check(initial)
 	      || PyTuple_Check(initial)
 	      || ((c=='u') && PyUnicode_Check(initial)))) {
 		it = PyObject_GetIter(initial);
@@ -1904,7 +1900,9 @@
 					}
 					Py_DECREF(v);
 				}
-			} else if (initial != NULL && PyBytes_Check(initial)) {
+			}
+			else if (initial != NULL && (PyBytes_Check(initial) ||
+					   PyString_Check(initial))) {
 				PyObject *t_initial, *v;
 				t_initial = PyTuple_Pack(1, initial);
 				if (t_initial == NULL) {
@@ -1919,7 +1917,8 @@
 					return NULL;
 				}
 				Py_DECREF(v);
-			} else if (initial != NULL && PyUnicode_Check(initial))  {
+			}
+			else if (initial != NULL && PyUnicode_Check(initial))  {
 				Py_ssize_t n = PyUnicode_GET_DATA_SIZE(initial);
 				if (n > 0) {
 					arrayobject *self = (arrayobject *)a;
@@ -1931,9 +1930,9 @@
 						return NULL;
 					}
 					self->ob_item = item;
-					Py_Size(self) = n / sizeof(Py_UNICODE);
+					Py_SIZE(self) = n / sizeof(Py_UNICODE);
 					memcpy(item, PyUnicode_AS_DATA(initial), n);
-					self->allocated = Py_Size(self);
+					self->allocated = Py_SIZE(self);
 				}
 			}
 			if (it != NULL) {
@@ -2006,13 +2005,11 @@
 index() -- return index of first occurence of an object\n\
 insert() -- insert a new item into the array at a provided position\n\
 pop() -- remove and return item (default last)\n\
-read() -- DEPRECATED, use fromfile()\n\
 remove() -- remove first occurence of an object\n\
 reverse() -- reverse the order of the items in the array\n\
 tofile() -- write all items to a file object\n\
 tolist() -- return the array converted to an ordinary list\n\
 tostring() -- return the array converted to a string\n\
-write() -- DEPRECATED, use tofile()\n\
 \n\
 Attributes:\n\
 \n\
@@ -2104,7 +2101,7 @@
 arrayiter_next(arrayiterobject *it)
 {
 	assert(PyArrayIter_Check(it));
-	if (it->index < Py_Size(it->ao))
+	if (it->index < Py_SIZE(it->ao))
 		return (*it->getitem)(it->ao, it->index++);
 	return NULL;
 }
@@ -2176,7 +2173,7 @@
 
 	if (PyType_Ready(&Arraytype) < 0)
             return;
-	Py_Type(&PyArrayIter_Type) = &PyType_Type;
+	Py_TYPE(&PyArrayIter_Type) = &PyType_Type;
 	m = Py_InitModule3("array", a_methods, module_doc);
 	if (m == NULL)
 		return;

Modified: python/branches/py3k-importlib/Modules/audioop.c
==============================================================================
--- python/branches/py3k-importlib/Modules/audioop.c	(original)
+++ python/branches/py3k-importlib/Modules/audioop.c	Thu Mar 27 00:48:05 2008
@@ -315,7 +315,7 @@
         if ( size == 1 )      val = (int)*CHARP(cp, i);
         else if ( size == 2 ) val = (int)*SHORTP(cp, i*2);
         else if ( size == 4 ) val = (int)*LONGP(cp, i*4);
-        return PyInt_FromLong(val);
+        return PyLong_FromLong(val);
 }
 
 static PyObject *
@@ -339,7 +339,7 @@
                 if ( val < 0 ) val = (-val);
                 if ( val > max ) max = val;
         }
-        return PyInt_FromLong(max);
+        return PyLong_FromLong(max);
 }
 
 static PyObject *
@@ -390,7 +390,7 @@
                 val = 0;
         else
                 val = (int)(avg / (double)(len/size));
-        return PyInt_FromLong(val);
+        return PyLong_FromLong(val);
 }
 
 static PyObject *
@@ -417,7 +417,7 @@
                 val = 0;
         else
                 val = (int)sqrt(sum_squares / (double)(len/size));
-        return PyInt_FromLong(val);
+        return PyLong_FromLong(val);
 }
 
 static double _sum2(short *a, short *b, int len)
@@ -599,7 +599,7 @@
         
         }
 
-        return PyInt_FromLong(best_j);
+        return PyLong_FromLong(best_j);
 }
 
 static PyObject *
@@ -656,7 +656,7 @@
                 val = 0;
         else
                 val = (int)(avg / (double)nextreme);
-        return PyInt_FromLong(val);
+        return PyLong_FromLong(val);
 }
 
 static PyObject *
@@ -709,7 +709,7 @@
                 if ( diff != 0 )
                         prevdiff = diff;
         }
-        return PyInt_FromLong(max);
+        return PyLong_FromLong(max);
 }
 
 static PyObject *
@@ -736,7 +736,7 @@
                 if ( val != prevval ) ncross++;
                 prevval = val;
         }
-        return PyInt_FromLong(ncross);
+        return PyLong_FromLong(ncross);
 }
 
 static PyObject *
@@ -759,10 +759,10 @@
                 return 0;
         }
     
-        rv = PyBytes_FromStringAndSize(NULL, len);
+        rv = PyString_FromStringAndSize(NULL, len);
         if ( rv == 0 )
                 return 0;
-        ncp = (signed char *)PyBytes_AsString(rv);
+        ncp = (signed char *)PyString_AsString(rv);
     
     
         for ( i=0; i < len; i += size ) {
@@ -801,10 +801,10 @@
                 return 0;
         }
     
-        rv = PyBytes_FromStringAndSize(NULL, len/2);
+        rv = PyString_FromStringAndSize(NULL, len/2);
         if ( rv == 0 )
                 return 0;
-        ncp = (signed char *)PyBytes_AsString(rv);
+        ncp = (signed char *)PyString_AsString(rv);
     
     
         for ( i=0; i < len; i += size*2 ) {
@@ -846,10 +846,10 @@
                 return 0;
         }
     
-        rv = PyBytes_FromStringAndSize(NULL, len*2);
+        rv = PyString_FromStringAndSize(NULL, len*2);
         if ( rv == 0 )
                 return 0;
-        ncp = (signed char *)PyBytes_AsString(rv);
+        ncp = (signed char *)PyString_AsString(rv);
     
     
         for ( i=0; i < len; i += size ) {
@@ -903,10 +903,10 @@
                 return 0;
         }
 
-        rv = PyBytes_FromStringAndSize(NULL, len1);
+        rv = PyString_FromStringAndSize(NULL, len1);
         if ( rv == 0 )
                 return 0;
-        ncp = (signed char *)PyBytes_AsString(rv);
+        ncp = (signed char *)PyString_AsString(rv);
 
         for ( i=0; i < len1; i += size ) {
                 if ( size == 1 )      val1 = (int)*CHARP(cp1, i);
@@ -949,10 +949,10 @@
                 return 0;
         }
     
-        rv = PyBytes_FromStringAndSize(NULL, len);
+        rv = PyString_FromStringAndSize(NULL, len);
         if ( rv == 0 )
                 return 0;
-        ncp = (signed char *)PyBytes_AsString(rv);
+        ncp = (signed char *)PyString_AsString(rv);
     
     
         for ( i=0; i < len; i += size ) {
@@ -985,10 +985,10 @@
                 return 0;
         }
     
-        rv = PyBytes_FromStringAndSize(NULL, len);
+        rv = PyString_FromStringAndSize(NULL, len);
         if ( rv == 0 )
                 return 0;
-        ncp = (unsigned char *)PyBytes_AsString(rv);
+        ncp = (unsigned char *)PyString_AsString(rv);
     
         for ( i=0; i < len; i += size ) {
                 if ( size == 1 )      val = ((int)*CHARP(cp, i)) << 8;
@@ -1023,10 +1023,10 @@
                 return 0;
         }
     
-        rv = PyBytes_FromStringAndSize(NULL, (len/size)*size2);
+        rv = PyString_FromStringAndSize(NULL, (len/size)*size2);
         if ( rv == 0 )
                 return 0;
-        ncp = (unsigned char *)PyBytes_AsString(rv);
+        ncp = (unsigned char *)PyString_AsString(rv);
     
         for ( i=0, j=0; i < len; i += size, j += size2 ) {
                 if ( size == 1 )      val = ((int)*CHARP(cp, i)) << 8;
@@ -1157,7 +1157,7 @@
                     nbytes / bytes_per_frame != ceiling)
                         str = NULL;
                 else
-                        str = PyBytes_FromStringAndSize(NULL, nbytes);
+                        str = PyString_FromStringAndSize(NULL, nbytes);
 
                 if (str == NULL) {
                         PyErr_SetString(PyExc_MemoryError,
@@ -1165,7 +1165,7 @@
                         goto exit;
                 }
         }
-        ncp = PyBytes_AsString(str);
+        ncp = PyString_AsString(str);
 
         for (;;) {
                 while (d < 0) {
@@ -1182,9 +1182,9 @@
                                         goto exit;
                                 /* We have checked before that the length
                                  * of the string fits into int. */
-                                len = (int)(ncp - PyBytes_AsString(str));
-				rv = PyBytes_FromStringAndSize
-					(PyBytes_AsString(str), len);
+                                len = (int)(ncp - PyString_AsString(str));
+				rv = PyString_FromStringAndSize
+					(PyString_AsString(str), len);
 				Py_DECREF(str);
 				str = rv;
 				if (str == NULL)
@@ -1254,10 +1254,10 @@
                 return 0;
         }
     
-        rv = PyBytes_FromStringAndSize(NULL, len/size);
+        rv = PyString_FromStringAndSize(NULL, len/size);
         if ( rv == 0 )
                 return 0;
-        ncp = (unsigned char *)PyBytes_AsString(rv);
+        ncp = (unsigned char *)PyString_AsString(rv);
     
         for ( i=0; i < len; i += size ) {
                 if ( size == 1 )      val = ((int)*CHARP(cp, i)) << 8;
@@ -1288,10 +1288,10 @@
                 return 0;
         }
     
-        rv = PyBytes_FromStringAndSize(NULL, len*size);
+        rv = PyString_FromStringAndSize(NULL, len*size);
         if ( rv == 0 )
                 return 0;
-        ncp = (signed char *)PyBytes_AsString(rv);
+        ncp = (signed char *)PyString_AsString(rv);
     
         for ( i=0; i < len*size; i += size ) {
                 cval = *cp++;
@@ -1322,10 +1322,10 @@
                 return 0;
         }
     
-        rv = PyBytes_FromStringAndSize(NULL, len/size);
+        rv = PyString_FromStringAndSize(NULL, len/size);
         if ( rv == 0 )
                 return 0;
-        ncp = (unsigned char *)PyBytes_AsString(rv);
+        ncp = (unsigned char *)PyString_AsString(rv);
     
         for ( i=0; i < len; i += size ) {
                 if ( size == 1 )      val = ((int)*CHARP(cp, i)) << 8;
@@ -1356,10 +1356,10 @@
                 return 0;
         }
     
-        rv = PyBytes_FromStringAndSize(NULL, len*size);
+        rv = PyString_FromStringAndSize(NULL, len*size);
         if ( rv == 0 )
                 return 0;
-        ncp = (signed char *)PyBytes_AsString(rv);
+        ncp = (signed char *)PyString_AsString(rv);
     
         for ( i=0; i < len*size; i += size ) {
                 cval = *cp++;
@@ -1392,10 +1392,10 @@
                 return 0;
         }
     
-        str = PyBytes_FromStringAndSize(NULL, len/(size*2));
+        str = PyString_FromStringAndSize(NULL, len/(size*2));
         if ( str == 0 )
                 return 0;
-        ncp = (signed char *)PyBytes_AsString(str);
+        ncp = (signed char *)PyString_AsString(str);
 
         /* Decode state, should have (value, step) */
         if ( state == Py_None ) {
@@ -1508,10 +1508,10 @@
         } else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) )
                 return 0;
     
-        str = PyBytes_FromStringAndSize(NULL, len*size*2);
+        str = PyString_FromStringAndSize(NULL, len*size*2);
         if ( str == 0 )
                 return 0;
-        ncp = (signed char *)PyBytes_AsString(str);
+        ncp = (signed char *)PyString_AsString(str);
 
         step = stepsizeTable[index];
         bufferstep = 0;

Modified: python/branches/py3k-importlib/Modules/binascii.c
==============================================================================
--- python/branches/py3k-importlib/Modules/binascii.c	(original)
+++ python/branches/py3k-importlib/Modules/binascii.c	Thu Mar 27 00:48:05 2008
@@ -56,6 +56,9 @@
 #define PY_SSIZE_T_CLEAN
 
 #include "Python.h"
+#ifdef USE_ZLIB_CRC32
+#include "zlib.h"
+#endif
 
 static PyObject *Error;
 static PyObject *Incomplete;
@@ -200,9 +203,9 @@
 	ascii_len--;
 
 	/* Allocate the buffer */
-	if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len)) == NULL )
+	if ( (rv=PyString_FromStringAndSize(NULL, bin_len)) == NULL )
 		return NULL;
-	bin_data = (unsigned char *)PyBytes_AS_STRING(rv);
+	bin_data = (unsigned char *)PyString_AS_STRING(rv);
 
 	for( ; bin_len > 0 ; ascii_len--, ascii_data++ ) {
 		/* XXX is it really best to add NULs if there's no more data */
@@ -277,9 +280,9 @@
 	}
 
 	/* We're lazy and allocate to much (fixed up later) */
-	if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len*2+2)) == NULL )
+	if ( (rv=PyString_FromStringAndSize(NULL, bin_len*2+2)) == NULL )
 		return NULL;
-	ascii_data = (unsigned char *)PyBytes_AS_STRING(rv);
+	ascii_data = (unsigned char *)PyString_AS_STRING(rv);
 
 	/* Store the length */
 	*ascii_data++ = ' ' + (bin_len & 077);
@@ -301,9 +304,9 @@
 	}
 	*ascii_data++ = '\n';	/* Append a courtesy newline */
 
-	if (PyBytes_Resize(rv,
+	if (_PyString_Resize(&rv,
                            (ascii_data -
-                            (unsigned char *)PyBytes_AS_STRING(rv))) < 0) {
+                            (unsigned char *)PyString_AS_STRING(rv))) < 0) {
 		Py_DECREF(rv);
 		rv = NULL;
 	}
@@ -355,9 +358,9 @@
 	bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */
 
 	/* Allocate the buffer */
-	if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len)) == NULL )
+	if ( (rv=PyString_FromStringAndSize(NULL, bin_len)) == NULL )
 		return NULL;
-	bin_data = (unsigned char *)PyBytes_AS_STRING(rv);
+	bin_data = (unsigned char *)PyString_AS_STRING(rv);
 	bin_len = 0;
 
 	for( ; ascii_len > 0; ascii_len--, ascii_data++) {
@@ -416,17 +419,17 @@
 
 	/* And set string size correctly. If the result string is empty
 	** (because the input was all invalid) return the shared empty
-	** string instead; PyBytes_Resize() won't do this for us.
+	** string instead; _PyString_Resize() won't do this for us.
 	*/
 	if (bin_len > 0) {
-		if (PyBytes_Resize(rv, bin_len) < 0) {
+		if (_PyString_Resize(&rv, bin_len) < 0) {
 			Py_DECREF(rv);
 			rv = NULL;
 		}
 	}
 	else {
 		Py_DECREF(rv);
-		rv = PyBytes_FromStringAndSize("", 0);
+		rv = PyString_FromStringAndSize("", 0);
 	}
 	return rv;
 }
@@ -453,9 +456,9 @@
 	/* We're lazy and allocate too much (fixed up later).
 	   "+3" leaves room for up to two pad characters and a trailing
 	   newline.  Note that 'b' gets encoded as 'Yg==\n' (1 in, 5 out). */
-	if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len*2 + 3)) == NULL )
+	if ( (rv=PyString_FromStringAndSize(NULL, bin_len*2 + 3)) == NULL )
 		return NULL;
-	ascii_data = (unsigned char *)PyBytes_AS_STRING(rv);
+	ascii_data = (unsigned char *)PyString_AS_STRING(rv);
 
 	for( ; bin_len > 0 ; bin_len--, bin_data++ ) {
 		/* Shift the data into our buffer */
@@ -479,9 +482,9 @@
 	}
 	*ascii_data++ = '\n';	/* Append a courtesy newline */
 
-	if (PyBytes_Resize(rv,
+	if (_PyString_Resize(&rv,
 			   (ascii_data -
-			    (unsigned char *)PyBytes_AS_STRING(rv))) < 0) {
+			    (unsigned char *)PyString_AS_STRING(rv))) < 0) {
 		Py_DECREF(rv);
 		rv = NULL;
 	}
@@ -507,9 +510,9 @@
 	/* Allocate a string that is too big (fixed later) 
 	   Add two to the initial length to prevent interning which
 	   would preclude subsequent resizing.  */
-	if ( (rv=PyBytes_FromStringAndSize(NULL, len+2)) == NULL )
+	if ( (rv=PyString_FromStringAndSize(NULL, len+2)) == NULL )
 		return NULL;
-	bin_data = (unsigned char *)PyBytes_AS_STRING(rv);
+	bin_data = (unsigned char *)PyString_AS_STRING(rv);
 
 	for( ; len > 0 ; len--, ascii_data++ ) {
 		/* Get the byte and look it up */
@@ -543,9 +546,9 @@
 		Py_DECREF(rv);
 		return NULL;
 	}
-	if (PyBytes_Resize(rv,
+	if (_PyString_Resize(&rv,
 			   (bin_data -
-			    (unsigned char *)PyBytes_AS_STRING(rv))) < 0) {
+			    (unsigned char *)PyString_AS_STRING(rv))) < 0) {
 		Py_DECREF(rv);
 		rv = NULL;
 	}
@@ -572,9 +575,9 @@
 		return NULL;
 
 	/* Worst case: output is twice as big as input (fixed later) */
-	if ( (rv=PyBytes_FromStringAndSize(NULL, len*2+2)) == NULL )
+	if ( (rv=PyString_FromStringAndSize(NULL, len*2+2)) == NULL )
 		return NULL;
-	out_data = (unsigned char *)PyBytes_AS_STRING(rv);
+	out_data = (unsigned char *)PyString_AS_STRING(rv);
 
 	for( in=0; in<len; in++) {
 		ch = in_data[in];
@@ -600,9 +603,9 @@
 			}
 		}
 	}
-	if (PyBytes_Resize(rv,
+	if (_PyString_Resize(&rv,
 			   (out_data -
-			    (unsigned char *)PyBytes_AS_STRING(rv))) < 0) {
+			    (unsigned char *)PyString_AS_STRING(rv))) < 0) {
 		Py_DECREF(rv);
 		rv = NULL;
 	}
@@ -625,9 +628,9 @@
 		return NULL;
 
 	/* Allocate a buffer that is at least large enough */
-	if ( (rv=PyBytes_FromStringAndSize(NULL, len*2+2)) == NULL )
+	if ( (rv=PyString_FromStringAndSize(NULL, len*2+2)) == NULL )
 		return NULL;
-	ascii_data = (unsigned char *)PyBytes_AS_STRING(rv);
+	ascii_data = (unsigned char *)PyString_AS_STRING(rv);
 
 	for( ; len > 0 ; len--, bin_data++ ) {
 		/* Shift into our buffer, and output any 6bits ready */
@@ -644,9 +647,9 @@
 		leftchar <<= (6-leftbits);
 		*ascii_data++ = table_b2a_hqx[leftchar & 0x3f];
 	}
-	if (PyBytes_Resize(rv,
+	if (_PyString_Resize(&rv,
 			   (ascii_data -
-			    (unsigned char *)PyBytes_AS_STRING(rv))) < 0) {
+			    (unsigned char *)PyString_AS_STRING(rv))) < 0) {
 		Py_DECREF(rv);
 		rv = NULL;
 	}
@@ -668,14 +671,14 @@
 
 	/* Empty string is a special case */
 	if ( in_len == 0 )
-		return PyBytes_FromStringAndSize("", 0);
+		return PyString_FromStringAndSize("", 0);
 
 	/* Allocate a buffer of reasonable size. Resized when needed */
 	out_len = in_len*2;
-	if ( (rv=PyBytes_FromStringAndSize(NULL, out_len)) == NULL )
+	if ( (rv=PyString_FromStringAndSize(NULL, out_len)) == NULL )
 		return NULL;
 	out_len_left = out_len;
-	out_data = (unsigned char *)PyBytes_AS_STRING(rv);
+	out_data = (unsigned char *)PyString_AS_STRING(rv);
 
 	/*
 	** We need two macros here to get/put bytes and handle
@@ -694,9 +697,9 @@
 #define OUTBYTE(b) \
 	do { \
 		 if ( --out_len_left < 0 ) { \
-			  if (PyBytes_Resize(rv, 2*out_len) < 0) \
+			  if (_PyString_Resize(&rv, 2*out_len) < 0) \
 			    { Py_DECREF(rv); return NULL; } \
-			  out_data = (unsigned char *)PyBytes_AS_STRING(rv) \
+			  out_data = (unsigned char *)PyString_AS_STRING(rv) \
 								 + out_len; \
 			  out_len_left = out_len-1; \
 			  out_len = out_len * 2; \
@@ -744,9 +747,9 @@
 			OUTBYTE(in_byte);
 		}
 	}
-	if (PyBytes_Resize(rv,
+	if (_PyString_Resize(&rv,
 			   (out_data -
-			    (unsigned char *)PyBytes_AS_STRING(rv))) < 0) {
+			    (unsigned char *)PyString_AS_STRING(rv))) < 0) {
 		Py_DECREF(rv);
 		rv = NULL;
 	}
@@ -776,6 +779,20 @@
 PyDoc_STRVAR(doc_crc32,
 "(data, oldcrc = 0) -> newcrc. Compute CRC-32 incrementally");
 
+#ifdef USE_ZLIB_CRC32
+/* This was taken from zlibmodule.c PyZlib_crc32 (but is PY_SSIZE_T_CLEAN) */
+static PyObject *
+binascii_crc32(PyObject *self, PyObject *args)
+{
+    uLong crc32val = 0;  /* crc32(0L, Z_NULL, 0) */
+    Byte *buf;
+    int len;
+    if (!PyArg_ParseTuple(args, "s#|I:crc32", &buf, &len, &crc32val))
+        return NULL;
+    crc32val = crc32(crc32val, buf, len);
+    return PyLong_FromUnsignedLong(crc32val & 0xffffffffU);
+}
+#else  /* USE_ZLIB_CRC32 */
 /*  Crc - 32 BIT ANSI X3.66 CRC checksum files
     Also known as: ISO 3307
 **********************************************************************|
@@ -898,34 +915,23 @@
 binascii_crc32(PyObject *self, PyObject *args)
 { /* By Jim Ahlstrom; All rights transferred to CNRI */
 	unsigned char *bin_data;
-	unsigned long crc = 0UL;	/* initial value of CRC */
+	unsigned int crc = 0;	/* initial value of CRC */
 	Py_ssize_t len;
-	long result;
+	unsigned int result;
 
-	if ( !PyArg_ParseTuple(args, "s#|l:crc32", &bin_data, &len, &crc) )
+	if ( !PyArg_ParseTuple(args, "s#|I:crc32", &bin_data, &len, &crc) )
 		return NULL;
 
 	crc = ~ crc;
-#if SIZEOF_LONG > 4
-	/* only want the trailing 32 bits */
-	crc &= 0xFFFFFFFFUL;
-#endif
-	while (len--)
-		crc = crc_32_tab[(crc ^ *bin_data++) & 0xffUL] ^ (crc >> 8);
+	while (len--) {
+		crc = crc_32_tab[(crc ^ *bin_data++) & 0xff] ^ (crc >> 8);
 		/* Note:  (crc >> 8) MUST zero fill on left */
+	}
 
-	result = (long)(crc ^ 0xFFFFFFFFUL);
-#if SIZEOF_LONG > 4
-	/* Extend the sign bit.  This is one way to ensure the result is the
-	 * same across platforms.  The other way would be to return an
-	 * unbounded unsigned long, but the evidence suggests that lots of
-	 * code outside this treats the result as if it were a signed 4-byte
-	 * integer.
-	 */
-	result |= -(result & (1L << 31));
-#endif
-	return PyInt_FromLong(result);
+	result = (crc ^ 0xFFFFFFFF);
+	return PyLong_FromUnsignedLong(result & 0xffffffff);
 }
+#endif  /* USE_ZLIB_CRC32 */
 
 
 static PyObject *
@@ -940,10 +946,10 @@
 	if (!PyArg_ParseTuple(args, "s#:b2a_hex", &argbuf, &arglen))
 		return NULL;
 
-	retval = PyBytes_FromStringAndSize(NULL, arglen*2);
+	retval = PyString_FromStringAndSize(NULL, arglen*2);
 	if (!retval)
 		return NULL;
-	retbuf = PyBytes_AS_STRING(retval);
+	retbuf = PyString_AS_STRING(retval);
 
 	/* make hex version of string, taken from shamodule.c */
 	for (i=j=0; i < arglen; i++) {
@@ -1000,10 +1006,10 @@
 		return NULL;
 	}
 
-	retval = PyBytes_FromStringAndSize(NULL, (arglen/2));
+	retval = PyString_FromStringAndSize(NULL, (arglen/2));
 	if (!retval)
 		return NULL;
-	retbuf = PyBytes_AS_STRING(retval);
+	retbuf = PyString_AS_STRING(retval);
 
 	for (i=j=0; i < arglen; i += 2) {
 		int top = to_int(Py_CHARMASK(argbuf[i]));
@@ -1115,7 +1121,7 @@
 			out++;
 		}
 	}
-	if ((rv = PyBytes_FromStringAndSize((char *)odata, out)) == NULL) {
+	if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
 		PyMem_Free(odata);
 		return NULL;
 	}
@@ -1315,7 +1321,7 @@
 			}
 		}
 	}
-	if ((rv = PyBytes_FromStringAndSize((char *)odata, out)) == NULL) {
+	if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
 		PyMem_Free(odata);
 		return NULL;
 	}

Modified: python/branches/py3k-importlib/Modules/bz2module.c
==============================================================================
--- python/branches/py3k-importlib/Modules/bz2module.c	(original)
+++ python/branches/py3k-importlib/Modules/bz2module.c	Thu Mar 27 00:48:05 2008
@@ -34,14 +34,14 @@
 #error "Large file support, but neither off_t nor fpos_t is large enough."
 #endif
 
-#define BUF(v) PyBytes_AS_STRING(v)
+#define BUF(v) PyString_AS_STRING(v)
 
 #define MODE_CLOSED   0
 #define MODE_READ     1
 #define MODE_READ_EOF 2
 #define MODE_WRITE    3
 
-#define BZ2FileObject_Check(v)	(Py_Type(v) == &BZ2File_Type)
+#define BZ2FileObject_Check(v)	(Py_TYPE(v) == &BZ2File_Type)
 
 
 #ifdef BZ_CONFIG_ERROR
@@ -232,7 +232,7 @@
 	int bytes_read;
 
 	total_v_size = n > 0 ? n : 100;
-	v = PyBytes_FromStringAndSize((char *)NULL, total_v_size);
+	v = PyString_FromStringAndSize((char *)NULL, total_v_size);
 	if (v == NULL)
 		return NULL;
 
@@ -272,8 +272,7 @@
 			Py_DECREF(v);
 			return NULL;
 		}
-		if (PyBytes_Resize(v, total_v_size) < 0) {
-			Py_DECREF(v);
+		if (_PyString_Resize(&v, total_v_size) < 0) {
 			return NULL;
 		}
 		buf = BUF(v) + used_v_size;
@@ -282,8 +281,7 @@
 
 	used_v_size = buf - BUF(v);
 	if (used_v_size != total_v_size) {
-		if (PyBytes_Resize(v, used_v_size) < 0) {
-			Py_DECREF(v);
+		if (_PyString_Resize(&v, used_v_size) < 0) {
 			v = NULL;
 		}
 	}
@@ -340,10 +338,10 @@
 
 /* This is a hacked version of Python's
  * fileobject.c:readahead_get_line_skip(). */
-static PyBytesObject *
+static PyStringObject *
 Util_ReadAheadGetLineSkip(BZ2FileObject *f, int skip, int bufsize)
 {
-	PyBytesObject* s;
+	PyStringObject* s;
 	char *bufptr;
 	char *buf;
 	int len;
@@ -354,17 +352,17 @@
 
 	len = f->f_bufend - f->f_bufptr;
 	if (len == 0)
-		return (PyBytesObject *)
-			PyBytes_FromStringAndSize(NULL, skip);
+		return (PyStringObject *)
+			PyString_FromStringAndSize(NULL, skip);
 	bufptr = memchr(f->f_bufptr, '\n', len);
 	if (bufptr != NULL) {
 		bufptr++;			/* Count the '\n' */
 		len = bufptr - f->f_bufptr;
-		s = (PyBytesObject *)
-			PyBytes_FromStringAndSize(NULL, skip+len);
+		s = (PyStringObject *)
+			PyString_FromStringAndSize(NULL, skip+len);
 		if (s == NULL)
 			return NULL;
-		memcpy(PyBytes_AS_STRING(s)+skip, f->f_bufptr, len);
+		memcpy(PyString_AS_STRING(s)+skip, f->f_bufptr, len);
 		f->f_bufptr = bufptr;
 		if (bufptr == f->f_bufend)
 			Util_DropReadAhead(f);
@@ -378,7 +376,7 @@
 		        PyMem_Free(buf);
 			return NULL;
 		}
-		memcpy(PyBytes_AS_STRING(s)+skip, bufptr, len);
+		memcpy(PyString_AS_STRING(s)+skip, bufptr, len);
 		PyMem_Free(buf);
 	}
 	return s;
@@ -411,7 +409,7 @@
 		case MODE_READ:
 			break;
 		case MODE_READ_EOF:
-			ret = PyBytes_FromStringAndSize("", 0);
+			ret = PyString_FromStringAndSize("", 0);
 			goto cleanup;
 		case MODE_CLOSED:
 			PyErr_SetString(PyExc_ValueError,
@@ -433,7 +431,7 @@
 				"more than a Python string can hold");
 		goto cleanup;
 	}
-	ret = PyBytes_FromStringAndSize((char *)NULL, buffersize);
+	ret = PyString_FromStringAndSize((char *)NULL, buffersize);
 	if (ret == NULL || buffersize == 0)
 		goto cleanup;
 	bytesread = 0;
@@ -458,8 +456,7 @@
 		}
 		if (bytesrequested < 0) {
 			buffersize = Util_NewBufferSize(buffersize);
-			if (PyBytes_Resize(ret, buffersize) < 0) {
-				Py_DECREF(ret);
+			if (_PyString_Resize(&ret, buffersize) < 0) {
 				ret = NULL;
 				goto cleanup;
 			}
@@ -468,8 +465,7 @@
 		}
 	}
 	if (bytesread != buffersize) {
-		if (PyBytes_Resize(ret, bytesread) < 0) {
-			Py_DECREF(ret);
+		if (_PyString_Resize(&ret, bytesread) < 0) {
 			ret = NULL;
 		}
 	}
@@ -502,7 +498,7 @@
 		case MODE_READ:
 			break;
 		case MODE_READ_EOF:
-			ret = PyBytes_FromStringAndSize("", 0);
+			ret = PyString_FromStringAndSize("", 0);
 			goto cleanup;
 		case MODE_CLOSED:
 			PyErr_SetString(PyExc_ValueError,
@@ -515,7 +511,7 @@
 	}
 
 	if (sizehint == 0)
-		ret = PyBytes_FromStringAndSize("", 0);
+		ret = PyString_FromStringAndSize("", 0);
 	else
 		ret = Util_GetLine(self, (sizehint < 0) ? 0 : sizehint);
 
@@ -608,21 +604,20 @@
 			}
 			if (big_buffer == NULL) {
 				/* Create the big buffer */
-				big_buffer = PyBytes_FromStringAndSize(
+				big_buffer = PyString_FromStringAndSize(
 					NULL, buffersize);
 				if (big_buffer == NULL)
 					goto error;
-				buffer = PyBytes_AS_STRING(big_buffer);
+				buffer = PyString_AS_STRING(big_buffer);
 				memcpy(buffer, small_buffer, nfilled);
 			}
 			else {
 				/* Grow the big buffer */
-				if (PyBytes_Resize(big_buffer, buffersize) < 0){
-					Py_DECREF(big_buffer);
+				if (_PyString_Resize(&big_buffer, buffersize) < 0){
 					big_buffer = NULL;
 					goto error;
 				}
-				buffer = PyBytes_AS_STRING(big_buffer);
+				buffer = PyString_AS_STRING(big_buffer);
 			}
 			continue;
 		}
@@ -631,7 +626,7 @@
 		while (p != NULL) {
 			/* Process complete lines */
 			p++;
-			line = PyBytes_FromStringAndSize(q, p-q);
+			line = PyString_FromStringAndSize(q, p-q);
 			if (line == NULL)
 				goto error;
 			err = PyList_Append(list, line);
@@ -654,21 +649,18 @@
 	}
 	if (nfilled != 0) {
 		/* Partial last line */
-		line = PyBytes_FromStringAndSize(buffer, nfilled);
+		line = PyString_FromStringAndSize(buffer, nfilled);
 		if (line == NULL)
 			goto error;
 		if (sizehint > 0) {
 			/* Need to complete the last line */
 			PyObject *rest = Util_GetLine(self, 0);
-			PyObject *new;
 			if (rest == NULL) {
 				Py_DECREF(line);
 				goto error;
 			}
-			new = PyBytes_Concat(line, rest);
-			Py_DECREF(line);
+			PyString_Concat(&line, rest);
 			Py_DECREF(rest);
-			line = new;
 			if (line == NULL)
 				goto error;
 		}
@@ -702,7 +694,7 @@
 	int len;
 	int bzerror;
 
-	if (!PyArg_ParseTuple(args, "s#:write", &buf, &len))
+	if (!PyArg_ParseTuple(args, "y#:write", &buf, &len))
 		return NULL;
 
 	ACQUIRE_LOCK(self);
@@ -820,7 +812,7 @@
 		   could potentially execute Python code. */
 		for (i = 0; i < j; i++) {
 			PyObject *v = PyList_GET_ITEM(list, i);
-			if (!PyBytes_Check(v)) {
+			if (!PyString_Check(v)) {
 			    	const char *buffer;
 			    	Py_ssize_t len;
 				if (PyObject_AsCharBuffer(v, &buffer, &len)) {
@@ -831,7 +823,7 @@
 							"bytes objects");
 					goto error;
 				}
-				line = PyBytes_FromStringAndSize(buffer,
+				line = PyString_FromStringAndSize(buffer,
 								  len);
 				if (line == NULL)
 					goto error;
@@ -845,9 +837,9 @@
 		Py_BEGIN_ALLOW_THREADS
 		for (i = 0; i < j; i++) {
 		    	line = PyList_GET_ITEM(list, i);
-			len = PyBytes_GET_SIZE(line);
+			len = PyString_GET_SIZE(line);
 			BZ2_bzWrite (&bzerror, self->fp,
-				     PyBytes_AS_STRING(line), len);
+				     PyString_AS_STRING(line), len);
 			if (bzerror != BZ_OK) {
 				Py_BLOCK_THREADS
 				Util_CatchBZ2Error(bzerror);
@@ -902,10 +894,10 @@
 	if (!PyArg_ParseTuple(args, "O|i:seek", &offobj, &where))
 		return NULL;
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-	offset = PyInt_AsLong(offobj);
+	offset = PyLong_AsLong(offobj);
 #else
 	offset = PyLong_Check(offobj) ?
-		PyLong_AsLongLong(offobj) : PyInt_AsLong(offobj);
+		PyLong_AsLongLong(offobj) : PyLong_AsLong(offobj);
 #endif
 	if (PyErr_Occurred())
 		return NULL;
@@ -1036,7 +1028,7 @@
 	}
 
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-	ret = PyInt_FromLong(self->pos);
+	ret = PyLong_FromLong(self->pos);
 #else
 	ret = PyLong_FromLongLong(self->pos);
 #endif
@@ -1110,7 +1102,7 @@
 static PyObject *
 BZ2File_get_closed(BZ2FileObject *self, void *closure)
 {
-	return PyInt_FromLong(self->mode == MODE_CLOSED);
+	return PyLong_FromLong(self->mode == MODE_CLOSED);
 }
 
 static PyGetSetDef BZ2File_getset[] = {
@@ -1248,7 +1240,7 @@
 	Util_DropReadAhead(self);
 	if (self->rawfp != NULL)
 		fclose(self->rawfp);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 /* This is a hacked version of Python's fileobject.c:file_getiter(). */
@@ -1269,7 +1261,7 @@
 static PyObject *
 BZ2File_iternext(BZ2FileObject *self)
 {
-	PyBytesObject* ret;
+	PyStringObject* ret;
 	ACQUIRE_LOCK(self);
 	if (self->mode == MODE_CLOSED) {
 		PyErr_SetString(PyExc_ValueError,
@@ -1278,7 +1270,7 @@
 	}
 	ret = Util_ReadAheadGetLineSkip(self, 0, READAHEAD_BUFSIZE);
 	RELEASE_LOCK(self);
-	if (ret == NULL || PyBytes_GET_SIZE(ret) == 0) {
+	if (ret == NULL || PyString_GET_SIZE(ret) == 0) {
 		Py_XDECREF(ret);
 		return NULL;
 	}
@@ -1367,11 +1359,11 @@
 	bz_stream *bzs = &self->bzs;
 	int bzerror;
 
-	if (!PyArg_ParseTuple(args, "s#:compress", &data, &datasize))
+	if (!PyArg_ParseTuple(args, "y#:compress", &data, &datasize))
 		return NULL;
 
 	if (datasize == 0)
-		return PyBytes_FromStringAndSize("", 0);
+		return PyString_FromStringAndSize("", 0);
 
 	ACQUIRE_LOCK(self);
 	if (!self->running) {
@@ -1380,7 +1372,7 @@
 		goto error;
 	}
 
-	ret = PyBytes_FromStringAndSize(NULL, bufsize);
+	ret = PyString_FromStringAndSize(NULL, bufsize);
 	if (!ret)
 		goto error;
 
@@ -1403,7 +1395,7 @@
 			break; /* no more input data */
 		if (bzs->avail_out == 0) {
 			bufsize = Util_NewBufferSize(bufsize);
-			if (PyBytes_Resize(ret, bufsize) < 0) {
+			if (_PyString_Resize(&ret, bufsize) < 0) {
 				BZ2_bzCompressEnd(bzs);
 				goto error;
 			}
@@ -1413,7 +1405,7 @@
 		}
 	}
 
-	if (PyBytes_Resize(ret,
+	if (_PyString_Resize(&ret,
 			   (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout)) < 0)
 		goto error;
 
@@ -1450,7 +1442,7 @@
 	}
 	self->running = 0;
 
-	ret = PyBytes_FromStringAndSize(NULL, bufsize);
+	ret = PyString_FromStringAndSize(NULL, bufsize);
 	if (!ret)
 		goto error;
 
@@ -1471,7 +1463,7 @@
 		}
 		if (bzs->avail_out == 0) {
 			bufsize = Util_NewBufferSize(bufsize);
-			if (PyBytes_Resize(ret, bufsize) < 0)
+			if (_PyString_Resize(&ret, bufsize) < 0)
 				goto error;
 			bzs->next_out = BUF(ret);
 			bzs->next_out = BUF(ret) + (BZS_TOTAL_OUT(bzs)
@@ -1481,7 +1473,7 @@
 	}
 
 	if (bzs->avail_out != 0) {
-		if (PyBytes_Resize(ret,
+		if (_PyString_Resize(&ret,
 			    (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout)) < 0)
 			goto error;
 	}
@@ -1560,7 +1552,7 @@
 		PyThread_free_lock(self->lock);
 #endif
 	BZ2_bzCompressEnd(&self->bzs);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 
@@ -1656,7 +1648,7 @@
 	bz_stream *bzs = &self->bzs;
 	int bzerror;
 
-	if (!PyArg_ParseTuple(args, "s#:decompress", &data, &datasize))
+	if (!PyArg_ParseTuple(args, "y#:decompress", &data, &datasize))
 		return NULL;
 
 	ACQUIRE_LOCK(self);
@@ -1666,7 +1658,7 @@
 		goto error;
 	}
 
-	ret = PyBytes_FromStringAndSize(NULL, bufsize);
+	ret = PyString_FromStringAndSize(NULL, bufsize);
 	if (!ret)
 		goto error;
 
@@ -1685,7 +1677,7 @@
 			if (bzs->avail_in != 0) {
 				Py_DECREF(self->unused_data);
 				self->unused_data =
-				    PyBytes_FromStringAndSize(bzs->next_in,
+				    PyString_FromStringAndSize(bzs->next_in,
 							       bzs->avail_in);
 			}
 			self->running = 0;
@@ -1699,7 +1691,7 @@
 			break; /* no more input data */
 		if (bzs->avail_out == 0) {
 			bufsize = Util_NewBufferSize(bufsize);
-			if (PyBytes_Resize(ret, bufsize) < 0) {
+			if (_PyString_Resize(&ret, bufsize) < 0) {
 				BZ2_bzDecompressEnd(bzs);
 				goto error;
 			}
@@ -1711,7 +1703,7 @@
 	}
 
 	if (bzs->avail_out != 0) {
-		if (PyBytes_Resize(ret,
+		if (_PyString_Resize(&ret,
 			    (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout)) < 0)
 			goto error;
 	}
@@ -1750,7 +1742,7 @@
 	}
 #endif
 
-	self->unused_data = PyBytes_FromStringAndSize("", 0);
+	self->unused_data = PyString_FromStringAndSize("", 0);
 	if (!self->unused_data)
 		goto error;
 
@@ -1785,7 +1777,7 @@
 #endif
 	Py_XDECREF(self->unused_data);
 	BZ2_bzDecompressEnd(&self->bzs);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 
@@ -1868,7 +1860,7 @@
 	int bzerror;
 	static char *kwlist[] = {"data", "compresslevel", 0};
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|i",
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y#|i",
 					 kwlist, &data, &datasize,
 					 &compresslevel))
 		return NULL;
@@ -1883,7 +1875,7 @@
 	 * data in one shot. We will check it later anyway. */
 	bufsize = datasize + (datasize/100+1) + 600;
 
-	ret = PyBytes_FromStringAndSize(NULL, bufsize);
+	ret = PyString_FromStringAndSize(NULL, bufsize);
 	if (!ret)
 		return NULL;
 
@@ -1915,9 +1907,8 @@
 		}
 		if (bzs->avail_out == 0) {
 			bufsize = Util_NewBufferSize(bufsize);
-			if (PyBytes_Resize(ret, bufsize) < 0) {
+			if (_PyString_Resize(&ret, bufsize) < 0) {
 				BZ2_bzCompressEnd(bzs);
-				Py_DECREF(ret);
 				return NULL;
 			}
 			bzs->next_out = BUF(ret) + BZS_TOTAL_OUT(bzs);
@@ -1926,8 +1917,7 @@
 	}
 
 	if (bzs->avail_out != 0) {
-		if (PyBytes_Resize(ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs)) < 0) {
-			Py_DECREF(ret);
+		if (_PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs)) < 0) {
 			ret = NULL;
 		}
 	}
@@ -1954,13 +1944,13 @@
 	bz_stream *bzs = &_bzs;
 	int bzerror;
 
-	if (!PyArg_ParseTuple(args, "s#:decompress", &data, &datasize))
+	if (!PyArg_ParseTuple(args, "y#:decompress", &data, &datasize))
 		return NULL;
 
 	if (datasize == 0)
-		return PyBytes_FromStringAndSize("", 0);
+		return PyString_FromStringAndSize("", 0);
 
-	ret = PyBytes_FromStringAndSize(NULL, bufsize);
+	ret = PyString_FromStringAndSize(NULL, bufsize);
 	if (!ret)
 		return NULL;
 
@@ -1999,9 +1989,8 @@
 		}
 		if (bzs->avail_out == 0) {
 			bufsize = Util_NewBufferSize(bufsize);
-			if (PyBytes_Resize(ret, bufsize) < 0) {
+			if (_PyString_Resize(&ret, bufsize) < 0) {
 				BZ2_bzDecompressEnd(bzs);
-				Py_DECREF(ret);
 				return NULL;
 			}
 			bzs->next_out = BUF(ret) + BZS_TOTAL_OUT(bzs);
@@ -2010,8 +1999,7 @@
 	}
 
 	if (bzs->avail_out != 0) {
-		if (PyBytes_Resize(ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs)) < 0) {
-			Py_DECREF(ret);
+		if (_PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs)) < 0) {
 			ret = NULL;
 		}
 	}
@@ -2043,9 +2031,9 @@
 {
 	PyObject *m;
 
-	Py_Type(&BZ2File_Type) = &PyType_Type;
-	Py_Type(&BZ2Comp_Type) = &PyType_Type;
-	Py_Type(&BZ2Decomp_Type) = &PyType_Type;
+	Py_TYPE(&BZ2File_Type) = &PyType_Type;
+	Py_TYPE(&BZ2Comp_Type) = &PyType_Type;
+	Py_TYPE(&BZ2Decomp_Type) = &PyType_Type;
 
 	m = Py_InitModule3("bz2", bz2_methods, bz2__doc__);
 	if (m == NULL)

Modified: python/branches/py3k-importlib/Modules/cStringIO.c
==============================================================================
--- python/branches/py3k-importlib/Modules/cStringIO.c	(original)
+++ python/branches/py3k-importlib/Modules/cStringIO.c	Thu Mar 27 00:48:05 2008
@@ -276,7 +276,7 @@
 
         if (!IO__opencheck(self)) return NULL;
 
-        return PyInt_FromSsize_t(self->pos);
+        return PyLong_FromSsize_t(self->pos);
 }
 
 PyDoc_STRVAR(IO_truncate__doc__,
@@ -566,8 +566,7 @@
 
 static PyObject *
 I_close(Iobject *self, PyObject *unused) {
-        Py_XDECREF(self->pbuf);
-        self->pbuf = NULL;
+        Py_CLEAR(self->pbuf);
         self->buf = NULL;
 
         self->pos = self->string_size = 0;
@@ -738,8 +737,8 @@
   d = PyModule_GetDict(m);
   
   /* Export C API */
-  Py_Type(&Itype)=&PyType_Type;
-  Py_Type(&Otype)=&PyType_Type;
+  Py_TYPE(&Itype)=&PyType_Type;
+  Py_TYPE(&Otype)=&PyType_Type;
   if (PyType_Ready(&Otype) < 0) return;
   if (PyType_Ready(&Itype) < 0) return;
   PyDict_SetItemString(d,"cStringIO_CAPI",

Modified: python/branches/py3k-importlib/Modules/cjkcodecs/_codecs_hk.c
==============================================================================
--- python/branches/py3k-importlib/Modules/cjkcodecs/_codecs_hk.c	(original)
+++ python/branches/py3k-importlib/Modules/cjkcodecs/_codecs_hk.c	Thu Mar 27 00:48:05 2008
@@ -26,6 +26,16 @@
 	return 0;
 }
 
+/*
+ * There are four possible pair unicode -> big5hkscs maps as in HKSCS 2004:
+ *  U+00CA U+0304 -> 8862  (U+00CA alone is mapped to 8866)
+ *  U+00CA U+030C -> 8864
+ *  U+00EA U+0304 -> 88a3  (U+00EA alone is mapped to 88a7)
+ *  U+00EA U+030C -> 88a5
+ * These are handled by not mapping tables but a hand-written code.
+ */
+static const DBCHAR big5hkscs_pairenc_table[4] = {0x8862, 0x8864, 0x88a3, 0x88a5};
+
 ENCODER(big5hkscs)
 {
 	while (inleft > 0) {
@@ -46,7 +56,27 @@
 		REQUIRE_OUTBUF(2)
 
 		if (c < 0x10000) {
-			TRYMAP_ENC(big5hkscs_bmp, code, c);
+			TRYMAP_ENC(big5hkscs_bmp, code, c) {
+				if (code == MULTIC) {
+					if (inleft >= 2 &&
+					    ((c & 0xffdf) == 0x00ca) &&
+					    (((*inbuf)[1] & 0xfff7) == 0x0304)) {
+						code = big5hkscs_pairenc_table[
+							((c >> 4) |
+							 ((*inbuf)[1] >> 3)) & 3];
+						insize = 2;
+					}
+					else if (inleft < 2 &&
+						 !(flags & MBENC_FLUSH))
+						return MBERR_TOOFEW;
+					else {
+						if (c == 0xca)
+							code = 0x8866;
+						else /* c == 0xea */
+							code = 0x88a7;
+					}
+				}
+			}
 			else TRYMAP_ENC(big5, code, c);
 			else return 1;
 		}
@@ -67,7 +97,7 @@
 	return 0;
 }
 
-#define BH2S(c1, c2) (((c1) - 0x88) * (0xfe - 0x40 + 1) + ((c2) - 0x40))
+#define BH2S(c1, c2) (((c1) - 0x87) * (0xfe - 0x40 + 1) + ((c2) - 0x40))
 
 DECODER(big5hkscs)
 {
@@ -96,19 +126,19 @@
 			int s = BH2S(c, IN2);
 			const unsigned char *hintbase;
 
-			assert(0x88 <= c && c <= 0xfe);
+			assert(0x87 <= c && c <= 0xfe);
 			assert(0x40 <= IN2 && IN2 <= 0xfe);
 
-			if (BH2S(0x88, 0x40) <= s && s <= BH2S(0xa0, 0xfe)) {
+			if (BH2S(0x87, 0x40) <= s && s <= BH2S(0xa0, 0xfe)) {
 				hintbase = big5hkscs_phint_0;
-				s -= BH2S(0x88, 0x40);
+				s -= BH2S(0x87, 0x40);
 			}
 			else if (BH2S(0xc6,0xa1) <= s && s <= BH2S(0xc8,0xfe)){
-				hintbase = big5hkscs_phint_11939;
+				hintbase = big5hkscs_phint_12130;
 				s -= BH2S(0xc6, 0xa1);
 			}
 			else if (BH2S(0xf9,0xd6) <= s && s <= BH2S(0xfe,0xfe)){
-				hintbase = big5hkscs_phint_21733;
+				hintbase = big5hkscs_phint_21924;
 				s -= BH2S(0xf9, 0xd6);
 			}
 			else
@@ -123,7 +153,17 @@
 				NEXT(2, 1)
 			}
 		}
-		else return 2;
+		else {
+			switch ((c << 8) | IN2) {
+			case 0x8862: WRITE2(0x00ca, 0x0304); break;
+			case 0x8864: WRITE2(0x00ca, 0x030c); break;
+			case 0x88a3: WRITE2(0x00ea, 0x0304); break;
+			case 0x88a5: WRITE2(0x00ea, 0x030c); break;
+			default: return 2;
+			}
+
+			NEXT(2, 2) /* all decoded codepoints are pairs, above. */
+		}
 	}
 
 	return 0;

Modified: python/branches/py3k-importlib/Modules/cjkcodecs/_codecs_iso2022.c
==============================================================================
--- python/branches/py3k-importlib/Modules/cjkcodecs/_codecs_iso2022.c	(original)
+++ python/branches/py3k-importlib/Modules/cjkcodecs/_codecs_iso2022.c	Thu Mar 27 00:48:05 2008
@@ -203,7 +203,7 @@
 				} else
 					encoded = dsg->encoder(&c, &length);
 #else
-				encoded = dsg->encoder(*inbuf, &length);
+				encoded = dsg->encoder(&c, &length);
 #endif
 				if (encoded != MAP_UNMAPPABLE) {
 					insize = length;

Modified: python/branches/py3k-importlib/Modules/cjkcodecs/cjkcodecs.h
==============================================================================
--- python/branches/py3k-importlib/Modules/cjkcodecs/cjkcodecs.h	(original)
+++ python/branches/py3k-importlib/Modules/cjkcodecs/cjkcodecs.h	Thu Mar 27 00:48:05 2008
@@ -245,7 +245,7 @@
 	static PyObject *cofunc = NULL;
 
 	if (cofunc == NULL) {
-		PyObject *mod = PyImport_ImportModule("_multibytecodec");
+		PyObject *mod = PyImport_ImportModuleNoBlock("_multibytecodec");
 		if (mod == NULL)
 			return NULL;
 		cofunc = PyObject_GetAttrString(mod, "__create_codec");

Modified: python/branches/py3k-importlib/Modules/cjkcodecs/mappings_hk.h
==============================================================================
--- python/branches/py3k-importlib/Modules/cjkcodecs/mappings_hk.h	(original)
+++ python/branches/py3k-importlib/Modules/cjkcodecs/mappings_hk.h	Thu Mar 27 00:48:05 2008
@@ -1,262 +1,271 @@
-static const ucs2_t __big5hkscs_decmap[6095] = {
-62211,62212,62213,62214,62215,268,62217,209,205,62220,62221,203,8168,62224,
-202,62226,62227,62228,62229,270,62231,62232,256,193,461,192,274,201,282,200,
-332,211,465,210,62245,7870,62247,7872,202,257,225,462,224,593,275,233,283,232,
-299,237,464,236,333,243,466,242,363,250,468,249,470,472,474,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,476,252,62276,7871,62278,
-7873,234,609,62282,62283,41897,4421,U,25866,U,U,20029,28381,40270,37343,U,U,
-30517,25745,20250,20264,20392,20822,20852,20892,20964,21153,21160,21307,21326,
-21457,21464,22242,22768,22788,22791,22834,22836,23398,23454,23455,23706,24198,
-24635,25993,26622,26628,26725,27982,28860,30005,32420,32428,32442,32455,32463,
-32479,32518,32567,33402,33487,33647,35270,35774,35810,36710,36711,36718,U,U,U,
-U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,29713,31996,
-32205,26950,31433,21031,U,U,U,U,37260,30904,37214,32956,U,36107,33014,2535,U,
-U,32927,40647,19661,40393,40460,19518,40438,28686,40458,41267,13761,U,28314,
-33342,29977,U,18705,39532,39567,40857,31111,33900,7626,1488,10982,20004,20097,
-20096,20103,20159,20203,20279,13388,20413,15944,20483,20616,13437,13459,13477,
-20870,22789,20955,20988,20997,20105,21113,21136,21287,13767,21417,13649,21424,
-13651,21442,21539,13677,13682,13953,21651,21667,21684,21689,21712,21743,21784,
-21795,21800,13720,21823,13733,13759,21975,13765,32132,21797,U,3138,3349,20779,
-21904,11462,14828,833,36422,19896,38117,16467,32958,30586,11320,14900,18389,
-33117,27122,19946,25821,3452,4020,3285,4340,25741,36478,3734,3083,3940,11433,
-33366,17619,U,3398,39501,33001,18420,20135,11458,39602,14951,38388,16365,
-13574,21191,38868,30920,11588,40302,38933,U,17369,24741,25780,21731,11596,
-11210,4215,14843,4207,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,26330,26390,31136,25834,20562,3139,36456,8609,35660,1841,U,18443,
-425,16378,22643,11661,U,17864,1276,24727,3916,3478,21881,16571,17338,U,19124,
-10854,4253,33194,39157,3484,25465,14846,10101,36288,22177,25724,15939,U,42497,
-3593,10959,11465,U,4296,14786,14738,14854,33435,13688,24137,8391,22098,3889,
-11442,38688,13500,27709,20027,U,U,30068,11915,8712,42587,36045,3706,3124,
-26652,32659,4303,10243,10553,13819,20963,3724,3981,3754,16275,3888,3399,4431,
-3660,U,3755,2985,3400,4288,4413,16377,9878,25650,4013,13300,30265,11214,3454,
-3455,11345,11349,14872,3736,4295,3886,42546,27472,36050,36249,36042,38314,
-21708,33476,21945,U,40643,39974,39606,30558,11758,28992,33133,33004,23580,
-25970,33076,14231,21343,32957,37302,3834,3599,3703,3835,13789,19947,13833,
-3286,22191,10165,4297,3600,3704,4216,4424,33287,5205,3705,20048,11684,23124,
-4125,4126,4341,4342,22428,3601,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,U,U,U,U,30356,33485,4021,3707,20862,14083,4022,4480,21208,41661,
-18906,6202,16759,33404,22681,21096,13850,22333,31666,23400,18432,19244,40743,
-18919,39967,39821,23412,12605,22011,13810,22153,20008,22786,7105,63608,38737,
-134,20059,20155,13630,23587,24401,24516,14586,25164,25909,27514,27701,27706,
-28780,29227,20012,29357,18665,32594,31035,31993,32595,25194,13505,U,25419,
-32770,32896,26130,26961,21341,34916,35265,30898,35744,36125,38021,38264,38271,
-38376,36367,38886,39029,39118,39134,39267,38928,40060,40479,40644,27503,63751,
-20023,135,38429,25143,38050,20539,28158,40051,62842,15817,34959,16718,28791,
-23797,19232,20941,13657,23856,24866,35378,36775,37366,29073,26393,29626,12929,
-41223,15499,6528,19216,30948,29698,20910,34575,16393,27235,41658,16931,34319,
-U,31274,39239,35562,38741,28749,21284,8318,37876,30425,35299,62884,30685,
-20131,20464,20668,20015,20247,62891,21556,32139,22674,22736,7606,24210,24217,
-24514,10002,25995,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,13305,26905,27203,15459,27903,U,29184,17669,29580,16091,18963,23317,
-29881,35715,23716,22165,31379,31724,31939,32364,33528,34199,62924,34960,62926,
-36537,62928,36815,34143,39392,37409,62933,36281,5183,16497,17058,23066,U,U,U,
-39016,26475,17014,22333,U,34262,18811,33471,28941,19585,28020,23931,27413,
-28606,62956,62957,23446,62959,U,32347,23870,23880,23894,15868,14351,23972,
-23993,14368,14392,24130,24253,24357,24451,14600,14612,14655,14669,24791,24893,
-23781,14729,25015,25017,25039,14776,25132,25232,25317,25368,14840,22193,U,U,U,
-U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,14851,25570,
-25595,25607,25690,14923,25792,23829,22049,40863,14999,25990,15037,26111,26195,
-15090,26258,15138,26390,15170,26532,26624,15192,26698,26756,15218,15217,15227,
-26889,26947,29276,26980,27039,27013,15292,27094,15325,27237,27252,27249,27266,
-15340,27289,15346,27307,27317,27348,27382,27521,27585,27626,27765,27818,15563,
-27906,27910,27942,28033,15599,28068,28081,28181,28184,28201,28294,35264,28347,
-28386,28378,40831,28392,28393,28452,28468,15686,16193,28545,28606,15722,15733,
-29111,23705,15754,28716,15761,28752,28756,28783,28799,28809,805,17345,13809,
-3800,16087,22462,28371,28990,22496,13902,27042,35817,23412,31305,22753,38105,
-31333,31357,22956,31419,31408,31426,31427,29137,25741,16842,31450,31453,31466,
-16879,21682,23553,31499,31573,31529,21262,23806,31650,31599,33692,23476,27775,
-31696,33825,31634,U,23840,15789,23653,33938,31738,U,31797,23745,31812,31875,
-18562,31910,26237,17784,31945,31943,31974,31860,31987,31989,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,32359,17693,28228,32093,
-28374,29837,32137,32171,28981,32179,U,16471,24617,32228,15635,32245,6137,
-32229,33645,U,24865,24922,32366,32402,17195,37996,32295,32576,32577,32583,
-31030,25296,39393,32663,25425,32675,5729,104,17756,14182,17667,33594,32762,
-25737,U,32776,32797,U,32815,41095,27843,32827,32828,32865,10004,18825,26150,
-15843,26344,26405,32935,35400,33031,33050,22704,9974,27775,25752,20408,25831,
-5258,33304,6238,27219,19045,19093,17530,33321,2829,27218,15742,20473,5373,
-34018,33634,27402,18855,13616,6003,15864,33450,26907,63892,16859,34123,33488,
-33562,3606,6068,14017,12669,13658,33403,33506,33560,16011,28067,27397,27543,
-13774,15807,33565,21996,33669,17675,28069,33708,U,33747,13438,28372,27223,
-34138,13462,28226,12015,33880,23524,33905,15827,17636,27303,33866,15541,31064,
-U,27542,28279,28227,34014,U,33681,17568,33939,34020,23697,16960,23744,17731,
-34100,23282,28313,17703,34163,17686,26559,34326,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,34341,34363,34241,28808,34306,5506,
-28877,63922,17770,34344,13896,6306,21495,29594,34430,34673,41208,34798,11303,
-34737,34778,34831,22113,34412,26710,17935,34885,34886,30176,15801,30180,34910,
-34972,18011,34996,34997,25537,35013,30583,30479,35207,35210,U,U,35239,35260,
-35365,35303,31012,31421,35484,30611,37374,35472,31321,31465,31546,16271,18195,
-31544,29052,35596,35615,21552,21861,35647,35660,35661,35497,19066,35728,35739,
-35503,5855,17941,34895,35995,32084,32143,63956,14117,32083,36054,32152,32189,
-36114,36099,6416,36059,28764,36113,19657,16080,36265,32770,4116,18826,15228,
-33212,28940,31463,36525,36534,36547,37588,36633,36653,33637,33810,36773,37635,
-41631,2640,36787,18730,35294,34109,15803,24312,12898,36857,40980,34492,34049,
-8997,14720,28375,36919,34108,31422,36961,34156,34315,37032,34579,37060,34534,
-37038,U,37223,15088,37289,37316,31916,35123,7817,37390,27807,37441,37474,
-21945,U,35526,15515,35596,21979,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,U,U,U,U,3377,37676,37739,35553,35819,28815,23235,35554,35557,
-18789,37444,35820,35897,35839,37747,37979,36540,38277,38310,37926,38304,28662,
-17081,9850,34520,4732,15918,18911,27676,38523,38550,16748,38563,28373,25050,
-38582,30965,35552,38589,21452,18849,27832,628,25616,37039,37093,19153,6421,
-13066,38705,34370,38710,18959,17725,17797,19177,28789,23361,38683,U,37333,
-38743,23370,37355,38751,37925,20688,12471,12476,38793,38815,38833,38846,38848,
-38866,38880,21612,38894,29724,37939,U,38901,37917,31098,19153,38964,38963,
-38987,39014,15118,29045,15697,1584,16732,22278,39114,39095,39112,39111,19199,
-27943,5843,21936,39137,39142,39148,37752,39225,18985,19314,38999,39173,39413,
-39436,39483,39440,39512,22309,14020,37041,39893,39648,39650,39685,39668,19470,
-39700,39725,34304,20532,39732,27048,14531,12413,39760,39744,40254,23109,6243,
-39822,16971,39938,39935,39948,40552,40404,40887,41362,41387,41185,41251,41439,
-40318,40323,41268,40462,26760,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,U,U,U,40388,8539,41363,41504,6459,41523,40249,41145,41652,40592,
-40597,40606,40610,19764,40618,40623,17252,40641,15200,14821,15645,20274,14270,
-35883,40706,40712,19350,37924,28066,40727,U,40761,22175,22154,40773,39352,
-37003,38898,33919,40802,40809,31452,40846,29206,19390,18805,18875,29047,18936,
-17224,19025,29598,35802,6394,31135,35198,36406,37737,37875,35396,37612,37761,
-37835,35180,17593,29207,16107,30578,31299,28880,17523,17400,29054,6127,28835,
-6334,13721,16071,6277,21551,6136,14114,5883,6201,14049,6004,6353,24395,14115,
-5824,22363,18981,5118,4776,5062,5302,34051,13990,U,33877,18836,29029,15921,
-21852,16123,28754,17652,14062,39325,28454,26617,14131,15381,15847,22636,6434,
-26640,16471,14143,16609,16523,16655,27681,21707,22174,26289,22162,4063,2984,
-3597,37830,35603,37788,20216,20779,14361,17462,20156,1125,895,20299,20362,
-22097,23144,427,971,14745,778,1044,13365,20265,704,36531,629,35546,524,20120,
-U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,20685,
-20749,20386,20227,18958,16010,20290,20526,20588,20609,20428,20453,20568,20732,
-U,U,U,U,28278,13717,15929,16063,28018,6276,16009,20904,20931,1504,17629,1187,
-1170,1169,36218,35484,1806,21081,21156,2163,21217,U,18042,29068,17292,3104,
-18860,4324,27089,3613,U,16094,29849,29716,29782,29592,19342,19132,16525,21456,
-13700,29199,16585,21940,837,21709,3014,22301,37469,38644,37734,22493,22413,
-22399,13886,22731,23193,35398,5882,5999,5904,23084,22968,37519,23166,23247,
-23058,22854,6643,6241,17045,14069,27909,29763,23073,24195,23169,35799,1043,
-37856,29836,4867,28933,18802,37896,35323,37821,14240,23582,23710,24158,24136,
-6550,6524,15086,24269,23375,6403,6404,14081,6304,14045,5886,14035,33066,35399,
-7610,13426,35240,24332,24334,6439,6059,23147,5947,23364,34324,30205,34912,
-24702,10336,9771,24539,16056,9647,9662,37000,28531,25024,62,70,9755,24985,
-24984,24693,11419,11527,18132,37197,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,U,U,U,U,U,U,25713,18021,11114,14889,11042,13392,39146,11896,
-25399,42075,25782,25393,25553,18915,11623,25252,11425,25659,25963,26994,15348,
-12430,12973,18825,12971,21773,13024,6361,37951,26318,12937,12723,15072,16784,
-21892,35618,21903,5884,21851,21541,30958,12547,6186,12852,13412,12815,12674,
-17097,26254,27940,26219,19347,26160,30832,7659,26211,13010,13025,26142,22642,
-14545,14394,14268,15257,14242,13310,29904,15254,26511,17962,26806,26654,15300,
-27326,14435,14293,17543,27187,27218,27337,27397,6418,25873,26776,27212,15319,
-27258,27479,16320,15514,37792,37618,35818,35531,37513,32798,35292,37991,28069,
-28427,18924,U,16255,15759,28164,16444,23101,28170,22599,27940,30786,28987,
-17178,17014,28913,29264,29319,29332,18319,18213,20857,19108,1515,29818,16120,
-13919,19018,18711,24545,16134,16049,19167,35875,16181,24743,16115,29900,29756,
-37767,29751,17567,28138,17745,30083,16227,19673,19718,16216,30037,30323,42438,
-15129,29800,35532,18859,18830,15099,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,U,U,U,U,U,U,15821,19022,16127,18885,18675,37370,22322,37698,
-35555,6244,20703,21025,20967,30584,12850,30478,30479,30587,18071,14209,14942,
-18672,29752,29851,16063,19130,19143,16584,19094,25006,37639,21889,30750,30861,
-30856,30930,29648,31065,30529,22243,16654,U,33942,31141,27181,16122,31290,
-31220,16750,5862,16690,37429,31217,3404,18828,665,15802,5998,13719,21867,
-13680,13994,468,3085,31458,23129,9973,23215,23196,23053,603,30960,23082,23494,
-31486,16889,31837,31853,16913,23475,24252,24230,31949,18937,6064,31886,31868,
-31918,27314,32220,32263,32211,32590,25185,24924,31560,32151,24194,17002,27509,
-2326,26582,78,13775,22468,25618,25592,18786,32733,31527,2092,23273,23875,
-31500,24078,39398,34373,39523,27164,13375,14818,18935,26029,39455,26016,33920,
-28967,27857,17642,33079,17410,32966,33033,33090,26548,39107,27202,33378,33381,
-27217,33875,28071,34320,29211,23174,16767,6208,23339,6305,23268,6360,34464,
-63932,15759,34861,29730,23042,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,U,U,U,34926,20293,34951,35007,35046,35173,35149,22147,35156,
-30597,30596,35829,35801,35740,35321,16045,33955,18165,18127,14322,35389,35356,
-37960,24397,37419,17028,26068,28969,28868,6213,40301,35999,36073,32220,22938,
-30659,23024,17262,14036,36394,36519,19465,36656,36682,17140,27736,28603,8993,
-18587,28537,28299,6106,39913,14005,18735,37051,U,21873,18694,37307,37892,
-35403,16482,35580,37927,35869,35899,34021,35371,38297,38311,38295,38294,36148,
-29765,16066,18687,19010,17386,16103,12837,38543,36583,36454,36453,16076,18925,
-19064,16366,29714,29803,16124,38721,37040,26695,18973,37011,22495,U,37736,
-35209,35878,35631,25534,37562,23313,35689,18748,29689,16923,38811,38769,39224,
-3878,24001,35781,19122,38943,38106,37622,38359,37349,17600,35664,19047,35684,
-39132,35397,16128,37418,18725,33812,39227,39245,31494,15869,39323,19311,39338,
-39516,35685,22728,27279,39457,23294,39471,39153,19344,39240,39356,19389,19351,
-37757,22642,4866,22562,18872,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,U,U,U,5352,30788,10015,15800,26821,15741,37976,14631,24912,
-10113,10603,24839,40015,40019,40059,39989,39952,39807,39887,40493,39839,41461,
-41214,40225,19630,16644,40472,19632,40204,41396,41197,41203,39215,40357,33981,
-28178,28639,27522,34300,17715,28068,28292,28144,33824,34286,28160,14295,24676,
-31202,13724,13888,18733,18910,15714,37851,37566,37704,703,30905,37495,37965,
-20452,13376,36964,21853,30781,30804,30902,30795,5975,12745,18753,13978,20338,
-28634,28633,U,28702,21524,16821,22459,22771,22410,40214,22487,28980,13487,
-16812,29163,27712,20375,U,6069,35401,24844,23246,23051,17084,17544,14124,
-19323,35324,37819,37816,6358,3869,33906,27840,5139,17146,11302,17345,22932,
-15799,26433,32168,24923,24740,18873,18827,35322,37605,29666,16105,29876,35683,
-6303,16097,19123,27352,29683,29691,16086,19006,19092,6105,19046,935,5156,
-18917,29768,18710,28837,18806,37508,29670,37727,1278,37681,35534,35350,37766,
-35815,21973,18741,35458,29035,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,U,U,U,18755,3327,22180,1562,3051,3256,21762,31172,6138,32254,
-5826,19024,6226,17710,37889,14090,35520,18861,22960,6335,6275,29828,23201,
-14050,15707,14000,37471,23161,35457,6242,37748,15565,2740,19094,14730,20724,
-15721,15692,5020,29045,17147,33304,28175,37092,17643,27991,32335,28775,27823,
-15574,16365,15917,28162,28428,15727,1013,30033,14012,13512,18048,16090,18545,
-22980,37486,18750,36673,35868,27584,22546,22472,14038,5202,28926,17250,19057,
-12259,4784,9149,26809,26983,5016,13541,31732,14047,35459,14294,13306,19615,
-27162,13997,27831,33854,17631,17614,27942,27985,27778,28638,28439,28937,33597,
-5946,33773,27776,28755,6107,22921,23170,6067,23137,23153,6405,16892,14125,
-23023,5948,14023,29070,37776,26266,17061,23150,23083,17043,27179,16121,30518,
-17499,17098,28957,16985,35297,20400,27944,23746,17614,32333,17341,27148,16982,
-4868,28838,28979,17385,15781,27871,63525,19023,32357,23019,23855,15859,24412,
-19037,6111,32164,33830,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,21637,15098,13056,532,22398,2261,1561,16357,8094,41654,28675,
-37211,23920,29583,31955,35417,37920,20424,32743,29389,29456,31476,29496,29497,
-22262,29505,29512,16041,31512,36972,29173,18674,29665,33270,16074,30476,16081,
-27810,22269,29721,29726,29727,16098,16112,16116,16122,29907,16142,16211,30018,
-30061,30066,30093,16252,30152,30172,16320,30285,16343,30324,16348,30330,20316,
-29064,22051,35200,22633,16413,30531,16441,26465,16453,13787,30616,16490,16495,
-23646,30654,30667,22770,30744,28857,30748,16552,30777,30791,30801,30822,33864,
-21813,31027,26627,31026,16643,16649,31121,31129,36795,31238,36796,16743,31377,
-16818,31420,33401,16836,31439,31451,16847,20001,31586,31596,31611,31762,31771,
-16992,17018,31867,31900,17036,31928,17044,31981,36755,28864,3279,32207,32212,
-32208,32253,32686,32692,29343,17303,32800,32805,31545,32814,32817,32852,15820,
-22452,28832,32951,33001,17389,33036,29482,33038,33042,30048,33044,17409,15161,
-33110,33113,33114,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,17427,22586,33148,33156,17445,33171,17453,33189,22511,33217,33252,
-33364,17551,33446,33398,33482,33496,33535,17584,33623,38505,27018,33797,28917,
-33892,24803,33928,17668,33982,34017,34040,34064,34104,34130,17723,34159,34160,
-34272,17783,34418,34450,34482,34543,38469,34699,17926,17943,34990,35071,35108,
-35143,35217,31079,35369,35384,35476,35508,35921,36052,36082,36124,18328,22623,
-36291,18413,20206,36410,21976,22356,36465,22005,36528,18487,36558,36578,36580,
-36589,36594,36791,36801,36810,36812,36915,39364,18605,39136,37395,18718,37416,
-37464,37483,37553,37550,37567,37603,37611,37619,37620,37629,37699,37764,37805,
-18757,18769,40639,37911,21249,37917,37933,37950,18794,37972,38009,38189,38306,
-18855,38388,38451,18917,26528,18980,38720,18997,38834,38850,22100,19172,24808,
-39097,19225,39153,22596,39182,39193,20916,39196,39223,39234,39261,39266,19312,
-39365,19357,39484,39695,31363,39785,39809,39901,39921,39924,19565,39968,14191,
-7106,40265,39994,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,40702,22096,40339,40381,40384,40444,38134,36790,40571,40620,40625,
-40637,40646,38108,40674,40689,40696,31432,40772,148,695,928,26906,38083,22956,
-1239,22592,38081,14265,1493,1557,1654,5818,22359,29043,2754,2765,3007,21610,
-63547,3019,21662,3067,3131,3155,3173,3196,24807,3213,22138,3253,3293,3309,
-3439,3506,3528,26965,39983,34725,3588,3598,3799,3984,3885,3699,23584,4028,
-24075,4188,4175,4214,26398,4219,4232,4246,13895,4287,4307,4399,4411,21348,
-33965,4835,4981,4918,35713,5495,5657,6083,6087,20088,28859,6189,6506,6701,
-6725,7210,7280,7340,7880,25283,7893,7957,29080,26709,8261,27113,14024,8828,
-9175,9210,10026,10353,10575,33533,10599,10643,10965,35237,10984,36768,11022,
-38840,11071,38983,39613,11340,U,11400,11447,23528,11528,11538,11703,11669,
-11842,12148,12236,12339,12390,13087,13278,24497,26184,26303,31353,13671,13811,
-U,18874,U,13850,14102,U,838,22709,26382,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,26904,15015,30295,24546,15889,16057,30206,8346,
-18640,19128,16665,35482,17134,17165,16443,17204,17302,19013,1482,20946,1553,
-22943,7848,15294,15615,17412,17622,22408,18036,14747,18223,34280,39369,14178,
-8643,35678,35662,U,18450,18683,18965,29193,19136,3192,22885,20133,20358,1913,
-36570,20524,21135,22335,29041,21145,21529,16202,19111,21948,21574,21614,27474,
-U,13427,21823,30258,21854,18200,21858,21862,22471,18751,22621,20582,13563,
-13260,U,22787,18300,35144,23214,23433,23558,7568,22433,29009,U,24834,31762,
-36950,25010,20378,35682,25602,25674,23899,27639,U,25732,6428,35562,18934,
-25736,16367,25874,19392,26047,26293,10011,37989,22497,24981,23079,63693,U,
-22201,17697,26364,20074,18740,38486,28047,27837,13848,35191,26521,26734,25617,
-26718,U,26823,31554,37056,2577,26918,U,26937,31301,U,27130,39462,27181,13919,
-25705,33,31107,27188,27483,23852,13593,U,27549,18128,27812,30011,34917,28078,
-22710,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-14108,9613,28747,29133,15444,29312,29317,37505,8570,29323,37680,29414,18896,
-27705,38047,29776,3832,34855,35061,10534,33907,6065,28344,18986,6176,14756,
-14009,U,U,17727,26294,40109,39076,35139,30668,30808,22230,16607,5642,14753,
-14127,33000,5061,29101,33638,31197,37288,U,19639,28847,35243,31229,31242,
-31499,32102,16762,31555,31102,32777,28597,41695,27139,33560,21410,28167,37823,
-26678,38749,33135,32803,27061,5101,12847,32840,23941,35888,32899,22293,38947,
-35145,23979,18824,26046,27093,21458,19109,16257,15377,26422,32912,33012,33070,
-8097,33103,33161,33199,33306,33542,33583,33674,13770,33896,34474,18682,25574,
-35158,30728,37461,35256,17394,35303,17375,35304,35654,35796,23032,35849,U,
-36805,37100,U,37136,37180,15863,37214,19146,36816,29327,22155,38119,38377,
+static const ucs2_t __big5hkscs_decmap[6219] = {
+17392,19506,17923,17830,17784,29287,19831,17843,31921,19682,31941,15253,18230,
+18244,19527,19520,17087,13847,29522,28299,28882,19543,41809,18255,17882,19589,
+31852,19719,19108,18081,27427,29221,23124,6755,15878,16225,26189,22267,U,
+32149,22813,35769,15860,38708,31727,23515,7518,23204,13861,40624,23249,23479,
+23804,26478,34195,39237,29793,29853,12736,12737,12738,12739,12740,268,12741,
+209,205,12742,12743,203,8168,12744,202,12745,12746,12747,12748,270,12749,
+12750,256,193,461,192,274,201,282,200,332,211,465,210,U,7870,U,7872,202,257,
+225,462,224,593,275,233,283,232,299,237,464,236,333,243,466,242,363,250,468,
+249,470,472,474,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,476,252,U,7871,U,7873,234,609,9178,9179,41897,4421,U,25866,U,U,20029,
+28381,40270,37343,U,U,30517,25745,20250,20264,20392,20822,20852,20892,20964,
+21153,21160,21307,21326,21457,21464,22242,22768,22788,22791,22834,22836,23398,
+23454,23455,23706,24198,24635,25993,26622,26628,26725,27982,28860,30005,32420,
+32428,32442,32455,32463,32479,32518,32567,33402,33487,33647,35270,35774,35810,
+36710,36711,36718,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,29713,31996,32205,26950,31433,21031,U,U,U,U,37260,30904,37214,32956,U,
+36107,33014,2535,U,U,32927,40647,19661,40393,40460,19518,40438,28686,40458,
+41267,13761,U,28314,33342,29977,U,18705,39532,39567,40857,31111,33900,7626,
+1488,10982,20004,20097,20096,20103,20159,20203,20279,13388,20413,15944,20483,
+20616,13437,13459,13477,20870,22789,20955,20988,20997,20105,21113,21136,21287,
+13767,21417,13649,21424,13651,21442,21539,13677,13682,13953,21651,21667,21684,
+21689,21712,21743,21784,21795,21800,13720,21823,13733,13759,21975,13765,32132,
+21797,U,3138,3349,20779,21904,11462,14828,833,36422,19896,38117,16467,32958,
+30586,11320,14900,18389,33117,27122,19946,25821,3452,4020,3285,4340,25741,
+36478,3734,3083,3940,11433,33366,17619,U,3398,39501,33001,18420,20135,11458,
+39602,14951,38388,16365,13574,21191,38868,30920,11588,40302,38933,U,17369,
+24741,25780,21731,11596,11210,4215,14843,4207,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,26330,26390,31136,25834,20562,3139,36456,
+8609,35660,1841,U,18443,425,16378,22643,11661,U,17864,1276,24727,3916,3478,
+21881,16571,17338,U,19124,10854,4253,33194,39157,3484,25465,14846,10101,36288,
+22177,25724,15939,U,42497,3593,10959,11465,U,4296,14786,14738,14854,33435,
+13688,24137,8391,22098,3889,11442,38688,13500,27709,20027,U,U,30068,11915,
+8712,42587,36045,3706,3124,26652,32659,4303,10243,10553,13819,20963,3724,3981,
+3754,16275,3888,3399,4431,3660,U,3755,2985,3400,4288,4413,16377,9878,25650,
+4013,13300,30265,11214,3454,3455,11345,11349,14872,3736,4295,3886,42546,27472,
+36050,36249,36042,38314,21708,33476,21945,U,40643,39974,39606,30558,11758,
+28992,33133,33004,23580,25970,33076,14231,21343,32957,37302,3834,3599,3703,
+3835,13789,19947,13833,3286,22191,10165,4297,3600,3704,4216,4424,33287,5205,
+3705,20048,11684,23124,4125,4126,4341,4342,22428,3601,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,30356,33485,4021,3707,20862,14083,
+4022,4480,21208,41661,18906,6202,16759,33404,22681,21096,13850,22333,31666,
+23400,18432,19244,40743,18919,39967,39821,23412,12605,22011,13810,22153,20008,
+22786,7105,63608,38737,134,20059,20155,13630,23587,24401,24516,14586,25164,
+25909,27514,27701,27706,28780,29227,20012,29357,18665,32594,31035,31993,32595,
+25194,13505,U,25419,32770,32896,26130,26961,21341,34916,35265,30898,35744,
+36125,38021,38264,38271,38376,36367,38886,39029,39118,39134,39267,38928,40060,
+40479,40644,27503,63751,20023,135,38429,25143,38050,20539,28158,40051,40870,
+15817,34959,16718,28791,23797,19232,20941,13657,23856,24866,35378,36775,37366,
+29073,26393,29626,12929,41223,15499,6528,19216,30948,29698,20910,34575,16393,
+27235,41658,16931,34319,2671,31274,39239,35562,38741,28749,21284,8318,37876,
+30425,35299,40871,30685,20131,20464,20668,20015,20247,40872,21556,32139,22674,
+22736,7606,24210,24217,24514,10002,25995,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,13305,26905,27203,15459,27903,U,29184,17669,
+29580,16091,18963,23317,29881,35715,23716,22165,31379,31724,31939,32364,33528,
+34199,40873,34960,40874,36537,40875,36815,34143,39392,37409,40876,36281,5183,
+16497,17058,23066,U,U,U,39016,26475,17014,22333,U,34262,18811,33471,28941,
+19585,28020,23931,27413,28606,40877,40878,23446,40879,26343,32347,28247,31178,
+15752,17603,12886,10134,17306,17718,U,23765,15130,35577,23672,15634,13649,
+23928,40882,29015,17752,16620,7715,19575,14712,13386,420,27713,35532,20404,
+569,22975,33132,38998,39162,24379,2975,U,8641,35181,16642,18107,36985,16135,
+40883,41397,16632,14294,18167,27718,16764,34482,29695,17773,14548,21658,17761,
+17691,19849,19579,19830,17898,16328,19215,13921,17630,17597,16877,23870,23880,
+23894,15868,14351,23972,23993,14368,14392,24130,24253,24357,24451,14600,14612,
+14655,14669,24791,24893,23781,14729,25015,25017,25039,14776,25132,25232,25317,
+25368,14840,22193,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,14851,25570,25595,25607,25690,14923,25792,23829,22049,40863,14999,
+25990,15037,26111,26195,15090,26258,15138,26390,15170,26532,26624,15192,26698,
+26756,15218,15217,15227,26889,26947,29276,26980,27039,27013,15292,27094,15325,
+27237,27252,27249,27266,15340,27289,15346,27307,27317,27348,27382,27521,27585,
+27626,27765,27818,15563,27906,27910,27942,28033,15599,28068,28081,28181,28184,
+28201,28294,35264,28347,28386,28378,40831,28392,28393,28452,28468,15686,16193,
+28545,28606,15722,15733,29111,23705,15754,28716,15761,28752,28756,28783,28799,
+28809,805,17345,13809,3800,16087,22462,28371,28990,22496,13902,27042,35817,
+23412,31305,22753,38105,31333,31357,22956,31419,31408,31426,31427,29137,25741,
+16842,31450,31453,31466,16879,21682,23553,31499,31573,31529,21262,23806,31650,
+31599,33692,23476,27775,31696,33825,31634,U,23840,15789,23653,33938,31738,U,
+31797,23745,31812,31875,18562,31910,26237,17784,31945,31943,31974,31860,31987,
+31989,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+32359,17693,28228,32093,28374,29837,32137,32171,28981,32179,U,16471,24617,
+32228,15635,32245,6137,32229,33645,U,24865,24922,32366,32402,17195,37996,
+32295,32576,32577,32583,31030,25296,39393,32663,25425,32675,5729,104,17756,
+14182,17667,33594,32762,25737,U,32776,32797,U,32815,41095,27843,32827,32828,
+32865,10004,18825,26150,15843,26344,26405,32935,35400,33031,33050,22704,9974,
+27775,25752,20408,25831,5258,33304,6238,27219,19045,19093,17530,33321,2829,
+27218,15742,20473,5373,34018,33634,27402,18855,13616,6003,15864,33450,26907,
+63892,16859,34123,33488,33562,3606,6068,14017,12669,13658,33403,33506,33560,
+16011,28067,27397,27543,13774,15807,33565,21996,33669,17675,28069,33708,U,
+33747,13438,28372,27223,34138,13462,28226,12015,33880,23524,33905,15827,17636,
+27303,33866,15541,31064,U,27542,28279,28227,34014,U,33681,17568,33939,34020,
+23697,16960,23744,17731,34100,23282,28313,17703,34163,17686,26559,34326,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,34341,34363,
+34241,28808,34306,5506,28877,63922,17770,34344,13896,6306,21495,29594,34430,
+34673,41208,34798,11303,34737,34778,34831,22113,34412,26710,17935,34885,34886,
+30176,15801,30180,34910,34972,18011,34996,34997,25537,35013,30583,30479,35207,
+35210,U,U,35239,35260,35365,35303,31012,31421,35484,30611,37374,35472,31321,
+31465,31546,16271,18195,31544,29052,35596,35615,21552,21861,35647,35660,35661,
+35497,19066,35728,35739,35503,5855,17941,34895,35995,32084,32143,63956,14117,
+32083,36054,32152,32189,36114,36099,6416,36059,28764,36113,19657,16080,36265,
+32770,4116,18826,15228,33212,28940,31463,36525,36534,36547,37588,36633,36653,
+33637,33810,36773,37635,41631,2640,36787,18730,35294,34109,15803,24312,12898,
+36857,40980,34492,34049,8997,14720,28375,36919,34108,31422,36961,34156,34315,
+37032,34579,37060,34534,37038,U,37223,15088,37289,37316,31916,35123,7817,
+37390,27807,37441,37474,21945,U,35526,15515,35596,21979,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,3377,37676,37739,35553,35819,
+28815,23235,35554,35557,18789,37444,35820,35897,35839,37747,37979,36540,38277,
+38310,37926,38304,28662,17081,9850,34520,4732,15918,18911,27676,38523,38550,
+16748,38563,28373,25050,38582,30965,35552,38589,21452,18849,27832,628,25616,
+37039,37093,19153,6421,13066,38705,34370,38710,18959,17725,17797,19177,28789,
+23361,38683,U,37333,38743,23370,37355,38751,37925,20688,12471,12476,38793,
+38815,38833,38846,38848,38866,38880,21612,38894,29724,37939,U,38901,37917,
+31098,19153,38964,38963,38987,39014,15118,29045,15697,1584,16732,22278,39114,
+39095,39112,39111,19199,27943,5843,21936,39137,39142,39148,37752,39225,18985,
+19314,38999,39173,39413,39436,39483,39440,39512,22309,14020,37041,39893,39648,
+39650,39685,39668,19470,39700,39725,34304,20532,39732,27048,14531,12413,39760,
+39744,40254,23109,6243,39822,16971,39938,39935,39948,40552,40404,40887,41362,
+41387,41185,41251,41439,40318,40323,41268,40462,26760,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,40388,8539,41363,41504,6459,41523,
+40249,41145,41652,40592,40597,40606,40610,19764,40618,40623,17252,40641,15200,
+14821,15645,20274,14270,35883,40706,40712,19350,37924,28066,40727,U,40761,
+22175,22154,40773,39352,37003,38898,33919,40802,40809,31452,40846,29206,19390,
+18805,18875,29047,18936,17224,19025,29598,35802,6394,31135,35198,36406,37737,
+37875,35396,37612,37761,37835,35180,17593,29207,16107,30578,31299,28880,17523,
+17400,29054,6127,28835,6334,13721,16071,6277,21551,6136,14114,5883,6201,14049,
+6004,6353,24395,14115,5824,22363,18981,5118,4776,5062,5302,34051,13990,U,
+33877,18836,29029,15921,21852,16123,28754,17652,14062,39325,28454,26617,14131,
+15381,15847,22636,6434,26640,16471,14143,16609,16523,16655,27681,21707,22174,
+26289,22162,4063,2984,3597,37830,35603,37788,20216,20779,14361,17462,20156,
+1125,895,20299,20362,22097,23144,427,971,14745,778,1044,13365,20265,704,36531,
+629,35546,524,20120,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,20685,20749,20386,20227,18958,16010,20290,20526,20588,20609,20428,
+20453,20568,20732,U,U,U,U,28278,13717,15929,16063,28018,6276,16009,20904,
+20931,1504,17629,1187,1170,1169,36218,35484,1806,21081,21156,2163,21217,U,
+18042,29068,17292,3104,18860,4324,27089,3613,U,16094,29849,29716,29782,29592,
+19342,19132,16525,21456,13700,29199,16585,21940,837,21709,3014,22301,37469,
+38644,37734,22493,22413,22399,13886,22731,23193,35398,5882,5999,5904,23084,
+22968,37519,23166,23247,23058,22854,6643,6241,17045,14069,27909,29763,23073,
+24195,23169,35799,1043,37856,29836,4867,28933,18802,37896,35323,37821,14240,
+23582,23710,24158,24136,6550,6524,15086,24269,23375,6403,6404,14081,6304,
+14045,5886,14035,33066,35399,7610,13426,35240,24332,24334,6439,6059,23147,
+5947,23364,34324,30205,34912,24702,10336,9771,24539,16056,9647,9662,37000,
+28531,25024,62,70,9755,24985,24984,24693,11419,11527,18132,37197,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,25713,18021,11114,
+14889,11042,13392,39146,11896,25399,42075,25782,25393,25553,18915,11623,25252,
+11425,25659,25963,26994,15348,12430,12973,18825,12971,21773,13024,6361,37951,
+26318,12937,12723,15072,16784,21892,35618,21903,5884,21851,21541,30958,12547,
+6186,12852,13412,12815,12674,17097,26254,27940,26219,19347,26160,30832,7659,
+26211,13010,13025,26142,22642,14545,14394,14268,15257,14242,13310,29904,15254,
+26511,17962,26806,26654,15300,27326,14435,14293,17543,27187,27218,27337,27397,
+6418,25873,26776,27212,15319,27258,27479,16320,15514,37792,37618,35818,35531,
+37513,32798,35292,37991,28069,28427,18924,U,16255,15759,28164,16444,23101,
+28170,22599,27940,30786,28987,17178,17014,28913,29264,29319,29332,18319,18213,
+20857,19108,1515,29818,16120,13919,19018,18711,24545,16134,16049,19167,35875,
+16181,24743,16115,29900,29756,37767,29751,17567,28138,17745,30083,16227,19673,
+19718,16216,30037,30323,42438,15129,29800,35532,18859,18830,15099,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,15821,19022,16127,
+18885,18675,37370,22322,37698,35555,6244,20703,21025,20967,30584,12850,30478,
+30479,30587,18071,14209,14942,18672,29752,29851,16063,19130,19143,16584,19094,
+25006,37639,21889,30750,30861,30856,30930,29648,31065,30529,22243,16654,U,
+33942,31141,27181,16122,31290,31220,16750,5862,16690,37429,31217,3404,18828,
+665,15802,5998,13719,21867,13680,13994,468,3085,31458,23129,9973,23215,23196,
+23053,603,30960,23082,23494,31486,16889,31837,31853,16913,23475,24252,24230,
+31949,18937,6064,31886,31868,31918,27314,32220,32263,32211,32590,25185,24924,
+31560,32151,24194,17002,27509,2326,26582,78,13775,22468,25618,25592,18786,
+32733,31527,2092,23273,23875,31500,24078,39398,34373,39523,27164,13375,14818,
+18935,26029,39455,26016,33920,28967,27857,17642,33079,17410,32966,33033,33090,
+26548,39107,27202,33378,33381,27217,33875,28071,34320,29211,23174,16767,6208,
+23339,6305,23268,6360,34464,63932,15759,34861,29730,23042,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,34926,20293,34951,35007,35046,
+35173,35149,22147,35156,30597,30596,35829,35801,35740,35321,16045,33955,18165,
+18127,14322,35389,35356,37960,24397,37419,17028,26068,28969,28868,6213,40301,
+35999,36073,32220,22938,30659,23024,17262,14036,36394,36519,19465,36656,36682,
+17140,27736,28603,8993,18587,28537,28299,6106,39913,14005,18735,37051,U,21873,
+18694,37307,37892,35403,16482,35580,37927,35869,35899,34021,35371,38297,38311,
+38295,38294,36148,29765,16066,18687,19010,17386,16103,12837,38543,36583,36454,
+36453,16076,18925,19064,16366,29714,29803,16124,38721,37040,26695,18973,37011,
+22495,U,37736,35209,35878,35631,25534,37562,23313,35689,18748,29689,16923,
+38811,38769,39224,3878,24001,35781,19122,38943,38106,37622,38359,37349,17600,
+35664,19047,35684,39132,35397,16128,37418,18725,33812,39227,39245,31494,15869,
+39323,19311,39338,39516,35685,22728,27279,39457,23294,39471,39153,19344,39240,
+39356,19389,19351,37757,22642,4866,22562,18872,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,5352,30788,10015,15800,26821,15741,
+37976,14631,24912,10113,10603,24839,40015,40019,40059,39989,39952,39807,39887,
+40493,39839,41461,41214,40225,19630,16644,40472,19632,40204,41396,41197,41203,
+39215,40357,33981,28178,28639,27522,34300,17715,28068,28292,28144,33824,34286,
+28160,14295,24676,31202,13724,13888,18733,18910,15714,37851,37566,37704,703,
+30905,37495,37965,20452,13376,36964,21853,30781,30804,30902,30795,5975,12745,
+18753,13978,20338,28634,28633,U,28702,21524,16821,22459,22771,22410,40214,
+22487,28980,13487,16812,29163,27712,20375,U,6069,35401,24844,23246,23051,
+17084,17544,14124,19323,35324,37819,37816,6358,3869,33906,27840,5139,17146,
+11302,17345,22932,15799,26433,32168,24923,24740,18873,18827,35322,37605,29666,
+16105,29876,35683,6303,16097,19123,27352,29683,29691,16086,19006,19092,6105,
+19046,935,5156,18917,29768,18710,28837,18806,37508,29670,37727,1278,37681,
+35534,35350,37766,35815,21973,18741,35458,29035,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,18755,3327,22180,1562,3051,3256,21762,
+31172,6138,32254,5826,19024,6226,17710,37889,14090,35520,18861,22960,6335,
+6275,29828,23201,14050,15707,14000,37471,23161,35457,6242,37748,15565,2740,
+19094,14730,20724,15721,15692,5020,29045,17147,33304,28175,37092,17643,27991,
+32335,28775,27823,15574,16365,15917,28162,28428,15727,1013,30033,14012,13512,
+18048,16090,18545,22980,37486,18750,36673,35868,27584,22546,22472,14038,5202,
+28926,17250,19057,12259,4784,9149,26809,26983,5016,13541,31732,14047,35459,
+14294,13306,19615,27162,13997,27831,33854,17631,17614,27942,27985,27778,28638,
+28439,28937,33597,5946,33773,27776,28755,6107,22921,23170,6067,23137,23153,
+6405,16892,14125,23023,5948,14023,29070,37776,26266,17061,23150,23083,17043,
+27179,16121,30518,17499,17098,28957,16985,35297,20400,27944,23746,17614,32333,
+17341,27148,16982,4868,28838,28979,17385,15781,27871,63525,19023,32357,23019,
+23855,15859,24412,19037,6111,32164,33830,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,21637,15098,13056,532,22398,2261,1561,16357,
+8094,41654,28675,37211,23920,29583,31955,35417,37920,20424,32743,29389,29456,
+31476,29496,29497,22262,29505,29512,16041,31512,36972,29173,18674,29665,33270,
+16074,30476,16081,27810,22269,29721,29726,29727,16098,16112,16116,16122,29907,
+16142,16211,30018,30061,30066,30093,16252,30152,30172,16320,30285,16343,30324,
+16348,30330,20316,29064,22051,35200,22633,16413,30531,16441,26465,16453,13787,
+30616,16490,16495,23646,30654,30667,22770,30744,28857,30748,16552,30777,30791,
+30801,30822,33864,21813,31027,26627,31026,16643,16649,31121,31129,36795,31238,
+36796,16743,31377,16818,31420,33401,16836,31439,31451,16847,20001,31586,31596,
+31611,31762,31771,16992,17018,31867,31900,17036,31928,17044,31981,36755,28864,
+3279,32207,32212,32208,32253,32686,32692,29343,17303,32800,32805,31545,32814,
+32817,32852,15820,22452,28832,32951,33001,17389,33036,29482,33038,33042,30048,
+33044,17409,15161,33110,33113,33114,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,17427,22586,33148,33156,17445,33171,17453,33189,
+22511,33217,33252,33364,17551,33446,33398,33482,33496,33535,17584,33623,38505,
+27018,33797,28917,33892,24803,33928,17668,33982,34017,34040,34064,34104,34130,
+17723,34159,34160,34272,17783,34418,34450,34482,34543,38469,34699,17926,17943,
+34990,35071,35108,35143,35217,31079,35369,35384,35476,35508,35921,36052,36082,
+36124,18328,22623,36291,18413,20206,36410,21976,22356,36465,22005,36528,18487,
+36558,36578,36580,36589,36594,36791,36801,36810,36812,36915,39364,18605,39136,
+37395,18718,37416,37464,37483,37553,37550,37567,37603,37611,37619,37620,37629,
+37699,37764,37805,18757,18769,40639,37911,21249,37917,37933,37950,18794,37972,
+38009,38189,38306,18855,38388,38451,18917,26528,18980,38720,18997,38834,38850,
+22100,19172,24808,39097,19225,39153,22596,39182,39193,20916,39196,39223,39234,
+39261,39266,19312,39365,19357,39484,39695,31363,39785,39809,39901,39921,39924,
+19565,39968,14191,7106,40265,39994,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,40702,22096,40339,40381,40384,40444,38134,36790,
+40571,40620,40625,40637,40646,38108,40674,40689,40696,31432,40772,148,695,928,
+26906,38083,22956,1239,22592,38081,14265,1493,1557,1654,5818,22359,29043,2754,
+2765,3007,21610,63547,3019,21662,3067,3131,3155,3173,3196,24807,3213,22138,
+3253,3293,3309,3439,3506,3528,26965,39983,34725,3588,3598,3799,3984,3885,3699,
+23584,4028,24075,4188,4175,4214,26398,4219,4232,4246,13895,4287,4307,4399,
+4411,21348,33965,4835,4981,4918,35713,5495,5657,6083,6087,20088,28859,6189,
+6506,6701,6725,7210,7280,7340,7880,25283,7893,7957,29080,26709,8261,27113,
+14024,8828,9175,9210,10026,10353,10575,33533,10599,10643,10965,35237,10984,
+36768,11022,38840,11071,38983,39613,11340,U,11400,11447,23528,11528,11538,
+11703,11669,11842,12148,12236,12339,12390,13087,13278,24497,26184,26303,31353,
+13671,13811,U,18874,U,13850,14102,U,838,22709,26382,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,26904,15015,30295,24546,15889,16057,
+30206,8346,18640,19128,16665,35482,17134,17165,16443,17204,17302,19013,1482,
+20946,1553,22943,7848,15294,15615,17412,17622,22408,18036,14747,18223,34280,
+39369,14178,8643,35678,35662,U,18450,18683,18965,29193,19136,3192,22885,20133,
+20358,1913,36570,20524,21135,22335,29041,21145,21529,16202,19111,21948,21574,
+21614,27474,U,13427,21823,30258,21854,18200,21858,21862,22471,18751,22621,
+20582,13563,13260,U,22787,18300,35144,23214,23433,23558,7568,22433,29009,U,
+24834,31762,36950,25010,20378,35682,25602,25674,23899,27639,U,25732,6428,
+35562,18934,25736,16367,25874,19392,26047,26293,10011,37989,22497,24981,23079,
+63693,U,22201,17697,26364,20074,18740,38486,28047,27837,13848,35191,26521,
+26734,25617,26718,U,26823,31554,37056,2577,26918,U,26937,31301,U,27130,39462,
+27181,13919,25705,33,31107,27188,27483,23852,13593,U,27549,18128,27812,30011,
+34917,28078,22710,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+U,U,U,U,14108,9613,28747,29133,15444,29312,29317,37505,8570,29323,37680,29414,
+18896,27705,38047,29776,3832,34855,35061,10534,33907,6065,28344,18986,6176,
+14756,14009,U,U,17727,26294,40109,39076,35139,30668,30808,22230,16607,5642,
+14753,14127,33000,5061,29101,33638,31197,37288,U,19639,28847,35243,31229,
+31242,31499,32102,16762,31555,31102,32777,28597,41695,27139,33560,21410,28167,
+37823,26678,38749,33135,32803,27061,5101,12847,32840,23941,35888,32899,22293,
+38947,35145,23979,18824,26046,27093,21458,19109,16257,15377,26422,32912,33012,
+33070,8097,33103,33161,33199,33306,33542,33583,33674,13770,33896,34474,18682,
+25574,35158,30728,37461,35256,17394,35303,17375,35304,35654,35796,23032,35849,
+U,36805,37100,U,37136,37180,15863,37214,19146,36816,29327,22155,38119,38377,
 38320,38328,38706,39121,39241,39274,39363,39464,39694,40282,40347,32415,40696,
 40739,19620,38215,41619,29090,41727,19857,36882,42443,19868,3228,36798,21953,
 U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,36794,
@@ -277,7 +286,7 @@
 19972,13687,23309,27826,21351,13996,14812,21373,13989,17944,22682,19310,33325,
 21579,22442,23189,2425,U,14930,9317,29556,40620,19721,39917,15614,40752,19547,
 20393,38302,40926,33884,15798,29362,26547,14112,25390,32037,16119,15916,14890,
-36872,21196,15988,13946,17897,1166,30272,23280,3766,30842,18358,22695,16575,
+36872,21196,15988,13946,17897,1166,30272,23280,3766,30842,32558,22695,16575,
 22140,39819,23924,30292,42036,40581,19681,U,14331,24857,12506,17394,U,22109,
 4777,22439,18787,40454,21044,28846,13741,U,40316,31830,39737,22494,5996,23635,
 25811,38096,25397,29028,34477,3368,27938,19170,3441,U,20990,7951,23950,38659,
@@ -327,9 +336,9 @@
 1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,
 1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1105,1078,1079,1080,1081,
 1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,
-1097,1098,1099,1100,1101,1102,1103,8679,8632,8633,63461,204,20058,138,20994,
-63466,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
-63467,20872,63469,30215,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+1097,1098,1099,1100,1101,1102,1103,8679,8632,8633,12751,204,20058,138,20994,
+17553,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
+40880,20872,40881,30215,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,U,
 U,U,U,U,U,U,U,U,U,U,U,U,U,65506,65508,65287,65282,12849,8470,8481,12443,12444,
 11904,11908,11910,11911,11912,11914,11916,11917,11925,11932,11933,11941,11943,
 11946,11948,11950,11958,11964,11966,11974,11978,11980,11981,11983,11990,11991,
@@ -417,67 +426,68 @@
 },{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,
 0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{
 0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0
-},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,
-0,0},{__big5hkscs_decmap+0,64,170},{__big5hkscs_decmap+107,64,254},{
-__big5hkscs_decmap+298,64,254},{__big5hkscs_decmap+489,64,253},{
-__big5hkscs_decmap+679,64,220},{__big5hkscs_decmap+836,96,254},{
-__big5hkscs_decmap+995,64,254},{__big5hkscs_decmap+1186,64,253},{
-__big5hkscs_decmap+1376,64,254},{__big5hkscs_decmap+1567,64,254},{
-__big5hkscs_decmap+1758,64,254},{__big5hkscs_decmap+1949,64,254},{
-__big5hkscs_decmap+2140,64,254},{__big5hkscs_decmap+2331,64,254},{
-__big5hkscs_decmap+2522,64,254},{__big5hkscs_decmap+2713,64,254},{
-__big5hkscs_decmap+2904,64,254},{__big5hkscs_decmap+3095,64,254},{
-__big5hkscs_decmap+3286,64,254},{__big5hkscs_decmap+3477,64,254},{
-__big5hkscs_decmap+3668,64,254},{__big5hkscs_decmap+3859,64,254},{
-__big5hkscs_decmap+4050,64,254},{__big5hkscs_decmap+4241,64,254},{
-__big5hkscs_decmap+4432,64,254},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0
-},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,
+},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{
+__big5hkscs_decmap+0,64,121},{__big5hkscs_decmap+58,64,170},{
+__big5hkscs_decmap+165,64,254},{__big5hkscs_decmap+356,64,254},{
+__big5hkscs_decmap+547,64,253},{__big5hkscs_decmap+737,64,254},{
+__big5hkscs_decmap+928,64,254},{__big5hkscs_decmap+1119,64,254},{
+__big5hkscs_decmap+1310,64,253},{__big5hkscs_decmap+1500,64,254},{
+__big5hkscs_decmap+1691,64,254},{__big5hkscs_decmap+1882,64,254},{
+__big5hkscs_decmap+2073,64,254},{__big5hkscs_decmap+2264,64,254},{
+__big5hkscs_decmap+2455,64,254},{__big5hkscs_decmap+2646,64,254},{
+__big5hkscs_decmap+2837,64,254},{__big5hkscs_decmap+3028,64,254},{
+__big5hkscs_decmap+3219,64,254},{__big5hkscs_decmap+3410,64,254},{
+__big5hkscs_decmap+3601,64,254},{__big5hkscs_decmap+3792,64,254},{
+__big5hkscs_decmap+3983,64,254},{__big5hkscs_decmap+4174,64,254},{
+__big5hkscs_decmap+4365,64,254},{__big5hkscs_decmap+4556,64,254},{0,0,0},{0,0,
+0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,
 0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{
 0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0
-},{0,0,0},{0,0,0},{__big5hkscs_decmap+4623,161,254},{__big5hkscs_decmap+4717,
-64,254},{__big5hkscs_decmap+4908,64,254},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,
-0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,
+},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{__big5hkscs_decmap+4747,
+161,254},{__big5hkscs_decmap+4841,64,254},{__big5hkscs_decmap+5032,64,254},{0,
 0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{
 0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0
 },{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,
-0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{__big5hkscs_decmap+5099,214,254},{
-__big5hkscs_decmap+5140,64,254},{__big5hkscs_decmap+5331,64,254},{
-__big5hkscs_decmap+5522,64,254},{__big5hkscs_decmap+5713,64,254},{
-__big5hkscs_decmap+5904,64,254},{0,0,0},
+0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{
+0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{
+__big5hkscs_decmap+5223,214,254},{__big5hkscs_decmap+5264,64,254},{
+__big5hkscs_decmap+5455,64,254},{__big5hkscs_decmap+5646,64,254},{
+__big5hkscs_decmap+5837,64,254},{__big5hkscs_decmap+6028,64,254},{0,0,0},
 };
 
 static const unsigned char big5hkscs_phint_0[] = {
-160,89,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,1,8,0,0,0,0,0,0,0,0,0,0,
-0,0,2,44,0,30,0,0,0,0,0,64,174,86,238,249,221,228,33,23,0,0,0,128,219,73,31,
-76,130,55,237,228,223,189,247,245,239,31,100,136,94,253,223,11,0,0,0,192,247,
-143,0,131,5,0,8,201,8,4,129,64,68,5,11,9,35,1,32,2,0,0,0,32,145,24,0,96,0,168,
-6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,128,0,64,86,50,65,32,198,
-80,72,2,0,0,0,0,160,192,168,1,164,85,48,58,209,106,46,159,176,241,65,136,5,57,
-80,4,0,0,0,0,172,163,20,192,1,2,13,45,134,136,107,34,110,192,204,245,218,10,
-24,122,0,0,0,0,50,115,0,15,68,252,3,33,49,32,25,232,96,160,65,19,82,42,250,9,
-0,0,0,0,190,1,129,16,16,96,183,137,193,218,237,250,242,59,200,167,11,77,155,
-11,0,0,0,0,24,0,220,116,19,94,192,168,0,60,240,208,68,224,172,60,75,230,29,15,
-0,0,0,128,189,88,120,55,191,187,216,218,8,134,192,108,148,192,176,125,14,136,
-145,3,0,0,0,64,99,139,197,22,24,68,124,152,75,112,3,92,219,185,208,26,40,149,
-106,1,0,0,0,0,232,7,36,34,32,136,4,106,32,215,29,50,15,162,149,11,4,67,65,1,0,
-0,0,104,48,64,19,207,57,183,16,8,7,4,180,33,217,183,15,11,127,69,91,0,0,0,0,
-236,116,236,196,4,41,49,2,48,250,252,27,175,78,38,164,183,110,50,24,0,0,0,0,
-220,22,67,34,1,0,0,128,0,0,0,4,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,
-0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,28,241,220,190,126,252,186,123,238,249,55,249,
-93,165,255,31,215,2,0,0,0,128,63,255,213,117,117,187,120,231,62,245,177,173,
-189,75,150,188,46,181,85,2,0,0,0,192,109,51,55,176,233,204,159,42,126,83,204,
-255,77,234,218,198,255,55,165,0,0,0,0,160,192,252,222,50,83,161,28,0,0,33,176,
-71,0,74,32,32,233,215,235,0,0,0,0,160,183,1,64,49,101,247,12,36,64,48,45,144,
-123,18,0,0,2,0,0,0,0,0,0,0,8,80,144,69,0,4,0,0,32,64,4,161,128,96,2,0,32,0,8,
-0,0,0,0,148,8,2,32,40,0,0,1,8,254,251,73,
+32,5,95,68,15,82,130,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,208,44,4,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,4,0,0,0,0,0,0,0,0,0,0,0,0,1,22,0,15,0,0,0,0,0,
+32,87,43,247,252,110,242,144,11,0,0,0,192,237,164,15,38,193,155,118,242,239,
+222,251,250,247,15,50,68,175,254,239,5,0,0,0,224,251,71,128,193,2,0,132,100,4,
+130,64,32,162,130,133,164,145,0,16,1,0,0,0,144,72,12,0,48,0,84,3,48,68,24,19,
+53,137,38,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,64,0,32,43,153,32,16,99,40,36,
+1,0,0,0,0,80,96,212,0,210,42,24,157,104,53,151,79,216,248,32,196,130,28,40,2,
+0,0,0,0,214,81,10,224,0,129,134,22,67,196,53,17,55,96,230,122,109,5,12,61,0,0,
+0,0,153,57,128,7,34,254,129,144,24,144,12,116,48,208,160,9,41,21,253,4,0,0,0,
+0,223,128,64,8,8,176,219,196,96,237,118,125,249,29,228,211,133,166,205,5,0,0,
+0,0,12,0,110,186,9,47,96,84,0,30,120,104,34,112,86,158,37,243,142,7,0,0,0,192,
+94,44,188,155,223,93,108,109,4,67,96,54,74,96,216,62,7,196,200,1,0,0,0,160,
+177,197,98,11,12,34,62,204,37,184,1,174,237,92,104,13,148,74,181,0,0,0,0,0,
+244,3,18,17,16,68,2,53,144,235,14,153,7,209,202,5,130,161,160,0,0,0,0,52,24,
+160,137,231,156,91,8,132,3,2,218,144,236,219,135,133,191,162,45,0,0,0,0,118,
+58,118,98,130,148,24,1,24,125,254,141,87,39,19,210,91,55,25,12,0,0,0,0,110,
+139,33,145,0,0,0,64,0,0,0,2,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,
+0,0,0,0,0,0,0,2,0,0,0,0,0,0,142,120,110,95,63,126,221,61,247,252,155,252,174,
+210,255,143,107,1,0,0,0,192,159,255,234,186,186,93,188,115,159,250,216,214,
+222,37,75,94,151,218,42,1,0,0,0,224,182,153,27,216,116,230,79,21,191,41,230,
+255,38,117,109,227,255,155,82,0,0,0,0,80,96,126,111,153,169,80,14,0,128,16,
+216,35,0,37,16,144,244,235,117,0,0,0,0,208,219,0,160,152,178,123,6,82,32,152,
+22,200,61,9,0,0,1,0,0,0,0,0,0,0,4,40,200,34,0,2,0,0,16,32,130,80,64,48,1,0,16,
+0,4,0,0,0,0,74,4,1,16,20,0,128,0,4,255,253,36,
 };
 
-static const unsigned char big5hkscs_phint_11939[] = {
+static const unsigned char big5hkscs_phint_12130[] = {
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 0,0,0,128,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,
 };
 
-static const unsigned char big5hkscs_phint_21733[] = {
+static const unsigned char big5hkscs_phint_21924[] = {
 0,0,0,0,0,26,172,248,250,90,192,250,51,0,0,0,0,0,129,0,160,156,130,144,9,1,
 180,192,176,3,86,2,160,66,45,136,1,0,0,0,0,146,119,139,96,5,201,33,6,70,56,96,
 72,192,180,36,222,132,224,192,36,0,0,0,0,205,80,197,52,192,40,162,173,124,153,
@@ -485,33 +495,33 @@
 5,72,8,22,230,28,165,0,8,0,0,0,192,45,22,20,128,24,58,212,25,136,28,138,4,
 };
 
-static const DBCHAR __big5hkscs_bmp_encmap[26537] = {
+static const DBCHAR __big5hkscs_bmp_encmap[26401] = {
 50904,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34905,34903,N,N,N,N,N,N,
-34909,34907,34918,N,N,N,N,N,N,N,34913,34911,N,N,N,N,N,N,N,N,N,N,N,N,34922,
-34920,N,N,N,N,N,N,34927,34925,34983,N,34931,34929,N,N,N,N,34935,34933,N,N,N,N,
-51451,34939,34937,N,34978,34902,34919,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34906,
-34924,N,N,N,N,N,N,34908,34926,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34928,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,51452,34910,34932,N,N,N,N,N,
-51450,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34936,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,34904,34921,N,34930,34912,34934,N,34938,N,34940,N,34941,N,
-34942,N,34977,51446,34923,N,N,51448,N,N,N,N,N,N,51447,N,N,N,N,N,34984,N,N,N,N,
-N,N,N,N,51454,N,N,N,N,N,N,N,N,N,N,51449,N,N,N,N,N,N,N,N,N,N,N,N,N,51445,N,N,N,
-N,N,N,51453,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,50905,51193,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,51187,51188,51189,51190,51191,51192,51194,51195,51196,51197,
-51198,51264,51265,51266,51267,51268,51269,51270,51271,51272,51273,51274,51275,
-51276,51277,51278,51279,51280,51281,51282,51283,51284,51285,51286,51287,51288,
-51289,51290,51292,51293,51294,51295,51296,51297,51298,51299,51300,51301,51302,
-51303,51304,51305,51306,51307,51308,51309,51310,51311,51312,51313,51314,51315,
-51316,51317,N,51291,34915,34980,34917,34982,51410,N,N,N,N,N,N,N,N,N,N,51411,N,
+34909,34907,M,N,N,N,N,N,N,N,34913,34911,N,N,N,N,N,N,N,N,N,N,N,N,34922,34920,N,
+N,N,N,N,N,34927,34925,M,N,34931,34929,N,N,N,N,34935,34933,N,N,N,N,51451,34939,
+34937,N,34978,34902,34919,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34906,34924,N,N,N,N,
+N,N,34908,34926,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34928,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,51452,34910,34932,N,N,N,N,N,51450,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34936,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,34904,34921,N,34930,34912,34934,N,34938,N,34940,N,34941,N,34942,N,34977,
+51446,34923,N,N,51448,N,N,N,N,N,N,51447,N,N,N,N,N,34984,N,N,N,N,N,N,N,N,51454,
+N,N,N,N,N,N,N,N,N,N,51449,N,N,N,N,N,N,N,N,N,N,N,N,N,51445,N,N,N,N,N,N,51453,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,50905,51193,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+51187,51188,51189,51190,51191,51192,51194,51195,51196,51197,51198,51264,51265,
+51266,51267,51268,51269,51270,51271,51272,51273,51274,51275,51276,51277,51278,
+51279,51280,51281,51282,51283,51284,51285,51286,51287,51288,51289,51290,51292,
+51293,51294,51295,51296,51297,51298,51299,51300,51301,51302,51303,51304,51305,
+51306,51307,51308,51309,51310,51311,51312,51313,51314,51315,51316,51317,N,
+51291,34915,34980,34917,34982,51410,N,N,N,N,N,N,N,N,N,N,51411,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-50869,50870,50871,50872,50873,50874,50875,50876,50877,50878,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,50869,50870,
+50871,50872,50873,50874,50875,50876,50877,50878,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,51319,51320,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,51318,50849,50850,50851,
+N,N,N,N,N,N,N,N,51319,51320,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,51318,34985,34986,50849,50850,50851,
 50852,50853,50854,50855,50856,50857,50858,N,N,N,N,N,N,N,N,N,N,50859,50860,
 50861,50862,50863,50864,50865,50866,50867,50868,63993,63992,63974,63983,63965,
 63976,63985,63967,63980,63989,63971,63982,63991,63973,63977,63986,63968,63979,
@@ -536,231 +546,235 @@
 51153,51154,51155,51156,51157,51158,51159,51160,51161,51162,51163,51164,51165,
 51166,51167,51168,51169,51170,51171,51172,51173,51174,51175,51176,51177,51178,
 51179,51180,51181,51182,51183,51184,51185,51186,N,N,N,N,N,50915,50906,50907,
-51409,37495,N,N,N,N,N,N,N,N,N,N,38623,N,N,N,N,N,N,N,N,N,N,N,35285,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37837,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39903,N,N,
-N,N,N,N,64104,N,N,35290,36697,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35291,N,
-N,36701,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35292,N,N,N,N,N,N,N,N,N,38647,N,N,N,N,N,N,
-N,N,N,N,N,N,35546,N,N,N,N,35804,N,N,N,N,N,N,38875,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,40531,N,N,N,N,40362,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,39914,35438,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35784,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,35304,N,35306,N,N,N,N,N,35915,N,N,N,N,N,N,N,64368,N,N,N,N,N,N,N,N,N,
-N,N,35309,N,N,38109,N,35310,N,N,N,N,40628,35539,N,N,N,N,N,N,N,N,N,N,N,37595,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38107,35321,N,N,N,N,N,N,N,N,64378,N,N,N,
-35323,N,N,N,N,N,N,N,40700,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35324,N,35263,N,N,
-N,35326,N,35302,N,N,40262,N,N,N,40430,N,N,N,41086,N,N,N,41064,N,N,N,N,39145,N,
-35688,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36349,35774,40921,N,N,N,N,N,N,N,
-35563,N,N,40919,35690,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40028,N,35761,N,N,N,N,N,N,N,
-N,64350,N,N,N,N,N,N,N,N,N,40435,N,N,N,N,N,N,N,41168,N,N,N,64614,N,N,N,N,37609,
-N,N,N,N,N,N,N,N,39660,36779,64072,N,N,N,N,36421,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,40047,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40670,N,N,N,N,N,N,
-35311,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38633,N,N,N,N,N,N,N,N,N,
-N,40635,N,N,N,N,38110,N,40632,N,N,N,38842,64357,N,N,N,38358,N,N,N,40123,N,N,
-38874,N,N,N,N,36677,N,64381,37208,65124,N,38998,39757,N,N,N,N,N,N,N,N,N,N,
-37723,38343,N,38887,N,N,N,N,N,N,37721,N,N,N,37365,38840,N,N,64930,64438,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,37626,37719,N,35750,N,N,N,N,64441,N,38832,N,N,64964,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,40097,N,N,N,N,N,37362,37369,N,36849,N,N,N,N,N,N,38725,
-38995,N,N,65144,N,64449,37457,N,N,N,N,N,N,40365,N,N,N,N,N,64876,N,N,64107,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39874,N,N,N,N,N,N,N,N,
-N,N,N,N,39547,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,35680,N,N,N,N,N,N,N,N,37707,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,39613,N,N,N,N,37303,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38324,N,N,N,N,N,65221,
-N,N,40688,36196,N,N,N,N,N,N,N,N,N,37481,N,N,N,N,N,N,36199,N,N,N,N,N,N,N,N,N,N,
-N,N,64490,N,N,N,N,N,N,N,N,64495,N,36200,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37867,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,64578,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,37222,N,N,N,N,N,N,N,N,64205,N,N,N,N,37853,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35788,36205,N,N,N,N,N,
-N,N,N,N,N,N,36206,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38568,N,N,N,N,N,N,N,N,N,
-N,64678,N,N,N,N,N,N,N,N,N,N,N,N,36207,N,N,N,N,N,N,N,N,N,N,N,N,N,36208,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64612,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,36960,N,N,N,N,N,N,N,N,36212,38851,N,N,N,N,N,N,N,35536,N,N,N,
-N,N,N,37492,N,39870,N,N,N,N,N,40136,N,N,40122,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,36216,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,40633,N,N,N,N,N,38234,N,N,37300,N,N,N,N,N,N,35400,N,N,N,N,N,N,N,N,N,N,N,
-36221,N,N,35453,N,N,35522,64842,N,36257,N,N,35537,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,64692,35655,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37796,40666,N,N,N,N,N,N,N,N,N,
-35409,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36262,N,N,N,N,N,N,40645,N,N,
-N,N,64708,N,N,N,N,41080,N,38069,N,N,N,N,N,N,N,64706,35435,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-36267,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64232,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,36269,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64585,N,37825,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36975,N,36272,N,N,N,N,N,N,N,N,
-38014,37114,N,N,N,N,N,N,N,N,N,N,38009,N,N,N,N,N,N,N,N,36274,N,N,N,N,N,N,N,N,
-64750,N,N,N,N,N,N,N,N,N,N,N,N,N,39291,N,N,N,N,N,N,N,N,36276,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,36279,N,N,N,N,N,N,N,37299,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,36283,36282,N,N,N,N,N,N,N,N,36284,36932,N,N,N,64844,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,37860,N,N,37856,N,N,N,N,N,N,N,64851,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36291,N,39864,N,N,N,64496,N,37865,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,37878,N,N,N,N,N,36293,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36298,
-N,N,N,N,N,36300,64861,37813,64865,N,N,N,40184,N,N,N,37458,N,N,41192,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40101,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35926,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36310,N,38848,N,N,N,41182,N,N,N,N,
-38866,N,N,N,N,N,64165,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64931,N,N,N,36315,36527,N,N,
-N,N,N,N,N,N,N,37301,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64841,N,N,N,N,N,N,
-N,N,64977,N,N,N,N,N,N,N,N,N,N,36331,N,N,N,N,N,38854,N,64974,N,N,37116,N,N,N,N,
-N,N,N,N,N,N,N,N,N,64601,N,N,38614,N,N,N,N,N,N,38853,36335,N,N,N,N,38871,N,N,N,
-N,N,36336,N,N,N,N,N,N,N,38566,N,N,N,N,N,N,N,64447,N,N,N,N,36339,N,N,N,N,37961,
-N,36341,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39026,N,N,N,N,N,N,N,36459,N,N,N,
-N,N,N,64253,N,N,N,N,N,N,N,N,N,N,36688,N,N,N,N,N,N,40396,64613,N,35908,N,N,
-39278,38049,N,N,N,N,N,36707,N,N,N,N,N,N,N,41178,N,N,N,N,N,N,N,N,N,N,N,37459,
-65001,N,N,40373,N,N,N,N,N,N,N,39033,N,N,N,40285,N,N,N,N,36195,38505,40816,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64618,N,N,35527,N,N,N,N,35287,N,N,N,N,N,N,N,N,
-N,N,N,N,65101,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-40669,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65275,39100,64204,N,N,38320,N,N,N,37988,N,N,N,N,
-N,N,37743,N,N,N,N,N,N,38073,N,N,38380,N,N,N,N,37358,N,N,39107,N,38390,N,N,N,
-36861,39109,N,N,N,N,38758,65134,N,N,38877,36010,N,N,37586,N,N,38753,39115,N,N,
-N,N,38384,N,38749,N,37347,N,N,N,N,39116,N,N,37993,39117,N,N,N,N,N,39118,N,
-38396,N,N,38051,38498,N,N,N,65206,N,37987,N,N,N,N,N,N,N,39120,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39121,N,N,N,N,38005,64224,N,N,N,N,N,
-N,N,N,N,38002,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39126,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35568,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39129,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,39131,N,N,N,N,39133,N,N,N,N,N,N,N,N,39080,N,N,N,N,N,N,N,
-35437,N,N,N,N,N,N,N,N,N,N,N,35579,35502,64457,N,N,N,N,35933,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,39140,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,39142,N,N,N,N,N,N,N,N,N,N,N,39144,N,N,N,N,N,N,N,N,N,N,N,N,N,35405,N,N,N,
-37463,N,N,N,N,N,N,N,N,N,N,38367,N,N,41132,N,N,N,N,39147,N,N,N,N,39148,N,36035,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39156,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35512,
-N,N,N,40679,N,N,N,N,N,N,N,N,38076,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64721,N,N,N,N,
-N,N,40134,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40574,39166,
-65000,N,N,N,N,39232,N,N,N,N,38089,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,38099,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39238,N,N,N,N,37056,
-N,38097,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38259,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-37826,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39240,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39243,N,N,N,N,N,36437,N,N,N,N,39246,N,N,N,N,
-N,N,N,N,N,N,N,36606,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36441,N,N,N,N,N,N,N,
-N,N,38124,38127,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35936,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36724,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,39253,N,N,N,N,N,N,N,N,N,38212,N,N,N,N,N,N,N,N,N,N,N,
-36043,N,N,N,39254,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39257,N,N,N,N,N,N,N,39259,
-N,N,N,N,N,N,N,N,N,N,N,N,N,36036,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64069,N,N,
-N,37047,N,N,38723,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38349,N,N,N,N,N,N,38857,
-64848,36537,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38342,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-39271,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-35513,N,N,N,N,N,N,36348,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35446,N,
-N,N,N,N,40273,N,N,N,N,N,N,N,N,N,N,N,N,N,39283,N,N,N,N,40271,39290,38244,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,39329,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39333,N,N,N,
-N,N,N,N,39335,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+34880,34881,34882,34883,34884,34886,34889,34890,34893,34895,34896,34897,34898,
+34900,34901,51321,51409,37495,N,N,N,N,N,N,N,N,N,N,38623,N,N,N,N,N,N,N,N,N,
+36084,N,35285,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37837,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,39903,N,N,N,N,N,N,64104,N,N,35290,36697,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,35291,N,N,36701,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35292,N,N,N,N,N,
+N,N,N,N,38647,N,N,N,N,N,N,N,N,N,N,N,N,35546,N,N,N,N,35804,N,N,N,N,N,N,38875,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40531,N,N,N,N,40362,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,39914,35438,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35784,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35304,N,35306,N,N,N,N,N,35915,N,N,N,N,N,N,
+N,64368,N,N,N,N,N,N,N,N,N,N,N,35309,N,N,38109,N,35310,N,N,N,N,40628,35539,N,N,
+N,N,N,N,N,N,N,N,N,37595,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38107,35321,N,N,N,
+N,N,N,N,N,64378,N,N,N,35323,N,N,N,N,N,N,N,40700,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,35324,N,35263,N,N,N,35326,N,35302,N,N,40262,N,N,N,40430,N,N,N,41086,N,N,N,
+41064,N,N,N,N,39145,N,35688,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36349,35774,
+40921,N,N,N,N,N,N,N,35563,N,N,40919,35690,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40028,N,
+35761,N,N,N,N,N,N,N,N,64350,N,34672,N,N,N,N,N,N,N,40435,N,N,N,N,N,N,N,41168,N,
+N,N,64614,N,N,N,N,37609,N,N,N,N,N,N,N,N,39660,36779,64072,N,N,N,N,36421,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,40047,N,36188,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,40670,N,N,N,N,N,N,35311,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,38633,N,N,N,N,N,N,N,N,N,N,40635,N,N,N,N,38110,N,40632,N,N,N,38842,64357,N,
+N,N,38358,N,N,N,40123,N,N,38874,N,N,N,N,36677,N,64381,37208,65124,N,38998,
+39757,N,N,N,N,N,N,N,N,N,N,37723,38343,N,38887,N,N,N,N,N,N,37721,N,N,N,37365,
+38840,N,N,64930,64438,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37626,37719,N,35750,N,N,N,N,
+64441,N,38832,N,N,64964,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40097,N,N,N,N,N,37362,
+37369,N,36849,N,N,N,N,N,N,38725,38995,N,N,65144,N,64449,37457,N,N,N,N,N,N,
+40365,N,N,N,N,N,64876,N,N,64107,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,39874,N,N,N,N,N,N,N,N,N,N,N,N,39547,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35680,N,N,N,N,N,N,N,N,37707,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39613,N,N,N,N,37303,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36171,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,38324,N,N,N,N,N,65221,N,N,40688,36196,N,N,N,N,N,N,N,N,N,
+37481,N,N,N,N,N,N,36199,N,N,N,N,N,N,N,N,N,N,N,N,64490,N,N,N,N,N,N,N,N,64495,N,
+36200,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,37867,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64578,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37222,N,N,N,N,N,N,N,N,
+64205,N,N,N,N,37853,N,N,36178,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,35788,36205,N,N,N,N,N,N,N,N,N,N,N,36206,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,38568,N,N,N,N,N,N,N,N,N,N,64678,N,N,N,N,N,N,N,N,N,N,N,
+N,36207,N,N,N,N,N,N,N,N,N,N,N,N,N,36208,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,64612,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36083,N,N,N,N,N,N,N,36960,N,
+N,N,N,N,N,N,N,36212,38851,N,N,N,N,N,N,N,35536,N,N,N,N,N,N,37492,N,39870,N,N,N,
+N,N,40136,N,N,40122,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36216,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40633,N,N,N,N,N,38234,
+N,N,37300,N,N,N,N,N,N,35400,N,N,N,N,N,N,N,N,N,N,N,36221,N,N,35453,N,N,35522,
+64842,N,36257,N,N,35537,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64692,35655,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,37796,40666,N,N,N,N,N,N,N,N,N,35409,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,36262,N,N,N,N,N,N,40645,N,N,N,N,64708,N,N,N,N,41080,N,
+38069,N,N,N,N,N,N,N,64706,35435,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36267,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,64232,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36269,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64585,N,37825,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,36975,N,36272,N,N,N,N,N,N,N,N,38014,37114,N,N,N,N,N,N,N,N,N,N,
+38009,N,N,N,N,N,N,N,N,36274,N,N,N,N,N,N,N,N,64750,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39291,N,N,N,N,N,N,N,N,36276,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36279,N,
+N,N,N,N,N,N,37299,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36283,36282,N,N,N,N,N,N,N,N,
+36284,36932,N,N,N,64844,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34635,37860,N,
+N,37856,N,N,N,N,N,N,N,64851,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,36291,N,39864,N,N,N,64496,N,37865,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37878,
+N,N,N,N,N,36293,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36298,N,N,N,N,N,36300,64861,37813,
+64865,N,N,N,40184,N,N,N,37458,N,N,41192,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,40101,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35926,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,36310,N,38848,N,N,N,41182,N,N,N,N,38866,N,N,N,N,N,64165,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,64931,N,N,N,36315,36074,36527,N,N,N,N,N,N,N,N,N,37301,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64841,N,N,N,N,N,N,N,N,64977,N,N,N,N,N,N,N,
+N,N,N,36331,N,N,N,N,N,38854,N,64974,N,N,37116,N,N,N,N,N,N,N,N,N,N,N,N,N,64601,
+N,N,38614,N,N,N,N,N,N,38853,36335,N,N,N,N,38871,N,N,N,N,N,36336,N,N,N,N,N,N,N,
+38566,N,N,N,N,N,N,N,64447,N,N,36063,N,36339,N,N,N,N,37961,N,36341,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,39026,N,N,N,N,N,N,N,36459,N,N,N,N,N,N,64253,N,N,N,N,
+N,N,N,N,N,N,36688,N,N,N,N,N,N,40396,64613,N,35908,N,N,39278,38049,N,N,N,N,N,
+36707,N,N,N,N,N,N,N,41178,N,N,N,N,N,N,N,N,N,N,N,37459,65001,N,N,40373,N,N,N,N,
+N,N,N,39033,34666,N,N,40285,N,N,N,N,36195,38505,40816,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,64618,N,N,35527,N,N,N,N,35287,N,N,N,N,N,N,N,N,N,N,N,N,65101,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40669,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,65275,39100,64204,N,N,38320,N,N,N,37988,N,N,N,N,N,N,37743,N,N,N,N,N,N,
+38073,N,N,38380,N,N,N,N,37358,N,N,39107,N,38390,N,N,N,36861,39109,N,N,N,N,
+38758,65134,N,N,38877,36010,N,N,37586,N,N,38753,39115,N,N,N,N,38384,N,38749,N,
+37347,N,N,N,N,39116,N,N,37993,39117,N,N,N,N,N,39118,N,38396,N,N,38051,38498,N,
+N,N,65206,N,37987,36167,N,N,N,N,N,N,39120,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,39121,N,N,N,N,38005,64224,N,N,N,N,N,N,N,N,N,38002,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39126,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,35568,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39129,N,N,N,N,N,N,N,36186,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,39131,N,N,N,N,39133,N,N,N,N,N,N,N,N,39080,N,N,N,N,N,N,N,35437,N,N,N,N,N,
+N,N,N,N,N,N,35579,35502,64457,N,N,N,N,35933,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,39140,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39142,N,N,N,N,
+N,N,N,N,N,N,N,39144,N,N,N,N,N,N,N,N,N,N,N,N,N,35405,N,N,N,37463,N,N,N,N,N,N,N,
+N,N,N,38367,N,N,41132,N,N,N,N,39147,N,N,N,N,39148,N,36035,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,39156,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35512,N,N,N,40679,N,N,N,N,
+N,N,N,N,38076,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64721,N,N,N,N,N,N,40134,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36170,N,40574,36164,39166,65000,N,N,N,N,
+39232,N,N,N,N,38089,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,38099,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39238,N,N,N,N,37056,N,38097,N,N,N,
+N,N,N,N,N,N,N,N,N,N,36174,N,N,38259,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37826,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39240,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,39243,N,N,N,N,N,36437,N,N,N,N,39246,N,N,N,N,N,N,N,N,N,
+N,N,36606,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36191,N,36441,N,N,N,N,N,N,N,N,N,
+38124,38127,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35936,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36724,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,39253,N,N,N,N,N,N,N,N,N,38212,N,N,N,N,N,N,N,N,N,N,N,36043,
+N,N,N,39254,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39257,N,N,N,N,N,N,N,39259,N,N,N,
+N,N,N,N,N,N,N,N,N,N,36036,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64069,N,N,N,
+37047,N,N,38723,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38349,N,N,N,N,N,N,38857,64848,
+36537,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38342,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39271,N,N,
+36067,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35513,N,N,
+N,N,N,N,36348,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35446,N,N,N,N,N,
+40273,N,N,N,N,N,N,N,N,N,N,N,N,N,39283,N,N,34624,N,40271,39290,38244,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,39329,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39333,N,N,N,N,N,
+N,N,39335,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,36589,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39341,N,N,N,N,N,N,N,N,
+N,N,N,36589,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39341,N,51326,N,N,N,N,N,N,
 N,N,N,N,N,N,N,37998,36720,N,64208,N,N,N,N,N,N,N,N,N,N,N,N,N,39347,N,N,N,N,N,N,
-41043,N,N,N,N,N,N,N,N,38492,N,N,N,N,64890,N,N,N,N,N,N,N,N,38910,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,37565,N,38909,N,N,N,N,36708,N,N,N,N,64759,38242,38861,40548,N,N,
-N,N,N,N,N,37452,36553,39356,N,N,N,N,40357,N,36692,N,N,N,N,N,N,N,N,N,N,36732,N,
-N,N,N,N,N,36514,N,N,N,N,N,N,N,N,N,36730,N,N,N,N,N,N,38830,N,N,N,N,38600,N,N,N,
-N,N,N,N,39363,N,37078,N,40126,N,N,N,36726,N,N,N,N,N,N,N,N,N,N,N,N,N,38000,
-64331,N,N,64970,N,N,N,N,N,N,36551,N,N,N,N,N,41209,N,N,N,N,N,N,N,36777,N,N,N,N,
-N,N,N,N,N,N,N,N,39367,N,N,N,N,N,N,N,N,N,N,N,N,N,37079,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,40671,39374,N,N,N,N,N,N,N,N,36794,N,N,N,N,N,36843,N,39375,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36802,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37577,N,N,N,N,N,38876,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38323,40057,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38322,
-36827,N,N,N,N,39907,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40570,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39918,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39390,N,N,N,N,N,N,N,N,N,N,N,N,
-N,64250,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40677,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,35410,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-39393,N,N,N,N,N,N,35431,35765,N,N,N,N,N,N,N,N,N,N,35500,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39401,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64458,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38878,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38353,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,39413,64586,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,39849,N,N,N,N,N,N,N,N,N,N,N,N,64476,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65110,N,
-N,N,N,N,40612,N,N,N,N,N,N,40265,38363,N,N,N,N,N,N,N,N,N,N,35269,N,N,N,N,N,N,N,
-N,N,N,N,N,39416,N,N,N,N,N,N,38500,N,N,N,N,36949,N,N,38612,N,N,N,N,N,N,N,38780,
-N,N,N,N,N,N,38477,N,38881,N,N,N,N,N,N,39496,N,N,N,N,N,N,N,N,N,N,N,39497,N,
-65149,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37034,N,N,N,N,39504,N,N,N,N,N,N,N,
-37703,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36568,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,37065,N,N,N,N,N,39509,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-37052,N,N,N,N,N,39512,N,35768,37077,N,N,N,N,N,N,N,N,N,N,N,N,N,38465,N,N,N,N,N,
-N,39514,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39516,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,38850,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35515,N,N,
-N,39850,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37109,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,39520,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-37189,35928,N,N,N,N,N,N,N,N,39523,N,N,N,N,N,N,35913,N,N,N,N,N,N,N,N,N,N,N,
-35766,N,N,N,N,N,N,N,N,N,N,64719,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38507,39534,N,
-37199,N,N,N,N,N,N,N,N,38726,N,N,41190,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37591,N,
-38517,N,N,37844,N,N,37307,38521,N,N,N,N,N,39536,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38520,37325,N,40010,41071,N,N,41066,N,N,N,N,N,
-N,37215,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,40869,N,N,35258,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,40653,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39545,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,40398,N,N,N,36050,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,40307,N,N,N,N,N,N,N,N,N,38585,N,38588,N,N,N,N,N,N,40145,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35255,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,40686,N,N,N,N,N,N,N,N,N,N,N,64323,40649,N,N,N,N,N,N,64467,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37294,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,40312,N,N,N,N,N,N,N,N,N,N,40315,40627,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,40626,N,40406,N,N,N,N,39247,N,N,35278,N,N,N,35776,N,40900,N,35796,
-N,N,35954,N,N,N,N,N,N,50879,35833,N,N,N,N,N,35142,N,50880,N,N,N,N,N,N,N,N,N,
-64229,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,51323,35782,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-40023,N,N,N,N,N,N,N,N,N,N,N,N,N,39675,N,N,N,N,N,N,N,35280,35279,N,N,N,50881,N,
-35281,N,35298,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37502,N,40378,N,N,N,N,N,50882,N,N,
-35951,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64504,N,N,N,35783,37483,N,N,35282,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,40911,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,40361,35283,N,N,39394,N,N,N,N,N,N,N,N,N,37479,37540,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,35955,N,N,35150,N,N,N,N,N,N,N,N,N,N,N,N,N,35151,37496,N,
-N,N,N,N,N,N,N,37302,N,N,N,N,35284,N,40914,N,N,N,N,N,N,N,N,37543,N,N,38306,N,N,
-N,N,N,37486,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,38634,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37487,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37539,N,N,N,N,N,35152,N,N,64087,N,N,N,N,
-39014,N,N,N,N,N,N,N,N,N,N,N,N,35286,N,N,N,N,N,N,N,N,N,N,39090,N,N,N,37547,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38622,37548,N,N,N,N,N,N,N,N,N,N,
-35952,N,40814,N,N,N,N,N,N,36594,N,N,N,40812,35288,N,N,N,N,64089,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37544,N,N,N,N,N,
-37219,N,N,N,N,N,N,35904,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-40819,N,37549,N,N,N,N,N,N,N,N,N,N,N,N,N,39913,N,N,N,N,N,37545,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,37546,N,N,N,N,N,N,35289,N,N,N,N,N,N,N,64854,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40872,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,35953,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37537,N,N,37091,N,N,N,N,N,N,N,N,41126,
-N,N,N,N,N,38059,N,64626,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38852,N,N,N,N,N,N,
-N,37550,64103,N,N,N,N,N,N,N,N,N,N,N,37538,64105,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,37480,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35153,N,N,N,N,N,N,N,N,N,64111,N,N,N,N,N,
-N,N,N,N,64113,N,N,N,N,N,N,N,N,N,35154,N,N,N,N,37978,N,N,N,N,N,N,N,N,50883,N,N,
-N,35293,N,51362,N,N,N,N,N,N,N,N,N,N,N,N,N,50884,N,N,N,40530,N,35155,N,N,N,N,N,
-N,N,N,N,N,40533,37562,N,N,50885,N,N,35931,N,N,N,64125,64168,39528,64071,N,N,
-64126,N,N,N,N,N,N,N,N,N,N,37563,N,N,N,64950,N,64162,N,N,N,N,N,64163,N,64164,
-39860,64166,N,N,N,N,N,N,N,35295,N,N,N,64987,N,N,64169,N,35156,N,N,N,N,N,N,N,N,
-64171,N,N,N,N,N,N,64634,N,N,N,N,N,N,N,35296,N,40783,51325,N,N,35297,N,N,N,N,N,
-64176,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40909,41191,N,N,N,N,N,64177,35238,
-N,N,N,N,N,N,N,N,N,N,N,N,40698,N,N,N,N,N,N,N,64178,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,64180,N,37572,N,N,N,N,N,N,40815,N,N,N,N,N,N,N,35760,N,
-N,N,N,N,N,N,N,N,N,40876,N,N,N,N,N,35299,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,39891,35300,N,N,N,64181,N,N,N,N,N,40917,N,N,N,N,N,N,35157,N,N,37573,N,N,N,
-35158,N,N,N,N,N,N,N,N,N,N,N,N,64179,N,N,N,64182,N,N,N,N,N,N,N,N,N,N,N,64183,N,
-N,N,N,N,N,40668,N,N,N,64452,40817,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64186,37575,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,50886,39500,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35944,N,N,35301,N,N,N,N,40829,N,N,
-N,N,N,41129,64196,N,N,N,N,50887,N,N,35159,N,N,N,N,N,N,64170,N,N,N,N,N,N,N,N,N,
-N,N,35160,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35811,N,35681,N,N,N,N,39665,N,N,40631,N,
+41043,N,N,N,N,N,36190,N,N,38492,N,N,36064,N,64890,N,N,N,N,N,N,N,N,38910,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,37565,36189,38909,N,N,N,N,36708,N,N,N,N,64759,38242,
+38861,40548,N,N,N,N,N,N,N,37452,36553,39356,N,N,N,N,40357,N,36692,N,N,N,N,N,N,
+N,N,N,N,36732,N,N,N,N,36181,N,36514,N,N,N,N,N,N,N,N,N,36730,N,N,N,N,N,N,38830,
+N,N,N,N,38600,N,N,36068,N,N,N,N,39363,N,37078,N,40126,N,N,N,36726,N,N,N,N,N,N,
+N,N,N,N,N,N,N,38000,64331,N,N,64970,N,N,36079,N,N,N,36551,N,N,N,N,36180,41209,
+N,N,N,N,N,N,N,36777,N,N,36177,N,N,N,N,N,N,N,N,N,39367,34628,N,N,N,N,N,N,N,N,N,
+N,N,N,37079,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+34627,N,N,N,N,N,N,N,N,N,N,N,N,34631,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34648,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40671,
+36185,34626,N,N,39374,N,N,N,N,N,N,N,N,36794,N,N,N,N,N,36843,N,39375,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36802,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37577,N,N,N,N,N,38876,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34653,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,36165,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38323,40057,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38322,N,
+36172,36827,N,N,N,N,39907,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,34636,N,N,N,N,N,N,N,N,N,N,N,N,N,34637,N,N,N,N,N,N,N,N,N,40570,34647,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,39918,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39390,N,N,N,
+N,N,N,N,N,N,N,N,N,N,64250,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35410,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,39393,N,N,N,N,N,N,35431,35765,N,N,N,N,N,N,N,N,N,N,35500,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39401,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,64458,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38878,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38353,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,39413,64586,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,39849,N,N,N,N,N,N,N,N,N,N,N,N,64476,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,65110,N,N,N,N,N,40612,N,N,N,N,N,N,40265,38363,N,N,N,N,N,N,N,N,N,N,35269,
+N,N,N,N,N,N,N,N,N,N,N,N,39416,N,N,N,N,N,N,38500,N,N,N,N,36949,N,N,38612,N,N,N,
+N,N,N,N,38780,N,N,N,N,N,N,38477,N,38881,N,N,N,N,N,N,39496,N,N,N,N,N,N,N,N,N,N,
+N,39497,N,65149,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37034,N,N,N,N,39504,N,N,N,N,
+N,N,N,37703,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36568,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37065,N,N,N,N,N,39509,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,37052,N,N,N,N,N,39512,N,35768,37077,N,N,N,N,N,N,N,N,N,N,N,N,N,38465,N,N,
+N,N,N,N,39514,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39516,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,38850,N,N,N,N,N,N,N,N,N,N,N,N,N,34652,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35515,N,N,N,39850,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37109,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39520,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,37189,35928,N,N,N,N,N,N,N,N,39523,N,N,N,N,N,N,35913,N,N,N,N,N,N,N,N,
+N,N,N,35766,N,N,N,N,N,N,N,N,N,N,64719,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38507,
+39534,N,37199,N,N,N,N,N,N,N,N,38726,N,N,41190,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+37591,N,38517,N,N,37844,N,N,37307,38521,N,N,N,N,N,39536,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38520,37325,N,40010,41071,N,N,41066,N,
+N,N,N,N,N,37215,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,34625,N,N,N,N,N,N,N,N,40869,N,N,35258,N,34639,N,N,N,N,N,N,34638,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,34645,N,N,N,40653,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39545,N,N,N,N,N,N,N,N,N,36082,N,N,N,36183,N,40398,N,N,N,36050,N,N,N,34649,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40307,N,N,N,N,N,N,N,N,
+N,38585,N,38588,N,N,N,N,N,N,40145,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35255,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40686,34633,N,N,N,N,N,N,N,N,N,N,
+64323,34651,N,40649,N,N,N,N,N,N,64467,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37294,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,36184,34630,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36182,N,N,N,N,N,N,N,
+40312,N,N,N,N,N,N,N,N,N,N,40315,40627,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,40626,N,40406,N,N,N,N,39247,N,N,35278,N,N,N,35776,N,40900,N,35796,N,N,35954,
+N,N,N,N,N,N,50879,35833,N,N,N,N,N,35142,N,50880,N,N,N,N,N,N,N,N,N,64229,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,51323,35782,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40023,N,N,N,
+N,N,N,N,N,N,N,N,N,N,39675,N,N,N,N,N,N,N,35280,35279,N,N,N,50881,N,35281,N,
+35298,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37502,N,40378,N,N,N,N,N,50882,N,N,35951,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64504,N,N,N,35783,37483,N,N,35282,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,40911,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40361,35283,N,N,39394,N,N,N,N,N,N,N,N,N,37479,37540,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,35955,N,N,35150,N,N,N,N,N,N,N,N,N,N,N,N,N,35151,37496,N,N,N,N,N,N,
+N,N,37302,N,N,N,N,35284,N,40914,N,N,N,N,N,N,N,N,37543,N,N,38306,N,N,N,N,N,
+37486,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,38634,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37487,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37539,N,N,N,N,N,35152,N,N,64087,N,N,N,N,39014,N,
+N,N,36088,N,N,N,N,N,N,N,N,35286,N,N,N,N,N,N,N,N,N,N,39090,N,N,N,37547,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38622,37548,N,N,N,N,N,N,N,N,N,N,35952,N,
+40814,N,N,N,N,N,N,36594,N,N,N,40812,35288,N,N,N,N,64089,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37544,N,N,N,N,N,37219,N,N,
+N,N,N,N,35904,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40819,N,
+37549,N,N,N,N,N,N,N,N,N,N,N,N,N,39913,N,N,N,N,N,37545,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,37546,N,N,N,N,N,N,35289,N,N,N,N,N,N,N,64854,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,40872,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35953,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37537,N,N,37091,N,N,N,N,N,N,N,N,41126,N,N,N,N,
+N,38059,N,64626,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38852,N,N,N,N,N,N,N,37550,
+64103,N,N,N,N,N,N,N,N,N,N,N,37538,64105,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,37480,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35153,N,N,N,N,N,N,N,N,N,64111,N,N,N,N,N,N,N,N,N,
+64113,N,N,N,N,N,N,N,N,N,35154,N,N,N,N,37978,N,N,N,N,N,N,N,N,50883,N,N,N,35293,
+N,51362,N,N,N,N,N,N,N,N,N,N,N,N,N,50884,N,N,N,40530,N,35155,N,N,N,N,N,N,N,N,N,
+N,40533,37562,N,N,50885,N,N,35931,N,N,N,64125,64168,39528,64071,N,N,64126,N,N,
+N,N,N,N,N,N,N,N,37563,N,N,N,64950,N,64162,N,N,N,N,N,64163,N,64164,39860,64166,
+N,N,N,N,N,N,N,35295,N,N,N,64987,N,N,64169,N,35156,N,N,N,N,N,N,N,N,64171,N,N,N,
+N,N,N,64634,N,N,N,N,N,N,N,35296,N,40783,51325,N,N,35297,N,N,N,N,N,64176,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40909,41191,N,N,N,N,N,64177,35238,N,N,N,N,N,N,
+N,N,N,N,N,N,40698,N,N,N,N,N,N,N,64178,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,64180,N,37572,N,N,N,N,N,N,40815,N,N,N,N,N,N,N,35760,N,N,N,N,N,N,N,
+N,N,N,40876,N,N,N,N,N,35299,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39891,
+35300,N,N,N,64181,N,N,N,N,N,40917,N,N,N,N,N,N,35157,N,N,37573,N,N,N,35158,N,N,
+N,N,N,N,N,N,N,N,N,N,64179,N,N,N,64182,N,N,N,N,N,N,N,N,N,N,N,64183,N,N,N,N,N,N,
+40668,N,N,N,64452,40817,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64186,37575,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,50886,39500,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35944,N,N,35301,N,N,N,N,40829,N,N,N,N,N,
+41129,64196,N,N,N,N,50887,N,N,35159,N,N,N,N,N,N,64170,N,N,N,N,N,N,N,N,N,N,N,
+35160,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35811,N,35681,N,N,N,N,39665,N,N,40631,N,
 50888,N,N,N,64209,N,N,N,N,N,N,64210,N,N,N,N,N,N,N,N,40634,64212,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,64217,N,N,N,N,N,N,N,N,N,N,N,N,64219,N,40160,N,N,N,
 64503,N,64506,35303,41082,64220,N,N,64221,N,35305,N,N,N,N,N,50889,N,N,N,N,N,N,
@@ -790,17 +804,17 @@
 N,N,N,N,N,N,37472,N,N,N,N,N,N,N,N,N,N,N,37470,37313,N,35525,N,N,38819,N,N,N,N,
 N,N,N,N,N,N,35692,N,36222,N,N,N,N,N,N,N,40020,N,N,N,N,N,40381,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,40133,N,N,N,N,N,N,N,N,N,N,N,35163,N,N,N,N,N,N,N,N,
-N,N,64348,N,64347,N,64343,N,N,N,N,N,N,N,N,N,N,N,39111,64346,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,40174,N,N,N,N,N,N,N,37602,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,38055,N,N,N,N,N,N,N,N,N,N,36044,N,39892,N,N,64356,64374,N,N,64352,N,
-N,N,N,N,N,N,N,N,N,N,N,N,39397,N,N,39618,N,N,N,37371,N,N,N,41075,N,N,N,N,N,N,N,
-40818,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40908,N,N,N,39077,37608,N,N,N,N,N,N,
-N,N,39868,N,38643,N,N,37607,N,N,64615,N,N,N,N,N,N,N,N,N,N,N,35709,N,N,N,N,
-39924,N,N,N,N,N,40695,N,N,40641,N,N,N,N,N,N,N,N,N,39279,N,N,N,N,N,N,38641,N,N,
-36417,N,N,N,N,N,38218,N,N,N,38886,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38645,N,N,N,N,N,
-37606,40770,N,N,N,N,N,N,N,64359,N,N,N,N,N,N,N,N,39337,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,64230,64361,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38885,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,38525,N,N,N,64364,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39330,N,N,N,N,N,
+N,N,64348,N,64347,N,64343,N,N,N,N,N,N,N,N,N,34661,N,39111,64346,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,40174,N,N,N,N,N,N,N,37602,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,38055,N,N,N,N,N,N,N,N,N,N,36044,N,39892,N,N,64356,64374,N,N,
+64352,N,N,N,N,N,N,N,N,N,N,N,N,N,39397,N,N,39618,N,N,N,37371,N,N,N,41075,N,N,N,
+N,N,N,N,40818,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40908,N,N,N,39077,37608,N,N,
+N,N,N,N,N,N,39868,N,38643,N,N,37607,N,N,64615,N,N,N,N,N,N,N,N,N,N,N,35709,N,N,
+N,N,39924,N,N,N,N,N,40695,N,N,40641,N,N,N,N,N,N,N,N,N,39279,N,N,N,N,N,N,38641,
+N,N,36417,N,N,N,N,N,38218,N,N,N,38886,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38645,N,N,N,
+N,N,37606,40770,N,N,N,N,N,N,N,64359,N,N,N,N,N,N,N,N,39337,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,64230,64361,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38885,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,38525,N,N,N,64364,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39330,N,N,N,N,N,
 39611,N,N,N,39525,N,N,37966,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64366,N,N,
 39391,N,N,N,N,N,N,N,N,N,39139,N,N,37460,N,N,N,N,N,38523,35503,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35959,N,N,N,N,N,N,35759,40637,N,N,
@@ -808,405 +822,407 @@
 N,63961,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37610,N,N,N,N,35960,N,N,N,N,N,N,N,N,N,N,
 N,64370,N,N,N,64369,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35164,N,39152,38642,N,N,N,N,
 N,N,N,64372,35777,N,35165,35294,N,35166,N,N,50890,N,N,N,N,N,N,65090,N,N,N,N,N,
-N,N,N,N,N,N,N,N,64379,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35167,N,35168,N,N,N,
+N,N,N,N,N,N,34664,N,64379,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35167,N,35168,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,39885,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40403,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,38988,N,N,N,N,N,N,N,N,N,N,38738,N,N,N,N,N,38339,N,N,N,N,39862,N,
-N,N,N,N,N,N,N,N,N,N,N,39609,N,N,N,38835,N,N,N,N,N,N,40820,37617,N,N,N,N,N,N,N,
-N,N,N,N,38879,N,N,N,N,64422,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64427,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,39031,N,N,N,38996,38341,N,N,N,N,N,N,N,40277,64434,38270,N,
-N,N,N,N,N,N,N,38722,N,38118,N,N,N,N,37621,N,N,N,N,N,N,N,36037,N,N,N,N,N,N,
-37629,N,N,64418,N,N,40017,N,N,38121,39004,37616,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,37964,N,N,N,N,N,N,N,37227,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35704,N,N,N,N,38114,N,
-N,N,N,N,N,N,38991,N,64437,N,N,N,N,37489,N,N,37733,N,N,39003,N,N,38992,N,N,N,N,
-N,N,N,38844,N,N,N,N,37619,N,N,37696,38989,N,N,N,38258,N,65007,N,N,N,N,N,N,N,N,
-64961,N,N,N,N,64442,N,N,37611,N,N,N,N,N,N,64627,38839,N,N,N,N,N,N,N,N,N,64436,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37031,N,N,N,N,N,N,N,N,N,N,38721,
-37620,N,N,N,64444,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38263,N,N,N,N,N,N,N,N,N,N,N,
-40674,N,36728,N,N,N,N,N,N,N,63964,N,N,N,38514,40629,N,N,N,38475,N,N,N,36012,N,
-N,N,N,N,N,N,N,N,41210,N,N,N,N,N,N,N,N,N,N,N,38261,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,37082,N,N,37735,N,65188,N,N,N,37087,N,N,N,N,37716,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35169,N,35764,N,N,N,N,40384,N,N,N,N,N,N,36424,N,
-64453,N,N,N,N,N,64455,N,N,N,50891,N,64121,N,N,N,N,N,N,N,N,N,N,N,N,N,40551,N,N,
-N,N,N,36057,N,N,N,N,N,N,64466,35170,35171,N,N,N,N,N,N,N,N,N,N,64637,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40811,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64460,N,65198,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64465,N,N,
-N,N,N,N,N,N,N,N,N,64373,64468,N,N,N,N,N,N,N,N,N,N,N,N,N,64470,64472,N,N,N,N,N,
-N,N,35677,N,37708,N,39650,N,N,35785,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64475,40905,N,N,N,N,N,N,N,N,40772,N,N,N,N,N,N,
-N,N,N,N,39149,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,64477,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36338,35172,N,65010,N,
-37709,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64487,N,N,N,N,N,N,
-41202,39016,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40792,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,36211,N,N,N,64478,N,N,N,N,N,64479,N,N,N,N,N,35912,64483,N,N,N,N,36264,N,
-N,64484,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40053,N,N,39032,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,36192,N,N,N,N,N,N,N,64485,N,36193,N,N,N,N,N,N,N,N,N,N,N,N,N,36194,
-41121,N,N,N,40000,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39085,N,N,N,40682,N,
-N,N,N,N,N,36052,N,N,N,N,N,N,N,N,N,40171,N,N,N,N,N,64480,N,N,40785,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36197,N,N,N,N,N,N,40177,N,N,N,N,N,N,N,N,N,N,
-64600,N,N,36198,N,N,N,N,N,N,N,38484,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64488,N,N,N,50892,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40910,
-64508,N,39652,N,N,N,N,N,N,40821,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,64497,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36201,N,N,N,N,N,37711,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37710,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,64500,N,N,N,N,50894,N,N,N,64451,N,N,35173,N,N,N,N,N,N,N,N,
-N,N,N,35962,N,N,N,N,N,N,35963,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,36202,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37715,N,N,40443,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64509,N,N,N,
-36953,64576,N,64577,64579,37729,64582,37730,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,36203,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64588,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,38328,N,N,50896,35786,N,N,N,N,N,N,N,N,N,N,39034,N,N,N,N,
-50897,N,64593,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64596,N,N,N,N,N,N,N,N,64175,N,N,N,N,
-N,N,N,36204,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64097,N,N,64599,N,N,N,N,N,N,N,N,N,39792,N,N,N,N,N,N,N,N,41041,N,N,N,N,N,N,N,
-35964,N,35787,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37742,N,N,N,64725,
-64681,N,N,N,N,N,N,N,N,N,N,N,N,N,64609,N,N,N,N,N,N,N,N,N,35174,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,64203,N,N,N,N,N,N,N,63962,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,37754,N,41184,N,N,N,N,N,N,37739,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64619,N,N,N,N,N,41180,N,N,37992,N,
-N,N,N,N,N,N,N,N,N,N,64621,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,36209,N,N,N,N,N,N,64868,N,N,N,N,39354,N,N,N,39632,39521,
-41189,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41051,38572,N,N,N,N,38720,N,N,N,N,
-N,N,N,N,N,N,N,N,40689,N,N,N,N,N,N,N,N,35917,N,N,N,N,N,N,N,N,N,N,N,N,N,40830,N,
-N,N,N,N,N,N,N,N,N,N,N,36210,N,N,N,N,64630,N,N,N,N,N,N,N,N,N,N,N,N,N,38569,N,N,
-N,N,N,N,N,N,41070,N,N,64682,N,N,N,64461,N,N,N,64628,N,N,N,N,N,N,N,N,N,N,41076,
-N,N,N,N,N,N,N,N,N,N,N,N,N,41073,N,N,N,64633,N,N,N,N,N,64636,N,N,N,N,N,N,N,N,N,
-N,N,N,N,40016,N,N,37753,37752,N,N,41181,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,36213,N,36214,N,N,N,N,N,N,37748,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-36215,64677,N,N,64674,N,N,N,N,N,N,37059,N,N,N,N,N,N,N,41081,36217,N,N,N,N,N,N,
-N,N,N,N,35836,N,41078,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35789,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40794,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,40948,N,N,40890,N,N,N,N,N,N,N,N,N,N,36218,N,N,N,N,N,N,N,N,N,
-N,N,N,40517,N,N,N,N,N,N,37808,N,41077,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,39750,N,64686,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64688,N,N,N,N,N,N,
-N,N,N,64081,N,N,N,N,N,36219,36220,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-40662,N,N,37804,N,N,N,40795,N,37801,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41084,N,N,N,N,N,N,N,64690,N,N,N,
-N,N,N,N,N,N,N,N,N,35521,N,N,N,N,N,40884,N,N,N,N,N,N,N,N,N,N,N,64684,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,40524,N,N,N,N,N,N,N,36805,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37805,N,N,N,N,N,N,N,
-N,N,N,N,N,40387,N,N,N,36258,N,N,N,40266,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64694,N,N,36259,40523,N,40525,36260,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35581,N,N,N,N,N,64693,N,64707,37810,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36261,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37793,N,N,N,N,N,N,N,N,N,N,35526,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,35419,N,N,N,35149,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,65236,N,N,N,N,35448,N,37803,N,N,N,N,N,N,N,N,N,36263,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,40773,N,N,N,N,N,N,N,N,N,35414,N,N,N,64703,N,N,N,
-64704,N,36582,N,N,35492,35139,N,N,N,N,N,N,37875,N,N,N,N,N,N,N,N,N,N,N,N,64683,
-40610,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40391,N,N,N,50898,35790,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64709,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64715,N,
-N,N,N,N,N,N,N,N,N,N,37811,N,64714,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,64713,36268,N,64454,35175,N,35966,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64717,N,N,N,N,N,N,N,N,40179,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,64720,N,N,38331,N,N,N,N,N,N,N,N,N,N,N,64723,N,N,
-64724,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36270,64727,N,N,N,
-N,N,37851,N,N,N,N,65123,N,N,N,N,N,N,N,N,N,N,N,N,37845,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,64730,N,N,N,39793,N,N,64733,N,N,N,N,N,N,N,36271,N,N,N,64242,N,N,
-N,N,N,N,N,N,N,N,N,37848,N,N,N,64735,N,N,N,37843,N,N,N,N,N,N,N,64737,N,N,N,N,N,
-N,N,N,N,36470,N,N,N,N,N,N,N,64610,N,N,N,N,N,N,N,N,37841,N,N,N,36273,N,N,N,N,N,
-N,N,39001,N,N,N,N,N,N,N,N,N,64338,N,N,N,N,N,N,N,N,64339,N,N,N,N,N,64333,N,N,
-40127,N,N,N,N,N,N,N,N,39794,N,N,N,N,N,N,N,N,N,N,N,N,N,64336,37822,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40433,64747,N,N,N,N,N,
-N,N,N,N,41147,N,39806,N,N,N,N,N,N,N,36275,N,N,35922,N,N,N,N,39656,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,39885,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40403,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,38988,N,N,N,N,N,N,N,N,N,N,38738,N,N,N,N,N,38339,N,N,N,N,
+39862,N,N,N,N,N,N,N,N,N,N,N,N,39609,N,N,N,38835,N,N,N,N,N,N,40820,37617,N,N,N,
+N,N,N,36090,N,N,N,N,38879,N,N,N,N,64422,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64427,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39031,N,N,N,38996,38341,N,N,N,N,N,N,N,40277,
+64434,38270,N,N,N,N,N,N,N,N,38722,N,38118,N,N,N,N,37621,N,N,N,N,N,N,N,36037,N,
+N,N,N,N,N,37629,N,N,64418,N,N,40017,N,N,38121,39004,37616,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,37964,N,N,N,N,N,N,N,37227,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35704,N,N,N,
+N,38114,N,N,N,N,N,N,N,38991,N,64437,N,N,N,N,37489,N,N,37733,N,N,39003,N,N,
+38992,N,N,N,N,N,N,N,38844,N,N,N,N,37619,N,N,37696,38989,N,N,N,38258,N,65007,N,
+N,N,N,N,N,N,N,64961,N,N,N,N,64442,N,N,37611,N,N,N,N,N,N,64627,38839,N,N,34671,
+N,N,N,N,N,N,64436,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37031,N,N,N,N,
+N,N,N,N,N,N,38721,37620,N,34674,N,64444,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38263,
+N,N,N,N,N,N,N,N,N,N,N,40674,N,36728,N,N,N,N,N,N,N,63964,N,N,N,38514,40629,N,N,
+N,38475,N,N,N,36012,N,N,N,N,N,N,N,N,N,41210,N,N,N,N,N,N,N,N,N,N,N,38261,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37082,N,N,37735,N,65188,N,N,N,37087,N,N,N,
+N,37716,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35169,N,35764,N,N,N,N,
+40384,N,N,N,N,N,N,36424,N,64453,N,N,N,N,N,64455,N,N,N,50891,N,64121,N,N,N,N,N,
+N,N,N,N,N,N,N,N,40551,N,N,N,N,N,36057,N,N,N,N,N,N,64466,35170,35171,N,N,N,N,N,
+N,N,N,N,N,64637,N,N,N,N,N,N,N,N,N,N,N,N,34675,N,N,N,N,N,N,N,N,N,N,N,40811,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64460,N,65198,N,N,N,34669,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,64465,N,N,N,N,N,N,N,N,N,N,N,64373,64468,N,N,N,N,N,N,N,
+N,N,N,N,N,N,64470,64472,N,N,N,N,N,N,N,35677,N,37708,N,39650,N,N,35785,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64475,40905,
+N,N,N,N,N,N,N,N,40772,N,N,N,N,N,N,N,N,N,N,39149,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,36073,N,N,N,N,N,N,N,N,N,N,N,N,64477,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,36338,35172,N,65010,N,37709,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,64487,N,N,N,N,N,N,41202,39016,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40792,N,N,N,36070,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36211,N,N,N,64478,N,N,N,N,N,
+64479,N,N,N,N,N,35912,N,N,N,N,N,N,34676,64483,N,N,N,N,36264,N,N,64484,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40053,N,N,39032,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+36192,N,N,N,N,N,N,N,64485,N,36193,N,N,N,N,N,N,N,N,N,N,N,N,N,36194,41121,N,N,N,
+40000,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39085,N,N,N,40682,N,N,N,36076,N,
+N,36052,N,N,N,N,N,N,N,N,N,40171,N,N,N,N,N,64480,N,N,40785,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,36197,N,N,N,N,N,N,40177,N,N,N,N,N,N,N,N,N,N,64600,N,N,
+36198,N,N,N,N,N,N,N,38484,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64488,N,N,
+N,50892,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40910,64508,N,39652,
+N,N,N,N,N,N,40821,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64497,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36201,N,N,N,N,N,37711,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,37710,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,64500,N,N,N,N,50894,N,N,N,64451,N,N,35173,N,N,N,N,N,N,N,N,N,N,N,35962,N,
+N,N,N,N,N,35963,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,36202,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37715,N,N,40443,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64509,N,N,N,36953,64576,N,
+64577,64579,37729,64582,37730,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+36203,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64588,36094,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,38328,N,N,50896,35786,N,N,N,N,N,N,N,N,N,N,39034,N,N,N,N,50897,N,
+64593,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64596,N,N,N,N,N,N,N,N,64175,N,N,N,N,N,N,N,
+36204,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64097,N,
+N,64599,N,N,N,N,N,N,N,N,N,39792,N,N,N,N,N,N,N,N,41041,N,N,N,N,N,N,N,35964,N,
+35787,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37742,N,N,N,64725,64681,N,N,
+N,N,N,N,N,N,N,N,N,N,N,64609,N,N,N,N,N,N,N,N,N,35174,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,64203,N,N,N,N,N,N,N,63962,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,37754,N,41184,N,N,N,N,N,N,37739,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64619,N,N,N,N,N,41180,N,N,37992,N,N,N,N,N,N,
+N,N,N,N,N,64621,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,36209,N,N,N,N,N,N,64868,N,N,N,N,39354,N,N,N,39632,39521,41189,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41051,38572,N,N,N,N,38720,N,N,N,N,N,N,N,N,N,N,N,
+N,40689,N,N,N,N,N,N,N,N,35917,N,N,N,N,N,N,N,N,N,N,N,N,N,40830,N,N,N,N,N,N,N,N,
+N,N,N,N,36210,N,N,N,N,64630,N,N,N,N,N,N,N,N,N,N,N,N,N,38569,N,N,N,N,N,N,N,N,
+41070,N,N,64682,N,N,N,64461,N,N,N,64628,N,N,N,N,N,N,N,N,N,N,41076,N,N,N,N,N,N,
+N,N,N,N,N,N,N,41073,N,N,N,64633,N,N,N,N,N,64636,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40016,N,N,37753,37752,N,N,41181,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,36213,N,36214,N,N,N,N,N,N,37748,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36215,64677,
+N,N,64674,N,N,N,N,N,N,37059,N,N,N,N,N,N,N,41081,36217,N,N,N,N,N,N,N,N,N,N,
+35836,N,41078,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35789,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40794,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,40948,N,N,40890,N,N,N,N,N,N,N,N,N,N,36218,N,N,N,N,N,N,N,N,N,N,N,N,
+40517,N,N,N,N,N,N,37808,N,41077,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,39750,N,64686,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64688,N,N,N,N,N,N,N,N,N,
+64081,N,N,N,N,N,36219,36220,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40662,N,
+N,37804,N,N,N,40795,N,37801,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41084,N,N,N,N,N,N,N,64690,N,N,N,N,N,N,N,
+N,N,N,N,N,35521,N,N,N,N,N,40884,N,N,N,N,N,N,N,N,N,N,N,64684,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40524,
+N,N,N,N,N,N,N,36805,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37805,N,N,N,N,N,N,N,N,N,N,N,
+N,40387,N,N,N,36258,N,N,N,40266,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64694,N,N,
+36259,40523,N,40525,36260,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35581,N,N,N,N,N,64693,N,64707,37810,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36261,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,37793,N,N,N,N,N,N,N,N,N,N,35526,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,35419,N,N,N,35149,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,65236,N,N,N,N,35448,N,37803,N,N,N,N,N,N,N,N,N,36263,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,40773,N,N,N,N,N,N,N,N,N,35414,N,N,N,64703,N,N,N,64704,N,36582,
+N,N,35492,35139,N,N,N,N,N,N,37875,N,N,N,N,N,N,N,N,N,N,N,N,64683,40610,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,40391,N,N,N,50898,35790,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,64709,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64715,N,N,N,N,N,N,N,N,
+N,N,N,37811,N,64714,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64713,36268,
+N,64454,35175,N,35966,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,64717,N,N,N,N,N,N,N,N,40179,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,64720,N,N,38331,N,N,N,N,N,N,N,N,N,N,N,64723,N,N,64724,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36270,64727,N,N,N,N,N,37851,N,N,N,N,
+65123,N,N,N,N,N,N,N,N,N,N,N,N,37845,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+64730,N,N,N,39793,N,N,64733,N,34660,N,N,N,N,N,36271,N,N,N,64242,N,N,N,N,N,N,N,
+N,N,N,N,37848,N,N,N,64735,N,N,N,37843,N,N,N,N,N,N,N,64737,N,N,N,N,N,N,N,N,N,
+36470,N,N,N,N,N,N,N,64610,N,N,N,N,N,N,N,N,37841,N,N,N,36273,N,N,N,N,N,N,N,
+39001,N,N,N,N,N,N,N,N,N,64338,N,N,N,N,N,N,N,N,64339,N,N,N,N,N,64333,N,N,40127,
+N,N,N,N,N,N,N,N,39794,N,N,N,N,N,N,N,N,N,N,N,N,N,64336,37822,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36059,N,N,N,N,N,N,N,N,N,40433,64747,N,N,N,N,N,N,
+N,N,N,41147,N,39806,N,N,N,N,N,N,N,36275,N,N,35922,N,N,N,N,39656,N,N,N,N,N,N,
 36572,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40185,N,N,N,N,N,N,N,N,N,N,N,N,N,64080,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39143,64755,N,N,N,N,
-64754,N,N,N,36042,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,37861,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39513,N,N,N,36277,N,N,N,N,N,N,
-N,64845,N,N,N,N,64862,N,N,N,N,N,N,N,N,N,N,N,N,N,36733,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,38215,64758,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,37456,N,N,N,N,35176,36278,64763,41085,39164,35177,N,N,N,N,
-N,N,N,N,65103,N,N,37462,N,N,N,N,N,N,N,N,N,N,64201,N,N,37864,N,N,N,64760,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40163,64937,N,N,N,N,N,N,64580,N,N,N,N,N,N,N,N,
-38464,N,N,36280,N,N,N,N,N,N,N,N,N,N,39754,36793,N,N,N,N,N,N,64766,N,N,N,N,N,N,
-N,35178,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36281,N,N,
-N,37246,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37876,N,N,N,N,N,N,N,N,N,N,N,N,N,64380,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,37863,N,N,38895,N,N,N,65098,N,N,N,N,N,64837,N,
-38565,N,N,N,N,65248,64840,64839,65266,65130,N,N,N,N,N,36285,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,39841,36002,39607,36604,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40865,N,N,N,
-N,N,N,N,N,N,64849,N,N,N,N,N,N,N,64173,N,N,N,N,36286,N,N,35236,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,39641,N,N,N,N,N,N,N,N,N,N,N,64846,N,N,36288,N,N,38896,N,N,N,N,N,N,
-N,N,N,N,37812,64836,N,N,N,N,N,N,N,N,N,N,N,N,40871,N,N,N,N,36290,N,N,N,N,39350,
-N,N,N,N,N,N,N,N,N,N,N,N,N,64850,N,N,N,N,N,N,36289,N,N,36422,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,41169,N,N,N,N,N,N,N,N,N,N,N,N,N,40906,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,37583,N,N,N,40180,36292,N,N,N,N,N,N,N,N,N,N,64833,N,N,N,N,N,N,N,39756,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,64855,64751,40158,N,N,N,N,N,N,N,64834,39020,N,N,N,N,
-N,N,N,N,N,N,N,N,N,38905,N,38232,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39006,65147,38093,
-N,N,N,N,N,37870,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36003,N,64858,N,N,N,N,N,N,37877,
-N,N,N,N,N,37871,36586,N,N,N,36699,N,N,N,N,N,N,N,N,N,N,N,35934,N,36294,N,N,N,N,
-N,N,N,N,N,N,N,36296,N,N,36295,N,N,N,N,N,37879,N,N,N,N,N,N,N,36297,N,N,N,N,N,N,
-N,64498,N,N,N,N,38512,N,N,N,N,N,N,N,N,N,36299,N,N,N,64860,N,N,N,N,N,N,N,N,N,
-36709,N,N,N,36301,N,N,N,N,N,40360,38137,N,N,36302,N,N,N,N,N,N,N,N,37866,N,N,N,
-N,N,N,N,N,N,64863,37872,40886,N,N,N,N,N,N,N,N,N,36303,N,N,N,38755,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36304,37873,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,64866,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64869,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40923,N,N,N,N,
-37880,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35831,N,N,N,N,64870,N,N,N,
-N,N,35791,N,N,N,N,N,N,36305,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+64754,N,N,N,36042,N,N,34677,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,37861,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39513,N,N,N,36277,N,N,N,N,
+N,N,N,64845,N,N,N,N,64862,N,N,N,N,N,N,N,N,N,N,N,N,N,36733,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,38215,64758,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,37456,N,N,N,N,35176,36278,64763,41085,39164,35177,N,N,
+N,N,N,N,N,N,65103,N,N,37462,N,N,N,N,N,N,N,N,N,N,64201,N,N,37864,N,N,N,64760,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40163,64937,N,N,N,N,N,N,64580,N,N,N,N,N,N,
+N,N,38464,N,N,36280,N,N,N,N,N,N,N,N,N,N,39754,36793,N,N,N,N,N,N,64766,N,N,N,N,
+N,N,N,35178,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36281,
+N,N,N,37246,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37876,N,N,N,N,N,N,N,N,N,N,N,N,N,
+64380,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37863,N,N,38895,N,N,N,65098,N,N,N,N,N,
+64837,N,38565,N,N,N,N,65248,64840,64839,65266,65130,N,N,N,N,N,36285,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,39841,36002,39607,36604,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40865,N,N,N,N,N,N,N,N,N,64849,N,N,N,N,N,N,N,64173,N,N,N,N,36286,N,N,35236,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,39641,N,N,N,N,N,N,N,N,N,N,N,64846,N,N,36288,N,N,38896,
+N,N,N,N,N,N,N,N,N,N,37812,64836,N,N,N,N,N,N,N,N,N,N,N,N,40871,N,N,N,N,36290,N,
+N,N,N,39350,N,N,N,N,N,N,N,N,N,N,N,N,N,64850,N,N,N,N,N,N,36289,N,N,36422,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,41169,N,N,N,N,N,N,N,N,N,N,N,N,N,40906,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,37583,N,N,N,40180,36292,N,N,N,N,N,N,N,N,N,N,64833,N,N,N,N,N,N,
+N,39756,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64855,64751,40158,N,N,N,N,N,N,N,64834,
+39020,N,N,N,N,N,N,N,N,N,N,N,N,N,38905,N,38232,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39006,65147,38093,N,N,N,N,N,37870,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36003,N,64858,
+N,N,N,N,N,N,37877,N,N,N,N,N,37871,36586,N,N,N,36699,N,N,N,N,N,N,N,N,N,N,N,
+35934,N,36294,N,N,N,N,N,N,N,N,N,N,N,36296,N,N,36295,N,N,N,N,N,37879,N,N,N,N,N,
+N,N,36297,N,N,N,N,N,N,N,64498,N,N,N,N,38512,N,N,N,N,N,N,N,N,N,36299,N,N,N,
+64860,N,N,N,N,N,N,N,N,N,36709,N,N,N,36301,N,N,N,N,N,40360,38137,N,N,36302,N,N,
+N,N,N,N,N,N,37866,N,N,N,N,N,N,N,N,N,64863,37872,40886,N,N,N,N,N,N,N,N,N,36303,
+N,N,N,38755,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36304,
+37873,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64866,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,64869,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,40923,N,N,N,N,37880,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35831,N,N,N,N,64870,N,N,N,N,N,35791,N,N,N,N,N,N,36305,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,36306,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,64881,N,N,N,N,64879,N,N,N,N,N,N,N,N,36307,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40935,37053,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40912,N,N,N,35792,N,64882,
+N,40110,35793,N,N,35547,N,N,N,N,N,N,N,N,N,N,N,64228,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,38350,N,64886,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64354,N,N,N,N,N,N,36308,
+N,N,N,64888,N,N,N,N,N,36579,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,36982,N,N,39110,N,N,N,N,N,N,N,36309,N,N,N,N,38865,N,N,40630,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64199,N,N,41026,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,39027,N,N,N,N,N,N,N,N,N,N,40956,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,36005,36311,N,N,37627,36312,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,37967,N,36313,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,35179,N,N,N,N,N,N,N,N,38862,N,N,N,64243,64942,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64431,37559,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+36314,N,N,N,N,N,N,N,N,N,N,N,N,N,40026,N,N,N,N,N,N,64941,N,N,N,N,N,N,N,N,N,N,N,
+N,N,36316,37956,N,N,N,N,N,N,N,N,N,N,N,36317,N,N,N,N,N,N,N,41174,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35905,38869,N,37962,N,N,N,N,N,
+37965,N,N,N,N,38859,N,N,N,N,N,36318,N,N,36319,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+36320,65273,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,64960,64761,N,N,N,N,N,N,36061,N,64382,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,37555,N,N,N,N,N,64943,N,N,N,N,N,N,N,N,N,36321,N,N,N,N,
+38355,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35265,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,64872,N,N,40119,N,N,36323,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,64192,36325,64100,N,35143,N,N,N,N,36324,N,N,N,N,N,36327,
+36328,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64967,64944,N,N,N,N,N,N,37957,38870,N,N,
+N,N,N,N,N,N,N,64710,38980,N,N,N,N,N,N,N,N,N,N,N,N,36329,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,36330,N,N,N,N,N,N,N,N,65104,N,N,N,N,N,N,64972,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,40359,N,N,N,N,N,64973,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+64975,N,N,N,N,38354,N,N,N,N,N,N,N,36333,N,N,N,N,N,N,N,N,64698,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,64965,N,64978,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40156,N,N,N,N,N,38351,N,N,36334,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64980,
+N,N,N,N,N,38636,38635,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+37046,N,64963,39083,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38638,
+N,N,N,N,N,N,N,N,N,N,N,N,N,36340,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,64992,N,35943,N,N,36342,N,N,N,36343,N,N,N,N,N,N,N,36858,N,N,N,N,
+N,N,N,N,N,N,38864,N,N,N,N,35794,N,N,36344,N,N,N,N,N,37081,N,35911,N,64240,N,N,
+N,N,64993,36345,N,64995,N,N,N,N,N,N,N,36346,N,64355,N,N,N,37030,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,39280,N,N,37355,N,38768,39023,64994,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,39154,N,39676,35180,65021,N,N,39262,N,N,N,38333,N,N,N,N,N,N,N,64996,
+N,N,N,37350,N,N,N,N,64997,64998,N,N,N,N,N,N,N,N,64999,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,37972,N,N,N,39352,N,N,N,N,N,N,N,N,38889,37702,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,39011,N,N,N,N,N,N,N,N,N,N,N,38332,N,65005,65015,N,N,N,
+N,N,N,39024,38646,36521,N,N,N,N,N,37969,N,N,36419,N,35674,N,N,N,N,65006,N,N,N,
+N,65008,N,N,N,N,65012,N,39925,N,N,N,N,N,36078,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,38782,N,N,N,N,N,39893,N,39619,N,38856,41179,37328,N,N,40932,N,36829,N,
+37353,N,N,N,N,N,N,N,N,N,39136,N,N,N,37578,N,38999,N,N,35921,N,N,N,N,65003,N,
+39753,N,N,N,N,N,N,N,N,N,40310,40623,N,N,N,N,N,N,N,N,N,40140,N,N,N,N,N,N,65002,
+N,N,36337,N,N,65019,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36435,N,N,N,N,
+N,N,N,N,N,N,N,64207,N,N,N,N,N,N,N,N,N,N,N,N,N,38649,N,N,N,N,N,N,N,N,N,39103,
+40521,36007,N,N,N,N,N,N,N,N,39882,N,N,N,N,65022,37596,N,N,N,N,N,65089,37324,
+37346,N,N,N,N,N,N,N,N,N,N,N,N,65092,34655,N,N,N,N,N,35795,N,N,65095,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,65096,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37973,N,N,N,N,
+65099,N,65100,N,N,N,N,36287,N,N,N,N,N,N,N,N,N,40568,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,65105,N,N,N,N,37974,N,N,N,N,N,N,N,40289,N,N,N,N,
+37975,N,N,N,N,N,N,N,N,N,N,39270,N,N,N,N,N,N,N,N,N,N,N,N,N,35797,N,N,N,N,41065,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39092,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,41033,41036,N,40549,N,N,N,N,N,N,N,N,N,N,N,39093,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65112,N,39285,65107,41061,N,65113,N,N,N,N,
+N,N,N,N,N,39095,39096,N,N,N,N,N,N,N,39098,N,N,N,N,N,N,39099,N,N,N,N,N,N,40892,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41034,N,N,
+40647,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36009,N,N,39086,N,N,N,N,N,
+N,N,N,37590,N,N,N,64225,N,37332,N,N,N,N,N,N,N,N,64222,N,N,65115,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,35923,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65118,N,N,N,N,64471,65114,
+38085,N,N,N,N,64202,N,N,N,N,N,N,N,N,N,N,N,39105,38748,N,65140,N,38771,N,N,N,N,
+N,N,N,N,64070,N,N,N,38756,N,N,N,65128,N,38478,N,38757,35930,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,35233,38394,N,37588,65129,N,64325,N,39112,N,N,37103,N,39113,39114,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37997,38071,65132,N,N,37995,N,N,N,
+N,N,N,37628,N,38379,N,65139,38766,65119,N,N,N,N,N,N,N,N,N,64957,N,N,37589,N,N,
+N,N,N,N,65209,N,N,65137,34680,N,N,N,64443,N,N,38010,N,N,38395,65143,N,N,N,N,N,
+N,N,65145,N,65141,N,N,N,37981,N,N,N,N,N,N,N,65148,N,N,N,N,N,N,N,N,N,37700,
+36518,N,N,N,N,N,N,N,N,N,N,N,37587,N,38072,N,34681,N,N,N,N,N,N,64625,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,38750,N,N,N,N,36013,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65191,N,N,
+N,37994,N,N,N,37859,N,N,39119,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41177,N,N,
+N,N,N,N,N,N,41151,41037,41144,N,N,N,N,N,41166,41143,N,N,N,N,N,N,N,N,65193,N,N,
+N,N,N,N,N,N,N,N,35267,N,N,N,N,65195,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40436,35181,N,N,N,N,N,40059,N,N,N,N,N,N,39122,N,N,N,40873,N,N,N,65202,N,N,
+65201,N,N,N,38873,N,41156,N,38006,N,N,N,N,N,N,N,N,N,N,39288,N,N,N,N,N,N,65203,
+N,N,N,N,N,39123,65204,N,N,N,39124,N,N,N,N,N,N,N,40889,N,N,N,N,N,N,N,N,38001,N,
+N,N,N,N,N,N,N,N,39125,65208,N,N,N,50900,N,N,N,N,N,N,N,N,N,N,N,65210,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,40540,N,N,65211,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41028,N,
+N,N,N,39127,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39128,65212,N,N,N,N,40958,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65213,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,40413,N,N,N,N,40673,N,N,N,N,N,N,N,N,N,N,N,N,39130,
+40415,65215,N,65214,N,N,40683,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40537,41052,N,
+N,N,N,N,N,N,65216,N,N,N,38007,39132,N,65217,N,N,N,39134,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,65219,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65224,N,N,N,65225,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65226,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+65227,N,N,N,N,N,N,N,N,N,40898,N,N,35947,39108,N,38064,38065,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,65233,N,N,N,N,N,41153,N,65234,N,N,N,N,41165,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,65235,N,N,39141,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65238,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37348,N,N,N,N,36807,38062,N,
+35407,38066,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36820,N,N,N,N,39146,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65240,N,N,N,N,N,N,N,N,N,40416,N,N,
+N,N,39150,N,N,N,N,38340,N,64744,N,N,N,N,N,39151,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,35950,N,N,N,N,N,N,N,N,64216,N,N,N,N,N,N,N,N,N,N,N,N,N,65244,N,N,N,N,N,N,N,
+N,N,41134,40268,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39153,N,N,N,39155,N,38081,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39157,N,N,64079,38626,N,N,N,N,
+37968,N,38562,N,N,39158,N,N,N,38629,N,N,N,N,N,39159,N,41030,38627,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,39160,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40676,N,N,N,
+N,N,N,63958,N,N,N,N,N,N,38083,N,N,N,N,38082,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65249,N,65257,N,N,N,N,38628,N,35244,38619,N,N,
+N,N,N,N,N,N,N,N,N,N,N,65250,N,N,N,N,N,N,N,N,N,N,38084,65251,N,N,N,65255,40955,
+N,N,N,N,N,N,N,N,N,N,N,35929,N,N,N,N,N,N,N,N,N,37833,N,38120,64342,N,N,N,37061,
+41128,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,65253,N,N,N,39165,39163,65256,N,36543,N,N,N,N,35800,65271,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36712,38086,N,N,N,N,N,N,N,N,40426,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,64617,N,N,N,N,N,N,N,N,N,N,N,N,40154,N,65267,N,N,40050,
+N,N,65264,35273,N,N,N,N,N,N,N,N,N,39233,N,N,N,N,N,N,N,39234,N,N,N,65269,N,
+37335,N,N,N,N,N,38092,N,N,N,65272,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,38824,N,65276,N,N,N,36062,N,64959,N,N,N,N,N,N,N,65278,N,N,N,N,N,N,N,N,
+N,N,N,N,N,38609,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38101,N,N,38096,39236,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35939,N,N,41139,N,N,
+N,N,N,N,N,N,N,N,N,N,38095,N,N,N,40954,N,N,N,N,37349,N,40042,N,N,N,36425,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36428,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,36429,N,N,N,N,N,39539,N,N,N,N,N,N,N,N,N,N,N,N,N,39239,N,
+36017,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36432,N,N,N,N,N,
+N,N,N,N,N,36431,39241,N,N,N,N,N,36433,36434,N,N,N,N,39602,35237,N,N,N,N,N,
+39244,N,N,N,40952,N,N,N,N,N,N,36438,39245,37322,36439,N,N,N,N,38113,N,N,N,N,
+36935,N,36824,36440,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38123,36444,38227,N,
+N,N,N,N,N,N,40933,N,N,N,N,N,N,N,N,N,N,40790,N,N,N,N,N,N,N,38223,N,36446,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,39274,N,N,N,N,N,N,N,N,40036,40153,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,36445,N,N,N,N,N,N,N,N,N,N,N,N,39248,N,N,N,N,N,N,N,N,N,39249,N,N,
+36450,N,N,N,N,N,N,N,N,N,N,N,39250,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+36456,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36449,40793,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35763,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40797,36454,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36018,N,N,N,N,N,N,N,N,N,N,N,
+N,N,36462,N,40804,39251,N,N,64184,N,N,N,N,N,39252,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,36464,N,N,N,N,N,N,N,N,N,N,N,N,40801,N,36466,N,N,N,N,N,N,
+N,N,N,N,N,N,41067,N,N,N,N,40768,N,N,N,N,N,N,38125,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,38126,N,N,40893,N,N,N,36475,N,N,N,N,N,N,39255,38135,N,40799,N,N,N,N,36467,N,
+N,40802,N,N,N,N,N,N,N,38134,N,N,N,N,N,N,N,N,N,N,N,N,N,39256,N,N,N,N,N,N,N,N,N,
+36469,63963,N,N,N,N,36978,N,38136,N,N,N,N,N,N,N,N,N,39258,N,N,N,N,N,N,N,N,N,
+41136,36019,N,N,N,36473,N,36472,N,N,N,38131,N,N,N,N,N,39087,N,N,N,N,N,N,41138,
+N,N,N,N,N,N,N,N,N,N,N,36474,N,N,N,N,N,N,39260,N,N,N,N,N,36476,N,36477,N,N,N,
+35801,N,N,35234,40663,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,41142,N,N,N,N,N,N,N,N,N,N,N,N,40514,N,N,36516,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-36306,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64881,N,N,N,N,64879,
-N,N,N,N,N,N,N,N,36307,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40935,37053,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,40912,N,N,N,35792,N,64882,N,40110,35793,N,N,35547,N,
-N,N,N,N,N,N,N,N,N,N,64228,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38350,N,64886,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,64354,N,N,N,N,N,N,36308,N,N,N,64888,N,N,N,N,N,
-36579,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36982,N,N,
-39110,N,N,N,N,N,N,N,36309,N,N,N,N,38865,N,N,40630,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,64199,N,N,41026,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39027,N,N,
-N,N,N,N,N,N,N,N,40956,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36005,36311,N,N,
-37627,36312,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37967,N,
-36313,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,35179,N,N,N,N,N,N,N,N,38862,N,N,N,64243,64942,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,64431,37559,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36314,N,N,N,N,N,N,N,N,N,
-N,N,N,N,40026,N,N,N,N,N,N,64941,N,N,N,N,N,N,N,N,N,N,N,N,N,36316,37956,N,N,N,N,
-N,N,N,N,N,N,N,36317,N,N,N,N,N,N,N,41174,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,35905,38869,N,37962,N,N,N,N,N,37965,N,N,N,N,38859,N,N,N,N,
-N,36318,N,N,36319,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36320,65273,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64960,64761,N,N,N,N,N,
-N,N,N,64382,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37555,N,N,
-N,N,N,64943,N,N,N,N,N,N,N,N,N,36321,N,N,N,N,38355,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-35265,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64872,N,N,40119,N,N,
-36323,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64192,36325,
-64100,N,35143,N,N,N,N,36324,N,N,N,N,N,36327,36328,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,64967,64944,N,N,N,N,N,N,37957,38870,N,N,N,N,N,N,N,N,N,64710,38980,N,N,N,N,
-N,N,N,N,N,N,N,N,36329,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36330,N,N,N,N,N,N,N,N,
-65104,N,N,N,N,N,N,64972,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40359,N,N,N,N,N,
-64973,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64975,N,N,N,N,38354,N,N,N,
-N,N,N,N,36333,N,N,N,N,N,N,N,N,64698,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64965,
-N,64978,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40156,N,N,N,N,N,38351,N,N,
-36334,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64980,N,N,N,N,N,38636,38635,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37046,N,64963,39083,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38638,N,N,N,N,N,N,N,N,N,N,N,N,N,
-36340,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64992,N,
-35943,N,N,36342,N,N,N,36343,N,N,N,N,N,N,N,36858,N,N,N,N,N,N,N,N,N,N,38864,N,N,
-N,N,35794,N,N,36344,N,N,N,N,N,37081,N,35911,N,64240,N,N,N,N,64993,36345,N,
-64995,N,N,N,N,N,N,N,36346,N,64355,N,N,N,37030,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-39280,N,N,37355,N,38768,39023,64994,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39154,N,
-39676,35180,65021,N,N,39262,N,N,N,38333,N,N,N,N,N,N,N,64996,N,N,N,37350,N,N,N,
-N,64997,64998,N,N,N,N,N,N,N,N,64999,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37972,N,
-N,N,39352,N,N,N,N,N,N,N,N,38889,37702,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,39011,N,N,N,N,N,N,N,N,N,N,N,38332,N,65005,65015,N,N,N,N,N,N,39024,38646,
-36521,N,N,N,N,N,37969,N,N,36419,N,35674,N,N,N,N,65006,N,N,N,N,65008,N,N,N,N,
-65012,N,39925,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38782,N,N,N,N,
-N,39893,N,39619,N,38856,41179,37328,N,N,40932,N,36829,N,37353,N,N,N,N,N,N,N,N,
-N,39136,N,N,N,37578,N,38999,N,N,35921,N,N,N,N,65003,N,39753,N,N,N,N,N,N,N,N,N,
-40310,40623,N,N,N,N,N,N,N,N,N,40140,N,N,N,N,N,N,65002,N,N,36337,N,N,65019,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36435,N,N,N,N,N,N,N,N,N,N,N,64207,N,N,
-N,N,N,N,N,N,N,N,N,N,N,38649,N,N,N,N,N,N,N,N,N,39103,40521,36007,N,N,N,N,N,N,N,
-N,39882,N,N,N,N,65022,37596,N,N,N,N,N,65089,37324,37346,N,N,N,N,N,N,N,N,N,N,N,
-N,65092,N,N,N,N,N,N,35795,N,N,65095,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65096,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,37973,N,N,N,N,65099,N,65100,N,N,N,N,36287,N,N,N,N,
-N,N,N,N,N,40568,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65105,N,
-N,N,N,37974,N,N,N,N,N,N,N,40289,N,N,N,N,37975,N,N,N,N,N,N,N,N,N,N,39270,N,N,N,
-N,N,N,N,N,N,N,N,N,N,35797,N,N,N,N,41065,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,39092,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41033,41036,N,
-40549,N,N,N,N,N,N,N,N,N,N,N,39093,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,65112,N,39285,65107,41061,N,65113,N,N,N,N,N,N,N,N,N,39095,39096,N,N,N,N,N,N,
-N,39098,N,N,N,N,N,N,39099,N,N,N,N,N,N,40892,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41034,N,N,40647,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,36009,N,N,39086,N,N,N,N,N,N,N,N,37590,N,N,N,64225,N,37332,N,N,
-N,N,N,N,N,N,64222,N,N,65115,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35923,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,65118,N,N,N,N,64471,65114,38085,N,N,N,N,64202,N,N,N,N,N,N,N,N,N,
-N,N,39105,38748,N,65140,N,38771,N,N,N,N,N,N,N,N,64070,N,N,N,38756,N,N,N,65128,
-N,38478,N,38757,35930,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35233,38394,N,37588,65129,N,
-64325,N,39112,N,N,37103,N,39113,39114,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,37997,38071,65132,N,N,37995,N,N,N,N,N,N,37628,N,38379,N,65139,38766,
-65119,N,N,N,N,N,N,N,N,N,64957,N,N,37589,N,N,N,N,N,N,65209,N,N,65137,N,N,N,N,
-64443,N,N,38010,N,N,38395,65143,N,N,N,N,N,N,N,65145,N,65141,N,N,N,37981,N,N,N,
-N,N,N,N,65148,N,N,N,N,N,N,N,N,N,37700,36518,N,N,N,N,N,N,N,N,N,N,N,37587,N,
-38072,N,N,N,N,N,N,N,N,64625,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38750,N,N,N,N,36013,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,65191,N,N,N,37994,N,N,N,37859,N,N,39119,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,41177,N,N,N,N,N,N,N,N,41151,41037,41144,N,N,N,N,N,
-41166,41143,N,N,N,N,N,N,N,N,65193,N,N,N,N,N,N,N,N,N,N,35267,N,N,N,N,65195,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40436,35181,N,N,N,N,N,40059,N,N,N,N,N,N,
-39122,N,N,N,40873,N,N,N,65202,N,N,65201,N,N,N,38873,N,41156,N,38006,N,N,N,N,N,
-N,N,N,N,N,39288,N,N,N,N,N,N,65203,N,N,N,N,N,39123,65204,N,N,N,39124,N,N,N,N,N,
-N,N,40889,N,N,N,N,N,N,N,N,38001,N,N,N,N,N,N,N,N,N,39125,65208,N,N,N,50900,N,N,
-N,N,N,N,N,N,N,N,N,65210,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40540,N,N,65211,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,41028,N,N,N,N,39127,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,39128,65212,N,N,N,N,40958,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,65213,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40413,N,N,N,N,
-40673,N,N,N,N,N,N,N,N,N,N,N,N,39130,40415,65215,N,65214,N,N,40683,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,40537,41052,N,N,N,N,N,N,N,65216,N,N,N,38007,39132,N,
-65217,N,N,N,39134,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65219,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,65224,N,N,N,65225,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65226,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65227,N,N,N,N,N,N,N,N,N,40898,N,N,
-35947,39108,N,38064,38065,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65233,N,N,N,N,N,41153,N,
-65234,N,N,N,N,41165,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65235,N,N,39141,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65238,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,37348,N,N,N,N,36807,38062,N,35407,38066,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,36820,N,N,N,N,39146,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,65240,N,N,N,N,N,N,N,N,N,40416,N,N,N,N,39150,N,N,N,N,38340,N,64744,N,
-N,N,N,N,39151,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35950,N,N,N,N,N,N,N,N,64216,N,
-N,N,N,N,N,N,N,N,N,N,N,N,65244,N,N,N,N,N,N,N,N,N,41134,40268,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,39153,N,N,N,39155,N,38081,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,39157,N,N,64079,38626,N,N,N,N,37968,N,38562,N,N,39158,N,N,N,38629,
-N,N,N,N,N,39159,N,41030,38627,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39160,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40676,N,N,N,N,N,N,63958,N,N,N,N,N,N,38083,N,N,N,
-N,38082,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-65249,N,65257,N,N,N,N,38628,N,35244,38619,N,N,N,N,N,N,N,N,N,N,N,N,N,65250,N,N,
-N,N,N,N,N,N,N,N,38084,65251,N,N,N,65255,40955,N,N,N,N,N,N,N,N,N,N,N,35929,N,N,
-N,N,N,N,N,N,N,37833,N,38120,64342,N,N,N,37061,41128,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65253,N,N,N,39165,39163,
-65256,N,36543,N,N,N,N,35800,65271,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,36712,38086,N,N,N,N,N,N,N,N,40426,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64617,
-N,N,N,N,N,N,N,N,N,N,N,N,40154,N,65267,N,N,40050,N,N,65264,35273,N,N,N,N,N,N,N,
-N,N,39233,N,N,N,N,N,N,N,39234,N,N,N,65269,N,37335,N,N,N,N,N,38092,N,N,N,65272,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38824,N,65276,N,N,N,N,N,
-64959,N,N,N,N,N,N,N,65278,N,N,N,N,N,N,N,N,N,N,N,N,N,38609,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,38101,N,N,38096,39236,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,35939,N,N,41139,N,N,N,N,N,N,N,N,N,N,N,N,38095,N,N,N,
-40954,N,N,N,N,37349,N,40042,N,N,N,36425,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,36428,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36429,N,N,
-N,N,N,39539,N,N,N,N,N,N,N,N,N,N,N,N,N,39239,N,36017,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36432,N,N,N,N,N,N,N,N,N,N,36431,39241,N,N,N,N,N,
-36433,36434,N,N,N,N,39602,35237,N,N,N,N,N,39244,N,N,N,40952,N,N,N,N,N,N,36438,
-39245,37322,36439,N,N,N,N,38113,N,N,N,N,36935,N,36824,36440,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,38123,36444,38227,N,N,N,N,N,N,N,40933,N,N,N,N,N,N,N,N,N,N,
-40790,N,N,N,N,N,N,N,38223,N,36446,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39274,N,N,N,N,
-N,N,N,N,40036,40153,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36445,N,N,N,N,N,N,N,N,N,
-N,N,N,39248,N,N,N,N,N,N,N,N,N,39249,N,N,36450,N,N,N,N,N,N,N,N,N,N,N,39250,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36456,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-36449,40793,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35763,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,40797,36454,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,36018,N,N,N,N,N,N,N,N,N,N,N,N,N,36462,N,40804,39251,N,N,64184,N,N,
-N,N,N,39252,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36464,N,N,N,N,N,
-N,N,N,N,N,N,N,40801,N,36466,N,N,N,N,N,N,N,N,N,N,N,N,41067,N,N,N,N,40768,N,N,N,
-N,N,N,38125,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38126,N,N,40893,N,N,N,36475,N,N,N,N,
-N,N,39255,38135,N,40799,N,N,N,N,36467,N,N,40802,N,N,N,N,N,N,N,38134,N,N,N,N,N,
-N,N,N,N,N,N,N,N,39256,N,N,N,N,N,N,N,N,N,36469,63963,N,N,N,N,36978,N,38136,N,N,
-N,N,N,N,N,N,N,39258,N,N,N,N,N,N,N,N,N,41136,36019,N,N,N,36473,N,36472,N,N,N,
-38131,N,N,N,N,N,39087,N,N,N,N,N,N,41138,N,N,N,N,N,N,N,N,N,N,N,36474,N,N,N,N,N,
-N,39260,N,N,N,N,N,36476,N,36477,N,N,N,35801,N,N,35234,40663,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41142,N,N,N,N,N,N,
-N,N,N,N,N,N,40514,N,N,36516,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36519,N,35958,N,N,N,N,N,N,N,N,N,N,N,38210,
-N,N,N,N,N,N,N,N,N,N,N,N,39037,N,N,N,38741,N,N,36520,N,N,N,N,N,N,N,36522,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35235,N,39264,39266,N,N,38140,
-39265,N,N,N,N,N,N,N,38138,N,N,N,N,N,N,N,36526,36530,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,36528,N,N,N,N,N,N,N,39267,38826,38139,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,36539,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36060,N,N,N,N,N,N,N,N,
-N,39030,N,36513,N,N,N,N,36020,N,36535,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40358,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,40624,N,N,N,36536,N,N,N,N,N,N,N,N,N,N,N,N,40304,N,N,
-N,N,35182,N,N,N,N,N,N,N,35183,N,N,N,N,N,N,N,N,N,N,N,N,N,35184,N,N,N,N,N,N,N,N,
-N,N,N,N,35185,N,N,N,N,N,N,N,35186,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35187,35188,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,35189,N,N,N,N,N,N,N,N,36540,36541,N,N,N,N,N,36542,N,40401,N,N,
-N,N,38141,N,N,N,35799,35802,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,41186,N,N,N,N,N,N,40937,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64936,N,N,N,35559,N,N,N,36546,N,N,N,N,N,N,N,N,N,N,N,36548,N,N,N,N,N,N,N,N,N,N,
-39268,N,N,N,N,N,39269,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,38222,N,N,N,N,N,N,N,N,N,39091,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,36555,35807,N,N,N,N,N,36558,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,36559,N,N,39272,N,N,N,N,39273,N,N,N,N,N,N,N,N,39275,36561,N,39276,N,N,N,N,N,
-N,N,N,N,36564,36565,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39277,N,N,N,
-N,N,N,41150,N,N,N,N,N,36566,41148,41141,N,N,41140,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,35808,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,35253,N,N,N,N,N,N,N,36573,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40541,39281,N,
-N,N,N,35246,40424,N,N,N,N,N,N,N,N,38245,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39282,N,N,35676,N,N,N,N,N,N,N,N,N,35249,41152,N,
-N,N,36575,N,38246,N,N,39284,N,39286,N,N,N,39287,N,39289,N,N,40410,N,N,36576,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,37724,N,N,N,N,N,N,N,40422,N,35679,N,N,38243,N,N,N,
-N,N,N,N,N,N,N,38247,N,N,N,N,N,40419,N,N,N,N,N,N,N,N,N,N,N,N,N,39292,N,N,39293,
-39294,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35675,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-39331,N,N,N,N,N,N,N,39332,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39334,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,39336,N,N,N,N,35518,N,N,N,N,N,N,N,N,N,N,N,40545,N,N,N,N,N,N,N,
-N,N,N,39338,N,N,N,N,N,N,41160,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,39339,N,N,N,N,N,N,N,N,N,N,65220,N,N,N,N,N,N,39106,36584,N,41146,N,N,N,N,
-N,N,N,N,N,N,N,64887,N,N,36590,N,N,N,40639,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-35266,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39340,N,N,N,N,N,N,N,N,N,N,N,N,
-N,38251,N,N,38252,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39343,N,N,39242,35190,36680,
-N,N,N,N,N,N,N,N,N,N,N,64494,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,39342,N,N,N,36603,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36048,N,N,
-N,N,35666,N,N,N,N,N,39344,N,N,N,N,35191,36673,N,N,N,N,N,N,N,39345,N,N,N,N,N,N,
-N,N,N,36681,N,N,N,N,N,N,N,N,N,N,N,64077,N,N,N,N,N,N,N,N,40420,36021,N,N,N,
-64489,39764,N,39346,40552,N,N,N,N,N,N,N,N,N,N,N,N,36682,N,36674,N,N,36689,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38982,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39348,N,N,N,N,N,N,N,N,N,N,36597,64853,N,N,
-40141,N,N,N,N,N,N,N,N,35192,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36691,N,
-N,N,N,N,N,N,N,N,N,N,36719,N,N,N,N,N,N,N,N,N,N,36451,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,36694,N,N,N,N,N,N,N,N,N,N,N,N,65142,N,N,N,N,40902,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,64172,N,N,N,N,N,36696,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-38984,39351,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38501,N,64108,N,40423,N,N,N,40546,N,N,
-N,38604,36455,N,N,64629,N,39038,N,N,N,N,N,N,N,64953,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,38908,N,N,N,N,N,N,N,N,N,39161,N,36710,N,N,N,N,N,N,N,N,38254,N,37445,N,N,
-36704,N,N,N,40657,N,N,N,N,N,65229,N,39353,N,N,N,N,N,N,N,N,N,N,N,N,36706,38732,
-N,N,N,N,N,N,N,N,N,N,N,N,37319,38239,N,N,N,N,N,N,N,39355,N,N,N,N,N,N,N,N,N,
-36461,36721,N,N,38091,N,N,N,N,N,N,N,N,N,N,N,N,38321,N,N,N,N,N,N,N,N,N,39666,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,38595,39357,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,41167,N,N,N,36717,N,N,39358,36596,N,36722,38372,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,39359,37442,N,64421,N,N,N,N,N,N,N,N,N,N,39360,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64948,36727,N,N,N,
-39361,N,N,N,N,N,N,N,N,N,64185,N,N,N,N,N,N,N,N,36672,64068,N,N,N,N,N,39362,N,N,
-N,N,N,N,N,36700,N,N,N,N,36029,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39364,39365,N,N,
-36731,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-36022,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,36771,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36046,N,N,N,N,N,N,N,N,
-N,39366,N,N,N,N,N,N,N,N,N,N,N,N,N,38605,N,N,N,N,N,N,N,N,N,N,N,N,N,38599,36773,
-N,N,N,N,N,N,N,N,N,N,64187,N,35937,38256,N,N,N,37736,N,36734,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,36778,N,N,N,N,N,N,41040,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-37075,N,N,38230,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,36792,N,N,N,N,N,39368,N,N,N,N,N,N,N,N,N,N,N,36783,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,39369,N,N,N,N,N,N,N,N,N,N,N,N,N,38265,N,N,N,N,N,N,N,N,
-N,N,N,N,40777,N,N,N,N,39370,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39371,
-40405,36784,N,N,N,N,N,N,N,N,N,N,N,64122,N,N,N,N,N,N,N,N,40543,N,N,N,N,39373,
-41161,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39643,N,N,N,41158,N,N,N,
-N,N,N,N,36788,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41175,N,N,N,N,N,N,N,N,N,N,N,N,
-41159,N,N,N,N,N,N,N,41027,N,N,N,36789,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-36786,N,N,N,N,N,N,41057,40542,N,N,N,N,N,N,N,N,N,N,36790,N,N,N,N,N,N,N,N,40936,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,40114,N,N,N,N,N,38268,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,40903,N,N,36795,36796,N,N,N,N,N,N,N,N,36844,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,36800,N,37738,N,N,N,35812,40060,N,N,N,N,N,N,N,N,38305,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,65260,N,N,38307,N,N,N,N,N,N,N,35909,36024,N,N,N,N,N,N,
-N,N,N,N,N,36801,N,N,N,41042,N,N,N,N,N,N,N,N,N,N,N,N,N,39376,N,N,N,N,N,36803,
-36804,N,N,N,N,N,N,N,N,N,38308,N,N,N,N,N,36806,N,40544,N,N,N,N,N,N,N,63960,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38309,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-40115,N,N,N,N,N,N,N,N,N,39377,65265,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,39378,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,40130,N,N,N,39379,N,N,N,N,N,38311,N,N,N,N,N,N,38313,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,38310,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40029,N,N,N,N,N,
-N,N,N,39138,N,N,N,N,N,N,36809,N,41154,36810,N,N,N,N,N,N,39380,N,N,41145,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,39768,N,36813,N,41172,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,36814,N,N,N,N,35813,N,N,N,N,35193,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,36816,38326,N,N,N,N,N,N,N,N,N,N,N,N,39382,N,38373,N,
-N,N,N,N,N,N,N,N,N,N,N,39383,N,N,N,N,38325,N,N,N,N,N,N,N,N,N,N,N,41162,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40957,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,41048,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36822,N,N,N,
-39384,N,N,N,N,N,N,N,36819,N,N,N,N,N,N,N,N,N,N,N,N,36837,N,N,N,N,N,36841,N,N,N,
-N,39385,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,37500,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40005,36830,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,36831,N,N,N,N,N,N,N,N,N,N,N,N,N,41035,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,36834,N,N,N,41164,N,N,N,N,N,N,N,N,36835,36836,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,39876,N,N,N,39932,N,N,N,N,N,N,38476,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,39670,N,36014,N,N,N,N,N,N,N,N,N,N,N,N,36839,N,N,N,N,N,N,N,N,N,N,36840,
-N,N,N,N,35815,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35194,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35195,
-39386,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+36519,N,35958,N,N,N,N,N,N,N,N,N,34663,N,38210,N,N,N,N,N,N,N,N,N,N,N,N,39037,N,
+N,N,38741,N,N,36520,N,N,N,N,N,N,N,36522,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,35235,N,39264,39266,N,N,38140,39265,N,N,N,N,N,N,N,38138,N,N,N,N,N,
+N,N,36526,36530,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36528,N,N,N,N,N,N,N,39267,38826,
+38139,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36539,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,36060,N,N,N,N,N,N,N,N,N,39030,N,36513,N,N,N,N,36020,N,
+36535,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40358,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40624,
+N,N,N,36536,N,N,N,N,N,N,N,N,N,N,N,N,40304,N,N,N,N,35182,N,N,N,N,N,N,N,35183,N,
+N,N,N,N,N,N,N,N,N,N,N,N,35184,N,N,N,N,N,N,N,N,N,N,N,N,35185,N,N,N,N,N,N,N,
+35186,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35187,35188,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35189,N,N,N,
+N,N,N,N,N,36540,36541,N,N,N,N,N,36542,N,40401,N,N,N,N,38141,N,N,N,35799,35802,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41186,N,N,N,N,N,N,
+40937,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64936,N,N,N,35559,N,N,N,
+36546,N,N,N,N,N,N,N,N,N,N,N,36548,N,N,N,N,N,N,N,N,N,N,39268,N,N,N,N,N,39269,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+38222,N,N,N,N,N,N,N,N,N,39091,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36555,35807,
+N,N,N,N,N,36558,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36559,N,N,39272,N,N,N,
+N,39273,N,N,N,N,N,N,N,N,39275,36561,N,39276,N,N,N,N,N,N,N,N,N,36564,36565,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39277,N,N,N,N,N,N,41150,N,N,N,N,N,
+36566,41148,41141,N,N,41140,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35808,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35253,N,N,N,
+N,N,N,N,36573,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40541,39281,N,N,N,N,35246,40424,N,N,
+N,N,N,N,N,N,38245,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,39282,N,N,35676,N,N,N,N,N,N,N,N,N,35249,41152,N,N,N,36575,N,38246,N,N,
+39284,N,39286,N,N,N,39287,N,39289,N,N,40410,N,N,36576,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,37724,N,N,N,N,N,N,N,40422,N,35679,N,N,38243,N,N,N,N,N,N,N,N,N,N,38247,N,
+N,N,N,N,40419,N,N,N,N,N,N,N,N,N,N,N,N,N,39292,N,N,39293,39294,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,36091,35675,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39331,N,N,N,N,N,N,N,
+39332,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39334,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39336,N,N,N,N,35518,N,N,N,N,N,N,N,N,N,N,N,40545,N,N,N,N,N,N,N,N,N,N,39338,N,N,
+N,N,N,N,41160,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39339,N,N,
+N,N,N,N,N,N,N,N,65220,N,N,N,N,N,N,39106,36584,N,41146,N,N,N,N,N,N,N,N,N,N,N,
+64887,N,N,36590,N,N,N,40639,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35266,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39340,N,N,N,N,N,N,N,N,N,N,N,N,N,38251,N,N,38252,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39343,N,N,39242,35190,36680,N,N,N,N,N,N,N,N,N,
+N,N,64494,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39342,N,
+N,N,36603,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36048,N,N,N,N,35666,N,N,N,N,
+N,39344,N,N,N,N,35191,36673,N,N,N,N,N,N,N,39345,N,N,N,N,N,N,N,N,N,36681,N,N,N,
+N,N,N,N,N,N,N,N,64077,N,N,N,N,N,N,N,N,40420,36021,N,N,N,64489,39764,N,39346,
+40552,N,N,N,N,N,N,N,N,N,N,N,N,36682,N,36674,N,N,36689,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38982,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,39348,N,N,N,N,N,N,N,N,N,N,36597,64853,N,N,40141,N,N,N,N,N,N,N,
+N,35192,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36691,N,N,N,N,N,N,N,N,N,N,N,
+36719,N,N,N,N,N,N,N,N,N,N,36451,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36694,N,N,N,N,N,
+N,N,N,N,N,N,N,65142,N,N,N,N,40902,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64172,N,N,N,N,N,
+36696,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38984,39351,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,38501,N,64108,N,40423,N,N,N,40546,N,N,N,38604,36455,N,N,
+64629,N,39038,N,N,N,N,N,N,N,64953,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38908,N,N,N,N,
+N,N,N,N,N,39161,N,36710,N,N,N,N,N,N,N,N,38254,N,37445,N,N,36704,N,N,N,40657,N,
+N,N,N,N,65229,N,39353,N,N,N,N,N,N,N,N,N,N,N,N,36706,38732,N,N,N,N,N,N,N,N,N,N,
+N,N,37319,38239,N,N,N,N,N,N,N,39355,N,N,N,N,N,N,N,N,N,36461,36721,N,N,38091,N,
+N,N,N,N,N,N,N,N,N,N,N,38321,N,N,N,N,N,N,N,N,N,39666,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,38595,39357,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41167,N,
+N,N,36717,N,N,39358,36596,N,36722,38372,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39359,37442,N,64421,N,N,N,N,N,N,N,N,N,N,39360,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64948,36727,N,N,N,39361,N,N,N,N,N,N,N,N,N,
+64185,N,N,N,N,N,N,N,N,36672,64068,N,N,N,N,N,39362,N,N,N,N,N,N,N,36700,N,N,N,N,
+36029,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39364,39365,N,N,36731,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34678,N,N,N,36022,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36771,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36046,N,N,N,N,N,N,N,N,N,39366,N,N,N,N,N,N,N,N,
+N,N,N,N,N,38605,N,N,N,N,N,N,N,N,N,N,N,N,N,38599,36773,N,N,N,N,N,N,N,N,N,N,
+64187,N,35937,38256,N,N,N,37736,N,36734,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+36778,N,N,N,N,N,N,41040,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37075,N,N,38230,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-36845,N,N,N,38336,N,N,N,N,N,N,N,N,N,N,N,N,N,41163,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40520,N,N,N,N,N,N,39387,N,36851,N,N,N,N,
-36857,N,N,N,N,N,N,N,N,N,N,N,N,N,38337,N,41038,N,N,N,N,N,N,39388,N,N,N,N,41060,
-36855,N,N,N,N,N,N,N,35248,41032,N,N,N,N,36859,36854,N,N,N,N,N,40412,N,N,N,
-39389,35816,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37569,N,N,N,N,N,N,N,40918,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41170,N,N,36928,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35524,N,N,39392,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,40944,40947,N,N,N,N,N,N,N,N,N,N,N,N,40383,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,40950,N,38344,N,N,40538,N,N,N,N,N,N,N,N,N,N,N,N,39395,
-N,N,N,N,N,N,N,N,N,N,N,35402,N,N,N,N,N,N,N,N,40945,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,35495,N,N,N,N,N,N,N,N,39398,N,N,N,40951,N,40941,N,N,N,N,N,
-N,35420,N,40366,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,38345,N,N,N,N,N,36936,N,N,39400,N,N,N,N,N,36937,N,N,36026,N,N,
-37041,N,N,N,N,N,N,36938,N,N,N,N,N,N,N,N,N,N,39402,N,N,N,N,N,N,N,N,N,N,N,39889,
-N,N,N,N,N,N,N,39403,N,39404,N,N,N,N,N,N,N,N,39405,N,N,N,N,39406,36940,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36941,N,N,38347,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-38882,N,N,N,N,N,N,N,N,38348,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40824,N,N,N,N,N,
-N,N,N,N,35196,35197,N,N,N,N,N,N,35198,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39261,N,N,N,N,N,N,N,N,N,N,N,N,39770,N,N,N,N,
-36944,N,35919,N,N,N,N,N,N,N,N,N,N,N,36948,N,50902,39592,39407,65259,40355,
+36792,N,N,N,N,N,39368,N,N,N,N,N,N,N,N,N,N,N,36783,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,39369,N,N,N,N,N,N,N,N,N,N,N,N,N,38265,N,N,N,N,N,N,N,N,N,N,N,N,40777,
+N,N,N,N,39370,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39371,40405,36784,N,N,
+N,N,N,N,N,N,N,N,N,64122,N,N,N,N,N,N,N,N,40543,N,N,N,N,39373,41161,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39643,N,N,N,41158,N,N,N,N,N,N,N,36788,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,41175,N,N,N,N,N,N,N,N,N,N,N,N,41159,N,N,N,N,N,N,N,
+41027,N,N,N,36789,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36786,N,N,N,N,N,N,
+41057,40542,N,N,N,N,N,N,N,N,N,N,36790,N,N,N,N,N,N,N,N,40936,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,40114,N,N,N,N,N,38268,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40903,
+N,N,36795,36796,N,N,N,N,N,N,N,N,36844,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36800,N,
+37738,N,N,N,35812,40060,N,N,N,N,N,N,N,N,38305,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,65260,N,N,38307,N,N,N,N,N,N,N,35909,36024,N,N,N,N,N,N,N,N,N,N,N,
+36801,N,N,N,41042,N,N,N,N,N,N,N,N,N,N,N,N,N,39376,N,N,N,N,N,36803,36804,N,N,N,
+N,N,N,N,N,N,38308,N,N,N,N,N,36806,N,40544,N,N,N,N,N,N,N,63960,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,38309,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40115,N,N,N,N,N,
+N,N,N,N,39377,65265,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,39378,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40130,N,N,N,39379,N,N,N,N,N,38311,N,N,N,N,N,N,38313,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,38310,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40029,N,N,N,N,N,N,N,N,39138,N,N,
+N,N,N,N,36809,N,41154,36810,N,N,N,N,N,N,39380,N,N,41145,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,39768,N,36813,N,41172,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36814,N,N,
+N,N,35813,N,N,N,N,35193,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,36816,38326,N,N,N,N,N,N,N,N,N,N,N,N,39382,N,38373,N,N,N,N,N,N,N,N,N,
+N,N,N,39383,N,N,N,N,38325,N,N,N,N,N,N,N,N,N,N,N,41162,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40957,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,41048,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36822,N,N,N,39384,N,N,N,N,N,N,N,
+36819,N,N,N,N,N,N,N,N,N,N,N,N,36837,N,N,N,N,N,36841,N,N,N,N,39385,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36087,N,N,N,N,N,N,N,N,N,N,N,N,N,37500,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,40005,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36072,36830,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,36831,N,N,N,N,N,N,N,N,N,N,N,N,N,41035,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,36834,N,N,N,41164,N,N,N,N,N,N,N,N,36835,36836,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,39876,N,N,N,39932,N,N,N,N,N,N,38476,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,39670,N,36014,N,N,N,N,N,N,N,N,N,N,N,N,36839,N,N,N,N,
+N,N,N,N,N,N,36840,N,N,N,N,35815,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,35194,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,35195,39386,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,36845,N,N,N,38336,N,N,N,N,N,N,N,N,N,N,N,N,N,41163,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40520,N,N,N,N,N,N,39387,N,36851,
+N,N,N,N,36857,N,N,N,N,N,N,N,N,N,N,N,N,N,38337,N,41038,N,N,N,N,N,N,39388,N,N,N,
+N,41060,36855,N,N,N,N,N,N,N,35248,41032,N,N,N,N,36859,36854,N,N,N,N,N,40412,N,
+N,N,39389,35816,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37569,N,N,N,N,N,N,N,40918,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41170,N,N,36928,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35524,N,N,39392,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,40944,40947,N,N,N,N,N,N,N,N,N,N,N,N,40383,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,40950,N,38344,N,N,40538,N,N,N,N,N,N,N,N,N,N,N,N,
+39395,N,N,N,N,N,N,N,N,N,N,N,35402,N,N,N,N,N,N,N,N,40945,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,35495,N,N,N,N,N,N,N,N,39398,N,N,N,40951,N,40941,N,N,
+N,N,N,N,35420,N,40366,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,38345,N,N,N,N,N,36936,N,N,39400,N,N,N,N,N,36937,N,N,36026,
+N,N,37041,N,N,N,N,N,N,36938,N,N,N,N,N,N,N,N,N,N,39402,N,N,N,N,N,N,N,N,N,N,N,
+39889,N,N,N,N,N,N,N,39403,N,39404,N,N,N,N,N,N,N,N,39405,N,N,N,N,39406,36940,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36941,N,N,38347,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,38882,N,N,N,N,N,N,N,N,38348,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40824,N,N,
+N,N,N,N,N,N,N,35196,35197,N,N,N,N,N,N,35198,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39261,N,N,N,N,N,N,N,N,N,N,N,N,39770,N,N,
+N,N,36944,N,35919,N,N,N,N,N,N,N,N,N,N,N,36948,N,50902,39592,39407,65259,40355,
 40353,39235,39237,N,40317,N,N,39408,N,N,N,N,N,N,N,N,39409,N,39410,N,N,36028,
 40288,N,N,N,N,N,N,N,N,N,41123,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,36955,40667,N,N,N,N,N,N,N,N,N,40313,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
@@ -1259,82 +1275,76 @@
 N,N,N,N,37063,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37604,40786,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,37083,N,N,N,N,N,41062,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-37074,N,N,N,N,37076,N,N,N,N,N,N,N,N,N,39515,38397,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,35780,N,N,N,35942,N,37086,N,N,N,N,N,40164,N,37089,N,N,N,N,N,N,N,N,N,N,N,N,N,
-40518,N,N,N,38481,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64344,N,37094,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38480,N,N,N,37095,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,37096,39517,N,40826,N,N,N,39772,N,40828,N,N,64594,37097,N,37098,N,39518,N,
-N,N,N,N,40822,N,N,N,N,N,N,N,N,N,37099,N,N,N,N,N,N,N,N,N,N,N,N,N,37100,N,N,N,N,
-N,35822,N,N,N,N,N,N,N,37102,N,N,N,37318,N,N,37106,64700,35444,N,N,N,N,N,N,N,N,
-N,38487,N,N,N,40175,N,N,N,N,N,N,N,N,N,N,40927,N,N,N,N,37111,37110,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,39774,N,N,N,37112,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,37113,N,36041,N,N,N,64106,N,N,N,N,N,N,N,N,35823,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40928,N,N,37186,N,39522,N,N,N,N,N,N,N,N,N,
-38249,N,N,N,37188,37187,N,37185,N,N,N,35824,N,N,N,N,N,N,N,N,N,N,N,N,N,38496,N,
-35825,N,39414,37193,N,N,N,N,37194,N,N,N,N,N,37195,N,N,N,N,39524,N,N,N,35519,
-39526,N,N,N,N,N,N,N,N,N,N,39527,N,N,39529,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,39530,38482,37197,N,38502,N,N,N,N,40827,N,39531,N,N,N,N,N,N,N,
-41068,N,N,38503,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39532,N,N,N,N,39533,35826,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,38506,N,N,N,N,N,N,N,N,64746,N,N,N,N,N,38508,N,N,N,N,
-N,N,N,N,N,N,N,N,N,37316,N,N,N,38519,N,N,N,N,N,N,N,39412,39535,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,40875,N,N,N,N,N,36030,36545,N,N,N,N,38229,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,37202,37203,N,N,N,37205,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38237,N,
-38513,N,N,N,N,40045,N,N,N,N,N,N,N,N,38515,N,N,N,N,N,N,N,N,N,N,N,37204,39537,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37206,N,N,N,38509,N,N,N,N,
-N,N,38231,N,N,N,N,N,N,N,N,35270,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,35271,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,35434,N,N,N,35671,N,N,N,40929,N,N,39775,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41053,N,N,N,N,N,N,N,N,37211,N,37212,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,37214,N,N,N,N,N,N,N,N,N,N,40796,40791,N,N,N,N,N,N,40805,
-N,N,N,N,N,39538,N,N,N,N,37216,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40798,
-N,N,37217,N,N,N,N,N,N,37220,N,N,N,N,40769,N,N,N,N,N,N,37225,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,37224,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39540,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38578,N,39541,N,64933,N,N,N,N,N,N,N,40681,
-N,35770,37229,41056,N,N,N,N,N,N,N,40926,N,N,N,N,N,40899,N,38581,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,41063,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,38579,N,N,N,N,N,N,N,N,N,N,N,N,N,39542,N,N,N,N,N,N,N,N,N,N,N,38357,N,N,N,
-40650,N,N,N,39543,N,N,39544,N,N,N,N,N,N,N,N,N,N,37232,37231,N,N,N,N,N,N,N,
-40867,N,37233,N,N,N,38577,N,N,N,N,40803,N,N,N,N,N,40807,N,N,N,35769,39546,N,N,
-N,N,N,35670,N,N,N,N,N,N,N,N,39642,N,N,N,N,N,38576,N,N,N,N,39550,N,N,N,N,N,N,N,
-N,N,N,40414,N,N,N,N,N,N,N,N,N,38573,N,N,N,38574,N,N,N,N,N,N,N,N,N,40609,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40528,N,N,N,N,N,N,N,N,38575,35828,40868,N,N,
-N,N,N,N,N,N,N,38589,N,N,N,N,N,N,N,N,N,38644,N,N,N,N,N,N,N,N,N,N,38584,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,64161,N,N,N,N,37287,N,N,N,N,N,N,N,N,N,N,41054,N,N,
-N,N,39549,N,N,N,N,35144,N,40625,N,N,N,N,N,N,N,N,N,N,N,N,N,40411,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,38335,35443,N,N,N,N,N,N,N,N,N,N,N,N,N,40702,N,37242,N,N,N,N,
-37243,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39587,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-38594,N,N,N,N,N,40823,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39588,N,N,39589,N,N,N,
-37281,N,N,N,N,35256,N,N,N,N,N,N,N,N,N,N,37235,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39590,35261,N,35257,N,37245,N,N,
-N,N,N,N,N,N,N,38587,N,N,N,40946,N,N,35829,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39593,N,N,
-N,N,N,40788,N,N,40931,40685,N,N,N,N,N,N,N,N,N,N,37290,N,N,N,N,37291,41072,N,
-40813,N,N,N,N,N,37292,N,N,N,37293,N,N,N,41213,N,40930,N,37295,40513,39594,N,N,
-37296,N,39595,N,N,N,N,N,N,N,N,N,N,N,39596,N,39498,N,37298,N,N,35830,N,39597,
-35254,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39599,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,39600,N,N,N,N,N,N,39601,N,N,N,N,N,39585,37305,N,N,N,N,N,37306,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,37310,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41025,35767,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,37312,N,N,N,N,N,N,N,N,N,N,39603,37315,N,N,N,N,N,N,
-N,N,N,N,41212,N,N,40942,N,N,N,N,N,N,40809,N,N,N,N,N,N,N,37320,N,N,N,N,N,N,
-37321,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36326,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,37323,N,N,N,N,N,N,N,N,N,N,35272,N,N,N,N,N,36266,N,N,N,N,N,40925,34880,
-34881,34882,34883,34884,N,34886,N,N,34889,34890,N,N,34893,N,34895,34896,34897,
-34898,N,34900,34901,N,N,N,N,N,N,N,N,N,N,N,N,34914,N,34916,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34979,N,34981,N,N,N,34985,34986,35907,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-35949,N,N,N,N,N,N,35956,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,36023,N,36025,N,36027,N,N,N,N,36032,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,36055,36056,N,36058,51321,N,N,N,N,51326,51361,N,51363,35832,51408,
-N,N,N,N,51407,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,50916,N,50917,N,N,N,N,N,N,N,N,N,N,N,N,N,
+37074,N,N,34667,N,37076,N,N,N,N,N,N,N,N,N,39515,38397,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,35780,N,N,N,35942,N,37086,N,N,N,N,N,40164,N,37089,N,N,N,N,N,N,N,N,N,N,N,
+N,N,40518,N,N,N,38481,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64344,N,37094,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38480,N,N,N,37095,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,37096,39517,N,40826,N,N,N,39772,N,40828,N,N,64594,37097,N,37098,N,
+39518,N,N,N,N,N,40822,N,N,N,N,N,N,N,N,N,37099,N,N,N,N,N,N,N,N,N,N,N,N,N,37100,
+N,N,N,N,N,35822,N,N,N,N,N,N,N,37102,N,N,N,37318,N,N,37106,64700,35444,N,N,N,N,
+N,N,N,N,N,38487,N,N,N,40175,N,N,N,N,N,N,N,N,N,N,40927,N,N,N,N,37111,37110,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39774,N,N,N,37112,N,N,N,N,N,N,N,N,N,N,36092,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,37113,N,36041,N,N,N,64106,N,N,N,N,N,N,N,N,35823,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40928,N,N,37186,N,39522,N,N,N,N,N,
+N,N,N,N,38249,N,N,N,37188,37187,N,37185,N,N,N,35824,N,N,N,N,N,N,N,N,N,N,N,N,N,
+38496,N,35825,N,39414,37193,N,N,N,N,37194,N,N,N,N,N,37195,N,N,N,N,39524,N,N,N,
+35519,39526,N,N,N,N,N,N,N,N,N,N,39527,N,N,39529,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,39530,38482,37197,N,38502,N,N,N,N,40827,N,39531,N,N,N,N,
+N,N,N,41068,N,N,38503,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39532,N,N,N,N,39533,35826,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38506,N,N,N,N,N,N,N,N,64746,N,N,N,N,N,38508,N,
+N,N,N,N,N,N,N,N,N,N,N,N,37316,N,N,N,38519,N,N,N,N,N,N,N,39412,39535,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40875,N,N,N,N,N,36030,36545,N,N,N,N,38229,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,37202,37203,N,N,N,37205,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+38237,N,38513,N,N,N,N,40045,N,N,N,N,N,N,N,N,38515,N,N,N,N,N,N,N,N,N,N,N,37204,
+39537,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37206,N,N,N,38509,
+N,N,N,N,N,N,38231,N,N,N,N,N,N,N,N,35270,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35271,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,35434,N,N,N,35671,N,N,N,40929,N,N,39775,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41053,N,N,N,N,N,N,N,N,37211,N,37212,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37214,N,N,N,N,N,N,N,N,N,N,40796,40791,N,N,N,N,N,
+N,40805,N,N,N,N,N,39538,N,N,N,N,37216,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,40798,N,N,37217,N,N,N,N,N,N,37220,N,N,N,N,40769,N,N,N,N,N,N,37225,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,37224,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39540,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38578,N,39541,N,64933,N,N,N,N,
+N,N,N,40681,N,35770,37229,41056,N,N,N,N,N,N,N,40926,N,N,N,N,N,40899,N,38581,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41063,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,38579,N,N,N,N,N,N,N,N,N,N,N,N,N,39542,N,N,N,N,N,N,N,N,N,N,N,
+38357,N,N,N,40650,N,N,N,39543,N,N,39544,N,N,N,N,N,N,N,N,N,N,37232,37231,N,N,N,
+N,N,N,N,40867,N,37233,N,N,N,38577,N,N,N,N,40803,N,N,N,N,N,40807,N,N,N,35769,
+39546,N,N,N,N,N,35670,N,N,N,N,N,N,N,N,39642,N,N,N,N,N,38576,N,N,N,N,39550,N,N,
+N,N,N,N,N,N,N,N,40414,N,N,N,N,N,N,N,N,N,38573,N,N,N,38574,N,N,N,N,N,N,N,N,N,
+40609,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40528,N,N,N,N,N,N,N,N,38575,
+35828,40868,N,N,N,N,N,N,N,N,N,38589,N,N,N,N,N,N,N,N,N,38644,N,N,N,N,N,N,N,N,N,
+N,38584,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64161,N,N,N,N,37287,N,N,N,N,N,N,N,
+N,N,N,41054,N,N,N,N,39549,N,N,N,N,35144,N,40625,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40411,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38335,35443,N,N,N,N,N,N,N,N,N,N,N,N,N,40702,
+N,37242,N,N,N,N,37243,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39587,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,38594,N,N,N,N,N,40823,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39588,N,
+N,39589,N,N,N,37281,N,N,N,N,35256,N,N,N,N,N,N,N,N,N,N,37235,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39590,35261,N,
+35257,N,37245,N,N,N,N,N,N,N,N,N,38587,N,N,N,40946,N,N,35829,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,39593,N,N,N,N,N,40788,N,N,40931,40685,N,N,N,N,N,N,N,N,N,N,37290,N,N,N,
+N,37291,41072,N,40813,N,N,N,N,N,37292,N,N,N,37293,N,N,N,41213,N,40930,N,37295,
+40513,39594,N,N,37296,N,39595,N,N,N,N,N,N,N,N,N,N,N,39596,N,39498,N,37298,N,N,
+35830,N,39597,35254,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39599,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,39600,N,N,N,N,N,N,39601,N,N,N,N,N,39585,37305,N,N,
+N,N,N,37306,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37310,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+41025,35767,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37312,N,N,N,N,N,N,N,N,N,N,39603,
+37315,N,N,N,N,N,N,N,N,N,N,41212,N,N,40942,N,N,N,N,N,N,40809,N,N,N,N,N,N,N,
+37320,N,N,N,N,N,N,37321,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36326,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,37323,N,N,N,N,N,N,N,N,N,N,35272,N,N,N,N,N,36266,N,N,N,N,
+N,40925,35907,35949,35956,36023,36025,36027,36032,36055,36056,36058,51361,
+51363,36077,36168,35832,51408,N,N,N,N,51407,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,50916,N,
+50917,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,51405,N,
-51406,N,N,N,N,N,N,N,N,63998,
+N,N,N,N,N,N,N,N,N,N,N,51405,N,51406,N,N,N,N,N,N,N,N,63998,
 };
 
 static const struct unim_index big5hkscs_bmp_encmap[256] = {
@@ -1343,65 +1353,66 @@
 0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0
 },{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,
 0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{__big5hkscs_bmp_encmap+506,190,
-193},{0,0,0},{0,0,0},{__big5hkscs_bmp_encmap+510,22,231},{0,0,0},{0,0,0},{
-__big5hkscs_bmp_encmap+720,96,125},{__big5hkscs_bmp_encmap+750,80,112},{0,0,0
-},{__big5hkscs_bmp_encmap+783,61,61},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{
-0,0,0},{__big5hkscs_bmp_encmap+784,128,227},{__big5hkscs_bmp_encmap+884,51,51
-},{__big5hkscs_bmp_encmap+885,5,254},{0,0,0},{__big5hkscs_bmp_encmap+1135,49,
-49},{0,0,0},{__big5hkscs_bmp_encmap+1136,53,251},{__big5hkscs_bmp_encmap+1335,
-6,254},{__big5hkscs_bmp_encmap+1584,9,245},{__big5hkscs_bmp_encmap+1821,1,251
-},{__big5hkscs_bmp_encmap+2072,15,250},{__big5hkscs_bmp_encmap+2308,8,254},{
-__big5hkscs_bmp_encmap+2555,1,251},{__big5hkscs_bmp_encmap+2806,14,244},{
-__big5hkscs_bmp_encmap+3037,13,239},{__big5hkscs_bmp_encmap+3264,19,253},{
-__big5hkscs_bmp_encmap+3499,6,255},{__big5hkscs_bmp_encmap+3749,0,250},{
-__big5hkscs_bmp_encmap+4000,4,250},{__big5hkscs_bmp_encmap+4247,3,249},{
-__big5hkscs_bmp_encmap+4494,17,252},{__big5hkscs_bmp_encmap+4730,43,242},{
-__big5hkscs_bmp_encmap+4930,1,244},{__big5hkscs_bmp_encmap+5174,3,233},{
-__big5hkscs_bmp_encmap+5405,6,245},{__big5hkscs_bmp_encmap+5645,19,244},{
-__big5hkscs_bmp_encmap+5871,0,250},{__big5hkscs_bmp_encmap+6122,6,231},{
-__big5hkscs_bmp_encmap+6348,15,255},{__big5hkscs_bmp_encmap+6589,16,192},{
-__big5hkscs_bmp_encmap+6766,4,237},{__big5hkscs_bmp_encmap+7000,9,156},{
-__big5hkscs_bmp_encmap+7148,4,248},{__big5hkscs_bmp_encmap+7393,3,253},{
-__big5hkscs_bmp_encmap+7644,3,252},{__big5hkscs_bmp_encmap+7894,1,254},{
-__big5hkscs_bmp_encmap+8148,2,249},{__big5hkscs_bmp_encmap+8396,1,254},{
-__big5hkscs_bmp_encmap+8650,19,239},{__big5hkscs_bmp_encmap+8871,2,251},{
-__big5hkscs_bmp_encmap+9121,5,253},{__big5hkscs_bmp_encmap+9370,0,254},{
-__big5hkscs_bmp_encmap+9625,3,251},{__big5hkscs_bmp_encmap+9874,2,249},{
-__big5hkscs_bmp_encmap+10122,2,254},{__big5hkscs_bmp_encmap+10375,13,255},{
-__big5hkscs_bmp_encmap+10618,5,245},{__big5hkscs_bmp_encmap+10859,16,245},{
-__big5hkscs_bmp_encmap+11089,9,252},{__big5hkscs_bmp_encmap+11333,12,223},{
-__big5hkscs_bmp_encmap+11545,35,253},{__big5hkscs_bmp_encmap+11764,7,226},{
-__big5hkscs_bmp_encmap+11984,44,229},{__big5hkscs_bmp_encmap+12170,24,254},{
-__big5hkscs_bmp_encmap+12401,7,234},{__big5hkscs_bmp_encmap+12629,10,255},{
-__big5hkscs_bmp_encmap+12875,24,241},{__big5hkscs_bmp_encmap+13093,2,254},{
-__big5hkscs_bmp_encmap+13346,0,202},{__big5hkscs_bmp_encmap+13549,0,250},{
-__big5hkscs_bmp_encmap+13800,3,246},{__big5hkscs_bmp_encmap+14044,5,250},{
-__big5hkscs_bmp_encmap+14290,28,255},{__big5hkscs_bmp_encmap+14518,2,254},{
-__big5hkscs_bmp_encmap+14771,2,250},{__big5hkscs_bmp_encmap+15020,4,248},{
-__big5hkscs_bmp_encmap+15265,3,254},{__big5hkscs_bmp_encmap+15517,5,246},{
-__big5hkscs_bmp_encmap+15759,0,226},{__big5hkscs_bmp_encmap+15986,2,251},{
-__big5hkscs_bmp_encmap+16236,2,248},{__big5hkscs_bmp_encmap+16483,5,220},{
-__big5hkscs_bmp_encmap+16699,2,217},{__big5hkscs_bmp_encmap+16915,12,254},{
-__big5hkscs_bmp_encmap+17158,8,245},{__big5hkscs_bmp_encmap+17396,6,244},{
-__big5hkscs_bmp_encmap+17635,6,254},{__big5hkscs_bmp_encmap+17884,11,252},{
-__big5hkscs_bmp_encmap+18126,18,252},{__big5hkscs_bmp_encmap+18361,37,254},{
-__big5hkscs_bmp_encmap+18579,7,223},{__big5hkscs_bmp_encmap+18796,6,250},{
-__big5hkscs_bmp_encmap+19041,2,246},{__big5hkscs_bmp_encmap+19286,3,246},{
-__big5hkscs_bmp_encmap+19530,24,255},{__big5hkscs_bmp_encmap+19762,11,237},{
-__big5hkscs_bmp_encmap+19989,5,248},{__big5hkscs_bmp_encmap+20233,3,252},{
-__big5hkscs_bmp_encmap+20483,2,239},{__big5hkscs_bmp_encmap+20721,112,245},{
-__big5hkscs_bmp_encmap+20855,4,255},{__big5hkscs_bmp_encmap+21107,0,231},{
-__big5hkscs_bmp_encmap+21339,28,234},{__big5hkscs_bmp_encmap+21546,12,226},{
-__big5hkscs_bmp_encmap+21761,81,247},{__big5hkscs_bmp_encmap+21928,3,212},{
-__big5hkscs_bmp_encmap+22138,1,242},{__big5hkscs_bmp_encmap+22380,25,249},{
-__big5hkscs_bmp_encmap+22605,8,196},{__big5hkscs_bmp_encmap+22794,81,254},{
-__big5hkscs_bmp_encmap+22968,8,253},{__big5hkscs_bmp_encmap+23214,3,244},{
-__big5hkscs_bmp_encmap+23456,1,246},{__big5hkscs_bmp_encmap+23702,45,244},{
-__big5hkscs_bmp_encmap+23902,29,244},{__big5hkscs_bmp_encmap+24118,3,245},{
-__big5hkscs_bmp_encmap+24361,20,245},{__big5hkscs_bmp_encmap+24587,14,245},{
-__big5hkscs_bmp_encmap+24819,12,255},{__big5hkscs_bmp_encmap+25063,2,255},{
-__big5hkscs_bmp_encmap+25317,2,124},{__big5hkscs_bmp_encmap+25440,2,252},{
-__big5hkscs_bmp_encmap+25691,10,254},{__big5hkscs_bmp_encmap+25936,2,165},{0,
+193},{0,0,0},{0,0,0},{__big5hkscs_bmp_encmap+510,22,231},{0,0,0},{
+__big5hkscs_bmp_encmap+720,218,219},{__big5hkscs_bmp_encmap+722,96,125},{
+__big5hkscs_bmp_encmap+752,80,112},{0,0,0},{__big5hkscs_bmp_encmap+785,61,61},
+{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{__big5hkscs_bmp_encmap+786,
+128,227},{__big5hkscs_bmp_encmap+886,51,51},{__big5hkscs_bmp_encmap+887,5,254
+},{__big5hkscs_bmp_encmap+1137,192,207},{__big5hkscs_bmp_encmap+1153,49,49},{
+0,0,0},{__big5hkscs_bmp_encmap+1154,53,251},{__big5hkscs_bmp_encmap+1353,6,254
+},{__big5hkscs_bmp_encmap+1602,9,245},{__big5hkscs_bmp_encmap+1839,1,251},{
+__big5hkscs_bmp_encmap+2090,15,250},{__big5hkscs_bmp_encmap+2326,8,254},{
+__big5hkscs_bmp_encmap+2573,1,251},{__big5hkscs_bmp_encmap+2824,14,244},{
+__big5hkscs_bmp_encmap+3055,13,239},{__big5hkscs_bmp_encmap+3282,18,253},{
+__big5hkscs_bmp_encmap+3518,6,255},{__big5hkscs_bmp_encmap+3768,0,250},{
+__big5hkscs_bmp_encmap+4019,4,250},{__big5hkscs_bmp_encmap+4266,2,249},{
+__big5hkscs_bmp_encmap+4514,17,252},{__big5hkscs_bmp_encmap+4750,43,242},{
+__big5hkscs_bmp_encmap+4950,1,244},{__big5hkscs_bmp_encmap+5194,3,234},{
+__big5hkscs_bmp_encmap+5426,3,247},{__big5hkscs_bmp_encmap+5671,19,244},{
+__big5hkscs_bmp_encmap+5897,0,250},{__big5hkscs_bmp_encmap+6148,6,231},{
+__big5hkscs_bmp_encmap+6374,15,255},{__big5hkscs_bmp_encmap+6615,16,192},{
+__big5hkscs_bmp_encmap+6792,4,237},{__big5hkscs_bmp_encmap+7026,7,156},{
+__big5hkscs_bmp_encmap+7176,4,248},{__big5hkscs_bmp_encmap+7421,3,253},{
+__big5hkscs_bmp_encmap+7672,3,252},{__big5hkscs_bmp_encmap+7922,1,254},{
+__big5hkscs_bmp_encmap+8176,2,249},{__big5hkscs_bmp_encmap+8424,1,254},{
+__big5hkscs_bmp_encmap+8678,19,239},{__big5hkscs_bmp_encmap+8899,2,251},{
+__big5hkscs_bmp_encmap+9149,5,253},{__big5hkscs_bmp_encmap+9398,0,254},{
+__big5hkscs_bmp_encmap+9653,3,251},{__big5hkscs_bmp_encmap+9902,2,249},{
+__big5hkscs_bmp_encmap+10150,2,254},{__big5hkscs_bmp_encmap+10403,13,255},{
+__big5hkscs_bmp_encmap+10646,5,252},{__big5hkscs_bmp_encmap+10894,16,245},{
+__big5hkscs_bmp_encmap+11124,9,252},{__big5hkscs_bmp_encmap+11368,12,223},{
+__big5hkscs_bmp_encmap+11580,35,253},{__big5hkscs_bmp_encmap+11799,7,226},{
+__big5hkscs_bmp_encmap+12019,44,229},{__big5hkscs_bmp_encmap+12205,24,254},{
+__big5hkscs_bmp_encmap+12436,7,234},{__big5hkscs_bmp_encmap+12664,10,255},{
+__big5hkscs_bmp_encmap+12910,24,241},{__big5hkscs_bmp_encmap+13128,2,254},{
+__big5hkscs_bmp_encmap+13381,0,202},{__big5hkscs_bmp_encmap+13584,0,250},{
+__big5hkscs_bmp_encmap+13835,3,246},{__big5hkscs_bmp_encmap+14079,5,250},{
+__big5hkscs_bmp_encmap+14325,28,255},{__big5hkscs_bmp_encmap+14553,2,254},{
+__big5hkscs_bmp_encmap+14806,2,250},{__big5hkscs_bmp_encmap+15055,4,248},{
+__big5hkscs_bmp_encmap+15300,3,254},{__big5hkscs_bmp_encmap+15552,5,246},{
+__big5hkscs_bmp_encmap+15794,0,226},{__big5hkscs_bmp_encmap+16021,2,251},{
+__big5hkscs_bmp_encmap+16271,2,248},{__big5hkscs_bmp_encmap+16518,5,220},{
+__big5hkscs_bmp_encmap+16734,2,217},{__big5hkscs_bmp_encmap+16950,12,254},{
+__big5hkscs_bmp_encmap+17193,8,245},{__big5hkscs_bmp_encmap+17431,6,244},{
+__big5hkscs_bmp_encmap+17670,6,254},{__big5hkscs_bmp_encmap+17919,11,252},{
+__big5hkscs_bmp_encmap+18161,18,252},{__big5hkscs_bmp_encmap+18396,37,254},{
+__big5hkscs_bmp_encmap+18614,7,223},{__big5hkscs_bmp_encmap+18831,6,250},{
+__big5hkscs_bmp_encmap+19076,2,246},{__big5hkscs_bmp_encmap+19321,3,246},{
+__big5hkscs_bmp_encmap+19565,24,255},{__big5hkscs_bmp_encmap+19797,11,237},{
+__big5hkscs_bmp_encmap+20024,5,248},{__big5hkscs_bmp_encmap+20268,3,252},{
+__big5hkscs_bmp_encmap+20518,2,239},{__big5hkscs_bmp_encmap+20756,112,245},{
+__big5hkscs_bmp_encmap+20890,4,255},{__big5hkscs_bmp_encmap+21142,0,231},{
+__big5hkscs_bmp_encmap+21374,28,249},{__big5hkscs_bmp_encmap+21596,12,226},{
+__big5hkscs_bmp_encmap+21811,81,247},{__big5hkscs_bmp_encmap+21978,3,212},{
+__big5hkscs_bmp_encmap+22188,1,242},{__big5hkscs_bmp_encmap+22430,25,249},{
+__big5hkscs_bmp_encmap+22655,8,196},{__big5hkscs_bmp_encmap+22844,81,254},{
+__big5hkscs_bmp_encmap+23018,8,253},{__big5hkscs_bmp_encmap+23264,3,244},{
+__big5hkscs_bmp_encmap+23506,1,246},{__big5hkscs_bmp_encmap+23752,45,244},{
+__big5hkscs_bmp_encmap+23952,29,244},{__big5hkscs_bmp_encmap+24168,3,245},{
+__big5hkscs_bmp_encmap+24411,20,245},{__big5hkscs_bmp_encmap+24637,14,245},{
+__big5hkscs_bmp_encmap+24869,12,255},{__big5hkscs_bmp_encmap+25113,2,255},{
+__big5hkscs_bmp_encmap+25367,2,124},{__big5hkscs_bmp_encmap+25490,2,252},{
+__big5hkscs_bmp_encmap+25741,10,254},{__big5hkscs_bmp_encmap+25986,2,179},{0,
 0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{
 0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0
 },{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,
@@ -1410,13 +1421,12 @@
 },{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,
 0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{
 0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0
-},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{__big5hkscs_bmp_encmap+26100,3,75},
-{0,0,0},{__big5hkscs_bmp_encmap+26173,122,239},{0,0,0},{__big5hkscs_bmp_encmap
-+26291,229,237},{0,0,0},{__big5hkscs_bmp_encmap+26300,7,7},{0,0,0},{0,0,0},{0,
-0,0},{0,0,0},{0,0,0},{__big5hkscs_bmp_encmap+26301,2,237},
+},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,
+0,0},{0,0,0},{__big5hkscs_bmp_encmap+26164,7,7},{0,0,0},{0,0,0},{0,0,0},{0,0,0
+},{0,0,0},{__big5hkscs_bmp_encmap+26165,2,237},
 };
 
-static const DBCHAR __big5hkscs_nonbmp_encmap[28325] = {
+static const DBCHAR __big5hkscs_nonbmp_encmap[29306] = {
 40049,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37749,N,N,N,N,N,
 N,N,37750,N,N,N,N,N,N,N,38216,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,36550,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35781,35834,
@@ -1427,34 +1437,34 @@
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,35501,N,37490,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64583,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38111,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,40913,64459,N,N,N,N,N,N,N,37501,N,N,N,N,N,N,N,
+N,N,N,N,N,N,36085,N,N,N,N,35501,N,37490,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,64583,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38111,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40913,64459,N,N,N,N,N,N,N,37501,N,N,N,N,N,N,N,
 39076,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38119,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37067,37499,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38104,N,N,N,N,64607,N,64084,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39605,N,N,N,N,N,N,N,38618,37497,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64116,
-37493,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36347,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35401,N,N,N,37599,39804,64099,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,64096,37485,64098,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,39606,N,N,N,N,N,N,38763,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64874,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64852,N,37491,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38872,N,N,N,N,N,
-N,40891,37698,37494,N,N,N,N,N,N,N,N,N,N,64101,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,37484,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,64110,N,N,N,N,N,N,40672,N,N,37568,37567,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,37566,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39610,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35507,N,38773,64064,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64118,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,64464,N,N,N,N,N,N,N,N,N,N,N,N,N,64123,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,65133,N,N,N,N,N,N,39859,N,N,N,N,N,35276,N,N,N,N,39614,N,N,N,N,N,N,
-N,N,N,64066,37564,N,N,N,N,N,N,N,N,N,N,37980,39861,N,N,N,39615,N,N,N,39079,
+36089,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38119,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37067,37499,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38104,N,N,N,N,64607,N,
+64084,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39605,N,N,N,N,N,N,N,38618,
+37497,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+64116,37493,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36347,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35401,N,N,N,37599,39804,64099,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,64096,37485,64098,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39606,N,N,N,N,N,N,38763,N,N,N,N,N,N,N,N,N,N,N,N,
+N,64874,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64852,N,37491,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38872,N,N,N,N,
+N,N,40891,37698,37494,N,N,N,N,N,N,N,N,N,N,64101,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37484,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,64110,N,N,N,N,N,N,40672,N,N,37568,37567,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,37566,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39610,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35507,N,38773,64064,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64118,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,64464,N,N,N,N,N,N,N,N,N,N,N,N,N,64123,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,65133,N,N,N,N,N,N,39859,N,N,N,N,N,35276,N,N,N,N,39614,N,N,N,N,N,
+N,N,N,N,64066,37564,N,N,N,N,N,N,N,N,N,N,37980,39861,N,N,N,39615,N,N,N,39079,
 38820,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37117,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64635,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39616,37571,N,N,N,N,N,N,N,N,N,N,N,N,N,
@@ -1473,38 +1483,38 @@
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35250,40038,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36947,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,35938,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,38849,N,N,N,N,N,N,N,N,N,N,N,N,N,39620,N,N,N,N,N,N,N,N,N,N,39621,36591,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-38849,N,N,N,N,N,N,N,N,N,N,N,N,N,39620,N,N,N,N,N,N,N,N,N,N,39621,36591,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,64233,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37474,
-35575,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39622,N,N,N,N,N,N,37601,N,N,N,
-N,39625,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64198,N,N,N,N,N,N,N,N,
-38821,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39627,N,N,N,64114,35422,N,38112,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,37580,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35557,N,
-N,N,N,N,65116,39628,N,N,N,N,N,40441,35395,35494,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-39629,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39630,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,64238,39884,N,N,N,39631,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39633,N,N,N,N,N,N,N,
-N,40442,N,N,N,N,N,40316,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39635,
-N,N,38822,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39263,N,N,N,64502,40901,
-35417,35691,N,N,N,N,N,N,39636,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39637,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,38818,35396,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40778,N,
-N,N,N,N,N,N,N,37025,64932,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35428,35570,
-35576,40408,N,N,38102,64254,64423,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,39638,N,40781,N,N,64246,N,N,N,N,N,N,N,35415,N,35651,35652,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35510,N,N,N,N,N,35520,N,N,N,N,N,N,
-N,N,N,N,40532,N,N,N,N,N,N,N,N,N,N,39639,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,39640,39644,N,N,N,N,35530,40616,N,N,37475,39645,35685,35695,35710,N,N,N,N,
-36675,N,N,N,N,N,N,37584,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35572,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40382,N,N,N,N,N,39649,N,64734,40445,35686,35696,
-35701,35556,35748,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35565,N,N,N,N,N,N,N,N,N,
-35421,N,35656,N,N,N,N,40429,N,N,N,N,40512,N,N,N,N,N,N,N,35567,35574,40566,N,N,
-N,N,N,N,N,N,N,40675,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,39646,36350,N,N,N,N,64252,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,40113,40567,35684,35687,38731,N,N,N,N,N,N,N,N,38483,N,N,N,N,N,N,39648,
+N,N,N,N,N,N,N,N,N,N,64233,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36160,N,N,N,N,N,N,N,N,
+37474,35575,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39622,N,N,N,N,N,N,37601,
+N,N,N,N,39625,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64198,N,N,N,N,N,N,N,
+N,38821,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39627,N,N,N,64114,35422,N,38112,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,37580,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35557,
+N,N,N,N,N,65116,39628,N,N,N,N,N,40441,35395,35494,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,39629,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39630,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,64238,39884,N,N,N,39631,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39633,N,N,N,N,N,N,
+N,N,40442,N,N,N,N,N,40316,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39635,N,N,38822,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39263,N,N,N,64502,
+40901,35417,35691,N,N,N,N,N,N,39636,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39637,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,38818,35396,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40778,N,N,N,N,N,N,N,N,37025,64932,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35428,
+35570,35576,40408,N,N,38102,64254,64423,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,39638,N,40781,N,N,64246,N,N,N,N,N,N,N,35415,N,35651,
+35652,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35510,N,N,N,N,N,35520,N,N,N,
+N,N,N,N,N,N,N,40532,N,N,N,N,N,N,N,N,N,N,39639,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,39640,39644,N,N,N,N,35530,40616,N,N,37475,39645,35685,35695,35710,N,
+N,N,N,36675,N,N,N,N,N,N,37584,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35572,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40382,N,N,N,N,N,39649,N,64734,40445,35686,
+35696,35701,35556,35748,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35565,N,N,N,N,N,N,N,N,
+N,35421,N,35656,N,N,N,N,40429,N,N,N,N,40512,N,N,N,N,N,N,N,35567,35574,40566,N,
+N,N,N,N,N,N,N,N,40675,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,39646,36350,N,N,N,N,64252,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,40113,40567,35684,35687,38731,N,N,N,N,N,N,N,N,38483,N,N,N,N,N,N,39648,
 35658,N,35569,35543,N,N,N,N,N,N,N,N,N,41131,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 35509,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35423,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35566,N,N,39647,N,
@@ -1574,151 +1584,152 @@
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64076,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37623,39744,N,N,N,N,N,N,64462,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,39745,N,N,N,N,N,65197,64469,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,39745,N,N,N,N,N,65197,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,34657,64469,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35778,39548,39746,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39747,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35778,39548,39746,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,40569,N,N,64473,N,N,N,N,N,N,39748,41127,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39747,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40569,N,N,64473,N,N,
+N,N,N,N,39748,41127,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34670,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39923,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35961,N,N,N,37726,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,35275,N,N,N,N,N,N,40787,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,37847,N,N,N,N,N,N,N,N,N,N,N,N,N,64481,65232,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,64482,N,N,N,N,N,64739,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,39923,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,35961,N,N,N,37726,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35275,N,N,N,N,
+N,N,40787,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37847,N,N,N,N,N,N,
+N,N,N,N,N,N,N,64481,65232,N,N,N,N,N,N,36081,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,64482,N,N,N,N,N,64739,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36980,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,64486,N,N,N,39863,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,39749,N,N,N,N,N,N,N,N,N,N,N,N,39751,40784,N,N,N,N,N,39752,
+N,N,N,N,N,N,N,N,N,N,36980,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+64486,N,N,N,39863,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,39749,N,N,N,N,N,N,N,N,N,N,N,N,39751,40784,N,N,N,N,N,39752,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64603,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,64603,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39081,N,N,40189,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,39081,N,N,40189,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34892,39755,N,N,N,64492,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,35945,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-39848,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,35541,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64115,64857,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-37282,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64493,N,N,N,N,N,N,40105,N,
+N,N,N,N,N,N,N,N,N,N,N,N,34892,39755,N,N,N,64492,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-35496,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39875,
-35553,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35945,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39848,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35541,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64115,64857,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37282,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64493,N,N,N,N,N,N,40105,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35496,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36162,N,39875,35553,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,39758,38352,N,N,N,36959,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39758,38352,N,
+N,N,36959,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,38894,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64590,N,N,N,N,N,N,
-39759,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-39760,40646,N,N,N,N,N,N,N,N,N,N,N,64592,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,64883,N,N,N,N,N,64935,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,40354,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64088,64094,N,
-N,N,N,N,N,N,41049,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64117,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64446,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,40098,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,37744,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37745,37751,65263,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,37741,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64605,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,37048,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,35580,N,64321,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40555,38115,36578,35965,N,36567,
-N,N,N,N,N,N,40013,N,N,N,38563,N,N,N,N,N,N,N,N,N,N,39761,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35523,N,N,N,N,N,N,N,N,N,N,N,
-38570,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,64616,35693,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,64871,35561,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64673,37740,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,39762,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65136,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,64680,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64745,40116,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,35562,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-39763,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39765,N,N,N,38571,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64679,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-39766,35516,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35531,N,N,N,N,
-N,39767,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35277,N,39769,39771,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,37797,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,39773,N,N,N,40527,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,37795,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35451,N,N,N,35650,
-38736,36787,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35408,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,39776,N,N,N,N,35653,N,N,N,35654,N,N,N,N,N,N,N,N,N,N,N,N,40446,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39778,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37755,N,N,N,N,N,37809,N,N,N,N,N,N,N,35424,N,N,
-N,N,N,N,N,N,35544,N,N,N,N,39779,N,N,N,N,N,N,N,N,N,N,35433,N,N,N,35399,N,N,
-35532,37756,39781,N,N,N,N,N,N,N,N,N,39782,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35442,N,N,N,N,N,
-N,N,35450,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37807,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35504,N,N,N,N,
-N,N,N,39784,N,N,N,N,N,N,N,N,N,N,40611,N,N,64236,35703,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,39783,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35673,64689,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64699,N,N,N,N,N,
-N,N,N,N,N,N,39785,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37800,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,35552,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,40529,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36703,39786,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,39787,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38892,39788,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65102,N,N,N,N,N,N,64962,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,39789,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-37223,64716,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37814,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37092,N,N,N,N,37093,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40690,37834,N,N,N,N,N,N,N,N,
+38894,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64590,N,N,N,N,N,N,39759,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39760,40646,N,N,N,N,N,
+N,N,N,N,N,N,64592,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64883,N,N,
+N,N,N,64935,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40354,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,35772,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64088,64094,N,N,N,N,N,N,N,41049,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64117,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64446,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-36678,N,N,N,N,37839,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,64731,64732,N,N,N,N,N,N,N,N,N,N,N,N,N,37824,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,64742,38631,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64728,64729,64934,37838,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,38385,N,N,N,N,N,N,N,N,N,40169,N,64740,38063,64119,
-37836,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,36954,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,35924,N,N,N,N,N,N,N,37823,64337,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,37817,65239,37815,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37849,N,N,N,N,N,N,N,N,N,N,N,N,N,37819,
-37850,39075,N,N,N,N,N,N,N,N,N,37073,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-39790,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64112,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39915,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,39791,N,N,N,N,N,N,N,64764,N,N,N,N,N,N,N,N,N,N,N,N,N,35648,41083,N,N,N,
-36001,38903,N,N,N,37858,64726,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-38233,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37798,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,64832,N,N,37727,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38898,40054,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,36600,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,36679,N,N,N,N,N,N,N,N,N,N,N,N,39796,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37556,
-N,N,N,37357,N,N,38610,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64838,36687,38217,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39797,64092,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39801,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,64843,N,N,N,38611,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,64856,N,N,N,N,N,37983,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,41205,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,37443,N,N,N,N,N,N,38906,N,N,N,N,N,N,N,N,N,N,N,N,
+40098,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37744,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,37745,37751,65263,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+37741,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64605,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,37048,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35580,N,
+64321,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40555,38115,36578,35965,N,36567,N,N,N,N,N,N,
+40013,N,N,N,38563,N,N,N,N,N,N,N,N,N,N,39761,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35523,N,N,N,N,N,N,N,N,N,N,N,38570,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36066,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,64616,35693,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+64871,35561,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64673,37740,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,39762,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65136,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,64680,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64745,40116,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,35562,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39763,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39765,N,N,N,38571,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,64679,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39766,35516,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35531,N,N,N,N,N,39767,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,35277,N,39769,39771,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,37797,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39773,N,N,
+N,40527,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,37795,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35451,N,N,N,35650,38736,36787,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35408,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39776,N,N,N,N,35653,N,N,N,35654,N,N,N,N,N,N,N,N,N,N,N,N,40446,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39778,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,37755,N,N,N,N,N,37809,N,N,N,N,N,N,N,35424,N,N,N,N,N,N,N,
+N,35544,N,N,N,N,39779,N,N,N,N,N,N,N,N,N,N,35433,N,N,N,35399,N,N,35532,37756,
+39781,N,N,N,N,N,N,N,N,N,39782,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35442,N,N,N,N,N,N,N,35450,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37807,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35504,N,N,N,N,N,N,N,39784,
+N,N,N,N,N,N,N,N,N,N,40611,N,N,64236,35703,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39783,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35673,64689,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64699,N,N,N,N,N,N,N,N,N,N,N,
+39785,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37800,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35552,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,40529,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36703,39786,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,39787,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38892,39788,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,65102,N,N,N,N,N,N,64962,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,39789,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37223,
+64716,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37814,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37092,N,N,N,N,37093,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40690,37834,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,35772,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36678,N,N,
+N,N,37839,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+64731,64732,N,N,N,N,N,N,N,N,N,N,N,N,N,37824,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,64742,38631,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64728,64729,64934,37838,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,38385,N,N,N,N,N,N,N,N,N,40169,N,64740,38063,64119,37836,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36065,N,N,N,N,N,
+N,N,N,N,N,N,36954,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35924,N,N,N,N,N,N,N,37823,64337,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,37817,65239,37815,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37849,N,N,N,N,N,N,N,N,N,N,N,N,N,37819,37850,
+39075,N,N,N,N,N,N,N,N,N,37073,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39790,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64112,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39915,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39791,N,N,N,N,N,N,N,64764,N,N,N,N,N,N,N,N,N,N,N,N,N,35648,41083,N,N,N,36001,
+38903,N,N,N,37858,64726,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38233,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37798,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,64832,N,N,37727,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,38898,40054,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,36600,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+36075,N,N,N,N,N,N,N,N,36679,N,N,N,N,N,N,N,N,N,N,N,N,39796,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37556,N,
+N,N,37357,N,N,38610,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64838,36687,38217,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39797,64092,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,34641,N,N,39801,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64843,N,N,N,38611,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,64856,N,N,N,N,N,37983,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,41205,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,37443,N,N,N,N,N,N,38906,N,N,N,N,N,N,N,N,N,N,N,N,
 40409,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 38900,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37453,64859,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,39802,N,N,N,N,N,N,N,N,N,40661,N,N,N,N,N,N,N,N,N,N,N,N,64174,N,40137,N,N,N,
@@ -1729,418 +1740,442 @@
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37868,38902,38607,37854,35535,39842,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,64873,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37714,N,N,N,N,N,N,
-N,N,N,N,N,39074,64878,36004,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64124,37882,36988,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36711,N,40375,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,41193,64078,64929,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40564,40895,40651,39865,
-40404,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38841,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36593,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,38267,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,40658,38739,38564,36798,38105,36952,64889,64891,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36570,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36602,39845,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,40665,38868,37051,64956,64966,37448,N,N,N,N,N,N,N,37557,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40385,
-37561,37542,36683,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39846,N,N,N,N,N,37558,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,36416,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,40664,37982,39007,38094,37450,64880,37991,N,N,N,N,N,N,N,N,N,N,N,
-36332,N,N,N,N,N,N,N,N,39896,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37960,64193,40183,64958,
-N,N,N,N,N,N,N,N,N,N,N,N,36826,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,64985,N,N,64638,N,N,N,N,N,N,N,N,37881,N,N,N,N,64067,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64235,
-64195,38867,38393,40008,64984,41176,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64983,64330,39855,37963,64969,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36524,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64946,N,N,N,N,N,37466,
-64701,37593,N,N,N,64981,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37597,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37465,38586,N,N,N,N,N,N,N,N,N,N,37467,N,N,N,N,N,
-N,N,N,N,39851,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,64986,64990,N,N,N,64979,N,N,N,N,N,N,N,N,N,35910,N,N,N,N,N,N,64982,
-64988,64989,N,N,N,N,37118,N,N,65185,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,35757,N,N,40152,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,40557,64892,64353,N,N,N,N,N,N,38648,N,N,N,N,N,N,N,N,
-38640,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64756,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,65120,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-38994,38479,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,37230,N,N,N,N,N,N,N,N,N,N,39021,N,N,39012,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37971,65004,64376,N,N,N,N,N,N,
-N,N,N,N,N,38330,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39005,N,37625,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,39002,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65014,N,
-N,N,N,N,N,N,37840,39010,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,39853,N,N,N,N,N,N,N,N,N,N,N,38735,39854,N,N,N,N,N,N,N,N,N,N,N,
-N,37970,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39856,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,37330,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,38890,64363,37297,65011,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,37579,N,N,N,N,N,N,N,N,N,39857,N,N,N,N,N,64748,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39019,N,N,N,38737,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-39025,38383,N,N,N,N,N,N,N,40691,N,N,N,N,N,37352,39866,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64332,
-37482,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-65016,39009,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37351,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,37869,38724,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37345,N,N,64501,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,39017,N,N,N,N,35426,N,N,39867,36008,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40021,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36471,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35506,
-40636,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37862,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,39074,36071,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64878,
+36004,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64124,37882,36988,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,36711,N,40375,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41193,
+64078,64929,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40564,40895,40651,39865,40404,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38841,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36593,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38267,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40658,38739,38564,36798,38105,36952,64889,64891,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36570,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,36602,34658,N,N,N,N,N,N,N,N,N,N,39845,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,40665,38868,37051,64956,64966,37448,N,N,N,N,N,N,N,
+37557,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,40385,37561,37542,36683,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39846,N,N,N,N,N,37558,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36416,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,40664,37982,39007,38094,37450,64880,37991,N,N,N,N,N,N,N,
+N,N,N,N,36332,N,N,N,N,N,N,N,N,39896,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,34659,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37960,64193,
+40183,64958,N,N,N,N,N,N,N,N,N,N,N,N,36826,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64985,N,N,64638,N,N,N,N,N,N,N,N,37881,N,N,
+N,N,64067,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,64235,64195,38867,38393,40008,64984,41176,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64983,64330,39855,37963,64969,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36524,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64946,N,N,
+N,N,N,37466,64701,37593,N,N,N,64981,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37597,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37465,N,N,N,N,N,N,N,N,N,N,36080,
+38586,N,N,N,N,N,N,N,N,N,N,37467,N,N,N,N,N,N,N,N,N,39851,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64986,64990,N,N,N,64979,N,
+N,N,N,N,N,N,N,N,35910,N,N,N,N,N,N,64982,64988,64989,N,N,N,N,37118,N,N,65185,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35757,N,N,40152,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40557,64892,
+64353,N,N,N,N,N,N,38648,N,N,N,N,N,N,N,N,38640,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,64756,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65120,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38994,38479,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37230,N,N,N,
+N,N,N,N,N,N,N,39021,N,N,39012,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,37971,65004,64376,N,N,N,N,N,N,N,N,N,N,N,38330,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,39005,N,37625,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39002,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,34640,N,65014,N,N,N,N,N,N,N,37840,39010,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39853,N,N,N,N,N,N,N,
+N,N,N,N,38735,39854,N,N,N,N,N,N,N,N,N,N,N,N,37970,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,39856,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37330,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38890,64363,37297,65011,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37579,N,N,N,
+N,N,N,N,N,N,39857,N,N,N,N,N,64748,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,39019,N,N,N,38737,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39025,38383,N,N,N,N,N,N,N,40691,N,N,N,N,
+N,37352,39866,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64332,37482,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65016,39009,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,37351,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37869,38724,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,37345,N,N,64501,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39017,N,N,N,N,
+35426,N,N,39867,36008,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40021,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,36471,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35506,40636,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+37862,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37794,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39869,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+38067,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37757,40550,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37977,N,N,N,N,N,N,N,N,N,39871,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,37976,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40613,39879,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,65108,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36468,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,35798,N,N,N,N,N,N,38070,64884,39104,38053,N,N,N,N,N,N,N,
+39880,N,N,N,38381,64894,64491,N,N,N,N,N,N,N,N,N,N,64893,N,N,N,N,N,N,N,N,N,
+38767,37985,N,40897,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38359,N,N,N,
+64082,40024,N,N,N,N,N,N,N,N,N,40808,39911,64718,38632,64073,38817,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38221,40696,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,65097,37326,38769,N,N,N,N,36047,N,N,N,64945,N,N,64622,N,N,N,N,N,
+40178,37816,36931,38745,38103,65126,38013,64623,N,N,N,N,37446,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,64109,N,N,36599,N,64439,N,38012,37581,38834,N,N,N,N,N,N,N,N,N,
+65125,38526,38744,39799,37327,N,N,N,N,N,N,N,N,N,38052,N,N,N,N,N,N,N,N,N,N,
+40109,N,N,N,N,N,N,N,N,N,35755,N,N,N,38613,64691,N,N,N,37806,N,38765,N,N,N,N,N,
+N,37958,38391,N,N,N,N,N,N,N,N,40006,38235,37329,38132,N,65127,37541,N,N,N,
+65247,36011,N,39881,N,N,N,N,N,N,N,N,N,N,N,64749,65018,64712,65122,37372,65131,
+65017,64711,37198,40120,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38759,N,N,N,
+38382,N,N,39858,N,N,N,N,37984,N,N,N,38050,39029,38828,37331,N,N,N,N,N,N,N,N,N,
+N,N,39035,N,N,N,N,N,N,N,36587,38762,38494,N,N,N,N,N,N,N,N,N,38891,N,N,N,N,N,
+40953,38392,65186,36838,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65150,N,N,N,N,N,N,
+40356,38760,36588,38077,N,N,N,N,N,N,N,N,N,N,N,N,N,37979,40182,64167,39897,N,N,
+N,N,N,N,N,N,N,64093,38486,38754,N,N,N,N,N,N,38074,41039,37592,N,N,N,39883,N,N,
+N,N,N,N,38075,N,N,40287,N,N,N,N,N,N,37071,N,N,N,N,N,N,N,N,N,N,N,N,N,37989,N,N,
+40780,N,N,N,N,N,N,37080,36187,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40638,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,64365,38346,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,40386,38904,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36860,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38003,
+38004,N,N,N,N,N,N,N,N,N,N,N,N,65207,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,37794,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39869,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38067,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,37757,40550,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-37977,N,N,N,N,N,N,N,N,N,39871,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35403,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37976,N,N,N,N,
+35413,35689,35548,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35702,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39886,N,35432,41208,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,39135,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,65205,N,N,N,39887,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38651,N,
+N,39931,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40654,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36581,N,
+N,N,N,N,N,N,N,N,40571,39890,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,35493,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,65230,35397,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,40444,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65231,35749,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35914,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,35564,N,N,64736,38061,65237,38060,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-40613,39879,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65108,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+64602,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39894,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,35439,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35753,36447,N,N,40395,N,
+64743,39895,N,N,N,N,N,N,N,N,N,N,N,37832,N,N,N,N,N,N,N,N,N,37360,36832,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39899,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37101,N,39900,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36179,41196,N,N,N,
+39162,N,N,N,N,N,N,N,N,N,39904,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,37831,37449,38625,39906,N,N,N,39908,N,N,36833,39909,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38080,N,N,37827,N,N,N,N,N,N,N,N,N,N,37829,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+36985,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38779,N,N,N,N,N,
+36990,N,N,N,N,65254,65094,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40376,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,37488,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38312,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,36016,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,38088,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39097,37184,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64702,N,N,N,N,N,N,N,37207,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35762,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64223,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,36468,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35798,N,N,N,N,N,N,
-38070,64884,39104,38053,N,N,N,N,N,N,N,39880,N,N,N,38381,64894,64491,N,N,N,N,N,
-N,N,N,N,N,64893,N,N,N,N,N,N,N,N,N,38767,37985,N,40897,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,38359,N,N,N,64082,40024,N,N,N,N,N,N,N,N,N,40808,39911,64718,
-38632,64073,38817,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-38221,40696,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65097,37326,38769,N,N,N,N,36047,N,
-N,N,64945,N,N,64622,N,N,N,N,N,40178,37816,36931,38745,38103,65126,38013,64623,
-N,N,N,N,37446,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64109,N,N,36599,N,64439,N,38012,
-37581,38834,N,N,N,N,N,N,N,N,N,65125,38526,38744,39799,37327,N,N,N,N,N,N,N,N,N,
-38052,N,N,N,N,N,N,N,N,N,N,40109,N,N,N,N,N,N,N,N,N,35755,N,N,N,38613,64691,N,N,
-N,37806,N,38765,N,N,N,N,N,N,37958,38391,N,N,N,N,N,N,N,N,40006,38235,37329,
-38132,N,65127,37541,N,N,N,65247,36011,N,39881,N,N,N,N,N,N,N,N,N,N,N,64749,
-65018,64712,65122,37372,65131,65017,64711,37198,40120,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,38759,N,N,N,38382,N,N,39858,N,N,N,N,37984,N,N,N,38050,39029,
-38828,37331,N,N,N,N,N,N,N,N,N,N,N,39035,N,N,N,N,N,N,N,36587,38762,38494,N,N,N,
-N,N,N,N,N,N,38891,N,N,N,N,N,40953,38392,65186,36838,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,65150,N,N,N,N,N,N,40356,38760,36588,38077,N,N,N,N,N,N,N,N,N,N,N,N,N,
-37979,40182,64167,39897,N,N,N,N,N,N,N,N,N,64093,38486,38754,N,N,N,N,N,N,38074,
-41039,37592,N,N,N,39883,N,N,N,N,N,N,38075,N,N,40287,N,N,N,N,N,N,37071,N,N,N,N,
-N,N,N,N,N,N,N,N,N,37989,N,N,40780,N,N,N,N,N,N,37080,40638,N,N,N,N,N,N,N,N,N,N,
+N,39910,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38467,36420,40015,65268,
+N,N,N,N,N,39912,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37852,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+38511,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36426,39917,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37622,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40377,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,64365,38346,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,36430,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,64463,34656,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40642,
+N,N,N,N,N,N,38117,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39920,38116,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,38225,35771,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39921,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,38128,36452,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38122,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36705,N,N,N,39780,36443,N,N,N,N,
+39922,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40894,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40393,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36460,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36723,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,36015,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,36725,36465,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36448,36458,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,35916,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38226,38228,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35540,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40379,38211,37630,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,38130,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38129,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41194,40402,41137,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37368,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,40386,38904,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,36860,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38003,38004,N,N,
-N,N,N,N,N,N,N,N,N,N,65207,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37986,39844,
+36525,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40621,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38608,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65262,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,35508,N,N,N,N,N,N,N,N,N,N,N,N,38743,35447,39927,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36533,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41069,
+36534,38742,38208,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,41203,38078,N,N,N,39930,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64991,40380,N,N,N,N,N,N,N,
+N,38142,N,N,N,N,N,N,N,N,35803,41214,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,36544,40775,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35806,41211,N,N,N,N,
+36547,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38473,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,65218,N,N,38220,39933,N,N,N,N,N,N,N,N,N,N,N,N,N,37068,
+40032,38219,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39934,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40048,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,40003,N,N,N,40007,36556,N,N,N,36436,N,N,N,N,N,N,N,N,N,N,36580,
+40009,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35678,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38238,N,N,N,N,N,N,N,
+N,N,N,N,N,38236,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40011,35809,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,36569,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40372,N,
+37471,N,N,N,40012,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,35489,N,N,N,N,N,N,N,N,N,N,N,N,N,36571,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,40022,35490,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,38740,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40030,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40660,38248,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,41155,35558,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,41207,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40033,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40031,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,64589,N,40539,N,N,N,N,N,N,N,N,40553,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40035,65223,N,N,65222,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40039,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,40041,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35810,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,37221,N,N,N,N,N,N,N,N,N,N,N,N,40167,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,35412,N,N,N,N,N,N,N,40044,40046,65117,N,N,N,N,N,40051,N,
+N,N,N,N,N,N,N,N,N,N,N,N,38250,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38253,36592,36685,N,
+N,N,N,36598,N,N,N,N,N,N,N,N,64188,N,36053,N,N,N,N,N,N,N,N,N,N,N,N,N,34654,N,N,
+N,N,64474,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,35660,64885,39901,64245,N,N,N,N,N,N,N,40052,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,38213,N,N,N,N,N,N,N,N,N,N,N,N,38598,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,36714,36686,N,N,N,N,N,40056,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,64085,N,N,N,N,N,N,N,N,N,N,N,N,38884,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,40001,37468,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+38650,36086,N,N,N,N,36173,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64358,36453,38985,
+64424,38978,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40058,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38907,37066,N,N,N,N,40027,N,N,38733,
+N,N,36563,N,N,N,N,N,N,N,N,N,N,N,N,N,38241,40779,40885,37842,64938,38976,37190,
+39015,64090,64425,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,38977,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,36051,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,64765,64939,37309,36684,38601,36693,64430,38255,N,N,
+N,N,N,N,40061,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,41200,N,N,N,N,N,N,N,N,N,N,N,N,N,37999,64940,N,N,N,N,
+38603,38606,N,N,N,N,41046,N,40161,N,N,N,N,N,N,N,N,N,N,38596,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+36702,36716,36515,64435,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,64595,N,N,N,64947,N,N,N,N,36715,N,N,N,N,N,N,N,N,N,N,
+N,N,38602,N,N,N,N,N,N,34643,N,N,N,N,N,N,N,N,N,N,N,N,N,36729,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,40559,41157,64632,36418,36698,37058,36517,36961,37455,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35403,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35413,
-35689,35548,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35702,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37747,64949,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39886,N,
-35432,41208,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,65228,N,64445,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36054,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38979,38597,
+35260,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40099,N,N,N,N,N,N,37451,38986,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,39135,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,65205,N,N,N,39887,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38651,N,N,39931,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,40654,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36581,N,N,N,N,N,
-N,N,N,N,40571,39890,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,35493,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,36772,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,41201,40699,40146,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,36775,N,N,N,N,34644,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64604,38981,N,N,36934,36049,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65274,38240,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,65230,35397,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,40444,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65231,35749,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,40776,37447,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37115,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35914,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,35564,N,N,64736,38061,65237,38060,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64602,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39894,N,N,N,N,N,N,
+N,40100,38257,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-35439,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35753,36447,N,N,40395,N,64743,39895,N,N,
-N,N,N,N,N,N,N,N,N,37832,N,N,N,N,N,N,N,N,N,37360,36832,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,39899,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,37101,N,39900,41196,N,N,N,39162,N,N,N,N,N,N,N,N,N,39904,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37831,37449,38625,39906,N,
-N,N,39908,N,N,36833,39909,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-38080,N,N,37827,N,N,N,N,N,N,N,N,N,N,37829,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36985,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,38779,N,N,N,N,N,36990,N,N,N,N,65254,65094,N,N,N,N,
+N,N,N,N,34629,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40102,N,N,N,N,
+40103,N,N,N,N,N,40106,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,40659,N,N,N,40560,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40108,34642,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,40376,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37488,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36782,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,38312,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36016,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38088,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,39097,37184,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,64702,N,N,N,N,N,N,N,37207,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-35762,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64223,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,36176,38269,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40112,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39910,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,38467,36420,40015,65268,N,N,N,N,N,39912,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,37852,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+38838,N,41149,35551,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40618,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38511,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,36426,39917,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,36797,N,N,N,36799,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37737,
+39847,51364,N,N,N,N,65258,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,39905,N,N,N,N,N,N,35649,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,40374,41195,39843,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,37622,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40377,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,35745,36808,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,35148,39008,N,N,N,N,N,N,N,N,N,N,38087,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,35672,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38315,38314,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36430,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64463,40642,N,N,N,N,N,
-N,38117,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39920,38116,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,40131,40132,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,37846,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,40364,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35814,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35441,36817,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,38225,35771,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39921,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-38128,36452,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38122,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36705,N,N,N,39780,36443,N,N,N,N,39922,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40894,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40393,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36460,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36723,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,36015,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36725,
-36465,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36448,36458,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,35916,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38226,38228,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,35540,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40379,38211,
-37630,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-38130,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38129,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,41194,40402,41137,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37368,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37986,39844,36525,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40621,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38608,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,65262,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35508,N,
-N,N,N,N,N,N,N,N,N,N,N,38743,35447,39927,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,36533,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41069,36534,38742,
-38208,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,41203,38078,N,N,N,39930,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64991,40380,N,N,N,N,N,N,N,N,38142,N,N,
-N,N,N,N,N,N,35803,41214,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36544,
-40775,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35806,41211,N,N,N,N,36547,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38473,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,65218,N,N,38220,39933,N,N,N,N,N,N,N,N,N,N,N,N,N,37068,40032,
-38219,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39934,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,40048,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,40003,N,N,N,40007,36556,N,N,N,36436,N,N,N,N,N,N,N,N,N,N,36580,40009,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35678,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38238,N,N,N,N,N,N,N,N,N,N,N,N,
-38236,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40011,35809,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,36569,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40372,N,37471,N,N,N,
-40012,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-35489,N,N,N,N,N,N,N,N,N,N,N,N,N,36571,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-40022,35490,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,38740,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40030,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,40660,38248,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-41155,35558,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,41207,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40033,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,40031,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,64589,N,40539,N,N,N,N,N,N,N,N,40553,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40035,65223,N,
-N,65222,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40039,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,40041,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35810,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,37221,N,N,N,N,N,N,N,N,N,N,N,N,40167,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,35412,N,N,N,N,N,N,N,40044,40046,65117,N,N,N,N,N,40051,N,N,N,N,N,N,N,N,
-N,N,N,N,N,38250,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38253,36592,36685,N,N,N,N,36598,N,
-N,N,N,N,N,N,N,64188,N,36053,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64474,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35660,
-64885,39901,64245,N,N,N,N,N,N,N,40052,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,38213,N,N,N,N,N,N,N,N,N,N,N,N,38598,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,36714,36686,N,N,N,N,N,40056,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64085,N,N,N,N,N,N,N,N,N,N,N,N,38884,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40001,37468,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38650,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64358,36453,38985,64424,38978,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40058,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,38907,37066,N,N,N,N,40027,N,N,38733,N,N,36563,N,N,N,N,N,N,N,N,N,
-N,N,N,N,38241,40779,40885,37842,64938,38976,37190,39015,64090,64425,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38977,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36051,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64765,64939,37309,36684,38601,36693,64430,38255,N,N,N,N,N,N,40061,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,39381,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37108,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35491,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-41200,N,N,N,N,N,N,N,N,N,N,N,N,N,37999,64940,N,N,N,N,38603,38606,N,N,N,N,41046,
-N,40161,N,N,N,N,N,N,N,N,N,N,38596,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36702,36716,36515,64435,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64595,N,N,N,64947,N,N,N,N,36715,N,N,N,N,N,N,N,N,N,N,N,N,38602,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,36729,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40559,41157,64632,
-36418,36698,37058,36517,36961,37455,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37747,64949,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65228,N,64445,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36054,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38979,38597,35260,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,40099,N,N,N,N,N,N,37451,38986,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36772,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41201,
-40699,40146,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36775,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,64604,38981,N,N,36934,36049,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,65274,38240,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40776,37447,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,37115,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40100,38257,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,40102,N,N,N,N,40103,N,N,N,N,N,40106,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40659,N,N,N,40560,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,40108,36782,38269,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40112,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38838,
-N,41149,35551,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,40618,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-36797,N,N,N,36799,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37737,39847,
-51364,N,N,N,N,65258,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,39905,N,N,N,N,N,N,35649,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,40374,41195,39843,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-35745,36808,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,35148,39008,N,N,N,N,N,N,N,N,N,N,38087,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,35672,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,38315,38314,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,40131,40132,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,37846,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,40364,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35814,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35441,36817,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,39381,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37108,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35491,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40142,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,40148,40149,N,N,N,64456,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40371,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64624,N,N,N,N,N,36823,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39795,N,N,N,N,N,N,N,N,N,N,64091,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40142,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40148,40149,N,N,N,64456,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40371,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64624,N,N,N,N,N,36823,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39795,N,N,N,N,N,N,N,N,N,N,64091,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,36818,36964,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39094,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36818,36964,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39094,
 38504,N,N,N,N,40150,N,N,N,N,N,N,N,N,N,N,N,N,39101,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36828,65270,36825,N,N,N,N,N,N,N,N,N,N,N,N,N,
 38209,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38899,39928,40556,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36850,36846,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,40151,N,N,N,N,N,N,N,N,N,N,N,N,40558,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,35392,N,N,N,N,N,N,N,N,N,N,36847,N,N,N,N,N,N,N,N,36852,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36853,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38338,39018,N,38863,40572,36929,N,N,N,
-N,N,N,40155,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37953,N,N,N,N,40166,40368,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40170,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40173,N,N,N,N,N,N,N,N,N,N,N,N,40186,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,35682,35406,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,40138,35430,N,N,N,N,N,N,N,N,N,N,40187,40188,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40190,N,N,N,N,N,N,N,N,N,N,N,
-N,N,35411,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40165,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,40256,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,40257,N,N,N,N,N,N,N,N,N,N,N,N,36933,35699,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,38858,N,40258,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-35425,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,35758,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35538,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,35746,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40434,40259,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40159,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,40260,N,N,N,N,N,N,N,N,N,N,36554,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36942,N,N,N,N,N,N,N,36531,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,40949,N,N,N,N,N,N,N,N,N,N,N,N,40261,36943,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,34668,N,N,N,N,38899,39928,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-40263,N,N,N,35274,N,N,N,N,N,N,40117,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64510,36958,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36963,36951,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36966,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,39872,N,N,N,N,N,N,N,N,N,N,N,64741,37218,N,N,N,N,N,N,N,N,N,N,36967,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36769,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,36770,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,40264,64211,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36957,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,37049,N,N,N,N,N,N,N,N,N,N,N,N,N,36971,35932,N,N,N,
-36969,65111,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,65109,36979,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39919,40176,N,N,
-N,N,N,N,N,N,N,N,N,N,40267,N,N,N,N,N,N,N,N,N,N,N,N,N,65241,N,N,N,65242,N,N,N,
-37344,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37336,N,N,N,N,N,N,N,N,N,N,38470,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37728,N,64083,40147,N,N,
-N,N,N,N,N,N,N,N,N,N,40270,N,N,N,64320,N,N,N,36322,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,37954,N,36950,N,N,39013,N,35948,64074,N,N,40272,
-40274,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38319,38746,37705,38727,41204,N,N,N,N,N,
-N,38776,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36815,N,N,N,64608,N,N,N,N,N,N,N,N,35918,N,
-N,N,64598,N,N,N,N,N,N,N,N,N,N,N,N,N,37340,38497,37612,37725,36574,38654,64847,
-38366,N,N,N,N,N,N,N,N,N,N,N,N,N,39088,41024,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38845,38781,38901,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,39852,64218,37570,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38833,N,N,N,N,N,36987,N,N,N,N,37886,38011,
-N,38775,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64190,64835,37062,37028,37032,38057,N,
-37033,N,N,N,N,35941,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38368,36989,N,N,N,N,N,N,
-37477,N,N,N,N,N,N,N,N,N,N,N,N,N,64954,37828,N,N,N,N,N,N,N,N,65261,40363,41187,
-N,38472,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40275,N,N,N,N,N,35497,N,
-39877,N,38493,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38751,38495,38510,64349,N,N,
-N,N,N,40369,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,65187,N,N,N,N,N,N,N,N,N,40370,N,N,38318,64675,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41122,N,N,38485,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,40276,N,N,37697,N,38317,37333,N,N,N,N,N,N,N,N,N,N,N,N,38778,65020,
-36423,37885,37029,37036,N,N,N,N,N,N,N,N,38316,N,N,N,N,N,N,N,N,N,37038,65189,N,
-N,N,N,N,40278,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38883,38370,N,N,N,N,N,37990,
-N,N,38471,N,N,N,N,37304,N,N,N,N,40172,N,N,N,N,N,N,N,N,37037,N,38371,N,N,N,N,N,
+34650,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34632,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34634,40556,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36850,36846,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,40151,N,N,N,N,N,N,N,N,N,N,N,N,40558,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35392,N,
+N,N,N,N,N,N,N,N,N,36847,N,N,N,N,N,N,N,N,36852,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36853,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,38338,39018,N,38863,40677,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40572,
+36929,N,N,N,N,N,N,40155,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37953,N,N,N,N,
+40166,40368,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,40170,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40173,N,N,N,N,N,N,N,N,N,N,N,N,
+40186,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,35682,35406,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40138,35430,N,N,N,N,N,N,N,N,N,N,40187,40188,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40190,N,N,N,N,N,
+N,N,N,N,N,N,N,N,35411,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40165,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40256,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40257,N,N,N,N,N,N,N,N,N,N,N,N,36933,35699,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38858,N,40258,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,35425,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,35758,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35538,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,35746,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40434,
+40259,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40159,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,40260,N,N,N,N,N,N,N,N,N,N,36554,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36942,N,N,N,N,N,N,N,36531,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,40949,N,N,N,N,N,N,N,N,N,N,N,N,40261,36943,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,40263,N,N,N,35274,N,N,N,N,N,N,40117,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64510,
+36958,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36963,36951,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36966,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,39872,N,N,N,N,N,N,N,N,N,N,N,64741,37218,N,N,N,N,N,N,N,N,N,N,36967,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36769,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,36770,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,40264,64211,N,N,N,N,N,N,36175,N,N,N,N,N,N,N,N,N,36957,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37049,N,N,N,N,N,N,N,N,N,N,N,N,N,36971,
+35932,N,N,N,36969,65111,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,65109,36979,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+39919,40176,N,N,N,N,N,N,N,N,N,N,N,N,40267,N,N,N,N,N,N,N,N,N,N,N,N,N,65241,N,N,
+N,65242,N,N,N,37344,36163,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37336,N,N,N,N,N,N,N,
+N,N,N,38470,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37728,
+N,64083,40147,N,N,N,N,N,N,N,N,N,N,N,N,40270,N,N,N,64320,N,N,N,36322,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37954,N,36950,N,N,39013,N,35948,
+64074,N,N,40272,40274,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38319,38746,37705,38727,
+41204,N,N,N,N,N,N,38776,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36815,N,N,N,64608,N,N,N,N,
+N,N,N,N,35918,N,N,N,64598,N,N,N,N,N,N,N,N,N,N,N,N,N,37340,38497,37612,37725,
+36574,38654,64847,38366,N,N,N,N,N,N,N,N,N,N,N,N,N,39088,41024,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38845,38781,38901,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39852,64218,37570,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38833,N,N,N,N,N,36987,N,
+N,N,N,37886,38011,N,38775,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64190,64835,37062,
+37028,37032,38057,N,37033,N,N,N,N,35941,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+38368,36989,N,N,N,N,N,N,37477,N,N,N,N,N,N,N,N,N,N,N,N,N,64954,37828,N,N,N,N,N,
+N,N,N,65261,40363,41187,N,38472,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40275,N,N,N,N,N,35497,N,39877,N,38493,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+38751,38495,38510,64349,N,N,N,N,N,40369,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65187,N,N,N,N,N,N,N,N,N,40370,N,N,38318,64675,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34665,N,N,N,N,N,N,N,N,
+41122,N,N,38485,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40276,N,N,37697,N,38317,37333,N,N,
+N,N,N,N,N,N,N,N,N,N,38778,65020,36423,37885,37029,37036,N,N,N,N,N,N,N,N,38316,
+N,N,N,N,N,N,N,N,N,37038,65189,N,N,N,N,N,40278,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,38883,38370,N,N,N,N,N,37990,N,N,38471,N,N,N,N,37304,N,N,N,N,40172,N,N,N,N,
+N,N,N,N,37037,N,38371,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35663,
+N,N,35555,N,N,N,N,35661,38378,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35663,N,N,35555,N,N,N,N,35661,38378,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35662,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36033,35821,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37337,N,N,41124,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38389,38388,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,40883,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65199,N,N,N,N,
-N,65138,37498,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,65196,N,N,N,N,N,N,N,N,N,N,N,N,N,38387,40280,37746,N,N,37317,N,N,N,N,
-N,N,N,38466,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37069,38398,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35662,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36033,
+35821,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,37337,N,N,41124,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,38389,38388,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40883,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,65199,N,N,N,N,N,65138,37498,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,65196,N,N,N,N,N,N,N,N,N,N,N,
+N,N,38387,40280,36166,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37746,N,N,37317,N,N,N,N,N,N,
+N,38466,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37069,38398,
 37209,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40037,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38860,37070,N,N,N,N,N,N,40281,64757,65277,N,N,
 40283,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
@@ -2168,70 +2203,72 @@
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,40129,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,40296,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-37799,N,N,N,N,N,N,38516,41199,N,37201,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38593,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,35940,38518,40297,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64676,
-N,N,N,N,N,N,N,N,N,N,N,N,40298,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37454,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40299,N,N,N,N,N,39873,
-40300,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-35429,37213,N,N,N,N,N,N,N,N,40301,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+37799,N,N,N,N,N,N,38516,N,N,N,N,N,N,N,N,36093,41199,N,37201,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38593,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,34679,N,35940,38518,40297,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,64676,N,N,N,N,N,N,N,N,N,N,N,N,40298,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+37454,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,40299,N,N,N,N,N,39873,40300,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,35429,37213,N,N,N,N,N,N,N,N,40301,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37210,35906,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37210,35906,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40128,37226,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,40302,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,40614,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+40397,N,N,40303,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,40128,37226,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-40302,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40614,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40397,N,N,40303,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35259,40697,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38580,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,37234,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,35259,40697,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,38580,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37234,N,
+40648,N,N,N,34673,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35669,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40648,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,35669,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40305,40306,N,N,N,N,
-N,N,N,N,N,N,N,N,40652,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,40305,40306,N,N,N,N,N,N,N,N,N,N,N,N,40652,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37236,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40656,36956,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,37236,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,40656,36956,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36562,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,37288,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,37239,N,N,N,N,N,N,N,N,N,N,N,38591,N,N,N,N,N,38592,N,N,N,N,
-36785,N,N,N,N,N,38583,35925,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,37240,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35262,37244,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,64375,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,36562,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37288,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37239,N,N,N,N,N,N,N,N,N,N,N,
+38591,N,N,N,N,N,38592,N,N,N,N,36785,N,N,N,N,N,38583,35925,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37240,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35262,
+37244,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64375,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,37237,37283,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37238,N,N,N,
-N,N,N,N,N,38590,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,37241,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,38582,
-37284,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37286,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37237,37283,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,37238,N,N,N,N,N,N,N,N,38590,36169,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37241,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,38582,37284,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+37286,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40309,N,N,N,N,N,N,N,N,N,N,N,36946,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,41029,N,37289,N,39082,N,N,N,35935,N,N,35754,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40157,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40311,34646,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,40309,N,N,N,N,N,N,N,N,N,N,N,36946,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-41029,N,37289,N,39082,N,N,N,35935,N,N,35754,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40157,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,40311,35136,40684,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,37802,38008,N,N,N,N,40314,35529,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,35659,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40940,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,35554,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,35136,40684,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,37802,38008,N,N,N,N,40314,35529,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35659,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40940,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+35554,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,40565,39028,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,39624,N,N,N,N,41031,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35779,N,N,N,N,N,N,N,N,N,
-N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64584,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-64631,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-N,N,40018,36605,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-36776,N,N,N,N,N,N,N,N,N,38266,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
-36848,
+N,N,40565,39028,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,39624,N,N,N,N,41031,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,35779,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,64584,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,64631,N,N,N,N,N,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,40018,36605,N,N,N,N,
+N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36776,N,N,N,N,N,N,N,N,N,
+38266,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,36848,
 };
 
 static const struct unim_index big5hkscs_nonbmp_encmap[256] = {
@@ -2249,84 +2286,84 @@
 253},{__big5hkscs_nonbmp_encmap+4292,119,150},{__big5hkscs_nonbmp_encmap+4324,
 10,254},{__big5hkscs_nonbmp_encmap+4569,13,252},{__big5hkscs_nonbmp_encmap+
 4809,32,250},{__big5hkscs_nonbmp_encmap+5028,3,243},{__big5hkscs_nonbmp_encmap
-+5269,45,75},{__big5hkscs_nonbmp_encmap+5300,68,194},{
-__big5hkscs_nonbmp_encmap+5427,42,172},{__big5hkscs_nonbmp_encmap+5558,70,249
-},{__big5hkscs_nonbmp_encmap+5738,28,213},{__big5hkscs_nonbmp_encmap+5924,15,
-232},{__big5hkscs_nonbmp_encmap+6142,69,252},{__big5hkscs_nonbmp_encmap+6326,
-42,195},{__big5hkscs_nonbmp_encmap+6480,8,124},{__big5hkscs_nonbmp_encmap+6597
-,33,250},{__big5hkscs_nonbmp_encmap+6815,101,237},{__big5hkscs_nonbmp_encmap+
-6952,19,190},{__big5hkscs_nonbmp_encmap+7124,27,246},{
-__big5hkscs_nonbmp_encmap+7344,18,205},{__big5hkscs_nonbmp_encmap+7532,3,247},
-{__big5hkscs_nonbmp_encmap+7777,38,147},{__big5hkscs_nonbmp_encmap+7887,102,
-232},{__big5hkscs_nonbmp_encmap+8018,14,206},{__big5hkscs_nonbmp_encmap+8211,
-38,201},{__big5hkscs_nonbmp_encmap+8375,7,238},{__big5hkscs_nonbmp_encmap+8607
-,13,239},{__big5hkscs_nonbmp_encmap+8834,116,227},{__big5hkscs_nonbmp_encmap+
-8946,51,218},{__big5hkscs_nonbmp_encmap+9114,3,249},{__big5hkscs_nonbmp_encmap
-+9361,15,225},{__big5hkscs_nonbmp_encmap+9572,0,254},{
-__big5hkscs_nonbmp_encmap+9827,0,229},{__big5hkscs_nonbmp_encmap+10057,25,243
-},{__big5hkscs_nonbmp_encmap+10276,0,238},{__big5hkscs_nonbmp_encmap+10515,3,
-215},{__big5hkscs_nonbmp_encmap+10728,58,58},{__big5hkscs_nonbmp_encmap+10729,
-194,194},{__big5hkscs_nonbmp_encmap+10730,167,250},{__big5hkscs_nonbmp_encmap+
-10814,90,90},{__big5hkscs_nonbmp_encmap+10815,99,255},{
-__big5hkscs_nonbmp_encmap+10972,64,248},{__big5hkscs_nonbmp_encmap+11157,17,
-252},{__big5hkscs_nonbmp_encmap+11393,53,240},{__big5hkscs_nonbmp_encmap+11581
-,17,225},{__big5hkscs_nonbmp_encmap+11790,4,252},{__big5hkscs_nonbmp_encmap+
-12039,27,250},{__big5hkscs_nonbmp_encmap+12263,13,248},{
-__big5hkscs_nonbmp_encmap+12499,4,214},{__big5hkscs_nonbmp_encmap+12710,5,200
-},{__big5hkscs_nonbmp_encmap+12906,24,212},{__big5hkscs_nonbmp_encmap+13095,6,
-224},{__big5hkscs_nonbmp_encmap+13314,18,255},{__big5hkscs_nonbmp_encmap+13552
-,0,251},{__big5hkscs_nonbmp_encmap+13804,14,233},{__big5hkscs_nonbmp_encmap+
-14024,110,245},{__big5hkscs_nonbmp_encmap+14160,9,217},{
-__big5hkscs_nonbmp_encmap+14369,6,235},{__big5hkscs_nonbmp_encmap+14599,59,167
-},{__big5hkscs_nonbmp_encmap+14708,14,194},{__big5hkscs_nonbmp_encmap+14889,
-44,157},{__big5hkscs_nonbmp_encmap+15003,43,231},{__big5hkscs_nonbmp_encmap+
-15192,32,216},{__big5hkscs_nonbmp_encmap+15377,14,19},{
-__big5hkscs_nonbmp_encmap+15383,25,110},{__big5hkscs_nonbmp_encmap+15469,49,
-224},{__big5hkscs_nonbmp_encmap+15645,5,246},{__big5hkscs_nonbmp_encmap+15887,
-6,225},{__big5hkscs_nonbmp_encmap+16107,87,225},{__big5hkscs_nonbmp_encmap+
-16246,3,204},{__big5hkscs_nonbmp_encmap+16448,149,233},{
-__big5hkscs_nonbmp_encmap+16533,116,232},{__big5hkscs_nonbmp_encmap+16650,1,
-254},{__big5hkscs_nonbmp_encmap+16904,32,67},{__big5hkscs_nonbmp_encmap+16940,
-14,216},{__big5hkscs_nonbmp_encmap+17143,26,226},{__big5hkscs_nonbmp_encmap+
-17344,41,165},{__big5hkscs_nonbmp_encmap+17469,2,221},{
-__big5hkscs_nonbmp_encmap+17689,88,208},{__big5hkscs_nonbmp_encmap+17810,53,
-248},{__big5hkscs_nonbmp_encmap+18006,2,152},{__big5hkscs_nonbmp_encmap+18157,
-18,191},{__big5hkscs_nonbmp_encmap+18331,18,252},{__big5hkscs_nonbmp_encmap+
-18566,22,204},{__big5hkscs_nonbmp_encmap+18749,28,199},{
-__big5hkscs_nonbmp_encmap+18921,14,250},{__big5hkscs_nonbmp_encmap+19158,45,82
-},{__big5hkscs_nonbmp_encmap+19196,5,247},{__big5hkscs_nonbmp_encmap+19439,33,
-209},{__big5hkscs_nonbmp_encmap+19616,34,240},{__big5hkscs_nonbmp_encmap+19823
-,0,215},{__big5hkscs_nonbmp_encmap+20039,38,223},{__big5hkscs_nonbmp_encmap+
-20225,14,248},{__big5hkscs_nonbmp_encmap+20460,9,205},{
-__big5hkscs_nonbmp_encmap+20657,27,230},{__big5hkscs_nonbmp_encmap+20861,154,
-154},{__big5hkscs_nonbmp_encmap+20862,34,134},{__big5hkscs_nonbmp_encmap+20963
-,116,254},{__big5hkscs_nonbmp_encmap+21102,7,148},{__big5hkscs_nonbmp_encmap+
-21244,15,204},{__big5hkscs_nonbmp_encmap+21434,88,200},{
-__big5hkscs_nonbmp_encmap+21547,36,253},{__big5hkscs_nonbmp_encmap+21765,10,
-244},{__big5hkscs_nonbmp_encmap+22000,6,244},{__big5hkscs_nonbmp_encmap+22239,
-18,18},{__big5hkscs_nonbmp_encmap+22240,47,220},{__big5hkscs_nonbmp_encmap+
-22414,77,79},{__big5hkscs_nonbmp_encmap+22417,249,249},{
-__big5hkscs_nonbmp_encmap+22418,2,244},{__big5hkscs_nonbmp_encmap+22661,46,188
-},{__big5hkscs_nonbmp_encmap+22804,7,226},{__big5hkscs_nonbmp_encmap+23024,6,
-138},{__big5hkscs_nonbmp_encmap+23157,18,130},{__big5hkscs_nonbmp_encmap+23270
-,1,244},{__big5hkscs_nonbmp_encmap+23514,0,230},{__big5hkscs_nonbmp_encmap+
-23745,15,19},{__big5hkscs_nonbmp_encmap+23750,4,43},{__big5hkscs_nonbmp_encmap
-+23790,51,252},{__big5hkscs_nonbmp_encmap+23992,15,252},{
-__big5hkscs_nonbmp_encmap+24230,12,255},{__big5hkscs_nonbmp_encmap+24474,3,210
-},{__big5hkscs_nonbmp_encmap+24682,52,185},{__big5hkscs_nonbmp_encmap+24816,
-15,231},{__big5hkscs_nonbmp_encmap+25033,197,197},{__big5hkscs_nonbmp_encmap+
-25034,136,237},{__big5hkscs_nonbmp_encmap+25136,13,235},{0,0,0},{0,0,0},{
-__big5hkscs_nonbmp_encmap+25359,29,231},{__big5hkscs_nonbmp_encmap+25562,158,
-244},{0,0,0},{__big5hkscs_nonbmp_encmap+25649,32,212},{
-__big5hkscs_nonbmp_encmap+25830,16,241},{__big5hkscs_nonbmp_encmap+26056,3,201
-},{__big5hkscs_nonbmp_encmap+26255,40,77},{__big5hkscs_nonbmp_encmap+26293,5,
-213},{__big5hkscs_nonbmp_encmap+26502,115,173},{__big5hkscs_nonbmp_encmap+
-26561,62,246},{__big5hkscs_nonbmp_encmap+26746,6,248},{
-__big5hkscs_nonbmp_encmap+26989,35,222},{__big5hkscs_nonbmp_encmap+27177,20,
-254},{__big5hkscs_nonbmp_encmap+27412,7,245},{__big5hkscs_nonbmp_encmap+27651,
-32,255},{__big5hkscs_nonbmp_encmap+27875,169,169},{__big5hkscs_nonbmp_encmap+
-27876,52,91},{__big5hkscs_nonbmp_encmap+27916,198,203},{
-__big5hkscs_nonbmp_encmap+27922,1,169},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0
++5269,45,99},{__big5hkscs_nonbmp_encmap+5324,68,194},{
+__big5hkscs_nonbmp_encmap+5451,42,172},{__big5hkscs_nonbmp_encmap+5582,70,249
+},{__big5hkscs_nonbmp_encmap+5762,28,213},{__big5hkscs_nonbmp_encmap+5948,15,
+232},{__big5hkscs_nonbmp_encmap+6166,69,252},{__big5hkscs_nonbmp_encmap+6350,
+42,195},{__big5hkscs_nonbmp_encmap+6504,8,124},{__big5hkscs_nonbmp_encmap+6621
+,33,250},{__big5hkscs_nonbmp_encmap+6839,101,237},{__big5hkscs_nonbmp_encmap+
+6976,19,190},{__big5hkscs_nonbmp_encmap+7148,27,246},{
+__big5hkscs_nonbmp_encmap+7368,18,205},{__big5hkscs_nonbmp_encmap+7556,3,247},
+{__big5hkscs_nonbmp_encmap+7801,38,147},{__big5hkscs_nonbmp_encmap+7911,102,
+232},{__big5hkscs_nonbmp_encmap+8042,14,206},{__big5hkscs_nonbmp_encmap+8235,
+38,201},{__big5hkscs_nonbmp_encmap+8399,7,238},{__big5hkscs_nonbmp_encmap+8631
+,13,239},{__big5hkscs_nonbmp_encmap+8858,116,227},{__big5hkscs_nonbmp_encmap+
+8970,51,218},{__big5hkscs_nonbmp_encmap+9138,3,249},{__big5hkscs_nonbmp_encmap
++9385,15,225},{__big5hkscs_nonbmp_encmap+9596,0,254},{
+__big5hkscs_nonbmp_encmap+9851,0,229},{__big5hkscs_nonbmp_encmap+10081,25,243
+},{__big5hkscs_nonbmp_encmap+10300,0,238},{__big5hkscs_nonbmp_encmap+10539,3,
+215},{__big5hkscs_nonbmp_encmap+10752,58,58},{__big5hkscs_nonbmp_encmap+10753,
+194,194},{__big5hkscs_nonbmp_encmap+10754,167,250},{__big5hkscs_nonbmp_encmap+
+10838,26,90},{__big5hkscs_nonbmp_encmap+10903,99,255},{
+__big5hkscs_nonbmp_encmap+11060,64,248},{__big5hkscs_nonbmp_encmap+11245,6,252
+},{__big5hkscs_nonbmp_encmap+11492,53,240},{__big5hkscs_nonbmp_encmap+11680,
+17,236},{__big5hkscs_nonbmp_encmap+11900,4,252},{__big5hkscs_nonbmp_encmap+
+12149,27,250},{__big5hkscs_nonbmp_encmap+12373,13,248},{
+__big5hkscs_nonbmp_encmap+12609,4,214},{__big5hkscs_nonbmp_encmap+12820,5,200
+},{__big5hkscs_nonbmp_encmap+13016,24,212},{__big5hkscs_nonbmp_encmap+13205,6,
+224},{__big5hkscs_nonbmp_encmap+13424,18,255},{__big5hkscs_nonbmp_encmap+13662
+,0,251},{__big5hkscs_nonbmp_encmap+13914,14,233},{__big5hkscs_nonbmp_encmap+
+14134,15,245},{__big5hkscs_nonbmp_encmap+14365,9,217},{
+__big5hkscs_nonbmp_encmap+14574,6,235},{__big5hkscs_nonbmp_encmap+14804,59,167
+},{__big5hkscs_nonbmp_encmap+14913,14,194},{__big5hkscs_nonbmp_encmap+15094,
+44,157},{__big5hkscs_nonbmp_encmap+15208,43,231},{__big5hkscs_nonbmp_encmap+
+15397,32,216},{__big5hkscs_nonbmp_encmap+15582,14,19},{
+__big5hkscs_nonbmp_encmap+15588,25,154},{__big5hkscs_nonbmp_encmap+15718,49,
+224},{__big5hkscs_nonbmp_encmap+15894,5,246},{__big5hkscs_nonbmp_encmap+16136,
+6,225},{__big5hkscs_nonbmp_encmap+16356,87,225},{__big5hkscs_nonbmp_encmap+
+16495,3,204},{__big5hkscs_nonbmp_encmap+16697,84,233},{
+__big5hkscs_nonbmp_encmap+16847,116,232},{__big5hkscs_nonbmp_encmap+16964,1,
+254},{__big5hkscs_nonbmp_encmap+17218,32,67},{__big5hkscs_nonbmp_encmap+17254,
+14,216},{__big5hkscs_nonbmp_encmap+17457,26,226},{__big5hkscs_nonbmp_encmap+
+17658,41,165},{__big5hkscs_nonbmp_encmap+17783,2,221},{
+__big5hkscs_nonbmp_encmap+18003,88,208},{__big5hkscs_nonbmp_encmap+18124,53,
+248},{__big5hkscs_nonbmp_encmap+18320,2,152},{__big5hkscs_nonbmp_encmap+18471,
+18,191},{__big5hkscs_nonbmp_encmap+18645,18,252},{__big5hkscs_nonbmp_encmap+
+18880,22,204},{__big5hkscs_nonbmp_encmap+19063,28,199},{
+__big5hkscs_nonbmp_encmap+19235,14,250},{__big5hkscs_nonbmp_encmap+19472,45,82
+},{__big5hkscs_nonbmp_encmap+19510,5,247},{__big5hkscs_nonbmp_encmap+19753,33,
+209},{__big5hkscs_nonbmp_encmap+19930,34,240},{__big5hkscs_nonbmp_encmap+20137
+,0,215},{__big5hkscs_nonbmp_encmap+20353,38,223},{__big5hkscs_nonbmp_encmap+
+20539,14,248},{__big5hkscs_nonbmp_encmap+20774,9,205},{
+__big5hkscs_nonbmp_encmap+20971,27,230},{__big5hkscs_nonbmp_encmap+21175,82,
+255},{__big5hkscs_nonbmp_encmap+21349,34,134},{__big5hkscs_nonbmp_encmap+21450
+,116,254},{__big5hkscs_nonbmp_encmap+21589,7,148},{__big5hkscs_nonbmp_encmap+
+21731,15,204},{__big5hkscs_nonbmp_encmap+21921,88,200},{
+__big5hkscs_nonbmp_encmap+22034,36,253},{__big5hkscs_nonbmp_encmap+22252,10,
+244},{__big5hkscs_nonbmp_encmap+22487,6,244},{__big5hkscs_nonbmp_encmap+22726,
+18,197},{__big5hkscs_nonbmp_encmap+22906,47,220},{__big5hkscs_nonbmp_encmap+
+23080,77,79},{__big5hkscs_nonbmp_encmap+23083,46,249},{
+__big5hkscs_nonbmp_encmap+23287,2,244},{__big5hkscs_nonbmp_encmap+23530,46,188
+},{__big5hkscs_nonbmp_encmap+23673,7,226},{__big5hkscs_nonbmp_encmap+23893,6,
+138},{__big5hkscs_nonbmp_encmap+24026,18,130},{__big5hkscs_nonbmp_encmap+24139
+,1,244},{__big5hkscs_nonbmp_encmap+24383,0,230},{__big5hkscs_nonbmp_encmap+
+24614,15,19},{__big5hkscs_nonbmp_encmap+24619,4,43},{__big5hkscs_nonbmp_encmap
++24659,51,252},{__big5hkscs_nonbmp_encmap+24861,15,252},{
+__big5hkscs_nonbmp_encmap+25099,12,255},{__big5hkscs_nonbmp_encmap+25343,3,210
+},{__big5hkscs_nonbmp_encmap+25551,52,185},{__big5hkscs_nonbmp_encmap+25685,
+15,231},{__big5hkscs_nonbmp_encmap+25902,197,197},{__big5hkscs_nonbmp_encmap+
+25903,121,237},{__big5hkscs_nonbmp_encmap+26020,13,235},{0,0,0},{0,0,0},{
+__big5hkscs_nonbmp_encmap+26243,29,231},{__big5hkscs_nonbmp_encmap+26446,158,
+244},{0,0,0},{__big5hkscs_nonbmp_encmap+26533,32,212},{
+__big5hkscs_nonbmp_encmap+26714,16,250},{__big5hkscs_nonbmp_encmap+26949,3,201
+},{__big5hkscs_nonbmp_encmap+27148,40,77},{__big5hkscs_nonbmp_encmap+27186,5,
+213},{__big5hkscs_nonbmp_encmap+27395,115,173},{__big5hkscs_nonbmp_encmap+
+27454,62,246},{__big5hkscs_nonbmp_encmap+27639,6,248},{
+__big5hkscs_nonbmp_encmap+27882,35,222},{__big5hkscs_nonbmp_encmap+28070,20,
+254},{__big5hkscs_nonbmp_encmap+28305,7,245},{__big5hkscs_nonbmp_encmap+28544,
+32,255},{__big5hkscs_nonbmp_encmap+28768,81,169},{__big5hkscs_nonbmp_encmap+
+28857,52,91},{__big5hkscs_nonbmp_encmap+28897,198,203},{
+__big5hkscs_nonbmp_encmap+28903,1,169},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0
 },{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,
 0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{
 0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0
@@ -2335,6 +2372,7 @@
 0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0
 },{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,
 0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{
-__big5hkscs_nonbmp_encmap+28091,37,205},{__big5hkscs_nonbmp_encmap+28260,148,
+__big5hkscs_nonbmp_encmap+29072,37,205},{__big5hkscs_nonbmp_encmap+29241,148,
 212},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},
 };
+

Modified: python/branches/py3k-importlib/Modules/cjkcodecs/multibytecodec.c
==============================================================================
--- python/branches/py3k-importlib/Modules/cjkcodecs/multibytecodec.c	(original)
+++ python/branches/py3k-importlib/Modules/cjkcodecs/multibytecodec.c	Thu Mar 27 00:48:05 2008
@@ -65,7 +65,7 @@
 	}
 	PyTuple_SET_ITEM(v, 0, object);
 
-	w = PyInt_FromSsize_t(len);
+	w = PyLong_FromSsize_t(len);
 	if (w == NULL) {
 		Py_DECREF(v);
 		return NULL;
@@ -175,15 +175,15 @@
 	Py_ssize_t orgpos, orgsize;
 
 	orgpos = (Py_ssize_t)((char *)buf->outbuf -
-				PyBytes_AS_STRING(buf->outobj));
-	orgsize = PyBytes_GET_SIZE(buf->outobj);
-	if (PyBytes_Resize(buf->outobj, orgsize + (
+				PyString_AS_STRING(buf->outobj));
+	orgsize = PyString_GET_SIZE(buf->outobj);
+	if (_PyString_Resize(&buf->outobj, orgsize + (
 	    esize < (orgsize >> 1) ? (orgsize >> 1) | 1 : esize)) == -1)
 		return -1;
 
-	buf->outbuf = (unsigned char *)PyBytes_AS_STRING(buf->outobj) +orgpos;
-	buf->outbuf_end = (unsigned char *)PyBytes_AS_STRING(buf->outobj)
-		+ PyBytes_GET_SIZE(buf->outobj);
+	buf->outbuf = (unsigned char *)PyString_AS_STRING(buf->outobj) +orgpos;
+	buf->outbuf_end = (unsigned char *)PyString_AS_STRING(buf->outobj)
+		+ PyString_GET_SIZE(buf->outobj);
 
 	return 0;
 }
@@ -313,8 +313,7 @@
 
 	if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 ||
 	    !PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0))) ||
-	    !(PyInt_Check(PyTuple_GET_ITEM(retobj, 1)) ||
-	      PyLong_Check(PyTuple_GET_ITEM(retobj, 1)))) {
+	    !PyLong_Check(PyTuple_GET_ITEM(retobj, 1))) {
 		PyErr_SetString(PyExc_TypeError,
 				"encoding error handler must return "
 				"(unicode, int) tuple");
@@ -331,14 +330,14 @@
 			goto errorexit;
 	}
 
-        assert(PyBytes_Check(retstr));
-	retstrsize = PyBytes_GET_SIZE(retstr);
+        assert(PyString_Check(retstr));
+	retstrsize = PyString_GET_SIZE(retstr);
 	REQUIRE_ENCODEBUFFER(buf, retstrsize);
 
-	memcpy(buf->outbuf, PyBytes_AS_STRING(retstr), retstrsize);
+	memcpy(buf->outbuf, PyString_AS_STRING(retstr), retstrsize);
 	buf->outbuf += retstrsize;
 
-	newpos = PyInt_AsSsize_t(PyTuple_GET_ITEM(retobj, 1));
+	newpos = PyLong_AsSsize_t(PyTuple_GET_ITEM(retobj, 1));
 	if (newpos < 0 && !PyErr_Occurred())
 		newpos += (Py_ssize_t)(buf->inbuf_end - buf->inbuf_top);
 	if (newpos < 0 || buf->inbuf_top + newpos > buf->inbuf_end) {
@@ -433,8 +432,7 @@
 
 	if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 ||
 	    !PyUnicode_Check((retuni = PyTuple_GET_ITEM(retobj, 0))) ||
-	    !(PyInt_Check(PyTuple_GET_ITEM(retobj, 1)) ||
-	      PyLong_Check(PyTuple_GET_ITEM(retobj, 1)))) {
+	    !PyLong_Check(PyTuple_GET_ITEM(retobj, 1))) {
 		PyErr_SetString(PyExc_TypeError,
 				"decoding error handler must return "
 				"(unicode, int) tuple");
@@ -449,7 +447,7 @@
 		buf->outbuf += retunisize;
 	}
 
-	newpos = PyInt_AsSsize_t(PyTuple_GET_ITEM(retobj, 1));
+	newpos = PyLong_AsSsize_t(PyTuple_GET_ITEM(retobj, 1));
 	if (newpos < 0 && !PyErr_Occurred())
 		newpos += (Py_ssize_t)(buf->inbuf_end - buf->inbuf_top);
 	if (newpos < 0 || buf->inbuf_top + newpos > buf->inbuf_end) {
@@ -478,16 +476,16 @@
 	Py_ssize_t finalsize, r = 0;
 
 	if (datalen == 0)
-		return PyBytes_FromStringAndSize(NULL, 0);
+		return PyString_FromStringAndSize(NULL, 0);
 
 	buf.excobj = NULL;
 	buf.inbuf = buf.inbuf_top = *data;
 	buf.inbuf_end = buf.inbuf_top + datalen;
-	buf.outobj = PyBytes_FromStringAndSize(NULL, datalen * 2 + 16);
+	buf.outobj = PyString_FromStringAndSize(NULL, datalen * 2 + 16);
 	if (buf.outobj == NULL)
 		goto errorexit;
-	buf.outbuf = (unsigned char *)PyBytes_AS_STRING(buf.outobj);
-	buf.outbuf_end = buf.outbuf + PyBytes_GET_SIZE(buf.outobj);
+	buf.outbuf = (unsigned char *)PyString_AS_STRING(buf.outobj);
+	buf.outbuf_end = buf.outbuf + PyString_GET_SIZE(buf.outobj);
 
 	while (buf.inbuf < buf.inbuf_end) {
 		Py_ssize_t inleft, outleft;
@@ -522,10 +520,10 @@
 		}
 
 	finalsize = (Py_ssize_t)((char *)buf.outbuf -
-				 PyBytes_AS_STRING(buf.outobj));
+				 PyString_AS_STRING(buf.outobj));
 
-	if (finalsize != PyBytes_GET_SIZE(buf.outobj))
-		if (PyBytes_Resize(buf.outobj, finalsize) == -1)
+	if (finalsize != PyString_GET_SIZE(buf.outobj))
+		if (_PyString_Resize(&buf.outobj, finalsize) == -1)
 			goto errorexit;
 
 	Py_XDECREF(buf.excobj);
@@ -554,7 +552,7 @@
 	if (PyUnicode_Check(arg))
 		ucvt = NULL;
 	else {
-		arg = ucvt = PyObject_Unicode(arg);
+		arg = ucvt = PyObject_Str(arg);
 		if (arg == NULL)
 			return NULL;
 		else if (!PyUnicode_Check(arg)) {
@@ -730,7 +728,7 @@
 	if (PyUnicode_Check(unistr))
 		ucvt = NULL;
 	else {
-		unistr = ucvt = PyObject_Unicode(unistr);
+		unistr = ucvt = PyObject_Str(unistr);
 		if (unistr == NULL)
 			return NULL;
 		else if (!PyUnicode_Check(unistr)) {
@@ -955,7 +953,7 @@
 {
 	PyObject_GC_UnTrack(self);
 	ERROR_DECREF(self->errors);
-	Py_Type(self)->tp_free(self);
+	Py_TYPE(self)->tp_free(self);
 }
 
 static PyTypeObject MultibyteIncrementalEncoder_Type = {
@@ -1155,7 +1153,7 @@
 {
 	PyObject_GC_UnTrack(self);
 	ERROR_DECREF(self->errors);
-	Py_Type(self)->tp_free(self);
+	Py_TYPE(self)->tp_free(self);
 }
 
 static PyTypeObject MultibyteIncrementalDecoder_Type = {
@@ -1232,15 +1230,7 @@
 		if (cres == NULL)
 			goto errorexit;
 
-		if (PyString_Check(cres)) {
-			PyObject *cres2 = PyBytes_FromObject(cres);
-			if (cres2 == NULL)
-				return NULL;
-			Py_DECREF(cres);
-			cres = cres2;
-		}
-
-		if (!PyBytes_Check(cres)) {
+		if (!PyString_Check(cres)) {
 			PyErr_Format(PyExc_TypeError,
                                      "stream function returned a "
                                      "non-bytes object (%.100s)",
@@ -1248,28 +1238,28 @@
 			goto errorexit;
 		}
 
- 		endoffile = (PyBytes_GET_SIZE(cres) == 0);
+ 		endoffile = (PyString_GET_SIZE(cres) == 0);
 
 		if (self->pendingsize > 0) {
 			PyObject *ctr;
 			char *ctrdata;
 
-			rsize = PyBytes_GET_SIZE(cres) + self->pendingsize;
-			ctr = PyBytes_FromStringAndSize(NULL, rsize);
+			rsize = PyString_GET_SIZE(cres) + self->pendingsize;
+			ctr = PyString_FromStringAndSize(NULL, rsize);
 			if (ctr == NULL)
 				goto errorexit;
-			ctrdata = PyBytes_AS_STRING(ctr);
+			ctrdata = PyString_AS_STRING(ctr);
 			memcpy(ctrdata, self->pending, self->pendingsize);
 			memcpy(ctrdata + self->pendingsize,
-				PyBytes_AS_STRING(cres),
-				PyBytes_GET_SIZE(cres));
+				PyString_AS_STRING(cres),
+				PyString_GET_SIZE(cres));
 			Py_DECREF(cres);
 			cres = ctr;
 			self->pendingsize = 0;
 		}
 
-		rsize = PyBytes_GET_SIZE(cres);
-		if (decoder_prepare_buffer(&buf, PyBytes_AS_STRING(cres),
+		rsize = PyString_GET_SIZE(cres);
+		if (decoder_prepare_buffer(&buf, PyString_AS_STRING(cres),
 					   rsize) != 0)
 			goto errorexit;
 
@@ -1327,8 +1317,8 @@
 
 	if (sizeobj == Py_None || sizeobj == NULL)
 		size = -1;
-	else if (PyInt_Check(sizeobj))
-		size = PyInt_AsSsize_t(sizeobj);
+	else if (PyLong_Check(sizeobj))
+		size = PyLong_AsSsize_t(sizeobj);
 	else {
 		PyErr_SetString(PyExc_TypeError, "arg 1 must be an integer");
 		return NULL;
@@ -1351,8 +1341,8 @@
 
 	if (sizeobj == Py_None || sizeobj == NULL)
 		size = -1;
-	else if (PyInt_Check(sizeobj))
-		size = PyInt_AsSsize_t(sizeobj);
+	else if (PyLong_Check(sizeobj))
+		size = PyLong_AsSsize_t(sizeobj);
 	else {
 		PyErr_SetString(PyExc_TypeError, "arg 1 must be an integer");
 		return NULL;
@@ -1375,8 +1365,8 @@
 
 	if (sizehintobj == Py_None || sizehintobj == NULL)
 		sizehint = -1;
-	else if (PyInt_Check(sizehintobj))
-		sizehint = PyInt_AsSsize_t(sizehintobj);
+	else if (PyLong_Check(sizehintobj))
+		sizehint = PyLong_AsSsize_t(sizehintobj);
 	else {
 		PyErr_SetString(PyExc_TypeError, "arg 1 must be an integer");
 		return NULL;
@@ -1489,7 +1479,7 @@
 	PyObject_GC_UnTrack(self);
 	ERROR_DECREF(self->errors);
 	Py_DECREF(self->stream);
-	Py_Type(self)->tp_free(self);
+	Py_TYPE(self)->tp_free(self);
 }
 
 static PyTypeObject MultibyteStreamReader_Type = {
@@ -1613,8 +1603,8 @@
 	if (pwrt == NULL)
 		return NULL;
 
-        assert(PyBytes_Check(pwrt));
-	if (PyBytes_Size(pwrt) > 0) {
+        assert(PyString_Check(pwrt));
+	if (PyString_Size(pwrt) > 0) {
 		PyObject *wr;
 		wr = PyObject_CallMethod(self->stream, "write", "O", pwrt);
 		if (wr == NULL) {
@@ -1692,7 +1682,7 @@
 	PyObject_GC_UnTrack(self);
 	ERROR_DECREF(self->errors);
 	Py_DECREF(self->stream);
-	Py_Type(self)->tp_free(self);
+	Py_TYPE(self)->tp_free(self);
 }
 
 static struct PyMethodDef mbstreamwriter_methods[] = {

Modified: python/branches/py3k-importlib/Modules/config.c.in
==============================================================================
--- python/branches/py3k-importlib/Modules/config.c.in	(original)
+++ python/branches/py3k-importlib/Modules/config.c.in	Thu Mar 27 00:48:05 2008
@@ -43,12 +43,12 @@
 	/* This lives in Python/Python-ast.c */
 	{"_ast", init_ast},
 
-	/* This lives in Python/_types.c */
+	/* This lives in Modules/_typesmodule.c */
 	{"_types", init_types},
 
 	/* These entries are here for sys.builtin_module_names */
 	{"__main__", NULL},
-	{"__builtin__", NULL},
+	{"builtins", NULL},
 	{"sys", NULL},
 
 	/* This lives in gcmodule.c */

Modified: python/branches/py3k-importlib/Modules/datetimemodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/datetimemodule.c	(original)
+++ python/branches/py3k-importlib/Modules/datetimemodule.c	Thu Mar 27 00:48:05 2008
@@ -764,7 +764,7 @@
 	PyErr_Format(PyExc_TypeError,
 		     "tzinfo argument must be None or of a tzinfo subclass, "
 		     "not type '%s'",
-		     Py_Type(p)->tp_name);
+		     Py_TYPE(p)->tp_name);
 	return -1;
 }
 
@@ -855,7 +855,7 @@
 		PyErr_Format(PyExc_TypeError,
 			     "tzinfo.%s() must return None or "
 			     "timedelta, not '%s'",
-			     name, Py_Type(u)->tp_name);
+			     name, Py_TYPE(u)->tp_name);
 	}
 
 	Py_DECREF(u);
@@ -950,7 +950,7 @@
 		if (!PyUnicode_Check(result)) {
 			PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must "
 				     "return None or a string, not '%s'",
-				     Py_Type(result)->tp_name);
+				     Py_TYPE(result)->tp_name);
 			Py_DECREF(result);
 			result = NULL;
 		}
@@ -1133,7 +1133,7 @@
 {
 	PyObject *temp;
 	PyObject *tzinfo = get_tzinfo_member(object);
-	PyObject *Zreplacement = PyBytes_FromStringAndSize("", 0);
+	PyObject *Zreplacement = PyUnicode_FromStringAndSize(NULL, 0);
 	if (Zreplacement == NULL)
 		return NULL;
 	if (tzinfo == Py_None || tzinfo == NULL)
@@ -1158,14 +1158,7 @@
 	Py_DECREF(temp);
 	if (Zreplacement == NULL)
 		return NULL;
-	if (PyUnicode_Check(Zreplacement)) {
-		PyObject *tmp = PyUnicode_AsUTF8String(Zreplacement);
-		Py_DECREF(Zreplacement);
-		if (tmp == NULL)
-			return NULL;
-		Zreplacement = tmp;
-	}
-	if (!PyBytes_Check(Zreplacement)) {
+	if (!PyUnicode_Check(Zreplacement)) {
 		PyErr_SetString(PyExc_TypeError,
 				"tzname.replace() did not return a string");
 		goto Error;
@@ -1177,10 +1170,24 @@
 	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 PyString_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 and %Z format codes via a preprocessing
- * step on the format string.
+ * 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.
  */
@@ -1192,6 +1199,7 @@
 
 	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 */
@@ -1204,7 +1212,7 @@
 	int usednew;	/* number bytes used so far in output format buffer */
 
 	const char *ptoappend;/* pointer to string to append to output buffer */
-	int ntoappend;	/* # of bytes to append to output buffer */
+	Py_ssize_t ntoappend;	/* # of bytes to append to output buffer */
 
 	assert(object && format && timetuple);
 	assert(PyUnicode_Check(format));
@@ -1227,8 +1235,8 @@
 		long year;
 		PyObject *pyyear = PySequence_GetItem(timetuple, 0);
 		if (pyyear == NULL) return NULL;
-		assert(PyInt_Check(pyyear));
-		year = PyInt_AsLong(pyyear);
+		assert(PyLong_Check(pyyear));
+		year = PyLong_AsLong(pyyear);
 		Py_DECREF(pyyear);
 		if (year < 1900) {
 			PyErr_Format(PyExc_ValueError, "year=%ld is before "
@@ -1239,14 +1247,14 @@
 		}
 	}
 
-	/* Scan the input format, looking for %z and %Z escapes, building
+	/* 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.
 	 */
 	totalnew = flen + 1;	/* realistic if no %z/%Z */
-	newfmt = PyBytes_FromStringAndSize(NULL, totalnew);
+	newfmt = PyString_FromStringAndSize(NULL, totalnew);
 	if (newfmt == NULL) goto Done;
-	pnew = PyBytes_AsString(newfmt);
+	pnew = PyString_AsString(newfmt);
 	usednew = 0;
 
 	while ((ch = *pin++) != '\0') {
@@ -1266,7 +1274,7 @@
 				/* format utcoffset */
 				char buf[100];
 				PyObject *tzinfo = get_tzinfo_member(object);
-				zreplacement = PyBytes_FromStringAndSize("", 0);
+				zreplacement = PyString_FromStringAndSize("", 0);
 				if (zreplacement == NULL) goto Done;
 				if (tzinfo != Py_None && tzinfo != NULL) {
 					assert(tzinfoarg != NULL);
@@ -1278,15 +1286,15 @@
 						goto Done;
 					Py_DECREF(zreplacement);
 					zreplacement =
-					  PyBytes_FromStringAndSize(buf,
+					  PyString_FromStringAndSize(buf,
 								   strlen(buf));
 					if (zreplacement == NULL)
 						goto Done;
 				}
 			}
 			assert(zreplacement != NULL);
-			ptoappend = PyBytes_AS_STRING(zreplacement);
-			ntoappend = PyBytes_GET_SIZE(zreplacement);
+			ptoappend = PyString_AS_STRING(zreplacement);
+			ntoappend = PyString_GET_SIZE(zreplacement);
 		}
 		else if (ch == 'Z') {
 			/* format tzname */
@@ -1297,9 +1305,22 @@
 					goto Done;
 			}
 			assert(Zreplacement != NULL);
-			assert(PyBytes_Check(Zreplacement));
-			ptoappend = PyBytes_AS_STRING(Zreplacement);
-			ntoappend = PyBytes_GET_SIZE(Zreplacement);
+			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(PyString_Check(freplacement));
+			ptoappend = PyString_AS_STRING(freplacement);
+			ntoappend = PyString_GET_SIZE(freplacement);
 		}
 		else {
 			/* percent followed by neither z nor Z */
@@ -1320,10 +1341,10 @@
  				PyErr_NoMemory();
  				goto Done;
  			}
- 			if (PyBytes_Resize(newfmt, bigger) < 0)
+ 			if (_PyString_Resize(&newfmt, bigger) < 0)
  				goto Done;
  			totalnew = bigger;
- 			pnew = PyBytes_AsString(newfmt) + usednew;
+ 			pnew = PyString_AsString(newfmt) + usednew;
  		}
 		memcpy(pnew, ptoappend, ntoappend);
 		pnew += ntoappend;
@@ -1331,14 +1352,14 @@
 		assert(usednew <= totalnew);
 	}  /* end while() */
 
-	if (PyBytes_Resize(newfmt, usednew) < 0)
+	if (_PyString_Resize(&newfmt, usednew) < 0)
 		goto Done;
 	{
 		PyObject *format;
-		PyObject *time = PyImport_ImportModule("time");
+		PyObject *time = PyImport_ImportModuleNoBlock("time");
 		if (time == NULL)
 			goto Done;
-		format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt));
+		format = PyUnicode_FromString(PyString_AS_STRING(newfmt));
 		if (format != NULL) {
 			result = PyObject_CallMethod(time, "strftime", "OO",
 						     format, timetuple);
@@ -1347,6 +1368,7 @@
 		Py_DECREF(time);
     	}
  Done:
+	Py_XDECREF(freplacement);
 	Py_XDECREF(zreplacement);
 	Py_XDECREF(Zreplacement);
 	Py_XDECREF(newfmt);
@@ -1363,7 +1385,7 @@
 time_time(void)
 {
 	PyObject *result = NULL;
-	PyObject *time = PyImport_ImportModule("time");
+	PyObject *time = PyImport_ImportModuleNoBlock("time");
 
 	if (time != NULL) {
 		result = PyObject_CallMethod(time, "time", "()");
@@ -1381,7 +1403,7 @@
 	PyObject *time;
 	PyObject *result = NULL;
 
-	time = PyImport_ImportModule("time");
+	time = PyImport_ImportModuleNoBlock("time");
 	if (time != NULL) {
 		result = PyObject_CallMethod(time, "struct_time",
 					     "((iiiiiiiii))",
@@ -1431,7 +1453,7 @@
 {
 	PyErr_Format(PyExc_TypeError,
 		     "can't compare %s to %s",
-		     Py_Type(a)->tp_name, Py_Type(b)->tp_name);
+		     Py_TYPE(a)->tp_name, Py_TYPE(b)->tp_name);
 	return NULL;
 }
 
@@ -1471,7 +1493,7 @@
 	PyObject *x3 = NULL;
 	PyObject *result = NULL;
 
-	x1 = PyInt_FromLong(GET_TD_DAYS(self));
+	x1 = PyLong_FromLong(GET_TD_DAYS(self));
 	if (x1 == NULL)
 		goto Done;
 	x2 = PyNumber_Multiply(x1, seconds_per_day);	/* days in seconds */
@@ -1481,7 +1503,7 @@
 	x1 = NULL;
 
 	/* x2 has days in seconds */
-	x1 = PyInt_FromLong(GET_TD_SECONDS(self));	/* seconds */
+	x1 = PyLong_FromLong(GET_TD_SECONDS(self));	/* seconds */
 	if (x1 == NULL)
 		goto Done;
 	x3 = PyNumber_Add(x1, x2);	/* days and seconds in seconds */
@@ -1499,7 +1521,7 @@
 	x3 = NULL;
 
 	/* x1 has days+seconds in us */
-	x2 = PyInt_FromLong(GET_TD_MICROSECONDS(self));
+	x2 = PyLong_FromLong(GET_TD_MICROSECONDS(self));
 	if (x2 == NULL)
 		goto Done;
 	result = PyNumber_Add(x1, x2);
@@ -1875,7 +1897,7 @@
 
 	PyErr_Format(PyExc_TypeError,
 		     "unsupported type for timedelta %s component: %s",
-		     tag, Py_Type(num)->tp_name);
+		     tag, Py_TYPE(num)->tp_name);
 	return NULL;
 }
 
@@ -1908,7 +1930,7 @@
 					&ms, &minute, &hour, &week) == 0)
 		goto Done;
 
-	x = PyInt_FromLong(0);
+	x = PyLong_FromLong(0);
 	if (x == NULL)
 		goto Done;
 
@@ -1979,18 +2001,18 @@
 {
 	if (GET_TD_MICROSECONDS(self) != 0)
 		return PyUnicode_FromFormat("%s(%d, %d, %d)",
-		                            Py_Type(self)->tp_name,
+		                            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,
+		                            Py_TYPE(self)->tp_name,
 		                            GET_TD_DAYS(self),
 		                            GET_TD_SECONDS(self));
 
 	return PyUnicode_FromFormat("%s(%d)",
-	                            Py_Type(self)->tp_name,
+	                            Py_TYPE(self)->tp_name,
 	                            GET_TD_DAYS(self));
 }
 
@@ -2037,7 +2059,7 @@
 static PyObject *
 delta_reduce(PyDateTime_Delta* self)
 {
-	return Py_BuildValue("ON", Py_Type(self), delta_getstate(self));
+	return Py_BuildValue("ON", Py_TYPE(self), delta_getstate(self));
 }
 
 #define OFFSET(field)  offsetof(PyDateTime_Delta, field)
@@ -2155,19 +2177,19 @@
 static PyObject *
 date_year(PyDateTime_Date *self, void *unused)
 {
-	return PyInt_FromLong(GET_YEAR(self));
+	return PyLong_FromLong(GET_YEAR(self));
 }
 
 static PyObject *
 date_month(PyDateTime_Date *self, void *unused)
 {
-	return PyInt_FromLong(GET_MONTH(self));
+	return PyLong_FromLong(GET_MONTH(self));
 }
 
 static PyObject *
 date_day(PyDateTime_Date *self, void *unused)
 {
-	return PyInt_FromLong(GET_DAY(self));
+	return PyLong_FromLong(GET_DAY(self));
 }
 
 static PyGetSetDef date_getset[] = {
@@ -2192,15 +2214,15 @@
 
 	/* 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]))
+	    PyString_Check(state = PyTuple_GET_ITEM(args, 0)) &&
+	    PyString_GET_SIZE(state) == _PyDateTime_DATE_DATASIZE &&
+	    MONTH_IS_SANE(PyString_AS_STRING(state)[2]))
 	{
 	    	PyDateTime_Date *me;
 
 		me = (PyDateTime_Date *) (type->tp_alloc(type, 0));
 		if (me != NULL) {
-			char *pdata = PyBytes_AS_STRING(state);
+			char *pdata = PyString_AS_STRING(state);
 			memcpy(me->data, pdata, _PyDateTime_DATE_DATASIZE);
 			me->hashcode = -1;
 		}
@@ -2391,7 +2413,7 @@
 date_repr(PyDateTime_Date *self)
 {
 	return PyUnicode_FromFormat("%s(%d, %d, %d)",
-	                            Py_Type(self)->tp_name,
+	                            Py_TYPE(self)->tp_name,
 	                            GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
 }
 
@@ -2450,7 +2472,7 @@
 
 	/* if the format is zero length, return str(self) */
 	if (PyUnicode_GetSize(format) == 0)
-                return PyObject_Unicode((PyObject *)self);
+                return PyObject_Str((PyObject *)self);
 
         return PyObject_CallMethod((PyObject *)self, "strftime", "O", format);
 }
@@ -2462,7 +2484,7 @@
 {
 	int dow = weekday(GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
 
-	return PyInt_FromLong(dow + 1);
+	return PyLong_FromLong(dow + 1);
 }
 
 static PyObject *
@@ -2528,7 +2550,7 @@
 	tuple = Py_BuildValue("iii", year, month, day);
 	if (tuple == NULL)
 		return NULL;
-	clone = date_new(Py_Type(self), tuple, NULL);
+	clone = date_new(Py_TYPE(self), tuple, NULL);
 	Py_DECREF(tuple);
 	return clone;
 }
@@ -2562,14 +2584,14 @@
 	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 PyInt_FromLong(ymd_to_ord(GET_YEAR(self), GET_MONTH(self),
+	return PyLong_FromLong(ymd_to_ord(GET_YEAR(self), GET_MONTH(self),
 					 GET_DAY(self)));
 }
 
@@ -2578,7 +2600,7 @@
 {
 	int dow = weekday(GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
 
-	return PyInt_FromLong(dow);
+	return PyLong_FromLong(dow);
 }
 
 /* Pickle support, a simple use of __reduce__. */
@@ -2588,15 +2610,15 @@
 date_getstate(PyDateTime_Date *self)
 {
 	PyObject* field;
-	field = PyBytes_FromStringAndSize(
-		(char*)self->data, _PyDateTime_DATE_DATASIZE);
+	field = PyString_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));
+	return Py_BuildValue("(ON)", Py_TYPE(self), date_getstate(self));
 }
 
 static PyMethodDef date_methods[] = {
@@ -2899,10 +2921,10 @@
 
 	if (state == Py_None) {
 		Py_DECREF(state);
-		return Py_BuildValue("(ON)", Py_Type(self), args);
+		return Py_BuildValue("(ON)", Py_TYPE(self), args);
 	}
 	else
-		return Py_BuildValue("(ONN)", Py_Type(self), args, state);
+		return Py_BuildValue("(ONN)", Py_TYPE(self), args, state);
 }
 
 static PyMethodDef tzinfo_methods[] = {
@@ -2981,26 +3003,26 @@
 static PyObject *
 time_hour(PyDateTime_Time *self, void *unused)
 {
-	return PyInt_FromLong(TIME_GET_HOUR(self));
+	return PyLong_FromLong(TIME_GET_HOUR(self));
 }
 
 static PyObject *
 time_minute(PyDateTime_Time *self, void *unused)
 {
-	return PyInt_FromLong(TIME_GET_MINUTE(self));
+	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 PyInt_FromLong(TIME_GET_SECOND(self));
+	return PyLong_FromLong(TIME_GET_SECOND(self));
 }
 
 static PyObject *
 time_microsecond(PyDateTime_Time *self, void *unused)
 {
-	return PyInt_FromLong(TIME_GET_MICROSECOND(self));
+	return PyLong_FromLong(TIME_GET_MICROSECOND(self));
 }
 
 static PyObject *
@@ -3041,9 +3063,9 @@
 	/* 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)
+	    PyString_Check(state = PyTuple_GET_ITEM(args, 0)) &&
+	    PyString_GET_SIZE(state) == _PyDateTime_TIME_DATASIZE &&
+	    ((unsigned char) (PyString_AS_STRING(state)[0])) < 24)
 	{
 		PyDateTime_Time *me;
 		char aware;
@@ -3059,7 +3081,7 @@
 		aware = (char)(tzinfo != Py_None);
 		me = (PyDateTime_Time *) (type->tp_alloc(type, aware));
 		if (me != NULL) {
-			char *pdata = PyBytes_AS_STRING(state);
+			char *pdata = PyString_AS_STRING(state);
 
 			memcpy(me->data, pdata, _PyDateTime_TIME_DATASIZE);
 			me->hashcode = -1;
@@ -3095,7 +3117,7 @@
 	if (HASTZINFO(self)) {
 		Py_XDECREF(self->tzinfo);
 	}
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 /*
@@ -3128,7 +3150,7 @@
 static PyObject *
 time_repr(PyDateTime_Time *self)
 {
-	const char *type_name = Py_Type(self)->tp_name;
+	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);
@@ -3194,7 +3216,7 @@
 	PyObject *tuple;
 	static char *keywords[] = {"format", NULL};
 
-	if (! PyArg_ParseTupleAndKeywords(args, kw, "S:strftime", keywords,
+	if (! PyArg_ParseTupleAndKeywords(args, kw, "U:strftime", keywords,
 					  &format))
 		return NULL;
 
@@ -3216,21 +3238,6 @@
 	return result;
 }
 
-static PyObject *
-time_format(PyDateTime_Time *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_Unicode((PyObject *)self);
-
-        return PyObject_CallMethod((PyObject *)self, "strftime", "O", format);
-}
-
 /*
  * Miscellaneous methods.
  */
@@ -3352,7 +3359,7 @@
 	tuple = Py_BuildValue("iiiiO", hh, mm, ss, us, tzinfo);
 	if (tuple == NULL)
 		return NULL;
-	clone = time_new(Py_Type(self), tuple, NULL);
+	clone = time_new(Py_TYPE(self), tuple, NULL);
 	Py_DECREF(tuple);
 	return clone;
 }
@@ -3391,7 +3398,7 @@
 	PyObject *basestate;
 	PyObject *result = NULL;
 
-	basestate =  PyBytes_FromStringAndSize((char *)self->data,
+	basestate =  PyString_FromStringAndSize((char *)self->data,
 						_PyDateTime_TIME_DATASIZE);
 	if (basestate != NULL) {
 		if (! HASTZINFO(self) || self->tzinfo == Py_None)
@@ -3406,7 +3413,7 @@
 static PyObject *
 time_reduce(PyDateTime_Time *self, PyObject *arg)
 {
-	return Py_BuildValue("(ON)", Py_Type(self), time_getstate(self));
+	return Py_BuildValue("(ON)", Py_TYPE(self), time_getstate(self));
 }
 
 static PyMethodDef time_methods[] = {
@@ -3418,7 +3425,7 @@
 	{"strftime",   	(PyCFunction)time_strftime,	METH_VARARGS | METH_KEYWORDS,
 	 PyDoc_STR("format -> strftime() style string.")},
 
-	{"__format__", 	(PyCFunction)time_format,	METH_VARARGS,
+	{"__format__", 	(PyCFunction)date_format,	METH_VARARGS,
 	 PyDoc_STR("Formats self with strftime.")},
 
 	{"utcoffset",	(PyCFunction)time_utcoffset,	METH_NOARGS,
@@ -3511,25 +3518,25 @@
 static PyObject *
 datetime_hour(PyDateTime_DateTime *self, void *unused)
 {
-	return PyInt_FromLong(DATE_GET_HOUR(self));
+	return PyLong_FromLong(DATE_GET_HOUR(self));
 }
 
 static PyObject *
 datetime_minute(PyDateTime_DateTime *self, void *unused)
 {
-	return PyInt_FromLong(DATE_GET_MINUTE(self));
+	return PyLong_FromLong(DATE_GET_MINUTE(self));
 }
 
 static PyObject *
 datetime_second(PyDateTime_DateTime *self, void *unused)
 {
-	return PyInt_FromLong(DATE_GET_SECOND(self));
+	return PyLong_FromLong(DATE_GET_SECOND(self));
 }
 
 static PyObject *
 datetime_microsecond(PyDateTime_DateTime *self, void *unused)
 {
-	return PyInt_FromLong(DATE_GET_MICROSECOND(self));
+	return PyLong_FromLong(DATE_GET_MICROSECOND(self));
 }
 
 static PyObject *
@@ -3575,9 +3582,9 @@
 	/* 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]))
+	    PyString_Check(state = PyTuple_GET_ITEM(args, 0)) &&
+	    PyString_GET_SIZE(state) == _PyDateTime_DATETIME_DATASIZE &&
+	    MONTH_IS_SANE(PyString_AS_STRING(state)[2]))
 	{
 		PyDateTime_DateTime *me;
 		char aware;
@@ -3593,7 +3600,7 @@
 		aware = (char)(tzinfo != Py_None);
 		me = (PyDateTime_DateTime *) (type->tp_alloc(type , aware));
 		if (me != NULL) {
-			char *pdata = PyBytes_AS_STRING(state);
+			char *pdata = PyString_AS_STRING(state);
 
 			memcpy(me->data, pdata, _PyDateTime_DATETIME_DATASIZE);
 			me->hashcode = -1;
@@ -3821,43 +3828,77 @@
 static PyObject *
 datetime_strptime(PyObject *cls, PyObject *args)
 {
-	PyObject *result = NULL, *obj, *module;
+	static PyObject *module = NULL;
+	PyObject *result = NULL, *obj, *st = NULL, *frac = NULL;
         const Py_UNICODE *string, *format;
 
 	if (!PyArg_ParseTuple(args, "uu:strptime", &string, &format))
 		return NULL;
 
-	if ((module = PyImport_ImportModule("time")) == NULL)
+	if (module == NULL &&
+	    (module = PyImport_ImportModuleNoBlock("_strptime")) == NULL)
 		return NULL;
-	obj = PyObject_CallMethod(module, "strptime", "uu", string, format);
-	Py_DECREF(module);
 
+	/* _strptime._strptime returns a two-element tuple.  The first
+	   element is a time.struct_time object.  The second is the
+	   microseconds (which are not defined for time.struct_time). */
+	obj = PyObject_CallMethod(module, "_strptime", "uu", string, format);
 	if (obj != NULL) {
 		int i, good_timetuple = 1;
-		long int ia[6];
-		if (PySequence_Check(obj) && PySequence_Size(obj) >= 6)
-			for (i=0; i < 6; i++) {
-				PyObject *p = PySequence_GetItem(obj, i);
-				if (p == NULL) {
-					Py_DECREF(obj);
-					return NULL;
+		long int ia[7];
+		if (PySequence_Check(obj) && PySequence_Size(obj) == 2) {
+			st = PySequence_GetItem(obj, 0);
+			frac = PySequence_GetItem(obj, 1);
+			if (st == NULL || frac == NULL)
+				good_timetuple = 0;
+			/* copy y/m/d/h/m/s values out of the
+			   time.struct_time */
+			if (good_timetuple &&
+			    PySequence_Check(st) &&
+			    PySequence_Size(st) >= 6) {
+				for (i=0; i < 6; i++) {
+					PyObject *p = PySequence_GetItem(st, i);
+					if (p == NULL) {
+						good_timetuple = 0;
+						break;
+					}
+					if (PyLong_Check(p))
+						ia[i] = PyLong_AsLong(p);
+					else
+						good_timetuple = 0;
+					Py_DECREF(p);
+				}
+/*				if (PyLong_CheckExact(p)) {
+					ia[i] = PyLong_AsLongAndOverflow(p, &overflow);
+					if (overflow)
+						good_timetuple = 0;
 				}
-				if (PyInt_CheckExact(p))
-					ia[i] = PyInt_AsLong(p);
 				else
 					good_timetuple = 0;
 				Py_DECREF(p);
-			}
+*/			}
+			else
+				good_timetuple = 0;
+			/* follow that up with a little dose of microseconds */
+			if (PyLong_Check(frac))
+				ia[6] = PyLong_AsLong(frac);
+			else
+				good_timetuple = 0;
+		}
 		else
 			good_timetuple = 0;
 		if (good_timetuple)
-			result = PyObject_CallFunction(cls, "iiiiii",
-				ia[0], ia[1], ia[2], ia[3], ia[4], ia[5]);
+			result = PyObject_CallFunction(cls, "iiiiiii",
+						       ia[0], ia[1], ia[2],
+						       ia[3], ia[4], ia[5],
+						       ia[6]);
 		else
 			PyErr_SetString(PyExc_ValueError,
-				"unexpected value from time.strptime");
-		Py_DECREF(obj);
+				"unexpected value from _strptime._strptime");
 	}
+	Py_XDECREF(obj);
+	Py_XDECREF(st);
+	Py_XDECREF(frac);
 	return result;
 }
 
@@ -3900,7 +3941,7 @@
 	if (HASTZINFO(self)) {
 		Py_XDECREF(self->tzinfo);
 	}
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 /*
@@ -4048,7 +4089,7 @@
 static PyObject *
 datetime_repr(PyDateTime_DateTime *self)
 {
-	const char *type_name = Py_Type(self)->tp_name;
+	const char *type_name = Py_TYPE(self)->tp_name;
 	PyObject *baserepr;
 
 	if (DATE_GET_MICROSECOND(self)) {
@@ -4265,7 +4306,7 @@
 	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);
+	clone = datetime_new(Py_TYPE(self), tuple, NULL);
 	Py_DECREF(tuple);
 	return clone;
 }
@@ -4438,8 +4479,8 @@
 	PyObject *basestate;
 	PyObject *result = NULL;
 
-	basestate = PyBytes_FromStringAndSize((char *)self->data,
-					      _PyDateTime_DATETIME_DATASIZE);
+	basestate = PyString_FromStringAndSize((char *)self->data,
+					       _PyDateTime_DATETIME_DATASIZE);
 	if (basestate != NULL) {
 		if (! HASTZINFO(self) || self->tzinfo == Py_None)
 			result = PyTuple_Pack(1, basestate);
@@ -4453,7 +4494,7 @@
 static PyObject *
 datetime_reduce(PyDateTime_DateTime *self, PyObject *arg)
 {
-	return Py_BuildValue("(ON)", Py_Type(self), datetime_getstate(self));
+	return Py_BuildValue("(ON)", Py_TYPE(self), datetime_getstate(self));
 }
 
 static PyMethodDef datetime_methods[] = {
@@ -4759,11 +4800,11 @@
 	assert(DI100Y == 25 * DI4Y - 1);
 	assert(DI100Y == days_before_year(100+1));
 
-	us_per_us = PyInt_FromLong(1);
-	us_per_ms = PyInt_FromLong(1000);
-	us_per_second = PyInt_FromLong(1000000);
-	us_per_minute = PyInt_FromLong(60000000);
-	seconds_per_day = PyInt_FromLong(24 * 3600);
+	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;

Modified: python/branches/py3k-importlib/Modules/dbmmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/dbmmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/dbmmodule.c	Thu Mar 27 00:48:05 2008
@@ -36,7 +36,7 @@
 
 static PyTypeObject Dbmtype;
 
-#define is_dbmobject(v) (Py_Type(v) == &Dbmtype)
+#define is_dbmobject(v) (Py_TYPE(v) == &Dbmtype)
 #define check_dbmobject_open(v) if ((v)->di_dbm == NULL) \
                { PyErr_SetString(DbmError, "DBM object has already been closed"); \
                  return NULL; }
@@ -219,14 +219,14 @@
 		if (arg == NULL)
 			return -1;
 	}
-	if (!PyBytes_Check(arg)) {
+	if (!PyString_Check(arg)) {
 		PyErr_Format(PyExc_TypeError,
 			     "dbm key must be string, not %.100s",
 			     arg->ob_type->tp_name);
 		return -1;
 	}
-	key.dptr = PyBytes_AS_STRING(arg);
-	key.dsize = PyBytes_GET_SIZE(arg);
+	key.dptr = PyString_AS_STRING(arg);
+	key.dsize = PyString_GET_SIZE(arg);
 	val = dbm_fetch(dp->di_dbm, key);
 	return val.dptr != NULL;
 }
@@ -344,6 +344,13 @@
 	0,			  /*tp_as_number*/
 	&dbm_as_sequence,	  /*tp_as_sequence*/
 	&dbm_as_mapping,	  /*tp_as_mapping*/
+	0,                    /*tp_hash*/
+	0,                    /*tp_call*/
+	0,                    /*tp_str*/
+	0,                    /*tp_getattro*/
+	0,                    /*tp_setattro*/
+	0,                    /*tp_as_buffer*/
+	Py_TPFLAGS_DEFAULT,   /*tp_xxx4*/
 };
 
 /* ----------------------------------------------------------------- */

Modified: python/branches/py3k-importlib/Modules/dlmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/dlmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/dlmodule.c	Thu Mar 27 00:48:05 2008
@@ -62,7 +62,7 @@
 		name = PyUnicode_AsString(args);
 	} else {
 		PyErr_Format(PyExc_TypeError, "expected string, found %.200s",
-			     Py_Type(args)->tp_name);
+			     Py_TYPE(args)->tp_name);
 		return NULL;
 	}
 	func = dlsym(xp->dl_handle, name);
@@ -70,7 +70,7 @@
 		Py_INCREF(Py_None);
 		return Py_None;
 	}
-	return PyInt_FromLong((long)func);
+	return PyLong_FromLong((long)func);
 }
 
 static PyObject *
@@ -107,8 +107,8 @@
 	}
 	for (i = 1; i < n; i++) {
 		PyObject *v = PyTuple_GetItem(args, i);
-		if (PyInt_Check(v)) {
-			alist[i-1] = PyInt_AsLong(v);
+		if (PyLong_Check(v)) {
+			alist[i-1] = PyLong_AsLong(v);
 			if (alist[i-1] == -1 && PyErr_Occurred())
 				return NULL;
 		} else if (PyUnicode_Check(v))
@@ -125,7 +125,7 @@
 		alist[i-1] = 0;
 	res = (*func)(alist[0], alist[1], alist[2], alist[3], alist[4],
 		      alist[5], alist[6], alist[7], alist[8], alist[9]);
-	return PyInt_FromLong(res);
+	return PyLong_FromLong(res);
 }
 
 static PyMethodDef dlobject_methods[] = {
@@ -225,7 +225,7 @@
 static void
 insint(PyObject *d, char *name, int value)
 {
-	PyObject *v = PyInt_FromLong((long) value);
+	PyObject *v = PyLong_FromLong((long) value);
 	if (!v || PyDict_SetItemString(d, name, v))
 		PyErr_Clear();
 
@@ -238,7 +238,7 @@
 	PyObject *m, *d, *x;
 
 	/* Initialize object type */
-	Py_Type(&Dltype) = &PyType_Type;
+	Py_TYPE(&Dltype) = &PyType_Type;
 
 	/* Create the module and add the functions */
 	m = Py_InitModule("dl", dl_methods);
@@ -249,7 +249,7 @@
 	d = PyModule_GetDict(m);
 	Dlerror = x = PyErr_NewException("dl.error", NULL, NULL);
 	PyDict_SetItemString(d, "error", x);
-	x = PyInt_FromLong((long)RTLD_LAZY);
+	x = PyLong_FromLong((long)RTLD_LAZY);
 	PyDict_SetItemString(d, "RTLD_LAZY", x);
 #define INSINT(X)    insint(d,#X,X)
 #ifdef RTLD_NOW

Modified: python/branches/py3k-importlib/Modules/errnomodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/errnomodule.c	(original)
+++ python/branches/py3k-importlib/Modules/errnomodule.c	Thu Mar 27 00:48:05 2008
@@ -5,6 +5,7 @@
 
 /* Windows socket errors (WSA*)  */
 #ifdef MS_WINDOWS
+#define WIN32_LEAN_AND_MEAN
 #include <winsock.h>
 #endif
 
@@ -22,7 +23,7 @@
 _inscode(PyObject *d, PyObject *de, const char *name, int code)
 {
 	PyObject *u = PyUnicode_FromString(name);
-	PyObject *v = PyInt_FromLong((long) code);
+	PyObject *v = PyLong_FromLong((long) code);
 
 	/* Don't bother checking for errors; they'll be caught at the end
 	 * of the module initialization function by the caller of

Modified: python/branches/py3k-importlib/Modules/fcntlmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/fcntlmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/fcntlmodule.c	Thu Mar 27 00:48:05 2008
@@ -73,7 +73,7 @@
 		PyErr_SetFromErrno(PyExc_IOError);
 		return NULL;
 	}
-	return PyInt_FromLong((long)ret);
+	return PyLong_FromLong((long)ret);
 }
 
 PyDoc_STRVAR(fcntl_doc,
@@ -97,11 +97,20 @@
 {
 #define IOCTL_BUFSZ 1024
 	int fd;
-	/* In PyArg_ParseTuple below, use the unsigned int 'I' format for
-	   the signed int 'code' variable, because Python turns 0x8000000
-	   into a large positive number (PyLong, or PyInt on 64-bit
-	   platforms,) whereas C expects it to be a negative int */
-	int code;
+	/* In PyArg_ParseTuple below, we use the unsigned non-checked 'I'
+	   format for the 'code' parameter because Python turns 0x8000000
+	   into either a large positive number (PyLong or PyInt on 64-bit
+	   platforms) or a negative number on others (32-bit PyInt)
+	   whereas the system expects it to be a 32bit bit field value
+	   regardless of it being passed as an int or unsigned long on
+	   various platforms.  See the termios.TIOCSWINSZ constant across
+	   platforms for an example of thise.
+
+	   If any of the 64bit platforms ever decide to use more than 32bits
+	   in their unsigned long ioctl codes this will break and need
+	   special casing based on the platform being built on.
+	 */
+	unsigned int code;
 	int arg;
 	int ret;
 	char *str;
@@ -152,7 +161,7 @@
 			return NULL;
 		}
 		if (mutate_arg) {
-			return PyInt_FromLong(ret);
+			return PyLong_FromLong(ret);
 		}
 		else {
 			return PyString_FromStringAndSize(buf, len);
@@ -198,7 +207,7 @@
 		PyErr_SetFromErrno(PyExc_IOError);
 		return NULL;
 	}
-	return PyInt_FromLong((long)ret);
+	return PyLong_FromLong((long)ret);
 #undef IOCTL_BUFSZ
 }
 
@@ -333,22 +342,22 @@
 		l.l_start = l.l_len = 0;
 		if (startobj != NULL) {
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-			l.l_start = PyInt_AsLong(startobj);
+			l.l_start = PyLong_AsLong(startobj);
 #else
 			l.l_start = PyLong_Check(startobj) ?
 					PyLong_AsLongLong(startobj) :
-					PyInt_AsLong(startobj);
+					PyLong_AsLong(startobj);
 #endif
 			if (PyErr_Occurred())
 				return NULL;
 		}
 		if (lenobj != NULL) {
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-			l.l_len = PyInt_AsLong(lenobj);
+			l.l_len = PyLong_AsLong(lenobj);
 #else
 			l.l_len = PyLong_Check(lenobj) ?
 					PyLong_AsLongLong(lenobj) :
-					PyInt_AsLong(lenobj);
+					PyLong_AsLong(lenobj);
 #endif
 			if (PyErr_Occurred())
 				return NULL;
@@ -378,7 +387,7 @@
     LOCK_SH - acquire a shared lock\n\
     LOCK_EX - acquire an exclusive lock\n\
 \n\
-When operation is LOCK_SH or LOCK_EX, it can also be bit-wise OR'd with\n\
+When operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with\n\
 LOCK_NB to avoid blocking on lock acquisition.  If LOCK_NB is used and the\n\
 lock cannot be acquired, an IOError will be raised and the exception will\n\
 have an errno attribute set to EACCES or EAGAIN (depending on the operating\n\
@@ -414,7 +423,7 @@
 static int
 ins(PyObject* d, char* symbol, long value)
 {
-        PyObject* v = PyInt_FromLong(value);
+        PyObject* v = PyLong_FromLong(value);
         if (!v || PyDict_SetItemString(d, symbol, v) < 0)
                 return -1;
 

Modified: python/branches/py3k-importlib/Modules/gcmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/gcmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/gcmodule.c	Thu Mar 27 00:48:05 2008
@@ -19,6 +19,7 @@
 */
 
 #include "Python.h"
+#include "frameobject.h"	/* for PyFrame_ClearFreeList */
 
 /* Get an object's GC head */
 #define AS_GC(o) ((PyGC_Head *)(o)-1)
@@ -66,11 +67,9 @@
 #define DEBUG_STATS		(1<<0) /* print collection statistics */
 #define DEBUG_COLLECTABLE	(1<<1) /* print collectable objects */
 #define DEBUG_UNCOLLECTABLE	(1<<2) /* print uncollectable objects */
-#define DEBUG_OBJECTS		(1<<4) /* print other objects */
 #define DEBUG_SAVEALL		(1<<5) /* save all garbage in gc.garbage */
 #define DEBUG_LEAK		DEBUG_COLLECTABLE | \
 				DEBUG_UNCOLLECTABLE | \
-				DEBUG_OBJECTS | \
 				DEBUG_SAVEALL
 static int debug;
 static PyObject *tmod = NULL;
@@ -237,7 +236,7 @@
 	PyGC_Head *gc = containers->gc.gc_next;
 	for (; gc != containers; gc = gc->gc.gc_next) {
 		assert(gc->gc.gc_refs == GC_REACHABLE);
-		gc->gc.gc_refs = Py_Refcnt(FROM_GC(gc));
+		gc->gc.gc_refs = Py_REFCNT(FROM_GC(gc));
 		/* Python's cyclic gc should never see an incoming refcount
 		 * of 0:  if something decref'ed to 0, it should have been
 		 * deallocated immediately at that time.
@@ -289,7 +288,7 @@
 	traverseproc traverse;
 	PyGC_Head *gc = containers->gc.gc_next;
 	for (; gc != containers; gc=gc->gc.gc_next) {
-		traverse = Py_Type(FROM_GC(gc))->tp_traverse;
+		traverse = Py_TYPE(FROM_GC(gc))->tp_traverse;
 		(void) traverse(FROM_GC(gc),
 			       (visitproc)visit_decref,
 			       NULL);
@@ -374,7 +373,7 @@
                          * the next object to visit.
                          */
                         PyObject *op = FROM_GC(gc);
-                        traverseproc traverse = Py_Type(op)->tp_traverse;
+                        traverseproc traverse = Py_TYPE(op)->tp_traverse;
                         assert(gc->gc.gc_refs > 0);
                         gc->gc.gc_refs = GC_REACHABLE;
                         (void) traverse(op,
@@ -398,13 +397,7 @@
 	}
 }
 
-/* Return true if object has a finalization method.
- * CAUTION:  An instance of an old-style class has to be checked for a
- *__del__ method, and earlier versions of this used to call PyObject_HasAttr,
- * which in turn could call the class's __getattr__ hook (if any).  That
- * could invoke arbitrary Python code, mutating the object graph in arbitrary
- * ways, and that was the source of some excruciatingly subtle bugs.
- */
+/* Return true if object has a finalization method. */
 static int
 has_finalizer(PyObject *op)
 {
@@ -464,7 +457,7 @@
 	PyGC_Head *gc = finalizers->gc.gc_next;
 	for (; gc != finalizers; gc = gc->gc.gc_next) {
 		/* Note that the finalizers list may grow during this. */
-		traverse = Py_Type(FROM_GC(gc))->tp_traverse;
+		traverse = Py_TYPE(FROM_GC(gc))->tp_traverse;
 		(void) traverse(FROM_GC(gc),
 				(visitproc)visit_move,
 				(void *)finalizers);
@@ -509,7 +502,7 @@
 		assert(IS_TENTATIVELY_UNREACHABLE(op));
 		next = gc->gc.gc_next;
 
-		if (! PyType_SUPPORTS_WEAKREFS(Py_Type(op)))
+		if (! PyType_SUPPORTS_WEAKREFS(Py_TYPE(op)))
 			continue;
 
 		/* It supports weakrefs.  Does it have any? */
@@ -627,10 +620,8 @@
 static void
 debug_cycle(char *msg, PyObject *op)
 {
-	if (debug & DEBUG_OBJECTS) {
-		PySys_WriteStderr("gc: %.100s <%.100s %p>\n",
-				  msg, Py_Type(op)->tp_name, op);
-	}
+	PySys_WriteStderr("gc: %.100s <%.100s %p>\n",
+			  msg, Py_TYPE(op)->tp_name, op);
 }
 
 /* Handle uncollectable garbage (cycles with finalizers, and stuff reachable
@@ -683,7 +674,7 @@
 			PyList_Append(garbage, op);
 		}
 		else {
-			if ((clear = Py_Type(op)->tp_clear) != NULL) {
+			if ((clear = Py_TYPE(op)->tp_clear) != NULL) {
 				Py_INCREF(op);
 				clear(op);
 				Py_DECREF(op);
@@ -697,6 +688,21 @@
 	}
 }
 
+/* Clear all free lists
+ * All free lists are cleared during the collection of the highest generation.
+ * Allocated items in the free list may keep a pymalloc arena occupied.
+ * Clearing the free lists may give back memory to the OS earlier.
+ */
+static void
+clear_freelists(void)
+{
+	(void)PyMethod_ClearFreeList();
+	(void)PyFrame_ClearFreeList();
+	(void)PyCFunction_ClearFreeList();
+	(void)PyTuple_ClearFreeList();
+	(void)PyUnicode_ClearFreeList();
+}
+
 /* This is the main function.  Read this to understand how the
  * collection process works. */
 static Py_ssize_t
@@ -849,6 +855,12 @@
 	 */
 	(void)handle_finalizers(&finalizers, old);
 
+	/* Clear free list only during the collection of the higest
+	 * generation */
+	if (generation == NUM_GENERATIONS-1) {
+		clear_freelists();
+	}
+
 	if (PyErr_Occurred()) {
 		if (gc_str == NULL)
 			gc_str = PyUnicode_FromString("garbage collection");
@@ -944,7 +956,7 @@
 		collecting = 0;
 	}
 
-	return PyInt_FromSsize_t(n);
+	return PyLong_FromSsize_t(n);
 }
 
 PyDoc_STRVAR(gc_set_debug__doc__,
@@ -958,7 +970,6 @@
 "  DEBUG_STATS - Print statistics during collection.\n"
 "  DEBUG_COLLECTABLE - Print collectable objects found.\n"
 "  DEBUG_UNCOLLECTABLE - Print unreachable but uncollectable objects found.\n"
-"  DEBUG_OBJECTS - Print objects other than instances.\n"
 "  DEBUG_SAVEALL - Save objects to gc.garbage rather than freeing them.\n"
 "  DEBUG_LEAK - Debug leaking programs (everything but STATS).\n");
 
@@ -1053,7 +1064,7 @@
 	traverseproc traverse;
 	for (gc = list->gc.gc_next; gc != list; gc = gc->gc.gc_next) {
 		obj = FROM_GC(gc);
-		traverse = Py_Type(obj)->tp_traverse;
+		traverse = Py_TYPE(obj)->tp_traverse;
 		if (obj == objs || obj == resultlist)
 			continue;
 		if (traverse(obj, (visitproc)referrersvisit, objs)) {
@@ -1110,7 +1121,7 @@
 
 		if (! PyObject_IS_GC(obj))
 			continue;
-		traverse = Py_Type(obj)->tp_traverse;
+		traverse = Py_TYPE(obj)->tp_traverse;
 		if (! traverse)
 			continue;
 		if (traverse(obj, (visitproc)referentsvisit, result)) {
@@ -1210,7 +1221,7 @@
 	 * the import and triggers an assertion.
 	 */
 	if (tmod == NULL) {
-		tmod = PyImport_ImportModule("time");
+		tmod = PyImport_ImportModuleNoBlock("time");
 		if (tmod == NULL)
 			PyErr_Clear();
 	}
@@ -1219,7 +1230,6 @@
 	ADD_INT(DEBUG_STATS);
 	ADD_INT(DEBUG_COLLECTABLE);
 	ADD_INT(DEBUG_UNCOLLECTABLE);
-	ADD_INT(DEBUG_OBJECTS);
 	ADD_INT(DEBUG_SAVEALL);
 	ADD_INT(DEBUG_LEAK);
 #undef ADD_INT
@@ -1332,13 +1342,13 @@
 PyVarObject *
 _PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
 {
-	const size_t basicsize = _PyObject_VAR_SIZE(Py_Type(op), nitems);
+	const size_t basicsize = _PyObject_VAR_SIZE(Py_TYPE(op), nitems);
 	PyGC_Head *g = AS_GC(op);
 	g = (PyGC_Head *)PyObject_REALLOC(g,  sizeof(PyGC_Head) + basicsize);
 	if (g == NULL)
 		return (PyVarObject *)PyErr_NoMemory();
 	op = (PyVarObject *) FROM_GC(g);
-	Py_Size(op) = nitems;
+	Py_SIZE(op) = nitems;
 	return op;
 }
 

Modified: python/branches/py3k-importlib/Modules/gdbmmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/gdbmmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/gdbmmodule.c	Thu Mar 27 00:48:05 2008
@@ -36,7 +36,7 @@
 
 static PyTypeObject Dbmtype;
 
-#define is_dbmobject(v) (Py_Type(v) == &Dbmtype)
+#define is_dbmobject(v) (Py_TYPE(v) == &Dbmtype)
 #define check_dbmobject_open(v) if ((v)->di_dbm == NULL) \
     { PyErr_SetString(DbmError, "GDBM object has already been closed"); \
       return NULL; }
@@ -130,7 +130,7 @@
         PyErr_SetObject(PyExc_KeyError, key);
         return NULL;
     }
-    v = PyBytes_FromStringAndSize(drec.dptr, drec.dsize);
+    v = PyString_FromStringAndSize(drec.dptr, drec.dsize);
     free(drec.dptr);
     return v;
 }
@@ -220,7 +220,7 @@
 
     key = gdbm_firstkey(dp->di_dbm);
     while (key.dptr) {
-        item = PyBytes_FromStringAndSize(key.dptr, key.dsize);
+        item = PyString_FromStringAndSize(key.dptr, key.dsize);
         if (item == NULL) {
             free(key.dptr);
             Py_DECREF(v);
@@ -251,14 +251,14 @@
 			"GDBM object has already been closed");
 	return -1;
     }
-    if (!PyBytes_Check(arg)) {
+    if (!PyString_Check(arg)) {
 	PyErr_Format(PyExc_TypeError,
 		     "gdbm key must be bytes, not %.100s",
 		     arg->ob_type->tp_name);
 	return -1;
     }
-    key.dptr = PyBytes_AsString(arg);
-    key.dsize = PyBytes_Size(arg);
+    key.dptr = PyString_AS_STRING(arg);
+    key.dsize = PyString_GET_SIZE(arg);
     return gdbm_exists(dp->di_dbm, key);
 }
 
@@ -291,7 +291,7 @@
     check_dbmobject_open(dp);
     key = gdbm_firstkey(dp->di_dbm);
     if (key.dptr) {
-        v = PyBytes_FromStringAndSize(key.dptr, key.dsize);
+        v = PyString_FromStringAndSize(key.dptr, key.dsize);
         free(key.dptr);
         return v;
     }
@@ -323,7 +323,7 @@
     check_dbmobject_open(dp);
     nextkey = gdbm_nextkey(dp->di_dbm, key);
     if (nextkey.dptr) {
-        v = PyBytes_FromStringAndSize(nextkey.dptr, nextkey.dsize);
+        v = PyString_FromStringAndSize(nextkey.dptr, nextkey.dsize);
         free(nextkey.dptr);
         return v;
     }
@@ -407,7 +407,7 @@
     0,                                  /*tp_getattro*/
     0,                                  /*tp_setattro*/
     0,                                  /*tp_as_buffer*/
-    0,                                  /*tp_xxx4*/
+    Py_TPFLAGS_DEFAULT,                 /*tp_xxx4*/
     gdbm_object__doc__,                 /*tp_doc*/
 };
 

Modified: python/branches/py3k-importlib/Modules/grpmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/grpmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/grpmodule.c	Thu Mar 27 00:48:05 2008
@@ -70,7 +70,7 @@
 	    Py_INCREF(Py_None);
     }
 #endif
-    SET(setIndex++, PyInt_FromLong((long) p->gr_gid));
+    SET(setIndex++, PyLong_FromLong((long) p->gr_gid));
     SET(setIndex++, w);
 #undef SET
 
@@ -93,7 +93,7 @@
     py_int_id = PyNumber_Int(pyo_id);
     if (!py_int_id)
 	    return NULL;
-    gid = PyInt_AS_LONG(py_int_id);
+    gid = PyLong_AS_LONG(py_int_id);
     Py_DECREF(py_int_id);
 
     if ((p = getgrgid(gid)) == NULL) {
@@ -110,7 +110,7 @@
     char *name;
     struct group *p;
 
-    py_str_name = PyObject_Unicode(pyo_name);
+    py_str_name = PyObject_Str(pyo_name);
     if (!py_str_name)
 	    return NULL;
     name = PyUnicode_AsString(py_str_name);

Modified: python/branches/py3k-importlib/Modules/itertoolsmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/itertoolsmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/itertoolsmodule.c	Thu Mar 27 00:48:05 2008
@@ -59,7 +59,7 @@
 	Py_XDECREF(gbo->tgtkey);
 	Py_XDECREF(gbo->currkey);
 	Py_XDECREF(gbo->currvalue);
-	Py_Type(gbo)->tp_free(gbo);
+	Py_TYPE(gbo)->tp_free(gbo);
 }
 
 static int
@@ -198,7 +198,7 @@
 {
 	_grouperobject *igo;
 
-	igo = PyObject_New(_grouperobject, &_grouper_type);
+	igo = PyObject_GC_New(_grouperobject, &_grouper_type);
 	if (igo == NULL)
 		return NULL;
 	igo->parent = (PyObject *)parent;
@@ -206,15 +206,25 @@
 	igo->tgtkey = tgtkey;
 	Py_INCREF(tgtkey);
 
+	PyObject_GC_Track(igo);
 	return (PyObject *)igo;
 }
 
 static void
 _grouper_dealloc(_grouperobject *igo)
 {
+	PyObject_GC_UnTrack(igo);
 	Py_DECREF(igo->parent);
 	Py_DECREF(igo->tgtkey);
-	PyObject_Del(igo);
+	PyObject_GC_Del(igo);
+}
+
+static int
+_grouper_traverse(_grouperobject *igo, visitproc visit, void *arg)
+{
+	Py_VISIT(igo->parent);
+	Py_VISIT(igo->tgtkey);
+	return 0;
 }
 
 static PyObject *
@@ -280,9 +290,9 @@
 	PyObject_GenericGetAttr,	/* tp_getattro */
 	0,				/* tp_setattro */
 	0,				/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT,		/* tp_flags */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,	/* tp_flags */
 	0,				/* tp_doc */
-	0, 				/* tp_traverse */
+	(traverseproc)_grouper_traverse,/* tp_traverse */
 	0,				/* tp_clear */
 	0,				/* tp_richcompare */
 	0,				/* tp_weaklistoffset */
@@ -299,7 +309,7 @@
 	0,				/* tp_init */
 	0,				/* tp_alloc */
 	0,				/* tp_new */
-	PyObject_Del,			/* tp_free */
+	PyObject_GC_Del,		/* tp_free */
 };
 
  
@@ -714,7 +724,7 @@
 	PyObject_GC_UnTrack(lz);
 	Py_XDECREF(lz->saved);
 	Py_XDECREF(lz->it);
-	Py_Type(lz)->tp_free(lz);
+	Py_TYPE(lz)->tp_free(lz);
 }
 
 static int
@@ -857,7 +867,7 @@
 	PyObject_GC_UnTrack(lz);
 	Py_XDECREF(lz->func);
 	Py_XDECREF(lz->it);
-	Py_Type(lz)->tp_free(lz);
+	Py_TYPE(lz)->tp_free(lz);
 }
 
 static int
@@ -877,7 +887,7 @@
 	PyObject *(*iternext)(PyObject *);
 
 	assert(PyIter_Check(it));
-	iternext = *Py_Type(it)->tp_iternext;
+	iternext = *Py_TYPE(it)->tp_iternext;
 	for (;;) {
 		item = iternext(it);
 		if (item == NULL)
@@ -1000,7 +1010,7 @@
 	PyObject_GC_UnTrack(lz);
 	Py_XDECREF(lz->func);
 	Py_XDECREF(lz->it);
-	Py_Type(lz)->tp_free(lz);
+	Py_TYPE(lz)->tp_free(lz);
 }
 
 static int
@@ -1022,7 +1032,7 @@
 		return NULL;
 
 	assert(PyIter_Check(it));
-	item = (*Py_Type(it)->tp_iternext)(it);
+	item = (*Py_TYPE(it)->tp_iternext)(it);
 	if (item == NULL)
 		return NULL;
 
@@ -1122,7 +1132,7 @@
 	numargs = PyTuple_Size(args);
 	if (numargs == 2) {
 		if (a1 != Py_None) {
-			stop = PyInt_AsSsize_t(a1);
+			stop = PyLong_AsSsize_t(a1);
 			if (stop == -1) {
 				if (PyErr_Occurred())
 					PyErr_Clear();
@@ -1133,11 +1143,11 @@
 		}
 	} else {
 		if (a1 != Py_None)
-			start = PyInt_AsSsize_t(a1);
+			start = PyLong_AsSsize_t(a1);
 		if (start == -1 && PyErr_Occurred())
 			PyErr_Clear();
 		if (a2 != Py_None) {
-			stop = PyInt_AsSsize_t(a2);
+			stop = PyLong_AsSsize_t(a2);
 			if (stop == -1) {
 				if (PyErr_Occurred())
 					PyErr_Clear();
@@ -1155,7 +1165,7 @@
 
 	if (a3 != NULL) {
 		if (a3 != Py_None)
-			step = PyInt_AsSsize_t(a3);
+			step = PyLong_AsSsize_t(a3);
 		if (step == -1 && PyErr_Occurred())
 			PyErr_Clear();
 	}
@@ -1190,7 +1200,7 @@
 {
 	PyObject_GC_UnTrack(lz);
 	Py_XDECREF(lz->it);
-	Py_Type(lz)->tp_free(lz);
+	Py_TYPE(lz)->tp_free(lz);
 }
 
 static int
@@ -1209,7 +1219,7 @@
 	PyObject *(*iternext)(PyObject *);
 
 	assert(PyIter_Check(it));
-	iternext = *Py_Type(it)->tp_iternext;
+	iternext = *Py_TYPE(it)->tp_iternext;
 	while (lz->cnt < lz->next) {
 		item = iternext(it);
 		if (item == NULL)
@@ -1333,7 +1343,7 @@
 	PyObject_GC_UnTrack(lz);
 	Py_XDECREF(lz->func);
 	Py_XDECREF(lz->it);
-	Py_Type(lz)->tp_free(lz);
+	Py_TYPE(lz)->tp_free(lz);
 }
 
 static int
@@ -1352,14 +1362,15 @@
 	PyObject *it = lz->it;
 
 	assert(PyIter_Check(it));
-	args = (*Py_Type(it)->tp_iternext)(it);
+	args = (*Py_TYPE(it)->tp_iternext)(it);
 	if (args == NULL)
 		return NULL;
 	if (!PyTuple_CheckExact(args)) {
+		PyObject *newargs = PySequence_Tuple(args);
 		Py_DECREF(args);
-		PyErr_SetString(PyExc_TypeError,
-				"iterator must return a tuple");
-		return NULL;
+		if (newargs == NULL)
+			return NULL;
+		args = newargs;
 	}
 	result = PyObject_Call(lz->func, args, NULL);
 	Py_DECREF(args);
@@ -1417,147 +1428,136 @@
 };
 
 
-/* imap object ************************************************************/
+/* chain object ************************************************************/
 
 typedef struct {
 	PyObject_HEAD
-	PyObject *iters;
-	PyObject *func;
-} imapobject;
+	PyObject *source;		/* Iterator over input iterables */
+	PyObject *active;		/* Currently running input iterator */
+} chainobject;
 
-static PyTypeObject imap_type;
+static PyTypeObject chain_type;
 
-static PyObject *
-imap_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+static PyObject * 
+chain_new_internal(PyTypeObject *type, PyObject *source)
 {
-	PyObject *it, *iters, *func;
-	imapobject *lz;
-	Py_ssize_t numargs, i;
-
-	if (type == &imap_type && !_PyArg_NoKeywords("imap()", kwds))
-		return NULL;
+	chainobject *lz;
 
-	numargs = PyTuple_Size(args);
-	if (numargs < 2) {
-		PyErr_SetString(PyExc_TypeError,
-		   "imap() must have at least two arguments.");
+	lz = (chainobject *)type->tp_alloc(type, 0);
+	if (lz == NULL) {
+		Py_DECREF(source);
 		return NULL;
 	}
+	
+	lz->source = source;
+	lz->active = NULL;
+	return (PyObject *)lz;
+}
 
-	iters = PyTuple_New(numargs-1);
-	if (iters == NULL)
+static PyObject *
+chain_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+	PyObject *source;
+
+	if (type == &chain_type && !_PyArg_NoKeywords("chain()", kwds))
+		return NULL;
+	
+	source = PyObject_GetIter(args);
+	if (source == NULL)
 		return NULL;
 
-	for (i=1 ; i<numargs ; i++) {
-		/* Get iterator. */
-		it = PyObject_GetIter(PyTuple_GET_ITEM(args, i));
-		if (it == NULL) {
-			Py_DECREF(iters);
-			return NULL;
-		}
-		PyTuple_SET_ITEM(iters, i-1, it);
-	}
+	return chain_new_internal(type, source);
+}
 
-	/* create imapobject structure */
-	lz = (imapobject *)type->tp_alloc(type, 0);
-	if (lz == NULL) {
-		Py_DECREF(iters);
+static PyObject *
+chain_new_from_iterable(PyTypeObject *type, PyObject *arg)
+{
+	PyObject *source;
+	
+	source = PyObject_GetIter(arg);
+	if (source == NULL)
 		return NULL;
-	}
-	lz->iters = iters;
-	func = PyTuple_GET_ITEM(args, 0);
-	Py_INCREF(func);
-	lz->func = func;
 
-	return (PyObject *)lz;
+	return chain_new_internal(type, source);
 }
 
 static void
-imap_dealloc(imapobject *lz)
+chain_dealloc(chainobject *lz)
 {
 	PyObject_GC_UnTrack(lz);
-	Py_XDECREF(lz->iters);
-	Py_XDECREF(lz->func);
-	Py_Type(lz)->tp_free(lz);
+	Py_XDECREF(lz->active);
+	Py_XDECREF(lz->source);
+	Py_TYPE(lz)->tp_free(lz);
 }
 
 static int
-imap_traverse(imapobject *lz, visitproc visit, void *arg)
+chain_traverse(chainobject *lz, visitproc visit, void *arg)
 {
-	Py_VISIT(lz->iters);
-	Py_VISIT(lz->func);
+	Py_VISIT(lz->source);
+	Py_VISIT(lz->active);
 	return 0;
 }
 
-/*	
-imap() is an iterator version of __builtins__.map() except that it does
-not have the None fill-in feature.  That was intentionally left out for
-the following reasons:
-
-  1) Itertools are designed to be easily combined and chained together.
-     Having all tools stop with the shortest input is a unifying principle
-     that makes it easier to combine finite iterators (supplying data) with
-     infinite iterators like count() and repeat() (for supplying sequential
-     or constant arguments to a function).
-
-  2) In typical use cases for combining itertools, having one finite data 
-     supplier run out before another is likely to be an error condition which
-     should not pass silently by automatically supplying None.
-
-  3) The use cases for automatic None fill-in are rare -- not many functions
-     do something useful when a parameter suddenly switches type and becomes
-     None.  
-
-  4) If a need does arise, it can be met by __builtins__.map() or by 
-     writing:  chain(iterable, repeat(None)).
-
-  5) Similar toolsets in Haskell and SML do not have automatic None fill-in.
-*/
-
 static PyObject *
-imap_next(imapobject *lz)
+chain_next(chainobject *lz)
 {
-	PyObject *val;
-	PyObject *argtuple;
-	PyObject *result;
-	Py_ssize_t numargs, i;
+	PyObject *item;
 
-	numargs = PyTuple_Size(lz->iters);
-	argtuple = PyTuple_New(numargs);
-	if (argtuple == NULL)
-		return NULL;
+	if (lz->source == NULL)
+		return NULL;				/* already stopped */
 
-	for (i=0 ; i<numargs ; i++) {
-		val = PyIter_Next(PyTuple_GET_ITEM(lz->iters, i));
-		if (val == NULL) {
-			Py_DECREF(argtuple);
-			return NULL;
+	if (lz->active == NULL) {
+		PyObject *iterable = PyIter_Next(lz->source);
+		if (iterable == NULL) {
+			Py_CLEAR(lz->source);
+			return NULL;			/* no more input sources */
+		}
+		lz->active = PyObject_GetIter(iterable);
+		Py_DECREF(iterable);
+		if (lz->active == NULL) {
+			Py_CLEAR(lz->source);
+			return NULL;			/* input not iterable */
 		}
-		PyTuple_SET_ITEM(argtuple, i, val);
 	}
-	if (lz->func == Py_None) 
-		return argtuple;
-	result = PyObject_Call(lz->func, argtuple, NULL);
-	Py_DECREF(argtuple);
-	return result;
+	item = PyIter_Next(lz->active);
+	if (item != NULL)
+		return item;
+	if (PyErr_Occurred()) {
+		if (PyErr_ExceptionMatches(PyExc_StopIteration))
+			PyErr_Clear();
+		else
+			return NULL; 			/* input raised an exception */
+	}
+	Py_CLEAR(lz->active);
+	return chain_next(lz);			/* recurse and use next active */
 }
 
-PyDoc_STRVAR(imap_doc,
-"imap(func, *iterables) --> imap object\n\
+PyDoc_STRVAR(chain_doc,
+"chain(*iterables) --> chain object\n\
+\n\
+Return a chain object whose .__next__() method returns elements from the\n\
+first iterable until it is exhausted, then elements from the next\n\
+iterable, until all of the iterables are exhausted.");
+
+PyDoc_STRVAR(chain_from_iterable_doc,
+"chain.from_iterable(iterable) --> chain object\n\
 \n\
-Make an iterator that computes the function using arguments from\n\
-each of the iterables.	Like map() except that it returns\n\
-an iterator instead of a list and that it stops when the shortest\n\
-iterable is exhausted instead of filling in None for shorter\n\
-iterables.");
+Alternate chain() contructor taking a single iterable argument\n\
+that evaluates lazily.");
+
+static PyMethodDef chain_methods[] = {
+	{"from_iterable", (PyCFunction) chain_new_from_iterable,	METH_O | METH_CLASS,
+		chain_from_iterable_doc},
+	{NULL,		NULL}	/* sentinel */
+};
 
-static PyTypeObject imap_type = {
+static PyTypeObject chain_type = {
 	PyVarObject_HEAD_INIT(NULL, 0)
-	"itertools.imap",		/* tp_name */
-	sizeof(imapobject),		/* tp_basicsize */
+	"itertools.chain",		/* tp_name */
+	sizeof(chainobject),		/* tp_basicsize */
 	0,				/* tp_itemsize */
 	/* methods */
-	(destructor)imap_dealloc,	/* tp_dealloc */
+	(destructor)chain_dealloc,	/* tp_dealloc */
 	0,				/* tp_print */
 	0,				/* tp_getattr */
 	0,				/* tp_setattr */
@@ -1574,14 +1574,14 @@
 	0,				/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
 		Py_TPFLAGS_BASETYPE,	/* tp_flags */
-	imap_doc,			/* tp_doc */
-	(traverseproc)imap_traverse,	/* tp_traverse */
+	chain_doc,			/* tp_doc */
+	(traverseproc)chain_traverse,	/* tp_traverse */
 	0,				/* tp_clear */
 	0,				/* tp_richcompare */
 	0,				/* tp_weaklistoffset */
 	PyObject_SelfIter,		/* tp_iter */
-	(iternextfunc)imap_next,	/* tp_iternext */
-	0,				/* tp_methods */
+	(iternextfunc)chain_next,	/* tp_iternext */
+	chain_methods,			/* tp_methods */
 	0,				/* tp_members */
 	0,				/* tp_getset */
 	0,				/* tp_base */
@@ -1591,117 +1591,220 @@
 	0,				/* tp_dictoffset */
 	0,				/* tp_init */
 	0,				/* tp_alloc */
-	imap_new,			/* tp_new */
+	chain_new,			/* tp_new */
 	PyObject_GC_Del,		/* tp_free */
 };
 
 
-/* chain object ************************************************************/
+/* product object ************************************************************/
 
 typedef struct {
 	PyObject_HEAD
-	Py_ssize_t tuplesize;
-	Py_ssize_t iternum;		/* which iterator is active */
-	PyObject *ittuple;		/* tuple of iterators */
-} chainobject;
+	PyObject *pools;		/* tuple of pool tuples */
+	Py_ssize_t *indices;            /* one index per pool */
+	PyObject *result;               /* most recently returned result tuple */
+	int stopped;                    /* set to 1 when the product iterator is exhausted */
+} productobject;
 
-static PyTypeObject chain_type;
+static PyTypeObject product_type;
 
 static PyObject *
-chain_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+product_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-	chainobject *lz;
-	Py_ssize_t tuplesize = PySequence_Length(args);
+	productobject *lz;
+	Py_ssize_t nargs, npools, repeat=1;
+	PyObject *pools = NULL;
+	Py_ssize_t *indices = NULL;
 	Py_ssize_t i;
-	PyObject *ittuple;
-
-	if (type == &chain_type && !_PyArg_NoKeywords("chain()", kwds))
-		return NULL;
 
-	/* obtain iterators */
-	assert(PyTuple_Check(args));
-	ittuple = PyTuple_New(tuplesize);
-	if (ittuple == NULL)
-		return NULL;
-	for (i=0; i < tuplesize; ++i) {
-		PyObject *item = PyTuple_GET_ITEM(args, i);
-		PyObject *it = PyObject_GetIter(item);
-		if (it == NULL) {
-			if (PyErr_ExceptionMatches(PyExc_TypeError))
-				PyErr_Format(PyExc_TypeError,
-				    "chain argument #%zd must support iteration",
-				    i+1);
-			Py_DECREF(ittuple);
+	if (kwds != NULL) {
+		char *kwlist[] = {"repeat", 0};
+		PyObject *tmpargs = PyTuple_New(0);
+		if (tmpargs == NULL)
+			return NULL;
+		if (!PyArg_ParseTupleAndKeywords(tmpargs, kwds, "|n:product", kwlist, &repeat)) {
+			Py_DECREF(tmpargs);
+			return NULL;
+		}
+		Py_DECREF(tmpargs);
+		if (repeat < 0) {
+			PyErr_SetString(PyExc_ValueError, 
+					"repeat argument cannot be negative");
 			return NULL;
 		}
-		PyTuple_SET_ITEM(ittuple, i, it);
 	}
 
-	/* create chainobject structure */
-	lz = (chainobject *)type->tp_alloc(type, 0);
-	if (lz == NULL) {
-		Py_DECREF(ittuple);
-		return NULL;
+	assert(PyTuple_Check(args));
+	nargs = (repeat == 0) ? 0 : PyTuple_GET_SIZE(args);
+	npools = nargs * repeat;
+
+	indices = PyMem_Malloc(npools * sizeof(Py_ssize_t));
+	if (indices == NULL) {
+    		PyErr_NoMemory();
+		goto error;
 	}
 
-	lz->ittuple = ittuple;
-	lz->iternum = 0;
-	lz->tuplesize = tuplesize;
+	pools = PyTuple_New(npools);
+	if (pools == NULL)
+		goto error;
+
+	for (i=0; i < nargs ; ++i) {
+		PyObject *item = PyTuple_GET_ITEM(args, i);
+		PyObject *pool = PySequence_Tuple(item);
+		if (pool == NULL)
+			goto error;
+		PyTuple_SET_ITEM(pools, i, pool);
+		indices[i] = 0;
+	}
+	for ( ; i < npools; ++i) {
+		PyObject *pool = PyTuple_GET_ITEM(pools, i - nargs);
+		Py_INCREF(pool);
+		PyTuple_SET_ITEM(pools, i, pool);
+		indices[i] = 0;
+	}
+
+	/* create productobject structure */
+	lz = (productobject *)type->tp_alloc(type, 0);
+	if (lz == NULL)
+		goto error;
+
+	lz->pools = pools;
+	lz->indices = indices;
+	lz->result = NULL;
+	lz->stopped = 0;
 
 	return (PyObject *)lz;
+
+error:
+	if (indices != NULL)
+		PyMem_Free(indices);
+	Py_XDECREF(pools);
+	return NULL;
 }
 
 static void
-chain_dealloc(chainobject *lz)
+product_dealloc(productobject *lz)
 {
 	PyObject_GC_UnTrack(lz);
-	Py_XDECREF(lz->ittuple);
-	Py_Type(lz)->tp_free(lz);
+	Py_XDECREF(lz->pools);
+	Py_XDECREF(lz->result);
+	PyMem_Free(lz->indices);
+	Py_TYPE(lz)->tp_free(lz);
 }
 
 static int
-chain_traverse(chainobject *lz, visitproc visit, void *arg)
+product_traverse(productobject *lz, visitproc visit, void *arg)
 {
-	Py_VISIT(lz->ittuple);
+	Py_VISIT(lz->pools);
+	Py_VISIT(lz->result);
 	return 0;
 }
 
 static PyObject *
-chain_next(chainobject *lz)
+product_next(productobject *lz)
 {
-	PyObject *it;
-	PyObject *item;
+	PyObject *pool;
+	PyObject *elem;
+	PyObject *oldelem;
+	PyObject *pools = lz->pools;
+	PyObject *result = lz->result;
+	Py_ssize_t npools = PyTuple_GET_SIZE(pools);
+	Py_ssize_t i;
 
-	while (lz->iternum < lz->tuplesize) {
-		it = PyTuple_GET_ITEM(lz->ittuple, lz->iternum);
-		item = PyIter_Next(it);
-		if (item != NULL)
-			return item;
-		if (PyErr_Occurred()) {
-			if (PyErr_ExceptionMatches(PyExc_StopIteration))
-				PyErr_Clear();
-			else
-				return NULL;
+	if (lz->stopped)
+		return NULL;
+
+	if (result == NULL) {
+                /* On the first pass, return an initial tuple filled with the 
+                   first element from each pool. */
+		result = PyTuple_New(npools);
+		if (result == NULL)
+            		goto empty;
+		lz->result = result;
+		for (i=0; i < npools; i++) {
+			pool = PyTuple_GET_ITEM(pools, i);
+			if (PyTuple_GET_SIZE(pool) == 0)
+				goto empty;
+    			elem = PyTuple_GET_ITEM(pool, 0);
+    			Py_INCREF(elem);
+    			PyTuple_SET_ITEM(result, i, elem);
 		}
-		lz->iternum++;
+	} else {
+		Py_ssize_t *indices = lz->indices;
+
+		/* Copy the previous result tuple or re-use it if available */
+		if (Py_REFCNT(result) > 1) {
+			PyObject *old_result = result;
+			result = PyTuple_New(npools);
+			if (result == NULL)
+				goto empty;
+			lz->result = result;
+			for (i=0; i < npools; i++) {
+				elem = PyTuple_GET_ITEM(old_result, i);
+    				Py_INCREF(elem);
+    				PyTuple_SET_ITEM(result, i, elem);
+			}
+			Py_DECREF(old_result);
+		}
+		/* Now, we've got the only copy so we can update it in-place */
+		assert (npools==0 || Py_REFCNT(result) == 1);
+
+                /* Update the pool indices right-to-left.  Only advance to the
+                   next pool when the previous one rolls-over */
+		for (i=npools-1 ; i >= 0 ; i--) {
+			pool = PyTuple_GET_ITEM(pools, i);
+			indices[i]++;
+			if (indices[i] == PyTuple_GET_SIZE(pool)) {
+				/* Roll-over and advance to next pool */
+				indices[i] = 0;
+				elem = PyTuple_GET_ITEM(pool, 0);
+				Py_INCREF(elem);
+				oldelem = PyTuple_GET_ITEM(result, i);
+				PyTuple_SET_ITEM(result, i, elem);
+				Py_DECREF(oldelem);
+			} else {
+				/* No rollover. Just increment and stop here. */
+				elem = PyTuple_GET_ITEM(pool, indices[i]);
+				Py_INCREF(elem);
+				oldelem = PyTuple_GET_ITEM(result, i);
+				PyTuple_SET_ITEM(result, i, elem);
+				Py_DECREF(oldelem);
+				break;
+			}
+		}
+
+		/* If i is negative, then the indices have all rolled-over
+                   and we're done. */
+		if (i < 0)
+			goto empty;
 	}
+
+	Py_INCREF(result);
+	return result;
+
+empty:
+	lz->stopped = 1;
 	return NULL;
 }
 
-PyDoc_STRVAR(chain_doc,
-"chain(*iterables) --> chain object\n\
+PyDoc_STRVAR(product_doc,
+"product(*iterables) --> product object\n\
 \n\
-Return a chain object whose .__next__() method returns elements from the\n\
-first iterable until it is exhausted, then elements from the next\n\
-iterable, until all of the iterables are exhausted.");
+Cartesian product of input iterables.  Equivalent to nested for-loops.\n\n\
+For example, product(A, B) returns the same as:  ((x,y) for x in A for y in B).\n\
+The leftmost iterators are in the outermost for-loop, so the output tuples\n\
+cycle in a manner similar to an odometer (with the rightmost element changing\n\
+on every iteration).\n\n\
+product('ab', range(3)) --> ('a',0) ('a',1) ('a',2) ('b',0) ('b',1) ('b',2)\n\
+product((0,1), (0,1), (0,1)) --> (0,0,0) (0,0,1) (0,1,0) (0,1,1) (1,0,0) ...");
 
-static PyTypeObject chain_type = {
+static PyTypeObject product_type = {
 	PyVarObject_HEAD_INIT(NULL, 0)
-	"itertools.chain",		/* tp_name */
-	sizeof(chainobject),		/* tp_basicsize */
+	"itertools.product",		/* tp_name */
+	sizeof(productobject),	/* tp_basicsize */
 	0,				/* tp_itemsize */
 	/* methods */
-	(destructor)chain_dealloc,	/* tp_dealloc */
+	(destructor)product_dealloc,	/* tp_dealloc */
 	0,				/* tp_print */
 	0,				/* tp_getattr */
 	0,				/* tp_setattr */
@@ -1718,13 +1821,13 @@
 	0,				/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
 		Py_TPFLAGS_BASETYPE,	/* tp_flags */
-	chain_doc,			/* tp_doc */
-	(traverseproc)chain_traverse,	/* tp_traverse */
+	product_doc,			/* tp_doc */
+	(traverseproc)product_traverse,	/* tp_traverse */
 	0,				/* tp_clear */
 	0,				/* tp_richcompare */
 	0,				/* tp_weaklistoffset */
 	PyObject_SelfIter,		/* tp_iter */
-	(iternextfunc)chain_next,	/* tp_iternext */
+	(iternextfunc)product_next,	/* tp_iternext */
 	0,				/* tp_methods */
 	0,				/* tp_members */
 	0,				/* tp_getset */
@@ -1735,116 +1838,474 @@
 	0,				/* tp_dictoffset */
 	0,				/* tp_init */
 	0,				/* tp_alloc */
-	chain_new,			/* tp_new */
+	product_new,			/* tp_new */
 	PyObject_GC_Del,		/* tp_free */
 };
 
 
-/* ifilter object ************************************************************/
+/* combinations object ************************************************************/
 
 typedef struct {
 	PyObject_HEAD
-	PyObject *func;
-	PyObject *it;
-} ifilterobject;
+	PyObject *pool;			/* input converted to a tuple */
+	Py_ssize_t *indices;            /* one index per result element */
+	PyObject *result;               /* most recently returned result tuple */
+	Py_ssize_t r;			/* size of result tuple */
+	int stopped;			/* set to 1 when the combinations iterator is exhausted */
+} combinationsobject;
+
+static PyTypeObject combinations_type;
+
+static PyObject *
+combinations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+	combinationsobject *co;
+	Py_ssize_t n;
+	Py_ssize_t r;
+	PyObject *pool = NULL;
+	PyObject *iterable = NULL;
+	Py_ssize_t *indices = NULL;
+	Py_ssize_t i;
+	static char *kwargs[] = {"iterable", "r", NULL};
+ 
+ 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "On:combinations", kwargs, 
+					 &iterable, &r))
+		return NULL;
 
-static PyTypeObject ifilter_type;
+	pool = PySequence_Tuple(iterable);
+	if (pool == NULL)
+		goto error;
+	n = PyTuple_GET_SIZE(pool);
+	if (r < 0) {
+		PyErr_SetString(PyExc_ValueError, "r must be non-negative");
+		goto error;
+	}
+	if (r > n) {
+		PyErr_SetString(PyExc_ValueError, "r cannot be bigger than the iterable");
+		goto error;
+	}
+
+	indices = PyMem_Malloc(r * sizeof(Py_ssize_t));
+	if (indices == NULL) {
+    		PyErr_NoMemory();
+		goto error;
+	}
+
+	for (i=0 ; i<r ; i++)
+		indices[i] = i;
+
+	/* create combinationsobject structure */
+	co = (combinationsobject *)type->tp_alloc(type, 0);
+	if (co == NULL)
+		goto error;
+
+	co->pool = pool;
+	co->indices = indices;
+	co->result = NULL;
+	co->r = r;
+	co->stopped = 0;
+
+	return (PyObject *)co;
+
+error:
+	if (indices != NULL)
+		PyMem_Free(indices);
+	Py_XDECREF(pool);
+	return NULL;
+}
+
+static void
+combinations_dealloc(combinationsobject *co)
+{
+	PyObject_GC_UnTrack(co);
+	Py_XDECREF(co->pool);
+	Py_XDECREF(co->result);
+	PyMem_Free(co->indices);
+	Py_TYPE(co)->tp_free(co);
+}
+
+static int
+combinations_traverse(combinationsobject *co, visitproc visit, void *arg)
+{
+	Py_VISIT(co->pool);
+	Py_VISIT(co->result);
+	return 0;
+}
 
 static PyObject *
-ifilter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+combinations_next(combinationsobject *co)
 {
-	PyObject *func, *seq;
-	PyObject *it;
-	ifilterobject *lz;
+	PyObject *elem;
+	PyObject *oldelem;
+	PyObject *pool = co->pool;
+	Py_ssize_t *indices = co->indices;
+	PyObject *result = co->result;
+	Py_ssize_t n = PyTuple_GET_SIZE(pool);
+	Py_ssize_t r = co->r;
+	Py_ssize_t i, j, index;
 
-	if (type == &ifilter_type && !_PyArg_NoKeywords("ifilter()", kwds))
+	if (co->stopped)
 		return NULL;
 
-	if (!PyArg_UnpackTuple(args, "ifilter", 2, 2, &func, &seq))
-		return NULL;
+	if (result == NULL) {
+                /* On the first pass, initialize result tuple using the indices */
+		result = PyTuple_New(r);
+		if (result == NULL)
+            		goto empty;
+		co->result = result;
+		for (i=0; i<r ; i++) {
+			index = indices[i];
+    			elem = PyTuple_GET_ITEM(pool, index);
+    			Py_INCREF(elem);
+    			PyTuple_SET_ITEM(result, i, elem);
+		}
+	} else {
+		/* Copy the previous result tuple or re-use it if available */
+		if (Py_REFCNT(result) > 1) {
+			PyObject *old_result = result;
+			result = PyTuple_New(r);
+			if (result == NULL)
+				goto empty;
+			co->result = result;
+			for (i=0; i<r ; i++) {
+				elem = PyTuple_GET_ITEM(old_result, i);
+    				Py_INCREF(elem);
+    				PyTuple_SET_ITEM(result, i, elem);
+			}
+			Py_DECREF(old_result);
+		}
+		/* Now, we've got the only copy so we can update it in-place
+		 * CPython's empty tuple is a singleton and cached in
+		 * PyTuple's freelist.
+		 */
+		assert(r == 0 || Py_REFCNT(result) == 1);
+
+                /* Scan indices right-to-left until finding one that is not
+                   at its maximum (i + n - r). */
+		for (i=r-1 ; i >= 0 && indices[i] == i+n-r ; i--)
+			;
+
+		/* If i is negative, then the indices are all at
+                   their maximum value and we're done. */
+		if (i < 0)
+			goto empty;
+
+		/* Increment the current index which we know is not at its
+                   maximum.  Then move back to the right setting each index
+                   to its lowest possible value (one higher than the index
+                   to its left -- this maintains the sort order invariant). */
+		indices[i]++;
+		for (j=i+1 ; j<r ; j++)
+			indices[j] = indices[j-1] + 1;
+
+		/* Update the result tuple for the new indices
+		   starting with i, the leftmost index that changed */
+		for ( ; i<r ; i++) {
+			index = indices[i];
+			elem = PyTuple_GET_ITEM(pool, index);
+			Py_INCREF(elem);
+			oldelem = PyTuple_GET_ITEM(result, i);
+			PyTuple_SET_ITEM(result, i, elem);
+			Py_DECREF(oldelem);
+		}
+	}
 
-	/* Get iterator. */
-	it = PyObject_GetIter(seq);
-	if (it == NULL)
-		return NULL;
+	Py_INCREF(result);
+	return result;
 
-	/* create ifilterobject structure */
-	lz = (ifilterobject *)type->tp_alloc(type, 0);
-	if (lz == NULL) {
-		Py_DECREF(it);
+empty:
+	co->stopped = 1;
+	return NULL;
+}
+
+PyDoc_STRVAR(combinations_doc,
+"combinations(iterables) --> combinations object\n\
+\n\
+Return successive r-length combinations of elements in the iterable.\n\n\
+combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)");
+
+static PyTypeObject combinations_type = {
+	PyVarObject_HEAD_INIT(NULL, 0)
+	"itertools.combinations",		/* tp_name */
+	sizeof(combinationsobject),	/* tp_basicsize */
+	0,				/* tp_itemsize */
+	/* methods */
+	(destructor)combinations_dealloc,	/* tp_dealloc */
+	0,				/* tp_print */
+	0,				/* tp_getattr */
+	0,				/* tp_setattr */
+	0,				/* tp_compare */
+	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_HAVE_GC |
+		Py_TPFLAGS_BASETYPE,	/* tp_flags */
+	combinations_doc,			/* tp_doc */
+	(traverseproc)combinations_traverse,	/* tp_traverse */
+	0,				/* tp_clear */
+	0,				/* tp_richcompare */
+	0,				/* tp_weaklistoffset */
+	PyObject_SelfIter,		/* tp_iter */
+	(iternextfunc)combinations_next,	/* tp_iternext */
+	0,				/* 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 */
+	combinations_new,			/* tp_new */
+	PyObject_GC_Del,		/* tp_free */
+};
+
+
+/* permutations object ************************************************************
+  
+def permutations(iterable, r=None):
+    'permutations(range(3), 2) --> (0,1) (0,2) (1,0) (1,2) (2,0) (2,1)'
+    pool = tuple(iterable)
+    n = len(pool)
+    r = n if r is None else r
+    indices = range(n)
+    cycles = range(n-r+1, n+1)[::-1]
+    yield tuple(pool[i] for i in indices[:r])
+    while n:
+        for i in reversed(range(r)):
+            cycles[i] -= 1
+            if cycles[i] == 0:
+                indices[i:] = indices[i+1:] + indices[i:i+1]
+                cycles[i] = n - i
+            else:
+                j = cycles[i]
+                indices[i], indices[-j] = indices[-j], indices[i]
+                yield tuple(pool[i] for i in indices[:r])
+                break
+        else:
+            return
+*/
+
+typedef struct {
+	PyObject_HEAD
+	PyObject *pool;			/* input converted to a tuple */
+	Py_ssize_t *indices;            /* one index per element in the pool */
+	Py_ssize_t *cycles;		/* one rollover counter per element in the result */
+	PyObject *result;               /* most recently returned result tuple */
+	Py_ssize_t r;			/* size of result tuple */
+	int stopped;			/* set to 1 when the permutations iterator is exhausted */
+} permutationsobject;
+
+static PyTypeObject permutations_type;
+
+static PyObject *
+permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+	permutationsobject *po;
+	Py_ssize_t n;
+	Py_ssize_t r;
+	PyObject *robj = Py_None;
+	PyObject *pool = NULL;
+	PyObject *iterable = NULL;
+	Py_ssize_t *indices = NULL;
+	Py_ssize_t *cycles = NULL;
+	Py_ssize_t i;
+	static char *kwargs[] = {"iterable", "r", NULL};
+ 
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:permutations", kwargs, 
+					 &iterable, &robj))
 		return NULL;
-	}
-	Py_INCREF(func);
-	lz->func = func;
-	lz->it = it;
 
-	return (PyObject *)lz;
+	pool = PySequence_Tuple(iterable);
+	if (pool == NULL)
+		goto error;
+	n = PyTuple_GET_SIZE(pool);
+
+	r = n;
+	if (robj != Py_None) {
+		if (!PyLong_Check(robj)) {
+			PyErr_SetString(PyExc_TypeError, "Expected int as r");
+			return NULL;
+		}
+		r = PyLong_AsSsize_t(robj);
+		if (r == -1 && PyErr_Occurred())
+			goto error;
+	}
+	if (r < 0) {
+		PyErr_SetString(PyExc_ValueError, "r must be non-negative");
+		goto error;
+	}
+	if (r > n) {
+		PyErr_SetString(PyExc_ValueError, "r cannot be bigger than the iterable");
+		goto error;
+	}
+
+	indices = PyMem_Malloc(n * sizeof(Py_ssize_t));
+	cycles = PyMem_Malloc(r * sizeof(Py_ssize_t));
+	if (indices == NULL || cycles == NULL) {
+    		PyErr_NoMemory();
+		goto error;
+	}
+
+	for (i=0 ; i<n ; i++)
+		indices[i] = i;
+	for (i=0 ; i<r ; i++)
+		cycles[i] = n - i;
+
+	/* create permutationsobject structure */
+	po = (permutationsobject *)type->tp_alloc(type, 0);
+	if (po == NULL)
+		goto error;
+
+	po->pool = pool;
+	po->indices = indices;
+	po->cycles = cycles;
+	po->result = NULL;
+	po->r = r;
+	po->stopped = 0;
+
+	return (PyObject *)po;
+
+error:
+	if (indices != NULL)
+		PyMem_Free(indices);
+	if (cycles != NULL)
+		PyMem_Free(cycles);
+	Py_XDECREF(pool);
+	return NULL;
 }
 
 static void
-ifilter_dealloc(ifilterobject *lz)
+permutations_dealloc(permutationsobject *po)
 {
-	PyObject_GC_UnTrack(lz);
-	Py_XDECREF(lz->func);
-	Py_XDECREF(lz->it);
-	Py_Type(lz)->tp_free(lz);
+	PyObject_GC_UnTrack(po);
+	Py_XDECREF(po->pool);
+	Py_XDECREF(po->result);
+	PyMem_Free(po->indices);
+	PyMem_Free(po->cycles);
+	Py_TYPE(po)->tp_free(po);
 }
 
 static int
-ifilter_traverse(ifilterobject *lz, visitproc visit, void *arg)
+permutations_traverse(permutationsobject *po, visitproc visit, void *arg)
 {
-	Py_VISIT(lz->it);
-	Py_VISIT(lz->func);
+	Py_VISIT(po->pool);
+	Py_VISIT(po->result);
 	return 0;
 }
 
 static PyObject *
-ifilter_next(ifilterobject *lz)
+permutations_next(permutationsobject *po)
 {
-	PyObject *item;
-	PyObject *it = lz->it;
-	long ok;
-	PyObject *(*iternext)(PyObject *);
+	PyObject *elem;
+	PyObject *oldelem;
+	PyObject *pool = po->pool;
+	Py_ssize_t *indices = po->indices;
+	Py_ssize_t *cycles = po->cycles;
+	PyObject *result = po->result;
+	Py_ssize_t n = PyTuple_GET_SIZE(pool);
+	Py_ssize_t r = po->r;
+	Py_ssize_t i, j, k, index;
 
-	assert(PyIter_Check(it));
-	iternext = *Py_Type(it)->tp_iternext;
-	for (;;) {
-		item = iternext(it);
-		if (item == NULL)
-			return NULL;
+	if (po->stopped)
+		return NULL;
 
-		if (lz->func == Py_None) {
-			ok = PyObject_IsTrue(item);
-		} else {
-			PyObject *good;
-			good = PyObject_CallFunctionObjArgs(lz->func,
-							    item, NULL);
-			if (good == NULL) {
-				Py_DECREF(item);
-				return NULL;
+	if (result == NULL) {
+                /* On the first pass, initialize result tuple using the indices */
+		result = PyTuple_New(r);
+		if (result == NULL)
+            		goto empty;
+		po->result = result;
+		for (i=0; i<r ; i++) {
+			index = indices[i];
+    			elem = PyTuple_GET_ITEM(pool, index);
+    			Py_INCREF(elem);
+    			PyTuple_SET_ITEM(result, i, elem);
+		}
+	} else {
+		if (n == 0)
+			goto empty;
+
+		/* Copy the previous result tuple or re-use it if available */
+		if (Py_REFCNT(result) > 1) {
+			PyObject *old_result = result;
+			result = PyTuple_New(r);
+			if (result == NULL)
+				goto empty;
+			po->result = result;
+			for (i=0; i<r ; i++) {
+				elem = PyTuple_GET_ITEM(old_result, i);
+    				Py_INCREF(elem);
+    				PyTuple_SET_ITEM(result, i, elem);
 			}
-			ok = PyObject_IsTrue(good);
-			Py_DECREF(good);
+			Py_DECREF(old_result);
 		}
-		if (ok)
-			return item;
-		Py_DECREF(item);
+		/* Now, we've got the only copy so we can update it in-place */
+		assert(r == 0 || Py_REFCNT(result) == 1);
+
+                /* Decrement rightmost cycle, moving leftward upon zero rollover */
+		for (i=r-1 ; i>=0 ; i--) {
+			cycles[i] -= 1;
+			if (cycles[i] == 0) {
+				/* rotatation: indices[i:] = indices[i+1:] + indices[i:i+1] */
+				index = indices[i];
+				for (j=i ; j<n-1 ; j++)
+					indices[j] = indices[j+1];
+				indices[n-1] = index;
+				cycles[i] = n - i;
+			} else {
+				j = cycles[i];
+				index = indices[i];
+				indices[i] = indices[n-j];
+				indices[n-j] = index;
+
+				for (k=i; k<r ; k++) {
+					/* start with i, the leftmost element that changed */
+					/* yield tuple(pool[k] for k in indices[:r]) */
+					index = indices[k];
+					elem = PyTuple_GET_ITEM(pool, index);
+    					Py_INCREF(elem);
+					oldelem = PyTuple_GET_ITEM(result, k);
+    					PyTuple_SET_ITEM(result, k, elem);
+					Py_DECREF(oldelem);
+				}
+				break;
+			}
+		}
+		/* If i is negative, then the cycles have all
+                   rolled-over and we're done. */
+		if (i < 0)
+			goto empty;
 	}
+	Py_INCREF(result);
+	return result;
+
+empty:
+	po->stopped = 1;
+	return NULL;
 }
 
-PyDoc_STRVAR(ifilter_doc,
-"ifilter(function or None, sequence) --> ifilter object\n\
+PyDoc_STRVAR(permutations_doc,
+"permutations(iterables[, r]) --> permutations object\n\
 \n\
-Return those items of sequence for which function(item) is true.\n\
-If function is None, return the items that are true.");
+Return successive r-length permutations of elements in the iterable.\n\n\
+permutations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)");
 
-static PyTypeObject ifilter_type = {
+static PyTypeObject permutations_type = {
 	PyVarObject_HEAD_INIT(NULL, 0)
-	"itertools.ifilter",		/* tp_name */
-	sizeof(ifilterobject),		/* tp_basicsize */
+	"itertools.permutations",		/* tp_name */
+	sizeof(permutationsobject),	/* tp_basicsize */
 	0,				/* tp_itemsize */
 	/* methods */
-	(destructor)ifilter_dealloc,	/* tp_dealloc */
+	(destructor)permutations_dealloc,	/* tp_dealloc */
 	0,				/* tp_print */
 	0,				/* tp_getattr */
 	0,				/* tp_setattr */
@@ -1861,13 +2322,13 @@
 	0,				/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
 		Py_TPFLAGS_BASETYPE,	/* tp_flags */
-	ifilter_doc,			/* tp_doc */
-	(traverseproc)ifilter_traverse,	/* tp_traverse */
+	permutations_doc,			/* tp_doc */
+	(traverseproc)permutations_traverse,	/* tp_traverse */
 	0,				/* tp_clear */
 	0,				/* tp_richcompare */
 	0,				/* tp_weaklistoffset */
 	PyObject_SelfIter,		/* tp_iter */
-	(iternextfunc)ifilter_next,	/* tp_iternext */
+	(iternextfunc)permutations_next,	/* tp_iternext */
 	0,				/* tp_methods */
 	0,				/* tp_members */
 	0,				/* tp_getset */
@@ -1878,33 +2339,33 @@
 	0,				/* tp_dictoffset */
 	0,				/* tp_init */
 	0,				/* tp_alloc */
-	ifilter_new,			/* tp_new */
+	permutations_new,			/* tp_new */
 	PyObject_GC_Del,		/* tp_free */
 };
 
 
-/* ifilterfalse object ************************************************************/
+/* filterfalse object ************************************************************/
 
 typedef struct {
 	PyObject_HEAD
 	PyObject *func;
 	PyObject *it;
-} ifilterfalseobject;
+} filterfalseobject;
 
-static PyTypeObject ifilterfalse_type;
+static PyTypeObject filterfalse_type;
 
 static PyObject *
-ifilterfalse_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+filterfalse_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
 	PyObject *func, *seq;
 	PyObject *it;
-	ifilterfalseobject *lz;
+	filterfalseobject *lz;
 
-	if (type == &ifilterfalse_type &&
-	    !_PyArg_NoKeywords("ifilterfalse()", kwds))
+	if (type == &filterfalse_type &&
+	    !_PyArg_NoKeywords("filterfalse()", kwds))
 		return NULL;
 
-	if (!PyArg_UnpackTuple(args, "ifilterfalse", 2, 2, &func, &seq))
+	if (!PyArg_UnpackTuple(args, "filterfalse", 2, 2, &func, &seq))
 		return NULL;
 
 	/* Get iterator. */
@@ -1912,8 +2373,8 @@
 	if (it == NULL)
 		return NULL;
 
-	/* create ifilterfalseobject structure */
-	lz = (ifilterfalseobject *)type->tp_alloc(type, 0);
+	/* create filterfalseobject structure */
+	lz = (filterfalseobject *)type->tp_alloc(type, 0);
 	if (lz == NULL) {
 		Py_DECREF(it);
 		return NULL;
@@ -1926,16 +2387,16 @@
 }
 
 static void
-ifilterfalse_dealloc(ifilterfalseobject *lz)
+filterfalse_dealloc(filterfalseobject *lz)
 {
 	PyObject_GC_UnTrack(lz);
 	Py_XDECREF(lz->func);
 	Py_XDECREF(lz->it);
-	Py_Type(lz)->tp_free(lz);
+	Py_TYPE(lz)->tp_free(lz);
 }
 
 static int
-ifilterfalse_traverse(ifilterfalseobject *lz, visitproc visit, void *arg)
+filterfalse_traverse(filterfalseobject *lz, visitproc visit, void *arg)
 {
 	Py_VISIT(lz->it);
 	Py_VISIT(lz->func);
@@ -1943,7 +2404,7 @@
 }
 
 static PyObject *
-ifilterfalse_next(ifilterfalseobject *lz)
+filterfalse_next(filterfalseobject *lz)
 {
 	PyObject *item;
 	PyObject *it = lz->it;
@@ -1951,13 +2412,13 @@
 	PyObject *(*iternext)(PyObject *);
 
 	assert(PyIter_Check(it));
-	iternext = *Py_Type(it)->tp_iternext;
+	iternext = *Py_TYPE(it)->tp_iternext;
 	for (;;) {
 		item = iternext(it);
 		if (item == NULL)
 			return NULL;
 
-		if (lz->func == Py_None) {
+		if (lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type) {
 			ok = PyObject_IsTrue(item);
 		} else {
 			PyObject *good;
@@ -1976,19 +2437,19 @@
 	}
 }
 
-PyDoc_STRVAR(ifilterfalse_doc,
-"ifilterfalse(function or None, sequence) --> ifilterfalse object\n\
+PyDoc_STRVAR(filterfalse_doc,
+"filterfalse(function or None, sequence) --> filterfalse object\n\
 \n\
 Return those items of sequence for which function(item) is false.\n\
 If function is None, return the items that are false.");
 
-static PyTypeObject ifilterfalse_type = {
+static PyTypeObject filterfalse_type = {
 	PyVarObject_HEAD_INIT(NULL, 0)
-	"itertools.ifilterfalse",	/* tp_name */
-	sizeof(ifilterfalseobject),	/* tp_basicsize */
+	"itertools.filterfalse",	/* tp_name */
+	sizeof(filterfalseobject),	/* tp_basicsize */
 	0,				/* tp_itemsize */
 	/* methods */
-	(destructor)ifilterfalse_dealloc,	/* tp_dealloc */
+	(destructor)filterfalse_dealloc,	/* tp_dealloc */
 	0,				/* tp_print */
 	0,				/* tp_getattr */
 	0,				/* tp_setattr */
@@ -2005,13 +2466,13 @@
 	0,				/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
 		Py_TPFLAGS_BASETYPE,	/* tp_flags */
-	ifilterfalse_doc,		/* tp_doc */
-	(traverseproc)ifilterfalse_traverse,	/* tp_traverse */
+	filterfalse_doc,		/* tp_doc */
+	(traverseproc)filterfalse_traverse,	/* tp_traverse */
 	0,				/* tp_clear */
 	0,				/* tp_richcompare */
 	0,				/* tp_weaklistoffset */
 	PyObject_SelfIter,		/* tp_iter */
-	(iternextfunc)ifilterfalse_next,	/* tp_iternext */
+	(iternextfunc)filterfalse_next,	/* tp_iternext */
 	0,				/* tp_methods */
 	0,				/* tp_members */
 	0,				/* tp_getset */
@@ -2022,7 +2483,7 @@
 	0,				/* tp_dictoffset */
 	0,				/* tp_init */
 	0,				/* tp_alloc */
-	ifilterfalse_new,		/* tp_new */
+	filterfalse_new,		/* tp_new */
 	PyObject_GC_Del,		/* tp_free */
 };
 
@@ -2032,6 +2493,7 @@
 typedef struct {
 	PyObject_HEAD
 	Py_ssize_t cnt;
+	PyObject *long_cnt;	/* Arbitrarily large count when cnt >= PY_SSIZE_T_MAX */
 } countobject;
 
 static PyTypeObject count_type;
@@ -2041,37 +2503,89 @@
 {
 	countobject *lz;
 	Py_ssize_t cnt = 0;
+	PyObject *cnt_arg = NULL;
+	PyObject *long_cnt = NULL;
 
 	if (type == &count_type && !_PyArg_NoKeywords("count()", kwds))
 		return NULL;
 
-	if (!PyArg_ParseTuple(args, "|n:count", &cnt))
+	if (!PyArg_UnpackTuple(args, "count", 0, 1, &cnt_arg))
 		return NULL;
 
+	if (cnt_arg != NULL) {
+		cnt = PyLong_AsSsize_t(cnt_arg);
+		if (cnt == -1 && PyErr_Occurred()) {
+			PyErr_Clear();
+			if (!PyLong_Check(cnt_arg)) {
+				PyErr_SetString(PyExc_TypeError, "an integer is required");
+				return NULL;
+			}
+			long_cnt = cnt_arg;
+			Py_INCREF(long_cnt);
+			cnt = PY_SSIZE_T_MAX;
+		}
+	}
+
 	/* create countobject structure */
 	lz = (countobject *)PyObject_New(countobject, &count_type);
-	if (lz == NULL)
+	if (lz == NULL) {
+		Py_XDECREF(long_cnt);
 		return NULL;
+	}
 	lz->cnt = cnt;
+	lz->long_cnt = long_cnt;
 
 	return (PyObject *)lz;
 }
 
+static void
+count_dealloc(countobject *lz)
+{
+	Py_XDECREF(lz->long_cnt); 
+	PyObject_Del(lz);
+}
+
+static PyObject *
+count_nextlong(countobject *lz)
+{
+	static PyObject *one = NULL;
+	PyObject *cnt;
+	PyObject *stepped_up;
+
+	if (lz->long_cnt == NULL) {
+		lz->long_cnt = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
+		if (lz->long_cnt == NULL)
+			return NULL;
+	}
+	if (one == NULL) {
+		one = PyLong_FromLong(1);
+		if (one == NULL)
+			return NULL;
+	}
+	cnt = lz->long_cnt;
+	assert(cnt != NULL);
+	stepped_up = PyNumber_Add(cnt, one);
+	if (stepped_up == NULL)
+		return NULL;
+	lz->long_cnt = stepped_up;
+	return cnt;
+}
+
 static PyObject *
 count_next(countobject *lz)
 {
-        if (lz->cnt == PY_SSIZE_T_MAX) {
-                PyErr_SetString(PyExc_OverflowError,
-                        "cannot count beyond PY_SSIZE_T_MAX");                
-                return NULL;         
-        }
-	return PyInt_FromSsize_t(lz->cnt++);
+        if (lz->cnt == PY_SSIZE_T_MAX)
+		return count_nextlong(lz);
+	return PyLong_FromSsize_t(lz->cnt++);
 }
 
 static PyObject *
 count_repr(countobject *lz)
 {
-	return PyUnicode_FromFormat("count(%zd)", lz->cnt);
+        if (lz->cnt != PY_SSIZE_T_MAX)
+		return PyUnicode_FromFormat("count(%zd)", lz->cnt);
+
+	return PyUnicode_FromFormat("count(%R)", lz->long_cnt);
 }
 
 PyDoc_STRVAR(count_doc,
@@ -2086,7 +2600,7 @@
 	sizeof(countobject),		/* tp_basicsize */
 	0,				/* tp_itemsize */
 	/* methods */
-	(destructor)PyObject_Del,	/* tp_dealloc */
+	(destructor)count_dealloc,	/* tp_dealloc */
 	0,				/* tp_print */
 	0,				/* tp_getattr */
 	0,				/* tp_setattr */
@@ -2123,193 +2637,6 @@
 };
 
 
-/* izip object ************************************************************/
-
-#include "Python.h"
-
-typedef struct {
-	PyObject_HEAD
-	Py_ssize_t	tuplesize;
-	PyObject *ittuple;		/* tuple of iterators */
-	PyObject *result;
-} izipobject;
-
-static PyTypeObject izip_type;
-
-static PyObject *
-izip_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
-	izipobject *lz;
-	Py_ssize_t i;
-	PyObject *ittuple;  /* tuple of iterators */
-	PyObject *result;
-	Py_ssize_t tuplesize = PySequence_Length(args);
-
-	if (type == &izip_type && !_PyArg_NoKeywords("izip()", kwds))
-		return NULL;
-
-	/* args must be a tuple */
-	assert(PyTuple_Check(args));
-
-	/* obtain iterators */
-	ittuple = PyTuple_New(tuplesize);
-	if (ittuple == NULL)
-		return NULL;
-	for (i=0; i < tuplesize; ++i) {
-		PyObject *item = PyTuple_GET_ITEM(args, i);
-		PyObject *it = PyObject_GetIter(item);
-		if (it == NULL) {
-			if (PyErr_ExceptionMatches(PyExc_TypeError))
-				PyErr_Format(PyExc_TypeError,
-				    "izip argument #%zd must support iteration",
-				    i+1);
-			Py_DECREF(ittuple);
-			return NULL;
-		}
-		PyTuple_SET_ITEM(ittuple, i, it);
-	}
-
-	/* create a result holder */
-	result = PyTuple_New(tuplesize);
-	if (result == NULL) {
-		Py_DECREF(ittuple);
-		return NULL;
-	}
-	for (i=0 ; i < tuplesize ; i++) {
-		Py_INCREF(Py_None);
-		PyTuple_SET_ITEM(result, i, Py_None);
-	}
-
-	/* create izipobject structure */
-	lz = (izipobject *)type->tp_alloc(type, 0);
-	if (lz == NULL) {
-		Py_DECREF(ittuple);
-		Py_DECREF(result);
-		return NULL;
-	}
-	lz->ittuple = ittuple;
-	lz->tuplesize = tuplesize;
-	lz->result = result;
-
-	return (PyObject *)lz;
-}
-
-static void
-izip_dealloc(izipobject *lz)
-{
-	PyObject_GC_UnTrack(lz);
-	Py_XDECREF(lz->ittuple);
-	Py_XDECREF(lz->result);
-	Py_Type(lz)->tp_free(lz);
-}
-
-static int
-izip_traverse(izipobject *lz, visitproc visit, void *arg)
-{
-	Py_VISIT(lz->ittuple);
-	Py_VISIT(lz->result);
-	return 0;
-}
-
-static PyObject *
-izip_next(izipobject *lz)
-{
-	Py_ssize_t i;
-	Py_ssize_t tuplesize = lz->tuplesize;
-	PyObject *result = lz->result;
-	PyObject *it;
-	PyObject *item;
-	PyObject *olditem;
-
-	if (tuplesize == 0)
-		return NULL;
-	if (Py_Refcnt(result) == 1) {
-		Py_INCREF(result);
-		for (i=0 ; i < tuplesize ; i++) {
-			it = PyTuple_GET_ITEM(lz->ittuple, i);
-			assert(PyIter_Check(it));
-			item = (*Py_Type(it)->tp_iternext)(it);
-			if (item == NULL) {
-				Py_DECREF(result);
-				return NULL;
-			}
-			olditem = PyTuple_GET_ITEM(result, i);
-			PyTuple_SET_ITEM(result, i, item);
-			Py_DECREF(olditem);
-		}
-	} else {
-		result = PyTuple_New(tuplesize);
-		if (result == NULL)
-			return NULL;
-		for (i=0 ; i < tuplesize ; i++) {
-			it = PyTuple_GET_ITEM(lz->ittuple, i);
-			assert(PyIter_Check(it));
-			item = (*Py_Type(it)->tp_iternext)(it);
-			if (item == NULL) {
-				Py_DECREF(result);
-				return NULL;
-			}
-			PyTuple_SET_ITEM(result, i, item);
-		}
-	}
-	return result;
-}
-
-PyDoc_STRVAR(izip_doc,
-"izip(iter1 [,iter2 [...]]) --> izip object\n\
-\n\
-Return a izip object whose .__next__() method returns a tuple where\n\
-the i-th element comes from the i-th iterable argument.  The .__next__()\n\
-method continues until the shortest iterable in the argument sequence\n\
-is exhausted and then it raises StopIteration.  Works like the zip()\n\
-function but consumes less memory by returning an iterator instead of\n\
-a list.");
-
-static PyTypeObject izip_type = {
-	PyVarObject_HEAD_INIT(NULL, 0)
-	"itertools.izip",		/* tp_name */
-	sizeof(izipobject),		/* tp_basicsize */
-	0,				/* tp_itemsize */
-	/* methods */
-	(destructor)izip_dealloc,	/* tp_dealloc */
-	0,				/* tp_print */
-	0,				/* tp_getattr */
-	0,				/* tp_setattr */
-	0,				/* tp_compare */
-	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_HAVE_GC |
-		Py_TPFLAGS_BASETYPE,	/* tp_flags */
-	izip_doc,			/* tp_doc */
-	(traverseproc)izip_traverse,    /* tp_traverse */
-	0,				/* tp_clear */
-	0,				/* tp_richcompare */
-	0,				/* tp_weaklistoffset */
-	PyObject_SelfIter,		/* tp_iter */
-	(iternextfunc)izip_next,	/* tp_iternext */
-	0,				/* 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 */
-	izip_new,			/* tp_new */
-	PyObject_GC_Del,		/* tp_free */
-};
-
-
 /* repeat object ************************************************************/
 
 typedef struct {
@@ -2350,7 +2677,7 @@
 {
 	PyObject_GC_UnTrack(ro);
 	Py_XDECREF(ro->element);
-	Py_Type(ro)->tp_free(ro);
+	Py_TYPE(ro)->tp_free(ro);
 }
 
 static int
@@ -2387,7 +2714,7 @@
                 PyErr_SetString(PyExc_TypeError, "len() of unsized object");
 		return NULL;
 	}
-        return PyInt_FromSize_t(ro->cnt);
+        return PyLong_FromSize_t(ro->cnt);
 }
 
 PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
@@ -2446,7 +2773,7 @@
 	PyObject_GC_Del,		/* tp_free */
 };
 
-/* iziplongest object ************************************************************/
+/* ziplongest object ************************************************************/
 
 #include "Python.h"
 
@@ -2457,14 +2784,14 @@
 	PyObject *ittuple;		/* tuple of iterators */
 	PyObject *result;
 	PyObject *fillvalue;
-} iziplongestobject;
+} ziplongestobject;
 
-static PyTypeObject iziplongest_type;
+static PyTypeObject ziplongest_type;
 
 static PyObject *
-izip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-	iziplongestobject *lz;
+	ziplongestobject *lz;
 	Py_ssize_t i;
 	PyObject *ittuple;  /* tuple of iterators */
 	PyObject *result;
@@ -2475,7 +2802,7 @@
                 fillvalue = PyDict_GetItemString(kwds, "fillvalue");
                 if (fillvalue == NULL  ||  PyDict_Size(kwds) > 1) {
                         PyErr_SetString(PyExc_TypeError,
-				"izip_longest() got an unexpected keyword argument");
+				"zip_longest() got an unexpected keyword argument");
                         return NULL;                      
                 }
         }
@@ -2493,7 +2820,7 @@
 		if (it == NULL) {
 			if (PyErr_ExceptionMatches(PyExc_TypeError))
 				PyErr_Format(PyExc_TypeError,
-				    "izip_longest argument #%zd must support iteration",
+				    "zip_longest argument #%zd must support iteration",
 				    i+1);
 			Py_DECREF(ittuple);
 			return NULL;
@@ -2512,8 +2839,8 @@
 		PyTuple_SET_ITEM(result, i, Py_None);
 	}
 
-	/* create iziplongestobject structure */
-	lz = (iziplongestobject *)type->tp_alloc(type, 0);
+	/* create ziplongestobject structure */
+	lz = (ziplongestobject *)type->tp_alloc(type, 0);
 	if (lz == NULL) {
 		Py_DECREF(ittuple);
 		Py_DECREF(result);
@@ -2529,17 +2856,17 @@
 }
 
 static void
-izip_longest_dealloc(iziplongestobject *lz)
+zip_longest_dealloc(ziplongestobject *lz)
 {
 	PyObject_GC_UnTrack(lz);
 	Py_XDECREF(lz->ittuple);
 	Py_XDECREF(lz->result);
 	Py_XDECREF(lz->fillvalue);
-	Py_Type(lz)->tp_free(lz);
+	Py_TYPE(lz)->tp_free(lz);
 }
 
 static int
-izip_longest_traverse(iziplongestobject *lz, visitproc visit, void *arg)
+zip_longest_traverse(ziplongestobject *lz, visitproc visit, void *arg)
 {
 	Py_VISIT(lz->ittuple);
 	Py_VISIT(lz->result);
@@ -2548,7 +2875,7 @@
 }
 
 static PyObject *
-izip_longest_next(iziplongestobject *lz)
+zip_longest_next(ziplongestobject *lz)
 {
 	Py_ssize_t i;
 	Py_ssize_t tuplesize = lz->tuplesize;
@@ -2561,7 +2888,7 @@
 		return NULL;
         if (lz->numactive == 0)
                 return NULL;
-	if (Py_Refcnt(result) == 1) {
+	if (Py_REFCNT(result) == 1) {
 		Py_INCREF(result);
 		for (i=0 ; i < tuplesize ; i++) {
 			it = PyTuple_GET_ITEM(lz->ittuple, i);
@@ -2570,7 +2897,7 @@
                                 item = lz->fillvalue;
                         } else {
                                 assert(PyIter_Check(it));
-                                item = (*Py_Type(it)->tp_iternext)(it);
+                                item = (*Py_TYPE(it)->tp_iternext)(it);
                                 if (item == NULL) {
                                         lz->numactive -= 1;      
                                         if (lz->numactive == 0) {
@@ -2599,7 +2926,7 @@
                                 item = lz->fillvalue;
                         } else {
                                 assert(PyIter_Check(it));
-                                item = (*Py_Type(it)->tp_iternext)(it);
+                                item = (*Py_TYPE(it)->tp_iternext)(it);
                                 if (item == NULL) {
                                         lz->numactive -= 1;      
                                         if (lz->numactive == 0) {
@@ -2619,10 +2946,10 @@
 	return result;
 }
 
-PyDoc_STRVAR(izip_longest_doc,
-"izip_longest(iter1 [,iter2 [...]], [fillvalue=None]) --> izip_longest object\n\
+PyDoc_STRVAR(zip_longest_doc,
+"zip_longest(iter1 [,iter2 [...]], [fillvalue=None]) --> zip_longest object\n\
 \n\
-Return an izip_longest object whose .__next__() method returns a tuple where\n\
+Return an zip_longest object whose .__next__() method returns a tuple where\n\
 the i-th element comes from the i-th iterable argument.  The .__next__()\n\
 method continues until the longest iterable in the argument sequence\n\
 is exhausted and then it raises StopIteration.  When the shorter iterables\n\
@@ -2630,13 +2957,13 @@
 defaults to None or can be specified by a keyword argument.\n\
 ");
 
-static PyTypeObject iziplongest_type = {
+static PyTypeObject ziplongest_type = {
 	PyVarObject_HEAD_INIT(NULL, 0)
-	"itertools.izip_longest",	/* tp_name */
-	sizeof(iziplongestobject),	/* tp_basicsize */
+	"itertools.zip_longest",	/* tp_name */
+	sizeof(ziplongestobject),	/* tp_basicsize */
 	0,				/* tp_itemsize */
 	/* methods */
-	(destructor)izip_longest_dealloc,	/* tp_dealloc */
+	(destructor)zip_longest_dealloc,	/* tp_dealloc */
 	0,				/* tp_print */
 	0,				/* tp_getattr */
 	0,				/* tp_setattr */
@@ -2653,13 +2980,13 @@
 	0,				/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
 		Py_TPFLAGS_BASETYPE,	/* tp_flags */
-	izip_longest_doc,			/* tp_doc */
-	(traverseproc)izip_longest_traverse,    /* tp_traverse */
+	zip_longest_doc,			/* tp_doc */
+	(traverseproc)zip_longest_traverse,    /* tp_traverse */
 	0,				/* tp_clear */
 	0,				/* tp_richcompare */
 	0,				/* tp_weaklistoffset */
 	PyObject_SelfIter,		/* tp_iter */
-	(iternextfunc)izip_longest_next,	/* tp_iternext */
+	(iternextfunc)zip_longest_next,	/* tp_iternext */
 	0,				/* tp_methods */
 	0,				/* tp_members */
 	0,				/* tp_getset */
@@ -2670,7 +2997,7 @@
 	0,				/* tp_dictoffset */
 	0,				/* tp_init */
 	0,				/* tp_alloc */
-	izip_longest_new,			/* tp_new */
+	zip_longest_new,			/* tp_new */
 	PyObject_GC_Del,		/* tp_free */
 };
 
@@ -2685,13 +3012,10 @@
 repeat(elem [,n]) --> elem, elem, elem, ... endlessly or up to n times\n\
 \n\
 Iterators terminating on the shortest input sequence:\n\
-izip(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... \n\
-izip_longest(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... \n\
-ifilter(pred, seq) --> elements of seq where pred(elem) is True\n\
-ifilterfalse(pred, seq) --> elements of seq where pred(elem) is False\n\
+zip_longest(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... \n\
+filterfalse(pred, seq) --> elements of seq where pred(elem) is False\n\
 islice(seq, [start,] stop [, step]) --> elements from\n\
        seq[start:stop:step]\n\
-imap(fun, p, q, ...) --> fun(p0, q0), fun(p1, q1), ...\n\
 starmap(fun, seq) --> fun(*seq[0]), fun(*seq[1]), ...\n\
 tee(it, n=2) --> (it1, it2 , ... itn) splits one iterator into n\n\
 chain(p, q, ...) --> p0, p1, ... plast, q0, q1, ... \n\
@@ -2713,24 +3037,24 @@
 	PyObject *m;
 	char *name;
 	PyTypeObject *typelist[] = {
+		&combinations_type,
 		&cycle_type,
 		&dropwhile_type,
 		&takewhile_type,
 		&islice_type,
 		&starmap_type,
-		&imap_type,
 		&chain_type,
-		&ifilter_type,
-		&ifilterfalse_type,
+		&filterfalse_type,
 		&count_type,
-		&izip_type,
-		&iziplongest_type,                
+		&ziplongest_type,
+		&permutations_type,
+		&product_type,         
 		&repeat_type,
 		&groupby_type,
 		NULL
 	};
 
-	Py_Type(&teedataobject_type) = &PyType_Type;
+	Py_TYPE(&teedataobject_type) = &PyType_Type;
 	m = Py_InitModule3("itertools", module_methods, module_doc);
 	if (m == NULL)
 		return;

Modified: python/branches/py3k-importlib/Modules/main.c
==============================================================================
--- python/branches/py3k-importlib/Modules/main.c	(original)
+++ python/branches/py3k-importlib/Modules/main.c	Thu Mar 27 00:48:05 2008
@@ -44,7 +44,7 @@
 static int  orig_argc;
 
 /* command line options */
-#define BASE_OPTS "c:dEhim:OStuvVW:xX?"
+#define BASE_OPTS "bBc:dEhim:OStuvVW:xX?"
 
 #define PROGRAM_OPTS BASE_OPTS
 
@@ -55,37 +55,42 @@
 /* Long usage message, split into parts < 512 bytes */
 static char *usage_1 = "\
 Options and arguments (and corresponding environment variables):\n\
+-b     : issue warnings about str(bytes_instance), str(buffer_instance)\n\
+         and comparing bytes/buffer with str. (-bb: issue errors)\n\
+-B     : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x\n\
 -c cmd : program passed in as string (terminates option list)\n\
 -d     : debug output from parser; also PYTHONDEBUG=x\n\
--E     : ignore environment variables (such as PYTHONPATH)\n\
+-E     : ignore PYTHON* environment variables (such as PYTHONPATH)\n\
 -h     : print this help message and exit (also --help)\n\
--i     : inspect interactively after running script; forces a prompt even\n\
-         if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n\
 ";
 static char *usage_2 = "\
+-i     : inspect interactively after running script; forces a prompt even\n\
+         if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n\
 -m mod : run library module as a script (terminates option list)\n\
 -O     : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x\n\
 -OO    : remove doc-strings in addition to the -O optimizations\n\
 -S     : don't imply 'import site' on initialization\n\
 -t     : issue warnings about inconsistent tab usage (-tt: issue errors)\n\
--u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x\n\
 ";
 static char *usage_3 = "\
+-u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x\n\
          see man page for details on internal buffering relating to '-u'\n\
 -v     : verbose (trace import statements); also PYTHONVERBOSE=x\n\
          can be supplied multiple times to increase verbosity\n\
 -V     : print the Python version number and exit (also --version)\n\
 -W arg : warning control; arg is action:message:category:module:lineno\n\
 -x     : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
-file   : program read from script file\n\
--      : program read from stdin (default; interactive mode if a tty)\n\
 ";
 static char *usage_4 = "\
+file   : program read from script file\n\
+-      : program read from stdin (default; interactive mode if a tty)\n\
 arg ...: arguments passed to program in sys.argv[1:]\n\n\
 Other environment variables:\n\
 PYTHONSTARTUP: file executed on interactive startup (no default)\n\
 PYTHONPATH   : '%c'-separated list of directories prefixed to the\n\
                default module search path.  The result is sys.path.\n\
+";
+static char *usage_5 = "\
 PYTHONHOME   : alternate <prefix> directory (or <prefix>%c<exec_prefix>).\n\
                The default module search path uses %s.\n\
 PYTHONCASEOK : ignore case in 'import' statements (Windows).\n\
@@ -104,7 +109,8 @@
 		fprintf(f, usage_1);
 		fprintf(f, usage_2);
 		fprintf(f, usage_3);
-		fprintf(f, usage_4, DELIM, DELIM, PYTHONHOMEHELP);
+		fprintf(f, usage_4, DELIM);
+		fprintf(f, usage_5, DELIM, PYTHONHOMEHELP);
 	}
 #if defined(__VMS)
 	if (exitcode == 0) {
@@ -130,12 +136,22 @@
 			(void) PyRun_SimpleFileExFlags(fp, startup, 0, cf);
 			PyErr_Clear();
 			fclose(fp);
+		} else {
+			int save_errno;
+			
+			save_errno = errno;
+			PySys_WriteStderr("Could not open PYTHONSTARTUP\n");
+			errno = save_errno;
+			PyErr_SetFromErrnoWithFilename(PyExc_IOError,
+					startup);
+			PyErr_Print();
+			PyErr_Clear();
 		}
 	}
 }
 
 
-static int RunModule(char *module)
+static int RunModule(char *module, int set_argv0)
 {
 	PyObject *runpy, *runmodule, *runargs, *result;
 	runpy = PyImport_ImportModule("runpy");
@@ -149,7 +165,7 @@
 		Py_DECREF(runpy);
 		return -1;
 	}
-	runargs = Py_BuildValue("(s)", module);
+	runargs = Py_BuildValue("(si)", module, set_argv0);
 	if (runargs == NULL) {
 		fprintf(stderr,
 			"Could not create arguments for runpy._run_module_as_main\n");
@@ -171,6 +187,38 @@
 	return 0;
 }
 
+static int RunMainFromImporter(char *filename)
+{
+	PyObject *argv0 = NULL, *importer = NULL;
+
+	if ((argv0 = PyUnicode_DecodeFSDefault(filename)) &&
+	    (importer = PyImport_GetImporter(argv0)) &&
+	    (importer->ob_type != &PyNullImporter_Type))
+	{
+		 /* argv0 is usable as an import source, so
+			put it in sys.path[0] and import __main__ */
+		PyObject *sys_path = NULL;
+		if ((sys_path = PySys_GetObject("path")) &&
+		    !PyList_SetItem(sys_path, 0, argv0))
+		{
+			Py_INCREF(argv0);
+			Py_DECREF(importer);
+			sys_path = NULL;
+			return RunModule("__main__", 0) != 0;
+		}
+	}
+	Py_XDECREF(argv0);
+	Py_XDECREF(importer);
+        if (PyErr_Occurred()) {
+		PyErr_Print();
+		return 1;
+        }
+	else {
+		return -1;
+	}
+}
+
+
 /* Wait until threading._shutdown completes, provided
    the threading module was imported in the first place.
    The shutdown routine will wait until all non-daemon
@@ -252,6 +300,9 @@
 		}
 
 		switch (c) {
+		case 'b':
+			Py_BytesWarningFlag++;
+			break;
 
 		case 'd':
 			Py_DebugFlag++;
@@ -266,6 +317,10 @@
 			Py_OptimizeFlag++;
 			break;
 
+		case 'B':
+			Py_DontWriteBytecodeFlag++;
+			break;
+
 		case 'S':
 			Py_NoSiteFlag++;
 			break;
@@ -339,38 +394,6 @@
 #else
 		filename = argv[_PyOS_optind];
 #endif
-		if (filename != NULL) {
-			if ((fp = fopen(filename, "r")) == NULL) {
-#ifdef HAVE_STRERROR
-				fprintf(stderr, "%s: can't open file '%s': [Errno %d] %s\n",
-					argv[0], filename, errno, strerror(errno));
-#else
-				fprintf(stderr, "%s: can't open file '%s': Errno %d\n",
-					argv[0], filename, errno);
-#endif
-				return 2;
-			}
-			else if (skipfirstline) {
-				int ch;
-				/* Push back first newline so line numbers
-				   remain the same */
-				while ((ch = getc(fp)) != EOF) {
-					if (ch == '\n') {
-						(void)ungetc(ch, fp);
-						break;
-					}
-				}
-			}
-			{
-				/* XXX: does this work on Win/Win64? (see posix_fstat) */
-				struct stat sb;
-				if (fstat(fileno(fp), &sb) == 0 &&
-				    S_ISDIR(sb.st_mode)) {
-					fprintf(stderr, "%s: '%s' is a directory, cannot continue\n", argv[0], filename);
-					return 1;
-				}
-			}
-		}
 	}
 
 	stdin_is_interactive = Py_FdIsInteractive(stdin, (char *)0);
@@ -465,19 +488,60 @@
 		sts = PyRun_SimpleStringFlags(command, &cf) != 0;
 		free(command);
 	} else if (module) {
-		sts = RunModule(module);
+		sts = RunModule(module, 1);
 		free(module);
 	}
 	else {
+
 		if (filename == NULL && stdin_is_interactive) {
 			Py_InspectFlag = 0; /* do exit on SystemExit */
 			RunStartupFile(&cf);
 		}
 		/* XXX */
-		sts = PyRun_AnyFileExFlags(
-			fp,
-			filename == NULL ? "<stdin>" : filename,
-			filename != NULL, &cf) != 0;
+
+		sts = -1;	/* keep track of whether we've already run __main__ */
+
+		if (filename != NULL) {
+			sts = RunMainFromImporter(filename);
+		}
+
+		if (sts==-1 && filename!=NULL) {
+			if ((fp = fopen(filename, "r")) == NULL) {
+				fprintf(stderr, "%s: can't open file '%s': [Errno %d] %s\n",
+					argv[0], filename, errno, strerror(errno));
+
+				return 2;
+			}
+			else if (skipfirstline) {
+				int ch;
+				/* Push back first newline so line numbers
+				   remain the same */
+				while ((ch = getc(fp)) != EOF) {
+					if (ch == '\n') {
+						(void)ungetc(ch, fp);
+						break;
+					}
+				}
+			}
+			{
+				/* XXX: does this work on Win/Win64? (see posix_fstat) */
+				struct stat sb;
+				if (fstat(fileno(fp), &sb) == 0 &&
+				    S_ISDIR(sb.st_mode)) {
+					fprintf(stderr, "%s: '%s' is a directory, cannot continue\n", argv[0], filename);
+					fclose(fp);
+					return 1;
+				}
+			}
+		}
+
+		if (sts==-1) {
+			sts = PyRun_AnyFileExFlags(
+				fp,
+				filename == NULL ? "<stdin>" : filename,
+				filename != NULL, &cf) != 0;
+		}
+		
 	}
 
 	/* Check this environment variable at the end, to give programs the
@@ -534,4 +598,3 @@
 #ifdef __cplusplus
 }
 #endif
-

Modified: python/branches/py3k-importlib/Modules/mathmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/mathmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/mathmodule.c	Thu Mar 27 00:48:05 2008
@@ -12,6 +12,11 @@
 #endif /* __STDC__ */
 #endif /* _MSC_VER */
 
+#ifdef _OSF_SOURCE
+/* OSF1 5.1 doesn't make this available with XOPEN_SOURCE_EXTENDED defined */
+extern double copysign(double, double);
+#endif
+
 /* Call is_error when errno != 0, and where x is the result libm
  * returned.  is_error will usually set up an exception and return
  * true (1), but may return false (0) without setting up an exception.
@@ -48,7 +53,8 @@
 }
 
 static PyObject *
-math_1(PyObject *arg, double (*func) (double))
+math_1_to_whatever(PyObject *arg, double (*func) (double),
+                   PyObject *(*from_double_func) (double))
 {
 	double x = PyFloat_AsDouble(arg);
 	if (x == -1.0 && PyErr_Occurred())
@@ -61,7 +67,19 @@
 	if (errno && is_error(x))
 		return NULL;
 	else
-		return PyFloat_FromDouble(x);
+        	return (*from_double_func)(x);
+}
+
+static PyObject *
+math_1(PyObject *arg, double (*func) (double))
+{
+	return math_1_to_whatever(arg, func, PyFloat_FromDouble);
+}
+
+static PyObject *
+math_1_to_int(PyObject *arg, double (*func) (double))
+{
+	return math_1_to_whatever(arg, func, PyLong_FromDouble);
 }
 
 static PyObject *
@@ -113,26 +131,36 @@
 	PyObject *method;
 
 	if (ceil_str == NULL) {
-		ceil_str = PyUnicode_FromString("__ceil__");
+		ceil_str = PyUnicode_InternFromString("__ceil__");
 		if (ceil_str == NULL)
 			return NULL;
 	}
 
-	method = _PyType_Lookup(Py_Type(number), ceil_str);
+	method = _PyType_Lookup(Py_TYPE(number), ceil_str);
 	if (method == NULL)
-		return math_1(number, ceil);
+		return math_1_to_int(number, ceil);
 	else
 		return PyObject_CallFunction(method, "O", number);
 }
 
 PyDoc_STRVAR(math_ceil_doc,
-	     "ceil(x)\n\nReturn the ceiling of x as a float.\n"
+	     "ceil(x)\n\nReturn the ceiling of x as an int.\n"
 	     "This is the smallest integral value >= x.");
 
 FUNC1(cos, cos,
       "cos(x)\n\nReturn the cosine of x (measured in radians).")
 FUNC1(cosh, cosh,
       "cosh(x)\n\nReturn the hyperbolic cosine of x.")
+
+#ifdef MS_WINDOWS
+#  define copysign _copysign
+#  define HAVE_COPYSIGN 1
+#endif
+#ifdef HAVE_COPYSIGN
+FUNC2(copysign, copysign,
+      "copysign(x,y)\n\nReturn x with the sign of y.");
+#endif
+
 FUNC1(exp, exp,
       "exp(x)\n\nReturn e raised to the power of x.")
 FUNC1(fabs, fabs,
@@ -143,20 +171,20 @@
 	PyObject *method;
 
 	if (floor_str == NULL) {
-		floor_str = PyUnicode_FromString("__floor__");
+		floor_str = PyUnicode_InternFromString("__floor__");
 		if (floor_str == NULL)
 			return NULL;
 	}
 
-	method = _PyType_Lookup(Py_Type(number), floor_str);
+	method = _PyType_Lookup(Py_TYPE(number), floor_str);
 	if (method == NULL)
-		return math_1(number, floor);
+        	return math_1_to_int(number, floor);
 	else
 		return PyObject_CallFunction(method, "O", number);
 }
 
 PyDoc_STRVAR(math_floor_doc,
-	     "floor(x)\n\nReturn the floor of x as a float.\n"
+	     "floor(x)\n\nReturn the floor of x as an int.\n"
 	     "This is the largest integral value <= x.");
 
 FUNC2(fmod, fmod,
@@ -178,6 +206,38 @@
       "tanh(x)\n\nReturn the hyperbolic tangent of x.")
 
 static PyObject *
+math_trunc(PyObject *self, PyObject *number)
+{
+	static PyObject *trunc_str = NULL;
+	PyObject *trunc;
+
+	if (Py_TYPE(number)->tp_dict == NULL) {
+		if (PyType_Ready(Py_TYPE(number)) < 0)
+			return NULL;
+	}
+
+	if (trunc_str == NULL) {
+		trunc_str = PyUnicode_InternFromString("__trunc__");
+		if (trunc_str == NULL)
+			return NULL;
+	}
+
+	trunc = _PyType_Lookup(Py_TYPE(number), trunc_str);
+	if (trunc == NULL) {
+		PyErr_Format(PyExc_TypeError,
+			     "type %.100s doesn't define __trunc__ method",
+			     Py_TYPE(number)->tp_name);
+		return NULL;
+	}
+	return PyObject_CallFunctionObjArgs(trunc, number, NULL);
+}
+
+PyDoc_STRVAR(math_trunc_doc,
+"trunc(x:Real) -> Integral\n"
+"\n"
+"Truncates x to the nearest Integral toward 0. Uses the __trunc__ magic method.");
+
+static PyObject *
 math_frexp(PyObject *self, PyObject *arg)
 {
 	int i;
@@ -263,9 +323,9 @@
 					"math domain error");
 			return NULL;
 		}
-		/* Value is ~= x * 2**(e*SHIFT), so the log ~=
-		   log(x) + log(2) * e * SHIFT.
-		   CAUTION:  e*SHIFT may overflow using int arithmetic,
+		/* Value is ~= x * 2**(e*PyLong_SHIFT), so the log ~=
+		   log(x) + log(2) * e * PyLong_SHIFT.
+		   CAUTION:  e*PyLong_SHIFT may overflow using int arithmetic,
 		   so force use of double. */
 		x = func(x) + (e * (double)PyLong_SHIFT) * func(2.0);
 		return PyFloat_FromDouble(x);
@@ -315,9 +375,8 @@
 PyDoc_STRVAR(math_log10_doc,
 "log10(x) -> the base 10 logarithm of x.");
 
-/* XXX(nnorwitz): Should we use the platform M_PI or something more accurate
-   like: 3.14159265358979323846264338327950288 */
-static const double degToRad = 3.141592653589793238462643383 / 180.0;
+static const double degToRad = Py_MATH_PI / 180.0;
+static const double radToDeg = 180.0 / Py_MATH_PI;
 
 static PyObject *
 math_degrees(PyObject *self, PyObject *arg)
@@ -325,7 +384,7 @@
 	double x = PyFloat_AsDouble(arg);
 	if (x == -1.0 && PyErr_Occurred())
 		return NULL;
-	return PyFloat_FromDouble(x / degToRad);
+	return PyFloat_FromDouble(x * radToDeg);
 }
 
 PyDoc_STRVAR(math_degrees_doc,
@@ -343,12 +402,42 @@
 PyDoc_STRVAR(math_radians_doc,
 "radians(x) -> converts angle x from degrees to radians");
 
+static PyObject *
+math_isnan(PyObject *self, PyObject *arg)
+{
+	double x = PyFloat_AsDouble(arg);
+	if (x == -1.0 && PyErr_Occurred())
+		return NULL;
+	return PyBool_FromLong((long)Py_IS_NAN(x));
+}
+
+PyDoc_STRVAR(math_isnan_doc,
+"isnan(x) -> bool\n\
+Checks if float x is not a number (NaN)");
+
+static PyObject *
+math_isinf(PyObject *self, PyObject *arg)
+{
+	double x = PyFloat_AsDouble(arg);
+	if (x == -1.0 && PyErr_Occurred())
+		return NULL;
+	return PyBool_FromLong((long)Py_IS_INFINITY(x));
+}
+
+PyDoc_STRVAR(math_isinf_doc,
+"isinf(x) -> bool\n\
+Checks if float x is infinite (positive or negative)");
+
+
 static PyMethodDef math_methods[] = {
 	{"acos",	math_acos,	METH_O,		math_acos_doc},
 	{"asin",	math_asin,	METH_O,		math_asin_doc},
 	{"atan",	math_atan,	METH_O,		math_atan_doc},
 	{"atan2",	math_atan2,	METH_VARARGS,	math_atan2_doc},
 	{"ceil",	math_ceil,	METH_O,		math_ceil_doc},
+#ifdef HAVE_COPYSIGN
+	{"copysign",	math_copysign,	METH_VARARGS,	math_copysign_doc},
+#endif
 	{"cos",		math_cos,	METH_O,		math_cos_doc},
 	{"cosh",	math_cosh,	METH_O,		math_cosh_doc},
 	{"degrees",	math_degrees,	METH_O,		math_degrees_doc},
@@ -358,6 +447,8 @@
 	{"fmod",	math_fmod,	METH_VARARGS,	math_fmod_doc},
 	{"frexp",	math_frexp,	METH_O,		math_frexp_doc},
 	{"hypot",	math_hypot,	METH_VARARGS,	math_hypot_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},
 	{"log",		math_log,	METH_VARARGS,	math_log_doc},
 	{"log10",	math_log10,	METH_O,		math_log10_doc},
@@ -369,6 +460,7 @@
 	{"sqrt",	math_sqrt,	METH_O,		math_sqrt_doc},
 	{"tan",		math_tan,	METH_O,		math_tan_doc},
 	{"tanh",	math_tanh,	METH_O,		math_tanh_doc},
+ 	{"trunc",	math_trunc,	METH_O,		math_trunc_doc},
 	{NULL,		NULL}		/* sentinel */
 };
 
@@ -389,13 +481,13 @@
 	if (d == NULL)
 		goto finally;
 
-        if (!(v = PyFloat_FromDouble(atan(1.0) * 4.0)))
+        if (!(v = PyFloat_FromDouble(Py_MATH_PI)))
                 goto finally;
 	if (PyDict_SetItemString(d, "pi", v) < 0)
                 goto finally;
 	Py_DECREF(v);
 
-        if (!(v = PyFloat_FromDouble(exp(1.0))))
+        if (!(v = PyFloat_FromDouble(Py_MATH_E)))
                 goto finally;
 	if (PyDict_SetItemString(d, "e", v) < 0)
                 goto finally;

Modified: python/branches/py3k-importlib/Modules/md5module.c
==============================================================================
--- python/branches/py3k-importlib/Modules/md5module.c	(original)
+++ python/branches/py3k-importlib/Modules/md5module.c	Thu Mar 27 00:48:05 2008
@@ -340,7 +340,7 @@
 {
     MD5object *newobj;
 
-    if (Py_Type(self) == &MD5type) {
+    if (Py_TYPE(self) == &MD5type) {
         if ( (newobj = newMD5object())==NULL)
             return NULL;
     } else {
@@ -363,7 +363,7 @@
 
     temp = self->hash_state;
     md5_done(&temp, digest);
-    return PyBytes_FromStringAndSize((const char *)digest, MD5_DIGESTSIZE);
+    return PyString_FromStringAndSize((const char *)digest, MD5_DIGESTSIZE);
 }
 
 PyDoc_STRVAR(MD5_hexdigest__doc__,
@@ -434,7 +434,7 @@
 static PyObject *
 MD5_get_block_size(PyObject *self, void *closure)
 {
-    return PyInt_FromLong(MD5_BLOCKSIZE);
+    return PyLong_FromLong(MD5_BLOCKSIZE);
 }
 
 static PyObject *
@@ -446,7 +446,7 @@
 static PyObject *
 md5_get_digest_size(PyObject *self, void *closure)
 {
-    return PyInt_FromLong(MD5_DIGESTSIZE);
+    return PyLong_FromLong(MD5_DIGESTSIZE);
 }
 
 
@@ -552,7 +552,7 @@
 {
     PyObject *m;
 
-    Py_Type(&MD5type) = &PyType_Type;
+    Py_TYPE(&MD5type) = &PyType_Type;
     if (PyType_Ready(&MD5type) < 0)
         return;
     m = Py_InitModule("_md5", MD5_functions);

Modified: python/branches/py3k-importlib/Modules/mmapmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/mmapmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/mmapmodule.c	Thu Mar 27 00:48:05 2008
@@ -3,6 +3,9 @@
  /  Hacked for Unix by AMK
  /  $Id$
 
+ / Modified to support mmap with offset - to map a 'window' of a file
+ /   Author:  Yotam Medini  yotamm at mellanox.co.il
+ /
  / mmapmodule.cpp -- map a view of a file into memory
  /
  / todo: need permission flags, perhaps a 'chsize' analog
@@ -31,6 +34,16 @@
 	GetSystemInfo(&si);
 	return si.dwPageSize;
 }
+
+static int
+my_getallocationgranularity (void)
+{
+
+	SYSTEM_INFO si;
+	GetSystemInfo(&si);
+	return si.dwAllocationGranularity;
+}
+
 #endif
 
 #ifdef UNIX
@@ -43,6 +56,8 @@
 {
 	return sysconf(_SC_PAGESIZE);
 }
+
+#define my_getallocationgranularity my_getpagesize
 #else
 #define my_getpagesize getpagesize
 #endif
@@ -74,7 +89,8 @@
 	PyObject_HEAD
 	char *	data;
 	size_t	size;
-	size_t	pos;
+	size_t	pos;    /* relative to offset */
+	size_t	offset; 
         int     exports;
 
 #ifdef MS_WINDOWS
@@ -114,7 +130,7 @@
 	}
 #endif /* UNIX */
 
-	PyObject_Del(m_obj);
+	Py_TYPE(m_obj)->tp_free((PyObject*)m_obj);
 }
 
 static PyObject *
@@ -238,19 +254,22 @@
 }
 
 static PyObject *
-mmap_find_method(mmap_object *self,
-		 PyObject *args)
+mmap_gfind(mmap_object *self,
+	   PyObject *args,
+	   int reverse)
 {
 	Py_ssize_t start = self->pos;
-	char *needle;
+	Py_ssize_t end = self->size;
+	const char *needle;
 	Py_ssize_t len;
 
 	CHECK_VALID(NULL);
-	if (!PyArg_ParseTuple(args, "s#|n:find", &needle, &len, &start)) {
+	if (!PyArg_ParseTuple(args, reverse ? "s#|nn:rfind" : "s#|nn:find",
+			      &needle, &len, &start, &end)) {
 		return NULL;
 	} else {
-		char *p;
-		char *e = self->data + self->size;
+		const char *p, *start_p, *end_p;
+		int sign = reverse ? -1 : 1;
 
                 if (start < 0)
 			start += self->size;
@@ -259,18 +278,43 @@
                 else if ((size_t)start > self->size)
 			start = self->size;
 
-		for (p = self->data + start; p + len <= e; ++p) {
+                if (end < 0)
+			end += self->size;
+		if (end < 0)
+			end = 0;
+		else if ((size_t)end > self->size)
+			end = self->size;
+
+		start_p = self->data + start;
+		end_p = self->data + end;
+
+		for (p = (reverse ? end_p - len : start_p);
+		     (p >= start_p) && (p + len <= end_p); p += sign) {
 			Py_ssize_t i;
 			for (i = 0; i < len && needle[i] == p[i]; ++i)
 				/* nothing */;
 			if (i == len) {
-				return PyInt_FromSsize_t(p - self->data);
+				return PyLong_FromSsize_t(p - self->data);
 			}
 		}
-		return PyInt_FromLong(-1);
+		return PyLong_FromLong(-1);
 	}
 }
 
+static PyObject *
+mmap_find_method(mmap_object *self,
+		 PyObject *args)
+{
+	return mmap_gfind(self, args, 0);
+}
+
+static PyObject *
+mmap_rfind_method(mmap_object *self,
+		 PyObject *args)
+{
+	return mmap_gfind(self, args, 1);
+}
+
 static int
 is_writable(mmap_object *self)
 {
@@ -289,7 +333,7 @@
                 return 0;
         }
 	if ((self->access == ACCESS_WRITE) || (self->access == ACCESS_DEFAULT))
-		return 1;        
+		return 1;
 	PyErr_Format(PyExc_TypeError,
 		     "mmap can't resize a readonly or copy-on-write memory map.");
 	return 0;
@@ -357,11 +401,11 @@
 				return PyErr_SetFromWindowsErr(error);
 		}
 		if (!high && low < LONG_MAX)
-			return PyInt_FromLong((long)low);
+			return PyLong_FromLong((long)low);
 		size = (((PY_LONG_LONG)high)<<32) + low;
 		return PyLong_FromLongLong(size);
 	} else {
-		return PyInt_FromSsize_t(self->size);
+		return PyLong_FromSsize_t(self->size);
 	}
 #endif /* MS_WINDOWS */
 
@@ -372,7 +416,7 @@
 			PyErr_SetFromErrno(mmap_module_error);
 			return NULL;
 		}
-		return PyInt_FromSsize_t(buf.st_size);
+		return PyLong_FromSsize_t(buf.st_size);
 	}
 #endif /* UNIX */
 }
@@ -398,18 +442,22 @@
 #ifdef MS_WINDOWS
 	} else {
 		DWORD dwErrCode = 0;
-		DWORD newSizeLow, newSizeHigh;
+		DWORD off_hi, off_lo, newSizeLow, newSizeHigh;
 		/* First, unmap the file view */
 		UnmapViewOfFile(self->data);
 		/* Close the mapping object */
 		CloseHandle(self->map_handle);
 		/* Move to the desired EOF position */
 #if SIZEOF_SIZE_T > 4
-		newSizeHigh = (DWORD)(new_size >> 32);
-		newSizeLow = (DWORD)(new_size & 0xFFFFFFFF);
+		newSizeHigh = (DWORD)((self->offset + new_size) >> 32);
+		newSizeLow = (DWORD)((self->offset + new_size) & 0xFFFFFFFF);
+		off_hi = (DWORD)(self->offset >> 32);
+		off_lo = (DWORD)(self->offset & 0xFFFFFFFF);
 #else
 		newSizeHigh = 0;
 		newSizeLow = (DWORD)new_size;
+		off_hi = 0;
+		off_lo = (DWORD)self->offset;
 #endif
 		SetFilePointer(self->file_handle,
 			       newSizeLow, &newSizeHigh, FILE_BEGIN);
@@ -420,15 +468,15 @@
 			self->file_handle,
 			NULL,
 			PAGE_READWRITE,
-			newSizeHigh,
-			newSizeLow,
+			0,
+			0,
 			self->tagname);
 		if (self->map_handle != NULL) {
 			self->data = (char *) MapViewOfFile(self->map_handle,
 							    FILE_MAP_WRITE,
-							    0,
-							    0,
-							    0);
+							    off_hi,
+							    off_lo,
+							    new_size);
 			if (self->data != NULL) {
 				self->size = new_size;
 				Py_INCREF(Py_None);
@@ -481,7 +529,7 @@
 mmap_tell_method(mmap_object *self, PyObject *unused)
 {
 	CHECK_VALID(NULL);
-	return PyInt_FromSize_t(self->pos);
+	return PyLong_FromSize_t(self->pos);
 }
 
 static PyObject *
@@ -495,23 +543,21 @@
 	if ((size_t)(offset + size) > self->size) {
 		PyErr_SetString(PyExc_ValueError, "flush values out of range");
 		return NULL;
-	} else {
+	}
 #ifdef MS_WINDOWS
-		return PyInt_FromLong((long)
-                                      FlushViewOfFile(self->data+offset, size));
-#endif /* MS_WINDOWS */
-#ifdef UNIX
-		/* XXX semantics of return value? */
-		/* XXX flags for msync? */
-		if (-1 == msync(self->data + offset, size,
-				MS_SYNC))
-		{
-			PyErr_SetFromErrno(mmap_module_error);
-			return NULL;
-		}
-		return PyInt_FromLong(0);
-#endif /* UNIX */
+	return PyLong_FromLong((long) FlushViewOfFile(self->data+offset, size));
+#elif defined(UNIX)
+	/* XXX semantics of return value? */
+	/* XXX flags for msync? */
+	if (-1 == msync(self->data + offset, size, MS_SYNC)) {
+		PyErr_SetFromErrno(mmap_module_error);
+		return NULL;
 	}
+	return PyLong_FromLong(0);
+#else
+	PyErr_SetString(PyExc_ValueError, "flush not supported on this system");
+	return NULL;
+#endif
 }
 
 static PyObject *
@@ -584,6 +630,7 @@
 static struct PyMethodDef mmap_object_methods[] = {
 	{"close",	(PyCFunction) mmap_close_method,	METH_NOARGS},
 	{"find",	(PyCFunction) mmap_find_method,		METH_VARARGS},
+	{"rfind",	(PyCFunction) mmap_rfind_method,	METH_VARARGS},
 	{"flush",	(PyCFunction) mmap_flush_method,	METH_VARARGS},
 	{"move",	(PyCFunction) mmap_move_method,		METH_VARARGS},
 	{"read",	(PyCFunction) mmap_read_method,		METH_VARARGS},
@@ -601,10 +648,10 @@
 /* Functions for treating an mmap'ed file as a buffer */
 
 static int
-mmap_buffer_getbuf(mmap_object *self, Py_buffer *view, int flags) 
+mmap_buffer_getbuf(mmap_object *self, Py_buffer *view, int flags)
 {
 	CHECK_VALID(-1);
-        if (PyBuffer_FillInfo(view, self->data, self->size, 
+        if (PyBuffer_FillInfo(view, self->data, self->size,
                               (self->access == ACCESS_READ), flags) < 0)
                 return -1;
         self->exports++;
@@ -617,12 +664,6 @@
         self->exports--;
 }
 
-static PyObject *
-mmap_object_getattr(mmap_object *self, char *name)
-{
-	return Py_FindMethod(mmap_object_methods, (PyObject *)self, name);
-}
-
 static Py_ssize_t
 mmap_length(mmap_object *self)
 {
@@ -651,12 +692,12 @@
 			return NULL;
 		if (i < 0)
 			i += self->size;
-		if (i < 0 || i > self->size) {
+		if (i < 0 || (size_t)i > self->size) {
 			PyErr_SetString(PyExc_IndexError,
 				"mmap index out of range");
 			return NULL;
 		}
-		return PyBytes_FromStringAndSize(self->data + i, 1);
+		return PyLong_FromLong(Py_CHARMASK(self->data[i]));
 	}
 	else if (PySlice_Check(item)) {
 		Py_ssize_t start, stop, step, slicelen;
@@ -665,12 +706,12 @@
 				 &start, &stop, &step, &slicelen) < 0) {
 			return NULL;
 		}
-		
+
 		if (slicelen <= 0)
-			return PyBytes_FromStringAndSize("", 0);
+			return PyString_FromStringAndSize("", 0);
 		else if (step == 1)
-			return PyBytes_FromStringAndSize(self->data + start,
-							 slicelen);
+			return PyString_FromStringAndSize(self->data + start,
+							  slicelen);
 		else {
 			char *result_buf = (char *)PyMem_Malloc(slicelen);
 			Py_ssize_t cur, i;
@@ -682,8 +723,8 @@
 			     cur += step, i++) {
 			     	result_buf[i] = self->data[cur];
 			}
-			result = PyBytes_FromStringAndSize(result_buf,
-							   slicelen);
+			result = PyString_FromStringAndSize(result_buf,
+							    slicelen);
 			PyMem_Free(result_buf);
 			return result;
 		}
@@ -745,38 +786,48 @@
 {
 	CHECK_VALID(-1);
 
+	if (!is_writable(self))
+		return -1;
+
 	if (PyIndex_Check(item)) {
 		Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
-		const char *buf;
+		Py_ssize_t v;
 
 		if (i == -1 && PyErr_Occurred())
 			return -1;
 		if (i < 0)
 			i += self->size;
-		if (i < 0 || i > self->size) {
+		if (i < 0 || (size_t)i > self->size) {
 			PyErr_SetString(PyExc_IndexError,
-				"mmap index out of range");
+					"mmap index out of range");
 			return -1;
 		}
 		if (value == NULL) {
 			PyErr_SetString(PyExc_TypeError,
-				"mmap object doesn't support item deletion");
+					"mmap doesn't support item deletion");
 			return -1;
 		}
-		if (!PyBytes_Check(value) || PyBytes_Size(value) != 1) {
-			PyErr_SetString(PyExc_IndexError,
-		          "mmap assignment must be length-1 bytes()");
+		if (!PyIndex_Check(value)) {
+			PyErr_SetString(PyExc_TypeError,
+					"mmap item value must be an int");
 			return -1;
 		}
-		if (!is_writable(self))
+		v = PyNumber_AsSsize_t(value, PyExc_TypeError);
+		if (v == -1 && PyErr_Occurred())
 			return -1;
-		buf = PyBytes_AsString(value);
-		self->data[i] = buf[0];
+		if (v < 0 || v > 255) {
+			PyErr_SetString(PyExc_ValueError,
+					"mmap item value must be "
+					"in range(0, 256)");
+			return -1;
+		}
+		self->data[i] = v;
 		return 0;
 	}
 	else if (PySlice_Check(item)) {
 		Py_ssize_t start, stop, step, slicelen;
-		
+                Py_buffer vbuf;
+
 		if (PySlice_GetIndicesEx((PySliceObject *)item,
 					 self->size, &start, &stop,
 					 &step, &slicelen) < 0) {
@@ -787,41 +838,32 @@
 				"mmap object doesn't support slice deletion");
 			return -1;
 		}
-		if (!PyBytes_Check(value)) {
-			PyErr_SetString(PyExc_IndexError,
-				"mmap slice assignment must be bytes");
+                if (PyObject_GetBuffer(value, &vbuf, PyBUF_SIMPLE) < 0)
 			return -1;
-		}
-		if (PyBytes_Size(value) != slicelen) {
+		if (vbuf.len != slicelen) {
 			PyErr_SetString(PyExc_IndexError,
 				"mmap slice assignment is wrong size");
+			PyObject_ReleaseBuffer(value, &vbuf);
 			return -1;
 		}
-		if (!is_writable(self))
-			return -1;
 
-		if (slicelen == 0)
-			return 0;
+		if (slicelen == 0) {
+		}
 		else if (step == 1) {
-			const char *buf = PyBytes_AsString(value);
-
-			if (buf == NULL)
-				return -1;
-			memcpy(self->data + start, buf, slicelen);
-			return 0;
+			memcpy(self->data + start, vbuf.buf, slicelen);
 		}
 		else {
 			Py_ssize_t cur, i;
-			const char *buf = PyBytes_AsString(value);
-			
-			if (buf == NULL)
-				return -1;
-			for (cur = start, i = 0; i < slicelen;
-			     cur += step, i++) {
-				self->data[cur] = buf[i];
+
+			for (cur = start, i = 0;
+			     i < slicelen;
+			     cur += step, i++)
+			{
+				self->data[cur] = ((char *)vbuf.buf)[i];
 			}
-			return 0;
 		}
+		PyObject_ReleaseBuffer(value, &vbuf);
+		return 0;
 	}
 	else {
 		PyErr_SetString(PyExc_TypeError,
@@ -851,15 +893,42 @@
         (releasebufferproc)mmap_buffer_releasebuf,
 };
 
+static PyObject *
+new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict);
+
+PyDoc_STRVAR(mmap_doc,
+"Windows: mmap(fileno, length[, tagname[, access[, offset]]])\n\
+\n\
+Maps length bytes from the file specified by the file handle fileno,\n\
+and returns a mmap object.  If length is larger than the current size\n\
+of the file, the file is extended to contain length bytes.  If length\n\
+is 0, the maximum length of the map is the current size of the file,\n\
+except that if the file is empty Windows raises an exception (you cannot\n\
+create an empty mapping on Windows).\n\
+\n\
+Unix: mmap(fileno, length[, flags[, prot[, access[, offset]]]])\n\
+\n\
+Maps length bytes from the file specified by the file descriptor fileno,\n\
+and returns a mmap object.  If length is 0, the maximum length of the map\n\
+will be the current size of the file when mmap is called.\n\
+flags specifies the nature of the mapping. MAP_PRIVATE creates a\n\
+private copy-on-write mapping, so changes to the contents of the mmap\n\
+object will be private to this process, and MAP_SHARED`creates a mapping\n\
+that's shared with all other processes mapping the same areas of the file.\n\
+The default value is MAP_SHARED.\n\
+\n\
+To map anonymous memory, pass -1 as the fileno (both versions).");
+
+
 static PyTypeObject mmap_object_type = {
-	PyVarObject_HEAD_INIT(0, 0) /* patched in module init */
+	PyVarObject_HEAD_INIT(NULL, 0)
 	"mmap.mmap",				/* tp_name */
 	sizeof(mmap_object),			/* tp_size */
 	0,					/* tp_itemsize */
 	/* methods */
 	(destructor) mmap_object_dealloc,	/* tp_dealloc */
 	0,					/* tp_print */
-	(getattrfunc) mmap_object_getattr,	/* tp_getattr */
+	0,					/* tp_getattr */
 	0,					/* tp_setattr */
 	0,					/* tp_compare */
 	0,					/* tp_repr */
@@ -869,11 +938,29 @@
 	0,					/*tp_hash*/
 	0,					/*tp_call*/
 	0,					/*tp_str*/
-	0,					/*tp_getattro*/
+	PyObject_GenericGetAttr,		/*tp_getattro*/
 	0,					/*tp_setattro*/
 	&mmap_as_buffer,			/*tp_as_buffer*/
-	Py_TPFLAGS_DEFAULT,			/*tp_flags*/
-	0,					/*tp_doc*/
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,		/*tp_flags*/
+	mmap_doc,				/*tp_doc*/
+	0,					/* tp_traverse */
+	0,					/* tp_clear */
+	0,					/* tp_richcompare */
+	0,					/* tp_weaklistoffset */
+	0,		                        /* tp_iter */
+	0,		                        /* tp_iternext */
+	mmap_object_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 */
+	PyType_GenericAlloc,			/* tp_alloc */
+	new_mmap_object,			/* tp_new */
+	PyObject_Del,                           /* tp_free */
 };
 
 
@@ -882,15 +969,18 @@
    Returns -1 on error, with an appropriate Python exception raised. On
    success, the map size is returned. */
 static Py_ssize_t
-_GetMapSize(PyObject *o)
+_GetMapSize(PyObject *o, const char* param)
 {
+	if (o == NULL)
+		return 0;
 	if (PyIndex_Check(o)) {
 		Py_ssize_t i = PyNumber_AsSsize_t(o, PyExc_OverflowError);
-		if (i==-1 && PyErr_Occurred()) 
+		if (i==-1 && PyErr_Occurred())
 			return -1;
-		if (i < 0) {	 
-			PyErr_SetString(PyExc_OverflowError,
-					"memory mapped size must be positive");
+		if (i < 0) {
+			PyErr_Format(PyExc_OverflowError,
+					"memory mapped %s must be positive",
+                                        param);
 			return -1;
 		}
 		return i;
@@ -902,28 +992,31 @@
 
 #ifdef UNIX
 static PyObject *
-new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
+new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
 {
 #ifdef HAVE_FSTAT
 	struct stat st;
 #endif
 	mmap_object *m_obj;
-	PyObject *map_size_obj = NULL;
-	Py_ssize_t map_size;
+	PyObject *map_size_obj = NULL, *offset_obj = NULL;
+	Py_ssize_t map_size, offset;
 	int fd, flags = MAP_SHARED, prot = PROT_WRITE | PROT_READ;
 	int devzero = -1;
 	int access = (int)ACCESS_DEFAULT;
 	static char *keywords[] = {"fileno", "length",
                                          "flags", "prot",
-                                         "access", NULL};
+                                         "access", "offset", NULL};
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iO|iii", keywords,
+	if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iO|iiiO", keywords,
 					 &fd, &map_size_obj, &flags, &prot,
-                                         &access))
+                                         &access, &offset_obj))
 		return NULL;
-	map_size = _GetMapSize(map_size_obj);
+	map_size = _GetMapSize(map_size_obj, "size");
 	if (map_size < 0)
 		return NULL;
+        offset = _GetMapSize(offset_obj, "offset");
+        if (offset < 0)
+                return NULL;
 
 	if ((access != (int)ACCESS_DEFAULT) &&
 	    ((flags != MAP_SHARED) || (prot != (PROT_WRITE | PROT_READ))))
@@ -950,27 +1043,34 @@
 				    "mmap invalid access parameter.");
 	}
 
+    if (prot == PROT_READ) {
+        access = ACCESS_READ;
+    }
+
 #ifdef HAVE_FSTAT
 #  ifdef __VMS
 	/* on OpenVMS we must ensure that all bytes are written to the file */
-	fsync(fd);
+	if (fd != -1) {
+	        fsync(fd);
+	}
 #  endif
-	if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
+	if (fd != -1 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
 		if (map_size == 0) {
 			map_size = st.st_size;
-		} else if ((size_t)map_size > st.st_size) {
+		} else if ((size_t)offset + (size_t)map_size > st.st_size) {
 			PyErr_SetString(PyExc_ValueError,
 					"mmap length is greater than file size");
 			return NULL;
 		}
 	}
 #endif
-	m_obj = PyObject_New(mmap_object, &mmap_object_type);
+	m_obj = (mmap_object *)type->tp_alloc(type, 0);
 	if (m_obj == NULL) {return NULL;}
 	m_obj->data = NULL;
 	m_obj->size = (size_t) map_size;
 	m_obj->pos = (size_t) 0;
 	m_obj->exports = 0;
+        m_obj->offset = offset;
 	if (fd == -1) {
 		m_obj->fd = -1;
 		/* Assume the caller wants to map anonymous memory.
@@ -997,10 +1097,10 @@
 			return NULL;
 		}
 	}
-
+	
 	m_obj->data = mmap(NULL, map_size,
 			   prot, flags,
-			   fd, 0);
+			   fd, offset);
 
 	if (devzero != -1) {
 		close(devzero);
@@ -1019,13 +1119,15 @@
 
 #ifdef MS_WINDOWS
 static PyObject *
-new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
+new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
 {
 	mmap_object *m_obj;
-	PyObject *map_size_obj = NULL;
-	Py_ssize_t map_size;
-	DWORD size_hi;	/* upper 32 bits of m_obj->size */
-	DWORD size_lo;	/* lower 32 bits of m_obj->size */
+	PyObject *map_size_obj = NULL, *offset_obj = NULL;
+	Py_ssize_t map_size, offset;
+	DWORD off_hi;	/* upper 32 bits of offset */
+	DWORD off_lo;	/* lower 32 bits of offset */
+	DWORD size_hi;	/* upper 32 bits of size */
+	DWORD size_lo;	/* lower 32 bits of size */
 	char *tagname = "";
 	DWORD dwErr = 0;
 	int fileno;
@@ -1034,11 +1136,11 @@
 	DWORD flProtect, dwDesiredAccess;
 	static char *keywords[] = { "fileno", "length",
                                           "tagname",
-                                          "access", NULL };
+                                          "access", "offset", NULL };
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iO|zi", keywords,
+	if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iO|ziO", keywords,
 					 &fileno, &map_size_obj,
-					 &tagname, &access)) {
+					 &tagname, &access, &offset_obj)) {
 		return NULL;
 	}
 
@@ -1060,9 +1162,12 @@
 				    "mmap invalid access parameter.");
 	}
 
-	map_size = _GetMapSize(map_size_obj);
+	map_size = _GetMapSize(map_size_obj, "size");
 	if (map_size < 0)
 		return NULL;
+        offset = _GetMapSize(offset_obj, "offset");
+        if (offset < 0)
+                return NULL;
 
 	/* assume -1 and 0 both mean invalid filedescriptor
 	   to 'anonymously' map memory.
@@ -1083,7 +1188,7 @@
 		lseek(fileno, 0, SEEK_SET);
 	}
 
-	m_obj = PyObject_New(mmap_object, &mmap_object_type);
+	m_obj = (mmap_object *)type->tp_alloc(type, 0);
 	if (m_obj == NULL)
 		return NULL;
 	/* Set every field to an invalid marker, so we can safely
@@ -1092,6 +1197,7 @@
 	m_obj->file_handle = INVALID_HANDLE_VALUE;
 	m_obj->map_handle = INVALID_HANDLE_VALUE;
 	m_obj->tagname = NULL;
+	m_obj->offset = offset;
 
 	if (fh) {
 		/* It is necessary to duplicate the handle, so the
@@ -1118,8 +1224,8 @@
 			    (dwErr = GetLastError()) != NO_ERROR) {
 				Py_DECREF(m_obj);
 				return PyErr_SetFromWindowsErr(dwErr);
-			}	
-				    
+			}
+
 #if SIZEOF_SIZE_T > 4
 			m_obj->size = (((size_t)high)<<32) + low;
 #else
@@ -1161,12 +1267,18 @@
 	 * right by 32, so we need different code.
 	 */
 #if SIZEOF_SIZE_T > 4
-	size_hi = (DWORD)(m_obj->size >> 32);
-	size_lo = (DWORD)(m_obj->size & 0xFFFFFFFF);
+	size_hi = (DWORD)((offset + m_obj->size) >> 32);
+	size_lo = (DWORD)((offset + m_obj->size) & 0xFFFFFFFF);
+	off_hi = (DWORD)(offset >> 32);
+	off_lo = (DWORD)(offset & 0xFFFFFFFF);
 #else
 	size_hi = 0;
-	size_lo = (DWORD)m_obj->size;
+	size_lo = (DWORD)(offset + m_obj->size);
+	off_hi = 0;
+	off_lo = (DWORD)offset;
 #endif
+	/* For files, it would be sufficient to pass 0 as size.
+	   For anonymous maps, we have to pass the size explicitly. */
 	m_obj->map_handle = CreateFileMapping(m_obj->file_handle,
 					      NULL,
 					      flProtect,
@@ -1176,8 +1288,8 @@
 	if (m_obj->map_handle != NULL) {
 		m_obj->data = (char *) MapViewOfFile(m_obj->map_handle,
 						     dwDesiredAccess,
-						     0,
-						     0,
+						     off_hi,
+						     off_lo,
 						     0);
 		if (m_obj->data != NULL)
 			return (PyObject *)m_obj;
@@ -1191,38 +1303,35 @@
 }
 #endif /* MS_WINDOWS */
 
-/* List of functions exported by this module */
-static struct PyMethodDef mmap_functions[] = {
-	{"mmap",	(PyCFunction) new_mmap_object,
-	 METH_VARARGS|METH_KEYWORDS},
-	{NULL,		NULL}	     /* Sentinel */
-};
-
 static void
 setint(PyObject *d, const char *name, long value)
 {
-	PyObject *o = PyInt_FromLong(value);
+	PyObject *o = PyLong_FromLong(value);
 	if (o && PyDict_SetItemString(d, name, o) == 0) {
 		Py_DECREF(o);
 	}
 }
 
 PyMODINIT_FUNC
-	initmmap(void)
+initmmap(void)
 {
 	PyObject *dict, *module;
 
-	/* Patch the object type */
-	Py_Type(&mmap_object_type) = &PyType_Type;
+	if (PyType_Ready(&mmap_object_type) < 0)
+		return;
 
-	module = Py_InitModule("mmap", mmap_functions);
+	module = Py_InitModule("mmap", NULL);
 	if (module == NULL)
 		return;
 	dict = PyModule_GetDict(module);
 	if (!dict)
 		return;
-	mmap_module_error = PyExc_EnvironmentError;
+	mmap_module_error = PyErr_NewException("mmap.error",
+		PyExc_EnvironmentError , NULL);
+	if (mmap_module_error == NULL)
+		return;
 	PyDict_SetItemString(dict, "error", mmap_module_error);
+	PyDict_SetItemString(dict, "mmap", (PyObject*) &mmap_object_type);
 #ifdef PROT_EXEC
 	setint(dict, "PROT_EXEC", PROT_EXEC);
 #endif
@@ -1252,6 +1361,8 @@
 
 	setint(dict, "PAGESIZE", (long)my_getpagesize());
 
+	setint(dict, "ALLOCATIONGRANULARITY", (long)my_getallocationgranularity()); 
+
 	setint(dict, "ACCESS_READ", ACCESS_READ);
 	setint(dict, "ACCESS_WRITE", ACCESS_WRITE);
 	setint(dict, "ACCESS_COPY", ACCESS_COPY);

Modified: python/branches/py3k-importlib/Modules/operator.c
==============================================================================
--- python/branches/py3k-importlib/Modules/operator.c	(original)
+++ python/branches/py3k-importlib/Modules/operator.c	Thu Mar 27 00:48:05 2008
@@ -46,13 +46,13 @@
   PyObject *a1, *a2; long r; \
   if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \
   if(-1 == (r=AOP(a1,a2))) return NULL; \
-  return PyInt_FromLong(r); }
+  return PyLong_FromLong(r); }
 
 #define spamn2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
   PyObject *a1, *a2; Py_ssize_t r; \
   if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \
   if(-1 == (r=AOP(a1,a2))) return NULL; \
-  return PyInt_FromSsize_t(r); }
+  return PyLong_FromSsize_t(r); }
 
 #define spami2b(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
   PyObject *a1, *a2; long r; \
@@ -160,47 +160,6 @@
 	return result;
 }
 
-static PyObject*
-op_getslice(PyObject *s, PyObject *a)
-{
-        PyObject *a1;
-        Py_ssize_t a2, a3;
-
-        if (!PyArg_ParseTuple(a, "Onn:getslice", &a1, &a2, &a3))
-                return NULL;
-        return PySequence_GetSlice(a1, a2, a3);
-}
-
-static PyObject*
-op_setslice(PyObject *s, PyObject *a)
-{
-        PyObject *a1, *a4;
-        Py_ssize_t a2, a3;
-
-        if (!PyArg_ParseTuple(a, "OnnO:setslice", &a1, &a2, &a3, &a4))
-                return NULL;
-
-        if (-1 == PySequence_SetSlice(a1, a2, a3, a4))
-                return NULL;
-
-	Py_RETURN_NONE;
-}
-
-static PyObject*
-op_delslice(PyObject *s, PyObject *a)
-{
-        PyObject *a1;
-        Py_ssize_t a2, a3;
-
-        if (!PyArg_ParseTuple(a, "Onn:delslice", &a1, &a2, &a3))
-                return NULL;
-
-        if (-1 == PySequence_DelSlice(a1, a2, a3))
-                return NULL;
-
-	Py_RETURN_NONE;
-}
-
 #undef spam1
 #undef spam2
 #undef spam1o
@@ -276,12 +235,6 @@
  "delitem(a, b) -- Same as del a[b].")
 spam2(pow,__pow__, "pow(a, b) -- Same as a ** b.")
 spam2(ipow,__ipow__, "ipow(a, b) -- Same as a **= b.")
-spam2(getslice,__getslice__,
- "getslice(a, b, c) -- Same as a[b:c].")
-spam2(setslice,__setslice__,
-"setslice(a, b, c, d) -- Same as a[b:c] = d.")
-spam2(delslice,__delslice__,
-"delslice(a, b, c) -- Same as del a[b:c].")
 spam2(lt,__lt__, "lt(a, b) -- Same as a<b.")
 spam2(le,__le__, "le(a, b) -- Same as a<=b.")
 spam2(eq,__eq__, "eq(a, b) -- Same as a==b.")
@@ -486,6 +439,41 @@
 }
 
 static PyObject *
+dotted_getattr(PyObject *obj, PyObject *attr)
+{
+	char *s, *p;
+
+	if (!PyUnicode_Check(attr)) {
+		PyErr_SetString(PyExc_TypeError,
+				"attribute name must be a string");
+		return NULL;
+	}
+
+	s = PyUnicode_AsString(attr);
+	Py_INCREF(obj);
+	for (;;) {
+		PyObject *newobj, *str;
+		p = strchr(s, '.');
+		str = p ? PyUnicode_FromStringAndSize(s, (p-s)) : 
+			  PyUnicode_FromString(s);
+		if (str == NULL) {
+			Py_DECREF(obj);
+			return NULL;
+		}
+		newobj = PyObject_GetAttr(obj, str);
+		Py_DECREF(str);
+		Py_DECREF(obj);
+		if (newobj == NULL)
+			return NULL;
+		obj = newobj;
+		if (p == NULL) break;
+		s = p+1;
+	}
+
+	return obj;
+}
+
+static PyObject *
 attrgetter_call(attrgetterobject *ag, PyObject *args, PyObject *kw)
 {
 	PyObject *obj, *result;
@@ -494,7 +482,7 @@
 	if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj))
 		return NULL;
 	if (ag->nattrs == 1)
-		return PyObject_GetAttr(obj, ag->attr);
+		return dotted_getattr(obj, ag->attr);
 
 	assert(PyTuple_Check(ag->attr));
 	assert(PyTuple_GET_SIZE(ag->attr) == nattrs);
@@ -506,7 +494,7 @@
 	for (i=0 ; i < nattrs ; i++) {
 		PyObject *attr, *val;
 		attr = PyTuple_GET_ITEM(ag->attr, i);
-		val = PyObject_GetAttr(obj, attr);
+		val = dotted_getattr(obj, attr);
 		if (val == NULL) {
 			Py_DECREF(result);
 			return NULL;
@@ -521,7 +509,9 @@
 \n\
 Return a callable object that fetches the given attribute(s) from its operand.\n\
 After, f=attrgetter('name'), the call f(r) returns r.name.\n\
-After, g=attrgetter('name', 'date'), the call g(r) returns (r.name, r.date).");
+After, g=attrgetter('name', 'date'), the call g(r) returns (r.name, r.date).\n\
+After, h=attrgetter('name.first', 'name.last'), the call h(r) returns\n\
+(r.name.first, r.name.last).");
 
 static PyTypeObject attrgetter_type = {
 	PyVarObject_HEAD_INIT(NULL, 0)
@@ -565,6 +555,139 @@
 	attrgetter_new,			/* tp_new */
 	0,				/* tp_free */
 };
+
+
+/* methodcaller object **********************************************************/
+
+typedef struct {
+	PyObject_HEAD
+	PyObject *name;
+	PyObject *args;
+	PyObject *kwds;
+} methodcallerobject;
+
+static PyTypeObject methodcaller_type;
+
+static PyObject *
+methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+	methodcallerobject *mc;
+	PyObject *name, *newargs;
+
+	if (PyTuple_GET_SIZE(args) < 1) {
+		PyErr_SetString(PyExc_TypeError, "methodcaller needs at least "
+				"one argument, the method name");
+		return NULL;
+	}
+
+	/* create methodcallerobject structure */
+	mc = PyObject_GC_New(methodcallerobject, &methodcaller_type);
+	if (mc == NULL) 
+		return NULL;	
+
+	newargs = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
+	if (newargs == NULL) {
+		Py_DECREF(mc);
+		return NULL;
+	}
+	mc->args = newargs;
+
+	name = PyTuple_GET_ITEM(args, 0);
+	Py_INCREF(name);
+	mc->name = name;
+
+	Py_XINCREF(kwds);
+	mc->kwds = kwds;
+
+	PyObject_GC_Track(mc);
+	return (PyObject *)mc;
+}
+
+static void
+methodcaller_dealloc(methodcallerobject *mc)
+{
+	PyObject_GC_UnTrack(mc);
+	Py_XDECREF(mc->name);
+	Py_XDECREF(mc->args);
+	Py_XDECREF(mc->kwds);
+	PyObject_GC_Del(mc);
+}
+
+static int
+methodcaller_traverse(methodcallerobject *mc, visitproc visit, void *arg)
+{
+	Py_VISIT(mc->args);
+	Py_VISIT(mc->kwds);
+	return 0;
+}
+
+static PyObject *
+methodcaller_call(methodcallerobject *mc, PyObject *args, PyObject *kw)
+{
+	PyObject *method, *obj, *result;
+
+	if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj))
+		return NULL;
+	method = PyObject_GetAttr(obj, mc->name);
+	if (method == NULL)
+		return NULL;
+	result = PyObject_Call(method, mc->args, mc->kwds);
+	Py_DECREF(method);
+	return result;
+}
+
+PyDoc_STRVAR(methodcaller_doc,
+"methodcaller(name, ...) --> methodcaller object\n\
+\n\
+Return a callable object that calls the given method on its operand.\n\
+After, f = methodcaller('name'), the call f(r) returns r.name().\n\
+After, g = methodcaller('name', 'date', foo=1), the call g(r) returns\n\
+r.name('date', foo=1).");
+
+static PyTypeObject methodcaller_type = {
+	PyVarObject_HEAD_INIT(NULL, 0)
+	"operator.methodcaller",	/* tp_name */
+	sizeof(methodcallerobject),	/* tp_basicsize */
+	0,				/* tp_itemsize */
+	/* methods */
+	(destructor)methodcaller_dealloc, /* tp_dealloc */
+	0,				/* tp_print */
+	0,				/* tp_getattr */
+	0,				/* tp_setattr */
+	0,				/* tp_compare */
+	0,				/* tp_repr */
+	0,				/* tp_as_number */
+	0,				/* tp_as_sequence */
+	0,				/* tp_as_mapping */
+	0,				/* tp_hash */
+	(ternaryfunc)methodcaller_call,	/* tp_call */
+	0,				/* tp_str */
+	PyObject_GenericGetAttr,	/* tp_getattro */
+	0,				/* tp_setattro */
+	0,				/* tp_as_buffer */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
+	methodcaller_doc,			/* tp_doc */
+	(traverseproc)methodcaller_traverse,	/* tp_traverse */
+	0,				/* tp_clear */
+	0,				/* tp_richcompare */
+	0,				/* tp_weaklistoffset */
+	0,				/* tp_iter */
+	0,				/* tp_iternext */
+	0,				/* 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 */
+	methodcaller_new,		/* tp_new */
+	0,				/* tp_free */
+};
+
+
 /* Initialization function for the module (*must* be called initoperator) */
 
 PyMODINIT_FUNC
@@ -587,4 +710,9 @@
 		return;
 	Py_INCREF(&attrgetter_type);
 	PyModule_AddObject(m, "attrgetter", (PyObject *)&attrgetter_type);
+
+	if (PyType_Ready(&methodcaller_type) < 0)
+		return;
+	Py_INCREF(&methodcaller_type);
+	PyModule_AddObject(m, "methodcaller", (PyObject *)&methodcaller_type);
 }

Modified: python/branches/py3k-importlib/Modules/ossaudiodev.c
==============================================================================
--- python/branches/py3k-importlib/Modules/ossaudiodev.c	(original)
+++ python/branches/py3k-importlib/Modules/ossaudiodev.c	Thu Mar 27 00:48:05 2008
@@ -235,7 +235,7 @@
 
     if (ioctl(fd, cmd, &arg) == -1)
         return PyErr_SetFromErrno(PyExc_IOError);
-    return PyInt_FromLong(arg);
+    return PyLong_FromLong(arg);
 }
 
 
@@ -260,7 +260,7 @@
 
     if (ioctl(fd, cmd, &arg) == -1)
         return PyErr_SetFromErrno(PyExc_IOError);
-    return PyInt_FromLong(arg);
+    return PyLong_FromLong(arg);
 }
 
 
@@ -320,7 +320,7 @@
     int mask;
     if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
         return PyErr_SetFromErrno(PyExc_IOError);
-    return PyInt_FromLong(mask);
+    return PyLong_FromLong(mask);
 }
 
 static PyObject *
@@ -404,7 +404,7 @@
     } else {
         self->ocount += rv;
     }
-    return PyInt_FromLong(rv);
+    return PyLong_FromLong(rv);
 }
 
 static PyObject *
@@ -472,7 +472,7 @@
 static PyObject *
 oss_fileno(oss_audio_t *self, PyObject *unused)
 {
-    return PyInt_FromLong(self->fd);
+    return PyLong_FromLong(self->fd);
 }
 
 
@@ -529,9 +529,9 @@
     rv = PyTuple_New(3);
     if (rv == NULL)
         return NULL;
-    PyTuple_SET_ITEM(rv, 0, PyInt_FromLong(fmt));
-    PyTuple_SET_ITEM(rv, 1, PyInt_FromLong(channels));
-    PyTuple_SET_ITEM(rv, 2, PyInt_FromLong(rate));
+    PyTuple_SET_ITEM(rv, 0, PyLong_FromLong(fmt));
+    PyTuple_SET_ITEM(rv, 1, PyLong_FromLong(channels));
+    PyTuple_SET_ITEM(rv, 2, PyLong_FromLong(rate));
     return rv;
 }
 
@@ -584,7 +584,7 @@
         PyErr_SetFromErrno(PyExc_IOError);
         return NULL;
     }
-    return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
+    return PyLong_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
 }
 
 /* obufcount returns the number of samples that are available in the
@@ -603,7 +603,7 @@
         PyErr_SetFromErrno(PyExc_IOError);
         return NULL;
     }
-    return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
+    return PyLong_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
                           (ssize * nchannels));
 }
 
@@ -623,7 +623,7 @@
         PyErr_SetFromErrno(PyExc_IOError);
         return NULL;
     }
-    return PyInt_FromLong(ai.bytes / (ssize * nchannels));
+    return PyLong_FromLong(ai.bytes / (ssize * nchannels));
 }
 
 static PyObject *
@@ -662,7 +662,7 @@
 static PyObject *
 oss_mixer_fileno(oss_mixer_t *self, PyObject *unused)
 {
-    return PyInt_FromLong(self->fd);
+    return PyLong_FromLong(self->fd);
 }
 
 /* Simple mixer interface methods */

Modified: python/branches/py3k-importlib/Modules/parsermodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/parsermodule.c	(original)
+++ python/branches/py3k-importlib/Modules/parsermodule.c	Thu Mar 27 00:48:05 2008
@@ -89,7 +89,7 @@
         v = mkseq(1 + NCH(n) + (TYPE(n) == encoding_decl));
         if (v == NULL)
             return (v);
-        w = PyInt_FromLong(TYPE(n));
+        w = PyLong_FromLong(TYPE(n));
         if (w == NULL) {
             Py_DECREF(v);
             return ((PyObject*) NULL);
@@ -111,12 +111,12 @@
     else if (ISTERMINAL(TYPE(n))) {
         PyObject *result = mkseq(2 + lineno + col_offset);
         if (result != NULL) {
-            (void) addelem(result, 0, PyInt_FromLong(TYPE(n)));
+            (void) addelem(result, 0, PyLong_FromLong(TYPE(n)));
             (void) addelem(result, 1, PyUnicode_FromString(STR(n)));
             if (lineno == 1)
-                (void) addelem(result, 2, PyInt_FromLong(n->n_lineno));
+                (void) addelem(result, 2, PyLong_FromLong(n->n_lineno));
             if (col_offset == 1)
-                (void) addelem(result, 3, PyInt_FromLong(n->n_col_offset));
+                (void) addelem(result, 3, PyLong_FromLong(n->n_col_offset));
         }
         return (result);
     }
@@ -664,9 +664,9 @@
             if (temp == NULL)
                 ok = 0;
             else {
-                ok = PyInt_Check(temp);
+                ok = PyLong_Check(temp);
                 if (ok)
-                    type = PyInt_AS_LONG(temp);
+                    type = PyLong_AS_LONG(temp);
                 Py_DECREF(temp);
             }
         }
@@ -694,7 +694,7 @@
                 PyErr_Format(parser_error,
                              "second item in terminal node must be a string,"
                              " found %s",
-                             Py_Type(temp)->tp_name);
+                             Py_TYPE(temp)->tp_name);
                 Py_DECREF(temp);
                 Py_DECREF(elem);
                 return 0;
@@ -702,13 +702,13 @@
             if (len == 3) {
                 PyObject *o = PySequence_GetItem(elem, 2);
                 if (o != NULL) {
-                    if (PyInt_Check(o))
-                        *line_num = PyInt_AS_LONG(o);
+                    if (PyLong_Check(o))
+                        *line_num = PyLong_AS_LONG(o);
                     else {
                         PyErr_Format(parser_error,
                                      "third item in terminal node must be an"
                                      " integer, found %s",
-				     Py_Type(temp)->tp_name);
+				     Py_TYPE(temp)->tp_name);
                         Py_DECREF(o);
                         Py_DECREF(temp);
                         Py_DECREF(elem);
@@ -774,7 +774,7 @@
     long num = -1;
 
     if (temp != NULL)
-        num = PyInt_AsLong(temp);
+        num = PyLong_AsLong(temp);
     Py_XDECREF(temp);
     if (ISTERMINAL(num)) {
         /*
@@ -861,7 +861,7 @@
 VALIDATER(class);               VALIDATER(node);
 VALIDATER(parameters);          VALIDATER(suite);
 VALIDATER(testlist);            VALIDATER(varargslist);
-VALIDATER(vfpdef);              
+VALIDATER(vfpdef);
 VALIDATER(stmt);                VALIDATER(simple_stmt);
 VALIDATER(expr_stmt);           VALIDATER(power);
 VALIDATER(del_stmt);
@@ -874,7 +874,7 @@
 VALIDATER(try);                 VALIDATER(except_clause);
 VALIDATER(test);                VALIDATER(and_test);
 VALIDATER(not_test);            VALIDATER(comparison);
-VALIDATER(comp_op);             
+VALIDATER(comp_op);
 VALIDATER(star_expr);           VALIDATER(expr);
 VALIDATER(xor_expr);            VALIDATER(and_expr);
 VALIDATER(shift_expr);          VALIDATER(arith_expr);
@@ -988,11 +988,11 @@
     else {
         (void) validate_numnodes(tree, 4, "class");
     }
-	
+
     if (res) {
 	if (nch == 7) {
 		res = ((validate_lparen(CHILD(tree, 2)) &&
-			validate_testlist(CHILD(tree, 3)) &&
+			validate_arglist(CHILD(tree, 3)) &&
 			validate_rparen(CHILD(tree, 4))));
 	}
 	else if (nch == 6) {
@@ -1177,11 +1177,11 @@
 	    }
             while (res && i+1 < nch) { /* validate  (',' vfpdef ['=' test])* */
                 res = validate_comma(CHILD(tree, i));
-                if (TYPE(CHILD(tree, i+1)) == DOUBLESTAR) 
+                if (TYPE(CHILD(tree, i+1)) == DOUBLESTAR)
                     break;
                 res = res && validate_vfpdef(CHILD(tree, i+1));
                 if (res && i+2 < nch && TYPE(CHILD(tree, i+2)) == EQUAL) {
-                    res = res && (i+3 < nch) 
+                    res = res && (i+3 < nch)
                           && validate_test(CHILD(tree, i+3));
                     i += 4;
                 }
@@ -1234,7 +1234,7 @@
     int sym;
     node *ch;
     int i = 0;
-    
+
     if (!res)
         return 0;
     if (nch < 1) {
@@ -1242,7 +1242,7 @@
         return 0;
     }
     while (i < nch) {
-        ch = CHILD(tree, i);      
+        ch = CHILD(tree, i);
         sym = TYPE(ch);
         if (sym == vfpdef || sym == tfpdef) {
             /* validate (vfpdef ['=' test] ',')+ */
@@ -1443,7 +1443,7 @@
 static int
 validate_yield_or_testlist(node *tree)
 {
-	if (TYPE(tree) == yield_expr) 
+	if (TYPE(tree) == yield_expr)
 		return validate_yield_expr(tree);
 	else
 		return validate_testlist(tree);
@@ -1675,7 +1675,7 @@
 		&& validate_dotted_as_names(CHILD(tree, 1)));
 }
 
-/* Helper function to count the number of leading dots in 
+/* Helper function to count the number of leading dots in
  * 'from ...module import name'
  */
 static int
@@ -2361,7 +2361,7 @@
 static int
 validate_decorators(node *tree)
 {
-    int i, nch, ok; 
+    int i, nch, ok;
     nch = NCH(tree);
     ok = validate_ntype(tree, decorators) && nch >= 1;
 
@@ -2372,7 +2372,7 @@
 }
 
 /*  funcdef:
- *      
+ *
  *     -5   -4         -3  -2    -1
  *  'def' NAME parameters ':' suite
  */
@@ -3056,7 +3056,7 @@
 {
     PyObject *module, *copyreg;
 
-    Py_Type(&PyST_Type) = &PyType_Type;
+    Py_TYPE(&PyST_Type) = &PyType_Type;
     module = Py_InitModule("parser", parser_functions);
     if (module == NULL)
     	return;
@@ -3093,7 +3093,7 @@
      * If this fails, the import of this module will fail because an
      * exception will be raised here; should we clear the exception?
      */
-    copyreg = PyImport_ImportModule("copy_reg");
+    copyreg = PyImport_ImportModuleNoBlock("copy_reg");
     if (copyreg != NULL) {
         PyObject *func, *pickler;
 

Modified: python/branches/py3k-importlib/Modules/posixmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/posixmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/posixmodule.c	Thu Mar 27 00:48:05 2008
@@ -186,6 +186,12 @@
 #else
 extern int chmod(const char *, mode_t);
 #endif
+/*#ifdef HAVE_FCHMOD
+extern int fchmod(int, mode_t);
+#endif*/
+/*#ifdef HAVE_LCHMOD
+extern int lchmod(const char *, mode_t);
+#endif*/
 extern int chown(const char *, uid_t, gid_t);
 extern char *getcwd(char *, int);
 extern char *strerror(int);
@@ -302,10 +308,6 @@
 #define USE_CTERMID_R
 #endif
 
-#if defined(HAVE_TMPNAM_R) && defined(WITH_THREAD)
-#define USE_TMPNAM_R
-#endif
-
 /* choose the appropriate stat and fstat functions and return structs */
 #undef STAT
 #if defined(MS_WIN64) || defined(MS_WINDOWS)
@@ -344,7 +346,11 @@
 convertenviron(void)
 {
 	PyObject *d;
+#ifdef MS_WINDOWS
+	wchar_t **e;
+#else
 	char **e;
+#endif
 	d = PyDict_New();
 	if (d == NULL)
 		return NULL;
@@ -352,6 +358,38 @@
 	if (environ == NULL)
 		environ = *_NSGetEnviron();
 #endif
+#ifdef MS_WINDOWS
+	/* _wenviron must be initialized in this way if the program is started
+	   through main() instead of wmain(). */
+	_wgetenv(L"");
+	if (_wenviron == NULL)
+		return d;
+	/* This part ignores errors */
+	for (e = _wenviron; *e != NULL; e++) {
+		PyObject *k;
+		PyObject *v;
+		wchar_t *p = wcschr(*e, L'=');
+		if (p == NULL)
+			continue;
+		k = PyUnicode_FromWideChar(*e, (Py_ssize_t)(p-*e));
+		if (k == NULL) {
+			PyErr_Clear();
+			continue;
+		}
+		v = PyUnicode_FromWideChar(p+1, wcslen(p+1));
+		if (v == NULL) {
+			PyErr_Clear();
+			Py_DECREF(k);
+			continue;
+		}
+		if (PyDict_GetItem(d, k) == NULL) {
+			if (PyDict_SetItem(d, k, v) != 0)
+				PyErr_Clear();
+		}
+		Py_DECREF(k);
+		Py_DECREF(v);
+	}
+#else
 	if (environ == NULL)
 		return d;
 	/* This part ignores errors */
@@ -361,12 +399,12 @@
 		char *p = strchr(*e, '=');
 		if (p == NULL)
 			continue;
-		k = PyString_FromStringAndSize(*e, (int)(p-*e));
+		k = PyUnicode_FromStringAndSize(*e, (int)(p-*e));
 		if (k == NULL) {
 			PyErr_Clear();
 			continue;
 		}
-		v = PyString_FromString(p+1);
+		v = PyUnicode_FromString(p+1);
 		if (v == NULL) {
 			PyErr_Clear();
 			Py_DECREF(k);
@@ -379,6 +417,7 @@
 		Py_DECREF(k);
 		Py_DECREF(v);
 	}
+#endif
 #if defined(PYOS_OS2)
     {
         APIRET rc;
@@ -1242,7 +1281,7 @@
 #if SIZEOF_TIME_T > SIZEOF_LONG
 	ival = PyLong_FromLongLong((PY_LONG_LONG)sec);
 #else
-	ival = PyInt_FromLong((long)sec);
+	ival = PyLong_FromLong((long)sec);
 #endif
 	if (!ival)
 		return;
@@ -1266,27 +1305,27 @@
 	if (v == NULL)
 		return NULL;
 
-        PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long)st->st_mode));
+        PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long)st->st_mode));
 #ifdef HAVE_LARGEFILE_SUPPORT
         PyStructSequence_SET_ITEM(v, 1,
 				  PyLong_FromLongLong((PY_LONG_LONG)st->st_ino));
 #else
-        PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long)st->st_ino));
+        PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long)st->st_ino));
 #endif
 #if defined(HAVE_LONG_LONG) && !defined(MS_WINDOWS)
         PyStructSequence_SET_ITEM(v, 2,
 				  PyLong_FromLongLong((PY_LONG_LONG)st->st_dev));
 #else
-        PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long)st->st_dev));
+        PyStructSequence_SET_ITEM(v, 2, PyLong_FromLong((long)st->st_dev));
 #endif
-        PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long)st->st_nlink));
-        PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long)st->st_uid));
-        PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long)st->st_gid));
+        PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long)st->st_nlink));
+        PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong((long)st->st_uid));
+        PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong((long)st->st_gid));
 #ifdef HAVE_LARGEFILE_SUPPORT
         PyStructSequence_SET_ITEM(v, 6,
 				  PyLong_FromLongLong((PY_LONG_LONG)st->st_size));
 #else
-        PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong(st->st_size));
+        PyStructSequence_SET_ITEM(v, 6, PyLong_FromLong(st->st_size));
 #endif
 
 #if defined(HAVE_STAT_TV_NSEC)
@@ -1310,19 +1349,19 @@
 
 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
 	PyStructSequence_SET_ITEM(v, ST_BLKSIZE_IDX,
-			 PyInt_FromLong((long)st->st_blksize));
+			 PyLong_FromLong((long)st->st_blksize));
 #endif
 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
 	PyStructSequence_SET_ITEM(v, ST_BLOCKS_IDX,
-			 PyInt_FromLong((long)st->st_blocks));
+			 PyLong_FromLong((long)st->st_blocks));
 #endif
 #ifdef HAVE_STRUCT_STAT_ST_RDEV
 	PyStructSequence_SET_ITEM(v, ST_RDEV_IDX,
-			 PyInt_FromLong((long)st->st_rdev));
+			 PyLong_FromLong((long)st->st_rdev));
 #endif
 #ifdef HAVE_STRUCT_STAT_ST_GEN
 	PyStructSequence_SET_ITEM(v, ST_GEN_IDX,
-			 PyInt_FromLong((long)st->st_gen));
+			 PyLong_FromLong((long)st->st_gen));
 #endif
 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
 	{
@@ -1337,7 +1376,7 @@
 	  if (_stat_float_times) {
 	    val = PyFloat_FromDouble(bsec + 1e-9*bnsec);
 	  } else {
-	    val = PyInt_FromLong((long)bsec);
+	    val = PyLong_FromLong((long)bsec);
 	  }
 	  PyStructSequence_SET_ITEM(v, ST_BIRTHTIME_IDX,
 				    val);
@@ -1345,7 +1384,7 @@
 #endif
 #ifdef HAVE_STRUCT_STAT_ST_FLAGS
 	PyStructSequence_SET_ITEM(v, ST_FLAGS_IDX,
-			 PyInt_FromLong((long)st->st_flags));
+			 PyLong_FromLong((long)st->st_flags));
 #endif
 
 	if (PyErr_Occurred()) {
@@ -1526,8 +1565,11 @@
 		/* File does not exist, or cannot read attributes */
 		return PyBool_FromLong(0);
 	/* Access is possible if either write access wasn't requested, or
-	   the file isn't read-only. */
-	return PyBool_FromLong(!(mode & 2) || !(attr & FILE_ATTRIBUTE_READONLY));
+	   the file isn't read-only, or if it's a directory, as there are
+	   no read-only directories on Windows. */
+	return PyBool_FromLong(!(mode & 2) 
+	                       || !(attr & FILE_ATTRIBUTE_READONLY)
+			       || (attr & FILE_ATTRIBUTE_DIRECTORY));
 #else
 	int res;
 	if (!PyArg_ParseTuple(args, "eti:access", 
@@ -1714,6 +1756,52 @@
 #endif
 }
 
+#ifdef HAVE_FCHMOD
+PyDoc_STRVAR(posix_fchmod__doc__,
+"fchmod(fd, mode)\n\n\
+Change the access permissions of the file given by file\n\
+descriptor fd.");
+
+static PyObject *
+posix_fchmod(PyObject *self, PyObject *args)
+{
+	int fd, mode, res;
+	if (!PyArg_ParseTuple(args, "ii:fchmod", &fd, &mode))
+		return NULL;
+	Py_BEGIN_ALLOW_THREADS
+	res = fchmod(fd, mode);
+	Py_END_ALLOW_THREADS
+	if (res < 0)
+		return posix_error();
+	Py_RETURN_NONE;
+}
+#endif /* HAVE_FCHMOD */
+
+#ifdef HAVE_LCHMOD
+PyDoc_STRVAR(posix_lchmod__doc__,
+"lchmod(path, mode)\n\n\
+Change the access permissions of a file. If path is a symlink, this\n\
+affects the link itself rather than the target.");
+
+static PyObject *
+posix_lchmod(PyObject *self, PyObject *args)
+{
+	char *path = NULL;
+	int i;
+	int res;
+	if (!PyArg_ParseTuple(args, "eti:lchmod", Py_FileSystemDefaultEncoding,
+	                      &path, &i))
+		return NULL;
+	Py_BEGIN_ALLOW_THREADS
+	res = lchmod(path, i);
+	Py_END_ALLOW_THREADS
+	if (res < 0)
+		return posix_error_with_allocated_filename(path);
+	PyMem_Free(path);
+	Py_RETURN_NONE;
+}
+#endif /* HAVE_LCHMOD */
+
 
 #ifdef HAVE_CHFLAGS
 PyDoc_STRVAR(posix_chflags__doc__,
@@ -1818,9 +1906,9 @@
 posix_chown(PyObject *self, PyObject *args)
 {
 	char *path = NULL;
-	int uid, gid;
+	long uid, gid;
 	int res;
-	if (!PyArg_ParseTuple(args, "etii:chown",
+	if (!PyArg_ParseTuple(args, "etll:chown",
 	                      Py_FileSystemDefaultEncoding, &path,
 	                      &uid, &gid))
 		return NULL;
@@ -1835,6 +1923,28 @@
 }
 #endif /* HAVE_CHOWN */
 
+#ifdef HAVE_FCHOWN
+PyDoc_STRVAR(posix_fchown__doc__,
+"fchown(fd, uid, gid)\n\n\
+Change the owner and group id of the file given by file descriptor\n\
+fd to the numeric uid and gid.");
+
+static PyObject *
+posix_fchown(PyObject *self, PyObject *args)
+{
+	int fd, uid, gid;
+	int res;
+	if (!PyArg_ParseTuple(args, "iii:chown", &fd, &uid, &gid))
+		return NULL;
+	Py_BEGIN_ALLOW_THREADS
+	res = fchown(fd, (uid_t) uid, (gid_t) gid);
+	Py_END_ALLOW_THREADS
+	if (res < 0)
+		return posix_error();
+	Py_RETURN_NONE;
+}
+#endif /* HAVE_FCHOWN */
+
 #ifdef HAVE_LCHOWN
 PyDoc_STRVAR(posix_lchown__doc__,
 "lchown(path, uid, gid)\n\n\
@@ -2421,7 +2531,7 @@
 	if (value == -1 && errno != 0)
 		/* either nice() or getpriority() returned an error */
 		return posix_error();
-	return PyInt_FromLong((long) value);
+	return PyLong_FromLong((long) value);
 }
 #endif /* HAVE_NICE */
 
@@ -2507,14 +2617,24 @@
 static PyObject *
 posix_system(PyObject *self, PyObject *args)
 {
-	char *command;
 	long sts;
+#ifdef MS_WINDOWS
+	wchar_t *command;
+	if (!PyArg_ParseTuple(args, "u:system", &command))
+		return NULL;
+#else
+	char *command;
 	if (!PyArg_ParseTuple(args, "s:system", &command))
 		return NULL;
+#endif
 	Py_BEGIN_ALLOW_THREADS
+#ifdef MS_WINDOWS
+	sts = _wsystem(command);
+#else
 	sts = system(command);
+#endif
 	Py_END_ALLOW_THREADS
-	return PyInt_FromLong(sts);
+	return PyLong_FromLong(sts);
 }
 #endif
 
@@ -2532,7 +2652,7 @@
 	i = (int)umask(i);
 	if (i < 0)
 		return posix_error();
-	return PyInt_FromLong((long)i);
+	return PyLong_FromLong((long)i);
 }
 
 
@@ -2586,10 +2706,10 @@
 	long intval;
 	if (PyFloat_Check(t)) {
 		double tval = PyFloat_AsDouble(t);
-		PyObject *intobj = Py_Type(t)->tp_as_number->nb_int(t);
+		PyObject *intobj = Py_TYPE(t)->tp_as_number->nb_int(t);
 		if (!intobj)
 			return -1;
-		intval = PyInt_AsLong(intobj);
+		intval = PyLong_AsLong(intobj);
 		Py_DECREF(intobj);
 		if (intval == -1 && PyErr_Occurred())
 			return -1;
@@ -2601,7 +2721,7 @@
 			*usec = 0;
 		return 0;
 	}
-	intval = PyInt_AsLong(t);
+	intval = PyLong_AsLong(t);
 	if (intval == -1 && PyErr_Occurred())
 		return -1;
 	*sec = intval;
@@ -2983,7 +3103,7 @@
         /* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */
         if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) {
 #endif
-		len = PyString_Size(key) + PyString_Size(val) + 2;
+		len = PyUnicode_GetSize(key) + PyUnicode_GetSize(val) + 2;
 		p = PyMem_NEW(char, len);
 		if (p == NULL) {
 			PyErr_NoMemory();
@@ -3213,7 +3333,7 @@
 		{
 			goto fail_2;
 		}
-		len = PyString_Size(key) + PyString_Size(val) + 2;
+		len = PyUnicode_GetSize(key) + PyUnicode_GetSize(val) + 2;
 		p = PyMem_NEW(char, len);
 		if (p == NULL) {
 			PyErr_NoMemory();
@@ -3446,7 +3566,7 @@
 		{
 			goto fail_2;
 		}
-		len = PyString_Size(key) + PyString_Size(val) + 2;
+		len = PyUnicode_GetSize(key) + PyUnicode_GetSize(val) + 2;
 		p = PyMem_NEW(char, len);
 		if (p == NULL) {
 			PyErr_NoMemory();
@@ -3459,9 +3579,9 @@
 
 	Py_BEGIN_ALLOW_THREADS
 #if defined(PYCC_GCC)
-	spawnval = spawnve(mode, path, argvlist, envlist);
+	spawnval = spawnvpe(mode, path, argvlist, envlist);
 #else
-	spawnval = _spawnve(mode, path, argvlist, envlist);
+	spawnval = _spawnvpe(mode, path, argvlist, envlist);
 #endif
 	Py_END_ALLOW_THREADS
 
@@ -3496,11 +3616,11 @@
 static PyObject *
 posix_fork1(PyObject *self, PyObject *noargs)
 {
-	int pid = fork1();
+	pid_t pid = fork1();
 	if (pid == -1)
 		return posix_error();
 	PyOS_AfterFork();
-	return PyInt_FromLong((long)pid);
+	return PyLong_FromLong(pid);
 }
 #endif
 
@@ -3514,12 +3634,12 @@
 static PyObject *
 posix_fork(PyObject *self, PyObject *noargs)
 {
-	int pid = fork();
+	pid_t pid = fork();
 	if (pid == -1)
 		return posix_error();
 	if (pid == 0)
 		PyOS_AfterFork();
-	return PyInt_FromLong((long)pid);
+	return PyLong_FromLong(pid);
 }
 #endif
 
@@ -3621,14 +3741,15 @@
 static PyObject *
 posix_forkpty(PyObject *self, PyObject *noargs)
 {
-	int master_fd = -1, pid;
+	int master_fd = -1;
+	pid_t pid;
 
 	pid = forkpty(&master_fd, NULL, NULL, NULL);
 	if (pid == -1)
 		return posix_error();
 	if (pid == 0)
 		PyOS_AfterFork();
-	return Py_BuildValue("(ii)", pid, master_fd);
+	return Py_BuildValue("(li)", pid, master_fd);
 }
 #endif
 
@@ -3640,7 +3761,7 @@
 static PyObject *
 posix_getegid(PyObject *self, PyObject *noargs)
 {
-	return PyInt_FromLong((long)getegid());
+	return PyLong_FromLong((long)getegid());
 }
 #endif
 
@@ -3653,7 +3774,7 @@
 static PyObject *
 posix_geteuid(PyObject *self, PyObject *noargs)
 {
-	return PyInt_FromLong((long)geteuid());
+	return PyLong_FromLong((long)geteuid());
 }
 #endif
 
@@ -3666,7 +3787,7 @@
 static PyObject *
 posix_getgid(PyObject *self, PyObject *noargs)
 {
-	return PyInt_FromLong((long)getgid());
+	return PyLong_FromLong((long)getgid());
 }
 #endif
 
@@ -3678,7 +3799,7 @@
 static PyObject *
 posix_getpid(PyObject *self, PyObject *noargs)
 {
-	return PyInt_FromLong((long)getpid());
+	return PyLong_FromLong((long)getpid());
 }
 
 
@@ -3709,7 +3830,7 @@
             if (result != NULL) {
                 int i;
                 for (i = 0; i < n; ++i) {
-                    PyObject *o = PyInt_FromLong((long)grouplist[i]);
+                    PyObject *o = PyLong_FromLong((long)grouplist[i]);
                     if (o == NULL) {
                         Py_DECREF(result);
                         result = NULL;
@@ -3738,7 +3859,7 @@
 	pgid = getpgid(pid);
 	if (pgid < 0)
 		return posix_error();
-	return PyInt_FromLong((long)pgid);
+	return PyLong_FromLong((long)pgid);
 }
 #endif /* HAVE_GETPGID */
 
@@ -3752,9 +3873,9 @@
 posix_getpgrp(PyObject *self, PyObject *noargs)
 {
 #ifdef GETPGRP_HAVE_ARG
-	return PyInt_FromLong((long)getpgrp(0));
+	return PyLong_FromLong((long)getpgrp(0));
 #else /* GETPGRP_HAVE_ARG */
-	return PyInt_FromLong((long)getpgrp());
+	return PyLong_FromLong((long)getpgrp());
 #endif /* GETPGRP_HAVE_ARG */
 }
 #endif /* HAVE_GETPGRP */
@@ -3788,7 +3909,7 @@
 static PyObject *
 posix_getppid(PyObject *self, PyObject *noargs)
 {
-	return PyInt_FromLong((long)getppid());
+	return PyLong_FromLong((long)getppid());
 }
 #endif
 
@@ -3830,7 +3951,7 @@
 static PyObject *
 posix_getuid(PyObject *self, PyObject *noargs)
 {
-	return PyInt_FromLong((long)getuid());
+	return PyLong_FromLong((long)getuid());
 }
 #endif
 
@@ -3843,7 +3964,8 @@
 static PyObject *
 posix_kill(PyObject *self, PyObject *args)
 {
-	int pid, sig;
+	pid_t pid;
+	int sig;
 	if (!PyArg_ParseTuple(args, "ii:kill", &pid, &sig))
 		return NULL;
 #if defined(PYOS_OS2) && !defined(PYCC_GCC)
@@ -4088,7 +4210,7 @@
 
 #if defined(HAVE_WAIT3) || defined(HAVE_WAIT4)
 static PyObject *
-wait_helper(int pid, int status, struct rusage *ru)
+wait_helper(pid_t pid, int status, struct rusage *ru)
 {
 	PyObject *result;
    	static PyObject *struct_rusage;
@@ -4097,7 +4219,7 @@
 		return posix_error();
 
 	if (struct_rusage == NULL) {
-		PyObject *m = PyImport_ImportModule("resource");
+		PyObject *m = PyImport_ImportModuleNoBlock("resource");
 		if (m == NULL)
 			return NULL;
 		struct_rusage = PyObject_GetAttrString(m, "struct_rusage");
@@ -4120,7 +4242,7 @@
 	PyStructSequence_SET_ITEM(result, 1,
 			PyFloat_FromDouble(doubletime(ru->ru_stime)));
 #define SET_INT(result, index, value)\
-		PyStructSequence_SET_ITEM(result, index, PyInt_FromLong(value))
+		PyStructSequence_SET_ITEM(result, index, PyLong_FromLong(value))
 	SET_INT(result, 2, ru->ru_maxrss);
 	SET_INT(result, 3, ru->ru_ixrss);
 	SET_INT(result, 4, ru->ru_idrss);
@@ -4154,7 +4276,8 @@
 static PyObject *
 posix_wait3(PyObject *self, PyObject *args)
 {
-	int pid, options;
+	pid_t pid;
+	int options;
 	struct rusage ru;
 	WAIT_TYPE status;
 	WAIT_STATUS_INT(status) = 0;
@@ -4178,7 +4301,8 @@
 static PyObject *
 posix_wait4(PyObject *self, PyObject *args)
 {
-	int pid, options;
+	pid_t pid;
+	int options;
 	struct rusage ru;
 	WAIT_TYPE status;
 	WAIT_STATUS_INT(status) = 0;
@@ -4202,7 +4326,8 @@
 static PyObject *
 posix_waitpid(PyObject *self, PyObject *args)
 {
-	int pid, options;
+	pid_t pid;
+	int options;
 	WAIT_TYPE status;
 	WAIT_STATUS_INT(status) = 0;
 
@@ -4251,7 +4376,7 @@
 static PyObject *
 posix_wait(PyObject *self, PyObject *noargs)
 {
-	int pid;
+	pid_t pid;
 	WAIT_TYPE status;
 	WAIT_STATUS_INT(status) = 0;
 
@@ -4421,10 +4546,10 @@
 	*/
 	return Py_BuildValue(
 		"ddddd",
-		(double)(kernel.dwHighDateTime*429.4967296 +
-		         kernel.dwLowDateTime*1e-7),
 		(double)(user.dwHighDateTime*429.4967296 +
 		         user.dwLowDateTime*1e-7),
+		(double)(kernel.dwHighDateTime*429.4967296 +
+		         kernel.dwLowDateTime*1e-7),
 		(double)0,
 		(double)0,
 		(double)0);
@@ -4446,13 +4571,14 @@
 static PyObject *
 posix_getsid(PyObject *self, PyObject *args)
 {
-	int pid, sid;
+	pid_t pid;
+	int sid;
 	if (!PyArg_ParseTuple(args, "i:getsid", &pid))
 		return NULL;
 	sid = getsid(pid);
 	if (sid < 0)
 		return posix_error();
-	return PyInt_FromLong((long)sid);
+	return PyLong_FromLong((long)sid);
 }
 #endif /* HAVE_GETSID */
 
@@ -4480,7 +4606,8 @@
 static PyObject *
 posix_setpgid(PyObject *self, PyObject *args)
 {
-	int pid, pgrp;
+	pid_t pid;
+	int pgrp;
 	if (!PyArg_ParseTuple(args, "ii:setpgid", &pid, &pgrp))
 		return NULL;
 	if (setpgid(pid, pgrp) < 0)
@@ -4499,13 +4626,14 @@
 static PyObject *
 posix_tcgetpgrp(PyObject *self, PyObject *args)
 {
-	int fd, pgid;
+	int fd;
+	pid_t pgid;
 	if (!PyArg_ParseTuple(args, "i:tcgetpgrp", &fd))
 		return NULL;
 	pgid = tcgetpgrp(fd);
 	if (pgid < 0)
 		return posix_error();
-	return PyInt_FromLong((long)pgid);
+	return PyLong_FromLong((long)pgid);
 }
 #endif /* HAVE_TCGETPGRP */
 
@@ -4553,7 +4681,7 @@
 			Py_END_ALLOW_THREADS
 			if (fd < 0)
 				return posix_error();
-			return PyInt_FromLong((long)fd);
+			return PyLong_FromLong((long)fd);
 		}
 		/* Drop the argument parsing error as narrow strings
 		   are also valid. */
@@ -4572,7 +4700,7 @@
 	if (fd < 0)
 		return posix_error_with_allocated_filename(file);
 	PyMem_Free(file);
-	return PyInt_FromLong((long)fd);
+	return PyLong_FromLong((long)fd);
 }
 
 
@@ -4596,6 +4724,24 @@
 }
 
 
+PyDoc_STRVAR(posix_closerange__doc__, 
+"closerange(fd_low, fd_high)\n\n\
+Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
+
+static PyObject *
+posix_closerange(PyObject *self, PyObject *args)
+{
+	int fd_from, fd_to, i;
+	if (!PyArg_ParseTuple(args, "ii:closerange", &fd_from, &fd_to))
+		return NULL;
+	Py_BEGIN_ALLOW_THREADS
+	for (i = fd_from; i < fd_to; i++)
+		close(i);
+	Py_END_ALLOW_THREADS
+	Py_RETURN_NONE;
+}
+
+
 PyDoc_STRVAR(posix_dup__doc__,
 "dup(fd) -> fd2\n\n\
 Return a duplicate of a file descriptor.");
@@ -4611,7 +4757,7 @@
 	Py_END_ALLOW_THREADS
 	if (fd < 0)
 		return posix_error();
-	return PyInt_FromLong((long)fd);
+	return PyLong_FromLong((long)fd);
 }
 
 
@@ -4661,10 +4807,10 @@
 #endif /* SEEK_END */
 
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-	pos = PyInt_AsLong(posobj);
+	pos = PyLong_AsLong(posobj);
 #else
 	pos = PyLong_Check(posobj) ?
-		PyLong_AsLongLong(posobj) : PyInt_AsLong(posobj);
+		PyLong_AsLongLong(posobj) : PyLong_AsLong(posobj);
 #endif
 	if (PyErr_Occurred())
 		return NULL;
@@ -4680,7 +4826,7 @@
 		return posix_error();
 
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-	return PyInt_FromLong(res);
+	return PyLong_FromLong(res);
 #else
 	return PyLong_FromLongLong(res);
 #endif
@@ -4703,18 +4849,18 @@
 		errno = EINVAL;
 		return posix_error();
 	}
-	buffer = PyBytes_FromStringAndSize((char *)NULL, size);
+	buffer = PyString_FromStringAndSize((char *)NULL, size);
 	if (buffer == NULL)
 		return NULL;
 	Py_BEGIN_ALLOW_THREADS
-	n = read(fd, PyBytes_AsString(buffer), size);
+	n = read(fd, PyString_AS_STRING(buffer), size);
 	Py_END_ALLOW_THREADS
 	if (n < 0) {
 		Py_DECREF(buffer);
 		return posix_error();
 	}
 	if (n != size)
-		PyBytes_Resize(buffer, n);
+		_PyString_Resize(&buffer, n);
 	return buffer;
 }
 
@@ -4737,7 +4883,7 @@
 	Py_END_ALLOW_THREADS
 	if (size < 0)
 		return posix_error();
-	return PyInt_FromSsize_t(size);
+	return PyLong_FromSsize_t(size);
 }
 
 
@@ -4897,7 +5043,7 @@
 	int device;
 	if (!PyArg_ParseTuple(args, "i:major", &device))
 		return NULL;
-	return PyInt_FromLong((long)major(device));
+	return PyLong_FromLong((long)major(device));
 }
 
 PyDoc_STRVAR(posix_minor__doc__,
@@ -4910,7 +5056,7 @@
 	int device;
 	if (!PyArg_ParseTuple(args, "i:minor", &device))
 		return NULL;
-	return PyInt_FromLong((long)minor(device));
+	return PyLong_FromLong((long)minor(device));
 }
 
 PyDoc_STRVAR(posix_makedev__doc__,
@@ -4923,7 +5069,7 @@
 	int major, minor;
 	if (!PyArg_ParseTuple(args, "ii:makedev", &major, &minor))
 		return NULL;
-	return PyInt_FromLong((long)makedev(major, minor));
+	return PyLong_FromLong((long)makedev(major, minor));
 }
 #endif /* device macros */
 
@@ -4945,10 +5091,10 @@
 		return NULL;
 
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-	length = PyInt_AsLong(lenobj);
+	length = PyLong_AsLong(lenobj);
 #else
 	length = PyLong_Check(lenobj) ?
-		PyLong_AsLongLong(lenobj) : PyInt_AsLong(lenobj);
+		PyLong_AsLongLong(lenobj) : PyLong_AsLong(lenobj);
 #endif
 	if (PyErr_Occurred())
 		return NULL;
@@ -4977,12 +5123,23 @@
 static PyObject *
 posix_putenv(PyObject *self, PyObject *args)
 {
+#ifdef MS_WINDOWS
+        wchar_t *s1, *s2;
+        wchar_t *newenv;
+#else
         char *s1, *s2;
         char *newenv;
+#endif
 	PyObject *newstr;
 	size_t len;
 
-	if (!PyArg_ParseTuple(args, "ss:putenv", &s1, &s2))
+	if (!PyArg_ParseTuple(args,
+#ifdef MS_WINDOWS
+			      "uu:putenv",
+#else
+			      "ss:putenv",
+#endif
+			      &s1, &s2))
 		return NULL;
 
 #if defined(PYOS_OS2)
@@ -5001,14 +5158,27 @@
             return os2_error(rc);
     } else {
 #endif
-
 	/* XXX This can leak memory -- not easy to fix :-( */
-	len = strlen(s1) + strlen(s2) + 2;
 	/* len includes space for a trailing \0; the size arg to
 	   PyString_FromStringAndSize does not count that */
+#ifdef MS_WINDOWS
+	len = wcslen(s1) + wcslen(s2) + 2;
+	newstr = PyUnicode_FromUnicode(NULL, (int)len - 1);
+#else
+	len = strlen(s1) + strlen(s2) + 2;
 	newstr = PyString_FromStringAndSize(NULL, (int)len - 1);
+#endif
 	if (newstr == NULL)
 		return PyErr_NoMemory();
+#ifdef MS_WINDOWS
+	newenv = PyUnicode_AsUnicode(newstr);
+	_snwprintf(newenv, len, L"%s=%s", s1, s2);
+	if (_wputenv(newenv)) {
+                Py_DECREF(newstr);
+                posix_error();
+                return NULL;
+	}
+#else
 	newenv = PyString_AS_STRING(newstr);
 	PyOS_snprintf(newenv, len, "%s=%s", s1, s2);
 	if (putenv(newenv)) {
@@ -5016,6 +5186,7 @@
                 posix_error();
                 return NULL;
 	}
+#endif
 	/* Install the first arg and newstr in posix_putenv_garbage;
 	 * this will cause previous value to be collected.  This has to
 	 * happen after the real putenv() call because the old value
@@ -5068,7 +5239,6 @@
 }
 #endif /* unsetenv */
 
-#ifdef HAVE_STRERROR
 PyDoc_STRVAR(posix_strerror__doc__,
 "strerror(code) -> string\n\n\
 Translate an error code to a message string.");
@@ -5088,7 +5258,6 @@
 	}
 	return PyUnicode_FromString(message);
 }
-#endif /* strerror */
 
 
 #ifdef HAVE_SYS_WAIT_H
@@ -5259,19 +5428,19 @@
 		return NULL;
 
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-        PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long) st.f_bsize));
-        PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) st.f_frsize));
-        PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long) st.f_blocks));
-        PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long) st.f_bfree));
-        PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long) st.f_bavail));
-        PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long) st.f_files));
-        PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong((long) st.f_ffree));
-        PyStructSequence_SET_ITEM(v, 7, PyInt_FromLong((long) st.f_favail));
-        PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) st.f_flag));
-        PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) st.f_namemax));
+        PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long) st.f_bsize));
+        PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long) st.f_frsize));
+        PyStructSequence_SET_ITEM(v, 2, PyLong_FromLong((long) st.f_blocks));
+        PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long) st.f_bfree));
+        PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong((long) st.f_bavail));
+        PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong((long) st.f_files));
+        PyStructSequence_SET_ITEM(v, 6, PyLong_FromLong((long) st.f_ffree));
+        PyStructSequence_SET_ITEM(v, 7, PyLong_FromLong((long) st.f_favail));
+        PyStructSequence_SET_ITEM(v, 8, PyLong_FromLong((long) st.f_flag));
+        PyStructSequence_SET_ITEM(v, 9, PyLong_FromLong((long) st.f_namemax));
 #else
-        PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long) st.f_bsize));
-        PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) st.f_frsize));
+        PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long) st.f_bsize));
+        PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long) st.f_frsize));
         PyStructSequence_SET_ITEM(v, 2,
 			       PyLong_FromLongLong((PY_LONG_LONG) st.f_blocks));
         PyStructSequence_SET_ITEM(v, 3,
@@ -5284,8 +5453,8 @@
 			       PyLong_FromLongLong((PY_LONG_LONG) st.f_ffree));
         PyStructSequence_SET_ITEM(v, 7,
 			       PyLong_FromLongLong((PY_LONG_LONG) st.f_favail));
-        PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) st.f_flag));
-        PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) st.f_namemax));
+        PyStructSequence_SET_ITEM(v, 8, PyLong_FromLong((long) st.f_flag));
+        PyStructSequence_SET_ITEM(v, 9, PyLong_FromLong((long) st.f_namemax));
 #endif
 
         return v;
@@ -5339,100 +5508,6 @@
 }
 #endif /* HAVE_STATVFS */
 
-
-#ifdef HAVE_TEMPNAM
-PyDoc_STRVAR(posix_tempnam__doc__,
-"tempnam([dir[, prefix]]) -> string\n\n\
-Return a unique name for a temporary file.\n\
-The directory and a prefix may be specified as strings; they may be omitted\n\
-or None if not needed.");
-
-static PyObject *
-posix_tempnam(PyObject *self, PyObject *args)
-{
-    PyObject *result = NULL;
-    char *dir = NULL;
-    char *pfx = NULL;
-    char *name;
-
-    if (!PyArg_ParseTuple(args, "|zz:tempnam", &dir, &pfx))
-        return NULL;
-
-    if (PyErr_WarnEx(PyExc_RuntimeWarning,
-		     "tempnam is a potential security risk to your program",
-		     1) < 0)
-	    return NULL;
-
-#ifdef MS_WINDOWS
-    name = _tempnam(dir, pfx);
-#else
-    name = tempnam(dir, pfx);
-#endif
-    if (name == NULL)
-        return PyErr_NoMemory();
-    result = PyUnicode_DecodeFSDefault(name);
-    free(name);
-    return result;
-}
-#endif
-
-
-#ifdef HAVE_TMPFILE
-PyDoc_STRVAR(posix_tmpfile__doc__,
-"tmpfile() -> file object\n\n\
-Create a temporary file with no directory entries.");
-
-static PyObject *
-posix_tmpfile(PyObject *self, PyObject *noargs)
-{
-    FILE *fp;
-
-    fp = tmpfile();
-    if (fp == NULL)
-        return posix_error();
-    return PyFile_FromFile(fp, "<tmpfile>", "w+b", fclose);
-}
-#endif
-
-
-#ifdef HAVE_TMPNAM
-PyDoc_STRVAR(posix_tmpnam__doc__,
-"tmpnam() -> string\n\n\
-Return a unique name for a temporary file.");
-
-static PyObject *
-posix_tmpnam(PyObject *self, PyObject *noargs)
-{
-    char buffer[L_tmpnam];
-    char *name;
-
-    if (PyErr_WarnEx(PyExc_RuntimeWarning,
-		     "tmpnam is a potential security risk to your program",
-		     1) < 0)
-	    return NULL;
-
-#ifdef USE_TMPNAM_R
-    name = tmpnam_r(buffer);
-#else
-    name = tmpnam(buffer);
-#endif
-    if (name == NULL) {
-	PyObject *err = Py_BuildValue("is", 0,
-#ifdef USE_TMPNAM_R
-                                      "unexpected NULL from tmpnam_r"
-#else
-                                      "unexpected NULL from tmpnam"
-#endif
-                                      );
-	PyErr_SetObject(PyExc_OSError, err);
-	Py_XDECREF(err);
-	return NULL;
-    }
-    return PyUnicode_DecodeFSDefault(buffer);
-}
-#endif
-
-
 /* This is used for fpathconf(), pathconf(), confstr() and sysconf().
  * It maps strings representing configuration variable names to
  * integer values, allowing those functions to be called with the
@@ -5453,8 +5528,8 @@
 conv_confname(PyObject *arg, int *valuep, struct constdef *table,
               size_t tablesize)
 {
-    if (PyInt_Check(arg)) {
-        *valuep = PyInt_AS_LONG(arg);
+    if (PyLong_Check(arg)) {
+        *valuep = PyLong_AS_LONG(arg);
         return 1;
     }
     else {
@@ -5577,7 +5652,7 @@
         if (limit == -1 && errno != 0)
             posix_error();
         else
-            result = PyInt_FromLong(limit);
+            result = PyLong_FromLong(limit);
     }
     return result;
 }
@@ -5611,7 +5686,7 @@
                 posix_error_with_filename(path);
         }
         else
-            result = PyInt_FromLong(limit);
+            result = PyLong_FromLong(limit);
     }
     return result;
 }
@@ -6335,7 +6410,7 @@
         if (value == -1 && errno != 0)
             posix_error();
         else
-            result = PyInt_FromLong(value);
+            result = PyLong_FromLong(value);
     }
     return result;
 }
@@ -6376,7 +6451,7 @@
 	    return -1;
 
     for (i=0; i < tablesize; ++i) {
-            PyObject *o = PyInt_FromLong(table[i].value);
+            PyObject *o = PyLong_FromLong(table[i].value);
             if (o == NULL || PyDict_SetItemString(d, table[i].name, o) == -1) {
 		    Py_XDECREF(o);
 		    Py_DECREF(d);
@@ -6594,11 +6669,11 @@
 	}
 
 	/* Allocate bytes */
-	result = PyBytes_FromStringAndSize(NULL, howMany);
+	result = PyString_FromStringAndSize(NULL, howMany);
 	if (result != NULL) {
 		/* Get random data */
 		if (! pCryptGenRandom(hCryptProv, howMany, (unsigned char*)
-				      PyBytes_AS_STRING(result))) {
+				      PyString_AS_STRING(result))) {
 			Py_DECREF(result);
 			return win32_error("CryptGenRandom", NULL);
 		}
@@ -6665,11 +6740,11 @@
 				    "negative argument not allowed");
 
 	/* Allocate bytes */
-	result = PyBytes_FromStringAndSize(NULL, howMany);
+	result = PyString_FromStringAndSize(NULL, howMany);
 	if (result != NULL) {
 		/* Get random data */
 		if (RAND_pseudo_bytes((unsigned char*)
-				      PyBytes_AS_STRING(result),
+				      PyString_AS_STRING(result),
 				      howMany) < 0) {
 			Py_DECREF(result);
 			return PyErr_Format(PyExc_ValueError,
@@ -6690,9 +6765,18 @@
 	{"chflags",	posix_chflags, METH_VARARGS, posix_chflags__doc__},
 #endif /* HAVE_CHFLAGS */
 	{"chmod",	posix_chmod, METH_VARARGS, posix_chmod__doc__},
+#ifdef HAVE_FCHMOD
+	{"fchmod",	posix_fchmod, METH_VARARGS, posix_fchmod__doc__},
+#endif /* HAVE_FCHMOD */
 #ifdef HAVE_CHOWN
 	{"chown",	posix_chown, METH_VARARGS, posix_chown__doc__},
 #endif /* HAVE_CHOWN */
+#ifdef HAVE_LCHMOD
+	{"lchmod",	posix_lchmod, METH_VARARGS, posix_lchmod__doc__},
+#endif /* HAVE_LCHMOD */
+#ifdef HAVE_FCHOWN
+	{"fchown",	posix_fchown, METH_VARARGS, posix_fchown__doc__},
+#endif /* HAVE_FCHOWN */
 #ifdef HAVE_LCHFLAGS
 	{"lchflags",	posix_lchflags, METH_VARARGS, posix_lchflags__doc__},
 #endif /* HAVE_LCHFLAGS */
@@ -6859,6 +6943,7 @@
 #endif /* HAVE_TCSETPGRP */
 	{"open",	posix_open, METH_VARARGS, posix_open__doc__},
 	{"close",	posix_close, METH_VARARGS, posix_close__doc__},
+	{"closerange",	posix_closerange, METH_VARARGS, posix_closerange__doc__},
 	{"device_encoding", device_encoding, METH_VARARGS, device_encoding__doc__},
 	{"dup",		posix_dup, METH_VARARGS, posix_dup__doc__},
 	{"dup2",	posix_dup2, METH_VARARGS, posix_dup2__doc__},
@@ -6890,9 +6975,7 @@
 #ifdef HAVE_UNSETENV
 	{"unsetenv",	posix_unsetenv, METH_VARARGS, posix_unsetenv__doc__},
 #endif
-#ifdef HAVE_STRERROR
 	{"strerror",	posix_strerror, METH_VARARGS, posix_strerror__doc__},
-#endif
 #ifdef HAVE_FCHDIR
 	{"fchdir",	posix_fchdir, METH_O, posix_fchdir__doc__},
 #endif
@@ -6934,15 +7017,6 @@
 #if defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)
 	{"statvfs",	posix_statvfs, METH_VARARGS, posix_statvfs__doc__},
 #endif
-#ifdef HAVE_TMPFILE
-	{"tmpfile",	posix_tmpfile, METH_NOARGS, posix_tmpfile__doc__},
-#endif
-#ifdef HAVE_TEMPNAM
-	{"tempnam",	posix_tempnam, METH_VARARGS, posix_tempnam__doc__},
-#endif
-#ifdef HAVE_TMPNAM
-	{"tmpnam",	posix_tmpnam, METH_NOARGS, posix_tmpnam__doc__},
-#endif
 #ifdef HAVE_CONFSTR
 	{"confstr",	posix_confstr, METH_VARARGS, posix_confstr__doc__},
 #endif
@@ -7152,6 +7226,10 @@
         /* Do not follow links.	 */
         if (ins(d, "O_NOFOLLOW", (long)O_NOFOLLOW)) return -1;
 #endif
+#ifdef O_NOATIME
+	/* Do not update the access time. */
+	if (ins(d, "O_NOATIME", (long)O_NOATIME)) return -1;
+#endif
 
 	/* These come from sysexits.h */
 #ifdef EX_OK

Modified: python/branches/py3k-importlib/Modules/pwdmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/pwdmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/pwdmodule.c	Thu Mar 27 00:48:05 2008
@@ -48,8 +48,11 @@
 static void
 sets(PyObject *v, int i, const char* val)
 {
-  if (val)
-	  PyStructSequence_SET_ITEM(v, i, PyUnicode_FromString(val));
+  if (val) {
+	  PyObject *o =
+		PyUnicode_DecodeUnicodeEscape(val, strlen(val), "strict");
+	  PyStructSequence_SET_ITEM(v, i, o);
+  }
   else {
 	  PyStructSequence_SET_ITEM(v, i, Py_None);
 	  Py_INCREF(Py_None);
@@ -64,7 +67,7 @@
 	if (v == NULL)
 		return NULL;
 
-#define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val))
+#define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyLong_FromLong((long) val))
 #define SETS(i,val) sets(v, i, val)
 
 	SETS(setIndex++, p->pw_name);

Modified: python/branches/py3k-importlib/Modules/pyexpat.c
==============================================================================
--- python/branches/py3k-importlib/Modules/pyexpat.c	(original)
+++ python/branches/py3k-importlib/Modules/pyexpat.c	Thu Mar 27 00:48:05 2008
@@ -8,20 +8,6 @@
 
 #define XML_COMBINED_VERSION (10000*XML_MAJOR_VERSION+100*XML_MINOR_VERSION+XML_MICRO_VERSION)
 
-#ifndef PyDoc_STRVAR
-
-/*
- * fdrake says:
- * Don't change the PyDoc_STR macro definition to (str), because
- * '''the parentheses cause compile failures
- * ("non-constant static initializer" or something like that)
- * on some platforms (Irix?)'''
- */
-#define PyDoc_STR(str)         str
-#define PyDoc_VAR(name)        static char name[]
-#define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
-#endif
-
 #define FIX_TRACE
 
 enum HandlerTypes {
@@ -97,7 +83,7 @@
 static int
 set_error_attr(PyObject *err, char *name, int value)
 {
-    PyObject *v = PyInt_FromLong(value);
+    PyObject *v = PyLong_FromLong(value);
 
     if (v == NULL || PyObject_SetAttrString(err, name, v) == -1) {
         Py_XDECREF(v);
@@ -597,7 +583,7 @@
 
 #define INT_HANDLER(NAME, PARAMS, PARAM_FORMAT)\
 	RC_HANDLER(int, NAME, PARAMS, int rc=0;, PARAM_FORMAT, \
-			rc = PyInt_AsLong(rv);, rc, \
+			rc = PyLong_AsLong(rv);, rc, \
 	(xmlparseobject *)userData)
 
 VOID_HANDLER(EndElement,
@@ -798,7 +784,7 @@
                 ("(O&NNN)",
 		 conv_string_to_unicode ,context, string_intern(self, base),
 		 string_intern(self, systemId), string_intern(self, publicId)),
-		rc = PyInt_AsLong(rv);, rc,
+		rc = PyLong_AsLong(rv);, rc,
 		XML_GetUserData(parser))
 
 /* XXX UnknownEncodingHandler */
@@ -827,7 +813,7 @@
     if (flush_character_buffer(self) < 0) {
         return NULL;
     }
-    return PyInt_FromLong(rv);
+    return PyLong_FromLong(rv);
 }
 
 PyDoc_STRVAR(xmlparse_Parse__doc__,
@@ -858,8 +844,9 @@
     PyObject *bytes = NULL;
     PyObject *str = NULL;
     int len = -1;
+    char *ptr;
 
-    if ((bytes = PyInt_FromLong(buf_size)) == NULL)
+    if ((bytes = PyLong_FromLong(buf_size)) == NULL)
         goto finally;
 
     if ((arg = PyTuple_New(1)) == NULL) {
@@ -877,14 +864,17 @@
     if (str == NULL)
         goto finally;
 
-    /* XXX what to do if it returns a Unicode string? */
-    if (!PyBytes_Check(str)) {
+    if (PyString_Check(str))
+        ptr = PyString_AS_STRING(str);
+    else if (PyBytes_Check(str))
+        ptr = PyBytes_AS_STRING(str);
+    else {
         PyErr_Format(PyExc_TypeError,
                      "read() did not return a bytes object (type=%.400s)",
-                     Py_Type(str)->tp_name);
+                     Py_TYPE(str)->tp_name);
         goto finally;
     }
-    len = PyBytes_GET_SIZE(str);
+    len = Py_SIZE(str);
     if (len > buf_size) {
         PyErr_Format(PyExc_ValueError,
                      "read() returned too much data: "
@@ -892,7 +882,7 @@
                      buf_size, len);
         goto finally;
     }
-    memcpy(buf, PyBytes_AsString(str), len);
+    memcpy(buf, ptr, len);
 finally:
     Py_XDECREF(arg);
     Py_XDECREF(str);
@@ -998,7 +988,7 @@
             = XML_GetInputContext(self->itself, &offset, &size);
 
         if (buffer != NULL)
-            return PyBytes_FromStringAndSize(buffer + offset,
+            return PyString_FromStringAndSize(buffer + offset,
                                               size - offset);
         else
             Py_RETURN_NONE;
@@ -1113,7 +1103,7 @@
     if (!PyArg_ParseTuple(args, "i", &flag))
         return NULL;
     flag = XML_SetParamEntityParsing(p->itself, flag);
-    return PyInt_FromLong(flag);
+    return PyLong_FromLong(flag);
 }
 
 
@@ -1352,36 +1342,36 @@
     }
     if (name[0] == 'E') {
         if (strcmp(name, "ErrorCode") == 0)
-            return PyInt_FromLong((long)
+            return PyLong_FromLong((long)
                                   XML_GetErrorCode(self->itself));
         if (strcmp(name, "ErrorLineNumber") == 0)
-            return PyInt_FromLong((long)
+            return PyLong_FromLong((long)
                                   XML_GetErrorLineNumber(self->itself));
         if (strcmp(name, "ErrorColumnNumber") == 0)
-            return PyInt_FromLong((long)
+            return PyLong_FromLong((long)
                                   XML_GetErrorColumnNumber(self->itself));
         if (strcmp(name, "ErrorByteIndex") == 0)
-            return PyInt_FromLong((long)
+            return PyLong_FromLong((long)
                                   XML_GetErrorByteIndex(self->itself));
     }
     if (name[0] == 'C') {
         if (strcmp(name, "CurrentLineNumber") == 0)
-            return PyInt_FromLong((long)
+            return PyLong_FromLong((long)
                                   XML_GetCurrentLineNumber(self->itself));
         if (strcmp(name, "CurrentColumnNumber") == 0)
-            return PyInt_FromLong((long)
+            return PyLong_FromLong((long)
                                   XML_GetCurrentColumnNumber(self->itself));
         if (strcmp(name, "CurrentByteIndex") == 0)
-            return PyInt_FromLong((long)
+            return PyLong_FromLong((long)
                                   XML_GetCurrentByteIndex(self->itself));
     }
     if (name[0] == 'b') {
         if (strcmp(name, "buffer_size") == 0)
-            return PyInt_FromLong((long) self->buffer_size);
+            return PyLong_FromLong((long) self->buffer_size);
         if (strcmp(name, "buffer_text") == 0)
             return get_pybool(self->buffer != NULL);
         if (strcmp(name, "buffer_used") == 0)
-            return PyInt_FromLong((long) self->buffer_used);
+            return PyLong_FromLong((long) self->buffer_used);
     }
     if (strcmp(name, "namespace_prefixes") == 0)
         return get_pybool(self->ns_prefixes);
@@ -1534,6 +1524,50 @@
             self->specified_attributes = 0;
         return 0;
     }
+
+    if (strcmp(name, "buffer_size") == 0) {
+      long new_buffer_size;
+      if (!PyLong_Check(v)) {
+      	PyErr_SetString(PyExc_TypeError, "buffer_size must be an integer");
+      	return -1;
+      }
+
+      new_buffer_size=PyLong_AS_LONG(v);
+      /* trivial case -- no change */
+      if (new_buffer_size == self->buffer_size) {
+	return 0;
+      }
+
+      if (new_buffer_size <= 0) {
+	PyErr_SetString(PyExc_ValueError, "buffer_size must be greater than zero");
+	return -1;
+      }
+
+      /* check maximum */
+      if (new_buffer_size > INT_MAX) {
+	char errmsg[100];
+	sprintf(errmsg, "buffer_size must not be greater than %i", INT_MAX);
+	PyErr_SetString(PyExc_ValueError, errmsg);
+	return -1;	
+      }
+
+      if (self->buffer != NULL) {
+	/* there is already a buffer */
+	if (self->buffer_used != 0) {
+	  flush_character_buffer(self);
+	}
+	/* free existing buffer */
+	free(self->buffer);
+      }
+      self->buffer = malloc(new_buffer_size);
+      if (self->buffer == NULL) {
+	PyErr_NoMemory();
+	return -1;
+      }	  
+      self->buffer_size = new_buffer_size;
+      return 0;
+    }
+
     if (strcmp(name, "CharacterDataHandler") == 0) {
         /* If we're changing the character data handler, flush all
          * cached data with the old handler.  Not sure there's a
@@ -1570,7 +1604,8 @@
 PyDoc_STRVAR(Xmlparsetype__doc__, "XML parser");
 
 static PyMethodDef xmlparse_tp_methods[] = {
-    {"__dir__", xmlparse_dir, METH_NOARGS}
+    {"__dir__", xmlparse_dir, METH_NOARGS},
+    {NULL, NULL}    /* sentinel */
 };
 
 static PyTypeObject Xmlparsetype = {
@@ -1747,7 +1782,7 @@
     if (modelmod_name == NULL)
         return;
 
-    Py_Type(&Xmlparsetype) = &PyType_Type;
+    Py_TYPE(&Xmlparsetype) = &PyType_Type;
 
     /* Create the module and add the functions */
     m = Py_InitModule3(MODULE_NAME, pyexpat_methods,

Modified: python/branches/py3k-importlib/Modules/readline.c
==============================================================================
--- python/branches/py3k-importlib/Modules/readline.c	(original)
+++ python/branches/py3k-importlib/Modules/readline.c	Thu Mar 27 00:48:05 2008
@@ -38,6 +38,10 @@
 extern char **completion_matches(char *, rl_compentry_func_t *);
 #endif
 
+static void
+on_completion_display_matches_hook(char **matches,
+				   int num_matches, int max_length);
+
 
 /* Exported function to send one line to readline's init file parser */
 
@@ -55,8 +59,7 @@
 	strcpy(copy, s);
 	rl_parse_and_bind(copy);
 	free(copy); /* Free the copy */
-	Py_INCREF(Py_None);
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 PyDoc_STRVAR(doc_parse_and_bind,
@@ -75,8 +78,7 @@
 	errno = rl_read_init_file(s);
 	if (errno)
 		return PyErr_SetFromErrno(PyExc_IOError);
-	Py_INCREF(Py_None);
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 PyDoc_STRVAR(doc_read_init_file,
@@ -96,8 +98,7 @@
 	errno = read_history(s);
 	if (errno)
 		return PyErr_SetFromErrno(PyExc_IOError);
-	Py_INCREF(Py_None);
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 static int _history_length = -1; /* do not truncate history by default */
@@ -120,8 +121,7 @@
 		history_truncate_file(s, _history_length);
 	if (errno)
 		return PyErr_SetFromErrno(PyExc_IOError);
-	Py_INCREF(Py_None);
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 PyDoc_STRVAR(doc_write_history_file,
@@ -139,8 +139,7 @@
 	if (!PyArg_ParseTuple(args, "i:set_history_length", &length))
 		return NULL;
 	_history_length = length;
-	Py_INCREF(Py_None);
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 PyDoc_STRVAR(set_history_length_doc,
@@ -155,7 +154,7 @@
 static PyObject*
 get_history_length(PyObject *self, PyObject *noarg)
 {
-	return PyInt_FromLong(_history_length);
+	return PyLong_FromLong(_history_length);
 }
 
 PyDoc_STRVAR(get_history_length_doc,
@@ -191,8 +190,7 @@
 		PyErr_SetString(PyExc_TypeError, buf);
 		return NULL;
 	}
-	Py_INCREF(Py_None);
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 
@@ -208,8 +206,17 @@
 static PyObject *
 set_completion_display_matches_hook(PyObject *self, PyObject *args)
 {
-	return set_hook("completion_display_matches_hook",
+	PyObject *result = set_hook("completion_display_matches_hook",
 			&completion_display_matches_hook, args);
+#ifdef HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK
+	/* We cannot set this hook globally, since it replaces the
+	   default completion display. */
+	rl_completion_display_matches_hook =
+		completion_display_matches_hook ?
+		(rl_compdisp_func_t *)on_completion_display_matches_hook : 0;
+#endif
+	return result;
+
 }
 
 PyDoc_STRVAR(doc_set_completion_display_matches_hook,
@@ -264,7 +271,7 @@
 static PyObject *
 get_completion_type(PyObject *self, PyObject *noarg)
 {
-  return PyInt_FromLong(rl_completion_type);
+  return PyLong_FromLong(rl_completion_type);
 }
 
 PyDoc_STRVAR(doc_get_completion_type,
@@ -312,8 +319,7 @@
 	}
 	free((void*)rl_completer_word_break_characters);
 	rl_completer_word_break_characters = strdup(break_chars);
-	Py_INCREF(Py_None);
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 PyDoc_STRVAR(doc_set_completer_delims,
@@ -323,32 +329,31 @@
 static PyObject *
 py_remove_history(PyObject *self, PyObject *args)
 {
-        int entry_number;
-        HIST_ENTRY *entry;
+	int entry_number;
+	HIST_ENTRY *entry;
 
-        if (!PyArg_ParseTuple(args, "i:remove_history", &entry_number))
-                return NULL;
-        if (entry_number < 0) {
-                PyErr_SetString(PyExc_ValueError,
-                                "History index cannot be negative");
-                return NULL;
-        }
-        entry = remove_history(entry_number);
-        if (!entry) {
-                PyErr_Format(PyExc_ValueError,
-                             "No history item at position %d",
-                             entry_number);
-                return NULL;
-        }
-        /* free memory allocated for the history entry */
-        if (entry->line)
-                free(entry->line);
-        if (entry->data)
-                free(entry->data);
-        free(entry);
+	if (!PyArg_ParseTuple(args, "i:remove_history", &entry_number))
+		return NULL;
+	if (entry_number < 0) {
+		PyErr_SetString(PyExc_ValueError,
+				"History index cannot be negative");
+		return NULL;
+	}
+	entry = remove_history(entry_number);
+	if (!entry) {
+		PyErr_Format(PyExc_ValueError,
+			     "No history item at position %d",
+			      entry_number);
+		return NULL;
+	}
+	/* free memory allocated for the history entry */
+	if (entry->line)
+		free(entry->line);
+	if (entry->data)
+		free(entry->data);
+	free(entry);
 
-        Py_INCREF(Py_None);
-        return Py_None;
+	Py_RETURN_NONE;
 }
 
 PyDoc_STRVAR(doc_remove_history,
@@ -358,34 +363,34 @@
 static PyObject *
 py_replace_history(PyObject *self, PyObject *args)
 {
-        int entry_number;
-        char *line;
-        HIST_ENTRY *old_entry;
-
-        if (!PyArg_ParseTuple(args, "is:replace_history", &entry_number, &line)) {
-                return NULL;
-        }
-        if (entry_number < 0) {
-                PyErr_SetString(PyExc_ValueError,
-                                "History index cannot be negative");
-                return NULL;
-        }
-        old_entry = replace_history_entry(entry_number, line, (void *)NULL);
-        if (!old_entry) {
-                PyErr_Format(PyExc_ValueError,
-                             "No history item at position %d",
-                             entry_number);
-                return NULL;
-        }
-        /* free memory allocated for the old history entry */
-        if (old_entry->line)
-            free(old_entry->line);
-        if (old_entry->data)
-            free(old_entry->data);
-        free(old_entry);
+	int entry_number;
+	char *line;
+	HIST_ENTRY *old_entry;
+
+	if (!PyArg_ParseTuple(args, "is:replace_history", &entry_number,
+	      		      &line)) {
+		return NULL;
+	}
+	if (entry_number < 0) {
+		PyErr_SetString(PyExc_ValueError,
+				"History index cannot be negative");
+		return NULL;
+	}
+	old_entry = replace_history_entry(entry_number, line, (void *)NULL);
+	if (!old_entry) {
+		PyErr_Format(PyExc_ValueError,
+			     "No history item at position %d",
+			     entry_number);
+		return NULL;
+	}
+	/* free memory allocated for the old history entry */
+	if (old_entry->line)
+	    free(old_entry->line);
+	if (old_entry->data)
+	    free(old_entry->data);
+	free(old_entry);
 
-        Py_INCREF(Py_None);
-        return Py_None;
+	Py_RETURN_NONE;
 }
 
 PyDoc_STRVAR(doc_replace_history,
@@ -403,8 +408,7 @@
 		return NULL;
 	}
 	add_history(line);
-	Py_INCREF(Py_None);
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 PyDoc_STRVAR(doc_add_history,
@@ -417,7 +421,7 @@
 static PyObject *
 get_completer_delims(PyObject *self, PyObject *noarg)
 {
-	return PyString_FromString(rl_completer_word_break_characters);
+	return PyUnicode_FromString(rl_completer_word_break_characters);
 }
 
 PyDoc_STRVAR(doc_get_completer_delims,
@@ -445,8 +449,7 @@
 get_completer(PyObject *self, PyObject *noargs)
 {
 	if (completer == NULL) {
-		Py_INCREF(Py_None);
-		return Py_None;
+		Py_RETURN_NONE;
 	}
 	Py_INCREF(completer);
 	return completer;
@@ -468,10 +471,9 @@
 	if (!PyArg_ParseTuple(args, "i:index", &idx))
 		return NULL;
 	if ((hist_ent = history_get(idx)))
-		return PyString_FromString(hist_ent->line);
+		return PyUnicode_FromString(hist_ent->line);
 	else {
-		Py_INCREF(Py_None);
-		return Py_None;
+		Py_RETURN_NONE;
 	}
 }
 
@@ -488,7 +490,7 @@
 	HISTORY_STATE *hist_st;
 
 	hist_st = history_get_history_state();
-	return PyInt_FromLong(hist_st ? (long) hist_st->length : (long) 0);
+	return PyLong_FromLong(hist_st ? (long) hist_st->length : (long) 0);
 }
 
 PyDoc_STRVAR(doc_get_current_history_length,
@@ -501,7 +503,7 @@
 static PyObject *
 get_line_buffer(PyObject *self, PyObject *noarg)
 {
-	return PyString_FromString(rl_line_buffer);
+	return PyUnicode_FromString(rl_line_buffer);
 }
 
 PyDoc_STRVAR(doc_get_line_buffer,
@@ -517,8 +519,7 @@
 py_clear_history(PyObject *self, PyObject *noarg)
 {
 	clear_history();
-	Py_INCREF(Py_None);
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 PyDoc_STRVAR(doc_clear_history,
@@ -536,8 +537,7 @@
 	if (!PyArg_ParseTuple(args, "s:insert_text", &s))
 		return NULL;
 	rl_insert_text(s);
-	Py_INCREF(Py_None);
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 PyDoc_STRVAR(doc_insert_text,
@@ -551,8 +551,7 @@
 redisplay(PyObject *self, PyObject *noarg)
 {
 	rl_redisplay();
-	Py_INCREF(Py_None);
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 PyDoc_STRVAR(doc_redisplay,
@@ -578,9 +577,9 @@
 	 METH_VARARGS, doc_get_history_item},
 	{"get_current_history_length", (PyCFunction)get_current_history_length,
 	 METH_NOARGS, doc_get_current_history_length},
- 	{"set_history_length", set_history_length,
+	{"set_history_length", set_history_length,
 	 METH_VARARGS, set_history_length_doc},
- 	{"get_history_length", get_history_length,
+	{"get_history_length", get_history_length,
 	 METH_NOARGS, get_history_length_doc},
 	{"set_completer", set_completer, METH_VARARGS, doc_set_completer},
 	{"get_completer", get_completer, METH_NOARGS, doc_get_completer},
@@ -592,8 +591,8 @@
 	{"set_completer_delims", set_completer_delims,
 	 METH_VARARGS, doc_set_completer_delims},
 	{"add_history", py_add_history, METH_VARARGS, doc_add_history},
-        {"remove_history_item", py_remove_history, METH_VARARGS, doc_remove_history},
-        {"replace_history_item", py_replace_history, METH_VARARGS, doc_replace_history},
+	{"remove_history_item", py_remove_history, METH_VARARGS, doc_remove_history},
+	{"replace_history_item", py_replace_history, METH_VARARGS, doc_replace_history},
 	{"get_completer_delims", get_completer_delims,
 	 METH_NOARGS, doc_get_completer_delims},
 
@@ -620,7 +619,7 @@
 	int result = 0;
 	if (func != NULL) {
 		PyObject *r;
-#ifdef WITH_THREAD	      
+#ifdef WITH_THREAD
 		PyGILState_STATE gilstate = PyGILState_Ensure();
 #endif
 		r = PyObject_CallFunction(func, NULL);
@@ -629,7 +628,7 @@
 		if (r == Py_None)
 			result = 0;
 		else {
-			result = PyInt_AsLong(r);
+			result = PyLong_AsLong(r);
 			if (result == -1 && PyErr_Occurred()) 
 				goto error;
 		}
@@ -639,7 +638,7 @@
 		PyErr_Clear();
 		Py_XDECREF(r);
 	  done:
-#ifdef WITH_THREAD	      
+#ifdef WITH_THREAD
 		PyGILState_Release(gilstate);
 #endif
 		return result;
@@ -668,39 +667,41 @@
 on_completion_display_matches_hook(char **matches,
 				   int num_matches, int max_length)
 {
-	if (completion_display_matches_hook != NULL) {
-	        int i;
-	        PyObject *m, *s;
-	        PyObject *r;
-#ifdef WITH_THREAD	      
-		PyGILState_STATE gilstate = PyGILState_Ensure();
+	int i;
+	PyObject *m=NULL, *s=NULL, *r=NULL;
+#ifdef WITH_THREAD
+	PyGILState_STATE gilstate = PyGILState_Ensure();
 #endif
-		m = PyList_New(num_matches);
-		for (i = 0; i < num_matches; i++) {
-		  s = PyString_FromString(matches[i+1]);
-		  PyList_SetItem(m, i, s);
-		}
-
-		r = PyObject_CallFunction(completion_display_matches_hook,
-					  "sOi", matches[0], m, max_length);
-
-		Py_DECREF(m);
+	m = PyList_New(num_matches);
+	if (m == NULL)
+		goto error;
+	for (i = 0; i < num_matches; i++) {
+		s = PyUnicode_FromString(matches[i+1]);
+		if (s == NULL)
+			goto error;
+		if (PyList_SetItem(m, i, s) == -1)
+			goto error;
+	}
+	r = PyObject_CallFunction(completion_display_matches_hook,
+				  "sOi", matches[0], m, max_length);
 
-		if (r == NULL ||
-		    (r != Py_None && PyInt_AsLong(r) == -1 && PyErr_Occurred())) {
-		  goto error;
-		}
+	Py_DECREF(m), m=NULL;
+	
+	if (r == NULL ||
+		(r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+		goto error;
+	}
+	Py_XDECREF(r), r=NULL;
 
-		Py_DECREF(r);
-		goto done;
-	  error:
+	if (0) {
+	error:
 		PyErr_Clear();
+		Py_XDECREF(m);
 		Py_XDECREF(r);
-	  done:
-#ifdef WITH_THREAD	      
-		PyGILState_Release(gilstate);
-#endif
 	}
+#ifdef WITH_THREAD
+	PyGILState_Release(gilstate);
+#endif
 }
 
 
@@ -712,7 +713,7 @@
 	char *result = NULL;
 	if (completer != NULL) {
 		PyObject *r;
-#ifdef WITH_THREAD	      
+#ifdef WITH_THREAD
 		PyGILState_STATE gilstate = PyGILState_Ensure();
 #endif
 		rl_attempted_completion_over = 1;
@@ -723,7 +724,7 @@
 			result = NULL;
 		}
 		else {
-			char *s = PyString_AsString(r);
+			char *s = PyUnicode_AsString(r);
 			if (s == NULL)
 				goto error;
 			result = strdup(s);
@@ -734,7 +735,7 @@
 		PyErr_Clear();
 		Py_XDECREF(r);
 	  done:
-#ifdef WITH_THREAD	      
+#ifdef WITH_THREAD
 		PyGILState_Release(gilstate);
 #endif
 		return result;
@@ -751,8 +752,8 @@
 {
 	Py_XDECREF(begidx);
 	Py_XDECREF(endidx);
-	begidx = PyInt_FromLong((long) start);
-	endidx = PyInt_FromLong((long) end);
+	begidx = PyLong_FromLong((long) start);
+	endidx = PyLong_FromLong((long) end);
 	return completion_matches(text, *on_completion);
 }
 
@@ -781,10 +782,6 @@
 	rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
 	rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
 	/* Set our hook functions */
-#ifdef HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK
-	rl_completion_display_matches_hook =
-	  (rl_compdisp_func_t *)on_completion_display_matches_hook;
-#endif
 	rl_startup_hook = (Function *)on_startup_hook;
 #ifdef HAVE_RL_PRE_INPUT_HOOK
 	rl_pre_input_hook = (Function *)on_pre_input_hook;
@@ -799,8 +796,8 @@
 	rl_completion_append_character ='\0';
 #endif
 
-	begidx = PyInt_FromLong(0L);
-	endidx = PyInt_FromLong(0L);
+	begidx = PyLong_FromLong(0L);
+	endidx = PyLong_FromLong(0L);
 	/* Initialize (allows .inputrc to override)
 	 *
 	 * XXX: A bug in the readline-2.2 library causes a memory leak

Modified: python/branches/py3k-importlib/Modules/resource.c
==============================================================================
--- python/branches/py3k-importlib/Modules/resource.c	(original)
+++ python/branches/py3k-importlib/Modules/resource.c	Thu Mar 27 00:48:05 2008
@@ -86,20 +86,20 @@
 			PyFloat_FromDouble(doubletime(ru.ru_utime)));
 	PyStructSequence_SET_ITEM(result, 1,
 			PyFloat_FromDouble(doubletime(ru.ru_stime)));
-	PyStructSequence_SET_ITEM(result, 2, PyInt_FromLong(ru.ru_maxrss));
-	PyStructSequence_SET_ITEM(result, 3, PyInt_FromLong(ru.ru_ixrss));
-	PyStructSequence_SET_ITEM(result, 4, PyInt_FromLong(ru.ru_idrss));
-	PyStructSequence_SET_ITEM(result, 5, PyInt_FromLong(ru.ru_isrss));
-	PyStructSequence_SET_ITEM(result, 6, PyInt_FromLong(ru.ru_minflt));
-	PyStructSequence_SET_ITEM(result, 7, PyInt_FromLong(ru.ru_majflt));
-	PyStructSequence_SET_ITEM(result, 8, PyInt_FromLong(ru.ru_nswap));
-	PyStructSequence_SET_ITEM(result, 9, PyInt_FromLong(ru.ru_inblock));
-	PyStructSequence_SET_ITEM(result, 10, PyInt_FromLong(ru.ru_oublock));
-	PyStructSequence_SET_ITEM(result, 11, PyInt_FromLong(ru.ru_msgsnd));
-	PyStructSequence_SET_ITEM(result, 12, PyInt_FromLong(ru.ru_msgrcv));
-	PyStructSequence_SET_ITEM(result, 13, PyInt_FromLong(ru.ru_nsignals));
-	PyStructSequence_SET_ITEM(result, 14, PyInt_FromLong(ru.ru_nvcsw));
-	PyStructSequence_SET_ITEM(result, 15, PyInt_FromLong(ru.ru_nivcsw));
+	PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong(ru.ru_maxrss));
+	PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong(ru.ru_ixrss));
+	PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong(ru.ru_idrss));
+	PyStructSequence_SET_ITEM(result, 5, PyLong_FromLong(ru.ru_isrss));
+	PyStructSequence_SET_ITEM(result, 6, PyLong_FromLong(ru.ru_minflt));
+	PyStructSequence_SET_ITEM(result, 7, PyLong_FromLong(ru.ru_majflt));
+	PyStructSequence_SET_ITEM(result, 8, PyLong_FromLong(ru.ru_nswap));
+	PyStructSequence_SET_ITEM(result, 9, PyLong_FromLong(ru.ru_inblock));
+	PyStructSequence_SET_ITEM(result, 10, PyLong_FromLong(ru.ru_oublock));
+	PyStructSequence_SET_ITEM(result, 11, PyLong_FromLong(ru.ru_msgsnd));
+	PyStructSequence_SET_ITEM(result, 12, PyLong_FromLong(ru.ru_msgrcv));
+	PyStructSequence_SET_ITEM(result, 13, PyLong_FromLong(ru.ru_nsignals));
+	PyStructSequence_SET_ITEM(result, 14, PyLong_FromLong(ru.ru_nvcsw));
+	PyStructSequence_SET_ITEM(result, 15, PyLong_FromLong(ru.ru_nivcsw));
 
 	if (PyErr_Occurred()) {
 		Py_DECREF(result);
@@ -158,20 +158,20 @@
 	}
 
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-	rl.rlim_cur = PyInt_AsLong(curobj);
+	rl.rlim_cur = PyLong_AsLong(curobj);
 	if (rl.rlim_cur == -1 && PyErr_Occurred())
 	    return NULL;
-	rl.rlim_max = PyInt_AsLong(maxobj);
+	rl.rlim_max = PyLong_AsLong(maxobj);
 	if (rl.rlim_max == -1 && PyErr_Occurred())
 	    return NULL;
 #else
 	/* The limits are probably bigger than a long */
 	rl.rlim_cur = PyLong_Check(curobj) ?
-		PyLong_AsLongLong(curobj) : PyInt_AsLong(curobj);
+		PyLong_AsLongLong(curobj) : PyLong_AsLong(curobj);
 	if (rl.rlim_cur == -1 && PyErr_Occurred())
 	    return NULL;
 	rl.rlim_max = PyLong_Check(maxobj) ?
-		PyLong_AsLongLong(maxobj) : PyInt_AsLong(maxobj);
+		PyLong_AsLongLong(maxobj) : PyLong_AsLong(maxobj);
 	if (rl.rlim_max == -1 && PyErr_Occurred())
 	    return NULL;
 #endif
@@ -320,7 +320,7 @@
 	} else 
 #endif
 	{
-		v = PyInt_FromLong((long) RLIM_INFINITY);
+		v = PyLong_FromLong((long) RLIM_INFINITY);
 	}
 	if (v) {
 		PyModule_AddObject(m, "RLIM_INFINITY", v);

Modified: python/branches/py3k-importlib/Modules/selectmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/selectmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/selectmodule.c	Thu Mar 27 00:48:05 2008
@@ -5,6 +5,7 @@
 */
 
 #include "Python.h"
+#include <structmember.h>
 
 #ifdef __APPLE__
     /* Perform runtime testing for a broken poll on OSX to make it easier
@@ -44,6 +45,7 @@
 #endif
 
 #ifdef MS_WINDOWS
+#  define WIN32_LEAN_AND_MEAN
 #  include <winsock.h>
 #else
 #  define SOCKET int
@@ -52,7 +54,6 @@
 #  endif
 #endif
 
-
 static PyObject *SelectError;
 
 /* list of Python objects and their file descriptor */
@@ -237,7 +238,7 @@
 		seconds = (long)timeout;
 		timeout = timeout - (double)seconds;
 		tv.tv_sec = seconds;
-		tv.tv_usec = (long)(timeout*1000000.0);
+		tv.tv_usec = (long)(timeout * 1E6);
 		tvp = &tv;
 	}
 
@@ -355,8 +356,8 @@
 
 	i = pos = 0;
 	while (PyDict_Next(self->dict, &pos, &key, &value)) {
-		self->ufds[i].fd = PyInt_AsLong(key);
-		self->ufds[i].events = (short)PyInt_AsLong(value);
+		self->ufds[i].fd = PyLong_AsLong(key);
+		self->ufds[i].events = (short)PyLong_AsLong(value);
 		i++;
 	}
 	self->ufd_uptodate = 1;
@@ -386,10 +387,10 @@
 
 	/* Add entry to the internal dictionary: the key is the 
 	   file descriptor, and the value is the event mask. */
-	key = PyInt_FromLong(fd);
+	key = PyLong_FromLong(fd);
 	if (key == NULL)
 		return NULL;
-	value = PyInt_FromLong(events);
+	value = PyLong_FromLong(events);
 	if (value == NULL) {
 		Py_DECREF(key);
 		return NULL;
@@ -401,11 +402,59 @@
 		return NULL;
 
 	self->ufd_uptodate = 0;
-		       
+
 	Py_INCREF(Py_None);
 	return Py_None;
 }
 
+PyDoc_STRVAR(poll_modify_doc,
+"modify(fd, eventmask) -> None\n\n\
+Modify an already register file descriptor.\n\
+fd -- either an integer, or an object with a fileno() method returning an\n\
+      int.\n\
+events -- an optional bitmask describing the type of events to check for");
+
+static PyObject *
+poll_modify(pollObject *self, PyObject *args)
+{
+	PyObject *o, *key, *value;
+	int fd, events;
+	int err;
+
+	if (!PyArg_ParseTuple(args, "Oi:modify", &o, &events)) {
+		return NULL;
+	}
+  
+	fd = PyObject_AsFileDescriptor(o);
+	if (fd == -1) return NULL;
+
+	/* Modify registered fd */
+	key = PyLong_FromLong(fd);
+	if (key == NULL)
+		return NULL;
+	if (PyDict_GetItem(self->dict, key) == NULL) {
+		errno = ENOENT;
+		PyErr_SetFromErrno(PyExc_IOError);
+		return NULL;
+	}
+	value = PyLong_FromLong(events);
+	if (value == NULL) {
+		Py_DECREF(key);
+		return NULL;
+	}
+	err = PyDict_SetItem(self->dict, key, value);
+	Py_DECREF(key);
+	Py_DECREF(value);
+	if (err < 0)
+		return NULL;
+
+	self->ufd_uptodate = 0;
+
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+
 PyDoc_STRVAR(poll_unregister_doc,
 "unregister(fd) -> None\n\n\
 Remove a file descriptor being tracked by the polling object.");
@@ -421,7 +470,7 @@
 		return NULL;
 
 	/* Check whether the fd is already in the array */
-	key = PyInt_FromLong(fd);
+	key = PyLong_FromLong(fd);
 	if (key == NULL) 
 		return NULL;
 
@@ -467,7 +516,7 @@
 		tout = PyNumber_Int(tout);
 		if (!tout)
 			return NULL;
-		timeout = PyInt_AsLong(tout);
+		timeout = PyLong_AsLong(tout);
 		Py_DECREF(tout);
 		if (timeout == -1 && PyErr_Occurred())
 			return NULL;
@@ -479,9 +528,9 @@
 			return NULL;
 
 	/* call poll() */
-	Py_BEGIN_ALLOW_THREADS;
+	Py_BEGIN_ALLOW_THREADS
 	poll_result = poll(self->ufds, self->ufd_len, timeout);
-	Py_END_ALLOW_THREADS;
+	Py_END_ALLOW_THREADS
  
 	if (poll_result < 0) {
 		PyErr_SetFromErrno(SelectError);
@@ -505,7 +554,7 @@
 			value = PyTuple_New(2);
 			if (value == NULL)
 				goto error;
-			num = PyInt_FromLong(self->ufds[i].fd);
+			num = PyLong_FromLong(self->ufds[i].fd);
 			if (num == NULL) {
 				Py_DECREF(value);
 				goto error;
@@ -516,7 +565,7 @@
 			   is a 16-bit short, and IBM assigned POLLNVAL
 			   to be 0x8000, so the conversion to int results
 			   in a negative number. See SF bug #923315. */
-			num = PyInt_FromLong(self->ufds[i].revents & 0xffff);
+			num = PyLong_FromLong(self->ufds[i].revents & 0xffff);
 			if (num == NULL) {
 				Py_DECREF(value);
 				goto error;
@@ -539,7 +588,9 @@
 static PyMethodDef poll_methods[] = {
 	{"register",	(PyCFunction)poll_register,	
 	 METH_VARARGS,  poll_register_doc},
-	{"unregister",	(PyCFunction)poll_unregister,	
+	{"modify",	(PyCFunction)poll_modify,
+	 METH_VARARGS,  poll_modify_doc},
+	{"unregister",	(PyCFunction)poll_unregister,
 	 METH_O,        poll_unregister_doc},
 	{"poll",	(PyCFunction)poll_poll,	
 	 METH_VARARGS,  poll_poll_doc},
@@ -642,6 +693,1007 @@
 
 #endif /* HAVE_POLL */
 
+#ifdef HAVE_EPOLL
+/* **************************************************************************
+ *                      epoll interface for Linux 2.6
+ *
+ * Written by Christian Heimes
+ * Inspired by Twisted's _epoll.pyx and select.poll()
+ */
+
+#ifdef HAVE_SYS_EPOLL_H
+#include <sys/epoll.h>
+#endif
+
+typedef struct {
+	PyObject_HEAD
+	SOCKET epfd;			/* epoll control file descriptor */
+} pyEpoll_Object;
+
+static PyTypeObject pyEpoll_Type;
+#define pyepoll_CHECK(op) (PyObject_TypeCheck((op), &pyEpoll_Type))
+
+static PyObject *
+pyepoll_err_closed(void)
+{
+	PyErr_SetString(PyExc_ValueError, "I/O operation on closed epoll fd");
+	return NULL;
+}
+
+static int
+pyepoll_internal_close(pyEpoll_Object *self)
+{
+	int save_errno = 0;
+	if (self->epfd >= 0) {
+		int epfd = self->epfd;
+		self->epfd = -1;
+		Py_BEGIN_ALLOW_THREADS
+		if (close(epfd) < 0)
+			save_errno = errno;
+		Py_END_ALLOW_THREADS
+	}
+	return save_errno;
+}
+
+static PyObject *
+newPyEpoll_Object(PyTypeObject *type, int sizehint, SOCKET fd)
+{
+	pyEpoll_Object *self;
+	
+	if (sizehint == -1) {
+		sizehint = FD_SETSIZE-1;
+	}
+	else if (sizehint < 1) {
+		PyErr_Format(PyExc_ValueError,
+			     "sizehint must be greater zero, got %d",
+			     sizehint);
+		return NULL;
+	}
+
+	assert(type != NULL && type->tp_alloc != NULL);
+	self = (pyEpoll_Object *) type->tp_alloc(type, 0);
+	if (self == NULL)
+		return NULL;
+
+	if (fd == -1) {
+		Py_BEGIN_ALLOW_THREADS
+		self->epfd = epoll_create(sizehint);
+		Py_END_ALLOW_THREADS
+	}
+	else {
+		self->epfd = fd;
+	}
+	if (self->epfd < 0) {
+		Py_DECREF(self);
+		PyErr_SetFromErrno(PyExc_IOError);
+		return NULL;
+	}
+	return (PyObject *)self;
+}
+
+
+static PyObject *
+pyepoll_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+	int sizehint = -1;
+	static char *kwlist[] = {"sizehint", NULL};
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:epoll", kwlist,
+					 &sizehint))
+		return NULL;
+
+	return newPyEpoll_Object(type, sizehint, -1);
+}
+
+
+static void
+pyepoll_dealloc(pyEpoll_Object *self)
+{
+	(void)pyepoll_internal_close(self);
+	Py_TYPE(self)->tp_free(self);
+}
+
+static PyObject*
+pyepoll_close(pyEpoll_Object *self)
+{
+	errno = pyepoll_internal_close(self);
+	if (errno < 0) {
+		PyErr_SetFromErrno(PyExc_IOError);
+		return NULL;
+	}
+	Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(pyepoll_close_doc,
+"close() -> None\n\
+\n\
+Close the epoll control file descriptor. Further operations on the epoll\n\
+object will raise an exception.");
+
+static PyObject*
+pyepoll_get_closed(pyEpoll_Object *self)
+{
+	if (self->epfd < 0)
+		Py_RETURN_TRUE;
+	else
+		Py_RETURN_FALSE;
+}
+
+static PyObject*
+pyepoll_fileno(pyEpoll_Object *self)
+{
+	if (self->epfd < 0)
+		return pyepoll_err_closed();
+	return PyLong_FromLong(self->epfd);
+}
+
+PyDoc_STRVAR(pyepoll_fileno_doc,
+"fileno() -> int\n\
+\n\
+Return the epoll control file descriptor.");
+
+static PyObject*
+pyepoll_fromfd(PyObject *cls, PyObject *args)
+{
+	SOCKET fd;
+
+	if (!PyArg_ParseTuple(args, "i:fromfd", &fd))
+		return NULL;
+
+	return newPyEpoll_Object((PyTypeObject*)cls, -1, fd);
+}
+
+PyDoc_STRVAR(pyepoll_fromfd_doc,
+"fromfd(fd) -> epoll\n\
+\n\
+Create an epoll object from a given control fd.");
+
+static PyObject *
+pyepoll_internal_ctl(int epfd, int op, PyObject *pfd, unsigned int events)
+{
+	struct epoll_event ev;
+	int result;
+	int fd;
+
+	if (epfd < 0)
+		return pyepoll_err_closed();
+
+	fd = PyObject_AsFileDescriptor(pfd);
+	if (fd == -1) {
+		return NULL;
+	}
+
+	switch(op) {
+	    case EPOLL_CTL_ADD:
+	    case EPOLL_CTL_MOD:
+		ev.events = events;
+		ev.data.fd = fd;
+		Py_BEGIN_ALLOW_THREADS
+		result = epoll_ctl(epfd, op, fd, &ev);
+		Py_END_ALLOW_THREADS
+		break;
+	    case EPOLL_CTL_DEL:
+		/* In kernel versions before 2.6.9, the EPOLL_CTL_DEL
+		 * operation required a non-NULL pointer in event, even
+		 * though this argument is ignored. */
+		Py_BEGIN_ALLOW_THREADS
+		result = epoll_ctl(epfd, op, fd, &ev);
+		if (errno == EBADF) {
+			/* fd already closed */
+			result = 0;
+			errno = 0;
+		}
+		Py_END_ALLOW_THREADS
+		break;
+	    default:
+		result = -1;
+		errno = EINVAL;
+	}
+
+	if (result < 0) {
+		PyErr_SetFromErrno(PyExc_IOError);
+		return NULL;
+	}
+	Py_RETURN_NONE;
+}
+
+static PyObject *
+pyepoll_register(pyEpoll_Object *self, PyObject *args, PyObject *kwds)
+{
+	PyObject *pfd;
+	unsigned int events = EPOLLIN | EPOLLOUT | EPOLLPRI;
+	static char *kwlist[] = {"fd", "eventmask", NULL};
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|I:register", kwlist,
+					 &pfd, &events)) {
+		return NULL;
+	}
+
+	return pyepoll_internal_ctl(self->epfd, EPOLL_CTL_ADD, pfd, events);
+}
+
+PyDoc_STRVAR(pyepoll_register_doc,
+"register(fd[, eventmask]) -> bool\n\
+\n\
+Registers a new fd or modifies an already registered fd. register returns\n\
+True if a new fd was registered or False if the event mask for fd was modified.\n\
+fd is the target file descriptor of the operation\n\
+events is a bit set composed of the various EPOLL constants, the default\n\
+is EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\
+\n\
+The epoll interface supports all file descriptors that support poll.");
+
+static PyObject *
+pyepoll_modify(pyEpoll_Object *self, PyObject *args, PyObject *kwds)
+{
+	PyObject *pfd;
+	unsigned int events;
+	static char *kwlist[] = {"fd", "eventmask", NULL};
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "OI:modify", kwlist,
+					 &pfd, &events)) {
+		return NULL;
+	}
+
+	return pyepoll_internal_ctl(self->epfd, EPOLL_CTL_MOD, pfd, events);
+}
+
+PyDoc_STRVAR(pyepoll_modify_doc,
+"modify(fd, eventmask) -> None\n\
+\n\
+fd is the target file descriptor of the operation\n\
+events is a bit set composed of the various EPOLL constants");
+
+static PyObject *
+pyepoll_unregister(pyEpoll_Object *self, PyObject *args, PyObject *kwds)
+{
+	PyObject *pfd;
+	static char *kwlist[] = {"fd", NULL};
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:unregister", kwlist,
+					 &pfd)) {
+		return NULL;
+	}
+
+	return pyepoll_internal_ctl(self->epfd, EPOLL_CTL_DEL, pfd, 0);
+}
+
+PyDoc_STRVAR(pyepoll_unregister_doc,
+"unregister(fd) -> None\n\
+\n\
+fd is the target file descriptor of the operation.");
+
+static PyObject *
+pyepoll_poll(pyEpoll_Object *self, PyObject *args, PyObject *kwds)
+{
+	double dtimeout = -1.;
+	int timeout;
+	int maxevents = -1;
+	int nfds, i;
+	PyObject *elist = NULL, *etuple = NULL;
+	struct epoll_event *evs = NULL;
+	static char *kwlist[] = {"timeout", "maxevents", NULL};
+
+	if (self->epfd < 0)
+		return pyepoll_err_closed();
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|di:poll", kwlist,
+					 &dtimeout, &maxevents)) {
+		return NULL;
+	}
+
+	if (dtimeout < 0) {
+		timeout = -1;
+	}
+	else if (dtimeout * 1000.0 > INT_MAX) {
+		PyErr_SetString(PyExc_OverflowError,
+				"timeout is too large");
+	}
+	else {
+		timeout = (int)(dtimeout * 1000.0);
+	}
+
+	if (maxevents == -1) {
+		maxevents = FD_SETSIZE-1;
+	}
+	else if (maxevents < 1) {
+		PyErr_Format(PyExc_ValueError,
+			     "maxevents must be greater than 0, got %d",
+			     maxevents);
+		return NULL;
+	}
+
+	evs = PyMem_New(struct epoll_event, maxevents);
+	if (evs == NULL) {
+		Py_DECREF(self);
+		PyErr_NoMemory();
+		return NULL;
+	}
+
+	Py_BEGIN_ALLOW_THREADS
+	nfds = epoll_wait(self->epfd, evs, maxevents, timeout);
+	Py_END_ALLOW_THREADS
+	if (nfds < 0) {
+		PyErr_SetFromErrno(PyExc_IOError);
+		goto error;
+	}
+
+	elist = PyList_New(nfds);
+	if (elist == NULL) {
+		goto error;
+	}
+
+	for (i = 0; i < nfds; i++) {
+		etuple = Py_BuildValue("iI", evs[i].data.fd,
+				       evs[i].events);
+		if (etuple == NULL) {
+			goto error;
+		}
+		PyList_SET_ITEM(elist, i, etuple);
+	}
+
+	if (0) {
+	    error:
+		Py_CLEAR(elist);
+		Py_XDECREF(etuple);
+	}
+	PyMem_Free(evs);
+	return elist;
+}
+
+PyDoc_STRVAR(pyepoll_poll_doc,
+"poll([timeout=-1[, maxevents=-1]]) -> [(fd, events), (...)]\n\
+\n\
+Wait for events on the epoll file descriptor for a maximum time of timeout\n\
+in seconds (as float). -1 makes poll wait indefinitely.\n\
+Up to maxevents are returned to the caller.");
+
+static PyMethodDef pyepoll_methods[] = {
+	{"fromfd",	(PyCFunction)pyepoll_fromfd,
+	 METH_VARARGS | METH_CLASS, pyepoll_fromfd_doc},
+	{"close",	(PyCFunction)pyepoll_close,	METH_NOARGS,
+	 pyepoll_close_doc},
+	{"fileno",	(PyCFunction)pyepoll_fileno,	METH_NOARGS,
+	 pyepoll_fileno_doc},
+	{"modify",	(PyCFunction)pyepoll_modify,
+	 METH_VARARGS | METH_KEYWORDS,	pyepoll_modify_doc},
+	{"register",	(PyCFunction)pyepoll_register,
+	 METH_VARARGS | METH_KEYWORDS,	pyepoll_register_doc},
+	{"unregister",	(PyCFunction)pyepoll_unregister,
+	 METH_VARARGS | METH_KEYWORDS,	pyepoll_unregister_doc},
+	{"poll",	(PyCFunction)pyepoll_poll,
+	 METH_VARARGS | METH_KEYWORDS,	pyepoll_poll_doc},
+	{NULL,	NULL},
+};
+
+static PyGetSetDef pyepoll_getsetlist[] = {
+	{"closed", (getter)pyepoll_get_closed, NULL,
+	 "True if the epoll handler is closed"},
+	{0},
+};
+
+PyDoc_STRVAR(pyepoll_doc,
+"select.epoll([sizehint=-1])\n\
+\n\
+Returns an epolling object\n\
+\n\
+sizehint must be a positive integer or -1 for the default size. The\n\
+sizehint is used to optimize internal data structures. It doesn't limit\n\
+the maximum number of monitored events.");
+
+static PyTypeObject pyEpoll_Type = {
+	PyVarObject_HEAD_INIT(NULL, 0)
+	"select.epoll",					/* tp_name */
+	sizeof(pyEpoll_Object),				/* tp_basicsize */
+	0,						/* tp_itemsize */
+	(destructor)pyepoll_dealloc,			/* tp_dealloc */
+	0,						/* tp_print */
+	0,						/* tp_getattr */
+	0,						/* tp_setattr */
+	0,						/* tp_compare */
+	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,				/* tp_flags */
+	pyepoll_doc,					/* tp_doc */
+	0,						/* tp_traverse */
+	0,						/* tp_clear */
+	0,						/* tp_richcompare */
+	0,						/* tp_weaklistoffset */
+	0,						/* tp_iter */
+	0,						/* tp_iternext */
+	pyepoll_methods,				/* tp_methods */
+	0,						/* tp_members */
+	pyepoll_getsetlist,				/* 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 */
+	pyepoll_new,					/* tp_new */
+	0,						/* tp_free */
+};
+
+#endif /* HAVE_EPOLL */
+
+#ifdef HAVE_KQUEUE
+/* **************************************************************************
+ *                      kqueue interface for BSD
+ *
+ * Copyright (c) 2000 Doug White, 2006 James Knight, 2007 Christian Heimes
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_SYS_EVENT_H
+#include <sys/event.h>
+#endif
+
+PyDoc_STRVAR(kqueue_event_doc,
+"kevent(ident, filter=KQ_FILTER_READ, flags=KQ_ADD, fflags=0, data=0, udata=0)\n\
+\n\
+This object is the equivalent of the struct kevent for the C API.\n\
+\n\
+See the kqueue manpage for more detailed information about the meaning\n\
+of the arguments.\n\
+\n\
+One minor note: while you might hope that udata could store a\n\
+reference to a python object, it cannot, because it is impossible to\n\
+keep a proper reference count of the object once it's passed into the\n\
+kernel. Therefore, I have restricted it to only storing an integer.  I\n\
+recommend ignoring it and simply using the 'ident' field to key off\n\
+of. You could also set up a dictionary on the python side to store a\n\
+udata->object mapping.");
+
+typedef struct {
+	PyObject_HEAD
+	struct kevent e;
+} kqueue_event_Object;
+
+static PyTypeObject kqueue_event_Type;
+
+#define kqueue_event_Check(op) (PyObject_TypeCheck((op), &kqueue_event_Type))
+
+typedef struct {
+	PyObject_HEAD
+	SOCKET kqfd;		/* kqueue control fd */
+} kqueue_queue_Object;
+
+static PyTypeObject kqueue_queue_Type;
+
+#define kqueue_queue_Check(op) (PyObject_TypeCheck((op), &kqueue_queue_Type))
+
+/* Unfortunately, we can't store python objects in udata, because
+ * kevents in the kernel can be removed without warning, which would
+ * forever lose the refcount on the object stored with it.
+ */
+
+#define KQ_OFF(x) offsetof(kqueue_event_Object, x)
+static struct PyMemberDef kqueue_event_members[] = {
+	{"ident",	T_UINT,		KQ_OFF(e.ident)},
+	{"filter",	T_SHORT,	KQ_OFF(e.filter)},
+	{"flags",	T_USHORT,	KQ_OFF(e.flags)},
+	{"fflags",	T_UINT,		KQ_OFF(e.fflags)},
+	{"data",	T_INT,		KQ_OFF(e.data)},
+	{"udata",	T_INT,		KQ_OFF(e.udata)},
+	{NULL} /* Sentinel */
+};
+#undef KQ_OFF
+
+static PyObject *
+kqueue_event_repr(kqueue_event_Object *s)
+{
+	char buf[1024];
+	PyOS_snprintf(
+		buf, sizeof(buf),
+		"<select.kevent ident=%lu filter=%d flags=0x%x fflags=0x%x "
+		"data=0x%lx udata=%p>",
+		(unsigned long)(s->e.ident), s->e.filter, s->e.flags,
+		s->e.fflags, (long)(s->e.data), s->e.udata);
+	return PyString_FromString(buf);
+}
+
+static int
+kqueue_event_init(kqueue_event_Object *self, PyObject *args, PyObject *kwds)
+{
+	PyObject *pfd;
+	static char *kwlist[] = {"ident", "filter", "flags", "fflags",
+				 "data", "udata", NULL};
+
+	EV_SET(&(self->e), 0, EVFILT_READ, EV_ADD, 0, 0, 0); /* defaults */
+	
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|hhiii:kevent", kwlist,
+		&pfd, &(self->e.filter), &(self->e.flags),
+		&(self->e.fflags), &(self->e.data), &(self->e.udata))) {
+		return -1;
+	}
+
+	self->e.ident = PyObject_AsFileDescriptor(pfd);
+	if (self->e.ident == -1) {
+		return -1;
+	}
+	return 0;
+}
+
+static PyObject *
+kqueue_event_richcompare(kqueue_event_Object *s, kqueue_event_Object *o,
+			 int op)
+{
+	int result = 0;
+
+	if (!kqueue_event_Check(o)) {
+		if (op == Py_EQ || op == Py_NE) {
+                	PyObject *res = op == Py_EQ ? Py_False : Py_True;
+			Py_INCREF(res);
+			return res;
+		}
+		PyErr_Format(PyExc_TypeError,
+			"can't compare %.200s to %.200s",
+			Py_TYPE(s)->tp_name, Py_TYPE(o)->tp_name);
+		return NULL;
+	}
+	if (((result = s->e.ident - o->e.ident) == 0) &&
+	    ((result = s->e.filter - o->e.filter) == 0) &&
+	    ((result = s->e.flags - o->e.flags) == 0) &&
+	    ((result = s->e.fflags - o->e.fflags) == 0) &&
+	    ((result = s->e.data - o->e.data) == 0) &&
+	    ((result = s->e.udata - o->e.udata) == 0)
+	   ) {
+		result = 0;
+	}
+
+	switch (op) {
+	    case Py_EQ:
+		result = (result == 0);
+		break;
+	    case Py_NE:
+		result = (result != 0);
+		break;
+	    case Py_LE:
+		result = (result <= 0);
+		break;
+	    case Py_GE:
+		result = (result >= 0);
+		break;
+	    case Py_LT:
+		result = (result < 0);
+		break;
+	    case Py_GT:
+		result = (result > 0);
+		break;
+	}
+	return PyBool_FromLong(result);
+}
+
+static PyTypeObject kqueue_event_Type = {
+	PyVarObject_HEAD_INIT(NULL, 0)
+	"select.kevent",				/* tp_name */
+	sizeof(kqueue_event_Object),			/* tp_basicsize */
+	0,						/* tp_itemsize */
+	0,						/* tp_dealloc */
+	0,						/* tp_print */
+	0,						/* tp_getattr */
+	0,						/* tp_setattr */
+	0,						/* tp_compare */
+	(reprfunc)kqueue_event_repr,			/* tp_repr */
+	0,						/* tp_as_number */
+	0,						/* tp_as_sequence */
+	0,						/* tp_as_mapping */
+	0,						/* tp_hash */
+	0,              				/* tp_call */
+	0,						/* tp_str */
+	0,						/* tp_getattro */
+	0,						/* tp_setattro */
+	0,						/* tp_as_buffer */
+	Py_TPFLAGS_DEFAULT,				/* tp_flags */
+	kqueue_event_doc,				/* tp_doc */
+	0,						/* tp_traverse */
+	0,						/* tp_clear */
+	(richcmpfunc)kqueue_event_richcompare,		/* tp_richcompare */
+	0,						/* tp_weaklistoffset */
+	0,						/* tp_iter */
+	0,						/* tp_iternext */
+	0,						/* tp_methods */
+	kqueue_event_members,				/* tp_members */
+	0,						/* tp_getset */
+	0,						/* tp_base */
+	0,						/* tp_dict */
+	0,						/* tp_descr_get */
+	0,						/* tp_descr_set */
+	0,						/* tp_dictoffset */
+	(initproc)kqueue_event_init,			/* tp_init */
+	0,						/* tp_alloc */
+	0,						/* tp_new */
+	0,						/* tp_free */
+};
+
+static PyObject *
+kqueue_queue_err_closed(void)
+{
+	PyErr_SetString(PyExc_ValueError, "I/O operation on closed kqueue fd");
+	return NULL;
+}
+
+static int
+kqueue_queue_internal_close(kqueue_queue_Object *self)
+{
+	int save_errno = 0;
+	if (self->kqfd >= 0) {
+		int kqfd = self->kqfd;
+		self->kqfd = -1;
+		Py_BEGIN_ALLOW_THREADS
+		if (close(kqfd) < 0)
+			save_errno = errno;
+		Py_END_ALLOW_THREADS
+	}
+	return save_errno;
+}
+
+static PyObject *
+newKqueue_Object(PyTypeObject *type, SOCKET fd)
+{
+	kqueue_queue_Object *self;
+	assert(type != NULL && type->tp_alloc != NULL);
+	self = (kqueue_queue_Object *) type->tp_alloc(type, 0);
+	if (self == NULL) {
+		return NULL;
+	}
+	
+	if (fd == -1) {
+		Py_BEGIN_ALLOW_THREADS
+		self->kqfd = kqueue();
+		Py_END_ALLOW_THREADS
+	}
+	else {
+		self->kqfd = fd;
+	}
+	if (self->kqfd < 0) {
+		Py_DECREF(self);
+		PyErr_SetFromErrno(PyExc_IOError);
+		return NULL;
+	}
+	return (PyObject *)self;
+}
+
+static PyObject *
+kqueue_queue_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+
+	if ((args != NULL && PyObject_Size(args)) ||
+			(kwds != NULL && PyObject_Size(kwds))) {
+		PyErr_SetString(PyExc_ValueError,
+				"select.kqueue doesn't accept arguments");
+		return NULL;
+	}
+
+	return newKqueue_Object(type, -1);
+}
+
+static void
+kqueue_queue_dealloc(kqueue_queue_Object *self)
+{
+	kqueue_queue_internal_close(self);
+	Py_TYPE(self)->tp_free(self);
+}
+
+static PyObject*
+kqueue_queue_close(kqueue_queue_Object *self)
+{
+	errno = kqueue_queue_internal_close(self);
+	if (errno < 0) {
+		PyErr_SetFromErrno(PyExc_IOError);
+		return NULL;
+	}
+	Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(kqueue_queue_close_doc,
+"close() -> None\n\
+\n\
+Close the kqueue control file descriptor. Further operations on the kqueue\n\
+object will raise an exception.");
+
+static PyObject*
+kqueue_queue_get_closed(kqueue_queue_Object *self)
+{
+	if (self->kqfd < 0)
+		Py_RETURN_TRUE;
+	else
+		Py_RETURN_FALSE;
+}
+
+static PyObject*
+kqueue_queue_fileno(kqueue_queue_Object *self)
+{
+	if (self->kqfd < 0)
+		return kqueue_queue_err_closed();
+	return PyLong_FromLong(self->kqfd);
+}
+
+PyDoc_STRVAR(kqueue_queue_fileno_doc,
+"fileno() -> int\n\
+\n\
+Return the kqueue control file descriptor.");
+
+static PyObject*
+kqueue_queue_fromfd(PyObject *cls, PyObject *args)
+{
+	SOCKET fd;
+
+	if (!PyArg_ParseTuple(args, "i:fromfd", &fd))
+		return NULL;
+
+	return newKqueue_Object((PyTypeObject*)cls, fd);
+}
+
+PyDoc_STRVAR(kqueue_queue_fromfd_doc,
+"fromfd(fd) -> kqueue\n\
+\n\
+Create a kqueue object from a given control fd.");
+
+static PyObject *
+kqueue_queue_control(kqueue_queue_Object *self, PyObject *args)
+{
+	int nevents = 0;
+	int gotevents = 0;
+	int nchanges = 0;
+	int i = 0;
+	PyObject *otimeout = NULL;
+	PyObject *ch = NULL;
+	PyObject *it = NULL, *ei = NULL;
+	PyObject *result = NULL;
+	struct kevent *evl = NULL;
+	struct kevent *chl = NULL;
+	struct timespec timeoutspec;
+	struct timespec *ptimeoutspec;
+
+	if (self->kqfd < 0)
+		return kqueue_queue_err_closed();
+
+	if (!PyArg_ParseTuple(args, "Oi|O:control", &ch, &nevents, &otimeout))
+		return NULL;
+
+	if (nevents < 0) {
+		PyErr_Format(PyExc_ValueError,
+			"Length of eventlist must be 0 or positive, got %d",
+			nchanges);
+		return NULL;
+	}
+
+	if (ch != NULL && ch != Py_None) {
+		it = PyObject_GetIter(ch);
+		if (it == NULL) {
+			PyErr_SetString(PyExc_TypeError,
+					"changelist is not iterable");
+			return NULL;
+		}
+		nchanges = PyObject_Size(ch);
+		if (nchanges < 0) {
+			return NULL;
+		}
+	}
+
+	if (otimeout == Py_None || otimeout == NULL) {
+		ptimeoutspec = NULL;
+	}
+	else if (PyNumber_Check(otimeout)) {
+		double timeout;
+		long seconds;
+
+		timeout = PyFloat_AsDouble(otimeout);
+		if (timeout == -1 && PyErr_Occurred())
+			return NULL;
+		if (timeout > (double)LONG_MAX) {
+			PyErr_SetString(PyExc_OverflowError,
+					"timeout period too long");
+			return NULL;
+		}
+		if (timeout < 0) {
+			PyErr_SetString(PyExc_ValueError,
+					"timeout must be positive or None");
+			return NULL;
+		}
+
+		seconds = (long)timeout;
+		timeout = timeout - (double)seconds;
+		timeoutspec.tv_sec = seconds;
+		timeoutspec.tv_nsec = (long)(timeout * 1E9);
+		ptimeoutspec = &timeoutspec;
+	}
+	else {
+		PyErr_Format(PyExc_TypeError,
+			"timeout argument must be an number "
+			"or None, got %.200s",
+			Py_TYPE(otimeout)->tp_name);
+		return NULL;
+	}
+
+	if (nchanges) {
+		chl = PyMem_New(struct kevent, nchanges);
+		if (chl == NULL) {
+			PyErr_NoMemory();
+			return NULL;
+		}
+		while ((ei = PyIter_Next(it)) != NULL) {
+			if (!kqueue_event_Check(ei)) {
+				Py_DECREF(ei);
+				PyErr_SetString(PyExc_TypeError,
+					"changelist must be an iterable of "
+				 	"select.kevent objects");
+				goto error;
+			} else {
+				chl[i] = ((kqueue_event_Object *)ei)->e;
+			}
+			Py_DECREF(ei);
+		}
+	}
+	Py_CLEAR(it);
+
+	/* event list */
+	if (nevents) {
+		evl = PyMem_New(struct kevent, nevents);
+		if (evl == NULL) {
+			PyErr_NoMemory();
+			return NULL;
+		}
+	}
+
+	Py_BEGIN_ALLOW_THREADS
+	gotevents = kevent(self->kqfd, chl, nchanges,
+			   evl, nevents, ptimeoutspec);
+	Py_END_ALLOW_THREADS
+
+	if (gotevents == -1) {
+		PyErr_SetFromErrno(PyExc_OSError);
+		goto error;
+	}
+
+	result = PyList_New(gotevents);
+	if (result == NULL) {
+		goto error;
+	}
+
+	for (i=0; i < gotevents; i++) {
+		kqueue_event_Object *ch;
+
+		ch = PyObject_New(kqueue_event_Object, &kqueue_event_Type);
+		if (ch == NULL) {
+			goto error;
+		}
+		ch->e = evl[i];
+		PyList_SET_ITEM(result, i, (PyObject *)ch);
+	}
+	PyMem_Free(chl);
+	PyMem_Free(evl);
+	return result;
+
+    error:
+	PyMem_Free(chl);
+	PyMem_Free(evl);
+	Py_XDECREF(result);
+	Py_XDECREF(it);
+	return NULL;
+}
+
+PyDoc_STRVAR(kqueue_queue_control_doc,
+"control(changelist, max_events=0[, timeout=None]) -> eventlist\n\
+\n\
+Calls the kernel kevent function.\n\
+- changelist must be a list of kevent objects describing the changes\n\
+  to be made to the kernel's watch list or None.\n\
+- max_events lets you specify the maximum number of events that the\n\
+  kernel will return.\n\
+- timeout is the maximum time to wait in seconds, or else None,\n\
+  to wait forever. timeout accepts floats for smaller timeouts, too.");
+
+
+static PyMethodDef kqueue_queue_methods[] = {
+	{"fromfd",	(PyCFunction)kqueue_queue_fromfd,
+	 METH_VARARGS | METH_CLASS, kqueue_queue_fromfd_doc},
+	{"close",	(PyCFunction)kqueue_queue_close,	METH_NOARGS,
+	 kqueue_queue_close_doc},
+	{"fileno",	(PyCFunction)kqueue_queue_fileno,	METH_NOARGS,
+	 kqueue_queue_fileno_doc},
+	{"control",	(PyCFunction)kqueue_queue_control,
+	 METH_VARARGS ,	kqueue_queue_control_doc},
+	{NULL,	NULL},
+};
+
+static PyGetSetDef kqueue_queue_getsetlist[] = {
+	{"closed", (getter)kqueue_queue_get_closed, NULL,
+	 "True if the kqueue handler is closed"},
+	{0},
+};
+
+PyDoc_STRVAR(kqueue_queue_doc,
+"Kqueue syscall wrapper.\n\
+\n\
+For example, to start watching a socket for input:\n\
+>>> kq = kqueue()\n\
+>>> sock = socket()\n\
+>>> sock.connect((host, port))\n\
+>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\
+\n\
+To wait one second for it to become writeable:\n\
+>>> kq.control(None, 1, 1000)\n\
+\n\
+To stop listening:\n\
+>>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)");
+
+static PyTypeObject kqueue_queue_Type = {
+	PyVarObject_HEAD_INIT(NULL, 0)
+	"select.kqueue",				/* tp_name */
+	sizeof(kqueue_queue_Object),			/* tp_basicsize */
+	0,						/* tp_itemsize */
+	(destructor)kqueue_queue_dealloc,		/* tp_dealloc */
+	0,						/* tp_print */
+	0,						/* tp_getattr */
+	0,						/* tp_setattr */
+	0,						/* tp_compare */
+	0,						/* tp_repr */
+	0,						/* tp_as_number */
+	0,						/* tp_as_sequence */
+	0,						/* tp_as_mapping */
+	0,						/* tp_hash */
+	0,              				/* tp_call */
+	0,						/* tp_str */
+	0,						/* tp_getattro */
+	0,						/* tp_setattro */
+	0,						/* tp_as_buffer */
+	Py_TPFLAGS_DEFAULT,				/* tp_flags */
+	kqueue_queue_doc,				/* tp_doc */
+	0,						/* tp_traverse */
+	0,						/* tp_clear */
+	0,						/* tp_richcompare */
+	0,						/* tp_weaklistoffset */
+	0,						/* tp_iter */
+	0,						/* tp_iternext */
+	kqueue_queue_methods,				/* tp_methods */
+	0,						/* tp_members */
+	kqueue_queue_getsetlist,			/* 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 */
+	kqueue_queue_new,				/* tp_new */
+	0,						/* tp_free */
+};
+
+#endif /* HAVE_KQUEUE */
+/* ************************************************************************ */
+
 PyDoc_STRVAR(select_doc,
 "select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\
 \n\
@@ -663,14 +1715,15 @@
 that are ready.\n\
 \n\
 *** IMPORTANT NOTICE ***\n\
-On Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors.");
+On Windows and OpenVMS, only sockets are supported; on Unix, all file\n\
+descriptors.");
 
 static PyMethodDef select_methods[] = {
-    {"select",	select_select, METH_VARARGS, select_doc},
-#if defined(HAVE_POLL) 
-    {"poll",    select_poll,   METH_NOARGS, poll_doc},
+	{"select",	select_select,	METH_VARARGS,	select_doc},
+#ifdef HAVE_POLL
+	{"poll",	select_poll,	METH_NOARGS,	poll_doc},
 #endif /* HAVE_POLL */
-    {0,  	0},			     /* sentinel */
+	{0,  	0},	/* sentinel */
 };
 
 PyDoc_STRVAR(module_doc,
@@ -690,8 +1743,8 @@
 	SelectError = PyErr_NewException("select.error", NULL, NULL);
 	Py_INCREF(SelectError);
 	PyModule_AddObject(m, "error", SelectError);
-#if defined(HAVE_POLL) 
 
+#if defined(HAVE_POLL)
 #ifdef __APPLE__
 	if (select_have_broken_poll()) {
 		if (PyObject_DelAttrString(m, "poll") == -1) {
@@ -701,7 +1754,7 @@
 #else
 	{
 #endif
-		Py_Type(&poll_Type) = &PyType_Type;
+		Py_TYPE(&poll_Type) = &PyType_Type;
 		PyModule_AddIntConstant(m, "POLLIN", POLLIN);
 		PyModule_AddIntConstant(m, "POLLPRI", POLLPRI);
 		PyModule_AddIntConstant(m, "POLLOUT", POLLOUT);
@@ -726,4 +1779,103 @@
 #endif
 	}
 #endif /* HAVE_POLL */
+
+#ifdef HAVE_EPOLL
+	Py_TYPE(&pyEpoll_Type) = &PyType_Type;
+	if (PyType_Ready(&pyEpoll_Type) < 0)
+		return;
+
+	Py_INCREF(&pyEpoll_Type);
+	PyModule_AddObject(m, "epoll", (PyObject *) &pyEpoll_Type);
+
+	PyModule_AddIntConstant(m, "EPOLLIN", EPOLLIN);
+	PyModule_AddIntConstant(m, "EPOLLOUT", EPOLLOUT);
+	PyModule_AddIntConstant(m, "EPOLLPRI", EPOLLPRI);
+	PyModule_AddIntConstant(m, "EPOLLERR", EPOLLERR);
+	PyModule_AddIntConstant(m, "EPOLLHUP", EPOLLHUP);
+	PyModule_AddIntConstant(m, "EPOLLET", EPOLLET);
+#ifdef EPOLLONESHOT
+	/* Kernel 2.6.2+ */
+	PyModule_AddIntConstant(m, "EPOLLONESHOT", EPOLLONESHOT);
+#endif
+	/* PyModule_AddIntConstant(m, "EPOLL_RDHUP", EPOLLRDHUP); */
+	PyModule_AddIntConstant(m, "EPOLLRDNORM", EPOLLRDNORM);
+	PyModule_AddIntConstant(m, "EPOLLRDBAND", EPOLLRDBAND);
+	PyModule_AddIntConstant(m, "EPOLLWRNORM", EPOLLWRNORM);
+	PyModule_AddIntConstant(m, "EPOLLWRBAND", EPOLLWRBAND);
+	PyModule_AddIntConstant(m, "EPOLLMSG", EPOLLMSG);
+#endif /* HAVE_EPOLL */
+
+#ifdef HAVE_KQUEUE
+	kqueue_event_Type.tp_new = PyType_GenericNew;
+	Py_TYPE(&kqueue_event_Type) = &PyType_Type;
+	if(PyType_Ready(&kqueue_event_Type) < 0)
+		return;
+
+	Py_INCREF(&kqueue_event_Type);
+	PyModule_AddObject(m, "kevent", (PyObject *)&kqueue_event_Type);
+
+	Py_TYPE(&kqueue_queue_Type) = &PyType_Type;
+	if(PyType_Ready(&kqueue_queue_Type) < 0)
+		return;
+	Py_INCREF(&kqueue_queue_Type);
+	PyModule_AddObject(m, "kqueue", (PyObject *)&kqueue_queue_Type);
+	
+	/* event filters */
+	PyModule_AddIntConstant(m, "KQ_FILTER_READ", EVFILT_READ);
+	PyModule_AddIntConstant(m, "KQ_FILTER_WRITE", EVFILT_WRITE);
+	PyModule_AddIntConstant(m, "KQ_FILTER_AIO", EVFILT_AIO);
+	PyModule_AddIntConstant(m, "KQ_FILTER_VNODE", EVFILT_VNODE);
+	PyModule_AddIntConstant(m, "KQ_FILTER_PROC", EVFILT_PROC);
+#ifdef EVFILT_NETDEV
+	PyModule_AddIntConstant(m, "KQ_FILTER_NETDEV", EVFILT_NETDEV);
+#endif
+	PyModule_AddIntConstant(m, "KQ_FILTER_SIGNAL", EVFILT_SIGNAL);
+	PyModule_AddIntConstant(m, "KQ_FILTER_TIMER", EVFILT_TIMER);
+
+	/* event flags */
+	PyModule_AddIntConstant(m, "KQ_EV_ADD", EV_ADD);
+	PyModule_AddIntConstant(m, "KQ_EV_DELETE", EV_DELETE);
+	PyModule_AddIntConstant(m, "KQ_EV_ENABLE", EV_ENABLE);
+	PyModule_AddIntConstant(m, "KQ_EV_DISABLE", EV_DISABLE);
+	PyModule_AddIntConstant(m, "KQ_EV_ONESHOT", EV_ONESHOT);
+	PyModule_AddIntConstant(m, "KQ_EV_CLEAR", EV_CLEAR);
+
+	PyModule_AddIntConstant(m, "KQ_EV_SYSFLAGS", EV_SYSFLAGS);
+	PyModule_AddIntConstant(m, "KQ_EV_FLAG1", EV_FLAG1);
+
+	PyModule_AddIntConstant(m, "KQ_EV_EOF", EV_EOF);
+	PyModule_AddIntConstant(m, "KQ_EV_ERROR", EV_ERROR);
+
+	/* READ WRITE filter flag */
+	PyModule_AddIntConstant(m, "KQ_NOTE_LOWAT", NOTE_LOWAT);
+	
+	/* VNODE filter flags  */
+	PyModule_AddIntConstant(m, "KQ_NOTE_DELETE", NOTE_DELETE);
+	PyModule_AddIntConstant(m, "KQ_NOTE_WRITE", NOTE_WRITE);
+	PyModule_AddIntConstant(m, "KQ_NOTE_EXTEND", NOTE_EXTEND);
+	PyModule_AddIntConstant(m, "KQ_NOTE_ATTRIB", NOTE_ATTRIB);
+	PyModule_AddIntConstant(m, "KQ_NOTE_LINK", NOTE_LINK);
+	PyModule_AddIntConstant(m, "KQ_NOTE_RENAME", NOTE_RENAME);
+	PyModule_AddIntConstant(m, "KQ_NOTE_REVOKE", NOTE_REVOKE);
+
+	/* PROC filter flags  */
+	PyModule_AddIntConstant(m, "KQ_NOTE_EXIT", NOTE_EXIT);
+	PyModule_AddIntConstant(m, "KQ_NOTE_FORK", NOTE_FORK);
+	PyModule_AddIntConstant(m, "KQ_NOTE_EXEC", NOTE_EXEC);
+	PyModule_AddIntConstant(m, "KQ_NOTE_PCTRLMASK", NOTE_PCTRLMASK);
+	PyModule_AddIntConstant(m, "KQ_NOTE_PDATAMASK", NOTE_PDATAMASK);
+
+	PyModule_AddIntConstant(m, "KQ_NOTE_TRACK", NOTE_TRACK);
+	PyModule_AddIntConstant(m, "KQ_NOTE_CHILD", NOTE_CHILD);
+	PyModule_AddIntConstant(m, "KQ_NOTE_TRACKERR", NOTE_TRACKERR);
+
+	/* NETDEV filter flags */
+#ifdef EVFILT_NETDEV
+	PyModule_AddIntConstant(m, "KQ_NOTE_LINKUP", NOTE_LINKUP);
+	PyModule_AddIntConstant(m, "KQ_NOTE_LINKDOWN", NOTE_LINKDOWN);
+	PyModule_AddIntConstant(m, "KQ_NOTE_LINKINV", NOTE_LINKINV);
+#endif
+
+#endif /* HAVE_KQUEUE */
 }

Modified: python/branches/py3k-importlib/Modules/sha1module.c
==============================================================================
--- python/branches/py3k-importlib/Modules/sha1module.c	(original)
+++ python/branches/py3k-importlib/Modules/sha1module.c	Thu Mar 27 00:48:05 2008
@@ -316,7 +316,7 @@
 {
     SHA1object *newobj;
 
-    if (Py_Type(self) == &SHA1type) {
+    if (Py_TYPE(self) == &SHA1type) {
         if ( (newobj = newSHA1object())==NULL)
             return NULL;
     } else {
@@ -339,7 +339,7 @@
 
     temp = self->hash_state;
     sha1_done(&temp, digest);
-    return PyBytes_FromStringAndSize((const char *)digest, SHA1_DIGESTSIZE);
+    return PyString_FromStringAndSize((const char *)digest, SHA1_DIGESTSIZE);
 }
 
 PyDoc_STRVAR(SHA1_hexdigest__doc__,
@@ -410,7 +410,7 @@
 static PyObject *
 SHA1_get_block_size(PyObject *self, void *closure)
 {
-    return PyInt_FromLong(SHA1_BLOCKSIZE);
+    return PyLong_FromLong(SHA1_BLOCKSIZE);
 }
 
 static PyObject *
@@ -422,7 +422,7 @@
 static PyObject *
 sha1_get_digest_size(PyObject *self, void *closure)
 {
-    return PyInt_FromLong(SHA1_DIGESTSIZE);
+    return PyLong_FromLong(SHA1_DIGESTSIZE);
 }
 
 
@@ -528,7 +528,7 @@
 {
     PyObject *m;
 
-    Py_Type(&SHA1type) = &PyType_Type;
+    Py_TYPE(&SHA1type) = &PyType_Type;
     if (PyType_Ready(&SHA1type) < 0)
         return;
     m = Py_InitModule("_sha1", SHA1_functions);

Modified: python/branches/py3k-importlib/Modules/sha256module.c
==============================================================================
--- python/branches/py3k-importlib/Modules/sha256module.c	(original)
+++ python/branches/py3k-importlib/Modules/sha256module.c	Thu Mar 27 00:48:05 2008
@@ -409,7 +409,7 @@
 {
     SHAobject *newobj;
 
-    if (Py_Type(self) == &SHA256type) {
+    if (Py_TYPE(self) == &SHA256type) {
         if ( (newobj = newSHA256object())==NULL)
             return NULL;
     } else {
@@ -432,7 +432,7 @@
 
     SHAcopy(self, &temp);
     sha_final(digest, &temp);
-    return PyBytes_FromStringAndSize((const char *)digest, self->digestsize);
+    return PyString_FromStringAndSize((const char *)digest, self->digestsize);
 }
 
 PyDoc_STRVAR(SHA256_hexdigest__doc__,
@@ -503,7 +503,7 @@
 static PyObject *
 SHA256_get_block_size(PyObject *self, void *closure)
 {
-    return PyInt_FromLong(SHA_BLOCKSIZE);
+    return PyLong_FromLong(SHA_BLOCKSIZE);
 }
 
 static PyObject *
@@ -687,10 +687,10 @@
 {
     PyObject *m;
 
-    Py_Type(&SHA224type) = &PyType_Type;
+    Py_TYPE(&SHA224type) = &PyType_Type;
     if (PyType_Ready(&SHA224type) < 0)
         return;
-    Py_Type(&SHA256type) = &PyType_Type;
+    Py_TYPE(&SHA256type) = &PyType_Type;
     if (PyType_Ready(&SHA256type) < 0)
         return;
     m = Py_InitModule("_sha256", SHA_functions);

Modified: python/branches/py3k-importlib/Modules/sha512module.c
==============================================================================
--- python/branches/py3k-importlib/Modules/sha512module.c	(original)
+++ python/branches/py3k-importlib/Modules/sha512module.c	Thu Mar 27 00:48:05 2008
@@ -498,7 +498,7 @@
 
     SHAcopy(self, &temp);
     sha512_final(digest, &temp);
-    return PyBytes_FromStringAndSize((const char *)digest, self->digestsize);
+    return PyString_FromStringAndSize((const char *)digest, self->digestsize);
 }
 
 PyDoc_STRVAR(SHA512_hexdigest__doc__,
@@ -569,7 +569,7 @@
 static PyObject *
 SHA512_get_block_size(PyObject *self, void *closure)
 {
-    return PyInt_FromLong(SHA_BLOCKSIZE);
+    return PyLong_FromLong(SHA_BLOCKSIZE);
 }
 
 static PyObject *
@@ -753,10 +753,10 @@
 {
     PyObject *m;
 
-    Py_Type(&SHA384type) = &PyType_Type;
+    Py_TYPE(&SHA384type) = &PyType_Type;
     if (PyType_Ready(&SHA384type) < 0)
         return;
-    Py_Type(&SHA512type) = &PyType_Type;
+    Py_TYPE(&SHA512type) = &PyType_Type;
     if (PyType_Ready(&SHA512type) < 0)
         return;
     m = Py_InitModule("_sha512", SHA_functions);

Modified: python/branches/py3k-importlib/Modules/signalmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/signalmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/signalmodule.c	Thu Mar 27 00:48:05 2008
@@ -12,6 +12,8 @@
 
 #include <signal.h>
 
+#include <sys/stat.h>
+
 #ifndef SIG_ERR
 #define SIG_ERR ((PyOS_sighandler_t)(-1))
 #endif
@@ -75,7 +77,10 @@
         PyObject *func;
 } Handlers[NSIG];
 
-static int is_tripped = 0; /* Speed up sigcheck() when none tripped */
+static sig_atomic_t wakeup_fd = -1;
+
+/* Speed up sigcheck() when none tripped */
+static volatile sig_atomic_t is_tripped = 0;
 
 static PyObject *DefaultHandler;
 static PyObject *IgnoreHandler;
@@ -122,9 +127,13 @@
 	/* See NOTES section above */
 	if (getpid() == main_pid) {
 #endif
-		is_tripped++;
 		Handlers[sig_num].tripped = 1;
+                /* Set is_tripped after setting .tripped, as it gets
+                   cleared in PyErr_CheckSignals() before .tripped. */
+		is_tripped = 1;
 		Py_AddPendingCall(checksignals_witharg, NULL);
+		if (wakeup_fd != -1)
+			write(wakeup_fd, "\0", 1);
 #ifdef WITH_THREAD
 	}
 #endif
@@ -149,7 +158,7 @@
 	if (!PyArg_ParseTuple(args, "i:alarm", &t))
 		return NULL;
 	/* alarm() returns the number of seconds remaining */
-	return PyInt_FromLong((long)alarm(t));
+	return PyLong_FromLong((long)alarm(t));
 }
 
 PyDoc_STRVAR(alarm_doc,
@@ -263,6 +272,80 @@
 None -- if an unknown handler is in effect\n\
 anything else -- the callable Python object used as a handler");
 
+#ifdef HAVE_SIGINTERRUPT
+PyDoc_STRVAR(siginterrupt_doc,
+"siginterrupt(sig, flag) -> None\n\
+change system call restart behaviour: if flag is False, system calls\n\
+will be restarted when interrupted by signal sig, else system calls\n\
+will be interrupted.");
+
+static PyObject *
+signal_siginterrupt(PyObject *self, PyObject *args)
+{
+	int sig_num;
+	int flag;
+
+	if (!PyArg_ParseTuple(args, "ii:siginterrupt", &sig_num, &flag))
+		return NULL;
+	if (sig_num < 1 || sig_num >= NSIG) {
+		PyErr_SetString(PyExc_ValueError,
+				"signal number out of range");
+		return NULL;
+	}
+	if (siginterrupt(sig_num, flag)<0) {
+		PyErr_SetFromErrno(PyExc_RuntimeError);
+		return NULL;
+	}
+
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+#endif
+
+static PyObject *
+signal_set_wakeup_fd(PyObject *self, PyObject *args)
+{
+	struct stat buf;
+	int fd, old_fd;
+	if (!PyArg_ParseTuple(args, "i:set_wakeup_fd", &fd))
+		return NULL;
+#ifdef WITH_THREAD
+	if (PyThread_get_thread_ident() != main_thread) {
+		PyErr_SetString(PyExc_ValueError,
+				"set_wakeup_fd only works in main thread");
+		return NULL;
+	}
+#endif
+	if (fd != -1 && fstat(fd, &buf) != 0) {
+		PyErr_SetString(PyExc_ValueError, "invalid fd");
+		return NULL;
+	}
+	old_fd = wakeup_fd;
+	wakeup_fd = fd;
+	return PyLong_FromLong(old_fd);
+}
+
+PyDoc_STRVAR(set_wakeup_fd_doc,
+"set_wakeup_fd(fd) -> fd\n\
+\n\
+Sets the fd to be written to (with '\\0') when a signal\n\
+comes in.  A library can use this to wakeup select or poll.\n\
+The previous fd is returned.\n\
+\n\
+The fd must be non-blocking.");
+
+/* C API for the same, without all the error checking */
+int
+PySignal_SetWakeupFd(int fd)
+{
+	int old_fd = wakeup_fd;
+	if (fd < 0)
+		fd = -1;
+	wakeup_fd = fd;
+	return old_fd;
+}
+
 
 /* List of functions defined in the module */
 static PyMethodDef signal_methods[] = {
@@ -271,11 +354,15 @@
 #endif
 	{"signal",	        signal_signal, METH_VARARGS, signal_doc},
 	{"getsignal",	        signal_getsignal, METH_VARARGS, getsignal_doc},
+	{"set_wakeup_fd",	signal_set_wakeup_fd, METH_VARARGS, set_wakeup_fd_doc},
+#ifdef HAVE_SIGINTERRUPT
+ 	{"siginterrupt",	signal_siginterrupt, METH_VARARGS, siginterrupt_doc},
+#endif
 #ifdef HAVE_PAUSE
 	{"pause",	        (PyCFunction)signal_pause,
 	 METH_NOARGS,pause_doc},
 #endif
-	{"default_int_handler", signal_default_int_handler, 
+	{"default_int_handler", signal_default_int_handler,
 	 METH_VARARGS, default_int_handler_doc},
 	{NULL,			NULL}		/* sentinel */
 };
@@ -331,7 +418,7 @@
         if (!x || PyDict_SetItemString(d, "SIG_IGN", x) < 0)
                 goto finally;
 
-        x = PyInt_FromLong((long)NSIG);
+        x = PyLong_FromLong((long)NSIG);
         if (!x || PyDict_SetItemString(d, "NSIG", x) < 0)
                 goto finally;
         Py_DECREF(x);
@@ -363,192 +450,192 @@
 	}
 
 #ifdef SIGHUP
-	x = PyInt_FromLong(SIGHUP);
+	x = PyLong_FromLong(SIGHUP);
 	PyDict_SetItemString(d, "SIGHUP", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGINT
-	x = PyInt_FromLong(SIGINT);
+	x = PyLong_FromLong(SIGINT);
 	PyDict_SetItemString(d, "SIGINT", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGBREAK
-	x = PyInt_FromLong(SIGBREAK);
+	x = PyLong_FromLong(SIGBREAK);
 	PyDict_SetItemString(d, "SIGBREAK", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGQUIT
-	x = PyInt_FromLong(SIGQUIT);
+	x = PyLong_FromLong(SIGQUIT);
 	PyDict_SetItemString(d, "SIGQUIT", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGILL
-	x = PyInt_FromLong(SIGILL);
+	x = PyLong_FromLong(SIGILL);
 	PyDict_SetItemString(d, "SIGILL", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGTRAP
-	x = PyInt_FromLong(SIGTRAP);
+	x = PyLong_FromLong(SIGTRAP);
 	PyDict_SetItemString(d, "SIGTRAP", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGIOT
-	x = PyInt_FromLong(SIGIOT);
+	x = PyLong_FromLong(SIGIOT);
 	PyDict_SetItemString(d, "SIGIOT", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGABRT
-	x = PyInt_FromLong(SIGABRT);
+	x = PyLong_FromLong(SIGABRT);
 	PyDict_SetItemString(d, "SIGABRT", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGEMT
-	x = PyInt_FromLong(SIGEMT);
+	x = PyLong_FromLong(SIGEMT);
 	PyDict_SetItemString(d, "SIGEMT", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGFPE
-	x = PyInt_FromLong(SIGFPE);
+	x = PyLong_FromLong(SIGFPE);
 	PyDict_SetItemString(d, "SIGFPE", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGKILL
-	x = PyInt_FromLong(SIGKILL);
+	x = PyLong_FromLong(SIGKILL);
 	PyDict_SetItemString(d, "SIGKILL", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGBUS
-	x = PyInt_FromLong(SIGBUS);
+	x = PyLong_FromLong(SIGBUS);
 	PyDict_SetItemString(d, "SIGBUS", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGSEGV
-	x = PyInt_FromLong(SIGSEGV);
+	x = PyLong_FromLong(SIGSEGV);
 	PyDict_SetItemString(d, "SIGSEGV", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGSYS
-	x = PyInt_FromLong(SIGSYS);
+	x = PyLong_FromLong(SIGSYS);
 	PyDict_SetItemString(d, "SIGSYS", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGPIPE
-	x = PyInt_FromLong(SIGPIPE);
+	x = PyLong_FromLong(SIGPIPE);
 	PyDict_SetItemString(d, "SIGPIPE", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGALRM
-	x = PyInt_FromLong(SIGALRM);
+	x = PyLong_FromLong(SIGALRM);
 	PyDict_SetItemString(d, "SIGALRM", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGTERM
-	x = PyInt_FromLong(SIGTERM);
+	x = PyLong_FromLong(SIGTERM);
 	PyDict_SetItemString(d, "SIGTERM", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGUSR1
-	x = PyInt_FromLong(SIGUSR1);
+	x = PyLong_FromLong(SIGUSR1);
 	PyDict_SetItemString(d, "SIGUSR1", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGUSR2
-	x = PyInt_FromLong(SIGUSR2);
+	x = PyLong_FromLong(SIGUSR2);
 	PyDict_SetItemString(d, "SIGUSR2", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGCLD
-	x = PyInt_FromLong(SIGCLD);
+	x = PyLong_FromLong(SIGCLD);
 	PyDict_SetItemString(d, "SIGCLD", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGCHLD
-	x = PyInt_FromLong(SIGCHLD);
+	x = PyLong_FromLong(SIGCHLD);
 	PyDict_SetItemString(d, "SIGCHLD", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGPWR
-	x = PyInt_FromLong(SIGPWR);
+	x = PyLong_FromLong(SIGPWR);
 	PyDict_SetItemString(d, "SIGPWR", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGIO
-	x = PyInt_FromLong(SIGIO);
+	x = PyLong_FromLong(SIGIO);
 	PyDict_SetItemString(d, "SIGIO", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGURG
-	x = PyInt_FromLong(SIGURG);
+	x = PyLong_FromLong(SIGURG);
 	PyDict_SetItemString(d, "SIGURG", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGWINCH
-	x = PyInt_FromLong(SIGWINCH);
+	x = PyLong_FromLong(SIGWINCH);
 	PyDict_SetItemString(d, "SIGWINCH", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGPOLL
-	x = PyInt_FromLong(SIGPOLL);
+	x = PyLong_FromLong(SIGPOLL);
 	PyDict_SetItemString(d, "SIGPOLL", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGSTOP
-	x = PyInt_FromLong(SIGSTOP);
+	x = PyLong_FromLong(SIGSTOP);
 	PyDict_SetItemString(d, "SIGSTOP", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGTSTP
-	x = PyInt_FromLong(SIGTSTP);
+	x = PyLong_FromLong(SIGTSTP);
 	PyDict_SetItemString(d, "SIGTSTP", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGCONT
-	x = PyInt_FromLong(SIGCONT);
+	x = PyLong_FromLong(SIGCONT);
 	PyDict_SetItemString(d, "SIGCONT", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGTTIN
-	x = PyInt_FromLong(SIGTTIN);
+	x = PyLong_FromLong(SIGTTIN);
 	PyDict_SetItemString(d, "SIGTTIN", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGTTOU
-	x = PyInt_FromLong(SIGTTOU);
+	x = PyLong_FromLong(SIGTTOU);
 	PyDict_SetItemString(d, "SIGTTOU", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGVTALRM
-	x = PyInt_FromLong(SIGVTALRM);
+	x = PyLong_FromLong(SIGVTALRM);
 	PyDict_SetItemString(d, "SIGVTALRM", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGPROF
-	x = PyInt_FromLong(SIGPROF);
+	x = PyLong_FromLong(SIGPROF);
 	PyDict_SetItemString(d, "SIGPROF", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGXCPU
-	x = PyInt_FromLong(SIGXCPU);
+	x = PyLong_FromLong(SIGXCPU);
 	PyDict_SetItemString(d, "SIGXCPU", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGXFSZ
-	x = PyInt_FromLong(SIGXFSZ);
+	x = PyLong_FromLong(SIGXFSZ);
 	PyDict_SetItemString(d, "SIGXFSZ", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGRTMIN
-        x = PyInt_FromLong(SIGRTMIN);
+        x = PyLong_FromLong(SIGRTMIN);
         PyDict_SetItemString(d, "SIGRTMIN", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGRTMAX
-        x = PyInt_FromLong(SIGRTMAX);
+        x = PyLong_FromLong(SIGRTMAX);
         PyDict_SetItemString(d, "SIGRTMAX", x);
         Py_XDECREF(x);
 #endif
 #ifdef SIGINFO
-	x = PyInt_FromLong(SIGINFO);
+	x = PyLong_FromLong(SIGINFO);
 	PyDict_SetItemString(d, "SIGINFO", x);
         Py_XDECREF(x);
 #endif
@@ -597,13 +684,31 @@
 
 	if (!is_tripped)
 		return 0;
+
 #ifdef WITH_THREAD
 	if (PyThread_get_thread_ident() != main_thread)
 		return 0;
 #endif
+
+	/*
+	 * The is_stripped variable is meant to speed up the calls to
+	 * PyErr_CheckSignals (both directly or via pending calls) when no
+	 * signal has arrived. This variable is set to 1 when a signal arrives
+	 * and it is set to 0 here, when we know some signals arrived. This way
+	 * we can run the registered handlers with no signals blocked.
+	 *
+	 * NOTE: with this approach we can have a situation where is_tripped is
+	 *       1 but we have no more signals to handle (Handlers[i].tripped
+	 *       is 0 for every signal i). This won't do us any harm (except
+	 *       we're gonna spent some cycles for nothing). This happens when
+	 *       we receive a signal i after we zero is_tripped and before we
+	 *       check Handlers[i].tripped.
+	 */
+	is_tripped = 0;
+
 	if (!(f = (PyObject *)PyEval_GetFrame()))
 		f = Py_None;
-	
+
 	for (i = 1; i < NSIG; i++) {
 		if (Handlers[i].tripped) {
 			PyObject *result = NULL;
@@ -621,7 +726,7 @@
 			Py_DECREF(result);
 		}
 	}
-	is_tripped = 0;
+
 	return 0;
 }
 
@@ -632,7 +737,7 @@
 void
 PyErr_SetInterrupt(void)
 {
-	is_tripped++;
+	is_tripped = 1;
 	Handlers[SIGINT].tripped = 1;
 	Py_AddPendingCall((int (*)(void *))PyErr_CheckSignals, NULL);
 }

Modified: python/branches/py3k-importlib/Modules/socketmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/socketmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/socketmodule.c	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,8 @@
 Limitations:
 
 - Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a
-  portable manner, though AF_PACKET and AF_NETLINK are supported under Linux.
+  portable manner, though AF_PACKET, AF_NETLINK and AF_TIPC are supported
+  under Linux.
 - No read/write operations (use sendall/recv or makefile instead).
 - Additional restrictions apply on some non-Unix platforms (compensated
   for by socket.py).
@@ -51,6 +52,25 @@
   the Ethernet protocol number to be received. For example:
   ("eth0",0x1234).  Optional 3rd,4th,5th elements in the tuple
   specify packet-type and ha-type/addr.
+- an AF_TIPC socket address is expressed as
+ (addr_type, v1, v2, v3 [, scope]); where addr_type can be one of:
+	TIPC_ADDR_NAMESEQ, TIPC_ADDR_NAME, and TIPC_ADDR_ID;
+  and scope can be one of:
+	TIPC_ZONE_SCOPE, TIPC_CLUSTER_SCOPE, and TIPC_NODE_SCOPE.
+  The meaning of v1, v2 and v3 depends on the value of addr_type:
+	if addr_type is TIPC_ADDR_NAME:
+		v1 is the server type
+		v2 is the port identifier
+		v3 is ignored
+	if addr_type is TIPC_ADDR_NAMESEQ:
+		v1 is the server type
+		v2 is the lower port number
+		v3 is the upper port number
+	if addr_type is TIPC_ADDR_ID:
+		v1 is the node
+		v2 is the ref
+		v3 is ignored
+
 
 Local naming conventions:
 
@@ -89,12 +109,12 @@
 \n\
 Methods of socket objects (keyword arguments not allowed):\n\
 \n\
-accept() -- accept a connection, returning new socket and client address\n\
+_accept() -- accept connection, returning new socket fd and client address\n\
 bind(addr) -- bind the socket to a local address\n\
 close() -- close the socket\n\
 connect(addr) -- connect the socket to a remote address\n\
 connect_ex(addr) -- connect, return an error code instead of an exception\n\
-dup() -- return a new socket object identical to the current one [*]\n\
+_dup() -- return a new socket fd duplicated from fileno()\n\
 fileno() -- return underlying file descriptor\n\
 getpeername() -- return remote address [*]\n\
 getsockname() -- return local address\n\
@@ -285,9 +305,11 @@
 #endif
 
 #ifndef HAVE_INET_PTON
+#if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN)
 int inet_pton(int af, const char *src, void *dst);
 const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
 #endif
+#endif
 
 #ifdef __APPLE__
 /* On OS X, getaddrinfo returns no error indication of lookup
@@ -324,10 +346,26 @@
 #include "getnameinfo.c"
 #endif
 
-#if defined(MS_WINDOWS)
-/* seem to be a few differences in the API */
+#ifdef MS_WINDOWS
+/* On Windows a socket is really a handle not an fd */
+static SOCKET
+dup_socket(SOCKET handle)
+{
+	HANDLE newhandle;
+
+	if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)handle,
+			     GetCurrentProcess(), &newhandle,
+			     0, FALSE, DUPLICATE_SAME_ACCESS))
+	{
+		WSASetLastError(GetLastError());
+		return INVALID_SOCKET;
+	}
+	return (SOCKET)newhandle;
+}
 #define SOCKETCLOSE closesocket
-#define NO_DUP /* Actually it exists on NT 3.5, but what the heck... */
+#else
+/* On Unix we can use dup to duplicate the file descriptor of a socket*/
+#define dup_socket(fd) dup(fd)
 #endif
 
 #ifdef MS_WIN32
@@ -447,87 +485,11 @@
 {
 #ifdef MS_WINDOWS
 	int err_no = WSAGetLastError();
-	static struct {
-		int no;
-		const char *msg;
-	} *msgp, msgs[] = {
-		{WSAEINTR, "Interrupted system call"},
-		{WSAEBADF, "Bad file descriptor"},
-		{WSAEACCES, "Permission denied"},
-		{WSAEFAULT, "Bad address"},
-		{WSAEINVAL, "Invalid argument"},
-		{WSAEMFILE, "Too many open files"},
-		{WSAEWOULDBLOCK,
-		  "The socket operation could not complete "
-		  "without blocking"},
-		{WSAEINPROGRESS, "Operation now in progress"},
-		{WSAEALREADY, "Operation already in progress"},
-		{WSAENOTSOCK, "Socket operation on non-socket"},
-		{WSAEDESTADDRREQ, "Destination address required"},
-		{WSAEMSGSIZE, "Message too long"},
-		{WSAEPROTOTYPE, "Protocol wrong type for socket"},
-		{WSAENOPROTOOPT, "Protocol not available"},
-		{WSAEPROTONOSUPPORT, "Protocol not supported"},
-		{WSAESOCKTNOSUPPORT, "Socket type not supported"},
-		{WSAEOPNOTSUPP, "Operation not supported"},
-		{WSAEPFNOSUPPORT, "Protocol family not supported"},
-		{WSAEAFNOSUPPORT, "Address family not supported"},
-		{WSAEADDRINUSE, "Address already in use"},
-		{WSAEADDRNOTAVAIL, "Can't assign requested address"},
-		{WSAENETDOWN, "Network is down"},
-		{WSAENETUNREACH, "Network is unreachable"},
-		{WSAENETRESET, "Network dropped connection on reset"},
-		{WSAECONNABORTED, "Software caused connection abort"},
-		{WSAECONNRESET, "Connection reset by peer"},
-		{WSAENOBUFS, "No buffer space available"},
-		{WSAEISCONN, "Socket is already connected"},
-		{WSAENOTCONN, "Socket is not connected"},
-		{WSAESHUTDOWN, "Can't send after socket shutdown"},
-		{WSAETOOMANYREFS, "Too many references: can't splice"},
-		{WSAETIMEDOUT, "Operation timed out"},
-		{WSAECONNREFUSED, "Connection refused"},
-		{WSAELOOP, "Too many levels of symbolic links"},
-		{WSAENAMETOOLONG, "File name too long"},
-		{WSAEHOSTDOWN, "Host is down"},
-		{WSAEHOSTUNREACH, "No route to host"},
-		{WSAENOTEMPTY, "Directory not empty"},
-		{WSAEPROCLIM, "Too many processes"},
-		{WSAEUSERS, "Too many users"},
-		{WSAEDQUOT, "Disc quota exceeded"},
-		{WSAESTALE, "Stale NFS file handle"},
-		{WSAEREMOTE, "Too many levels of remote in path"},
-		{WSASYSNOTREADY, "Network subsystem is unvailable"},
-		{WSAVERNOTSUPPORTED, "WinSock version is not supported"},
-		{WSANOTINITIALISED,
-		  "Successful WSAStartup() not yet performed"},
-		{WSAEDISCON, "Graceful shutdown in progress"},
-		/* Resolver errors */
-		{WSAHOST_NOT_FOUND, "No such host is known"},
-		{WSATRY_AGAIN, "Host not found, or server failed"},
-		{WSANO_RECOVERY, "Unexpected server error encountered"},
-		{WSANO_DATA, "Valid name without requested data"},
-		{WSANO_ADDRESS, "No address, look for MX record"},
-		{0, NULL}
-	};
-	if (err_no) {
-		PyObject *v;
-		const char *msg = "winsock error";
-
-		for (msgp = msgs; msgp->msg; msgp++) {
-			if (err_no == msgp->no) {
-				msg = msgp->msg;
-				break;
-			}
-		}
-
-		v = Py_BuildValue("(is)", err_no, msg);
-		if (v != NULL) {
-			PyErr_SetObject(socket_error, v);
-			Py_DECREF(v);
-		}
-		return NULL;
-	}
-	else
+	/* PyErr_SetExcFromWindowsErr() invokes FormatMessage() which
+	   recognizes the error codes used by both GetLastError() and
+	   WSAGetLastError */
+	if (err_no)
+		return PyErr_SetExcFromWindowsErr(socket_error, err_no);
 #endif
 
 #if defined(PYOS_OS2) && !defined(PYCC_GCC)
@@ -701,7 +663,7 @@
 		pollfd.events = writing ? POLLOUT : POLLIN;
 
 		/* s->sock_timeout is in seconds, timeout in ms */
-		timeout = (int)(s->sock_timeout * 1000 + 0.5); 
+		timeout = (int)(s->sock_timeout * 1000 + 0.5);
 		n = poll(&pollfd, 1, timeout);
 	}
 #else
@@ -721,7 +683,7 @@
 			n = select(s->sock_fd+1, &fds, NULL, NULL, &tv);
 	}
 #endif
-	
+
 	if (n < 0)
 		return -1;
 	if (n == 0)
@@ -1004,8 +966,8 @@
 		struct sockaddr_un *a = (struct sockaddr_un *) addr;
 #ifdef linux
 		if (a->sun_path[0] == 0) {  /* Linux abstract namespace */
-			addrlen -= (sizeof(*a) - sizeof(a->sun_path));
-			return PyBytes_FromStringAndSize(a->sun_path, addrlen);
+			addrlen -= offsetof(struct sockaddr_un, sun_path);
+			return PyString_FromStringAndSize(a->sun_path, addrlen);
 		}
 		else
 #endif /* linux */
@@ -1116,6 +1078,39 @@
 	}
 #endif
 
+#ifdef HAVE_LINUX_TIPC_H
+	case AF_TIPC:
+	{
+		struct sockaddr_tipc *a = (struct sockaddr_tipc *) addr;
+		if (a->addrtype == TIPC_ADDR_NAMESEQ) {
+			return Py_BuildValue("IIIII",
+					a->addrtype,
+					a->addr.nameseq.type,
+					a->addr.nameseq.lower,
+					a->addr.nameseq.upper,
+					a->scope);
+		} else if (a->addrtype == TIPC_ADDR_NAME) {
+			return Py_BuildValue("IIIII",
+					a->addrtype,
+					a->addr.name.name.type,
+					a->addr.name.name.instance,
+					a->addr.name.name.instance,
+					a->scope);
+		} else if (a->addrtype == TIPC_ADDR_ID) {
+			return Py_BuildValue("IIIII",
+					a->addrtype,
+					a->addr.id.node,
+					a->addr.id.ref,
+					0,
+					a->scope);
+		} else {
+			PyErr_SetString(PyExc_TypeError,
+					"Invalid address type");
+			return NULL;
+		}
+	}
+#endif
+
 	/* More cases here... */
 
 	default:
@@ -1176,7 +1171,7 @@
 #if defined(PYOS_OS2)
 		*len_ret = sizeof(*addr);
 #else
-		*len_ret = len + sizeof(*addr) - sizeof(addr->sun_path);
+		*len_ret = len + offsetof(struct sockaddr_un, sun_path);
 #endif
 		return 1;
 	}
@@ -1193,7 +1188,7 @@
 				PyExc_TypeError,
 				"getsockaddrarg: "
 				"AF_NETLINK address must be tuple, not %.500s",
-				Py_Type(args)->tp_name);
+				Py_TYPE(args)->tp_name);
 			return 0;
 		}
 		if (!PyArg_ParseTuple(args, "II:getsockaddrarg", &pid, &groups))
@@ -1216,7 +1211,7 @@
 				PyExc_TypeError,
 				"getsockaddrarg: "
 				"AF_INET address must be tuple, not %.500s",
-				Py_Type(args)->tp_name);
+				Py_TYPE(args)->tp_name);
 			return 0;
 		}
 		if (!PyArg_ParseTuple(args, "eti:getsockaddrarg",
@@ -1246,7 +1241,7 @@
 				PyExc_TypeError,
 				"getsockaddrarg: "
 				"AF_INET6 address must be tuple, not %.500s",
-				Py_Type(args)->tp_name);
+				Py_TYPE(args)->tp_name);
 			return 0;
 		}
 		if (!PyArg_ParseTuple(args, "eti|ii",
@@ -1331,12 +1326,12 @@
 
 			addr = (struct sockaddr_sco *)addr_ret;
 			_BT_SCO_MEMB(addr, family) = AF_BLUETOOTH;
-			if (!PyBytes_Check(args)) {
+			if (!PyString_Check(args)) {
 				PyErr_SetString(socket_error, "getsockaddrarg: "
 						"wrong format");
 				return 0;
 			}
-			straddr = PyBytes_AS_STRING(args);
+			straddr = PyString_AS_STRING(args);
 			if (setbdaddr(straddr, &_BT_SCO_MEMB(addr, bdaddr)) < 0)
 				return 0;
 
@@ -1368,10 +1363,10 @@
 				PyExc_TypeError,
 				"getsockaddrarg: "
 				"AF_PACKET address must be tuple, not %.500s",
-				Py_Type(args)->tp_name);
+				Py_TYPE(args)->tp_name);
 			return 0;
 		}
-		if (!PyArg_ParseTuple(args, "si|iis#", &interfaceName,
+		if (!PyArg_ParseTuple(args, "si|iiy#", &interfaceName,
 				      &protoNumber, &pkttype, &hatype,
 				      &haddr, &halen))
 			return 0;
@@ -1401,6 +1396,56 @@
 	}
 #endif
 
+#ifdef HAVE_LINUX_TIPC_H
+	case AF_TIPC:
+	{
+		unsigned int atype, v1, v2, v3;
+		unsigned int scope = TIPC_CLUSTER_SCOPE;
+		struct sockaddr_tipc *addr;
+
+		if (!PyTuple_Check(args)) {
+			PyErr_Format(
+				PyExc_TypeError,
+				"getsockaddrarg: "
+				"AF_TIPC address must be tuple, not %.500s",
+				Py_TYPE(args)->tp_name);
+			return 0;
+		}
+
+		if (!PyArg_ParseTuple(args,
+					"IIII|I;Invalid TIPC address format",
+					&atype, &v1, &v2, &v3, &scope))
+			return 0;
+
+		addr = (struct sockaddr_tipc *) addr_ret;
+		memset(addr, 0, sizeof(struct sockaddr_tipc));
+
+		addr->family = AF_TIPC;
+		addr->scope = scope;
+		addr->addrtype = atype;
+
+		if (atype == TIPC_ADDR_NAMESEQ) {
+			addr->addr.nameseq.type = v1;
+			addr->addr.nameseq.lower = v2;
+			addr->addr.nameseq.upper = v3;
+		} else if (atype == TIPC_ADDR_NAME) {
+			addr->addr.name.name.type = v1;
+			addr->addr.name.name.instance = v2;
+		} else if (atype == TIPC_ADDR_ID) {
+			addr->addr.id.node = v1;
+			addr->addr.id.ref = v2;
+		} else {
+			/* Shouldn't happen */
+			PyErr_SetString(PyExc_TypeError, "Invalid address type");
+			return 0;
+		}
+
+		*len_ret = sizeof(*addr);
+
+		return 1;
+	}
+#endif
+
 	/* More cases here... */
 
 	default:
@@ -1486,6 +1531,14 @@
 	}
 #endif
 
+#ifdef HAVE_LINUX_TIPC_H
+	case AF_TIPC:
+	{
+		*len_ret = sizeof (struct sockaddr_tipc);
+		return 1;
+	}
+#endif
+
 	/* More cases here... */
 
 	default:
@@ -1496,7 +1549,7 @@
 }
 
 
-/* s.accept() method */
+/* s._accept() -> (fd, address) */
 
 static PyObject *
 sock_accept(PySocketSockObject *s)
@@ -1530,17 +1583,12 @@
 	if (newfd == INVALID_SOCKET)
 		return s->errorhandler();
 
-	/* Create the new object with unspecified family,
-	   to avoid calls to bind() etc. on it. */
-	sock = (PyObject *) new_sockobject(newfd,
-					   s->sock_family,
-					   s->sock_type,
-					   s->sock_proto);
-
+	sock = PyLong_FromSocket_t(newfd);
 	if (sock == NULL) {
 		SOCKETCLOSE(newfd);
 		goto finally;
 	}
+
 	addr = makesockaddr(s->sock_fd, SAS2SA(&addrbuf),
 			    addrlen, s->sock_proto);
 	if (addr == NULL)
@@ -1555,11 +1603,11 @@
 }
 
 PyDoc_STRVAR(accept_doc,
-"accept() -> (socket object, address info)\n\
+"_accept() -> (integer, address info)\n\
 \n\
-Wait for an incoming connection.  Return a new socket representing the\n\
-connection, and the address of the client.  For IP sockets, the address\n\
-info is a pair (hostaddr, port).");
+Wait for an incoming connection.  Return a new socket file descriptor\n\
+representing the connection, and the address of the client.\n\
+For IP sockets, the address info is a pair (hostaddr, port).");
 
 /* s.setblocking(flag) method.  Argument:
    False -- non-blocking mode; same as settimeout(0)
@@ -1571,7 +1619,7 @@
 {
 	int block;
 
-	block = PyInt_AsLong(arg);
+	block = PyLong_AsLong(arg);
 	if (block == -1 && PyErr_Occurred())
 		return NULL;
 
@@ -1669,7 +1717,7 @@
 	}
 	else {
 		PyErr_Clear();
-		if (!PyArg_ParseTuple(args, "iis#:setsockopt",
+		if (!PyArg_ParseTuple(args, "iiy#:setsockopt",
 				      &level, &optname, &buf, &buflen))
 			return NULL;
 	}
@@ -1712,7 +1760,7 @@
 				 (void *)&flag, &flagsize);
 		if (res < 0)
 			return s->errorhandler();
-		return PyInt_FromLong(flag);
+		return PyLong_FromLong(flag);
 	}
 #ifdef __VMS
 	/* socklen_t is unsigned so no negative test is needed,
@@ -1725,19 +1773,16 @@
 				"getsockopt buflen out of range");
 		return NULL;
 	}
-	buf = PyBytes_FromStringAndSize((char *)NULL, buflen);
+	buf = PyString_FromStringAndSize((char *)NULL, buflen);
 	if (buf == NULL)
 		return NULL;
 	res = getsockopt(s->sock_fd, level, optname,
-			 (void *)PyBytes_AS_STRING(buf), &buflen);
+			 (void *)PyString_AS_STRING(buf), &buflen);
 	if (res < 0) {
 		Py_DECREF(buf);
 		return s->errorhandler();
 	}
-	if (PyBytes_Resize(buf, buflen) < 0) {
-		Py_DECREF(buf);
-		return NULL;
-	}
+	_PyString_Resize(&buf, buflen);
 	return buf;
 }
 
@@ -1859,15 +1904,22 @@
 #else
 
 	if (s->sock_timeout > 0.0) {
-		if (res < 0 && errno == EINPROGRESS && IS_SELECTABLE(s)) {
-			timeout = internal_select(s, 1);
-			if (timeout == 0) {
-				res = connect(s->sock_fd, addr, addrlen);
-				if (res < 0 && errno == EISCONN)
-					res = 0;
-			}
-			else if (timeout == -1)
-				res = errno;		/* had error */
+                if (res < 0 && errno == EINPROGRESS && IS_SELECTABLE(s)) {
+                        timeout = internal_select(s, 1);
+                        if (timeout == 0) {
+                                /* Bug #1019808: in case of an EINPROGRESS, 
+                                   use getsockopt(SO_ERROR) to get the real 
+                                   error. */
+                                socklen_t res_size = sizeof res;
+                                (void)getsockopt(s->sock_fd, SOL_SOCKET, 
+                                                 SO_ERROR, &res, &res_size);
+                                if (res == EISCONN)
+                                        res = 0;
+                                errno = res;
+                        }
+                        else if (timeout == -1) {
+                                res = errno;            /* had error */
+                        }
 			else
 				res = EWOULDBLOCK;	/* timed out */
 		}
@@ -1940,7 +1992,7 @@
 		return NULL;
 #endif
 
-	return PyInt_FromLong((long) res);
+	return PyLong_FromLong((long) res);
 }
 
 PyDoc_STRVAR(connect_ex_doc,
@@ -1955,11 +2007,7 @@
 static PyObject *
 sock_fileno(PySocketSockObject *s)
 {
-#if SIZEOF_SOCKET_T <= SIZEOF_LONG
-	return PyInt_FromLong((long) s->sock_fd);
-#else
-	return PyLong_FromLongLong((PY_LONG_LONG)s->sock_fd);
-#endif
+	return PyLong_FromSocket_t(s->sock_fd);
 }
 
 PyDoc_STRVAR(fileno_doc,
@@ -1968,35 +2016,6 @@
 Return the integer file descriptor of the socket.");
 
 
-#ifndef NO_DUP
-/* s.dup() method */
-
-static PyObject *
-sock_dup(PySocketSockObject *s)
-{
-	SOCKET_T newfd;
-	PyObject *sock;
-
-	newfd = dup(s->sock_fd);
-	if (newfd < 0)
-		return s->errorhandler();
-	sock = (PyObject *) new_sockobject(newfd,
-					   s->sock_family,
-					   s->sock_type,
-					   s->sock_proto);
-	if (sock == NULL)
-		SOCKETCLOSE(newfd);
-	return sock;
-}
-
-PyDoc_STRVAR(dup_doc,
-"dup() -> socket object\n\
-\n\
-Return a new socket object connected to the same system resource.");
-
-#endif
-
-
 /* s.getsockname() method */
 
 static PyObject *
@@ -2064,7 +2083,7 @@
 	int backlog;
 	int res;
 
-	backlog = PyInt_AsLong(arg);
+	backlog = PyLong_AsLong(arg);
 	if (backlog == -1 && PyErr_Occurred())
 		return NULL;
 	Py_BEGIN_ALLOW_THREADS
@@ -2193,12 +2212,12 @@
 	}
 
 	/* Allocate a new string. */
-	buf = PyBytes_FromStringAndSize((char *) 0, recvlen);
+	buf = PyString_FromStringAndSize((char *) 0, recvlen);
 	if (buf == NULL)
 		return NULL;
 
 	/* Call the guts */
-	outlen = sock_recv_guts(s, PyBytes_AS_STRING(buf), recvlen, flags);
+	outlen = sock_recv_guts(s, PyString_AS_STRING(buf), recvlen, flags);
 	if (outlen < 0) {
 		/* An error occurred, release the string and return an
 		   error. */
@@ -2208,9 +2227,7 @@
 	if (outlen != recvlen) {
 		/* We did not read as many bytes as we anticipated, resize the
 		   string if possible and be successful. */
-		if (PyBytes_Resize(buf, outlen) < 0)
-			/* Oopsy, not so successful after all. */
-			return NULL;
+		_PyString_Resize(&buf, outlen);
 	}
 
 	return buf;
@@ -2268,7 +2285,7 @@
 
 	/* Return the number of bytes read.  Note that we do not do anything
 	   special here in the case that readlen < recvlen. */
-	return PyInt_FromSsize_t(readlen);
+	return PyLong_FromSsize_t(readlen);
 }
 
 PyDoc_STRVAR(recv_into_doc,
@@ -2282,12 +2299,12 @@
 
 
 /*
- * This is the guts of the recv() and recv_into() methods, which reads into a
- * char buffer.  If you have any inc/def ref to do to the objects that contain
- * the buffer, do it in the caller.  This function returns the number of bytes
- * succesfully read.  If there was an error, it returns -1.  Note that it is
- * also possible that we return a number of bytes smaller than the request
- * bytes.
+ * This is the guts of the recvfrom() and recvfrom_into() methods, which reads
+ * into a char buffer.  If you have any inc/def ref to do to the objects that
+ * contain the buffer, do it in the caller.  This function returns the number
+ * of bytes succesfully read.  If there was an error, it returns -1.  Note
+ * that it is also possible that we return a number of bytes smaller than the
+ * request bytes.
  *
  * 'addr' is a return value for the address object.  Note that you must decref
  * it yourself.
@@ -2366,11 +2383,11 @@
 		return NULL;
 	}
 
-	buf = PyBytes_FromStringAndSize((char *) 0, recvlen);
+	buf = PyString_FromStringAndSize((char *) 0, recvlen);
 	if (buf == NULL)
 		return NULL;
 
-	outlen = sock_recvfrom_guts(s, PyBytes_AS_STRING(buf),
+	outlen = sock_recvfrom_guts(s, PyString_AS_STRING(buf),
 				    recvlen, flags, &addr);
 	if (outlen < 0) {
 		goto finally;
@@ -2379,7 +2396,7 @@
 	if (outlen != recvlen) {
 		/* We did not read as many bytes as we anticipated, resize the
 		   string if possible and be succesful. */
-		if (PyBytes_Resize(buf, outlen) < 0)
+		if (_PyString_Resize(&buf, outlen) < 0)
 			/* Oopsy, not so succesful after all. */
 			goto finally;
 	}
@@ -2454,7 +2471,7 @@
 	char *buf;
 	int len, n = -1, flags = 0, timeout;
 
-	if (!PyArg_ParseTuple(args, "s#|i:send", &buf, &len, &flags))
+	if (!PyArg_ParseTuple(args, "y#|i:send", &buf, &len, &flags))
 		return NULL;
 
 	if (!IS_SELECTABLE(s))
@@ -2476,7 +2493,7 @@
 	}
 	if (n < 0)
 		return s->errorhandler();
-	return PyInt_FromLong((long)n);
+	return PyLong_FromLong((long)n);
 }
 
 PyDoc_STRVAR(send_doc,
@@ -2495,7 +2512,7 @@
 	char *buf;
 	int len, n = -1, flags = 0, timeout;
 
-	if (!PyArg_ParseTuple(args, "s#|i:sendall", &buf, &len, &flags))
+	if (!PyArg_ParseTuple(args, "y#|i:sendall", &buf, &len, &flags))
 		return NULL;
 
 	if (!IS_SELECTABLE(s))
@@ -2550,9 +2567,9 @@
 	int addrlen, len, n = -1, flags, timeout;
 
 	flags = 0;
-	if (!PyArg_ParseTuple(args, "s#O:sendto", &buf, &len, &addro)) {
+	if (!PyArg_ParseTuple(args, "y#O:sendto", &buf, &len, &addro)) {
 		PyErr_Clear();
-		if (!PyArg_ParseTuple(args, "s#iO:sendto",
+		if (!PyArg_ParseTuple(args, "y#iO:sendto",
 				      &buf, &len, &flags, &addro))
 			return NULL;
 	}
@@ -2575,7 +2592,7 @@
 	}
 	if (n < 0)
 		return s->errorhandler();
-	return PyInt_FromLong((long)n);
+	return PyLong_FromLong((long)n);
 }
 
 PyDoc_STRVAR(sendto_doc,
@@ -2593,7 +2610,7 @@
 	int how;
 	int res;
 
-	how = PyInt_AsLong(arg);
+	how = PyLong_AsLong(arg);
 	if (how == -1 && PyErr_Occurred())
 		return NULL;
 	Py_BEGIN_ALLOW_THREADS
@@ -2611,11 +2628,36 @@
 Shut down the reading side of the socket (flag == SHUT_RD), the writing side\n\
 of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR).");
 
+#ifdef MS_WINDOWS
+static PyObject*
+sock_ioctl(PySocketSockObject *s, PyObject *arg)
+{
+	unsigned long cmd = SIO_RCVALL;
+	unsigned int option = RCVALL_ON;
+        DWORD recv;
+
+	if (!PyArg_ParseTuple(arg, "kI:ioctl", &cmd, &option))
+		return NULL;
+
+	if (WSAIoctl(s->sock_fd, cmd, &option, sizeof(option), 
+		     NULL, 0, &recv, NULL, NULL) == SOCKET_ERROR) {
+		return set_error();
+	}
+	return PyLong_FromUnsignedLong(recv);
+}
+PyDoc_STRVAR(sock_ioctl_doc,
+"ioctl(cmd, option) -> long\n\
+\n\
+Control the socket with WSAIoctl syscall. Currently only socket.SIO_RCVALL\n\
+is supported as control. Options must be one of the socket.RCVALL_*\n\
+constants.");
+
+#endif
 
 /* List of methods for socket objects */
 
 static PyMethodDef sock_methods[] = {
-	{"accept",	  (PyCFunction)sock_accept, METH_NOARGS,
+	{"_accept",	  (PyCFunction)sock_accept, METH_NOARGS,
 			  accept_doc},
 	{"bind",	  (PyCFunction)sock_bind, METH_O,
 			  bind_doc},
@@ -2625,10 +2667,6 @@
 			  connect_doc},
 	{"connect_ex",	  (PyCFunction)sock_connect_ex, METH_O,
 			  connect_ex_doc},
-#ifndef NO_DUP
-	{"dup",		  (PyCFunction)sock_dup, METH_NOARGS,
-			  dup_doc},
-#endif
 	{"fileno",	  (PyCFunction)sock_fileno, METH_NOARGS,
 			  fileno_doc},
 #ifdef HAVE_GETPEERNAME
@@ -2639,6 +2677,10 @@
 			  METH_NOARGS, getsockname_doc},
 	{"getsockopt",	  (PyCFunction)sock_getsockopt, METH_VARARGS,
 			  getsockopt_doc},
+#ifdef MS_WINDOWS
+	{"ioctl",	  (PyCFunction)sock_ioctl, METH_VARARGS,
+			  sock_ioctl_doc},
+#endif
 	{"listen",	  (PyCFunction)sock_listen, METH_O,
 			  listen_doc},
 	{"recv",	  (PyCFunction)sock_recv, METH_VARARGS,
@@ -2685,7 +2727,7 @@
 {
 	if (s->sock_fd != -1)
 		(void) SOCKETCLOSE(s->sock_fd);
-	Py_Type(s)->tp_free((PyObject *)s);
+	Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 
@@ -2745,8 +2787,8 @@
 					 &family, &type, &proto, &fdobj))
 		return -1;
 
-	if (fdobj != NULL) {
-		fd = PyLong_AsLongLong(fdobj);
+	if (fdobj != NULL && fdobj != Py_None) {
+		fd = PyLong_AsSocket_t(fdobj);
 		if (fd == (SOCKET_T)(-1) && PyErr_Occurred())
 			return -1;
 		if (fd == INVALID_SOCKET) {
@@ -2880,15 +2922,10 @@
 	}
 
 	if (h->h_addrtype != af) {
-#ifdef HAVE_STRERROR
 		/* Let's get real error message to return */
 		PyErr_SetString(socket_error,
 				(char *)strerror(EAFNOSUPPORT));
-#else
-		PyErr_SetString(
-			socket_error,
-			"Address family not supported by protocol family");
-#endif
+
 		return NULL;
 	}
 
@@ -3176,7 +3213,7 @@
 		PyErr_SetString(socket_error, "service/proto not found");
 		return NULL;
 	}
-	return PyInt_FromLong((long) ntohs(sp->s_port));
+	return PyLong_FromLong((long) ntohs(sp->s_port));
 }
 
 PyDoc_STRVAR(getservbyname_doc,
@@ -3236,7 +3273,7 @@
 		PyErr_SetString(socket_error, "protocol not found");
 		return NULL;
 	}
-	return PyInt_FromLong((long) sp->p_proto);
+	return PyLong_FromLong((long) sp->p_proto);
 }
 
 PyDoc_STRVAR(getprotobyname_doc,
@@ -3245,6 +3282,38 @@
 Return the protocol number for the named protocol.  (Rarely used.)");
 
 
+#ifndef NO_DUP
+/* dup() function for socket fds */
+
+static PyObject *
+socket_dup(PyObject *self, PyObject *fdobj)
+{
+	SOCKET_T fd, newfd;
+	PyObject *newfdobj;
+
+
+	fd = PyLong_AsSocket_t(fdobj);
+	if (fd == (SOCKET_T)(-1) && PyErr_Occurred())
+		return NULL;
+
+	newfd = dup_socket(fd);
+	if (newfd == INVALID_SOCKET)
+		return set_error();
+
+	newfdobj = PyLong_FromSocket_t(newfd);
+	if (newfdobj == NULL)
+		SOCKETCLOSE(newfd);
+	return newfdobj;
+}
+
+PyDoc_STRVAR(dup_doc,
+"dup(integer) -> integer\n\
+\n\
+Duplicate an integer socket file descriptor.  This is like os.dup(), but for\n\
+sockets; on some platforms os.dup() won't work for socket file descriptors.");
+#endif
+
+
 #ifdef HAVE_SOCKETPAIR
 /* Create a pair of sockets using the socketpair() function.
    Arguments as for socket() except the default family is AF_UNIX if
@@ -3315,7 +3384,7 @@
 		return NULL;
 	}
 	x2 = (unsigned int)ntohs((unsigned short)x1);
-	return PyInt_FromLong(x2);
+	return PyLong_FromLong(x2);
 }
 
 PyDoc_STRVAR(ntohs_doc,
@@ -3348,7 +3417,7 @@
 	else
 		return PyErr_Format(PyExc_TypeError,
 				    "expected int/long, %s found",
-				    Py_Type(arg)->tp_name);
+				    Py_TYPE(arg)->tp_name);
 	if (x == (unsigned long) -1 && PyErr_Occurred())
 		return NULL;
 	return PyLong_FromUnsignedLong(ntohl(x));
@@ -3374,7 +3443,7 @@
 		return NULL;
 	}
 	x2 = (unsigned int)htons((unsigned short)x1);
-	return PyInt_FromLong(x2);
+	return PyLong_FromLong(x2);
 }
 
 PyDoc_STRVAR(htons_doc,
@@ -3407,7 +3476,7 @@
 	else
 		return PyErr_Format(PyExc_TypeError,
 				    "expected int/long, %s found",
-				    Py_Type(arg)->tp_name);
+				    Py_TYPE(arg)->tp_name);
 	return PyLong_FromUnsignedLong(htonl((unsigned long)x));
 }
 
@@ -3450,7 +3519,7 @@
     if (inet_aton != NULL) {
 #endif
 	if (inet_aton(ip_addr, &buf))
-		return PyBytes_FromStringAndSize((char *)(&buf),
+		return PyString_FromStringAndSize((char *)(&buf),
 						  sizeof(buf));
 
 	PyErr_SetString(socket_error,
@@ -3479,8 +3548,8 @@
 			return NULL;
 		}
 	}
-	return PyBytes_FromStringAndSize((char *) &packed_addr,
-					 sizeof(packed_addr));
+	return PyString_FromStringAndSize((char *) &packed_addr,
+                                          sizeof(packed_addr));
 
 #ifdef USE_INET_ATON_WEAKLINK
    }
@@ -3556,12 +3625,12 @@
 			"illegal IP address string passed to inet_pton");
 		return NULL;
 	} else if (af == AF_INET) {
-		return PyBytes_FromStringAndSize(packed,
-			sizeof(struct in_addr));
+		return PyString_FromStringAndSize(packed,
+                                                  sizeof(struct in_addr));
 #ifdef ENABLE_IPV6
 	} else if (af == AF_INET6) {
-		return PyBytes_FromStringAndSize(packed,
-			sizeof(struct in6_addr));
+		return PyString_FromStringAndSize(packed,
+                                                  sizeof(struct in6_addr));
 #endif
 	} else {
 		PyErr_SetString(socket_error, "unknown address family");
@@ -3659,8 +3728,8 @@
 		idna = PyObject_CallMethod(hobj, "encode", "s", "idna");
 		if (!idna)
 			return NULL;
-		assert(PyBytes_Check(idna));
-		hptr = PyBytes_AsString(idna);
+		assert(PyString_Check(idna));
+		hptr = PyString_AS_STRING(idna);
 	} else if (PyString_Check(hobj)) {
 		hptr = PyString_AsString(hobj);
 	} else {
@@ -3668,8 +3737,11 @@
 				"getaddrinfo() argument 1 must be string or None");
 		return NULL;
 	}
-	if (PyInt_CheckExact(pobj)) {
-		PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj));
+	if (PyLong_CheckExact(pobj)) {
+		long value = PyLong_AsLong(pobj);
+		if (value == -1 && PyErr_Occurred())
+			goto err;
+		PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", value);
 		pptr = pbuf;
 	} else if (PyUnicode_Check(pobj)) {
 		pptr = PyUnicode_AsString(pobj);
@@ -3884,6 +3956,10 @@
 	 METH_VARARGS, getservbyport_doc},
 	{"getprotobyname",	socket_getprotobyname,
 	 METH_VARARGS, getprotobyname_doc},
+#ifndef NO_DUP
+	{"dup",			socket_dup,
+         METH_O, dup_doc},
+#endif
 #ifdef HAVE_SOCKETPAIR
 	{"socketpair",		socket_socketpair,
 	 METH_VARARGS, socketpair_doc},
@@ -4028,7 +4104,7 @@
 	if (!os_init())
 		return;
 
-	Py_Type(&sock_type) = &PyType_Type;
+	Py_TYPE(&sock_type) = &PyType_Type;
 	m = Py_InitModule3(PySocket_MODULE_NAME,
 			   socket_methods,
 			   socket_doc);
@@ -4178,7 +4254,7 @@
 	PyModule_AddIntConstant(m, "NETLINK_IP6_FW", NETLINK_IP6_FW);
 #ifdef NETLINK_DNRTMSG
 	PyModule_AddIntConstant(m, "NETLINK_DNRTMSG", NETLINK_DNRTMSG);
-#endif 
+#endif
 #ifdef NETLINK_TAPBASE
 	PyModule_AddIntConstant(m, "NETLINK_TAPBASE", NETLINK_TAPBASE);
 #endif
@@ -4248,6 +4324,50 @@
 	PyModule_AddIntConstant(m, "PACKET_FASTROUTE", PACKET_FASTROUTE);
 #endif
 
+#ifdef HAVE_LINUX_TIPC_H
+	PyModule_AddIntConstant(m, "AF_TIPC", AF_TIPC);
+
+	/* for addresses */
+	PyModule_AddIntConstant(m, "TIPC_ADDR_NAMESEQ", TIPC_ADDR_NAMESEQ);
+	PyModule_AddIntConstant(m, "TIPC_ADDR_NAME", TIPC_ADDR_NAME);
+	PyModule_AddIntConstant(m, "TIPC_ADDR_ID", TIPC_ADDR_ID);
+
+	PyModule_AddIntConstant(m, "TIPC_ZONE_SCOPE", TIPC_ZONE_SCOPE);
+	PyModule_AddIntConstant(m, "TIPC_CLUSTER_SCOPE", TIPC_CLUSTER_SCOPE);
+	PyModule_AddIntConstant(m, "TIPC_NODE_SCOPE", TIPC_NODE_SCOPE);
+
+	/* for setsockopt() */
+	PyModule_AddIntConstant(m, "SOL_TIPC", SOL_TIPC);
+	PyModule_AddIntConstant(m, "TIPC_IMPORTANCE", TIPC_IMPORTANCE);
+	PyModule_AddIntConstant(m, "TIPC_SRC_DROPPABLE", TIPC_SRC_DROPPABLE);
+	PyModule_AddIntConstant(m, "TIPC_DEST_DROPPABLE",
+			TIPC_DEST_DROPPABLE);
+	PyModule_AddIntConstant(m, "TIPC_CONN_TIMEOUT", TIPC_CONN_TIMEOUT);
+
+	PyModule_AddIntConstant(m, "TIPC_LOW_IMPORTANCE",
+			TIPC_LOW_IMPORTANCE);
+	PyModule_AddIntConstant(m, "TIPC_MEDIUM_IMPORTANCE",
+			TIPC_MEDIUM_IMPORTANCE);
+	PyModule_AddIntConstant(m, "TIPC_HIGH_IMPORTANCE",
+			TIPC_HIGH_IMPORTANCE);
+	PyModule_AddIntConstant(m, "TIPC_CRITICAL_IMPORTANCE",
+			TIPC_CRITICAL_IMPORTANCE);
+
+	/* for subscriptions */
+	PyModule_AddIntConstant(m, "TIPC_SUB_PORTS", TIPC_SUB_PORTS);
+	PyModule_AddIntConstant(m, "TIPC_SUB_SERVICE", TIPC_SUB_SERVICE);
+#ifdef TIPC_SUB_CANCEL
+	/* doesn't seem to be available everywhere */
+	PyModule_AddIntConstant(m, "TIPC_SUB_CANCEL", TIPC_SUB_CANCEL);
+#endif
+	PyModule_AddIntConstant(m, "TIPC_WAIT_FOREVER", TIPC_WAIT_FOREVER);
+	PyModule_AddIntConstant(m, "TIPC_PUBLISHED", TIPC_PUBLISHED);
+	PyModule_AddIntConstant(m, "TIPC_WITHDRAWN", TIPC_WITHDRAWN);
+	PyModule_AddIntConstant(m, "TIPC_SUBSCR_TIMEOUT", TIPC_SUBSCR_TIMEOUT);
+	PyModule_AddIntConstant(m, "TIPC_CFG_SRV", TIPC_CFG_SRV);
+	PyModule_AddIntConstant(m, "TIPC_TOP_SRV", TIPC_TOP_SRV);
+#endif
+
 	/* Socket types */
 	PyModule_AddIntConstant(m, "SOCK_STREAM", SOCK_STREAM);
 	PyModule_AddIntConstant(m, "SOCK_DGRAM", SOCK_DGRAM);
@@ -4860,6 +4980,21 @@
 	PyModule_AddIntConstant(m, "SHUT_RDWR", 2);
 #endif
 
+#ifdef SIO_RCVALL
+	{
+		PyObject *tmp;
+		tmp = PyLong_FromUnsignedLong(SIO_RCVALL);
+		if (tmp == NULL)
+			return;
+		PyModule_AddObject(m, "SIO_RCVALL", tmp);
+	}
+	PyModule_AddIntConstant(m, "RCVALL_OFF", RCVALL_OFF);
+	PyModule_AddIntConstant(m, "RCVALL_ON", RCVALL_ON);
+	PyModule_AddIntConstant(m, "RCVALL_SOCKETLEVELONLY", RCVALL_SOCKETLEVELONLY);
+	PyModule_AddIntConstant(m, "RCVALL_IPLEVEL", RCVALL_IPLEVEL);
+	PyModule_AddIntConstant(m, "RCVALL_MAX", RCVALL_MAX);
+#endif /* _MSTCPIP_ */
+
 	/* Initialize gethostbyname lock */
 #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK)
 	netdb_lock = PyThread_allocate_lock();
@@ -4868,6 +5003,7 @@
 
 
 #ifndef HAVE_INET_PTON
+#if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN)
 
 /* Simplistic emulation code for inet_pton that only works for IPv4 */
 /* These are not exposed because they do not set errno properly */
@@ -4903,3 +5039,4 @@
 }
 
 #endif
+#endif

Modified: python/branches/py3k-importlib/Modules/socketmodule.h
==============================================================================
--- python/branches/py3k-importlib/Modules/socketmodule.h	(original)
+++ python/branches/py3k-importlib/Modules/socketmodule.h	Thu Mar 27 00:48:05 2008
@@ -8,7 +8,7 @@
 #   include <sys/socket.h>
 # endif
 # include <netinet/in.h>
-# if defined(__CYGWIN__) || (defined(PYOS_OS2) && defined(PYCC_VACPP))
+# if !(defined(__CYGWIN__) || (defined(PYOS_OS2) && defined(PYCC_VACPP)))
 #  include <netinet/tcp.h>
 # endif
 
@@ -16,12 +16,14 @@
 #if _MSC_VER >= 1300
 # include <winsock2.h>
 # include <ws2tcpip.h>
+# include <MSTcpIP.h> /* for SIO_RCVALL */
 # define HAVE_ADDRINFO
 # define HAVE_SOCKADDR_STORAGE
 # define HAVE_GETADDRINFO
 # define HAVE_GETNAMEINFO
 # define ENABLE_IPV6
 #else
+# define WIN32_LEAN_AND_MEAN
 # include <winsock.h>
 #endif
 #endif
@@ -59,6 +61,10 @@
 # include <netpacket/packet.h>
 #endif
 
+#ifdef HAVE_LINUX_TIPC_H
+# include <linux/tipc.h>
+#endif
+
 #ifndef Py__SOCKET_H
 #define Py__SOCKET_H
 #ifdef __cplusplus
@@ -222,7 +228,7 @@
 	void *api;
 
 	DPRINTF("Importing the %s C API...\n", apimodule);
-	mod = PyImport_ImportModule(apimodule);
+	mod = PyImport_ImportModuleNoBlock(apimodule);
 	if (mod == NULL)
 		goto onError;
 	DPRINTF(" %s package found\n", apimodule);

Modified: python/branches/py3k-importlib/Modules/spwdmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/spwdmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/spwdmodule.c	Thu Mar 27 00:48:05 2008
@@ -74,7 +74,7 @@
 	if (v == NULL)
 		return NULL;
 
-#define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val))
+#define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyLong_FromLong((long) val))
 #define SETS(i,val) sets(v, i, val)
 
 	SETS(setIndex++, p->sp_namp);

Modified: python/branches/py3k-importlib/Modules/syslogmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/syslogmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/syslogmodule.c	Thu Mar 27 00:48:05 2008
@@ -100,9 +100,10 @@
 	message = PyUnicode_AsString(message_object);
 	if (message == NULL)
 		return NULL;
+	Py_BEGIN_ALLOW_THREADS;
 	syslog(priority, "%s", message);
-	Py_INCREF(Py_None);
-	return Py_None;
+	Py_END_ALLOW_THREADS;
+	Py_RETURN_NONE;
 }
 
 static PyObject * 
@@ -123,7 +124,7 @@
 	if (!PyArg_ParseTuple(args, "l;mask for priority", &maskpri))
 		return NULL;
 	omaskpri = setlogmask(maskpri);
-	return PyInt_FromLong(omaskpri);
+	return PyLong_FromLong(omaskpri);
 }
 
 static PyObject * 
@@ -134,7 +135,7 @@
 	if (!PyArg_ParseTuple(args, "l:LOG_MASK", &pri))
 		return NULL;
 	mask = LOG_MASK(pri);
-	return PyInt_FromLong(mask);
+	return PyLong_FromLong(mask);
 }
 
 static PyObject * 
@@ -145,7 +146,7 @@
 	if (!PyArg_ParseTuple(args, "l:LOG_UPTO", &pri))
 		return NULL;
 	mask = LOG_UPTO(pri);
-	return PyInt_FromLong(mask);
+	return PyLong_FromLong(mask);
 }
 
 /* List of functions defined in the module */

Modified: python/branches/py3k-importlib/Modules/termios.c
==============================================================================
--- python/branches/py3k-importlib/Modules/termios.c	(original)
+++ python/branches/py3k-importlib/Modules/termios.c	Thu Mar 27 00:48:05 2008
@@ -101,11 +101,11 @@
 	   MIN and TIME slots are the same as the EOF and EOL slots.  So we
 	   only do this in noncanonical input mode.  */
 	if ((mode.c_lflag & ICANON) == 0) {
-		v = PyInt_FromLong((long)mode.c_cc[VMIN]);
+		v = PyLong_FromLong((long)mode.c_cc[VMIN]);
 		if (v == NULL)
 			goto err;
 		PyList_SetItem(cc, VMIN, v);
-		v = PyInt_FromLong((long)mode.c_cc[VTIME]);
+		v = PyLong_FromLong((long)mode.c_cc[VTIME]);
 		if (v == NULL)
 			goto err;
 		PyList_SetItem(cc, VTIME, v);
@@ -114,12 +114,12 @@
 	if (!(v = PyList_New(7)))
 		goto err;
 
-	PyList_SetItem(v, 0, PyInt_FromLong((long)mode.c_iflag));
-	PyList_SetItem(v, 1, PyInt_FromLong((long)mode.c_oflag));
-	PyList_SetItem(v, 2, PyInt_FromLong((long)mode.c_cflag));
-	PyList_SetItem(v, 3, PyInt_FromLong((long)mode.c_lflag));
-	PyList_SetItem(v, 4, PyInt_FromLong((long)ispeed));
-	PyList_SetItem(v, 5, PyInt_FromLong((long)ospeed));
+	PyList_SetItem(v, 0, PyLong_FromLong((long)mode.c_iflag));
+	PyList_SetItem(v, 1, PyLong_FromLong((long)mode.c_oflag));
+	PyList_SetItem(v, 2, PyLong_FromLong((long)mode.c_cflag));
+	PyList_SetItem(v, 3, PyLong_FromLong((long)mode.c_lflag));
+	PyList_SetItem(v, 4, PyLong_FromLong((long)ispeed));
+	PyList_SetItem(v, 5, PyLong_FromLong((long)ospeed));
 	PyList_SetItem(v, 6, cc);
 	if (PyErr_Occurred()){
 		Py_DECREF(v);
@@ -163,12 +163,12 @@
 	/* Get the old mode, in case there are any hidden fields... */
 	if (tcgetattr(fd, &mode) == -1)
 		return PyErr_SetFromErrno(TermiosError);
-	mode.c_iflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 0));
-	mode.c_oflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 1));
-	mode.c_cflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 2));
-	mode.c_lflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 3));
-	ispeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 4));
-	ospeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 5));
+	mode.c_iflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 0));
+	mode.c_oflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 1));
+	mode.c_cflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 2));
+	mode.c_lflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 3));
+	ispeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 4));
+	ospeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 5));
 	cc = PyList_GetItem(term, 6);
 	if (PyErr_Occurred())
 		return NULL;
@@ -185,8 +185,8 @@
 
 		if (PyString_Check(v) && PyString_Size(v) == 1)
 			mode.c_cc[i] = (cc_t) * PyString_AsString(v);
-		else if (PyInt_Check(v))
-			mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
+		else if (PyLong_Check(v))
+			mode.c_cc[i] = (cc_t) PyLong_AsLong(v);
 		else {
 			PyErr_SetString(PyExc_TypeError, 
      "tcsetattr: elements of attributes must be characters or integers");

Modified: python/branches/py3k-importlib/Modules/threadmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/threadmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/threadmodule.c	Thu Mar 27 00:48:05 2008
@@ -250,7 +250,7 @@
 	}
 
 	local_clear(self);
-	Py_Type(self)->tp_free((PyObject*)self);
+	Py_TYPE(self)->tp_free((PyObject*)self);
 }
 
 static PyObject *
@@ -282,8 +282,8 @@
 		Py_INCREF(ldict);
 		self->dict = ldict; /* still borrowed */
 
-		if (Py_Type(self)->tp_init != PyBaseObject_Type.tp_init &&
-		    Py_Type(self)->tp_init((PyObject*)self, 
+		if (Py_TYPE(self)->tp_init != PyBaseObject_Type.tp_init &&
+		    Py_TYPE(self)->tp_init((PyObject*)self, 
 					   self->args, self->kw) < 0) {
 			/* we need to get rid of ldict from thread so
 			   we create a new one the next time we do an attr
@@ -386,7 +386,7 @@
 	if (ldict == NULL) 
 		return NULL;
 
-	if (Py_Type(self) != &localtype)
+	if (Py_TYPE(self) != &localtype)
 		/* use generic lookup for subtypes */
 		return PyObject_GenericGetAttr((PyObject *)self, name);
 
@@ -429,7 +429,7 @@
 			PySys_WriteStderr(
 				"Unhandled exception in thread started by ");
 			file = PySys_GetObject("stderr");
-			if (file)
+			if (file != NULL && file != Py_None)
 				PyFile_WriteObject(boot->func, file, 0);
 			else
 				PyObject_Print(boot->func, stderr, 0);
@@ -493,7 +493,7 @@
 		PyMem_DEL(boot);
 		return NULL;
 	}
-	return PyInt_FromLong(ident);
+	return PyLong_FromLong(ident);
 }
 
 PyDoc_STRVAR(start_new_doc,
@@ -571,7 +571,7 @@
 		PyErr_SetString(ThreadError, "no current thread ident");
 		return NULL;
 	}
-	return PyInt_FromLong(ident);
+	return PyLong_FromLong(ident);
 }
 
 PyDoc_STRVAR(get_ident_doc,
@@ -616,7 +616,7 @@
 		return NULL;
 	}
 
-	return PyInt_FromSsize_t((Py_ssize_t) old_size);
+	return PyLong_FromSsize_t((Py_ssize_t) old_size);
 }
 
 PyDoc_STRVAR(stack_size_doc,

Modified: python/branches/py3k-importlib/Modules/timemodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/timemodule.c	(original)
+++ python/branches/py3k-importlib/Modules/timemodule.c	Thu Mar 27 00:48:05 2008
@@ -237,7 +237,7 @@
 	if (v == NULL)
 		return NULL;
 
-#define SET(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val))
+#define SET(i,val) PyStructSequence_SET_ITEM(v, i, PyLong_FromLong((long) val))
 
 	SET(0, p->tm_year + 1900);
 	SET(1, p->tm_mon + 1);	   /* Want January == 1 */
@@ -332,7 +332,7 @@
 }
 
 PyDoc_STRVAR(gmtime_doc,
-"gmtime([seconds]) -> (tm_year, tm_mon, tm_day, tm_hour, tm_min,\n\
+"gmtime([seconds]) -> (tm_year, tm_mon, tm_mday, tm_hour, tm_min,\n\
                        tm_sec, tm_wday, tm_yday, tm_isdst)\n\
 \n\
 Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a.\n\
@@ -348,7 +348,8 @@
 }
 
 PyDoc_STRVAR(localtime_doc,
-"localtime([seconds]) -> (tm_year,tm_mon,tm_day,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst)\n\
+"localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,\n\
+			  tm_sec,tm_wday,tm_yday,tm_isdst)\n\
 \n\
 Convert seconds since the Epoch to a time tuple expressing local time.\n\
 When 'seconds' is not passed in, convert the current time instead.");
@@ -365,7 +366,7 @@
 		t = args;
 		Py_INCREF(t);
 	}
-	else if (Py_Type(args) == &StructTimeType) {
+	else if (Py_TYPE(args) == &StructTimeType) {
 		t = structtime_totuple(args);
 	}
 	else {
@@ -392,8 +393,8 @@
 	if (y < 1900) {
 		PyObject *accept = PyDict_GetItemString(moddict,
 							"accept2dyear");
-		if (accept == NULL || !PyInt_CheckExact(accept) ||
-		    PyInt_AsLong(accept) == 0) {
+		if (accept == NULL || !PyLong_CheckExact(accept) ||
+		    !PyObject_IsTrue(accept)) {
 			PyErr_SetString(PyExc_ValueError,
 					"year >= 1900 required");
 			return 0;
@@ -528,7 +529,8 @@
 			   e.g. an empty format, or %Z when the timezone
 			   is unknown. */
 			PyObject *ret;
-			ret = PyUnicode_FromStringAndSize(outbuf, buflen);
+			ret = PyUnicode_Decode(outbuf, buflen,
+					       TZNAME_ENCODING, NULL);
 			PyMem_Free(outbuf);
 			return ret;
 		}
@@ -554,12 +556,12 @@
 static PyObject *
 time_strptime(PyObject *self, PyObject *args)
 {
-    PyObject *strptime_module = PyImport_ImportModule("_strptime");
+    PyObject *strptime_module = PyImport_ImportModuleNoBlock("_strptime");
     PyObject *strptime_result;
 
     if (!strptime_module)
         return NULL;
-    strptime_result = PyObject_CallMethod(strptime_module, "strptime", "O", args);
+    strptime_result = PyObject_CallMethod(strptime_module, "_strptime_time", "O", args);
     Py_DECREF(strptime_module);
     return strptime_result;
 }
@@ -666,7 +668,7 @@
 {
 	PyObject* m;
 
-	m = PyImport_ImportModule("time");
+	m = PyImport_ImportModuleNoBlock("time");
 	if (m == NULL) {
 	    return NULL;
 	}
@@ -1035,5 +1037,3 @@
 
 	return 0;
 }
-
-

Modified: python/branches/py3k-importlib/Modules/unicodedata.c
==============================================================================
--- python/branches/py3k-importlib/Modules/unicodedata.c	(original)
+++ python/branches/py3k-importlib/Modules/unicodedata.c	Thu Mar 27 00:48:05 2008
@@ -143,7 +143,7 @@
 	    return defobj;
 	}
     }
-    return PyInt_FromLong(rc);
+    return PyLong_FromLong(rc);
 }
 
 PyDoc_STRVAR(unicodedata_digit__doc__,
@@ -178,7 +178,7 @@
 	    return defobj;
 	}
     }
-    return PyInt_FromLong(rc);
+    return PyLong_FromLong(rc);
 }
 
 PyDoc_STRVAR(unicodedata_numeric__doc__,
@@ -320,7 +320,7 @@
         if (old->category_changed == 0)
             index = 0; /* unassigned */
     }
-    return PyInt_FromLong(index);
+    return PyLong_FromLong(index);
 }
 
 PyDoc_STRVAR(unicodedata_mirrored__doc__,
@@ -350,7 +350,7 @@
         if (old->category_changed == 0)
             index = 0; /* unassigned */
     }
-    return PyInt_FromLong(index);
+    return PyLong_FromLong(index);
 }
 
 PyDoc_STRVAR(unicodedata_east_asian_width__doc__,
@@ -1187,7 +1187,7 @@
 {
     PyObject *m, *v;
 
-    Py_Type(&UCD_Type) = &PyType_Type;
+    Py_TYPE(&UCD_Type) = &PyType_Type;
 
     m = Py_InitModule3(
         "unicodedata", unicodedata_functions, unicodedata_docstring);

Modified: python/branches/py3k-importlib/Modules/xxmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/xxmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/xxmodule.c	Thu Mar 27 00:48:05 2008
@@ -25,7 +25,7 @@
 
 static PyTypeObject Xxo_Type;
 
-#define XxoObject_Check(v)	(Py_Type(v) == &Xxo_Type)
+#define XxoObject_Check(v)	(Py_TYPE(v) == &Xxo_Type)
 
 static XxoObject *
 newXxoObject(PyObject *arg)
@@ -156,7 +156,7 @@
 	if (!PyArg_ParseTuple(args, "ll:foo", &i, &j))
 		return NULL;
 	res = i+j; /* XXX Do something here */
-	return PyInt_FromLong(res);
+	return PyLong_FromLong(res);
 }
 
 
@@ -187,7 +187,7 @@
 
 	item = PyList_GetItem(list, 0);
 	/* Py_INCREF(item); */
-	PyList_SetItem(list, 1, PyInt_FromLong(0L));
+	PyList_SetItem(list, 1, PyLong_FromLong(0L));
 	PyObject_Print(item, stdout, 0);
 	printf("\n");
 	/* Py_DECREF(item); */
@@ -246,7 +246,7 @@
 	0,			/*tp_methods*/
 	0,			/*tp_members*/
 	0,			/*tp_getset*/
-	&PyUnicode_Type,	/*tp_base*/
+	0, /* see initxx */	/*tp_base*/
 	0,			/*tp_dict*/
 	0,			/*tp_descr_get*/
 	0,			/*tp_descr_set*/
@@ -301,14 +301,14 @@
 	0,			/*tp_methods*/
 	0,			/*tp_members*/
 	0,			/*tp_getset*/
-	&PyBaseObject_Type,	/*tp_base*/
+	0, /* see initxx */	/*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, /* see initxx */	/*tp_new*/
 	0,			/*tp_free*/
 	0,			/*tp_is_gc*/
 };
@@ -341,9 +341,15 @@
 {
 	PyObject *m;
 
+	/* Due to cross platform compiler issues the slots must be filled
+	 * here. It's required for portability to Windows without requiring
+	 * C++. */
+	Null_Type.tp_base = &PyBaseObject_Type;
+	Null_Type.tp_new = PyType_GenericNew;
+	Str_Type.tp_base = &PyUnicode_Type;
+
 	/* Finalize the type object including setting type of the new type
-	 * object; doing it here is required for portability to Windows 
-	 * without requiring C++. */
+	 * object; doing it here is required for portability, too. */
 	if (PyType_Ready(&Xxo_Type) < 0)
 		return;
 

Modified: python/branches/py3k-importlib/Modules/xxsubtype.c
==============================================================================
--- python/branches/py3k-importlib/Modules/xxsubtype.c	(original)
+++ python/branches/py3k-importlib/Modules/xxsubtype.c	Thu Mar 27 00:48:05 2008
@@ -28,7 +28,7 @@
 {
 	if (!PyArg_ParseTuple(args, ":getstate"))
 		return NULL;
-	return PyInt_FromLong(self->state);
+	return PyLong_FromLong(self->state);
 }
 
 static PyObject *
@@ -91,7 +91,7 @@
 static PyObject *
 spamlist_state_get(spamlistobject *self)
 {
-	return PyInt_FromLong(self->state);
+	return PyLong_FromLong(self->state);
 }
 
 static PyGetSetDef spamlist_getsets[] = {
@@ -153,7 +153,7 @@
 {
 	if (!PyArg_ParseTuple(args, ":getstate"))
 		return NULL;
-	return PyInt_FromLong(self->state);
+	return PyLong_FromLong(self->state);
 }
 
 static PyObject *

Modified: python/branches/py3k-importlib/Modules/zipimport.c
==============================================================================
--- python/branches/py3k-importlib/Modules/zipimport.c	(original)
+++ python/branches/py3k-importlib/Modules/zipimport.c	Thu Mar 27 00:48:05 2008
@@ -171,7 +171,7 @@
 	Py_XDECREF(self->archive);
 	Py_XDECREF(self->prefix);
 	Py_XDECREF(self->files);
-	Py_Type(self)->tp_free((PyObject *)self);
+	Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static PyObject *
@@ -766,7 +766,7 @@
 			   let's avoid a stack overflow. */
 			return NULL;
 		importing_zlib = 1;
-		zlib = PyImport_ImportModule("zlib");	/* import zlib */
+		zlib = PyImport_ImportModuleNoBlock("zlib");
 		importing_zlib = 0;
 		if (zlib != NULL) {
 			decompress = PyObject_GetAttrString(zlib,
@@ -1000,6 +1000,8 @@
 {
 	struct tm stm;
 
+	memset((void *) &stm, '\0', sizeof(stm));
+
 	stm.tm_sec   =  (dostime        & 0x1f) * 2;
 	stm.tm_min   =  (dostime >> 5)  & 0x3f;
 	stm.tm_hour  =  (dostime >> 11) & 0x1f;
@@ -1028,8 +1030,8 @@
 		/* fetch the time stamp of the .py file for comparison
 		   with an embedded pyc time stamp */
 		int time, date;
-		time = PyInt_AsLong(PyTuple_GetItem(toc_entry, 5));
-		date = PyInt_AsLong(PyTuple_GetItem(toc_entry, 6));
+		time = PyLong_AsLong(PyTuple_GetItem(toc_entry, 5));
+		date = PyLong_AsLong(PyTuple_GetItem(toc_entry, 6));
 		mtime = parse_dostime(time, date);
 	}
 	path[lastchar] = savechar;

Modified: python/branches/py3k-importlib/Modules/zlibmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/zlibmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/zlibmodule.c	Thu Mar 27 00:48:05 2008
@@ -197,10 +197,11 @@
     PyObject *result_str;
     Byte *input;
     int length, err;
-    int wsize=DEF_WBITS, r_strlen=DEFAULTALLOC;
+    int wsize=DEF_WBITS;
+    Py_ssize_t r_strlen=DEFAULTALLOC;
     z_stream zst;
 
-    if (!PyArg_ParseTuple(args, "s#|ii:decompress",
+    if (!PyArg_ParseTuple(args, "s#|in:decompress",
 			  &input, &length, &wsize, &r_strlen))
 	return NULL;
 
@@ -914,14 +915,14 @@
 static PyObject *
 PyZlib_adler32(PyObject *self, PyObject *args)
 {
-    uLong adler32val = adler32(0L, Z_NULL, 0);
+    uLong adler32val = 1;  /* adler32(0L, Z_NULL, 0) */
     Byte *buf;
     int len;
 
-    if (!PyArg_ParseTuple(args, "s#|k:adler32", &buf, &len, &adler32val))
+    if (!PyArg_ParseTuple(args, "s#|I:adler32", &buf, &len, &adler32val))
 	return NULL;
     adler32val = adler32(adler32val, buf, len);
-    return PyInt_FromLong(adler32val);
+    return PyLong_FromUnsignedLong(adler32val & 0xffffffffU);
 }
 
 PyDoc_STRVAR(crc32__doc__,
@@ -933,13 +934,13 @@
 static PyObject *
 PyZlib_crc32(PyObject *self, PyObject *args)
 {
-    uLong crc32val = crc32(0L, Z_NULL, 0);
+    uLong crc32val = 0;  /* crc32(0L, Z_NULL, 0) */
     Byte *buf;
     int len;
-    if (!PyArg_ParseTuple(args, "s#|k:crc32", &buf, &len, &crc32val))
+    if (!PyArg_ParseTuple(args, "s#|I:crc32", &buf, &len, &crc32val))
 	return NULL;
     crc32val = crc32(crc32val, buf, len);
-    return PyInt_FromLong(crc32val);
+    return PyLong_FromUnsignedLong(crc32val & 0xffffffffU);
 }
 
 
@@ -1011,8 +1012,8 @@
 PyInit_zlib(void)
 {
     PyObject *m, *ver;
-    Py_Type(&Comptype) = &PyType_Type;
-    Py_Type(&Decomptype) = &PyType_Type;
+    Py_TYPE(&Comptype) = &PyType_Type;
+    Py_TYPE(&Decomptype) = &PyType_Type;
     m = Py_InitModule4("zlib", zlib_methods,
 		       zlib_module_documentation,
 		       (PyObject*)NULL,PYTHON_API_VERSION);

Modified: python/branches/py3k-importlib/Objects/abstract.c
==============================================================================
--- python/branches/py3k-importlib/Objects/abstract.c	(original)
+++ python/branches/py3k-importlib/Objects/abstract.c	Thu Mar 27 00:48:05 2008
@@ -80,29 +80,47 @@
 }
 #define PyObject_Length PyObject_Size
 
+
+/* The length hint function returns a non-negative value from o.__len__()
+   or o.__length_hint__().  If those methods aren't found or return a negative
+   value, then the defaultvalue is returned.  This function never fails. 
+   Accordingly, it will mask exceptions raised in either method.
+*/
+
 Py_ssize_t
-_PyObject_LengthHint(PyObject *o)
+_PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
 {
-	Py_ssize_t rv = PyObject_Size(o);
-	if (rv != -1)
+	static PyObject *hintstrobj = NULL;
+	PyObject *ro;
+	Py_ssize_t rv;
+
+	/* try o.__len__() */
+	rv = PyObject_Size(o);
+	if (rv >= 0)
 		return rv;
-	if (PyErr_ExceptionMatches(PyExc_TypeError) ||
-	    PyErr_ExceptionMatches(PyExc_AttributeError)) {
-		PyObject *err_type, *err_value, *err_tb, *ro;
-
-		PyErr_Fetch(&err_type, &err_value, &err_tb);
-		ro = PyObject_CallMethod(o, "__length_hint__", NULL);
-		if (ro != NULL) {
-			rv = PyInt_AsLong(ro);
-			Py_DECREF(ro);
-			Py_XDECREF(err_type);
-			Py_XDECREF(err_value);
-			Py_XDECREF(err_tb);
-			return rv;
-		}
-		PyErr_Restore(err_type, err_value, err_tb);
+	if (PyErr_Occurred())
+		PyErr_Clear();
+
+	/* cache a hashed version of the attribute string */
+	if (hintstrobj == NULL) {
+		hintstrobj = PyUnicode_InternFromString("__length_hint__");
+		if (hintstrobj == NULL)
+			goto defaultcase;
 	}
-	return -1;
+
+	/* try o.__length_hint__() */
+	ro = PyObject_CallMethodObjArgs(o, hintstrobj, NULL);
+	if (ro == NULL)
+		goto defaultcase;
+	rv = PyLong_AsSsize_t(ro);
+	Py_DECREF(ro);
+	if (rv >= 0)
+		return rv;
+
+defaultcase:
+	if (PyErr_Occurred())
+		PyErr_Clear();
+	return defaultvalue;
 }
 
 PyObject *
@@ -216,7 +234,7 @@
 }
 
 /* We release the buffer right after use of this function which could
-   cause issues later on.  Don't use these functions in new code. 
+   cause issues later on.  Don't use these functions in new code.
  */
 int
 PyObject_AsCharBuffer(PyObject *obj,
@@ -248,7 +266,7 @@
 int
 PyObject_CheckReadBuffer(PyObject *obj)
 {
-	PyBufferProcs *pb = obj->ob_type->tp_as_buffer;		       
+	PyBufferProcs *pb = obj->ob_type->tp_as_buffer;
 
 	if (pb == NULL ||
 	    pb->bf_getbuffer == NULL)
@@ -305,7 +323,7 @@
 	if (pb == NULL ||
 	    pb->bf_getbuffer == NULL ||
 	    ((*pb->bf_getbuffer)(obj, &view, PyBUF_WRITABLE) != 0)) {
-		PyErr_SetString(PyExc_TypeError, 
+		PyErr_SetString(PyExc_TypeError,
 				"expected an object with a writable buffer interface");
 		return -1;
 	}
@@ -323,8 +341,9 @@
 PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
 {
 	if (!PyObject_CheckBuffer(obj)) {
-		PyErr_SetString(PyExc_TypeError,
-				"object does not have the buffer interface");
+		PyErr_Format(PyExc_TypeError,
+                             "'%100s' does not have the buffer interface",
+                             Py_TYPE(obj)->tp_name);
 		return -1;
 	}
 	return (*(obj->ob_type->tp_as_buffer->bf_getbuffer))(obj, view, flags);
@@ -333,7 +352,7 @@
 void
 PyObject_ReleaseBuffer(PyObject *obj, Py_buffer *view)
 {
-	if (obj->ob_type->tp_as_buffer != NULL && 
+	if (obj->ob_type->tp_as_buffer != NULL &&
 	    obj->ob_type->tp_as_buffer->bf_releasebuffer != NULL) {
 		(*(obj->ob_type->tp_as_buffer->bf_releasebuffer))(obj, view);
 	}
@@ -345,7 +364,7 @@
 {
 	Py_ssize_t sd, dim;
 	int i;
-	
+
 	if (view->ndim == 0) return 1;
 	if (view->strides == NULL) return (view->ndim == 1);
 
@@ -366,7 +385,7 @@
 {
 	Py_ssize_t sd, dim;
 	int i;
-	
+
 	if (view->ndim == 0) return 1;
 	if (view->strides == NULL) return 1;
 
@@ -379,7 +398,7 @@
 		if (view->strides[i] != sd) return 0;
 		sd *= dim;
 	}
-	return 1;	 
+	return 1;
 }
 
 int
@@ -390,7 +409,7 @@
 
 	if (fort == 'C')
 		return _IsCContiguous(view);
-	else if (fort == 'F') 
+	else if (fort == 'F')
 		return _IsFortranContiguous(view);
 	else if (fort == 'A')
 		return (_IsCContiguous(view) || _IsFortranContiguous(view));
@@ -398,7 +417,7 @@
 }
 
 
-void* 
+void*
 PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices)
 {
 	char* pointer;
@@ -414,11 +433,11 @@
 }
 
 
-void 
+void
 _add_one_to_index_F(int nd, Py_ssize_t *index, Py_ssize_t *shape)
 {
 	int k;
-	
+
 	for (k=0; k<nd; k++) {
 		if (index[k] < shape[k]-1) {
 			index[k]++;
@@ -430,7 +449,7 @@
 	}
 }
 
-void 
+void
 _add_one_to_index_C(int nd, Py_ssize_t *index, Py_ssize_t *shape)
 {
 	int k;
@@ -447,11 +466,11 @@
 }
 
   /* view is not checked for consistency in either of these.  It is
-     assumed that the size of the buffer is view->len in 
+     assumed that the size of the buffer is view->len in
      view->len / view->itemsize elements.
   */
 
-int 
+int
 PyBuffer_ToContiguous(void *buf, Py_buffer *view, Py_ssize_t len, char fort)
 {
 	int k;
@@ -462,7 +481,7 @@
 	if (len > view->len) {
 		len = view->len;
 	}
-	
+
 	if (PyBuffer_IsContiguous(view, fort)) {
 		/* simplest copy is all that is needed */
 		memcpy(buf, view->buf, len);
@@ -470,7 +489,7 @@
 	}
 
 	/* Otherwise a more elaborate scheme is needed */
-	
+
 	/* XXX(nnorwitz): need to check for overflow! */
 	indices = (Py_ssize_t *)PyMem_Malloc(sizeof(Py_ssize_t)*(view->ndim));
 	if (indices == NULL) {
@@ -480,7 +499,7 @@
 	for (k=0; k<view->ndim;k++) {
 		indices[k] = 0;
 	}
-	
+
 	if (fort == 'F') {
 		addone = _add_one_to_index_F;
 	}
@@ -489,7 +508,7 @@
 	}
 	dest = buf;
 	/* XXX : This is not going to be the fastest code in the world
-		 several optimizations are possible. 
+		 several optimizations are possible.
 	 */
 	elements = len / view->itemsize;
 	while (elements--) {
@@ -497,7 +516,7 @@
 		ptr = PyBuffer_GetPointer(view, indices);
 		memcpy(dest, ptr, view->itemsize);
 		dest += view->itemsize;
-	}		 
+	}
 	PyMem_Free(indices);
 	return 0;
 }
@@ -521,7 +540,7 @@
 	}
 
 	/* Otherwise a more elaborate scheme is needed */
-	
+
 	/* XXX(nnorwitz): need to check for overflow! */
 	indices = (Py_ssize_t *)PyMem_Malloc(sizeof(Py_ssize_t)*(view->ndim));
 	if (indices == NULL) {
@@ -531,7 +550,7 @@
 	for (k=0; k<view->ndim;k++) {
 		indices[k] = 0;
 	}
-	
+
 	if (fort == 'F') {
 		addone = _add_one_to_index_F;
 	}
@@ -540,7 +559,7 @@
 	}
 	src = buf;
 	/* XXX : This is not going to be the fastest code in the world
-		 several optimizations are possible. 
+		 several optimizations are possible.
 	 */
 	elements = len / view->itemsize;
 	while (elements--) {
@@ -549,12 +568,12 @@
 		memcpy(ptr, src, view->itemsize);
 		src += view->itemsize;
 	}
-		
+
 	PyMem_Free(indices);
 	return 0;
 }
 
-int PyObject_CopyData(PyObject *dest, PyObject *src) 
+int PyObject_CopyData(PyObject *dest, PyObject *src)
 {
 	Py_buffer view_dest, view_src;
 	int k;
@@ -576,16 +595,16 @@
 	}
 
 	if (view_dest.len < view_src.len) {
-		PyErr_SetString(PyExc_BufferError, 
+		PyErr_SetString(PyExc_BufferError,
 				"destination is too small to receive data from source");
 		PyObject_ReleaseBuffer(dest, &view_dest);
 		PyObject_ReleaseBuffer(src, &view_src);
 		return -1;
 	}
 
-	if ((PyBuffer_IsContiguous(&view_dest, 'C') && 
+	if ((PyBuffer_IsContiguous(&view_dest, 'C') &&
 	     PyBuffer_IsContiguous(&view_src, 'C')) ||
-	    (PyBuffer_IsContiguous(&view_dest, 'F') && 
+	    (PyBuffer_IsContiguous(&view_dest, 'F') &&
 	     PyBuffer_IsContiguous(&view_src, 'F'))) {
 		/* simplest copy is all that is needed */
 		memcpy(view_dest.buf, view_src.buf, view_src.len);
@@ -595,7 +614,7 @@
 	}
 
 	/* Otherwise a more elaborate copy scheme is needed */
-	
+
 	/* XXX(nnorwitz): need to check for overflow! */
 	indices = (Py_ssize_t *)PyMem_Malloc(sizeof(Py_ssize_t)*view_src.ndim);
 	if (indices == NULL) {
@@ -606,7 +625,7 @@
 	}
 	for (k=0; k<view_src.ndim;k++) {
 		indices[k] = 0;
-	}	 
+	}
 	elements = 1;
 	for (k=0; k<view_src.ndim; k++) {
 		/* XXX(nnorwitz): can this overflow? */
@@ -617,7 +636,7 @@
 		dptr = PyBuffer_GetPointer(&view_dest, indices);
 		sptr = PyBuffer_GetPointer(&view_src, indices);
 		memcpy(dptr, sptr, view_src.itemsize);
-	}		 
+	}
 	PyMem_Free(indices);
 	PyObject_ReleaseBuffer(dest, &view_dest);
 	PyObject_ReleaseBuffer(src, &view_src);
@@ -631,13 +650,13 @@
 {
 	int k;
 	Py_ssize_t sd;
-	
+
 	sd = itemsize;
 	if (fort == 'F') {
 		for (k=0; k<nd; k++) {
 			strides[k] = sd;
 			sd *= shape[k];
-		}				       
+		}
 	}
 	else {
 		for (k=nd-1; k>=0; k--) {
@@ -651,11 +670,11 @@
 int
 PyBuffer_FillInfo(Py_buffer *view, void *buf, Py_ssize_t len,
 	      int readonly, int flags)
-{	 
+{
 	if (view == NULL) return 0;
-	if (((flags & PyBUF_LOCK) == PyBUF_LOCK) && 
-	    readonly >= 0) {
-		PyErr_SetString(PyExc_BufferError, 
+	if (((flags & PyBUF_LOCK) == PyBUF_LOCK) &&
+	    readonly != 0) {
+		PyErr_SetString(PyExc_BufferError,
 				"Cannot lock this object.");
 		return -1;
 	}
@@ -665,13 +684,13 @@
 				"Object is not writable.");
 		return -1;
 	}
-	
+
 	view->buf = buf;
 	view->len = len;
 	view->readonly = readonly;
 	view->itemsize = 1;
 	view->format = NULL;
-	if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) 
+	if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT)
 		view->format = "B";
 	view->ndim = 1;
 	view->shape = NULL;
@@ -685,6 +704,57 @@
 	return 0;
 }
 
+PyObject *
+PyObject_Format(PyObject *obj, PyObject *format_spec)
+{
+    static PyObject * str__format__ = NULL;
+    PyObject *meth;
+    PyObject *empty = NULL;
+    PyObject *result = NULL;
+
+    /* Initialize cached value */
+    if (str__format__ == NULL) {
+        /* Initialize static variable needed by _PyType_Lookup */
+        str__format__ = PyUnicode_FromString("__format__");
+        if (str__format__ == NULL)
+            goto done;
+    }
+
+    /* If no format_spec is provided, use an empty string */
+    if (format_spec == NULL) {
+        empty = PyUnicode_FromUnicode(NULL, 0);
+        format_spec = empty;
+    }
+
+    /* Make sure the type is initialized.  float gets initialized late */
+    if (Py_TYPE(obj)->tp_dict == NULL)
+        if (PyType_Ready(Py_TYPE(obj)) < 0)
+            goto done;
+
+    /* Find the (unbound!) __format__ method (a borrowed reference) */
+    meth = _PyType_Lookup(Py_TYPE(obj), str__format__);
+    if (meth == NULL) {
+        PyErr_Format(PyExc_TypeError,
+                "Type %.100s doesn't define __format__",
+                Py_TYPE(obj)->tp_name);
+            goto done;
+    }
+
+    /* And call it, binding it to the value */
+    result = PyObject_CallFunctionObjArgs(meth, obj, format_spec, NULL);
+
+    if (result && !PyUnicode_Check(result)) {
+        PyErr_SetString(PyExc_TypeError,
+            "__format__ method did not return string");
+        Py_DECREF(result);
+        result = NULL;
+        goto done;
+    }
+
+done:
+    Py_XDECREF(empty);
+    return result;
+}
 /* Operations on numbers */
 
 int
@@ -1143,9 +1213,9 @@
 	return type_error("bad operand type for abs(): '%.200s'", o);
 }
 
-/* Return a Python Int or Long from the object item 
+/* Return a Python Int or Long from the object item
    Raise TypeError if the result is not an int-or-long
-   or if the object cannot be interpreted as an index. 
+   or if the object cannot be interpreted as an index.
 */
 PyObject *
 PyNumber_Index(PyObject *item)
@@ -1187,25 +1257,25 @@
 	if (value == NULL)
 		return -1;
 
-	/* We're done if PyInt_AsSsize_t() returns without error. */
-	result = PyInt_AsSsize_t(value);
+	/* We're done if PyLong_AsSsize_t() returns without error. */
+	result = PyLong_AsSsize_t(value);
 	if (result != -1 || !(runerr = PyErr_Occurred()))
 		goto finish;
 
 	/* Error handling code -- only manage OverflowError differently */
-	if (!PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) 
+	if (!PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError))
 		goto finish;
 
 	PyErr_Clear();
-	/* If no error-handling desired then the default clipping 
+	/* If no error-handling desired then the default clipping
 	   is sufficient.
 	 */
 	if (!err) {
 		assert(PyLong_Check(value));
-		/* Whether or not it is less than or equal to 
+		/* Whether or not it is less than or equal to
 		   zero is determined by the sign of ob_size
 		*/
-		if (_PyLong_Sign(value) < 0) 
+		if (_PyLong_Sign(value) < 0)
 			result = PY_SSIZE_T_MIN;
 		else
 			result = PY_SSIZE_T_MAX;
@@ -1213,16 +1283,50 @@
 	else {
 		/* Otherwise replace the error with caller's error object. */
 		PyErr_Format(err,
-			     "cannot fit '%.200s' into an index-sized integer", 
-			     item->ob_type->tp_name); 
+			     "cannot fit '%.200s' into an index-sized integer",
+			     item->ob_type->tp_name);
 	}
-	
+
  finish:
 	Py_DECREF(value);
 	return result;
 }
 
 
+PyObject *
+_PyNumber_ConvertIntegralToInt(PyObject *integral, const char* error_format)
+{
+	static PyObject *int_name = NULL;
+	if (int_name == NULL) {
+		int_name = PyUnicode_InternFromString("__int__");
+		if (int_name == NULL)
+			return NULL;
+	}
+
+	if (integral && !PyLong_Check(integral)) { 
+		/* Don't go through tp_as_number->nb_int to avoid
+		   hitting the classic class fallback to __trunc__. */
+		PyObject *int_func = PyObject_GetAttr(integral, int_name);
+		if (int_func == NULL) {
+			PyErr_Clear(); /* Raise a different error. */
+			goto non_integral_error;
+		}
+		Py_DECREF(integral);
+		integral = PyEval_CallObject(int_func, NULL);
+		Py_DECREF(int_func);
+		if (integral && !PyLong_Check(integral)) { 
+			goto non_integral_error;
+		}
+	}
+	return integral;
+
+non_integral_error:
+	PyErr_Format(PyExc_TypeError, error_format, Py_TYPE(integral)->tp_name);
+	Py_DECREF(integral);
+	return NULL;
+}
+
+
 /* Add a check for embedded NULL-bytes in the argument. */
 static PyObject *
 long_from_string(const char *s, Py_ssize_t len)
@@ -1246,9 +1350,17 @@
 PyNumber_Long(PyObject *o)
 {
 	PyNumberMethods *m;
+	static PyObject *trunc_name = NULL;
+	PyObject *trunc_func;
 	const char *buffer;
 	Py_ssize_t buffer_len;
 
+	if (trunc_name == NULL) {
+		trunc_name = PyUnicode_InternFromString("__trunc__");
+		if (trunc_name == NULL)
+			return NULL;
+	}
+
 	if (o == NULL)
 		return null_error();
 	if (PyLong_CheckExact(o)) {
@@ -1268,6 +1380,7 @@
 		return res;
 	}
 	if (m && m->nb_long) { /* This should include subclasses of long */
+		/* Classic classes always take this branch. */
 		PyObject *res = m->nb_long(o);
 		if (res && !PyLong_Check(res)) {
 			PyErr_Format(PyExc_TypeError,
@@ -1280,6 +1393,27 @@
 	}
 	if (PyLong_Check(o)) /* A long subclass without nb_long */
 		return _PyLong_Copy((PyLongObject *)o);
+	trunc_func = PyObject_GetAttr(o, trunc_name);
+	if (trunc_func) {
+		PyObject *truncated = PyEval_CallObject(trunc_func, NULL);
+		PyObject *int_instance;
+		Py_DECREF(trunc_func);
+		/* __trunc__ is specified to return an Integral type,
+		   but long() needs to return a long. */
+		int_instance = _PyNumber_ConvertIntegralToInt(
+			truncated,
+			"__trunc__ returned non-Integral (type %.200s)");
+		return int_instance;
+	}
+	PyErr_Clear();  /* It's not an error if  o.__trunc__ doesn't exist. */
+
+	if (PyString_Check(o))
+		/* need to do extra error checking that PyLong_FromString()
+		 * doesn't do.  In particular long('9.5') must raise an
+		 * exception, not truncate the float.
+		 */
+		return long_from_string(PyString_AS_STRING(o),
+					PyString_GET_SIZE(o));
 	if (PyUnicode_Check(o))
 		/* The above check is done in PyLong_FromUnicode(). */
 		return PyLong_FromUnicode(PyUnicode_AS_UNICODE(o),
@@ -1322,13 +1456,19 @@
 PyObject *
 PyNumber_ToBase(PyObject *n, int base)
 {
-	PyObject *res;
+	PyObject *res = NULL;
 	PyObject *index = PyNumber_Index(n);
 
 	if (!index)
 		return NULL;
-	assert(PyLong_Check(index));
-	res = _PyLong_Format(index, base);
+	if (PyLong_Check(index))
+		res = _PyLong_Format(index, base);
+	else
+		/* It should not be possible to get here, as
+		   PyNumber_Index already has a check for the same
+		   condition */
+		PyErr_SetString(PyExc_ValueError, "PyNumber_ToBase: index not "
+				"int or long");
 	Py_DECREF(index);
 	return res;
 }
@@ -1412,7 +1552,7 @@
 	   to nb_multiply if o appears to be a sequence. */
 	if (PySequence_Check(o)) {
 		PyObject *n, *result;
-		n = PyInt_FromSsize_t(count);
+		n = PyLong_FromSsize_t(count);
 		if (n == NULL)
 			return NULL;
 		result = binary_op1(o, n, NB_SLOT(nb_multiply));
@@ -1464,7 +1604,7 @@
 
 	if (PySequence_Check(o)) {
 		PyObject *n, *result;
-		n = PyInt_FromSsize_t(count);
+		n = PyLong_FromSsize_t(count);
 		if (n == NULL)
 			return NULL;
 		result = binary_iop1(o, n, NB_SLOT(nb_inplace_multiply),
@@ -1654,16 +1794,7 @@
 		return NULL;
 
 	/* Guess result size and allocate space. */
-	n = _PyObject_LengthHint(v);
-	if (n < 0) {
-		if (!PyErr_ExceptionMatches(PyExc_TypeError)  &&
-		    !PyErr_ExceptionMatches(PyExc_AttributeError)) {
-			Py_DECREF(it);
-			return NULL;
-		}
-		PyErr_Clear();
-		n = 10;	 /* arbitrary */
-	}
+	n = _PyObject_LengthHint(v, 10);
 	result = PyTuple_New(n);
 	if (result == NULL)
 		goto Fail;
@@ -1679,7 +1810,7 @@
 		if (j >= n) {
 			Py_ssize_t oldn = n;
 			/* The over-allocation strategy can grow a bit faster
-			   than for lists because unlike lists the 
+			   than for lists because unlike lists the
 			   over-allocation isn't permanent -- we reclaim
 			   the excess before the end of this routine.
 			   So, grow by ten and then add 25%.
@@ -1690,7 +1821,7 @@
 				/* Check for overflow */
 				PyErr_NoMemory();
 				Py_DECREF(item);
-				goto Fail; 
+				goto Fail;
 			}
 			if (_PyTuple_Resize(&result, n) != 0) {
 				Py_DECREF(item);
@@ -2147,7 +2278,7 @@
 	}
 
 	if (!PyCallable_Check(func)) {
-		type_error("attribute of type '%.200s' is not callable", func); 
+		type_error("attribute of type '%.200s' is not callable", func);
 		goto exit;
 	}
 
@@ -2186,7 +2317,7 @@
 	}
 
 	if (!PyCallable_Check(func)) {
-		type_error("attribute of type '%.200s' is not callable", func); 
+		type_error("attribute of type '%.200s' is not callable", func);
 		goto exit;
 	}
 
@@ -2323,7 +2454,7 @@
 	PyObject *bases;
 
 	if (__bases__ == NULL) {
-		__bases__ = PyUnicode_FromString("__bases__");
+		__bases__ = PyUnicode_InternFromString("__bases__");
 		if (__bases__ == NULL)
 			return NULL;
 	}
@@ -2403,7 +2534,7 @@
 	int retval = 0;
 
 	if (__class__ == NULL) {
-		__class__ = PyUnicode_FromString("__class__");
+		__class__ = PyUnicode_InternFromString("__class__");
 		if (__class__ == NULL)
 			return -1;
 	}
@@ -2466,11 +2597,21 @@
 int
 PyObject_IsInstance(PyObject *inst, PyObject *cls)
 {
-	PyObject *t, *v, *tb;
+	static PyObject *name = NULL;
 	PyObject *checker;
-	PyErr_Fetch(&t, &v, &tb);
-	checker = PyObject_GetAttrString(cls, "__instancecheck__");
-	PyErr_Restore(t, v, tb);
+
+	/* Quick test for an exact match */
+	if (Py_TYPE(inst) == (PyTypeObject *)cls)
+		return 1;
+
+	if (name == NULL) {
+		name = PyUnicode_InternFromString("__instancecheck__");
+		if (name == NULL)
+			return -1;
+	}
+	checker = PyObject_GetAttr(cls, name);
+	if (checker == NULL && PyErr_Occurred())
+		PyErr_Clear();
 	if (checker != NULL) {
 		PyObject *res;
 		int ok = -1;
@@ -2537,10 +2678,17 @@
 int
 PyObject_IsSubclass(PyObject *derived, PyObject *cls)
 {
+	static PyObject *name = NULL;
 	PyObject *t, *v, *tb;
 	PyObject *checker;
 	PyErr_Fetch(&t, &v, &tb);
-	checker = PyObject_GetAttrString(cls, "__subclasscheck__");
+	
+	if (name == NULL) {
+		name = PyUnicode_InternFromString("__subclasscheck__");
+		if (name == NULL)
+			return -1;
+	}
+	checker = PyObject_GetAttr(cls, name);
 	PyErr_Restore(t, v, tb);
 	if (checker != NULL) {
 		PyObject *res;

Modified: python/branches/py3k-importlib/Objects/bytesobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/bytesobject.c	(original)
+++ python/branches/py3k-importlib/Objects/bytesobject.c	Thu Mar 27 00:48:05 2008
@@ -1,15 +1,10 @@
-/* Bytes object implementation */
-
-/* XXX TO DO: optimizations */
+/* PyBytes (bytearray) implementation */
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
 #include "structmember.h"
+#include "bytes_methods.h"
 
-/* The nullbytes are used by the stringlib during partition.
- * If partition is removed from bytes, nullbytes and its helper
- * Init/Fini should also be removed.
- */
 static PyBytesObject *nullbytes = NULL;
 
 void
@@ -25,7 +20,7 @@
     if (nullbytes == NULL)
         return 0;
     nullbytes->ob_bytes = NULL;
-    Py_Size(nullbytes) = nullbytes->ob_alloc = 0;
+    Py_SIZE(nullbytes) = nullbytes->ob_alloc = 0;
     nullbytes->ob_exports = 0;
     return 1;
 }
@@ -37,15 +32,20 @@
 static int
 _getbytevalue(PyObject* arg, int *value)
 {
-    PyObject *intarg = PyNumber_Int(arg);
-    if (! intarg)
-        return 0;
-    *value = PyInt_AsLong(intarg);
-    Py_DECREF(intarg);
-    if (*value < 0 || *value >= 256) {
-        PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
+    long face_value;
+
+    if (PyLong_Check(arg)) {
+        face_value = PyLong_AsLong(arg);
+        if (face_value < 0 || face_value >= 256) {
+            PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
+            return 0;
+        }
+    } else {
+        PyErr_Format(PyExc_TypeError, "an integer is required");
         return 0;
     }
+
+    *value = face_value;
     return 1;
 }
 
@@ -62,7 +62,7 @@
                 ptr = "";
         else
                 ptr = obj->ob_bytes;
-        ret = PyBuffer_FillInfo(view, ptr, Py_Size(obj), 0, flags);
+        ret = PyBuffer_FillInfo(view, ptr, Py_SIZE(obj), 0, flags);
         if (ret >= 0) {
                 obj->ob_exports++;
         }
@@ -78,15 +78,13 @@
 static Py_ssize_t
 _getbuffer(PyObject *obj, Py_buffer *view)
 {
-    PyBufferProcs *buffer = Py_Type(obj)->tp_as_buffer;
+    PyBufferProcs *buffer = Py_TYPE(obj)->tp_as_buffer;
 
-    if (buffer == NULL ||
-        PyUnicode_Check(obj) ||
-        buffer->bf_getbuffer == NULL)
+    if (buffer == NULL || buffer->bf_getbuffer == NULL)
     {
         PyErr_Format(PyExc_TypeError,
                      "Type %.100s doesn't support the buffer API",
-                     Py_Type(obj)->tp_name);
+                     Py_TYPE(obj)->tp_name);
         return -1;
     }
 
@@ -108,7 +106,7 @@
 PyBytes_FromStringAndSize(const char *bytes, Py_ssize_t size)
 {
     PyBytesObject *new;
-    int alloc;
+    Py_ssize_t alloc;
 
     assert(size >= 0);
 
@@ -131,7 +129,7 @@
             memcpy(new->ob_bytes, bytes, size);
         new->ob_bytes[size] = '\0';  /* Trailing null byte */
     }
-    Py_Size(new) = size;
+    Py_SIZE(new) = size;
     new->ob_alloc = alloc;
     new->ob_exports = 0;
 
@@ -172,7 +170,7 @@
     }
     else if (size < alloc) {
         /* Within allocated size; quick exit */
-        Py_Size(self) = size;
+        Py_SIZE(self) = size;
         ((PyBytesObject *)self)->ob_bytes[size] = '\0'; /* Trailing null */
         return 0;
     }
@@ -202,7 +200,7 @@
     }
 
     ((PyBytesObject *)self)->ob_bytes = sval;
-    Py_Size(self) = size;
+    Py_SIZE(self) = size;
     ((PyBytesObject *)self)->ob_alloc = alloc;
     ((PyBytesObject *)self)->ob_bytes[size] = '\0'; /* Trailing null byte */
 
@@ -214,26 +212,21 @@
 {
     Py_ssize_t size;
     Py_buffer va, vb;
-    PyBytesObject *result;
+    PyBytesObject *result = NULL;
 
     va.len = -1;
     vb.len = -1;
     if (_getbuffer(a, &va) < 0  ||
         _getbuffer(b, &vb) < 0) {
-            if (va.len != -1)
-                    PyObject_ReleaseBuffer(a, &va);
-            if (vb.len != -1)
-                    PyObject_ReleaseBuffer(b, &vb);
             PyErr_Format(PyExc_TypeError, "can't concat %.100s to %.100s",
-                         Py_Type(a)->tp_name, Py_Type(b)->tp_name);
-            return NULL;
+                         Py_TYPE(a)->tp_name, Py_TYPE(b)->tp_name);
+            goto done;
     }
 
     size = va.len + vb.len;
     if (size < 0) {
-            PyObject_ReleaseBuffer(a, &va);
-            PyObject_ReleaseBuffer(b, &vb);
             return PyErr_NoMemory();
+            goto done;
     }
 
     result = (PyBytesObject *) PyBytes_FromStringAndSize(NULL, size);
@@ -242,8 +235,11 @@
         memcpy(result->ob_bytes + va.len, vb.buf, vb.len);
     }
 
-    PyObject_ReleaseBuffer(a, &va);
-    PyObject_ReleaseBuffer(b, &vb);
+  done:
+    if (va.len != -1)
+        PyObject_ReleaseBuffer(a, &va);
+    if (vb.len != -1)
+        PyObject_ReleaseBuffer(b, &vb);
     return (PyObject *)result;
 }
 
@@ -252,13 +248,7 @@
 static Py_ssize_t
 bytes_length(PyBytesObject *self)
 {
-    return Py_Size(self);
-}
-
-static PyObject *
-bytes_concat(PyBytesObject *self, PyObject *other)
-{
-    return PyBytes_Concat((PyObject *)self, other);
+    return Py_SIZE(self);
 }
 
 static PyObject *
@@ -270,19 +260,19 @@
 
     if (_getbuffer(other, &vo) < 0) {
         PyErr_Format(PyExc_TypeError, "can't concat bytes to %.100s",
-                     Py_Type(self)->tp_name);
+                     Py_TYPE(self)->tp_name);
         return NULL;
     }
 
-    mysize = Py_Size(self);
+    mysize = Py_SIZE(self);
     size = mysize + vo.len;
     if (size < 0) {
         PyObject_ReleaseBuffer(other, &vo);
         return PyErr_NoMemory();
     }
     if (size < self->ob_alloc) {
-        Py_Size(self) = size;
-        self->ob_bytes[Py_Size(self)] = '\0'; /* Trailing null byte */
+        Py_SIZE(self) = size;
+        self->ob_bytes[Py_SIZE(self)] = '\0'; /* Trailing null byte */
     }
     else if (PyBytes_Resize((PyObject *)self, size) < 0) {
         PyObject_ReleaseBuffer(other, &vo);
@@ -303,7 +293,7 @@
 
     if (count < 0)
         count = 0;
-    mysize = Py_Size(self);
+    mysize = Py_SIZE(self);
     size = mysize * count;
     if (count != 0 && size / count != mysize)
         return PyErr_NoMemory();
@@ -328,13 +318,13 @@
 
     if (count < 0)
         count = 0;
-    mysize = Py_Size(self);
+    mysize = Py_SIZE(self);
     size = mysize * count;
     if (count != 0 && size / count != mysize)
         return PyErr_NoMemory();
     if (size < self->ob_alloc) {
-        Py_Size(self) = size;
-        self->ob_bytes[Py_Size(self)] = '\0'; /* Trailing null byte */
+        Py_SIZE(self) = size;
+        self->ob_bytes[Py_SIZE(self)] = '\0'; /* Trailing null byte */
     }
     else if (PyBytes_Resize((PyObject *)self, size) < 0)
         return NULL;
@@ -351,54 +341,16 @@
     return (PyObject *)self;
 }
 
-static int
-bytes_substring(PyBytesObject *self, PyBytesObject *other)
-{
-    Py_ssize_t i;
-
-    if (Py_Size(other) == 1) {
-        return memchr(self->ob_bytes, other->ob_bytes[0],
-                      Py_Size(self)) != NULL;
-    }
-    if (Py_Size(other) == 0)
-        return 1; /* Edge case */
-    for (i = 0; i + Py_Size(other) <= Py_Size(self); i++) {
-        /* XXX Yeah, yeah, lots of optimizations possible... */
-        if (memcmp(self->ob_bytes + i, other->ob_bytes, Py_Size(other)) == 0)
-            return 1;
-    }
-    return 0;
-}
-
-static int
-bytes_contains(PyBytesObject *self, PyObject *value)
-{
-    Py_ssize_t ival;
-
-    if (PyBytes_Check(value))
-        return bytes_substring(self, (PyBytesObject *)value);
-
-    ival = PyNumber_AsSsize_t(value, PyExc_ValueError);
-    if (ival == -1 && PyErr_Occurred())
-        return -1;
-    if (ival < 0 || ival >= 256) {
-        PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
-        return -1;
-    }
-
-    return memchr(self->ob_bytes, ival, Py_Size(self)) != NULL;
-}
-
 static PyObject *
 bytes_getitem(PyBytesObject *self, Py_ssize_t i)
 {
     if (i < 0)
-        i += Py_Size(self);
-    if (i < 0 || i >= Py_Size(self)) {
-        PyErr_SetString(PyExc_IndexError, "bytes index out of range");
+        i += Py_SIZE(self);
+    if (i < 0 || i >= Py_SIZE(self)) {
+        PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
         return NULL;
     }
-    return PyInt_FromLong((unsigned char)(self->ob_bytes[i]));
+    return PyLong_FromLong((unsigned char)(self->ob_bytes[i]));
 }
 
 static PyObject *
@@ -413,11 +365,11 @@
         if (i < 0)
             i += PyBytes_GET_SIZE(self);
 
-        if (i < 0 || i >= Py_Size(self)) {
-            PyErr_SetString(PyExc_IndexError, "bytes index out of range");
+        if (i < 0 || i >= Py_SIZE(self)) {
+            PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
             return NULL;
         }
-        return PyInt_FromLong((unsigned char)(self->ob_bytes[i]));
+        return PyLong_FromLong((unsigned char)(self->ob_bytes[i]));
     }
     else if (PySlice_Check(item)) {
         Py_ssize_t start, stop, step, slicelength, cur, i;
@@ -451,7 +403,7 @@
         }
     }
     else {
-        PyErr_SetString(PyExc_TypeError, "bytes indices must be integers");
+        PyErr_SetString(PyExc_TypeError, "bytearray indices must be integers");
         return NULL;
     }
 }
@@ -485,7 +437,7 @@
             if (_getbuffer(values, &vbytes) < 0) {
                     PyErr_Format(PyExc_TypeError,
                                  "can't set bytes slice from %.100s",
-                                 Py_Type(values)->tp_name);
+                                 Py_TYPE(values)->tp_name);
                     return -1;
             }
             needed = vbytes.len;
@@ -496,8 +448,8 @@
         lo = 0;
     if (hi < lo)
         hi = lo;
-    if (hi > Py_Size(self))
-        hi = Py_Size(self);
+    if (hi > Py_SIZE(self))
+        hi = Py_SIZE(self);
 
     avail = hi - lo;
     if (avail < 0)
@@ -512,11 +464,11 @@
               0   lo      new_hi              new_size
             */
             memmove(self->ob_bytes + lo + needed, self->ob_bytes + hi,
-                    Py_Size(self) - hi);
+                    Py_SIZE(self) - hi);
         }
         /* XXX(nnorwitz): need to verify this can't overflow! */
         if (PyBytes_Resize((PyObject *)self,
-                           Py_Size(self) + needed - avail) < 0) {
+                           Py_SIZE(self) + needed - avail) < 0) {
                 res = -1;
                 goto finish;
         }
@@ -528,7 +480,7 @@
               0   lo            new_hi              new_size
              */
             memmove(self->ob_bytes + lo + needed, self->ob_bytes + hi,
-                    Py_Size(self) - lo - needed);
+                    Py_SIZE(self) - lo - needed);
         }
     }
 
@@ -548,10 +500,10 @@
     Py_ssize_t ival;
 
     if (i < 0)
-        i += Py_Size(self);
+        i += Py_SIZE(self);
 
-    if (i < 0 || i >= Py_Size(self)) {
-        PyErr_SetString(PyExc_IndexError, "bytes index out of range");
+    if (i < 0 || i >= Py_SIZE(self)) {
+        PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
         return -1;
     }
 
@@ -586,8 +538,8 @@
         if (i < 0)
             i += PyBytes_GET_SIZE(self);
 
-        if (i < 0 || i >= Py_Size(self)) {
-            PyErr_SetString(PyExc_IndexError, "bytes index out of range");
+        if (i < 0 || i >= Py_SIZE(self)) {
+            PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
             return -1;
         }
 
@@ -619,7 +571,7 @@
         }
     }
     else {
-        PyErr_SetString(PyExc_TypeError, "bytes indices must be integer");
+        PyErr_SetString(PyExc_TypeError, "bytearray indices must be integer");
         return -1;
     }
 
@@ -640,7 +592,7 @@
     else {
         assert(PyBytes_Check(values));
         bytes = ((PyBytesObject *)values)->ob_bytes;
-        needed = Py_Size(values);
+        needed = Py_SIZE(values);
     }
     /* Make sure b[5:2] = ... inserts before 5, not before 2. */
     if ((step < 0 && start < stop) ||
@@ -656,10 +608,10 @@
                   0   lo      new_hi              new_size
                 */
                 memmove(self->ob_bytes + start + needed, self->ob_bytes + stop,
-                        Py_Size(self) - stop);
+                        Py_SIZE(self) - stop);
             }
             if (PyBytes_Resize((PyObject *)self,
-                               Py_Size(self) + needed - slicelen) < 0)
+                               Py_SIZE(self) + needed - slicelen) < 0)
                 return -1;
             if (slicelen < needed) {
                 /*
@@ -669,7 +621,7 @@
                   0   lo            new_hi              new_size
                  */
                 memmove(self->ob_bytes + start + needed, self->ob_bytes + stop,
-                        Py_Size(self) - start - needed);
+                        Py_SIZE(self) - start - needed);
             }
         }
 
@@ -740,7 +692,7 @@
     PyObject *it;
     PyObject *(*iternext)(PyObject *);
 
-    if (Py_Size(self) != 0) {
+    if (Py_SIZE(self) != 0) {
         /* Empty previous contents (yes, do this first of all!) */
         if (PyBytes_Resize((PyObject *)self, 0) < 0)
             return -1;
@@ -772,13 +724,7 @@
         encoded = PyCodec_Encode(arg, encoding, errors);
         if (encoded == NULL)
             return -1;
-        if (!PyBytes_Check(encoded) && !PyString_Check(encoded)) {
-            PyErr_Format(PyExc_TypeError,
-                "encoder did not return a str8 or bytes object (type=%.400s)",
-                Py_Type(encoded)->tp_name);
-            Py_DECREF(encoded);
-            return -1;
-        }
+        assert(PyString_Check(encoded));
         new = bytes_iconcat(self, encoded);
         Py_DECREF(encoded);
         if (new == NULL)
@@ -811,7 +757,7 @@
         return 0;
     }
 
-    /* Use the modern buffer interface */
+    /* Use the buffer API */
     if (PyObject_CheckBuffer(arg)) {
         Py_ssize_t size;
         Py_buffer view;
@@ -834,7 +780,7 @@
     it = PyObject_GetIter(arg);
     if (it == NULL)
         return -1;
-    iternext = *Py_Type(it)->tp_iternext;
+    iternext = *Py_TYPE(it)->tp_iternext;
 
     /* Run the iterator to exhaustion */
     for (;;) {
@@ -866,11 +812,11 @@
         }
 
         /* Append the byte */
-        if (Py_Size(self) < self->ob_alloc)
-            Py_Size(self)++;
-        else if (PyBytes_Resize((PyObject *)self, Py_Size(self)+1) < 0)
+        if (Py_SIZE(self) < self->ob_alloc)
+            Py_SIZE(self)++;
+        else if (PyBytes_Resize((PyObject *)self, Py_SIZE(self)+1) < 0)
             goto error;
-        self->ob_bytes[Py_Size(self)-1] = value;
+        self->ob_bytes[Py_SIZE(self)-1] = value;
     }
 
     /* Clean up and return success */
@@ -889,11 +835,15 @@
 bytes_repr(PyBytesObject *self)
 {
     static const char *hexdigits = "0123456789abcdef";
-    size_t newsize = 3 + 4 * Py_Size(self);
+    const char *quote_prefix = "bytearray(b";
+    const char *quote_postfix = ")";
+    Py_ssize_t length = Py_SIZE(self);
+    /* 14 == strlen(quote_prefix) + 2 + strlen(quote_postfix) */
+    size_t newsize = 14 + 4 * length;
     PyObject *v;
-    if (newsize > PY_SSIZE_T_MAX || newsize / 4 != Py_Size(self)) {
+    if (newsize > PY_SSIZE_T_MAX || newsize / 4 - 3 != length) {
         PyErr_SetString(PyExc_OverflowError,
-            "bytes object is too large to make repr");
+            "bytearray object is too large to make repr");
         return NULL;
     }
     v = PyUnicode_FromUnicode(NULL, newsize);
@@ -904,17 +854,36 @@
         register Py_ssize_t i;
         register Py_UNICODE c;
         register Py_UNICODE *p;
-        int quote = '\'';
+        int quote;
+
+        /* Figure out which quote to use; single is preferred */
+        quote = '\'';
+        {
+            char *test, *start;
+            start = PyBytes_AS_STRING(self);
+            for (test = start; test < start+length; ++test) {
+                if (*test == '"') {
+                    quote = '\''; /* back to single */
+                    goto decided;
+                }
+                else if (*test == '\'')
+                    quote = '"';
+            }
+          decided:
+            ;
+        }
 
         p = PyUnicode_AS_UNICODE(v);
-        *p++ = 'b';
+        while (*quote_prefix)
+            *p++ = *quote_prefix++;
         *p++ = quote;
-        for (i = 0; i < Py_Size(self); i++) {
+
+        for (i = 0; i < length; i++) {
             /* There's at least enough room for a hex escape
                and a closing quote. */
             assert(newsize - (p - PyUnicode_AS_UNICODE(v)) >= 5);
             c = self->ob_bytes[i];
-            if (c == quote || c == '\\')
+            if (c == '\'' || c == '\\')
                 *p++ = '\\', *p++ = c;
             else if (c == '\t')
                 *p++ = '\\', *p++ = 't';
@@ -935,6 +904,9 @@
         }
         assert(newsize - (p - PyUnicode_AS_UNICODE(v)) >= 1);
         *p++ = quote;
+        while (*quote_postfix) {
+           *p++ = *quote_postfix++;
+        }
         *p = '\0';
         if (PyUnicode_Resize(&v, (p - PyUnicode_AS_UNICODE(v)))) {
             Py_DECREF(v);
@@ -945,9 +917,14 @@
 }
 
 static PyObject *
-bytes_str(PyBytesObject *self)
+bytes_str(PyObject *op)
 {
-    return PyString_FromStringAndSize(self->ob_bytes, Py_Size(self));
+	if (Py_BytesWarningFlag) {
+		if (PyErr_WarnEx(PyExc_BytesWarning,
+				 "str() on a bytearray instance", 1))
+			return NULL;
+	}
+	return bytes_repr((PyBytesObject*)op);
 }
 
 static PyObject *
@@ -964,6 +941,12 @@
        error, even if the comparison is for equality. */
     if (PyObject_IsInstance(self, (PyObject*)&PyUnicode_Type) ||
         PyObject_IsInstance(other, (PyObject*)&PyUnicode_Type)) {
+        if (Py_BytesWarningFlag && op == Py_EQ) {
+            if (PyErr_WarnEx(PyExc_BytesWarning,
+                            "Comparsion between bytearray and string", 1))
+                return NULL;
+        }
+
         Py_INCREF(Py_NotImplemented);
         return Py_NotImplemented;
     }
@@ -1025,7 +1008,7 @@
     if (self->ob_bytes != 0) {
         PyMem_Free(self->ob_bytes);
     }
-    Py_Type(self)->tp_free((PyObject *)self);
+    Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 
@@ -1035,13 +1018,18 @@
 #define STRINGLIB_CHAR char
 #define STRINGLIB_CMP memcmp
 #define STRINGLIB_LEN PyBytes_GET_SIZE
+#define STRINGLIB_STR PyBytes_AS_STRING
 #define STRINGLIB_NEW PyBytes_FromStringAndSize
 #define STRINGLIB_EMPTY nullbytes
+#define STRINGLIB_CHECK_EXACT PyBytes_CheckExact
+#define STRINGLIB_MUTABLE 1
 
 #include "stringlib/fastsearch.h"
 #include "stringlib/count.h"
 #include "stringlib/find.h"
 #include "stringlib/partition.h"
+#include "stringlib/ctype.h"
+#include "stringlib/transmogrify.h"
 
 
 /* The following Py_LOCAL_INLINE and Py_LOCAL functions
@@ -1088,7 +1076,6 @@
     return res;
 }
 
-
 PyDoc_STRVAR(find__doc__,
 "B.find(sub [,start [,end]]) -> int\n\
 \n\
@@ -1104,11 +1091,11 @@
     Py_ssize_t result = bytes_find_internal(self, args, +1);
     if (result == -2)
         return NULL;
-    return PyInt_FromSsize_t(result);
+    return PyLong_FromSsize_t(result);
 }
 
 PyDoc_STRVAR(count__doc__,
-"B.count(sub[, start[, end]]) -> int\n\
+"B.count(sub [,start [,end]]) -> int\n\
 \n\
 Return the number of non-overlapping occurrences of subsection sub in\n\
 bytes B[start:end].  Optional arguments start and end are interpreted\n\
@@ -1118,27 +1105,25 @@
 bytes_count(PyBytesObject *self, PyObject *args)
 {
     PyObject *sub_obj;
-    const char *str = PyBytes_AS_STRING(self), *sub;
-    Py_ssize_t sub_len;
+    const char *str = PyBytes_AS_STRING(self);
     Py_ssize_t start = 0, end = PY_SSIZE_T_MAX;
+    Py_buffer vsub;
+    PyObject *count_obj;
 
     if (!PyArg_ParseTuple(args, "O|O&O&:count", &sub_obj,
         _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
         return NULL;
 
-    if (PyBytes_Check(sub_obj)) {
-        sub = PyBytes_AS_STRING(sub_obj);
-        sub_len = PyBytes_GET_SIZE(sub_obj);
-    }
-    /* XXX --> use the modern buffer interface */
-    else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len))
+    if (_getbuffer(sub_obj, &vsub) < 0)
         return NULL;
 
     _adjust_indices(&start, &end, PyBytes_GET_SIZE(self));
 
-    return PyInt_FromSsize_t(
-        stringlib_count(str + start, end - start, sub, sub_len)
+    count_obj = PyLong_FromSsize_t(
+        stringlib_count(str + start, end - start, vsub.buf, vsub.len)
         );
+    PyObject_ReleaseBuffer(sub_obj, &vsub);
+    return count_obj;
 }
 
 
@@ -1158,7 +1143,7 @@
                         "subsection not found");
         return NULL;
     }
-    return PyInt_FromSsize_t(result);
+    return PyLong_FromSsize_t(result);
 }
 
 
@@ -1177,7 +1162,7 @@
     Py_ssize_t result = bytes_find_internal(self, args, -1);
     if (result == -2)
         return NULL;
-    return PyInt_FromSsize_t(result);
+    return PyLong_FromSsize_t(result);
 }
 
 
@@ -1197,7 +1182,31 @@
                         "subsection not found");
         return NULL;
     }
-    return PyInt_FromSsize_t(result);
+    return PyLong_FromSsize_t(result);
+}
+
+
+static int
+bytes_contains(PyObject *self, PyObject *arg)
+{
+    Py_ssize_t ival = PyNumber_AsSsize_t(arg, PyExc_ValueError);
+    if (ival == -1 && PyErr_Occurred()) {
+        Py_buffer varg;
+        int pos;
+        PyErr_Clear();
+        if (_getbuffer(arg, &varg) < 0)
+            return -1;
+        pos = stringlib_find(PyBytes_AS_STRING(self), Py_SIZE(self),
+                             varg.buf, varg.len, 0);
+        PyObject_ReleaseBuffer(arg, &varg);
+        return pos >= 0;
+    }
+    if (ival < 0 || ival >= 256) {
+        PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
+        return -1;
+    }
+
+    return memchr(PyBytes_AS_STRING(self), ival, Py_SIZE(self)) != NULL;
 }
 
 
@@ -1210,41 +1219,42 @@
                  Py_ssize_t end, int direction)
 {
     Py_ssize_t len = PyBytes_GET_SIZE(self);
-    Py_ssize_t slen;
-    const char* sub;
     const char* str;
+    Py_buffer vsubstr;
+    int rv = 0;
 
-    if (PyBytes_Check(substr)) {
-        sub = PyBytes_AS_STRING(substr);
-        slen = PyBytes_GET_SIZE(substr);
-    }
-    /* XXX --> Use the modern buffer interface */
-    else if (PyObject_AsCharBuffer(substr, &sub, &slen))
-        return -1;
     str = PyBytes_AS_STRING(self);
 
+    if (_getbuffer(substr, &vsubstr) < 0)
+        return -1;
+
     _adjust_indices(&start, &end, len);
 
     if (direction < 0) {
         /* startswith */
-        if (start+slen > len)
-            return 0;
+        if (start+vsubstr.len > len) {
+            goto done;
+        }
     } else {
         /* endswith */
-        if (end-start < slen || start > len)
-            return 0;
+        if (end-start < vsubstr.len || start > len) {
+            goto done;
+        }
 
-        if (end-slen > start)
-            start = end - slen;
+        if (end-vsubstr.len > start)
+            start = end - vsubstr.len;
     }
-    if (end-start >= slen)
-        return ! memcmp(str+start, sub, slen);
-    return 0;
+    if (end-start >= vsubstr.len)
+        rv = ! memcmp(str+start, vsubstr.buf, vsubstr.len);
+
+done:
+    PyObject_ReleaseBuffer(substr, &vsubstr);
+    return rv;
 }
 
 
 PyDoc_STRVAR(startswith__doc__,
-"B.startswith(prefix[, start[, end]]) -> bool\n\
+"B.startswith(prefix [,start [,end]]) -> bool\n\
 \n\
 Return True if B starts with the specified prefix, False otherwise.\n\
 With optional start, test B beginning at that position.\n\
@@ -1284,7 +1294,7 @@
 }
 
 PyDoc_STRVAR(endswith__doc__,
-"B.endswith(suffix[, start[, end]]) -> bool\n\
+"B.endswith(suffix [,start [,end]]) -> bool\n\
 \n\
 Return True if B ends with the specified suffix, False otherwise.\n\
 With optional start, test B beginning at that position.\n\
@@ -1324,14 +1334,13 @@
 }
 
 
-
 PyDoc_STRVAR(translate__doc__,
-"B.translate(table [,deletechars]) -> bytes\n\
+"B.translate(table[, deletechars]) -> bytearray\n\
 \n\
-Return a copy of the bytes B, where all characters occurring\n\
-in the optional argument deletechars are removed, and the\n\
-remaining characters have been mapped through the given\n\
-translation table, which must be a bytes of length 256.");
+Return a copy of B, where all characters occurring in the\n\
+optional argument deletechars are removed, and the remaining\n\
+characters have been mapped through the given translation\n\
+table, which must be a bytes object of length 256.");
 
 static PyObject *
 bytes_translate(PyBytesObject *self, PyObject *args)
@@ -1340,53 +1349,47 @@
     register const char *table;
     register Py_ssize_t i, c, changed = 0;
     PyObject *input_obj = (PyObject*)self;
-    const char *table1, *output_start, *del_table=NULL;
-    Py_ssize_t inlen, tablen, dellen = 0;
+    const char *output_start;
+    Py_ssize_t inlen;
     PyObject *result;
     int trans_table[256];
     PyObject *tableobj, *delobj = NULL;
+    Py_buffer vtable, vdel;
 
     if (!PyArg_UnpackTuple(args, "translate", 1, 2,
                            &tableobj, &delobj))
           return NULL;
 
-    if (PyBytes_Check(tableobj)) {
-        table1 = PyBytes_AS_STRING(tableobj);
-        tablen = PyBytes_GET_SIZE(tableobj);
-    }
-    /* XXX -> Use the modern buffer interface */
-    else if (PyObject_AsCharBuffer(tableobj, &table1, &tablen))
+    if (_getbuffer(tableobj, &vtable) < 0)
         return NULL;
 
-    if (tablen != 256) {
+    if (vtable.len != 256) {
         PyErr_SetString(PyExc_ValueError,
                         "translation table must be 256 characters long");
-        return NULL;
+        result = NULL;
+        goto done;
     }
 
     if (delobj != NULL) {
-        if (PyBytes_Check(delobj)) {
-            del_table = PyBytes_AS_STRING(delobj);
-            dellen = PyBytes_GET_SIZE(delobj);
+        if (_getbuffer(delobj, &vdel) < 0) {
+            result = NULL;
+            goto done;
         }
-        /* XXX -> use the modern buffer interface */
-        else if (PyObject_AsCharBuffer(delobj, &del_table, &dellen))
-            return NULL;
     }
     else {
-        del_table = NULL;
-        dellen = 0;
+        vdel.buf = NULL;
+        vdel.len = 0;
     }
 
-    table = table1;
+    table = (const char *)vtable.buf;
     inlen = PyBytes_GET_SIZE(input_obj);
     result = PyBytes_FromStringAndSize((char *)NULL, inlen);
     if (result == NULL)
-        return NULL;
+        goto done;
     output_start = output = PyBytes_AsString(result);
     input = PyBytes_AS_STRING(input_obj);
 
-    if (dellen == 0) {
+    if (vdel.len == 0) {
         /* If no deletions are required, use faster code */
         for (i = inlen; --i >= 0; ) {
             c = Py_CHARMASK(*input++);
@@ -1394,17 +1397,18 @@
                 changed = 1;
         }
         if (changed || !PyBytes_CheckExact(input_obj))
-            return result;
+            goto done;
         Py_DECREF(result);
         Py_INCREF(input_obj);
-        return input_obj;
+        result = input_obj;
+        goto done;
     }
 
     for (i = 0; i < 256; i++)
         trans_table[i] = Py_CHARMASK(table[i]);
 
-    for (i = 0; i < dellen; i++)
-        trans_table[(int) Py_CHARMASK(del_table[i])] = -1;
+    for (i = 0; i < vdel.len; i++)
+        trans_table[(int) Py_CHARMASK( ((unsigned char*)vdel.buf)[i] )] = -1;
 
     for (i = inlen; --i >= 0; ) {
         c = Py_CHARMASK(*input++);
@@ -1416,11 +1420,17 @@
     if (!changed && PyBytes_CheckExact(input_obj)) {
         Py_DECREF(result);
         Py_INCREF(input_obj);
-        return input_obj;
+        result = input_obj;
+        goto done;
     }
     /* Fix the size of the resulting string */
     if (inlen > 0)
         PyBytes_Resize(result, output - output_start);
+
+done:
+    PyObject_ReleaseBuffer(tableobj, &vtable);
+    if (delobj != NULL)
+        PyObject_ReleaseBuffer(delobj, &vdel);
     return result;
 }
 
@@ -1455,7 +1465,7 @@
 }
 
 Py_LOCAL_INLINE(Py_ssize_t)
-countchar(const char *target, int target_len, char c, Py_ssize_t maxcount)
+countchar(const char *target, Py_ssize_t target_len, char c, Py_ssize_t maxcount)
 {
     Py_ssize_t count=0;
     const char *start=target;
@@ -2021,10 +2031,11 @@
     }
 }
 
+
 PyDoc_STRVAR(replace__doc__,
-"B.replace (old, new[, count]) -> bytes\n\
+"B.replace(old, new[, count]) -> bytes\n\
 \n\
-Return a copy of bytes B with all occurrences of subsection\n\
+Return a copy of B with all occurrences of subsection\n\
 old replaced by new.  If the optional argument count is\n\
 given, only the first count occurrences are replaced.");
 
@@ -2098,7 +2109,7 @@
     count++; }
 
 /* Always force the list to the expected size. */
-#define FIX_PREALLOC_SIZE(list) Py_Size(list) = count
+#define FIX_PREALLOC_SIZE(list) Py_SIZE(list) = count
 
 
 Py_LOCAL_INLINE(PyObject *)
@@ -2133,7 +2144,6 @@
     return NULL;
 }
 
-#define ISSPACE(c) (isspace(Py_CHARMASK(c)) && ((c) & 0x80) == 0)
 
 Py_LOCAL_INLINE(PyObject *)
 split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxcount)
@@ -2146,23 +2156,23 @@
         return NULL;
 
     for (i = j = 0; i < len; ) {
-	/* find a token */
-	while (i < len && ISSPACE(s[i]))
-	    i++;
-	j = i;
-	while (i < len && !ISSPACE(s[i]))
-	    i++;
-	if (j < i) {
-	    if (maxcount-- <= 0)
-		break;
-	    SPLIT_ADD(s, j, i);
-	    while (i < len && ISSPACE(s[i]))
-		i++;
-	    j = i;
-	}
+        /* find a token */
+        while (i < len && ISSPACE(s[i]))
+            i++;
+        j = i;
+        while (i < len && !ISSPACE(s[i]))
+            i++;
+        if (j < i) {
+            if (maxcount-- <= 0)
+                break;
+            SPLIT_ADD(s, j, i);
+            while (i < len && ISSPACE(s[i]))
+                i++;
+            j = i;
+        }
     }
     if (j < len) {
-	SPLIT_ADD(s, j, len);
+        SPLIT_ADD(s, j, len);
     }
     FIX_PREALLOC_SIZE(list);
     return list;
@@ -2173,10 +2183,10 @@
 }
 
 PyDoc_STRVAR(split__doc__,
-"B.split([sep [, maxsplit]]) -> list of bytes\n\
+"B.split([sep[, maxsplit]]) -> list of bytearray\n\
 \n\
-Return a list of the bytes in the string B, using sep as the delimiter.\n\
-If sep is not given, B is split on ASCII whitespace charcters\n\
+Return a list of the sections in B, using sep as the delimiter.\n\
+If sep is not given, B is split on ASCII whitespace characters\n\
 (space, tab, return, newline, formfeed, vertical tab).\n\
 If maxsplit is given, at most maxsplit splits are done.");
 
@@ -2252,12 +2262,37 @@
     return NULL;
 }
 
+/* stringlib's partition shares nullbytes in some cases.
+   undo this, we don't want the nullbytes to be shared. */
+static PyObject *
+make_nullbytes_unique(PyObject *result)
+{
+    if (result != NULL) {
+        int i;
+        assert(PyTuple_Check(result));
+        assert(PyTuple_GET_SIZE(result) == 3);
+        for (i = 0; i < 3; i++) {
+            if (PyTuple_GET_ITEM(result, i) == (PyObject *)nullbytes) {
+                PyObject *new = PyBytes_FromStringAndSize(NULL, 0);
+                if (new == NULL) {
+                    Py_DECREF(result);
+                    result = NULL;
+                    break;
+                }
+                Py_DECREF(nullbytes);
+                PyTuple_SET_ITEM(result, i, new);
+            }
+        }
+    }
+    return result;
+}
+
 PyDoc_STRVAR(partition__doc__,
 "B.partition(sep) -> (head, sep, tail)\n\
 \n\
 Searches for the separator sep in B, and returns the part before it,\n\
 the separator itself, and the part after it.  If the separator is not\n\
-found, returns B and two empty bytes.");
+found, returns B and two empty bytearray objects.");
 
 static PyObject *
 bytes_partition(PyBytesObject *self, PyObject *sep_obj)
@@ -2276,15 +2311,16 @@
             );
 
     Py_DECREF(bytesep);
-    return result;
+    return make_nullbytes_unique(result);
 }
 
 PyDoc_STRVAR(rpartition__doc__,
 "B.rpartition(sep) -> (tail, sep, head)\n\
 \n\
-Searches for the separator sep in B, starting at the end of B, and returns\n\
-the part before it, the separator itself, and the part after it.  If the\n\
-separator is not found, returns two empty bytes and B.");
+Searches for the separator sep in B, starting at the end of B,\n\
+and returns the part before it, the separator itself, and the\n\
+part after it.  If the separator is not found, returns two empty\n\
+bytearray objects and B.");
 
 static PyObject *
 bytes_rpartition(PyBytesObject *self, PyObject *sep_obj)
@@ -2303,7 +2339,7 @@
             );
 
     Py_DECREF(bytesep);
-    return result;
+    return make_nullbytes_unique(result);
 }
 
 Py_LOCAL_INLINE(PyObject *)
@@ -2351,23 +2387,23 @@
         return NULL;
 
     for (i = j = len - 1; i >= 0; ) {
-	/* find a token */
-	while (i >= 0 && Py_UNICODE_ISSPACE(s[i]))
-	    i--;
-	j = i;
-	while (i >= 0 && !Py_UNICODE_ISSPACE(s[i]))
-	    i--;
-	if (j > i) {
-	    if (maxcount-- <= 0)
-		break;
-	    SPLIT_ADD(s, i + 1, j + 1);
-	    while (i >= 0 && Py_UNICODE_ISSPACE(s[i]))
-		i--;
-	    j = i;
-	}
+        /* find a token */
+        while (i >= 0 && ISSPACE(s[i]))
+            i--;
+        j = i;
+        while (i >= 0 && !ISSPACE(s[i]))
+            i--;
+        if (j > i) {
+            if (maxcount-- <= 0)
+                break;
+            SPLIT_ADD(s, i + 1, j + 1);
+            while (i >= 0 && ISSPACE(s[i]))
+                i--;
+            j = i;
+        }
     }
     if (j >= 0) {
-	SPLIT_ADD(s, 0, j + 1);
+        SPLIT_ADD(s, 0, j + 1);
     }
     FIX_PREALLOC_SIZE(list);
     if (PyList_Reverse(list) < 0)
@@ -2381,10 +2417,10 @@
 }
 
 PyDoc_STRVAR(rsplit__doc__,
-"B.rsplit(sep [,maxsplit]) -> list of bytes\n\
+"B.rsplit(sep[, maxsplit]) -> list of bytearray\n\
 \n\
-Return a list of the sections in the byte B, using sep as the delimiter,\n\
-starting at the end of the bytes and working to the front.\n\
+Return a list of the sections in B, using sep as the delimiter,\n\
+starting at the end of B and working to the front.\n\
 If sep is not given, B is split on ASCII whitespace characters\n\
 (space, tab, return, newline, formfeed, vertical tab).\n\
 If maxsplit is given, at most maxsplit splits are done.");
@@ -2451,29 +2487,15 @@
     return NULL;
 }
 
-PyDoc_STRVAR(extend__doc__,
-"B.extend(iterable int) -> None\n\
-\n\
-Append all the elements from the iterator or sequence to the\n\
-end of the bytes.");
-static PyObject *
-bytes_extend(PyBytesObject *self, PyObject *arg)
-{
-    if (bytes_setslice(self, Py_Size(self), Py_Size(self), arg) == -1)
-        return NULL;
-    Py_RETURN_NONE;
-}
-
-
 PyDoc_STRVAR(reverse__doc__,
 "B.reverse() -> None\n\
 \n\
-Reverse the order of the values in bytes in place.");
+Reverse the order of the values in B in place.");
 static PyObject *
 bytes_reverse(PyBytesObject *self, PyObject *unused)
 {
     char swap, *head, *tail;
-    Py_ssize_t i, j, n = Py_Size(self);
+    Py_ssize_t i, j, n = Py_SIZE(self);
 
     j = n / 2;
     head = self->ob_bytes;
@@ -2490,12 +2512,12 @@
 PyDoc_STRVAR(insert__doc__,
 "B.insert(index, int) -> None\n\
 \n\
-Insert a single item into the bytes before the given index.");
+Insert a single item into the bytearray before the given index.");
 static PyObject *
 bytes_insert(PyBytesObject *self, PyObject *args)
 {
     int value;
-    Py_ssize_t where, n = Py_Size(self);
+    Py_ssize_t where, n = Py_SIZE(self);
 
     if (!PyArg_ParseTuple(args, "ni:insert", &where, &value))
         return NULL;
@@ -2529,12 +2551,12 @@
 PyDoc_STRVAR(append__doc__,
 "B.append(int) -> None\n\
 \n\
-Append a single item to the end of the bytes.");
+Append a single item to the end of B.");
 static PyObject *
 bytes_append(PyBytesObject *self, PyObject *arg)
 {
     int value;
-    Py_ssize_t n = Py_Size(self);
+    Py_ssize_t n = Py_SIZE(self);
 
     if (! _getbytevalue(arg, &value))
         return NULL;
@@ -2551,16 +2573,76 @@
     Py_RETURN_NONE;
 }
 
+PyDoc_STRVAR(extend__doc__,
+"B.extend(iterable int) -> None\n\
+\n\
+Append all the elements from the iterator or sequence to the\n\
+end of B.");
+static PyObject *
+bytes_extend(PyBytesObject *self, PyObject *arg)
+{
+    PyObject *it, *item, *tmp, *res;
+    Py_ssize_t buf_size = 0, len = 0;
+    int value;
+    char *buf;
+
+    /* bytes_setslice code only accepts something supporting PEP 3118. */
+    if (PyObject_CheckBuffer(arg)) {
+        if (bytes_setslice(self, Py_SIZE(self), Py_SIZE(self), arg) == -1)
+            return NULL;
+
+        Py_RETURN_NONE;
+    }
+
+    it = PyObject_GetIter(arg);
+    if (it == NULL)
+        return NULL;
+
+    /* Try to determine the length of the argument. 32 is abitrary. */
+    buf_size = _PyObject_LengthHint(arg, 32);
+
+    buf = (char *)PyMem_Malloc(buf_size * sizeof(char));
+    if (buf == NULL)
+        return PyErr_NoMemory();
+
+    while ((item = PyIter_Next(it)) != NULL) {
+        if (! _getbytevalue(item, &value)) {
+            Py_DECREF(item);
+            Py_DECREF(it);
+            return NULL;
+        }
+        buf[len++] = value;
+        Py_DECREF(item);
+        if (len >= buf_size) {
+            buf_size = len + (len >> 1) + 1;
+            buf = (char *)PyMem_Realloc(buf, buf_size * sizeof(char));
+            if (buf == NULL) {
+                Py_DECREF(it);
+                return PyErr_NoMemory();
+            }
+        }
+    }
+    Py_DECREF(it);
+
+    /* XXX: Is possible to avoid a full copy of the buffer? */
+    tmp = PyBytes_FromStringAndSize(buf, len);
+    res = bytes_extend(self, tmp);
+    Py_DECREF(tmp);
+    PyMem_Free(buf);
+
+    return res;
+}
+
 PyDoc_STRVAR(pop__doc__,
 "B.pop([index]) -> int\n\
 \n\
-Remove and return a single item from the bytes. If no index\n\
+Remove and return a single item from B. If no index\n\
 argument is give, will pop the last value.");
 static PyObject *
 bytes_pop(PyBytesObject *self, PyObject *args)
 {
     int value;
-    Py_ssize_t where = -1, n = Py_Size(self);
+    Py_ssize_t where = -1, n = Py_SIZE(self);
 
     if (!PyArg_ParseTuple(args, "|n:pop", &where))
         return NULL;
@@ -2571,8 +2653,8 @@
         return NULL;
     }
     if (where < 0)
-        where += Py_Size(self);
-    if (where < 0 || where >= Py_Size(self)) {
+        where += Py_SIZE(self);
+    if (where < 0 || where >= Py_SIZE(self)) {
         PyErr_SetString(PyExc_IndexError, "pop index out of range");
         return NULL;
     }
@@ -2582,18 +2664,18 @@
     if (PyBytes_Resize((PyObject *)self, n - 1) < 0)
         return NULL;
 
-    return PyInt_FromLong(value);
+    return PyLong_FromLong(value);
 }
 
 PyDoc_STRVAR(remove__doc__,
 "B.remove(int) -> None\n\
 \n\
-Remove the first occurance of a value in bytes");
+Remove the first occurance of a value in B.");
 static PyObject *
 bytes_remove(PyBytesObject *self, PyObject *arg)
 {
     int value;
-    Py_ssize_t where, n = Py_Size(self);
+    Py_ssize_t where, n = Py_SIZE(self);
 
     if (! _getbytevalue(arg, &value))
         return NULL;
@@ -2637,7 +2719,7 @@
 }
 
 PyDoc_STRVAR(strip__doc__,
-"B.strip([bytes]) -> bytes\n\
+"B.strip([bytes]) -> bytearray\n\
 \n\
 Strip leading and trailing bytes contained in the argument.\n\
 If the argument is omitted, strip ASCII whitespace.");
@@ -2655,25 +2737,25 @@
         argsize = 6;
     }
     else {
-	    if (_getbuffer(arg, &varg) < 0)
-		    return NULL;
-	    argptr = varg.buf;
-	    argsize = varg.len;
+        if (_getbuffer(arg, &varg) < 0)
+            return NULL;
+        argptr = varg.buf;
+        argsize = varg.len;
     }
     myptr = self->ob_bytes;
-    mysize = Py_Size(self);
+    mysize = Py_SIZE(self);
     left = lstrip_helper(myptr, mysize, argptr, argsize);
     if (left == mysize)
         right = left;
     else
         right = rstrip_helper(myptr, mysize, argptr, argsize);
     if (arg != Py_None)
-	    PyObject_ReleaseBuffer(arg, &varg);
+        PyObject_ReleaseBuffer(arg, &varg);
     return PyBytes_FromStringAndSize(self->ob_bytes + left, right - left);
 }
 
 PyDoc_STRVAR(lstrip__doc__,
-"B.lstrip([bytes]) -> bytes\n\
+"B.lstrip([bytes]) -> bytearray\n\
 \n\
 Strip leading bytes contained in the argument.\n\
 If the argument is omitted, strip leading ASCII whitespace.");
@@ -2691,22 +2773,22 @@
         argsize = 6;
     }
     else {
-	    if (_getbuffer(arg, &varg) < 0)
-		    return NULL;
-	    argptr = varg.buf;
-	    argsize = varg.len;
+        if (_getbuffer(arg, &varg) < 0)
+            return NULL;
+        argptr = varg.buf;
+        argsize = varg.len;
     }
     myptr = self->ob_bytes;
-    mysize = Py_Size(self);
+    mysize = Py_SIZE(self);
     left = lstrip_helper(myptr, mysize, argptr, argsize);
     right = mysize;
     if (arg != Py_None)
-	    PyObject_ReleaseBuffer(arg, &varg);
+        PyObject_ReleaseBuffer(arg, &varg);
     return PyBytes_FromStringAndSize(self->ob_bytes + left, right - left);
 }
 
 PyDoc_STRVAR(rstrip__doc__,
-"B.rstrip([bytes]) -> bytes\n\
+"B.rstrip([bytes]) -> bytearray\n\
 \n\
 Strip trailing bytes contained in the argument.\n\
 If the argument is omitted, strip trailing ASCII whitespace.");
@@ -2724,28 +2806,28 @@
         argsize = 6;
     }
     else {
-	    if (_getbuffer(arg, &varg) < 0)
-		    return NULL;
-	    argptr = varg.buf;
-	    argsize = varg.len;
+        if (_getbuffer(arg, &varg) < 0)
+            return NULL;
+        argptr = varg.buf;
+        argsize = varg.len;
     }
     myptr = self->ob_bytes;
-    mysize = Py_Size(self);
+    mysize = Py_SIZE(self);
     left = 0;
     right = rstrip_helper(myptr, mysize, argptr, argsize);
     if (arg != Py_None)
-	    PyObject_ReleaseBuffer(arg, &varg);
+        PyObject_ReleaseBuffer(arg, &varg);
     return PyBytes_FromStringAndSize(self->ob_bytes + left, right - left);
 }
 
 PyDoc_STRVAR(decode_doc,
-"B.decode([encoding[,errors]]) -> unicode obect.\n\
+"B.decode([encoding[, errors]]) -> unicode object.\n\
 \n\
 Decodes B using the codec registered for encoding. encoding defaults\n\
 to the default encoding. errors may be given to set a different error\n\
-handling scheme. Default is 'strict' meaning that encoding errors raise\n\
-a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n\
-as well as any other name registerd with codecs.register_error that is\n\
+handling scheme.  Default is 'strict' meaning that encoding errors raise\n\
+a UnicodeDecodeError.  Other possible values are 'ignore' and 'replace'\n\
+as well as any other name registered with codecs.register_error that is\n\
 able to handle UnicodeDecodeErrors.");
 
 static PyObject *
@@ -2769,20 +2851,19 @@
 static PyObject *
 bytes_alloc(PyBytesObject *self)
 {
-    return PyInt_FromSsize_t(self->ob_alloc);
+    return PyLong_FromSsize_t(self->ob_alloc);
 }
 
 PyDoc_STRVAR(join_doc,
 "B.join(iterable_of_bytes) -> bytes\n\
 \n\
-Concatenates any number of bytes objects, with B in between each pair.\n\
-Example: b'.'.join([b'ab', b'pq', b'rs']) -> b'ab.pq.rs'.");
+Concatenates any number of bytearray objects, with B in between each pair.");
 
 static PyObject *
 bytes_join(PyBytesObject *self, PyObject *it)
 {
     PyObject *seq;
-    Py_ssize_t mysize = Py_Size(self);
+    Py_ssize_t mysize = Py_SIZE(self);
     Py_ssize_t i;
     Py_ssize_t n;
     PyObject **items;
@@ -2797,19 +2878,20 @@
     items = PySequence_Fast_ITEMS(seq);
 
     /* Compute the total size, and check that they are all bytes */
+    /* XXX Shouldn't we use _getbuffer() on these items instead? */
     for (i = 0; i < n; i++) {
         PyObject *obj = items[i];
-        if (!PyBytes_Check(obj)) {
+        if (!PyBytes_Check(obj) && !PyString_Check(obj)) {
             PyErr_Format(PyExc_TypeError,
                          "can only join an iterable of bytes "
                          "(item %ld has type '%.100s')",
                          /* XXX %ld isn't right on Win64 */
-                         (long)i, Py_Type(obj)->tp_name);
+                         (long)i, Py_TYPE(obj)->tp_name);
             goto error;
         }
         if (i > 0)
             totalsize += mysize;
-        totalsize += PyBytes_GET_SIZE(obj);
+        totalsize += Py_SIZE(obj);
         if (totalsize < 0) {
             PyErr_NoMemory();
             goto error;
@@ -2823,12 +2905,17 @@
     dest = PyBytes_AS_STRING(result);
     for (i = 0; i < n; i++) {
         PyObject *obj = items[i];
-        Py_ssize_t size = PyBytes_GET_SIZE(obj);
-        if (i > 0) {
+        Py_ssize_t size = Py_SIZE(obj);
+        char *buf;
+        if (PyBytes_Check(obj))
+           buf = PyBytes_AS_STRING(obj);
+        else
+           buf = PyString_AS_STRING(obj);
+        if (i) {
             memcpy(dest, self->ob_bytes, mysize);
             dest += mysize;
         }
-        memcpy(dest, PyBytes_AS_STRING(obj), size);
+        memcpy(dest, buf, size);
         dest += size;
     }
 
@@ -2843,20 +2930,22 @@
 }
 
 PyDoc_STRVAR(fromhex_doc,
-"bytes.fromhex(string) -> bytes\n\
+"bytearray.fromhex(string) -> bytearray\n\
 \n\
-Create a bytes object from a string of hexadecimal numbers.\n\
-Spaces between two numbers are accepted. Example:\n\
-bytes.fromhex('10 2030') -> bytes([0x10, 0x20, 0x30]).");
+Create a bytearray object from a string of hexadecimal numbers.\n\
+Spaces between two numbers are accepted.\n\
+Example: bytearray.fromhex('B9 01EF') -> bytearray(b'\\xb9\\x01\\xef').");
 
 static int
-hex_digit_to_int(int c)
+hex_digit_to_int(Py_UNICODE c)
 {
-    if (isdigit(c))
+    if (c >= 128)
+        return -1;
+    if (ISDIGIT(c))
         return c - '0';
     else {
-        if (isupper(c))
-            c = tolower(c);
+        if (ISUPPER(c))
+            c = TOLOWER(c);
         if (c >= 'a' && c <= 'f')
             return c - 'a' + 10;
     }
@@ -2866,34 +2955,34 @@
 static PyObject *
 bytes_fromhex(PyObject *cls, PyObject *args)
 {
-    PyObject *newbytes;
-    char *hex, *buf;
-    Py_ssize_t len, byteslen, i, j;
+    PyObject *newbytes, *hexobj;
+    char *buf;
+    Py_UNICODE *hex;
+    Py_ssize_t hexlen, byteslen, i, j;
     int top, bot;
 
-    if (!PyArg_ParseTuple(args, "s#:fromhex", &hex, &len))
+    if (!PyArg_ParseTuple(args, "U:fromhex", &hexobj))
         return NULL;
-
-    byteslen = len / 2; /* max length if there are no spaces */
-
+    assert(PyUnicode_Check(hexobj));
+    hexlen = PyUnicode_GET_SIZE(hexobj);
+    hex = PyUnicode_AS_UNICODE(hexobj);
+    byteslen = hexlen/2; /* This overestimates if there are spaces */
     newbytes = PyBytes_FromStringAndSize(NULL, byteslen);
     if (!newbytes)
         return NULL;
     buf = PyBytes_AS_STRING(newbytes);
-
-    for (i = j = 0; i < len; i += 2) {
+    for (i = j = 0; i < hexlen; i += 2) {
         /* skip over spaces in the input */
-        while (Py_CHARMASK(hex[i]) == ' ')
+        while (hex[i] == ' ')
             i++;
-        if (i >= len)
+        if (i >= hexlen)
             break;
-        top = hex_digit_to_int(Py_CHARMASK(hex[i]));
-        bot = hex_digit_to_int(Py_CHARMASK(hex[i+1]));
+        top = hex_digit_to_int(hex[i]);
+        bot = hex_digit_to_int(hex[i+1]);
         if (top == -1 || bot == -1) {
             PyErr_Format(PyExc_ValueError,
-                         "non-hexadecimal number string '%c%c' found in "
-                         "fromhex() arg at position %zd",
-                         hex[i], hex[i+1], i);
+                         "non-hexadecimal number found in "
+                         "fromhex() arg at position %zd", i);
             goto error;
         }
         buf[j++] = (top << 4) + bot;
@@ -2912,18 +3001,26 @@
 static PyObject *
 bytes_reduce(PyBytesObject *self)
 {
-    PyObject *latin1;
+    PyObject *latin1, *dict;
     if (self->ob_bytes)
         latin1 = PyUnicode_DecodeLatin1(self->ob_bytes,
-                                        Py_Size(self), NULL);
+                                        Py_SIZE(self), NULL);
     else
         latin1 = PyUnicode_FromString("");
-    return Py_BuildValue("(O(Ns))", Py_Type(self), latin1, "latin-1");
+
+    dict = PyObject_GetAttrString((PyObject *)self, "__dict__");
+    if (dict == NULL) {
+        PyErr_Clear();
+        dict = Py_None;
+        Py_INCREF(dict);
+    }
+
+    return Py_BuildValue("(O(Ns)N)", Py_TYPE(self), latin1, "latin-1", dict);
 }
 
 static PySequenceMethods bytes_as_sequence = {
     (lenfunc)bytes_length,              /* sq_length */
-    (binaryfunc)bytes_concat,           /* sq_concat */
+    (binaryfunc)PyBytes_Concat,         /* sq_concat */
     (ssizeargfunc)bytes_repeat,         /* sq_repeat */
     (ssizeargfunc)bytes_getitem,        /* sq_item */
     0,                                  /* sq_slice */
@@ -2947,46 +3044,90 @@
 
 static PyMethodDef
 bytes_methods[] = {
-    {"find", (PyCFunction)bytes_find, METH_VARARGS, find__doc__},
+    {"__alloc__", (PyCFunction)bytes_alloc, METH_NOARGS, alloc_doc},
+    {"__reduce__", (PyCFunction)bytes_reduce, METH_NOARGS, reduce_doc},
+    {"append", (PyCFunction)bytes_append, METH_O, append__doc__},
+    {"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS,
+     _Py_capitalize__doc__},
+    {"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__},
     {"count", (PyCFunction)bytes_count, METH_VARARGS, count__doc__},
-    {"index", (PyCFunction)bytes_index, METH_VARARGS, index__doc__},
-    {"rfind", (PyCFunction)bytes_rfind, METH_VARARGS, rfind__doc__},
-    {"rindex", (PyCFunction)bytes_rindex, METH_VARARGS, rindex__doc__},
+    {"decode", (PyCFunction)bytes_decode, METH_VARARGS, decode_doc},
     {"endswith", (PyCFunction)bytes_endswith, METH_VARARGS, endswith__doc__},
-    {"startswith", (PyCFunction)bytes_startswith, METH_VARARGS,
-                startswith__doc__},
-    {"replace", (PyCFunction)bytes_replace, METH_VARARGS, replace__doc__},
-    {"translate", (PyCFunction)bytes_translate, METH_VARARGS, translate__doc__},
-    {"partition", (PyCFunction)bytes_partition, METH_O, partition__doc__},
-    {"rpartition", (PyCFunction)bytes_rpartition, METH_O, rpartition__doc__},
-    {"split", (PyCFunction)bytes_split, METH_VARARGS, split__doc__},
-    {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS, rsplit__doc__},
+    {"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS,
+     expandtabs__doc__},
     {"extend", (PyCFunction)bytes_extend, METH_O, extend__doc__},
+    {"find", (PyCFunction)bytes_find, METH_VARARGS, find__doc__},
+    {"fromhex", (PyCFunction)bytes_fromhex, METH_VARARGS|METH_CLASS,
+     fromhex_doc},
+    {"index", (PyCFunction)bytes_index, METH_VARARGS, index__doc__},
     {"insert", (PyCFunction)bytes_insert, METH_VARARGS, insert__doc__},
-    {"append", (PyCFunction)bytes_append, METH_O, append__doc__},
-    {"reverse", (PyCFunction)bytes_reverse, METH_NOARGS, reverse__doc__},
+    {"isalnum", (PyCFunction)stringlib_isalnum, METH_NOARGS,
+     _Py_isalnum__doc__},
+    {"isalpha", (PyCFunction)stringlib_isalpha, METH_NOARGS,
+     _Py_isalpha__doc__},
+    {"isdigit", (PyCFunction)stringlib_isdigit, METH_NOARGS,
+     _Py_isdigit__doc__},
+    {"islower", (PyCFunction)stringlib_islower, METH_NOARGS,
+     _Py_islower__doc__},
+    {"isspace", (PyCFunction)stringlib_isspace, METH_NOARGS,
+     _Py_isspace__doc__},
+    {"istitle", (PyCFunction)stringlib_istitle, METH_NOARGS,
+     _Py_istitle__doc__},
+    {"isupper", (PyCFunction)stringlib_isupper, METH_NOARGS,
+     _Py_isupper__doc__},
+    {"join", (PyCFunction)bytes_join, METH_O, join_doc},
+    {"ljust", (PyCFunction)stringlib_ljust, METH_VARARGS, ljust__doc__},
+    {"lower", (PyCFunction)stringlib_lower, METH_NOARGS, _Py_lower__doc__},
+    {"lstrip", (PyCFunction)bytes_lstrip, METH_VARARGS, lstrip__doc__},
+    {"partition", (PyCFunction)bytes_partition, METH_O, partition__doc__},
     {"pop", (PyCFunction)bytes_pop, METH_VARARGS, pop__doc__},
     {"remove", (PyCFunction)bytes_remove, METH_O, remove__doc__},
-    {"strip", (PyCFunction)bytes_strip, METH_VARARGS, strip__doc__},
-    {"lstrip", (PyCFunction)bytes_lstrip, METH_VARARGS, lstrip__doc__},
+    {"replace", (PyCFunction)bytes_replace, METH_VARARGS, replace__doc__},
+    {"reverse", (PyCFunction)bytes_reverse, METH_NOARGS, reverse__doc__},
+    {"rfind", (PyCFunction)bytes_rfind, METH_VARARGS, rfind__doc__},
+    {"rindex", (PyCFunction)bytes_rindex, METH_VARARGS, rindex__doc__},
+    {"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, rjust__doc__},
+    {"rpartition", (PyCFunction)bytes_rpartition, METH_O, rpartition__doc__},
+    {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS, rsplit__doc__},
     {"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, rstrip__doc__},
-    {"decode", (PyCFunction)bytes_decode, METH_VARARGS, decode_doc},
-    {"__alloc__", (PyCFunction)bytes_alloc, METH_NOARGS, alloc_doc},
-    {"fromhex", (PyCFunction)bytes_fromhex, METH_VARARGS|METH_CLASS,
-     fromhex_doc},
-    {"join", (PyCFunction)bytes_join, METH_O, join_doc},
-    {"__reduce__", (PyCFunction)bytes_reduce, METH_NOARGS, reduce_doc},
+    {"split", (PyCFunction)bytes_split, METH_VARARGS, split__doc__},
+    {"splitlines", (PyCFunction)stringlib_splitlines, METH_VARARGS,
+     splitlines__doc__},
+    {"startswith", (PyCFunction)bytes_startswith, METH_VARARGS ,
+     startswith__doc__},
+    {"strip", (PyCFunction)bytes_strip, METH_VARARGS, strip__doc__},
+    {"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS,
+     _Py_swapcase__doc__},
+    {"title", (PyCFunction)stringlib_title, METH_NOARGS, _Py_title__doc__},
+    {"translate", (PyCFunction)bytes_translate, METH_VARARGS,
+     translate__doc__},
+    {"upper", (PyCFunction)stringlib_upper, METH_NOARGS, _Py_upper__doc__},
+    {"zfill", (PyCFunction)stringlib_zfill, METH_VARARGS, zfill__doc__},
     {NULL}
 };
 
 PyDoc_STRVAR(bytes_doc,
-"bytes([iterable]) -> new array of bytes.\n\
+"bytearray(iterable_of_ints) -> bytearray.\n\
+bytearray(string, encoding[, errors]) -> bytearray.\n\
+bytearray(bytes_or_bytearray) -> mutable copy of bytes_or_bytearray.\n\
+bytearray(memory_view) -> bytearray.\n\
+\n\
+Construct an mutable bytearray object from:\n\
+  - an iterable yielding integers in range(256)\n\
+  - a text string encoded using the specified encoding\n\
+  - a bytes or a bytearray object\n\
+  - any object implementing the buffer API.\n\
 \n\
-If an argument is given it must be an iterable yielding ints in range(256).");
+bytearray(int) -> bytearray.\n\
+\n\
+Construct a zero-initialized bytearray of the given length.");
+
+
+static PyObject *bytes_iter(PyObject *seq);
 
 PyTypeObject PyBytes_Type = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
-    "bytes",
+    "bytearray",
     sizeof(PyBytesObject),
     0,
     (destructor)bytes_dealloc,          /* tp_dealloc */
@@ -3000,18 +3141,17 @@
     &bytes_as_mapping,                  /* tp_as_mapping */
     0,                                  /* tp_hash */
     0,                                  /* tp_call */
-    (reprfunc)bytes_str,                /* tp_str */
+    bytes_str,                          /* tp_str */
     PyObject_GenericGetAttr,            /* tp_getattro */
     0,                                  /* tp_setattro */
     &bytes_as_buffer,                   /* tp_as_buffer */
-    /* bytes is 'final' or 'sealed' */
-    Py_TPFLAGS_DEFAULT,                 /* tp_flags */
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
     bytes_doc,                          /* tp_doc */
     0,                                  /* tp_traverse */
     0,                                  /* tp_clear */
     (richcmpfunc)bytes_richcompare,     /* tp_richcompare */
     0,                                  /* tp_weaklistoffset */
-    0,                                  /* tp_iter */
+    bytes_iter,                         /* tp_iter */
     0,                                  /* tp_iternext */
     bytes_methods,                      /* tp_methods */
     0,                                  /* tp_members */
@@ -3026,3 +3166,121 @@
     PyType_GenericNew,                  /* tp_new */
     PyObject_Del,                       /* tp_free */
 };
+
+/*********************** Bytes Iterator ****************************/
+
+typedef struct {
+    PyObject_HEAD
+    Py_ssize_t it_index;
+    PyBytesObject *it_seq; /* Set to NULL when iterator is exhausted */
+} bytesiterobject;
+
+static void
+bytesiter_dealloc(bytesiterobject *it)
+{
+    _PyObject_GC_UNTRACK(it);
+    Py_XDECREF(it->it_seq);
+    PyObject_GC_Del(it);
+}
+
+static int
+bytesiter_traverse(bytesiterobject *it, visitproc visit, void *arg)
+{
+    Py_VISIT(it->it_seq);
+    return 0;
+}
+
+static PyObject *
+bytesiter_next(bytesiterobject *it)
+{
+    PyBytesObject *seq;
+    PyObject *item;
+
+    assert(it != NULL);
+    seq = it->it_seq;
+    if (seq == NULL)
+        return NULL;
+    assert(PyBytes_Check(seq));
+
+    if (it->it_index < PyBytes_GET_SIZE(seq)) {
+        item = PyLong_FromLong(
+            (unsigned char)seq->ob_bytes[it->it_index]);
+        if (item != NULL)
+            ++it->it_index;
+        return item;
+    }
+
+    Py_DECREF(seq);
+    it->it_seq = NULL;
+    return NULL;
+}
+
+static PyObject *
+bytesiter_length_hint(bytesiterobject *it)
+{
+    Py_ssize_t len = 0;
+    if (it->it_seq)
+        len = PyBytes_GET_SIZE(it->it_seq) - it->it_index;
+    return PyLong_FromSsize_t(len);
+}
+
+PyDoc_STRVAR(length_hint_doc,
+    "Private method returning an estimate of len(list(it)).");
+
+static PyMethodDef bytesiter_methods[] = {
+    {"__length_hint__", (PyCFunction)bytesiter_length_hint, METH_NOARGS,
+     length_hint_doc},
+    {NULL, NULL} /* sentinel */
+};
+
+PyTypeObject PyBytesIter_Type = {
+    PyVarObject_HEAD_INIT(&PyType_Type, 0)
+    "bytearray_iterator",              /* tp_name */
+    sizeof(bytesiterobject),           /* tp_basicsize */
+    0,                                 /* tp_itemsize */
+    /* methods */
+    (destructor)bytesiter_dealloc,     /* tp_dealloc */
+    0,                                 /* tp_print */
+    0,                                 /* tp_getattr */
+    0,                                 /* tp_setattr */
+    0,                                 /* tp_compare */
+    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_HAVE_GC, /* tp_flags */
+    0,                                 /* tp_doc */
+    (traverseproc)bytesiter_traverse,  /* tp_traverse */
+    0,                                 /* tp_clear */
+    0,                                 /* tp_richcompare */
+    0,                                 /* tp_weaklistoffset */
+    PyObject_SelfIter,                 /* tp_iter */
+    (iternextfunc)bytesiter_next,      /* tp_iternext */
+    bytesiter_methods,                 /* tp_methods */
+    0,
+};
+
+static PyObject *
+bytes_iter(PyObject *seq)
+{
+    bytesiterobject *it;
+
+    if (!PyBytes_Check(seq)) {
+        PyErr_BadInternalCall();
+        return NULL;
+    }
+    it = PyObject_GC_New(bytesiterobject, &PyBytesIter_Type);
+    if (it == NULL)
+        return NULL;
+    it->it_index = 0;
+    Py_INCREF(seq);
+    it->it_seq = (PyBytesObject *)seq;
+    _PyObject_GC_TRACK(it);
+    return (PyObject *)it;
+}

Modified: python/branches/py3k-importlib/Objects/cellobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/cellobject.c	(original)
+++ python/branches/py3k-importlib/Objects/cellobject.c	Thu Mar 27 00:48:05 2008
@@ -31,13 +31,15 @@
 int
 PyCell_Set(PyObject *op, PyObject *obj)
 {
+	PyObject* oldobj;
 	if (!PyCell_Check(op)) {
 		PyErr_BadInternalCall();
 		return -1;
 	}
-	Py_XDECREF(((PyCellObject*)op)->ob_ref);
+	oldobj = PyCell_GET(op);
 	Py_XINCREF(obj);
 	PyCell_SET(op, obj);
+	Py_XDECREF(oldobj);
 	return 0;
 }
 
@@ -49,6 +51,18 @@
 	PyObject_GC_Del(op);
 }
 
+static int
+cell_compare(PyCellObject *a, PyCellObject *b)
+{
+	if (a->ob_ref == NULL) {
+		if (b->ob_ref == NULL)
+			return 0;
+		return -1;
+	} else if (b->ob_ref == NULL)
+		return 1;
+	return PyObject_Compare(a->ob_ref, b->ob_ref);
+}
+
 static PyObject *
 cell_repr(PyCellObject *op)
 {
@@ -77,7 +91,12 @@
 static PyObject *
 cell_get_contents(PyCellObject *op, void *closure)
 {
-	Py_XINCREF(op->ob_ref);
+	if (op->ob_ref == NULL)
+	{
+		PyErr_SetString(PyExc_ValueError, "Cell is empty");
+		return NULL;
+	}
+	Py_INCREF(op->ob_ref);
 	return op->ob_ref;
 }
 
@@ -95,7 +114,7 @@
 	0,                                      /* tp_print */
 	0,	                                /* tp_getattr */
 	0,					/* tp_setattr */
-	0,					/* tp_compare */
+	(cmpfunc)cell_compare,					/* tp_compare */
 	(reprfunc)cell_repr,			/* tp_repr */
 	0,					/* tp_as_number */
 	0,			                /* tp_as_sequence */

Modified: python/branches/py3k-importlib/Objects/classobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/classobject.c	(original)
+++ python/branches/py3k-importlib/Objects/classobject.c	Thu Mar 27 00:48:05 2008
@@ -5,6 +5,14 @@
 
 #define TP_DESCR_GET(t) ((t)->tp_descr_get)
 
+/* Free list for method objects to safe malloc/free overhead
+ * The im_self element is used to chain the elements.
+ */
+static PyMethodObject *free_list;
+static int numfree = 0;
+#ifndef PyMethod_MAXFREELIST
+#define PyMethod_MAXFREELIST 256
+#endif
 
 PyObject *
 PyMethod_Function(PyObject *im)
@@ -26,37 +34,28 @@
 	return ((PyMethodObject *)im)->im_self;
 }
 
-PyObject *
-PyMethod_Class(PyObject *im)
-{
-	if (!PyMethod_Check(im)) {
-		PyErr_BadInternalCall();
-		return NULL;
-	}
-	return ((PyMethodObject *)im)->im_class;
-}
-
-
-/* Method objects are used for two purposes:
-   (a) as bound instance methods (returned by instancename.methodname)
-   (b) as unbound methods (returned by ClassName.methodname)
-   In case (b), im_self is NULL
+/* Method objects are used for bound instance methods returned by
+   instancename.methodname. ClassName.methodname returns an ordinary
+   function.
 */
 
-static PyMethodObject *free_list;
-
 PyObject *
-PyMethod_New(PyObject *func, PyObject *self, PyObject *klass)
+PyMethod_New(PyObject *func, PyObject *self)
 {
 	register PyMethodObject *im;
 	if (!PyCallable_Check(func)) {
 		PyErr_BadInternalCall();
 		return NULL;
 	}
+	if (self == NULL) {
+		PyErr_BadInternalCall();
+		return NULL;
+	}
 	im = free_list;
 	if (im != NULL) {
 		free_list = (PyMethodObject *)(im->im_self);
 		PyObject_INIT(im, &PyMethod_Type);
+		numfree--;
 	}
 	else {
 		im = PyObject_GC_New(PyMethodObject, &PyMethod_Type);
@@ -68,25 +67,21 @@
 	im->im_func = func;
 	Py_XINCREF(self);
 	im->im_self = self;
-	Py_XINCREF(klass);
-	im->im_class = klass;
 	_PyObject_GC_TRACK(im);
 	return (PyObject *)im;
 }
 
 /* Descriptors for PyMethod attributes */
 
-/* im_class, im_func and im_self are stored in the PyMethod object */
+/* im_func and im_self are stored in the PyMethod object */
 
-#define OFF(x) offsetof(PyMethodObject, x)
+#define MO_OFF(x) offsetof(PyMethodObject, x)
 
 static PyMemberDef method_memberlist[] = {
-	{"im_class",	T_OBJECT,	OFF(im_class),	READONLY|RESTRICTED,
-	 "the class associated with a method"},
-	{"im_func",	T_OBJECT,	OFF(im_func),	READONLY|RESTRICTED,
+	{"__func__", T_OBJECT, MO_OFF(im_func), READONLY|RESTRICTED,
 	 "the function (or other callable) implementing a method"},
-	{"im_self",	T_OBJECT,	OFF(im_self),	READONLY|RESTRICTED,
-	 "the instance to which a method is bound; None for unbound methods"},
+	{"__self__", T_OBJECT, MO_OFF(im_self), READONLY|RESTRICTED,
+	 "the instance to which a method is bound"},
 	{NULL}	/* Sentinel */
 };
 
@@ -141,36 +136,33 @@
 }
 
 PyDoc_STRVAR(method_doc,
-"method(function, instance, class)\n\
+"method(function, instance)\n\
 \n\
-Create an instance method object.");
+Create a bound instance method object.");
 
 static PyObject *
 method_new(PyTypeObject* type, PyObject* args, PyObject *kw)
 {
 	PyObject *func;
 	PyObject *self;
-	PyObject *classObj = NULL;
 
-	if (!_PyArg_NoKeywords("instancemethod", kw))
+	if (!_PyArg_NoKeywords("method", kw))
 		return NULL;
-	if (!PyArg_UnpackTuple(args, "method", 2, 3,
-			      &func, &self, &classObj))
+	if (!PyArg_UnpackTuple(args, "method", 2, 2,
+			      &func, &self))
 		return NULL;
 	if (!PyCallable_Check(func)) {
 		PyErr_SetString(PyExc_TypeError,
 				"first argument must be callable");
 		return NULL;
 	}
-	if (self == Py_None)
-		self = NULL;
-	if (self == NULL && classObj == NULL) {
+	if (self == NULL || self == Py_None) {
 		PyErr_SetString(PyExc_TypeError,
-			"unbound methods must have non-NULL im_class");
+			"self must not be None");
 		return NULL;
 	}
 
-	return PyMethod_New(func, self, classObj);
+	return PyMethod_New(func, self);
 }
 
 static void
@@ -181,9 +173,14 @@
 		PyObject_ClearWeakRefs((PyObject *)im);
 	Py_DECREF(im->im_func);
 	Py_XDECREF(im->im_self);
-	Py_XDECREF(im->im_class);
-	im->im_self = (PyObject *)free_list;
-	free_list = im;
+	if (numfree < PyMethod_MAXFREELIST) {
+		im->im_self = (PyObject *)free_list;
+		free_list = im;
+		numfree++;
+	}
+	else {
+		PyObject_GC_Del(im);
+	}
 }
 
 static PyObject *
@@ -225,10 +222,15 @@
 {
 	PyObject *self = a->im_self;
 	PyObject *func = a->im_func;
-	PyObject *klass = a->im_class;
-	PyObject *funcname = NULL, *klassname = NULL, *result = NULL;
+	PyObject *klass = (PyObject*)Py_TYPE(self);
+	PyObject *funcname = NULL ,*klassname = NULL, *result = NULL;
 	char *defname = "?";
 
+	if (self == NULL) {
+		PyErr_BadInternalCall();
+		return NULL;
+	}
+
 	funcname = PyObject_GetAttrString(func, "__name__");
 	if (funcname == NULL) {
 		if (!PyErr_ExceptionMatches(PyExc_AttributeError))
@@ -239,6 +241,7 @@
 		Py_DECREF(funcname);
 		funcname = NULL;
 	}
+
 	if (klass == NULL)
 		klassname = NULL;
 	else {
@@ -253,16 +256,12 @@
 			klassname = NULL;
 		}
 	}
-	if (self == NULL)
-		result = PyUnicode_FromFormat("<unbound method %V.%V>",
-		                              klassname, defname,
-		                              funcname, defname);
-	else {
-		/* XXX Shouldn't use repr()/%R here! */
-		result = PyUnicode_FromFormat("<bound method %V.%V of %R>",
-		                              klassname, defname,
-		                              funcname, defname, self);
-	}
+
+	/* XXX Shouldn't use repr()/%R here! */
+	result = PyUnicode_FromFormat("<bound method %V.%V of %R>",
+	                              klassname, defname,
+	                              funcname, defname, self);
+
 	Py_XDECREF(funcname);
 	Py_XDECREF(klassname);
 	return result;
@@ -292,92 +291,19 @@
 {
 	Py_VISIT(im->im_func);
 	Py_VISIT(im->im_self);
-	Py_VISIT(im->im_class);
 	return 0;
 }
 
-static void
-getclassname(PyObject *klass, char *buf, int bufsize)
-{
-	PyObject *name;
-
-	assert(bufsize > 1);
-	strcpy(buf, "?"); /* Default outcome */
-	if (klass == NULL)
-		return;
-	name = PyObject_GetAttrString(klass, "__name__");
-	if (name == NULL) {
-		/* This function cannot return an exception */
-		PyErr_Clear();
-		return;
-	}
-	if (PyUnicode_Check(name)) {
-		strncpy(buf, PyUnicode_AsString(name), bufsize);
-		buf[bufsize-1] = '\0';
-	}
-	Py_DECREF(name);
-}
-
-static void
-getinstclassname(PyObject *inst, char *buf, int bufsize)
-{
-	PyObject *klass;
-
-	if (inst == NULL) {
-		assert(bufsize > 0 && (size_t)bufsize > strlen("nothing"));
-		strcpy(buf, "nothing");
-		return;
-	}
-
-	klass = PyObject_GetAttrString(inst, "__class__");
-	if (klass == NULL) {
-		/* This function cannot return an exception */
-		PyErr_Clear();
-		klass = (PyObject *)(inst->ob_type);
-		Py_INCREF(klass);
-	}
-	getclassname(klass, buf, bufsize);
-	Py_XDECREF(klass);
-}
-
 static PyObject *
 method_call(PyObject *func, PyObject *arg, PyObject *kw)
 {
 	PyObject *self = PyMethod_GET_SELF(func);
-	PyObject *klass = PyMethod_GET_CLASS(func);
 	PyObject *result;
 
 	func = PyMethod_GET_FUNCTION(func);
 	if (self == NULL) {
-		/* Unbound methods must be called with an instance of
-		   the class (or a derived class) as first argument */
-		int ok;
-		if (PyTuple_Size(arg) >= 1)
-			self = PyTuple_GET_ITEM(arg, 0);
-		if (self == NULL)
-			ok = 0;
-		else {
-			ok = PyObject_IsInstance(self, klass);
-			if (ok < 0)
-				return NULL;
-		}
-		if (!ok) {
-			char clsbuf[256];
-			char instbuf[256];
-			getclassname(klass, clsbuf, sizeof(clsbuf));
-			getinstclassname(self, instbuf, sizeof(instbuf));
-			PyErr_Format(PyExc_TypeError,
-				     "unbound method %s%s must be called with "
-				     "%s instance as first argument "
-				     "(got %s%s instead)",
-				     PyEval_GetFuncName(func),
-				     PyEval_GetFuncDesc(func),
-				     clsbuf,
-				     instbuf,
-				     self == NULL ? "" : " instance");
-			return NULL;
-		}
-		Py_INCREF(arg);
+		PyErr_BadInternalCall();
+		return NULL;
 	}
 	else {
 		Py_ssize_t argcount = PyTuple_Size(arg);
@@ -402,27 +328,15 @@
 static PyObject *
 method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls)
 {
-	/* Don't rebind an already bound method, or an unbound method
-	   of a class that's not a base class of cls. */
-
+	/* Don't rebind an already bound method of a class that's not a base
+	   class of cls. */
 	if (PyMethod_GET_SELF(meth) != NULL) {
 		/* Already bound */
 		Py_INCREF(meth);
 		return meth;
 	}
-	/* No, it is an unbound method */
-	if (PyMethod_GET_CLASS(meth) != NULL && cls != NULL) {
-		/* Do subclass test.  If it fails, return meth unchanged. */
-		int ok = PyObject_IsSubclass(cls, PyMethod_GET_CLASS(meth));
-		if (ok < 0)
-			return NULL;
-		if (!ok) {
-			Py_INCREF(meth);
-			return meth;
-		}
-	}
 	/* Bind it to obj */
-	return PyMethod_New(PyMethod_GET_FUNCTION(meth), obj, cls);
+	return PyMethod_New(PyMethod_GET_FUNCTION(meth), obj);
 }
 
 PyTypeObject PyMethod_Type = {
@@ -450,7 +364,7 @@
 	(traverseproc)method_traverse,		/* tp_traverse */
 	0,					/* tp_clear */
 	method_richcompare,			/* tp_richcompare */
- 	offsetof(PyMethodObject, im_weakreflist), /* tp_weaklistoffset */
+	offsetof(PyMethodObject, im_weakreflist), /* tp_weaklistoffset */
 	0,					/* tp_iter */
 	0,					/* tp_iternext */
 	0,					/* tp_methods */
@@ -468,12 +382,265 @@
 
 /* Clear out the free list */
 
-void
-PyMethod_Fini(void)
+int
+PyMethod_ClearFreeList(void)
 {
+	int freelist_size = numfree;
+	
 	while (free_list) {
 		PyMethodObject *im = free_list;
 		free_list = (PyMethodObject *)(im->im_self);
 		PyObject_GC_Del(im);
+		numfree--;
+	}
+	assert(numfree == 0);
+	return freelist_size;
+}
+
+void
+PyMethod_Fini(void)
+{
+	(void)PyMethod_ClearFreeList();
+}
+
+/* ------------------------------------------------------------------------
+ * instance method
+ */
+
+PyObject *
+PyInstanceMethod_New(PyObject *func) {
+	PyInstanceMethodObject *method;
+	method = PyObject_GC_New(PyInstanceMethodObject,
+				 &PyInstanceMethod_Type);
+	if (method == NULL) return NULL;
+	Py_INCREF(func);
+	method->func = func;
+	_PyObject_GC_TRACK(method);
+	return (PyObject *)method;
+}
+
+PyObject *
+PyInstanceMethod_Function(PyObject *im)
+{
+	if (!PyInstanceMethod_Check(im)) {
+		PyErr_BadInternalCall();
+		return NULL;
+	}
+	return PyInstanceMethod_GET_FUNCTION(im);
+}
+
+#define IMO_OFF(x) offsetof(PyInstanceMethodObject, x)
+
+static PyMemberDef instancemethod_memberlist[] = {
+	{"__func__", T_OBJECT, IMO_OFF(func), READONLY|RESTRICTED,
+	 "the function (or other callable) implementing a method"},
+	{NULL}	/* Sentinel */
+};
+
+static PyObject *
+instancemethod_get_doc(PyObject *self, void *context)
+{
+	static PyObject *docstr;
+	if (docstr == NULL) {
+		docstr = PyUnicode_InternFromString("__doc__");
+		if (docstr == NULL)
+			return NULL;
 	}
+	return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), docstr);
 }
+
+static PyGetSetDef instancemethod_getset[] = {
+	{"__doc__", (getter)instancemethod_get_doc, NULL, NULL},
+	{0}
+};
+
+static PyObject *
+instancemethod_getattro(PyObject *self, PyObject *name)
+{
+	PyTypeObject *tp = self->ob_type;
+	PyObject *descr = NULL;
+
+	if (tp->tp_dict == NULL) {
+		if (PyType_Ready(tp) < 0)
+			return NULL;
+	}
+	descr = _PyType_Lookup(tp, name);
+
+	if (descr != NULL) {
+		descrgetfunc f = TP_DESCR_GET(descr->ob_type);
+		if (f != NULL)
+			return f(descr, self, (PyObject *)self->ob_type);
+		else {
+			Py_INCREF(descr);
+			return descr;
+		}
+	}
+
+	return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), name);
+}
+
+static void
+instancemethod_dealloc(PyObject *self) {
+	_PyObject_GC_UNTRACK(self);
+	Py_DECREF(PyInstanceMethod_GET_FUNCTION(self));
+	PyObject_GC_Del(self);
+}
+
+static int
+instancemethod_traverse(PyObject *self, visitproc visit, void *arg) {
+	Py_VISIT(PyInstanceMethod_GET_FUNCTION(self));
+	return 0;
+}
+
+static PyObject *
+instancemethod_call(PyObject *self, PyObject *arg, PyObject *kw)
+{
+	return PyObject_Call(PyMethod_GET_FUNCTION(self), arg, kw);
+}
+
+static PyObject *
+instancemethod_descr_get(PyObject *descr, PyObject *obj, PyObject *type) {
+	register PyObject *func = PyInstanceMethod_GET_FUNCTION(descr);
+	if (obj == NULL)
+		return func;
+	else
+		return PyMethod_New(func, obj);
+}
+
+static PyObject *
+instancemethod_richcompare(PyObject *self, PyObject *other, int op)
+{
+	PyInstanceMethodObject *a, *b;
+	PyObject *res;
+	int eq;
+
+	if ((op != Py_EQ && op != Py_NE) ||
+	    !PyInstanceMethod_Check(self) ||
+	    !PyInstanceMethod_Check(other))
+	{
+		Py_INCREF(Py_NotImplemented);
+		return Py_NotImplemented;
+	}
+	a = (PyInstanceMethodObject *)self;
+	b = (PyInstanceMethodObject *)other;
+	eq = PyObject_RichCompareBool(a->func, b->func, Py_EQ);
+	if (eq < 0)
+		return NULL;
+	if (op == Py_EQ)
+		res = eq ? Py_True : Py_False;
+	else
+		res = eq ? Py_False : Py_True;
+	Py_INCREF(res);
+	return res;
+}
+
+static PyObject *
+instancemethod_repr(PyObject *self)
+{
+	PyObject *func = PyInstanceMethod_Function(self);
+	PyObject *funcname = NULL , *result = NULL;
+	char *defname = "?";
+
+	if (func == NULL) {
+		PyErr_BadInternalCall();
+		return NULL;
+	}
+
+	funcname = PyObject_GetAttrString(func, "__name__");
+	if (funcname == NULL) {
+		if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+			return NULL;
+		PyErr_Clear();
+	}
+	else if (!PyUnicode_Check(funcname)) {
+		Py_DECREF(funcname);
+		funcname = NULL;
+	}
+
+	result = PyUnicode_FromFormat("<instancemethod %V at %p>",
+	                              funcname, defname, self);
+
+	Py_XDECREF(funcname);
+	return result;
+}
+
+/*
+static long
+instancemethod_hash(PyObject *self)
+{
+	long x, y;
+	x = (long)self;
+	y = PyObject_Hash(PyInstanceMethod_GET_FUNCTION(self));
+	if (y == -1)
+		return -1;
+	x = x ^ y;
+	if (x == -1)
+		x = -2;
+	return x;
+}
+*/
+
+PyDoc_STRVAR(instancemethod_doc,
+"instancemethod(function)\n\
+\n\
+Bind a function to a class.");
+
+static PyObject *
+instancemethod_new(PyTypeObject* type, PyObject* args, PyObject *kw)
+{
+	PyObject *func;
+
+	if (!_PyArg_NoKeywords("instancemethod", kw))
+		return NULL;
+	if (!PyArg_UnpackTuple(args, "instancemethod", 1, 1, &func))
+		return NULL;
+	if (!PyCallable_Check(func)) {
+		PyErr_SetString(PyExc_TypeError,
+				"first argument must be callable");
+		return NULL;
+	}
+
+	return PyInstanceMethod_New(func);
+}
+
+PyTypeObject PyInstanceMethod_Type = {
+	PyVarObject_HEAD_INIT(&PyType_Type, 0)
+	"instancemethod",			/* tp_name */
+	sizeof(PyInstanceMethodObject),		/* tp_basicsize */
+	0,					/* tp_itemsize */
+	instancemethod_dealloc,			/* tp_dealloc */
+	0,					/* tp_print */
+	0,					/* tp_getattr */
+	0,					/* tp_setattr */
+	0,					/* tp_compare */
+	(reprfunc)instancemethod_repr,		/* tp_repr */
+	0,					/* tp_as_number */
+	0,					/* tp_as_sequence */
+	0,					/* tp_as_mapping */
+	0, /*(hashfunc)instancemethod_hash,	tp_hash  */
+	instancemethod_call,			/* tp_call */
+	0,					/* tp_str */
+	instancemethod_getattro,		/* tp_getattro */
+	PyObject_GenericSetAttr,		/* tp_setattro */
+	0,					/* tp_as_buffer */
+	Py_TPFLAGS_DEFAULT
+		| Py_TPFLAGS_HAVE_GC,		/* tp_flags */
+	instancemethod_doc,			/* tp_doc */
+	instancemethod_traverse,		/* tp_traverse */
+	0,					/* tp_clear */
+	instancemethod_richcompare,		/* tp_richcompare */
+	0,					/* tp_weaklistoffset */
+	0,					/* tp_iter */
+	0,					/* tp_iternext */
+	0,					/* tp_methods */
+	instancemethod_memberlist,		/* tp_members */
+	instancemethod_getset,			/* tp_getset */
+	0,					/* tp_base */
+	0,					/* tp_dict */
+	instancemethod_descr_get,		/* tp_descr_get */
+	0,					/* tp_descr_set */
+	0,					/* tp_dictoffset */
+	0,					/* tp_init */
+	0,					/* tp_alloc */
+	instancemethod_new,			/* tp_new */
+};

Modified: python/branches/py3k-importlib/Objects/codeobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/codeobject.c	(original)
+++ python/branches/py3k-importlib/Objects/codeobject.c	Thu Mar 27 00:48:05 2008
@@ -8,7 +8,7 @@
 /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */
 
 static int
-all_name_chars(unsigned char *s)
+all_name_chars(Py_UNICODE *s)
 {
 	static char ok_name_char[256];
 	static unsigned char *name_chars = (unsigned char *)NAME_CHARS;
@@ -19,6 +19,8 @@
 			ok_name_char[*p] = 1;
 	}
 	while (*s) {
+		if (*s >= 128)
+			return 0;
 		if (ok_name_char[*s++] == 0)
 			return 0;
 	}
@@ -66,9 +68,6 @@
 		PyErr_BadInternalCall();
 		return NULL;
 	}
-	Py_INCREF(name);
-	Py_INCREF(filename);
-
 	intern_strings(names);
 	intern_strings(varnames);
 	intern_strings(freevars);
@@ -76,11 +75,11 @@
 	/* Intern selected string constants */
 	for (i = PyTuple_Size(consts); --i >= 0; ) {
 		PyObject *v = PyTuple_GetItem(consts, i);
-		if (!PyString_Check(v))
+		if (!PyUnicode_Check(v))
 			continue;
-		if (!all_name_chars((unsigned char *)PyString_AS_STRING(v)))
+		if (!all_name_chars(PyUnicode_AS_UNICODE(v)))
 			continue;
-		PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i));
+		PyUnicode_InternInPlace(&PyTuple_GET_ITEM(consts, i));
 	}
 	co = PyObject_NEW(PyCodeObject, &PyCode_Type);
 	if (co != NULL) {
@@ -110,7 +109,6 @@
 		co->co_lnotab = lnotab;
                 co->co_zombieframe = NULL;
 	}
-	Py_DECREF(name);
 	return co;
 }
 
@@ -181,8 +179,9 @@
 }
 
 PyDoc_STRVAR(code_doc,
-"code(argcount, nlocals, stacksize, flags, codestring, constants, names,\n\
-      varnames, filename, name, firstlineno, lnotab[, freevars[, cellvars]])\n\
+"code(argcount, kwonlyargcount nlocals, stacksize, flags, codestring,\n\
+      constants, names, varnames, filename, name, firstlineno,\n\
+      lnotab[, freevars[, cellvars]])\n\
 \n\
 Create a code object.  Not for the faint of heart.");
 
@@ -206,7 +205,7 @@
 	int firstlineno;
 	PyObject *lnotab;
 
-	if (!PyArg_ParseTuple(args, "iiiiiSO!O!O!SSiS|O!O!:code",
+	if (!PyArg_ParseTuple(args, "iiiiiSO!O!O!UUiS|O!O!:code",
 			      &argcount, &kwonlyargcount,
 				  &nlocals, &stacksize, &flags,
 			      &code,

Modified: python/branches/py3k-importlib/Objects/complexobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/complexobject.c	(original)
+++ python/branches/py3k-importlib/Objects/complexobject.c	Thu Mar 27 00:48:05 2008
@@ -265,13 +265,14 @@
 	/* return -1 on failure */
 	cv.real = -1.;
 	cv.imag = 0.;
-	
+		
+	if (complex_str == NULL) {
+		if (!(complex_str = PyUnicode_FromString("__complex__")))
+			return cv;
+	}
+
         {
 		PyObject *complexfunc;
-		if (!complex_str) {
-			if (!(complex_str = PyUnicode_FromString("__complex__")))
-				return cv;
-		}
 		complexfunc = _PyType_Lookup(op->ob_type, complex_str);
 		/* complexfunc is a borrowed reference */
 		if (complexfunc) {
@@ -313,16 +314,49 @@
 {
 	char format[32];
 	if (v->cval.real == 0.) {
-		PyOS_snprintf(format, sizeof(format), "%%.%ig", precision);
-		PyOS_ascii_formatd(buf, bufsz - 1, format, v->cval.imag);
-		strncat(buf, "j", 1);
+		if (!Py_IS_FINITE(v->cval.imag)) {
+			if (Py_IS_NAN(v->cval.imag))
+				strncpy(buf, "nan*j", 6);
+			/* else if (copysign(1, v->cval.imag) == 1) */
+			else if (v->cval.imag > 0)
+				strncpy(buf, "inf*j", 6);
+			else
+				strncpy(buf, "-inf*j", 7);
+		}
+		else {
+			PyOS_snprintf(format, sizeof(format), "%%.%ig", precision);
+			PyOS_ascii_formatd(buf, bufsz - 1, format, v->cval.imag);
+			strncat(buf, "j", 1);
+		}
 	} else {
 		char re[64], im[64];
 		/* Format imaginary part with sign, real part without */
-		PyOS_snprintf(format, sizeof(format), "%%.%ig", precision);
-		PyOS_ascii_formatd(re, sizeof(re), format, v->cval.real);
-		PyOS_snprintf(format, sizeof(format), "%%+.%ig", precision);
-		PyOS_ascii_formatd(im, sizeof(im), format, v->cval.imag);
+		if (!Py_IS_FINITE(v->cval.real)) {
+			if (Py_IS_NAN(v->cval.real))
+				strncpy(re, "nan", 4);
+			/* else if (copysign(1, v->cval.real) == 1) */
+			else if (v->cval.real > 0)
+				strncpy(re, "inf", 4);
+			else
+				strncpy(re, "-inf", 5);
+		}
+		else {
+			PyOS_snprintf(format, sizeof(format), "%%.%ig", precision);
+			PyOS_ascii_formatd(re, sizeof(re), format, v->cval.real);
+		}
+		if (!Py_IS_FINITE(v->cval.imag)) {
+			if (Py_IS_NAN(v->cval.imag))
+				strncpy(im, "+nan*", 6);
+			/* else if (copysign(1, v->cval.imag) == 1) */
+			else if (v->cval.imag > 0)
+				strncpy(im, "+inf*", 6);
+			else
+				strncpy(im, "-inf*", 6);
+		}
+		else {
+			PyOS_snprintf(format, sizeof(format), "%%+.%ig", precision);
+			PyOS_ascii_formatd(im, sizeof(im), format, v->cval.imag);
+		}
 		PyOS_snprintf(buf, bufsz, "(%s%sj)", re, im);
 	}
 }
@@ -375,24 +409,24 @@
 static int
 to_complex(PyObject **pobj, Py_complex *pc)
 {
-    PyObject *obj = *pobj;
+	PyObject *obj = *pobj;
 
-    pc->real = pc->imag = 0.0;
-    if (PyLong_Check(obj)) {
-        pc->real = PyLong_AsDouble(obj);
-        if (pc->real == -1.0 && PyErr_Occurred()) {
-            *pobj = NULL;
-            return -1;
-        }
-        return 0;
-    }
-    if (PyFloat_Check(obj)) {
-        pc->real = PyFloat_AsDouble(obj);
-        return 0;
-    }
-    Py_INCREF(Py_NotImplemented);
-    *pobj = Py_NotImplemented;
-    return -1;
+	pc->real = pc->imag = 0.0;
+	if (PyLong_Check(obj)) {
+		pc->real = PyLong_AsDouble(obj);
+		if (pc->real == -1.0 && PyErr_Occurred()) {
+			*pobj = NULL;
+			return -1;
+		}
+		return 0;
+	}
+	if (PyFloat_Check(obj)) {
+		pc->real = PyFloat_AsDouble(obj);
+		return 0;
+	}
+	Py_INCREF(Py_NotImplemented);
+	*pobj = Py_NotImplemented;
+	return -1;
 }
 		
 
@@ -401,8 +435,8 @@
 {
 	Py_complex result;
 	Py_complex a, b;
-        TO_COMPLEX(v, a);
-        TO_COMPLEX(w, b);
+	TO_COMPLEX(v, a);
+	TO_COMPLEX(w, b);
 	PyFPE_START_PROTECT("complex_add", return 0)
 	result = c_sum(a, b);
 	PyFPE_END_PROTECT(result)
@@ -414,8 +448,8 @@
 {
 	Py_complex result;
 	Py_complex a, b;
-        TO_COMPLEX(v, a);
-        TO_COMPLEX(w, b);
+	TO_COMPLEX(v, a);
+	TO_COMPLEX(w, b);
 	PyFPE_START_PROTECT("complex_sub", return 0)
 	result = c_diff(a, b);
 	PyFPE_END_PROTECT(result)
@@ -427,8 +461,8 @@
 {
 	Py_complex result;
 	Py_complex a, b;
-        TO_COMPLEX(v, a);
-        TO_COMPLEX(w, b);
+	TO_COMPLEX(v, a);
+	TO_COMPLEX(w, b);
 	PyFPE_START_PROTECT("complex_mul", return 0)
 	result = c_prod(a, b);
 	PyFPE_END_PROTECT(result)
@@ -440,8 +474,8 @@
 {
 	Py_complex quot;
 	Py_complex a, b;
-        TO_COMPLEX(v, a);
-        TO_COMPLEX(w, b);
+	TO_COMPLEX(v, a);
+	TO_COMPLEX(w, b);
 	PyFPE_START_PROTECT("complex_div", return 0)
 	errno = 0;
 	quot = c_quot(a, b);
@@ -477,8 +511,8 @@
 	Py_complex exponent;
 	long int_exponent;
 	Py_complex a, b;
-        TO_COMPLEX(v, a);
-        TO_COMPLEX(w, b);
+	TO_COMPLEX(v, a);
+	TO_COMPLEX(w, b);
 
  	if (z != Py_None) {
 		PyErr_SetString(PyExc_ValueError, "complex modulo");
@@ -557,8 +591,8 @@
 {
 	PyObject *res;
 	Py_complex i, j;
-        TO_COMPLEX(v, i);
-        TO_COMPLEX(w, j);
+	TO_COMPLEX(v, i);
+	TO_COMPLEX(w, j);
 
 	if (op != Py_EQ && op != Py_NE) {
 		/* XXX Should eventually return NotImplemented */
@@ -673,11 +707,11 @@
 	start = s;
 	while (*s && isspace(Py_CHARMASK(*s)))
 		s++;
-    if (s[0] == '\0') {
+	if (s[0] == '\0') {
 		PyErr_SetString(PyExc_ValueError,
 				"complex() arg is an empty string");
 		return NULL;
-    }
+	}
 	if (s[0] == '(') {
 		/* Skip over possible bracket from repr(). */
 		got_bracket = 1;
@@ -809,6 +843,8 @@
 	PyNumberMethods *nbr, *nbi = NULL;
 	Py_complex cr, ci;
 	int own_r = 0;
+	int cr_is_complex = 0;
+	int ci_is_complex = 0;
 	static PyObject *complexstr;
 	static char *kwlist[] = {"real", "imag", 0};
 
@@ -835,7 +871,7 @@
 					"complex() can't take second arg"
 					" if first is a string");
 			return NULL;
-                }
+		}
 		return complex_subtype_from_string(type, r);
 	}
 	if (i != NULL && PyUnicode_Check(i)) {
@@ -889,6 +925,7 @@
 		   retaining its real & imag parts here, and the return
 		   value is (properly) of the builtin complex type. */
 		cr = ((PyComplexObject*)r)->cval;
+		cr_is_complex = 1;
 		if (own_r) {
 			Py_DECREF(r);
 		}
@@ -897,7 +934,6 @@
 		/* The "real" part really is entirely real, and contributes
 		   nothing in the imaginary direction.  
 		   Just treat it as a double. */
-		cr.imag = 0.0;  
 		tmp = PyNumber_Float(r);
 		if (own_r) {
 			/* r was a newly created complex number, rather
@@ -913,19 +949,19 @@
 			return NULL;
 		}
 		cr.real = PyFloat_AsDouble(tmp);
+		cr.imag = 0.0; /* Shut up compiler warning */
 		Py_DECREF(tmp);
 	}
 	if (i == NULL) {
 		ci.real = 0.0;
-		ci.imag = 0.0;
 	}
-	else if (PyComplex_Check(i))
+	else if (PyComplex_Check(i)) {
 		ci = ((PyComplexObject*)i)->cval;
-	else {
+		ci_is_complex = 1;
+	} else {
 		/* The "imag" part really is entirely imaginary, and
 		   contributes nothing in the real direction.
 		   Just treat it as a double. */
-		ci.imag = 0.0;
 		tmp = (*nbi->nb_float)(i);
 		if (tmp == NULL)
 			return NULL;
@@ -933,11 +969,16 @@
 		Py_DECREF(tmp);
 	}
 	/*  If the input was in canonical form, then the "real" and "imag"
-	    parts are real numbers, so that ci.real and cr.imag are zero.
+	    parts are real numbers, so that ci.imag and cr.imag are zero.
 	    We need this correction in case they were not real numbers. */
-	cr.real -= ci.imag;
-	cr.imag += ci.real;
-	return complex_subtype_from_c_complex(type, cr);
+
+	if (ci_is_complex) {
+		cr.real -= ci.imag;
+	}
+	if (cr_is_complex) {
+		ci.real += cr.imag;
+	}
+	return complex_subtype_from_doubles(type, cr.real, ci.real);
 }
 
 PyDoc_STRVAR(complex_doc,

Modified: python/branches/py3k-importlib/Objects/descrobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/descrobject.c	(original)
+++ python/branches/py3k-importlib/Objects/descrobject.c	Thu Mar 27 00:48:05 2008
@@ -168,7 +168,7 @@
 	       int *pres)
 {
 	assert(obj != NULL);
-	if (!PyObject_IsInstance(obj, (PyObject *)(descr->d_type))) {
+	if (!PyObject_TypeCheck(obj, descr->d_type)) {
 		PyErr_Format(PyExc_TypeError,
 			     "descriptor '%V' for '%.100s' objects "
 			     "doesn't apply to '%.100s' object",
@@ -383,7 +383,7 @@
 	return 0;
 }
 
-static PyTypeObject PyMethodDescr_Type = {
+PyTypeObject PyMethodDescr_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
 	"method_descriptor",
 	sizeof(PyMethodDescrObject),
@@ -421,7 +421,7 @@
 };
 
 /* This is for METH_CLASS in C, not for "f = classmethod(f)" in Python! */
-static PyTypeObject PyClassMethodDescr_Type = {
+PyTypeObject PyClassMethodDescr_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
 	"classmethod_descriptor",
 	sizeof(PyMethodDescrObject),
@@ -458,7 +458,7 @@
 	0,					/* tp_descr_set */
 };
 
-static PyTypeObject PyMemberDescr_Type = {
+PyTypeObject PyMemberDescr_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
 	"member_descriptor",
 	sizeof(PyMemberDescrObject),
@@ -495,7 +495,7 @@
 	(descrsetfunc)member_set,		/* tp_descr_set */
 };
 
-static PyTypeObject PyGetSetDescr_Type = {
+PyTypeObject PyGetSetDescr_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
 	"getset_descriptor",
 	sizeof(PyGetSetDescrObject),
@@ -726,23 +726,6 @@
 }
 
 static PyObject *
-proxy_iterkeys(proxyobject *pp)
-{
-	return PyObject_CallMethod(pp->dict, "iterkeys", NULL);
-}
-
-static PyObject *
-proxy_itervalues(proxyobject *pp)
-{
-	return PyObject_CallMethod(pp->dict, "itervalues", NULL);
-}
-
-static PyObject *
-proxy_iteritems(proxyobject *pp)
-{
-	return PyObject_CallMethod(pp->dict, "iteritems", NULL);
-}
-static PyObject *
 proxy_copy(proxyobject *pp)
 {
 	return PyObject_CallMethod(pp->dict, "copy", NULL);
@@ -758,13 +741,6 @@
 	 PyDoc_STR("D.values() -> list of D's values")},
 	{"items",     (PyCFunction)proxy_items,      METH_NOARGS,
 	 PyDoc_STR("D.items() -> list of D's (key, value) pairs, as 2-tuples")},
-	{"iterkeys",  (PyCFunction)proxy_iterkeys,   METH_NOARGS,
-	 PyDoc_STR("D.iterkeys() -> an iterator over the keys of D")},
-	{"itervalues",(PyCFunction)proxy_itervalues, METH_NOARGS,
-	 PyDoc_STR("D.itervalues() -> an iterator over the values of D")},
-	{"iteritems", (PyCFunction)proxy_iteritems,  METH_NOARGS,
-	 PyDoc_STR("D.iteritems() ->"
-	 	   " an iterator over the (key, value) items of D")},
 	{"copy",      (PyCFunction)proxy_copy,       METH_NOARGS,
 	 PyDoc_STR("D.copy() -> a shallow copy of D")},
 	{0}
@@ -810,9 +786,9 @@
 	return PyObject_RichCompare(v->dict, w, op);
 }
 
-static PyTypeObject proxytype = {
+PyTypeObject PyDictProxy_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"dictproxy",				/* tp_name */
+	"dict_proxy",				/* tp_name */
 	sizeof(proxyobject),			/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */
@@ -853,7 +829,7 @@
 {
 	proxyobject *pp;
 
-	pp = PyObject_GC_New(proxyobject, &proxytype);
+	pp = PyObject_GC_New(proxyobject, &PyDictProxy_Type);
 	if (pp != NULL) {
 		Py_INCREF(dict);
 		pp->dict = dict;
@@ -1089,8 +1065,12 @@
 	PyObject *prop_set;
 	PyObject *prop_del;
 	PyObject *prop_doc;
+	int getter_doc;
 } propertyobject;
 
+static PyObject * property_copy(PyObject *, PyObject *, PyObject *,
+				  PyObject *, PyObject *);
+
 static PyMemberDef property_members[] = {
 	{"fget", T_OBJECT, offsetof(propertyobject, prop_get), READONLY},
 	{"fset", T_OBJECT, offsetof(propertyobject, prop_set), READONLY},
@@ -1100,6 +1080,44 @@
 };
 
 
+PyDoc_STRVAR(getter_doc,
+	     "Descriptor to change the getter on a property.");
+
+PyObject *
+property_getter(PyObject *self, PyObject *getter)
+{
+	return property_copy(self, getter, NULL, NULL, NULL);
+}
+
+
+PyDoc_STRVAR(setter_doc,
+	     "Descriptor to change the setter on a property.");
+
+PyObject *
+property_setter(PyObject *self, PyObject *setter)
+{
+	return property_copy(self, NULL, setter, NULL, NULL);
+}
+
+
+PyDoc_STRVAR(deleter_doc,
+	     "Descriptor to change the deleter on a property.");
+
+PyObject *
+property_deleter(PyObject *self, PyObject *deleter)
+{
+	return property_copy(self, NULL, NULL, deleter, NULL);
+}
+
+
+static PyMethodDef property_methods[] = {
+	{"getter", property_getter, METH_O, getter_doc},
+	{"setter", property_setter, METH_O, setter_doc},
+	{"deleter", property_deleter, METH_O, deleter_doc},
+	{0}
+};
+
+
 static void
 property_dealloc(PyObject *self)
 {
@@ -1156,15 +1174,63 @@
 	return 0;
 }
 
+static PyObject *
+property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *del,
+		PyObject *doc)
+{
+	propertyobject *pold = (propertyobject *)old;
+	propertyobject *pnew = NULL;
+	PyObject *new, *type;
+
+	type = PyObject_Type(old);
+	if (type == NULL)
+		return NULL;
+
+	if (get == NULL || get == Py_None) {
+		Py_XDECREF(get);
+		get = pold->prop_get ? pold->prop_get : Py_None;
+	}
+	if (set == NULL || set == Py_None) {
+		Py_XDECREF(set);
+		set = pold->prop_set ? pold->prop_set : Py_None;
+	}
+	if (del == NULL || del == Py_None) {
+		Py_XDECREF(del);
+		del = pold->prop_del ? pold->prop_del : Py_None;
+	}
+	if (doc == NULL || doc == Py_None) {
+		Py_XDECREF(doc);
+		doc = pold->prop_doc ? pold->prop_doc : Py_None;
+	}
+	
+	new =  PyObject_CallFunction(type, "OOOO", get, set, del, doc);
+	Py_DECREF(type);
+	if (new == NULL)
+		return NULL;
+	pnew = (propertyobject *)new;
+	
+	if (pold->getter_doc && get != Py_None) {
+		PyObject *get_doc = PyObject_GetAttrString(get, "__doc__");
+		if (get_doc != NULL) {
+			Py_XDECREF(pnew->prop_doc);
+			pnew->prop_doc = get_doc;  /* get_doc already INCREF'd by GetAttr */
+			pnew->getter_doc = 1;
+		} else {
+			PyErr_Clear();
+		}
+	}
+	return new;
+}
+
 static int
 property_init(PyObject *self, PyObject *args, PyObject *kwds)
 {
 	PyObject *get = NULL, *set = NULL, *del = NULL, *doc = NULL;
 	static char *kwlist[] = {"fget", "fset", "fdel", "doc", 0};
-	propertyobject *gs = (propertyobject *)self;
-
+	propertyobject *prop = (propertyobject *)self;
+	
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO:property",
-	     				 kwlist, &get, &set, &del, &doc))
+					 kwlist, &get, &set, &del, &doc))
 		return -1;
 
 	if (get == Py_None)
@@ -1179,22 +1245,24 @@
 	Py_XINCREF(del);
 	Py_XINCREF(doc);
 
+	prop->prop_get = get;
+	prop->prop_set = set;
+	prop->prop_del = del;
+	prop->prop_doc = doc;
+	prop->getter_doc = 0;
+
 	/* if no docstring given and the getter has one, use that one */
 	if ((doc == NULL || doc == Py_None) && get != NULL) {
 		PyObject *get_doc = PyObject_GetAttrString(get, "__doc__");
 		if (get_doc != NULL) {
-			Py_XDECREF(doc);
-			doc = get_doc;  /* get_doc already INCREF'd by GetAttr */
+			Py_XDECREF(prop->prop_doc);
+			prop->prop_doc = get_doc;  /* get_doc already INCREF'd by GetAttr */
+			prop->getter_doc = 1;
 		} else {
 			PyErr_Clear();
 		}
 	}
 
-	gs->prop_get = get;
-	gs->prop_set = set;
-	gs->prop_del = del;
-	gs->prop_doc = doc;
-
 	return 0;
 }
 
@@ -1205,10 +1273,20 @@
 "fset is a function for setting, and fdel a function for del'ing, an\n"
 "attribute.  Typical use is to define a managed attribute x:\n"
 "class C(object):\n"
-"    def getx(self): return self.__x\n"
-"    def setx(self, value): self.__x = value\n"
-"    def delx(self): del self.__x\n"
-"    x = property(getx, setx, delx, \"I'm the 'x' property.\")");
+"    def getx(self): return self._x\n"
+"    def setx(self, value): self._x = value\n"
+"    def delx(self): del self._x\n"
+"    x = property(getx, setx, delx, \"I'm the 'x' property.\")\n"
+"\n"
+"Decorators make defining new properties or modifying existing ones easy:\n"
+"class C(object):\n"
+"    @property\n"
+"    def x(self): return self._x\n"
+"    @x.setter\n"
+"    def x(self, value): self._x = value\n"
+"    @x.deleter\n"
+"    def x(self): del self._x\n"
+);
 
 static int
 property_traverse(PyObject *self, visitproc visit, void *arg)
@@ -1251,7 +1329,7 @@
 	0,					/* tp_weaklistoffset */
 	0,					/* tp_iter */
 	0,					/* tp_iternext */
-	0,					/* tp_methods */
+	property_methods,			/* tp_methods */
 	property_members,			/* tp_members */
 	0,					/* tp_getset */
 	0,					/* tp_base */

Modified: python/branches/py3k-importlib/Objects/dictobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/dictobject.c	(original)
+++ python/branches/py3k-importlib/Objects/dictobject.c	Thu Mar 27 00:48:05 2008
@@ -8,9 +8,8 @@
 */
 
 #include "Python.h"
+#include "stringlib/eq.h"
 
-typedef PyDictEntry dictentry;
-typedef PyDictObject dictobject;
 
 /* Set a key error with the specified argument, wrapping it in a
  * tuple automatically so that tuple keys are not unpacked as the
@@ -116,14 +115,14 @@
 polynomial for each table size was chosen such that x was a primitive root.
 Christian Tismer later extended that to use division by x instead, as an
 efficient way to get the high bits of the hash code into play.  This scheme
-also gave excellent collision statistics, but was more expensive: two if-tests
-were required inside the loop; computing "the next" index took about the same
-number of operations but without as much potential parallelism (e.g.,
-computing 5*j can go on at the same time as computing 1+perturb in the above,
-and then shifting perturb can be done while the table index is being masked);
-and the dictobject struct required a member to hold the table's polynomial.
-In Tim's experiments the current scheme ran faster, produced equally good
-collision statistics, needed less code & used less memory.
+also gave excellent collision statistics, but was more expensive:  two
+if-tests were required inside the loop; computing "the next" index took about
+the same number of operations but without as much potential parallelism
+(e.g., computing 5*j can go on at the same time as computing 1+perturb in the
+above, and then shifting perturb can be done while the table index is being
+masked); and the PyDictObject struct required a member to hold the table's
+polynomial.  In Tim's experiments the current scheme ran faster, produced
+equally good collision statistics, needed less code & used less memory.
 
 Theoretical Python 2.5 headache:  hash codes are only C "long", but
 sizeof(Py_ssize_t) > sizeof(long) may be possible.  In that case, and if a
@@ -137,7 +136,7 @@
 */
 
 /* Object used as dummy key to fill deleted entries */
-static PyObject *dummy = NULL; /* Initialized by first call to newdictobject() */
+static PyObject *dummy = NULL; /* Initialized by first call to newPyDictObject() */
 
 #ifdef Py_REF_DEBUG
 PyObject *
@@ -148,8 +147,8 @@
 #endif
 
 /* forward declarations */
-static dictentry *
-lookdict_unicode(dictobject *mp, PyObject *key, long hash);
+static PyDictEntry *
+lookdict_unicode(PyDictObject *mp, PyObject *key, long hash);
 
 #ifdef SHOW_CONVERSION_COUNTS
 static long created = 0L;
@@ -164,6 +163,24 @@
 }
 #endif
 
+/* Debug statistic to compare allocations with reuse through the free list */
+#undef SHOW_ALLOC_COUNT
+#ifdef SHOW_ALLOC_COUNT
+static size_t count_alloc = 0;
+static size_t count_reuse = 0;
+
+static void
+show_alloc(void)
+{
+	fprintf(stderr, "Dict allocations: %" PY_FORMAT_SIZE_T "d\n",
+		count_alloc);
+	fprintf(stderr, "Dict reuse through freelist: %" PY_FORMAT_SIZE_T
+		"d\n", count_reuse);
+	fprintf(stderr, "%.2f%% reuse rate\n\n",
+		(100.0*count_reuse/(count_alloc+count_reuse)));
+}
+#endif
+
 /* Initialization macros.
    There are two ways to create a dict:  PyDict_New() is the main C API
    function, and the tp_new slot maps to dict_new().  In the latter case we
@@ -185,14 +202,28 @@
     } while(0)
 
 /* Dictionary reuse scheme to save calls to malloc, free, and memset */
-#define MAXFREEDICTS 80
-static PyDictObject *free_dicts[MAXFREEDICTS];
-static int num_free_dicts = 0;
+#ifndef PyDict_MAXFREELIST
+#define PyDict_MAXFREELIST 80
+#endif
+static PyDictObject *free_list[PyDict_MAXFREELIST];
+static int numfree = 0;
+
+void
+PyDict_Fini(void)
+{
+	PyDictObject *op;
+
+	while (numfree) {
+		op = free_list[--numfree];
+		assert(PyDict_CheckExact(op));
+		PyObject_GC_Del(op);
+	}
+}
 
 PyObject *
 PyDict_New(void)
 {
-	register dictobject *mp;
+	register PyDictObject *mp;
 	if (dummy == NULL) { /* Auto-initialize dummy */
 		dummy = PyUnicode_FromString("<dummy key>");
 		if (dummy == NULL)
@@ -200,11 +231,14 @@
 #ifdef SHOW_CONVERSION_COUNTS
 		Py_AtExit(show_counts);
 #endif
+#ifdef SHOW_ALLOC_COUNT
+		Py_AtExit(show_alloc);
+#endif
 	}
-	if (num_free_dicts) {
-		mp = free_dicts[--num_free_dicts];
+	if (numfree) {
+		mp = free_list[--numfree];
 		assert (mp != NULL);
-		assert (Py_Type(mp) == &PyDict_Type);
+		assert (Py_TYPE(mp) == &PyDict_Type);
 		_Py_NewReference((PyObject *)mp);
 		if (mp->ma_fill) {
 			EMPTY_TO_MINSIZE(mp);
@@ -212,11 +246,17 @@
 		assert (mp->ma_used == 0);
 		assert (mp->ma_table == mp->ma_smalltable);
 		assert (mp->ma_mask == PyDict_MINSIZE - 1);
+#ifdef SHOW_ALLOC_COUNT
+		count_reuse++;
+#endif
 	} else {
-		mp = PyObject_GC_New(dictobject, &PyDict_Type);
+		mp = PyObject_GC_New(PyDictObject, &PyDict_Type);
 		if (mp == NULL)
 			return NULL;
 		EMPTY_TO_MINSIZE(mp);
+#ifdef SHOW_ALLOC_COUNT
+		count_alloc++;
+#endif
 	}
 	mp->ma_lookup = lookdict_unicode;
 #ifdef SHOW_CONVERSION_COUNTS
@@ -245,20 +285,20 @@
 comparison raises an exception (this was new in Python 2.5).
 lookdict_unicode() below is specialized to string keys, comparison of which can
 never raise an exception; that function can never return NULL.  For both, when
-the key isn't found a dictentry* is returned for which the me_value field is
+the key isn't found a PyDictEntry* is returned for which the me_value field is
 NULL; this is the slot in the dict at which the key would have been found, and
 the caller can (if it wishes) add the <key, value> pair to the returned
-dictentry*.
+PyDictEntry*.
 */
-static dictentry *
-lookdict(dictobject *mp, PyObject *key, register long hash)
+static PyDictEntry *
+lookdict(PyDictObject *mp, PyObject *key, register long hash)
 {
 	register size_t i;
 	register size_t perturb;
-	register dictentry *freeslot;
+	register PyDictEntry *freeslot;
 	register size_t mask = (size_t)mp->ma_mask;
-	dictentry *ep0 = mp->ma_table;
-	register dictentry *ep;
+	PyDictEntry *ep0 = mp->ma_table;
+	register PyDictEntry *ep;
 	register int cmp;
 	PyObject *startkey;
 
@@ -272,7 +312,9 @@
 	else {
 		if (ep->me_hash == hash) {
 			startkey = ep->me_key;
+			Py_INCREF(startkey);
 			cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
+			Py_DECREF(startkey);
 			if (cmp < 0)
 				return NULL;
 			if (ep0 == mp->ma_table && ep->me_key == startkey) {
@@ -302,7 +344,9 @@
 			return ep;
 		if (ep->me_hash == hash && ep->me_key != dummy) {
 			startkey = ep->me_key;
+			Py_INCREF(startkey);
 			cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
+			Py_DECREF(startkey);
 			if (cmp < 0)
 				return NULL;
 			if (ep0 == mp->ma_table && ep->me_key == startkey) {
@@ -325,25 +369,6 @@
 	return 0;
 }
 
-/* Return 1 if two unicode objects are equal, 0 if not. */
-static int
-unicode_eq(PyObject *aa, PyObject *bb)
-{
-	PyUnicodeObject *a = (PyUnicodeObject *)aa;
-	PyUnicodeObject *b = (PyUnicodeObject *)bb;
-
-	if (a->length != b->length)
-		return 0;
-	if (a->length == 0)
-		return 1;
-	if (a->str[0] != b->str[0])
-		return 0;
-	if (a->length == 1)
-		return 1;
-	return memcmp(a->str, b->str, a->length * sizeof(Py_UNICODE)) == 0;
-}
-
-
 /*
  * Hacked up version of lookdict which can assume keys are always
  * unicodes; this assumption allows testing for errors during
@@ -354,15 +379,15 @@
  *
  * This is valuable because dicts with only unicode keys are very common.
  */
-static dictentry *
-lookdict_unicode(dictobject *mp, PyObject *key, register long hash)
+static PyDictEntry *
+lookdict_unicode(PyDictObject *mp, PyObject *key, register long hash)
 {
 	register size_t i;
 	register size_t perturb;
-	register dictentry *freeslot;
+	register PyDictEntry *freeslot;
 	register size_t mask = (size_t)mp->ma_mask;
-	dictentry *ep0 = mp->ma_table;
-	register dictentry *ep;
+	PyDictEntry *ep0 = mp->ma_table;
+	register PyDictEntry *ep;
 
 	/* Make sure this function doesn't have to handle non-unicode keys,
 	   including subclasses of str; e.g., one reason to subclass
@@ -413,10 +438,10 @@
 Returns -1 if an error occurred, or 0 on success.
 */
 static int
-insertdict(register dictobject *mp, PyObject *key, long hash, PyObject *value)
+insertdict(register PyDictObject *mp, PyObject *key, long hash, PyObject *value)
 {
 	PyObject *old_value;
-	register dictentry *ep;
+	register PyDictEntry *ep;
 	typedef PyDictEntry *(*lookupfunc)(PyDictObject *, PyObject *, long);
 
 	assert(mp->ma_lookup != NULL);
@@ -456,14 +481,14 @@
 is responsible for incref'ing `key` and `value`.
 */
 static void
-insertdict_clean(register dictobject *mp, PyObject *key, long hash,
+insertdict_clean(register PyDictObject *mp, PyObject *key, long hash,
 		 PyObject *value)
 {
 	register size_t i;
 	register size_t perturb;
 	register size_t mask = (size_t)mp->ma_mask;
-	dictentry *ep0 = mp->ma_table;
-	register dictentry *ep;
+	PyDictEntry *ep0 = mp->ma_table;
+	register PyDictEntry *ep;
 
 	i = hash & mask;
 	ep = &ep0[i];
@@ -485,13 +510,13 @@
 actually be smaller than the old one.
 */
 static int
-dictresize(dictobject *mp, Py_ssize_t minused)
+dictresize(PyDictObject *mp, Py_ssize_t minused)
 {
 	Py_ssize_t newsize;
-	dictentry *oldtable, *newtable, *ep;
+	PyDictEntry *oldtable, *newtable, *ep;
 	Py_ssize_t i;
 	int is_oldtable_malloced;
-	dictentry small_copy[PyDict_MINSIZE];
+	PyDictEntry small_copy[PyDict_MINSIZE];
 
 	assert(minused >= 0);
 
@@ -530,7 +555,7 @@
 		}
 	}
 	else {
-		newtable = PyMem_NEW(dictentry, newsize);
+		newtable = PyMem_NEW(PyDictEntry, newsize);
 		if (newtable == NULL) {
 			PyErr_NoMemory();
 			return -1;
@@ -541,7 +566,7 @@
 	assert(newtable != oldtable);
 	mp->ma_table = newtable;
 	mp->ma_mask = newsize - 1;
-	memset(newtable, 0, sizeof(dictentry) * newsize);
+	memset(newtable, 0, sizeof(PyDictEntry) * newsize);
 	mp->ma_used = 0;
 	i = mp->ma_fill;
 	mp->ma_fill = 0;
@@ -567,6 +592,23 @@
 	return 0;
 }
 
+/* Create a new dictionary pre-sized to hold an estimated number of elements.
+   Underestimates are okay because the dictionary will resize as necessary.
+   Overestimates just mean the dictionary will be more sparse than usual.
+*/
+
+PyObject *
+_PyDict_NewPresized(Py_ssize_t minused)
+{
+	PyObject *op = PyDict_New();
+
+	if (minused>5 && op != NULL && dictresize((PyDictObject *)op, minused) == -1) {
+		Py_DECREF(op);
+		return NULL;
+	}
+	return op;
+}
+
 /* Note that, for historical reasons, PyDict_GetItem() suppresses all errors
  * that may occur (originally dicts supported only string keys, and exceptions
  * weren't possible).  So, while the original intent was that a NULL return
@@ -581,8 +623,8 @@
 PyDict_GetItem(PyObject *op, PyObject *key)
 {
 	long hash;
-	dictobject *mp = (dictobject *)op;
-	dictentry *ep;
+	PyDictObject *mp = (PyDictObject *)op;
+	PyDictEntry *ep;
 	PyThreadState *tstate;
 	if (!PyDict_Check(op))
 		return NULL;
@@ -628,8 +670,8 @@
 PyDict_GetItemWithError(PyObject *op, PyObject *key)
 {
 	long hash;
-	dictobject *mp = (dictobject *)op;
-	dictentry *ep;
+        PyDictObject*mp = (PyDictObject *)op;
+	PyDictEntry *ep;
 
 	if (!PyDict_Check(op)) {
 		PyErr_BadInternalCall();
@@ -659,7 +701,7 @@
 int
 PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value)
 {
-	register dictobject *mp;
+	register PyDictObject *mp;
 	register long hash;
 	register Py_ssize_t n_used;
 
@@ -669,7 +711,7 @@
 	}
 	assert(key);
 	assert(value);
-	mp = (dictobject *)op;
+	mp = (PyDictObject *)op;
 	if (!PyUnicode_CheckExact(key) ||
 	    (hash = ((PyUnicodeObject *) key)->hash) == -1)
 	{
@@ -705,9 +747,9 @@
 int
 PyDict_DelItem(PyObject *op, PyObject *key)
 {
-	register dictobject *mp;
+	register PyDictObject *mp;
 	register long hash;
-	register dictentry *ep;
+	register PyDictEntry *ep;
 	PyObject *old_value, *old_key;
 
 	if (!PyDict_Check(op)) {
@@ -721,7 +763,7 @@
 		if (hash == -1)
 			return -1;
 	}
-	mp = (dictobject *)op;
+	mp = (PyDictObject *)op;
 	ep = (mp->ma_lookup)(mp, key, hash);
 	if (ep == NULL)
 		return -1;
@@ -743,18 +785,18 @@
 void
 PyDict_Clear(PyObject *op)
 {
-	dictobject *mp;
-	dictentry *ep, *table;
+	PyDictObject *mp;
+	PyDictEntry *ep, *table;
 	int table_is_malloced;
 	Py_ssize_t fill;
-	dictentry small_copy[PyDict_MINSIZE];
+	PyDictEntry small_copy[PyDict_MINSIZE];
 #ifdef Py_DEBUG
 	Py_ssize_t i, n;
 #endif
 
 	if (!PyDict_Check(op))
 		return;
-	mp = (dictobject *)op;
+	mp = (PyDictObject *)op;
 #ifdef Py_DEBUG
 	n = mp->ma_mask + 1;
 	i = 0;
@@ -829,15 +871,15 @@
 {
 	register Py_ssize_t i;
 	register Py_ssize_t mask;
-	register dictentry *ep;
+	register PyDictEntry *ep;
 
 	if (!PyDict_Check(op))
 		return 0;
 	i = *ppos;
 	if (i < 0)
 		return 0;
-	ep = ((dictobject *)op)->ma_table;
-	mask = ((dictobject *)op)->ma_mask;
+	ep = ((PyDictObject *)op)->ma_table;
+	mask = ((PyDictObject *)op)->ma_mask;
 	while (i <= mask && ep[i].me_value == NULL)
 		i++;
 	*ppos = i+1;
@@ -856,15 +898,15 @@
 {
 	register Py_ssize_t i;
 	register Py_ssize_t mask;
-	register dictentry *ep;
+	register PyDictEntry *ep;
 
 	if (!PyDict_Check(op))
 		return 0;
 	i = *ppos;
 	if (i < 0)
 		return 0;
-	ep = ((dictobject *)op)->ma_table;
-	mask = ((dictobject *)op)->ma_mask;
+	ep = ((PyDictObject *)op)->ma_table;
+	mask = ((PyDictObject *)op)->ma_mask;
 	while (i <= mask && ep[i].me_value == NULL)
 		i++;
 	*ppos = i+1;
@@ -881,9 +923,9 @@
 /* Methods */
 
 static void
-dict_dealloc(register dictobject *mp)
+dict_dealloc(register PyDictObject *mp)
 {
-	register dictentry *ep;
+	register PyDictEntry *ep;
 	Py_ssize_t fill = mp->ma_fill;
  	PyObject_GC_UnTrack(mp);
 	Py_TRASHCAN_SAFE_BEGIN(mp)
@@ -896,15 +938,15 @@
 	}
 	if (mp->ma_table != mp->ma_smalltable)
 		PyMem_DEL(mp->ma_table);
-	if (num_free_dicts < MAXFREEDICTS && Py_Type(mp) == &PyDict_Type)
-		free_dicts[num_free_dicts++] = mp;
+	if (numfree < PyDict_MAXFREELIST && Py_TYPE(mp) == &PyDict_Type)
+		free_list[numfree++] = mp;
 	else
-		Py_Type(mp)->tp_free((PyObject *)mp);
+		Py_TYPE(mp)->tp_free((PyObject *)mp);
 	Py_TRASHCAN_SAFE_END(mp)
 }
 
 static PyObject *
-dict_repr(dictobject *mp)
+dict_repr(PyDictObject *mp)
 {
 	Py_ssize_t i;
 	PyObject *s, *temp, *colon = NULL;
@@ -983,17 +1025,17 @@
 }
 
 static Py_ssize_t
-dict_length(dictobject *mp)
+dict_length(PyDictObject *mp)
 {
 	return mp->ma_used;
 }
 
 static PyObject *
-dict_subscript(dictobject *mp, register PyObject *key)
+dict_subscript(PyDictObject *mp, register PyObject *key)
 {
 	PyObject *v;
 	long hash;
-	dictentry *ep;
+	PyDictEntry *ep;
 	assert(mp->ma_table != NULL);
 	if (!PyUnicode_CheckExact(key) ||
 	    (hash = ((PyUnicodeObject *) key)->hash) == -1) {
@@ -1013,7 +1055,7 @@
 			if (missing_str == NULL)
 				missing_str =
 				  PyUnicode_InternFromString("__missing__");
-			missing = _PyType_Lookup(Py_Type(mp), missing_str);
+			missing = _PyType_Lookup(Py_TYPE(mp), missing_str);
 			if (missing != NULL)
 				return PyObject_CallFunctionObjArgs(missing,
 					(PyObject *)mp, key, NULL);
@@ -1027,7 +1069,7 @@
 }
 
 static int
-dict_ass_sub(dictobject *mp, PyObject *v, PyObject *w)
+dict_ass_sub(PyDictObject *mp, PyObject *v, PyObject *w)
 {
 	if (w == NULL)
 		return PyDict_DelItem((PyObject *)mp, v);
@@ -1042,11 +1084,11 @@
 };
 
 static PyObject *
-dict_keys(register dictobject *mp)
+dict_keys(register PyDictObject *mp)
 {
 	register PyObject *v;
 	register Py_ssize_t i, j;
-	dictentry *ep;
+	PyDictEntry *ep;
 	Py_ssize_t mask, n;
 
   again:
@@ -1076,11 +1118,11 @@
 }
 
 static PyObject *
-dict_values(register dictobject *mp)
+dict_values(register PyDictObject *mp)
 {
 	register PyObject *v;
 	register Py_ssize_t i, j;
-	dictentry *ep;
+	PyDictEntry *ep;
 	Py_ssize_t mask, n;
 
   again:
@@ -1110,13 +1152,13 @@
 }
 
 static PyObject *
-dict_items(register dictobject *mp)
+dict_items(register PyDictObject *mp)
 {
 	register PyObject *v;
 	register Py_ssize_t i, j, n;
 	Py_ssize_t mask;
 	PyObject *item, *key, *value;
-	dictentry *ep;
+	PyDictEntry *ep;
 
 	/* Preallocate the list of tuples, to avoid allocations during
 	 * the loop over the items, which could trigger GC, which
@@ -1177,8 +1219,27 @@
 	if (d == NULL)
 		return NULL;
 
+	if (PyDict_CheckExact(d) && PyDict_CheckExact(seq)) {
+		PyDictObject *mp = (PyDictObject *)d;
+		PyObject *oldvalue;
+		Py_ssize_t pos = 0;
+		PyObject *key;
+		long hash;
+
+		if (dictresize(mp, PySet_GET_SIZE(seq)))
+			return NULL;
+
+		while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) {
+			Py_INCREF(key);
+			Py_INCREF(value);
+			if (insertdict(mp, key, hash, value))
+				return NULL;
+		}
+		return d;
+	}
+
 	if (PyDict_CheckExact(d) && PyAnySet_CheckExact(seq)) {
-		dictobject *mp = (dictobject *)d;
+		PyDictObject *mp = (PyDictObject *)d;
 		Py_ssize_t pos = 0;
 		PyObject *key;
 		long hash;
@@ -1201,19 +1262,24 @@
 		return NULL;
 	}
 
-	for (;;) {
-		key = PyIter_Next(it);
-		if (key == NULL) {
-			if (PyErr_Occurred())
+	if (PyDict_CheckExact(d)) {
+		while ((key = PyIter_Next(it)) != NULL) {
+			status = PyDict_SetItem(d, key, value);
+			Py_DECREF(key);
+			if (status < 0)
+				goto Fail;
+		}
+	} else {
+		while ((key = PyIter_Next(it)) != NULL) {
+			status = PyObject_SetItem(d, key, value);
+			Py_DECREF(key);
+			if (status < 0)
 				goto Fail;
-			break;
 		}
-		status = PyObject_SetItem(d, key, value);
-		Py_DECREF(key);
-		if (status < 0)
-			goto Fail;
 	}
 
+	if (PyErr_Occurred())
+		goto Fail;
 	Py_DECREF(it);
 	return d;
 
@@ -1342,7 +1408,7 @@
 {
 	register PyDictObject *mp, *other;
 	register Py_ssize_t i;
-	dictentry *entry;
+	PyDictEntry *entry;
 
 	/* We accept for the argument either a concrete dictionary object,
 	 * or an abstract "mapping" object.  For the former, we can do
@@ -1353,9 +1419,9 @@
 		PyErr_BadInternalCall();
 		return -1;
 	}
-	mp = (dictobject*)a;
-	if (PyDict_CheckExact(b)) {
-		other = (dictobject*)b;
+	mp = (PyDictObject*)a;
+	if (PyDict_Check(b)) {
+		other = (PyDictObject*)b;
 		if (other == mp || other->ma_used == 0)
 			/* a.update(a) or a.update({}); nothing to do */
 			return 0;
@@ -1435,7 +1501,7 @@
 }
 
 static PyObject *
-dict_copy(register dictobject *mp)
+dict_copy(register PyDictObject *mp)
 {
 	return PyDict_Copy((PyObject*)mp);
 }
@@ -1465,7 +1531,7 @@
 		PyErr_BadInternalCall();
 		return -1;
 	}
-	return ((dictobject *)mp)->ma_used;
+	return ((PyDictObject *)mp)->ma_used;
 }
 
 PyObject *
@@ -1475,7 +1541,7 @@
 		PyErr_BadInternalCall();
 		return NULL;
 	}
-	return dict_keys((dictobject *)mp);
+	return dict_keys((PyDictObject *)mp);
 }
 
 PyObject *
@@ -1485,7 +1551,7 @@
 		PyErr_BadInternalCall();
 		return NULL;
 	}
-	return dict_values((dictobject *)mp);
+	return dict_values((PyDictObject *)mp);
 }
 
 PyObject *
@@ -1495,7 +1561,7 @@
 		PyErr_BadInternalCall();
 		return NULL;
 	}
-	return dict_items((dictobject *)mp);
+	return dict_items((PyDictObject *)mp);
 }
 
 /* Return 1 if dicts equal, 0 if not, -1 if error.
@@ -1503,7 +1569,7 @@
  * Uses only Py_EQ comparison.
  */
 static int
-dict_equal(dictobject *a, dictobject *b)
+dict_equal(PyDictObject *a, PyDictObject *b)
 {
 	Py_ssize_t i;
 
@@ -1550,7 +1616,7 @@
 		res = Py_NotImplemented;
 	}
 	else if (op == Py_EQ || op == Py_NE) {
-		cmp = dict_equal((dictobject *)v, (dictobject *)w);
+		cmp = dict_equal((PyDictObject *)v, (PyDictObject *)w);
 		if (cmp < 0)
 			return NULL;
 		res = (cmp == (op == Py_EQ)) ? Py_True : Py_False;
@@ -1562,10 +1628,10 @@
  }
 
 static PyObject *
-dict_contains(register dictobject *mp, PyObject *key)
+dict_contains(register PyDictObject *mp, PyObject *key)
 {
 	long hash;
-	dictentry *ep;
+	PyDictEntry *ep;
 
 	if (!PyUnicode_CheckExact(key) ||
 	    (hash = ((PyUnicodeObject *) key)->hash) == -1) {
@@ -1580,13 +1646,13 @@
 }
 
 static PyObject *
-dict_get(register dictobject *mp, PyObject *args)
+dict_get(register PyDictObject *mp, PyObject *args)
 {
 	PyObject *key;
 	PyObject *failobj = Py_None;
 	PyObject *val = NULL;
 	long hash;
-	dictentry *ep;
+	PyDictEntry *ep;
 
 	if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &failobj))
 		return NULL;
@@ -1609,13 +1675,13 @@
 
 
 static PyObject *
-dict_setdefault(register dictobject *mp, PyObject *args)
+dict_setdefault(register PyDictObject *mp, PyObject *args)
 {
 	PyObject *key;
 	PyObject *failobj = Py_None;
 	PyObject *val = NULL;
 	long hash;
-	dictentry *ep;
+	PyDictEntry *ep;
 
 	if (!PyArg_UnpackTuple(args, "setdefault", 1, 2, &key, &failobj))
 		return NULL;
@@ -1641,17 +1707,17 @@
 
 
 static PyObject *
-dict_clear(register dictobject *mp)
+dict_clear(register PyDictObject *mp)
 {
 	PyDict_Clear((PyObject *)mp);
 	Py_RETURN_NONE;
 }
 
 static PyObject *
-dict_pop(dictobject *mp, PyObject *args)
+dict_pop(PyDictObject *mp, PyObject *args)
 {
 	long hash;
-	dictentry *ep;
+	PyDictEntry *ep;
 	PyObject *old_value, *old_key;
 	PyObject *key, *deflt = NULL;
 
@@ -1694,10 +1760,10 @@
 }
 
 static PyObject *
-dict_popitem(dictobject *mp)
+dict_popitem(PyDictObject *mp)
 {
 	Py_ssize_t i = 0;
-	dictentry *ep;
+	PyDictEntry *ep;
 	PyObject *res;
 
 	/* Allocate the result tuple before checking the size.  Believe it
@@ -1772,12 +1838,7 @@
 	return 0;
 }
 
-
-extern PyTypeObject PyDictIterKey_Type; /* Forward */
-extern PyTypeObject PyDictIterValue_Type; /* Forward */
-extern PyTypeObject PyDictIterItem_Type; /* Forward */
-static PyObject *dictiter_new(dictobject *, PyTypeObject *);
-
+static PyObject *dictiter_new(PyDictObject *, PyTypeObject *);
 
 PyDoc_STRVAR(contains__doc__,
 "D.__contains__(k) -> True if D has a key k, else False");
@@ -1859,8 +1920,8 @@
 PyDict_Contains(PyObject *op, PyObject *key)
 {
 	long hash;
-	dictobject *mp = (dictobject *)op;
-	dictentry *ep;
+	PyDictObject *mp = (PyDictObject *)op;
+	PyDictEntry *ep;
 
 	if (!PyUnicode_CheckExact(key) ||
 	    (hash = ((PyUnicodeObject *) key)->hash) == -1) {
@@ -1876,8 +1937,8 @@
 int
 _PyDict_Contains(PyObject *op, PyObject *key, long hash)
 {
-	dictobject *mp = (dictobject *)op;
-	dictentry *ep;
+	PyDictObject *mp = (PyDictObject *)op;
+	PyDictEntry *ep;
 
 	ep = (mp->ma_lookup)(mp, key, hash);
 	return ep == NULL ? -1 : (ep->me_value != NULL);
@@ -1924,7 +1985,7 @@
 }
 
 static PyObject *
-dict_iter(dictobject *dict)
+dict_iter(PyDictObject *dict)
 {
 	return dictiter_new(dict, &PyDictIterKey_Type);
 }
@@ -1943,7 +2004,7 @@
 PyTypeObject PyDict_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
 	"dict",
-	sizeof(dictobject),
+	sizeof(PyDictObject),
 	0,
 	(destructor)dict_dealloc,		/* tp_dealloc */
 	0,					/* tp_print */
@@ -2028,7 +2089,7 @@
 
 typedef struct {
 	PyObject_HEAD
-	dictobject *di_dict; /* Set to NULL when iterator is exhausted */
+	PyDictObject *di_dict; /* Set to NULL when iterator is exhausted */
 	Py_ssize_t di_used;
 	Py_ssize_t di_pos;
 	PyObject* di_result; /* reusable result tuple for iteritems */
@@ -2036,7 +2097,7 @@
 } dictiterobject;
 
 static PyObject *
-dictiter_new(dictobject *dict, PyTypeObject *itertype)
+dictiter_new(PyDictObject *dict, PyTypeObject *itertype)
 {
 	dictiterobject *di;
 	di = PyObject_New(dictiterobject, itertype);
@@ -2073,7 +2134,7 @@
 	Py_ssize_t len = 0;
 	if (di->di_dict != NULL && di->di_used == di->di_dict->ma_used)
 		len = di->len;
-	return PyInt_FromSize_t(len);
+	return PyLong_FromSize_t(len);
 }
 
 PyDoc_STRVAR(length_hint_doc,
@@ -2089,8 +2150,8 @@
 {
 	PyObject *key;
 	register Py_ssize_t i, mask;
-	register dictentry *ep;
-	dictobject *d = di->di_dict;
+	register PyDictEntry *ep;
+	PyDictObject *d = di->di_dict;
 
 	if (d == NULL)
 		return NULL;
@@ -2126,7 +2187,7 @@
 
 PyTypeObject PyDictIterKey_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"dictionary-keyiterator",		/* tp_name */
+	"dict_keyiterator",			/* tp_name */
 	sizeof(dictiterobject),			/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */
@@ -2161,8 +2222,8 @@
 {
 	PyObject *value;
 	register Py_ssize_t i, mask;
-	register dictentry *ep;
-	dictobject *d = di->di_dict;
+	register PyDictEntry *ep;
+	PyDictObject *d = di->di_dict;
 
 	if (d == NULL)
 		return NULL;
@@ -2198,7 +2259,7 @@
 
 PyTypeObject PyDictIterValue_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"dictionary-valueiterator",		/* tp_name */
+	"dict_valueiterator",			/* tp_name */
 	sizeof(dictiterobject),			/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */
@@ -2233,8 +2294,8 @@
 {
 	PyObject *key, *value, *result = di->di_result;
 	register Py_ssize_t i, mask;
-	register dictentry *ep;
-	dictobject *d = di->di_dict;
+	register PyDictEntry *ep;
+	PyDictObject *d = di->di_dict;
 
 	if (d == NULL)
 		return NULL;
@@ -2284,7 +2345,7 @@
 
 PyTypeObject PyDictIterItem_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"dictionary-itemiterator",		/* tp_name */
+	"dict_itemiterator",			/* tp_name */
 	sizeof(dictiterobject),			/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */
@@ -2324,7 +2385,7 @@
 
 typedef struct {
 	PyObject_HEAD
-	dictobject *dv_dict;
+	PyDictObject *dv_dict;
 } dictviewobject;
 
 
@@ -2363,7 +2424,7 @@
 	if (dv == NULL)
 		return NULL;
 	Py_INCREF(dict);
-	dv->dv_dict = (dictobject *)dict;
+	dv->dv_dict = (PyDictObject *)dict;
 	return (PyObject *)dv;
 }
 
@@ -2375,19 +2436,6 @@
    - if public then they should probably be in builtins
 */
 
-/* Forward */
-PyTypeObject PyDictKeys_Type;
-PyTypeObject PyDictItems_Type;
-PyTypeObject PyDictValues_Type;
-
-#define PyDictKeys_Check(obj) ((obj)->ob_type == &PyDictKeys_Type)
-#define PyDictItems_Check(obj) ((obj)->ob_type == &PyDictItems_Type)
-#define PyDictValues_Check(obj) ((obj)->ob_type == &PyDictValues_Type)
-
-/* This excludes Values, since they are not sets. */
-# define PyDictViewSet_Check(obj) \
-	(PyDictKeys_Check(obj) || PyDictItems_Check(obj))
-
 /* Return 1 if self is a subset of other, iterating over self;
    0 if not; -1 if an error occurred. */
 static int

Modified: python/branches/py3k-importlib/Objects/enumobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/enumobject.c	(original)
+++ python/branches/py3k-importlib/Objects/enumobject.c	Thu Mar 27 00:48:05 2008
@@ -7,6 +7,7 @@
 	long      en_index;        /* current index of enumeration */
 	PyObject* en_sit;          /* secondary iterator of enumeration */
 	PyObject* en_result;	   /* result tuple  */
+	PyObject* en_longindex;	   /* index for sequences >= LONG_MAX */
 } enumobject;
 
 static PyObject *
@@ -25,6 +26,7 @@
 		return NULL;
 	en->en_index = 0;
 	en->en_sit = PyObject_GetIter(seq);
+	en->en_longindex = NULL;
 	if (en->en_sit == NULL) {
 		Py_DECREF(en);
 		return NULL;
@@ -43,7 +45,8 @@
 	PyObject_GC_UnTrack(en);
 	Py_XDECREF(en->en_sit);
 	Py_XDECREF(en->en_result);
-	Py_Type(en)->tp_free(en);
+	Py_XDECREF(en->en_longindex);
+	Py_TYPE(en)->tp_free(en);
 }
 
 static int
@@ -51,10 +54,53 @@
 {
 	Py_VISIT(en->en_sit);
 	Py_VISIT(en->en_result);
+	Py_VISIT(en->en_longindex);
 	return 0;
 }
 
 static PyObject *
+enum_next_long(enumobject *en, PyObject* next_item)
+{
+	static PyObject *one = NULL;
+	PyObject *result = en->en_result;
+	PyObject *next_index;
+	PyObject *stepped_up;
+
+	if (en->en_longindex == NULL) {
+		en->en_longindex = PyLong_FromLong(LONG_MAX);
+		if (en->en_longindex == NULL)
+			return NULL;
+	}
+	if (one == NULL) {
+		one = PyLong_FromLong(1);
+		if (one == NULL)
+			return NULL;
+	}
+	next_index = en->en_longindex;
+	assert(next_index != NULL);
+	stepped_up = PyNumber_Add(next_index, one);
+	if (stepped_up == NULL)
+		return NULL;
+	en->en_longindex = stepped_up;
+
+	if (result->ob_refcnt == 1) {
+		Py_INCREF(result);
+		Py_DECREF(PyTuple_GET_ITEM(result, 0));
+		Py_DECREF(PyTuple_GET_ITEM(result, 1));
+	} else {
+		result = PyTuple_New(2);
+		if (result == NULL) {
+			Py_DECREF(next_index);
+			Py_DECREF(next_item);
+			return NULL;
+		}
+	}
+	PyTuple_SET_ITEM(result, 0, next_index);
+	PyTuple_SET_ITEM(result, 1, next_item);
+	return result;
+}
+
+static PyObject *
 enum_next(enumobject *en)
 {
 	PyObject *next_index;
@@ -62,17 +108,14 @@
 	PyObject *result = en->en_result;
 	PyObject *it = en->en_sit;
 
-	if (en->en_index == LONG_MAX) {
-		PyErr_SetString(PyExc_OverflowError,
-			"enumerate() is limited to LONG_MAX items");                
-		return NULL;         
-	}
-
-	next_item = (*Py_Type(it)->tp_iternext)(it);
+	next_item = (*Py_TYPE(it)->tp_iternext)(it);
 	if (next_item == NULL)
 		return NULL;
 
-	next_index = PyInt_FromLong(en->en_index);
+	if (en->en_index == LONG_MAX)
+		return enum_next_long(en, next_item);
+
+	next_index = PyLong_FromLong(en->en_index);
 	if (next_index == NULL) {
 		Py_DECREF(next_item);
 		return NULL;
@@ -194,7 +237,7 @@
 {
 	PyObject_GC_UnTrack(ro);
 	Py_XDECREF(ro->seq);
-	Py_Type(ro)->tp_free(ro);
+	Py_TYPE(ro)->tp_free(ro);
 }
 
 static int
@@ -236,12 +279,12 @@
 	Py_ssize_t position, seqsize;
 
 	if (ro->seq == NULL)
-		return PyInt_FromLong(0);
+		return PyLong_FromLong(0);
 	seqsize = PySequence_Size(ro->seq);
 	if (seqsize == -1)
 		return NULL;
 	position = ro->index + 1;
-	return PyInt_FromSsize_t((seqsize < position)  ?  0  :  position);
+	return PyLong_FromSsize_t((seqsize < position)  ?  0  :  position);
 }
 
 PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");

Modified: python/branches/py3k-importlib/Objects/exceptions.c
==============================================================================
--- python/branches/py3k-importlib/Objects/exceptions.c	(original)
+++ python/branches/py3k-importlib/Objects/exceptions.c	Thu Mar 27 00:48:05 2008
@@ -42,7 +42,7 @@
 static int
 BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds)
 {
-    if (!_PyArg_NoKeywords(Py_Type(self)->tp_name, kwds))
+    if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds))
         return -1;
 
     Py_DECREF(self->args);
@@ -68,7 +68,7 @@
 {
     _PyObject_GC_UNTRACK(self);
     BaseException_clear(self);
-    Py_Type(self)->tp_free((PyObject *)self);
+    Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static int
@@ -89,9 +89,9 @@
     case 0:
         return PyUnicode_FromString("");
     case 1:
-        return PyObject_Unicode(PyTuple_GET_ITEM(self->args, 0));
+        return PyObject_Str(PyTuple_GET_ITEM(self->args, 0));
     default:
-        return PyObject_Unicode(self->args);
+        return PyObject_Str(self->args);
     }
 }
 
@@ -101,7 +101,7 @@
     char *name;
     char *dot;
 
-    name = (char *)Py_Type(self)->tp_name;
+    name = (char *)Py_TYPE(self)->tp_name;
     dot = strrchr(name, '.');
     if (dot != NULL) name = dot+1;
 
@@ -113,9 +113,9 @@
 BaseException_reduce(PyBaseExceptionObject *self)
 {
     if (self->args && self->dict)
-        return PyTuple_Pack(3, Py_Type(self), self->args, self->dict);
+        return PyTuple_Pack(3, Py_TYPE(self), self->args, self->dict);
     else
-        return PyTuple_Pack(2, Py_Type(self), self->args);
+        return PyTuple_Pack(2, Py_TYPE(self), self->args);
 }
 
 /*
@@ -424,9 +424,9 @@
 
 
 /*
- *    GeneratorExit extends Exception
+ *    GeneratorExit extends BaseException
  */
-SimpleExtendsException(PyExc_Exception, GeneratorExit,
+SimpleExtendsException(PyExc_BaseException, GeneratorExit,
                        "Request that a generator exit.");
 
 
@@ -465,7 +465,7 @@
 {
     _PyObject_GC_UNTRACK(self);
     SystemExit_clear(self);
-    Py_Type(self)->tp_free((PyObject *)self);
+    Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static int
@@ -570,7 +570,7 @@
 {
     _PyObject_GC_UNTRACK(self);
     EnvironmentError_clear(self);
-    Py_Type(self)->tp_free((PyObject *)self);
+    Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static int
@@ -636,9 +636,9 @@
         Py_INCREF(args);
 
     if (self->dict)
-        res = PyTuple_Pack(3, Py_Type(self), args, self->dict);
+        res = PyTuple_Pack(3, Py_TYPE(self), args, self->dict);
     else
-        res = PyTuple_Pack(2, Py_Type(self), args);
+        res = PyTuple_Pack(2, Py_TYPE(self), args);
     Py_DECREF(args);
     return res;
 }
@@ -691,7 +691,7 @@
 {
     _PyObject_GC_UNTRACK(self);
     WindowsError_clear(self);
-    Py_Type(self)->tp_free((PyObject *)self);
+    Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static int
@@ -720,7 +720,7 @@
 
     /* Set errno to the POSIX errno, and winerror to the Win32
        error code. */
-    errcode = PyInt_AsLong(self->myerrno);
+    errcode = PyLong_AsLong(self->myerrno);
     if (errcode == -1 && PyErr_Occurred())
         return -1;
     posix_errno = winerror_to_errno(errcode);
@@ -728,7 +728,7 @@
     Py_CLEAR(self->winerror);
     self->winerror = self->myerrno;
 
-    o_errcode = PyInt_FromLong(posix_errno);
+    o_errcode = PyLong_FromLong(posix_errno);
     if (!o_errcode)
         return -1;
 
@@ -889,7 +889,7 @@
 {
     _PyObject_GC_UNTRACK(self);
     SyntaxError_clear(self);
-    Py_Type(self)->tp_free((PyObject *)self);
+    Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static int
@@ -929,6 +929,10 @@
 {
     int have_lineno = 0;
     char *filename = 0;
+    /* Below, we always ignore overflow errors, just printing -1.
+       Still, we cannot allow an OverflowError to be raised, so
+       we need to call PyLong_AsLongAndOverflow. */
+    int overflow;
 
     /* XXX -- do all the additional formatting with filename and
        lineno here */
@@ -936,16 +940,16 @@
     if (self->filename && PyUnicode_Check(self->filename)) {
 	    filename = PyUnicode_AsString(self->filename);
     }
-    have_lineno = (self->lineno != NULL) && PyInt_CheckExact(self->lineno);
+    have_lineno = (self->lineno != NULL) && PyLong_CheckExact(self->lineno);
 
     if (!filename && !have_lineno)
-        return PyObject_Unicode(self->msg ? self->msg : Py_None);
+        return PyObject_Str(self->msg ? self->msg : Py_None);
 
     if (filename && have_lineno)
         return PyUnicode_FromFormat("%S (%s, line %ld)",
                    self->msg ? self->msg : Py_None,
                    my_basename(filename),
-                   PyInt_AsLong(self->lineno));
+		   PyLong_AsLongAndOverflow(self->lineno, &overflow));
     else if (filename)
         return PyUnicode_FromFormat("%S (%s)",
                    self->msg ? self->msg : Py_None,
@@ -953,7 +957,7 @@
     else /* only have_lineno */
         return PyUnicode_FromFormat("%S (line %ld)",
                    self->msg ? self->msg : Py_None,
-                   PyInt_AsLong(self->lineno));
+                   PyLong_AsLongAndOverflow(self->lineno, &overflow));
 }
 
 static PyMemberDef SyntaxError_members[] = {
@@ -1045,14 +1049,14 @@
                        "Unicode related error.");
 
 static PyObject *
-get_bytes(PyObject *attr, const char *name)
+get_string(PyObject *attr, const char *name)
 {
     if (!attr) {
         PyErr_Format(PyExc_TypeError, "%.200s attribute not set", name);
         return NULL;
     }
 
-    if (!PyBytes_Check(attr)) {
+    if (!PyString_Check(attr)) {
         PyErr_Format(PyExc_TypeError, "%.200s attribute must be bytes", name);
         return NULL;
     }
@@ -1109,7 +1113,7 @@
 PyObject *
 PyUnicodeDecodeError_GetObject(PyObject *exc)
 {
-    return get_bytes(((PyUnicodeErrorObject *)exc)->object, "object");
+    return get_string(((PyUnicodeErrorObject *)exc)->object, "object");
 }
 
 PyObject *
@@ -1141,10 +1145,10 @@
 PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start)
 {
     Py_ssize_t size;
-    PyObject *obj = get_bytes(((PyUnicodeErrorObject *)exc)->object, "object");
+    PyObject *obj = get_string(((PyUnicodeErrorObject *)exc)->object, "object");
     if (!obj)
         return -1;
-    size = PyBytes_GET_SIZE(obj);
+    size = PyString_GET_SIZE(obj);
     *start = ((PyUnicodeErrorObject *)exc)->start;
     if (*start<0)
         *start = 0;
@@ -1209,10 +1213,10 @@
 PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
 {
     Py_ssize_t size;
-    PyObject *obj = get_bytes(((PyUnicodeErrorObject *)exc)->object, "object");
+    PyObject *obj = get_string(((PyUnicodeErrorObject *)exc)->object, "object");
     if (!obj)
         return -1;
-    size = PyBytes_GET_SIZE(obj);
+    size = PyString_GET_SIZE(obj);
     *end = ((PyUnicodeErrorObject *)exc)->end;
     if (*end<1)
         *end = 1;
@@ -1299,31 +1303,6 @@
 
 
 static int
-UnicodeError_init(PyUnicodeErrorObject *self, PyObject *args, PyObject *kwds,
-                  PyTypeObject *objecttype)
-{
-    Py_CLEAR(self->encoding);
-    Py_CLEAR(self->object);
-    Py_CLEAR(self->reason);
-
-    if (!PyArg_ParseTuple(args, "O!O!nnO!",
-        &PyUnicode_Type, &self->encoding,
-        objecttype, &self->object,
-        &self->start,
-        &self->end,
-        &PyUnicode_Type, &self->reason)) {
-        self->encoding = self->object = self->reason = NULL;
-        return -1;
-    }
-
-    Py_INCREF(self->encoding);
-    Py_INCREF(self->object);
-    Py_INCREF(self->reason);
-
-    return 0;
-}
-
-static int
 UnicodeError_clear(PyUnicodeErrorObject *self)
 {
     Py_CLEAR(self->encoding);
@@ -1337,7 +1316,7 @@
 {
     _PyObject_GC_UNTRACK(self);
     UnicodeError_clear(self);
-    Py_Type(self)->tp_free((PyObject *)self);
+    Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
 static int
@@ -1371,10 +1350,32 @@
 static int
 UnicodeEncodeError_init(PyObject *self, PyObject *args, PyObject *kwds)
 {
+    PyUnicodeErrorObject *err;
+
     if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)
         return -1;
-    return UnicodeError_init((PyUnicodeErrorObject *)self, args,
-                             kwds, &PyUnicode_Type);
+
+    err = (PyUnicodeErrorObject *)self;
+
+    Py_CLEAR(err->encoding);
+    Py_CLEAR(err->object);
+    Py_CLEAR(err->reason);
+
+    if (!PyArg_ParseTuple(args, "O!O!nnO!",
+        &PyUnicode_Type, &err->encoding,
+        &PyUnicode_Type, &err->object,
+        &err->start,
+        &err->end,
+        &PyUnicode_Type, &err->reason)) {
+          err->encoding = err->object = err->reason = NULL;
+          return -1;
+    }
+
+    Py_INCREF(err->encoding);
+    Py_INCREF(err->object);
+    Py_INCREF(err->reason);
+
+    return 0;
 }
 
 static PyObject *
@@ -1439,10 +1440,44 @@
 static int
 UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds)
 {
+    PyUnicodeErrorObject *ude;
+    const char *data;
+    Py_ssize_t size;
+
     if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)
         return -1;
-    return UnicodeError_init((PyUnicodeErrorObject *)self, args,
-                             kwds, &PyBytes_Type);
+
+    ude = (PyUnicodeErrorObject *)self;
+
+    Py_CLEAR(ude->encoding);
+    Py_CLEAR(ude->object);
+    Py_CLEAR(ude->reason);
+
+    if (!PyArg_ParseTuple(args, "O!OnnO!",
+         &PyUnicode_Type, &ude->encoding,
+         &ude->object,
+         &ude->start,
+         &ude->end,
+         &PyUnicode_Type, &ude->reason)) {
+             ude->encoding = ude->object = ude->reason = NULL;
+             return -1;
+    }
+
+    if (!PyString_Check(ude->object)) {
+        if (PyObject_AsReadBuffer(ude->object, (const void **)&data, &size)) {
+            ude->encoding = ude->object = ude->reason = NULL;
+            return -1;
+        }
+        ude->object = PyString_FromStringAndSize(data, size);
+    }
+    else {
+        Py_INCREF(ude->object);
+    }
+
+    Py_INCREF(ude->encoding);
+    Py_INCREF(ude->reason);
+
+    return 0;
 }
 
 static PyObject *
@@ -1451,7 +1486,7 @@
     PyUnicodeErrorObject *uself = (PyUnicodeErrorObject *)self;
 
     if (uself->end==uself->start+1) {
-        int byte = (int)(PyBytes_AS_STRING(((PyUnicodeErrorObject *)self)->object)[uself->start]&0xff);
+        int byte = (int)(PyString_AS_STRING(((PyUnicodeErrorObject *)self)->object)[uself->start]&0xff);
         return PyUnicode_FromFormat(
             "'%U' codec can't decode byte 0x%02x in position %zd: %U",
             ((PyUnicodeErrorObject *)self)->encoding,
@@ -1709,6 +1744,14 @@
     "Base class for warnings about Unicode related problems, mostly\n"
     "related to conversion problems.");
 
+/*
+ *    BytesWarning extends Warning
+ */
+SimpleExtendsException(PyExc_Warning, BytesWarning,
+    "Base class for warnings about bytes and buffer related problems, mostly\n"
+    "related to conversion from str or comparing to str.");
+
+
 
 /* Pre-computed MemoryError instance.  Best to create this as early as
  * possible and not wait until a MemoryError is actually raised!
@@ -1808,8 +1851,9 @@
     PRE_INIT(FutureWarning)
     PRE_INIT(ImportWarning)
     PRE_INIT(UnicodeWarning)
+    PRE_INIT(BytesWarning)
 
-    bltinmod = PyImport_ImportModule("__builtin__");
+    bltinmod = PyImport_ImportModule("builtins");
     if (bltinmod == NULL)
         Py_FatalError("exceptions bootstrapping error.");
     bdict = PyModule_GetDict(bltinmod);
@@ -1868,6 +1912,7 @@
     POST_INIT(FutureWarning)
     POST_INIT(ImportWarning)
     POST_INIT(UnicodeWarning)
+    POST_INIT(BytesWarning)
 
     PyExc_MemoryErrorInst = BaseException_new(&_PyExc_MemoryError, NULL, NULL);
     if (!PyExc_MemoryErrorInst)
@@ -1882,7 +1927,7 @@
 	    (PyBaseExceptionObject *)PyExc_RecursionErrorInst;
 	PyObject *args_tuple;
 	PyObject *exc_message;
-	exc_message = PyString_FromString("maximum recursion depth exceeded");
+	exc_message = PyUnicode_FromString("maximum recursion depth exceeded");
 	if (!exc_message)
 	    Py_FatalError("cannot allocate argument for RuntimeError "
 			    "pre-allocation");

Modified: python/branches/py3k-importlib/Objects/fileobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/fileobject.c	(original)
+++ python/branches/py3k-importlib/Objects/fileobject.c	Thu Mar 27 00:48:05 2008
@@ -26,24 +26,29 @@
 /* External C interface */
 
 PyObject *
-PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *))
+PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding,
+	      char *errors, char *newline, int closefd)
 {
-	PyObject *io, *stream, *nameobj;
+	PyObject *io, *stream, *nameobj = NULL;
 
 	io = PyImport_ImportModule("io");
 	if (io == NULL)
 		return NULL;
-	stream = PyObject_CallMethod(io, "open", "is", fileno(fp), mode);
-        Py_DECREF(io);
+	stream = PyObject_CallMethod(io, "open", "isisssi", fd, mode,
+				     buffering, encoding, errors,
+				     newline, closefd);
+	Py_DECREF(io);
 	if (stream == NULL)
 		return NULL;
-        nameobj = PyUnicode_FromString(name);
-        if (nameobj == NULL)
-		PyErr_Clear();
-	else {
-		if (PyObject_SetAttrString(stream, "name", nameobj) < 0)
+	if (name != NULL) {
+		nameobj = PyUnicode_FromString(name);
+		if (nameobj == NULL)
 			PyErr_Clear();
-		Py_DECREF(nameobj);
+		else {
+			if (PyObject_SetAttrString(stream, "name", nameobj) < 0)
+				PyErr_Clear();
+			Py_DECREF(nameobj);
+		}
 	}
 	return stream;
 }
@@ -142,7 +147,7 @@
 	if (writer == NULL)
 		return -1;
 	if (flags & Py_PRINT_RAW) {
-		value = _PyObject_Str(v);
+		value = PyObject_Str(v);
 	}
 	else
 		value = PyObject_Repr(v);
@@ -202,10 +207,7 @@
 	int fd;
 	PyObject *meth;
 
-	if (PyInt_Check(o)) {
-		fd = PyInt_AsLong(o);
-	}
-	else if (PyLong_Check(o)) {
+	if (PyLong_Check(o)) {
 		fd = PyLong_AsLong(o);
 	}
 	else if ((meth = PyObject_GetAttrString(o, "fileno")) != NULL)
@@ -215,11 +217,7 @@
 		if (fno == NULL)
 			return -1;
 
-		if (PyInt_Check(fno)) {
-			fd = PyInt_AsLong(fno);
-			Py_DECREF(fno);
-		}
-		else if (PyLong_Check(fno)) {
+		if (PyLong_Check(fno)) {
 			fd = PyLong_AsLong(fno);
 			Py_DECREF(fno);
 		}
@@ -328,6 +326,204 @@
 	return buf;
 }
 
+/* **************************** std printer ****************************
+ * The stdprinter is used during the boot strapping phase as a preliminary
+ * file like object for sys.stderr.
+ */
+
+typedef struct {
+	PyObject_HEAD
+	int fd;
+} PyStdPrinter_Object;
+
+static PyObject *
+stdprinter_new(PyTypeObject *type, PyObject *args, PyObject *kews)
+{
+	PyStdPrinter_Object *self;
+
+	assert(type != NULL && type->tp_alloc != NULL);
+
+	self = (PyStdPrinter_Object *) type->tp_alloc(type, 0);
+	if (self != NULL) {
+		self->fd = -1;
+	}
+
+	return (PyObject *) self;
+}
+
+static int
+fileio_init(PyObject *self, PyObject *args, PyObject *kwds)
+{
+	PyErr_SetString(PyExc_TypeError,
+			"cannot create 'stderrprinter' instances");
+	return -1;
+}
+
+PyObject *
+PyFile_NewStdPrinter(int fd)
+{
+	PyStdPrinter_Object *self;
+
+	if (fd != fileno(stdout) && fd != fileno(stderr)) {
+		/* not enough infrastructure for PyErr_BadInternalCall() */
+		return NULL;
+	}
+
+	self = PyObject_New(PyStdPrinter_Object,
+			    &PyStdPrinter_Type);
+        if (self != NULL) {
+		self->fd = fd;
+	}
+	return (PyObject*)self;
+}
+
+PyObject *
+stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
+{
+	char *c;
+	Py_ssize_t n;
+
+	if (self->fd < 0) {
+		/* fd might be invalid on Windows
+		 * I can't raise an exception here. It may lead to an
+		 * unlimited recursion in the case stderr is invalid.
+		 */
+		Py_RETURN_NONE;
+	}
+
+	if (!PyArg_ParseTuple(args, "s", &c)) {
+		return NULL;
+	}
+	n = strlen(c);
+
+	Py_BEGIN_ALLOW_THREADS
+	errno = 0;
+	n = write(self->fd, c, n);
+	Py_END_ALLOW_THREADS
+
+	if (n < 0) {
+		if (errno == EAGAIN)
+			Py_RETURN_NONE;
+		PyErr_SetFromErrno(PyExc_IOError);
+		return NULL;
+	}
+
+	return PyLong_FromSsize_t(n);
+}
+
+static PyObject *
+stdprinter_fileno(PyStdPrinter_Object *self)
+{
+	return PyLong_FromLong((long) self->fd);
+}
+
+static PyObject *
+stdprinter_repr(PyStdPrinter_Object *self)
+{
+	return PyUnicode_FromFormat("<stdprinter(fd=%d) object at 0x%x>",
+				    self->fd, self);
+}
+
+static PyObject *
+stdprinter_noop(PyStdPrinter_Object *self)
+{
+	Py_RETURN_NONE;
+}
+
+static PyObject *
+stdprinter_isatty(PyStdPrinter_Object *self)
+{
+	long res;
+	if (self->fd < 0) {
+		Py_RETURN_FALSE;
+	}
+
+	Py_BEGIN_ALLOW_THREADS
+	res = isatty(self->fd);
+	Py_END_ALLOW_THREADS
+
+	return PyBool_FromLong(res);
+}
+
+static PyMethodDef stdprinter_methods[] = {
+	{"close",	(PyCFunction)stdprinter_noop, METH_NOARGS, ""},
+	{"flush",	(PyCFunction)stdprinter_noop, METH_NOARGS, ""},
+	{"fileno",	(PyCFunction)stdprinter_fileno, METH_NOARGS, ""},
+	{"isatty",	(PyCFunction)stdprinter_isatty, METH_NOARGS, ""},
+	{"write",	(PyCFunction)stdprinter_write, METH_VARARGS, ""},
+	{NULL,		NULL}  /*sentinel */
+};
+
+static PyObject *
+get_closed(PyStdPrinter_Object *self, void *closure)
+{
+	Py_INCREF(Py_False);
+	return Py_False;
+}
+
+static PyObject *
+get_mode(PyStdPrinter_Object *self, void *closure)
+{
+	return PyUnicode_FromString("w");
+}
+
+static PyObject *
+get_encoding(PyStdPrinter_Object *self, void *closure)
+{
+	Py_RETURN_NONE;
+}
+
+static PyGetSetDef stdprinter_getsetlist[] = {
+	{"closed", (getter)get_closed, NULL, "True if the file is closed"},
+	{"encoding", (getter)get_encoding, NULL, "Encoding of the file"},
+	{"mode", (getter)get_mode, NULL, "String giving the file mode"},
+	{0},
+};
+
+PyTypeObject PyStdPrinter_Type = {
+	PyVarObject_HEAD_INIT(&PyType_Type, 0)
+	"stderrprinter",			/* tp_name */
+	sizeof(PyStdPrinter_Object),		/* tp_basicsize */
+	0,					/* tp_itemsize */
+	/* methods */
+	0,					/* tp_dealloc */
+	0,					/* tp_print */
+	0,					/* tp_getattr */
+	0,					/* tp_setattr */
+	0,					/* tp_compare */
+	(reprfunc)stdprinter_repr,		/* 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,			/* tp_flags */
+	0,					/* tp_doc */
+	0,					/* tp_traverse */
+	0,					/* tp_clear */
+	0,					/* tp_richcompare */
+	0,					/* tp_weaklistoffset */
+	0,					/* tp_iter */
+	0,					/* tp_iternext */
+	stdprinter_methods,			/* tp_methods */
+	0,					/* tp_members */
+	stdprinter_getsetlist,			/* tp_getset */
+	0,					/* tp_base */
+	0,					/* tp_dict */
+	0,					/* tp_descr_get */
+	0,					/* tp_descr_set */
+	0,					/* tp_dictoffset */
+	fileio_init,				/* tp_init */
+	PyType_GenericAlloc,			/* tp_alloc */
+	stdprinter_new,				/* tp_new */
+	PyObject_Del,				/* tp_free */
+};
+
+
 #ifdef __cplusplus
 }
 #endif

Modified: python/branches/py3k-importlib/Objects/floatobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/floatobject.c	(original)
+++ python/branches/py3k-importlib/Objects/floatobject.c	Thu Mar 27 00:48:05 2008
@@ -5,16 +5,23 @@
    for any kind of float exception without losing portability. */
 
 #include "Python.h"
+#include "structseq.h"
 
 #include "formatter_unicode.h"
 
 #include <ctype.h>
+#include <float.h>
 
 #if !defined(__STDC__)
 extern double fmod(double, double);
 extern double pow(double, double);
 #endif
 
+#ifdef _OSF_SOURCE
+/* OSF1 5.1 doesn't make this available with XOPEN_SOURCE_EXTENDED defined */
+extern int finite(double);
+#endif
+
 /* Special free list -- see comments for same code in intobject.c. */
 #define BLOCK_SIZE	1000	/* 1K less typical malloc overhead */
 #define BHEAD_SIZE	8	/* Enough for a 64-bit pointer */
@@ -43,11 +50,96 @@
 	p = &((PyFloatBlock *)p)->objects[0];
 	q = p + N_FLOATOBJECTS;
 	while (--q > p)
-		Py_Type(q) = (struct _typeobject *)(q-1);
-	Py_Type(q) = NULL;
+		Py_TYPE(q) = (struct _typeobject *)(q-1);
+	Py_TYPE(q) = NULL;
 	return p + N_FLOATOBJECTS - 1;
 }
 
+double
+PyFloat_GetMax(void)
+{
+	return DBL_MAX;
+}
+
+double
+PyFloat_GetMin(void)
+{
+	return DBL_MIN;
+}
+
+static PyTypeObject FloatInfoType;
+
+PyDoc_STRVAR(floatinfo__doc__,
+"sys.floatinfo\n\
+\n\
+A structseq holding information about the float type. It contains low level\n\
+information about the precision and internal representation. Please study\n\
+your system's :file:`float.h` for more information.");
+
+static PyStructSequence_Field floatinfo_fields[] = {
+	{"max",		"DBL_MAX -- maximum representable finite float"},
+	{"max_exp",	"DBL_MAX_EXP -- maximum int e such that radix**(e-1) "
+			"is representable"},
+	{"max_10_exp",	"DBL_MAX_10_EXP -- maximum int e such that 10**e "
+			"is representable"},
+	{"min",		"DBL_MIN -- Minimum positive normalizer float"},
+	{"min_exp",	"DBL_MIN_EXP -- minimum int e such that radix**(e-1) "
+			"is a normalized float"},
+	{"min_10_exp",	"DBL_MIN_10_EXP -- minimum int e such that 10**e is "
+			"a normalized"},
+	{"dig",		"DBL_DIG -- digits"},
+	{"mant_dig",	"DBL_MANT_DIG -- mantissa digits"},
+	{"epsilon",	"DBL_EPSILON -- Difference between 1 and the next "
+			"representable float"},
+	{"radix",	"FLT_RADIX -- radix of exponent"},
+	{"rounds",	"FLT_ROUNDS -- addition rounds"},
+	{0}
+};
+
+static PyStructSequence_Desc floatinfo_desc = {
+	"sys.floatinfo",	/* name */
+	floatinfo__doc__,	/* doc */
+	floatinfo_fields,	/* fields */
+	11
+};
+
+PyObject *
+PyFloat_GetInfo(void)
+{
+	PyObject* floatinfo;
+	int pos = 0;
+
+	floatinfo = PyStructSequence_New(&FloatInfoType);
+	if (floatinfo == NULL) {
+		return NULL;
+	}
+
+#define SetIntFlag(flag) \
+	PyStructSequence_SET_ITEM(floatinfo, pos++, PyLong_FromLong(flag))
+#define SetDblFlag(flag) \
+	PyStructSequence_SET_ITEM(floatinfo, pos++, PyFloat_FromDouble(flag))
+
+	SetDblFlag(DBL_MAX);
+	SetIntFlag(DBL_MAX_EXP);
+	SetIntFlag(DBL_MAX_10_EXP);
+	SetDblFlag(DBL_MIN);
+	SetIntFlag(DBL_MIN_EXP);
+	SetIntFlag(DBL_MIN_10_EXP);
+	SetIntFlag(DBL_DIG);
+	SetIntFlag(DBL_MANT_DIG);
+	SetDblFlag(DBL_EPSILON);
+	SetIntFlag(FLT_RADIX);
+	SetIntFlag(FLT_ROUNDS);
+#undef SetIntFlag
+#undef SetDblFlag
+	
+	if (PyErr_Occurred()) {
+		Py_CLEAR(floatinfo);
+		return NULL;
+	}
+	return floatinfo;
+}
+
 PyObject *
 PyFloat_FromDouble(double fval)
 {
@@ -58,7 +150,7 @@
 	}
 	/* Inline PyObject_New */
 	op = free_list;
-	free_list = (PyFloatObject *)Py_Type(op);
+	free_list = (PyFloatObject *)Py_TYPE(op);
 	PyObject_INIT(op, &PyFloat_Type);
 	op->ob_fval = fval;
 	return (PyObject *) op;
@@ -67,7 +159,7 @@
 PyObject *
 PyFloat_FromString(PyObject *v)
 {
-	const char *s, *last, *end;
+	const char *s, *last, *end, *sp;
 	double x;
 	char buffer[256]; /* for errors */
 	char *s_buffer = NULL;
@@ -99,6 +191,7 @@
 		PyErr_SetString(PyExc_ValueError, "empty string for float()");
 		goto error;
 	}
+	sp = s;
 	/* We don't care about overflow or underflow.  If the platform supports
 	 * them, infinities and signed zeroes (on underflow) are fine.
 	 * However, strtod can return 0 for denormalized numbers, where atof
@@ -114,7 +207,26 @@
 	   byte at the end of the string, when the input is inf(inity). */
 	if (end > last)
 		end = last;
+	/* Check for inf and nan. This is done late because it rarely happens. */
 	if (end == s) {
+		char *p = (char*)sp;
+		int sign = 1;
+
+		if (*p == '-') {
+			sign = -1;
+			p++;
+		}
+		if (*p == '+') {
+			p++;
+		}
+		if (PyOS_strnicmp(p, "inf", 4) == 0) {
+			return PyFloat_FromDouble(sign * Py_HUGE_VAL);
+		}
+#ifdef Py_NAN
+		if(PyOS_strnicmp(p, "nan", 4) == 0) {
+			return PyFloat_FromDouble(Py_NAN);
+		}
+#endif
 		PyOS_snprintf(buffer, sizeof(buffer),
 			      "invalid literal for float(): %.200s", s);
 		PyErr_SetString(PyExc_ValueError, buffer);
@@ -154,11 +266,11 @@
 float_dealloc(PyFloatObject *op)
 {
 	if (PyFloat_CheckExact(op)) {
-		Py_Type(op) = (struct _typeobject *)free_list;
+		Py_TYPE(op) = (struct _typeobject *)free_list;
 		free_list = op;
 	}
 	else
-		Py_Type(op)->tp_free((PyObject *)op);
+		Py_TYPE(op)->tp_free((PyObject *)op);
 }
 
 double
@@ -176,7 +288,7 @@
 		return -1;
 	}
 
-	if ((nb = Py_Type(op)->tp_as_number) == NULL || nb->nb_float == NULL) {
+	if ((nb = Py_TYPE(op)->tp_as_number) == NULL || nb->nb_float == NULL) {
 		PyErr_SetString(PyExc_TypeError, "a float is required");
 		return -1;
 	}
@@ -203,7 +315,9 @@
 {
 	register char *cp;
 	char format[32];
-	/* Subroutine for float_repr, float_str, and others.
+	int i;
+
+	/* Subroutine for float_repr, float_str and float_print.
 	   We want float numbers to be recognizable as such,
 	   i.e., they should contain a decimal point or an exponent.
 	   However, %g may print the number as an integer;
@@ -224,7 +338,33 @@
 		*cp++ = '.';
 		*cp++ = '0';
 		*cp++ = '\0';
+		return;
 	}
+	/* Checking the next three chars should be more than enough to
+	 * detect inf or nan, even on Windows. We check for inf or nan
+	 * at last because they are rare cases.
+	 */
+	for (i=0; *cp != '\0' && i<3; cp++, i++) {
+		if (isdigit(Py_CHARMASK(*cp)) || *cp == '.')
+			continue;
+		/* found something that is neither a digit nor point
+		 * it might be a NaN or INF
+		 */
+#ifdef Py_NAN
+		if (Py_IS_NAN(ob_fval)) {
+			strcpy(buf, "nan");
+		}
+                else
+#endif
+		if (Py_IS_INFINITY(ob_fval)) {
+			cp = buf;
+			if (*cp == '-')
+				cp++;
+			strcpy(cp, "inf");
+		}
+		break;
+	}
+
 }
 
 static void
@@ -234,6 +374,110 @@
 	format_double(buf, buflen, PyFloat_AS_DOUBLE(v), precision);
 }
 
+#ifdef Py_BROKEN_REPR
+/* The following function is based on Tcl_PrintDouble,
+ * from tclUtil.c.
+ */
+
+#define is_infinite(d)	( (d) > DBL_MAX || (d) < -DBL_MAX )
+#define is_nan(d)		((d) != (d))
+
+static void
+format_double_repr(char *dst, double value)
+{
+    char *p, c;
+    int exp;
+    int signum;
+    char buffer[30];
+
+	/*
+	 * Handle NaN.
+	 */
+
+	if (is_nan(value)) {
+	    strcpy(dst, "nan");
+	    return;
+	}
+
+	/*
+	 * Handle infinities.
+	 */
+
+	if (is_infinite(value)) {
+	    if (value < 0) {
+		strcpy(dst, "-inf");
+	    } else {
+		strcpy(dst, "inf");
+	    }
+	    return;
+	}
+
+	/*
+	 * Ordinary (normal and denormal) values.
+	 */
+
+	exp = _PyFloat_Digits(buffer, value, &signum)+1;
+	if (signum) {
+	    *dst++ = '-';
+	}
+	p = buffer;
+	if (exp < -3 || exp > 17) {
+	    /*
+	     * E format for numbers < 1e-3 or >= 1e17.
+	     */
+
+	    *dst++ = *p++;
+	    c = *p;
+	    if (c != '\0') {
+		*dst++ = '.';
+		while (c != '\0') {
+		    *dst++ = c;
+		    c = *++p;
+		}
+	    }
+	    sprintf(dst, "e%+d", exp-1);
+	} else {
+	    /*
+	     * F format for others.
+	     */
+
+	    if (exp <= 0) {
+		*dst++ = '0';
+	    }
+	    c = *p;
+	    while (exp-- > 0) {
+		if (c != '\0') {
+		    *dst++ = c;
+		    c = *++p;
+		} else {
+		    *dst++ = '0';
+		}
+	    }
+	    *dst++ = '.';
+	    if (c == '\0') {
+		*dst++ = '0';
+	    } else {
+		while (++exp < 0) {
+		    *dst++ = '0';
+		}
+		while (c != '\0') {
+		    *dst++ = c;
+		    c = *++p;
+		}
+	    }
+	    *dst++ = '\0';
+	}
+}
+
+static void
+format_float_repr(char *buf, PyFloatObject *v)
+{
+	assert(PyFloat_Check(v));
+	format_double_repr(buf, PyFloat_AS_DOUBLE(v));
+}
+
+#endif /* Py_BROKEN_REPR */
+
 /* Macro and helper that convert PyObject obj to a C double and store
    the value in dbl.  If conversion to double raises an exception, obj is
    set to NULL, and the function invoking this macro returns NULL.  If
@@ -286,8 +530,14 @@
 static PyObject *
 float_repr(PyFloatObject *v)
 {
+#ifdef Py_BROKEN_REPR
+	char buf[30];
+	format_float_repr(buf, v);
+#else
 	char buf[100];
 	format_float(buf, sizeof(buf), v, PREC_REPR);
+#endif
+
 	return PyUnicode_FromString(buf);
 }
 
@@ -434,7 +684,7 @@
 				 */
 				PyObject *temp;
 
-				one = PyInt_FromLong(1);
+				one = PyLong_FromLong(1);
 				if (one == NULL)
 					goto Error;
 
@@ -761,7 +1011,7 @@
 	 */
 	if (LONG_MIN < wholepart && wholepart < LONG_MAX) {
 		const long aslong = (long)wholepart;
-		return PyInt_FromLong(aslong);
+		return PyLong_FromLong(aslong);
 	}
 	return PyLong_FromDouble(wholepart);
 }
@@ -815,6 +1065,104 @@
 	return v;
 }
 
+static PyObject *
+float_as_integer_ratio(PyObject *v, PyObject *unused)
+{
+	double self;
+	double float_part;
+	int exponent;
+	int i;
+
+	PyObject *prev;
+	PyObject *py_exponent = NULL;
+	PyObject *numerator = NULL;
+	PyObject *denominator = NULL;
+	PyObject *result_pair = NULL;
+	PyNumberMethods *long_methods = PyLong_Type.tp_as_number;
+
+#define INPLACE_UPDATE(obj, call) \
+	prev = obj; \
+	obj = call; \
+	Py_DECREF(prev); \
+
+	CONVERT_TO_DOUBLE(v, self);
+
+	if (Py_IS_INFINITY(self)) {
+	  PyErr_SetString(PyExc_OverflowError,
+			  "Cannot pass infinity to float.as_integer_ratio.");
+	  return NULL;
+	}
+#ifdef Py_NAN
+	if (Py_IS_NAN(self)) {
+	  PyErr_SetString(PyExc_ValueError,
+			  "Cannot pass nan to float.as_integer_ratio.");
+	  return NULL;
+	}
+#endif
+
+	PyFPE_START_PROTECT("as_integer_ratio", goto error);
+	float_part = frexp(self, &exponent);  	/* self == float_part * 2**exponent exactly */
+	PyFPE_END_PROTECT(float_part);
+	
+	for (i=0; i<300 && float_part != floor(float_part) ; i++) {
+		float_part *= 2.0;
+		exponent--;
+	}	
+	/* self == float_part * 2**exponent exactly and float_part is integral.
+           If FLT_RADIX != 2, the 300 steps may leave a tiny fractional part
+           to be truncated by PyLong_FromDouble(). */
+
+	numerator = PyLong_FromDouble(float_part);
+	if (numerator == NULL) goto error;
+
+	/* fold in 2**exponent */
+	denominator = PyLong_FromLong(1);
+	py_exponent = PyLong_FromLong(labs((long)exponent));
+	if (py_exponent == NULL) goto error;
+	INPLACE_UPDATE(py_exponent,
+		       long_methods->nb_lshift(denominator, py_exponent));
+	if (py_exponent == NULL) goto error;
+	if (exponent > 0) {
+		INPLACE_UPDATE(numerator,
+			       long_methods->nb_multiply(numerator, py_exponent));
+		if (numerator == NULL) goto error;
+	}
+	else {
+		Py_DECREF(denominator);
+		denominator = py_exponent;
+		py_exponent = NULL;
+	}
+
+	/* Returns ints instead of longs where possible */
+	INPLACE_UPDATE(numerator, PyNumber_Int(numerator));
+	if (numerator == NULL) goto error;
+	INPLACE_UPDATE(denominator, PyNumber_Int(denominator));
+	if (denominator == NULL) goto error;
+
+	result_pair = PyTuple_Pack(2, numerator, denominator);
+
+#undef INPLACE_UPDATE
+error:
+	Py_XDECREF(py_exponent);
+	Py_XDECREF(denominator);
+	Py_XDECREF(numerator);
+	return result_pair;
+}
+
+PyDoc_STRVAR(float_as_integer_ratio_doc,
+"float.as_integer_ratio() -> (int, int)\n"
+"\n"
+"Returns a pair of integers, whose ratio is exactly equal to the original\n"
+"float and with a positive denominator.\n"
+"Raises OverflowError on infinities and a ValueError on nans.\n"
+"\n"
+">>> (10.0).as_integer_ratio()\n"
+"(10, 1)\n"
+">>> (0.0).as_integer_ratio()\n"
+"(0, 1)\n"
+">>> (-.25).as_integer_ratio()\n"
+"(-1, 4)");
+
 
 static PyObject *
 float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
@@ -883,7 +1231,7 @@
 	if (!PyUnicode_Check(arg)) {
 		PyErr_Format(PyExc_TypeError,
 	     "__getformat__() argument must be string, not %.500s",
-			     Py_Type(arg)->tp_name);
+			     Py_TYPE(arg)->tp_name);
 		return NULL;
 	}
 	s = PyUnicode_AsString(arg);
@@ -1023,6 +1371,8 @@
 	{"__round__",	(PyCFunction)float_round, METH_VARARGS,
          "Returns the Integral closest to x, rounding half toward even.\n"
          "When an argument is passed, works like built-in round(x, ndigits)."},
+	{"as_integer_ratio", (PyCFunction)float_as_integer_ratio, METH_NOARGS,
+	 float_as_integer_ratio_doc},
 	{"__getnewargs__",	(PyCFunction)float_getnewargs,	METH_NOARGS},
 	{"__getformat__",	(PyCFunction)float_getformat,	
 	 METH_O|METH_CLASS,		float_getformat_doc},
@@ -1179,20 +1529,26 @@
 
 	double_format = detected_double_format;
 	float_format = detected_float_format;
+
+#ifdef Py_BROKEN_REPR	
+	/* Initialize floating point repr */
+	_PyFloat_DigitsInit();
+#endif
+	/* Init float info */
+	if (FloatInfoType.tp_name == 0)
+		PyStructSequence_InitType(&FloatInfoType, &floatinfo_desc);
 }
 
 void
-PyFloat_Fini(void)
+PyFloat_CompactFreeList(size_t *pbc, size_t *pbf, size_t *bsum)
 {
 	PyFloatObject *p;
 	PyFloatBlock *list, *next;
 	unsigned i;
-	int bc, bf;	/* block count, number of freed blocks */
-	int frem, fsum;	/* remaining unfreed floats per block, total */
+	size_t bc = 0, bf = 0;	/* block count, number of freed blocks */
+	size_t fsum = 0;	/* total unfreed ints */
+	int frem;		/* remaining unfreed ints per block */
 
-	bc = 0;
-	bf = 0;
-	fsum = 0;
 	list = block_list;
 	block_list = NULL;
 	free_list = NULL;
@@ -1202,7 +1558,7 @@
 		for (i = 0, p = &list->objects[0];
 		     i < N_FLOATOBJECTS;
 		     i++, p++) {
-			if (PyFloat_CheckExact(p) && Py_Refcnt(p) != 0)
+			if (PyFloat_CheckExact(p) && Py_REFCNT(p) != 0)
 				frem++;
 		}
 		next = list->next;
@@ -1213,8 +1569,8 @@
 			     i < N_FLOATOBJECTS;
 			     i++, p++) {
 				if (!PyFloat_CheckExact(p) ||
-				    Py_Refcnt(p) == 0) {
-					Py_Type(p) = (struct _typeobject *)
+				    Py_REFCNT(p) == 0) {
+					Py_TYPE(p) = (struct _typeobject *)
 						free_list;
 					free_list = p;
 				}
@@ -1227,6 +1583,22 @@
 		fsum += frem;
 		list = next;
 	}
+	*pbc = bc;
+	*pbf = bf;
+	*bsum = fsum;
+}
+
+void
+PyFloat_Fini(void)
+{
+	PyFloatObject *p;
+	PyFloatBlock *list;
+	unsigned i;
+	size_t bc, bf;	/* block count, number of freed blocks */
+	size_t fsum;	/* total unfreed floats per block */
+
+	PyFloat_CompactFreeList(&bc, &bf, &fsum);
+
 	if (!Py_VerboseFlag)
 		return;
 	fprintf(stderr, "# cleanup floats");
@@ -1235,7 +1607,9 @@
 	}
 	else {
 		fprintf(stderr,
-			": %d unfreed float%s in %d out of %d block%s\n",
+			": %" PY_FORMAT_SIZE_T "d unfreed floats%s in %"
+			PY_FORMAT_SIZE_T "d out of %"
+			PY_FORMAT_SIZE_T "d block%s\n",
 			fsum, fsum == 1 ? "" : "s",
 			bc - bf, bc, bc == 1 ? "" : "s");
 	}
@@ -1246,7 +1620,7 @@
 			     i < N_FLOATOBJECTS;
 			     i++, p++) {
 				if (PyFloat_CheckExact(p) &&
-				    Py_Refcnt(p) != 0) {
+				    Py_REFCNT(p) != 0) {
 					char buf[100];
 					format_float(buf, sizeof(buf), p, PREC_STR);
 					/* XXX(twouters) cast refcount to
@@ -1255,7 +1629,7 @@
 					 */
 					fprintf(stderr,
 			     "#   <float at %p, refcnt=%ld, val=%s>\n",
-						p, (long)Py_Refcnt(p), buf);
+						p, (long)Py_REFCNT(p), buf);
 				}
 			}
 			list = list->next;
@@ -1265,9 +1639,6 @@
 
 /*----------------------------------------------------------------------------
  * _PyFloat_{Pack,Unpack}{4,8}.  See floatobject.h.
- *
- * TODO:  On platforms that use the standard IEEE-754 single and double
- * formats natively, these routines could simply copy the bytes.
  */
 int
 _PyFloat_Pack4(double x, unsigned char *p, int le)
@@ -1347,28 +1718,31 @@
 		/* Done */
 		return 0;
 
-	  Overflow:
-		PyErr_SetString(PyExc_OverflowError,
-				"float too large to pack with f format");
-		return -1;
 	}
 	else {
 		float y = (float)x;
 		const char *s = (char*)&y;
 		int i, incr = 1;
 
+		if (Py_IS_INFINITY(y) && !Py_IS_INFINITY(x))
+			goto Overflow;
+
 		if ((float_format == ieee_little_endian_format && !le)
 		    || (float_format == ieee_big_endian_format && le)) {
 			p += 3;
 			incr = -1;
 		}
-		
+
 		for (i = 0; i < 4; i++) {
 			*p = *s++;
 			p += incr;
 		}
 		return 0;
 	}
+  Overflow:
+	PyErr_SetString(PyExc_OverflowError,
+			"float too large to pack with f format");
+	return -1;
 }
 
 int

Modified: python/branches/py3k-importlib/Objects/frameobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/frameobject.c	(original)
+++ python/branches/py3k-importlib/Objects/frameobject.c	Thu Mar 27 00:48:05 2008
@@ -44,7 +44,7 @@
 	else
 		lineno = PyCode_Addr2Line(f->f_code, f->f_lasti);
 
-	return PyInt_FromLong(lineno);
+	return PyLong_FromLong(lineno);
 }
 
 /* Setter for f_lineno - you can set f_lineno from within a trace function in
@@ -66,6 +66,8 @@
 frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
 {
 	int new_lineno = 0;		/* The new value of f_lineno */
+	long l_new_lineno;
+	int overflow;
 	int new_lasti = 0;		/* The new value of f_lasti */
 	int new_iblock = 0;		/* The new value of f_iblock */
 	unsigned char *code = NULL;	/* The bytecode for the frame... */
@@ -88,7 +90,7 @@
 	unsigned char setup_op = 0;	/* (ditto) */
 
 	/* f_lineno must be an integer. */
-	if (!PyInt_CheckExact(p_new_lineno)) {
+	if (!PyLong_CheckExact(p_new_lineno)) {
 		PyErr_SetString(PyExc_ValueError,
 				"lineno must be an integer");
 		return -1;
@@ -104,7 +106,19 @@
 	}
 
 	/* Fail if the line comes before the start of the code block. */
-	new_lineno = (int) PyInt_AsLong(p_new_lineno);
+	l_new_lineno = PyLong_AsLongAndOverflow(p_new_lineno, &overflow);
+	if (overflow
+#if SIZEOF_LONG > SIZEOF_INT
+	    || l_new_lineno > INT_MAX
+	    || l_new_lineno < INT_MIN
+#endif
+	   ) {
+		PyErr_SetString(PyExc_ValueError,
+				"lineno out of range");
+		return -1;
+	}
+	new_lineno = (int)l_new_lineno;
+	    
 	if (new_lineno < f->f_code->co_firstlineno) {
 		PyErr_Format(PyExc_ValueError,
 			     "line %d comes before the current code block",
@@ -387,14 +401,15 @@
    call depth of more than 20 or 30 is probably already exceptional
    unless the program contains run-away recursion.  I hope.
 
-   Later, MAXFREELIST was added to bound the # of frames saved on
+   Later, PyFrame_MAXFREELIST was added to bound the # of frames saved on
    free_list.  Else programs creating lots of cyclic trash involving
    frames could provoke free_list into growing without bound.
 */
 
 static PyFrameObject *free_list = NULL;
 static int numfree = 0;		/* number of frames currently in free_list */
-#define MAXFREELIST 200		/* max value for numfree */
+/* max value for numfree */
+#define PyFrame_MAXFREELIST 200	
 
 static void
 frame_dealloc(PyFrameObject *f)
@@ -427,7 +442,7 @@
 	co = f->f_code;
 	if (co->co_zombieframe == NULL)
 		co->co_zombieframe = f;
-	else if (numfree < MAXFREELIST) {
+	else if (numfree < PyFrame_MAXFREELIST) {
 		++numfree;
 		f->f_back = free_list;
 		free_list = f;
@@ -616,7 +631,7 @@
 		    --numfree;
 		    f = free_list;
 		    free_list = free_list->f_back;
-		    if (Py_Size(f) < extras) {
+		    if (Py_SIZE(f) < extras) {
 			    f = PyObject_GC_Resize(PyFrameObject, f, extras);
 			    if (f == NULL) {
 				    Py_DECREF(builtins);
@@ -721,7 +736,7 @@
 	for (j = nmap; --j >= 0; ) {
 		PyObject *key = PyTuple_GET_ITEM(map, j);
 		PyObject *value = values[j];
-		assert(PyString_Check(key)/*XXX this should go*/ || PyUnicode_Check(key));
+		assert(PyUnicode_Check(key));
 		if (deref) {
 			assert(PyCell_Check(value));
 			value = PyCell_GET(value);
@@ -882,10 +897,11 @@
 }
 
 /* Clear out the free list */
-
-void
-PyFrame_Fini(void)
+int
+PyFrame_ClearFreeList(void)
 {
+	int freelist_size = numfree;
+	
 	while (free_list != NULL) {
 		PyFrameObject *f = free_list;
 		free_list = free_list->f_back;
@@ -893,6 +909,13 @@
 		--numfree;
 	}
 	assert(numfree == 0);
+	return freelist_size;
+}
+
+void
+PyFrame_Fini(void)
+{
+	(void)PyFrame_ClearFreeList();
 	Py_XDECREF(builtin_object);
 	builtin_object = NULL;
 }

Modified: python/branches/py3k-importlib/Objects/funcobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/funcobject.c	(original)
+++ python/branches/py3k-importlib/Objects/funcobject.c	Thu Mar 27 00:48:05 2008
@@ -227,10 +227,10 @@
 static PyMemberDef func_memberlist[] = {
         {"__closure__",   T_OBJECT,     OFF(func_closure),
 	 RESTRICTED|READONLY},
-        {"__doc__",       T_OBJECT,     OFF(func_doc), WRITE_RESTRICTED},
+        {"__doc__",       T_OBJECT,     OFF(func_doc), PY_WRITE_RESTRICTED},
         {"__globals__",   T_OBJECT,     OFF(func_globals),
 	 RESTRICTED|READONLY},
-        {"__module__",    T_OBJECT,     OFF(func_module), WRITE_RESTRICTED},
+        {"__module__",    T_OBJECT,     OFF(func_module), PY_WRITE_RESTRICTED},
         {NULL}  /* Sentinel */
 };
 
@@ -643,9 +643,11 @@
 static PyObject *
 func_descr_get(PyObject *func, PyObject *obj, PyObject *type)
 {
-	if (obj == Py_None)
-		obj = NULL;
-	return PyMethod_New(func, obj, type);
+	if (obj == Py_None || obj == NULL) {
+		Py_INCREF(func);
+		return func;
+	}
+	return PyMethod_New(func, obj);
 }
 
 PyTypeObject PyFunction_Type = {
@@ -719,7 +721,7 @@
 {
 	_PyObject_GC_UNTRACK((PyObject *)cm);
 	Py_XDECREF(cm->cm_callable);
-	Py_Type(cm)->tp_free((PyObject *)cm);
+	Py_TYPE(cm)->tp_free((PyObject *)cm);
 }
 
 static int
@@ -748,9 +750,8 @@
 		return NULL;
 	}
 	if (type == NULL)
-		type = (PyObject *)(Py_Type(obj));
- 	return PyMethod_New(cm->cm_callable,
-			    type, (PyObject *)(Py_Type(type)));
+		type = (PyObject *)(Py_TYPE(obj));
+ 	return PyMethod_New(cm->cm_callable, type);
 }
 
 static int
@@ -876,7 +877,7 @@
 {
 	_PyObject_GC_UNTRACK((PyObject *)sm);
 	Py_XDECREF(sm->sm_callable);
-	Py_Type(sm)->tp_free((PyObject *)sm);
+	Py_TYPE(sm)->tp_free((PyObject *)sm);
 }
 
 static int

Modified: python/branches/py3k-importlib/Objects/genobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/genobject.c	(original)
+++ python/branches/py3k-importlib/Objects/genobject.c	Thu Mar 27 00:48:05 2008
@@ -11,6 +11,7 @@
 gen_traverse(PyGenObject *gen, visitproc visit, void *arg)
 {
 	Py_VISIT((PyObject *)gen->gi_frame);
+	Py_VISIT(gen->gi_code);
 	return 0;
 }
 
@@ -28,13 +29,14 @@
 
 	if (gen->gi_frame != NULL && gen->gi_frame->f_stacktop != NULL) {
 		/* Generator is paused, so we need to close */
-		Py_Type(gen)->tp_del(self);
+		Py_TYPE(gen)->tp_del(self);
 		if (self->ob_refcnt > 0)
 			return;		/* resurrected.  :( */
 	}
 
 	_PyObject_GC_UNTRACK(self);
 	Py_CLEAR(gen->gi_frame);
+	Py_CLEAR(gen->gi_code);
 	PyObject_GC_Del(gen);
 }
 
@@ -283,6 +285,7 @@
 static PyMemberDef gen_memberlist[] = {
 	{"gi_frame",	T_OBJECT, offsetof(PyGenObject, gi_frame),	READONLY},
 	{"gi_running",	T_INT,    offsetof(PyGenObject, gi_running),	READONLY},
+	{"gi_code",     T_OBJECT, offsetof(PyGenObject, gi_code),  READONLY},
 	{NULL}	/* Sentinel */
 };
 
@@ -353,6 +356,8 @@
 		return NULL;
 	}
 	gen->gi_frame = f;
+	Py_INCREF(f->f_code);
+	gen->gi_code = (PyObject *)(f->f_code);
 	gen->gi_running = 0;
 	gen->gi_weakreflist = NULL;
 	_PyObject_GC_TRACK(gen);

Modified: python/branches/py3k-importlib/Objects/iterobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/iterobject.c	(original)
+++ python/branches/py3k-importlib/Objects/iterobject.c	Thu Mar 27 00:48:05 2008
@@ -81,9 +81,9 @@
 			return NULL;
 		len = seqsize - it->it_index;
 		if (len >= 0)
-			return PyInt_FromSsize_t(len);
+			return PyLong_FromSsize_t(len);
 	}
-	return PyInt_FromLong(0);
+	return PyLong_FromLong(0);
 }
 
 PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
@@ -199,7 +199,7 @@
 
 PyTypeObject PyCallIter_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"callable-iterator",			/* tp_name */
+	"callable_iterator",			/* tp_name */
 	sizeof(calliterobject),			/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */
@@ -230,172 +230,3 @@
 };
 
 
-/*********************** Zip Iterator **************************/
-/* Largely copied from itertools.c by Brian Holmes */
-
-typedef struct zipiterobject_t {
-	PyObject_HEAD
-	PyTupleObject *it_tuple;  /* Set to NULL when iterator is exhausted */
-        Py_ssize_t resultsize;	
-	PyTupleObject *result;	/* Reusable tuple for optimization */
-} zipiterobject;
-
-static PyTypeObject PyZipIter_Type; /* Forward */
-
-PyObject *
-_PyZip_CreateIter(PyObject* args)
-{
-	Py_ssize_t i;
-        Py_ssize_t tuplesize;
-	PyObject* ziptuple;
-	PyObject* result;
-	struct zipiterobject_t* zipiter;
-        
-        assert(PyTuple_Check(args));
-
-	if (Py_Type(&PyZipIter_Type) == NULL) {
-		if (PyType_Ready(&PyZipIter_Type) < 0)
-			return NULL;
-	}
-
-	tuplesize = PySequence_Length((PyObject*) args);
-
-	ziptuple = PyTuple_New(tuplesize);
-	if (ziptuple == NULL)
-		return NULL;
-
-	for (i = 0; i < tuplesize; i++) {
-		PyObject *o = PyTuple_GET_ITEM(args, i);
-		PyObject *it = PyObject_GetIter(o);
-		if (it == NULL) {
-			/* XXX Should we do this?
-			if (PyErr_ExceptionMatches(PyExc_TypeError))
-				PyErr_Format(PyExc_TypeError, 
-				  "zip argument #%zd must support iteration",
-					I+1);
-			*/
-			Py_DECREF(ziptuple);
-			return NULL;
-		}
-		PyTuple_SET_ITEM(ziptuple, i, it);
-	}
-
-        /* create a reusable result holder */
-        result = PyTuple_New(tuplesize);
-        if (result == NULL) {
-                Py_DECREF(ziptuple);
-                return NULL;
-        }
-        for (i = 0; i < tuplesize; i++) {
-                Py_INCREF(Py_None);
-                PyTuple_SET_ITEM(result, i, Py_None);
-        }
-	
-	zipiter = PyObject_GC_New(zipiterobject, &PyZipIter_Type);
-	if (zipiter == NULL) {
-		Py_DECREF(ziptuple);
-		Py_DECREF(result);
-		return NULL;
-	}
-
-	zipiter->result = (PyTupleObject*) result;
-        zipiter->resultsize = tuplesize;
-	zipiter->it_tuple = (PyTupleObject *) ziptuple;
-	_PyObject_GC_TRACK(zipiter);
-	return (PyObject *)zipiter;
-}
-
-static void
-zipiter_dealloc(zipiterobject *it)
-{
-	_PyObject_GC_UNTRACK(it);
-	Py_XDECREF(it->it_tuple);
-	Py_XDECREF(it->result);
-	PyObject_GC_Del(it);
-}
-
-static int
-zipiter_traverse(zipiterobject *it, visitproc visit, void *arg)
-{
-	Py_VISIT(it->it_tuple);
-	Py_VISIT(it->result);
-	return 0;
-}
-
-static PyObject *
-zipiter_next(zipiterobject *zit)
-{
-        Py_ssize_t i;
-        Py_ssize_t tuplesize = zit->resultsize;
-        PyObject *result = (PyObject*) zit->result;
-        PyObject *olditem;
-
-        if (tuplesize == 0)
-                return NULL;
-
-        if (result->ob_refcnt == 1) {
-		Py_INCREF(result);
-		for (i = 0; i < tuplesize; i++) {
-			PyObject *it = PyTuple_GET_ITEM(zit->it_tuple, i);
-			PyObject *item;
-			assert(PyIter_Check(it));
-			item = (*it->ob_type->tp_iternext)(it);
-			if (item == NULL) {
-				Py_DECREF(result);
-				return NULL;
-			}
-			olditem = PyTuple_GET_ITEM(result, i);
-			PyTuple_SET_ITEM(result, i, item);
-			Py_DECREF(olditem);
-		}
-	} else {
-		result = PyTuple_New(tuplesize);
-		if (result == NULL)
-			return NULL;
-		for (i = 0; i < tuplesize; i++) {
-			PyObject *it = PyTuple_GET_ITEM(zit->it_tuple, i);
-			PyObject *item;
-			assert(PyIter_Check(it));
-			item = (*it->ob_type->tp_iternext)(it);
-			if (item == NULL) {
-				Py_DECREF(result);
-				return NULL;
-			}
-			PyTuple_SET_ITEM(result, i, item);
-		}
-	}
-	return result;
-}
-
-static PyTypeObject PyZipIter_Type = {
-	PyVarObject_HEAD_INIT(0, 0)
-	"zipiterator",				/* tp_name */
-	sizeof(zipiterobject),			/* tp_basicsize */
-	0,					/* tp_itemsize */
-	/* methods */
-	(destructor)zipiter_dealloc,		/* tp_dealloc */
-	0,					/* tp_print */
-	0,					/* tp_getattr */
-	0,					/* tp_setattr */
-	0,					/* tp_compare */
-	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_HAVE_GC,/* tp_flags */
-	0,					/* tp_doc */
-	(traverseproc)zipiter_traverse,		/* tp_traverse */
-	0,					/* tp_clear */
-	0,					/* tp_richcompare */
-	0,					/* tp_weakzipoffset */
-	PyObject_SelfIter,			/* tp_iter */
-	(iternextfunc)zipiter_next,		/* tp_iternext */
-	0,					/* tp_methods */
-	0,					/* tp_members */
-};

Modified: python/branches/py3k-importlib/Objects/listobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/listobject.c	(original)
+++ python/branches/py3k-importlib/Objects/listobject.c	Thu Mar 27 00:48:05 2008
@@ -34,7 +34,7 @@
 	*/
 	if (allocated >= newsize && newsize >= (allocated >> 1)) {
 		assert(self->ob_item != NULL || newsize == 0);
-		Py_Size(self) = newsize;
+		Py_SIZE(self) = newsize;
 		return 0;
 	}
 
@@ -58,24 +58,43 @@
 		return -1;
 	}
 	self->ob_item = items;
-	Py_Size(self) = newsize;
+	Py_SIZE(self) = newsize;
 	self->allocated = new_allocated;
 	return 0;
 }
 
+/* Debug statistic to compare allocations with reuse through the free list */
+#undef SHOW_ALLOC_COUNT
+#ifdef SHOW_ALLOC_COUNT
+static size_t count_alloc = 0;
+static size_t count_reuse = 0;
+
+static void
+show_alloc(void)
+{
+	fprintf(stderr, "List allocations: %" PY_FORMAT_SIZE_T "d\n",
+		count_alloc);
+	fprintf(stderr, "List reuse through freelist: %" PY_FORMAT_SIZE_T
+		"d\n", count_reuse);
+	fprintf(stderr, "%.2f%% reuse rate\n\n",
+		(100.0*count_reuse/(count_alloc+count_reuse)));
+}
+#endif
+
 /* Empty list reuse scheme to save calls to malloc and free */
-#define MAXFREELISTS 80
-static PyListObject *free_lists[MAXFREELISTS];
-static int num_free_lists = 0;
+#ifndef PyList_MAXFREELIST
+#define PyList_MAXFREELIST 80
+#endif
+static PyListObject *free_list[PyList_MAXFREELIST];
+static int numfree = 0;
 
 void
 PyList_Fini(void)
 {
 	PyListObject *op;
 
-	while (num_free_lists) {
-		num_free_lists--;
-		op = free_lists[num_free_lists]; 
+	while (numfree) {
+		op = free_list[--numfree];
 		assert(PyList_CheckExact(op));
 		PyObject_GC_Del(op);
 	}
@@ -86,6 +105,13 @@
 {
 	PyListObject *op;
 	size_t nbytes;
+#ifdef SHOW_ALLOC_COUNT
+	static int initialized = 0;
+	if (!initialized) {
+		Py_AtExit(show_alloc);
+		initialized = 1;
+	}
+#endif
 
 	if (size < 0) {
 		PyErr_BadInternalCall();
@@ -95,14 +121,20 @@
 	/* Check for overflow */
 	if (nbytes / sizeof(PyObject *) != (size_t)size)
 		return PyErr_NoMemory();
-	if (num_free_lists) {
-		num_free_lists--;
-		op = free_lists[num_free_lists];
+	if (numfree) {
+		numfree--;
+		op = free_list[numfree];
 		_Py_NewReference((PyObject *)op);
+#ifdef SHOW_ALLOC_COUNT
+		count_reuse++;
+#endif
 	} else {
 		op = PyObject_GC_New(PyListObject, &PyList_Type);
 		if (op == NULL)
 			return NULL;
+#ifdef SHOW_ALLOC_COUNT
+		count_alloc++;
+#endif
 	}
 	if (size <= 0)
 		op->ob_item = NULL;
@@ -114,7 +146,7 @@
 		}
 		memset(op->ob_item, 0, nbytes);
 	}
-	Py_Size(op) = size;
+	Py_SIZE(op) = size;
 	op->allocated = size;
 	_PyObject_GC_TRACK(op);
 	return (PyObject *) op;
@@ -128,7 +160,7 @@
 		return -1;
 	}
 	else
-		return Py_Size(op);
+		return Py_SIZE(op);
 }
 
 static PyObject *indexerr = NULL;
@@ -140,7 +172,7 @@
 		PyErr_BadInternalCall();
 		return NULL;
 	}
-	if (i < 0 || i >= Py_Size(op)) {
+	if (i < 0 || i >= Py_SIZE(op)) {
 		if (indexerr == NULL)
 			indexerr = PyUnicode_FromString(
 				"list index out of range");
@@ -161,7 +193,7 @@
 		PyErr_BadInternalCall();
 		return -1;
 	}
-	if (i < 0 || i >= Py_Size(op)) {
+	if (i < 0 || i >= Py_SIZE(op)) {
 		Py_XDECREF(newitem);
 		PyErr_SetString(PyExc_IndexError,
 				"list assignment index out of range");
@@ -177,7 +209,7 @@
 static int
 ins1(PyListObject *self, Py_ssize_t where, PyObject *v)
 {
-	Py_ssize_t i, n = Py_Size(self);
+	Py_ssize_t i, n = Py_SIZE(self);
 	PyObject **items;
 	if (v == NULL) {
 		PyErr_BadInternalCall();
@@ -259,16 +291,16 @@
 		   There's a simple test case where somehow this reduces
 		   thrashing when a *very* large list is created and
 		   immediately deleted. */
-		i = Py_Size(op);
+		i = Py_SIZE(op);
 		while (--i >= 0) {
 			Py_XDECREF(op->ob_item[i]);
 		}
 		PyMem_FREE(op->ob_item);
 	}
-	if (num_free_lists < MAXFREELISTS && PyList_CheckExact(op))
-		free_lists[num_free_lists++] = op;
+	if (numfree < PyList_MAXFREELIST && PyList_CheckExact(op))
+		free_list[numfree++] = op;
 	else
-		Py_Type(op)->tp_free((PyObject *)op);
+		Py_TYPE(op)->tp_free((PyObject *)op);
 	Py_TRASHCAN_SAFE_END(op)
 }
 
@@ -284,7 +316,7 @@
 		return i > 0 ? PyUnicode_FromString("[...]") : NULL;
 	}
 
-	if (Py_Size(v) == 0) {
+	if (Py_SIZE(v) == 0) {
 		result = PyUnicode_FromString("[]");
 		goto Done;
 	}
@@ -295,7 +327,7 @@
 
 	/* Do repr() on each element.  Note that this may mutate the list,
 	   so must refetch the list size on each iteration. */
-	for (i = 0; i < Py_Size(v); ++i) {
+	for (i = 0; i < Py_SIZE(v); ++i) {
 		int status;
 		if (Py_EnterRecursiveCall(" while getting the repr of a list"))
 			goto Done;
@@ -345,7 +377,7 @@
 static Py_ssize_t
 list_length(PyListObject *a)
 {
-	return Py_Size(a);
+	return Py_SIZE(a);
 }
 
 static int
@@ -354,7 +386,7 @@
 	Py_ssize_t i;
 	int cmp;
 
-	for (i = 0, cmp = 0 ; cmp == 0 && i < Py_Size(a); ++i)
+	for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i)
 		cmp = PyObject_RichCompareBool(el, PyList_GET_ITEM(a, i),
 						   Py_EQ);
 	return cmp;
@@ -363,7 +395,7 @@
 static PyObject *
 list_item(PyListObject *a, Py_ssize_t i)
 {
-	if (i < 0 || i >= Py_Size(a)) {
+	if (i < 0 || i >= Py_SIZE(a)) {
 		if (indexerr == NULL)
 			indexerr = PyUnicode_FromString(
 				"list index out of range");
@@ -382,12 +414,12 @@
 	Py_ssize_t i, len;
 	if (ilow < 0)
 		ilow = 0;
-	else if (ilow > Py_Size(a))
-		ilow = Py_Size(a);
+	else if (ilow > Py_SIZE(a))
+		ilow = Py_SIZE(a);
 	if (ihigh < ilow)
 		ihigh = ilow;
-	else if (ihigh > Py_Size(a))
-		ihigh = Py_Size(a);
+	else if (ihigh > Py_SIZE(a))
+		ihigh = Py_SIZE(a);
 	len = ihigh - ilow;
 	np = (PyListObject *) PyList_New(len);
 	if (np == NULL)
@@ -427,7 +459,7 @@
 		return NULL;
 	}
 #define b ((PyListObject *)bb)
-	size = Py_Size(a) + Py_Size(b);
+	size = Py_SIZE(a) + Py_SIZE(b);
 	if (size < 0)
 		return PyErr_NoMemory();
 	np = (PyListObject *) PyList_New(size);
@@ -436,14 +468,14 @@
 	}
 	src = a->ob_item;
 	dest = np->ob_item;
-	for (i = 0; i < Py_Size(a); i++) {
+	for (i = 0; i < Py_SIZE(a); i++) {
 		PyObject *v = src[i];
 		Py_INCREF(v);
 		dest[i] = v;
 	}
 	src = b->ob_item;
-	dest = np->ob_item + Py_Size(a);
-	for (i = 0; i < Py_Size(b); i++) {
+	dest = np->ob_item + Py_SIZE(a);
+	for (i = 0; i < Py_SIZE(b); i++) {
 		PyObject *v = src[i];
 		Py_INCREF(v);
 		dest[i] = v;
@@ -462,17 +494,17 @@
 	PyObject *elem;
 	if (n < 0)
 		n = 0;
-	size = Py_Size(a) * n;
-	if (size == 0)
-              return PyList_New(0);
-	if (n && size/n != Py_Size(a))
+	size = Py_SIZE(a) * n;
+	if (n && size/n != Py_SIZE(a))
 		return PyErr_NoMemory();
+	if (size == 0)
+		return PyList_New(0);
 	np = (PyListObject *) PyList_New(size);
 	if (np == NULL)
 		return NULL;
 
 	items = np->ob_item;
-	if (Py_Size(a) == 1) {
+	if (Py_SIZE(a) == 1) {
 		elem = a->ob_item[0];
 		for (i = 0; i < n; i++) {
 			items[i] = elem;
@@ -483,7 +515,7 @@
 	p = np->ob_item;
 	items = a->ob_item;
 	for (i = 0; i < n; i++) {
-		for (j = 0; j < Py_Size(a); j++) {
+		for (j = 0; j < Py_SIZE(a); j++) {
 			*p = items[j];
 			Py_INCREF(*p);
 			p++;
@@ -500,8 +532,8 @@
 	if (item != NULL) {
 		/* Because XDECREF can recursively invoke operations on
 		   this list, we make it empty first. */
-		i = Py_Size(a);
-		Py_Size(a) = 0;
+		i = Py_SIZE(a);
+		Py_SIZE(a) = 0;
 		a->ob_item = NULL;
 		a->allocated = 0;
 		while (--i >= 0) {
@@ -547,7 +579,7 @@
 	else {
 		if (a == b) {
 			/* Special case "a[i:j] = a" -- copy b first */
-			v = list_slice(b, 0, Py_Size(b));
+			v = list_slice(b, 0, Py_SIZE(b));
 			if (v == NULL)
 				return result;
 			result = list_ass_slice(a, ilow, ihigh, v);
@@ -562,18 +594,18 @@
 	}
 	if (ilow < 0)
 		ilow = 0;
-	else if (ilow > Py_Size(a))
-		ilow = Py_Size(a);
+	else if (ilow > Py_SIZE(a))
+		ilow = Py_SIZE(a);
 
 	if (ihigh < ilow)
 		ihigh = ilow;
-	else if (ihigh > Py_Size(a))
-		ihigh = Py_Size(a);
+	else if (ihigh > Py_SIZE(a))
+		ihigh = Py_SIZE(a);
 
 	norig = ihigh - ilow;
 	assert(norig >= 0);
 	d = n - norig;
-	if (Py_Size(a) + d == 0) {
+	if (Py_SIZE(a) + d == 0) {
 		Py_XDECREF(v_as_SF);
 		return list_clear(a);
 	}
@@ -591,12 +623,12 @@
 
 	if (d < 0) { /* Delete -d items */
 		memmove(&item[ihigh+d], &item[ihigh],
-			(Py_Size(a) - ihigh)*sizeof(PyObject *));
-		list_resize(a, Py_Size(a) + d);
+			(Py_SIZE(a) - ihigh)*sizeof(PyObject *));
+		list_resize(a, Py_SIZE(a) + d);
 		item = a->ob_item;
 	}
 	else if (d > 0) { /* Insert d items */
-		k = Py_Size(a);
+		k = Py_SIZE(a);
 		if (list_resize(a, k+d) < 0)
 			goto Error;
 		item = a->ob_item;
@@ -637,7 +669,7 @@
 
 
 	size = PyList_GET_SIZE(self);
-	if (size == 0) {
+	if (size == 0 || n == 1) {
 		Py_INCREF(self);
 		return (PyObject *)self;
 	}
@@ -648,6 +680,10 @@
 		return (PyObject *)self;
 	}
 
+	if (size > PY_SSIZE_T_MAX / n) {
+		return PyErr_NoMemory();
+	}
+
 	if (list_resize(self, size*n) == -1)
 		return NULL;
 
@@ -668,7 +704,7 @@
 list_ass_item(PyListObject *a, Py_ssize_t i, PyObject *v)
 {
 	PyObject *old_value;
-	if (i < 0 || i >= Py_Size(a)) {
+	if (i < 0 || i >= Py_SIZE(a)) {
 		PyErr_SetString(PyExc_IndexError,
 				"list assignment index out of range");
 		return -1;
@@ -727,7 +763,7 @@
 			Py_DECREF(b);
 			Py_RETURN_NONE;
 		}
-		m = Py_Size(self);
+		m = Py_SIZE(self);
 		if (list_resize(self, m + n) == -1) {
 			Py_DECREF(b);
 			return NULL;
@@ -755,24 +791,15 @@
 	iternext = *it->ob_type->tp_iternext;
 
 	/* Guess a result list size. */
-	n = _PyObject_LengthHint(b);
-	if (n < 0) {
-		if (!PyErr_ExceptionMatches(PyExc_TypeError)  &&
-		    !PyErr_ExceptionMatches(PyExc_AttributeError)) {
-			Py_DECREF(it);
-			return NULL;
-		}
-		PyErr_Clear();
-		n = 8;	/* arbitrary */
-	}
-	m = Py_Size(self);
+	n = _PyObject_LengthHint(b, 8);
+	m = Py_SIZE(self);
 	mn = m + n;
 	if (mn >= m) {
 		/* Make room. */
 		if (list_resize(self, mn) == -1)
 			goto error;
 		/* Make the list sane again. */
-		Py_Size(self) = m;
+		Py_SIZE(self) = m;
 	}
 	/* Else m + n overflowed; on the chance that n lied, and there really
 	 * is enough room, ignore it.  If n was telling the truth, we'll
@@ -791,10 +818,10 @@
 			}
 			break;
 		}
-		if (Py_Size(self) < self->allocated) {
+		if (Py_SIZE(self) < self->allocated) {
 			/* steals ref */
-			PyList_SET_ITEM(self, Py_Size(self), item);
-			++Py_Size(self);
+			PyList_SET_ITEM(self, Py_SIZE(self), item);
+			++Py_SIZE(self);
 		}
 		else {
 			int status = app1(self, item);
@@ -805,8 +832,8 @@
 	}
 
 	/* Cut back result list if initial guess was too large. */
-	if (Py_Size(self) < self->allocated)
-		list_resize(self, Py_Size(self));  /* shrinking can't fail */
+	if (Py_SIZE(self) < self->allocated)
+		list_resize(self, Py_SIZE(self));  /* shrinking can't fail */
 
 	Py_DECREF(it);
 	Py_RETURN_NONE;
@@ -845,20 +872,20 @@
 	if (!PyArg_ParseTuple(args, "|n:pop", &i))
 		return NULL;
 
-	if (Py_Size(self) == 0) {
+	if (Py_SIZE(self) == 0) {
 		/* Special-case most common failure cause */
 		PyErr_SetString(PyExc_IndexError, "pop from empty list");
 		return NULL;
 	}
 	if (i < 0)
-		i += Py_Size(self);
-	if (i < 0 || i >= Py_Size(self)) {
+		i += Py_SIZE(self);
+	if (i < 0 || i >= Py_SIZE(self)) {
 		PyErr_SetString(PyExc_IndexError, "pop index out of range");
 		return NULL;
 	}
 	v = self->ob_item[i];
-	if (i == Py_Size(self) - 1) {
-		status = list_resize(self, Py_Size(self) - 1);
+	if (i == Py_SIZE(self) - 1) {
+		status = list_resize(self, Py_SIZE(self) - 1);
 		assert(status >= 0);
 		return v; /* and v now owns the reference the list had */
 	}
@@ -893,60 +920,17 @@
  * pieces to this algorithm; read listsort.txt for overviews and details.
  */
 
-/* Comparison function.  Takes care of calling a user-supplied
- * comparison function (any callable Python object), which must not be
- * NULL (use the ISLT macro if you don't know, or call PyObject_RichCompareBool
- * with Py_LT if you know it's NULL).
+/* Comparison function: PyObject_RichCompareBool with Py_LT.
  * Returns -1 on error, 1 if x < y, 0 if x >= y.
  */
-static int
-islt(PyObject *x, PyObject *y, PyObject *compare)
-{
-	PyObject *res;
-	PyObject *args;
-	Py_ssize_t i;
 
-	assert(compare != NULL);
-	/* Call the user's comparison function and translate the 3-way
-	 * result into true or false (or error).
-	 */
-	args = PyTuple_New(2);
-	if (args == NULL)
-		return -1;
-	Py_INCREF(x);
-	Py_INCREF(y);
-	PyTuple_SET_ITEM(args, 0, x);
-	PyTuple_SET_ITEM(args, 1, y);
-	res = PyObject_Call(compare, args, NULL);
-	Py_DECREF(args);
-	if (res == NULL)
-		return -1;
-	if (!PyInt_CheckExact(res)) {
-		PyErr_Format(PyExc_TypeError,
-			     "comparison function must return int, not %.200s",
-			     res->ob_type->tp_name);
-		Py_DECREF(res);
-		return -1;
-	}
-	i = PyInt_AsLong(res);
-	Py_DECREF(res);
-	return i < 0;
-}
-
-/* If COMPARE is NULL, calls PyObject_RichCompareBool with Py_LT, else calls
- * islt.  This avoids a layer of function call in the usual case, and
- * sorting does many comparisons.
- * Returns -1 on error, 1 if x < y, 0 if x >= y.
- */
-#define ISLT(X, Y, COMPARE) ((COMPARE) == NULL ?			\
-			     PyObject_RichCompareBool(X, Y, Py_LT) :	\
-			     islt(X, Y, COMPARE))
+#define ISLT(X, Y) (PyObject_RichCompareBool(X, Y, Py_LT))
 
 /* Compare X to Y via "<".  Goto "fail" if the comparison raises an
    error.  Else "k" is set to true iff X<Y, and an "if (k)" block is
    started.  It makes more sense in context <wink>.  X and Y are PyObject*s.
 */
-#define IFLT(X, Y) if ((k = ISLT(X, Y, compare)) < 0) goto fail;  \
+#define IFLT(X, Y) if ((k = ISLT(X, Y)) < 0) goto fail;  \
 		   if (k)
 
 /* binarysort is the best method for sorting small arrays: it does
@@ -961,8 +945,7 @@
    the input (nothing is lost or duplicated).
 */
 static int
-binarysort(PyObject **lo, PyObject **hi, PyObject **start, PyObject *compare)
-     /* compare -- comparison function object, or NULL for default */
+binarysort(PyObject **lo, PyObject **hi, PyObject **start)
 {
 	register Py_ssize_t k;
 	register PyObject **l, **p, **r;
@@ -1027,7 +1010,7 @@
 Returns -1 in case of error.
 */
 static Py_ssize_t
-count_run(PyObject **lo, PyObject **hi, PyObject *compare, int *descending)
+count_run(PyObject **lo, PyObject **hi, int *descending)
 {
 	Py_ssize_t k;
 	Py_ssize_t n;
@@ -1082,7 +1065,7 @@
 Returns -1 on error.  See listsort.txt for info on the method.
 */
 static Py_ssize_t
-gallop_left(PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize_t hint, PyObject *compare)
+gallop_left(PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize_t hint)
 {
 	Py_ssize_t ofs;
 	Py_ssize_t lastofs;
@@ -1173,7 +1156,7 @@
 written as one routine with yet another "left or right?" flag.
 */
 static Py_ssize_t
-gallop_right(PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize_t hint, PyObject *compare)
+gallop_right(PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize_t hint)
 {
 	Py_ssize_t ofs;
 	Py_ssize_t lastofs;
@@ -1274,9 +1257,6 @@
 };
 
 typedef struct s_MergeState {
-	/* The user-supplied comparison function. or NULL if none given. */
-	PyObject *compare;
-
 	/* This controls when we get *into* galloping mode.  It's initialized
 	 * to MIN_GALLOP.  merge_lo and merge_hi tend to nudge it higher for
 	 * random data, and lower for highly structured data.
@@ -1307,10 +1287,9 @@
 
 /* Conceptually a MergeState's constructor. */
 static void
-merge_init(MergeState *ms, PyObject *compare)
+merge_init(MergeState *ms)
 {
 	assert(ms != NULL);
-	ms->compare = compare;
 	ms->a = ms->temparray;
 	ms->alloced = MERGESTATE_TEMP_SIZE;
 	ms->n = 0;
@@ -1367,7 +1346,6 @@
                          PyObject **pb, Py_ssize_t nb)
 {
 	Py_ssize_t k;
-	PyObject *compare;
 	PyObject **dest;
 	int result = -1;	/* guilty until proved innocent */
 	Py_ssize_t min_gallop;
@@ -1387,7 +1365,6 @@
 		goto CopyB;
 
 	min_gallop = ms->min_gallop;
-	compare = ms->compare;
 	for (;;) {
 		Py_ssize_t acount = 0;	/* # of times A won in a row */
 		Py_ssize_t bcount = 0;	/* # of times B won in a row */
@@ -1397,7 +1374,7 @@
 		 */
  		for (;;) {
  			assert(na > 1 && nb > 0);
-	 		k = ISLT(*pb, *pa, compare);
+	 		k = ISLT(*pb, *pa);
 			if (k) {
 				if (k < 0)
 					goto Fail;
@@ -1432,7 +1409,7 @@
  			assert(na > 1 && nb > 0);
 			min_gallop -= min_gallop > 1;
 	 		ms->min_gallop = min_gallop;
-			k = gallop_right(*pb, pa, na, 0, compare);
+			k = gallop_right(*pb, pa, na, 0);
 			acount = k;
 			if (k) {
 				if (k < 0)
@@ -1455,7 +1432,7 @@
 			if (nb == 0)
 				goto Succeed;
 
- 			k = gallop_left(*pa, pb, nb, 0, compare);
+ 			k = gallop_left(*pa, pb, nb, 0);
  			bcount = k;
 			if (k) {
 				if (k < 0)
@@ -1499,7 +1476,6 @@
 merge_hi(MergeState *ms, PyObject **pa, Py_ssize_t na, PyObject **pb, Py_ssize_t nb)
 {
 	Py_ssize_t k;
-	PyObject *compare;
 	PyObject **dest;
 	int result = -1;	/* guilty until proved innocent */
 	PyObject **basea;
@@ -1524,7 +1500,6 @@
 		goto CopyA;
 
 	min_gallop = ms->min_gallop;
-	compare = ms->compare;
 	for (;;) {
 		Py_ssize_t acount = 0;	/* # of times A won in a row */
 		Py_ssize_t bcount = 0;	/* # of times B won in a row */
@@ -1534,7 +1509,7 @@
 		 */
  		for (;;) {
  			assert(na > 0 && nb > 1);
-	 		k = ISLT(*pb, *pa, compare);
+	 		k = ISLT(*pb, *pa);
 			if (k) {
 				if (k < 0)
 					goto Fail;
@@ -1569,7 +1544,7 @@
  			assert(na > 0 && nb > 1);
 			min_gallop -= min_gallop > 1;
 	 		ms->min_gallop = min_gallop;
-			k = gallop_right(*pb, basea, na, na-1, compare);
+			k = gallop_right(*pb, basea, na, na-1);
 			if (k < 0)
 				goto Fail;
 			k = na - k;
@@ -1587,7 +1562,7 @@
 			if (nb == 1)
 				goto CopyA;
 
- 			k = gallop_left(*pa, baseb, nb, nb-1, compare);
+ 			k = gallop_left(*pa, baseb, nb, nb-1);
 			if (k < 0)
 				goto Fail;
 			k = nb - k;
@@ -1639,7 +1614,6 @@
 	PyObject **pa, **pb;
 	Py_ssize_t na, nb;
 	Py_ssize_t k;
-	PyObject *compare;
 
 	assert(ms != NULL);
 	assert(ms->n >= 2);
@@ -1665,8 +1639,7 @@
 	/* Where does b start in a?  Elements in a before that can be
 	 * ignored (already in place).
 	 */
-	compare = ms->compare;
-	k = gallop_right(*pb, pa, na, 0, compare);
+	k = gallop_right(*pb, pa, na, 0);
 	if (k < 0)
 		return -1;
 	pa += k;
@@ -1677,7 +1650,7 @@
 	/* Where does a end in b?  Elements in b after that can be
 	 * ignored (already in place).
 	 */
-	nb = gallop_left(pa[na-1], pb, nb, nb-1, compare);
+	nb = gallop_left(pa[na-1], pb, nb, nb-1);
 	if (nb <= 0)
 		return nb;
 
@@ -1772,8 +1745,8 @@
    pattern.  Holds a key which is used for comparisons and the original record
    which is returned during the undecorate phase.  By exposing only the key
    during comparisons, the underlying sort stability characteristics are left
-   unchanged.  Also, if a custom comparison function is used, it will only see
-   the key instead of a full record. */
+   unchanged.  Also, the comparison function will only see the key instead of
+   a full record. */
 
 typedef struct {
 	PyObject_HEAD
@@ -1787,7 +1760,7 @@
 static void
 sortwrapper_dealloc(sortwrapperobject *);
 
-static PyTypeObject sortwrapper_type = {
+PyTypeObject PySortWrapper_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
 	"sortwrapper",				/* tp_name */
 	sizeof(sortwrapperobject),		/* tp_basicsize */
@@ -1819,7 +1792,7 @@
 static PyObject *
 sortwrapper_richcompare(sortwrapperobject *a, sortwrapperobject *b, int op)
 {
-	if (!PyObject_TypeCheck(b, &sortwrapper_type)) {
+	if (!PyObject_TypeCheck(b, &PySortWrapper_Type)) {
 		PyErr_SetString(PyExc_TypeError,
 			"expected a sortwrapperobject");
 		return NULL;
@@ -1843,7 +1816,7 @@
 {
 	sortwrapperobject *so;
 
-	so = PyObject_New(sortwrapperobject, &sortwrapper_type);
+	so = PyObject_New(sortwrapperobject, &PySortWrapper_Type);
 	if (so == NULL)
 		return NULL;
 	so->key = key;
@@ -1857,7 +1830,7 @@
 {
 	PyObject *value;
 
-	if (!PyObject_TypeCheck(so, &sortwrapper_type)) {
+	if (!PyObject_TypeCheck(so, &PySortWrapper_Type)) {
 		PyErr_SetString(PyExc_TypeError,
 			"expected a sortwrapperobject");
 		return NULL;
@@ -1867,104 +1840,6 @@
 	return value;
 }
 
-/* Wrapper for user specified cmp functions in combination with a
-   specified key function.  Makes sure the cmp function is presented
-   with the actual key instead of the sortwrapper */
-
-typedef struct {
-	PyObject_HEAD
-	PyObject *func;
-} cmpwrapperobject;
-
-static void
-cmpwrapper_dealloc(cmpwrapperobject *co)
-{
-	Py_XDECREF(co->func);
-	PyObject_Del(co);
-}
-
-static PyObject *
-cmpwrapper_call(cmpwrapperobject *co, PyObject *args, PyObject *kwds)
-{
-	PyObject *x, *y, *xx, *yy;
-
-	if (!PyArg_UnpackTuple(args, "", 2, 2, &x, &y))
-		return NULL;
-	if (!PyObject_TypeCheck(x, &sortwrapper_type) ||
-	    !PyObject_TypeCheck(y, &sortwrapper_type)) {
-		PyErr_SetString(PyExc_TypeError,
-			"expected a sortwrapperobject");
-		return NULL;
-	}
-	xx = ((sortwrapperobject *)x)->key;
-	yy = ((sortwrapperobject *)y)->key;
-	return PyObject_CallFunctionObjArgs(co->func, xx, yy, NULL);
-}
-
-PyDoc_STRVAR(cmpwrapper_doc, "cmp() wrapper for sort with custom keys.");
-
-static PyTypeObject cmpwrapper_type = {
-	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"cmpwrapper",				/* tp_name */
-	sizeof(cmpwrapperobject),		/* tp_basicsize */
-	0,					/* tp_itemsize */
-	/* methods */
-	(destructor)cmpwrapper_dealloc,		/* tp_dealloc */
-	0,					/* tp_print */
-	0,					/* tp_getattr */
-	0,					/* tp_setattr */
-	0,					/* tp_compare */
-	0,					/* tp_repr */
-	0,					/* tp_as_number */
-	0,					/* tp_as_sequence */
-	0,					/* tp_as_mapping */
-	0,					/* tp_hash */
-	(ternaryfunc)cmpwrapper_call,		/* tp_call */
-	0,					/* tp_str */
-	PyObject_GenericGetAttr,		/* tp_getattro */
-	0,					/* tp_setattro */
-	0,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT,			/* tp_flags */
-	cmpwrapper_doc,				/* tp_doc */
-};
-
-static PyObject *
-build_cmpwrapper(PyObject *cmpfunc)
-{
-	cmpwrapperobject *co;
-
-	co = PyObject_New(cmpwrapperobject, &cmpwrapper_type);
-	if (co == NULL)
-		return NULL;
-	Py_INCREF(cmpfunc);
-	co->func = cmpfunc;
-	return (PyObject *)co;
-}
-
-static int
-is_default_cmp(PyObject *cmpfunc)
-{
-	PyCFunctionObject *f;
-	const char *module;
-	if (cmpfunc == NULL || cmpfunc == Py_None)
-		return 1;
-	if (!PyCFunction_Check(cmpfunc))
-		return 0;
-	f = (PyCFunctionObject *)cmpfunc;
-	if (f->m_self != NULL)
-		return 0;
-	if (!PyUnicode_Check(f->m_module))
-		return 0;
-	module = PyUnicode_AsString(f->m_module);
-	if (module == NULL)
-		return 0;
-	if (strcmp(module, "__builtin__") != 0)
-		return 0;
-	if (strcmp(f->m_ml->ml_name, "cmp") != 0)
-		return 0;
-	return 1;
-}
-
 /* An adaptive, stable, natural mergesort.  See listsort.txt.
  * Returns Py_None on success, NULL on error.  Even in case of error, the
  * list will be some permutation of its input state (nothing is lost or
@@ -1980,41 +1855,37 @@
 	Py_ssize_t saved_ob_size, saved_allocated;
 	PyObject **saved_ob_item;
 	PyObject **final_ob_item;
-	PyObject *compare = NULL;
 	PyObject *result = NULL;	/* guilty until proved innocent */
 	int reverse = 0;
 	PyObject *keyfunc = NULL;
 	Py_ssize_t i;
 	PyObject *key, *value, *kvpair;
-	static char *kwlist[] = {"cmp", "key", "reverse", 0};
+	static char *kwlist[] = {"key", "reverse", 0};
 
 	assert(self != NULL);
 	assert (PyList_Check(self));
 	if (args != NULL) {
-		if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOi:sort",
-			kwlist, &compare, &keyfunc, &reverse))
+		if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:sort",
+			kwlist, &keyfunc, &reverse))
+			return NULL;
+		if (Py_SIZE(args) > 0) {
+			PyErr_SetString(PyExc_TypeError,
+				"must use keyword argument for key function");
 			return NULL;
+		}
 	}
-	if (is_default_cmp(compare))
-		compare = NULL;
 	if (keyfunc == Py_None)
 		keyfunc = NULL;
-	if (compare != NULL && keyfunc != NULL) {
-		compare = build_cmpwrapper(compare);
-		if (compare == NULL)
-			return NULL;
-	} else
-		Py_XINCREF(compare);
 
 	/* The list is temporarily made empty, so that mutations performed
 	 * by comparison functions can't affect the slice of memory we're
 	 * sorting (allowing mutations during sorting is a core-dump
 	 * factory, since ob_item may change).
 	 */
-	saved_ob_size = Py_Size(self);
+	saved_ob_size = Py_SIZE(self);
 	saved_ob_item = self->ob_item;
 	saved_allocated = self->allocated;
-	Py_Size(self) = 0;
+	Py_SIZE(self) = 0;
 	self->ob_item = NULL;
 	self->allocated = -1; /* any operation will reset it to >= 0 */
 
@@ -2044,7 +1915,7 @@
 	if (reverse && saved_ob_size > 1)
 		reverse_slice(saved_ob_item, saved_ob_item + saved_ob_size);
 
-	merge_init(&ms, compare);
+	merge_init(&ms);
 
 	nremaining = saved_ob_size;
 	if (nremaining < 2)
@@ -2061,7 +1932,7 @@
 		Py_ssize_t n;
 
 		/* Identify next run. */
-		n = count_run(lo, hi, compare, &descending);
+		n = count_run(lo, hi, &descending);
 		if (n < 0)
 			goto fail;
 		if (descending)
@@ -2070,7 +1941,7 @@
 		if (n < minrun) {
 			const Py_ssize_t force = nremaining <= minrun ?
 	 			  	  nremaining : minrun;
-			if (binarysort(lo, lo + force, lo + n, compare) < 0)
+			if (binarysort(lo, lo + force, lo + n) < 0)
 				goto fail;
 			n = force;
 		}
@@ -2120,8 +1991,8 @@
 
 dsu_fail:
 	final_ob_item = self->ob_item;
-	i = Py_Size(self);
-	Py_Size(self) = saved_ob_size;
+	i = Py_SIZE(self);
+	Py_SIZE(self) = saved_ob_size;
 	self->ob_item = saved_ob_item;
 	self->allocated = saved_allocated;
 	if (final_ob_item != NULL) {
@@ -2132,7 +2003,6 @@
 		}
 		PyMem_FREE(final_ob_item);
 	}
-	Py_XDECREF(compare);
 	Py_XINCREF(result);
 	return result;
 }
@@ -2156,8 +2026,8 @@
 static PyObject *
 listreverse(PyListObject *self)
 {
-	if (Py_Size(self) > 1)
-		reverse_slice(self->ob_item, self->ob_item + Py_Size(self));
+	if (Py_SIZE(self) > 1)
+		reverse_slice(self->ob_item, self->ob_item + Py_SIZE(self));
 	Py_RETURN_NONE;
 }
 
@@ -2170,8 +2040,8 @@
 		PyErr_BadInternalCall();
 		return -1;
 	}
-	if (Py_Size(self) > 1)
-		reverse_slice(self->ob_item, self->ob_item + Py_Size(self));
+	if (Py_SIZE(self) > 1)
+		reverse_slice(self->ob_item, self->ob_item + Py_SIZE(self));
 	return 0;
 }
 
@@ -2179,23 +2049,23 @@
 PyList_AsTuple(PyObject *v)
 {
 	PyObject *w;
-	PyObject **p;
+	PyObject **p, **q;
 	Py_ssize_t n;
 	if (v == NULL || !PyList_Check(v)) {
 		PyErr_BadInternalCall();
 		return NULL;
 	}
-	n = Py_Size(v);
+	n = Py_SIZE(v);
 	w = PyTuple_New(n);
 	if (w == NULL)
 		return NULL;
 	p = ((PyTupleObject *)w)->ob_item;
-	memcpy((void *)p,
-	       (void *)((PyListObject *)v)->ob_item,
-	       n*sizeof(PyObject *));
+	q = ((PyListObject *)v)->ob_item;
 	while (--n >= 0) {
-		Py_INCREF(*p);
+		Py_INCREF(*q);
+		*p = *q;
 		p++;
+		q++;
 	}
 	return w;
 }
@@ -2203,7 +2073,7 @@
 static PyObject *
 listindex(PyListObject *self, PyObject *args)
 {
-	Py_ssize_t i, start=0, stop=Py_Size(self);
+	Py_ssize_t i, start=0, stop=Py_SIZE(self);
 	PyObject *v;
 
 	if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
@@ -2211,19 +2081,19 @@
 	                            _PyEval_SliceIndex, &stop))
 		return NULL;
 	if (start < 0) {
-		start += Py_Size(self);
+		start += Py_SIZE(self);
 		if (start < 0)
 			start = 0;
 	}
 	if (stop < 0) {
-		stop += Py_Size(self);
+		stop += Py_SIZE(self);
 		if (stop < 0)
 			stop = 0;
 	}
-	for (i = start; i < stop && i < Py_Size(self); i++) {
+	for (i = start; i < stop && i < Py_SIZE(self); i++) {
 		int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
 		if (cmp > 0)
-			return PyInt_FromSsize_t(i);
+			return PyLong_FromSsize_t(i);
 		else if (cmp < 0)
 			return NULL;
 	}
@@ -2237,14 +2107,14 @@
 	Py_ssize_t count = 0;
 	Py_ssize_t i;
 
-	for (i = 0; i < Py_Size(self); i++) {
+	for (i = 0; i < Py_SIZE(self); i++) {
 		int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
 		if (cmp > 0)
 			count++;
 		else if (cmp < 0)
 			return NULL;
 	}
-	return PyInt_FromSsize_t(count);
+	return PyLong_FromSsize_t(count);
 }
 
 static PyObject *
@@ -2252,7 +2122,7 @@
 {
 	Py_ssize_t i;
 
-	for (i = 0; i < Py_Size(self); i++) {
+	for (i = 0; i < Py_SIZE(self); i++) {
 		int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
 		if (cmp > 0) {
 			if (list_ass_slice(self, i, i+1,
@@ -2272,7 +2142,7 @@
 {
 	Py_ssize_t i;
 
-	for (i = Py_Size(o); --i >= 0; )
+	for (i = Py_SIZE(o); --i >= 0; )
 		Py_VISIT(o->ob_item[i]);
 	return 0;
 }
@@ -2291,7 +2161,7 @@
 	vl = (PyListObject *)v;
 	wl = (PyListObject *)w;
 
-	if (Py_Size(vl) != Py_Size(wl) && (op == Py_EQ || op == Py_NE)) {
+	if (Py_SIZE(vl) != Py_SIZE(wl) && (op == Py_EQ || op == Py_NE)) {
 		/* Shortcut: if the lengths differ, the lists differ */
 		PyObject *res;
 		if (op == Py_EQ)
@@ -2303,7 +2173,7 @@
 	}
 
 	/* Search for the first index where items are different */
-	for (i = 0; i < Py_Size(vl) && i < Py_Size(wl); i++) {
+	for (i = 0; i < Py_SIZE(vl) && i < Py_SIZE(wl); i++) {
 		int k = PyObject_RichCompareBool(vl->ob_item[i],
 						 wl->ob_item[i], Py_EQ);
 		if (k < 0)
@@ -2312,10 +2182,10 @@
 			break;
 	}
 
-	if (i >= Py_Size(vl) || i >= Py_Size(wl)) {
+	if (i >= Py_SIZE(vl) || i >= Py_SIZE(wl)) {
 		/* No more items to compare -- compare sizes */
-		Py_ssize_t vs = Py_Size(vl);
-		Py_ssize_t ws = Py_Size(wl);
+		Py_ssize_t vs = Py_SIZE(vl);
+		Py_ssize_t ws = Py_SIZE(wl);
 		int cmp;
 		PyObject *res;
 		switch (op) {
@@ -2359,8 +2229,8 @@
 		return -1;
 
 	/* Verify list invariants established by PyType_GenericAlloc() */
-	assert(0 <= Py_Size(self));
-	assert(Py_Size(self) <= self->allocated || self->allocated == -1);
+	assert(0 <= Py_SIZE(self));
+	assert(Py_SIZE(self) <= self->allocated || self->allocated == -1);
 	assert(self->ob_item != NULL ||
 	       self->allocated == 0 || self->allocated == -1);
 
@@ -2401,7 +2271,7 @@
 PyDoc_STRVAR(reverse_doc,
 "L.reverse() -- reverse *IN PLACE*");
 PyDoc_STRVAR(sort_doc,
-"L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;\n\
+"L.sort(key=None, reverse=False) -- stable sort *IN PLACE*;\n\
 cmp(x, y) -> -1, 0, 1");
 
 static PyObject *list_subscript(PyListObject*, PyObject*);
@@ -2456,7 +2326,7 @@
 		PyObject* it;
 		PyObject **src, **dest;
 
-		if (PySlice_GetIndicesEx((PySliceObject*)item, Py_Size(self),
+		if (PySlice_GetIndicesEx((PySliceObject*)item, Py_SIZE(self),
 				 &start, &stop, &step, &slicelength) < 0) {
 			return NULL;
 		}
@@ -2505,7 +2375,7 @@
 	else if (PySlice_Check(item)) {
 		Py_ssize_t start, stop, step, slicelength;
 
-		if (PySlice_GetIndicesEx((PySliceObject*)item, Py_Size(self),
+		if (PySlice_GetIndicesEx((PySliceObject*)item, Py_SIZE(self),
 				 &start, &stop, &step, &slicelength) < 0) {
 			return -1;
 		}
@@ -2553,8 +2423,8 @@
 
 				garbage[i] = PyList_GET_ITEM(self, cur);
 
-				if (cur + step >= Py_Size(self)) {
-					lim = Py_Size(self) - cur - 1;
+				if (cur + step >= Py_SIZE(self)) {
+					lim = Py_SIZE(self) - cur - 1;
 				}
 
 				memmove(self->ob_item + cur - i,
@@ -2562,15 +2432,15 @@
 					lim * sizeof(PyObject *));
 			}
 			cur = start + slicelength*step;
-			if (cur < Py_Size(self)) {
+			if (cur < Py_SIZE(self)) {
 				memmove(self->ob_item + cur - slicelength,
 					self->ob_item + cur,
-					(Py_Size(self) - cur) * 
+					(Py_SIZE(self) - cur) * 
 					 sizeof(PyObject *));
 			}
 
-			Py_Size(self) -= slicelength;
-			list_resize(self, Py_Size(self));
+			Py_SIZE(self) -= slicelength;
+			list_resize(self, Py_SIZE(self));
 
 			for (i = 0; i < slicelength; i++) {
 				Py_DECREF(garbage[i]);
@@ -2723,7 +2593,7 @@
 
 PyTypeObject PyListIter_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"listiterator",				/* tp_name */
+	"list_iterator",			/* tp_name */
 	sizeof(listiterobject),			/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */
@@ -2820,9 +2690,9 @@
 	if (it->it_seq) {
 		len = PyList_GET_SIZE(it->it_seq) - it->it_index;
 		if (len >= 0)
-			return PyInt_FromSsize_t(len);
+			return PyLong_FromSsize_t(len);
 	}
-	return PyInt_FromLong(0);
+	return PyLong_FromLong(0);
 }
 /*********************** List Reverse Iterator **************************/
 
@@ -2845,7 +2715,7 @@
 
 PyTypeObject PyListRevIter_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"listreverseiterator",			/* tp_name */
+	"list_reverseiterator",			/* tp_name */
 	sizeof(listreviterobject),		/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */

Modified: python/branches/py3k-importlib/Objects/longobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/longobject.c	(original)
+++ python/branches/py3k-importlib/Objects/longobject.c	Thu Mar 27 00:48:05 2008
@@ -9,12 +9,6 @@
 
 #include <ctype.h>
 
-long
-PyInt_GetMax(void)
-{
-	return LONG_MAX;	/* To initialize sys.maxint */
-}
-
 #ifndef NSMALLPOSINTS
 #define NSMALLPOSINTS		257
 #endif
@@ -54,12 +48,12 @@
 #define CHECK_SMALL_INT(ival)
 #endif
 
-#define MEDIUM_VALUE(x) (Py_Size(x) < 0 ? -(x)->ob_digit[0] : (Py_Size(x) == 0 ? 0 : (x)->ob_digit[0]))
+#define MEDIUM_VALUE(x) (Py_SIZE(x) < 0 ? -(x)->ob_digit[0] : (Py_SIZE(x) == 0 ? 0 : (x)->ob_digit[0]))
 /* If a freshly-allocated long is already shared, it must
    be a small integer, so negating it must go to PyLong_FromLong */
 #define NEGATE(x) \
-	do if (Py_Refcnt(x) == 1) Py_Size(x) = -Py_Size(x);  \
-	   else { PyObject* tmp=PyInt_FromLong(-MEDIUM_VALUE(x));  \
+	do if (Py_REFCNT(x) == 1) Py_SIZE(x) = -Py_SIZE(x);  \
+	   else { PyObject* tmp=PyLong_FromLong(-MEDIUM_VALUE(x));  \
 		   Py_DECREF(x); (x) = (PyLongObject*)tmp; }	   \
         while(0)
 /* For long multiplication, use the O(N**2) school algorithm unless
@@ -102,13 +96,13 @@
 static PyLongObject *
 long_normalize(register PyLongObject *v)
 {
-	Py_ssize_t j = ABS(Py_Size(v));
+	Py_ssize_t j = ABS(Py_SIZE(v));
 	Py_ssize_t i = j;
 
 	while (i > 0 && v->ob_digit[i-1] == 0)
 		--i;
 	if (i != j)
-		Py_Size(v) = (Py_Size(v) < 0) ? -(i) : i;
+		Py_SIZE(v) = (Py_SIZE(v) < 0) ? -(i) : i;
 	return v;
 }
 
@@ -142,18 +136,18 @@
 	Py_ssize_t i;
 
 	assert(src != NULL);
-	i = Py_Size(src);
+	i = Py_SIZE(src);
 	if (i < 0)
 		i = -(i);
 	if (i < 2) {
 		int ival = src->ob_digit[0];
-		if (Py_Size(src) < 0)
+		if (Py_SIZE(src) < 0)
 			ival = -ival;
 		CHECK_SMALL_INT(ival);
 	}
 	result = _PyLong_New(i);
 	if (result != NULL) {
-		Py_Size(result) = Py_Size(src);
+		Py_SIZE(result) = Py_SIZE(src);
 		while (--i >= 0)
 			result->ob_digit[i] = src->ob_digit[i];
 	}
@@ -181,7 +175,7 @@
 	if (!(ival>>PyLong_SHIFT)) {
 		v = _PyLong_New(1);
 		if (v) {
-			Py_Size(v) = sign;
+			Py_SIZE(v) = sign;
 			v->ob_digit[0] = ival;
 		}
 		return (PyObject*)v;
@@ -191,7 +185,7 @@
 	if (!(ival >> 2*PyLong_SHIFT)) {
 		v = _PyLong_New(2);
 		if (v) {
-			Py_Size(v) = 2*sign;
+			Py_SIZE(v) = 2*sign;
 			v->ob_digit[0] = (digit)ival & PyLong_MASK;
 			v->ob_digit[1] = ival >> PyLong_SHIFT;
 		}
@@ -207,7 +201,7 @@
 	v = _PyLong_New(ndigits);
 	if (v != NULL) {
 		digit *p = v->ob_digit;
-		Py_Size(v) = ndigits*sign;
+		Py_SIZE(v) = ndigits*sign;
 		t = (unsigned long)ival;
 		while (t) {
 			*p++ = (digit)(t & PyLong_MASK);
@@ -237,7 +231,7 @@
 	v = _PyLong_New(ndigits);
 	if (v != NULL) {
 		digit *p = v->ob_digit;
-		Py_Size(v) = ndigits;
+		Py_SIZE(v) = ndigits;
 		while (ival) {
 			*p++ = (digit)(ival & PyLong_MASK);
 			ival >>= PyLong_SHIFT;
@@ -260,6 +254,11 @@
 			"cannot convert float infinity to int");
 		return NULL;
 	}
+	if (Py_IS_NAN(dval)) {
+		PyErr_SetString(PyExc_OverflowError,
+			"cannot convert float NaN to int");
+		return NULL;
+	}
 	if (dval < 0.0) {
 		neg = 1;
 		dval = -dval;
@@ -279,7 +278,7 @@
 		frac = ldexp(frac, PyLong_SHIFT);
 	}
 	if (neg)
-		Py_Size(v) = -(Py_Size(v));
+		Py_SIZE(v) = -(Py_SIZE(v));
 	return (PyObject *)v;
 }
 
@@ -299,7 +298,7 @@
    Returns -1 and sets an error condition if overflow occurs. */
 
 long
-PyLong_AsLong(PyObject *vv)
+PyLong_AsLongAndOverflow(PyObject *vv, int *overflow)
 {
 	/* This version by Tim Peters */
 	register PyLongObject *v;
@@ -309,6 +308,7 @@
 	int sign;
 	int do_decref = 0; /* if nb_int was called */
 
+	*overflow = 0;
 	if (vv == NULL) {
 		PyErr_BadInternalCall();
 		return -1;
@@ -335,7 +335,7 @@
 
 	res = -1;
 	v = (PyLongObject *)vv;
-	i = Py_Size(v);
+	i = Py_SIZE(v);
 
 	switch (i) {
 	case -1:
@@ -358,8 +358,7 @@
 			prev = x;
 			x = (x << PyLong_SHIFT) + v->ob_digit[i];
 			if ((x >> PyLong_SHIFT) != prev) {
-				PyErr_SetString(PyExc_OverflowError,
-					"Python int too large to convert to C long");
+				*overflow = Py_SIZE(v) > 0 ? 1 : -1;
 				goto exit;
 			}
 		}
@@ -373,8 +372,8 @@
 			res = LONG_MIN;
 		}
 		else {
-			PyErr_SetString(PyExc_OverflowError,
-				"Python int too large to convert to C long");
+			*overflow = Py_SIZE(v) > 0 ? 1 : -1;
+			/* res is already set to -1 */
 		}	
 	}
  exit:
@@ -384,17 +383,18 @@
 	return res;
 }
 
-int
-_PyLong_FitsInLong(PyObject *vv)
+long 
+PyLong_AsLong(PyObject *obj)
 {
-	int size;
-	if (!PyLong_CheckExact(vv)) {
-		PyErr_BadInternalCall();
-		return 0;
+	int overflow;
+	long result = PyLong_AsLongAndOverflow(obj, &overflow);
+	if (overflow) {
+		/* XXX: could be cute and give a different 
+		   message for overflow == -1 */
+		PyErr_SetString(PyExc_OverflowError,
+				"Python int too large to convert to C long");
 	}
-	/* conservative estimate */
-	size = Py_Size(vv);
-	return -2 <= size && size <= 2;
+	return result;
 }
 
 /* Get a Py_ssize_t from a long int object.
@@ -412,7 +412,7 @@
 		return -1;
 	}
 	v = (PyLongObject *)vv;
-	i = Py_Size(v);
+	i = Py_SIZE(v);
 	switch (i) {
 	case -1: return -v->ob_digit[0];
 	case 0: return 0;
@@ -462,7 +462,7 @@
 		return (unsigned long) -1;
 	}
 	v = (PyLongObject *)vv;
-	i = Py_Size(v);
+	i = Py_SIZE(v);
 	x = 0;
 	if (i < 0) {
 		PyErr_SetString(PyExc_OverflowError,
@@ -500,7 +500,7 @@
 		return (unsigned long) -1;
 	}
 	v = (PyLongObject *)vv;
-	i = Py_Size(v);
+	i = Py_SIZE(v);
 	x = 0;
 	if (i < 0) {
 		PyErr_SetString(PyExc_OverflowError,
@@ -539,7 +539,7 @@
 		return (unsigned long) -1;
 	}
 	v = (PyLongObject *)vv;
-	i = Py_Size(v);
+	i = Py_SIZE(v);
 	switch (i) {
 	case 0: return 0;
 	case 1: return v->ob_digit[0];
@@ -599,7 +599,7 @@
 	assert(v != NULL);
 	assert(PyLong_Check(v));
 
-	return Py_Size(v) == 0 ? 0 : (Py_Size(v) < 0 ? -1 : 1);
+	return Py_SIZE(v) == 0 ? 0 : (Py_SIZE(v) < 0 ? -1 : 1);
 }
 
 size_t
@@ -611,7 +611,7 @@
 
 	assert(v != NULL);
 	assert(PyLong_Check(v));
-	ndigits = ABS(Py_Size(v));
+	ndigits = ABS(Py_SIZE(v));
 	assert(ndigits == 0 || v->ob_digit[ndigits - 1] != 0);
 	if (ndigits > 0) {
 		digit msd = v->ob_digit[ndigits - 1];
@@ -737,7 +737,7 @@
 		}
 	}
 
-	Py_Size(v) = is_signed ? -idigit : idigit;
+	Py_SIZE(v) = is_signed ? -idigit : idigit;
 	return (PyObject *)long_normalize(v);
 }
 
@@ -758,8 +758,8 @@
 
 	assert(v != NULL && PyLong_Check(v));
 
-	if (Py_Size(v) < 0) {
-		ndigits = -(Py_Size(v));
+	if (Py_SIZE(v) < 0) {
+		ndigits = -(Py_SIZE(v));
 		if (!is_signed) {
 			PyErr_SetString(PyExc_TypeError,
 				"can't convert negative int to unsigned");
@@ -768,7 +768,7 @@
 		do_twos_comp = 1;
 	}
 	else {
-		ndigits = Py_Size(v);
+		ndigits = Py_SIZE(v);
 		do_twos_comp = 0;
 	}
 
@@ -904,7 +904,7 @@
 		return -1;
 	}
 	v = (PyLongObject *)vv;
-	i = Py_Size(v);
+	i = Py_SIZE(v);
 	sign = 1;
 	if (i < 0) {
 		sign = -1;
@@ -976,7 +976,7 @@
 #endif
 	/* special-case null pointer */
 	if (!p)
-		return PyInt_FromLong(0);
+		return PyLong_FromLong(0);
 	return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)(Py_uintptr_t)p);
 
 }
@@ -1055,7 +1055,7 @@
 	v = _PyLong_New(ndigits);
 	if (v != NULL) {
 		digit *p = v->ob_digit;
-		Py_Size(v) = negative ? -ndigits : ndigits;
+		Py_SIZE(v) = negative ? -ndigits : ndigits;
 		t = (unsigned PY_LONG_LONG)ival;
 		while (t) {
 			*p++ = (digit)(t & PyLong_MASK);
@@ -1085,7 +1085,7 @@
 	v = _PyLong_New(ndigits);
 	if (v != NULL) {
 		digit *p = v->ob_digit;
-		Py_Size(v) = ndigits;
+		Py_SIZE(v) = ndigits;
 		while (ival) {
 			*p++ = (digit)(ival & PyLong_MASK);
 			ival >>= PyLong_SHIFT;
@@ -1159,7 +1159,7 @@
 	}
 
 	v = (PyLongObject*)vv;
-	switch(Py_Size(v)) {
+	switch(Py_SIZE(v)) {
 	case -1: return -v->ob_digit[0];
 	case 0: return 0;
 	case 1: return v->ob_digit[0];
@@ -1192,7 +1192,7 @@
 	}
 
 	v = (PyLongObject*)vv;
-	switch(Py_Size(v)) {
+	switch(Py_SIZE(v)) {
 	case 0: return 0;
 	case 1: return v->ob_digit[0];
 	}
@@ -1224,11 +1224,11 @@
 		return (unsigned long) -1;
 	}
 	v = (PyLongObject *)vv;
-	switch(Py_Size(v)) {
+	switch(Py_SIZE(v)) {
 	case 0: return 0;
 	case 1: return v->ob_digit[0];
 	}
-	i = Py_Size(v);
+	i = Py_SIZE(v);
 	sign = 1;
 	x = 0;
 	if (i < 0) {
@@ -1350,7 +1350,7 @@
 static PyLongObject *
 muladd1(PyLongObject *a, wdigit n, wdigit extra)
 {
-	Py_ssize_t size_a = ABS(Py_Size(a));
+	Py_ssize_t size_a = ABS(Py_SIZE(a));
 	PyLongObject *z = _PyLong_New(size_a+1);
 	twodigits carry = extra;
 	Py_ssize_t i;
@@ -1396,7 +1396,7 @@
 static PyLongObject *
 divrem1(PyLongObject *a, digit n, digit *prem)
 {
-	const Py_ssize_t size = ABS(Py_Size(a));
+	const Py_ssize_t size = ABS(Py_SIZE(a));
 	PyLongObject *z;
 
 	assert(n > 0 && n <= PyLong_MASK);
@@ -1427,7 +1427,7 @@
 		return NULL;
 	}
 	assert(base >= 2 && base <= 36);
-	size_a = ABS(Py_Size(a));
+	size_a = ABS(Py_SIZE(a));
 
 	/* Compute a rough upper bound for the length of the string */
 	i = base;
@@ -1449,10 +1449,10 @@
 		return NULL;
 	p = PyUnicode_AS_UNICODE(str) + sz;
 	*p = '\0';
-	if (Py_Size(a) < 0)
+	if (Py_SIZE(a) < 0)
 		sign = '-';
 
-	if (Py_Size(a) == 0) {
+	if (Py_SIZE(a) == 0) {
 		*--p = '0';
 	}
 	else if ((base & (base - 1)) == 0) {
@@ -1685,8 +1685,6 @@
 		++str;
 		sign = -1;
 	}
-	while (*str != '\0' && isspace(Py_CHARMASK(*str)))
-		str++;
 	if (base == 0) {
 		if (str[0] != '0')
 			base = 10;
@@ -1845,7 +1843,7 @@
 		z = _PyLong_New(size_z);
 		if (z == NULL)
 			return NULL;
-		Py_Size(z) = 0;
+		Py_SIZE(z) = 0;
 
 		/* `convwidth` consecutive input digits are treated as a single
 		 * digit in base `convmultmax`.
@@ -1875,7 +1873,7 @@
 
 			/* Multiply z by convmult, and add c. */
 			pz = z->ob_digit;
-			pzstop = pz + Py_Size(z);
+			pzstop = pz + Py_SIZE(z);
 			for (; pz < pzstop; ++pz) {
 				c += (twodigits)*pz * convmult;
 				*pz = (digit)(c & PyLong_MASK);
@@ -1884,14 +1882,14 @@
 			/* carry off the current end? */
 			if (c) {
 				assert(c < PyLong_BASE);
-				if (Py_Size(z) < size_z) {
+				if (Py_SIZE(z) < size_z) {
 					*pz = (digit)c;
-					++Py_Size(z);
+					++Py_SIZE(z);
 				}
 				else {
 					PyLongObject *tmp;
 					/* Extremely rare.  Get more space. */
-					assert(Py_Size(z) == size_z);
+					assert(Py_SIZE(z) == size_z);
 					tmp = _PyLong_New(size_z + 1);
 					if (tmp == NULL) {
 						Py_DECREF(z);
@@ -1914,7 +1912,7 @@
 		/* reset the base to 0, else the exception message
 		   doesn't make too much sense */
 		base = 0;
-		if (Py_Size(z) != 0)
+		if (Py_SIZE(z) != 0)
 			goto onError;
 		/* there might still be other problems, therefore base
 		   remains zero here for the same reason */
@@ -1922,7 +1920,7 @@
 	if (str == start)
 		goto onError;
 	if (sign < 0)
-		Py_Size(z) = -(Py_Size(z));
+		Py_SIZE(z) = -(Py_SIZE(z));
 	if (*str == 'L' || *str == 'l')
 		str++;
 	while (*str && isspace(Py_CHARMASK(*str)))
@@ -1977,7 +1975,7 @@
 long_divrem(PyLongObject *a, PyLongObject *b,
 	    PyLongObject **pdiv, PyLongObject **prem)
 {
-	Py_ssize_t size_a = ABS(Py_Size(a)), size_b = ABS(Py_Size(b));
+	Py_ssize_t size_a = ABS(Py_SIZE(a)), size_b = ABS(Py_SIZE(b));
 	PyLongObject *z;
 
 	if (size_b == 0) {
@@ -2016,9 +2014,9 @@
 	   The quotient z has the sign of a*b;
 	   the remainder r has the sign of a,
 	   so a = b*z + r. */
-	if ((Py_Size(a) < 0) != (Py_Size(b) < 0))
+	if ((Py_SIZE(a) < 0) != (Py_SIZE(b) < 0))
 		NEGATE(z);
-	if (Py_Size(a) < 0 && Py_Size(*prem) != 0)
+	if (Py_SIZE(a) < 0 && Py_SIZE(*prem) != 0)
 		NEGATE(*prem);
 	*pdiv = z;
 	return 0;
@@ -2029,7 +2027,7 @@
 static PyLongObject *
 x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
 {
-	Py_ssize_t size_v = ABS(Py_Size(v1)), size_w = ABS(Py_Size(w1));
+	Py_ssize_t size_v = ABS(Py_SIZE(v1)), size_w = ABS(Py_SIZE(w1));
 	digit d = (digit) ((twodigits)PyLong_BASE / (w1->ob_digit[size_w-1] + 1));
 	PyLongObject *v = mul1(v1, d);
 	PyLongObject *w = mul1(w1, d);
@@ -2043,10 +2041,10 @@
 	}
 
 	assert(size_v >= size_w && size_w > 1); /* Assert checks by div() */
-	assert(Py_Refcnt(v) == 1); /* Since v will be used as accumulator! */
-	assert(size_w == ABS(Py_Size(w))); /* That's how d was calculated */
+	assert(Py_REFCNT(v) == 1); /* Since v will be used as accumulator! */
+	assert(size_w == ABS(Py_SIZE(w))); /* That's how d was calculated */
 
-	size_v = ABS(Py_Size(v));
+	size_v = ABS(Py_SIZE(v));
 	k = size_v - size_w;
 	a = _PyLong_New(k + 1);
 
@@ -2129,7 +2127,7 @@
 static void
 long_dealloc(PyObject *v)
 {
-	Py_Type(v)->tp_free(v);
+	Py_TYPE(v)->tp_free(v);
 }
 
 static PyObject *
@@ -2143,21 +2141,21 @@
 {
 	Py_ssize_t sign;
 
-	if (Py_Size(a) != Py_Size(b)) {
-		if (ABS(Py_Size(a)) == 0 && ABS(Py_Size(b)) == 0)
+	if (Py_SIZE(a) != Py_SIZE(b)) {
+		if (ABS(Py_SIZE(a)) == 0 && ABS(Py_SIZE(b)) == 0)
 			sign = 0;
 		else
-			sign = Py_Size(a) - Py_Size(b);
+			sign = Py_SIZE(a) - Py_SIZE(b);
 	}
 	else {
-		Py_ssize_t i = ABS(Py_Size(a));
+		Py_ssize_t i = ABS(Py_SIZE(a));
 		while (--i >= 0 && a->ob_digit[i] == b->ob_digit[i])
 			;
 		if (i < 0)
 			sign = 0;
 		else {
 			sign = (int)a->ob_digit[i] - (int)b->ob_digit[i];
-			if (Py_Size(a) < 0)
+			if (Py_SIZE(a) < 0)
 				sign = -sign;
 		}
 	}
@@ -2184,7 +2182,7 @@
 	/* This is designed so that Python ints and longs with the
 	   same value hash to the same value, otherwise comparisons
 	   of mapping keys will turn out weird */
-	i = Py_Size(v);
+	i = Py_SIZE(v);
 	switch(i) {
 	case -1: return v->ob_digit[0]==1 ? -2 : -v->ob_digit[0];
 	case 0: return 0;
@@ -2223,7 +2221,7 @@
 static PyLongObject *
 x_add(PyLongObject *a, PyLongObject *b)
 {
-	Py_ssize_t size_a = ABS(Py_Size(a)), size_b = ABS(Py_Size(b));
+	Py_ssize_t size_a = ABS(Py_SIZE(a)), size_b = ABS(Py_SIZE(b));
 	PyLongObject *z;
 	int i;
 	digit carry = 0;
@@ -2257,7 +2255,7 @@
 static PyLongObject *
 x_sub(PyLongObject *a, PyLongObject *b)
 {
-	Py_ssize_t size_a = ABS(Py_Size(a)), size_b = ABS(Py_Size(b));
+	Py_ssize_t size_a = ABS(Py_SIZE(a)), size_b = ABS(Py_SIZE(b));
 	PyLongObject *z;
 	Py_ssize_t i;
 	int sign = 1;
@@ -2314,22 +2312,22 @@
 
 	CHECK_BINOP(a, b);
 
-	if (ABS(Py_Size(a)) <= 1 && ABS(Py_Size(b)) <= 1) {
-		PyObject *result = PyInt_FromLong(MEDIUM_VALUE(a) +
+	if (ABS(Py_SIZE(a)) <= 1 && ABS(Py_SIZE(b)) <= 1) {
+		PyObject *result = PyLong_FromLong(MEDIUM_VALUE(a) +
 						  MEDIUM_VALUE(b));
 		return result;
 	}
-	if (Py_Size(a) < 0) {
-		if (Py_Size(b) < 0) {
+	if (Py_SIZE(a) < 0) {
+		if (Py_SIZE(b) < 0) {
 			z = x_add(a, b);
-			if (z != NULL && Py_Size(z) != 0)
-				Py_Size(z) = -(Py_Size(z));
+			if (z != NULL && Py_SIZE(z) != 0)
+				Py_SIZE(z) = -(Py_SIZE(z));
 		}
 		else
 			z = x_sub(b, a);
 	}
 	else {
-		if (Py_Size(b) < 0)
+		if (Py_SIZE(b) < 0)
 			z = x_sub(a, b);
 		else
 			z = x_add(a, b);
@@ -2344,21 +2342,21 @@
 
 	CHECK_BINOP(a, b);
 
-	if (ABS(Py_Size(a)) <= 1 && ABS(Py_Size(b)) <= 1) {
+	if (ABS(Py_SIZE(a)) <= 1 && ABS(Py_SIZE(b)) <= 1) {
 		PyObject* r;
 		r = PyLong_FromLong(MEDIUM_VALUE(a)-MEDIUM_VALUE(b));
 		return r;
 	}
-	if (Py_Size(a) < 0) {
-		if (Py_Size(b) < 0)
+	if (Py_SIZE(a) < 0) {
+		if (Py_SIZE(b) < 0)
 			z = x_sub(a, b);
 		else
 			z = x_add(a, b);
-		if (z != NULL && Py_Size(z) != 0)
-			Py_Size(z) = -(Py_Size(z));
+		if (z != NULL && Py_SIZE(z) != 0)
+			Py_SIZE(z) = -(Py_SIZE(z));
 	}
 	else {
-		if (Py_Size(b) < 0)
+		if (Py_SIZE(b) < 0)
 			z = x_add(a, b);
 		else
 			z = x_sub(a, b);
@@ -2373,15 +2371,15 @@
 x_mul(PyLongObject *a, PyLongObject *b)
 {
 	PyLongObject *z;
-	Py_ssize_t size_a = ABS(Py_Size(a));
-	Py_ssize_t size_b = ABS(Py_Size(b));
+	Py_ssize_t size_a = ABS(Py_SIZE(a));
+	Py_ssize_t size_b = ABS(Py_SIZE(b));
 	Py_ssize_t i;
 
      	z = _PyLong_New(size_a + size_b);
 	if (z == NULL)
 		return NULL;
 
-	memset(z->ob_digit, 0, Py_Size(z) * sizeof(digit));
+	memset(z->ob_digit, 0, Py_SIZE(z) * sizeof(digit));
 	if (a == b) {
 		/* Efficient squaring per HAC, Algorithm 14.16:
 		 * http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf
@@ -2465,7 +2463,7 @@
 {
 	PyLongObject *hi, *lo;
 	Py_ssize_t size_lo, size_hi;
-	const Py_ssize_t size_n = ABS(Py_Size(n));
+	const Py_ssize_t size_n = ABS(Py_SIZE(n));
 
 	size_lo = MIN(size_n, size);
 	size_hi = size_n - size_lo;
@@ -2494,8 +2492,8 @@
 static PyLongObject *
 k_mul(PyLongObject *a, PyLongObject *b)
 {
-	Py_ssize_t asize = ABS(Py_Size(a));
-	Py_ssize_t bsize = ABS(Py_Size(b));
+	Py_ssize_t asize = ABS(Py_SIZE(a));
+	Py_ssize_t bsize = ABS(Py_SIZE(b));
 	PyLongObject *ah = NULL;
 	PyLongObject *al = NULL;
 	PyLongObject *bh = NULL;
@@ -2547,7 +2545,7 @@
 	/* Split a & b into hi & lo pieces. */
 	shift = bsize >> 1;
 	if (kmul_split(a, shift, &ah, &al) < 0) goto fail;
-	assert(Py_Size(ah) > 0);	/* the split isn't degenerate */
+	assert(Py_SIZE(ah) > 0);	/* the split isn't degenerate */
 
 	if (a == b) {
 		bh = ah;
@@ -2578,20 +2576,20 @@
 	if (ret == NULL) goto fail;
 #ifdef Py_DEBUG
 	/* Fill with trash, to catch reference to uninitialized digits. */
-	memset(ret->ob_digit, 0xDF, Py_Size(ret) * sizeof(digit));
+	memset(ret->ob_digit, 0xDF, Py_SIZE(ret) * sizeof(digit));
 #endif
 
 	/* 2. t1 <- ah*bh, and copy into high digits of result. */
 	if ((t1 = k_mul(ah, bh)) == NULL) goto fail;
-	assert(Py_Size(t1) >= 0);
-	assert(2*shift + Py_Size(t1) <= Py_Size(ret));
+	assert(Py_SIZE(t1) >= 0);
+	assert(2*shift + Py_SIZE(t1) <= Py_SIZE(ret));
 	memcpy(ret->ob_digit + 2*shift, t1->ob_digit,
-	       Py_Size(t1) * sizeof(digit));
+	       Py_SIZE(t1) * sizeof(digit));
 
 	/* Zero-out the digits higher than the ah*bh copy. */
-	i = Py_Size(ret) - 2*shift - Py_Size(t1);
+	i = Py_SIZE(ret) - 2*shift - Py_SIZE(t1);
 	if (i)
-		memset(ret->ob_digit + 2*shift + Py_Size(t1), 0,
+		memset(ret->ob_digit + 2*shift + Py_SIZE(t1), 0,
 		       i * sizeof(digit));
 
 	/* 3. t2 <- al*bl, and copy into the low digits. */
@@ -2599,23 +2597,23 @@
 		Py_DECREF(t1);
 		goto fail;
 	}
-	assert(Py_Size(t2) >= 0);
-	assert(Py_Size(t2) <= 2*shift); /* no overlap with high digits */
-	memcpy(ret->ob_digit, t2->ob_digit, Py_Size(t2) * sizeof(digit));
+	assert(Py_SIZE(t2) >= 0);
+	assert(Py_SIZE(t2) <= 2*shift); /* no overlap with high digits */
+	memcpy(ret->ob_digit, t2->ob_digit, Py_SIZE(t2) * sizeof(digit));
 
 	/* Zero out remaining digits. */
-	i = 2*shift - Py_Size(t2);	/* number of uninitialized digits */
+	i = 2*shift - Py_SIZE(t2);	/* number of uninitialized digits */
 	if (i)
-		memset(ret->ob_digit + Py_Size(t2), 0, i * sizeof(digit));
+		memset(ret->ob_digit + Py_SIZE(t2), 0, i * sizeof(digit));
 
 	/* 4 & 5. Subtract ah*bh (t1) and al*bl (t2).  We do al*bl first
 	 * because it's fresher in cache.
 	 */
-	i = Py_Size(ret) - shift;  /* # digits after shift */
-	(void)v_isub(ret->ob_digit + shift, i, t2->ob_digit, Py_Size(t2));
+	i = Py_SIZE(ret) - shift;  /* # digits after shift */
+	(void)v_isub(ret->ob_digit + shift, i, t2->ob_digit, Py_SIZE(t2));
 	Py_DECREF(t2);
 
-	(void)v_isub(ret->ob_digit + shift, i, t1->ob_digit, Py_Size(t1));
+	(void)v_isub(ret->ob_digit + shift, i, t1->ob_digit, Py_SIZE(t1));
 	Py_DECREF(t1);
 
 	/* 6. t3 <- (ah+al)(bh+bl), and add into result. */
@@ -2640,12 +2638,12 @@
 	Py_DECREF(t1);
 	Py_DECREF(t2);
 	if (t3 == NULL) goto fail;
-	assert(Py_Size(t3) >= 0);
+	assert(Py_SIZE(t3) >= 0);
 
 	/* Add t3.  It's not obvious why we can't run out of room here.
 	 * See the (*) comment after this function.
 	 */
-	(void)v_iadd(ret->ob_digit + shift, i, t3->ob_digit, Py_Size(t3));
+	(void)v_iadd(ret->ob_digit + shift, i, t3->ob_digit, Py_SIZE(t3));
 	Py_DECREF(t3);
 
 	return long_normalize(ret);
@@ -2715,8 +2713,8 @@
 static PyLongObject *
 k_lopsided_mul(PyLongObject *a, PyLongObject *b)
 {
-	const Py_ssize_t asize = ABS(Py_Size(a));
-	Py_ssize_t bsize = ABS(Py_Size(b));
+	const Py_ssize_t asize = ABS(Py_SIZE(a));
+	Py_ssize_t bsize = ABS(Py_SIZE(b));
 	Py_ssize_t nbdone;	/* # of b digits already multiplied */
 	PyLongObject *ret;
 	PyLongObject *bslice = NULL;
@@ -2728,7 +2726,7 @@
 	ret = _PyLong_New(asize + bsize);
 	if (ret == NULL)
 		return NULL;
-	memset(ret->ob_digit, 0, Py_Size(ret) * sizeof(digit));
+	memset(ret->ob_digit, 0, Py_SIZE(ret) * sizeof(digit));
 
 	/* Successive slices of b are copied into bslice. */
 	bslice = _PyLong_New(asize);
@@ -2743,14 +2741,14 @@
 		/* Multiply the next slice of b by a. */
 		memcpy(bslice->ob_digit, b->ob_digit + nbdone,
 		       nbtouse * sizeof(digit));
-		Py_Size(bslice) = nbtouse;
+		Py_SIZE(bslice) = nbtouse;
 		product = k_mul(a, bslice);
 		if (product == NULL)
 			goto fail;
 
 		/* Add into result. */
-		(void)v_iadd(ret->ob_digit + nbdone, Py_Size(ret) - nbdone,
-			     product->ob_digit, Py_Size(product));
+		(void)v_iadd(ret->ob_digit + nbdone, Py_SIZE(ret) - nbdone,
+			     product->ob_digit, Py_SIZE(product));
 		Py_DECREF(product);
 
 		bsize -= nbtouse;
@@ -2773,7 +2771,7 @@
 
 	CHECK_BINOP(a, b);
 
-	if (ABS(Py_Size(a)) <= 1 && ABS(Py_Size(b)) <= 1) {
+	if (ABS(Py_SIZE(a)) <= 1 && ABS(Py_SIZE(b)) <= 1) {
 		PyObject *r;
 		r = PyLong_FromLong(MEDIUM_VALUE(a)*MEDIUM_VALUE(b));
 		return r;
@@ -2781,7 +2779,7 @@
 
 	z = k_mul(a, b);
 	/* Negate if exactly one of the inputs is negative. */
-	if (((Py_Size(a) ^ Py_Size(b)) < 0) && z)
+	if (((Py_SIZE(a) ^ Py_SIZE(b)) < 0) && z)
 		NEGATE(z);
 	return (PyObject *)z;
 }
@@ -2815,8 +2813,8 @@
 
 	if (long_divrem(v, w, &div, &mod) < 0)
 		return -1;
-	if ((Py_Size(mod) < 0 && Py_Size(w) > 0) ||
-	    (Py_Size(mod) > 0 && Py_Size(w) < 0)) {
+	if ((Py_SIZE(mod) < 0 && Py_SIZE(w) > 0) ||
+	    (Py_SIZE(mod) > 0 && Py_SIZE(w) < 0)) {
 		PyLongObject *temp;
 		PyLongObject *one;
 		temp = (PyLongObject *) long_add(mod, w);
@@ -2974,7 +2972,7 @@
 		return Py_NotImplemented;
 	}
 
-	if (Py_Size(b) < 0) {  /* if exponent is negative */
+	if (Py_SIZE(b) < 0) {  /* if exponent is negative */
 		if (c) {
 			PyErr_SetString(PyExc_TypeError, "pow() 2nd argument "
 			    "cannot be negative when 3rd argument specified");
@@ -2993,7 +2991,7 @@
 	if (c) {
 		/* if modulus == 0:
 		       raise ValueError() */
-		if (Py_Size(c) == 0) {
+		if (Py_SIZE(c) == 0) {
 			PyErr_SetString(PyExc_ValueError,
 					"pow() 3rd argument cannot be 0");
 			goto Error;
@@ -3002,7 +3000,7 @@
 		/* if modulus < 0:
 		       negativeOutput = True
 		       modulus = -modulus */
-		if (Py_Size(c) < 0) {
+		if (Py_SIZE(c) < 0) {
 			negativeOutput = 1;
 			temp = (PyLongObject *)_PyLong_Copy(c);
 			if (temp == NULL)
@@ -3015,7 +3013,7 @@
 
 		/* if modulus == 1:
 		       return 0 */
-		if ((Py_Size(c) == 1) && (c->ob_digit[0] == 1)) {
+		if ((Py_SIZE(c) == 1) && (c->ob_digit[0] == 1)) {
 			z = (PyLongObject *)PyLong_FromLong(0L);
 			goto Done;
 		}
@@ -3023,7 +3021,7 @@
 		/* if base < 0:
 		       base = base % modulus
 		   Having the base positive just makes things easier. */
-		if (Py_Size(a) < 0) {
+		if (Py_SIZE(a) < 0) {
 			if (l_divmod(a, c, NULL, &temp) < 0)
 				goto Error;
 			Py_DECREF(a);
@@ -3064,10 +3062,10 @@
 	REDUCE(result)					\
 }
 
-	if (Py_Size(b) <= FIVEARY_CUTOFF) {
+	if (Py_SIZE(b) <= FIVEARY_CUTOFF) {
 		/* Left-to-right binary exponentiation (HAC Algorithm 14.79) */
 		/* http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf    */
-		for (i = Py_Size(b) - 1; i >= 0; --i) {
+		for (i = Py_SIZE(b) - 1; i >= 0; --i) {
 			digit bi = b->ob_digit[i];
 
 			for (j = 1 << (PyLong_SHIFT-1); j != 0; j >>= 1) {
@@ -3084,7 +3082,7 @@
 		for (i = 1; i < 32; ++i)
 			MULT(table[i-1], a, table[i])
 
-		for (i = Py_Size(b) - 1; i >= 0; --i) {
+		for (i = Py_SIZE(b) - 1; i >= 0; --i) {
 			const digit bi = b->ob_digit[i];
 
 			for (j = PyLong_SHIFT - 5; j >= 0; j -= 5) {
@@ -3097,7 +3095,7 @@
 		}
 	}
 
-	if (negativeOutput && (Py_Size(z) != 0)) {
+	if (negativeOutput && (Py_SIZE(z) != 0)) {
 		temp = (PyLongObject *)long_sub(z, c);
 		if (temp == NULL)
 			goto Error;
@@ -3114,7 +3112,7 @@
  	}
 	/* fall through */
  Done:
-	if (Py_Size(b) > FIVEARY_CUTOFF) {
+	if (Py_SIZE(b) > FIVEARY_CUTOFF) {
 		for (i = 0; i < 32; ++i)
 			Py_XDECREF(table[i]);
 	}
@@ -3131,7 +3129,7 @@
 	/* Implement ~x as -(x+1) */
 	PyLongObject *x;
 	PyLongObject *w;
-	if (ABS(Py_Size(v)) <=1)
+	if (ABS(Py_SIZE(v)) <=1)
 		return PyLong_FromLong(-(MEDIUM_VALUE(v)+1));
 	w = (PyLongObject *)PyLong_FromLong(1L);
 	if (w == NULL)
@@ -3140,7 +3138,7 @@
 	Py_DECREF(w);
 	if (x == NULL)
 		return NULL;
-	Py_Size(x) = -(Py_Size(x));
+	Py_SIZE(x) = -(Py_SIZE(x));
 	return (PyObject *)x;
 }
 
@@ -3148,18 +3146,18 @@
 long_neg(PyLongObject *v)
 {
 	PyLongObject *z;
-	if (ABS(Py_Size(v)) <= 1)
+	if (ABS(Py_SIZE(v)) <= 1)
 		return PyLong_FromLong(-MEDIUM_VALUE(v));
 	z = (PyLongObject *)_PyLong_Copy(v);
 	if (z != NULL)
-		Py_Size(z) = -(Py_Size(v));
+		Py_SIZE(z) = -(Py_SIZE(v));
 	return (PyObject *)z;
 }
 
 static PyObject *
 long_abs(PyLongObject *v)
 {
-	if (Py_Size(v) < 0)
+	if (Py_SIZE(v) < 0)
 		return long_neg(v);
 	else
 		return long_long((PyObject *)v);
@@ -3168,7 +3166,7 @@
 static int
 long_bool(PyLongObject *v)
 {
-	return ABS(Py_Size(v)) != 0;
+	return ABS(Py_SIZE(v)) != 0;
 }
 
 static PyObject *
@@ -3181,7 +3179,7 @@
 
 	CHECK_BINOP(a, b);
 
-	if (Py_Size(a) < 0) {
+	if (Py_SIZE(a) < 0) {
 		/* Right shifting negative numbers is harder */
 		PyLongObject *a1, *a2;
 		a1 = (PyLongObject *) long_invert(a);
@@ -3205,7 +3203,7 @@
 			goto rshift_error;
 		}
 		wordshift = shiftby / PyLong_SHIFT;
-		newsize = ABS(Py_Size(a)) - wordshift;
+		newsize = ABS(Py_SIZE(a)) - wordshift;
 		if (newsize <= 0) {
 			z = _PyLong_New(0);
 			return (PyObject *)z;
@@ -3217,8 +3215,8 @@
 		z = _PyLong_New(newsize);
 		if (z == NULL)
 			goto rshift_error;
-		if (Py_Size(a) < 0)
-			Py_Size(z) = -(Py_Size(z));
+		if (Py_SIZE(a) < 0)
+			Py_SIZE(z) = -(Py_SIZE(z));
 		for (i = 0, j = wordshift; i < newsize; i++, j++) {
 			z->ob_digit[i] = (a->ob_digit[j] >> loshift) & lomask;
 			if (i+1 < newsize)
@@ -3261,14 +3259,14 @@
 	wordshift = (int)shiftby / PyLong_SHIFT;
 	remshift  = (int)shiftby - wordshift * PyLong_SHIFT;
 
-	oldsize = ABS(Py_Size(a));
+	oldsize = ABS(Py_SIZE(a));
 	newsize = oldsize + wordshift;
 	if (remshift)
 		++newsize;
 	z = _PyLong_New(newsize);
 	if (z == NULL)
 		goto lshift_error;
-	if (Py_Size(a) < 0)
+	if (Py_SIZE(a) < 0)
 		NEGATE(z);
 	for (i = 0; i < wordshift; i++)
 		z->ob_digit[i] = 0;
@@ -3303,7 +3301,7 @@
 	digit diga, digb;
 	PyObject *v;
 
-	if (Py_Size(a) < 0) {
+	if (Py_SIZE(a) < 0) {
 		a = (PyLongObject *) long_invert(a);
 		if (a == NULL)
 			return NULL;
@@ -3313,7 +3311,7 @@
 		Py_INCREF(a);
 		maska = 0;
 	}
-	if (Py_Size(b) < 0) {
+	if (Py_SIZE(b) < 0) {
 		b = (PyLongObject *) long_invert(b);
 		if (b == NULL) {
 			Py_DECREF(a);
@@ -3362,8 +3360,8 @@
 	   whose length should be ignored.
 	*/
 
-	size_a = Py_Size(a);
-	size_b = Py_Size(b);
+	size_a = Py_SIZE(a);
+	size_b = Py_SIZE(b);
 	size_z = op == '&'
 		? (maska
 		   ? size_b
@@ -3462,14 +3460,22 @@
 		return PyLong_FromLong(0L);
 	if (base == -909)
 		return PyNumber_Long(x);
-	else if (PyBytes_Check(x)) {
+	else if (PyUnicode_Check(x))
+		return PyLong_FromUnicode(PyUnicode_AS_UNICODE(x),
+					  PyUnicode_GET_SIZE(x),
+					  base);
+	else if (PyBytes_Check(x) || PyString_Check(x)) {
 		/* Since PyLong_FromString doesn't have a length parameter,
 		 * check here for possible NULs in the string. */
-		char *string = PyBytes_AS_STRING(x);
-		int size = PyBytes_GET_SIZE(x);
+		char *string;
+		int size = Py_SIZE(x);
+		if (PyBytes_Check(x))
+			string = PyBytes_AS_STRING(x);
+		else
+			string = PyString_AS_STRING(x);
 		if (strlen(string) != size) {
 			/* We only see this if there's a null byte in x,
-			   x is a str8 or a bytes, *and* a base is given. */
+			   x is a bytes or buffer, *and* a base is given. */
 			PyErr_Format(PyExc_ValueError,
 			    "invalid literal for int() with base %d: %R",
 			    base, x);
@@ -3477,10 +3483,6 @@
 		}
 		return PyLong_FromString(string, NULL, base);
 	}
-	else if (PyUnicode_Check(x))
-		return PyLong_FromUnicode(PyUnicode_AS_UNICODE(x),
-					  PyUnicode_GET_SIZE(x),
-					  base);
 	else {
 		PyErr_SetString(PyExc_TypeError,
 			"int() can't convert non-string with explicit base");
@@ -3504,7 +3506,7 @@
 	if (tmp == NULL)
 		return NULL;
 	assert(PyLong_CheckExact(tmp));
-	n = Py_Size(tmp);
+	n = Py_SIZE(tmp);
 	if (n < 0)
 		n = -n;
 	newobj = (PyLongObject *)type->tp_alloc(type, n);
@@ -3513,7 +3515,7 @@
 		return NULL;
 	}
 	assert(PyLong_Check(newobj));
-	Py_Size(newobj) = Py_Size(tmp);
+	Py_SIZE(newobj) = Py_SIZE(tmp);
 	for (i = 0; i < n; i++)
 		newobj->ob_digit[i] = tmp->ob_digit[i];
 	Py_DECREF(tmp);
@@ -3528,7 +3530,7 @@
 
 static PyObject *
 long_getN(PyLongObject *v, void *context) {
-	return PyLong_FromLong((intptr_t)context);
+	return PyLong_FromLong((Py_intptr_t)context);
 }
 
 static PyObject *
@@ -3703,17 +3705,32 @@
 _PyLong_Init(void)
 {
 #if NSMALLNEGINTS + NSMALLPOSINTS > 0
-	int ival;
+	int ival, size;
 	PyLongObject *v = small_ints;
-	for (ival = -NSMALLNEGINTS; ival < 0; ival++, v++) {
-		PyObject_INIT(v, &PyLong_Type);
-		Py_Size(v) = -1;
-		v->ob_digit[0] = -ival;
-	}
-	for (; ival < NSMALLPOSINTS; ival++, v++) {
-		PyObject_INIT(v, &PyLong_Type);
-		Py_Size(v) = ival ? 1 : 0;
-		v->ob_digit[0] = ival;
+
+	for (ival = -NSMALLNEGINTS; ival <  NSMALLPOSINTS; ival++, v++) {
+		size = (ival < 0) ? -1 : ((ival == 0) ? 0 : 1);
+		if (Py_TYPE(v) == &PyLong_Type) {
+			/* The element is already initialized, most likely
+			 * the Python interpreter was initialized before.
+			 */
+			Py_ssize_t refcnt;
+			PyObject* op = (PyObject*)v;
+
+			refcnt = Py_REFCNT(op) < 0 ? 0 : Py_REFCNT(op);
+			_Py_NewReference(op);
+			/* _Py_NewReference sets the ref count to 1 but
+			 * the ref count might be larger. Set the refcnt
+			 * to the original refcnt + 1 */	 
+			Py_REFCNT(op) = refcnt + 1;
+			assert(Py_SIZE(op) == size);
+			assert(v->ob_digit[0] == abs(ival));
+		}
+		else {
+			PyObject_INIT(v, &PyLong_Type);
+		}
+		Py_SIZE(v) = size;
+		v->ob_digit[0] = abs(ival);
 	}
 #endif
 	return 1;
@@ -3722,19 +3739,15 @@
 void
 PyLong_Fini(void)
 {
-#if 0
-	int i;
-	/* This is currently not needed; the small integers
-	   are statically allocated */
+	/* Integers are currently statically allocated. Py_DECREF is not
+	   needed, but Python must forget about the reference or multiple
+	   reinitializations will fail. */
 #if NSMALLNEGINTS + NSMALLPOSINTS > 0
-        PyIntObject **q;
-
-        i = NSMALLNEGINTS + NSMALLPOSINTS;
-        q = small_ints;
-        while (--i >= 0) {
-                Py_XDECREF(*q);
-                *q++ = NULL;
-        }
-#endif
+	int i;
+	PyLongObject *v = small_ints;
+	for (i = 0; i < NSMALLNEGINTS + NSMALLPOSINTS; i++, v++) {
+		_Py_DEC_REFTOTAL;
+		_Py_ForgetReference((PyObject*)v);
+	}
 #endif
 }

Modified: python/branches/py3k-importlib/Objects/memoryobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/memoryobject.c	(original)
+++ python/branches/py3k-importlib/Objects/memoryobject.c	Thu Mar 27 00:48:05 2008
@@ -69,16 +69,21 @@
 static PyObject *
 memory_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
 {
-        PyObject *obj;
-        if (!PyArg_UnpackTuple(args, "memoryview", 1, 1, &obj)) return NULL;
+	PyObject *obj;
+	static char *kwlist[] = {"object", 0};
 
-        return PyMemoryView_FromObject(obj);
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:memoryview", kwlist,
+					 &obj)) {
+		return NULL;
+	}
+
+	return PyMemoryView_FromObject(obj);
 }
 
 
 static void
 _strided_copy_nd(char *dest, char *src, int nd, Py_ssize_t *shape,
-                 Py_ssize_t *strides, int itemsize, char fort)
+                 Py_ssize_t *strides, Py_ssize_t itemsize, char fort)
 {
         int k;
         Py_ssize_t outstride;
@@ -298,7 +303,7 @@
 static PyObject *
 memory_itemsize_get(PyMemoryViewObject *self)
 {
-        return PyInt_FromLong(self->view.itemsize);
+        return PyLong_FromSsize_t(self->view.itemsize);
 }
 
 static PyObject *
@@ -315,7 +320,7 @@
         intTuple = PyTuple_New(len);
         if (!intTuple) return NULL;
         for(i=0; i<len; i++) {
-                o = PyInt_FromSsize_t(vals[i]);
+                o = PyLong_FromSsize_t(vals[i]);
                 if (!o) {
                         Py_DECREF(intTuple);
                         return NULL;
@@ -346,7 +351,7 @@
 static PyObject *
 memory_size_get(PyMemoryViewObject *self)
 {
-        return PyInt_FromSsize_t(self->view.len);
+        return PyLong_FromSsize_t(self->view.len);
 }
 
 static PyObject *
@@ -358,7 +363,7 @@
 static PyObject *
 memory_ndim_get(PyMemoryViewObject *self)
 {
-        return PyInt_FromLong(self->view.ndim);
+        return PyLong_FromLong(self->view.ndim);
 }
 
 static PyGetSetDef memory_getsetlist[] ={

Modified: python/branches/py3k-importlib/Objects/methodobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/methodobject.c	(original)
+++ python/branches/py3k-importlib/Objects/methodobject.c	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,14 @@
 #include "Python.h"
 #include "structmember.h"
 
+/* Free list for method objects to safe malloc/free overhead
+ * The m_self element is used to chain the objects.
+ */
 static PyCFunctionObject *free_list = NULL;
+static int numfree = 0;
+#ifndef PyCFunction_MAXFREELIST
+#define PyCFunction_MAXFREELIST 256
+#endif
 
 PyObject *
 PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
@@ -14,6 +21,7 @@
 	if (op != NULL) {
 		free_list = (PyCFunctionObject *)(op->m_self);
 		PyObject_INIT(op, &PyCFunction_Type);
+		numfree--;
 	}
 	else {
 		op = PyObject_GC_New(PyCFunctionObject, &PyCFunction_Type);
@@ -116,8 +124,14 @@
 	_PyObject_GC_UNTRACK(m);
 	Py_XDECREF(m->m_self);
 	Py_XDECREF(m->m_module);
-	m->m_self = (PyObject *)free_list;
-	free_list = m;
+	if (numfree < PyCFunction_MAXFREELIST) {
+		m->m_self = (PyObject *)free_list;
+		free_list = m;
+		numfree++;
+	}
+	else {
+		PyObject_GC_Del(m);
+	}
 }
 
 static PyObject *
@@ -167,7 +181,7 @@
 #define OFF(x) offsetof(PyCFunctionObject, x)
 
 static PyMemberDef meth_members[] = {
-	{"__module__",    T_OBJECT,     OFF(m_module), WRITE_RESTRICTED},
+	{"__module__",    T_OBJECT,     OFF(m_module), PY_WRITE_RESTRICTED},
 	{NULL}
 };
 
@@ -305,21 +319,32 @@
 
 /* Clear out the free list */
 
-void
-PyCFunction_Fini(void)
+int
+PyCFunction_ClearFreeList(void)
 {
+	int freelist_size = numfree;
+	
 	while (free_list) {
 		PyCFunctionObject *v = free_list;
 		free_list = (PyCFunctionObject *)(v->m_self);
 		PyObject_GC_Del(v);
+		numfree--;
 	}
+	assert(numfree == 0);
+	return freelist_size;
+}
+
+void
+PyCFunction_Fini(void)
+{
+	(void)PyCFunction_ClearFreeList();
 }
 
 /* PyCFunction_New() is now just a macro that calls PyCFunction_NewEx(),
    but it's part of the API so we need to keep a function around that
    existing C extensions can call.
 */
-   
+
 #undef PyCFunction_New
 PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);
 

Modified: python/branches/py3k-importlib/Objects/moduleobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/moduleobject.c	(original)
+++ python/branches/py3k-importlib/Objects/moduleobject.c	Thu Mar 27 00:48:05 2008
@@ -30,6 +30,8 @@
 		goto fail;
 	if (PyDict_SetItemString(m->md_dict, "__doc__", Py_None) != 0)
 		goto fail;
+	if (PyDict_SetItemString(m->md_dict, "__package__", Py_None) != 0)
+		goto fail;
 	Py_DECREF(nameobj);
 	PyObject_GC_Track(m);
 	return (PyObject *)m;
@@ -151,7 +153,7 @@
 {
 	static char *kwlist[] = {"name", "doc", NULL};
 	PyObject *dict, *name = Py_None, *doc = Py_None;
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, "S|O:module.__init__",
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "U|O:module.__init__",
                                          kwlist, &name, &doc))
 		return -1;
 	dict = m->md_dict;
@@ -176,7 +178,7 @@
 		_PyModule_Clear((PyObject *)m);
 		Py_DECREF(m->md_dict);
 	}
-	Py_Type(m)->tp_free((PyObject *)m);
+	Py_TYPE(m)->tp_free((PyObject *)m);
 }
 
 static PyObject *

Modified: python/branches/py3k-importlib/Objects/object.c
==============================================================================
--- python/branches/py3k-importlib/Objects/object.c	(original)
+++ python/branches/py3k-importlib/Objects/object.c	Thu Mar 27 00:48:05 2008
@@ -214,7 +214,7 @@
 	if (op == NULL)
 		return PyErr_NoMemory();
 	/* Any changes should be reflected in PyObject_INIT (objimpl.h) */
-	Py_Type(op) = tp;
+	Py_TYPE(op) = tp;
 	_Py_NewReference(op);
 	return op;
 }
@@ -226,7 +226,7 @@
 		return (PyVarObject *) PyErr_NoMemory();
 	/* Any changes should be reflected in PyObject_INIT_VAR */
 	op->ob_size = size;
-	Py_Type(op) = tp;
+	Py_TYPE(op) = tp;
 	_Py_NewReference((PyObject *)op);
 	return op;
 }
@@ -352,7 +352,7 @@
 			"type    : %s\n"
 			"refcount: %ld\n"
 			"address : %p\n",
-			Py_Type(op)==NULL ? "NULL" : Py_Type(op)->tp_name,
+			Py_TYPE(op)==NULL ? "NULL" : Py_TYPE(op)->tp_name,
 			(long)op->ob_refcnt,
 			op);
 	}
@@ -372,144 +372,55 @@
 #endif
 	if (v == NULL)
 		return PyUnicode_FromString("<NULL>");
-	else if (Py_Type(v)->tp_repr == NULL)
-		return PyUnicode_FromFormat("<%s object at %p>", v->ob_type->tp_name, v);
-	else {
-		res = (*v->ob_type->tp_repr)(v);
-		if (res != NULL && !PyUnicode_Check(res)) {
-			PyErr_Format(PyExc_TypeError,
-				     "__repr__ returned non-string (type %.200s)",
-				     res->ob_type->tp_name);
-			Py_DECREF(res);
-			return NULL;
-		}
-		return res;
-	}
-}
-
-PyObject *
-PyObject_ReprStr8(PyObject *v)
-{
-	PyObject *resu = PyObject_Repr(v);
-	if (resu) {
-		PyObject *resb = PyUnicode_AsEncodedString(resu, NULL, NULL);
-		Py_DECREF(resu);
-		if (resb) {
-			PyObject *ress = PyString_FromStringAndSize(
-				PyBytes_AS_STRING(resb),
-				PyBytes_GET_SIZE(resb)
-			);
-			Py_DECREF(resb);
-			return ress;
-		}
-	}
-	return NULL;
-}
-
-PyObject *
-_PyObject_Str(PyObject *v)
-{
-	PyObject *res;
-	if (v == NULL)
-		return PyUnicode_FromString("<NULL>");
-	if (PyString_CheckExact(v)) {
-		Py_INCREF(v);
-		return v;
-	}
-	if (PyUnicode_CheckExact(v)) {
-		Py_INCREF(v);
-		return v;
-	}
-	if (Py_Type(v)->tp_str == NULL)
-		return PyObject_Repr(v);
-
-	res = (*Py_Type(v)->tp_str)(v);
-	if (res == NULL)
-		return NULL;
-	if (!(PyString_Check(res) || PyUnicode_Check(res))) {
+	if (Py_TYPE(v)->tp_repr == NULL)
+		return PyUnicode_FromFormat("<%s object at %p>",
+                                            v->ob_type->tp_name, v);
+        res = (*v->ob_type->tp_repr)(v);
+        if (res != NULL && !PyUnicode_Check(res)) {
 		PyErr_Format(PyExc_TypeError,
-			     "__str__ returned non-string (type %.200s)",
-			     Py_Type(res)->tp_name);
+			     "__repr__ returned non-string (type %.200s)",
+			     res->ob_type->tp_name);
 		Py_DECREF(res);
 		return NULL;
-	}
-	return res;
+        }
+        return res;
 }
 
 PyObject *
 PyObject_Str(PyObject *v)
 {
-	PyObject *res = _PyObject_Str(v);
-	if (res == NULL)
+	PyObject *res;
+	if (PyErr_CheckSignals())
+		return NULL;
+#ifdef USE_STACKCHECK
+	if (PyOS_CheckStack()) {
+		PyErr_SetString(PyExc_MemoryError, "stack overflow");
 		return NULL;
-	if (PyUnicode_Check(res)) {
-		PyObject* str;
-		str = _PyUnicode_AsDefaultEncodedString(res, NULL);
-		Py_XINCREF(str);
-		Py_DECREF(res);
-		if (str)
-			res = str;
-		else
-		    	return NULL;
 	}
-	assert(PyString_Check(res));
-	return res;
-}
-
-PyObject *
-PyObject_Unicode(PyObject *v)
-{
-	PyObject *res;
-	PyObject *func;
-	PyObject *str;
-	static PyObject *unicodestr;
-
+#endif
 	if (v == NULL)
 		return PyUnicode_FromString("<NULL>");
-	else if (PyUnicode_CheckExact(v)) {
+	if (PyUnicode_CheckExact(v)) {
 		Py_INCREF(v);
 		return v;
 	}
-	/* XXX As soon as we have a tp_unicode slot, we should
-	   check this before trying the __unicode__
-	   method. */
-	if (unicodestr == NULL) {
-		unicodestr= PyUnicode_InternFromString("__unicode__");
-		if (unicodestr == NULL)
-			return NULL;
-	}
-	func = PyObject_GetAttr(v, unicodestr);
-	if (func != NULL) {
-		res = PyEval_CallObject(func, (PyObject *)NULL);
-		Py_DECREF(func);
-	}
-	else {
-		PyErr_Clear();
-		if (PyUnicode_Check(v) &&
-		    v->ob_type->tp_str == PyUnicode_Type.tp_str) {
-			/* For a Unicode subtype that's didn't overwrite
-			   __unicode__ or __str__,
-			   return a true Unicode object with the same data. */
-			return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(v),
-			                             PyUnicode_GET_SIZE(v));
-		}
-		if (PyString_CheckExact(v)) {
-			Py_INCREF(v);
-			res = v;
-		}
-		else {
-			if (Py_Type(v)->tp_str != NULL)
-				res = (*Py_Type(v)->tp_str)(v);
-			else
-				res = PyObject_Repr(v);
-		}
-	}
+	if (Py_TYPE(v)->tp_str == NULL)
+		return PyObject_Repr(v);
+
+	/* It is possible for a type to have a tp_str representation that loops
+	   infinitely. */
+	if (Py_EnterRecursiveCall(" while getting the str of an object"))
+		return NULL;
+	res = (*Py_TYPE(v)->tp_str)(v);
+	Py_LeaveRecursiveCall();
 	if (res == NULL)
 		return NULL;
 	if (!PyUnicode_Check(res)) {
-		str = PyUnicode_FromEncodedObject(res, NULL, "strict");
+		PyErr_Format(PyExc_TypeError,
+			     "__str__ returned non-string (type %.200s)",
+			     Py_TYPE(res)->tp_name);
 		Py_DECREF(res);
-		res = str;
+		return NULL;
 	}
 	return res;
 }
@@ -519,7 +430,7 @@
    comparison from rich comparison.  That is, PyObject_Compare() and
    PyObject_Cmp() *just* use the tp_compare slot.  And PyObject_RichCompare()
    and PyObject_RichCompareBool() *just* use the tp_richcompare slot.
-   
+
    See (*) below for practical amendments.
 
    IOW, only cmp() uses tp_compare; the comparison operators (==, !=, <=, <,
@@ -575,7 +486,7 @@
 	cmpfunc f;
 	int ok;
 
-	if (v->ob_type == w->ob_type && 
+	if (v->ob_type == w->ob_type &&
 	    (f = v->ob_type->tp_compare) != NULL) {
 		return (*f)(v, w);
 	}
@@ -733,25 +644,25 @@
 		return NULL;
 	switch (op) {
 	case Py_LT:
-		ok = cmp <  0; 
+		ok = cmp <  0;
 		break;
 	case Py_LE:
-		ok = cmp <= 0; 
+		ok = cmp <= 0;
 		break;
 	case Py_EQ:
-		ok = cmp == 0; 
+		ok = cmp == 0;
 		break;
 	case Py_NE:
-		ok = cmp != 0; 
+		ok = cmp != 0;
 		break;
-	case Py_GT: 
-		ok = cmp >  0; 
+	case Py_GT:
+		ok = cmp >  0;
 		break;
 	case Py_GE:
-		ok = cmp >= 0; 
+		ok = cmp >= 0;
 		break;
 	default:
-		PyErr_BadArgument(); 
+		PyErr_BadArgument();
 		return NULL;
 	}
 	res = ok ? Py_True : Py_False;
@@ -861,8 +772,8 @@
 {
 	PyObject *w, *res;
 
-	if (Py_Type(v)->tp_getattr != NULL)
-		return (*Py_Type(v)->tp_getattr)(v, (char*)name);
+	if (Py_TYPE(v)->tp_getattr != NULL)
+		return (*Py_TYPE(v)->tp_getattr)(v, (char*)name);
 	w = PyUnicode_InternFromString(name);
 	if (w == NULL)
 		return NULL;
@@ -889,8 +800,8 @@
 	PyObject *s;
 	int res;
 
-	if (Py_Type(v)->tp_setattr != NULL)
-		return (*Py_Type(v)->tp_setattr)(v, (char*)name, w);
+	if (Py_TYPE(v)->tp_setattr != NULL)
+		return (*Py_TYPE(v)->tp_setattr)(v, (char*)name, w);
 	s = PyUnicode_InternFromString(name);
 	if (s == NULL)
 		return -1;
@@ -902,7 +813,7 @@
 PyObject *
 PyObject_GetAttr(PyObject *v, PyObject *name)
 {
-	PyTypeObject *tp = Py_Type(v);
+	PyTypeObject *tp = Py_TYPE(v);
 
  	if (!PyUnicode_Check(name)) {
 		PyErr_Format(PyExc_TypeError,
@@ -935,7 +846,7 @@
 int
 PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
 {
-	PyTypeObject *tp = Py_Type(v);
+	PyTypeObject *tp = Py_TYPE(v);
 	int err;
 
 	if (!PyUnicode_Check(name)) {
@@ -982,7 +893,7 @@
 _PyObject_GetDictPtr(PyObject *obj)
 {
 	Py_ssize_t dictoffset;
-	PyTypeObject *tp = Py_Type(obj);
+	PyTypeObject *tp = Py_TYPE(obj);
 
 	dictoffset = tp->tp_dictoffset;
 	if (dictoffset == 0)
@@ -1015,7 +926,7 @@
 PyObject *
 PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
 {
-	PyTypeObject *tp = Py_Type(obj);
+	PyTypeObject *tp = Py_TYPE(obj);
 	PyObject *descr = NULL;
 	PyObject *res = NULL;
 	descrgetfunc f;
@@ -1036,6 +947,7 @@
 			goto done;
 	}
 
+#if 0 /* XXX this is not quite _PyType_Lookup anymore */
 	/* Inline _PyType_Lookup */
 	{
 		Py_ssize_t i, n;
@@ -1056,6 +968,9 @@
 				break;
 		}
 	}
+#else
+	descr = _PyType_Lookup(tp, name);
+#endif
 
 	Py_XINCREF(descr);
 
@@ -1089,17 +1004,20 @@
 		dictptr = (PyObject **) ((char *)obj + dictoffset);
 		dict = *dictptr;
 		if (dict != NULL) {
+			Py_INCREF(dict);
 			res = PyDict_GetItem(dict, name);
 			if (res != NULL) {
 				Py_INCREF(res);
 				Py_XDECREF(descr);
+                                Py_DECREF(dict);
 				goto done;
 			}
+                        Py_DECREF(dict);
 		}
 	}
 
 	if (f != NULL) {
-		res = f(descr, obj, (PyObject *)Py_Type(obj));
+		res = f(descr, obj, (PyObject *)Py_TYPE(obj));
 		Py_DECREF(descr);
 		goto done;
 	}
@@ -1121,7 +1039,7 @@
 int
 PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
 {
-	PyTypeObject *tp = Py_Type(obj);
+	PyTypeObject *tp = Py_TYPE(obj);
 	PyObject *descr;
 	descrsetfunc f;
 	PyObject **dictptr;
@@ -1161,12 +1079,14 @@
 			*dictptr = dict;
 		}
 		if (dict != NULL) {
+			Py_INCREF(dict);
 			if (value == NULL)
 				res = PyDict_DelItem(dict, name);
 			else
 				res = PyDict_SetItem(dict, name, value);
 			if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
 				PyErr_SetObject(PyExc_AttributeError, name);
+			Py_DECREF(dict);
 			goto done;
 		}
 	}
@@ -1321,7 +1241,7 @@
 	if (!PyList_Check(names)) {
 		PyErr_Format(PyExc_TypeError,
 			"dir(): expected keys() of locals to be a list, "
-			"not '%.200s'", Py_Type(names)->tp_name);
+			"not '%.200s'", Py_TYPE(names)->tp_name);
 		Py_DECREF(names);
 		return NULL;
 	}
@@ -1330,10 +1250,10 @@
 }
 
 /* Helper for PyObject_Dir of type objects: returns __dict__ and __bases__.
-   We deliberately don't suck up its __class__, as methods belonging to the 
-   metaclass would probably be more confusing than helpful. 
+   We deliberately don't suck up its __class__, as methods belonging to the
+   metaclass would probably be more confusing than helpful.
 */
-static PyObject * 
+static PyObject *
 _specialized_dir_type(PyObject *obj)
 {
 	PyObject *result = NULL;
@@ -1376,7 +1296,7 @@
 	PyObject *result = NULL;
 	PyObject *dict = NULL;
 	PyObject *itsclass = NULL;
-	
+
 	/* Get __dict__ (which may or may not be a real dict...) */
 	dict = PyObject_GetAttrString(obj, "__dict__");
 	if (dict == NULL) {
@@ -1449,7 +1369,7 @@
 		if (!PyList_Check(result)) {
 			PyErr_Format(PyExc_TypeError,
 				     "__dir__() must return a list, not %.200s",
-				     Py_Type(result)->tp_name);
+				     Py_TYPE(result)->tp_name);
 			Py_DECREF(result);
 			result = NULL;
 		}
@@ -1481,7 +1401,7 @@
 		Py_DECREF(result);
 		result = NULL;
 	}
-	
+
 	return result;
 }
 
@@ -1595,6 +1515,9 @@
 
 	if (PyType_Ready(&PyCode_Type) < 0)
 		Py_FatalError("Can't initialize 'code'");
+
+	if (PyType_Ready(&PyStdPrinter_Type) < 0)
+		Py_FatalError("Can't initialize StdPrinter");
 }
 
 
@@ -1618,8 +1541,15 @@
 	if (op->ob_refcnt < 0)
 		Py_FatalError("UNREF negative refcnt");
 	if (op == &refchain ||
-	    op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != op)
+	    op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != op) {
+		fprintf(stderr, "* ob\n");
+		_PyObject_Dump(op);
+		fprintf(stderr, "* op->_ob_prev->_ob_next\n");
+		_PyObject_Dump(op->_ob_prev->_ob_next);
+		fprintf(stderr, "* op->_ob_next->_ob_prev\n");
+		_PyObject_Dump(op->_ob_next->_ob_prev);
 		Py_FatalError("UNREF invalid object");
+	}
 #ifdef SLOW_UNREF_CHECK
 	for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) {
 		if (p == op)
@@ -1637,7 +1567,7 @@
 void
 _Py_Dealloc(PyObject *op)
 {
-	destructor dealloc = Py_Type(op)->tp_dealloc;
+	destructor dealloc = Py_TYPE(op)->tp_dealloc;
 	_Py_ForgetReference(op);
 	(*dealloc)(op);
 }
@@ -1668,7 +1598,7 @@
 	fprintf(fp, "Remaining object addresses:\n");
 	for (op = refchain._ob_next; op != &refchain; op = op->_ob_next)
 		fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] %s\n", op,
-			op->ob_refcnt, Py_Type(op)->tp_name);
+			op->ob_refcnt, Py_TYPE(op)->tp_name);
 }
 
 PyObject *
@@ -1686,7 +1616,7 @@
 		return NULL;
 	for (i = 0; (n == 0 || i < n) && op != &refchain; i++) {
 		while (op == self || op == args || op == res || op == t ||
-		       (t != NULL && Py_Type(op) != (PyTypeObject *) t)) {
+		       (t != NULL && Py_TYPE(op) != (PyTypeObject *) t)) {
 			op = op->_ob_next;
 			if (op == &refchain)
 				return res;
@@ -1829,7 +1759,7 @@
 {
 	while (_PyTrash_delete_later) {
 		PyObject *op = _PyTrash_delete_later;
-		destructor dealloc = Py_Type(op)->tp_dealloc;
+		destructor dealloc = Py_TYPE(op)->tp_dealloc;
 
 		_PyTrash_delete_later =
 			(PyObject*) _Py_AS_GC(op)->gc.gc_prev;

Modified: python/branches/py3k-importlib/Objects/rangeobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/rangeobject.c	(original)
+++ python/branches/py3k-importlib/Objects/rangeobject.c	Thu Mar 27 00:48:05 2008
@@ -24,7 +24,7 @@
 {
     /* No step specified, use a step of 1. */
     if (!step)
-        return PyInt_FromLong(1);
+        return PyLong_FromLong(1);
 
     step = PyNumber_Index(step);
     if (step) {
@@ -63,8 +63,8 @@
         stop = PyNumber_Index(stop);
         if (!stop)
             goto Fail;
-        start = PyInt_FromLong(0);
-        step = PyInt_FromLong(1);
+        start = PyLong_FromLong(0);
+        step = PyLong_FromLong(1);
         if (!start || !step)
             goto Fail;
     }
@@ -107,12 +107,13 @@
     Py_DECREF(r->start);
     Py_DECREF(r->stop);
     Py_DECREF(r->step);
+    PyObject_Del(r);
 }
 
 /* Return number of items in range (lo, hi, step), when arguments are
  * PyInt or PyLong objects.  step > 0 required.  Return a value < 0 if
  * & only if the true value is too large to fit in a signed long.
- * Arguments MUST return 1 with either PyInt_Check() or
+ * Arguments MUST return 1 with either PyLong_Check() or
  * PyLong_Check().  Return -1 when there is an error.
  */
 static PyObject*
@@ -219,7 +220,7 @@
         }
 
     /* XXX(nnorwitz): optimize for short ints. */
-    rem = PyLong_FromSsize_t(i % len);
+    rem = PyLong_FromSsize_t(i);
     if (!rem)
         return NULL;
     incr = PyNumber_Multiply(rem, r->step);
@@ -331,14 +332,14 @@
 rangeiter_next(rangeiterobject *r)
 {
     if (r->index < r->len)
-        return PyInt_FromLong(r->start + (r->index++) * r->step);
+        return PyLong_FromLong(r->start + (r->index++) * r->step);
     return NULL;
 }
 
 static PyObject *
 rangeiter_len(rangeiterobject *r)
 {
-    return PyInt_FromLong(r->len - r->index);
+    return PyLong_FromLong(r->len - r->index);
 }
 
 typedef struct {
@@ -366,9 +367,9 @@
     {NULL,		NULL}		/* sentinel */
 };
 
-PyTypeObject Pyrangeiter_Type = {
+PyTypeObject PyRangeIter_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rangeiterator",                        /* tp_name */
+	"range_iterator",                        /* tp_name */
 	sizeof(rangeiterobject),                /* tp_basicsize */
 	0,                                      /* tp_itemsize */
 	/* methods */
@@ -440,7 +441,7 @@
 static PyObject *
 int_range_iter(long start, long stop, long step)
 {
-    rangeiterobject *it = PyObject_New(rangeiterobject, &Pyrangeiter_Type);
+    rangeiterobject *it = PyObject_New(rangeiterobject, &PyRangeIter_Type);
     if (it == NULL)
         return NULL;
     it->start = start;
@@ -481,6 +482,7 @@
     Py_XDECREF(r->start);
     Py_XDECREF(r->step);
     Py_XDECREF(r->len);
+    PyObject_Del(r);
 }
 
 static PyObject *
@@ -517,9 +519,9 @@
     return result;
 }
 
-static PyTypeObject Pylongrangeiter_Type = {
+PyTypeObject PyLongRangeIter_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"rangeiterator",                        /* tp_name */
+	"longrange_iterator",                   /* tp_name */
 	sizeof(longrangeiterobject),            /* tp_basicsize */
 	0,                                      /* tp_itemsize */
 	/* methods */
@@ -556,16 +558,25 @@
     rangeobject *r = (rangeobject *)seq;
     longrangeiterobject *it;
     PyObject *tmp, *len;
+    long lstart, lstop, lstep;
 
     assert(PyRange_Check(seq));
-    if (_PyLong_FitsInLong(r->start) &&
-        _PyLong_FitsInLong(r->stop) &&
-        _PyLong_FitsInLong(r->step))
-        return int_range_iter(PyLong_AsLong(r->start),
-                      PyLong_AsLong(r->stop),
-                      PyLong_AsLong(r->step));
 
-    it = PyObject_New(longrangeiterobject, &Pylongrangeiter_Type);
+    /* If all three fields convert to long, use the int version */
+    lstart = PyLong_AsLong(r->start);
+    if (lstart != -1 || !PyErr_Occurred()) {
+	lstop = PyLong_AsLong(r->stop);
+	if (lstop != -1 || !PyErr_Occurred()) {
+	    lstep = PyLong_AsLong(r->step);
+	    if (lstep != -1 || !PyErr_Occurred())
+		return int_range_iter(lstart, lstop, lstep);
+	}
+    }
+    /* Some conversion failed, so there is an error set. Clear it,
+       and try again with a long range. */
+    PyErr_Clear();
+
+    it = PyObject_New(longrangeiterobject, &PyLongRangeIter_Type);
     if (it == NULL)
         return NULL;
 
@@ -603,29 +614,35 @@
     rangeobject *range = (rangeobject*) seq;
     longrangeiterobject *it;
     PyObject *one, *sum, *diff, *len = NULL, *product;
+    long lstart, lstop, lstep;
 
     /* XXX(nnorwitz): do the calc for the new start/stop first,
         then if they fit, call the proper iter()?
     */
     assert(PyRange_Check(seq));
-    if (_PyLong_FitsInLong(range->start) &&
-        _PyLong_FitsInLong(range->stop) &&
-        _PyLong_FitsInLong(range->step)) {
-        long start = PyLong_AsLong(range->start);
-        long step = PyLong_AsLong(range->step);
-        long stop = PyLong_AsLong(range->stop);
-        /* XXX(nnorwitz): need to check for overflow and simplify. */
-        long len = get_len_of_range(start, stop, step);
-        long new_start = start + (len - 1) * step;
-        long new_stop = start;
-        if (step > 0)
-            new_stop -= 1;
-        else
-            new_stop += 1;
-        return int_range_iter(new_start, new_stop, -step);
+
+    /* If all three fields convert to long, use the int version */
+    lstart = PyLong_AsLong(range->start);
+    if (lstart != -1 || !PyErr_Occurred()) {
+	lstop = PyLong_AsLong(range->stop);
+	if (lstop != -1 || !PyErr_Occurred()) {
+	    lstep = PyLong_AsLong(range->step);
+	    if (lstep != -1 || !PyErr_Occurred()) {
+		/* XXX(nnorwitz): need to check for overflow and simplify. */
+		long len = get_len_of_range(lstart, lstop, lstep);
+		long new_start = lstart + (len - 1) * lstep;
+		long new_stop = lstart;
+		if (lstep > 0)
+		    new_stop -= 1;
+		else
+		    new_stop += 1;
+		return int_range_iter(new_start, new_stop, -lstep);
+	    }
+	}
     }
+    PyErr_Clear();
 
-    it = PyObject_New(longrangeiterobject, &Pylongrangeiter_Type);
+    it = PyObject_New(longrangeiterobject, &PyLongRangeIter_Type);
     if (it == NULL)
         return NULL;
 

Modified: python/branches/py3k-importlib/Objects/setobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/setobject.c	(original)
+++ python/branches/py3k-importlib/Objects/setobject.c	Thu Mar 27 00:48:05 2008
@@ -9,6 +9,7 @@
 
 #include "Python.h"
 #include "structmember.h"
+#include "stringlib/eq.h"
 
 /* Set a key error with the specified argument, wrapping it in a
  * tuple automatically so that tuple keys are not unpacked as the
@@ -51,9 +52,12 @@
     } while(0)
 
 /* Reuse scheme to save calls to malloc, free, and memset */
-#define MAXFREESETS 80
-static PySetObject *free_sets[MAXFREESETS];
-static int num_free_sets = 0;
+#ifndef PySet_MAXFREELIST
+#define PySet_MAXFREELIST 80
+#endif
+static PySetObject *free_list[PySet_MAXFREELIST];
+static int numfree = 0;
+
 
 /*
 The basic lookup function used by all operations.
@@ -144,12 +148,12 @@
 }
 
 /*
- * Hacked up version of set_lookkey which can assume keys are always strings;
- * This means we can always use _PyString_Eq directly and not have to check to
+ * Hacked up version of set_lookkey which can assume keys are always unicode;
+ * This means we can always use unicode_eq directly and not have to check to
  * see if the comparison altered the table.
  */
 static setentry *
-set_lookkey_string(PySetObject *so, PyObject *key, register long hash)
+set_lookkey_unicode(PySetObject *so, PyObject *key, register long hash)
 {
 	register Py_ssize_t i;
 	register size_t perturb;
@@ -158,11 +162,11 @@
 	setentry *table = so->table;
 	register setentry *entry;
 
-	/* Make sure this function doesn't have to handle non-string keys,
+	/* Make sure this function doesn't have to handle non-unicode keys,
 	   including subclasses of str; e.g., one reason to subclass
 	   strings is to override __eq__, and for speed we don't cater to
 	   that here. */
-	if (!PyString_CheckExact(key)) {
+	if (!PyUnicode_CheckExact(key)) {
 		so->lookup = set_lookkey;
 		return set_lookkey(so, key, hash);
 	}
@@ -173,7 +177,7 @@
 	if (entry->key == dummy)
 		freeslot = entry;
 	else {
-		if (entry->hash == hash && _PyString_Eq(entry->key, key))
+		if (entry->hash == hash && unicode_eq(entry->key, key))
 			return entry;
 		freeslot = NULL;
 	}
@@ -188,7 +192,7 @@
 		if (entry->key == key
 		    || (entry->hash == hash
 			&& entry->key != dummy
-			&& _PyString_Eq(entry->key, key)))
+			&& unicode_eq(entry->key, key)))
 			return entry;
 		if (entry->key == dummy && freeslot == NULL)
 			freeslot = entry;
@@ -375,8 +379,8 @@
 	register long hash;
 	register Py_ssize_t n_used;
 
-	if (!PyString_CheckExact(key) ||
-	    (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+	if (!PyUnicode_CheckExact(key) ||
+	    (hash = ((PyUnicodeObject *) key)->hash) == -1) {
 		hash = PyObject_Hash(key);
 		if (hash == -1)
 			return -1;
@@ -422,8 +426,9 @@
 	PyObject *old_key;
 
 	assert (PyAnySet_Check(so));
-	if (!PyString_CheckExact(key) ||
-	    (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+
+	if (!PyUnicode_CheckExact(key) ||
+	    (hash = ((PyUnicodeObject *) key)->hash) == -1) {
 		hash = PyObject_Hash(key);
 		if (hash == -1)
 			return -1;
@@ -558,10 +563,10 @@
 	}
 	if (so->table != so->smalltable)
 		PyMem_DEL(so->table);
-	if (num_free_sets < MAXFREESETS && PyAnySet_CheckExact(so))
-		free_sets[num_free_sets++] = so;
+	if (numfree < PySet_MAXFREELIST && PyAnySet_CheckExact(so))
+		free_list[numfree++] = so;
 	else 
-		Py_Type(so)->tp_free(so);
+		Py_TYPE(so)->tp_free(so);
 	Py_TRASHCAN_SAFE_END(so)
 }
 
@@ -577,13 +582,13 @@
 	if (status != 0) {
 		if (status < 0)
 			return NULL;
-		return PyUnicode_FromFormat("%s(...)", Py_Type(so)->tp_name);
+		return PyUnicode_FromFormat("%s(...)", Py_TYPE(so)->tp_name);
 	}
 
 	/* shortcut for the empty set */
 	if (!so->used) {
 		Py_ReprLeave((PyObject*)so);
-		return PyUnicode_FromFormat("%s()", Py_Type(so)->tp_name);
+		return PyUnicode_FromFormat("%s()", Py_TYPE(so)->tp_name);
 	}
 
 	keys = PySequence_List((PyObject *)so);
@@ -608,9 +613,9 @@
 		*u++ = '}';
 	}
 	Py_DECREF(listrepr);
-	if (Py_Type(so) != &PySet_Type) {
+	if (Py_TYPE(so) != &PySet_Type) {
 		PyObject *tmp = PyUnicode_FromFormat("%s(%U)",
-						     Py_Type(so)->tp_name,
+						     Py_TYPE(so)->tp_name,
 						     result);
 		Py_DECREF(result);
 		result = tmp;
@@ -668,8 +673,8 @@
 	long hash;
 	setentry *entry;
 
-	if (!PyString_CheckExact(key) ||
-	    (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+	if (!PyUnicode_CheckExact(key) ||
+	    (hash = ((PyUnicodeObject *) key)->hash) == -1) {
 		hash = PyObject_Hash(key);
 		if (hash == -1)
 			return -1;
@@ -801,7 +806,7 @@
 	Py_ssize_t len = 0;
 	if (si->si_set != NULL && si->si_used == si->si_set->used)
 		len = si->len;
-	return PyInt_FromLong(len);
+	return PyLong_FromLong(len);
 }
 
 PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
@@ -849,9 +854,9 @@
 	return NULL;
 }
 
-static PyTypeObject PySetIter_Type = {
+PyTypeObject PySetIter_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"setiterator",				/* tp_name */
+	"set_iterator",				/* tp_name */
 	sizeof(setiterobject),			/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */
@@ -901,7 +906,7 @@
 {
 	PyObject *key, *it;
 
-	if (PyAnySet_CheckExact(other))
+	if (PyAnySet_Check(other))
 		return set_merge(so, other);
 
 	if (PyDict_CheckExact(other)) {
@@ -972,11 +977,11 @@
 	}
 
 	/* create PySetObject structure */
-	if (num_free_sets && 
+	if (numfree &&
 	    (type == &PySet_Type  ||  type == &PyFrozenSet_Type)) {
-		so = free_sets[--num_free_sets];
+		so = free_list[--numfree];
 		assert (so != NULL && PyAnySet_CheckExact(so));
-		Py_Type(so) = type;
+		Py_TYPE(so) = type;
 		_Py_NewReference((PyObject *)so);
 		EMPTY_TO_MINSIZE(so);
 		PyObject_GC_Track(so);
@@ -989,7 +994,7 @@
 		INIT_NONZERO_SET_SLOTS(so);
 	}
 
-	so->lookup = set_lookkey_string;
+	so->lookup = set_lookkey_unicode;
 	so->weakreflist = NULL;
 
 	if (iterable != NULL) {
@@ -1042,9 +1047,9 @@
 {
 	PySetObject *so;
 
-	while (num_free_sets) {
-		num_free_sets--;
-		so = free_sets[num_free_sets];
+	while (numfree) {
+		numfree--;
+		so = free_list[numfree];
 		PyObject_GC_Del(so);
 	}
 	Py_CLEAR(dummy);
@@ -1102,8 +1107,8 @@
 		memcpy(b->smalltable, tab, sizeof(tab));
 	}
 
-	if (PyType_IsSubtype(Py_Type(a), &PyFrozenSet_Type)  &&
-	    PyType_IsSubtype(Py_Type(b), &PyFrozenSet_Type)) {
+	if (PyType_IsSubtype(Py_TYPE(a), &PyFrozenSet_Type)  &&
+	    PyType_IsSubtype(Py_TYPE(b), &PyFrozenSet_Type)) {
 		h = a->hash;     a->hash = b->hash;  b->hash = h;
 	} else {
 		a->hash = -1;
@@ -1114,7 +1119,7 @@
 static PyObject *
 set_copy(PySetObject *so)
 {
-	return make_new_set(Py_Type(so), (PyObject *)so);
+	return make_new_set(Py_TYPE(so), (PyObject *)so);
 }
 
 static PyObject *
@@ -1192,11 +1197,11 @@
 	if ((PyObject *)so == other)
 		return set_copy(so);
 
-	result = (PySetObject *)make_new_set(Py_Type(so), NULL);
+	result = (PySetObject *)make_new_set(Py_TYPE(so), NULL);
 	if (result == NULL)
 		return NULL;
 
-	if (PyAnySet_CheckExact(other)) {		
+	if (PyAnySet_Check(other)) {		
 		Py_ssize_t pos = 0;
 		setentry *entry;
 
@@ -1314,13 +1319,80 @@
 	return (PyObject *)so;
 }
 
+static PyObject *
+set_isdisjoint(PySetObject *so, PyObject *other)
+{
+	PyObject *key, *it, *tmp;
+
+	if ((PyObject *)so == other) {
+		if (PySet_GET_SIZE(so) == 0)
+			Py_RETURN_TRUE;
+		else
+			Py_RETURN_FALSE;
+	}
+
+	if (PyAnySet_CheckExact(other)) {		
+		Py_ssize_t pos = 0;
+		setentry *entry;
+
+		if (PySet_GET_SIZE(other) > PySet_GET_SIZE(so)) {
+			tmp = (PyObject *)so;
+			so = (PySetObject *)other;
+			other = tmp;
+		}
+		while (set_next((PySetObject *)other, &pos, &entry)) {
+			int rv = set_contains_entry(so, entry);
+			if (rv == -1)
+				return NULL;
+			if (rv)
+				Py_RETURN_FALSE;
+		}
+		Py_RETURN_TRUE;
+	}
+
+	it = PyObject_GetIter(other);
+	if (it == NULL)
+		return NULL;
+
+	while ((key = PyIter_Next(it)) != NULL) {
+		int rv;
+		setentry entry;
+		long hash = PyObject_Hash(key);;
+
+		if (hash == -1) {
+			Py_DECREF(key);
+			Py_DECREF(it);
+			return NULL;
+		}
+		entry.hash = hash;
+		entry.key = key;
+		rv = set_contains_entry(so, &entry);
+		Py_DECREF(key);
+		if (rv == -1) {
+			Py_DECREF(it);
+			return NULL;
+		}
+		if (rv) {
+			Py_DECREF(it);
+			Py_RETURN_FALSE;
+		}
+	}
+	Py_DECREF(it);
+	if (PyErr_Occurred())
+		return NULL;
+	Py_RETURN_TRUE;
+}
+
+PyDoc_STRVAR(isdisjoint_doc,
+"Return True if two sets have a null intersection.");
+
 static int
 set_difference_update_internal(PySetObject *so, PyObject *other)
 {
 	if ((PyObject *)so == other)
 		return set_clear_internal(so);
 	
-	if (PyAnySet_CheckExact(other)) {
+	if (PyAnySet_Check(other)) {
 		setentry *entry;
 		Py_ssize_t pos = 0;
 
@@ -1369,7 +1441,7 @@
 	setentry *entry;
 	Py_ssize_t pos = 0;
 
-	if (!PyAnySet_CheckExact(other)  && !PyDict_CheckExact(other)) {
+	if (!PyAnySet_Check(other)  && !PyDict_CheckExact(other)) {
 		result = set_copy(so);
 		if (result == NULL)
 			return NULL;
@@ -1379,7 +1451,7 @@
 		return NULL;
 	}
 	
-	result = make_new_set(Py_Type(so), NULL);
+	result = make_new_set(Py_TYPE(so), NULL);
 	if (result == NULL)
 		return NULL;
 
@@ -1476,11 +1548,11 @@
 		Py_RETURN_NONE;
 	}
 
-	if (PyAnySet_CheckExact(other)) {
+	if (PyAnySet_Check(other)) {
 		Py_INCREF(other);
 		otherset = (PySetObject *)other;
 	} else {
-		otherset = (PySetObject *)make_new_set(Py_Type(so), other);
+		otherset = (PySetObject *)make_new_set(Py_TYPE(so), other);
 		if (otherset == NULL)
 			return NULL;
 	}
@@ -1511,7 +1583,7 @@
 	PyObject *rv;
 	PySetObject *otherset;
 
-	otherset = (PySetObject *)make_new_set(Py_Type(so), other);
+	otherset = (PySetObject *)make_new_set(Py_TYPE(so), other);
 	if (otherset == NULL)
 		return NULL;
 	rv = set_symmetric_difference_update(otherset, (PyObject *)so);
@@ -1559,7 +1631,7 @@
 	setentry *entry;
 	Py_ssize_t pos = 0;
 
-	if (!PyAnySet_CheckExact(other)) {
+	if (!PyAnySet_Check(other)) {
 		PyObject *tmp, *result;
 		tmp = make_new_set(&PySet_Type, other);
 		if (tmp == NULL)
@@ -1588,7 +1660,7 @@
 {
 	PyObject *tmp, *result;
 
-	if (!PyAnySet_CheckExact(other)) {
+	if (!PyAnySet_Check(other)) {
 		tmp = make_new_set(&PySet_Type, other);
 		if (tmp == NULL)
 			return NULL;
@@ -1774,7 +1846,7 @@
 		dict = Py_None;
 		Py_INCREF(dict);
 	}
-	result = PyTuple_Pack(3, Py_Type(so), args, dict);
+	result = PyTuple_Pack(3, Py_TYPE(so), args, dict);
 done:
 	Py_XDECREF(args);
 	Py_XDECREF(keys);
@@ -1791,7 +1863,7 @@
 
 	if (!PyAnySet_Check(self))
 		return -1;
-	if (!PyArg_UnpackTuple(args, Py_Type(self)->tp_name, 0, 1, &iterable))
+	if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable))
 		return -1;
 	set_clear_internal(self);
 	self->hash = -1;
@@ -1839,6 +1911,8 @@
 	 intersection_doc},
 	{"intersection_update",(PyCFunction)set_intersection_update,	METH_O,
 	 intersection_update_doc},
+	{"isdisjoint",	(PyCFunction)set_isdisjoint,	METH_O,
+	 isdisjoint_doc},
 	{"issubset",	(PyCFunction)set_issubset,	METH_O,
 	 issubset_doc},
 	{"issuperset",	(PyCFunction)set_issuperset,	METH_O,
@@ -1960,6 +2034,8 @@
 	 difference_doc},
 	{"intersection",(PyCFunction)set_intersection,	METH_O,
 	 intersection_doc},
+	{"isdisjoint",	(PyCFunction)set_isdisjoint,	METH_O,
+	 isdisjoint_doc},
 	{"issubset",	(PyCFunction)set_issubset,	METH_O,
 	 issubset_doc},
 	{"issuperset",	(PyCFunction)set_issuperset,	METH_O,
@@ -2053,17 +2129,7 @@
 PyObject *
 PyFrozenSet_New(PyObject *iterable)
 {
-	PyObject *args, *result;
-
-	if (iterable == NULL)
-		args = PyTuple_New(0);
-	else
-		args = PyTuple_Pack(1, iterable);
-	if (args == NULL)
-		return NULL;
-	result = frozenset_new(&PyFrozenSet_Type, args, NULL);
-	Py_DECREF(args);
-	return result;
+	return make_new_set(&PyFrozenSet_Type, iterable);
 }
 
 Py_ssize_t
@@ -2079,7 +2145,7 @@
 int
 PySet_Clear(PyObject *set)
 {
-	if (!PyType_IsSubtype(Py_Type(set), &PySet_Type)) {
+	if (!PySet_Check(set)) {
 		PyErr_BadInternalCall();
 		return -1;
 	}
@@ -2099,7 +2165,7 @@
 int
 PySet_Discard(PyObject *set, PyObject *key)
 {
-	if (!PyType_IsSubtype(Py_Type(set), &PySet_Type)) {
+	if (!PySet_Check(set)) {
 		PyErr_BadInternalCall();
 		return -1;
 	}
@@ -2107,28 +2173,14 @@
 }
 
 int
-PySet_Add(PyObject *set, PyObject *key)
-{
-	if (!PyType_IsSubtype(Py_Type(set), &PySet_Type)) {
-		PyErr_BadInternalCall();
-		return -1;
-	}
-	return set_add_key((PySetObject *)set, key);
-}
-
-int
-_PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **key)
+PySet_Add(PyObject *anyset, PyObject *key)
 {
-	setentry *entry_ptr;
-
-	if (!PyAnySet_Check(set)) {
+	if (!PySet_Check(anyset) && 
+	    (!PyFrozenSet_Check(anyset) || Py_REFCNT(anyset) != 1)) {
 		PyErr_BadInternalCall();
 		return -1;
 	}
-	if (set_next((PySetObject *)set, pos, &entry_ptr) == 0)
-		return 0;
-	*key = entry_ptr->key;
-	return 1;
+	return set_add_key((PySetObject *)anyset, key);
 }
 
 int
@@ -2150,7 +2202,7 @@
 PyObject *
 PySet_Pop(PyObject *set)
 {
-	if (!PyType_IsSubtype(Py_Type(set), &PySet_Type)) {
+	if (!PySet_Check(set)) {
 		PyErr_BadInternalCall();
 		return NULL;
 	}
@@ -2160,7 +2212,7 @@
 int
 _PySet_Update(PyObject *set, PyObject *iterable)
 {
-	if (!PyType_IsSubtype(Py_Type(set), &PySet_Type)) {
+	if (!PySet_Check(set)) {
 		PyErr_BadInternalCall();
 		return -1;
 	}
@@ -2187,6 +2239,7 @@
 	Py_ssize_t i;
 	PyObject *elem=NULL, *dup=NULL, *t, *f, *dup2, *x;
 	PyObject *ob = (PyObject *)so;
+	long hash;
 
 	/* Verify preconditions and exercise type/size checks */
 	assert(PyAnySet_Check(ob));
@@ -2227,12 +2280,16 @@
 	f = PyFrozenSet_New(dup);
 	assertRaises(PySet_Clear(f) == -1, PyExc_SystemError);
 	assertRaises(_PySet_Update(f, dup) == -1, PyExc_SystemError);
+	assert(PySet_Add(f, elem) == 0);
+	Py_INCREF(f);
+	assertRaises(PySet_Add(f, elem) == -1, PyExc_SystemError);
+	Py_DECREF(f);
 	Py_DECREF(f);
 
 	/* Exercise direct iteration */
 	i = 0, count = 0;
-	while (_PySet_Next((PyObject *)dup, &i, &x)) {
-		s = PyString_AsString(x);
+	while (_PySet_NextEntry((PyObject *)dup, &i, &x, &hash)) {
+		s = PyUnicode_AsString(x);
 		assert(s && (s[0] == 'a' || s[0] == 'b' || s[0] == 'c'));
 		count++;
 	}
@@ -2256,7 +2313,6 @@
 	f = PyFrozenSet_New(dup);
 	assert(PySet_Size(f) == 3);
 	assert(PyFrozenSet_CheckExact(f));
-	assertRaises(PySet_Add(f, elem) == -1, PyExc_SystemError);
 	assertRaises(PySet_Discard(f, elem) == -1, PyExc_SystemError);
 	assertRaises(PySet_Pop(f) == NULL, PyExc_SystemError);
 	Py_DECREF(f);

Modified: python/branches/py3k-importlib/Objects/sliceobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/sliceobject.c	(original)
+++ python/branches/py3k-importlib/Objects/sliceobject.c	Thu Mar 27 00:48:05 2008
@@ -83,10 +83,10 @@
 _PySlice_FromIndices(Py_ssize_t istart, Py_ssize_t istop)
 {
 	PyObject *start, *end, *slice;
-	start = PyInt_FromSsize_t(istart);
+	start = PyLong_FromSsize_t(istart);
 	if (!start)
 		return NULL;
-	end = PyInt_FromSsize_t(istop);
+	end = PyLong_FromSsize_t(istop);
 	if (!end) {
 		Py_DECREF(start);
 		return NULL;
@@ -107,20 +107,20 @@
 		*step = 1;
 	} else {
 		if (!PyLong_Check(r->step)) return -1;
-		*step = PyInt_AsSsize_t(r->step);
+		*step = PyLong_AsSsize_t(r->step);
 	}
 	if (r->start == Py_None) {
 		*start = *step < 0 ? length-1 : 0;
 	} else {
-		if (!PyInt_Check(r->start) && !PyLong_Check(r->step)) return -1;
-		*start = PyInt_AsSsize_t(r->start);
+		if (!PyLong_Check(r->start)) return -1;
+		*start = PyLong_AsSsize_t(r->start);
 		if (*start < 0) *start += length;
 	}
 	if (r->stop == Py_None) {
 		*stop = *step < 0 ? -1 : length;
 	} else {
-		if (!PyInt_Check(r->stop) && !PyLong_Check(r->step)) return -1;
-		*stop = PyInt_AsSsize_t(r->stop);
+		if (!PyLong_Check(r->stop)) return -1;
+		*stop = PyLong_AsSsize_t(r->stop);
 		if (*stop < 0) *stop += length;
 	}
 	if (*stop > length) return -1;
@@ -266,7 +266,7 @@
 static PyObject *
 slice_reduce(PySliceObject* self)
 {
-	return Py_BuildValue("O(OOO)", Py_Type(self), self->start, self->stop, self->step);
+	return Py_BuildValue("O(OOO)", Py_TYPE(self), self->start, self->stop, self->step);
 }
 
 PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");

Modified: python/branches/py3k-importlib/Objects/stringlib/README.txt
==============================================================================
--- python/branches/py3k-importlib/Objects/stringlib/README.txt	(original)
+++ python/branches/py3k-importlib/Objects/stringlib/README.txt	Thu Mar 27 00:48:05 2008
@@ -32,3 +32,12 @@
 
     returns the pointer to the character data for the given string
     object (which must be of the right type)
+
+int STRINGLIB_CHECK_EXACT(PyObject *)
+
+    returns true if the object is an instance of our type, not a subclass.
+
+STRINGLIB_MUTABLE
+
+    Must be 0 or 1 to tell the cpp macros in stringlib code if the object
+    being operated on is mutable or not.

Modified: python/branches/py3k-importlib/Objects/stringlib/find.h
==============================================================================
--- python/branches/py3k-importlib/Objects/stringlib/find.h	(original)
+++ python/branches/py3k-importlib/Objects/stringlib/find.h	Thu Mar 27 00:48:05 2008
@@ -90,7 +90,7 @@
     return stringlib_rfind(str + start, end - start, sub, sub_len, start);
 }
 
-#ifdef STRINGLIB_STR
+#ifdef STRINGLIB_WANT_CONTAINS_OBJ
 
 Py_LOCAL_INLINE(int)
 stringlib_contains_obj(PyObject* str, PyObject* sub)
@@ -103,6 +103,56 @@
 
 #endif /* STRINGLIB_STR */
 
+#ifdef FROM_UNICODE
+
+/*
+This function is a helper for the "find" family (find, rfind, index,
+rindex) of unicodeobject.c file, because they all have the same 
+behaviour for the arguments.
+
+It does not touch the variables received until it knows everything 
+is ok.
+
+Note that we receive a pointer to the pointer of the substring object,
+so when we create that object in this function we don't DECREF it,
+because it continues living in the caller functions (those functions, 
+after finishing using the substring, must DECREF it).
+*/
+
+Py_LOCAL_INLINE(int)
+_ParseTupleFinds (PyObject *args, PyObject **substring, 
+                  Py_ssize_t *start, Py_ssize_t *end) {
+    PyObject *tmp_substring;
+    Py_ssize_t tmp_start = 0;
+    Py_ssize_t tmp_end = PY_SSIZE_T_MAX;
+    PyObject *obj_start=Py_None, *obj_end=Py_None;
+
+    if (!PyArg_ParseTuple(args, "O|OO:find", &tmp_substring,
+         &obj_start, &obj_end))
+        return 0;
+
+    /* To support None in "start" and "end" arguments, meaning
+       the same as if they were not passed.
+    */
+    if (obj_start != Py_None)
+        if (!_PyEval_SliceIndex(obj_start, &tmp_start))
+            return 0;
+    if (obj_end != Py_None)
+        if (!_PyEval_SliceIndex(obj_end, &tmp_end))
+            return 0;
+
+    tmp_substring = PyUnicode_FromObject(tmp_substring);
+    if (!tmp_substring)
+        return 0;
+
+    *start = tmp_start;
+    *end = tmp_end;
+    *substring = tmp_substring;
+    return 1;
+}
+
+#endif /* FROM_UNICODE */
+
 #endif /* STRINGLIB_FIND_H */
 
 /*

Modified: python/branches/py3k-importlib/Objects/stringlib/formatter.h
==============================================================================
--- python/branches/py3k-importlib/Objects/stringlib/formatter.h	(original)
+++ python/branches/py3k-importlib/Objects/stringlib/formatter.h	Thu Mar 27 00:48:05 2008
@@ -130,16 +130,16 @@
     }
     else if (end-ptr >= 1 && is_alignment_token(ptr[0])) {
         format->align = ptr[0];
-        ptr++;
+        ++ptr;
     }
 
     /* Parse the various sign options */
     if (end-ptr >= 1 && is_sign_element(ptr[0])) {
         format->sign = ptr[0];
-        ptr++;
+        ++ptr;
 #if ALLOW_PARENS_FOR_SIGN
         if (end-ptr >= 1 && ptr[0] == ')') {
-            ptr++;
+            ++ptr;
         }
 #endif
     }
@@ -150,7 +150,7 @@
         if (format->align == '\0') {
             format->align = '=';
         }
-        ptr++;
+        ++ptr;
     }
 
     /* XXX add error checking */
@@ -165,7 +165,7 @@
 
     /* Parse field precision */
     if (end-ptr && ptr[0] == '.') {
-        ptr++;
+        ++ptr;
 
         /* XXX add error checking */
         specified_width = get_integer(&ptr, end, &format->precision);
@@ -189,13 +189,13 @@
 
     if (end-ptr == 1) {
         format->type = ptr[0];
-        ptr++;
+        ++ptr;
     }
 
     return 1;
 }
 
-
+#if defined FORMAT_FLOAT || defined FORMAT_LONG
 /************************************************************************/
 /*********** common routines for numeric formatting *********************/
 /************************************************************************/
@@ -288,7 +288,8 @@
         else {
             /* determine which of left, space, or right padding is
                needed */
-            Py_ssize_t padding = format->width - (r->n_lsign + n_digits + r->n_rsign);
+            Py_ssize_t padding = format->width -
+		                    (r->n_lsign + n_digits + r->n_rsign);
             if (format->align == '<')
                 r->n_rpadding = padding;
             else if (format->align == '>')
@@ -338,6 +339,7 @@
     }
     return p_digits;
 }
+#endif /* FORMAT_FLOAT || FORMAT_LONG */
 
 /************************************************************************/
 /*********** string formatting ******************************************/
@@ -434,18 +436,23 @@
 /*********** long formatting ********************************************/
 /************************************************************************/
 
+#if defined FORMAT_LONG || defined FORMAT_INT
+typedef PyObject*
+(*IntOrLongToString)(PyObject *value, int base);
+
 static PyObject *
-format_long_internal(PyObject *value, const InternalFormatSpec *format)
+format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
+			    IntOrLongToString tostring)
 {
     PyObject *result = NULL;
-    int total_leading_chars_to_skip = 0; /* also includes sign, if
-                                            present */
+    PyObject *tmp = NULL;
+    STRINGLIB_CHAR *pnumeric_chars;
+    STRINGLIB_CHAR numeric_char;
     STRINGLIB_CHAR sign = '\0';
     STRINGLIB_CHAR *p;
     Py_ssize_t n_digits;       /* count of digits need from the computed
                                   string */
-    Py_ssize_t len;
-    Py_ssize_t tmp;
+    Py_ssize_t n_leading_chars;
     NumberFieldWidths spec;
     long x;
 
@@ -469,7 +476,8 @@
 
         /* taken from unicodeobject.c formatchar() */
         /* Integer input truncated to a character */
-        x = PyInt_AsLong(value);
+/* XXX: won't work for int */
+        x = PyLong_AsLong(value);
         if (x == -1 && PyErr_Occurred())
             goto done;
 #ifdef Py_UNICODE_WIDE
@@ -487,151 +495,121 @@
             goto done;
         }
 #endif
-        result = STRINGLIB_NEW(NULL, 1);
-        if (result == NULL)
-            goto done;
-        p = STRINGLIB_STR(result);
-        p[0] = (Py_UNICODE) x;
-        n_digits = len = 1;
+	numeric_char = (STRINGLIB_CHAR)x;
+	pnumeric_chars = &numeric_char;
+        n_digits = 1;
     }
     else {
         int base;
-        int format_leading_chars_to_skip;  /* characters added by
-                                              PyNumber_ToBase that we
-                                              want to skip over.
-                                              instead of using them,
-                                              we'll compute our
-                                              own. */
-        /* compute the base and how many characters will be added by
+	int leading_chars_to_skip;  /* Number of characters added by
+				       PyNumber_ToBase that we want to
+				       skip over. */
+
+        /* Compute the base and how many characters will be added by
            PyNumber_ToBase */
         switch (format->type) {
         case 'b':
             base = 2;
-            format_leading_chars_to_skip = 2; /* 0b */
+            leading_chars_to_skip = 2; /* 0b */
             break;
         case 'o':
             base = 8;
-            format_leading_chars_to_skip = 2; /* 0o */
+            leading_chars_to_skip = 2; /* 0o */
             break;
         case 'x':
         case 'X':
             base = 16;
-            format_leading_chars_to_skip = 2; /* 0x */
+            leading_chars_to_skip = 2; /* 0x */
             break;
         default:  /* shouldn't be needed, but stops a compiler warning */
         case 'd':
             base = 10;
-            format_leading_chars_to_skip = 0;
+            leading_chars_to_skip = 0;
             break;
         }
 
-        /* do the hard part, converting to a string in a given base */
-        result = PyNumber_ToBase(value, base);
-        if (result == NULL)
+        /* Do the hard part, converting to a string in a given base */
+	tmp = tostring(value, base);
+        if (tmp == NULL)
             goto done;
 
-        n_digits = STRINGLIB_LEN(result);
-        len = n_digits;
-        p = STRINGLIB_STR(result);
-
-        /* if X, convert to uppercase */
-        if (format->type == 'X')
-            for (tmp = 0; tmp < len; tmp++)
-                p[tmp] = STRINGLIB_TOUPPER(p[tmp]);
+	pnumeric_chars = STRINGLIB_STR(tmp);
+        n_digits = STRINGLIB_LEN(tmp);
+
+	/* Remember not to modify what pnumeric_chars points to.  it
+	   might be interned.  Only modify it after we copy it into a
+	   newly allocated output buffer. */
 
-        /* is a sign character present in the output?  if so, remember it
+        /* Is a sign character present in the output?  If so, remember it
            and skip it */
-        sign = p[0];
+        sign = pnumeric_chars[0];
         if (sign == '-') {
-            total_leading_chars_to_skip += 1;
-            n_digits--;
+	    ++leading_chars_to_skip;
         }
 
-        /* skip over the leading digits (0x, 0b, etc.) */
-        assert(n_digits >= format_leading_chars_to_skip + 1);
-        n_digits -= format_leading_chars_to_skip;
-        total_leading_chars_to_skip += format_leading_chars_to_skip;
+	/* Skip over the leading chars (0x, 0b, etc.) */
+	n_digits -= leading_chars_to_skip;
+	pnumeric_chars += leading_chars_to_skip;
     }
 
+    /* Calculate the widths of the various leading and trailing parts */
     calc_number_widths(&spec, sign, n_digits, format);
 
-    /* if the buffer is getting bigger, realloc it.  if it's getting
-       smaller, don't realloc because we need to move the results
-       around first.  realloc after we've done that */
-
-    if (spec.n_total > len) {
-        if (STRINGLIB_RESIZE(&result, spec.n_total) < 0)
-            goto done;
-        /* recalc, because string might have moved */
-        p = STRINGLIB_STR(result);
-    }
-
-    /* copy the characters into position first, since we're going to
-       overwrite some of that space */
-    /* we need to move if the number of left padding in the output is
-       different from the number of characters we need to skip */
-    if ((spec.n_lpadding + spec.n_lsign + spec.n_spadding) !=
-          total_leading_chars_to_skip) {
-        memmove(p + (spec.n_lpadding + spec.n_lsign + spec.n_spadding),
-                p + total_leading_chars_to_skip,
-                n_digits * sizeof(STRINGLIB_CHAR));
+    /* Allocate a new string to hold the result */
+    result = STRINGLIB_NEW(NULL, spec.n_total);
+    if (!result)
+	goto done;
+    p = STRINGLIB_STR(result);
+
+    /* Fill in the digit parts */
+    n_leading_chars = spec.n_lpadding + spec.n_lsign + spec.n_spadding;
+    memmove(p + n_leading_chars,
+	    pnumeric_chars,
+	    n_digits * sizeof(STRINGLIB_CHAR));
+
+    /* if X, convert to uppercase */
+    if (format->type == 'X') {
+	Py_ssize_t t;
+	for (t = 0; t < n_digits; ++t)
+	    p[t + n_leading_chars] = STRINGLIB_TOUPPER(p[t + n_leading_chars]);
     }
 
-    /* now fill in the non-digit parts */
+    /* Fill in the non-digit parts */
     fill_number(p, &spec, n_digits,
                 format->fill_char == '\0' ? ' ' : format->fill_char);
 
-    /* if we're getting smaller, realloc now */
-    if (spec.n_total < len) {
-        if (STRINGLIB_RESIZE(&result, spec.n_total) < 0)
-            goto done;
-    }
-
 done:
+    Py_XDECREF(tmp);
     return result;
 }
-
+#endif /* defined FORMAT_LONG || defined FORMAT_INT */
 
 /************************************************************************/
 /*********** float formatting *******************************************/
 /************************************************************************/
 
+#ifdef FORMAT_FLOAT
+#if STRINGLIB_IS_UNICODE
 /* taken from unicodeobject.c */
 static Py_ssize_t
 strtounicode(Py_UNICODE *buffer, const char *charbuffer)
 {
     register Py_ssize_t i;
     Py_ssize_t len = strlen(charbuffer);
-    for (i = len - 1; i >= 0; i--)
+    for (i = len - 1; i >= 0; --i)
         buffer[i] = (Py_UNICODE) charbuffer[i];
 
     return len;
 }
-
-/* the callback function to call to do the actual float formatting.
-   it matches the definition of PyOS_ascii_formatd */
-typedef char*
-(*DoubleSnprintfFunction)(char *buffer, size_t buf_len,
-                          const char *format, double d);
-
-/* just a wrapper to make PyOS_snprintf look like DoubleSnprintfFunction */
-static char*
-snprintf_double(char *buffer, size_t buf_len, const char *format, double d)
-{
-    PyOS_snprintf(buffer, buf_len, format, d);
-    return NULL;
-}
+#endif
 
 /* see FORMATBUFLEN in unicodeobject.c */
 #define FLOAT_FORMATBUFLEN 120
 
 /* much of this is taken from unicodeobject.c */
-/* use type instead of format->type, so that it can be overridden by
-   format_number() */
 static PyObject *
-_format_float(STRINGLIB_CHAR type, PyObject *value,
-              const InternalFormatSpec *format,
-              DoubleSnprintfFunction snprintf)
+format_float_internal(PyObject *value,
+		      const InternalFormatSpec *format)
 {
     /* fmt = '%.' + `prec` + `type` + '%%'
        worst case length = 2 + 10 (len of INT_MAX) + 1 + 2 = 15 (use 20)*/
@@ -663,6 +641,7 @@
     char* trailing = "";
     STRINGLIB_CHAR *p;
     NumberFieldWidths spec;
+    STRINGLIB_CHAR type = format->type;
 
 #if STRINGLIB_IS_UNICODE
     Py_UNICODE unicodebuf[FLOAT_FORMATBUFLEN];
@@ -694,10 +673,11 @@
     /* cast "type", because if we're in unicode we need to pass a
        8-bit char.  this is safe, because we've restricted what "type"
        can be */
-    PyOS_snprintf(fmt, sizeof(fmt), "%%.%" PY_FORMAT_SIZE_T "d%c", precision, (char)type);
+    PyOS_snprintf(fmt, sizeof(fmt), "%%.%" PY_FORMAT_SIZE_T "d%c", precision,
+		  (char)type);
 
-    /* call the passed in function to do the actual formatting */
-    snprintf(charbuf, sizeof(charbuf), fmt, x);
+    /* do the actual formatting */
+    PyOS_ascii_formatd(charbuf, sizeof(charbuf), fmt, x);
 
     /* adding trailing to fmt with PyOS_snprintf doesn't work, not
        sure why.  we'll just concatentate it here, no harm done.  we
@@ -723,8 +703,8 @@
        and skip it */
     sign = p[0];
     if (sign == '-') {
-        p++;
-        n_digits--;
+        ++p;
+        --n_digits;
     }
 
     calc_number_widths(&spec, sign, n_digits, format);
@@ -739,37 +719,51 @@
                 format->fill_char == '\0' ? ' ' : format->fill_char);
 
     /* fill in the digit parts */
-    memmove(STRINGLIB_STR(result) + (spec.n_lpadding + spec.n_lsign + spec.n_spadding),
+    memmove(STRINGLIB_STR(result) +
+	       (spec.n_lpadding + spec.n_lsign + spec.n_spadding),
             p,
             n_digits * sizeof(STRINGLIB_CHAR));
 
 done:
     return result;
 }
-
-static PyObject *
-format_float_internal(PyObject *value, const InternalFormatSpec *format)
-{
-    if (format->type == 'n')
-        return _format_float('f', value, format, snprintf_double);
-    else
-        return _format_float(format->type, value, format, PyOS_ascii_formatd);
-}
+#endif /* FORMAT_FLOAT */
 
 /************************************************************************/
 /*********** built in formatters ****************************************/
 /************************************************************************/
-
+#ifdef FORMAT_STRING
 PyObject *
 FORMAT_STRING(PyObject* value, PyObject* args)
 {
     PyObject *format_spec;
-    PyObject *tmp = NULL;
     PyObject *result = NULL;
+#if PY_VERSION_HEX < 0x03000000
+    PyObject *tmp = NULL;
+#endif
     InternalFormatSpec format;
 
-    if (!PyArg_ParseTuple(args, STRINGLIB_PARSE_CODE ":__format__", &format_spec))
+    /* If 2.x, we accept either str or unicode, and try to convert it
+       to the right type.  In 3.x, we insist on only unicode */
+#if PY_VERSION_HEX >= 0x03000000
+    if (!PyArg_ParseTuple(args, STRINGLIB_PARSE_CODE ":__format__",
+			  &format_spec))
         goto done;
+#else
+    /* If 2.x, convert format_spec to the same type as value */
+    /* This is to allow things like u''.format('') */
+    if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
+        goto done;
+    if (!(PyString_Check(format_spec) || PyUnicode_Check(format_spec))) {
+        PyErr_Format(PyExc_TypeError, "__format__ arg must be str "
+		     "or unicode, not %s", Py_TYPE(format_spec)->tp_name);
+	goto done;
+    }
+    tmp = STRINGLIB_TOSTR(format_spec);
+    if (tmp == NULL)
+        goto done;
+    format_spec = tmp;
+#endif
 
     /* check for the special case of zero length format spec, make
        it equivalent to str(value) */
@@ -778,6 +772,7 @@
         goto done;
     }
 
+
     /* parse the format_spec */
     if (!parse_internal_render_format_spec(format_spec, &format, 's'))
         goto done;
@@ -788,37 +783,6 @@
         /* no type conversion needed, already a string.  do the formatting */
         result = format_string_internal(value, &format);
         break;
-#if 0
-    case 'b':
-    case 'c':
-    case 'd':
-    case 'o':
-    case 'x':
-    case 'X':
-        /* convert to integer */
-        /* XXX: make a stringlib function to do this when backporting,
-           since FromUnicode differs from FromString */
-        tmp = PyLong_FromUnicode(STRINGLIB_STR(value), STRINGLIB_LEN(value), 0);
-        if (tmp == NULL)
-            goto done;
-        result = format_long_internal(tmp, &format);
-        break;
-
-    case 'e':
-    case 'E':
-    case 'f':
-    case 'F':
-    case 'g':
-    case 'G':
-    case 'n':
-    case '%':
-        /* convert to float */
-        tmp = PyFloat_FromString(value);
-        if (tmp == NULL)
-            goto done;
-        result = format_float_internal(tmp, &format);
-        break;
-#endif
     default:
         /* unknown */
         PyErr_Format(PyExc_ValueError, "Unknown conversion type %c",
@@ -827,19 +791,24 @@
     }
 
 done:
+#if PY_VERSION_HEX < 0x03000000
     Py_XDECREF(tmp);
+#endif
     return result;
 }
+#endif /* FORMAT_STRING */
 
-PyObject *
-FORMAT_LONG(PyObject* value, PyObject* args)
+#if defined FORMAT_LONG || defined FORMAT_INT
+static PyObject*
+format_int_or_long(PyObject* value, PyObject* args, IntOrLongToString tostring)
 {
     PyObject *format_spec;
     PyObject *result = NULL;
     PyObject *tmp = NULL;
     InternalFormatSpec format;
 
-    if (!PyArg_ParseTuple(args, STRINGLIB_PARSE_CODE ":__format__", &format_spec))
+    if (!PyArg_ParseTuple(args, STRINGLIB_PARSE_CODE ":__format__",
+			  &format_spec))
         goto done;
 
     /* check for the special case of zero length format spec, make
@@ -855,23 +824,15 @@
 
     /* type conversion? */
     switch (format.type) {
-#if 0
-    case 's':
-        /* convert to string/unicode */
-        tmp = STRINGLIB_TOSTR(value);
-        if (tmp == NULL)
-            goto done;
-        result = format_string_internal(tmp, &format);
-        break;
-#endif
     case 'b':
     case 'c':
     case 'd':
     case 'o':
     case 'x':
     case 'X':
-        /* no type conversion needed, already an int.  do the formatting */
-        result = format_long_internal(value, &format);
+        /* no type conversion needed, already an int (or long).  do
+	   the formatting */
+	    result = format_int_or_long_internal(value, &format, tostring);
         break;
 
     case 'e':
@@ -900,13 +861,57 @@
     Py_XDECREF(tmp);
     return result;
 }
+#endif /* FORMAT_LONG || defined FORMAT_INT */
+
+#ifdef FORMAT_LONG
+/* Need to define long_format as a function that will convert a long
+   to a string.  In 3.0, _PyLong_Format has the correct signature.  In
+   2.x, we need to fudge a few parameters */
+#if PY_VERSION_HEX >= 0x03000000
+#define long_format _PyLong_Format
+#else
+static PyObject*
+long_format(PyObject* value, int base)
+{
+    /* Convert to base, don't add trailing 'L', and use the new octal
+       format. We already know this is a long object */
+    assert(PyLong_Check(value));
+    /* convert to base, don't add 'L', and use the new octal format */
+    return _PyLong_Format(value, base, 0, 1);
+}
+#endif
 
 PyObject *
+FORMAT_LONG(PyObject* value, PyObject* args)
+{
+    return format_int_or_long(value, args, long_format);
+}
+#endif /* FORMAT_LONG */
+
+#ifdef FORMAT_INT
+/* this is only used for 2.x, not 3.0 */
+static PyObject*
+int_format(PyObject* value, int base)
+{
+    /* Convert to base, and use the new octal format. We already
+       know this is an int object */
+    assert(PyInt_Check(value));
+    return _PyInt_Format((PyIntObject*)value, base, 1);
+}
+
+PyObject *
+FORMAT_INT(PyObject* value, PyObject* args)
+{
+    return format_int_or_long(value, args, int_format);
+}
+#endif /* FORMAT_INT */
+
+#ifdef FORMAT_FLOAT
+PyObject *
 FORMAT_FLOAT(PyObject *value, PyObject *args)
 {
     PyObject *format_spec;
     PyObject *result = NULL;
-    PyObject *tmp = NULL;
     InternalFormatSpec format;
 
     if (!PyArg_ParseTuple(args, STRINGLIB_PARSE_CODE ":__format__", &format_spec))
@@ -920,33 +925,16 @@
     }
 
     /* parse the format_spec */
-    if (!parse_internal_render_format_spec(format_spec, &format, 'g'))
+    if (!parse_internal_render_format_spec(format_spec, &format, '\0'))
         goto done;
 
     /* type conversion? */
     switch (format.type) {
-#if 0
-    case 's':
-        /* convert to string/unicode */
-        tmp = STRINGLIB_TOSTR(value);
-        if (tmp == NULL)
-            goto done;
-        result = format_string_internal(tmp, &format);
-        break;
-#endif
-    case 'b':
-    case 'c':
-    case 'd':
-    case 'o':
-    case 'x':
-    case 'X':
-        /* convert to integer */
-        tmp = PyNumber_Long(value);
-        if (tmp == NULL)
-            goto done;
-        result = format_long_internal(tmp, &format);
-        break;
-
+    case '\0':
+	/* 'Z' means like 'g', but with at least one decimal.  See
+	   PyOS_ascii_formatd */
+	format.type = 'Z';
+	/* Deliberate fall through to the next case statement */
     case 'e':
     case 'E':
     case 'f':
@@ -967,6 +955,6 @@
     }
 
 done:
-    Py_XDECREF(tmp);
     return result;
 }
+#endif /* FORMAT_FLOAT */

Modified: python/branches/py3k-importlib/Objects/stringlib/string_format.h
==============================================================================
--- python/branches/py3k-importlib/Objects/stringlib/string_format.h	(original)
+++ python/branches/py3k-importlib/Objects/stringlib/string_format.h	Thu Mar 27 00:48:05 2008
@@ -6,6 +6,11 @@
 */
 
 
+/* Defines for Python 2.6 compatability */
+#if PY_VERSION_HEX < 0x03000000
+#define PyLong_FromSsize_t _PyLong_FromSsize_t
+#endif
+
 /* Defines for more efficiently reallocating the string buffer */
 #define INITIAL_SIZE_INCREMENT 100
 #define SIZE_MULTIPLIER 2
@@ -204,7 +209,7 @@
 getitem_idx(PyObject *obj, Py_ssize_t idx)
 {
     PyObject *newobj;
-    PyObject *idx_obj = PyInt_FromSsize_t(idx);
+    PyObject *idx_obj = PyLong_FromSsize_t(idx);
     if (idx_obj == NULL)
         return NULL;
     newobj = PyObject_GetItem(obj, idx_obj);
@@ -470,81 +475,44 @@
     field object and field specification string generated by
     get_field_and_spec, and renders the field into the output string.
 
-    format() does the actual calling of the objects __format__ method.
+    render_field calls fieldobj.__format__(format_spec) method, and
+    appends to the output.
 */
-
-
-/* returns fieldobj.__format__(format_spec) */
-static PyObject *
-format(PyObject *fieldobj, SubString *format_spec)
+static int
+render_field(PyObject *fieldobj, SubString *format_spec, OutputString *output)
 {
-    static PyObject *format_str = NULL;
-    PyObject *meth;
-    PyObject *spec = NULL;
+    int ok = 0;
     PyObject *result = NULL;
 
-    /* Initialize cached value */
-    if (format_str == NULL) {
-        /* Initialize static variable needed by _PyType_Lookup */
-        format_str = PyUnicode_FromString("__format__");
-        if (format_str == NULL)
-            return NULL;
-    }
-
-    /* Make sure the type is initialized.  float gets initialized late */
-    if (Py_Type(fieldobj)->tp_dict == NULL)
-        if (PyType_Ready(Py_Type(fieldobj)) < 0)
-            return NULL;
-
     /* we need to create an object out of the pointers we have */
-    spec = SubString_new_object_or_empty(format_spec);
-    if (spec == NULL)
-        goto done;
-
-    /* Find the (unbound!) __format__ method (a borrowed reference) */
-    meth = _PyType_Lookup(Py_Type(fieldobj), format_str);
-    if (meth == NULL) {
-        PyErr_Format(PyExc_TypeError,
-                     "Type %.100s doesn't define __format__",
-                     Py_Type(fieldobj)->tp_name);
+    PyObject *format_spec_object = SubString_new_object_or_empty(format_spec);
+    if (format_spec_object == NULL)
         goto done;
-    }
 
-    /* And call it, binding it to the value */
-    result = PyObject_CallFunctionObjArgs(meth, fieldobj, spec, NULL);
+    result = PyObject_Format(fieldobj, format_spec_object);
     if (result == NULL)
         goto done;
 
-    if (!STRINGLIB_CHECK(result)) {
-        PyErr_SetString(PyExc_TypeError,
-                        "__format__ method did not return "
-                        STRINGLIB_TYPE_NAME);
-        Py_DECREF(result);
-        result = NULL;
-        goto done;
+#if PY_VERSION_HEX >= 0x03000000
+    assert(PyUnicode_Check(result));
+#else
+    assert(PyString_Check(result) || PyUnicode_Check(result));
+
+    /* Convert result to our type.  We could be str, and result could
+       be unicode */
+    {
+	PyObject *tmp = STRINGLIB_TOSTR(result);
+	if (tmp == NULL)
+	    goto done;
+	Py_DECREF(result);
+	result = tmp;
     }
-
-done:
-    Py_XDECREF(spec);
-    return result;
-}
-
-/*
-    render_field calls fieldobj.__format__(format_spec) method, and
-    appends to the output.
-*/
-static int
-render_field(PyObject *fieldobj, SubString *format_spec, OutputString *output)
-{
-    int ok = 0;
-    PyObject *result = format(fieldobj, format_spec);
-
-    if (result == NULL)
-        goto done;
+#endif
 
     ok = output_data(output,
                      STRINGLIB_STR(result), STRINGLIB_LEN(result));
 done:
+    Py_DECREF(format_spec_object);
     Py_XDECREF(result);
     return ok;
 }
@@ -770,7 +738,7 @@
     case 'r':
         return PyObject_Repr(obj);
     case 's':
-        return PyObject_Unicode(obj);
+        return STRINGLIB_TOSTR(obj);
     default:
         PyErr_Format(PyExc_ValueError,
                      "Unknown converion specifier %c",
@@ -845,7 +813,7 @@
 }
 
 /*
-    do_markup is the top-level loop for the format() function.  It
+    do_markup is the top-level loop for the format() method.  It
     searches through the format string for escapes to markup codes, and
     calls other functions to move non-markup text to the output,
     and to perform the markup to the output.
@@ -958,7 +926,7 @@
 typedef struct {
     PyObject_HEAD
 
-    PyUnicodeObject *str;
+    STRINGLIB_OBJECT *str;
 
     MarkupIterator it_markup;
 } formatteriterobject;
@@ -984,7 +952,7 @@
     SubString literal;
     SubString field_name;
     SubString format_spec;
-    Py_UNICODE conversion;
+    STRINGLIB_CHAR conversion;
     int format_spec_needs_expanding;
     int result = MarkupIterator_next(&it->it_markup, &literal, &field_name,
                                      &format_spec, &conversion,
@@ -1028,7 +996,7 @@
             Py_INCREF(conversion_str);
         }
         else
-            conversion_str = PyUnicode_FromUnicode(&conversion, 1);
+	    conversion_str = STRINGLIB_NEW(&conversion, 1);
         if (conversion_str == NULL)
             goto done;
 
@@ -1047,7 +1015,7 @@
     {NULL,		NULL}		/* sentinel */
 };
 
-PyTypeObject PyFormatterIter_Type = {
+static PyTypeObject PyFormatterIter_Type = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
     "formatteriterator",		/* tp_name */
     sizeof(formatteriterobject),	/* tp_basicsize */
@@ -1085,7 +1053,7 @@
    describing the parsed elements.  It's a wrapper around
    stringlib/string_format.h's MarkupIterator */
 static PyObject *
-formatter_parser(PyUnicodeObject *self)
+formatter_parser(STRINGLIB_OBJECT *self)
 {
     formatteriterobject *it;
 
@@ -1099,8 +1067,8 @@
 
     /* initialize the contained MarkupIterator */
     MarkupIterator_init(&it->it_markup,
-                        PyUnicode_AS_UNICODE(self),
-                        PyUnicode_GET_SIZE(self));
+                        STRINGLIB_STR(self),
+                        STRINGLIB_LEN(self));
 
     return (PyObject *)it;
 }
@@ -1118,7 +1086,7 @@
 typedef struct {
     PyObject_HEAD
 
-    PyUnicodeObject *str;
+    STRINGLIB_OBJECT *str;
 
     FieldNameIterator it_field;
 } fieldnameiterobject;
@@ -1160,7 +1128,7 @@
 
         /* either an integer or a string */
         if (idx != -1)
-            obj = PyInt_FromSsize_t(idx);
+            obj = PyLong_FromSsize_t(idx);
         else
             obj = SubString_new_object(&name);
         if (obj == NULL)
@@ -1220,7 +1188,7 @@
    field_name_split.  The iterator it returns is a
    FieldNameIterator */
 static PyObject *
-formatter_field_name_split(PyUnicodeObject *self)
+formatter_field_name_split(STRINGLIB_OBJECT *self)
 {
     SubString first;
     Py_ssize_t first_idx;
@@ -1245,7 +1213,7 @@
 
     /* first becomes an integer, if possible; else a string */
     if (first_idx != -1)
-        first_obj = PyInt_FromSsize_t(first_idx);
+        first_obj = PyLong_FromSsize_t(first_idx);
     else
         /* convert "first" into a string object */
         first_obj = SubString_new_object(&first);

Modified: python/branches/py3k-importlib/Objects/stringlib/stringdefs.h
==============================================================================
--- python/branches/py3k-importlib/Objects/stringlib/stringdefs.h	(original)
+++ python/branches/py3k-importlib/Objects/stringlib/stringdefs.h	Thu Mar 27 00:48:05 2008
@@ -6,12 +6,15 @@
    compiled as unicode. */
 #define STRINGLIB_IS_UNICODE     0
 
+#define STRINGLIB_OBJECT         PyStringObject
 #define STRINGLIB_CHAR           char
 #define STRINGLIB_TYPE_NAME      "string"
 #define STRINGLIB_PARSE_CODE     "S"
-#define STRINGLIB_EMPTY          string_empty
+#define STRINGLIB_EMPTY          nullstring
 #define STRINGLIB_ISDECIMAL(x)   ((x >= '0') && (x <= '9'))
 #define STRINGLIB_TODECIMAL(x)   (STRINGLIB_ISDECIMAL(x) ? (x - '0') : -1)
+#define STRINGLIB_TOUPPER        toupper
+#define STRINGLIB_TOLOWER        tolower
 #define STRINGLIB_FILL           memset
 #define STRINGLIB_STR            PyString_AS_STRING
 #define STRINGLIB_LEN            PyString_GET_SIZE

Modified: python/branches/py3k-importlib/Objects/stringlib/unicodedefs.h
==============================================================================
--- python/branches/py3k-importlib/Objects/stringlib/unicodedefs.h	(original)
+++ python/branches/py3k-importlib/Objects/stringlib/unicodedefs.h	Thu Mar 27 00:48:05 2008
@@ -6,6 +6,7 @@
    compiled as unicode. */
 #define STRINGLIB_IS_UNICODE     1
 
+#define STRINGLIB_OBJECT         PyUnicodeObject
 #define STRINGLIB_CHAR           Py_UNICODE
 #define STRINGLIB_TYPE_NAME      "unicode"
 #define STRINGLIB_PARSE_CODE     "U"
@@ -20,7 +21,14 @@
 #define STRINGLIB_NEW            PyUnicode_FromUnicode
 #define STRINGLIB_RESIZE         PyUnicode_Resize
 #define STRINGLIB_CHECK          PyUnicode_Check
+
+#if PY_VERSION_HEX < 0x03000000
 #define STRINGLIB_TOSTR          PyObject_Unicode
+#else
+#define STRINGLIB_TOSTR          PyObject_Str
+#endif
+
+#define STRINGLIB_WANT_CONTAINS_OBJ 1
 
 /* STRINGLIB_CMP was defined as:
 

Modified: python/branches/py3k-importlib/Objects/stringobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/stringobject.c	(original)
+++ python/branches/py3k-importlib/Objects/stringobject.c	Thu Mar 27 00:48:05 2008
@@ -1,259 +1,31 @@
 /* String object implementation */
 
+/* XXX This is now called 'bytes' as far as the user is concerned.
+   Many docstrings and error messages need to be cleaned up. */
+
 #define PY_SSIZE_T_CLEAN
 
 #include "Python.h"
 
-/* Our own locale-independent ctype.h-like macros */
-/* XXX Move into a header file? */
-
-#define FLAG_LOWER  0x01
-#define FLAG_UPPER  0x02
-#define FLAG_ALPHA  (FLAG_LOWER|FLAG_UPPER)
-#define FLAG_DIGIT  0x04
-#define FLAG_ALNUM  (FLAG_ALPHA|FLAG_DIGIT)
-#define FLAG_SPACE  0x08
-#define FLAG_XDIGIT 0x10
-
-static unsigned int ctype_table[256] = {
-    0, /* 0x0 '\x00' */
-    0, /* 0x1 '\x01' */
-    0, /* 0x2 '\x02' */
-    0, /* 0x3 '\x03' */
-    0, /* 0x4 '\x04' */
-    0, /* 0x5 '\x05' */
-    0, /* 0x6 '\x06' */
-    0, /* 0x7 '\x07' */
-    0, /* 0x8 '\x08' */
-    FLAG_SPACE, /* 0x9 '\t' */
-    FLAG_SPACE, /* 0xa '\n' */
-    FLAG_SPACE, /* 0xb '\v' */
-    FLAG_SPACE, /* 0xc '\f' */
-    FLAG_SPACE, /* 0xd '\r' */
-    0, /* 0xe '\x0e' */
-    0, /* 0xf '\x0f' */
-    0, /* 0x10 '\x10' */
-    0, /* 0x11 '\x11' */
-    0, /* 0x12 '\x12' */
-    0, /* 0x13 '\x13' */
-    0, /* 0x14 '\x14' */
-    0, /* 0x15 '\x15' */
-    0, /* 0x16 '\x16' */
-    0, /* 0x17 '\x17' */
-    0, /* 0x18 '\x18' */
-    0, /* 0x19 '\x19' */
-    0, /* 0x1a '\x1a' */
-    0, /* 0x1b '\x1b' */
-    0, /* 0x1c '\x1c' */
-    0, /* 0x1d '\x1d' */
-    0, /* 0x1e '\x1e' */
-    0, /* 0x1f '\x1f' */
-    FLAG_SPACE, /* 0x20 ' ' */
-    0, /* 0x21 '!' */
-    0, /* 0x22 '"' */
-    0, /* 0x23 '#' */
-    0, /* 0x24 '$' */
-    0, /* 0x25 '%' */
-    0, /* 0x26 '&' */
-    0, /* 0x27 "'" */
-    0, /* 0x28 '(' */
-    0, /* 0x29 ')' */
-    0, /* 0x2a '*' */
-    0, /* 0x2b '+' */
-    0, /* 0x2c ',' */
-    0, /* 0x2d '-' */
-    0, /* 0x2e '.' */
-    0, /* 0x2f '/' */
-    FLAG_DIGIT|FLAG_XDIGIT, /* 0x30 '0' */
-    FLAG_DIGIT|FLAG_XDIGIT, /* 0x31 '1' */
-    FLAG_DIGIT|FLAG_XDIGIT, /* 0x32 '2' */
-    FLAG_DIGIT|FLAG_XDIGIT, /* 0x33 '3' */
-    FLAG_DIGIT|FLAG_XDIGIT, /* 0x34 '4' */
-    FLAG_DIGIT|FLAG_XDIGIT, /* 0x35 '5' */
-    FLAG_DIGIT|FLAG_XDIGIT, /* 0x36 '6' */
-    FLAG_DIGIT|FLAG_XDIGIT, /* 0x37 '7' */
-    FLAG_DIGIT|FLAG_XDIGIT, /* 0x38 '8' */
-    FLAG_DIGIT|FLAG_XDIGIT, /* 0x39 '9' */
-    0, /* 0x3a ':' */
-    0, /* 0x3b ';' */
-    0, /* 0x3c '<' */
-    0, /* 0x3d '=' */
-    0, /* 0x3e '>' */
-    0, /* 0x3f '?' */
-    0, /* 0x40 '@' */
-    FLAG_UPPER|FLAG_XDIGIT, /* 0x41 'A' */
-    FLAG_UPPER|FLAG_XDIGIT, /* 0x42 'B' */
-    FLAG_UPPER|FLAG_XDIGIT, /* 0x43 'C' */
-    FLAG_UPPER|FLAG_XDIGIT, /* 0x44 'D' */
-    FLAG_UPPER|FLAG_XDIGIT, /* 0x45 'E' */
-    FLAG_UPPER|FLAG_XDIGIT, /* 0x46 'F' */
-    FLAG_UPPER, /* 0x47 'G' */
-    FLAG_UPPER, /* 0x48 'H' */
-    FLAG_UPPER, /* 0x49 'I' */
-    FLAG_UPPER, /* 0x4a 'J' */
-    FLAG_UPPER, /* 0x4b 'K' */
-    FLAG_UPPER, /* 0x4c 'L' */
-    FLAG_UPPER, /* 0x4d 'M' */
-    FLAG_UPPER, /* 0x4e 'N' */
-    FLAG_UPPER, /* 0x4f 'O' */
-    FLAG_UPPER, /* 0x50 'P' */
-    FLAG_UPPER, /* 0x51 'Q' */
-    FLAG_UPPER, /* 0x52 'R' */
-    FLAG_UPPER, /* 0x53 'S' */
-    FLAG_UPPER, /* 0x54 'T' */
-    FLAG_UPPER, /* 0x55 'U' */
-    FLAG_UPPER, /* 0x56 'V' */
-    FLAG_UPPER, /* 0x57 'W' */
-    FLAG_UPPER, /* 0x58 'X' */
-    FLAG_UPPER, /* 0x59 'Y' */
-    FLAG_UPPER, /* 0x5a 'Z' */
-    0, /* 0x5b '[' */
-    0, /* 0x5c '\\' */
-    0, /* 0x5d ']' */
-    0, /* 0x5e '^' */
-    0, /* 0x5f '_' */
-    0, /* 0x60 '`' */
-    FLAG_LOWER|FLAG_XDIGIT, /* 0x61 'a' */
-    FLAG_LOWER|FLAG_XDIGIT, /* 0x62 'b' */
-    FLAG_LOWER|FLAG_XDIGIT, /* 0x63 'c' */
-    FLAG_LOWER|FLAG_XDIGIT, /* 0x64 'd' */
-    FLAG_LOWER|FLAG_XDIGIT, /* 0x65 'e' */
-    FLAG_LOWER|FLAG_XDIGIT, /* 0x66 'f' */
-    FLAG_LOWER, /* 0x67 'g' */
-    FLAG_LOWER, /* 0x68 'h' */
-    FLAG_LOWER, /* 0x69 'i' */
-    FLAG_LOWER, /* 0x6a 'j' */
-    FLAG_LOWER, /* 0x6b 'k' */
-    FLAG_LOWER, /* 0x6c 'l' */
-    FLAG_LOWER, /* 0x6d 'm' */
-    FLAG_LOWER, /* 0x6e 'n' */
-    FLAG_LOWER, /* 0x6f 'o' */
-    FLAG_LOWER, /* 0x70 'p' */
-    FLAG_LOWER, /* 0x71 'q' */
-    FLAG_LOWER, /* 0x72 'r' */
-    FLAG_LOWER, /* 0x73 's' */
-    FLAG_LOWER, /* 0x74 't' */
-    FLAG_LOWER, /* 0x75 'u' */
-    FLAG_LOWER, /* 0x76 'v' */
-    FLAG_LOWER, /* 0x77 'w' */
-    FLAG_LOWER, /* 0x78 'x' */
-    FLAG_LOWER, /* 0x79 'y' */
-    FLAG_LOWER, /* 0x7a 'z' */
-    0, /* 0x7b '{' */
-    0, /* 0x7c '|' */
-    0, /* 0x7d '}' */
-    0, /* 0x7e '~' */
-    0, /* 0x7f '\x7f' */
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
-#define ISLOWER(c) (ctype_table[Py_CHARMASK(c)] & FLAG_LOWER)
-#define ISUPPER(c) (ctype_table[Py_CHARMASK(c)] & FLAG_UPPER)
-#define ISALPHA(c) (ctype_table[Py_CHARMASK(c)] & FLAG_ALPHA)
-#define ISDIGIT(c) (ctype_table[Py_CHARMASK(c)] & FLAG_DIGIT)
-#define ISXDIGIT(c) (ctype_table[Py_CHARMASK(c)] & FLAG_XDIGIT)
-#define ISALNUM(c) (ctype_table[Py_CHARMASK(c)] & FLAG_ALNUM)
-#define ISSPACE(c) (ctype_table[Py_CHARMASK(c)] & FLAG_SPACE)
-
-#undef islower
-#define islower(c) undefined_islower(c)
-#undef isupper
-#define isupper(c) undefined_isupper(c)
-#undef isalpha
-#define isalpha(c) undefined_isalpha(c)
-#undef isdigit
-#define isdigit(c) undefined_isdigit(c)
-#undef isxdigit
-#define isxdigit(c) undefined_isxdigit(c)
-#undef isalnum
-#define isalnum(c) undefined_isalnum(c)
-#undef isspace
-#define isspace(c) undefined_isspace(c)
-
-static unsigned char ctype_tolower[256] = {
-    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
-    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
-    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
-    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
-    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
-    0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
-    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
-    0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
-    0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
-    0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
-    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
-    0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
-    0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
-    0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
-    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
-    0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
-    0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
-    0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
-    0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
-    0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
-    0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
-    0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
-    0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
-    0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
-    0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
-    0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
-    0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
-    0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
-    0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
-    0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
-    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
-    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
-};
+#include "bytes_methods.h"
 
-static unsigned char ctype_toupper[256] = {
-    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
-    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
-    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
-    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
-    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
-    0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
-    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
-    0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
-    0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
-    0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
-    0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
-    0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
-    0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
-    0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
-    0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
-    0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
-    0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
-    0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
-    0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
-    0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
-    0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
-    0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
-    0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
-    0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
-    0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
-    0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
-    0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
-    0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
-    0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
-    0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
-    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
-    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
-};
+static Py_ssize_t
+_getbuffer(PyObject *obj, Py_buffer *view)
+{
+    PyBufferProcs *buffer = Py_TYPE(obj)->tp_as_buffer;
 
-#define TOLOWER(c) (ctype_tolower[Py_CHARMASK(c)])
-#define TOUPPER(c) (ctype_toupper[Py_CHARMASK(c)])
+    if (buffer == NULL || buffer->bf_getbuffer == NULL)
+    {
+        PyErr_Format(PyExc_TypeError,
+                     "Type %.100s doesn't support the buffer API",
+                     Py_TYPE(obj)->tp_name);
+        return -1;
+    }
 
-#undef tolower
-#define tolower(c) undefined_tolower(c)
-#undef toupper
-#define toupper(c) undefined_toupper(c)
+    if (buffer->bf_getbuffer(obj, view, PyBUF_SIMPLE) < 0)
+            return -1;
+    return view->len;
+}
 
 #ifdef COUNT_ALLOCS
 int null_strings, one_strings;
@@ -262,16 +34,6 @@
 static PyStringObject *characters[UCHAR_MAX + 1];
 static PyStringObject *nullstring;
 
-/* This dictionary holds all interned strings.  Note that references to
-   strings in this dictionary are *not* counted in the string's ob_refcnt.
-   When the interned string reaches a refcnt of 0 the string deallocation
-   function will delete the reference from this dictionary.
-
-   Another way to look at this is that to say that the actual reference
-   count of a string is:  s->ob_refcnt + (s->ob_sstate?2:0)
-*/
-static PyObject *interned;
-
 /*
    For both PyString_FromString() and PyString_FromStringAndSize(), the
    parameter `size' denotes number of characters to allocate, not counting any
@@ -326,21 +88,14 @@
 		return PyErr_NoMemory();
 	PyObject_INIT_VAR(op, &PyString_Type, size);
 	op->ob_shash = -1;
-	op->ob_sstate = SSTATE_NOT_INTERNED;
 	if (str != NULL)
 		Py_MEMCPY(op->ob_sval, str, size);
 	op->ob_sval[size] = '\0';
 	/* share short strings */
 	if (size == 0) {
-		PyObject *t = (PyObject *)op;
-		PyString_InternInPlace(&t);
-		op = (PyStringObject *)t;
 		nullstring = op;
 		Py_INCREF(op);
 	} else if (size == 1 && str != NULL) {
-		PyObject *t = (PyObject *)op;
-		PyString_InternInPlace(&t);
-		op = (PyStringObject *)t;
 		characters[*str & UCHAR_MAX] = op;
 		Py_INCREF(op);
 	}
@@ -381,19 +136,12 @@
 		return PyErr_NoMemory();
 	PyObject_INIT_VAR(op, &PyString_Type, size);
 	op->ob_shash = -1;
-	op->ob_sstate = SSTATE_NOT_INTERNED;
 	Py_MEMCPY(op->ob_sval, str, size+1);
 	/* share short strings */
 	if (size == 0) {
-		PyObject *t = (PyObject *)op;
-		PyString_InternInPlace(&t);
-		op = (PyStringObject *)t;
 		nullstring = op;
 		Py_INCREF(op);
 	} else if (size == 1) {
-		PyObject *t = (PyObject *)op;
-		PyString_InternInPlace(&t);
-		op = (PyStringObject *)t;
 		characters[*str & UCHAR_MAX] = op;
 		Py_INCREF(op);
 	}
@@ -600,175 +348,10 @@
 	return ret;
 }
 
-
-PyObject *PyString_Decode(const char *s,
-			  Py_ssize_t size,
-			  const char *encoding,
-			  const char *errors)
-{
-    PyObject *v, *str;
-
-    str = PyString_FromStringAndSize(s, size);
-    if (str == NULL)
-	return NULL;
-    v = PyString_AsDecodedString(str, encoding, errors);
-    Py_DECREF(str);
-    return v;
-}
-
-PyObject *PyString_AsDecodedObject(PyObject *str,
-				   const char *encoding,
-				   const char *errors)
-{
-    PyObject *v;
-
-    if (!PyString_Check(str)) {
-        PyErr_BadArgument();
-        goto onError;
-    }
-
-    if (encoding == NULL) {
-	encoding = PyUnicode_GetDefaultEncoding();
-    }
-
-    /* Decode via the codec registry */
-    v = PyCodec_Decode(str, encoding, errors);
-    if (v == NULL)
-        goto onError;
-
-    return v;
-
- onError:
-    return NULL;
-}
-
-PyObject *PyString_AsDecodedString(PyObject *str,
-				   const char *encoding,
-				   const char *errors)
-{
-    PyObject *v;
-
-    v = PyString_AsDecodedObject(str, encoding, errors);
-    if (v == NULL)
-        goto onError;
-
-    /* Convert Unicode to a string using the default encoding */
-    if (PyUnicode_Check(v)) {
-	PyObject *temp = v;
-	v = PyUnicode_AsEncodedString(v, NULL, NULL);
-	Py_DECREF(temp);
-	if (v == NULL)
-	    goto onError;
-    }
-    if (!PyString_Check(v)) {
-        PyErr_Format(PyExc_TypeError,
-                     "decoder did not return a string object (type=%.400s)",
-                     Py_Type(v)->tp_name);
-        Py_DECREF(v);
-        goto onError;
-    }
-
-    return v;
-
- onError:
-    return NULL;
-}
-
-PyObject *PyString_Encode(const char *s,
-			  Py_ssize_t size,
-			  const char *encoding,
-			  const char *errors)
-{
-    PyObject *v, *str;
-
-    str = PyString_FromStringAndSize(s, size);
-    if (str == NULL)
-	return NULL;
-    v = PyString_AsEncodedString(str, encoding, errors);
-    Py_DECREF(str);
-    return v;
-}
-
-PyObject *PyString_AsEncodedObject(PyObject *str,
-				   const char *encoding,
-				   const char *errors)
-{
-    PyObject *v;
-
-    if (!PyString_Check(str)) {
-        PyErr_BadArgument();
-        goto onError;
-    }
-
-    if (encoding == NULL) {
-	encoding = PyUnicode_GetDefaultEncoding();
-    }
-
-    /* Encode via the codec registry */
-    v = PyCodec_Encode(str, encoding, errors);
-    if (v == NULL)
-        goto onError;
-
-    return v;
-
- onError:
-    return NULL;
-}
-
-PyObject *PyString_AsEncodedString(PyObject *str,
-				   const char *encoding,
-				   const char *errors)
-{
-    PyObject *v;
-
-    v = PyString_AsEncodedObject(str, encoding, errors);
-    if (v == NULL)
-        goto onError;
-
-    /* Convert Unicode to a string using the default encoding */
-    if (PyUnicode_Check(v)) {
-	PyObject *temp = v;
-	v = PyUnicode_AsEncodedString(v, NULL, NULL);
-	Py_DECREF(temp);
-	if (v == NULL)
-	    goto onError;
-    }
-    if (!PyString_Check(v)) {
-        PyErr_Format(PyExc_TypeError,
-                     "encoder did not return a string object (type=%.400s)",
-                     Py_Type(v)->tp_name);
-        Py_DECREF(v);
-        goto onError;
-    }
-
-    return v;
-
- onError:
-    return NULL;
-}
-
 static void
 string_dealloc(PyObject *op)
 {
-	switch (PyString_CHECK_INTERNED(op)) {
-		case SSTATE_NOT_INTERNED:
-			break;
-
-		case SSTATE_INTERNED_MORTAL:
-			/* revive dead object temporarily for DelItem */
-			Py_Refcnt(op) = 3;
-			if (PyDict_DelItem(interned, op) != 0)
-				Py_FatalError(
-					"deletion of interned string failed");
-			break;
-
-		case SSTATE_INTERNED_IMMORTAL:
-			Py_FatalError("Immortal interned string died.");
-
-		default:
-			Py_FatalError("Inconsistent interned string state.");
-	}
-	Py_Type(op)->tp_free(op);
+	Py_TYPE(op)->tp_free(op);
 }
 
 /* Unescape a backslash-escaped string. If unicode is non-zero,
@@ -826,7 +409,7 @@
 			continue;
 		}
 		s++;
-                if (s==end) {
+		if (s==end) {
 			PyErr_SetString(PyExc_ValueError,
 					"Trailing \\ in string");
 			goto failed;
@@ -847,15 +430,15 @@
 		case '0': case '1': case '2': case '3':
 		case '4': case '5': case '6': case '7':
 			c = s[-1] - '0';
-			if ('0' <= *s && *s <= '7') {
+			if (s < end && '0' <= *s && *s <= '7') {
 				c = (c<<3) + *s++ - '0';
-				if ('0' <= *s && *s <= '7')
+				if (s < end && '0' <= *s && *s <= '7')
 					c = (c<<3) + *s++ - '0';
 			}
 			*p++ = c;
 			break;
 		case 'x':
-			if (ISXDIGIT(s[0]) && ISXDIGIT(s[1])) {
+			if (s+1 < end && ISXDIGIT(s[0]) && ISXDIGIT(s[1])) {
 				unsigned int x = 0;
 				c = Py_CHARMASK(*s);
 				s++;
@@ -888,8 +471,8 @@
 				/* do nothing */;
 			else {
 				PyErr_Format(PyExc_ValueError,
-					     "decoding error; "
-					     "unknown error handling code: %.400s",
+					     "decoding error; unknown "
+					     "error handling code: %.400s",
 					     errors);
 				goto failed;
 			}
@@ -911,50 +494,26 @@
 /* -------------------------------------------------------------------- */
 /* object api */
 
-static Py_ssize_t
-string_getsize(register PyObject *op)
-{
-    	char *s;
-    	Py_ssize_t len;
-	if (PyString_AsStringAndSize(op, &s, &len))
-		return -1;
-	return len;
-}
-
-static /*const*/ char *
-string_getbuffer(register PyObject *op)
-{
-    	char *s;
-    	Py_ssize_t len;
-	if (PyString_AsStringAndSize(op, &s, &len))
-		return NULL;
-	return s;
-}
-
 Py_ssize_t
 PyString_Size(register PyObject *op)
 {
-	if (PyUnicode_Check(op)) {
-		op = _PyUnicode_AsDefaultEncodedString(op, NULL);
-		if (!op)
-			return -1;
+	if (!PyString_Check(op)) {
+		PyErr_Format(PyExc_TypeError,
+		     "expected bytes, %.200s found", Py_TYPE(op)->tp_name);
+		return -1;
 	}
-	if (!PyString_Check(op))
-		return string_getsize(op);
-	return Py_Size(op);
+	return Py_SIZE(op);
 }
 
-/*const*/ char *
+char *
 PyString_AsString(register PyObject *op)
 {
-	if (PyUnicode_Check(op)) {
-		op = _PyUnicode_AsDefaultEncodedString(op, NULL);
-		if (!op)
-			return NULL;
+	if (!PyString_Check(op)) {
+		PyErr_Format(PyExc_TypeError,
+		     "expected bytes, %.200s found", Py_TYPE(op)->tp_name);
+		return NULL;
 	}
-	if (!PyString_Check(op))
-		return string_getbuffer(op);
-	return ((PyStringObject *)op) -> ob_sval;
+	return ((PyStringObject *)op)->ob_sval;
 }
 
 int
@@ -968,18 +527,9 @@
 	}
 
 	if (!PyString_Check(obj)) {
-		if (PyUnicode_Check(obj)) {
-			obj = _PyUnicode_AsDefaultEncodedString(obj, NULL);
-			if (obj == NULL)
-				return -1;
-		}
-		else
-		{
-			PyErr_Format(PyExc_TypeError,
-				     "expected string, "
-				     "%.200s found", Py_Type(obj)->tp_name);
-			return -1;
-		}
+		PyErr_Format(PyExc_TypeError,
+		     "expected bytes, %.200s found", Py_TYPE(obj)->tp_name);
+		return -1;
 	}
 
 	*s = PyString_AS_STRING(obj);
@@ -987,7 +537,7 @@
 		*len = PyString_GET_SIZE(obj);
 	else if (strlen(*s) != (size_t)PyString_GET_SIZE(obj)) {
 		PyErr_SetString(PyExc_TypeError,
-				"expected string without null bytes");
+				"expected bytes with no null");
 		return -1;
 	}
 	return 0;
@@ -1002,14 +552,19 @@
 #define STRINGLIB_LEN PyString_GET_SIZE
 #define STRINGLIB_NEW PyString_FromStringAndSize
 #define STRINGLIB_STR PyString_AS_STRING
+/* #define STRINGLIB_WANT_CONTAINS_OBJ 1 */
 
 #define STRINGLIB_EMPTY nullstring
+#define STRINGLIB_CHECK_EXACT PyString_CheckExact
+#define STRINGLIB_MUTABLE 0
 
 #include "stringlib/fastsearch.h"
 
 #include "stringlib/count.h"
 #include "stringlib/find.h"
 #include "stringlib/partition.h"
+#include "stringlib/ctype.h"
+#include "stringlib/transmogrify.h"
 
 
 PyObject *
@@ -1017,12 +572,13 @@
 {
 	static const char *hexdigits = "0123456789abcdef";
 	register PyStringObject* op = (PyStringObject*) obj;
-	Py_ssize_t length = PyString_GET_SIZE(op);
-	size_t newsize = 3 + 4 * Py_Size(op);
+	Py_ssize_t length = Py_SIZE(op);
+	size_t newsize = 3 + 4 * length;
 	PyObject *v;
-	if (newsize > PY_SSIZE_T_MAX || newsize / 4 != Py_Size(op)) {
+	if (newsize > PY_SSIZE_T_MAX || (newsize-3) / 4 != length) {
 		PyErr_SetString(PyExc_OverflowError,
-			"string is too large to make repr");
+			"bytes object is too large to make repr");
+                return NULL;
 	}
 	v = PyUnicode_FromUnicode(NULL, newsize);
 	if (v == NULL) {
@@ -1034,14 +590,14 @@
 		register Py_UNICODE *p = PyUnicode_AS_UNICODE(v);
 		int quote;
 
-		/* figure out which quote to use; single is preferred */
+		/* Figure out which quote to use; single is preferred */
 		quote = '\'';
 		if (smartquotes) {
 			char *test, *start;
 			start = PyString_AS_STRING(op);
 			for (test = start; test < start+length; ++test) {
 				if (*test == '"') {
-					quote = '\''; /* switch back to single quote */
+					quote = '\''; /* back to single */
 					goto decided;
 				}
 				else if (*test == '\'')
@@ -1051,8 +607,8 @@
 			;
 		}
 
-		*p++ = 's', *p++ = quote;
-		for (i = 0; i < Py_Size(op); i++) {
+		*p++ = 'b', *p++ = quote;
+		for (i = 0; i < length; i++) {
 			/* There's at least enough room for a hex escape
 			   and a closing quote. */
 			assert(newsize - (p - PyUnicode_AS_UNICODE(v)) >= 5);
@@ -1092,71 +648,69 @@
 }
 
 static PyObject *
-string_str(PyObject *s)
+string_str(PyObject *op)
 {
-	assert(PyString_Check(s));
-	if (PyString_CheckExact(s)) {
-		Py_INCREF(s);
-		return s;
-	}
-	else {
-		/* Subtype -- return genuine string with the same value. */
-		PyStringObject *t = (PyStringObject *) s;
-		return PyString_FromStringAndSize(t->ob_sval, Py_Size(t));
+	if (Py_BytesWarningFlag) {
+		if (PyErr_WarnEx(PyExc_BytesWarning,
+				 "str() on a bytes instance", 1))
+			return NULL;
 	}
+	return string_repr(op);
 }
 
 static Py_ssize_t
 string_length(PyStringObject *a)
 {
-	return Py_Size(a);
+	return Py_SIZE(a);
 }
 
+/* This is also used by PyString_Concat() */
 static PyObject *
-string_concat(register PyStringObject *a, register PyObject *bb)
+string_concat(PyObject *a, PyObject *b)
 {
-	register Py_ssize_t size;
-	register PyStringObject *op;
-	if (!PyString_Check(bb)) {
-		if (PyUnicode_Check(bb))
-		    return PyUnicode_Concat((PyObject *)a, bb);
-                if (PyBytes_Check(bb))
-			return PyBytes_Concat((PyObject *)a, bb);
-		PyErr_Format(PyExc_TypeError,
-			     "cannot concatenate 'str8' and '%.200s' objects",
-			     Py_Type(bb)->tp_name);
-		return NULL;
-	}
-#define b ((PyStringObject *)bb)
-	/* Optimize cases with empty left or right operand */
-	if ((Py_Size(a) == 0 || Py_Size(b) == 0) &&
-	    PyString_CheckExact(a) && PyString_CheckExact(b)) {
-		if (Py_Size(a) == 0) {
-			Py_INCREF(bb);
-			return bb;
-		}
-		Py_INCREF(a);
-		return (PyObject *)a;
+	Py_ssize_t size;
+	Py_buffer va, vb;
+	PyObject *result = NULL;
+
+	va.len = -1;
+	vb.len = -1;
+	if (_getbuffer(a, &va) < 0  ||
+	    _getbuffer(b, &vb) < 0) {
+		PyErr_Format(PyExc_TypeError, "can't concat %.100s to %.100s",
+			     Py_TYPE(a)->tp_name, Py_TYPE(b)->tp_name);
+		goto done;
+	}
+
+	/* Optimize end cases */
+	if (va.len == 0 && PyString_CheckExact(b)) {
+		result = b;
+		Py_INCREF(result);
+		goto done;
+	}
+	if (vb.len == 0 && PyString_CheckExact(a)) {
+		result = a;
+		Py_INCREF(result);
+		goto done;
 	}
-	size = Py_Size(a) + Py_Size(b);
+
+	size = va.len + vb.len;
 	if (size < 0) {
-		PyErr_SetString(PyExc_OverflowError,
-				"strings are too large to concat");
-		return NULL;
+		PyErr_NoMemory();
+		goto done;
 	}
-	  
-	/* Inline PyObject_NewVar */
-	op = (PyStringObject *)PyObject_MALLOC(sizeof(PyStringObject) + size);
-	if (op == NULL)
-		return PyErr_NoMemory();
-	PyObject_INIT_VAR(op, &PyString_Type, size);
-	op->ob_shash = -1;
-	op->ob_sstate = SSTATE_NOT_INTERNED;
-	Py_MEMCPY(op->ob_sval, a->ob_sval, Py_Size(a));
-	Py_MEMCPY(op->ob_sval + Py_Size(a), b->ob_sval, Py_Size(b));
-	op->ob_sval[size] = '\0';
-	return (PyObject *) op;
-#undef b
+
+	result = PyString_FromStringAndSize(NULL, size);
+	if (result != NULL) {
+		memcpy(PyString_AS_STRING(result), va.buf, va.len);
+		memcpy(PyString_AS_STRING(result) + va.len, vb.buf, vb.len);
+	}
+
+  done:
+	if (va.len != -1)
+		PyObject_ReleaseBuffer(a, &va);
+	if (vb.len != -1)
+		PyObject_ReleaseBuffer(b, &vb);
+	return result;
 }
 
 static PyObject *
@@ -1172,13 +726,13 @@
 	/* watch out for overflows:  the size can overflow int,
 	 * and the # of bytes needed can overflow size_t
 	 */
-	size = Py_Size(a) * n;
-	if (n && size / n != Py_Size(a)) {
+	size = Py_SIZE(a) * n;
+	if (n && size / n != Py_SIZE(a)) {
 		PyErr_SetString(PyExc_OverflowError,
 			"repeated string is too long");
 		return NULL;
 	}
-	if (size == Py_Size(a) && PyString_CheckExact(a)) {
+	if (size == Py_SIZE(a) && PyString_CheckExact(a)) {
 		Py_INCREF(a);
 		return (PyObject *)a;
 	}
@@ -1194,16 +748,15 @@
 		return PyErr_NoMemory();
 	PyObject_INIT_VAR(op, &PyString_Type, size);
 	op->ob_shash = -1;
-	op->ob_sstate = SSTATE_NOT_INTERNED;
 	op->ob_sval[size] = '\0';
-	if (Py_Size(a) == 1 && n > 0) {
+	if (Py_SIZE(a) == 1 && n > 0) {
 		memset(op->ob_sval, a->ob_sval[0] , n);
 		return (PyObject *) op;
 	}
 	i = 0;
 	if (i < size) {
-		Py_MEMCPY(op->ob_sval, a->ob_sval, Py_Size(a));
-		i = Py_Size(a);
+		Py_MEMCPY(op->ob_sval, a->ob_sval, Py_SIZE(a));
+		i = Py_SIZE(a);
 	}
 	while (i < size) {
 		j = (i <= size-i)  ?  i  :  size-i;
@@ -1214,42 +767,36 @@
 }
 
 static int
-string_contains(PyObject *str_obj, PyObject *sub_obj)
+string_contains(PyObject *self, PyObject *arg)
 {
-	if (!PyString_CheckExact(sub_obj)) {
-		if (PyUnicode_Check(sub_obj))
-			return PyUnicode_Contains(str_obj, sub_obj);
-		if (!PyString_Check(sub_obj)) {
-			PyErr_Format(PyExc_TypeError,
-			    "'in <string>' requires string as left operand, "
-			    "not %.200s", Py_Type(sub_obj)->tp_name);
-			return -1;
-		}
-	}
+    Py_ssize_t ival = PyNumber_AsSsize_t(arg, PyExc_ValueError);
+    if (ival == -1 && PyErr_Occurred()) {
+        Py_buffer varg;
+        int pos;
+        PyErr_Clear();
+        if (_getbuffer(arg, &varg) < 0)
+            return -1;
+        pos = stringlib_find(PyString_AS_STRING(self), Py_SIZE(self),
+                             varg.buf, varg.len, 0);
+        PyObject_ReleaseBuffer(arg, &varg);
+        return pos >= 0;
+    }
+    if (ival < 0 || ival >= 256) {
+        PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
+        return -1;
+    }
 
-	return stringlib_contains_obj(str_obj, sub_obj);
+    return memchr(PyString_AS_STRING(self), ival, Py_SIZE(self)) != NULL;
 }
 
 static PyObject *
 string_item(PyStringObject *a, register Py_ssize_t i)
 {
-	char pchar;
-	PyObject *v;
-	if (i < 0 || i >= Py_Size(a)) {
+	if (i < 0 || i >= Py_SIZE(a)) {
 		PyErr_SetString(PyExc_IndexError, "string index out of range");
 		return NULL;
 	}
-	pchar = a->ob_sval[i];
-	v = (PyObject *)characters[pchar & UCHAR_MAX];
-	if (v == NULL)
-		v = PyString_FromStringAndSize(&pchar, 1);
-	else {
-#ifdef COUNT_ALLOCS
-		one_strings++;
-#endif
-		Py_INCREF(v);
-	}
-	return v;
+	return PyLong_FromLong((unsigned char)a->ob_sval[i]);
 }
 
 static PyObject*
@@ -1262,6 +809,15 @@
 
 	/* Make sure both arguments are strings. */
 	if (!(PyString_Check(a) && PyString_Check(b))) {
+		if (Py_BytesWarningFlag && (op == Py_EQ) &&
+		    (PyObject_IsInstance((PyObject*)a,
+					 (PyObject*)&PyUnicode_Type) ||
+		    PyObject_IsInstance((PyObject*)b,
+					 (PyObject*)&PyUnicode_Type))) {
+			if (PyErr_WarnEx(PyExc_BytesWarning,
+				    "Comparsion between bytes and string", 1))
+				return NULL;
+		}
 		result = Py_NotImplemented;
 		goto out;
 	}
@@ -1278,16 +834,16 @@
 	if (op == Py_EQ) {
 		/* Supporting Py_NE here as well does not save
 		   much time, since Py_NE is rarely used.  */
-		if (Py_Size(a) == Py_Size(b)
+		if (Py_SIZE(a) == Py_SIZE(b)
 		    && (a->ob_sval[0] == b->ob_sval[0]
-			&& memcmp(a->ob_sval, b->ob_sval, Py_Size(a)) == 0)) {
+			&& memcmp(a->ob_sval, b->ob_sval, Py_SIZE(a)) == 0)) {
 			result = Py_True;
 		} else {
 			result = Py_False;
 		}
 		goto out;
 	}
-	len_a = Py_Size(a); len_b = Py_Size(b);
+	len_a = Py_SIZE(a); len_b = Py_SIZE(b);
 	min_len = (len_a < len_b) ? len_a : len_b;
 	if (min_len > 0) {
 		c = Py_CHARMASK(*a->ob_sval) - Py_CHARMASK(*b->ob_sval);
@@ -1314,16 +870,6 @@
 	return result;
 }
 
-int
-_PyString_Eq(PyObject *o1, PyObject *o2)
-{
-	PyStringObject *a = (PyStringObject*) o1;
-	PyStringObject *b = (PyStringObject*) o2;
-        return Py_Size(a) == Py_Size(b)
-          && *a->ob_sval == *b->ob_sval
-          && memcmp(a->ob_sval, b->ob_sval, Py_Size(a)) == 0;
-}
-
 static long
 string_hash(PyStringObject *a)
 {
@@ -1333,12 +879,12 @@
 
 	if (a->ob_shash != -1)
 		return a->ob_shash;
-	len = Py_Size(a);
+	len = Py_SIZE(a);
 	p = (unsigned char *) a->ob_sval;
 	x = *p << 7;
 	while (--len >= 0)
 		x = (1000003*x) ^ *p++;
-	x ^= Py_Size(a);
+	x ^= Py_SIZE(a);
 	if (x == -1)
 		x = -2;
 	a->ob_shash = x;
@@ -1354,7 +900,12 @@
 			return NULL;
 		if (i < 0)
 			i += PyString_GET_SIZE(self);
-		return string_item(self, i);
+		if (i < 0 || i >= PyString_GET_SIZE(self)) {
+			PyErr_SetString(PyExc_IndexError,
+					"string index out of range");
+			return NULL;
+		}
+		return PyLong_FromLong((unsigned char)self->ob_sval[i]);
 	}
 	else if (PySlice_Check(item)) {
 		Py_ssize_t start, stop, step, slicelength, cur, i;
@@ -1402,7 +953,7 @@
 	else {
 		PyErr_Format(PyExc_TypeError,
 			     "string indices must be integers, not %.200s",
-			     Py_Type(item)->tp_name);
+			     Py_TYPE(item)->tp_name);
 		return NULL;
 	}
 }
@@ -1410,7 +961,8 @@
 static int
 string_buffer_getbuffer(PyStringObject *self, Py_buffer *view, int flags)
 {
-        return PyBuffer_FillInfo(view, (void *)self->ob_sval, Py_Size(self), 0, flags);
+	return PyBuffer_FillInfo(view, (void *)self->ob_sval, Py_SIZE(self),
+				 0, flags);
 }
 
 static PySequenceMethods string_as_sequence = {
@@ -1432,7 +984,7 @@
 
 static PyBufferProcs string_as_buffer = {
 	(getbufferproc)string_buffer_getbuffer,
-        NULL,
+	NULL,
 };
 
 
@@ -1466,18 +1018,6 @@
 #define PREALLOC_SIZE(maxsplit) \
 	(maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
 
-#define SPLIT_APPEND(data, left, right)				\
-	str = PyString_FromStringAndSize((data) + (left),	\
-					 (right) - (left));	\
-	if (str == NULL)					\
-		goto onError;					\
-	if (PyList_Append(list, str)) {				\
-		Py_DECREF(str);					\
-		goto onError;					\
-	}							\
-	else							\
-		Py_DECREF(str);
-
 #define SPLIT_ADD(data, left, right) {				\
 	str = PyString_FromStringAndSize((data) + (left),	\
 					 (right) - (left));	\
@@ -1496,7 +1036,7 @@
 	count++; }
 
 /* Always force the list to the expected size. */
-#define FIX_PREALLOC_SIZE(list) Py_Size(list) = count
+#define FIX_PREALLOC_SIZE(list) Py_SIZE(list) = count
 
 #define SKIP_SPACE(s, i, len)    { while (i<len &&  ISSPACE(s[i])) i++; }
 #define SKIP_NONSPACE(s, i, len) { while (i<len && !ISSPACE(s[i])) i++; }
@@ -1504,8 +1044,9 @@
 #define RSKIP_NONSPACE(s, i)     { while (i>=0  && !ISSPACE(s[i])) i--; }
 
 Py_LOCAL_INLINE(PyObject *)
-split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
+split_whitespace(PyStringObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
 {
+	const char *s = PyString_AS_STRING(self);
 	Py_ssize_t i, j, count=0;
 	PyObject *str;
 	PyObject *list = PyList_New(PREALLOC_SIZE(maxsplit));
@@ -1520,6 +1061,13 @@
 		if (i==len) break;
 		j = i; i++;
 		SKIP_NONSPACE(s, i, len);
+		if (j == 0 && i == len && PyString_CheckExact(self)) {
+			/* No whitespace in self, so just use it as list[0] */
+			Py_INCREF(self);
+			PyList_SET_ITEM(list, 0, (PyObject *)self);
+			count++;
+			break;
+		}
 		SPLIT_ADD(s, j, i);
 	}
 
@@ -1538,8 +1086,9 @@
 }
 
 Py_LOCAL_INLINE(PyObject *)
-split_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount)
+split_char(PyStringObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
 {
+	const char *s = PyString_AS_STRING(self);
 	register Py_ssize_t i, j, count=0;
 	PyObject *str;
 	PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
@@ -1558,7 +1107,13 @@
 			}
 		}
 	}
-	if (i <= len) {
+	if (i == 0 && count == 0 && PyString_CheckExact(self)) {
+		/* ch not in self, so just use self as list[0] */
+		Py_INCREF(self);
+		PyList_SET_ITEM(list, 0, (PyObject *)self);
+		count++;
+	}
+	else if (i <= len) {
 		SPLIT_ADD(s, i, len);
 	}
 	FIX_PREALLOC_SIZE(list);
@@ -1570,12 +1125,12 @@
 }
 
 PyDoc_STRVAR(split__doc__,
-"S.split([sep [,maxsplit]]) -> list of strings\n\
+"B.split([sep[, maxsplit]]) -> list of bytes\n\
 \n\
-Return a list of the words in the string S, using sep as the\n\
-delimiter string.  If maxsplit is given, at most maxsplit\n\
-splits are done. If sep is not specified or is None, any\n\
-whitespace string is a separator.");
+Return a list of the sections in B, using sep as the delimiter.\n\
+If sep is not given, B is split on ASCII whitespace characters\n\
+(space, tab, return, newline, formfeed, vertical tab).\n\
+If maxsplit is given, at most maxsplit splits are done.");
 
 static PyObject *
 string_split(PyStringObject *self, PyObject *args)
@@ -1583,6 +1138,7 @@
 	Py_ssize_t len = PyString_GET_SIZE(self), n, i, j;
 	Py_ssize_t maxsplit = -1, count=0;
 	const char *s = PyString_AS_STRING(self), *sub;
+	Py_buffer vsub;
 	PyObject *list, *str, *subobj = Py_None;
 #ifdef USE_FAST
 	Py_ssize_t pos;
@@ -1593,26 +1149,25 @@
 	if (maxsplit < 0)
 		maxsplit = PY_SSIZE_T_MAX;
 	if (subobj == Py_None)
-		return split_whitespace(s, len, maxsplit);
-	if (PyString_Check(subobj)) {
-		sub = PyString_AS_STRING(subobj);
-		n = PyString_GET_SIZE(subobj);
-	}
-	else if (PyUnicode_Check(subobj))
-		return PyUnicode_Split((PyObject *)self, subobj, maxsplit);
-	else if (PyObject_AsCharBuffer(subobj, &sub, &n))
+		return split_whitespace(self, len, maxsplit);
+	if (_getbuffer(subobj, &vsub) < 0)
 		return NULL;
+	sub = vsub.buf;
+	n = vsub.len;
 
 	if (n == 0) {
 		PyErr_SetString(PyExc_ValueError, "empty separator");
+		PyObject_ReleaseBuffer(subobj, &vsub);
 		return NULL;
 	}
 	else if (n == 1)
-		return split_char(s, len, sub[0], maxsplit);
+		return split_char(self, len, sub[0], maxsplit);
 
 	list = PyList_New(PREALLOC_SIZE(maxsplit));
-	if (list == NULL)
+	if (list == NULL) {
+		PyObject_ReleaseBuffer(subobj, &vsub);
 		return NULL;
+	}
 
 #ifdef USE_FAST
 	i = j = 0;
@@ -1638,19 +1193,21 @@
 #endif
 	SPLIT_ADD(s, i, len);
 	FIX_PREALLOC_SIZE(list);
+	PyObject_ReleaseBuffer(subobj, &vsub);
 	return list;
 
  onError:
 	Py_DECREF(list);
+	PyObject_ReleaseBuffer(subobj, &vsub);
 	return NULL;
 }
 
 PyDoc_STRVAR(partition__doc__,
-"S.partition(sep) -> (head, sep, tail)\n\
+"B.partition(sep) -> (head, sep, tail)\n\
 \n\
-Searches for the separator sep in S, and returns the part before it,\n\
+Searches for the separator sep in B, and returns the part before it,\n\
 the separator itself, and the part after it.  If the separator is not\n\
-found, returns S and two empty strings.");
+found, returns B and two empty bytes objects.");
 
 static PyObject *
 string_partition(PyStringObject *self, PyObject *sep_obj)
@@ -1662,8 +1219,6 @@
 		sep = PyString_AS_STRING(sep_obj);
 		sep_len = PyString_GET_SIZE(sep_obj);
 	}
-	else if (PyUnicode_Check(sep_obj))
-		return PyUnicode_Partition((PyObject *) self, sep_obj);
 	else if (PyObject_AsCharBuffer(sep_obj, &sep, &sep_len))
 		return NULL;
 
@@ -1675,11 +1230,12 @@
 }
 
 PyDoc_STRVAR(rpartition__doc__,
-"S.rpartition(sep) -> (tail, sep, head)\n\
+"B.rpartition(sep) -> (tail, sep, head)\n\
 \n\
-Searches for the separator sep in S, starting at the end of S, and returns\n\
-the part before it, the separator itself, and the part after it.  If the\n\
-separator is not found, returns two empty strings and S.");
+Searches for the separator sep in B, starting at the end of B,\n\
+and returns the part before it, the separator itself, and the\n\
+part after it.  If the separator is not found, returns two empty\n\
+bytes objects and B.");
 
 static PyObject *
 string_rpartition(PyStringObject *self, PyObject *sep_obj)
@@ -1691,8 +1247,6 @@
 		sep = PyString_AS_STRING(sep_obj);
 		sep_len = PyString_GET_SIZE(sep_obj);
 	}
-	else if (PyUnicode_Check(sep_obj))
-		return PyUnicode_Partition((PyObject *) self, sep_obj);
 	else if (PyObject_AsCharBuffer(sep_obj, &sep, &sep_len))
 		return NULL;
 
@@ -1704,8 +1258,9 @@
 }
 
 Py_LOCAL_INLINE(PyObject *)
-rsplit_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
+rsplit_whitespace(PyStringObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
 {
+	const char *s = PyString_AS_STRING(self);
 	Py_ssize_t i, j, count=0;
 	PyObject *str;
 	PyObject *list = PyList_New(PREALLOC_SIZE(maxsplit));
@@ -1720,11 +1275,18 @@
 		if (i<0) break;
 		j = i; i--;
 		RSKIP_NONSPACE(s, i);
+		if (j == len-1 && i < 0 && PyString_CheckExact(self)) {
+			/* No whitespace in self, so just use it as list[0] */
+			Py_INCREF(self);
+			PyList_SET_ITEM(list, 0, (PyObject *)self);
+			count++;
+			break;
+		}
 		SPLIT_ADD(s, i + 1, j + 1);
 	}
 	if (i >= 0) {
-		/* Only occurs when maxsplit was reached */
-		/* Skip any remaining whitespace and copy to beginning of string */
+		/* Only occurs when maxsplit was reached.  Skip any remaining
+		   whitespace and copy to beginning of string. */
 		RSKIP_SPACE(s, i);
 		if (i >= 0)
 			SPLIT_ADD(s, 0, i + 1);
@@ -1740,8 +1302,9 @@
 }
 
 Py_LOCAL_INLINE(PyObject *)
-rsplit_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount)
+rsplit_char(PyStringObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
 {
+	const char *s = PyString_AS_STRING(self);
 	register Py_ssize_t i, j, count=0;
 	PyObject *str;
 	PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
@@ -1759,7 +1322,13 @@
 			}
 		}
 	}
-	if (j >= -1) {
+	if (i < 0 && count == 0 && PyString_CheckExact(self)) {
+		/* ch not in self, so just use self as list[0] */
+		Py_INCREF(self);
+		PyList_SET_ITEM(list, 0, (PyObject *)self);
+		count++;
+	}
+	else if (j >= -1) {
 		SPLIT_ADD(s, 0, j + 1);
 	}
 	FIX_PREALLOC_SIZE(list);
@@ -1773,20 +1342,22 @@
 }
 
 PyDoc_STRVAR(rsplit__doc__,
-"S.rsplit([sep [,maxsplit]]) -> list of strings\n\
+"B.rsplit([sep[, maxsplit]]) -> list of strings\n\
 \n\
-Return a list of the words in the string S, using sep as the\n\
-delimiter string, starting at the end of the string and working\n\
-to the front.  If maxsplit is given, at most maxsplit splits are\n\
-done. If sep is not specified or is None, any whitespace string\n\
-is a separator.");
+Return a list of the sections in B, using sep as the delimiter,\n\
+starting at the end of B and working to the front.\n\
+If sep is not given, B is split on ASCII whitespace characters\n\
+(space, tab, return, newline, formfeed, vertical tab).\n\
+If maxsplit is given, at most maxsplit splits are done.");
+
 
 static PyObject *
 string_rsplit(PyStringObject *self, PyObject *args)
 {
 	Py_ssize_t len = PyString_GET_SIZE(self), n, i, j;
 	Py_ssize_t maxsplit = -1, count=0;
-	const char *s = PyString_AS_STRING(self), *sub;
+	const char *s, *sub;
+	Py_buffer vsub;
 	PyObject *list, *str, *subobj = Py_None;
 
 	if (!PyArg_ParseTuple(args, "|On:rsplit", &subobj, &maxsplit))
@@ -1794,30 +1365,30 @@
 	if (maxsplit < 0)
 		maxsplit = PY_SSIZE_T_MAX;
 	if (subobj == Py_None)
-		return rsplit_whitespace(s, len, maxsplit);
-	if (PyString_Check(subobj)) {
-		sub = PyString_AS_STRING(subobj);
-		n = PyString_GET_SIZE(subobj);
-	}
-	else if (PyUnicode_Check(subobj))
-		return PyUnicode_RSplit((PyObject *)self, subobj, maxsplit);
-	else if (PyObject_AsCharBuffer(subobj, &sub, &n))
+		return rsplit_whitespace(self, len, maxsplit);
+	if (_getbuffer(subobj, &vsub) < 0)
 		return NULL;
+	sub = vsub.buf;
+	n = vsub.len;
 
 	if (n == 0) {
 		PyErr_SetString(PyExc_ValueError, "empty separator");
+		PyObject_ReleaseBuffer(subobj, &vsub);
 		return NULL;
 	}
 	else if (n == 1)
-		return rsplit_char(s, len, sub[0], maxsplit);
+		return rsplit_char(self, len, sub[0], maxsplit);
 
 	list = PyList_New(PREALLOC_SIZE(maxsplit));
-	if (list == NULL)
+	if (list == NULL) {
+		PyObject_ReleaseBuffer(subobj, &vsub);
 		return NULL;
+	}
 
 	j = len;
 	i = j - n;
 
+	s = PyString_AS_STRING(self);
 	while ( (i >= 0) && (maxsplit-- > 0) ) {
 		for (; i>=0; i--) {
 			if (Py_STRING_MATCH(s, i, sub, n)) {
@@ -1832,22 +1403,28 @@
 	FIX_PREALLOC_SIZE(list);
 	if (PyList_Reverse(list) < 0)
 		goto onError;
+	PyObject_ReleaseBuffer(subobj, &vsub);
 	return list;
 
 onError:
 	Py_DECREF(list);
+	PyObject_ReleaseBuffer(subobj, &vsub);
 	return NULL;
 }
 
+#undef SPLIT_ADD
+#undef MAX_PREALLOC
+#undef PREALLOC_SIZE
+
 
 PyDoc_STRVAR(join__doc__,
-"S.join(sequence) -> string\n\
+"B.join(iterable_of_bytes) -> bytes\n\
 \n\
-Return a string which is the concatenation of the strings in the\n\
-sequence.  The separator between elements is S.");
+Concatenates any number of bytes objects, with B in between each pair.\n\
+Example: b'.'.join([b'ab', b'pq', b'rs']) -> b'ab.pq.rs'.");
 
 static PyObject *
-string_join(PyStringObject *self, PyObject *orig)
+string_join(PyObject *self, PyObject *orig)
 {
 	char *sep = PyString_AS_STRING(self);
 	const Py_ssize_t seplen = PyString_GET_SIZE(self);
@@ -1870,7 +1447,7 @@
 	}
 	if (seqlen == 1) {
 		item = PySequence_Fast_GET_ITEM(seq, 0);
-		if (PyString_CheckExact(item) || PyUnicode_CheckExact(item)) {
+		if (PyString_CheckExact(item)) {
 			Py_INCREF(item);
 			Py_DECREF(seq);
 			return item;
@@ -1880,37 +1457,26 @@
 	/* There are at least two things to join, or else we have a subclass
 	 * of the builtin types in the sequence.
 	 * Do a pre-pass to figure out the total amount of space we'll
-	 * need (sz), see whether any argument is absurd, and defer to
-	 * the Unicode join if appropriate.
+	 * need (sz), and see whether all argument are bytes.
 	 */
+	/* XXX Shouldn't we use _getbuffer() on these items instead? */
 	for (i = 0; i < seqlen; i++) {
 		const size_t old_sz = sz;
 		item = PySequence_Fast_GET_ITEM(seq, i);
-		if (!PyString_Check(item)){
-			if (PyUnicode_Check(item)) {
-				/* Defer to Unicode join.
-				 * CAUTION:  There's no gurantee that the
-				 * original sequence can be iterated over
-				 * again, so we must pass seq here.
-				 */
-				PyObject *result;
-				result = PyUnicode_Join((PyObject *)self, seq);
-				Py_DECREF(seq);
-				return result;
-			}
+		if (!PyString_Check(item) && !PyBytes_Check(item)) {
 			PyErr_Format(PyExc_TypeError,
-				     "sequence item %zd: expected string,"
+				     "sequence item %zd: expected bytes,"
 				     " %.80s found",
-				     i, Py_Type(item)->tp_name);
+				     i, Py_TYPE(item)->tp_name);
 			Py_DECREF(seq);
 			return NULL;
 		}
-		sz += PyString_GET_SIZE(item);
+		sz += Py_SIZE(item);
 		if (i != 0)
 			sz += seplen;
 		if (sz < old_sz || sz > PY_SSIZE_T_MAX) {
 			PyErr_SetString(PyExc_OverflowError,
-				"join() result is too long for a Python string");
+			    "join() result is too long for a Python string");
 			Py_DECREF(seq);
 			return NULL;
 		}
@@ -1924,17 +1490,24 @@
 	}
 
 	/* Catenate everything. */
+	/* I'm not worried about a PyBytes item growing because there's
+	   nowhere in this function where we release the GIL. */
 	p = PyString_AS_STRING(res);
 	for (i = 0; i < seqlen; ++i) {
 		size_t n;
-		item = PySequence_Fast_GET_ITEM(seq, i);
-		n = PyString_GET_SIZE(item);
-		Py_MEMCPY(p, PyString_AS_STRING(item), n);
-		p += n;
-		if (i < seqlen - 1) {
+                char *q;
+		if (i) {
 			Py_MEMCPY(p, sep, seplen);
 			p += seplen;
 		}
+		item = PySequence_Fast_GET_ITEM(seq, i);
+		n = Py_SIZE(item);
+                if (PyString_Check(item))
+			q = PyString_AS_STRING(item);
+		else
+			q = PyBytes_AS_STRING(item);
+		Py_MEMCPY(p, q, n);
+		p += n;
 	}
 
 	Py_DECREF(seq);
@@ -1946,7 +1519,7 @@
 {
 	assert(sep != NULL && PyString_Check(sep));
 	assert(x != NULL);
-	return string_join((PyStringObject *)sep, x);
+	return string_join(sep, x);
 }
 
 Py_LOCAL_INLINE(void)
@@ -1971,17 +1544,25 @@
 	const char *sub;
 	Py_ssize_t sub_len;
 	Py_ssize_t start=0, end=PY_SSIZE_T_MAX;
+	PyObject *obj_start=Py_None, *obj_end=Py_None;
 
-	if (!PyArg_ParseTuple(args, "O|O&O&:find/rfind/index/rindex", &subobj,
-		_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+	if (!PyArg_ParseTuple(args, "O|OO:find/rfind/index/rindex", &subobj,
+		&obj_start, &obj_end))
 		return -2;
+	/* To support None in "start" and "end" arguments, meaning
+	   the same as if they were not passed.
+	*/
+	if (obj_start != Py_None)
+		if (!_PyEval_SliceIndex(obj_start, &start))
+	        return -2;
+	if (obj_end != Py_None)
+		if (!_PyEval_SliceIndex(obj_end, &end))
+	        return -2;
+
 	if (PyString_Check(subobj)) {
 		sub = PyString_AS_STRING(subobj);
 		sub_len = PyString_GET_SIZE(subobj);
 	}
-	else if (PyUnicode_Check(subobj))
-		return PyUnicode_Find(
-			(PyObject *)self, subobj, start, end, dir);
 	else if (PyObject_AsCharBuffer(subobj, &sub, &sub_len))
 		/* XXX - the "expected a character buffer object" is pretty
 		   confusing for a non-expert.  remap to something else ? */
@@ -1999,7 +1580,7 @@
 
 
 PyDoc_STRVAR(find__doc__,
-"S.find(sub [,start [,end]]) -> int\n\
+"B.find(sub [,start [,end]]) -> int\n\
 \n\
 Return the lowest index in S where substring sub is found,\n\
 such that sub is contained within s[start:end].  Optional\n\
@@ -2013,14 +1594,14 @@
 	Py_ssize_t result = string_find_internal(self, args, +1);
 	if (result == -2)
 		return NULL;
-	return PyInt_FromSsize_t(result);
+	return PyLong_FromSsize_t(result);
 }
 
 
 PyDoc_STRVAR(index__doc__,
-"S.index(sub [,start [,end]]) -> int\n\
+"B.index(sub [,start [,end]]) -> int\n\
 \n\
-Like S.find() but raise ValueError when the substring is not found.");
+Like B.find() but raise ValueError when the substring is not found.");
 
 static PyObject *
 string_index(PyStringObject *self, PyObject *args)
@@ -2033,14 +1614,14 @@
 				"substring not found");
 		return NULL;
 	}
-	return PyInt_FromSsize_t(result);
+	return PyLong_FromSsize_t(result);
 }
 
 
 PyDoc_STRVAR(rfind__doc__,
-"S.rfind(sub [,start [,end]]) -> int\n\
+"B.rfind(sub [,start [,end]]) -> int\n\
 \n\
-Return the highest index in S where substring sub is found,\n\
+Return the highest index in B where substring sub is found,\n\
 such that sub is contained within s[start:end].  Optional\n\
 arguments start and end are interpreted as in slice notation.\n\
 \n\
@@ -2052,14 +1633,14 @@
 	Py_ssize_t result = string_find_internal(self, args, -1);
 	if (result == -2)
 		return NULL;
-	return PyInt_FromSsize_t(result);
+	return PyLong_FromSsize_t(result);
 }
 
 
 PyDoc_STRVAR(rindex__doc__,
-"S.rindex(sub [,start [,end]]) -> int\n\
+"B.rindex(sub [,start [,end]]) -> int\n\
 \n\
-Like S.rfind() but raise ValueError when the substring is not found.");
+Like B.rfind() but raise ValueError when the substring is not found.");
 
 static PyObject *
 string_rindex(PyStringObject *self, PyObject *args)
@@ -2072,19 +1653,25 @@
 				"substring not found");
 		return NULL;
 	}
-	return PyInt_FromSsize_t(result);
+	return PyLong_FromSsize_t(result);
 }
 
 
 Py_LOCAL_INLINE(PyObject *)
 do_xstrip(PyStringObject *self, int striptype, PyObject *sepobj)
 {
+	Py_buffer vsep;
 	char *s = PyString_AS_STRING(self);
 	Py_ssize_t len = PyString_GET_SIZE(self);
-	char *sep = PyString_AS_STRING(sepobj);
-	Py_ssize_t seplen = PyString_GET_SIZE(sepobj);
+	char *sep;
+	Py_ssize_t seplen;
 	Py_ssize_t i, j;
 
+	if (_getbuffer(sepobj, &vsep) < 0)
+		return NULL;
+	sep = vsep.buf;
+	seplen = vsep.len;
+
 	i = 0;
 	if (striptype != RIGHTSTRIP) {
 		while (i < len && memchr(sep, Py_CHARMASK(s[i]), seplen)) {
@@ -2100,6 +1687,8 @@
 		j++;
 	}
 
+	PyObject_ReleaseBuffer(sepobj, &vsep);
+
 	if (i == 0 && j == len && PyString_CheckExact(self)) {
 		Py_INCREF(self);
 		return (PyObject*)self;
@@ -2148,36 +1737,17 @@
 		return NULL;
 
 	if (sep != NULL && sep != Py_None) {
-		if (PyString_Check(sep))
-			return do_xstrip(self, striptype, sep);
-		else if (PyUnicode_Check(sep)) {
-			PyObject *uniself = PyUnicode_FromObject((PyObject *)self);
-			PyObject *res;
-			if (uniself==NULL)
-				return NULL;
-			res = _PyUnicode_XStrip((PyUnicodeObject *)uniself,
-				striptype, sep);
-			Py_DECREF(uniself);
-			return res;
-		}
-		PyErr_Format(PyExc_TypeError,
-			     "%s arg must be None or string",
-			     STRIPNAME(striptype));
-		return NULL;
+		return do_xstrip(self, striptype, sep);
 	}
-
 	return do_strip(self, striptype);
 }
 
 
 PyDoc_STRVAR(strip__doc__,
-"S.strip([chars]) -> string\n\
+"B.strip([bytes]) -> bytes\n\
 \n\
-Return a copy of the string S with leading and trailing\n\
-whitespace removed.\n\
-If chars is given and not None, remove characters in chars instead.\n\
-If chars is unicode, S will be converted to unicode before stripping");
-
+Strip leading and trailing bytes contained in the argument.\n\
+If the argument is omitted, strip trailing ASCII whitespace.");
 static PyObject *
 string_strip(PyStringObject *self, PyObject *args)
 {
@@ -2189,12 +1759,10 @@
 
 
 PyDoc_STRVAR(lstrip__doc__,
-"S.lstrip([chars]) -> string\n\
+"B.lstrip([bytes]) -> bytes\n\
 \n\
-Return a copy of the string S with leading whitespace removed.\n\
-If chars is given and not None, remove characters in chars instead.\n\
-If chars is unicode, S will be converted to unicode before stripping");
-
+Strip leading bytes contained in the argument.\n\
+If the argument is omitted, strip leading ASCII whitespace.");
 static PyObject *
 string_lstrip(PyStringObject *self, PyObject *args)
 {
@@ -2206,12 +1774,10 @@
 
 
 PyDoc_STRVAR(rstrip__doc__,
-"S.rstrip([chars]) -> string\n\
+"B.rstrip([bytes]) -> bytes\n\
 \n\
-Return a copy of the string S with trailing whitespace removed.\n\
-If chars is given and not None, remove characters in chars instead.\n\
-If chars is unicode, S will be converted to unicode before stripping");
-
+Strip trailing bytes contained in the argument.\n\
+If the argument is omitted, strip trailing ASCII whitespace.");
 static PyObject *
 string_rstrip(PyStringObject *self, PyObject *args)
 {
@@ -2222,138 +1788,8 @@
 }
 
 
-PyDoc_STRVAR(lower__doc__,
-"S.lower() -> string\n\
-\n\
-Return a copy of the string S converted to lowercase.");
-
-static PyObject *
-string_lower(PyStringObject *self)
-{
-	char *s;
-	Py_ssize_t i, n = PyString_GET_SIZE(self);
-	PyObject *newobj;
-
-	newobj = PyString_FromStringAndSize(NULL, n);
-	if (!newobj)
-		return NULL;
-
-	s = PyString_AS_STRING(newobj);
-
-	Py_MEMCPY(s, PyString_AS_STRING(self), n);
-
-	for (i = 0; i < n; i++) {
-		int c = Py_CHARMASK(s[i]);
-		if (ISUPPER(c))
-			s[i] = TOLOWER(c);
-	}
-
-	return newobj;
-}
-
-PyDoc_STRVAR(upper__doc__,
-"S.upper() -> string\n\
-\n\
-Return a copy of the string S converted to uppercase.");
-
-static PyObject *
-string_upper(PyStringObject *self)
-{
-	char *s;
-	Py_ssize_t i, n = PyString_GET_SIZE(self);
-	PyObject *newobj;
-
-	newobj = PyString_FromStringAndSize(NULL, n);
-	if (!newobj)
-		return NULL;
-
-	s = PyString_AS_STRING(newobj);
-
-	Py_MEMCPY(s, PyString_AS_STRING(self), n);
-
-	for (i = 0; i < n; i++) {
-		int c = Py_CHARMASK(s[i]);
-		if (ISLOWER(c))
-			s[i] = TOUPPER(c);
-	}
-
-	return newobj;
-}
-
-PyDoc_STRVAR(title__doc__,
-"S.title() -> string\n\
-\n\
-Return a titlecased version of S, i.e. words start with uppercase\n\
-characters, all remaining cased characters have lowercase.");
-
-static PyObject*
-string_title(PyStringObject *self)
-{
-	char *s = PyString_AS_STRING(self), *s_new;
-	Py_ssize_t i, n = PyString_GET_SIZE(self);
-	int previous_is_cased = 0;
-	PyObject *newobj;
-
-	newobj = PyString_FromStringAndSize(NULL, n);
-	if (newobj == NULL)
-		return NULL;
-	s_new = PyString_AsString(newobj);
-	for (i = 0; i < n; i++) {
-		int c = Py_CHARMASK(*s++);
-		if (ISLOWER(c)) {
-			if (!previous_is_cased)
-			    c = TOUPPER(c);
-			previous_is_cased = 1;
-		} else if (ISUPPER(c)) {
-			if (previous_is_cased)
-			    c = TOLOWER(c);
-			previous_is_cased = 1;
-		} else
-			previous_is_cased = 0;
-		*s_new++ = c;
-	}
-	return newobj;
-}
-
-PyDoc_STRVAR(capitalize__doc__,
-"S.capitalize() -> string\n\
-\n\
-Return a copy of the string S with only its first character\n\
-capitalized.");
-
-static PyObject *
-string_capitalize(PyStringObject *self)
-{
-	char *s = PyString_AS_STRING(self), *s_new;
-	Py_ssize_t i, n = PyString_GET_SIZE(self);
-	PyObject *newobj;
-
-	newobj = PyString_FromStringAndSize(NULL, n);
-	if (newobj == NULL)
-		return NULL;
-	s_new = PyString_AsString(newobj);
-	if (0 < n) {
-		int c = Py_CHARMASK(*s++);
-		if (ISLOWER(c))
-			*s_new = TOUPPER(c);
-		else
-			*s_new = c;
-		s_new++;
-	}
-	for (i = 1; i < n; i++) {
-		int c = Py_CHARMASK(*s++);
-		if (ISUPPER(c))
-			*s_new = TOLOWER(c);
-		else
-			*s_new = c;
-		s_new++;
-	}
-	return newobj;
-}
-
-
 PyDoc_STRVAR(count__doc__,
-"S.count(sub[, start[, end]]) -> int\n\
+"B.count(sub [,start [,end]]) -> int\n\
 \n\
 Return the number of non-overlapping occurrences of substring sub in\n\
 string S[start:end].  Optional arguments start and end are interpreted\n\
@@ -2375,64 +1811,24 @@
 		sub = PyString_AS_STRING(sub_obj);
 		sub_len = PyString_GET_SIZE(sub_obj);
 	}
-	else if (PyUnicode_Check(sub_obj)) {
-		Py_ssize_t count;
-		count = PyUnicode_Count((PyObject *)self, sub_obj, start, end);
-		if (count == -1)
-			return NULL;
-		else
-		    	return PyInt_FromSsize_t(count);
-	}
 	else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len))
 		return NULL;
 
 	string_adjust_indices(&start, &end, PyString_GET_SIZE(self));
 
-	return PyInt_FromSsize_t(
+	return PyLong_FromSsize_t(
 		stringlib_count(str + start, end - start, sub, sub_len)
 		);
 }
 
-PyDoc_STRVAR(swapcase__doc__,
-"S.swapcase() -> string\n\
-\n\
-Return a copy of the string S with uppercase characters\n\
-converted to lowercase and vice versa.");
-
-static PyObject *
-string_swapcase(PyStringObject *self)
-{
-	char *s = PyString_AS_STRING(self), *s_new;
-	Py_ssize_t i, n = PyString_GET_SIZE(self);
-	PyObject *newobj;
-
-	newobj = PyString_FromStringAndSize(NULL, n);
-	if (newobj == NULL)
-		return NULL;
-	s_new = PyString_AsString(newobj);
-	for (i = 0; i < n; i++) {
-		int c = Py_CHARMASK(*s++);
-		if (ISLOWER(c)) {
-			*s_new = TOUPPER(c);
-		}
-		else if (ISUPPER(c)) {
-			*s_new = TOLOWER(c);
-		}
-		else
-			*s_new = c;
-		s_new++;
-	}
-	return newobj;
-}
-
 
 PyDoc_STRVAR(translate__doc__,
-"S.translate(table [,deletechars]) -> string\n\
+"B.translate(table[, deletechars]) -> bytes\n\
 \n\
-Return a copy of the string S, where all characters occurring\n\
-in the optional argument deletechars are removed, and the\n\
-remaining characters have been mapped through the given\n\
-translation table, which must be a string of length 256.");
+Return a copy of B, where all characters occurring in the\n\
+optional argument deletechars are removed, and the remaining\n\
+characters have been mapped through the given translation\n\
+table, which must be a bytes object of length 256.");
 
 static PyObject *
 string_translate(PyStringObject *self, PyObject *args)
@@ -2459,17 +1855,6 @@
 		table = NULL;
 		tablen = 256;
 	}
-	else if (PyUnicode_Check(tableobj)) {
-		/* Unicode .translate() does not support the deletechars
-		   parameter; instead a mapping to None will cause characters
-		   to be deleted. */
-		if (delobj != NULL) {
-			PyErr_SetString(PyExc_TypeError,
-			"deletions are implemented differently for unicode");
-			return NULL;
-		}
-		return PyUnicode_Translate((PyObject *)self, tableobj, NULL);
-	}
 	else if (PyObject_AsCharBuffer(tableobj, &table, &tablen))
 		return NULL;
 
@@ -2618,7 +2003,7 @@
 				return end;
 	} else {
 		for (; start <= end; start++)
-			if (Py_STRING_MATCH(target, start, pattern, pattern_len))
+			if (Py_STRING_MATCH(target, start,pattern,pattern_len))
 				return start;
 	}
 	return -1;
@@ -2656,14 +2041,15 @@
 	end -= pattern_len;
 	if (direction < 0) {
 		for (; (end >= start); end--)
-			if (Py_STRING_MATCH(target, end, pattern, pattern_len)) {
+			if (Py_STRING_MATCH(target, end,pattern,pattern_len)) {
 				count++;
 				if (--maxcount <= 0) break;
 				end -= pattern_len-1;
 			}
 	} else {
 		for (; (start <= end); start++)
-			if (Py_STRING_MATCH(target, start, pattern, pattern_len)) {
+			if (Py_STRING_MATCH(target, start,
+					    pattern, pattern_len)) {
 				count++;
 				if (--maxcount <= 0)
 					break;
@@ -2691,7 +2077,7 @@
 
 	/* 1 at the end plus 1 after every character */
 	count = self_len+1;
-	if (maxcount < count) 
+	if (maxcount < count)
 		count = maxcount;
 
 	/* Check for overflow */
@@ -2708,7 +2094,7 @@
 				"replace string is too long");
 		return NULL;
 	}
-  
+
 	if (! (result = (PyStringObject *)
 	                 PyString_FromStringAndSize(NULL, result_len)) )
 		return NULL;
@@ -2722,7 +2108,7 @@
 	Py_MEMCPY(result_s, to_s, to_len);
 	result_s += to_len;
 	count -= 1;
-  
+
 	for (i=0; i<count; i++) {
 		*result_s++ = *self_s++;
 		Py_MEMCPY(result_s, to_s, to_len);
@@ -2754,7 +2140,7 @@
 	if (count == 0) {
 		return return_self(self);
 	}
-  
+
 	result_len = self_len - count;  /* from_len == 1 */
 	assert(result_len>=0);
 
@@ -2953,12 +2339,14 @@
 	/*   result_len = self_len + count * (to_len-1)  */
 	product = count * (to_len-1);
 	if (product / (to_len-1) != count) {
-		PyErr_SetString(PyExc_OverflowError, "replace string is too long");
+		PyErr_SetString(PyExc_OverflowError,
+				"replace string is too long");
 		return NULL;
 	}
 	result_len = self_len + product;
 	if (result_len < 0) {
-		PyErr_SetString(PyExc_OverflowError, "replace string is too long");
+		PyErr_SetString(PyExc_OverflowError,
+				"replace string is too long");
 		return NULL;
 	}
 
@@ -2971,7 +2359,7 @@
 	end = self_s + self_len;
 	while (count-- > 0) {
 		next = findchar(start, end-start, from_c);
-		if (next == NULL) 
+		if (next == NULL)
 			break;
 
 		if (next == start) {
@@ -3021,12 +2409,14 @@
 	/*    result_len = self_len + count * (to_len-from_len) */
 	product = count * (to_len-from_len);
 	if (product / (to_len-from_len) != count) {
-		PyErr_SetString(PyExc_OverflowError, "replace string is too long");
+		PyErr_SetString(PyExc_OverflowError,
+				"replace string is too long");
 		return NULL;
 	}
 	result_len = self_len + product;
 	if (result_len < 0) {
-		PyErr_SetString(PyExc_OverflowError, "replace string is too long");
+		PyErr_SetString(PyExc_OverflowError,
+				"replace string is too long");
 		return NULL;
 	}
 
@@ -3106,7 +2496,8 @@
 			return replace_delete_single_character(
 				self, from_s[0], maxcount);
 		} else {
-			return replace_delete_substring(self, from_s, from_len, maxcount);
+			return replace_delete_substring(self, from_s,
+							from_len, maxcount);
 		}
 	}
 
@@ -3121,7 +2512,8 @@
 				maxcount);
 		} else {
 			return replace_substring_in_place(
-				self, from_s, from_len, to_s, to_len, maxcount);
+				self, from_s, from_len, to_s, to_len,
+				maxcount);
 		}
 	}
 
@@ -3131,14 +2523,15 @@
 						to_s, to_len, maxcount);
 	} else {
 		/* len('from')>=2, len('to')>=1 */
-		return replace_substring(self, from_s, from_len, to_s, to_len, maxcount);
+		return replace_substring(self, from_s, from_len, to_s, to_len,
+					 maxcount);
 	}
 }
 
 PyDoc_STRVAR(replace__doc__,
-"S.replace (old, new[, count]) -> string\n\
+"B.replace(old, new[, count]) -> bytes\n\
 \n\
-Return a copy of string S with all occurrences of substring\n\
+Return a copy of B with all occurrences of subsection\n\
 old replaced by new.  If the optional argument count is\n\
 given, only the first count occurrences are replaced.");
 
@@ -3157,9 +2550,6 @@
 		from_s = PyString_AS_STRING(from);
 		from_len = PyString_GET_SIZE(from);
 	}
-	if (PyUnicode_Check(from))
-		return PyUnicode_Replace((PyObject *)self,
-					 from, to, count);
 	else if (PyObject_AsCharBuffer(from, &from_s, &from_len))
 		return NULL;
 
@@ -3167,9 +2557,6 @@
 		to_s = PyString_AS_STRING(to);
 		to_len = PyString_GET_SIZE(to);
 	}
-	else if (PyUnicode_Check(to))
-		return PyUnicode_Replace((PyObject *)self,
-					 from, to, count);
 	else if (PyObject_AsCharBuffer(to, &to_s, &to_len))
 		return NULL;
 
@@ -3197,9 +2584,6 @@
 		sub = PyString_AS_STRING(substr);
 		slen = PyString_GET_SIZE(substr);
 	}
-	else if (PyUnicode_Check(substr))
-		return PyUnicode_Tailmatch((PyObject *)self,
-					   substr, start, end, direction);
 	else if (PyObject_AsCharBuffer(substr, &sub, &slen))
 		return -1;
 	str = PyString_AS_STRING(self);
@@ -3225,11 +2609,11 @@
 
 
 PyDoc_STRVAR(startswith__doc__,
-"S.startswith(prefix[, start[, end]]) -> bool\n\
+"B.startswith(prefix [,start [,end]]) -> bool\n\
 \n\
-Return True if S starts with the specified prefix, False otherwise.\n\
-With optional start, test S beginning at that position.\n\
-With optional end, stop comparing S at that position.\n\
+Return True if B starts with the specified prefix, False otherwise.\n\
+With optional start, test B beginning at that position.\n\
+With optional end, stop comparing B at that position.\n\
 prefix can also be a tuple of strings to try.");
 
 static PyObject *
@@ -3266,11 +2650,11 @@
 
 
 PyDoc_STRVAR(endswith__doc__,
-"S.endswith(suffix[, start[, end]]) -> bool\n\
+"B.endswith(suffix [,start [,end]]) -> bool\n\
 \n\
-Return True if S ends with the specified suffix, False otherwise.\n\
-With optional start, test S beginning at that position.\n\
-With optional end, stop comparing S at that position.\n\
+Return True if B ends with the specified suffix, False otherwise.\n\
+With optional start, test B beginning at that position.\n\
+With optional end, stop comparing B at that position.\n\
 suffix can also be a tuple of strings to try.");
 
 static PyObject *
@@ -3306,677 +2690,161 @@
 }
 
 
-PyDoc_STRVAR(encode__doc__,
-"S.encode([encoding[,errors]]) -> object\n\
-\n\
-Encodes S using the codec registered for encoding. encoding defaults\n\
-to the default encoding. errors may be given to set a different error\n\
-handling scheme. Default is 'strict' meaning that encoding errors raise\n\
-a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n\
-'xmlcharrefreplace' as well as any other name registered with\n\
-codecs.register_error that is able to handle UnicodeEncodeErrors.");
-
-static PyObject *
-string_encode(PyStringObject *self, PyObject *args)
-{
-    char *encoding = NULL;
-    char *errors = NULL;
-    PyObject *v;
-
-    if (!PyArg_ParseTuple(args, "|ss:encode", &encoding, &errors))
-        return NULL;
-    v = PyString_AsEncodedObject((PyObject *)self, encoding, errors);
-    if (v == NULL)
-        goto onError;
-    if (!PyBytes_Check(v)) {
-        PyErr_Format(PyExc_TypeError,
-                     "[str8] encoder did not return a bytes object "
-                     "(type=%.400s)",
-                     Py_Type(v)->tp_name);
-        Py_DECREF(v);
-        return NULL;
-    }
-    return v;
-
- onError:
-    return NULL;
-}
-
-
 PyDoc_STRVAR(decode__doc__,
-"S.decode([encoding[,errors]]) -> object\n\
+"B.decode([encoding[, errors]]) -> object\n\
 \n\
 Decodes S using the codec registered for encoding. encoding defaults\n\
 to the default encoding. errors may be given to set a different error\n\
-handling scheme. Default is 'strict' meaning that encoding errors raise\n\
-a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n\
+handling scheme.  Default is 'strict' meaning that encoding errors raise\n\
+a UnicodeDecodeError.  Other possible values are 'ignore' and 'replace'\n\
 as well as any other name registerd with codecs.register_error that is\n\
 able to handle UnicodeDecodeErrors.");
 
 static PyObject *
-string_decode(PyStringObject *self, PyObject *args)
+string_decode(PyObject *self, PyObject *args)
 {
-    char *encoding = NULL;
-    char *errors = NULL;
-    PyObject *v;
-
-    if (!PyArg_ParseTuple(args, "|ss:decode", &encoding, &errors))
-        return NULL;
-    v = PyString_AsDecodedObject((PyObject *)self, encoding, errors);
-    if (v == NULL)
-        goto onError;
-    if (!PyString_Check(v) && !PyUnicode_Check(v)) {
-        PyErr_Format(PyExc_TypeError,
-                     "decoder did not return a string/unicode object "
-                     "(type=%.400s)",
-                     Py_Type(v)->tp_name);
-        Py_DECREF(v);
-        return NULL;
-    }
-    return v;
+	const char *encoding = NULL;
+	const char *errors = NULL;
 
- onError:
-    return NULL;
+	if (!PyArg_ParseTuple(args, "|ss:decode", &encoding, &errors))
+		return NULL;
+	if (encoding == NULL)
+		encoding = PyUnicode_GetDefaultEncoding();
+	return PyCodec_Decode(self, encoding, errors);
 }
 
 
-PyDoc_STRVAR(expandtabs__doc__,
-"S.expandtabs([tabsize]) -> string\n\
+PyDoc_STRVAR(fromhex_doc,
+"bytes.fromhex(string) -> bytes\n\
 \n\
-Return a copy of S where all tab characters are expanded using spaces.\n\
-If tabsize is not given, a tab size of 8 characters is assumed.");
+Create a bytes object from a string of hexadecimal numbers.\n\
+Spaces between two numbers are accepted.\n\
+Example: bytes.fromhex('B9 01EF') -> b'\\xb9\\x01\\xef'.");
 
-static PyObject*
-string_expandtabs(PyStringObject *self, PyObject *args)
+static int
+hex_digit_to_int(Py_UNICODE c)
 {
-    const char *e, *p;
-    char *q;
-    Py_ssize_t i, j, old_j;
-    PyObject *u;
-    int tabsize = 8;
-
-    if (!PyArg_ParseTuple(args, "|i:expandtabs", &tabsize))
-	return NULL;
-
-    /* First pass: determine size of output string */
-    i = j = old_j = 0;
-    e = PyString_AS_STRING(self) + PyString_GET_SIZE(self);
-    for (p = PyString_AS_STRING(self); p < e; p++)
-        if (*p == '\t') {
-	    if (tabsize > 0) {
-		j += tabsize - (j % tabsize);
-		if (old_j > j) {
-		    PyErr_SetString(PyExc_OverflowError,
-				    "new string is too long");
-		    return NULL;
-		}
-		old_j = j;
-            }
-	}
-        else {
-            j++;
-            if (*p == '\n' || *p == '\r') {
-                i += j;
-                old_j = j = 0;
-                if (i < 0) {
-                    PyErr_SetString(PyExc_OverflowError,
-                                    "new string is too long");
-                    return NULL;
-                }
-            }
-        }
-
-    if ((i + j) < 0) {
-        PyErr_SetString(PyExc_OverflowError, "new string is too long");
-        return NULL;
-    }
-
-    /* Second pass: create output string and fill it */
-    u = PyString_FromStringAndSize(NULL, i + j);
-    if (!u)
-        return NULL;
-
-    j = 0;
-    q = PyString_AS_STRING(u);
-
-    for (p = PyString_AS_STRING(self); p < e; p++)
-        if (*p == '\t') {
-	    if (tabsize > 0) {
-		i = tabsize - (j % tabsize);
-		j += i;
-		while (i--)
-		    *q++ = ' ';
-	    }
-	}
+	if (c >= 128)
+		return -1;
+	if (ISDIGIT(c))
+		return c - '0';
 	else {
-            j++;
-	    *q++ = *p;
-            if (*p == '\n' || *p == '\r')
-                j = 0;
-        }
-
-    return u;
-}
-
-Py_LOCAL_INLINE(PyObject *)
-pad(PyStringObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
-{
-    PyObject *u;
-
-    if (left < 0)
-        left = 0;
-    if (right < 0)
-        right = 0;
-
-    if (left == 0 && right == 0 && PyString_CheckExact(self)) {
-        Py_INCREF(self);
-        return (PyObject *)self;
-    }
-
-    u = PyString_FromStringAndSize(NULL,
-				   left + PyString_GET_SIZE(self) + right);
-    if (u) {
-        if (left)
-            memset(PyString_AS_STRING(u), fill, left);
-        Py_MEMCPY(PyString_AS_STRING(u) + left,
-	       PyString_AS_STRING(self),
-	       PyString_GET_SIZE(self));
-        if (right)
-            memset(PyString_AS_STRING(u) + left + PyString_GET_SIZE(self),
-		   fill, right);
-    }
-
-    return u;
-}
-
-PyDoc_STRVAR(ljust__doc__,
-"S.ljust(width[, fillchar]) -> string\n"
-"\n"
-"Return S left justified in a string of length width. Padding is\n"
-"done using the specified fill character (default is a space).");
-
-static PyObject *
-string_ljust(PyStringObject *self, PyObject *args)
-{
-    Py_ssize_t width;
-    char fillchar = ' ';
-
-    if (!PyArg_ParseTuple(args, "n|c:ljust", &width, &fillchar))
-        return NULL;
-
-    if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
-        Py_INCREF(self);
-        return (PyObject*) self;
-    }
-
-    return pad(self, 0, width - PyString_GET_SIZE(self), fillchar);
-}
-
-
-PyDoc_STRVAR(rjust__doc__,
-"S.rjust(width[, fillchar]) -> string\n"
-"\n"
-"Return S right justified in a string of length width. Padding is\n"
-"done using the specified fill character (default is a space)");
-
-static PyObject *
-string_rjust(PyStringObject *self, PyObject *args)
-{
-    Py_ssize_t width;
-    char fillchar = ' ';
-
-    if (!PyArg_ParseTuple(args, "n|c:rjust", &width, &fillchar))
-        return NULL;
-
-    if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
-        Py_INCREF(self);
-        return (PyObject*) self;
-    }
-
-    return pad(self, width - PyString_GET_SIZE(self), 0, fillchar);
-}
-
-
-PyDoc_STRVAR(center__doc__,
-"S.center(width[, fillchar]) -> string\n"
-"\n"
-"Return S centered in a string of length width. Padding is\n"
-"done using the specified fill character (default is a space)");
-
-static PyObject *
-string_center(PyStringObject *self, PyObject *args)
-{
-    Py_ssize_t marg, left;
-    Py_ssize_t width;
-    char fillchar = ' ';
-
-    if (!PyArg_ParseTuple(args, "n|c:center", &width, &fillchar))
-        return NULL;
-
-    if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
-        Py_INCREF(self);
-        return (PyObject*) self;
-    }
-
-    marg = width - PyString_GET_SIZE(self);
-    left = marg / 2 + (marg & width & 1);
-
-    return pad(self, left, marg - left, fillchar);
-}
-
-PyDoc_STRVAR(zfill__doc__,
-"S.zfill(width) -> string\n"
-"\n"
-"Pad a numeric string S with zeros on the left, to fill a field\n"
-"of the specified width.  The string S is never truncated.");
-
-static PyObject *
-string_zfill(PyStringObject *self, PyObject *args)
-{
-    Py_ssize_t fill;
-    PyObject *s;
-    char *p;
-    Py_ssize_t width;
-
-    if (!PyArg_ParseTuple(args, "n:zfill", &width))
-        return NULL;
-
-    if (PyString_GET_SIZE(self) >= width) {
-        if (PyString_CheckExact(self)) {
-            Py_INCREF(self);
-            return (PyObject*) self;
-        }
-        else
-            return PyString_FromStringAndSize(
-                PyString_AS_STRING(self),
-                PyString_GET_SIZE(self)
-            );
-    }
-
-    fill = width - PyString_GET_SIZE(self);
-
-    s = pad(self, fill, 0, '0');
-
-    if (s == NULL)
-        return NULL;
-
-    p = PyString_AS_STRING(s);
-    if (p[fill] == '+' || p[fill] == '-') {
-        /* move sign to beginning of string */
-        p[0] = p[fill];
-        p[fill] = '0';
-    }
-
-    return (PyObject*) s;
-}
-
-PyDoc_STRVAR(isspace__doc__,
-"S.isspace() -> bool\n\
-\n\
-Return True if all characters in S are whitespace\n\
-and there is at least one character in S, False otherwise.");
-
-static PyObject*
-string_isspace(PyStringObject *self)
-{
-    register const unsigned char *p
-        = (unsigned char *) PyString_AS_STRING(self);
-    register const unsigned char *e;
-
-    /* Shortcut for single character strings */
-    if (PyString_GET_SIZE(self) == 1 &&
-	ISSPACE(*p))
-	return PyBool_FromLong(1);
-
-    /* Special case for empty strings */
-    if (PyString_GET_SIZE(self) == 0)
-	return PyBool_FromLong(0);
-
-    e = p + PyString_GET_SIZE(self);
-    for (; p < e; p++) {
-	if (!ISSPACE(*p))
-	    return PyBool_FromLong(0);
-    }
-    return PyBool_FromLong(1);
-}
-
-
-PyDoc_STRVAR(isalpha__doc__,
-"S.isalpha() -> bool\n\
-\n\
-Return True if all characters in S are alphabetic\n\
-and there is at least one character in S, False otherwise.");
-
-static PyObject*
-string_isalpha(PyStringObject *self)
-{
-    register const unsigned char *p
-        = (unsigned char *) PyString_AS_STRING(self);
-    register const unsigned char *e;
-
-    /* Shortcut for single character strings */
-    if (PyString_GET_SIZE(self) == 1 &&
-	ISALPHA(*p))
-	return PyBool_FromLong(1);
-
-    /* Special case for empty strings */
-    if (PyString_GET_SIZE(self) == 0)
-	return PyBool_FromLong(0);
-
-    e = p + PyString_GET_SIZE(self);
-    for (; p < e; p++) {
-	if (!ISALPHA(*p))
-	    return PyBool_FromLong(0);
-    }
-    return PyBool_FromLong(1);
-}
-
-
-PyDoc_STRVAR(isalnum__doc__,
-"S.isalnum() -> bool\n\
-\n\
-Return True if all characters in S are alphanumeric\n\
-and there is at least one character in S, False otherwise.");
-
-static PyObject*
-string_isalnum(PyStringObject *self)
-{
-    register const unsigned char *p
-        = (unsigned char *) PyString_AS_STRING(self);
-    register const unsigned char *e;
-
-    /* Shortcut for single character strings */
-    if (PyString_GET_SIZE(self) == 1 && ISALNUM(*p))
-	return PyBool_FromLong(1);
-
-    /* Special case for empty strings */
-    if (PyString_GET_SIZE(self) == 0)
-	return PyBool_FromLong(0);
-
-    e = p + PyString_GET_SIZE(self);
-    for (; p < e; p++) {
-	if (!ISALNUM(*p))
-	    return PyBool_FromLong(0);
-    }
-    return PyBool_FromLong(1);
-}
-
-
-PyDoc_STRVAR(isdigit__doc__,
-"S.isdigit() -> bool\n\
-\n\
-Return True if all characters in S are digits\n\
-and there is at least one character in S, False otherwise.");
-
-static PyObject*
-string_isdigit(PyStringObject *self)
-{
-    register const unsigned char *p
-        = (unsigned char *) PyString_AS_STRING(self);
-    register const unsigned char *e;
-
-    /* Shortcut for single character strings */
-    if (PyString_GET_SIZE(self) == 1 && ISDIGIT(*p))
-	return PyBool_FromLong(1);
-
-    /* Special case for empty strings */
-    if (PyString_GET_SIZE(self) == 0)
-	return PyBool_FromLong(0);
-
-    e = p + PyString_GET_SIZE(self);
-    for (; p < e; p++) {
-	if (!ISDIGIT(*p))
-	    return PyBool_FromLong(0);
-    }
-    return PyBool_FromLong(1);
-}
-
-
-PyDoc_STRVAR(islower__doc__,
-"S.islower() -> bool\n\
-\n\
-Return True if all cased characters in S are lowercase and there is\n\
-at least one cased character in S, False otherwise.");
-
-static PyObject*
-string_islower(PyStringObject *self)
-{
-    register const unsigned char *p
-        = (unsigned char *) PyString_AS_STRING(self);
-    register const unsigned char *e;
-    int cased;
-
-    /* Shortcut for single character strings */
-    if (PyString_GET_SIZE(self) == 1)
-	return PyBool_FromLong(ISLOWER(*p));
-
-    /* Special case for empty strings */
-    if (PyString_GET_SIZE(self) == 0)
-	return PyBool_FromLong(0);
-
-    e = p + PyString_GET_SIZE(self);
-    cased = 0;
-    for (; p < e; p++) {
-	if (ISUPPER(*p))
-	    return PyBool_FromLong(0);
-	else if (!cased && ISLOWER(*p))
-	    cased = 1;
-    }
-    return PyBool_FromLong(cased);
-}
-
-
-PyDoc_STRVAR(isupper__doc__,
-"S.isupper() -> bool\n\
-\n\
-Return True if all cased characters in S are uppercase and there is\n\
-at least one cased character in S, False otherwise.");
-
-static PyObject*
-string_isupper(PyStringObject *self)
-{
-    register const unsigned char *p
-        = (unsigned char *) PyString_AS_STRING(self);
-    register const unsigned char *e;
-    int cased;
-
-    /* Shortcut for single character strings */
-    if (PyString_GET_SIZE(self) == 1)
-	return PyBool_FromLong(ISUPPER(*p));
-
-    /* Special case for empty strings */
-    if (PyString_GET_SIZE(self) == 0)
-	return PyBool_FromLong(0);
-
-    e = p + PyString_GET_SIZE(self);
-    cased = 0;
-    for (; p < e; p++) {
-	if (ISLOWER(*p))
-	    return PyBool_FromLong(0);
-	else if (!cased && ISUPPER(*p))
-	    cased = 1;
-    }
-    return PyBool_FromLong(cased);
-}
-
-
-PyDoc_STRVAR(istitle__doc__,
-"S.istitle() -> bool\n\
-\n\
-Return True if S is a titlecased string and there is at least one\n\
-character in S, i.e. uppercase characters may only follow uncased\n\
-characters and lowercase characters only cased ones. Return False\n\
-otherwise.");
-
-static PyObject*
-string_istitle(PyStringObject *self, PyObject *uncased)
-{
-    register const unsigned char *p
-        = (unsigned char *) PyString_AS_STRING(self);
-    register const unsigned char *e;
-    int cased, previous_is_cased;
-
-    /* Shortcut for single character strings */
-    if (PyString_GET_SIZE(self) == 1)
-	return PyBool_FromLong(ISUPPER(*p));
-
-    /* Special case for empty strings */
-    if (PyString_GET_SIZE(self) == 0)
-	return PyBool_FromLong(0);
-
-    e = p + PyString_GET_SIZE(self);
-    cased = 0;
-    previous_is_cased = 0;
-    for (; p < e; p++) {
-	register const unsigned char ch = *p;
-
-	if (ISUPPER(ch)) {
-	    if (previous_is_cased)
-		return PyBool_FromLong(0);
-	    previous_is_cased = 1;
-	    cased = 1;
-	}
-	else if (ISLOWER(ch)) {
-	    if (!previous_is_cased)
-		return PyBool_FromLong(0);
-	    previous_is_cased = 1;
-	    cased = 1;
+		if (ISUPPER(c))
+			c = TOLOWER(c);
+		if (c >= 'a' && c <= 'f')
+			return c - 'a' + 10;
 	}
-	else
-	    previous_is_cased = 0;
-    }
-    return PyBool_FromLong(cased);
+	return -1;
 }
 
-
-PyDoc_STRVAR(splitlines__doc__,
-"S.splitlines([keepends]) -> list of strings\n\
-\n\
-Return a list of the lines in S, breaking at line boundaries.\n\
-Line breaks are not included in the resulting list unless keepends\n\
-is given and true.");
-
-static PyObject*
-string_splitlines(PyStringObject *self, PyObject *args)
+static PyObject *
+string_fromhex(PyObject *cls, PyObject *args)
 {
-    register Py_ssize_t i;
-    register Py_ssize_t j;
-    Py_ssize_t len;
-    int keepends = 0;
-    PyObject *list;
-    PyObject *str;
-    char *data;
-
-    if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends))
-        return NULL;
-
-    data = PyString_AS_STRING(self);
-    len = PyString_GET_SIZE(self);
-
-    /* This does not use the preallocated list because splitlines is
-       usually run with hundreds of newlines.  The overhead of
-       switching between PyList_SET_ITEM and append causes about a
-       2-3% slowdown for that common case.  A smarter implementation
-       could move the if check out, so the SET_ITEMs are done first
-       and the appends only done when the prealloc buffer is full.
-       That's too much work for little gain.*/
-
-    list = PyList_New(0);
-    if (!list)
-        goto onError;
-
-    for (i = j = 0; i < len; ) {
-	Py_ssize_t eol;
-
-	/* Find a line and append it */
-	while (i < len && data[i] != '\n' && data[i] != '\r')
-	    i++;
-
-	/* Skip the line break reading CRLF as one line break */
-	eol = i;
-	if (i < len) {
-	    if (data[i] == '\r' && i + 1 < len &&
-		data[i+1] == '\n')
-		i += 2;
-	    else
-		i++;
-	    if (keepends)
-		eol = i;
+	PyObject *newstring, *hexobj;
+	char *buf;
+	Py_UNICODE *hex;
+	Py_ssize_t hexlen, byteslen, i, j;
+	int top, bot;
+
+	if (!PyArg_ParseTuple(args, "U:fromhex", &hexobj))
+		return NULL;
+	assert(PyUnicode_Check(hexobj));
+	hexlen = PyUnicode_GET_SIZE(hexobj);
+	hex = PyUnicode_AS_UNICODE(hexobj);
+	byteslen = hexlen/2; /* This overestimates if there are spaces */
+	newstring = PyString_FromStringAndSize(NULL, byteslen);
+	if (!newstring)
+		return NULL;
+	buf = PyString_AS_STRING(newstring);
+	for (i = j = 0; i < hexlen; i += 2) {
+		/* skip over spaces in the input */
+		while (hex[i] == ' ')
+			i++;
+		if (i >= hexlen)
+			break;
+		top = hex_digit_to_int(hex[i]);
+		bot = hex_digit_to_int(hex[i+1]);
+		if (top == -1 || bot == -1) {
+			PyErr_Format(PyExc_ValueError,
+				     "non-hexadecimal number found in "
+				     "fromhex() arg at position %zd", i);
+			goto error;
+		}
+		buf[j++] = (top << 4) + bot;
 	}
-	SPLIT_APPEND(data, j, eol);
-	j = i;
-    }
-    if (j < len) {
-	SPLIT_APPEND(data, j, len);
-    }
-
-    return list;
+	if (j != byteslen && _PyString_Resize(&newstring, j) < 0)
+		goto error;
+	return newstring;
 
- onError:
-    Py_XDECREF(list);
-    return NULL;
+  error:
+	Py_XDECREF(newstring);
+	return NULL;
 }
 
-#undef SPLIT_APPEND
-#undef SPLIT_ADD
-#undef MAX_PREALLOC
-#undef PREALLOC_SIZE
 
 static PyObject *
 string_getnewargs(PyStringObject *v)
 {
-	return Py_BuildValue("(s#)", v->ob_sval, Py_Size(v));
+	return Py_BuildValue("(s#)", v->ob_sval, Py_SIZE(v));
 }
 
-
+
 static PyMethodDef
 string_methods[] = {
-	{"join", (PyCFunction)string_join, METH_O, join__doc__},
-	{"split", (PyCFunction)string_split, METH_VARARGS, split__doc__},
-	{"rsplit", (PyCFunction)string_rsplit, METH_VARARGS, rsplit__doc__},
-	{"lower", (PyCFunction)string_lower, METH_NOARGS, lower__doc__},
-	{"upper", (PyCFunction)string_upper, METH_NOARGS, upper__doc__},
-	{"islower", (PyCFunction)string_islower, METH_NOARGS, islower__doc__},
-	{"isupper", (PyCFunction)string_isupper, METH_NOARGS, isupper__doc__},
-	{"isspace", (PyCFunction)string_isspace, METH_NOARGS, isspace__doc__},
-	{"isdigit", (PyCFunction)string_isdigit, METH_NOARGS, isdigit__doc__},
-	{"istitle", (PyCFunction)string_istitle, METH_NOARGS, istitle__doc__},
-	{"isalpha", (PyCFunction)string_isalpha, METH_NOARGS, isalpha__doc__},
-	{"isalnum", (PyCFunction)string_isalnum, METH_NOARGS, isalnum__doc__},
-	{"capitalize", (PyCFunction)string_capitalize, METH_NOARGS,
-	 capitalize__doc__},
+	{"__getnewargs__",	(PyCFunction)string_getnewargs,	METH_NOARGS},
+	{"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS,
+	 _Py_capitalize__doc__},
+	{"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__},
 	{"count", (PyCFunction)string_count, METH_VARARGS, count__doc__},
+	{"decode", (PyCFunction)string_decode, METH_VARARGS, decode__doc__},
 	{"endswith", (PyCFunction)string_endswith, METH_VARARGS,
-	 endswith__doc__},
-	{"partition", (PyCFunction)string_partition, METH_O, partition__doc__},
+         endswith__doc__},
+	{"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS,
+	 expandtabs__doc__},
 	{"find", (PyCFunction)string_find, METH_VARARGS, find__doc__},
+        {"fromhex", (PyCFunction)string_fromhex, METH_VARARGS|METH_CLASS,
+         fromhex_doc},
 	{"index", (PyCFunction)string_index, METH_VARARGS, index__doc__},
+	{"isalnum", (PyCFunction)stringlib_isalnum, METH_NOARGS,
+         _Py_isalnum__doc__},
+	{"isalpha", (PyCFunction)stringlib_isalpha, METH_NOARGS,
+         _Py_isalpha__doc__},
+	{"isdigit", (PyCFunction)stringlib_isdigit, METH_NOARGS,
+         _Py_isdigit__doc__},
+	{"islower", (PyCFunction)stringlib_islower, METH_NOARGS,
+         _Py_islower__doc__},
+	{"isspace", (PyCFunction)stringlib_isspace, METH_NOARGS,
+         _Py_isspace__doc__},
+	{"istitle", (PyCFunction)stringlib_istitle, METH_NOARGS,
+         _Py_istitle__doc__},
+	{"isupper", (PyCFunction)stringlib_isupper, METH_NOARGS,
+         _Py_isupper__doc__},
+	{"join", (PyCFunction)string_join, METH_O, join__doc__},
+	{"ljust", (PyCFunction)stringlib_ljust, METH_VARARGS, ljust__doc__},
+	{"lower", (PyCFunction)stringlib_lower, METH_NOARGS, _Py_lower__doc__},
 	{"lstrip", (PyCFunction)string_lstrip, METH_VARARGS, lstrip__doc__},
+	{"partition", (PyCFunction)string_partition, METH_O, partition__doc__},
 	{"replace", (PyCFunction)string_replace, METH_VARARGS, replace__doc__},
 	{"rfind", (PyCFunction)string_rfind, METH_VARARGS, rfind__doc__},
 	{"rindex", (PyCFunction)string_rindex, METH_VARARGS, rindex__doc__},
-	{"rstrip", (PyCFunction)string_rstrip, METH_VARARGS, rstrip__doc__},
+	{"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, rjust__doc__},
 	{"rpartition", (PyCFunction)string_rpartition, METH_O,
 	 rpartition__doc__},
+	{"rsplit", (PyCFunction)string_rsplit, METH_VARARGS, rsplit__doc__},
+	{"rstrip", (PyCFunction)string_rstrip, METH_VARARGS, rstrip__doc__},
+	{"split", (PyCFunction)string_split, METH_VARARGS, split__doc__},
+	{"splitlines", (PyCFunction)stringlib_splitlines, METH_VARARGS,
+	 splitlines__doc__},
 	{"startswith", (PyCFunction)string_startswith, METH_VARARGS,
-	 startswith__doc__},
+         startswith__doc__},
 	{"strip", (PyCFunction)string_strip, METH_VARARGS, strip__doc__},
-	{"swapcase", (PyCFunction)string_swapcase, METH_NOARGS,
-	 swapcase__doc__},
+	{"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS,
+	 _Py_swapcase__doc__},
+	{"title", (PyCFunction)stringlib_title, METH_NOARGS, _Py_title__doc__},
 	{"translate", (PyCFunction)string_translate, METH_VARARGS,
 	 translate__doc__},
-	{"title", (PyCFunction)string_title, METH_NOARGS, title__doc__},
-	{"ljust", (PyCFunction)string_ljust, METH_VARARGS, ljust__doc__},
-	{"rjust", (PyCFunction)string_rjust, METH_VARARGS, rjust__doc__},
-	{"center", (PyCFunction)string_center, METH_VARARGS, center__doc__},
-	{"zfill", (PyCFunction)string_zfill, METH_VARARGS, zfill__doc__},
-	{"encode", (PyCFunction)string_encode, METH_VARARGS, encode__doc__},
-	{"decode", (PyCFunction)string_decode, METH_VARARGS, decode__doc__},
-	{"expandtabs", (PyCFunction)string_expandtabs, METH_VARARGS,
-	 expandtabs__doc__},
-	{"splitlines", (PyCFunction)string_splitlines, METH_VARARGS,
-	 splitlines__doc__},
-	{"__getnewargs__",	(PyCFunction)string_getnewargs,	METH_NOARGS},
+	{"upper", (PyCFunction)stringlib_upper, METH_NOARGS, _Py_upper__doc__},
+	{"zfill", (PyCFunction)stringlib_zfill, METH_VARARGS, zfill__doc__},
 	{NULL,     NULL}		     /* sentinel */
 };
 
@@ -3986,16 +2854,150 @@
 static PyObject *
 string_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-	PyObject *x = NULL;
-	static char *kwlist[] = {"object", 0};
+	PyObject *x = NULL, *it;
+	const char *encoding = NULL;
+	const char *errors = NULL;
+	PyObject *new = NULL;
+	Py_ssize_t i, size;
+	static char *kwlist[] = {"source", "encoding", "errors", 0};
 
 	if (type != &PyString_Type)
 		return str_subtype_new(type, args, kwds);
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:str8", kwlist, &x))
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oss:bytes", kwlist, &x,
+					 &encoding, &errors))
 		return NULL;
-	if (x == NULL)
+	if (x == NULL) {
+		if (encoding != NULL || errors != NULL) {
+			PyErr_SetString(PyExc_TypeError,
+					"encoding or errors without sequence "
+					"argument");
+			return NULL;
+		}
 		return PyString_FromString("");
-	return PyObject_Str(x);
+	}
+
+	if (PyUnicode_Check(x)) {
+		/* Encode via the codec registry */
+		if (encoding == NULL) {
+			PyErr_SetString(PyExc_TypeError,
+					"string argument without an encoding");
+			return NULL;
+		}
+		new = PyCodec_Encode(x, encoding, errors);
+		if (new == NULL)
+			return NULL;
+		assert(PyString_Check(new));
+		return new;
+	}
+
+	/* If it's not unicode, there can't be encoding or errors */
+	if (encoding != NULL || errors != NULL) {
+		PyErr_SetString(PyExc_TypeError,
+			"encoding or errors without a string argument");
+		return NULL;
+	}
+
+	/* Is it an int? */
+	size = PyNumber_AsSsize_t(x, PyExc_ValueError);
+	if (size == -1 && PyErr_Occurred()) {
+		PyErr_Clear();
+	}
+	else {
+		if (size < 0) {
+			PyErr_SetString(PyExc_ValueError, "negative count");
+			return NULL;
+		}
+		new = PyString_FromStringAndSize(NULL, size);
+		if (new == NULL) {
+			return NULL;
+		}
+		if (size > 0) {
+			memset(((PyStringObject*)new)->ob_sval, 0, size);
+		}
+		return new;
+	}
+
+	/* Use the modern buffer interface */
+	if (PyObject_CheckBuffer(x)) {
+		Py_buffer view;
+		if (PyObject_GetBuffer(x, &view, PyBUF_FULL_RO) < 0)
+			return NULL;
+		new = PyString_FromStringAndSize(NULL, view.len);
+		if (!new)
+			goto fail;
+		// XXX(brett.cannon): Better way to get to internal buffer?
+		if (PyBuffer_ToContiguous(((PyStringObject *)new)->ob_sval,
+					  &view, view.len, 'C') < 0)
+			goto fail;
+		PyObject_ReleaseBuffer(x, &view);
+		return new;
+	  fail:
+		Py_XDECREF(new);
+		PyObject_ReleaseBuffer(x, &view);
+		return NULL;
+	}
+
+	/* For iterator version, create a string object and resize as needed */
+	/* XXX(gb): is 64 a good value? also, optimize if length is known */
+	/* XXX(guido): perhaps use Pysequence_Fast() -- I can't imagine the
+	   input being a truly long iterator. */
+	size = 64;
+	new = PyString_FromStringAndSize(NULL, size);
+	if (new == NULL)
+		return NULL;
+
+	/* XXX Optimize this if the arguments is a list, tuple */
+
+	/* Get the iterator */
+	it = PyObject_GetIter(x);
+	if (it == NULL)
+		goto error;
+
+	/* Run the iterator to exhaustion */
+	for (i = 0; ; i++) {
+		PyObject *item;
+		Py_ssize_t value;
+
+		/* Get the next item */
+		item = PyIter_Next(it);
+		if (item == NULL) {
+			if (PyErr_Occurred())
+				goto error;
+			break;
+		}
+
+		/* Interpret it as an int (__index__) */
+		value = PyNumber_AsSsize_t(item, PyExc_ValueError);
+		Py_DECREF(item);
+		if (value == -1 && PyErr_Occurred())
+			goto error;
+
+		/* Range check */
+		if (value < 0 || value >= 256) {
+			PyErr_SetString(PyExc_ValueError,
+					"bytes must be in range(0, 256)");
+			goto error;
+		}
+
+		/* Append the byte */
+		if (i >= size) {
+			size *= 2;
+			if (_PyString_Resize(&new, size) < 0)
+				goto error;
+		}
+		((PyStringObject *)new)->ob_sval[i] = value;
+	}
+	_PyString_Resize(&new, i);
+
+	/* Clean up and return success */
+	Py_DECREF(it);
+	return new;
+
+  error:
+	/* Error handling when new != NULL */
+	Py_XDECREF(it);
+	Py_DECREF(new);
+	return NULL;
 }
 
 static PyObject *
@@ -4012,97 +3014,32 @@
 	n = PyString_GET_SIZE(tmp);
 	pnew = type->tp_alloc(type, n);
 	if (pnew != NULL) {
-		Py_MEMCPY(PyString_AS_STRING(pnew), PyString_AS_STRING(tmp), n+1);
+		Py_MEMCPY(PyString_AS_STRING(pnew),
+			  PyString_AS_STRING(tmp), n+1);
 		((PyStringObject *)pnew)->ob_shash =
 			((PyStringObject *)tmp)->ob_shash;
-		((PyStringObject *)pnew)->ob_sstate = SSTATE_NOT_INTERNED;
 	}
 	Py_DECREF(tmp);
 	return pnew;
 }
 
-static PyObject *
-basestring_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
-	PyErr_SetString(PyExc_TypeError,
-			"The basestring type cannot be instantiated");
-	return NULL;
-}
-
-static PyObject *
-string_mod(PyObject *v, PyObject *w)
-{
-	if (!PyString_Check(v)) {
-		Py_INCREF(Py_NotImplemented);
-		return Py_NotImplemented;
-	}
-	return PyString_Format(v, w);
-}
-
-PyDoc_STRVAR(basestring_doc,
-"Type basestring cannot be instantiated; it is the base for str8 and str.");
-
-static PyNumberMethods string_as_number = {
-	0,			/*nb_add*/
-	0,			/*nb_subtract*/
-	0,			/*nb_multiply*/
-	string_mod,		/*nb_remainder*/
-};
-
-
-PyTypeObject PyBaseString_Type = {
-	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"basestring",
-	0,
-	0,
- 	0,			 		/* tp_dealloc */
-	0,			 		/* tp_print */
-	0,					/* tp_getattr */
-	0,					/* tp_setattr */
-	0,					/* tp_compare */
-	0,		 			/* tp_repr */
-	0,					/* tp_as_number */
-	0,					/* tp_as_sequence */
-	0,					/* tp_as_mapping */
-	0,		 			/* tp_hash */
-	0,					/* tp_call */
-	0,					/* tp_str */
-	0,					/* tp_getattro */
-	0,					/* tp_setattro */
-	0,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
-	basestring_doc,				/* tp_doc */
-	0,					/* tp_traverse */
-	0,					/* tp_clear */
-	0,					/* tp_richcompare */
-	0,					/* tp_weaklistoffset */
-	0,					/* tp_iter */
-	0,					/* tp_iternext */
-	0,					/* tp_methods */
-	0,					/* tp_members */
-	0,					/* tp_getset */
-	&PyBaseObject_Type,			/* tp_base */
-	0,					/* tp_dict */
-	0,					/* tp_descr_get */
-	0,					/* tp_descr_set */
-	0,					/* tp_dictoffset */
-	0,					/* tp_init */
-	0,					/* tp_alloc */
-	basestring_new,				/* tp_new */
-	0,		                	/* tp_free */
-};
-
 PyDoc_STRVAR(string_doc,
-"str(object) -> string\n\
-\n\
-Return a nice string representation of the object.\n\
-If the argument is a string, the return value is the same object.");
+"bytes(iterable_of_ints) -> bytes.\n\
+bytes(string, encoding[, errors]) -> bytes\n\
+bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer.\n\
+bytes(memory_view) -> bytes.\n\
+\n\
+Construct an immutable array of bytes from:\n\
+  - an iterable yielding integers in range(256)\n\
+  - a text string encoded using the specified encoding\n\
+  - a bytes or a buffer object\n\
+  - any object implementing the buffer API.");
 
 static PyObject *str_iter(PyObject *seq);
 
 PyTypeObject PyString_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"str8",
+	"bytes",
 	sizeof(PyStringObject),
 	sizeof(char),
  	string_dealloc, 			/* tp_dealloc */
@@ -4110,8 +3047,8 @@
 	0,					/* tp_getattr */
 	0,					/* tp_setattr */
 	0,					/* tp_compare */
-	string_repr, 				/* tp_repr */
-	&string_as_number,			/* tp_as_number */
+	(reprfunc)string_repr, 			/* tp_repr */
+	0,					/* tp_as_number */
 	&string_as_sequence,			/* tp_as_sequence */
 	&string_as_mapping,			/* tp_as_mapping */
 	(hashfunc)string_hash, 			/* tp_hash */
@@ -4132,7 +3069,7 @@
 	string_methods,				/* tp_methods */
 	0,					/* tp_members */
 	0,					/* tp_getset */
-	&PyBaseString_Type,			/* tp_base */
+	&PyBaseObject_Type,			/* tp_base */
 	0,					/* tp_dict */
 	0,					/* tp_descr_get */
 	0,					/* tp_descr_set */
@@ -4147,14 +3084,15 @@
 PyString_Concat(register PyObject **pv, register PyObject *w)
 {
 	register PyObject *v;
+	assert(pv != NULL);
 	if (*pv == NULL)
 		return;
-	if (w == NULL || !PyString_Check(*pv)) {
+	if (w == NULL) {
 		Py_DECREF(*pv);
 		*pv = NULL;
 		return;
 	}
-	v = string_concat((PyStringObject *) *pv, w);
+	v = string_concat(*pv, w);
 	Py_DECREF(*pv);
 	*pv = v;
 }
@@ -4187,8 +3125,7 @@
 	register PyObject *v;
 	register PyStringObject *sv;
 	v = *pv;
-	if (!PyString_Check(v) || Py_Refcnt(v) != 1 || newsize < 0 ||
-	    PyString_CHECK_INTERNED(v)) {
+	if (!PyString_Check(v) || Py_REFCNT(v) != 1 || newsize < 0) {
 		*pv = 0;
 		Py_DECREF(v);
 		PyErr_BadInternalCall();
@@ -4206,91 +3143,12 @@
 	}
 	_Py_NewReference(*pv);
 	sv = (PyStringObject *) *pv;
-	Py_Size(sv) = newsize;
+	Py_SIZE(sv) = newsize;
 	sv->ob_sval[newsize] = '\0';
 	sv->ob_shash = -1;	/* invalidate cached hash value */
 	return 0;
 }
 
-/* Helpers for formatstring */
-
-Py_LOCAL_INLINE(PyObject *)
-getnextarg(PyObject *args, Py_ssize_t arglen, Py_ssize_t *p_argidx)
-{
-	Py_ssize_t argidx = *p_argidx;
-	if (argidx < arglen) {
-		(*p_argidx)++;
-		if (arglen < 0)
-			return args;
-		else
-			return PyTuple_GetItem(args, argidx);
-	}
-	PyErr_SetString(PyExc_TypeError,
-			"not enough arguments for format string");
-	return NULL;
-}
-
-/* Format codes
- * F_LJUST	'-'
- * F_SIGN	'+'
- * F_BLANK	' '
- * F_ALT	'#'
- * F_ZERO	'0'
- */
-#define F_LJUST (1<<0)
-#define F_SIGN	(1<<1)
-#define F_BLANK (1<<2)
-#define F_ALT	(1<<3)
-#define F_ZERO	(1<<4)
-
-Py_LOCAL_INLINE(int)
-formatfloat(char *buf, size_t buflen, int flags,
-            int prec, int type, PyObject *v)
-{
-	/* fmt = '%#.' + `prec` + `type`
-	   worst case length = 3 + 10 (len of INT_MAX) + 1 = 14 (use 20)*/
-	char fmt[20];
-	double x;
-	x = PyFloat_AsDouble(v);
-	if (x == -1.0 && PyErr_Occurred()) {
-		PyErr_Format(PyExc_TypeError, "float argument required, "
-			     "not %.200s", Py_Type(v)->tp_name);
-		return -1;
-	}
-	if (prec < 0)
-		prec = 6;
-	if (type == 'f' && fabs(x)/1e25 >= 1e25)
-		type = 'g';
-	/* Worst case length calc to ensure no buffer overrun:
-
-	   'g' formats:
-	     fmt = %#.<prec>g
-	     buf = '-' + [0-9]*prec + '.' + 'e+' + (longest exp
-	        for any double rep.)
-	     len = 1 + prec + 1 + 2 + 5 = 9 + prec
-
-	   'f' formats:
-	     buf = '-' + [0-9]*x + '.' + [0-9]*prec (with x < 50)
-	     len = 1 + 50 + 1 + prec = 52 + prec
-
-	   If prec=0 the effective precision is 1 (the leading digit is
-	   always given), therefore increase the length by one.
-
-	*/
-	if (((type == 'g' || type == 'G') &&
-              buflen <= (size_t)10 + (size_t)prec) ||
-	    (type == 'f' && buflen <= (size_t)53 + (size_t)prec)) {
-		PyErr_SetString(PyExc_OverflowError,
-			"formatted float is too long (precision too large?)");
-		return -1;
-	}
-	PyOS_snprintf(fmt, sizeof(fmt), "%%%s.%d%c",
-		      (flags&F_ALT) ? "#" : "",
-		      prec, type);
-        PyOS_ascii_formatd(buf, buflen, fmt, x);
-	return (int)strlen(buf);
-}
-
 /* _PyString_FormatLong emulates the format codes d, u, o, x and X, and
  * the F_ALT flag, for Python's long (unbounded) ints.  It's not used for
  * Python's regular ints.
@@ -4339,7 +3197,7 @@
 		if (PyBool_Check(val))
 			result = PyNumber_ToBase(val, 10);
 		else
-			result = Py_Type(val)->tp_str(val);
+			result = Py_TYPE(val)->tp_str(val);
 		break;
 	case 'o':
 		numnondigits = 2;
@@ -4356,20 +3214,21 @@
 	if (!result)
 		return NULL;
 
-	buf = PyString_AsString(result);
+	buf = PyUnicode_AsString(result);
 	if (!buf) {
 		Py_DECREF(result);
 		return NULL;
 	}
 
 	/* To modify the string in-place, there can only be one reference. */
-	if (Py_Refcnt(result) != 1) {
+	if (Py_REFCNT(result) != 1) {
 		PyErr_BadInternalCall();
 		return NULL;
 	}
-	llen = PyString_Size(result);
+	llen = PyUnicode_GetSize(result);
 	if (llen > INT_MAX) {
-		PyErr_SetString(PyExc_ValueError, "string too large in _PyString_FormatLong");
+		PyErr_SetString(PyExc_ValueError,
+				"string too large in _PyString_FormatLong");
 		return NULL;
 	}
 	len = (int)llen;
@@ -4387,7 +3246,7 @@
 	    (type == 'o' || type == 'x' || type == 'X'))) {
 		assert(buf[sign] == '0');
 		assert(buf[sign+1] == 'x' || buf[sign+1] == 'X' ||
-                       buf[sign+1] == 'o');
+		       buf[sign+1] == 'o');
 		numnondigits -= 2;
 		buf += 2;
 		len -= 2;
@@ -4433,623 +3292,6 @@
 	return result;
 }
 
-Py_LOCAL_INLINE(int)
-formatint(char *buf, size_t buflen, int flags,
-          int prec, int type, PyObject *v)
-{
-	/* fmt = '%#.' + `prec` + 'l' + `type`
-	   worst case length = 3 + 19 (worst len of INT_MAX on 64-bit machine)
-	   + 1 + 1 = 24 */
-	char fmt[64];	/* plenty big enough! */
-	char *sign;
-	long x;
-
-	x = PyInt_AsLong(v);
-	if (x == -1 && PyErr_Occurred()) {
-		PyErr_Format(PyExc_TypeError, "int argument required, not %.200s",
-			     Py_Type(v)->tp_name);
-		return -1;
-	}
-	if (x < 0 && type == 'u') {
-		type = 'd';
-	}
-	if (x < 0 && (type == 'x' || type == 'X' || type == 'o'))
-		sign = "-";
-	else
-		sign = "";
-	if (prec < 0)
-		prec = 1;
-
-	if ((flags & F_ALT) &&
-	    (type == 'x' || type == 'X' || type == 'o')) {
-		/* When converting under %#o, %#x or %#X, there are a number
-		 * of issues that cause pain:
-		 * - for %#o, we want a different base marker than C
-		 * - when 0 is being converted, the C standard leaves off
-		 *   the '0x' or '0X', which is inconsistent with other
-		 *   %#x/%#X conversions and inconsistent with Python's
-		 *   hex() function
-		 * - there are platforms that violate the standard and
-		 *   convert 0 with the '0x' or '0X'
-		 *   (Metrowerks, Compaq Tru64)
-		 * - there are platforms that give '0x' when converting
-		 *   under %#X, but convert 0 in accordance with the
-		 *   standard (OS/2 EMX)
-		 *
-		 * We can achieve the desired consistency by inserting our
-		 * own '0x' or '0X' prefix, and substituting %x/%X in place
-		 * of %#x/%#X.
-		 *
-		 * Note that this is the same approach as used in
-		 * formatint() in unicodeobject.c
-		 */
-		PyOS_snprintf(fmt, sizeof(fmt), "%s0%c%%.%dl%c",
-			      sign, type, prec, type);
-	}
-	else {
-		PyOS_snprintf(fmt, sizeof(fmt), "%s%%%s.%dl%c",
-			      sign, (flags&F_ALT) ? "#" : "",
-			      prec, type);
-	}
-
-	/* buf = '+'/'-'/'' + '0o'/'0x'/'' + '[0-9]'*max(prec, len(x in octal))
-	 * worst case buf = '-0x' + [0-9]*prec, where prec >= 11
-	 */
-	if (buflen <= 14 || buflen <= (size_t)3 + (size_t)prec) {
-		PyErr_SetString(PyExc_OverflowError,
-		    "formatted integer is too long (precision too large?)");
-		return -1;
-	}
-	if (sign[0])
-		PyOS_snprintf(buf, buflen, fmt, -x);
-	else
-		PyOS_snprintf(buf, buflen, fmt, x);
-	return (int)strlen(buf);
-}
-
-Py_LOCAL_INLINE(int)
-formatchar(char *buf, size_t buflen, PyObject *v)
-{
-	/* presume that the buffer is at least 2 characters long */
-	if (PyString_Check(v)) {
-		if (!PyArg_Parse(v, "c;%c requires int or char", &buf[0]))
-			return -1;
-	}
-	else {
-		if (!PyArg_Parse(v, "b;%c requires int or char", &buf[0]))
-			return -1;
-	}
-	buf[1] = '\0';
-	return 1;
-}
-
-/* fmt%(v1,v2,...) is roughly equivalent to sprintf(fmt, v1, v2, ...)
-
-   FORMATBUFLEN is the length of the buffer in which the floats, ints, &
-   chars are formatted. XXX This is a magic number. Each formatting
-   routine does bounds checking to ensure no overflow, but a better
-   solution may be to malloc a buffer of appropriate size for each
-   format. For now, the current solution is sufficient.
-*/
-#define FORMATBUFLEN (size_t)120
-
-PyObject *
-PyString_Format(PyObject *format, PyObject *args)
-{
-	char *fmt, *res;
-	Py_ssize_t arglen, argidx;
-	Py_ssize_t reslen, rescnt, fmtcnt;
-	int args_owned = 0;
-	PyObject *result, *orig_args;
-	PyObject *v, *w;
-	PyObject *dict = NULL;
-	if (format == NULL || !PyString_Check(format) || args == NULL) {
-		PyErr_BadInternalCall();
-		return NULL;
-	}
-	orig_args = args;
-	fmt = PyString_AS_STRING(format);
-	fmtcnt = PyString_GET_SIZE(format);
-	reslen = rescnt = fmtcnt + 100;
-	result = PyString_FromStringAndSize((char *)NULL, reslen);
-	if (result == NULL)
-		return NULL;
-	res = PyString_AsString(result);
-	if (PyTuple_Check(args)) {
-		arglen = PyTuple_GET_SIZE(args);
-		argidx = 0;
-	}
-	else {
-		arglen = -1;
-		argidx = -2;
-	}
-	if (Py_Type(args)->tp_as_mapping && !PyTuple_Check(args) &&
-	    !PyObject_TypeCheck(args, &PyBaseString_Type))
-		dict = args;
-	while (--fmtcnt >= 0) {
-		if (*fmt != '%') {
-			if (--rescnt < 0) {
-				rescnt = fmtcnt + 100;
-				reslen += rescnt;
-				if (_PyString_Resize(&result, reslen) < 0)
-					return NULL;
-				res = PyString_AS_STRING(result)
-					+ reslen - rescnt;
-				--rescnt;
-			}
-			*res++ = *fmt++;
-		}
-		else {
-			/* Got a format specifier */
-			int flags = 0;
-			Py_ssize_t width = -1;
-			int prec = -1;
-			int c = '\0';
-			int fill;
-			PyObject *v = NULL;
-			PyObject *temp = NULL;
-			char *pbuf;
-			int sign;
-			Py_ssize_t len;
-			char formatbuf[FORMATBUFLEN];
-			     /* For format{float,int,char}() */
-			char *fmt_start = fmt;
-			Py_ssize_t argidx_start = argidx;
-
-			fmt++;
-			if (*fmt == '(') {
-				char *keystart;
-				Py_ssize_t keylen;
-				PyObject *key;
-				int pcount = 1;
-
-				if (dict == NULL) {
-					PyErr_SetString(PyExc_TypeError,
-						 "format requires a mapping");
-					goto error;
-				}
-				++fmt;
-				--fmtcnt;
-				keystart = fmt;
-				/* Skip over balanced parentheses */
-				while (pcount > 0 && --fmtcnt >= 0) {
-					if (*fmt == ')')
-						--pcount;
-					else if (*fmt == '(')
-						++pcount;
-					fmt++;
-				}
-				keylen = fmt - keystart - 1;
-				if (fmtcnt < 0 || pcount > 0) {
-					PyErr_SetString(PyExc_ValueError,
-						   "incomplete format key");
-					goto error;
-				}
-				key = PyString_FromStringAndSize(keystart,
-								 keylen);
-				if (key == NULL)
-					goto error;
-				if (args_owned) {
-					Py_DECREF(args);
-					args_owned = 0;
-				}
-				args = PyObject_GetItem(dict, key);
-				Py_DECREF(key);
-				if (args == NULL) {
-					goto error;
-				}
-				args_owned = 1;
-				arglen = -1;
-				argidx = -2;
-			}
-			while (--fmtcnt >= 0) {
-				switch (c = *fmt++) {
-				case '-': flags |= F_LJUST; continue;
-				case '+': flags |= F_SIGN; continue;
-				case ' ': flags |= F_BLANK; continue;
-				case '#': flags |= F_ALT; continue;
-				case '0': flags |= F_ZERO; continue;
-				}
-				break;
-			}
-			if (c == '*') {
-				v = getnextarg(args, arglen, &argidx);
-				if (v == NULL)
-					goto error;
-				if (!PyInt_Check(v)) {
-					PyErr_SetString(PyExc_TypeError,
-							"* wants int");
-					goto error;
-				}
-				width = PyInt_AsLong(v);
-				if (width == -1 && PyErr_Occurred())
-					goto error;
-				if (width < 0) {
-					flags |= F_LJUST;
-					width = -width;
-				}
-				if (--fmtcnt >= 0)
-					c = *fmt++;
-			}
-			else if (c >= 0 && ISDIGIT(c)) {
-				width = c - '0';
-				while (--fmtcnt >= 0) {
-					c = Py_CHARMASK(*fmt++);
-					if (!ISDIGIT(c))
-						break;
-					if ((width*10) / 10 != width) {
-						PyErr_SetString(
-							PyExc_ValueError,
-							"width too big");
-						goto error;
-					}
-					width = width*10 + (c - '0');
-				}
-			}
-			if (c == '.') {
-				prec = 0;
-				if (--fmtcnt >= 0)
-					c = *fmt++;
-				if (c == '*') {
-					v = getnextarg(args, arglen, &argidx);
-					if (v == NULL)
-						goto error;
-					if (!PyInt_Check(v)) {
-						PyErr_SetString(
-							PyExc_TypeError,
-							"* wants int");
-						goto error;
-					}
-					prec = PyInt_AsLong(v);
-					if (prec == -1 && PyErr_Occurred())
-						goto error;
-					if (prec < 0)
-						prec = 0;
-					if (--fmtcnt >= 0)
-						c = *fmt++;
-				}
-				else if (c >= 0 && ISDIGIT(c)) {
-					prec = c - '0';
-					while (--fmtcnt >= 0) {
-						c = Py_CHARMASK(*fmt++);
-						if (!ISDIGIT(c))
-							break;
-						if ((prec*10) / 10 != prec) {
-							PyErr_SetString(
-							    PyExc_ValueError,
-							    "prec too big");
-							goto error;
-						}
-						prec = prec*10 + (c - '0');
-					}
-				}
-			} /* prec */
-			if (fmtcnt >= 0) {
-				if (c == 'h' || c == 'l' || c == 'L') {
-					if (--fmtcnt >= 0)
-						c = *fmt++;
-				}
-			}
-			if (fmtcnt < 0) {
-				PyErr_SetString(PyExc_ValueError,
-						"incomplete format");
-				goto error;
-			}
-			if (c != '%') {
-				v = getnextarg(args, arglen, &argidx);
-				if (v == NULL)
-					goto error;
-			}
-			sign = 0;
-			fill = ' ';
-			switch (c) {
-			case '%':
-				pbuf = "%";
-				len = 1;
-				break;
-			case 's':
-				if (PyUnicode_Check(v)) {
-					fmt = fmt_start;
-					argidx = argidx_start;
-					goto unicode;
-				}
-				temp = _PyObject_Str(v);
-				if (temp != NULL && PyUnicode_Check(temp)) {
-					Py_DECREF(temp);
-					fmt = fmt_start;
-					argidx = argidx_start;
-					goto unicode;
-				}
-				/* Fall through */
-			case 'r':
-				if (c == 'r')
-					temp = PyObject_ReprStr8(v);
-				if (temp == NULL)
-					goto error;
-				if (!PyString_Check(temp)) {
-					PyErr_SetString(PyExc_TypeError,
-					  "%s argument has non-string str()/repr()");
-					Py_DECREF(temp);
-					goto error;
-				}
-				pbuf = PyString_AS_STRING(temp);
-				len = PyString_GET_SIZE(temp);
-				if (prec >= 0 && len > prec)
-					len = prec;
-				break;
-			case 'i':
-			case 'd':
-			case 'u':
-			case 'o':
-			case 'x':
-			case 'X':
-				if (c == 'i')
-					c = 'd';
-				if (PyLong_Check(v)) {
-					int ilen;
-					temp = _PyString_FormatLong(v, flags,
-						prec, c, &pbuf, &ilen);
-					len = ilen;
-					if (!temp)
-						goto error;
-					sign = 1;
-				}
-				else {
-					pbuf = formatbuf;
-					len = formatint(pbuf,
-							sizeof(formatbuf),
-							flags, prec, c, v);
-					if (len < 0)
-						goto error;
-					sign = 1;
-				}
-				if (flags & F_ZERO)
-					fill = '0';
-				break;
-			case 'e':
-			case 'E':
-			case 'f':
-			case 'F':
-			case 'g':
-			case 'G':
-				if (c == 'F')
-					c = 'f';
-				pbuf = formatbuf;
-				len = formatfloat(pbuf, sizeof(formatbuf),
-						  flags, prec, c, v);
-				if (len < 0)
-					goto error;
-				sign = 1;
-				if (flags & F_ZERO)
-					fill = '0';
-				break;
-			case 'c':
-				if (PyUnicode_Check(v)) {
-					fmt = fmt_start;
-					argidx = argidx_start;
-					goto unicode;
-				}
-				pbuf = formatbuf;
-				len = formatchar(pbuf, sizeof(formatbuf), v);
-				if (len < 0)
-					goto error;
-				break;
-			default:
-				PyErr_Format(PyExc_ValueError,
-				  "unsupported format character '%c' (0x%x) "
-				  "at index %zd",
-				  c, c,
-				  (Py_ssize_t)(fmt - 1 -
-					       PyString_AsString(format)));
-				goto error;
-			}
-			if (sign) {
-				if (*pbuf == '-' || *pbuf == '+') {
-					sign = *pbuf++;
-					len--;
-				}
-				else if (flags & F_SIGN)
-					sign = '+';
-				else if (flags & F_BLANK)
-					sign = ' ';
-				else
-					sign = 0;
-			}
-			if (width < len)
-				width = len;
-			if (rescnt - (sign != 0) < width) {
-				reslen -= rescnt;
-				rescnt = width + fmtcnt + 100;
-				reslen += rescnt;
-				if (reslen < 0) {
-					Py_DECREF(result);
-					Py_XDECREF(temp);
-					return PyErr_NoMemory();
-				}
-				if (_PyString_Resize(&result, reslen) < 0) {
-					Py_XDECREF(temp);
-					return NULL;
-				}
-				res = PyString_AS_STRING(result)
-					+ reslen - rescnt;
-			}
-			if (sign) {
-				if (fill != ' ')
-					*res++ = sign;
-				rescnt--;
-				if (width > len)
-					width--;
-			}
-			if ((flags & F_ALT) &&
-			    (c == 'x' || c == 'X' || c == 'o')) {
-				assert(pbuf[0] == '0');
-				assert(pbuf[1] == c);
-				if (fill != ' ') {
-					*res++ = *pbuf++;
-					*res++ = *pbuf++;
-				}
-				rescnt -= 2;
-				width -= 2;
-				if (width < 0)
-					width = 0;
-				len -= 2;
-			}
-			if (width > len && !(flags & F_LJUST)) {
-				do {
-					--rescnt;
-					*res++ = fill;
-				} while (--width > len);
-			}
-			if (fill == ' ') {
-				if (sign)
-					*res++ = sign;
-				if ((flags & F_ALT) &&
-				    (c == 'x' || c == 'X' || c == 'o')) {
-					assert(pbuf[0] == '0');
-					assert(pbuf[1] == c);
-					*res++ = *pbuf++;
-					*res++ = *pbuf++;
-				}
-			}
-			Py_MEMCPY(res, pbuf, len);
-			res += len;
-			rescnt -= len;
-			while (--width >= len) {
-				--rescnt;
-				*res++ = ' ';
-			}
-                        if (dict && (argidx < arglen) && c != '%') {
-                                PyErr_SetString(PyExc_TypeError,
-                                           "not all arguments converted during string formatting");
-                                Py_XDECREF(temp);
-                                goto error;
-                        }
-			Py_XDECREF(temp);
-		} /* '%' */
-	} /* until end */
-	if (argidx < arglen && !dict) {
-		PyErr_SetString(PyExc_TypeError,
-				"not all arguments converted during string formatting");
-		goto error;
-	}
-	if (args_owned) {
-		Py_DECREF(args);
-	}
-	_PyString_Resize(&result, reslen - rescnt);
-	return result;
-
- unicode:
-	if (args_owned) {
-		Py_DECREF(args);
-		args_owned = 0;
-	}
-	/* Fiddle args right (remove the first argidx arguments) */
-	if (PyTuple_Check(orig_args) && argidx > 0) {
-		PyObject *v;
-		Py_ssize_t n = PyTuple_GET_SIZE(orig_args) - argidx;
-		v = PyTuple_New(n);
-		if (v == NULL)
-			goto error;
-		while (--n >= 0) {
-			PyObject *w = PyTuple_GET_ITEM(orig_args, n + argidx);
-			Py_INCREF(w);
-			PyTuple_SET_ITEM(v, n, w);
-		}
-		args = v;
-	} else {
-		Py_INCREF(orig_args);
-		args = orig_args;
-	}
-	args_owned = 1;
-	/* Take what we have of the result and let the Unicode formatting
-	   function format the rest of the input. */
-	rescnt = res - PyString_AS_STRING(result);
-	if (_PyString_Resize(&result, rescnt))
-		goto error;
-	fmtcnt = PyString_GET_SIZE(format) - \
-		 (fmt - PyString_AS_STRING(format));
-	format = PyUnicode_Decode(fmt, fmtcnt, NULL, NULL);
-	if (format == NULL)
-		goto error;
-	v = PyUnicode_Format(format, args);
-	Py_DECREF(format);
-	if (v == NULL)
-		goto error;
-	/* Paste what we have (result) to what the Unicode formatting
-	   function returned (v) and return the result (or error) */
-	w = PyUnicode_Concat(result, v);
-	Py_DECREF(result);
-	Py_DECREF(v);
-	Py_DECREF(args);
-	return w;
-
- error:
-	Py_DECREF(result);
-	if (args_owned) {
-		Py_DECREF(args);
-	}
-	return NULL;
-}
-
-void
-PyString_InternInPlace(PyObject **p)
-{
-	register PyStringObject *s = (PyStringObject *)(*p);
-	PyObject *t;
-	if (s == NULL || !PyString_Check(s))
-		Py_FatalError("PyString_InternInPlace: strings only please!");
-	/* If it's a string subclass, we don't really know what putting
-	   it in the interned dict might do. */
-	if (!PyString_CheckExact(s))
-		return;
-	if (PyString_CHECK_INTERNED(s))
-		return;
-	if (interned == NULL) {
-		interned = PyDict_New();
-		if (interned == NULL) {
-			PyErr_Clear(); /* Don't leave an exception */
-			return;
-		}
-	}
-	t = PyDict_GetItem(interned, (PyObject *)s);
-	if (t) {
-		Py_INCREF(t);
-		Py_DECREF(*p);
-		*p = t;
-		return;
-	}
-
-	if (PyDict_SetItem(interned, (PyObject *)s, (PyObject *)s) < 0) {
-		PyErr_Clear();
-		return;
-	}
-	/* The two references in interned are not counted by refcnt.
-	   The string deallocator will take care of this */
-	Py_Refcnt(s) -= 2;
-	PyString_CHECK_INTERNED(s) = SSTATE_INTERNED_MORTAL;
-}
-
-void
-PyString_InternImmortal(PyObject **p)
-{
-	PyString_InternInPlace(p);
-	if (PyString_CHECK_INTERNED(*p) != SSTATE_INTERNED_IMMORTAL) {
-		PyString_CHECK_INTERNED(*p) = SSTATE_INTERNED_IMMORTAL;
-		Py_INCREF(*p);
-	}
-}
-
-
-PyObject *
-PyString_InternFromString(const char *cp)
-{
-	PyObject *s = PyString_FromString(cp);
-	if (s == NULL)
-		return NULL;
-	PyString_InternInPlace(&s);
-	return s;
-}
-
 void
 PyString_Fini(void)
 {
@@ -5062,58 +3304,6 @@
 	nullstring = NULL;
 }
 
-void _Py_ReleaseInternedStrings(void)
-{
-	PyObject *keys;
-	PyStringObject *s;
-	Py_ssize_t i, n;
-	Py_ssize_t immortal_size = 0, mortal_size = 0;
-
-	if (interned == NULL || !PyDict_Check(interned))
-		return;
-	keys = PyDict_Keys(interned);
-	if (keys == NULL || !PyList_Check(keys)) {
-		PyErr_Clear();
-		return;
-	}
-
-	/* Since _Py_ReleaseInternedStrings() is intended to help a leak
-	   detector, interned strings are not forcibly deallocated; rather, we
-	   give them their stolen references back, and then clear and DECREF
-	   the interned dict. */
-
-	n = PyList_GET_SIZE(keys);
-	fprintf(stderr, "releasing %" PY_FORMAT_SIZE_T "d interned strings\n",
-		n);
-	for (i = 0; i < n; i++) {
-		s = (PyStringObject *) PyList_GET_ITEM(keys, i);
-		switch (s->ob_sstate) {
-		case SSTATE_NOT_INTERNED:
-			/* XXX Shouldn't happen */
-			break;
-		case SSTATE_INTERNED_IMMORTAL:
-			Py_Refcnt(s) += 1;
-			immortal_size += Py_Size(s);
-			break;
-		case SSTATE_INTERNED_MORTAL:
-			Py_Refcnt(s) += 2;
-			mortal_size += Py_Size(s);
-			break;
-		default:
-			Py_FatalError("Inconsistent interned string state.");
-		}
-		s->ob_sstate = SSTATE_NOT_INTERNED;
-	}
-	fprintf(stderr, "total size of all interned strings: "
-			"%" PY_FORMAT_SIZE_T "d/%" PY_FORMAT_SIZE_T "d "
-			"mortal/immortal\n", mortal_size, immortal_size);
-	Py_DECREF(keys);
-	PyDict_Clear(interned);
-	Py_DECREF(interned);
-	interned = NULL;
-}
-
-
 /*********************** Str Iterator ****************************/
 
 typedef struct {
@@ -5150,8 +3340,8 @@
 	assert(PyString_Check(seq));
 
 	if (it->it_index < PyString_GET_SIZE(seq)) {
-		item = PyString_FromStringAndSize(
-			PyString_AS_STRING(seq)+it->it_index, 1);
+		item = PyLong_FromLong(
+			(unsigned char)seq->ob_sval[it->it_index]);
 		if (item != NULL)
 			++it->it_index;
 		return item;
@@ -5168,7 +3358,7 @@
 	Py_ssize_t len = 0;
 	if (it->it_seq)
 		len = PyString_GET_SIZE(it->it_seq) - it->it_index;
-	return PyInt_FromSsize_t(len);
+	return PyLong_FromSsize_t(len);
 }
 
 PyDoc_STRVAR(length_hint_doc,
@@ -5182,7 +3372,7 @@
 
 PyTypeObject PyStringIter_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"striterator",				/* tp_name */
+	"bytes_iterator",			/* tp_name */
 	sizeof(striterobject),			/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */

Modified: python/branches/py3k-importlib/Objects/structseq.c
==============================================================================
--- python/branches/py3k-importlib/Objects/structseq.c	(original)
+++ python/branches/py3k-importlib/Objects/structseq.c	Thu Mar 27 00:48:05 2008
@@ -13,26 +13,26 @@
    They are only allowed for indices < n_visible_fields. */
 char *PyStructSequence_UnnamedField = "unnamed field";
 
-#define VISIBLE_SIZE(op) Py_Size(op)
-#define VISIBLE_SIZE_TP(tp) PyInt_AsLong( \
+#define VISIBLE_SIZE(op) Py_SIZE(op)
+#define VISIBLE_SIZE_TP(tp) PyLong_AsLong( \
                       PyDict_GetItemString((tp)->tp_dict, visible_length_key))
 
-#define REAL_SIZE_TP(tp) PyInt_AsLong( \
+#define REAL_SIZE_TP(tp) PyLong_AsLong( \
                       PyDict_GetItemString((tp)->tp_dict, real_length_key))
-#define REAL_SIZE(op) REAL_SIZE_TP(Py_Type(op))
+#define REAL_SIZE(op) REAL_SIZE_TP(Py_TYPE(op))
 
-#define UNNAMED_FIELDS_TP(tp) PyInt_AsLong( \
+#define UNNAMED_FIELDS_TP(tp) PyLong_AsLong( \
                       PyDict_GetItemString((tp)->tp_dict, unnamed_fields_key))
-#define UNNAMED_FIELDS(op) UNNAMED_FIELDS_TP(Py_Type(op))
+#define UNNAMED_FIELDS(op) UNNAMED_FIELDS_TP(Py_TYPE(op))
 
 
 PyObject *
 PyStructSequence_New(PyTypeObject *type)
 {
 	PyStructSequence *obj;
-       
+
 	obj = PyObject_New(PyStructSequence, type);
-	Py_Size(obj) = VISIBLE_SIZE_TP(type);
+	Py_SIZE(obj) = VISIBLE_SIZE_TP(type);
 
 	return (PyObject*) obj;
 }
@@ -230,11 +230,83 @@
 static PyObject *
 structseq_repr(PyStructSequence *obj)
 {
-	PyObject *tup, *str;
-	tup = make_tuple(obj);
-	str = PyObject_Repr(tup);
+	/* buffer and type size were chosen well considered. */
+#define REPR_BUFFER_SIZE 512
+#define TYPE_MAXSIZE 100
+
+	PyObject *tup;
+	PyTypeObject *typ = Py_TYPE(obj);
+	int i, removelast = 0;
+	Py_ssize_t len;
+	char buf[REPR_BUFFER_SIZE];
+	char *endofbuf, *pbuf = buf;
+
+	/* pointer to end of writeable buffer; safes space for "...)\0" */
+	endofbuf= &buf[REPR_BUFFER_SIZE-5];
+
+	if ((tup = make_tuple(obj)) == NULL) {
+		return NULL;
+	}
+
+	/* "typename(", limited to  TYPE_MAXSIZE */
+	len = strlen(typ->tp_name) > TYPE_MAXSIZE ? TYPE_MAXSIZE :
+						    strlen(typ->tp_name);
+	strncpy(pbuf, typ->tp_name, len);
+	pbuf += len;
+	*pbuf++ = '(';
+
+	for (i=0; i < VISIBLE_SIZE(obj); i++) {
+		PyObject *val, *repr;
+		char *cname, *crepr;
+
+		cname = typ->tp_members[i].name;
+		
+		val = PyTuple_GetItem(tup, i);
+		if (cname == NULL || val == NULL) {
+			return NULL;
+		}
+		repr = PyObject_Repr(val);
+		if (repr == NULL) {
+			Py_DECREF(tup);
+			return NULL;
+		}
+		crepr = PyUnicode_AsString(repr);
+		if (crepr == NULL) {
+			Py_DECREF(tup);
+			Py_DECREF(repr);
+			return NULL;
+		}
+		
+		/* + 3: keep space for "=" and ", " */
+ 		len = strlen(cname) + strlen(crepr) + 3;
+		if ((pbuf+len) <= endofbuf) {
+			strcpy(pbuf, cname);
+			pbuf += strlen(cname);
+			*pbuf++ = '=';
+			strcpy(pbuf, crepr);
+			pbuf += strlen(crepr);
+			*pbuf++ = ',';
+			*pbuf++ = ' ';
+			removelast = 1;
+			Py_DECREF(repr);
+		}
+		else {
+			strcpy(pbuf, "...");
+			pbuf += 3;
+			removelast = 0;
+			Py_DECREF(repr);
+			break;
+		}
+	}
 	Py_DECREF(tup);
-	return str;
+	if (removelast) {
+		/* overwrite last ", " */
+		pbuf-=2;
+	}
+	*pbuf++ = ')';
+	*pbuf = '\0';
+
+	return PyUnicode_FromString(buf);
 }
 
 static PyObject *
@@ -322,12 +394,12 @@
 	}
 	
 	for (; i < n_fields; i++) {
-		char *n = Py_Type(self)->tp_members[i-n_unnamed_fields].name;
+		char *n = Py_TYPE(self)->tp_members[i-n_unnamed_fields].name;
 		PyDict_SetItemString(dict, n,
 				     self->ob_item[i]);
 	}
 
-	result = Py_BuildValue("(O(OO))", Py_Type(self), tup, dict);
+	result = Py_BuildValue("(O(OO))", Py_TYPE(self), tup, dict);
 
 	Py_DECREF(tup);
 	Py_DECREF(dict);
@@ -451,9 +523,9 @@
 
 	dict = type->tp_dict;
 	PyDict_SetItemString(dict, visible_length_key, 
-		       PyInt_FromLong((long) desc->n_in_sequence));
+		       PyLong_FromLong((long) desc->n_in_sequence));
 	PyDict_SetItemString(dict, real_length_key, 
-		       PyInt_FromLong((long) n_members));
+		       PyLong_FromLong((long) n_members));
 	PyDict_SetItemString(dict, unnamed_fields_key, 
-		       PyInt_FromLong((long) n_unnamed_members));
+		       PyLong_FromLong((long) n_unnamed_members));
 }

Modified: python/branches/py3k-importlib/Objects/tupleobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/tupleobject.c	(original)
+++ python/branches/py3k-importlib/Objects/tupleobject.c	Thu Mar 27 00:48:05 2008
@@ -4,19 +4,19 @@
 #include "Python.h"
 
 /* Speed optimization to avoid frequent malloc/free of small tuples */
-#ifndef MAXSAVESIZE
-#define MAXSAVESIZE	20  /* Largest tuple to save on free list */
+#ifndef PyTuple_MAXSAVESIZE
+#define PyTuple_MAXSAVESIZE	20  /* Largest tuple to save on free list */
 #endif
-#ifndef MAXSAVEDTUPLES 
-#define MAXSAVEDTUPLES  2000  /* Maximum number of tuples of each size to save */
+#ifndef PyTuple_MAXFREELIST 
+#define PyTuple_MAXFREELIST  2000  /* Maximum number of tuples of each size to save */
 #endif
 
-#if MAXSAVESIZE > 0
-/* Entries 1 up to MAXSAVESIZE are free lists, entry 0 is the empty
+#if PyTuple_MAXSAVESIZE > 0
+/* Entries 1 up to PyTuple_MAXSAVESIZE are free lists, entry 0 is the empty
    tuple () of which at most one instance will be allocated.
 */
-static PyTupleObject *free_tuples[MAXSAVESIZE];
-static int num_free_tuples[MAXSAVESIZE];
+static PyTupleObject *free_list[PyTuple_MAXSAVESIZE];
+static int numfree[PyTuple_MAXSAVESIZE];
 #endif
 #ifdef COUNT_ALLOCS
 int fast_tuple_allocs;
@@ -32,25 +32,25 @@
 		PyErr_BadInternalCall();
 		return NULL;
 	}
-#if MAXSAVESIZE > 0
-	if (size == 0 && free_tuples[0]) {
-		op = free_tuples[0];
+#if PyTuple_MAXSAVESIZE > 0
+	if (size == 0 && free_list[0]) {
+		op = free_list[0];
 		Py_INCREF(op);
 #ifdef COUNT_ALLOCS
 		tuple_zero_allocs++;
 #endif
 		return (PyObject *) op;
 	}
-	if (size < MAXSAVESIZE && (op = free_tuples[size]) != NULL) {
-		free_tuples[size] = (PyTupleObject *) op->ob_item[0];
-		num_free_tuples[size]--;
+	if (size < PyTuple_MAXSAVESIZE && (op = free_list[size]) != NULL) {
+		free_list[size] = (PyTupleObject *) op->ob_item[0];
+		numfree[size]--;
 #ifdef COUNT_ALLOCS
 		fast_tuple_allocs++;
 #endif
 		/* Inline PyObject_InitVar */
 #ifdef Py_TRACE_REFS
-		Py_Size(op) = size;
-		Py_Type(op) = &PyTuple_Type;
+		Py_SIZE(op) = size;
+		Py_TYPE(op) = &PyTuple_Type;
 #endif
 		_Py_NewReference((PyObject *)op);
 	}
@@ -71,10 +71,10 @@
 	}
 	for (i=0; i < size; i++)
 		op->ob_item[i] = NULL;
-#if MAXSAVESIZE > 0
+#if PyTuple_MAXSAVESIZE > 0
 	if (size == 0) {
-		free_tuples[0] = op;
-		++num_free_tuples[0];
+		free_list[0] = op;
+		++numfree[0];
 		Py_INCREF(op);	/* extra INCREF so that this is never freed */
 	}
 #endif
@@ -90,7 +90,7 @@
 		return -1;
 	}
 	else
-		return Py_Size(op);
+		return Py_SIZE(op);
 }
 
 PyObject *
@@ -100,7 +100,7 @@
 		PyErr_BadInternalCall();
 		return NULL;
 	}
-	if (i < 0 || i >= Py_Size(op)) {
+	if (i < 0 || i >= Py_SIZE(op)) {
 		PyErr_SetString(PyExc_IndexError, "tuple index out of range");
 		return NULL;
 	}
@@ -117,7 +117,7 @@
 		PyErr_BadInternalCall();
 		return -1;
 	}
-	if (i < 0 || i >= Py_Size(op)) {
+	if (i < 0 || i >= Py_SIZE(op)) {
 		Py_XDECREF(newitem);
 		PyErr_SetString(PyExc_IndexError,
 				"tuple assignment index out of range");
@@ -160,26 +160,26 @@
 tupledealloc(register PyTupleObject *op)
 {
 	register Py_ssize_t i;
-	register Py_ssize_t len =  Py_Size(op);
+	register Py_ssize_t len =  Py_SIZE(op);
 	PyObject_GC_UnTrack(op);
 	Py_TRASHCAN_SAFE_BEGIN(op)
 	if (len > 0) {
 		i = len;
 		while (--i >= 0)
 			Py_XDECREF(op->ob_item[i]);
-#if MAXSAVESIZE > 0
-		if (len < MAXSAVESIZE &&
-		    num_free_tuples[len] < MAXSAVEDTUPLES &&
-		    Py_Type(op) == &PyTuple_Type)
+#if PyTuple_MAXSAVESIZE > 0
+		if (len < PyTuple_MAXSAVESIZE &&
+		    numfree[len] < PyTuple_MAXFREELIST &&
+		    Py_TYPE(op) == &PyTuple_Type)
 		{
-			op->ob_item[0] = (PyObject *) free_tuples[len];
-			num_free_tuples[len]++;
-			free_tuples[len] = op;
+			op->ob_item[0] = (PyObject *) free_list[len];
+			numfree[len]++;
+			free_list[len] = op;
 			goto done; /* return */
 		}
 #endif
 	}
-	Py_Type(op)->tp_free((PyObject *)op);
+	Py_TYPE(op)->tp_free((PyObject *)op);
 done:
 	Py_TRASHCAN_SAFE_END(op)
 }
@@ -191,17 +191,29 @@
 	PyObject *s, *temp;
 	PyObject *pieces, *result = NULL;
 
-	n = Py_Size(v);
+	n = Py_SIZE(v);
 	if (n == 0)
 		return PyUnicode_FromString("()");
 
+	/* While not mutable, it is still possible to end up with a cycle in a
+	   tuple through an object that stores itself within a tuple (and thus
+	   infinitely asks for the repr of itself). This should only be
+	   possible within a type. */
+	i = Py_ReprEnter((PyObject *)v);
+	if (i != 0) {
+		return i > 0 ? PyString_FromString("(...)") : NULL;
+	}
+
 	pieces = PyTuple_New(n);
 	if (pieces == NULL)
 		return NULL;
 
 	/* Do repr() on each element. */
 	for (i = 0; i < n; ++i) {
+		if (Py_EnterRecursiveCall(" while getting the repr of a tuple"))
+			goto Done;
 		s = PyObject_Repr(v->ob_item[i]);
+		Py_LeaveRecursiveCall();
 		if (s == NULL)
 			goto Done;
 		PyTuple_SET_ITEM(pieces, i, s);
@@ -236,6 +248,7 @@
 
 Done:
 	Py_DECREF(pieces);
+	Py_ReprLeave((PyObject *)v);
 	return result;
 }
 
@@ -251,7 +264,7 @@
 tuplehash(PyTupleObject *v)
 {
 	register long x, y;
-	register Py_ssize_t len = Py_Size(v);
+	register Py_ssize_t len = Py_SIZE(v);
 	register PyObject **p;
 	long mult = 1000003L;
 	x = 0x345678L;
@@ -273,7 +286,7 @@
 static Py_ssize_t
 tuplelength(PyTupleObject *a)
 {
-	return Py_Size(a);
+	return Py_SIZE(a);
 }
 
 static int
@@ -282,7 +295,7 @@
 	Py_ssize_t i;
 	int cmp;
 
-	for (i = 0, cmp = 0 ; cmp == 0 && i < Py_Size(a); ++i)
+	for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i)
 		cmp = PyObject_RichCompareBool(el, PyTuple_GET_ITEM(a, i),
 						   Py_EQ);
 	return cmp;
@@ -291,7 +304,7 @@
 static PyObject *
 tupleitem(register PyTupleObject *a, register Py_ssize_t i)
 {
-	if (i < 0 || i >= Py_Size(a)) {
+	if (i < 0 || i >= Py_SIZE(a)) {
 		PyErr_SetString(PyExc_IndexError, "tuple index out of range");
 		return NULL;
 	}
@@ -309,11 +322,11 @@
 	Py_ssize_t len;
 	if (ilow < 0)
 		ilow = 0;
-	if (ihigh > Py_Size(a))
-		ihigh = Py_Size(a);
+	if (ihigh > Py_SIZE(a))
+		ihigh = Py_SIZE(a);
 	if (ihigh < ilow)
 		ihigh = ilow;
-	if (ilow == 0 && ihigh == Py_Size(a) && PyTuple_CheckExact(a)) {
+	if (ilow == 0 && ihigh == Py_SIZE(a) && PyTuple_CheckExact(a)) {
 		Py_INCREF(a);
 		return (PyObject *)a;
 	}
@@ -351,11 +364,11 @@
 	if (!PyTuple_Check(bb)) {
 		PyErr_Format(PyExc_TypeError,
        		     "can only concatenate tuple (not \"%.200s\") to tuple",
-			     Py_Type(bb)->tp_name);
+			     Py_TYPE(bb)->tp_name);
 		return NULL;
 	}
 #define b ((PyTupleObject *)bb)
-	size = Py_Size(a) + Py_Size(b);
+	size = Py_SIZE(a) + Py_SIZE(b);
 	if (size < 0)
 		return PyErr_NoMemory();
 	np = (PyTupleObject *) PyTuple_New(size);
@@ -364,14 +377,14 @@
 	}
 	src = a->ob_item;
 	dest = np->ob_item;
-	for (i = 0; i < Py_Size(a); i++) {
+	for (i = 0; i < Py_SIZE(a); i++) {
 		PyObject *v = src[i];
 		Py_INCREF(v);
 		dest[i] = v;
 	}
 	src = b->ob_item;
-	dest = np->ob_item + Py_Size(a);
-	for (i = 0; i < Py_Size(b); i++) {
+	dest = np->ob_item + Py_SIZE(a);
+	for (i = 0; i < Py_SIZE(b); i++) {
 		PyObject *v = src[i];
 		Py_INCREF(v);
 		dest[i] = v;
@@ -389,18 +402,18 @@
 	PyObject **p, **items;
 	if (n < 0)
 		n = 0;
-	if (Py_Size(a) == 0 || n == 1) {
+	if (Py_SIZE(a) == 0 || n == 1) {
 		if (PyTuple_CheckExact(a)) {
 			/* Since tuples are immutable, we can return a shared
 			   copy in this case */
 			Py_INCREF(a);
 			return (PyObject *)a;
 		}
-		if (Py_Size(a) == 0)
+		if (Py_SIZE(a) == 0)
 			return PyTuple_New(0);
 	}
-	size = Py_Size(a) * n;
-	if (size/Py_Size(a) != n)
+	size = Py_SIZE(a) * n;
+	if (size/Py_SIZE(a) != n)
 		return PyErr_NoMemory();
 	np = (PyTupleObject *) PyTuple_New(size);
 	if (np == NULL)
@@ -408,7 +421,7 @@
 	p = np->ob_item;
 	items = a->ob_item;
 	for (i = 0; i < n; i++) {
-		for (j = 0; j < Py_Size(a); j++) {
+		for (j = 0; j < Py_SIZE(a); j++) {
 			*p = items[j];
 			Py_INCREF(*p);
 			p++;
@@ -417,12 +430,59 @@
 	return (PyObject *) np;
 }
 
+static PyObject *
+tupleindex(PyTupleObject *self, PyObject *args)
+{
+	Py_ssize_t i, start=0, stop=Py_SIZE(self);
+	PyObject *v;
+
+	if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
+	                            _PyEval_SliceIndex, &start,
+	                            _PyEval_SliceIndex, &stop))
+		return NULL;
+	if (start < 0) {
+		start += Py_SIZE(self);
+		if (start < 0)
+			start = 0;
+	}
+	if (stop < 0) {
+		stop += Py_SIZE(self);
+		if (stop < 0)
+			stop = 0;
+	}
+	for (i = start; i < stop && i < Py_SIZE(self); i++) {
+		int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
+		if (cmp > 0)
+			return PyLong_FromSsize_t(i);
+		else if (cmp < 0)
+			return NULL;
+	}
+	PyErr_SetString(PyExc_ValueError, "tuple.index(x): x not in list");
+	return NULL;
+}
+
+static PyObject *
+tuplecount(PyTupleObject *self, PyObject *v)
+{
+	Py_ssize_t count = 0;
+	Py_ssize_t i;
+
+	for (i = 0; i < Py_SIZE(self); i++) {
+		int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
+		if (cmp > 0)
+			count++;
+		else if (cmp < 0)
+			return NULL;
+	}
+	return PyLong_FromSsize_t(count);
+}
+
 static int
 tupletraverse(PyTupleObject *o, visitproc visit, void *arg)
 {
 	Py_ssize_t i;
 
-	for (i = Py_Size(o); --i >= 0; )
+	for (i = Py_SIZE(o); --i >= 0; )
 		Py_VISIT(o->ob_item[i]);
 	return 0;
 }
@@ -442,8 +502,8 @@
 	vt = (PyTupleObject *)v;
 	wt = (PyTupleObject *)w;
 
-	vlen = Py_Size(vt);
-	wlen = Py_Size(wt);
+	vlen = Py_SIZE(vt);
+	wlen = Py_SIZE(wt);
 
 	/* Note:  the corresponding code for lists has an "early out" test
 	 * here when op is EQ or NE and the lengths differ.  That pays there,
@@ -611,7 +671,7 @@
 	else {
 		PyErr_Format(PyExc_TypeError, 
 			     "tuple indices must be integers, not %.200s",
-			     Py_Type(item)->tp_name);
+			     Py_TYPE(item)->tp_name);
 		return NULL;
 	}
 }
@@ -619,12 +679,19 @@
 static PyObject *
 tuple_getnewargs(PyTupleObject *v)
 {
-	return Py_BuildValue("(N)", tupleslice(v, 0, Py_Size(v)));
+	return Py_BuildValue("(N)", tupleslice(v, 0, Py_SIZE(v)));
 	
 }
 
+PyDoc_STRVAR(index_doc,
+"T.index(value, [start, [stop]]) -> integer -- return first index of value");
+PyDoc_STRVAR(count_doc,
+"T.count(value) -> integer -- return number of occurrences of value");
+
 static PyMethodDef tuple_methods[] = {
 	{"__getnewargs__",	(PyCFunction)tuple_getnewargs,	METH_NOARGS},
+	{"index",	(PyCFunction)tupleindex,  METH_VARARGS, index_doc},
+	{"count",	(PyCFunction)tuplecount,  METH_O, count_doc},
 	{NULL,		NULL}		/* sentinel */
 };
 
@@ -695,14 +762,14 @@
 	Py_ssize_t oldsize;
 
 	v = (PyTupleObject *) *pv;
-	if (v == NULL || Py_Type(v) != &PyTuple_Type ||
-	    (Py_Size(v) != 0 && Py_Refcnt(v) != 1)) {
+	if (v == NULL || Py_TYPE(v) != &PyTuple_Type ||
+	    (Py_SIZE(v) != 0 && Py_REFCNT(v) != 1)) {
 		*pv = 0;
 		Py_XDECREF(v);
 		PyErr_BadInternalCall();
 		return -1;
 	}
-	oldsize = Py_Size(v);
+	oldsize = Py_SIZE(v);
 	if (oldsize == newsize)
 		return 0;
 
@@ -740,19 +807,18 @@
 	return 0;
 }
 
-void
-PyTuple_Fini(void)
+int
+PyTuple_ClearFreeList(void)
 {
-#if MAXSAVESIZE > 0
+	int freelist_size = 0;
+#if PyTuple_MAXSAVESIZE > 0
 	int i;
-
-	Py_XDECREF(free_tuples[0]);
-	free_tuples[0] = NULL;
-
-	for (i = 1; i < MAXSAVESIZE; i++) {
+	for (i = 1; i < PyTuple_MAXSAVESIZE; i++) {
 		PyTupleObject *p, *q;
-		p = free_tuples[i];
-		free_tuples[i] = NULL;
+		p = free_list[i];
+		freelist_size += numfree[i];
+		free_list[i] = NULL;
+		numfree[i] = 0;
 		while (p) {
 			q = p;
 			p = (PyTupleObject *)(p->ob_item[0]);
@@ -760,6 +826,20 @@
 		}
 	}
 #endif
+	return freelist_size;
+}
+	
+void
+PyTuple_Fini(void)
+{
+#if PyTuple_MAXSAVESIZE > 0
+	/* empty tuples are used all over the place and applications may
+	 * rely on the fact that an empty tuple is a singleton. */
+	Py_XDECREF(free_list[0]);
+	free_list[0] = NULL;
+
+	(void)PyTuple_ClearFreeList();
+#endif
 }
 
 /*********************** Tuple Iterator **************************/
@@ -815,7 +895,7 @@
 	Py_ssize_t len = 0;
 	if (it->it_seq)
 		len = PyTuple_GET_SIZE(it->it_seq) - it->it_index;
-	return PyInt_FromSsize_t(len);
+	return PyLong_FromSsize_t(len);
 }
 
 PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
@@ -827,7 +907,7 @@
 
 PyTypeObject PyTupleIter_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"tupleiterator",			/* tp_name */
+	"tuple_iterator",			/* tp_name */
 	sizeof(tupleiterobject),		/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */

Modified: python/branches/py3k-importlib/Objects/typeobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/typeobject.c	(original)
+++ python/branches/py3k-importlib/Objects/typeobject.c	Thu Mar 27 00:48:05 2008
@@ -6,6 +6,189 @@
 
 #include <ctype.h>
 
+
+/* Support type attribute cache */
+
+/* The cache can keep references to the names alive for longer than
+   they normally would.  This is why the maximum size is limited to
+   MCACHE_MAX_ATTR_SIZE, since it might be a problem if very large
+   strings are used as attribute names. */
+#define MCACHE_MAX_ATTR_SIZE	100
+#define MCACHE_SIZE_EXP		10
+#define MCACHE_HASH(version, name_hash)					\
+		(((unsigned int)(version) * (unsigned int)(name_hash))	\
+		 >> (8*sizeof(unsigned int) - MCACHE_SIZE_EXP))
+#define MCACHE_HASH_METHOD(type, name)                                  \
+		MCACHE_HASH((type)->tp_version_tag,                     \
+		            ((PyStringObject *)(name))->ob_shash)
+#define MCACHE_CACHEABLE_NAME(name)                                     \
+		PyString_CheckExact(name) &&                            \
+		PyString_GET_SIZE(name) <= MCACHE_MAX_ATTR_SIZE
+
+struct method_cache_entry {
+	unsigned int version;
+	PyObject *name;		/* reference to exactly a str or None */
+	PyObject *value;	/* borrowed */
+};
+
+static struct method_cache_entry method_cache[1 << MCACHE_SIZE_EXP];
+static unsigned int next_version_tag = 0;
+static void type_modified(PyTypeObject *);
+
+unsigned int
+PyType_ClearCache(void)
+{
+	Py_ssize_t i;
+	unsigned int cur_version_tag = next_version_tag - 1;
+	
+	for (i = 0; i < (1 << MCACHE_SIZE_EXP); i++) {
+		method_cache[i].version = 0;
+		Py_CLEAR(method_cache[i].name);
+		method_cache[i].value = NULL;
+	}
+	next_version_tag = 0;
+	/* mark all version tags as invalid */
+	type_modified(&PyBaseObject_Type);
+	return cur_version_tag;
+}
+
+static void
+type_modified(PyTypeObject *type)
+{
+	/* Invalidate any cached data for the specified type and all
+	   subclasses.  This function is called after the base
+	   classes, mro, or attributes of the type are altered.
+
+	   Invariants:
+
+	   - Py_TPFLAGS_VALID_VERSION_TAG is never set if
+	     Py_TPFLAGS_HAVE_VERSION_TAG is not set (e.g. on type
+	     objects coming from non-recompiled extension modules)
+
+	   - before Py_TPFLAGS_VALID_VERSION_TAG can be set on a type,
+	     it must first be set on all super types.
+
+	   This function clears the Py_TPFLAGS_VALID_VERSION_TAG of a
+	   type (so it must first clear it on all subclasses).  The
+	   tp_version_tag value is meaningless unless this flag is set.
+	   We don't assign new version tags eagerly, but only as
+	   needed.
+	 */
+	PyObject *raw, *ref;
+	Py_ssize_t i, n;
+
+	if (!PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG))
+		return;
+
+	raw = type->tp_subclasses;
+	if (raw != NULL) {
+		n = PyList_GET_SIZE(raw);
+		for (i = 0; i < n; i++) {
+			ref = PyList_GET_ITEM(raw, i);
+			ref = PyWeakref_GET_OBJECT(ref);
+			if (ref != Py_None) {
+				type_modified((PyTypeObject *)ref);
+			}
+		}
+	}
+	type->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG;
+}
+
+static void
+type_mro_modified(PyTypeObject *type, PyObject *bases) {
+	/*
+	   Check that all base classes or elements of the mro of type are
+	   able to be cached.  This function is called after the base
+	   classes or mro of the type are altered.
+
+	   Unset HAVE_VERSION_TAG and VALID_VERSION_TAG if the type
+	   inherits from an old-style class, either directly or if it
+	   appears in the MRO of a new-style class.  No support either for
+	   custom MROs that include types that are not officially super
+	   types.
+
+	   Called from mro_internal, which will subsequently be called on
+	   each subclass when their mro is recursively updated.
+	 */
+	Py_ssize_t i, n;
+	int clear = 0;
+
+	if (!PyType_HasFeature(type, Py_TPFLAGS_HAVE_VERSION_TAG))
+		return;
+
+	n = PyTuple_GET_SIZE(bases);
+	for (i = 0; i < n; i++) {
+		PyObject *b = PyTuple_GET_ITEM(bases, i);
+		PyTypeObject *cls;
+
+		if (!PyType_Check(b) ) {
+			clear = 1;
+			break;
+		}
+
+		cls = (PyTypeObject *)b;
+
+		if (!PyType_HasFeature(cls, Py_TPFLAGS_HAVE_VERSION_TAG) ||
+		    !PyType_IsSubtype(type, cls)) {
+			clear = 1;
+			break;
+		}
+	}
+
+	if (clear)
+		type->tp_flags &= ~(Py_TPFLAGS_HAVE_VERSION_TAG|
+		                    Py_TPFLAGS_VALID_VERSION_TAG);
+}
+
+static int
+assign_version_tag(PyTypeObject *type)
+{
+	/* Ensure that the tp_version_tag is valid and set
+	   Py_TPFLAGS_VALID_VERSION_TAG.  To respect the invariant, this
+	   must first be done on all super classes.  Return 0 if this
+	   cannot be done, 1 if Py_TPFLAGS_VALID_VERSION_TAG.
+	*/
+	Py_ssize_t i, n;
+	PyObject *bases;
+
+	if (PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG))
+		return 1;
+	if (!PyType_HasFeature(type, Py_TPFLAGS_HAVE_VERSION_TAG))
+		return 0;
+	if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+		return 0;
+
+	type->tp_version_tag = next_version_tag++;
+	/* for stress-testing: next_version_tag &= 0xFF; */
+
+	if (type->tp_version_tag == 0) {
+		/* wrap-around or just starting Python - clear the whole
+		   cache by filling names with references to Py_None.
+		   Values are also set to NULL for added protection, as they
+		   are borrowed reference */
+		for (i = 0; i < (1 << MCACHE_SIZE_EXP); i++) {
+			method_cache[i].value = NULL;
+			Py_XDECREF(method_cache[i].name);
+			method_cache[i].name = Py_None;
+			Py_INCREF(Py_None);
+		}
+		/* mark all version tags as invalid */
+		type_modified(&PyBaseObject_Type);
+		return 1;
+	}
+	bases = type->tp_bases;
+	n = PyTuple_GET_SIZE(bases);
+	for (i = 0; i < n; i++) {
+		PyObject *b = PyTuple_GET_ITEM(bases, i);
+		assert(PyType_Check(b));
+		if (!assign_version_tag((PyTypeObject *)b))
+			return 0;
+	}
+	type->tp_flags |= Py_TPFLAGS_VALID_VERSION_TAG;
+	return 1;
+}
+
+
 static PyMemberDef type_members[] = {
 	{"__basicsize__", T_INT, offsetof(PyTypeObject,tp_basicsize),READONLY},
 	{"__itemsize__", T_INT, offsetof(PyTypeObject, tp_itemsize), READONLY},
@@ -45,6 +228,7 @@
 {
 	PyHeapTypeObject* et;
 	char *tp_name;
+        PyObject *tmp;
 
 	if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
 		PyErr_Format(PyExc_TypeError,
@@ -59,17 +243,25 @@
 	if (!PyUnicode_Check(value)) {
 		PyErr_Format(PyExc_TypeError,
 			     "can only assign string to %s.__name__, not '%s'",
-			     type->tp_name, Py_Type(value)->tp_name);
+			     type->tp_name, Py_TYPE(value)->tp_name);
 		return -1;
 	}
-	tp_name = PyUnicode_AsString(value);
-	if (tp_name == NULL)
+
+        /* Check absence of null characters */
+        tmp = PyUnicode_FromStringAndSize("\0", 1);
+        if (tmp == NULL)
 		return -1;
-	if (strlen(tp_name) != (size_t)PyUnicode_GET_SIZE(value)) {
+	if (PyUnicode_Contains(value, tmp) != 0) {
+		Py_DECREF(tmp);
 		PyErr_Format(PyExc_ValueError,
 			     "__name__ must not contain null bytes");
 		return -1;
 	}
+	Py_DECREF(tmp);
+
+	tp_name = PyUnicode_AsString(value);
+	if (tp_name == NULL)
+		return -1;
 
 	et = (PyHeapTypeObject*)type;
 
@@ -103,7 +295,7 @@
 		if (s != NULL)
 			return PyUnicode_FromStringAndSize(
 			    type->tp_name, (Py_ssize_t)(s - type->tp_name));
-		return PyUnicode_FromString("__builtin__");
+		return PyUnicode_FromString("builtins");
 	}
 }
 
@@ -121,10 +313,46 @@
 		return -1;
 	}
 
+	type_modified(type);
+
 	return PyDict_SetItemString(type->tp_dict, "__module__", value);
 }
 
 static PyObject *
+type_abstractmethods(PyTypeObject *type, void *context)
+{
+	PyObject *mod = PyDict_GetItemString(type->tp_dict,
+					     "__abstractmethods__");
+	if (!mod) {
+		PyErr_Format(PyExc_AttributeError, "__abstractmethods__");
+		return NULL;
+	}
+	Py_XINCREF(mod);
+	return mod;
+}
+
+static int
+type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context)
+{
+	/* __abstractmethods__ should only be set once on a type, in
+	   abc.ABCMeta.__new__, so this function doesn't do anything
+	   special to update subclasses.
+	*/
+	int res = PyDict_SetItemString(type->tp_dict,
+				       "__abstractmethods__", value);
+	if (res == 0) {
+		type_modified(type);
+		if (value && PyObject_IsTrue(value)) {
+			type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT;
+		}
+		else {
+			type->tp_flags &= ~Py_TPFLAGS_IS_ABSTRACT;
+		}
+	}
+	return res;
+}
+
+static PyObject *
 type_get_bases(PyTypeObject *type, void *context)
 {
 	Py_INCREF(type->tp_bases);
@@ -207,7 +435,7 @@
 	if (!PyTuple_Check(value)) {
 		PyErr_Format(PyExc_TypeError,
 		     "can only assign tuple to %s.__bases__, not %s",
-			     type->tp_name, Py_Type(value)->tp_name);
+			     type->tp_name, Py_TYPE(value)->tp_name);
 		return -1;
 	}
 	if (PyTuple_GET_SIZE(value) == 0) {
@@ -222,7 +450,7 @@
 			PyErr_Format(
 				PyExc_TypeError,
 	"%s.__bases__ must be tuple of old- or new-style classes, not '%s'",
-				type->tp_name, Py_Type(ob)->tp_name);
+				type->tp_name, Py_TYPE(ob)->tp_name);
 			return -1;
 		}
 		if (PyType_Check(ob)) {
@@ -347,8 +575,8 @@
 		result = Py_None;
 		Py_INCREF(result);
 	}
-	else if (Py_Type(result)->tp_descr_get) {
-		result = Py_Type(result)->tp_descr_get(result, NULL,
+	else if (Py_TYPE(result)->tp_descr_get) {
+		result = Py_TYPE(result)->tp_descr_get(result, NULL,
 						       (PyObject *)type);
 	}
 	else {
@@ -361,6 +589,8 @@
 	{"__name__", (getter)type_name, (setter)type_set_name, NULL},
 	{"__bases__", (getter)type_get_bases, (setter)type_set_bases, NULL},
 	{"__module__", (getter)type_module, (setter)type_set_module, NULL},
+	{"__abstractmethods__", (getter)type_abstractmethods,
+	 (setter)type_set_abstractmethods, NULL},
 	{"__dict__",  (getter)type_dict,  NULL, NULL},
 	{"__doc__", (getter)type_get_doc, NULL, NULL},
 	{0}
@@ -388,7 +618,7 @@
 	else
 		kind = "type";
 
-	if (mod != NULL && PyUnicode_CompareWithASCIIString(mod, "__builtin__"))
+	if (mod != NULL && PyUnicode_CompareWithASCIIString(mod, "builtins"))
 		rtn = PyUnicode_FromFormat("<%s '%U.%U'>", kind, mod, name);
 	else
 		rtn = PyUnicode_FromFormat("<%s '%s'>", kind, type->tp_name);
@@ -421,9 +651,9 @@
 			return obj;
 		/* If the returned object is not an instance of type,
 		   it won't be initialized. */
-		if (!PyType_IsSubtype(Py_Type(obj), type))
+		if (!PyType_IsSubtype(Py_TYPE(obj), type))
 			return obj;
-		type = Py_Type(obj);
+		type = Py_TYPE(obj);
 		if (type->tp_init != NULL &&
 		    type->tp_init(obj, args, kwds) < 0) {
 			Py_DECREF(obj);
@@ -477,7 +707,7 @@
 	Py_ssize_t i, n;
 	PyMemberDef *mp;
 
-	n = Py_Size(type);
+	n = Py_SIZE(type);
 	mp = PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
 	for (i = 0; i < n; i++, mp++) {
 		if (mp->type == T_OBJECT_EX) {
@@ -501,10 +731,10 @@
 
 	/* Find the nearest base with a different tp_traverse,
 	   and traverse slots while we're at it */
-	type = Py_Type(self);
+	type = Py_TYPE(self);
 	base = type;
 	while ((basetraverse = base->tp_traverse) == subtype_traverse) {
-		if (Py_Size(base)) {
+		if (Py_SIZE(base)) {
 			int err = traverse_slots(base, self, visit, arg);
 			if (err)
 				return err;
@@ -536,7 +766,7 @@
 	Py_ssize_t i, n;
 	PyMemberDef *mp;
 
-	n = Py_Size(type);
+	n = Py_SIZE(type);
 	mp = PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
 	for (i = 0; i < n; i++, mp++) {
 		if (mp->type == T_OBJECT_EX && !(mp->flags & READONLY)) {
@@ -558,10 +788,10 @@
 
 	/* Find the nearest base with a different tp_clear
 	   and clear slots while we're at it */
-	type = Py_Type(self);
+	type = Py_TYPE(self);
 	base = type;
 	while ((baseclear = base->tp_clear) == subtype_clear) {
-		if (Py_Size(base))
+		if (Py_SIZE(base))
 			clear_slots(base, self);
 		base = base->tp_base;
 		assert(base);
@@ -582,7 +812,7 @@
 	destructor basedealloc;
 
 	/* Extract the type; we expect it to be a heap type */
-	type = Py_Type(self);
+	type = Py_TYPE(self);
 	assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);
 
 	/* Test whether the type has GC exactly once */
@@ -604,7 +834,7 @@
 		/* Find the nearest base with a different tp_dealloc */
 		base = type;
 		while ((basedealloc = base->tp_dealloc) == subtype_dealloc) {
-			assert(Py_Size(base) == 0);
+			assert(Py_SIZE(base) == 0);
 			base = base->tp_base;
 			assert(base);
 		}
@@ -672,7 +902,7 @@
 	/*  Clear slots up to the nearest base with a different tp_dealloc */
 	base = type;
 	while ((basedealloc = base->tp_dealloc) == subtype_dealloc) {
-		if (Py_Size(base))
+		if (Py_SIZE(base))
 			clear_slots(base, self);
 		base = base->tp_base;
 		assert(base);
@@ -863,13 +1093,13 @@
 		if (*attrobj == NULL)
 			return NULL;
 	}
-	res = _PyType_Lookup(Py_Type(self), *attrobj);
+	res = _PyType_Lookup(Py_TYPE(self), *attrobj);
 	if (res != NULL) {
 		descrgetfunc f;
-		if ((f = Py_Type(res)->tp_descr_get) == NULL)
+		if ((f = Py_TYPE(res)->tp_descr_get) == NULL)
 			Py_INCREF(res);
 		else
-			res = f(res, self, (PyObject *)(Py_Type(self)));
+			res = f(res, self, (PyObject *)(Py_TYPE(self)));
 	}
 	return res;
 }
@@ -1006,7 +1236,7 @@
 	if (name == NULL) {
 		PyErr_Clear();
 		Py_XDECREF(name);
-		name = PyObject_ReprStr8(cls);
+		name = PyObject_Repr(cls);
 	}
 	if (name == NULL)
 		return NULL;
@@ -1166,8 +1396,8 @@
 	PyObject *bases, *result;
 	PyObject *to_merge, *bases_aslist;
 
-	if(type->tp_dict == NULL) {
-		if(PyType_Ready(type) < 0)
+	if (type->tp_dict == NULL) {
+		if (PyType_Ready(type) < 0)
 			return NULL;
 	}
 
@@ -1242,7 +1472,7 @@
 	PyObject *mro, *result, *tuple;
 	int checkit = 0;
 
-	if (Py_Type(type) == &PyType_Type) {
+	if (Py_TYPE(type) == &PyType_Type) {
 		result = mro_implementation(type);
 	}
 	else {
@@ -1275,7 +1505,7 @@
 			if (!PyType_Check(cls)) {
 				PyErr_Format(PyExc_TypeError,
 			     "mro() returned a non-class ('%.500s')",
-					     Py_Type(cls)->tp_name);
+					     Py_TYPE(cls)->tp_name);
 				Py_DECREF(tuple);
 				return -1;
 			}
@@ -1290,6 +1520,14 @@
 		}
 	}
 	type->tp_mro = tuple;
+
+	type_mro_modified(type, type->tp_mro);
+	/* corner case: the old-style super class might have been hidden
+	   from the custom MRO */
+	type_mro_modified(type, type->tp_bases);
+
+	type_modified(type);
+
 	return 0;
 }
 
@@ -1431,7 +1669,7 @@
 {
 	PyErr_Format(PyExc_TypeError,
 		     "this __dict__ descriptor does not support "
-		     "'%.200s' objects", Py_Type(obj)->tp_name);
+		     "'%.200s' objects", Py_TYPE(obj)->tp_name);
 }
 
 static PyObject *
@@ -1441,7 +1679,7 @@
 	PyObject *dict;
 	PyTypeObject *base;
 
-	base = get_builtin_base_with_dict(Py_Type(obj));
+	base = get_builtin_base_with_dict(Py_TYPE(obj));
 	if (base != NULL) {
 		descrgetfunc func;
 		PyObject *descr = get_dict_descriptor(base);
@@ -1449,12 +1687,12 @@
 			raise_dict_descr_error(obj);
 			return NULL;
 		}
-		func = Py_Type(descr)->tp_descr_get;
+		func = Py_TYPE(descr)->tp_descr_get;
 		if (func == NULL) {
 			raise_dict_descr_error(obj);
 			return NULL;
 		}
-		return func(descr, obj, (PyObject *)(Py_Type(obj)));
+		return func(descr, obj, (PyObject *)(Py_TYPE(obj)));
 	}
 
 	dictptr = _PyObject_GetDictPtr(obj);
@@ -1477,7 +1715,7 @@
 	PyObject *dict;
 	PyTypeObject *base;
 
-	base = get_builtin_base_with_dict(Py_Type(obj));
+	base = get_builtin_base_with_dict(Py_TYPE(obj));
 	if (base != NULL) {
 		descrsetfunc func;
 		PyObject *descr = get_dict_descriptor(base);
@@ -1485,7 +1723,7 @@
 			raise_dict_descr_error(obj);
 			return -1;
 		}
-		func = Py_Type(descr)->tp_descr_set;
+		func = Py_TYPE(descr)->tp_descr_set;
 		if (func == NULL) {
 			raise_dict_descr_error(obj);
 			return -1;
@@ -1502,7 +1740,7 @@
 	if (value != NULL && !PyDict_Check(value)) {
 		PyErr_Format(PyExc_TypeError,
 			     "__dict__ must be set to a dictionary, "
-			     "not a '%.200s'", Py_Type(value)->tp_name);
+			     "not a '%.200s'", Py_TYPE(value)->tp_name);
 		return -1;
 	}
 	dict = *dictptr;
@@ -1518,16 +1756,16 @@
 	PyObject **weaklistptr;
 	PyObject *result;
 
-	if (Py_Type(obj)->tp_weaklistoffset == 0) {
+	if (Py_TYPE(obj)->tp_weaklistoffset == 0) {
 		PyErr_SetString(PyExc_AttributeError,
 				"This object has no __weakref__");
 		return NULL;
 	}
-	assert(Py_Type(obj)->tp_weaklistoffset > 0);
-	assert(Py_Type(obj)->tp_weaklistoffset + sizeof(PyObject *) <=
-	       (size_t)(Py_Type(obj)->tp_basicsize));
+	assert(Py_TYPE(obj)->tp_weaklistoffset > 0);
+	assert(Py_TYPE(obj)->tp_weaklistoffset + sizeof(PyObject *) <=
+	       (size_t)(Py_TYPE(obj)->tp_basicsize));
 	weaklistptr = (PyObject **)
-		((char *)obj + Py_Type(obj)->tp_weaklistoffset);
+		((char *)obj + Py_TYPE(obj)->tp_weaklistoffset);
 	if (*weaklistptr == NULL)
 		result = Py_None;
 	else
@@ -1564,7 +1802,7 @@
 	if (!PyUnicode_Check(s)) {
 		PyErr_Format(PyExc_TypeError,
 			     "__slots__ items must be strings, not '%.200s'",
-			     Py_Type(s)->tp_name);
+			     Py_TYPE(s)->tp_name);
 		return 0;
 	}
 	if (!PyUnicode_IsIdentifier(s)) {
@@ -1630,8 +1868,8 @@
 
 		if (PyType_CheckExact(metatype) && nargs == 1 && nkwds == 0) {
 			PyObject *x = PyTuple_GET_ITEM(args, 0);
-			Py_INCREF(Py_Type(x));
-			return (PyObject *) Py_Type(x);
+			Py_INCREF(Py_TYPE(x));
+			return (PyObject *) Py_TYPE(x);
 		}
 
 		/* SF bug 475327 -- if that didn't trigger, we need 3
@@ -1645,7 +1883,7 @@
 	}
 
 	/* Check arguments: (name, bases, dict) */
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, "SO!O!:type", kwlist,
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "UO!O!:type", kwlist,
 					 &name,
 					 &PyTuple_Type, &bases,
 					 &PyDict_Type, &dict))
@@ -1659,7 +1897,7 @@
 	winner = metatype;
 	for (i = 0; i < nbases; i++) {
 		tmp = PyTuple_GET_ITEM(bases, i);
-		tmptype = Py_Type(tmp);
+		tmptype = Py_TYPE(tmp);
 		if (PyType_IsSubtype(winner, tmptype))
 			continue;
 		if (PyType_IsSubtype(tmptype, winner)) {
@@ -2017,6 +2255,16 @@
 {
 	Py_ssize_t i, n;
 	PyObject *mro, *res, *base, *dict;
+	unsigned int h;
+
+	if (MCACHE_CACHEABLE_NAME(name) &&
+	    PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) {
+		/* fast path */
+		h = MCACHE_HASH_METHOD(type, name);
+		if (method_cache[h].version == type->tp_version_tag &&
+		    method_cache[h].name == name)
+		    return method_cache[h].value;
+	}
 
 	/* Look in tp_dict of types in MRO */
 	mro = type->tp_mro;
@@ -2027,6 +2275,7 @@
 	if (mro == NULL)
 		return NULL;
 
+	res = NULL;
 	assert(PyTuple_Check(mro));
 	n = PyTuple_GET_SIZE(mro);
 	for (i = 0; i < n; i++) {
@@ -2036,9 +2285,18 @@
 		assert(dict && PyDict_Check(dict));
 		res = PyDict_GetItem(dict, name);
 		if (res != NULL)
-			return res;
+			break;
 	}
-	return NULL;
+
+	if (MCACHE_CACHEABLE_NAME(name) && assign_version_tag(type)) {
+		h = MCACHE_HASH_METHOD(type, name);
+		method_cache[h].version = type->tp_version_tag;
+		method_cache[h].value = res;  /* borrowed */
+		Py_INCREF(name);
+		Py_DECREF(method_cache[h].name);
+		method_cache[h].name = name;
+	}
+	return res;
 }
 
 /* This is similar to PyObject_GenericGetAttr(),
@@ -2046,7 +2304,7 @@
 static PyObject *
 type_getattro(PyTypeObject *type, PyObject *name)
 {
-	PyTypeObject *metatype = Py_Type(type);
+	PyTypeObject *metatype = Py_TYPE(type);
 	PyObject *meta_attribute, *attribute;
 	descrgetfunc meta_get;
 
@@ -2063,7 +2321,7 @@
 	meta_attribute = _PyType_Lookup(metatype, name);
 
 	if (meta_attribute != NULL) {
-		meta_get = Py_Type(meta_attribute)->tp_descr_get;
+		meta_get = Py_TYPE(meta_attribute)->tp_descr_get;
 
 		if (meta_get != NULL && PyDescr_IsData(meta_attribute)) {
 			/* Data descriptors implement tp_descr_set to intercept
@@ -2081,7 +2339,7 @@
 	attribute = _PyType_Lookup(type, name);
 	if (attribute != NULL) {
 		/* Implement descriptor functionality, if any */
-		descrgetfunc local_get = Py_Type(attribute)->tp_descr_get;
+		descrgetfunc local_get = Py_TYPE(attribute)->tp_descr_get;
 
 		Py_XDECREF(meta_attribute);
 
@@ -2128,10 +2386,6 @@
 			type->tp_name);
 		return -1;
 	}
-	/* XXX Example of how I expect this to be used...
-	if (update_subclasses(type, name, invalidate_cache, NULL) < 0)
-		return -1;
-	*/
 	if (PyObject_GenericSetAttr((PyObject *)type, name, value) < 0)
 		return -1;
 	return update_slot(type, name);
@@ -2159,7 +2413,7 @@
 	PyObject_Free((char *)type->tp_doc);
 	Py_XDECREF(et->ht_name);
 	Py_XDECREF(et->ht_slots);
-	Py_Type(type)->tp_free((PyObject *)type);
+	Py_TYPE(type)->tp_free((PyObject *)type);
 }
 
 static PyObject *
@@ -2379,7 +2633,7 @@
 {
 	int err = 0;
 	if (excess_args(args, kwds)) {
-		PyTypeObject *type = Py_Type(self);
+		PyTypeObject *type = Py_TYPE(self);
 		if (type->tp_init != object_init &&
 		    type->tp_new != object_new)
 		{
@@ -2420,13 +2674,59 @@
 	}
 	if (err < 0)
 		return NULL;
+
+	if (type->tp_flags & Py_TPFLAGS_IS_ABSTRACT) {
+		static PyObject *comma = NULL;
+		PyObject *abstract_methods = NULL;
+		PyObject *builtins;
+		PyObject *sorted;
+		PyObject *sorted_methods = NULL;
+		PyObject *joined = NULL;
+
+		/* Compute ", ".join(sorted(type.__abstractmethods__))
+		   into joined. */
+		abstract_methods = type_abstractmethods(type, NULL);
+		if (abstract_methods == NULL)
+			goto error;
+		builtins = PyEval_GetBuiltins();
+		if (builtins == NULL)
+			goto error;
+		sorted = PyDict_GetItemString(builtins, "sorted");
+		if (sorted == NULL)
+			goto error;
+		sorted_methods = PyObject_CallFunctionObjArgs(sorted,
+							      abstract_methods,
+							      NULL);
+		if (sorted_methods == NULL)
+			goto error;
+		if (comma == NULL) {
+			comma = PyUnicode_InternFromString(", ");
+			if (comma == NULL)
+				goto error;
+		}
+		joined = PyObject_CallMethod(comma, "join",
+					     "O",  sorted_methods);
+		if (joined == NULL)
+			goto error;
+
+		PyErr_Format(PyExc_TypeError,
+			     "Can't instantiate abstract class %s "
+			     "with abstract methods %U",
+			     type->tp_name,
+			     joined);
+	error:
+		Py_XDECREF(joined);
+		Py_XDECREF(sorted_methods);
+		Py_XDECREF(abstract_methods);
+		return NULL;
+	}
 	return type->tp_alloc(type, 0);
 }
 
 static void
 object_dealloc(PyObject *self)
 {
-	Py_Type(self)->tp_free(self);
+	Py_TYPE(self)->tp_free(self);
 }
 
 static PyObject *
@@ -2435,7 +2735,7 @@
 	PyTypeObject *type;
 	PyObject *mod, *name, *rtn;
 
-	type = Py_Type(self);
+	type = Py_TYPE(self);
 	mod = type_module(type, NULL);
 	if (mod == NULL)
 		PyErr_Clear();
@@ -2446,7 +2746,7 @@
 	name = type_name(type, NULL);
 	if (name == NULL)
 		return NULL;
-	if (mod != NULL && PyUnicode_CompareWithASCIIString(mod, "__builtin__"))
+	if (mod != NULL && PyUnicode_CompareWithASCIIString(mod, "builtins"))
 		rtn = PyUnicode_FromFormat("<%U.%U object at %p>", mod, name, self);
 	else
 		rtn = PyUnicode_FromFormat("<%s object at %p>",
@@ -2461,7 +2761,7 @@
 {
 	unaryfunc f;
 
-	f = Py_Type(self)->tp_repr;
+	f = Py_TYPE(self)->tp_repr;
 	if (f == NULL)
 		f = object_repr;
 	return f(self);
@@ -2475,7 +2775,10 @@
 	switch (op) {
 
 	case Py_EQ:
-		res = (self == other) ? Py_True : Py_False;
+		/* Return NotImplemented instead of False, so if two
+		   objects are compared, both get a chance at the
+		   comparison.  See issue #1393. */
+		res = (self == other) ? Py_True : Py_NotImplemented;
 		Py_INCREF(res);
 		break;
 
@@ -2510,8 +2813,8 @@
 static PyObject *
 object_get_class(PyObject *self, void *closure)
 {
-	Py_INCREF(Py_Type(self));
-	return (PyObject *)(Py_Type(self));
+	Py_INCREF(Py_TYPE(self));
+	return (PyObject *)(Py_TYPE(self));
 }
 
 static int
@@ -2596,7 +2899,7 @@
 static int
 object_set_class(PyObject *self, PyObject *value, void *closure)
 {
-	PyTypeObject *oldto = Py_Type(self);
+	PyTypeObject *oldto = Py_TYPE(self);
 	PyTypeObject *newto;
 
 	if (value == NULL) {
@@ -2607,7 +2910,7 @@
 	if (!PyType_Check(value)) {
 		PyErr_Format(PyExc_TypeError,
 		  "__class__ must be set to new-style class, not '%s' object",
-		  Py_Type(value)->tp_name);
+		  Py_TYPE(value)->tp_name);
 		return -1;
 	}
 	newto = (PyTypeObject *)value;
@@ -2620,7 +2923,7 @@
 	}
 	if (compatible_for_assignment(newto, oldto, "__class__")) {
 		Py_INCREF(newto);
-		Py_Type(self) = newto;
+		Py_TYPE(self) = newto;
 		Py_DECREF(oldto);
 		return 0;
 	}
@@ -2716,7 +3019,7 @@
 		if (args != NULL && !PyTuple_Check(args)) {
 			PyErr_Format(PyExc_TypeError,
 				"__getnewargs__ should return a tuple, "
-				"not '%.200s'", Py_Type(args)->tp_name);
+				"not '%.200s'", Py_TYPE(args)->tp_name);
 			goto end;
 		}
 	}
@@ -2922,6 +3225,20 @@
 	return _common_reduce(self, proto);
 }
 
+static PyObject *
+object_subclasshook(PyObject *cls, PyObject *args)
+{
+	Py_INCREF(Py_NotImplemented);
+	return Py_NotImplemented;
+}
+
+PyDoc_STRVAR(object_subclasshook_doc,
+"Abstract classes can override this to customize issubclass().\n"
+"\n"
+"This is invoked early on by abc.ABCMeta.__subclasscheck__().\n"
+"It should return True, False or NotImplemented.  If it returns\n"
+"NotImplemented, the normal algorithm is used.  Otherwise, it\n"
+"overrides the normal algorithm (and the outcome is cached).\n");
 
 /*
    from PEP 3101, this code implements:
@@ -2938,14 +3255,10 @@
         PyObject *result = NULL;
         PyObject *format_meth = NULL;
 
-        if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
-                return NULL;
-        if (!PyUnicode_Check(format_spec)) {
-                PyErr_SetString(PyExc_TypeError, "Unicode object required");
+        if (!PyArg_ParseTuple(args, "U:__format__", &format_spec))
                 return NULL;
-        }
 
-        self_as_str = PyObject_Unicode(self);
+        self_as_str = PyObject_Str(self);
         if (self_as_str != NULL) {
                 /* find the format function */
                 format_meth = PyObject_GetAttrString(self_as_str, "__format__");
@@ -2966,6 +3279,8 @@
 	 PyDoc_STR("helper for pickle")},
 	{"__reduce__", object_reduce, METH_VARARGS,
 	 PyDoc_STR("helper for pickle")},
+	{"__subclasshook__", object_subclasshook, METH_CLASS | METH_VARARGS,
+	 object_subclasshook_doc},
         {"__format__", object_format, METH_VARARGS,
          PyDoc_STR("default object formatter")},
 	{0}
@@ -3158,28 +3473,22 @@
 		type->tp_flags |= Py_TPFLAGS_DICT_SUBCLASS;
 }
 
-/* Map rich comparison operators to their __xx__ namesakes */
-static char *name_op[] = {
-	"__lt__",
-	"__le__",
+static char *hash_name_op[] = {
 	"__eq__",
-	"__ne__",
-	"__gt__",
-	"__ge__",
-	/* These are only for overrides_cmp_or_hash(): */ 
 	"__cmp__",
 	"__hash__",
+	NULL
 };
 
 static int
-overrides_cmp_or_hash(PyTypeObject *type)
+overrides_hash(PyTypeObject *type)
 {
-	int i;
+	char **p;
 	PyObject *dict = type->tp_dict;
 
 	assert(dict != NULL);
-	for (i = 0; i < 8; i++) {
-		if (PyDict_GetItemString(dict, name_op[i]) != NULL)
+	for (p = hash_name_op; *p; p++) {
+		if (PyDict_GetItemString(dict, *p) != NULL)
 			return 1;
 	}
 	return 0;
@@ -3305,7 +3614,7 @@
 		if (type->tp_compare == NULL &&
 		    type->tp_richcompare == NULL &&
 		    type->tp_hash == NULL &&
-		    !overrides_cmp_or_hash(type))
+		    !overrides_hash(type))
 		{
 			type->tp_compare = base->tp_compare;
 			type->tp_richcompare = base->tp_richcompare;
@@ -3394,8 +3703,8 @@
 	   NULL when type is &PyBaseObject_Type, and we know its ob_type is
 	   not NULL (it's initialized to &PyType_Type).	 But coverity doesn't
 	   know that. */
-	if (Py_Type(type) == NULL && base != NULL)
-		Py_Type(type) = Py_Type(base);
+	if (Py_TYPE(type) == NULL && base != NULL)
+		Py_TYPE(type) = Py_TYPE(base);
 
 	/* Initialize tp_bases */
 	bases = type->tp_bases;
@@ -3614,7 +3923,7 @@
 	res = (*func)(self);
 	if (res == -1 && PyErr_Occurred())
 		return NULL;
-	return PyInt_FromLong((long)res);
+	return PyLong_FromLong((long)res);
 }
 
 static PyObject *
@@ -3664,7 +3973,7 @@
 	if (!check_num_args(args, 1))
 		return NULL;
 	other = PyTuple_GET_ITEM(args, 0);
-	if (!PyType_IsSubtype(Py_Type(other), Py_Type(self))) {
+	if (!PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) {
 		Py_INCREF(Py_NotImplemented);
 		return Py_NotImplemented;
 	}
@@ -3733,7 +4042,7 @@
 	if (i == -1 && PyErr_Occurred())
 		return -1;
 	if (i < 0) {
-		PySequenceMethods *sq = Py_Type(self)->tp_as_sequence;
+		PySequenceMethods *sq = Py_TYPE(self)->tp_as_sequence;
 		if (sq && sq->sq_length) {
 			Py_ssize_t n = (*sq->sq_length)(self);
 			if (n < 0)
@@ -3865,20 +4174,20 @@
 	if (!check_num_args(args, 1))
 		return NULL;
 	other = PyTuple_GET_ITEM(args, 0);
-	if (Py_Type(other)->tp_compare != func &&
-	    !PyType_IsSubtype(Py_Type(other), Py_Type(self))) {
+	if (Py_TYPE(other)->tp_compare != func &&
+	    !PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) {
 		PyErr_Format(
 			PyExc_TypeError,
 			"%s.__cmp__(x,y) requires y to be a '%s', not a '%s'",
-			Py_Type(self)->tp_name,
-			Py_Type(self)->tp_name,
-			Py_Type(other)->tp_name);
+			Py_TYPE(self)->tp_name,
+			Py_TYPE(self)->tp_name,
+			Py_TYPE(other)->tp_name);
 		return NULL;
 	}
 	res = (*func)(self, other);
 	if (PyErr_Occurred())
 		return NULL;
-	return PyInt_FromLong((long)res);
+	return PyLong_FromLong((long)res);
 }
 
 /* Helper to check for object.__setattr__ or __delattr__ applied to a type.
@@ -3886,7 +4195,7 @@
 static int
 hackcheck(PyObject *self, setattrofunc func, char *what)
 {
-	PyTypeObject *type = Py_Type(self);
+	PyTypeObject *type = Py_TYPE(self);
 	while (type && type->tp_flags & Py_TPFLAGS_HEAPTYPE)
 		type = type->tp_base;
 	/* If type is NULL now, this is a really weird type.
@@ -3949,7 +4258,7 @@
 	res = (*func)(self);
 	if (res == -1 && PyErr_Occurred())
 		return NULL;
-	return PyInt_FromLong(res);
+	return PyLong_FromLong(res);
 }
 
 static PyObject *
@@ -4086,7 +4395,7 @@
 		PyErr_Format(PyExc_TypeError,
 			     "%s.__new__(X): X is not a type object (%s)",
 			     type->tp_name,
-			     Py_Type(arg0)->tp_name);
+			     Py_TYPE(arg0)->tp_name);
 		return NULL;
 	}
 	subtype = (PyTypeObject *)arg0;
@@ -4177,14 +4486,14 @@
 	PyObject *a, *b;
 	int ok;
 
-	b = PyObject_GetAttrString((PyObject *)(Py_Type(right)), name);
+	b = PyObject_GetAttrString((PyObject *)(Py_TYPE(right)), name);
 	if (b == NULL) {
 		PyErr_Clear();
 		/* If right doesn't have it, it's not overloaded */
 		return 0;
 	}
 
-	a = PyObject_GetAttrString((PyObject *)(Py_Type(left)), name);
+	a = PyObject_GetAttrString((PyObject *)(Py_TYPE(left)), name);
 	if (a == NULL) {
 		PyErr_Clear();
 		Py_DECREF(b);
@@ -4209,14 +4518,14 @@
 FUNCNAME(PyObject *self, PyObject *other) \
 { \
 	static PyObject *cache_str, *rcache_str; \
-	int do_other = Py_Type(self) != Py_Type(other) && \
-	    Py_Type(other)->tp_as_number != NULL && \
-	    Py_Type(other)->tp_as_number->SLOTNAME == TESTFUNC; \
-	if (Py_Type(self)->tp_as_number != NULL && \
-	    Py_Type(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
+	int do_other = Py_TYPE(self) != Py_TYPE(other) && \
+	    Py_TYPE(other)->tp_as_number != NULL && \
+	    Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
+	if (Py_TYPE(self)->tp_as_number != NULL && \
+	    Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
 		PyObject *r; \
 		if (do_other && \
-		    PyType_IsSubtype(Py_Type(other), Py_Type(self)) && \
+		    PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self)) && \
 		    method_is_overloaded(self, other, ROPSTR)) { \
 			r = call_maybe( \
 				other, ROPSTR, &rcache_str, "(O)", self); \
@@ -4228,7 +4537,7 @@
 		r = call_maybe( \
 			self, OPSTR, &cache_str, "(O)", other); \
 		if (r != Py_NotImplemented || \
-		    Py_Type(other) == Py_Type(self)) \
+		    Py_TYPE(other) == Py_TYPE(self)) \
 			return r; \
 		Py_DECREF(r); \
 	} \
@@ -4261,7 +4570,7 @@
 
 	if (res == NULL)
 		return -1;
-	len = PyInt_AsSsize_t(res);
+	len = PyLong_AsSsize_t(res);
 	Py_DECREF(res);
 	if (len < 0) {
 		if (!PyErr_Occurred())
@@ -4286,17 +4595,17 @@
 		if (getitem_str == NULL)
 			return NULL;
 	}
-	func = _PyType_Lookup(Py_Type(self), getitem_str);
+	func = _PyType_Lookup(Py_TYPE(self), getitem_str);
 	if (func != NULL) {
-		if ((f = Py_Type(func)->tp_descr_get) == NULL)
+		if ((f = Py_TYPE(func)->tp_descr_get) == NULL)
 			Py_INCREF(func);
 		else {
-			func = f(func, self, (PyObject *)(Py_Type(self)));
+			func = f(func, self, (PyObject *)(Py_TYPE(self)));
 			if (func == NULL) {
 				return NULL;
 			}
 		}
-		ival = PyInt_FromSsize_t(i);
+		ival = PyLong_FromSsize_t(i);
 		if (ival != NULL) {
 			args = PyTuple_New(1);
 			if (args != NULL) {
@@ -4409,8 +4718,8 @@
 	/* Three-arg power doesn't use __rpow__.  But ternary_op
 	   can call this when the second argument's type uses
 	   slot_nb_power, so check before calling self.__pow__. */
-	if (Py_Type(self)->tp_as_number != NULL &&
-	    Py_Type(self)->tp_as_number->nb_power == slot_nb_power) {
+	if (Py_TYPE(self)->tp_as_number != NULL &&
+	    Py_TYPE(self)->tp_as_number->nb_power == slot_nb_power) {
 		return call_method(self, "__pow__", &pow_str,
 				   "(OO)", other, modulus);
 	}
@@ -4455,7 +4764,7 @@
 				PyErr_Format(PyExc_TypeError,
 					 "__bool__ should return "
 					 "bool, returned %s",
-					 Py_Type(temp)->tp_name);
+					 Py_TYPE(temp)->tp_name);
 				result = -1;
 			}
 			Py_DECREF(temp);
@@ -4529,7 +4838,7 @@
 		if (res != Py_NotImplemented) {
 			if (res == NULL)
 				return -2;
-			c = PyInt_AsLong(res);
+			c = PyLong_AsLong(res);
 			Py_DECREF(res);
 			if (c == -1 && PyErr_Occurred())
 				return -2;
@@ -4546,12 +4855,12 @@
 {
 	int c;
 
-	if (Py_Type(self)->tp_compare == _PyObject_SlotCompare) {
+	if (Py_TYPE(self)->tp_compare == _PyObject_SlotCompare) {
 		c = half_compare(self, other);
 		if (c <= 1)
 			return c;
 	}
-	if (Py_Type(other)->tp_compare == _PyObject_SlotCompare) {
+	if (Py_TYPE(other)->tp_compare == _PyObject_SlotCompare) {
 		c = half_compare(other, self);
 		if (c < -1)
 			return -2;
@@ -4576,7 +4885,7 @@
 	}
 	PyErr_Clear();
 	return PyUnicode_FromFormat("<%s object at %p>",
-				   Py_Type(self)->tp_name, self);
+				   Py_TYPE(self)->tp_name, self);
 }
 
 static PyObject *
@@ -4619,7 +4928,7 @@
 
 	if (func == NULL) {
 		PyErr_Format(PyExc_TypeError, "unhashable type: '%.200s'",
-			     Py_Type(self)->tp_name);
+			     Py_TYPE(self)->tp_name);
 		return -1;
         }
 
@@ -4630,7 +4939,7 @@
 	if (PyLong_Check(res))
 		h = PyLong_Type.tp_hash(res);
 	else
-		h = PyInt_AsLong(res);
+		h = PyLong_AsLong(res);
 	Py_DECREF(res);
                if (h == -1 && !PyErr_Occurred())
                    h = -2;
@@ -4675,7 +4984,7 @@
 static PyObject *
 slot_tp_getattr_hook(PyObject *self, PyObject *name)
 {
-	PyTypeObject *tp = Py_Type(self);
+	PyTypeObject *tp = Py_TYPE(self);
 	PyObject *getattr, *getattribute, *res;
 	static PyObject *getattribute_str = NULL;
 	static PyObject *getattr_str = NULL;
@@ -4699,7 +5008,7 @@
 	}
 	getattribute = _PyType_Lookup(tp, getattribute_str);
 	if (getattribute == NULL ||
-	    (Py_Type(getattribute) == &PyWrapperDescr_Type &&
+	    (Py_TYPE(getattribute) == &PyWrapperDescr_Type &&
 	     ((PyWrapperDescrObject *)getattribute)->d_wrapped ==
 	     (void *)PyObject_GenericGetAttr))
 		res = PyObject_GenericGetAttr(self, name);
@@ -4730,6 +5039,15 @@
 	return 0;
 }
 
+static char *name_op[] = {
+    "__lt__",
+    "__le__",
+    "__eq__",
+    "__ne__",
+    "__gt__",
+    "__ge__",
+};
+
 static PyObject *
 half_richcompare(PyObject *self, PyObject *other, int op)
 {
@@ -4758,13 +5076,13 @@
 {
 	PyObject *res;
 
-	if (Py_Type(self)->tp_richcompare == slot_tp_richcompare) {
+	if (Py_TYPE(self)->tp_richcompare == slot_tp_richcompare) {
 		res = half_richcompare(self, other, op);
 		if (res != Py_NotImplemented)
 			return res;
 		Py_DECREF(res);
 	}
-	if (Py_Type(other)->tp_richcompare == slot_tp_richcompare) {
+	if (Py_TYPE(other)->tp_richcompare == slot_tp_richcompare) {
 		res = half_richcompare(other, self, _Py_SwappedOp[op]);
 		if (res != Py_NotImplemented) {
 			return res;
@@ -4797,7 +5115,7 @@
 	if (func == NULL) {
 		PyErr_Format(PyExc_TypeError,
 			     "'%.200s' object is not iterable",
-			     Py_Type(self)->tp_name);
+			     Py_TYPE(self)->tp_name);
 		return NULL;
 	}
 	Py_DECREF(func);
@@ -4814,7 +5132,7 @@
 static PyObject *
 slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type)
 {
-	PyTypeObject *tp = Py_Type(self);
+	PyTypeObject *tp = Py_TYPE(self);
 	PyObject *get;
 	static PyObject *get_str = NULL;
 
@@ -4872,7 +5190,7 @@
 	if (res != Py_None) {
 		PyErr_Format(PyExc_TypeError,
 			     "__init__() should return None, not '%.200s'",
-			     Py_Type(res)->tp_name);
+			     Py_TYPE(res)->tp_name);
 		Py_DECREF(res);
 		return -1;
 	}
@@ -4957,7 +5275,7 @@
 		_Py_NewReference(self);
 		self->ob_refcnt = refcnt;
 	}
-	assert(!PyType_IS_GC(Py_Type(self)) ||
+	assert(!PyType_IS_GC(Py_TYPE(self)) ||
 	       _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
 	/* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
 	 * we need to undo that. */
@@ -4969,8 +5287,8 @@
 	 * undone.
 	 */
 #ifdef COUNT_ALLOCS
-	--Py_Type(self)->tp_frees;
-	--Py_Type(self)->tp_allocs;
+	--Py_TYPE(self)->tp_frees;
+	--Py_TYPE(self)->tp_allocs;
 #endif
 }
 
@@ -5305,7 +5623,7 @@
 		descr = _PyType_Lookup(type, p->name_strobj);
 		if (descr == NULL)
 			continue;
-		if (Py_Type(descr) == &PyWrapperDescr_Type) {
+		if (Py_TYPE(descr) == &PyWrapperDescr_Type) {
 			void **tptr = resolve_slotdups(type, p->name_strobj);
 			if (tptr == NULL || tptr == ptr)
 				generic = p->function;
@@ -5320,7 +5638,7 @@
 					use_generic = 1;
 			}
 		}
-		else if (Py_Type(descr) == &PyCFunction_Type &&
+		else if (Py_TYPE(descr) == &PyCFunction_Type &&
 			 PyCFunction_GET_FUNCTION(descr) ==
 			 (PyCFunction)tp_new_wrapper &&
 			 strcmp(p->name, "__new__") == 0)
@@ -5410,6 +5728,13 @@
 	slotdef **pp;
 	int offset;
 
+	/* Clear the VALID_VERSION flag of 'type' and all its
+	   subclasses.  This could possibly be unified with the
+	   update_subclasses() recursion below, but carefully:
+	   they each have their own conditions on which to stop
+	   recursing into subclasses. */
+	type_modified(type);
+
 	init_slotdefs();
 	pp = ptrs;
 	for (p = slotdefs; p->name; p++) {
@@ -5591,7 +5916,7 @@
 	Py_XDECREF(su->obj);
 	Py_XDECREF(su->type);
 	Py_XDECREF(su->obj_type);
-	Py_Type(self)->tp_free(self);
+	Py_TYPE(self)->tp_free(self);
 }
 
 static PyObject *
@@ -5654,7 +5979,7 @@
 			res = PyDict_GetItem(dict, name);
 			if (res != NULL) {
 				Py_INCREF(res);
-				f = Py_Type(res)->tp_descr_get;
+				f = Py_TYPE(res)->tp_descr_get;
 				if (f != NULL) {
 					tmp = f(res,
 						/* Only pass 'obj' param if
@@ -5690,7 +6015,7 @@
 	     the normal case; the return value is obj.__class__.
 
 	   But... when obj is an instance, we want to allow for the case where
-	   Py_Type(obj) is not a subclass of type, but obj.__class__ is!
+	   Py_TYPE(obj) is not a subclass of type, but obj.__class__ is!
 	   This will allow using super() with a proxy for obj.
 	*/
 
@@ -5701,9 +6026,9 @@
 	}
 
 	/* Normal case */
-	if (PyType_IsSubtype(Py_Type(obj), type)) {
-		Py_INCREF(Py_Type(obj));
-		return Py_Type(obj);
+	if (PyType_IsSubtype(Py_TYPE(obj), type)) {
+		Py_INCREF(Py_TYPE(obj));
+		return Py_TYPE(obj);
 	}
 	else {
 		/* Try the slow way */
@@ -5720,7 +6045,7 @@
 
 		if (class_attr != NULL &&
 		    PyType_Check(class_attr) &&
-		    (PyTypeObject *)class_attr != Py_Type(obj))
+		    (PyTypeObject *)class_attr != Py_TYPE(obj))
 		{
 			int ok = PyType_IsSubtype(
 				(PyTypeObject *)class_attr, type);
@@ -5751,10 +6076,10 @@
 		Py_INCREF(self);
 		return self;
 	}
-	if (Py_Type(su) != &PySuper_Type)
+	if (Py_TYPE(su) != &PySuper_Type)
 		/* If su is an instance of a (strict) subclass of super,
 		   call its type */
-		return PyObject_CallFunctionObjArgs((PyObject *)Py_Type(su),
+		return PyObject_CallFunctionObjArgs((PyObject *)Py_TYPE(su),
 						    su->type, obj, NULL);
 	else {
 		/* Inline the common case */
@@ -5836,7 +6161,7 @@
 				if (!PyType_Check(type)) {
 				    PyErr_Format(PyExc_SystemError,
 				      "super(): __class__ is not a type (%s)",
-				      Py_Type(type)->tp_name);
+				      Py_TYPE(type)->tp_name);
 				    return -1;
 				}
 				break;

Modified: python/branches/py3k-importlib/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/unicodeobject.c	(original)
+++ python/branches/py3k-importlib/Objects/unicodeobject.c	Thu Mar 27 00:48:05 2008
@@ -41,6 +41,7 @@
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
+#include "bytes_methods.h"
 
 #include "unicodeobject.h"
 #include "ucnhash.h"
@@ -53,7 +54,7 @@
 
 /* Limit for the Unicode object free list */
 
-#define MAX_UNICODE_FREELIST_SIZE       1024
+#define PyUnicode_MAXFREELIST       1024
 
 /* Limit for the Unicode object free list stay alive optimization.
 
@@ -61,7 +62,7 @@
    all objects on the free list having a size less than this
    limit. This reduces malloc() overhead for small Unicode objects.
 
-   At worst this will result in MAX_UNICODE_FREELIST_SIZE *
+   At worst this will result in PyUnicode_MAXFREELIST *
    (sizeof(PyUnicodeObject) + KEEPALIVE_SIZE_LIMIT +
    malloc()-overhead) bytes of unused garbage.
 
@@ -100,13 +101,13 @@
    function will delete the reference from this dictionary.
 
    Another way to look at this is that to say that the actual reference
-   count of a string is:  s->ob_refcnt + (s->ob_sstate?2:0)
+   count of a string is:  s->ob_refcnt + (s->state ? 2 : 0)
 */
 static PyObject *interned;
 
 /* Free list for Unicode objects */
-static PyUnicodeObject *unicode_freelist;
-static int unicode_freelist_size;
+static PyUnicodeObject *free_list;
+static int numfree;
 
 /* The empty Unicode object is shared to improve performance. */
 static PyUnicodeObject *unicode_empty;
@@ -119,11 +120,69 @@
    parameter; it is fixed to "utf-8".  Always use the
    PyUnicode_GetDefaultEncoding() API to access this global.
 
-   Don't forget to alter Py_FileSystemDefaultEncoding() if you change the
+   Don't forget to alter Py_FileSystemDefaultEncoding if you change the
    hard coded default!
 */
 static const char unicode_default_encoding[] = "utf-8";
 
+/* Fast detection of the most frequent whitespace characters */
+const unsigned char _Py_ascii_whitespace[] = {
+	0, 0, 0, 0, 0, 0, 0, 0,
+//     case 0x0009: /* HORIZONTAL TABULATION */
+//     case 0x000A: /* LINE FEED */
+//     case 0x000B: /* VERTICAL TABULATION */
+//     case 0x000C: /* FORM FEED */
+//     case 0x000D: /* CARRIAGE RETURN */
+	0, 1, 1, 1, 1, 1, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+//     case 0x001C: /* FILE SEPARATOR */
+//     case 0x001D: /* GROUP SEPARATOR */
+//     case 0x001E: /* RECORD SEPARATOR */
+//     case 0x001F: /* UNIT SEPARATOR */
+	0, 0, 0, 0, 1, 1, 1, 1,
+//     case 0x0020: /* SPACE */
+	1, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/* Same for linebreaks */
+static unsigned char ascii_linebreak[] = {
+	0, 0, 0, 0, 0, 0, 0, 0,
+//         0x000A, /* LINE FEED */
+//         0x000D, /* CARRIAGE RETURN */
+	0, 0, 1, 0, 0, 1, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+//         0x001C, /* FILE SEPARATOR */
+//         0x001D, /* GROUP SEPARATOR */
+//         0x001E, /* RECORD SEPARATOR */
+	0, 0, 0, 0, 1, 1, 1, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
 Py_UNICODE
 PyUnicode_GetMax(void)
 {
@@ -150,8 +209,9 @@
 
 #define BLOOM(mask, ch) ((mask & (1 << ((ch) & 0x1F))))
 
-#define BLOOM_LINEBREAK(ch)\
-    (BLOOM(bloom_linebreak, (ch)) && Py_UNICODE_ISLINEBREAK((ch)))
+#define BLOOM_LINEBREAK(ch) \
+    ((ch) < 128U ? ascii_linebreak[(ch)] : \
+    (BLOOM(bloom_linebreak, (ch)) && Py_UNICODE_ISLINEBREAK(ch)))
 
 Py_LOCAL_INLINE(BLOOM_MASK) make_bloom_mask(Py_UNICODE* ptr, Py_ssize_t len)
 {
@@ -212,7 +272,8 @@
        it contains). */
 
     oldstr = unicode->str;
-    PyMem_RESIZE(unicode->str, Py_UNICODE, length + 1);
+    unicode->str = PyObject_REALLOC(unicode->str,
+				    sizeof(Py_UNICODE) * (length + 1));
     if (!unicode->str) {
 	unicode->str = (Py_UNICODE *)oldstr;
         PyErr_NoMemory();
@@ -253,29 +314,32 @@
     }
 
     /* Unicode freelist & memory allocation */
-    if (unicode_freelist) {
-        unicode = unicode_freelist;
-        unicode_freelist = *(PyUnicodeObject **)unicode;
-        unicode_freelist_size--;
+    if (free_list) {
+        unicode = free_list;
+        free_list = *(PyUnicodeObject **)unicode;
+        numfree--;
 	if (unicode->str) {
 	    /* Keep-Alive optimization: we only upsize the buffer,
 	       never downsize it. */
 	    if ((unicode->length < length) &&
                 unicode_resize(unicode, length) < 0) {
-		PyMem_DEL(unicode->str);
+		PyObject_DEL(unicode->str);
 		goto onError;
 	    }
 	}
         else {
-	    unicode->str = PyMem_NEW(Py_UNICODE, length + 1);
+	    size_t new_size = sizeof(Py_UNICODE) * ((size_t)length + 1);
+	    unicode->str = (Py_UNICODE*) PyObject_MALLOC(new_size);
         }
         PyObject_INIT(unicode, &PyUnicode_Type);
     }
     else {
+	size_t new_size;
         unicode = PyObject_New(PyUnicodeObject, &PyUnicode_Type);
         if (unicode == NULL)
             return NULL;
-	unicode->str = PyMem_NEW(Py_UNICODE, length + 1);
+	new_size = sizeof(Py_UNICODE) * ((size_t)length + 1);
+	unicode->str = (Py_UNICODE*) PyObject_MALLOC(new_size);
     }
 
     if (!unicode->str) {
@@ -312,7 +376,7 @@
 
         case SSTATE_INTERNED_MORTAL:
             /* revive dead object temporarily for DelItem */
-            Py_Refcnt(unicode) = 3;
+            Py_REFCNT(unicode) = 3;
             if (PyDict_DelItem(interned, (PyObject *)unicode) != 0)
                 Py_FatalError(
                     "deletion of interned unicode string failed");
@@ -326,10 +390,10 @@
     }
 
     if (PyUnicode_CheckExact(unicode) &&
-	unicode_freelist_size < MAX_UNICODE_FREELIST_SIZE) {
+	numfree < PyUnicode_MAXFREELIST) {
         /* Keep-Alive optimization */
 	if (unicode->length >= KEEPALIVE_SIZE_LIMIT) {
-	    PyMem_DEL(unicode->str);
+	    PyObject_DEL(unicode->str);
 	    unicode->str = NULL;
 	    unicode->length = 0;
 	}
@@ -338,14 +402,14 @@
 	    unicode->defenc = NULL;
 	}
 	/* Add to free list */
-        *(PyUnicodeObject **)unicode = unicode_freelist;
-        unicode_freelist = unicode;
-        unicode_freelist_size++;
+        *(PyUnicodeObject **)unicode = free_list;
+        free_list = unicode;
+        numfree++;
     }
     else {
-	PyMem_DEL(unicode->str);
+	PyObject_DEL(unicode->str);
 	Py_XDECREF(unicode->defenc);
-	Py_Type(unicode)->tp_free((PyObject *)unicode);
+	Py_TYPE(unicode)->tp_free((PyObject *)unicode);
     }
 }
 
@@ -359,7 +423,7 @@
 	return -1;
     }
     v = (PyUnicodeObject *)*unicode;
-    if (v == NULL || !PyUnicode_Check(v) || Py_Refcnt(v) != 1 || length < 0) {
+    if (v == NULL || !PyUnicode_Check(v) || Py_REFCNT(v) != 1 || length < 0) {
 	PyErr_BadInternalCall();
 	return -1;
     }
@@ -571,16 +635,16 @@
 #endif
 #endif
 	/* step 1: count the number of %S/%R format specifications
-	 * (we call PyObject_Unicode()/PyObject_Repr() for these objects
+	 * (we call PyObject_Str()/PyObject_Repr() for these objects
 	 * once during step 3 and put the result in an array) */
 	for (f = format; *f; f++) {
 		if (*f == '%' && (*(f+1)=='S' || *(f+1)=='R'))
 			++callcount;
 	}
 	/* step 2: allocate memory for the results of
-	 * PyObject_Unicode()/PyObject_Repr() calls */
+	 * PyObject_Str()/PyObject_Repr() calls */
 	if (callcount) {
-		callresults = PyMem_Malloc(sizeof(PyObject *)*callcount);
+		callresults = PyObject_Malloc(sizeof(PyObject *)*callcount);
 		if (!callresults) {
 			PyErr_NoMemory();
 			return NULL;
@@ -592,9 +656,9 @@
 		if (*f == '%') {
 			const char* p = f;
 			width = 0;
-			while (isdigit(Py_CHARMASK(*f)))
+			while (ISDIGIT((unsigned)*f))
 				width = (width*10) + *f++ - '0';
-			while (*++f && *f != '%' && !isalpha(Py_CHARMASK(*f)))
+			while (*++f && *f != '%' && !ISALPHA((unsigned)*f))
 				;
 
 			/* skip the 'l' or 'z' in {%ld, %zd, %lu, %zu} since
@@ -682,7 +746,7 @@
 				PyObject *obj = va_arg(count, PyObject *);
 				PyObject *str;
 				assert(obj);
-				str = PyObject_Unicode(obj);
+				str = PyObject_Str(obj);
 				if (!str)
 					goto fail;
 				n += PyUnicode_GET_SIZE(str);
@@ -727,7 +791,7 @@
 	}
  expand:
 	if (abuffersize > 20) {
-		abuffer = PyMem_Malloc(abuffersize);
+		abuffer = PyObject_Malloc(abuffersize);
 		if (!abuffer) {
 			PyErr_NoMemory();
 			goto fail;
@@ -755,12 +819,12 @@
 			zeropad = (*f == '0');
 			/* parse the width.precision part */
 			width = 0;
-			while (isdigit(Py_CHARMASK(*f)))
+			while (ISDIGIT((unsigned)*f))
 				width = (width*10) + *f++ - '0';
 			precision = 0;
 			if (*f == '.') {
 				f++;
-				while (isdigit(Py_CHARMASK(*f)))
+				while (ISDIGIT((unsigned)*f))
 					precision = (precision*10) + *f++ - '0';
 			}
 			/* handle the long flag, but only for %ld and %lu.
@@ -890,9 +954,9 @@
 
  end:
 	if (callresults)
-		PyMem_Free(callresults);
+		PyObject_Free(callresults);
 	if (abuffer)
-		PyMem_Free(abuffer);
+		PyObject_Free(abuffer);
 	_PyUnicode_Resize(&string, s - PyUnicode_AS_UNICODE(string));
 	return string;
  fail:
@@ -902,10 +966,10 @@
 			Py_DECREF(*callresult2);
 			++callresult2;
 		}
-		PyMem_Free(callresults);
+		PyObject_Free(callresults);
 	}
 	if (abuffer)
-		PyMem_Free(abuffer);
+		PyObject_Free(abuffer);
 	return NULL;
 }
 
@@ -986,7 +1050,7 @@
 PyObject *PyUnicode_FromObject(register PyObject *obj)
 {
     /* XXX Perhaps we should make this API an alias of
-           PyObject_Unicode() instead ?! */
+           PyObject_Str() instead ?! */
     if (PyUnicode_CheckExact(obj)) {
 	Py_INCREF(obj);
 	return obj;
@@ -997,7 +1061,10 @@
 	return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(obj),
 				     PyUnicode_GET_SIZE(obj));
     }
-    return PyUnicode_FromEncodedObject(obj, NULL, "strict");
+    PyErr_Format(PyExc_TypeError,
+                 "Can't convert '%.100s' object to str implicitly",
+                 Py_TYPE(obj)->tp_name);
+    return NULL;
 }
 
 PyObject *PyUnicode_FromEncodedObject(register PyObject *obj,
@@ -1031,7 +1098,7 @@
 	PyErr_Format(PyExc_TypeError,
 			 "coercing to Unicode: need string or buffer, "
 			 "%.80s found",
-		     Py_Type(obj)->tp_name);
+		     Py_TYPE(obj)->tp_name);
 	goto onError;
     }
 
@@ -1056,21 +1123,47 @@
 {
     PyObject *buffer = NULL, *unicode;
     Py_buffer info;
+    char lower[20];  /* Enough for any encoding name we recognize */
+    char *l;
+    const char *e;
 
     if (encoding == NULL)
-	encoding = PyUnicode_GetDefaultEncoding();
+        encoding = PyUnicode_GetDefaultEncoding();
+
+    /* Convert encoding to lower case and replace '_' with '-' in order to
+       catch e.g. UTF_8 */
+    e = encoding;
+    l = lower;
+    while (*e && l < &lower[(sizeof lower) - 2]) {
+        if (ISUPPER(*e)) {
+            *l++ = TOLOWER(*e++);
+        }
+        else if (*e == '_') {
+            *l++ = '-';
+            e++;
+        }
+        else {
+            *l++ = *e++;
+        }
+    }
+    *l = '\0';
 
     /* Shortcuts for common default encodings */
-    if (strcmp(encoding, "utf-8") == 0)
+    if (strcmp(lower, "utf-8") == 0)
         return PyUnicode_DecodeUTF8(s, size, errors);
-    else if (strcmp(encoding, "latin-1") == 0)
+    else if ((strcmp(lower, "latin-1") == 0) ||
+             (strcmp(lower, "iso-8859-1") == 0))
         return PyUnicode_DecodeLatin1(s, size, errors);
 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
-    else if (strcmp(encoding, "mbcs") == 0)
+    else if (strcmp(lower, "mbcs") == 0)
         return PyUnicode_DecodeMBCS(s, size, errors);
 #endif
-    else if (strcmp(encoding, "ascii") == 0)
+    else if (strcmp(lower, "ascii") == 0)
         return PyUnicode_DecodeASCII(s, size, errors);
+    else if (strcmp(lower, "utf-16") == 0)
+        return PyUnicode_DecodeUTF16(s, size, errors, 0);
+    else if (strcmp(lower, "utf-32") == 0)
+        return PyUnicode_DecodeUTF32(s, size, errors, 0);
 
     /* Decode via the codec registry */
     buffer = NULL;
@@ -1085,7 +1178,7 @@
     if (!PyUnicode_Check(unicode)) {
         PyErr_Format(PyExc_TypeError,
                      "decoder did not return an unicode object (type=%.400s)",
-                     Py_Type(unicode)->tp_name);
+                     Py_TYPE(unicode)->tp_name);
         Py_DECREF(unicode);
         goto onError;
     }
@@ -1192,22 +1285,7 @@
     v = PyCodec_Encode(unicode, encoding, errors);
     if (v == NULL)
         goto onError;
-    if (!PyBytes_Check(v)) {
-        if (PyString_Check(v)) {
-            /* Old codec, turn it into bytes */
-            PyObject *b = PyBytes_FromObject(v);
-            Py_DECREF(v);
-            return b;
-        }
-        PyErr_Format(PyExc_TypeError,
-                     "encoder did not return a bytes object "
-                     "(type=%.400s, encoding=%.20s, errors=%.20s)",
-                     v->ob_type->tp_name,
-                     encoding ? encoding : "NULL",
-                     errors ? errors : "NULL");
-        Py_DECREF(v);
-        goto onError;
-    }
+    assert(PyString_Check(v));
     return v;
 
  onError:
@@ -1218,28 +1296,28 @@
 					    const char *errors)
 {
     PyObject *v = ((PyUnicodeObject *)unicode)->defenc;
-    PyObject *b;
     if (v)
         return v;
     if (errors != NULL)
         Py_FatalError("non-NULL encoding in _PyUnicode_AsDefaultEncodedString");
-    b = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode),
+    v = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode),
                              PyUnicode_GET_SIZE(unicode),
                              NULL);
-    if (!b)
+    if (!v)
         return NULL;
-    v = PyString_FromStringAndSize(PyBytes_AsString(b),
-                                   PyBytes_Size(b));
-    Py_DECREF(b);
     ((PyUnicodeObject *)unicode)->defenc = v;
     return v;
 }
 
 PyObject*
-PyUnicode_DecodeFSDefault(const char *s)
-{
+PyUnicode_DecodeFSDefault(const char *s) {
     Py_ssize_t size = (Py_ssize_t)strlen(s);
+    return PyUnicode_DecodeFSDefaultAndSize(s, size);
+}
 
+PyObject*
+PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
+{
     /* During the early bootstrapping process, Py_FileSystemDefaultEncoding
        can be undefined. If it is case, decode using UTF-8. The following assumes
        that Py_FileSystemDefaultEncoding is set to a built-in encoding during the
@@ -1247,11 +1325,11 @@
     */
     if (Py_FileSystemDefaultEncoding) {
 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
-        if (strcmp(Py_FileSystemDefaultEncoding, "mbcs")) {
+        if (strcmp(Py_FileSystemDefaultEncoding, "mbcs") == 0) {
             return PyUnicode_DecodeMBCS(s, size, "replace");
         }
 #elif defined(__APPLE__)
-        if (strcmp(Py_FileSystemDefaultEncoding, "utf-8")) {
+        if (strcmp(Py_FileSystemDefaultEncoding, "utf-8") == 0) {
             return PyUnicode_DecodeUTF8(s, size, "replace");
         }
 #endif
@@ -1267,17 +1345,17 @@
 char*
 PyUnicode_AsStringAndSize(PyObject *unicode, Py_ssize_t *psize)
 {
-    PyObject *str8;
+    PyObject *bytes;
     if (!PyUnicode_Check(unicode)) {
         PyErr_BadArgument();
         return NULL;
     }
-    str8 = _PyUnicode_AsDefaultEncodedString(unicode, NULL);
-    if (str8 == NULL)
+    bytes = _PyUnicode_AsDefaultEncodedString(unicode, NULL);
+    if (bytes == NULL)
         return NULL;
     if (psize != NULL)
-        *psize = PyString_GET_SIZE(str8);
-    return PyString_AS_STRING(str8);
+        *psize = PyString_GET_SIZE(bytes);
+    return PyString_AS_STRING(bytes);
 }
 
 char*
@@ -1389,11 +1467,11 @@
     inputobj = PyUnicodeDecodeError_GetObject(*exceptionObject);
     if (!inputobj)
         goto onError;
-    if (!PyBytes_Check(inputobj)) {
+    if (!PyString_Check(inputobj)) {
 	PyErr_Format(PyExc_TypeError, "exception attribute object must be bytes");
     }
-    *input = PyBytes_AS_STRING(inputobj);
-    insize = PyBytes_GET_SIZE(inputobj);
+    *input = PyString_AS_STRING(inputobj);
+    insize = PyString_GET_SIZE(inputobj);
     *inend = *input + insize;
     /* we can DECREF safely, as the exception has another reference,
        so the object won't go away. */
@@ -1470,7 +1548,7 @@
 #define B64(n)  \
     ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(n) & 0x3f])
 #define B64CHAR(c) \
-    (isalnum(c) || (c) == '+' || (c) == '/')
+    (ISALNUM(c) || (c) == '+' || (c) == '/')
 #define UB64(c) \
     ((c) == '+' ? 62 : (c) == '/' ? 63 : (c) >= 'a' ?                   \
      (c) - 71 : (c) >= 'A' ? (c) - 65 : (c) + 4 )
@@ -1504,6 +1582,14 @@
 			       Py_ssize_t size,
 			       const char *errors)
 {
+    return PyUnicode_DecodeUTF7Stateful(s, size, errors, NULL);
+}
+
+PyObject *PyUnicode_DecodeUTF7Stateful(const char *s,
+			       Py_ssize_t size,
+			       const char *errors,
+			       Py_ssize_t *consumed)
+{
     const char *starts = s;
     Py_ssize_t startinpos;
     Py_ssize_t endinpos;
@@ -1522,8 +1608,11 @@
     unicode = _PyUnicode_New(size);
     if (!unicode)
         return NULL;
-    if (size == 0)
+    if (size == 0) {
+        if (consumed)
+            *consumed = 0;
         return (PyObject *)unicode;
+    }
 
     p = unicode->str;
     e = s + size;
@@ -1609,7 +1698,7 @@
         goto onError;
     }
 
-    if (inShift) {
+    if (inShift && !consumed) {
         outpos = p-PyUnicode_AS_UNICODE(unicode);
         endinpos = size;
         if (unicode_decode_call_errorhandler(
@@ -1621,6 +1710,12 @@
         if (s < e)
            goto restart;
     }
+    if (consumed) {
+        if(inShift)
+            *consumed = startinpos;
+        else
+            *consumed = s-starts;
+    }
 
     if (_PyUnicode_Resize(&unicode, p - PyUnicode_AS_UNICODE(unicode)) < 0)
         goto onError;
@@ -1643,7 +1738,7 @@
                    int encodeWhiteSpace,
                    const char *errors)
 {
-    PyObject *v;
+    PyObject *v, *result;
     /* It might be possible to tighten this worst case */
     Py_ssize_t cbAllocated = 5 * size;
     int inShift = 0;
@@ -1654,7 +1749,7 @@
     char * start;
 
     if (size == 0)
-	return PyBytes_FromStringAndSize(NULL, 0);
+       return PyString_FromStringAndSize(NULL, 0);
 
     v = PyBytes_FromStringAndSize(NULL, cbAllocated);
     if (v == NULL)
@@ -1726,11 +1821,9 @@
         *out++ = '-';
     }
 
-    if (PyBytes_Resize(v, out - start)) {
-        Py_DECREF(v);
-        return NULL;
-    }
-    return v;
+    result = PyString_FromStringAndSize(PyBytes_AS_STRING(v), out - start);
+    Py_DECREF(v);
+    return result;
 }
 
 #undef SPECIAL
@@ -1970,11 +2063,11 @@
 {
 #define MAX_SHORT_UNICHARS 300  /* largest size we'll do on the stack */
 
-    Py_ssize_t i;           /* index into s of next input byte */
-    PyObject *v;        /* result string object */
-    char *p;            /* next free byte in output buffer */
-    Py_ssize_t nallocated;  /* number of result bytes allocated */
-    Py_ssize_t nneeded;        /* number of result bytes needed */
+    Py_ssize_t i;                /* index into s of next input byte */
+    PyObject *result;            /* result string object */
+    char *p;                     /* next free byte in output buffer */
+    Py_ssize_t nallocated;      /* number of result bytes allocated */
+    Py_ssize_t nneeded;            /* number of result bytes needed */
     char stackbuf[MAX_SHORT_UNICHARS * 4];
 
     assert(s != NULL);
@@ -1986,7 +2079,7 @@
          * turns out we need.
          */
         nallocated = Py_SAFE_DOWNCAST(sizeof(stackbuf), size_t, int);
-        v = NULL;   /* will allocate after we're done */
+        result = NULL;   /* will allocate after we're done */
         p = stackbuf;
     }
     else {
@@ -1994,10 +2087,10 @@
         nallocated = size * 4;
         if (nallocated / 4 != size)  /* overflow! */
             return PyErr_NoMemory();
-        v = PyBytes_FromStringAndSize(NULL, nallocated);
-        if (v == NULL)
+        result = PyString_FromStringAndSize(NULL, nallocated);
+        if (result == NULL)
             return NULL;
-        p = PyBytes_AS_STRING(v);
+        p = PyString_AS_STRING(result);
     }
 
     for (i = 0; i < size;) {
@@ -2041,19 +2134,19 @@
         }
     }
 
-    if (v == NULL) {
+    if (result == NULL) {
         /* This was stack allocated. */
         nneeded = p - stackbuf;
         assert(nneeded <= nallocated);
-        v = PyBytes_FromStringAndSize(stackbuf, nneeded);
+        result = PyString_FromStringAndSize(stackbuf, nneeded);
     }
     else {
-    	/* Cut back to size actually needed. */
-        nneeded = p - PyBytes_AS_STRING(v);
+        /* Cut back to size actually needed. */
+        nneeded = p - PyString_AS_STRING(result);
         assert(nneeded <= nallocated);
-        PyBytes_Resize(v, nneeded);
+        _PyString_Resize(&result, nneeded);
     }
-    return v;
+    return result;
 
 #undef MAX_SHORT_UNICHARS
 }
@@ -2248,7 +2341,7 @@
 		      const char *errors,
 		      int byteorder)
 {
-    PyObject *v;
+    PyObject *v, *result;
     unsigned char *p;
 #ifndef Py_UNICODE_WIDE
     int i, pairs;
@@ -2288,7 +2381,7 @@
     if (byteorder == 0)
 	STORECHAR(0xFEFF);
     if (size == 0)
-        return v;
+        goto done;
 
     if (byteorder == -1) {
         /* force LE */
@@ -2319,7 +2412,11 @@
 #endif
         STORECHAR(ch);
     }
-    return v;
+
+  done:
+    result = PyString_FromStringAndSize(PyBytes_AS_STRING(v), Py_SIZE(v));
+    Py_DECREF(v);
+    return result;
 #undef STORECHAR
 }
 
@@ -2518,7 +2615,7 @@
 		      const char *errors,
 		      int byteorder)
 {
-    PyObject *v;
+    PyObject *v, *result;
     unsigned char *p;
 #ifdef Py_UNICODE_WIDE
     int i, pairs;
@@ -2553,7 +2650,7 @@
     if (byteorder == 0)
 	STORECHAR(0xFEFF);
     if (size == 0)
-        return v;
+        goto done;
 
     if (byteorder == -1) {
         /* force LE */
@@ -2579,7 +2676,11 @@
         if (ch2)
             STORECHAR(ch2);
     }
-    return v;
+
+  done:
+    result = PyString_FromStringAndSize(PyBytes_AS_STRING(v), Py_SIZE(v));
+    Py_DECREF(v);
+    return result;
 #undef STORECHAR
 }
 
@@ -2644,7 +2745,10 @@
         startinpos = s-starts;
         /* \ - Escapes */
         s++;
-        switch (*s++) {
+        c = *s++;
+        if (s > end)
+            c = '\0'; /* Invalid after \ */
+        switch (c) {
 
         /* \x escapes */
         case '\n': break;
@@ -2663,9 +2767,9 @@
         case '0': case '1': case '2': case '3':
         case '4': case '5': case '6': case '7':
             x = s[-1] - '0';
-            if ('0' <= *s && *s <= '7') {
+            if (s < end && '0' <= *s && *s <= '7') {
                 x = (x<<3) + *s++ - '0';
-                if ('0' <= *s && *s <= '7')
+                if (s < end && '0' <= *s && *s <= '7')
                     x = (x<<3) + *s++ - '0';
             }
             *p++ = x;
@@ -2703,7 +2807,7 @@
             }
             for (i = 0; i < digits; ++i) {
                 c = (unsigned char) s[i];
-                if (!isxdigit(c)) {
+                if (!ISXDIGIT(c)) {
                     endinpos = (s+i+1)-starts;
                     if (unicode_decode_call_errorhandler(
                         errors, &errorHandler,
@@ -2759,7 +2863,7 @@
             if (ucnhash_CAPI == NULL) {
                 /* load the unicode data module */
                 PyObject *m, *api;
-                m = PyImport_ImportModule("unicodedata");
+                m = PyImport_ImportModuleNoBlock("unicodedata");
                 if (m == NULL)
                     goto ucnhashError;
                 api = PyObject_GetAttrString(m, "ucnhash_CAPI");
@@ -2866,7 +2970,7 @@
 PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
 					Py_ssize_t size)
 {
-    PyObject *repr;
+    PyObject *repr, *result;
     char *p;
 
     /* XXX(nnorwitz): rather than over-allocating, it would be
@@ -2989,12 +3093,10 @@
             *p++ = (char) ch;
     }
 
-    *p = '\0';
-    if (PyBytes_Resize(repr, p - PyBytes_AS_STRING(repr))) {
-        Py_DECREF(repr);
-        return NULL;
-    }
-    return repr;
+    result = PyString_FromStringAndSize(PyBytes_AS_STRING(repr),
+                                        p - PyBytes_AS_STRING(repr));
+    Py_DECREF(repr);
+    return result;
 }
 
 PyObject *PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
@@ -3077,7 +3179,7 @@
 	outpos = p-PyUnicode_AS_UNICODE(v);
 	for (x = 0, i = 0; i < count; ++i, ++s) {
 	    c = (unsigned char)*s;
-	    if (!isxdigit(c)) {
+	    if (!ISXDIGIT(c)) {
 		endinpos = s-starts;
 		if (unicode_decode_call_errorhandler(
 		    errors, &errorHandler,
@@ -3095,8 +3197,22 @@
 	    else
 		x += 10 + c - 'A';
 	}
-#ifndef Py_UNICODE_WIDE
-        if (x > 0x10000) {
+        if (x <= 0xffff)
+                /* UCS-2 character */
+                *p++ = (Py_UNICODE) x;
+        else if (x <= 0x10ffff) {
+                /* UCS-4 character. Either store directly, or as
+                   surrogate pair. */
+#ifdef Py_UNICODE_WIDE
+                *p++ = (Py_UNIC0DE) x;
+#else
+                x -= 0x10000L;
+                *p++ = 0xD800 + (Py_UNICODE) (x >> 10);
+                *p++ = 0xDC00 + (Py_UNICODE) (x & 0x03FF);
+#endif
+        } else {
+            endinpos = s-starts;
+            outpos = p-PyUnicode_AS_UNICODE(v);
             if (unicode_decode_call_errorhandler(
                     errors, &errorHandler,
                     "rawunicodeescape", "\\Uxxxxxxxx out of range",
@@ -3104,8 +3220,6 @@
 		    (PyObject **)&v, &outpos, &p))
 		    goto onError;
         }
-#endif
-	*p++ = x;
 	nextByte:
 	;
     }
@@ -3125,7 +3239,7 @@
 PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
 					   Py_ssize_t size)
 {
-    PyObject *repr;
+    PyObject *repr, *result;
     char *p;
     char *q;
 
@@ -3137,7 +3251,7 @@
     if (repr == NULL)
         return NULL;
     if (size == 0)
-	return repr;
+        goto done;
 
     p = q = PyBytes_AS_STRING(repr);
     while (size-- > 0) {
@@ -3157,6 +3271,32 @@
             *p++ = hexdigits[ch & 15];
         }
         else
+#else
+	/* Map UTF-16 surrogate pairs to '\U00xxxxxx' */
+	if (ch >= 0xD800 && ch < 0xDC00) {
+	    Py_UNICODE ch2;
+	    Py_UCS4 ucs;
+
+	    ch2 = *s++;
+	    size--;
+	    if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) {
+		ucs = (((ch & 0x03FF) << 10) | (ch2 & 0x03FF)) + 0x00010000;
+		*p++ = '\\';
+		*p++ = 'U';
+		*p++ = hexdigits[(ucs >> 28) & 0xf];
+		*p++ = hexdigits[(ucs >> 24) & 0xf];
+		*p++ = hexdigits[(ucs >> 20) & 0xf];
+		*p++ = hexdigits[(ucs >> 16) & 0xf];
+		*p++ = hexdigits[(ucs >> 12) & 0xf];
+		*p++ = hexdigits[(ucs >> 8) & 0xf];
+		*p++ = hexdigits[(ucs >> 4) & 0xf];
+		*p++ = hexdigits[ucs & 0xf];
+		continue;
+	    }
+	    /* Fall through: isolated surrogates are copied as-is */
+	    s--;
+	    size++;
+	}
 #endif
 	/* Map 16-bit characters to '\uxxxx' */
 	if (ch >= 256) {
@@ -3171,12 +3311,12 @@
 	else
             *p++ = (char) ch;
     }
-    *p = '\0';
-    if (PyBytes_Resize(repr, p - q)) {
-        Py_DECREF(repr);
-        return NULL;
-    }
-    return repr;
+    size = p - q;
+
+  done:
+    result = PyString_FromStringAndSize(PyBytes_AS_STRING(repr), size);
+    Py_DECREF(repr);
+    return result;
 }
 
 PyObject *PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
@@ -3411,23 +3551,23 @@
     /* pointer into the output */
     char *str;
     /* current output position */
-    Py_ssize_t respos = 0;
     Py_ssize_t ressize;
     const char *encoding = (limit == 256) ? "latin-1" : "ascii";
     const char *reason = (limit == 256) ? "ordinal not in range(256)" : "ordinal not in range(128)";
     PyObject *errorHandler = NULL;
     PyObject *exc = NULL;
+    PyObject *result = NULL;
     /* the following variable is used for caching string comparisons
      * -1=not initialized, 0=unknown, 1=strict, 2=replace, 3=ignore, 4=xmlcharrefreplace */
     int known_errorHandler = -1;
 
     /* allocate enough for a simple encoding without
        replacements, if we need more, we'll resize */
+    if (size == 0)
+        return PyString_FromStringAndSize(NULL, 0);
     res = PyBytes_FromStringAndSize(NULL, size);
     if (res == NULL)
-        goto onError;
-    if (size == 0)
-	return res;
+        return NULL;
     str = PyBytes_AS_STRING(res);
     ressize = size;
 
@@ -3555,20 +3695,13 @@
 	    }
 	}
     }
-    /* Resize if we allocated to much */
-    respos = str - PyBytes_AS_STRING(res);
-    if (respos<ressize)
-       /* If this falls res will be NULL */
-	PyBytes_Resize(res, respos);
-    Py_XDECREF(errorHandler);
-    Py_XDECREF(exc);
-    return res;
-
-    onError:
-    Py_XDECREF(res);
+    result = PyString_FromStringAndSize(PyBytes_AS_STRING(res),
+                                        str - PyBytes_AS_STRING(res));
+  onError:
+    Py_DECREF(res);
     Py_XDECREF(errorHandler);
     Py_XDECREF(exc);
-    return NULL;
+    return result;
 }
 
 PyObject *PyUnicode_EncodeLatin1(const Py_UNICODE *p,
@@ -3814,20 +3947,20 @@
 
     if (*repr == NULL) {
 	/* Create string object */
-	*repr = PyBytes_FromStringAndSize(NULL, mbcssize);
+	*repr = PyString_FromStringAndSize(NULL, mbcssize);
 	if (*repr == NULL)
 	    return -1;
     }
     else {
 	/* Extend string object */
-	n = PyBytes_Size(*repr);
-	if (PyBytes_Resize(*repr, n + mbcssize) < 0)
+	n = PyString_Size(*repr);
+	if (_PyString_Resize(repr, n + mbcssize) < 0)
 	    return -1;
     }
 
     /* Do the conversion */
     if (size > 0) {
-	char *s = PyBytes_AS_STRING(*repr) + n;
+	char *s = PyString_AS_STRING(*repr) + n;
 	if (0 == WideCharToMultiByte(CP_ACP, 0, p, size, s, mbcssize, NULL, NULL)) {
 	    PyErr_SetFromWindowsErrWithFilename(0, NULL);
 	    return -1;
@@ -3948,7 +4081,7 @@
 	    PyObject *w, *x;
 
 	    /* Get mapping (char ordinal -> integer, Unicode char or None) */
-	    w = PyInt_FromLong((long)ch);
+	    w = PyLong_FromLong((long)ch);
 	    if (w == NULL)
 		goto onError;
 	    x = PyObject_GetItem(mapping, w);
@@ -3964,8 +4097,8 @@
 	    }
     
 	    /* Apply mapping */
-	    if (PyInt_Check(x)) {
-		long value = PyInt_AS_LONG(x);
+	    if (PyLong_Check(x)) {
+		long value = PyLong_AS_LONG(x);
 		if (value < 0 || value > 65535) {
 		    PyErr_SetString(PyExc_TypeError,
 				    "character mapping must be in range(65536)");
@@ -4059,7 +4192,7 @@
 encoding_map_size(PyObject *obj, PyObject* args)
 {
     struct encoding_map *map = (struct encoding_map*)obj;
-    return PyInt_FromLong(sizeof(*map) - 1 + 16*map->count2 + 
+    return PyLong_FromLong(sizeof(*map) - 1 + 16*map->count2 + 
                           128*map->count3);
 }
 
@@ -4176,8 +4309,8 @@
             return NULL;
         for (i = 0; i < 256; i++) {
             key = value = NULL;
-            key = PyInt_FromLong(decode[i]);
-            value = PyInt_FromLong(i);
+            key = PyLong_FromLong(decode[i]);
+            value = PyLong_FromLong(i);
             if (!key || !value)
                 goto failed1;
             if (PyDict_SetItem(result, key, value) == -1)
@@ -4265,7 +4398,7 @@
    error occurred). */
 static PyObject *charmapencode_lookup(Py_UNICODE c, PyObject *mapping)
 {
-    PyObject *w = PyInt_FromLong((long)c);
+    PyObject *w = PyLong_FromLong((long)c);
     PyObject *x;
 
     if (w == NULL)
@@ -4284,8 +4417,8 @@
     }
     else if (x == Py_None)
 	return x;
-    else if (PyInt_Check(x)) {
-	long value = PyInt_AS_LONG(x);
+    else if (PyLong_Check(x)) {
+	long value = PyLong_AS_LONG(x);
 	if (value < 0 || value > 255) {
 	    PyErr_SetString(PyExc_TypeError,
 			     "character mapping must be in range(256)");
@@ -4299,7 +4432,7 @@
     else {
 	/* wrong return value */
 	PyErr_Format(PyExc_TypeError,
-                "character mapping must return integer, None or str8, not %.400s",
+                "character mapping must return integer, bytes or None, not %.400s",
                 x->ob_type->tp_name);
 	Py_DECREF(x);
 	return NULL;
@@ -4307,16 +4440,14 @@
 }
 
 static int
-charmapencode_resize(PyObject *outobj, Py_ssize_t *outpos, Py_ssize_t requiredsize)
+charmapencode_resize(PyObject **outobj, Py_ssize_t *outpos, Py_ssize_t requiredsize)
 {
-	Py_ssize_t outsize = PyBytes_GET_SIZE(  outobj);
+	Py_ssize_t outsize = PyString_GET_SIZE(*outobj);
 	/* exponentially overallocate to minimize reallocations */
 	if (requiredsize < 2*outsize)
 	    requiredsize = 2*outsize;
-	if (PyBytes_Resize(outobj, requiredsize)) {
-	    Py_DECREF(outobj);
+	if (_PyString_Resize(outobj, requiredsize))
 	    return -1;
-	}
 	return 0;
 }
 
@@ -4331,21 +4462,21 @@
    reallocation error occurred. The caller must decref the result */
 static
 charmapencode_result charmapencode_output(Py_UNICODE c, PyObject *mapping,
-    PyObject *outobj, Py_ssize_t *outpos)
+    PyObject **outobj, Py_ssize_t *outpos)
 {
     PyObject *rep;
     char *outstart;
-    Py_ssize_t outsize = PyBytes_GET_SIZE(outobj);
+    Py_ssize_t outsize = PyString_GET_SIZE(*outobj);
 
-    if (Py_Type(mapping) == &EncodingMapType) {
+    if (Py_TYPE(mapping) == &EncodingMapType) {
         int res = encoding_map_lookup(c, mapping);
 	Py_ssize_t requiredsize = *outpos+1;
         if (res == -1)
             return enc_FAILED;
-	if (outsize<requiredsize) 
+	if (outsize<requiredsize)
 	    if (charmapencode_resize(outobj, outpos, requiredsize))
 		return enc_EXCEPTION;
-        outstart = PyBytes_AS_STRING(outobj);
+        outstart = PyString_AS_STRING(*outobj);
 	outstart[(*outpos)++] = (char)res;
 	return enc_SUCCESS;
     }
@@ -4357,15 +4488,15 @@
 	Py_DECREF(rep);
 	return enc_FAILED;
     } else {
-	if (PyInt_Check(rep)) {
+	if (PyLong_Check(rep)) {
 	    Py_ssize_t requiredsize = *outpos+1;
 	    if (outsize<requiredsize)
 		if (charmapencode_resize(outobj, outpos, requiredsize)) {
 		    Py_DECREF(rep);
 		    return enc_EXCEPTION;
 		}
-            outstart = PyBytes_AS_STRING(outobj);
-	    outstart[(*outpos)++] = (char)PyInt_AS_LONG(rep);
+            outstart = PyString_AS_STRING(*outobj);
+	    outstart[(*outpos)++] = (char)PyLong_AS_LONG(rep);
 	}
 	else {
 	    const char *repchars = PyString_AS_STRING(rep);
@@ -4376,7 +4507,7 @@
 		    Py_DECREF(rep);
 		    return enc_EXCEPTION;
 		}
-            outstart = PyBytes_AS_STRING(outobj);
+            outstart = PyString_AS_STRING(*outobj);
 	    memcpy(outstart + *outpos, repchars, repsize);
 	    *outpos += repsize;
 	}
@@ -4392,7 +4523,7 @@
     const Py_UNICODE *p, Py_ssize_t size, Py_ssize_t *inpos, PyObject *mapping,
     PyObject **exceptionObject,
     int *known_errorHandler, PyObject **errorHandler, const char *errors,
-    PyObject *res, Py_ssize_t *respos)
+    PyObject **res, Py_ssize_t *respos)
 {
     PyObject *repunicode = NULL; /* initialize to prevent gcc warning */
     Py_ssize_t repsize;
@@ -4409,7 +4540,7 @@
     /* find all unencodable characters */
     while (collendpos < size) {
         PyObject *rep;
-        if (Py_Type(mapping) == &EncodingMapType) {
+        if (Py_TYPE(mapping) == &EncodingMapType) {
 	    int res = encoding_map_lookup(p[collendpos], mapping);
 	    if (res != -1)
 		break;
@@ -4527,7 +4658,7 @@
 
     /* allocate enough for a simple encoding without
        replacements, if we need more, we'll resize */
-    res = PyBytes_FromStringAndSize(NULL, size);
+    res = PyString_FromStringAndSize(NULL, size);
     if (res == NULL)
         goto onError;
     if (size == 0)
@@ -4535,14 +4666,14 @@
 
     while (inpos<size) {
 	/* try to encode it */
-	charmapencode_result x = charmapencode_output(p[inpos], mapping, res, &respos);
+	charmapencode_result x = charmapencode_output(p[inpos], mapping, &res, &respos);
 	if (x==enc_EXCEPTION) /* error */
 	    goto onError;
 	if (x==enc_FAILED) { /* unencodable character */
 	    if (charmap_encoding_error(p, size, &inpos, mapping,
 		&exc,
 		&known_errorHandler, &errorHandler, errors,
-		res, &respos)) {
+		&res, &respos)) {
 		goto onError;
 	    }
 	}
@@ -4552,10 +4683,9 @@
     }
 
     /* Resize if we allocated to much */
-    if (respos<PyBytes_GET_SIZE(res)) {
-	if (PyBytes_Resize(res, respos))
-	    goto onError;
-    }
+    if (respos<PyString_GET_SIZE(res))
+	_PyString_Resize(&res, respos);
+
     Py_XDECREF(exc);
     Py_XDECREF(errorHandler);
     return res;
@@ -4678,7 +4808,7 @@
 static
 int charmaptranslate_lookup(Py_UNICODE c, PyObject *mapping, PyObject **result)
 {
-    PyObject *w = PyInt_FromLong((long)c);
+    PyObject *w = PyLong_FromLong((long)c);
     PyObject *x;
 
     if (w == NULL)
@@ -4698,12 +4828,12 @@
 	*result = x;
 	return 0;
     }
-    else if (PyInt_Check(x)) {
-	long value = PyInt_AS_LONG(x);
+    else if (PyLong_Check(x)) {
+	long value = PyLong_AS_LONG(x);
 	long max = PyUnicode_GetMax();
 	if (value < 0 || value > max) {
 	    PyErr_Format(PyExc_TypeError,
-			     "character mapping must be in range(0x%lx)", max+1);
+                         "character mapping must be in range(0x%x)", max+1);
 	    Py_DECREF(x);
 	    return -1;
 	}
@@ -4761,9 +4891,9 @@
     }
     else if (*res==Py_None)
 	;
-    else if (PyInt_Check(*res)) {
+    else if (PyLong_Check(*res)) {
 	/* no overflow check, because we know that the space is enough */
-	*(*outp)++ = (Py_UNICODE)PyInt_AS_LONG(*res);
+	*(*outp)++ = (Py_UNICODE)PyLong_AS_LONG(*res);
     }
     else if (PyUnicode_Check(*res)) {
 	Py_ssize_t repsize = PyUnicode_GET_SIZE(*res);
@@ -5084,10 +5214,10 @@
 /* --- Helpers ------------------------------------------------------------ */
 
 #include "stringlib/unicodedefs.h"
-
 #include "stringlib/fastsearch.h"
-
 #include "stringlib/count.h"
+/* Include _ParseTupleFinds from find.h */
+#define FROM_UNICODE
 #include "stringlib/find.h"
 #include "stringlib/partition.h"
 
@@ -5449,20 +5579,14 @@
 
 	item = PySequence_Fast_GET_ITEM(fseq, i);
 	/* Convert item to Unicode. */
-	if (!PyString_Check(item) && !PyUnicode_Check(item))
-	{
-		if (PyBytes_Check(item))
-		{
-			PyErr_Format(PyExc_TypeError,
-                            "sequence item %d: join() will not operate on "
-                            "bytes objects", i);
-			goto onError;
-		}
-		item = PyObject_Unicode(item);
+	if (!PyUnicode_Check(item)) {
+	    PyErr_Format(PyExc_TypeError,
+			 "sequence item %zd: expected str instance,"
+			 " %.80s found",
+			 i, Py_TYPE(item)->tp_name);
+	    goto onError;
 	}
-	else
-		item = PyUnicode_FromObject(item);
-
+	item = PyUnicode_FromObject(item);
 	if (item == NULL)
 	    goto onError;
 	/* We own a reference to item from here on. */
@@ -5579,25 +5703,26 @@
     register Py_ssize_t j;
     Py_ssize_t len = self->length;
     PyObject *str;
+    register const Py_UNICODE *buf = self->str;
 
     for (i = j = 0; i < len; ) {
 	/* find a token */
-	while (i < len && Py_UNICODE_ISSPACE(self->str[i]))
+	while (i < len && Py_UNICODE_ISSPACE(buf[i]))
 	    i++;
 	j = i;
-	while (i < len && !Py_UNICODE_ISSPACE(self->str[i]))
+	while (i < len && !Py_UNICODE_ISSPACE(buf[i]))
 	    i++;
 	if (j < i) {
 	    if (maxcount-- <= 0)
 		break;
-	    SPLIT_APPEND(self->str, j, i);
-	    while (i < len && Py_UNICODE_ISSPACE(self->str[i]))
+	    SPLIT_APPEND(buf, j, i);
+	    while (i < len && Py_UNICODE_ISSPACE(buf[i]))
 		i++;
 	    j = i;
 	}
     }
     if (j < len) {
-	SPLIT_APPEND(self->str, j, len);
+	SPLIT_APPEND(buf, j, len);
     }
     return list;
 
@@ -5670,18 +5795,19 @@
     register Py_ssize_t j;
     Py_ssize_t len = self->length;
     PyObject *str;
+    register const Py_UNICODE *buf = self->str;
 
     for (i = j = 0; i < len; ) {
-	if (self->str[i] == ch) {
+	if (buf[i] == ch) {
 	    if (maxcount-- <= 0)
 		break;
-	    SPLIT_APPEND(self->str, j, i);
+	    SPLIT_APPEND(buf, j, i);
 	    i = j = i + 1;
 	} else
 	    i++;
     }
     if (j <= len) {
-	SPLIT_APPEND(self->str, j, len);
+	SPLIT_APPEND(buf, j, len);
     }
     return list;
 
@@ -5730,25 +5856,26 @@
     register Py_ssize_t j;
     Py_ssize_t len = self->length;
     PyObject *str;
+    register const Py_UNICODE *buf = self->str;
 
     for (i = j = len - 1; i >= 0; ) {
 	/* find a token */
-	while (i >= 0 && Py_UNICODE_ISSPACE(self->str[i]))
+	while (i >= 0 && Py_UNICODE_ISSPACE(buf[i]))
 	    i--;
 	j = i;
-	while (i >= 0 && !Py_UNICODE_ISSPACE(self->str[i]))
+	while (i >= 0 && !Py_UNICODE_ISSPACE(buf[i]))
 	    i--;
 	if (j > i) {
 	    if (maxcount-- <= 0)
 		break;
-	    SPLIT_APPEND(self->str, i + 1, j + 1);
-	    while (i >= 0 && Py_UNICODE_ISSPACE(self->str[i]))
+	    SPLIT_APPEND(buf, i + 1, j + 1);
+	    while (i >= 0 && Py_UNICODE_ISSPACE(buf[i]))
 		i--;
 	    j = i;
 	}
     }
     if (j >= 0) {
-	SPLIT_APPEND(self->str, 0, j + 1);
+	SPLIT_APPEND(buf, 0, j + 1);
     }
     if (PyList_Reverse(list) < 0)
         goto onError;
@@ -5769,18 +5896,19 @@
     register Py_ssize_t j;
     Py_ssize_t len = self->length;
     PyObject *str;
+    register const Py_UNICODE *buf = self->str;
 
     for (i = j = len - 1; i >= 0; ) {
-	if (self->str[i] == ch) {
+	if (buf[i] == ch) {
 	    if (maxcount-- <= 0)
 		break;
-	    SPLIT_APPEND(self->str, i + 1, j + 1);
+	    SPLIT_APPEND(buf, i + 1, j + 1);
 	    j = i = i - 1;
 	} else
 	    i--;
     }
     if (j >= -1) {
-	SPLIT_APPEND(self->str, 0, j + 1);
+	SPLIT_APPEND(buf, 0, j + 1);
     }
     if (PyList_Reverse(list) < 0)
         goto onError;
@@ -6224,16 +6352,6 @@
     if (PyUnicode_Check(left) && PyUnicode_Check(right))
         return unicode_compare((PyUnicodeObject *)left,
                                (PyUnicodeObject *)right);
-    if ((PyString_Check(left) && PyUnicode_Check(right)) ||
-        (PyUnicode_Check(left) && PyString_Check(right))) {
-        if (PyUnicode_Check(left))
-            left = _PyUnicode_AsDefaultEncodedString(left, NULL);
-        if (PyUnicode_Check(right))
-            right = _PyUnicode_AsDefaultEncodedString(right, NULL);
-        assert(PyString_Check(left));
-        assert(PyString_Check(right));
-        return PyObject_Compare(left, right);
-    }
     PyErr_Format(PyExc_TypeError,
                  "Can't compare %.100s and %.100s",
                  left->ob_type->tp_name,
@@ -6372,9 +6490,6 @@
 {
     PyUnicodeObject *u = NULL, *v = NULL, *w;
 
-    if (PyBytes_Check(left) || PyBytes_Check(right))
-        return PyBytes_Concat(left, right);
-
     /* Coerce the two arguments */
     u = (PyUnicodeObject *)PyUnicode_FromObject(left);
     if (u == NULL)
@@ -6459,7 +6574,7 @@
 
     FIX_START_END(self);
 
-    result = PyInt_FromSsize_t(
+    result = PyLong_FromSsize_t(
         stringlib_count(self->str + start, end - start,
                         substring->str, substring->length)
         );
@@ -6491,11 +6606,11 @@
     v = PyUnicode_AsEncodedObject((PyObject *)self, encoding, errors);
     if (v == NULL)
         goto onError;
-    if (!PyBytes_Check(v)) {
+    if (!PyString_Check(v)) {
         PyErr_Format(PyExc_TypeError,
                      "encoder did not return a bytes object "
                      "(type=%.400s)",
-                     Py_Type(v)->tp_name);
+                     Py_TYPE(v)->tp_name);
         Py_DECREF(v);
         return NULL;
     }
@@ -6517,7 +6632,8 @@
     Py_UNICODE *e;
     Py_UNICODE *p;
     Py_UNICODE *q;
-    Py_ssize_t i, j, old_j;
+    Py_UNICODE *qe;
+    Py_ssize_t i, j, incr;
     PyUnicodeObject *u;
     int tabsize = 8;
 
@@ -6525,63 +6641,70 @@
 	return NULL;
 
     /* First pass: determine size of output string */
-    i = j = old_j = 0;
-    e = self->str + self->length;
+    i = 0; /* chars up to and including most recent \n or \r */
+    j = 0; /* chars since most recent \n or \r (use in tab calculations) */
+    e = self->str + self->length; /* end of input */
     for (p = self->str; p < e; p++)
         if (*p == '\t') {
 	    if (tabsize > 0) {
-		j += tabsize - (j % tabsize);
-		if (old_j > j) {
-		    PyErr_SetString(PyExc_OverflowError,
-				    "new string is too long");
-		    return NULL;
-		}
-		old_j = j;
-	    }
+		incr = tabsize - (j % tabsize); /* cannot overflow */
+		if (j > PY_SSIZE_T_MAX - incr)
+		    goto overflow1;
+		j += incr;
+            }
 	}
         else {
+	    if (j > PY_SSIZE_T_MAX - 1)
+		goto overflow1;
             j++;
             if (*p == '\n' || *p == '\r') {
+		if (i > PY_SSIZE_T_MAX - j)
+		    goto overflow1;
                 i += j;
-                old_j = j = 0;
-                if (i < 0) {
-                    PyErr_SetString(PyExc_OverflowError,
-                                    "new string is too long");
-                    return NULL;
-                }
+                j = 0;
             }
         }
 
-    if ((i + j) < 0) {
-        PyErr_SetString(PyExc_OverflowError, "new string is too long");
-        return NULL;
-    }
+    if (i > PY_SSIZE_T_MAX - j)
+	goto overflow1;
 
     /* Second pass: create output string and fill it */
     u = _PyUnicode_New(i + j);
     if (!u)
         return NULL;
 
-    j = 0;
-    q = u->str;
+    j = 0; /* same as in first pass */
+    q = u->str; /* next output char */
+    qe = u->str + u->length; /* end of output */
 
     for (p = self->str; p < e; p++)
         if (*p == '\t') {
 	    if (tabsize > 0) {
 		i = tabsize - (j % tabsize);
 		j += i;
-		while (i--)
+		while (i--) {
+		    if (q >= qe)
+			goto overflow2;
 		    *q++ = ' ';
+                }
 	    }
 	}
 	else {
-            j++;
+	    if (q >= qe)
+		goto overflow2;
 	    *q++ = *p;
+            j++;
             if (*p == '\n' || *p == '\r')
                 j = 0;
         }
 
     return (PyObject*) u;
+
+  overflow2:
+    Py_DECREF(u);
+  overflow1:
+    PyErr_SetString(PyExc_OverflowError, "new string is too long");
+    return NULL;
 }
 
 PyDoc_STRVAR(find__doc__,
@@ -6597,16 +6720,12 @@
 unicode_find(PyUnicodeObject *self, PyObject *args)
 {
     PyObject *substring;
-    Py_ssize_t start = 0;
-    Py_ssize_t end = PY_SSIZE_T_MAX;
+    Py_ssize_t start;
+    Py_ssize_t end;
     Py_ssize_t result;
 
-    if (!PyArg_ParseTuple(args, "O|O&O&:find", &substring,
-		_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+    if (!_ParseTupleFinds(args, &substring, &start, &end))
         return NULL;
-    substring = PyUnicode_FromObject(substring);
-    if (!substring)
-	return NULL;
 
     result = stringlib_find_slice(
         PyUnicode_AS_UNICODE(self), PyUnicode_GET_SIZE(self),
@@ -6616,7 +6735,7 @@
 
     Py_DECREF(substring);
 
-    return PyInt_FromSsize_t(result);
+    return PyLong_FromSsize_t(result);
 }
 
 static PyObject *
@@ -6641,12 +6760,12 @@
 
     if (self->hash != -1)
         return self->hash;
-    len = Py_Size(self);
+    len = Py_SIZE(self);
     p = self->str;
     x = *p << 7;
     while (--len >= 0)
         x = (1000003*x) ^ *p++;
-    x ^= Py_Size(self);
+    x ^= Py_SIZE(self);
     if (x == -1)
         x = -2;
     self->hash = x;
@@ -6663,15 +6782,11 @@
 {
     Py_ssize_t result;
     PyObject *substring;
-    Py_ssize_t start = 0;
-    Py_ssize_t end = PY_SSIZE_T_MAX;
+    Py_ssize_t start;
+    Py_ssize_t end;
 
-    if (!PyArg_ParseTuple(args, "O|O&O&:index", &substring,
-		_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+    if (!_ParseTupleFinds(args, &substring, &start, &end))
         return NULL;
-    substring = PyUnicode_FromObject(substring);
-    if (!substring)
-	return NULL;
 
     result = stringlib_find_slice(
         PyUnicode_AS_UNICODE(self), PyUnicode_GET_SIZE(self),
@@ -6686,7 +6801,7 @@
         return NULL;
     }
 
-    return PyInt_FromSsize_t(result);
+    return PyLong_FromSsize_t(result);
 }
 
 PyDoc_STRVAR(islower__doc__,
@@ -7158,15 +7273,6 @@
 	if (sep != NULL && sep != Py_None) {
 		if (PyUnicode_Check(sep))
 			return _PyUnicode_XStrip(self, striptype, sep);
-		else if (PyString_Check(sep)) {
-			PyObject *res;
-			sep = PyUnicode_FromObject(sep);
-			if (sep==NULL)
-				return NULL;
-			res = _PyUnicode_XStrip(self, striptype, sep);
-			Py_DECREF(sep);
-			return res;
-		}
 		else {
 			PyErr_Format(PyExc_TypeError,
 				     "%s arg must be None, unicode or str",
@@ -7506,16 +7612,12 @@
 unicode_rfind(PyUnicodeObject *self, PyObject *args)
 {
     PyObject *substring;
-    Py_ssize_t start = 0;
-    Py_ssize_t end = PY_SSIZE_T_MAX;
+    Py_ssize_t start;
+    Py_ssize_t end;
     Py_ssize_t result;
 
-    if (!PyArg_ParseTuple(args, "O|O&O&:rfind", &substring,
-		_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
-        return NULL;
-    substring = PyUnicode_FromObject(substring);
-    if (!substring)
-	return NULL;
+    if (!_ParseTupleFinds(args, &substring, &start, &end))
+	    return NULL;
 
     result = stringlib_rfind_slice(
         PyUnicode_AS_UNICODE(self), PyUnicode_GET_SIZE(self),
@@ -7525,7 +7627,7 @@
 
     Py_DECREF(substring);
 
-    return PyInt_FromSsize_t(result);
+    return PyLong_FromSsize_t(result);
 }
 
 PyDoc_STRVAR(rindex__doc__,
@@ -7537,16 +7639,12 @@
 unicode_rindex(PyUnicodeObject *self, PyObject *args)
 {
     PyObject *substring;
-    Py_ssize_t start = 0;
-    Py_ssize_t end = PY_SSIZE_T_MAX;
+    Py_ssize_t start;
+    Py_ssize_t end;
     Py_ssize_t result;
 
-    if (!PyArg_ParseTuple(args, "O|O&O&:rindex", &substring,
-		_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
-        return NULL;
-    substring = PyUnicode_FromObject(substring);
-    if (!substring)
-	return NULL;
+    if (!_ParseTupleFinds(args, &substring, &start, &end))
+	    return NULL;
 
     result = stringlib_rfind_slice(
         PyUnicode_AS_UNICODE(self), PyUnicode_GET_SIZE(self),
@@ -7560,7 +7658,7 @@
         PyErr_SetString(PyExc_ValueError, "substring not found");
         return NULL;
     }
-    return PyInt_FromSsize_t(result);
+    return PyLong_FromSsize_t(result);
 }
 
 PyDoc_STRVAR(rjust__doc__,
@@ -7808,6 +7906,109 @@
     return fixup(self, fixswapcase);
 }
 
+PyDoc_STRVAR(maketrans__doc__,
+"str.maketrans(x[, y[, z]]) -> dict (static method)\n\
+\n\
+Return a translation table usable for str.translate().\n\
+If there is only one argument, it must be a dictionary mapping Unicode\n\
+ordinals (integers) or characters to Unicode ordinals, strings or None.\n\
+Character keys will then be converted to ordinals.\n\
+If there are two arguments, they must be strings of equal length, and\n\
+in the resulting dictionary, each character in x will be mapped to the\n\
+character at the same position in y. If there is a third argument, it\n\
+must be a string, whose characters will be mapped to None in the result.");
+
+static PyObject*
+unicode_maketrans(PyUnicodeObject *null, PyObject *args)
+{
+    PyObject *x, *y = NULL, *z = NULL;
+    PyObject *new = NULL, *key, *value;
+    Py_ssize_t i = 0;
+    int res;
+    
+    if (!PyArg_ParseTuple(args, "O|UU:maketrans", &x, &y, &z))
+        return NULL;
+    new = PyDict_New();
+    if (!new)
+        return NULL;
+    if (y != NULL) {
+        /* x must be a string too, of equal length */
+        Py_ssize_t ylen = PyUnicode_GET_SIZE(y);
+        if (!PyUnicode_Check(x)) {
+            PyErr_SetString(PyExc_TypeError, "first maketrans argument must "
+                            "be a string if there is a second argument");
+            goto err;
+        }
+        if (PyUnicode_GET_SIZE(x) != ylen) {
+            PyErr_SetString(PyExc_ValueError, "the first two maketrans "
+                            "arguments must have equal length");
+            goto err;
+        }
+        /* create entries for translating chars in x to those in y */
+        for (i = 0; i < PyUnicode_GET_SIZE(x); i++) {
+            key = PyLong_FromLong(PyUnicode_AS_UNICODE(x)[i]);
+            value = PyLong_FromLong(PyUnicode_AS_UNICODE(y)[i]);
+            if (!key || !value)
+                goto err;
+            res = PyDict_SetItem(new, key, value);
+            Py_DECREF(key);
+            Py_DECREF(value);
+            if (res < 0)
+                goto err;
+        }
+        /* create entries for deleting chars in z */
+        if (z != NULL) {
+            for (i = 0; i < PyUnicode_GET_SIZE(z); i++) {
+                key = PyLong_FromLong(PyUnicode_AS_UNICODE(z)[i]);
+                if (!key)
+                    goto err;
+                res = PyDict_SetItem(new, key, Py_None);
+                Py_DECREF(key);
+                if (res < 0)
+                    goto err;
+            }
+        }
+    } else {
+        /* x must be a dict */
+        if (!PyDict_Check(x)) {
+            PyErr_SetString(PyExc_TypeError, "if you give only one argument "
+                            "to maketrans it must be a dict");
+            goto err;
+        }
+        /* copy entries into the new dict, converting string keys to int keys */
+        while (PyDict_Next(x, &i, &key, &value)) {
+            if (PyUnicode_Check(key)) {
+                /* convert string keys to integer keys */
+                PyObject *newkey;
+                if (PyUnicode_GET_SIZE(key) != 1) {
+                    PyErr_SetString(PyExc_ValueError, "string keys in translate "
+                                    "table must be of length 1");
+                    goto err;
+                }
+                newkey = PyLong_FromLong(PyUnicode_AS_UNICODE(key)[0]);
+                if (!newkey)
+                    goto err;
+                res = PyDict_SetItem(new, newkey, value);
+                Py_DECREF(newkey);
+                if (res < 0)
+                    goto err;
+            } else if (PyLong_Check(key)) {
+                /* just keep integer keys */
+                if (PyDict_SetItem(new, key, value) < 0)
+                    goto err;
+            } else {
+                PyErr_SetString(PyExc_TypeError, "keys in translate table must "
+                                "be strings or integers");
+                goto err;
+            }
+        }
+    }
+    return new;
+  err:
+    Py_DECREF(new);
+    return NULL;
+}
+
 PyDoc_STRVAR(translate__doc__,
 "S.translate(table) -> unicode\n\
 \n\
@@ -7820,10 +8021,7 @@
 static PyObject*
 unicode_translate(PyUnicodeObject *self, PyObject *table)
 {
-    return PyUnicode_TranslateCharmap(self->str,
-				      self->length,
-				      table,
-				      "ignore");
+    return PyUnicode_TranslateCharmap(self->str, self->length, table, "ignore");
 }
 
 PyDoc_STRVAR(upper__doc__,
@@ -7885,7 +8083,7 @@
 static PyObject*
 unicode_freelistsize(PyUnicodeObject *self)
 {
-    return PyInt_FromLong(unicode_freelist_size);
+    return PyLong_FromLong(numfree);
 }
 #endif
 
@@ -8047,6 +8245,8 @@
     {"__format__", (PyCFunction) unicode_unicode__format__, METH_VARARGS, p_format__doc__},
     {"_formatter_field_name_split", (PyCFunction) formatter_field_name_split, METH_NOARGS},
     {"_formatter_parser", (PyCFunction) formatter_parser, METH_NOARGS},
+    {"maketrans", (PyCFunction) unicode_maketrans,
+     METH_VARARGS | METH_STATIC, maketrans__doc__},
 #if 0
     {"capwords", (PyCFunction) unicode_capwords, METH_NOARGS, capwords__doc__},
 #endif
@@ -8119,8 +8319,8 @@
             return PyUnicode_FromUnicode(self->str + start, slicelength);
         } else {
             source_buf = PyUnicode_AS_UNICODE((PyObject*)self);
-            result_buf = (Py_UNICODE *)PyMem_MALLOC(slicelength*
-                                                    sizeof(Py_UNICODE));
+            result_buf = (Py_UNICODE *)PyObject_MALLOC(slicelength*
+                                                       sizeof(Py_UNICODE));
 	    
 	    if (result_buf == NULL)
 		    return PyErr_NoMemory();
@@ -8130,7 +8330,7 @@
             }
 
             result = PyUnicode_FromUnicode(result_buf, slicelength);
-            PyMem_FREE(result_buf);
+            PyObject_FREE(result_buf);
             return result;
         }
     } else {
@@ -8164,12 +8364,6 @@
     return NULL;
 }
 
-#define F_LJUST (1<<0)
-#define F_SIGN	(1<<1)
-#define F_BLANK (1<<2)
-#define F_ALT	(1<<3)
-#define F_ZERO	(1<<4)
-
 static Py_ssize_t
 strtounicode(Py_UNICODE *buffer, const char *charbuffer)
 {
@@ -8191,6 +8385,7 @@
     return Py_SAFE_DOWNCAST(result, Py_ssize_t, int);
 }
 
+#if 0 
 static int
 longtounicode(Py_UNICODE *buffer, size_t len, const char *format, long x)
 {
@@ -8200,6 +8395,7 @@
     result = strtounicode(buffer, (char *)buffer);
     return Py_SAFE_DOWNCAST(result, Py_ssize_t, int);
 }
+#endif
 
 /* XXX To save some code duplication, formatfloat/long/int could have been
    shared with stringobject.c, converting from 8-bit to Unicode after the
@@ -8270,6 +8466,7 @@
 	return result;
 }
 
+#if 0
 static int
 formatint(Py_UNICODE *buf,
 	  size_t buflen,
@@ -8287,7 +8484,7 @@
     char *sign;
     long x;
 
-    x = PyInt_AsLong(v);
+    x = PyLong_AsLong(v);
     if (x == -1 && PyErr_Occurred())
         return -1;
     if (x < 0 && type == 'u') {
@@ -8345,6 +8542,7 @@
     else
         return longtounicode(buf, buflen, fmt, x);
 }
+#endif
 
 static int
 formatchar(Py_UNICODE *buf,
@@ -8357,17 +8555,10 @@
 	    goto onError;
 	buf[0] = PyUnicode_AS_UNICODE(v)[0];
     }
-
-    else if (PyString_Check(v)) {
-	if (PyString_GET_SIZE(v) != 1)
-	    goto onError;
-	buf[0] = (Py_UNICODE)PyString_AS_STRING(v)[0];
-    }
-
     else {
 	/* Integer input truncated to a character */
         long x;
-	x = PyInt_AsLong(v);
+	x = PyLong_AsLong(v);
 	if (x == -1 && PyErr_Occurred())
 	    goto onError;
 #ifdef Py_UNICODE_WIDE
@@ -8440,8 +8631,8 @@
 	arglen = -1;
 	argidx = -2;
     }
-    if (Py_Type(args)->tp_as_mapping && !PyTuple_Check(args) &&
-        !PyObject_TypeCheck(args, &PyBaseString_Type))
+    if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) &&
+        !PyUnicode_Check(args))
 	dict = args;
 
     while (--fmtcnt >= 0) {
@@ -8463,6 +8654,7 @@
 	    int prec = -1;
 	    Py_UNICODE c = '\0';
 	    Py_UNICODE fill;
+	    int isnumok;
 	    PyObject *v = NULL;
 	    PyObject *temp = NULL;
 	    Py_UNICODE *pbuf;
@@ -8539,12 +8731,12 @@
 		v = getnextarg(args, arglen, &argidx);
 		if (v == NULL)
 		    goto onError;
-		if (!PyInt_Check(v)) {
+		if (!PyLong_Check(v)) {
 		    PyErr_SetString(PyExc_TypeError,
 				    "* wants int");
 		    goto onError;
 		}
-		width = PyInt_AsLong(v);
+		width = PyLong_AsLong(v);
 		if (width == -1 && PyErr_Occurred())
 			goto onError;
 		if (width < 0) {
@@ -8576,12 +8768,12 @@
 		    v = getnextarg(args, arglen, &argidx);
 		    if (v == NULL)
 			goto onError;
-		    if (!PyInt_Check(v)) {
+		    if (!PyLong_Check(v)) {
 			PyErr_SetString(PyExc_TypeError,
 					"* wants int");
 			goto onError;
 		    }
-		    prec = PyInt_AsLong(v);
+		    prec = PyLong_AsLong(v);
 		    if (prec == -1 && PyErr_Occurred())
 			goto onError;
 		    if (prec < 0)
@@ -8638,26 +8830,14 @@
 		    Py_INCREF(temp);
 		}
 		else {
-		    PyObject *unicode;
 		    if (c == 's')
-			temp = PyObject_Unicode(v);
+			temp = PyObject_Str(v);
 		    else
 			temp = PyObject_Repr(v);
 		    if (temp == NULL)
 			goto onError;
                     if (PyUnicode_Check(temp))
                         /* nothing to do */;
-                    else if (PyString_Check(temp)) {
-                        /* convert to string to Unicode */
-		        unicode = PyUnicode_Decode(PyString_AS_STRING(temp),
-						   PyString_GET_SIZE(temp),
-						   NULL,
-						   "strict");
-		        Py_DECREF(temp);
-		        temp = unicode;
-		        if (temp == NULL)
-			    goto onError;
-		    }
 		    else {
 			Py_DECREF(temp);
 			PyErr_SetString(PyExc_TypeError,
@@ -8679,21 +8859,38 @@
 	    case 'X':
 		if (c == 'i')
 		    c = 'd';
-		if (PyLong_Check(v)) {
-		    temp = formatlong(v, flags, prec, c);
-		    if (!temp)
-			goto onError;
-		    pbuf = PyUnicode_AS_UNICODE(temp);
-		    len = PyUnicode_GET_SIZE(temp);
-		    sign = 1;
+		isnumok = 0;
+		if (PyNumber_Check(v)) {
+			PyObject *iobj=NULL;
+
+			if (PyLong_Check(v)) {
+				iobj = v;
+				Py_INCREF(iobj);
+			}
+			else {
+				iobj = PyNumber_Long(v);
+			}
+			if (iobj!=NULL) {
+				if (PyLong_Check(iobj)) {
+					isnumok = 1;
+					temp = formatlong(iobj, flags, prec, c);
+					Py_DECREF(iobj);
+					if (!temp)
+					    goto onError;
+					pbuf = PyUnicode_AS_UNICODE(temp);
+					len = PyUnicode_GET_SIZE(temp);
+					sign = 1;
+				}
+				else {
+					Py_DECREF(iobj);
+				}
+			}
 		}
-		else {
-		    pbuf = formatbuf;
-		    len = formatint(pbuf, sizeof(formatbuf)/sizeof(Py_UNICODE),
-				    flags, prec, c, v);
-		    if (len < 0)
+		if (!isnumok) {
+			PyErr_Format(PyExc_TypeError, 
+			    "%%%c format: a number is required, "
+			    "not %.200s", c, Py_TYPE(v)->tp_name);
 			goto onError;
-		    sign = 1;
 		}
 		if (flags & F_ZERO)
 		    fill = '0';
@@ -8858,7 +9055,7 @@
 	if (x == NULL)
 		return (PyObject *)_PyUnicode_New(0);
 	if (encoding == NULL && errors == NULL)
-	    return PyObject_Unicode(x);
+	    return PyObject_Str(x);
 	else
 	return PyUnicode_FromEncodedObject(x, encoding, errors);
 }
@@ -8879,7 +9076,7 @@
 		Py_DECREF(tmp);
 		return NULL;
 	}
-	pnew->str = PyMem_NEW(Py_UNICODE, n+1);
+	pnew->str = (Py_UNICODE*) PyObject_MALLOC(sizeof(Py_UNICODE) * (n+1));
 	if (pnew->str == NULL) {
 		_Py_ForgetReference((PyObject *)pnew);
 		PyObject_Del(pnew);
@@ -8935,7 +9132,7 @@
     unicode_methods,			/* tp_methods */
     0,					/* tp_members */
     0,					/* tp_getset */
-    &PyBaseString_Type,			/* tp_base */
+    &PyBaseObject_Type,			/* tp_base */
     0,					/* tp_dict */
     0,					/* tp_descr_get */
     0,					/* tp_descr_set */
@@ -8965,8 +9162,8 @@
     };
 
     /* Init the implementation */
-    unicode_freelist = NULL;
-    unicode_freelist_size = 0;
+    free_list = NULL;
+    numfree = 0;
     unicode_empty = _PyUnicode_New(0);
     if (!unicode_empty)
 	return;
@@ -8986,10 +9183,29 @@
 
 /* Finalize the Unicode implementation */
 
+int
+PyUnicode_ClearFreeList(void)
+{
+    int freelist_size = numfree;
+    PyUnicodeObject *u;
+
+    for (u = free_list; u != NULL;) {
+	PyUnicodeObject *v = u;
+	u = *(PyUnicodeObject **)u;
+	if (v->str)
+	    PyObject_DEL(v->str);
+	Py_XDECREF(v->defenc);
+	PyObject_Del(v);
+	numfree--;
+    }
+    free_list = NULL;
+    assert(numfree == 0);
+    return freelist_size;
+}
+
 void
 _PyUnicode_Fini(void)
 {
-    PyUnicodeObject *u;
     int i;
 
     Py_XDECREF(unicode_empty);
@@ -9001,17 +9217,7 @@
 	    unicode_latin1[i] = NULL;
 	}
     }
-
-    for (u = unicode_freelist; u != NULL;) {
-	PyUnicodeObject *v = u;
-	u = *(PyUnicodeObject **)u;
-	if (v->str)
-	    PyMem_DEL(v->str);
-	Py_XDECREF(v->defenc);
-	PyObject_Del(v);
-    }
-    unicode_freelist = NULL;
-    unicode_freelist_size = 0;
+    (void)PyUnicode_ClearFreeList();
 }
 
 void
@@ -9058,7 +9264,7 @@
 	PyThreadState_GET()->recursion_critical = 0;
 	/* The two references in interned are not counted by refcnt.
 	   The deallocator will take care of this */
-	Py_Refcnt(s) -= 2;
+	Py_REFCNT(s) -= 2;
 	PyUnicode_CHECK_INTERNED(s) = SSTATE_INTERNED_MORTAL;
 }
 
@@ -9112,11 +9318,11 @@
 			/* XXX Shouldn't happen */
 			break;
 		case SSTATE_INTERNED_IMMORTAL:
-			Py_Refcnt(s) += 1;
+			Py_REFCNT(s) += 1;
 			immortal_size += s->length;
 			break;
 		case SSTATE_INTERNED_MORTAL:
-			Py_Refcnt(s) += 2;
+			Py_REFCNT(s) += 2;
 			mortal_size += s->length;
 			break;
 		default:
@@ -9188,7 +9394,7 @@
 	Py_ssize_t len = 0;
 	if (it->it_seq)
 		len = PyUnicode_GET_SIZE(it->it_seq) - it->it_index;
-	return PyInt_FromSsize_t(len);
+	return PyLong_FromSsize_t(len);
 }
 
 PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
@@ -9201,7 +9407,7 @@
 
 PyTypeObject PyUnicodeIter_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"unicodeiterator",			/* tp_name */
+	"str_iterator",			/* tp_name */
 	sizeof(unicodeiterobject),		/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */

Modified: python/branches/py3k-importlib/Objects/weakrefobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/weakrefobject.c	(original)
+++ python/branches/py3k-importlib/Objects/weakrefobject.c	Thu Mar 27 00:48:05 2008
@@ -105,7 +105,7 @@
 {
     PyObject_GC_UnTrack(self);
     clear_weakref((PyWeakReference *) self);
-    Py_Type(self)->tp_free(self);
+    Py_TYPE(self)->tp_free(self);
 }
 
 
@@ -172,7 +172,7 @@
 		      name ? "<weakref at %p; to '%.50s' at %p (%s)>"
 		           : "<weakref at %p; to '%.50s' at %p>",
 		      self,
-		      Py_Type(PyWeakref_GET_OBJECT(self))->tp_name,
+		      Py_TYPE(PyWeakref_GET_OBJECT(self))->tp_name,
 		      PyWeakref_GET_OBJECT(self),
 		      name);
 	Py_XDECREF(nameobj);
@@ -276,10 +276,10 @@
         PyWeakReference *ref, *proxy;
         PyWeakReference **list;
 
-        if (!PyType_SUPPORTS_WEAKREFS(Py_Type(ob))) {
+        if (!PyType_SUPPORTS_WEAKREFS(Py_TYPE(ob))) {
             PyErr_Format(PyExc_TypeError,
                          "cannot create weak reference to '%s' object",
-                         Py_Type(ob)->tp_name);
+                         Py_TYPE(ob)->tp_name);
             return NULL;
         }
         if (callback == Py_None)
@@ -448,7 +448,7 @@
     char buf[160];
     PyOS_snprintf(buf, sizeof(buf),
 		  "<weakproxy at %p to %.100s at %p>", proxy,
-		  Py_Type(PyWeakref_GET_OBJECT(proxy))->tp_name,
+		  Py_TYPE(PyWeakref_GET_OBJECT(proxy))->tp_name,
 		  PyWeakref_GET_OBJECT(proxy));
     return PyUnicode_FromString(buf);
 }
@@ -699,10 +699,10 @@
     PyWeakReference **list;
     PyWeakReference *ref, *proxy;
 
-    if (!PyType_SUPPORTS_WEAKREFS(Py_Type(ob))) {
+    if (!PyType_SUPPORTS_WEAKREFS(Py_TYPE(ob))) {
         PyErr_Format(PyExc_TypeError,
 		     "cannot create weak reference to '%s' object",
-                     Py_Type(ob)->tp_name);
+                     Py_TYPE(ob)->tp_name);
         return NULL;
     }
     list = GET_WEAKREFS_LISTPTR(ob);
@@ -758,10 +758,10 @@
     PyWeakReference **list;
     PyWeakReference *ref, *proxy;
 
-    if (!PyType_SUPPORTS_WEAKREFS(Py_Type(ob))) {
+    if (!PyType_SUPPORTS_WEAKREFS(Py_TYPE(ob))) {
         PyErr_Format(PyExc_TypeError,
 		     "cannot create weak reference to '%s' object",
-                     Py_Type(ob)->tp_name);
+                     Py_TYPE(ob)->tp_name);
         return NULL;
     }
     list = GET_WEAKREFS_LISTPTR(ob);
@@ -784,9 +784,9 @@
             PyWeakReference *prev;
 
             if (PyCallable_Check(ob))
-                Py_Type(result) = &_PyWeakref_CallableProxyType;
+                Py_TYPE(result) = &_PyWeakref_CallableProxyType;
             else
-                Py_Type(result) = &_PyWeakref_ProxyType;
+                Py_TYPE(result) = &_PyWeakref_ProxyType;
             get_basic_refs(*list, &ref, &proxy);
             if (callback == NULL) {
                 if (proxy != NULL) {
@@ -851,7 +851,7 @@
     PyWeakReference **list;
 
     if (object == NULL
-        || !PyType_SUPPORTS_WEAKREFS(Py_Type(object))
+        || !PyType_SUPPORTS_WEAKREFS(Py_TYPE(object))
         || object->ob_refcnt != 0) {
         PyErr_BadInternalCall();
         return;

Modified: python/branches/py3k-importlib/PC/VC6/build_ssl.py
==============================================================================
--- python/branches/py3k-importlib/PC/VC6/build_ssl.py	(original)
+++ python/branches/py3k-importlib/PC/VC6/build_ssl.py	Thu Mar 27 00:48:05 2008
@@ -8,7 +8,7 @@
 #   directory.  It is likely you will already find the zlib library and
 #   any other external packages there.
 # * Install ActivePerl and ensure it is somewhere on your path.
-# * Run this script from the PCBuild directory.
+# * Run this script from the PC/VC6 directory.
 #
 # it should configure and build SSL, then build the ssl Python extension
 # without intervention.

Modified: python/branches/py3k-importlib/PC/VC6/pcbuild.dsw
==============================================================================
--- python/branches/py3k-importlib/PC/VC6/pcbuild.dsw	(original)
+++ python/branches/py3k-importlib/PC/VC6/pcbuild.dsw	Thu Mar 27 00:48:05 2008
@@ -57,6 +57,21 @@
 
 ###############################################################################
 
+Project: "_msi"=".\_msi.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+    Begin Project Dependency
+    Project_Dep_Name pythoncore
+    End Project Dependency
+}}}
+
+###############################################################################
+
 Project: "_socket"=".\_socket.dsp" - Package Owner=<4>
 
 Package=<5>
@@ -288,3 +303,4 @@
 
 ###############################################################################
 
+

Modified: python/branches/py3k-importlib/PC/VC6/python.dsp
==============================================================================
--- python/branches/py3k-importlib/PC/VC6/python.dsp	(original)
+++ python/branches/py3k-importlib/PC/VC6/python.dsp	Thu Mar 27 00:48:05 2008
@@ -77,6 +77,11 @@
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
 # ADD LINK32 odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /base:"0x1d000000" /subsystem:console /debug /machine:I386 /out:"./python_d.exe" /pdbtype:sept
 # SUBTRACT LINK32 /pdb:none
+# Begin Special Build Tool
+SOURCE="$(InputPath)"
+PostBuild_Desc=Changing stack size...
+PostBuild_Cmds=editbin /STACK:0x200000 python_d.exe
+# End Special Build Tool
 
 !ENDIF 
 

Modified: python/branches/py3k-importlib/PC/VC6/pythoncore.dsp
==============================================================================
--- python/branches/py3k-importlib/PC/VC6/pythoncore.dsp	(original)
+++ python/branches/py3k-importlib/PC/VC6/pythoncore.dsp	Thu Mar 27 00:48:05 2008
@@ -54,7 +54,7 @@
 # ADD BSC32 /nologo
 LINK32=link.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
-# ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib shell32.lib /nologo /base:"0x1e000000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./python26.dll"
+# ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib shell32.lib /nologo /base:"0x1e000000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./python30.dll"
 # SUBTRACT LINK32 /pdb:none
 
 !ELSEIF  "$(CFG)" == "pythoncore - Win32 Debug"
@@ -82,7 +82,7 @@
 # ADD BSC32 /nologo
 LINK32=link.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib shell32.lib /nologo /base:"0x1e000000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./python26_d.dll" /pdbtype:sept
+# ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib shell32.lib /nologo /base:"0x1e000000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./python30_d.dll" /pdbtype:sept
 # SUBTRACT LINK32 /pdb:none
 
 !ENDIF 
@@ -125,10 +125,18 @@
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\Modules\_collectionsmodule.c
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\Modules\_csv.c
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\Modules\_fileio.c
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\Modules\_functoolsmodule.c
 # End Source File
 # Begin Source File
@@ -197,6 +205,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\Modules\atexitmodule.c
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\Modules\audioop.c
 # End Source File
 # Begin Source File
@@ -217,6 +229,14 @@
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\Objects\bytes_methods.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Objects\bytesobject.c
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\Objects\cellobject.c
 # End Source File
 # Begin Source File
@@ -245,7 +265,7 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\collectionsmodule.c
+SOURCE=..\..\Modules\_collectionsmodule.c
 # End Source File
 # Begin Source File
 
@@ -281,6 +301,14 @@
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\Modules\zlib\gzio.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Modules\zlib\infback.c
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\Objects\descrobject.c
 # End Source File
 # Begin Source File
@@ -317,14 +345,30 @@
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\Parser\firstsets.c
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\Objects\floatobject.c
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\Python\formatter_string.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Python\formatter_unicode.c
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\Objects\frameobject.c
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\Python\formatter_unicode.c
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\Python\frozen.c
 # End Source File
 # Begin Source File
@@ -386,11 +430,11 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Parser\grammar1.c
+SOURCE=..\..\Parser\grammar.c
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\imageop.c
+SOURCE=..\..\Parser\grammar1.c
 # End Source File
 # Begin Source File
 
@@ -451,15 +495,15 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\md5.c
+SOURCE=..\..\Modules\md5module.c
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\md5module.c
+SOURCE=..\..\Parser\metagrammar.c
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Parser\metagrammar.c
+SOURCE=..\..\Objects\memoryobject.c
 # End Source File
 # Begin Source File
 
@@ -547,6 +591,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\Python\pystrcmp.c
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\Python\pystrtod.c
 # End Source File
 # Begin Source File
@@ -567,10 +615,6 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\rgbimgmodule.c
-# End Source File
-# Begin Source File
-
 SOURCE=..\..\Modules\rotatingtree.c
 # End Source File
 # Begin Source File
@@ -587,7 +631,7 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Modules\shamodule.c
+SOURCE=..\..\Modules\sha1module.c
 # End Source File
 # Begin Source File
 
@@ -647,6 +691,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\Modules\zlib\uncompr.c
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\Objects\tupleobject.c
 # End Source File
 # Begin Source File

Modified: python/branches/py3k-importlib/PC/VC6/readme.txt
==============================================================================
--- python/branches/py3k-importlib/PC/VC6/readme.txt	(original)
+++ python/branches/py3k-importlib/PC/VC6/readme.txt	Thu Mar 27 00:48:05 2008
@@ -199,12 +199,10 @@
         http://www.activestate.com/Products/ActivePerl/
     as this is used by the OpenSSL build process.  Complain to them <wink>.
 
-    The MSVC project simply invokes PCBuild/build_ssl.py to perform
+    The MSVC project simply invokes PC/VC6/build_ssl.py to perform
     the build.  This Python script locates and builds your OpenSSL
     installation, then invokes a simple makefile to build the final .pyd.
 
-    Win9x users:  see "Win9x note" below.
-
     build_ssl.py attempts to catch the most common errors (such as not
     being able to find OpenSSL sources, or not being able to find a Perl
     that works with OpenSSL) and give a reasonable error message.
@@ -216,30 +214,6 @@
     build_ssl.py/MSVC isn't clever enough to clean OpenSSL - you must do
     this by hand.
 
-    Win9x note:  If, near the start of the build process, you see
-    something like
-
-        C:\Code\openssl-0.9.6g>set OPTS=no-asm
-        Out of environment space
-
-    then you're in trouble, and will probably also see these errors near
-    the end of the process:
-
-        NMAKE : fatal error U1073: don't know how to make
-            'crypto\md5\asm\m5_win32.asm'
-        Stop.
-        NMAKE : fatal error U1073: don't know how to make
-            'C:\Code\openssl-0.9.6g/out32/libeay32.lib'
-        Stop.
-
-    You need more environment space.  Win9x only has room for 256 bytes
-    by default, and especially after installing ActivePerl (which fiddles
-    the PATH envar), you're likely to run out.  KB Q230205
-
-        http://support.microsoft.com/default.aspx?scid=KB;en-us;q230205
-
-    explains how to edit CONFIG.SYS to cure this.
-
 
 YOUR OWN EXTENSION DLLs
 -----------------------

Modified: python/branches/py3k-importlib/PC/_msi.c
==============================================================================
--- python/branches/py3k-importlib/PC/_msi.c	(original)
+++ python/branches/py3k-importlib/PC/_msi.c	Thu Mar 27 00:48:05 2008
@@ -180,12 +180,12 @@
 
 static PyObject* fcicreate(PyObject* obj, PyObject* args)
 {
-    char *cabname;
+    char *cabname, *p;
     PyObject *files;
     CCAB ccab;
     HFCI hfci;
     ERF erf;
-    int i;
+    Py_ssize_t i;
 
 
     if (!PyArg_ParseTuple(args, "sO:FCICreate", &cabname, &files))
@@ -208,22 +208,22 @@
     ccab.setID = 0;
     ccab.szDisk[0] = '\0';
 
-    for (i=0; cabname[i]; i++)
-	if (cabname[i] == '\\' || cabname[i] == '/')
-	    break;
+    for (i = 0, p = cabname; *p; p = CharNext(p))
+	if (*p == '\\' || *p == '/')
+	    i = p - cabname + 1;
 
-    if (i > sizeof(ccab.szCabPath) ||
-	strlen(cabname+i) > sizeof(ccab.szCab)) {
+    if (i >= sizeof(ccab.szCabPath) ||
+	strlen(cabname+i) >= sizeof(ccab.szCab)) {
 	PyErr_SetString(PyExc_ValueError, "path name too long");
 	return 0;
     }
 
-    if (cabname[i]) {
+    if (i > 0) {
 	memcpy(ccab.szCabPath, cabname, i);
 	ccab.szCabPath[i] = '\0';
 	strcpy(ccab.szCab, cabname+i);
     } else {
-	strcpy(ccab.szCabPath, ".");
+	strcpy(ccab.szCabPath, ".\\");
 	strcpy(ccab.szCab, cabname);
     }
 
@@ -335,7 +335,7 @@
 static PyObject*
 record_getfieldcount(msiobj* record, PyObject* args)
 {
-    return PyInt_FromLong(MsiRecordGetFieldCount(record->h));
+    return PyLong_FromLong(MsiRecordGetFieldCount(record->h));
 }
 
 static PyObject*
@@ -502,7 +502,7 @@
 
     switch(type) {
 	case VT_I2: case VT_I4:
-	    return PyInt_FromLong(ival);
+	    return PyLong_FromLong(ival);
 	case VT_FILETIME:
 	    PyErr_SetString(PyExc_NotImplementedError, "FILETIME result");
 	    return NULL;
@@ -526,7 +526,7 @@
     if (status != ERROR_SUCCESS)
 	return msierror(status);
 
-    return PyInt_FromLong(result);
+    return PyLong_FromLong(result);
 }
 
 static PyObject*
@@ -542,9 +542,13 @@
     if (PyString_Check(data)) {
 	status = MsiSummaryInfoSetProperty(si->h, field, VT_LPSTR,
 	    0, NULL, PyString_AsString(data));
-    } else if (PyInt_CheckExact(data)) {
+    } else if (PyLong_CheckExact(data)) {
+	long value = PyLong_AsLong(data);
+	if (value == -1 && PyErr_Occurred()) {
+	    return NULL;
+	}
 	status = MsiSummaryInfoSetProperty(si->h, field, VT_I4,
-	    PyInt_AsLong(data), NULL, NULL);
+	    value, NULL, NULL);
     } else {
 	PyErr_SetString(PyExc_TypeError, "unsupported type");
 	return NULL;

Modified: python/branches/py3k-importlib/PC/_subprocess.c
==============================================================================
--- python/branches/py3k-importlib/PC/_subprocess.c	(original)
+++ python/branches/py3k-importlib/PC/_subprocess.c	Thu Mar 27 00:48:05 2008
@@ -79,7 +79,7 @@
 	self->handle = NULL;
 
 	/* note: return the current handle, as an integer */
-	return PyInt_FromLong((long) handle);
+	return PyLong_FromLong((long) handle);
 }
 
 static PyObject*
@@ -119,7 +119,7 @@
 static PyObject*
 sp_handle_as_int(sp_handle_object* self)
 {
-	return PyInt_FromLong((long) self->handle);
+	return PyLong_FromLong((long) self->handle);
 }
 
 static PyNumberMethods sp_handle_as_number;
@@ -164,7 +164,7 @@
 	}
 
 	/* note: returns integer, not handle object */
-	return PyInt_FromLong((long) handle);
+	return PyLong_FromLong((long) handle);
 }
 
 static PyObject *
@@ -253,7 +253,7 @@
 		PyErr_Clear(); /* FIXME: propagate error? */
 		return 0;
 	}
-	ret = (int) PyInt_AsLong(value);
+	ret = (int) PyLong_AsLong(value);
 	Py_DECREF(value);
 	return ret;
 }
@@ -269,7 +269,7 @@
 		PyErr_Clear(); /* FIXME: propagate error? */
 		return NULL;
 	}
-	if (Py_Type(value) != &sp_handle_type)
+	if (Py_TYPE(value) != &sp_handle_type)
 		ret = NULL;
 	else
 		ret = value->handle;
@@ -462,7 +462,7 @@
 	if (! result)
 		return PyErr_SetFromWindowsErr(GetLastError());
 
-	return PyInt_FromLong(exit_code);
+	return PyLong_FromLong(exit_code);
 }
 
 static PyObject *
@@ -484,7 +484,7 @@
 	if (result == WAIT_FAILED)
 		return PyErr_SetFromWindowsErr(GetLastError());
 
-	return PyInt_FromLong((int) result);
+	return PyLong_FromLong((int) result);
 }
 
 static PyObject *
@@ -493,7 +493,7 @@
 	if (! PyArg_ParseTuple(args, ":GetVersion"))
 		return NULL;
 
-	return PyInt_FromLong((int) GetVersion());
+	return PyLong_FromLong((int) GetVersion());
 }
 
 static PyObject *
@@ -534,7 +534,7 @@
 static void
 defint(PyObject* d, const char* name, int value)
 {
-	PyObject* v = PyInt_FromLong((long) value);
+	PyObject* v = PyLong_FromLong((long) value);
 	if (v) {
 		PyDict_SetItemString(d, (char*) name, v);
 		Py_DECREF(v);
@@ -552,7 +552,7 @@
 	PyObject *m;
 
 	/* patch up object descriptors */
-	Py_Type(&sp_handle_type) = &PyType_Type;
+	Py_TYPE(&sp_handle_type) = &PyType_Type;
 	sp_handle_as_number.nb_int = (unaryfunc) sp_handle_as_int;
 
 	m = Py_InitModule("_subprocess", sp_functions);

Modified: python/branches/py3k-importlib/PC/_winreg.c
==============================================================================
--- python/branches/py3k-importlib/PC/_winreg.c	(original)
+++ python/branches/py3k-importlib/PC/_winreg.c	Thu Mar 27 00:48:05 2008
@@ -46,6 +46,7 @@
 "DeleteValue() - Removes a named value from the specified registry key.\n"
 "EnumKey() - Enumerates subkeys of the specified open registry key.\n"
 "EnumValue() - Enumerates values of the specified open registry key.\n"
+"ExpandEnvironmentStrings() - Expand the env strings in a REG_EXPAND_SZ string.\n"
 "FlushKey() - Writes all the attributes of the specified key to the registry.\n"
 "LoadKey() - Creates a subkey under HKEY_USER or HKEY_LOCAL_MACHINE and stores\n"
 "            registration information from a specified file into that subkey.\n"
@@ -145,6 +146,9 @@
 " on the underlying registry type.\n"
 "data_type is an integer that identifies the type of the value data.");
 
+PyDoc_STRVAR(ExpandEnvironmentStrings_doc,
+"string = ExpandEnvironmentStrings(string) - Expand environment vars.\n");
+
 PyDoc_STRVAR(FlushKey_doc,
 "FlushKey(key) - Writes all the attributes of a key to the registry.\n"
 "\n"
@@ -503,9 +507,27 @@
 	return PyLong_FromVoidPtr(ret);
 }
 
+static PyObject *
+PyHKEY_Enter(PyObject *self)
+{
+	Py_XINCREF(self);
+	return self;
+}
+
+static PyObject *
+PyHKEY_Exit(PyObject *self, PyObject *args)
+{
+	if (!PyHKEY_Close(self))
+		return NULL;
+	Py_RETURN_NONE;
+}
+
+
 static struct PyMethodDef PyHKEY_methods[] = {
 	{"Close",  PyHKEY_CloseMethod, METH_VARARGS, PyHKEY_Close_doc},
 	{"Detach", PyHKEY_DetachMethod, METH_VARARGS, PyHKEY_Detach_doc},
+	{"__enter__", (PyCFunction)PyHKEY_Enter, METH_NOARGS, NULL},
+	{"__exit__", PyHKEY_Exit, METH_VARARGS, NULL},
 	{NULL}
 };
 
@@ -522,7 +544,7 @@
 		return PyLong_FromVoidPtr(((PyHKEYObject *)self)->hkey);
 	PyErr_Format(PyExc_AttributeError,
                      "'%.50s' object has no attribute '%.400s'",
-                     Py_Type(self)->tp_name, name);
+                     Py_TYPE(self)->tp_name, name);
 	return NULL;
 }
 
@@ -614,8 +636,8 @@
 		ok = PyHKEY_Close(obHandle);
 	}
 #if SIZEOF_LONG >= SIZEOF_HKEY
-	else if (PyInt_Check(obHandle)) {
-		long rc = RegCloseKey((HKEY)PyInt_AsLong(obHandle));
+	else if (PyLong_Check(obHandle)) {
+		long rc = RegCloseKey((HKEY)PyLong_AsLong(obHandle));
 		ok = (rc == ERROR_SUCCESS);
 		if (!ok)
 			PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
@@ -810,9 +832,9 @@
 	switch (typ) {
 		case REG_DWORD:
 			if (retDataSize == 0)
-				obData = PyInt_FromLong(0);
+				obData = PyLong_FromLong(0);
 			else
-				obData = PyInt_FromLong(*(int *)retDataBuf);
+				obData = PyLong_FromLong(*(int *)retDataBuf);
 			break;
 		case REG_SZ:
 		case REG_EXPAND_SZ:
@@ -1062,6 +1084,39 @@
 }
 
 static PyObject *
+PyExpandEnvironmentStrings(PyObject *self, PyObject *args)
+{
+	Py_UNICODE *retValue = NULL;
+	Py_UNICODE *src;
+	DWORD retValueSize;
+	DWORD rc;
+	PyObject *o;
+
+	if (!PyArg_ParseTuple(args, "u:ExpandEnvironmentStrings", &src))
+		return NULL;
+
+	retValueSize = ExpandEnvironmentStringsW(src, retValue, 0);
+	if (retValueSize == 0) {
+		return PyErr_SetFromWindowsErrWithFunction(retValueSize,
+						"ExpandEnvironmentStrings");
+	}
+	retValue = (Py_UNICODE *)PyMem_Malloc(retValueSize * sizeof(Py_UNICODE));
+	if (retValue == NULL) {
+		return PyErr_NoMemory();
+	}
+
+	rc = ExpandEnvironmentStringsW(src, retValue, retValueSize);
+	if (rc == 0) {
+		PyMem_Free(retValue);
+		return PyErr_SetFromWindowsErrWithFunction(retValueSize,
+						"ExpandEnvironmentStrings");
+	}
+	o = PyUnicode_FromUnicode(retValue, wcslen(retValue));
+	PyMem_Free(retValue);
+	return o;
+}
+
+static PyObject *
 PyFlushKey(PyObject *self, PyObject *args)
 {
 	HKEY hKey;
@@ -1346,6 +1401,8 @@
 	{"DeleteValue",      PyDeleteValue,     METH_VARARGS, DeleteValue_doc},
 	{"EnumKey",          PyEnumKey,         METH_VARARGS, EnumKey_doc},
 	{"EnumValue",        PyEnumValue,       METH_VARARGS, EnumValue_doc},
+	{"ExpandEnvironmentStrings", PyExpandEnvironmentStrings, METH_VARARGS,
+		ExpandEnvironmentStrings_doc },
 	{"FlushKey",         PyFlushKey,        METH_VARARGS, FlushKey_doc},
 	{"LoadKey",          PyLoadKey,         METH_VARARGS, LoadKey_doc},
 	{"OpenKey",          PyOpenKey,         METH_VARARGS, OpenKey_doc},
@@ -1362,7 +1419,7 @@
 static void
 insint(PyObject * d, char * name, long value)
 {
-	PyObject *v = PyInt_FromLong(value);
+	PyObject *v = PyLong_FromLong(value);
 	if (!v || PyDict_SetItemString(d, name, v))
 		PyErr_Clear();
 	Py_XDECREF(v);
@@ -1388,7 +1445,7 @@
 	if (m == NULL)
 		return;
 	d = PyModule_GetDict(m);
-	Py_Type(&PyHKEY_Type) = &PyType_Type;
+	Py_TYPE(&PyHKEY_Type) = &PyType_Type;
 	PyHKEY_Type.tp_doc = PyHKEY_doc;
 	Py_INCREF(&PyHKEY_Type);
 	if (PyDict_SetItemString(d, "HKEYType",

Modified: python/branches/py3k-importlib/PC/bdist_wininst/install.c
==============================================================================
--- python/branches/py3k-importlib/PC/bdist_wininst/install.c	(original)
+++ python/branches/py3k-importlib/PC/bdist_wininst/install.c	Thu Mar 27 00:48:05 2008
@@ -654,7 +654,7 @@
 	if (!Py_BuildValue || !PyArg_ParseTuple || !PyErr_Format)
 		return 1;
 
-	mod = PyImport_ImportModule("__builtin__");
+	mod = PyImport_ImportModule("builtins");
 	if (mod) {
 		int i;
 		g_PyExc_ValueError = PyObject_GetAttrString(mod, "ValueError");

Modified: python/branches/py3k-importlib/PC/config.c
==============================================================================
--- python/branches/py3k-importlib/PC/config.c	(original)
+++ python/branches/py3k-importlib/PC/config.c	Thu Mar 27 00:48:05 2008
@@ -14,9 +14,11 @@
 extern void initerrno(void);
 extern void initgc(void);
 extern void initmath(void);
+extern void init_md5(void);
 extern void initnt(void);
 extern void initoperator(void);
 extern void initsignal(void);
+extern void init_sha1(void);
 extern void init_sha256(void);
 extern void init_sha512(void);
 extern void inittime(void);
@@ -83,6 +85,8 @@
         {"nt", initnt}, /* Use the NT os functions, not posix */
         {"operator", initoperator},
         {"signal", initsignal},
+        {"_md5", init_md5},
+        {"_sha1", init_sha1},
         {"_sha256", init_sha256},
         {"_sha512", init_sha512},
         {"time", inittime},
@@ -139,7 +143,7 @@
 
         /* These entries are here for sys.builtin_module_names */
         {"__main__", NULL},
-        {"__builtin__", NULL},
+        {"builtins", NULL},
         {"sys", NULL},
         
         {"_types", init_types},

Modified: python/branches/py3k-importlib/PC/dl_nt.c
==============================================================================
--- python/branches/py3k-importlib/PC/dl_nt.c	(original)
+++ python/branches/py3k-importlib/PC/dl_nt.c	Thu Mar 27 00:48:05 2008
@@ -11,6 +11,7 @@
 #include "Python.h"
 #include "windows.h"
 
+#ifdef Py_ENABLE_SHARED
 char dllVersionBuffer[16] = ""; // a private buffer
 
 // Python Globals
@@ -35,3 +36,5 @@
 	}
 	return TRUE;
 }
+
+#endif /* Py_ENABLE_SHARED */

Modified: python/branches/py3k-importlib/PC/msvcrtmodule.c
==============================================================================
--- python/branches/py3k-importlib/PC/msvcrtmodule.c	(original)
+++ python/branches/py3k-importlib/PC/msvcrtmodule.c	Thu Mar 27 00:48:05 2008
@@ -74,7 +74,7 @@
 	if (flags == -1)
 		return PyErr_SetFromErrno(PyExc_IOError);
 
-	return PyInt_FromLong(flags);
+	return PyLong_FromLong(flags);
 }
 
 // Convert an OS file handle to a C runtime file descriptor.
@@ -92,7 +92,7 @@
 	if (fd == -1)
 		return PyErr_SetFromErrno(PyExc_IOError);
 
-	return PyInt_FromLong(fd);
+	return PyLong_FromLong(fd);
 }
 
 // Convert a C runtime file descriptor to an OS file handle.
@@ -126,7 +126,7 @@
 		return NULL;
 
 	ok = _kbhit();
-	return PyInt_FromLong(ok);
+	return PyLong_FromLong(ok);
 }
 
 static PyObject *
@@ -145,6 +145,24 @@
 	return PyString_FromStringAndSize(s, 1);
 }
 
+#if _MSC_VER >= 1300
+static PyObject *
+msvcrt_getwch(PyObject *self, PyObject *args)
+{
+	Py_UNICODE ch;
+	Py_UNICODE u[1];
+
+	if (!PyArg_ParseTuple(args, ":getwch"))
+		return NULL;
+
+	Py_BEGIN_ALLOW_THREADS
+	ch = _getwch();
+	Py_END_ALLOW_THREADS
+	u[0] = ch;
+	return PyUnicode_FromUnicode(u, 1);
+}
+#endif
+
 static PyObject *
 msvcrt_getche(PyObject *self, PyObject *args)
 {
@@ -161,6 +179,24 @@
 	return PyString_FromStringAndSize(s, 1);
 }
 
+#if _MSC_VER >= 1300
+static PyObject *
+msvcrt_getwche(PyObject *self, PyObject *args)
+{
+	Py_UNICODE ch;
+	Py_UNICODE s[1];
+
+	if (!PyArg_ParseTuple(args, ":getwche"))
+		return NULL;
+
+	Py_BEGIN_ALLOW_THREADS
+	ch = _getwche();
+	Py_END_ALLOW_THREADS
+	s[0] = ch;
+	return PyUnicode_FromUnicode(s, 1);
+}
+#endif
+
 static PyObject *
 msvcrt_putch(PyObject *self, PyObject *args)
 {
@@ -174,6 +210,28 @@
 	return Py_None;
 }
 
+
+#if _MSC_VER >= 1300
+static PyObject *
+msvcrt_putwch(PyObject *self, PyObject *args)
+{
+	Py_UNICODE *ch;
+	int size;
+
+	if (!PyArg_ParseTuple(args, "u#:putwch", &ch, &size))
+		return NULL;
+
+	if (size == 0) {
+		PyErr_SetString(PyExc_ValueError,
+			"Expected unicode string of length 1");
+		return NULL;
+	}
+	_putwch(*ch);
+	Py_RETURN_NONE;
+
+}
+#endif
+
 static PyObject *
 msvcrt_ungetch(PyObject *self, PyObject *args)
 {
@@ -188,11 +246,26 @@
 	return Py_None;
 }
 
+#if _MSC_VER >= 1300
+static PyObject *
+msvcrt_ungetwch(PyObject *self, PyObject *args)
+{
+	Py_UNICODE ch;
+
+	if (!PyArg_ParseTuple(args, "u:ungetwch", &ch))
+		return NULL;
+
+	if (_ungetch(ch) == EOF)
+		return PyErr_SetFromErrno(PyExc_IOError);
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+#endif
 
 static void
 insertint(PyObject *d, char *name, int value)
 {
-	PyObject *v = PyInt_FromLong((long) value);
+	PyObject *v = PyLong_FromLong((long) value);
 	if (v == NULL) {
 		/* Don't bother reporting this error */
 		PyErr_Clear();
@@ -214,7 +287,7 @@
 	if (!PyArg_ParseTuple(args, "ii", &type, &file))
 		return NULL;
 	res = _CrtSetReportFile(type, (_HFILE)file);
-	return PyInt_FromLong((long)res);
+	return PyLong_FromLong((long)res);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
@@ -276,6 +349,12 @@
 	{"CrtSetReportMode",	msvcrt_setreportmode, METH_VARARGS},
 	{"set_error_mode",	msvcrt_seterrormode, METH_VARARGS},
 #endif
+#if _MSC_VER >= 1300
+	{"getwch",		msvcrt_getwch, METH_VARARGS},
+	{"getwche",		msvcrt_getwche, METH_VARARGS},
+	{"putwch",		msvcrt_putwch, METH_VARARGS},
+	{"ungetwch",		msvcrt_ungetwch, METH_VARARGS},
+#endif
 	{NULL,			NULL}
 };
 

Modified: python/branches/py3k-importlib/PC/os2emx/Makefile
==============================================================================
--- python/branches/py3k-importlib/PC/os2emx/Makefile	(original)
+++ python/branches/py3k-importlib/PC/os2emx/Makefile	Thu Mar 27 00:48:05 2008
@@ -1,16 +1,16 @@
 #####################==================----------------
 #
-# Top-Level Makefile for Building Python 2.4 for OS/2 using GCC/EMX
+# Top-Level Makefile for Building Python 2.6 for OS/2 using GCC/EMX
 # Originally written by Andrew Zabolotny, <bit at eltech.ru> for Python 1.5.2
-# Modified by Andrew MacIntyre, <andymac at pcug.org.au> for Python 2.5
+# Modified by Andrew MacIntyre, <andymac at pcug.org.au> for Python 2.6
 #
 # This makefile was developed for use with [P]GCC/EMX compiler any
 # version and GNU Make.
 #
-# The output of the build is a largish Python25.DLL containing the
+# The output of the build is a largish Python26.DLL containing the
 # essential modules of Python and a small Python.exe program to start
 # the interpreter. When embedding Python within another program, only
-# Python25.DLL is needed. We also build python_s.a static library (which
+# Python26.DLL is needed. We also build python_s.a static library (which
 # can be converted into OMF (.lib) format using emxomf tool) and both
 # python.a and python.lib import libraries.  Then the optional 
 # extension modules, which are OS/2 DLLs renamed with a PYD file extension.
@@ -64,7 +64,7 @@
 
 # === install locations ===
 # default value of PYTHONHOME
-LIB_DIR=C:/Python25
+LIB_DIR=C:/Python26
 # default is to have everything in or under PYTHONHOME
 EXE_DIR=$(LIB_DIR)
 DLL_DIR=$(EXE_DIR)
@@ -236,8 +236,8 @@
 	@echo STACKSIZE 2097152 >>$@
 
 # Output file names
-PYTHON_VER=	2.5
-PYTHON_LIB=	python25
+PYTHON_VER=	2.6
+PYTHON_LIB=	python26
 PYTHON.LIB=	$(PYTHON_LIB)_s$A
 PYTHON.IMPLIB=	$(PYTHON_LIB)$A
 ifeq ($(EXEOMF),yes)

Modified: python/branches/py3k-importlib/PC/os2emx/README.os2emx
==============================================================================
--- python/branches/py3k-importlib/PC/os2emx/README.os2emx	(original)
+++ python/branches/py3k-importlib/PC/os2emx/README.os2emx	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,4 @@
-This is a port of Python 2.5 to OS/2 using the EMX development tools
+This is a port of Python 2.6 to OS/2 using the EMX development tools
 =========================================================================
 
 What's new since the previous release
@@ -10,11 +10,11 @@
 Licenses and info about Python and EMX
 --------------------------------------
 
-Please read the file README.Python-2.5 included in this package for 
-information about Python 2.5.  This file is the README file from the 
-Python 2.5 source distribution available via http://www.python.org/ 
-and its mirrors.  The file LICENCE.Python-2.5 is the text of the Licence 
-from the Python 2.5 source distribution.
+Please read the file README.Python-2.6 included in this package for 
+information about Python 2.6.  This file is the README file from the 
+Python 2.6 source distribution available via http://www.python.org/ 
+and its mirrors.  The file LICENCE.Python-2.6 is the text of the Licence 
+from the Python 2.6 source distribution.
 
 Note that the EMX package that this package depends on is released under 
 the GNU General Public Licence.  Please refer to the documentation 
@@ -46,7 +46,7 @@
 
 The best known would be that by Jeff Rush, most recently of version 
 1.5.2.  Jeff used IBM's Visual Age C++ (v3) for his ports, and his 
-patches have been included in the Python 2.5 source distribution.
+patches have been included in the Python 2.6 source distribution.
 
 Andy Zabolotny implemented a port of Python v1.5.2 using the EMX 
 development tools.  His patches against the Python v1.5.2 source 
@@ -92,7 +92,7 @@
 to compile & link the executable.  This is so that fork() works (see 
 "YOU HAVE BEEN WARNED" item 1).
 
-Python25.dll is created as a normal OMF DLL, with an OMF import 
+Python26.dll is created as a normal OMF DLL, with an OMF import 
 library and module definition file.  There is also an a.out (.a) import 
 library to support linking the DLL to a.out executables.  The DLL 
 requires the EMX runtime DLLs.
@@ -148,7 +148,7 @@
 
 Upstream source patches:
 
-No updates to the Python 2.5 release have become available.
+No updates to the Python 2.6 release have become available.
 
 Eberhard Mattes' EMXFIX04 update to his EMX 0.9d tools suite includes 
 bug fixes for the BSD DB library.  The bsddb module included in this 
@@ -157,7 +157,7 @@
 Library and other distributed Python code:
 
 The Python standard library lives in the Lib directory.  All the standard 
-library code included with the Python 2.5 source distribution is included 
+library code included with the Python 2.6 source distribution is included 
 in the binary archive, with the exception of the dos-8x3 and tkinter 
 subdirectories which have been omitted to reduce the size of the binary 
 archive - the dos-8x3 components are unnecessary duplicates and Tkinter 
@@ -172,7 +172,7 @@
 also been omitted.
 
 All subdirectories omitted from the binary archive can be reconstituted 
-from the Python 2.5 source distribution, if desired.
+from the Python 2.6 source distribution, if desired.
 
 Support for building Python extensions:
 
@@ -190,15 +190,15 @@
 ---------
 
 This port is packaged as follows:
-- python-2.5-os2emx-bin-03????.zip  (binaries, library modules)
-- python-2.5-os2emx-src-03????      (patches+makefiles for non-Python code)
+- python-2.6-os2emx-bin-03????.zip  (binaries, library modules)
+- python-2.6-os2emx-src-03????      (patches+makefiles for non-Python code)
 
 As all the Python specific patches for the port are now part of the 
 Python release tarball, only the patches and makefiles involved in 
 building external libraries for optional extensions are included in 
 the source archive.
 
-Documentation for the Python language, as well as the Python 2.5 
+Documentation for the Python language, as well as the Python 2.6 
 source distibution, can be obtained from the Python website 
 (http://www.python.org/) or the Python project pages at Sourceforge 
 (http://sf.net/projects/python/).
@@ -213,7 +213,7 @@
 Unpack this archive, preserving the subdirectories, in the root directory 
 of the drive where you want Python to live.
 
-Add the Python directory (eg C:\Python25) to the PATH and LIBPATH 
+Add the Python directory (eg C:\Python26) to the PATH and LIBPATH 
 variables in CONFIG.SYS.
 
 You should then set the PYTHONHOME and PYTHONPATH environment variables 
@@ -223,9 +223,9 @@
 should be set to the semicolon separated list of principal Python library 
 directories.
 I use:
-  SET PYTHONHOME=F:/Python25
-  SET PYTHONPATH=F:/Python25/Lib;F:/Python25/Lib/plat-os2emx;
-                 F:/Python25/Lib/lib-dynload;F:/Python25/Lib/site-packages
+  SET PYTHONHOME=F:/Python26
+  SET PYTHONPATH=F:/Python26/Lib;F:/Python26/Lib/plat-os2emx;
+                 F:/Python26/Lib/lib-dynload;F:/Python26/Lib/site-packages
 
 NOTE!:  the PYTHONPATH setting above is linewrapped for this document - it 
 should all be on one line in CONFIG.SYS!
@@ -238,7 +238,7 @@
 distribution.  This can be used by setting the TERMINFO environment variable 
 to the path of the Terminfo subdirectory below the Python home directory.
 On my system this looks like:
-  SET TERMINFO=F:/Python25/Terminfo
+  SET TERMINFO=F:/Python26/Terminfo
 
 For the TERM environment variable, I would try one of the following:
   SET TERM=ansi
@@ -252,8 +252,8 @@
 you can change into the Python home directory and run the COMPILEALL.CMD 
 batch file.
 
-You can execute the regression tests included with the Python 2.5 source 
-distribution by changing to the Python 2.5 home directory and executing the 
+You can execute the regression tests included with the Python 2.6 source 
+distribution by changing to the Python 2.6 home directory and executing the 
 REGRTEST.CMD batch file.  The following tests are known to fail at this 
 time:
 - test_mhlib (I don't know of any port of MH to OS/2);
@@ -299,7 +299,7 @@
 1. decide if you need to change the location of the Python installation.
    If you wish to do this, set the value of the Makefile variable LIB_DIR 
    to the directory you wish to use for PYTHONHOME 
-   (eg /usr/local/lib/python2.5).
+   (eg /usr/local/lib/python2.6).
 
    If you want Python to find its library without the PYTHONHOME 
    environment variable set, set the value of the Makefile variable 
@@ -309,7 +309,7 @@
    to be installed in a directory other than the PYTHONHOME directory, set 
    the value of the Makefile variable EXE_DIR to the appropriate directory.
 
-3. If you wish the Python core DLL (python25.dll) to be installed in a 
+3. If you wish the Python core DLL (python26.dll) to be installed in a 
    directory other than the directory in which the Python executables are 
    installed (by default, the PYTHONHOME directory), set the value of the 
    Makefile variable DLL_DIR to the appropriate directory.  This DLL must 
@@ -698,4 +698,4 @@
 E-mail: andymac at bullseye.apana.org.au, or andymac at pcug.org.au
 Web:    http://www.andymac.org/
 
-23 July, 2006.
+28 January, 2008.

Modified: python/branches/py3k-importlib/PC/os2emx/config.c
==============================================================================
--- python/branches/py3k-importlib/PC/os2emx/config.c	(original)
+++ python/branches/py3k-importlib/PC/os2emx/config.c	Thu Mar 27 00:48:05 2008
@@ -156,7 +156,7 @@
 
 	/* These entries are here for sys.builtin_module_names */
 	{"__main__", NULL},
-	{"__builtin__", NULL},
+	{"builtins", NULL},
 	{"sys", NULL},
 
 	/* This lives in gcmodule.c */

Modified: python/branches/py3k-importlib/PC/os2emx/pyconfig.h
==============================================================================
--- python/branches/py3k-importlib/PC/os2emx/pyconfig.h	(original)
+++ python/branches/py3k-importlib/PC/os2emx/pyconfig.h	Thu Mar 27 00:48:05 2008
@@ -58,7 +58,6 @@
 #define WITH_DOC_STRINGS 1
 
 /* Unicode related */
-#define Py_USING_UNICODE 1
 #define PY_UNICODE_TYPE	wchar_t
 #define Py_UNICODE_SIZE SIZEOF_SHORT
 

Deleted: /python/branches/py3k-importlib/PC/os2emx/python25.def
==============================================================================
--- /python/branches/py3k-importlib/PC/os2emx/python25.def	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,1263 +0,0 @@
-LIBRARY python25 INITINSTANCE TERMINSTANCE 
-DESCRIPTION "Python 2.5 Core DLL" 
-PROTMODE 
-DATA MULTIPLE NONSHARED 
-EXPORTS 
-
-; From python25_s.lib(config)
-  "_PyImport_Inittab"
-
-; From python25_s.lib(dlfcn)
-;  "dlopen"
-;  "dlsym"
-;  "dlclose"
-;  "dlerror"
-
-; From python25_s.lib(getpathp)
-  "Py_GetProgramFullPath"
-  "Py_GetPrefix"
-  "Py_GetExecPrefix"
-  "Py_GetPath"
-
-; From python25_s.lib(getbuildinfo)
-  "Py_GetBuildInfo"
-  "_Py_svnversion"
-
-; From python25_s.lib(main)
-  "Py_Main"
-  "Py_GetArgcArgv"
-
-; From python25_s.lib(acceler)
-  "PyGrammar_AddAccelerators"
-  "PyGrammar_RemoveAccelerators"
-
-; From python25_s.lib(grammar1)
-  "PyGrammar_FindDFA"
-  "PyGrammar_LabelRepr"
-
-; From python25_s.lib(listnode)
-  "PyNode_ListTree"
-
-; From python25_s.lib(node)
-  "PyNode_New"
-  "PyNode_AddChild"
-  "PyNode_Free"
-
-; From python25_s.lib(parser)
-  "PyParser_AddToken"
-  "PyParser_New"
-  "PyParser_Delete"
-
-; From python25_s.lib(parsetok)
-  "Py_TabcheckFlag"
-  "PyParser_ParseString"
-  "PyParser_ParseStringFlagsFilename"
-  "PyParser_ParseFile"
-  "PyParser_ParseFileFlags"
-  "PyParser_ParseStringFlags"
-
-; From python25_s.lib(bitset)
-  "_Py_newbitset"
-  "_Py_delbitset"
-  "_Py_addbit"
-  "_Py_samebitset"
-  "_Py_mergebitset"
-
-; From python25_s.lib(metagrammar)
-  "_Py_meta_grammar"
-  "Py_meta_grammar"
-
-; From python25_s.lib(tokenizer)
-  "PyToken_OneChar"
-  "PyToken_TwoChars"
-  "PyToken_ThreeChars"
-  "PyTokenizer_FromString"
-  "PyTokenizer_Free"
-  "PyTokenizer_FromFile"
-  "PyTokenizer_Get"
-  "_PyParser_TokenNames"
-
-; From python25_s.lib(myreadline)
-  "_PyOS_ReadlineTState"
-  "PyOS_ReadlineFunctionPointer"
-  "PyOS_StdioReadline"
-  "PyOS_Readline"
-  "PyOS_InputHook"
-
-; From python25_s.lib(abstract)
-  "_PyObject_LengthHint"
-  "PyMapping_Size"
-  "PyObject_CallMethod"
-  "PyObject_GetItem"
-  "PySequence_GetItem"
-  "PyObject_SetItem"
-  "PySequence_SetItem"
-  "PyObject_DelItem"
-  "PySequence_DelItem"
-  "PyNumber_Multiply"
-  "PyNumber_InPlaceAdd"
-  "PyNumber_InPlaceMultiply"
-  "PyNumber_Int"
-  "PyNumber_Long"
-  "PyNumber_Float"
-  "PySequence_Concat"
-  "PySequence_Repeat"
-  "PySequence_InPlaceConcat"
-  "PySequence_InPlaceRepeat"
-  "PySequence_GetSlice"
-  "PySequence_SetSlice"
-  "PySequence_Tuple"
-  "PyObject_GetIter"
-  "PyIter_Next"
-  "PySequence_Fast"
-  "_PySequence_IterSearch"
-  "PyObject_CallFunction"
-  "_PyObject_CallFunction_SizeT"
-  "_PyObject_CallMethod_SizeT"
-  "PyObject_CallMethodObjArgs"
-  "PyObject_CallFunctionObjArgs"
-  "PyObject_Cmp"
-  "PyObject_Call"
-  "PyObject_CallObject"
-  "PyObject_Type"
-  "PyObject_Size"
-  "PyObject_Length"
-  "PyObject_DelItemString"
-  "PyObject_AsCharBuffer"
-  "PyObject_CheckReadBuffer"
-  "PyObject_AsReadBuffer"
-  "PyObject_AsWriteBuffer"
-  "PyNumber_Check"
-  "PyNumber_Add"
-  "PyNumber_Subtract"
-  "PyNumber_Divide"
-  "PyNumber_FloorDivide"
-  "PyNumber_TrueDivide"
-  "PyNumber_Remainder"
-  "PyNumber_Divmod"
-  "PyNumber_Power"
-  "PyNumber_Negative"
-  "PyNumber_Positive"
-  "PyNumber_Absolute"
-  "PyNumber_Invert"
-  "PyNumber_Lshift"
-  "PyNumber_Rshift"
-  "PyNumber_And"
-  "PyNumber_Xor"
-  "PyNumber_Or"
-  "PyNumber_Index"
-  "PyNumber_InPlaceSubtract"
-  "PyNumber_InPlaceDivide"
-  "PyNumber_InPlaceFloorDivide"
-  "PyNumber_InPlaceTrueDivide"
-  "PyNumber_InPlaceRemainder"
-  "PyNumber_InPlacePower"
-  "PyNumber_InPlaceLshift"
-  "PyNumber_InPlaceRshift"
-  "PyNumber_InPlaceAnd"
-  "PyNumber_InPlaceXor"
-  "PyNumber_InPlaceOr"
-  "PySequence_Check"
-  "PySequence_Size"
-  "PySequence_Length"
-  "PySequence_DelSlice"
-  "PySequence_List"
-  "PySequence_Count"
-  "PySequence_Contains"
-  "PySequence_In"
-  "PySequence_Index"
-  "PyMapping_Check"
-  "PyMapping_Length"
-  "PyMapping_HasKeyString"
-  "PyMapping_HasKey"
-  "PyMapping_GetItemString"
-  "PyMapping_SetItemString"
-  "PyObject_IsInstance"
-  "PyObject_IsSubclass"
-
-; From python25_s.lib(boolobject)
-  "PyBool_FromLong"
-  "PyBool_Type"
-  "_Py_ZeroStruct"
-  "_Py_TrueStruct"
-
-; From python25_s.lib(cellobject)
-  "PyCell_New"
-  "PyCell_Get"
-  "PyCell_Set"
-  "PyCell_Type"
-
-; From python25_s.lib(classobject)
-  "PyClass_New"
-  "PyClass_IsSubclass"
-  "PyInstance_New"
-  "PyInstance_NewRaw"
-  "PyMethod_New"
-  "PyMethod_Function"
-  "PyMethod_Self"
-  "PyMethod_Class"
-  "_PyInstance_Lookup"
-  "PyMethod_Fini"
-  "PyClass_Type"
-  "PyInstance_Type"
-  "PyMethod_Type"
-
-; From python25_s.lib(cobject)
-  "PyCObject_FromVoidPtr"
-  "PyCObject_FromVoidPtrAndDesc"
-  "PyCObject_AsVoidPtr"
-  "PyCObject_GetDesc"
-  "PyCObject_Import"
-  "PyCObject_SetVoidPtr"
-  "PyCObject_Type"
-
-; From python25_s.lib(codeobject)
-  "PyCode_New"
-  "PyCode_Addr2Line"
-  "PyCode_CheckLineNumber"
-  "PyCode_Type"
-
-; From python25_s.lib(complexobject)
-  "_Py_c_pow"
-  "_Py_c_sum"
-  "_Py_c_diff"
-  "_Py_c_neg"
-  "_Py_c_prod"
-  "_Py_c_quot"
-  "PyComplex_FromCComplex"
-  "PyComplex_FromDoubles"
-  "PyComplex_RealAsDouble"
-  "PyComplex_ImagAsDouble"
-  "PyComplex_AsCComplex"
-  "PyComplex_Type"
-
-; From python25_s.lib(descrobject)
-  "PyWrapper_New"
-  "PyDescr_NewMethod"
-  "PyDescr_NewClassMethod"
-  "PyDescr_NewMember"
-  "PyDescr_NewGetSet"
-  "PyDescr_NewWrapper"
-  "PyDictProxy_New"
-  "PyWrapperDescr_Type"
-  "PyProperty_Type"
-
-; From python25_s.lib(dictobject)
-  "PyDict_New"
-  "PyDict_GetItem"
-  "PyDict_SetItem"
-  "PyDict_DelItem"
-  "PyDict_Clear"
-  "PyDict_MergeFromSeq2"
-  "PyDict_Merge"
-  "PyDict_Keys"
-  "PyDict_Values"
-  "PyDict_Contains"
-  "PyDict_Next"
-  "PyDict_Items"
-  "PyDict_Size"
-  "PyDict_Copy"
-  "PyDict_Update"
-  "PyDict_GetItemString"
-  "PyDict_SetItemString"
-  "PyDict_DelItemString"
-  "PyDict_Type"
-  "PyDictIterKey_Type"
-  "PyDictIterValue_Type"
-  "PyDictIterItem_Type"
-
-; From python25_s.lib(enumobject)
-  "PyEnum_Type"
-  "PyReversed_Type"
-
-; From python25_s.lib(fileobject)
-  "PyFile_FromString"
-  "Py_UniversalNewlineFread"
-  "PyFile_GetLine"
-  "PyFile_SoftSpace"
-  "PyFile_WriteObject"
-  "PyFile_WriteString"
-  "PyObject_AsFileDescriptor"
-  "Py_UniversalNewlineFgets"
-  "PyFile_SetBufSize"
-  "PyFile_SetEncoding"
-  "PyFile_FromFile"
-  "PyFile_AsFile"
-  "PyFile_Name"
-  "PyFile_Type"
-
-; From python25_s.lib(floatobject)
-  "PyFloat_FromString"
-  "PyFloat_AsDouble"
-  "PyFloat_Fini"
-  "_PyFloat_Pack4"
-  "_PyFloat_Pack8"
-  "_PyFloat_Unpack4"
-  "_PyFloat_Unpack8"
-  "PyFloat_FromDouble"
-  "PyFloat_AsReprString"
-  "PyFloat_AsString"
-  "_PyFloat_Init"
-  "PyFloat_AsStringEx"
-  "PyFloat_Type"
-
-; From python25_s.lib(frameobject)
-  "PyFrame_New"
-  "PyFrame_FastToLocals"
-  "PyFrame_LocalsToFast"
-  "_PyFrame_Init"
-  "PyFrame_Fini"
-  "PyFrame_BlockSetup"
-  "PyFrame_BlockPop"
-  "PyFrame_Type"
-
-; From python25_s.lib(funcobject)
-  "PyFunction_New"
-  "PyFunction_GetCode"
-  "PyFunction_GetGlobals"
-  "PyFunction_GetModule"
-  "PyFunction_GetDefaults"
-  "PyFunction_SetDefaults"
-  "PyFunction_GetClosure"
-  "PyFunction_SetClosure"
-  "PyClassMethod_New"
-  "PyStaticMethod_New"
-  "PyFunction_Type"
-  "PyClassMethod_Type"
-  "PyStaticMethod_Type"
-
-; From python25_s.lib(genobject)
-  "PyGen_New"
-  "PyGen_NeedsFinalizing"
-  "PyGen_Type"
-
-; From python25_s.lib(iterobject)
-  "PySeqIter_New"
-  "PyCallIter_New"
-  "PySeqIter_Type"
-  "PyCallIter_Type"
-
-; From python25_s.lib(listobject)
-  "PyList_New"
-  "PyList_Append"
-  "PyList_Size"
-  "PyList_GetItem"
-  "PyList_SetItem"
-  "PyList_Insert"
-  "PyList_GetSlice"
-  "PyList_SetSlice"
-  "PyList_Sort"
-  "PyList_Reverse"
-  "PyList_AsTuple"
-  "_PyList_Extend"
-  "PyList_Fini"
-  "PyList_Type"
-  "PyListIter_Type"
-  "PyListRevIter_Type"
-
-; From python25_s.lib(longobject)
-  "PyLong_FromDouble"
-  "PyLong_AsLong"
-  "_PyLong_AsSsize_t"
-  "PyLong_AsUnsignedLong"
-  "_PyLong_FromByteArray"
-  "_PyLong_AsByteArray"
-  "PyLong_AsDouble"
-  "PyLong_FromLongLong"
-  "PyLong_AsLongLong"
-  "PyLong_FromString"
-  "PyLong_FromLong"
-  "PyLong_FromUnsignedLong"
-  "PyLong_AsUnsignedLongMask"
-  "_PyLong_FromSize_t"
-  "_PyLong_FromSsize_t"
-  "_PyLong_AsScaledDouble"
-  "PyLong_FromVoidPtr"
-  "PyLong_AsVoidPtr"
-  "PyLong_FromUnsignedLongLong"
-  "PyLong_AsUnsignedLongLong"
-  "PyLong_AsUnsignedLongLongMask"
-  "PyLong_FromUnicode"
-  "_PyLong_Sign"
-  "_PyLong_NumBits"
-  "_PyLong_New"
-  "_PyLong_Copy"
-  "PyLong_Type"
-  "_PyLong_DigitValue"
-
-; From python25_s.lib(methodobject)
-  "PyCFunction_Call"
-  "Py_FindMethodInChain"
-  "PyCFunction_GetFunction"
-  "PyCFunction_GetSelf"
-  "PyCFunction_GetFlags"
-  "Py_FindMethod"
-  "PyCFunction_NewEx"
-  "PyCFunction_Fini"
-  "PyCFunction_New"
-  "PyCFunction_Type"
-
-; From python25_s.lib(moduleobject)
-  "PyModule_New"
-  "_PyModule_Clear"
-  "PyModule_GetDict"
-  "PyModule_GetName"
-  "PyModule_GetFilename"
-  "PyModule_Type"
-
-; From python25_s.lib(object)
-  "Py_DivisionWarningFlag"
-  "PyObject_Str"
-  "PyObject_Repr"
-  "_PyObject_Str"
-  "PyObject_Unicode"
-  "PyObject_GetAttr"
-  "PyObject_IsTrue"
-  "PyNumber_CoerceEx"
-  "PyObject_Compare"
-  "PyObject_RichCompare"
-  "_Py_HashDouble"
-  "PyObject_Hash"
-  "PyObject_SetAttr"
-  "PyObject_GenericGetAttr"
-  "PyObject_GenericSetAttr"
-  "PyCallable_Check"
-  "PyObject_Dir"
-  "PyMem_Malloc"
-  "PyMem_Realloc"
-  "PyMem_Free"
-  "PyObject_Print"
-  "_PyObject_Dump"
-  "PyObject_RichCompareBool"
-  "PyObject_GetAttrString"
-  "PyObject_SetAttrString"
-  "PyObject_HasAttrString"
-  "PyObject_HasAttr"
-  "_PyObject_GetDictPtr"
-  "PyObject_SelfIter"
-  "PyObject_Not"
-  "PyNumber_Coerce"
-  "Py_ReprEnter"
-  "Py_ReprLeave"
-  "_Py_HashPointer"
-  "Py_IncRef"
-  "Py_DecRef"
-  "_PyTrash_deposit_object"
-  "_PyTrash_destroy_chain"
-  "PyObject_Init"
-  "PyObject_InitVar"
-  "_PyObject_New"
-  "_PyObject_NewVar"
-  "_Py_ReadyTypes"
-  "_Py_SwappedOp"
-  "_Py_NotImplementedStruct"
-  "_Py_NoneStruct"
-  "_Py_cobject_hack"
-  "_Py_abstract_hack"
-  "_PyTrash_delete_nesting"
-  "_PyTrash_delete_later"
-
-; From python25_s.lib(obmalloc)
-  "PyObject_Malloc"
-  "PyObject_Free"
-  "PyObject_Realloc"
-
-; From python25_s.lib(rangeobject)
-  "PyRange_Type"
-
-; From python25_s.lib(setobject)
-  "PySet_Pop"
-  "PySet_New"
-  "PyFrozenSet_New"
-  "PySet_Size"
-  "PySet_Clear"
-  "PySet_Contains"
-  "PySet_Discard"
-  "PySet_Add"
-  "_PySet_Next"
-  "_PySet_Update"
-  "PySet_Fini"
-  "PySet_Type"
-  "PyFrozenSet_Type"
-
-; From python25_s.lib(sliceobject)
-  "_PySlice_FromIndices"
-  "PySlice_GetIndices"
-  "PySlice_GetIndicesEx"
-  "PySlice_New"
-  "_Py_EllipsisObject"
-  "PySlice_Type"
-
-; From python25_s.lib(stringobject)
-  "PyString_FromStringAndSize"
-  "PyString_InternInPlace"
-  "PyString_FromString"
-  "PyString_FromFormatV"
-  "PyString_AsString"
-  "_PyString_Resize"
-  "PyString_FromFormat"
-  "PyString_AsDecodedString"
-  "PyString_AsEncodedString"
-  "PyString_DecodeEscape"
-  "PyString_Repr"
-  "PyString_AsStringAndSize"
-  "_PyString_FormatLong"
-  "PyString_Format"
-  "_Py_ReleaseInternedStrings"
-  "PyString_Size"
-  "PyString_Concat"
-  "PyString_ConcatAndDel"
-  "_PyString_Eq"
-  "PyString_InternImmortal"
-  "PyString_InternFromString"
-  "_PyString_Join"
-  "PyString_Decode"
-  "PyString_Encode"
-  "PyString_AsEncodedObject"
-  "PyString_AsDecodedObject"
-  "PyString_Fini"
-  "PyString_Type"
-  "PyBaseString_Type"
-
-; From python25_s.lib(structseq)
-  "PyStructSequence_InitType"
-  "PyStructSequence_New"
-  "PyStructSequence_UnnamedField"
-
-; From python25_s.lib(tupleobject)
-  "PyTuple_New"
-  "PyTuple_Pack"
-  "_PyTuple_Resize"
-  "PyTuple_Size"
-  "PyTuple_GetItem"
-  "PyTuple_SetItem"
-  "PyTuple_GetSlice"
-  "PyTuple_Fini"
-  "PyTuple_Type"
-  "PyTupleIter_Type"
-
-; From python25_s.lib(typeobject)
-  "PyType_IsSubtype"
-  "_PyType_Lookup"
-  "PyType_Ready"
-  "PyType_GenericAlloc"
-  "_PyObject_SlotCompare"
-  "PyType_GenericNew"
-  "PyType_Type"
-  "PyBaseObject_Type"
-  "PySuper_Type"
-
-; From python25_s.lib(unicodeobject)
-  "PyUnicodeUCS2_Resize"
-  "PyUnicodeUCS2_FromOrdinal"
-  "PyUnicodeUCS2_FromObject"
-  "PyUnicodeUCS2_FromEncodedObject"
-  "PyUnicodeUCS2_Decode"
-  "PyUnicodeUCS2_GetDefaultEncoding"
-  "PyUnicodeUCS2_DecodeUTF8"
-  "PyUnicodeUCS2_DecodeLatin1"
-  "PyUnicodeUCS2_DecodeASCII"
-  "PyUnicodeUCS2_AsEncodedString"
-  "PyUnicodeUCS2_AsUTF8String"
-  "PyUnicodeUCS2_AsLatin1String"
-  "PyUnicodeUCS2_AsASCIIString"
-  "PyUnicode_DecodeUTF7"
-  "PyUnicode_EncodeUTF7"
-  "PyUnicodeUCS2_DecodeUTF8Stateful"
-  "PyUnicodeUCS2_EncodeUTF8"
-  "PyUnicodeUCS2_DecodeUTF16Stateful"
-  "PyUnicodeUCS2_AsUTF16String"
-  "PyUnicodeUCS2_DecodeUnicodeEscape"
-  "PyUnicodeUCS2_DecodeRawUnicodeEscape"
-  "PyUnicodeUCS2_EncodeRawUnicodeEscape"
-  "_PyUnicode_DecodeUnicodeInternal"
-  "PyUnicodeUCS2_DecodeCharmap"
-  "PyUnicode_BuildEncodingMap"
-  "PyUnicodeUCS2_EncodeCharmap"
-  "PyUnicodeUCS2_TranslateCharmap"
-  "PyUnicodeUCS2_EncodeDecimal"
-  "PyUnicodeUCS2_Count"
-  "PyUnicodeUCS2_Find"
-  "PyUnicodeUCS2_Join"
-  "PyUnicodeUCS2_Splitlines"
-  "PyUnicodeUCS2_Compare"
-  "PyUnicodeUCS2_Contains"
-  "PyUnicodeUCS2_Concat"
-  "_PyUnicode_XStrip"
-  "PyUnicodeUCS2_Replace"
-  "PyUnicodeUCS2_Split"
-  "PyUnicodeUCS2_RSplit"
-  "PyUnicodeUCS2_Format"
-  "_PyUnicodeUCS2_Init"
-  "_PyUnicodeUCS2_Fini"
-  "PyUnicodeUCS2_FromUnicode"
-  "PyUnicodeUCS2_AsUnicode"
-  "PyUnicodeUCS2_GetSize"
-  "PyUnicodeUCS2_GetMax"
-  "_PyUnicodeUCS2_AsDefaultEncodedString"
-  "PyUnicodeUCS2_SetDefaultEncoding"
-  "PyUnicodeUCS2_Encode"
-  "PyUnicodeUCS2_AsEncodedObject"
-  "PyUnicodeUCS2_DecodeUTF16"
-  "PyUnicodeUCS2_EncodeUTF16"
-  "PyUnicodeUCS2_AsUnicodeEscapeString"
-  "PyUnicodeUCS2_EncodeUnicodeEscape"
-  "PyUnicodeUCS2_AsRawUnicodeEscapeString"
-  "PyUnicodeUCS2_EncodeLatin1"
-  "PyUnicodeUCS2_EncodeASCII"
-  "PyUnicodeUCS2_AsCharmapString"
-  "PyUnicodeUCS2_Partition"
-  "PyUnicodeUCS2_RPartition"
-  "PyUnicodeUCS2_Translate"
-  "PyUnicodeUCS2_Tailmatch"
-  "PyUnicode_AsDecodedObject"
-  "PyUnicode_Type"
-
-; From python25_s.lib(unicodectype)
-  "_PyUnicode_TypeRecords"
-  "_PyUnicodeUCS2_ToNumeric"
-  "_PyUnicodeUCS2_IsLowercase"
-  "_PyUnicodeUCS2_IsUppercase"
-  "_PyUnicodeUCS2_IsTitlecase"
-  "_PyUnicodeUCS2_IsWhitespace"
-  "_PyUnicodeUCS2_IsLinebreak"
-  "_PyUnicodeUCS2_ToLowercase"
-  "_PyUnicodeUCS2_ToUppercase"
-  "_PyUnicodeUCS2_ToTitlecase"
-  "_PyUnicodeUCS2_ToDecimalDigit"
-  "_PyUnicodeUCS2_ToDigit"
-  "_PyUnicodeUCS2_IsDecimalDigit"
-  "_PyUnicodeUCS2_IsDigit"
-  "_PyUnicodeUCS2_IsNumeric"
-  "_PyUnicodeUCS2_IsAlpha"
-
-; From python25_s.lib(weakrefobject)
-  "PyWeakref_NewRef"
-  "PyWeakref_NewProxy"
-  "PyObject_ClearWeakRefs"
-  "PyWeakref_GetObject"
-  "_PyWeakref_GetWeakrefCount"
-  "_PyWeakref_ClearRef"
-  "_PyWeakref_RefType"
-  "_PyWeakref_ProxyType"
-  "_PyWeakref_CallableProxyType"
-
-; From python25_s.lib(Python-ast)
-;  "init_ast"
-  "Module"
-  "Interactive"
-  "Expression"
-  "Suite"
-  "FunctionDef"
-  "ClassDef"
-  "Return"
-  "Delete"
-  "Assign"
-  "AugAssign"
-  "Print"
-  "For"
-  "While"
-  "If"
-  "With"
-  "Raise"
-  "TryExcept"
-  "TryFinally"
-  "Assert"
-  "Import"
-  "ImportFrom"
-  "Exec"
-  "Global"
-  "Expr"
-  "Pass"
-  "Break"
-  "Continue"
-  "BoolOp"
-  "BinOp"
-  "UnaryOp"
-  "Lambda"
-  "IfExp"
-  "Dict"
-  "ListComp"
-  "GeneratorExp"
-  "Yield"
-  "Compare"
-  "Call"
-  "Repr"
-  "Num"
-  "Str"
-  "Attribute"
-  "Subscript"
-  "Name"
-  "List"
-  "Tuple"
-  "Ellipsis"
-  "Slice"
-  "ExtSlice"
-  "Index"
-  "comprehension"
-  "excepthandler"
-  "arguments"
-  "keyword"
-  "alias"
-  "PyAST_mod2obj"
-
-; From python25_s.lib(asdl)
-  "asdl_seq_new"
-  "asdl_int_seq_new"
-
-; From python25_s.lib(ast)
-  "PyAST_FromNode"
-
-; From python25_s.lib(bltinmodule)
-  "_PyBuiltin_Init"
-  "Py_FileSystemDefaultEncoding"
-
-; From python25_s.lib(exceptions)
-  "PyUnicodeEncodeError_GetStart"
-  "PyUnicodeDecodeError_GetStart"
-  "PyUnicodeEncodeError_GetEnd"
-  "PyUnicodeDecodeError_GetEnd"
-  "_PyExc_Init"
-  "PyUnicodeDecodeError_Create"
-  "PyUnicodeEncodeError_Create"
-  "PyUnicodeTranslateError_Create"
-  "PyUnicodeEncodeError_GetEncoding"
-  "PyUnicodeDecodeError_GetEncoding"
-  "PyUnicodeEncodeError_GetObject"
-  "PyUnicodeDecodeError_GetObject"
-  "PyUnicodeTranslateError_GetObject"
-  "PyUnicodeTranslateError_GetStart"
-  "PyUnicodeEncodeError_SetStart"
-  "PyUnicodeDecodeError_SetStart"
-  "PyUnicodeTranslateError_SetStart"
-  "PyUnicodeTranslateError_GetEnd"
-  "PyUnicodeEncodeError_SetEnd"
-  "PyUnicodeDecodeError_SetEnd"
-  "PyUnicodeTranslateError_SetEnd"
-  "PyUnicodeEncodeError_GetReason"
-  "PyUnicodeDecodeError_GetReason"
-  "PyUnicodeTranslateError_GetReason"
-  "PyUnicodeEncodeError_SetReason"
-  "PyUnicodeDecodeError_SetReason"
-  "PyUnicodeTranslateError_SetReason"
-  "_PyExc_Fini"
-  "PyExc_BaseException"
-  "PyExc_Exception"
-  "PyExc_TypeError"
-  "PyExc_StopIteration"
-  "PyExc_GeneratorExit"
-  "PyExc_SystemExit"
-  "PyExc_KeyboardInterrupt"
-  "PyExc_ImportError"
-  "PyExc_EnvironmentError"
-  "PyExc_IOError"
-  "PyExc_OSError"
-  "PyExc_EOFError"
-  "PyExc_RuntimeError"
-  "PyExc_NotImplementedError"
-  "PyExc_NameError"
-  "PyExc_UnboundLocalError"
-  "PyExc_AttributeError"
-  "PyExc_IndexError"
-  "PyExc_SyntaxError"
-  "PyExc_IndentationError"
-  "PyExc_TabError"
-  "PyExc_LookupError"
-  "PyExc_KeyError"
-  "PyExc_ValueError"
-  "PyExc_UnicodeError"
-  "PyExc_UnicodeEncodeError"
-  "PyExc_UnicodeDecodeError"
-  "PyExc_UnicodeTranslateError"
-  "PyExc_AssertionError"
-  "PyExc_ArithmeticError"
-  "PyExc_FloatingPointError"
-  "PyExc_OverflowError"
-  "PyExc_ZeroDivisionError"
-  "PyExc_SystemError"
-  "PyExc_ReferenceError"
-  "PyExc_MemoryError"
-  "PyExc_Warning"
-  "PyExc_UserWarning"
-  "PyExc_DeprecationWarning"
-  "PyExc_PendingDeprecationWarning"
-  "PyExc_SyntaxWarning"
-  "PyExc_RuntimeWarning"
-  "PyExc_FutureWarning"
-  "PyExc_ImportWarning"
-  "PyExc_MemoryErrorInst"
-
-; From python25_s.lib(ceval)
-  "PyEval_EvalFrameEx"
-  "PyEval_CallObjectWithKeywords"
-  "PyEval_EvalCodeEx"
-  "PyEval_GetFrame"
-  "PyEval_CallObject"
-  "PyEval_SetProfile"
-  "PyEval_SetTrace"
-  "PyEval_GetBuiltins"
-  "PyEval_GetGlobals"
-  "PyEval_GetLocals"
-  "PyEval_GetRestricted"
-  "PyEval_MergeCompilerFlags"
-  "Py_FlushLine"
-  "Py_AddPendingCall"
-  "Py_MakePendingCalls"
-  "Py_SetRecursionLimit"
-  "Py_GetRecursionLimit"
-  "_Py_CheckRecursiveCall"
-  "PyEval_GetFuncName"
-  "PyEval_GetFuncDesc"
-  "PyEval_GetCallStats"
-  "PyEval_EvalFrame"
-  "PyEval_SaveThread"
-  "PyEval_RestoreThread"
-  "PyEval_ThreadsInitialized"
-  "PyEval_InitThreads"
-  "PyEval_AcquireLock"
-  "PyEval_ReleaseLock"
-  "PyEval_AcquireThread"
-  "PyEval_ReleaseThread"
-  "PyEval_ReInitThreads"
-  "_PyEval_SliceIndex"
-  "PyEval_EvalCode"
-  "_PyEval_CallTracing"
-  "_Py_CheckRecursionLimit"
-  "_Py_CheckInterval"
-  "_Py_Ticker"
-
-; From python25_s.lib(compile)
-  "_Py_Mangle"
-  "PyAST_Compile"
-  "PyNode_Compile"
-  "Py_OptimizeFlag"
-
-; From python25_s.lib(codecs)
-  "_PyCodec_Lookup"
-  "PyCodec_Encode"
-  "PyCodec_Decode"
-  "PyCodec_IgnoreErrors"
-  "PyCodec_ReplaceErrors"
-  "PyCodec_XMLCharRefReplaceErrors"
-  "PyCodec_BackslashReplaceErrors"
-  "PyCodec_Register"
-  "PyCodec_Encoder"
-  "PyCodec_Decoder"
-  "PyCodec_IncrementalEncoder"
-  "PyCodec_IncrementalDecoder"
-  "PyCodec_StreamReader"
-  "PyCodec_StreamWriter"
-  "PyCodec_RegisterError"
-  "PyCodec_LookupError"
-  "PyCodec_StrictErrors"
-
-; From python25_s.lib(errors)
-  "PyErr_SetNone"
-  "PyErr_SetString"
-  "PyErr_GivenExceptionMatches"
-  "PyErr_NormalizeException"
-  "PyErr_Fetch"
-  "PyErr_Clear"
-  "PyErr_NoMemory"
-  "PyErr_SetFromErrnoWithFilenameObject"
-  "PyErr_Format"
-  "PyErr_NewException"
-  "PyErr_WriteUnraisable"
-  "PyErr_SyntaxLocation"
-  "PyErr_ProgramText"
-  "PyErr_SetObject"
-  "PyErr_Occurred"
-  "PyErr_Restore"
-  "PyErr_ExceptionMatches"
-  "PyErr_BadArgument"
-  "PyErr_SetFromErrno"
-  "PyErr_SetFromErrnoWithFilename"
-  "PyErr_BadInternalCall"
-  "_PyErr_BadInternalCall"
-  "PyErr_Warn"
-  "PyErr_WarnExplicit"
-
-; From python25_s.lib(frozen)
-  "PyImport_FrozenModules"
-
-; From python25_s.lib(frozenmain)
-  "Py_FrozenMain"
-
-; From python25_s.lib(future)
-  "PyFuture_FromAST"
-
-; From python25_s.lib(getargs)
-  "PyArg_Parse"
-  "_PyArg_Parse_SizeT"
-  "PyArg_ParseTuple"
-  "_PyArg_ParseTuple_SizeT"
-  "PyArg_ParseTupleAndKeywords"
-  "_PyArg_ParseTupleAndKeywords_SizeT"
-  "PyArg_UnpackTuple"
-  "_PyArg_NoKeywords"
-  "PyArg_VaParse"
-  "PyArg_VaParseTupleAndKeywords"
-  "_PyArg_VaParse_SizeT"
-  "_PyArg_VaParseTupleAndKeywords_SizeT"
-
-; From python25_s.lib(getcompiler)
-  "Py_GetCompiler"
-
-; From python25_s.lib(getcopyright)
-  "Py_GetCopyright"
-
-; From python25_s.lib(getmtime)
-  "PyOS_GetLastModificationTime"
-
-; From python25_s.lib(getplatform)
-  "Py_GetPlatform"
-
-; From python25_s.lib(getversion)
-  "Py_GetVersion"
-
-; From python25_s.lib(graminit)
-  "_PyParser_Grammar"
-
-; From python25_s.lib(import)
-  "_PyImport_Init"
-  "_PyImportHooks_Init"
-  "PyImport_ImportModule"
-  "PyImport_Cleanup"
-  "_PyImport_FixupExtension"
-  "PyImport_AddModule"
-  "PyImport_ExecCodeModuleEx"
-  "PyImport_ImportFrozenModule"
-  "PyImport_ImportModuleEx"
-  "PyImport_ImportModuleLevel"
-  "PyImport_ReloadModule"
-  "PyImport_Import"
-;  "initimp"
-  "_PyImport_Fini"
-  "PyImport_GetMagicNumber"
-  "PyImport_ExecCodeModule"
-  "PyImport_GetModuleDict"
-  "_PyImport_FindModule"
-  "_PyImport_IsScript"
-  "_PyImport_ReInitLock"
-  "_PyImport_FindExtension"
-  "PyImport_AppendInittab"
-  "PyImport_ExtendInittab"
-  "PyImport_Inittab"
-  "_PyImport_Filetab"
-
-; From python25_s.lib(importdl)
-  "_PyImport_LoadDynamicModule"
-
-; From python25_s.lib(marshal)
-  "PyMarshal_ReadLongFromFile"
-  "PyMarshal_WriteObjectToString"
-  "PyMarshal_WriteLongToFile"
-  "PyMarshal_WriteObjectToFile"
-  "PyMarshal_ReadShortFromFile"
-  "PyMarshal_ReadObjectFromFile"
-  "PyMarshal_ReadLastObjectFromFile"
-  "PyMarshal_ReadObjectFromString"
-  "PyMarshal_Init"
-
-; From python25_s.lib(modsupport)
-  "Py_InitModule4"
-  "Py_BuildValue"
-  "_Py_BuildValue_SizeT"
-  "PyEval_CallFunction"
-  "PyEval_CallMethod"
-  "_Py_VaBuildValue_SizeT"
-  "Py_VaBuildValue"
-  "PyModule_AddObject"
-  "PyModule_AddIntConstant"
-  "PyModule_AddStringConstant"
-  "_Py_PackageContext"
-
-; From python25_s.lib(mysnprintf)
-  "PyOS_snprintf"
-  "PyOS_vsnprintf"
-
-; From python25_s.lib(mystrtoul)
-  "PyOS_strtoul"
-  "PyOS_strtol"
-
-; From python25_s.lib(pyarena)
-  "PyArena_New"
-  "PyArena_Free"
-  "PyArena_Malloc"
-  "PyArena_AddPyObject"
-
-; From python25_s.lib(pyfpe)
-  "PyFPE_dummy"
-
-; From python25_s.lib(pystate)
-  "PyInterpreterState_Clear"
-  "PyThreadState_Clear"
-  "_PyThread_CurrentFrames"
-  "PyGILState_Ensure"
-  "PyGILState_Release"
-  "PyInterpreterState_New"
-  "PyInterpreterState_Delete"
-  "PyThreadState_Delete"
-  "PyThreadState_New"
-  "PyThreadState_DeleteCurrent"
-  "PyThreadState_Get"
-  "PyThreadState_Swap"
-  "PyThreadState_GetDict"
-  "PyThreadState_SetAsyncExc"
-  "PyGILState_GetThisThreadState"
-  "PyInterpreterState_Head"
-  "PyInterpreterState_Next"
-  "PyInterpreterState_ThreadHead"
-  "PyThreadState_Next"
-  "_PyGILState_Init"
-  "_PyGILState_Fini"
-  "_PyThreadState_Current"
-  "_PyThreadState_GetFrame"
-
-; From python25_s.lib(pystrtod)
-  "PyOS_ascii_strtod"
-  "PyOS_ascii_formatd"
-  "PyOS_ascii_atof"
-
-; From python25_s.lib(pythonrun)
-  "Py_IgnoreEnvironmentFlag"
-  "Py_DebugFlag"
-  "Py_VerboseFlag"
-  "Py_NoSiteFlag"
-  "Py_InteractiveFlag"
-  "Py_FrozenFlag"
-  "Py_InitializeEx"
-  "Py_FatalError"
-  "Py_NewInterpreter"
-  "PyErr_Print"
-  "PyRun_InteractiveOneFlags"
-  "PyParser_ASTFromFile"
-  "PyRun_SimpleFileExFlags"
-  "PyRun_FileExFlags"
-  "Py_Exit"
-  "PyErr_PrintEx"
-  "PyErr_Display"
-  "Py_SetProgramName"
-  "Py_GetProgramName"
-  "Py_SetPythonHome"
-  "Py_GetPythonHome"
-  "Py_Initialize"
-  "Py_Finalize"
-  "Py_IsInitialized"
-  "Py_EndInterpreter"
-  "PyRun_AnyFileFlags"
-  "Py_FdIsInteractive"
-  "PyRun_InteractiveLoopFlags"
-  "PyRun_AnyFileExFlags"
-  "PyRun_SimpleStringFlags"
-  "PyRun_StringFlags"
-  "PyParser_ASTFromString"
-  "PyParser_SimpleParseStringFlags"
-  "PyParser_SimpleParseFileFlags"
-  "Py_CompileStringFlags"
-  "Py_SymtableString"
-  "Py_AtExit"
-  "PyOS_getsig"
-  "PyOS_setsig"
-  "PyParser_SetError"
-  "PyModule_GetWarningsModule"
-  "PyParser_SimpleParseStringFlagsFilename"
-  "PyParser_SimpleParseStringFilename"
-  "PyParser_SimpleParseFile"
-  "PyParser_SimpleParseString"
-  "PyRun_AnyFile"
-  "PyRun_AnyFileEx"
-  "PyRun_File"
-  "PyRun_FileEx"
-  "PyRun_FileFlags"
-  "PyRun_SimpleFile"
-  "PyRun_SimpleFileEx"
-  "PyRun_String"
-  "PyRun_SimpleString"
-  "Py_CompileString"
-  "PyRun_InteractiveOne"
-  "PyRun_InteractiveLoop"
-  "Py_UseClassExceptionsFlag"
-  "Py_UnicodeFlag"
-  "_Py_QnewFlag"
-
-; From python25_s.lib(structmember)
-  "PyMember_GetOne"
-  "PyMember_SetOne"
-
-; From python25_s.lib(symtable)
-  "PySymtable_Build"
-  "PySymtable_Free"
-  "PyST_GetScope"
-  "PySymtable_Lookup"
-  "PySTEntry_Type"
-
-; From python25_s.lib(sysmodule)
-  "_PySys_Init"
-  "PySys_WriteStderr"
-  "PySys_SetPath"
-  "PySys_SetArgv"
-  "PySys_WriteStdout"
-  "Py_SubversionRevision"
-  "Py_SubversionShortBranch"
-  "PySys_GetObject"
-  "PySys_SetObject"
-  "PySys_GetFile"
-  "PySys_ResetWarnOptions"
-  "PySys_AddWarnOption"
-
-; From python25_s.lib(traceback)
-  "PyTraceBack_Here"
-  "PyTraceBack_Print"
-  "PyTraceBack_Type"
-
-; From python25_s.lib(getopt)
-  "_PyOS_GetOpt"
-  "_PyOS_opterr"
-  "_PyOS_optind"
-  "_PyOS_optarg"
-
-; From python25_s.lib(dynload_shlib)
-  "_PyImport_DynLoadFiletab"
-  "_PyImport_GetDynLoadFunc"
-
-; From python25_s.lib(thread)
-  "PyThread_delete_key_value"
-  "PyThread_init_thread"
-  "PyThread_start_new_thread"
-  "PyThread_exit_thread"
-  "PyThread_get_thread_ident"
-  "PyThread_allocate_lock"
-  "PyThread_free_lock"
-  "PyThread_acquire_lock"
-  "PyThread_release_lock"
-  "PyThread_get_stacksize"
-  "PyThread_set_stacksize"
-  "PyThread_create_key"
-  "PyThread_delete_key"
-  "PyThread_set_key_value"
-  "PyThread_get_key_value"
-  "PyThread__exit_thread"
-
-; From python25_s.lib(gcmodule)
-;  "initgc"
-  "_PyObject_GC_New"
-  "_PyObject_GC_NewVar"
-  "PyGC_Collect"
-  "_PyObject_GC_Resize"
-  "_PyObject_GC_Malloc"
-  "PyObject_GC_Track"
-  "PyObject_GC_UnTrack"
-  "PyObject_GC_Del"
-  "_PyGC_Dump"
-  "_PyObject_GC_Track"
-  "_PyObject_GC_UnTrack"
-  "_PyObject_GC_Del"
-  "_PyGC_generation0"
-
-; From python25_s.lib(signalmodule)
-;  "initsignal"
-  "PyErr_CheckSignals"
-  "PyErr_SetInterrupt"
-  "PyOS_FiniInterrupts"
-  "PyOS_InterruptOccurred"
-  "PyOS_InitInterrupts"
-  "PyOS_AfterFork"
-
-; From python25_s.lib(posixmodule)
-;  "initos2"
-
-; From python25_s.lib(threadmodule)
-;  "initthread"
-
-; From python25_s.lib(arraymodule)
-;  "initarray"
-;  "array_methods"
-
-; From python25_s.lib(binascii)
-;  "initbinascii"
-
-; From python25_s.lib(cmathmodule)
-;  "initcmath"
-
-; From python25_s.lib(_codecsmodule)
-;  "init_codecs"
-
-; From python25_s.lib(collectionsmodule)
-;  "initcollections"
-  "dequeiter_type"
-  "dequereviter_type"
-
-; From python25_s.lib(cStringIO)
-;  "initcStringIO"
-
-; From python25_s.lib(_csv)
-;  "init_csv"
-
-; From python25_s.lib(datetimemodule)
-;  "initdatetime"
-
-; From python25_s.lib(dlmodule)
-;  "initdl"
-
-; From python25_s.lib(errnomodule)
-;  "initerrno"
-
-; From python25_s.lib(fcntlmodule)
-;  "initfcntl"
-
-; From python25_s.lib(_functoolsmodule)
-;  "init_functools"
-
-; From python25_s.lib(_heapqmodule)
-;  "init_heapq"
-
-; From python25_s.lib(imageop)
-;  "initimageop"
-
-; From python25_s.lib(itertoolsmodule)
-;  "inititertools"
-
-; From python25_s.lib(_localemodule)
-;  "init_locale"
-
-; From python25_s.lib(mathmodule)
-;  "initmath"
-
-; From python25_s.lib(operator)
-;  "initoperator"
-
-; From python25_s.lib(_randommodule)
-;  "init_random"
-
-; From python25_s.lib(sha256module)
-;  "init_sha256"
-
-; From python25_s.lib(sha512module)
-;  "init_sha512"
-
-; From python25_s.lib(_sre)
-;  "init_sre"
-
-; From python25_s.lib(_struct)
-;  "init_struct"
-
-; From python25_s.lib(symtablemodule)
-;  "init_symtable"
-
-; From python25_s.lib(termios)
-;  "inittermios"
-
-; From python25_s.lib(timemodule)
-;  "inittime"
-  "_PyTime_DoubleToTimet"
-;  "inittimezone"
-
-; From python25_s.lib(_weakref)
-;  "init_weakref"
-
-; From python25_s.lib(xxsubtype)
-;  "initxxsubtype"
-
-; From python25_s.lib(zipimport)
-;  "initzipimport"

Modified: python/branches/py3k-importlib/PC/os2vacpp/config.c
==============================================================================
--- python/branches/py3k-importlib/PC/os2vacpp/config.c	(original)
+++ python/branches/py3k-importlib/PC/os2vacpp/config.c	Thu Mar 27 00:48:05 2008
@@ -94,7 +94,7 @@
 
         /* These entries are here for sys.builtin_module_names */
         {"__main__", NULL},
-        {"__builtin__", NULL},
+        {"builtins", NULL},
         {"sys", NULL},
 
         /* Sentinel */

Modified: python/branches/py3k-importlib/PC/os2vacpp/pyconfig.h
==============================================================================
--- python/branches/py3k-importlib/PC/os2vacpp/pyconfig.h	(original)
+++ python/branches/py3k-importlib/PC/os2vacpp/pyconfig.h	Thu Mar 27 00:48:05 2008
@@ -80,7 +80,6 @@
 /* #define SIZEOF_LONG_LONG   8 */ /* Count of Bytes in a (long long)       */
 
 /* unicode definines */
-#define Py_USING_UNICODE
 #define PY_UNICODE_TYPE    wchar_t
 #define Py_UNICODE_SIZE SIZEOF_SHORT
 

Modified: python/branches/py3k-importlib/PC/pyconfig.h
==============================================================================
--- python/branches/py3k-importlib/PC/pyconfig.h	(original)
+++ python/branches/py3k-importlib/PC/pyconfig.h	Thu Mar 27 00:48:05 2008
@@ -23,9 +23,11 @@
 
 
 NOTE: The following symbols are deprecated:
-NT, WIN32, USE_DL_EXPORT, USE_DL_IMPORT, DL_EXPORT, DL_IMPORT
+NT, USE_DL_EXPORT, USE_DL_IMPORT, DL_EXPORT, DL_IMPORT
 MS_CORE_DLL.
 
+WIN32 is still required for the locale module.
+
 */
 
 #ifdef _WIN32_WCE
@@ -156,10 +158,12 @@
 /* set the version macros for the windows headers */
 #ifdef MS_WINX64
 /* 64 bit only runs on XP or greater */
-#define Py_WINVER 0x0501
+#define Py_WINVER _WIN32_WINNT_WINXP
+#define Py_NTDDI NTDDI_WINXP
 #else
-/* NT 4.0 or greater required otherwise */
-#define Py_WINVER 0x0400
+/* Python 2.6+ requires Windows 2000 or greater */
+#define Py_WINVER _WIN32_WINNT_WIN2K
+#define Py_NTDDI NTDDI_WIN2KSP4
 #endif
 
 /* We only set these values when building Python - we don't want to force
@@ -169,7 +173,10 @@
    structures etc so it can optionally use new Windows features if it
    determines at runtime they are available.
 */
-#ifdef Py_BUILD_CORE
+#if defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_MODULE)
+#ifndef NTDDI_VERSION
+#define NTDDI_VERSION Py_NTDDI
+#endif
 #ifndef WINVER
 #define WINVER Py_WINVER
 #endif
@@ -207,12 +214,6 @@
 #define Py_IS_INFINITY(X) (!_finite(X) && !_isnan(X))
 #define Py_IS_FINITE(X) _finite(X)
 
-/* Turn off warnings about deprecated C runtime functions in 
-   VisualStudio .NET 2005 */
-#if _MSC_VER >= 1400 && !defined _CRT_SECURE_NO_DEPRECATE
-#define _CRT_SECURE_NO_DEPRECATE
-#endif
-
 #endif /* _MSC_VER */
 
 /* define some ANSI types that are not defined in earlier Win headers */
@@ -377,11 +378,11 @@
    define these.
    If some compiler does not provide them, modify the #if appropriately. */
 #if defined(_MSC_VER)
-#if _MSC_VER > 1201
+#if _MSC_VER > 1300
 #define HAVE_UINTPTR_T 1
 #define HAVE_INTPTR_T 1
 #else
-/* VC6 & eVC4 don't support the C99 LL suffix for 64-bit integer literals */
+/* VC6, VS 2002 and eVC4 don't support the C99 LL suffix for 64-bit integer literals */
 #define Py_LL(x) x##I64
 #endif  /* _MSC_VER > 1200  */
 #endif  /* _MSC_VER */
@@ -390,6 +391,15 @@
 
 /* Fairly standard from here! */
 
+/* Define to 1 if you have the `copysign' function. */
+/* #define HAVE_COPYSIGN 1*/
+
+/* Define to 1 if you have the `isinf' function. */
+#define HAVE_ISINF 1
+
+/* Define to 1 if you have the `isnan' function. */
+#define HAVE_ISNAN 1
+
 /* Define if on AIX 3.
    System headers sometimes define this.
    We just want to avoid a redefinition error message.  */

Modified: python/branches/py3k-importlib/PC/python_nt.rc
==============================================================================
--- python/branches/py3k-importlib/PC/python_nt.rc	(original)
+++ python/branches/py3k-importlib/PC/python_nt.rc	Thu Mar 27 00:48:05 2008
@@ -61,7 +61,7 @@
             VALUE "FileDescription", "Python Core\0"
             VALUE "FileVersion", PYTHON_VERSION
             VALUE "InternalName", "Python DLL\0"
-            VALUE "LegalCopyright", "Copyright © 2001-2007 Python Software Foundation. Copyright © 2000 BeOpen.com. Copyright © 1995-2001 CNRI. Copyright © 1991-1995 SMC.\0"
+            VALUE "LegalCopyright", "Copyright © 2001-2008 Python Software Foundation. Copyright © 2000 BeOpen.com. Copyright © 1995-2001 CNRI. Copyright © 1991-1995 SMC.\0"
             VALUE "OriginalFilename", PYTHON_DLL_NAME "\0"
             VALUE "ProductName", "Python\0"
             VALUE "ProductVersion", PYTHON_VERSION

Modified: python/branches/py3k-importlib/PC/readme.txt
==============================================================================
--- python/branches/py3k-importlib/PC/readme.txt	(original)
+++ python/branches/py3k-importlib/PC/readme.txt	Thu Mar 27 00:48:05 2008
@@ -1,11 +1,6 @@
 Welcome to the "PC" subdirectory of the Python distribution
 ***********************************************************
 
-*** Note: the project files for MS VC++ 7.1 are now in the
-*** PCbuild directory.  See the file readme.txt there for build
-*** instructions.  There is some information below that might
-*** still be relevant.
-
 This "PC" subdirectory contains complete project files to make
 several older PC ports of Python, as well as all the PC-specific
 Python source files.  It should be located in the root of the
@@ -79,18 +74,23 @@
 example_nt     A subdirectory showing how to build an extension as a
                DLL.
 
-Visual Studio 6.0
-=================
-The subdirectory VC6 contains Visual Studio 6 project files. These
-were originally located in the PCBuild directory, but are no longer
-maintained.
+Legacy support for older versions of Visual Studio
+==================================================
+The subdirectories VC6, VS7.1 and VS8.0 contain legacy support older
+versions of Microsoft Visual Studio. See PCbuild/readme.txt.
+
+EMX development tools for OS/2
+==============================
 
+See os2emx/readme.txt. This platform is maintained by Andrew MacIntyre.
 
 IBM VisualAge C/C++ for OS/2
 ============================
 
 See os2vacpp/readme.txt.  This platform is supported by Jeff Rush.
 
+NOTE: Support for os2vacpp may be dropped in the near future. Please move
+      to EMX.
 
 Note for Windows 3.x and DOS users
 ==================================

Modified: python/branches/py3k-importlib/Parser/asdl.py
==============================================================================
--- python/branches/py3k-importlib/Parser/asdl.py	(original)
+++ python/branches/py3k-importlib/Parser/asdl.py	Thu Mar 27 00:48:05 2008
@@ -181,7 +181,7 @@
         " sum ::= constructor """
         return [constructor[0]]
 
-    def p_sum_1(self, ):
+    def p_sum_1(self, info):
         " sum ::= constructor | sum "
         constructor, _, sum = info
         return [constructor] + sum

Modified: python/branches/py3k-importlib/Parser/asdl_c.py
==============================================================================
--- python/branches/py3k-importlib/Parser/asdl_c.py	(original)
+++ python/branches/py3k-importlib/Parser/asdl_c.py	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,7 @@
 # TO DO
 # handle fields that have a type but no name
 
-import os, sys, traceback
+import os, sys
 
 import asdl
 
@@ -415,7 +415,7 @@
         }
         PyTuple_SET_ITEM(fnames, i, field);
     }
-    result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
+    result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}",
                     type, base, "_fields", fnames, "__module__", "_ast");
     Py_DECREF(fnames);
     return (PyTypeObject*)result;
@@ -469,7 +469,7 @@
 
 static PyObject* ast2obj_int(long b)
 {
-    return PyInt_FromLong(b);
+    return PyLong_FromLong(b);
 }
 """, 0, reflow=False)
 
@@ -741,7 +741,7 @@
         sys.exit(1)
     if INC_DIR:
         p = "%s/%s-ast.h" % (INC_DIR, mod.name)
-        f = open(p, "wb")
+        f = open(p, "w")
         f.write(auto_gen_msg)
         f.write('#include "asdl.h"\n\n')
         c = ChainOfVisitors(TypeDefVisitor(f),
@@ -754,7 +754,7 @@
 
     if SRC_DIR:
         p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c")
-        f = open(p, "wb")
+        f = open(p, "w")
         f.write(auto_gen_msg)
         f.write(c_file_msg % parse_version(mod))
         f.write('#include "Python.h"\n')

Modified: python/branches/py3k-importlib/Parser/parser.h
==============================================================================
--- python/branches/py3k-importlib/Parser/parser.h	(original)
+++ python/branches/py3k-importlib/Parser/parser.h	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,7 @@
 
 /* Parser interface */
 
-#define MAXSTACK 500
+#define MAXSTACK 1500
 
 typedef struct {
 	int		 s_state;	/* State in current DFA */

Modified: python/branches/py3k-importlib/Parser/parsetok.c
==============================================================================
--- python/branches/py3k-importlib/Parser/parsetok.c	(original)
+++ python/branches/py3k-importlib/Parser/parsetok.c	Thu Mar 27 00:48:05 2008
@@ -213,24 +213,16 @@
 			err_ret->error = E_EOF;
 		err_ret->lineno = tok->lineno;
 		if (tok->buf != NULL) {
-			char *text = NULL;
 			size_t len;
 			assert(tok->cur - tok->buf < INT_MAX);
 			err_ret->offset = (int)(tok->cur - tok->buf);
 			len = tok->inp - tok->buf;
-#ifdef Py_USING_UNICODE
-			text = PyTokenizer_RestoreEncoding(tok, len, &err_ret->offset);
-
-#endif
-			if (text == NULL) {
-				text = (char *) PyObject_MALLOC(len + 1);
-				if (text != NULL) {
-					if (len > 0)
-						strncpy(text, tok->buf, len);
-					text[len] = '\0';
-				}
+			err_ret->text = (char *) PyObject_MALLOC(len + 1);
+			if (err_ret->text != NULL) {
+				if (len > 0)
+					strncpy(err_ret->text, tok->buf, len);
+				err_ret->text[len] = '\0';
 			}
-			err_ret->text = text;
 		}
 	} else if (tok->encoding != NULL) {
 		node* r = PyNode_New(encoding_decl);

Modified: python/branches/py3k-importlib/Parser/pgen.c
==============================================================================
--- python/branches/py3k-importlib/Parser/pgen.c	(original)
+++ python/branches/py3k-importlib/Parser/pgen.c	Thu Mar 27 00:48:05 2008
@@ -124,7 +124,7 @@
 	
 	nf = newnfa(name);
 	gr->gr_nfa = (nfa **)PyObject_REALLOC(gr->gr_nfa,
-				      sizeof(nfa) * (gr->gr_nnfas + 1));
+				      sizeof(nfa*) * (gr->gr_nnfas + 1));
 	if (gr->gr_nfa == NULL)
 		Py_FatalError("out of mem");
 	gr->gr_nfa[gr->gr_nnfas++] = nf;
@@ -487,6 +487,7 @@
 	convert(d, xx_nstates, xx_state);
 	
 	/* XXX cleanup */
+	PyObject_FREE(xx_state);
 }
 
 static void
@@ -666,6 +667,7 @@
 	g = maketables(gr);
 	translatelabels(g);
 	addfirstsets(g);
+	PyObject_FREE(gr);
 	return g;
 }
 

Modified: python/branches/py3k-importlib/Parser/spark.py
==============================================================================
--- python/branches/py3k-importlib/Parser/spark.py	(original)
+++ python/branches/py3k-importlib/Parser/spark.py	Thu Mar 27 00:48:05 2008
@@ -22,7 +22,6 @@
 __version__ = 'SPARK-0.7 (pre-alpha-5)'
 
 import re
-import sys
 
 # Compatability with older pythons.
 def output(string='', end='\n'):

Modified: python/branches/py3k-importlib/Parser/tokenizer.c
==============================================================================
--- python/branches/py3k-importlib/Parser/tokenizer.c	(original)
+++ python/branches/py3k-importlib/Parser/tokenizer.c	Thu Mar 27 00:48:05 2008
@@ -52,6 +52,7 @@
 static int tok_nextc(struct tok_state *tok);
 static void tok_backup(struct tok_state *tok, int c);
 
+
 /* Token names */
 
 char *_PyParser_TokenNames[] = {
@@ -322,8 +323,21 @@
 	if (ch == EOF) {
 		return 1;
 	} else if (ch == 0xEF) {
-		ch = get_char(tok); if (ch != 0xBB) goto NON_BOM;
-		ch = get_char(tok); if (ch != 0xBF) goto NON_BOM;
+		ch = get_char(tok); 
+		if (ch != 0xBB) {
+			unget_char(ch, tok);
+			unget_char(0xEF, tok);
+			/* any token beginning with '\xEF' is a bad token */
+			return 1;
+		}
+		ch = get_char(tok); 
+		if (ch != 0xBF) {
+			unget_char(ch, tok);
+			unget_char(0xBB, tok);
+			unget_char(0xEF, tok);
+			/* any token beginning with '\xEF' is a bad token */
+			return 1;
+		}
 #if 0
 	/* Disable support for UTF-16 BOMs until a decision
 	   is made whether this needs to be supported.  */
@@ -343,10 +357,7 @@
 	if (tok->encoding != NULL)
 		PyMem_FREE(tok->encoding);
 	tok->encoding = new_string("utf-8", 5);	/* resulting is in utf-8 */
-	return 1;
-  NON_BOM:
-	/* any token beginning with '\xEF', '\xFE', '\xFF' is a bad token */
-	unget_char(0xFF, tok);	/* XXX this will cause a syntax error */
+	/* No need to set_readline: input is already utf-8 */
 	return 1;
 }
 
@@ -368,46 +379,61 @@
 static char *
 fp_readl(char *s, int size, struct tok_state *tok)
 {
-	PyObject* bufobj = tok->decoding_buffer;
+	PyObject* bufobj;
 	const char *buf;
 	Py_ssize_t buflen;
-	int allocated = 0;
 
 	/* Ask for one less byte so we can terminate it */
 	assert(size > 0);
 	size--;
 
-	if (bufobj == NULL) {
+	if (tok->decoding_buffer) {
+		bufobj = tok->decoding_buffer;
+		Py_INCREF(bufobj);
+	}
+	else
+	{
 		bufobj = PyObject_CallObject(tok->decoding_readline, NULL);
 		if (bufobj == NULL)
 			goto error;
-		allocated = 1;
 	}
-	buf = PyUnicode_AsStringAndSize(bufobj, &buflen);
-	if (buf == NULL) {
-		goto error;
+	if (PyUnicode_CheckExact(bufobj))
+	{
+		buf = PyUnicode_AsStringAndSize(bufobj, &buflen);
+		if (buf == NULL) {
+			goto error;
+		}
+	}
+	else
+	{
+		buf = PyBytes_AsString(bufobj);
+		if (buf == NULL) {
+			goto error;
+		}
+		buflen = PyBytes_GET_SIZE(bufobj);
 	}
+
+	Py_XDECREF(tok->decoding_buffer);
 	if (buflen > size) {
-		Py_XDECREF(tok->decoding_buffer);
+		/* Too many chars, the rest goes into tok->decoding_buffer */
 		tok->decoding_buffer = PyBytes_FromStringAndSize(buf+size,
 								 buflen-size);
 		if (tok->decoding_buffer == NULL)
 			goto error;
 		buflen = size;
 	}
+	else
+		tok->decoding_buffer = NULL;
+
 	memcpy(s, buf, buflen);
 	s[buflen] = '\0';
 	if (buflen == 0) /* EOF */
 		s = NULL;
-	if (allocated) {
-		Py_DECREF(bufobj);
-	}
+	Py_DECREF(bufobj);
 	return s;
 
 error:
-	if (allocated) {
-		Py_XDECREF(bufobj);
-	}
+	Py_XDECREF(bufobj);
 	return error_ret(tok);
 }
 
@@ -426,7 +452,7 @@
 {
 	PyObject *readline = NULL, *stream = NULL, *io = NULL;
 
-	io = PyImport_ImportModule("io");
+	io = PyImport_ImportModuleNoBlock("io");
 	if (io == NULL)
 		goto cleanup;
 
@@ -614,6 +640,7 @@
 {
 	PyObject* utf8 = NULL;
 	const char *s;
+	const char *newl[2] = {NULL, NULL};
 	int lineno = 0;
 	tok->enc = NULL;
 	tok->str = str;
@@ -625,18 +652,29 @@
 		utf8 = translate_into_utf8(str, tok->enc);
 		if (utf8 == NULL)
 			return error_ret(tok);
-		str = PyBytes_AsString(utf8);
+		str = PyString_AsString(utf8);
 	}
 	for (s = str;; s++) {
 		if (*s == '\0') break;
 		else if (*s == '\n') {
+			assert(lineno < 2);
+			newl[lineno] = s;
 			lineno++;
 			if (lineno == 2) break;
 		}
 	}
 	tok->enc = NULL;
-	if (!check_coding_spec(str, s - str, tok, buf_setreadl))
-		return error_ret(tok);
+	/* need to check line 1 and 2 separately since check_coding_spec
+	   assumes a single line as input */
+	if (newl[0]) {
+		if (!check_coding_spec(str, newl[0] - str, tok, buf_setreadl))
+			return error_ret(tok);
+		if (tok->enc == NULL && newl[1]) {
+			if (!check_coding_spec(newl[0]+1, newl[1] - newl[0],
+					       tok, buf_setreadl))
+				return error_ret(tok);
+		}
+	}
 	if (tok->enc != NULL) {
 		assert(utf8 == NULL);
 		utf8 = translate_into_utf8(str, tok->enc);
@@ -645,7 +683,7 @@
 				"unknown encoding: %s", tok->enc);
 			return error_ret(tok);
 		}
-		str = PyBytes_AsString(utf8);
+		str = PyString_AS_STRING(utf8);
 	}
 	assert(tok->decoding_buffer == NULL);
 	tok->decoding_buffer = utf8; /* CAUTION */
@@ -764,8 +802,8 @@
 					tok->done = E_DECODE;
 					return EOF;
 				}
-				buflen = PyBytes_Size(u);
-				buf = PyBytes_AsString(u);
+				buflen = PyString_GET_SIZE(u);
+				buf = PyString_AS_STRING(u);
 				if (!buf) {
 					Py_DECREF(u);
 					tok->done = E_DECODE;
@@ -1253,30 +1291,24 @@
 	/* Identifier (most frequent token!) */
 	nonascii = 0;
 	if (is_potential_identifier_start(c)) {
-		/* Process r"", u"" and ur"" */
-		switch (c) {
-		case 'r':
-		case 'R':
+		/* Process b"", r"" and br"" */
+		if (c == 'b' || c == 'B') {
 			c = tok_nextc(tok);
 			if (c == '"' || c == '\'')
 				goto letter_quote;
-			break;
-		case 'b':
-		case 'B':
+		}
+		if (c == 'r' || c == 'R') {
 			c = tok_nextc(tok);
-			if (c == 'r' || c == 'R')
-				c = tok_nextc(tok);
 			if (c == '"' || c == '\'')
 				goto letter_quote;
-			break;
-		}
+	    }
 		while (is_potential_identifier_char(c)) {
 			if (c >= 128)
 				nonascii = 1;
 			c = tok_nextc(tok);
 		}
 		tok_backup(tok, c);
-		if (nonascii && 
+		if (nonascii &&
 		    !verify_identifier(tok->start, tok->cur)) {
 			tok->done = E_IDENTIFIER;
 			return ERRORTOKEN;
@@ -1306,7 +1338,7 @@
 			c = tok_nextc(tok);
 			if (c == '.') {
 				*p_start = tok->start;
-				*p_end = tok->cur; 
+				*p_end = tok->cur;
 				return ELLIPSIS;
 			} else {
 				tok_backup(tok, c);
@@ -1332,19 +1364,38 @@
 				goto imaginary;
 #endif
 			if (c == 'x' || c == 'X') {
+
 				/* Hex */
+				c = tok_nextc(tok);
+				if (!isxdigit(c)) {
+					tok->done = E_TOKEN;
+					tok_backup(tok, c);
+					return ERRORTOKEN;
+				}
 				do {
 					c = tok_nextc(tok);
 				} while (isxdigit(c));
 			}
                         else if (c == 'o' || c == 'O') {
 				/* Octal */
+				c = tok_nextc(tok);
+				if (c < '0' || c > '8') {
+					tok->done = E_TOKEN;
+					tok_backup(tok, c);
+					return ERRORTOKEN;
+				}
 				do {
 					c = tok_nextc(tok);
 				} while ('0' <= c && c < '8');
 			}
 			else if (c == 'b' || c == 'B') {
 				/* Binary */
+				c = tok_nextc(tok);
+				if (c != '0' && c != '1') {
+					tok->done = E_TOKEN;
+					tok_backup(tok, c);
+					return ERRORTOKEN;
+				}
 				do {
 					c = tok_nextc(tok);
 				} while (c == '0' || c == '1');
@@ -1420,55 +1471,47 @@
   letter_quote:
 	/* String */
 	if (c == '\'' || c == '"') {
-		Py_ssize_t quote2 = tok->cur - tok->start + 1;
-		int quote = c;
-		int triple = 0;
-		int tripcount = 0;
-		for (;;) {
-			c = tok_nextc(tok);
-			if (c == '\n') {
-				if (!triple) {
-					tok->done = E_EOLS;
-					tok_backup(tok, c);
-					return ERRORTOKEN;
-				}
-				tripcount = 0;
-                                tok->cont_line = 1; /* multiline string. */
-			}
-			else if (c == EOF) {
-				if (triple)
-					tok->done = E_EOFS;
-				else
-					tok->done = E_EOLS;
-				tok->cur = tok->inp;
-				return ERRORTOKEN;
-			}
-			else if (c == quote) {
-				tripcount++;
-				if (tok->cur - tok->start == quote2) {
-					c = tok_nextc(tok);
-					if (c == quote) {
-						triple = 1;
-						tripcount = 0;
-						continue;
-					}
-					tok_backup(tok, c);
-				}
-				if (!triple || tripcount == 3)
-					break;
-			}
-			else if (c == '\\') {
-				tripcount = 0;
-				c = tok_nextc(tok);
-				if (c == EOF) {
-					tok->done = E_EOLS;
-					tok->cur = tok->inp;
-					return ERRORTOKEN;
-				}
-			}
+ 		int quote = c;
+		int quote_size = 1;             /* 1 or 3 */
+		int end_quote_size = 0;
+
+		/* Find the quote size and start of string */
+		c = tok_nextc(tok);
+		if (c == quote) {
+ 			c = tok_nextc(tok);
+			if (c == quote)
+				quote_size = 3;
 			else
-				tripcount = 0;
+				end_quote_size = 1;     /* empty string found */
 		}
+		if (c != quote)
+		    tok_backup(tok, c);
+
+		/* Get rest of string */
+		while (end_quote_size != quote_size) {
+ 			c = tok_nextc(tok);
+  			if (c == EOF) {
+				if (quote_size == 3)
+ 					tok->done = E_EOFS;
+ 				else
+ 					tok->done = E_EOLS;
+ 				tok->cur = tok->inp;
+ 				return ERRORTOKEN;
+ 			}
+ 			if (quote_size == 1 && c == '\n') {
+ 			    tok->done = E_EOLS;
+ 			    tok->cur = tok->inp;
+ 			    return ERRORTOKEN;
+ 			}
+ 			if (c == quote)
+ 			    end_quote_size += 1;
+ 			else {
+ 			    end_quote_size = 0;
+ 			    if (c == '\\')
+ 			        c = tok_nextc(tok);  /* skip escaped char */
+ 			}
+ 		}
+
 		*p_start = tok->start;
 		*p_end = tok->cur;
 		return STRING;
@@ -1536,72 +1579,46 @@
 	return result;
 }
 
-/* This function is only called from parsetok. However, it cannot live
-   there, as it must be empty for PGEN, and we can check for PGEN only
-   in this file. */
+/* Get -*- encoding -*- from a Python file.
 
-#ifdef PGEN
-char*
-PyTokenizer_RestoreEncoding(struct tok_state* tok, int len, int* offset)
+   PyTokenizer_FindEncoding returns NULL when it can't find the encoding in
+   the first or second line of the file (in which case the encoding
+   should be assumed to be PyUnicode_GetDefaultEncoding()).
+
+   The char * returned is malloc'ed via PyMem_MALLOC() and thus must be freed
+   by the caller.
+*/
+char *
+PyTokenizer_FindEncoding(int fd)
 {
-	return NULL;
-}
-#else
-static PyObject *
-dec_utf8(const char *enc, const char *text, size_t len) {
-	PyObject *ret = NULL;	
-	PyObject *unicode_text = PyUnicode_DecodeUTF8(text, len, "replace");
-	if (unicode_text) {
-		ret = PyUnicode_AsEncodedString(unicode_text, enc, "replace");
-		Py_DECREF(unicode_text);
+	struct tok_state *tok;
+	FILE *fp;
+	char *p_start =NULL , *p_end =NULL , *encoding = NULL;
+
+	fd = dup(fd);
+	if (fd < 0) {
+		return NULL;
 	}
-	if (!ret) {
-		PyErr_Clear();
+	fp = fdopen(fd, "r");
+	if (fp == NULL) {
+		return NULL;
 	}
-        else {
-		assert(PyBytes_Check(ret));
+	tok = PyTokenizer_FromFile(fp, NULL, NULL, NULL);
+	if (tok == NULL) {
+		fclose(fp);
+		return NULL;
 	}
-	return ret;
-}
-
-char *
-PyTokenizer_RestoreEncoding(struct tok_state* tok, int len, int *offset)
-{
-	char *text = NULL;
-	if (tok->encoding) {
-		/* convert source to original encondig */
-		PyObject *lineobj = dec_utf8(tok->encoding, tok->buf, len);
-		if (lineobj != NULL) {
-			int linelen = PyBytes_GET_SIZE(lineobj);
-			const char *line = PyBytes_AS_STRING(lineobj);
-			text = PyObject_MALLOC(linelen + 1);
-			if (text != NULL && line != NULL) {
-				if (linelen)
-					strncpy(text, line, linelen);
-				text[linelen] = '\0';
-			}
-			Py_DECREF(lineobj);
-					
-			/* adjust error offset */
-			if (*offset > 1) {
-				PyObject *offsetobj = dec_utf8(tok->encoding, 
-							       tok->buf,
-							       *offset-1);
-				if (offsetobj) {
-					*offset = 1 +
-						PyBytes_GET_SIZE(offsetobj);
-					Py_DECREF(offsetobj);
-				}
-			}
-			
-		}
+	while (tok->lineno < 2 && tok->done == E_OK) {
+		PyTokenizer_Get(tok, &p_start, &p_end);
 	}
-	return text;
-
+	fclose(fp);
+	if (tok->encoding) {
+            encoding = (char *)PyMem_MALLOC(strlen(tok->encoding) + 1);
+            strcpy(encoding, tok->encoding);
+        }
+	PyTokenizer_Free(tok);
+	return encoding;
 }
-#endif
-
-			   
 
 #ifdef Py_DEBUG
 

Modified: python/branches/py3k-importlib/Parser/tokenizer.h
==============================================================================
--- python/branches/py3k-importlib/Parser/tokenizer.h	(original)
+++ python/branches/py3k-importlib/Parser/tokenizer.h	Thu Mar 27 00:48:05 2008
@@ -67,6 +67,7 @@
 extern int PyTokenizer_Get(struct tok_state *, char **, char **);
 extern char * PyTokenizer_RestoreEncoding(struct tok_state* tok, 
 					  int len, int *offset);
+extern char * PyTokenizer_FindEncoding(int);
 
 #ifdef __cplusplus
 }

Modified: python/branches/py3k-importlib/Python/Python-ast.c
==============================================================================
--- python/branches/py3k-importlib/Python/Python-ast.c	(original)
+++ python/branches/py3k-importlib/Python/Python-ast.c	Thu Mar 27 00:48:05 2008
@@ -410,7 +410,7 @@
         }
         PyTuple_SET_ITEM(fnames, i, field);
     }
-    result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
+    result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}",
                     type, base, "_fields", fnames, "__module__", "_ast");
     Py_DECREF(fnames);
     return (PyTypeObject*)result;
@@ -464,7 +464,7 @@
 
 static PyObject* ast2obj_int(long b)
 {
-    return PyInt_FromLong(b);
+    return PyLong_FromLong(b);
 }
 
 static int init_types(void)

Modified: python/branches/py3k-importlib/Python/ast.c
==============================================================================
--- python/branches/py3k-importlib/Python/ast.c	(original)
+++ python/branches/py3k-importlib/Python/ast.c	Thu Mar 27 00:48:05 2008
@@ -19,6 +19,7 @@
 struct compiling {
     char *c_encoding; /* source encoding */
     PyArena *c_arena; /* arena for allocating memeory */
+    const char *c_filename; /* filename */
 };
 
 static asdl_seq *seq_for_testlist(struct compiling *, const node *);
@@ -55,7 +56,7 @@
        identifier; if so, normalize to NFKC. */
     for (; *u; u++) {
 	if (*u >= 128) {
-	    PyObject *m = PyImport_ImportModule("unicodedata");
+	    PyObject *m = PyImport_ImportModuleNoBlock("unicodedata");
 	    PyObject *id2;
 	    if (!m)
 		return NULL;
@@ -109,7 +110,7 @@
     if (!errstr)
         return;
     Py_INCREF(errstr);
-    lineno = PyInt_AsLong(PyTuple_GetItem(value, 1));
+    lineno = PyLong_AsLong(PyTuple_GetItem(value, 1));
     if (lineno == -1) {
         Py_DECREF(errstr);
         return;
@@ -226,6 +227,7 @@
         c.c_encoding = "utf-8";
     }
     c.c_arena = arena;
+    c.c_filename = filename;
 
     k = 0;
     switch (TYPE(n)) {
@@ -647,7 +649,11 @@
     arg_ty arg;
     int i = start;
     int j = 0; /* index for kwdefaults and kwonlyargs */
-    assert(kwonlyargs != NULL);
+
+    if (kwonlyargs == NULL) {
+        ast_error(CHILD(n, start), "named arguments must follow bare *");
+        return -1;
+    }
     assert(kwdefaults != NULL);
     while (i < NCH(n)) {
         ch = CHILD(n, i);
@@ -812,7 +818,8 @@
                 break;
             case STAR:
                 if (i+1 >= NCH(n)) {
-                    ast_error(CHILD(n, i), "no name for vararg");
+                    ast_error(CHILD(n, i), 
+                        "named arguments must follow bare *");
                     goto error;
                 }
                 ch = CHILD(n, i+1);  /* tfpdef or COMMA */
@@ -1008,6 +1015,12 @@
     } else if (TYPE(CHILD(n, 1)) == classdef) {
       thing = ast_for_classdef(c, CHILD(n, 1), decorator_seq);
     }
+    /* we count the decorators in when talking about the class' or
+     * function's line number */
+    if (thing) {
+        thing->lineno = LINENO(n);
+        thing->col_offset = n->n_col_offset;
+    }
     return thing;
 }
 
@@ -1292,14 +1305,14 @@
     case STRING: {
         PyObject *str = parsestrplus(c, n, &bytesmode);
         if (!str) {
-            if (PyErr_ExceptionMatches(PyExc_UnicodeError)){
+            if (PyErr_ExceptionMatches(PyExc_UnicodeError)) {
                 PyObject *type, *value, *tback, *errstr;
                 PyErr_Fetch(&type, &value, &tback);
                 errstr = ((PyUnicodeErrorObject *)value)->reason;
                 if (errstr) {
                     char *s = "";
                     char buf[128];
-                    s = PyString_AsString(errstr);
+                    s = PyUnicode_AsString(errstr);
                     PyOS_snprintf(buf, sizeof(buf), "(unicode error) %s", s);
                     ast_error(n, buf);
                 } else {
@@ -1539,7 +1552,7 @@
         tmp_result = BinOp(result, newoperator, tmp, 
                            LINENO(next_oper), next_oper->n_col_offset,
                            c->c_arena);
-        if (!tmp) 
+        if (!tmp_result) 
             return NULL;
         result = tmp_result;
     }
@@ -1981,10 +1994,14 @@
         }
         else if (TYPE(ch) == STAR) {
             vararg = ast_for_expr(c, CHILD(n, i+1));
+            if (!vararg)
+                return NULL;
             i++;
         }
         else if (TYPE(ch) == DOUBLESTAR) {
             kwarg = ast_for_expr(c, CHILD(n, i+1));
+            if (!kwarg)
+                return NULL;
             i++;
         }
     }
@@ -2369,10 +2386,6 @@
             /* from ... import * */
             n = CHILD(n, idx);
             n_children = 1;
-            if (ndots) {
-                ast_error(n, "'import *' not allowed with 'from .'");
-                return NULL;
-            }
             break;
         case LPAR:
             /* from ... import (x, y, z) */
@@ -3072,7 +3085,7 @@
     if (*end == '\0') {
         if (errno != 0)
             return PyLong_FromString((char *)s, (char **)0, 0);
-        return PyInt_FromLong(x);
+        return PyLong_FromLong(x);
     }
     /* XXX Huge floats may silently fail */
 #ifndef WITHOUT_COMPLEX
@@ -3117,6 +3130,7 @@
     char *buf;
     char *p;
     const char *end;
+
     if (encoding == NULL) {
         buf = (char *)s;
         u = NULL;
@@ -3147,9 +3161,8 @@
                     Py_DECREF(u);
                     return NULL;
                 }
-                assert(PyBytes_Check(w));
-                r = PyBytes_AsString(w);
-                rn = PyBytes_Size(w);
+                r = PyString_AS_STRING(w);
+                rn = Py_SIZE(w);
                 assert(rn % 2 == 0);
                 for (i = 0; i < rn; i += 2) {
                     sprintf(p, "\\u%02x%02x",
@@ -3174,7 +3187,7 @@
 }
 
 /* s is a Python string literal, including the bracketing quote characters,
- * and r &/or u prefixes (if any), and embedded escape sequences (if any).
+ * and r &/or b prefixes (if any), and embedded escape sequences (if any).
  * parsestr parses it, and returns the decoded Python string object.
  */
 static PyObject *
@@ -3186,7 +3199,7 @@
     int rawmode = 0;
     int need_encoding;
 
-    if (isalpha(quote) || quote == '_') {
+    if (isalpha(quote)) {
         if (quote == 'b' || quote == 'B') {
             quote = *++s;
             *bytesmode = 1;
@@ -3219,7 +3232,7 @@
             return NULL;
         }
     }
-    if (!*bytesmode) {
+    if (!*bytesmode && !rawmode) {
         return decode_unicode(s, len, rawmode, encoding);
     }
     if (*bytesmode) {
@@ -3239,13 +3252,17 @@
     if (rawmode || strchr(s, '\\') == NULL) {
         if (need_encoding) {
             PyObject *v, *u = PyUnicode_DecodeUTF8(s, len, NULL);
-            if (u == NULL)
-                return NULL;
+            if (u == NULL || !*bytesmode)
+                return u;
             v = PyUnicode_AsEncodedString(u, encoding, NULL);
             Py_DECREF(u);
             return v;
-        } else {
+        } else if (*bytesmode) {
             return PyString_FromStringAndSize(s, len);
+        } else if (strcmp(encoding, "utf-8") == 0) {
+            return PyUnicode_FromStringAndSize(s, len);
+	} else {
+            return PyUnicode_DecodeLatin1(s, len, NULL);
         }
     }
 
@@ -3253,7 +3270,7 @@
                                  need_encoding ? encoding : NULL);
 }
 
-/* Build a Python string object out of a STRING atom.  This takes care of
+/* Build a Python string object out of a STRING+ atom.  This takes care of
  * compile-time literal catenation, calling parsestr() on each piece, and
  * pasting the intermediate results together.
  */
@@ -3273,8 +3290,7 @@
             if (s == NULL)
                 goto onError;
             if (*bytesmode != subbm) {
-                ast_error(n, "cannot mix bytes and nonbytes"
-                          "literals");
+                ast_error(n, "cannot mix bytes and nonbytes literals");
                 goto onError;
             }
             if (PyString_Check(v) && PyString_Check(s)) {

Modified: python/branches/py3k-importlib/Python/bltinmodule.c
==============================================================================
--- python/branches/py3k-importlib/Python/bltinmodule.c	(original)
+++ python/branches/py3k-importlib/Python/bltinmodule.c	Thu Mar 27 00:48:05 2008
@@ -16,10 +16,13 @@
 */
 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
 const char *Py_FileSystemDefaultEncoding = "mbcs";
+const int Py_HasFileSystemDefaultEncoding = 1;
 #elif defined(__APPLE__)
 const char *Py_FileSystemDefaultEncoding = "utf-8";
+const int Py_HasFileSystemDefaultEncoding = 1;
 #else
 const char *Py_FileSystemDefaultEncoding = NULL; /* use default */
+const int Py_HasFileSystemDefaultEncoding = 0;
 #endif
 
 static PyObject *
@@ -181,13 +184,19 @@
 builtin_all(PyObject *self, PyObject *v)
 {
 	PyObject *it, *item;
+	PyObject *(*iternext)(PyObject *);
+	int cmp;
 
 	it = PyObject_GetIter(v);
 	if (it == NULL)
 		return NULL;
+	iternext = *Py_TYPE(it)->tp_iternext;
 
-	while ((item = PyIter_Next(it)) != NULL) {
-		int cmp = PyObject_IsTrue(item);
+	for (;;) {
+		item = iternext(it);
+		if (item == NULL)
+			break;
+		cmp = PyObject_IsTrue(item);
 		Py_DECREF(item);
 		if (cmp < 0) {
 			Py_DECREF(it);
@@ -199,8 +208,12 @@
 		}
 	}
 	Py_DECREF(it);
-	if (PyErr_Occurred())
-		return NULL;
+	if (PyErr_Occurred()) {
+		if (PyErr_ExceptionMatches(PyExc_StopIteration))
+			PyErr_Clear();
+		else
+			return NULL;
+	}
 	Py_RETURN_TRUE;
 }
 
@@ -213,13 +226,19 @@
 builtin_any(PyObject *self, PyObject *v)
 {
 	PyObject *it, *item;
+	PyObject *(*iternext)(PyObject *);
+	int cmp;
 
 	it = PyObject_GetIter(v);
 	if (it == NULL)
 		return NULL;
+	iternext = *Py_TYPE(it)->tp_iternext;
 
-	while ((item = PyIter_Next(it)) != NULL) {
-		int cmp = PyObject_IsTrue(item);
+	for (;;) {
+		item = iternext(it);
+		if (item == NULL)
+			break;
+		cmp = PyObject_IsTrue(item);
 		Py_DECREF(item);
 		if (cmp < 0) {
 			Py_DECREF(it);
@@ -231,8 +250,12 @@
 		}
 	}
 	Py_DECREF(it);
-	if (PyErr_Occurred())
-		return NULL;
+	if (PyErr_Occurred()) {
+		if (PyErr_ExceptionMatches(PyExc_StopIteration))
+			PyErr_Clear();
+		else
+			return NULL;
+	}
 	Py_RETURN_FALSE;
 }
 
@@ -254,85 +277,157 @@
 Return the binary representation of an integer or long integer.");
 
 
+typedef struct {
+	PyObject_HEAD
+	PyObject *func;
+	PyObject *it;
+} filterobject;
+
+PyTypeObject PyFilter_Type;
+
 static PyObject *
-builtin_filter(PyObject *self, PyObject *args)
+filter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-	PyObject *itertools, *ifilter, *result;
-	itertools = PyImport_ImportModule("itertools");
-	if (itertools == NULL)
-		return NULL;
-	ifilter = PyObject_GetAttrString(itertools, "ifilter");
-	Py_DECREF(itertools);
-	if (ifilter == NULL)
+	PyObject *func, *seq;
+	PyObject *it;
+	filterobject *lz;
+
+	if (type == &PyFilter_Type && !_PyArg_NoKeywords("filter()", kwds))
 		return NULL;
-	result = PyObject_Call(ifilter, args, NULL);
-	Py_DECREF(ifilter);
-	return result;
+
+	if (!PyArg_UnpackTuple(args, "filter", 2, 2, &func, &seq))
+		return NULL;
+
+	/* Get iterator. */
+	it = PyObject_GetIter(seq);
+	if (it == NULL)
+		return NULL;
+
+	/* create filterobject structure */
+	lz = (filterobject *)type->tp_alloc(type, 0);
+	if (lz == NULL) {
+		Py_DECREF(it);
+		return NULL;
+	}
+	Py_INCREF(func);
+	lz->func = func;
+	lz->it = it;
+
+	return (PyObject *)lz;
 }
 
-PyDoc_STRVAR(filter_doc,
-"filter(predicate, iterable) -> iterator\n\
-\n\
-Return an iterator yielding only those elements of the input iterable\n\
-for which the predicate (a Boolean function) returns true.\n\
-If the predicate is None, 'lambda x: bool(x)' is assumed.\n\
-(This is identical to itertools.ifilter().)");
+static void
+filter_dealloc(filterobject *lz)
+{
+	PyObject_GC_UnTrack(lz);
+	Py_XDECREF(lz->func);
+	Py_XDECREF(lz->it);
+	Py_TYPE(lz)->tp_free(lz);
+}
+
+static int
+filter_traverse(filterobject *lz, visitproc visit, void *arg)
+{
+	Py_VISIT(lz->it);
+	Py_VISIT(lz->func);
+	return 0;
+}
 
 static PyObject *
-builtin_format(PyObject *self, PyObject *args)
+filter_next(filterobject *lz)
 {
-        static PyObject * format_str = NULL;
-        PyObject *value;
-        PyObject *spec = NULL;
-        PyObject *meth;
-        PyObject *empty = NULL;
-        PyObject *result = NULL;
-
-        /* Initialize cached value */
-        if (format_str == NULL) {
-                /* Initialize static variable needed by _PyType_Lookup */
-                format_str = PyUnicode_FromString("__format__");
-                if (format_str == NULL)
-                        goto done;
-        }
+	PyObject *item;
+	PyObject *it = lz->it;
+	long ok;
+	PyObject *(*iternext)(PyObject *);
 
-        if (!PyArg_ParseTuple(args, "O|U:format", &value, &spec))
-               goto done;
+	assert(PyIter_Check(it));
+	iternext = *Py_TYPE(it)->tp_iternext;
+	for (;;) {
+		item = iternext(it);
+		if (item == NULL)
+			return NULL;
 
-        /* initialize the default value */
-        if (spec == NULL) {
-            empty = PyUnicode_FromUnicode(NULL, 0);
-            spec = empty;
-        }
+		if (lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type) {
+			ok = PyObject_IsTrue(item);
+		} else {
+			PyObject *good;
+			good = PyObject_CallFunctionObjArgs(lz->func,
+							    item, NULL);
+			if (good == NULL) {
+				Py_DECREF(item);
+				return NULL;
+			}
+			ok = PyObject_IsTrue(good);
+			Py_DECREF(good);
+		}
+		if (ok)
+			return item;
+		Py_DECREF(item);
+	}
+}
 
-        /* Make sure the type is initialized.  float gets initialized late */
-        if (Py_Type(value)->tp_dict == NULL)
-                if (PyType_Ready(Py_Type(value)) < 0)
-                        goto done;
-
-        /* Find the (unbound!) __format__ method (a borrowed reference) */
-        meth = _PyType_Lookup(Py_Type(value), format_str);
-        if (meth == NULL) {
-                PyErr_Format(PyExc_TypeError,
-                             "Type %.100s doesn't define __format__",
-                             Py_Type(value)->tp_name);
-                goto done;
-        }
+PyDoc_STRVAR(filter_doc,
+"filter(function or None, sequence) --> filter object\n\
+\n\
+Return an iterator yielding those items of sequence for which function(item)\n\
+is true. If function is None, return the items that are true.");
+
+PyTypeObject PyFilter_Type = {
+	PyVarObject_HEAD_INIT(&PyType_Type, 0)
+	"filter",			/* tp_name */
+	sizeof(filterobject),		/* tp_basicsize */
+	0,				/* tp_itemsize */
+	/* methods */
+	(destructor)filter_dealloc,	/* tp_dealloc */
+	0,				/* tp_print */
+	0,				/* tp_getattr */
+	0,				/* tp_setattr */
+	0,				/* tp_compare */
+	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_HAVE_GC |
+		Py_TPFLAGS_BASETYPE,	/* tp_flags */
+	filter_doc,			/* tp_doc */
+	(traverseproc)filter_traverse,	/* tp_traverse */
+	0,				/* tp_clear */
+	0,				/* tp_richcompare */
+	0,				/* tp_weaklistoffset */
+	PyObject_SelfIter,		/* tp_iter */
+	(iternextfunc)filter_next,	/* tp_iternext */
+	0,				/* 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 */
+	PyType_GenericAlloc,		/* tp_alloc */
+	filter_new,			/* tp_new */
+	PyObject_GC_Del,		/* tp_free */
+};
 
-        /* And call it, binding it to the value */
-        result = PyObject_CallFunctionObjArgs(meth, value, spec, NULL);
 
-        if (result && !PyUnicode_Check(result)) {
-                PyErr_SetString(PyExc_TypeError,
-                                "__format__ method did not return string");
-                Py_DECREF(result);
-                result = NULL;
-                goto done;
-        }
+static PyObject *
+builtin_format(PyObject *self, PyObject *args)
+{
+    PyObject *value;
+    PyObject *format_spec = NULL;
+
+    if (!PyArg_ParseTuple(args, "O|U:format", &value, &format_spec))
+        return NULL;
 
-done:
-        Py_XDECREF(empty);
-        return result;
+    return PyObject_Format(value, format_spec);
 }
 
 PyDoc_STRVAR(format_doc,
@@ -375,7 +470,7 @@
 		return NULL;
 	if (PyObject_Cmp(a, b, &c) < 0)
 		return NULL;
-	return PyInt_FromLong((long)c);
+	return PyLong_FromLong((long)c);
 }
 
 PyDoc_STRVAR(cmp_doc,
@@ -769,32 +864,153 @@
 simultaneously existing objects.  (Hint: it's the object's memory address.)");
 
 
+/* map object ************************************************************/
+
+typedef struct {
+	PyObject_HEAD
+	PyObject *iters;
+	PyObject *func;
+} mapobject;
+
+PyTypeObject PyMap_Type;
+
+static PyObject *
+map_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+	PyObject *it, *iters, *func;
+	mapobject *lz;
+	Py_ssize_t numargs, i;
+
+	if (type == &PyMap_Type && !_PyArg_NoKeywords("map()", kwds))
+		return NULL;
+
+	numargs = PyTuple_Size(args);
+	if (numargs < 2) {
+		PyErr_SetString(PyExc_TypeError,
+		   "map() must have at least two arguments.");
+		return NULL;
+	}
+
+	iters = PyTuple_New(numargs-1);
+	if (iters == NULL)
+		return NULL;
+
+	for (i=1 ; i<numargs ; i++) {
+		/* Get iterator. */
+		it = PyObject_GetIter(PyTuple_GET_ITEM(args, i));
+		if (it == NULL) {
+			Py_DECREF(iters);
+			return NULL;
+		}
+		PyTuple_SET_ITEM(iters, i-1, it);
+	}
+
+	/* create mapobject structure */
+	lz = (mapobject *)type->tp_alloc(type, 0);
+	if (lz == NULL) {
+		Py_DECREF(iters);
+		return NULL;
+	}
+	lz->iters = iters;
+	func = PyTuple_GET_ITEM(args, 0);
+	Py_INCREF(func);
+	lz->func = func;
+
+	return (PyObject *)lz;
+}
+
+static void
+map_dealloc(mapobject *lz)
+{
+	PyObject_GC_UnTrack(lz);
+	Py_XDECREF(lz->iters);
+	Py_XDECREF(lz->func);
+	Py_TYPE(lz)->tp_free(lz);
+}
+
+static int
+map_traverse(mapobject *lz, visitproc visit, void *arg)
+{
+	Py_VISIT(lz->iters);
+	Py_VISIT(lz->func);
+	return 0;
+}
+
 static PyObject *
-builtin_map(PyObject *self, PyObject *args)
+map_next(mapobject *lz)
 {
-	PyObject *itertools, *imap, *result;
-	itertools = PyImport_ImportModule("itertools");
-	if (itertools == NULL)
-		return NULL;
-	imap = PyObject_GetAttrString(itertools, "imap");
-	Py_DECREF(itertools);
-	if (imap == NULL)
+	PyObject *val;
+	PyObject *argtuple;
+	PyObject *result;
+	Py_ssize_t numargs, i;
+
+	numargs = PyTuple_Size(lz->iters);
+	argtuple = PyTuple_New(numargs);
+	if (argtuple == NULL)
 		return NULL;
-	result = PyObject_Call(imap, args, NULL);
-	Py_DECREF(imap);
+
+	for (i=0 ; i<numargs ; i++) {
+		val = PyIter_Next(PyTuple_GET_ITEM(lz->iters, i));
+		if (val == NULL) {
+			Py_DECREF(argtuple);
+			return NULL;
+		}
+		PyTuple_SET_ITEM(argtuple, i, val);
+	}
+	result = PyObject_Call(lz->func, argtuple, NULL);
+	Py_DECREF(argtuple);
 	return result;
 }
 
 PyDoc_STRVAR(map_doc,
-"map(function, iterable[, iterable, ...]) -> iterator\n\
+"map(func, *iterables) --> map object\n\
 \n\
-Return an iterator yielding the results of applying the function to the\n\
-items of the argument iterables(s).  If more than one iterable is given,\n\
-the function is called with an argument list consisting of the\n\
-corresponding item of each iterable, until an iterable is exhausted.\n\
-If the function is None, 'lambda *a: a' is assumed.\n\
-(This is identical to itertools.imap().)");
+Make an iterator that computes the function using arguments from\n\
+each of the iterables.	Stops when the shortest iterable is exhausted.");
 
+PyTypeObject PyMap_Type = {
+	PyVarObject_HEAD_INIT(&PyType_Type, 0)
+	"map",				/* tp_name */
+	sizeof(mapobject),		/* tp_basicsize */
+	0,				/* tp_itemsize */
+	/* methods */
+	(destructor)map_dealloc,	/* tp_dealloc */
+	0,				/* tp_print */
+	0,				/* tp_getattr */
+	0,				/* tp_setattr */
+	0,				/* tp_compare */
+	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_HAVE_GC |
+		Py_TPFLAGS_BASETYPE,	/* tp_flags */
+	map_doc,			/* tp_doc */
+	(traverseproc)map_traverse,	/* tp_traverse */
+	0,				/* tp_clear */
+	0,				/* tp_richcompare */
+	0,				/* tp_weaklistoffset */
+	PyObject_SelfIter,		/* tp_iter */
+	(iternextfunc)map_next,	/* tp_iternext */
+	0,				/* 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 */
+	PyType_GenericAlloc,		/* tp_alloc */
+	map_new,			/* tp_new */
+	PyObject_GC_Del,		/* tp_free */
+};
 
 static PyObject *
 builtin_next(PyObject *self, PyObject *args)
@@ -887,7 +1103,7 @@
 	x = PyObject_Hash(v);
 	if (x == -1)
 		return NULL;
-	return PyInt_FromLong(x);
+	return PyLong_FromLong(x);
 }
 
 PyDoc_STRVAR(hash_doc,
@@ -943,7 +1159,7 @@
 	res = PyObject_Size(v);
 	if (res < 0 && PyErr_Occurred())
 		return NULL;
-	return PyInt_FromSsize_t(res);
+	return PyLong_FromSsize_t(res);
 }
 
 PyDoc_STRVAR(len_doc,
@@ -986,11 +1202,14 @@
 				"%s() got an unexpected keyword argument", name);
 			return NULL;
 		}
+		Py_INCREF(keyfunc);
 	}
 
 	it = PyObject_GetIter(v);
-	if (it == NULL)
+	if (it == NULL) {
+		Py_XDECREF(keyfunc);
 		return NULL;
+	}
 
 	maxitem = NULL; /* the result */
 	maxval = NULL;  /* the value associated with the result */
@@ -1039,6 +1258,7 @@
 	else
 		Py_DECREF(maxval);
 	Py_DECREF(it);
+	Py_XDECREF(keyfunc);
 	return maxitem;
 
 Fail_it_item_and_val:
@@ -1049,6 +1269,7 @@
 	Py_XDECREF(maxval);
 	Py_XDECREF(maxitem);
 	Py_DECREF(it);
+	Py_XDECREF(keyfunc);
 	return NULL;
 }
 
@@ -1102,14 +1323,14 @@
 		size = PyString_GET_SIZE(obj);
 		if (size == 1) {
 			ord = (long)((unsigned char)*PyString_AS_STRING(obj));
-			return PyInt_FromLong(ord);
+			return PyLong_FromLong(ord);
 		}
 	}
 	else if (PyUnicode_Check(obj)) {
 		size = PyUnicode_GET_SIZE(obj);
 		if (size == 1) {
 			ord = (long)*PyUnicode_AS_UNICODE(obj);
-			return PyInt_FromLong(ord);
+			return PyLong_FromLong(ord);
 		}
 #ifndef Py_UNICODE_WIDE
 		if (size == 2) {
@@ -1120,7 +1341,7 @@
 			    0xDC00 <= c1 && c1 <= 0xDFFF) {
 				ord = ((((c0 & 0x03FF) << 10) | (c1 & 0x03FF)) +
 				       0x00010000);
-				return PyInt_FromLong(ord);
+				return PyLong_FromLong(ord);
 			}
 		}
 #endif
@@ -1130,7 +1351,7 @@
 		size = PyBytes_GET_SIZE(obj);
 		if (size == 1) {
 			ord = (long)((unsigned char)*PyBytes_AS_STRING(obj));
-			return PyInt_FromLong(ord);
+			return PyLong_FromLong(ord);
 		}
 	}
 	else {
@@ -1192,9 +1413,13 @@
 	}
 	if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:print",
 					 kwlist, &sep, &end, &file))
-                return NULL;
-	if (file == NULL || file == Py_None)
+		return NULL;
+	if (file == NULL || file == Py_None) {
 		file = PySys_GetObject("stdout");
+		/* sys.stdout may be None when FILE* stdout isn't connected */
+		if (file == Py_None)
+			Py_RETURN_NONE;
+	}
 
 	if (sep && sep != Py_None && !PyUnicode_Check(sep)) {
 		PyErr_Format(PyExc_TypeError,
@@ -1236,7 +1461,7 @@
 }
 
 PyDoc_STRVAR(print_doc,
-"print(value, ..., file=None, sep=' ', end='\\n')\n\
+"print(value, ..., sep=' ', end='\\n', file=sys.stdout)\n\
 \n\
 Prints the values to a stream, or to sys.stdout by default.\n\
 Optional keyword arguments:\n\
@@ -1261,17 +1486,17 @@
 		return NULL;
 
 	/* Check that stdin/out/err are intact */
-	if (fin == NULL) {
+	if (fin == NULL || fin == Py_None) {
 		PyErr_SetString(PyExc_RuntimeError,
 				"input(): lost sys.stdin");
 		return NULL;
 	}
-	if (fout == NULL) {
+	if (fout == NULL || fout == Py_None) {
 		PyErr_SetString(PyExc_RuntimeError,
 				"input(): lost sys.stdout");
 		return NULL;
 	}
-	if (ferr == NULL) {
+	if (ferr == NULL || ferr == Py_None) {
 		PyErr_SetString(PyExc_RuntimeError,
 				"input(): lost sys.stderr");
 		return NULL;
@@ -1293,7 +1518,7 @@
 		tty = 0;
 	}
 	else {
-		fd = PyInt_AsLong(tmp);
+		fd = PyLong_AsLong(tmp);
 		Py_DECREF(tmp);
 		if (fd < 0 && PyErr_Occurred())
 			return NULL;
@@ -1304,7 +1529,7 @@
 		if (tmp == NULL)
 			PyErr_Clear();
 		else {
-			fd = PyInt_AsLong(tmp);
+			fd = PyLong_AsLong(tmp);
 			Py_DECREF(tmp);
 			if (fd < 0 && PyErr_Occurred())
 				return NULL;
@@ -1336,7 +1561,7 @@
 				Py_DECREF(stdin_encoding);
 				return NULL;
 			}
-			prompt = PyString_AsString(po);
+			prompt = PyUnicode_AsString(po);
 			if (prompt == NULL) {
 				Py_DECREF(stdin_encoding);
 				Py_DECREF(po);
@@ -1426,22 +1651,22 @@
                 kwlist, &number, &ndigits))
                 return NULL;
 
-	if (Py_Type(number)->tp_dict == NULL) {
-		if (PyType_Ready(Py_Type(number)) < 0)
+	if (Py_TYPE(number)->tp_dict == NULL) {
+		if (PyType_Ready(Py_TYPE(number)) < 0)
 			return NULL;
 	}
 
 	if (round_str == NULL) {
-		round_str = PyUnicode_FromString("__round__");
+		round_str = PyUnicode_InternFromString("__round__");
 		if (round_str == NULL)
 			return NULL;
 	}
 
-	round = _PyType_Lookup(Py_Type(number), round_str);
+	round = _PyType_Lookup(Py_TYPE(number), round_str);
 	if (round == NULL) {
 		PyErr_Format(PyExc_TypeError,
 			     "type %.100s doesn't define __round__ method",
-			     Py_Type(number)->tp_name);
+			     Py_TYPE(number)->tp_name);
 		return NULL;
 	}
 
@@ -1463,14 +1688,14 @@
 static PyObject *
 builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
 {
-	PyObject *newlist, *v, *seq, *compare=NULL, *keyfunc=NULL, *newargs;
+	PyObject *newlist, *v, *seq, *keyfunc=NULL, *newargs;
 	PyObject *callable;
-	static char *kwlist[] = {"iterable", "cmp", "key", "reverse", 0};
+	static char *kwlist[] = {"iterable", "key", "reverse", 0};
 	int reverse;
 
-	/* args 1-4 should match listsort in Objects/listobject.c */
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOi:sorted",
-		kwlist, &seq, &compare, &keyfunc, &reverse))
+	/* args 1-3 should match listsort in Objects/listobject.c */
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted",
+		kwlist, &seq, &keyfunc, &reverse))
 		return NULL;
 
 	newlist = PySequence_List(seq);
@@ -1502,7 +1727,7 @@
 }
 
 PyDoc_STRVAR(sorted_doc,
-"sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list");
+"sorted(iterable, key=None, reverse=False) --> new sorted list");
 
 static PyObject *
 builtin_vars(PyObject *self, PyObject *args)
@@ -1539,40 +1764,6 @@
 Without arguments, equivalent to locals().\n\
 With an argument, equivalent to object.__dict__.");
 
-static PyObject *
-builtin_trunc(PyObject *self, PyObject *number)
-{
-	static PyObject *trunc_str = NULL;
-	PyObject *trunc;
-
-	if (Py_Type(number)->tp_dict == NULL) {
-		if (PyType_Ready(Py_Type(number)) < 0)
-			return NULL;
-	}
-
-	if (trunc_str == NULL) {
-		trunc_str = PyUnicode_FromString("__trunc__");
-		if (trunc_str == NULL)
-			return NULL;
-	}
-
-	trunc = _PyType_Lookup(Py_Type(number), trunc_str);
-	if (trunc == NULL) {
-		PyErr_Format(PyExc_TypeError,
-			     "type %.100s doesn't define __trunc__ method",
-			     Py_Type(number)->tp_name);
-		return NULL;
-	}
-	return PyObject_CallFunction(trunc, "O", number);
-}
-
-PyDoc_STRVAR(trunc_doc,
-"trunc(Real) -> Integral\n\
-\n\
-returns the integral closest to x between 0 and x.");
-
-
-
 static PyObject*
 builtin_sum(PyObject *self, PyObject *args)
 {
@@ -1588,22 +1779,116 @@
 		return NULL;
 
 	if (result == NULL) {
-		result = PyInt_FromLong(0);
+		result = PyLong_FromLong(0);
 		if (result == NULL) {
 			Py_DECREF(iter);
 			return NULL;
 		}
 	} else {
 		/* reject string values for 'start' parameter */
-		if (PyObject_TypeCheck(result, &PyBaseString_Type)) {
+		if (PyUnicode_Check(result)) {
 			PyErr_SetString(PyExc_TypeError,
 				"sum() can't sum strings [use ''.join(seq) instead]");
 			Py_DECREF(iter);
 			return NULL;
 		}
+		if (PyBytes_Check(result)) {
+			PyErr_SetString(PyExc_TypeError,
+				"sum() can't sum bytes [use b''.join(seq) instead]");
+			Py_DECREF(iter);
+			return NULL;
+		}
+
 		Py_INCREF(result);
 	}
 
+#ifndef SLOW_SUM
+	/* Fast addition by keeping temporary sums in C instead of new Python objects.
+           Assumes all inputs are the same type.  If the assumption fails, default
+           to the more general routine.
+	*/
+	if (PyLong_CheckExact(result)) {
+		int overflow;
+		long i_result = PyLong_AsLongAndOverflow(result, &overflow);
+		/* If this already overflowed, don't even enter the loop. */
+		if (overflow == 0) {
+			Py_DECREF(result);
+			result = NULL;
+		}
+		while(result == NULL) {
+			item = PyIter_Next(iter);
+			if (item == NULL) {
+				Py_DECREF(iter);
+				if (PyErr_Occurred())
+					return NULL;
+    				return PyLong_FromLong(i_result);
+			}
+        		if (PyLong_CheckExact(item)) {
+            			long b = PyLong_AsLongAndOverflow(item, &overflow);
+				long x = i_result + b;
+				if (overflow == 0 && ((x^i_result) >= 0 || (x^b) >= 0)) {
+					i_result = x;
+					Py_DECREF(item);
+					continue;
+				}
+			}
+			/* Either overflowed or is not an int. Restore real objects and process normally */
+			result = PyLong_FromLong(i_result);
+			temp = PyNumber_Add(result, item);
+			Py_DECREF(result);
+			Py_DECREF(item);
+			result = temp;
+			if (result == NULL) {
+				Py_DECREF(iter);
+				return NULL;
+			}
+		}
+	}
+
+	if (PyFloat_CheckExact(result)) {
+		double f_result = PyFloat_AS_DOUBLE(result);
+		Py_DECREF(result);
+		result = NULL;
+		while(result == NULL) {
+			item = PyIter_Next(iter);
+			if (item == NULL) {
+				Py_DECREF(iter);
+				if (PyErr_Occurred())
+					return NULL;
+    				return PyFloat_FromDouble(f_result);
+			}
+        		if (PyFloat_CheckExact(item)) {
+				PyFPE_START_PROTECT("add", return 0)
+				f_result += PyFloat_AS_DOUBLE(item);
+				PyFPE_END_PROTECT(f_result)
+				Py_DECREF(item);
+				continue;
+			}
+        		if (PyLong_CheckExact(item)) {
+				long value;
+				int overflow;
+				value = PyLong_AsLongAndOverflow(item, &overflow);
+				if (!overflow) {
+					PyFPE_START_PROTECT("add", return 0)
+					f_result += (double)value;
+					PyFPE_END_PROTECT(f_result)
+					Py_DECREF(item);
+					continue;
+				}
+			}
+			result = PyFloat_FromDouble(f_result);
+			temp = PyNumber_Add(result, item);
+			Py_DECREF(result);
+			Py_DECREF(item);
+			result = temp;
+			if (result == NULL) {
+				Py_DECREF(iter);
+				return NULL;
+			}
+		}
+	}
+#endif
+
 	for(;;) {
 		item = PyIter_Next(iter);
 		if (item == NULL) {
@@ -1682,23 +1967,187 @@
 is a shortcut for issubclass(X, A) or issubclass(X, B) or ... (etc.).");
 
 
-static PyObject*
-builtin_zip(PyObject *self, PyObject *args)
+typedef struct {
+	PyObject_HEAD
+	Py_ssize_t	tuplesize;
+	PyObject *ittuple;		/* tuple of iterators */
+	PyObject *result;
+} zipobject;
+
+PyTypeObject PyZip_Type;
+
+static PyObject *
+zip_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
+	zipobject *lz;
+	Py_ssize_t i;
+	PyObject *ittuple;  /* tuple of iterators */
+	PyObject *result;
+	Py_ssize_t tuplesize = PySequence_Length(args);
+
+	if (type == &PyZip_Type && !_PyArg_NoKeywords("zip()", kwds))
+		return NULL;
+
 	/* args must be a tuple */
 	assert(PyTuple_Check(args));
 
-	return _PyZip_CreateIter(args);
+	/* obtain iterators */
+	ittuple = PyTuple_New(tuplesize);
+	if (ittuple == NULL)
+		return NULL;
+	for (i=0; i < tuplesize; ++i) {
+		PyObject *item = PyTuple_GET_ITEM(args, i);
+		PyObject *it = PyObject_GetIter(item);
+		if (it == NULL) {
+			if (PyErr_ExceptionMatches(PyExc_TypeError))
+				PyErr_Format(PyExc_TypeError,
+				    "zip argument #%zd must support iteration",
+				    i+1);
+			Py_DECREF(ittuple);
+			return NULL;
+		}
+		PyTuple_SET_ITEM(ittuple, i, it);
+	}
+
+	/* create a result holder */
+	result = PyTuple_New(tuplesize);
+	if (result == NULL) {
+		Py_DECREF(ittuple);
+		return NULL;
+	}
+	for (i=0 ; i < tuplesize ; i++) {
+		Py_INCREF(Py_None);
+		PyTuple_SET_ITEM(result, i, Py_None);
+	}
+
+	/* create zipobject structure */
+	lz = (zipobject *)type->tp_alloc(type, 0);
+	if (lz == NULL) {
+		Py_DECREF(ittuple);
+		Py_DECREF(result);
+		return NULL;
+	}
+	lz->ittuple = ittuple;
+	lz->tuplesize = tuplesize;
+	lz->result = result;
+
+	return (PyObject *)lz;
+}
+
+static void
+zip_dealloc(zipobject *lz)
+{
+	PyObject_GC_UnTrack(lz);
+	Py_XDECREF(lz->ittuple);
+	Py_XDECREF(lz->result);
+	Py_TYPE(lz)->tp_free(lz);
+}
+
+static int
+zip_traverse(zipobject *lz, visitproc visit, void *arg)
+{
+	Py_VISIT(lz->ittuple);
+	Py_VISIT(lz->result);
+	return 0;
 }
 
+static PyObject *
+zip_next(zipobject *lz)
+{
+	Py_ssize_t i;
+	Py_ssize_t tuplesize = lz->tuplesize;
+	PyObject *result = lz->result;
+	PyObject *it;
+	PyObject *item;
+	PyObject *olditem;
+
+	if (tuplesize == 0)
+		return NULL;
+	if (Py_REFCNT(result) == 1) {
+		Py_INCREF(result);
+		for (i=0 ; i < tuplesize ; i++) {
+			it = PyTuple_GET_ITEM(lz->ittuple, i);
+			assert(PyIter_Check(it));
+			item = (*Py_TYPE(it)->tp_iternext)(it);
+			if (item == NULL) {
+				Py_DECREF(result);
+				return NULL;
+			}
+			olditem = PyTuple_GET_ITEM(result, i);
+			PyTuple_SET_ITEM(result, i, item);
+			Py_DECREF(olditem);
+		}
+	} else {
+		result = PyTuple_New(tuplesize);
+		if (result == NULL)
+			return NULL;
+		for (i=0 ; i < tuplesize ; i++) {
+			it = PyTuple_GET_ITEM(lz->ittuple, i);
+			assert(PyIter_Check(it));
+			item = (*Py_TYPE(it)->tp_iternext)(it);
+			if (item == NULL) {
+				Py_DECREF(result);
+				return NULL;
+			}
+			PyTuple_SET_ITEM(result, i, item);
+		}
+	}
+	return result;
+}
 
 PyDoc_STRVAR(zip_doc,
-"zip(it1 [, it2 [...]]) -> iter([(it1[0], it2[0] ...), ...])\n\
+"zip(iter1 [,iter2 [...]]) --> zip object\n\
 \n\
-Return an iterator yielding tuples, where each tuple contains the\n\
-corresponding element from each of the argument iterables.\n\
-The returned iterator ends when the shortest argument iterable is exhausted.\n\
-(This is identical to itertools.izip().)");
+Return a zip object whose .__next__() method returns a tuple where\n\
+the i-th element comes from the i-th iterable argument.  The .__next__()\n\
+method continues until the shortest iterable in the argument sequence\n\
+is exhausted and then it raises StopIteration.  Works like the zip()\n\
+function but consumes less memory by returning an iterator instead of\n\
+a list.");
+
+PyTypeObject PyZip_Type = {
+	PyVarObject_HEAD_INIT(&PyType_Type, 0)
+	"zip",				/* tp_name */
+	sizeof(zipobject),		/* tp_basicsize */
+	0,				/* tp_itemsize */
+	/* methods */
+	(destructor)zip_dealloc,	/* tp_dealloc */
+	0,				/* tp_print */
+	0,				/* tp_getattr */
+	0,				/* tp_setattr */
+	0,				/* tp_compare */
+	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_HAVE_GC |
+		Py_TPFLAGS_BASETYPE,	/* tp_flags */
+	zip_doc,			/* tp_doc */
+	(traverseproc)zip_traverse,    /* tp_traverse */
+	0,				/* tp_clear */
+	0,				/* tp_richcompare */
+	0,				/* tp_weaklistoffset */
+	PyObject_SelfIter,		/* tp_iter */
+	(iternextfunc)zip_next,	/* tp_iternext */
+	0,				/* 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 */
+	PyType_GenericAlloc,		/* tp_alloc */
+	zip_new,			/* tp_new */
+	PyObject_GC_Del,		/* tp_free */
+};
 
 
 static PyMethodDef builtin_methods[] = {
@@ -1717,7 +2166,6 @@
  	{"divmod",	builtin_divmod,     METH_VARARGS, divmod_doc},
  	{"eval",	builtin_eval,       METH_VARARGS, eval_doc},
 	{"exec",        builtin_exec,       METH_VARARGS, exec_doc},
- 	{"filter",	builtin_filter,     METH_VARARGS, filter_doc},
  	{"format",	builtin_format,     METH_VARARGS, format_doc},
  	{"getattr",	builtin_getattr,    METH_VARARGS, getattr_doc},
  	{"globals",	(PyCFunction)builtin_globals,    METH_NOARGS, globals_doc},
@@ -1731,7 +2179,6 @@
  	{"iter",	builtin_iter,       METH_VARARGS, iter_doc},
  	{"len",		builtin_len,        METH_O, len_doc},
  	{"locals",	(PyCFunction)builtin_locals,     METH_NOARGS, locals_doc},
- 	{"map",		builtin_map,        METH_VARARGS, map_doc},
  	{"max",		(PyCFunction)builtin_max,        METH_VARARGS | METH_KEYWORDS, max_doc},
  	{"min",		(PyCFunction)builtin_min,        METH_VARARGS | METH_KEYWORDS, min_doc},
 	{"next",	(PyCFunction)builtin_next,       METH_VARARGS, next_doc},
@@ -1745,8 +2192,6 @@
  	{"sorted",	(PyCFunction)builtin_sorted,     METH_VARARGS | METH_KEYWORDS, sorted_doc},
  	{"sum",		builtin_sum,        METH_VARARGS, sum_doc},
  	{"vars",	builtin_vars,       METH_VARARGS, vars_doc},
- 	{"trunc",	builtin_trunc,      METH_O, trunc_doc},
-  	{"zip",         builtin_zip,        METH_VARARGS, zip_doc},
 	{NULL,		NULL},
 };
 
@@ -1759,7 +2204,7 @@
 _PyBuiltin_Init(void)
 {
 	PyObject *mod, *dict, *debug;
-	mod = Py_InitModule4("__builtin__", builtin_methods,
+	mod = Py_InitModule4("builtins", builtin_methods,
 			     builtin_doc, (PyObject *)NULL,
 			     PYTHON_API_VERSION);
 	if (mod == NULL)
@@ -1767,7 +2212,7 @@
 	dict = PyModule_GetDict(mod);
 
 #ifdef Py_TRACE_REFS
-	/* __builtin__ exposes a number of statically allocated objects
+	/* "builtins" exposes a number of statically allocated objects
 	 * that, before this code was added in 2.3, never showed up in
 	 * the list of "all objects" maintained by Py_TRACE_REFS.  As a
 	 * result, programs leaking references to None and False (etc)
@@ -1788,21 +2233,23 @@
 	SETBUILTIN("NotImplemented",	Py_NotImplemented);
 	SETBUILTIN("False",		Py_False);
 	SETBUILTIN("True",		Py_True);
-	SETBUILTIN("basestring",	&PyBaseString_Type);
 	SETBUILTIN("bool",		&PyBool_Type);
         SETBUILTIN("memoryview",        &PyMemoryView_Type);
-	SETBUILTIN("bytes",		&PyBytes_Type);
+	SETBUILTIN("bytearray",		&PyBytes_Type);
+	SETBUILTIN("bytes",		&PyString_Type);
 	SETBUILTIN("classmethod",	&PyClassMethod_Type);
 #ifndef WITHOUT_COMPLEX
 	SETBUILTIN("complex",		&PyComplex_Type);
 #endif
 	SETBUILTIN("dict",		&PyDict_Type);
  	SETBUILTIN("enumerate",		&PyEnum_Type);
+ 	SETBUILTIN("filter",		&PyFilter_Type);
 	SETBUILTIN("float",		&PyFloat_Type);
 	SETBUILTIN("frozenset",		&PyFrozenSet_Type);
 	SETBUILTIN("property",		&PyProperty_Type);
 	SETBUILTIN("int",		&PyLong_Type);
 	SETBUILTIN("list",		&PyList_Type);
+	SETBUILTIN("map",		&PyMap_Type);
 	SETBUILTIN("object",		&PyBaseObject_Type);
 	SETBUILTIN("range",		&PyRange_Type);
 	SETBUILTIN("reversed",		&PyReversed_Type);
@@ -1810,10 +2257,10 @@
 	SETBUILTIN("slice",		&PySlice_Type);
 	SETBUILTIN("staticmethod",	&PyStaticMethod_Type);
 	SETBUILTIN("str",		&PyUnicode_Type);
-	SETBUILTIN("str8",		&PyString_Type);
 	SETBUILTIN("super",		&PySuper_Type);
 	SETBUILTIN("tuple",		&PyTuple_Type);
 	SETBUILTIN("type",		&PyType_Type);
+	SETBUILTIN("zip",		&PyZip_Type);
 	debug = PyBool_FromLong(Py_OptimizeFlag == 0);
 	if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
 		Py_XDECREF(debug);

Modified: python/branches/py3k-importlib/Python/ceval.c
==============================================================================
--- python/branches/py3k-importlib/Python/ceval.c	(original)
+++ python/branches/py3k-importlib/Python/ceval.c	Thu Mar 27 00:48:05 2008
@@ -107,7 +107,7 @@
 #endif
 static int call_trace(Py_tracefunc, PyObject *, PyFrameObject *,
 		      int, PyObject *);
-static void call_trace_protected(Py_tracefunc, PyObject *,
+static int call_trace_protected(Py_tracefunc, PyObject *,
 				 PyFrameObject *, int, PyObject *);
 static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);
 static int maybe_call_line_trace(Py_tracefunc, PyObject *,
@@ -119,8 +119,8 @@
 static void set_exc_info(PyThreadState *, PyObject *, PyObject *, PyObject *);
 static void reset_exc_info(PyThreadState *);
 static void format_exc_check_arg(PyObject *, const char *, PyObject *);
-static PyObject * string_concatenate(PyObject *, PyObject *,
-				    PyFrameObject *, unsigned char *);
+static PyObject * unicode_concatenate(PyObject *, PyObject *,
+                                      PyFrameObject *, unsigned char *);
 
 #define NAME_ERROR_MSG \
 	"name '%.200s' is not defined"
@@ -625,7 +625,7 @@
 	next opcode.
 
 	A successful prediction saves a trip through the eval-loop including
-	its two unpredictable branches, the HASARG test and the switch-case.
+	its two unpredictable branches, the HAS_ARG test and the switch-case.
 
         If collecting opcode statistics, turn off prediction so that
 	statistics are accurately maintained (the predictions bypass
@@ -668,8 +668,9 @@
 #define STACKADJ(n)	{ (void)(BASIC_STACKADJ(n), \
                                lltrace && prtrace(TOP(), "stackadj")); \
                                assert(STACK_LEVEL() <= co->co_stacksize); }
-#define EXT_POP(STACK_POINTER) (lltrace && prtrace((STACK_POINTER)[-1], \
-				"ext_pop"), *--(STACK_POINTER))
+#define EXT_POP(STACK_POINTER) ((void)(lltrace && \
+				prtrace((STACK_POINTER)[-1], "ext_pop")), \
+				*--(STACK_POINTER))
 #else
 #define PUSH(v)		BASIC_PUSH(v)
 #define POP()		BASIC_POP()
@@ -717,8 +718,9 @@
 			   an argument which depends on the situation.
 			   The global trace function is also called
 			   whenever an exception is detected. */
-			if (call_trace(tstate->c_tracefunc, tstate->c_traceobj,
-				       f, PyTrace_CALL, Py_None)) {
+			if (call_trace_protected(tstate->c_tracefunc, 
+						 tstate->c_traceobj,
+						 f, PyTrace_CALL, Py_None)) {
 				/* Trace function raised an error */
 				goto exit_eval_frame;
 			}
@@ -726,9 +728,9 @@
 		if (tstate->c_profilefunc != NULL) {
 			/* Similar for c_profilefunc, except it needn't
 			   return itself and isn't called for "line" events */
-			if (call_trace(tstate->c_profilefunc,
-				       tstate->c_profileobj,
-				       f, PyTrace_CALL, Py_None)) {
+			if (call_trace_protected(tstate->c_profilefunc,
+						 tstate->c_profileobj,
+						 f, PyTrace_CALL, Py_None)) {
 				/* Profile function raised an error */
 				goto exit_eval_frame;
 			}
@@ -1117,24 +1119,13 @@
 		case BINARY_ADD:
 			w = POP();
 			v = TOP();
-			if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
-				/* INLINE: int + int */
-				register long a, b, i;
-				a = PyInt_AS_LONG(v);
-				b = PyInt_AS_LONG(w);
-				i = a + b;
-				if ((i^a) < 0 && (i^b) < 0)
-					goto slow_add;
-				x = PyInt_FromLong(i);
-			}
-			else if (PyString_CheckExact(v) &&
-				 PyString_CheckExact(w)) {
-				x = string_concatenate(v, w, f, next_instr);
-				/* string_concatenate consumed the ref to v */
+			if (PyUnicode_CheckExact(v) &&
+				 PyUnicode_CheckExact(w)) {
+				x = unicode_concatenate(v, w, f, next_instr);
+				/* unicode_concatenate consumed the ref to v */
 				goto skip_decref_vx;
 			}
 			else {
-			  slow_add:
 				x = PyNumber_Add(v, w);
 			}
 			Py_DECREF(v);
@@ -1147,20 +1138,7 @@
 		case BINARY_SUBTRACT:
 			w = POP();
 			v = TOP();
-			if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
-				/* INLINE: int - int */
-				register long a, b, i;
-				a = PyInt_AS_LONG(v);
-				b = PyInt_AS_LONG(w);
-				i = a - b;
-				if ((i^a) < 0 && (i^~b) < 0)
-					goto slow_sub;
-				x = PyInt_FromLong(i);
-			}
-			else {
-			  slow_sub:
-				x = PyNumber_Subtract(v, w);
-			}
+			x = PyNumber_Subtract(v, w);
 			Py_DECREF(v);
 			Py_DECREF(w);
 			SET_TOP(x);
@@ -1170,21 +1148,7 @@
 		case BINARY_SUBSCR:
 			w = POP();
 			v = TOP();
-			if (PyList_CheckExact(v) && PyInt_CheckExact(w)) {
-				/* INLINE: list[int] */
-				Py_ssize_t i = PyInt_AsSsize_t(w);
-				if (i < 0)
-					i += PyList_GET_SIZE(v);
-				if (i >= 0 && i < PyList_GET_SIZE(v)) {
-					x = PyList_GET_ITEM(v, i);
-					Py_INCREF(x);
-				}
-				else
-					goto slow_get;
-			}
-			else
-			  slow_get:
-				x = PyObject_GetItem(v, w);
+			x = PyObject_GetItem(v, w);
 			Py_DECREF(v);
 			Py_DECREF(w);
 			SET_TOP(x);
@@ -1318,24 +1282,13 @@
 		case INPLACE_ADD:
 			w = POP();
 			v = TOP();
-			if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
-				/* INLINE: int + int */
-				register long a, b, i;
-				a = PyInt_AS_LONG(v);
-				b = PyInt_AS_LONG(w);
-				i = a + b;
-				if ((i^a) < 0 && (i^b) < 0)
-					goto slow_iadd;
-				x = PyInt_FromLong(i);
-			}
-			else if (PyString_CheckExact(v) &&
-				 PyString_CheckExact(w)) {
-				x = string_concatenate(v, w, f, next_instr);
-				/* string_concatenate consumed the ref to v */
+			if (PyUnicode_CheckExact(v) &&
+				 PyUnicode_CheckExact(w)) {
+				x = unicode_concatenate(v, w, f, next_instr);
+				/* unicode_concatenate consumed the ref to v */
 				goto skip_decref_v;
 			}
 			else {
-			  slow_iadd:
 				x = PyNumber_InPlaceAdd(v, w);
 			}
 			Py_DECREF(v);
@@ -1348,20 +1301,7 @@
 		case INPLACE_SUBTRACT:
 			w = POP();
 			v = TOP();
-			if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
-				/* INLINE: int - int */
-				register long a, b, i;
-				a = PyInt_AS_LONG(v);
-				b = PyInt_AS_LONG(w);
-				i = a - b;
-				if ((i^a) < 0 && (i^~b) < 0)
-					goto slow_isub;
-				x = PyInt_FromLong(i);
-			}
-			else {
-			  slow_isub:
-				x = PyNumber_InPlaceSubtract(v, w);
-			}
+			x = PyNumber_InPlaceSubtract(v, w);
 			Py_DECREF(v);
 			Py_DECREF(w);
 			SET_TOP(x);
@@ -1515,10 +1455,11 @@
 			}
 			continue;
 
+		PREDICTED(END_FINALLY);
 		case END_FINALLY:
 			v = POP();
-			if (PyInt_Check(v)) {
-				why = (enum why_code) PyInt_AS_LONG(v);
+			if (PyLong_Check(v)) {
+				why = (enum why_code) PyLong_AS_LONG(v);
 				assert(why != WHY_YIELD);
 				if (why == WHY_RETURN ||
 				    why == WHY_CONTINUE)
@@ -1564,8 +1505,7 @@
 				break;
 			}
 			PyErr_Format(PyExc_SystemError,
-				     "no locals found when storing %s",
-				     PyObject_REPR(w));
+				     "no locals found when storing %R", w);
 			break;
 
 		case DELETE_NAME:
@@ -1578,8 +1518,7 @@
 				break;
 			}
 			PyErr_Format(PyExc_SystemError,
-				     "no locals when deleting %s",
-				     PyObject_REPR(w));
+				     "no locals when deleting %R", w);
 			break;
 
 		PREDICTED_WITH_ARG(UNPACK_SEQUENCE);
@@ -1668,8 +1607,7 @@
 			w = GETITEM(names, oparg);
 			if ((v = f->f_locals) == NULL) {
 				PyErr_Format(PyExc_SystemError,
-					     "no locals when loading %s",
-					     PyObject_REPR(w));
+					     "no locals when loading %R", w);
 				break;
 			}
 			if (PyDict_CheckExact(v)) {
@@ -1850,22 +1788,21 @@
 			break;
 
 		case BUILD_MAP:
-			x = PyDict_New();
+			x = _PyDict_NewPresized((Py_ssize_t)oparg);
 			PUSH(x);
 			if (x != NULL) continue;
 			break;
-		
-		case MAKE_BYTES:
-			w = POP();
-			if (PyString_Check(w))
-				x = PyBytes_FromStringAndSize(
-					PyString_AS_STRING(w),
-					PyString_GET_SIZE(w));
-			else
-				x = NULL;
+
+		case STORE_MAP:
+			w = TOP();     /* key */
+			u = SECOND();  /* value */
+			v = THIRD();   /* dict */
+			STACKADJ(-2);
+			assert (PyDict_CheckExact(v));
+			err = PyDict_SetItem(v, w, u);  /* v[w] = u */
+			Py_DECREF(u);
 			Py_DECREF(w);
-			PUSH(x);
-			if (x != NULL) continue;
+			if (err == 0) continue;
 			break;
 
 		case LOAD_ATTR:
@@ -1880,30 +1817,7 @@
 		case COMPARE_OP:
 			w = POP();
 			v = TOP();
-			if (PyInt_CheckExact(w) && PyInt_CheckExact(v)) {
-				/* INLINE: cmp(int, int) */
-				register long a, b;
-				register int res;
-				a = PyInt_AS_LONG(v);
-				b = PyInt_AS_LONG(w);
-				switch (oparg) {
-				case PyCmp_LT: res = a <  b; break;
-				case PyCmp_LE: res = a <= b; break;
-				case PyCmp_EQ: res = a == b; break;
-				case PyCmp_NE: res = a != b; break;
-				case PyCmp_GT: res = a >  b; break;
-				case PyCmp_GE: res = a >= b; break;
-				case PyCmp_IS: res = v == w; break;
-				case PyCmp_IS_NOT: res = v != w; break;
-				default: goto slow_compare;
-				}
-				x = res ? Py_True : Py_False;
-				Py_INCREF(x);
-			}
-			else {
-			  slow_compare:
-				x = cmp_outcome(oparg, v, w);
-			}
+			x = cmp_outcome(oparg, v, w);
 			Py_DECREF(v);
 			Py_DECREF(w);
 			SET_TOP(x);
@@ -1920,9 +1834,10 @@
 						"__import__ not found");
 				break;
 			}
+			Py_INCREF(x);
 			v = POP();
 			u = TOP();
-			if (PyInt_AsLong(u) != -1 || PyErr_Occurred())
+			if (PyLong_AsLong(u) != -1 || PyErr_Occurred())
 				w = PyTuple_Pack(5,
 					    w,
 					    f->f_globals,
@@ -1941,11 +1856,14 @@
 			Py_DECREF(u);
 			if (w == NULL) {
 				u = POP();
+				Py_DECREF(x);
 				x = NULL;
 				break;
 			}
 			READ_TIMESTAMP(intr0);
-			x = PyEval_CallObject(x, w);
+			v = x;
+			x = PyEval_CallObject(v, w);
+			Py_DECREF(v);
 			READ_TIMESTAMP(intr1);
 			Py_DECREF(w);
 			SET_TOP(x);
@@ -2027,7 +1945,18 @@
 		PREDICTED_WITH_ARG(JUMP_ABSOLUTE);
 		case JUMP_ABSOLUTE:
 			JUMPTO(oparg);
+#if FAST_LOOPS
+			/* Enabling this path speeds-up all while and for-loops by bypassing
+                           the per-loop checks for signals.  By default, this should be turned-off
+                           because it prevents detection of a control-break in tight loops like
+                           "while 1: pass".  Compile with this option turned-on when you need
+                           the speed-up and do not need break checking inside tight loops (ones
+                           that contain only instructions ending with goto fast_next_opcode). 
+                        */
+			goto fast_next_opcode;
+#else
 			continue;
+#endif
 
 		case GET_ITER:
 			/* before: [obj]; after [getiter(obj)] */
@@ -2070,7 +1999,7 @@
 			goto fast_block_end;
 
 		case CONTINUE_LOOP:
-			retval = PyInt_FromLong(oparg);
+			retval = PyLong_FromLong(oparg);
 			if (!retval) {
 				x = NULL;
 				break;
@@ -2092,17 +2021,20 @@
 
 		case WITH_CLEANUP:
 		{
-			/* TOP is the context.__exit__ bound method.
-			   Below that are 1-3 values indicating how/why
-			   we entered the finally clause:
-			   - SECOND = None
-			   - (SECOND, THIRD) = (WHY_{RETURN,CONTINUE}), retval
-			   - SECOND = WHY_*; no retval below it
-			   - (SECOND, THIRD, FOURTH) = exc_info()
+			/* At the top of the stack are 1-3 values indicating
+			   how/why we entered the finally clause:
+			   - TOP = None
+			   - (TOP, SECOND) = (WHY_{RETURN,CONTINUE}), retval
+			   - TOP = WHY_*; no retval below it
+			   - (TOP, SECOND, THIRD) = exc_info()
+			   Below them is EXIT, the context.__exit__ bound method.
 			   In the last case, we must call
-			     TOP(SECOND, THIRD, FOURTH)
+			     EXIT(TOP, SECOND, THIRD)
 			   otherwise we must call
-			     TOP(None, None, None)
+			     EXIT(None, None, None)
+
+			   In all cases, we remove EXIT from the stack, leaving
+			   the rest in the same order.
 
 			   In addition, if the stack represents an exception,
 			   *and* the function call returns a 'true' value, we
@@ -2111,36 +2043,60 @@
 			   should still be resumed.)
 			*/
 
-			x = TOP();
-			u = SECOND();
-			if (PyInt_Check(u) || u == Py_None) {
+			PyObject *exit_func;
+
+			u = POP();
+			if (u == Py_None) {
+			       	exit_func = TOP();
+				SET_TOP(u);
+				v = w = Py_None;
+			}
+			else if (PyLong_Check(u)) {
+				switch(PyLong_AS_LONG(u)) {
+				case WHY_RETURN:
+				case WHY_CONTINUE:
+					/* Retval in TOP. */
+					exit_func = SECOND();
+					SET_SECOND(TOP());
+					SET_TOP(u);
+					break;
+				default:
+					exit_func = TOP();
+					SET_TOP(u);
+					break;
+				}
 				u = v = w = Py_None;
 			}
 			else {
-				v = THIRD();
-				w = FOURTH();
+				v = TOP();
+				w = SECOND();
+				exit_func = THIRD();
+				SET_TOP(u);
+				SET_SECOND(v);
+				SET_THIRD(w);
 			}
 			/* XXX Not the fastest way to call it... */
-			x = PyObject_CallFunctionObjArgs(x, u, v, w, NULL);
-			if (x == NULL)
+			x = PyObject_CallFunctionObjArgs(exit_func, u, v, w,
+							 NULL);
+			if (x == NULL) {
+				Py_DECREF(exit_func);
 				break; /* Go to error exit */
+			}
 			if (u != Py_None && PyObject_IsTrue(x)) {
 				/* There was an exception and a true return */
-				Py_DECREF(x);
-				x = TOP(); /* Again */
-				STACKADJ(-3);
+				STACKADJ(-2);
 				Py_INCREF(Py_None);
 				SET_TOP(Py_None);
-				Py_DECREF(x);
 				Py_DECREF(u);
 				Py_DECREF(v);
 				Py_DECREF(w);
 			} else {
-				/* Let END_FINALLY do its thing */
-				Py_DECREF(x);
-				x = POP();
-				Py_DECREF(x);
+				/* The stack was rearranged to remove EXIT
+				   above. Let END_FINALLY do its thing */
 			}
+			Py_DECREF(x);
+			Py_DECREF(exit_func);
+			PREDICT(END_FINALLY);
 			break;
 		}
 
@@ -2360,7 +2316,7 @@
 		else {
 			/* This check is expensive! */
 			if (PyErr_Occurred()) {
-				char buf[1024];
+				char buf[128];
 				sprintf(buf, "Stack unwind with exception "
 					"set and why=%d", why);
 				Py_FatalError(buf);
@@ -2396,7 +2352,7 @@
 				PyFrame_BlockSetup(f, b->b_type, b->b_handler,
 						   b->b_level);
 				why = WHY_NOT;
-				JUMPTO(PyInt_AS_LONG(retval));
+				JUMPTO(PyLong_AS_LONG(retval));
 				Py_DECREF(retval);
 				break;
 			}
@@ -2442,7 +2398,7 @@
 				else {
 					if (why & (WHY_RETURN | WHY_CONTINUE))
 						PUSH(retval);
-					v = PyInt_FromLong((long)why);
+					v = PyLong_FromLong((long)why);
 					PUSH(v);
 				}
 				why = WHY_NOT;
@@ -2712,7 +2668,7 @@
 		Py_UNICODE *cellname, *argname;
 		PyObject *c;
 
-		nargs = co->co_argcount;
+		nargs = co->co_argcount + co->co_kwonlyargcount;
 		if (co->co_flags & CO_VARARGS)
 			nargs++;
 		if (co->co_flags & CO_VARKEYWORDS)
@@ -3082,7 +3038,7 @@
 		*--sp = PyList_GET_ITEM(l, ll - j);
 	}
 	/* Resize the list. */
-	Py_Size(l) = ll - argcntafter;
+	Py_SIZE(l) = ll - argcntafter;
 	Py_DECREF(it);
 	return 1;
 
@@ -3132,7 +3088,7 @@
 	}
 }
 
-static void
+static int
 call_trace_protected(Py_tracefunc func, PyObject *obj, PyFrameObject *frame,
 		     int what, PyObject *arg)
 {
@@ -3141,11 +3097,15 @@
 	PyErr_Fetch(&type, &value, &traceback);
 	err = call_trace(func, obj, frame, what, arg);
 	if (err == 0)
+	{
 		PyErr_Restore(type, value, traceback);
+		return 0;
+	}
 	else {
 		Py_XDECREF(type);
 		Py_XDECREF(value);
 		Py_XDECREF(traceback);
+		return -1;
 	}
 }
 
@@ -3568,7 +3528,7 @@
 	}
 	if (argdefs != NULL) {
 		d = &PyTuple_GET_ITEM(argdefs, 0);
-		nd = Py_Size(argdefs);
+		nd = Py_SIZE(argdefs);
 	}
 	return PyEval_EvalCodeEx(co, globals,
 				 (PyObject *)NULL, (*pp_stack)-n, na,
@@ -3796,14 +3756,7 @@
 {
 	if (v != NULL) {
 		Py_ssize_t x;
-		if (PyInt_CheckExact(v)) {
-			/* XXX(nnorwitz): I think PyInt_AS_LONG is correct,
-			   however, it looks like it should be AsSsize_t.
-			   There should be a comment here explaining why.
-			*/
-			x = PyInt_AS_LONG(v);
-		}
-		else if (PyIndex_Check(v)) {
+		if (PyIndex_Check(v)) {
 			x = PyNumber_AsSsize_t(v, NULL);
 			if (x == -1 && PyErr_Occurred())
 				return 0;
@@ -3961,13 +3914,13 @@
 }
 
 static PyObject *
-string_concatenate(PyObject *v, PyObject *w,
+unicode_concatenate(PyObject *v, PyObject *w,
 		   PyFrameObject *f, unsigned char *next_instr)
 {
 	/* This function implements 'variable += expr' when both arguments
-	   are strings. */
-	Py_ssize_t v_len = PyString_GET_SIZE(v);
-	Py_ssize_t w_len = PyString_GET_SIZE(w);
+	   are (Unicode) strings. */
+	Py_ssize_t v_len = PyUnicode_GET_SIZE(v);
+	Py_ssize_t w_len = PyUnicode_GET_SIZE(w);
 	Py_ssize_t new_len = v_len + w_len;
 	if (new_len < 0) {
 		PyErr_SetString(PyExc_OverflowError,
@@ -4016,12 +3969,12 @@
 		}
 	}
 
-	if (v->ob_refcnt == 1 && !PyString_CHECK_INTERNED(v)) {
+	if (v->ob_refcnt == 1 && !PyUnicode_CHECK_INTERNED(v)) {
 		/* Now we own the last reference to 'v', so we can resize it
 		 * in-place.
 		 */
-		if (_PyString_Resize(&v, new_len) != 0) {
-			/* XXX if _PyString_Resize() fails, 'v' has been
+		if (PyUnicode_Resize(&v, new_len) != 0) {
+			/* XXX if PyUnicode_Resize() fails, 'v' has been
 			 * deallocated so it cannot be put back into
 			 * 'variable'.  The MemoryError is raised when there
 			 * is no value in 'variable', which might (very
@@ -4030,14 +3983,15 @@
 			return NULL;
 		}
 		/* copy 'w' into the newly allocated area of 'v' */
-		memcpy(PyString_AS_STRING(v) + v_len,
-		       PyString_AS_STRING(w), w_len);
+		memcpy(PyUnicode_AS_UNICODE(v) + v_len,
+		       PyUnicode_AS_UNICODE(w), w_len*sizeof(Py_UNICODE));
 		return v;
 	}
 	else {
 		/* When in-place resizing is not an option. */
-		PyString_Concat(&v, w);
-		return v;
+		w = PyUnicode_Concat(v, w);
+                Py_DECREF(v);
+		return w;
 	}
 }
 
@@ -4050,7 +4004,7 @@
 	PyObject *l = PyList_New(256);
 	if (l == NULL) return NULL;
 	for (i = 0; i < 256; i++) {
-		PyObject *x = PyInt_FromLong(a[i]);
+		PyObject *x = PyLong_FromLong(a[i]);
 		if (x == NULL) {
 			Py_DECREF(l);
 			return NULL;

Modified: python/branches/py3k-importlib/Python/codecs.c
==============================================================================
--- python/branches/py3k-importlib/Python/codecs.c	(original)
+++ python/branches/py3k-importlib/Python/codecs.c	Thu Mar 27 00:48:05 2008
@@ -14,7 +14,7 @@
 /* --- Codec Registry ----------------------------------------------------- */
 
 /* Import the standard encodings package which will register the first
-   codec search function. 
+   codec search function.
 
    This is done in a lazy way so that the Unicode implementation does
    not downgrade startup time of scripts not needing it.
@@ -55,16 +55,15 @@
     size_t len = strlen(string);
     char *p;
     PyObject *v;
-    
+
     if (len > PY_SSIZE_T_MAX) {
 	PyErr_SetString(PyExc_OverflowError, "string is too large");
 	return NULL;
     }
-	
-    v = PyString_FromStringAndSize(NULL, len);
-    if (v == NULL)
-	return NULL;
-    p = PyString_AS_STRING(v);
+
+    p = PyMem_Malloc(len + 1);
+    if (p == NULL)
+        return NULL;
     for (i = 0; i < len; i++) {
         register char ch = string[i];
         if (ch == ' ')
@@ -73,6 +72,11 @@
             ch = tolower(Py_CHARMASK(ch));
 	p[i] = ch;
     }
+    p[i] = '\0';
+    v = PyUnicode_FromString(p);
+    if (v == NULL)
+        return NULL;
+    PyMem_Free(p);
     return v;
 }
 
@@ -83,7 +87,7 @@
    characters. This makes encodings looked up through this mechanism
    effectively case-insensitive.
 
-   If no codec is found, a LookupError is set and NULL returned. 
+   If no codec is found, a LookupError is set and NULL returned.
 
    As side effect, this tries to load the encodings package, if not
    yet done. This is part of the lazy load strategy for the encodings
@@ -112,7 +116,7 @@
     v = normalizestring(encoding);
     if (v == NULL)
 	goto onError;
-    PyString_InternInPlace(&v);
+    PyUnicode_InternInPlace(&v);
 
     /* First, try to lookup the name in the registry dictionary */
     result = PyDict_GetItem(interp->codec_search_cache, v);
@@ -121,7 +125,7 @@
 	Py_DECREF(v);
 	return result;
     }
-    
+
     /* Next, scan the search functions in order of registration */
     args = PyTuple_New(1);
     if (args == NULL)
@@ -140,7 +144,7 @@
 
     for (i = 0; i < len; i++) {
 	PyObject *func;
-	
+
 	func = PyList_GetItem(interp->codec_search_path, i);
 	if (func == NULL)
 	    goto onError;
@@ -184,7 +188,7 @@
 		     const char *errors)
 {
     PyObject *args;
-    
+
     args = PyTuple_New(1 + (errors != NULL));
     if (args == NULL)
 	return NULL;
@@ -192,8 +196,8 @@
     PyTuple_SET_ITEM(args,0,object);
     if (errors) {
 	PyObject *v;
-	
-	v = PyString_FromString(errors);
+
+	v = PyUnicode_FromString(errors);
 	if (v == NULL) {
 	    Py_DECREF(args);
 	    return NULL;
@@ -267,10 +271,10 @@
     return streamcodec;
 }
 
-/* Convenience APIs to query the Codec registry. 
-   
+/* Convenience APIs to query the Codec registry.
+
    All APIs return a codec object with incremented refcount.
-   
+
  */
 
 PyObject *PyCodec_Encoder(const char *encoding)
@@ -320,7 +324,7 @@
 {
     PyObject *encoder = NULL;
     PyObject *args = NULL, *result = NULL;
-    PyObject *v;
+    PyObject *v = NULL;
 
     encoder = PyCodec_Encoder(encoding);
     if (encoder == NULL)
@@ -329,31 +333,43 @@
     args = args_tuple(object, errors);
     if (args == NULL)
 	goto onError;
-    
-    result = PyEval_CallObject(encoder,args);
+
+    result = PyEval_CallObject(encoder, args);
     if (result == NULL)
 	goto onError;
 
-    if (!PyTuple_Check(result) || 
+    if (!PyTuple_Check(result) ||
 	PyTuple_GET_SIZE(result) != 2) {
 	PyErr_SetString(PyExc_TypeError,
-			"encoder must return a tuple (object,integer)");
+			"encoder must return a tuple (object, integer)");
 	goto onError;
     }
-    v = PyTuple_GET_ITEM(result,0);
-    Py_INCREF(v);
+    v = PyTuple_GET_ITEM(result, 0);
+    if (PyBytes_Check(v)) {
+        char msg[100];
+        PyOS_snprintf(msg, sizeof(msg),
+                      "encoder %s returned buffer instead of bytes",
+                      encoding);
+        if (PyErr_WarnEx(PyExc_RuntimeWarning, msg, 1) < 0) {
+            v = NULL;
+            goto onError;
+        }
+        v = PyString_FromStringAndSize(PyBytes_AS_STRING(v), Py_SIZE(v));
+    }
+    else if (PyString_Check(v))
+        Py_INCREF(v);
+    else {
+        PyErr_SetString(PyExc_TypeError,
+                        "encoding must return a tuple(bytes, integer)");
+        v = NULL;
+    }
     /* We don't check or use the second (integer) entry. */
 
-    Py_DECREF(args);
-    Py_DECREF(encoder);
-    Py_DECREF(result);
-    return v;
-	
  onError:
     Py_XDECREF(result);
     Py_XDECREF(args);
     Py_XDECREF(encoder);
-    return NULL;
+    return v;
 }
 
 /* Decode an object (usually a Python string) using the given encoding
@@ -376,11 +392,11 @@
     args = args_tuple(object, errors);
     if (args == NULL)
 	goto onError;
-    
+
     result = PyEval_CallObject(decoder,args);
     if (result == NULL)
 	goto onError;
-    if (!PyTuple_Check(result) || 
+    if (!PyTuple_Check(result) ||
 	PyTuple_GET_SIZE(result) != 2) {
 	PyErr_SetString(PyExc_TypeError,
 			"decoder must return a tuple (object,integer)");
@@ -394,7 +410,7 @@
     Py_DECREF(decoder);
     Py_DECREF(result);
     return v;
-	
+
  onError:
     Py_XDECREF(args);
     Py_XDECREF(decoder);
@@ -834,7 +850,7 @@
 	interp->codec_error_registry == NULL)
 	Py_FatalError("can't initialize codec registry");
 
-    mod = PyImport_ImportModuleLevel("encodings", NULL, NULL, NULL, 0);
+    mod = PyImport_ImportModuleNoBlock("encodings");
     if (mod == NULL) {
 	if (PyErr_ExceptionMatches(PyExc_ImportError)) {
 	    /* Ignore ImportErrors... this is done so that

Modified: python/branches/py3k-importlib/Python/compile.c
==============================================================================
--- python/branches/py3k-importlib/Python/compile.c	(original)
+++ python/branches/py3k-importlib/Python/compile.c	Thu Mar 27 00:48:05 2008
@@ -335,7 +335,7 @@
 
 	n = PyList_Size(list);
 	for (i = 0; i < n; i++) {
-		v = PyInt_FromLong(i);
+		v = PyLong_FromLong(i);
 		if (!v) {
 			Py_DECREF(dict);
 			return NULL;
@@ -375,12 +375,12 @@
 	while (PyDict_Next(src, &pos, &k, &v)) {
 		/* XXX this should probably be a macro in symtable.h */
 		long vi;
-		assert(PyInt_Check(v));
-		vi = PyInt_AS_LONG(v);
+		assert(PyLong_Check(v));
+		vi = PyLong_AS_LONG(v);
 		scope = (vi >> SCOPE_OFFSET) & SCOPE_MASK;
 
 		if (scope == scope_type || vi & flag) {
-			PyObject *tuple, *item = PyInt_FromLong(i);
+			PyObject *tuple, *item = PyLong_FromLong(i);
 			if (item == NULL) {
 				Py_DECREF(dest);
 				return NULL;
@@ -405,9 +405,9 @@
 {
 	basicblock *block;
 	for (block = u->u_blocks; block != NULL; block = block->b_list) {
-		assert(block != (void *)0xcbcbcbcb);
-		assert(block != (void *)0xfbfbfbfb);
-		assert(block != (void *)0xdbdbdbdb);
+		assert((void *)block != (void *)0xcbcbcbcb);
+		assert((void *)block != (void *)0xfbfbfbfb);
+		assert((void *)block != (void *)0xdbdbdbdb);
 		if (block->b_instr != NULL) {
 			assert(block->b_ialloc > 0);
 			assert(block->b_iused > 0);
@@ -652,11 +652,16 @@
 	return b->b_iused++;
 }
 
-/* Set the i_lineno member of the instruction at offse off if the
-   line number for the current expression/statement (?) has not
+/* Set the i_lineno member of the instruction at offset off if the
+   line number for the current expression/statement has not
    already been set.  If it has been set, the call has no effect.
 
-   Every time a new node is b
+   The line number is reset in the following cases:
+   - when entering a new scope
+   - on each statement
+   - on each expression that start a new line
+   - before the "except" clause
+   - before the "for" and "while" expressions
 */
 
 static void
@@ -714,6 +719,8 @@
 			return -1;
 		case STORE_SUBSCR:
 			return -3;
+		case STORE_MAP:
+			return -2;
 		case DELETE_SUBSCR:
 			return -2;
 
@@ -787,8 +794,6 @@
 			return 1-oparg;
 		case BUILD_MAP:
 			return 1;
-		case MAKE_BYTES:
-			return 0;
 		case LOAD_ATTR:
 			return 0;
 		case COMPARE_OP:
@@ -885,31 +890,66 @@
 {
 	PyObject *t, *v;
 	Py_ssize_t arg;
+	unsigned char *p, *q;
+	Py_complex z;
+	double d;
+	int real_part_zero, imag_part_zero;
 
 	/* necessary to make sure types aren't coerced (e.g., int and long) */
         /* _and_ to distinguish 0.0 from -0.0 e.g. on IEEE platforms */
         if (PyFloat_Check(o)) {
-            double d = PyFloat_AS_DOUBLE(o);
-            unsigned char* p = (unsigned char*) &d;
-            /* all we need is to make the tuple different in either the 0.0
-             * or -0.0 case from all others, just to avoid the "coercion".
-             */
-            if (*p==0 && p[sizeof(double)-1]==0)
-                t = PyTuple_Pack(3, o, o->ob_type, Py_None);
-            else
-	        t = PyTuple_Pack(2, o, o->ob_type);
-        } else {
-	    t = PyTuple_Pack(2, o, o->ob_type);
+		d = PyFloat_AS_DOUBLE(o);
+		p = (unsigned char*) &d;
+		/* all we need is to make the tuple different in either the 0.0
+		 * or -0.0 case from all others, just to avoid the "coercion".
+		 */
+		if (*p==0 && p[sizeof(double)-1]==0)
+			t = PyTuple_Pack(3, o, o->ob_type, Py_None);
+		else
+			t = PyTuple_Pack(2, o, o->ob_type);
+	}
+	else if (PyComplex_Check(o)) {
+		/* complex case is even messier: we need to make complex(x,
+		   0.) different from complex(x, -0.) and complex(0., y)
+		   different from complex(-0., y), for any x and y.  In
+		   particular, all four complex zeros should be
+		   distinguished.*/
+		z = PyComplex_AsCComplex(o);
+		p = (unsigned char*) &(z.real);
+		q = (unsigned char*) &(z.imag);
+		/* all that matters here is that on IEEE platforms
+		   real_part_zero will be true if z.real == 0., and false if
+		   z.real == -0.  In fact, real_part_zero will also be true
+		   for some other rarely occurring nonzero floats, but this
+		   doesn't matter. Similar comments apply to
+		   imag_part_zero. */
+		real_part_zero = *p==0 && p[sizeof(double)-1]==0;
+		imag_part_zero = *q==0 && q[sizeof(double)-1]==0;
+		if (real_part_zero && imag_part_zero) {
+			t = PyTuple_Pack(4, o, o->ob_type, Py_True, Py_True);
+		}
+		else if (real_part_zero && !imag_part_zero) {
+			t = PyTuple_Pack(4, o, o->ob_type, Py_True, Py_False);
+		}
+		else if (!real_part_zero && imag_part_zero) {
+			t = PyTuple_Pack(4, o, o->ob_type, Py_False, Py_True);
+		}
+		else {
+			t = PyTuple_Pack(2, o, o->ob_type);
+		}
+        }
+	else {
+		t = PyTuple_Pack(2, o, o->ob_type);
         }
 	if (t == NULL)
-	    return -1;
+		return -1;
 
 	v = PyDict_GetItem(dict, t);
 	if (!v) {
                 if (PyErr_Occurred())
                         return -1;
 		arg = PyDict_Size(dict);
-		v = PyInt_FromLong(arg);
+		v = PyLong_FromLong(arg);
 		if (!v) {
 			Py_DECREF(t);
 			return -1;
@@ -922,7 +962,7 @@
 		Py_DECREF(v);
 	}
 	else
-		arg = PyInt_AsLong(v);
+		arg = PyLong_AsLong(v);
 	Py_DECREF(t);
 	return arg;
 }
@@ -1133,7 +1173,7 @@
 	int addNone = 1;
 	static PyObject *module;
 	if (!module) {
-		module = PyUnicode_FromString("<module>");
+		module = PyUnicode_InternFromString("<module>");
 		if (!module)
 			return NULL;
 	}
@@ -1210,7 +1250,7 @@
     Py_DECREF(k);
     if (v == NULL)
 	return -1;
-    return PyInt_AS_LONG(v);
+    return PyLong_AS_LONG(v);
 }
 
 static int
@@ -1477,7 +1517,7 @@
 
 	/* initialize statics */
 	if (locals == NULL) {
-		locals = PyUnicode_FromString("__locals__");
+		locals = PyUnicode_InternFromString("__locals__");
 		if (locals == NULL)
 			return 0;
 	}
@@ -1715,9 +1755,8 @@
 	VISIT(c, expr, s->v.For.iter);
 	ADDOP(c, GET_ITER);
 	compiler_use_next_block(c, start);
-	/* XXX(nnorwitz): is there a better way to handle this?
-	   for loops are special, we want to be able to trace them
-	   each time around, so we need to set an extra line number. */
+	/* for expressions must be traced on each iteration,
+	   so we need to set an extra line number. */
 	c->u->u_lineno_set = 0;
 	ADDOP_JREL(c, FOR_ITER, cleanup);
 	VISIT(c, expr, s->v.For.target);
@@ -1737,8 +1776,11 @@
 	basicblock *loop, *orelse, *end, *anchor = NULL;
 	int constant = expr_constant(s->v.While.test);
 
-	if (constant == 0)
+	if (constant == 0) {
+		if (s->v.While.orelse)
+			VISIT_SEQ(c, stmt, s->v.While.orelse);
 		return 1;
+	}
 	loop = compiler_new_block(c);
 	end = compiler_new_block(c);
 	if (constant == -1) {
@@ -1761,6 +1803,9 @@
 	if (!compiler_push_fblock(c, LOOP, loop))
 		return 0;
 	if (constant == -1) {
+		/* while expressions must be traced on each iteration,
+		   so we need to set an extra line number. */
+		c->u->u_lineno_set = 0;
 		VISIT(c, expr, s->v.While.test);
 		ADDOP_JREL(c, JUMP_IF_FALSE, anchor);
 		ADDOP(c, POP_TOP);
@@ -1941,8 +1986,8 @@
 						s->v.TryExcept.handlers, i);
 		if (!handler->type && i < n-1)
 		    return compiler_error(c, "default 'except:' must be last");
-	c->u->u_lineno_set = 0;
-	c->u->u_lineno = handler->lineno;
+		c->u->u_lineno_set = 0;
+		c->u->u_lineno = handler->lineno;
 		except = compiler_new_block(c);
 		if (except == NULL)
 			return 0;
@@ -2067,7 +2112,7 @@
 		int r;
 		PyObject *level;
 
-                level = PyInt_FromLong(0);
+                level = PyLong_FromLong(0);
 		if (level == NULL)
 			return 0;
 
@@ -2110,7 +2155,7 @@
 	if (!names)
 		return 0;
 
-        level = PyInt_FromLong(s->v.ImportFrom.level);
+        level = PyLong_FromLong(s->v.ImportFrom.level);
 	if (!level) {
 		Py_DECREF(names);
 		return 0;
@@ -2174,10 +2219,18 @@
 	if (Py_OptimizeFlag)
 		return 1;
 	if (assertion_error == NULL) {
-		assertion_error = PyUnicode_FromString("AssertionError");
+		assertion_error = PyUnicode_InternFromString("AssertionError");
 		if (assertion_error == NULL)
 			return 0;
 	}
+	if (s->v.Assert.test->kind == Tuple_kind &&
+	    asdl_seq_LEN(s->v.Assert.test->v.Tuple.elts) > 0) {
+		const char* msg =
+			"assertion is always true, perhaps remove parentheses?";
+		if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, c->c_filename,
+				       c->u->u_lineno, NULL, NULL) == -1)
+			return 0;
+	}
 	VISIT(c, expr, s->v.Assert.test);
 	end = compiler_new_block(c);
 	if (end == NULL)
@@ -2569,6 +2622,11 @@
 		for (i = 0; i < n; i++) {
 			expr_ty elt = asdl_seq_GET(e->v.List.elts, i);
 			if (elt->kind == Starred_kind && !seen_star) {
+				if ((i >= (1 << 8)) ||
+				    (n-i-1 >= (INT_MAX >> 8)))
+					return compiler_error(c,
+						"too many expressions in "
+						"star-unpacking assignment");
 				ADDOP_I(c, UNPACK_EX, (i + ((n-i-1) << 8)));
 				seen_star = 1;
 				asdl_seq_SET(e->v.List.elts, i, elt->v.Starred.value);
@@ -2597,6 +2655,11 @@
 		for (i = 0; i < n; i++) {
 			expr_ty elt = asdl_seq_GET(e->v.Tuple.elts, i);
 			if (elt->kind == Starred_kind && !seen_star) {
+				if ((i >= (1 << 8)) ||
+				    (n-i-1 >= (INT_MAX >> 8)))
+					return compiler_error(c,
+						"too many expressions in "
+						"star-unpacking assignment");
 				ADDOP_I(c, UNPACK_EX, (i + ((n-i-1) << 8)));
 				seen_star = 1;
 				asdl_seq_SET(e->v.Tuple.elts, i, elt->v.Starred.value);
@@ -3037,7 +3100,7 @@
 {
     static identifier enter_attr, exit_attr;
     basicblock *block, *finally;
-    identifier tmpexit, tmpvalue = NULL;
+    identifier tmpvalue = NULL;
 
     assert(s->kind == With_kind);
 
@@ -3057,12 +3120,6 @@
     if (!block || !finally)
 	return 0;
 
-    /* Create a temporary variable to hold context.__exit__ */
-    tmpexit = compiler_new_tmpname(c);
-    if (tmpexit == NULL)
-	return 0;
-    PyArena_AddPyObject(c->c_arena, tmpexit);
-
     if (s->v.With.optional_vars) {
 	/* Create a temporary variable to hold context.__enter__().
 	   We need to do this rather than preserving it on the stack
@@ -3082,11 +3139,10 @@
     /* Evaluate EXPR */
     VISIT(c, expr, s->v.With.context_expr);
 
-    /* Squirrel away context.__exit__  */
+    /* Squirrel away context.__exit__ by stuffing it under context */
     ADDOP(c, DUP_TOP);
     ADDOP_O(c, LOAD_ATTR, exit_attr, names);
-    if (!compiler_nameop(c, tmpexit, Store))
-	return 0;
+    ADDOP(c, ROT_TWO);
 
     /* Call context.__enter__() */
     ADDOP_O(c, LOAD_ATTR, enter_attr, names);
@@ -3130,10 +3186,9 @@
     if (!compiler_push_fblock(c, FINALLY_END, finally))
 	return 0;
 
-    /* Finally block starts; push tmpexit and issue our magic opcode. */
-    if (!compiler_nameop(c, tmpexit, Load) ||
-	!compiler_nameop(c, tmpexit, Del))
-	return 0;
+    /* Finally block starts; context.__exit__ is on the stack under
+       the exception or return information. Just issue our magic
+       opcode. */
     ADDOP(c, WITH_CLEANUP);
 
     /* Finally block ends. */
@@ -3171,19 +3226,14 @@
 	case IfExp_kind:
 		return compiler_ifexp(c, e);
 	case Dict_kind:
-		/* XXX get rid of arg? */
-		ADDOP_I(c, BUILD_MAP, 0);
 		n = asdl_seq_LEN(e->v.Dict.values);
-		/* We must arrange things just right for STORE_SUBSCR.
-		   It wants the stack to look like (value) (dict) (key) */
+		ADDOP_I(c, BUILD_MAP, (n>0xFFFF ? 0xFFFF : n));
 		for (i = 0; i < n; i++) {
-			ADDOP(c, DUP_TOP);
 			VISIT(c, expr, 
 				(expr_ty)asdl_seq_GET(e->v.Dict.values, i));
-			ADDOP(c, ROT_TWO);
 			VISIT(c, expr, 
 				(expr_ty)asdl_seq_GET(e->v.Dict.keys, i));
-			ADDOP(c, STORE_SUBSCR);
+			ADDOP(c, STORE_MAP);
 		}
 		break;
 	case Set_kind:
@@ -3222,7 +3272,6 @@
 		break;
 	case Bytes_kind:
 		ADDOP_O(c, LOAD_CONST, e->v.Bytes.s, consts);
-		ADDOP(c, MAKE_BYTES);
 		break;
 	case Ellipsis_kind:
 		ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts);
@@ -3654,10 +3703,10 @@
 instrsize(struct instr *instr)
 {
 	if (!instr->i_hasarg)
-		return 1;
+		return 1;	/* 1 byte for the opcode*/
 	if (instr->i_oparg > 0xffff)
-		return 6;
-	return 3;
+		return 6;	/* 1 (opcode) + 1 (EXTENDED_ARG opcode) + 2 (oparg) + 2(oparg extended) */
+	return 3; 		/* 1 (opcode) + 2 (oparg) */
 }
 
 static int
@@ -3730,10 +3779,7 @@
 	assert(d_bytecode >= 0);
 	assert(d_lineno >= 0);
 
-	/* XXX(nnorwitz): is there a better way to handle this?
-	   for loops are special, we want to be able to trace them
-	   each time around, so we need to set an extra line number. */
-	if (d_lineno == 0 && i->i_opcode != FOR_ITER)
+	if(d_bytecode == 0 && d_lineno == 0)
 		return 1;
 
 	if (d_bytecode > 255) {
@@ -3919,7 +3965,7 @@
 	if (tuple == NULL)
 		return NULL;
 	while (PyDict_Next(dict, &pos, &k, &v)) {
-		i = PyInt_AS_LONG(v);
+		i = PyLong_AS_LONG(v);
 		k = PyTuple_GET_ITEM(k, 0);
 		Py_INCREF(k);
 		assert((i - offset) < size);

Modified: python/branches/py3k-importlib/Python/dynload_win.c
==============================================================================
--- python/branches/py3k-importlib/Python/dynload_win.c	(original)
+++ python/branches/py3k-importlib/Python/dynload_win.c	Thu Mar 27 00:48:05 2008
@@ -1,12 +1,13 @@
 
 /* Support for dynamic loading of extension modules */
 
+#include "Python.h"
+
 #ifdef HAVE_DIRECT_H
 #include <direct.h>
 #endif
 #include <ctype.h>
 
-#include "Python.h"
 #include "importdl.h"
 #include <windows.h>
 
@@ -170,11 +171,16 @@
 		HINSTANCE hDLL = NULL;
 		char pathbuf[260];
 		LPTSTR dummy;
+		unsigned int old_mode;
 		/* We use LoadLibraryEx so Windows looks for dependent DLLs 
 		    in directory of pathname first.  However, Windows95
 		    can sometimes not work correctly unless the absolute
 		    path is used.  If GetFullPathName() fails, the LoadLibrary
 		    will certainly fail too, so use its error code */
+
+		/* Don't display a message box when Python can't load a DLL */
+		old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
+
 		if (GetFullPathName(pathname,
 				    sizeof(pathbuf),
 				    pathbuf,
@@ -182,34 +188,40 @@
 			/* XXX This call doesn't exist in Windows CE */
 			hDLL = LoadLibraryEx(pathname, NULL,
 					     LOAD_WITH_ALTERED_SEARCH_PATH);
+
+		/* restore old error mode settings */
+		SetErrorMode(old_mode);
+
 		if (hDLL==NULL){
-			char errBuf[256];
+			PyObject *message;
 			unsigned int errorCode;
 
 			/* Get an error string from Win32 error code */
-			char theInfo[256]; /* Pointer to error text
+			wchar_t theInfo[256]; /* Pointer to error text
 					      from system */
 			int theLength; /* Length of error text */
 
 			errorCode = GetLastError();
 
-			theLength = FormatMessage(
-				FORMAT_MESSAGE_FROM_SYSTEM, /* flags */
+			theLength = FormatMessageW(
+				FORMAT_MESSAGE_FROM_SYSTEM |
+				FORMAT_MESSAGE_IGNORE_INSERTS, /* flags */
 				NULL, /* message source */
 				errorCode, /* the message (error) ID */
-				0, /* default language environment */
-				(LPTSTR) theInfo, /* the buffer */
+				MAKELANGID(LANG_NEUTRAL,
+					   SUBLANG_DEFAULT),
+				           /* Default language */
+				theInfo, /* the buffer */
 				sizeof(theInfo), /* the buffer size */
 				NULL); /* no additional format args. */
 
 			/* Problem: could not get the error message.
 			   This should not happen if called correctly. */
 			if (theLength == 0) {
-				PyOS_snprintf(errBuf, sizeof(errBuf),
-				      "DLL load failed with error code %d",
-					      errorCode);
+				message = PyUnicode_FromFormat(
+					"DLL load failed with error code %d",
+					errorCode);
 			} else {
-				size_t len;
 				/* For some reason a \r\n
 				   is appended to the text */
 				if (theLength >= 2 &&
@@ -218,13 +230,16 @@
 					theLength -= 2;
 					theInfo[theLength] = '\0';
 				}
-				strcpy(errBuf, "DLL load failed: ");
-				len = strlen(errBuf);
-				strncpy(errBuf+len, theInfo,
-					sizeof(errBuf)-len);
-				errBuf[sizeof(errBuf)-1] = '\0';
+				message = PyUnicode_FromString(
+					"DLL load failed: ");
+
+				PyUnicode_AppendAndDel(&message, 
+					PyUnicode_FromUnicode(
+						theInfo, 
+						theLength));
 			}
-			PyErr_SetString(PyExc_ImportError, errBuf);
+			PyErr_SetObject(PyExc_ImportError, message);
+			Py_XDECREF(message);
 			return NULL;
 		} else {
 			char buffer[256];

Modified: python/branches/py3k-importlib/Python/errors.c
==============================================================================
--- python/branches/py3k-importlib/Python/errors.c	(original)
+++ python/branches/py3k-importlib/Python/errors.c	Thu Mar 27 00:48:05 2008
@@ -608,7 +608,7 @@
 			goto failure;
 	}
 	/* Create a real new-style class. */
-	result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO",
+	result = PyObject_CallFunction((PyObject *)&PyType_Type, "UOO",
 				       dot+1, bases, dict);
   failure:
 	Py_XDECREF(bases);
@@ -626,7 +626,7 @@
 	PyObject *f, *t, *v, *tb;
 	PyErr_Fetch(&t, &v, &tb);
 	f = PySys_GetObject("stderr");
-	if (f != NULL) {
+	if (f != NULL && f != Py_None) {
 		PyFile_WriteString("Exception ", f);
 		if (t) {
 			PyObject* moduleName;
@@ -645,7 +645,7 @@
 			else {
 				char* modstr = PyUnicode_AsString(moduleName);
 				if (modstr &&
-				    strcmp(modstr, "__builtin__") != 0)
+				    strcmp(modstr, "builtins") != 0)
 				{
 					PyFile_WriteString(modstr, f);
 					PyFile_WriteString(".", f);
@@ -711,7 +711,7 @@
 {
 	PyObject *mod, *dict, *func = NULL;
 
-	mod = PyImport_ImportModule("warnings");
+	mod = PyImport_ImportModuleNoBlock("warnings");
 	if (mod != NULL) {
 		dict = PyModule_GetDict(mod);
 		func = PyDict_GetItemString(dict, "warn_explicit");
@@ -752,7 +752,7 @@
 	PyErr_NormalizeException(&exc, &v, &tb);
 	/* XXX check that it is, indeed, a syntax error. It might not
 	 * be, though. */
-	tmp = PyInt_FromLong(lineno);
+	tmp = PyLong_FromLong(lineno);
 	if (tmp == NULL)
 		PyErr_Clear();
 	else {

Modified: python/branches/py3k-importlib/Python/frozen.c
==============================================================================
--- python/branches/py3k-importlib/Python/frozen.c	(original)
+++ python/branches/py3k-importlib/Python/frozen.c	Thu Mar 27 00:48:05 2008
@@ -8,19 +8,18 @@
    some famous words... */
 
 /* To regenerate this data after the bytecode or marshal format has changed,
-   go to ../Tools/freeze/ and freeze the hello.py file; then copy and paste
+   go to ../Tools/freeze/ and freeze the flag.py file; then copy and paste
    the appropriate bytes from M___main__.c. */
 
 static unsigned char M___hello__[] = {
-	99,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,
-	0,64,0,0,0,115,14,0,0,0,101,0,0,100,0,0,
-	131,1,0,1,100,1,0,83,40,2,0,0,0,117,14,0,
-	0,0,72,101,108,108,111,32,119,111,114,108,100,46,46,46,
-	78,40,1,0,0,0,117,5,0,0,0,112,114,105,110,116,
-	40,0,0,0,0,40,0,0,0,0,40,0,0,0,0,117,
-	8,0,0,0,104,101,108,108,111,46,112,121,117,8,0,0,
-	0,60,109,111,100,117,108,101,62,1,0,0,0,115,0,0,
-	0,0,
+	99,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
+	0,64,0,0,0,115,10,0,0,0,100,1,0,90,1,0,
+	100,0,0,83,40,2,0,0,0,78,84,40,2,0,0,0,
+	117,4,0,0,0,84,114,117,101,117,11,0,0,0,105,110,
+	105,116,105,97,108,105,122,101,100,40,0,0,0,0,40,0,
+	0,0,0,40,0,0,0,0,117,7,0,0,0,102,108,97,
+	103,46,112,121,117,8,0,0,0,60,109,111,100,117,108,101,
+	62,1,0,0,0,115,0,0,0,0,
 };
 
 #define SIZE (int)sizeof(M___hello__)

Modified: python/branches/py3k-importlib/Python/future.c
==============================================================================
--- python/branches/py3k-importlib/Python/future.c	(original)
+++ python/branches/py3k-importlib/Python/future.c	Thu Mar 27 00:48:05 2008
@@ -33,6 +33,8 @@
 			continue;
 		} else if (strcmp(feature, FUTURE_WITH_STATEMENT) == 0) {
 			continue;
+		} else if (strcmp(feature, FUTURE_PRINT_FUNCTION) == 0) {
+			continue;
 		} else if (strcmp(feature, "braces") == 0) {
 			PyErr_SetString(PyExc_SyntaxError,
 					"not a chance");
@@ -65,7 +67,7 @@
 
 	/* A subsequent pass will detect future imports that don't
 	   appear at the beginning of the file.  There's one case,
-	   however, that is easier to handl here: A series of imports
+	   however, that is easier to handle here: A series of imports
 	   joined by semi-colons, where the first import is a future
 	   statement but some subsequent import has the future form
 	   but is preceded by a regular import.

Modified: python/branches/py3k-importlib/Python/getargs.c
==============================================================================
--- python/branches/py3k-importlib/Python/getargs.c	(original)
+++ python/branches/py3k-importlib/Python/getargs.c	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,7 @@
 
 
 #ifdef __cplusplus
-extern "C" { 
+extern "C" {
 #endif
 int PyArg_Parse(PyObject *, const char *, ...);
 int PyArg_ParseTuple(PyObject *, const char *, ...);
@@ -37,7 +37,7 @@
 /* Forward */
 static int vgetargs1(PyObject *, const char *, va_list *, int);
 static void seterror(int, const char *, int *, const char *, const char *);
-static char *convertitem(PyObject *, const char **, va_list *, int, int *, 
+static char *convertitem(PyObject *, const char **, va_list *, int, int *,
                          char *, size_t, PyObject **);
 static char *converttuple(PyObject *, const char **, va_list *, int,
 			  int *, char *, size_t, int, PyObject **);
@@ -54,7 +54,7 @@
 {
 	int retval;
 	va_list va;
-	
+
 	va_start(va, format);
 	retval = vgetargs1(args, format, &va, FLAG_COMPAT);
 	va_end(va);
@@ -66,7 +66,7 @@
 {
 	int retval;
 	va_list va;
-	
+
 	va_start(va, format);
 	retval = vgetargs1(args, format, &va, FLAG_COMPAT|FLAG_SIZE_T);
 	va_end(va);
@@ -79,7 +79,7 @@
 {
 	int retval;
 	va_list va;
-	
+
 	va_start(va, format);
 	retval = vgetargs1(args, format, &va, 0);
 	va_end(va);
@@ -91,7 +91,7 @@
 {
 	int retval;
 	va_list va;
-	
+
 	va_start(va, format);
 	retval = vgetargs1(args, format, &va, FLAG_SIZE_T);
 	va_end(va);
@@ -154,7 +154,7 @@
 		PyMem_FREE(ptr);
 		return -1;
 	}
-	if(PyList_Append(*freelist, cobj)) {
+	if (PyList_Append(*freelist, cobj)) {
                 PyMem_FREE(ptr);
 		Py_DECREF(cobj);
 		return -1;
@@ -166,8 +166,8 @@
 static int
 cleanreturn(int retval, PyObject *freelist)
 {
-	if(freelist) {
-		if((retval) == 0) {
+	if (freelist) {
+		if (retval == 0) {
 			Py_ssize_t len = PyList_GET_SIZE(freelist), i;
 			for (i = 0; i < len; i++)
                                 PyMem_FREE(PyCObject_AsVoidPtr(
@@ -240,15 +240,15 @@
 			break;
 		}
 	}
-	
+
 	if (level != 0)
 		Py_FatalError(/* '(' */ "missing ')' in getargs format");
-	
+
 	if (min < 0)
 		min = max;
-	
+
 	format = formatsave;
-	
+
 	if (compat) {
 		if (max == 0) {
 			if (args == NULL)
@@ -269,7 +269,7 @@
 				PyErr_SetString(PyExc_TypeError, msgbuf);
 				return 0;
 			}
-			msg = convertitem(args, &format, p_va, flags, levels, 
+			msg = convertitem(args, &format, p_va, flags, levels,
 					  msgbuf, sizeof(msgbuf), &freelist);
 			if (msg == NULL)
 				return cleanreturn(1, freelist);
@@ -282,15 +282,15 @@
 			return 0;
 		}
 	}
-	
+
 	if (!PyTuple_Check(args)) {
 		PyErr_SetString(PyExc_SystemError,
 		    "new style getargs format but argument is not a tuple");
 		return 0;
 	}
-	
+
 	len = PyTuple_GET_SIZE(args);
-	
+
 	if (len < min || max < len) {
 		if (message == NULL) {
 			PyOS_snprintf(msgbuf, sizeof(msgbuf),
@@ -308,12 +308,12 @@
 		PyErr_SetString(PyExc_TypeError, message);
 		return 0;
 	}
-	
+
 	for (i = 0; i < len; i++) {
 		if (*format == '|')
 			format++;
 		msg = convertitem(PyTuple_GET_ITEM(args, i), &format, p_va,
-				  flags, levels, msgbuf, 
+				  flags, levels, msgbuf,
 				  sizeof(msgbuf), &freelist);
 		if (msg) {
 			seterror(i+1, msg, levels, fname, message);
@@ -328,7 +328,7 @@
 			     "bad format string: %.200s", formatsave);
 		return cleanreturn(0, freelist);
 	}
-	
+
 	return cleanreturn(1, freelist);
 }
 
@@ -392,14 +392,14 @@
 
 static char *
 converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
-             int *levels, char *msgbuf, size_t bufsize, int toplevel, 
+             int *levels, char *msgbuf, size_t bufsize, int toplevel,
              PyObject **freelist)
 {
 	int level = 0;
 	int n = 0;
 	const char *format = *p_format;
 	int i;
-	
+
 	for (;;) {
 		int c = *format++;
 		if (c == '(') {
@@ -417,17 +417,17 @@
 		else if (level == 0 && isalpha(Py_CHARMASK(c)))
 			n++;
 	}
-	
+
 	if (!PySequence_Check(arg) || PyString_Check(arg)) {
 		levels[0] = 0;
 		PyOS_snprintf(msgbuf, bufsize,
 			      toplevel ? "expected %d arguments, not %.50s" :
 			              "must be %d-item sequence, not %.50s",
-			      n, 
+			      n,
 			      arg == Py_None ? "None" : arg->ob_type->tp_name);
 		return msgbuf;
 	}
-	
+
 	if ((i = PySequence_Size(arg)) != n) {
 		levels[0] = 0;
 		PyOS_snprintf(msgbuf, bufsize,
@@ -449,7 +449,7 @@
 			strncpy(msgbuf, "is not retrievable", bufsize);
 			return msgbuf;
 		}
-		msg = convertitem(item, &format, p_va, flags, levels+1, 
+		msg = convertitem(item, &format, p_va, flags, levels+1,
 				  msgbuf, bufsize, freelist);
 		/* PySequence_GetItem calls tp->sq_item, which INCREFs */
 		Py_XDECREF(item);
@@ -472,16 +472,16 @@
 {
 	char *msg;
 	const char *format = *p_format;
-	
+
 	if (*format == '(' /* ')' */) {
 		format++;
-		msg = converttuple(arg, &format, p_va, flags, levels, msgbuf, 
+		msg = converttuple(arg, &format, p_va, flags, levels, msgbuf,
 				   bufsize, 0, freelist);
 		if (msg == NULL)
 			format++;
 	}
 	else {
-		msg = convertsimple(arg, &format, p_va, flags, 
+		msg = convertsimple(arg, &format, p_va, flags,
 				    msgbuf, bufsize, freelist);
 		if (msg != NULL)
 			levels[0] = 0;
@@ -502,7 +502,7 @@
 converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
 {
 	assert(expected != NULL);
-	assert(arg != NULL); 
+	assert(arg != NULL);
 	PyOS_snprintf(msgbuf, bufsize,
 		      "must be %.50s, not %.50s", expected,
 		      arg == Py_None ? "None" : arg->ob_type->tp_name);
@@ -548,15 +548,15 @@
 	const char *format = *p_format;
 	char c = *format++;
 	PyObject *uarg;
-	
+
 	switch (c) {
-	
+
 	case 'b': { /* unsigned byte -- very short int */
 		char *p = va_arg(*p_va, char *);
 		long ival;
 		if (float_argument_error(arg))
 			return converterr("integer<b>", arg, msgbuf, bufsize);
-		ival = PyInt_AsLong(arg);
+		ival = PyLong_AsLong(arg);
 		if (ival == -1 && PyErr_Occurred())
 			return converterr("integer<b>", arg, msgbuf, bufsize);
 		else if (ival < 0) {
@@ -573,27 +573,27 @@
 			*p = (unsigned char) ival;
 		break;
 	}
-	
+
 	case 'B': {/* byte sized bitfield - both signed and unsigned
-		      values allowed */  
+		      values allowed */
 		char *p = va_arg(*p_va, char *);
 		long ival;
 		if (float_argument_error(arg))
 			return converterr("integer<B>", arg, msgbuf, bufsize);
-		ival = PyInt_AsUnsignedLongMask(arg);
+		ival = PyLong_AsUnsignedLongMask(arg);
 		if (ival == -1 && PyErr_Occurred())
 			return converterr("integer<B>", arg, msgbuf, bufsize);
 		else
 			*p = (unsigned char) ival;
 		break;
 	}
-	
+
 	case 'h': {/* signed short int */
 		short *p = va_arg(*p_va, short *);
 		long ival;
 		if (float_argument_error(arg))
 			return converterr("integer<h>", arg, msgbuf, bufsize);
-		ival = PyInt_AsLong(arg);
+		ival = PyLong_AsLong(arg);
 		if (ival == -1 && PyErr_Occurred())
 			return converterr("integer<h>", arg, msgbuf, bufsize);
 		else if (ival < SHRT_MIN) {
@@ -610,14 +610,14 @@
 			*p = (short) ival;
 		break;
 	}
-	
+
 	case 'H': { /* short int sized bitfield, both signed and
-		       unsigned allowed */ 
+		       unsigned allowed */
 		unsigned short *p = va_arg(*p_va, unsigned short *);
 		long ival;
 		if (float_argument_error(arg))
 			return converterr("integer<H>", arg, msgbuf, bufsize);
-		ival = PyInt_AsUnsignedLongMask(arg);
+		ival = PyLong_AsUnsignedLongMask(arg);
 		if (ival == -1 && PyErr_Occurred())
 			return converterr("integer<H>", arg, msgbuf, bufsize);
 		else
@@ -630,7 +630,7 @@
 		long ival;
 		if (float_argument_error(arg))
 			return converterr("integer<i>", arg, msgbuf, bufsize);
-		ival = PyInt_AsLong(arg);
+		ival = PyLong_AsLong(arg);
 		if (ival == -1 && PyErr_Occurred())
 			return converterr("integer<i>", arg, msgbuf, bufsize);
 		else if (ival > INT_MAX) {
@@ -649,19 +649,19 @@
 	}
 
 	case 'I': { /* int sized bitfield, both signed and
-		       unsigned allowed */ 
+		       unsigned allowed */
 		unsigned int *p = va_arg(*p_va, unsigned int *);
 		unsigned int ival;
 		if (float_argument_error(arg))
 			return converterr("integer<I>", arg, msgbuf, bufsize);
-		ival = (unsigned int)PyInt_AsUnsignedLongMask(arg);
+		ival = (unsigned int)PyLong_AsUnsignedLongMask(arg);
 		if (ival == (unsigned int)-1 && PyErr_Occurred())
 			return converterr("integer<I>", arg, msgbuf, bufsize);
 		else
 			*p = ival;
 		break;
 	}
-	
+
 	case 'n': /* Py_ssize_t */
 #if SIZEOF_SIZE_T != SIZEOF_LONG
 	{
@@ -672,7 +672,7 @@
 			return converterr("integer<n>", arg, msgbuf, bufsize);
 		iobj = PyNumber_Index(arg);
 		if (iobj != NULL)
-			ival = PyInt_AsSsize_t(arg);
+			ival = PyLong_AsSsize_t(arg);
 		if (ival == -1 && PyErr_Occurred())
 			return converterr("integer<n>", arg, msgbuf, bufsize);
 		*p = ival;
@@ -685,7 +685,7 @@
 		long ival;
 		if (float_argument_error(arg))
 			return converterr("integer<l>", arg, msgbuf, bufsize);
-		ival = PyInt_AsLong(arg);
+		ival = PyLong_AsLong(arg);
 		if (ival == -1 && PyErr_Occurred())
 			return converterr("integer<l>", arg, msgbuf, bufsize);
 		else
@@ -696,21 +696,19 @@
 	case 'k': { /* long sized bitfield */
 		unsigned long *p = va_arg(*p_va, unsigned long *);
 		unsigned long ival;
-		if (PyInt_Check(arg))
-			ival = PyInt_AsUnsignedLongMask(arg);
-		else if (PyLong_Check(arg))
+		if (PyLong_Check(arg))
 			ival = PyLong_AsUnsignedLongMask(arg);
 		else
 			return converterr("integer<k>", arg, msgbuf, bufsize);
 		*p = ival;
 		break;
 	}
-	
+
 #ifdef HAVE_LONG_LONG
 	case 'L': {/* PY_LONG_LONG */
 		PY_LONG_LONG *p = va_arg( *p_va, PY_LONG_LONG * );
 		PY_LONG_LONG ival = PyLong_AsLongLong( arg );
-		if( ival == (PY_LONG_LONG)-1 && PyErr_Occurred() ) {
+		if (ival == (PY_LONG_LONG)-1 && PyErr_Occurred() ) {
 			return converterr("long<L>", arg, msgbuf, bufsize);
 		} else {
 			*p = ival;
@@ -729,7 +727,7 @@
 		break;
 	}
 #endif
-	
+
 	case 'f': {/* float */
 		float *p = va_arg(*p_va, float *);
 		double dval = PyFloat_AsDouble(arg);
@@ -739,7 +737,7 @@
 			*p = (float) dval;
 		break;
 	}
-	
+
 	case 'd': {/* double */
 		double *p = va_arg(*p_va, double *);
 		double dval = PyFloat_AsDouble(arg);
@@ -749,7 +747,7 @@
 			*p = dval;
 		break;
 	}
-	
+
 #ifndef WITHOUT_COMPLEX
 	case 'D': {/* complex double */
 		Py_complex *p = va_arg(*p_va, Py_complex *);
@@ -762,7 +760,7 @@
 		break;
 	}
 #endif /* WITHOUT_COMPLEX */
-	
+
 	case 'c': {/* char */
 		char *p = va_arg(*p_va, char *);
 		if (PyString_Check(arg) && PyString_Size(arg) == 1)
@@ -770,12 +768,12 @@
 		else if (PyUnicode_Check(arg) &&
 			 PyUnicode_GET_SIZE(arg) == 1 &&
 			 PyUnicode_AS_UNICODE(arg)[0] < 256)
-			*p = PyUnicode_AS_UNICODE(arg)[0];
+			*p = (char)PyUnicode_AS_UNICODE(arg)[0];
 		else
 			return converterr("char < 256", arg, msgbuf, bufsize);
 		break;
 	}
-	
+
 	case 'C': {/* unicode char */
 		int *p = va_arg(*p_va, int *);
 		if (PyString_Check(arg) && PyString_Size(arg) == 1)
@@ -787,17 +785,16 @@
 			return converterr("char", arg, msgbuf, bufsize);
 		break;
 	}
-	
-	case 's': {/* string */
+
+	/* XXX WAAAAH!  's', 'y', 'z', 'u', 'Z', 'e', 'w', 't' codes all
+	   need to be cleaned up! */
+
+	case 's': {/* text string */
 		if (*format == '#') {
 			void **p = (void **)va_arg(*p_va, char **);
 			FETCH_SIZE;
-			
-			if (PyString_Check(arg)) {
-				*p = PyString_AS_STRING(arg);
-				STORE_SIZE(PyString_GET_SIZE(arg));
-			}
-			else if (PyUnicode_Check(arg)) {
+
+			if (PyUnicode_Check(arg)) {
 				uarg = UNICODE_DEFAULT_ENCODING(arg);
 				if (uarg == NULL)
 					return converterr(CONV_UNICODE,
@@ -806,6 +803,7 @@
 				STORE_SIZE(PyString_GET_SIZE(uarg));
 			}
 			else { /* any buffer-like object */
+				/* XXX Really? */
 				char *buf;
 				Py_ssize_t count = convertbuffer(arg, p, &buf);
 				if (count < 0)
@@ -815,10 +813,8 @@
 			format++;
 		} else {
 			char **p = va_arg(*p_va, char **);
-			
-			if (PyString_Check(arg))
-				*p = PyString_AS_STRING(arg);
-			else if (PyUnicode_Check(arg)) {
+
+			if (PyUnicode_Check(arg)) {
 				uarg = UNICODE_DEFAULT_ENCODING(arg);
 				if (uarg == NULL)
 					return converterr(CONV_UNICODE,
@@ -827,52 +823,39 @@
 			}
 			else
 				return converterr("string", arg, msgbuf, bufsize);
-			if ((Py_ssize_t)strlen(*p) != PyString_Size(arg))
+			/* XXX(gb): this test is completely wrong -- p is a
+			 * byte string while arg is a Unicode. I *think* it should
+			 * check against the size of uarg... */
+			if ((Py_ssize_t)strlen(*p) != PyUnicode_GetSize(arg))
 				return converterr("string without null bytes",
 						  arg, msgbuf, bufsize);
 		}
 		break;
 	}
 
-	case 'y': {/* bytes */
+	case 'y': {/* any buffer-like object, but not PyUnicode */
+		void **p = (void **)va_arg(*p_va, char **);
+		char *buf;
+		Py_ssize_t count = convertbuffer(arg, p, &buf);
+		if (count < 0)
+			return converterr(buf, arg, msgbuf, bufsize);
 		if (*format == '#') {
-			void **p = (void **)va_arg(*p_va, char **);
 			FETCH_SIZE;
-			
-			if (PyBytes_Check(arg)) {
-				*p = PyBytes_AS_STRING(arg);
-				STORE_SIZE(PyBytes_GET_SIZE(arg));
-			}
-			else
-				return converterr("bytes", arg, msgbuf, bufsize);
+			STORE_SIZE(count);
 			format++;
-		} else {
-			char **p = va_arg(*p_va, char **);
-			
-			if (PyBytes_Check(arg))
-				*p = PyBytes_AS_STRING(arg);
-			else
-				return converterr("bytes", arg, msgbuf, bufsize);
-			if ((Py_ssize_t)strlen(*p) != PyBytes_Size(arg))
-				return converterr("bytes without null bytes",
-						  arg, msgbuf, bufsize);
 		}
 		break;
 	}
 
-	case 'z': {/* string, may be NULL (None) */
+	case 'z': {/* like 's' or 's#', but None is okay, stored as NULL */
 		if (*format == '#') { /* any buffer-like object */
 			void **p = (void **)va_arg(*p_va, char **);
 			FETCH_SIZE;
-			
+
 			if (arg == Py_None) {
 				*p = 0;
 				STORE_SIZE(0);
 			}
-			else if (PyString_Check(arg)) {
-				*p = PyString_AS_STRING(arg);
-				STORE_SIZE(PyString_GET_SIZE(arg));
-			}
 			else if (PyUnicode_Check(arg)) {
 				uarg = UNICODE_DEFAULT_ENCODING(arg);
 				if (uarg == NULL)
@@ -882,6 +865,7 @@
 				STORE_SIZE(PyString_GET_SIZE(uarg));
 			}
 			else { /* any buffer-like object */
+				/* XXX Really? */
 				char *buf;
 				Py_ssize_t count = convertbuffer(arg, p, &buf);
 				if (count < 0)
@@ -891,7 +875,7 @@
 			format++;
 		} else {
 			char **p = va_arg(*p_va, char **);
-			
+
 			if (arg == Py_None)
 				*p = 0;
 			else if (PyString_Check(arg))
@@ -904,31 +888,34 @@
 				*p = PyString_AS_STRING(uarg);
 			}
 			else
-				return converterr("string or None", 
+				return converterr("string or None",
 						  arg, msgbuf, bufsize);
 			if (*format == '#') {
 				FETCH_SIZE;
 				assert(0); /* XXX redundant with if-case */
-				if (arg == Py_None)
-					*q = 0;
-				else
-					*q = PyString_Size(arg);
+				if (arg == Py_None) {
+					STORE_SIZE(0);
+				}
+				else {
+					STORE_SIZE(PyString_Size(arg));
+				}
 				format++;
 			}
+			/* XXX(gb): same comment as for 's' applies here... */
 			else if (*p != NULL &&
-				 (Py_ssize_t)strlen(*p) != PyString_Size(arg))
+				 (Py_ssize_t)strlen(*p) != PyUnicode_GetSize(arg))
 				return converterr(
-					"string without null bytes or None", 
+					"string without null bytes or None",
 					arg, msgbuf, bufsize);
 		}
 		break;
 	}
-	
+
 	case 'Z': {/* unicode, may be NULL (None) */
 		if (*format == '#') { /* any buffer-like object */
 			Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);
 			FETCH_SIZE;
-			
+
 			if (arg == Py_None) {
 				*p = 0;
 				STORE_SIZE(0);
@@ -940,18 +927,18 @@
 			format++;
 		} else {
 			Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);
-			
+
 			if (arg == Py_None)
 				*p = 0;
 			else if (PyUnicode_Check(arg))
 				*p = PyUnicode_AS_UNICODE(arg);
 			else
-				return converterr("string or None", 
+				return converterr("string or None",
 						  arg, msgbuf, bufsize);
 		}
 		break;
 	}
-	
+
 	case 'e': {/* encoded string */
 		char **buffer;
 		const char *encoding;
@@ -964,10 +951,10 @@
 		encoding = (const char *)va_arg(*p_va, const char *);
 		if (encoding == NULL)
 			encoding = PyUnicode_GetDefaultEncoding();
-			
+
 		/* Get output buffer parameter:
 		   's' (recode all objects via Unicode) or
-		   't' (only recode non-string objects) 
+		   't' (only recode non-string objects)
 		*/
 		if (*format == 's')
 			recode_strings = 1;
@@ -980,9 +967,9 @@
 		buffer = (char **)va_arg(*p_va, char **);
 		format++;
 		if (buffer == NULL)
-			return converterr("(buffer is NULL)", 
+			return converterr("(buffer is NULL)",
 					  arg, msgbuf, bufsize);
-			
+
 		/* Encode object */
 		if (!recode_strings &&
                     (PyString_Check(arg) || PyBytes_Check(arg))) {
@@ -999,9 +986,9 @@
 			u = PyUnicode_FromObject(arg);
 			if (u == NULL)
 				return converterr(
-					"string or unicode or text buffer", 
+					"string or unicode or text buffer",
 					arg, msgbuf, bufsize);
-			
+
 			/* Encode object; use default error handling */
 			s = PyUnicode_AsEncodedString(u,
 						      encoding,
@@ -1010,28 +997,28 @@
 			if (s == NULL)
 				return converterr("(encoding failed)",
 						  arg, msgbuf, bufsize);
-			if (!PyBytes_Check(s)) {
+			if (!PyString_Check(s)) {
 				Py_DECREF(s);
 				return converterr(
 					"(encoder failed to return bytes)",
 					arg, msgbuf, bufsize);
 			}
-			size = PyBytes_GET_SIZE(s);
-			ptr = PyBytes_AS_STRING(s);
+			size = PyString_GET_SIZE(s);
+			ptr = PyString_AS_STRING(s);
 			if (ptr == NULL)
 				ptr = "";
 		}
 
 		/* Write output; output is guaranteed to be 0-terminated */
-		if (*format == '#') { 
+		if (*format == '#') {
 			/* Using buffer length parameter '#':
-				   
+
 			   - if *buffer is NULL, a new buffer of the
 			   needed size is allocated and the data
 			   copied into it; *buffer is updated to point
 			   to the new buffer; the caller is
 			   responsible for PyMem_Free()ing it after
-			   usage 
+			   usage
 
 			   - if *buffer is not NULL, the data is
 			   copied to *buffer; *buffer_len has to be
@@ -1039,11 +1026,11 @@
 			   buffer overflow is signalled with an error;
 			   buffer has to provide enough room for the
 			   encoded string plus the trailing 0-byte
-			   
+
 			   - in both cases, *buffer_len is updated to
 			   the size of the buffer /excluding/ the
-			   trailing 0-byte 
-			   
+			   trailing 0-byte
+
 			*/
 			FETCH_SIZE;
 
@@ -1062,7 +1049,7 @@
 						"(memory error)",
 						arg, msgbuf, bufsize);
 				}
-				if(addcleanup(*buffer, freelist)) {
+				if (addcleanup(*buffer, freelist)) {
 					Py_DECREF(s);
 					return converterr(
 						"(cleanup problem)",
@@ -1072,7 +1059,7 @@
 				if (size + 1 > BUFFER_LEN) {
 					Py_DECREF(s);
 					return converterr(
-						"(buffer overflow)", 
+						"(buffer overflow)",
 						arg, msgbuf, bufsize);
 				}
 			}
@@ -1080,10 +1067,10 @@
 			STORE_SIZE(size);
 		} else {
 			/* Using a 0-terminated buffer:
-				   
+
 			   - the encoded string has to be 0-terminated
 			   for this variant to work; if it is not, an
-			   error raised 
+			   error raised
 
 			   - a new buffer of the needed size is
 			   allocated and the data copied into it;
@@ -1104,7 +1091,7 @@
 				return converterr("(memory error)",
 						  arg, msgbuf, bufsize);
 			}
-			if(addcleanup(*buffer, freelist)) {
+			if (addcleanup(*buffer, freelist)) {
 				Py_DECREF(s);
 				return converterr("(cleanup problem)",
 						arg, msgbuf, bufsize);
@@ -1116,55 +1103,45 @@
 	}
 
 	case 'u': {/* raw unicode buffer (Py_UNICODE *) */
-		if (*format == '#') { /* any buffer-like object */
-			void **p = (void **)va_arg(*p_va, char **);
+		Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);
+		if (!PyUnicode_Check(arg))
+			return converterr("str", arg, msgbuf, bufsize);
+		*p = PyUnicode_AS_UNICODE(arg);
+		if (*format == '#') { /* store pointer and size */
 			FETCH_SIZE;
-			if (PyUnicode_Check(arg)) {
-			    	*p = PyUnicode_AS_UNICODE(arg);
-				STORE_SIZE(PyUnicode_GET_SIZE(arg));
-			}
-			else {
-				return converterr("cannot convert raw buffers",
-						  arg, msgbuf, bufsize);
-			}
+			STORE_SIZE(PyUnicode_GET_SIZE(arg));
 			format++;
-		} else {
-			Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);
-			if (PyUnicode_Check(arg))
-				*p = PyUnicode_AS_UNICODE(arg);
-			else
-				return converterr("unicode", arg, msgbuf, bufsize);
 		}
 		break;
 	}
 
-	case 'S': { /* string object */
+	case 'S': { /* PyString object */
 		PyObject **p = va_arg(*p_va, PyObject **);
-		if (PyString_Check(arg) || PyUnicode_Check(arg))
+		if (PyString_Check(arg))
 			*p = arg;
 		else
-			return converterr("string", arg, msgbuf, bufsize);
+			return converterr("bytes", arg, msgbuf, bufsize);
 		break;
 	}
 
-	case 'Y': { /* bytes object */
+	case 'Y': { /* PyBytes object */
 		PyObject **p = va_arg(*p_va, PyObject **);
 		if (PyBytes_Check(arg))
 			*p = arg;
 		else
-			return converterr("bytes", arg, msgbuf, bufsize);
+			return converterr("buffer", arg, msgbuf, bufsize);
 		break;
 	}
-	
-	case 'U': { /* Unicode object */
+
+	case 'U': { /* PyUnicode object */
 		PyObject **p = va_arg(*p_va, PyObject **);
 		if (PyUnicode_Check(arg))
 			*p = arg;
 		else
-			return converterr("unicode", arg, msgbuf, bufsize);
+			return converterr("str", arg, msgbuf, bufsize);
 		break;
 	}
-	
+
 	case 'O': { /* object */
 		PyTypeObject *type;
 		PyObject **p;
@@ -1182,12 +1159,12 @@
 			inquiry pred = va_arg(*p_va, inquiry);
 			p = va_arg(*p_va, PyObject **);
 			format++;
-			if ((*pred)(arg)) 
+			if ((*pred)(arg))
 				*p = arg;
 			else
-				return converterr("(unspecified)", 
+				return converterr("(unspecified)",
 						  arg, msgbuf, bufsize);
-				
+
 		}
 		else if (*format == '&') {
 			typedef int (*converter)(PyObject *, void *);
@@ -1195,7 +1172,7 @@
 			void *addr = va_arg(*p_va, void *);
 			format++;
 			if (! (*convert)(arg, addr))
-				return converterr("(unspecified)", 
+				return converterr("(unspecified)",
 						  arg, msgbuf, bufsize);
 		}
 		else {
@@ -1204,27 +1181,27 @@
 		}
 		break;
 	}
-		
-		
+
+
 	case 'w': { /* memory buffer, read-write access */
 		void **p = va_arg(*p_va, void **);
 		PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
-		int count;
+		Py_ssize_t count;
                 int temp=-1;
                 Py_buffer view;
-			
-		if (pb == NULL || 
+
+		if (pb == NULL ||
 		    pb->bf_getbuffer == NULL ||
-                    ((temp = (*pb->bf_getbuffer)(arg, &view, 
+                    ((temp = (*pb->bf_getbuffer)(arg, &view,
                                                  PyBUF_SIMPLE)) != 0) ||
                     view.readonly == 1) {
                         if (temp==0 && pb->bf_releasebuffer != NULL) {
                                 (*pb->bf_releasebuffer)(arg, &view);
                         }
-			return converterr("single-segment read-write buffer", 
+			return converterr("single-segment read-write buffer",
 					  arg, msgbuf, bufsize);
                 }
-                        
+
                 if ((count = view.len) < 0)
 			return converterr("(unspecified)", arg, msgbuf, bufsize);
                 *p = view.buf;
@@ -1243,19 +1220,19 @@
 	case 't': { /* 8-bit character buffer, read-only access */
 		char **p = va_arg(*p_va, char **);
 		PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
-		int count;
+		Py_ssize_t count;
                 Py_buffer view;
-		
+
 		if (*format++ != '#')
 			return converterr(
-				"invalid use of 't' format character", 
+				"invalid use of 't' format character",
 				arg, msgbuf, bufsize);
 		if (pb == NULL || pb->bf_getbuffer == NULL)
 			return converterr(
 				"bytes or read-only character buffer",
 				arg, msgbuf, bufsize);
 
-		if ((*pb->bf_getbuffer)(arg, &view, PyBUF_SIMPLE) != 0) 
+		if ((*pb->bf_getbuffer)(arg, &view, PyBUF_SIMPLE) != 0)
 			return converterr("string or single-segment read-only buffer",
                                           arg, msgbuf, bufsize);
 
@@ -1263,7 +1240,7 @@
                 *p = view.buf;
                 /* XXX : shouldn't really release buffer, but it should be O.K.
                 */
-                if (pb->bf_releasebuffer != NULL) 
+                if (pb->bf_releasebuffer != NULL)
                         (*pb->bf_releasebuffer)(arg, &view);
 		if (count < 0)
 			return converterr("(unspecified)", arg, msgbuf, bufsize);
@@ -1276,9 +1253,9 @@
 
 	default:
 		return converterr("impossible<bad format char>", arg, msgbuf, bufsize);
-	
+
 	}
-	
+
 	*p_format = format;
 	return NULL;
 }
@@ -1294,12 +1271,12 @@
         *p = NULL;
 	if (pb == NULL ||
 	    pb->bf_getbuffer == NULL) {
-		*errmsg = "string or read-only buffer";
+		*errmsg = "bytes or read-only buffer";
 		return -1;
 	}
 
 	if ((*pb->bf_getbuffer)(arg, &view, PyBUF_SIMPLE) != 0) {
-		*errmsg = "string or single-segment read-only buffer";
+		*errmsg = "bytes or single-segment read-only buffer";
 		return -1;
 	}
         count = view.len;
@@ -1316,7 +1293,7 @@
 int
 PyArg_ParseTupleAndKeywords(PyObject *args,
 			    PyObject *keywords,
-			    const char *format, 
+			    const char *format,
 			    char **kwlist, ...)
 {
 	int retval;
@@ -1332,7 +1309,7 @@
 	}
 
 	va_start(va, kwlist);
-	retval = vgetargskeywords(args, keywords, format, kwlist, &va, 0);	
+	retval = vgetargskeywords(args, keywords, format, kwlist, &va, 0);
 	va_end(va);
 	return retval;
 }
@@ -1340,7 +1317,7 @@
 int
 _PyArg_ParseTupleAndKeywords_SizeT(PyObject *args,
 				  PyObject *keywords,
-				  const char *format, 
+				  const char *format,
 				  char **kwlist, ...)
 {
 	int retval;
@@ -1356,7 +1333,7 @@
 	}
 
 	va_start(va, kwlist);
-	retval = vgetargskeywords(args, keywords, format, 
+	retval = vgetargskeywords(args, keywords, format,
 				  kwlist, &va, FLAG_SIZE_T);
 	va_end(va);
 	return retval;
@@ -1366,7 +1343,7 @@
 int
 PyArg_VaParseTupleAndKeywords(PyObject *args,
                               PyObject *keywords,
-                              const char *format, 
+                              const char *format,
                               char **kwlist, va_list va)
 {
 	int retval;
@@ -1391,14 +1368,14 @@
 #endif
 #endif
 
-	retval = vgetargskeywords(args, keywords, format, kwlist, &lva, 0);	
+	retval = vgetargskeywords(args, keywords, format, kwlist, &lva, 0);
 	return retval;
 }
 
 int
 _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,
 				    PyObject *keywords,
-				    const char *format, 
+				    const char *format,
 				    char **kwlist, va_list va)
 {
 	int retval;
@@ -1423,11 +1400,12 @@
 #endif
 #endif
 
-	retval = vgetargskeywords(args, keywords, format, 
+	retval = vgetargskeywords(args, keywords, format,
 				  kwlist, &lva, FLAG_SIZE_T);
 	return retval;
 }
 
+#define IS_END_OF_FORMAT(c) (c == '\0' || c == ';' || c == ':')
 
 static int
 vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
@@ -1435,13 +1413,10 @@
 {
 	char msgbuf[512];
 	int levels[32];
-	const char *fname, *message;
-	int min, max;
-	const char *formatsave;
+	const char *fname, *msg, *custom_msg, *keyword;
+	int min = INT_MAX;
 	int i, len, nargs, nkeywords;
-	const char *msg;
-	char **p;
-	PyObject *freelist = NULL;
+	PyObject *freelist = NULL, *current_arg;
 
 	assert(args != NULL && PyTuple_Check(args));
 	assert(keywords == NULL || PyDict_Check(keywords));
@@ -1449,166 +1424,106 @@
 	assert(kwlist != NULL);
 	assert(p_va != NULL);
 
-	/* Search the format:
-	   message <- error msg, if any (else NULL).
-	   fname <- routine name, if any (else NULL).
-	   min <- # of required arguments, or -1 if all are required.
-	   max <- most arguments (required + optional).
-	   Check that kwlist has a non-NULL entry for each arg.
-	   Raise error if a tuple arg spec is found.
-	*/
-	fname = message = NULL;
-	formatsave = format;
-	p = kwlist;
-	min = -1;
-	max = 0;
-	while ((i = *format++) != '\0') {
-		if (isalpha(Py_CHARMASK(i)) && i != 'e') {
-			max++;
-			if (*p == NULL) {
-				PyErr_SetString(PyExc_RuntimeError,
-					"more argument specifiers than "
-					"keyword list entries");
-				return 0;
-			}
-			p++;
-		}
-		else if (i == '|')
-			min = max;
-		else if (i == ':') {
-			fname = format;
-			break;
-		}
-		else if (i == ';') {
-			message = format;
-			break;
-		}
-		else if (i == '(') {
-			PyErr_SetString(PyExc_RuntimeError,
-				"tuple found in format when using keyword "
-				"arguments");
-			return 0;
-		}
-	}
-	format = formatsave;
-	if (*p != NULL) {
-		PyErr_SetString(PyExc_RuntimeError,
-			"more keyword list entries than "
-			"argument specifiers");
-		return 0;
-	}
-	if (min < 0) {
-		/* All arguments are required. */
-		min = max;
+	/* grab the function name or custom error msg first (mutually exclusive) */
+	fname = strchr(format, ':');
+	if (fname) {
+		fname++;
+		custom_msg = NULL;
 	}
-
-	nargs = PyTuple_GET_SIZE(args);
-	nkeywords = keywords == NULL ? 0 : PyDict_Size(keywords);
-
-	/* make sure there are no duplicate values for an argument;
-	   its not clear when to use the term "keyword argument vs. 
-	   keyword parameter in messages */
-	if (nkeywords > 0) {
-		for (i = 0; i < nargs; i++) {
-			const char *thiskw = kwlist[i];
-			if (thiskw == NULL)
-				break;
-			if (PyDict_GetItemString(keywords, thiskw)) {
-				PyErr_Format(PyExc_TypeError,
-					"keyword parameter '%s' was given "
-					"by position and by name",
-					thiskw);
-				return 0;
-			}
-			else if (PyErr_Occurred())
-				return 0;
-		}
+	else {
+		custom_msg = strchr(format,';');
+		if (custom_msg)
+			custom_msg++;
 	}
 
-	/* required arguments missing from args can be supplied by keyword 
-	   arguments; set len to the number of positional arguments, and,
-	   if that's less than the minimum required, add in the number of
-	   required arguments that are supplied by keywords */
-	len = nargs;
-	if (nkeywords > 0 && nargs < min) {
-		for (i = nargs; i < min; i++) {
-			if (PyDict_GetItemString(keywords, kwlist[i]))
-				len++;
-			else if (PyErr_Occurred())
-				return 0;
-		}
-	}
+	/* scan kwlist and get greatest possible nbr of args */
+	for (len=0; kwlist[len]; len++)
+		continue;
 
-	/* make sure we got an acceptable number of arguments; the message
-	   is a little confusing with keywords since keyword arguments
-	   which are supplied, but don't match the required arguments
-	   are not included in the "%d given" part of the message 
-	   XXX and this isn't a bug!? */
-	if (len < min || max < len) {
-		if (message == NULL) {
-			PyOS_snprintf(msgbuf, sizeof(msgbuf),
-				      "%.200s%s takes %s %d argument%s "
-				      "(%d given)",
-				      fname==NULL ? "function" : fname,
-				      fname==NULL ? "" : "()",
-				      min==max ? "exactly"
-			              : len < min ? "at least" : "at most",
-				      len < min ? min : max,
-				      (len < min ? min : max) == 1 ? "" : "s",
-				      len);
-			message = msgbuf;
-		}
-		PyErr_SetString(PyExc_TypeError, message);
+	nargs = PyTuple_GET_SIZE(args);
+	nkeywords = (keywords == NULL) ? 0 : PyDict_Size(keywords);
+	if (nargs + nkeywords > len) {
+		PyErr_Format(PyExc_TypeError, "%s%s takes at most %d "
+			     "argument%s (%d given)",
+			     (fname == NULL) ? "function" : fname,
+			     (fname == NULL) ? "" : "()",
+			     len,
+			     (len == 1) ? "" : "s",
+			     nargs + nkeywords);
 		return 0;
 	}
 
-	/* convert the positional arguments */
-	for (i = 0; i < nargs; i++) {
-		if (*format == '|')
+	/* convert tuple args and keyword args in same loop, using kwlist to drive process */
+	for (i = 0; i < len; i++) {
+		keyword = kwlist[i];
+		if (*format == '|') {
+			min = i;
 			format++;
-		msg = convertitem(PyTuple_GET_ITEM(args, i), &format, p_va,
-				  flags, levels, msgbuf, sizeof(msgbuf), 
-				  &freelist);
-		if (msg) {
-			seterror(i+1, msg, levels, fname, message);
+		}
+		if (IS_END_OF_FORMAT(*format)) {
+			PyErr_Format(PyExc_RuntimeError,
+				     "More keyword list entries (%d) than "
+				     "format specifiers (%d)", len, i);
 			return cleanreturn(0, freelist);
 		}
-	}
-
-	/* handle no keyword parameters in call */	
-	if (nkeywords == 0)
-		return cleanreturn(1, freelist);
-
-	/* convert the keyword arguments; this uses the format 
-	   string where it was left after processing args */
-	for (i = nargs; i < max; i++) {
-		PyObject *item;
-		if (*format == '|')
-			format++;
-		item = PyDict_GetItemString(keywords, kwlist[i]);
-		if (item != NULL) {
-			Py_INCREF(item);
-			msg = convertitem(item, &format, p_va, flags, levels, 
-					  msgbuf, sizeof(msgbuf), &freelist);
-			Py_DECREF(item);
-			if (msg) {
-				seterror(i+1, msg, levels, fname, message);
+		current_arg = NULL;
+		if (nkeywords) {
+			current_arg = PyDict_GetItemString(keywords, keyword);
+		}
+		if (current_arg) {
+			--nkeywords;
+			if (i < nargs) {
+				/* arg present in tuple and in dict */
+				PyErr_Format(PyExc_TypeError,
+					     "Argument given by name ('%s') "
+					     "and position (%d)",
+					     keyword, i+1);
 				return cleanreturn(0, freelist);
 			}
-			--nkeywords;
-			if (nkeywords == 0)
-				break;
 		}
-		else if (PyErr_Occurred())
+		else if (nkeywords && PyErr_Occurred())
 			return cleanreturn(0, freelist);
-		else {
-			msg = skipitem(&format, p_va, flags);
+		else if (i < nargs)
+			current_arg = PyTuple_GET_ITEM(args, i);
+			
+		if (current_arg) {
+			msg = convertitem(current_arg, &format, p_va, flags,
+				levels, msgbuf, sizeof(msgbuf), &freelist);
 			if (msg) {
-				levels[0] = 0;
-				seterror(i+1, msg, levels, fname, message);
+				seterror(i+1, msg, levels, fname, custom_msg);
 				return cleanreturn(0, freelist);
 			}
+			continue;
+		}
+
+		if (i < min) {
+			PyErr_Format(PyExc_TypeError, "Required argument "
+				     "'%s' (pos %d) not found",
+				     keyword, i+1);
+			return cleanreturn(0, freelist);
 		}
+		/* current code reports success when all required args
+		 * fulfilled and no keyword args left, with no further
+		 * validation. XXX Maybe skip this in debug build ?
+		 */
+		if (!nkeywords)
+			return cleanreturn(1, freelist);
+
+		/* We are into optional args, skip thru to any remaining
+		 * keyword args */
+		msg = skipitem(&format, p_va, flags);
+		if (msg) {
+			PyErr_Format(PyExc_RuntimeError, "%s: '%s'", msg,
+				     format);
+			return cleanreturn(0, freelist);
+		}
+	}
+
+	if (!IS_END_OF_FORMAT(*format)) {
+		PyErr_Format(PyExc_RuntimeError,
+			"more argument specifiers than keyword list entries "
+			"(remaining format:'%s')", format);
+		return cleanreturn(0, freelist);
 	}
 
 	/* make sure there are no extraneous keyword arguments */
@@ -1619,12 +1534,12 @@
 			int match = 0;
 			char *ks;
 			if (!PyString_Check(key) && !PyUnicode_Check(key)) {
-				PyErr_SetString(PyExc_TypeError, 
+				PyErr_SetString(PyExc_TypeError,
 					        "keywords must be strings");
 				return cleanreturn(0, freelist);
 			}
-			ks = PyString_AsString(key);
-			for (i = 0; i < max; i++) {
+			ks = PyUnicode_AsString(key);
+			for (i = 0; i < len; i++) {
 				if (!strcmp(ks, kwlist[i])) {
 					match = 1;
 					break;
@@ -1647,9 +1562,9 @@
 static char *
 skipitem(const char **p_format, va_list *p_va, int flags)
 {
-        const char *format = *p_format;
+	const char *format = *p_format;
 	char c = *format++;
-	
+
 	switch (c) {
 
 	/* simple codes
@@ -1683,9 +1598,9 @@
 			(void) va_arg(*p_va, Py_ssize_t *);
 			break;
 		}
-	
+
 	/* string codes */
-		
+
 	case 'e': /* string with encoding */
 		{
 			(void) va_arg(*p_va, const char *);
@@ -1695,7 +1610,7 @@
 			format++;
 			/* explicit fallthrough to string cases */
 		}
-	
+
 	case 's': /* string */
 	case 'z': /* string or None */
 	case 'y': /* bytes */
@@ -1723,7 +1638,7 @@
 			(void) va_arg(*p_va, PyObject **);
 			break;
 		}
-	
+
 	case 'O': /* object */
 		{
 			if (*format == '!') {
@@ -1752,16 +1667,33 @@
 			}
 			break;
 		}
-	
+
+	case '(':	/* bypass tuple, not handled at all previously */
+		{
+			char *msg;
+			for (;;) {
+				if (*format==')')
+					break;
+				if (IS_END_OF_FORMAT(*format))
+					return "Unmatched left paren in format "
+					       "string";
+				msg = skipitem(&format, p_va, flags);
+				if (msg)
+					return msg;
+			}
+			format++;
+			break;
+		}
+
+	case ')':
+		return "Unmatched right paren in format string";
+
 	default:
 err:
 		return "impossible<bad format char>";
-	
+
 	}
 
-	/* The "(...)" format code for tuples is not handled here because
-	 * it is not allowed with keyword args. */
-	
 	*p_format = format;
 	return NULL;
 }
@@ -1786,19 +1718,19 @@
 		PyErr_SetString(PyExc_SystemError,
 		    "PyArg_UnpackTuple() argument list is not a tuple");
 		return 0;
-	}	
+	}
 	l = PyTuple_GET_SIZE(args);
 	if (l < min) {
 		if (name != NULL)
 			PyErr_Format(
 			    PyExc_TypeError,
-			    "%s expected %s%zd arguments, got %zd", 
+			    "%s expected %s%zd arguments, got %zd",
 			    name, (min == max ? "" : "at least "), min, l);
 		else
 			PyErr_Format(
 			    PyExc_TypeError,
 			    "unpacked tuple should have %s%zd elements,"
-			    " but has %zd", 
+			    " but has %zd",
 			    (min == max ? "" : "at least "), min, l);
 		va_end(vargs);
 		return 0;
@@ -1807,13 +1739,13 @@
 		if (name != NULL)
 			PyErr_Format(
 			    PyExc_TypeError,
-			    "%s expected %s%zd arguments, got %zd", 
+			    "%s expected %s%zd arguments, got %zd",
 			    name, (min == max ? "" : "at most "), max, l);
 		else
 			PyErr_Format(
 			    PyExc_TypeError,
 			    "unpacked tuple should have %s%zd elements,"
-			    " but has %zd", 
+			    " but has %zd",
 			    (min == max ? "" : "at most "), max, l);
 		va_end(vargs);
 		return 0;
@@ -1829,7 +1761,7 @@
 
 /* For type constructors that don't take keyword args
  *
- * Sets a TypeError and returns 0 if the kwds dict is 
+ * Sets a TypeError and returns 0 if the kwds dict is
  * not empty, returns 1 otherwise
  */
 int
@@ -1843,8 +1775,8 @@
 	}
 	if (PyDict_Size(kw) == 0)
 		return 1;
-	
-	PyErr_Format(PyExc_TypeError, "%s does not take keyword arguments", 
+
+	PyErr_Format(PyExc_TypeError, "%s does not take keyword arguments",
 			funcname);
 	return 0;
 }

Modified: python/branches/py3k-importlib/Python/getcopyright.c
==============================================================================
--- python/branches/py3k-importlib/Python/getcopyright.c	(original)
+++ python/branches/py3k-importlib/Python/getcopyright.c	Thu Mar 27 00:48:05 2008
@@ -4,7 +4,7 @@
 
 static char cprt[] = 
 "\
-Copyright (c) 2001-2007 Python Software Foundation.\n\
+Copyright (c) 2001-2008 Python Software Foundation.\n\
 All Rights Reserved.\n\
 \n\
 Copyright (c) 2000 BeOpen.com.\n\

Modified: python/branches/py3k-importlib/Python/hypot.c
==============================================================================
--- python/branches/py3k-importlib/Python/hypot.c	(original)
+++ python/branches/py3k-importlib/Python/hypot.c	Thu Mar 27 00:48:05 2008
@@ -1,8 +1,8 @@
 /* hypot() replacement */
 
-#include "pyconfig.h"
-#include "pyport.h"
+#include "Python.h"
 
+#ifndef HAVE_HYPOT
 double hypot(double x, double y)
 {
 	double yx;
@@ -21,3 +21,5 @@
 		return x*sqrt(1.+yx*yx);
 	}
 }
+#endif /* HAVE_HYPOT */
+

Modified: python/branches/py3k-importlib/Python/import.c
==============================================================================
--- python/branches/py3k-importlib/Python/import.c	(original)
+++ python/branches/py3k-importlib/Python/import.c	Thu Mar 27 00:48:05 2008
@@ -22,6 +22,11 @@
 extern "C" { 
 #endif
 
+#ifdef MS_WINDOWS
+/* for stat.st_mode */
+typedef unsigned short mode_t;
+#endif
+
 extern time_t PyOS_GetLastModificationTime(char *, FILE *);
 						/* In getmtime.c */
 
@@ -66,7 +71,8 @@
        Python 2.5c1: 62121 (fix wrong lnotab with for loops and
        			    storing constants that should have been removed)
        Python 2.5c2: 62131 (fix wrong code: for x, in ... in listcomp/genexp)
-       Python 2.6a0: 62141 (peephole optimizations)
+       Python 2.6a0: 62151 (peephole optimizations and STORE_MAP opcode)
+       Python 2.6a1: 62161 (WITH_CLEANUP optimization)
        Python 3000:   3000
        	              3010 (removed UNARY_CONVERT)
 		      3020 (added BUILD_SET)
@@ -76,9 +82,12 @@
 		      3060 (PEP 3115 metaclass syntax)
 		      3070 (PEP 3109 raise changes)
 		      3080 (PEP 3137 make __file__ and __name__ unicode)
-.
+		      3090 (kill str8 interning)
+		      3100 (merge from 2.6a0, see 62151)
+		      3102 (__file__ points to source file)
+       Python 3.0a4: 3110 (WITH_CLEANUP optimization).
 */
-#define MAGIC (3080 | ((long)'\r'<<16) | ((long)'\n'<<24))
+#define MAGIC (3110 | ((long)'\r'<<16) | ((long)'\n'<<24))
 
 /* Magic word as global; note that _PyImport_Init() can change the
    value of this global to accommodate for alterations of how the
@@ -91,6 +100,9 @@
 /* This table is defined in config.c: */
 extern struct _inittab _PyImport_Inittab[];
 
+/* Method from Parser/tokenizer.c */
+extern char * PyTokenizer_FindEncoding(int);
+
 struct _inittab *PyImport_Inittab = _PyImport_Inittab;
 
 /* these tables define the module suffixes that Python recognizes */
@@ -106,7 +118,7 @@
 };
 
 /* Forward declarations */
-static PyTypeObject NullImporterType;
+PyTypeObject NullImporter_Type;
 static PyCodeObject * parse_source_module(const char *, FILE *);
 static int init_builtin(char *);
 
@@ -168,7 +180,7 @@
 
 	/* adding sys.path_hooks and sys.path_importer_cache, setting up
 	   zipimport */
-	if (PyType_Ready(&NullImporterType) < 0)
+	if (PyType_Ready(&PyNullImporter_Type) < 0)
 		goto error;
 
 	if (Py_VerboseFlag)
@@ -371,6 +383,8 @@
 	"path", "argv", "ps1", "ps2",
 	"last_type", "last_value", "last_traceback",
 	"path_hooks", "path_importer_cache", "meta_path",
+	/* misc stuff */
+	"flags", "float_info",
 	NULL
 };
 
@@ -402,11 +416,11 @@
 	   deleted *last* of all, they would come too late in the normal
 	   destruction order.  Sigh. */
 
-	value = PyDict_GetItemString(modules, "__builtin__");
+	value = PyDict_GetItemString(modules, "builtins");
 	if (value != NULL && PyModule_Check(value)) {
 		dict = PyModule_GetDict(value);
 		if (Py_VerboseFlag)
-			PySys_WriteStderr("# clear __builtin__._\n");
+			PySys_WriteStderr("# clear builtins._\n");
 		PyDict_SetItemString(dict, "_", Py_None);
 	}
 	value = PyDict_GetItemString(modules, "sys");
@@ -438,11 +452,11 @@
 		PyDict_SetItemString(modules, "__main__", Py_None);
 	}
 
-	/* The special treatment of __builtin__ here is because even
+	/* The special treatment of "builtins" here is because even
 	   when it's not referenced as a module, its dictionary is
 	   referenced by almost every module's __builtins__.  Since
 	   deleting a module clears its dictionary (even if there are
-	   references left to it), we need to delete the __builtin__
+	   references left to it), we need to delete the "builtins"
 	   module last.  Likewise, we don't delete sys until the very
 	   end because it is implicitly referenced (e.g. by print).
 
@@ -453,7 +467,7 @@
 	   re-imported. */
 
 	/* Next, repeatedly delete modules with a reference count of
-	   one (skipping __builtin__ and sys) and delete them */
+	   one (skipping builtins and sys) and delete them */
 	do {
 		ndone = 0;
 		pos = 0;
@@ -462,7 +476,7 @@
 				continue;
 			if (PyUnicode_Check(key) && PyModule_Check(value)) {
 				name = PyUnicode_AsString(key);
-				if (strcmp(name, "__builtin__") == 0)
+				if (strcmp(name, "builtins") == 0)
 					continue;
 				if (strcmp(name, "sys") == 0)
 					continue;
@@ -476,12 +490,12 @@
 		}
 	} while (ndone > 0);
 
-	/* Next, delete all modules (still skipping __builtin__ and sys) */
+	/* Next, delete all modules (still skipping builtins and sys) */
 	pos = 0;
 	while (PyDict_Next(modules, &pos, &key, &value)) {
 		if (PyUnicode_Check(key) && PyModule_Check(value)) {
 			name = PyUnicode_AsString(key);
-			if (strcmp(name, "__builtin__") == 0)
+			if (strcmp(name, "builtins") == 0)
 				continue;
 			if (strcmp(name, "sys") == 0)
 				continue;
@@ -492,7 +506,7 @@
 		}
 	}
 
-	/* Next, delete sys and __builtin__ (in that order) */
+	/* Next, delete sys and builtins (in that order) */
 	value = PyDict_GetItemString(modules, "sys");
 	if (value != NULL && PyModule_Check(value)) {
 		if (Py_VerboseFlag)
@@ -500,12 +514,12 @@
 		_PyModule_Clear(value);
 		PyDict_SetItemString(modules, "sys", Py_None);
 	}
-	value = PyDict_GetItemString(modules, "__builtin__");
+	value = PyDict_GetItemString(modules, "builtins");
 	if (value != NULL && PyModule_Check(value)) {
 		if (Py_VerboseFlag)
-			PySys_WriteStderr("# cleanup __builtin__\n");
+			PySys_WriteStderr("# cleanup builtins\n");
 		_PyModule_Clear(value);
-		PyDict_SetItemString(modules, "__builtin__", Py_None);
+		PyDict_SetItemString(modules, "builtins", Py_None);
 	}
 
 	/* Finally, clear and delete the modules directory */
@@ -583,7 +597,7 @@
     }
 
     /* Add SEP as path_sep to _importlib's globals. */
-    attr = PyString_FromFormat("%c", SEP);
+    attr = PyUnicode_FromFormat("%c", SEP);
     if (!attr)
 	    Py_FatalError("could not create path_sep for _importlib");
     if (PyModule_AddObject(importlib, "path_sep", attr) < 0)
@@ -712,6 +726,8 @@
 			      "sys.modules failed");
 }
 
+static PyObject * get_sourcefile(const char *file);
+
 /* Execute a code object in a module and return the module object
  * WITH INCREMENTED REFERENCE COUNT.  If an error occurs, name is
  * removed from sys.modules, to avoid leaving damaged module objects
@@ -745,7 +761,7 @@
 	/* Remember the filename as the __file__ attribute */
 	v = NULL;
 	if (pathname != NULL) {
-		v = PyUnicode_DecodeFSDefault(pathname);
+		v = get_sourcefile(pathname);
 		if (v == NULL)
 			PyErr_Clear();
 	}
@@ -916,7 +932,7 @@
 /* Helper to open a bytecode file for writing in exclusive mode */
 
 static FILE *
-open_exclusive(char *filename)
+open_exclusive(char *filename, mode_t mode)
 {
 #if defined(O_EXCL)&&defined(O_CREAT)&&defined(O_WRONLY)&&defined(O_TRUNC)
 	/* Use O_EXCL to avoid a race condition when another process tries to
@@ -932,9 +948,9 @@
 				|O_BINARY   /* necessary for Windows */
 #endif
 #ifdef __VMS
-                        , 0666, "ctxt=bin", "shr=nil"
+                        , mode, "ctxt=bin", "shr=nil"
 #else
-                        , 0666
+                        , mode
 #endif
 		  );
 	if (fd < 0)
@@ -953,11 +969,13 @@
    remove the file. */
 
 static void
-write_compiled_module(PyCodeObject *co, char *cpathname, time_t mtime)
+write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat)
 {
 	FILE *fp;
+	time_t mtime = srcstat->st_mtime;
+	mode_t mode = srcstat->st_mode;
 
-	fp = open_exclusive(cpathname);
+	fp = open_exclusive(cpathname, mode);
 	if (fp == NULL) {
 		if (Py_VerboseFlag)
 			PySys_WriteStderr(
@@ -994,17 +1012,16 @@
 static PyObject *
 load_source_module(char *name, char *pathname, FILE *fp)
 {
-	time_t mtime;
+	struct stat st;
 	FILE *fpc;
 	char buf[MAXPATHLEN+1];
 	char *cpathname;
 	PyCodeObject *co;
 	PyObject *m;
-
-	mtime = PyOS_GetLastModificationTime(pathname, fp);
-	if (mtime == (time_t)(-1)) {
+	
+	if (fstat(fileno(fp), &st) != 0) {
 		PyErr_Format(PyExc_RuntimeError,
-			     "unable to get modification time from '%s'",
+			     "unable to get file status from '%s'",
 			     pathname);
 		return NULL;
 	}
@@ -1013,7 +1030,7 @@
 	   in 4 bytes. This will be fine until sometime in the year 2038,
 	   when a 4-byte signed time_t will overflow.
 	 */
-	if (mtime >> 32) {
+	if (st.st_mtime >> 32) {
 		PyErr_SetString(PyExc_OverflowError,
 			"modification time overflows a 4 byte field");
 		return NULL;
@@ -1022,7 +1039,7 @@
 	cpathname = make_compiled_pathname(pathname, buf,
 					   (size_t)MAXPATHLEN + 1);
 	if (cpathname != NULL &&
-	    (fpc = check_compiled_module(pathname, mtime, cpathname))) {
+	    (fpc = check_compiled_module(pathname, st.st_mtime, cpathname))) {
 		co = read_compiled_module(cpathname, fpc);
 		fclose(fpc);
 		if (co == NULL)
@@ -1039,8 +1056,11 @@
 		if (Py_VerboseFlag)
 			PySys_WriteStderr("import %s # from %s\n",
 				name, pathname);
-		if (cpathname)
-			write_compiled_module(co, cpathname, mtime);
+		if (cpathname) {
+			PyObject *ro = PySys_GetObject("dont_write_bytecode");
+			if (ro == NULL || !PyObject_IsTrue(ro))
+				write_compiled_module(co, cpathname, &st);
+		}
 	}
 	m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, pathname);
 	Py_DECREF(co);
@@ -1048,12 +1068,44 @@
 	return m;
 }
 
+/* Get source file -> unicode or None
+ * Returns the path to the py file if available, else the given path
+ */
+static PyObject *
+get_sourcefile(const char *file)
+{
+	char py[MAXPATHLEN + 1];
+	Py_ssize_t len;
+	PyObject *u;
+	struct stat statbuf;
+
+	if (!file || !*file) {
+		Py_RETURN_NONE;
+	}
+
+	len = strlen(file);
+        /* match '*.py?' */
+	if (len > MAXPATHLEN || PyOS_strnicmp(&file[len-4], ".py", 3) != 0) {
+		return PyUnicode_DecodeFSDefault(file);
+	}
+
+	strncpy(py, file, len-1);
+	py[len-1] = '\0';
+	if (stat(py, &statbuf) == 0 &&
+		S_ISREG(statbuf.st_mode)) {
+		u = PyUnicode_DecodeFSDefault(py);
+	}
+	else {
+		u = PyUnicode_DecodeFSDefault(file);
+	}
+	return u;
+}
 
 /* Forward */
 static PyObject *load_module(char *, FILE *, char *, int, PyObject *);
 static struct filedescr *find_module(char *, char *, PyObject *,
 				     char *, size_t, FILE **, PyObject **);
-static struct _frozen *find_frozen(char *name);
+static struct _frozen * find_frozen(char *);
 
 /* Load a package and return its module object WITH INCREMENTED
    REFERENCE COUNT */
@@ -1076,7 +1128,7 @@
 		PySys_WriteStderr("import %s # directory %s\n",
 			name, pathname);
 	d = PyModule_GetDict(m);
-	file = PyUnicode_DecodeFSDefault(pathname);
+	file = get_sourcefile(pathname);
 	if (file == NULL)
 		goto error;
 	path = Py_BuildValue("[O]", file);
@@ -1176,7 +1228,7 @@
 	}
 	if (importer == NULL) {
 		importer = PyObject_CallFunctionObjArgs(
-			(PyObject *)&NullImporterType, p, NULL
+			(PyObject *)&PyNullImporter_Type, p, NULL
 		);
 		if (importer == NULL) {
 			if (PyErr_ExceptionMatches(PyExc_ImportError)) {
@@ -1194,6 +1246,20 @@
 	return importer;
 }
 
+PyAPI_FUNC(PyObject *)
+PyImport_GetImporter(PyObject *path) {
+        PyObject *importer=NULL, *path_importer_cache=NULL, *path_hooks=NULL;
+
+	if ((path_importer_cache = PySys_GetObject("path_importer_cache"))) {
+		if ((path_hooks = PySys_GetObject("path_hooks"))) {
+			importer = get_path_importer(path_importer_cache,
+			                             path_hooks, path);
+		}
+	}
+	Py_XINCREF(importer); /* get_path_importer returns a borrowed reference */
+	return importer;
+}
+
 /* Search the path (default sys.path) for a module.  Return the
    corresponding filedescr struct, and (via return arguments) the
    pathname and an open file.  Return NULL if the module is not found. */
@@ -1644,7 +1710,7 @@
 	FILEFINDBUF3 ffbuf;
 	APIRET rc;
 
-	if (getenv("PYTHONCASEOK") != NULL)
+	if (Py_GETENV("PYTHONCASEOK") != NULL)
 		return 1;
 
 	rc = DosFindFirst(buf,
@@ -1969,6 +2035,53 @@
 	return result;
 }
 
+/* Import a module without blocking
+ *
+ * At first it tries to fetch the module from sys.modules. If the module was
+ * never loaded before it loads it with PyImport_ImportModule() unless another
+ * thread holds the import lock. In the latter case the function raises an
+ * ImportError instead of blocking.
+ *
+ * Returns the module object with incremented ref count.
+ */
+PyObject *
+PyImport_ImportModuleNoBlock(const char *name)
+{
+	PyObject *result;
+	PyObject *modules;
+	long me;
+
+	/* Try to get the module from sys.modules[name] */
+	modules = PyImport_GetModuleDict();
+	if (modules == NULL)
+		return NULL;
+
+	result = PyDict_GetItemString(modules, name);
+	if (result != NULL) {
+		Py_INCREF(result);
+		return result;
+	}
+	else {
+		PyErr_Clear();
+	}
+
+	/* check the import lock
+	 * me might be -1 but I ignore the error here, the lock function
+	 * takes care of the problem */
+	me = PyThread_get_thread_ident();
+	if (import_lock_thread == -1 || import_lock_thread == me) {
+		/* no thread or me is holding the lock */
+		return PyImport_ImportModule(name);
+	}
+	else {
+		PyErr_Format(PyExc_ImportError,
+			     "Failed to import %.200s because the import lock"
+			     "is held by another thread.",
+			     name);
+		return NULL;
+	}
+}
+
 /* Forward declarations for helper routines */
 static PyObject *get_parent(PyObject *globals, char *buf,
 			    Py_ssize_t *p_buflen, int level);
@@ -1989,6 +2102,16 @@
 	Py_ssize_t buflen = 0;
 	PyObject *parent, *head, *next, *tail;
 
+	if (strchr(name, '/') != NULL
+#ifdef MS_WINDOWS
+	    || strchr(name, '\\') != NULL
+#endif
+		) {
+		PyErr_SetString(PyExc_ImportError,
+				"Import by filename is not supported.");
+		return NULL;
+	}
+
 	parent = get_parent(globals, buf, &buflen, level);
 	if (parent == NULL)
 		return NULL;
@@ -2038,26 +2161,6 @@
 	return tail;
 }
 
-/* For DLL compatibility */
-#undef PyImport_ImportModuleEx
-PyObject *
-PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals,
-			PyObject *fromlist)
-{
-	PyObject *result;
-	lock_import();
-	result = import_module_level(name, globals, locals, fromlist, -1);
-	if (unlock_import() < 0) {
-		Py_XDECREF(result);
-		PyErr_SetString(PyExc_RuntimeError,
-				"not holding the import lock");
-		return NULL;
-	}
-	return result;
-}
-#define PyImport_ImportModuleEx(n, g, l, f) \
-	PyImport_ImportModuleLevel(n, g, l, f, -1);
-
 PyObject *
 PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals,
 			 PyObject *fromlist, int level)
@@ -2090,7 +2193,8 @@
 {
 	static PyObject *namestr = NULL;
 	static PyObject *pathstr = NULL;
-	PyObject *modname, *modpath, *modules, *parent;
+	static PyObject *pkgstr = NULL;
+	PyObject *pkgname, *modname, *modpath, *modules, *parent;
 
 	if (globals == NULL || !PyDict_Check(globals) || !level)
 		return Py_None;
@@ -2105,44 +2209,103 @@
 		if (pathstr == NULL)
 			return NULL;
 	}
+	if (pkgstr == NULL) {
+		pkgstr = PyUnicode_InternFromString("__package__");
+		if (pkgstr == NULL)
+			return NULL;
+	}
 
 	*buf = '\0';
 	*p_buflen = 0;
-	modname = PyDict_GetItem(globals, namestr);
-	if (modname == NULL || !PyUnicode_Check(modname))
-		return Py_None;
+	pkgname = PyDict_GetItem(globals, pkgstr);
 
-	modpath = PyDict_GetItem(globals, pathstr);
-	if (modpath != NULL) {
-		Py_ssize_t len = PyUnicode_GET_SIZE(modname);
-		if (len > MAXPATHLEN) {
+	if ((pkgname != NULL) && (pkgname != Py_None)) {
+		/* __package__ is set, so use it */
+		Py_ssize_t len;
+		if (!PyUnicode_Check(pkgname)) {
 			PyErr_SetString(PyExc_ValueError,
-					"Module name too long");
+					"__package__ set to non-string");
 			return NULL;
 		}
-		strcpy(buf, PyUnicode_AsString(modname));
-	}
-	else {
-		char *start = PyUnicode_AsString(modname);
-		char *lastdot = strrchr(start, '.');
-		size_t len;
-		if (lastdot == NULL && level > 0) {
+		len = PyUnicode_GET_SIZE(pkgname);
+		if (len == 0) {
+			if (level > 0) {
+				PyErr_SetString(PyExc_ValueError,
+					"Attempted relative import in non-package");
+				return NULL;
+			}
+			return Py_None;
+		}
+		if (len > MAXPATHLEN) {
 			PyErr_SetString(PyExc_ValueError,
-				"Attempted relative import in non-package");
+					"Package name too long");
 			return NULL;
 		}
-		if (lastdot == NULL)
+		strcpy(buf, PyUnicode_AsString(pkgname));
+	} else {
+		/* __package__ not set, so figure it out and set it */
+		modname = PyDict_GetItem(globals, namestr);
+		if (modname == NULL || !PyUnicode_Check(modname))
 			return Py_None;
-		len = lastdot - start;
-		if (len >= MAXPATHLEN) {
-			PyErr_SetString(PyExc_ValueError,
-					"Module name too long");
-			return NULL;
+	
+		modpath = PyDict_GetItem(globals, pathstr);
+		if (modpath != NULL) {
+			/* __path__ is set, so modname is already the package name */
+			Py_ssize_t len = PyUnicode_GET_SIZE(modname);
+			int error;
+			if (len > MAXPATHLEN) {
+				PyErr_SetString(PyExc_ValueError,
+						"Module name too long");
+				return NULL;
+			}
+			strcpy(buf, PyUnicode_AsString(modname));
+			error = PyDict_SetItem(globals, pkgstr, modname);
+			if (error) {
+				PyErr_SetString(PyExc_ValueError,
+						"Could not set __package__");
+				return NULL;
+			}
+		} else {
+			/* Normal module, so work out the package name if any */
+			char *start = PyUnicode_AsString(modname);
+			char *lastdot = strrchr(start, '.');
+			size_t len;
+			int error;
+			if (lastdot == NULL && level > 0) {
+				PyErr_SetString(PyExc_ValueError,
+					"Attempted relative import in non-package");
+				return NULL;
+			}
+			if (lastdot == NULL) {
+				error = PyDict_SetItem(globals, pkgstr, Py_None);
+				if (error) {
+					PyErr_SetString(PyExc_ValueError,
+						"Could not set __package__");
+					return NULL;
+				}
+				return Py_None;
+			}
+			len = lastdot - start;
+			if (len >= MAXPATHLEN) {
+				PyErr_SetString(PyExc_ValueError,
+						"Module name too long");
+				return NULL;
+			}
+			strncpy(buf, start, len);
+			buf[len] = '\0';
+			pkgname = PyUnicode_FromString(buf);
+			if (pkgname == NULL) {
+				return NULL;
+			}
+			error = PyDict_SetItem(globals, pkgstr, pkgname);
+			Py_DECREF(pkgname);
+			if (error) {
+				PyErr_SetString(PyExc_ValueError,
+						"Could not set __package__");
+				return NULL;
+			}
 		}
-		strncpy(buf, start, len);
-		buf[len] = '\0';
 	}
-
 	while (--level > 0) {
 		char *dot = strrchr(buf, '.');
 		if (dot == NULL) {
@@ -2300,14 +2463,14 @@
 							      PyUnicode_GetSize(item),
 							      NULL);
 			} else {
-				item8 = PyUnicode_AsEncodedString(item, 
-				Py_FileSystemDefaultEncoding, NULL);
+				item8 = PyUnicode_AsEncodedString(item,
+					Py_FileSystemDefaultEncoding, NULL);
 			}
 			if (!item8) {
 				PyErr_SetString(PyExc_ValueError, "Cannot encode path item");
 				return 0;
 			}
-			subname = PyBytes_AsString(item8);
+			subname = PyString_AS_STRING(item8);
 			if (buflen + strlen(subname) >= MAXPATHLEN) {
 				PyErr_SetString(PyExc_ValueError,
 						"Module name too long");
@@ -2472,7 +2635,7 @@
 		subname = name;
 	else {
 		PyObject *parentname, *parent;
-		parentname = PyString_FromStringAndSize(name, (subname-name));
+		parentname = PyUnicode_FromStringAndSize(name, (subname-name));
 		if (parentname == NULL) {
 			imp_modules_reloading_clear();
 			return NULL;
@@ -2481,7 +2644,7 @@
 		if (parent == NULL) {
 			PyErr_Format(PyExc_ImportError,
 			    "reload(): parent %.200s not in sys.modules",
-			    PyString_AS_STRING(parentname));
+			     PyUnicode_AsString(parentname));
 			Py_DECREF(parentname);
 			imp_modules_reloading_clear();
 			return NULL;
@@ -2565,7 +2728,7 @@
 		/* No globals -- use standard builtins, and fake globals */
 		PyErr_Clear();
 
-		builtins = PyImport_ImportModuleLevel("__builtin__",
+		builtins = PyImport_ImportModuleLevel("builtins",
 						      NULL, NULL, NULL, 0);
 		if (builtins == NULL)
 			return NULL;
@@ -2585,9 +2748,10 @@
 	if (import == NULL)
 		goto err;
 
-	/* Call the __import__ function with the proper argument list */
-	r = PyObject_CallFunctionObjArgs(import, module_name, globals,
-					 globals, silly_list, NULL);
+	/* Call the __import__ function with the proper argument list
+	 * Always use absolute import here. */
+	r = PyObject_CallFunction(import, "OOOOi", module_name, globals,
+				  globals, silly_list, 0, NULL);
 
   err:
 	Py_XDECREF(globals);
@@ -2670,6 +2834,9 @@
 	struct filedescr *fdp;
 	char pathname[MAXPATHLEN+1];
 	FILE *fp = NULL;
+	int fd = -1;
+	char *found_encoding = NULL;
+	char *encoding = NULL;
 
 	pathname[0] = '\0';
 	if (path == Py_None)
@@ -2678,9 +2845,26 @@
 	if (fdp == NULL)
 		return NULL;
 	if (fp != NULL) {
-		fob = PyFile_FromFile(fp, pathname, fdp->mode, fclose);
+		fd = fileno(fp);
+		if (fd != -1)
+			fd = dup(fd);
+		fclose(fp);
+		fp = NULL;
+	}
+	if (fd != -1) {
+		if (strchr(fdp->mode, 'b') == NULL) {
+			/* PyTokenizer_FindEncoding() returns PyMem_MALLOC'ed
+			   memory. */
+			found_encoding = PyTokenizer_FindEncoding(fd);
+			lseek(fd, 0, 0); /* Reset position */
+			encoding = (found_encoding != NULL) ? found_encoding :
+				   (char*)PyUnicode_GetDefaultEncoding();
+		}
+		fob = PyFile_FromFd(fd, pathname, fdp->mode, -1,
+				    (char*)encoding, NULL, NULL, 1);
 		if (fob == NULL) {
-			fclose(fp);
+			close(fd);
+			PyMem_FREE(found_encoding);
 			return NULL;
 		}
 	}
@@ -2691,6 +2875,8 @@
 	ret = Py_BuildValue("Os(ssi)",
 		      fob, pathname, fdp->suffix, fdp->mode, fdp->type);
 	Py_DECREF(fob);
+	PyMem_FREE(found_encoding);
+
 	return ret;
 }
 
@@ -2760,7 +2946,7 @@
 	char *name;
 	if (!PyArg_ParseTuple(args, "s:is_builtin", &name))
 		return NULL;
-	return PyInt_FromLong(is_builtin(name));
+	return PyLong_FromLong(is_builtin(name));
 }
 
 static PyObject *
@@ -2915,6 +3101,17 @@
 	return PyModule_New(name);
 }
 
+static PyObject *
+imp_reload(PyObject *self, PyObject *v)
+{
+        return PyImport_ReloadModule(v);
+}
+
+PyDoc_STRVAR(doc_reload,
+"reload(module) -> module\n\
+\n\
+Reload the module.  The module must have been successfully imported before.");
+
 /* Doc strings */
 
 PyDoc_STRVAR(doc_imp,
@@ -2974,6 +3171,7 @@
 	{"lock_held",	 imp_lock_held,	   METH_NOARGS,  doc_lock_held},
 	{"acquire_lock", imp_acquire_lock, METH_NOARGS,  doc_acquire_lock},
 	{"release_lock", imp_release_lock, METH_NOARGS,  doc_release_lock},
+	{"reload",       imp_reload,       METH_O,       doc_reload},
 	/* The rest are obsolete */
 	{"get_frozen_object",	imp_get_frozen_object,	METH_VARARGS},
 	{"init_builtin",	imp_init_builtin,	METH_VARARGS},
@@ -2995,7 +3193,7 @@
 	PyObject *v;
 	int err;
 
-	v = PyInt_FromLong((long)value);
+	v = PyLong_FromLong((long)value);
 	err = PyDict_SetItemString(d, name, v);
 	Py_XDECREF(v);
 	return err;
@@ -3009,6 +3207,7 @@
 NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
 {
 	char *path;
+	Py_ssize_t pathlen;
 
 	if (!_PyArg_NoKeywords("NullImporter()", kwds))
 		return -1;
@@ -3017,7 +3216,8 @@
 			      &path))
 		return -1;
 
-	if (strlen(path) == 0) {
+	pathlen = strlen(path);
+	if (pathlen == 0) {
 		PyErr_SetString(PyExc_ImportError, "empty pathname");
 		return -1;
 	} else {
@@ -3025,6 +3225,20 @@
 		int rv;
 
 		rv = stat(path, &statbuf);
+#ifdef MS_WINDOWS
+		/* MS Windows stat() chokes on paths like C:\path\. Try to
+		 * recover *one* time by stripping off a trailing slash or
+		 * backslash. http://bugs.python.org/issue1293
+		 */
+		if (rv != 0 && pathlen <= MAXPATHLEN &&
+		    (path[pathlen-1] == '/' || path[pathlen-1] == '\\')) {
+			char mangled[MAXPATHLEN+1];
+
+			strcpy(mangled, path);
+			mangled[pathlen-1] = '\0';
+			rv = stat(mangled, &statbuf);
+		}
+#endif
 		if (rv == 0) {
 			/* it exists */
 			if (S_ISDIR(statbuf.st_mode)) {
@@ -3052,7 +3266,7 @@
 };
 
 
-static PyTypeObject NullImporterType = {
+PyTypeObject PyNullImporter_Type = {
 	PyVarObject_HEAD_INIT(NULL, 0)
 	"imp.NullImporter",        /*tp_name*/
 	sizeof(NullImporter),      /*tp_basicsize*/
@@ -3099,7 +3313,7 @@
 {
 	PyObject *m, *d;
 
-	if (PyType_Ready(&NullImporterType) < 0)
+	if (PyType_Ready(&PyNullImporter_Type) < 0)
 		goto failure;
 
 	m = Py_InitModule4("imp", imp_methods, doc_imp,
@@ -3121,8 +3335,8 @@
 	if (setint(d, "PY_CODERESOURCE", PY_CODERESOURCE) < 0) goto failure;
 	if (setint(d, "IMP_HOOK", IMP_HOOK) < 0) goto failure;
 
-	Py_INCREF(&NullImporterType);
-	PyModule_AddObject(m, "NullImporter", (PyObject *)&NullImporterType);
+	Py_INCREF(&PyNullImporter_Type);
+	PyModule_AddObject(m, "NullImporter", (PyObject *)&PyNullImporter_Type);
   failure:
 	;
 }

Modified: python/branches/py3k-importlib/Python/mactoolboxglue.c
==============================================================================
--- python/branches/py3k-importlib/Python/mactoolboxglue.c	(original)
+++ python/branches/py3k-importlib/Python/mactoolboxglue.c	Thu Mar 27 00:48:05 2008
@@ -36,7 +36,7 @@
 	PyObject *m;
 	PyObject *rv;
 
-	m = PyImport_ImportModule("MacOS");
+	m = PyImport_ImportModuleNoBlock("MacOS");
 	if (!m) {
 		if (Py_VerboseFlag)
 			PyErr_Print();
@@ -194,7 +194,7 @@
 PyMac_BuildOSType(OSType t)
 {
 	uint32_t tmp = htonl((uint32_t)t);
-	return PyBytes_FromStringAndSize((char *)&tmp, 4);
+	return PyString_FromStringAndSize((char *)&tmp, 4);
 }
 
 /* Convert an NumVersion value to a 4-element tuple */
@@ -348,9 +348,9 @@
 int
 PyMac_Getwide(PyObject *v, wide *rv)
 {
-	if (PyInt_Check(v)) {
+	if (PyLong_Check(v)) {
 		rv->hi = 0;
-		rv->lo = PyInt_AsLong(v);
+		rv->lo = PyLong_AsLong(v);
 		if( rv->lo & 0x80000000 )
 			rv->hi = -1;
 		return 1;
@@ -364,7 +364,7 @@
 {
 	if ( (w->hi == 0 && (w->lo & 0x80000000) == 0) ||
 	     (w->hi == -1 && (w->lo & 0x80000000) ) )
-		return PyInt_FromLong(w->lo);
+		return PyLong_FromLong(w->lo);
 	return Py_BuildValue("(ll)", w->hi, w->lo);
 }
 

Modified: python/branches/py3k-importlib/Python/marshal.c
==============================================================================
--- python/branches/py3k-importlib/Python/marshal.c	(original)
+++ python/branches/py3k-importlib/Python/marshal.c	Thu Mar 27 00:48:05 2008
@@ -36,8 +36,6 @@
 #define TYPE_BINARY_COMPLEX	'y'
 #define TYPE_LONG		'l'
 #define TYPE_STRING		's'
-#define TYPE_INTERNED		't'
-#define TYPE_STRINGREF		'R'
 #define TYPE_TUPLE		'('
 #define TYPE_LIST		'['
 #define TYPE_DICT		'{'
@@ -149,13 +147,13 @@
 	else if (v == Py_True) {
 	        w_byte(TYPE_TRUE, p);
 	}
-	else if (PyLong_Check(v)) {
+	else if (PyLong_CheckExact(v)) {
 		long x = PyLong_AsLong(v);
 		if ((x == -1)  && PyErr_Occurred()) {
 			PyLongObject *ob = (PyLongObject *)v;
 			PyErr_Clear();
 			w_byte(TYPE_LONG, p);
-			n = Py_Size(ob);
+			n = Py_SIZE(ob);
 			w_long((long)n, p);
 			if (n < 0)
 				n = -n;
@@ -177,7 +175,7 @@
 			}
 		}
 	}
-	else if (PyFloat_Check(v)) {
+	else if (PyFloat_CheckExact(v)) {
 		if (p->version > 1) {
 			unsigned char buf[8];
 			if (_PyFloat_Pack8(PyFloat_AsDouble(v), 
@@ -198,7 +196,7 @@
 		}
 	}
 #ifndef WITHOUT_COMPLEX
-	else if (PyComplex_Check(v)) {
+	else if (PyComplex_CheckExact(v)) {
 		if (p->version > 1) {
 			unsigned char buf[8];
 			if (_PyFloat_Pack8(PyComplex_RealAsDouble(v),
@@ -230,32 +228,8 @@
 		}
 	}
 #endif
-	else if (PyString_Check(v)) {
-		if (p->strings && PyString_CHECK_INTERNED(v)) {
-			PyObject *o = PyDict_GetItem(p->strings, v);
-			if (o) {
-				long w = PyInt_AsLong(o);
-				w_byte(TYPE_STRINGREF, p);
-				w_long(w, p);
-				goto exit;
-			}
-			else {
-				int ok;
-				o = PyInt_FromSsize_t(PyDict_Size(p->strings));
-				ok = o &&
-				     PyDict_SetItem(p->strings, v, o) >= 0;
-				Py_XDECREF(o);
-				if (!ok) {
-					p->depth--;
-					p->error = 1;
-					return;
-				}
-				w_byte(TYPE_INTERNED, p);
-			}
-		}
-		else {
-			w_byte(TYPE_STRING, p);
-		}
+	else if (PyString_CheckExact(v)) {
+		w_byte(TYPE_STRING, p);
 		n = PyString_GET_SIZE(v);
 		if (n > INT_MAX) {
 			/* huge strings are not supported */
@@ -266,7 +240,7 @@
 		w_long((long)n, p);
 		w_string(PyString_AS_STRING(v), (int)n, p);
 	}
-	else if (PyUnicode_Check(v)) {
+	else if (PyUnicode_CheckExact(v)) {
 	        PyObject *utf8;
 		utf8 = PyUnicode_AsUTF8String(v);
 		if (utf8 == NULL) {
@@ -275,17 +249,17 @@
 			return;
 		}
 		w_byte(TYPE_UNICODE, p);
-		n = PyBytes_GET_SIZE(utf8);
+		n = PyString_GET_SIZE(utf8);
 		if (n > INT_MAX) {
 			p->depth--;
 			p->error = 1;
 			return;
 		}
 		w_long((long)n, p);
-		w_string(PyBytes_AS_STRING(utf8), (int)n, p);
+		w_string(PyString_AS_STRING(utf8), (int)n, p);
 		Py_DECREF(utf8);
 	}
-	else if (PyTuple_Check(v)) {
+	else if (PyTuple_CheckExact(v)) {
 		w_byte(TYPE_TUPLE, p);
 		n = PyTuple_Size(v);
 		w_long((long)n, p);
@@ -293,7 +267,7 @@
 			w_object(PyTuple_GET_ITEM(v, i), p);
 		}
 	}
-	else if (PyList_Check(v)) {
+	else if (PyList_CheckExact(v)) {
 		w_byte(TYPE_LIST, p);
 		n = PyList_GET_SIZE(v);
 		w_long((long)n, p);
@@ -301,7 +275,7 @@
 			w_object(PyList_GET_ITEM(v, i), p);
 		}
 	}
-	else if (PyDict_Check(v)) {
+	else if (PyDict_CheckExact(v)) {
 		Py_ssize_t pos;
 		PyObject *key, *value;
 		w_byte(TYPE_DICT, p);
@@ -313,7 +287,7 @@
 		}
 		w_object((PyObject *)NULL, p);
 	}
-	else if (PyAnySet_Check(v)) {
+	else if (PyAnySet_CheckExact(v)) {
 		PyObject *value, *it;
 
 		if (PyObject_TypeCheck(v, &PySet_Type))
@@ -389,7 +363,6 @@
 		w_byte(TYPE_UNKNOWN, p);
 		p->error = 1;
 	}
-   exit:
 	p->depth--;
 }
 
@@ -487,7 +460,7 @@
 	long hi4 = r_long(p);
 #if SIZEOF_LONG > 4
 	long x = (hi4 << 32) | (lo4 & 0xFFFFFFFFL);
-	return PyInt_FromLong(x);
+	return PyLong_FromLong(x);
 #else
 	unsigned char buf[8];
 	int one = 1;
@@ -509,7 +482,7 @@
 {
 	/* NULL is a valid return value, it does not necessarily means that
 	   an exception is set. */
-	PyObject *v, *v2, *v3;
+	PyObject *v, *v2;
 	long i, n;
 	int type = r_byte(p);
 	PyObject *retval;
@@ -560,7 +533,7 @@
 		break;
 
 	case TYPE_INT:
-		retval = PyInt_FromLong(r_long(p));
+		retval = PyLong_FromLong(r_long(p));
 		break;
 
 	case TYPE_INT64:
@@ -584,7 +557,7 @@
 				retval = NULL;
 				break;
 			}
-			Py_Size(ob) = n;
+			Py_SIZE(ob) = n;
 			for (i = 0; i < size; i++) {
 				int digit = r_short(p);
 				if (digit < 0) {
@@ -703,7 +676,6 @@
 		}
 #endif
 
-	case TYPE_INTERNED:
 	case TYPE_STRING:
 		n = r_long(p);
 		if (n < 0 || n > INT_MAX) {
@@ -723,25 +695,6 @@
 			retval = NULL;
 			break;
 		}
-		if (type == TYPE_INTERNED) {
-			PyString_InternInPlace(&v);
-			if (PyList_Append(p->strings, v) < 0) {
-				retval = NULL;
-				break;
-			}
-		}
-		retval = v;
-		break;
-
-	case TYPE_STRINGREF:
-		n = r_long(p);
-		if (n < 0 || n >= PyList_GET_SIZE(p->strings)) {
-			PyErr_SetString(PyExc_ValueError, "bad marshal data");
-			retval = NULL;
-			break;
-		}
-		v = PyList_GET_ITEM(p->strings, n);
-		Py_INCREF(v);
 		retval = v;
 		break;
 
@@ -859,7 +812,7 @@
 			retval = NULL;
 			break;
 		}
-		v = PyTuple_New((int)n);
+                v = (type == TYPE_SET) ? PySet_New(NULL) : PyFrozenSet_New(NULL);
 		if (v == NULL) {
 			retval = NULL;
 			break;
@@ -874,18 +827,15 @@
 				v = NULL;
 				break;
 			}
-			PyTuple_SET_ITEM(v, (int)i, v2);
+			if (PySet_Add(v, v2) == -1) {
+                                Py_DECREF(v);
+                                Py_DECREF(v2);
+                                v = NULL;
+                                break;
+                        }
+                        Py_DECREF(v2);
 		}
-		if (v == NULL) {
-			retval = NULL;
-			break;
-		}
-		if (type == TYPE_SET)
-			v3 = PySet_New(v);
-		else
-			v3 = PyFrozenSet_New(v);
-		Py_DECREF(v);
-		retval = v3;
+		retval = v;
 		break;
 
 	case TYPE_CODE:
@@ -1009,6 +959,7 @@
 	RFILE rf;
 	rf.fp = fp;
 	rf.strings = NULL;
+	rf.ptr = rf.end = NULL;
 	return r_long(&rf);
 }
 
@@ -1082,6 +1033,7 @@
 	rf.fp = fp;
 	rf.strings = PyList_New(0);
 	rf.depth = 0;
+	rf.ptr = rf.end = NULL;
 	result = r_object(&rf);
 	Py_DECREF(rf.strings);
 	return result;
@@ -1258,7 +1210,7 @@
 
 	long_result = r_long(&rf);
 
-	obj_result = PyInt_FromLong(long_result);
+	obj_result = PyLong_FromLong(long_result);
 
   exit:
 	Py_DECREF(bytes);
@@ -1273,7 +1225,7 @@
 	long value;
 
 	/* Get the long value of the argument. */
-	value = PyInt_AsLong(obj);
+	value = PyLong_AsLong(obj);
 	if ((value == -1) && PyErr_Occurred())
 		return NULL;
 

Deleted: /python/branches/py3k-importlib/Python/memmove.c
==============================================================================
--- /python/branches/py3k-importlib/Python/memmove.c	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,25 +0,0 @@
-
-/* A perhaps slow but I hope correct implementation of memmove */
-
-extern char *memcpy(char *, char *, int);
-
-char *
-memmove(char *dst, char *src, int n)
-{
-	char *realdst = dst;
-	if (n <= 0)
-		return dst;
-	if (src >= dst+n || dst >= src+n)
-		return memcpy(dst, src, n);
-	if (src > dst) {
-		while (--n >= 0)
-			*dst++ = *src++;
-	}
-	else if (src < dst) {
-		src += n;
-		dst += n;
-		while (--n >= 0)
-			*--dst = *--src;
-	}
-	return realdst;
-}

Modified: python/branches/py3k-importlib/Python/modsupport.c
==============================================================================
--- python/branches/py3k-importlib/Python/modsupport.c	(original)
+++ python/branches/py3k-importlib/Python/modsupport.c	Thu Mar 27 00:48:05 2008
@@ -307,37 +307,31 @@
 		case 'B':
 		case 'h':
 		case 'i':
-			return PyInt_FromLong((long)va_arg(*p_va, int));
+			return PyLong_FromLong((long)va_arg(*p_va, int));
 			
 		case 'H':
-			return PyInt_FromLong((long)va_arg(*p_va, unsigned int));
+			return PyLong_FromLong((long)va_arg(*p_va, unsigned int));
 
 		case 'I':
 		{
 			unsigned int n;
 			n = va_arg(*p_va, unsigned int);
-			if (n > (unsigned long)PyInt_GetMax())
-				return PyLong_FromUnsignedLong((unsigned long)n);
-			else
-				return PyInt_FromLong(n);
+			return PyLong_FromUnsignedLong(n);
 		}
 		
 		case 'n':
 #if SIZEOF_SIZE_T!=SIZEOF_LONG
-			return PyInt_FromSsize_t(va_arg(*p_va, Py_ssize_t));
+			return PyLong_FromSsize_t(va_arg(*p_va, Py_ssize_t));
 #endif
 			/* Fall through from 'n' to 'l' if Py_ssize_t is long */
 		case 'l':
-			return PyInt_FromLong(va_arg(*p_va, long));
+			return PyLong_FromLong(va_arg(*p_va, long));
 
 		case 'k':
 		{
 			unsigned long n;
 			n = va_arg(*p_va, unsigned long);
-			if (n > (unsigned long)PyInt_GetMax())
-				return PyLong_FromUnsignedLong(n);
-			else
-				return PyInt_FromLong(n);
+			return PyLong_FromUnsignedLong(n);
 		}
 
 #ifdef HAVE_LONG_LONG
@@ -504,7 +498,7 @@
 					}
 					n = (Py_ssize_t)m;
 				}
-				v = PyBytes_FromStringAndSize(str, n);
+				v = PyString_FromStringAndSize(str, n);
 			}
 			return v;
 		}
@@ -702,11 +696,23 @@
 int 
 PyModule_AddIntConstant(PyObject *m, const char *name, long value)
 {
-	return PyModule_AddObject(m, name, PyInt_FromLong(value));
+	PyObject *o = PyLong_FromLong(value);
+	if (!o)
+		return -1;
+	if (PyModule_AddObject(m, name, o) == 0)
+		return 0;
+	Py_DECREF(o);
+	return -1;
 }
 
 int 
 PyModule_AddStringConstant(PyObject *m, const char *name, const char *value)
 {
-	return PyModule_AddObject(m, name, PyUnicode_FromString(value));
+	PyObject *o = PyUnicode_FromString(value);
+	if (!o)
+		return -1;
+	if (PyModule_AddObject(m, name, o) == 0)
+		return 0;
+	Py_DECREF(o);
+	return -1;
 }

Modified: python/branches/py3k-importlib/Python/mystrtoul.c
==============================================================================
--- python/branches/py3k-importlib/Python/mystrtoul.c	(original)
+++ python/branches/py3k-importlib/Python/mystrtoul.c	Thu Mar 27 00:48:05 2008
@@ -5,14 +5,6 @@
 #define _SGI_MP_SOURCE
 #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
-#define Py_CHARMASK(c)		((c) & 0xff)
-#endif
-
 /* strtol and strtoul, renamed to avoid conflicts */
 
 
@@ -116,12 +108,30 @@
 		if (*str == '0') {
 			++str;
 			if (*str == 'x' || *str == 'X') {
+				/* there must be at least one digit after 0x */
+				if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {
+					if (ptr)
+						*ptr = str;
+					return 0;
+				}
 				++str;
 				base = 16;
 			} else if (*str == 'o' || *str == 'O') {
+				/* there must be at least one digit after 0o */
+				if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 8) {
+					if (ptr)
+						*ptr = str;
+					return 0;
+				}
 				++str;
 				base = 8;
 			} else if (*str == 'b' || *str == 'B') {
+				/* there must be at least one digit after 0b */
+				if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 2) {
+					if (ptr)
+						*ptr = str;
+					return 0;
+				}
 				++str;
 				base = 2;
 			} else {
@@ -143,22 +153,43 @@
 	case 16:
 		if (*str == '0') {
 			++str;
-			if (*str == 'x' || *str == 'X')
+			if (*str == 'x' || *str == 'X') {
+				/* there must be at least one digit after 0x */
+				if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {
+					if (ptr)
+						*ptr = str;
+					return 0;
+				}
 				++str;
+			}
 		}
 		break;
 	case 8:
 		if (*str == '0') {
 			++str;
-			if (*str == 'o' || *str == 'O')
+			if (*str == 'o' || *str == 'O') {
+				/* there must be at least one digit after 0o */
+				if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 8) {
+					if (ptr)
+						*ptr = str;
+					return 0;
+				}
 				++str;
+			}
 		}
 		break;
 	case 2:
 		if(*str == '0') {
 			++str;
-			if (*str == 'b' || *str == 'B')
+			if (*str == 'b' || *str == 'B') {
+				/* there must be at least one digit after 0b */
+				if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 2) {
+					if (ptr)
+						*ptr = str;
+					return 0;
+				}
 				++str;
+			}
 		}
 		break;
 	}

Modified: python/branches/py3k-importlib/Python/peephole.c
==============================================================================
--- python/branches/py3k-importlib/Python/peephole.c	(original)
+++ python/branches/py3k-importlib/Python/peephole.c	Thu Mar 27 00:48:05 2008
@@ -342,7 +342,7 @@
 	if (codestr == NULL)
 		goto exitUnchanged;
 	codestr = (unsigned char *)memcpy(codestr, 
-                                        PyString_AS_STRING(code), codelen);
+					  PyString_AS_STRING(code), codelen);
 
 	/* Verify that RETURN_VALUE terminates the codestring.	This allows
 	   the various transformation patterns to look ahead several
@@ -407,7 +407,7 @@
 			case LOAD_NAME:
 			case LOAD_GLOBAL:
 				j = GETARG(codestr, i);
-				name = PyString_AsString(PyTuple_GET_ITEM(names, j));
+				name = PyUnicode_AsString(PyTuple_GET_ITEM(names, j));
 				h = load_global(codestr, i, name, consts);
 				if (h < 0)
 					goto exitUnchanged;

Modified: python/branches/py3k-importlib/Python/pystate.c
==============================================================================
--- python/branches/py3k-importlib/Python/pystate.c	(original)
+++ python/branches/py3k-importlib/Python/pystate.c	Thu Mar 27 00:48:05 2008
@@ -242,6 +242,7 @@
 {
 	PyInterpreterState *interp;
 	PyThreadState **p;
+	PyThreadState *prev_p = NULL;
 	if (tstate == NULL)
 		Py_FatalError("PyThreadState_Delete: NULL tstate");
 	interp = tstate->interp;
@@ -254,6 +255,15 @@
 				"PyThreadState_Delete: invalid tstate");
 		if (*p == tstate)
 			break;
+		if (*p == prev_p)
+			Py_FatalError(
+				"PyThreadState_Delete: small circular list(!)"
+                                " and tstate not found.");
+		prev_p = *p;
+		if ((*p)->next == interp->tstate_head)
+			Py_FatalError(
+				"PyThreadState_Delete: circular list(!) and"
+                                " tstate not found.");
 	}
 	*p = tstate->next;
 	HEAD_UNLOCK();
@@ -445,7 +455,7 @@
 			struct _frame *frame = t->frame;
 			if (frame == NULL)
 				continue;
-			id = PyInt_FromLong(t->thread_id);
+			id = PyLong_FromLong(t->thread_id);
 			if (id == NULL)
 				goto Fail;
 			stat = PyDict_SetItem(result, id, (PyObject *)frame);

Modified: python/branches/py3k-importlib/Python/pystrtod.c
==============================================================================
--- python/branches/py3k-importlib/Python/pystrtod.c	(original)
+++ python/branches/py3k-importlib/Python/pystrtod.c	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,6 @@
 #define ISSPACE(c)  ((c) == ' ' || (c) == '\f' || (c) == '\n' || \
                      (c) == '\r' || (c) == '\t' || (c) == '\v')
 #define ISDIGIT(c)  ((c) >= '0' && (c) <= '9')
-#define ISXDIGIT(c) (ISDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
 
 
 /**
@@ -48,6 +47,8 @@
 	size_t decimal_point_len;
 	const char *p, *decimal_point_pos;
 	const char *end = NULL; /* Silence gcc */
+	const char *digits_pos = NULL;
+	int negate = 0;
 
 	assert(nptr != NULL);
 
@@ -60,18 +61,41 @@
 	assert(decimal_point_len != 0);
 
 	decimal_point_pos = NULL;
+
+	/* We process any leading whitespace and the optional sign manually,
+	   then pass the remainder to the system strtod.  This ensures that
+	   the result of an underflow has the correct sign. (bug #1725)  */
+
+	p = nptr;
+	/* Skip leading space */
+	while (ISSPACE(*p))
+		p++;
+
+	/* Process leading sign, if present */
+	if (*p == '-') {
+		negate = 1;
+		p++;
+	} else if (*p == '+') {
+		p++;
+	}
+
+	/* What's left should begin with a digit, a decimal point, or one of
+	   the letters i, I, n, N. It should not begin with 0x or 0X */
+	if ((!ISDIGIT(*p) &&
+	     *p != '.' && *p != 'i' && *p != 'I' && *p != 'n' && *p != 'N')
+	    ||
+	    (*p == '0' && (p[1] == 'x' || p[1] == 'X')))
+	{
+		if (endptr)
+			*endptr = (char*)nptr;
+		errno = EINVAL;
+		return val;
+	}
+	digits_pos = p;
+
 	if (decimal_point[0] != '.' || 
 	    decimal_point[1] != 0)
 	{
-		p = nptr;
-		  /* Skip leading space */
-		while (ISSPACE(*p))
-			p++;
-
-		  /* Skip leading optional sign */
-		if (*p == '+' || *p == '-')
-			p++;
-
 		while (ISDIGIT(*p))
 			p++;
 
@@ -93,11 +117,13 @@
 		else if (strncmp(p, decimal_point, decimal_point_len) == 0)
 		{
 			/* Python bug #1417699 */
-			*endptr = (char*)nptr;
+			if (endptr)
+				*endptr = (char*)nptr;
 			errno = EINVAL;
 			return val;
 		}
-		/* For the other cases, we need not convert the decimal point */
+		/* For the other cases, we need not convert the decimal
+		   point */
 	}
 
 	/* Set errno to zero, so that we can distinguish zero results
@@ -108,8 +134,10 @@
 	{
 		char *copy, *c;
 
-		/* We need to convert the '.' to the locale specific decimal point */
-		copy = (char *)PyMem_MALLOC(end - nptr + 1 + decimal_point_len);
+		/* We need to convert the '.' to the locale specific decimal
+		   point */
+		copy = (char *)PyMem_MALLOC(end - digits_pos +
+					    1 + decimal_point_len);
 		if (copy == NULL) {
 			if (endptr)
 				*endptr = (char *)nptr;
@@ -118,11 +146,12 @@
 		}
 
 		c = copy;
-		memcpy(c, nptr, decimal_point_pos - nptr);
-		c += decimal_point_pos - nptr;
+		memcpy(c, digits_pos, decimal_point_pos - digits_pos);
+		c += decimal_point_pos - digits_pos;
 		memcpy(c, decimal_point, decimal_point_len);
 		c += decimal_point_len;
-		memcpy(c, decimal_point_pos + 1, end - (decimal_point_pos + 1));
+		memcpy(c, decimal_point_pos + 1,
+		       end - (decimal_point_pos + 1));
 		c += end - (decimal_point_pos + 1);
 		*c = 0;
 
@@ -131,24 +160,27 @@
 		if (fail_pos)
 		{
 			if (fail_pos > decimal_point_pos)
-				fail_pos = (char *)nptr + (fail_pos - copy) - (decimal_point_len - 1);
+				fail_pos = (char *)digits_pos +
+					(fail_pos - copy) -
+					(decimal_point_len - 1);
 			else
-				fail_pos = (char *)nptr + (fail_pos - copy);
+				fail_pos = (char *)digits_pos +
+					(fail_pos - copy);
 		}
 
 		PyMem_FREE(copy);
 
 	}
 	else {
-		unsigned i = 0;
-		if (nptr[i] == '-')
-			i++;
-		if (nptr[i] == '0' && (nptr[i+1] == 'x' || nptr[i+1] == 'X'))
-			fail_pos = (char*)nptr;
-		else
-			val = strtod(nptr, &fail_pos);
+		val = strtod(digits_pos, &fail_pos);
 	}
 
+	if (fail_pos == digits_pos)
+		fail_pos = (char *)nptr;
+
+	if (negate && fail_pos != nptr)
+		val = -val;
+
 	if (endptr)
 		*endptr = fail_pos;
 
@@ -156,10 +188,19 @@
 }
 
 
+/* From the C99 standard, section 7.19.6:
+The exponent always contains at least two digits, and only as many more digits
+as necessary to represent the exponent.
+*/
+#define MIN_EXPONENT_DIGITS 2
+
+/* see FORMATBUFLEN in unicodeobject.c */
+#define FLOAT_FORMATBUFLEN 120
+
 /**
  * PyOS_ascii_formatd:
  * @buffer: A buffer to place the resulting string in
- * @buf_len: The length of the buffer.
+ * @buf_size: The length of the buffer.
  * @format: The printf()-style format to use for the
  *          code to use for converting. 
  * @d: The #gdouble to convert
@@ -167,73 +208,210 @@
  * Converts a #gdouble to a string, using the '.' as
  * decimal point. To format the number you pass in
  * a printf()-style format string. Allowed conversion
- * specifiers are 'e', 'E', 'f', 'F', 'g' and 'G'. 
+ * specifiers are 'e', 'E', 'f', 'F', 'g', 'G', and 'n'.
  * 
+ * 'n' is the same as 'g', except it uses the current locale.
+ * 'Z' is the same as 'g', except it always has a decimal and
+ *     at least one digit after the decimal.
+ *
  * Return value: The pointer to the buffer with the converted string.
  **/
 char *
 PyOS_ascii_formatd(char       *buffer, 
-		   size_t      buf_len, 
+		   size_t      buf_size, 
 		   const char *format, 
 		   double      d)
 {
-	struct lconv *locale_data;
-	const char *decimal_point;
-	size_t decimal_point_len, rest_len;
 	char *p;
 	char format_char;
+	size_t format_len = strlen(format);
 
-/* 	g_return_val_if_fail (buffer != NULL, NULL); */
-/* 	g_return_val_if_fail (format[0] == '%', NULL); */
-/* 	g_return_val_if_fail (strpbrk (format + 1, "'l%") == NULL, NULL); */
-
-	format_char = format[strlen(format) - 1];
-
-/* 	g_return_val_if_fail (format_char == 'e' || format_char == 'E' || */
-/* 			      format_char == 'f' || format_char == 'F' || */
-/* 			      format_char == 'g' || format_char == 'G', */
-/* 			      NULL); */
+	/* For type 'n', we need to make a copy of the format string, because
+	   we're going to modify 'n' -> 'g', and format is const char*, so we
+	   can't modify it directly.  FLOAT_FORMATBUFLEN should be longer than
+	   we ever need this to be.  There's an upcoming check to ensure it's
+	   big enough. */
+	/* Issue 2264: code 'Z' requires copying the format.  'Z' is 'g', but
+	   also with at least one character past the decimal. */
+	char tmp_format[FLOAT_FORMATBUFLEN];
+
+	/* The last character in the format string must be the format char */
+	format_char = format[format_len - 1];
 
 	if (format[0] != '%')
 		return NULL;
 
+	/* I'm not sure why this test is here.  It's ensuring that the format
+	   string after the first character doesn't have a single quote, a
+	   lowercase l, or a percent. This is the reverse of the commented-out
+	   test about 10 lines ago. */
 	if (strpbrk(format + 1, "'l%"))
 		return NULL;
 
+	/* Also curious about this function is that it accepts format strings
+	   like "%xg", which are invalid for floats.  In general, the
+	   interface to this function is not very good, but changing it is
+	   difficult because it's a public API. */
+
 	if (!(format_char == 'e' || format_char == 'E' || 
 	      format_char == 'f' || format_char == 'F' || 
-	      format_char == 'g' || format_char == 'G'))
+	      format_char == 'g' || format_char == 'G' ||
+	      format_char == 'n' || format_char == 'Z'))
 		return NULL;
 
+	/* Map 'n' or 'Z' format_char to 'g', by copying the format string and
+	   replacing the final char with a 'g' */
+	if (format_char == 'n' || format_char == 'Z') {
+		if (format_len + 1 >= sizeof(tmp_format)) {
+			/* The format won't fit in our copy.  Error out.  In
+			   practice, this will never happen and will be
+			   detected by returning NULL */
+			return NULL;
+		}
+		strcpy(tmp_format, format);
+		tmp_format[format_len - 1] = 'g';
+		format = tmp_format;
+	}
 
-	PyOS_snprintf(buffer, buf_len, format, d);
 
-	locale_data = localeconv();
-	decimal_point = locale_data->decimal_point;
-	decimal_point_len = strlen(decimal_point);
+	/* Have PyOS_snprintf do the hard work */
+	PyOS_snprintf(buffer, buf_size, format, d);
 
-	assert(decimal_point_len != 0);
+	/* Get the current local, and find the decimal point character (or
+	   string?).  Convert that string back to a dot.  Do not do this if
+	   using the 'n' (number) format code. */
+	if (format_char != 'n') {
+		struct lconv *locale_data = localeconv();
+		const char *decimal_point = locale_data->decimal_point;
+		size_t decimal_point_len = strlen(decimal_point);
+		size_t rest_len;
 
-	if (decimal_point[0] != '.' || 
-	    decimal_point[1] != 0)
-	{
-		p = buffer;
+		assert(decimal_point_len != 0);
 
-		if (*p == '+' || *p == '-')
-			p++;
+		if (decimal_point[0] != '.' || decimal_point[1] != 0) {
+			p = buffer;
 
-		while (isdigit((unsigned char)*p))
-			p++;
+			if (*p == '+' || *p == '-')
+				p++;
 
-		if (strncmp(p, decimal_point, decimal_point_len) == 0)
-		{
-			*p = '.';
-			p++;
-			if (decimal_point_len > 1) {
-				rest_len = strlen(p + (decimal_point_len - 1));
-				memmove(p, p + (decimal_point_len - 1), 
-					rest_len);
-				p[rest_len] = 0;
+			while (isdigit(Py_CHARMASK(*p)))
+				p++;
+
+			if (strncmp(p, decimal_point,
+				    decimal_point_len) == 0) {
+				*p = '.';
+				p++;
+				if (decimal_point_len > 1) {
+					rest_len = strlen(p +
+						      (decimal_point_len - 1));
+					memmove(p, p + (decimal_point_len - 1),
+						rest_len);
+					p[rest_len] = 0;
+				}
+			}
+		}
+	}
+
+	/* If an exponent exists, ensure that the exponent is at least
+	   MIN_EXPONENT_DIGITS digits, providing the buffer is large enough
+	   for the extra zeros.  Also, if there are more than
+	   MIN_EXPONENT_DIGITS, remove as many zeros as possible until we get
+	   back to MIN_EXPONENT_DIGITS */
+	p = strpbrk(buffer, "eE");
+	if (p && (*(p + 1) == '-' || *(p + 1) == '+')) {
+		char *start = p + 2;
+		int exponent_digit_cnt = 0;
+		int leading_zero_cnt = 0;
+		int in_leading_zeros = 1;
+		int significant_digit_cnt;
+
+		p += 2;
+		while (*p && isdigit(Py_CHARMASK(*p))) {
+			if (in_leading_zeros && *p == '0')
+				++leading_zero_cnt;
+			if (*p != '0')
+				in_leading_zeros = 0;
+			++p;
+			++exponent_digit_cnt;
+		}
+
+		significant_digit_cnt = exponent_digit_cnt - leading_zero_cnt;
+		if (exponent_digit_cnt == MIN_EXPONENT_DIGITS) {
+			/* If there are 2 exactly digits, we're done,
+			   regardless of what they contain */
+		}
+		else if (exponent_digit_cnt > MIN_EXPONENT_DIGITS) {
+			int extra_zeros_cnt;
+
+			/* There are more than 2 digits in the exponent.  See
+			   if we can delete some of the leading zeros */
+			if (significant_digit_cnt < MIN_EXPONENT_DIGITS)
+				significant_digit_cnt = MIN_EXPONENT_DIGITS;
+			extra_zeros_cnt = exponent_digit_cnt -
+				significant_digit_cnt;
+
+			/* Delete extra_zeros_cnt worth of characters from the
+			   front of the exponent */
+			assert(extra_zeros_cnt >= 0);
+
+			/* Add one to significant_digit_cnt to copy the
+			   trailing 0 byte, thus setting the length */
+			memmove(start,
+				start + extra_zeros_cnt,
+				significant_digit_cnt + 1);
+		}
+		else {
+			/* If there are fewer than 2 digits, add zeros
+			   until there are 2, if there's enough room */
+			int zeros = MIN_EXPONENT_DIGITS - exponent_digit_cnt;
+			if (start + zeros + exponent_digit_cnt + 1
+			      < buffer + buf_size) {
+				memmove(start + zeros, start,
+					exponent_digit_cnt + 1);
+				memset(start, '0', zeros);
+			}
+		}
+	}
+
+	/* If format_char is 'Z', make sure we have at least one character
+	   after the decimal point (and make sure we have a decimal point). */
+	if (format_char == 'Z') {
+		int insert_count = 0;
+		char* chars_to_insert;
+
+		/* search for the first non-digit character */
+		p = buffer;
+		while (*p && isdigit(Py_CHARMASK(*p)))
+			++p;
+
+		if (*p == '.') {
+			if (isdigit(Py_CHARMASK(*(p+1)))) {
+				/* Nothing to do, we already have a decimal
+				   point and a digit after it */
+			}
+			else {
+				/* We have a decimal point, but no following
+				   digit.  Insert a zero after the decimal. */
+				++p;
+				chars_to_insert = "0";
+				insert_count = 1;
+			}
+		}
+		else {
+			chars_to_insert = ".0";
+			insert_count = 2;
+		}
+		if (insert_count) {
+			size_t buf_len = strlen(buffer);
+			if (buf_len + insert_count + 1 >= buf_size) {
+				/* If there is not enough room in the buffer
+				   for the additional text, just skip it.  It's
+				   not worth generating an error over. */
+			}
+			else {
+				memmove(p + insert_count, p,
+					buffer + strlen(buffer) - p + 1);
+				memcpy(p, chars_to_insert, insert_count);
 			}
 		}
 	}

Modified: python/branches/py3k-importlib/Python/pythonrun.c
==============================================================================
--- python/branches/py3k-importlib/Python/pythonrun.c	(original)
+++ python/branches/py3k-importlib/Python/pythonrun.c	Thu Mar 27 00:48:05 2008
@@ -51,6 +51,7 @@
 /* Forward */
 static void initmain(void);
 static void initsite(void);
+static int initstdio(void);
 static PyObject *run_mod(mod_ty, const char *, PyObject *, PyObject *,
 			  PyCompilerFlags *, PyArena *);
 static PyObject *run_pyc_file(FILE *, const char *, PyObject *, PyObject *,
@@ -74,6 +75,8 @@
 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
 int Py_InspectFlag; /* Needed to determine whether to exit at SystemError */
 int Py_NoSiteFlag; /* Suppress 'import site' */
+int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */
+int Py_DontWriteBytecodeFlag; /* Suppress writing bytecode files (*.py[co]) */
 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
 int Py_FrozenFlag; /* Needed by getpath.c */
 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */
@@ -150,7 +153,7 @@
 {
 	PyInterpreterState *interp;
 	PyThreadState *tstate;
-	PyObject *bimod, *sysmod;
+	PyObject *bimod, *sysmod, *pstderr;
 	char *p;
 #if defined(HAVE_LANGINFO_H) && defined(CODESET)
 	char *codeset;
@@ -174,6 +177,8 @@
 		Py_VerboseFlag = add_flag(Py_VerboseFlag, p);
 	if ((p = Py_GETENV("PYTHONOPTIMIZE")) && *p != '\0')
 		Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p);
+	if ((p = Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p != '\0')
+		Py_DontWriteBytecodeFlag = add_flag(Py_DontWriteBytecodeFlag, p);
 
 	interp = PyInterpreterState_New();
 	if (interp == NULL)
@@ -209,12 +214,15 @@
 
 	bimod = _PyBuiltin_Init();
 	if (bimod == NULL)
-		Py_FatalError("Py_Initialize: can't initialize __builtin__");
+		Py_FatalError("Py_Initialize: can't initialize builtins modules");
 	interp->builtins = PyModule_GetDict(bimod);
 	if (interp->builtins == NULL)
 		Py_FatalError("Py_Initialize: can't initialize builtins dict");
 	Py_INCREF(interp->builtins);
 
+	/* initialize builtin exceptions */
+	_PyExc_Init();
+
 	sysmod = _PySys_Init();
 	if (sysmod == NULL)
 		Py_FatalError("Py_Initialize: can't initialize sys");
@@ -227,13 +235,18 @@
 	PyDict_SetItemString(interp->sysdict, "modules",
 			     interp->modules);
 
-	_PyImport_Init();
+	/* Set up a preliminary stderr printer until we have enough
+	   infrastructure for the io module in place. */
+	pstderr = PyFile_NewStdPrinter(fileno(stderr));
+	if (pstderr == NULL)
+		Py_FatalError("Py_Initialize: can't set preliminary stderr");
+	PySys_SetObject("stderr", pstderr);
+	PySys_SetObject("__stderr__", pstderr);
 
-	/* initialize builtin exceptions */
-	_PyExc_Init();
+	_PyImport_Init();
 
 	/* phase 2 of builtins */
-	_PyImport_FixupExtension("__builtin__", "__builtin__");
+	_PyImport_FixupExtension("builtins", "builtins");
 
 	_PyImportHooks_Init();
 
@@ -243,6 +256,11 @@
 	initmain(); /* Module __main__ */
 
 	_PyImport_Importlib(interp->builtins, interp->modules);
+
+	if (initstdio() < 0)
+		Py_FatalError(
+		    "Py_Initialize: can't initialize sys standard streams");
+
 	if (!Py_NoSiteFlag)
 		initsite(); /* Module site */
 
@@ -252,8 +270,28 @@
 #endif /* WITH_THREAD */
 
 	warnings_module = PyImport_ImportModule("warnings");
-	if (!warnings_module)
+	if (!warnings_module) {
 		PyErr_Clear();
+	}
+	else {
+		PyObject *o;
+		char *action[8];
+
+		if (Py_BytesWarningFlag > 1)
+			*action = "error";
+		else if (Py_BytesWarningFlag)
+			*action = "default";
+		else
+			*action = "ignore";
+
+		o = PyObject_CallMethod(warnings_module,
+					"simplefilter", "sO",
+					*action, PyExc_BytesWarning);
+		if (o == NULL)
+			Py_FatalError("Py_Initialize: can't initialize"
+				      "warning filter for BytesWarning.");
+		Py_DECREF(o);
+        }
 
 #if defined(HAVE_LANGINFO_H) && defined(CODESET)
 	/* On Unix, set the file system encoding according to the
@@ -304,7 +342,7 @@
 	PyObject *ferr = PySys_GetObject("stderr");
 	PyObject *tmp;
 
-	if (fout != NULL) {
+	if (fout != NULL && fout != Py_None) {
 		tmp = PyObject_CallMethod(fout, "flush", "");
 		if (tmp == NULL)
 			PyErr_Clear();
@@ -312,7 +350,7 @@
 			Py_DECREF(tmp);
 	}
 
-	if (ferr != NULL) {
+	if (ferr != NULL || ferr != Py_None) {
 		tmp = PyObject_CallMethod(ferr, "flush", "");
 		if (tmp == NULL)
 			PyErr_Clear();
@@ -370,6 +408,9 @@
 	Py_XDECREF(warnings_module);
 	warnings_module = NULL;
 
+	/* Clear type lookup cache */
+	PyType_ClearCache();
+
 	/* Collect garbage.  This may call finalizers; it's nice to call these
 	 * before all modules are destroyed.
 	 * XXX If a __del__ or weakref callback is triggered here, and tries to
@@ -436,11 +477,6 @@
 		_Py_PrintReferences(stderr);
 #endif /* Py_TRACE_REFS */
 
-	/* Cleanup auto-thread-state */
-#ifdef WITH_THREAD
-	_PyGILState_Fini();
-#endif /* WITH_THREAD */
-
 	/* Clear interpreter state */
 	PyInterpreterState_Clear(interp);
 
@@ -452,6 +488,11 @@
 
 	_PyExc_Fini();
 
+	/* Cleanup auto-thread-state */
+#ifdef WITH_THREAD
+	_PyGILState_Fini();
+#endif /* WITH_THREAD */
+
 	/* Delete current thread */
 	PyThreadState_Swap(NULL);
 	PyInterpreterState_Delete(interp);
@@ -467,10 +508,17 @@
 	PyBytes_Fini();
 	PyLong_Fini();
 	PyFloat_Fini();
+	PyDict_Fini();
 
 	/* Cleanup Unicode implementation */
 	_PyUnicode_Fini();
 
+	/* reset file system default encoding */
+	if (!Py_HasFileSystemDefaultEncoding) {
+		free((char*)Py_FileSystemDefaultEncoding);
+		Py_FileSystemDefaultEncoding = NULL;
+	}
+
 	/* XXX Still allocated:
 	   - various static ad-hoc pointers to interned strings
 	   - int and float free list blocks
@@ -535,7 +583,7 @@
 	interp->modules = PyDict_New();
 	interp->modules_reloading = PyDict_New();
 
-	bimod = _PyImport_FindExtension("__builtin__", "__builtin__");
+	bimod = _PyImport_FindExtension("builtins", "builtins");
 	if (bimod != NULL) {
 		interp->builtins = PyModule_GetDict(bimod);
 		if (interp->builtins == NULL)
@@ -645,7 +693,7 @@
 		Py_FatalError("can't create __main__ module");
 	d = PyModule_GetDict(m);
 	if (PyDict_GetItemString(d, "__builtins__") == NULL) {
-		PyObject *bimod = PyImport_ImportModule("__builtin__");
+		PyObject *bimod = PyImport_ImportModule("builtins");
 		if (bimod == NULL ||
 		    PyDict_SetItemString(d, "__builtins__", bimod) != 0)
 			Py_FatalError("can't add __builtins__ to __main__");
@@ -662,6 +710,8 @@
 	m = PyImport_ImportModule("site");
 	if (m == NULL) {
 		f = PySys_GetObject("stderr");
+		if (f == NULL || f == Py_None)
+			return;
 		if (Py_VerboseFlag) {
 			PyFile_WriteString(
 				"'import site' failed; traceback:\n", f);
@@ -678,6 +728,134 @@
 	}
 }
 
+/* Initialize sys.stdin, stdout, stderr and builtins.open */
+static int
+initstdio(void)
+{
+	PyObject *iomod = NULL, *wrapper;
+	PyObject *bimod = NULL;
+	PyObject *m;
+	PyObject *std = NULL;
+	int status = 0, fd;
+	PyObject * encoding_attr;
+
+	/* Hack to avoid a nasty recursion issue when Python is invoked
+	   in verbose mode: pre-import the Latin-1 and UTF-8 codecs */
+	if ((m = PyImport_ImportModule("encodings.utf_8")) == NULL) {
+		goto error;
+	}
+	Py_DECREF(m);
+
+	if (!(m = PyImport_ImportModule("encodings.latin_1"))) {
+		goto error;
+	}
+	Py_DECREF(m);
+
+	if (!(bimod = PyImport_ImportModule("builtins"))) {
+		goto error;
+	}
+
+	if (!(iomod = PyImport_ImportModule("io"))) {
+		goto error;
+	}
+	if (!(wrapper = PyObject_GetAttrString(iomod, "OpenWrapper"))) {
+		goto error;
+	}
+
+	/* Set builtins.open */
+	if (PyObject_SetAttrString(bimod, "open", wrapper) == -1) {
+		goto error;
+	}
+
+	/* Set sys.stdin */
+	fd = fileno(stdin);
+	/* Under some conditions stdin, stdout and stderr may not be connected
+	 * and fileno() may point to an invalid file descriptor. For example
+	 * GUI apps don't have valid standard streams by default.
+	 */
+	if (fd < 0) {
+#ifdef MS_WINDOWS
+		std = Py_None;
+		Py_INCREF(std);
+#else
+		goto error;
+#endif
+	}
+	else {
+		if (!(std = PyFile_FromFd(fd, "<stdin>", "r", -1, NULL, NULL,
+					  "\n", 0))) {
+			goto error;
+		}
+	} /* if (fd < 0) */
+	PySys_SetObject("__stdin__", std);
+	PySys_SetObject("stdin", std);
+	Py_DECREF(std);
+
+	/* Set sys.stdout */
+	fd = fileno(stdout);
+	if (fd < 0) {
+#ifdef MS_WINDOWS
+		std = Py_None;
+		Py_INCREF(std);
+#else
+		goto error;
+#endif
+	}
+	else {
+		if (!(std = PyFile_FromFd(fd, "<stdout>", "w", -1, NULL, NULL,
+					  "\n", 0))) {
+			goto error;
+		}
+	} /* if (fd < 0) */
+	PySys_SetObject("__stdout__", std);
+	PySys_SetObject("stdout", std);
+	Py_DECREF(std);
+
+#if 1 /* Disable this if you have trouble debugging bootstrap stuff */
+	/* Set sys.stderr, replaces the preliminary stderr */
+	fd = fileno(stderr);
+	if (fd < 0) {
+#ifdef MS_WINDOWS
+		std = Py_None;
+		Py_INCREF(std);
+#else
+		goto error;
+#endif
+	}
+	else {
+		if (!(std = PyFile_FromFd(fd, "<stderr>", "w", -1, NULL, NULL,
+					  "\n", 0))) {
+			goto error;
+		}
+	} /* if (fd < 0) */
+
+	/* Same as hack above, pre-import stderr's codec to avoid recursion
+	   when import.c tries to write to stderr in verbose mode. */
+	encoding_attr = PyObject_GetAttrString(std, "encoding");
+	if (encoding_attr != NULL) {
+		const char * encoding;
+		encoding = PyUnicode_AsString(encoding_attr);
+		if (encoding != NULL) {
+			_PyCodec_Lookup(encoding);
+		}
+	}
+	PyErr_Clear();  /* Not a fatal error if codec isn't available */
+
+	PySys_SetObject("__stderr__", std);
+	PySys_SetObject("stderr", std);
+	Py_DECREF(std);
+#endif
+
+	if (0) {
+  error:
+		status = -1;
+	}
+
+	Py_XDECREF(bimod);
+	Py_XDECREF(iomod);
+	return status;
+}
+
 /* Parse input from a file and execute it */
 
 int
@@ -755,7 +933,7 @@
 	if (fp == stdin) {
 		/* Fetch encoding from sys.stdin */
 		v = PySys_GetObject("stdin");
-		if (!v)
+		if (v == NULL || v == Py_None)
 			return -1;
 		oenc = PyObject_GetAttrString(v, "encoding");
 		if (!oenc)
@@ -764,7 +942,7 @@
 	}
 	v = PySys_GetObject("ps1");
 	if (v != NULL) {
-		v = PyObject_Unicode(v);
+		v = PyObject_Str(v);
 		if (v == NULL)
 			PyErr_Clear();
 		else if (PyUnicode_Check(v))
@@ -772,7 +950,7 @@
 	}
 	w = PySys_GetObject("ps2");
 	if (w != NULL) {
-		w = PyObject_Unicode(w);
+		w = PyObject_Str(w);
 		if (w == NULL)
 			PyErr_Clear();
 		else if (PyUnicode_Check(w))
@@ -950,13 +1128,13 @@
 		goto finally;
 	if (v == Py_None)
 		*filename = NULL;
-	else if (! (*filename = PyString_AsString(v)))
+	else if (! (*filename = PyUnicode_AsString(v)))
 		goto finally;
 
 	Py_DECREF(v);
 	if (!(v = PyObject_GetAttrString(err, "lineno")))
 		goto finally;
-	hold = PyInt_AsLong(v);
+	hold = PyLong_AsLong(v);
 	Py_DECREF(v);
 	v = NULL;
 	if (hold < 0 && PyErr_Occurred())
@@ -970,7 +1148,7 @@
 		Py_DECREF(v);
 		v = NULL;
 	} else {
-		hold = PyInt_AsLong(v);
+		hold = PyLong_AsLong(v);
 		Py_DECREF(v);
 		v = NULL;
 		if (hold < 0 && PyErr_Occurred())
@@ -1060,8 +1238,8 @@
 		/* If we failed to dig out the 'code' attribute,
 		   just let the else clause below print the error. */
 	}
-	if (PyInt_Check(value))
-		exitcode = (int)PyInt_AsLong(value);
+	if (PyLong_Check(value))
+		exitcode = (int)PyLong_AsLong(value);
 	else {
 		PyObject_Print(value, stderr, Py_PRINT_RAW);
 		PySys_WriteStderr("\n");
@@ -1148,10 +1326,13 @@
 	int err = 0;
 	PyObject *f = PySys_GetObject("stderr");
 	Py_INCREF(value);
-	if (f == NULL)
+	if (f == Py_None) {
+		/* pass */
+	}
+	else if (f == NULL) {
 		_PyObject_Dump(value);
-	if (f == NULL)
 		fprintf(stderr, "lost sys.stderr\n");
+	}
 	else {
 		fflush(stdout);
 		if (tb && tb != Py_None)
@@ -1206,7 +1387,7 @@
 			}
 			else {
 				char* modstr = PyUnicode_AsString(moduleName);
-				if (modstr && strcmp(modstr, "__builtin__"))
+				if (modstr && strcmp(modstr, "builtins"))
 				{
 					err = PyFile_WriteString(modstr, f);
 					err += PyFile_WriteString(".", f);
@@ -1223,7 +1404,7 @@
 		else
 			err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);
 		if (err == 0 && (value != Py_None)) {
-			PyObject *s = PyObject_Unicode(value);
+			PyObject *s = PyObject_Str(value);
 			/* only print colon if the str() of the
 			   object is not the empty string
 			*/
@@ -1255,7 +1436,7 @@
 	PyArena *arena = PyArena_New();
 	if (arena == NULL)
 		return NULL;
-	
+
 	mod = PyParser_ASTFromString(str, "<string>", start, flags, arena);
 	if (mod != NULL)
 		ret = run_mod(mod, "<string>", globals, locals, flags, arena);
@@ -1272,7 +1453,7 @@
 	PyArena *arena = PyArena_New();
 	if (arena == NULL)
 		return NULL;
-	
+
 	mod = PyParser_ASTFromFile(fp, filename, NULL, start, 0, 0,
 				   flags, NULL, arena);
 	if (closeit)
@@ -1286,6 +1467,28 @@
 	return ret;
 }
 
+static void
+flush_io(void)
+{
+	PyObject *f, *r;
+	f = PySys_GetObject("stderr");
+	if (f != NULL) {
+		r = PyObject_CallMethod(f, "flush", "");
+		if (r)
+			Py_DECREF(r);
+		else
+			PyErr_Clear();
+	}
+	f = PySys_GetObject("stdout");
+	if (f != NULL) {
+		r = PyObject_CallMethod(f, "flush", "");
+		if (r)
+			Py_DECREF(r);
+		else
+			PyErr_Clear();
+	}
+}
+
 static PyObject *
 run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals,
 	 PyCompilerFlags *flags, PyArena *arena)
@@ -1297,6 +1500,7 @@
 		return NULL;
 	v = PyEval_EvalCode(co, globals, locals);
 	Py_DECREF(co);
+	flush_io();
 	return v;
 }
 
@@ -1329,6 +1533,7 @@
 	if (v && flags)
 		flags->cf_flags |= (co->co_flags & PyCF_MASK);
 	Py_DECREF(co);
+	flush_io();
 	return v;
 }
 
@@ -1537,7 +1742,7 @@
 		PyObject *type, *value, *tb;
 		PyErr_Fetch(&type, &value, &tb);
 		if (value != NULL) {
-			u = PyObject_Unicode(value);
+			u = PyObject_Str(value);
 			if (u != NULL) {
 				msg = PyUnicode_AsString(u);
 			}
@@ -1591,6 +1796,9 @@
 Py_FatalError(const char *msg)
 {
 	fprintf(stderr, "Fatal Python error: %s\n", msg);
+	if (PyErr_Occurred()) {
+		PyErr_Print();
+	}
 #ifdef MS_WINDOWS
 	OutputDebugString("Fatal Python error: ");
 	OutputDebugString(msg);
@@ -1618,7 +1826,7 @@
 static void
 call_py_exitfuncs(void)
 {
-	if (pyexitfunc == NULL) 
+	if (pyexitfunc == NULL)
 		return;
 
 	(*pyexitfunc)();
@@ -1709,8 +1917,14 @@
 		   not enough space left on the stack */
 		alloca(PYOS_STACK_MARGIN * sizeof(void*));
 		return 0;
-	} __except (EXCEPTION_EXECUTE_HANDLER) {
-		/* just ignore all errors */
+	} __except (GetExceptionCode() == STATUS_STACK_OVERFLOW ?
+			EXCEPTION_EXECUTE_HANDLER : 
+			EXCEPTION_CONTINUE_SEARCH) {
+		int errcode = _resetstkoflw();
+		if (errcode)
+		{
+			Py_FatalError("Could not reset the stack!");
+		}
 	}
 	return 1;
 }

Deleted: /python/branches/py3k-importlib/Python/strerror.c
==============================================================================
--- /python/branches/py3k-importlib/Python/strerror.c	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,19 +0,0 @@
-
-/* PD implementation of strerror() for systems that don't have it.
-   Author: Guido van Rossum, CWI Amsterdam, Oct. 1990, <guido at cwi.nl>. */
-
-#include <stdio.h>
-#include "Python.h"
-
-extern int sys_nerr;
-extern char *sys_errlist[];
-
-char *
-strerror(int err)
-{
-	static char buf[20];
-	if (err >= 0 && err < sys_nerr)
-		return sys_errlist[err];
-	PyOS_snprintf(buf, sizeof(buf), "Unknown errno %d", err);
-	return buf;
-}

Modified: python/branches/py3k-importlib/Python/strtod.c
==============================================================================
--- python/branches/py3k-importlib/Python/strtod.c	(original)
+++ python/branches/py3k-importlib/Python/strtod.c	Thu Mar 27 00:48:05 2008
@@ -44,11 +44,11 @@
     I do know about <values.h>, but the whole point of this file is that
     we can't always trust that stuff to be there or to be correct.
 */
-static	int	MDMINEXPT	= {-323};
+static	int	MDMINEXPT	= -323;
 static	char	MDMINFRAC[]	= "494065645841246544";
 static	double	ZERO		= 0.0;
 
-static	int	MDMAXEXPT	= { 309};
+static	int	MDMAXEXPT	= 309;
 static	char	MDMAXFRAC[]	= "17976931348623157";
 static	double	HUGE		= 1.7976931348623157e308;
 

Modified: python/branches/py3k-importlib/Python/structmember.c
==============================================================================
--- python/branches/py3k-importlib/Python/structmember.c	(original)
+++ python/branches/py3k-importlib/Python/structmember.c	Thu Mar 27 00:48:05 2008
@@ -12,32 +12,35 @@
 
 	addr += l->offset;
 	switch (l->type) {
+	case T_BOOL:
+		v = PyBool_FromLong(*(char*)addr);
+		break;
 	case T_BYTE:
-		v = PyInt_FromLong(*(char*)addr);
+		v = PyLong_FromLong(*(char*)addr);
 		break;
 	case T_UBYTE:
 		v = PyLong_FromUnsignedLong(*(unsigned char*)addr);
 		break;
 	case T_SHORT:
-		v = PyInt_FromLong(*(short*)addr);
+		v = PyLong_FromLong(*(short*)addr);
 		break;
 	case T_USHORT:
 		v = PyLong_FromUnsignedLong(*(unsigned short*)addr);
 		break;
 	case T_INT:
-		v = PyInt_FromLong(*(int*)addr);
+		v = PyLong_FromLong(*(int*)addr);
 		break;
 	case T_UINT:
 		v = PyLong_FromUnsignedLong(*(unsigned int*)addr);
 		break;
 	case T_LONG:
-		v = PyInt_FromLong(*(long*)addr);
+		v = PyLong_FromLong(*(long*)addr);
 		break;
 	case T_ULONG:
 		v = PyLong_FromUnsignedLong(*(unsigned long*)addr);
 		break;
 	case T_PYSSIZET:
-		v = PyInt_FromSsize_t(*(Py_ssize_t*)addr);
+		v = PyLong_FromSsize_t(*(Py_ssize_t*)addr);
 		break;
 	case T_FLOAT:
 		v = PyFloat_FromDouble((double)*(float*)addr);
@@ -51,13 +54,13 @@
 			v = Py_None;
 		}
 		else
-			v = PyString_FromString(*(char**)addr);
+			v = PyUnicode_FromString(*(char**)addr);
 		break;
 	case T_STRING_INPLACE:
-		v = PyString_FromString((char*)addr);
+		v = PyUnicode_FromString((char*)addr);
 		break;
 	case T_CHAR:
-		v = PyString_FromStringAndSize((char*)addr, 1);
+		v = PyUnicode_FromStringAndSize((char*)addr, 1);
 		break;
 	case T_OBJECT:
 		v = *(PyObject **)addr;
@@ -113,8 +116,20 @@
 	}
 	addr += l->offset;
 	switch (l->type) {
+	case T_BOOL:{
+		if (!PyBool_Check(v)) {
+			PyErr_SetString(PyExc_TypeError,
+					"attribute value type must be bool");
+			return -1;
+		}
+		if (v == Py_True)
+			*(char*)addr = (char) 1;
+		else
+			*(char*)addr = (char) 0;
+		break;
+		}
 	case T_BYTE:{
-		long long_val = PyInt_AsLong(v);
+		long long_val = PyLong_AsLong(v);
 		if ((long_val == -1) && PyErr_Occurred())
 			return -1;
 		*(char*)addr = (char)long_val;
@@ -125,7 +140,7 @@
 		break;
 		}
 	case T_UBYTE:{
-		long long_val = PyInt_AsLong(v);
+		long long_val = PyLong_AsLong(v);
 		if ((long_val == -1) && PyErr_Occurred())
 			return -1;
 		*(unsigned char*)addr = (unsigned char)long_val;
@@ -134,7 +149,7 @@
 		break;
 		}
 	case T_SHORT:{
-		long long_val = PyInt_AsLong(v);
+		long long_val = PyLong_AsLong(v);
 		if ((long_val == -1) && PyErr_Occurred())
 			return -1;
 		*(short*)addr = (short)long_val;
@@ -143,7 +158,7 @@
 		break;
 		}
 	case T_USHORT:{
-		long long_val = PyInt_AsLong(v);
+		long long_val = PyLong_AsLong(v);
 		if ((long_val == -1) && PyErr_Occurred())
 			return -1;
 		*(unsigned short*)addr = (unsigned short)long_val;
@@ -152,7 +167,7 @@
 		break;
 		}
   	case T_INT:{
-		long long_val = PyInt_AsLong(v);
+		long long_val = PyLong_AsLong(v);
 		if ((long_val == -1) && PyErr_Occurred())
 			return -1;
 		*(int *)addr = (int)long_val;
@@ -199,7 +214,7 @@
 		break;
 		}
 	case T_PYSSIZET:{
-		*(Py_ssize_t*)addr = PyInt_AsSsize_t(v);
+		*(Py_ssize_t*)addr = PyLong_AsSsize_t(v);
 		if ((*(Py_ssize_t*)addr == (Py_ssize_t)-1)
 		    && PyErr_Occurred())
 				return -1;
@@ -225,8 +240,8 @@
 		Py_XDECREF(oldv);
 		break;
 	case T_CHAR:
-		if (PyString_Check(v) && PyString_Size(v) == 1) {
-			*(char*)addr = PyString_AsString(v)[0];
+		if (PyUnicode_Check(v) && PyUnicode_GetSize(v) == 1) {
+			*(char*)addr = PyUnicode_AsString(v)[0];
 		}
 		else {
 			PyErr_BadArgument();
@@ -248,7 +263,7 @@
 		if (PyLong_Check(v))
 			*(unsigned PY_LONG_LONG*)addr = value = PyLong_AsUnsignedLongLong(v);
 		else
-			*(unsigned PY_LONG_LONG*)addr = value = PyInt_AsLong(v);
+			*(unsigned PY_LONG_LONG*)addr = value = PyLong_AsLong(v);
 		if ((value == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())
 			return -1;
 		break;

Modified: python/branches/py3k-importlib/Python/symtable.c
==============================================================================
--- python/branches/py3k-importlib/Python/symtable.c	(original)
+++ python/branches/py3k-importlib/Python/symtable.c	Thu Mar 27 00:48:05 2008
@@ -33,8 +33,9 @@
 	k = PyLong_FromVoidPtr(key);
 	if (k == NULL)
 		goto fail;
-	ste = (PySTEntryObject *)PyObject_New(PySTEntryObject,
-					      &PySTEntry_Type);
+	ste = PyObject_New(PySTEntryObject, &PySTEntry_Type);
+	if (ste == NULL)
+		goto fail;
 	ste->ste_table = st;
 	ste->ste_id = k;
 	ste->ste_tmpname = 0;
@@ -90,7 +91,7 @@
 {
 	return PyUnicode_FromFormat("<symtable entry %U(%ld), line %d>",
 	                            ste->ste_name,
-	                            PyInt_AS_LONG(ste->ste_id), ste->ste_lineno);
+	                            PyLong_AS_LONG(ste->ste_id), ste->ste_lineno);
 }
 
 static void
@@ -310,8 +311,8 @@
 	PyObject *v = PyDict_GetItem(ste->ste_symbols, name);
 	if (!v)
 		return 0;
-	assert(PyInt_Check(v));
-	return (PyInt_AS_LONG(v) >> SCOPE_OFFSET) & SCOPE_MASK;
+	assert(PyLong_Check(v));
+	return (PyLong_AS_LONG(v) >> SCOPE_OFFSET) & SCOPE_MASK;
 }
 
 
@@ -361,7 +362,7 @@
 */
 
 #define SET_SCOPE(DICT, NAME, I) { \
-	PyObject *o = PyInt_FromLong(I); \
+	PyObject *o = PyLong_FromLong(I); \
 	if (!o) \
 		return 0; \
 	if (PyDict_SetItem((DICT), (NAME), o) < 0) { \
@@ -465,30 +466,30 @@
    Note that the current block's free variables are included in free.
    That's safe because no name can be free and local in the same scope.
 
-   The 'restrict' argument may be set to a string to restrict the analysis
+   The 'restricted' argument may be set to a string to restrict the analysis
    to the one variable whose name equals that string (e.g. "__class__").
 */
 
 static int
-analyze_cells(PyObject *scopes, PyObject *free, const char *restrict)
+analyze_cells(PyObject *scopes, PyObject *free, const char *restricted)
 {
         PyObject *name, *v, *v_cell;
 	int success = 0;
 	Py_ssize_t pos = 0;
 
-	v_cell = PyInt_FromLong(CELL);
+	v_cell = PyLong_FromLong(CELL);
 	if (!v_cell)
 		return 0;
 	while (PyDict_Next(scopes, &pos, &name, &v)) {
 		long scope;
-		assert(PyInt_Check(v));
-		scope = PyInt_AS_LONG(v);
+		assert(PyLong_Check(v));
+		scope = PyLong_AS_LONG(v);
 		if (scope != LOCAL)
 			continue;
 		if (!PySet_Contains(free, name))
 			continue;
-		if (restrict != NULL &&
-                    PyUnicode_CompareWithASCIIString(name, restrict))
+		if (restricted != NULL &&
+                    PyUnicode_CompareWithASCIIString(name, restricted))
 			continue;
 		/* Replace LOCAL with CELL for this name, and remove
 		   from free. It is safe to replace the value of name 
@@ -548,13 +549,13 @@
 	/* Update scope information for all symbols in this scope */
 	while (PyDict_Next(symbols, &pos, &name, &v)) {
 		long scope, flags;
-		assert(PyInt_Check(v));
-		flags = PyInt_AS_LONG(v);
+		assert(PyLong_Check(v));
+		flags = PyLong_AS_LONG(v);
 		v_scope = PyDict_GetItem(scopes, name);
-		assert(v_scope && PyInt_Check(v_scope));
-		scope = PyInt_AS_LONG(v_scope);
+		assert(v_scope && PyLong_Check(v_scope));
+		scope = PyLong_AS_LONG(v_scope);
 		flags |= (scope << SCOPE_OFFSET);
-		v_new = PyInt_FromLong(flags);
+		v_new = PyLong_FromLong(flags);
 		if (!v_new)
 			return 0;
 		if (PyDict_SetItem(symbols, name, v_new) < 0) {
@@ -565,7 +566,7 @@
 	}
 
 	/* Record not yet resolved free variables from children (if any) */
-        v_free = PyInt_FromLong(FREE << SCOPE_OFFSET);
+        v_free = PyLong_FromLong(FREE << SCOPE_OFFSET);
         if (!v_free)
 		return 0;
 
@@ -583,9 +584,9 @@
 			   or global in the class scope.
 			*/
 			if  (classflag && 
-			     PyInt_AS_LONG(v) & (DEF_BOUND | DEF_GLOBAL)) {
-				long flags = PyInt_AS_LONG(v) | DEF_FREE_CLASS;
-				v_new = PyInt_FromLong(flags);
+			     PyLong_AS_LONG(v) & (DEF_BOUND | DEF_GLOBAL)) {
+				long flags = PyLong_AS_LONG(v) | DEF_FREE_CLASS;
+				v_new = PyLong_FromLong(flags);
 				if (!v_new) {
 					goto error;
 				}
@@ -675,7 +676,7 @@
 	assert(PySTEntry_Check(ste));
 	assert(PyDict_Check(ste->ste_symbols));
 	while (PyDict_Next(ste->ste_symbols, &pos, &name, &v)) {
-		long flags = PyInt_AS_LONG(v);
+		long flags = PyLong_AS_LONG(v);
 		if (!analyze_name(ste, scopes, name, flags, bound, local, free,
 				  global))
 			goto error;
@@ -849,7 +850,7 @@
 	Py_DECREF(mangled);
 	if (!o)
 		return 0;
-	return PyInt_AsLong(o);
+	return PyLong_AsLong(o);
 }
 
 static int
@@ -865,7 +866,7 @@
 		return 0;
 	dict = st->st_cur->ste_symbols;
 	if ((o = PyDict_GetItem(dict, mangled))) {
-	    val = PyInt_AS_LONG(o);
+	    val = PyLong_AS_LONG(o);
 	    if ((flag & DEF_PARAM) && (val & DEF_PARAM)) {
 		    /* Is it better to use 'mangled' or 'name' here? */
 		    PyErr_Format(PyExc_SyntaxError, DUPLICATE_ARGUMENT, name);
@@ -876,7 +877,7 @@
 	    val |= flag;
 	} else
 	    val = flag;
-	o = PyInt_FromLong(val);
+	o = PyLong_FromLong(val);
         if (o == NULL)
 	    goto error;
 	if (PyDict_SetItem(dict, mangled, o) < 0) {
@@ -893,9 +894,9 @@
 		   perhaps only DEF_FREE_GLOBAL */
 		val = flag;
 		if ((o = PyDict_GetItem(st->st_global, mangled))) {
-			val |= PyInt_AS_LONG(o);
+			val |= PyLong_AS_LONG(o);
 		}
-		o = PyInt_FromLong(val);
+		o = PyLong_FromLong(val);
 		if (o == NULL)
 			goto error;
 		if (PyDict_SetItem(st->st_global, mangled, o) < 0) {

Modified: python/branches/py3k-importlib/Python/sysmodule.c
==============================================================================
--- python/branches/py3k-importlib/Python/sysmodule.c	(original)
+++ python/branches/py3k-importlib/Python/sysmodule.c	Thu Mar 27 00:48:05 2008
@@ -15,6 +15,7 @@
 */
 
 #include "Python.h"
+#include "structseq.h"
 #include "code.h"
 #include "frameobject.h"
 #include "eval.h"
@@ -23,7 +24,7 @@
 
 #ifdef MS_WINDOWS
 #define WIN32_LEAN_AND_MEAN
-#include "windows.h"
+#include <windows.h>
 #endif /* MS_WINDOWS */
 
 #ifdef MS_COREDLL
@@ -36,10 +37,6 @@
 #include <unixlib.h>
 #endif
 
-#ifdef MS_WINDOWS
-#include <windows.h>
-#endif
-
 #ifdef HAVE_LANGINFO_H
 #include <locale.h>
 #include <langinfo.h>
@@ -76,10 +73,10 @@
 	PyObject *outf;
 	PyInterpreterState *interp = PyThreadState_GET()->interp;
 	PyObject *modules = interp->modules;
-	PyObject *builtins = PyDict_GetItemString(modules, "__builtin__");
+	PyObject *builtins = PyDict_GetItemString(modules, "builtins");
 
 	if (builtins == NULL) {
-		PyErr_SetString(PyExc_RuntimeError, "lost __builtin__");
+		PyErr_SetString(PyExc_RuntimeError, "lost builtins module");
 		return NULL;
 	}
 
@@ -93,7 +90,7 @@
 	if (PyObject_SetAttrString(builtins, "_", Py_None) != 0)
 		return NULL;
 	outf = PySys_GetObject("stdout");
-	if (outf == NULL) {
+	if (outf == NULL || outf == Py_None) {
 		PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
 		return NULL;
 	}
@@ -110,7 +107,7 @@
 PyDoc_STRVAR(displayhook_doc,
 "displayhook(object) -> None\n"
 "\n"
-"Print an object to sys.stdout and also save it in __builtin__.\n"
+"Print an object to sys.stdout and also save it in builtins.\n"
 );
 
 static PyObject *
@@ -225,14 +222,9 @@
 sys_intern(PyObject *self, PyObject *args)
 {
 	PyObject *s;
-	if (!PyArg_ParseTuple(args, "S:intern", &s))
+	if (!PyArg_ParseTuple(args, "U:intern", &s))
 		return NULL;
-	if (PyString_CheckExact(s)) {
-		Py_INCREF(s);
-		PyString_InternInPlace(&s);
-		return s;
-	}
-	else if (PyUnicode_CheckExact(s)) {
+	if (PyUnicode_CheckExact(s)) {
 		Py_INCREF(s);
 		PyUnicode_InternInPlace(&s);
 		return s;
@@ -382,6 +374,25 @@
 );
 
 static PyObject *
+sys_gettrace(PyObject *self, PyObject *args)
+{
+	PyThreadState *tstate = PyThreadState_GET();
+	PyObject *temp = tstate->c_traceobj;
+
+	if (temp == NULL)
+		temp = Py_None;
+	Py_INCREF(temp);
+	return temp;
+}
+
+PyDoc_STRVAR(gettrace_doc,
+"gettrace()\n\
+\n\
+Return the global debug tracing function set with sys.settrace.\n\
+See the debugger chapter in the library manual."
+);
+
+static PyObject *
 sys_setprofile(PyObject *self, PyObject *args)
 {
 	if (trace_init() == -1)
@@ -402,6 +413,25 @@
 );
 
 static PyObject *
+sys_getprofile(PyObject *self, PyObject *args)
+{
+	PyThreadState *tstate = PyThreadState_GET();
+	PyObject *temp = tstate->c_profileobj;
+
+	if (temp == NULL)
+		temp = Py_None;
+	Py_INCREF(temp);
+	return temp;
+}
+
+PyDoc_STRVAR(getprofile_doc,
+"getprofile()\n\
+\n\
+Return the profiling function set with sys.setprofile.\n\
+See the profiler chapter in the library manual."
+);
+
+static PyObject *
 sys_setcheckinterval(PyObject *self, PyObject *args)
 {
 	if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_Py_CheckInterval))
@@ -420,7 +450,7 @@
 static PyObject *
 sys_getcheckinterval(PyObject *self, PyObject *args)
 {
-	return PyInt_FromLong(_Py_CheckInterval);
+	return PyLong_FromLong(_Py_CheckInterval);
 }
 
 PyDoc_STRVAR(getcheckinterval_doc,
@@ -482,7 +512,7 @@
 static PyObject *
 sys_getrecursionlimit(PyObject *self)
 {
-	return PyInt_FromLong(Py_GetRecursionLimit());
+	return PyLong_FromLong(Py_GetRecursionLimit());
 }
 
 PyDoc_STRVAR(getrecursionlimit_doc,
@@ -552,7 +582,7 @@
         PyThreadState *tstate = PyThreadState_GET();
         if (!tstate)
 		return NULL;
-        return PyInt_FromLong(tstate->interp->dlopenflags);
+        return PyLong_FromLong(tstate->interp->dlopenflags);
 }
 
 PyDoc_STRVAR(getdlopenflags_doc,
@@ -582,14 +612,14 @@
 static PyObject *
 sys_getrefcount(PyObject *self, PyObject *arg)
 {
-	return PyInt_FromSsize_t(arg->ob_refcnt);
+	return PyLong_FromSsize_t(arg->ob_refcnt);
 }
 
 #ifdef Py_REF_DEBUG
 static PyObject *
 sys_gettotalrefcount(PyObject *self)
 {
-	return PyInt_FromSsize_t(_Py_GetRefTotal());
+	return PyLong_FromSsize_t(_Py_GetRefTotal());
 }
 #endif /* Py_REF_DEBUG */
 
@@ -718,10 +748,41 @@
 }
 #endif
 
+static PyObject *
+sys_clear_type_cache(PyObject* self, PyObject* args)
+{
+	PyType_ClearCache();
+	Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(sys_clear_type_cache__doc__,
+"_clear_type_cache() -> None\n\
+Clear the internal type lookup cache.");
+
+
+static PyObject *
+sys_compact_freelists(PyObject* self, PyObject* args)
+{
+	size_t fsum, fbc, fbf;
+
+	PyFloat_CompactFreeList(&fbc, &fbf, &fsum);
+
+	return Py_BuildValue("((kkk))", fsum, fbc, fbf);
+
+}
+
+PyDoc_STRVAR(sys_compact_freelists__doc__,
+"_compact_freelists() -> ((remaing_objects, total_blocks, freed_blocks),)\n\
+Compact the free lists of floats.");
+
 static PyMethodDef sys_methods[] = {
 	/* Might as well keep this in alphabetic order */
 	{"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
 	 callstats_doc},
+	{"_clear_type_cache",	sys_clear_type_cache,	  METH_NOARGS,
+	 sys_clear_type_cache__doc__},
+	{"_compact_freelists",	sys_compact_freelists,	  METH_NOARGS,
+	 sys_compact_freelists__doc__},
 	{"_current_frames", sys_current_frames, METH_NOARGS,
 	 current_frames_doc},
 	{"displayhook",	sys_displayhook, METH_O, displayhook_doc},
@@ -771,12 +832,14 @@
 	 setdlopenflags_doc},
 #endif
 	{"setprofile",	sys_setprofile, METH_O, setprofile_doc},
+	{"getprofile",	sys_getprofile, METH_NOARGS, getprofile_doc},
 	{"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
 	 setrecursionlimit_doc},
 #ifdef WITH_TSC
 	{"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc},
 #endif
 	{"settrace",	sys_settrace, METH_O, settrace_doc},
+	{"gettrace",	sys_gettrace, METH_NOARGS, gettrace_doc},
 	{"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
 	{NULL,		NULL}		/* sentinel */
 };
@@ -874,10 +937,11 @@
 "\n\
 Static objects:\n\
 \n\
-maxint -- the largest supported integer (the smallest is -maxint-1)\n\
+float_info -- a dict with information about the float implementation.\n\
 maxsize -- the largest supported length of containers.\n\
 maxunicode -- the largest supported character\n\
 builtin_module_names -- tuple of module names built into this interpreter\n\
+subversion -- subversion information of the build as tuple\n\
 version -- the version of this interpreter as a string\n\
 version_info -- version information as a tuple\n\
 hexversion -- version information encoded as a single integer\n\
@@ -905,13 +969,15 @@
 \n\
 Functions:\n\
 \n\
-displayhook() -- print an object to the screen, and save it in __builtin__._\n\
+displayhook() -- print an object to the screen, and save it in builtins._\n\
 excepthook() -- print an exception and its traceback to sys.stderr\n\
 exc_info() -- return thread-safe information about the current exception\n\
 exit() -- exit the interpreter by raising SystemExit\n\
 getdlopenflags() -- returns flags to be used for dlopen() calls\n\
+getprofile() -- get the global profiling function\n\
 getrefcount() -- return the reference count for an object (plus one :-)\n\
 getrecursionlimit() -- return the max recursion depth for the interpreter\n\
+gettrace() -- get the global debug tracing function\n\
 setcheckinterval() -- control how often the interpreter checks for events\n\
 setdlopenflags() -- set the flags to be used for dlopen() calls\n\
 setprofile() -- set the global profiling function\n\
@@ -1010,6 +1076,82 @@
 	return shortbranch;
 }
 
+
+PyDoc_STRVAR(flags__doc__,
+"sys.flags\n\
+\n\
+Flags provided through command line arguments or environment vars.");
+
+static PyTypeObject FlagsType;
+
+static PyStructSequence_Field flags_fields[] = {
+	{"debug",		"-d"},
+	{"division_warning",	"-Q"},
+	{"inspect",		"-i"},
+	{"interactive",		"-i"},
+	{"optimize",		"-O or -OO"},
+	{"dont_write_bytecode",	"-B"},
+	/* {"no_user_site",	"-s"}, */
+	{"no_site",		"-S"},
+	{"ignore_environment",	"-E"},
+	{"tabcheck",		"-t or -tt"},
+	{"verbose",		"-v"},
+#ifdef RISCOS
+	{"riscos_wimp",		"???"},
+#endif
+	/* {"unbuffered",		"-u"}, */
+	/* {"skip_first",		"-x"}, */
+	{0}
+};
+
+static PyStructSequence_Desc flags_desc = {
+	"sys.flags",	/* name */
+	flags__doc__,	/* doc */
+	flags_fields,	/* fields */
+#ifdef RISCOS
+	11
+#else
+	10
+#endif
+};
+
+static PyObject*
+make_flags(void)
+{
+	int pos = 0;
+	PyObject *seq;
+
+	seq = PyStructSequence_New(&FlagsType);
+	if (seq == NULL)
+		return NULL;
+
+#define SetFlag(flag) \
+	PyStructSequence_SET_ITEM(seq, pos++, PyLong_FromLong(flag))
+
+	SetFlag(Py_DebugFlag);
+	SetFlag(Py_DivisionWarningFlag);
+	SetFlag(Py_InspectFlag);
+	SetFlag(Py_InteractiveFlag);
+	SetFlag(Py_OptimizeFlag);
+	SetFlag(Py_DontWriteBytecodeFlag);
+	/* SetFlag(Py_NoUserSiteDirectory); */
+	SetFlag(Py_NoSiteFlag);
+	SetFlag(Py_IgnoreEnvironmentFlag);
+	SetFlag(Py_TabcheckFlag);
+	SetFlag(Py_VerboseFlag);
+#ifdef RISCOS
+	SetFlag(Py_RISCOSWimpFlag);
+#endif
+	/* SetFlag(saw_unbuffered_flag); */
+	/* SetFlag(skipfirstline); */
+#undef SetFlag
+
+	if (PyErr_Occurred()) {
+		return NULL;
+	}
+	return seq;
+}
+
 PyObject *
 _PySys_Init(void)
 {
@@ -1020,6 +1162,11 @@
 	if (m == NULL)
 		return NULL;
 	sysdict = PyModule_GetDict(m);
+#define SET_SYS_FROM_STRING(key, value)			\
+	v = value;					\
+	if (v != NULL)					\
+		PyDict_SetItemString(sysdict, key, v);	\
+	Py_XDECREF(v)
 
 	{
 		/* XXX: does this work on Win/Win64? (see posix_fstat) */
@@ -1033,22 +1180,22 @@
 		}
 	}
 
-        /* stdin/stdout/stderr are now set by site.py. */
+        /* stdin/stdout/stderr are now set by pythonrun.c */
 
 	PyDict_SetItemString(sysdict, "__displayhook__",
                              PyDict_GetItemString(sysdict, "displayhook"));
 	PyDict_SetItemString(sysdict, "__excepthook__",
                              PyDict_GetItemString(sysdict, "excepthook"));
-	PyDict_SetItemString(sysdict, "version",
-			     v = PyUnicode_FromString(Py_GetVersion()));
-	Py_XDECREF(v);
-	PyDict_SetItemString(sysdict, "hexversion",
-			     v = PyInt_FromLong(PY_VERSION_HEX));
-	Py_XDECREF(v);
+	SET_SYS_FROM_STRING("version",
+			     PyUnicode_FromString(Py_GetVersion()));
+	SET_SYS_FROM_STRING("hexversion",
+			     PyLong_FromLong(PY_VERSION_HEX));
 	svnversion_init();
-	v = Py_BuildValue("(UUU)", "CPython", branch, svn_revision);
-	PyDict_SetItemString(sysdict, "subversion", v);
-	Py_XDECREF(v);
+	SET_SYS_FROM_STRING("subversion",
+			    Py_BuildValue("(UUU)", "CPython", branch,
+					  svn_revision));
+	SET_SYS_FROM_STRING("dont_write_bytecode",
+			    PyBool_FromLong(Py_DontWriteBytecodeFlag));
 	/*
 	 * These release level checks are mutually exclusive and cover
 	 * the field, so don't get too fancy with the pre-processor!
@@ -1063,35 +1210,30 @@
 	s = "final";
 #endif
 
-#define SET_SYS_FROM_STRING(key, value)			\
-	v = value;					\
-	if (v != NULL)					\
-		PyDict_SetItemString(sysdict, key, v);	\
-	Py_XDECREF(v)
-
 	SET_SYS_FROM_STRING("version_info",
 			    Py_BuildValue("iiiUi", PY_MAJOR_VERSION,
 					       PY_MINOR_VERSION,
 					       PY_MICRO_VERSION, s,
 					       PY_RELEASE_SERIAL));
 	SET_SYS_FROM_STRING("api_version",
-			    PyInt_FromLong(PYTHON_API_VERSION));
+			    PyLong_FromLong(PYTHON_API_VERSION));
 	SET_SYS_FROM_STRING("copyright",
 			    PyUnicode_FromString(Py_GetCopyright()));
 	SET_SYS_FROM_STRING("platform",
 			    PyUnicode_FromString(Py_GetPlatform()));
 	SET_SYS_FROM_STRING("executable",
-			    PyUnicode_FromString(Py_GetProgramFullPath()));
+			    PyUnicode_DecodeFSDefault(
+				Py_GetProgramFullPath()));
 	SET_SYS_FROM_STRING("prefix",
-			    PyUnicode_FromString(Py_GetPrefix()));
+			    PyUnicode_DecodeFSDefault(Py_GetPrefix()));
 	SET_SYS_FROM_STRING("exec_prefix",
-		   	    PyUnicode_FromString(Py_GetExecPrefix()));
-	SET_SYS_FROM_STRING("maxint",
-			    PyInt_FromLong(PyInt_GetMax()));
+		   	    PyUnicode_DecodeFSDefault(Py_GetExecPrefix()));
 	SET_SYS_FROM_STRING("maxsize",
-			    PyInt_FromLong(PY_SSIZE_T_MAX));
+			    PyLong_FromSsize_t(PY_SSIZE_T_MAX));
+	SET_SYS_FROM_STRING("float_info",
+			    PyFloat_GetInfo());
 	SET_SYS_FROM_STRING("maxunicode",
-			    PyInt_FromLong(PyUnicode_GetMax()));
+			    PyLong_FromLong(PyUnicode_GetMax()));
 	SET_SYS_FROM_STRING("builtin_module_names",
 			    list_builtin_module_names());
 	{
@@ -1114,7 +1256,6 @@
 	SET_SYS_FROM_STRING("winver",
 			    PyUnicode_FromString(PyWin_DLLVersionString));
 #endif
-#undef SET_SYS_FROM_STRING
 	if (warnoptions == NULL) {
 		warnoptions = PyList_New(0);
 	}
@@ -1125,6 +1266,14 @@
 		PyDict_SetItemString(sysdict, "warnoptions", warnoptions);
 	}
 
+	if (FlagsType.tp_name == 0)
+		PyStructSequence_InitType(&FlagsType, &flags_desc);
+	SET_SYS_FROM_STRING("flags", make_flags());
+	/* prevent user from creating new instances */
+	FlagsType.tp_init = NULL;
+	FlagsType.tp_new = NULL;
+
+#undef SET_SYS_FROM_STRING
 	if (PyErr_Occurred())
 		return NULL;
 	return m;
@@ -1150,7 +1299,7 @@
 		p = strchr(path, delim);
 		if (p == NULL)
 			p = strchr(path, '\0'); /* End of string */
-		w = PyUnicode_FromStringAndSize(path, (Py_ssize_t) (p - path));
+		w = PyUnicode_DecodeFSDefaultAndSize(path, (Py_ssize_t) (p - path));
 		if (w == NULL) {
 			Py_DECREF(v);
 			return NULL;

Modified: python/branches/py3k-importlib/Python/thread.c
==============================================================================
--- python/branches/py3k-importlib/Python/thread.c	(original)
+++ python/branches/py3k-importlib/Python/thread.c	Thu Mar 27 00:48:05 2008
@@ -79,7 +79,7 @@
 PyThread_init_thread(void)
 {
 #ifdef Py_DEBUG
-	char *p = getenv("THREADDEBUG");
+	char *p = Py_GETENV("PYTHONTHREADDEBUG");
 
 	if (p) {
 		if (*p)

Modified: python/branches/py3k-importlib/Python/traceback.c
==============================================================================
--- python/branches/py3k-importlib/Python/traceback.c	(original)
+++ python/branches/py3k-importlib/Python/traceback.c	Thu Mar 27 00:48:05 2008
@@ -135,6 +135,8 @@
 	FILE *xfp;
 	char linebuf[2000];
 	int i;
+	char namebuf[MAXPATHLEN+1];
+
 	if (filename == NULL || name == NULL)
 		return -1;
 	/* This is needed by Emacs' compile command */
@@ -153,7 +155,6 @@
 			Py_ssize_t _npath = PyList_Size(path);
 			int npath = Py_SAFE_DOWNCAST(_npath, Py_ssize_t, int);
 			size_t taillen = strlen(tail);
-			char namebuf[MAXPATHLEN+1];
 			for (i = 0; i < npath; i++) {
 				PyObject *v = PyList_GetItem(path, i);
 				if (v == NULL) {
@@ -242,12 +243,15 @@
 	return err;
 }
 
+#define PyTraceBack_LIMIT 1000
+
 int
 PyTraceBack_Print(PyObject *v, PyObject *f)
 {
 	int err;
 	PyObject *limitv;
-	int limit = 1000;
+	int limit = PyTraceBack_LIMIT;
+
 	if (v == NULL)
 		return 0;
 	if (!PyTraceBack_Check(v)) {
@@ -255,10 +259,26 @@
 		return -1;
 	}
 	limitv = PySys_GetObject("tracebacklimit");
-	if (limitv && PyInt_CheckExact(limitv)) {
-		limit = PyInt_AsLong(limitv);
-		if (limit <= 0)
-			return 0;
+	if (limitv) {
+		PyObject *exc_type, *exc_value, *exc_tb;
+
+		PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
+		limit = PyLong_AsLong(limitv);
+		if (limit == -1 && PyErr_Occurred()) {
+			if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
+				limit = PyTraceBack_LIMIT;
+			}
+			else {
+				Py_XDECREF(exc_type);
+				Py_XDECREF(exc_value);
+				Py_XDECREF(exc_tb);
+				return 0;
+			}
+		}
+		else if (limit <= 0) {
+			limit = PyTraceBack_LIMIT;
+		}
+		PyErr_Restore(exc_type, exc_value, exc_tb);
 	}
 	err = PyFile_WriteString("Traceback (most recent call last):\n", f);
 	if (!err)

Modified: python/branches/py3k-importlib/README
==============================================================================
--- python/branches/py3k-importlib/README	(original)
+++ python/branches/py3k-importlib/README	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,10 @@
-This is Python version 3.0 alpha 1
+This is Python version 3.0 alpha 3
 ==================================
 
 For notes specific to this release, see RELNOTES in this directory.
+Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+Python Software Foundation.
+All rights reserved.
 
 Python 3000 (a.k.a. "Py3k", and released as Python 3.0) is a new
 version of the language, which is incompatible with the 2.x line of
@@ -11,8 +14,8 @@
 finally been removed.
 
 This is an ongoing project; the cleanup isn't expected to be complete
-until 2008.  In particular there are plans to reorganize the standard
-library namespace.
+until some time in 2008.  In particular there are plans to reorganize
+the standard library namespace.
 
 
 Release Schedule
@@ -51,8 +54,28 @@
 
     http://www.artima.com/weblogs/index.jsp?blogger=guido
 
-We'll eventually have a comprehensive overview of the changes in a
-"What's New in Python 3.0" document.  Please help write it!
+We try to eventually have a comprehensive overview of the changes in
+the "What's New in Python 3.0" document, found at
+
+    http://docs.python.org/dev/3.0/whatsnew/3.0
+
+Please help write it!
+
+If you want to install multiple versions of Python see the section below
+entitled "Installing multiple versions".
+
+
+What's New Since 3.0a1
+----------------------
+
+Undoubtedly the biggest change is in the bytes type: 'bytes' is now
+immutable, and there is a new mutable bytes type 'bytearray'.  These
+two types are interoperable in every way.  For more info on this
+issue, read PEP 3137.
+
+For a more detailed change log, read Misc/NEWS (though this file, too,
+is incomplete, and also doesn't list anything merged in from the 2.6
+release under development).
 
 
 Converting From Python 2.x to 3.0
@@ -63,6 +86,29 @@
 deprecated features are used, and backported versions of certain key
 Python 3000 features.
 
+
+Installing multiple versions
+----------------------------
+
+On Unix and Mac systems if you intend to install multiple versions of Python
+using the same installation prefix (--prefix argument to the configure
+script) you must take care that your primary python executable is not
+overwritten by the installation of a different versio.  All files and
+directories installed using "make altinstall" contain the major and minor
+version and can thus live side-by-side.  "make install" also creates
+${prefix}/bin/python which refers to ${prefix}/bin/pythonX.Y.  If you intend
+to install multiple versions using the same prefix you must decide which
+version (if any) is your "primary" version.  Install that version using
+"make install".  Install all other versions using "make altinstall".
+
+For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being
+the primary version, you would execute "make install" in your 2.6 build
+directory and "make altinstall" in the others.
+
+
+Configuration options and variables
+-----------------------------------
+
 A source-to-source translation tool, "2to3", can take care of the
 mundane task of converting large amounts of source code.  It is not a
 complete solution but is complemented by the deprecation warnings in
@@ -128,7 +174,7 @@
 Copyright and License Information
 ---------------------------------
 
-Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007 
+Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
 Python Software Foundation.
 All rights reserved.
 

Modified: python/branches/py3k-importlib/RELNOTES
==============================================================================
--- python/branches/py3k-importlib/RELNOTES	(original)
+++ python/branches/py3k-importlib/RELNOTES	Thu Mar 27 00:48:05 2008
@@ -5,6 +5,43 @@
 
 Please report bugs to http://bugs.python.org/.
 
+Version 3.0a2 - Release Date 07-Dec-2007
+----------------------------------------
+
+* The AMD64 Windows installer doesn't contain Tcl/Tk, and hence IDLE
+  won't work.  This is because Tcl doesn't compile at all on this
+  platform.
+
+* The 32bit build for the Win32/x86 platform is optimized with PGO
+  (profile guided optimization).  Please read Microsoft's docs for
+  `PGO
+  <http://msdn2.microsoft.com/en-us/library/e7k32f4k(VS.90).aspx>`_
+  if you are interested in details.  Preliminary benchmarks have shown
+  a speedup of about 10% in PyBench.  Real world applications may gain
+  more or less speedup.
+
+* The Tools directory contains a copy of the 2to3 conversion tool.
+  Note that 2to3 itself must be run with Python 2.5!
+
+* SSL support is back!  However, while the tests pass, the SSL code
+  appears to be leaking quite a bit, and there are still bugs.
+  We'll be working on this for the next release.
+
+* On Windows, Python can't be run from a directory with non ASCII chars
+  in its path name (`bug #1342 <http://bugs.python.org/issue1342>`_).
+
+* On Windows, the module doc server (pydocgui.pyw) is crashing.
+
+* On Windows, the menus in IDLE are broken.
+
+* The current releases of Cygwin and MinGW can't create extensions for
+  the official Python 3.0 binary.  The necessary modifications to
+  Cygwin are already in its CVS.  Look out for a new Cygwin release!
+
+* Otherwise, the 3.0a1 release notes below still apply, except hashlib
+  no longer requires openssl, and IDLE now seems fine (except on Windows).
+
+
 Version 3.0a1 - Release Date 31-Aug-2007
 ----------------------------------------
 

Modified: python/branches/py3k-importlib/Tools/bgen/bgen/bgenObjectDefinition.py
==============================================================================
--- python/branches/py3k-importlib/Tools/bgen/bgen/bgenObjectDefinition.py	(original)
+++ python/branches/py3k-importlib/Tools/bgen/bgen/bgenObjectDefinition.py	Thu Mar 27 00:48:05 2008
@@ -236,8 +236,8 @@
     def assertions(self):
         # Check that various things aren't overridden. If they are it could
         # signify a bgen-client that has been partially converted to PEP252.
-        assert self.outputGetattr.im_func == PEP252Mixin.outputGetattr.im_func
-        assert self.outputSetattr.im_func == PEP252Mixin.outputSetattr.im_func
+        assert self.outputGetattr.__func__ == PEP252Mixin.outputGetattr.__func__
+        assert self.outputSetattr.__func__ == PEP252Mixin.outputSetattr.__func__
         assert self.outputGetattrBody == None
         assert self.outputGetattrHook == None
         assert self.basechain == "NULL"

Modified: python/branches/py3k-importlib/Tools/buildbot/build-amd64.bat
==============================================================================
--- python/branches/py3k-importlib/Tools/buildbot/build-amd64.bat	(original)
+++ python/branches/py3k-importlib/Tools/buildbot/build-amd64.bat	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,6 @@
 @rem Used by the buildbot "compile" step.
-setlocal
 cmd /c Tools\buildbot\external-amd64.bat
-call "%VS71COMNTOOLS%vsvars32.bat"
+call "%VS90COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64
 REM cmd /q/c Tools\buildbot\kill_python.bat
-devenv.com /build ReleaseAMD64 PCbuild\pcbuild.sln
+cmd /c Tools\buildbot\clean-amd64.bat
+vcbuild PCbuild\pcbuild.sln "Debug|x64"

Modified: python/branches/py3k-importlib/Tools/buildbot/build.bat
==============================================================================
--- python/branches/py3k-importlib/Tools/buildbot/build.bat	(original)
+++ python/branches/py3k-importlib/Tools/buildbot/build.bat	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,7 @@
 @rem Used by the buildbot "compile" step.
 cmd /c Tools\buildbot\external.bat
-call "%VS71COMNTOOLS%vsvars32.bat"
+call "%VS90COMNTOOLS%vsvars32.bat"
 cmd /q/c Tools\buildbot\kill_python.bat
-devenv.com /useenv /build Debug PCbuild\pcbuild.sln
+cmd /c Tools\buildbot\clean.bat
+vcbuild /useenv PCbuild\pcbuild.sln "Debug|Win32"
+

Modified: python/branches/py3k-importlib/Tools/buildbot/buildmsi.bat
==============================================================================
--- python/branches/py3k-importlib/Tools/buildbot/buildmsi.bat	(original)
+++ python/branches/py3k-importlib/Tools/buildbot/buildmsi.bat	Thu Mar 27 00:48:05 2008
@@ -2,14 +2,14 @@
 
 cmd /c Tools\buildbot\external.bat
 @rem build release versions of things
-call "%VS71COMNTOOLS%vsvars32.bat"
+call "%VS90COMNTOOLS%vsvars32.bat"
 if not exist ..\db-4.4.20\build_win32\release\libdb44s.lib (
-   devenv ..\db-4.4.20\build_win32\Berkeley_DB.sln /build Release /project db_static
+  vcbuild db-4.4.20\build_win32\Berkeley_DB.sln /build Release /project db_static
 )
 
 @rem build Python
 cmd /q/c Tools\buildbot\kill_python.bat
-devenv.com /useenv /build Release PCbuild\pcbuild.sln
+vcbuild /useenv PCbuild\pcbuild.sln "Release|Win32"
 
 @rem build the documentation
 bash.exe -c 'cd Doc;make PYTHON=python2.5 update htmlhelp'

Modified: python/branches/py3k-importlib/Tools/buildbot/clean-amd64.bat
==============================================================================
--- python/branches/py3k-importlib/Tools/buildbot/clean-amd64.bat	(original)
+++ python/branches/py3k-importlib/Tools/buildbot/clean-amd64.bat	Thu Mar 27 00:48:05 2008
@@ -1,6 +1,7 @@
 @rem Used by the buildbot "clean" step.
-call "%VS71COMNTOOLS%vsvars32.bat"
+call "%VS90COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64
 cd PCbuild
 @echo Deleting .pyc/.pyo files ...
-python.exe rmpyc.py
-devenv.com /clean ReleaseAMD64 pcbuild.sln
+del /s Lib\*.pyc Lib\*.pyo
+vcbuild /clean pcbuild.sln "Release|x64"
+vcbuild /clean pcbuild.sln "Debug|x64"

Modified: python/branches/py3k-importlib/Tools/buildbot/clean.bat
==============================================================================
--- python/branches/py3k-importlib/Tools/buildbot/clean.bat	(original)
+++ python/branches/py3k-importlib/Tools/buildbot/clean.bat	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,7 @@
 @rem Used by the buildbot "clean" step.
-call "%VS71COMNTOOLS%vsvars32.bat"
-cd PCbuild
+call "%VS90COMNTOOLS%vsvars32.bat"
 @echo Deleting .pyc/.pyo files ...
-python_d.exe rmpyc.py
-devenv.com /clean Release pcbuild.sln
-devenv.com /clean Debug pcbuild.sln
+del /s Lib\*.pyc Lib\*.pyo
+cd PCbuild
+vcbuild /clean pcbuild.sln "Release|Win32"
+vcbuild /clean pcbuild.sln "Debug|Win32"

Modified: python/branches/py3k-importlib/Tools/buildbot/external-amd64.bat
==============================================================================
--- python/branches/py3k-importlib/Tools/buildbot/external-amd64.bat	(original)
+++ python/branches/py3k-importlib/Tools/buildbot/external-amd64.bat	Thu Mar 27 00:48:05 2008
@@ -1,50 +1,17 @@
 @rem Fetches (and builds if necessary) external dependencies
-setlocal
-
- at rem need this so that 'devenv' is found
-call "%VS71COMNTOOLS%vsvars32.bat"
- at rem set the build environment
-call "%MSSdk%\SetEnv" /XP64 /RETAIL
 
 @rem Assume we start inside the Python source directory
-for %%i in (.) do set CWD=%%~fi
-cd ..
-
- at rem sqlite
-if not exist sqlite-source-3.3.4 (
-   svn export http://svn.python.org/projects/external/sqlite-source-3.3.4
-   if exist %CWD%\PCbuild\sqlite3.dll del %CWD%\PCbuild\sqlite3.dll
-)
-if not exist %CWD%\PCbuild\sqlite3.dll (
-   cd sqlite-source-3.3.4\amd64
-   cl ..\*.c
-   link /def:..\sqlite3.def  /dll *.obj /out:sqlite3.dll bufferoverflowU.lib
-   cd ..\..
-   copy sqlite-source-3.3.4\amd64\sqlite3.dll %CWD%\PCbuild
-)
+call "Tools\buildbot\external-common.bat"
+call "%VS90COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64
 
- at rem bzip
-if not exist bzip2-1.0.3 svn export http://svn.python.org/projects/external/bzip2-1.0.3
-if not exist bzip2-1.0.3\libbz2.lib (
-   cd bzip2-1.0.3
-   nmake /f makefile.msc CFLAGS="-DWIN32 -MD -Ox -D_FILE_OFFSET_BITS=64 -nologo /GS-"
-   cd ..
+if not exist tcltk64\bin\tcl84g.dll (
+    cd tcl-8.4.18.2\win
+    nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
+    cd ..\..
 )
 
- at rem Sleepycat db
-if not exist db-4.4.20 svn export http://svn.python.org/projects/external/db-4.4.20
-if not exist "db-4.4.20\build_win32\Release_AMD64\libdb44s.lib" (
-   cd db-4.4.20\build_win32
-   devenv Berkeley_DB.sln /build "Release AMD64" /project db_static /useenv
-   cd ..\..
-)
-
- at rem OpenSSL
-if not exist openssl-0.9.8a svn export http://svn.python.org/projects/external/openssl-0.9.8a
-
- at rem tcltk
-if not exist tcl8.4.12 (
-   if exist tcltk rd /s/q tcltk
-   svn export http://svn.python.org/projects/external/tcl8.4.12
-   svn export http://svn.python.org/projects/external/tk8.4.12
+if not exist tcltk64\bin\tk84g.dll (
+    cd tk-8.4.18.1\win    
+    nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 TCLDIR=..\..\tcl-8.4.18.2 clean all install
+    cd ..\..
 )

Modified: python/branches/py3k-importlib/Tools/buildbot/external.bat
==============================================================================
--- python/branches/py3k-importlib/Tools/buildbot/external.bat	(original)
+++ python/branches/py3k-importlib/Tools/buildbot/external.bat	Thu Mar 27 00:48:05 2008
@@ -1,36 +1,17 @@
 @rem Fetches (and builds if necessary) external dependencies
 
 @rem Assume we start inside the Python source directory
-cd ..
-call "%VS71COMNTOOLS%vsvars32.bat"
+call "Tools\buildbot\external-common.bat"
+call "%VS90COMNTOOLS%\vsvars32.bat"
 
- at rem bzip
-if not exist bzip2-1.0.3 svn export http://svn.python.org/projects/external/bzip2-1.0.3
-
- at rem Sleepycat db
-if not exist db-4.4.20 svn export http://svn.python.org/projects/external/db-4.4.20
-if not exist db-4.4.20\build_win32\debug\libdb44sd.lib (
-   devenv db-4.4.20\build_win32\Berkeley_DB.sln /build Debug /project db_static
+if not exist tcltk\bin\tcl84g.dll (
+    cd tcl-8.4.18.2\win
+    nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 DEBUG=1 INSTALLDIR=..\..\tcltk clean all install
+    cd ..\..
 )
 
- at rem OpenSSL
-if not exist openssl-0.9.8a svn export http://svn.python.org/projects/external/openssl-0.9.8a
-
- at rem tcltk
-if not exist tcl8.4.12 (
-   if exist tcltk rd /s/q tcltk
-   svn export http://svn.python.org/projects/external/tcl8.4.12
-   svn export http://svn.python.org/projects/external/tk8.4.12
-   cd tcl8.4.12\win
-   nmake -f makefile.vc
-   nmake -f makefile.vc INSTALLDIR=..\..\tcltk install
-   cd ..\..
-   cd tk8.4.12\win
-   nmake -f makefile.vc TCLDIR=..\..\tcl8.4.12
-   nmake -f makefile.vc TCLDIR=..\..\tcl8.4.12 INSTALLDIR=..\..\tcltk install
-   cd ..\..
+if not exist tcltk\bin\tk84g.dll (
+    cd tk-8.4.18.1\win    
+    nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 DEBUG=1 INSTALLDIR=..\..\tcltk TCLDIR=..\..\tcl-8.4.18.2 clean all install
+    cd ..\..
 )
-
- at rem sqlite
-if not exist sqlite-source-3.3.4 svn export http://svn.python.org/projects/external/sqlite-source-3.3.4
-if not exist build\PCbuild\sqlite3.dll copy sqlite-source-3.3.4\sqlite3.dll build\PCbuild

Modified: python/branches/py3k-importlib/Tools/buildbot/kill_python.c
==============================================================================
--- python/branches/py3k-importlib/Tools/buildbot/kill_python.c	(original)
+++ python/branches/py3k-importlib/Tools/buildbot/kill_python.c	Thu Mar 27 00:48:05 2008
@@ -53,7 +53,7 @@
 		   PCbuild\\python.exe which could be a normal instance
 		   of Python running on vanilla Windows.
 		*/
-		if ((strstr(path, "build\\pcbuild\\python_d.exe") != NULL) ||
+		if ((strstr(path, "pcbuild\\python_d.exe") != NULL) ||
 		    (strstr(path, "\\build\\python.exe") != NULL)) {
 			printf("Terminating %s (pid %d)\n", path, pids[i]);
 			if (!TerminateProcess(hProcess, 1)) {

Modified: python/branches/py3k-importlib/Tools/buildbot/test-amd64.bat
==============================================================================
--- python/branches/py3k-importlib/Tools/buildbot/test-amd64.bat	(original)
+++ python/branches/py3k-importlib/Tools/buildbot/test-amd64.bat	Thu Mar 27 00:48:05 2008
@@ -1,3 +1,3 @@
 @rem Used by the buildbot "test" step.
 cd PCbuild
-call rt.bat -q -uall -rw
+call rt.bat -q -d -x64 -uall -rw

Modified: python/branches/py3k-importlib/Tools/faqwiz/faqw.py
==============================================================================
--- python/branches/py3k-importlib/Tools/faqwiz/faqw.py	(original)
+++ python/branches/py3k-importlib/Tools/faqwiz/faqw.py	Thu Mar 27 00:48:05 2008
@@ -20,7 +20,7 @@
 try:
     FAQDIR = "/usr/people/guido/python/FAQ"
     SRCDIR = "/usr/people/guido/python/src/Tools/faqwiz"
-    import os, sys, time, operator
+    import os, sys
     os.chdir(FAQDIR)
     sys.path.insert(0, SRCDIR)
     import faqwiz

Modified: python/branches/py3k-importlib/Tools/freeze/makeconfig.py
==============================================================================
--- python/branches/py3k-importlib/Tools/freeze/makeconfig.py	(original)
+++ python/branches/py3k-importlib/Tools/freeze/makeconfig.py	Thu Mar 27 00:48:05 2008
@@ -3,7 +3,7 @@
 
 # Write the config.c file
 
-never = ['marshal', '__main__', '__builtin__', 'sys', 'exceptions']
+never = ['marshal', '__main__', 'builtins', 'sys', 'exceptions']
 
 def makeconfig(infp, outfp, modules, with_ifdef=0):
     m1 = re.compile('-- ADDMODULE MARKER 1 --')

Modified: python/branches/py3k-importlib/Tools/i18n/pygettext.py
==============================================================================
--- python/branches/py3k-importlib/Tools/i18n/pygettext.py	(original)
+++ python/branches/py3k-importlib/Tools/i18n/pygettext.py	Thu Mar 27 00:48:05 2008
@@ -453,11 +453,9 @@
         # sort all the entries by their first item.
         reverse = {}
         for k, v in self.__messages.items():
-            keys = v.keys()
-            keys.sort()
+            keys = sorted(v.keys())
             reverse.setdefault(tuple(keys), []).append((k, v))
-        rkeys = reverse.keys()
-        rkeys.sort()
+        rkeys = sorted(reverse.keys())
         for rkey in rkeys:
             rentries = reverse[rkey]
             rentries.sort()
@@ -469,8 +467,7 @@
                 # k is the message string, v is a dictionary-set of (filename,
                 # lineno) tuples.  We want to sort the entries in v first by
                 # file name and then by line number.
-                v = v.keys()
-                v.sort()
+                v = sorted(v.keys())
                 if not options.writelocations:
                     pass
                 # location comments are different b/w Solaris and GNU:
@@ -634,10 +631,13 @@
         try:
             eater.set_filename(filename)
             try:
-                tokenize.tokenize(fp.readline, eater)
+                tokens = tokenize.generate_tokens(fp.readline)
+                for _token in tokens:
+                    eater(*_token)
             except tokenize.TokenError as e:
                 print('%s: %s, line %d, column %d' % (
-                    e[0], filename, e[1][0], e[1][1]), file=sys.stderr)
+                    e.args[0], filename, e.args[1][0], e.args[1][1]),
+                    file=sys.stderr)
         finally:
             if closep:
                 fp.close()
@@ -661,7 +661,6 @@
 if __name__ == '__main__':
     main()
     # some more test strings
-    _(u'a unicode string')
     # this one creates a warning
     _('*** Seen unexpected token "%(token)s"') % {'token': 'test'}
     _('more' 'than' 'one' 'string')

Modified: python/branches/py3k-importlib/Tools/modulator/Tkextra.py
==============================================================================
--- python/branches/py3k-importlib/Tools/modulator/Tkextra.py	(original)
+++ python/branches/py3k-importlib/Tools/modulator/Tkextra.py	Thu Mar 27 00:48:05 2008
@@ -218,7 +218,6 @@
                   0, 'Save', 'Save as text'))
 
 def _test():
-    import sys
     global mainWidget
     mainWidget = Frame()
     Pack.config(mainWidget)

Modified: python/branches/py3k-importlib/Tools/msi/msi.py
==============================================================================
--- python/branches/py3k-importlib/Tools/msi/msi.py	(original)
+++ python/branches/py3k-importlib/Tools/msi/msi.py	Thu Mar 27 00:48:05 2008
@@ -1,7 +1,7 @@
 # Python MSI Generator
 # (C) 2003 Martin v. Loewis
 # See "FOO" in comments refers to MSDN sections with the title FOO.
-import msilib, schema, sequence, os, glob, time, re
+import msilib, schema, sequence, os, glob, time, re, shutil
 from msilib import Feature, CAB, Directory, Dialog, Binary, add_data
 import uisample
 from win32com.client import constants
@@ -26,6 +26,11 @@
 have_tcl = True
 # Where is sqlite3.dll located, relative to srcdir?
 sqlite_dir = "../sqlite-source-3.3.4"
+# path to PCbuild directory
+PCBUILD="PCbuild"
+# msvcrt version
+#MSVCR = "71"
+MSVCR = "90"
 
 try:
     from config import *
@@ -100,7 +105,9 @@
 # from 1 to 2 (due to what I consider a bug in MSI)
 # Using the same UUID is fine since these files are versioned,
 # so Installer will always keep the newest version.
+# NOTE: All uuids are self generated.
 msvcr71_uuid = "{8666C8DD-D0B4-4B42-928E-A69E32FA5D4D}"
+msvcr90_uuid = "{9C28CD84-397C-4045-855C-28B02291A272}"
 pythondll_uuid = {
     "24":"{9B81E618-2301-4035-AC77-75D9ABEB7301}",
     "25":"{2e41b118-38bd-4c1b-a840-6977efd1b911}",
@@ -147,15 +154,15 @@
     return True
 
 # Target files (.def and .a) go in PCBuild directory
-lib_file = os.path.join(srcdir, "PCBuild", "python%s%s.lib" % (major, minor))
-def_file = os.path.join(srcdir, "PCBuild", "python%s%s.def" % (major, minor))
+lib_file = os.path.join(srcdir, PCBUILD, "python%s%s.lib" % (major, minor))
+def_file = os.path.join(srcdir, PCBUILD, "python%s%s.def" % (major, minor))
 dll_file = "python%s%s.dll" % (major, minor)
-mingw_lib = os.path.join(srcdir, "PCBuild", "libpython%s%s.a" % (major, minor))
+mingw_lib = os.path.join(srcdir, PCBUILD, "libpython%s%s.a" % (major, minor))
 
 have_mingw = build_mingw_lib(lib_file, def_file, dll_file, mingw_lib)
 
 # Determine the target architechture
-dll_path = os.path.join(srcdir, "PCBuild", dll_file)
+dll_path = os.path.join(srcdir, PCBUILD, dll_file)
 msilib.set_arch_from_file(dll_path)
 if msilib.pe_type(dll_path) != msilib.pe_type("msisupport.dll"):
     raise SystemError("msisupport.dll for incorrect architecture")
@@ -327,7 +334,7 @@
     if not os.path.exists(srcdir+r"\PC\python_icon.exe"):
         raise "Run icons.mak in PC directory"
     add_data(db, "Binary",
-             [("PythonWin", msilib.Binary(srcdir+r"\PCbuild\installer.bmp")), # 152x328 pixels
+             [("PythonWin", msilib.Binary(r"%s\PCbuild\installer.bmp" % srcdir)), # 152x328 pixels
               ("py.ico",msilib.Binary(srcdir+r"\PC\py.ico")),
              ])
     add_data(db, "Icon",
@@ -817,7 +824,7 @@
     dir = _winreg.QueryValueEx(k, "MSMDir")[0]
     _winreg.CloseKey(k)
     files = glob.glob1(dir, "*CRT71*")
-    assert len(files) == 1
+    assert len(files) == 1, (dir, files)
     file = os.path.join(dir, files[0])
     # Extract msvcr71.dll
     m = msilib.MakeMerge2()
@@ -829,6 +836,23 @@
     return installer.FileVersion("msvcr71.dll", 0), \
            installer.FileVersion("msvcr71.dll", 1)
 
+def extract_msvcr90():
+    # Find the redistributable files
+    dir = os.path.join(os.environ['VS90COMNTOOLS'], r"..\..\VC\redist\x86\Microsoft.VC90.CRT")
+
+    result = []
+    installer = msilib.MakeInstaller()
+    # omit msvcm90 and msvcp90, as they aren't really needed
+    files = ["Microsoft.VC90.CRT.manifest", "msvcr90.dll"]
+    for f in files:
+        path = os.path.join(dir, f)
+        kw = {'src':path}
+        if f.endswith('.dll'):
+            kw['version'] = installer.FileVersion(path, 0)
+            kw['language'] = installer.FileVersion(path, 1)
+        result.append((f, kw))
+    return result
+
 class PyDirectory(Directory):
     """By default, all components in the Python installer
     can run from source."""
@@ -846,19 +870,22 @@
     root = PyDirectory(db, cab, None, srcdir, "TARGETDIR", "SourceDir")
     default_feature.set_current()
     if not msilib.Win64:
-        root.add_file("PCBuild/w9xpopen.exe")
+        root.add_file("%s/w9xpopen.exe" % PCBUILD)
     root.add_file("README.txt", src="README")
     root.add_file("NEWS.txt", src="Misc/NEWS")
     root.add_file("LICENSE.txt", src="LICENSE")
     root.start_component("python.exe", keyfile="python.exe")
-    root.add_file("PCBuild/python.exe")
+    root.add_file("%s/python.exe" % PCBUILD)
     root.start_component("pythonw.exe", keyfile="pythonw.exe")
-    root.add_file("PCBuild/pythonw.exe")
+    root.add_file("%s/pythonw.exe" % PCBUILD)
 
     # msidbComponentAttributesSharedDllRefCount = 8, see "Component Table"
-    dlldir = PyDirectory(db, cab, root, srcdir, "DLLDIR", ".")
+    #dlldir = PyDirectory(db, cab, root, srcdir, "DLLDIR", ".")
+    #install python30.dll into root dir for now
+    dlldir = root
+
     pydll = "python%s%s.dll" % (major, minor)
-    pydllsrc = srcdir + "/PCBuild/" + pydll
+    pydllsrc = os.path.join(srcdir, PCBUILD, pydll)
     dlldir.start_component("DLLDIR", flags = 8, keyfile = pydll, uuid = pythondll_uuid)
     installer = msilib.MakeInstaller()
     pyversion = installer.FileVersion(pydllsrc, 0)
@@ -866,18 +893,28 @@
         # For releases, the Python DLL has the same version as the
         # installer package.
         assert pyversion.split(".")[:3] == current_version.split(".")
-    dlldir.add_file("PCBuild/python%s%s.dll" % (major, minor),
+    dlldir.add_file("%s/python%s%s.dll" % (PCBUILD, major, minor),
                     version=pyversion,
                     language=installer.FileVersion(pydllsrc, 1))
+    DLLs = PyDirectory(db, cab, root, srcdir + "/" + PCBUILD, "DLLs", "DLLS|DLLs")
     # XXX determine dependencies
-    version, lang = extract_msvcr71()
-    dlldir.start_component("msvcr71", flags=8, keyfile="msvcr71.dll", uuid=msvcr71_uuid)
-    dlldir.add_file("msvcr71.dll", src=os.path.abspath("msvcr71.dll"),
-                    version=version, language=lang)
-    tmpfiles.append("msvcr71.dll")
+    if MSVCR == "90":
+        root.start_component("msvcr90")
+        for file, kw in extract_msvcr90():
+            root.add_file(file, **kw)
+            if file.endswith("manifest"):
+                DLLs.add_file(file, **kw)
+    else:
+        version, lang = extract_msvcr71()
+        dlldir.start_component("msvcr71", flags=8, keyfile="msvcr71.dll",
+                               uuid=msvcr71_uuid)
+        dlldir.add_file("msvcr71.dll", src=os.path.abspath("msvcr71.dll"),
+                        version=version, language=lang)
+        tmpfiles.append("msvcr71.dll")
+
 
     # Check if _ctypes.pyd exists
-    have_ctypes = os.path.exists(srcdir+"/PCBuild/_ctypes.pyd")
+    have_ctypes = os.path.exists(srcdir+"/%s/_ctypes.pyd" % PCBUILD)
     if not have_ctypes:
         print("WARNING: _ctypes.pyd not found, ctypes will not be included")
         extensions.remove("_ctypes.pyd")
@@ -933,6 +970,8 @@
             lib.add_file("check_soundcard.vbs")
             lib.add_file("empty.vbs")
             lib.glob("*.uue")
+            lib.glob("*.pem")
+            lib.glob("*.pck")
             lib.add_file("readme.txt", src="README")
         if dir=='decimaltestdata':
             lib.glob("*.decTest")
@@ -945,8 +984,10 @@
             lib.glob("*.gif")
             lib.add_file("idle.icns")
         if dir=="command" and parent.physical=="distutils":
-            lib.add_file("wininst-6.exe")
+            lib.add_file("wininst-6.0.exe")
             lib.add_file("wininst-7.1.exe")
+            lib.add_file("wininst-8.0.exe")
+            lib.add_file("wininst-9.0.exe")
         if dir=="setuptools":
             lib.add_file("cli.exe")
             lib.add_file("gui.exe")
@@ -963,15 +1004,15 @@
                 pydirs.append((lib, f))
     # Add DLLs
     default_feature.set_current()
-    lib = PyDirectory(db, cab, root, srcdir+"/PCBuild", "DLLs", "DLLS|DLLs")
-    lib.add_file("py.ico", src="../PC/py.ico")
-    lib.add_file("pyc.ico", src="../PC/pyc.ico")
+    lib = DLLs
+    lib.add_file("py.ico", src=srcdir+"/PC/py.ico")
+    lib.add_file("pyc.ico", src=srcdir+"/PC/pyc.ico")
     dlls = []
     tclfiles = []
     for f in extensions:
         if f=="_tkinter.pyd":
             continue
-        if not os.path.exists(srcdir+"/PCBuild/"+f):
+        if not os.path.exists(srcdir + "/" + PCBUILD + "/" + f):
             print("WARNING: Missing extension", f)
             continue
         dlls.append(f)
@@ -981,21 +1022,23 @@
         sqlite_arch = "/ia64"
     elif msilib.msi_type=="x64;1033":
         sqlite_arch = "/amd64"
+        tclsuffix = "64"
     else:
         sqlite_arch = ""
+        tclsuffix = ""
     lib.add_file(srcdir+"/"+sqlite_dir+sqlite_arch+"/sqlite3.dll")
     if have_tcl:
-        if not os.path.exists(srcdir+"/PCBuild/_tkinter.pyd"):
+        if not os.path.exists("%s/%s/_tkinter.pyd" % (srcdir, PCBUILD)):
             print("WARNING: Missing _tkinter.pyd")
         else:
             lib.start_component("TkDLLs", tcltk)
             lib.add_file("_tkinter.pyd")
             dlls.append("_tkinter.pyd")
-            tcldir = os.path.normpath(srcdir+"/../tcltk/bin")
+            tcldir = os.path.normpath(srcdir+("/../tcltk%s/bin" % tclsuffix))
             for f in glob.glob1(tcldir, "*.dll"):
                 lib.add_file(f, src=os.path.join(tcldir, f))
     # check whether there are any unknown extensions
-    for f in glob.glob1(srcdir+"/PCBuild", "*.pyd"):
+    for f in glob.glob1(srcdir+"/"+PCBUILD, "*.pyd"):
         if f.endswith("_d.pyd"): continue # debug version
         if f in dlls: continue
         print("WARNING: Unknown extension", f)
@@ -1006,7 +1049,7 @@
     lib.glob("*.h")
     lib.add_file("pyconfig.h", src="../PC/pyconfig.h")
     # Add import libraries
-    lib = PyDirectory(db, cab, root, "PCBuild", "libs", "LIBS|libs")
+    lib = PyDirectory(db, cab, root, PCBUILD, "libs", "LIBS|libs")
     for f in dlls:
         lib.add_file(f.replace('pyd','lib'))
     lib.add_file('python%s%s.lib' % (major, minor))
@@ -1015,7 +1058,7 @@
         lib.add_file('libpython%s%s.a' % (major, minor))
     if have_tcl:
         # Add Tcl/Tk
-        tcldirs = [(root, '../tcltk/lib', 'tcl')]
+        tcldirs = [(root, '../tcltk%s/lib' % tclsuffix, 'tcl')]
         tcltk.set_current()
         while tcldirs:
             parent, phys, dir = tcldirs.pop()

Modified: python/branches/py3k-importlib/Tools/msi/msilib.py
==============================================================================
--- python/branches/py3k-importlib/Tools/msi/msilib.py	(original)
+++ python/branches/py3k-importlib/Tools/msi/msilib.py	Thu Mar 27 00:48:05 2008
@@ -376,14 +376,19 @@
         except OSError:
             pass
         for k, v in [(r"Software\Microsoft\VisualStudio\7.1\Setup\VS", "VS7CommonBinDir"),
-                     (r"Software\Microsoft\Win32SDK\Directories", "Install Dir")]:
+                     (r"Software\Microsoft\VisualStudio\8.0\Setup\VS", "VS7CommonBinDir"),
+                     (r"Software\Microsoft\VisualStudio\9.0\Setup\VS", "VS7CommonBinDir"),
+                     (r"Software\Microsoft\Win32SDK\Directories", "Install Dir"),
+                    ]:
             try:
                 key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, k)
-            except WindowsError:
+                dir = _winreg.QueryValueEx(key, v)[0]
+                _winreg.CloseKey(key)
+            except (WindowsError, IndexError):
+                continue
+            cabarc = os.path.join(dir, r"Bin", "cabarc.exe")
+            if not os.path.exists(cabarc):
                 continue
-            cabarc = os.path.join(_winreg.QueryValueEx(key, v)[0], r"Bin", "cabarc.exe")
-            _winreg.CloseKey(key)
-            if not os.path.exists(cabarc):continue
             break
         else:
             print("WARNING: cabarc.exe not found in registry")

Modified: python/branches/py3k-importlib/Tools/msi/uuids.py
==============================================================================
--- python/branches/py3k-importlib/Tools/msi/uuids.py	(original)
+++ python/branches/py3k-importlib/Tools/msi/uuids.py	Thu Mar 27 00:48:05 2008
@@ -37,6 +37,10 @@
     '2.5.1150':'{31800004-6386-4999-a519-518f2d78d8f0}', # 2.5.1
     '2.5.2150':'{6304a7da-1132-4e91-a343-a296269eab8a}', # 2.5.2c1
     '2.5.2150':'{6b976adf-8ae8-434e-b282-a06c7f624d2f}', # 2.5.2
+    '2.6.101': '{0ba82e1b-52fd-4e03-8610-a6c76238e8a8}', # 2.6a1
+    '2.6.102': '{3b27e16c-56db-4570-a2d3-e9a26180c60b}', # 2.6a2
+    '2.6.103': '{cd06a9c5-bde5-4bd7-9874-48933997122a}', # 2.6a3
+    '2.6.104': '{dc6ed634-474a-4a50-a547-8de4b7491e53}', # 2.6a4
     '3.0.101': '{8554263a-3242-4857-9359-aa87bc2c58c2}', # 3.0a1
     '3.0.102': '{692d6e2c-f0ac-40b8-a133-7191aeeb67f9}', # 3.0a2
     '3.0.103': '{49cb2995-751a-4753-be7a-d0b1bb585e06}', # 3.0a3

Modified: python/branches/py3k-importlib/Tools/pybench/Setup.py
==============================================================================
--- python/branches/py3k-importlib/Tools/pybench/Setup.py	(original)
+++ python/branches/py3k-importlib/Tools/pybench/Setup.py	Thu Mar 27 00:48:05 2008
@@ -30,6 +30,10 @@
 from Tuples import *
 from Dict import *
 from Exceptions import *
+try:
+    from With import *
+except SyntaxError:
+    pass
 from Imports import *
 from Strings import *
 from Numbers import *

Modified: python/branches/py3k-importlib/Tools/pybench/pybench.py
==============================================================================
--- python/branches/py3k-importlib/Tools/pybench/pybench.py	(original)
+++ python/branches/py3k-importlib/Tools/pybench/pybench.py	Thu Mar 27 00:48:05 2008
@@ -121,7 +121,8 @@
         'platform': platform.platform(),
         'processor': platform.processor(),
         'executable': sys.executable,
-        'implementation': platform.python_implementation(),
+        'implementation': getattr(platform, 'python_implementation',
+                                  lambda:'n/a')(),
         'python': platform.python_version(),
         'compiler': platform.python_compiler(),
         'buildno': buildno,
@@ -833,7 +834,7 @@
         print('PYBENCH %s' % __version__)
         print('-' * LINE)
         print('* using %s %s' % (
-            platform.python_implementation(),
+            getattr(platform, 'python_implementation', lambda:'Python')(),
             ' '.join(sys.version.split())))
 
         # Switch off garbage collection

Modified: python/branches/py3k-importlib/Tools/pybench/systimes.py
==============================================================================
--- python/branches/py3k-importlib/Tools/pybench/systimes.py	(original)
+++ python/branches/py3k-importlib/Tools/pybench/systimes.py	Thu Mar 27 00:48:05 2008
@@ -31,7 +31,7 @@
     the author. All Rights Reserved.
 
 """
-import time, sys, struct
+import time, sys
 
 #
 # Note: Please keep this module compatible to Python 1.5.2.

Modified: python/branches/py3k-importlib/Tools/pynche/ChipViewer.py
==============================================================================
--- python/branches/py3k-importlib/Tools/pynche/ChipViewer.py	(original)
+++ python/branches/py3k-importlib/Tools/pynche/ChipViewer.py	Thu Mar 27 00:48:05 2008
@@ -13,7 +13,6 @@
 selected and nearest ChipWidgets.
 """
 
-from types import StringType
 from Tkinter import *
 import ColorDB
 

Modified: python/branches/py3k-importlib/Tools/pynche/ColorDB.py
==============================================================================
--- python/branches/py3k-importlib/Tools/pynche/ColorDB.py	(original)
+++ python/branches/py3k-importlib/Tools/pynche/ColorDB.py	Thu Mar 27 00:48:05 2008
@@ -50,10 +50,7 @@
         self.__byname = {}
         # all unique names (non-aliases).  built-on demand
         self.__allnames = None
-        while 1:
-            line = fp.readline()
-            if not line:
-                break
+        for line in fp:
             # get this compiled regular expression from derived class
             mo = self._re.match(line)
             if not mo:
@@ -125,10 +122,7 @@
             self.__allnames = []
             for name, aliases in self.__byrgb.values():
                 self.__allnames.append(name)
-            # sort irregardless of case
-            def nocase_cmp(n1, n2):
-                return cmp(n1.lower(), n2.lower())
-            self.__allnames.sort(nocase_cmp)
+            self.__allnames.sort(key=unicode.lower)
         return self.__allnames
 
     def aliases_of(self, red, green, blue):

Modified: python/branches/py3k-importlib/Tools/pynche/TypeinViewer.py
==============================================================================
--- python/branches/py3k-importlib/Tools/pynche/TypeinViewer.py	(original)
+++ python/branches/py3k-importlib/Tools/pynche/TypeinViewer.py	Thu Mar 27 00:48:05 2008
@@ -12,8 +12,6 @@
 you must hit Return or Tab to select the color.
 """
 
-import sys
-import re
 from Tkinter import *
 
 

Modified: python/branches/py3k-importlib/Tools/scripts/checkappend.py
==============================================================================
--- python/branches/py3k-importlib/Tools/scripts/checkappend.py	(original)
+++ python/branches/py3k-importlib/Tools/scripts/checkappend.py	Thu Mar 27 00:48:05 2008
@@ -103,7 +103,9 @@
 
     def run(self):
         try:
-            tokenize.tokenize(self.file.readline, self.tokeneater)
+            tokens = tokenize.generate_tokens(self.file.readline)
+            for _token in tokens:
+                self.tokeneater(*_token)
         except tokenize.TokenError as msg:
             errprint("%r: Token Error: %s" % (self.fname, msg))
             self.nerrors = self.nerrors + 1

Modified: python/branches/py3k-importlib/Tools/scripts/combinerefs.py
==============================================================================
--- python/branches/py3k-importlib/Tools/scripts/combinerefs.py	(original)
+++ python/branches/py3k-importlib/Tools/scripts/combinerefs.py	Thu Mar 27 00:48:05 2008
@@ -86,7 +86,8 @@
             break
 
 def combine(fname):
-    f = file(fname)
+    f = open(fname)
+
     fi = iter(f)
 
     for line in read(fi, re.compile(r'^Remaining objects:$'), False):

Modified: python/branches/py3k-importlib/Tools/scripts/finddiv.py
==============================================================================
--- python/branches/py3k-importlib/Tools/scripts/finddiv.py	(original)
+++ python/branches/py3k-importlib/Tools/scripts/finddiv.py	Thu Mar 27 00:48:05 2008
@@ -78,7 +78,7 @@
         fn = os.path.join(dir, name)
         if os.path.normcase(fn).endswith(".py") or os.path.isdir(fn):
             files.append(fn)
-    files.sort(lambda a, b: cmp(os.path.normcase(a), os.path.normcase(b)))
+    files.sort(key=os.path.normcase)
     exit = None
     for fn in files:
         x = process(fn, listnames)

Modified: python/branches/py3k-importlib/Tools/scripts/h2py.py
==============================================================================
--- python/branches/py3k-importlib/Tools/scripts/h2py.py	(original)
+++ python/branches/py3k-importlib/Tools/scripts/h2py.py	Thu Mar 27 00:48:05 2008
@@ -96,13 +96,13 @@
     body = p_char.sub('ord(\\0)', body)
     # Compute negative hexadecimal constants
     start = 0
-    UMAX = 2*(sys.maxint+1)
+    UMAX = 2*(sys.maxsize+1)
     while 1:
         m = p_hex.search(body, start)
         if not m: break
         s,e = m.span()
         val = long(body[slice(*m.span(1))], 16)
-        if val > sys.maxint:
+        if val > sys.maxsize:
             val -= UMAX
             body = body[:s] + "(" + str(val) + ")" + body[e:]
         start = s + 1

Modified: python/branches/py3k-importlib/Tools/scripts/logmerge.py
==============================================================================
--- python/branches/py3k-importlib/Tools/scripts/logmerge.py	(original)
+++ python/branches/py3k-importlib/Tools/scripts/logmerge.py	Thu Mar 27 00:48:05 2008
@@ -34,7 +34,7 @@
 from their output.
 """
 
-import os, sys, errno, getopt, re
+import sys, errno, getopt, re
 
 sep1 = '='*77 + '\n'                    # file separator
 sep2 = '-'*28 + '\n'                    # revision separator

Modified: python/branches/py3k-importlib/Tools/scripts/nm2def.py
==============================================================================
--- python/branches/py3k-importlib/Tools/scripts/nm2def.py	(original)
+++ python/branches/py3k-importlib/Tools/scripts/nm2def.py	Thu Mar 27 00:48:05 2008
@@ -34,7 +34,7 @@
 option to produce this format (since it is the original v7 Unix format).
 
 """
-import os,re,sys
+import os, sys
 
 PYTHONLIB = 'libpython'+sys.version[:3]+'.a'
 PC_PYTHONLIB = 'Python'+sys.version[0]+sys.version[2]+'.dll'

Modified: python/branches/py3k-importlib/Tools/scripts/pindent.py
==============================================================================
--- python/branches/py3k-importlib/Tools/scripts/pindent.py	(original)
+++ python/branches/py3k-importlib/Tools/scripts/pindent.py	Thu Mar 27 00:48:05 2008
@@ -81,7 +81,6 @@
 TABSIZE = 8
 EXPANDTABS = 0
 
-import os
 import re
 import sys
 

Modified: python/branches/py3k-importlib/Tools/scripts/pysource.py
==============================================================================
--- python/branches/py3k-importlib/Tools/scripts/pysource.py	(original)
+++ python/branches/py3k-importlib/Tools/scripts/pysource.py	Thu Mar 27 00:48:05 2008
@@ -20,7 +20,7 @@
 __all__ = ["has_python_ext", "looks_like_python", "can_be_compiled", "walk_python_files"]
 
 
-import sys, os, re
+import os, re
 
 binary_re = re.compile('[\x00-\x08\x0E-\x1F\x7F]')
 

Modified: python/branches/py3k-importlib/Tools/scripts/reindent.py
==============================================================================
--- python/branches/py3k-importlib/Tools/scripts/reindent.py	(original)
+++ python/branches/py3k-importlib/Tools/scripts/reindent.py	Thu Mar 27 00:48:05 2008
@@ -4,10 +4,11 @@
 
 """reindent [-d][-r][-v] [ path ... ]
 
--d (--dryrun)  Dry run.  Analyze, but don't make any changes to, files.
--r (--recurse) Recurse.  Search for all .py files in subdirectories too.
--v (--verbose) Verbose.  Print informative msgs; else no output.
--h (--help)    Help.     Print this usage information and exit.
+-d (--dryrun)   Dry run.   Analyze, but don't make any changes to, files.
+-r (--recurse)  Recurse.   Search for all .py files in subdirectories too.
+-n (--nobackup) No backup. Does not make a ".bak" file before reindenting.
+-v (--verbose)  Verbose.   Print informative msgs; else no output.
+-h (--help)     Help.      Print this usage information and exit.
 
 Change Python (.py) files to use 4-space indents and no hard tab characters.
 Also trim excess spaces and tabs from ends of lines, and remove empty lines
@@ -31,17 +32,23 @@
 The hard part of reindenting is figuring out what to do with comment
 lines.  So long as the input files get a clean bill of health from
 tabnanny.py, reindent should do a good job.
+
+The backup file is a copy of the one that is being reindented. The ".bak"
+file is generated with shutil.copy(), but some corner cases regarding
+user/group and permissions could leave the backup file more readable that
+you'd prefer. You can always use the --nobackup option to prevent this.
 """
 
 __version__ = "1"
 
 import tokenize
-import os
+import os, shutil
 import sys
 
-verbose = 0
-recurse = 0
-dryrun  = 0
+verbose    = 0
+recurse    = 0
+dryrun     = 0
+makebackup = True
 
 def usage(msg=None):
     if msg is not None:
@@ -57,10 +64,10 @@
 
 def main():
     import getopt
-    global verbose, recurse, dryrun
+    global verbose, recurse, dryrun, makebackup
     try:
-        opts, args = getopt.getopt(sys.argv[1:], "drvh",
-                                   ["dryrun", "recurse", "verbose", "help"])
+        opts, args = getopt.getopt(sys.argv[1:], "drnvh",
+                        ["dryrun", "recurse", "nobackup", "verbose", "help"])
     except getopt.error as msg:
         usage(msg)
         return
@@ -69,6 +76,8 @@
             dryrun += 1
         elif o in ('-r', '--recurse'):
             recurse += 1
+        elif o in ('-n', '--nobackup'):
+            makebackup = False
         elif o in ('-v', '--verbose'):
             verbose += 1
         elif o in ('-h', '--help'):
@@ -112,19 +121,20 @@
                 print("But this is a dry run, so leaving it alone.")
         if not dryrun:
             bak = file + ".bak"
-            if os.path.exists(bak):
-                os.remove(bak)
-            os.rename(file, bak)
-            if verbose:
-                print("renamed", file, "to", bak)
+            if makebackup:
+                shutil.copyfile(file, bak)
+                if verbose:
+                    print("backed up", file, "to", bak)
             f = open(file, "w")
             r.write(f)
             f.close()
             if verbose:
                 print("wrote new", file)
+        return True
     else:
         if verbose:
             print("unchanged.")
+        return False
 
 def _rstrip(line, JUNK='\n \t'):
     """Return line stripped of trailing spaces, tabs, newlines.
@@ -163,7 +173,9 @@
         self.stats = []
 
     def run(self):
-        tokenize.tokenize(self.getline, self.tokeneater)
+        tokens = tokenize.generate_tokens(self.getline)
+        for _token in tokens:
+            self.tokeneater(*_token)
         # Remove trailing empty lines.
         lines = self.lines
         while lines and lines[-1] == "\n":

Deleted: /python/branches/py3k-importlib/Tools/scripts/texcheck.py
==============================================================================
--- /python/branches/py3k-importlib/Tools/scripts/texcheck.py	Thu Mar 27 00:48:05 2008
+++ (empty file)
@@ -1,233 +0,0 @@
-""" TeXcheck.py -- rough syntax checking on Python style LaTeX documents.
-
-   Written by Raymond D. Hettinger <python at rcn.com>
-   Copyright (c) 2003 Python Software Foundation.  All rights reserved.
-
-Designed to catch common markup errors including:
-* Unbalanced or mismatched parenthesis, brackets, and braces.
-* Unbalanced or mismatched \\begin and \\end blocks.
-* Misspelled or invalid LaTeX commands.
-* Use of forward slashes instead of backslashes for commands.
-* Table line size mismatches.
-
-Sample command line usage:
-    python texcheck.py -k chapterheading -m lib/librandomtex *.tex
-
-Options:
-    -m          Munge parenthesis and brackets. [0,n) would normally mismatch.
-    -k keyword: Keyword is a valid LaTeX command. Do not include the backslash.
-    -d:         Delimiter check only (useful for non-LaTeX files).
-    -h:         Help
-    -s lineno:  Start at lineno (useful for skipping complex sections).
-    -v:         Verbose.  Trace the matching of //begin and //end blocks.
-"""
-
-import re
-import sys
-import getopt
-from itertools import izip, count, islice
-import glob
-
-cmdstr = r"""
-    \section \module \declaremodule \modulesynopsis \moduleauthor
-    \sectionauthor \versionadded \code \class \method \begin
-    \optional \var \ref \end \subsection \lineiii \hline \label
-    \indexii \textrm \ldots \keyword \stindex \index \item \note
-    \withsubitem \ttindex \footnote \citetitle \samp \opindex
-    \noindent \exception \strong \dfn \ctype \obindex \character
-    \indexiii \function \bifuncindex \refmodule \refbimodindex
-    \subsubsection \nodename \member \chapter \emph \ASCII \UNIX
-    \regexp \program \production \token \productioncont \term
-    \grammartoken \lineii \seemodule \file \EOF \documentclass
-    \usepackage \title \input \maketitle \ifhtml \fi \url \Cpp
-    \tableofcontents \kbd \programopt \envvar \refstmodindex
-    \cfunction \constant \NULL \moreargs \cfuncline \cdata
-    \textasciicircum \n \ABC \setindexsubitem \versionchanged
-    \deprecated \seetext \newcommand \POSIX \pep \warning \rfc
-    \verbatiminput \methodline \textgreater \seetitle \lineiv
-    \funclineni \ulink \manpage \funcline \dataline \unspecified
-    \textbackslash \mimetype \mailheader \seepep \textunderscore
-    \longprogramopt \infinity \plusminus \shortversion \version
-    \refmodindex \seerfc \makeindex \makemodindex \renewcommand
-    \indexname \appendix \protect \indexiv \mbox \textasciitilde
-    \platform \seeurl \leftmargin \labelwidth \localmoduletable
-    \LaTeX \copyright \memberline \backslash \pi \centerline
-    \caption \vspace \textwidth \menuselection \textless
-    \makevar \csimplemacro \menuselection \bfcode \sub \release
-    \email \kwindex \refexmodindex \filenq \e \menuselection
-    \exindex \linev \newsgroup \verbatim \setshortversion
-    \author \authoraddress \paragraph \subparagraph \cmemberline
-    \textbar \C \seelink
-"""
-
-def matchclose(c_lineno, c_symbol, openers, pairmap):
-    "Verify that closing delimiter matches most recent opening delimiter"
-    try:
-        o_lineno, o_symbol = openers.pop()
-    except IndexError:
-        print("\nDelimiter mismatch.  On line %d, encountered closing '%s' without corresponding open" % (c_lineno, c_symbol))
-        return
-    if o_symbol in pairmap.get(c_symbol, [c_symbol]): return
-    print("\nOpener '%s' on line %d was not closed before encountering '%s' on line %d" % (o_symbol, o_lineno, c_symbol, c_lineno))
-    return
-
-def checkit(source, opts, morecmds=[]):
-    """Check the LaTeX formatting in a sequence of lines.
-
-    Opts is a mapping of options to option values if any:
-        -m          munge parenthesis and brackets
-        -d          delimiters only checking
-        -v          verbose trace of delimiter matching
-        -s lineno:  linenumber to start scan (default is 1).
-
-    Morecmds is a sequence of LaTeX commands (without backslashes) that
-    are to be considered valid in the scan.
-    """
-
-    texcmd = re.compile(r'\\[A-Za-z]+')
-    falsetexcmd = re.compile(r'\/([A-Za-z]+)') # Mismarked with forward slash
-
-    validcmds = set(cmdstr.split())
-    for cmd in morecmds:
-        validcmds.add('\\' + cmd)
-
-    if '-m' in opts:
-        pairmap = {']':'[(', ')':'(['}      # Munged openers
-    else:
-        pairmap = {']':'[', ')':'('}        # Normal opener for a given closer
-    openpunct = set('([')                   # Set of valid openers
-
-    delimiters = re.compile(r'\\(begin|end){([_a-zA-Z]+)}|([()\[\]])')
-    braces = re.compile(r'({)|(})')
-    doubledwords = re.compile(r'(\b[A-za-z]+\b) \b\1\b')
-    spacingmarkup = re.compile(r'\\(ABC|ASCII|C|Cpp|EOF|infinity|NULL|plusminus|POSIX|UNIX)\s')
-
-    openers = []                            # Stack of pending open delimiters
-    bracestack = []                         # Stack of pending open braces
-
-    tablestart = re.compile(r'\\begin{(?:long)?table([iv]+)}')
-    tableline = re.compile(r'\\line([iv]+){')
-    tableend = re.compile(r'\\end{(?:long)?table([iv]+)}')
-    tablelevel = ''
-    tablestartline = 0
-
-    startline = int(opts.get('-s', '1'))
-    lineno = 0
-
-    for lineno, line in izip(count(startline), islice(source, startline-1, None)):
-        line = line.rstrip()
-
-        # Check balancing of open/close parenthesis, brackets, and begin/end blocks
-        for begend, name, punct in delimiters.findall(line):
-            if '-v' in opts:
-                print(lineno, '|', begend, name, punct, end=' ')
-            if begend == 'begin' and '-d' not in opts:
-                openers.append((lineno, name))
-            elif punct in openpunct:
-                openers.append((lineno, punct))
-            elif begend == 'end' and '-d' not in opts:
-                matchclose(lineno, name, openers, pairmap)
-            elif punct in pairmap:
-                matchclose(lineno, punct, openers, pairmap)
-            if '-v' in opts:
-                print('   --> ', openers)
-
-        # Balance opening and closing braces
-        for open, close in braces.findall(line):
-            if open == '{':
-                bracestack.append(lineno)
-            if close == '}':
-                try:
-                    bracestack.pop()
-                except IndexError:
-                    print(r'Warning, unmatched } on line %s.' % (lineno,))
-
-        # Optionally, skip LaTeX specific checks
-        if '-d' in opts:
-            continue
-
-        # Warn whenever forward slashes encountered with a LaTeX command
-        for cmd in falsetexcmd.findall(line):
-            if '822' in line or '.html' in line:
-                continue    # Ignore false positives for urls and for /rfc822
-            if '\\' + cmd in validcmds:
-                print('Warning, forward slash used on line %d with cmd: /%s' % (lineno, cmd))
-
-        # Check for markup requiring {} for correct spacing
-        for cmd in spacingmarkup.findall(line):
-            print(r'Warning, \%s should be written as \%s{} on line %d' % (cmd, cmd, lineno))
-
-        # Validate commands
-        nc = line.find(r'\newcommand')
-        if nc != -1:
-            start = line.find('{', nc)
-            end = line.find('}', start)
-            validcmds.add(line[start+1:end])
-        for cmd in texcmd.findall(line):
-            if cmd not in validcmds:
-                print(r'Warning, unknown tex cmd on line %d: \%s' % (lineno, cmd))
-
-        # Check table levels (make sure lineii only inside tableii)
-        m = tablestart.search(line)
-        if m:
-            tablelevel = m.group(1)
-            tablestartline = lineno
-        m = tableline.search(line)
-        if m and m.group(1) != tablelevel:
-            print(r'Warning, \line%s on line %d does not match \table%s on line %d' % (m.group(1), lineno, tablelevel, tablestartline))
-        if tableend.search(line):
-            tablelevel = ''
-
-        # Style guide warnings
-        if 'e.g.' in line or 'i.e.' in line:
-            print(r'Style warning, avoid use of i.e or e.g. on line %d' % (lineno,))
-
-        for dw in doubledwords.findall(line):
-            print(r'Doubled word warning.  "%s" on line %d' % (dw, lineno))
-
-    lastline = lineno
-    for lineno, symbol in openers:
-        print("Unmatched open delimiter '%s' on line %d" % (symbol, lineno))
-    for lineno in bracestack:
-        print("Unmatched { on line %d" % (lineno,))
-    print('Done checking %d lines.' % (lastline,))
-    return 0
-
-def main(args=None):
-    if args is None:
-        args = sys.argv[1:]
-    optitems, arglist = getopt.getopt(args, "k:mdhs:v")
-    opts = dict(optitems)
-    if '-h' in opts or args==[]:
-        print(__doc__)
-        return 0
-
-    if len(arglist) < 1:
-        print('Please specify a file to be checked')
-        return 1
-
-    for i, filespec in enumerate(arglist):
-        if '*' in filespec or '?' in filespec:
-            arglist[i:i+1] = glob.glob(filespec)
-
-    morecmds = [v for k,v in optitems if k=='-k']
-    err = []
-
-    for filename in arglist:
-        print('=' * 30)
-        print("Checking", filename)
-        try:
-            f = open(filename)
-        except IOError:
-            print('Cannot open file %s.' % arglist[0])
-            return 2
-
-        try:
-            err.append(checkit(f, opts, morecmds))
-        finally:
-            f.close()
-
-    return max(err)
-
-if __name__ == '__main__':
-    sys.exit(main())

Modified: python/branches/py3k-importlib/Tools/scripts/xxci.py
==============================================================================
--- python/branches/py3k-importlib/Tools/scripts/xxci.py	(original)
+++ python/branches/py3k-importlib/Tools/scripts/xxci.py	Thu Mar 27 00:48:05 2008
@@ -7,7 +7,6 @@
 import sys
 import os
 from stat import *
-import commands
 import fnmatch
 
 EXECMAGIC = '\001\140\000\010'

Modified: python/branches/py3k-importlib/Tools/ssl/get-remote-certificate.py
==============================================================================
--- python/branches/py3k-importlib/Tools/ssl/get-remote-certificate.py	(original)
+++ python/branches/py3k-importlib/Tools/ssl/get-remote-certificate.py	Thu Mar 27 00:48:05 2008
@@ -6,7 +6,7 @@
 #
 # By Bill Janssen.
 
-import sys, os
+import sys
 
 def fetch_server_certificate (host, port):
 

Modified: python/branches/py3k-importlib/Tools/unicode/gencodec.py
==============================================================================
--- python/branches/py3k-importlib/Tools/unicode/gencodec.py	(original)
+++ python/branches/py3k-importlib/Tools/unicode/gencodec.py	Thu Mar 27 00:48:05 2008
@@ -26,7 +26,7 @@
 
 """#"
 
-import re, os, time, marshal, codecs
+import re, os, marshal, codecs
 
 # Maximum allowed size of charmap tables
 MAX_TABLE_SIZE = 8192

Modified: python/branches/py3k-importlib/Tools/unicode/makeunicodedata.py
==============================================================================
--- python/branches/py3k-importlib/Tools/unicode/makeunicodedata.py	(original)
+++ python/branches/py3k-importlib/Tools/unicode/makeunicodedata.py	Thu Mar 27 00:48:05 2008
@@ -441,6 +441,15 @@
 # --------------------------------------------------------------------
 # unicode name database
 
+def CmpToKey(mycmp):
+    'Convert a cmp= function into a key= function'
+    class K(object):
+        def __init__(self, obj, *args):
+            self.obj = obj
+        def __lt__(self, other):
+            return mycmp(self.obj, other.obj) == -1
+    return K
+
 def makeunicodename(unicode, trace):
 
     FILE = "Modules/unicodename_db.h"
@@ -490,7 +499,7 @@
         if r:
             return r
         return cmp(aword, bword)
-    wordlist.sort(cmpwords)
+    wordlist.sort(key=CmpToKey(cmpwords))
 
     # figure out how many phrasebook escapes we need
     escapes = 0
@@ -514,7 +523,7 @@
     # length (to maximize overlap)
 
     wordlist, wordtail = wordlist[:short], wordlist[short:]
-    wordtail.sort(lambda a, b: len(b[0])-len(a[0]))
+    wordtail.sort(key=lambda a: a[0], reverse=True)
     wordlist.extend(wordtail)
 
     # generate lexicon from words
@@ -948,7 +957,7 @@
             n >>= 1
             maxshift += 1
     del n
-    bytes = sys.maxint  # smallest total size so far
+    bytes = sys.maxsize  # smallest total size so far
     t = tuple(t)    # so slices can be dict keys
     for shift in range(maxshift + 1):
         t1 = []

Modified: python/branches/py3k-importlib/Tools/webchecker/wcgui.py
==============================================================================
--- python/branches/py3k-importlib/Tools/webchecker/wcgui.py	(original)
+++ python/branches/py3k-importlib/Tools/webchecker/wcgui.py	Thu Mar 27 00:48:05 2008
@@ -63,7 +63,6 @@
 from Tkinter import *
 import tktools
 import webchecker
-import random
 
 # Override some for a weaker platform
 if sys.platform == 'mac':

Modified: python/branches/py3k-importlib/Tools/webchecker/wsgui.py
==============================================================================
--- python/branches/py3k-importlib/Tools/webchecker/wsgui.py	(original)
+++ python/branches/py3k-importlib/Tools/webchecker/wsgui.py	Thu Mar 27 00:48:05 2008
@@ -7,9 +7,7 @@
 """
 
 from Tkinter import *
-import Tkinter
 import websucker
-import sys
 import os
 import threading
 import Queue

Modified: python/branches/py3k-importlib/Tools/world/world
==============================================================================
--- python/branches/py3k-importlib/Tools/world/world	(original)
+++ python/branches/py3k-importlib/Tools/world/world	Thu Mar 27 00:48:05 2008
@@ -42,7 +42,7 @@
 
 The latest known change to this information was:
 
-    Friday, 5 April 2002, 12.00 CET 2002
+    Monday, 10 October 2006, 17:59:51 UTC 2006
 
 This script also knows about non-geographic top-level domains, and the
 additional ccTLDs reserved by IANA.
@@ -91,9 +91,9 @@
 
 
 def usage(code, msg=''):
-    print __doc__ % globals()
+    print(__doc__ % globals())
     if msg:
-        print msg
+        print(msg)
     sys.exit(code)
 
 
@@ -104,11 +104,11 @@
         # no top level domain found, bounce it to the next step
         return rawaddr
     addr = parts[-1]
-    if nameorgs.has_key(addr):
-        print rawaddr, 'is in the', nameorgs[addr], 'top level domain'
+    if addr in nameorgs:
+        print(rawaddr, 'is in the', nameorgs[addr], 'top level domain')
         return None
-    elif countries.has_key(addr):
-        print rawaddr, 'originated from', countries[addr]
+    elif addr in countries:
+        print(rawaddr, 'originated from', countries[addr])
         return None
     else:
         # Not resolved, bounce it to the next step
@@ -129,11 +129,11 @@
         return regexp
     if len(matches) == 1:
         code = matches[0]
-        print regexp, "matches code `%s', %s" % (code, all[code])
+        print(regexp, "matches code `%s', %s" % (code, all[code]))
     else:
-        print regexp, 'matches %d countries:' % len(matches)
+        print(regexp, 'matches %d countries:' % len(matches))
         for code in matches:
-            print "    %s: %s" % (code, all[code])
+            print("    %s: %s" % (code, all[code]))
     return None
 
 
@@ -141,14 +141,16 @@
 def parse(file, normalize):
     try:
         fp = open(file)
-    except IOError, (err, msg):
-        print msg, ':', file
+    except IOError as err:
+        errno, msg = err.args
+        print(msg, ':', file)
+        return
 
     cre = re.compile('(.*?)[ \t]+([A-Z]{2})[ \t]+[A-Z]{3}[ \t]+[0-9]{3}')
     scanning = 0
 
     if normalize:
-        print 'countries = {'
+        print('countries = {')
 
     while 1:
         line = fp.readline()
@@ -163,7 +165,7 @@
                 elif line[0] == '-':
                     break
                 else:
-                    print 'Could not parse line:', line
+                    print('Could not parse line:', line)
                     continue
             country, code = mo.group(1, 2)
             if normalize:
@@ -173,30 +175,30 @@
                     # XXX special cases
                     if w in ('AND', 'OF', 'OF)', 'name:', 'METROPOLITAN'):
                         words[i] = w.lower()
-                    elif w == 'THE' and i <> 1:
+                    elif w == 'THE' and i != 1:
                         words[i] = w.lower()
                     elif len(w) > 3 and w[1] == "'":
                         words[i] = w[0:3].upper() + w[3:].lower()
                     elif w in ('(U.S.)', 'U.S.'):
                         pass
-                    elif w[0] == '(' and w <> '(local':
+                    elif w[0] == '(' and w != '(local':
                         words[i] = '(' + w[1:].capitalize()
-                    elif w.find('-') <> -1:
+                    elif w.find('-') != -1:
                         words[i] = '-'.join(
                             [s.capitalize() for s in w.split('-')])
                     else:
                         words[i] = w.capitalize()
                 code = code.lower()
                 country = ' '.join(words)
-                print '    "%s": "%s",' % (code, country)
+                print('    "%s": "%s",' % (code, country))
             else:
-                print code, country
-            
+                print(code, country)
+
         elif line[0] == '-':
             scanning = 1
 
     if normalize:
-        print '    }'
+        print('    }')
 
 
 def main():
@@ -212,7 +214,7 @@
             sys.argv[1:],
             'p:rohd',
             ['parse=', 'reverse', 'outputdict', 'help', 'dump'])
-    except getopt.error, msg:
+    except getopt.error as msg:
         usage(1, msg)
 
     for opt, arg in opts:
@@ -231,17 +233,15 @@
         usage(status)
 
     if dump:
-        print 'Non-geographic domains:'
-        codes = nameorgs.keys()
-        codes.sort()
+        print('Official country coded domains:')
+        codes = sorted(countries)
         for code in codes:
-            print '    %4s:' % code, nameorgs[code]
+            print('      %2s:' % code, countries[code])
 
-        print '\nCountry coded domains:'
-        codes = countries.keys()
-        codes.sort()
+        print('\nOther top-level domains:')
+        codes = sorted(nameorgs)
         for code in codes:
-            print '    %2s:' % code, countries[code]
+            print('  %6s:' % code, nameorgs[code])
     elif parsefile:
         parse(parsefile, normalize)
     else:
@@ -249,7 +249,7 @@
             args = filter(None, map(resolve, args))
         args = filter(None, map(reverse, args))
         for arg in args:
-            print 'Where in the world is %s?' % arg
+            print('Where in the world is %s?' % arg)
 
 
 
@@ -258,26 +258,30 @@
     # New top level domains as described by ICANN
     # http://www.icann.org/tlds/
     "aero": "air-transport industry",
+    "asia": "from Asia/for Asia",
     "arpa": "Arpanet",
     "biz": "business",
+    "cat": "Catalan community",
     "com": "commercial",
     "coop": "cooperatives",
     "edu": "educational",
     "gov": "government",
     "info": "unrestricted `info'",
     "int": "international",
+    "jobs": "employment-related",
     "mil": "military",
+    "mobi": "mobile specific",
     "museum": "museums",
     "name": "`name' (for registration by individuals)",
     "net": "networking",
     "org": "non-commercial",
     "pro": "professionals",
+    "tel": "business telecommunications",
+    "travel": "travel and tourism",
     # These additional ccTLDs are included here even though they are not part
-    # of ISO 3166.  IANA has 5 reserved ccTLDs as described here:
-    #
-    # http://www.iso.org/iso/en/prods-services/iso3166ma/04background-on-iso-3166/iso3166-1-and-ccTLDs.html
+    # of ISO 3166.  IANA has a decoding table listing all reserved ccTLDs:
     #
-    # but I can't find an official list anywhere.
+    # http://www.iso.org/iso/iso-3166-1_decoding_table
     #
     # Note that `uk' is the common practice country code for the United
     # Kingdom.  AFAICT, the official `gb' code is routinely ignored!
@@ -292,9 +296,13 @@
     #
     # Also, `su', while obsolete is still in limited use.
     "ac": "Ascension Island",
-    "gg": "Guernsey",
-    "im": "Isle of Man",
-    "je": "Jersey",
+    "cp": "Clipperton Island",
+    "dg": "Diego Garcia",
+    "ea": "Ceuta, Melilla",
+    "eu": "European Union",
+    "fx": "Metropolitan France",
+    "ic": "Canary Islands",
+    "ta": "Tristan da Cunha",
     "uk": "United Kingdom (common practice)",
     "su": "Soviet Union (still in limited use)",
     }
@@ -303,6 +311,7 @@
 
 countries = {
     "af": "Afghanistan",
+    "ax": "Aland Islands",
     "al": "Albania",
     "dz": "Algeria",
     "as": "American Samoa",
@@ -328,7 +337,7 @@
     "bm": "Bermuda",
     "bt": "Bhutan",
     "bo": "Bolivia",
-    "ba": "Bosnia and Herzegowina",
+    "ba": "Bosnia and Herzegovina",
     "bw": "Botswana",
     "bv": "Bouvet Island",
     "br": "Brazil",
@@ -363,7 +372,6 @@
     "dj": "Djibouti",
     "dm": "Dominica",
     "do": "Dominican Republic",
-    "tp": "East Timor",
     "ec": "Ecuador",
     "eg": "Egypt",
     "sv": "El Salvador",
@@ -391,6 +399,7 @@
     "gp": "Guadeloupe",
     "gu": "Guam",
     "gt": "Guatemala",
+    "gg": "Guernsey",
     "gn": "Guinea",
     "gw": "Guinea-Bissau",
     "gy": "Guyana",
@@ -403,15 +412,17 @@
     "is": "Iceland",
     "in": "India",
     "id": "Indonesia",
-    "ir": "Iran, Islamic Republic of",
+    "ir": "Iran (Islamic Republic of)",
     "iq": "Iraq",
     "ie": "Ireland",
+    "im": "Isle of Man",
     "il": "Israel",
     "it": "Italy",
     "jm": "Jamaica",
     "jp": "Japan",
+    "je": "Jersey",
     "jo": "Jordan",
-    "kz": "Kazakstan",
+    "kz": "Kazakhstan",
     "ke": "Kenya",
     "ki": "Kiribati",
     "kp": "Korea, Democratic People's Republic of",
@@ -427,7 +438,7 @@
     "li": "Liechtenstein",
     "lt": "Lithuania",
     "lu": "Luxembourg",
-    "mo": "Macau",
+    "mo": "Macao",
     "mk": "Macedonia, The Former Yugoslav Republic of",
     "mg": "Madagascar",
     "mw": "Malawi",
@@ -445,6 +456,7 @@
     "md": "Moldova, Republic of",
     "mc": "Monaco",
     "mn": "Mongolia",
+    "me": "Montenegro",
     "ms": "Montserrat",
     "ma": "Morocco",
     "mz": "Mozambique",
@@ -491,6 +503,7 @@
     "st": "Sao Tome and Principe",
     "sa": "Saudi Arabia",
     "sn": "Senegal",
+    "rs": "Serbia",
     "sc": "Seychelles",
     "sl": "Sierra Leone",
     "sg": "Singapore",
@@ -505,6 +518,8 @@
     "sd": "Sudan",
     "sr": "Suriname",
     "sj": "Svalbard and Jan Mayen",
+    "sh": "St. Helena",
+    "pm": "St. Pierre and Miquelon",
     "sz": "Swaziland",
     "se": "Sweden",
     "ch": "Switzerland",
@@ -513,6 +528,7 @@
     "tj": "Tajikistan",
     "tz": "Tanzania, United Republic of",
     "th": "Thailand",
+    "tl": "Timor-Leste",
     "tg": "Togo",
     "tk": "Tokelau",
     "to": "Tonga",
@@ -531,10 +547,11 @@
     "uy": "Uruguay",
     "uz": "Uzbekistan",
     "vu": "Vanuatu",
+    "va": "Vatican City State (Holy See)",
     "ve": "Venezuela",
     "vn": "Viet Nam",
-    "vg": "Virgin Islands, British",
-    "vi": "Virgin Islands, U.S.",
+    "vg": "Virgin Islands (British)",
+    "vi": "Virgin Islands (U.S.)",
     "wf": "Wallis and Futuna",
     "eh": "Western Sahara",
     "ye": "Yemen",

Modified: python/branches/py3k-importlib/configure
==============================================================================
--- python/branches/py3k-importlib/configure	(original)
+++ python/branches/py3k-importlib/configure	Thu Mar 27 00:48:05 2008
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 58054 .
+# From configure.in Revision: 61306 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61 for python 3.0.
 #
@@ -728,7 +728,6 @@
 HAVE_GETHOSTBYNAME
 LIBM
 LIBC
-UNICODE_OBJS
 THREADHEADERS
 SRCDIRS
 LTLIBOBJS'
@@ -1312,8 +1311,8 @@
 Optional Features:
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
-  --enable-universalsdk[SDKDIR]
-                          Build agains Mac OS X 10.4u SDK (ppc/i386)
+  --enable-universalsdk[=SDKDIR]
+                          Build against Mac OS X 10.4u SDK (ppc/i386)
   --enable-framework[=INSTALLDIR]
                           Build (MacOSX|Darwin) framework
   --enable-shared         disable/enable building shared python library
@@ -1321,8 +1320,6 @@
   --enable-toolbox-glue   disable/enable MacOSX glue code for extensions
   --enable-ipv6           Enable ipv6 (with ipv4) support
   --disable-ipv6          Disable ipv6 support
-  --enable-unicode[=ucs[24]]
-                          Enable Unicode strings (default is yes)
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -1349,6 +1346,7 @@
   --with-fpectl           enable SIGFPE catching
   --with-libm=STRING      math library
   --with-libc=STRING      C library
+  --with-wide-unicode     Use 4-byte Unicode characters (default is 2 bytes)
 
 Some influential environment variables:
   CC          C compiler command
@@ -1838,14 +1836,6 @@
 _ACEOF
 
 
-# OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is
-# also defined. This can be overridden by defining _BSD_SOURCE
-
-cat >>confdefs.h <<\_ACEOF
-#define _BSD_SOURCE 1
-_ACEOF
-
-
 # The later defininition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
 # u_int on Irix 5.3. Defining _BSD_TYPES brings it back.
 
@@ -2012,7 +2002,16 @@
   # even though select is a POSIX function. Reported by J. Ribbens.
   # Reconfirmed for OpenBSD 3.3 by Zachary Hamm, for 3.4 by Jason Ish.
   OpenBSD/2.* | OpenBSD/3.[0123456789] | OpenBSD/4.[0])
-    define_xopen_source=no;;
+    define_xopen_source=no
+    # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is
+    # also defined. This can be overridden by defining _BSD_SOURCE
+    # As this has a different meaning on Linux, only define it on OpenBSD
+
+cat >>confdefs.h <<\_ACEOF
+#define _BSD_SOURCE 1
+_ACEOF
+
+    ;;
   # Defining _XOPEN_SOURCE on NetBSD version prior to the introduction of
   # _NETBSD_SOURCE disables certain features (eg. setgroups). Reported by
   # Marc Recht
@@ -4403,6 +4402,10 @@
         if test "$CC" != 'g++' ; then
 	    STRICT_PROTO="-Wstrict-prototypes"
 	fi
+        # For gcc 4.x we need to use -fwrapv so lets check if its supported
+        if "$CC" -v --help 2>/dev/null |grep -- -fwrapv > /dev/null; then
+           WRAP="-fwrapv"
+        fi
 	case $ac_cv_prog_cc_g in
 	yes)
 	    if test "$Py_DEBUG" = 'true' ; then
@@ -4410,7 +4413,7 @@
 		# debug builds.
 		OPT="-g -Wall $STRICT_PROTO"
 	    else
-		OPT="-g -O3 -Wall $STRICT_PROTO"
+		OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
 	    fi
 	    ;;
 	*)
@@ -4506,7 +4509,8 @@
 	    ;;
 	# is there any other compiler on Darwin besides gcc?
 	Darwin*)
-	    BASECFLAGS="$BASECFLAGS -Wno-long-double -no-cpp-precomp -mno-fused-madd"
+	    # -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd
+	    # used to be here, but non-Apple gcc doesn't accept them.
 	    if test "${enable_universalsdk}"; then
 		BASECFLAGS="-arch ppc -arch i386 -isysroot ${UNIVERSALSDK} ${BASECFLAGS}"
 	    fi
@@ -5385,18 +5389,21 @@
 
 
 
+
+
+
 for ac_header in asm/types.h conio.h curses.h direct.h dlfcn.h errno.h \
 fcntl.h grp.h \
 io.h langinfo.h libintl.h ncurses.h poll.h process.h pthread.h \
 shadow.h signal.h stdint.h stropts.h termios.h thread.h \
 unistd.h utime.h \
-sys/audioio.h sys/bsdtty.h sys/file.h sys/loadavg.h sys/lock.h sys/mkdev.h \
-sys/modem.h \
+sys/audioio.h sys/bsdtty.h sys/epoll.h sys/event.h sys/file.h sys/loadavg.h \
+sys/lock.h sys/mkdev.h sys/modem.h \
 sys/param.h sys/poll.h sys/select.h sys/socket.h sys/statvfs.h sys/stat.h \
 sys/time.h \
 sys/times.h sys/types.h sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \
 sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \
-bluetooth/bluetooth.h
+bluetooth/bluetooth.h linux/tipc.h
 do
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
 if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
@@ -10127,64 +10134,9 @@
 _ACEOF
 
 
-
-{ echo "$as_me:$LINENO: checking for long long support" >&5
-echo $ECHO_N "checking for long long support... $ECHO_C" >&6; }
-have_long_long=no
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-
-int
-main ()
-{
-long long x; x = (long long)0;
-  ;
-  return 0;
-}
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-
-
-cat >>confdefs.h <<\_ACEOF
-#define HAVE_LONG_LONG 1
-_ACEOF
-
-  have_long_long=yes
-
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $have_long_long" >&5
-echo "${ECHO_T}$have_long_long" >&6; }
-if test "$have_long_long" = yes ; then
-{ echo "$as_me:$LINENO: checking for long long" >&5
-echo $ECHO_N "checking for long long... $ECHO_C" >&6; }
-if test "${ac_cv_type_long_long+set}" = set; then
+{ echo "$as_me:$LINENO: checking for pid_t" >&5
+echo $ECHO_N "checking for pid_t... $ECHO_C" >&6; }
+if test "${ac_cv_type_pid_t+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
@@ -10194,7 +10146,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-typedef long long ac__type_new_;
+typedef pid_t ac__type_new_;
 int
 main ()
 {
@@ -10223,26 +10175,26 @@
 	 test -z "$ac_c_werror_flag" ||
 	 test ! -s conftest.err
        } && test -s conftest.$ac_objext; then
-  ac_cv_type_long_long=yes
+  ac_cv_type_pid_t=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-	ac_cv_type_long_long=no
+	ac_cv_type_pid_t=no
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_type_long_long" >&5
-echo "${ECHO_T}$ac_cv_type_long_long" >&6; }
+{ echo "$as_me:$LINENO: result: $ac_cv_type_pid_t" >&5
+echo "${ECHO_T}$ac_cv_type_pid_t" >&6; }
 
 # The cast to long int works around a bug in the HP C Compiler
 # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
 # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
 # This bug is HP SR number 8606223364.
-{ echo "$as_me:$LINENO: checking size of long long" >&5
-echo $ECHO_N "checking size of long long... $ECHO_C" >&6; }
-if test "${ac_cv_sizeof_long_long+set}" = set; then
+{ echo "$as_me:$LINENO: checking size of pid_t" >&5
+echo $ECHO_N "checking size of pid_t... $ECHO_C" >&6; }
+if test "${ac_cv_sizeof_pid_t+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   if test "$cross_compiling" = yes; then
@@ -10254,7 +10206,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef long long ac__type_sizeof_;
+   typedef pid_t ac__type_sizeof_;
 int
 main ()
 {
@@ -10291,7 +10243,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef long long ac__type_sizeof_;
+   typedef pid_t ac__type_sizeof_;
 int
 main ()
 {
@@ -10345,7 +10297,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef long long ac__type_sizeof_;
+   typedef pid_t ac__type_sizeof_;
 int
 main ()
 {
@@ -10382,7 +10334,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef long long ac__type_sizeof_;
+   typedef pid_t ac__type_sizeof_;
 int
 main ()
 {
@@ -10446,7 +10398,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef long long ac__type_sizeof_;
+   typedef pid_t ac__type_sizeof_;
 int
 main ()
 {
@@ -10485,15 +10437,15 @@
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 done
 case $ac_lo in
-?*) ac_cv_sizeof_long_long=$ac_lo;;
-'') if test "$ac_cv_type_long_long" = yes; then
-     { { echo "$as_me:$LINENO: error: cannot compute sizeof (long long)
+?*) ac_cv_sizeof_pid_t=$ac_lo;;
+'') if test "$ac_cv_type_pid_t" = yes; then
+     { { echo "$as_me:$LINENO: error: cannot compute sizeof (pid_t)
 See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute sizeof (long long)
+echo "$as_me: error: cannot compute sizeof (pid_t)
 See \`config.log' for more details." >&2;}
    { (exit 77); exit 77; }; }
    else
-     ac_cv_sizeof_long_long=0
+     ac_cv_sizeof_pid_t=0
    fi ;;
 esac
 else
@@ -10504,7 +10456,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef long long ac__type_sizeof_;
+   typedef pid_t ac__type_sizeof_;
 static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); }
 static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); }
 #include <stdio.h>
@@ -10556,42 +10508,41 @@
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  ac_cv_sizeof_long_long=`cat conftest.val`
+  ac_cv_sizeof_pid_t=`cat conftest.val`
 else
   echo "$as_me: program exited with status $ac_status" >&5
 echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
 ( exit $ac_status )
-if test "$ac_cv_type_long_long" = yes; then
-     { { echo "$as_me:$LINENO: error: cannot compute sizeof (long long)
+if test "$ac_cv_type_pid_t" = yes; then
+     { { echo "$as_me:$LINENO: error: cannot compute sizeof (pid_t)
 See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute sizeof (long long)
+echo "$as_me: error: cannot compute sizeof (pid_t)
 See \`config.log' for more details." >&2;}
    { (exit 77); exit 77; }; }
    else
-     ac_cv_sizeof_long_long=0
+     ac_cv_sizeof_pid_t=0
    fi
 fi
 rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
 fi
 rm -f conftest.val
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_long_long" >&5
-echo "${ECHO_T}$ac_cv_sizeof_long_long" >&6; }
+{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_pid_t" >&5
+echo "${ECHO_T}$ac_cv_sizeof_pid_t" >&6; }
 
 
 
 cat >>confdefs.h <<_ACEOF
-#define SIZEOF_LONG_LONG $ac_cv_sizeof_long_long
+#define SIZEOF_PID_T $ac_cv_sizeof_pid_t
 _ACEOF
 
 
-fi
 
-{ echo "$as_me:$LINENO: checking for long double support" >&5
-echo $ECHO_N "checking for long double support... $ECHO_C" >&6; }
-have_long_double=no
+{ echo "$as_me:$LINENO: checking for long long support" >&5
+echo $ECHO_N "checking for long long support... $ECHO_C" >&6; }
+have_long_long=no
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -10602,7 +10553,7 @@
 int
 main ()
 {
-long double x; x = (long double)0;
+long long x; x = (long long)0;
   ;
   return 0;
 }
@@ -10627,10 +10578,10 @@
 
 
 cat >>confdefs.h <<\_ACEOF
-#define HAVE_LONG_DOUBLE 1
+#define HAVE_LONG_LONG 1
 _ACEOF
 
-  have_long_double=yes
+  have_long_long=yes
 
 else
   echo "$as_me: failed program was:" >&5
@@ -10640,12 +10591,12 @@
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $have_long_double" >&5
-echo "${ECHO_T}$have_long_double" >&6; }
-if test "$have_long_double" = yes ; then
-{ echo "$as_me:$LINENO: checking for long double" >&5
-echo $ECHO_N "checking for long double... $ECHO_C" >&6; }
-if test "${ac_cv_type_long_double+set}" = set; then
+{ echo "$as_me:$LINENO: result: $have_long_long" >&5
+echo "${ECHO_T}$have_long_long" >&6; }
+if test "$have_long_long" = yes ; then
+{ echo "$as_me:$LINENO: checking for long long" >&5
+echo $ECHO_N "checking for long long... $ECHO_C" >&6; }
+if test "${ac_cv_type_long_long+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
@@ -10655,7 +10606,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-typedef long double ac__type_new_;
+typedef long long ac__type_new_;
 int
 main ()
 {
@@ -10684,26 +10635,26 @@
 	 test -z "$ac_c_werror_flag" ||
 	 test ! -s conftest.err
        } && test -s conftest.$ac_objext; then
-  ac_cv_type_long_double=yes
+  ac_cv_type_long_long=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-	ac_cv_type_long_double=no
+	ac_cv_type_long_long=no
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_type_long_double" >&5
-echo "${ECHO_T}$ac_cv_type_long_double" >&6; }
+{ echo "$as_me:$LINENO: result: $ac_cv_type_long_long" >&5
+echo "${ECHO_T}$ac_cv_type_long_long" >&6; }
 
 # The cast to long int works around a bug in the HP C Compiler
 # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
 # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
 # This bug is HP SR number 8606223364.
-{ echo "$as_me:$LINENO: checking size of long double" >&5
-echo $ECHO_N "checking size of long double... $ECHO_C" >&6; }
-if test "${ac_cv_sizeof_long_double+set}" = set; then
+{ echo "$as_me:$LINENO: checking size of long long" >&5
+echo $ECHO_N "checking size of long long... $ECHO_C" >&6; }
+if test "${ac_cv_sizeof_long_long+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   if test "$cross_compiling" = yes; then
@@ -10715,7 +10666,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef long double ac__type_sizeof_;
+   typedef long long ac__type_sizeof_;
 int
 main ()
 {
@@ -10752,7 +10703,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef long double ac__type_sizeof_;
+   typedef long long ac__type_sizeof_;
 int
 main ()
 {
@@ -10806,7 +10757,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef long double ac__type_sizeof_;
+   typedef long long ac__type_sizeof_;
 int
 main ()
 {
@@ -10843,7 +10794,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef long double ac__type_sizeof_;
+   typedef long long ac__type_sizeof_;
 int
 main ()
 {
@@ -10907,7 +10858,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef long double ac__type_sizeof_;
+   typedef long long ac__type_sizeof_;
 int
 main ()
 {
@@ -10946,15 +10897,15 @@
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 done
 case $ac_lo in
-?*) ac_cv_sizeof_long_double=$ac_lo;;
-'') if test "$ac_cv_type_long_double" = yes; then
-     { { echo "$as_me:$LINENO: error: cannot compute sizeof (long double)
+?*) ac_cv_sizeof_long_long=$ac_lo;;
+'') if test "$ac_cv_type_long_long" = yes; then
+     { { echo "$as_me:$LINENO: error: cannot compute sizeof (long long)
 See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute sizeof (long double)
+echo "$as_me: error: cannot compute sizeof (long long)
 See \`config.log' for more details." >&2;}
    { (exit 77); exit 77; }; }
    else
-     ac_cv_sizeof_long_double=0
+     ac_cv_sizeof_long_long=0
    fi ;;
 esac
 else
@@ -10965,7 +10916,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef long double ac__type_sizeof_;
+   typedef long long ac__type_sizeof_;
 static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); }
 static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); }
 #include <stdio.h>
@@ -11017,43 +10968,42 @@
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  ac_cv_sizeof_long_double=`cat conftest.val`
+  ac_cv_sizeof_long_long=`cat conftest.val`
 else
   echo "$as_me: program exited with status $ac_status" >&5
 echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
 ( exit $ac_status )
-if test "$ac_cv_type_long_double" = yes; then
-     { { echo "$as_me:$LINENO: error: cannot compute sizeof (long double)
+if test "$ac_cv_type_long_long" = yes; then
+     { { echo "$as_me:$LINENO: error: cannot compute sizeof (long long)
 See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute sizeof (long double)
+echo "$as_me: error: cannot compute sizeof (long long)
 See \`config.log' for more details." >&2;}
    { (exit 77); exit 77; }; }
    else
-     ac_cv_sizeof_long_double=0
+     ac_cv_sizeof_long_long=0
    fi
 fi
 rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
 fi
 rm -f conftest.val
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_long_double" >&5
-echo "${ECHO_T}$ac_cv_sizeof_long_double" >&6; }
+{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_long_long" >&5
+echo "${ECHO_T}$ac_cv_sizeof_long_long" >&6; }
 
 
 
 cat >>confdefs.h <<_ACEOF
-#define SIZEOF_LONG_DOUBLE $ac_cv_sizeof_long_double
+#define SIZEOF_LONG_LONG $ac_cv_sizeof_long_long
 _ACEOF
 
 
 fi
 
-
-{ echo "$as_me:$LINENO: checking for _Bool support" >&5
-echo $ECHO_N "checking for _Bool support... $ECHO_C" >&6; }
-have_c99_bool=no
+{ echo "$as_me:$LINENO: checking for long double support" >&5
+echo $ECHO_N "checking for long double support... $ECHO_C" >&6; }
+have_long_double=no
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -11064,7 +11014,7 @@
 int
 main ()
 {
-_Bool x; x = (_Bool)0;
+long double x; x = (long double)0;
   ;
   return 0;
 }
@@ -11089,10 +11039,10 @@
 
 
 cat >>confdefs.h <<\_ACEOF
-#define HAVE_C99_BOOL 1
+#define HAVE_LONG_DOUBLE 1
 _ACEOF
 
-  have_c99_bool=yes
+  have_long_double=yes
 
 else
   echo "$as_me: failed program was:" >&5
@@ -11102,12 +11052,12 @@
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $have_c99_bool" >&5
-echo "${ECHO_T}$have_c99_bool" >&6; }
-if test "$have_c99_bool" = yes ; then
-{ echo "$as_me:$LINENO: checking for _Bool" >&5
-echo $ECHO_N "checking for _Bool... $ECHO_C" >&6; }
-if test "${ac_cv_type__Bool+set}" = set; then
+{ echo "$as_me:$LINENO: result: $have_long_double" >&5
+echo "${ECHO_T}$have_long_double" >&6; }
+if test "$have_long_double" = yes ; then
+{ echo "$as_me:$LINENO: checking for long double" >&5
+echo $ECHO_N "checking for long double... $ECHO_C" >&6; }
+if test "${ac_cv_type_long_double+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
@@ -11117,7 +11067,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-typedef _Bool ac__type_new_;
+typedef long double ac__type_new_;
 int
 main ()
 {
@@ -11146,26 +11096,26 @@
 	 test -z "$ac_c_werror_flag" ||
 	 test ! -s conftest.err
        } && test -s conftest.$ac_objext; then
-  ac_cv_type__Bool=yes
+  ac_cv_type_long_double=yes
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-	ac_cv_type__Bool=no
+	ac_cv_type_long_double=no
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_type__Bool" >&5
-echo "${ECHO_T}$ac_cv_type__Bool" >&6; }
+{ echo "$as_me:$LINENO: result: $ac_cv_type_long_double" >&5
+echo "${ECHO_T}$ac_cv_type_long_double" >&6; }
 
 # The cast to long int works around a bug in the HP C Compiler
 # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
 # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
 # This bug is HP SR number 8606223364.
-{ echo "$as_me:$LINENO: checking size of _Bool" >&5
-echo $ECHO_N "checking size of _Bool... $ECHO_C" >&6; }
-if test "${ac_cv_sizeof__Bool+set}" = set; then
+{ echo "$as_me:$LINENO: checking size of long double" >&5
+echo $ECHO_N "checking size of long double... $ECHO_C" >&6; }
+if test "${ac_cv_sizeof_long_double+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   if test "$cross_compiling" = yes; then
@@ -11177,7 +11127,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef _Bool ac__type_sizeof_;
+   typedef long double ac__type_sizeof_;
 int
 main ()
 {
@@ -11214,7 +11164,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef _Bool ac__type_sizeof_;
+   typedef long double ac__type_sizeof_;
 int
 main ()
 {
@@ -11268,7 +11218,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef _Bool ac__type_sizeof_;
+   typedef long double ac__type_sizeof_;
 int
 main ()
 {
@@ -11305,7 +11255,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef _Bool ac__type_sizeof_;
+   typedef long double ac__type_sizeof_;
 int
 main ()
 {
@@ -11369,7 +11319,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef _Bool ac__type_sizeof_;
+   typedef long double ac__type_sizeof_;
 int
 main ()
 {
@@ -11408,15 +11358,15 @@
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 done
 case $ac_lo in
-?*) ac_cv_sizeof__Bool=$ac_lo;;
-'') if test "$ac_cv_type__Bool" = yes; then
-     { { echo "$as_me:$LINENO: error: cannot compute sizeof (_Bool)
+?*) ac_cv_sizeof_long_double=$ac_lo;;
+'') if test "$ac_cv_type_long_double" = yes; then
+     { { echo "$as_me:$LINENO: error: cannot compute sizeof (long double)
 See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute sizeof (_Bool)
+echo "$as_me: error: cannot compute sizeof (long double)
 See \`config.log' for more details." >&2;}
    { (exit 77); exit 77; }; }
    else
-     ac_cv_sizeof__Bool=0
+     ac_cv_sizeof_long_double=0
    fi ;;
 esac
 else
@@ -11427,7 +11377,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-   typedef _Bool ac__type_sizeof_;
+   typedef long double ac__type_sizeof_;
 static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); }
 static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); }
 #include <stdio.h>
@@ -11479,15 +11429,477 @@
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  ac_cv_sizeof__Bool=`cat conftest.val`
+  ac_cv_sizeof_long_double=`cat conftest.val`
 else
   echo "$as_me: program exited with status $ac_status" >&5
 echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
 ( exit $ac_status )
-if test "$ac_cv_type__Bool" = yes; then
-     { { echo "$as_me:$LINENO: error: cannot compute sizeof (_Bool)
+if test "$ac_cv_type_long_double" = yes; then
+     { { echo "$as_me:$LINENO: error: cannot compute sizeof (long double)
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute sizeof (long double)
+See \`config.log' for more details." >&2;}
+   { (exit 77); exit 77; }; }
+   else
+     ac_cv_sizeof_long_double=0
+   fi
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f conftest.val
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_long_double" >&5
+echo "${ECHO_T}$ac_cv_sizeof_long_double" >&6; }
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define SIZEOF_LONG_DOUBLE $ac_cv_sizeof_long_double
+_ACEOF
+
+
+fi
+
+
+{ echo "$as_me:$LINENO: checking for _Bool support" >&5
+echo $ECHO_N "checking for _Bool support... $ECHO_C" >&6; }
+have_c99_bool=no
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+_Bool x; x = (_Bool)0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_C99_BOOL 1
+_ACEOF
+
+  have_c99_bool=yes
+
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $have_c99_bool" >&5
+echo "${ECHO_T}$have_c99_bool" >&6; }
+if test "$have_c99_bool" = yes ; then
+{ echo "$as_me:$LINENO: checking for _Bool" >&5
+echo $ECHO_N "checking for _Bool... $ECHO_C" >&6; }
+if test "${ac_cv_type__Bool+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+typedef _Bool ac__type_new_;
+int
+main ()
+{
+if ((ac__type_new_ *) 0)
+  return 0;
+if (sizeof (ac__type_new_))
+  return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_type__Bool=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_type__Bool=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_type__Bool" >&5
+echo "${ECHO_T}$ac_cv_type__Bool" >&6; }
+
+# The cast to long int works around a bug in the HP C Compiler
+# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
+# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
+# This bug is HP SR number 8606223364.
+{ echo "$as_me:$LINENO: checking size of _Bool" >&5
+echo $ECHO_N "checking size of _Bool... $ECHO_C" >&6; }
+if test "${ac_cv_sizeof__Bool+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$cross_compiling" = yes; then
+  # Depending upon the size, compute the lo and hi bounds.
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+   typedef _Bool ac__type_sizeof_;
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= 0)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_lo=0 ac_mid=0
+  while :; do
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+   typedef _Bool ac__type_sizeof_;
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_hi=$ac_mid; break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_lo=`expr $ac_mid + 1`
+			if test $ac_lo -le $ac_mid; then
+			  ac_lo= ac_hi=
+			  break
+			fi
+			ac_mid=`expr 2 '*' $ac_mid + 1`
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+   typedef _Bool ac__type_sizeof_;
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) < 0)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_hi=-1 ac_mid=-1
+  while :; do
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+   typedef _Bool ac__type_sizeof_;
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= $ac_mid)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_lo=$ac_mid; break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_hi=`expr '(' $ac_mid ')' - 1`
+			if test $ac_mid -le $ac_hi; then
+			  ac_lo= ac_hi=
+			  break
+			fi
+			ac_mid=`expr 2 '*' $ac_mid`
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_lo= ac_hi=
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+# Binary search between lo and hi bounds.
+while test "x$ac_lo" != "x$ac_hi"; do
+  ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+   typedef _Bool ac__type_sizeof_;
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_hi=$ac_mid
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_lo=`expr '(' $ac_mid ')' + 1`
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+case $ac_lo in
+?*) ac_cv_sizeof__Bool=$ac_lo;;
+'') if test "$ac_cv_type__Bool" = yes; then
+     { { echo "$as_me:$LINENO: error: cannot compute sizeof (_Bool)
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute sizeof (_Bool)
+See \`config.log' for more details." >&2;}
+   { (exit 77); exit 77; }; }
+   else
+     ac_cv_sizeof__Bool=0
+   fi ;;
+esac
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+   typedef _Bool ac__type_sizeof_;
+static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); }
+static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); }
+#include <stdio.h>
+#include <stdlib.h>
+int
+main ()
+{
+
+  FILE *f = fopen ("conftest.val", "w");
+  if (! f)
+    return 1;
+  if (((long int) (sizeof (ac__type_sizeof_))) < 0)
+    {
+      long int i = longval ();
+      if (i != ((long int) (sizeof (ac__type_sizeof_))))
+	return 1;
+      fprintf (f, "%ld\n", i);
+    }
+  else
+    {
+      unsigned long int i = ulongval ();
+      if (i != ((long int) (sizeof (ac__type_sizeof_))))
+	return 1;
+      fprintf (f, "%lu\n", i);
+    }
+  return ferror (f) || fclose (f) != 0;
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_sizeof__Bool=`cat conftest.val`
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+if test "$ac_cv_type__Bool" = yes; then
+     { { echo "$as_me:$LINENO: error: cannot compute sizeof (_Bool)
 See \`config.log' for more details." >&5
 echo "$as_me: error: cannot compute sizeof (_Bool)
 See \`config.log' for more details." >&2;}
@@ -13181,9 +13593,6 @@
 fi
 
 
-if test -z "$with_system_ffi"
-then with_system_ffi="no"
-fi
 { echo "$as_me:$LINENO: result: $with_system_ffi" >&5
 echo "${ECHO_T}$with_system_ffi" >&6; }
 
@@ -14461,6 +14870,12 @@
 _ACEOF
 
 		       ;;
+      AIX/5)
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_BROKEN_POSIX_SEMAPHORES 1
+_ACEOF
+
+		       ;;
       esac
 
       { echo "$as_me:$LINENO: checking if PTHREAD_SCOPE_SYSTEM is supported" >&5
@@ -15302,18 +15717,20 @@
 
 
 
-for ac_func in alarm bind_textdomain_codeset chflags chown clock confstr \
- ctermid execv fork fpathconf ftime ftruncate \
+
+
+for ac_func in alarm bind_textdomain_codeset chown clock confstr \
+ ctermid execv fchmod fchown fork fpathconf ftime ftruncate \
  gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
  getpriority getpwent getspnam getspent getsid getwd \
- kill killpg lchflags lchown lstat mkfifo mknod mktime \
+ kill killpg lchmod lchown lstat mkfifo mknod mktime \
  mremap nice pathconf pause plock poll pthread_init \
  putenv readlink realpath \
  select setegid seteuid setgid \
  setlocale setregid setreuid setsid setpgid setpgrp setuid setvbuf snprintf \
  sigaction siginterrupt sigrelse strftime strlcpy \
  sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
- truncate uname unsetenv utimes waitpid wait3 wait4 wcscoll _getpty
+ truncate uname unsetenv utimes waitpid wait3 wait4 wcscoll wcsxfrm _getpty
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 { echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -15715,7 +16132,111 @@
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: checking for epoll" >&5
+echo $ECHO_N "checking for epoll... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/epoll.h>
+int
+main ()
+{
+void *x=epoll_create
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_EPOLL 1
+_ACEOF
+
+  { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	{ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: checking for kqueue" >&5
+echo $ECHO_N "checking for kqueue... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+#include <sys/types.h>
+#include <sys/event.h>
+
+int
+main ()
+{
+int x=kqueue()
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_KQUEUE 1
+_ACEOF
+
+  { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	{ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+
+fi
 
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 # On some systems (eg. FreeBSD 5), we would find a definition of the
 # functions ctermid_r, setgroups in the library, but no prototype
 # (e.g. because we use _XOPEN_SOURCE). See whether we can take their
@@ -16070,6 +16591,144 @@
 fi
 
 
+# On Tru64, chflags seems to be present, but calling it will
+# exit Python
+{ echo "$as_me:$LINENO: checking for chflags" >&5
+echo $ECHO_N "checking for chflags... $ECHO_C" >&6; }
+if test "$cross_compiling" = yes; then
+  { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+#include <sys/stat.h>
+#include <unistd.h>
+int main(int argc, char*argv[])
+{
+  if(chflags(argv[0], 0) != 0)
+    return 1;
+  return 0;
+}
+
+_ACEOF
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_CHFLAGS 1
+_ACEOF
+
+  { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+{ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+
+{ echo "$as_me:$LINENO: checking for lchflags" >&5
+echo $ECHO_N "checking for lchflags... $ECHO_C" >&6; }
+if test "$cross_compiling" = yes; then
+  { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+#include <sys/stat.h>
+#include <unistd.h>
+int main(int argc, char*argv[])
+{
+  if(lchflags(argv[0], 0) != 0)
+    return 1;
+  return 0;
+}
+
+_ACEOF
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_LCHFLAGS 1
+_ACEOF
+
+  { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+{ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+
 case $ac_sys_system/$ac_sys_release in
 Darwin/*)
 	_CUR_CFLAGS="${CFLAGS}"
@@ -16861,6 +17520,102 @@
 done
 
 
+# Stuff for expat.
+
+for ac_func in memmove
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; }
+if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$ac_func || defined __stub___$ac_func
+choke me
+#endif
+
+int
+main ()
+{
+return $ac_func ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	eval "$as_ac_var=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+ac_res=`eval echo '${'$as_ac_var'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
 # check for long file support functions
 
 
@@ -16965,9 +17720,7 @@
 
 
 
-
-
-for ac_func in dup2 getcwd strdup strerror memmove
+for ac_func in dup2 getcwd strdup
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 { echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -20300,7 +21053,9 @@
 fi
 
 
-# check for hypot() in math library
+# ************************************
+# * Check for mathematical functions *
+# ************************************
 LIBS_SAVE=$LIBS
 LIBS="$LIBS $LIBM"
 
@@ -20405,6 +21160,110 @@
 done
 
 
+
+
+
+
+
+
+
+
+
+
+for ac_func in acosh asinh atanh copysign expm1 finite isinf isnan log1p
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; }
+if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$ac_func || defined __stub___$ac_func
+choke me
+#endif
+
+int
+main ()
+{
+return $ac_func ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	eval "$as_ac_var=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+ac_res=`eval echo '${'$as_ac_var'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
 LIBS=$LIBS_SAVE
 
 # check for wchar.h
@@ -21096,95 +21955,76 @@
 echo "${ECHO_T}$ac_cv_wchar_t_signed" >&6; }
 fi
 
-{ echo "$as_me:$LINENO: checking what type to use for unicode" >&5
-echo $ECHO_N "checking what type to use for unicode... $ECHO_C" >&6; }
-# Check whether --enable-unicode was given.
-if test "${enable_unicode+set}" = set; then
-  enableval=$enable_unicode;
-else
-  enable_unicode=yes
+{ echo "$as_me:$LINENO: checking what type to use for str" >&5
+echo $ECHO_N "checking what type to use for str... $ECHO_C" >&6; }
+
+# Check whether --with-wide-unicode was given.
+if test "${with_wide_unicode+set}" = set; then
+  withval=$with_wide_unicode;
+if test "$withval" != no
+then unicode_size="4"
+else unicode_size="2"
 fi
 
+else
+
+case "$have_ucs4_tcl" in
+  yes) unicode_size="4" ;;
+  *)   unicode_size="2" ;;
+esac
 
-if test $enable_unicode = yes
-then
-  # Without any arguments, Py_UNICODE defaults to two-byte mode
-  case "$have_ucs4_tcl" in
-  yes) enable_unicode="ucs4"
-       ;;
-  *)   enable_unicode="ucs2"
-       ;;
-  esac
 fi
 
 
 
-case "$enable_unicode" in
-ucs2) unicode_size="2"
-      cat >>confdefs.h <<\_ACEOF
-#define Py_UNICODE_SIZE 2
-_ACEOF
 
-      ;;
-ucs4) unicode_size="4"
-      cat >>confdefs.h <<\_ACEOF
+case "$unicode_size" in
+  4) cat >>confdefs.h <<\_ACEOF
 #define Py_UNICODE_SIZE 4
 _ACEOF
-
-      ;;
+ ;;
+  *) cat >>confdefs.h <<\_ACEOF
+#define Py_UNICODE_SIZE 2
+_ACEOF
+ ;;
 esac
 
 
 
 
-
-if test "$enable_unicode" = "no"
-then
-  UNICODE_OBJS=""
-  { echo "$as_me:$LINENO: result: not used" >&5
-echo "${ECHO_T}not used" >&6; }
-else
-  UNICODE_OBJS="Objects/unicodeobject.o Objects/unicodectype.o"
-
-cat >>confdefs.h <<\_ACEOF
-#define Py_USING_UNICODE 1
-_ACEOF
-
-
-  # wchar_t is only usable if it maps to an unsigned type
-  if test "$unicode_size" = "$ac_cv_sizeof_wchar_t" \
+# wchar_t is only usable if it maps to an unsigned type
+if test "$unicode_size" = "$ac_cv_sizeof_wchar_t" \
           -a "$ac_cv_wchar_t_signed" = "no"
-  then
-    PY_UNICODE_TYPE="wchar_t"
+then
+  PY_UNICODE_TYPE="wchar_t"
 
 cat >>confdefs.h <<\_ACEOF
 #define HAVE_USABLE_WCHAR_T 1
 _ACEOF
 
-    cat >>confdefs.h <<\_ACEOF
+  cat >>confdefs.h <<\_ACEOF
 #define PY_UNICODE_TYPE wchar_t
 _ACEOF
 
-  elif test "$ac_cv_sizeof_short" = "$unicode_size"
-  then
-       PY_UNICODE_TYPE="unsigned short"
-       cat >>confdefs.h <<\_ACEOF
+elif test "$ac_cv_sizeof_short" = "$unicode_size"
+then
+     PY_UNICODE_TYPE="unsigned short"
+     cat >>confdefs.h <<\_ACEOF
 #define PY_UNICODE_TYPE unsigned short
 _ACEOF
 
-  elif test "$ac_cv_sizeof_long" = "$unicode_size"
-  then
-       PY_UNICODE_TYPE="unsigned long"
-       cat >>confdefs.h <<\_ACEOF
+elif test "$ac_cv_sizeof_long" = "$unicode_size"
+then
+     PY_UNICODE_TYPE="unsigned long"
+     cat >>confdefs.h <<\_ACEOF
 #define PY_UNICODE_TYPE unsigned long
 _ACEOF
 
-  else
-       PY_UNICODE_TYPE="no type found"
-  fi
-  { echo "$as_me:$LINENO: result: $PY_UNICODE_TYPE" >&5
-echo "${ECHO_T}$PY_UNICODE_TYPE" >&6; }
+else
+     PY_UNICODE_TYPE="no type found"
 fi
+{ echo "$as_me:$LINENO: result: $PY_UNICODE_TYPE" >&5
+echo "${ECHO_T}$PY_UNICODE_TYPE" >&6; }
 
 # check for endianness
 { echo "$as_me:$LINENO: checking whether byte ordering is bigendian" >&5
@@ -23108,9 +23948,9 @@
 #include <stddef.h>
 #include <string.h>
 
-int main()
-{
-    char buffer[256];
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
 
 #ifdef HAVE_SSIZE_T
 typedef ssize_t Py_ssize_t;
@@ -23120,6 +23960,10 @@
 typedef int Py_ssize_t;
 #endif
 
+int main()
+{
+    char buffer[256];
+
     if(sprintf(buffer, "%zd", (size_t)123) < 0)
        	return 1;
 
@@ -24043,13 +24887,12 @@
 HAVE_GETHOSTBYNAME!$HAVE_GETHOSTBYNAME$ac_delim
 LIBM!$LIBM$ac_delim
 LIBC!$LIBC$ac_delim
-UNICODE_OBJS!$UNICODE_OBJS$ac_delim
 THREADHEADERS!$THREADHEADERS$ac_delim
 SRCDIRS!$SRCDIRS$ac_delim
 LTLIBOBJS!$LTLIBOBJS$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 19; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 18; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5

Modified: python/branches/py3k-importlib/configure.in
==============================================================================
--- python/branches/py3k-importlib/configure.in	(original)
+++ python/branches/py3k-importlib/configure.in	Thu Mar 27 00:48:05 2008
@@ -50,10 +50,6 @@
 # them.
 AC_DEFINE(__BSD_VISIBLE, 1, [Define on FreeBSD to activate all library features])
 
-# OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is
-# also defined. This can be overridden by defining _BSD_SOURCE
-AC_DEFINE(_BSD_SOURCE, 1, [Define on OpenBSD to activate all library features])
-
 # The later defininition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
 # u_int on Irix 5.3. Defining _BSD_TYPES brings it back.
 AC_DEFINE(_BSD_TYPES, 1, [Define on Irix to enable u_int])
@@ -65,7 +61,7 @@
 CONFIG_ARGS="$ac_configure_args"
 
 AC_ARG_ENABLE(universalsdk,
-	AC_HELP_STRING(--enable-universalsdk@<:@SDKDIR@:>@, Build agains Mac OS X 10.4u SDK (ppc/i386)),
+	AC_HELP_STRING(--enable-universalsdk@<:@=SDKDIR@:>@, Build against Mac OS X 10.4u SDK (ppc/i386)),
 [
 	case $enableval in
 	yes)
@@ -206,7 +202,12 @@
   # even though select is a POSIX function. Reported by J. Ribbens.
   # Reconfirmed for OpenBSD 3.3 by Zachary Hamm, for 3.4 by Jason Ish.
   OpenBSD/2.* | OpenBSD/3.@<:@0123456789@:>@ | OpenBSD/4.@<:@0@:>@) 
-    define_xopen_source=no;;
+    define_xopen_source=no
+    # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is
+    # also defined. This can be overridden by defining _BSD_SOURCE
+    # As this has a different meaning on Linux, only define it on OpenBSD
+    AC_DEFINE(_BSD_SOURCE, 1, [Define on OpenBSD to activate all library features])
+    ;;
   # Defining _XOPEN_SOURCE on NetBSD version prior to the introduction of
   # _NETBSD_SOURCE disables certain features (eg. setgroups). Reported by
   # Marc Recht
@@ -732,6 +733,10 @@
         if test "$CC" != 'g++' ; then
 	    STRICT_PROTO="-Wstrict-prototypes"
 	fi
+        # For gcc 4.x we need to use -fwrapv so lets check if its supported
+        if "$CC" -v --help 2>/dev/null |grep -- -fwrapv > /dev/null; then
+           WRAP="-fwrapv"
+        fi
 	case $ac_cv_prog_cc_g in
 	yes)
 	    if test "$Py_DEBUG" = 'true' ; then
@@ -739,7 +744,7 @@
 		# debug builds.
 		OPT="-g -Wall $STRICT_PROTO"
 	    else
-		OPT="-g -O3 -Wall $STRICT_PROTO"
+		OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
 	    fi
 	    ;;
 	*)
@@ -793,7 +798,8 @@
 	    ;;
 	# is there any other compiler on Darwin besides gcc?
 	Darwin*)
-	    BASECFLAGS="$BASECFLAGS -Wno-long-double -no-cpp-precomp -mno-fused-madd"
+	    # -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd
+	    # used to be here, but non-Apple gcc doesn't accept them.
 	    if test "${enable_universalsdk}"; then
 		BASECFLAGS="-arch ppc -arch i386 -isysroot ${UNIVERSALSDK} ${BASECFLAGS}"
 	    fi
@@ -1071,13 +1077,13 @@
 io.h langinfo.h libintl.h ncurses.h poll.h process.h pthread.h \
 shadow.h signal.h stdint.h stropts.h termios.h thread.h \
 unistd.h utime.h \
-sys/audioio.h sys/bsdtty.h sys/file.h sys/loadavg.h sys/lock.h sys/mkdev.h \
-sys/modem.h \
+sys/audioio.h sys/bsdtty.h sys/epoll.h sys/event.h sys/file.h sys/loadavg.h \
+sys/lock.h sys/mkdev.h sys/modem.h \
 sys/param.h sys/poll.h sys/select.h sys/socket.h sys/statvfs.h sys/stat.h \
 sys/time.h \
 sys/times.h sys/types.h sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \
 sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \
-bluetooth/bluetooth.h)
+bluetooth/bluetooth.h linux/tipc.h)
 AC_HEADER_DIRENT
 AC_HEADER_MAJOR
 
@@ -1172,7 +1178,7 @@
 AC_TYPE_SIGNAL
 AC_TYPE_SIZE_T
 AC_TYPE_UID_T
-AC_CHECK_TYPE(ssize_t, 
+AC_CHECK_TYPE(ssize_t,
   AC_DEFINE(HAVE_SSIZE_T, 1, Define if your compiler provides ssize_t),,)
 
 # Sizes of various common basic types
@@ -1185,6 +1191,7 @@
 AC_CHECK_SIZEOF(double, 8)
 AC_CHECK_SIZEOF(fpos_t, 4)
 AC_CHECK_SIZEOF(size_t, 4)
+AC_CHECK_SIZEOF(pid_t, 4)
 
 AC_MSG_CHECKING(for long long support)
 have_long_long=no
@@ -1728,9 +1735,6 @@
 AC_ARG_WITH(system_ffi,
             AC_HELP_STRING(--with-system-ffi, build _ctypes module using an installed ffi library))
 
-if test -z "$with_system_ffi"
-then with_system_ffi="no"
-fi
 AC_MSG_RESULT($with_system_ffi)
 
 # Determine if signalmodule should be used.
@@ -1953,6 +1957,9 @@
       SunOS/5.8) AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1,
 		       Define if the Posix semaphores do not work on your system)
 		       ;;
+      AIX/5) AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1,
+		       Define if the Posix semaphores do not work on your system)
+		       ;;
       esac
 
       AC_MSG_CHECKING(if PTHREAD_SCOPE_SYSTEM is supported)
@@ -2267,18 +2274,18 @@
 AC_MSG_RESULT(MACHDEP_OBJS)
 
 # checks for library functions
-AC_CHECK_FUNCS(alarm bind_textdomain_codeset chflags chown clock confstr \
- ctermid execv fork fpathconf ftime ftruncate \
+AC_CHECK_FUNCS(alarm bind_textdomain_codeset chown clock confstr \
+ ctermid execv fchmod fchown fork fpathconf ftime ftruncate \
  gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
  getpriority getpwent getspnam getspent getsid getwd \
- kill killpg lchflags lchown lstat mkfifo mknod mktime \
+ kill killpg lchmod lchown lstat mkfifo mknod mktime \
  mremap nice pathconf pause plock poll pthread_init \
  putenv readlink realpath \
  select setegid seteuid setgid \
  setlocale setregid setreuid setsid setpgid setpgrp setuid setvbuf snprintf \
  sigaction siginterrupt sigrelse strftime strlcpy \
  sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
- truncate uname unsetenv utimes waitpid wait3 wait4 wcscoll _getpty)
+ truncate uname unsetenv utimes waitpid wait3 wait4 wcscoll wcsxfrm _getpty)
 
 # For some functions, having a definition is not sufficient, since
 # we want to take their address.
@@ -2318,7 +2325,21 @@
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no)
 )
-
+AC_MSG_CHECKING(for epoll)
+AC_TRY_COMPILE([#include <sys/epoll.h>], void *x=epoll_create,
+  AC_DEFINE(HAVE_EPOLL, 1, Define if you have the 'epoll' functions.)
+  AC_MSG_RESULT(yes),
+  AC_MSG_RESULT(no)
+)
+AC_MSG_CHECKING(for kqueue)
+AC_TRY_COMPILE([
+#include <sys/types.h>
+#include <sys/event.h>
+    ], int x=kqueue(),
+  AC_DEFINE(HAVE_KQUEUE, 1, Define if you have the 'kqueue' functions.)
+  AC_MSG_RESULT(yes),
+  AC_MSG_RESULT(no)
+)
 # On some systems (eg. FreeBSD 5), we would find a definition of the
 # functions ctermid_r, setgroups in the library, but no prototype
 # (e.g. because we use _XOPEN_SOURCE). See whether we can take their
@@ -2364,6 +2385,38 @@
   AC_CHECK_LIB(resolv, inet_aton)
 )
 
+# On Tru64, chflags seems to be present, but calling it will
+# exit Python
+AC_MSG_CHECKING(for chflags)
+AC_TRY_RUN([
+#include <sys/stat.h>
+#include <unistd.h>
+int main(int argc, char*argv[])
+{
+  if(chflags(argv[0], 0) != 0)
+    return 1;
+  return 0;
+}
+],AC_DEFINE(HAVE_CHFLAGS, 1, Define to 1 if you have the `chflags' function.)
+  AC_MSG_RESULT(yes),
+  AC_MSG_RESULT(no)
+)
+
+AC_MSG_CHECKING(for lchflags)
+AC_TRY_RUN([
+#include <sys/stat.h>
+#include <unistd.h>
+int main(int argc, char*argv[])
+{
+  if(lchflags(argv[0], 0) != 0)
+    return 1;
+  return 0;
+}
+],AC_DEFINE(HAVE_LCHFLAGS, 1, Define to 1 if you have the `lchflags' function.)
+  AC_MSG_RESULT(yes),
+  AC_MSG_RESULT(no)
+)
+
 dnl Check if system zlib has *Copy() functions
 dnl
 dnl On MacOSX the linker will search for dylibs on the entire linker path
@@ -2459,10 +2512,13 @@
    )
 )
 
+# Stuff for expat.
+AC_CHECK_FUNCS(memmove)
+
 # check for long file support functions
 AC_CHECK_FUNCS(fseek64 fseeko fstatvfs ftell64 ftello statvfs)
 
-AC_REPLACE_FUNCS(dup2 getcwd strdup strerror memmove)
+AC_REPLACE_FUNCS(dup2 getcwd strdup)
 AC_CHECK_FUNCS(getpgrp, 
   AC_TRY_COMPILE([#include <unistd.h>], 
    [getpgrp(0);], 
@@ -2901,10 +2957,15 @@
 fi],
 [AC_MSG_RESULT(default LIBC="$LIBC")])
 
-# check for hypot() in math library
+# ************************************
+# * Check for mathematical functions *
+# ************************************
 LIBS_SAVE=$LIBS
 LIBS="$LIBS $LIBM"
 AC_REPLACE_FUNCS(hypot)
+
+AC_CHECK_FUNCS(acosh asinh atanh copysign expm1 finite isinf isnan log1p)
+
 LIBS=$LIBS_SAVE
 
 # check for wchar.h
@@ -2953,72 +3014,55 @@
   ac_cv_wchar_t_signed=yes)])
   AC_MSG_RESULT($ac_cv_wchar_t_signed)
 fi
-  
-AC_MSG_CHECKING(what type to use for unicode)
-dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
-AC_ARG_ENABLE(unicode, 
-              AC_HELP_STRING(--enable-unicode@<:@=ucs@<:@24@:>@@:>@, Enable Unicode strings (default is yes)),
-              [],
-              [enable_unicode=yes])
-
-if test $enable_unicode = yes
-then
-  # Without any arguments, Py_UNICODE defaults to two-byte mode
-  case "$have_ucs4_tcl" in
-  yes) enable_unicode="ucs4"
-       ;;
-  *)   enable_unicode="ucs2"
-       ;;
-  esac
+
+AC_MSG_CHECKING(what type to use for str)
+AC_ARG_WITH(wide-unicode, 
+            AC_HELP_STRING(--with-wide-unicode, Use 4-byte Unicode characters (default is 2 bytes)),
+[
+if test "$withval" != no
+then unicode_size="4"
+else unicode_size="2"
 fi
+],
+[
+case "$have_ucs4_tcl" in
+  yes) unicode_size="4" ;;
+  *)   unicode_size="2" ;;
+esac
+])
 
 AH_TEMPLATE(Py_UNICODE_SIZE,
   [Define as the size of the unicode type.])
-case "$enable_unicode" in
-ucs2) unicode_size="2"
-      AC_DEFINE(Py_UNICODE_SIZE,2)
-      ;;
-ucs4) unicode_size="4"
-      AC_DEFINE(Py_UNICODE_SIZE,4)
-      ;;
+case "$unicode_size" in
+  4) AC_DEFINE(Py_UNICODE_SIZE, 4) ;;
+  *) AC_DEFINE(Py_UNICODE_SIZE, 2) ;;
 esac
 
 AH_TEMPLATE(PY_UNICODE_TYPE,
   [Define as the integral type used for Unicode representation.])
 
-AC_SUBST(UNICODE_OBJS)
-if test "$enable_unicode" = "no"
+# wchar_t is only usable if it maps to an unsigned type
+if test "$unicode_size" = "$ac_cv_sizeof_wchar_t" \
+          -a "$ac_cv_wchar_t_signed" = "no"
 then
-  UNICODE_OBJS=""
-  AC_MSG_RESULT(not used)
+  PY_UNICODE_TYPE="wchar_t"
+  AC_DEFINE(HAVE_USABLE_WCHAR_T, 1,
+  [Define if you have a useable wchar_t type defined in wchar.h; useable
+   means wchar_t must be an unsigned type with at least 16 bits. (see
+   Include/unicodeobject.h).])
+  AC_DEFINE(PY_UNICODE_TYPE,wchar_t)
+elif test "$ac_cv_sizeof_short" = "$unicode_size"
+then
+     PY_UNICODE_TYPE="unsigned short"
+     AC_DEFINE(PY_UNICODE_TYPE,unsigned short)
+elif test "$ac_cv_sizeof_long" = "$unicode_size"
+then
+     PY_UNICODE_TYPE="unsigned long"
+     AC_DEFINE(PY_UNICODE_TYPE,unsigned long)
 else
-  UNICODE_OBJS="Objects/unicodeobject.o Objects/unicodectype.o"
-  AC_DEFINE(Py_USING_UNICODE, 1,
-  [Define if you want to have a Unicode type.])
-
-  # wchar_t is only usable if it maps to an unsigned type
-  if test "$unicode_size" = "$ac_cv_sizeof_wchar_t" \
-          -a "$ac_cv_wchar_t_signed" = "no"
-  then
-    PY_UNICODE_TYPE="wchar_t"
-    AC_DEFINE(HAVE_USABLE_WCHAR_T, 1,
-    [Define if you have a useable wchar_t type defined in wchar.h; useable
-     means wchar_t must be an unsigned type with at least 16 bits. (see
-     Include/unicodeobject.h).])
-    AC_DEFINE(PY_UNICODE_TYPE,wchar_t)
-  elif test "$ac_cv_sizeof_short" = "$unicode_size"
-  then
-       PY_UNICODE_TYPE="unsigned short"
-       AC_DEFINE(PY_UNICODE_TYPE,unsigned short)
-  elif test "$ac_cv_sizeof_long" = "$unicode_size"
-  then
-       PY_UNICODE_TYPE="unsigned long"
-       AC_DEFINE(PY_UNICODE_TYPE,unsigned long)
-  else
-       PY_UNICODE_TYPE="no type found"
-  fi
-  AC_MSG_RESULT($PY_UNICODE_TYPE)
+     PY_UNICODE_TYPE="no type found"
 fi
+AC_MSG_RESULT($PY_UNICODE_TYPE)
 
 # check for endianness
 AC_C_BIGENDIAN
@@ -3386,9 +3430,9 @@
 #include <stddef.h>
 #include <string.h>
 
-int main()
-{
-    char buffer[256];
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
 
 #ifdef HAVE_SSIZE_T
 typedef ssize_t Py_ssize_t;
@@ -3398,6 +3442,10 @@
 typedef int Py_ssize_t;
 #endif
 
+int main()
+{
+    char buffer[256];
+
     if(sprintf(buffer, "%zd", (size_t)123) < 0)
        	return 1;
 

Modified: python/branches/py3k-importlib/pyconfig.h.in
==============================================================================
--- python/branches/py3k-importlib/pyconfig.h.in	(original)
+++ python/branches/py3k-importlib/pyconfig.h.in	Thu Mar 27 00:48:05 2008
@@ -25,6 +25,9 @@
    the case on Motorola V4 (R40V4.2) */
 #undef GETTIMEOFDAY_NO_TZ
 
+/* Define to 1 if you have the `acosh' function. */
+#undef HAVE_ACOSH
+
 /* struct addrinfo (netdb.h) */
 #undef HAVE_ADDRINFO
 
@@ -34,9 +37,15 @@
 /* Define this if your time.h defines altzone. */
 #undef HAVE_ALTZONE
 
+/* Define to 1 if you have the `asinh' function. */
+#undef HAVE_ASINH
+
 /* Define to 1 if you have the <asm/types.h> header file. */
 #undef HAVE_ASM_TYPES_H
 
+/* Define to 1 if you have the `atanh' function. */
+#undef HAVE_ATANH
+
 /* Define if GCC supports __attribute__((format(PyArg_ParseTuple, 2, 3))) */
 #undef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE
 
@@ -82,6 +91,9 @@
 /* Define to 1 if you have the <conio.h> header file. */
 #undef HAVE_CONIO_H
 
+/* Define to 1 if you have the `copysign' function. */
+#undef HAVE_COPYSIGN
+
 /* Define to 1 if you have the `ctermid' function. */
 #undef HAVE_CTERMID
 
@@ -132,21 +144,36 @@
 /* Defined when any dynamic module loading is enabled. */
 #undef HAVE_DYNAMIC_LOADING
 
+/* Define if you have the 'epoll' functions. */
+#undef HAVE_EPOLL
+
 /* Define to 1 if you have the <errno.h> header file. */
 #undef HAVE_ERRNO_H
 
 /* Define to 1 if you have the `execv' function. */
 #undef HAVE_EXECV
 
+/* Define to 1 if you have the `expm1' function. */
+#undef HAVE_EXPM1
+
 /* Define if you have the 'fchdir' function. */
 #undef HAVE_FCHDIR
 
+/* Define to 1 if you have the `fchmod' function. */
+#undef HAVE_FCHMOD
+
+/* Define to 1 if you have the `fchown' function. */
+#undef HAVE_FCHOWN
+
 /* Define to 1 if you have the <fcntl.h> header file. */
 #undef HAVE_FCNTL_H
 
 /* Define if you have the 'fdatasync' function. */
 #undef HAVE_FDATASYNC
 
+/* Define to 1 if you have the `finite' function. */
+#undef HAVE_FINITE
+
 /* Define if you have the 'flock' function. */
 #undef HAVE_FLOCK
 
@@ -279,12 +306,21 @@
 /* Define to 1 if you have the <io.h> header file. */
 #undef HAVE_IO_H
 
+/* Define to 1 if you have the `isinf' function. */
+#undef HAVE_ISINF
+
+/* Define to 1 if you have the `isnan' function. */
+#undef HAVE_ISNAN
+
 /* Define to 1 if you have the `kill' function. */
 #undef HAVE_KILL
 
 /* Define to 1 if you have the `killpg' function. */
 #undef HAVE_KILLPG
 
+/* Define if you have the 'kqueue' functions. */
+#undef HAVE_KQUEUE
+
 /* Define to 1 if you have the <langinfo.h> header file. */
 #undef HAVE_LANGINFO_H
 
@@ -297,6 +333,9 @@
 /* Define to 1 if you have the `lchflags' function. */
 #undef HAVE_LCHFLAGS
 
+/* Define to 1 if you have the `lchmod' function. */
+#undef HAVE_LCHMOD
+
 /* Define to 1 if you have the `lchown' function. */
 #undef HAVE_LCHOWN
 
@@ -330,6 +369,12 @@
 /* Define to 1 if you have the <linux/netlink.h> header file. */
 #undef HAVE_LINUX_NETLINK_H
 
+/* Define to 1 if you have the <linux/tipc.h> header file. */
+#undef HAVE_LINUX_TIPC_H
+
+/* Define to 1 if you have the `log1p' function. */
+#undef HAVE_LOG1P
+
 /* Define this if you have the type long double. */
 #undef HAVE_LONG_DOUBLE
 
@@ -532,9 +577,6 @@
 /* Define to 1 if you have the `strdup' function. */
 #undef HAVE_STRDUP
 
-/* Define to 1 if you have the `strerror' function. */
-#undef HAVE_STRERROR
-
 /* Define to 1 if you have the `strftime' function. */
 #undef HAVE_STRFTIME
 
@@ -594,6 +636,12 @@
    */
 #undef HAVE_SYS_DIR_H
 
+/* Define to 1 if you have the <sys/epoll.h> header file. */
+#undef HAVE_SYS_EPOLL_H
+
+/* Define to 1 if you have the <sys/event.h> header file. */
+#undef HAVE_SYS_EVENT_H
+
 /* Define to 1 if you have the <sys/file.h> header file. */
 #undef HAVE_SYS_FILE_H
 
@@ -737,6 +785,9 @@
 /* Define to 1 if you have the `wcscoll' function. */
 #undef HAVE_WCSCOLL
 
+/* Define to 1 if you have the `wcsxfrm' function. */
+#undef HAVE_WCSXFRM
+
 /* Define if tzset() actually switches the local timezone in a meaningful way.
    */
 #undef HAVE_WORKING_TZSET
@@ -797,9 +848,6 @@
 /* Define as the size of the unicode type. */
 #undef Py_UNICODE_SIZE
 
-/* Define if you want to have a Unicode type. */
-#undef Py_USING_UNICODE
-
 /* Define as the return type of signal handlers (`int' or `void'). */
 #undef RETSIGTYPE
 
@@ -836,6 +884,9 @@
 /* The number of bytes in an off_t. */
 #undef SIZEOF_OFF_T
 
+/* The size of `pid_t', as computed by sizeof. */
+#undef SIZEOF_PID_T
+
 /* The number of bytes in a pthread_t. */
 #undef SIZEOF_PTHREAD_T
 

Modified: python/branches/py3k-importlib/runtests.sh
==============================================================================
--- python/branches/py3k-importlib/runtests.sh	(original)
+++ python/branches/py3k-importlib/runtests.sh	Thu Mar 27 00:48:05 2008
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 HELP="Usage: ./runtests.py [-h] [-x] [flags] [tests]
 

Modified: python/branches/py3k-importlib/setup.py
==============================================================================
--- python/branches/py3k-importlib/setup.py	(original)
+++ python/branches/py3k-importlib/setup.py	Thu Mar 27 00:48:05 2008
@@ -4,6 +4,7 @@
 __version__ = "$Revision$"
 
 import sys, os, imp, re, optparse
+from glob import glob
 
 from distutils import log
 from distutils import sysconfig
@@ -101,8 +102,14 @@
         missing = self.detect_modules()
 
         # Remove modules that are present on the disabled list
-        self.extensions = [ext for ext in self.extensions
-                           if ext.name not in disabled_module_list]
+        extensions = [ext for ext in self.extensions
+                      if ext.name not in disabled_module_list]
+        # move ctypes to the end, it depends on other modules
+        ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
+        if "_ctypes" in ext_map:
+            ctypes = extensions.pop(ext_map["_ctypes"])
+            extensions.append(ctypes)
+        self.extensions = extensions
 
         # Fix up the autodetected modules, prefixing all the source files
         # with Modules/ and adding Python's include directory to the path.
@@ -136,12 +143,20 @@
         self.distribution.scripts = [os.path.join(srcdir, filename)
                                      for filename in self.distribution.scripts]
 
+        # Python header files
+        headers = glob("Include/*.h") + ["pyconfig.h"]
+
         for ext in self.extensions[:]:
             ext.sources = [ find_module_file(filename, moddirlist)
                             for filename in ext.sources ]
             if ext.depends is not None:
                 ext.depends = [find_module_file(filename, alldirlist)
                                for filename in ext.depends]
+            else:
+                ext.depends = []
+            # re-compile extensions if a header file has been changed
+            ext.depends.extend(headers)
+
             ext.include_dirs.append( '.' ) # to get config.h
             for incdir in incdirlist:
                 ext.include_dirs.append( os.path.join(srcdir, incdir) )
@@ -312,7 +327,7 @@
                 parser.add_option(arg_name, dest="dirs", action="append")
                 options = parser.parse_args(env_val.split())[0]
                 if options.dirs:
-                    for directory in options.dirs:
+                    for directory in reversed(options.dirs):
                         add_dir_to_list(dir_list, directory)
 
         if os.path.normpath(sys.prefix) != '/usr':
@@ -395,10 +410,10 @@
                                libraries=math_libs) )
         exts.append( Extension('datetime', ['datetimemodule.c', 'timemodule.c'],
                                libraries=math_libs) )
-        # random number generator implemented in C
-        exts.append( Extension("_random", ["_randommodule.c"]) )
         # fast iterator tools implemented in C
         exts.append( Extension("itertools", ["itertoolsmodule.c"]) )
+        # random number generator implemented in C
+        exts.append( Extension("_random", ["_randommodule.c"]) )
         # high-performance collections
         exts.append( Extension("_collections", ["_collectionsmodule.c"]) )
         # bisect
@@ -457,9 +472,6 @@
         # select(2); not on ancient System V
         exts.append( Extension('select', ['selectmodule.c']) )
 
-        # Helper module for various ascii-encoders
-        exts.append( Extension('binascii', ['binascii.c']) )
-
         # Fred Drake's interface to the Python parser
         exts.append( Extension('parser', ['parsermodule.c']) )
 
@@ -637,7 +649,10 @@
         # a release.  Most open source OSes come with one or more
         # versions of BerkeleyDB already installed.
 
-        max_db_ver = (4, 6)
+        max_db_ver = (4, 5)  # XXX(gregory.p.smith): 4.6 "works" but seems to
+                             # have issues on many platforms.  I've temporarily
+                             # disabled 4.6 to see what the odd platform
+                             # buildbots say.
         min_db_ver = (3, 3)
         db_setup_debug = False   # verbose debug prints from this script?
 
@@ -680,10 +695,10 @@
         for dn in inc_dirs:
             std_variants.append(os.path.join(dn, 'db3'))
             std_variants.append(os.path.join(dn, 'db4'))
-            for x in (0,1,2,3,4,5,6):
+            for x in range(max_db_ver[1]+1):
                 std_variants.append(os.path.join(dn, "db4%d"%x))
                 std_variants.append(os.path.join(dn, "db4.%d"%x))
-            for x in (2,3):
+            for x in (3,):
                 std_variants.append(os.path.join(dn, "db3%d"%x))
                 std_variants.append(os.path.join(dn, "db3.%d"%x))
 
@@ -773,6 +788,7 @@
             # some unusual system configurations (e.g. the directory
             # is on an NFS server that goes away).
             exts.append(Extension('_bsddb', ['_bsddb.c'],
+                                  depends = ['bsddb.h'],
                                   library_dirs=dblib_dir,
                                   runtime_library_dirs=dblib_dir,
                                   include_dirs=db_incs,
@@ -986,6 +1002,7 @@
         # You can upgrade zlib to version 1.1.4 yourself by going to
         # http://www.gzip.org/zlib/
         zlib_inc = find_file('zlib.h', [], inc_dirs)
+        have_zlib = False
         if zlib_inc is not None:
             zlib_h = zlib_inc[0] + '/zlib.h'
             version = '"0.0.0"'
@@ -1007,6 +1024,7 @@
                     exts.append( Extension('zlib', ['zlibmodule.c'],
                                            libraries = ['z'],
                                            extra_link_args = zlib_extra_link_args))
+                    have_zlib = True
                 else:
                     missing.append('zlib')
             else:
@@ -1014,6 +1032,21 @@
         else:
             missing.append('zlib')
 
+        # Helper module for various ascii-encoders.  Uses zlib for an optimized
+        # crc32 if we have it.  Otherwise binascii uses its own.
+        if have_zlib:
+            extra_compile_args = ['-DUSE_ZLIB_CRC32']
+            libraries = ['z']
+            extra_link_args = zlib_extra_link_args
+        else:
+            extra_compile_args = []
+            libraries = []
+            extra_link_args = []
+        exts.append( Extension('binascii', ['binascii.c'],
+                               extra_compile_args = extra_compile_args,
+                               libraries = libraries,
+                               extra_link_args = extra_link_args) )
+
         # Gustavo Niemeyer's bz2 module.
         if (self.compiler.find_library_file(lib_dirs, 'bz2')):
             if sys.platform == "darwin":
@@ -1073,7 +1106,7 @@
                                   ['cjkcodecs/_codecs_%s.c' % loc]))
 
         # Dynamic loading module
-        if sys.maxint == 0x7fffffff:
+        if sys.maxsize == 0x7fffffff:
             # This requires sizeof(int) == sizeof(long) == sizeof(char*)
             dl_inc = find_file('dlfcn.h', [], inc_dirs)
             if (dl_inc is not None) and (platform not in ['atheos']):
@@ -1091,7 +1124,7 @@
 
         # Platform-specific libraries
         if platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
-                        'freebsd7'):
+                        'freebsd7', 'freebsd8'):
             exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) )
         else:
             missing.append('ossaudiodev')
@@ -1358,8 +1391,37 @@
         # *** Uncomment these for TOGL extension only:
         #       -lGL -lGLU -lXext -lXmu \
 
+    def configure_ctypes_darwin(self, ext):
+        # Darwin (OS X) uses preconfigured files, in
+        # the Modules/_ctypes/libffi_osx directory.
+        (srcdir,) = sysconfig.get_config_vars('srcdir')
+        ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
+                                                  '_ctypes', 'libffi_osx'))
+        sources = [os.path.join(ffi_srcdir, p)
+                   for p in ['ffi.c',
+                             'x86/x86-darwin.S',
+                             'x86/x86-ffi_darwin.c',
+                             'x86/x86-ffi64.c',
+                             'powerpc/ppc-darwin.S',
+                             'powerpc/ppc-darwin_closure.S',
+                             'powerpc/ppc-ffi_darwin.c',
+                             'powerpc/ppc64-darwin_closure.S',
+                             ]]
+
+        # Add .S (preprocessed assembly) to C compiler source extensions.
+        self.compiler.src_extensions.append('.S')
+
+        include_dirs = [os.path.join(ffi_srcdir, 'include'),
+                        os.path.join(ffi_srcdir, 'powerpc')]
+        ext.include_dirs.extend(include_dirs)
+        ext.sources.extend(sources)
+        return True
+
     def configure_ctypes(self, ext):
         if not self.use_system_libffi:
+            if sys.platform == 'darwin':
+                return self.configure_ctypes_darwin(ext)
+
             (srcdir,) = sysconfig.get_config_vars('srcdir')
             ffi_builddir = os.path.join(self.build_temp, 'libffi')
             ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
@@ -1423,6 +1485,7 @@
 
         if sys.platform == 'darwin':
             sources.append('_ctypes/darwin/dlfcn_simple.c')
+            extra_compile_args.append('-DMACOSX')
             include_dirs.append('_ctypes/darwin')
 # XXX Is this still needed?
 ##            extra_link_args.extend(['-read_only_relocs', 'warning'])
@@ -1452,6 +1515,11 @@
         if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"):
             return
 
+        if sys.platform == 'darwin':
+            # OS X 10.5 comes with libffi.dylib; the include files are
+            # in /usr/include/ffi
+            inc_dirs.append('/usr/include/ffi')
+
         ffi_inc = find_file('ffi.h', [], inc_dirs)
         if ffi_inc is not None:
             ffi_h = ffi_inc[0] + '/ffi.h'


More information about the Python-3000-checkins mailing list